From b51710fb310a998a65c3bb03968bfe6e1d971509 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 3 Apr 2023 15:44:12 +0200 Subject: [PATCH 001/116] refs #5525 mod yml y sql --- db/changes/231401/00-accountCountry.sql | 10 ++++++++++ print/templates/reports/sepa-core/locale/es.yml | 2 ++ print/templates/reports/sepa-core/locale/fr.yml | 2 ++ print/templates/reports/sepa-core/sepa-core.html | 4 ++-- print/templates/reports/sepa-core/sepa-core.js | 5 +++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 db/changes/231401/00-accountCountry.sql diff --git a/db/changes/231401/00-accountCountry.sql b/db/changes/231401/00-accountCountry.sql new file mode 100644 index 000000000..73c21f0b2 --- /dev/null +++ b/db/changes/231401/00-accountCountry.sql @@ -0,0 +1,10 @@ +-- vn.accountCountry definition + +CREATE TABLE `accountCountry` in `vn` ( + `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, + `countryFk` mediumint(8) unsigned DEFAULT NULL, + KEY `supplierAccountFk` (`supplierAccountFk`), + KEY `countryFk` (`countryFk`), + CONSTRAINT `accountCountry_ibfk_1` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`), + CONSTRAINT `accountCountry_ibfk_2` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/print/templates/reports/sepa-core/locale/es.yml b/print/templates/reports/sepa-core/locale/es.yml index 5f3f08fc3..ebb8dce1a 100644 --- a/print/templates/reports/sepa-core/locale/es.yml +++ b/print/templates/reports/sepa-core/locale/es.yml @@ -17,6 +17,8 @@ supplier: toCompleteBySupplier: A cumplimentar por el acreedor orderReference: Referencia de la orden de domiciliación identifier: Identificador del acreedor + iban: ES89000B97367486 + cif: B97367486-000 name: Nombre del acreedor street: Dirección location: CP - Población - Provincia diff --git a/print/templates/reports/sepa-core/locale/fr.yml b/print/templates/reports/sepa-core/locale/fr.yml index 354c06114..3f39d18d4 100644 --- a/print/templates/reports/sepa-core/locale/fr.yml +++ b/print/templates/reports/sepa-core/locale/fr.yml @@ -13,6 +13,8 @@ sendOrder: APRÈS SIGNATURA, RENVOYER AU CRÉANCIER ET AU VOTRE ÉTABLISSEMENT F supplier: toCompleteBySupplier: Á compléter pour le créancier orderReference: Numéro de référence du mandat + iban: FR7630003012690002801121597 + cif: B97367486-000 identifier: Identifiant créancier name: Nom du céancier street: Adresse diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index a8c270ad5..defbdb110 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -27,8 +27,8 @@ {{$t('supplier.identifier')}} -
ES89000B97367486
-
B97367486-000
+
{{$t('supplier.iban')}}
+
{{$t('supplier.cif')}}
diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 0e19d2a6a..2198984f3 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -1,5 +1,10 @@ const vnReport = require('../../../core/mixins/vn-report.js'); +// class Controller { +// constructor(country, supplier, iban, cif) { +// this.country = countryFk; +// } +// } module.exports = { name: 'sepa-core', mixins: [vnReport], From 95602895df87beb59bc2075bee83487f8e15ebc1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Apr 2023 14:40:02 +0200 Subject: [PATCH 002/116] refs #5525 update changes --- db/changes/{231401 => 231601}/00-accountCountry.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/changes/{231401 => 231601}/00-accountCountry.sql (91%) diff --git a/db/changes/231401/00-accountCountry.sql b/db/changes/231601/00-accountCountry.sql similarity index 91% rename from db/changes/231401/00-accountCountry.sql rename to db/changes/231601/00-accountCountry.sql index 73c21f0b2..05e9d83f1 100644 --- a/db/changes/231401/00-accountCountry.sql +++ b/db/changes/231601/00-accountCountry.sql @@ -1,6 +1,6 @@ -- vn.accountCountry definition -CREATE TABLE `accountCountry` in `vn` ( +CREATE TABLE `vn`.`accountCountry` ( `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, `countryFk` mediumint(8) unsigned DEFAULT NULL, KEY `supplierAccountFk` (`supplierAccountFk`), From 790de4f05f1645ca087f3c4f56bdf5f3d83dc9f5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 25 May 2023 13:08:24 +0200 Subject: [PATCH 003/116] refs #5525 trad fr pt --- .../email/letter-debtor-nd/locale/fr.yml | 26 +++++++++++++++++++ .../email/letter-debtor-nd/locale/pt.yml | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 print/templates/email/letter-debtor-nd/locale/fr.yml create mode 100644 print/templates/email/letter-debtor-nd/locale/pt.yml diff --git a/print/templates/email/letter-debtor-nd/locale/fr.yml b/print/templates/email/letter-debtor-nd/locale/fr.yml new file mode 100644 index 000000000..3ea3501d7 --- /dev/null +++ b/print/templates/email/letter-debtor-nd/locale/fr.yml @@ -0,0 +1,26 @@ +subject: Réitération de l'avis de solde débiteur +title: Avis réitéré +sections: + introduction: + title: Cher client + description: Nous vous écrivons à nouveau pour vous informer qu'il est toujours en attente + votre dette envers notre société, comme vous pouvez le voir dans le relevé ci-joint. + terms: Étant donné que les délais de paiement convenus sont largement dépassés, il n'est pas approprié + retard plus important dans le règlement du montant dû. + payMethod: + description: Pour cela, vous disposez des modes de paiement suivants + options: + - Paiement en ligne depuis notre site internet. + - Revenu ou virement sur le numéro de compte que nous détaillons en bas de ce courrier, + indiquant le numéro de client. + legalAction: + description: Si cette obligation de paiement n'est pas remplie, nous serons contraints de + d'engager les actions judiciaires qui se déroulent, parmi lesquelles + options: + - Inclusion dans les dossiers négatifs sur la solvabilité financière et le crédit. + - Réclamation judiciaire. + - Cession de créance à une société de gestion de recouvrement. +contactPhone: Pour toute demande, vous pouvez nous contacter au 96 + 324 21 00. +conclusion: En attente de vos nouvelles.
Merci pour ton attention. +transferAccount: Données pour virement bancaire \ No newline at end of file diff --git a/print/templates/email/letter-debtor-nd/locale/pt.yml b/print/templates/email/letter-debtor-nd/locale/pt.yml new file mode 100644 index 000000000..f4acbd1d3 --- /dev/null +++ b/print/templates/email/letter-debtor-nd/locale/pt.yml @@ -0,0 +1,26 @@ +subject: Reiteração de aviso de saldo devedor +title: Aviso reiterado +sections: + introduction: + title: Estimado cliente + description: Estamos escrevendo para você novamente para informar que ainda está pendente + sua dívida para com nossa empresa, conforme demonstrativo anexo. + terms: Dado que os prazos de pagamento acordados são largamente excedidos, não é adequado + maior atraso na liquidação do valor devido. + payMethod: + description: Para isso você tem as seguintes formas de pagamento + options: + - Pagamento online em nosso site. + - Renda ou transferência para o número da conta que detalhamos no final desta carta, + indicando o número do cliente. + legalAction: + description: Se esta obrigação de pagamento não for cumprida, seremos obrigados a + para iniciar as ações legais que procedem, entre as quais estão + options: + - Inclusão em processos negativos de solvência financeira e de crédito. + - Reivindicação judicial. + - Cessão de dívida a uma empresa de gestão de cobranças. +contactPhone: Para consultas, você pode entrar em contato conosco em 96 + 324 21 00. +conclusion: Aguardando suas notícias.
Agradecimentos para sua atenção. +transferAccount: Dados para transferência bancária \ No newline at end of file From de7b270d9e6528f29d768a90b9a091fa4c0a5401 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 9 Jun 2023 11:24:51 +0200 Subject: [PATCH 004/116] refs #5525 sql --- db/changes/231801/00-accountCountry.sql | 10 ---------- db/changes/232601/00-accountCountry.sql | 13 +++++++++++++ db/changes/232601/00-supplierDefault.sql | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) delete mode 100644 db/changes/231801/00-accountCountry.sql create mode 100644 db/changes/232601/00-accountCountry.sql create mode 100644 db/changes/232601/00-supplierDefault.sql diff --git a/db/changes/231801/00-accountCountry.sql b/db/changes/231801/00-accountCountry.sql deleted file mode 100644 index 05e9d83f1..000000000 --- a/db/changes/231801/00-accountCountry.sql +++ /dev/null @@ -1,10 +0,0 @@ --- vn.accountCountry definition - -CREATE TABLE `vn`.`accountCountry` ( - `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, - `countryFk` mediumint(8) unsigned DEFAULT NULL, - KEY `supplierAccountFk` (`supplierAccountFk`), - KEY `countryFk` (`countryFk`), - CONSTRAINT `accountCountry_ibfk_1` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`), - CONSTRAINT `accountCountry_ibfk_2` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/changes/232601/00-accountCountry.sql b/db/changes/232601/00-accountCountry.sql new file mode 100644 index 000000000..f92abd9df --- /dev/null +++ b/db/changes/232601/00-accountCountry.sql @@ -0,0 +1,13 @@ +-- vn.supplierAccountContry definition + +CREATE TABLE `supplierAccountCountry` ( + `supplierAccountFk` mediumint(8) unsigned NOT NULL, + `companyFk` int(11) DEFAULT NULL, + `countryFk` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`supplierAccountFk`), + UNIQUE KEY `countryFk` (`countryFk`), + UNIQUE KEY `companyFk` (`companyFk`), + CONSTRAINT `companyFk_supplier` FOREIGN KEY (`companyFk`) REFERENCES `supplierAccount` (`supplierFk`) ON UPDATE CASCADE, + CONSTRAINT `countryFk_id` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccountFk_id` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/changes/232601/00-supplierDefault.sql b/db/changes/232601/00-supplierDefault.sql new file mode 100644 index 000000000..c411558f1 --- /dev/null +++ b/db/changes/232601/00-supplierDefault.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplier ADD defaultAccountFk varchar(100) DEFAULT NULL NULL; From b8f0b205db1b9e732a43d05c826f1e963bf4e5b2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 28 Jun 2023 06:53:42 +0200 Subject: [PATCH 005/116] refs #5525 move sql --- db/changes/{232601 => 232801}/00-accountCountry.sql | 0 db/changes/{232601 => 232801}/00-supplierDefault.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{232601 => 232801}/00-accountCountry.sql (100%) rename db/changes/{232601 => 232801}/00-supplierDefault.sql (100%) diff --git a/db/changes/232601/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql similarity index 100% rename from db/changes/232601/00-accountCountry.sql rename to db/changes/232801/00-accountCountry.sql diff --git a/db/changes/232601/00-supplierDefault.sql b/db/changes/232801/00-supplierDefault.sql similarity index 100% rename from db/changes/232601/00-supplierDefault.sql rename to db/changes/232801/00-supplierDefault.sql From 0a78dd344fab7f8fbb77a3c6240db0d6b77db723 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 29 Jun 2023 06:24:13 +0200 Subject: [PATCH 006/116] refs #5525 sql --- db/changes/232801/00-accountCountry.sql | 38 ++++++++++++++++-------- db/changes/232801/00-supplierDefault.sql | 1 - 2 files changed, 25 insertions(+), 14 deletions(-) delete mode 100644 db/changes/232801/00-supplierDefault.sql diff --git a/db/changes/232801/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql index f92abd9df..d44cdcc4e 100644 --- a/db/changes/232801/00-accountCountry.sql +++ b/db/changes/232801/00-accountCountry.sql @@ -1,13 +1,25 @@ --- vn.supplierAccountContry definition - -CREATE TABLE `supplierAccountCountry` ( - `supplierAccountFk` mediumint(8) unsigned NOT NULL, - `companyFk` int(11) DEFAULT NULL, - `countryFk` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`supplierAccountFk`), - UNIQUE KEY `countryFk` (`countryFk`), - UNIQUE KEY `companyFk` (`companyFk`), - CONSTRAINT `companyFk_supplier` FOREIGN KEY (`companyFk`) REFERENCES `supplierAccount` (`supplierFk`) ON UPDATE CASCADE, - CONSTRAINT `countryFk_id` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, - CONSTRAINT `supplierAccountFk_id` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +CREATE TABLE `supplierAccount` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `supplierFk` int(11) DEFAULT NULL, + `iban` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `office` varchar(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `DC` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `number` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `description__` varchar(45) DEFAULT NULL COMMENT '@deprecated 2023-03-23', + `bankEntityFk` int(10) unsigned DEFAULT NULL, + `accountingFk` int(11) DEFAULT NULL, + `beneficiary` varchar(50) DEFAULT NULL, + `editorFk` int(10) unsigned DEFAULT NULL, + `countryFk` int(10) unsigned UNIQUE KEY, + `companyFk` int(10) unsigned UNIQUE KEY, + PRIMARY KEY (`id`), + KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), + KEY `fk_Proveedores_account_entity1_idx` (`bankEntityFk`), + KEY `fk_banco_prov_account_idx` (`accountingFk`), + KEY `supplierAccount_fk_editor` (`editorFk`), + CONSTRAINT `supplierAccount_FK` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccount_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccount_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), + CONSTRAINT `supplierAccount_FK_country` FOREIGN KEY (`countryFk`) REFERENCES `vn`.`country` (`id`), + CONSTRAINT `supplierAccount_FK_company` FOREIGN KEY (`companyFk`) REFERENCES `vn`.`company` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=242 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/changes/232801/00-supplierDefault.sql b/db/changes/232801/00-supplierDefault.sql deleted file mode 100644 index c411558f1..000000000 --- a/db/changes/232801/00-supplierDefault.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE vn.supplier ADD defaultAccountFk varchar(100) DEFAULT NULL NULL; From f3a40dfb231f5e23b9535080ffdbae36652753a2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 29 Jun 2023 06:33:50 +0200 Subject: [PATCH 007/116] refs #5525 comment --- db/changes/232801/00-accountCountry.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/232801/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql index d44cdcc4e..9f16b9b00 100644 --- a/db/changes/232801/00-accountCountry.sql +++ b/db/changes/232801/00-accountCountry.sql @@ -10,7 +10,7 @@ CREATE TABLE `supplierAccount` ( `accountingFk` int(11) DEFAULT NULL, `beneficiary` varchar(50) DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, - `countryFk` int(10) unsigned UNIQUE KEY, + `countryFk` int(10) unsigned UNIQUE KEY COMMENT 'Cuenta por defecto para ingresos desde esta empresa', `companyFk` int(10) unsigned UNIQUE KEY, PRIMARY KEY (`id`), KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), From c453935ddd8bc6beb2d0d334f318a6e7e13073d5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 11 Jul 2023 06:38:44 +0200 Subject: [PATCH 008/116] refs #5525 sql --- db/.archive/231001/00-supplier.sql | 3 +++ print/templates/email/letter-debtor-st/letter-debtor-st.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 db/.archive/231001/00-supplier.sql diff --git a/db/.archive/231001/00-supplier.sql b/db/.archive/231001/00-supplier.sql new file mode 100644 index 000000000..fccc35ba3 --- /dev/null +++ b/db/.archive/231001/00-supplier.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`supplierAccount` ADD COLUMN `countryFk` mediumint(8) unsigned NULL; +ALTER TABLE `vn`.`supplierAccount` ADD CONSTRAINT `supplierAccount_fk_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`); +ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.html b/print/templates/email/letter-debtor-st/letter-debtor-st.html index 36f300c98..6679567c0 100644 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.html +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.html @@ -28,4 +28,4 @@ - \ No newline at end of file + From 5b5191a6a5e0bd79666752556de0025d3d06a1d4 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 11 Jul 2023 13:49:39 +0200 Subject: [PATCH 009/116] refs #5525 findOne sql --- .../231001 => changes/233001}/00-supplier.sql | 0 .../email/letter-debtor-st/letter-debtor-st.js | 12 ++++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) rename db/{.archive/231001 => changes/233001}/00-supplier.sql (100%) diff --git a/db/.archive/231001/00-supplier.sql b/db/changes/233001/00-supplier.sql similarity index 100% rename from db/.archive/231001/00-supplier.sql rename to db/changes/233001/00-supplier.sql diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index e0a690f81..5d93116af 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -1,14 +1,18 @@ const Component = require(`vn-print/core/component`); const emailBody = new Component('email-body'); const attachment = new Component('attachment'); +const db = require('../../../core/database'); module.exports = { name: 'letter-debtor-st', async serverPrefetch() { - this.debtor = await this.fetchDebtor(this.id, this.companyId); - - if (!this.debtor) - throw new Error('Something went wrong'); + this.debtor = await db.findOne(` + SELECT sa.iban, be.name bankName + FROM supplierAccount sa + LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + [this.id]); }, data() { return { From cc6ffff018842fc4c28539b4ba1e437ff8ce44ab Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 19 Jul 2023 07:14:01 +0200 Subject: [PATCH 010/116] refs #5525 nd debtor --- db/changes/232801/00-accountCountry.sql | 25 ------------------- .../letter-debtor-nd/letter-debtor-nd.js | 12 ++++++--- 2 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 db/changes/232801/00-accountCountry.sql diff --git a/db/changes/232801/00-accountCountry.sql b/db/changes/232801/00-accountCountry.sql deleted file mode 100644 index 9f16b9b00..000000000 --- a/db/changes/232801/00-accountCountry.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE TABLE `supplierAccount` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `supplierFk` int(11) DEFAULT NULL, - `iban` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `office` varchar(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `DC` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `number` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `description__` varchar(45) DEFAULT NULL COMMENT '@deprecated 2023-03-23', - `bankEntityFk` int(10) unsigned DEFAULT NULL, - `accountingFk` int(11) DEFAULT NULL, - `beneficiary` varchar(50) DEFAULT NULL, - `editorFk` int(10) unsigned DEFAULT NULL, - `countryFk` int(10) unsigned UNIQUE KEY COMMENT 'Cuenta por defecto para ingresos desde esta empresa', - `companyFk` int(10) unsigned UNIQUE KEY, - PRIMARY KEY (`id`), - KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), - KEY `fk_Proveedores_account_entity1_idx` (`bankEntityFk`), - KEY `fk_banco_prov_account_idx` (`accountingFk`), - KEY `supplierAccount_fk_editor` (`editorFk`), - CONSTRAINT `supplierAccount_FK` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, - CONSTRAINT `supplierAccount_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, - CONSTRAINT `supplierAccount_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), - CONSTRAINT `supplierAccount_FK_country` FOREIGN KEY (`countryFk`) REFERENCES `vn`.`country` (`id`), - CONSTRAINT `supplierAccount_FK_company` FOREIGN KEY (`companyFk`) REFERENCES `vn`.`company` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=242 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index 54ed9fed6..2f4a25cfe 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -1,14 +1,18 @@ const Component = require(`vn-print/core/component`); const emailBody = new Component('email-body'); const attachment = new Component('attachment'); +const db = require('../../../core/database'); module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { - this.debtor = await this.fetchDebtor(this.id, this.companyId); - - if (!this.debtor) - throw new Error('Something went wrong'); + this.debtor = await db.findOne(` + SELECT sa.iban, be.name bankName + FROM supplierAccount sa + LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + [this.id]); }, data() { return { From 2f9979046d66725ea9a33dc10ba489324e82df51 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 26 Jul 2023 13:10:18 +0200 Subject: [PATCH 011/116] refs #5525 iban --- .../templates/reports/sepa-core/sepa-core.html | 2 +- print/templates/reports/sepa-core/sepa-core.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index defbdb110..1b2ad13d9 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -28,7 +28,7 @@ {{$t('supplier.identifier')}}
{{$t('supplier.iban')}}
-
{{$t('supplier.cif')}}
+
{{supplier.nif}}
diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index 2198984f3..efc9ed7ed 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -1,10 +1,6 @@ const vnReport = require('../../../core/mixins/vn-report.js'); +const db = require('../../../core/database'); -// class Controller { -// constructor(country, supplier, iban, cif) { -// this.country = countryFk; -// } -// } module.exports = { name: 'sepa-core', mixins: [vnReport], @@ -12,6 +8,7 @@ module.exports = { this.client = await this.findOneFromDef('client', [this.companyId, this.companyId, this.id]); this.checkMainEntity(this.client); this.supplier = await this.findOneFromDef('supplier', [this.companyId, this.companyId, this.id]); + console.log(this.supplier); }, props: { id: { @@ -23,5 +20,16 @@ module.exports = { type: Number, required: true } + }, + methods: { + getSupplierCif() { + return db.findOne(` + SELECT sa.iban, s.nif + FROM supplierAccount sa + INNER JOIN supplier s ON sa.supplierFk = s.id + WHERE s.countryFk = ? + LIMIT 1`), [this.countryFk]; + } } + }; From 344b5d984a3de6fe2484ffa5dc629c1ddaa2e99e Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 27 Jul 2023 17:19:44 +0200 Subject: [PATCH 012/116] refs #5525 add nif iban --- .../reports/sepa-core/sepa-core.html | 2 +- .../reports/sepa-core/sql/supplier.sql | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index 1b2ad13d9..363ebdfe5 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -27,7 +27,7 @@ {{$t('supplier.identifier')}} -
{{$t('supplier.iban')}}
+
{{supplier.iban}}
{{supplier.nif}}
diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index 55b0e49ca..d93175118 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -1,17 +1,24 @@ SELECT - m.code mandateCode, - s.name, - s.street, - sc.country, - s.postCode, - s.city, - sp.name province -FROM client c - LEFT JOIN mandate m ON m.clientFk = c.id - AND m.companyFk = ? AND m.finished IS NULL + m.code AS mandateCode, + s.name, + s.street, + sc.country, + s.postCode, + s.city, + sp.name AS province, + s.nif, + sa.iban, + be.name AS bankName +FROM + client c + LEFT JOIN mandate m ON m.clientFk = c.id AND m.companyFk = ? AND m.finished IS NULL LEFT JOIN supplier s ON s.id = m.companyFk LEFT JOIN country sc ON sc.id = s.countryFk LEFT JOIN province sp ON sp.id = s.provinceFk LEFT JOIN province p ON p.id = c.provinceFk -WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ? -ORDER BY m.created DESC LIMIT 1 \ No newline at end of file + LEFT JOIN bankEntity be ON sa.supplierFk = s.id + LEFT JOIN supplierAccount sa ON sa.bankEntityFk = be.id + WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk) + ORDER BY + m.created DESC + LIMIT 1; From 5664ec3a8f97935e098a49d434d8ba46d5b53c99 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 31 Aug 2023 17:23:01 +0200 Subject: [PATCH 013/116] refs #5525 change supplier --- db/changes/{233001 => 233801}/00-supplier.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{233001 => 233801}/00-supplier.sql (100%) diff --git a/db/changes/233001/00-supplier.sql b/db/changes/233801/00-supplier.sql similarity index 100% rename from db/changes/233001/00-supplier.sql rename to db/changes/233801/00-supplier.sql From 8678d2b1e0d451913f2d55c043c951860d854e13 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Sep 2023 17:23:31 +0200 Subject: [PATCH 014/116] refs #5525 new sql --- .../email/letter-debtor-nd/letter-debtor-nd.html | 2 +- .../templates/email/letter-debtor-st/letter-debtor-st.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html index 44a34a9b4..01bab7939 100644 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html @@ -45,4 +45,4 @@ - \ No newline at end of file + diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 5d93116af..478249b80 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,11 +7,10 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, be.name bankName - FROM supplierAccount sa - LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + SELECT sa.iban FROM client c + LEFT JOIN supplierAccount sa ON c.countryFk = sa.countryFk + WHERE c.id = ? + OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, [this.id]); }, data() { From d26a73bdd98b2b3954214bde040ae508ce7834b9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Sep 2023 11:02:47 +0200 Subject: [PATCH 015/116] refs #5525 sql correct --- db/changes/233801/00-supplier.sql | 4 ++++ .../templates/email/letter-debtor-st/letter-debtor-st.js | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/db/changes/233801/00-supplier.sql b/db/changes/233801/00-supplier.sql index fccc35ba3..5708749fd 100644 --- a/db/changes/233801/00-supplier.sql +++ b/db/changes/233801/00-supplier.sql @@ -1,3 +1,7 @@ ALTER TABLE `vn`.`supplierAccount` ADD COLUMN `countryFk` mediumint(8) unsigned NULL; + + + ALTER TABLE `vn`.`supplierAccount` ADD CONSTRAINT `supplierAccount_fk_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`); ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; +d diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 478249b80..5d0a11baf 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,10 +7,11 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban FROM client c - LEFT JOIN supplierAccount sa ON c.countryFk = sa.countryFk - WHERE c.id = ? - OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, + SELECT sa.iban, be.name bankName + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk);`, [this.id]); }, data() { From cdc91e76f56f3306199ac06abf06c572a72c71a2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 14 Sep 2023 10:04:34 +0200 Subject: [PATCH 016/116] refs #5525 supplier sql table i18n --- db/changes/233801/00-supplier.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/db/changes/233801/00-supplier.sql b/db/changes/233801/00-supplier.sql index 5708749fd..ad9ce892c 100644 --- a/db/changes/233801/00-supplier.sql +++ b/db/changes/233801/00-supplier.sql @@ -1,7 +1,9 @@ -ALTER TABLE `vn`.`supplierAccount` ADD COLUMN `countryFk` mediumint(8) unsigned NULL; - - - -ALTER TABLE `vn`.`supplierAccount` ADD CONSTRAINT `supplierAccount_fk_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`); ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; -d + +CREATE TABLE `vn`.`supplierAccountI18n` ( + supplierAccountFk int(10) unsigned NOT NULL, + countryFk mediumint(8) unsigned NOT NULL, + FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id), + FOREIGN KEY (countryFk) REFERENCES country(id) +); + From f4ac6f68c09cf839c7df52dfbe1061ab6e1bcda6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 20 Sep 2023 13:03:49 +0200 Subject: [PATCH 017/116] refs #5525 trad en --- .../email/letter-debtor-nd/locale/en.yml | 21 +++++++++++++++++++ .../email/letter-debtor-st/locale/en.yml | 11 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 print/templates/email/letter-debtor-nd/locale/en.yml create mode 100644 print/templates/email/letter-debtor-st/locale/en.yml diff --git a/print/templates/email/letter-debtor-nd/locale/en.yml b/print/templates/email/letter-debtor-nd/locale/en.yml new file mode 100644 index 000000000..34b1c7b5f --- /dev/null +++ b/print/templates/email/letter-debtor-nd/locale/en.yml @@ -0,0 +1,21 @@ +subject: Reminder of Outstanding Balance Notice +title: Reminder Notice +sections: + introduction: + title: Dear Customer + description: We are writing to you once again to inform you that your debt with our company remains unpaid, as you can verify in the attached statement. + terms: Since the agreed payment deadlines have significantly passed, there should be no further delay in settling the outstanding amount. + payMethod: + description: To do so, you have the following payment options: + options: + - Online payment through our website. + - Deposit or transfer to the account number provided at the bottom of this letter, indicating your customer number. + legalAction: + description: If this payment reminder is not heeded, we will be compelled to initiate the necessary legal actions, which may include: + options: + - Inclusion in negative credit and financial solvency records. + - Legal proceedings. + - Debt assignment to a debt collection agency. +contactPhone: For inquiries, you can reach us at 96 324 21 00. +conclusion: We look forward to hearing from you.
Thank you for your attention. +transferAccount: Bank Transfer Details diff --git a/print/templates/email/letter-debtor-st/locale/en.yml b/print/templates/email/letter-debtor-st/locale/en.yml new file mode 100644 index 000000000..42b3bb504 --- /dev/null +++ b/print/templates/email/letter-debtor-st/locale/en.yml @@ -0,0 +1,11 @@ +subject: Initial Notice for Outstanding Balance +title: Initial Notice for Outstanding Balance +sections: + introduction: + title: Dear Customer + description: Through this letter, we would like to inform you that, according to our accounting records, your account has an outstanding balance that needs to be settled. +checkExtract: We kindly request you to verify that the attached statement corresponds to the information you have. Our administration department will be happy to clarify any questions you may have and provide any documents you may request. +checkValidData: If, upon reviewing the provided information, everything appears to be accurate, we kindly ask you to proceed with rectifying your situation. +payMethod: If you prefer not to visit our offices in person, you can make the payment through a bank transfer to the account listed at the bottom of this communication, indicating your customer number. Alternatively, you can make the payment online through our website. +conclusion: We sincerely appreciate your kind cooperation. +transferAccount: Bank Transfer Details From a7361a89bd1d6d65a734bed619ec675d71f7d3a0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 27 Nov 2023 12:58:07 +0100 Subject: [PATCH 018/116] refs #6489 remove auth --- back/methods/osticket/sendToSupport.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/back/methods/osticket/sendToSupport.js b/back/methods/osticket/sendToSupport.js index 5b9ebb4e3..135774919 100644 --- a/back/methods/osticket/sendToSupport.js +++ b/back/methods/osticket/sendToSupport.js @@ -35,10 +35,17 @@ module.exports = Self => { let html = `Motivo:
${reason}
`; html += `Usuario:
${ctx.req.accessToken.userId} ${emailUser.email}
`; + delete additionalData.backError.config.headers.Authorization; + const httpRequest = JSON.parse(additionalData?.httpRequest); + + if (httpRequest) + delete httpRequest.config.headers.Authorization; + additionalData.httpRequest = httpRequest; + for (const data in additionalData) html += `${data}:
${tryParse(additionalData[data])}
`; - const subjectReason = JSON.parse(additionalData?.httpRequest)?.data?.error; + const subjectReason = httpRequest?.data?.error; smtp.send({ to: `${config.app.reportEmail}, ${emailUser.email}`, subject: From 920b38c9294af25055c3081060166280b6de89dc Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 7 Dec 2023 09:49:15 +0100 Subject: [PATCH 019/116] refs #5525 move sql --- db/changes/{233801 => 235001}/00-supplier.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename db/changes/{233801 => 235001}/00-supplier.sql (87%) diff --git a/db/changes/233801/00-supplier.sql b/db/changes/235001/00-supplier.sql similarity index 87% rename from db/changes/233801/00-supplier.sql rename to db/changes/235001/00-supplier.sql index ad9ce892c..eebd8b4f2 100644 --- a/db/changes/233801/00-supplier.sql +++ b/db/changes/235001/00-supplier.sql @@ -1,7 +1,8 @@ ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; + CREATE TABLE `vn`.`supplierAccountI18n` ( - supplierAccountFk int(10) unsigned NOT NULL, + supplierAccountFk mediumint(8) unsigned NOT NULL, countryFk mediumint(8) unsigned NOT NULL, FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id), FOREIGN KEY (countryFk) REFERENCES country(id) From a8dfe8f3bfb9dc4ef8f7d1965b8b628fc81eeb2c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Dec 2023 14:53:29 +0100 Subject: [PATCH 020/116] refs #2687 feat: modify vn.travel_cloneWithEntries --- ...pdate_procedure_TravelCloneWithEntries.sql | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql diff --git a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql new file mode 100644 index 000000000..85be8ca93 --- /dev/null +++ b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql @@ -0,0 +1,88 @@ +DROP PROCEDURE IF EXISTS vn.travel_cloneWithEntries; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`( + IN vTravelFk INT, + IN vDateStart DATE, + IN vDateEnd DATE, + IN vWarehouseOutFk INT, + IN vWarehouseInFk INT, + IN vRef VARCHAR(255), + IN vAgencyModeFk INT, + IN vTx BOOL, + OUT vNewTravelFk INT) +BEGIN +/** + * Clona un travel junto con sus entradas y compras + * @param vTravelFk travel plantilla a clonar + * @param vDateStart fecha del shipment del nuevo travel + * @param vDateEnd fecha del landing del nuevo travel + * @param vWarehouseOutFk fecha del salida del nuevo travel + * @param vWarehouseInFk warehouse de landing del nuevo travel + * @param vRef referencia del nuevo travel + * @param vAgencyModeFk del nuevo travel + * @param vNewTravelFk id del nuevo travel + */ + DECLARE vNewEntryFk INT; + DECLARE vEvaNotes VARCHAR(255); + DECLARE vDone BOOL; + DECLARE vAuxEntryFk INT; + DECLARE vTx BOOLEAN DEFAULT !@@in_transaction; + DECLARE vRsEntry CURSOR FOR + SELECT e.id + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.travelFk = vTravelFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) + SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk + FROM travel + WHERE id = vTravelFk; + + SET vNewTravelFk = LAST_INSERT_ID(); + + SET vDone = FALSE; + SET @isModeInventory = TRUE; + + OPEN vRsEntry; + + l: LOOP + SET vDone = FALSE; + FETCH vRsEntry INTO vAuxEntryFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL util.tx_start(vTx); + CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); + CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); + CALL util.tx_commit(vTx); + + SELECT evaNotes INTO vEvaNotes + FROM entry + WHERE id = vAuxEntryFk; + + UPDATE entry + SET evaNotes = vEvaNotes + WHERE id = vNewEntryFk; + + END LOOP; + + SET @isModeInventory = FALSE; + CLOSE vRsEntry; + + COMMIT; +END$$ +DELIMITER ; From 64fbbd5dda94c2f6a94dc1f7f79403b24014696f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Dec 2023 14:53:55 +0100 Subject: [PATCH 021/116] refs #2687 feat: new transaction procedure utils --- db/changes/235201/00-util_tx_commit.sql | 12 ++++++++++++ db/changes/235201/00-util_tx_rollback.sql | 12 ++++++++++++ db/changes/235201/00-util_tx_start.sql | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 db/changes/235201/00-util_tx_commit.sql create mode 100644 db/changes/235201/00-util_tx_rollback.sql create mode 100644 db/changes/235201/00-util_tx_start.sql diff --git a/db/changes/235201/00-util_tx_commit.sql b/db/changes/235201/00-util_tx_commit.sql new file mode 100644 index 000000000..036909ed5 --- /dev/null +++ b/db/changes/235201/00-util_tx_commit.sql @@ -0,0 +1,12 @@ +DROP PROCEDURE IF EXISTS util.tx_commit; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) +BEGIN + IF tx THEN + COMMIT; + END IF; +END +$$ +DELIMITER ; diff --git a/db/changes/235201/00-util_tx_rollback.sql b/db/changes/235201/00-util_tx_rollback.sql new file mode 100644 index 000000000..ff27601b8 --- /dev/null +++ b/db/changes/235201/00-util_tx_rollback.sql @@ -0,0 +1,12 @@ +DROP PROCEDURE IF EXISTS util.tx_rollback; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) +BEGIN + IF tx THEN + ROLLBACK; + END IF; +END +$$ +DELIMITER ; diff --git a/db/changes/235201/00-util_tx_start.sql b/db/changes/235201/00-util_tx_start.sql new file mode 100644 index 000000000..ac7c94f27 --- /dev/null +++ b/db/changes/235201/00-util_tx_start.sql @@ -0,0 +1,12 @@ +DROP PROCEDURE IF EXISTS util.tx_start; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) +BEGIN + IF tx THEN + START TRANSACTION; + END IF; +END +$$ +DELIMITER ; From c0d2e0511d7baf426927a9657b8d642e51771ead Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 11 Dec 2023 14:54:12 +0100 Subject: [PATCH 022/116] refs #2687 feat: modify back method --- modules/travel/back/methods/travel/cloneWithEntries.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index 45ebef283..8d0f638cc 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -45,16 +45,17 @@ module.exports = Self => { let stmts = []; let stmt; - + let tx = await Self.beginTransaction({}); stmt = new ParameterizedSQL( - `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [ + `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [ id, started, ended, travel.warehouseOutFk, travel.warehouseInFk, travel.ref, - travel.agencyModeFk + travel.agencyModeFk, + !!tx.id ] ); stmts.push(stmt); From 30dbc8a5871bdf27617af4d7d984ccbaeae321c6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 07:33:08 +0100 Subject: [PATCH 023/116] refs #2687 feat: fix test suite --- .../travel/specs/cloneWithEntries.spec.js | 80 ++++++++++++++----- 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index 0e434e048..ae3ec8c68 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -46,32 +46,72 @@ describe('Travel cloneWithEntries()', () => { // }); it(`should clone the travel and the containing entries`, async() => { - pending('#2687 - Cannot make a data rollback because of the triggers'); + const tx = await models.Travel.beginTransaction({}); const warehouseThree = 3; const agencyModeOne = 1; - const yesterday = Date.vnNew(); - yesterday.setDate(yesterday.getDate() - 1); + try { + // pending('#2687 - Cannot make a data rollback because of the triggers'); - travelBefore = await models.Travel.findById(travelId); - await travelBefore.updateAttributes({ - shipped: yesterday, - landed: yesterday - }); + console.info('TRAVEL_CLONE_WITH_ENTRIES'); + // const yesterday = Date.vnNew(); + // yesterday.setDate(yesterday.getDate() - 1); - newTravelId = await models.Travel.cloneWithEntries(ctx, travelId); - const travelEntries = await models.Entry.find({ - where: { + // travelBefore = await models.Travel.findById(travelId); + // await travelBefore.updateAttributes({ + // shipped: yesterday, + // landed: yesterday + // }); + // const filter = { + // order: 'landed ASC, shipped ASC, travelFk, loadPriority, agencyModeFk, evaNotes', + // }; + // const agencyModeFk_BEFORE = await app.models.Travel.extraCommunityFilter({ + // args: { + // agencyModeFk: 1 + // } + // }, filter); + // const cargoSupplierFk_BEFORE = await app.models.Travel.extraCommunityFilter({ + // args: { + // cargoSupplierFk: 1 + // } + // }, filter); + + const options = {transaction: tx}; + newTravelId = await models.Travel.cloneWithEntries(ctx, travelId, options); + const travelEntries = await models.Entry.find({ + where: { + travelFk: newTravelId + } + }, options); + const newTravel = await models.Travel.findById(travelId, options); + + expect(newTravelId).not.toEqual(travelId); + expect(newTravel.ref).toEqual('fifth travel'); + expect(newTravel.warehouseInFk).toEqual(warehouseThree); + expect(newTravel.warehouseOutFk).toEqual(warehouseThree); + expect(newTravel.agencyModeFk).toEqual(agencyModeOne); + expect(travelEntries.length).toBeGreaterThan(0); + await models.Entry.destroyAll({ travelFk: newTravelId - } - }); + }, options); - const newTravel = await models.Travel.findById(travelId); + // Destroy new travel + await models.Travel.destroyById(newTravelId, options); + // const agencyModeFk_AFTER = await app.models.Travel.extraCommunityFilter({ + // args: { + // agencyModeFk: 1 + // } + // }, filter); + // const cargoSupplierFk_AFTER = await app.models.Travel.extraCommunityFilter({ + // args: { + // cargoSupplierFk: 1 + // } + // }, filter); - expect(newTravelId).not.toEqual(travelId); - expect(newTravel.ref).toEqual('fifth travel'); - expect(newTravel.warehouseInFk).toEqual(warehouseThree); - expect(newTravel.warehouseOutFk).toEqual(warehouseThree); - expect(newTravel.agencyModeFk).toEqual(agencyModeOne); - expect(travelEntries.length).toBeGreaterThan(0); + // expect(agencyModeFk_BEFORE.length).toEqual(agencyModeFk_AFTER.length); + // expect(cargoSupplierFk_BEFORE.length).toEqual(cargoSupplierFk_AFTER.length); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } }); }); From 8bd9becb74a08132f3724476bf3a3dfb2024266e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 07:34:20 +0100 Subject: [PATCH 024/116] refs #2687 feat: remove procedure argument --- ...pdate_procedure_TravelCloneWithEntries.sql | 1 - .../back/methods/travel/cloneWithEntries.js | 115 ++++++++++-------- .../travel/specs/cloneWithEntries.spec.js | 78 ------------ 3 files changed, 62 insertions(+), 132 deletions(-) diff --git a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql index 85be8ca93..fa47881cc 100644 --- a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql +++ b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql @@ -10,7 +10,6 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`( IN vWarehouseInFk INT, IN vRef VARCHAR(255), IN vAgencyModeFk INT, - IN vTx BOOL, OUT vNewTravelFk INT) BEGIN /** diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index 8d0f638cc..1591fb65c 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -11,8 +11,9 @@ module.exports = Self => { type: 'number', required: true, description: 'The original travel id', - http: {source: 'path'} - }], + http: {source: 'path'}, + }, + ], returns: { type: 'object', description: 'The new cloned travel id', @@ -24,62 +25,70 @@ module.exports = Self => { } }); - Self.cloneWithEntries = async(ctx, id) => { - const conn = Self.dataSource.connector; - const travel = await Self.findById(id, { - fields: [ - 'id', - 'shipped', - 'landed', - 'warehouseInFk', - 'warehouseOutFk', - 'agencyModeFk', - 'ref' - ] - }); - const started = Date.vnNew(); - const ended = Date.vnNew(); + Self.cloneWithEntries = async(ctx, id, options) => { + try { + const conn = Self.dataSource.connector; + const myOptions = {}; - if (!travel) - throw new UserError('Travel not found'); + if (typeof options == 'object') + Object.assign(myOptions, options); + const travel = await Self.findById(id, { + fields: [ + 'id', + 'shipped', + 'landed', + 'warehouseInFk', + 'warehouseOutFk', + 'agencyModeFk', + 'ref' + ] + }); + const started = Date.vnNew(); + const ended = Date.vnNew(); - let stmts = []; - let stmt; - let tx = await Self.beginTransaction({}); - stmt = new ParameterizedSQL( - `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [ - id, - started, - ended, - travel.warehouseOutFk, - travel.warehouseInFk, - travel.ref, - travel.agencyModeFk, - !!tx.id - ] - ); - stmts.push(stmt); - const newTravelIndex = stmts.push('SELECT @vTravelFk AS id') - 1; + if (!travel) + throw new UserError('Travel not found'); - const sql = ParameterizedSQL.join(stmts, ';'); - const result = await conn.executeStmt(sql); - const [lastInsert] = result[newTravelIndex]; + let stmts = []; + let stmt; + let tx = options.transaction; + stmt = new ParameterizedSQL( + `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [ + id, + started, + ended, + travel.warehouseOutFk, + travel.warehouseInFk, + travel.ref, + travel.agencyModeFk + ] + ); + stmts.push(stmt); + const newTravelIndex = stmts.push('SELECT @vTravelFk AS id') - 1; - if (!lastInsert.id) - throw new UserError('Unable to clone this travel'); + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql, myOptions); + const [lastInsert] = result[newTravelIndex]; - const newTravel = await Self.findById(lastInsert.id, { - fields: [ - 'id', - 'shipped', - 'landed', - 'warehouseInFk', - 'warehouseOutFk', - 'agencyModeFk', - 'ref' - ] - }); + if (!lastInsert.id) + throw new UserError('Unable to clone this travel'); - return newTravel.id; + const newTravel = await Self.findById(lastInsert.id, { + fields: [ + 'id', + 'shipped', + 'landed', + 'warehouseInFk', + 'warehouseOutFk', + 'agencyModeFk', + 'ref' + ] + }); + + return newTravel.id; + } catch (e) { + if (myOptions.transaction) await myOptions.transaction.rollback(); + throw e; + } }; }; diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index ae3ec8c68..fb8bf3897 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -5,76 +5,12 @@ describe('Travel cloneWithEntries()', () => { const travelId = 5; const currentUserId = 1102; const ctx = {req: {accessToken: {userId: currentUserId}}}; - let travelBefore; let newTravelId; - - // afterAll(async() => { - // try { - // const entries = await models.Entry.find({ - // where: { - // travelFk: newTravelId - // } - // }); - // const entriesId = entries.map(entry => entry.id); - - // // Destroy all entries buys - // await models.Buy.destroyAll({ - // where: { - // entryFk: {inq: entriesId} - // } - // }); - - // // Destroy travel entries - // await models.Entry.destroyAll({ - // where: { - // travelFk: newTravelId - // } - // }); - - // // Destroy new travel - // await models.Travel.destroyById(newTravelId); - - // // Restore original travel shipped & landed - // const travel = await models.Travel.findById(travelId); - // await travel.updateAttributes({ - // shipped: travelBefore.shipped, - // landed: travelBefore.landed - // }); - // } catch (error) { - // console.error(error); - // } - // }); - it(`should clone the travel and the containing entries`, async() => { const tx = await models.Travel.beginTransaction({}); const warehouseThree = 3; const agencyModeOne = 1; try { - // pending('#2687 - Cannot make a data rollback because of the triggers'); - - console.info('TRAVEL_CLONE_WITH_ENTRIES'); - // const yesterday = Date.vnNew(); - // yesterday.setDate(yesterday.getDate() - 1); - - // travelBefore = await models.Travel.findById(travelId); - // await travelBefore.updateAttributes({ - // shipped: yesterday, - // landed: yesterday - // }); - // const filter = { - // order: 'landed ASC, shipped ASC, travelFk, loadPriority, agencyModeFk, evaNotes', - // }; - // const agencyModeFk_BEFORE = await app.models.Travel.extraCommunityFilter({ - // args: { - // agencyModeFk: 1 - // } - // }, filter); - // const cargoSupplierFk_BEFORE = await app.models.Travel.extraCommunityFilter({ - // args: { - // cargoSupplierFk: 1 - // } - // }, filter); - const options = {transaction: tx}; newTravelId = await models.Travel.cloneWithEntries(ctx, travelId, options); const travelEntries = await models.Entry.find({ @@ -94,21 +30,7 @@ describe('Travel cloneWithEntries()', () => { travelFk: newTravelId }, options); - // Destroy new travel await models.Travel.destroyById(newTravelId, options); - // const agencyModeFk_AFTER = await app.models.Travel.extraCommunityFilter({ - // args: { - // agencyModeFk: 1 - // } - // }, filter); - // const cargoSupplierFk_AFTER = await app.models.Travel.extraCommunityFilter({ - // args: { - // cargoSupplierFk: 1 - // } - // }, filter); - - // expect(agencyModeFk_BEFORE.length).toEqual(agencyModeFk_AFTER.length); - // expect(cargoSupplierFk_BEFORE.length).toEqual(cargoSupplierFk_AFTER.length); } catch (e) { if (tx) await tx.rollback(); throw e; From 556b403a5b3ee3a8f8a92846ec43ec2ab2ed134d Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 11:29:50 +0100 Subject: [PATCH 025/116] refs #5525 letter debtor st --- db/changes/235001/00-supplier.sql | 11 ++++---- .../letter-debtor-st/letter-debtor-st.js | 28 +++++++++++++++---- .../email/letter-debtor-st/sql/client.sql | 19 ++++++------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/db/changes/235001/00-supplier.sql b/db/changes/235001/00-supplier.sql index eebd8b4f2..704479130 100644 --- a/db/changes/235001/00-supplier.sql +++ b/db/changes/235001/00-supplier.sql @@ -1,10 +1,9 @@ ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; -CREATE TABLE `vn`.`supplierAccountI18n` ( - supplierAccountFk mediumint(8) unsigned NOT NULL, - countryFk mediumint(8) unsigned NOT NULL, - FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id), - FOREIGN KEY (countryFk) REFERENCES country(id) -); +ALTER TABLE `vn`.`supplierAccount` +ADD COLUMN `countryFk` mediumint(8) unsigned DEFAULT NULL, +ADD CONSTRAINT `fk_supplierAccount_country` + FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE; + diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 5d0a11baf..76df43d70 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,12 +7,28 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, be.name bankName - FROM supplierAccount sa - JOIN bankEntity be ON sa.bankEntityFk = be.id - JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk);`, - [this.id]); + SELECT sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? + ORDER BY co.id DESC + LIMIT 1; + `, [this.id]); + if (!this.debtor.length) { + this.debtor = await db.findOne(` + SELECT sa.iban, + be.name bankName + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + JOIN company co ON co.supplierAccountFk = sa.id + WHERE co.code = ?; + `, [this.companyCode]); + } }, data() { return { diff --git a/print/templates/email/letter-debtor-st/sql/client.sql b/print/templates/email/letter-debtor-st/sql/client.sql index d5da5d0d5..013a3b7d6 100644 --- a/print/templates/email/letter-debtor-st/sql/client.sql +++ b/print/templates/email/letter-debtor-st/sql/client.sql @@ -1,10 +1,9 @@ -SELECT - c.dueDay, - c.iban, - sa.iban, - be.name AS bankName -FROM client c - JOIN company AS cny - JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk - JOIN bankEntity be ON be.id = sa.bankEntityFk -WHERE c.id = ? AND cny.id = ? \ No newline at end of file +SELECT c.dueDay, + sa.iban, + be.name bankName + FROM client c + JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk + JOIN bankEntity be ON be.id = sa.bankEntityFk + JOIN company cny + WHERE c.id = ? + AND cny.id = ? From ea31d3bebb71923242cbf0ddf0818827ce65c9ba Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 11:46:48 +0100 Subject: [PATCH 026/116] refs #5525 debtor-nd --- .../letter-debtor-nd/letter-debtor-nd.js | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index 2f4a25cfe..781cd21f4 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -7,12 +7,28 @@ module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, be.name bankName - FROM supplierAccount sa - LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)`, - [this.id]); + SELECT sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + LEFT JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ? + ORDER BY co.id DESC + LIMIT 1; + `, [this.id]); + if (!this.debtor.length) { + this.debtor = await db.findOne(` + SELECT sa.iban, + be.name bankName + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + JOIN company co ON co.supplierAccountFk = sa.id + WHERE co.code = ?; + `, [this.companyCode]); + } }, data() { return { From d9ffdaf855891aaa3228b693703b90a10bf0f9ee Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 14 Dec 2023 16:00:29 +0100 Subject: [PATCH 027/116] refs #2687 test: use tx.rollback() --- ...pdate_procedure_TravelCloneWithEntries.sql | 19 ++++++++++----- .../back/methods/travel/cloneWithEntries.js | 24 ++++++++++++------- .../travel/specs/cloneWithEntries.spec.js | 24 ++++++++++++------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql index fa47881cc..54772d768 100644 --- a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql +++ b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql @@ -10,7 +10,8 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`( IN vWarehouseInFk INT, IN vRef VARCHAR(255), IN vAgencyModeFk INT, - OUT vNewTravelFk INT) + OUT vNewTravelFk INT, + OUT vXTx BOOLEAN ) BEGIN /** * Clona un travel junto con sus entradas y compras @@ -38,11 +39,12 @@ BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vTx); RESIGNAL; END; - START TRANSACTION; + -- START TRANSACTION; + CALL util.tx_start(vTx); INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk @@ -64,10 +66,13 @@ BEGIN LEAVE l; END IF; - CALL util.tx_start(vTx); + -- CALL util.tx_start(vTx); CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); + -- CALL util.tx_commit(vTx); + -- CALL util.tx_start(vTx); CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); - CALL util.tx_commit(vTx); +-- CALL util.tx_commit(vTx); + SELECT evaNotes INTO vEvaNotes FROM entry @@ -82,6 +87,8 @@ BEGIN SET @isModeInventory = FALSE; CLOSE vRsEntry; - COMMIT; + -- COMMIT; + SET vXTx = vTx; + CALL util.tx_commit(vTx); END$$ DELIMITER ; diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index 1591fb65c..998e8e3d4 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -1,6 +1,5 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const UserError = require('vn-loopback/util/user-error'); -const loggable = require('vn-loopback/util/log'); module.exports = Self => { Self.remoteMethodCtx('cloneWithEntries', { @@ -26,12 +25,19 @@ module.exports = Self => { }); Self.cloneWithEntries = async(ctx, id, options) => { + const conn = Self.dataSource.connector; + const myOptions = {}; + let tx = options?.transaction; try { - const conn = Self.dataSource.connector; - const myOptions = {}; - if (typeof options == 'object') Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + if (myOptions.transaction !== tx) + throw new Error('transaction ID not match'); const travel = await Self.findById(id, { fields: [ 'id', @@ -51,9 +57,8 @@ module.exports = Self => { let stmts = []; let stmt; - let tx = options.transaction; stmt = new ParameterizedSQL( - `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [ + `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk, @vNewTx)`, [ id, started, ended, @@ -68,6 +73,8 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); + // if (tx) await tx.commit(); + const [lastInsert] = result[newTravelIndex]; if (!lastInsert.id) @@ -83,11 +90,10 @@ module.exports = Self => { 'agencyModeFk', 'ref' ] - }); - + }, myOptions); return newTravel.id; } catch (e) { - if (myOptions.transaction) await myOptions.transaction.rollback(); + if (tx) await tx.rollback(); throw e; } }; diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index fb8bf3897..82ea588e7 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -1,13 +1,14 @@ const app = require('vn-loopback/server/server'); -describe('Travel cloneWithEntries()', () => { +fdescribe('Travel cloneWithEntries()', () => { const models = app.models; const travelId = 5; const currentUserId = 1102; const ctx = {req: {accessToken: {userId: currentUserId}}}; let newTravelId; it(`should clone the travel and the containing entries`, async() => { - const tx = await models.Travel.beginTransaction({}); + const tx = await models.Travel.beginTransaction({ + }); const warehouseThree = 3; const agencyModeOne = 1; try { @@ -18,19 +19,26 @@ describe('Travel cloneWithEntries()', () => { travelFk: newTravelId } }, options); - const newTravel = await models.Travel.findById(travelId, options); + const newTravel = await models.Travel.findById(travelId); expect(newTravelId).not.toEqual(travelId); + expect(newTravel.ref).toEqual('fifth travel'); expect(newTravel.warehouseInFk).toEqual(warehouseThree); expect(newTravel.warehouseOutFk).toEqual(warehouseThree); expect(newTravel.agencyModeFk).toEqual(agencyModeOne); - expect(travelEntries.length).toBeGreaterThan(0); - await models.Entry.destroyAll({ - travelFk: newTravelId - }, options); - await models.Travel.destroyById(newTravelId, options); + expect(travelEntries.length).toBeGreaterThan(0); + await tx.rollback(); + const travelRemoved = await models.Travel.findById(newTravelId, options); + + expect(travelRemoved).toBeNull(); + + // await models.Entry.destroyAll({ + // travelFk: newTravelId + // }, options); + + // await models.Travel.destroyById(newTravelId, options); } catch (e) { if (tx) await tx.rollback(); throw e; From b5b58faee4a58d14ee2ae4509fa9a401433692d1 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 15 Dec 2023 07:34:37 +0100 Subject: [PATCH 028/116] refs #2687 perf: remove comments --- ...-update_procedure_TravelCloneWithEntries.sql | 17 ++++------------- .../back/methods/travel/cloneWithEntries.js | 8 +++----- .../travel/specs/cloneWithEntries.spec.js | 9 +-------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql index 54772d768..7d04096e3 100644 --- a/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql +++ b/db/changes/235201/00-update_procedure_TravelCloneWithEntries.sql @@ -10,8 +10,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`( IN vWarehouseInFk INT, IN vRef VARCHAR(255), IN vAgencyModeFk INT, - OUT vNewTravelFk INT, - OUT vXTx BOOLEAN ) + OUT vNewTravelFk INT) BEGIN /** * Clona un travel junto con sus entradas y compras @@ -43,8 +42,7 @@ BEGIN RESIGNAL; END; - -- START TRANSACTION; - CALL util.tx_start(vTx); + CALL util.tx_start(vTx); INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk @@ -66,13 +64,8 @@ BEGIN LEAVE l; END IF; - -- CALL util.tx_start(vTx); - CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); - -- CALL util.tx_commit(vTx); - -- CALL util.tx_start(vTx); - CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); --- CALL util.tx_commit(vTx); - + CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); + CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); SELECT evaNotes INTO vEvaNotes FROM entry @@ -87,8 +80,6 @@ BEGIN SET @isModeInventory = FALSE; CLOSE vRsEntry; - -- COMMIT; - SET vXTx = vTx; CALL util.tx_commit(vTx); END$$ DELIMITER ; diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index 998e8e3d4..e5eb0b06c 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -28,6 +28,7 @@ module.exports = Self => { const conn = Self.dataSource.connector; const myOptions = {}; let tx = options?.transaction; + try { if (typeof options == 'object') Object.assign(myOptions, options); @@ -36,8 +37,7 @@ module.exports = Self => { tx = await Self.beginTransaction({}); myOptions.transaction = tx; } - if (myOptions.transaction !== tx) - throw new Error('transaction ID not match'); + const travel = await Self.findById(id, { fields: [ 'id', @@ -58,7 +58,7 @@ module.exports = Self => { let stmts = []; let stmt; stmt = new ParameterizedSQL( - `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk, @vNewTx)`, [ + `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [ id, started, ended, @@ -73,8 +73,6 @@ module.exports = Self => { const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); - // if (tx) await tx.commit(); - const [lastInsert] = result[newTravelIndex]; if (!lastInsert.id) diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index 82ea588e7..9e14bdd3b 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -22,23 +22,16 @@ fdescribe('Travel cloneWithEntries()', () => { const newTravel = await models.Travel.findById(travelId); expect(newTravelId).not.toEqual(travelId); - expect(newTravel.ref).toEqual('fifth travel'); expect(newTravel.warehouseInFk).toEqual(warehouseThree); expect(newTravel.warehouseOutFk).toEqual(warehouseThree); expect(newTravel.agencyModeFk).toEqual(agencyModeOne); - expect(travelEntries.length).toBeGreaterThan(0); + await tx.rollback(); const travelRemoved = await models.Travel.findById(newTravelId, options); expect(travelRemoved).toBeNull(); - - // await models.Entry.destroyAll({ - // travelFk: newTravelId - // }, options); - - // await models.Travel.destroyById(newTravelId, options); } catch (e) { if (tx) await tx.rollback(); throw e; From 98a98e0d9ef46a278ea203ab336f01fccf4bb9b9 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 15 Dec 2023 07:40:31 +0100 Subject: [PATCH 029/116] refs #2687 perf: remove force test --- .../travel/back/methods/travel/specs/cloneWithEntries.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index 9e14bdd3b..74ec10155 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); -fdescribe('Travel cloneWithEntries()', () => { +describe('Travel cloneWithEntries()', () => { const models = app.models; const travelId = 5; const currentUserId = 1102; From 18e87a05c44ec4cc1dc7f344b016a8b4216dd69c Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 19 Dec 2023 10:07:17 +0100 Subject: [PATCH 030/116] refs #5525 st and nd --- db/changes/235001/00-supplier.sql | 3 +++ .../letter-debtor-nd/letter-debtor-nd.js | 27 +++++++++---------- .../email/letter-debtor-nd/locale/en.yml | 4 +-- .../email/letter-debtor-nd/sql/client.sql | 19 +++++++------ .../letter-debtor-st/letter-debtor-st.js | 27 +++++++++---------- .../templates/reports/sepa-core/locale/es.yml | 4 +-- .../templates/reports/sepa-core/locale/fr.yml | 16 +++++------ 7 files changed, 48 insertions(+), 52 deletions(-) diff --git a/db/changes/235001/00-supplier.sql b/db/changes/235001/00-supplier.sql index 704479130..e60707eca 100644 --- a/db/changes/235001/00-supplier.sql +++ b/db/changes/235001/00-supplier.sql @@ -6,4 +6,7 @@ ADD COLUMN `countryFk` mediumint(8) unsigned DEFAULT NULL, ADD CONSTRAINT `fk_supplierAccount_country` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE; +ALTER TABLE `vn`.`supplierAccount` +ADD UNIQUE KEY `uk_supplier_country` (`supplierFk`, `countryFk`); + diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js index 781cd21f4..41b6f1af8 100755 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.js +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.js @@ -7,27 +7,26 @@ module.exports = { name: 'letter-debtor-nd', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, - be.name bankName, - sa.countryFk, - c.countryFk - FROM supplierAccount sa - JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN company co ON co.supplierAccountFk = sa.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? - ORDER BY co.id DESC - LIMIT 1; + SELECT sa.id, + sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ?; `, [this.id]); - if (!this.debtor.length) { + if (!this.debtor) { this.debtor = await db.findOne(` SELECT sa.iban, be.name bankName FROM supplierAccount sa JOIN bankEntity be ON sa.bankEntityFk = be.id JOIN company co ON co.supplierAccountFk = sa.id - WHERE co.code = ?; - `, [this.companyCode]); + WHERE co.id = ?; + `, [this.companyId]); } }, data() { diff --git a/print/templates/email/letter-debtor-nd/locale/en.yml b/print/templates/email/letter-debtor-nd/locale/en.yml index 34b1c7b5f..9fb334339 100644 --- a/print/templates/email/letter-debtor-nd/locale/en.yml +++ b/print/templates/email/letter-debtor-nd/locale/en.yml @@ -6,12 +6,12 @@ sections: description: We are writing to you once again to inform you that your debt with our company remains unpaid, as you can verify in the attached statement. terms: Since the agreed payment deadlines have significantly passed, there should be no further delay in settling the outstanding amount. payMethod: - description: To do so, you have the following payment options: + description: To do so, you have the following payment options options: - Online payment through our website. - Deposit or transfer to the account number provided at the bottom of this letter, indicating your customer number. legalAction: - description: If this payment reminder is not heeded, we will be compelled to initiate the necessary legal actions, which may include: + description: If this payment reminder is not heeded, we will be compelled to initiate the necessary legal actions, which may include options: - Inclusion in negative credit and financial solvency records. - Legal proceedings. diff --git a/print/templates/email/letter-debtor-nd/sql/client.sql b/print/templates/email/letter-debtor-nd/sql/client.sql index d5da5d0d5..013a3b7d6 100644 --- a/print/templates/email/letter-debtor-nd/sql/client.sql +++ b/print/templates/email/letter-debtor-nd/sql/client.sql @@ -1,10 +1,9 @@ -SELECT - c.dueDay, - c.iban, - sa.iban, - be.name AS bankName -FROM client c - JOIN company AS cny - JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk - JOIN bankEntity be ON be.id = sa.bankEntityFk -WHERE c.id = ? AND cny.id = ? \ No newline at end of file +SELECT c.dueDay, + sa.iban, + be.name bankName + FROM client c + JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk + JOIN bankEntity be ON be.id = sa.bankEntityFk + JOIN company cny + WHERE c.id = ? + AND cny.id = ? diff --git a/print/templates/email/letter-debtor-st/letter-debtor-st.js b/print/templates/email/letter-debtor-st/letter-debtor-st.js index 76df43d70..b168f969f 100755 --- a/print/templates/email/letter-debtor-st/letter-debtor-st.js +++ b/print/templates/email/letter-debtor-st/letter-debtor-st.js @@ -7,27 +7,26 @@ module.exports = { name: 'letter-debtor-st', async serverPrefetch() { this.debtor = await db.findOne(` - SELECT sa.iban, - be.name bankName, - sa.countryFk, - c.countryFk - FROM supplierAccount sa - JOIN bankEntity be ON sa.bankEntityFk = be.id - LEFT JOIN company co ON co.supplierAccountFk = sa.id - LEFT JOIN client c ON c.countryFk = sa.countryFk - WHERE c.id = ? - ORDER BY co.id DESC - LIMIT 1; + SELECT sa.id, + sa.iban, + be.name bankName, + sa.countryFk, + c.countryFk + FROM supplierAccount sa + JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN company co ON co.supplierAccountFk = sa.id + JOIN client c ON c.countryFk = sa.countryFk + WHERE c.id = ?; `, [this.id]); - if (!this.debtor.length) { + if (!this.debtor) { this.debtor = await db.findOne(` SELECT sa.iban, be.name bankName FROM supplierAccount sa JOIN bankEntity be ON sa.bankEntityFk = be.id JOIN company co ON co.supplierAccountFk = sa.id - WHERE co.code = ?; - `, [this.companyCode]); + WHERE co.id = ?; + `, [this.companyId]); } }, data() { diff --git a/print/templates/reports/sepa-core/locale/es.yml b/print/templates/reports/sepa-core/locale/es.yml index ebb8dce1a..2737dc313 100644 --- a/print/templates/reports/sepa-core/locale/es.yml +++ b/print/templates/reports/sepa-core/locale/es.yml @@ -17,8 +17,6 @@ supplier: toCompleteBySupplier: A cumplimentar por el acreedor orderReference: Referencia de la orden de domiciliación identifier: Identificador del acreedor - iban: ES89000B97367486 - cif: B97367486-000 name: Nombre del acreedor street: Dirección location: CP - Población - Provincia @@ -47,4 +45,4 @@ instructions: title: Instrucciones accountFields: Rellenar los campos relativos a la cuenta bancaria signDocument: Firmar y sellar el documento. Para que tenga validez, en el sello debe aparecer el CIF/NIF. De no ser así, deberá acompañarse la solicitud de un certificado de titularidad de la cuenta. - thanks: ¡Gracias por su colaboración! \ No newline at end of file + thanks: ¡Gracias por su colaboración! diff --git a/print/templates/reports/sepa-core/locale/fr.yml b/print/templates/reports/sepa-core/locale/fr.yml index 3f39d18d4..355b880a1 100644 --- a/print/templates/reports/sepa-core/locale/fr.yml +++ b/print/templates/reports/sepa-core/locale/fr.yml @@ -1,11 +1,11 @@ reportName: direct-debit title: Direct Debit -description: En signant ce formulaire de mandat, vous autorisez VERDNATURA LEVANTE SL - à envoyer des instructions à votre banque pour débiter votre compte, et (B) votre banque - à débiter votre compte conformément aux instructions de VERDNATURA LEVANTE SL. - Vous bénéficiez d’un droit au remboursement par votre banque selon les conditions décrites - dans la convention que vous avez passée avec elle. Toute demande de remboursement doit être - présentée dans les 8 semaines suivant la date de débit de votre compte. +description: En signant ce formulaire de mandat, vous autorisez VERDNATURA LEVANTE SL + à envoyer des instructions à votre banque pour débiter votre compte, et (B) votre banque + à débiter votre compte conformément aux instructions de VERDNATURA LEVANTE SL. + Vous bénéficiez d’un droit au remboursement par votre banque selon les conditions décrites + dans la convention que vous avez passée avec elle. Toute demande de remboursement doit être + présentée dans les 8 semaines suivant la date de débit de votre compte. Votre banque peut vous renseigner au sujet de vos droits relatifs à ce mandat. documentCopy: Veuillez dater, signer et retourner ce document à votre banque. mandatoryFields: TOUS LES CHAMPS DOIVENT ÊTRE REINSEGNÉS IMPÉRATIVEMENT. @@ -13,8 +13,6 @@ sendOrder: APRÈS SIGNATURA, RENVOYER AU CRÉANCIER ET AU VOTRE ÉTABLISSEMENT F supplier: toCompleteBySupplier: Á compléter pour le créancier orderReference: Numéro de référence du mandat - iban: FR7630003012690002801121597 - cif: B97367486-000 identifier: Identifiant créancier name: Nom du céancier street: Adresse @@ -44,4 +42,4 @@ instructions: title: instructions accountFields: Remplissez les champs relatifs au compte bancaire signDocument: Signez et scellez le document. Pour être valide, le CIF / NIF doit apparaître sur le cachet. Sinon, la demande de certificat de propriété du compte doit être jointe. - thanks: Merci de votre collaboration! \ No newline at end of file + thanks: Merci de votre collaboration! From df1c9e3d9f087d8aa59b8c5f147ad01bddd34e3b Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 27 Dec 2023 17:46:46 +0100 Subject: [PATCH 031/116] refs #5525 suppliercif --- print/templates/reports/sepa-core/sepa-core.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index efc9ed7ed..96c512a9d 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -8,7 +8,6 @@ module.exports = { this.client = await this.findOneFromDef('client', [this.companyId, this.companyId, this.id]); this.checkMainEntity(this.client); this.supplier = await this.findOneFromDef('supplier', [this.companyId, this.companyId, this.id]); - console.log(this.supplier); }, props: { id: { @@ -26,9 +25,9 @@ module.exports = { return db.findOne(` SELECT sa.iban, s.nif FROM supplierAccount sa - INNER JOIN supplier s ON sa.supplierFk = s.id - WHERE s.countryFk = ? - LIMIT 1`), [this.countryFk]; + JOIN company co ON co.supplierAccountFk = sa.id + JOIN supplier s ON sa.supplierFk = s.id + WHERE co.id = ?`) [this.companyId]; } } From bfb31ad7c3f80d56530fed86e48cdfb46f56c4f2 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 28 Dec 2023 11:46:34 +0100 Subject: [PATCH 032/116] refs #5525 supplier --- modules/supplier/back/models/supplier-account.json | 3 +++ print/templates/reports/sepa-core/sql/supplier.sql | 1 + 2 files changed, 4 insertions(+) diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index bc9cf0e24..9f9ad70c5 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -17,6 +17,9 @@ }, "beneficiary": { "type": "string" + }, + "supplierFk": { + "type": "string" } }, "relations": { diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index d93175118..72f950213 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -8,6 +8,7 @@ SELECT sp.name AS province, s.nif, sa.iban, + sa.supplierFk, be.name AS bankName FROM client c From bbf1bb50e978318cb9ea2b8f9692615c49cb5055 Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 28 Dec 2023 13:27:38 +0100 Subject: [PATCH 033/116] refs #5525 fix sql supplier for sepacore --- print/templates/reports/sepa-core/sql/supplier.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index 72f950213..ade4b048e 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -17,9 +17,11 @@ FROM LEFT JOIN country sc ON sc.id = s.countryFk LEFT JOIN province sp ON sp.id = s.provinceFk LEFT JOIN province p ON p.id = c.provinceFk - LEFT JOIN bankEntity be ON sa.supplierFk = s.id - LEFT JOIN supplierAccount sa ON sa.bankEntityFk = be.id - WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk) - ORDER BY - m.created DESC - LIMIT 1; + LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id + LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id +WHERE + (m.companyFk = ? OR m.companyFk IS NULL) + AND (c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)) +ORDER BY + m.created DESC +LIMIT 1; From 9165b921ca3ad360e8a1c3a9751e9bbe22d36782 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jan 2024 13:00:37 +0100 Subject: [PATCH 034/116] refs #2687 perf: change db/changes folder --- .../00-update_procedure_TravelCloneWithEntries.sql | 0 db/changes/{240001 => 240201}/00-util_tx_commit.sql | 0 db/changes/{240001 => 240201}/00-util_tx_rollback.sql | 0 db/changes/{240001 => 240201}/00-util_tx_start.sql | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{240001 => 240201}/00-update_procedure_TravelCloneWithEntries.sql (100%) rename db/changes/{240001 => 240201}/00-util_tx_commit.sql (100%) rename db/changes/{240001 => 240201}/00-util_tx_rollback.sql (100%) rename db/changes/{240001 => 240201}/00-util_tx_start.sql (100%) diff --git a/db/changes/240001/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/240201/00-update_procedure_TravelCloneWithEntries.sql similarity index 100% rename from db/changes/240001/00-update_procedure_TravelCloneWithEntries.sql rename to db/changes/240201/00-update_procedure_TravelCloneWithEntries.sql diff --git a/db/changes/240001/00-util_tx_commit.sql b/db/changes/240201/00-util_tx_commit.sql similarity index 100% rename from db/changes/240001/00-util_tx_commit.sql rename to db/changes/240201/00-util_tx_commit.sql diff --git a/db/changes/240001/00-util_tx_rollback.sql b/db/changes/240201/00-util_tx_rollback.sql similarity index 100% rename from db/changes/240001/00-util_tx_rollback.sql rename to db/changes/240201/00-util_tx_rollback.sql diff --git a/db/changes/240001/00-util_tx_start.sql b/db/changes/240201/00-util_tx_start.sql similarity index 100% rename from db/changes/240001/00-util_tx_start.sql rename to db/changes/240201/00-util_tx_start.sql From cc0c8443bf0c4ff938a6f9a14ed44a3ade04812c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jan 2024 08:06:20 +0100 Subject: [PATCH 035/116] refs #6613 perf: translate message error --- loopback/server/middleware/error-handler.js | 5 +++-- loopback/util/forbiddenError.js | 5 +++-- loopback/util/salixError.js | 5 +++++ loopback/util/user-error.js | 5 +++-- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 loopback/util/salixError.js diff --git a/loopback/server/middleware/error-handler.js b/loopback/server/middleware/error-handler.js index 725826ae7..cc7b81618 100644 --- a/loopback/server/middleware/error-handler.js +++ b/loopback/server/middleware/error-handler.js @@ -1,10 +1,11 @@ +const SalixError = require('../../util/salixError'); const UserError = require('../../util/user-error'); const logToConsole = require('strong-error-handler/lib/logger'); module.exports = function() { return function(err, req, res, next) { // Thrown user errors - if (err instanceof UserError) { + if (err instanceof SalixError) { err.message = req.__(err.message, ...err.translateArgs); return next(err); } @@ -13,7 +14,7 @@ module.exports = function() { if (err.statusCode == 422) { try { let code; - let messages = err.details.messages; + let {messages} = err.details; for (code in messages) break; err.message = req.__(messages[code][0]); return next(err); diff --git a/loopback/util/forbiddenError.js b/loopback/util/forbiddenError.js index 998cb4593..8f6561059 100644 --- a/loopback/util/forbiddenError.js +++ b/loopback/util/forbiddenError.js @@ -1,7 +1,8 @@ -module.exports = class ForbiddenError extends Error { +const SalixError = require('./salixError'); +module.exports = class ForbiddenError extends SalixError { constructor(message, code, ...translateArgs) { super(message); - this.name = 'ForbiddenError'; + this.name = ForbiddenError.name; this.statusCode = 403; this.code = code; this.translateArgs = translateArgs; diff --git a/loopback/util/salixError.js b/loopback/util/salixError.js new file mode 100644 index 000000000..427b871ab --- /dev/null +++ b/loopback/util/salixError.js @@ -0,0 +1,5 @@ +module.exports = class SalixError extends Error { + constructor(message) { + super(message); + } +}; diff --git a/loopback/util/user-error.js b/loopback/util/user-error.js index c2d01e080..feee208b3 100644 --- a/loopback/util/user-error.js +++ b/loopback/util/user-error.js @@ -4,10 +4,11 @@ * the final user, so they cannot contain sensitive data and must * be understandable by people who do not have a technical profile. */ -module.exports = class UserError extends Error { +const SalixError = require('./salixError'); +module.exports = class UserError extends SalixError { constructor(message, code, ...translateArgs) { super(message); - this.name = 'UserError'; + this.name = UserError.name; this.statusCode = 400; this.code = code; this.translateArgs = translateArgs; From ea5483e8476300e65fb3dc059a42bb4250826248 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jan 2024 10:50:37 +0100 Subject: [PATCH 036/116] refs #6222 refactor: sale_calculateComponent --- db/changes/240201/00-saleComponent.sql | 589 ++++++++++++++++++ .../back/methods/ticket/componentUpdate.js | 4 +- .../ticket/specs/componentUpdate.spec.js | 10 +- .../front/basic-data/step-two/index.html | 2 +- .../ticket/front/basic-data/step-two/index.js | 9 +- .../methods/worker-time-control/getClockIn.js | 2 +- 6 files changed, 600 insertions(+), 16 deletions(-) create mode 100644 db/changes/240201/00-saleComponent.sql diff --git a/db/changes/240201/00-saleComponent.sql b/db/changes/240201/00-saleComponent.sql new file mode 100644 index 000000000..44f9d172c --- /dev/null +++ b/db/changes/240201/00-saleComponent.sql @@ -0,0 +1,589 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption VARCHAR(25)) +proc: BEGIN +/** + * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id de la venta + * @param vOption indica en que componente pone el descuadre, NULL en casos habituales + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.id = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) +BEGIN +/** + * Comprueba que las ventas creadas entre un rango de fechas tienen componentes + * + * @param vCreatedFrom inicio del rango + * @param vCreatedTo fin del rango + */ + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vSaleFk INTEGER; + DECLARE vTicketFk INTEGER; + DECLARE vConcept VARCHAR(50); + DECLARE vCur CURSOR FOR + SELECT s.id + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo + AND c.id IS NULL + AND t.agencyModeFk IS NOT NULL + AND t.isDeleted IS FALSE + AND t.warehouseFk = 60 + AND ic.merchandise != FALSE + GROUP BY s.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + CREATE TEMPORARY TABLE tmp.coste + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT s.id + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6 + WHERE s.created >= vCreatedFrom + AND ic.merchandise != FALSE; + + OPEN vCur; + + l: LOOP + SET v_done = FALSE; + FETCH vCur INTO vSaleFk; + + IF v_done THEN + LEAVE l; + END IF; + + SELECT ticketFk, concept + INTO vTicketFk, vConcept + FROM sale + WHERE id = vSaleFk; + + CALL sale_calculateComponent(vSaleFk, 'renewPrices'); + END LOOP; + + CLOSE vCur; + DROP TEMPORARY TABLE tmp.coste; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25)) +proc: BEGIN +/** + * Este procedimiento recalcula los componentes de un conjunto de sales, + * eliminando los componentes existentes e insertandolos de nuevo + * + * @param vOption si no se quiere forzar llamar con NULL + * @table tmp.recalculateSales (id) + */ + DECLARE vShipped DATE; + DECLARE vWarehouseFk SMALLINT; + DECLARE vAgencyModeFk INT; + DECLARE vAddressFk INT; + DECLARE vTicketFk INT; + DECLARE vLanded DATE; + DECLARE vIsEditable BOOLEAN; + DECLARE vZoneFk INTEGER; + DECLARE vDone BOOL DEFAULT FALSE; + + DECLARE vCur CURSOR FOR + SELECT DISTINCT s.ticketFk + FROM tmp.recalculateSales rs + JOIN vn.sale s ON s.id = rs.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCur; + + l: LOOP + SET vDone = FALSE; + FETCH vCur INTO vTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, + t.zoneFk, + t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, + t.landed + INTO vIsEditable, + vZoneFk, + vWarehouseFk, + vShipped, + vAddressFk, + vAgencyModeFk, + vLanded + FROM ticket t + LEFT JOIN ticketState ts ON t.id = ts.ticket + LEFT JOIN alertLevel al ON al.id = ts.alertLevel + WHERE t.id = vTicketFk; + + CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); + + IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN + CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); + END IF; + + IF vLanded IS NULL OR vZoneFk IS NULL THEN + + UPDATE ticket t + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + WHERE t.id = vTicketFk AND t.landed IS NULL; + + IF vZoneFk IS NULL THEN + SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; + UPDATE ticket t + SET t.zoneFk = vZoneFk + WHERE t.id = vTicketFk AND t.zoneFk IS NULL; + END IF; + + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetLanded; + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) ENGINE = MEMORY + SELECT s.id saleFk, vWarehouseFk warehouseFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + WHERE s.ticketFk = vTicketFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY s.itemFk; + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + IF vOption IS NULL THEN + SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); + END IF; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + + DROP TEMPORARY TABLE tmp.buyUltimate; + DROP TEMPORARY TABLE tmp.sale; + + END LOOP; + CLOSE vCur; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) +BEGIN +/* + * Recalcula los componentes un ticket clonado, + * las lineas a precio cero fuerza para que tengan precio, el resto lo respeta + * @param vTicketNew nuevo ticket clonado + * @param vTicketOld icket original, a partir del qual se clonara el nuevo +*/ + + REPLACE INTO orderTicket(orderFk,ticketFk) + SELECT orderFk, vTicketNew + FROM orderTicket + WHERE ticketFk = vTicketOld; + + -- Bionizamos lineas con Preu = 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price = 0; + + CALL sale_recalcComponent('renewPrices'); + + -- Bionizamos lineas con Preu > 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price > 0; + + CALL sale_recalcComponent('imbalance'); + + DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) +BEGIN + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + END IF; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + COMMIT; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) +BEGIN +/** + * A partir de la tabla tmp.sale, crea los Movimientos_componentes + * y modifica el campo Preu de la tabla Movimientos + * + * @param i_option integer tipo de actualizacion + * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk + **/ + DECLARE vComponentFk INT; + + IF vCode <> 'renewPrices' THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; + END IF; + + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN `component` c ON c.id = sc.componentFk + WHERE c.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, tc.cost + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); + + -- Añadir componente venta por paquete + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT t.id, t.componentFk, t.cost + FROM ( + SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN vn.buy b ON b.id = buy_id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + LEFT JOIN ( + SELECT s.id + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk + JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' + ) tp ON tp.id = s.id + WHERE tp.id IS NULL + HAVING resto <> 0) t; + + IF vCode <> 'renewPrices' THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE + UPDATE sale s + JOIN item i on i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.price = sumValue / ((100 - s.discount) / 100) + WHERE it.code != 'PRT' ; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.componentFk != 21 + GROUP BY s.id + HAVING ROUND(saleValue, 4) <> 0; + END IF; + + UPDATE sale s + JOIN ( + SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN `component` c ON c.id = sc.componentFk + JOIN componentType ct on ct.id = c.typeFk AND ct.isBase + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.priceFixed = sumValue, s.isPriceFixed = 1; + + DELETE sc.* + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN sale s on s.id = sc.saleFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT'; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 15, s.price + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN item i ON i.id = s.itemFK + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT' AND s.price > 0; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) +BEGIN + +/** + * Comprueba que los tickets entre un rango de fechas tienen componentes + * y recalcula sus componentes + * + * @param vShippedFrom rango inicial de fecha + * @param vShippedTo rango final de fecha + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.coste + (primary key (id)) ENGINE = MEMORY + SELECT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 + WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo + AND ic.merchandise; + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (primary key (id)) ENGINE = MEMORY + SELECT DISTINCT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo + AND c.id IS NULL + AND ic.merchandise; + + CALL sale_recalcComponent('renewPrices'); + + DROP TEMPORARY TABLE tmp.recalculateSales; + DROP TEMPORARY TABLE tmp.coste; + END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( + vTicketFk INT, + vClientFk INT, + vNickname VARCHAR(50), + vAgencyModeFk INT, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk INT, + vCompanyFk INT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) +BEGIN + + /** + * Modifica en el ticket los campos que se le pasan por parámetro + * y cambia sus componentes + * + * @param vTicketFk Id del ticket a modificar + * @param vClientFk nuevo cliente + * @param vNickname nuevo alias + * @param vAgencyModeFk nueva agencia + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo almacen + * @param vCompanyFk nueva empresa + * @param vShipped nueva fecha del envio de mercancia + * @param vLanded nueva fecha de recepcion de mercancia + * @param vIsDeleted si se borra el ticket + * @param vHasToBeUnrouted si se le elimina la ruta al ticket + * @param vOption opcion para el case del proc ticketComponentUpdateSale + */ + + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + + CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.nickname = vNickname, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.zoneFk = vZoneFk, + t.zonePrice = vPrice, + t.zoneBonus = vBonus, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent + SELECT * FROM tmp.ticketComponentPreview; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + + DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption VARCHAR(25)) +proc: BEGIN + +/** + * Crea tabla temporal para sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id del ticket + * @param vOption si no se quiere forzar llamar con NULL + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.ticketFk = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; + +TRUNCATE TABLE `vn`.`ticketUpdateAction`; +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrice'); +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(2, 'Convertir en maná', 'mana'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 3acd68cfb..0786b72c8 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -74,8 +74,8 @@ module.exports = Self => { }, { arg: 'option', - type: 'number', - description: 'Action id' + type: 'string', + description: 'Action code' }, { arg: 'isWithoutNegatives', diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 40be4161c..c9a13b4cc 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -60,7 +60,7 @@ describe('ticket componentUpdate()', () => { shipped: today, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false }; @@ -110,7 +110,7 @@ describe('ticket componentUpdate()', () => { shipped: today, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false }; @@ -176,7 +176,7 @@ describe('ticket componentUpdate()', () => { shipped: newDate, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: true }; @@ -235,7 +235,7 @@ describe('ticket componentUpdate()', () => { shipped: newDate, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false, keepPrice: true }; @@ -288,7 +288,7 @@ describe('ticket componentUpdate()', () => { shipped: newDate, landed: tomorrow, isDeleted: false, - option: 1, + option: 'renewPrices', isWithoutNegatives: false, keepPrice: false }; diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index fc57a354a..528971154 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -76,7 +76,7 @@ + val={{::action.code}}> diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index 8c8a3a079..9717d1ea4 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -25,12 +25,7 @@ class Controller extends Component { loadDefaultTicketAction() { const isSalesAssistant = this.aclService.hasAny(['salesAssistant']); - const defaultOption = isSalesAssistant ? 'turnInMana' : 'changePrice'; - const filter = {where: {code: defaultOption}}; - - this.$http.get(`TicketUpdateActions`, {filter}).then(response => { - return this.ticket.option = response.data[0].id; - }); + this.ticket.option = isSalesAssistant ? 'mana' : 'buyerDiscount'; } onStepChange() { @@ -112,7 +107,7 @@ class Controller extends Component { shipped: this.ticket.shipped, landed: this.ticket.landed, isDeleted: this.ticket.isDeleted, - option: parseInt(this.ticket.option), + option: this.ticket.option, isWithoutNegatives: this.ticket.withoutNegatives, withWarningAccept: this.ticket.withWarningAccept, keepPrice: false diff --git a/modules/worker/back/methods/worker-time-control/getClockIn.js b/modules/worker/back/methods/worker-time-control/getClockIn.js index 470700643..458cadafb 100644 --- a/modules/worker/back/methods/worker-time-control/getClockIn.js +++ b/modules/worker/back/methods/worker-time-control/getClockIn.js @@ -5,7 +5,7 @@ module.exports = Self => { accepts: [ { arg: 'workerFk', - type: 'int', + type: 'number', required: true, }, From 6236cf062143bc893b04d5f98dfe5b2ec440b6bf Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 12 Jan 2024 16:18:26 +0100 Subject: [PATCH 037/116] hotfix ticketRefund --- modules/ticket/back/methods/sale/clone.js | 71 +++++++++++-------- modules/ticket/back/methods/sale/refund.js | 1 - .../back/methods/sale/specs/refund.spec.js | 57 ++++++++++----- 3 files changed, 79 insertions(+), 50 deletions(-) diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index a5ccb6de4..fd8e31e82 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -14,17 +14,30 @@ module.exports = Self => { } try { - const salesFilter = { - where: {id: {inq: salesIds}}, - include: { - relation: 'components', - scope: { - fields: ['saleFk', 'componentFk', 'value'] + let sales; + let services; + + if (salesIds && salesIds.length) { + sales = await models.Sale.find({ + where: {id: {inq: salesIds}}, + include: { + relation: 'components', + scope: { + fields: ['saleFk', 'componentFk', 'value'] + } } - } - }; - const sales = await models.Sale.find(salesFilter, myOptions); - let ticketsIds = [...new Set(sales.map(sale => sale.ticketFk))]; + }, myOptions); + } + + if (servicesIds && servicesIds.length) { + services = await models.TicketService.find({ + where: {id: {inq: servicesIds}} + }, myOptions); + } + + let ticketsIds = sales ? + [...new Set(sales.map(sale => sale.ticketFk))] : + [...new Set(services.map(service => service.ticketFk))]; const mappedTickets = new Map(); @@ -41,32 +54,28 @@ module.exports = Self => { newTickets.push(newTicket); mappedTickets.set(ticketId, newTicket.id); } + if (sales) { + for (const sale of sales) { + const newTicketId = mappedTickets.get(sale.ticketFk); - for (const sale of sales) { - const newTicketId = mappedTickets.get(sale.ticketFk); + const createdSale = await models.Sale.create({ + ticketFk: newTicketId, + itemFk: sale.itemFk, + quantity: negative ? - sale.quantity : sale.quantity, + concept: sale.concept, + price: sale.price, + discount: sale.discount, + }, myOptions); - const createdSale = await models.Sale.create({ - ticketFk: newTicketId, - itemFk: sale.itemFk, - quantity: negative ? - sale.quantity : sale.quantity, - concept: sale.concept, - price: sale.price, - discount: sale.discount, - }, myOptions); + const components = sale.components(); + for (const component of components) + component.saleFk = createdSale.id; - const components = sale.components(); - for (const component of components) - component.saleFk = createdSale.id; - - await models.SaleComponent.create(components, myOptions); + await models.SaleComponent.create(components, myOptions); + } } - if (servicesIds && servicesIds.length) { - const servicesFilter = { - where: {id: {inq: servicesIds}} - }; - const services = await models.TicketService.find(servicesFilter, myOptions); - + if (services) { for (const service of services) { const newTicketId = mappedTickets.get(service.ticketFk); diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js index a7831e7e3..e1d23001f 100644 --- a/modules/ticket/back/methods/sale/refund.js +++ b/modules/ticket/back/methods/sale/refund.js @@ -6,7 +6,6 @@ module.exports = Self => { { arg: 'salesIds', type: ['number'], - required: true }, { arg: 'servicesIds', diff --git a/modules/ticket/back/methods/sale/specs/refund.spec.js b/modules/ticket/back/methods/sale/specs/refund.spec.js index 60f77e90c..ab5e1e281 100644 --- a/modules/ticket/back/methods/sale/specs/refund.spec.js +++ b/modules/ticket/back/methods/sale/specs/refund.spec.js @@ -44,24 +44,7 @@ describe('Sale refund()', () => { const tickets = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, options); - const refundedTicket = await models.Ticket.findOne({ - where: { - id: tickets[0].id - }, - include: [ - { - relation: 'ticketSales', - scope: { - include: { - relation: 'components' - } - } - }, - { - relation: 'ticketServices', - } - ] - }, options); + const refundedTicket = await getTicketRefund(tickets[0].id, options); const ticketsAfter = await models.Ticket.find({}, options); const salesLength = refundedTicket.ticketSales().length; const componentsLength = refundedTicket.ticketSales()[0].components().length; @@ -77,4 +60,42 @@ describe('Sale refund()', () => { throw e; } }); + + it('should create a ticket without sales', async() => { + const servicesIds = [4]; + const tx = await models.Sale.beginTransaction({}); + const options = {transaction: tx}; + try { + const tickets = await models.Sale.refund(ctx, null, servicesIds, withWarehouse, options); + const refundedTicket = await getTicketRefund(tickets[0].id, options); + + expect(refundedTicket).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); + +async function getTicketRefund(id, options) { + return models.Ticket.findOne({ + where: { + id + }, + include: [ + { + relation: 'ticketSales', + scope: { + include: { + relation: 'components' + } + } + }, + { + relation: 'ticketServices', + } + ] + }, options); +} From c20b9fe212dfbb32db96014733ab8fd7d3c85c9f Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 15 Jan 2024 07:45:40 +0100 Subject: [PATCH 038/116] refs #6656 fix(updateTimeEntry): correct accessType (WRITE) --- .../worker/back/methods/worker-time-control/updateTimeEntry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index 8231be7bb..e9d35f880 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -3,7 +3,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('updateTimeEntry', { description: 'Updates a time entry for a worker if the user role is above the worker', - accessType: 'READ', + accessType: 'WRITE', accepts: [{ arg: 'id', type: 'number', From 107dded4114a6d027a172d5d4ea216df961d13e5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 15 Jan 2024 09:03:56 +0100 Subject: [PATCH 039/116] refs #6296 countryAddress --- modules/client/front/address/index/index.html | 10 +++++----- modules/client/front/address/index/index.js | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/client/front/address/index/index.html b/modules/client/front/address/index/index.html index 8fdfce2bb..989ce13a9 100644 --- a/modules/client/front/address/index/index.html +++ b/modules/client/front/address/index/index.html @@ -42,14 +42,14 @@ translate-attr="{title: 'Set as default'}"> -
{{::address.nickname}} - #{{::address.id}}
{{::address.street}}
- {{::address.postalCode}} - - {{::address.city}}, - {{::address.province.name}} + {{::address.city}}, + {{::address.province.name}}, + {{::address.province.country.country}}
{{::address.phone}}, @@ -72,7 +72,7 @@ class="vn-hide-narrow vn-px-md border-solid-left" style="height: 6em; overflow: auto;"> - {{::observation.observationType.description}}: + {{::observation.observationType.description}}: {{::observation.description}} diff --git a/modules/client/front/address/index/index.js b/modules/client/front/address/index/index.js index 608bbbc20..4bad9d4c8 100644 --- a/modules/client/front/address/index/index.js +++ b/modules/client/front/address/index/index.js @@ -33,7 +33,13 @@ class Controller extends Section { }, { relation: 'province', scope: { - fields: ['id', 'name'] + fields: ['id', 'name', 'countryFk'], + include: { + relation: 'country', + scope: { + fields: ['id', 'country'] + } + } } } ] From be1a94c2838422a2600e9c590a25d853bdadd063 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 15 Jan 2024 09:59:32 +0100 Subject: [PATCH 040/116] feat: refs #6634 Modified collection-label --- .../240401/01-saleGroupDetailDefaultSize.sql | 2 ++ .../reports/collection-label/collection-label.html | 2 +- .../reports/collection-label/collection-label.js | 2 +- .../reports/collection-label/sql/labelsData.sql | 14 +++++++++----- 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 db/changes/240401/01-saleGroupDetailDefaultSize.sql diff --git a/db/changes/240401/01-saleGroupDetailDefaultSize.sql b/db/changes/240401/01-saleGroupDetailDefaultSize.sql new file mode 100644 index 000000000..a1e0537ed --- /dev/null +++ b/db/changes/240401/01-saleGroupDetailDefaultSize.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.productionConfig ADD saleGroupDetailDefaultSize int NULL COMMENT 'Altura por defecto para los artículos de previa'; +UPDATE IGNORE vn.productionConfig SET saleGroupDetailDefaultSize = 40 WHERE id = 1; diff --git a/print/templates/reports/collection-label/collection-label.html b/print/templates/reports/collection-label/collection-label.html index a699d4ac5..a0bfcad0e 100644 --- a/print/templates/reports/collection-label/collection-label.html +++ b/print/templates/reports/collection-label/collection-label.html @@ -15,7 +15,7 @@ {{labelData.workerCode || '---'}} - {{labelCount || labelData.labelCount || 0}} + {{labelData.labelCount || 0}} {{labelData.code == 'V' ? (labelData.size || 0) + 'cm' : (labelData.volume || 0) + 'm³'}} diff --git a/print/templates/reports/collection-label/collection-label.js b/print/templates/reports/collection-label/collection-label.js index d45ecb2bc..cd6ff719a 100644 --- a/print/templates/reports/collection-label/collection-label.js +++ b/print/templates/reports/collection-label/collection-label.js @@ -18,9 +18,9 @@ module.exports = { } }, async serverPrefetch() { + await this.rawSql('SET @hasPrevia := 0'); let ticketIds; const res = await this.rawSqlFromDef('tickets', [this.id]); - if (res.length) { ticketIds = []; for (const row of res) diff --git a/print/templates/reports/collection-label/sql/labelsData.sql b/print/templates/reports/collection-label/sql/labelsData.sql index fef692272..fffa1bb53 100644 --- a/print/templates/reports/collection-label/sql/labelsData.sql +++ b/print/templates/reports/collection-label/sql/labelsData.sql @@ -7,14 +7,16 @@ SELECT c.itemPackingTypeFk code, cc.code color, t.clientFk, CAST(SUM(sv.volume) AS DECIMAL(5, 2)) volume, - MAX(i.`size`) `size`, + MAX( + IF(sgd.id, IFNULL(pc.saleGroupDetailDefaultSize, i.`size`), i.`size`) + ) `size`, w.code workerCode, TIME_FORMAT(t.shipped, '%H:%i') shippedHour, TIME_FORMAT(zo.`hour`, '%H:%i') zoneHour, DATE_FORMAT(t.shipped, '%d/%m/%y') shipped, tt.labelCount, t.nickName, - COUNT(*) lineCount, + SUM(IF(sgd.id, IF(@hasPrevia, 0, @hasPrevia := 1), 1)) lineCount, rm.routeFk FROM vn.ticket t JOIN vn.ticketCollection tc ON tc.ticketFk = t.id @@ -23,7 +25,7 @@ SELECT c.itemPackingTypeFk code, AND cc.wagon = tc.wagon AND cc.trainFk = c.trainFk JOIN vn.sale s ON s.ticketFk = t.id - LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id + LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id JOIN vn.item i ON i.id = s.itemFk JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk @@ -32,7 +34,9 @@ SELECT c.itemPackingTypeFk code, LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id LEFT JOIN vn.`zone` zo ON t.zoneFk = zo.id LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.productionConfig pc WHERE t.id IN (?) GROUP BY t.id - ORDER BY cc.`code`; \ No newline at end of file + ORDER BY cc.`code` \ No newline at end of file From a900e0fff62ce1a9d2c7f49ce201aa1da91b0702 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 15 Jan 2024 10:03:05 +0100 Subject: [PATCH 041/116] feat: refs #6634 Minor change --- db/changes/240401/01-saleGroupDetailDefaultSize.sql | 4 ++-- print/templates/reports/collection-label/sql/labelsData.sql | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/changes/240401/01-saleGroupDetailDefaultSize.sql b/db/changes/240401/01-saleGroupDetailDefaultSize.sql index a1e0537ed..12f17c5e7 100644 --- a/db/changes/240401/01-saleGroupDetailDefaultSize.sql +++ b/db/changes/240401/01-saleGroupDetailDefaultSize.sql @@ -1,2 +1,2 @@ -ALTER TABLE vn.productionConfig ADD saleGroupDetailDefaultSize int NULL COMMENT 'Altura por defecto para los artículos de previa'; -UPDATE IGNORE vn.productionConfig SET saleGroupDetailDefaultSize = 40 WHERE id = 1; +ALTER TABLE vn.productionConfig ADD itemPreviousDefaultSize int NULL COMMENT 'Altura por defecto para los artículos de previa'; +UPDATE IGNORE vn.productionConfig SET itemPreviousDefaultSize = 40 WHERE id = 1; diff --git a/print/templates/reports/collection-label/sql/labelsData.sql b/print/templates/reports/collection-label/sql/labelsData.sql index fffa1bb53..7a12a56d3 100644 --- a/print/templates/reports/collection-label/sql/labelsData.sql +++ b/print/templates/reports/collection-label/sql/labelsData.sql @@ -8,7 +8,7 @@ SELECT c.itemPackingTypeFk code, t.clientFk, CAST(SUM(sv.volume) AS DECIMAL(5, 2)) volume, MAX( - IF(sgd.id, IFNULL(pc.saleGroupDetailDefaultSize, i.`size`), i.`size`) + IF(sgd.id, IFNULL(pc.itemPreviousDefaultSize, i.`size`), i.`size`) ) `size`, w.code workerCode, TIME_FORMAT(t.shipped, '%H:%i') shippedHour, From 107e35001a83f86cf08fa95d4258d9d704885f48 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 15 Jan 2024 10:09:43 +0100 Subject: [PATCH 042/116] fix: refs #6582 Solved log error --- modules/route/back/models/routesMonitor.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/route/back/models/routesMonitor.json b/modules/route/back/models/routesMonitor.json index e5a0f6062..122026336 100644 --- a/modules/route/back/models/routesMonitor.json +++ b/modules/route/back/models/routesMonitor.json @@ -1,6 +1,9 @@ { "name": "RoutesMonitor", - "base": "Loggable", + "base": "VnModel", + "mixins": { + "Loggable": true + }, "options": { "mysql": { "table": "routesMonitor" From 831d358e41aae03ceb29ff46b1bf8b469c1adb35 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 15 Jan 2024 10:52:02 +0100 Subject: [PATCH 043/116] refs #6174 feat first approach --- .../invoiceOut/back/methods/invoiceOut/transferInvoice.js | 8 ++++---- modules/ticket/back/methods/ticket/invoiceTickets.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index 782eaf6d8..3372c84dd 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -50,6 +50,7 @@ module.exports = Self => { Self.transferInvoice = async(ctx, options) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; + let makePdf = false; const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args; let tx; if (typeof options == 'object') @@ -63,6 +64,7 @@ module.exports = Self => { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; + makePdf = true; } try { const filterRef = {where: {refFk: refFk}}; @@ -93,11 +95,9 @@ module.exports = Self => { await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); const [invoiceId] = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions); - if (tx) { - await tx.commit(); - await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); - } + tx && await tx.commit(); + makePdf && await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); return invoiceId; } catch (e) { if (tx) await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/invoiceTickets.js b/modules/ticket/back/methods/ticket/invoiceTickets.js index 06429836e..162ddda03 100644 --- a/modules/ticket/back/methods/ticket/invoiceTickets.js +++ b/modules/ticket/back/methods/ticket/invoiceTickets.js @@ -32,6 +32,7 @@ module.exports = function(Self) { const models = Self.app.models; const date = Date.vnNew(); date.setHours(0, 0, 0, 0); + let makePdf = false; const myOptions = {userId: ctx.req.accessToken.userId}; let tx; @@ -42,6 +43,7 @@ module.exports = function(Self) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; + makePdf = true; } let invoicesIds = []; @@ -81,7 +83,7 @@ module.exports = function(Self) { if (tx) await tx.rollback(); throw e; } - if (tx) { + if (makePdf) { for (const invoiceId of invoicesIds) await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); } From b7edbbe12f35d0cbc3e6b83e54977ac1c8acfc74 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 15 Jan 2024 12:31:03 +0100 Subject: [PATCH 044/116] feat: refs #5483 Copy vn-database project --- db/.archive/224701/00-ACL.sql | 49 - db/.archive/224701/00-acl_receiptPdf.sql | 3 - .../224701/00-clientConsumptionQueue.sql | 9 - db/.archive/224701/00-invoiceOutQueue.sql | 1 - db/.archive/224701/00-itemConfig.sql | 5 - db/.archive/224701/00-printConfig.sql | 10 - db/.archive/224701/00-sample.sql | 6 - db/.archive/224701/00-user_hasGrant.sql | 1 - .../224702/00-ACL_workerDisableExcluded.sql | 2 - db/.archive/224702/00-aclBusiness.sql | 3 - db/.archive/224702/00-aclUsesMana.sql | 3 - .../00-defaultPayDem_sameAs_production.sql | 2 - db/.archive/224702/00-invoiceInPdf.sql | 4 - db/.archive/224702/00-newSupplier_ACL.sql | 2 - db/.archive/224702/00-notificationTables.sql | 63 - .../224702/00-payMethodFk_Allow_Null.sql | 1 - .../00-supplierActivityFk_Allow_Null.sql | 1 - db/.archive/224801/00-ACL.sql | 5 - db/.archive/224801/00-claim.sql | 1 - db/.archive/224801/00-claimRma.sql | 7 - db/.archive/224901/00-aclNotification.sql | 3 - db/.archive/224901/00-packingSiteConfig.sql | 12 - db/.archive/224901/00-packingSiteUpdate.sql | 56 - db/.archive/224901/00-salix_url.sql | 33 - db/.archive/224902/00-aclUserPassword.sql | 2 - db/.archive/224902/00-deletePickupContact.sql | 1 - db/.archive/224902/00-itemShelvingACL.sql | 4 - ...00-itemShelvingPlacementSupplyStockACL.sql | 4 - .../224902/00-workerTimeControlMail.sql | 1 - db/.archive/224902/00-zone_getPostalCode.sql | 54 - .../224903/00-ACL_notification_InvoiceE.sql | 2 - db/.archive/224903/00-aclInvoiceOut.sql | 7 - .../224903/00-alter_expedition_itemFk.sql | 1 - .../224903/00-clientHasInvoiceElectronic.sql | 8 - .../224903/00-collection_missingTrash.sql | 1 - .../224903/00-deleteInvoiceOutQueue.sql | 1 - db/.archive/224903/00-editTrackedACL.sql | 4 - db/.archive/224903/00-greuge.sql | 1 - db/.archive/224903/00-isCompensationACL.sql | 4 - db/.archive/224903/00-osTicketConfig.sql | 8 - db/.archive/224903/00-ticket_canMerge.sql | 14 - .../224903/00-ticket_canbePostponed.sql | 79 - .../224903/00-timeBusiness_calculate.sql | 88 - .../01-updateClientHasInvoiceElectronic.sql | 6 - db/.archive/225001/00-aclMdbApp.sql | 4 - db/.archive/225001/00-updateCollection.sql | 3 - db/.archive/225201/00-ACL_saveSign.sql | 1 - db/.archive/225201/00-aclTicketLog.sql | 3 - db/.archive/225201/00-entryDeleteRef.sql | 1 - db/.archive/225201/00-invoiceInConfig.sql | 12 - db/.archive/225201/00-invoiceOut_new.sql | 225 - db/.archive/225201/00-mdbApp.sql | 11 - db/.archive/225201/00-notification_send.sql | 24 - db/.archive/225201/00-ticketSms.sql | 8 - db/.archive/225201/00-ticket_canAdvance.sql | 104 - .../225201/00-ticket_canbePostponed.sql | 73 - db/.archive/225201/00-ticket_split_merge.sql | 2 - db/.archive/225201/00-utilNotification.sql | 4 - db/.archive/225201/01-create_stateI18n.sql | 7 - db/.archive/225201/01-modules.sql | 60 - db/.archive/225201/02-insert_stateI18n.sql | 73 - db/.archive/225201/02-starredModule.sql | 16 - db/.archive/225202/00-mdbApp.sql | 28 - db/.archive/225203/00-mdbApp.sql | 5 - .../230201/00-ACL_ItemShelvingSale.sql | 2 - db/.archive/230201/00-SupplierUniqueKey.sql | 1 - .../00-autoincrement_VnReport_VnPrinter.sql | 4 - db/.archive/230201/00-borradoLogicoIPT.sql | 3 - db/.archive/230201/00-docuwareStore.sql | 23 - .../230201/00-validPriorities_ItemConfig.sql | 5 - .../230201/00-workerTimeControlConfig.sql | 6 - db/.archive/230202/00-itemConfig.sql | 5 - db/.archive/230401/00-ACL.sql | 18 - db/.archive/230401/00-ACL_tag_update.sql | 3 - db/.archive/230401/00-createWorker.sql | 24 - db/.archive/230401/00-ticket_canAdvance.sql | 110 - db/.archive/230401/00-updateIsToBeMailed.sql | 6 - db/.archive/230403/00-clienteCompensado.sql | 3 - db/.archive/230404/00-ticket_canAdvance.sql | 127 - db/.archive/230601/00-acl_claim.sql | 6 - db/.archive/230601/00-acl_notifications.sql | 4 - .../230601/00-itemConfig_warehouseFk.sql | 4 - .../00-uniqueKeyNotificationSubscription.sql | 4 - db/.archive/230601/01-alter_notSubs.sql | 7 - db/.archive/230801/00-acl_itemConfig.sql | 3 - db/.archive/230801/00-supplierIsVies.sql | 16 - db/.archive/230801/00-workerLocker.sql | 15 - db/.archive/231001/00-delivery.sql | 74 - db/.archive/231001/00-invoiceOut.sql | 6 - db/.archive/231001/00-report.sql | 6 - db/.archive/231001/02-invoiceOut_new.sql | 258 - db/.archive/231201/00-ACL.sql | 3 - db/.archive/231201/00-chatRefactor.sql | 16 - db/.archive/231201/00-invoiceInSerial.sql | 4 - db/.archive/231201/00-itemType_isFragile.sql | 14 - db/.archive/231201/00-mailACL.sql | 2 - db/.archive/231201/00-operator.sql | 159 - .../00-supplierAccount_deleteTriggers.sql | 3 - db/.archive/231201/00-wagon.sql | 71 - db/.archive/231202/00-delivery.sql | 74 - db/.archive/231203/00-delivery.sql | 67 - db/.archive/231204/00-rollbackDelivery.sql | 83 - db/.archive/231205/00-printQueueArgs.sql | 1 - .../231401/00-claimBeginningAfterInsert.sql | 1 - db/.archive/231401/00-negativeBases.sql | 4 - db/.archive/231401/00-workerNotes.sql | 14 - db/.archive/231402/00-negativeBases.sql | 3 - db/.archive/231801/00-aclClientInforma.sql | 3 - db/.archive/231801/00-acl_receiptEmail.sql | 3 - db/.archive/231801/00-clientInforma.sql | 16 - db/.archive/231801/00-client_setRatingAcl.sql | 63 - db/.archive/231801/00-deleteProcs_refund.sql | 2 - db/.archive/231801/00-deviceProduction.sql | 5 - db/.archive/231801/00-kkearEntryNotes.sql | 1 - db/.archive/231801/00-newCompanyI18n.sql | 9 - db/.archive/231801/00-newTableWeb.sql | 1 - db/.archive/231801/00-observationEmailACL.sql | 3 - .../00-optimiceZoneEstimatedDelivery.sql | 77 - db/.archive/231801/00-saleTracking.sql | 5 - db/.archive/231801/00-ticketConfig.sql | 1 - db/.archive/231801/00-updateIsVies.sql | 5 - db/.archive/231801/00-updateisViesClient.sql | 5 - db/.archive/231801/00-userAcl.sql | 20 - db/.archive/231801/00-userRoleLog.sql | 4 - db/.archive/231801/01-viewCompany10L.sql | 12 - db/.archive/232001/00-clientWorkerName.sql | 73 - db/.archive/232001/00-createWorker.sql | 14 - db/.archive/232001/00-wagon.sql | 1 - db/.archive/232201/00-defaulterView.sql | 20 - db/.archive/232201/00-procedurecanAdvance.sql | 127 - .../232201/00-workerConfigPayMethod.sql | 7 - db/.archive/232202/00-procedurecanAdvance.sql | 127 - .../232401/00-buyConfig_travelConfig.sql | 28 - db/.archive/232401/00-printer.sql | 3 - db/.archive/232401/00-ticket_warehouse.sql | 1 - db/.archive/232401/00-userPassExpired.sql | 76 - db/.archive/232402/00-hotFix_travelConfig.sql | 22 - db/.archive/232601/00-aclAccount.sql | 8 - db/.archive/232601/00-aclInvoiceTickets.sql | 2 - db/.archive/232601/00-aclMailAliasAccount.sql | 5 - db/.archive/232601/00-aclMailForward.sql | 5 - db/.archive/232601/00-aclRole.sql | 5 - db/.archive/232601/00-aclVnUser.sql | 10 - .../232601/00-aclVnUser_renewToken.sql | 3 - db/.archive/232601/00-salix.sql | 11 - db/.archive/232601/00-useSpecificsAcls.sql | 121 - db/.archive/232601/01-invoiceOutPdf.sql | 13 - db/.archive/232602/01-aclAddAlias.sql | 8 - db/.archive/232801/00-authCode.sql | 13 - db/.archive/232801/00-client_create.sql | 89 - db/.archive/232801/00-client_create2.sql | 17 - db/.archive/232801/00-department.sql | 24 - db/.archive/232801/00-fix_editCredit.sql | 13 - db/.archive/232801/00-user.sql | 5 - db/.archive/232802/01-aclWorkerDisable.sql | 4 - db/.archive/233001/.gitkeep | 0 db/.archive/233001/00-aclSaleTracking.sql | 4 - db/.archive/233001/00-clientSms.sql | 15 - db/.archive/233001/00-company.sql | 1 - db/.archive/233001/00-fixACLVehicle.sql | 3 - db/.archive/233001/00-itemRecycle.sql | 2 - .../233001/00-itemShelving_inventory.sql | 64 - db/.archive/233001/00-noUniqueSocialName.sql | 2 - db/.archive/233001/00-roadmap.sql | 8 - db/.archive/233001/00-roadmapACL.sql | 6 - db/.archive/233001/00-ticketWeight.sql | 7 - db/.archive/233201/.gitkeep | 0 .../233201/00-acl_viaexpressConfig.sql | 4 - db/.archive/233201/00-transferClient.sql | 2 - db/.archive/233201/00-updatePrice.sql | 2 - db/.archive/233201/00-viaexpress.sql | 10 - db/.archive/233201/00-workerDocuware.sql | 10 - db/.archive/233202/00-ticketSmsACL.sql | 3 - db/.archive/233401/00-setDeleted_acl.sql | 6 - db/.archive/233601/.gitkeep | 0 db/.archive/233601/00-aclWorker.sql | 3 - db/.archive/233601/00-addExpeditionState.sql | 2 - db/.archive/233601/00-department.sql | 3 - db/.archive/233601/00-saleGroupDetail.sql | 7 - db/.archive/233801/.gitkeep | 0 db/.archive/233801/00-firstScript.sql | 1 - db/.archive/233801/01-deviceLog_acl.sql | 6 - db/.archive/233802/.gitkeep | 0 .../233802/00-collectionGetTicketsACL.sql | 3 - db/.gitignore | 10 +- db/Dockerfile | 45 - db/changes/234001/.gitkeep | 0 db/changes/234001/00-aclClient.sql | 42 - db/changes/234001/00-dropUserFk.sql | 4 - db/changes/234001/00-models.sql | 11 - db/changes/234001/00-ticketConfig.sql | 7 - .../234001/00-updateAfterBusinnesInsert.sql | 57 - db/changes/234001/01-aclAccount.sql | 10 - db/changes/234001/01-deliveryAssistantACL.sql | 21 - db/changes/234001/01-workerCreate.sql | 20 - db/changes/234001/02-roleSync.sql | 2 - db/changes/234002/.gitkeep | 0 db/changes/234002/01-itemShelvingSale.sql | 291 - .../234003/00-ticket_canAdvance_zone.sql | 133 - db/changes/234004/.gitkeep | 0 db/changes/234004/00-workerTimeControl.sql | 41 - db/changes/234201/.gitkeep | 0 db/changes/234201/00-ACL_workerDepartment.sql | 3 - db/changes/234201/00-account_acl.sql | 7 - db/changes/234201/00-aclClient.sql | 3 - db/changes/234201/00-aclSetPassword.sql | 4 - db/changes/234201/00-aclUrlHedera.sql | 7 - db/changes/234201/00-dropWorkerCreate.sql | 1 - db/changes/234201/00-packagingFk.sql | 5 - db/changes/234201/00-packagingFkviews.sql | 150 - .../234201/00-supplierAccountCheckLength.sql | 6 - db/changes/234201/00-zoneIncluded.sql | 26 - db/changes/234201/03-packagingFkProc.sql | 1381 - db/changes/234601/.gitkeep | 0 .../234601/00-ACLticketTrackingState.sql | 4 - db/changes/234601/00-claimViewerAcl.sql | 31 - db/changes/234601/00-clientAfterUpdate.sql | 95 - db/changes/234601/00-transferInvoice.sql | 6 - db/changes/234601/00-updateCourtesyTime.sql | 4 - db/changes/234602/00-roleSync.sql | 1 - db/changes/234604/00-sambaConfigUserDn.sql | 2 - db/changes/234801/.gitkeep | 0 db/changes/234801/00-ACL_executeRoutine.sql | 4 - .../234801/00-notificationSubscription.sql | 3 - db/changes/234802/00-createSignInLogTable.sql | 21 - db/changes/235001/.gitkeep | 0 db/changes/235001/00-getRoutesByWorker.sql | 26 - db/changes/240001/00-alterTable.sql | 1 - .../00-clientCreditLimitToRoleCreditLimit.sql | 4 - db/changes/240001/01-procedures.sql | 1129 - db/changes/240001/02-views.sql | 56 - db/changes/240002/00-silexToSalix.sql | 46 - db/docker.js | 211 - db/docker/docker-dump.sh | 6 - db/docker/docker-fixtures.sh | 10 - db/docker/docker-init.sh | 14 - db/docker/docker-start.sh | 10 - db/docker/docker-structure.sh | 7 - db/docker/docker-temp-stop.sh | 7 - db/docker/docker.cnf | 8 - db/dump/.dump/data.sql | 2736 + db/dump/.dump/privileges.sql | 1958 + db/dump/{ => .dump}/structure.sql | 47519 ++++++++++------ db/dump/Dockerfile | 5 + db/dump/db.cnf | 9 + db/dump/dump.after.sql | 1 + db/dump/dump.before.sql | 1 + db/dump/dumpedFixtures.sql | 793 - db/dump/fixtures.after.sql | 341 + db/dump/fixtures.before.sql | 2998 + db/dump/mockDate.sql | 29 +- db/export-data.sh | 109 - db/export-structure.sh | 95 - db/import-changes.sh | 119 - db/remotes/ca.pem | 23 + db/{config.ini => remotes/docker.ini} | 3 +- db/remotes/local.ini | 5 + db/remotes/old-ca.pem | 26 + .../account/functions/myUser_checkLogin.sql | 27 + .../account/functions/myUser_getId.sql | 24 + .../account/functions/myUser_getName.sql | 23 + .../account/functions/myUser_hasPriv.sql | 18 + .../account/functions/myUser_hasRole.sql | 14 + .../account/functions/myUser_hasRoleId.sql | 14 + .../functions/myUser_hasRoutinePriv.sql | 18 + .../account/functions/passwordGenerate.sql | 53 + db/routines/account/functions/toUnixDays.sql | 14 + .../account/functions/user_getMysqlRole.sql | 23 + .../account/functions/user_getNameFromId.sql | 20 + .../account/functions/user_hasPriv.sql | 109 + .../account/functions/user_hasRole.sql | 24 + .../account/functions/user_hasRoleId.sql | 24 + .../account/functions/user_hasRoutinePriv.sql | 81 + .../account/procedures/account_enable.sql | 24 + .../account/procedures/myUser_login.sql | 25 + .../procedures/myUser_loginWithKey.sql | 21 + .../procedures/myUser_loginWithName.sql | 24 + .../account/procedures/myUser_logout.sql | 11 + .../account/procedures/role_checkName.sql | 16 + .../procedures/role_getDescendents.sql | 64 + db/routines/account/procedures/role_sync.sql | 51 + .../procedures/role_syncPrivileges.sql | 565 + .../account/procedures/user_checkName.sql | 15 + .../account/procedures/user_checkPassword.sql | 55 + .../account/triggers/account_afterDelete.sql | 15 + .../account/triggers/account_afterInsert.sql | 9 + .../account/triggers/account_beforeInsert.sql | 8 + .../account/triggers/account_beforeUpdate.sql | 8 + .../triggers/mailAlias_afterDelete.sql | 12 + .../triggers/mailAlias_beforeInsert.sql | 8 + .../triggers/mailAlias_beforeUpdate.sql | 8 + .../triggers/mailForward_afterDelete.sql | 12 + .../triggers/mailForward_beforeInsert.sql | 8 + .../triggers/mailForward_beforeUpdate.sql | 8 + .../triggers/roleInherit_afterDelete.sql | 12 + .../triggers/roleInherit_beforeInsert.sql | 8 + .../triggers/roleInherit_beforeUpdate.sql | 8 + .../account/triggers/role_afterDelete.sql | 12 + .../account/triggers/role_beforeInsert.sql | 9 + .../account/triggers/role_beforeUpdate.sql | 11 + .../account/triggers/user_afterDelete.sql | 16 + .../account/triggers/user_afterInsert.sql | 10 + .../account/triggers/user_afterUpdate.sql | 18 + .../account/triggers/user_beforeInsert.sql | 14 + .../account/triggers/user_beforeUpdate.sql | 16 + db/routines/account/views/accountDovecot.sql | 10 + db/routines/account/views/emailUser.sql | 9 + db/routines/account/views/myRole.sql | 9 + db/routines/account/views/myUser.sql | 14 + db/routines/bi/functions/nz.sql | 16 + .../bi/procedures/Greuge_Evolution_Add.sql | 115 + .../analisis_ventas_evolution_add.sql | 232 + .../bi/procedures/analisis_ventas_simple.sql | 13 + .../bi/procedures/analisis_ventas_update.sql | 53 + .../bi/procedures/claim_ratio_routine.sql | 168 + db/routines/bi/procedures/clean.sql | 19 + db/routines/bi/procedures/clean_launcher.sql | 9 + db/routines/bi/procedures/comparativa_add.sql | 32 + .../bi/procedures/comparativa_add_manual.sql | 40 + .../bi/procedures/defaultersFromDate.sql | 24 + db/routines/bi/procedures/defaulting.sql | 98 + .../bi/procedures/defaulting_launcher.sql | 9 + .../facturacion_media_anual_update.sql | 16 + .../bi/procedures/greuge_dif_porte_add.sql | 93 + .../bi/procedures/nigthlyAnalisisVentas.sql | 8 + db/routines/bi/procedures/rutasAnalyze.sql | 127 + .../bi/procedures/rutasAnalyze_launcher.sql | 9 + .../bi/views/analisis_grafico_ventas.sql | 9 + .../bi/views/analisis_ventas_simple.sql | 9 + db/routines/bi/views/claims_ratio.sql | 10 + db/routines/bi/views/customerRiskOverdue.sql | 40 + db/routines/bi/views/defaulters.sql | 10 + .../bi/views/facturacion_media_anual.sql | 6 + db/routines/bi/views/last_Id_Cubo.sql | 19 + db/routines/bi/views/rotacion.sql | 15 + db/routines/bi/views/tarifa_componentes.sql | 11 + .../bi/views/tarifa_componentes_series.sql | 8 + db/routines/bi/views/v_clientes_jerarquia.sql | 21 + db/routines/bi/views/v_ventas_contables.sql | 23 + db/routines/bs/events/clientDied_recalc.sql | 28 + .../bs/events/inventoryDiscrepancy_launch.sql | 8 + db/routines/bs/events/nightTask_launchAll.sql | 8 + db/routines/bs/functions/tramo.sql | 21 + .../bs/procedures/bancos_evolution_add.sql | 112 + .../bs/procedures/campaignComparative.sql | 42 + db/routines/bs/procedures/carteras_add.sql | 27 + db/routines/bs/procedures/clean.sql | 34 + .../bs/procedures/clientDied_recalc.sql | 62 + .../bs/procedures/clientNewBorn_recalc.sql | 87 + .../bs/procedures/comercialesCompleto.sql | 111 + .../procedures/compradores_evolution_add.sql | 66 + .../bs/procedures/fondo_evolution_add.sql | 65 + db/routines/bs/procedures/fruitsEvolution.sql | 17 + .../bs/procedures/indicatorsUpdate.sql | 150 + .../procedures/indicatorsUpdateLauncher.sql | 22 + .../inventoryDiscrepancyDetail_replace.sql | 92 + db/routines/bs/procedures/m3Add.sql | 32 + .../bs/procedures/manaCustomerUpdate.sql | 101 + .../bs/procedures/manaSpellers_actualize.sql | 29 + .../bs/procedures/nightTask_launchAll.sql | 80 + .../bs/procedures/nightTask_launchTask.sql | 26 + .../bs/procedures/payMethodClientAdd.sql | 21 + db/routines/bs/procedures/saleGraphic.sql | 39 + .../bs/procedures/salePersonEvolutionAdd.sql | 20 + .../bs/procedures/salesByItemTypeDay_add.sql | 132 + .../salesByItemTypeDay_addLauncher.sql | 6 + .../salesByclientSalesPerson_add.sql | 46 + .../procedures/salesPersonEvolution_add.sql | 65 + .../bs/procedures/vendedores_add_launcher.sql | 8 + db/routines/bs/procedures/ventas_add.sql | 78 + .../bs/procedures/ventas_add_launcher.sql | 13 + .../bs/procedures/ventas_contables_add.sql | 102 + .../ventas_contables_add_launcher.sql | 14 + .../ventas_contables_por_cliente.sql | 47 + db/routines/bs/procedures/vivosMuertos.sql | 63 + db/routines/bs/procedures/waste_addSales.sql | 31 + .../bs/procedures/workerLabour_getData.sql | 106 + .../bs/procedures/workerProductivity_add.sql | 99 + .../triggers/clientNewBorn_BEFORE_UPDATE.sql | 11 + .../bs/triggers/nightTaskBeforeInsert.sql | 14 + .../bs/triggers/nightTaskBeforeUpdate.sql | 14 + db/routines/bs/views/VentasPorCliente.sql | 14 + db/routines/bs/views/bajasLaborales.sql | 31 + db/routines/bs/views/horasSilla.sql | 27 + db/routines/bs/views/lastIndicators.sql | 39 + db/routines/bs/views/packingSpeed.sql | 19 + db/routines/bs/views/s1_ticketDetail.sql | 19 + db/routines/bs/views/s21_saleDetail.sql | 42 + db/routines/bs/views/ventas.sql | 12 + db/routines/cache/events/cacheCalc_clean.sql | 8 + db/routines/cache/events/cache_clean.sql | 8 + .../procedures/addressFriendship_Update.sql | 27 + .../procedures/availableNoRaids_refresh.sql | 123 + .../cache/procedures/available_clean.sql | 22 + .../cache/procedures/available_refresh.sql | 127 + .../cache/procedures/cacheCalc_clean.sql | 7 + .../cache/procedures/cache_calc_end.sql | 25 + .../cache/procedures/cache_calc_start.sql | 87 + .../cache/procedures/cache_calc_unlock.sql | 22 + db/routines/cache/procedures/cache_clean.sql | 8 + db/routines/cache/procedures/clean.sql | 10 + .../cache/procedures/departure_timing.sql | 74 + .../cache/procedures/last_buy_refresh.sql | 45 + .../cache/procedures/prod_graphic_refresh.sql | 36 + .../cache/procedures/stock_refresh.sql | 53 + .../cache/procedures/visible_clean.sql | 17 + .../cache/procedures/visible_refresh.sql | 37 + db/routines/dipole/procedures/clean.sql | 14 + .../dipole/procedures/expedition_add.sql | 74 + .../dipole/views/expeditionControl.sql | 11 + db/routines/edi/events/floramondo.sql | 8 + db/routines/edi/functions/imageName.sql | 22 + db/routines/edi/procedures/clean.sql | 22 + .../procedures/deliveryInformation_Delete.sql | 26 + db/routines/edi/procedures/ekt_add.sql | 64 + db/routines/edi/procedures/ekt_load.sql | 277 + db/routines/edi/procedures/ekt_loadNotBuy.sql | 33 + db/routines/edi/procedures/ekt_refresh.sql | 55 + db/routines/edi/procedures/ekt_scan.sql | 131 + .../procedures/floramondo_offerRefresh.sql | 522 + db/routines/edi/procedures/item_freeAdd.sql | 32 + .../edi/procedures/item_getNewByEkt.sql | 186 + db/routines/edi/procedures/mail_new.sql | 40 + db/routines/edi/triggers/BEFORE UPDATE.sql | 38 + db/routines/edi/triggers/item_feature_bi.sql | 10 + .../edi/triggers/putOrder_AFTER_UPDATE.sql | 75 + .../edi/triggers/putOrder_BEFORE_INSERT.sql | 14 + .../triggers/supplyResponse_AFTER_UPDATE.sql | 21 + db/routines/edi/views/ektRecent.sql | 57 + db/routines/edi/views/errorList.sql | 23 + db/routines/edi/views/supplyOffer.sql | 113 + db/routines/hedera/events/order_doRecalc.sql | 8 + .../hedera/functions/myClient_getDebt.sql | 13 + .../hedera/functions/myUser_checkRestPriv.sql | 31 + .../hedera/functions/order_getTotal.sql | 31 + .../procedures/catalog_calcFromMyAddress.sql | 39 + db/routines/hedera/procedures/image_ref.sql | 25 + db/routines/hedera/procedures/image_unref.sql | 17 + .../hedera/procedures/item_calcCatalog.sql | 35 + .../hedera/procedures/item_getVisible.sql | 124 + .../hedera/procedures/item_listAllocation.sql | 28 + .../hedera/procedures/myOrder_addItem.sql | 11 + .../myOrder_calcCatalogFromItem.sql | 18 + .../procedures/myOrder_calcCatalogFull.sql | 18 + .../hedera/procedures/myOrder_checkConfig.sql | 14 + .../hedera/procedures/myOrder_checkMine.sql | 20 + .../hedera/procedures/myOrder_configure.sql | 34 + .../procedures/myOrder_configureForGuest.sql | 45 + .../hedera/procedures/myOrder_confirm.sql | 8 + .../hedera/procedures/myOrder_create.sql | 37 + .../procedures/myOrder_getAvailable.sql | 13 + .../hedera/procedures/myOrder_getTax.sql | 21 + .../procedures/myOrder_newWithAddress.sql | 59 + .../hedera/procedures/myOrder_newWithDate.sql | 59 + .../hedera/procedures/myTicket_get.sql | 41 + .../procedures/myTicket_getPackages.sql | 20 + .../hedera/procedures/myTicket_getRows.sql | 16 + .../procedures/myTicket_getServices.sql | 14 + .../hedera/procedures/myTicket_list.sql | 39 + .../hedera/procedures/myTicket_logAccess.sql | 15 + .../procedures/myTpvTransaction_end.sql | 23 + .../procedures/myTpvTransaction_start.sql | 14 + .../hedera/procedures/order_addItem.sql | 114 + .../hedera/procedures/order_calcCatalog.sql | 34 + .../procedures/order_calcCatalogFromItem.sql | 27 + .../procedures/order_calcCatalogFull.sql | 36 + .../hedera/procedures/order_checkConfig.sql | 64 + .../hedera/procedures/order_checkEditable.sql | 18 + .../hedera/procedures/order_configure.sql | 56 + .../hedera/procedures/order_confirm.sql | 13 + .../procedures/order_confirmWithUser.sql | 296 + .../hedera/procedures/order_doRecalc.sql | 53 + .../hedera/procedures/order_getAvailable.sql | 32 + .../hedera/procedures/order_getTax.sql | 62 + .../hedera/procedures/order_getTotal.sql | 25 + .../hedera/procedures/order_recalc.sql | 33 + .../hedera/procedures/order_requestRecalc.sql | 15 + .../hedera/procedures/order_update.sql | 67 + db/routines/hedera/procedures/survey_vote.sql | 19 + .../procedures/tpvTransaction_confirm.sql | 112 + .../procedures/tpvTransaction_confirmAll.sql | 38 + .../procedures/tpvTransaction_confirmById.sql | 29 + .../tpvTransaction_confirmFromExport.sql | 53 + .../hedera/procedures/tpvTransaction_end.sql | 21 + .../procedures/tpvTransaction_start.sql | 71 + .../hedera/procedures/tpvTransaction_undo.sql | 81 + .../hedera/procedures/visitUser_new.sql | 21 + .../hedera/procedures/visit_listByBrowser.sql | 24 + .../hedera/procedures/visit_register.sql | 75 + .../hedera/triggers/link_afterDelete.sql | 8 + .../hedera/triggers/link_afterInsert.sql | 8 + .../hedera/triggers/link_afterUpdate.sql | 11 + .../hedera/triggers/news_afterDelete.sql | 8 + .../hedera/triggers/news_afterInsert.sql | 8 + .../hedera/triggers/news_afterUpdate.sql | 11 + .../hedera/triggers/orderRow_afterDelete.sql | 9 + .../hedera/triggers/orderRow_afterInsert.sql | 9 + .../hedera/triggers/orderRow_afterUpdate.sql | 10 + .../hedera/triggers/orderRow_beforeInsert.sql | 17 + .../hedera/triggers/order_afterInsert.sql | 17 + .../hedera/triggers/order_afterUpdate.sql | 24 + .../hedera/triggers/order_beforeDelete.sql | 8 + db/routines/hedera/views/mainAccountBank.sql | 12 + db/routines/hedera/views/messageL10n.sql | 12 + db/routines/hedera/views/myAddress.sql | 18 + db/routines/hedera/views/myBasketDefaults.sql | 26 + db/routines/hedera/views/myClient.sql | 10 + db/routines/hedera/views/myInvoice.sql | 10 + db/routines/hedera/views/myMenu.sql | 14 + db/routines/hedera/views/myOrder.sql | 24 + db/routines/hedera/views/myOrderRow.sql | 19 + db/routines/hedera/views/myOrderTicket.sql | 9 + db/routines/hedera/views/myTicket.sql | 16 + db/routines/hedera/views/myTicketRow.sql | 17 + db/routines/hedera/views/myTicketService.sql | 15 + db/routines/hedera/views/myTicketState.sql | 21 + db/routines/hedera/views/myTpvTransaction.sql | 13 + db/routines/hedera/views/orderTicket.sql | 6 + db/routines/hedera/views/order_component.sql | 7 + db/routines/hedera/views/order_row.sql | 14 + db/routines/pbx/functions/clientFromPhone.sql | 11 + db/routines/pbx/functions/phone_format.sql | 36 + db/routines/pbx/procedures/phone_isValid.sql | 22 + db/routines/pbx/procedures/queue_isValid.sql | 20 + .../pbx/procedures/sip_getExtension.sql | 17 + db/routines/pbx/procedures/sip_isValid.sql | 21 + .../pbx/procedures/sip_setPassword.sql | 11 + .../pbx/triggers/blacklist_beforeInsert.sql | 8 + .../pbx/triggers/blacklist_berforeUpdate.sql | 8 + .../pbx/triggers/followme_beforeInsert.sql | 8 + .../pbx/triggers/followme_beforeUpdate.sql | 8 + .../pbx/triggers/queuePhone_beforeInsert.sql | 8 + .../pbx/triggers/queuePhone_beforeUpdate.sql | 8 + .../pbx/triggers/queue_beforeInsert.sql | 8 + .../pbx/triggers/queue_beforeUpdate.sql | 8 + db/routines/pbx/triggers/sip_afterInsert.sql | 13 + db/routines/pbx/triggers/sip_afterUpdate.sql | 13 + db/routines/pbx/triggers/sip_beforeInsert.sql | 8 + db/routines/pbx/triggers/sip_beforeUpdate.sql | 8 + db/routines/pbx/views/cdrConf.sql | 20 + db/routines/pbx/views/followmeConf.sql | 12 + db/routines/pbx/views/followmeNumberConf.sql | 11 + db/routines/pbx/views/queueConf.sql | 14 + db/routines/pbx/views/queueMemberConf.sql | 14 + db/routines/pbx/views/sipConf.sql | 40 + db/routines/psico/procedures/answerSort.sql | 10 + db/routines/psico/procedures/examNew.sql | 56 + .../psico/procedures/getExamQuestions.sql | 12 + db/routines/psico/procedures/getExamType.sql | 9 + db/routines/psico/procedures/questionSort.sql | 9 + db/routines/psico/views/examView.sql | 12 + db/routines/psico/views/results.sql | 22 + .../sage/functions/company_getCode.sql | 26 + .../procedures/accountingMovements_add.sql} | 87 +- .../sage/procedures/clientSupplier_add.sql} | 19 +- db/routines/sage/procedures/invoiceIn_add.sql | 202 + .../sage/procedures/invoiceIn_manager.sql | 271 + .../sage/procedures/invoiceOut_add.sql | 194 + .../sage/procedures/invoiceOut_manager.sql | 54 + db/routines/sage/procedures/pgc_add.sql | 37 + .../sage/triggers/movConta_BEFORE_UPDATE.sql | 10 + .../sage/views/clientLastTwoMonths.sql | 12 + .../sage/views/supplierLastThreeMonths.sql | 12 + .../salix/events/accessToken_prune.sql | 8 + .../salix/procedures/accessToken_prune.sql | 10 + db/routines/salix/views/Account.sql | 12 + db/routines/salix/views/Role.sql | 9 + db/routines/salix/views/RoleMapping.sql | 11 + db/routines/salix/views/User.sql | 11 + db/routines/srt/events/moving_clean.sql | 13 + db/routines/srt/functions/bid.sql | 37 + db/routines/srt/functions/bufferPool_get.sql | 39 + db/routines/srt/functions/buffer_get.sql | 70 + .../srt/functions/buffer_getRandom.sql | 23 + db/routines/srt/functions/buffer_getState.sql | 23 + db/routines/srt/functions/buffer_getType.sql | 23 + db/routines/srt/functions/buffer_isFull.sql | 34 + db/routines/srt/functions/dayMinute.sql | 18 + .../srt/functions/expedition_check.sql | 60 + .../srt/functions/expedition_getDayMinute.sql | 31 + .../srt/procedures/buffer_getExpCount.sql | 14 + .../srt/procedures/buffer_getStateType.sql | 19 + .../srt/procedures/buffer_giveBack.sql | 24 + .../srt/procedures/buffer_readPhotocell.sql | 28 + .../srt/procedures/buffer_setEmpty.sql | 23 + .../srt/procedures/buffer_setState.sql | 18 + .../srt/procedures/buffer_setStateType.sql | 56 + db/routines/srt/procedures/buffer_setType.sql | 18 + .../srt/procedures/buffer_setTypeByName.sql | 28 + db/routines/srt/procedures/clean.sql | 14 + .../srt/procedures/expeditionLoading_add.sql | 31 + .../srt/procedures/expedition_arrived.sql | 83 + .../srt/procedures/expedition_bufferOut.sql | 82 + .../srt/procedures/expedition_entering.sql | 61 + db/routines/srt/procedures/expedition_get.sql | 77 + .../srt/procedures/expedition_groupOut.sql | 91 + db/routines/srt/procedures/expedition_in.sql | 61 + .../srt/procedures/expedition_moving.sql | 47 + db/routines/srt/procedures/expedition_out.sql | 68 + .../srt/procedures/expedition_outAll.sql | 21 + .../srt/procedures/expedition_relocate.sql | 64 + .../srt/procedures/expedition_reset.sql | 309 + .../srt/procedures/expedition_routeOut.sql | 83 + .../srt/procedures/expedition_scan.sql | 19 + .../procedures/expedition_setDimensions.sql | 43 + .../srt/procedures/expedition_weighing.sql | 23 + db/routines/srt/procedures/failureLog_add.sql | 13 + db/routines/srt/procedures/lastRFID_add.sql | 15 + .../srt/procedures/lastRFID_add_beta.sql | 15 + .../srt/procedures/moving_CollidingSet.sql | 25 + db/routines/srt/procedures/moving_between.sql | 30 + db/routines/srt/procedures/moving_clean.sql | 63 + db/routines/srt/procedures/moving_delete.sql | 20 + .../srt/procedures/moving_groupOut.sql | 145 + db/routines/srt/procedures/moving_next.sql | 74 + .../srt/procedures/photocell_setActive.sql | 6 + db/routines/srt/procedures/randomMoving.sql | 50 + .../srt/procedures/randomMoving_Launch.sql | 21 + db/routines/srt/procedures/restart.sql | 15 + db/routines/srt/procedures/start.sql | 14 + db/routines/srt/procedures/stop.sql | 14 + db/routines/srt/procedures/test.sql | 8 + db/routines/srt/triggers/expedition_BU.sql | 10 + db/routines/srt/triggers/moving_AI.sql | 22 + db/routines/srt/views/bufferDayMinute.sql | 41 + db/routines/srt/views/bufferFreeLength.sql | 39 + db/routines/srt/views/bufferStock.sql | 54 + db/routines/srt/views/expeditionVolume.sql | 20 + db/routines/srt/views/routePalletized.sql | 31 + db/routines/srt/views/routeVolume.sql | 20 + db/routines/srt/views/ticketPalletized.sql | 32 + db/routines/srt/views/upperStickers.sql | 40 + db/routines/stock/events/log_clean.sql | 8 + db/routines/stock/events/log_syncNoWait.sql | 8 + .../stock/procedures/inbound_addPick.sql | 16 + .../stock/procedures/inbound_removePick.sql | 20 + .../procedures/inbound_requestQuantity.sql | 61 + db/routines/stock/procedures/inbound_sync.sql | 84 + db/routines/stock/procedures/log_add.sql | 21 + db/routines/stock/procedures/log_clean.sql | 7 + db/routines/stock/procedures/log_delete.sql | 19 + .../stock/procedures/log_refreshAll.sql | 33 + .../stock/procedures/log_refreshBuy.sql | 74 + .../stock/procedures/log_refreshOrder.sql | 47 + .../stock/procedures/log_refreshSale.sql | 65 + db/routines/stock/procedures/log_sync.sql | 123 + .../stock/procedures/log_syncNoWait.sql | 16 + .../procedures/outbound_requestQuantity.sql | 61 + .../stock/procedures/outbound_sync.sql | 78 + db/routines/stock/procedures/visible_log.sql | 20 + .../stock/triggers/inbound_afterDelete.sql | 22 + .../stock/triggers/inbound_beforeInsert.sql | 15 + .../stock/triggers/outbound_afterDelete.sql | 22 + .../stock/triggers/outbound_beforeInsert.sql | 16 + db/routines/tmp/events/clean.sql | 8 + db/routines/tmp/procedures/clean.sql | 28 + db/routines/util/events/slowLog_prune.sql | 8 + db/routines/util/functions/VN_CURDATE.sql | 11 + db/routines/util/functions/VN_CURTIME.sql | 11 + db/routines/util/functions/VN_NOW.sql | 11 + .../util/functions/VN_UNIX_TIMESTAMP.sql | 11 + db/routines/util/functions/VN_UTC_DATE.sql | 11 + db/routines/util/functions/VN_UTC_TIME.sql | 11 + .../util/functions/VN_UTC_TIMESTAMP.sql | 11 + .../util/functions/accountShortToStandard.sql | 8 + .../util/functions/capitalizeFirst.sql | 42 + db/routines/util/functions/crypt.sql | 15 + db/routines/util/functions/cryptOff.sql | 15 + db/routines/util/functions/dayEnd.sql | 15 + .../util/functions/firstDayOfMonth.sql | 15 + db/routines/util/functions/firstDayOfYear.sql | 15 + db/routines/util/functions/formatRow.sql | 21 + db/routines/util/functions/formatTable.sql | 23 + .../util/functions/hasDateOverlapped.sql | 10 + db/routines/util/functions/hmacSha2.sql | 32 + db/routines/util/functions/isLeapYear.sql | 10 + .../util/functions/json_removeNulls.sql | 32 + db/routines/util/functions/lang.sql | 14 + db/routines/util/functions/lastDayOfYear.sql | 15 + db/routines/util/functions/log_formatDate.sql | 30 + db/routines/util/functions/midnight.sql | 11 + db/routines/util/functions/mockTime.sql | 13 + db/routines/util/functions/mockTimeBase.sql | 26 + db/routines/util/functions/mockUtcTime.sql | 25 + db/routines/util/functions/nextWeek.sql | 19 + .../util/functions/notification_send.sql} | 8 +- .../util/functions/quarterFirstDay.sql | 8 + .../util/functions/quoteIdentifier.sql | 9 + db/routines/util/functions/stringXor.sql | 24 + db/routines/util/functions/today.sql | 15 + db/routines/util/functions/tomorrow.sql | 13 + db/routines/util/functions/twoDaysAgo.sql | 13 + .../util/functions/yearRelativePosition.sql | 29 + db/routines/util/functions/yesterday.sql | 13 + db/routines/util/procedures/checkHex.sql | 13 + db/routines/util/procedures/debugAdd.sql | 20 + db/routines/util/procedures/exec.sql | 18 + db/routines/util/procedures/log_add.sql | 25 + .../util/procedures/log_addWithUser.sql | 37 + .../util/procedures/log_cleanInstances.sql | 55 + db/routines/util/procedures/procNoOverlap.sql | 24 + .../util/procedures/proc_changedPrivs.sql | 15 + .../util/procedures/proc_restorePrivs.sql | 15 + .../util/procedures/proc_savePrivs.sql | 15 + db/routines/util/procedures/slowLog_prune.sql | 23 + db/routines/util/procedures/throw.sql | 12 + db/routines/util/procedures/time_generate.sql | 38 + db/routines/util/procedures/warn.sql | 7 + db/routines/util/views/eventLogGrouped.sql | 11 + .../vn/events/client_unassignSalesPerson.sql | 8 + db/routines/vn/events/clientsDisable.sql | 22 + db/routines/vn/events/collection_make.sql | 8 + db/routines/vn/events/department_doCalc.sql | 8 + .../vn/events/envialiaThreHoldChecker.sql | 36 + db/routines/vn/events/greuge_notify.sql | 9 + .../vn/events/itemImageQueue_check.sql | 11 + .../vn/events/mysqlConnectionsSorter_kill.sql | 8 + db/routines/vn/events/printQueue_check.sql | 84 + db/routines/vn/events/route_doRecalc.sql | 8 + .../vn/events/sale_checkWithoutComponents.sql | 8 + db/routines/vn/events/ticket_doRecalc.sql | 8 + db/routines/vn/events/travel_doRecalc.sql | 8 + db/routines/vn/events/vehicle_notify.sql | 9 + .../vn/events/workerJourney_doRecalc.sql | 8 + .../events/worker_updateChangedBusiness.sql | 8 + db/routines/vn/events/zoneGeo_doCalc.sql | 8 + db/routines/vn/functions/MIDNIGHT.sql | 8 + db/routines/vn/functions/addressTaxArea.sql | 29 + db/routines/vn/functions/address_getGeo.sql | 24 + db/routines/vn/functions/barcodeToItem.sql | 51 + .../vn/functions/buy_getUnitVolume.sql | 23 + db/routines/vn/functions/buy_getVolume.sql | 21 + .../vn/functions/catalog_componentReverse.sql | 95 + db/routines/vn/functions/clientGetMana.sql | 28 + .../vn/functions/clientGetSalesPerson.sql | 11 + db/routines/vn/functions/clientTaxArea.sql | 24 + db/routines/vn/functions/client_getDebt.sql | 38 + .../vn/functions/client_getFromPhone.sql | 43 + .../vn/functions/client_getSalesPerson.sql | 74 + .../client_getSalesPersonByTicket.sql | 23 + .../functions/client_getSalesPersonCode.sql | 26 + .../client_getSalesPersonCodeByTicket.sql | 23 + .../client_hasDifferentCountries.sql | 21 + .../vn/functions/collection_isPacked.sql | 22 + .../vn/functions/currency_getCommission.sql | 23 + db/routines/vn/functions/currentRate.sql | 20 + .../deviceProductionUser_accessGranted.sql | 29 + db/routines/vn/functions/duaTax_getRate.sql | 23 + db/routines/vn/functions/ekt_getEntry.sql | 71 + db/routines/vn/functions/ekt_getTravel.sql | 45 + .../vn/functions/entry_count} | 0 .../vn/functions/entry_getCommission.sql | 58 + .../vn/functions/entry_getCurrency.sql | 20 + .../vn/functions/entry_getForLogiflora.sql | 64 + .../vn/functions/entry_isIntrastat.sql | 39 + .../functions/entry_isInventoryOrPrevious.sql | 18 + .../vn/functions/expedition_checkRoute.sql | 32 + db/routines/vn/functions/firstDayOfWeek.sql | 24 + db/routines/vn/functions/getAlert3State.sql | 39 + .../vn/functions/getAlert3StateTest.sql | 40 + db/routines/vn/functions/getDueDate.sql | 17 + db/routines/vn/functions/getInventoryDate.sql | 8 + db/routines/vn/functions/getNewItemId.sql | 18 + db/routines/vn/functions/getNextDueDate.sql | 31 + db/routines/vn/functions/getShipmentHour.sql | 34 + db/routines/vn/functions/getSpecialPrice.sql | 20 + .../functions/getTicketTrolleyLabelCount.sql | 20 + db/routines/vn/functions/getUser.sql | 11 + db/routines/vn/functions/getUserId.sql | 16 + .../vn/functions/hasAnyNegativeBase.sql | 37 + db/routines/vn/functions/hasItemsInSector.sql | 20 + .../vn/functions/hasSomeNegativeBase.sql | 30 + db/routines/vn/functions/invoiceOutAmount.sql | 24 + .../vn/functions/invoiceOut_getMaxIssued.sql} | 14 +- .../vn/functions/invoiceOut_getPath.sql | 21 + .../vn/functions/invoiceOut_getWeight.sql} | 12 +- db/routines/vn/functions/invoiceSerial.sql | 26 + .../vn/functions/invoiceSerialArea.sql | 34 + db/routines/vn/functions/isLogifloraDay.sql | 19 + .../vn/functions/isPalletHomogeneus.sql | 27 + db/routines/vn/functions/itemPacking.sql | 41 + ...itemShelvingPlacementSupply_ClosestGet.sql | 33 + .../vn/functions/itemTag_getIntValue.sql | 12 + db/routines/vn/functions/item_getFhImage.sql | 17 + db/routines/vn/functions/item_getPackage.sql | 30 + db/routines/vn/functions/item_getVolume.sql | 27 + .../vn/functions/itemsInSector_get.sql | 21 + db/routines/vn/functions/lastDayOfWeek.sql | 24 + .../vn/functions/machine_checkPlate.sql | 24 + db/routines/vn/functions/messageSend.sql | 15 + .../vn/functions/messageSendWithUser.sql | 53 + db/routines/vn/functions/nz.sql | 14 + db/routines/vn/functions/orderTotalVolume.sql | 20 + .../vn/functions/orderTotalVolumeBoxes.sql | 25 + .../vn/functions/packaging_calculate.sql | 27 + .../vn/functions/priceFixed_getRate2.sql} | 8 +- db/routines/vn/functions/routeProposal.sql | 55 + db/routines/vn/functions/routeProposal_.sql | 30 + .../vn/functions/routeProposal_beta.sql | 55 + .../vn/functions/specie_IsForbidden.sql | 28 + db/routines/vn/functions/testCIF.sql | 73 + db/routines/vn/functions/testNIE.sql | 55 + db/routines/vn/functions/testNIF.sql | 29 + .../ticketCollection_getNoPacked.sql | 27 + db/routines/vn/functions/ticketGetTotal.sql | 31 + .../vn/functions/ticketPositionInPath.sql | 79 + .../vn/functions/ticketSplitCounter.sql | 21 + .../vn/functions/ticketTotalVolume.sql | 17 + .../vn/functions/ticketTotalVolumeBoxes.sql | 25 + .../vn/functions/ticketWarehouseGet.sql | 15 + db/routines/vn/functions/ticket_CC_volume.sql | 22 + .../vn/functions/ticket_HasUbication.sql | 19 + db/routines/vn/functions/ticket_get.sql | 64 + .../vn/functions/ticket_getFreightCost.sql | 28 + db/routines/vn/functions/ticket_getWeight.sql | 22 + .../vn/functions/ticket_isOutClosureZone.sql | 23 + db/routines/vn/functions/till_new.sql | 79 + .../timeWorkerControl_getDirection.sql | 65 + .../vn/functions/time_getSalesYear.sql | 13 + .../vn/functions/travel_getForLogiflora.sql | 52 + db/routines/vn/functions/validationCode.sql | 29 + .../vn/functions/validationCode_beta.sql | 29 + .../workerMachinery_isRegistered.sql | 23 + .../workerNigthlyHours_calculate.sql | 28 + .../vn/functions/workerTimeControl_add.sql | 57 + .../workerTimeControl_addDirection.sql | 57 + db/routines/vn/functions/worker_getCode.sql | 15 + db/routines/vn/functions/worker_isBoss.sql | 47 + db/routines/vn/functions/worker_isWorking.sql | 28 + db/routines/vn/functions/xdiario_new.sql | 44 + db/routines/vn/functions/zoneGeo_new.sql | 29 + .../vn/procedures/XDiario_checkDate.sql | 24 + .../vn/procedures/addNoteFromDelivery.sql | 13 + db/routines/vn/procedures/addressTaxArea.sql | 38 + .../procedures/agencyHourGetFirstShipped.sql | 35 + .../vn/procedures/agencyHourGetLanded.sql | 37 + .../vn/procedures/agencyHourGetWarehouse.sql | 78 + .../procedures/agencyHourListGetShipped.sql | 13 + db/routines/vn/procedures/available_calc.sql | 57 + .../vn/procedures/bankEntity_checkBic.sql | 19 + .../procedures/bankPolicy_notifyExpired.sql | 22 + db/routines/vn/procedures/buyUltimate.sql | 36 + .../vn/procedures/buyUltimateFromInterval.sql | 129 + db/routines/vn/procedures/buy_afterUpsert.sql | 79 + .../vn/procedures/buy_checkGrouping.sql | 14 + db/routines/vn/procedures/buy_getSplit.sql | 128 + db/routines/vn/procedures/buy_getVolume.sql | 21 + .../vn/procedures/buy_getVolumeByAgency.sql | 20 + .../vn/procedures/buy_getVolumeByEntry.sql | 18 + .../vn/procedures/buy_recalcPrices.sql | 52 + .../vn/procedures/buy_recalcPricesByAwb.sql | 24 + .../vn/procedures/buy_recalcPricesByBuy.sql | 18 + .../vn/procedures/buy_recalcPricesByEntry.sql | 20 + db/routines/vn/procedures/buy_scan.sql | 39 + .../vn/procedures/buy_updateGrouping.sql | 21 + .../vn/procedures/buy_updatePacking.sql | 22 + .../vn/procedures/catalog_calcFromItem.sql | 26 + .../vn/procedures/catalog_calculate.sql | 186 + .../procedures/catalog_componentCalculate.sql | 294 + .../procedures/catalog_componentPrepare.sql | 27 + .../vn/procedures/catalog_componentPurge.sql | 9 + .../vn/procedures/clean.sql} | 47 +- db/routines/vn/procedures/clean_logiflora.sql | 81 + .../vn/procedures/clearShelvingList.sql | 8 + db/routines/vn/procedures/clientDebtSpray.sql | 29 + db/routines/vn/procedures/clientFreeze.sql | 44 + .../vn/procedures/clientGetDebtDiary.sql | 117 + .../vn/procedures/clientGreugeSpray.sql | 73 + .../procedures/clientPackagingOverstock.sql | 92 + .../clientPackagingOverstockReturn.sql | 40 + .../vn/procedures/clientRemoveWorker.sql | 40 + .../vn/procedures/clientRisk_update.sql | 15 + .../vn/procedures/client_RandomList.sql | 59 + .../vn/procedures/client_checkBalance.sql | 68 + .../vn/procedures/client_create.sql} | 0 db/routines/vn/procedures/client_getDebt.sql | 62 + db/routines/vn/procedures/client_getMana.sql | 56 + .../procedures/client_unassignSalesPerson.sql | 51 + db/routines/vn/procedures/cmrPallet_add.sql | 37 + .../vn/procedures/collectionPlacement_get.sql | 150 + .../vn/procedures/collection_addItem.sql | 57 + .../vn/procedures/collection_assign.sql | 72 + db/routines/vn/procedures/collection_get.sql | 33 + .../vn/procedures/collection_getTickets.sql | 62 + db/routines/vn/procedures/collection_kill.sql | 16 + db/routines/vn/procedures/collection_make.sql | 68 + db/routines/vn/procedures/collection_new.sql | 303 + .../vn/procedures/collection_printSticker.sql | 33 + .../vn/procedures/collection_setParking.sql | 15 + .../vn/procedures/collection_setState.sql | 44 + .../vn/procedures/company_getFiscaldata.sql | 25 + .../procedures/company_getSuppliersDebt.sql | 197 + db/routines/vn/procedures/comparative_add.sql | 59 + .../vn/procedures/conveyorExpedition_Add.sql | 52 + .../procedures/copyComponentsFromSaleList.sql | 34 + .../vn/procedures/createPedidoInterno.sql | 9 + db/routines/vn/procedures/crypt.sql | 57 + db/routines/vn/procedures/cryptOff.sql | 54 + .../vn/procedures/department_calcTree.sql | 31 + .../vn/procedures/department_calcTreeRec.sql | 69 + .../vn/procedures/department_doCalc.sql | 29 + .../procedures/department_getHasMistake.sql | 16 + .../vn/procedures/department_getLeaves.sql | 78 + db/routines/vn/procedures/deviceLog_add.sql | 15 + .../deviceProductionUser_exists.sql | 11 + .../deviceProductionUser_getWorker.sql | 14 + .../deviceProduction_getnameDevice.sql | 13 + .../vn/procedures/device_checkLogin.sql | 43 + .../vn/procedures/duaEntryValueUpdate.sql | 28 + .../vn/procedures/duaInvoiceInBooking.sql | 70 + db/routines/vn/procedures/duaParcialMake.sql | 21 + db/routines/vn/procedures/duaTaxBooking.sql | 136 + db/routines/vn/procedures/duaTax_doRecalc.sql | 54 + .../vn/procedures/ediTables_Update.sql | 13 + .../vn/procedures/ektEntryAssign_setEntry.sql | 112 + .../vn/procedures/energyMeter_record.sql | 20 + db/routines/vn/procedures/entryDelivered.sql | 31 + db/routines/vn/procedures/entryWithItem.sql | 54 + .../vn/procedures/entry_checkPackaging.sql | 20 + db/routines/vn/procedures/entry_clone.sql | 20 + .../vn/procedures/entry_cloneHeader.sql | 42 + .../vn/procedures/entry_cloneWithoutBuy.sql | 21 + db/routines/vn/procedures/entry_copyBuys.sql | 59 + db/routines/vn/procedures/entry_fixMisfit.sql | 65 + db/routines/vn/procedures/entry_getRate.sql | 21 + db/routines/vn/procedures/entry_lock.sql | 13 + .../vn/procedures/entry_moveNotPrinted.sql | 177 + .../vn/procedures/entry_notifyChanged.sql | 32 + db/routines/vn/procedures/entry_recalc.sql | 34 + .../vn/procedures/entry_splitByShelving.sql | 131 + .../vn/procedures/entry_splitMisfit.sql | 34 + db/routines/vn/procedures/entry_unlock.sql | 13 + .../vn/procedures/entry_updateComission.sql} | 5 +- .../vn/procedures/expeditionGetFromRoute.sql | 32 + .../vn/procedures/expeditionPallet_Del.sql | 9 + .../vn/procedures/expeditionPallet_List.sql | 16 + .../vn/procedures/expeditionPallet_View.sql | 16 + .../vn/procedures/expeditionPallet_build.sql | 100 + .../expeditionPallet_printLabel.sql | 29 + .../vn/procedures/expeditionScan_Add.sql | 27 + .../vn/procedures/expeditionScan_Del.sql | 9 + .../vn/procedures/expeditionScan_List.sql | 17 + .../vn/procedures/expeditionScan_Put.sql | 11 + .../vn/procedures/expeditionState_add.sql | 31 + .../expeditionState_addByAdress.sql | 21 + .../expeditionState_addByExpedition.sql | 18 + .../expeditionState_addByPallet.sql | 31 + .../procedures/expeditionState_addByRoute.sql | 20 + .../vn/procedures/expeditionTruck_Add.sql | 9 + .../vn/procedures/expeditionTruck_List.sql | 12 + .../vn/procedures/expedition_StateGet.sql | 74 + .../vn/procedures/expedition_getFromRoute.sql | 39 + .../vn/procedures/expedition_getState.sql | 57 + .../vn/procedures/freelance_getInfo.sql | 14 + db/routines/vn/procedures/fustControl.sql | 79 + .../vn/procedures/fustControlDetail.sql | 36 + db/routines/vn/procedures/fv_pca.sql | 101 + .../vn/procedures/getDayExpeditions.sql | 15 + db/routines/vn/procedures/getInfoDelivery.sql | 10 + .../vn/procedures/getPedidosInternos.sql | 8 + db/routines/vn/procedures/greuge_add.sql | 22 + .../vn/procedures/greuge_notifyEvents.sql | 72 + .../vn/procedures/inventoryFailureAdd.sql | 48 + db/routines/vn/procedures/inventoryMake.sql | 265 + .../vn/procedures/inventoryMakeLauncher.sql | 11 + .../vn/procedures/inventory_repair.sql | 111 + .../vn/procedures/invoiceExpenseMake.sql | 30 + .../vn/procedures/invoiceFromAddress.sql | 19 + .../vn/procedures/invoiceFromClient.sql | 22 + .../vn/procedures/invoiceFromTicket.sql | 14 + .../procedures/invoiceInDueDay_calculate.sql | 73 + .../vn/procedures/invoiceInDueDay_recalc.sql | 11 + .../vn/procedures/invoiceInTaxMakeByDua.sql | 32 + .../procedures/invoiceInTax_afterUpsert.sql | 22 + .../vn/procedures/invoiceInTax_getFromDua.sql | 32 + .../invoiceInTax_getFromEntries.sql | 45 + .../vn/procedures/invoiceIn_booking.sql | 283 + db/routines/vn/procedures/invoiceOutAgain.sql | 57 + .../vn/procedures/invoiceOutBooking.sql | 194 + .../vn/procedures/invoiceOutBookingRange.sql | 47 + .../vn/procedures/invoiceOutListByCompany.sql | 27 + .../vn/procedures/invoiceOutTaxAndExpense.sql | 76 + .../invoiceOut_exportationFromClient.sql | 32 + .../vn/procedures/invoiceOut_new.sql} | 36 +- .../procedures/invoiceOut_newFromClient.sql | 56 + .../procedures/invoiceOut_newFromTicket.sql | 34 + db/routines/vn/procedures/invoiceTaxMake.sql | 44 + .../vn/procedures/itemBarcode_update.sql | 11 + .../vn/procedures/itemFuentesBalance.sql | 80 + .../vn/procedures/itemPlacementFromTicket.sql | 24 + .../procedures/itemPlacementSupplyAiming.sql | 30 + .../itemPlacementSupplyCloseOrder.sql | 10 + .../itemPlacementSupplyGetOrder.sql | 37 + .../itemPlacementSupplyStockGetTargetList.sql | 34 + db/routines/vn/procedures/itemProposal.sql | 87 + .../vn/procedures/itemProposal_Add.sql | 59 + .../vn/procedures/itemProposal_beta.sql | 76 + db/routines/vn/procedures/itemRefreshTags.sql | 20 + db/routines/vn/procedures/itemSale_byWeek.sql | 45 + db/routines/vn/procedures/itemSaveMin.sql | 13 + .../vn/procedures/itemSearchShelving.sql | 9 + .../vn/procedures/itemShelvingDelete.sql | 8 + .../vn/procedures/itemShelvingLog_get.sql | 35 + .../procedures/itemShelvingMakeFromDate.sql | 58 + .../vn/procedures/itemShelvingMatch.sql | 31 + .../itemShelvingPlacementSupplyAdd.sql | 20 + .../vn/procedures/itemShelvingProblem.sql | 49 + .../vn/procedures/itemShelvingRadar.sql | 188 + .../vn/procedures/itemShelvingRadar_Entry.sql | 52 + .../itemShelvingRadar_Entry_State_beta.sql | 38 + .../vn/procedures/itemShelvingSale_Add.sql | 29 + .../procedures/itemShelvingSale_reserve.sql | 92 + .../itemShelvingSale_reserveByCollection.sql | 29 + .../itemShelvingSale_reserveBySale.sql | 21 + .../itemShelvingSale_setQuantity.sql | 118 + .../vn/procedures/itemShelvingTransfer.sql | 45 + .../vn/procedures/itemShelving_add.sql | 63 + .../vn/procedures/itemShelving_addByClaim.sql | 30 + .../vn/procedures/itemShelving_addList.sql | 47 + .../procedures/itemShelving_filterBuyer.sql | 86 + .../vn/procedures/itemShelving_get.sql | 25 + .../itemShelving_getAlternatives.sql | 22 + .../vn/procedures/itemShelving_getInfo.sql | 24 + .../procedures/itemShelving_getSaleDate.sql | 165 + .../vn/procedures/itemShelving_inventory.sql | 62 + .../itemShelving_selfConsumption.sql | 86 + .../vn/procedures/itemShelving_update.sql | 19 + db/routines/vn/procedures/itemTagMake.sql | 56 + db/routines/vn/procedures/itemTagReorder.sql | 27 + .../vn/procedures/itemTagReorderByName.sql | 27 + db/routines/vn/procedures/itemTag_replace.sql | 35 + db/routines/vn/procedures/itemTopSeller.sql | 63 + .../vn/procedures/itemTrash.sql} | 30 +- db/routines/vn/procedures/itemUpdateTag.sql | 41 + db/routines/vn/procedures/item_GetVisible.sql | 43 + .../vn/procedures/item_ValuateInventory.sql | 237 + .../vn/procedures/item_cleanFloramondo.sql | 203 + .../vn/procedures/item_comparative.sql | 297 + .../vn/procedures/item_deactivateUnused.sql | 31 + db/routines/vn/procedures/item_getAtp.sql | 48 + db/routines/vn/procedures/item_getBalance.sql | 224 + db/routines/vn/procedures/item_getInfo.sql | 72 + db/routines/vn/procedures/item_getLack.sql | 55 + db/routines/vn/procedures/item_getMinETD.sql | 24 + db/routines/vn/procedures/item_getMinacum.sql | 79 + db/routines/vn/procedures/item_getSimilar.sql | 84 + db/routines/vn/procedures/item_getStock.sql | 72 + .../vn/procedures/item_multipleBuy.sql | 36 + .../vn/procedures/item_multipleBuyByDate.sql | 40 + .../vn/procedures/item_refreshFromTags.sql | 62 + .../vn/procedures/item_refreshTags.sql | 29 + .../vn/procedures/item_saveReference.sql | 19 + db/routines/vn/procedures/item_setGeneric.sql | 56 + .../vn/procedures/item_setVisibleDiscard.sql} | 20 - .../procedures/item_updatePackingShelve.sql | 17 + .../vn/procedures/item_updatePackingType.sql | 13 + .../vn/procedures/item_zoneClosure.sql | 25 + .../vn/procedures/ledger_doCompensation.sql | 78 + db/routines/vn/procedures/ledger_next.sql | 9 + db/routines/vn/procedures/logShow.sql | 23 + .../vn/procedures/lungSize_generator.sql | 48 + .../vn/procedures/machineWorker_add.sql | 22 + .../machineWorker_getHistorical.sql | 21 + .../vn/procedures/machineWorker_update.sql | 38 + .../vn/procedures/machine_getWorkerPlate.sql | 16 + db/routines/vn/procedures/mail_insert.sql | 38 + db/routines/vn/procedures/makeNewItem.sql | 16 + db/routines/vn/procedures/makePCSGraf.sql | 39 + .../vn/procedures/manaSpellersRequery.sql | 36 + .../vn/procedures/multipleInventory.sql | 194 + .../mysqlConnectionsSorter_kill.sql | 37 + .../procedures/mysqlPreparedCount_check.sql | 21 + .../vn/procedures/nextShelvingCodeMake.sql | 41 + db/routines/vn/procedures/observationAdd.sql | 28 + db/routines/vn/procedures/orderCreate.sql | 27 + db/routines/vn/procedures/orderDelete.sql | 8 + db/routines/vn/procedures/orderListCreate.sql | 14 + db/routines/vn/procedures/orderListVolume.sql | 16 + .../vn/procedures/packageInvoicing.sql | 121 + .../vn/procedures/packingListPrinted.sql | 13 + .../vn/procedures/packingListSwitch.sql | 20 + .../packingSite_startCollection.sql} | 22 +- db/routines/vn/procedures/parking_add.sql | 41 + .../vn/procedures/parking_algemesi.sql | 62 + db/routines/vn/procedures/parking_new.sql | 32 + .../vn/procedures/parking_setOrder.sql | 27 + .../vn/procedures/prepareClientList.sql | 16 + .../vn/procedures/prepareTicketList.sql | 22 + .../vn/procedures/previousSticker_get.sql | 58 + .../vn/procedures/printer_checkSector.sql | 22 + .../vn/procedures/productionControl.sql | 263 + .../vn/procedures/productionError_add.sql | 158 + .../productionError_addCheckerPackager.sql | 47 + .../vn/procedures/productionSectorList.sql | 108 + db/routines/vn/procedures/rangeDateInfo.sql | 37 + db/routines/vn/procedures/rate_getPrices.sql | 45 + db/routines/vn/procedures/recipe_Cook.sql | 74 + db/routines/vn/procedures/recipe_Plaster.sql | 35 + .../procedures/reportLabelCollection_get.sql | 55 + db/routines/vn/procedures/report_print.sql | 83 + db/routines/vn/procedures/riskAllClients.sql | 29 + .../vn/procedures/routeGuessPriority.sql | 20 + db/routines/vn/procedures/routeInfo.sql | 33 + .../vn/procedures/routeMonitor_calculate.sql | 114 + db/routines/vn/procedures/routeSetOk.sql | 11 + db/routines/vn/procedures/routeUpdateM3.sql | 9 + .../vn/procedures/route_calcCommission.sql | 94 + db/routines/vn/procedures/route_doRecalc.sql | 48 + .../vn/procedures/route_getTickets.sql | 72 + db/routines/vn/procedures/route_updateM3.sql | 14 + db/routines/vn/procedures/saleBuy_Add.sql | 26 + db/routines/vn/procedures/saleGroup_add.sql | 14 + .../vn/procedures/saleGroup_setParking.sql | 17 + db/routines/vn/procedures/saleMistake_Add.sql | 9 + .../vn/procedures/salePreparingList.sql | 46 + db/routines/vn/procedures/saleSplit.sql | 43 + .../vn/procedures/saleTracking_add.sql | 22 + .../saleTracking_addPreparedSaleGroup.sql | 15 + .../vn/procedures/saleTracking_addPrevOK.sql | 25 + .../vn/procedures/saleTracking_del.sql | 15 + .../vn/procedures/saleTracking_new.sql | 38 + .../saleTracking_updateIsChecked.sql | 28 + db/routines/vn/procedures/sale_PriceFix.sql | 22 + .../vn/procedures/sale_calculateComponent.sql | 19 + .../vn/procedures/sale_checkNoComponents.sql | 70 + .../vn/procedures/sale_getBoxPickingList.sql | 58 + .../sale_getFromTicketOrCollection.sql | 115 + .../vn/procedures/sale_getProblems.sql | 299 + .../procedures/sale_getProblemsByTicket.sql | 26 + .../vn/procedures/sale_recalcComponent.sql | 115 + db/routines/vn/procedures/sales_merge.sql | 39 + .../vn/procedures/sales_mergeByCollection.sql | 36 + .../sectorCollectionSaleGroup_add.sql | 38 + .../vn/procedures/sectorCollection_get.sql | 22 + .../procedures/sectorCollection_getSale.sql | 32 + .../vn/procedures/sectorCollection_new.sql | 28 + .../vn/procedures/sectorProductivity_add.sql | 74 + db/routines/vn/procedures/sector_get.sql | 13 + .../vn/procedures/sector_getWarehouse.sql | 10 + db/routines/vn/procedures/setParking.sql | 61 + db/routines/vn/procedures/shelvingChange.sql | 11 + db/routines/vn/procedures/shelvingLog_get.sql | 18 + .../vn/procedures/shelvingParking_get.sql | 23 + .../vn/procedures/shelvingPriority_update.sql | 8 + db/routines/vn/procedures/shelving_clean.sql | 37 + .../vn/procedures/shelving_getSpam.sql | 84 + .../vn/procedures/shelving_setParking.sql | 23 + db/routines/vn/procedures/sleep_X_min.sql | 9 + .../vn/procedures/solunionRiskRequest.sql | 31 + .../vn/procedures/stockBuyedByWorker.sql | 74 + db/routines/vn/procedures/stockBuyed_add.sql | 70 + db/routines/vn/procedures/stockTraslation.sql | 41 + .../vn/procedures/subordinateGetList.sql | 50 + .../vn/procedures/supplierExpenses.sql | 79 + .../supplierPackaging_ReportSource.sql | 82 + .../vn/procedures/supplier_checkBalance.sql | 74 + .../vn/procedures/supplier_checkIsActive.sql | 17 + .../supplier_disablePayMethodChecked.sql | 25 + db/routines/vn/procedures/test.sql | 6 + db/routines/vn/procedures/ticketBoxesView.sql | 25 + db/routines/vn/procedures/ticketBuiltTime.sql | 38 + .../vn/procedures/ticketCalculateClon.sql | 37 + .../vn/procedures/ticketCalculateFromType.sql | 18 + .../vn/procedures/ticketCalculatePurge.sql | 11 + db/routines/vn/procedures/ticketClon.sql | 55 + .../vn/procedures/ticketClon_OneYear.sql | 22 + .../vn/procedures/ticketCollection_get.sql | 10 + .../ticketCollection_setUsedShelves.sql | 17 + .../vn/procedures/ticketComponentUpdate.sql | 65 + .../procedures/ticketComponentUpdateSale.sql | 184 + .../ticketDown_PrintableSelection.sql | 22 + db/routines/vn/procedures/ticketGetTaxAdd.sql | 31 + .../vn/procedures/ticketGetTax_new.sql | 66 + db/routines/vn/procedures/ticketGetTotal.sql | 27 + .../procedures/ticketGetVisibleAvailable.sql | 33 + .../vn/procedures/ticketMissed_List.sql | 49 + .../procedures/ticketNotInvoicedByClient.sql | 30 + .../ticketObservation_addNewBorn.sql | 20 + .../vn/procedures/ticketPackaging_add.sql} | 5 +- .../procedures/ticketParking_findSkipped.sql | 64 + .../procedures/ticketRefund_beforeUpsert.sql | 18 + .../vn/procedures/ticketRequest_Add.sql | 19 + .../procedures/ticketStateToday_setState.sql | 27 + .../vn/procedures/ticketStateUpdate.sql | 26 + .../procedures/ticketToInvoiceByAddress.sql | 23 + .../vn/procedures/ticketToInvoiceByDate.sql | 23 + .../vn/procedures/ticketToInvoiceByRef.sql | 47 + db/routines/vn/procedures/ticket_Clone.sql | 61 + .../vn/procedures/ticket_DelayTruck.sql | 34 + .../vn/procedures/ticket_DelayTruckSplit.sql | 57 + .../procedures/ticket_WeightDeclaration.sql | 50 + db/routines/vn/procedures/ticket_add.sql | 123 + .../procedures/ticket_administrativeCopy.sql | 19 + .../vn/procedures/ticket_canAdvance.sql} | 1 - .../vn/procedures/ticket_canMerge.sql} | 63 +- .../vn/procedures/ticket_canbePostponed.sql} | 8 +- .../procedures/ticket_checkNoComponents.sql | 45 + .../vn/procedures/ticket_cloneWeekly.sql | 202 + db/routines/vn/procedures/ticket_close.sql | 103 + .../vn/procedures/ticket_closeByTicket.sql} | 22 +- .../procedures/ticket_componentMakeUpdate.sql | 99 + .../vn/procedures/ticket_componentPreview.sql | 101 + db/routines/vn/procedures/ticket_doCmr.sql | 89 + db/routines/vn/procedures/ticket_doRecalc.sql | 53 + .../procedures/ticket_getFromFloramondo.sql | 127 + .../vn/procedures/ticket_getMovable.sql | 44 + .../vn/procedures/ticket_getProblems.sql | 48 + .../vn/procedures/ticket_getSplitList.sql | 160 + db/routines/vn/procedures/ticket_getTax.sql | 103 + .../vn/procedures/ticket_getWarnings.sql} | 31 +- .../procedures/ticket_getWithParameters.sql | 49 + .../vn/procedures/ticket_insertZone.sql | 30 + .../vn/procedures/ticket_priceDifference.sql | 44 + .../procedures/ticket_printLabelPrevious.sql | 33 + db/routines/vn/procedures/ticket_recalc.sql | 37 + .../vn/procedures/ticket_recalcComponents.sql | 21 + .../vn/procedures/ticket_requestRecalc.sql | 15 + .../vn/procedures/ticket_setNextState.sql | 23 + .../vn/procedures/ticket_setParking.sql | 42 + .../vn/procedures/ticket_setPreviousState.sql | 32 + .../vn/procedures/ticket_setState.sql} | 2 +- db/routines/vn/procedures/ticket_split.sql | 78 + .../ticket_splitItemPackingType.sql | 106 + .../ticket_splitPackingComplete.sql | 42 + .../vn/procedures/timeBusiness_calculate.sql} | 3 +- .../procedures/timeBusiness_calculateAll.sql | 19 + .../timeBusiness_calculateByDepartment.sql | 25 + .../timeBusiness_calculateByUser.sql | 22 + .../timeBusiness_calculateByWorker.sql | 21 + .../vn/procedures/timeControl_calculate.sql} | 88 +- .../procedures/timeControl_calculateAll.sql | 19 + .../timeControl_calculateByDepartment.sql | 25 + .../timeControl_calculateByUser.sql | 22 + .../timeControl_calculateByWorker.sql | 22 + .../vn/procedures/timeControl_getError.sql | 70 + .../vn/procedures/timeWorkerControl_check.sql | 10 + .../procedures/tpvTransaction_checkStatus.sql | 24 + db/routines/vn/procedures/travelVolume.sql | 30 + .../vn/procedures/travelVolume_get.sql | 17 + .../vn/procedures/travel_checkDates.sql | 17 + .../vn/procedures/travel_checkPackaging.sql | 30 + .../travel_checkWarehouseIsFeedStock.sql | 17 + db/routines/vn/procedures/travel_clone.sql | 48 + .../vn/procedures/travel_cloneWithEntries.sql | 81 + db/routines/vn/procedures/travel_doRecalc.sql | 34 + .../travel_getEntriesMissingPackage.sql | 18 + .../vn/procedures/travel_moveRaids.sql | 72 + .../vn/procedures/travel_requestRecalc.sql | 15 + .../vn/procedures/travel_upcomingArrivals.sql | 81 + .../vn/procedures/travel_updatePacking.sql | 29 + .../vn/procedures/travel_weeklyClone.sql | 73 + db/routines/vn/procedures/typeTagMake.sql | 58 + .../vn/procedures/updatePedidosInternos.sql | 9 + .../procedures/vehicle_checkNumberPlate.sql | 17 + .../vn/procedures/vehicle_notifyEvents.sql | 51 + .../vn/procedures/visible_getMisfit.sql | 46 + .../vn/procedures/warehouseFitting.sql | 25 + .../procedures/warehouseFitting_byTravel.sql | 15 + .../vn/procedures/workerCalculateBoss.sql | 28 + .../workerCalendar_calculateBusiness.sql | 61 + .../workerCalendar_calculateYear.sql | 59 + .../vn/procedures/workerCreateExternal.sql | 29 + .../vn/procedures/workerDepartmentByDate.sql | 24 + db/routines/vn/procedures/workerDisable.sql | 32 + .../vn/procedures/workerDisableAll.sql | 36 + .../procedures/workerForAllCalculateBoss.sql | 33 + .../vn/procedures/workerJourney_replace.sql | 308 + .../vn/procedures/workerMistakeType_get.sql | 14 + .../vn/procedures/workerMistake_add.sql | 15 + .../vn/procedures/workerTimeControlAdd.sql | 14 + .../workerTimeControlPinGenerate.sql | 13 + .../vn/procedures/workerTimeControlSOWP.sql | 13 + .../procedures/workerTimeControlSetOrder.sql | 16 + .../vn/procedures/workerTimeControl_add.sql | 8 + .../workerTimeControl_calculateOddDays.sql | 34 + .../vn/procedures/workerTimeControl_check.sql | 168 + .../workerTimeControl_checkBreak.sql | 154 + .../procedures/workerTimeControl_clockIn.sql} | 2 +- .../workerTimeControl_direction.sql | 61 + .../workerTimeControl_getClockIn.sql | 78 + .../vn/procedures/workerTimeControl_login.sql | 26 + .../procedures/workerTimeControl_remove.sql | 49 + .../procedures/workerTimeControl_repair.sql | 39 + ...workerTimeControl_sendMailByDepartment.sql | 129 + ...meControl_sendMailByDepartmentLauncher.sql | 12 + .../procedures/workerTimeControl_setOrder.sql | 15 + .../workerTimeControl_weekCheckBreak.sql | 36 + .../vn/procedures/workerWeekControl.sql | 133 + .../procedures/worker_getFromHasMistake.sql | 19 + .../vn/procedures/worker_getHierarchy.sql | 27 + .../vn/procedures/worker_getSector.sql | 15 + .../vn/procedures/worker_updateBalance.sql | 13 + .../vn/procedures/worker_updateBusiness.sql | 28 + .../worker_updateChangedBusiness.sql | 40 + db/routines/vn/procedures/workingHours.sql | 16 + .../vn/procedures/workingHoursTimeIn.sql | 7 + .../vn/procedures/workingHoursTimeOut.sql | 9 + .../vn/procedures/wrongEqualizatedClient.sql | 27 + .../vn/procedures/zoneClosure_recalc.sql | 47 + .../vn/procedures/zoneGeo_calcTree.sql | 31 + .../vn/procedures/zoneGeo_calcTreeRec.sql | 69 + .../vn/procedures/zoneGeo_checkName.sql | 9 + db/routines/vn/procedures/zoneGeo_delete.sql | 13 + db/routines/vn/procedures/zoneGeo_doCalc.sql | 29 + .../vn/procedures/zoneGeo_setParent.sql | 16 + .../procedures/zoneGeo_throwNotEditable.sql | 7 + .../vn/procedures/zone_excludeFromGeo.sql | 20 + .../vn/procedures/zone_getAddresses.sql | 55 + db/routines/vn/procedures/zone_getAgency.sql | 36 + .../vn/procedures/zone_getAvailable.sql | 13 + db/routines/vn/procedures/zone_getClosed.sql | 34 + .../vn/procedures/zone_getCollisions.sql | 125 + db/routines/vn/procedures/zone_getEvents.sql | 64 + db/routines/vn/procedures/zone_getFromGeo.sql | 56 + db/routines/vn/procedures/zone_getLanded.sql | 47 + db/routines/vn/procedures/zone_getLeaves.sql | 123 + .../procedures/zone_getOptionsForLanding.sql | 64 + .../procedures/zone_getOptionsForShipment.sql | 75 + .../vn/procedures/zone_getPostalCode.sql | 46 + db/routines/vn/procedures/zone_getShipped.sql | 51 + db/routines/vn/procedures/zone_getState.sql | 42 + .../vn/procedures/zone_getWarehouse.sql | 37 + .../vn/procedures/zone_upcomingDeliveries.sql | 77 + db/routines/vn/triggers/BEFORE_INSERT.sql | 10 + .../vn/triggers/XDiario_beforeInsert.sql | 24 + .../vn/triggers/XDiario_beforeUpdate.sql} | 37 +- .../vn/triggers/address_afterDelete.sql | 12 + .../vn/triggers/address_afterInsert.sql | 12 + .../vn/triggers/address_afterUpdate.sql | 40 + .../vn/triggers/address_beforeInsert.sql | 27 + .../vn/triggers/address_beforeUpdate.sql | 18 + .../vn/triggers/agency_afterInsert.sql | 8 + db/routines/vn/triggers/autonomy_AD.sql | 8 + db/routines/vn/triggers/autonomy_BI.sql | 10 + db/routines/vn/triggers/autonomy_BU.sql | 16 + db/routines/vn/triggers/awb_bi.sql | 11 + .../vn/triggers/bankEntity_beforeInsert.sql | 8 + .../vn/triggers/bankEntity_beforeUpdate.sql | 10 + .../vn/triggers/budgetNotes_BeforeInsert.sql | 14 + .../vn/triggers/business_afterDelete.sql | 14 + .../vn/triggers/business_afterInsert.sql | 8 + .../vn/triggers/business_afterUpdate.sql | 12 + .../vn/triggers/business_beforeInsert.sql | 12 + .../vn/triggers/business_beforeUpdate.sql | 34 + db/routines/vn/triggers/buy_afterDelete.sql | 21 + db/routines/vn/triggers/buy_afterInsert.sql | 14 + .../vn/triggers/buy_afterUpdate.sql} | 2 +- db/routines/vn/triggers/buy_beforeDelete.sql | 10 + db/routines/vn/triggers/buy_beforeInsert.sql | 84 + db/routines/vn/triggers/buy_beforeUpdate.sql | 68 + .../triggers/claimBeginning_afterDelete.sql | 12 + .../triggers/claimBeginning_beforeInsert.sql | 8 + .../triggers/claimBeginning_beforeUpdate.sql | 8 + .../triggers/claimDevelopment_afterDelete.sql | 12 + .../claimDevelopment_beforeInsert.sql | 8 + .../claimDevelopment_beforeUpdate.sql | 8 + .../vn/triggers/claimDms_afterDelete.sql | 12 + .../vn/triggers/claimDms_beforeInsert.sql | 8 + .../vn/triggers/claimDms_beforeUpdate.sql | 8 + .../vn/triggers/claimEnd_afterDelete.sql | 12 + .../vn/triggers/claimEnd_beforeInsert.sql | 8 + .../vn/triggers/claimEnd_beforeUpdate.sql | 8 + .../triggers/claimObservation_afterDelete.sql | 12 + .../claimObservation_beforeInsert.sql | 8 + .../claimObservation_beforeUpdate.sql | 8 + .../vn/triggers/claimState_afterDelete.sql | 12 + .../vn/triggers/claimState_beforeInsert.sql | 8 + .../vn/triggers/claimState_beforeUpdate.sql | 8 + db/routines/vn/triggers/claim_afterDelete.sql | 12 + .../vn/triggers/claim_beforeInsert.sql | 8 + .../vn/triggers/claim_beforeUpdate.sql | 8 + .../vn/triggers/clientContact_afterDelete.sql | 12 + .../triggers/clientContact_beforeInsert.sql | 8 + .../vn/triggers/clientCredit_AfterInsert.sql | 23 + .../vn/triggers/clientDms_afterDelete.sql | 12 + .../vn/triggers/clientDms_beforeInsert.sql | 8 + .../vn/triggers/clientDms_beforeUpdate.sql | 8 + .../clientObservation_afterDelete.sql | 12 + .../clientObservation_beforeInsert.sql | 8 + .../clientObservation_beforeUpdate.sql | 8 + .../vn/triggers/clientSample_afterDelete.sql | 12 + .../vn/triggers/clientSample_beforeInsert.sql | 8 + .../vn/triggers/clientSample_beforeUpdate.sql | 8 + .../vn/triggers/client_AfterInsert.sql | 13 + .../vn/triggers/client_afterDelete.sql | 12 + .../vn/triggers/client_afterUpdate.sql | 27 + .../vn/triggers/client_beforeInsert.sql | 21 + .../vn/triggers/client_beforeUpdate.sql} | 32 +- db/routines/vn/triggers/cmr_beforeDelete.sql | 10 + .../collectionColors_beforeInsert.sql | 8 + .../collectionColors_beforeUpdate.sql | 8 + .../collectionVolumetry_afterDelete.sql | 26 + .../collectionVolumetry_afterInsert.sql | 26 + .../collectionVolumetry_afterUpdate.sql | 46 + .../vn/triggers/collection_BEFORE_UPDATE.sql | 36 + .../vn/triggers/country_AFTER_INSERT.sql | 19 + .../vn/triggers/country_afterDelete.sql | 8 + .../vn/triggers/country_afterUpdate.sql | 11 + .../vn/triggers/country_beforeInsert.sql | 8 + .../vn/triggers/country_beforeUpdate.sql | 10 + .../creditClassification_beforeUpdate.sql | 14 + .../triggers/creditInsurance_afterInsert.sql | 11 + .../triggers/creditInsurance_beforeInsert.sql | 10 + .../vn/triggers/department_afterDelete.sql | 14 + .../vn/triggers/department_afterUpdate.sql | 17 + .../vn/triggers/department_beforeDelete.sql | 13 + .../vn/triggers/department_beforeInsert.sql | 8 + .../deviceProductionConfig_afterUpdate.sql | 13 + .../deviceProductionModels_beforeInsert.sql | 8 + .../deviceProductionModels_beforeUpdate.sql | 8 + .../deviceProductionState_beforeInsert.sql | 8 + .../deviceProductionState_beforeUpdate.sql | 8 + .../deviceProductionUser_afterDelete.sql | 12 + .../deviceProductionUser_beforeInsert.sql | 8 + .../deviceProductionUser_beforeUpdate.sql | 8 + .../triggers/deviceProduction_afterDelete.sql | 12 + .../deviceProduction_beforeInsert.sql | 8 + .../deviceProduction_beforeUpdate.sql | 8 + db/routines/vn/triggers/dms_beforeDelete.sql | 16 + db/routines/vn/triggers/dms_beforeInsert.sql | 27 + db/routines/vn/triggers/dms_beforeUpdate.sql | 28 + .../vn/triggers/duaTax_BEFORE_INSERT.sql | 9 + .../vn/triggers/duaTax_BEFORE_UPDATE.sql | 9 + .../triggers/ektEntryAssign_afterInsert.sql | 6 + .../triggers/ektEntryAssign_afterUpdate.sql | 10 + .../triggers/entryObservation_afterDelete.sql | 12 + .../entryObservation_beforeInsert.sql | 8 + .../entryObservation_beforeUpdate.sql | 8 + db/routines/vn/triggers/entry_afterDelete.sql | 14 + db/routines/vn/triggers/entry_afterInsert.sql | 8 + db/routines/vn/triggers/entry_afterUpdate.sql | 17 + .../vn/triggers/entry_beforeDelete.sql | 8 + .../vn/triggers/entry_beforeInsert.sql | 12 + .../vn/triggers/entry_beforeUpdate.sql | 51 + .../expeditionPallet_BEFORE_INSERT.sql | 16 + .../triggers/expeditionScan_BEFORE_INSERT.sql | 10 + .../triggers/expeditionState_AfterInsert.sql | 12 + .../expeditionState_BeforeInsert.sql} | 5 - .../expeditionTruck_BEFORE_INSERT.sql | 10 + .../expeditionTruck_BEFORE_UPDATE.sql | 10 + .../vn/triggers/expedition_afterDelete.sql | 12 + .../vn/triggers/expedition_beforeDelete.sql | 12 + .../vn/triggers/expedition_beforeInsert.sql | 27 + .../vn/triggers/expedition_beforeUpdate.sql | 17 + .../floramondoConfig_AFTER_INSERT.sql | 8 + .../vn/triggers/gregue_beforeInsert.sql | 10 + .../vn/triggers/greuge_afterDelete.sql | 12 + .../vn/triggers/greuge_beforeInsert.sql | 8 + .../vn/triggers/greuge_beforeUpdate.sql | 8 + db/routines/vn/triggers/host_beforeUpdate.sql | 8 + .../triggers/invoiceInDueDay_afterDelete.sql | 12 + .../triggers/invoiceInDueDay_beforeInsert.sql | 30 + .../triggers/invoiceInDueDay_beforeUpdate.sql | 30 + .../vn/triggers/invoiceInTax_afterDelete.sql | 12 + .../vn/triggers/invoiceInTax_beforeInsert.sql | 9 + .../vn/triggers/invoiceInTax_beforeUpdate.sql | 12 + .../vn/triggers/invoiceIn_afterDelete.sql | 12 + db/routines/vn/triggers/invoiceIn_au.sql | 27 + db/routines/vn/triggers/invoiceIn_bi.sql | 52 + db/routines/vn/triggers/invoiceIn_bu.sql | 29 + .../vn/triggers/invoiceOut_afterInsert.sql} | 7 +- .../vn/triggers/invoiceOut_beforeDelete.sql | 8 + .../vn/triggers/invoiceOut_beforeInsert.sql | 32 + .../vn/triggers/invoiceOut_beforeUpdate.sql | 9 + .../vn/triggers/itemBarcode_afterDelete.sql | 12 + .../vn/triggers/itemBarcode_beforeInsert.sql | 8 + .../vn/triggers/itemBarcode_beforeUpdate.sql | 8 + .../vn/triggers/itemBotanical_afterDelete.sql | 12 + .../triggers/itemBotanical_beforeInsert.sql | 8 + .../triggers/itemBotanical_beforeUpdate.sql | 8 + .../vn/triggers/itemCategory_AFTER_INSERT.sql | 11 + .../vn/triggers/itemCost_beforeInsert.sql | 11 + .../vn/triggers/itemCost_beforeUpdate.sql | 30 + .../itemShelvingSale_AFTER_INSERT.sql | 12 + .../vn/triggers/itemShelving_AFTER_INSERT.sql | 22 + .../vn/triggers/itemShelving_AFTER_UPDATE.sql | 14 + .../triggers/itemShelving_BEFORE_DELETE.sql | 15 + .../triggers/itemShelving_BEFORE_INSERT.sql | 11 + .../triggers/itemShelving_BEFORE_UPDATE.sql | 10 + .../vn/triggers/itemTag_afterDelete.sql | 18 + .../vn/triggers/itemTag_afterInsert.sql | 12 + .../vn/triggers/itemTag_afterUpdate.sql | 24 + .../vn/triggers/itemTag_beforeInsert.sql | 9 + .../vn/triggers/itemTag_beforeUpdate.sql | 13 + .../triggers/itemTaxCountry_afterDelete.sql | 12 + .../triggers/itemTaxCountry_beforeInsert.sql | 8 + .../triggers/itemTaxCountry_beforeUpdate.sql | 8 + .../vn/triggers/itemType_beforeUpdate.sql | 18 + db/routines/vn/triggers/item_afterDelete.sql | 13 + db/routines/vn/triggers/item_afterInsert.sql | 16 + db/routines/vn/triggers/item_afterUpdate.sql | 11 + db/routines/vn/triggers/item_beforeInsert.sql | 18 + db/routines/vn/triggers/item_beforeUpdate.sql | 22 + db/routines/vn/triggers/machine_BI.sql | 10 + db/routines/vn/triggers/mail_beforeInsert.sql | 14 + .../vn/triggers/mandate_beforeInsert.sql | 12 + .../vn/triggers/operator_beforeInsert.sql | 8 + .../vn/triggers/operator_beforeUpdate.sql | 10 + .../vn/triggers/packaging_beforeInsert.sql | 8 + .../vn/triggers/packaging_beforeUpdate.sql | 8 + .../vn/triggers/packingSite_afterDelete.sql | 12 + .../vn/triggers/packingSite_beforeInsert.sql | 8 + .../vn/triggers/packingSite_beforeUpdate.sql | 8 + .../vn/triggers/parking_BEFORE_INSERT.sql | 10 + .../vn/triggers/parking_BEFORE_UPDATE.sql | 10 + .../vn/triggers/payment_afterInsert.sql | 34 + .../vn/triggers/payment_beforeInsert.sql | 94 + .../vn/triggers/payment_beforeUpdate.sql | 10 + .../vn/triggers/postCode_afterDelete.sql | 8 + .../vn/triggers/postCode_afterUpdate.sql | 16 + .../vn/triggers/postCode_beforeInsert.sql | 9 + .../vn/triggers/postCode_beforeUpdate.sql | 10 + .../vn/triggers/priceFixed_beforeInsert.sql | 13 + .../vn/triggers/priceFixed_beforeUpdate.sql | 13 + .../vn/triggers/projectNotes_BeforeInsert.sql | 14 + .../vn/triggers/province_afterDelete.sql | 8 + .../vn/triggers/province_afterUpdate.sql | 16 + .../vn/triggers/province_beforeInsert.sql | 13 + .../vn/triggers/province_beforeUpdate.sql | 14 + db/routines/vn/triggers/rate_afterDelete.sql | 12 + db/routines/vn/triggers/rate_beforeInsert.sql | 8 + db/routines/vn/triggers/rate_beforeUpdate.sql | 8 + .../vn/triggers/receipt_afterInsert.sql | 6 + .../vn/triggers/receipt_afterUpdate.sql | 15 + .../vn/triggers/receipt_beforeDelete.sql | 6 + .../vn/triggers/receipt_beforeInsert.sql | 17 + .../vn/triggers/receipt_beforeUpdate.sql | 10 + .../vn/triggers/recovery_afterDelete.sql | 12 + .../vn/triggers/recovery_beforeInsert.sql | 8 + .../vn/triggers/recovery_beforeUpdate.sql | 8 + db/routines/vn/triggers/route_afterDelete.sql | 12 + db/routines/vn/triggers/route_afterInsert.sql | 8 + db/routines/vn/triggers/route_afterUpdate.sql | 29 + .../vn/triggers/route_beforeInsert.sql | 29 + .../vn/triggers/route_beforeUpdate.sql | 29 + .../vn/triggers/routesMonitor_afterDelete.sql | 12 + .../triggers/routesMonitor_beforeInsert.sql | 8 + .../triggers/routesMonitor_beforeUpdate.sql | 8 + db/routines/vn/triggers/saleBuy_AI.sql | 13 + .../vn/triggers/saleTracking_After_Insert.sql | 17 + .../vn/triggers/sale_BEFORE_DELETE.sql | 18 + db/routines/vn/triggers/sale_afterDelete.sql | 48 + db/routines/vn/triggers/sale_afterInsert.sql | 34 + .../vn/triggers/sale_afterUpdate.sql} | 47 +- db/routines/vn/triggers/sale_beforeInsert.sql | 9 + db/routines/vn/triggers/sale_beforeUpdate.sql | 23 + .../vn/triggers/sharingCart_beforeDelete.sql | 11 + .../vn/triggers/sharingCart_beforeInsert.sql | 15 + .../vn/triggers/sharingCart_beforeUpdate.sql | 21 + .../triggers/sharingClient_beforeInsert.sql | 9 + .../triggers/sharingClient_beforeUpdate.sql | 9 + .../vn/triggers/shelving_BEFORE_UPDATE.sql | 16 + .../vn/triggers/shelving_afterDelete.sql | 12 + .../vn/triggers/shelving_beforeInsert.sql | 13 + .../vn/triggers/solunionCAP_AFTER_INSERT.sql | 11 + .../vn/triggers/solunionCAP_AFTER_UPDATE.sql | 18 + .../vn/triggers/solunionCAP_BEFORE_DELETE.sql | 11 + .../vn/triggers/specie_BEFORE_INSERT.sql | 8 + .../vn/triggers/specie_BEFORE_UPDATE.sql | 8 + .../triggers/supplierAccount_afterDelete.sql | 12 + .../triggers/supplierAccount_beforeInsert.sql | 8 + .../triggers/supplierAccount_beforeUpdate.sql | 8 + .../triggers/supplierAddress_afterDelete.sql | 12 + .../triggers/supplierAddress_beforeInsert.sql | 8 + .../triggers/supplierAddress_beforeUpdate.sql | 8 + .../triggers/supplierContact_afterDelete.sql | 12 + .../triggers/supplierContact_beforeInsert.sql | 8 + .../triggers/supplierContact_beforeUpdate.sql | 8 + .../vn/triggers/supplier_afterDelete.sql | 12 + .../vn/triggers/supplier_beforeInsert.sql | 8 + .../vn/triggers/supplier_beforeUpdate.sql} | 8 +- db/routines/vn/triggers/tag_BEFORE_INSERT.sql | 10 + .../triggers/ticketCollection_afterDelete.sql | 28 + .../vn/triggers/ticketDms_afterDelete.sql | 12 + .../vn/triggers/ticketDms_beforeDelete.sql | 16 + .../vn/triggers/ticketDms_beforeInsert.sql | 8 + .../vn/triggers/ticketDms_beforeUpdate.sql | 8 + .../ticketObservation_afterDelete.sql | 12 + .../ticketObservation_beforeInsert.sql | 8 + .../ticketObservation_beforeUpdate.sql | 8 + .../ticketPackaging_BEFORE_INSERT.sql | 10 + .../triggers/ticketPackaging_afterDelete.sql | 12 + .../triggers/ticketPackaging_beforeUpdate.sql | 8 + .../triggers/ticketParking_BEFORE_INSERT.sql | 10 + .../vn/triggers/ticketRefund_afterDelete.sql | 12 + .../vn/triggers/ticketRefund_beforeInsert.sql | 9 + .../vn/triggers/ticketRefund_beforeUpdate.sql | 9 + .../vn/triggers/ticketRequest_afterDelete.sql | 12 + .../triggers/ticketRequest_beforeInsert.sql | 20 + .../triggers/ticketRequest_beforeUpdate.sql | 20 + db/routines/vn/triggers/ticketService_ad.sql | 15 + db/routines/vn/triggers/ticketService_ai.sql | 10 + db/routines/vn/triggers/ticketService_au.sql | 13 + .../triggers/ticketService_beforeInsert.sql | 8 + .../triggers/ticketService_beforeUpdate.sql | 8 + .../triggers/ticketTracking_afterDelete.sql | 40 + .../triggers/ticketTracking_afterInsert.sql | 13 + .../triggers/ticketTracking_afterUpdate.sql | 32 + .../triggers/ticketTracking_beforeInsert.sql | 8 + .../triggers/ticketTracking_beforeUpdate.sql | 8 + .../vn/triggers/ticketWeekly_afterDelete.sql | 12 + .../vn/triggers/ticketWeekly_beforeInsert.sql | 8 + .../vn/triggers/ticketWeekly_beforeUpdate.sql | 8 + .../vn/triggers/ticket_afterDelete.sql | 12 + .../vn/triggers/ticket_afterInsert.sql | 38 + .../vn/triggers/ticket_afterUpdate.sql | 26 + .../vn/triggers/ticket_beforeDelete.sql | 18 + .../vn/triggers/ticket_beforeInsert.sql | 8 + .../vn/triggers/ticket_beforeUpdate.sql | 77 + db/routines/vn/triggers/time_AFTER_UPDATE.sql | 13 + db/routines/vn/triggers/town_afterDelete.sql | 8 + db/routines/vn/triggers/town_afterUpdate.sql | 16 + db/routines/vn/triggers/town_beforeInsert.sql | 9 + db/routines/vn/triggers/town_beforeUpdate.sql | 10 + .../travelThermograph_afterDelete.sql | 12 + .../travelThermograph_beforeInsert.sql | 8 + .../travelThermograph_beforeUpdate.sql | 8 + .../vn/triggers/travel_afterDelete.sql | 12 + .../vn/triggers/travel_afterUpdate.sql | 14 + .../vn/triggers/travel_beforeInsert.sql | 21 + .../vn/triggers/travel_beforeUpdate.sql | 38 + .../vn/triggers/vehicle_beforeInsert.sql | 8 + .../vn/triggers/vehicle_beforeUpdate.sql | 8 + .../vn/triggers/warehouse_afterInsert.sql | 10 + .../vn/triggers/warehouse_afterUpdate.sql | 12 + .../triggers/workerDocument_afterDelete.sql | 12 + .../triggers/workerDocument_beforeInsert.sql | 8 + .../triggers/workerDocument_beforeUpdate.sql | 8 + .../vn/triggers/workerIncome_afterDelete.sql | 8 + .../vn/triggers/workerIncome_afterInsert.sql | 8 + .../vn/triggers/workerIncome_afterUpdate.sql | 10 + .../vn/triggers/workerTimeControl_AI.sql | 10 + .../vn/triggers/worker_afterDelete.sql | 12 + .../vn/triggers/worker_beforeInsert.sql | 8 + .../vn/triggers/worker_beforeUpdate.sql | 8 + .../vn/triggers/workingHoursBeforeInsert.sql | 10 + .../vn/triggers/zoneEvent_afterDelete.sql | 12 + .../vn/triggers/zoneEvent_beforeInsert.sql | 8 + .../vn/triggers/zoneEvent_beforeUpdate.sql | 8 + db/routines/vn/triggers/zoneExclusion_BI.sql | 10 + db/routines/vn/triggers/zoneExclusion_BU.sql | 10 + .../vn/triggers/zoneExclusion_afterDelete.sql | 12 + .../vn/triggers/zoneGeo_beforeInsert.sql | 8 + .../vn/triggers/zoneGeo_beforeUpdate.sql | 10 + .../vn/triggers/zoneIncluded_afterDelete.sql | 12 + .../vn/triggers/zoneIncluded_beforeInsert.sql | 8 + .../vn/triggers/zoneIncluded_beforeUpdate.sql | 8 + .../vn/triggers/zoneWarehouse_afterDelete.sql | 12 + .../triggers/zoneWarehouse_beforeInsert.sql | 8 + .../triggers/zoneWarehouse_beforeUpdate.sql | 8 + db/routines/vn/triggers/zone_afterDelete.sql | 12 + db/routines/vn/triggers/zone_beforeInsert.sql | 8 + db/routines/vn/triggers/zone_beforeUpdate.sql | 8 + db/routines/vn/views/NewView.sql | 19 + db/routines/vn/views/__coolerPathDetail.sql | 7 + db/routines/vn/views/agencyTerm.sql | 12 + db/routines/vn/views/agencyWarehouse.sql | 7 + .../vn/views/annualAverageInvoiced.sql | 6 + db/routines/vn/views/awbVolume.sql | 36 + db/routines/vn/views/bank.sql | 12 + db/routines/vn/views/bankPolicy.sql | 24 + db/routines/vn/views/businessCalendar.sql | 8 + db/routines/vn/views/buyer.sql | 11 + db/routines/vn/views/buyerSales.sql | 17 + db/routines/vn/views/clientDefaultCompany.sql | 9 + db/routines/vn/views/clientLost.sql | 19 + db/routines/vn/views/clientPhoneBook.sql | 41 + db/routines/vn/views/companyL10n.sql | 12 + db/routines/vn/views/coolerPath.sql | 6 + db/routines/vn/views/defaulter.sql | 20 + db/routines/vn/views/departmentTree.sql | 17 + db/routines/vn/views/doc.sql | 14 + db/routines/vn/views/ediGenus.sql | 9 + db/routines/vn/views/ediSpecie.sql | 10 + db/routines/vn/views/ektSubAddress.sql | 12 + db/routines/vn/views/especialPrice.sql | 8 + db/routines/vn/views/exchangeInsurance.sql | 16 + .../vn/views/exchangeInsuranceEntry.sql | 28 + db/routines/vn/views/exchangeInsuranceIn.sql | 12 + .../vn/views/exchangeInsuranceInPrevious.sql | 9 + db/routines/vn/views/exchangeInsuranceOut.sql | 17 + db/routines/vn/views/exchangeReportSource.sql | 22 + .../vn/views/exchangeReportSourcePrevious.sql | 29 + db/routines/vn/views/expeditionCommon.sql | 31 + .../vn/views/expeditionPallet_Print.sql | 39 + .../vn/views/expeditionRoute_Monitor.sql | 27 + .../vn/views/expeditionRoute_freeTickets.sql | 17 + .../vn/views/expeditionScan_Monitor.sql | 19 + db/routines/vn/views/expeditionSticker.sql | 61 + .../vn/views/expeditionTicket_NoBoxes.sql | 19 + .../vn/views/expeditionTimeExpended.sql | 18 + .../vn/views/expeditionTruck_Control.sql | 19 + .../views/expeditionTruck_Control_Detail.sql | 18 + .../expeditionTruck_Control_Detail_Pallet.sql | 22 + db/routines/vn/views/firstTicketShipped.sql | 8 + .../vn/views/floraHollandBuyedItems.sql | 31 + db/routines/vn/views/grantGroup.sql | 7 + db/routines/vn/views/inkL10n.sql | 12 + .../vn/views/invoiceCorrectionDataSource.sql | 16 + .../vn/views/itemBotanicalWithGenus.sql | 12 + db/routines/vn/views/itemCategoryL10n.sql | 12 + db/routines/vn/views/itemColor.sql | 10 + db/routines/vn/views/itemEntryIn.sql | 19 + db/routines/vn/views/itemEntryOut.sql | 19 + db/routines/vn/views/itemInk.sql | 12 + .../vn/views/itemPlacementSupplyList.sql | 34 + db/routines/vn/views/itemProductor.sql | 10 + db/routines/vn/views/itemSearch.sql | 17 + .../vn/views/itemShelvingAvailable.sql | 59 + db/routines/vn/views/itemShelvingList.sql | 24 + .../itemShelvingPlacementSupplyStock.sql | 27 + db/routines/vn/views/itemShelvingSaleSum.sql | 20 + db/routines/vn/views/itemShelvingStock.sql | 27 + .../vn/views/itemShelvingStockFull.sql | 29 + .../vn/views/itemShelvingStockRemoved.sql | 14 + db/routines/vn/views/itemTagged.sql | 5 + db/routines/vn/views/itemTaxCountrySpain.sql | 20 + db/routines/vn/views/itemTicketOut.sql | 17 + db/routines/vn/views/itemTypeL10n.sql | 12 + db/routines/vn/views/item_Free_Id.sql | 10 + db/routines/vn/views/labelInfo.sql | 35 + db/routines/vn/views/lastHourProduction.sql | 25 + db/routines/vn/views/lastPurchases.sql | 35 + db/routines/vn/views/lastTopClaims.sql | 38 + db/routines/vn/views/mistake.sql | 27 + db/routines/vn/views/mistakeRatio.sql | 24 + db/routines/vn/views/newBornSales.sql | 26 + db/routines/vn/views/operatorWorkerCode.sql | 22 + db/routines/vn/views/originL10n.sql | 12 + .../vn/views/packageEquivalentItem.sql | 12 + .../vn/views/paymentExchangeInsurance.sql | 16 + db/routines/vn/views/payrollCenter.sql | 12 + db/routines/vn/views/personMedia.sql | 10 + db/routines/vn/views/phoneBook.sql | 22 + db/routines/vn/views/preparationException.sql | 7 + db/routines/vn/views/productionVolume.sql | 23 + .../vn/views/productionVolume_LastHour.sql | 11 + db/routines/vn/views/promissoryNote.sql | 7 + db/routines/vn/views/role.sql | 8 + db/routines/vn/views/routesControl.sql | 27 + db/routines/vn/views/saleCost.sql | 22 + db/routines/vn/views/saleLabel.sql | 8 + db/routines/vn/views/saleMistakeList.sql | 29 + db/routines/vn/views/saleMistake_list__2.sql | 29 + db/routines/vn/views/saleSaleTracking.sql | 6 + db/routines/vn/views/saleValue.sql | 50 + db/routines/vn/views/saleVolume.sql | 45 + db/routines/vn/views/saleVolume_Today_VNH.sql | 27 + .../vn/views/sale_freightComponent.sql | 21 + db/routines/vn/views/salesPersonSince.sql | 16 + .../vn/views/salesPreparedLastHour.sql | 46 + .../vn/views/salesPreviousPreparated.sql | 10 + db/routines/vn/views/supplierPackaging.sql | 33 + db/routines/vn/views/tagL10n.sql | 12 + db/routines/vn/views/ticketDownBuffer.sql | 22 + db/routines/vn/views/ticketLastUpdated.sql | 7 + .../vn/views/ticketLastUpdatedList.sql | 23 + db/routines/vn/views/ticketMRW.sql | 47 + db/routines/vn/views/ticketNotInvoiced.sql | 26 + db/routines/vn/views/ticketPackingList.sql | 38 + .../vn/views/ticketPreviousPreparingList.sql | 36 + db/routines/vn/views/ticketState.sql | 22 + db/routines/vn/views/ticketStateToday.sql | 16 + db/routines/vn/views/ticketToPrepare.sql | 58 + .../vn/views/ticketeToPreparePrepared.sql | 47 + db/routines/vn/views/tr2.sql | 19 + db/routines/vn/views/traceabilityBuy.sql | 23 + db/routines/vn/views/traceabilitySale.sql | 19 + db/routines/vn/views/unary.sql | 6 + db/routines/vn/views/unaryScan.sql | 8 + db/routines/vn/views/unaryScanLine.sql | 8 + db/routines/vn/views/unaryScanLineBuy.sql | 6 + .../vn/views/unaryScanLineExpedition.sql | 6 + db/routines/vn/views/warehouseJoined.sql | 6 + db/routines/vn/views/workerBusinessDated.sql | 13 + db/routines/vn/views/workerDepartment.sql | 9 + db/routines/vn/views/workerLabour.sql | 12 + db/routines/vn/views/workerMedia.sql | 7 + .../vn/views/workerSpeedExpedition.sql | 25 + .../vn/views/workerSpeedSaleTracking.sql | 29 + db/routines/vn/views/workerTeamCollegues.sql | 9 + .../vn/views/workerTimeControlUserInfo.sql | 20 + db/routines/vn/views/workerTimeJourneyNG.sql | 13 + db/routines/vn/views/workerWithoutTractor.sql | 20 + .../vn/views/zoneEstimatedDelivery.sql | 48 + db/routines/vn2008/events/raidUpdate.sql | 8 + db/routines/vn2008/functions/cc_to_iban.sql | 49 + .../vn2008/functions/intrastat_neto.sql | 20 + db/routines/vn2008/functions/nz.sql | 14 + db/routines/vn2008/functions/red.sql | 14 + .../vn2008/procedures/Cajas_Saldo_Detalle.sql | 51 + .../vn2008/procedures/CalculoRemesas.sql | 66 + .../procedures/CompresTriggerBeforeDelete.sql | 21 + .../EntradasTriggerBeforeDelete.sql | 18 + .../EntradasTriggerBeforeUpdate.sql | 28 + .../vn2008/procedures/Facturas_Saltos.sql | 65 + .../vn2008/procedures/InsertarEspionaje.sql | 26 + .../procedures/ListaTicketsEncajados.sql | 25 + db/routines/vn2008/procedures/Rutas_Graph.sql | 46 + db/routines/vn2008/procedures/Trabuque.sql | 72 + ...Vehiculos_consumo_calculateLiters100km.sql | 42 + .../vn2008/procedures/XDiario_Quadrator.sql | 34 + .../procedures/account_conciliacion_add.sql | 33 + .../vn2008/procedures/add_awb_component.sql | 64 + .../vn2008/procedures/agencia_descuadre.sql | 32 + .../vn2008/procedures/agencia_volume.sql | 44 + .../vn2008/procedures/agencyModeImbalance.sql | 50 + db/routines/vn2008/procedures/article.sql | 15 + .../procedures/article_available_single.sql | 13 + .../procedures/article_multiple_buy.sql | 6 + .../procedures/article_multiple_buy_date.sql | 9 + .../vn2008/procedures/availableTraslate.sql | 126 + .../vn2008/procedures/balance_create.sql | 207 + db/routines/vn2008/procedures/base_ticket.sql | 12 + .../bionic_available_types_filter.sql | 38 + db/routines/vn2008/procedures/buy_label.sql | 40 + db/routines/vn2008/procedures/buy_split.sql | 150 + db/routines/vn2008/procedures/buy_tarifas.sql | 6 + .../vn2008/procedures/buy_tarifas_entry.sql | 11 + .../buy_tarifas_recalcular_almacen.sql | 36 + .../vn2008/procedures/buy_transfer.sql | 104 + db/routines/vn2008/procedures/cacheReset.sql | 11 + db/routines/vn2008/procedures/camiones.sql | 23 + .../procedures/check_table_existence.sql | 16 + db/routines/vn2008/procedures/clean.sql | 95 + .../vn2008/procedures/clean_launcher.sql | 6 + db/routines/vn2008/procedures/cobro.sql | 79 + .../vn2008/procedures/comercial_caducado.sql | 57 + .../procedures/compresTriggerBeforeInsert.sql | 17 + .../procedures/compresTriggerBeforeUpdate.sql | 36 + .../procedures/confection_control_source.sql | 105 + .../vn2008/procedures/createBouquet.sql | 50 + .../vn2008/procedures/credit_update.sql | 17 + .../procedures/customerDebtEvolution.sql | 49 + .../vn2008/procedures/desglose_volume.sql | 82 + .../emailYesterdayPurchasesByConsigna.sql | 87 + .../emailYesterdayPurchasesLauncher.sql | 27 + .../vn2008/procedures/embalajes_stocks.sql | 51 + .../procedures/embalajes_stocks_detalle.sql | 78 + .../vn2008/procedures/entryFromOrder.sql | 55 + .../vn2008/procedures/entryFromTicket.sql | 62 + .../vn2008/procedures/eti_to_print.sql | 24 + .../vn2008/procedures/f10_no_vincular.sql | 60 + .../vn2008/procedures/historico_absoluto.sql | 91 + .../vn2008/procedures/historico_joined.sql | 88 + .../vn2008/procedures/historico_multiple.sql | 206 + .../vn2008/procedures/inventario_valorado.sql | 185 + db/routines/vn2008/procedures/item_buy.sql | 32 + .../vn2008/procedures/item_express.sql | 41 + db/routines/vn2008/procedures/item_new.sql | 11 + db/routines/vn2008/procedures/malpagantes.sql | 44 + db/routines/vn2008/procedures/mensaje.sql | 13 + db/routines/vn2008/procedures/msg.sql | 21 + .../vn2008/procedures/nest_child_add.sql | 48 + db/routines/vn2008/procedures/nest_delete.sql | 51 + db/routines/vn2008/procedures/nest_move.sql | 108 + db/routines/vn2008/procedures/newItem.sql | 34 + db/routines/vn2008/procedures/niching.sql | 49 + .../vn2008/procedures/notify_passport.sql | 12 + db/routines/vn2008/procedures/pay.sql | 67 + db/routines/vn2008/procedures/percentil.sql | 30 + .../vn2008/procedures/preOrdenarRuta.sql | 22 + .../vn2008/procedures/prepare_client_list.sql | 11 + .../vn2008/procedures/prepare_ticket_list.sql | 22 + db/routines/vn2008/procedures/proc_end.sql | 11 + db/routines/vn2008/procedures/proc_start.sql | 13 + .../vn2008/procedures/prueba_miguel.sql | 6 + .../vn2008/procedures/quadre_clientes.sql | 67 + .../procedures/quadre_clientes_detalle.sql | 70 + db/routines/vn2008/procedures/raidUpdate.sql | 28 + db/routines/vn2008/procedures/rateView.sql | 37 + .../vn2008/procedures/recibidaIvaInsert.sql | 39 + .../vn2008/procedures/recobro_credito.sql | 55 + .../vn2008/procedures/risk_vs_client_list.sql | 84 + .../vn2008/procedures/scan_rutas_view.sql | 31 + .../procedures/sort_merge_passes_ernesto.sql | 85 + .../vn2008/procedures/splitAnthuriums2016.sql | 86 + db/routines/vn2008/procedures/subordinate.sql | 46 + .../vn2008/procedures/supplierStatement.sql | 117 + .../vn2008/procedures/suppliersDebt.sql | 35 + db/routines/vn2008/procedures/top_seller.sql | 113 + db/routines/vn2008/procedures/traslado.sql | 182 + .../vn2008/procedures/travelDetail.sql | 119 + .../procedures/travel_tree_shipment.sql | 37 + .../vn2008/procedures/unary_delete.sql | 30 + .../vn2008/procedures/unary_insert.sql | 17 + .../vn2008/procedures/unary_leaves.sql | 58 + .../vn2008/procedures/unary_scan_ident.sql | 25 + .../vn2008/procedures/unary_scan_insert.sql | 20 + db/routines/vn2008/procedures/unary_tops.sql | 19 + .../vn2008/procedures/unary_update.sql | 32 + db/routines/vn2008/triggers/Conteo_ai.sql | 14 + .../account_conciliacion_BEFORE_INSERT.sql | 14 + .../triggers/agency_hourBeforeInsert.sql | 21 + .../triggers/agency_hour_AFTER_UPDATE.sql | 18 + .../vn2008/triggers/awb_recibida_ad.sql | 13 + .../vn2008/triggers/movement_label_au.sql | 8 + db/routines/vn2008/views/Agencias.sql | 18 + db/routines/vn2008/views/Articles.sql | 52 + .../vn2008/views/Articles_botanical.sql | 7 + db/routines/vn2008/views/Bancos.sql | 11 + db/routines/vn2008/views/Cajas.sql | 24 + db/routines/vn2008/views/Clientes.sql | 49 + db/routines/vn2008/views/Comparativa.sql | 10 + db/routines/vn2008/views/Compres.sql | 33 + db/routines/vn2008/views/Compres_mark.sql | 8 + db/routines/vn2008/views/Consignatarios.sql | 19 + db/routines/vn2008/views/Cubos.sql | 21 + db/routines/vn2008/views/Cubos_Retorno.sql | 8 + db/routines/vn2008/views/Entradas.sql | 29 + db/routines/vn2008/views/Entradas_Auto.sql | 5 + db/routines/vn2008/views/Equipos.sql | 8 + db/routines/vn2008/views/Facturas.sql | 20 + db/routines/vn2008/views/Gastos.sql | 7 + db/routines/vn2008/views/Greuges.sql | 12 + db/routines/vn2008/views/Greuges_type.sql | 6 + db/routines/vn2008/views/Impresoras.sql | 9 + db/routines/vn2008/views/Intrastat.sql | 8 + db/routines/vn2008/views/Monedas.sql | 8 + db/routines/vn2008/views/Movimientos.sql | 18 + .../vn2008/views/Movimientos_componentes.sql | 9 + db/routines/vn2008/views/Movimientos_mark.sql | 11 + db/routines/vn2008/views/Ordenes.sql | 23 + db/routines/vn2008/views/Origen.sql | 9 + db/routines/vn2008/views/Paises.sql | 13 + .../vn2008/views/PreciosEspeciales.sql | 8 + db/routines/vn2008/views/Prioridades.sql | 6 + db/routines/vn2008/views/Proveedores.sql | 35 + db/routines/vn2008/views/Recibos.sql | 14 + db/routines/vn2008/views/Rutas.sql | 19 + db/routines/vn2008/views/Rutas_Master | 24 + db/routines/vn2008/views/Rutas_Master.sql | 22 + db/routines/vn2008/views/Rutas_monitor.sql | 18 + db/routines/vn2008/views/Tickets.sql | 33 + db/routines/vn2008/views/Tickets_state.sql | 7 + db/routines/vn2008/views/Tickets_turno.sql | 6 + db/routines/vn2008/views/Tintas.sql | 11 + db/routines/vn2008/views/Tipos.sql | 22 + db/routines/vn2008/views/Trabajadores.sql | 16 + db/routines/vn2008/views/V_edi_item_track.sql | 19 + db/routines/vn2008/views/Vehiculos.sql | 14 + db/routines/vn2008/views/VerEspionaje.sql | 17 + db/routines/vn2008/views/Vistas.sql | 7 + db/routines/vn2008/views/XDiario.sql | 56 + db/routines/vn2008/views/agency.sql | 10 + db/routines/vn2008/views/awb.sql | 33 + db/routines/vn2008/views/barcodes.sql | 7 + .../vn2008/views/bionic_updating_options.sql | 6 + .../vn2008/views/businessReasonEnd.sql | 6 + db/routines/vn2008/views/buySource.sql | 77 + db/routines/vn2008/views/buy_edi.sql | 41 + db/routines/vn2008/views/cdr.sql | 20 + db/routines/vn2008/views/chanel.sql | 6 + db/routines/vn2008/views/cl_act.sql | 10 + db/routines/vn2008/views/cl_cau.sql | 12 + db/routines/vn2008/views/cl_con.sql | 6 + db/routines/vn2008/views/cl_det.sql | 8 + db/routines/vn2008/views/cl_dev.sql | 6 + db/routines/vn2008/views/cl_est.sql | 7 + db/routines/vn2008/views/cl_main.sql | 14 + db/routines/vn2008/views/cl_mot.sql | 6 + db/routines/vn2008/views/cl_res.sql | 7 + db/routines/vn2008/views/cl_sol.sql | 7 + .../vn2008/views/client_observation.sql | 9 + db/routines/vn2008/views/clientes_gestdoc.sql | 6 + .../vn2008/views/clientes_regalos_enc.sql | 7 + .../views/clientes_regalos_lista_enc.sql | 17 + db/routines/vn2008/views/clientes_tipo.sql | 8 + db/routines/vn2008/views/config_host.sql | 11 + .../views/consignatarios_observation.sql | 8 + .../vn2008/views/cooler_path_detail.sql | 7 + db/routines/vn2008/views/credit.sql | 9 + db/routines/vn2008/views/deliveryPoint.sql | 7 + db/routines/vn2008/views/device_user.sql | 6 + db/routines/vn2008/views/edi_article.sql | 12 + db/routines/vn2008/views/edi_bucket.sql | 15 + db/routines/vn2008/views/edi_bucket_type.sql | 9 + db/routines/vn2008/views/edi_feature.sql | 10 + db/routines/vn2008/views/edi_genus.sql | 9 + db/routines/vn2008/views/edi_item_feature.sql | 11 + db/routines/vn2008/views/edi_plant.sql | 10 + db/routines/vn2008/views/edi_specie.sql | 10 + db/routines/vn2008/views/edi_supplier.sql | 6 + db/routines/vn2008/views/edi_type.sql | 10 + db/routines/vn2008/views/edi_value.sql | 10 + db/routines/vn2008/views/empresa.sql | 24 + db/routines/vn2008/views/empresa_grupo.sql | 6 + db/routines/vn2008/views/entrySource.sql | 55 + db/routines/vn2008/views/escritos.sql | 9 + db/routines/vn2008/views/escritos_det.sql | 12 + db/routines/vn2008/views/expeditions.sql | 16 + db/routines/vn2008/views/gestdoc.sql | 16 + db/routines/vn2008/views/gesttip.sql | 10 + db/routines/vn2008/views/intrastat_data.sql | 13 + .../vn2008/views/invoiceCorrection.sql | 9 + db/routines/vn2008/views/itemTag.sql | 9 + db/routines/vn2008/views/item_entry_in.sql | 20 + db/routines/vn2008/views/item_entry_out.sql | 27 + db/routines/vn2008/views/item_out.sql | 17 + db/routines/vn2008/views/iva_codigo.sql | 15 + db/routines/vn2008/views/iva_group.sql | 7 + db/routines/vn2008/views/iva_group_codigo.sql | 7 + db/routines/vn2008/views/iva_tipo.sql | 11 + db/routines/vn2008/views/mail.sql | 16 + db/routines/vn2008/views/mandato.sql | 11 + db/routines/vn2008/views/mandato_tipo.sql | 6 + db/routines/vn2008/views/observation_type.sql | 6 + db/routines/vn2008/views/order.sql | 15 + db/routines/vn2008/views/order_Tickets.sql | 6 + db/routines/vn2008/views/order_component.sql | 7 + db/routines/vn2008/views/order_row.sql | 14 + db/routines/vn2008/views/pago.sql | 18 + db/routines/vn2008/views/pay_dem.sql | 6 + db/routines/vn2008/views/pay_dem_det.sql | 6 + db/routines/vn2008/views/pay_met.sql | 10 + .../vn2008/views/payroll_categorias.sql | 7 + db/routines/vn2008/views/person_user.sql | 10 + .../vn2008/views/person_user_idtrabajador.sql | 9 + db/routines/vn2008/views/plantpassport.sql | 8 + .../vn2008/views/plantpassport_authority.sql | 7 + db/routines/vn2008/views/price_fixed.sql | 18 + db/routines/vn2008/views/producer.sql | 7 + .../vn2008/views/proveedores_clientes.sql | 11 + db/routines/vn2008/views/province.sql | 10 + db/routines/vn2008/views/recibida.sql | 26 + .../vn2008/views/recibida_intrastat.sql | 7 + db/routines/vn2008/views/recibida_iva.sql | 13 + .../vn2008/views/recibida_vencimiento.sql | 11 + db/routines/vn2008/views/recovery.sql | 10 + db/routines/vn2008/views/reference_min.sql | 7 + db/routines/vn2008/views/reference_rate.sql | 7 + db/routines/vn2008/views/reinos.sql | 12 + db/routines/vn2008/views/sharingcart.sql | 10 + db/routines/vn2008/views/sharingclient.sql | 9 + db/routines/vn2008/views/sms.sql | 12 + db/routines/vn2008/views/state.sql | 13 + db/routines/vn2008/views/tag.sql | 10 + .../vn2008/views/tarifa_componentes.sql | 10 + .../views/tarifa_componentes_series.sql | 7 + db/routines/vn2008/views/tarifas.sql | 11 + db/routines/vn2008/views/tblContadores.sql | 39 + db/routines/vn2008/views/thermograph.sql | 6 + .../vn2008/views/ticketCreationData.sql | 9 + db/routines/vn2008/views/ticketMRW.sql | 38 + .../vn2008/views/ticket_observation.sql | 8 + db/routines/vn2008/views/tickets_gestdoc.sql | 6 + db/routines/vn2008/views/time.sql | 11 + db/routines/vn2008/views/tr2.sql | 19 + db/routines/vn2008/views/travel.sql | 20 + .../vn2008/views/travel_thermograph.sql | 11 + .../vn2008/views/v_Articles_botanical.sql | 15 + db/routines/vn2008/views/v_account.sql | 5 + .../vn2008/views/v_analisis_ventas.sql | 15 + db/routines/vn2008/views/v_barcodes.sql | 21 + db/routines/vn2008/views/v_compres.sql | 90 + .../vn2008/views/v_departure_limit.sql | 8 + .../vn2008/views/v_descuadre_bionic.sql | 41 + db/routines/vn2008/views/v_empresa.sql | 25 + db/routines/vn2008/views/v_inter.sql | 11 + db/routines/vn2008/views/v_jerarquia.sql | 10 + db/routines/vn2008/views/v_miriam.sql | 23 + db/routines/vn2008/views/v_price_fixed.sql | 35 + .../vn2008/views/v_price_fixed_group.sql | 20 + db/routines/vn2008/views/v_ticket_amount.sql | 15 + db/routines/vn2008/views/v_ventes.sql | 68 + db/routines/vn2008/views/v_warehouse.sql | 10 + db/routines/vn2008/views/v_xsubclien.sql | 12 + db/routines/vn2008/views/v_xsubcuentas.sql | 169 + db/routines/vn2008/views/v_xsubprov.sql | 16 + db/routines/vn2008/views/versiones.sql | 8 + .../vn2008/views/vnCreditClassification.sql | 8 + .../vn2008/views/vnCreditInsurance.sql | 9 + db/routines/vn2008/views/vnSolunionCAP.sql | 8 + db/routines/vn2008/views/warehouse.sql | 21 + db/routines/vn2008/views/warehouse_alias.sql | 6 + .../vn2008/views/workcenter_holiday.sql | 7 + db/routines/vn2008/views/workerDocument.sql | 8 + db/routines/vn2008/views/workerTeam.sql | 7 + db/routines/vn2008/views/zoneNickname.sql | 19 + db/tests.js | 39 - db/tests/cache/last_buy_refresh.spec.js | 42 - db/tests/vn/buyUltimate.spec.js | 55 - db/tests/vn/buyUltimateFromInterval.spec.js | 132 - db/tests/vn/item_getBalance.spec.js | 31 - db/tests/vn/ticketCalculateClon.spec.js | 108 - db/tests/vn/ticketComponentUpdateSale.spec.js | 294 - db/tests/vn/ticketCreateWithUser.spec.js | 203 - db/tests/vn/ticket_recalcComponents.spec.js | 62 - .../vn/timeBusiness_calculateByUser.spec.js | 40 - db/tests/vn/zone_getEvents.spec.js | 31 - db/tests/vn/zone_getFromGeo.spec.js | 28 - db/tests/vn/zone_getLanded.spec.js | 75 - .../10107-pinkPaniculata/00-firstScript.sql | 3 + .../10112-wheatAnthurium/00-firstScript.sql | 1 + .../10113-blueMonstera/00-firstScript.sql | 3 + .../10114-maroonOrchid/00-updateConfig.sql | 1 + .../.archive/10116-pinkOak/00-firstScript.sql | 3 + .../10118-blueFern/00-firstScript.sql | 1 + .../10119-navyGerbera/00-AfegirFKPart1.sql | 18 + .../10119-navyGerbera/01-AfegirFkPart2.sql | 17 + .../10125-grayRose/00-firstScript.sql | 45 + .../10127-purpleMedeola/00-firstScript.sql | 28 + .../10128-tealGerbera/00-firstScript.sql | 1 + .../00-firstScript.sql | 4 + .../00-firstScript.sql | 3 + .../10133-crimsonLaurel/00-firstScript.sql | 1 + .../10134-limeAnthurium/00-firstScript.sql | 35 + .../10135-brownMonstera/00-firstScript.sql | 12 + .../00-workerTimeControl.sql | 9 + .../10138-limeBirch/00-firstScript.sql | 14 + .../10139-grayAspidistra/00-firstScript.sql | 63 + .../10139-grayAspidistra/01-secondScript.sql | 18 + .../00-firstScript.sql | 1 + .../10142-silverMedeola/00-firstScript.sql | 11 + .../10143-whiteFern/00-firstScript.sql | 1 + .../10144-silverAralia/00-AfegirFKPArt1.sql | 62 + .../00-AfegirFKPArt1.undo.sql | 34 + .../10147-tealRuscus/00-firstScript.sql | 2 + .../10149-whiteMonstera/00-firstScript.sql | 9 + .../10150-4062isLaid/00-firstScript.sql | 4 + .../10152-bluePalmetto/00-firstScript.sql | 19 + .../10153-maroonAralia/00-firstScript.sql | 1 + .../10154-blackSalal/00-compressionKk.sql | 3 + .../10157-goldenCyca/00-firstScript.sql | 3 + .../10158-grayCordyline/00-firstScript.sql | 31 + .../10160-limePalmetto/00-firstScript.sql | 7 + .../10163-tealErica/00-firstScript.sql | 2 + .../00-borrarSectorsDesus.sql | 2 + .../10165-yellowMastic/00-firstScript.sql | 5 + .../10166-grayArborvitae/00-firstScript.sql | 5 + .../00-renameVnActiveContrat.sql | 1 + .../01-renameVnActiveContrat.undo.sql | 1 + .../10168-orangeAnthurium/00-firstScript.sql | 2 + .../00-createTableBankEntityConfig.sql | 10 + .../01-createTableBankEntityConfig.undo.sql | 1 + .../02-addNotNullToBankEntityBic.sql | 1 + .../00-volumeConfig.sql | 2 + .../10171-crimsonCarnation/01-itemWeight.sql | 27 + .../10171-crimsonCarnation/02-agencymode.sql | 1 + .../10172-brownMedeola/00-firstScript.sql | 4 + .../10174-silverOrchid/00-firstScript.sql | 25 + .../10175-bluePaniculata/00-firstScript.sql | 40 + .../00-crearTablaSpecialLabels.sql | 11 + .../10178-tealMoss/00-firstScript.sql | 6 + .../10179-goldenMonstera/00-firstScript.sql | 2 + .../10183-navyBamboo/00-firstScript.sql | 6 + .../10184-azureLaurel/00-firstScript.sql | 1 + .../10185-greenGalax/00-firstScript.sql | 3 + .../00-desactivar_trigger.sql | 2 + .../01-alter_Table_buy.sql | 3 + .../02-alter_table_entryConfig.sql | 1 + .../04-regularizar_Sticker_Inventario.sql | 6 + .../09-reactivar_trigger.sql | 94 + .../10187-pinkAspidistra/00-firstScript.sql | 4 + .../10188-limeMedeola/00-firstScript.sql | 5 + .../10189-aquaDendro/00-firstScript.sql | 2 + .../10191-orangeRoebelini/00-firstScript.sql | 3 + .../.archive/10194-redRose/00-firstScript.sql | 3 + .../10195-redPhormium/00-firstScript.sql | 24 + .../10200-bronzeCyca/00-firstScript.sql | 5 + .../10201-whiteRaphis/00-firstScript.sql | 4 + .../00-Remove_FK_to_ediGenus.sql | 2 + .../10203-redMedeola/00-firstScript.sql | 1 + .../10204-bronzeCarnation/00-firstScript.sql | 1 + .../10205-bronzeAnthurium/00-firstScript.sql | 32 + .../10207-greenRose/00-Alter_table_entry.sql | 3 + .../00-Alter_table_entry.undo.sql | 3 + .../01-Update_invoiceAmount.sql | 4 + .../10208-goldenRuscus/00-firstScript.sql | 131 + .../10209-bronzeBirch/00-firstScript.sql | 1 + .../10211-greenDendro/01-firstScript.sql | 24 + .../00-renameIsInventory.sql | 1 + .../00-renameIsInventory.undo.sql | 1 + .../10216-pinkMedeola/00-firstScript.sql | 36 + .../10216-pinkMedeola/00-firstScript.undo.sql | 35 + .../10216-pinkMedeola/01-batchIndex.sql | 15 + .../10216-pinkMedeola/01-batchIndex.undo.sql | 11 + .../00-AddCollectionFkOnPackingSite.sql | 1 + .../01-AddFkToCollectionFk.sql | 1 + .../00-createPersonalProtectionEquipment.sql | 8 + .../10222-redEucalyptus/00-firstScript.sql | 226 + .../10223-azureRuscus/00-firstScript.sql | 17 + .../10224-orangeEucalyptus/00-cosetes.sql | 20 + .../10229-salmonDendro/00-firstScript.sql | 9 + .../10231-buyScanPAK/01-tablaEktConfig.sql | 16 + .../10233-aquaCymbidium/00-firstScript.sql | 5 + .../10235-limeDracena/00-firstScript.sql | 4 + .../10236-limeArborvitae/00-firstScript.sql | 93 + .../10237-greenRoebelini/00-firstScript.sql | 6 + .../00-worker_mobileExtension.sql | 6 + .../10239-redAsparagus/00-firstScript.sql | 23 + .../00-firstScript.undo.sql | 16 + .../10241-whiteTulip/00-firstScript.sql | 161 + .../10242-grayChico/00-firstScript.sql | 2 + .../10243-wheatErica/00-firstScript.sql | 7 + .../10245-yellowRaphis/00-firstScript.sql | 7 + .../10247-whiteAsparagus/00-firstScript.sql | 13 + .../10248-azureCordyline/00-firstScript.sql | 30 + .../10250-wheatBamboo/00-firstScript.sql | 6 + .../10253-whiteAnthurium/00-firstScript.sql | 2 + .../10254-whiteOak/00-firstScript.sql | 4 + .../10256-orangeFern/00-firstScript.sql | 16 + .../10258-azureOak/00-firstScript.sql | 21 + .../10259-limeMonstera/00-firstScript.sql | 15 + .../10261-maroonArborvitae/00-firstScript.sql | 10 + .../00-createTablepackagingWithFreight.sql | 9 + .../01-alterTablePackagingConfig.sql | 3 + .../10262-salmonTulip/02-insertsInicials.sql | 21 + .../03-createTablepackingWithoutFreight.sql | 9 + .../10263-tealPaniculata/00-firstScript.sql | 1 + .../10265-greenAspidistra/00-firstScript.sql | 9 + .../10267-blueDracena/00-firstScript.sql | 4 + .../10267-blueDracena/01-fixMerge.sql | 12 + .../00-improvedGeneralLog.sql | 15 + .../10277-azurePalmetto/00-firstScript.sql | 12 + .../10278-silverRose/00-firstScript.sql | 1 + .../10279-purpleAsparagus/00-firstScript.sql | 7 + .../10281-navyPalmetto/00-firstScript.sql | 2 + .../10282-brownAsparagus/00-firstScript.sql | 10 + .../10283-rm4375pak/00-alterTable.sql | 3 + .../10284-aquaErica/00-firstScript.sql | 11 + .../10285-aquaHydrangea/00-firstScript.sql | 2 + .../10287-turquoiseRose/00-firstScript.sql | 4 + .../10288-chocolateSalal/00-firstScript.sql | 2 + .../00-firstScript.sql | 4 + .../10291-azureGalax/00-firstScript.sql | 1 + .../10293-salmonCamellia/00-firstScript.sql | 9 + .../10297-redErica/00-firstScript.sql | 3 + .../10298-grayBamboo/00-firstScript.sql | 1 + .../10299-blueTulip/00-firstScript.sql | 10 + .../10299-blueTulip/00-firstScript.undo.sql | 7 + .../00-productionConfig.sql | 7 + .../10301-4415collectionNewPAK/01-drop.sql | 2 + .../02-collection.sql | 9 + .../00-CreateTableEntryType.sql | 6 + .../01-insertDataEntryType.sql | 4 + .../02-alterTableEntry.sql | 2 + .../10303-tealRoebelini/00-firstScript.sql | 3 + .../10304-limeAsparagus/00-firstScript.sql | 1 + .../01-altertableticket.sql | 1 + .../.archive/10305-brownFern/00-ektAssign.sql | 1 + .../00-deliveryInformation.sql | 3 + .../10307-tealFern/00-firstScript.sql | 10 + .../10308-grayAsparagus/00-firstScript.sql | 2 + .../10309-navyCordyline/00-firstScript.sql | 5 + .../10310-azureCymbidium/00-firstScript.sql | 10 + .../10311-navyChico/00-firstScript.sql | 3 + .../10312-pinkCymbidium/00-firstScript.sql | 1 + .../10313-chocolateMastic/00-firstScript.sql | 1 + .../10314-goldenGerbera/00-firstScript.sql | 1 + .../10315-purpleDracena/00-firstScript.sql | 6 + .../10317-crimsonRuscus/00-firstScript.sql | 8 + .../10318-greenPaniculata/00-firstScript.sql | 25 + .../10319-orangeLaurel/00-firstScript.sql | 244 + .../00-operator.sql | 7 + .../01-collection.sql | 3 + .../02-productionConfig.sql | 3 + .../10321-yellowDendro/00-firstScript.sql | 1 + .../10322-maroonFern/00-firstScript.sql | 1 + .../10326-crimsonCyca/00-firstScript.sql | 1 + .../10328-whiteMedeola/00-firstScript.sql | 10 + .../10329-aquaRose/00-firstScript.sql | 10 + .../10330-pinkCataractarum/00-firstScript.sql | 9 + .../10332-greenMedeola/00-firstScript.sql | 10 + .../00-collectionHotbed.sql | 7 + .../01-saleGroupDetail.sql | 1 + .../10335-silverCyca/00-firstScript.sql | 3 + .../10336-grayMoss/00-firstScript.sql | 9 + .../10337-orangePalmetto/00-firstScript.sql | 3 + .../10339-goldenCarnation/00-firstScript.sql | 6 + .../10340-maroonCordyline/00-firstScript.sql | 5 + .../10341-redDendro/00-firstScript.sql | 20 + .../10342-limeChico/00-firstScript.sql | 33 + .../10343-azureOak/00-firstScript.sql | 6 + .../10345-wheatRaphis/00-firstScript.sql | 15 + .../10347-wheatDracena/00-firstScript.sql | 3 + .../10347-wheatDracena/01-addVirtualField.sql | 1 + .../10349-greenOak/00-firstScript.sql | 9 + .../10350-azureAnthurium/00-firstScript.sql | 2 + .../10352-maroonHydrangea/00-firstScript.sql | 3 + .../10353-silverRoebelini/00-firstScript.sql | 9 + .../10354-wheatMedeola/00-firstScript.sql | 2 + .../00-firstScript.sql | 20 + .../01-orderConfigFk.sql | 1 + .../02-orderConfigDrop.sql | 1 + .../10357-blackAnthurium/00-firstScript.sql | 2 + .../00-improvedGeneralLog_collate.sql | 2 + .../10360-tealLaurel/00-firstScript.sql | 6 + .../10361-redTulip/00-firstScript.sql | 3 + .../.archive/10362-azureMoss/00-dropUdfs.sql | 3 + .../10362-azureMoss/00-dropUdfs.undo.sql | 3 + .../10363-azureLilium/00-firstScript.sql | 2 + .../10365-hfCollectionPAK/00-firstScript.sql | 2 + .../10368-maroonErica/00-firstScript.sql | 2 + .../00-firstScript.sql | 2 + .../10370-pinkBirch/00-deleteForeignKey.sql | 45 + .../10370-pinkBirch/01-firstScript.sql | 193 + .../10370-pinkBirch/02-deleteTable.sql | 116 + .../.archive/10370-pinkBirch/03-accion.sql | 8 + .../.archive/10370-pinkBirch/04-inter.sql | 35 + .../10371-crimsonChico/00-firstScript.sql | 47 + .../.archive/10372-grayIvy/00-firstScript.sql | 15 + .../10373-salmonHydrangea/00-firstScript.sql | 30 + .../00-rename_routeUserPercentage.sql | 1 + .../00-firstScript.sql | 2 + .../10383-navyBirch/00-firstScript.sql | 2 + .../00-firstScript.sql | 2 + .../10386-tealTulip/00-firstScript.sql | 5 + .../10387-wheatRuscus/00-firstScript.sql | 18 + .../00-resizeUtilVerionLogCode.sql | 1 + .../01-resizeUtilVersionCode.sql | 1 + .../00-firstScript.sql | 2 + .../10391-orangeCyca/00-firstScript.sql | 9 + .../10394-brownHydrangea/00-firstScript.sql | 2 + db/versions/10193-navyHydrangea/00-delete.sql | 46 + .../10193-navyHydrangea/01-botanicExport.sql | 1 + db/versions/10193-navyHydrangea/02-item.sql | 1 + .../10193-navyHydrangea/03-autonomy.sql | 17 + db/versions/10193-navyHydrangea/03-turn.sql | 1 + .../10193-navyHydrangea/04-country.sql | 2 + .../10379-turquoiseOrchid/00-firstScript.sql | 8 + .../00-business_workcenterFk.sql | 15 + .../10395-blueGalax/00-firstScript.sql | 2 + .../10396-grayRoebelini/00-firstScript.sql | 5 + .../00-firstScript.sql | 5 + .../10399-blueErica/00-firstScript.sql | 5 + .../10400-brownEucalyptus/00-firstScript.sql | 2 + .../10402-orangeTulip/00-firstScript.sql | 5 + .../10404-grayMedeola/00-firstScript.sql | 2 + .../10405-orangeGalax/00-firstScript.sql | 3 + db/versions/10407-blueOak/00-firstScript.sql | 5 + .../10408-purpleIvy/00-firstScript.sql | 31 + .../10409-brownSalal/00-firstScript.sql | 5 + .../10412-yellowCarnation/00-firstScript.sql} | 4 - .../10413-whiteCymbidium/00-firstScript.sql | 3 + .../10416-blueAsparagus/00-firstScript.sql | 25 + .../00-firstScript.sql | 1 + .../10421-navyMonstera/00-firstScript.sql | 6 + .../10426-silverAsparagus/00-firstScript.sql | 7 + .../10428-wheatRose/00-firstScript.sql | 14 + .../10431-redCordyline/00-firstScript.sql | 9 + .../10433-salmonAnthurium/00-firstScript.sql | 3 + .../10434-grayTulip/00-firstScript.sql | 1 + .../10435-aquaGalax/00-firstScript.sql | 2 + .../10436-tealPalmetto/00-createFkWorker.sql | 3 + .../01-addStateToWorkerProductivity.sql | 2 + .../02-DeprecateVnSaleTrackingState.sql | 1 + ...-DeprecateColumnVnSaleTrackingActionFk.sql | 1 + .../04-DropSchemaVnControl.sql | 1 + .../05-RemoveFkWorkerProductivity.sql | 2 + db/versions/10439-greenTulip/00-fixRole.sql | 2 + .../10440-grayDendro/00-firstScript.sql | 3 + .../10444-crimsonBamboo/00-firstScript.sql | 7 + .../10445-orangeMoss/00-firstScript.sql | 27 + .../00-firstScript.sql | 10 + db/versions/10450-blackIvy/00-firstScript.sql | 7 + .../10451-salmonOak/00-firstScript.sql | 4 + .../10452-redEucalyptus/00-firstScript.sql | 13 + .../10453-aquaMedeola/00-firstScript.sql | 2 + .../10454-bronzeMoss/00-firstScript.sql | 2 + .../10455-blackGerbera/00-firstScript.sql | 1 + .../10456-greenArborvitae/00-firstScript.sql | 2 + .../10457-crimsonTulip/00-firstScript.sql | 17 + .../10458-orangePalmetto/00-firstScript.sql | 18 + .../00-alterTableUtilConfig.sql | 10 + .../01-createFunctionCurdate.sql | 13 + .../02-createFunctionMockTime.sql | 23 + .../03-createFunctionMockTimeBase.sql | 27 + .../04-createFunctionNow.sql | 12 + .../10460-crimsonDendro/00-firstScript.sql | 2 + .../10461-filtroPorTipos/00-firstScript.sql | 39 + .../10463-wheatMonstera/00-firstScript.sql | 1 + .../10468-goldenGerbera/00-firstScript.sql | 2 + .../10469-bronzeEucalyptus/00-firstScript.sql | 1 + .../00-firstScript.sql | 15 + .../10471-orangeMastic/00-firstScript.sql | 3 + .../10472-bronzeOak/00-firstScript.sql | 5 + .../10477-goldenDendro/00-firstScript.sql | 12 + db/versions/10478-tealGalax/00-dropBasket.sql | 1 + .../10478-tealGalax/00-firstScript.sql | 2 + .../10478-tealGalax/01-orderConfigured.sql | 1 + .../10478-tealGalax/02-configuredUpdate.sql | 1 + db/versions/10478-tealGalax/99-privileges.sql | 12 + .../10480-blueTulip/00-firstScript.sql | 1 + .../10481-brownAspidistra/00-firstScript.sql | 1 + .../10482-blueMastic/00-firstScript.sql | 4 + .../10485-aquaCamellia/00-firstScript.sql | 9 + .../10488-grayCarnation/00-firstScript.sql | 9 + .../10491-orangeDracena/00-firstScript.sql | 1 + db/versions/10492-wheatIvy/00-firstScript.sql | 38 + .../10493-purpleAnthurium/00-firstScript.sql | 2 + .../10495-whiteFern/00-firstScript.sql | 1 + .../10498-redAspidistra/00-firstScript.sql | 3 + .../00-firstScript.sql | 1 + .../10500-limeRaphis/00-firstScript.sql | 10 + .../10501-orangeAnthurium/00-firstScript.sql | 5 + .../10502-azureCarnation/00-firstScript.sql | 8 + .../10502-yellowCordyline/00-firstScript.sql | 8 + .../10504-maroonPalmetto/00-firstScript.sql | 1 + .../10506-aquaPaniculata/01-firstScript.sql | 12 + .../10506-aquaPaniculata/02-secondScript.sql | 3 + .../10506-aquaPaniculata/03-thirdScript.sql | 48 + .../10506-crimsonRoebelini/00-firstScript.sql | 12 + .../10507-greenAspidistra/00-firstScript.sql | 40 + .../10508-maroonMonstera/00-firstScript.sql | 2 + .../10510-salmonMoss/00-dropBusinessFk.sql | 1 + .../01-createTableProfessionalCategory.sql | 11 + .../10510-salmonMoss/02-exportToNewTable.sql | 3 + .../10510-salmonMoss/03-RecreateFK.sql | 2 + .../10510-salmonMoss/04-kkPostgresqlTable.sql | 2 + .../00-firstScript.sql | 33 + .../10512-purpleRoebelini/00-firstScript.sql | 2 + .../10513-aquaCataractarum/00-firstScript.sql | 4 + .../10514-silverAspidistra/00-firstScript.sql | 5 + .../10516-crimsonSalal/00-firstScript.sql | 10 + .../10521-salmonLilium/00-firstScript.sql | 4 + .../10522-yellowMedeola/00-firstScript.sql | 4 + .../10523-tealCataractarum/00-firstScript.sql | 54 + .../10524-limeCordyline/00-firstScript.sql | 21 + .../10524-limeCordyline/01-rateEditorFk.sql | 3 + .../10525-yellowRuscus/00-firstScript.sql | 2 + .../10526-goldenOak/00-firstScript.sql | 3 + .../10528-orangeRoebelini/00-firstScript.sql | 3 + .../10530-orangeCyca/00-firstScript.sql | 1 + .../10531-chocolateFern/00-firstScript.sql | 2 + .../10532-tealTulip/00-firstScript.sql | 1 + .../10533-crimsonLaurel/00-firstScript.sql | 2 + .../10537-grayCordyline/00-firstScript.sql | 1 + .../00-createChronopostConfig.sql | 24 + .../01-createChronopostService.sql | 9 + .../02-createChronopostExpedition.sql | 9 + .../03-createChronopostSenderAddress.sql | 8 + .../04-addgrantPrivilegies.sql | 5 + .../05-updateChronopostConfig.sql | 1 + .../10539-pinkPalmetto/00-firstScript.sql | 8 + .../10540-bronzeOrchid/00-firstScript.sql | 39 + .../10545-maroonDracena/00-firstScript.sql | 5 + db/versions/10546-redOak/00-firstScript.sql | 6 + .../10547-aquaDendro/00-firstScript.sql | 17 + .../00-updateUpdateLog.sql | 37 + .../01-updateInsertLog.sql | 37 + .../02-updateDeleteLog.sql | 37 + .../03-deleteEmptyLog.sql | 45 + .../04-optimizeLogTables.sql | 13 + .../10550-grayMonstera/00-editorFk.sql | 227 + .../10550-grayMonstera/01-originFk.sql | 48 + .../10552-blackAnthurium/00-firstScript.sql | 1 + .../10554-maroonFern/00-firstScript.sql | 3 + .../10557-whiteCordyline/00-firstScript.sql | 2 + .../10559-brownDracena/00-firstScript.sql | 15 + .../00-firstScript.sql | 2 + .../10562-whiteDendro/00-firstScript.sql | 6 + .../00-delivery_ticketFk.sql | 3 + .../10566-azureArborvitae/00-firstScript.sql} | 7 +- .../10567-salmonAspidistra/00-firstScript.sql | 2 + .../10568-grayAnthurium/00-firstScript.sql | 3 + .../10569-salmonLaurel/00-firstScript.sql | 3 + .../00-createSendingConfig.sql | 9 + .../01-createSendingServiceWeekday.sql | 6 + .../02-createSendingService.sql | 7 + db/versions/10570-goldenTulip/03-permisos.sql | 3 + db/versions/10571-navyCyca/00-firstScript.sql | 9 + .../10573-tealChico/00-firstScript.sql | 11 + .../10575-crimsonAnthurium/00-firstScript.sql | 3 + .../10577-salmonMonstera/00-firstScript.sql | 2 + .../10578-brownCarnation/00-firstScript.sql | 6 + .../10579-aquaRoebelini/00-firstScript.sql | 3 + .../00-itemTypeDropConstraint.sql | 1 + .../01-itemTypeAddConstraint.sql | 2 + .../00-itemTypeAutoIncrement.sql | 29 + .../10582-purpleOrchid/00-firstScript.sql | 2 + .../10583-turquoiseGerbera/00-firstScript.sql | 1 + .../10584-azureGerbera/00-firstScript.sql | 10 + .../10585-pinkMedeola/00-ticketLog.sql | 10 + db/versions/10585-pinkMedeola/01-entryLog.sql | 8 + db/versions/10585-pinkMedeola/02-claimLog.sql | 8 + .../10585-pinkMedeola/03-clientLog.sql | 8 + .../10585-pinkMedeola/04-invoiceInLog.sql | 8 + db/versions/10585-pinkMedeola/05-itemLog.sql | 9 + db/versions/10585-pinkMedeola/06-routeLog.sql | 8 + .../10585-pinkMedeola/07-shelvingLog.sql | 15 + .../10585-pinkMedeola/08-supplierLog.sql | 8 + .../10585-pinkMedeola/09-travelLog.sql | 8 + .../10585-pinkMedeola/10-workerLog.sql | 8 + db/versions/10585-pinkMedeola/11-zoneLog.sql | 9 + db/versions/10585-pinkMedeola/12-userLog.sql | 9 + db/versions/10585-pinkMedeola/13-roleLog.sql | 9 + .../10587-navyOak/00-arcRead_addMinimum.sql | 1 + .../10593-greenLilium/00-firstScript.sql | 7 + .../10596-purpleCamellia/00-firstScript.sql | 1 + .../10597-navyAralia/00-firstScript.sql | 1 + .../10598-purpleGalax/00-workerLog.sql | 3 + .../10598-purpleGalax/01-supplierLog.sql | 3 + .../02-workerTimeControlLog.sql | 3 + .../10598-purpleGalax/03-workerClockLog.sql | 3 + .../10599-orangeHydrangea/00-firstScript.sql | 2 + .../10601-orangeErica/00-firstScript.sql | 2 + .../10602-whiteArborvitae/00-firstScript.sql | 3 + .../10606-pinkChico/00-firstScript.sql | 2 + .../10608-pinkAsparagus/00-firstScript.sql | 2 + .../10609-grayRaphis/00-firstScript.sql | 19 + .../00-updateCompanyId.sql | 104 + .../01-updateSupplierId.sql | 80 + .../02-invoiceOutCompany.sql | 8 + .../10611-blueGerbera/00-firstScript.sql | 1 + .../10613-purpleAspidistra/00-firstScript.sql | 1 + .../10614-chocolateGalax/00-firstScript.sql | 1 + .../00-firstScript.sql | 3 + .../10616-yellowIvy/00-firstScript.sql | 13 + .../10616-yellowIvy/01-firstScript.sql | 8 + .../10617-aquaAralia/00-firstScript.sql | 1 + .../10618-whiteArborvitae/00-firstScript.sql | 2 + .../10619-chocolateErica/00-firstScript.sql | 1 + .../10620-azurePalmetto/00-firstScript.sql | 11 + .../10624-blueAnthurium/00-firstScript.sql | 142 + db/versions/10625-whiteOak/00-firstScript.sql | 3 + .../10626-silverRaphis/00-firstScript.sql | 5 + .../10628-grayOrchid/00-firstScript.sql | 1 + .../10630-brownMastic/00-firstScript.sql | 38 + .../10631-yellowBamboo/00-firstScript.sql | 18 + .../10632-wheatPaniculata/00-firstScript.sql | 4 + .../10633-orangeArborvitae/00-firstScript.sql | 2 + .../10634-pinkCymbidium/00-firstScript.sql | 70 + .../10637-yellowAspidistra/00-firstScript.sql | 17 + .../10640-redPalmetto/00-companyFkDrop.sql | 36 + .../10640-redPalmetto/01-companyFkAi.sql | 1 + .../10640-redPalmetto/02-companyFkCreate.sql | 32 + .../10640-redPalmetto/04-supplierFkDrop.sql | 26 + .../10640-redPalmetto/05-supplierFkAi.sql | 1 + .../10640-redPalmetto/06-supplierFkCreate.sql | 26 + .../00-firstScript.sql | 303 + .../10643-blueCataractarum/00-firstScript.sql | 43 + .../10644-aquaLaurel/00-firstScript.sql | 5 + .../10645-purplePalmetto/00-addNewFields.sql | 2 + .../01-updateCollectionWagonPrimaryKey.sql | 4 + .../02-updateWagonPrimaryKey.sql | 20 + .../03-addFieldToPackingSite.sql | 2 + .../10647-goldenBamboo/00-renombrarTabla.sql | 2 + .../10648-blackBirch/00-firstScript.sql | 3 + .../10649-yellowAsparagus/00-firstScript.sql | 1 + .../00-comparativeCountryFk.sql | 40 + .../01-comparativeAddConfig.sql | 11 + .../02-nightTaskAddNewTask.sql | 6 + .../03-grantProc.vn.sql | 2 + .../10652-maroonPhormium/00-firstScript.sql | 4 + .../10653-redHydrangea/00-firstScript.sql | 3 + .../10655-navyRuscus/00-firstScript.sql | 6 + .../10656-navyMastic/00-firstScript.sql | 34 + .../00-renameErrorProduction.sql | 1 + .../10657-redDracena/01-changeNightTask.sql | 1 + .../02-addCodeToClaimResponsible.sql | 27 + .../03-grantSelectGrafana.sql | 1 + .../10658-whiteDracena/00-firstScript.sql | 3 + .../10659-azureDracena/00-firstScript.sql | 11 + .../10661-crimsonIvy/00-firstScript.sql | 4 + .../10662-wheatErica/00-firstScript.sql | 2 + .../10663-tealCymbidium/00-firstScript.sql | 2 + .../10665-maroonSalal/00-firstScript.sql | 19 + .../10666-limeGerbera/00-firstScript.sql | 3 + .../00-firstScript.sql | 1 + .../10668-tealBirch/00-firstScript.sql | 29 + .../10671-maroonIvy/00-firstScript.sql | 2 + .../10675-grayRuscus/00-firstScript.sql | 1 + .../10676-aquaTulip/00-firstScript.sql | 4 + .../10677-yellowMoss/00-firstScript.sql | 4 + .../10678-orangeMedeola/00-firstScript.sql | 2 + .../10679-inventoryDiscrepancy/00-tables.sql | 28 + .../10680-turquoiseLilium/00-firstScript.sql | 2 + .../00-firstScript.sql | 15 + .../10683-bronzeMastic/00-firstScript.sql | 20 + .../10684-tealEucalyptus/00-firstScript.sql | 2 + .../10685-blueMedeola/00-firstScript.sql | 23 + .../10690-azureGalax/00-firstScript.sql | 2 + .../10691-bronzeCamellia/00-firstScript.sql | 7 + .../10692-silverLilium/00-firstScript.sql | 3 + .../00-firstScript.sql | 2 + .../10694-bluePaniculata/00-firstScript.sql | 3 + .../10695-pinkMastic/00-firstScript.sql | 4 + .../00-firstScript.sql | 2 + .../10698-yellowGalax/00-firstScript.sql | 2 + db/versions/10699-aquaOak/00-firstScript.sql | 3 + .../10700-salmonTulip/00-firstScript.sql | 3 + .../00-firstScript.sql | 21 + .../10702-crimsonCymbidium/00-firstScript.sql | 11 + .../10704-wheatMastic/00-firstScript.sql | 2 + .../10705-yellowBirch/00-firstScript.sql | 2 + .../10707-azureFern/00-firstScript.sql | 5 + .../00-firstScript.sql | 12 + .../10712-crimsonCordyline/00-firstScript.sql | 1 + db/versions/10714-azureOak/00-firstScript.sql | 25 + .../00-firstScript.sql | 17 + .../10717-silverRose/00-firstScript.sql | 6 + .../10718-orangeRaphis/00-firstScript.sql | 2 + .../10719-orangeMonstera/00-firstScript.sql | 6 + .../10720-wheatCymbidium/00-firstScript.sql | 5 + .../10721-blueEucalyptus/00-firstScript.sql | 2 + .../10725-wheatAnthurium/00-firstScript.sql | 2 + .../10726-blackMastic/00-firstScript.sql | 3 + .../10727-limeErica/00-addPrinterField.sql | 1 + .../01-createTableScreenModel.sql | 13 + .../10727-limeErica/02-createTableScreen.sql | 10 + .../03-createTableScreenModel.sql | 7 + .../10727-limeErica/04-createTableScanner.sql | 10 + .../05-createTablePackingSiteDeviceLog.sql | 19 + .../06-alterTablePrinterModel.sql | 8 + .../07-AddFieldsToPackingSite.sql | 14 + .../00-firstScript.sql | 1 + .../10733-azureErica/00-firstScript.sql | 1 + .../10736-maroonChico/00-workerBossNull.sql | 1 + .../00-firstScript.sql | 88 + .../10740-pinkCataractarum/00-firstScript.sql | 9 + .../01-refactorCplusTrascendency472.sql | 54 + .../02-refactorCplusTrascendency477.sql | 55 + .../03-refactorCplusInvoiceType477.sql | 49 + .../04-refactorCplusInvoiceType472.sql | 44 + db/versions/10741-maroonMastic/05-fixes.sql | 1 + .../10744-aquaBirch/00-firstScript.sql | 9 + .../10746-aquaMastic/00-firstScript.sql | 4 + .../10747-brownRaphis/00-firstScript.sql | 13 + db/versions/10748-navyRose/00-firstScript.sql | 2 + .../10748-navyRose/01-SecondScript.sql | 7 + .../00-firstScript.sql | 2 + .../10750-limeAsparagus/00-firstScript.sql | 1 + .../10750-wheatGalax/00-ticket_addGrants.sql | 3 + .../10751-silverArborvitae/00-firstScript.sql | 3 + .../00-firstScript.sql | 1 + .../10753-blueDracena/00-firstScript.sql | 1 + .../10754-purpleMonstera/00-firstScript.sql | 2 + db/versions/10755-redGalax/00-firstScript.sql | 1 + .../10756-wheatRoebelini/00-firstScript.sql | 1 + .../00-firstScript.sql | 3 + .../10758-boxPicking/00-sectorType.sql | 33 + db/versions/10758-boxPicking/01-dipole.sql | 5 + .../10761-greenGalax/00-firstScript.sql | 4 + db/versions/10768-blueRose/00-firstScript.sql | 8 + .../10771-bronzeLaurel/00-firstScript.sql | 14 + .../10773-maroonBamboo/00-firstScript.sql | 1 + .../10775-chocolateOrchid/00-firstScript.sql | 2 + .../10778-goldenSalal/00-firstScript.sql | 1 + .../10782-salmonErica/00-firstScript.sql | 10 + .../10783-silverGalax/00-firstScript.sql | 1 + db/versions/10785-grayCyca/00-firstScript.sql | 9 + db/versions/10785-grayCyca/02-invoiceIn.sql | 1 + .../10785-grayCyca/02-invoiceInTax.sql | 1 + db/versions/10785-grayCyca/02-item.sql | 1 + .../10789-whiteSalal/00-firstScript.sql | 5 + .../10789-whiteSalal/00-firstScript.vn.sql | 5 + db/versions/10792-crimsonMoss/00-buy.sql | 1 + .../10798-grayLaurel/00-firstScript.sql | 5 + .../10799-limePalmetto/00-firstScript.sql | 27 + .../10800-yellowSalal/00-firstScript.sql | 2 + .../10801-redRoebelini/00-firstScript.sql | 3 + db/versions/10806-limeRose/00-firstScript.sql | 3 + myt.config.yml | 401 + package-lock.json | 1624 +- package.json | 1 + 2656 files changed, 107579 insertions(+), 26834 deletions(-) delete mode 100644 db/.archive/224701/00-ACL.sql delete mode 100644 db/.archive/224701/00-acl_receiptPdf.sql delete mode 100644 db/.archive/224701/00-clientConsumptionQueue.sql delete mode 100644 db/.archive/224701/00-invoiceOutQueue.sql delete mode 100644 db/.archive/224701/00-itemConfig.sql delete mode 100644 db/.archive/224701/00-printConfig.sql delete mode 100644 db/.archive/224701/00-sample.sql delete mode 100644 db/.archive/224701/00-user_hasGrant.sql delete mode 100644 db/.archive/224702/00-ACL_workerDisableExcluded.sql delete mode 100644 db/.archive/224702/00-aclBusiness.sql delete mode 100644 db/.archive/224702/00-aclUsesMana.sql delete mode 100644 db/.archive/224702/00-defaultPayDem_sameAs_production.sql delete mode 100644 db/.archive/224702/00-invoiceInPdf.sql delete mode 100644 db/.archive/224702/00-newSupplier_ACL.sql delete mode 100644 db/.archive/224702/00-notificationTables.sql delete mode 100644 db/.archive/224702/00-payMethodFk_Allow_Null.sql delete mode 100644 db/.archive/224702/00-supplierActivityFk_Allow_Null.sql delete mode 100644 db/.archive/224801/00-ACL.sql delete mode 100644 db/.archive/224801/00-claim.sql delete mode 100644 db/.archive/224801/00-claimRma.sql delete mode 100644 db/.archive/224901/00-aclNotification.sql delete mode 100644 db/.archive/224901/00-packingSiteConfig.sql delete mode 100644 db/.archive/224901/00-packingSiteUpdate.sql delete mode 100644 db/.archive/224901/00-salix_url.sql delete mode 100644 db/.archive/224902/00-aclUserPassword.sql delete mode 100644 db/.archive/224902/00-deletePickupContact.sql delete mode 100644 db/.archive/224902/00-itemShelvingACL.sql delete mode 100644 db/.archive/224902/00-itemShelvingPlacementSupplyStockACL.sql delete mode 100644 db/.archive/224902/00-workerTimeControlMail.sql delete mode 100644 db/.archive/224902/00-zone_getPostalCode.sql delete mode 100644 db/.archive/224903/00-ACL_notification_InvoiceE.sql delete mode 100644 db/.archive/224903/00-aclInvoiceOut.sql delete mode 100644 db/.archive/224903/00-alter_expedition_itemFk.sql delete mode 100644 db/.archive/224903/00-clientHasInvoiceElectronic.sql delete mode 100644 db/.archive/224903/00-collection_missingTrash.sql delete mode 100644 db/.archive/224903/00-deleteInvoiceOutQueue.sql delete mode 100644 db/.archive/224903/00-editTrackedACL.sql delete mode 100644 db/.archive/224903/00-greuge.sql delete mode 100644 db/.archive/224903/00-isCompensationACL.sql delete mode 100644 db/.archive/224903/00-osTicketConfig.sql delete mode 100644 db/.archive/224903/00-ticket_canMerge.sql delete mode 100644 db/.archive/224903/00-ticket_canbePostponed.sql delete mode 100644 db/.archive/224903/00-timeBusiness_calculate.sql delete mode 100644 db/.archive/224903/01-updateClientHasInvoiceElectronic.sql delete mode 100644 db/.archive/225001/00-aclMdbApp.sql delete mode 100644 db/.archive/225001/00-updateCollection.sql delete mode 100644 db/.archive/225201/00-ACL_saveSign.sql delete mode 100644 db/.archive/225201/00-aclTicketLog.sql delete mode 100644 db/.archive/225201/00-entryDeleteRef.sql delete mode 100644 db/.archive/225201/00-invoiceInConfig.sql delete mode 100644 db/.archive/225201/00-invoiceOut_new.sql delete mode 100644 db/.archive/225201/00-mdbApp.sql delete mode 100644 db/.archive/225201/00-notification_send.sql delete mode 100644 db/.archive/225201/00-ticketSms.sql delete mode 100644 db/.archive/225201/00-ticket_canAdvance.sql delete mode 100644 db/.archive/225201/00-ticket_canbePostponed.sql delete mode 100644 db/.archive/225201/00-ticket_split_merge.sql delete mode 100644 db/.archive/225201/00-utilNotification.sql delete mode 100644 db/.archive/225201/01-create_stateI18n.sql delete mode 100644 db/.archive/225201/01-modules.sql delete mode 100644 db/.archive/225201/02-insert_stateI18n.sql delete mode 100644 db/.archive/225201/02-starredModule.sql delete mode 100644 db/.archive/225202/00-mdbApp.sql delete mode 100644 db/.archive/225203/00-mdbApp.sql delete mode 100644 db/.archive/230201/00-ACL_ItemShelvingSale.sql delete mode 100644 db/.archive/230201/00-SupplierUniqueKey.sql delete mode 100644 db/.archive/230201/00-autoincrement_VnReport_VnPrinter.sql delete mode 100644 db/.archive/230201/00-borradoLogicoIPT.sql delete mode 100644 db/.archive/230201/00-docuwareStore.sql delete mode 100644 db/.archive/230201/00-validPriorities_ItemConfig.sql delete mode 100644 db/.archive/230201/00-workerTimeControlConfig.sql delete mode 100644 db/.archive/230202/00-itemConfig.sql delete mode 100644 db/.archive/230401/00-ACL.sql delete mode 100644 db/.archive/230401/00-ACL_tag_update.sql delete mode 100644 db/.archive/230401/00-createWorker.sql delete mode 100644 db/.archive/230401/00-ticket_canAdvance.sql delete mode 100644 db/.archive/230401/00-updateIsToBeMailed.sql delete mode 100644 db/.archive/230403/00-clienteCompensado.sql delete mode 100644 db/.archive/230404/00-ticket_canAdvance.sql delete mode 100644 db/.archive/230601/00-acl_claim.sql delete mode 100644 db/.archive/230601/00-acl_notifications.sql delete mode 100644 db/.archive/230601/00-itemConfig_warehouseFk.sql delete mode 100644 db/.archive/230601/00-uniqueKeyNotificationSubscription.sql delete mode 100644 db/.archive/230601/01-alter_notSubs.sql delete mode 100644 db/.archive/230801/00-acl_itemConfig.sql delete mode 100644 db/.archive/230801/00-supplierIsVies.sql delete mode 100644 db/.archive/230801/00-workerLocker.sql delete mode 100644 db/.archive/231001/00-delivery.sql delete mode 100644 db/.archive/231001/00-invoiceOut.sql delete mode 100644 db/.archive/231001/00-report.sql delete mode 100644 db/.archive/231001/02-invoiceOut_new.sql delete mode 100644 db/.archive/231201/00-ACL.sql delete mode 100644 db/.archive/231201/00-chatRefactor.sql delete mode 100644 db/.archive/231201/00-invoiceInSerial.sql delete mode 100644 db/.archive/231201/00-itemType_isFragile.sql delete mode 100644 db/.archive/231201/00-mailACL.sql delete mode 100644 db/.archive/231201/00-operator.sql delete mode 100644 db/.archive/231201/00-supplierAccount_deleteTriggers.sql delete mode 100644 db/.archive/231201/00-wagon.sql delete mode 100644 db/.archive/231202/00-delivery.sql delete mode 100644 db/.archive/231203/00-delivery.sql delete mode 100644 db/.archive/231204/00-rollbackDelivery.sql delete mode 100644 db/.archive/231205/00-printQueueArgs.sql delete mode 100644 db/.archive/231401/00-claimBeginningAfterInsert.sql delete mode 100644 db/.archive/231401/00-negativeBases.sql delete mode 100644 db/.archive/231401/00-workerNotes.sql delete mode 100644 db/.archive/231402/00-negativeBases.sql delete mode 100644 db/.archive/231801/00-aclClientInforma.sql delete mode 100644 db/.archive/231801/00-acl_receiptEmail.sql delete mode 100644 db/.archive/231801/00-clientInforma.sql delete mode 100644 db/.archive/231801/00-client_setRatingAcl.sql delete mode 100644 db/.archive/231801/00-deleteProcs_refund.sql delete mode 100644 db/.archive/231801/00-deviceProduction.sql delete mode 100644 db/.archive/231801/00-kkearEntryNotes.sql delete mode 100644 db/.archive/231801/00-newCompanyI18n.sql delete mode 100644 db/.archive/231801/00-newTableWeb.sql delete mode 100644 db/.archive/231801/00-observationEmailACL.sql delete mode 100644 db/.archive/231801/00-optimiceZoneEstimatedDelivery.sql delete mode 100644 db/.archive/231801/00-saleTracking.sql delete mode 100644 db/.archive/231801/00-ticketConfig.sql delete mode 100644 db/.archive/231801/00-updateIsVies.sql delete mode 100644 db/.archive/231801/00-updateisViesClient.sql delete mode 100644 db/.archive/231801/00-userAcl.sql delete mode 100644 db/.archive/231801/00-userRoleLog.sql delete mode 100644 db/.archive/231801/01-viewCompany10L.sql delete mode 100644 db/.archive/232001/00-clientWorkerName.sql delete mode 100644 db/.archive/232001/00-createWorker.sql delete mode 100644 db/.archive/232001/00-wagon.sql delete mode 100644 db/.archive/232201/00-defaulterView.sql delete mode 100644 db/.archive/232201/00-procedurecanAdvance.sql delete mode 100644 db/.archive/232201/00-workerConfigPayMethod.sql delete mode 100644 db/.archive/232202/00-procedurecanAdvance.sql delete mode 100644 db/.archive/232401/00-buyConfig_travelConfig.sql delete mode 100644 db/.archive/232401/00-printer.sql delete mode 100644 db/.archive/232401/00-ticket_warehouse.sql delete mode 100644 db/.archive/232401/00-userPassExpired.sql delete mode 100644 db/.archive/232402/00-hotFix_travelConfig.sql delete mode 100644 db/.archive/232601/00-aclAccount.sql delete mode 100644 db/.archive/232601/00-aclInvoiceTickets.sql delete mode 100644 db/.archive/232601/00-aclMailAliasAccount.sql delete mode 100644 db/.archive/232601/00-aclMailForward.sql delete mode 100644 db/.archive/232601/00-aclRole.sql delete mode 100644 db/.archive/232601/00-aclVnUser.sql delete mode 100644 db/.archive/232601/00-aclVnUser_renewToken.sql delete mode 100644 db/.archive/232601/00-salix.sql delete mode 100644 db/.archive/232601/00-useSpecificsAcls.sql delete mode 100644 db/.archive/232601/01-invoiceOutPdf.sql delete mode 100644 db/.archive/232602/01-aclAddAlias.sql delete mode 100644 db/.archive/232801/00-authCode.sql delete mode 100644 db/.archive/232801/00-client_create.sql delete mode 100644 db/.archive/232801/00-client_create2.sql delete mode 100644 db/.archive/232801/00-department.sql delete mode 100644 db/.archive/232801/00-fix_editCredit.sql delete mode 100644 db/.archive/232801/00-user.sql delete mode 100644 db/.archive/232802/01-aclWorkerDisable.sql delete mode 100644 db/.archive/233001/.gitkeep delete mode 100644 db/.archive/233001/00-aclSaleTracking.sql delete mode 100644 db/.archive/233001/00-clientSms.sql delete mode 100644 db/.archive/233001/00-company.sql delete mode 100644 db/.archive/233001/00-fixACLVehicle.sql delete mode 100644 db/.archive/233001/00-itemRecycle.sql delete mode 100644 db/.archive/233001/00-itemShelving_inventory.sql delete mode 100644 db/.archive/233001/00-noUniqueSocialName.sql delete mode 100644 db/.archive/233001/00-roadmap.sql delete mode 100644 db/.archive/233001/00-roadmapACL.sql delete mode 100644 db/.archive/233001/00-ticketWeight.sql delete mode 100644 db/.archive/233201/.gitkeep delete mode 100644 db/.archive/233201/00-acl_viaexpressConfig.sql delete mode 100644 db/.archive/233201/00-transferClient.sql delete mode 100644 db/.archive/233201/00-updatePrice.sql delete mode 100644 db/.archive/233201/00-viaexpress.sql delete mode 100644 db/.archive/233201/00-workerDocuware.sql delete mode 100644 db/.archive/233202/00-ticketSmsACL.sql delete mode 100644 db/.archive/233401/00-setDeleted_acl.sql delete mode 100644 db/.archive/233601/.gitkeep delete mode 100644 db/.archive/233601/00-aclWorker.sql delete mode 100644 db/.archive/233601/00-addExpeditionState.sql delete mode 100644 db/.archive/233601/00-department.sql delete mode 100644 db/.archive/233601/00-saleGroupDetail.sql delete mode 100644 db/.archive/233801/.gitkeep delete mode 100644 db/.archive/233801/00-firstScript.sql delete mode 100644 db/.archive/233801/01-deviceLog_acl.sql delete mode 100644 db/.archive/233802/.gitkeep delete mode 100644 db/.archive/233802/00-collectionGetTicketsACL.sql delete mode 100644 db/Dockerfile delete mode 100644 db/changes/234001/.gitkeep delete mode 100644 db/changes/234001/00-aclClient.sql delete mode 100644 db/changes/234001/00-dropUserFk.sql delete mode 100644 db/changes/234001/00-models.sql delete mode 100644 db/changes/234001/00-ticketConfig.sql delete mode 100644 db/changes/234001/00-updateAfterBusinnesInsert.sql delete mode 100644 db/changes/234001/01-aclAccount.sql delete mode 100644 db/changes/234001/01-deliveryAssistantACL.sql delete mode 100644 db/changes/234001/01-workerCreate.sql delete mode 100644 db/changes/234001/02-roleSync.sql delete mode 100644 db/changes/234002/.gitkeep delete mode 100644 db/changes/234002/01-itemShelvingSale.sql delete mode 100644 db/changes/234003/00-ticket_canAdvance_zone.sql delete mode 100644 db/changes/234004/.gitkeep delete mode 100644 db/changes/234004/00-workerTimeControl.sql delete mode 100644 db/changes/234201/.gitkeep delete mode 100644 db/changes/234201/00-ACL_workerDepartment.sql delete mode 100644 db/changes/234201/00-account_acl.sql delete mode 100644 db/changes/234201/00-aclClient.sql delete mode 100644 db/changes/234201/00-aclSetPassword.sql delete mode 100644 db/changes/234201/00-aclUrlHedera.sql delete mode 100644 db/changes/234201/00-dropWorkerCreate.sql delete mode 100644 db/changes/234201/00-packagingFk.sql delete mode 100644 db/changes/234201/00-packagingFkviews.sql delete mode 100644 db/changes/234201/00-supplierAccountCheckLength.sql delete mode 100644 db/changes/234201/00-zoneIncluded.sql delete mode 100644 db/changes/234201/03-packagingFkProc.sql delete mode 100644 db/changes/234601/.gitkeep delete mode 100644 db/changes/234601/00-ACLticketTrackingState.sql delete mode 100644 db/changes/234601/00-claimViewerAcl.sql delete mode 100644 db/changes/234601/00-clientAfterUpdate.sql delete mode 100644 db/changes/234601/00-transferInvoice.sql delete mode 100644 db/changes/234601/00-updateCourtesyTime.sql delete mode 100644 db/changes/234602/00-roleSync.sql delete mode 100644 db/changes/234604/00-sambaConfigUserDn.sql delete mode 100644 db/changes/234801/.gitkeep delete mode 100644 db/changes/234801/00-ACL_executeRoutine.sql delete mode 100644 db/changes/234801/00-notificationSubscription.sql delete mode 100644 db/changes/234802/00-createSignInLogTable.sql delete mode 100644 db/changes/235001/.gitkeep delete mode 100644 db/changes/235001/00-getRoutesByWorker.sql delete mode 100644 db/changes/240001/00-alterTable.sql delete mode 100644 db/changes/240001/00-clientCreditLimitToRoleCreditLimit.sql delete mode 100644 db/changes/240001/01-procedures.sql delete mode 100644 db/changes/240001/02-views.sql delete mode 100644 db/changes/240002/00-silexToSalix.sql delete mode 100644 db/docker.js delete mode 100755 db/docker/docker-dump.sh delete mode 100755 db/docker/docker-fixtures.sh delete mode 100755 db/docker/docker-init.sh delete mode 100755 db/docker/docker-start.sh delete mode 100755 db/docker/docker-structure.sh delete mode 100644 db/docker/docker-temp-stop.sh delete mode 100644 db/docker/docker.cnf create mode 100644 db/dump/.dump/data.sql create mode 100644 db/dump/.dump/privileges.sql rename db/dump/{ => .dump}/structure.sql (74%) create mode 100644 db/dump/Dockerfile create mode 100644 db/dump/db.cnf create mode 100644 db/dump/dump.after.sql create mode 100644 db/dump/dump.before.sql delete mode 100644 db/dump/dumpedFixtures.sql create mode 100644 db/dump/fixtures.after.sql create mode 100644 db/dump/fixtures.before.sql delete mode 100755 db/export-data.sh delete mode 100755 db/export-structure.sh delete mode 100755 db/import-changes.sh create mode 100644 db/remotes/ca.pem rename db/{config.ini => remotes/docker.ini} (53%) create mode 100644 db/remotes/local.ini create mode 100644 db/remotes/old-ca.pem create mode 100644 db/routines/account/functions/myUser_checkLogin.sql create mode 100644 db/routines/account/functions/myUser_getId.sql create mode 100644 db/routines/account/functions/myUser_getName.sql create mode 100644 db/routines/account/functions/myUser_hasPriv.sql create mode 100644 db/routines/account/functions/myUser_hasRole.sql create mode 100644 db/routines/account/functions/myUser_hasRoleId.sql create mode 100644 db/routines/account/functions/myUser_hasRoutinePriv.sql create mode 100644 db/routines/account/functions/passwordGenerate.sql create mode 100644 db/routines/account/functions/toUnixDays.sql create mode 100644 db/routines/account/functions/user_getMysqlRole.sql create mode 100644 db/routines/account/functions/user_getNameFromId.sql create mode 100644 db/routines/account/functions/user_hasPriv.sql create mode 100644 db/routines/account/functions/user_hasRole.sql create mode 100644 db/routines/account/functions/user_hasRoleId.sql create mode 100644 db/routines/account/functions/user_hasRoutinePriv.sql create mode 100644 db/routines/account/procedures/account_enable.sql create mode 100644 db/routines/account/procedures/myUser_login.sql create mode 100644 db/routines/account/procedures/myUser_loginWithKey.sql create mode 100644 db/routines/account/procedures/myUser_loginWithName.sql create mode 100644 db/routines/account/procedures/myUser_logout.sql create mode 100644 db/routines/account/procedures/role_checkName.sql create mode 100644 db/routines/account/procedures/role_getDescendents.sql create mode 100644 db/routines/account/procedures/role_sync.sql create mode 100644 db/routines/account/procedures/role_syncPrivileges.sql create mode 100644 db/routines/account/procedures/user_checkName.sql create mode 100644 db/routines/account/procedures/user_checkPassword.sql create mode 100644 db/routines/account/triggers/account_afterDelete.sql create mode 100644 db/routines/account/triggers/account_afterInsert.sql create mode 100644 db/routines/account/triggers/account_beforeInsert.sql create mode 100644 db/routines/account/triggers/account_beforeUpdate.sql create mode 100644 db/routines/account/triggers/mailAlias_afterDelete.sql create mode 100644 db/routines/account/triggers/mailAlias_beforeInsert.sql create mode 100644 db/routines/account/triggers/mailAlias_beforeUpdate.sql create mode 100644 db/routines/account/triggers/mailForward_afterDelete.sql create mode 100644 db/routines/account/triggers/mailForward_beforeInsert.sql create mode 100644 db/routines/account/triggers/mailForward_beforeUpdate.sql create mode 100644 db/routines/account/triggers/roleInherit_afterDelete.sql create mode 100644 db/routines/account/triggers/roleInherit_beforeInsert.sql create mode 100644 db/routines/account/triggers/roleInherit_beforeUpdate.sql create mode 100644 db/routines/account/triggers/role_afterDelete.sql create mode 100644 db/routines/account/triggers/role_beforeInsert.sql create mode 100644 db/routines/account/triggers/role_beforeUpdate.sql create mode 100644 db/routines/account/triggers/user_afterDelete.sql create mode 100644 db/routines/account/triggers/user_afterInsert.sql create mode 100644 db/routines/account/triggers/user_afterUpdate.sql create mode 100644 db/routines/account/triggers/user_beforeInsert.sql create mode 100644 db/routines/account/triggers/user_beforeUpdate.sql create mode 100644 db/routines/account/views/accountDovecot.sql create mode 100644 db/routines/account/views/emailUser.sql create mode 100644 db/routines/account/views/myRole.sql create mode 100644 db/routines/account/views/myUser.sql create mode 100644 db/routines/bi/functions/nz.sql create mode 100644 db/routines/bi/procedures/Greuge_Evolution_Add.sql create mode 100644 db/routines/bi/procedures/analisis_ventas_evolution_add.sql create mode 100644 db/routines/bi/procedures/analisis_ventas_simple.sql create mode 100644 db/routines/bi/procedures/analisis_ventas_update.sql create mode 100644 db/routines/bi/procedures/claim_ratio_routine.sql create mode 100644 db/routines/bi/procedures/clean.sql create mode 100644 db/routines/bi/procedures/clean_launcher.sql create mode 100644 db/routines/bi/procedures/comparativa_add.sql create mode 100644 db/routines/bi/procedures/comparativa_add_manual.sql create mode 100644 db/routines/bi/procedures/defaultersFromDate.sql create mode 100644 db/routines/bi/procedures/defaulting.sql create mode 100644 db/routines/bi/procedures/defaulting_launcher.sql create mode 100644 db/routines/bi/procedures/facturacion_media_anual_update.sql create mode 100644 db/routines/bi/procedures/greuge_dif_porte_add.sql create mode 100644 db/routines/bi/procedures/nigthlyAnalisisVentas.sql create mode 100644 db/routines/bi/procedures/rutasAnalyze.sql create mode 100644 db/routines/bi/procedures/rutasAnalyze_launcher.sql create mode 100644 db/routines/bi/views/analisis_grafico_ventas.sql create mode 100644 db/routines/bi/views/analisis_ventas_simple.sql create mode 100644 db/routines/bi/views/claims_ratio.sql create mode 100644 db/routines/bi/views/customerRiskOverdue.sql create mode 100644 db/routines/bi/views/defaulters.sql create mode 100644 db/routines/bi/views/facturacion_media_anual.sql create mode 100644 db/routines/bi/views/last_Id_Cubo.sql create mode 100644 db/routines/bi/views/rotacion.sql create mode 100644 db/routines/bi/views/tarifa_componentes.sql create mode 100644 db/routines/bi/views/tarifa_componentes_series.sql create mode 100644 db/routines/bi/views/v_clientes_jerarquia.sql create mode 100644 db/routines/bi/views/v_ventas_contables.sql create mode 100644 db/routines/bs/events/clientDied_recalc.sql create mode 100644 db/routines/bs/events/inventoryDiscrepancy_launch.sql create mode 100644 db/routines/bs/events/nightTask_launchAll.sql create mode 100644 db/routines/bs/functions/tramo.sql create mode 100644 db/routines/bs/procedures/bancos_evolution_add.sql create mode 100644 db/routines/bs/procedures/campaignComparative.sql create mode 100644 db/routines/bs/procedures/carteras_add.sql create mode 100644 db/routines/bs/procedures/clean.sql create mode 100644 db/routines/bs/procedures/clientDied_recalc.sql create mode 100644 db/routines/bs/procedures/clientNewBorn_recalc.sql create mode 100644 db/routines/bs/procedures/comercialesCompleto.sql create mode 100644 db/routines/bs/procedures/compradores_evolution_add.sql create mode 100644 db/routines/bs/procedures/fondo_evolution_add.sql create mode 100644 db/routines/bs/procedures/fruitsEvolution.sql create mode 100644 db/routines/bs/procedures/indicatorsUpdate.sql create mode 100644 db/routines/bs/procedures/indicatorsUpdateLauncher.sql create mode 100644 db/routines/bs/procedures/inventoryDiscrepancyDetail_replace.sql create mode 100644 db/routines/bs/procedures/m3Add.sql create mode 100644 db/routines/bs/procedures/manaCustomerUpdate.sql create mode 100644 db/routines/bs/procedures/manaSpellers_actualize.sql create mode 100644 db/routines/bs/procedures/nightTask_launchAll.sql create mode 100644 db/routines/bs/procedures/nightTask_launchTask.sql create mode 100644 db/routines/bs/procedures/payMethodClientAdd.sql create mode 100644 db/routines/bs/procedures/saleGraphic.sql create mode 100644 db/routines/bs/procedures/salePersonEvolutionAdd.sql create mode 100644 db/routines/bs/procedures/salesByItemTypeDay_add.sql create mode 100644 db/routines/bs/procedures/salesByItemTypeDay_addLauncher.sql create mode 100644 db/routines/bs/procedures/salesByclientSalesPerson_add.sql create mode 100644 db/routines/bs/procedures/salesPersonEvolution_add.sql create mode 100644 db/routines/bs/procedures/vendedores_add_launcher.sql create mode 100644 db/routines/bs/procedures/ventas_add.sql create mode 100644 db/routines/bs/procedures/ventas_add_launcher.sql create mode 100644 db/routines/bs/procedures/ventas_contables_add.sql create mode 100644 db/routines/bs/procedures/ventas_contables_add_launcher.sql create mode 100644 db/routines/bs/procedures/ventas_contables_por_cliente.sql create mode 100644 db/routines/bs/procedures/vivosMuertos.sql create mode 100644 db/routines/bs/procedures/waste_addSales.sql create mode 100644 db/routines/bs/procedures/workerLabour_getData.sql create mode 100644 db/routines/bs/procedures/workerProductivity_add.sql create mode 100644 db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql create mode 100644 db/routines/bs/triggers/nightTaskBeforeInsert.sql create mode 100644 db/routines/bs/triggers/nightTaskBeforeUpdate.sql create mode 100644 db/routines/bs/views/VentasPorCliente.sql create mode 100644 db/routines/bs/views/bajasLaborales.sql create mode 100644 db/routines/bs/views/horasSilla.sql create mode 100644 db/routines/bs/views/lastIndicators.sql create mode 100644 db/routines/bs/views/packingSpeed.sql create mode 100644 db/routines/bs/views/s1_ticketDetail.sql create mode 100644 db/routines/bs/views/s21_saleDetail.sql create mode 100644 db/routines/bs/views/ventas.sql create mode 100644 db/routines/cache/events/cacheCalc_clean.sql create mode 100644 db/routines/cache/events/cache_clean.sql create mode 100644 db/routines/cache/procedures/addressFriendship_Update.sql create mode 100644 db/routines/cache/procedures/availableNoRaids_refresh.sql create mode 100644 db/routines/cache/procedures/available_clean.sql create mode 100644 db/routines/cache/procedures/available_refresh.sql create mode 100644 db/routines/cache/procedures/cacheCalc_clean.sql create mode 100644 db/routines/cache/procedures/cache_calc_end.sql create mode 100644 db/routines/cache/procedures/cache_calc_start.sql create mode 100644 db/routines/cache/procedures/cache_calc_unlock.sql create mode 100644 db/routines/cache/procedures/cache_clean.sql create mode 100644 db/routines/cache/procedures/clean.sql create mode 100644 db/routines/cache/procedures/departure_timing.sql create mode 100644 db/routines/cache/procedures/last_buy_refresh.sql create mode 100644 db/routines/cache/procedures/prod_graphic_refresh.sql create mode 100644 db/routines/cache/procedures/stock_refresh.sql create mode 100644 db/routines/cache/procedures/visible_clean.sql create mode 100644 db/routines/cache/procedures/visible_refresh.sql create mode 100644 db/routines/dipole/procedures/clean.sql create mode 100644 db/routines/dipole/procedures/expedition_add.sql create mode 100644 db/routines/dipole/views/expeditionControl.sql create mode 100644 db/routines/edi/events/floramondo.sql create mode 100644 db/routines/edi/functions/imageName.sql create mode 100644 db/routines/edi/procedures/clean.sql create mode 100644 db/routines/edi/procedures/deliveryInformation_Delete.sql create mode 100644 db/routines/edi/procedures/ekt_add.sql create mode 100644 db/routines/edi/procedures/ekt_load.sql create mode 100644 db/routines/edi/procedures/ekt_loadNotBuy.sql create mode 100644 db/routines/edi/procedures/ekt_refresh.sql create mode 100644 db/routines/edi/procedures/ekt_scan.sql create mode 100644 db/routines/edi/procedures/floramondo_offerRefresh.sql create mode 100644 db/routines/edi/procedures/item_freeAdd.sql create mode 100644 db/routines/edi/procedures/item_getNewByEkt.sql create mode 100644 db/routines/edi/procedures/mail_new.sql create mode 100644 db/routines/edi/triggers/BEFORE UPDATE.sql create mode 100644 db/routines/edi/triggers/item_feature_bi.sql create mode 100644 db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql create mode 100644 db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql create mode 100644 db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql create mode 100644 db/routines/edi/views/ektRecent.sql create mode 100644 db/routines/edi/views/errorList.sql create mode 100644 db/routines/edi/views/supplyOffer.sql create mode 100644 db/routines/hedera/events/order_doRecalc.sql create mode 100644 db/routines/hedera/functions/myClient_getDebt.sql create mode 100644 db/routines/hedera/functions/myUser_checkRestPriv.sql create mode 100644 db/routines/hedera/functions/order_getTotal.sql create mode 100644 db/routines/hedera/procedures/catalog_calcFromMyAddress.sql create mode 100644 db/routines/hedera/procedures/image_ref.sql create mode 100644 db/routines/hedera/procedures/image_unref.sql create mode 100644 db/routines/hedera/procedures/item_calcCatalog.sql create mode 100644 db/routines/hedera/procedures/item_getVisible.sql create mode 100644 db/routines/hedera/procedures/item_listAllocation.sql create mode 100644 db/routines/hedera/procedures/myOrder_addItem.sql create mode 100644 db/routines/hedera/procedures/myOrder_calcCatalogFromItem.sql create mode 100644 db/routines/hedera/procedures/myOrder_calcCatalogFull.sql create mode 100644 db/routines/hedera/procedures/myOrder_checkConfig.sql create mode 100644 db/routines/hedera/procedures/myOrder_checkMine.sql create mode 100644 db/routines/hedera/procedures/myOrder_configure.sql create mode 100644 db/routines/hedera/procedures/myOrder_configureForGuest.sql create mode 100644 db/routines/hedera/procedures/myOrder_confirm.sql create mode 100644 db/routines/hedera/procedures/myOrder_create.sql create mode 100644 db/routines/hedera/procedures/myOrder_getAvailable.sql create mode 100644 db/routines/hedera/procedures/myOrder_getTax.sql create mode 100644 db/routines/hedera/procedures/myOrder_newWithAddress.sql create mode 100644 db/routines/hedera/procedures/myOrder_newWithDate.sql create mode 100644 db/routines/hedera/procedures/myTicket_get.sql create mode 100644 db/routines/hedera/procedures/myTicket_getPackages.sql create mode 100644 db/routines/hedera/procedures/myTicket_getRows.sql create mode 100644 db/routines/hedera/procedures/myTicket_getServices.sql create mode 100644 db/routines/hedera/procedures/myTicket_list.sql create mode 100644 db/routines/hedera/procedures/myTicket_logAccess.sql create mode 100644 db/routines/hedera/procedures/myTpvTransaction_end.sql create mode 100644 db/routines/hedera/procedures/myTpvTransaction_start.sql create mode 100644 db/routines/hedera/procedures/order_addItem.sql create mode 100644 db/routines/hedera/procedures/order_calcCatalog.sql create mode 100644 db/routines/hedera/procedures/order_calcCatalogFromItem.sql create mode 100644 db/routines/hedera/procedures/order_calcCatalogFull.sql create mode 100644 db/routines/hedera/procedures/order_checkConfig.sql create mode 100644 db/routines/hedera/procedures/order_checkEditable.sql create mode 100644 db/routines/hedera/procedures/order_configure.sql create mode 100644 db/routines/hedera/procedures/order_confirm.sql create mode 100644 db/routines/hedera/procedures/order_confirmWithUser.sql create mode 100644 db/routines/hedera/procedures/order_doRecalc.sql create mode 100644 db/routines/hedera/procedures/order_getAvailable.sql create mode 100644 db/routines/hedera/procedures/order_getTax.sql create mode 100644 db/routines/hedera/procedures/order_getTotal.sql create mode 100644 db/routines/hedera/procedures/order_recalc.sql create mode 100644 db/routines/hedera/procedures/order_requestRecalc.sql create mode 100644 db/routines/hedera/procedures/order_update.sql create mode 100644 db/routines/hedera/procedures/survey_vote.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_confirm.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_confirmAll.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_confirmById.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_confirmFromExport.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_end.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_start.sql create mode 100644 db/routines/hedera/procedures/tpvTransaction_undo.sql create mode 100644 db/routines/hedera/procedures/visitUser_new.sql create mode 100644 db/routines/hedera/procedures/visit_listByBrowser.sql create mode 100644 db/routines/hedera/procedures/visit_register.sql create mode 100644 db/routines/hedera/triggers/link_afterDelete.sql create mode 100644 db/routines/hedera/triggers/link_afterInsert.sql create mode 100644 db/routines/hedera/triggers/link_afterUpdate.sql create mode 100644 db/routines/hedera/triggers/news_afterDelete.sql create mode 100644 db/routines/hedera/triggers/news_afterInsert.sql create mode 100644 db/routines/hedera/triggers/news_afterUpdate.sql create mode 100644 db/routines/hedera/triggers/orderRow_afterDelete.sql create mode 100644 db/routines/hedera/triggers/orderRow_afterInsert.sql create mode 100644 db/routines/hedera/triggers/orderRow_afterUpdate.sql create mode 100644 db/routines/hedera/triggers/orderRow_beforeInsert.sql create mode 100644 db/routines/hedera/triggers/order_afterInsert.sql create mode 100644 db/routines/hedera/triggers/order_afterUpdate.sql create mode 100644 db/routines/hedera/triggers/order_beforeDelete.sql create mode 100644 db/routines/hedera/views/mainAccountBank.sql create mode 100644 db/routines/hedera/views/messageL10n.sql create mode 100644 db/routines/hedera/views/myAddress.sql create mode 100644 db/routines/hedera/views/myBasketDefaults.sql create mode 100644 db/routines/hedera/views/myClient.sql create mode 100644 db/routines/hedera/views/myInvoice.sql create mode 100644 db/routines/hedera/views/myMenu.sql create mode 100644 db/routines/hedera/views/myOrder.sql create mode 100644 db/routines/hedera/views/myOrderRow.sql create mode 100644 db/routines/hedera/views/myOrderTicket.sql create mode 100644 db/routines/hedera/views/myTicket.sql create mode 100644 db/routines/hedera/views/myTicketRow.sql create mode 100644 db/routines/hedera/views/myTicketService.sql create mode 100644 db/routines/hedera/views/myTicketState.sql create mode 100644 db/routines/hedera/views/myTpvTransaction.sql create mode 100644 db/routines/hedera/views/orderTicket.sql create mode 100644 db/routines/hedera/views/order_component.sql create mode 100644 db/routines/hedera/views/order_row.sql create mode 100644 db/routines/pbx/functions/clientFromPhone.sql create mode 100644 db/routines/pbx/functions/phone_format.sql create mode 100644 db/routines/pbx/procedures/phone_isValid.sql create mode 100644 db/routines/pbx/procedures/queue_isValid.sql create mode 100644 db/routines/pbx/procedures/sip_getExtension.sql create mode 100644 db/routines/pbx/procedures/sip_isValid.sql create mode 100644 db/routines/pbx/procedures/sip_setPassword.sql create mode 100644 db/routines/pbx/triggers/blacklist_beforeInsert.sql create mode 100644 db/routines/pbx/triggers/blacklist_berforeUpdate.sql create mode 100644 db/routines/pbx/triggers/followme_beforeInsert.sql create mode 100644 db/routines/pbx/triggers/followme_beforeUpdate.sql create mode 100644 db/routines/pbx/triggers/queuePhone_beforeInsert.sql create mode 100644 db/routines/pbx/triggers/queuePhone_beforeUpdate.sql create mode 100644 db/routines/pbx/triggers/queue_beforeInsert.sql create mode 100644 db/routines/pbx/triggers/queue_beforeUpdate.sql create mode 100644 db/routines/pbx/triggers/sip_afterInsert.sql create mode 100644 db/routines/pbx/triggers/sip_afterUpdate.sql create mode 100644 db/routines/pbx/triggers/sip_beforeInsert.sql create mode 100644 db/routines/pbx/triggers/sip_beforeUpdate.sql create mode 100644 db/routines/pbx/views/cdrConf.sql create mode 100644 db/routines/pbx/views/followmeConf.sql create mode 100644 db/routines/pbx/views/followmeNumberConf.sql create mode 100644 db/routines/pbx/views/queueConf.sql create mode 100644 db/routines/pbx/views/queueMemberConf.sql create mode 100644 db/routines/pbx/views/sipConf.sql create mode 100644 db/routines/psico/procedures/answerSort.sql create mode 100644 db/routines/psico/procedures/examNew.sql create mode 100644 db/routines/psico/procedures/getExamQuestions.sql create mode 100644 db/routines/psico/procedures/getExamType.sql create mode 100644 db/routines/psico/procedures/questionSort.sql create mode 100644 db/routines/psico/views/examView.sql create mode 100644 db/routines/psico/views/results.sql create mode 100644 db/routines/sage/functions/company_getCode.sql rename db/{.archive/225201/00-accountingMovements_add.sql => routines/sage/procedures/accountingMovements_add.sql} (86%) rename db/{.archive/230801/01-sage_supplierAdd.sql => routines/sage/procedures/clientSupplier_add.sql} (86%) create mode 100644 db/routines/sage/procedures/invoiceIn_add.sql create mode 100644 db/routines/sage/procedures/invoiceIn_manager.sql create mode 100644 db/routines/sage/procedures/invoiceOut_add.sql create mode 100644 db/routines/sage/procedures/invoiceOut_manager.sql create mode 100644 db/routines/sage/procedures/pgc_add.sql create mode 100644 db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql create mode 100644 db/routines/sage/views/clientLastTwoMonths.sql create mode 100644 db/routines/sage/views/supplierLastThreeMonths.sql create mode 100644 db/routines/salix/events/accessToken_prune.sql create mode 100644 db/routines/salix/procedures/accessToken_prune.sql create mode 100644 db/routines/salix/views/Account.sql create mode 100644 db/routines/salix/views/Role.sql create mode 100644 db/routines/salix/views/RoleMapping.sql create mode 100644 db/routines/salix/views/User.sql create mode 100644 db/routines/srt/events/moving_clean.sql create mode 100644 db/routines/srt/functions/bid.sql create mode 100644 db/routines/srt/functions/bufferPool_get.sql create mode 100644 db/routines/srt/functions/buffer_get.sql create mode 100644 db/routines/srt/functions/buffer_getRandom.sql create mode 100644 db/routines/srt/functions/buffer_getState.sql create mode 100644 db/routines/srt/functions/buffer_getType.sql create mode 100644 db/routines/srt/functions/buffer_isFull.sql create mode 100644 db/routines/srt/functions/dayMinute.sql create mode 100644 db/routines/srt/functions/expedition_check.sql create mode 100644 db/routines/srt/functions/expedition_getDayMinute.sql create mode 100644 db/routines/srt/procedures/buffer_getExpCount.sql create mode 100644 db/routines/srt/procedures/buffer_getStateType.sql create mode 100644 db/routines/srt/procedures/buffer_giveBack.sql create mode 100644 db/routines/srt/procedures/buffer_readPhotocell.sql create mode 100644 db/routines/srt/procedures/buffer_setEmpty.sql create mode 100644 db/routines/srt/procedures/buffer_setState.sql create mode 100644 db/routines/srt/procedures/buffer_setStateType.sql create mode 100644 db/routines/srt/procedures/buffer_setType.sql create mode 100644 db/routines/srt/procedures/buffer_setTypeByName.sql create mode 100644 db/routines/srt/procedures/clean.sql create mode 100644 db/routines/srt/procedures/expeditionLoading_add.sql create mode 100644 db/routines/srt/procedures/expedition_arrived.sql create mode 100644 db/routines/srt/procedures/expedition_bufferOut.sql create mode 100644 db/routines/srt/procedures/expedition_entering.sql create mode 100644 db/routines/srt/procedures/expedition_get.sql create mode 100644 db/routines/srt/procedures/expedition_groupOut.sql create mode 100644 db/routines/srt/procedures/expedition_in.sql create mode 100644 db/routines/srt/procedures/expedition_moving.sql create mode 100644 db/routines/srt/procedures/expedition_out.sql create mode 100644 db/routines/srt/procedures/expedition_outAll.sql create mode 100644 db/routines/srt/procedures/expedition_relocate.sql create mode 100644 db/routines/srt/procedures/expedition_reset.sql create mode 100644 db/routines/srt/procedures/expedition_routeOut.sql create mode 100644 db/routines/srt/procedures/expedition_scan.sql create mode 100644 db/routines/srt/procedures/expedition_setDimensions.sql create mode 100644 db/routines/srt/procedures/expedition_weighing.sql create mode 100644 db/routines/srt/procedures/failureLog_add.sql create mode 100644 db/routines/srt/procedures/lastRFID_add.sql create mode 100644 db/routines/srt/procedures/lastRFID_add_beta.sql create mode 100644 db/routines/srt/procedures/moving_CollidingSet.sql create mode 100644 db/routines/srt/procedures/moving_between.sql create mode 100644 db/routines/srt/procedures/moving_clean.sql create mode 100644 db/routines/srt/procedures/moving_delete.sql create mode 100644 db/routines/srt/procedures/moving_groupOut.sql create mode 100644 db/routines/srt/procedures/moving_next.sql create mode 100644 db/routines/srt/procedures/photocell_setActive.sql create mode 100644 db/routines/srt/procedures/randomMoving.sql create mode 100644 db/routines/srt/procedures/randomMoving_Launch.sql create mode 100644 db/routines/srt/procedures/restart.sql create mode 100644 db/routines/srt/procedures/start.sql create mode 100644 db/routines/srt/procedures/stop.sql create mode 100644 db/routines/srt/procedures/test.sql create mode 100644 db/routines/srt/triggers/expedition_BU.sql create mode 100644 db/routines/srt/triggers/moving_AI.sql create mode 100644 db/routines/srt/views/bufferDayMinute.sql create mode 100644 db/routines/srt/views/bufferFreeLength.sql create mode 100644 db/routines/srt/views/bufferStock.sql create mode 100644 db/routines/srt/views/expeditionVolume.sql create mode 100644 db/routines/srt/views/routePalletized.sql create mode 100644 db/routines/srt/views/routeVolume.sql create mode 100644 db/routines/srt/views/ticketPalletized.sql create mode 100644 db/routines/srt/views/upperStickers.sql create mode 100644 db/routines/stock/events/log_clean.sql create mode 100644 db/routines/stock/events/log_syncNoWait.sql create mode 100644 db/routines/stock/procedures/inbound_addPick.sql create mode 100644 db/routines/stock/procedures/inbound_removePick.sql create mode 100644 db/routines/stock/procedures/inbound_requestQuantity.sql create mode 100644 db/routines/stock/procedures/inbound_sync.sql create mode 100644 db/routines/stock/procedures/log_add.sql create mode 100644 db/routines/stock/procedures/log_clean.sql create mode 100644 db/routines/stock/procedures/log_delete.sql create mode 100644 db/routines/stock/procedures/log_refreshAll.sql create mode 100644 db/routines/stock/procedures/log_refreshBuy.sql create mode 100644 db/routines/stock/procedures/log_refreshOrder.sql create mode 100644 db/routines/stock/procedures/log_refreshSale.sql create mode 100644 db/routines/stock/procedures/log_sync.sql create mode 100644 db/routines/stock/procedures/log_syncNoWait.sql create mode 100644 db/routines/stock/procedures/outbound_requestQuantity.sql create mode 100644 db/routines/stock/procedures/outbound_sync.sql create mode 100644 db/routines/stock/procedures/visible_log.sql create mode 100644 db/routines/stock/triggers/inbound_afterDelete.sql create mode 100644 db/routines/stock/triggers/inbound_beforeInsert.sql create mode 100644 db/routines/stock/triggers/outbound_afterDelete.sql create mode 100644 db/routines/stock/triggers/outbound_beforeInsert.sql create mode 100644 db/routines/tmp/events/clean.sql create mode 100644 db/routines/tmp/procedures/clean.sql create mode 100644 db/routines/util/events/slowLog_prune.sql create mode 100644 db/routines/util/functions/VN_CURDATE.sql create mode 100644 db/routines/util/functions/VN_CURTIME.sql create mode 100644 db/routines/util/functions/VN_NOW.sql create mode 100644 db/routines/util/functions/VN_UNIX_TIMESTAMP.sql create mode 100644 db/routines/util/functions/VN_UTC_DATE.sql create mode 100644 db/routines/util/functions/VN_UTC_TIME.sql create mode 100644 db/routines/util/functions/VN_UTC_TIMESTAMP.sql create mode 100644 db/routines/util/functions/accountShortToStandard.sql create mode 100644 db/routines/util/functions/capitalizeFirst.sql create mode 100644 db/routines/util/functions/crypt.sql create mode 100644 db/routines/util/functions/cryptOff.sql create mode 100644 db/routines/util/functions/dayEnd.sql create mode 100644 db/routines/util/functions/firstDayOfMonth.sql create mode 100644 db/routines/util/functions/firstDayOfYear.sql create mode 100644 db/routines/util/functions/formatRow.sql create mode 100644 db/routines/util/functions/formatTable.sql create mode 100644 db/routines/util/functions/hasDateOverlapped.sql create mode 100644 db/routines/util/functions/hmacSha2.sql create mode 100644 db/routines/util/functions/isLeapYear.sql create mode 100644 db/routines/util/functions/json_removeNulls.sql create mode 100644 db/routines/util/functions/lang.sql create mode 100644 db/routines/util/functions/lastDayOfYear.sql create mode 100644 db/routines/util/functions/log_formatDate.sql create mode 100644 db/routines/util/functions/midnight.sql create mode 100644 db/routines/util/functions/mockTime.sql create mode 100644 db/routines/util/functions/mockTimeBase.sql create mode 100644 db/routines/util/functions/mockUtcTime.sql create mode 100644 db/routines/util/functions/nextWeek.sql rename db/{.archive/224702/00-notificationProc.sql => routines/util/functions/notification_send.sql} (66%) create mode 100644 db/routines/util/functions/quarterFirstDay.sql create mode 100644 db/routines/util/functions/quoteIdentifier.sql create mode 100644 db/routines/util/functions/stringXor.sql create mode 100644 db/routines/util/functions/today.sql create mode 100644 db/routines/util/functions/tomorrow.sql create mode 100644 db/routines/util/functions/twoDaysAgo.sql create mode 100644 db/routines/util/functions/yearRelativePosition.sql create mode 100644 db/routines/util/functions/yesterday.sql create mode 100644 db/routines/util/procedures/checkHex.sql create mode 100644 db/routines/util/procedures/debugAdd.sql create mode 100644 db/routines/util/procedures/exec.sql create mode 100644 db/routines/util/procedures/log_add.sql create mode 100644 db/routines/util/procedures/log_addWithUser.sql create mode 100644 db/routines/util/procedures/log_cleanInstances.sql create mode 100644 db/routines/util/procedures/procNoOverlap.sql create mode 100644 db/routines/util/procedures/proc_changedPrivs.sql create mode 100644 db/routines/util/procedures/proc_restorePrivs.sql create mode 100644 db/routines/util/procedures/proc_savePrivs.sql create mode 100644 db/routines/util/procedures/slowLog_prune.sql create mode 100644 db/routines/util/procedures/throw.sql create mode 100644 db/routines/util/procedures/time_generate.sql create mode 100644 db/routines/util/procedures/warn.sql create mode 100644 db/routines/util/views/eventLogGrouped.sql create mode 100644 db/routines/vn/events/client_unassignSalesPerson.sql create mode 100644 db/routines/vn/events/clientsDisable.sql create mode 100644 db/routines/vn/events/collection_make.sql create mode 100644 db/routines/vn/events/department_doCalc.sql create mode 100644 db/routines/vn/events/envialiaThreHoldChecker.sql create mode 100644 db/routines/vn/events/greuge_notify.sql create mode 100644 db/routines/vn/events/itemImageQueue_check.sql create mode 100644 db/routines/vn/events/mysqlConnectionsSorter_kill.sql create mode 100644 db/routines/vn/events/printQueue_check.sql create mode 100644 db/routines/vn/events/route_doRecalc.sql create mode 100644 db/routines/vn/events/sale_checkWithoutComponents.sql create mode 100644 db/routines/vn/events/ticket_doRecalc.sql create mode 100644 db/routines/vn/events/travel_doRecalc.sql create mode 100644 db/routines/vn/events/vehicle_notify.sql create mode 100644 db/routines/vn/events/workerJourney_doRecalc.sql create mode 100644 db/routines/vn/events/worker_updateChangedBusiness.sql create mode 100644 db/routines/vn/events/zoneGeo_doCalc.sql create mode 100644 db/routines/vn/functions/MIDNIGHT.sql create mode 100644 db/routines/vn/functions/addressTaxArea.sql create mode 100644 db/routines/vn/functions/address_getGeo.sql create mode 100644 db/routines/vn/functions/barcodeToItem.sql create mode 100644 db/routines/vn/functions/buy_getUnitVolume.sql create mode 100644 db/routines/vn/functions/buy_getVolume.sql create mode 100644 db/routines/vn/functions/catalog_componentReverse.sql create mode 100644 db/routines/vn/functions/clientGetMana.sql create mode 100644 db/routines/vn/functions/clientGetSalesPerson.sql create mode 100644 db/routines/vn/functions/clientTaxArea.sql create mode 100644 db/routines/vn/functions/client_getDebt.sql create mode 100644 db/routines/vn/functions/client_getFromPhone.sql create mode 100644 db/routines/vn/functions/client_getSalesPerson.sql create mode 100644 db/routines/vn/functions/client_getSalesPersonByTicket.sql create mode 100644 db/routines/vn/functions/client_getSalesPersonCode.sql create mode 100644 db/routines/vn/functions/client_getSalesPersonCodeByTicket.sql create mode 100644 db/routines/vn/functions/client_hasDifferentCountries.sql create mode 100644 db/routines/vn/functions/collection_isPacked.sql create mode 100644 db/routines/vn/functions/currency_getCommission.sql create mode 100644 db/routines/vn/functions/currentRate.sql create mode 100644 db/routines/vn/functions/deviceProductionUser_accessGranted.sql create mode 100644 db/routines/vn/functions/duaTax_getRate.sql create mode 100644 db/routines/vn/functions/ekt_getEntry.sql create mode 100644 db/routines/vn/functions/ekt_getTravel.sql rename db/{.archive/232401/.gitkeep => routines/vn/functions/entry_count} (100%) create mode 100644 db/routines/vn/functions/entry_getCommission.sql create mode 100644 db/routines/vn/functions/entry_getCurrency.sql create mode 100644 db/routines/vn/functions/entry_getForLogiflora.sql create mode 100644 db/routines/vn/functions/entry_isIntrastat.sql create mode 100644 db/routines/vn/functions/entry_isInventoryOrPrevious.sql create mode 100644 db/routines/vn/functions/expedition_checkRoute.sql create mode 100644 db/routines/vn/functions/firstDayOfWeek.sql create mode 100644 db/routines/vn/functions/getAlert3State.sql create mode 100644 db/routines/vn/functions/getAlert3StateTest.sql create mode 100644 db/routines/vn/functions/getDueDate.sql create mode 100644 db/routines/vn/functions/getInventoryDate.sql create mode 100644 db/routines/vn/functions/getNewItemId.sql create mode 100644 db/routines/vn/functions/getNextDueDate.sql create mode 100644 db/routines/vn/functions/getShipmentHour.sql create mode 100644 db/routines/vn/functions/getSpecialPrice.sql create mode 100644 db/routines/vn/functions/getTicketTrolleyLabelCount.sql create mode 100644 db/routines/vn/functions/getUser.sql create mode 100644 db/routines/vn/functions/getUserId.sql create mode 100644 db/routines/vn/functions/hasAnyNegativeBase.sql create mode 100644 db/routines/vn/functions/hasItemsInSector.sql create mode 100644 db/routines/vn/functions/hasSomeNegativeBase.sql create mode 100644 db/routines/vn/functions/invoiceOutAmount.sql rename db/{.archive/231001/01-invoiceOut_getMaxIssued.sql => routines/vn/functions/invoiceOut_getMaxIssued.sql} (83%) create mode 100644 db/routines/vn/functions/invoiceOut_getPath.sql rename db/{.archive/231001/00-invoiceOut_getWeight.sql => routines/vn/functions/invoiceOut_getWeight.sql} (75%) create mode 100644 db/routines/vn/functions/invoiceSerial.sql create mode 100644 db/routines/vn/functions/invoiceSerialArea.sql create mode 100644 db/routines/vn/functions/isLogifloraDay.sql create mode 100644 db/routines/vn/functions/isPalletHomogeneus.sql create mode 100644 db/routines/vn/functions/itemPacking.sql create mode 100644 db/routines/vn/functions/itemShelvingPlacementSupply_ClosestGet.sql create mode 100644 db/routines/vn/functions/itemTag_getIntValue.sql create mode 100644 db/routines/vn/functions/item_getFhImage.sql create mode 100644 db/routines/vn/functions/item_getPackage.sql create mode 100644 db/routines/vn/functions/item_getVolume.sql create mode 100644 db/routines/vn/functions/itemsInSector_get.sql create mode 100644 db/routines/vn/functions/lastDayOfWeek.sql create mode 100644 db/routines/vn/functions/machine_checkPlate.sql create mode 100644 db/routines/vn/functions/messageSend.sql create mode 100644 db/routines/vn/functions/messageSendWithUser.sql create mode 100644 db/routines/vn/functions/nz.sql create mode 100644 db/routines/vn/functions/orderTotalVolume.sql create mode 100644 db/routines/vn/functions/orderTotalVolumeBoxes.sql create mode 100644 db/routines/vn/functions/packaging_calculate.sql rename db/{.archive/230201/00-priceFixed_getRate2.sql => routines/vn/functions/priceFixed_getRate2.sql} (69%) create mode 100644 db/routines/vn/functions/routeProposal.sql create mode 100644 db/routines/vn/functions/routeProposal_.sql create mode 100644 db/routines/vn/functions/routeProposal_beta.sql create mode 100644 db/routines/vn/functions/specie_IsForbidden.sql create mode 100644 db/routines/vn/functions/testCIF.sql create mode 100644 db/routines/vn/functions/testNIE.sql create mode 100644 db/routines/vn/functions/testNIF.sql create mode 100644 db/routines/vn/functions/ticketCollection_getNoPacked.sql create mode 100644 db/routines/vn/functions/ticketGetTotal.sql create mode 100644 db/routines/vn/functions/ticketPositionInPath.sql create mode 100644 db/routines/vn/functions/ticketSplitCounter.sql create mode 100644 db/routines/vn/functions/ticketTotalVolume.sql create mode 100644 db/routines/vn/functions/ticketTotalVolumeBoxes.sql create mode 100644 db/routines/vn/functions/ticketWarehouseGet.sql create mode 100644 db/routines/vn/functions/ticket_CC_volume.sql create mode 100644 db/routines/vn/functions/ticket_HasUbication.sql create mode 100644 db/routines/vn/functions/ticket_get.sql create mode 100644 db/routines/vn/functions/ticket_getFreightCost.sql create mode 100644 db/routines/vn/functions/ticket_getWeight.sql create mode 100644 db/routines/vn/functions/ticket_isOutClosureZone.sql create mode 100644 db/routines/vn/functions/till_new.sql create mode 100644 db/routines/vn/functions/timeWorkerControl_getDirection.sql create mode 100644 db/routines/vn/functions/time_getSalesYear.sql create mode 100644 db/routines/vn/functions/travel_getForLogiflora.sql create mode 100644 db/routines/vn/functions/validationCode.sql create mode 100644 db/routines/vn/functions/validationCode_beta.sql create mode 100644 db/routines/vn/functions/workerMachinery_isRegistered.sql create mode 100644 db/routines/vn/functions/workerNigthlyHours_calculate.sql create mode 100644 db/routines/vn/functions/workerTimeControl_add.sql create mode 100644 db/routines/vn/functions/workerTimeControl_addDirection.sql create mode 100644 db/routines/vn/functions/worker_getCode.sql create mode 100644 db/routines/vn/functions/worker_isBoss.sql create mode 100644 db/routines/vn/functions/worker_isWorking.sql create mode 100644 db/routines/vn/functions/xdiario_new.sql create mode 100644 db/routines/vn/functions/zoneGeo_new.sql create mode 100644 db/routines/vn/procedures/XDiario_checkDate.sql create mode 100644 db/routines/vn/procedures/addNoteFromDelivery.sql create mode 100644 db/routines/vn/procedures/addressTaxArea.sql create mode 100644 db/routines/vn/procedures/agencyHourGetFirstShipped.sql create mode 100644 db/routines/vn/procedures/agencyHourGetLanded.sql create mode 100644 db/routines/vn/procedures/agencyHourGetWarehouse.sql create mode 100644 db/routines/vn/procedures/agencyHourListGetShipped.sql create mode 100644 db/routines/vn/procedures/available_calc.sql create mode 100644 db/routines/vn/procedures/bankEntity_checkBic.sql create mode 100644 db/routines/vn/procedures/bankPolicy_notifyExpired.sql create mode 100644 db/routines/vn/procedures/buyUltimate.sql create mode 100644 db/routines/vn/procedures/buyUltimateFromInterval.sql create mode 100644 db/routines/vn/procedures/buy_afterUpsert.sql create mode 100644 db/routines/vn/procedures/buy_checkGrouping.sql create mode 100644 db/routines/vn/procedures/buy_getSplit.sql create mode 100644 db/routines/vn/procedures/buy_getVolume.sql create mode 100644 db/routines/vn/procedures/buy_getVolumeByAgency.sql create mode 100644 db/routines/vn/procedures/buy_getVolumeByEntry.sql create mode 100644 db/routines/vn/procedures/buy_recalcPrices.sql create mode 100644 db/routines/vn/procedures/buy_recalcPricesByAwb.sql create mode 100644 db/routines/vn/procedures/buy_recalcPricesByBuy.sql create mode 100644 db/routines/vn/procedures/buy_recalcPricesByEntry.sql create mode 100644 db/routines/vn/procedures/buy_scan.sql create mode 100644 db/routines/vn/procedures/buy_updateGrouping.sql create mode 100644 db/routines/vn/procedures/buy_updatePacking.sql create mode 100644 db/routines/vn/procedures/catalog_calcFromItem.sql create mode 100644 db/routines/vn/procedures/catalog_calculate.sql create mode 100644 db/routines/vn/procedures/catalog_componentCalculate.sql create mode 100644 db/routines/vn/procedures/catalog_componentPrepare.sql create mode 100644 db/routines/vn/procedures/catalog_componentPurge.sql rename db/{.archive/230201/00-kkearSaleChecked.sql => routines/vn/procedures/clean.sql} (83%) create mode 100644 db/routines/vn/procedures/clean_logiflora.sql create mode 100644 db/routines/vn/procedures/clearShelvingList.sql create mode 100644 db/routines/vn/procedures/clientDebtSpray.sql create mode 100644 db/routines/vn/procedures/clientFreeze.sql create mode 100644 db/routines/vn/procedures/clientGetDebtDiary.sql create mode 100644 db/routines/vn/procedures/clientGreugeSpray.sql create mode 100644 db/routines/vn/procedures/clientPackagingOverstock.sql create mode 100644 db/routines/vn/procedures/clientPackagingOverstockReturn.sql create mode 100644 db/routines/vn/procedures/clientRemoveWorker.sql create mode 100644 db/routines/vn/procedures/clientRisk_update.sql create mode 100644 db/routines/vn/procedures/client_RandomList.sql create mode 100644 db/routines/vn/procedures/client_checkBalance.sql rename db/{.archive/233202/00-client_create_upper.sql => routines/vn/procedures/client_create.sql} (100%) create mode 100644 db/routines/vn/procedures/client_getDebt.sql create mode 100644 db/routines/vn/procedures/client_getMana.sql create mode 100644 db/routines/vn/procedures/client_unassignSalesPerson.sql create mode 100644 db/routines/vn/procedures/cmrPallet_add.sql create mode 100644 db/routines/vn/procedures/collectionPlacement_get.sql create mode 100644 db/routines/vn/procedures/collection_addItem.sql create mode 100644 db/routines/vn/procedures/collection_assign.sql create mode 100644 db/routines/vn/procedures/collection_get.sql create mode 100644 db/routines/vn/procedures/collection_getTickets.sql create mode 100644 db/routines/vn/procedures/collection_kill.sql create mode 100644 db/routines/vn/procedures/collection_make.sql create mode 100644 db/routines/vn/procedures/collection_new.sql create mode 100644 db/routines/vn/procedures/collection_printSticker.sql create mode 100644 db/routines/vn/procedures/collection_setParking.sql create mode 100644 db/routines/vn/procedures/collection_setState.sql create mode 100644 db/routines/vn/procedures/company_getFiscaldata.sql create mode 100644 db/routines/vn/procedures/company_getSuppliersDebt.sql create mode 100644 db/routines/vn/procedures/comparative_add.sql create mode 100644 db/routines/vn/procedures/conveyorExpedition_Add.sql create mode 100644 db/routines/vn/procedures/copyComponentsFromSaleList.sql create mode 100644 db/routines/vn/procedures/createPedidoInterno.sql create mode 100644 db/routines/vn/procedures/crypt.sql create mode 100644 db/routines/vn/procedures/cryptOff.sql create mode 100644 db/routines/vn/procedures/department_calcTree.sql create mode 100644 db/routines/vn/procedures/department_calcTreeRec.sql create mode 100644 db/routines/vn/procedures/department_doCalc.sql create mode 100644 db/routines/vn/procedures/department_getHasMistake.sql create mode 100644 db/routines/vn/procedures/department_getLeaves.sql create mode 100644 db/routines/vn/procedures/deviceLog_add.sql create mode 100644 db/routines/vn/procedures/deviceProductionUser_exists.sql create mode 100644 db/routines/vn/procedures/deviceProductionUser_getWorker.sql create mode 100644 db/routines/vn/procedures/deviceProduction_getnameDevice.sql create mode 100644 db/routines/vn/procedures/device_checkLogin.sql create mode 100644 db/routines/vn/procedures/duaEntryValueUpdate.sql create mode 100644 db/routines/vn/procedures/duaInvoiceInBooking.sql create mode 100644 db/routines/vn/procedures/duaParcialMake.sql create mode 100644 db/routines/vn/procedures/duaTaxBooking.sql create mode 100644 db/routines/vn/procedures/duaTax_doRecalc.sql create mode 100644 db/routines/vn/procedures/ediTables_Update.sql create mode 100644 db/routines/vn/procedures/ektEntryAssign_setEntry.sql create mode 100644 db/routines/vn/procedures/energyMeter_record.sql create mode 100644 db/routines/vn/procedures/entryDelivered.sql create mode 100644 db/routines/vn/procedures/entryWithItem.sql create mode 100644 db/routines/vn/procedures/entry_checkPackaging.sql create mode 100644 db/routines/vn/procedures/entry_clone.sql create mode 100644 db/routines/vn/procedures/entry_cloneHeader.sql create mode 100644 db/routines/vn/procedures/entry_cloneWithoutBuy.sql create mode 100644 db/routines/vn/procedures/entry_copyBuys.sql create mode 100644 db/routines/vn/procedures/entry_fixMisfit.sql create mode 100644 db/routines/vn/procedures/entry_getRate.sql create mode 100644 db/routines/vn/procedures/entry_lock.sql create mode 100644 db/routines/vn/procedures/entry_moveNotPrinted.sql create mode 100644 db/routines/vn/procedures/entry_notifyChanged.sql create mode 100644 db/routines/vn/procedures/entry_recalc.sql create mode 100644 db/routines/vn/procedures/entry_splitByShelving.sql create mode 100644 db/routines/vn/procedures/entry_splitMisfit.sql create mode 100644 db/routines/vn/procedures/entry_unlock.sql rename db/{.archive/232601/00-entry_updateComission.sql => routines/vn/procedures/entry_updateComission.sql} (96%) create mode 100644 db/routines/vn/procedures/expeditionGetFromRoute.sql create mode 100644 db/routines/vn/procedures/expeditionPallet_Del.sql create mode 100644 db/routines/vn/procedures/expeditionPallet_List.sql create mode 100644 db/routines/vn/procedures/expeditionPallet_View.sql create mode 100644 db/routines/vn/procedures/expeditionPallet_build.sql create mode 100644 db/routines/vn/procedures/expeditionPallet_printLabel.sql create mode 100644 db/routines/vn/procedures/expeditionScan_Add.sql create mode 100644 db/routines/vn/procedures/expeditionScan_Del.sql create mode 100644 db/routines/vn/procedures/expeditionScan_List.sql create mode 100644 db/routines/vn/procedures/expeditionScan_Put.sql create mode 100644 db/routines/vn/procedures/expeditionState_add.sql create mode 100644 db/routines/vn/procedures/expeditionState_addByAdress.sql create mode 100644 db/routines/vn/procedures/expeditionState_addByExpedition.sql create mode 100644 db/routines/vn/procedures/expeditionState_addByPallet.sql create mode 100644 db/routines/vn/procedures/expeditionState_addByRoute.sql create mode 100644 db/routines/vn/procedures/expeditionTruck_Add.sql create mode 100644 db/routines/vn/procedures/expeditionTruck_List.sql create mode 100644 db/routines/vn/procedures/expedition_StateGet.sql create mode 100644 db/routines/vn/procedures/expedition_getFromRoute.sql create mode 100644 db/routines/vn/procedures/expedition_getState.sql create mode 100644 db/routines/vn/procedures/freelance_getInfo.sql create mode 100644 db/routines/vn/procedures/fustControl.sql create mode 100644 db/routines/vn/procedures/fustControlDetail.sql create mode 100644 db/routines/vn/procedures/fv_pca.sql create mode 100644 db/routines/vn/procedures/getDayExpeditions.sql create mode 100644 db/routines/vn/procedures/getInfoDelivery.sql create mode 100644 db/routines/vn/procedures/getPedidosInternos.sql create mode 100644 db/routines/vn/procedures/greuge_add.sql create mode 100644 db/routines/vn/procedures/greuge_notifyEvents.sql create mode 100644 db/routines/vn/procedures/inventoryFailureAdd.sql create mode 100644 db/routines/vn/procedures/inventoryMake.sql create mode 100644 db/routines/vn/procedures/inventoryMakeLauncher.sql create mode 100644 db/routines/vn/procedures/inventory_repair.sql create mode 100644 db/routines/vn/procedures/invoiceExpenseMake.sql create mode 100644 db/routines/vn/procedures/invoiceFromAddress.sql create mode 100644 db/routines/vn/procedures/invoiceFromClient.sql create mode 100644 db/routines/vn/procedures/invoiceFromTicket.sql create mode 100644 db/routines/vn/procedures/invoiceInDueDay_calculate.sql create mode 100644 db/routines/vn/procedures/invoiceInDueDay_recalc.sql create mode 100644 db/routines/vn/procedures/invoiceInTaxMakeByDua.sql create mode 100644 db/routines/vn/procedures/invoiceInTax_afterUpsert.sql create mode 100644 db/routines/vn/procedures/invoiceInTax_getFromDua.sql create mode 100644 db/routines/vn/procedures/invoiceInTax_getFromEntries.sql create mode 100644 db/routines/vn/procedures/invoiceIn_booking.sql create mode 100644 db/routines/vn/procedures/invoiceOutAgain.sql create mode 100644 db/routines/vn/procedures/invoiceOutBooking.sql create mode 100644 db/routines/vn/procedures/invoiceOutBookingRange.sql create mode 100644 db/routines/vn/procedures/invoiceOutListByCompany.sql create mode 100644 db/routines/vn/procedures/invoiceOutTaxAndExpense.sql create mode 100644 db/routines/vn/procedures/invoiceOut_exportationFromClient.sql rename db/{.archive/232001/00-invoiceOut_new.sql => routines/vn/procedures/invoiceOut_new.sql} (90%) create mode 100644 db/routines/vn/procedures/invoiceOut_newFromClient.sql create mode 100644 db/routines/vn/procedures/invoiceOut_newFromTicket.sql create mode 100644 db/routines/vn/procedures/invoiceTaxMake.sql create mode 100644 db/routines/vn/procedures/itemBarcode_update.sql create mode 100644 db/routines/vn/procedures/itemFuentesBalance.sql create mode 100644 db/routines/vn/procedures/itemPlacementFromTicket.sql create mode 100644 db/routines/vn/procedures/itemPlacementSupplyAiming.sql create mode 100644 db/routines/vn/procedures/itemPlacementSupplyCloseOrder.sql create mode 100644 db/routines/vn/procedures/itemPlacementSupplyGetOrder.sql create mode 100644 db/routines/vn/procedures/itemPlacementSupplyStockGetTargetList.sql create mode 100644 db/routines/vn/procedures/itemProposal.sql create mode 100644 db/routines/vn/procedures/itemProposal_Add.sql create mode 100644 db/routines/vn/procedures/itemProposal_beta.sql create mode 100644 db/routines/vn/procedures/itemRefreshTags.sql create mode 100644 db/routines/vn/procedures/itemSale_byWeek.sql create mode 100644 db/routines/vn/procedures/itemSaveMin.sql create mode 100644 db/routines/vn/procedures/itemSearchShelving.sql create mode 100644 db/routines/vn/procedures/itemShelvingDelete.sql create mode 100644 db/routines/vn/procedures/itemShelvingLog_get.sql create mode 100644 db/routines/vn/procedures/itemShelvingMakeFromDate.sql create mode 100644 db/routines/vn/procedures/itemShelvingMatch.sql create mode 100644 db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql create mode 100644 db/routines/vn/procedures/itemShelvingProblem.sql create mode 100644 db/routines/vn/procedures/itemShelvingRadar.sql create mode 100644 db/routines/vn/procedures/itemShelvingRadar_Entry.sql create mode 100644 db/routines/vn/procedures/itemShelvingRadar_Entry_State_beta.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_Add.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_reserve.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql create mode 100644 db/routines/vn/procedures/itemShelvingSale_setQuantity.sql create mode 100644 db/routines/vn/procedures/itemShelvingTransfer.sql create mode 100644 db/routines/vn/procedures/itemShelving_add.sql create mode 100644 db/routines/vn/procedures/itemShelving_addByClaim.sql create mode 100644 db/routines/vn/procedures/itemShelving_addList.sql create mode 100644 db/routines/vn/procedures/itemShelving_filterBuyer.sql create mode 100644 db/routines/vn/procedures/itemShelving_get.sql create mode 100644 db/routines/vn/procedures/itemShelving_getAlternatives.sql create mode 100644 db/routines/vn/procedures/itemShelving_getInfo.sql create mode 100644 db/routines/vn/procedures/itemShelving_getSaleDate.sql create mode 100644 db/routines/vn/procedures/itemShelving_inventory.sql create mode 100644 db/routines/vn/procedures/itemShelving_selfConsumption.sql create mode 100644 db/routines/vn/procedures/itemShelving_update.sql create mode 100644 db/routines/vn/procedures/itemTagMake.sql create mode 100644 db/routines/vn/procedures/itemTagReorder.sql create mode 100644 db/routines/vn/procedures/itemTagReorderByName.sql create mode 100644 db/routines/vn/procedures/itemTag_replace.sql create mode 100644 db/routines/vn/procedures/itemTopSeller.sql rename db/{changes/234001/00-item_setVisibleDiscard.sql => routines/vn/procedures/itemTrash.sql} (67%) create mode 100644 db/routines/vn/procedures/itemUpdateTag.sql create mode 100644 db/routines/vn/procedures/item_GetVisible.sql create mode 100644 db/routines/vn/procedures/item_ValuateInventory.sql create mode 100644 db/routines/vn/procedures/item_cleanFloramondo.sql create mode 100644 db/routines/vn/procedures/item_comparative.sql create mode 100644 db/routines/vn/procedures/item_deactivateUnused.sql create mode 100644 db/routines/vn/procedures/item_getAtp.sql create mode 100644 db/routines/vn/procedures/item_getBalance.sql create mode 100644 db/routines/vn/procedures/item_getInfo.sql create mode 100644 db/routines/vn/procedures/item_getLack.sql create mode 100644 db/routines/vn/procedures/item_getMinETD.sql create mode 100644 db/routines/vn/procedures/item_getMinacum.sql create mode 100644 db/routines/vn/procedures/item_getSimilar.sql create mode 100644 db/routines/vn/procedures/item_getStock.sql create mode 100644 db/routines/vn/procedures/item_multipleBuy.sql create mode 100644 db/routines/vn/procedures/item_multipleBuyByDate.sql create mode 100644 db/routines/vn/procedures/item_refreshFromTags.sql create mode 100644 db/routines/vn/procedures/item_refreshTags.sql create mode 100644 db/routines/vn/procedures/item_saveReference.sql create mode 100644 db/routines/vn/procedures/item_setGeneric.sql rename db/{changes/234601/00-addressShortage.sql => routines/vn/procedures/item_setVisibleDiscard.sql} (65%) create mode 100644 db/routines/vn/procedures/item_updatePackingShelve.sql create mode 100644 db/routines/vn/procedures/item_updatePackingType.sql create mode 100644 db/routines/vn/procedures/item_zoneClosure.sql create mode 100644 db/routines/vn/procedures/ledger_doCompensation.sql create mode 100644 db/routines/vn/procedures/ledger_next.sql create mode 100644 db/routines/vn/procedures/logShow.sql create mode 100644 db/routines/vn/procedures/lungSize_generator.sql create mode 100644 db/routines/vn/procedures/machineWorker_add.sql create mode 100644 db/routines/vn/procedures/machineWorker_getHistorical.sql create mode 100644 db/routines/vn/procedures/machineWorker_update.sql create mode 100644 db/routines/vn/procedures/machine_getWorkerPlate.sql create mode 100644 db/routines/vn/procedures/mail_insert.sql create mode 100644 db/routines/vn/procedures/makeNewItem.sql create mode 100644 db/routines/vn/procedures/makePCSGraf.sql create mode 100644 db/routines/vn/procedures/manaSpellersRequery.sql create mode 100644 db/routines/vn/procedures/multipleInventory.sql create mode 100644 db/routines/vn/procedures/mysqlConnectionsSorter_kill.sql create mode 100644 db/routines/vn/procedures/mysqlPreparedCount_check.sql create mode 100644 db/routines/vn/procedures/nextShelvingCodeMake.sql create mode 100644 db/routines/vn/procedures/observationAdd.sql create mode 100644 db/routines/vn/procedures/orderCreate.sql create mode 100644 db/routines/vn/procedures/orderDelete.sql create mode 100644 db/routines/vn/procedures/orderListCreate.sql create mode 100644 db/routines/vn/procedures/orderListVolume.sql create mode 100644 db/routines/vn/procedures/packageInvoicing.sql create mode 100644 db/routines/vn/procedures/packingListPrinted.sql create mode 100644 db/routines/vn/procedures/packingListSwitch.sql rename db/{.archive/232601/00-packingSiteAdvanced.sql => routines/vn/procedures/packingSite_startCollection.sql} (60%) create mode 100644 db/routines/vn/procedures/parking_add.sql create mode 100644 db/routines/vn/procedures/parking_algemesi.sql create mode 100644 db/routines/vn/procedures/parking_new.sql create mode 100644 db/routines/vn/procedures/parking_setOrder.sql create mode 100644 db/routines/vn/procedures/prepareClientList.sql create mode 100644 db/routines/vn/procedures/prepareTicketList.sql create mode 100644 db/routines/vn/procedures/previousSticker_get.sql create mode 100644 db/routines/vn/procedures/printer_checkSector.sql create mode 100644 db/routines/vn/procedures/productionControl.sql create mode 100644 db/routines/vn/procedures/productionError_add.sql create mode 100644 db/routines/vn/procedures/productionError_addCheckerPackager.sql create mode 100644 db/routines/vn/procedures/productionSectorList.sql create mode 100644 db/routines/vn/procedures/rangeDateInfo.sql create mode 100644 db/routines/vn/procedures/rate_getPrices.sql create mode 100644 db/routines/vn/procedures/recipe_Cook.sql create mode 100644 db/routines/vn/procedures/recipe_Plaster.sql create mode 100644 db/routines/vn/procedures/reportLabelCollection_get.sql create mode 100644 db/routines/vn/procedures/report_print.sql create mode 100644 db/routines/vn/procedures/riskAllClients.sql create mode 100644 db/routines/vn/procedures/routeGuessPriority.sql create mode 100644 db/routines/vn/procedures/routeInfo.sql create mode 100644 db/routines/vn/procedures/routeMonitor_calculate.sql create mode 100644 db/routines/vn/procedures/routeSetOk.sql create mode 100644 db/routines/vn/procedures/routeUpdateM3.sql create mode 100644 db/routines/vn/procedures/route_calcCommission.sql create mode 100644 db/routines/vn/procedures/route_doRecalc.sql create mode 100644 db/routines/vn/procedures/route_getTickets.sql create mode 100644 db/routines/vn/procedures/route_updateM3.sql create mode 100644 db/routines/vn/procedures/saleBuy_Add.sql create mode 100644 db/routines/vn/procedures/saleGroup_add.sql create mode 100644 db/routines/vn/procedures/saleGroup_setParking.sql create mode 100644 db/routines/vn/procedures/saleMistake_Add.sql create mode 100644 db/routines/vn/procedures/salePreparingList.sql create mode 100644 db/routines/vn/procedures/saleSplit.sql create mode 100644 db/routines/vn/procedures/saleTracking_add.sql create mode 100644 db/routines/vn/procedures/saleTracking_addPreparedSaleGroup.sql create mode 100644 db/routines/vn/procedures/saleTracking_addPrevOK.sql create mode 100644 db/routines/vn/procedures/saleTracking_del.sql create mode 100644 db/routines/vn/procedures/saleTracking_new.sql create mode 100644 db/routines/vn/procedures/saleTracking_updateIsChecked.sql create mode 100644 db/routines/vn/procedures/sale_PriceFix.sql create mode 100644 db/routines/vn/procedures/sale_calculateComponent.sql create mode 100644 db/routines/vn/procedures/sale_checkNoComponents.sql create mode 100644 db/routines/vn/procedures/sale_getBoxPickingList.sql create mode 100644 db/routines/vn/procedures/sale_getFromTicketOrCollection.sql create mode 100644 db/routines/vn/procedures/sale_getProblems.sql create mode 100644 db/routines/vn/procedures/sale_getProblemsByTicket.sql create mode 100644 db/routines/vn/procedures/sale_recalcComponent.sql create mode 100644 db/routines/vn/procedures/sales_merge.sql create mode 100644 db/routines/vn/procedures/sales_mergeByCollection.sql create mode 100644 db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql create mode 100644 db/routines/vn/procedures/sectorCollection_get.sql create mode 100644 db/routines/vn/procedures/sectorCollection_getSale.sql create mode 100644 db/routines/vn/procedures/sectorCollection_new.sql create mode 100644 db/routines/vn/procedures/sectorProductivity_add.sql create mode 100644 db/routines/vn/procedures/sector_get.sql create mode 100644 db/routines/vn/procedures/sector_getWarehouse.sql create mode 100644 db/routines/vn/procedures/setParking.sql create mode 100644 db/routines/vn/procedures/shelvingChange.sql create mode 100644 db/routines/vn/procedures/shelvingLog_get.sql create mode 100644 db/routines/vn/procedures/shelvingParking_get.sql create mode 100644 db/routines/vn/procedures/shelvingPriority_update.sql create mode 100644 db/routines/vn/procedures/shelving_clean.sql create mode 100644 db/routines/vn/procedures/shelving_getSpam.sql create mode 100644 db/routines/vn/procedures/shelving_setParking.sql create mode 100644 db/routines/vn/procedures/sleep_X_min.sql create mode 100644 db/routines/vn/procedures/solunionRiskRequest.sql create mode 100644 db/routines/vn/procedures/stockBuyedByWorker.sql create mode 100644 db/routines/vn/procedures/stockBuyed_add.sql create mode 100644 db/routines/vn/procedures/stockTraslation.sql create mode 100644 db/routines/vn/procedures/subordinateGetList.sql create mode 100644 db/routines/vn/procedures/supplierExpenses.sql create mode 100644 db/routines/vn/procedures/supplierPackaging_ReportSource.sql create mode 100644 db/routines/vn/procedures/supplier_checkBalance.sql create mode 100644 db/routines/vn/procedures/supplier_checkIsActive.sql create mode 100644 db/routines/vn/procedures/supplier_disablePayMethodChecked.sql create mode 100644 db/routines/vn/procedures/test.sql create mode 100644 db/routines/vn/procedures/ticketBoxesView.sql create mode 100644 db/routines/vn/procedures/ticketBuiltTime.sql create mode 100644 db/routines/vn/procedures/ticketCalculateClon.sql create mode 100644 db/routines/vn/procedures/ticketCalculateFromType.sql create mode 100644 db/routines/vn/procedures/ticketCalculatePurge.sql create mode 100644 db/routines/vn/procedures/ticketClon.sql create mode 100644 db/routines/vn/procedures/ticketClon_OneYear.sql create mode 100644 db/routines/vn/procedures/ticketCollection_get.sql create mode 100644 db/routines/vn/procedures/ticketCollection_setUsedShelves.sql create mode 100644 db/routines/vn/procedures/ticketComponentUpdate.sql create mode 100644 db/routines/vn/procedures/ticketComponentUpdateSale.sql create mode 100644 db/routines/vn/procedures/ticketDown_PrintableSelection.sql create mode 100644 db/routines/vn/procedures/ticketGetTaxAdd.sql create mode 100644 db/routines/vn/procedures/ticketGetTax_new.sql create mode 100644 db/routines/vn/procedures/ticketGetTotal.sql create mode 100644 db/routines/vn/procedures/ticketGetVisibleAvailable.sql create mode 100644 db/routines/vn/procedures/ticketMissed_List.sql create mode 100644 db/routines/vn/procedures/ticketNotInvoicedByClient.sql create mode 100644 db/routines/vn/procedures/ticketObservation_addNewBorn.sql rename db/{.archive/231001/03-ticketPackaging_add.sql => routines/vn/procedures/ticketPackaging_add.sql} (98%) create mode 100644 db/routines/vn/procedures/ticketParking_findSkipped.sql create mode 100644 db/routines/vn/procedures/ticketRefund_beforeUpsert.sql create mode 100644 db/routines/vn/procedures/ticketRequest_Add.sql create mode 100644 db/routines/vn/procedures/ticketStateToday_setState.sql create mode 100644 db/routines/vn/procedures/ticketStateUpdate.sql create mode 100644 db/routines/vn/procedures/ticketToInvoiceByAddress.sql create mode 100644 db/routines/vn/procedures/ticketToInvoiceByDate.sql create mode 100644 db/routines/vn/procedures/ticketToInvoiceByRef.sql create mode 100644 db/routines/vn/procedures/ticket_Clone.sql create mode 100644 db/routines/vn/procedures/ticket_DelayTruck.sql create mode 100644 db/routines/vn/procedures/ticket_DelayTruckSplit.sql create mode 100644 db/routines/vn/procedures/ticket_WeightDeclaration.sql create mode 100644 db/routines/vn/procedures/ticket_add.sql create mode 100644 db/routines/vn/procedures/ticket_administrativeCopy.sql rename db/{changes/234801/00-ticket_canAdvance_update.sql => routines/vn/procedures/ticket_canAdvance.sql} (99%) rename db/{.archive/232201/00-procedurecanbePostponed.sql => routines/vn/procedures/ticket_canMerge.sql} (55%) rename db/{.archive/232202/00-procedurecanbePostponed.sql => routines/vn/procedures/ticket_canbePostponed.sql} (94%) create mode 100644 db/routines/vn/procedures/ticket_checkNoComponents.sql create mode 100644 db/routines/vn/procedures/ticket_cloneWeekly.sql create mode 100644 db/routines/vn/procedures/ticket_close.sql rename db/{.archive/224702/00-ticket_closeByTicket.sql => routines/vn/procedures/ticket_closeByTicket.sql} (58%) create mode 100644 db/routines/vn/procedures/ticket_componentMakeUpdate.sql create mode 100644 db/routines/vn/procedures/ticket_componentPreview.sql create mode 100644 db/routines/vn/procedures/ticket_doCmr.sql create mode 100644 db/routines/vn/procedures/ticket_doRecalc.sql create mode 100644 db/routines/vn/procedures/ticket_getFromFloramondo.sql create mode 100644 db/routines/vn/procedures/ticket_getMovable.sql create mode 100644 db/routines/vn/procedures/ticket_getProblems.sql create mode 100644 db/routines/vn/procedures/ticket_getSplitList.sql create mode 100644 db/routines/vn/procedures/ticket_getTax.sql rename db/{.archive/231201/00-ticket_getWarnings.sql => routines/vn/procedures/ticket_getWarnings.sql} (58%) create mode 100644 db/routines/vn/procedures/ticket_getWithParameters.sql create mode 100644 db/routines/vn/procedures/ticket_insertZone.sql create mode 100644 db/routines/vn/procedures/ticket_priceDifference.sql create mode 100644 db/routines/vn/procedures/ticket_printLabelPrevious.sql create mode 100644 db/routines/vn/procedures/ticket_recalc.sql create mode 100644 db/routines/vn/procedures/ticket_recalcComponents.sql create mode 100644 db/routines/vn/procedures/ticket_requestRecalc.sql create mode 100644 db/routines/vn/procedures/ticket_setNextState.sql create mode 100644 db/routines/vn/procedures/ticket_setParking.sql create mode 100644 db/routines/vn/procedures/ticket_setPreviousState.sql rename db/{changes/234601/00-ticketSetStateRefactor.sql => routines/vn/procedures/ticket_setState.sql} (96%) create mode 100644 db/routines/vn/procedures/ticket_split.sql create mode 100644 db/routines/vn/procedures/ticket_splitItemPackingType.sql create mode 100644 db/routines/vn/procedures/ticket_splitPackingComplete.sql rename db/{changes/234001/00-timeBusiness_calculate.sql => routines/vn/procedures/timeBusiness_calculate.sql} (99%) create mode 100644 db/routines/vn/procedures/timeBusiness_calculateAll.sql create mode 100644 db/routines/vn/procedures/timeBusiness_calculateByDepartment.sql create mode 100644 db/routines/vn/procedures/timeBusiness_calculateByUser.sql create mode 100644 db/routines/vn/procedures/timeBusiness_calculateByWorker.sql rename db/{changes/234004/01-timeControl_calculate.sql => routines/vn/procedures/timeControl_calculate.sql} (82%) create mode 100644 db/routines/vn/procedures/timeControl_calculateAll.sql create mode 100644 db/routines/vn/procedures/timeControl_calculateByDepartment.sql create mode 100644 db/routines/vn/procedures/timeControl_calculateByUser.sql create mode 100644 db/routines/vn/procedures/timeControl_calculateByWorker.sql create mode 100644 db/routines/vn/procedures/timeControl_getError.sql create mode 100644 db/routines/vn/procedures/timeWorkerControl_check.sql create mode 100644 db/routines/vn/procedures/tpvTransaction_checkStatus.sql create mode 100644 db/routines/vn/procedures/travelVolume.sql create mode 100644 db/routines/vn/procedures/travelVolume_get.sql create mode 100644 db/routines/vn/procedures/travel_checkDates.sql create mode 100644 db/routines/vn/procedures/travel_checkPackaging.sql create mode 100644 db/routines/vn/procedures/travel_checkWarehouseIsFeedStock.sql create mode 100644 db/routines/vn/procedures/travel_clone.sql create mode 100644 db/routines/vn/procedures/travel_cloneWithEntries.sql create mode 100644 db/routines/vn/procedures/travel_doRecalc.sql create mode 100644 db/routines/vn/procedures/travel_getEntriesMissingPackage.sql create mode 100644 db/routines/vn/procedures/travel_moveRaids.sql create mode 100644 db/routines/vn/procedures/travel_requestRecalc.sql create mode 100644 db/routines/vn/procedures/travel_upcomingArrivals.sql create mode 100644 db/routines/vn/procedures/travel_updatePacking.sql create mode 100644 db/routines/vn/procedures/travel_weeklyClone.sql create mode 100644 db/routines/vn/procedures/typeTagMake.sql create mode 100644 db/routines/vn/procedures/updatePedidosInternos.sql create mode 100644 db/routines/vn/procedures/vehicle_checkNumberPlate.sql create mode 100644 db/routines/vn/procedures/vehicle_notifyEvents.sql create mode 100644 db/routines/vn/procedures/visible_getMisfit.sql create mode 100644 db/routines/vn/procedures/warehouseFitting.sql create mode 100644 db/routines/vn/procedures/warehouseFitting_byTravel.sql create mode 100644 db/routines/vn/procedures/workerCalculateBoss.sql create mode 100644 db/routines/vn/procedures/workerCalendar_calculateBusiness.sql create mode 100644 db/routines/vn/procedures/workerCalendar_calculateYear.sql create mode 100644 db/routines/vn/procedures/workerCreateExternal.sql create mode 100644 db/routines/vn/procedures/workerDepartmentByDate.sql create mode 100644 db/routines/vn/procedures/workerDisable.sql create mode 100644 db/routines/vn/procedures/workerDisableAll.sql create mode 100644 db/routines/vn/procedures/workerForAllCalculateBoss.sql create mode 100644 db/routines/vn/procedures/workerJourney_replace.sql create mode 100644 db/routines/vn/procedures/workerMistakeType_get.sql create mode 100644 db/routines/vn/procedures/workerMistake_add.sql create mode 100644 db/routines/vn/procedures/workerTimeControlAdd.sql create mode 100644 db/routines/vn/procedures/workerTimeControlPinGenerate.sql create mode 100644 db/routines/vn/procedures/workerTimeControlSOWP.sql create mode 100644 db/routines/vn/procedures/workerTimeControlSetOrder.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_add.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_calculateOddDays.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_check.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_checkBreak.sql rename db/{changes/234004/02-workerTimeControl_clockIn.sql => routines/vn/procedures/workerTimeControl_clockIn.sql} (99%) create mode 100644 db/routines/vn/procedures/workerTimeControl_direction.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_getClockIn.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_login.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_remove.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_repair.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_sendMailByDepartment.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_sendMailByDepartmentLauncher.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_setOrder.sql create mode 100644 db/routines/vn/procedures/workerTimeControl_weekCheckBreak.sql create mode 100644 db/routines/vn/procedures/workerWeekControl.sql create mode 100644 db/routines/vn/procedures/worker_getFromHasMistake.sql create mode 100644 db/routines/vn/procedures/worker_getHierarchy.sql create mode 100644 db/routines/vn/procedures/worker_getSector.sql create mode 100644 db/routines/vn/procedures/worker_updateBalance.sql create mode 100644 db/routines/vn/procedures/worker_updateBusiness.sql create mode 100644 db/routines/vn/procedures/worker_updateChangedBusiness.sql create mode 100644 db/routines/vn/procedures/workingHours.sql create mode 100644 db/routines/vn/procedures/workingHoursTimeIn.sql create mode 100644 db/routines/vn/procedures/workingHoursTimeOut.sql create mode 100644 db/routines/vn/procedures/wrongEqualizatedClient.sql create mode 100644 db/routines/vn/procedures/zoneClosure_recalc.sql create mode 100644 db/routines/vn/procedures/zoneGeo_calcTree.sql create mode 100644 db/routines/vn/procedures/zoneGeo_calcTreeRec.sql create mode 100644 db/routines/vn/procedures/zoneGeo_checkName.sql create mode 100644 db/routines/vn/procedures/zoneGeo_delete.sql create mode 100644 db/routines/vn/procedures/zoneGeo_doCalc.sql create mode 100644 db/routines/vn/procedures/zoneGeo_setParent.sql create mode 100644 db/routines/vn/procedures/zoneGeo_throwNotEditable.sql create mode 100644 db/routines/vn/procedures/zone_excludeFromGeo.sql create mode 100644 db/routines/vn/procedures/zone_getAddresses.sql create mode 100644 db/routines/vn/procedures/zone_getAgency.sql create mode 100644 db/routines/vn/procedures/zone_getAvailable.sql create mode 100644 db/routines/vn/procedures/zone_getClosed.sql create mode 100644 db/routines/vn/procedures/zone_getCollisions.sql create mode 100644 db/routines/vn/procedures/zone_getEvents.sql create mode 100644 db/routines/vn/procedures/zone_getFromGeo.sql create mode 100644 db/routines/vn/procedures/zone_getLanded.sql create mode 100644 db/routines/vn/procedures/zone_getLeaves.sql create mode 100644 db/routines/vn/procedures/zone_getOptionsForLanding.sql create mode 100644 db/routines/vn/procedures/zone_getOptionsForShipment.sql create mode 100644 db/routines/vn/procedures/zone_getPostalCode.sql create mode 100644 db/routines/vn/procedures/zone_getShipped.sql create mode 100644 db/routines/vn/procedures/zone_getState.sql create mode 100644 db/routines/vn/procedures/zone_getWarehouse.sql create mode 100644 db/routines/vn/procedures/zone_upcomingDeliveries.sql create mode 100644 db/routines/vn/triggers/BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/XDiario_beforeInsert.sql rename db/{.archive/230201/00-triggersXDiario.sql => routines/vn/triggers/XDiario_beforeUpdate.sql} (54%) create mode 100644 db/routines/vn/triggers/address_afterDelete.sql create mode 100644 db/routines/vn/triggers/address_afterInsert.sql create mode 100644 db/routines/vn/triggers/address_afterUpdate.sql create mode 100644 db/routines/vn/triggers/address_beforeInsert.sql create mode 100644 db/routines/vn/triggers/address_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/agency_afterInsert.sql create mode 100644 db/routines/vn/triggers/autonomy_AD.sql create mode 100644 db/routines/vn/triggers/autonomy_BI.sql create mode 100644 db/routines/vn/triggers/autonomy_BU.sql create mode 100644 db/routines/vn/triggers/awb_bi.sql create mode 100644 db/routines/vn/triggers/bankEntity_beforeInsert.sql create mode 100644 db/routines/vn/triggers/bankEntity_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/budgetNotes_BeforeInsert.sql create mode 100644 db/routines/vn/triggers/business_afterDelete.sql create mode 100644 db/routines/vn/triggers/business_afterInsert.sql create mode 100644 db/routines/vn/triggers/business_afterUpdate.sql create mode 100644 db/routines/vn/triggers/business_beforeInsert.sql create mode 100644 db/routines/vn/triggers/business_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/buy_afterDelete.sql create mode 100644 db/routines/vn/triggers/buy_afterInsert.sql rename db/{changes/234201/02-packagingFktrigger.sql => routines/vn/triggers/buy_afterUpdate.sql} (99%) create mode 100644 db/routines/vn/triggers/buy_beforeDelete.sql create mode 100644 db/routines/vn/triggers/buy_beforeInsert.sql create mode 100644 db/routines/vn/triggers/buy_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claimBeginning_afterDelete.sql create mode 100644 db/routines/vn/triggers/claimBeginning_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claimBeginning_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claimDevelopment_afterDelete.sql create mode 100644 db/routines/vn/triggers/claimDevelopment_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claimDevelopment_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claimDms_afterDelete.sql create mode 100644 db/routines/vn/triggers/claimDms_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claimDms_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claimEnd_afterDelete.sql create mode 100644 db/routines/vn/triggers/claimEnd_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claimEnd_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claimObservation_afterDelete.sql create mode 100644 db/routines/vn/triggers/claimObservation_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claimObservation_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claimState_afterDelete.sql create mode 100644 db/routines/vn/triggers/claimState_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claimState_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/claim_afterDelete.sql create mode 100644 db/routines/vn/triggers/claim_beforeInsert.sql create mode 100644 db/routines/vn/triggers/claim_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/clientContact_afterDelete.sql create mode 100644 db/routines/vn/triggers/clientContact_beforeInsert.sql create mode 100644 db/routines/vn/triggers/clientCredit_AfterInsert.sql create mode 100644 db/routines/vn/triggers/clientDms_afterDelete.sql create mode 100644 db/routines/vn/triggers/clientDms_beforeInsert.sql create mode 100644 db/routines/vn/triggers/clientDms_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/clientObservation_afterDelete.sql create mode 100644 db/routines/vn/triggers/clientObservation_beforeInsert.sql create mode 100644 db/routines/vn/triggers/clientObservation_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/clientSample_afterDelete.sql create mode 100644 db/routines/vn/triggers/clientSample_beforeInsert.sql create mode 100644 db/routines/vn/triggers/clientSample_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/client_AfterInsert.sql create mode 100644 db/routines/vn/triggers/client_afterDelete.sql create mode 100644 db/routines/vn/triggers/client_afterUpdate.sql create mode 100644 db/routines/vn/triggers/client_beforeInsert.sql rename db/{.archive/231401/00-clientBeforeUpdate.sql => routines/vn/triggers/client_beforeUpdate.sql} (73%) create mode 100644 db/routines/vn/triggers/cmr_beforeDelete.sql create mode 100644 db/routines/vn/triggers/collectionColors_beforeInsert.sql create mode 100644 db/routines/vn/triggers/collectionColors_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/collectionVolumetry_afterDelete.sql create mode 100644 db/routines/vn/triggers/collectionVolumetry_afterInsert.sql create mode 100644 db/routines/vn/triggers/collectionVolumetry_afterUpdate.sql create mode 100644 db/routines/vn/triggers/collection_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/country_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/country_afterDelete.sql create mode 100644 db/routines/vn/triggers/country_afterUpdate.sql create mode 100644 db/routines/vn/triggers/country_beforeInsert.sql create mode 100644 db/routines/vn/triggers/country_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/creditClassification_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/creditInsurance_afterInsert.sql create mode 100644 db/routines/vn/triggers/creditInsurance_beforeInsert.sql create mode 100644 db/routines/vn/triggers/department_afterDelete.sql create mode 100644 db/routines/vn/triggers/department_afterUpdate.sql create mode 100644 db/routines/vn/triggers/department_beforeDelete.sql create mode 100644 db/routines/vn/triggers/department_beforeInsert.sql create mode 100644 db/routines/vn/triggers/deviceProductionConfig_afterUpdate.sql create mode 100644 db/routines/vn/triggers/deviceProductionModels_beforeInsert.sql create mode 100644 db/routines/vn/triggers/deviceProductionModels_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/deviceProductionState_beforeInsert.sql create mode 100644 db/routines/vn/triggers/deviceProductionState_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/deviceProductionUser_afterDelete.sql create mode 100644 db/routines/vn/triggers/deviceProductionUser_beforeInsert.sql create mode 100644 db/routines/vn/triggers/deviceProductionUser_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/deviceProduction_afterDelete.sql create mode 100644 db/routines/vn/triggers/deviceProduction_beforeInsert.sql create mode 100644 db/routines/vn/triggers/deviceProduction_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/dms_beforeDelete.sql create mode 100644 db/routines/vn/triggers/dms_beforeInsert.sql create mode 100644 db/routines/vn/triggers/dms_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/ektEntryAssign_afterInsert.sql create mode 100644 db/routines/vn/triggers/ektEntryAssign_afterUpdate.sql create mode 100644 db/routines/vn/triggers/entryObservation_afterDelete.sql create mode 100644 db/routines/vn/triggers/entryObservation_beforeInsert.sql create mode 100644 db/routines/vn/triggers/entryObservation_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/entry_afterDelete.sql create mode 100644 db/routines/vn/triggers/entry_afterInsert.sql create mode 100644 db/routines/vn/triggers/entry_afterUpdate.sql create mode 100644 db/routines/vn/triggers/entry_beforeDelete.sql create mode 100644 db/routines/vn/triggers/entry_beforeInsert.sql create mode 100644 db/routines/vn/triggers/entry_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/expeditionState_AfterInsert.sql rename db/{changes/234601/00-expeditionStateBeforeInsert.sql => routines/vn/triggers/expeditionState_BeforeInsert.sql} (97%) create mode 100644 db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/expedition_afterDelete.sql create mode 100644 db/routines/vn/triggers/expedition_beforeDelete.sql create mode 100644 db/routines/vn/triggers/expedition_beforeInsert.sql create mode 100644 db/routines/vn/triggers/expedition_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/gregue_beforeInsert.sql create mode 100644 db/routines/vn/triggers/greuge_afterDelete.sql create mode 100644 db/routines/vn/triggers/greuge_beforeInsert.sql create mode 100644 db/routines/vn/triggers/greuge_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/host_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/invoiceInDueDay_afterDelete.sql create mode 100644 db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql create mode 100644 db/routines/vn/triggers/invoiceInDueDay_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/invoiceInTax_afterDelete.sql create mode 100644 db/routines/vn/triggers/invoiceInTax_beforeInsert.sql create mode 100644 db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/invoiceIn_afterDelete.sql create mode 100644 db/routines/vn/triggers/invoiceIn_au.sql create mode 100644 db/routines/vn/triggers/invoiceIn_bi.sql create mode 100644 db/routines/vn/triggers/invoiceIn_bu.sql rename db/{.archive/231401/00-invoiceOutAfterInsert.sql => routines/vn/triggers/invoiceOut_afterInsert.sql} (51%) create mode 100644 db/routines/vn/triggers/invoiceOut_beforeDelete.sql create mode 100644 db/routines/vn/triggers/invoiceOut_beforeInsert.sql create mode 100644 db/routines/vn/triggers/invoiceOut_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/itemBarcode_afterDelete.sql create mode 100644 db/routines/vn/triggers/itemBarcode_beforeInsert.sql create mode 100644 db/routines/vn/triggers/itemBarcode_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/itemBotanical_afterDelete.sql create mode 100644 db/routines/vn/triggers/itemBotanical_beforeInsert.sql create mode 100644 db/routines/vn/triggers/itemBotanical_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/itemCost_beforeInsert.sql create mode 100644 db/routines/vn/triggers/itemCost_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql create mode 100644 db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql create mode 100644 db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/itemTag_afterDelete.sql create mode 100644 db/routines/vn/triggers/itemTag_afterInsert.sql create mode 100644 db/routines/vn/triggers/itemTag_afterUpdate.sql create mode 100644 db/routines/vn/triggers/itemTag_beforeInsert.sql create mode 100644 db/routines/vn/triggers/itemTag_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/itemTaxCountry_afterDelete.sql create mode 100644 db/routines/vn/triggers/itemTaxCountry_beforeInsert.sql create mode 100644 db/routines/vn/triggers/itemTaxCountry_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/itemType_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/item_afterDelete.sql create mode 100644 db/routines/vn/triggers/item_afterInsert.sql create mode 100644 db/routines/vn/triggers/item_afterUpdate.sql create mode 100644 db/routines/vn/triggers/item_beforeInsert.sql create mode 100644 db/routines/vn/triggers/item_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/machine_BI.sql create mode 100644 db/routines/vn/triggers/mail_beforeInsert.sql create mode 100644 db/routines/vn/triggers/mandate_beforeInsert.sql create mode 100644 db/routines/vn/triggers/operator_beforeInsert.sql create mode 100644 db/routines/vn/triggers/operator_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/packaging_beforeInsert.sql create mode 100644 db/routines/vn/triggers/packaging_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/packingSite_afterDelete.sql create mode 100644 db/routines/vn/triggers/packingSite_beforeInsert.sql create mode 100644 db/routines/vn/triggers/packingSite_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/parking_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/parking_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/payment_afterInsert.sql create mode 100644 db/routines/vn/triggers/payment_beforeInsert.sql create mode 100644 db/routines/vn/triggers/payment_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/postCode_afterDelete.sql create mode 100644 db/routines/vn/triggers/postCode_afterUpdate.sql create mode 100644 db/routines/vn/triggers/postCode_beforeInsert.sql create mode 100644 db/routines/vn/triggers/postCode_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/priceFixed_beforeInsert.sql create mode 100644 db/routines/vn/triggers/priceFixed_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/projectNotes_BeforeInsert.sql create mode 100644 db/routines/vn/triggers/province_afterDelete.sql create mode 100644 db/routines/vn/triggers/province_afterUpdate.sql create mode 100644 db/routines/vn/triggers/province_beforeInsert.sql create mode 100644 db/routines/vn/triggers/province_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/rate_afterDelete.sql create mode 100644 db/routines/vn/triggers/rate_beforeInsert.sql create mode 100644 db/routines/vn/triggers/rate_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/receipt_afterInsert.sql create mode 100644 db/routines/vn/triggers/receipt_afterUpdate.sql create mode 100644 db/routines/vn/triggers/receipt_beforeDelete.sql create mode 100644 db/routines/vn/triggers/receipt_beforeInsert.sql create mode 100644 db/routines/vn/triggers/receipt_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/recovery_afterDelete.sql create mode 100644 db/routines/vn/triggers/recovery_beforeInsert.sql create mode 100644 db/routines/vn/triggers/recovery_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/route_afterDelete.sql create mode 100644 db/routines/vn/triggers/route_afterInsert.sql create mode 100644 db/routines/vn/triggers/route_afterUpdate.sql create mode 100644 db/routines/vn/triggers/route_beforeInsert.sql create mode 100644 db/routines/vn/triggers/route_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/routesMonitor_afterDelete.sql create mode 100644 db/routines/vn/triggers/routesMonitor_beforeInsert.sql create mode 100644 db/routines/vn/triggers/routesMonitor_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/saleBuy_AI.sql create mode 100644 db/routines/vn/triggers/saleTracking_After_Insert.sql create mode 100644 db/routines/vn/triggers/sale_BEFORE_DELETE.sql create mode 100644 db/routines/vn/triggers/sale_afterDelete.sql create mode 100644 db/routines/vn/triggers/sale_afterInsert.sql rename db/{.archive/224701/00-sale_afterUpdate.sql => routines/vn/triggers/sale_afterUpdate.sql} (83%) create mode 100644 db/routines/vn/triggers/sale_beforeInsert.sql create mode 100644 db/routines/vn/triggers/sale_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/sharingCart_beforeDelete.sql create mode 100644 db/routines/vn/triggers/sharingCart_beforeInsert.sql create mode 100644 db/routines/vn/triggers/sharingCart_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/sharingClient_beforeInsert.sql create mode 100644 db/routines/vn/triggers/sharingClient_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/shelving_afterDelete.sql create mode 100644 db/routines/vn/triggers/shelving_beforeInsert.sql create mode 100644 db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql create mode 100644 db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql create mode 100644 db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql create mode 100644 db/routines/vn/triggers/specie_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/specie_BEFORE_UPDATE.sql create mode 100644 db/routines/vn/triggers/supplierAccount_afterDelete.sql create mode 100644 db/routines/vn/triggers/supplierAccount_beforeInsert.sql create mode 100644 db/routines/vn/triggers/supplierAccount_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/supplierAddress_afterDelete.sql create mode 100644 db/routines/vn/triggers/supplierAddress_beforeInsert.sql create mode 100644 db/routines/vn/triggers/supplierAddress_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/supplierContact_afterDelete.sql create mode 100644 db/routines/vn/triggers/supplierContact_beforeInsert.sql create mode 100644 db/routines/vn/triggers/supplierContact_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/supplier_afterDelete.sql create mode 100644 db/routines/vn/triggers/supplier_beforeInsert.sql rename db/{.archive/225201/00-supplier_beforeUpdate.sql => routines/vn/triggers/supplier_beforeUpdate.sql} (88%) create mode 100644 db/routines/vn/triggers/tag_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/ticketCollection_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketDms_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketDms_beforeDelete.sql create mode 100644 db/routines/vn/triggers/ticketDms_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketDms_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketObservation_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketObservation_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketObservation_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/ticketPackaging_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketPackaging_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql create mode 100644 db/routines/vn/triggers/ticketRefund_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketRefund_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketRefund_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketRequest_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketRequest_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketRequest_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketService_ad.sql create mode 100644 db/routines/vn/triggers/ticketService_ai.sql create mode 100644 db/routines/vn/triggers/ticketService_au.sql create mode 100644 db/routines/vn/triggers/ticketService_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketService_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketTracking_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketTracking_afterInsert.sql create mode 100644 db/routines/vn/triggers/ticketTracking_afterUpdate.sql create mode 100644 db/routines/vn/triggers/ticketTracking_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketTracking_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticketWeekly_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticketWeekly_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticketWeekly_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/ticket_afterDelete.sql create mode 100644 db/routines/vn/triggers/ticket_afterInsert.sql create mode 100644 db/routines/vn/triggers/ticket_afterUpdate.sql create mode 100644 db/routines/vn/triggers/ticket_beforeDelete.sql create mode 100644 db/routines/vn/triggers/ticket_beforeInsert.sql create mode 100644 db/routines/vn/triggers/ticket_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/time_AFTER_UPDATE.sql create mode 100644 db/routines/vn/triggers/town_afterDelete.sql create mode 100644 db/routines/vn/triggers/town_afterUpdate.sql create mode 100644 db/routines/vn/triggers/town_beforeInsert.sql create mode 100644 db/routines/vn/triggers/town_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/travelThermograph_afterDelete.sql create mode 100644 db/routines/vn/triggers/travelThermograph_beforeInsert.sql create mode 100644 db/routines/vn/triggers/travelThermograph_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/travel_afterDelete.sql create mode 100644 db/routines/vn/triggers/travel_afterUpdate.sql create mode 100644 db/routines/vn/triggers/travel_beforeInsert.sql create mode 100644 db/routines/vn/triggers/travel_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/vehicle_beforeInsert.sql create mode 100644 db/routines/vn/triggers/vehicle_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/warehouse_afterInsert.sql create mode 100644 db/routines/vn/triggers/warehouse_afterUpdate.sql create mode 100644 db/routines/vn/triggers/workerDocument_afterDelete.sql create mode 100644 db/routines/vn/triggers/workerDocument_beforeInsert.sql create mode 100644 db/routines/vn/triggers/workerDocument_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/workerIncome_afterDelete.sql create mode 100644 db/routines/vn/triggers/workerIncome_afterInsert.sql create mode 100644 db/routines/vn/triggers/workerIncome_afterUpdate.sql create mode 100644 db/routines/vn/triggers/workerTimeControl_AI.sql create mode 100644 db/routines/vn/triggers/worker_afterDelete.sql create mode 100644 db/routines/vn/triggers/worker_beforeInsert.sql create mode 100644 db/routines/vn/triggers/worker_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/workingHoursBeforeInsert.sql create mode 100644 db/routines/vn/triggers/zoneEvent_afterDelete.sql create mode 100644 db/routines/vn/triggers/zoneEvent_beforeInsert.sql create mode 100644 db/routines/vn/triggers/zoneEvent_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/zoneExclusion_BI.sql create mode 100644 db/routines/vn/triggers/zoneExclusion_BU.sql create mode 100644 db/routines/vn/triggers/zoneExclusion_afterDelete.sql create mode 100644 db/routines/vn/triggers/zoneGeo_beforeInsert.sql create mode 100644 db/routines/vn/triggers/zoneGeo_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/zoneIncluded_afterDelete.sql create mode 100644 db/routines/vn/triggers/zoneIncluded_beforeInsert.sql create mode 100644 db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/zoneWarehouse_afterDelete.sql create mode 100644 db/routines/vn/triggers/zoneWarehouse_beforeInsert.sql create mode 100644 db/routines/vn/triggers/zoneWarehouse_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/zone_afterDelete.sql create mode 100644 db/routines/vn/triggers/zone_beforeInsert.sql create mode 100644 db/routines/vn/triggers/zone_beforeUpdate.sql create mode 100644 db/routines/vn/views/NewView.sql create mode 100644 db/routines/vn/views/__coolerPathDetail.sql create mode 100644 db/routines/vn/views/agencyTerm.sql create mode 100644 db/routines/vn/views/agencyWarehouse.sql create mode 100644 db/routines/vn/views/annualAverageInvoiced.sql create mode 100644 db/routines/vn/views/awbVolume.sql create mode 100644 db/routines/vn/views/bank.sql create mode 100644 db/routines/vn/views/bankPolicy.sql create mode 100644 db/routines/vn/views/businessCalendar.sql create mode 100644 db/routines/vn/views/buyer.sql create mode 100644 db/routines/vn/views/buyerSales.sql create mode 100644 db/routines/vn/views/clientDefaultCompany.sql create mode 100644 db/routines/vn/views/clientLost.sql create mode 100644 db/routines/vn/views/clientPhoneBook.sql create mode 100644 db/routines/vn/views/companyL10n.sql create mode 100644 db/routines/vn/views/coolerPath.sql create mode 100644 db/routines/vn/views/defaulter.sql create mode 100644 db/routines/vn/views/departmentTree.sql create mode 100644 db/routines/vn/views/doc.sql create mode 100644 db/routines/vn/views/ediGenus.sql create mode 100644 db/routines/vn/views/ediSpecie.sql create mode 100644 db/routines/vn/views/ektSubAddress.sql create mode 100644 db/routines/vn/views/especialPrice.sql create mode 100644 db/routines/vn/views/exchangeInsurance.sql create mode 100644 db/routines/vn/views/exchangeInsuranceEntry.sql create mode 100644 db/routines/vn/views/exchangeInsuranceIn.sql create mode 100644 db/routines/vn/views/exchangeInsuranceInPrevious.sql create mode 100644 db/routines/vn/views/exchangeInsuranceOut.sql create mode 100644 db/routines/vn/views/exchangeReportSource.sql create mode 100644 db/routines/vn/views/exchangeReportSourcePrevious.sql create mode 100644 db/routines/vn/views/expeditionCommon.sql create mode 100644 db/routines/vn/views/expeditionPallet_Print.sql create mode 100644 db/routines/vn/views/expeditionRoute_Monitor.sql create mode 100644 db/routines/vn/views/expeditionRoute_freeTickets.sql create mode 100644 db/routines/vn/views/expeditionScan_Monitor.sql create mode 100644 db/routines/vn/views/expeditionSticker.sql create mode 100644 db/routines/vn/views/expeditionTicket_NoBoxes.sql create mode 100644 db/routines/vn/views/expeditionTimeExpended.sql create mode 100644 db/routines/vn/views/expeditionTruck_Control.sql create mode 100644 db/routines/vn/views/expeditionTruck_Control_Detail.sql create mode 100644 db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql create mode 100644 db/routines/vn/views/firstTicketShipped.sql create mode 100644 db/routines/vn/views/floraHollandBuyedItems.sql create mode 100644 db/routines/vn/views/grantGroup.sql create mode 100644 db/routines/vn/views/inkL10n.sql create mode 100644 db/routines/vn/views/invoiceCorrectionDataSource.sql create mode 100644 db/routines/vn/views/itemBotanicalWithGenus.sql create mode 100644 db/routines/vn/views/itemCategoryL10n.sql create mode 100644 db/routines/vn/views/itemColor.sql create mode 100644 db/routines/vn/views/itemEntryIn.sql create mode 100644 db/routines/vn/views/itemEntryOut.sql create mode 100644 db/routines/vn/views/itemInk.sql create mode 100644 db/routines/vn/views/itemPlacementSupplyList.sql create mode 100644 db/routines/vn/views/itemProductor.sql create mode 100644 db/routines/vn/views/itemSearch.sql create mode 100644 db/routines/vn/views/itemShelvingAvailable.sql create mode 100644 db/routines/vn/views/itemShelvingList.sql create mode 100644 db/routines/vn/views/itemShelvingPlacementSupplyStock.sql create mode 100644 db/routines/vn/views/itemShelvingSaleSum.sql create mode 100644 db/routines/vn/views/itemShelvingStock.sql create mode 100644 db/routines/vn/views/itemShelvingStockFull.sql create mode 100644 db/routines/vn/views/itemShelvingStockRemoved.sql create mode 100644 db/routines/vn/views/itemTagged.sql create mode 100644 db/routines/vn/views/itemTaxCountrySpain.sql create mode 100644 db/routines/vn/views/itemTicketOut.sql create mode 100644 db/routines/vn/views/itemTypeL10n.sql create mode 100644 db/routines/vn/views/item_Free_Id.sql create mode 100644 db/routines/vn/views/labelInfo.sql create mode 100644 db/routines/vn/views/lastHourProduction.sql create mode 100644 db/routines/vn/views/lastPurchases.sql create mode 100644 db/routines/vn/views/lastTopClaims.sql create mode 100644 db/routines/vn/views/mistake.sql create mode 100644 db/routines/vn/views/mistakeRatio.sql create mode 100644 db/routines/vn/views/newBornSales.sql create mode 100644 db/routines/vn/views/operatorWorkerCode.sql create mode 100644 db/routines/vn/views/originL10n.sql create mode 100644 db/routines/vn/views/packageEquivalentItem.sql create mode 100644 db/routines/vn/views/paymentExchangeInsurance.sql create mode 100644 db/routines/vn/views/payrollCenter.sql create mode 100644 db/routines/vn/views/personMedia.sql create mode 100644 db/routines/vn/views/phoneBook.sql create mode 100644 db/routines/vn/views/preparationException.sql create mode 100644 db/routines/vn/views/productionVolume.sql create mode 100644 db/routines/vn/views/productionVolume_LastHour.sql create mode 100644 db/routines/vn/views/promissoryNote.sql create mode 100644 db/routines/vn/views/role.sql create mode 100644 db/routines/vn/views/routesControl.sql create mode 100644 db/routines/vn/views/saleCost.sql create mode 100644 db/routines/vn/views/saleLabel.sql create mode 100644 db/routines/vn/views/saleMistakeList.sql create mode 100644 db/routines/vn/views/saleMistake_list__2.sql create mode 100644 db/routines/vn/views/saleSaleTracking.sql create mode 100644 db/routines/vn/views/saleValue.sql create mode 100644 db/routines/vn/views/saleVolume.sql create mode 100644 db/routines/vn/views/saleVolume_Today_VNH.sql create mode 100644 db/routines/vn/views/sale_freightComponent.sql create mode 100644 db/routines/vn/views/salesPersonSince.sql create mode 100644 db/routines/vn/views/salesPreparedLastHour.sql create mode 100644 db/routines/vn/views/salesPreviousPreparated.sql create mode 100644 db/routines/vn/views/supplierPackaging.sql create mode 100644 db/routines/vn/views/tagL10n.sql create mode 100644 db/routines/vn/views/ticketDownBuffer.sql create mode 100644 db/routines/vn/views/ticketLastUpdated.sql create mode 100644 db/routines/vn/views/ticketLastUpdatedList.sql create mode 100644 db/routines/vn/views/ticketMRW.sql create mode 100644 db/routines/vn/views/ticketNotInvoiced.sql create mode 100644 db/routines/vn/views/ticketPackingList.sql create mode 100644 db/routines/vn/views/ticketPreviousPreparingList.sql create mode 100644 db/routines/vn/views/ticketState.sql create mode 100644 db/routines/vn/views/ticketStateToday.sql create mode 100644 db/routines/vn/views/ticketToPrepare.sql create mode 100644 db/routines/vn/views/ticketeToPreparePrepared.sql create mode 100644 db/routines/vn/views/tr2.sql create mode 100644 db/routines/vn/views/traceabilityBuy.sql create mode 100644 db/routines/vn/views/traceabilitySale.sql create mode 100644 db/routines/vn/views/unary.sql create mode 100644 db/routines/vn/views/unaryScan.sql create mode 100644 db/routines/vn/views/unaryScanLine.sql create mode 100644 db/routines/vn/views/unaryScanLineBuy.sql create mode 100644 db/routines/vn/views/unaryScanLineExpedition.sql create mode 100644 db/routines/vn/views/warehouseJoined.sql create mode 100644 db/routines/vn/views/workerBusinessDated.sql create mode 100644 db/routines/vn/views/workerDepartment.sql create mode 100644 db/routines/vn/views/workerLabour.sql create mode 100644 db/routines/vn/views/workerMedia.sql create mode 100644 db/routines/vn/views/workerSpeedExpedition.sql create mode 100644 db/routines/vn/views/workerSpeedSaleTracking.sql create mode 100644 db/routines/vn/views/workerTeamCollegues.sql create mode 100644 db/routines/vn/views/workerTimeControlUserInfo.sql create mode 100644 db/routines/vn/views/workerTimeJourneyNG.sql create mode 100644 db/routines/vn/views/workerWithoutTractor.sql create mode 100644 db/routines/vn/views/zoneEstimatedDelivery.sql create mode 100644 db/routines/vn2008/events/raidUpdate.sql create mode 100644 db/routines/vn2008/functions/cc_to_iban.sql create mode 100644 db/routines/vn2008/functions/intrastat_neto.sql create mode 100644 db/routines/vn2008/functions/nz.sql create mode 100644 db/routines/vn2008/functions/red.sql create mode 100644 db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql create mode 100644 db/routines/vn2008/procedures/CalculoRemesas.sql create mode 100644 db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql create mode 100644 db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql create mode 100644 db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql create mode 100644 db/routines/vn2008/procedures/Facturas_Saltos.sql create mode 100644 db/routines/vn2008/procedures/InsertarEspionaje.sql create mode 100644 db/routines/vn2008/procedures/ListaTicketsEncajados.sql create mode 100644 db/routines/vn2008/procedures/Rutas_Graph.sql create mode 100644 db/routines/vn2008/procedures/Trabuque.sql create mode 100644 db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql create mode 100644 db/routines/vn2008/procedures/XDiario_Quadrator.sql create mode 100644 db/routines/vn2008/procedures/account_conciliacion_add.sql create mode 100644 db/routines/vn2008/procedures/add_awb_component.sql create mode 100644 db/routines/vn2008/procedures/agencia_descuadre.sql create mode 100644 db/routines/vn2008/procedures/agencia_volume.sql create mode 100644 db/routines/vn2008/procedures/agencyModeImbalance.sql create mode 100644 db/routines/vn2008/procedures/article.sql create mode 100644 db/routines/vn2008/procedures/article_available_single.sql create mode 100644 db/routines/vn2008/procedures/article_multiple_buy.sql create mode 100644 db/routines/vn2008/procedures/article_multiple_buy_date.sql create mode 100644 db/routines/vn2008/procedures/availableTraslate.sql create mode 100644 db/routines/vn2008/procedures/balance_create.sql create mode 100644 db/routines/vn2008/procedures/base_ticket.sql create mode 100644 db/routines/vn2008/procedures/bionic_available_types_filter.sql create mode 100644 db/routines/vn2008/procedures/buy_label.sql create mode 100644 db/routines/vn2008/procedures/buy_split.sql create mode 100644 db/routines/vn2008/procedures/buy_tarifas.sql create mode 100644 db/routines/vn2008/procedures/buy_tarifas_entry.sql create mode 100644 db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql create mode 100644 db/routines/vn2008/procedures/buy_transfer.sql create mode 100644 db/routines/vn2008/procedures/cacheReset.sql create mode 100644 db/routines/vn2008/procedures/camiones.sql create mode 100644 db/routines/vn2008/procedures/check_table_existence.sql create mode 100644 db/routines/vn2008/procedures/clean.sql create mode 100644 db/routines/vn2008/procedures/clean_launcher.sql create mode 100644 db/routines/vn2008/procedures/cobro.sql create mode 100644 db/routines/vn2008/procedures/comercial_caducado.sql create mode 100644 db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql create mode 100644 db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql create mode 100644 db/routines/vn2008/procedures/confection_control_source.sql create mode 100644 db/routines/vn2008/procedures/createBouquet.sql create mode 100644 db/routines/vn2008/procedures/credit_update.sql create mode 100644 db/routines/vn2008/procedures/customerDebtEvolution.sql create mode 100644 db/routines/vn2008/procedures/desglose_volume.sql create mode 100644 db/routines/vn2008/procedures/emailYesterdayPurchasesByConsigna.sql create mode 100644 db/routines/vn2008/procedures/emailYesterdayPurchasesLauncher.sql create mode 100644 db/routines/vn2008/procedures/embalajes_stocks.sql create mode 100644 db/routines/vn2008/procedures/embalajes_stocks_detalle.sql create mode 100644 db/routines/vn2008/procedures/entryFromOrder.sql create mode 100644 db/routines/vn2008/procedures/entryFromTicket.sql create mode 100644 db/routines/vn2008/procedures/eti_to_print.sql create mode 100644 db/routines/vn2008/procedures/f10_no_vincular.sql create mode 100644 db/routines/vn2008/procedures/historico_absoluto.sql create mode 100644 db/routines/vn2008/procedures/historico_joined.sql create mode 100644 db/routines/vn2008/procedures/historico_multiple.sql create mode 100644 db/routines/vn2008/procedures/inventario_valorado.sql create mode 100644 db/routines/vn2008/procedures/item_buy.sql create mode 100644 db/routines/vn2008/procedures/item_express.sql create mode 100644 db/routines/vn2008/procedures/item_new.sql create mode 100644 db/routines/vn2008/procedures/malpagantes.sql create mode 100644 db/routines/vn2008/procedures/mensaje.sql create mode 100644 db/routines/vn2008/procedures/msg.sql create mode 100644 db/routines/vn2008/procedures/nest_child_add.sql create mode 100644 db/routines/vn2008/procedures/nest_delete.sql create mode 100644 db/routines/vn2008/procedures/nest_move.sql create mode 100644 db/routines/vn2008/procedures/newItem.sql create mode 100644 db/routines/vn2008/procedures/niching.sql create mode 100644 db/routines/vn2008/procedures/notify_passport.sql create mode 100644 db/routines/vn2008/procedures/pay.sql create mode 100644 db/routines/vn2008/procedures/percentil.sql create mode 100644 db/routines/vn2008/procedures/preOrdenarRuta.sql create mode 100644 db/routines/vn2008/procedures/prepare_client_list.sql create mode 100644 db/routines/vn2008/procedures/prepare_ticket_list.sql create mode 100644 db/routines/vn2008/procedures/proc_end.sql create mode 100644 db/routines/vn2008/procedures/proc_start.sql create mode 100644 db/routines/vn2008/procedures/prueba_miguel.sql create mode 100644 db/routines/vn2008/procedures/quadre_clientes.sql create mode 100644 db/routines/vn2008/procedures/quadre_clientes_detalle.sql create mode 100644 db/routines/vn2008/procedures/raidUpdate.sql create mode 100644 db/routines/vn2008/procedures/rateView.sql create mode 100644 db/routines/vn2008/procedures/recibidaIvaInsert.sql create mode 100644 db/routines/vn2008/procedures/recobro_credito.sql create mode 100644 db/routines/vn2008/procedures/risk_vs_client_list.sql create mode 100644 db/routines/vn2008/procedures/scan_rutas_view.sql create mode 100644 db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql create mode 100644 db/routines/vn2008/procedures/splitAnthuriums2016.sql create mode 100644 db/routines/vn2008/procedures/subordinate.sql create mode 100644 db/routines/vn2008/procedures/supplierStatement.sql create mode 100644 db/routines/vn2008/procedures/suppliersDebt.sql create mode 100644 db/routines/vn2008/procedures/top_seller.sql create mode 100644 db/routines/vn2008/procedures/traslado.sql create mode 100644 db/routines/vn2008/procedures/travelDetail.sql create mode 100644 db/routines/vn2008/procedures/travel_tree_shipment.sql create mode 100644 db/routines/vn2008/procedures/unary_delete.sql create mode 100644 db/routines/vn2008/procedures/unary_insert.sql create mode 100644 db/routines/vn2008/procedures/unary_leaves.sql create mode 100644 db/routines/vn2008/procedures/unary_scan_ident.sql create mode 100644 db/routines/vn2008/procedures/unary_scan_insert.sql create mode 100644 db/routines/vn2008/procedures/unary_tops.sql create mode 100644 db/routines/vn2008/procedures/unary_update.sql create mode 100644 db/routines/vn2008/triggers/Conteo_ai.sql create mode 100644 db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql create mode 100644 db/routines/vn2008/triggers/agency_hourBeforeInsert.sql create mode 100644 db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql create mode 100644 db/routines/vn2008/triggers/awb_recibida_ad.sql create mode 100644 db/routines/vn2008/triggers/movement_label_au.sql create mode 100644 db/routines/vn2008/views/Agencias.sql create mode 100644 db/routines/vn2008/views/Articles.sql create mode 100644 db/routines/vn2008/views/Articles_botanical.sql create mode 100644 db/routines/vn2008/views/Bancos.sql create mode 100644 db/routines/vn2008/views/Cajas.sql create mode 100644 db/routines/vn2008/views/Clientes.sql create mode 100644 db/routines/vn2008/views/Comparativa.sql create mode 100644 db/routines/vn2008/views/Compres.sql create mode 100644 db/routines/vn2008/views/Compres_mark.sql create mode 100644 db/routines/vn2008/views/Consignatarios.sql create mode 100644 db/routines/vn2008/views/Cubos.sql create mode 100644 db/routines/vn2008/views/Cubos_Retorno.sql create mode 100644 db/routines/vn2008/views/Entradas.sql create mode 100644 db/routines/vn2008/views/Entradas_Auto.sql create mode 100644 db/routines/vn2008/views/Equipos.sql create mode 100644 db/routines/vn2008/views/Facturas.sql create mode 100644 db/routines/vn2008/views/Gastos.sql create mode 100644 db/routines/vn2008/views/Greuges.sql create mode 100644 db/routines/vn2008/views/Greuges_type.sql create mode 100644 db/routines/vn2008/views/Impresoras.sql create mode 100644 db/routines/vn2008/views/Intrastat.sql create mode 100644 db/routines/vn2008/views/Monedas.sql create mode 100644 db/routines/vn2008/views/Movimientos.sql create mode 100644 db/routines/vn2008/views/Movimientos_componentes.sql create mode 100644 db/routines/vn2008/views/Movimientos_mark.sql create mode 100644 db/routines/vn2008/views/Ordenes.sql create mode 100644 db/routines/vn2008/views/Origen.sql create mode 100644 db/routines/vn2008/views/Paises.sql create mode 100644 db/routines/vn2008/views/PreciosEspeciales.sql create mode 100644 db/routines/vn2008/views/Prioridades.sql create mode 100644 db/routines/vn2008/views/Proveedores.sql create mode 100644 db/routines/vn2008/views/Recibos.sql create mode 100644 db/routines/vn2008/views/Rutas.sql create mode 100644 db/routines/vn2008/views/Rutas_Master create mode 100644 db/routines/vn2008/views/Rutas_Master.sql create mode 100644 db/routines/vn2008/views/Rutas_monitor.sql create mode 100644 db/routines/vn2008/views/Tickets.sql create mode 100644 db/routines/vn2008/views/Tickets_state.sql create mode 100644 db/routines/vn2008/views/Tickets_turno.sql create mode 100644 db/routines/vn2008/views/Tintas.sql create mode 100644 db/routines/vn2008/views/Tipos.sql create mode 100644 db/routines/vn2008/views/Trabajadores.sql create mode 100644 db/routines/vn2008/views/V_edi_item_track.sql create mode 100644 db/routines/vn2008/views/Vehiculos.sql create mode 100644 db/routines/vn2008/views/VerEspionaje.sql create mode 100644 db/routines/vn2008/views/Vistas.sql create mode 100644 db/routines/vn2008/views/XDiario.sql create mode 100644 db/routines/vn2008/views/agency.sql create mode 100644 db/routines/vn2008/views/awb.sql create mode 100644 db/routines/vn2008/views/barcodes.sql create mode 100644 db/routines/vn2008/views/bionic_updating_options.sql create mode 100644 db/routines/vn2008/views/businessReasonEnd.sql create mode 100644 db/routines/vn2008/views/buySource.sql create mode 100644 db/routines/vn2008/views/buy_edi.sql create mode 100644 db/routines/vn2008/views/cdr.sql create mode 100644 db/routines/vn2008/views/chanel.sql create mode 100644 db/routines/vn2008/views/cl_act.sql create mode 100644 db/routines/vn2008/views/cl_cau.sql create mode 100644 db/routines/vn2008/views/cl_con.sql create mode 100644 db/routines/vn2008/views/cl_det.sql create mode 100644 db/routines/vn2008/views/cl_dev.sql create mode 100644 db/routines/vn2008/views/cl_est.sql create mode 100644 db/routines/vn2008/views/cl_main.sql create mode 100644 db/routines/vn2008/views/cl_mot.sql create mode 100644 db/routines/vn2008/views/cl_res.sql create mode 100644 db/routines/vn2008/views/cl_sol.sql create mode 100644 db/routines/vn2008/views/client_observation.sql create mode 100644 db/routines/vn2008/views/clientes_gestdoc.sql create mode 100644 db/routines/vn2008/views/clientes_regalos_enc.sql create mode 100644 db/routines/vn2008/views/clientes_regalos_lista_enc.sql create mode 100644 db/routines/vn2008/views/clientes_tipo.sql create mode 100644 db/routines/vn2008/views/config_host.sql create mode 100644 db/routines/vn2008/views/consignatarios_observation.sql create mode 100644 db/routines/vn2008/views/cooler_path_detail.sql create mode 100644 db/routines/vn2008/views/credit.sql create mode 100644 db/routines/vn2008/views/deliveryPoint.sql create mode 100644 db/routines/vn2008/views/device_user.sql create mode 100644 db/routines/vn2008/views/edi_article.sql create mode 100644 db/routines/vn2008/views/edi_bucket.sql create mode 100644 db/routines/vn2008/views/edi_bucket_type.sql create mode 100644 db/routines/vn2008/views/edi_feature.sql create mode 100644 db/routines/vn2008/views/edi_genus.sql create mode 100644 db/routines/vn2008/views/edi_item_feature.sql create mode 100644 db/routines/vn2008/views/edi_plant.sql create mode 100644 db/routines/vn2008/views/edi_specie.sql create mode 100644 db/routines/vn2008/views/edi_supplier.sql create mode 100644 db/routines/vn2008/views/edi_type.sql create mode 100644 db/routines/vn2008/views/edi_value.sql create mode 100644 db/routines/vn2008/views/empresa.sql create mode 100644 db/routines/vn2008/views/empresa_grupo.sql create mode 100644 db/routines/vn2008/views/entrySource.sql create mode 100644 db/routines/vn2008/views/escritos.sql create mode 100644 db/routines/vn2008/views/escritos_det.sql create mode 100644 db/routines/vn2008/views/expeditions.sql create mode 100644 db/routines/vn2008/views/gestdoc.sql create mode 100644 db/routines/vn2008/views/gesttip.sql create mode 100644 db/routines/vn2008/views/intrastat_data.sql create mode 100644 db/routines/vn2008/views/invoiceCorrection.sql create mode 100644 db/routines/vn2008/views/itemTag.sql create mode 100644 db/routines/vn2008/views/item_entry_in.sql create mode 100644 db/routines/vn2008/views/item_entry_out.sql create mode 100644 db/routines/vn2008/views/item_out.sql create mode 100644 db/routines/vn2008/views/iva_codigo.sql create mode 100644 db/routines/vn2008/views/iva_group.sql create mode 100644 db/routines/vn2008/views/iva_group_codigo.sql create mode 100644 db/routines/vn2008/views/iva_tipo.sql create mode 100644 db/routines/vn2008/views/mail.sql create mode 100644 db/routines/vn2008/views/mandato.sql create mode 100644 db/routines/vn2008/views/mandato_tipo.sql create mode 100644 db/routines/vn2008/views/observation_type.sql create mode 100644 db/routines/vn2008/views/order.sql create mode 100644 db/routines/vn2008/views/order_Tickets.sql create mode 100644 db/routines/vn2008/views/order_component.sql create mode 100644 db/routines/vn2008/views/order_row.sql create mode 100644 db/routines/vn2008/views/pago.sql create mode 100644 db/routines/vn2008/views/pay_dem.sql create mode 100644 db/routines/vn2008/views/pay_dem_det.sql create mode 100644 db/routines/vn2008/views/pay_met.sql create mode 100644 db/routines/vn2008/views/payroll_categorias.sql create mode 100644 db/routines/vn2008/views/person_user.sql create mode 100644 db/routines/vn2008/views/person_user_idtrabajador.sql create mode 100644 db/routines/vn2008/views/plantpassport.sql create mode 100644 db/routines/vn2008/views/plantpassport_authority.sql create mode 100644 db/routines/vn2008/views/price_fixed.sql create mode 100644 db/routines/vn2008/views/producer.sql create mode 100644 db/routines/vn2008/views/proveedores_clientes.sql create mode 100644 db/routines/vn2008/views/province.sql create mode 100644 db/routines/vn2008/views/recibida.sql create mode 100644 db/routines/vn2008/views/recibida_intrastat.sql create mode 100644 db/routines/vn2008/views/recibida_iva.sql create mode 100644 db/routines/vn2008/views/recibida_vencimiento.sql create mode 100644 db/routines/vn2008/views/recovery.sql create mode 100644 db/routines/vn2008/views/reference_min.sql create mode 100644 db/routines/vn2008/views/reference_rate.sql create mode 100644 db/routines/vn2008/views/reinos.sql create mode 100644 db/routines/vn2008/views/sharingcart.sql create mode 100644 db/routines/vn2008/views/sharingclient.sql create mode 100644 db/routines/vn2008/views/sms.sql create mode 100644 db/routines/vn2008/views/state.sql create mode 100644 db/routines/vn2008/views/tag.sql create mode 100644 db/routines/vn2008/views/tarifa_componentes.sql create mode 100644 db/routines/vn2008/views/tarifa_componentes_series.sql create mode 100644 db/routines/vn2008/views/tarifas.sql create mode 100644 db/routines/vn2008/views/tblContadores.sql create mode 100644 db/routines/vn2008/views/thermograph.sql create mode 100644 db/routines/vn2008/views/ticketCreationData.sql create mode 100644 db/routines/vn2008/views/ticketMRW.sql create mode 100644 db/routines/vn2008/views/ticket_observation.sql create mode 100644 db/routines/vn2008/views/tickets_gestdoc.sql create mode 100644 db/routines/vn2008/views/time.sql create mode 100644 db/routines/vn2008/views/tr2.sql create mode 100644 db/routines/vn2008/views/travel.sql create mode 100644 db/routines/vn2008/views/travel_thermograph.sql create mode 100644 db/routines/vn2008/views/v_Articles_botanical.sql create mode 100644 db/routines/vn2008/views/v_account.sql create mode 100644 db/routines/vn2008/views/v_analisis_ventas.sql create mode 100644 db/routines/vn2008/views/v_barcodes.sql create mode 100644 db/routines/vn2008/views/v_compres.sql create mode 100644 db/routines/vn2008/views/v_departure_limit.sql create mode 100644 db/routines/vn2008/views/v_descuadre_bionic.sql create mode 100644 db/routines/vn2008/views/v_empresa.sql create mode 100644 db/routines/vn2008/views/v_inter.sql create mode 100644 db/routines/vn2008/views/v_jerarquia.sql create mode 100644 db/routines/vn2008/views/v_miriam.sql create mode 100644 db/routines/vn2008/views/v_price_fixed.sql create mode 100644 db/routines/vn2008/views/v_price_fixed_group.sql create mode 100644 db/routines/vn2008/views/v_ticket_amount.sql create mode 100644 db/routines/vn2008/views/v_ventes.sql create mode 100644 db/routines/vn2008/views/v_warehouse.sql create mode 100644 db/routines/vn2008/views/v_xsubclien.sql create mode 100644 db/routines/vn2008/views/v_xsubcuentas.sql create mode 100644 db/routines/vn2008/views/v_xsubprov.sql create mode 100644 db/routines/vn2008/views/versiones.sql create mode 100644 db/routines/vn2008/views/vnCreditClassification.sql create mode 100644 db/routines/vn2008/views/vnCreditInsurance.sql create mode 100644 db/routines/vn2008/views/vnSolunionCAP.sql create mode 100644 db/routines/vn2008/views/warehouse.sql create mode 100644 db/routines/vn2008/views/warehouse_alias.sql create mode 100644 db/routines/vn2008/views/workcenter_holiday.sql create mode 100644 db/routines/vn2008/views/workerDocument.sql create mode 100644 db/routines/vn2008/views/workerTeam.sql create mode 100644 db/routines/vn2008/views/zoneNickname.sql delete mode 100644 db/tests.js delete mode 100644 db/tests/cache/last_buy_refresh.spec.js delete mode 100644 db/tests/vn/buyUltimate.spec.js delete mode 100644 db/tests/vn/buyUltimateFromInterval.spec.js delete mode 100644 db/tests/vn/item_getBalance.spec.js delete mode 100644 db/tests/vn/ticketCalculateClon.spec.js delete mode 100644 db/tests/vn/ticketComponentUpdateSale.spec.js delete mode 100644 db/tests/vn/ticketCreateWithUser.spec.js delete mode 100644 db/tests/vn/ticket_recalcComponents.spec.js delete mode 100644 db/tests/vn/timeBusiness_calculateByUser.spec.js delete mode 100644 db/tests/vn/zone_getEvents.spec.js delete mode 100644 db/tests/vn/zone_getFromGeo.spec.js delete mode 100644 db/tests/vn/zone_getLanded.spec.js create mode 100644 db/versions/.archive/10107-pinkPaniculata/00-firstScript.sql create mode 100644 db/versions/.archive/10112-wheatAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10113-blueMonstera/00-firstScript.sql create mode 100644 db/versions/.archive/10114-maroonOrchid/00-updateConfig.sql create mode 100644 db/versions/.archive/10116-pinkOak/00-firstScript.sql create mode 100644 db/versions/.archive/10118-blueFern/00-firstScript.sql create mode 100644 db/versions/.archive/10119-navyGerbera/00-AfegirFKPart1.sql create mode 100644 db/versions/.archive/10119-navyGerbera/01-AfegirFkPart2.sql create mode 100644 db/versions/.archive/10125-grayRose/00-firstScript.sql create mode 100644 db/versions/.archive/10127-purpleMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10128-tealGerbera/00-firstScript.sql create mode 100644 db/versions/.archive/10129-maroonChrysanthemum/00-firstScript.sql create mode 100644 db/versions/.archive/10132-blackChrysanthemum/00-firstScript.sql create mode 100644 db/versions/.archive/10133-crimsonLaurel/00-firstScript.sql create mode 100644 db/versions/.archive/10134-limeAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10135-brownMonstera/00-firstScript.sql create mode 100644 db/versions/.archive/10136-turquoiseGerbera/00-workerTimeControl.sql create mode 100644 db/versions/.archive/10138-limeBirch/00-firstScript.sql create mode 100644 db/versions/.archive/10139-grayAspidistra/00-firstScript.sql create mode 100644 db/versions/.archive/10139-grayAspidistra/01-secondScript.sql create mode 100644 db/versions/.archive/10141-turquoiseCordyline/00-firstScript.sql create mode 100644 db/versions/.archive/10142-silverMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10143-whiteFern/00-firstScript.sql create mode 100644 db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.sql create mode 100644 db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.undo.sql create mode 100644 db/versions/.archive/10147-tealRuscus/00-firstScript.sql create mode 100644 db/versions/.archive/10149-whiteMonstera/00-firstScript.sql create mode 100644 db/versions/.archive/10150-4062isLaid/00-firstScript.sql create mode 100644 db/versions/.archive/10152-bluePalmetto/00-firstScript.sql create mode 100644 db/versions/.archive/10153-maroonAralia/00-firstScript.sql create mode 100644 db/versions/.archive/10154-blackSalal/00-compressionKk.sql create mode 100644 db/versions/.archive/10157-goldenCyca/00-firstScript.sql create mode 100644 db/versions/.archive/10158-grayCordyline/00-firstScript.sql create mode 100644 db/versions/.archive/10160-limePalmetto/00-firstScript.sql create mode 100644 db/versions/.archive/10163-tealErica/00-firstScript.sql create mode 100644 db/versions/.archive/10164-pinkMastic/00-borrarSectorsDesus.sql create mode 100644 db/versions/.archive/10165-yellowMastic/00-firstScript.sql create mode 100644 db/versions/.archive/10166-grayArborvitae/00-firstScript.sql create mode 100644 db/versions/.archive/10167-limeRoebelini/00-renameVnActiveContrat.sql create mode 100644 db/versions/.archive/10167-limeRoebelini/01-renameVnActiveContrat.undo.sql create mode 100644 db/versions/.archive/10168-orangeAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10169-greenMonstera/00-createTableBankEntityConfig.sql create mode 100644 db/versions/.archive/10169-greenMonstera/01-createTableBankEntityConfig.undo.sql create mode 100644 db/versions/.archive/10169-greenMonstera/02-addNotNullToBankEntityBic.sql create mode 100644 db/versions/.archive/10171-crimsonCarnation/00-volumeConfig.sql create mode 100644 db/versions/.archive/10171-crimsonCarnation/01-itemWeight.sql create mode 100644 db/versions/.archive/10171-crimsonCarnation/02-agencymode.sql create mode 100644 db/versions/.archive/10172-brownMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10174-silverOrchid/00-firstScript.sql create mode 100644 db/versions/.archive/10175-bluePaniculata/00-firstScript.sql create mode 100644 db/versions/.archive/10177-pinkArborvitae/00-crearTablaSpecialLabels.sql create mode 100644 db/versions/.archive/10178-tealMoss/00-firstScript.sql create mode 100644 db/versions/.archive/10179-goldenMonstera/00-firstScript.sql create mode 100644 db/versions/.archive/10183-navyBamboo/00-firstScript.sql create mode 100644 db/versions/.archive/10184-azureLaurel/00-firstScript.sql create mode 100644 db/versions/.archive/10185-greenGalax/00-firstScript.sql create mode 100644 db/versions/.archive/10186-silverGerbera/00-desactivar_trigger.sql create mode 100644 db/versions/.archive/10186-silverGerbera/01-alter_Table_buy.sql create mode 100644 db/versions/.archive/10186-silverGerbera/02-alter_table_entryConfig.sql create mode 100644 db/versions/.archive/10186-silverGerbera/04-regularizar_Sticker_Inventario.sql create mode 100644 db/versions/.archive/10186-silverGerbera/09-reactivar_trigger.sql create mode 100644 db/versions/.archive/10187-pinkAspidistra/00-firstScript.sql create mode 100644 db/versions/.archive/10188-limeMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10189-aquaDendro/00-firstScript.sql create mode 100644 db/versions/.archive/10191-orangeRoebelini/00-firstScript.sql create mode 100644 db/versions/.archive/10194-redRose/00-firstScript.sql create mode 100644 db/versions/.archive/10195-redPhormium/00-firstScript.sql create mode 100644 db/versions/.archive/10200-bronzeCyca/00-firstScript.sql create mode 100644 db/versions/.archive/10201-whiteRaphis/00-firstScript.sql create mode 100644 db/versions/.archive/10202-redCamellia/00-Remove_FK_to_ediGenus.sql create mode 100644 db/versions/.archive/10203-redMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10204-bronzeCarnation/00-firstScript.sql create mode 100644 db/versions/.archive/10205-bronzeAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10207-greenRose/00-Alter_table_entry.sql create mode 100644 db/versions/.archive/10207-greenRose/00-Alter_table_entry.undo.sql create mode 100644 db/versions/.archive/10207-greenRose/01-Update_invoiceAmount.sql create mode 100644 db/versions/.archive/10208-goldenRuscus/00-firstScript.sql create mode 100644 db/versions/.archive/10209-bronzeBirch/00-firstScript.sql create mode 100644 db/versions/.archive/10211-greenDendro/01-firstScript.sql create mode 100644 db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.sql create mode 100644 db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.undo.sql create mode 100644 db/versions/.archive/10216-pinkMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10216-pinkMedeola/00-firstScript.undo.sql create mode 100644 db/versions/.archive/10216-pinkMedeola/01-batchIndex.sql create mode 100644 db/versions/.archive/10216-pinkMedeola/01-batchIndex.undo.sql create mode 100644 db/versions/.archive/10219-orangeRuscus/00-AddCollectionFkOnPackingSite.sql create mode 100644 db/versions/.archive/10219-orangeRuscus/01-AddFkToCollectionFk.sql create mode 100644 db/versions/.archive/10220-chocolateCymbidium/00-createPersonalProtectionEquipment.sql create mode 100644 db/versions/.archive/10222-redEucalyptus/00-firstScript.sql create mode 100644 db/versions/.archive/10223-azureRuscus/00-firstScript.sql create mode 100644 db/versions/.archive/10224-orangeEucalyptus/00-cosetes.sql create mode 100644 db/versions/.archive/10229-salmonDendro/00-firstScript.sql create mode 100644 db/versions/.archive/10231-buyScanPAK/01-tablaEktConfig.sql create mode 100644 db/versions/.archive/10233-aquaCymbidium/00-firstScript.sql create mode 100644 db/versions/.archive/10235-limeDracena/00-firstScript.sql create mode 100644 db/versions/.archive/10236-limeArborvitae/00-firstScript.sql create mode 100644 db/versions/.archive/10237-greenRoebelini/00-firstScript.sql create mode 100644 db/versions/.archive/10238-azureMastic/00-worker_mobileExtension.sql create mode 100644 db/versions/.archive/10239-redAsparagus/00-firstScript.sql create mode 100644 db/versions/.archive/10239-redAsparagus/00-firstScript.undo.sql create mode 100644 db/versions/.archive/10241-whiteTulip/00-firstScript.sql create mode 100644 db/versions/.archive/10242-grayChico/00-firstScript.sql create mode 100644 db/versions/.archive/10243-wheatErica/00-firstScript.sql create mode 100644 db/versions/.archive/10245-yellowRaphis/00-firstScript.sql create mode 100644 db/versions/.archive/10247-whiteAsparagus/00-firstScript.sql create mode 100644 db/versions/.archive/10248-azureCordyline/00-firstScript.sql create mode 100644 db/versions/.archive/10250-wheatBamboo/00-firstScript.sql create mode 100644 db/versions/.archive/10253-whiteAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10254-whiteOak/00-firstScript.sql create mode 100644 db/versions/.archive/10256-orangeFern/00-firstScript.sql create mode 100644 db/versions/.archive/10258-azureOak/00-firstScript.sql create mode 100644 db/versions/.archive/10259-limeMonstera/00-firstScript.sql create mode 100644 db/versions/.archive/10261-maroonArborvitae/00-firstScript.sql create mode 100644 db/versions/.archive/10262-salmonTulip/00-createTablepackagingWithFreight.sql create mode 100644 db/versions/.archive/10262-salmonTulip/01-alterTablePackagingConfig.sql create mode 100644 db/versions/.archive/10262-salmonTulip/02-insertsInicials.sql create mode 100644 db/versions/.archive/10262-salmonTulip/03-createTablepackingWithoutFreight.sql create mode 100644 db/versions/.archive/10263-tealPaniculata/00-firstScript.sql create mode 100644 db/versions/.archive/10265-greenAspidistra/00-firstScript.sql create mode 100644 db/versions/.archive/10267-blueDracena/00-firstScript.sql create mode 100644 db/versions/.archive/10267-blueDracena/01-fixMerge.sql create mode 100644 db/versions/.archive/10275-maroonCataractarum/00-improvedGeneralLog.sql create mode 100644 db/versions/.archive/10277-azurePalmetto/00-firstScript.sql create mode 100644 db/versions/.archive/10278-silverRose/00-firstScript.sql create mode 100644 db/versions/.archive/10279-purpleAsparagus/00-firstScript.sql create mode 100644 db/versions/.archive/10281-navyPalmetto/00-firstScript.sql create mode 100644 db/versions/.archive/10282-brownAsparagus/00-firstScript.sql create mode 100644 db/versions/.archive/10283-rm4375pak/00-alterTable.sql create mode 100644 db/versions/.archive/10284-aquaErica/00-firstScript.sql create mode 100644 db/versions/.archive/10285-aquaHydrangea/00-firstScript.sql create mode 100644 db/versions/.archive/10287-turquoiseRose/00-firstScript.sql create mode 100644 db/versions/.archive/10288-chocolateSalal/00-firstScript.sql create mode 100644 db/versions/.archive/10289-turquoiseCarnation/00-firstScript.sql create mode 100644 db/versions/.archive/10291-azureGalax/00-firstScript.sql create mode 100644 db/versions/.archive/10293-salmonCamellia/00-firstScript.sql create mode 100644 db/versions/.archive/10297-redErica/00-firstScript.sql create mode 100644 db/versions/.archive/10298-grayBamboo/00-firstScript.sql create mode 100644 db/versions/.archive/10299-blueTulip/00-firstScript.sql create mode 100644 db/versions/.archive/10299-blueTulip/00-firstScript.undo.sql create mode 100644 db/versions/.archive/10301-4415collectionNewPAK/00-productionConfig.sql create mode 100644 db/versions/.archive/10301-4415collectionNewPAK/01-drop.sql create mode 100644 db/versions/.archive/10301-4415collectionNewPAK/02-collection.sql create mode 100644 db/versions/.archive/10302-chocolateRoebelini/00-CreateTableEntryType.sql create mode 100644 db/versions/.archive/10302-chocolateRoebelini/01-insertDataEntryType.sql create mode 100644 db/versions/.archive/10302-chocolateRoebelini/02-alterTableEntry.sql create mode 100644 db/versions/.archive/10303-tealRoebelini/00-firstScript.sql create mode 100644 db/versions/.archive/10304-limeAsparagus/00-firstScript.sql create mode 100644 db/versions/.archive/10304-limeAsparagus/01-altertableticket.sql create mode 100644 db/versions/.archive/10305-brownFern/00-ektAssign.sql create mode 100644 db/versions/.archive/10306-turquoiseCyca/00-deliveryInformation.sql create mode 100644 db/versions/.archive/10307-tealFern/00-firstScript.sql create mode 100644 db/versions/.archive/10308-grayAsparagus/00-firstScript.sql create mode 100644 db/versions/.archive/10309-navyCordyline/00-firstScript.sql create mode 100644 db/versions/.archive/10310-azureCymbidium/00-firstScript.sql create mode 100644 db/versions/.archive/10311-navyChico/00-firstScript.sql create mode 100644 db/versions/.archive/10312-pinkCymbidium/00-firstScript.sql create mode 100644 db/versions/.archive/10313-chocolateMastic/00-firstScript.sql create mode 100644 db/versions/.archive/10314-goldenGerbera/00-firstScript.sql create mode 100644 db/versions/.archive/10315-purpleDracena/00-firstScript.sql create mode 100644 db/versions/.archive/10317-crimsonRuscus/00-firstScript.sql create mode 100644 db/versions/.archive/10318-greenPaniculata/00-firstScript.sql create mode 100644 db/versions/.archive/10319-orangeLaurel/00-firstScript.sql create mode 100644 db/versions/.archive/10320-4130collectionnewPAK/00-operator.sql create mode 100644 db/versions/.archive/10320-4130collectionnewPAK/01-collection.sql create mode 100644 db/versions/.archive/10320-4130collectionnewPAK/02-productionConfig.sql create mode 100644 db/versions/.archive/10321-yellowDendro/00-firstScript.sql create mode 100644 db/versions/.archive/10322-maroonFern/00-firstScript.sql create mode 100644 db/versions/.archive/10326-crimsonCyca/00-firstScript.sql create mode 100644 db/versions/.archive/10328-whiteMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10329-aquaRose/00-firstScript.sql create mode 100644 db/versions/.archive/10330-pinkCataractarum/00-firstScript.sql create mode 100644 db/versions/.archive/10332-greenMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10334-4310collectionAssignPAK/00-collectionHotbed.sql create mode 100644 db/versions/.archive/10334-4310collectionAssignPAK/01-saleGroupDetail.sql create mode 100644 db/versions/.archive/10335-silverCyca/00-firstScript.sql create mode 100644 db/versions/.archive/10336-grayMoss/00-firstScript.sql create mode 100644 db/versions/.archive/10337-orangePalmetto/00-firstScript.sql create mode 100644 db/versions/.archive/10339-goldenCarnation/00-firstScript.sql create mode 100644 db/versions/.archive/10340-maroonCordyline/00-firstScript.sql create mode 100644 db/versions/.archive/10341-redDendro/00-firstScript.sql create mode 100644 db/versions/.archive/10342-limeChico/00-firstScript.sql create mode 100644 db/versions/.archive/10343-azureOak/00-firstScript.sql create mode 100644 db/versions/.archive/10345-wheatRaphis/00-firstScript.sql create mode 100644 db/versions/.archive/10347-wheatDracena/00-firstScript.sql create mode 100644 db/versions/.archive/10347-wheatDracena/01-addVirtualField.sql create mode 100644 db/versions/.archive/10349-greenOak/00-firstScript.sql create mode 100644 db/versions/.archive/10350-azureAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10352-maroonHydrangea/00-firstScript.sql create mode 100644 db/versions/.archive/10353-silverRoebelini/00-firstScript.sql create mode 100644 db/versions/.archive/10354-wheatMedeola/00-firstScript.sql create mode 100644 db/versions/.archive/10356-turquoiseAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10356-turquoiseAnthurium/01-orderConfigFk.sql create mode 100644 db/versions/.archive/10356-turquoiseAnthurium/02-orderConfigDrop.sql create mode 100644 db/versions/.archive/10357-blackAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10359-turquoiseAnthurium/00-improvedGeneralLog_collate.sql create mode 100644 db/versions/.archive/10360-tealLaurel/00-firstScript.sql create mode 100644 db/versions/.archive/10361-redTulip/00-firstScript.sql create mode 100644 db/versions/.archive/10362-azureMoss/00-dropUdfs.sql create mode 100644 db/versions/.archive/10362-azureMoss/00-dropUdfs.undo.sql create mode 100644 db/versions/.archive/10363-azureLilium/00-firstScript.sql create mode 100644 db/versions/.archive/10365-hfCollectionPAK/00-firstScript.sql create mode 100644 db/versions/.archive/10368-maroonErica/00-firstScript.sql create mode 100644 db/versions/.archive/10369-hfProductionControlPAK/00-firstScript.sql create mode 100644 db/versions/.archive/10370-pinkBirch/00-deleteForeignKey.sql create mode 100644 db/versions/.archive/10370-pinkBirch/01-firstScript.sql create mode 100644 db/versions/.archive/10370-pinkBirch/02-deleteTable.sql create mode 100644 db/versions/.archive/10370-pinkBirch/03-accion.sql create mode 100644 db/versions/.archive/10370-pinkBirch/04-inter.sql create mode 100644 db/versions/.archive/10371-crimsonChico/00-firstScript.sql create mode 100644 db/versions/.archive/10372-grayIvy/00-firstScript.sql create mode 100644 db/versions/.archive/10373-salmonHydrangea/00-firstScript.sql create mode 100644 db/versions/.archive/10378-blueCarnation/00-rename_routeUserPercentage.sql create mode 100644 db/versions/.archive/10382-4777itemShelvingPAK/00-firstScript.sql create mode 100644 db/versions/.archive/10383-navyBirch/00-firstScript.sql create mode 100644 db/versions/.archive/10385-chocolateMonstera/00-firstScript.sql create mode 100644 db/versions/.archive/10386-tealTulip/00-firstScript.sql create mode 100644 db/versions/.archive/10387-wheatRuscus/00-firstScript.sql create mode 100644 db/versions/.archive/10388-bronzePaniculata/00-resizeUtilVerionLogCode.sql create mode 100644 db/versions/.archive/10388-bronzePaniculata/01-resizeUtilVersionCode.sql create mode 100644 db/versions/.archive/10390-chocolateAnthurium/00-firstScript.sql create mode 100644 db/versions/.archive/10391-orangeCyca/00-firstScript.sql create mode 100644 db/versions/.archive/10394-brownHydrangea/00-firstScript.sql create mode 100644 db/versions/10193-navyHydrangea/00-delete.sql create mode 100644 db/versions/10193-navyHydrangea/01-botanicExport.sql create mode 100644 db/versions/10193-navyHydrangea/02-item.sql create mode 100644 db/versions/10193-navyHydrangea/03-autonomy.sql create mode 100644 db/versions/10193-navyHydrangea/03-turn.sql create mode 100644 db/versions/10193-navyHydrangea/04-country.sql create mode 100644 db/versions/10379-turquoiseOrchid/00-firstScript.sql create mode 100644 db/versions/10384-limeLaurel/00-business_workcenterFk.sql create mode 100644 db/versions/10395-blueGalax/00-firstScript.sql create mode 100644 db/versions/10396-grayRoebelini/00-firstScript.sql create mode 100644 db/versions/10397-4848TicketsFloramondo/00-firstScript.sql create mode 100644 db/versions/10399-blueErica/00-firstScript.sql create mode 100644 db/versions/10400-brownEucalyptus/00-firstScript.sql create mode 100644 db/versions/10402-orangeTulip/00-firstScript.sql create mode 100644 db/versions/10404-grayMedeola/00-firstScript.sql create mode 100644 db/versions/10405-orangeGalax/00-firstScript.sql create mode 100644 db/versions/10407-blueOak/00-firstScript.sql create mode 100644 db/versions/10408-purpleIvy/00-firstScript.sql create mode 100644 db/versions/10409-brownSalal/00-firstScript.sql rename db/{.archive/224702/00-zipConfig.sql => versions/10412-yellowCarnation/00-firstScript.sql} (53%) create mode 100644 db/versions/10413-whiteCymbidium/00-firstScript.sql create mode 100644 db/versions/10416-blueAsparagus/00-firstScript.sql create mode 100644 db/versions/10420-goldenCataractarum/00-firstScript.sql create mode 100644 db/versions/10421-navyMonstera/00-firstScript.sql create mode 100644 db/versions/10426-silverAsparagus/00-firstScript.sql create mode 100644 db/versions/10428-wheatRose/00-firstScript.sql create mode 100644 db/versions/10431-redCordyline/00-firstScript.sql create mode 100644 db/versions/10433-salmonAnthurium/00-firstScript.sql create mode 100644 db/versions/10434-grayTulip/00-firstScript.sql create mode 100644 db/versions/10435-aquaGalax/00-firstScript.sql create mode 100644 db/versions/10436-tealPalmetto/00-createFkWorker.sql create mode 100644 db/versions/10436-tealPalmetto/01-addStateToWorkerProductivity.sql create mode 100644 db/versions/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql create mode 100644 db/versions/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql create mode 100644 db/versions/10436-tealPalmetto/04-DropSchemaVnControl.sql create mode 100644 db/versions/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql create mode 100644 db/versions/10439-greenTulip/00-fixRole.sql create mode 100644 db/versions/10440-grayDendro/00-firstScript.sql create mode 100644 db/versions/10444-crimsonBamboo/00-firstScript.sql create mode 100644 db/versions/10445-orangeMoss/00-firstScript.sql create mode 100644 db/versions/10448-wheatChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10450-blackIvy/00-firstScript.sql create mode 100644 db/versions/10451-salmonOak/00-firstScript.sql create mode 100644 db/versions/10452-redEucalyptus/00-firstScript.sql create mode 100644 db/versions/10453-aquaMedeola/00-firstScript.sql create mode 100644 db/versions/10454-bronzeMoss/00-firstScript.sql create mode 100644 db/versions/10455-blackGerbera/00-firstScript.sql create mode 100644 db/versions/10456-greenArborvitae/00-firstScript.sql create mode 100644 db/versions/10457-crimsonTulip/00-firstScript.sql create mode 100644 db/versions/10458-orangePalmetto/00-firstScript.sql create mode 100644 db/versions/10459-chocolateMedeola/00-alterTableUtilConfig.sql create mode 100644 db/versions/10459-chocolateMedeola/01-createFunctionCurdate.sql create mode 100644 db/versions/10459-chocolateMedeola/02-createFunctionMockTime.sql create mode 100644 db/versions/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql create mode 100644 db/versions/10459-chocolateMedeola/04-createFunctionNow.sql create mode 100644 db/versions/10460-crimsonDendro/00-firstScript.sql create mode 100644 db/versions/10461-filtroPorTipos/00-firstScript.sql create mode 100644 db/versions/10463-wheatMonstera/00-firstScript.sql create mode 100644 db/versions/10468-goldenGerbera/00-firstScript.sql create mode 100644 db/versions/10469-bronzeEucalyptus/00-firstScript.sql create mode 100644 db/versions/10470-notaUltimoUsuario/00-firstScript.sql create mode 100644 db/versions/10471-orangeMastic/00-firstScript.sql create mode 100644 db/versions/10472-bronzeOak/00-firstScript.sql create mode 100644 db/versions/10477-goldenDendro/00-firstScript.sql create mode 100644 db/versions/10478-tealGalax/00-dropBasket.sql create mode 100644 db/versions/10478-tealGalax/00-firstScript.sql create mode 100644 db/versions/10478-tealGalax/01-orderConfigured.sql create mode 100644 db/versions/10478-tealGalax/02-configuredUpdate.sql create mode 100644 db/versions/10478-tealGalax/99-privileges.sql create mode 100644 db/versions/10480-blueTulip/00-firstScript.sql create mode 100644 db/versions/10481-brownAspidistra/00-firstScript.sql create mode 100644 db/versions/10482-blueMastic/00-firstScript.sql create mode 100644 db/versions/10485-aquaCamellia/00-firstScript.sql create mode 100644 db/versions/10488-grayCarnation/00-firstScript.sql create mode 100644 db/versions/10491-orangeDracena/00-firstScript.sql create mode 100644 db/versions/10492-wheatIvy/00-firstScript.sql create mode 100644 db/versions/10493-purpleAnthurium/00-firstScript.sql create mode 100644 db/versions/10495-whiteFern/00-firstScript.sql create mode 100644 db/versions/10498-redAspidistra/00-firstScript.sql create mode 100644 db/versions/10500-limeChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10500-limeRaphis/00-firstScript.sql create mode 100644 db/versions/10501-orangeAnthurium/00-firstScript.sql create mode 100644 db/versions/10502-azureCarnation/00-firstScript.sql create mode 100644 db/versions/10502-yellowCordyline/00-firstScript.sql create mode 100644 db/versions/10504-maroonPalmetto/00-firstScript.sql create mode 100644 db/versions/10506-aquaPaniculata/01-firstScript.sql create mode 100644 db/versions/10506-aquaPaniculata/02-secondScript.sql create mode 100644 db/versions/10506-aquaPaniculata/03-thirdScript.sql create mode 100644 db/versions/10506-crimsonRoebelini/00-firstScript.sql create mode 100644 db/versions/10507-greenAspidistra/00-firstScript.sql create mode 100644 db/versions/10508-maroonMonstera/00-firstScript.sql create mode 100644 db/versions/10510-salmonMoss/00-dropBusinessFk.sql create mode 100644 db/versions/10510-salmonMoss/01-createTableProfessionalCategory.sql create mode 100644 db/versions/10510-salmonMoss/02-exportToNewTable.sql create mode 100644 db/versions/10510-salmonMoss/03-RecreateFK.sql create mode 100644 db/versions/10510-salmonMoss/04-kkPostgresqlTable.sql create mode 100644 db/versions/10511-chocolateChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10512-purpleRoebelini/00-firstScript.sql create mode 100644 db/versions/10513-aquaCataractarum/00-firstScript.sql create mode 100644 db/versions/10514-silverAspidistra/00-firstScript.sql create mode 100644 db/versions/10516-crimsonSalal/00-firstScript.sql create mode 100644 db/versions/10521-salmonLilium/00-firstScript.sql create mode 100644 db/versions/10522-yellowMedeola/00-firstScript.sql create mode 100644 db/versions/10523-tealCataractarum/00-firstScript.sql create mode 100644 db/versions/10524-limeCordyline/00-firstScript.sql create mode 100644 db/versions/10524-limeCordyline/01-rateEditorFk.sql create mode 100644 db/versions/10525-yellowRuscus/00-firstScript.sql create mode 100644 db/versions/10526-goldenOak/00-firstScript.sql create mode 100644 db/versions/10528-orangeRoebelini/00-firstScript.sql create mode 100644 db/versions/10530-orangeCyca/00-firstScript.sql create mode 100644 db/versions/10531-chocolateFern/00-firstScript.sql create mode 100644 db/versions/10532-tealTulip/00-firstScript.sql create mode 100644 db/versions/10533-crimsonLaurel/00-firstScript.sql create mode 100644 db/versions/10537-grayCordyline/00-firstScript.sql create mode 100644 db/versions/10538-silverAspidistra/00-createChronopostConfig.sql create mode 100644 db/versions/10538-silverAspidistra/01-createChronopostService.sql create mode 100644 db/versions/10538-silverAspidistra/02-createChronopostExpedition.sql create mode 100644 db/versions/10538-silverAspidistra/03-createChronopostSenderAddress.sql create mode 100644 db/versions/10538-silverAspidistra/04-addgrantPrivilegies.sql create mode 100644 db/versions/10538-silverAspidistra/05-updateChronopostConfig.sql create mode 100644 db/versions/10539-pinkPalmetto/00-firstScript.sql create mode 100644 db/versions/10540-bronzeOrchid/00-firstScript.sql create mode 100644 db/versions/10545-maroonDracena/00-firstScript.sql create mode 100644 db/versions/10546-redOak/00-firstScript.sql create mode 100644 db/versions/10547-aquaDendro/00-firstScript.sql create mode 100644 db/versions/10549-goldenHydrangea/00-updateUpdateLog.sql create mode 100644 db/versions/10549-goldenHydrangea/01-updateInsertLog.sql create mode 100644 db/versions/10549-goldenHydrangea/02-updateDeleteLog.sql create mode 100644 db/versions/10549-goldenHydrangea/03-deleteEmptyLog.sql create mode 100644 db/versions/10549-goldenHydrangea/04-optimizeLogTables.sql create mode 100644 db/versions/10550-grayMonstera/00-editorFk.sql create mode 100644 db/versions/10550-grayMonstera/01-originFk.sql create mode 100644 db/versions/10552-blackAnthurium/00-firstScript.sql create mode 100644 db/versions/10554-maroonFern/00-firstScript.sql create mode 100644 db/versions/10557-whiteCordyline/00-firstScript.sql create mode 100644 db/versions/10559-brownDracena/00-firstScript.sql create mode 100644 db/versions/10560-crimsonCataractarum/00-firstScript.sql create mode 100644 db/versions/10562-whiteDendro/00-firstScript.sql create mode 100644 db/versions/10563-azureMonstera/00-delivery_ticketFk.sql rename db/{.archive/231401/00-hotfixDelivery.sql => versions/10566-azureArborvitae/00-firstScript.sql} (85%) create mode 100644 db/versions/10567-salmonAspidistra/00-firstScript.sql create mode 100644 db/versions/10568-grayAnthurium/00-firstScript.sql create mode 100644 db/versions/10569-salmonLaurel/00-firstScript.sql create mode 100644 db/versions/10570-goldenTulip/00-createSendingConfig.sql create mode 100644 db/versions/10570-goldenTulip/01-createSendingServiceWeekday.sql create mode 100644 db/versions/10570-goldenTulip/02-createSendingService.sql create mode 100644 db/versions/10570-goldenTulip/03-permisos.sql create mode 100644 db/versions/10571-navyCyca/00-firstScript.sql create mode 100644 db/versions/10573-tealChico/00-firstScript.sql create mode 100644 db/versions/10575-crimsonAnthurium/00-firstScript.sql create mode 100644 db/versions/10577-salmonMonstera/00-firstScript.sql create mode 100644 db/versions/10578-brownCarnation/00-firstScript.sql create mode 100644 db/versions/10579-aquaRoebelini/00-firstScript.sql create mode 100644 db/versions/10580-purpleCataractarum/00-itemTypeDropConstraint.sql create mode 100644 db/versions/10580-purpleCataractarum/01-itemTypeAddConstraint.sql create mode 100644 db/versions/10581-grayPaniculata/00-itemTypeAutoIncrement.sql create mode 100644 db/versions/10582-purpleOrchid/00-firstScript.sql create mode 100644 db/versions/10583-turquoiseGerbera/00-firstScript.sql create mode 100644 db/versions/10584-azureGerbera/00-firstScript.sql create mode 100644 db/versions/10585-pinkMedeola/00-ticketLog.sql create mode 100644 db/versions/10585-pinkMedeola/01-entryLog.sql create mode 100644 db/versions/10585-pinkMedeola/02-claimLog.sql create mode 100644 db/versions/10585-pinkMedeola/03-clientLog.sql create mode 100644 db/versions/10585-pinkMedeola/04-invoiceInLog.sql create mode 100644 db/versions/10585-pinkMedeola/05-itemLog.sql create mode 100644 db/versions/10585-pinkMedeola/06-routeLog.sql create mode 100644 db/versions/10585-pinkMedeola/07-shelvingLog.sql create mode 100644 db/versions/10585-pinkMedeola/08-supplierLog.sql create mode 100644 db/versions/10585-pinkMedeola/09-travelLog.sql create mode 100644 db/versions/10585-pinkMedeola/10-workerLog.sql create mode 100644 db/versions/10585-pinkMedeola/11-zoneLog.sql create mode 100644 db/versions/10585-pinkMedeola/12-userLog.sql create mode 100644 db/versions/10585-pinkMedeola/13-roleLog.sql create mode 100644 db/versions/10587-navyOak/00-arcRead_addMinimum.sql create mode 100644 db/versions/10593-greenLilium/00-firstScript.sql create mode 100644 db/versions/10596-purpleCamellia/00-firstScript.sql create mode 100644 db/versions/10597-navyAralia/00-firstScript.sql create mode 100644 db/versions/10598-purpleGalax/00-workerLog.sql create mode 100644 db/versions/10598-purpleGalax/01-supplierLog.sql create mode 100644 db/versions/10598-purpleGalax/02-workerTimeControlLog.sql create mode 100644 db/versions/10598-purpleGalax/03-workerClockLog.sql create mode 100644 db/versions/10599-orangeHydrangea/00-firstScript.sql create mode 100644 db/versions/10601-orangeErica/00-firstScript.sql create mode 100644 db/versions/10602-whiteArborvitae/00-firstScript.sql create mode 100644 db/versions/10606-pinkChico/00-firstScript.sql create mode 100644 db/versions/10608-pinkAsparagus/00-firstScript.sql create mode 100644 db/versions/10609-grayRaphis/00-firstScript.sql create mode 100644 db/versions/10610-goldenArborvitae/00-updateCompanyId.sql create mode 100644 db/versions/10610-goldenArborvitae/01-updateSupplierId.sql create mode 100644 db/versions/10610-goldenArborvitae/02-invoiceOutCompany.sql create mode 100644 db/versions/10611-blueGerbera/00-firstScript.sql create mode 100644 db/versions/10613-purpleAspidistra/00-firstScript.sql create mode 100644 db/versions/10614-chocolateGalax/00-firstScript.sql create mode 100644 db/versions/10615-azureCataractarum/00-firstScript.sql create mode 100644 db/versions/10616-yellowIvy/00-firstScript.sql create mode 100644 db/versions/10616-yellowIvy/01-firstScript.sql create mode 100644 db/versions/10617-aquaAralia/00-firstScript.sql create mode 100644 db/versions/10618-whiteArborvitae/00-firstScript.sql create mode 100644 db/versions/10619-chocolateErica/00-firstScript.sql create mode 100644 db/versions/10620-azurePalmetto/00-firstScript.sql create mode 100644 db/versions/10624-blueAnthurium/00-firstScript.sql create mode 100644 db/versions/10625-whiteOak/00-firstScript.sql create mode 100644 db/versions/10626-silverRaphis/00-firstScript.sql create mode 100644 db/versions/10628-grayOrchid/00-firstScript.sql create mode 100644 db/versions/10630-brownMastic/00-firstScript.sql create mode 100644 db/versions/10631-yellowBamboo/00-firstScript.sql create mode 100644 db/versions/10632-wheatPaniculata/00-firstScript.sql create mode 100644 db/versions/10633-orangeArborvitae/00-firstScript.sql create mode 100644 db/versions/10634-pinkCymbidium/00-firstScript.sql create mode 100644 db/versions/10637-yellowAspidistra/00-firstScript.sql create mode 100644 db/versions/10640-redPalmetto/00-companyFkDrop.sql create mode 100644 db/versions/10640-redPalmetto/01-companyFkAi.sql create mode 100644 db/versions/10640-redPalmetto/02-companyFkCreate.sql create mode 100644 db/versions/10640-redPalmetto/04-supplierFkDrop.sql create mode 100644 db/versions/10640-redPalmetto/05-supplierFkAi.sql create mode 100644 db/versions/10640-redPalmetto/06-supplierFkCreate.sql create mode 100644 db/versions/10642-crimsonAspidistra/00-firstScript.sql create mode 100644 db/versions/10643-blueCataractarum/00-firstScript.sql create mode 100644 db/versions/10644-aquaLaurel/00-firstScript.sql create mode 100644 db/versions/10645-purplePalmetto/00-addNewFields.sql create mode 100644 db/versions/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql create mode 100644 db/versions/10645-purplePalmetto/02-updateWagonPrimaryKey.sql create mode 100644 db/versions/10645-purplePalmetto/03-addFieldToPackingSite.sql create mode 100644 db/versions/10647-goldenBamboo/00-renombrarTabla.sql create mode 100644 db/versions/10648-blackBirch/00-firstScript.sql create mode 100644 db/versions/10649-yellowAsparagus/00-firstScript.sql create mode 100644 db/versions/10651-chocolatePalmetto/00-comparativeCountryFk.sql create mode 100644 db/versions/10651-chocolatePalmetto/01-comparativeAddConfig.sql create mode 100644 db/versions/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql create mode 100644 db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql create mode 100644 db/versions/10652-maroonPhormium/00-firstScript.sql create mode 100644 db/versions/10653-redHydrangea/00-firstScript.sql create mode 100644 db/versions/10655-navyRuscus/00-firstScript.sql create mode 100644 db/versions/10656-navyMastic/00-firstScript.sql create mode 100644 db/versions/10657-redDracena/00-renameErrorProduction.sql create mode 100644 db/versions/10657-redDracena/01-changeNightTask.sql create mode 100644 db/versions/10657-redDracena/02-addCodeToClaimResponsible.sql create mode 100644 db/versions/10657-redDracena/03-grantSelectGrafana.sql create mode 100644 db/versions/10658-whiteDracena/00-firstScript.sql create mode 100644 db/versions/10659-azureDracena/00-firstScript.sql create mode 100644 db/versions/10661-crimsonIvy/00-firstScript.sql create mode 100644 db/versions/10662-wheatErica/00-firstScript.sql create mode 100644 db/versions/10663-tealCymbidium/00-firstScript.sql create mode 100644 db/versions/10665-maroonSalal/00-firstScript.sql create mode 100644 db/versions/10666-limeGerbera/00-firstScript.sql create mode 100644 db/versions/10667-blackChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10668-tealBirch/00-firstScript.sql create mode 100644 db/versions/10671-maroonIvy/00-firstScript.sql create mode 100644 db/versions/10675-grayRuscus/00-firstScript.sql create mode 100644 db/versions/10676-aquaTulip/00-firstScript.sql create mode 100644 db/versions/10677-yellowMoss/00-firstScript.sql create mode 100644 db/versions/10678-orangeMedeola/00-firstScript.sql create mode 100644 db/versions/10679-inventoryDiscrepancy/00-tables.sql create mode 100644 db/versions/10680-turquoiseLilium/00-firstScript.sql create mode 100644 db/versions/10682-crimsonEucalyptus/00-firstScript.sql create mode 100644 db/versions/10683-bronzeMastic/00-firstScript.sql create mode 100644 db/versions/10684-tealEucalyptus/00-firstScript.sql create mode 100644 db/versions/10685-blueMedeola/00-firstScript.sql create mode 100644 db/versions/10690-azureGalax/00-firstScript.sql create mode 100644 db/versions/10691-bronzeCamellia/00-firstScript.sql create mode 100644 db/versions/10692-silverLilium/00-firstScript.sql create mode 100644 db/versions/10693-chocolateCordyline/00-firstScript.sql create mode 100644 db/versions/10694-bluePaniculata/00-firstScript.sql create mode 100644 db/versions/10695-pinkMastic/00-firstScript.sql create mode 100644 db/versions/10696-blackCataractarum/00-firstScript.sql create mode 100644 db/versions/10698-yellowGalax/00-firstScript.sql create mode 100644 db/versions/10699-aquaOak/00-firstScript.sql create mode 100644 db/versions/10700-salmonTulip/00-firstScript.sql create mode 100644 db/versions/10701-turquoisePaniculata/00-firstScript.sql create mode 100644 db/versions/10702-crimsonCymbidium/00-firstScript.sql create mode 100644 db/versions/10704-wheatMastic/00-firstScript.sql create mode 100644 db/versions/10705-yellowBirch/00-firstScript.sql create mode 100644 db/versions/10707-azureFern/00-firstScript.sql create mode 100644 db/versions/10708-greenChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10712-crimsonCordyline/00-firstScript.sql create mode 100644 db/versions/10714-azureOak/00-firstScript.sql create mode 100644 db/versions/10716-chocolateCamellia/00-firstScript.sql create mode 100644 db/versions/10717-silverRose/00-firstScript.sql create mode 100644 db/versions/10718-orangeRaphis/00-firstScript.sql create mode 100644 db/versions/10719-orangeMonstera/00-firstScript.sql create mode 100644 db/versions/10720-wheatCymbidium/00-firstScript.sql create mode 100644 db/versions/10721-blueEucalyptus/00-firstScript.sql create mode 100644 db/versions/10725-wheatAnthurium/00-firstScript.sql create mode 100644 db/versions/10726-blackMastic/00-firstScript.sql create mode 100644 db/versions/10727-limeErica/00-addPrinterField.sql create mode 100644 db/versions/10727-limeErica/01-createTableScreenModel.sql create mode 100644 db/versions/10727-limeErica/02-createTableScreen.sql create mode 100644 db/versions/10727-limeErica/03-createTableScreenModel.sql create mode 100644 db/versions/10727-limeErica/04-createTableScanner.sql create mode 100644 db/versions/10727-limeErica/05-createTablePackingSiteDeviceLog.sql create mode 100644 db/versions/10727-limeErica/06-alterTablePrinterModel.sql create mode 100644 db/versions/10727-limeErica/07-AddFieldsToPackingSite.sql create mode 100644 db/versions/10730-whiteChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10733-azureErica/00-firstScript.sql create mode 100644 db/versions/10736-maroonChico/00-workerBossNull.sql create mode 100644 db/versions/10739-turquoiseCordyline/00-firstScript.sql create mode 100644 db/versions/10740-pinkCataractarum/00-firstScript.sql create mode 100644 db/versions/10741-maroonMastic/01-refactorCplusTrascendency472.sql create mode 100644 db/versions/10741-maroonMastic/02-refactorCplusTrascendency477.sql create mode 100644 db/versions/10741-maroonMastic/03-refactorCplusInvoiceType477.sql create mode 100644 db/versions/10741-maroonMastic/04-refactorCplusInvoiceType472.sql create mode 100644 db/versions/10741-maroonMastic/05-fixes.sql create mode 100644 db/versions/10744-aquaBirch/00-firstScript.sql create mode 100644 db/versions/10746-aquaMastic/00-firstScript.sql create mode 100644 db/versions/10747-brownRaphis/00-firstScript.sql create mode 100644 db/versions/10748-navyRose/00-firstScript.sql create mode 100644 db/versions/10748-navyRose/01-SecondScript.sql create mode 100644 db/versions/10749-chocolateEucalyptus/00-firstScript.sql create mode 100644 db/versions/10750-limeAsparagus/00-firstScript.sql create mode 100644 db/versions/10750-wheatGalax/00-ticket_addGrants.sql create mode 100644 db/versions/10751-silverArborvitae/00-firstScript.sql create mode 100644 db/versions/10752-crimsonChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10753-blueDracena/00-firstScript.sql create mode 100644 db/versions/10754-purpleMonstera/00-firstScript.sql create mode 100644 db/versions/10755-redGalax/00-firstScript.sql create mode 100644 db/versions/10756-wheatRoebelini/00-firstScript.sql create mode 100644 db/versions/10757-silverChrysanthemum/00-firstScript.sql create mode 100644 db/versions/10758-boxPicking/00-sectorType.sql create mode 100644 db/versions/10758-boxPicking/01-dipole.sql create mode 100644 db/versions/10761-greenGalax/00-firstScript.sql create mode 100644 db/versions/10768-blueRose/00-firstScript.sql create mode 100644 db/versions/10771-bronzeLaurel/00-firstScript.sql create mode 100644 db/versions/10773-maroonBamboo/00-firstScript.sql create mode 100644 db/versions/10775-chocolateOrchid/00-firstScript.sql create mode 100644 db/versions/10778-goldenSalal/00-firstScript.sql create mode 100644 db/versions/10782-salmonErica/00-firstScript.sql create mode 100644 db/versions/10783-silverGalax/00-firstScript.sql create mode 100644 db/versions/10785-grayCyca/00-firstScript.sql create mode 100644 db/versions/10785-grayCyca/02-invoiceIn.sql create mode 100644 db/versions/10785-grayCyca/02-invoiceInTax.sql create mode 100644 db/versions/10785-grayCyca/02-item.sql create mode 100644 db/versions/10789-whiteSalal/00-firstScript.sql create mode 100644 db/versions/10789-whiteSalal/00-firstScript.vn.sql create mode 100644 db/versions/10792-crimsonMoss/00-buy.sql create mode 100644 db/versions/10798-grayLaurel/00-firstScript.sql create mode 100644 db/versions/10799-limePalmetto/00-firstScript.sql create mode 100644 db/versions/10800-yellowSalal/00-firstScript.sql create mode 100644 db/versions/10801-redRoebelini/00-firstScript.sql create mode 100644 db/versions/10806-limeRose/00-firstScript.sql create mode 100755 myt.config.yml diff --git a/db/.archive/224701/00-ACL.sql b/db/.archive/224701/00-ACL.sql deleted file mode 100644 index 2cce197b2..000000000 --- a/db/.archive/224701/00-ACL.sql +++ /dev/null @@ -1,49 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('ClientConsumptionQueue', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'deliveryNotePdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'deliveryNoteEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'deliveryNoteCsvPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'deliveryNoteCsvEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientWelcomeHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientWelcomeEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'creditRequestPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'creditRequestHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'creditRequestEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'printerSetupHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'printerSetupEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'sepaCoreEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorStHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorStEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorNdHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorNdEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'incotermsAuthorizationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'incotermsAuthorizationHtml', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'incotermsAuthorizationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'consumptionSendQueued', 'WRITE', 'ALLOW', 'ROLE', 'system'), - ('InvoiceOut', 'invoiceEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('InvoiceOut', 'exportationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('InvoiceOut', 'sendQueued', 'WRITE', 'ALLOW', 'ROLE', 'system'), - ('Ticket', 'invoiceCsvPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'invoiceCsvEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Supplier', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Supplier', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Travel', 'extraCommunityPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Travel', 'extraCommunityEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Entry', 'entryOrderPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('OsTicket', 'osTicketReportEmail', 'WRITE', 'ALLOW', 'ROLE', 'system'), - ('Item', 'buyerWasteEmail', 'WRITE', 'ALLOW', 'ROLE', 'system'), - ('Claim', 'claimPickupPdf', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Claim', 'claimPickupEmail', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), - ('Item', 'labelPdf', 'READ', 'ALLOW', 'ROLE', 'employee'); - -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Sector','*','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Sector','*','WRITE','ALLOW','ROLE','employee'); diff --git a/db/.archive/224701/00-acl_receiptPdf.sql b/db/.archive/224701/00-acl_receiptPdf.sql deleted file mode 100644 index 42f84b87d..000000000 --- a/db/.archive/224701/00-acl_receiptPdf.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Receipt', 'receiptPdf', '*', 'ALLOW', 'ROLE', 'salesAssistant'); diff --git a/db/.archive/224701/00-clientConsumptionQueue.sql b/db/.archive/224701/00-clientConsumptionQueue.sql deleted file mode 100644 index 2734d32cc..000000000 --- a/db/.archive/224701/00-clientConsumptionQueue.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table `vn`.`clientConsumptionQueue` -( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - params json not null, - queued datetime default current_timestamp() not null, - printed datetime null, - status varchar(50) default '' null -) - comment 'Queue for client consumption PDF mailing'; diff --git a/db/.archive/224701/00-invoiceOutQueue.sql b/db/.archive/224701/00-invoiceOutQueue.sql deleted file mode 100644 index 52ed4a113..000000000 --- a/db/.archive/224701/00-invoiceOutQueue.sql +++ /dev/null @@ -1 +0,0 @@ -rename table `vn`.`invoiceOut_queue` to `vn`.`invoiceOutQueue`; diff --git a/db/.archive/224701/00-itemConfig.sql b/db/.archive/224701/00-itemConfig.sql deleted file mode 100644 index b148aa094..000000000 --- a/db/.archive/224701/00-itemConfig.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `vn`.`itemConfig` - ADD id int null PRIMARY KEY first; - -ALTER TABLE `vn`.`itemConfig` - ADD wasteRecipients VARCHAR(50) NOT NULL comment 'Weekly waste report schedule recipients'; diff --git a/db/.archive/224701/00-printConfig.sql b/db/.archive/224701/00-printConfig.sql deleted file mode 100644 index c5af09ac9..000000000 --- a/db/.archive/224701/00-printConfig.sql +++ /dev/null @@ -1,10 +0,0 @@ -create table `salix`.`printConfig` -( - id int auto_increment, - itRecipient varchar(50) null comment 'IT recipients for report mailing', - incidencesEmail varchar(50) null comment 'CAU destinatary email', - constraint printConfig_pk - primary key (id) -) - comment 'Print service config'; - diff --git a/db/.archive/224701/00-sample.sql b/db/.archive/224701/00-sample.sql deleted file mode 100644 index f84cd723e..000000000 --- a/db/.archive/224701/00-sample.sql +++ /dev/null @@ -1,6 +0,0 @@ -alter table `vn`.`sample` - add model VARCHAR(25) null comment 'Model name in plural'; - -UPDATE vn.sample t - SET t.model = 'Clients' - WHERE t.id IN(12, 13, 14, 15, 16, 18, 19, 20); \ No newline at end of file diff --git a/db/.archive/224701/00-user_hasGrant.sql b/db/.archive/224701/00-user_hasGrant.sql deleted file mode 100644 index 60d1273d8..000000000 --- a/db/.archive/224701/00-user_hasGrant.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `account`.`user` ADD hasGrant TINYINT(1) NOT NULL; diff --git a/db/.archive/224702/00-ACL_workerDisableExcluded.sql b/db/.archive/224702/00-ACL_workerDisableExcluded.sql deleted file mode 100644 index 2fd9e8b12..000000000 --- a/db/.archive/224702/00-ACL_workerDisableExcluded.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalId) - VALUES ('WorkerDisableExcluded','*','*','ALLOW','hr'); \ No newline at end of file diff --git a/db/.archive/224702/00-aclBusiness.sql b/db/.archive/224702/00-aclBusiness.sql deleted file mode 100644 index 8ea2c6d83..000000000 --- a/db/.archive/224702/00-aclBusiness.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Business', '*', '*', 'ALLOW', 'ROLE', 'hr'); \ No newline at end of file diff --git a/db/.archive/224702/00-aclUsesMana.sql b/db/.archive/224702/00-aclUsesMana.sql deleted file mode 100644 index 5bb7178dd..000000000 --- a/db/.archive/224702/00-aclUsesMana.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Sale', 'usesMana', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/.archive/224702/00-defaultPayDem_sameAs_production.sql b/db/.archive/224702/00-defaultPayDem_sameAs_production.sql deleted file mode 100644 index 294247338..000000000 --- a/db/.archive/224702/00-defaultPayDem_sameAs_production.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `vn`.`payDem` (id,payDem) - VALUES (7,'0'); diff --git a/db/.archive/224702/00-invoiceInPdf.sql b/db/.archive/224702/00-invoiceInPdf.sql deleted file mode 100644 index bce256c05..000000000 --- a/db/.archive/224702/00-invoiceInPdf.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('InvoiceIn', 'invoiceInPdf', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('InvoiceIn', 'invoiceInEmail', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/.archive/224702/00-newSupplier_ACL.sql b/db/.archive/224702/00-newSupplier_ACL.sql deleted file mode 100644 index c88f3de3f..000000000 --- a/db/.archive/224702/00-newSupplier_ACL.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) - VALUES ('Supplier','newSupplier','WRITE','administrative'); diff --git a/db/.archive/224702/00-notificationTables.sql b/db/.archive/224702/00-notificationTables.sql deleted file mode 100644 index 2db7d9874..000000000 --- a/db/.archive/224702/00-notificationTables.sql +++ /dev/null @@ -1,63 +0,0 @@ -USE util; - -CREATE TABLE notification( - id INT PRIMARY KEY, - `name` VARCHAR(255) UNIQUE, - `description` VARCHAR(255) -); - -CREATE TABLE notificationAcl( - notificationFk INT, - roleFk INT(10) unsigned, - PRIMARY KEY(notificationFk, roleFk) -); - -ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_ibfk_2` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role`(`id`) - ON DELETE RESTRICT - ON UPDATE CASCADE; - -CREATE TABLE notificationSubscription( - notificationFk INT, - userFk INT(10) unsigned, - PRIMARY KEY(notificationFk, userFk) -); - -ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -CREATE TABLE notificationQueue( - id INT PRIMARY KEY AUTO_INCREMENT, - notificationFk VARCHAR(255), - params JSON, - authorFk INT(10) unsigned NULL, - `status` ENUM('pending', 'sent', 'error') NOT NULL DEFAULT 'pending', - created DATETIME DEFAULT CURRENT_TIMESTAMP, - INDEX(notificationFk), - INDEX(authorFk), - INDEX(status) -); - -ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `nnotificationQueue_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification` (`name`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_ibfk_2` FOREIGN KEY (`authorFk`) REFERENCES `account`.`user`(`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -CREATE TABLE notificationConfig( - id INT PRIMARY KEY AUTO_INCREMENT, - cleanDays MEDIUMINT -); - -INSERT INTO notificationConfig - SET cleanDays = 90; diff --git a/db/.archive/224702/00-payMethodFk_Allow_Null.sql b/db/.archive/224702/00-payMethodFk_Allow_Null.sql deleted file mode 100644 index 6d9931d3c..000000000 --- a/db/.archive/224702/00-payMethodFk_Allow_Null.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`supplier` MODIFY COLUMN payMethodFk tinyint(3) unsigned NULL; \ No newline at end of file diff --git a/db/.archive/224702/00-supplierActivityFk_Allow_Null.sql b/db/.archive/224702/00-supplierActivityFk_Allow_Null.sql deleted file mode 100644 index 62aac0556..000000000 --- a/db/.archive/224702/00-supplierActivityFk_Allow_Null.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`supplier` MODIFY COLUMN supplierActivityFk varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/.archive/224801/00-ACL.sql b/db/.archive/224801/00-ACL.sql deleted file mode 100644 index 0b726538c..000000000 --- a/db/.archive/224801/00-ACL.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) -VALUES - ('ClaimRma', '*', 'READ', 'ALLOW', 'ROLE', 'claimManager'), - ('ClaimRma', '*', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'); - diff --git a/db/.archive/224801/00-claim.sql b/db/.archive/224801/00-claim.sql deleted file mode 100644 index 0b9879878..000000000 --- a/db/.archive/224801/00-claim.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`claim` ADD rma varchar(100) NULL ; \ No newline at end of file diff --git a/db/.archive/224801/00-claimRma.sql b/db/.archive/224801/00-claimRma.sql deleted file mode 100644 index 91e1ebaba..000000000 --- a/db/.archive/224801/00-claimRma.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `vn`.`claimRma` ( - id INT UNSIGNED auto_increment NOT NULL PRIMARY KEY, - code varchar(100) NOT NULL, - created timestamp DEFAULT current_timestamp() NOT NULL, - workerFk INTEGER UNSIGNED NOT NULL -) -ENGINE=InnoDB; diff --git a/db/.archive/224901/00-aclNotification.sql b/db/.archive/224901/00-aclNotification.sql deleted file mode 100644 index 51d6b2471..000000000 --- a/db/.archive/224901/00-aclNotification.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Notification', '*', 'WRITE', 'ALLOW', 'ROLE', 'developer'); diff --git a/db/.archive/224901/00-packingSiteConfig.sql b/db/.archive/224901/00-packingSiteConfig.sql deleted file mode 100644 index 945b5a54c..000000000 --- a/db/.archive/224901/00-packingSiteConfig.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `vn`.`packingSiteConfig` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `shinobiUrl` varchar(255) NOT NULL, - `shinobiToken` varchar(255) NOT NULL, - `shinobiGroupKey` varchar(255) NOT NULL, - `avgBoxingTime` INT(3) NULL, - PRIMARY KEY (`id`) - ); - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Boxing', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/224901/00-packingSiteUpdate.sql b/db/.archive/224901/00-packingSiteUpdate.sql deleted file mode 100644 index 14313fd52..000000000 --- a/db/.archive/224901/00-packingSiteUpdate.sql +++ /dev/null @@ -1,56 +0,0 @@ -ALTER TABLE `vn`.`packingSite` ADD monitorId varchar(255) NULL; - -UPDATE `vn`.`packingSite` - SET monitorId = 'VbiUcajdaT' - WHERE code = 'h1'; -UPDATE `vn`.`packingSite` - SET monitorId = 'qKMPn9aaVe' - WHERE code = 'h2'; -UPDATE `vn`.`packingSite` - SET monitorId = '3CtdIAGPAv' - WHERE code = 'h3'; -UPDATE `vn`.`packingSite` - SET monitorId = 'Xme2hiqz1f' - WHERE code = 'h4'; -UPDATE `vn`.`packingSite` - SET monitorId = 'aulxefgfJU' - WHERE code = 'h5'; -UPDATE `vn`.`packingSite` - SET monitorId = '6Ou0D1bhBw' - WHERE code = 'h6'; -UPDATE `vn`.`packingSite` - SET monitorId = 'eVUvnE6pNw' - WHERE code = 'h7'; -UPDATE `vn`.`packingSite` - SET monitorId = '0wsmSvqmrs' - WHERE code = 'h8'; -UPDATE `vn`.`packingSite` - SET monitorId = 'r2l2RyyF4I' - WHERE code = 'h9'; -UPDATE `vn`.`packingSite` - SET monitorId = 'EdjHLIiDVD' - WHERE code = 'h10'; -UPDATE `vn`.`packingSite` - SET monitorId = 'czC45kmwqI' - WHERE code = 'h11'; -UPDATE `vn`.`packingSite` - SET monitorId = 'PNsmxPaCwQ' - WHERE code = 'h12'; -UPDATE `vn`.`packingSite` - SET monitorId = 'agVssO0FDC' - WHERE code = 'h13'; -UPDATE `vn`.`packingSite` - SET monitorId = 'f2SPNENHPo' - WHERE code = 'h14'; -UPDATE `vn`.`packingSite` - SET monitorId = '6UR7gUZxks' - WHERE code = 'h15'; -UPDATE `vn`.`packingSite` - SET monitorId = 'bOB0f8WZ2V' - WHERE code = 'h16'; -UPDATE `vn`.`packingSite` - SET monitorId = 'MIR1nXaL0n' - WHERE code = 'h17'; -UPDATE `vn`.`packingSite` - SET monitorId = '0Oj9SgGTXR' - WHERE code = 'h18'; diff --git a/db/.archive/224901/00-salix_url.sql b/db/.archive/224901/00-salix_url.sql deleted file mode 100644 index ea5c3b606..000000000 --- a/db/.archive/224901/00-salix_url.sql +++ /dev/null @@ -1,33 +0,0 @@ -CREATE TABLE `salix`.`url` ( - `appName` varchar(100) NOT NULL, - `environment` varchar(100) NOT NULL, - `url` varchar(255) NOT NULL, - PRIMARY KEY (`appName`,`environment`) -); - -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('salix', 'production', 'https://salix.verdnatura.es/#!/'); -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('salix', 'test', 'https://test-salix.verdnatura.es/#!/'); -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('salix', 'dev', 'http://localhost:5000/#!/'); -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('lilium', 'production', 'https://lilium.verdnatura.es/#/'); -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('lilium', 'test', 'https://test-lilium.verdnatura.es/#/'); -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('lilium', 'dev', 'http://localhost:8080/#/'); - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Url', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Url', '*', 'WRITE', 'ALLOW', 'ROLE', 'it'); diff --git a/db/.archive/224902/00-aclUserPassword.sql b/db/.archive/224902/00-aclUserPassword.sql deleted file mode 100644 index b92b54c28..000000000 --- a/db/.archive/224902/00-aclUserPassword.sql +++ /dev/null @@ -1,2 +0,0 @@ -DELETE FROM `salix`.`ACL` - WHERE model = 'UserPassword'; diff --git a/db/.archive/224902/00-deletePickupContact.sql b/db/.archive/224902/00-deletePickupContact.sql deleted file mode 100644 index 6bfa662c5..000000000 --- a/db/.archive/224902/00-deletePickupContact.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`claimConfig` DROP COLUMN `pickupContact`; diff --git a/db/.archive/224902/00-itemShelvingACL.sql b/db/.archive/224902/00-itemShelvingACL.sql deleted file mode 100644 index fc32fe1ed..000000000 --- a/db/.archive/224902/00-itemShelvingACL.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) -VALUES - ('ItemShelving', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('ItemShelving', '*', 'WRITE', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/db/.archive/224902/00-itemShelvingPlacementSupplyStockACL.sql b/db/.archive/224902/00-itemShelvingPlacementSupplyStockACL.sql deleted file mode 100644 index 25eac8d51..000000000 --- a/db/.archive/224902/00-itemShelvingPlacementSupplyStockACL.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) -VALUES - ('ItemShelvingPlacementSupplyStock', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); - diff --git a/db/.archive/224902/00-workerTimeControlMail.sql b/db/.archive/224902/00-workerTimeControlMail.sql deleted file mode 100644 index e3d169a83..000000000 --- a/db/.archive/224902/00-workerTimeControlMail.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`workerTimeControlMail` CHANGE emailResponse reason text CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/.archive/224902/00-zone_getPostalCode.sql b/db/.archive/224902/00-zone_getPostalCode.sql deleted file mode 100644 index 58a281cb2..000000000 --- a/db/.archive/224902/00-zone_getPostalCode.sql +++ /dev/null @@ -1,54 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`zone_getPostalCode`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getPostalCode`(vSelf INT) -BEGIN -/** - * Devuelve los códigos postales incluidos en una zona - */ - DECLARE vGeoFk INT DEFAULT NULL; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes; - CREATE TEMPORARY TABLE tmp.zoneNodes ( - geoFk INT, - name VARCHAR(100), - parentFk INT, - sons INT, - isChecked BOOL DEFAULT 0, - zoneFk INT, - PRIMARY KEY zoneNodesPk (zoneFk, geoFk), - INDEX(geoFk)) - ENGINE = MEMORY; - - CALL zone_getLeaves2(vSelf, NULL , NULL); - - UPDATE tmp.zoneNodes zn - SET isChecked = 0 - WHERE parentFk IS NULL; - - myLoop: LOOP - SET vGeoFk = NULL; - SELECT geoFk INTO vGeoFk - FROM tmp.zoneNodes zn - WHERE NOT isChecked - LIMIT 1; - - CALL zone_getLeaves2(vSelf, vGeoFk, NULL); - UPDATE tmp.zoneNodes - SET isChecked = TRUE - WHERE geoFk = vGeoFk; - - IF vGeoFk IS NULL THEN - LEAVE myLoop; - END IF; - END LOOP; - - DELETE FROM tmp.zoneNodes - WHERE sons > 0; - - SELECT zn.geoFk, zn.name - FROM tmp.zoneNodes zn - JOIN zone z ON z.id = zn.zoneFk; -END$$ -DELIMITER ; diff --git a/db/.archive/224903/00-ACL_notification_InvoiceE.sql b/db/.archive/224903/00-ACL_notification_InvoiceE.sql deleted file mode 100644 index 660efc41e..000000000 --- a/db/.archive/224903/00-ACL_notification_InvoiceE.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('NotificationQueue','*','*','ALLOW','ROLE','employee'); diff --git a/db/.archive/224903/00-aclInvoiceOut.sql b/db/.archive/224903/00-aclInvoiceOut.sql deleted file mode 100644 index 7715045b5..000000000 --- a/db/.archive/224903/00-aclInvoiceOut.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('InvoiceOut', 'clientsToInvoice', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('InvoiceOut', 'invoiceClient', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); \ No newline at end of file diff --git a/db/.archive/224903/00-alter_expedition_itemFk.sql b/db/.archive/224903/00-alter_expedition_itemFk.sql deleted file mode 100644 index d2849481b..000000000 --- a/db/.archive/224903/00-alter_expedition_itemFk.sql +++ /dev/null @@ -1 +0,0 @@ -Alter table `vn`.`expedition` RENAME COLUMN itemFk TO itemFk__; \ No newline at end of file diff --git a/db/.archive/224903/00-clientHasInvoiceElectronic.sql b/db/.archive/224903/00-clientHasInvoiceElectronic.sql deleted file mode 100644 index 21f68c9ca..000000000 --- a/db/.archive/224903/00-clientHasInvoiceElectronic.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE - `vn`.`client` -ADD - COLUMN `hasElectronicInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Registro de facturas mediante FACe' -AFTER - `hasInvoiceSimplified`; - --- sería más correcto hasElectronicInvoice pero ya existe un campo hasInvoiceSimplified \ No newline at end of file diff --git a/db/.archive/224903/00-collection_missingTrash.sql b/db/.archive/224903/00-collection_missingTrash.sql deleted file mode 100644 index d4467c699..000000000 --- a/db/.archive/224903/00-collection_missingTrash.sql +++ /dev/null @@ -1 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`collection_missingTrash`; diff --git a/db/.archive/224903/00-deleteInvoiceOutQueue.sql b/db/.archive/224903/00-deleteInvoiceOutQueue.sql deleted file mode 100644 index 87a3059a0..000000000 --- a/db/.archive/224903/00-deleteInvoiceOutQueue.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE `vn`.`invoiceOutQueue`; \ No newline at end of file diff --git a/db/.archive/224903/00-editTrackedACL.sql b/db/.archive/224903/00-editTrackedACL.sql deleted file mode 100644 index e768fb7c7..000000000 --- a/db/.archive/224903/00-editTrackedACL.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Sale', 'editTracked', 'WRITE', 'ALLOW', 'ROLE', 'production'), - ('Sale', 'editFloramondo', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'); diff --git a/db/.archive/224903/00-greuge.sql b/db/.archive/224903/00-greuge.sql deleted file mode 100644 index ec4bf3146..000000000 --- a/db/.archive/224903/00-greuge.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`greuge` CHANGE `userFK` `userFk` int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/.archive/224903/00-isCompensationACL.sql b/db/.archive/224903/00-isCompensationACL.sql deleted file mode 100644 index ac01758b0..000000000 --- a/db/.archive/224903/00-isCompensationACL.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Receipt', 'balanceCompensationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Receipt', 'balanceCompensationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/224903/00-osTicketConfig.sql b/db/.archive/224903/00-osTicketConfig.sql deleted file mode 100644 index 10a58b6c8..000000000 --- a/db/.archive/224903/00-osTicketConfig.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE `vn`.`osTicketConfig` DROP COLUMN `action`; -ALTER TABLE `vn`.`osTicketConfig` ADD responseType varchar(100) NULL; -ALTER TABLE `vn`.`osTicketConfig` ADD fromEmailId INT NULL; -ALTER TABLE `vn`.`osTicketConfig` ADD replyTo varchar(100) NULL; - -UPDATE `vn`.`osTicketConfig` - SET responseType='reply', fromEmailId=5, replyTo='all' -WHERE id=0; \ No newline at end of file diff --git a/db/.archive/224903/00-ticket_canMerge.sql b/db/.archive/224903/00-ticket_canMerge.sql deleted file mode 100644 index 843237b64..000000000 --- a/db/.archive/224903/00-ticket_canMerge.sql +++ /dev/null @@ -1,14 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticket_canMerge`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canMerge`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) -BEGIN - CALL vn.ticket_canbePostponed(vDated,TIMESTAMPADD(DAY, vScopeDays, vDated),vLitersMax,vLinesMax,vWarehouseFk); -END $$ -DELIMITER ; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) -VALUES - ('Ticket', 'getTicketsFuture', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'merge', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/224903/00-ticket_canbePostponed.sql b/db/.archive/224903/00-ticket_canbePostponed.sql deleted file mode 100644 index c691fa4bd..000000000 --- a/db/.archive/224903/00-ticket_canbePostponed.sql +++ /dev/null @@ -1,79 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticket_canbePostponed`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) -BEGIN -/** - * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * - * @param vOriginDated Fecha en cuestión - * @param vFutureDated Fecha en el futuro a sondear - * @param vLitersMax Volumen máximo de los tickets a catapultar - * @param vLinesMax Número máximo de lineas de los tickets a catapultar - * @param vWarehouseFk Identificador de vn.warehouse - */ - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT sv.ticketFk id, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, - st.name state, - sub2.id ticketFuture, - t.landed originETD, - sub2.landed destETD, - sub2.iptd tfIpt, - sub2.state tfState, - t.clientFk, - t.warehouseFk, - ts.alertLevel, - t.shipped, - sub2.shipped tfShipped, - t.workerFk, - st.code code, - sub2.code tfCode - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticket t ON t.id = sv.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.country c ON c.id = p.countryFk - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.alertLevel al ON al.id = ts.alertLevel - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN ( - SELECT * - FROM ( - SELECT - t.addressFk , - t.id, - t.landed, - t.shipped, - st.name state, - st.code code, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd - FROM vn.ticket t - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - WHERE t.shipped BETWEEN vFutureDated - AND util.dayend(vFutureDated) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) sub - GROUP BY sub.addressFk - ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id - WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated) - AND t.warehouseFk = vWarehouseFk - AND al.code = 'FREE' - AND tp.ticketFk IS NULL - GROUP BY sv.ticketFk - HAVING liters <= IFNULL(vLitersMax, 9999) AND `lines` <= IFNULL(vLinesMax, 9999) AND ticketFuture; -END$$ -DELIMITER ; - diff --git a/db/.archive/224903/00-timeBusiness_calculate.sql b/db/.archive/224903/00-timeBusiness_calculate.sql deleted file mode 100644 index 6345475dd..000000000 --- a/db/.archive/224903/00-timeBusiness_calculate.sql +++ /dev/null @@ -1,88 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`timeBusiness_calculate`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) -BEGIN -/** - * Horas que debe trabajar un empleado según contrato y día. - * @param vDatedFrom workerTimeControl - * @param vDatedTo workerTimeControl - * @table tmp.user(userFk) - * @return tmp.timeBusinessCalculate - */ - DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate; - CREATE TEMPORARY TABLE tmp.timeBusinessCalculate - (INDEX (departmentFk)) - SELECT dated, - businessFk, - userFk, - departmentFk, - hourStart, - hourEnd, - timeTable, - timeWorkSeconds, - SEC_TO_TIME(timeWorkSeconds) timeWorkSexagesimal, - timeWorkSeconds / 3600 timeWorkDecimal, - timeWorkSeconds timeBusinessSeconds, - SEC_TO_TIME(timeWorkSeconds) timeBusinessSexagesimal, - timeWorkSeconds / 3600 timeBusinessDecimal, - name type, - permissionRate, - hoursWeek, - discountRate, - isAllowedToWork - FROM(SELECT t.dated, - b.id businessFk, - w.id, - b.departmentFk, - IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,5) ORDER BY j.start ASC SEPARATOR ' - ')) hourStart , - IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) hourEnd, - IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,5), " - ", LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) timeTable, - IF(j.start = NULL, 0, IFNULL(SUM(TIME_TO_SEC(j.end)) - SUM(TIME_TO_SEC(j.start)), 0)) timeWorkSeconds, - at2.name, - at2.permissionRate, - at2.discountRate, - cl.hours_week hoursWeek, - at2.isAllowedToWork - FROM time t - LEFT JOIN business b ON t.dated BETWEEN b.started AND IFNULL(b.ended, vDatedTo) - LEFT JOIN worker w ON w.id = b.workerFk - JOIN tmp.`user` u ON u.userFK = w.id - LEFT JOIN workCenter wc ON wc.id = b.workcenterFK - LEFT JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = b.calendarTypeFk - LEFT JOIN postgresql.journey j ON j.business_id = b.id AND j.day_id = WEEKDAY(t.dated) + 1 - LEFT JOIN postgresql.calendar_employee ce ON ce.businessFk = b.id AND ce.date = t.dated - LEFT JOIN absenceType at2 ON at2.id = ce.calendar_state_id - WHERE t.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.id, t.dated - )sub; - - UPDATE tmp.timeBusinessCalculate t - LEFT JOIN postgresql.journey j ON j.business_id = t.businessFk - SET t.timeWorkSeconds = t.hoursWeek / 5 * 3600, - t.timeWorkSexagesimal = SEC_TO_TIME( t.hoursWeek / 5 * 3600), - t.timeWorkDecimal = t.hoursWeek / 5, - t.timeBusinessSeconds = t.hoursWeek / 5 * 3600, - t.timeBusinessSexagesimal = SEC_TO_TIME( t.hoursWeek / 5 * 3600), - t.timeBusinessDecimal = t.hoursWeek / 5 - WHERE DAYOFWEEK(t.dated) IN(2,3,4,5,6) AND j.journey_id IS NULL ; - - UPDATE tmp.timeBusinessCalculate t - SET t.timeWorkSeconds = t.timeWorkSeconds - (t.timeWorkSeconds * permissionRate) , - t.timeWorkSexagesimal = SEC_TO_TIME ((t.timeWorkDecimal - (t.timeWorkDecimal * permissionRate)) * 3600), - t.timeWorkDecimal = t.timeWorkDecimal - (t.timeWorkDecimal * permissionRate) - WHERE permissionRate <> 0; - - UPDATE tmp.timeBusinessCalculate t - JOIN calendarHolidays ch ON ch.dated = t.dated - JOIN business b ON b.id = t.businessFk - AND b.workcenterFk = ch.workcenterFk - SET t.timeWorkSeconds = 0, - t.timeWorkSexagesimal = 0, - t.timeWorkDecimal = 0, - t.permissionrate = 1, - t.type = 'Festivo' - WHERE t.type IS NULL; -END$$ -DELIMITER ; diff --git a/db/.archive/224903/01-updateClientHasInvoiceElectronic.sql b/db/.archive/224903/01-updateClientHasInvoiceElectronic.sql deleted file mode 100644 index af1c8ca9a..000000000 --- a/db/.archive/224903/01-updateClientHasInvoiceElectronic.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE - `vn`.`client` -SET - hasElectronicInvoice = TRUE -WHERE - businessTypeFk = 'officialOrganism'; \ No newline at end of file diff --git a/db/.archive/225001/00-aclMdbApp.sql b/db/.archive/225001/00-aclMdbApp.sql deleted file mode 100644 index b5b60546c..000000000 --- a/db/.archive/225001/00-aclMdbApp.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('MdbApp', 'lock', 'WRITE', 'ALLOW', 'ROLE', 'developer'), - ('MdbApp', 'unlock', 'WRITE', 'ALLOW', 'ROLE', 'developer'); diff --git a/db/.archive/225001/00-updateCollection.sql b/db/.archive/225001/00-updateCollection.sql deleted file mode 100644 index 6d4ec4307..000000000 --- a/db/.archive/225001/00-updateCollection.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE `vn`.`collection` - SET sectorFk=1 - WHERE id=1; diff --git a/db/.archive/225201/00-ACL_saveSign.sql b/db/.archive/225201/00-ACL_saveSign.sql deleted file mode 100644 index 16f9931c4..000000000 --- a/db/.archive/225201/00-ACL_saveSign.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) VALUES ('Dms','saveSign','*','ALLOW','employee'); diff --git a/db/.archive/225201/00-aclTicketLog.sql b/db/.archive/225201/00-aclTicketLog.sql deleted file mode 100644 index edba17ab4..000000000 --- a/db/.archive/225201/00-aclTicketLog.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('TicketLog', 'getChanges', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/225201/00-entryDeleteRef.sql b/db/.archive/225201/00-entryDeleteRef.sql deleted file mode 100644 index 7e47eae63..000000000 --- a/db/.archive/225201/00-entryDeleteRef.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`entry` DROP COLUMN `ref`; diff --git a/db/.archive/225201/00-invoiceInConfig.sql b/db/.archive/225201/00-invoiceInConfig.sql deleted file mode 100644 index a27b59440..000000000 --- a/db/.archive/225201/00-invoiceInConfig.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `vn`.`invoiceInConfig` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `retentionRate` int(3) NOT NULL, - `retentionName` varchar(25) NOT NULL, - `sageWithholdingFk` smallint(6) NOT NULL, - PRIMARY KEY (`id`), - CONSTRAINT `invoiceInConfig_sageWithholdingFk` FOREIGN KEY (`sageWithholdingFk`) REFERENCES `sage`.`TiposRetencion`(`CodigoRetencion`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`) - VALUES - (1, -2, 'Retención 2%', 2); diff --git a/db/.archive/225201/00-invoiceOut_new.sql b/db/.archive/225201/00-invoiceOut_new.sql deleted file mode 100644 index c0f6bc697..000000000 --- a/db/.archive/225201/00-invoiceOut_new.sql +++ /dev/null @@ -1,225 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_new`; -DELIMITER $$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATETIME, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN -/** - * Creación de facturas emitidas. - * requiere previamente tabla tmp.ticketToInvoice(id). - * - * @param vSerial serie a la cual se hace la factura - * @param vInvoiceDate fecha de la factura - * @param vTaxArea tipo de iva en relacion a la empresa y al cliente - * @param vNewInvoiceId id de la factura que se acaba de generar - * @return vNewInvoiceId - */ - DECLARE vSpainCountryCode INT DEFAULT 1; - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompany INT; - DECLARE vSupplier INT; - DECLARE vClient INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInId INT; - DECLARE vIsInterCompany BOOL; - - SET vInvoiceDate = IFNULL(vInvoiceDate,CURDATE()); - - SELECT t.clientFk, t.companyFk - INTO vClient, vCompany - FROM tmp.ticketToInvoice tt - JOIN ticket t ON t.id = tt.id - LIMIT 1; - - -- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM tmp.ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN supplier su ON su.id = t.companyFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - WHERE YEAR(t.shipped) < 2001 - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE - OR itc.id IS NULL; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id - INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice - FROM tmp.ticketToInvoice t - LEFT JOIN sale s ON s.ticketFk = t.id - LEFT JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut - ( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - siiTypeInvoiceOutFk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClient, - getDueDate(vInvoiceDate, dueDay), - vCompany, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClient; - - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - UPDATE ticket t - JOIN tmp.ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticket - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); - - INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador) - SELECT * FROM tmp.updateInter; - - INSERT INTO ticketLog (action, userFk, originFk, description) - SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef) - FROM tmp.ticketToInvoice ti; - - CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) AS total - FROM invoiceOutExpense - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) AS total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT ios.isCEE INTO vIsInterCompany - FROM vn.ticket t - JOIN vn.invoiceOut io ON io.`ref` = t.refFk - JOIN vn.invoiceOutSerial ios ON ios.code = io.serial - WHERE t.refFk = vNewRef - LIMIT 1; - - IF (vIsInterCompany) THEN - - SELECT vCompany INTO vSupplier; - SELECT id INTO vCompany FROM company WHERE clientFk = vClient; - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vSupplier, vNewRef, vInvoiceDate, vCompany; - - SET vNewInvoiceInId = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInId, @vTaxableBaseServices, sub.expenseFk, sub.taxTypeSageFk , sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, i.expenseFk, i.taxTypeSageFk , i.transactionTypeSageFk, @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInId, SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, @vTaxableBaseServices, 0) taxableBase, i.expenseFk, i.taxTypeSageFk , i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL invoiceInDueDay_calculate(vNewInvoiceInId); - - INSERT INTO invoiceInIntrastat ( - invoiceInFk, - intrastatFk, - amount, - stems, - countryFk, - net) - SELECT - vNewInvoiceInId invoiceInFk, - i.intrastatFk, - CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100 )) AS DECIMAL(10,2)) subtotal, - CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL(10,2)) stems, - su.countryFk, - CAST(SUM(IFNULL(i.stems, 1) - * s.quantity - * IF(ic.grams, ic.grams, i.weightByPiece) / 1000) AS DECIMAL(10,2)) netKg - FROM sale s - JOIN ticket t ON s.ticketFk = t.id - JOIN supplier su ON su.id = t.companyFk - JOIN item i ON i.id = s.itemFk - JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - JOIN intrastat ir ON ir.id = i.intrastatFk - WHERE t.refFk = vNewRef; - - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - - END IF; - - END IF; - - DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`; -END$$ -DELIMITER ; diff --git a/db/.archive/225201/00-mdbApp.sql b/db/.archive/225201/00-mdbApp.sql deleted file mode 100644 index 3202e3f08..000000000 --- a/db/.archive/225201/00-mdbApp.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `vn`.`mdbApp` ( - `app` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, - `baselineBranchFk` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `userFk` int(10) unsigned DEFAULT NULL, - `locked` datetime DEFAULT NULL, - PRIMARY KEY (`app`), - KEY `mdbApp_FK` (`userFk`), - KEY `mdbApp_FK_1` (`baselineBranchFk`), - CONSTRAINT `mdbApp_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `mdbApp_FK_1` FOREIGN KEY (`baselineBranchFk`) REFERENCES `mdbBranch` (`name`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci diff --git a/db/.archive/225201/00-notification_send.sql b/db/.archive/225201/00-notification_send.sql deleted file mode 100644 index a422cebac..000000000 --- a/db/.archive/225201/00-notification_send.sql +++ /dev/null @@ -1,24 +0,0 @@ -DROP FUNCTION IF EXISTS `util`.`notification_send`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`notification_send`(vNotificationName VARCHAR(255), vParams TEXT, vAuthorFk INT) RETURNS int(11) - MODIFIES SQL DATA -BEGIN -/** - * Sends a notification. - * - * @param vNotificationName The notification name - * @param vParams The notification parameters formatted as JSON - * @param vAuthorFk The notification author or %NULL if there is no author - * @return The notification id - */ - - INSERT INTO notificationQueue - SET notificationFk = vNotificationName, - params = vParams, - authorFk = vAuthorFk; - - RETURN LAST_INSERT_ID(); -END$$ -DELIMITER ; diff --git a/db/.archive/225201/00-ticketSms.sql b/db/.archive/225201/00-ticketSms.sql deleted file mode 100644 index f454f99b1..000000000 --- a/db/.archive/225201/00-ticketSms.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE `vn`.`ticketSms` ( - `smsFk` mediumint(8) unsigned NOT NULL, - `ticketFk` int(11) DEFAULT NULL, - PRIMARY KEY (`smsFk`), - KEY `ticketSms_FK_1` (`ticketFk`), - CONSTRAINT `ticketSms_FK` FOREIGN KEY (`smsFk`) REFERENCES `sms` (`id`) ON UPDATE CASCADE, - CONSTRAINT `ticketSms_FK_1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci diff --git a/db/.archive/225201/00-ticket_canAdvance.sql b/db/.archive/225201/00-ticket_canAdvance.sql deleted file mode 100644 index acc4dcc4a..000000000 --- a/db/.archive/225201/00-ticket_canAdvance.sql +++ /dev/null @@ -1,104 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticket_canAdvance`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM vn.config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM vn.itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM vn.itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM vn.itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT s.ticketFk futureId, - t2.ticketFk id, - sum((s.quantity <= IFNULL(st.amount,0))) hasStock, - count(DISTINCT s.id) saleCount, - t2.state, - t2.stateCode, - st.name futureState, - st.code futureStateCode, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - t2.ipt, - t.workerFk, - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, - t2.shipped, - t.shipped futureShipped, - t2.totalWithVat, - t.totalWithVat futureTotalWithVat - FROM vn.ticket t - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.saleVolume sv ON t.id = sv.ticketFk - JOIN (SELECT - t2.id ticketFk, - t2.addressFk, - st.name state, - st.code stateCode, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t2.shipped, - t2.totalWithVat - FROM vn.ticket t2 - JOIN vn.sale s ON s.ticketFk = t2.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticketState ts ON ts.ticketFk = t2.id - JOIN vn.state st ON st.id = ts.stateFk - LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t2.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t2.warehouseFk = vWarehouseFk - GROUP BY t2.id) t2 ON t2.addressFk = t.addressFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = s.itemFk - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id; - - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) -VALUES - ('Ticket', 'getTicketsAdvance', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/225201/00-ticket_canbePostponed.sql b/db/.archive/225201/00-ticket_canbePostponed.sql deleted file mode 100644 index 572824b4b..000000000 --- a/db/.archive/225201/00-ticket_canbePostponed.sql +++ /dev/null @@ -1,73 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticket_canbePostponed`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * - * @param vOriginDated Fecha en cuestión - * @param vFutureDated Fecha en el futuro a sondear - * @param vWarehouseFk Identificador de vn.warehouse - */ - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT sv.ticketFk id, - sub2.id futureId, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, - st.name state, - sub2.iptd futureIpt, - sub2.state futureState, - t.clientFk, - t.warehouseFk, - ts.alertLevel, - t.shipped, - sub2.shipped futureShipped, - t.workerFk, - st.code stateCode, - sub2.code futureStateCode - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticket t ON t.id = sv.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.country c ON c.id = p.countryFk - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.alertLevel al ON al.id = ts.alertLevel - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN ( - SELECT * - FROM ( - SELECT - t.addressFk, - t.id, - t.shipped, - st.name state, - st.code code, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd - FROM vn.ticket t - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - WHERE t.shipped BETWEEN vFutureDated - AND util.dayend(vFutureDated) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) sub - GROUP BY sub.addressFk - ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id - WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated) - AND t.warehouseFk = vWarehouseFk - AND al.code = 'FREE' - AND tp.ticketFk IS NULL - GROUP BY sv.ticketFk - HAVING futureId; -END$$ -DELIMITER ; diff --git a/db/.archive/225201/00-ticket_split_merge.sql b/db/.archive/225201/00-ticket_split_merge.sql deleted file mode 100644 index a1a6579e6..000000000 --- a/db/.archive/225201/00-ticket_split_merge.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP PROCEDURE IF EXISTS `ticket_split`; -DROP PROCEDURE IF EXISTS `ticket_merge`; diff --git a/db/.archive/225201/00-utilNotification.sql b/db/.archive/225201/00-utilNotification.sql deleted file mode 100644 index 74f0de5e2..000000000 --- a/db/.archive/225201/00-utilNotification.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `util`.`notification` (id, name, description) VALUES(3, 'book-entries-imported-incorrectly', 'accounting entries exported incorrectly'); -INSERT INTO `util`.`notificationAcl` (notificationFk, roleFk) VALUES(3, 5); -INSERT IGNORE INTO `util`.`notificationSubscription` (notificationFk, userFk) VALUES(3, 19663); - diff --git a/db/.archive/225201/01-create_stateI18n.sql b/db/.archive/225201/01-create_stateI18n.sql deleted file mode 100644 index 799360b1e..000000000 --- a/db/.archive/225201/01-create_stateI18n.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `vn`.`stateI18n` ( - `stateFk` tinyint(3) unsigned NOT NULL, - `lang` char(2) NOT NULL, - `name` varchar(255) NOT NULL, - PRIMARY KEY (`stateFk`, `lang`), - CONSTRAINT `stateI18n_state_id` FOREIGN KEY (`stateFk`) REFERENCES `vn`.`state` (`id`) -) ENGINE = InnoDB DEFAULT CHARSET = utf8; diff --git a/db/.archive/225201/01-modules.sql b/db/.archive/225201/01-modules.sql deleted file mode 100644 index 243d2d016..000000000 --- a/db/.archive/225201/01-modules.sql +++ /dev/null @@ -1,60 +0,0 @@ -UPDATE salix.module t -SET t.code = 'supplier' -WHERE t.code LIKE 'Suppliers' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'travel' -WHERE t.code LIKE 'Travels' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'ticket' -WHERE t.code LIKE 'Tickets' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'zone' -WHERE t.code LIKE 'Zones' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'monitor' -WHERE t.code LIKE 'Monitors' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'entry' -WHERE t.code LIKE 'Entries' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'invoiceIn' -WHERE t.code LIKE 'Invoices in' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'customer' -WHERE t.code LIKE 'Clients' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'route' -WHERE t.code LIKE 'Routes' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'item' -WHERE t.code LIKE 'Items' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'claim' -WHERE t.code LIKE 'Claims' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'account' -WHERE t.code LIKE 'Users' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'invoiceOut' -WHERE t.code LIKE 'Invoices out' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'order' -WHERE t.code LIKE 'Orders' ESCAPE '#'; - -UPDATE salix.module t -SET t.code = 'worker' -WHERE t.code LIKE 'Workers' ESCAPE '#'; - diff --git a/db/.archive/225201/02-insert_stateI18n.sql b/db/.archive/225201/02-insert_stateI18n.sql deleted file mode 100644 index 7df36d662..000000000 --- a/db/.archive/225201/02-insert_stateI18n.sql +++ /dev/null @@ -1,73 +0,0 @@ -INSERT INTO - `vn`.`stateI18n` (`stateFk`, `lang`, `name`) -VALUES - (1, 'en', 'Fix'), - (1, 'es', 'Arreglar'), - (2, 'en', 'Free'), - (2, 'es', 'Libre'), - (3, 'en', 'OK'), - (3, 'es', 'OK'), - (4, 'en', 'Printed'), - (4, 'es', 'Impreso'), - (5, 'en', 'Preparation'), - (5, 'es', 'Preparación'), - (6, 'en', 'In Review'), - (6, 'es', 'En Revisión'), - (7, 'en', 'Unfinished'), - (7, 'es', 'Sin Acabar'), - (8, 'en', 'Reviewed'), - (8, 'es', 'Revisado'), - (9, 'en', 'Fitting'), - (9, 'es', 'Encajando'), - (10, 'en', 'Fitted'), - (10, 'es', 'Encajado'), - (11, 'en', 'Billed'), - (11, 'es', 'Facturado'), - (12, 'en', 'Blocked'), - (12, 'es', 'Bloqueado'), - (13, 'en', 'In Delivery'), - (13, 'es', 'En Reparto'), - (14, 'en', 'Prepared'), - (14, 'es', 'Preparado'), - (15, 'en', 'Pending Collection'), - (15, 'es', 'Pendiente de Recogida'), - (16, 'en', 'Delivered'), - (16, 'es', 'Entregado'), - (20, 'en', 'Assigned'), - (20, 'es', 'Asignado'), - (21, 'en', 'Returned'), - (21, 'es', 'Retornado'), - (22, 'en', 'Pending to extend'), - (22, 'es', 'Pendiente ampliar'), - (23, 'en', 'URGENT'), - (23, 'es', 'URGENTE'), - (24, 'en', 'Chained'), - (24, 'es', 'Encadenado'), - (25, 'en', 'Shipping'), - (25, 'es', 'Embarcando'), - (26, 'en', 'Preparation'), - (26, 'es', 'Preparación previa'), - (27, 'en', 'Assisted preparation'), - (27, 'es', 'Preparación asistida'), - (28, 'en', 'Preparation OK'), - (28, 'es', 'Previa OK'), - (29, 'en', 'Preparation Printed'), - (29, 'es', 'Previa Impreso'), - (30, 'en', 'Shipped'), - (30, 'es', 'Embarcado'), - (31, 'en', 'Stowaway printed'), - (31, 'es', 'Polizón Impreso'), - (32, 'en', 'Stowaway OK'), - (32, 'es', 'Polizón OK'), - (33, 'en', 'Auto_Printed'), - (33, 'es', 'Auto_Impreso'), - (34, 'en', 'Pending payment'), - (34, 'es', 'Pendiente de pago'), - (35, 'en', 'Half-Embedded'), - (35, 'es', 'Semi-Encajado'), - (36, 'en', 'Preparation Reviewing'), - (36, 'es', 'Previa Revisando'), - (37, 'en', 'Preparation Reviewed'), - (37, 'es', 'Previa Revisado'), - (38, 'en', 'Preparation Chamber'), - (38, 'es', 'Preparación Cámara'); \ No newline at end of file diff --git a/db/.archive/225201/02-starredModule.sql b/db/.archive/225201/02-starredModule.sql deleted file mode 100644 index 3ca67fce4..000000000 --- a/db/.archive/225201/02-starredModule.sql +++ /dev/null @@ -1,16 +0,0 @@ -UPDATE `vn`.starredModule SET moduleFk = 'customer' WHERE moduleFk = 'Clients'; -UPDATE `vn`.starredModule SET moduleFk = 'ticket' WHERE moduleFk = 'Tickets'; -UPDATE `vn`.starredModule SET moduleFk = 'route' WHERE moduleFk = 'Routes'; -UPDATE `vn`.starredModule SET moduleFk = 'zone' WHERE moduleFk = 'Zones'; -UPDATE `vn`.starredModule SET moduleFk = 'order' WHERE moduleFk = 'Orders'; -UPDATE `vn`.starredModule SET moduleFk = 'claim' WHERE moduleFk = 'Claims'; -UPDATE `vn`.starredModule SET moduleFk = 'item' WHERE moduleFk = 'Items'; -UPDATE `vn`.starredModule SET moduleFk = 'worker' WHERE moduleFk = 'Workers'; -UPDATE `vn`.starredModule SET moduleFk = 'entry' WHERE moduleFk = 'Entries'; -UPDATE `vn`.starredModule SET moduleFk = 'invoiceOut' WHERE moduleFk = 'Invoices out'; -UPDATE `vn`.starredModule SET moduleFk = 'invoiceIn' WHERE moduleFk = 'Invoices in'; -UPDATE `vn`.starredModule SET moduleFk = 'monitor' WHERE moduleFk = 'Monitors'; -UPDATE `vn`.starredModule SET moduleFk = 'user' WHERE moduleFk = 'Users'; -UPDATE `vn`.starredModule SET moduleFk = 'supplier' WHERE moduleFk = 'Suppliers'; -UPDATE `vn`.starredModule SET moduleFk = 'travel' WHERE moduleFk = 'Travels'; -UPDATE `vn`.starredModule SET moduleFk = 'shelving' WHERE moduleFk = 'Shelvings'; \ No newline at end of file diff --git a/db/.archive/225202/00-mdbApp.sql b/db/.archive/225202/00-mdbApp.sql deleted file mode 100644 index 50c595d71..000000000 --- a/db/.archive/225202/00-mdbApp.sql +++ /dev/null @@ -1,28 +0,0 @@ -ALTER TABLE `vn`.`mdbApp` DROP PRIMARY KEY; -ALTER TABLE `vn`.`mdbApp` ADD CONSTRAINT mdbApp_PK PRIMARY KEY (app,baselineBranchFk); - -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('com','master'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('enc','master'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('ent','master'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('eti','master'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('lab','master'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('tpv','master'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('com','dev'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('enc','dev'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('ent','dev'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('eti','dev'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('lab','dev'); -INSERT INTO `vn`.`mdbApp` (app,baselineBranchFk) - VALUES ('tpv','dev'); - diff --git a/db/.archive/225203/00-mdbApp.sql b/db/.archive/225203/00-mdbApp.sql deleted file mode 100644 index 32a21eb6b..000000000 --- a/db/.archive/225203/00-mdbApp.sql +++ /dev/null @@ -1,5 +0,0 @@ -UPDATE `vn`.`osTicketConfig` -SET oldStatus='1,6' -WHERE id=0; - - diff --git a/db/.archive/230201/00-ACL_ItemShelvingSale.sql b/db/.archive/230201/00-ACL_ItemShelvingSale.sql deleted file mode 100644 index 38b65f89a..000000000 --- a/db/.archive/230201/00-ACL_ItemShelvingSale.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES ('ItemShelvingSale','*','*','ALLOW','employee'); diff --git a/db/.archive/230201/00-SupplierUniqueKey.sql b/db/.archive/230201/00-SupplierUniqueKey.sql deleted file mode 100644 index 9c0d4a192..000000000 --- a/db/.archive/230201/00-SupplierUniqueKey.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`supplier` ADD UNIQUE (name, countryFk); diff --git a/db/.archive/230201/00-autoincrement_VnReport_VnPrinter.sql b/db/.archive/230201/00-autoincrement_VnReport_VnPrinter.sql deleted file mode 100644 index a28bf6e90..000000000 --- a/db/.archive/230201/00-autoincrement_VnReport_VnPrinter.sql +++ /dev/null @@ -1,4 +0,0 @@ -SET FOREIGN_KEY_CHECKS = 0; -ALTER TABLE `vn`.`report` MODIFY COLUMN id tinyint(3) unsigned NOT NULL AUTO_INCREMENT; -ALTER TABLE `vn`.`printer` MODIFY COLUMN id tinyint(3) unsigned NOT NULL AUTO_INCREMENT; -SET FOREIGN_KEY_CHECKS = 1; diff --git a/db/.archive/230201/00-borradoLogicoIPT.sql b/db/.archive/230201/00-borradoLogicoIPT.sql deleted file mode 100644 index ae7ecf0ca..000000000 --- a/db/.archive/230201/00-borradoLogicoIPT.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `vn`.`itemPackingType` ADD isActive BOOLEAN NOT NULL; -UPDATE `vn`.`itemPackingType` SET isActive = 0 WHERE code IN ('P', 'F'); -UPDATE `vn`.`itemPackingType` SET isActive = 1 WHERE code IN ('V', 'H'); diff --git a/db/.archive/230201/00-docuwareStore.sql b/db/.archive/230201/00-docuwareStore.sql deleted file mode 100644 index b20c2554f..000000000 --- a/db/.archive/230201/00-docuwareStore.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE OR REPLACE TABLE `vn`.`docuware` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `code` varchar(50) COLLATE utf8mb3_unicode_ci NOT NULL, - `fileCabinetName` varchar(50) COLLATE utf8mb3_unicode_ci NOT NULL, - `action` varchar(255) COLLATE utf8mb3_unicode_ci NOT NULL, - `dialogName` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, - `findById` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `vn`.`docuware` (`code`, `fileCabinetName`, `action`, `dialogName`, `findById`) - VALUES - ('deliveryNote', 'Albaranes cliente', 'find', 'find', 'N__ALBAR_N'), - ('deliveryNote', 'Albaranes cliente', 'store', 'Archivar', 'N__ALBAR_N'); - -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('Docuware','checkFile','READ','ALLOW','employee'), - ('Docuware','download','READ','ALLOW','salesPerson'), - ('Docuware','upload','WRITE','ALLOW','productionAssi'), - ('Docuware','deliveryNoteEmail','WRITE','ALLOW','salesPerson'); - -ALTER TABLE `vn`.`docuwareConfig` CHANGE token cookie varchar(1000) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; diff --git a/db/.archive/230201/00-validPriorities_ItemConfig.sql b/db/.archive/230201/00-validPriorities_ItemConfig.sql deleted file mode 100644 index 0b32d5de8..000000000 --- a/db/.archive/230201/00-validPriorities_ItemConfig.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `vn`.`itemConfig` ADD defaultTag INT DEFAULT 56 NOT NULL; -ALTER TABLE `vn`.`itemConfig` ADD CONSTRAINT itemConfig_FK FOREIGN KEY (defaultTag) REFERENCES vn.tag(id); -ALTER TABLE `vn`.`itemConfig` ADD validPriorities varchar(50) DEFAULT '[1,2,3]' NOT NULL; -ALTER TABLE `vn`.`itemConfig` ADD defaultPriority INT DEFAULT 2 NOT NULL; -ALTER TABLE `vn`.`item` MODIFY COLUMN relevancy tinyint(1) DEFAULT 0 NOT NULL COMMENT 'La web ordena de forma descendiente por este campo para mostrar los artículos'; diff --git a/db/.archive/230201/00-workerTimeControlConfig.sql b/db/.archive/230201/00-workerTimeControlConfig.sql deleted file mode 100644 index c04acd936..000000000 --- a/db/.archive/230201/00-workerTimeControlConfig.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE `vn`.`workerTimeControlConfig` ADD teleworkingStart INT NULL COMMENT 'Hora comienzo jornada de los teletrabajdores expresada en segundos'; -ALTER TABLE `vn`.`workerTimeControlConfig` ADD teleworkingStartBreakTime INT NULL COMMENT 'Hora comienzo descanso de los teletrabjadores expresada en segundos'; - -UPDATE `vn`.`workerTimeControlConfig` - SET `teleworkingStart`=28800, `teleworkingStartBreakTime`=32400 -WHERE `id`=1; diff --git a/db/.archive/230202/00-itemConfig.sql b/db/.archive/230202/00-itemConfig.sql deleted file mode 100644 index 0b32d5de8..000000000 --- a/db/.archive/230202/00-itemConfig.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `vn`.`itemConfig` ADD defaultTag INT DEFAULT 56 NOT NULL; -ALTER TABLE `vn`.`itemConfig` ADD CONSTRAINT itemConfig_FK FOREIGN KEY (defaultTag) REFERENCES vn.tag(id); -ALTER TABLE `vn`.`itemConfig` ADD validPriorities varchar(50) DEFAULT '[1,2,3]' NOT NULL; -ALTER TABLE `vn`.`itemConfig` ADD defaultPriority INT DEFAULT 2 NOT NULL; -ALTER TABLE `vn`.`item` MODIFY COLUMN relevancy tinyint(1) DEFAULT 0 NOT NULL COMMENT 'La web ordena de forma descendiente por este campo para mostrar los artículos'; diff --git a/db/.archive/230401/00-ACL.sql b/db/.archive/230401/00-ACL.sql deleted file mode 100644 index ae9f781f7..000000000 --- a/db/.archive/230401/00-ACL.sql +++ /dev/null @@ -1,18 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) -VALUES ('VnUser', '*', '*', 'ALLOW', 'ROLE', 'employee'); - -INSERT INTO `salix`.`ACL` (id, model, property, accessType, permission, principalType, principalId) -VALUES ('VnUser', 'acl', 'READ', 'ALLOW', 'ROLE', 'account'); - -INSERT INTO `salix`.`ACL` (id, model, property, accessType, permission, principalType, principalId) -VALUES ('VnUser', 'getCurrentUserData', 'READ', 'ALLOW', 'ROLE', 'account'); - -INSERT INTO `salix`.`ACL` (id, model, property, accessType, permission, principalType, principalId) -VALUES ('VnUser', 'changePassword', '*', 'ALLOW', 'ROLE', 'account'); - - - -UPDATE `hedera`.`imageCollection` t -SET t.model = 'VnUser' -WHERE t.id = 6; - diff --git a/db/.archive/230401/00-ACL_tag_update.sql b/db/.archive/230401/00-ACL_tag_update.sql deleted file mode 100644 index 3c103e990..000000000 --- a/db/.archive/230401/00-ACL_tag_update.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Tag', 'onSubmit', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/230401/00-createWorker.sql b/db/.archive/230401/00-createWorker.sql deleted file mode 100644 index 7ca2c41ee..000000000 --- a/db/.archive/230401/00-createWorker.sql +++ /dev/null @@ -1,24 +0,0 @@ -UPDATE `salix`.`ACL` -SET accessType='READ' -WHERE model='Worker' - AND property='*' - AND accessType='*' - AND permission='ALLOW' - AND principalType='ROLE' - AND principalId='employee'; - - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Worker', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'hr'), - ('Worker', 'createAbsence', '*', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'updateAbsence', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'deleteAbsence', '*', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'new', 'WRITE', 'ALLOW', 'ROLE', 'hr'), - ('Role', '*', 'READ', 'ALLOW', 'ROLE', 'hr'); - -ALTER TABLE `vn`.`workerConfig` ADD roleFk int(10) unsigned NOT NULL COMMENT 'Rol por defecto al dar de alta un trabajador nuevo'; -UPDATE `vn`.`workerConfig` - SET roleFk = 1 - WHERE id = 1; - diff --git a/db/.archive/230401/00-ticket_canAdvance.sql b/db/.archive/230401/00-ticket_canAdvance.sql deleted file mode 100644 index fd9d451bf..000000000 --- a/db/.archive/230401/00-ticket_canAdvance.sql +++ /dev/null @@ -1,110 +0,0 @@ -DROP PROCEDURE IF EXISTS vn.ticket_canAdvance; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM vn.config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM vn.itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM vn.itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM vn.itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT s.ticketFk futureId, - t2.ticketFk id, - count(DISTINCT s.id) saleCount, - t2.state, - t2.isNotValidated, - st.name futureState, - st.isNotValidated futureIsNotValidated, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - t2.ipt, - t.workerFk, - CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - CAST(COUNT(*) AS DECIMAL(10,0)) `futureLines`, - t2.shipped, - t.shipped futureShipped, - t2.totalWithVat, - t.totalWithVat futureTotalWithVat, - t2.agency, - am.name futureAgency, - t2.lines, - t2.liters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock - FROM vn.ticket t - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.saleVolume sv ON t.id = sv.ticketFk - JOIN (SELECT - t2.id ticketFk, - t2.addressFk, - st.isNotValidated, - st.name state, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t2.shipped, - t2.totalWithVat, - am.name agency, - CAST(SUM(litros) AS DECIMAL(10,0)) liters, - CAST(COUNT(*) AS DECIMAL(10,0)) `lines` - FROM vn.ticket t2 - JOIN vn.saleVolume sv ON t2.id = sv.ticketFk - JOIN vn.sale s ON s.ticketFk = t2.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticketState ts ON ts.ticketFk = t2.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.agencyMode am ON t2.agencyModeFk = am.id - LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t2.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t2.warehouseFk = vWarehouseFk - GROUP BY t2.id) t2 ON t2.addressFk = t.addressFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = s.itemFk - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id; - - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; diff --git a/db/.archive/230401/00-updateIsToBeMailed.sql b/db/.archive/230401/00-updateIsToBeMailed.sql deleted file mode 100644 index 1bb177f57..000000000 --- a/db/.archive/230401/00-updateIsToBeMailed.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE `vn`.`client` - SET isToBeMailed = FALSE - WHERE - mailAddress is NULL - AND email is NULL - AND isToBeMailed = TRUE; diff --git a/db/.archive/230403/00-clienteCompensado.sql b/db/.archive/230403/00-clienteCompensado.sql deleted file mode 100644 index ff1982b93..000000000 --- a/db/.archive/230403/00-clienteCompensado.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Client', 'getClientOrSupplierReference', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/230404/00-ticket_canAdvance.sql b/db/.archive/230404/00-ticket_canAdvance.sql deleted file mode 100644 index d7386e9d1..000000000 --- a/db/.archive/230404/00-ticket_canAdvance.sql +++ /dev/null @@ -1,127 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticket_canAdvance`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - - SELECT - origin.ticketFk futureId, - dest.ticketFk id, - dest.state, - origin.futureState, - origin.futureIpt, - dest.ipt, - origin.workerFk, - origin.futureLiters, - origin.futureLines, - dest.shipped, - origin.shipped futureShipped, - dest.totalWithVat, - origin.totalWithVat futureTotalWithVat, - dest.agency, - origin.futureAgency, - dest.lines, - dest.liters, - origin.futureLines - origin.hasStock AS notMovableLines, - (origin.futureLines = origin.hasStock) AS isFullMovable - FROM ( - SELECT - s.ticketFk, - t.workerFk, - t.shipped, - t.totalWithVat, - st.name futureState, - t.addressFk, - am.name futureAgency, - count(s.id) futureLines, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) origin - JOIN ( - SELECT - t.id ticketFk, - t.addressFk, - st.name state, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t.shipped, - t.totalWithVat, - am.name agency, - CAST(SUM(litros) AS DECIMAL(10,0)) liters, - CAST(COUNT(*) AS DECIMAL(10,0)) `lines` - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t.warehouseFk = vWarehouseFk - AND st.order <= 5 - GROUP BY t.id - ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock != 0; - - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; diff --git a/db/.archive/230601/00-acl_claim.sql b/db/.archive/230601/00-acl_claim.sql deleted file mode 100644 index 4e680eb4f..000000000 --- a/db/.archive/230601/00-acl_claim.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES('ClaimBeginning', 'isEditable', 'READ', 'ALLOW', 'ROLE', 'employee'); - -DELETE FROM `salix`.`ACL` - WHERE model='Claim' AND property='isEditable'; - diff --git a/db/.archive/230601/00-acl_notifications.sql b/db/.archive/230601/00-acl_notifications.sql deleted file mode 100644 index ab40b16a5..000000000 --- a/db/.archive/230601/00-acl_notifications.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) - VALUES - ('NotificationSubscription','*','*','employee'), - ('NotificationAcl','*','READ','employee'); diff --git a/db/.archive/230601/00-itemConfig_warehouseFk.sql b/db/.archive/230601/00-itemConfig_warehouseFk.sql deleted file mode 100644 index c860986d6..000000000 --- a/db/.archive/230601/00-itemConfig_warehouseFk.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE `vn`.`itemConfig` ADD warehouseFk smallint(6) unsigned NULL; -UPDATE `vn`.`itemConfig` - SET warehouseFk=60 -WHERE id=0; diff --git a/db/.archive/230601/00-uniqueKeyNotificationSubscription.sql b/db/.archive/230601/00-uniqueKeyNotificationSubscription.sql deleted file mode 100644 index 623ecf770..000000000 --- a/db/.archive/230601/00-uniqueKeyNotificationSubscription.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE - `util`.`notificationSubscription` -ADD - CONSTRAINT `notificationSubscription_UN` UNIQUE KEY (`notificationFk`, `userFk`); \ No newline at end of file diff --git a/db/.archive/230601/01-alter_notSubs.sql b/db/.archive/230601/01-alter_notSubs.sql deleted file mode 100644 index 07ea7c2bf..000000000 --- a/db/.archive/230601/01-alter_notSubs.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE `util`.`notificationSubscription` -ADD `id` int(11) auto_increment NULL, -DROP PRIMARY KEY, -ADD CONSTRAINT PRIMARY KEY (`id`); - -ALTER TABLE `util`.`notificationSubscription` -ADD KEY `notificationSubscription_ibfk_1` (`notificationFk`); diff --git a/db/.archive/230801/00-acl_itemConfig.sql b/db/.archive/230801/00-acl_itemConfig.sql deleted file mode 100644 index 8c35022b4..000000000 --- a/db/.archive/230801/00-acl_itemConfig.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ItemConfig', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/230801/00-supplierIsVies.sql b/db/.archive/230801/00-supplierIsVies.sql deleted file mode 100644 index 5861e7615..000000000 --- a/db/.archive/230801/00-supplierIsVies.sql +++ /dev/null @@ -1,16 +0,0 @@ -ALTER TABLE `vn`.`supplier` ADD `isVies` tinyint(4) DEFAULT 0 NOT NULL; - -UPDATE `vn`.`supplier` s - JOIN vn.country c ON c.id = s.countryFk - SET s.nif = MID(s.nif, 3, LENGTH(s.nif)-1), s.isVies = TRUE -WHERE s.nif <> TRIM(IF(c.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif)-1), s.nif)); - -INSERT IGNORE INTO `vn`.`chat` -(senderFk, recipient, checkUserStatus, message, status, attempts) -VALUES(19263, '#informatica-cau', 0, ' -``` -UPDATE `vn`.`supplier` s - JOIN vn.country c ON c.id = s.countryFk - SET s.nif = MID(s.nif, 3, LENGTH(s.nif)-1), s.isVies = TRUE -WHERE s.nif <> TRIM(IF(c.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif)-1), s.nif)); -```', 0, 0); diff --git a/db/.archive/230801/00-workerLocker.sql b/db/.archive/230801/00-workerLocker.sql deleted file mode 100644 index 0a72cca1e..000000000 --- a/db/.archive/230801/00-workerLocker.sql +++ /dev/null @@ -1,15 +0,0 @@ -ALTER TABLE `vn`.`worker` ADD locker INT UNSIGNED NULL UNIQUE; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('DeviceProduction', '*', '*', 'ALLOW', 'ROLE', 'hr'), - ('DeviceProductionModels', '*', '*', 'ALLOW', 'ROLE', 'hr'), - ('DeviceProductionState', '*', '*', 'ALLOW', 'ROLE', 'hr'), - ('DeviceProductionUser', '*', '*', 'ALLOW', 'ROLE', 'hr'), - ('DeviceProduction', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('DeviceProductionModels', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('DeviceProductionState', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('DeviceProductionUser', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('Worker', 'deallocatePDA', '*', 'ALLOW', 'ROLE', 'hr'), - ('Worker', 'allocatePDA', '*', 'ALLOW', 'ROLE', 'hr'), - ('Worker', 'deallocatePDA', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('Worker', 'allocatePDA', '*', 'ALLOW', 'ROLE', 'productionAssi'); diff --git a/db/.archive/231001/00-delivery.sql b/db/.archive/231001/00-delivery.sql deleted file mode 100644 index 3a9269183..000000000 --- a/db/.archive/231001/00-delivery.sql +++ /dev/null @@ -1,74 +0,0 @@ -DROP TABLE `vn`.`dmsRecover`; - -ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; -ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; -ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; -ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); - -DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('Ticket','saveSign','WRITE','ALLOW','employee'); - -DROP PROCEDURE IF EXISTS vn.route_getTickets; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) -BEGIN -/** - * Pasado un RouteFk devuelve la información - * de sus tickets. - * - * @param vRouteFk - * - * @select Información de los tickets - */ - - SELECT - t.id Id, - t.clientFk Client, - a.id Address, - t.packages Packages, - a.street AddressName, - a.postalCode PostalCode, - a.city City, - sub2.itemPackingTypeFk PackingType, - c.phone ClientPhone, - c.mobile ClientMobile, - a.phone AddressPhone, - a.mobile AddressMobile, - d.longitude Longitude, - d.latitude Latitude, - wm.mediaValue SalePersonPhone, - tob.Note Note, - t.isSigned Signed - FROM ticket t - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN delivery d ON t.id = d.ticketFk - LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk - LEFT JOIN - (SELECT tob.description Note, t.id - FROM ticketObservation tob - JOIN ticket t ON tob.ticketFk = t.id - JOIN observationType ot ON ot.id = tob.observationTypeFk - WHERE t.routeFk = vRouteFk - AND ot.code = 'delivery' - )tob ON tob.id = t.id - LEFT JOIN - (SELECT sub.ticketFk, - CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk - FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.routeFk = vRouteFk - GROUP BY t.id,i.itemPackingTypeFk)sub - GROUP BY sub.ticketFk - ) sub2 ON sub2.ticketFk = t.id - WHERE t.routeFk = vRouteFk - GROUP BY t.id - ORDER BY t.priority; -END$$ -DELIMITER ; diff --git a/db/.archive/231001/00-invoiceOut.sql b/db/.archive/231001/00-invoiceOut.sql deleted file mode 100644 index 4404c8f4a..000000000 --- a/db/.archive/231001/00-invoiceOut.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE vn.invoiceOutSerial - ADD `type` ENUM('global', 'quick') DEFAULT NULL NULL; - - UPDATE vn.invoiceOutSerial - SET type = 'global' - WHERE code IN ('A','V'); \ No newline at end of file diff --git a/db/.archive/231001/00-report.sql b/db/.archive/231001/00-report.sql deleted file mode 100644 index 0bc7c8da4..000000000 --- a/db/.archive/231001/00-report.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE `vn`.`report` - SET `method`='InvoiceOuts/{refFk}/invoice-out-pdf' -WHERE name='invoice'; - -ALTER TABLE `vn`.`printQueue` MODIFY COLUMN printerFk tinyint(3) unsigned DEFAULT 82 NOT NULL; - diff --git a/db/.archive/231001/02-invoiceOut_new.sql b/db/.archive/231001/02-invoiceOut_new.sql deleted file mode 100644 index e87c44cd0..000000000 --- a/db/.archive/231001/02-invoiceOut_new.sql +++ /dev/null @@ -1,258 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_new`; - -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATE, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN -/** - * Creación de facturas emitidas. - * requiere previamente tabla tmp.ticketToInvoice(id). - * - * @param vSerial serie a la cual se hace la factura - * @param vInvoiceDate fecha de la factura - * @param vTaxArea tipo de iva en relacion a la empresa y al cliente - * @param vNewInvoiceId id de la factura que se acaba de generar - * @return vNewInvoiceId - */ - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompanyFk INT; - DECLARE vInterCompanyFk INT; - DECLARE vClientFk INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInFk INT; - DECLARE vIsInterCompany BOOL DEFAULT FALSE; - DECLARE vIsCEESerial BOOL DEFAULT FALSE; - DECLARE vIsCorrectInvoiceDate BOOL; - DECLARE vMaxShipped DATE; - - SET vInvoiceDate = IFNULL(vInvoiceDate, util.CURDATE()); - - SELECT t.clientFk, - t.companyFk, - MAX(DATE(t.shipped)), - DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( - vSerial, - t.companyFk, - YEAR(vInvoiceDate)) - INTO vClientFk, - vCompanyFk, - vMaxShipped, - vIsCorrectInvoiceDate - FROM tmp.ticketToInvoice tt - JOIN ticket t ON t.id = tt.id; - - IF(vMaxShipped > vInvoiceDate) THEN - CALL util.throw("Invoice date can't be less than max date"); - END IF; - - IF NOT vIsCorrectInvoiceDate THEN - CALL util.throw('Exists an invoice with a previous date'); - END IF; - - -- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM tmp.ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN supplier su ON su.id = t.companyFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE - OR itc.id IS NULL; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 - INTO vIsAnySaleToInvoice - FROM tmp.ticketToInvoice t - JOIN sale s ON s.ticketFk = t.id; - - SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice - FROM tmp.ticketToInvoice t - JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - siiTypeInvoiceOutFk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClientFk, - getDueDate(vInvoiceDate, dueDay), - vCompanyFk, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClientFk; - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - UPDATE ticket t - JOIN tmp.ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticket - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); - - INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) - SELECT * FROM tmp.updateInter; - - INSERT INTO ticketLog (action, userFk, originFk, description) - SELECT 'UPDATE', account.myUser_getId(), ti.id, CONCAT('Crea factura ', vNewRef) - FROM tmp.ticketToInvoice ti; - - CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) total - FROM invoiceOutExpense - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT COUNT(*), id - INTO vIsInterCompany, vInterCompanyFk - FROM company - WHERE clientFk = vClientFk; - - IF (vIsInterCompany) THEN - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; - - SET vNewInvoiceInFk = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - @vTaxableBaseServices, - sub.expenseFk, - sub.taxTypeSageFk, - sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, - i.expenseFk, - i.taxTypeSageFk, - i.transactionTypeSageFk, - @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, - @vTaxableBaseServices, 0) taxableBase, - i.expenseFk, - i.taxTypeSageFk , - i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL invoiceInDueDay_calculate(vNewInvoiceInFk); - - SELECT COUNT(*) INTO vIsCEESerial - FROM invoiceOutSerial - WHERE code = vSerial; - - IF vIsCEESerial THEN - - INSERT INTO invoiceInIntrastat ( - invoiceInFk, - intrastatFk, - amount, - stems, - countryFk, - net) - SELECT - vNewInvoiceInFk, - i.intrastatFk, - SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), - SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), - su.countryFk, - CAST(SUM(IFNULL(i.stems, 1) - * s.quantity - * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) - FROM sale s - JOIN ticket t ON s.ticketFk = t.id - JOIN supplier su ON su.id = t.companyFk - JOIN item i ON i.id = s.itemFk - LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - WHERE t.refFk = vNewRef - GROUP BY i.intrastatFk; - - END IF; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - END IF; - END IF; - DROP TEMPORARY TABLE tmp.`ticketToInvoice`; -END$$ -DELIMITER ; diff --git a/db/.archive/231201/00-ACL.sql b/db/.archive/231201/00-ACL.sql deleted file mode 100644 index 47a818977..000000000 --- a/db/.archive/231201/00-ACL.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) -VALUES ('Operator', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Operator', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/231201/00-chatRefactor.sql b/db/.archive/231201/00-chatRefactor.sql deleted file mode 100644 index 66d1bf3bf..000000000 --- a/db/.archive/231201/00-chatRefactor.sql +++ /dev/null @@ -1,16 +0,0 @@ -ALTER TABLE `vn`.`chat` ADD statusNew enum('pending','sent','error','sending') DEFAULT 'pending' NOT NULL; - -UPDATE `vn`.`chat` - SET statusNew = 'pending' -WHERE status = 0; - -UPDATE `vn`.`chat` - SET statusNew = 'sent' -WHERE status = 1; - -UPDATE `vn`.`chat` - SET statusNew = 'error' -WHERE status = 2; - -ALTER TABLE `vn`.`chat` CHANGE status status__ tinyint(1) DEFAULT NULL NULL; -ALTER TABLE `vn`.`chat` CHANGE statusNew status enum('pending','sent','error','sending') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'pending' NOT NULL; diff --git a/db/.archive/231201/00-invoiceInSerial.sql b/db/.archive/231201/00-invoiceInSerial.sql deleted file mode 100644 index de476027c..000000000 --- a/db/.archive/231201/00-invoiceInSerial.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE `vn`.`invoiceInConfig` ADD daysAgo INT UNSIGNED DEFAULT 45 COMMENT 'Días en el pasado para mostrar facturas en invoiceIn series en salix'; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('InvoiceIn', 'getSerial', 'READ', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/.archive/231201/00-itemType_isFragile.sql b/db/.archive/231201/00-itemType_isFragile.sql deleted file mode 100644 index ecc1bfbb2..000000000 --- a/db/.archive/231201/00-itemType_isFragile.sql +++ /dev/null @@ -1,14 +0,0 @@ -ALTER TABLE `vn`.`itemType` ADD isFragile tinyint(1) NULL; -ALTER TABLE `vn`.`itemType` MODIFY COLUMN isFragile tinyint(1) DEFAULT 0 NOT NULL; - -UPDATE `vn`.`itemType` - SET isFragile = 1 -WHERE code IN ('ZKA', 'ZKE'); - -UPDATE `vn`.`itemType` - SET isFragile = 1 -WHERE id IN (SELECT it.id - FROM `vn`.`itemCategory` ic - JOIN `vn`.`itemType` it ON it.categoryFk = ic.id - WHERE ic.code = 'plant'); - diff --git a/db/.archive/231201/00-mailACL.sql b/db/.archive/231201/00-mailACL.sql deleted file mode 100644 index ac687818d..000000000 --- a/db/.archive/231201/00-mailACL.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId) -VALUES('Mail', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/231201/00-operator.sql b/db/.archive/231201/00-operator.sql deleted file mode 100644 index 9b7815b41..000000000 --- a/db/.archive/231201/00-operator.sql +++ /dev/null @@ -1,159 +0,0 @@ -ALTER TABLE `vn`.`operator` ADD sectorFk int(11) NULL; -ALTER TABLE `vn`.`operator` ADD labelerFk tinyint(3) unsigned NULL; -ALTER TABLE `vn`.`operator` ADD CONSTRAINT operator_FK_5 FOREIGN KEY (labelerFk) REFERENCES `vn`.`printer`(id) ON DELETE CASCADE ON UPDATE CASCADE; - -UPDATE `vn`.`operator` o -JOIN (SELECT id, sectorFk, labelerFk - FROM `vn`.`worker`) sub ON sub.id = o.workerFk - SET o.sectorFk = sub.sectorFk, - o.labelerFk = sub.labelerFk; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_printSticker`( - vSelf INT, - vLabelCount INT -) -BEGIN -/** - * Prints a yellow label from a collection or a ticket - * - * @param vSelf collection or ticket - * @param vLabelCount number of times the collection has been printed - */ - DECLARE vPrintArgs JSON DEFAULT JSON_OBJECT('collectionOrTicketFk', vSelf); - - IF vLabelCount IS NULL THEN - INSERT INTO ticketTrolley - SELECT ticketFk, 1 - FROM ticketCollection - WHERE collectionFk = vSelf - ON DUPLICATE KEY UPDATE labelCount = labelCount + 1; - ELSE - SET vPrintArgs = JSON_MERGE_PATCH(vPrintArgs, JSON_OBJECT('labelCount', vLabelCount)); - END IF; - - CALL report_print( - 'LabelCollection', - (SELECT o.labelerFk FROM operator o WHERE o.workerFk = account.myUser_getId()), - account.myUser_getId(), - vPrintArgs, - 'high' - ); -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_printLabel`(vSelf INT) -BEGIN -/** - * Calls the report_print procedure and passes it - * the necessary parameters for printing. - * - * @param vSelf expeditioPallet id. - */ - DECLARE vPrinterFk INT; - DECLARE vUserFk INT DEFAULT account.myUser_getId(); - - SELECT o.labelerFk INTO vPrinterFk - FROM operator o - WHERE o.workerFk = vUserFk; - - CALL vn.report_print( - 'LabelPalletExpedition', - vPrinterFk, - account.myUser_getId(), - JSON_OBJECT('palletFk', vSelf, 'userFk', vUserFk), - 'high' - ); - - UPDATE vn.expeditionPallet - SET isPrint = TRUE - WHERE id = vSelf; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getAlternatives`(vShelvingFk VARCHAR(10)) -BEGIN -/** - * Devuelve un listado de posibles ubicaciones alternativas a ubicar los item de la matricula - * del carro que se le ha pasado. - * - * @param vShelvingFk matricula del carro - */ - SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder - FROM itemShelving is2 - JOIN shelving sh ON sh.code = is2.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - LEFT JOIN operator o ON o.sectorFk = s.id - LEFT JOIN worker w ON w.sectorFk = s.id AND w.id = account.myUser_getId() - JOIN warehouse wh ON wh.id = s.warehouseFk - JOIN itemShelving is3 ON is3.itemFk = is2.itemFk AND is3.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci - WHERE is2.shelvingFk <> vShelvingFk COLLATE utf8_unicode_ci - GROUP BY is2.id - ORDER BY p.pickingOrder DESC; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`operator_beforeInsert` - BEFORE INSERT ON `operator` - FOR EACH ROW -BEGIN - CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`operator_beforeUpdate` - BEFORE UPDATE ON `operator` - FOR EACH ROW -BEGIN - IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN - CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`worker_beforeUpdate` - BEFORE UPDATE ON `worker` - FOR EACH ROW -BEGIN - IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN - CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); - - INSERT IGNORE INTO vn.operator (workerFk) - VALUES (NEW.id); - - UPDATE operator - SET labelerFk = NEW.labelerFk, - sectorFk = NEW.sectorFk - WHERE workerFk = NEW.id; - END IF; -END$$ -DELIMITER ; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`operatorWorkerCode` -AS SELECT `o`.`workerFk` AS `workerFk`, - concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `fullName`, - `w`.`code` AS `code`, - `o`.`numberOfWagons` AS `numberOfWagons` -FROM ( - ( - `vn`.`worker` `w` - JOIN `vn`.`operator` `o` ON(`o`.`workerFk` = `w`.`id`) - ) - JOIN `vn`.`sector` `s` ON(`o`.`sectorFk` = `s`.`id`) - ) -WHERE `o`.`sectorFk` IS NOT NULL - AND `s`.`code` IN ( - 'H2', - 'H2', - 'PEQUES_H', - 'ALTILLO COMP', - 'ALTILLO ARTI' - ) \ No newline at end of file diff --git a/db/.archive/231201/00-supplierAccount_deleteTriggers.sql b/db/.archive/231201/00-supplierAccount_deleteTriggers.sql deleted file mode 100644 index d7f9f734a..000000000 --- a/db/.archive/231201/00-supplierAccount_deleteTriggers.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TRIGGER `vn`.`supplierAccount_afterInsert`; -DROP TRIGGER `vn`.`supplierAccount_afterUpdate`; -DROP TRIGGER `vn`.`supplierAccount_afterDelete`; diff --git a/db/.archive/231201/00-wagon.sql b/db/.archive/231201/00-wagon.sql deleted file mode 100644 index 9e817bac4..000000000 --- a/db/.archive/231201/00-wagon.sql +++ /dev/null @@ -1,71 +0,0 @@ -CREATE TABLE `vn`.`wagonType` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(30) NOT NULL UNIQUE, - `divisible` tinyint(1) NOT NULL DEFAULT 0, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; - -CREATE TABLE `vn`.`wagonTypeColor` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(30) NOT NULL UNIQUE, - `rgb` varchar(30) NOT NULL UNIQUE, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; - -CREATE TABLE `vn`.`wagonTypeTray` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `typeFk` int(11) unsigned, - `height` int(11) unsigned NOT NULL, - `colorFk` int(11) unsigned, - PRIMARY KEY (`id`), - UNIQUE KEY (`typeFk`,`height`), - CONSTRAINT `wagonTypeTray_type` FOREIGN KEY (`typeFk`) REFERENCES `wagonType` (`id`) ON UPDATE CASCADE, - CONSTRAINT `wagonTypeTray_color` FOREIGN KEY (`colorFk`) REFERENCES `wagonTypeColor` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; - -CREATE TABLE `vn`.`wagonConfig` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `width` int(11) unsigned DEFAULT 1350, - `height` int(11) unsigned DEFAULT 1900, - `maxWagonHeight` int(11) unsigned DEFAULT 200, - `minHeightBetweenTrays` int(11) unsigned DEFAULT 50, - `maxTrays` int(11) unsigned DEFAULT 6, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3; - -CREATE TABLE `vn`.`collectionWagon` ( - `collectionFk` int(11) NOT NULL, - `wagonFk` int(11) NOT NULL, - `position` int(11) unsigned, - PRIMARY KEY (`collectionFk`,`position`), - UNIQUE KEY `collectionWagon_unique` (`collectionFk`,`wagonFk`), - CONSTRAINT `collectionWagon_collection` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON UPDATE CASCADE, - CONSTRAINT `collectionWagon_wagon` FOREIGN KEY (`wagonFk`) REFERENCES `wagon` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; - -CREATE TABLE `vn`.`collectionWagonTicket` ( - `ticketFk` int(11) NOT NULL, - `wagonFk` int(11) NOT NULL, - `trayFk` int(11) unsigned NOT NULL, - `side` SET('L', 'R') NULL, - PRIMARY KEY (`ticketFk`), - CONSTRAINT `collectionWagonTicket_ticket` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE, - CONSTRAINT `collectionWagonTicket_wagon` FOREIGN KEY (`wagonFk`) REFERENCES `wagon` (`id`) ON UPDATE CASCADE, - CONSTRAINT `collectionWagonTicket_tray` FOREIGN KEY (`trayFk`) REFERENCES `wagonTypeTray` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; - -ALTER TABLE `vn`.`wagon` ADD `typeFk` int(11) unsigned NOT NULL; -ALTER TABLE `vn`.`wagon` ADD `label` int(11) unsigned NOT NULL; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('WagonType', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('WagonTypeColor', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('WagonTypeTray', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('WagonConfig', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('CollectionWagon', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('CollectionWagonTicket', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('Wagon', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('WagonType', 'createWagonType', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('WagonType', 'deleteWagonType', '*', 'ALLOW', 'ROLE', 'productionAssi'), - ('WagonType', 'editWagonType', '*', 'ALLOW', 'ROLE', 'productionAssi'); - diff --git a/db/.archive/231202/00-delivery.sql b/db/.archive/231202/00-delivery.sql deleted file mode 100644 index 3a9269183..000000000 --- a/db/.archive/231202/00-delivery.sql +++ /dev/null @@ -1,74 +0,0 @@ -DROP TABLE `vn`.`dmsRecover`; - -ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_FK; -ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; -ALTER TABLE `vn`.`delivery` ADD ticketFk INT NOT NULL; -ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); - -DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('Ticket','saveSign','WRITE','ALLOW','employee'); - -DROP PROCEDURE IF EXISTS vn.route_getTickets; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) -BEGIN -/** - * Pasado un RouteFk devuelve la información - * de sus tickets. - * - * @param vRouteFk - * - * @select Información de los tickets - */ - - SELECT - t.id Id, - t.clientFk Client, - a.id Address, - t.packages Packages, - a.street AddressName, - a.postalCode PostalCode, - a.city City, - sub2.itemPackingTypeFk PackingType, - c.phone ClientPhone, - c.mobile ClientMobile, - a.phone AddressPhone, - a.mobile AddressMobile, - d.longitude Longitude, - d.latitude Latitude, - wm.mediaValue SalePersonPhone, - tob.Note Note, - t.isSigned Signed - FROM ticket t - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN delivery d ON t.id = d.ticketFk - LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk - LEFT JOIN - (SELECT tob.description Note, t.id - FROM ticketObservation tob - JOIN ticket t ON tob.ticketFk = t.id - JOIN observationType ot ON ot.id = tob.observationTypeFk - WHERE t.routeFk = vRouteFk - AND ot.code = 'delivery' - )tob ON tob.id = t.id - LEFT JOIN - (SELECT sub.ticketFk, - CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk - FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.routeFk = vRouteFk - GROUP BY t.id,i.itemPackingTypeFk)sub - GROUP BY sub.ticketFk - ) sub2 ON sub2.ticketFk = t.id - WHERE t.routeFk = vRouteFk - GROUP BY t.id - ORDER BY t.priority; -END$$ -DELIMITER ; diff --git a/db/.archive/231203/00-delivery.sql b/db/.archive/231203/00-delivery.sql deleted file mode 100644 index 0815ec421..000000000 --- a/db/.archive/231203/00-delivery.sql +++ /dev/null @@ -1,67 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE `property` = 'saveSign'; -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('Ticket','saveSign','WRITE','ALLOW','employee'); - -DROP PROCEDURE IF EXISTS vn.route_getTickets; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) -BEGIN -/** - * Pasado un RouteFk devuelve la información - * de sus tickets. - * - * @param vRouteFk - * - * @select Información de los tickets - */ - - SELECT - t.id Id, - t.clientFk Client, - a.id Address, - t.packages Packages, - a.street AddressName, - a.postalCode PostalCode, - a.city City, - sub2.itemPackingTypeFk PackingType, - c.phone ClientPhone, - c.mobile ClientMobile, - a.phone AddressPhone, - a.mobile AddressMobile, - d.longitude Longitude, - d.latitude Latitude, - wm.mediaValue SalePersonPhone, - tob.Note Note, - t.isSigned Signed - FROM ticket t - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN delivery d ON t.id = d.ticketFk - LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk - LEFT JOIN - (SELECT tob.description Note, t.id - FROM ticketObservation tob - JOIN ticket t ON tob.ticketFk = t.id - JOIN observationType ot ON ot.id = tob.observationTypeFk - WHERE t.routeFk = vRouteFk - AND ot.code = 'delivery' - )tob ON tob.id = t.id - LEFT JOIN - (SELECT sub.ticketFk, - CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk - FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.routeFk = vRouteFk - GROUP BY t.id,i.itemPackingTypeFk)sub - GROUP BY sub.ticketFk - ) sub2 ON sub2.ticketFk = t.id - WHERE t.routeFk = vRouteFk - GROUP BY t.id - ORDER BY t.priority; -END$$ -DELIMITER ; diff --git a/db/.archive/231204/00-rollbackDelivery.sql b/db/.archive/231204/00-rollbackDelivery.sql deleted file mode 100644 index d7fa6b587..000000000 --- a/db/.archive/231204/00-rollbackDelivery.sql +++ /dev/null @@ -1,83 +0,0 @@ -CREATE TABLE `vn`.`dmsRecover` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `ticketFk` int(11) DEFAULT NULL, - `sign` text DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), - PRIMARY KEY (`id`), - KEY `ticketFk_idx` (`ticketFk`), - CONSTRAINT `ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=31917 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -ALTER TABLE `vn`.`delivery` ADD addressFk INT; - -DROP PROCEDURE IF EXISTS `vn`.`route_getTickets`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) -BEGIN -/** - * Pasado un RouteFk devuelve la información - * de sus tickets. - * - * @param vRouteFk - * @select Información de los tickets - */ -SELECT * - FROM ( - SELECT t.id Id, - t.clientFk Client, - a.id Address, - a.nickname ClientName, - t.packages Packages, - a.street AddressName, - a.postalCode PostalCode, - a.city City, - sub2.itemPackingTypeFk PackingType, - c.phone ClientPhone, - c.mobile ClientMobile, - a.phone AddressPhone, - a.mobile AddressMobile, - d.longitude Longitude, - d.latitude Latitude, - wm.mediaValue SalePersonPhone, - tob.description Note, - t.isSigned Signed, - t.priority - FROM ticket t - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN delivery d ON d.addressFk = a.id - LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk - LEFT JOIN( - SELECT tob.description, t.id - FROM ticketObservation tob - JOIN ticket t ON tob.ticketFk = t.id - JOIN observationType ot ON ot.id = tob.observationTypeFk - WHERE t.routeFk = vRouteFk - AND ot.code = 'delivery' - )tob ON tob.id = t.id - LEFT JOIN( - SELECT sub.ticketFk, - CONCAT('(', - GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk - ORDER BY sub.items DESC SEPARATOR ','), - ') ') itemPackingTypeFk - FROM ( - SELECT s.ticketFk, i.itemPackingTypeFk, COUNT(*) items - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.routeFk = vRouteFk - GROUP BY t.id, i.itemPackingTypeFk - )sub - GROUP BY sub.ticketFk - )sub2 ON sub2.ticketFk = t.id - WHERE t.routeFk = vRouteFk - ORDER BY d.id DESC - LIMIT 10000000000000000000 - )sub3 - GROUP BY sub3.id - ORDER BY sub3.priority; -END$$ -DELIMITER ; diff --git a/db/.archive/231205/00-printQueueArgs.sql b/db/.archive/231205/00-printQueueArgs.sql deleted file mode 100644 index 972031325..000000000 --- a/db/.archive/231205/00-printQueueArgs.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`printQueueArgs` MODIFY COLUMN value varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; diff --git a/db/.archive/231401/00-claimBeginningAfterInsert.sql b/db/.archive/231401/00-claimBeginningAfterInsert.sql deleted file mode 100644 index 230b6defb..000000000 --- a/db/.archive/231401/00-claimBeginningAfterInsert.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TRIGGER IF EXISTS `vn`.`claimBeginning_afterInsert`; diff --git a/db/.archive/231401/00-negativeBases.sql b/db/.archive/231401/00-negativeBases.sql deleted file mode 100644 index 0bdc6f2dc..000000000 --- a/db/.archive/231401/00-negativeBases.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('InvoiceIn', 'negativeBases', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('InvoiceIn', 'negativeBasesCsv', 'READ', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/.archive/231401/00-workerNotes.sql b/db/.archive/231401/00-workerNotes.sql deleted file mode 100644 index 0d9eaae7e..000000000 --- a/db/.archive/231401/00-workerNotes.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE `vn`.`workerObservation` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `workerFk` int(10) unsigned DEFAULT NULL, - `userFk` int(10) unsigned DEFAULT NULL, - `text` text COLLATE utf8mb3_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - PRIMARY KEY (`id`), - CONSTRAINT `workerFk_workerObservation_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, - CONSTRAINT `userFk_workerObservation_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador'; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('WorkerObservation', '*', '*', 'ALLOW', 'ROLE', 'hr'); diff --git a/db/.archive/231402/00-negativeBases.sql b/db/.archive/231402/00-negativeBases.sql deleted file mode 100644 index f7d6cdfb0..000000000 --- a/db/.archive/231402/00-negativeBases.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE `salix`.`ACL` - SET model = 'InvoiceOut' - WHERE property IN ('negativeBases', 'negativeBasesCsv'); diff --git a/db/.archive/231801/00-aclClientInforma.sql b/db/.archive/231801/00-aclClientInforma.sql deleted file mode 100644 index 6222d2632..000000000 --- a/db/.archive/231801/00-aclClientInforma.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) -VALUES ('ClientInforma', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('ClientInforma', '*', 'WRITE', 'ALLOW', 'ROLE', 'financial'); diff --git a/db/.archive/231801/00-acl_receiptEmail.sql b/db/.archive/231801/00-acl_receiptEmail.sql deleted file mode 100644 index 2de8adf50..000000000 --- a/db/.archive/231801/00-acl_receiptEmail.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Receipt', 'receiptEmail', '*', 'ALLOW', 'ROLE', 'salesAssistant'); diff --git a/db/.archive/231801/00-clientInforma.sql b/db/.archive/231801/00-clientInforma.sql deleted file mode 100644 index 9bf757fc3..000000000 --- a/db/.archive/231801/00-clientInforma.sql +++ /dev/null @@ -1,16 +0,0 @@ -ALTER TABLE `vn`.`client` ADD rating INT UNSIGNED DEFAULT NULL NULL COMMENT 'información proporcionada por Informa'; -ALTER TABLE `vn`.`client` ADD recommendedCredit INT UNSIGNED DEFAULT NULL NULL COMMENT 'información proporcionada por Informa'; - -CREATE TABLE `vn`.`clientInforma` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `clientFk` int(11) NOT NULL, - `rating` int(10) unsigned DEFAULT NULL, - `recommendedCredit` int(10) unsigned DEFAULT NULL, - `workerFk` int(10) unsigned NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - PRIMARY KEY (`id`), - KEY `informaWorkers_fk_idx` (`workerFk`), - KEY `informaClientFk` (`clientFk`), - CONSTRAINT `informa_ClienteFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `informa_workers_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='información proporcionada por Informa, se actualiza desde el hook de client (salix)'; diff --git a/db/.archive/231801/00-client_setRatingAcl.sql b/db/.archive/231801/00-client_setRatingAcl.sql deleted file mode 100644 index 6687b11ec..000000000 --- a/db/.archive/231801/00-client_setRatingAcl.sql +++ /dev/null @@ -1,63 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE id=7; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('Client', 'setRating', 'WRITE', 'ALLOW', 'ROLE', 'financial'); - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('Client', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'addressesPropagateRe', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'canBeInvoiced', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'canCreateTicket', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'consumption', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'createAddress', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'createWithUser', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'extendedListFilter', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'getAverageInvoiced', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'getCard', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'getDebt', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'getMana', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'transactions', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'hasCustomerRole', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'isValidClient', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'lastActiveTickets', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'sendSms', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'setPassword', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'summary', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'updateAddress', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'updateFiscalData', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'uploadFile', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'campaignMetricsPdf', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'campaignMetricsEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientWelcomeHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientWelcomeEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'printerSetupHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'printerSetupEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'sepaCoreEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorPdf', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorStHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorStEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorNdHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'letterDebtorNdEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementPdf', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'clientDebtStatementEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'creditRequestPdf', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'creditRequestHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'creditRequestEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'incotermsAuthorizationPdf', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'incotermsAuthorizationHtml', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'incotermsAuthorizationEmail', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'consumptionSendQueued', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'filter', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'getClientOrSupplierReference', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'upsert', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'create', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'replaceById', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'updateAttributes', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'updateAttributes', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'deleteById', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'replaceOrCreate', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'updateAll', '*', 'ALLOW', 'ROLE', 'employee'), - ('Client', 'upsertWithWhere', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/231801/00-deleteProcs_refund.sql b/db/.archive/231801/00-deleteProcs_refund.sql deleted file mode 100644 index 8bf8982f4..000000000 --- a/db/.archive/231801/00-deleteProcs_refund.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP PROCEDURE `vn`.`refund`; -DROP PROCEDURE `vn`.`ticket_doRefund`; diff --git a/db/.archive/231801/00-deviceProduction.sql b/db/.archive/231801/00-deviceProduction.sql deleted file mode 100644 index 37a2f1371..000000000 --- a/db/.archive/231801/00-deviceProduction.sql +++ /dev/null @@ -1,5 +0,0 @@ -DROP TRIGGER `vn`.`deviceProduction_afterInsert`; -DROP TRIGGER `vn`.`deviceProduction_afterUpdate`; - -DROP TRIGGER `vn`.`deviceProductionUser_afterDelete`; - diff --git a/db/.archive/231801/00-kkearEntryNotes.sql b/db/.archive/231801/00-kkearEntryNotes.sql deleted file mode 100644 index ff5c7ce29..000000000 --- a/db/.archive/231801/00-kkearEntryNotes.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`entry` DROP COLUMN `notes`; \ No newline at end of file diff --git a/db/.archive/231801/00-newCompanyI18n.sql b/db/.archive/231801/00-newCompanyI18n.sql deleted file mode 100644 index 948b9cb08..000000000 --- a/db/.archive/231801/00-newCompanyI18n.sql +++ /dev/null @@ -1,9 +0,0 @@ --- vn.companyI18n definition -CREATE TABLE `vn`.`companyI18n` ( - `companyFk` smallint(5) unsigned NOT NULL, - `lang` char(2) CHARACTER SET utf8mb3 NOT NULL, - `footnotes` longtext COLLATE utf8mb3_unicode_ci DEFAULT NULL, - PRIMARY KEY (`companyFk`,`lang`), - CONSTRAINT `companyI18n_FK` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - diff --git a/db/.archive/231801/00-newTableWeb.sql b/db/.archive/231801/00-newTableWeb.sql deleted file mode 100644 index 1a2402956..000000000 --- a/db/.archive/231801/00-newTableWeb.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`company` ADD `web` varchar(100) NULL; \ No newline at end of file diff --git a/db/.archive/231801/00-observationEmailACL.sql b/db/.archive/231801/00-observationEmailACL.sql deleted file mode 100644 index 1a5d475e8..000000000 --- a/db/.archive/231801/00-observationEmailACL.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Defaulter', 'observationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/231801/00-optimiceZoneEstimatedDelivery.sql b/db/.archive/231801/00-optimiceZoneEstimatedDelivery.sql deleted file mode 100644 index 209e1efc3..000000000 --- a/db/.archive/231801/00-optimiceZoneEstimatedDelivery.sql +++ /dev/null @@ -1,77 +0,0 @@ -CREATE OR REPLACE -ALGORITHM = UNDEFINED VIEW `vn`.`zoneEstimatedDelivery` AS -select - `t`.`zoneFk` AS `zoneFk`, - cast(`util`.`VN_CURDATE`() + interval hour(ifnull(`zc`.`hour`, `z`.`hour`)) * 60 + minute(ifnull(`zc`.`hour`, `z`.`hour`)) minute as time) AS `hourTheoretical`, - cast(sum(`sv`.`volume`) as decimal(5, 1)) AS `totalVolume`, - cast(sum(if(`s`.`alertLevel` < 2, `sv`.`volume`, 0)) as decimal(5, 1)) AS `remainingVolume`, - greatest( - ifnull(`lhp`.`m3`, 0), - ifnull(`dl`.`minSpeed`, 0) - ) AS `speed`, - cast(`zc`.`hour` + interval -sum(if(`s`.`alertLevel` < 2, `sv`.`volume`, 0)) * 60 / greatest(ifnull(`lhp`.`m3`, 0), ifnull(`dl`.`minSpeed`, 0)) minute as time) AS `hourEffective`, - floor(-sum(if(`s`.`alertLevel` < 2, `sv`.`volume`, 0)) * 60 / greatest(ifnull(`lhp`.`m3`, 0), ifnull(`dl`.`minSpeed`, 0))) AS `minutesLess`, - cast(`zc`.`hour` + interval -sum(if(`s`.`alertLevel` < 2, `sv`.`volume`, 0)) * 60 / greatest(ifnull(`lhp`.`m3`, 0), ifnull(`dl`.`minSpeed`, 0)) minute as time) AS `etc` -from - ( - ( - ( - ( - ( - ( - ( - ( - ( - `vn`.`ticket` `t` - join `vn`.`ticketStateToday` `tst` on - ( - `tst`.`ticket` = `t`.`id` - ) - ) - join `vn`.`state` `s` on - ( - `s`.`id` = `tst`.`state` - ) - ) - join `vn`.`saleVolume` `sv` on - ( - `sv`.`ticketFk` = `t`.`id` - ) - ) - left join `vn`.`lastHourProduction` `lhp` on - ( - `lhp`.`warehouseFk` = `t`.`warehouseFk` - ) - ) - join `vn`.`warehouse` `w` on - ( - `w`.`id` = `t`.`warehouseFk` - ) - ) - join `vn`.`warehouseAlias` `wa` on - ( - `wa`.`id` = `w`.`aliasFk` - ) - ) - straight_join `vn`.`zone` `z` on - ( - `z`.`id` = `t`.`zoneFk` - ) - ) - left join `vn`.`zoneClosure` `zc` on - ( - `zc`.`zoneFk` = `t`.`zoneFk` - and `zc`.`dated` = `util`.`VN_CURDATE`() - ) - ) - left join `cache`.`departure_limit` `dl` on - ( - `dl`.`warehouse_id` = `t`.`warehouseFk` - and `dl`.`fecha` = `util`.`VN_CURDATE`() - ) - ) -where - `w`.`hasProduction` <> 0 - and cast(`t`.`shipped` as date) = `util`.`VN_CURDATE`() -group by - `t`.`zoneFk`; diff --git a/db/.archive/231801/00-saleTracking.sql b/db/.archive/231801/00-saleTracking.sql deleted file mode 100644 index d651a2447..000000000 --- a/db/.archive/231801/00-saleTracking.sql +++ /dev/null @@ -1,5 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`sale_setQuantity`; -DROP PROCEDURE IF EXISTS `vn`.`collection_updateSale`; -DROP PROCEDURE IF EXISTS `vn`.`replaceMovimientosMark`; -DROP PROCEDURE IF EXISTS `vn`.`saleTracking_Replace`; -DROP PROCEDURE IF EXISTS `vn`.`sale_updateOriginalQuantity`; diff --git a/db/.archive/231801/00-ticketConfig.sql b/db/.archive/231801/00-ticketConfig.sql deleted file mode 100644 index 7c8aa83a4..000000000 --- a/db/.archive/231801/00-ticketConfig.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`ticketConfig` ADD daysForWarningClaim INT DEFAULT 2 NOT NULL COMMENT 'dias restantes hasta que salte el aviso de reclamación fuera de plazo'; diff --git a/db/.archive/231801/00-updateIsVies.sql b/db/.archive/231801/00-updateIsVies.sql deleted file mode 100644 index 4e5277559..000000000 --- a/db/.archive/231801/00-updateIsVies.sql +++ /dev/null @@ -1,5 +0,0 @@ - UPDATE `vn`.`supplier` s - JOIN `vn`.`country` c ON c.id = s.countryFk - SET s.nif = MID(REPLACE(s.nif, ' ', ''), 3, LENGTH(REPLACE(s.nif, ' ', '')) - 1) - WHERE s.isVies = TRUE - AND c.code = LEFT(REPLACE(s.nif, ' ', ''), 2); diff --git a/db/.archive/231801/00-updateisViesClient.sql b/db/.archive/231801/00-updateisViesClient.sql deleted file mode 100644 index a153c5219..000000000 --- a/db/.archive/231801/00-updateisViesClient.sql +++ /dev/null @@ -1,5 +0,0 @@ -UPDATE IGNORE `vn`.`client` c - JOIN `vn`.`country` co ON co.id = c.countryFk - SET c.fi = MID(REPLACE(c.fi, ' ', ''), 3, LENGTH(REPLACE(c.fi, ' ', '')) - 1) - WHERE c.isVies = TRUE - AND co.code = LEFT(REPLACE(c.fi, ' ', ''), 2); diff --git a/db/.archive/231801/00-userAcl.sql b/db/.archive/231801/00-userAcl.sql deleted file mode 100644 index 9eb3ebf28..000000000 --- a/db/.archive/231801/00-userAcl.sql +++ /dev/null @@ -1,20 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('VnUser','acl','READ','ALLOW','ROLE','account'), - ('VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'), - ('VnUser','changePassword', 'WRITE', 'ALLOW', 'ROLE', 'account'), - ('Account','exists','READ','ALLOW','ROLE','account'); - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('Account','exists','READ','ALLOW','ROLE','account'); - -DELETE FROM `salix`.`ACL` WHERE (model, property) = ('Account', 'acl'); -DELETE FROM `salix`.`ACL` WHERE (model, property) = ('Account', 'getCurrentUserData'); -DELETE FROM `salix`.`ACL` WHERE (model, property) = ('Account', 'changePassword'); -DELETE FROM `salix`.`ACL` WHERE model = 'UserAccount'; - -UPDATE `hedera`.`imageCollection` t -SET t.model = 'VnUser' -WHERE t.id = 6; - diff --git a/db/.archive/231801/00-userRoleLog.sql b/db/.archive/231801/00-userRoleLog.sql deleted file mode 100644 index ae5da13cb..000000000 --- a/db/.archive/231801/00-userRoleLog.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('UserLog', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('RoleLog', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/231801/01-viewCompany10L.sql b/db/.archive/231801/01-viewCompany10L.sql deleted file mode 100644 index 335827b42..000000000 --- a/db/.archive/231801/01-viewCompany10L.sql +++ /dev/null @@ -1,12 +0,0 @@ --- vn.companyL10n source - -CREATE OR REPLACE -ALGORITHM = UNDEFINED VIEW `vn`.`companyL10n` AS -select - `c`.`id` AS `id`, - ifnull(`ci`.`footnotes`, `c`.`footnotes`) AS `footnotes` -from - (`vn`.`company` `c` -left join `vn`.`companyI18n` `ci` on - (`ci`.`companyFk` = `c`.`id` - and `ci`.`lang` = `util`.`LANG`())); \ No newline at end of file diff --git a/db/.archive/232001/00-clientWorkerName.sql b/db/.archive/232001/00-clientWorkerName.sql deleted file mode 100644 index 676d26691..000000000 --- a/db/.archive/232001/00-clientWorkerName.sql +++ /dev/null @@ -1,73 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientCreate`( - vFirstname VARCHAR(50), - vSurnames VARCHAR(50), - vFi VARCHAR(9), - vAddress TEXT, - vPostcode CHAR(5), - vCity VARCHAR(25), - vProvinceFk SMALLINT(5), - vCompanyFk SMALLINT(5), - vPhone VARCHAR(11), - vEmail VARCHAR(255), - vUserFk INT) -BEGIN -/** - * Create new client - * - */ - DECLARE vPayMethodFk INT DEFAULT 4; - DECLARE vDueDay INT DEFAULT 5; - DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00; - DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; - DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE; - DECLARE vMandateTypeFk INT DEFAULT 2; - - INSERT INTO `client` ( - id, - name, - street, - fi, - phone, - email, - provinceFk, - city, - postcode, - socialName, - payMethodFk, - dueDay, - credit, - isTaxDataChecked, - hasCoreVnl, - isEqualizated) - VALUES ( - vUserFk, - CONCAT(vFirstname, ' ', vSurnames), - vAddress, - TRIM(vFi), - vPhone, - vEmail, - vProvinceFk, - vCity, - vPostcode, - CONCAT(vSurnames, ' ', vFirstname), - vPayMethodFk, - vDueDay, - vDefaultCredit, - vIsTaxDataChecked, - vHasCoreVnl, - FALSE - ) ON duplicate key update - payMethodFk = vPayMethodFk, - dueDay = vDueDay, - credit = vDefaultCredit, - isTaxDataChecked = vIsTaxDataChecked, - hasCoreVnl = vHasCoreVnl, - isActive = TRUE; - - IF (SELECT COUNT(*) FROM mandate WHERE clientFk = vUserFk AND companyFk = vCompanyFk AND mandateTypeFk = vMandateTypeFk) = 0 THEN - INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) - VALUES (vUserFk, vCompanyFk, vMandateTypeFk); - END IF; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/.archive/232001/00-createWorker.sql b/db/.archive/232001/00-createWorker.sql deleted file mode 100644 index 0ea7ecbe8..000000000 --- a/db/.archive/232001/00-createWorker.sql +++ /dev/null @@ -1,14 +0,0 @@ -INSERT INTO `vn`.`businessType` (`code`, `description`) - VALUES ('worker','Trabajador'); - -ALTER TABLE `vn`.`workerConfig` ADD businessTypeFk varchar(100) NULL - COMMENT 'Tipo de negocio por defecto al dar de alta un trabajador nuevo'; - -UPDATE `vn`.`workerConfig` - SET businessTypeFk = 'worker' - WHERE id = 1; - - UPDATE `vn`.`client` c - JOIN `vn`.`worker` w ON w.id = c.id - SET c.name = REPLACE(c.name, 'TR ', ''), - c.businessTypeFk = 'worker'; diff --git a/db/.archive/232001/00-wagon.sql b/db/.archive/232001/00-wagon.sql deleted file mode 100644 index bdb384db5..000000000 --- a/db/.archive/232001/00-wagon.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`wagon` ADD CONSTRAINT `wagon_type` FOREIGN KEY (`typeFk`) REFERENCES `wagonType` (`id`) ON UPDATE CASCADE; diff --git a/db/.archive/232201/00-defaulterView.sql b/db/.archive/232201/00-defaulterView.sql deleted file mode 100644 index 8b56e5945..000000000 --- a/db/.archive/232201/00-defaulterView.sql +++ /dev/null @@ -1,20 +0,0 @@ --- vn.defaulter source - -CREATE OR REPLACE -ALGORITHM = UNDEFINED VIEW `vn`.`defaulter` AS -select - `d`.`clientFk` AS `clientFk`, - `d`.`created` AS `created`, - `d`.`amount` AS `amount`, - `d`.`defaulterSinced` AS `defaulterSinced`, - `d`.`hasChanged` AS `hasChanged`, - `c`.`countryFk` AS `country`, - `c`.`payMethodFk` AS `payMethod` -from - (((`bs`.`defaulter` `d` -join `vn`.`client` `c` on - (`c`.`id` = `d`.`clientFk`)) -join `vn`.`country` `co` on - (`co`.`id` = `c`.`countryFk`)) -join `vn`.`payMethod` `pm` on - (`pm`.`id` = `c`.`payMethodFk`)); \ No newline at end of file diff --git a/db/.archive/232201/00-procedurecanAdvance.sql b/db/.archive/232201/00-procedurecanAdvance.sql deleted file mode 100644 index 9d5c24296..000000000 --- a/db/.archive/232201/00-procedurecanAdvance.sql +++ /dev/null @@ -1,127 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) -SELECT - origin.ticketFk futureId, - dest.ticketFk id, - dest.state, - origin.futureState, - origin.futureIpt, - dest.ipt, - origin.workerFk, - origin.futureLiters, - origin.futureLines, - dest.shipped, - origin.shipped futureShipped, - dest.totalWithVat, - origin.totalWithVat futureTotalWithVat, - dest.agency, - origin.futureAgency, - dest.lines, - dest.liters, - origin.futureLines - origin.hasStock AS notMovableLines, - (origin.futureLines = origin.hasStock) AS isFullMovable, - origin.classColor, - dest.classColor futureClassColor - FROM ( - SELECT - s.ticketFk, - t.workerFk, - t.shipped, - t.totalWithVat, - st.name futureState, - t.addressFk, - am.name futureAgency, - count(s.id) futureLines, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, - st.classColor - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) origin - JOIN ( - SELECT - t.id ticketFk, - t.addressFk, - st.name state, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t.shipped, - t.totalWithVat, - am.name agency, - CAST(SUM(litros) AS DECIMAL(10,0)) liters, - CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, - st.classColor - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t.warehouseFk = vWarehouseFk - AND st.order <= 5 - GROUP BY t.id - ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock != 0; - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; \ No newline at end of file diff --git a/db/.archive/232201/00-workerConfigPayMethod.sql b/db/.archive/232201/00-workerConfigPayMethod.sql deleted file mode 100644 index 8896f636d..000000000 --- a/db/.archive/232201/00-workerConfigPayMethod.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE `vn`.`workerConfig` ADD payMethodFk tinyint(3) unsigned NULL; -ALTER TABLE `vn`.`workerConfig` ADD CONSTRAINT workerConfig_FK FOREIGN KEY (roleFk) REFERENCES account.`role`(id) ON DELETE RESTRICT ON UPDATE CASCADE; -ALTER TABLE `vn`.`workerConfig` ADD CONSTRAINT workerConfig_FK_1 FOREIGN KEY (payMethodFk) REFERENCES `vn`.`payMethod`(id) ON DELETE SET NULL ON UPDATE CASCADE; - -UPDATE `vn`.`workerConfig` - SET payMethodFk = 4 - WHERE id=1; diff --git a/db/.archive/232202/00-procedurecanAdvance.sql b/db/.archive/232202/00-procedurecanAdvance.sql deleted file mode 100644 index d82294b3c..000000000 --- a/db/.archive/232202/00-procedurecanAdvance.sql +++ /dev/null @@ -1,127 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) -SELECT - origin.ticketFk futureId, - dest.ticketFk id, - dest.state, - origin.futureState, - origin.futureIpt, - dest.ipt, - origin.workerFk, - origin.futureLiters, - origin.futureLines, - dest.shipped, - origin.shipped futureShipped, - dest.totalWithVat, - origin.totalWithVat futureTotalWithVat, - dest.agency, - origin.futureAgency, - dest.lines, - dest.liters, - origin.futureLines - origin.hasStock AS notMovableLines, - (origin.futureLines = origin.hasStock) AS isFullMovable, - origin.classColor futureClassColor, - dest.classColor - FROM ( - SELECT - s.ticketFk, - t.workerFk, - t.shipped, - t.totalWithVat, - st.name futureState, - t.addressFk, - am.name futureAgency, - count(s.id) futureLines, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, - st.classColor - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) origin - JOIN ( - SELECT - t.id ticketFk, - t.addressFk, - st.name state, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t.shipped, - t.totalWithVat, - am.name agency, - CAST(SUM(litros) AS DECIMAL(10,0)) liters, - CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, - st.classColor - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t.warehouseFk = vWarehouseFk - AND st.order <= 5 - GROUP BY t.id - ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock != 0; - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; diff --git a/db/.archive/232401/00-buyConfig_travelConfig.sql b/db/.archive/232401/00-buyConfig_travelConfig.sql deleted file mode 100644 index 0f73ddc8c..000000000 --- a/db/.archive/232401/00-buyConfig_travelConfig.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE `vn`.`buyConfig` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `monthsAgo` int(11) NOT NULL DEFAULT 6 COMMENT 'Meses desde la última compra', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -CREATE TABLE `vn`.`travelConfig` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `warehouseInFk` smallint(6) unsigned NOT NULL DEFAULT 8 COMMENT 'Warehouse de origen', - `warehouseOutFk` smallint(6) unsigned NOT NULL DEFAULT 60 COMMENT 'Warehouse destino', - `agencyFk` int(11) NOT NULL DEFAULT 1378 COMMENT 'Agencia por defecto', - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442 COMMENT 'Compañía por defecto', - PRIMARY KEY (`id`), - KEY `travelConfig_FK` (`warehouseInFk`), - KEY `travelConfig_FK_1` (`warehouseOutFk`), - KEY `travelConfig_FK_2` (`agencyFk`), - KEY `travelConfig_FK_3` (`companyFk`), - CONSTRAINT `travelConfig_FK` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `travelConfig_FK_1` FOREIGN KEY (`warehouseOutFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `travelConfig_FK_2` FOREIGN KEY (`agencyFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `travelConfig_FK_3` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Entry', 'addFromPackaging', 'WRITE', 'ALLOW', 'ROLE', 'production'), - ('Entry', 'addFromBuy', 'WRITE', 'ALLOW', 'ROLE', 'production'), - ('Supplier', 'getItemsPackaging', 'READ', 'ALLOW', 'ROLE', 'production'); diff --git a/db/.archive/232401/00-printer.sql b/db/.archive/232401/00-printer.sql deleted file mode 100644 index 6280c2c6d..000000000 --- a/db/.archive/232401/00-printer.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `vn`.`sector` DROP COLUMN `printerFk`; -ALTER TABLE `vn`.`sector` ADD COLUMN `mainPrinterFk` tinyint(3) unsigned; -ALTER TABLE `vn`.`sector` ADD CONSTRAINT sector_FK_1 FOREIGN KEY (mainPrinterFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/.archive/232401/00-ticket_warehouse.sql b/db/.archive/232401/00-ticket_warehouse.sql deleted file mode 100644 index b5255ee3f..000000000 --- a/db/.archive/232401/00-ticket_warehouse.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`ticket` MODIFY COLUMN warehouseFk smallint(6) unsigned DEFAULT NULL NULL; diff --git a/db/.archive/232401/00-userPassExpired.sql b/db/.archive/232401/00-userPassExpired.sql deleted file mode 100644 index 2d4b45937..000000000 --- a/db/.archive/232401/00-userPassExpired.sql +++ /dev/null @@ -1,76 +0,0 @@ -ALTER TABLE `account`.`user` ADD passExpired DATE DEFAULT NULL; - -DROP PROCEDURE `account`.`myUser_changePassword`; -DROP PROCEDURE `account`.`myUser_restorePassword`; -DROP PROCEDURE `account`.`user_changePassword`; -DROP PROCEDURE `account`.`user_restorePassword`; -DROP PROCEDURE `account`.`user_setPassword`; - -ALTER TABLE account.`user` CHANGE password password__ char(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT 'Deprecated'; -ALTER TABLE account.`user` CHANGE bcryptPassword password varchar(512) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; - -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_beforeUpdate` - BEFORE UPDATE ON `user` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF !(NEW.`name` <=> OLD.`name`) THEN - CALL user_checkName (NEW.`name`); - END IF; - - IF !(NEW.`password` <=> OLD.`password`) THEN - SET NEW.lastPassChange = util.VN_NOW(); - END IF; -END$$ -DELIMITER ; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `account`.`accountDovecot` AS -select - `u`.`name` AS `name`, - `u`.`password` AS `password` -from - (`account`.`user` `u` -join `account`.`account` `a` on - (`a`.`id` = `u`.`id`)) -where - `u`.`active` <> 0; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `salix`.`User` AS -select - `account`.`user`.`id` AS `id`, - `account`.`user`.`realm` AS `realm`, - `account`.`user`.`name` AS `username`, - `account`.`user`.`password` AS `password`, - `account`.`user`.`email` AS `email`, - `account`.`user`.`emailVerified` AS `emailVerified`, - `account`.`user`.`verificationToken` AS `verificationToken` -from - `account`.`user`; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`workerTimeControlUserInfo` AS -select - `u`.`id` AS `userFk`, - `w`.`firstName` AS `name`, - `w`.`lastName` AS `surname`, - `u`.`name` AS `user`, - `u`.`password` AS `password`, - `wd`.`departmentFk` AS `departmentFk`, - left(`c`.`fi`, - 8) AS `dni` -from - (((`account`.`user` `u` -join `vn`.`worker` `w` on - (`w`.`userFk` = `u`.`id`)) -join `vn`.`client` `c` on - (`c`.`id` = `u`.`id`)) -left join `vn`.`workerDepartment` `wd` on - (`wd`.`workerFk` = `w`.`id`)); diff --git a/db/.archive/232402/00-hotFix_travelConfig.sql b/db/.archive/232402/00-hotFix_travelConfig.sql deleted file mode 100644 index 65450a74d..000000000 --- a/db/.archive/232402/00-hotFix_travelConfig.sql +++ /dev/null @@ -1,22 +0,0 @@ -CREATE TABLE `vn`.`travelConfig` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `warehouseInFk` smallint(6) unsigned NOT NULL DEFAULT 8 COMMENT 'Warehouse de origen', - `warehouseOutFk` smallint(6) unsigned NOT NULL DEFAULT 60 COMMENT 'Warehouse destino', - `agencyFk` int(11) NOT NULL DEFAULT 1378 COMMENT 'Agencia por defecto', - `companyFk` int(10) unsigned NOT NULL DEFAULT 442 COMMENT 'Compañía por defecto', - PRIMARY KEY (`id`), - KEY `travelConfig_FK` (`warehouseInFk`), - KEY `travelConfig_FK_1` (`warehouseOutFk`), - KEY `travelConfig_FK_2` (`agencyFk`), - KEY `travelConfig_FK_3` (`companyFk`), - CONSTRAINT `travelConfig_FK` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `travelConfig_FK_1` FOREIGN KEY (`warehouseOutFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `travelConfig_FK_2` FOREIGN KEY (`agencyFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `travelConfig_FK_3` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Entry', 'addFromPackaging', 'WRITE', 'ALLOW', 'ROLE', 'production'), - ('Entry', 'addFromBuy', 'WRITE', 'ALLOW', 'ROLE', 'production'), - ('Supplier', 'getItemsPackaging', 'READ', 'ALLOW', 'ROLE', 'production'); diff --git a/db/.archive/232601/00-aclAccount.sql b/db/.archive/232601/00-aclAccount.sql deleted file mode 100644 index bf8106b98..000000000 --- a/db/.archive/232601/00-aclAccount.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELETE - FROM `salix`.`ACL` - WHERE model='Account' AND property='*' AND accessType='*'; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('Account', '*', 'WRITE', 'ALLOW', 'ROLE', 'sysadmin'), - ('Account', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/232601/00-aclInvoiceTickets.sql b/db/.archive/232601/00-aclInvoiceTickets.sql deleted file mode 100644 index 2c221950e..000000000 --- a/db/.archive/232601/00-aclInvoiceTickets.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES('Ticket', 'invoiceTickets', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/232601/00-aclMailAliasAccount.sql b/db/.archive/232601/00-aclMailAliasAccount.sql deleted file mode 100644 index 619e9bb6e..000000000 --- a/db/.archive/232601/00-aclMailAliasAccount.sql +++ /dev/null @@ -1,5 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount'; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('MailAliasAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement'); diff --git a/db/.archive/232601/00-aclMailForward.sql b/db/.archive/232601/00-aclMailForward.sql deleted file mode 100644 index afe2acec8..000000000 --- a/db/.archive/232601/00-aclMailForward.sql +++ /dev/null @@ -1,5 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE model = 'MailForward'; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('MailForward', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('MailForward', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement'); diff --git a/db/.archive/232601/00-aclRole.sql b/db/.archive/232601/00-aclRole.sql deleted file mode 100644 index e16f052be..000000000 --- a/db/.archive/232601/00-aclRole.sql +++ /dev/null @@ -1,5 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE model = 'Role'; -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Role', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Role', '*', 'WRITE', 'ALLOW', 'ROLE', 'it'); diff --git a/db/.archive/232601/00-aclVnUser.sql b/db/.archive/232601/00-aclVnUser.sql deleted file mode 100644 index 39fa2cb14..000000000 --- a/db/.archive/232601/00-aclVnUser.sql +++ /dev/null @@ -1,10 +0,0 @@ -DELETE - FROM `salix`.`ACL` - WHERE model = 'VnUser' AND property = '*' AND principalId = 'employee'; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('VnUser', '*', '*', 'ALLOW', 'ROLE', 'itManagement'), - ('VnUser', '__get__preview', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('VnUser', 'preview', '*', 'ALLOW', 'ROLE', 'employee'), - ('VnUser', 'create', '*', 'ALLOW', 'ROLE', 'itManagement'); diff --git a/db/.archive/232601/00-aclVnUser_renewToken.sql b/db/.archive/232601/00-aclVnUser_renewToken.sql deleted file mode 100644 index aa20f7a82..000000000 --- a/db/.archive/232601/00-aclVnUser_renewToken.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('VnUser', 'renewToken', 'WRITE', 'ALLOW', 'ROLE', 'employee') diff --git a/db/.archive/232601/00-salix.sql b/db/.archive/232601/00-salix.sql deleted file mode 100644 index 44366abce..000000000 --- a/db/.archive/232601/00-salix.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `salix`.`accessTokenConfig` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `renewPeriod` int(10) unsigned DEFAULT NULL, - `courtesyTime` int(10) unsigned DEFAULT NULL, - `renewInterval` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`) - VALUES - (1, 21600, 5, 300); diff --git a/db/.archive/232601/00-useSpecificsAcls.sql b/db/.archive/232601/00-useSpecificsAcls.sql deleted file mode 100644 index d124786f6..000000000 --- a/db/.archive/232601/00-useSpecificsAcls.sql +++ /dev/null @@ -1,121 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Ticket', 'editDiscount', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), - ('Ticket', 'editDiscount', 'WRITE', 'ALLOW', 'ROLE', 'salesPerson'), - ('Ticket', 'isRoleAdvanced', '*', 'ALLOW', 'ROLE', 'salesAssistant'), - ('Ticket', 'isRoleAdvanced', '*', 'ALLOW', 'ROLE', 'deliveryAssistant'), - ('Ticket', 'isRoleAdvanced', '*', 'ALLOW', 'ROLE', 'buyer'), - ('Ticket', 'isRoleAdvanced', '*', 'ALLOW', 'ROLE', 'claimManager'), - ('Ticket', 'deleteTicketWithPartPrepared', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'), - ('Ticket', 'editZone', 'WRITE', 'ALLOW', 'ROLE', 'deliveryAssistant'), - ('State', 'editableStates', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('State', 'seeEditableStates', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('State', 'seeEditableStates', 'READ', 'ALLOW', 'ROLE', 'production'), - ('State', 'isSomeEditable', 'READ', 'ALLOW', 'ROLE', 'salesPerson'), - ('State', 'isAllEditable', 'READ', 'ALLOW', 'ROLE', 'production'), - ('State', 'isAllEditable', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('Agency', 'seeExpired', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('Agency', 'seeExpired', 'READ', 'ALLOW', 'ROLE', 'productionBoss'), - ('Claim', 'createAfterDeadline', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), - ('Client', 'editAddressLogifloraAllowed', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'), - ('Client', 'editFiscalDataWithoutTaxDataCheck', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'), - ('Client', 'editVerifiedDataWithoutTaxDataCheck', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'), - ('Client', 'editCredit', 'WRITE', 'ALLOW', 'ROLE', 'financialBoss'), - ('Client', 'isNotEditableCredit', 'WRITE', 'ALLOW', 'ROLE', 'financialBoss'), - ('InvoiceOut', 'canCreatePdf', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'), - ('Supplier', 'editPayMethodCheck', 'WRITE', 'ALLOW', 'ROLE', 'financial'), - ('Worker', 'isTeamBoss', 'WRITE', 'ALLOW', 'ROLE', 'teamBoss'), - ('Worker', 'forceIsSubordinate', 'READ', 'ALLOW', 'ROLE', 'hr'), - ('Claim', 'editState', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'); - -DELETE FROM `salix`.`ACL` - WHERE - model = 'Claim' - AND property = '*' - AND accessType = '*'; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Claim', 'find', 'READ', 'ALLOW', 'ROLE', 'salesPerson'), - ('Claim', 'findById', 'READ', 'ALLOW', 'ROLE', 'salesPerson'), - ('Claim', 'findOne', 'READ', 'ALLOW', 'ROLE', 'salesPerson'), - ('Claim', 'getSummary', 'READ', 'ALLOW', 'ROLE', 'salesPerson'), - ('Claim', 'updateClaim', 'WRITE', 'ALLOW', 'ROLE', 'salesPerson'), - ('Claim', 'regularizeClaim', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), - ('Claim', 'updateClaimDestination', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), - ('Claim', 'downloadFile', 'READ', 'ALLOW', 'ROLE', 'claimManager'), - ('Claim', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'), - ('Claim', 'filter', 'READ', 'ALLOW', 'ROLE', 'salesPerson'), - ('Claim', 'logs', 'READ', 'ALLOW', 'ROLE', 'claimManager'); - -DELETE FROM `salix`.`ACL` - WHERE - model = 'Ticket' - AND property = '*' - AND accessType = '*'; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Ticket', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'findById', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'getVolume', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'getTotalVolume', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'summary', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'priceDifference', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'componentUpdate', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'new', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'isEditable', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'setDeleted', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'restore', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'getSales', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'getSalesPersonMana', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'makeInvoice', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'updateEditableTicket', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'updateDiscount', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'transferSales', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'sendSms', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'isLocked', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'freightCost', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'getComponentsSum', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Ticket', 'updateAttributes', 'WRITE', 'ALLOW', 'ROLE', 'delivery'), -- Change Priority in Route tickets - ('Ticket', 'deliveryNoteCsv', 'READ', 'ALLOW', 'ROLE', 'employee'); - -DELETE FROM `salix`.`ACL` - WHERE - model = 'State' - AND property = '*' - AND accessType = 'READ'; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('State', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('State', 'findById', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('State', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'); - -DELETE FROM `salix`.`ACL` - WHERE - model = 'Worker' - AND property = '*' - AND accessType = 'READ'; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Worker', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'findById', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'getWorkedHours', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'active', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'activeWithRole', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'uploadFile', 'WRITE', 'ALLOW', 'ROLE', 'hr'), - ('Worker', 'contracts', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'holidays', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'activeContract', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'activeWithInheritedRole', 'READ', 'ALLOW', 'ROLE', 'employee'); - -DELETE FROM `salix`.`ACL` - WHERE model = 'Client' - AND property = 'updateUser' - AND accessType = '*'; diff --git a/db/.archive/232601/01-invoiceOutPdf.sql b/db/.archive/232601/01-invoiceOutPdf.sql deleted file mode 100644 index e013736df..000000000 --- a/db/.archive/232601/01-invoiceOutPdf.sql +++ /dev/null @@ -1,13 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES - ('InvoiceOut','makePdfAndNotify','WRITE','ALLOW','ROLE','invoicing'), - ('InvoiceOutConfig','*','READ','ALLOW','ROLE','invoicing'); - -CREATE OR REPLACE TABLE `vn`.`invoiceOutConfig` ( - id INT UNSIGNED auto_increment NOT NULL, - parallelism int UNSIGNED DEFAULT 1 NOT NULL, - PRIMARY KEY (id) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; diff --git a/db/.archive/232602/01-aclAddAlias.sql b/db/.archive/232602/01-aclAddAlias.sql deleted file mode 100644 index d4df3cd44..000000000 --- a/db/.archive/232602/01-aclAddAlias.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount'; - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('MailAliasAccount', 'create', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('MailAliasAccount', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('MailAliasAccount', 'canEditAlias', 'WRITE', 'ALLOW', 'ROLE', 'itManagement'); diff --git a/db/.archive/232801/00-authCode.sql b/db/.archive/232801/00-authCode.sql deleted file mode 100644 index a256db43f..000000000 --- a/db/.archive/232801/00-authCode.sql +++ /dev/null @@ -1,13 +0,0 @@ -create table `salix`.`authCode` -( - userFk int UNSIGNED not null, - code int not null, - expires bigint not null, - constraint authCode_pk - primary key (userFk), - constraint authCode_unique - unique (code), - constraint authCode_user_id_fk - foreign key (userFk) references `account`.`user` (id) - on update cascade on delete cascade -); diff --git a/db/.archive/232801/00-client_create.sql b/db/.archive/232801/00-client_create.sql deleted file mode 100644 index d21094dad..000000000 --- a/db/.archive/232801/00-client_create.sql +++ /dev/null @@ -1,89 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`clientCreate`; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_create`( - vFirstname VARCHAR(50), - vSurnames VARCHAR(50), - vFi VARCHAR(9), - vAddress TEXT, - vPostcode CHAR(5), - vCity VARCHAR(25), - vProvinceFk SMALLINT(5), - vCompanyFk SMALLINT(5), - vPhone VARCHAR(11), - vEmail VARCHAR(255), - vUserFk INT -) -BEGIN -/** - * Create new client - * - * @params vFirstname firstName - * @params vSurnames surnames - * @params vFi company code from accounting transactions - * @params vAddress address - * @params vPostcode postCode - * @params vCity city - * @params vProvinceFk province - * @params vCompanyFk company in which he has become a client - * @params vPhone telephone number - * @params vEmail email address - * @params vUserFk user id - */ - DECLARE vPayMethodFk INT; - DECLARE vDueDay INT; - DECLARE vDefaultCredit DECIMAL(10, 2); - DECLARE vIsTaxDataChecked TINYINT(1); - DECLARE vHasCoreVnl BOOLEAN; - DECLARE vMandateTypeFk INT; - - SELECT defaultPayMethodFk, - defaultDueDay, - defaultCredit, - defaultIsTaxDataChecked, - defaultHasCoreVnl, - defaultMandateTypeFk - INTO vPayMethodFk, - vDueDay, - vDefaultCredit, - vIsTaxDataChecked, - vHasCoreVnl, - vMandateTypeFk - FROM clientConfig; - - INSERT INTO `client` - SET id = vUserFk, - name = CONCAT(vFirstname, ' ', vSurnames), - street = vAddress, - fi = TRIM(vFi), - phone = vPhone, - email = vEmail, - provinceFk = vProvinceFk, - city = vCity, - postcode = vPostcode, - socialName = CONCAT(vSurnames, ' ', vFirstname), - payMethodFk = vPayMethodFk, - dueDay = vDueDay, - credit = vDefaultCredit, - isTaxDataChecked = vIsTaxDataChecked, - hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE - ON duplicate KEY UPDATE - payMethodFk = vPayMethodFk, - dueDay = vDueDay, - credit = vDefaultCredit, - isTaxDataChecked = vIsTaxDataChecked, - hasCoreVnl = vHasCoreVnl, - isActive = TRUE; - - INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) - SELECT vUserFk, vCompanyFk, vMandateTypeFk - WHERE NOT EXISTS ( - SELECT id - FROM mandate - WHERE clientFk = vUserFk - AND companyFk = vCompanyFk - AND mandateTypeFk = vMandateTypeFk - ); -END$$ -DELIMITER ; diff --git a/db/.archive/232801/00-client_create2.sql b/db/.archive/232801/00-client_create2.sql deleted file mode 100644 index f2e660351..000000000 --- a/db/.archive/232801/00-client_create2.sql +++ /dev/null @@ -1,17 +0,0 @@ -ALTER TABLE `vn`.`clientConfig` ADD defaultPayMethodFk tinyint(3) unsigned NULL; -ALTER TABLE `vn`.`clientConfig` ADD defaultDueDay int unsigned NULL; -ALTER TABLE `vn`.`clientConfig` ADD defaultCredit decimal(10, 2) NULL; -ALTER TABLE `vn`.`clientConfig` ADD defaultIsTaxDataChecked tinyint(1) NULL; -ALTER TABLE `vn`.`clientConfig` ADD defaultHasCoreVnl boolean NULL; -ALTER TABLE `vn`.`clientConfig` ADD defaultMandateTypeFk smallint(5) NULL; -ALTER TABLE `vn`.`clientConfig` ADD CONSTRAINT clientNewConfigPayMethod_FK FOREIGN KEY (defaultPayMethodFk) REFERENCES vn.payMethod(id); -ALTER TABLE `vn`.`clientConfig` ADD CONSTRAINT clientNewConfigMandateType_FK FOREIGN KEY (defaultMandateTypeFk) REFERENCES vn.mandateType(id); - -UPDATE `vn`.`clientConfig` - SET defaultPayMethodFk = 4, - defaultDueDay = 5, - defaultCredit = 300.0, - defaultIsTaxDataChecked = 1, - defaultHasCoreVnl = 1, - defaultMandateTypeFk = 2 - WHERE id = 1; diff --git a/db/.archive/232801/00-department.sql b/db/.archive/232801/00-department.sql deleted file mode 100644 index 3dcb8501d..000000000 --- a/db/.archive/232801/00-department.sql +++ /dev/null @@ -1,24 +0,0 @@ -alter table `vn`.`department` - add `twoFactor` ENUM ('email') null comment 'Default user two-factor auth type'; - -drop trigger `vn`.`department_afterUpdate`; - -DELIMITER $$ -$$ -create definer = root@localhost trigger `vn`.`department_afterUpdate` - after update - on department - for each row -BEGIN - IF !(OLD.parentFk <=> NEW.parentFk) THEN - UPDATE vn.department_recalc SET isChanged = TRUE; - END IF; - - IF !(OLD.twoFactor <=> NEW.twoFactor) THEN - UPDATE account.user u - JOIN vn.workerDepartment wd ON wd.workerFk = u.id - SET u.twoFactor = NEW.twoFactor - WHERE wd.departmentFk = NEW.id; - END IF; -END;$$ -DELIMITER ; diff --git a/db/.archive/232801/00-fix_editCredit.sql b/db/.archive/232801/00-fix_editCredit.sql deleted file mode 100644 index ff0d9e2b3..000000000 --- a/db/.archive/232801/00-fix_editCredit.sql +++ /dev/null @@ -1,13 +0,0 @@ -UPDATE `salix`.`ACL` - SET principalId='financialBoss' - WHERE - model = 'Client' - AND property = 'editCredit'; - -UPDATE `salix`.`ACL` - SET property='zeroCreditEditor' - WHERE - model = 'Client' - AND property = 'isNotEditableCredit'; - - diff --git a/db/.archive/232801/00-user.sql b/db/.archive/232801/00-user.sql deleted file mode 100644 index 376b3dbb1..000000000 --- a/db/.archive/232801/00-user.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table `account`.`user` - add `twoFactor` ENUM ('email') null comment 'Two-factor auth type'; - -DELETE FROM `salix`.`ACL` - WHERE model = 'VnUser' AND property = 'changePassword'; diff --git a/db/.archive/232802/01-aclWorkerDisable.sql b/db/.archive/232802/01-aclWorkerDisable.sql deleted file mode 100644 index 149dd6f15..000000000 --- a/db/.archive/232802/01-aclWorkerDisable.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('WorkerDisableExcluded', '*', 'READ', 'ALLOW', 'ROLE', 'itManagement'), - ('WorkerDisableExcluded', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement'); diff --git a/db/.archive/233001/.gitkeep b/db/.archive/233001/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/.archive/233001/00-aclSaleTracking.sql b/db/.archive/233001/00-aclSaleTracking.sql deleted file mode 100644 index 6a699091a..000000000 --- a/db/.archive/233001/00-aclSaleTracking.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('SaleTracking', 'deleteSaleGroupDetail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('SaleTracking', 'replaceOrCreate', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/233001/00-clientSms.sql b/db/.archive/233001/00-clientSms.sql deleted file mode 100644 index e1e34f6b2..000000000 --- a/db/.archive/233001/00-clientSms.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE `vn`.`clientSms` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `clientFk` int(11) NOT NULL, - `smsFk` mediumint(8) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `clientSms_FK` (`clientFk`), - KEY `clientSms_FK_1` (`smsFk`), - CONSTRAINT `clientSms_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, - CONSTRAINT `clientSms_FK_1` FOREIGN KEY (`smsFk`) REFERENCES `sms` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ClientSms', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('ClientSms', 'create', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/233001/00-company.sql b/db/.archive/233001/00-company.sql deleted file mode 100644 index a3b61b9cc..000000000 --- a/db/.archive/233001/00-company.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`company` MODIFY COLUMN sage200Company int(2) DEFAULT 10 NOT NULL; diff --git a/db/.archive/233001/00-fixACLVehicle.sql b/db/.archive/233001/00-fixACLVehicle.sql deleted file mode 100644 index 6625f0d5c..000000000 --- a/db/.archive/233001/00-fixACLVehicle.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('Vehicle','sorted','WRITE','ALLOW','employee'); \ No newline at end of file diff --git a/db/.archive/233001/00-itemRecycle.sql b/db/.archive/233001/00-itemRecycle.sql deleted file mode 100644 index c191e5d1c..000000000 --- a/db/.archive/233001/00-itemRecycle.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `vn`.`item` ADD recycledPlastic INT NULL; -ALTER TABLE `vn`.`item` ADD nonRecycledPlastic INT NULL; diff --git a/db/.archive/233001/00-itemShelving_inventory.sql b/db/.archive/233001/00-itemShelving_inventory.sql deleted file mode 100644 index b0b080ef3..000000000 --- a/db/.archive/233001/00-itemShelving_inventory.sql +++ /dev/null @@ -1,64 +0,0 @@ - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_inventory`(vParkingFromFk VARCHAR(8), vParkingToFk VARCHAR(8)) -BEGIN -/** - * Devuelve un listado de ubicaciones a revisar - * - * @param vParkingFromFk Parking de partida, identificador de parking - * @param vParkingToFk Parking de llegada, identificador de parking -*/ - - DECLARE vSectorFk INT; - DECLARE vPickingOrderFrom INT; - DECLARE vPickingOrderTo INT; - - SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom - FROM parking p - WHERE p.code = vParkingFromFk COLLATE 'utf8mb3_general_ci'; - - SELECT p.pickingOrder INTO vPickingOrderTo - FROM parking p - WHERE p.code = vParkingToFk COLLATE 'utf8mb3_general_ci'; - - CALL visible_getMisfit(vSectorFk); - - SELECT ish.id, - p.pickingOrder, - p.code parking, - ish.shelvingFk, - ish.itemFk, - i.longName, - ish.visible, - p.sectorFk, - it.workerFk buyer, - CONCAT('http:',ic.url, '/catalog/1600x900/',i.image) urlImage, - ish.isChecked, - CASE - WHEN s.notPrepared > sm.parked THEN 0 - WHEN sm.visible > sm.parked THEN 1 - ELSE 2 - END priority - FROM itemShelving ish - JOIN item i ON i.id = ish.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN (SELECT s.itemFk, sum(s.quantity) notPrepared - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - JOIN config c ON c.mainWarehouseFk = w.id - WHERE t.shipped BETWEEN util.VN_CURDATE() - AND util.dayEnd(util.VN_CURDATE()) - AND s.isPicked = FALSE - GROUP BY s.itemFk) s ON s.itemFk = i.id - JOIN hedera.imageConfig ic - WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo - AND p.sectorFk = vSectorFk - ORDER BY p.pickingOrder; - -END$$ -DELIMITER ; - diff --git a/db/.archive/233001/00-noUniqueSocialName.sql b/db/.archive/233001/00-noUniqueSocialName.sql deleted file mode 100644 index 0dc4c832f..000000000 --- a/db/.archive/233001/00-noUniqueSocialName.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `vn`.`country` -ADD COLUMN `isSocialNameUnique` tinyint(1) NOT NULL DEFAULT 1; diff --git a/db/.archive/233001/00-roadmap.sql b/db/.archive/233001/00-roadmap.sql deleted file mode 100644 index 9b5db54eb..000000000 --- a/db/.archive/233001/00-roadmap.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE `vn`.`roadmap` COMMENT='Troncales diarios que se contratan'; -ALTER TABLE `vn`.`roadmap` ADD price decimal(10,2) NULL; -ALTER TABLE `vn`.`roadmap` ADD driverName varchar(45) NULL; -ALTER TABLE `vn`.`roadmap` ADD name varchar(45) NOT NULL; -ALTER TABLE `vn`.`roadmap` CHANGE name name varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL AFTER id; -ALTER TABLE `vn`.`roadmap` MODIFY COLUMN etd datetime NOT NULL; - -ALTER TABLE `vn`.`expeditionTruck` COMMENT='Distintas paradas que hacen los trocales'; diff --git a/db/.archive/233001/00-roadmapACL.sql b/db/.archive/233001/00-roadmapACL.sql deleted file mode 100644 index 4fc116f86..000000000 --- a/db/.archive/233001/00-roadmapACL.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Roadmap', '*', '*', 'ALLOW', 'ROLE', 'palletizerBoss'), - ('Roadmap', '*', '*', 'ALLOW', 'ROLE', 'productionBoss'), - ('ExpeditionTruck', '*', '*', 'ALLOW', 'ROLE', 'palletizerBoss'), - ('ExpeditionTruck', '*', '*', 'ALLOW', 'ROLE', 'productionBoss'); diff --git a/db/.archive/233001/00-ticketWeight.sql b/db/.archive/233001/00-ticketWeight.sql deleted file mode 100644 index 0b727b434..000000000 --- a/db/.archive/233001/00-ticketWeight.sql +++ /dev/null @@ -1,7 +0,0 @@ -UPDATE `vn`.`ticket` t - JOIN `vn`.`ticketObservation` o ON o.ticketFk = t.id - SET t.weight = cast(REPLACE(o.description, ',', '.') as decimal(10,2)) - WHERE o.observationTypeFk = 6; - -DELETE FROM `vn`.`ticketObservation` WHERE observationTypeFk = 6; -DELETE FROM `vn`.`observationType` WHERE id = 6; diff --git a/db/.archive/233201/.gitkeep b/db/.archive/233201/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/.archive/233201/00-acl_viaexpressConfig.sql b/db/.archive/233201/00-acl_viaexpressConfig.sql deleted file mode 100644 index d4c186dd4..000000000 --- a/db/.archive/233201/00-acl_viaexpressConfig.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ViaexpressConfig', 'internationalExpedition', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('ViaexpressConfig', 'renderer', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/233201/00-transferClient.sql b/db/.archive/233201/00-transferClient.sql deleted file mode 100644 index 8a7ce0543..000000000 --- a/db/.archive/233201/00-transferClient.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'); \ No newline at end of file diff --git a/db/.archive/233201/00-updatePrice.sql b/db/.archive/233201/00-updatePrice.sql deleted file mode 100644 index 959943d6f..000000000 --- a/db/.archive/233201/00-updatePrice.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer'); diff --git a/db/.archive/233201/00-viaexpress.sql b/db/.archive/233201/00-viaexpress.sql deleted file mode 100644 index 42cf3b647..000000000 --- a/db/.archive/233201/00-viaexpress.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE `vn`.`viaexpressConfig` ( - id int auto_increment NOT NULL, - url varchar(100) NOT NULL, - client varchar(100) NOT NULL, - user varchar(100) NOT NULL, - password varchar(100) NOT NULL, - defaultWeight decimal(10,2) NOT NULL, - deliveryType varchar(5) NOT NULL, - CONSTRAINT viaexpressConfig_PK PRIMARY KEY (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/.archive/233201/00-workerDocuware.sql b/db/.archive/233201/00-workerDocuware.sql deleted file mode 100644 index 2f2c4a1cd..000000000 --- a/db/.archive/233201/00-workerDocuware.sql +++ /dev/null @@ -1,10 +0,0 @@ -ALTER TABLE `vn`.`docuware` ADD dmsTypeFk INT(11) DEFAULT NULL NULL; -ALTER TABLE `vn`.`docuware` ADD CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES `vn`.`dmsType`(id) ON DELETE RESTRICT ON UPDATE CASCADE; -INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById, dmsTypeFk) - VALUES - ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL); -- set dmsTypeFk 3 when deploy in production - -INSERT INTO `salix`.`url` (appName, environment, url) - VALUES - ('docuware', 'production', 'https://verdnatura.docuware.cloud/DocuWare/Platform/'); - diff --git a/db/.archive/233202/00-ticketSmsACL.sql b/db/.archive/233202/00-ticketSmsACL.sql deleted file mode 100644 index a25a876f8..000000000 --- a/db/.archive/233202/00-ticketSmsACL.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('TicketSms', 'find', 'READ', 'ALLOW', 'ROLE', 'salesPerson'); diff --git a/db/.archive/233401/00-setDeleted_acl.sql b/db/.archive/233401/00-setDeleted_acl.sql deleted file mode 100644 index cdeff9522..000000000 --- a/db/.archive/233401/00-setDeleted_acl.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE `salix`.`ACL` - SET principalId='salesPerson' - WHERE - model='Ticket' - AND property='setDeleted' - AND accessType='WRITE'; diff --git a/db/.archive/233601/.gitkeep b/db/.archive/233601/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/.archive/233601/00-aclWorker.sql b/db/.archive/233601/00-aclWorker.sql deleted file mode 100644 index e79d8f738..000000000 --- a/db/.archive/233601/00-aclWorker.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('Worker', 'search', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.archive/233601/00-addExpeditionState.sql b/db/.archive/233601/00-addExpeditionState.sql deleted file mode 100644 index fb236b0c3..000000000 --- a/db/.archive/233601/00-addExpeditionState.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('ExpeditionState','addExpeditionState','WRITE','ALLOW','ROLE','delivery'); \ No newline at end of file diff --git a/db/.archive/233601/00-department.sql b/db/.archive/233601/00-department.sql deleted file mode 100644 index 777d26b9f..000000000 --- a/db/.archive/233601/00-department.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE `vn`.`department` - SET code='VN' -WHERE name='VERDNATURA'; diff --git a/db/.archive/233601/00-saleGroupDetail.sql b/db/.archive/233601/00-saleGroupDetail.sql deleted file mode 100644 index d16478716..000000000 --- a/db/.archive/233601/00-saleGroupDetail.sql +++ /dev/null @@ -1,7 +0,0 @@ -DELETE FROM `vn`.`saleGroupDetail` WHERE id IN (468106,468104,468107,468105,495210,495208,495207,495209,462879,462880,447186,450623,450622,455606,455605,455827,455829,455828,459067,460689,460691,460690,460692,462408,463403,463405,463404,463129,463127,463126,463128,468098,468096,468099,468097,468310,468314,468313,475654,468325,473248,474803,474739,475042,475052,475047,475041,475051,475046,475040,475050,475045,475039,475049,475044,475038,475048,475043,474888,474892,474890,474887,474891,474889,481109,481107,481105,481108,481106,481110,479008,490787,490792,490791,485295,485294,485293,485528,490796,487853,487959,491303,490789,490914,490913,492305,492310,492307,492304,492309,492306,492303,492308,494111,494110,494480,494482,494481,494483,495202,495200,495199,495201,497209,499765,499763,499767,499764,499768,499766,502014,502013,508820,508819,508818,463133,463131,463130,463132,468102,468100,468103,468101,468311,468316,468315,468327,474894,474898,474896,474893,474897,474895,495206,495204,495203,495205,499771,499769,499773,499770,499774,499772); -ALTER TABLE `vn`.`saleGroupDetail` ADD CONSTRAINT saleGroupDetail_UN UNIQUE KEY (saleFk); - -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`) - VALUES - ('SaleGroupDetail','deleteById','WRITE','ALLOW','employee'); - diff --git a/db/.archive/233801/.gitkeep b/db/.archive/233801/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/.archive/233801/00-firstScript.sql b/db/.archive/233801/00-firstScript.sql deleted file mode 100644 index 47b96b3bc..000000000 --- a/db/.archive/233801/00-firstScript.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`province` ADD CONSTRAINT `countryName_UN` UNIQUE KEY (`countryFk`,`name`); diff --git a/db/.archive/233801/01-deviceLog_acl.sql b/db/.archive/233801/01-deviceLog_acl.sql deleted file mode 100644 index 2b646a6a3..000000000 --- a/db/.archive/233801/01-deviceLog_acl.sql +++ /dev/null @@ -1,6 +0,0 @@ - --- ALTER TABLE `vn`.`deviceLog` ADD serialNumber varchar(45) DEFAULT NULL NULL; - --- INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId) --- VALUES( 'DeviceLog', 'create', 'WRITE', 'ALLOW', 'ROLE', 'employee'); - diff --git a/db/.archive/233802/.gitkeep b/db/.archive/233802/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/.archive/233802/00-collectionGetTicketsACL.sql b/db/.archive/233802/00-collectionGetTicketsACL.sql deleted file mode 100644 index 06b584386..000000000 --- a/db/.archive/233802/00-collectionGetTicketsACL.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL`(model, property, accessType, permission, principalType, principalId) - VALUES - ('Collection', 'getTickets', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/.gitignore b/db/.gitignore index 34fb91784..b81ed39cc 100644 --- a/db/.gitignore +++ b/db/.gitignore @@ -1 +1,9 @@ -config.*.ini +.DS_Store +node_modules +remotes/*.ini +!remotes/local.ini +!remotes/docker.ini +dump/.changes +dump/fixtures.local.sql +.dBeaver +.idea diff --git a/db/Dockerfile b/db/Dockerfile deleted file mode 100644 index 0020e8950..000000000 --- a/db/Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM mariadb:10.11.6 - -ENV MYSQL_ROOT_PASSWORD root -ENV TZ Europe/Madrid -ARG MOCKDATE=2001-01-01 11:00:00 -ARG DEBIAN_FRONTEND=noninteractive - -COPY docker/docker.cnf /etc/mysql/conf.d/ -COPY \ - docker/docker-start.sh \ - docker/docker-init.sh \ - docker/docker-temp-stop.sh \ - docker/docker-dump.sh \ - docker/docker-structure.sh \ - docker/docker-fixtures.sh \ - /usr/local/bin/ - -RUN mkdir /mysql-data \ - && chown -R mysql:mysql /mysql-data - -WORKDIR /docker-boot - -COPY \ - import-changes.sh \ - config.ini \ - dump/structure.sql \ - dump/mockDate.sql \ - dump/dumpedFixtures.sql \ - ./ -RUN sed -i -e 's/@mockDate/'"$MOCKDATE"'/g' mockDate.sql \ - && gosu mysql docker-structure.sh -COPY changes ./changes -COPY dump/fixtures.sql ./ -RUN gosu mysql docker-fixtures.sh - -RUN echo "[INFO] -> Import finished" \ - && rm -rf /docker-boot - -USER mysql -ENTRYPOINT ["docker-start.sh"] - -CMD ["mysqld"] - -HEALTHCHECK --interval=2s --timeout=10s --retries=200 \ - CMD mysqladmin ping -h 127.0.0.1 -u root --password=root || exit 1 diff --git a/db/changes/234001/.gitkeep b/db/changes/234001/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/234001/00-aclClient.sql b/db/changes/234001/00-aclClient.sql deleted file mode 100644 index 109b3a4fb..000000000 --- a/db/changes/234001/00-aclClient.sql +++ /dev/null @@ -1,42 +0,0 @@ --- No encuentro este back -DELETE FROM `salix`.`ACL` WHERE property = 'activeWorkersWithRole'; -DELETE FROM `salix`.`ACL` WHERE model = 'Client' AND property = '*'; - -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Client','findOne','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Client','findById','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Client','find','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Client','exists','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Client','__get__addresses','READ','ALLOW','ROLE','employee'); - -DELETE FROM `salix`.`ACL` WHERE model = 'Client' AND property = '*' AND accessType IN ( - 'campaignMetricsEmail', - 'campaignMetricsPdf', - 'clientDebtStatementEmail', - 'clientDebtStatementHtml', - 'clientDebtStatementPdf', - 'clientWelcomeEmail', - 'clientWelcomeHtml', - 'consumptionSendQueued', - 'creditRequestEmail', - 'creditRequestHtml', - 'creditRequestPdf', - 'getClientOrSupplierReference', - 'incotermsAuthorizationEmail', - 'incotermsAuthorizationHtml', - 'incotermsAuthorizationPdf', - 'letterDebtorNdEmail', - 'letterDebtorNdHtml', - 'letterDebtorPdf', - 'letterDebtorStEmail', - 'letterDebtorStHtml', - 'printerSetupEmail', - 'printerSetupHtml', - 'sepaCoreEmail', - 'setPassword', - 'updateUser', - 'uploadFile'); diff --git a/db/changes/234001/00-dropUserFk.sql b/db/changes/234001/00-dropUserFk.sql deleted file mode 100644 index d6ce328a8..000000000 --- a/db/changes/234001/00-dropUserFk.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE `vn`.`worker` DROP KEY `user_id_UNIQUE`; - -ALTER TABLE `vn`.`worker` DROP COLUMN `userFk`; - diff --git a/db/changes/234001/00-models.sql b/db/changes/234001/00-models.sql deleted file mode 100644 index abf1e3ea5..000000000 --- a/db/changes/234001/00-models.sql +++ /dev/null @@ -1,11 +0,0 @@ -INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId) - VALUES - ('ExpeditionMistakeType', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('WorkerMistakeType', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('ExpeditionMistake','*','WRITE','ALLOW','ROLE','employee'), - ('WorkerMistake', '*', 'WRITE', 'ALLOW', 'ROLE', 'coolerBoss'), - ('MistakesTypes', '*', 'WRITE', 'ALLOW', 'ROLE', 'coolerBoss'), - ('MistakeType','*','READ','ALLOW','ROLE','employee'), - ('MachineWorker', '*', 'READ', 'ALLOW', 'ROLE', 'coolerAssist'), - ('Printer','*','READ','ALLOW','ROLE','employee'), - ('SaleMistake', '*', 'WRITE', 'ALLOW', 'ROLE', 'production'); diff --git a/db/changes/234001/00-ticketConfig.sql b/db/changes/234001/00-ticketConfig.sql deleted file mode 100644 index 5429878b4..000000000 --- a/db/changes/234001/00-ticketConfig.sql +++ /dev/null @@ -1,7 +0,0 @@ - - INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES('Item', 'setVisibleDiscard', 'WRITE', 'ALLOW', 'ROLE', 'employee'); - - INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES('Address', 'getAddress', 'READ', 'ALLOW', 'ROLE', 'employee'); - diff --git a/db/changes/234001/00-updateAfterBusinnesInsert.sql b/db/changes/234001/00-updateAfterBusinnesInsert.sql deleted file mode 100644 index 71356db80..000000000 --- a/db/changes/234001/00-updateAfterBusinnesInsert.sql +++ /dev/null @@ -1,57 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`account_enable`(vSelf INT) -BEGIN -/** - * Enables a worker's account and sets up email configurations. - */ - UPDATE user - SET active = TRUE - WHERE id = vSelf; - - INSERT IGNORE INTO account - SET id = vSelf; - - INSERT IGNORE INTO mailAliasAccount (mailAlias, account) - SELECT id, vSelf - FROM mailAlias - WHERE alias = 'general'; - - INSERT IGNORE INTO mailForward (account, forwardTo) - SELECT vSelf, email - FROM user - WHERE id = vSelf; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBusiness`(vSelf INT) -BEGIN -/** - * Activates an account and configures its email settings. - * - * @param vSelf account id. - */ - DECLARE vOldBusinessFk INT; - DECLARE vNewBusinessFk INT; - - SELECT businessFk INTO vOldBusinessFk FROM worker WHERE id = vSelf; - - SELECT id INTO vNewBusinessFk - FROM business - WHERE workerFk = vSelf - AND util.VN_CURDATE() BETWEEN started AND IFNULL(ended, util.VN_CURDATE()); - - UPDATE worker - SET businessFk = vNewBusinessFk - WHERE id = vSelf; - - IF NOT (vOldBusinessFk <=> vNewBusinessFk) THEN - IF vNewBusinessFk IS NULL THEN - CALL workerDisable(vSelf); - END IF; - IF vOldBusinessFk IS NULL THEN - CALL account.account_enable(vSelf); - END IF; - END IF; -END$$ -DELIMITER ; diff --git a/db/changes/234001/01-aclAccount.sql b/db/changes/234001/01-aclAccount.sql deleted file mode 100644 index d749b52ab..000000000 --- a/db/changes/234001/01-aclAccount.sql +++ /dev/null @@ -1,10 +0,0 @@ -DELETE FROM `salix`.`ACL` WHERE model = 'Account' AND property = '*' AND principalId = 'employee'; - -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Account','findOne','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Account','findById','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Account','find','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Account','exists','READ','ALLOW','ROLE','employee'); diff --git a/db/changes/234001/01-deliveryAssistantACL.sql b/db/changes/234001/01-deliveryAssistantACL.sql deleted file mode 100644 index 0f273325f..000000000 --- a/db/changes/234001/01-deliveryAssistantACL.sql +++ /dev/null @@ -1,21 +0,0 @@ --- Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values. -INSERT INTO `account`.`role` (name, description) - VALUES ('deliveryAssistant','Jefe auxiliar repartos'); - -INSERT INTO `account`.`roleInherit` (role, inheritsFrom) - SELECT (SELECT id FROM account.role r1 WHERE r1.name = 'deliveryAssistant'), ri.inheritsFrom - FROM account.roleInherit ri - JOIN account.role r2 ON r2.id = ri.`role` - WHERE r2.name = 'deliveryBoss'; - -DELETE `account`.`roleInherit` FROM `account`.`roleInherit` - JOIN `account`.`role` r ON `account`.`roleInherit`.role = r.id - WHERE r.name = 'deliveryBoss'; - -INSERT INTO `account`.`roleInherit` (role, inheritsFrom) - SELECT (SELECT id FROM account.role WHERE name = 'deliveryBoss') role, - (SELECT id FROM account.role WHERE name = 'deliveryAssistant') roleInherit; - -UPDATE `salix`.`ACL` - SET principalId='deliveryAssistant' - WHERE principalId='deliveryBoss'; diff --git a/db/changes/234001/01-workerCreate.sql b/db/changes/234001/01-workerCreate.sql deleted file mode 100644 index 166c65a26..000000000 --- a/db/changes/234001/01-workerCreate.sql +++ /dev/null @@ -1,20 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerCreate`( - vFirstname VARCHAR(50), - vLastName VARCHAR(50), - vCode CHAR(3), - vBossFk INT, - vUserFk INT, - vFi VARCHAR(15) , - vBirth DATE -) -BEGIN -/** - * Create new worker - * - */ - INSERT INTO worker(id, code, firstName, lastName, bossFk, fi, birth) - VALUES (vUserFk, vCode, vFirstname, vLastName, vBossFk, vFi, vBirth); -END$$ -DELIMITER ; diff --git a/db/changes/234001/02-roleSync.sql b/db/changes/234001/02-roleSync.sql deleted file mode 100644 index 6fe47f691..000000000 --- a/db/changes/234001/02-roleSync.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Locally it fails because it is executed before the fixtures and the roleConfig table is empty -CALL `account`.`role_syncPrivileges`(); diff --git a/db/changes/234002/.gitkeep b/db/changes/234002/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/234002/01-itemShelvingSale.sql b/db/changes/234002/01-itemShelvingSale.sql deleted file mode 100644 index 817c6317a..000000000 --- a/db/changes/234002/01-itemShelvingSale.sql +++ /dev/null @@ -1,291 +0,0 @@ -ALTER TABLE `vn`.`itemShelvingSale` DROP COLUMN IF EXISTS isPicked; - -ALTER TABLE`vn`.`itemShelvingSale` - ADD isPicked TINYINT(1) DEFAULT FALSE NOT NULL; - -ALTER TABLE `vn`.`productionConfig` DROP COLUMN IF EXISTS orderMode; - -ALTER TABLE `vn`.`productionConfig` - ADD orderMode ENUM('Location', 'Age') NOT NULL DEFAULT 'Location'; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserveByCollection`( - vCollectionFk INT(11) -) -BEGIN -/** - * Reserva cantidades con ubicaciones para el contenido de una colección - * - * @param vCollectionFk Identificador de collection - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) - ENGINE = MEMORY - SELECT s.id saleFk, NULL userFk - FROM ticketCollection tc - JOIN sale s ON s.ticketFk = tc.ticketFk - LEFT JOIN ( - SELECT DISTINCT saleFk - FROM saleTracking st - JOIN state s ON s.id = st.stateFk - WHERE st.isChecked - AND s.semaphore = 1)st ON st.saleFk = s.id - WHERE tc.collectionFk = vCollectionFk - AND st.saleFk IS NULL - AND NOT s.isPicked; - - CALL itemShelvingSale_reserve(); -END$$ -DELIMITER ; - - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setQuantity`( - vItemShelvingSaleFk INT(10), - vQuantity DECIMAL(10,0), - vIsItemShelvingSaleEmpty BOOLEAN -) -BEGIN -/** - * Gestiona la reserva de un itemShelvingFk, actualizando isPicked y quantity - * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. - * Si la reserva de la ubicación es fallida, se regulariza la situación - * - * @param vItemShelvingSaleFk Id itemShelvingSaleFK - * @param vQuantity Cantidad real que se ha cogido de la ubicación - * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha - * quedado vacio tras el movimiento - */ - DECLARE vSaleFk INT; - DECLARE vCursorSaleFk INT; - DECLARE vItemShelvingFk INT; - DECLARE vReservedQuantity INT; - DECLARE vRemainingQuantity INT; - DECLARE vItemFk INT; - DECLARE vUserFk INT; - DECLARE vDone BOOLEAN DEFAULT FALSE; - DECLARE vSales CURSOR FOR - SELECT iss.saleFk, iss.userFk - FROM itemShelvingSale iss - JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vItemShelvingSaleFk - AND s.itemFk = vItemFk - AND NOT iss.isPicked; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - IF (SELECT isPicked FROM itemShelvingSale WHERE id = vItemShelvingSaleFk) THEN - CALL util.throw('Booking completed'); - END IF; - - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk - INTO vItemFk, vSaleFk, vItemShelvingFk - FROM itemShelvingSale iss - JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vItemShelvingSaleFk - AND NOT iss.isPicked; - - UPDATE itemShelvingSale - SET isPicked = TRUE, - quantity = vQuantity - WHERE id = vItemShelvingSaleFk; - - UPDATE itemShelving - SET visible = IF(vIsItemShelvingSaleEmpty, 0, GREATEST(0,visible - vQuantity)) - WHERE id = vItemShelvingFk; - - IF vIsItemShelvingSaleEmpty THEN - OPEN vSales; -l: LOOP - SET vDone = FALSE; - FETCH vSales INTO vCursorSaleFk, vUserFk; - IF vDone THEN - LEAVE l; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk, userFk)) - ENGINE = MEMORY - SELECT vCursorSaleFk, vUserFk; - - CALL itemShelvingSale_reserveWhitUser(); - DROP TEMPORARY TABLE tmp.sale; - - END LOOP; - CLOSE vSales; - - DELETE iss - FROM itemShelvingSale iss - JOIN sale s ON s.id = iss.saleFk - WHERE iss.id = vItemShelvingSaleFk - AND s.itemFk = vItemFk - AND NOT iss.isPicked; - END IF; - - SELECT SUM(quantity) INTO vRemainingQuantity - FROM itemShelvingSale - WHERE saleFk = vSaleFk - AND NOT isPicked; - - IF vRemainingQuantity THEN - CALL itemShelvingSale_reserveBySale (vSaleFk, vRemainingQuantity, NULL); - - SELECT SUM(quantity) INTO vRemainingQuantity - FROM itemShelvingSale - WHERE saleFk = vSaleFk - AND NOT isPicked; - - IF NOT vRemainingQuantity <=> 0 THEN - SELECT SUM(iss.quantity) - INTO vReservedQuantity - FROM itemShelvingSale iss - WHERE iss.saleFk = vSaleFk; - - CALL saleTracking_new( - vSaleFk, - TRUE, - vReservedQuantity, - `account`.`myUser_getId`(), - NULL, - 'PREPARED', - TRUE); - - UPDATE sale s - SET s.quantity = vReservedQuantity - WHERE s.id = vSaleFk ; - END IF; - END IF; -END$$ -DELIMITER ; - - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserve`() -BEGIN -/** - * Reserva cantidades con ubicaciones para un conjunto de sales del mismo wareHouse - * - * @table tmp.sale(saleFk, userFk) - */ - DECLARE vCalcFk INT; - DECLARE vWarehouseFk INT; - DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); - DECLARE vLastPickingOrder INT; - - SELECT t.warehouseFk, MAX(p.pickingOrder) - INTO vWarehouseFk, vLastPickingOrder - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN tmp.sale ts ON ts.saleFk = s.id - LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk - LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - LEFT JOIN shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = sh.parkingFk - WHERE t.warehouseFk IS NOT NULL; - - IF vWarehouseFk IS NULL THEN - CALL util.throw('Warehouse not set'); - END IF; - - CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - - SET @outstanding = 0; - SET @oldsaleFk = 0; - - CREATE OR REPLACE TEMPORARY TABLE tSalePlacementQuantity - (INDEX(saleFk)) - ENGINE = MEMORY - SELECT saleFk, userFk, quantityToReserve, itemShelvingFk - FROM( SELECT saleFk, - sub.userFk, - itemShelvingFk , - IF(saleFk <> @oldsaleFk, @outstanding := quantity, @outstanding), - @qtr := LEAST(@outstanding, available) quantityToReserve, - @outStanding := @outStanding - @qtr, - @oldsaleFk := saleFk - FROM( - SELECT ts.saleFk, - ts.userFk, - s.quantity, - ish.id itemShelvingFk, - ish.visible - IFNULL(ishr.reservedQuantity, 0) available - FROM tmp.sale ts - JOIN sale s ON s.id = ts.saleFk - JOIN itemShelving ish ON ish.itemFk = s.itemFk - LEFT JOIN ( - SELECT itemShelvingFk, SUM(quantity) reservedQuantity - FROM itemShelvingSale - WHERE NOT isPicked - GROUP BY itemShelvingFk) ishr ON ishr.itemShelvingFk = ish.id - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector sc ON sc.id = p.sectorFk - JOIN warehouse w ON w.id = sc.warehouseFk - JOIN productionConfig pc - WHERE w.id = vWarehouseFk - AND NOT sc.isHideForPickers - ORDER BY - s.id, - p.pickingOrder >= vLastPickingOrder, - sh.priority DESC, - ish.visible >= s.quantity DESC, - s.quantity MOD ish.grouping = 0 DESC, - ish.grouping DESC, - IF(pc.orderMode = 'Location', p.pickingOrder, ish.created) - )sub - )sub2 - WHERE quantityToReserve > 0; - - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk) - SELECT itemShelvingFk, - saleFk, - quantityToReserve, - IFNULL(userFk, getUser()) - FROM tSalePlacementQuantity spl; - - DROP TEMPORARY TABLE tmp.sale; -END$$ -DELIMITER ; - - - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserveBySale`( - vSelf INT , - vQuantity INT, - vUserFk INT -) -BEGIN -/** - * Reserva cantida y ubicación para una saleFk - * - * @param vSelf Identificador de la venta - * @param vQuantity Cantidad a reservar - * @param vUserFk Id de usuario que realiza la reserva - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - ENGINE = MEMORY - SELECT vSelf saleFk, vUserFk userFk; - - CALL itemShelvingSale_reserve(); -END$$ -DELIMITER ; - - - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_AFTER_INSERT` - AFTER INSERT ON `itemShelvingSale` - FOR EACH ROW -BEGIN - - UPDATE vn.sale - SET isPicked = TRUE - WHERE id = NEW.saleFk; - -END$$ -DELIMITER ; diff --git a/db/changes/234003/00-ticket_canAdvance_zone.sql b/db/changes/234003/00-ticket_canAdvance_zone.sql deleted file mode 100644 index ee07ce978..000000000 --- a/db/changes/234003/00-ticket_canAdvance_zone.sql +++ /dev/null @@ -1,133 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. - * - * @param vDateFuture Fecha de los tickets que se quieren adelantar. - * @param vDateToAdvance Fecha a cuando se quiere adelantar. - * @param vWarehouseFk Almacén - */ - DECLARE vDateInventory DATE; - - SELECT inventoried INTO vDateInventory FROM config; - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE landed >= vDateInventory - AND landed < vDateFuture - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; - - CREATE OR REPLACE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT - origin.ticketFk futureId, - dest.ticketFk id, - dest.state, - origin.futureState, - origin.futureIpt, - dest.ipt, - origin.workerFk, - origin.futureLiters, - origin.futureLines, - dest.shipped, - origin.shipped futureShipped, - dest.totalWithVat, - origin.totalWithVat futureTotalWithVat, - dest.agency, - origin.futureAgency, - dest.lines, - dest.liters, - origin.futureLines - origin.hasStock AS notMovableLines, - (origin.futureLines = origin.hasStock) AS isFullMovable, - origin.futureZoneFk, - origin.futureZoneName, - origin.classColor futureClassColor, - dest.classColor - FROM ( - SELECT - s.ticketFk, - c.salesPersonFk workerFk, - t.shipped, - t.totalWithVat, - st.name futureState, - t.addressFk, - am.name futureAgency, - count(s.id) futureLines, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, - CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, - z.id futureZoneFk, - z.name futureZoneName, - st.classColor - FROM ticket t - JOIN client c ON c.id = t.clientFk - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - JOIN zone z ON t.zoneFk = z.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id - WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) origin - JOIN ( - SELECT - t.id ticketFk, - t.addressFk, - st.name state, - GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, - t.shipped, - t.totalWithVat, - am.name agency, - CAST(SUM(litros) AS DECIMAL(10,0)) liters, - CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, - st.classColor - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN state st ON st.id = ts.stateFk - JOIN agencyMode am ON t.agencyModeFk = am.id - LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) - AND t.warehouseFk = vWarehouseFk - AND st.order <= 5 - GROUP BY t.id - ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock != 0; - - DROP TEMPORARY TABLE tmp.stock; -END$$ -DELIMITER ; - diff --git a/db/changes/234004/.gitkeep b/db/changes/234004/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/234004/00-workerTimeControl.sql b/db/changes/234004/00-workerTimeControl.sql deleted file mode 100644 index 8f6263533..000000000 --- a/db/changes/234004/00-workerTimeControl.sql +++ /dev/null @@ -1,41 +0,0 @@ -UPDATE `vn`.`workerTimeControlConfig` - SET `timeToBreakTime` = 18000; - -ALTER TABLE `vn`.`workerTimeControlConfig` - DROP COLUMN IF EXISTS `maxTimeToBreak`; -ALTER TABLE `vn`.`workerTimeControlConfig` - ADD COLUMN maxTimeToBreak INT DEFAULT 3600 NULL; - -ALTER TABLE `vn`.`workerTimeControlConfig` - DROP COLUMN IF EXISTS `maxWorkShortCycle`; - -ALTER TABLE `vn`.`workerTimeControlConfig` - ADD COLUMN `maxWorkShortCycle` INT(10) UNSIGNED DEFAULT 561600 - COMMENT 'Máximo tiempo que un trabajador puede estar trabajando con el que adquirirá el derecho a un descanso semanal corto'; - -ALTER TABLE `vn`.`workerTimeControlConfig` - DROP COLUMN IF EXISTS `maxWorkLongCycle`; - -ALTER TABLE `vn`.`workerTimeControlConfig` - ADD COLUMN `maxWorkLongCycle` INT(10) UNSIGNED DEFAULT 950400 - COMMENT 'Máximo tiempo que un trabajador puede estar trabajando con el que adquirirá el derecho a un descanso semanal largo'; - -CREATE TABLE IF NOT EXISTS `vn`.`workerTimeControlError` ( - `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `code` char(35) NOT NULL, - `description` varchar(255) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `code` (`code`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT IGNORE INTO `vn`.`workerTimeControlError` (`code`, `description`) - VALUES - ('IS_NOT_ALLOWED_FUTURE', 'No se permite fichar a futuro'), - ('INACTIVE_BUSINESS', 'No hay un contrato en vigor'), - ('IS_NOT_ALLOWED_WORK', 'No está permitido trabajar'), - ('ODD_WORKERTIMECONTROL', 'Fichadas impares'), - ('DAY_MAX_TIME', 'Superado el tiempo máximo entre entrada y salida'), - ('BREAK_DAY', 'Descanso diario'), - ('BREAK_WEEK', 'Descanso semanal'), - ('WRONG_DIRECTION', 'Dirección incorrecta'), - ('UNDEFINED_ERROR', 'Error sin definir'); \ No newline at end of file diff --git a/db/changes/234201/.gitkeep b/db/changes/234201/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/234201/00-ACL_workerDepartment.sql b/db/changes/234201/00-ACL_workerDepartment.sql deleted file mode 100644 index ceb8d5d75..000000000 --- a/db/changes/234201/00-ACL_workerDepartment.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('WorkerDepartment', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/234201/00-account_acl.sql b/db/changes/234201/00-account_acl.sql deleted file mode 100644 index 8dfe1d1ec..000000000 --- a/db/changes/234201/00-account_acl.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('VnUser', 'higherPrivileges', '*', 'ALLOW', 'ROLE', 'itManagement'), - ('VnUser', 'mediumPrivileges', '*', 'ALLOW', 'ROLE', 'hr'), - ('VnUser', 'updateUser', '*', 'ALLOW', 'ROLE', 'employee'); - -ALTER TABLE `account`.`user` ADD `username` varchar(30) AS (name) VIRTUAL; diff --git a/db/changes/234201/00-aclClient.sql b/db/changes/234201/00-aclClient.sql deleted file mode 100644 index 3df9522cf..000000000 --- a/db/changes/234201/00-aclClient.sql +++ /dev/null @@ -1,3 +0,0 @@ - -INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId) - VALUES('TicketCollection', '*', 'WRITE', 'ALLOW', 'ROLE', 'production'); diff --git a/db/changes/234201/00-aclSetPassword.sql b/db/changes/234201/00-aclSetPassword.sql deleted file mode 100644 index 44b3e9de0..000000000 --- a/db/changes/234201/00-aclSetPassword.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) - VALUES ('Worker','setPassword','*','ALLOW','ROLE','employee'); - - diff --git a/db/changes/234201/00-aclUrlHedera.sql b/db/changes/234201/00-aclUrlHedera.sql deleted file mode 100644 index 79d9fb4c8..000000000 --- a/db/changes/234201/00-aclUrlHedera.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('hedera', 'test', 'https://test-shop.verdnatura.es/'), - ('hedera', 'production', 'https://shop.verdnatura.es/'); - -INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId) - VALUES('Url', 'getByUser', 'READ', 'ALLOW', 'ROLE', '$everyone'); diff --git a/db/changes/234201/00-dropWorkerCreate.sql b/db/changes/234201/00-dropWorkerCreate.sql deleted file mode 100644 index b903909b6..000000000 --- a/db/changes/234201/00-dropWorkerCreate.sql +++ /dev/null @@ -1 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`workerCreate`; diff --git a/db/changes/234201/00-packagingFk.sql b/db/changes/234201/00-packagingFk.sql deleted file mode 100644 index 9a775ada9..000000000 --- a/db/changes/234201/00-packagingFk.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `vn`.`buy` CHANGE `packageFk` `packagingFk` varchar(10) -CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT '--' NULL; - -ALTER TABLE `vn`.`buy` -ADD COLUMN `packageFk` varchar(10) AS (`packagingFk`) VIRTUAL; \ No newline at end of file diff --git a/db/changes/234201/00-packagingFkviews.sql b/db/changes/234201/00-packagingFkviews.sql deleted file mode 100644 index 49d41c26c..000000000 --- a/db/changes/234201/00-packagingFkviews.sql +++ /dev/null @@ -1,150 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS `vn2008`; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`awbVolume` -AS SELECT `d`.`awbFk` AS `awbFk`, - `b`.`stickers` * `i`.`density` * IF( - `p`.`volume` > 0, - `p`.`volume`, - `p`.`width` * `p`.`depth` * IF(`p`.`height` = 0, `i`.`size` + 10, `p`.`height`) - ) / (`vc`.`aerealVolumetricDensity` * 1000) AS `volume`, - `b`.`id` AS `buyFk` -FROM ( - ( - ( - ( - ( - ( - ( - ( - `vn`.`buy` `b` - JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) - ) - JOIN `vn`.`itemType` `it` ON(`i`.`typeFk` = `it`.`id`) - ) - JOIN `vn`.`packaging` `p` ON(`p`.`id` = `b`.`packagingFk`) - ) - JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) - ) - JOIN `vn`.`travel` `t` ON(`t`.`id` = `e`.`travelFk`) - ) - JOIN `vn`.`duaEntry` `de` ON(`de`.`entryFk` = `e`.`id`) - ) - JOIN `vn`.`dua` `d` ON(`d`.`id` = `de`.`duaFk`) - ) - JOIN `vn`.`volumeConfig` `vc` - ) -WHERE `t`.`shipped` > makedate(year(`util`.`VN_CURDATE`()) - 1, 1); - - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`Compres` -AS SELECT `c`.`id` AS `Id_Compra`, - `c`.`entryFk` AS `Id_Entrada`, - `c`.`itemFk` AS `Id_Article`, - `c`.`buyingValue` AS `Costefijo`, - `c`.`quantity` AS `Cantidad`, - `c`.`packagingFk` AS `Id_Cubo`, - `c`.`stickers` AS `Etiquetas`, - `c`.`freightValue` AS `Portefijo`, - `c`.`packageValue` AS `Embalajefijo`, - `c`.`comissionValue` AS `Comisionfija`, - `c`.`packing` AS `Packing`, - `c`.`grouping` AS `grouping`, - `c`.`groupingMode` AS `caja`, - `c`.`location` AS `Nicho`, - `c`.`price1` AS `Tarifa1`, - `c`.`price2` AS `Tarifa2`, - `c`.`price3` AS `Tarifa3`, - `c`.`minPrice` AS `PVP`, - `c`.`printedStickers` AS `Vida`, - `c`.`isChecked` AS `punteo`, - `c`.`ektFk` AS `buy_edi_id`, - `c`.`created` AS `odbc_date`, - `c`.`isIgnored` AS `Novincular`, - `c`.`isPickedOff` AS `isPickedOff`, - `c`.`workerFk` AS `Id_Trabajador`, - `c`.`weight` AS `weight`, - `c`.`dispatched` AS `dispatched`, - `c`.`containerFk` AS `container_id`, - `c`.`itemOriginalFk` AS `itemOriginalFk` -FROM `vn`.`buy` `c`; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`buySource` -AS SELECT `b`.`entryFk` AS `Id_Entrada`, - `b`.`isPickedOff` AS `isPickedOff`, - NULL AS `tarifa0`, - `e`.`kop` AS `kop`, - `b`.`id` AS `Id_Compra`, - `i`.`typeFk` AS `tipo_id`, - `b`.`itemFk` AS `Id_Article`, - `i`.`size` AS `Medida`, - `i`.`stems` AS `Tallos`, - `b`.`stickers` AS `Etiquetas`, - `b`.`packagingFk` AS `Id_Cubo`, - `b`.`buyingValue` AS `Costefijo`, - `b`.`packing` AS `Packing`, - `b`.`grouping` AS `Grouping`, - `b`.`quantity` AS `Cantidad`, - `b`.`price2` AS `Tarifa2`, - `b`.`price3` AS `Tarifa3`, - `b`.`isChecked` AS `Punteo`, - `b`.`groupingMode` AS `Caja`, - `i`.`isToPrint` AS `Imprimir`, - `i`.`name` AS `Article`, - `vn`.`ink`.`picture` AS `Tinta`, - `i`.`originFk` AS `id_origen`, - `i`.`minPrice` AS `PVP`, - NULL AS `Id_Accion`, - `s`.`company_name` AS `pro`, - `i`.`hasMinPrice` AS `Min`, - `b`.`isIgnored` AS `Novincular`, - `b`.`freightValue` AS `Portefijo`, - round(`b`.`buyingValue` * `b`.`quantity`, 2) AS `Importe`, - `b`.`printedStickers` AS `Vida`, - `i`.`comment` AS `reference`, - `b`.`workerFk` AS `Id_Trabajador`, - `e`.`s1` AS `S1`, - `e`.`s2` AS `S2`, - `e`.`s3` AS `S3`, - `e`.`s4` AS `S4`, - `e`.`s5` AS `S5`, - `e`.`s6` AS `S6`, - 0 AS `price_fixed`, - `i`.`producerFk` AS `producer_id`, - `i`.`subName` AS `tag1`, - `i`.`value5` AS `tag2`, - `i`.`value6` AS `tag3`, - `i`.`value7` AS `tag4`, - `i`.`value8` AS `tag5`, - `i`.`value9` AS `tag6`, - `s`.`company_name` AS `company_name`, - `b`.`weight` AS `weightPacking`, - `i`.`packingOut` AS `packingOut`, - `b`.`itemOriginalFk` AS `itemOriginalFk`, - `io`.`longName` AS `itemOriginalName`, - `it`.`gramsMax` AS `gramsMax` -FROM ( - ( - ( - ( - ( - ( - `vn`.`item` `i` - JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`) - ) - LEFT JOIN `vn`.`ink` ON(`vn`.`ink`.`id` = `i`.`inkFk`) - ) - LEFT JOIN `vn`.`buy` `b` ON(`b`.`itemFk` = `i`.`id`) - ) - LEFT JOIN `vn`.`item` `io` ON(`io`.`id` = `b`.`itemOriginalFk`) - ) - LEFT JOIN `edi`.`ekt` `e` ON(`e`.`id` = `b`.`ektFk`) - ) - LEFT JOIN `edi`.`supplier` `s` ON(`e`.`pro` = `s`.`supplier_id`) - ); - diff --git a/db/changes/234201/00-supplierAccountCheckLength.sql b/db/changes/234201/00-supplierAccountCheckLength.sql deleted file mode 100644 index 55a68e37b..000000000 --- a/db/changes/234201/00-supplierAccountCheckLength.sql +++ /dev/null @@ -1,6 +0,0 @@ -UPDATE `vn`.`supplier` - SET account = LPAD(id,10,'0') - WHERE account IS NULL; - -ALTER TABLE `vn`.`supplier` ADD CONSTRAINT supplierAccountTooShort CHECK (LENGTH(account) = 10); -ALTER TABLE `vn`.`supplier` MODIFY COLUMN account varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT 4100000000 NOT NULL COMMENT 'Default accounting code for suppliers.'; diff --git a/db/changes/234201/00-zoneIncluded.sql b/db/changes/234201/00-zoneIncluded.sql deleted file mode 100644 index 12d4058cf..000000000 --- a/db/changes/234201/00-zoneIncluded.sql +++ /dev/null @@ -1,26 +0,0 @@ -ALTER TABLE `vn`.`zoneIncluded` - ADD COLUMN `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST, - DROP PRIMARY KEY, - DROP FOREIGN KEY `zoneFk2`, - DROP FOREIGN KEY `zoneGeoFk2`, - DROP KEY `geoFk_idx`, - ADD PRIMARY KEY (`id`), - ADD CONSTRAINT `zoneIncluded_FK_1` FOREIGN KEY (zoneFk) REFERENCES `vn`.`zone`(id) ON DELETE CASCADE ON UPDATE CASCADE, - ADD CONSTRAINT `zoneIncluded_FK_2` FOREIGN KEY (geoFk) REFERENCES `vn`.`zoneGeo`(id) ON DELETE CASCADE ON UPDATE CASCADE, - ADD CONSTRAINT `unique_zone_geo` UNIQUE (`zoneFk`, `geoFk`); - -DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`; -USE `vn`; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete` - AFTER DELETE ON `zoneIncluded` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'zoneIncluded', - `changedModelId` = OLD.zoneFk, - `userFk` = account.myUser_getId(); -END$$ -DELIMITER ; diff --git a/db/changes/234201/03-packagingFkProc.sql b/db/changes/234201/03-packagingFkProc.sql deleted file mode 100644 index 4876c270e..000000000 --- a/db/changes/234201/03-packagingFkProc.sql +++ /dev/null @@ -1,1381 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travelVolume`(vTravelFk INT) -BEGIN - - SELECT w1.name AS ORI, - w2.name AS DES, - tr.shipped shipment, - tr.landed landing, - a.name Agencia, - s.name Proveedor, - e.id Id_Entrada, - e.invoiceNumber Referencia, - CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * - vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) AS CC, - CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * - vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) AS espais - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode a ON a.id = tr.agencyModeFk - JOIN vn.warehouse w1 ON w1.id = tr.warehouseInFk - JOIN vn.warehouse w2 ON w2.id = tr.warehouseOutFk - JOIN vn.volumeConfig vc - JOIN vn.item i ON i.id = b.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - WHERE tr.id = vTravelFk; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travelVolume_get`(vFromDated DATE, vToDated DATE, vWarehouseFk INT) -BEGIN - SELECT tr.landed Fecha, - a.name Agencia, - count(DISTINCT e.id) numEntradas, - FLOOR(sum(item_getVolume(b.itemFk, b.packagingFk) * b.stickers / 1000000 )) AS m3 - FROM vn.travel tr - JOIN vn.agencyMode a ON a.id = tr.agencyModeFk - JOIN vn.entry e ON e.travelFk = tr.id - JOIN vn.buy b ON b.entryFk = e.id - WHERE tr.landed BETWEEN vFromDated AND vToDated - AND e.isRaid = FALSE - AND tr.warehouseInFk = vWarehouseFk - GROUP BY tr.landed , a.name ; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_getEntriesMissingPackage`(vSelf INT) -BEGIN - DECLARE vpackageOrPackingNull INT; - DECLARE vTravelFk INT; - - SELECT travelfk INTO vTravelFk - FROM entry - WHERE id = vSelf; - - SELECT e.id entryFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - JOIN buy b ON b.entryFk = e.id - WHERE t.id = vTravelFk - AND (b.packing IS NULL OR b.packagingFk IS NULL); -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketBoxesView`(IN vTicketFk INT) -BEGIN - - SELECT s.id, - s.itemFk, - s.concept, - floor(s.quantity / b.packing) as Cajas, - b.packing, - s.isPicked, - i.size - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN cache.last_buy lb on lb.warehouse_id = t.warehouseFk AND lb.item_id = s.itemFk - JOIN buy b on b.id = lb.buy_id - JOIN packaging p on p.id = b.packagingFk - WHERE s.quantity >= b.packing - AND t.id = vTicketFk - AND p.isBox - GROUP BY s.itemFk; - - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBuyedByWorker`( - vDated DATE, - vWorker INT -) -BEGIN -/** - * Inserta el volumen de compra de un comprador - * en stockBuyed de acuerdo con la fecha. - * - * @param vDated Fecha de compra - * @param vWorker Id de trabajador - */ - CREATE OR REPLACE TEMPORARY TABLE tStockBuyed - (INDEX (userFk)) - ENGINE = MEMORY - SELECT requested, reserved, userFk - FROM stockBuyed - WHERE dated = vDated - AND userFk = vWorker; - - DELETE FROM stockBuyed - WHERE dated = vDated - AND userFk = vWorker; - - CALL stockTraslation(vDated); - - INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description) - SELECT it.workerFk, - SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000, - vDated, - sb.reserved, - sb.requested, - u.name - FROM itemType it - JOIN item i ON i.typeFk = it.id - LEFT JOIN tmp.item ti ON ti.itemFk = i.id - JOIN itemCategory ic ON ic.id = it.categoryFk - JOIN warehouse wh ON wh.code = 'VNH' - JOIN tmp.buyUltimate bu ON bu.itemFk = i.id - AND bu.warehouseFk = wh.id - JOIN buy b ON b.id = bu.buyFk - JOIN volumeConfig vc - JOIN account.`user` u ON u.id = it.workerFk - LEFT JOIN tStockBuyed sb ON sb.userFk = it.workerFk - WHERE ic.display - AND it.workerFk = vWorker; - - SELECT b.entryFk Id_Entrada, - i.id Id_Article, - i.name Article, - ti.quantity Cantidad, - (ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id)) - / (vc.trolleyM3 * 1000000) buyed, - b.packagingFk id_cubo, - b.packing - FROM tmp.item ti - JOIN item i ON i.id = ti.itemFk - JOIN itemType it ON i.typeFk = it.id - JOIN itemCategory ic ON ic.id = it.categoryFk - JOIN worker w ON w.id = it.workerFk - JOIN auctionConfig ac - JOIN tmp.buyUltimate bu ON bu.itemFk = i.id - AND bu.warehouseFk = ac.warehouseFk - JOIN buy b ON b.id = bu.buyFk - JOIN volumeConfig vc - WHERE ic.display - AND w.id = vWorker; - - DROP TEMPORARY TABLE tmp.buyUltimate, - tmp.item, - tStockBuyed; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` 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; - - IF (SELECT COUNT(*) FROM vn.itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN - - UPDATE vn.itemShelving - SET visible = visible+vQuantity, - created = vCreated - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking; - - ELSE - CALL cache.last_buy_refresh(FALSE); - INSERT INTO itemShelving( itemFk, - shelvingFk, - visible, - created, - `grouping`, - packing, - packagingFk) - SELECT vItemFk, - vShelvingFk, - vQuantity, - vCreated, - IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) `grouping`, - IF(vPacking = 0, b.packing, vPacking) packing, - IF(vPackagingFk = '', b.packagingFk, vPackagingFk) packaging - FROM vn.item i - LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - WHERE i.id = vItemFk; - END IF; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) -BEGIN - - -/** - * Añade registro o lo actualiza si ya existe. - * - * @param vShelvingFk matrícula del carro - * @param vBarcode el id del registro - * @param vQuantity indica la cantidad del producto - * @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra - * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra - * @param vPacking el packing del producto, NULL para coger el de la ultima compra - * @param vWarehouseFk indica el sector - * - **/ - - DECLARE vItemFk INT; - - SELECT barcodeToItem(vBarcode) INTO vItemFk; - - IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN - - INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); - INSERT INTO shelving(code, parkingFk) - SELECT vShelvingFk, id - FROM parking - WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; - - END IF; - - IF (SELECT COUNT(*) FROM itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk - AND packing = vPacking) = 1 THEN - - UPDATE itemShelving - SET visible = visible+vQuantity - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; - - ELSE - CALL cache.last_buy_refresh(FALSE); - INSERT INTO itemShelving( itemFk, - shelvingFk, - visible, - grouping, - packing, - packagingFk) - - SELECT vItemFk, - vShelvingFk, - vQuantity, - IFNULL(vGrouping, b.grouping), - IFNULL(vPacking, b.packing), - IFNULL(vPackagingFk, b.packagingFk) - FROM item i - LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id - WHERE i.id = vItemFk; - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemFreight_Show`(vItemFk INT, vWarehouseFk INT) -BEGIN - - SELECT cm3 Volumen_Entrada, - cm3delivery Volumen_Salida, - p.volume Volumen_del_embalaje, - p.width Ancho_del_embalaje, - p.`depth` Largo_del_embalaje, - b.packagingFk , - IFNULL(p.height, i.`size`) + 10 Altura, - b.packing Packing_Entrada, - i.packingOut Packing_Salida, - i.id itemFk, - b.id buyFk, - b.entryFk, - w.name warehouseFk - FROM vn.itemCost ic - JOIN vn.item i ON i.id = ic.itemFk - LEFT JOIN cache.last_buy lb ON lb.item_id = ic.itemFk AND lb.warehouse_id = ic.warehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.packaging p ON p.id = b.packagingFk - LEFT JOIN vn.warehouse w ON w.id = ic.warehouseFk - WHERE ic.itemFk = vItemFk - AND ic.warehouseFk = vWarehouseFk; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`inventoryMake`(vDate DATE, vWh INT) -proc: BEGIN -/** -* Recalcula los inventarios de todos los almacenes, si vWh = 0 -* -* @param vDate Fecha de los nuevos inventarios -* @param vWh almacen al cual hacer el inventario -*/ - - DECLARE vDone BOOL; - DECLARE vEntryFk INT; - DECLARE vTravelFk INT; - DECLARE vDateLastInventory DATE; - DECLARE vDateYesterday DATETIME DEFAULT vDate - INTERVAL 1 SECOND; - DECLARE vWarehouseOutFkInventory INT; - DECLARE vInventorySupplierFk INT; - DECLARE vAgencyModeFkInventory INT; - - DECLARE cWarehouses CURSOR FOR - SELECT id - FROM warehouse - WHERE isInventory - AND vWh IN (0,id); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN cWarehouses; - SET @isModeInventory := TRUE; - l: LOOP - - SET vDone = FALSE; - FETCH cWarehouses INTO vWh; - - IF vDone THEN - LEAVE l; - END IF; - - SELECT w.id INTO vWarehouseOutFkInventory - FROM warehouse w - WHERE w.code = 'inv'; - - SELECT inventorySupplierFk INTO vInventorySupplierFk - FROM entryConfig; - - SELECT am.id INTO vAgencyModeFkInventory - FROM agencyMode am - where code = 'inv'; - - SELECT MAX(landed) INTO vDateLastInventory - FROM travel tr - JOIN entry e ON e.travelFk = tr.id - JOIN buy b ON b.entryFk = e.id - WHERE warehouseOutFk = vWarehouseOutFkInventory - AND landed < vDate - AND e.supplierFk = vInventorySupplierFk - AND warehouseInFk = vWh - AND NOT isRaid; - - IF vDateLastInventory IS NULL THEN - SELECT inventoried INTO vDateLastInventory FROM config; - END IF; - - -- Generamos travel, si no existe. - SET vTravelFK = 0; - - SELECT id INTO vTravelFk - FROM travel - WHERE warehouseOutFk = vWarehouseOutFkInventory - AND warehouseInFk = vWh - AND landed = vDate - AND agencyModeFk = vAgencyModeFkInventory - AND ref = 'inventario' - LIMIT 1; - - IF NOT vTravelFK THEN - - INSERT INTO travel SET - warehouseOutFk = vWarehouseOutFkInventory, - warehouseInFk = vWh, - shipped = vDate, - landed = vDate, - agencyModeFk = vAgencyModeFkInventory, - ref = 'inventario', - isDelivered = TRUE, - isReceived = TRUE; - - SELECT LAST_INSERT_ID() INTO vTravelFk; - - END IF; - - -- Generamos entrada si no existe, o la vaciamos. - SET vEntryFk = 0; - - SELECT id INTO vEntryFk - FROM entry - WHERE supplierFk = vInventorySupplierFk - AND travelFk = vTravelFk; - - IF NOT vEntryFk THEN - - INSERT INTO entry SET - supplierFk = vInventorySupplierFk, - isConfirmed = TRUE, - isOrdered = TRUE, - travelFk = vTravelFk; - - SELECT LAST_INSERT_ID() INTO vEntryFk; - - ELSE - - DELETE FROM buy WHERE entryFk = vEntryFk; - - END IF; - - -- Preparamos tabla auxilar - CREATE OR REPLACE TEMPORARY TABLE tmp.inventory ( - itemFk INT(11) NOT NULL PRIMARY KEY, - quantity int(11) DEFAULT '0', - buyingValue decimal(10,3) DEFAULT '0.000', - freightValue decimal(10,3) DEFAULT '0.000', - packing int(11) DEFAULT '0', - `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', - groupingMode tinyint(4) NOT NULL DEFAULT 0 , - comissionValue decimal(10,3) DEFAULT '0.000', - packageValue decimal(10,3) DEFAULT '0.000', - packageFk varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', - price1 decimal(10,2) DEFAULT '0.00', - price2 decimal(10,2) DEFAULT '0.00', - price3 decimal(10,2) DEFAULT '0.00', - minPrice decimal(10,2) DEFAULT '0.00', - producer varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - INDEX (itemFK)) ENGINE = MEMORY; - - -- Compras - INSERT INTO tmp.inventory(itemFk,quantity) - SELECT b.itemFk, SUM(b.quantity) - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - WHERE tr.warehouseInFk = vWh - AND tr.landed BETWEEN vDateLastInventory - AND vDateYesterday - AND NOT isRaid - GROUP BY b.itemFk; - SELECT vDateLastInventory , vDateYesterday; - - -- Traslados - INSERT INTO tmp.inventory(itemFk, quantity) - SELECT itemFk, quantityOut - FROM ( - SELECT b.itemFk,- SUM(b.quantity) quantityOut - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - WHERE tr.warehouseOutFk = vWh - AND tr.shipped BETWEEN vDateLastInventory - AND vDateYesterday - AND NOT isRaid - GROUP BY b.itemFk - ) sub - ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity, 0) + sub.quantityOut; - - -- Ventas - INSERT INTO tmp.inventory(itemFk,quantity) - SELECT itemFk, saleOut - FROM ( - SELECT s.itemFk, - SUM(s.quantity) saleOut - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - WHERE t.warehouseFk = vWh - AND t.shipped BETWEEN vDateLastInventory AND vDateYesterday - GROUP BY s.itemFk - ) sub - ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity,0) + sub.saleOut; - - -- Actualiza valores de la ultima compra - UPDATE tmp.inventory inv - JOIN cache.last_buy lb ON lb.item_id = inv.itemFk AND lb.warehouse_id = vWh - JOIN buy b ON b.id = lb.buy_id - JOIN item i ON i.id = b.itemFk - LEFT JOIN producer p ON p.id = i.producerFk - SET inv.buyingValue = b.buyingValue, - inv.freightValue = b.freightValue, - inv.packing = b.packing, - inv.`grouping`= b.`grouping`, - inv.groupingMode = b.groupingMode, - inv.comissionValue = b.comissionValue, - inv.packageValue = b.packageValue, - inv.packageFk = b.packagingFk, - inv.price1 = b.price1, - inv.price2 = b.price2, - inv.price3 = b.price3, - inv.minPrice = b.minPrice, - inv.producer = p.name; - - INSERT INTO buy( itemFk, - quantity, - buyingValue, - freightValue, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - packagingFk, - price1, - price2, - price3, - minPrice, - entryFk) - SELECT itemFk, - GREATEST(quantity, 0), - buyingValue, - freightValue, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - packagingFk, - price1, - price2, - price3, - minPrice, - vEntryFk - FROM tmp.inventory; - - SELECT vWh, COUNT(*), util.VN_NOW() FROM tmp.inventory; - - -- Actualizamos el campo lastUsed de item - UPDATE item i - JOIN tmp.inventory i2 ON i2.itemFk = i.id - SET i.lastUsed = NOW() - WHERE i2.quantity; - - -- DROP TEMPORARY TABLE tmp.inventory; - - END LOOP; - - CLOSE cWarehouses; - - UPDATE config SET inventoried = vDate; - SET @isModeInventory := FALSE; - - DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; - CREATE TEMPORARY TABLE tmp.entryToDelete - (INDEX(entryId) USING BTREE) ENGINE = MEMORY - SELECT e.id as entryId, - t.id as travelId - FROM travel t - JOIN `entry` e ON e.travelFk = t.id - WHERE e.supplierFk = vInventorySupplierFk - AND t.shipped <= util.VN_CURDATE() - INTERVAL 12 DAY - AND (DAY(t.shipped) <> 1 OR shipped < util.VN_CURDATE() - INTERVAL 12 DAY); - - DELETE e - FROM `entry` e - JOIN tmp.entryToDelete tmp ON tmp.entryId = e.id; - - DELETE IGNORE t - FROM travel t - JOIN tmp.entryToDelete tmp ON tmp.travelId = t.id; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`inventory_repair`() -BEGIN - - DROP TEMPORARY TABLE IF EXISTS tmp.lastEntry; - CREATE TEMPORARY TABLE tmp.lastEntry - (PRIMARY KEY (buyFk)) - SELECT - i.id AS itemFk, - w.id AS warehouseFk, - w.name AS warehouse, - tr.landed, - b.id AS buyFk, - b.entryFk, - b.isIgnored, - b.price2, - b.price3, - b.stickers, - b.packing, - b.grouping, - b.groupingMode, - b.weight, - i.stems, - b.quantity, - b.buyingValue, - b.packagingFk , - s.id AS supplierFk, - s.name AS supplier - FROM itemType it - RIGHT JOIN (entry e - LEFT JOIN supplier s ON s.id = e.supplierFk - RIGHT JOIN buy b ON b.entryFk = e.id - LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk - LEFT JOIN travel tr ON tr.id = e.travelFk - LEFT JOIN warehouse w ON w.id = tr.warehouseInFk - LEFT JOIN origin o ON o.id = i.originFk - ) ON it.id = i.typeFk - LEFT JOIN edi.ekt ek ON b.ektFk = ek.id - WHERE (b.packagingFk = "--" OR b.price2 = 0 OR b.packing = 0 OR b.buyingValue = 0) AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())) AND s.name = 'INVENTARIO'; - - DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOk; - CREATE TEMPORARY TABLE tmp.lastEntryOk - (PRIMARY KEY (buyFk)) - SELECT - i.id AS itemFk, - w.id AS warehouseFk, - w.name AS warehouse, - tr.landed, - b.id AS buyFk, - b.entryFk, - b.isIgnored, - b.price2, - b.price3, - b.stickers, - b.packing, - b.grouping, - b.groupingMode, - b.weight, - i.stems, - b.quantity, - b.buyingValue, - b.packagingFk, - s.id AS supplierFk, - s.name AS supplier - FROM itemType it - RIGHT JOIN (entry e - LEFT JOIN supplier s ON s.id = e.supplierFk - RIGHT JOIN buy b ON b.entryFk = e.id - LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk - LEFT JOIN travel tr ON tr.id = e.travelFk - LEFT JOIN warehouse w ON w.id = tr.warehouseInFk - LEFT JOIN origin o ON o.id = i.originFk - ) ON it.id = i.typeFk - LEFT JOIN edi.ekt ek ON b.ektFk = ek.id - WHERE b.packagingFk != "--" AND b.price2 != 0 AND b.packing != 0 AND b.buyingValue > 0 AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-2,util.VN_CURDATE())) - ORDER BY tr.landed DESC; - - DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOkGroup; - CREATE TEMPORARY TABLE tmp.lastEntryOkGroup - (INDEX (warehouseFk,itemFk)) - SELECT * - FROM tmp.lastEntryOk tmp - GROUP BY tmp.itemFk,tmp.warehouseFk; - - UPDATE buy b - JOIN tmp.lastEntry lt ON lt.buyFk = b.id - JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk - SET b.packagingFk = eo.packagingFk WHERE b.packagingFk = "--"; - - UPDATE buy b - JOIN tmp.lastEntry lt ON lt.buyFk = b.id - JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk - SET b.price2 = eo.price2 WHERE b.price2 = 0 ; - - UPDATE buy b - JOIN tmp.lastEntry lt ON lt.buyFk = b.id - JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk - SET b.packing = eo.packing WHERE b.packing = 0; - - UPDATE buy b - JOIN tmp.lastEntry lt ON lt.buyFk = b.id - JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk - SET b.buyingValue = eo.buyingValue WHERE b.buyingValue = 0; - - DROP TEMPORARY TABLE tmp.lastEntry; - DROP TEMPORARY TABLE tmp.lastEntryOk; - DROP TEMPORARY TABLE tmp.lastEntryOkGroup; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`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 vPackingOut DECIMAL(10,2); - DECLARE vWarehouse INT; - DECLARE vStandardFlowerBox INT; - DECLARE vWarehouseOut INT; - DECLARE vIsMerchandise BOOL; - DECLARE vIsFeedStock BOOL; - DECLARE vWeight DECIMAL(10,2); - DECLARE vPacking INT; - - SELECT b.entryFk, - b.itemFk, - i.packingOut, - ic.merchandise, - vc.standardFlowerBox, - b.weight, - b.packing - INTO - vEntryFk, - vItemFk, - vPackingOut, - vIsMerchandise, - vStandardFlowerBox, - vWeight, - vPacking - FROM buy b - LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN packaging p ON p.id = b.packagingFk AND NOT p.isBox - JOIN volumeConfig vc ON TRUE - WHERE b.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; - - IF vIsMerchandise THEN - - REPLACE itemCost SET - itemFk = vItemFk, - warehouseFk = vWarehouse, - cm3 = buy_getUnitVolume(vSelf), - cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf)); - - IF vWeight AND vPacking THEN - UPDATE itemCost SET - grams = vWeight * 1000 / vPacking - WHERE itemFk = vItemFk - AND warehouseFk = vWarehouse; - END IF; - END IF; - - SELECT isFeedStock INTO vIsFeedStock - FROM warehouse WHERE id = vWarehouseOut; - - IF vIsFeedStock THEN - INSERT IGNORE INTO producer(`name`) - SELECT es.company_name - FROM buy b - JOIN edi.ekt be ON be.id = b.ektFk - JOIN edi.supplier es ON es.supplier_id = be.pro - WHERE b.id = vSelf; - - END IF; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`buy_getUnitVolume`(vSelf INT) - RETURNS int(11) - DETERMINISTIC -BEGIN -/** - * Calculates the unit volume occupied by a buy. - * - * @param vSelf The buy id - * @return The unit volume in cubic centimeters - */ - DECLARE vItem INT; - DECLARE vPackaging VARCHAR(10); - DECLARE vPacking INT; - - SELECT itemFk, packagingFk, packing - INTO vItem, vPackaging, vPacking - FROM buy - WHERE id = vSelf; - - RETURN IFNULL(ROUND(item_getVolume(vItem, vPackaging) / vPacking), 0); -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPrices`() -BEGIN -/** - * Recalcula los precios para las compras insertadas en tmp.buyRecalc - * - * @param tmp.buyRecalc (id) - */ - DECLARE vLanded DATE; - DECLARE vWarehouseFk INT; - DECLARE vHasNotPrice BOOL; - DECLARE vBuyingValue DECIMAL(10,3); - DECLARE vPackagingFk VARCHAR(10); - DECLARE vIsWarehouseFloramondo BOOL; - - SELECT t.landed, t.warehouseInFk, (w.`name` = 'Floramondo') - INTO vLanded, vWarehouseFk, vIsWarehouseFloramondo - FROM tmp.buyRecalc br - JOIN buy b ON b.id = br.id - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - LIMIT 1; - - CALL rate_getPrices(vLanded, vWarehouseFk); - - UPDATE buy b - JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id) - LEFT JOIN packaging p ON p.id = b.packagingFk - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN itemType it ON it.id = i.typeFk - JOIN travel tr ON tr.id = e.travelFk - JOIN agencyMode am ON am.id = tr.agencyModeFk - JOIN tmp.rate r - JOIN volumeConfig vc - SET b.freightValue = @PF:= IFNULL(((am.m3 * @m3:= item_getVolume(b.itemFk, b.packagingFk) / 1000000) - / b.packing) * IF(am.hasWeightVolumetric, GREATEST(b.weight / @m3 / vc.aerealVolumetricDensity, 1), 1), 0), - b.comissionValue = @CF:= ROUND(IFNULL(e.commission * b.buyingValue / 100, 0), 3), - b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)), - b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 - b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), - b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2); - - SELECT (b.buyingValue = b.price2), b.buyingValue, b.packagingFk - INTO vHasNotPrice, vBuyingValue, vPackagingFk - FROM vn.buy b - WHERE b.id = @buyId AND b.buyingValue <> 0.01; - - DROP TEMPORARY TABLE tmp.rate; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_load`(IN `vSelf` INT) -proc:BEGIN - - DECLARE vRef INT; - DECLARE vBuy INT; - DECLARE vItem INT; - DECLARE vQty INT; - DECLARE vPackage INT; - DECLARE vPutOrderFk INT; - DECLARE vIsLot BOOLEAN; - DECLARE vForceToPacking INT DEFAULT 2; - DECLARE vEntryFk INT; - DECLARE vHasToChangePackagingFk BOOLEAN; - DECLARE vIsFloramondoDirect BOOLEAN; - DECLARE vTicketFk INT; - DECLARE vHasItemGroup BOOL; - DECLARE vDescription VARCHAR(255); - DECLARE vSaleFk INT; - - -- Carga los datos necesarios del EKT - - SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), - CONCAT(e.`ref`, ' ', e.item, ' ', e.sub, ' EktFk:', e.id) - INTO vRef, vQty, vPackage, vPutOrderFk, vItem, vIsFloramondoDirect, vHasItemGroup, vDescription - FROM edi.ekt e - LEFT JOIN edi.item i ON e.ref = i.id - LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk - LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID - LEFT JOIN vn.ektEntryAssign eea ON eea.sub = e.sub - LEFT JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id - WHERE e.id = vSelf - LIMIT 1; - - IF NOT vHasItemGroup THEN - - CALL vn.mail_insert('logistica@verdnatura.es', 'nocontestar@verdnatura.es', 'Nuevo grupo en Floramondo', vDescription); - - CALL vn.mail_insert('pako@verdnatura.es', 'nocontestar@verdnatura.es', CONCAT('Nuevo grupo en Floramondo: ', vDescription), vDescription); - - LEAVE proc; - - END IF; - - -- Asigna la entrada - SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; - - -- Inserta el cubo si no existe - - IF vPackage = 800 THEN - - SET vHasToChangePackagingFk = TRUE; - - IF vItem THEN - - SELECT vn.item_getPackage(vItem) INTO vPackage ; - - ELSE - - SET vPackage = 8000 + vQty; - - INSERT IGNORE INTO vn.packaging(id, width, `depth`) - SELECT vPackage, vc.ccLength / vQty, vc.ccWidth - FROM vn.volumeConfig vc; - - END IF; - - ELSE - - INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z) - SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10) - FROM bucket WHERE bucket_id = vPackage; - - IF ROW_COUNT() > 0 - THEN - INSERT INTO vn2008.mail SET - `subject` = 'Cubo añadido', - `text` = CONCAT('Se ha añadido el cubo: ', vPackage), - `to` = 'ekt@verdnatura.es'; - END IF; - END IF; - - -- Si es una compra de Logiflora obtiene el articulo - IF vPutOrderFk THEN - - SELECT i.id INTO vItem - FROM edi.putOrder po - JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID - WHERE po.id = vPutOrderFk - LIMIT 1; - - END IF; - - INSERT IGNORE INTO item_track SET - item_id = vRef; - - IF IFNULL(vItem,0) = 0 THEN - - -- Intenta obtener el artículo en base a los atributos holandeses - - SELECT b.id, IFNULL(b.itemOriginalFk ,b.itemFk) INTO vBuy, vItem - FROM edi.ekt e - JOIN edi.item_track t ON t.item_id = e.ref - LEFT JOIN edi.ekt l ON l.ref = e.ref - LEFT JOIN vn.buy b ON b.ektFk = l.id - LEFT JOIN vn.item i ON i.id = b.itemFk - JOIN vn2008.config cfg - WHERE e.id = vSelf - AND l.id != vSelf - AND b.itemFk != cfg.generic_item - AND IF(t.s1, l.s1 = e.s1, TRUE) - AND IF(t.s2, l.s2 = e.s2, TRUE) - AND IF(t.s3, l.s3 = e.s3, TRUE) - AND IF(t.s4, l.s4 = e.s4, TRUE) - AND IF(t.s5, l.s5 = e.s5, TRUE) - AND IF(t.s6, l.s6 = e.s6, TRUE) - AND IF(t.pac, l.pac = e.pac, TRUE) - AND IF(t.cat, l.cat = e.cat, TRUE) - AND IF(t.ori, l.ori = e.ori, TRUE) - AND IF(t.pro, l.pro = e.pro, TRUE) - AND IF(t.package, l.package = e.package, TRUE) - AND IF(t.item, l.item = e.item, TRUE) - AND i.isFloramondo = vIsFloramondoDirect - ORDER BY l.now DESC, b.id ASC - LIMIT 1; - - END IF; - - -- Si no encuentra el articulo lo crea en el caso de las compras directas en Floramondo - IF ISNULL(vItem) AND vIsFloramondoDirect THEN - - CALL edi.item_getNewByEkt(vSelf, vItem); - - END IF; - - INSERT INTO vn.buy - ( - entryFk - ,ektFk - ,buyingValue - ,itemFk - ,stickers - ,packing - ,`grouping` - ,quantity - ,groupingMode - ,packagingFk - ,weight - ) - SELECT - vEntryFk - ,vSelf - ,(@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue - ,IFNULL(vItem, cfg.generic_item) itemFk - ,e.qty stickers - ,@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing - ,IFNULL(b.`grouping`, e.pac) - ,@pac * e.qty - ,vForceToPacking - ,IF(vHasToChangePackagingFk OR ISNULL(b.packagingFk), vPackage, b.packagingFk) - ,(IFNULL(i.weightByPiece,0) * @pac)/1000 - FROM edi.ekt e - LEFT JOIN vn.buy b ON b.id = vBuy - LEFT JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.supplier s ON e.pro = s.id - JOIN vn2008.config cfg - WHERE e.id = vSelf - LIMIT 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; - - CREATE TEMPORARY TABLE tmp.buyRecalc - SELECT buy.id - FROM vn.buy - WHERE ektFk = vSelf; - - CALL vn.buy_recalcPrices(); - - -- Si es una compra de Logiflora hay que informar la tabla vn.saleBuy - IF vPutOrderFk THEN - - REPLACE vn.saleBuy(saleFk, buyFk, workerFk) - SELECT po.saleFk, b.id, account.myUser_getId() - FROM edi.putOrder po - JOIN vn.buy b ON b.ektFk = vSelf - WHERE po.id = vPutOrderFk; - - END IF; - -- Si es una compra directa en Floramondo hay que añadirlo al ticket - - IF vIsFloramondoDirect THEN - - SELECT t.id INTO vTicketFk - FROM vn.ticket t - JOIN vn.ektEntryAssign eea - ON eea.addressFk = t.addressFk - AND t.warehouseFk = eea.warehouseInFk - JOIN edi.ekt e - ON e.sub = eea.sub - AND e.id = vSelf - WHERE e.fec = t.shipped - LIMIT 1; - - IF ISNULL(vTicketFk) THEN - - INSERT INTO vn.ticket ( - clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus - ) - SELECT - a.clientFk, - e.fec, - a.id, - a.agencyModeFk, - a.nickname, - eea.warehouseInFk, - c.id, - e.fec, - z.id, - z.price, - z.bonus - FROM edi.ekt e - JOIN vn.ektEntryAssign eea ON eea.sub = e.sub - JOIN vn.address a ON a.id = eea.addressFk - JOIN vn.company c ON c.code = 'VNL' - JOIN vn.`zone` z ON z.code = 'FLORAMONDO' - WHERE e.id = vSelf - LIMIT 1; - - SET vTicketFk = LAST_INSERT_ID(); - - INSERT INTO vn.ticketLog - SET originFk = vTicketFk, - userFk = account.myUser_getId(), - `action` = 'insert', - description = CONCAT('EktLoad ha creado el ticket:', ' ', vTicketFk); - - END IF; - - INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, price) - SELECT vItem, vTicketFk, e.item, e.qty * e.pac, e.pri * ( 1 + fhc.floramondoMargin ) - FROM edi.ekt e - JOIN edi.floraHollandConfig fhc - WHERE e.id = vSelf; - - SELECT LAST_INSERT_ID() INTO vSaleFk; - - REPLACE vn.saleBuy(saleFk, buyFk, workerFk) - SELECT vSaleFk, b.id, account.myUser_getId() - FROM vn.buy b - WHERE b.ektFk = vSelf; - - INSERT INTO vn.saleComponent(saleFk, componentFk, value) - SELECT vSaleFk, c.id, e.pri - FROM edi.ekt e - JOIN vn.component c ON c.code = 'purchaseValue' - WHERE e.id = vSelf; - - INSERT INTO vn.saleComponent(saleFk, componentFk, value) - SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin - FROM edi.ekt e - JOIN edi.floraHollandConfig fhc - JOIN vn.component c ON c.code = 'margin' - WHERE e.id = vSelf; - END IF; - DROP TEMPORARY TABLE tmp.buyRecalc; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_getVisible`( - vWarehouse TINYINT, - vDate DATE, - vType INT, - vPrefix VARCHAR(255)) -BEGIN - -/** - * Gets visible items of the specified type at specified date. - * - * @param vWarehouse The warehouse id - * @param vDate The visible date - * @param vType The type id - * @param vPrefix The article prefix to filter or %NULL for all - * @return tmp.itemVisible Visible items - */ - DECLARE vPrefixLen SMALLINT; - DECLARE vFilter VARCHAR(255) DEFAULT NULL; - DECLARE vDateInv DATE DEFAULT vn2008.date_inv(); - DECLARE EXIT HANDLER FOR 1114 - BEGIN - GET DIAGNOSTICS CONDITION 1 - @message = MESSAGE_TEXT; - CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, - CONCAT('hedera.item_getVisible error: ', @message), - CONCAT( - 'warehouse: ', IFNULL(vWarehouse, ''), - ', Fecha:', IFNULL(vDate, ''), - ', tipo: ', IFNULL(vType,''), - ', prefijo: ', IFNULL(vPrefix,''))); - RESIGNAL; - END; - SET vPrefixLen = IFNULL(LENGTH(vPrefix), 0) + 1; - - IF vPrefixLen > 1 THEN - SET vFilter = CONCAT(vPrefix, '%'); - END IF; - - DROP TEMPORARY TABLE IF EXISTS `filter`; - CREATE TEMPORARY TABLE `filter` - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT id itemFk FROM vn.item - WHERE typeFk = vType - AND (vFilter IS NULL OR `name` LIKE vFilter); - - DROP TEMPORARY TABLE IF EXISTS currentStock; - CREATE TEMPORARY TABLE currentStock - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT itemFk, SUM(quantity) quantity - FROM ( - SELECT b.itemFk, b.quantity - 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 BETWEEN vDateInv AND vDate - AND t.warehouseInFk = vWarehouse - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, -b.quantity - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel t ON t.id = e.travelFk - WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() - AND t.warehouseOutFk = vWarehouse - AND NOT e.isRaid - AND t.isDelivered - UNION ALL - SELECT m.itemFk, -m.quantity - FROM vn.sale m - JOIN vn.ticket t ON t.id = m.ticketFk - JOIN vn.ticketState s ON s.ticket = t.id - WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() - AND t.warehouseFk = vWarehouse - AND s.alertLevel = 3 - ) t - GROUP BY itemFk - HAVING quantity > 0; - - DROP TEMPORARY TABLE IF EXISTS tmp; - CREATE TEMPORARY TABLE tmp - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT * - FROM ( - SELECT b.itemFk, b.packagingFk, b.packing - 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 BETWEEN vDateInv AND vDate - AND NOT b.isIgnored - AND b.price2 >= 0 - AND b.packagingFk IS NOT NULL - ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC - LIMIT 10000000000000000000 - ) t GROUP BY itemFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.itemVisible; - CREATE TEMPORARY TABLE tmp.itemVisible - ENGINE = MEMORY - SELECT i.id Id_Article, - SUBSTRING(i.`name`, vPrefixLen) Article, - t.packing, p.id Id_Cubo, - IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, - CEIL(s.quantity / t.packing) etiquetas - FROM vn.item i - JOIN `filter` f ON f.itemFk = i.id - JOIN currentStock s ON s.itemFk = i.id - LEFT JOIN tmp t ON t.itemFk = i.id - LEFT JOIN vn.packaging p ON p.id = t.packagingFk - WHERE CEIL(s.quantity / t.packing) > 0 - -- FIXME: Column Cubos.box not included in view vn.packaging - /* AND p.box */; - - DROP TEMPORARY TABLE - `filter`, - currentStock, - tmp; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getVolume`() -BEGIN -/** - * Cálculo de volumen en líneas de compra - * @table tmp.buy(buyFk) - */ - SELECT t.name Temp, - CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * - item_getVolume(b.itemFk, b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) carros , - CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * - item_getVolume(b.itemFk, b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) espais - FROM buy b - JOIN tmp.buy tb ON tb.buyFk = b.id - JOIN volumeConfig vc - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk - LEFT JOIN temperature t ON t.code = it.temperatureFk - GROUP BY Temp; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkPackaging`(vEntryFk INT) -BEGIN -/** - * Comprueba que los campos package y packaging no sean nulos - * - * @param vEntryFk Id de entrada - */ - DECLARE vpackageOrPackingNull INT; - - SELECT count(*) INTO vpackageOrPackingNull - FROM buy b - WHERE b.entryFk = vEntryFk - AND (b.packing IS NULL OR b.packagingFk IS NULL); - - IF vpackageOrPackingNull THEN - CALL util.throw("packageOrPackingNull"); - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`fustControl`(vFromDated DATE, vToDated DATE) -BEGIN - - DECLARE vSijsnerClientFk INT DEFAULT 19752; - - DECLARE vDateStart DATETIME; - DECLARE vDateEnd DATETIME; - - SET vDateStart = vFromDated; - SET vDateEnd = util.Dayend(vToDated); - - SELECT p.id FustCode, - CAST(sent.stucks AS DECIMAL(10,0)) FH, - CAST(tp.stucks AS DECIMAL(10,0)) Tickets, - CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, - CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo - FROM vn.packaging p - LEFT JOIN ( - SELECT FustCode, sum(fustQuantity) stucks - FROM ( - SELECT IFNULL(pe.equivalentFk ,b.packagingFk) FustCode, s.quantity / b.packing AS fustQuantity - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk - JOIN vn.buy b ON b.id = lb.buy_id - JOIN vn.packaging p ON p.id = b.packagingFk - LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk - WHERE t.shipped BETWEEN vDateStart AND vDateEnd - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA') sub - GROUP BY FustCode) sent ON sent.FustCode = p.id - LEFT JOIN ( - SELECT FustCode, sum(quantity) stucks - FROM ( - SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk - LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk - WHERE t.shipped BETWEEN vDateStart AND vDateEnd - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA' - AND t.clientFk != vSijsnerClientFk - AND tp.quantity > 0) sub - GROUP BY FustCode) tp ON tp.FustCode = p.id - LEFT JOIN ( - SELECT FustCode, sum(quantity) stucks - FROM ( - SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk - LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND t.clientFk = vSijsnerClientFk) sub - GROUP BY FustCode) sj ON sj.FustCode = p.id - WHERE sent.stucks - OR tp.stucks - OR sj.stucks; - -END$$ -DELIMITER ; - diff --git a/db/changes/234601/.gitkeep b/db/changes/234601/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/234601/00-ACLticketTrackingState.sql b/db/changes/234601/00-ACLticketTrackingState.sql deleted file mode 100644 index ca6dce0c9..000000000 --- a/db/changes/234601/00-ACLticketTrackingState.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE `salix`.`ACL` - SET `property` = 'state', - `model` = 'Ticket' - WHERE `property` = 'changeState'; diff --git a/db/changes/234601/00-claimViewerAcl.sql b/db/changes/234601/00-claimViewerAcl.sql deleted file mode 100644 index 17d8d4ce0..000000000 --- a/db/changes/234601/00-claimViewerAcl.sql +++ /dev/null @@ -1,31 +0,0 @@ -INSERT INTO `account`.`role` (`name`, `description`, `hasLogin`) - VALUES ('claimViewer','Trabajadores que consulta las reclamaciones ',1); - -INSERT INTO `account`.`roleInherit` (`role`,`inheritsFrom`) - SELECT `r`.`id`, `r2`.`id` - FROM `account`.`role` `r` - JOIN `account`.`role` `r2` ON `r2`.`name` = 'claimViewer' - WHERE `r`.`name` IN ( - 'salesPerson', - 'buyer', - 'deliveryBoss', - 'handmadeBoss' - ); - -DELETE FROM `salix`.`ACL` - WHERE `model`= 'claim' - AND `property` IN ( - 'filter', - 'find', - 'findById', - 'getSummary' - ); - -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Claim','filter','READ','ALLOW','ROLE','claimViewer'); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Claim','find','READ','ALLOW','ROLE','claimViewer'); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Claim','findById','READ','ALLOW','ROLE','claimViewer'); -INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Claim','getSummary','READ','ALLOW','ROLE','claimViewer'); diff --git a/db/changes/234601/00-clientAfterUpdate.sql b/db/changes/234601/00-clientAfterUpdate.sql deleted file mode 100644 index c6483813f..000000000 --- a/db/changes/234601/00-clientAfterUpdate.sql +++ /dev/null @@ -1,95 +0,0 @@ -ALTER TABLE `vn`.`client` MODIFY COLUMN `credit` decimal(10,2) unsigned DEFAULT 0.00 NOT NULL; - -DELETE FROM `salix`.`ACL` WHERE `model` = 'Client' AND `property` = 'create'; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate` - BEFORE UPDATE ON `client` - FOR EACH ROW -BEGIN - DECLARE vText VARCHAR(255) DEFAULT NULL; - DECLARE vPayMethodFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF NOT(NEW.credit <=> OLD.credit) THEN - INSERT INTO clientCredit - SET clientFk = NEW.id, - amount = NEW.credit, - workerFk = NEW.editorFk; - END IF; - -- Comprueba que el formato de los teléfonos es válido - - IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN - CALL pbx.phone_isValid(NEW.phone); - END IF; - - IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN - CALL pbx.phone_isValid(NEW.mobile); - END IF; - - SELECT id INTO vPayMethodFk - FROM vn.payMethod - WHERE code = 'bankDraft'; - - IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN - SET NEW.dueDay = 5; - END IF; - - -- Avisar al comercial si ha llegado la documentación sepa/core - - IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN - SET vText = 'Sepa de VNL'; - END IF; - - IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN - SET vText = 'Core de VNL'; - END IF; - - IF vText IS NOT NULL - THEN - INSERT INTO mail(receiver, replyTo, `subject`, body) - SELECT - CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'), - 'administracion@verdnatura.es', - CONCAT('Cliente ', NEW.id), - CONCAT('Recibida la documentación: ', vText) - FROM worker w - LEFT JOIN account.user u ON w.id = u.id AND u.active - LEFT JOIN account.account ac ON ac.id = u.id - WHERE w.id = NEW.salesPersonFk; - END IF; - - IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN - IF (SELECT COUNT(clientFk) - FROM clientProtected - WHERE clientFk = NEW.id - ) > 0 THEN - CALL util.throw("HAS_CLIENT_PROTECTED"); - END IF; - END IF; - - IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN - SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); - END IF; - - IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN - SET NEW.isTaxDataChecked = 0; - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_AfterInsert` - AFTER INSERT ON `client` - FOR EACH ROW -BEGIN - IF NEW.credit IS NOT NULL AND NEW.credit THEN - INSERT INTO clientCredit - SET clientFk = NEW.id, - workerFk = NEW.editorFk, - amount = NEW.credit; - END IF; -END$$ -DELIMITER ; - diff --git a/db/changes/234601/00-transferInvoice.sql b/db/changes/234601/00-transferInvoice.sql deleted file mode 100644 index d9ae39464..000000000 --- a/db/changes/234601/00-transferInvoice.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('CplusRectificationType', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('SiiTypeInvoiceOut', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('InvoiceCorrectionType', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'), - ('InvoiceOut', 'transferInvoice', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); diff --git a/db/changes/234601/00-updateCourtesyTime.sql b/db/changes/234601/00-updateCourtesyTime.sql deleted file mode 100644 index 4751b2e03..000000000 --- a/db/changes/234601/00-updateCourtesyTime.sql +++ /dev/null @@ -1,4 +0,0 @@ --- Auto-generated SQL script #202311061003 -UPDATE salix.accessTokenConfig - SET courtesyTime=60 - WHERE id=1; diff --git a/db/changes/234602/00-roleSync.sql b/db/changes/234602/00-roleSync.sql deleted file mode 100644 index 7ce277748..000000000 --- a/db/changes/234602/00-roleSync.sql +++ /dev/null @@ -1 +0,0 @@ -CALL `account`.`role_sync`(); diff --git a/db/changes/234604/00-sambaConfigUserDn.sql b/db/changes/234604/00-sambaConfigUserDn.sql deleted file mode 100644 index cacb30e97..000000000 --- a/db/changes/234604/00-sambaConfigUserDn.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE account.sambaConfig - ADD userDn varchar(255) NOT NULL COMMENT 'Base DN for users without domain DN part'; diff --git a/db/changes/234801/.gitkeep b/db/changes/234801/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/234801/00-ACL_executeRoutine.sql b/db/changes/234801/00-ACL_executeRoutine.sql deleted file mode 100644 index cfe7018e9..000000000 --- a/db/changes/234801/00-ACL_executeRoutine.sql +++ /dev/null @@ -1,4 +0,0 @@ -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('Application', 'executeProc', '*', 'ALLOW', 'ROLE', 'employee'), - ('Application', 'executeFunc', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/234801/00-notificationSubscription.sql b/db/changes/234801/00-notificationSubscription.sql deleted file mode 100644 index ef081437d..000000000 --- a/db/changes/234801/00-notificationSubscription.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('NotificationSubscription', 'getList', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/234802/00-createSignInLogTable.sql b/db/changes/234802/00-createSignInLogTable.sql deleted file mode 100644 index 942f651c9..000000000 --- a/db/changes/234802/00-createSignInLogTable.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- --- Table structure for table `signInLog` --- Description: log to debug cross-login error --- - -DROP TABLE IF EXISTS `account`.`signInLog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `account`.`signInLog` ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `token` varchar(255) NOT NULL , - `userFk` int(10) unsigned DEFAULT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), - `userName` varchar(30) NOT NULL, - `ip` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, - `owner` tinyint(1) DEFAULT 1, - KEY `userFk` (`userFk`), - CONSTRAINT `signInLog_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -); - diff --git a/db/changes/235001/.gitkeep b/db/changes/235001/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/235001/00-getRoutesByWorker.sql b/db/changes/235001/00-getRoutesByWorker.sql deleted file mode 100644 index 00d6e658a..000000000 --- a/db/changes/235001/00-getRoutesByWorker.sql +++ /dev/null @@ -1,26 +0,0 @@ -DELETE FROM `salix`.`ACL` - WHERE - model = 'Route' - AND property = '*' - AND accessType = 'READ'; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('Route', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'findById', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'findOne', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getRoutesByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'canViewAllRoute', 'READ', 'ALLOW', 'ROLE', 'deliveryBoss'), - ('Route', 'cmr', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'downloadCmrsZip', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'downloadZip', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getByWorker', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getDeliveryPoint', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getExternalCmrs', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getSuggestedTickets', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'guessPriority', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'insertTicket', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('Route', 'getDeliveryPoint', 'READ', 'ALLOW', 'ROLE', 'deliveryBoss'), - ('Route', 'summary', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/240001/00-alterTable.sql b/db/changes/240001/00-alterTable.sql deleted file mode 100644 index b6974b715..000000000 --- a/db/changes/240001/00-alterTable.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`ticketTracking` CHANGE `workerFk` `userFk` int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/changes/240001/00-clientCreditLimitToRoleCreditLimit.sql b/db/changes/240001/00-clientCreditLimitToRoleCreditLimit.sql deleted file mode 100644 index 2bc0f830d..000000000 --- a/db/changes/240001/00-clientCreditLimitToRoleCreditLimit.sql +++ /dev/null @@ -1,4 +0,0 @@ -RENAME TABLE `vn`.`clientCreditLimit` TO `vn`.`roleCreditLimit`; -ALTER TABLE `vn`.`roleCreditLimit` DROP FOREIGN KEY `clientCreditLimit_FK`; -ALTER TABLE `vn`.`roleCreditLimit` ADD CONSTRAINT `roleCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - diff --git a/db/changes/240001/01-procedures.sql b/db/changes/240001/01-procedures.sql deleted file mode 100644 index 3777708d5..000000000 --- a/db/changes/240001/01-procedures.sql +++ /dev/null @@ -1,1129 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirmWithUser`(vSelf INT, vUserId INT) -BEGIN -/** - * Confirms an order, creating each of its tickets on the corresponding - * date, store and user. - * - * @param vSelf The order identifier - * @param vUser The user identifier - */ - DECLARE vOk BOOL; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vWarehouse INT; - DECLARE vShipment DATE; - 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 vPriceFixed DECIMAL(10,2); - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vIsConfirmed BOOL; - DECLARE vClientId INT; - DECLARE vCompanyId INT; - DECLARE vAgencyModeId INT; - DECLARE TICKET_FREE INT DEFAULT 2; - DECLARE vCalc INT; - DECLARE vIsLogifloraItem BOOL; - DECLARE vOldQuantity INT; - DECLARE vNewQuantity INT; - DECLARE vIsTaxDataChecked BOOL; - - DECLARE cDates CURSOR FOR - SELECT zgs.shipped, r.warehouse_id - FROM `order` o - JOIN order_row r ON r.order_id = o.id - LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id - WHERE o.id = vSelf AND r.amount != 0 - GROUP BY r.warehouse_id; - - DECLARE cRows CURSOR FOR - SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo - FROM order_row r - JOIN vn.item i ON i.id = r.item_id - WHERE r.amount != 0 - AND r.warehouse_id = vWarehouse - AND r.order_id = vSelf - ORDER BY r.rate DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, - o.company_id, o.agency_id, c.isTaxDataChecked - INTO vDelivery, vAddress, vNotes, vClientId, - vCompanyId, vAgencyModeId, vIsTaxDataChecked - FROM hedera.`order` o - JOIN vn.address a ON a.id = o.address_id - JOIN vn.client c ON c.id = a.clientFk - WHERE o.id = vSelf; - - -- Verifica si el cliente tiene los datos comprobados - IF NOT vIsTaxDataChecked THEN - CALL util.throw ('clientNotVerified'); - END IF; - - -- Carga las fechas de salida de cada almacen - CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE); - - -- Trabajador que realiza la accion - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; - END IF; - - START TRANSACTION; - - CALL order_checkEditable(vSelf); - - -- Check order is not empty - - SELECT COUNT(*) > 0 INTO vOk - FROM order_row WHERE order_id = vSelf AND amount > 0; - - IF NOT vOk THEN - CALL util.throw ('ORDER_EMPTY'); - END IF; - - -- Crea los tickets del pedido - - OPEN cDates; - - lDates: - LOOP - SET vTicket = NULL; - SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouse; - - IF vDone THEN - LEAVE lDates; - END IF; - - -- Busca un ticket existente que coincida con los parametros - WITH tPrevia AS - (SELECT DISTINCT s.ticketFk - FROM vn.sale s - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ) - SELECT t.id INTO vTicket - FROM vn.ticket t - LEFT JOIN tPrevia tp ON tp.ticketFk = t.id - LEFT JOIN vn.ticketState tls on tls.ticket = t.id - JOIN hedera.`order` o - ON o.address_id = t.addressFk - AND vWarehouse = t.warehouseFk - AND o.date_send = t.landed - AND DATE(t.shipped) = vShipment - WHERE o.id = vSelf - AND t.refFk IS NULL - AND tp.ticketFk IS NULL - AND IFNULL(tls.alertLevel,0) = 0 - LIMIT 1; - - -- Crea el ticket en el caso de no existir uno adecuado - IF vTicket IS NULL - THEN - - SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); - - CALL vn.ticket_add( - vClientId, - vShipment, - vWarehouse, - vCompanyId, - vAddress, - vAgencyModeId, - NULL, - vDelivery, - vUserId, - TRUE, - vTicket - ); - ELSE - INSERT INTO vn.ticketTracking - SET ticketFk = vTicket, - userFk = vUserId, - stateFk = TICKET_FREE; - END IF; - - INSERT IGNORE INTO vn.orderTicket - SET orderFk = vSelf, - ticketFk = vTicket; - - -- Añade las notas - - IF vNotes IS NOT NULL AND vNotes != '' - THEN - INSERT INTO vn.ticketObservation SET - ticketFk = vTicket, - observationTypeFk = 4 /* salesperson */, - `description` = vNotes - ON DUPLICATE KEY UPDATE - `description` = CONCAT(VALUES(`description`),'. ', `description`); - END IF; - - -- Añade los movimientos y sus componentes - - OPEN cRows; - - lRows: LOOP - SET vDone = FALSE; - FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; - - IF vDone THEN - LEAVE lRows; - END IF; - - SET vSale = NULL; - - SELECT s.id, s.quantity INTO vSale, vOldQuantity - FROM vn.sale s - WHERE ticketFk = vTicket - AND price = vPrice - AND itemFk = vItem - AND discount = 0 - LIMIT 1; - - IF vSale THEN - UPDATE vn.sale - SET quantity = quantity + vAmount, - originalQuantity = quantity - WHERE id = vSale; - - SELECT s.quantity INTO vNewQuantity - FROM vn.sale s - WHERE id = vSale; - ELSE - -- Obtiene el coste - SELECT SUM(rc.`price`) valueSum INTO vPriceFixed - FROM orderRowComponent rc - JOIN vn.component c ON c.id = rc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk AND ct.isBase - WHERE rc.rowFk = vRowId; - - INSERT INTO vn.sale - SET itemFk = vItem, - ticketFk = vTicket, - concept = vConcept, - quantity = vAmount, - price = vPrice, - priceFixed = vPriceFixed, - isPriceFixed = TRUE; - - SET vSale = LAST_INSERT_ID(); - - INSERT INTO vn.saleComponent - (saleFk, componentFk, `value`) - SELECT vSale, rc.componentFk, rc.price - FROM orderRowComponent rc - JOIN vn.component c ON c.id = rc.componentFk - WHERE rc.rowFk = vRowId - GROUP BY vSale, rc.componentFk; - END IF; - - UPDATE order_row SET Id_Movimiento = vSale - WHERE id = vRowId; - - -- Inserta en putOrder si la compra es de Floramondo - IF vIsLogifloraItem THEN - CALL cache.availableNoRaids_refresh(vCalc,FALSE,vWarehouse,vShipment); - - SET @available := 0; - - SELECT GREATEST(0,available) INTO @available - FROM cache.availableNoRaids - WHERE calc_id = vCalc - AND item_id = vItem; - - UPDATE cache.availableNoRaids - SET available = GREATEST(0,available - vAmount) - WHERE item_id = vItem - AND calc_id = vCalc; - - INSERT INTO edi.putOrder ( - deliveryInformationID, - supplyResponseId, - quantity , - EndUserPartyId, - EndUserPartyGLN, - FHAdminNumber, - saleFk - ) - SELECT di.ID, - i.supplyResponseFk, - CEIL((vAmount - @available)/ sr.NumberOfItemsPerCask), - o.address_id , - vClientId, - IFNULL(ca.fhAdminNumber, fhc.defaultAdminNumber), - vSale - FROM edi.deliveryInformation di - JOIN vn.item i ON i.supplyResponseFk = di.supplyResponseID - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientId - JOIN edi.floraHollandConfig fhc - JOIN hedera.`order` o ON o.id = vSelf - WHERE i.id = vItem - AND di.LatestOrderDateTime > util.VN_NOW() - AND vAmount > @available - LIMIT 1; - END IF; - END LOOP; - - CLOSE cRows; - END LOOP; - - CLOSE cDates; - - UPDATE `order` SET confirmed = TRUE, confirm_date = util.VN_NOW() - WHERE id = vSelf; - - COMMIT; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATE, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN -/** - * Creación de facturas emitidas. - * requiere previamente tabla tmp.ticketToInvoice(id). - * - * @param vSerial serie a la cual se hace la factura - * @param vInvoiceDate fecha de la factura - * @param vTaxArea tipo de iva en relacion a la empresa y al cliente - * @param vNewInvoiceId id de la factura que se acaba de generar - * @return vNewInvoiceId - */ - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompanyFk INT; - DECLARE vInterCompanyFk INT; - DECLARE vClientFk INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInFk INT; - DECLARE vIsInterCompany BOOL DEFAULT FALSE; - DECLARE vIsCEESerial BOOL DEFAULT FALSE; - DECLARE vIsCorrectInvoiceDate BOOL; - DECLARE vMaxShipped DATE; - DECLARE vDone BOOL; - DECLARE vTicketFk INT; - DECLARE vCursor CURSOR FOR - SELECT id - FROM tmp.ticketToInvoice; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); - - SELECT t.clientFk, - t.companyFk, - MAX(DATE(t.shipped)), - DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( - vSerial, - t.companyFk, - YEAR(vInvoiceDate)) - INTO vClientFk, - vCompanyFk, - vMaxShipped, - vIsCorrectInvoiceDate - FROM tmp.ticketToInvoice tt - JOIN ticket t ON t.id = tt.id; - - IF(vMaxShipped > vInvoiceDate) THEN - CALL util.throw("Invoice date can't be less than max date"); - END IF; - - IF NOT vIsCorrectInvoiceDate THEN - CALL util.throw('Exists an invoice with a previous date'); - END IF; - - -- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM tmp.ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN supplier su ON su.id = t.companyFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE - OR itc.id IS NULL; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 - INTO vIsAnySaleToInvoice - FROM tmp.ticketToInvoice t - JOIN sale s ON s.ticketFk = t.id; - - SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice - FROM tmp.ticketToInvoice t - JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - siiTypeInvoiceOutFk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClientFk, - getDueDate(vInvoiceDate, dueDay), - vCompanyFk, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClientFk; - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - OPEN vCursor; - l: LOOP - SET vDone = FALSE; - FETCH vCursor INTO vTicketFk; - - IF vDone THEN - LEAVE l; - END IF; - - CALL ticket_recalc(vTicketFk, vTaxArea); - - END LOOP; - CLOSE vCursor; - - UPDATE ticket t - JOIN tmp.ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id, ti.id ticket_id, vWorker Id_Trabajador - FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticket - JOIN state s - WHERE IFNULL(ts.alertLevel, 0) < 3 and s.`code` = getAlert3State(ti.id); - - INSERT INTO ticketTracking(stateFk, ticketFk, userFk) - SELECT * FROM tmp.updateInter; - - CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId, vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) total - FROM invoiceOutExpense - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT COUNT(*), id - INTO vIsInterCompany, vInterCompanyFk - FROM company - WHERE clientFk = vClientFk; - - IF (vIsInterCompany) THEN - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; - - SET vNewInvoiceInFk = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - @vTaxableBaseServices, - sub.expenseFk, - sub.taxTypeSageFk, - sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, - i.expenseFk, - i.taxTypeSageFk, - i.transactionTypeSageFk, - @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, - @vTaxableBaseServices, 0) taxableBase, - i.expenseFk, - i.taxTypeSageFk , - i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL invoiceInDueDay_calculate(vNewInvoiceInFk); - - SELECT COUNT(*) INTO vIsCEESerial - FROM invoiceOutSerial - WHERE code = vSerial; - - IF vIsCEESerial THEN - - INSERT INTO invoiceInIntrastat ( - invoiceInFk, - intrastatFk, - amount, - stems, - countryFk, - net) - SELECT - vNewInvoiceInFk, - i.intrastatFk, - SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), - SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), - su.countryFk, - CAST(SUM(IFNULL(i.stems, 1) - * s.quantity - * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) - FROM sale s - JOIN ticket t ON s.ticketFk = t.id - JOIN supplier su ON su.id = t.companyFk - JOIN item i ON i.id = s.itemFk - LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - WHERE t.refFk = vNewRef - GROUP BY i.intrastatFk; - - END IF; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - END IF; - END IF; - DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionError_add`() -BEGIN - DECLARE vDatedFrom DATETIME; - DECLARE vDatedTo DATETIME; -/** - * Rellena la tabla vn.productionError con estadisticas de encajadores, revisores y sacadores. Se ejecuta en el nightTask - */ - SELECT util.VN_CURDATE() - INTERVAL 1 DAY, util.dayend(util.VN_CURDATE() - INTERVAL 1 DAY) INTO vDatedFrom, vDatedTo; - CALL timeControl_calculateAll(vDatedFrom, vDatedTo); - - -- Rellena la tabla tmp.errorsByClaim con encajadores, revisores y sacadores - CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByClaim - ENGINE = MEMORY - SELECT COUNT(c.ticketFk) errors, - cd.workerFk - FROM claimDevelopment cd - JOIN claim c ON cd.claimFk = c.id - JOIN ticket t ON c.ticketFk = t.id - JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo - AND cr.code IN ('pic', 'chk', 'pck') - GROUP BY cd.workerFk; - - -- Genera la tabla tmp.volume con encajadores, sacadores y revisores - CREATE OR REPLACE TEMPORARY TABLE tmp.volume - ENGINE = MEMORY - SELECT SUM(w.volume) volume, - w.workerFk - FROM bs.workerProductivity w - WHERE w.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.workerFk; - - -- Rellena la tabla tmp.errorsByChecker con fallos de revisores - CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByChecker - ENGINE = MEMORY - SELECT st.workerFk, - COUNT(t.id) errors - FROM saleMistake sm - JOIN saleTracking st ON sm.saleFk = st.saleFk - JOIN `state` s2 ON s2.id = st.stateFk - JOIN sale s ON s.id = sm.saleFk - JOIN ticket t on t.id = s.ticketFk - WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) - AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') - GROUP BY st.workerFk; - - -- Rellena la tabla tmp.expeditionErrors con fallos de expediciones - CREATE OR REPLACE TEMPORARY TABLE tmp.expeditionErrors - ENGINE = MEMORY - SELECT COUNT(t.id) errors, - e.workerFk - FROM vn.expeditionMistake pm - JOIN vn.expedition e ON e.id = pm.expeditionFk - JOIN vn.ticket t ON t.id = e.ticketFk - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo - GROUP BY e.workerFk; - - -- Genera la tabla tmp.total para sacadores y revisores - CREATE OR REPLACE TEMPORARY TABLE tmp.total - ENGINE = MEMORY - SELECT st.workerFk, - COUNT(DISTINCT t.id) ticketCount, - COUNT(s.id) lineCount - FROM saleTracking st - JOIN `state` s2 ON s2.id = st.stateFk - JOIN sale s ON s.id = st.saleFk - JOIN ticket t ON s.ticketFk = t.id - WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) - AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') - GROUP BY st.workerFk; - - -- Rellena la tabla vn.productionError con sacadores - INSERT INTO productionError(userFk, - firstname, - lastname, - rol, - ticketNumber, - lineNumber, - error, - volume, - hourStart, - hourEnd, - hourWorked, - dated) - SELECT w.id, - w.firstName, - w.lastName, - "Sacadores", - t.ticketCount totalTickets, - t.lineCount, - IFNULL(ec.errors,0) + IFNULL(ec2.errors,0) errors, - v.volume volume, - SUBSTRING(tc.tableTimed, 1, 5) hourStart, - SUBSTRING(tc.tableTimed, LENGTH(tc.tableTimed)-4, 5) hourEnd, - IFNULL(CAST(tc.timeWorkDecimal AS DECIMAL (10,2)) , 0) hourWorked, - vDatedFrom dated - FROM tmp.total t - LEFT JOIN worker w ON w.id = t.workerFk - LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = t.workerFk - LEFT JOIN tmp.errorsByClaim ec ON ec.workerFk = t.workerFk - LEFT JOIN tmp.volume v ON v.workerFk = t.workerFk - LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = t.workerFk - JOIN (SELECT DISTINCT w.id -- Verificamos que son sacadores - FROM vn.collection c - JOIN vn.state s ON s.id = c.stateFk - JOIN vn.train tn ON tn.id = c.trainFk - JOIN vn.worker w ON w.id = c.workerFk - WHERE c.created BETWEEN vDatedFrom AND vDatedTo) sub ON sub.id = w.id - GROUP BY w.id; - - CREATE OR REPLACE TEMPORARY TABLE itemPickerErrors -- Errores de los sacadores, derivadores de los revisadores - ENGINE = MEMORY - SELECT COUNT(c.ticketFk) errors, - tt.userFk - FROM claimDevelopment cd - JOIN claim c ON cd.claimFk = c.id - JOIN ticket t ON c.ticketFk = t.id - JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id - JOIN ticketTracking tt ON tt.ticketFk = t.id - JOIN `state` s ON s.id = tt.stateFk - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo - AND cr.code = 'chk' - AND s.code = 'ON_PREPARATION' - GROUP BY tt.userFk; - - UPDATE productionError ep - JOIN itemPickerErrors ipe ON ipe.workerFk = ep.userFk - SET ep.error = ep.error + ipe.errors - WHERE vDatedFrom = ep.dated AND ep.rol = 'Sacadores'; - - DROP TEMPORARY TABLE itemPickerErrors; - - -- Rellena la tabla vn.productionError con revisores - CALL productionError_addCheckerPackager(vDatedFrom, vDatedTo, "Revisadores"); - - -- Genera la tabla tmp.total para encajadores - CREATE OR REPLACE TEMPORARY TABLE tmp.total - ENGINE = MEMORY - SELECT e.workerFk, - COUNT(DISTINCT t.id) ticketCount, - COUNT(s.id) lineCount - FROM expedition e - JOIN ticket t ON e.ticketFk = t.id - JOIN sale s ON s.ticketFk = t.id - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo - GROUP BY e.workerFk; - - -- Rellena la tabla vn.productionError con encajadores - CALL productionError_addCheckerPackager(vDatedFrom, vDatedTo, "Encajadores"); - - DROP TEMPORARY TABLE tmp.errorsByClaim, - tmp.volume, - tmp.errorsByChecker, - tmp.expeditionErrors, - tmp.total; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorProductivity_add`() -BEGIN - DECLARE vDatedFrom DATETIME; - DECLARE vDatedTo DATETIME; - - SELECT DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY),' 23:59:59') INTO vDatedFrom, vDatedTo; - - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; - DROP TEMPORARY TABLE IF EXISTS tmp.errorsByChecker; - DROP TEMPORARY TABLE IF EXISTS tmp.previousErrors; - - CALL timeControl_calculateAll(vDatedFrom, vDatedTo); - - CREATE TEMPORARY TABLE tmp.errorsByChecker - ENGINE = MEMORY - SELECT sc.userFk workerFk, COUNT(DISTINCT s.ticketFk) errorsByChecker - FROM saleMistake sm - JOIN vn.saleGroupDetail sgd on sgd.saleFk = sm.saleFk - JOIN vn.sectorCollectionSaleGroup scsg on scsg.saleGroupFk = sgd.saleGroupFk - JOIN vn.sectorCollection sc on sc.id = scsg.sectorCollectionFk - JOIN sale s ON s.id = sm.saleFk - JOIN ticket t on t.id = s.ticketFk - WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) - GROUP BY sc.userFk ; - - CREATE TEMPORARY TABLE tmp.previousErrors -- Errores de previa, derivadores de los revisadores (por reclamación) - ENGINE = MEMORY - SELECT tt.userFk, COUNT(c.ticketFk) errorsByClaim - FROM claimDevelopment cd - JOIN claim c ON cd.claimFk = c.id - JOIN ticket t ON c.ticketFk = t.id - JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id - JOIN ticketTracking tt ON tt.ticketFk = t.id - JOIN `state` s ON s.id = tt.stateFk - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.description = 'Revisadores' AND s.code = 'OK PREVIOUS' - GROUP BY cd.workerFk; - - DELETE FROM sectorProductivity - WHERE dated = vDatedFrom - AND sector IN ('Algemesi Artificial','Algemesi Complementos'); - - INSERT INTO sectorProductivity(workerFk, firstName, lastName, sector, ticketCount, saleCount, error, volume, hourWorked, dated) - SELECT w.id workerFk, - w.firstName, - w.lastName, - se.description sector, - COUNT(DISTINCT s.ticketFk) ticketCount, - COUNT(sgd.id) saleCount, - IFNULL(ec2.errorsByChecker,0) + IFNULL(pe.errorsByClaim, 0) errors, - wp.volume, - IFNULL(CAST(tc.timeWorkDecimal AS DECIMAL (10,2)) , 0) AS hourWorked, - DATE(vDatedFrom) dated - FROM vn.saleGroupDetail sgd - JOIN vn.saleGroup sg on sg.id = sgd.saleGroupFk - JOIN vn.sectorCollectionSaleGroup scsg on scsg.saleGroupFk = sgd.saleGroupFk - JOIN vn.sectorCollection sc on sc.id = scsg.sectorCollectionFk - join vn.sector se on se.id = sc.sectorFk - JOIN vn.worker w ON w.id = sc.userFk - LEFT JOIN vn.sale s ON s.id = sgd.saleFk - LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = w.id - LEFT JOIN bs.workerProductivity wp ON wp.workerFk = w.id - LEFT JOIN `state` s2 ON s2.id = wp.stateFk AND s2.code = 'OK PREVIOUS' - LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = w.id - LEFT JOIN tmp.previousErrors pe ON pe.workerFk = w.id - WHERE DATE(sc.created) = vDatedFrom - AND wp.dated = vDatedFrom - GROUP BY w.id; - - DROP TEMPORARY TABLE tmp.timeControlCalculate; - DROP TEMPORARY TABLE tmp.errorsByChecker; - DROP TEMPORARY TABLE tmp.previousErrors; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) -BEGIN - - /* - * @deprecated:utilizar ticket_setState - */ - - DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM vn.state s - JOIN vn.ticketState ts ON ts.stateFk = s.id - WHERE ts.ticketFk = vTicketFk; - - IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN - - INSERT INTO ticketTracking(stateFk, ticketFk, userFk) - SELECT id, vTicketFk, account.myUser_getId() - FROM vn.state - WHERE `code` = vStateCode collate utf8_unicode_ci; - - END IF; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) -BEGIN -/** - * Clona el contenido de un ticket en otro - * - * @param vOriginalTicket ticket Original - * @param vNewTicket ticket creado - */ - DECLARE vStateFk INT; - - INSERT INTO ticket ( - clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus, - routeFk, - priority, - hasPriority, - clonedFrom - ) - SELECT - clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus, - routeFk, - priority, - hasPriority, - vOriginalTicket - FROM ticket - WHERE id = vOriginalTicket; - - SET vNewTicket = LAST_INSERT_ID(); - - INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) - SELECT vNewTicket, observationTypeFk, description - FROM ticketObservation - WHERE ticketFk = vOriginalTicket; - - INSERT INTO ticketTracking(ticketFk, stateFk, userFk, created) - SELECT vNewTicket, stateFk, userFk, created - FROM ticketTracking - WHERE ticketFk = vOriginalTicket - ORDER BY created; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_add`( - vClientId INT - ,vShipped DATE - ,vWarehouseFk INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyModeFk INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,vIsRequiredZone INT - ,OUT vNewTicket INT) -BEGIN -/** -* Crea un ticket, -* ¡¡NO se debe llamar directamente, llamar a salix que hace comprobaciones previas!! -* -* @param vClientId id del cliente -* @param vShipped dia preparacion -* @param vWarehouseFk id del warehouse -* @param vCompanyFk id la empresa -* @param vAddressFk id del consignatario -* @param vAgencyModeFk id de la agencia -* @param vRouteFk id de la ruta | NULL -* @param vlanded dia llegada -* @param vUserId que crea el ticket -* @param vIsRequiredZone Indica si tiene que tener zona valida para ser creado -* @return vNewTicket id del ticket creado -*/ - DECLARE vZoneFk INT; - DECLARE vPrice DECIMAL(10,2); - DECLARE vBonus DECIMAL(10,2); - DECLARE vIsActive BOOL; - - IF vClientId IS NULL THEN - CALL util.throw ('CLIENT_NOT_ESPECIFIED'); - END IF; - - SELECT isActive INTO vIsActive - FROM vn.client - WHERE id = vClientId; - - IF NOT vIsActive THEN - CALL util.throw ('CLIENT_NOT_ACTIVE'); - END IF; - - IF NOT vAddressFk OR vAddressFk IS NULL THEN - SELECT id INTO vAddressFk - FROM address - WHERE clientFk = vClientId - AND isDefaultAddress; - END IF; - - IF vAgencyModeFk IS NOT NULL THEN - CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); - - SELECT zoneFk, price, bonus - INTO vZoneFk, vPrice, vBonus - FROM tmp.zoneGetShipped - WHERE shipped = vShipped - AND warehouseFk = vWarehouseFk - LIMIT 1; - - IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN - CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); - END IF; - END IF; - - INSERT INTO ticket ( - clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - routeFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus - ) - SELECT vClientId, - vShipped, - a.id, - vAgencyModeFk, - a.nickname, - vWarehouseFk, - IF(vRouteFk,vRouteFk,NULL), - vCompanyFk, - vlanded, - vZoneFk, - vPrice, - vBonus - 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; - - IF (SELECT COUNT(*) - FROM bs.clientNewBorn cnb - WHERE cnb.clientFk = vClientId - AND NOT cnb.isRookie) = 0 THEN - - CALL vn.ticketObservation_addNewBorn(vNewTicket); - END IF; - - 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 ticketTracking(stateFk, ticketFk, userFk) - SELECT id, vNewTicket, account.myUser_getId() - FROM state - WHERE `code` = 'DELIVERED'; - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT) -BEGIN -/** - * Cambia el estado del ticket al siguiente estado según la tabla state - * - * @param vSelf id dle ticket - */ - DECLARE vStateFk INT; - DECLARE vNewStateFk INT; - - SELECT stateFk INTO vStateFk - FROM ticketState - WHERE ticketFk = vSelf; - - SELECT nextStateFk INTO vNewStateFk - FROM state - WHERE id = vStateFk; - - INSERT INTO ticketTracking(stateFk, ticketFk, userFk) - VALUES (vNewStateFk, vSelf, account.myUser_getId()); -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setPreviousState`(vTicketFk INT) -BEGIN - DECLARE vControlFk INT; - - SELECT MAX(id) INTO vControlFk - FROM ticketTracking - WHERE ticketFk = vTicketFk; - - IF (SELECT s.code - FROM vn.state s - JOIN ticketTracking tt ON tt.stateFk = s.id - WHERE tt.id = vControlFk) - = 'PREVIOUS_PREPARATION' THEN - SELECT id - INTO vControlFk - FROM ticketTracking tt - JOIN vn.state s ON tt.stateFk = s.id - WHERE ticketFk = vTicketFk - AND id < vControlFk - AND s.code != 'PREVIOUS_PREPARATION' - ORDER BY id DESC - LIMIT 1; - - INSERT INTO ticketTracking(stateFk, ticketFk, userFk) - SELECT s.nextStateFk, tt.ticketFk, account.myUser_getId() - FROM ticketTracking tt - JOIN vn.state s ON tt.stateFk = s.id - WHERE id = vControlFk; - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setState`( - vSelf INT, - vStateCode VARCHAR(255) COLLATE utf8_general_ci -) -BEGIN -/** - * Modifica el estado de un ticket si se cumplen las condiciones necesarias. - * - * @param vSelf el id del ticket - * @param vStateCode estado a modificar del ticket - */ - DECLARE vticketAlertLevel INT; - DECLARE vTicketStateCode VARCHAR(255); - DECLARE vCanChangeState BOOL; - DECLARE vPackedAlertLevel INT; - DECLARE vZoneFk INT; - - SELECT s.alertLevel, s.`code`, t.zoneFk - INTO vticketAlertLevel, vTicketStateCode, vZoneFk - FROM state s - JOIN ticketTracking tt ON tt.stateFk = s.id - JOIN ticket t ON t.id = tt.ticketFk - WHERE tt.ticketFk = vSelf - ORDER BY tt.created DESC - LIMIT 1; - - SELECT id INTO vPackedAlertLevel FROM alertLevel WHERE code = 'PACKED'; - - IF vStateCode = 'OK' AND vZoneFk IS NULL THEN - CALL util.throw('ASSIGN_ZONE_FIRST'); - END IF; - - SET vCanChangeState = ( - vStateCode <> 'ON_CHECKING' OR - vticketAlertLevel < vPackedAlertLevel - )AND NOT ( - vTicketStateCode IN ('CHECKED', 'CHECKING') - AND vStateCode IN ('PREPARED', 'ON_PREPARATION') - ); - - IF vCanChangeState THEN - INSERT INTO ticketTracking (stateFk, ticketFk, userFk) - SELECT id, vSelf, account.myUser_getId() - FROM state - WHERE `code` = vStateCode COLLATE utf8_unicode_ci; - - IF vStateCode = 'PACKED' THEN - CALL ticket_doCmr(vSelf); - END IF; - ELSE - CALL util.throw('INCORRECT_TICKET_STATE'); - END IF; -END$$ -DELIMITER ; diff --git a/db/changes/240001/02-views.sql b/db/changes/240001/02-views.sql deleted file mode 100644 index 86a1049a7..000000000 --- a/db/changes/240001/02-views.sql +++ /dev/null @@ -1,56 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS `vn2008`; -USE `vn`; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `ticketState` -AS SELECT `tt`.`created` AS `updated`, - `tt`.`stateFk` AS `stateFk`, - `tt`.`userFk` AS `workerFk`, - `tls`.`ticketFk` AS `ticketFk`, - `s`.`id` AS `state`, - `s`.`order` AS `productionOrder`, - `s`.`alertLevel` AS `alertLevel`, - `s`.`code` AS `code`, - `tls`.`ticketFk` AS `ticket`, - `tt`.`userFk` AS `worker`, - `s`.`isPreviousPreparable` AS `isPreviousPreparable`, - `s`.`isPicked` AS `isPicked` -FROM ( - ( - `ticketLastState` `tls` - JOIN `ticketTracking` `tt` ON(`tt`.`id` = `tls`.`ticketTrackingFk`) - ) - JOIN `state` `s` ON(`s`.`id` = `tt`.`stateFk`) - ); - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`v_inter` -AS SELECT `tt`.`id` AS `inter_id`, - `tt`.`stateFk` AS `state_id`, - `tt`.`notes` AS `nota`, - `tt`.`created` AS `odbc_date`, - `tt`.`ticketFk` AS `Id_Ticket`, - `tt`.`userFk` AS `Id_Trabajador`, - `tt`.`supervisorFk` AS `Id_supervisor` -FROM `vn`.`ticketTracking` `tt`; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `ticketStateToday` -AS SELECT - `ts`.`ticket` AS `ticket`, - `ts`.`state` AS `state`, - `ts`.`productionOrder` AS `productionOrder`, - `ts`.`alertLevel` AS `alertLevel`, - `ts`.`worker` AS `worker`, - `ts`.`code` AS `code`, - `ts`.`updated` AS `updated`, - `ts`.`isPicked` AS `isPicked` -FROM - (`ticketState` `ts` -JOIN `ticket` `t` ON - (`t`.`id` = `ts`.`ticket`)) -WHERE - `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`()); diff --git a/db/changes/240002/00-silexToSalix.sql b/db/changes/240002/00-silexToSalix.sql deleted file mode 100644 index bad430ac2..000000000 --- a/db/changes/240002/00-silexToSalix.sql +++ /dev/null @@ -1,46 +0,0 @@ - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert` - BEFORE INSERT ON `delivery` - FOR EACH ROW -BEGIN - - IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); - END IF; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate` - BEFORE UPDATE ON `delivery` - FOR EACH ROW -BEGIN - -IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); - END IF; - -END$$ -DELIMITER ; - - -ALTER TABLE `vn`.`address` MODIFY COLUMN longitude decimal(11,7) DEFAULT NULL NULL COMMENT 'Indica la última longitud proporcionada por tabla delivery'; -ALTER TABLE `vn`.`address` MODIFY COLUMN latitude decimal(11,7) DEFAULT NULL NULL COMMENT 'Indica la última latitud proporcionada por tabla delivery'; diff --git a/db/docker.js b/db/docker.js deleted file mode 100644 index ae49c3337..000000000 --- a/db/docker.js +++ /dev/null @@ -1,211 +0,0 @@ -const exec = require('child_process').exec; -const log = require('fancy-log'); -const dataSources = require('../loopback/server/datasources.json'); - -module.exports = class Docker { - constructor(name) { - Object.assign(this, { - id: name, - name, - isRandom: name == null, - dbConf: Object.assign({}, dataSources.vn) - }); - } - - /** - * Builds the database image and runs a container. It only rebuilds the - * image when fixtures have been modified or when the day on which the - * image was built is different to today. Some workarounds have been used - * to avoid a bug with OverlayFS driver on MacOS. - * - * @param {Boolean} ci continuous integration environment argument - * @param {String} networkName Name of the container network - */ - async run(ci, networkName = 'jenkins') { - log('Building container image...'); - await this.execP(`docker build -t salix-db ./db`); - log('Image built.'); - - let dockerArgs; - - if (this.isRandom) - dockerArgs = '-p 3306'; - else { - try { - await this.rm(); - } catch (e) {} - dockerArgs = `--name ${this.name} -p 3306:${this.dbConf.port}`; - } - - let runChown = process.platform != 'linux'; - - let network = ''; - if (ci) network = `--network="${networkName}"`; - - log('Starting container...'); - const container = await this.execP( - `docker run ${network} --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`); - this.id = container.stdout.trim(); - - try { - if (this.isRandom) { - let inspect = await this.execP(`docker inspect -f "{{json .NetworkSettings}}" ${this.id}`); - let netSettings = JSON.parse(inspect.stdout); - - if (ci) { - this.dbConf.host = netSettings.Networks[networkName].IPAddress; - this.dbConf.port = 3306; - } else - this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort']; - } - - await this.wait(); - } catch (err) { - if (this.isRandom) - await this.rm(); - throw err; - } - } - - /** - * Does the minium effort to start the database container, if it doesn't exists - * calls the 'docker' task, if it is started does nothing. Keep in mind that when - * you do not rebuild the docker you may be using an outdated version of it. - * See the 'docker' task for more info. - */ - async start() { - let state; - try { - let result = await this.execP(`docker inspect -f "{{json .State}}" ${this.id}`); - state = JSON.parse(result.stdout); - } catch (err) { - return await this.run(); - } - - switch (state.Status) { - case 'running': - return; - case 'exited': - await this.execP(`docker start ${this.id}`); - await this.wait(); - return; - default: - throw new Error(`Unknown docker status: ${state.Status}`); - } - } - - waitForHealthy() { - return new Promise((resolve, reject) => { - let interval = 100; - let elapsedTime = 0; - let maxInterval = 4 * 60 * 1000; - - log('Waiting for MySQL init process...'); - - async function checker() { - elapsedTime += interval; - let status; - - try { - let result = await this.execP(`docker inspect -f "{{.State.Health.Status}}" ${this.id}`); - status = result.stdout.trimEnd(); - } catch (err) { - return reject(new Error(err.message)); - } - - if (status == 'unhealthy') - return reject(new Error('Docker exited, please see the docker logs for more info')); - - if (status == 'healthy') { - log('MySQL process ready.'); - return resolve(); - } - - if (elapsedTime >= maxInterval) - reject(new Error(`MySQL not initialized whithin ${elapsedTime / 1000} secs`)); - else - setTimeout(bindedChecker, interval); - } - let bindedChecker = checker.bind(this); - bindedChecker(); - }); - } - - wait() { - return new Promise((resolve, reject) => { - const mysql = require('mysql2'); - - let interval = 100; - let elapsedTime = 0; - let maxInterval = 4 * 60 * 1000; - - let myConf = { - user: this.dbConf.username, - password: this.dbConf.password, - host: this.dbConf.host, - port: this.dbConf.port, - connectTimeout: maxInterval - }; - - log('Waiting for MySQL init process...'); - - async function checker() { - elapsedTime += interval; - let state; - - try { - let result = await this.execP(`docker inspect -f "{{json .State}}" ${this.id}`); - state = JSON.parse(result.stdout); - } catch (err) { - return reject(new Error(err.message)); - } - - if (state.Status === 'exited') - return reject(new Error('Docker exited, please see the docker logs for more info')); - - let conn = mysql.createConnection(myConf); - - conn.on('error', () => {}); - conn.connect(err => { - conn.destroy(); - if (!err) { - log('MySQL process ready.'); - return resolve(); - } - - if (elapsedTime >= maxInterval) - reject(new Error(`MySQL not initialized whithin ${elapsedTime / 1000} secs`)); - else - setTimeout(bindedChecker, interval); - }); - } - let bindedChecker = checker.bind(this); - bindedChecker(); - }); - } - - rm() { - return this.execP(`docker stop ${this.id} && docker rm -v ${this.id}`); - } - - /** - * Promisified version of exec(). - * - * @param {String} command The exec command - * @return {Promise} The promise - */ - execP(command) { - return new Promise((resolve, reject) => { - exec(command, (err, stdout, stderr) => { - if (err) - reject(err); - else { - resolve({ - stdout: stdout, - stderr: stderr - }); - } - }); - }); - } -}; diff --git a/db/docker/docker-dump.sh b/db/docker/docker-dump.sh deleted file mode 100755 index 0d7a379a7..000000000 --- a/db/docker/docker-dump.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -export MYSQL_PWD=root -FILE="/docker-boot/$1.sql" -echo "[INFO] -> Importing $FILE" -mysql -u root --default-character-set=utf8 --comments -f < "$FILE" diff --git a/db/docker/docker-fixtures.sh b/db/docker/docker-fixtures.sh deleted file mode 100755 index 0de6114d9..000000000 --- a/db/docker/docker-fixtures.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -. /usr/local/bin/docker-entrypoint.sh -CMD=mysqld - -docker_setup_env "$CMD" -docker_temp_server_start "$CMD" -bash import-changes.sh -docker-dump.sh fixtures -docker_temp_server_stop diff --git a/db/docker/docker-init.sh b/db/docker/docker-init.sh deleted file mode 100755 index ccd14283e..000000000 --- a/db/docker/docker-init.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -. /usr/local/bin/docker-entrypoint.sh -CMD=mysqld - -mysql_check_config "$CMD" -docker_setup_env "$CMD" -docker_create_db_directories - -docker_verify_minimum_env -docker_init_database_dir "$CMD" -docker_temp_server_start "$CMD" -docker_setup_db -docker_process_init_files /docker-entrypoint-initdb.d/* diff --git a/db/docker/docker-start.sh b/db/docker/docker-start.sh deleted file mode 100755 index 1db1933d1..000000000 --- a/db/docker/docker-start.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# XXX: Workaround to avoid OverlayFS bug on MacOs -# https://docs.docker.com/storage/storagedriver/overlayfs-driver/#limitations-on-overlayfs-compatibility - -if [ "$RUN_CHOWN" = "true" ]; then - chown -R mysql:mysql /mysql-data -fi - -exec "$@" diff --git a/db/docker/docker-structure.sh b/db/docker/docker-structure.sh deleted file mode 100755 index 75a1c24f3..000000000 --- a/db/docker/docker-structure.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -. docker-init.sh -docker-dump.sh structure -docker-dump.sh mockDate -docker-dump.sh dumpedFixtures -. docker-temp-stop.sh diff --git a/db/docker/docker-temp-stop.sh b/db/docker/docker-temp-stop.sh deleted file mode 100644 index df66959df..000000000 --- a/db/docker/docker-temp-stop.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -. /usr/local/bin/docker-entrypoint.sh -CMD=mysqld - -docker_setup_env "$CMD" -docker_temp_server_stop diff --git a/db/docker/docker.cnf b/db/docker/docker.cnf deleted file mode 100644 index be79ecf69..000000000 --- a/db/docker/docker.cnf +++ /dev/null @@ -1,8 +0,0 @@ -[mysqld] -innodb_log_file_size = 4M -innodb_autoextend_increment = 4 -innodb_page_size = 8K -log_bin_trust_function_creators = ON -datadir = /mysql-data -sql_mode = NO_ENGINE_SUBSTITUTION -skip-log-bin diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql new file mode 100644 index 000000000..69a59885a --- /dev/null +++ b/db/dump/.dump/data.sql @@ -0,0 +1,2736 @@ +USE `util`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL); +INSERT INTO `version` VALUES ('vn-database','10806','f73a447391b7541f41e3be2ccc05327c1254578e','2024-01-04 08:36:01','10808'); + +INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10097','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10103','00-awbVolume.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10104','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10105','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10113','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10119','00-AfegirFKPart1.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10119','01-AfegirFkPart2.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10125','00-firstScript.sql','jenkins@10.0.2.68','2022-05-18 18:44:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10132','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10133','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 14:32:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10134','00-firstScript.sql','jenkins@10.0.2.69','2022-05-06 07:45:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10135','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10136','00-workerTimeControl.sql','jenkins@10.0.2.69','2022-05-09 13:51:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10138','00-firstScript.sql','jenkins@10.0.2.69','2022-05-10 13:58:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10139','00-firstScript.sql','jenkins@10.0.2.68','2022-05-16 14:32:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10139','01-secondScript.sql','jenkins@10.0.2.68','2022-05-17 12:16:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10141','00-firstScript.sql','jenkins@10.0.2.70','2022-05-12 08:27:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10142','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10143','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10144','00-AfegirFKPArt1.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10144','00-firstScript.sql','jenkins@10.0.2.68','2022-05-13 09:44:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10147','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10149','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10150','00-firstScript.sql','jenkins@10.0.2.68','2022-05-17 09:57:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10152','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10153','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10154','00-compressionKk.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10157','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10158','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10160','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:30:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10163','00-firstScript.sql','jenkins@10.0.2.68','2022-05-23 08:17:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10164','00-borrarSectorsDesus.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10165','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10166','00-firstScript.sql','jenkins@10.0.2.68','2022-05-24 16:11:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10167','00-renameVnActiveContrat.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10168','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10169','00-createTableBankEntityConfig.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10169','02-addNotNullToBankEntityBic.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10171','00-volumeConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 14:11:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10171','01-itemWeight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10171','02-agencymode.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10172','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10174','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10175','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10177','00-crearTablaSpecialLabels.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10178','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10179','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10183','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10184','00-firstScript.sql','jenkins@10.0.2.68','2022-06-03 08:05:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10185','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 09:07:45',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10186','00-desactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:31:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10186','01-alter_Table_buy.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10186','02-alter_table_entryConfig.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10186','04-regularizar_Sticker_Inventario.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10186','09-reactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10187','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 12:37:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10188','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 14:03:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10189','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10191','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10193','00-delete.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10193','01-botanicExport.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10193','02-item.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10193','03-autonomy.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10193','03-turn.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10193','04-country.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10194','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10195','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10200','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10201','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10202','00-Remove_FK_to_ediGenus.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10203','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10204','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10205','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10207','00-Alter_table_entry.sql','jenkins@10.0.2.69','2022-06-16 07:22:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10207','01-Update_invoiceAmount.sql','jenkins@10.0.2.69','2022-06-16 07:23:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10208','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10209','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 08:47:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10210','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 17:39:17',1046,'Base de datos no seleccionada'); +INSERT INTO `versionLog` VALUES ('vn-database','10211','01-firstScript.sql','jenkins@10.0.2.69','2022-06-17 07:11:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10215','00-renameIsInventory.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10216','00-firstScript.sql','jenkins@10.0.2.69','2022-06-23 11:15:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10216','01-batchIndex.sql','jenkins@10.0.2.70','2022-06-27 18:10:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10219','00-AddCollectionFkOnPackingSite.sql','jenkins@10.0.2.70','2022-06-29 09:23:42',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10219','01-AddFkToCollectionFk.sql','jenkins@10.0.2.70','2022-06-29 09:23:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10220','00-createPersonalProtectionEquipment.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10222','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:12:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10223','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:52',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10224','00-cosetes.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-21 12:03:45',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10229','00-firstScript.sql','jenkins@10.0.2.69','2022-07-01 11:59:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10231','01-tablaEktConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:25:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10233','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10235','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10236','00-firstScript.sql','jenkins@10.0.2.69','2022-07-05 12:11:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10237','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10238','00-worker_mobileExtension.sql','jenkins@10.0.2.69','2022-07-14 09:14:09',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10239','00-firstScript.sql','jenkins@10.0.2.69','2022-07-07 21:51:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10241','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-29 08:14:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10242','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10243','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10245','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10247','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10248','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-20 17:27:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10250','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10253','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:57',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10254','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10256','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10258','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10259','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-02 08:54:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10261','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-22 08:42:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10262','00-createTablepackagingWithFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10262','01-alterTablePackagingConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10262','02-insertsInicials.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10262','03-createTablepackingWithoutFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10263','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10265','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10267','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10267','01-fixMerge.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10275','00-improvedGeneralLog.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 09:55:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10277','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10278','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 17:51:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10279','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10281','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10282','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10283','00-alterTable.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10284','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-04 16:59:08',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10285','00-firstScript.sql','jenkins@swarm-worker3.static.verdnatura.es','2022-08-05 09:19:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10287','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10288','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10289','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10291','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-10 14:19:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10293','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10297','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-16 12:43:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10298','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-13 21:04:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10299','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10301','00-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10301','01-drop.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10301','02-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10302','00-CreateTableEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10302','01-insertDataEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10302','02-alterTableEntry.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10303','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10304','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10304','01-altertableticket.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10305','00-ektAssign.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:24:52',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10306','00-deliveryInformation.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10307','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10308','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:26:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10309','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10310','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10311','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10312','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10313','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:27:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10314','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:19',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10315','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10317','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10318','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10319','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10320','00-operator.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10320','01-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10320','02-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10321','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 11:11:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10322','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-09 09:19:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10326','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10328','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10329','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10330','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10332','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10334','00-collectionHotbed.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10334','01-saleGroupDetail.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10335','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10336','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10337','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10339','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-19 09:41:19',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10340','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10341','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10342','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10343','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:35:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10345','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10347','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10347','01-addVirtualField.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10349','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10350','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-30 10:11:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10352','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10353','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10354','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10356','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10356','01-orderConfigFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10356','02-orderConfigDrop.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10357','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10359','00-improvedGeneralLog_collate.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10360','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10361','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 11:16:07',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10362','00-dropUdfs.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-10 11:01:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10363','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10365','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-13 19:30:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10368','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10369','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-14 13:38:06',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10370','00-deleteForeignKey.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10370','01-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10370','02-deleteTable.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10370','03-accion.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10370','04-inter.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10371','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10372','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10373','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-19 08:31:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10378','00-rename_routeUserPercentage.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10379','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10382','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10383','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10384','00-business_workcenterFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10385','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10386','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10387','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-16 14:05:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10388','00-resizeUtilVerionLogCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10388','01-resizeUtilVersionCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10390','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10391','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10394','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10395','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10396','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 15:36:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10397','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10399','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10400','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10402','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-21 14:11:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10404','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10405','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10407','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10408','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10409','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10412','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-30 12:45:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10413','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10416','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10420','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10421','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10426','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10428','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10431','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10433','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10434','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10435','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-13 07:30:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10436','00-createFkWorker.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:59',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10436','01-addStateToWorkerProductivity.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10436','02-DeprecateVnSaleTrackingState.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10436','03-DeprecateColumnVnSaleTrackingActionFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10436','04-DropSchemaVnControl.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10436','05-RemoveFkWorkerProductivity.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-17 14:51:19',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10439','00-fixRole.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10440','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10444','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10445','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10448','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10450','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-27 08:28:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10451','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-06 08:08:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10452','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10453','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 14:04:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10454','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10455','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10456','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10457','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10458','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10459','00-alterTableUtilConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10459','01-createFunctionCurdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10459','02-createFunctionMockTime.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10459','03-createFunctionMockTimeBase.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10459','04-createFunctionNow.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10460','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10461','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10463','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-03 12:59:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10468','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10469','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10470','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10471','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10472','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10477','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10478','00-dropBasket.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10478','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10478','01-orderConfigured.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10478','02-configuredUpdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10478','99-privileges.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10480','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 15:09:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10481','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 16:37:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10482','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-21 10:00:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10485','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10488','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10491','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10492','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10493','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10495','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:19',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10498','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10500','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 07:06:03',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10501','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 10:52:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10502','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10504','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10506','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10506','01-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10506','02-secondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10506','03-thirdScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10507','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:35:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10508','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10510','00-dropBusinessFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10510','01-createTableProfessionalCategory.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10510','02-exportToNewTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10510','03-RecreateFK.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10510','04-kkPostgresqlTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10511','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10512','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:52',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10513','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10514','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10516','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10521','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 06:58:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10522','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10523','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10524','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10524','01-rateEditorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10525','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 12:42:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10526','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:57',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10528','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10530','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-23 14:49:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10531','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:47:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10532','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:17:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10533','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10537','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-29 15:18:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10538','00-createChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10538','01-createChronopostService.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10538','02-createChronopostExpedition.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10538','03-createChronopostSenderAddress.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10538','04-addgrantPrivilegies.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10538','05-updateChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 11:54:57',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10539','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:07',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10540','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10545','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-11 08:31:03',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10546','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10547','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:21:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10549','00-updateUpdateLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:29:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10549','01-updateInsertLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10549','02-updateDeleteLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10549','03-deleteEmptyLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:31:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10549','04-optimizeLogTables.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:33:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10550','00-editorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:42:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10550','01-originFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10552','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-13 08:25:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10554','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10557','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-17 07:45:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10559','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-18 10:53:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10560','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-17 09:19:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10562','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10563','00-delivery_ticketFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 09:30:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10566','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:08:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10567','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:18:06',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10568','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10569','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-24 09:14:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10570','00-createSendingConfig.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10570','01-createSendingServiceWeekday.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10570','02-createSendingService.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10570','03-permisos.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10571','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10573','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10575','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-26 11:27:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10577','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-27 14:00:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10578','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10579','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-28 11:27:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10580','00-itemTypeDropConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:18:52',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10580','01-itemTypeAddConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:19:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10581','00-itemTypeAutoIncrement.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 19:06:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10582','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10583','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10584','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','00-ticketLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:20:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','01-entryLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:21:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','02-claimLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','03-clientLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','04-invoiceInLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','05-itemLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:29:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','06-routeLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','07-shelvingLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','08-supplierLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','09-travelLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','10-workerLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:42',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','11-zoneLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:43',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','12-userLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10585','13-roleLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10587','00-arcRead_addMinimum.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-16 13:13:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10593','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10596','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10597','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10598','00-workerLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10598','01-supplierLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10598','02-workerTimeControlLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10598','03-workerClockLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10599','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10601','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-17 09:26:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10602','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 08:52:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10606','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 09:26:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10608','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 12:36:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10609','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 08:28:07',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10610','00-updateCompanyId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:07',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10610','01-updateSupplierId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10610','02-invoiceOutCompany.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 09:49:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10611','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-19 14:39:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10613','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10614','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10615','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10616','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10616','01-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10617','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:41',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10618','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 12:55:56',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10619','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10620','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:20:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10624','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-30 19:01:10',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10625','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10626','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 13:32:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10628','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10630','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-02 13:30:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10631','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-05 08:37:25',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10632','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10633','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10634','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-06 12:15:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10637','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:19',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10640','00-companyFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10640','00-updateCompany.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-07 14:22:13',1205,'Tiempo de espera de bloqueo excedido; intente rearrancar la transacción'); +INSERT INTO `versionLog` VALUES ('vn-database','10640','01-companyFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10640','02-companyFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:47:04',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10640','04-supplierFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:48:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10640','05-supplierFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:53:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10640','06-supplierFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 15:06:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10642','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10643','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-09 15:04:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10644','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10645','00-addNewFields.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10645','01-updateCollectionWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10645','02-updateWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10645','03-addFieldToPackingSite.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10647','00-renombrarTabla.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10648','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10649','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-16 10:59:06',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10651','00-comparativeCountryFk.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10651','01-comparativeAddConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10651','02-nightTaskAddNewTask.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10652','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10653','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10655','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10656','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10657','00-renameErrorProduction.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10657','01-changeNightTask.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10657','02-addCodeToClaimResponsible.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10657','03-grantSelectGrafana.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10658','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10659','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10661','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10662','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:33',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10663','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10665','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-30 08:52:51',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10666','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10667','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10668','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10671','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-25 14:56:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10675','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10676','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10677','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10678','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10679','00-tables.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10680','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-18 14:58:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10682','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10683','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10684','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10685','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:53:55',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10690','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-27 10:52:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10691','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-31 13:37:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10692','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10693','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10694','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 09:50:53',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10695','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 13:40:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10696','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 16:54:57',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10698','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-03 08:53:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10699','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 15:24:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10700','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:11',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10701','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10702','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 12:50:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10704','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10705','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-16 14:16:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10707','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-21 12:31:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10708','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10712','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10714','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-28 13:01:45',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10716','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10717','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:28:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10718','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10719','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-01 12:53:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10720','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10721','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10722','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-09 13:00:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10725','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-12 14:15:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10726','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 15:32:20',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','00-addPrinterField.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','01-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','02-createTableScreen.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','03-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','04-createTableScanner.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','05-createTablePackingSiteDeviceLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','06-alterTablePrinterModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10727','07-AddFieldsToPackingSite.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10730','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-15 11:42:48',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10733','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:54:00',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10736','00-workerBossNull.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-22 00:02:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10739','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-10 10:19:07',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10740','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10741','01-refactorCplusTrascendency472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10741','02-refactorCplusTrascendency477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10741','03-refactorCplusInvoiceType477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10741','04-refactorCplusInvoiceType472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10741','05-fixes.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10744','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-13 09:23:19',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10746','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-16 18:22:46',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10747','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10748','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10748','01-SecondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10749','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-22 16:08:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10750','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-23 13:04:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10750','00-ticket_addGrants.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10751','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10752','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-24 14:07:54',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10753','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-24 14:37:21',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10754','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10755','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10756','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-03 07:14:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10757','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:57',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10758','00-sectorType.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10758','01-dipole.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10761','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10768','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10771','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:37',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10773','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10775','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:18:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10778','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10782','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:18:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10783','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-24 14:49:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10785','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10785','02-invoiceIn.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:38',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10785','02-invoiceInTax.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10785','02-item.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10789','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10792','00-buy.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:20:15',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10798','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:21:14',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10799','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-26 12:00:59',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10800','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:21:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10806','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-03 11:56:05',NULL,NULL); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `account`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 09:04:58','2023-06-08 18:47:57',NULL); +INSERT INTO `role` VALUES (2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 09:04:58','2023-06-02 22:33:28',NULL); +INSERT INTO `role` VALUES (3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (9,'developer','Desarrolladores del sistema',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (11,'account','Privilegios relacionados con el login',0,'2017-05-19 09:04:58','2017-09-20 19:06:35',NULL); +INSERT INTO `role` VALUES (13,'teamBoss','Jefe de equipo/departamento',1,'2017-05-19 09:04:58','2021-06-30 15:29:30',NULL); +INSERT INTO `role` VALUES (15,'logistic','Departamento de compras, responsables de la logistica',1,'2017-05-19 09:04:58','2018-02-12 11:50:10',NULL); +INSERT INTO `role` VALUES (16,'logisticBoss','Jefe del departamento de logística',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (17,'adminBoss','Jefe del departamento de administración',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (18,'salesPerson','Departamento de ventas',1,'2017-05-19 09:04:58','2017-05-19 09:04:58',NULL); +INSERT INTO `role` VALUES (19,'salesBoss','Jefe del departamento de ventas',1,'2017-05-19 09:04:58','2017-08-16 14:38:27',NULL); +INSERT INTO `role` VALUES (20,'manager','Gerencia',1,'2017-06-01 16:57:02','2022-07-29 09:36:15',NULL); +INSERT INTO `role` VALUES (21,'salesAssistant','Jefe auxiliar de ventas',1,'2017-08-16 14:40:52','2017-08-16 14:40:52',NULL); +INSERT INTO `role` VALUES (22,'teamManager','Jefe de departamento con privilegios de auxiliar de venta.',1,'2017-09-07 11:08:12','2017-09-07 11:08:12',NULL); +INSERT INTO `role` VALUES (30,'financialBoss','Director finaciero',1,'2017-09-21 13:05:36','2017-09-21 13:05:36',NULL); +INSERT INTO `role` VALUES (31,'freelancer','Trabajadores por cuenta ajena',1,'2017-10-10 14:57:26','2017-10-10 14:59:27',NULL); +INSERT INTO `role` VALUES (32,'ett','Trabajadores de empresa temporal',1,'2017-10-10 14:58:58','2017-10-10 14:59:20',NULL); +INSERT INTO `role` VALUES (33,'invoicing','Personal con acceso a facturación',0,'2018-01-29 17:43:34','2018-01-29 17:43:34',NULL); +INSERT INTO `role` VALUES (34,'agencyBoss','Jefe/a del departamento de agencias',1,'2018-01-29 17:44:39','2018-02-23 08:58:53',NULL); +INSERT INTO `role` VALUES (35,'buyer','Departamento de compras',1,'2018-02-12 11:35:42','2018-02-12 11:35:42',NULL); +INSERT INTO `role` VALUES (36,'replenisher','Trabajadores de camara',1,'2018-02-16 15:07:10','2019-04-12 07:38:08',NULL); +INSERT INTO `role` VALUES (37,'hr','Gestor/a de recursos humanos',1,'2018-02-22 18:34:53','2018-02-22 18:34:53',NULL); +INSERT INTO `role` VALUES (38,'hrBoss','Jefe/a de recursos humanos',1,'2018-02-22 18:35:09','2018-02-22 18:35:09',NULL); +INSERT INTO `role` VALUES (39,'adminAssistant','Jefe auxiliar administrativo',1,'2018-02-23 11:37:36','2018-02-23 11:38:41',NULL); +INSERT INTO `role` VALUES (40,'handmade','Departamento de confección',1,'2018-02-23 12:14:53','2018-02-23 12:39:12',NULL); +INSERT INTO `role` VALUES (41,'handmadeBoss','Jefe de departamento de confección',1,'2018-02-23 12:15:09','2018-02-23 12:39:26',NULL); +INSERT INTO `role` VALUES (42,'artificial','Departamento de artificial',1,'2018-02-23 12:39:59','2018-02-23 12:39:59',NULL); +INSERT INTO `role` VALUES (43,'artificialBoss','Jefe del departamento de artificial',1,'2018-02-23 12:40:16','2018-02-23 12:40:16',NULL); +INSERT INTO `role` VALUES (44,'accessory','Departamento de complementos',1,'2018-02-23 12:41:12','2018-02-23 12:41:12',NULL); +INSERT INTO `role` VALUES (45,'accessoryBoss','Jefe del departamento de complementos',1,'2018-02-23 12:41:23','2018-02-23 12:41:23',NULL); +INSERT INTO `role` VALUES (47,'cooler','Empleados de cámara',1,'2018-02-23 14:08:18','2018-02-23 14:08:18',NULL); +INSERT INTO `role` VALUES (48,'coolerBoss','Jefe de cámara',1,'2018-02-23 14:12:01','2023-03-13 09:49:43',NULL); +INSERT INTO `role` VALUES (49,'production','Empleado de producción',1,'2018-02-26 16:28:23','2021-02-12 10:42:35',NULL); +INSERT INTO `role` VALUES (50,'productionBoss','Jefe de producción',1,'2018-02-26 16:34:12','2018-02-26 16:34:12',NULL); +INSERT INTO `role` VALUES (51,'marketing','Departamento de marketing',1,'2018-03-01 08:28:39','2018-03-01 08:28:39',NULL); +INSERT INTO `role` VALUES (52,'marketingBoss','Jefe del departamento de marketing',1,'2018-03-01 08:28:57','2018-03-01 08:28:57',NULL); +INSERT INTO `role` VALUES (53,'insurance','Gestor de seguros de cambio',0,'2018-03-05 08:44:35','2019-02-01 14:47:57',NULL); +INSERT INTO `role` VALUES (54,'itemPicker','Sacador en cámara',1,'2018-03-05 13:08:17','2018-03-05 13:08:17',NULL); +INSERT INTO `role` VALUES (55,'itemPickerBoss','Jefe de sacadores',1,'2018-03-05 13:08:31','2018-03-05 13:08:31',NULL); +INSERT INTO `role` VALUES (56,'delivery','Personal de reparto',1,'2018-05-30 08:07:02','2018-05-30 08:07:02',NULL); +INSERT INTO `role` VALUES (57,'deliveryBoss','Jefe de personal de reparto',1,'2018-05-30 08:07:19','2018-05-30 08:07:19',NULL); +INSERT INTO `role` VALUES (58,'packager','Departamento encajadores',1,'2019-01-21 13:43:45','2019-01-21 13:43:45',NULL); +INSERT INTO `role` VALUES (59,'packagerBoss','Jefe departamento encajadores',1,'2019-01-21 13:44:10','2019-01-21 13:44:10',NULL); +INSERT INTO `role` VALUES (60,'productionAssi','Tareas relacionadas con producción y administración',1,'2019-01-29 14:29:01','2019-01-29 14:29:01',NULL); +INSERT INTO `role` VALUES (61,'replenisherBos','Jefe de Complementos/Camara',1,'2019-07-01 08:44:07','2019-07-01 08:44:07',NULL); +INSERT INTO `role` VALUES (62,'noLogin','Role without login access to MySQL',0,'2019-07-01 08:50:19','2019-07-02 15:42:05',NULL); +INSERT INTO `role` VALUES (64,'balanceSheet','Consulta de Balance',0,'2019-07-16 14:12:08','2019-07-16 14:12:08',NULL); +INSERT INTO `role` VALUES (65,'officeBoss','Jefe de filial',1,'2019-08-02 08:54:26','2019-08-02 08:54:26',NULL); +INSERT INTO `role` VALUES (66,'sysadmin','Administrador de sistema',1,'2019-08-08 08:58:56','2019-08-08 08:58:56',NULL); +INSERT INTO `role` VALUES (67,'adminOfficer','categoria profesional oficial de administración',1,'2020-01-03 09:09:23','2020-01-03 09:09:23',NULL); +INSERT INTO `role` VALUES (69,'coolerAssist','Asistente de cámara con permiso compras',1,'2020-02-05 13:36:09','2023-03-13 09:50:07',NULL); +INSERT INTO `role` VALUES (70,'trainee','Alumno de prácticas',1,'2020-03-04 12:00:25','2020-03-04 12:00:25',NULL); +INSERT INTO `role` VALUES (71,'checker','Rol de revisor con privilegios de itemPicker',1,'2020-10-02 12:50:07','2020-10-02 12:50:07',NULL); +INSERT INTO `role` VALUES (72,'claimManager','Personal de reclamaciones',1,'2020-10-13 12:01:32','2020-10-26 08:29:46',NULL); +INSERT INTO `role` VALUES (73,'financial','Departamento de finanzas',1,'2020-11-16 10:30:27','2020-11-16 10:30:27',NULL); +INSERT INTO `role` VALUES (74,'userPhotos','Privilegios para subir fotos de usuario',1,'2021-02-03 11:24:27','2021-02-03 11:24:27',NULL); +INSERT INTO `role` VALUES (75,'catalogPhotos','Privilegios para subir fotos del catálogo',1,'2021-02-03 11:24:27','2021-02-03 11:24:27',NULL); +INSERT INTO `role` VALUES (76,'chat','Rol para utilizar el rocket chat',1,'2020-11-27 14:06:50','2020-12-17 08:49:41',NULL); +INSERT INTO `role` VALUES (100,'root','Rol con todos los privilegios',0,'2018-04-23 16:33:36','2020-11-12 07:50:07',NULL); +INSERT INTO `role` VALUES (101,'buyerBoss','Jefe del departamento de compras',1,'2021-06-16 11:53:17','2021-06-16 11:53:17',NULL); +INSERT INTO `role` VALUES (102,'preservedBoss','Responsable preservado',1,'2021-09-14 15:45:37','2021-09-14 15:45:37',NULL); +INSERT INTO `role` VALUES (103,'it','Departamento de informática',1,'2021-11-11 10:48:22','2021-11-11 10:48:22',NULL); +INSERT INTO `role` VALUES (104,'itBoss','Jefe de departamento de informática',1,'2021-11-11 10:48:49','2021-11-11 10:48:49',NULL); +INSERT INTO `role` VALUES (105,'grant','Adjudicar roles a usuarios',1,'2021-11-11 13:41:09','2021-11-11 13:41:09',NULL); +INSERT INTO `role` VALUES (106,'ext','Usuarios externos de la Base de datos',1,'2021-11-23 15:51:16','2021-11-23 15:51:16',NULL); +INSERT INTO `role` VALUES (107,'productionPlus','Creado para pepe por orden de Juanvi',1,'2022-02-08 07:47:10','2022-02-08 07:47:10',NULL); +INSERT INTO `role` VALUES (108,'system','System user',1,'2022-05-16 10:09:51','2022-05-16 10:09:51',NULL); +INSERT INTO `role` VALUES (109,'salesTeamBoss','Jefe de equipo de comerciales',1,'2022-06-14 15:45:56','2022-06-14 15:45:56',NULL); +INSERT INTO `role` VALUES (110,'palletizer','Paletizadores',1,'2022-12-02 13:56:22','2022-12-02 13:56:30',NULL); +INSERT INTO `role` VALUES (111,'entryEditor','Entry editor',1,'2023-01-13 12:21:55','2023-01-13 12:21:55',NULL); +INSERT INTO `role` VALUES (112,'maintenance','Personal de mantenimiento',1,'2023-01-19 07:23:35','2023-01-19 07:23:35',NULL); +INSERT INTO `role` VALUES (114,'maintenanceBos','Jefe de mantenimiento',1,'2023-01-19 07:31:16','2023-05-17 13:07:21',NULL); +INSERT INTO `role` VALUES (115,'itManagement','TI management',1,'2023-03-29 09:27:55','2023-03-29 09:28:04',NULL); +INSERT INTO `role` VALUES (119,'palletizerBoss','Jefe de paletizadores',1,'2023-06-07 13:51:54','2023-06-07 13:51:54',NULL); +INSERT INTO `role` VALUES (120,'developerBoss','Jefe de proyecto de desarrollo',1,'2023-06-19 09:07:21','2023-06-19 09:07:21',21709); +INSERT INTO `role` VALUES (121,'buyerSalesAssistant','Rol para compradores que también son responsables de ventas',1,'2023-06-23 16:48:19','2023-06-23 16:48:19',NULL); +INSERT INTO `role` VALUES (122,'logisticAssistant','Jefe auxiliar de logística',1,'2023-06-26 09:21:15','2023-06-26 09:21:15',NULL); +INSERT INTO `role` VALUES (123,'deliveryAssistant','Jefe auxiliar repartos',1,'2023-10-05 08:47:48','2023-10-05 08:47:48',10578); +INSERT INTO `role` VALUES (124,'hrBuyer','Recursos Humanos con Buyer',1,'2023-10-23 13:50:43','2023-10-23 13:50:43',NULL); +INSERT INTO `role` VALUES (125,'claimViewer','Trabajadores que consulta las reclamaciones ',1,'2023-11-16 09:14:46','2023-11-16 09:14:46',10578); +INSERT INTO `role` VALUES (126,'greenhouseBoss','Jefe de invernadero',1,'2023-11-16 14:32:13','2023-11-16 14:32:13',NULL); + +INSERT INTO `roleInherit` VALUES (1,1,2,NULL); +INSERT INTO `roleInherit` VALUES (2,1,3,NULL); +INSERT INTO `roleInherit` VALUES (3,1,70,NULL); +INSERT INTO `roleInherit` VALUES (4,2,11,NULL); +INSERT INTO `roleInherit` VALUES (5,3,11,NULL); +INSERT INTO `roleInherit` VALUES (6,5,1,NULL); +INSERT INTO `roleInherit` VALUES (8,5,33,NULL); +INSERT INTO `roleInherit` VALUES (10,11,6,NULL); +INSERT INTO `roleInherit` VALUES (11,13,1,NULL); +INSERT INTO `roleInherit` VALUES (12,15,35,NULL); +INSERT INTO `roleInherit` VALUES (16,17,20,NULL); +INSERT INTO `roleInherit` VALUES (17,17,37,NULL); +INSERT INTO `roleInherit` VALUES (18,17,39,NULL); +INSERT INTO `roleInherit` VALUES (19,17,64,NULL); +INSERT INTO `roleInherit` VALUES (20,18,1,NULL); +INSERT INTO `roleInherit` VALUES (21,19,21,NULL); +INSERT INTO `roleInherit` VALUES (22,20,13,NULL); +INSERT INTO `roleInherit` VALUES (23,20,16,NULL); +INSERT INTO `roleInherit` VALUES (24,20,65,NULL); +INSERT INTO `roleInherit` VALUES (25,21,13,NULL); +INSERT INTO `roleInherit` VALUES (26,21,18,NULL); +INSERT INTO `roleInherit` VALUES (27,21,53,NULL); +INSERT INTO `roleInherit` VALUES (28,22,13,NULL); +INSERT INTO `roleInherit` VALUES (29,22,21,NULL); +INSERT INTO `roleInherit` VALUES (30,30,5,NULL); +INSERT INTO `roleInherit` VALUES (31,30,20,NULL); +INSERT INTO `roleInherit` VALUES (32,30,22,NULL); +INSERT INTO `roleInherit` VALUES (33,30,53,NULL); +INSERT INTO `roleInherit` VALUES (34,30,64,NULL); +INSERT INTO `roleInherit` VALUES (35,31,1,NULL); +INSERT INTO `roleInherit` VALUES (36,32,1,NULL); +INSERT INTO `roleInherit` VALUES (37,34,1,NULL); +INSERT INTO `roleInherit` VALUES (38,34,13,NULL); +INSERT INTO `roleInherit` VALUES (39,34,33,NULL); +INSERT INTO `roleInherit` VALUES (40,35,1,NULL); +INSERT INTO `roleInherit` VALUES (41,36,44,NULL); +INSERT INTO `roleInherit` VALUES (42,36,47,NULL); +INSERT INTO `roleInherit` VALUES (43,37,1,NULL); +INSERT INTO `roleInherit` VALUES (44,38,37,NULL); +INSERT INTO `roleInherit` VALUES (45,38,64,NULL); +INSERT INTO `roleInherit` VALUES (46,39,5,NULL); +INSERT INTO `roleInherit` VALUES (47,39,21,NULL); +INSERT INTO `roleInherit` VALUES (48,39,57,NULL); +INSERT INTO `roleInherit` VALUES (49,40,1,NULL); +INSERT INTO `roleInherit` VALUES (50,40,49,NULL); +INSERT INTO `roleInherit` VALUES (51,41,13,NULL); +INSERT INTO `roleInherit` VALUES (52,41,35,NULL); +INSERT INTO `roleInherit` VALUES (53,41,40,NULL); +INSERT INTO `roleInherit` VALUES (54,42,35,NULL); +INSERT INTO `roleInherit` VALUES (55,42,49,NULL); +INSERT INTO `roleInherit` VALUES (56,43,13,NULL); +INSERT INTO `roleInherit` VALUES (57,43,42,NULL); +INSERT INTO `roleInherit` VALUES (58,44,1,NULL); +INSERT INTO `roleInherit` VALUES (59,45,13,NULL); +INSERT INTO `roleInherit` VALUES (60,45,44,NULL); +INSERT INTO `roleInherit` VALUES (61,47,1,NULL); +INSERT INTO `roleInherit` VALUES (62,48,13,NULL); +INSERT INTO `roleInherit` VALUES (63,48,47,NULL); +INSERT INTO `roleInherit` VALUES (64,49,36,NULL); +INSERT INTO `roleInherit` VALUES (65,49,58,NULL); +INSERT INTO `roleInherit` VALUES (66,50,13,NULL); +INSERT INTO `roleInherit` VALUES (67,50,21,NULL); +INSERT INTO `roleInherit` VALUES (70,50,57,NULL); +INSERT INTO `roleInherit` VALUES (72,51,1,NULL); +INSERT INTO `roleInherit` VALUES (73,52,13,NULL); +INSERT INTO `roleInherit` VALUES (74,52,19,NULL); +INSERT INTO `roleInherit` VALUES (76,52,51,NULL); +INSERT INTO `roleInherit` VALUES (77,53,1,NULL); +INSERT INTO `roleInherit` VALUES (78,54,1,NULL); +INSERT INTO `roleInherit` VALUES (79,55,13,NULL); +INSERT INTO `roleInherit` VALUES (80,55,54,NULL); +INSERT INTO `roleInherit` VALUES (81,56,1,NULL); +INSERT INTO `roleInherit` VALUES (84,58,1,NULL); +INSERT INTO `roleInherit` VALUES (85,59,13,NULL); +INSERT INTO `roleInherit` VALUES (87,60,5,NULL); +INSERT INTO `roleInherit` VALUES (91,61,13,NULL); +INSERT INTO `roleInherit` VALUES (92,61,36,NULL); +INSERT INTO `roleInherit` VALUES (94,65,35,NULL); +INSERT INTO `roleInherit` VALUES (97,67,5,NULL); +INSERT INTO `roleInherit` VALUES (98,67,37,NULL); +INSERT INTO `roleInherit` VALUES (99,69,35,NULL); +INSERT INTO `roleInherit` VALUES (101,70,11,NULL); +INSERT INTO `roleInherit` VALUES (102,71,1,NULL); +INSERT INTO `roleInherit` VALUES (103,71,58,NULL); +INSERT INTO `roleInherit` VALUES (105,72,18,NULL); +INSERT INTO `roleInherit` VALUES (106,73,5,NULL); +INSERT INTO `roleInherit` VALUES (107,73,64,NULL); +INSERT INTO `roleInherit` VALUES (108,73,19,NULL); +INSERT INTO `roleInherit` VALUES (109,59,50,NULL); +INSERT INTO `roleInherit` VALUES (115,39,76,NULL); +INSERT INTO `roleInherit` VALUES (117,65,76,NULL); +INSERT INTO `roleInherit` VALUES (118,30,76,NULL); +INSERT INTO `roleInherit` VALUES (124,5,76,NULL); +INSERT INTO `roleInherit` VALUES (125,37,76,NULL); +INSERT INTO `roleInherit` VALUES (126,38,76,NULL); +INSERT INTO `roleInherit` VALUES (128,42,76,NULL); +INSERT INTO `roleInherit` VALUES (129,35,76,NULL); +INSERT INTO `roleInherit` VALUES (130,60,76,NULL); +INSERT INTO `roleInherit` VALUES (131,21,76,NULL); +INSERT INTO `roleInherit` VALUES (132,18,76,NULL); +INSERT INTO `roleInherit` VALUES (133,50,76,NULL); +INSERT INTO `roleInherit` VALUES (134,20,76,NULL); +INSERT INTO `roleInherit` VALUES (135,41,76,NULL); +INSERT INTO `roleInherit` VALUES (136,17,76,NULL); +INSERT INTO `roleInherit` VALUES (137,52,76,NULL); +INSERT INTO `roleInherit` VALUES (139,37,74,NULL); +INSERT INTO `roleInherit` VALUES (140,51,74,NULL); +INSERT INTO `roleInherit` VALUES (141,51,75,NULL); +INSERT INTO `roleInherit` VALUES (142,35,75,NULL); +INSERT INTO `roleInherit` VALUES (143,15,49,NULL); +INSERT INTO `roleInherit` VALUES (145,17,67,NULL); +INSERT INTO `roleInherit` VALUES (146,38,13,NULL); +INSERT INTO `roleInherit` VALUES (147,101,35,NULL); +INSERT INTO `roleInherit` VALUES (148,101,13,NULL); +INSERT INTO `roleInherit` VALUES (150,15,56,NULL); +INSERT INTO `roleInherit` VALUES (152,69,47,NULL); +INSERT INTO `roleInherit` VALUES (153,48,35,NULL); +INSERT INTO `roleInherit` VALUES (154,102,1,NULL); +INSERT INTO `roleInherit` VALUES (167,9,103,NULL); +INSERT INTO `roleInherit` VALUES (168,66,9,NULL); +INSERT INTO `roleInherit` VALUES (169,104,100,NULL); +INSERT INTO `roleInherit` VALUES (172,103,76,NULL); +INSERT INTO `roleInherit` VALUES (173,103,1,NULL); +INSERT INTO `roleInherit` VALUES (174,103,44,NULL); +INSERT INTO `roleInherit` VALUES (175,103,45,NULL); +INSERT INTO `roleInherit` VALUES (176,103,11,NULL); +INSERT INTO `roleInherit` VALUES (177,103,39,NULL); +INSERT INTO `roleInherit` VALUES (178,103,17,NULL); +INSERT INTO `roleInherit` VALUES (179,103,5,NULL); +INSERT INTO `roleInherit` VALUES (180,103,67,NULL); +INSERT INTO `roleInherit` VALUES (181,103,3,NULL); +INSERT INTO `roleInherit` VALUES (182,103,34,NULL); +INSERT INTO `roleInherit` VALUES (183,103,42,NULL); +INSERT INTO `roleInherit` VALUES (184,103,43,NULL); +INSERT INTO `roleInherit` VALUES (185,103,64,NULL); +INSERT INTO `roleInherit` VALUES (186,103,35,NULL); +INSERT INTO `roleInherit` VALUES (187,103,101,NULL); +INSERT INTO `roleInherit` VALUES (188,103,75,NULL); +INSERT INTO `roleInherit` VALUES (189,103,71,NULL); +INSERT INTO `roleInherit` VALUES (190,103,72,NULL); +INSERT INTO `roleInherit` VALUES (191,103,47,NULL); +INSERT INTO `roleInherit` VALUES (192,103,69,NULL); +INSERT INTO `roleInherit` VALUES (193,103,48,NULL); +INSERT INTO `roleInherit` VALUES (194,103,2,NULL); +INSERT INTO `roleInherit` VALUES (195,103,56,NULL); +INSERT INTO `roleInherit` VALUES (196,103,57,NULL); +INSERT INTO `roleInherit` VALUES (197,103,32,NULL); +INSERT INTO `roleInherit` VALUES (198,103,73,NULL); +INSERT INTO `roleInherit` VALUES (199,103,30,NULL); +INSERT INTO `roleInherit` VALUES (200,103,31,NULL); +INSERT INTO `roleInherit` VALUES (201,103,6,NULL); +INSERT INTO `roleInherit` VALUES (202,103,40,NULL); +INSERT INTO `roleInherit` VALUES (203,103,41,NULL); +INSERT INTO `roleInherit` VALUES (204,103,37,NULL); +INSERT INTO `roleInherit` VALUES (205,103,38,NULL); +INSERT INTO `roleInherit` VALUES (206,103,53,NULL); +INSERT INTO `roleInherit` VALUES (207,103,33,NULL); +INSERT INTO `roleInherit` VALUES (210,103,54,NULL); +INSERT INTO `roleInherit` VALUES (211,103,55,NULL); +INSERT INTO `roleInherit` VALUES (212,103,15,NULL); +INSERT INTO `roleInherit` VALUES (213,103,16,NULL); +INSERT INTO `roleInherit` VALUES (215,103,51,NULL); +INSERT INTO `roleInherit` VALUES (216,103,52,NULL); +INSERT INTO `roleInherit` VALUES (218,103,65,NULL); +INSERT INTO `roleInherit` VALUES (219,103,58,NULL); +INSERT INTO `roleInherit` VALUES (220,103,59,NULL); +INSERT INTO `roleInherit` VALUES (221,103,102,NULL); +INSERT INTO `roleInherit` VALUES (222,103,49,NULL); +INSERT INTO `roleInherit` VALUES (223,103,60,NULL); +INSERT INTO `roleInherit` VALUES (224,103,50,NULL); +INSERT INTO `roleInherit` VALUES (225,103,36,NULL); +INSERT INTO `roleInherit` VALUES (226,103,61,NULL); +INSERT INTO `roleInherit` VALUES (228,103,21,NULL); +INSERT INTO `roleInherit` VALUES (229,103,19,NULL); +INSERT INTO `roleInherit` VALUES (230,103,18,NULL); +INSERT INTO `roleInherit` VALUES (231,103,13,NULL); +INSERT INTO `roleInherit` VALUES (232,103,22,NULL); +INSERT INTO `roleInherit` VALUES (233,103,70,NULL); +INSERT INTO `roleInherit` VALUES (234,103,74,NULL); +INSERT INTO `roleInherit` VALUES (237,66,103,NULL); +INSERT INTO `roleInherit` VALUES (238,103,20,NULL); +INSERT INTO `roleInherit` VALUES (239,106,11,NULL); +INSERT INTO `roleInherit` VALUES (240,107,60,NULL); +INSERT INTO `roleInherit` VALUES (241,21,72,NULL); +INSERT INTO `roleInherit` VALUES (242,20,9,NULL); +INSERT INTO `roleInherit` VALUES (246,102,35,NULL); +INSERT INTO `roleInherit` VALUES (247,108,1,NULL); +INSERT INTO `roleInherit` VALUES (248,102,13,NULL); +INSERT INTO `roleInherit` VALUES (249,109,18,NULL); +INSERT INTO `roleInherit` VALUES (250,109,13,NULL); +INSERT INTO `roleInherit` VALUES (251,51,21,NULL); +INSERT INTO `roleInherit` VALUES (253,48,49,NULL); +INSERT INTO `roleInherit` VALUES (254,110,1,NULL); +INSERT INTO `roleInherit` VALUES (255,110,76,NULL); +INSERT INTO `roleInherit` VALUES (256,48,69,NULL); +INSERT INTO `roleInherit` VALUES (257,47,111,NULL); +INSERT INTO `roleInherit` VALUES (258,43,111,NULL); +INSERT INTO `roleInherit` VALUES (259,72,111,NULL); +INSERT INTO `roleInherit` VALUES (260,35,111,NULL); +INSERT INTO `roleInherit` VALUES (261,5,111,NULL); +INSERT INTO `roleInherit` VALUES (262,112,1,NULL); +INSERT INTO `roleInherit` VALUES (263,114,112,NULL); +INSERT INTO `roleInherit` VALUES (264,51,35,NULL); +INSERT INTO `roleInherit` VALUES (265,72,49,NULL); +INSERT INTO `roleInherit` VALUES (266,101,18,NULL); +INSERT INTO `roleInherit` VALUES (268,65,57,NULL); +INSERT INTO `roleInherit` VALUES (269,65,59,NULL); +INSERT INTO `roleInherit` VALUES (270,65,49,NULL); +INSERT INTO `roleInherit` VALUES (271,65,18,NULL); +INSERT INTO `roleInherit` VALUES (272,65,13,NULL); +INSERT INTO `roleInherit` VALUES (273,60,35,NULL); +INSERT INTO `roleInherit` VALUES (275,50,59,NULL); +INSERT INTO `roleInherit` VALUES (276,60,49,NULL); +INSERT INTO `roleInherit` VALUES (280,5,53,NULL); +INSERT INTO `roleInherit` VALUES (281,5,18,NULL); +INSERT INTO `roleInherit` VALUES (282,50,60,NULL); +INSERT INTO `roleInherit` VALUES (283,5,21,NULL); +INSERT INTO `roleInherit` VALUES (285,58,76,NULL); +INSERT INTO `roleInherit` VALUES (287,69,58,NULL); +INSERT INTO `roleInherit` VALUES (288,115,66,NULL); +INSERT INTO `roleInherit` VALUES (290,104,115,NULL); +INSERT INTO `roleInherit` VALUES (291,115,103,NULL); +INSERT INTO `roleInherit` VALUES (297,21,33,NULL); +INSERT INTO `roleInherit` VALUES (298,49,54,NULL); +INSERT INTO `roleInherit` VALUES (299,112,49,NULL); +INSERT INTO `roleInherit` VALUES (300,114,13,NULL); +INSERT INTO `roleInherit` VALUES (302,5,35,NULL); +INSERT INTO `roleInherit` VALUES (303,69,49,NULL); +INSERT INTO `roleInherit` VALUES (306,119,110,NULL); +INSERT INTO `roleInherit` VALUES (307,1,76,NULL); +INSERT INTO `roleInherit` VALUES (309,120,9,NULL); +INSERT INTO `roleInherit` VALUES (310,120,66,NULL); +INSERT INTO `roleInherit` VALUES (311,120,13,25508); +INSERT INTO `roleInherit` VALUES (312,115,120,NULL); +INSERT INTO `roleInherit` VALUES (314,43,18,NULL); +INSERT INTO `roleInherit` VALUES (315,121,35,NULL); +INSERT INTO `roleInherit` VALUES (316,121,21,NULL); +INSERT INTO `roleInherit` VALUES (317,122,15,NULL); +INSERT INTO `roleInherit` VALUES (318,16,122,NULL); +INSERT INTO `roleInherit` VALUES (319,37,49,NULL); +INSERT INTO `roleInherit` VALUES (320,37,18,NULL); +INSERT INTO `roleInherit` VALUES (328,57,123,10578); +INSERT INTO `roleInherit` VALUES (329,123,33,NULL); +INSERT INTO `roleInherit` VALUES (330,123,56,NULL); +INSERT INTO `roleInherit` VALUES (332,103,112,NULL); +INSERT INTO `roleInherit` VALUES (333,57,13,NULL); +INSERT INTO `roleInherit` VALUES (334,60,123,NULL); +INSERT INTO `roleInherit` VALUES (335,124,37,NULL); +INSERT INTO `roleInherit` VALUES (336,124,35,NULL); +INSERT INTO `roleInherit` VALUES (337,103,124,NULL); +INSERT INTO `roleInherit` VALUES (338,35,125,10578); +INSERT INTO `roleInherit` VALUES (339,57,125,10578); +INSERT INTO `roleInherit` VALUES (340,41,125,10578); +INSERT INTO `roleInherit` VALUES (341,18,125,10578); +INSERT INTO `roleInherit` VALUES (346,126,15,NULL); +INSERT INTO `roleInherit` VALUES (347,102,49,NULL); +INSERT INTO `roleInherit` VALUES (350,49,75,NULL); +INSERT INTO `roleInherit` VALUES (351,72,35,NULL); +INSERT INTO `roleInherit` VALUES (353,110,49,NULL); +INSERT INTO `roleInherit` VALUES (354,103,119,NULL); + +INSERT INTO `userPassword` VALUES (1,7,1,0,2,1); + +INSERT INTO `accountConfig` VALUES (1,'/mnt/homes','/bin/bash',10000,5,60,5,30); + +INSERT INTO `mailConfig` VALUES (1,'verdnatura.es'); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `salix`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `ACL` VALUES (3,'Address','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (5,'AgencyService','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (9,'ClientObservation','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (13,'Employee','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (14,'PayMethod','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (16,'FakeProduction','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (20,'TicketState','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (24,'Delivery','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (25,'Zone','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (26,'ClientCredit','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (27,'ClientCreditLimit','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (30,'GreugeType','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (31,'Mandate','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (32,'MandateType','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (33,'Company','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (34,'Greuge','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (35,'AddressObservation','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (36,'ObservationType','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (37,'Greuge','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (38,'AgencyMode','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'); +INSERT INTO `ACL` VALUES (44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'); +INSERT INTO `ACL` VALUES (51,'ItemTag','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (53,'Item','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (54,'Item','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (55,'Recovery','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (58,'CreditClassification','*','*','ALLOW','ROLE','insurance'); +INSERT INTO `ACL` VALUES (60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'); +INSERT INTO `ACL` VALUES (61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (63,'TicketObservation','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (65,'Sale','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (66,'TicketTracking','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (68,'TicketPackaging','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (69,'Packaging','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'); +INSERT INTO `ACL` VALUES (72,'SaleComponent','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (73,'Expedition','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (75,'Expedition','*','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (77,'WorkerMana','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (79,'Ticket','state','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (80,'Sale','deleteSales','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (83,'Sale','updatePrice','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (85,'SaleTracking','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (86,'Order','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (87,'OrderRow','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (88,'ClientContact','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (90,'Sale','reserve','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (91,'TicketWeekly','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (102,'Claim','createFromSales','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'); +INSERT INTO `ACL` VALUES (105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'); +INSERT INTO `ACL` VALUES (106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'); +INSERT INTO `ACL` VALUES (108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'); +INSERT INTO `ACL` VALUES (109,'UserConfig','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (110,'Bank','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (111,'ClientLog','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (112,'Defaulter','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (114,'Receipt','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (116,'BankEntity','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (117,'ClientSample','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (119,'Travel','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (120,'Travel','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (121,'Item','regularize','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (122,'TicketRequest','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (127,'TicketLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (129,'TicketService','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (130,'Expedition','*','WRITE','ALLOW','ROLE','packager'); +INSERT INTO `ACL` VALUES (131,'CreditInsurance','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'); +INSERT INTO `ACL` VALUES (135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (141,'Zone','*','*','ALLOW','ROLE','logisticBoss'); +INSERT INTO `ACL` VALUES (142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (144,'Stowaway','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (147,'UserConfigView','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (148,'UserConfigView','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (149,'Sip','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (150,'Sip','*','WRITE','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (151,'Department','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (152,'Department','*','WRITE','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (154,'Route','*','WRITE','ALLOW','ROLE','delivery'); +INSERT INTO `ACL` VALUES (155,'Calendar','*','READ','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (157,'Calendar','absences','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'); +INSERT INTO `ACL` VALUES (160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (161,'TicketConfig','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (165,'TicketDms','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (172,'Sms','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (173,'Sms','send','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (176,'Device','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (177,'Device','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (179,'ItemLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (180,'RouteLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (186,'ClientDms','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (191,'Agency','getLanded','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (192,'Agency','getShipped','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (197,'Dms','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (199,'ClaimDms','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (203,'UserPhone','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (205,'WorkerDms','*','READ','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (206,'Chat','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (207,'Chat','sendMessage','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (211,'TravelLog','*','READ','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (212,'Thermograph','*','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (214,'Entry','*','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (218,'Intrastat','*','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (227,'Address','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (231,'ClientContact','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (232,'ClientSample','*','READ','ALLOW','ROLE','trainee'); +INSERT INTO `ACL` VALUES (233,'EntryLog','*','READ','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (234,'WorkerLog','find','READ','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (235,'CustomsAgent','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (236,'Buy','*','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (237,'WorkerDms','filter','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (238,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (239,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (248,'RoleMapping','*','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (249,'UserPassword','*','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (250,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (251,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (252,'Supplier','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (254,'SupplierLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (256,'Image','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (257,'FixedPrice','*','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (258,'PayDem','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (262,'Entry','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (264,'StarredModule','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'); +INSERT INTO `ACL` VALUES (266,'ZoneLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'); +INSERT INTO `ACL` VALUES (268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'); +INSERT INTO `ACL` VALUES (269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (270,'SupplierAddress','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (271,'SalesMonitor','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (272,'InvoiceInLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'); +INSERT INTO `ACL` VALUES (279,'MailAlias','*','*','ALLOW','ROLE','marketing'); +INSERT INTO `ACL` VALUES (283,'EntryObservation','*','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'); +INSERT INTO `ACL` VALUES (285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'); +INSERT INTO `ACL` VALUES (286,'ACL','*','*','ALLOW','ROLE','developer'); +INSERT INTO `ACL` VALUES (287,'AccessToken','*','*','ALLOW','ROLE','developer'); +INSERT INTO `ACL` VALUES (293,'RoleInherit','*','*','ALLOW','ROLE','it'); +INSERT INTO `ACL` VALUES (294,'RoleRole','*','*','ALLOW','ROLE','it'); +INSERT INTO `ACL` VALUES (295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'); +INSERT INTO `ACL` VALUES (296,'Collection','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (297,'Sale','refund','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (305,'EducationLevel','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (308,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (309,'Zone','getZoneClosing','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (310,'ExpeditionState','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (311,'Expense','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (312,'Expense','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (314,'SupplierActivity','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (315,'SupplierActivity','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (316,'Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (317,'ClientUnpaid','*','*','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (318,'MdbVersion','*','*','ALLOW','ROLE','developer'); +INSERT INTO `ACL` VALUES (319,'ItemType','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (320,'ItemType','*','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (321,'InvoiceOut','refund','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (322,'InvoiceOut','refund','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (323,'InvoiceOut','refund','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (324,'Ticket','refund','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (325,'Ticket','refund','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (326,'Ticket','refund','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (327,'Sale','refund','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (328,'Sale','refund','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (329,'TicketRefund','*','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (330,'ClaimObservation','*','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (331,'ClaimObservation','*','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (332,'Client','setPassword','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (333,'Client','updateUser','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (334,'ShelvingLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (335,'ZoneExclusionGeo','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (336,'ZoneExclusionGeo','*','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (337,'Parking','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (338,'Shelving','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (339,'OsTicket','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (340,'OsTicketConfig','*','*','ALLOW','ROLE','it'); +INSERT INTO `ACL` VALUES (341,'ClientConsumptionQueue','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (342,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (343,'Ticket','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (344,'Ticket','deliveryNoteCsvPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (345,'Ticket','deliveryNoteCsvEmail','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (346,'Client','campaignMetricsPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (347,'Client','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (348,'Client','clientWelcomeHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (349,'Client','clientWelcomeEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (350,'Client','creditRequestPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (351,'Client','creditRequestHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (352,'Client','creditRequestEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (353,'Client','printerSetupHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (354,'Client','printerSetupEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (355,'Client','sepaCoreEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (356,'Client','letterDebtorPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (357,'Client','letterDebtorStHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (358,'Client','letterDebtorStEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (359,'Client','letterDebtorNdHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (360,'Client','letterDebtorNdEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (361,'Client','clientDebtStatementPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (362,'Client','clientDebtStatementHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (363,'Client','clientDebtStatementEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (364,'Client','incotermsAuthorizationPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (365,'Client','incotermsAuthorizationHtml','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (366,'Client','incotermsAuthorizationEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (367,'Client','consumptionSendQueued','WRITE','ALLOW','ROLE','system'); +INSERT INTO `ACL` VALUES (368,'InvoiceOut','invoiceEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (369,'InvoiceOut','exportationPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (370,'InvoiceOut','sendQueued','WRITE','ALLOW','ROLE','system'); +INSERT INTO `ACL` VALUES (371,'Ticket','invoiceCsvPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (372,'Ticket','invoiceCsvEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (373,'Supplier','campaignMetricsPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (374,'Supplier','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (375,'Travel','extraCommunityPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (376,'Travel','extraCommunityEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (377,'Entry','entryOrderPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (378,'OsTicket','osTicketReportEmail','WRITE','ALLOW','ROLE','system'); +INSERT INTO `ACL` VALUES (379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system'); +INSERT INTO `ACL` VALUES (380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (382,'Item','labelPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (383,'Sector','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (384,'Sector','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (386,'Route','driverRouteEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','customer'); +INSERT INTO `ACL` VALUES (388,'Supplier','newSupplier','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (389,'ClaimRma','*','READ','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (390,'ClaimRma','*','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (391,'Notification','*','WRITE','ALLOW','ROLE','system'); +INSERT INTO `ACL` VALUES (392,'Boxing','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (393,'Url','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (394,'Url','*','WRITE','ALLOW','ROLE','it'); +INSERT INTO `ACL` VALUES (395,'ItemShelving','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (396,'ItemShelving','*','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (397,'ItemShelvingPlacementSupplyStock','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (398,'NotificationQueue','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (399,'InvoiceOut','clientsToInvoice','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (400,'InvoiceOut','invoiceClient','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (401,'Sale','editTracked','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (402,'Sale','editFloramondo','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (403,'Receipt','balanceCompensationEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (404,'Receipt','balanceCompensationPdf','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (405,'Ticket','getTicketsFuture','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (406,'Ticket','merge','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (407,'Sale','editFloramondo','WRITE','ALLOW','ROLE','logistic'); +INSERT INTO `ACL` VALUES (408,'ZipConfig','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (409,'Item','*','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (410,'Sale','editCloned','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (411,'Sale','editCloned','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (414,'MdbVersion','*','READ','ALLOW','ROLE','$everyone'); +INSERT INTO `ACL` VALUES (416,'TicketLog','getChanges','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (417,'Ticket','getTicketsAdvance','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (418,'EntryLog','*','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (419,'Sale','editTracked','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (420,'MdbBranch','*','READ','ALLOW','ROLE','$everyone'); +INSERT INTO `ACL` VALUES (421,'ItemShelvingSale','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (422,'Docuware','checkFile','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (423,'Docuware','download','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (424,'Docuware','upload','WRITE','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (425,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (426,'TpvTransaction','confirm','WRITE','ALLOW','ROLE','$everyone'); +INSERT INTO `ACL` VALUES (427,'TpvTransaction','start','WRITE','ALLOW','ROLE','$authenticated'); +INSERT INTO `ACL` VALUES (428,'TpvTransaction','end','WRITE','ALLOW','ROLE','$authenticated'); +INSERT INTO `ACL` VALUES (429,'ItemConfig','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (431,'Tag','onSubmit','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (432,'Worker','updateAttributes','WRITE','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (433,'Worker','createAbsence','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (434,'Worker','updateAbsence','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (435,'Worker','deleteAbsence','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (436,'Worker','new','WRITE','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (438,'Client','getClientOrSupplierReference','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (439,'NotificationSubscription','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (440,'NotificationAcl','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (441,'MdbApp','*','READ','ALLOW','ROLE','$everyone'); +INSERT INTO `ACL` VALUES (442,'MdbApp','*','*','ALLOW','ROLE','developer'); +INSERT INTO `ACL` VALUES (443,'ItemConfig','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (444,'DeviceProduction','*','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (445,'DeviceProductionModels','*','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (446,'DeviceProductionState','*','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (447,'DeviceProductionUser','*','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (448,'DeviceProduction','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (449,'DeviceProductionModels','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (450,'DeviceProductionState','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (451,'DeviceProductionUser','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (452,'Worker','deallocatePDA','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (453,'Worker','allocatePDA','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (454,'Worker','deallocatePDA','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (455,'Worker','allocatePDA','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (456,'Zone','*','*','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (458,'Operator','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (459,'Operator','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (460,'InvoiceIn','getSerial','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (461,'Ticket','saveSign','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (462,'InvoiceOut','negativeBases','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (463,'InvoiceOut','negativeBasesCsv','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (464,'WorkerObservation','*','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (465,'ClientInforma','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (466,'ClientInforma','*','WRITE','ALLOW','ROLE','financial'); +INSERT INTO `ACL` VALUES (467,'Receipt','receiptEmail','*','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (468,'Client','setRating','WRITE','ALLOW','ROLE','financial'); +INSERT INTO `ACL` VALUES (470,'Client','addressesPropagateRe','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (471,'Client','canBeInvoiced','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (472,'Client','canCreateTicket','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (473,'Client','consumption','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (474,'Client','createAddress','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (475,'Client','createWithUser','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (476,'Client','extendedListFilter','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (477,'Client','getAverageInvoiced','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (478,'Client','getCard','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (479,'Client','getDebt','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (480,'Client','getMana','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (481,'Client','transactions','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (482,'Client','hasCustomerRole','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (483,'Client','isValidClient','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (484,'Client','lastActiveTickets','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (485,'Client','sendSms','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (486,'Client','setPassword','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (487,'Client','summary','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (488,'Client','updateAddress','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (489,'Client','updateFiscalData','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (491,'Client','uploadFile','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (492,'Client','campaignMetricsPdf','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (493,'Client','campaignMetricsEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (494,'Client','clientWelcomeHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (495,'Client','clientWelcomeEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (496,'Client','printerSetupHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (497,'Client','printerSetupEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (498,'Client','sepaCoreEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (499,'Client','letterDebtorPdf','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (500,'Client','letterDebtorStHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (501,'Client','letterDebtorStEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (502,'Client','letterDebtorNdHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (503,'Client','letterDebtorNdEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (504,'Client','clientDebtStatementPdf','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (505,'Client','clientDebtStatementHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (506,'Client','clientDebtStatementEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (507,'Client','creditRequestPdf','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (508,'Client','creditRequestHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (509,'Client','creditRequestEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (510,'Client','incotermsAuthorizationPdf','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (511,'Client','incotermsAuthorizationHtml','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (512,'Client','incotermsAuthorizationEmail','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (513,'Client','consumptionSendQueued','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (514,'Client','filter','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (515,'Client','getClientOrSupplierReference','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (516,'Client','upsert','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (518,'Client','replaceById','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (519,'Client','updateAttributes','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (520,'Client','updateAttributes','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (521,'Client','deleteById','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (522,'Client','replaceOrCreate','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (523,'Client','updateAll','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (524,'Client','upsertWithWhere','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (525,'Defaulter','observationEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (527,'VnUser','acl','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (528,'VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (530,'Account','exists','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (531,'Account','exists','READ','ALLOW','ROLE','account'); +INSERT INTO `ACL` VALUES (532,'UserLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (533,'RoleLog','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (534,'WagonType','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (535,'WagonTypeColor','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (536,'WagonTypeTray','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (537,'WagonConfig','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (538,'CollectionWagon','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (539,'CollectionWagonTicket','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (540,'Wagon','*','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (541,'WagonType','createWagonType','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (542,'WagonType','deleteWagonType','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (543,'WagonType','editWagonType','*','ALLOW','ROLE','productionAssi'); +INSERT INTO `ACL` VALUES (544,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (545,'Agency','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (546,'Agency','seeExpired','READ','ALLOW','ROLE','coolerAssist'); +INSERT INTO `ACL` VALUES (547,'WorkerLog','models','READ','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (548,'Ticket','editDiscount','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (549,'Ticket','editDiscount','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (550,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (551,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (552,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (553,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (554,'Ticket','deleteTicketWithPartPrepared','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (555,'Ticket','editZone','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (556,'State','editableStates','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (557,'State','seeEditableStates','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (558,'State','seeEditableStates','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (559,'State','isSomeEditable','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (560,'State','isAllEditable','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (561,'State','isAllEditable','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (562,'Agency','seeExpired','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (563,'Agency','seeExpired','READ','ALLOW','ROLE','productionBoss'); +INSERT INTO `ACL` VALUES (564,'Claim','createAfterDeadline','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (565,'Client','editAddressLogifloraAllowed','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (566,'Client','editFiscalDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (567,'Client','editVerifiedDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'); +INSERT INTO `ACL` VALUES (568,'Client','editCredit','WRITE','ALLOW','ROLE','financialBoss'); +INSERT INTO `ACL` VALUES (569,'Client','zeroCreditEditor','WRITE','ALLOW','ROLE','financialBoss'); +INSERT INTO `ACL` VALUES (570,'InvoiceOut','canCreatePdf','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (571,'Supplier','editPayMethodCheck','WRITE','ALLOW','ROLE','financial'); +INSERT INTO `ACL` VALUES (572,'Worker','isTeamBoss','WRITE','ALLOW','ROLE','teamBoss'); +INSERT INTO `ACL` VALUES (573,'Worker','forceIsSubordinate','READ','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (574,'Claim','editState','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (577,'Claim','findOne','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (579,'Claim','updateClaim','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (580,'Claim','regularizeClaim','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (581,'Claim','updateClaimDestination','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (582,'Claim','downloadFile','READ','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (583,'Claim','deleteById','WRITE','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (585,'Claim','logs','READ','ALLOW','ROLE','claimManager'); +INSERT INTO `ACL` VALUES (586,'Ticket','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (587,'Ticket','findById','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (588,'Ticket','findOne','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (589,'Ticket','getVolume','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (590,'Ticket','getTotalVolume','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (591,'Ticket','summary','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (592,'Ticket','priceDifference','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (593,'Ticket','componentUpdate','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (594,'Ticket','new','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (595,'Ticket','isEditable','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (596,'Ticket','setDeleted','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (597,'Ticket','restore','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (598,'Ticket','getSales','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (599,'Ticket','getSalesPersonMana','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (600,'Ticket','filter','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (601,'Ticket','makeInvoice','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (602,'Ticket','updateEditableTicket','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (603,'Ticket','updateDiscount','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (604,'Ticket','transferSales','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (605,'Ticket','sendSms','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (606,'Ticket','isLocked','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (607,'Ticket','freightCost','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (608,'Ticket','getComponentsSum','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (609,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','delivery'); +INSERT INTO `ACL` VALUES (610,'Ticket','deliveryNoteCsv','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (611,'State','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (612,'State','findById','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (613,'State','findOne','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (614,'Worker','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (615,'Worker','findById','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (616,'Worker','findOne','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (617,'Worker','filter','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (618,'Worker','getWorkedHours','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (619,'Worker','active','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (620,'Worker','activeWithRole','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (621,'Worker','uploadFile','WRITE','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (622,'Worker','contracts','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (623,'Worker','holidays','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (624,'Worker','activeContract','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (625,'Worker','activeWithInheritedRole','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (626,'Ticket','collectionLabel','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (628,'Ticket','expeditionPalletLabel','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (629,'Ticket','editDiscount','WRITE','ALLOW','ROLE','artificialBoss'); +INSERT INTO `ACL` VALUES (630,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesTeamBoss'); +INSERT INTO `ACL` VALUES (635,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (636,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (637,'Claim','downloadFile','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (638,'Agency','seeExpired','READ','ALLOW','ROLE','artificialBoss'); +INSERT INTO `ACL` VALUES (639,'Agency','seeExpired','READ','ALLOW','ROLE','logisticAssistant'); +INSERT INTO `ACL` VALUES (654,'Ticket','editZone','WRITE','ALLOW','ROLE','logisticAssistant'); +INSERT INTO `ACL` VALUES (655,'Entry','addFromPackaging','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (656,'Entry','addFromBuy','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (657,'Supplier','getItemsPackaging','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (658,'Ticket','closeAll','WRITE','ALLOW','ROLE','system'); +INSERT INTO `ACL` VALUES (659,'Account','*','*','ALLOW','ROLE','developerBoss'); +INSERT INTO `ACL` VALUES (664,'MailForward','*','*','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (665,'Role','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (666,'Role','*','WRITE','ALLOW','ROLE','it'); +INSERT INTO `ACL` VALUES (667,'VnUser','*','*','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (668,'VnUser','__get__preview','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (669,'VnUser','preview','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (670,'VnUser','create','*','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (671,'VnUser','renewToken','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (672,'PackingSiteAdvanced','*','*','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (673,'InvoiceOut','makePdfAndNotify','WRITE','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (674,'InvoiceOutConfig','*','READ','ALLOW','ROLE','invoicing'); +INSERT INTO `ACL` VALUES (676,'Ticket','invoiceTickets','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (680,'MailAliasAccount','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (681,'MailAliasAccount','create','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (682,'MailAliasAccount','deleteById','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (683,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (684,'WorkerDisableExcluded','*','READ','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (685,'WorkerDisableExcluded','*','WRITE','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (686,'MailForward','*','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (687,'ClientSms','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (688,'ClientSms','create','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'); +INSERT INTO `ACL` VALUES (691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'); +INSERT INTO `ACL` VALUES (692,'ExpeditionTruck','*','*','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (693,'ExpeditionTruck','*','*','ALLOW','ROLE','productionBoss'); +INSERT INTO `ACL` VALUES (694,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','marketingBoss'); +INSERT INTO `ACL` VALUES (695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (698,'Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (699,'TicketSms','find','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (701,'Docuware','upload','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (702,'Ticket','docuwareDownload','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (703,'Worker','search','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (704,'ExpeditionState','addExpeditionState','WRITE','ALLOW','ROLE','delivery'); +INSERT INTO `ACL` VALUES (705,'SaleGroupDetail','deleteById','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (706,'Ticket','setDeleted','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (707,'DeviceLog','create','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (708,'Collection','getTickets','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (709,'Client','findOne','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (710,'Client','findById','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (711,'Client','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (712,'Client','exists','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (713,'Client','__get__addresses','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (714,'ExpeditionMistakeType','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (715,'WorkerMistakeType','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (716,'ExpeditionMistake','*','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (717,'WorkerMistake','*','WRITE','ALLOW','ROLE','coolerBoss'); +INSERT INTO `ACL` VALUES (718,'MistakesTypes','*','WRITE','ALLOW','ROLE','coolerBoss'); +INSERT INTO `ACL` VALUES (719,'MistakeType','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (720,'MachineWorker','*','READ','ALLOW','ROLE','coolerAssist'); +INSERT INTO `ACL` VALUES (721,'Printer','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (722,'SaleMistake','*','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (723,'Item','setVisibleDiscard','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (724,'Address','getAddress','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (725,'Account','findOne','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (726,'Account','findById','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (727,'Account','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (728,'Account','exists','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (729,'Sale','refund','WRITE','ALLOW','ROLE','buyer'); +INSERT INTO `ACL` VALUES (730,'Ticket','setDeleted','WRITE','ALLOW','ROLE','deliveryAssistant'); +INSERT INTO `ACL` VALUES (732,'Sale','isInPreparing','*','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (733,'Train','*','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (734,'WorkerDepartment','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (735,'VnUser','higherPrivileges','*','ALLOW','ROLE','itManagement'); +INSERT INTO `ACL` VALUES (736,'VnUser','mediumPrivileges','*','ALLOW','ROLE','hr'); +INSERT INTO `ACL` VALUES (737,'VnUser','updateUser','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (738,'TicketCollection','*','WRITE','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (739,'Worker','setPassword','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (740,'Url','getByUser','READ','ALLOW','ROLE','$everyone'); +INSERT INTO `ACL` VALUES (741,'Claim','__get__lines','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `ACL` VALUES (742,'AddressShortage','*','READ','ALLOW','ROLE','production'); +INSERT INTO `ACL` VALUES (743,'Claim','filter','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `ACL` VALUES (744,'Claim','find','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `ACL` VALUES (745,'Claim','findById','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `ACL` VALUES (746,'Claim','getSummary','READ','ALLOW','ROLE','claimViewer'); +INSERT INTO `ACL` VALUES (747,'CplusRectificationType','*','READ','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (748,'SiiTypeInvoiceOut','*','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (749,'InvoiceCorrectionType','*','READ','ALLOW','ROLE','salesPerson'); +INSERT INTO `ACL` VALUES (750,'InvoiceOut','transferInvoice','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (751,'Application','executeProc','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (752,'Application','executeFunc','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (753,'NotificationSubscription','getList','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (754,'Route','find','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (755,'Route','findById','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (756,'Route','findOne','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (757,'Route','getRoutesByWorker','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (758,'Route','canViewAllRoute','READ','ALLOW','ROLE','deliveryBoss'); +INSERT INTO `ACL` VALUES (759,'Route','cmr','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (760,'Route','downloadCmrsZip','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (761,'Route','downloadZip','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (762,'Route','filter','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (763,'Route','getByWorker','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (764,'Route','getDeliveryPoint','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (765,'Route','getExternalCmrs','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (766,'Route','getSuggestedTickets','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (767,'Route','getTickets','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (768,'Route','guessPriority','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (769,'Route','insertTicket','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (770,'Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryBoss'); +INSERT INTO `ACL` VALUES (771,'Route','summary','READ','ALLOW','ROLE','employee'); + +INSERT INTO `fieldAcl` VALUES (1,'Client','name','update','employee'); +INSERT INTO `fieldAcl` VALUES (2,'Client','contact','update','employee'); +INSERT INTO `fieldAcl` VALUES (3,'Client','email','update','employee'); +INSERT INTO `fieldAcl` VALUES (4,'Client','phone','update','employee'); +INSERT INTO `fieldAcl` VALUES (5,'Client','mobile','update','employee'); +INSERT INTO `fieldAcl` VALUES (6,'Client','contactChannelFk','update','employee'); +INSERT INTO `fieldAcl` VALUES (7,'Client','socialName','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (8,'Client','fi','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (9,'Client','street','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (10,'Client','postcode','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (11,'Client','city','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (12,'Client','countryFk','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (13,'Client','provinceFk','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (14,'Client','isActive','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (15,'Client','salesPersonFk','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (16,'Client','hasToInvoice','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (17,'Client','isToBeMailed','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (18,'Client','isEqualizated','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (19,'Client','isFreezed','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (20,'Client','isVies','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (21,'Client','hasToInvoiceByAddress','update','salesPerson'); +INSERT INTO `fieldAcl` VALUES (22,'Client','isTaxDataChecked','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (23,'Client','payMethodFk','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (24,'Client','dueDay','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (25,'Client','iban','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (26,'Client','bankEntityFk','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (27,'Client','hasLcr','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (28,'Client','hasCoreVnl','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (29,'Client','hasSepaVnl','update','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (30,'Client','credit','update','teamBoss'); +INSERT INTO `fieldAcl` VALUES (31,'BankEntity','*','insert','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (32,'Address','isDefaultAddress','*','employee'); +INSERT INTO `fieldAcl` VALUES (33,'Address','nickname','*','employee'); +INSERT INTO `fieldAcl` VALUES (34,'Address','postalCode','*','employee'); +INSERT INTO `fieldAcl` VALUES (35,'Address','provinceFk','*','employee'); +INSERT INTO `fieldAcl` VALUES (36,'Address','agencyModeFk','*','employee'); +INSERT INTO `fieldAcl` VALUES (37,'Address','phone','*','employee'); +INSERT INTO `fieldAcl` VALUES (38,'Address','mobile','*','employee'); +INSERT INTO `fieldAcl` VALUES (39,'Address','street','*','employee'); +INSERT INTO `fieldAcl` VALUES (40,'Address','city','*','employee'); +INSERT INTO `fieldAcl` VALUES (41,'Address','isActive','*','employee'); +INSERT INTO `fieldAcl` VALUES (42,'Address','isEqualizated','*','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (43,'Address','clientFk','insert','employee'); +INSERT INTO `fieldAcl` VALUES (44,'ClientObservation','*','insert','employee'); +INSERT INTO `fieldAcl` VALUES (45,'Recovery','*','insert','administrative'); +INSERT INTO `fieldAcl` VALUES (46,'Recovery','finished','update','administrative'); +INSERT INTO `fieldAcl` VALUES (47,'CreditClassification','finished','update','creditInsurance'); +INSERT INTO `fieldAcl` VALUES (48,'Account','*','update','employee'); +INSERT INTO `fieldAcl` VALUES (49,'Greuge','*','insert','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (50,'ClientSample','*','insert','employee'); +INSERT INTO `fieldAcl` VALUES (51,'Item','*','*','buyer'); +INSERT INTO `fieldAcl` VALUES (52,'Item','*','*','marketingBoss'); +INSERT INTO `fieldAcl` VALUES (53,'ItemBotanical','*','*','buyer'); +INSERT INTO `fieldAcl` VALUES (54,'ClaimEnd','*','*','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (55,'Receipt','*','*','administrative'); +INSERT INTO `fieldAcl` VALUES (56,'ClaimBeginning','*','*','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (57,'TicketRequest','*','*','salesPerson'); +INSERT INTO `fieldAcl` VALUES (58,'ClaimBeginning','*','*','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (59,'TicketRequest','*','*','salesPerson'); +INSERT INTO `fieldAcl` VALUES (60,'ClaimBeginning','*','*','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (61,'TicketRequest','*','*','salesPerson'); +INSERT INTO `fieldAcl` VALUES (62,'ClaimBeginning','*','*','salesAssistant'); +INSERT INTO `fieldAcl` VALUES (63,'TicketRequest','*','*','salesPerson'); +INSERT INTO `fieldAcl` VALUES (64,'ClaimBeginning','*','*','salesAssistant'); + +INSERT INTO `module` VALUES ('account'); +INSERT INTO `module` VALUES ('claim'); +INSERT INTO `module` VALUES ('customer'); +INSERT INTO `module` VALUES ('entry'); +INSERT INTO `module` VALUES ('invoiceIn'); +INSERT INTO `module` VALUES ('invoiceOut'); +INSERT INTO `module` VALUES ('item'); +INSERT INTO `module` VALUES ('monitor'); +INSERT INTO `module` VALUES ('order'); +INSERT INTO `module` VALUES ('route'); +INSERT INTO `module` VALUES ('shelving'); +INSERT INTO `module` VALUES ('supplier'); +INSERT INTO `module` VALUES ('ticket'); +INSERT INTO `module` VALUES ('travel'); +INSERT INTO `module` VALUES ('wagon'); +INSERT INTO `module` VALUES ('worker'); +INSERT INTO `module` VALUES ('zone'); + +INSERT INTO `defaultViewConfig` VALUES ('itemsIndex','{\"intrastat\":false,\"stemMultiplier\":false,\"landed\":false,\"producer\":false}'); +INSERT INTO `defaultViewConfig` VALUES ('latestBuys','{\"intrastat\":false,\"description\":false,\"density\":false,\"isActive\":false,\n \"freightValue\":false,\"packageValue\":false,\"isIgnored\":false,\"price2\":false,\"ektFk\":false,\"weight\":false,\n \"size\":false,\"comissionValue\":false,\"landing\":false}'); +INSERT INTO `defaultViewConfig` VALUES ('ticketsMonitor','{\"id\":false}'); +INSERT INTO `defaultViewConfig` VALUES ('clientsDetail','{\"id\":true,\"phone\":true,\"city\":true,\"socialName\":true,\"salesPersonFk\":true,\"email\":true,\"name\":false,\"fi\":false,\"credit\":false,\"creditInsurance\":false,\"mobile\":false,\"street\":false,\"countryFk\":false,\"provinceFk\":false,\"postcode\":false,\"created\":false,\"businessTypeFk\":false,\"payMethodFk\":false,\"sageTaxTypeFk\":false,\"sageTransactionTypeFk\":false,\"isActive\":false,\"isVies\":false,\"isTaxDataChecked\":false,\"isEqualizated\":false,\"isFreezed\":false,\"hasToInvoice\":false,\"hasToInvoiceByAddress\":false,\"isToBeMailed\":false,\"hasLcr\":false,\"hasCoreVnl\":false,\"hasSepaVnl\":false}'); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `vn`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios'); + +INSERT INTO `alertLevel` VALUES ('FREE',0,1); +INSERT INTO `alertLevel` VALUES ('ON_PREPARATION',1,1); +INSERT INTO `alertLevel` VALUES ('PACKED',2,0); +INSERT INTO `alertLevel` VALUES ('DELIVERED',3,0); + +INSERT INTO `bookingPlanner` VALUES (5,'2017-07-01 00:00:00','4770000002','WORLD',7,4,1); +INSERT INTO `bookingPlanner` VALUES (6,'2017-07-01 00:00:00','4770000010','NATIONAL',3,1,1); +INSERT INTO `bookingPlanner` VALUES (8,'2017-07-01 00:00:00','4770000021','NATIONAL',1,2,1); +INSERT INTO `bookingPlanner` VALUES (9,'2017-07-01 00:00:00','4770000101','EQU',3,1,1); +INSERT INTO `bookingPlanner` VALUES (11,'2017-07-01 00:00:00','4770000110','EQU',4,1,1); +INSERT INTO `bookingPlanner` VALUES (12,'2017-07-01 00:00:00','4770000215','EQU',1,2,1); +INSERT INTO `bookingPlanner` VALUES (13,'2017-07-01 00:00:00','4770000521','EQU',2,2,1); +INSERT INTO `bookingPlanner` VALUES (15,'2017-07-01 00:00:00','4771000000','CEE',3,1,1); +INSERT INTO `bookingPlanner` VALUES (16,'2017-07-01 00:00:00','4771000001','CEE',8,3,1); +INSERT INTO `bookingPlanner` VALUES (19,'2017-07-05 13:54:58','4770000020','NATIONAL',7,4,1); +INSERT INTO `bookingPlanner` VALUES (20,'2017-07-05 14:09:24','4771000000','CEE',1,2,1); +INSERT INTO `bookingPlanner` VALUES (21,'2017-07-05 14:09:24','4771000000','CEE',7,4,1); +INSERT INTO `bookingPlanner` VALUES (22,'2017-07-05 14:12:14','4770000002','WORLD',3,1,1); +INSERT INTO `bookingPlanner` VALUES (23,'2017-07-05 14:12:14','4770000002','WORLD',1,2,1); +INSERT INTO `bookingPlanner` VALUES (24,'2017-07-06 10:07:21','4770000002','WORLD',7,4,5); +INSERT INTO `bookingPlanner` VALUES (25,'2017-07-06 10:07:21','HolandaRED','NATIONAL',3,1,5); +INSERT INTO `bookingPlanner` VALUES (27,'2017-07-06 10:07:21','HolandaGEN','NATIONAL',1,2,5); +INSERT INTO `bookingPlanner` VALUES (32,'2017-07-06 10:07:21','4771000000','CEE',3,1,5); +INSERT INTO `bookingPlanner` VALUES (33,'2017-07-06 10:07:21','4771000001','CEE',8,3,5); +INSERT INTO `bookingPlanner` VALUES (34,'2017-07-06 10:07:21','4770000020','NATIONAL',7,4,5); +INSERT INTO `bookingPlanner` VALUES (35,'2017-07-06 10:07:21','4771000000','CEE',1,2,5); +INSERT INTO `bookingPlanner` VALUES (36,'2017-07-06 10:07:21','4771000000','CEE',7,4,5); +INSERT INTO `bookingPlanner` VALUES (37,'2017-07-06 10:07:21','4770000002','WORLD',3,1,5); +INSERT INTO `bookingPlanner` VALUES (38,'2017-07-06 10:07:21','4770000002','WORLD',1,2,5); +INSERT INTO `bookingPlanner` VALUES (82,'2019-01-01 12:51:56','4770000504','EQU',5,5,1); +INSERT INTO `bookingPlanner` VALUES (83,'2019-09-11 12:54:03','4770000405','EQU',6,5,1); +INSERT INTO `bookingPlanner` VALUES (84,'2019-09-11 12:58:17','4770000004','NATIONAL',5,5,1); +INSERT INTO `bookingPlanner` VALUES (85,'2019-09-19 00:00:00','4771000000','CEE',5,5,1); +INSERT INTO `bookingPlanner` VALUES (86,'2021-10-14 00:00:00','4770000002','WORLD',5,5,1); + +INSERT INTO `businessType` VALUES ('decoration','Decoración'); +INSERT INTO `businessType` VALUES ('events','Eventos'); +INSERT INTO `businessType` VALUES ('florist','Floristería'); +INSERT INTO `businessType` VALUES ('gardenCentre','Vivero'); +INSERT INTO `businessType` VALUES ('gardening','Jardinería'); +INSERT INTO `businessType` VALUES ('individual','Particular'); +INSERT INTO `businessType` VALUES ('mortuary','Funeraria'); +INSERT INTO `businessType` VALUES ('officialOrganism','Organismo oficial'); +INSERT INTO `businessType` VALUES ('others','Otros'); +INSERT INTO `businessType` VALUES ('otherSector','Profesional de otro sector'); +INSERT INTO `businessType` VALUES ('restoration','Restauración'); +INSERT INTO `businessType` VALUES ('trainingCentre','Centro de formación'); +INSERT INTO `businessType` VALUES ('wholesaler','Mayorista'); +INSERT INTO `businessType` VALUES ('worker','Trabajador'); + +INSERT INTO `companyI18n` VALUES (442,'en','In compliance with the provisions of Organic Law 15/1999, on the Protection of Personal Data, we inform you that the personal data you provide will be included in automated files of VERDNATURA LEVANTE SL, being able at all times to exercise the rights of access, rectification, cancellation and opposition, communicating it in writing to the registered office of the entity. The purpose of the file is administrative management, accounting, and billing.'); +INSERT INTO `companyI18n` VALUES (442,'fr','Conformément aux dispositions de la loi organique 15/1999 sur la protection des données personnelles, nous vous informons que les données personnelles que vous fournissez seront incluses dans des dossiers. VERDNATURA LEVANTE S.L., vous pouvez à tout moment, exercer les droits d``accès, de rectification, d``annulation et d``opposition, en communiquant par écrit au siège social de la société. Le dossier a pour objet la gestion administrative, la comptabilité et la facturation.'); +INSERT INTO `companyI18n` VALUES (442,'pt','Em cumprimento do disposto na lei Orgânica 15/1999, de Protecção de Dados de Carácter Pessoal, comunicamos que os dados pessoais que facilite se incluirão nos ficheiros automatizados de VERDNATURA LEVANTE S.L., podendo em todo momento exercer os direitos de acesso, rectificação, cancelação e oposição, comunicando por escrito ao domicílio social da entidade. A finalidade do ficheiro é a gestão administrativa, contabilidade e facturação.'); + +INSERT INTO `cplusRectificationType` VALUES (1,'Campo vacio'); +INSERT INTO `cplusRectificationType` VALUES (2,'I – Por diferencias'); +INSERT INTO `cplusRectificationType` VALUES (3,'S – Por sustitución'); + +INSERT INTO `cplusSubjectOp` VALUES (1,'Campo vacio'); +INSERT INTO `cplusSubjectOp` VALUES (2,'S1 – Sujeta – No exenta'); +INSERT INTO `cplusSubjectOp` VALUES (3,'S2 – Sujeta – No exenta – Inv. Suj. Pasivo'); + +INSERT INTO `cplusTaxBreak` VALUES (1,'Campo vacio'); +INSERT INTO `cplusTaxBreak` VALUES (2,'E1 - Exenta por el artículo 20'); +INSERT INTO `cplusTaxBreak` VALUES (3,'E2 - Exenta por el artículo 21'); +INSERT INTO `cplusTaxBreak` VALUES (4,'E3 - Exenta por el artículo 22'); +INSERT INTO `cplusTaxBreak` VALUES (5,'E4 - Exenta por el artículo 24'); +INSERT INTO `cplusTaxBreak` VALUES (6,'E5 - Exenta por el artículo 25'); +INSERT INTO `cplusTaxBreak` VALUES (7,'E6 - Exenta por otros'); + +INSERT INTO `claimResponsible` VALUES (1,'Compradores',0,'buy'); +INSERT INTO `claimResponsible` VALUES (2,'Proveedor',0,'sup'); +INSERT INTO `claimResponsible` VALUES (3,'Entradores',0,'ent'); +INSERT INTO `claimResponsible` VALUES (4,'Camareros',0,'bar'); +INSERT INTO `claimResponsible` VALUES (6,'Sacadores',0,'pic'); +INSERT INTO `claimResponsible` VALUES (7,'Revisadores',0,'chk'); +INSERT INTO `claimResponsible` VALUES (8,'Calidad general',0,'qas'); +INSERT INTO `claimResponsible` VALUES (9,'Encajadores',0,'pck'); +INSERT INTO `claimResponsible` VALUES (10,'Clima',0,'wea'); +INSERT INTO `claimResponsible` VALUES (11,'Comerciales',1,'com'); +INSERT INTO `claimResponsible` VALUES (12,'Clientes',1,'cli'); +INSERT INTO `claimResponsible` VALUES (13,'Administración',0,'adm'); +INSERT INTO `claimResponsible` VALUES (14,'Agencia',0,'age'); +INSERT INTO `claimResponsible` VALUES (15,'Repartidores',0,'del'); +INSERT INTO `claimResponsible` VALUES (16,'Informatica',0,'ite'); +INSERT INTO `claimResponsible` VALUES (17,'Transp.origen',0,'tra'); +INSERT INTO `claimResponsible` VALUES (18,'Confeccion',0,'con'); +INSERT INTO `claimResponsible` VALUES (19,'OTROS',0,'oth'); +INSERT INTO `claimResponsible` VALUES (21,'Gerencia',0,'man'); +INSERT INTO `claimResponsible` VALUES (22,'Paletizadores',0,'pal'); +INSERT INTO `claimResponsible` VALUES (23,'Preparación Previa',0,'pre'); +INSERT INTO `claimResponsible` VALUES (24,'Almacén PCA',0,'war'); +INSERT INTO `claimResponsible` VALUES (25,'Huelga',0,'str'); + +INSERT INTO `claimReason` VALUES (1,'Prisas',0); +INSERT INTO `claimReason` VALUES (2,'Novato',0); +INSERT INTO `claimReason` VALUES (3,'Exceso de confianza',0); +INSERT INTO `claimReason` VALUES (4,'Exceso de celo',0); +INSERT INTO `claimReason` VALUES (5,'Indiferencia',0); +INSERT INTO `claimReason` VALUES (6,'Extraviado o Hurto',0); +INSERT INTO `claimReason` VALUES (7,'Incompetencia',0); +INSERT INTO `claimReason` VALUES (8,'Ubicación erronea',0); +INSERT INTO `claimReason` VALUES (9,'Dat.Inctos/Pak.conf',0); +INSERT INTO `claimReason` VALUES (10,'Datos duplicados',0); +INSERT INTO `claimReason` VALUES (11,'Fallo stock',0); +INSERT INTO `claimReason` VALUES (12,'Innovación',0); +INSERT INTO `claimReason` VALUES (13,'Distracción',1); +INSERT INTO `claimReason` VALUES (15,'Portes indebidos',0); +INSERT INTO `claimReason` VALUES (16,'Baja calidad',0); +INSERT INTO `claimReason` VALUES (17,'Defectuoso',0); +INSERT INTO `claimReason` VALUES (19,'Endiñado',0); +INSERT INTO `claimReason` VALUES (20,'Calor',0); +INSERT INTO `claimReason` VALUES (21,'Frio',0); +INSERT INTO `claimReason` VALUES (22,'Cambiado',0); +INSERT INTO `claimReason` VALUES (24,'Cansancio',1); +INSERT INTO `claimReason` VALUES (25,'Mal etiquetado',1); +INSERT INTO `claimReason` VALUES (26,'Cantidad malentendido',0); +INSERT INTO `claimReason` VALUES (30,'No revisado',1); +INSERT INTO `claimReason` VALUES (34,'Error fotografia',0); +INSERT INTO `claimReason` VALUES (40,'Fallo Personal VN',0); +INSERT INTO `claimReason` VALUES (41,'Fallo Personal Cliente',0); +INSERT INTO `claimReason` VALUES (42,'Otros',0); +INSERT INTO `claimReason` VALUES (43,'Precio alto',0); +INSERT INTO `claimReason` VALUES (44,'Abuso de confianza',0); +INSERT INTO `claimReason` VALUES (45,'Retraso Agencia',0); +INSERT INTO `claimReason` VALUES (46,'Delicado',0); +INSERT INTO `claimReason` VALUES (47,'Seco',0); +INSERT INTO `claimReason` VALUES (48,'Retraso Reparto',0); +INSERT INTO `claimReason` VALUES (49,'Mal Embalado',0); +INSERT INTO `claimReason` VALUES (50,'Tumbado',0); +INSERT INTO `claimReason` VALUES (51,'Enfermo/Plaga',0); +INSERT INTO `claimReason` VALUES (52,'Mala gestión comercial',0); +INSERT INTO `claimReason` VALUES (53,'Mala gestión comprador',0); +INSERT INTO `claimReason` VALUES (54,'A2',0); +INSERT INTO `claimReason` VALUES (55,'Entrega 48h o más',0); + +INSERT INTO `claimRedelivery` VALUES (1,'Cliente'); +INSERT INTO `claimRedelivery` VALUES (2,'No dev./No especif.'); +INSERT INTO `claimRedelivery` VALUES (3,'Reparto'); +INSERT INTO `claimRedelivery` VALUES (4,'Agencia'); +INSERT INTO `claimRedelivery` VALUES (5,'Tour'); +INSERT INTO `claimRedelivery` VALUES (6,'Fuera Peninsula'); + +INSERT INTO `claimResult` VALUES (1,'Otros daños'); +INSERT INTO `claimResult` VALUES (2,'Roces'); +INSERT INTO `claimResult` VALUES (3,'Humedad'); +INSERT INTO `claimResult` VALUES (4,'Deshidratacion'); +INSERT INTO `claimResult` VALUES (5,'Error identidad'); +INSERT INTO `claimResult` VALUES (6,'Incompleto (Faltas)'); +INSERT INTO `claimResult` VALUES (7,'Error packing'); +INSERT INTO `claimResult` VALUES (8,'Error color'); +INSERT INTO `claimResult` VALUES (9,'Error medida'); +INSERT INTO `claimResult` VALUES (10,'Error origen'); +INSERT INTO `claimResult` VALUES (11,'Envejecido'); +INSERT INTO `claimResult` VALUES (12,'Venta Perdida'); +INSERT INTO `claimResult` VALUES (13,'Duplicacion'); +INSERT INTO `claimResult` VALUES (14,'Rechazado'); +INSERT INTO `claimResult` VALUES (15,'Rotura'); +INSERT INTO `claimResult` VALUES (16,'Deterioro/Estropeado'); +INSERT INTO `claimResult` VALUES (17,'Podrido'); +INSERT INTO `claimResult` VALUES (18,'Baboso'); +INSERT INTO `claimResult` VALUES (19,'Cocido'); +INSERT INTO `claimResult` VALUES (20,'Congelado'); +INSERT INTO `claimResult` VALUES (21,'Machacado'); +INSERT INTO `claimResult` VALUES (22,'Error precio'); +INSERT INTO `claimResult` VALUES (23,'Manchado'); +INSERT INTO `claimResult` VALUES (24,'No entregado'); +INSERT INTO `claimResult` VALUES (25,'Cobro indebido'); +INSERT INTO `claimResult` VALUES (26,'Decepcion/Esperaba mas'); +INSERT INTO `claimResult` VALUES (27,'Otros'); +INSERT INTO `claimResult` VALUES (28,'Baboso/Cocido'); +INSERT INTO `claimResult` VALUES (29,'Video Camara'); + +INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices',0); +INSERT INTO `component` VALUES (14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay',0); +INSERT INTO `component` VALUES (15,'reparto',6,NULL,NULL,1,'delivery',1); +INSERT INTO `component` VALUES (17,'recobro',5,NULL,NULL,1,'debtCollection',0); +INSERT INTO `component` VALUES (21,'ajuste',4,NULL,NULL,1,'adjustment',0); +INSERT INTO `component` VALUES (22,'venta por paquete',9,1,NULL,0,'salePerPackage',0); +INSERT INTO `component` VALUES (23,'venta por caja',9,2,NULL,0,'salePerBox',0); +INSERT INTO `component` VALUES (28,'valor de compra',1,NULL,NULL,1,'purchaseValue',1); +INSERT INTO `component` VALUES (29,'margen',4,NULL,NULL,1,'margin',1); +INSERT INTO `component` VALUES (32,'descuento ultimas unidades',9,3,-0.05,0,'lastUnitsDiscount',0); +INSERT INTO `component` VALUES (33,'venta por caja',9,1,NULL,0,'salePerBox',0); +INSERT INTO `component` VALUES (34,'descuento comprador',4,NULL,NULL,1,'buyerDiscount',0); +INSERT INTO `component` VALUES (35,'cartera comprador',10,NULL,NULL,1,NULL,0); +INSERT INTO `component` VALUES (36,'descuadre',4,NULL,NULL,1,'imbalance',0); +INSERT INTO `component` VALUES (37,'maná',7,4,NULL,0,'mana',0); +INSERT INTO `component` VALUES (38,'embolsado',9,NULL,NULL,1,'bagged',0); +INSERT INTO `component` VALUES (39,'maná auto',7,NULL,NULL,1,'autoMana',0); +INSERT INTO `component` VALUES (40,'cambios Santos 2016',4,NULL,NULL,1,NULL,0); +INSERT INTO `component` VALUES (41,'bonificacion porte',6,NULL,NULL,1,'freightCharge',0); +INSERT INTO `component` VALUES (42,'promocion Francia',4,NULL,NULL,1,'frenchOffer',0); +INSERT INTO `component` VALUES (43,'promocion Floramondo',4,NULL,NULL,1,'floramondoPromo',0); +INSERT INTO `component` VALUES (44,'rappel cadena',2,NULL,NULL,1,'rappel',0); +INSERT INTO `component` VALUES (45,'maná reclamacion',7,4,NULL,0,'manaClaim',0); +INSERT INTO `component` VALUES (46,'recargo a particular',2,NULL,0.25,0,'individual',0); +INSERT INTO `component` VALUES (47,'promocion Italia',4,NULL,NULL,1,'italianOffer',0); +INSERT INTO `component` VALUES (48,'fusión de lineas',4,NULL,NULL,1,'lineFusion',0); + +INSERT INTO `componentType` VALUES (1,'coste',1,0,'COST'); +INSERT INTO `componentType` VALUES (2,'com ventas',1,1,NULL); +INSERT INTO `componentType` VALUES (3,'com compras',1,1,NULL); +INSERT INTO `componentType` VALUES (4,'empresa',1,1,'MARGIN'); +INSERT INTO `componentType` VALUES (5,'cliente',0,0,NULL); +INSERT INTO `componentType` VALUES (6,'agencia',0,0,'FREIGHT'); +INSERT INTO `componentType` VALUES (7,'cartera_comercial',0,0,'MANA'); +INSERT INTO `componentType` VALUES (8,'cartera_producto',0,1,NULL); +INSERT INTO `componentType` VALUES (9,'maniobra',1,0,NULL); +INSERT INTO `componentType` VALUES (10,'cartera_comprador',0,1,NULL); +INSERT INTO `componentType` VALUES (11,'errores',0,1,NULL); +INSERT INTO `componentType` VALUES (12,'otros',0,1,NULL); + +INSERT INTO `continent` VALUES (1,'Asia','AS'); +INSERT INTO `continent` VALUES (2,'América','AM'); +INSERT INTO `continent` VALUES (3,'África','AF'); +INSERT INTO `continent` VALUES (4,'Europa','EU'); +INSERT INTO `continent` VALUES (5,'Oceanía','OC'); + +INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,104,763,0,0,0,0,28,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (22,'shopping','COMPRAS',2,3,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (23,'CMA','CAMARA',13,14,NULL,72,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL,NULL); +INSERT INTO `department` VALUES (31,'it','INFORMATICA',4,5,NULL,72,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (34,'accounting','CONTABILIDAD',6,7,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (35,'finance','FINANZAS',8,9,NULL,0,0,0,1,0,1,'/1/',NULL,1,'begonya@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (36,'labor','LABORAL',10,11,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (37,'PROD','PRODUCCION',12,33,NULL,72,1,1,1,10,1,'/1/',NULL,0,NULL,0,1,1,1,NULL,NULL); +INSERT INTO `department` VALUES (38,'picking','SACADO',15,16,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (39,'packing','ENCAJADO',17,18,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (41,'administration','ADMINISTRACION',34,35,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (43,'VT','VENTAS',36,59,NULL,0,0,0,1,11,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (44,'management','GERENCIA',60,61,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (45,'logistic','LOGISTICA',62,63,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (46,'delivery','REPARTO',64,65,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (48,'storage','ALMACENAJE',66,67,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (49,NULL,'PROPIEDAD',68,69,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (52,NULL,'CARGA AEREA',70,71,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (53,'marketing','MARKETING Y COMUNICACIÓN',72,73,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (54,NULL,'ORNAMENTALES',74,75,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (55,NULL,'TALLER NATURAL',19,20,14548,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1118,NULL); +INSERT INTO `department` VALUES (56,NULL,'TALLER ARTIFICIAL',21,22,8470,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1927,NULL); +INSERT INTO `department` VALUES (58,'CMP','CAMPOS',76,79,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (59,'maintenance','MANTENIMIENTO',80,81,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (60,'claims','RECLAMACIONES',82,83,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (61,NULL,'VNH',84,87,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (66,NULL,'VERDNAMADRID',88,89,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (68,NULL,'COMPLEMENTOS',23,24,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (69,NULL,'VERDNABARNA',90,91,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (80,NULL,'EQUIPO J VALLES',37,38,4250,72,0,0,2,0,43,'/1/43/','jvp_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (86,NULL,'LIMPIEZA',92,93,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (89,NULL,'COORDINACION',94,95,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (90,NULL,'TRAILER',85,86,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (91,'artificial','ARTIFICIAL',25,26,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (92,NULL,'EQUIPO SILVERIO',39,40,1203,0,0,0,2,0,43,'/1/43/','sdc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (94,NULL,'EQUIPO J BROCAL',41,42,3797,0,0,0,2,0,43,'/1/43/','jes_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (95,NULL,'EQUIPO C ZAMBRANO',43,44,4667,0,0,0,2,0,43,'/1/43/','czg_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (96,NULL,'EQUIPO C LOPEZ',45,46,4661,0,0,0,2,0,43,'/1/43/','cla_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (115,NULL,'EQUIPO CLAUDI',47,48,3810,0,0,0,2,0,43,'/1/43/','csr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (123,NULL,'EQUIPO ELENA BASCUÑANA',49,50,7102,0,0,0,2,0,43,'/1/43/','ebt_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (124,NULL,'CONTROL INTERNO',96,97,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (125,NULL,'EQUIPO MIRIAM MAR',51,52,1118,0,0,0,2,0,43,'/1/43/','mir_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (126,NULL,'PRESERVADO',27,28,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,NULL,NULL); +INSERT INTO `department` VALUES (128,NULL,'PALETIZADO',29,30,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (130,NULL,'REVISION',31,32,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (131,'greenhouse','INVERNADERO',77,78,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (132,NULL,'EQUIPO DC',53,54,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (133,'franceTeam','EQUIPO FRANCIA',55,56,1731,72,0,0,2,0,43,'/1/43/','fra_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (134,NULL,'EQUIPO RODRI',57,58,6264,0,0,0,2,0,43,'/1/43/','rhr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (135,'routers','ENRUTADORES',98,99,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (136,'heavyVehicles','VEHICULOS PESADOS',100,101,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (137,'sorter','SORTER',102,103,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); + +INSERT INTO `docuware` VALUES (1,'deliveryNote','Albaranes cliente','find','find','N__ALBAR_N',NULL); +INSERT INTO `docuware` VALUES (2,'deliveryNote','Albaranes cliente','store','Archivar','N__ALBAR_N',NULL); +INSERT INTO `docuware` VALUES (3,'hr','RRHH','find','Búsqueda','N__DOCUMENTO',3); + +INSERT INTO `itemPackingType` VALUES ('F','Fruta y Verdura',0); +INSERT INTO `itemPackingType` VALUES ('H','Horizontal',1); +INSERT INTO `itemPackingType` VALUES ('P','Pienso',0); +INSERT INTO `itemPackingType` VALUES ('V','Vertical',1); + +INSERT INTO `pgc` VALUES ('4722000000',0.00,'Importación Exento ',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('4722000010',10.00,'Importación Reducido ',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('4722000021',21.00,'Importación General ',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('4770000001',8.00,'Reducido',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000002',0.00,'Extra-Community supply',3,1,0,2,0); +INSERT INTO `pgc` VALUES ('4770000004',4.00,'Super reducido',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000010',10.00,'Reducido',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000020',0.00,'Exento',7,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000021',21.00,'General',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000101',10.00,'Reducido ',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000108',8.00,'Reducido',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000110',1.40,'Rec. Eq. Reducido',1,0,0,1,1); +INSERT INTO `pgc` VALUES ('4770000215',21.00,'General',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000405',0.50,'Rec. Eq. Super Reducido',1,0,0,1,1); +INSERT INTO `pgc` VALUES ('4770000504',4.00,'Super reducido',1,1,1,1,0); +INSERT INTO `pgc` VALUES ('4770000521',5.20,'Rec. Eq. General',1,0,0,1,1); +INSERT INTO `pgc` VALUES ('4770000701',1.00,'Rec. Eq. Reducido',1,0,0,1,1); +INSERT INTO `pgc` VALUES ('4771000000',0.00,'Intra-Community supply',6,1,1,1,0); +INSERT INTO `pgc` VALUES ('4771000001',0.00,'Intra-Community services',7,1,1,1,0); +INSERT INTO `pgc` VALUES ('HolandaGEN',21.00,'General',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('HolandaRED',9.00,'Reducido',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('IGIC cero',0.00,'Cero',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('IGIC gener',6.50,'General',1,0,0,1,0); +INSERT INTO `pgc` VALUES ('IGIC reduc',3.00,'Reducido',1,0,0,1,0); + +INSERT INTO `sample` VALUES (1,'Carta_1','Aviso inicial por saldo deudor',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (2,'Carta_2','Reiteracion de aviso por saldo deudor',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (3,'Cred_Up','Notificación de aumento de crédito',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (4,'Cred_down','Notificación de reducción de crédito',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (5,'Pet_CC','Petición de datos bancarios B2B',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (6,'SolCredito','Solicitud de crédito',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (7,'LeyPago','Ley de pagos',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (8,'Pet_CC_Core','Petición de datos bancarios CORE',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (9,'nueva_alta','Documento de nueva alta de cliente',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (10,'client_welcome','Email de bienvenida para nuevo cliente',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (11,'setup_printer','Email de instalación de impresora',0,0,1,0,NULL); +INSERT INTO `sample` VALUES (12,'client-welcome','Bienvenida como nuevo cliente',1,0,1,0,'Clients'); +INSERT INTO `sample` VALUES (13,'printer-setup','Instalación y configuración de impresora de coronas',1,0,1,0,'Clients'); +INSERT INTO `sample` VALUES (14,'sepa-core','Solicitud de domiciliación bancaria',1,1,0,0,'Clients'); +INSERT INTO `sample` VALUES (15,'letter-debtor-st','Aviso inicial por saldo deudor',1,1,1,0,'Clients'); +INSERT INTO `sample` VALUES (16,'letter-debtor-nd','Aviso reiterado por saldo deudor',1,1,1,0,'Clients'); +INSERT INTO `sample` VALUES (17,'client-lcr','Email de solicitud de datos bancarios LCR',0,1,1,0,NULL); +INSERT INTO `sample` VALUES (18,'client-debt-statement','Extracto del cliente',1,0,1,1,'Clients'); +INSERT INTO `sample` VALUES (19,'credit-request','Solicitud de crédito',1,1,1,0,'Clients'); +INSERT INTO `sample` VALUES (20,'incoterms-authorization','Autorización de incoterms',1,1,1,0,'Clients'); + +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (1,'Operación de régimen general'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (2,'Operaciones por las que los empresarios satisfacen compensaciones REAGYP'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (3,'Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (135 - 139 de LIVA)'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (4,'Régimen especial oro de inversión'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (5,'Régimen especial agencias de viajes'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (6,'Régimen especial grupo de entidades en IVA (Nivel Avanzado)'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (7,'Régimen especial criterio de caja'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (8,'Operaciones sujetas al IPSI / IGIC'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (9,'Adquisiciones intracomunitarias de bienes y prestaciones de servicios'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (12,'Operaciones de arrendamiento de local de negocio'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (13,'Factura correspondiente a una importación (informada sin asociar a un DUA)'); +INSERT INTO `siiTrascendencyInvoiceIn` VALUES (14,'Primer semestre 2017'); + +INSERT INTO `siiTypeInvoiceIn` VALUES (1,'F1','Factura'); +INSERT INTO `siiTypeInvoiceIn` VALUES (2,'F2','Factura simplificada (ticket)'); +INSERT INTO `siiTypeInvoiceIn` VALUES (3,'F3','Factura emitida en sustitución de facturas simplificadas facturadas y declaradas'); +INSERT INTO `siiTypeInvoiceIn` VALUES (4,'F4','Asiento resumen de facturas'); +INSERT INTO `siiTypeInvoiceIn` VALUES (5,'F5','Importaciones (DUA)'); +INSERT INTO `siiTypeInvoiceIn` VALUES (6,'F6','Otros justificantes contables'); +INSERT INTO `siiTypeInvoiceIn` VALUES (7,'R1','Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)'); +INSERT INTO `siiTypeInvoiceIn` VALUES (8,'R2','Factura rectificativa (Art. 80.3)'); +INSERT INTO `siiTypeInvoiceIn` VALUES (9,'R3','Factura rectificativa (Art. 80.4)'); +INSERT INTO `siiTypeInvoiceIn` VALUES (10,'R4','Factura rectificativa (Resto)'); +INSERT INTO `siiTypeInvoiceIn` VALUES (11,'R5','Factura rectificativa en facturas simplificadas'); + +INSERT INTO `siiTypeInvoiceOut` VALUES (1,'F1','Factura'); +INSERT INTO `siiTypeInvoiceOut` VALUES (2,'F2','Factura simplificada (ticket)'); +INSERT INTO `siiTypeInvoiceOut` VALUES (3,'F3','Factura emitida en sustitución de facturas simplificadas facturadas y declaradas'); +INSERT INTO `siiTypeInvoiceOut` VALUES (4,'F4','Asiento resumen de facturas'); +INSERT INTO `siiTypeInvoiceOut` VALUES (5,'R1','Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)'); +INSERT INTO `siiTypeInvoiceOut` VALUES (6,'R2','Factura rectificativa (Art. 80.3)'); +INSERT INTO `siiTypeInvoiceOut` VALUES (7,'R3','Factura rectificativa (Art. 80.4)'); +INSERT INTO `siiTypeInvoiceOut` VALUES (8,'R4','Factura rectificativa (Resto)'); +INSERT INTO `siiTypeInvoiceOut` VALUES (9,'R5','Factura rectificativa en facturas simplificadas'); + +INSERT INTO `silexACL` VALUES (1,'workerTimeControl','clockIn','$everyone'); +INSERT INTO `silexACL` VALUES (2,'workerTimeControl','getClockIn','$everyone'); +INSERT INTO `silexACL` VALUES (3,'workerTimeControl','login','$everyone'); +INSERT INTO `silexACL` VALUES (4,'security','device_checkLogin','employee'); +INSERT INTO `silexACL` VALUES (5,'security','getVersion','employee'); +INSERT INTO `silexACL` VALUES (6,'security','login','employee'); +INSERT INTO `silexACL` VALUES (7,'delivery','addNote','employee'); +INSERT INTO `silexACL` VALUES (8,'delivery','expeditionState_add','employee'); +INSERT INTO `silexACL` VALUES (9,'delivery','expeditionState_addByExpedition','employee'); +INSERT INTO `silexACL` VALUES (10,'delivery','expeditionState_addByExpeditionMulti','employee'); +INSERT INTO `silexACL` VALUES (11,'delivery','expeditionState_addByRoute','employee'); +INSERT INTO `silexACL` VALUES (12,'delivery','expedition_getLog','employee'); +INSERT INTO `silexACL` VALUES (13,'delivery','getExpeditionFromRoute','employee'); +INSERT INTO `silexACL` VALUES (14,'delivery','getInfo','employee'); +INSERT INTO `silexACL` VALUES (15,'delivery','getInfoCompany','employee'); +INSERT INTO `silexACL` VALUES (16,'delivery','getInfoFreelance','employee'); +INSERT INTO `silexACL` VALUES (17,'delivery','getWorkers','employee'); +INSERT INTO `silexACL` VALUES (18,'delivery','get_routes','employee'); +INSERT INTO `silexACL` VALUES (19,'delivery','get_tickets','employee'); +INSERT INTO `silexACL` VALUES (20,'delivery','get_version','employee'); +INSERT INTO `silexACL` VALUES (21,'delivery','saveLoadersWorkers','employee'); +INSERT INTO `silexACL` VALUES (22,'delivery','save_sign','employee'); +INSERT INTO `silexACL` VALUES (23,'delivery','setRouteOk','employee'); +INSERT INTO `silexACL` VALUES (24,'delivery','updateExpeditionChecked','employee'); +INSERT INTO `silexACL` VALUES (25,'delivery','update_routes','employee'); +INSERT INTO `silexACL` VALUES (26,'almacennew','barcodes_edit','employee'); +INSERT INTO `silexACL` VALUES (27,'almacennew','barcodeToItem','employee'); +INSERT INTO `silexACL` VALUES (28,'almacennew','buffer_setTypeByName','employee'); +INSERT INTO `silexACL` VALUES (29,'almacennew','buy_updateGrouping','employee'); +INSERT INTO `silexACL` VALUES (30,'almacennew','buy_updatePacking','employee'); +INSERT INTO `silexACL` VALUES (31,'almacennew','checkRouteExpeditionScanPut','employee'); +INSERT INTO `silexACL` VALUES (32,'almacennew','clearShelvingList','employee'); +INSERT INTO `silexACL` VALUES (33,'almacennew','collectionAddItem','employee'); +INSERT INTO `silexACL` VALUES (34,'almacennew','collectionGet','employee'); +INSERT INTO `silexACL` VALUES (35,'almacennew','collectionIncreaseQuantity','employee'); +INSERT INTO `silexACL` VALUES (36,'almacennew','collectionMissingTrash','employee'); +INSERT INTO `silexACL` VALUES (37,'almacennew','collectionNew','employee'); +INSERT INTO `silexACL` VALUES (38,'almacennew','collectionStickerPrint','employee'); +INSERT INTO `silexACL` VALUES (39,'almacennew','collection_getTickets','employee'); +INSERT INTO `silexACL` VALUES (40,'almacennew','collection_printSticker','employee'); +INSERT INTO `silexACL` VALUES (41,'almacennew','department_getHasMistake','employee'); +INSERT INTO `silexACL` VALUES (42,'almacennew','deviceLog_add','employee'); +INSERT INTO `silexACL` VALUES (43,'almacennew','deviceProductionUser_getWorker','employee'); +INSERT INTO `silexACL` VALUES (44,'almacennew','deviceProduction_getnameDevice','employee'); +INSERT INTO `silexACL` VALUES (45,'almacennew','expeditionLoading_add','employee'); +INSERT INTO `silexACL` VALUES (46,'almacennew','expeditionPalletDel','employee'); +INSERT INTO `silexACL` VALUES (47,'almacennew','expeditionPalletList','employee'); +INSERT INTO `silexACL` VALUES (48,'almacennew','expeditionPalletPrintSet','employee'); +INSERT INTO `silexACL` VALUES (49,'almacennew','expeditionPalletView','employee'); +INSERT INTO `silexACL` VALUES (50,'almacennew','expeditionScanAdd','employee'); +INSERT INTO `silexACL` VALUES (51,'almacennew','expeditionScanDel','employee'); +INSERT INTO `silexACL` VALUES (52,'almacennew','expeditionScanList','employee'); +INSERT INTO `silexACL` VALUES (53,'almacennew','expeditionScanPut','employee'); +INSERT INTO `silexACL` VALUES (54,'almacennew','expeditionState_addByPallet','employee'); +INSERT INTO `silexACL` VALUES (55,'almacennew','expeditionTruckAdd','employee'); +INSERT INTO `silexACL` VALUES (56,'almacennew','expeditionTruckList','employee'); +INSERT INTO `silexACL` VALUES (57,'almacennew','expedition_getState','employee'); +INSERT INTO `silexACL` VALUES (58,'almacennew','expedition_scan','employee'); +INSERT INTO `silexACL` VALUES (59,'almacennew','faultsReview','employee'); +INSERT INTO `silexACL` VALUES (60,'almacennew','faultsReview_isChecked','employee'); +INSERT INTO `silexACL` VALUES (61,'almacennew','getItemUbication','employee'); +INSERT INTO `silexACL` VALUES (62,'almacennew','get_ItemPackingType','employee'); +INSERT INTO `silexACL` VALUES (63,'almacennew','itemDiary','employee'); +INSERT INTO `silexACL` VALUES (64,'almacennew','itemPlacementSupplyAiming','employee'); +INSERT INTO `silexACL` VALUES (65,'almacennew','itemPlacementSupplyCloseOrder','employee'); +INSERT INTO `silexACL` VALUES (66,'almacennew','itemPlacementSupplyGetOrder','employee'); +INSERT INTO `silexACL` VALUES (68,'almacennew','itemShelvingBuyerGet','employee'); +INSERT INTO `silexACL` VALUES (69,'almacennew','itemShelvingBuyerTask','employee'); +INSERT INTO `silexACL` VALUES (70,'almacennew','itemShelvingDelete','employee'); +INSERT INTO `silexACL` VALUES (71,'almacennew','itemShelvingList','employee'); +INSERT INTO `silexACL` VALUES (72,'almacennew','itemShelvingLog_get','employee'); +INSERT INTO `silexACL` VALUES (73,'almacennew','itemShelvingMake','employee'); +INSERT INTO `silexACL` VALUES (74,'almacennew','itemShelvingMakeEdit','employee'); +INSERT INTO `silexACL` VALUES (75,'almacennew','itemShelvingMake_multi','employee'); +INSERT INTO `silexACL` VALUES (76,'almacennew','itemShelvingPlacementSupplyAdd','employee'); +INSERT INTO `silexACL` VALUES (77,'almacennew','itemShelvingSaleSupplyAdd','employee'); +INSERT INTO `silexACL` VALUES (78,'almacennew','itemShelvingStarsUpdate','employee'); +INSERT INTO `silexACL` VALUES (79,'almacennew','itemShelvingTransfer','employee'); +INSERT INTO `silexACL` VALUES (80,'almacennew','itemShelving_addByClaim','employee'); +INSERT INTO `silexACL` VALUES (81,'almacennew','itemShelving_filterBuyer','employee'); +INSERT INTO `silexACL` VALUES (82,'almacennew','itemShelving_getSaleDate','employee'); +INSERT INTO `silexACL` VALUES (83,'almacennew','itemTrash','employee'); +INSERT INTO `silexACL` VALUES (84,'almacennew','item_card','employee'); +INSERT INTO `silexACL` VALUES (85,'almacennew','item_getSimilar','employee'); +INSERT INTO `silexACL` VALUES (86,'almacennew','item_placement_save','employee'); +INSERT INTO `silexACL` VALUES (87,'almacennew','item_saveReference','employee'); +INSERT INTO `silexACL` VALUES (88,'almacennew','item_updatePackingShelve','employee'); +INSERT INTO `silexACL` VALUES (89,'almacennew','machineWorker_add','employee'); +INSERT INTO `silexACL` VALUES (90,'almacennew','machineWorker_getHistorical','employee'); +INSERT INTO `silexACL` VALUES (91,'almacennew','machineWorker_update','employee'); +INSERT INTO `silexACL` VALUES (92,'almacennew','machineWorker_Worker','employee'); +INSERT INTO `silexACL` VALUES (93,'almacennew','machine_checkPlate','employee'); +INSERT INTO `silexACL` VALUES (94,'almacennew','machine_getWorkerPlate','employee'); +INSERT INTO `silexACL` VALUES (95,'almacennew','mistakeType','employee'); +INSERT INTO `silexACL` VALUES (96,'almacennew','printer_get','employee'); +INSERT INTO `silexACL` VALUES (97,'almacennew','qr_getCall','developer'); +INSERT INTO `silexACL` VALUES (98,'almacennew','saleMistakeAdd','employee'); +INSERT INTO `silexACL` VALUES (99,'almacennew','saleMove','employee'); +INSERT INTO `silexACL` VALUES (100,'almacennew','saleParking_add','employee'); +INSERT INTO `silexACL` VALUES (101,'almacennew','saleTrackingDel','employee'); +INSERT INTO `silexACL` VALUES (102,'almacennew','saleTrackingReplace','employee'); +INSERT INTO `silexACL` VALUES (103,'almacennew','saleTracking_add','employee'); +INSERT INTO `silexACL` VALUES (104,'almacennew','saleTracking_addPrevOK','employee'); +INSERT INTO `silexACL` VALUES (105,'almacennew','saleTracking_updateIsChecked','employee'); +INSERT INTO `silexACL` VALUES (106,'almacennew','sectorCollectionSaleGroup_add','employee'); +INSERT INTO `silexACL` VALUES (107,'almacennew','sectorCollection_get','employee'); +INSERT INTO `silexACL` VALUES (108,'almacennew','sectorCollection_getSale','employee'); +INSERT INTO `silexACL` VALUES (109,'almacennew','sectorCollection_new','employee'); +INSERT INTO `silexACL` VALUES (110,'almacennew','sector_get','employee'); +INSERT INTO `silexACL` VALUES (111,'almacennew','shelvingChange','employee'); +INSERT INTO `silexACL` VALUES (112,'almacennew','shelvingLog_get','employee'); +INSERT INTO `silexACL` VALUES (113,'almacennew','shelvingPark','employee'); +INSERT INTO `silexACL` VALUES (114,'almacennew','shelvingParking_get','employee'); +INSERT INTO `silexACL` VALUES (115,'almacennew','shelvingPriorityUpdate','employee'); +INSERT INTO `silexACL` VALUES (116,'almacennew','sip_getExtension','employee'); +INSERT INTO `silexACL` VALUES (117,'almacennew','ticketCollection_setUsedShelves','employee'); +INSERT INTO `silexACL` VALUES (118,'almacennew','ticketOrCollection_checkFullyControlled','employee'); +INSERT INTO `silexACL` VALUES (119,'almacennew','ticketToPrePrepare','employee'); +INSERT INTO `silexACL` VALUES (120,'almacennew','ticket_checkFullyControlled','employee'); +INSERT INTO `silexACL` VALUES (121,'almacennew','ticket_setState','employee'); +INSERT INTO `silexACL` VALUES (122,'almacennew','update_ItemPackingType','employee'); +INSERT INTO `silexACL` VALUES (123,'almacennew','workerMachinery_isRegistered','employee'); +INSERT INTO `silexACL` VALUES (124,'almacennew','workerMistakeType_get','employee'); +INSERT INTO `silexACL` VALUES (125,'almacennew','workerMistake_Add','coolerBoss'); +INSERT INTO `silexACL` VALUES (126,'almacennew','workerShelving_add','employee'); +INSERT INTO `silexACL` VALUES (127,'almacennew','workerShelving_delete','employee'); +INSERT INTO `silexACL` VALUES (128,'almacennew','worker_getFromHasMistake','employee'); +INSERT INTO `silexACL` VALUES (129,'almacennew','worker_getId','employee'); +INSERT INTO `silexACL` VALUES (130,'almacennew','worker_getPrinter','employee'); +INSERT INTO `silexACL` VALUES (131,'almacennew','worker_getSector','employee'); +INSERT INTO `silexACL` VALUES (132,'almacennew','worker_updatePrinter','employee'); +INSERT INTO `silexACL` VALUES (133,'almacennew','worker_updateSector','employee'); +INSERT INTO `silexACL` VALUES (134,'almacennew','itemShelving_updateFromSale','employee'); +INSERT INTO `silexACL` VALUES (135,'almacennew','collection_getUncheckedTicket','employee'); +INSERT INTO `silexACL` VALUES (136,'almacennew','itemShelving_return','employee'); +INSERT INTO `silexACL` VALUES (137,'almacennew','itemShelving_merge','employee'); +INSERT INTO `silexACL` VALUES (139,'delivery','get_expeditionsSummary','employee'); +INSERT INTO `silexACL` VALUES (140,'almacennew','cmrExpeditionPallet_add','employee'); +INSERT INTO `silexACL` VALUES (141,'delivery','route_getExpeditionSummary','employee'); +INSERT INTO `silexACL` VALUES (142,'almacennew','item_saveStems','employee'); +INSERT INTO `silexACL` VALUES (143,'almacennew','debug_add','employee'); +INSERT INTO `silexACL` VALUES (144,'almacennew','operator_getNumberOfWagons','employee'); +INSERT INTO `silexACL` VALUES (145,'almacennew','operator_add','employee'); +INSERT INTO `silexACL` VALUES (146,'almacennew','expeditionPallet_get','employee'); +INSERT INTO `silexACL` VALUES (147,'almacennew','worker_isF11Allowed','employee'); +INSERT INTO `silexACL` VALUES (148,'almacennew','train_get','employee'); +INSERT INTO `silexACL` VALUES (149,'almacennew','saleTracking_mark','employee'); +INSERT INTO `silexACL` VALUES (150,'almacennew','operator_updateItemPackingType','employee'); +INSERT INTO `silexACL` VALUES (151,'almacennew','operator_updateTrain','employee'); +INSERT INTO `silexACL` VALUES (152,'almacennew','operator_getTrain','employee'); +INSERT INTO `silexACL` VALUES (153,'almacennew','operator_getItemPackingType','employee'); +INSERT INTO `silexACL` VALUES (154,'almacennew','collection_assign','employee'); +INSERT INTO `silexACL` VALUES (155,'almacennew','itemPacking_get','employee'); +INSERT INTO `silexACL` VALUES (156,'almacennew','shelvingLog_add','employee'); +INSERT INTO `silexACL` VALUES (157,'almacennew','collection_get','employee'); +INSERT INTO `silexACL` VALUES (158,'delivery','get_routesFromExpedition','employee'); +INSERT INTO `silexACL` VALUES (160,'almacennew','expeditionMistakeType_get','employee'); +INSERT INTO `silexACL` VALUES (161,'almacennew','expeditionMistake_add','employee'); +INSERT INTO `silexACL` VALUES (162,'almacennew','itemShelving_addList','employee'); +INSERT INTO `silexACL` VALUES (163,'almacennew','cmrPallet_add','employee'); +INSERT INTO `silexACL` VALUES (164,'almacennew','ticket_isOutClosureZone','employee'); +INSERT INTO `silexACL` VALUES (165,'almacennew','itemShelving_selfConsumption','employee'); +INSERT INTO `silexACL` VALUES (166,'almacennew','ticket_printLabelPrevious','employee'); +INSERT INTO `silexACL` VALUES (167,'almacennew','travel_updatePacking','employee'); +INSERT INTO `silexACL` VALUES (168,'app','status','$everyone'); + +INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1,'alert'); +INSERT INTO `state` VALUES (2,'Libre',2,0,'FREE',NULL,2,0,0,0,0,0,0,4,1,'notice'); +INSERT INTO `state` VALUES (3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0,'success'); +INSERT INTO `state` VALUES (4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0,'success'); +INSERT INTO `state` VALUES (5,'Preparación',6,1,'ON_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'); +INSERT INTO `state` VALUES (6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0,'warning'); +INSERT INTO `state` VALUES (7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1,'alert'); +INSERT INTO `state` VALUES (8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0,'warning'); +INSERT INTO `state` VALUES (9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0,NULL); +INSERT INTO `state` VALUES (10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0,NULL); +INSERT INTO `state` VALUES (11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0,NULL); +INSERT INTO `state` VALUES (12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1,'alert'); +INSERT INTO `state` VALUES (13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0,NULL); +INSERT INTO `state` VALUES (14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0,'warning'); +INSERT INTO `state` VALUES (15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0,NULL); +INSERT INTO `state` VALUES (16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0,NULL); +INSERT INTO `state` VALUES (20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0,'success'); +INSERT INTO `state` VALUES (21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0,'success'); +INSERT INTO `state` VALUES (22,'Pte. Ampliar',2,0,'EXPANDABLE',NULL,22,0,0,0,0,0,0,4,1,'alert'); +INSERT INTO `state` VALUES (23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1,'success'); +INSERT INTO `state` VALUES (24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1,'success'); +INSERT INTO `state` VALUES (25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0,'alert'); +INSERT INTO `state` VALUES (26,'Prep Previa',5,0,'PREVIOUS_PREPARATION',1,28,1,0,0,1,0,0,2,0,'warning'); +INSERT INTO `state` VALUES (27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0,'success'); +INSERT INTO `state` VALUES (28,'Previa OK',3,0,'OK PREVIOUS',3,28,1,0,1,1,1,1,3,0,'warning'); +INSERT INTO `state` VALUES (29,'Previa Impreso',4,0,'PRINTED PREVIOUS',2,29,1,0,1,0,0,1,2,0,'success'); +INSERT INTO `state` VALUES (30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0,'success'); +INSERT INTO `state` VALUES (31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,2,0,'success'); +INSERT INTO `state` VALUES (32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0,'warning'); +INSERT INTO `state` VALUES (33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0,'success'); +INSERT INTO `state` VALUES (34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1,'alert'); +INSERT INTO `state` VALUES (35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0,NULL); +INSERT INTO `state` VALUES (36,'Previa Revisando',3,0,'PREVIOUS_CONTROL',2,37,1,0,0,4,0,1,2,0,'warning'); +INSERT INTO `state` VALUES (37,'Previa Revisado',3,0,'PREVIOUS_CONTROLLED',2,29,1,0,1,0,0,1,2,0,'warning'); +INSERT INTO `state` VALUES (38,'Prep Cámara',6,1,'COOLER_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'); +INSERT INTO `state` VALUES (41,'Prep Parcial',6,1,'PARTIAL_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'); + +INSERT INTO `ticketUpdateAction` VALUES (1,'Cambiar los precios en el ticket','changePrice'); +INSERT INTO `ticketUpdateAction` VALUES (3,'Convertir en maná','turnInMana'); + +INSERT INTO `volumeConfig` VALUES (2.67,1.60,0.8,150,0.30,120,57,2.0,50,200,10,167.0); + +INSERT INTO `workCenter` VALUES (1,'Silla',20,859,1,'Av espioca 100',552703,NULL); +INSERT INTO `workCenter` VALUES (2,'Mercaflor',19,NULL,NULL,NULL,NULL,NULL); +INSERT INTO `workCenter` VALUES (3,'Marjales',26,20008,NULL,NULL,NULL,NULL); +INSERT INTO `workCenter` VALUES (4,'VNH',NULL,NULL,NULL,NULL,NULL,NULL); +INSERT INTO `workCenter` VALUES (5,'Madrid',28,2869,5,'Av constitución 3',554145,2.00); +INSERT INTO `workCenter` VALUES (6,'Vilassar',88,88038,NULL,'Cami del Crist, 33',556412,NULL); +INSERT INTO `workCenter` VALUES (7,'Tenerife',NULL,NULL,NULL,NULL,NULL,NULL); +INSERT INTO `workCenter` VALUES (8,'Silla-Agrario',26,NULL,NULL,NULL,NULL,NULL); +INSERT INTO `workCenter` VALUES (9,'Algemesi',20,1354,60,'Fenollars, 2',523549,NULL); +INSERT INTO `workCenter` VALUES (10,'Rubi',88,NULL,84,'Av. de la Llana, 131',549722,NULL); + +INSERT INTO `workerBusinessAgreement` VALUES (1,'Flores y Plantas',2.5,1830,'2012-01-01',NULL); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `cache`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `cache` VALUES (1,'equalizator','00:19:00'); +INSERT INTO `cache` VALUES (2,'available','00:06:00'); +INSERT INTO `cache` VALUES (3,'stock','00:30:00'); +INSERT INTO `cache` VALUES (4,'last_buy','23:59:00'); +INSERT INTO `cache` VALUES (5,'weekly_sales','12:00:00'); +INSERT INTO `cache` VALUES (6,'bionic','00:06:00'); +INSERT INTO `cache` VALUES (7,'sales','00:04:00'); +INSERT INTO `cache` VALUES (8,'visible','00:04:00'); +INSERT INTO `cache` VALUES (9,'item_range','00:03:00'); +INSERT INTO `cache` VALUES (10,'barcodes','01:00:00'); +INSERT INTO `cache` VALUES (11,'prod_graphic','00:17:00'); +INSERT INTO `cache` VALUES (12,'ticketShipping','00:01:00'); +INSERT INTO `cache` VALUES (13,'availableNoRaids','00:06:00'); +INSERT INTO `cache` VALUES (14,'lastBuy','23:59:00'); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `hedera`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `browser` VALUES ('Chrome',49); +INSERT INTO `browser` VALUES ('Edge',79); +INSERT INTO `browser` VALUES ('Firefox',69); +INSERT INTO `browser` VALUES ('Opera',36); +INSERT INTO `browser` VALUES ('Safari',11); + +INSERT INTO `imageCollection` VALUES (1,'catalog','Artículo',3840,2160,'Item','image','vn','item','image',1,75); +INSERT INTO `imageCollection` VALUES (4,'link','Enlace',200,200,'Link','image','hedera','link','image',1,9); +INSERT INTO `imageCollection` VALUES (5,'news','Noticias',800,1200,'New','image','hedera','news','image',1,9); +INSERT INTO `imageCollection` VALUES (6,'user','Usuario',800,1200,'VnUser','image','account','user','image',1,74); + +INSERT INTO `imageCollectionSize` VALUES (2,1,50,50,1); +INSERT INTO `imageCollectionSize` VALUES (3,1,200,200,1); +INSERT INTO `imageCollectionSize` VALUES (5,5,200,200,1); +INSERT INTO `imageCollectionSize` VALUES (6,1,70,70,1); +INSERT INTO `imageCollectionSize` VALUES (8,5,50,50,1); +INSERT INTO `imageCollectionSize` VALUES (9,1,1600,900,0); +INSERT INTO `imageCollectionSize` VALUES (13,6,160,160,1); +INSERT INTO `imageCollectionSize` VALUES (14,6,520,520,1); +INSERT INTO `imageCollectionSize` VALUES (15,6,1600,1600,1); +INSERT INTO `imageCollectionSize` VALUES (16,1,500,500,1); + +INSERT INTO `language` VALUES ('ca','Català','Catalan',1); +INSERT INTO `language` VALUES ('en','English','English',1); +INSERT INTO `language` VALUES ('es','Español','Spanish',1); +INSERT INTO `language` VALUES ('fr','Français','French',1); +INSERT INTO `language` VALUES ('mn','Португалий','Mongolian',1); +INSERT INTO `language` VALUES ('pt','Português','Portuguese',1); + +INSERT INTO `link` VALUES (16,'Printing server','Manage the CUPS printing server','http://printnatura.verdnatura.es','printer'); +INSERT INTO `link` VALUES (20,'Webmail','Verdnatura webmail','https://webmail.verdnatura.es/','mail'); +INSERT INTO `link` VALUES (23,'Verdnatura Beta','Trial version of the web page','https://test-shop.verdnatura.es/','vn'); +INSERT INTO `link` VALUES (25,'Shared folder','Shared folder','https://cdn.verdnatura.es/share','backup'); +INSERT INTO `link` VALUES (29,'phpMyAdmin','Manage MySQL database','https://pma.verdnatura.es/','pma'); +INSERT INTO `link` VALUES (30,'Nagios','Monitoring system','https://nagios.verdnatura.es/','nagios'); +INSERT INTO `link` VALUES (33,'Gitea','Version control system','https://gitea.verdnatura.es/','git'); +INSERT INTO `link` VALUES (34,'Wiknatura','Verdnatura wiki page','https://wiki.verdnatura.es/','wiki'); +INSERT INTO `link` VALUES (35,'phpLDAPadmin','Manage the LDAP database','https://pla.verdnatura.es/','pla'); +INSERT INTO `link` VALUES (36,'Applications','Access applications repository','https://cdn.verdnatura.es/vn-access','access'); +INSERT INTO `link` VALUES (37,'Jenkins','CI and CD system','https://jenkins.verdnatura.es','jenkins'); +INSERT INTO `link` VALUES (38,'osTicket','User service center','https://cau.verdnatura.es','osticket'); +INSERT INTO `link` VALUES (39,'Redmine','Flexible project management','https://redmine.verdnatura.es','redmine'); +INSERT INTO `link` VALUES (40,'Grafana','Analytics & monitoring solution','https://grafana.verdnatura.es','grafana'); +INSERT INTO `link` VALUES (41,'Rocket.Chat','Communications platform','https://chat.verdnatura.es','rocketchat'); +INSERT INTO `link` VALUES (42,'Salix','ERP software','https://salix.verdnatura.es','salix'); +INSERT INTO `link` VALUES (43,'Docker','Container management','https://docker.verdnatura.es','docker'); +INSERT INTO `link` VALUES (44,'Proxmox','Virtual environment','https://mox.verdnatura.es','proxmox'); +INSERT INTO `link` VALUES (45,'Shinobi','Network video recorder','https://shinobi.verdnatura.es','shinobi'); +INSERT INTO `link` VALUES (46,'DokuWiki','Internal documentation','https://doku.verdnatura.es','dokuwiki'); + +INSERT INTO `location` VALUES (2,'39.2095886','-0.4173501','Valencia','Calle Fenollar, 2','46680','Algemesi','Valencia','963 242 100','es'); +INSERT INTO `location` VALUES (3,'40.4564969','-3.4875829','Madrid','Avenida de la Constitución, 3 - Nave E','28850','Torrejón de Ardoz','Madrid','963 242 100',NULL); +INSERT INTO `location` VALUES (4,'41.4962045','2.3765504','Barcelona','Camí del crist, 33','08340','Vilassar de Mar','Barcelona','607 562 391','ca'); +INSERT INTO `location` VALUES (5,'52.2612312','4.7818154','Holland','Aalsmeer Flower Auction','1430 BA','Legmeerdijk 313','Aalsmeer','Nederland','nl'); +INSERT INTO `location` VALUES (6,'43.4375416','5.2261456','Marseille','ruben@verdnatura.es','13054','Marigname','Marseille','+33 781 533 900','fr'); + +INSERT INTO `menu` VALUES (1,'Home','cms/home',6,NULL,1); +INSERT INTO `menu` VALUES (2,'Orders',NULL,11,NULL,1); +INSERT INTO `menu` VALUES (3,'Catalog','ecomerce/catalog',6,NULL,2); +INSERT INTO `menu` VALUES (7,'Administration',NULL,1,NULL,2); +INSERT INTO `menu` VALUES (8,'Users','admin/users',1,7,2); +INSERT INTO `menu` VALUES (9,'Connections','admin/connections',1,7,2); +INSERT INTO `menu` VALUES (11,'Agencies','agencies/packages',3,NULL,2); +INSERT INTO `menu` VALUES (12,'News','news/news',1,7,3); +INSERT INTO `menu` VALUES (15,'Photos','admin/photos',1,7,3); +INSERT INTO `menu` VALUES (17,'Configuration',NULL,11,NULL,3); +INSERT INTO `menu` VALUES (19,'Control panel','admin/links',1,7,1); +INSERT INTO `menu` VALUES (21,'Basket','ecomerce/basket',11,NULL,1); +INSERT INTO `menu` VALUES (22,'Last orders','ecomerce/orders',11,2,2); +INSERT INTO `menu` VALUES (23,'Invoices','ecomerce/invoices',11,2,2); +INSERT INTO `menu` VALUES (24,'Account','account/conf',11,17,1); +INSERT INTO `menu` VALUES (25,'Addresses','account/address-list',11,17,2); +INSERT INTO `menu` VALUES (26,'Shelves','reports/shelves',1,29,1); +INSERT INTO `menu` VALUES (28,'Visits','admin/visits',1,7,2); +INSERT INTO `menu` VALUES (29,'Reports',NULL,1,NULL,2); +INSERT INTO `menu` VALUES (30,'Items','admin/items',1,7,3); +INSERT INTO `menu` VALUES (31,'Pending orders','ecomerce/pending',11,2,1); + +INSERT INTO `message` VALUES (1,'ORDER_DATE_HOLIDAY','Orders for holidays are not possible'); +INSERT INTO `message` VALUES (2,'ORDER_EMPTY','The order is empty'); +INSERT INTO `message` VALUES (3,'ORDER_UNAVAILABLE','Some items are no longer available, please check the quantities highlighted in red'); +INSERT INTO `message` VALUES (4,'SURVEY_MAX_ONE_VOTE','Only one vote per survey is possible'); +INSERT INTO `message` VALUES (5,'ORDER_MAX_EXCEEDED','You have exceeded the maximum number of unconfirmed orders, please delete or confirm started orders'); +INSERT INTO `message` VALUES (6,'LOGIN_INCORRECT','Incorrect username or password. Case-sensitive.'); +INSERT INTO `message` VALUES (7,'ORDER_DATE_PAST','The order date must be today or later'); +INSERT INTO `message` VALUES (8,'ORDER_DATE_LAST','No more orders can be made for today, please postpone your order for tomorrow or later'); +INSERT INTO `message` VALUES (9,'ORDER_DATE_SUNDAY','Orders for Sunday cannot be confirmed'); +INSERT INTO `message` VALUES (10,'ORDER_DATE_SATURATED','We are overwhelmed with orders, please select another delivery or pick-up date'); +INSERT INTO `message` VALUES (11,'USER_DISCONNECTED','You have been disconnected from the server, please log in again'); +INSERT INTO `message` VALUES (12,'UNAUTH_ACTION','Action not allowed'); +INSERT INTO `message` VALUES (13,'ORDER_INVALID_AGENCY','The shipping agency is not valid'); +INSERT INTO `message` VALUES (14,'ORDER_EMPTY_ADDRESS','Please select a shipping address'); +INSERT INTO `message` VALUES (15,'ORDER_AMOUNT_ROUNDED','This item is sold in bundles, the quantity has been rounded'); +INSERT INTO `message` VALUES (17,'orderOutdated','The order configuration is incorrect, please reconfigure it to continue shopping'); +INSERT INTO `message` VALUES (18,'orderNotOwnedByUser','The order belongs to another user'); +INSERT INTO `message` VALUES (19,'orderConfirmed','The order has already been confirmed and cannot be modified'); +INSERT INTO `message` VALUES (20,'clientNotVerified','Incomplete tax data, please contact your sales representative'); +INSERT INTO `message` VALUES (21,'quantityLessThanMin','The quantity cannot be less than the minimum'); + +INSERT INTO `metatag` VALUES (2,'title','Verdnatura Levante SL, mayorista de flores, plantas y complementos para floristería y decoración'); +INSERT INTO `metatag` VALUES (3,'description','Verdnatura Levante SL, mayorista de flores, plantas y complementos para floristería y decoración. Envío a toda España, pedidos por internet o por teléfono.'); +INSERT INTO `metatag` VALUES (4,'keywords','verdnatura, mayorista, floristería, flores, verdes, plantas, ramos, complementos, artificial, natural, decoración, rosas, helecho, fern, clavel, lilium, orquídea, tulipan, crisantemo, cala, gerbera, hiedra, eucaliptus, cinerea, aralia'); +INSERT INTO `metatag` VALUES (6,'revisit-after','15 days'); +INSERT INTO `metatag` VALUES (7,'rating','general'); +INSERT INTO `metatag` VALUES (8,'author','Juan Ferrer Toribio'); +INSERT INTO `metatag` VALUES (9,'owner','Verdnatura Levante S.L.'); +INSERT INTO `metatag` VALUES (10,'robots','index, follow'); + +INSERT INTO `newsTag` VALUES ('course','Curso'); +INSERT INTO `newsTag` VALUES ('new','Noticia'); +INSERT INTO `newsTag` VALUES ('offer','Oferta'); + +INSERT INTO `restPriv` VALUES (1,'tpv/transaction',2); +INSERT INTO `restPriv` VALUES (3,'image/upload',1); +INSERT INTO `restPriv` VALUES (5,'user/supplant',104); +INSERT INTO `restPriv` VALUES (10,'misc/captcha',NULL); +INSERT INTO `restPriv` VALUES (11,'core/log',NULL); +INSERT INTO `restPriv` VALUES (14,'core/query',NULL); +INSERT INTO `restPriv` VALUES (15,'user/recover-password',NULL); +INSERT INTO `restPriv` VALUES (16,'user/restore-password',NULL); +INSERT INTO `restPriv` VALUES (17,'dms/invoice',2); +INSERT INTO `restPriv` VALUES (18,'image/thumb',NULL); +INSERT INTO `restPriv` VALUES (19,'misc/contact',NULL); +INSERT INTO `restPriv` VALUES (20,'misc/production',NULL); +INSERT INTO `restPriv` VALUES (21,'tpv/confirm-post',NULL); +INSERT INTO `restPriv` VALUES (22,'tpv/confirm-soap',NULL); +INSERT INTO `restPriv` VALUES (23,'client/supplant',18); +INSERT INTO `restPriv` VALUES (24,'client/supplant',35); +INSERT INTO `restPriv` VALUES (25,'user/logout',NULL); + +INSERT INTO `social` VALUES (1,'Blog','https://blog.verdnatura.es/','blog.svg',0); +INSERT INTO `social` VALUES (3,'Facebook','http://www.facebook.com/verdnatura','facebook.svg',2); +INSERT INTO `social` VALUES (4,'YouTube','http://www.youtube.com/user/verdnatura','youtube.svg',2); +INSERT INTO `social` VALUES (5,'Twitter','https://twitter.com/Verdnatura','twitter.svg',1); +INSERT INTO `social` VALUES (6,'Instagram','https://www.instagram.com/verdnatura','instagram.svg',2); +INSERT INTO `social` VALUES (7,'Linkedin','https://www.linkedin.com/company/verdnatura','linkedin.svg',1); +INSERT INTO `social` VALUES (8,'Pinterest','https://es.pinterest.com/verdnatura/','pinterest.svg',1); + +INSERT INTO `tpvError` VALUES ('SIS0007','Error al desmontar el XML de entrada'); +INSERT INTO `tpvError` VALUES ('SIS0008','Error falta Ds_Merchant_MerchantCode'); +INSERT INTO `tpvError` VALUES ('SIS0009','Error de formato en Ds_Merchant_MerchantCode'); +INSERT INTO `tpvError` VALUES ('SIS0010','Error falta Ds_Merchant_Terminal'); +INSERT INTO `tpvError` VALUES ('SIS0011','Error de formato en Ds_Merchant_Terminal'); +INSERT INTO `tpvError` VALUES ('SIS0014','Error de formato en Ds_Merchant_Order'); +INSERT INTO `tpvError` VALUES ('SIS0015','Error falta Ds_Merchant_Currency'); +INSERT INTO `tpvError` VALUES ('SIS0016','Error de formato en Ds_Merchant_Currency'); +INSERT INTO `tpvError` VALUES ('SIS0017','Error no se admite operaciones en pesetas'); +INSERT INTO `tpvError` VALUES ('SIS0018','Error falta Ds_Merchant_Amount'); +INSERT INTO `tpvError` VALUES ('SIS0019','Error de formato en Ds_Merchant_Amount'); +INSERT INTO `tpvError` VALUES ('SIS0020','Error falta Ds_Merchant_MerchantSignature'); +INSERT INTO `tpvError` VALUES ('SIS0021','Error la Ds_Merchant_MerchantSignature viene vacía'); +INSERT INTO `tpvError` VALUES ('SIS0022','Error de formato en Ds_Merchant_TransactionType'); +INSERT INTO `tpvError` VALUES ('SIS0023','Error Ds_Merchant_TransactionType desconocido'); +INSERT INTO `tpvError` VALUES ('SIS0024','Error Ds_Merchant_ConsumerLanguage tiene más de 3 posiciones'); +INSERT INTO `tpvError` VALUES ('SIS0026','Error No existe el comercio / terminal enviado'); +INSERT INTO `tpvError` VALUES ('SIS0027','Error Moneda enviada por el comercio es diferente a la que tiene asignada para ese terminal'); +INSERT INTO `tpvError` VALUES ('SIS0028','Error Comercio / terminal está dado de baja'); +INSERT INTO `tpvError` VALUES ('SIS0030','Error en un pago con tarjeta ha llegado un tipo de operación no valido'); +INSERT INTO `tpvError` VALUES ('SIS0031','Método de pago no definido'); +INSERT INTO `tpvError` VALUES ('SIS0034','Error de acceso a la Base de Datos'); +INSERT INTO `tpvError` VALUES ('SIS0038','Error en java'); +INSERT INTO `tpvError` VALUES ('SIS0040','Error el comercio / terminal no tiene ningún método de pago asignado'); +INSERT INTO `tpvError` VALUES ('SIS0041','Error en el cálculo de la firma de datos del comercio'); +INSERT INTO `tpvError` VALUES ('SIS0042','La firma enviada no es correcta'); +INSERT INTO `tpvError` VALUES ('SIS0046','El BIN de la tarjeta no está dado de alta'); +INSERT INTO `tpvError` VALUES ('SIS0051','Error número de pedido repetido'); +INSERT INTO `tpvError` VALUES ('SIS0054','Error no existe operación sobre la que realizar la devolución'); +INSERT INTO `tpvError` VALUES ('SIS0055','Error no existe más de un pago con el mismo número de pedido'); +INSERT INTO `tpvError` VALUES ('SIS0056','La operación sobre la que se desea devolver no está autorizada'); +INSERT INTO `tpvError` VALUES ('SIS0057','El importe a devolver supera el permitido'); +INSERT INTO `tpvError` VALUES ('SIS0058','Inconsistencia de datos, en la validación de una confirmación'); +INSERT INTO `tpvError` VALUES ('SIS0059','Error no existe operación sobre la que realizar la devolución'); +INSERT INTO `tpvError` VALUES ('SIS0060','Ya existe una confirmación asociada a la preautorización'); +INSERT INTO `tpvError` VALUES ('SIS0061','La preautorización sobre la que se desea confirmar no está autorizada'); +INSERT INTO `tpvError` VALUES ('SIS0062','El importe a confirmar supera el permitido'); +INSERT INTO `tpvError` VALUES ('SIS0063','Error. Número de tarjeta no disponible'); +INSERT INTO `tpvError` VALUES ('SIS0064','Error. El número de tarjeta no puede tener más de 19 posiciones'); +INSERT INTO `tpvError` VALUES ('SIS0065','Error. El número de tarjeta no es numérico'); +INSERT INTO `tpvError` VALUES ('SIS0066','Error. Mes de caducidad no disponible'); +INSERT INTO `tpvError` VALUES ('SIS0067','Error. El mes de la caducidad no es numérico'); +INSERT INTO `tpvError` VALUES ('SIS0068','Error. El mes de la caducidad no es válido'); +INSERT INTO `tpvError` VALUES ('SIS0069','Error. Año de caducidad no disponible'); +INSERT INTO `tpvError` VALUES ('SIS0070','Error. El Año de la caducidad no es numérico'); +INSERT INTO `tpvError` VALUES ('SIS0071','Tarjeta caducada'); +INSERT INTO `tpvError` VALUES ('SIS0072','Operación no anulable'); +INSERT INTO `tpvError` VALUES ('SIS0074','Error falta Ds_Merchant_Order'); +INSERT INTO `tpvError` VALUES ('SIS0075','Error el Ds_Merchant_Order tiene menos de 4 posiciones o más de 12'); +INSERT INTO `tpvError` VALUES ('SIS0076','Error el Ds_Merchant_Order no tiene las cuatro primeras posiciones numéricas'); +INSERT INTO `tpvError` VALUES ('SIS0078','Método de pago no disponible'); +INSERT INTO `tpvError` VALUES ('SIS0079','Error al realizar el pago con tarjeta'); +INSERT INTO `tpvError` VALUES ('SIS0081','La sesión es nueva, se han perdido los datos almacenados'); +INSERT INTO `tpvError` VALUES ('SIS0089','El valor de Ds_Merchant_ExpiryDate no ocupa 4 posiciones'); +INSERT INTO `tpvError` VALUES ('SIS0092','El valor de Ds_Merchant_ExpiryDate es nulo'); +INSERT INTO `tpvError` VALUES ('SIS0093','Tarjeta no encontrada en la tabla de rangos'); +INSERT INTO `tpvError` VALUES ('SIS0112','Error. El tipo de transacción especificado en Ds_Merchant_Transaction_Type no esta permitido'); +INSERT INTO `tpvError` VALUES ('SIS0115','Error no existe operación sobre la que realizar el pago de la cuota'); +INSERT INTO `tpvError` VALUES ('SIS0116','La operación sobre la que se desea pagar una cuota no es una operación válida'); +INSERT INTO `tpvError` VALUES ('SIS0117','La operación sobre la que se desea pagar una cuota no está autorizada'); +INSERT INTO `tpvError` VALUES ('SIS0118','Se ha excedido el importe total de las cuotas'); +INSERT INTO `tpvError` VALUES ('SIS0119','Valor del campo Ds_Merchant_DateFrecuency no válido'); +INSERT INTO `tpvError` VALUES ('SIS0120','Valor del campo Ds_Merchant_CargeExpiryDate no válido'); +INSERT INTO `tpvError` VALUES ('SIS0121','Valor del campo Ds_Merchant_SumTotal no válido'); +INSERT INTO `tpvError` VALUES ('SIS0122','Valor del campo Ds_merchant_DateFrecuency o Ds_Merchant_SumTotal tiene formato incorrecto'); +INSERT INTO `tpvError` VALUES ('SIS0123','Se ha excedido la fecha tope para realizar transacciones'); +INSERT INTO `tpvError` VALUES ('SIS0124','No ha transcurrido la frecuencia mínima en un pago recurrente sucesivo'); +INSERT INTO `tpvError` VALUES ('SIS0132','La fecha de Confirmación de Autorización no puede superar en más de 7 días a la de Preautorización'); +INSERT INTO `tpvError` VALUES ('SIS0139','Error el pago recurrente inicial está duplicado SIS0142 Tiempo excedido para el pago'); +INSERT INTO `tpvError` VALUES ('SIS0216','Error Ds_Merchant_CVV2 tiene mas de 3/4 posiciones'); +INSERT INTO `tpvError` VALUES ('SIS0217','Error de formato en Ds_Merchant_CVV2'); +INSERT INTO `tpvError` VALUES ('SIS0221','Error el CVV2 es obligatorio'); +INSERT INTO `tpvError` VALUES ('SIS0222','Ya existe una anulación asociada a la preautorización'); +INSERT INTO `tpvError` VALUES ('SIS0223','La preautorización que se desea anular no está autorizada'); +INSERT INTO `tpvError` VALUES ('SIS0225','Error no existe operación sobre la que realizar la anulación'); +INSERT INTO `tpvError` VALUES ('SIS0226','Inconsistencia de datos, en la validación de una anulación'); +INSERT INTO `tpvError` VALUES ('SIS0227','Valor del campo Ds_Merchan_TransactionDate no válido'); +INSERT INTO `tpvError` VALUES ('SIS0252','El comercio no permite el envío de tarjeta'); +INSERT INTO `tpvError` VALUES ('SIS0253','La tarjeta no cumple el check-digit'); +INSERT INTO `tpvError` VALUES ('SIS0261','Operación detenida por superar el control de restricciones en la entrada al SIS'); +INSERT INTO `tpvError` VALUES ('SIS0274','Tipo de operación desconocida o no permitida por esta entrada al SIS'); +INSERT INTO `tpvError` VALUES ('SIS9915','A petición del usuario se ha cancelado el pago'); + +INSERT INTO `tpvResponse` VALUES (101,'Tarjeta Caducada'); +INSERT INTO `tpvResponse` VALUES (102,'Tarjeta en excepción transitoria o bajo sospecha de fraude'); +INSERT INTO `tpvResponse` VALUES (104,'Operación no permitida para esa tarjeta o terminal'); +INSERT INTO `tpvResponse` VALUES (106,'Intentos de PIN excedidos'); +INSERT INTO `tpvResponse` VALUES (116,'Disponible Insuficiente'); +INSERT INTO `tpvResponse` VALUES (118,'Tarjeta no Registrada'); +INSERT INTO `tpvResponse` VALUES (125,'Tarjeta no efectiva'); +INSERT INTO `tpvResponse` VALUES (129,'Código de seguridad (CVV2/CVC2) incorrecto'); +INSERT INTO `tpvResponse` VALUES (180,'Tarjeta ajena al servicio'); +INSERT INTO `tpvResponse` VALUES (184,'Error en la autenticación del titular'); +INSERT INTO `tpvResponse` VALUES (190,'Denegación sin especificar motivo'); +INSERT INTO `tpvResponse` VALUES (191,'Fecha de caducidad errónea'); +INSERT INTO `tpvResponse` VALUES (202,'Tarjeta en excepción transitoria o bajo sospecha de fraude con retirada de tarjeta'); +INSERT INTO `tpvResponse` VALUES (904,'Comercio no registrado en FUC'); +INSERT INTO `tpvResponse` VALUES (909,'Error de sistema'); +INSERT INTO `tpvResponse` VALUES (912,'Emisor no Disponible'); +INSERT INTO `tpvResponse` VALUES (913,'Pedido repetido'); +INSERT INTO `tpvResponse` VALUES (944,'Sesión Incorrecta'); +INSERT INTO `tpvResponse` VALUES (950,'Operación de devolución no permitida'); +INSERT INTO `tpvResponse` VALUES (9064,'Número de posiciones de la tarjeta incorrecto'); +INSERT INTO `tpvResponse` VALUES (9078,'No existe método de pago válido para esa tarjeta'); +INSERT INTO `tpvResponse` VALUES (9093,'Tarjeta no existente'); +INSERT INTO `tpvResponse` VALUES (9094,'Rechazo servidores internacionales'); +INSERT INTO `tpvResponse` VALUES (9104,'A petición del usuario se ha cancelado el pago'); +INSERT INTO `tpvResponse` VALUES (9218,'El comercio no permite op. seguras por entrada /operaciones'); +INSERT INTO `tpvResponse` VALUES (9253,'Tarjeta no cumple el check-digit'); +INSERT INTO `tpvResponse` VALUES (9256,'El comercio no puede realizar preautorizaciones'); +INSERT INTO `tpvResponse` VALUES (9257,'Esta tarjeta no permite operativa de preautorizaciones'); +INSERT INTO `tpvResponse` VALUES (9261,'Operación detenida por superar el control de restricciones en la entrada al SIS'); +INSERT INTO `tpvResponse` VALUES (9912,'Emisor no Disponible'); +INSERT INTO `tpvResponse` VALUES (9913,'Error en la confirmación que el comercio envía al TPV Virtual (solo aplicable en la opción de sincronización SOAP)'); +INSERT INTO `tpvResponse` VALUES (9914,'Confirmación “KO” del comercio (solo aplicable en la opción de sincronización SOAP)'); +INSERT INTO `tpvResponse` VALUES (9915,'A petición del usuario se ha cancelado el pago'); +INSERT INTO `tpvResponse` VALUES (9928,'Anulación de autorización en diferido realizada por el SIS (proceso batch)'); +INSERT INTO `tpvResponse` VALUES (9929,'Anulación de autorización en diferido realizada por el comercio'); +INSERT INTO `tpvResponse` VALUES (9998,'Operación en proceso de solicitud de datos de tarjeta'); +INSERT INTO `tpvResponse` VALUES (9999,'Operación que ha sido redirigida al emisora autenticar'); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `sage`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +INSERT INTO `TiposIva` VALUES (2,0,'Operaciones no sujetas',0.0000000000,0.0000000000,0.0000000000,'','4770000020','','','','','','','95B21A93-5910-489D-83BB-C32788C9B19D','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (4,0,'I.V.A. 4%',0.0000000000,4.0000000000,0.0000000000,'4720000004','4770000004','','6310000000','','','','','9E6160D5-984E-4643-ACBC-1EBC3BF73360','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (5,0,'I.V.A. 4% y R.E. 0.5%',0.0000000000,4.0000000000,0.5000000000,'','4770000504','4770000405','','','','','','DBEFA562-63FB-4FFC-8171-64F0C6F065FF','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (6,0,'H.P. IVA 4% CEE',0.0000000000,4.0000000000,0.0000000000,'4721000004','4771000004','','','','','','','DD0ECBA8-2EF5-425E-911B-623580BADA77','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (7,0,'H.P. IVA 10% CEE',0.0000000000,10.0000000000,0.0000000000,'4721000011','4771000010','','','','','','','593208CD-6F28-4489-B6EC-907AD689EAC9','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (8,0,'H.P. IVA 21% CEE',0.0000000000,21.0000000000,0.0000000000,'4721000021','4771000021','','','','','','','27061852-9BC1-4C4F-9B6E-69970E208F23','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (10,0,'I.V.A. 10% Nacional',0.0000000000,10.0000000000,0.0000000000,'4720000011','4770000010','','6290000553','','','','','828A9D6F-5C01-4C3A-918A-B2E4482830D3','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (11,0,'I.V.A. 10% y R.E. 1,4%',0.0000000000,10.0000000000,1.4000000000,'','4770000101','4770000110','','','','','','C1F2D910-83A1-4191-A76C-8B3D7AB98348','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (16,0,'I.V.A. Adqui. servicios CEE',0.0000000000,21.0000000000,0.0000000000,'4721000015','4771000016','','','','','','','E3EDE961-CE8F-41D4-9E6C-D8BCD32275A1','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (18,0,'H.P. Iva Importación 0% ISP',0.0000000000,0.0000000000,0.0000000000,'4720000005','4770000005','','','','','','','27AD4158-2349-49C2-B53A-A4E0EFAC5D09','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (20,0,'I.V.A 0% Nacional',0.0000000000,0.0000000000,0.0000000000,'4720000000','','','','','','','','B90B0FBD-E513-4F04-9721-C873504E08DF','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (21,0,'I.V.A. 21%',0.0000000000,21.0000000000,0.0000000000,'4720000021','4770000021','4770000000','','','','','','BA8C4E28-DCFA-4F7B-AE4F-CA044626B55E','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (22,0,'IVA 10% importaciones',0.0000000000,10.0000000000,0.0000000000,'4722000010','','','','','','','','540450A8-4B41-4607-96D1-E7F296FB6933','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (26,0,'I.V.A. 21% y R.E. 5,2%',0.0000000000,21.0000000000,5.2000000000,'4720000021','4770000215','4770000521','631000000','','','','','2BC0765F-7739-49AE-A5F0-28B648B81677','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (90,0,'IVA 21% importaciones',0.0000000000,21.0000000000,0.0000000000,'4722000021','','','','','','','','EB675F91-5FF2-4E26-A31E-EEB674125945','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (91,0,'IVA 0% importaciones',0.0000000000,0.0000000000,0.0000000000,'4723000000','','','','','','','','5E5EFA56-2A99-4D54-A16B-5D818274CA18','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (92,0,'8.5% comp. ganadera o pesquera',0.0000000000,8.5000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (93,0,'12% com. agrícola o forestal',0.0000000000,12.0000000000,0.0000000000,'4720000012','','','','','','','','267B1DDB-247F-4A71-AB95-3349FEFC5F92','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (94,0,'10,5% com. ganadera o pesquera',0.0000000000,10.5000000000,0.0000000000,'4770000000','4720000000','631000000','477000000','','','','','','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (100,0,'HP IVA SOPORTADO 5%',0.0000000000,5.0000000000,0.0000000000,'4720000055','','','','','','','','3AD36CB2-4172-4CC9-9F87-2BF2B56AAC80','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (108,0,'I.V.A. 8%',0.0000000000,8.0000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (109,0,'I.V.A. 8% y R.E. 1%',0.0000000000,8.0000000000,1.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (110,0,'HP IVA Devengado Exento CEE',0.0000000000,0.0000000000,0.0000000000,'','4771000000','','','','','','','C605BC32-E161-42FD-83F3-3A66B1FBE399','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (111,0,'H.P. Iva Devengado Exento Ser',0.0000000000,0.0000000000,0.0000000000,'','4771000001','','','','','','','F1AEC4DC-AFE5-498E-A713-2648FFB6DA32','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (112,0,'H.P. IVA Devengado en exportac',0.0000000000,0.0000000000,0.0000000000,'','4770000002','','','','','','','F980AE74-BF75-4F4C-927F-0CCCE0DB8D15','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (113,0,'HP DEVENGADO 21 ISP ',0.0000000000,21.0000000000,0.0000000000,'4720000006','4770000006','','','','','','','728D7A76-E936-438C-AF05-3CA38FE16EA5','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (114,0,'HP.IVA NO DEDUCIBLE 10%',0.0000000000,0.0000000000,0.0000000000,'4720000026','','','','','','','','','','','','','','','','','',0); +INSERT INTO `TiposIva` VALUES (115,0,'H.P. IVA Soportado Impor 4% ',0.0000000000,4.0000000000,0.0000000000,'4722000004','','','','','','','','','','','','','','','','','',0); + +INSERT INTO `TiposTransacciones` VALUES (1,'Rég.general/Oper.interiores bienes y serv.corrien.','',0,''); +INSERT INTO `TiposTransacciones` VALUES (2,'Régimen especial de bienes usados','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (3,'Régimen especial de obj. de arte y antigüedades','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (4,'Régimen especial agencias de viaje','',0,''); +INSERT INTO `TiposTransacciones` VALUES (5,'Régimen especial determinación proporcional','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (6,'Oper.en rég.simplificado art.37.1.2º Rgto.IVA','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (7,'Oper.en rég.simplificado art.37.1.1º Rgto.IVA','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (8,'Oper.en rég.de agricultura, ganadería y pesca','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (9,'Oper.en rég.especial de recargo de equivalencia','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (10,'Entregas intracomunitarias','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (11,'Entregas intermediarias intracomunitarias','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (12,'Operaciones sujetas con derecho a devolución','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (13,'Prest. Serv. No sujetas derecho devolución','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (14,'Exportaciones definitivas','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (15,'Envíos definitivos a Canarias, Ceuta y Melilla','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (16,'Devoluciones en régimen de viajeros','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (17,'Operaciones con áreas exentas','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (18,'Operaciones exentas con derecho a deducción','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (19,'Operaciones exentas sin derecho a deducción','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (20,'Adquisic.intracomunitarias de bienes y serv.corr.','',-1,'P'); +INSERT INTO `TiposTransacciones` VALUES (21,'Adquisic.intracomunitarias de bienes de inversión','',-1,'P'); +INSERT INTO `TiposTransacciones` VALUES (22,'Adquisic.intermediarias intracomunitarias','',-1,'P'); +INSERT INTO `TiposTransacciones` VALUES (23,'Modif.autorizadas en quiebras y susp.de pagos','',0,''); +INSERT INTO `TiposTransacciones` VALUES (24,'Entrega de bienes inmuebles no habituales','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (25,'Entrega de bienes de inversión','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (26,'Op.finan. y Entregas oro inversión, no habituales','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (27,'Inversión sujeto pasivo','',-1,'I'); +INSERT INTO `TiposTransacciones` VALUES (28,'Prestaciones intracomunitarias de servicios','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (29,'Adquisiciones intracomunitarias de servicios','',-1,'I'); +INSERT INTO `TiposTransacciones` VALUES (30,'Operaciones interiores de bienes de inversión','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (31,'Importaciones de bienes y servicios corrientes','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (32,'Importaciones de bienes de inversión','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (33,'Operaciones que generan inversión sujeto pasivo','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (35,'Compensaciones en rég.de agricultura, gan.y pesca','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (36,'Regularización de inversiones','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (37,'Operaciones exentas','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (38,'Operaciones no sujetas','',0,''); +INSERT INTO `TiposTransacciones` VALUES (39,'Gastos devengados op interiores (País Vasco)','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (40,'Gastos Adq.intracom. bienes (País Vasco)','',-1,'P'); +INSERT INTO `TiposTransacciones` VALUES (42,'Gastos Adq.intermediarias intracom. (País Vasco)','',-1,'P'); +INSERT INTO `TiposTransacciones` VALUES (47,'Gastos Inversión sujeto pasivo (País Vasco)','',-1,'I'); +INSERT INTO `TiposTransacciones` VALUES (49,'Gastos Adq. intracom. servicios (País Vasco)','',-1,'I'); +INSERT INTO `TiposTransacciones` VALUES (51,'Gastos Importaciones (País Vasco)','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (53,'Adquisiciones a agencias de viajes en rég.especial','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (54,'Entregas intrac.posteriores a importaciones','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (55,'Entregas intrac.post.impor.con representante','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (56,'Import. bienes y serv. corrientes pdte. liquidar','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (57,'Import. bienes de inversión pdte. liquidar','R',0,''); +INSERT INTO `TiposTransacciones` VALUES (58,'Servicios prestados por Internet desde España','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (59,'Servicios prestados por Internet fuera de España','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (60,'Régimen depósito distinto al aduanero','',0,''); +INSERT INTO `TiposTransacciones` VALUES (61,'Adquisición de bienes de inversión con ISP','',-1,'I'); +INSERT INTO `TiposTransacciones` VALUES (62,'Prest. Serv. Interiores clientes comunit./extranj.','',0,''); +INSERT INTO `TiposTransacciones` VALUES (63,'Prest. Serv. Ex. con derecho a deducc. comu./extr.','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (64,'Prest. Serv. Ex. sin derecho a deducc. comu./extr.','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (65,'Entregas No sujetas derecho devolución','E',0,''); +INSERT INTO `TiposTransacciones` VALUES (66,'Operaciones exentas art. 25 ley 19/1994 (Canarias)','',0,''); +INSERT INTO `TiposTransacciones` VALUES (67,'Entrega de bienes exenta \"Zona Especial Canaria\"','',0,''); +INSERT INTO `TiposTransacciones` VALUES (68,'Prestac. servicios exenta \"Zona Especial Canaria\"','',0,''); + +INSERT INTO `TiposRetencion` VALUES (1,'RETENCION ESTIMACION OBJETIVA',1.0000000000,'4730000000','4751000000',NULL,NULL,NULL,'03811652-0F3A-44A1-AE1C-B19624525D7F'); +INSERT INTO `TiposRetencion` VALUES (2,'ACTIVIDADES AGRICOLAS O GANADERAS',2.0000000000,'4730000000','4751000000',NULL,NULL,NULL,'F3F91EF3-FED6-444D-B03C-75B639D13FB4'); +INSERT INTO `TiposRetencion` VALUES (9,'ACTIVIDADES PROFESIONALES 2 PRIMEROS AÑOS',9.0000000000,'4730000000','4751000000',NULL,NULL,NULL,'73F95642-E951-4C91-970A-60C503A4792B'); +INSERT INTO `TiposRetencion` VALUES (15,'ACTIVIDADES PROFESIONALES',15.0000000000,'4730000000','4751000000','6',NULL,NULL,'F6BDE0EE-3B01-4023-8FFF-A73AE9AC50D7'); +INSERT INTO `TiposRetencion` VALUES (19,'ARRENDAMIENTO Y SUBARRENDAMIENTO',19.0000000000,'4730000000','4751000000','8',NULL,NULL,'09B033AE-16E5-4057-8D4A-A7710C8A4FB9'); + +INSERT INTO `taxType` VALUES (2,'nonTaxable',0); +INSERT INTO `taxType` VALUES (4,'national4',0); +INSERT INTO `taxType` VALUES (5,NULL,0); +INSERT INTO `taxType` VALUES (6,NULL,1); +INSERT INTO `taxType` VALUES (7,NULL,1); +INSERT INTO `taxType` VALUES (8,NULL,1); +INSERT INTO `taxType` VALUES (10,'national10',0); +INSERT INTO `taxType` VALUES (11,NULL,0); +INSERT INTO `taxType` VALUES (16,'CEEServices21',1); +INSERT INTO `taxType` VALUES (18,NULL,0); +INSERT INTO `taxType` VALUES (20,'national0',0); +INSERT INTO `taxType` VALUES (21,'national21',0); +INSERT INTO `taxType` VALUES (22,'import10',0); +INSERT INTO `taxType` VALUES (26,NULL,0); +INSERT INTO `taxType` VALUES (90,'import21',0); +INSERT INTO `taxType` VALUES (91,NULL,0); +INSERT INTO `taxType` VALUES (92,NULL,0); +INSERT INTO `taxType` VALUES (93,NULL,0); +INSERT INTO `taxType` VALUES (94,NULL,0); +INSERT INTO `taxType` VALUES (100,NULL,0); +INSERT INTO `taxType` VALUES (108,NULL,0); +INSERT INTO `taxType` VALUES (109,NULL,0); +INSERT INTO `taxType` VALUES (110,NULL,1); +INSERT INTO `taxType` VALUES (111,NULL,0); +INSERT INTO `taxType` VALUES (112,NULL,0); +INSERT INTO `taxType` VALUES (113,'ISP21',0); +INSERT INTO `taxType` VALUES (114,NULL,0); +INSERT INTO `taxType` VALUES (115,'import4',0); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + diff --git a/db/dump/.dump/privileges.sql b/db/dump/.dump/privileges.sql new file mode 100644 index 000000000..b8abe322e --- /dev/null +++ b/db/dump/.dump/privileges.sql @@ -0,0 +1,1958 @@ +USE `mysql`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +/*!40000 ALTER TABLE `db` DISABLE KEYS */; +INSERT IGNORE INTO `db` VALUES ('','tmp','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','postgresql','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','util','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn2008','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','tmp','android','Y','Y','Y','Y','N','Y','N','N','N','N','Y','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','cache','salix','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','hedera','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','nst','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','postgresql','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','hedera','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','android','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','sage','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','pbx','android','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn','android','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','cache','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn2008','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','bi','android','Y','Y','Y','Y','N','Y','N','N','N','N','Y','Y','N','Y','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn2008','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','srt','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','psico','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','account','android','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','edi','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','stock','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','hedera','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','salix','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','account','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','edi','android','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','util','hedera-web','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn','hedera-web','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','Consumos','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vncontrol','android','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','salix','salix','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N'); +INSERT IGNORE INTO `db` VALUES ('','vn','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','Y','N','N'); +INSERT IGNORE INTO `db` VALUES ('','pbx','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','edi','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','bs','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','managedesktop','salix','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','account','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','Y','N','N'); +INSERT IGNORE INTO `db` VALUES ('','mysql','salix','Y','N','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','psico','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','geo','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','tmp','guest','Y','Y','Y','Y','N','Y','N','N','N','N','Y','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','util','salix','Y','Y','Y','Y','N','N','N','N','N','N','Y','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','dipole','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','bi','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','sage','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','bs','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','util','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','stock','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','salix','sysadmin','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','pbx','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','.mysqlworkbench','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','hedera','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','account','sysadmin','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','cache','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn2008','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','srt','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','sage','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','srt','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','psico','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','postgresql','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','edi','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn2008','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','vn','developerBoss','Y','Y','Y','Y','N','N','Y','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','edi','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','dipole','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','cache','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','bs','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','bi','developer','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','util','grafana','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N'); +INSERT IGNORE INTO `db` VALUES ('','mysql','developerBoss','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); +/*!40000 ALTER TABLE `db` ENABLE KEYS */; + +/*!40000 ALTER TABLE `tables_priv` DISABLE KEYS */; +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','itemTypeL10n','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','country','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','itemType','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myAddress','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select','Insert,Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','visitUser','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','producer','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','tagL10n','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','config','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','originL10n','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','origin','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','entryEditor','entry','guillermo@10.5.1.4','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','social','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','image','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','guest','tblContadores','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','logistic','item_track','alexm@db-proxy2.static.verdnatura.es','2022-08-03 23:44:43','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','administrative','value','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','administrative','type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','buyer','type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','buyer','value','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developerBoss','general_log','juan@10.5.1.1','0000-00-00 00:00:00','Select,Drop',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','dipole','employee','expedition_PrintOut','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','logistic','marketPlace','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','definitivo','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','manager','item_group','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','administrative','item_feature','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','buyer','item_feature','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','itemTag','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','itemCategoryL10n','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','guest','warehouse','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Vistas','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','guest','Tipos','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','producer','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','mdbVersion','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','province','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','versiones','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','mistakeType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','warehouse','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','account','itemTaxCountry','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','province','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myTpvTransaction','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myTicketState','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myTicketRow','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myTicket','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myOrderTicket','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myOrderRow','juan@db-proxy2.static.verdnatura.es','2022-08-03 23:44:43','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myOrder','juan@db-proxy2.static.verdnatura.es','2022-08-03 23:44:43','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myInvoice','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myClient','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myBasketItem','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myBasketDefaults','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','account','userPassword','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','mainAccountBank','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','itemCategory','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','psico','hr','answer','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','ticketDms','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','employee','ekt','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','sage','administrative','taxType','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','psico','hr','fellow','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','address_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','user','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','userPassword','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','roleRole','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','roleInherit','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','role','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','mailConfig','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','mailAliasAccount','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','mailAlias','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','accountConfig','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','employee','account','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','tpvMerchant','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','account','myUser','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','language','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','imageConfig','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','guest','Paises','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','guest','Tintas','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','item','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','agencyMode','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','inkL10n','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','ink','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','deliveryMethod','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','guest','reinos','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','collectionHotbed','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','mailForward','juan@db-proxy1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','location','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','mailAliasAccount','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','tag','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','news','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','buy_edi_k012','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','buy_edi_k012','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','myMenu','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','myBasket','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','message','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','guest','myUser','root@pc-juan.dyn.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','guest','myRole','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','followme','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','account','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','android','AccessToken','jenkins@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','itemTag','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemTag','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','buy_edi_k03','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','psico','hr','examQuestion','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','psico','hr','exam','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','manager','exchange','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','employee','supplier','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','dipole','employee','printer','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','manager','item_groupToOffer','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','dipole','coolerAssist','expedition_PrintOut','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','logistic','putOrder','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','logistic','supplyResponse','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','collectionWagonTicket','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','blacklist','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','cdr','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','queue','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','queueMember','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','queuePhone','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','schedule','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','employee','sip','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','browser','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','config','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','order','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select,Insert,Update,Delete','References'); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','orderRowComponent','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','imageCollection','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','orderRow','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','link','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','shelf','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','shelfConfig','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','order_row','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','order_component','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','visitAccess','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','visitAgent','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','visit','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','userSession','z-developer@172.16.255.16','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','collectionWagon','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','marketing','news','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','newsTag','z-developer@www1.static.verdnatura.es','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','sage','employee','TiposIva','z-sysadmin@172.16.255.30','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','sage','employee','TiposRetencion','z-sysadmin@172.16.255.30','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','sage','employee','TiposTransacciones','z-sysadmin@172.16.255.30','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','bank_account_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','salesPerson','item_groupToOffer','carlosap@172.16.5.232','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','account','myTicketService','root@10.2.3.180','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','sage','administrative','movConta','carlosap@172.16.5.232','2022-08-03 23:44:43','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','employee','mailConfig','jgallego@81.202.38.190','2022-08-03 23:44:43','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','account_conciliacion','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','accion_dits','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','config','juan@%','0000-00-00 00:00:00','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','util','account','config','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','transitoryDuaUnified','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','clientDied','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','userPassword','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','roleRole','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','roleInherit','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','role','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','mailConfig','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','hr','mailAlias','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','tables_priv','$itBoss@10.0.2.69','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','event','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','proxies_priv','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','procs_priv','$itBoss@10.5.1.5','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','db','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','columns_priv','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','time','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','slow_log','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','user','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','proc','$itBoss@10.0.2.68','2022-08-03 23:44:43','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','account_detail','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','account_detail_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','entryEditor','Compres','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Agencias','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','awb_component','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','developer','emailUser','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','agencia_descuadre','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','airline','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','airline','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','agency_warehouse','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','albaran','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vncontrol','salesPerson','inter','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Articles_botanical','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','albaran_gestdoc','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','albaran_state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Articles','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Articles_botanical','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','awb','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','awb','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb_component','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','awb_component','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb_component_template','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','awb_component_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','awb_gestdoc','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','awb_gestdoc','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','awb_recibida','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb_role','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb_unit','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financialBoss','balance_nest_tree','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vncontrol','deliveryBoss','inter','juan@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Bancos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','barcodes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','barcodes','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vncontrol','buyer','inter','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vncontrol','employee','inter','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb_gestdoc','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','agency','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','buySource','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','buy_edi','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','buy_edi_k04','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','buy_edi_k03','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','buy_edi_k04','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesAssistant','Clientes','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','v_empresa','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','v_empresa','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','chanel','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','v_empresa','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Clientes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','V_edi_item_track','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','v_compres','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionPlus','v_botanic_export','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','manager','v_botanic_export','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionPlus','v_Articles_botanical','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Colores','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Clientes','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','clientes_regalos_lista_enc','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','jerarquia','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','warehouse','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerBusinessAgreement','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','tarifa_componentes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','officeBoss','Vehiculos','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','tarifa_componentes_series','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','Entradas','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','cl_main','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','cl_main','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','producer','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','officeBoss','ticket_observation','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Cajas','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','cmrConfig','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hrBoss','awb_recibida','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hrBoss','awb','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Compres','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','workerDocument','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','buy_edi','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','ACL','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Vehiculos_consumo','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','palletizer','cmr','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','Colores','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Consignatarios','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','artificialBoss','travel','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','price_fixed','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','Vehiculos','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','printQueue','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','preservedBoss','travel','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','travel','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Cubos_Retorno','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Cubos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financialBoss','credit','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Cubos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Cubos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','Cubos_Retorno','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','artificialBoss','state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','travel','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Bancos_poliza','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','cmr','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','edi_bucket_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','edi_bucket','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','duaDismissed','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','edi_article','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','edi_bucket','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','edi_bucket_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','time','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','operator','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','payment','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','edi_supplier','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','edi_supplier','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','travel','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Tramos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Trabajadores','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','empresa','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','sectorType','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Tintas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','Movimientos','juan@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Entradas','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','ticket_observation','juan@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Entradas_dits','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','sale','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Entradas_orden','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','ticket_observation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Entradas_turno','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','entrySource','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Tickets_turno','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Tickets_turno','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionScan','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Tickets_state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','tickets_gestdoc','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hrBoss','tickets_gestdoc','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','tickets_gestdoc','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Tickets','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Entradas','root@localhost','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','expeditions','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Entradas','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Entradas','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Facturas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Facturas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','Tintas','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','filtros','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Entradas_kop','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','flight','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','warehouse_pickup','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','zones','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','warehouse_pickup','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','businessReasonEnd','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','businessCalendar','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','business','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','budgetNotes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','specialLabels','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','budgetDms','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','budget','juan@10.5.1.2','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','offerList','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','bookingPlanner','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','budgetInvoiceIn','juan@10.5.1.2','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','beach','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','business','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Movimientos_revisar','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Movimientos_mark','alexm@%','0000-00-00 00:00:00','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Movimientos_componentes','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Movimientos_componentes','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Movimientos','juan@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','handmadeBoss','Movimientos','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','Movimientos','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Movimientos','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Movimientos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Monedas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','calendarHolidays','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','mandato','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','mandato','alexm@%','0000-00-00 00:00:00','Select,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','iva_group','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','invoiceCorrection','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','intrastat_data','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','intrastat_data','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Intrastat','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Intrastat','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','integra2_province','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Grupos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Greuges','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','gesttip','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','gestdoc','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Gastos','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','artificialBoss','Movimientos_componentes','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Movimientos_componentes','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Movimientos_mark','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Movimientos_revisar','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','handmadeBoss','Reservas','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','bankEntity','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','bank','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Ordenes','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','bank','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','awb','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Origen','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','pago','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','awb','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Paises','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','salesAssistant','clientDied','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','warehouse_pickup','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','payroll_categorias','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','payroll_centros','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','payroll_conceptos','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','Tintas','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','alertLevel','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','bankEntity','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','payroll_employee','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','sale','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','bankEntity','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','agencyMode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Recibos','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','saleCloned','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','pay_met','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Permisos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','shelving','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemShelvingStock','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','palletizer','cmrConfig','carlosap@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Proveedores','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','PreciosEspeciales','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','agencia_descuadre','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','price_fixed','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','gestdoc','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','iva_tipo','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','iva_codigo','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','pago','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Proveedores','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Proveedores_cargueras','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Proveedores_gestdoc','juan@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','palletizer','Facturas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expedition','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Proveedores_gestdoc','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','claimManager','recibida','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','recibida','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','adminOfficer','recibida_iva','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','recibida_intrastat','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','recibida_iva','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','recibida_vencimiento','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesPerson','Recibos','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','officeBoss','bankEntity','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','agency','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','bankEntity','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','reference_min','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','reference_rate','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','saleComponent','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','Remesas','juan@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','Reservas','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','cmr','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Rutas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','address','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','Rutas_Master','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','Rutas_monitor','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','address','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','accountingType','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemShelvingStock_byWarehouse','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','Movimientos','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','Series','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','adminOfficer','Series','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','Recibos','alexm@%','0000-00-00 00:00:00','Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','price_fixed','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','accountingConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','buyer','salesByItemTypeDay','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesAssistant','state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','bufferState','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','coolerAssist','state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','absenceType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','artificialBoss','Entradas_Auto','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','XDiario','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionAssi','Vehiculos_consumo','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','employee','tblContadores','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','buyMark','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','calendar','juan@10.5.1.2','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','calendarHolidays','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','claim','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','claimEnd','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','claimRatio','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Cubos','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','cplusRectificationType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','cplusInvoiceType477','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','duaInvoiceIn','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','country','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','duaInvoiceIn','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','mandato_tipo','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','propertyNotes','juan@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','province','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','receipt','jgallego@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','receipt','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','grafana','visitUser','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','referenceRate','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','report','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','cache','productionBoss','available','guillermo@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','time','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','role','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','config__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','role','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','comparativeFilterType','guillermo@10.5.1.4','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','comparativeFilter','guillermo@10.5.1.4','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','route','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','company','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionStateType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','collectionHotbed','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','collectionColors','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','collection','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','cmr_list','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','collection','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','cmr','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','clientYoke','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','mysql','developer','roles_mapping','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketLastState','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionBoss','calendar','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','adminOfficer','pago','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','clientPhoneBook','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','saleGroupDetail','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','clientObservation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','clientObservation','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','productionConfig','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionBoss','sale','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','packingSite','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionPlus','province','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','productionPlus','province','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','property','juan@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','grafana','sip','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','clientCredit','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','artificialBoss','saleTracking','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','saleTracking','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','saleTracking','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','saleTracking','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','client','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','client','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','saleVolume','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Proveedores_gestdoc','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','awb_gestdoc','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','Cubos','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','routesMonitor','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','sale','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','sale','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Delete','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','sale','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Delete','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','sale','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','zoneClosure','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','saleComponent','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','saleComponent','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','marketingBoss','saleGoal','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','saleGroup','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','saleGroupDetail','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','account_detail','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','awb_component_type','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vncontrol','employee','accion','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','volumeConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','currency','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','tag','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','currency','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','creditClassification','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','creditInsurance','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','currency','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','dms','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerTimeControl','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','defaulter','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','deliveryMethod','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','deliveryMethod','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','dms','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','deviceProductionUser','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','department','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','deviceProductionConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','deviceProduction','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','deviceProduction','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionBoss','absenceType','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','deviceProductionConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','deviceProductionUser','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','disabilityGrade','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','dms','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','duaInvoiceIn','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','dmsType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','duaEntry','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','duaEntry','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','dua','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','duaIntrastat','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','duaInvoiceIn','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','duaTax','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Tickets_turno','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','cl_main','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','agency','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','ektEntryAssign','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionBoss','itemShelving','root@localhost','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','propertyDms','juan@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerTimeControlConfig','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','entry','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','businessType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','entryLog','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','projectState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','entrySplit__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','entryType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','projectNotes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','project','juan@10.5.1.1','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','productionConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','productionConfig','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','creditInsurance','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','cache','productionBoss','visible','guillermo@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','errorProduction__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','coolerAssist','Tickets','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','packingSite','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','accessTokenConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','printQueueArgs','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','printQueue','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','printer','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','expedition','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','sector','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppeLocation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','wks','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','entryObservation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','itemShelvingList','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','cmrConfig','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','expeditionTruck','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','alertLevel','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','expeditionSticker','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','artificialBoss','entryObservation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','dock','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','expeditionTruck','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','expeditionPallet','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','expense','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','expeditionScan','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','entryObservation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppeGroup','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','floramondoNotOfferDay__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','fuelType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppeDMS','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','genericAllocation','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppeComponent','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppe','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','glsExpedition__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','postCode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','pgcMaster','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemBarcode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemBarcode','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','host','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Facturas','guillermo@10.5.1.4','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticket','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceIn','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','invoiceIn','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','invoiceIn','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','inventoryFailure','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','intrastat','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','inventoryFailure','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','inventoryFailureCause','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceCorrection','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceCorrectionDataSource','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceCorrectionType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','invoiceIn','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceInDueDay','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','invoiceInDueDay','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','invoiceInIntrastat__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','invoiceInTax','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceInSage','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','invoiceInTax','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceInTax','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceOutExpense','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','item','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceOutSerial','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceOutTax','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','item','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','itemBarcode','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemBotanical','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemBotanicalWithGenus','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemCategory','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','pgcEqu','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','pgc','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','itemCost','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','itemConfig','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemConversor__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','itemCost','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','personalProtectionEquipment','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','payMethod','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','payment','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','payDem','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemPlacementSupplyList','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','itemPlacementSupplyList','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemPlacementSupply','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemPackingType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','itemPlacementSupply','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','itemPlacementSupplyList','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemPlacement__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','payDem','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemRepo__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemSearch','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemShelving','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','itemShelvingLog','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketWeekly','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','itemShelvingLog','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','airport','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemShelvingSale','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hrBoss','Tickets','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimEnd','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','itemTaxCountry','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workCenter','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','itemTaxCountry','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemTaxCountry','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','parking','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packingSiteLog','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','dua','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packingSite','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packagingWithoutFreight','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemVerdecora__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packagingWithFreight','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packagingGifts','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packagingConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packaging','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','packageEquivalentItem','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','packageEquivalent','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','packageChecked','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','packageChecked','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','packageChecked','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','operator','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','operator','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','mail','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Recibos','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','operator','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','mandate','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','occupationCode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','observationType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','defaultViewConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','medicalCenter','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','medicalReview','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','noticeSubscription','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','noticeSubscription','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','noticeCategory','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','noticeCategory','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','mrwServiceWeekday','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','mrw','alexm@%','0000-00-00 00:00:00','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','mrwService','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppePlan','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','accountingConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','buy','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','buy','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','saleGoal','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','packingSiteLog','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','component','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hrBoss','Entradas','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','saleComponent','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','arcRead','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','clientProtected','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','dua','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','duaEntry','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','expeditionTruck','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','moving','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','machineDetail','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','machineDms','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','vehicle','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','awb','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','machine','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','buy','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Entradas_dits','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerTimeControlMail','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','coolerBoss','rotacion','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','PreciosEspeciales','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','movingState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','bufferType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','bufferState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','vehicle','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','buffer','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','bufferGroup','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','lastRFID','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','person__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','config','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenance','expedition','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','travel','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','itemPicker','buy','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','logistic','Entradas_Auto','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','machine','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financialBoss','referenceCurrent','alexm@%','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','vehicleState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','vehicleEvent','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','cooler','Tintas','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','itemBotanical','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','cooler','Entradas','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','developer','signInLog','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketTracking','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','deviceProductionState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','deviceProductionState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vncontrol','hr','inter','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','printServerQueue2__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','printServerQueue__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','artificialBoss','buy','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Movimientos','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','buy','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','tarifas','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','receipt','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','producer','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','administrative','link','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','link','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','delivery','vehicle','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','upperStickers','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','province','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','till','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','recovery','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','photocell','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','supplyResponse','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','cache','customer','last_buy','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','financial','Greuges_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','invoiceInTax','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','workerTeam','juan@10.5.1.2','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','profile_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','profile_media','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','recovery','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','buffer','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','professional_category','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','media_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','media','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','labour_agreement','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','returnBuckets__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','journey','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','income_employee','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','incometype_employee','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hrBoss','income_employee','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','buyer','salesByWeek','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','routeGate__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','calendar_labour_type','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','adminBoss','XDiario_ALL','alexm@%','0000-00-00 00:00:00','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','rate','carlosap@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','expeditionState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','salesPerson','clientAnnualConsumption','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','buyer','tarifa_componentes_series','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','buyer','tarifa_componentes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','productionAssi','rutasBoard','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','logistic','rotacion','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','salesPerson','tarifa_componentes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','salesPerson','tarifa_componentes_series','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','expeditionLog','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','salesPerson','clientNewBorn','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','saleItemShelving__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesBoss','workerTeam','juan@10.5.1.2','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','expedition','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemShelvingStock','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','saleParking__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','property','juan@10.5.1.1','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','employee','config','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','vehicleEvent','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','vehicle','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','buyer','lastIndicators','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','saleComponent','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','itemBotanical','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','buyer','item','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','marketingBoss','salesPersonGoal','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hrBoss','journey','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','workerTimeControl','alexm@%','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','currentWorkersStats','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','ticketStateToday','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','shelving','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','shelving','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','shelving','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','supplierAccount','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','supplierAccount','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','supplierAccount','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','customer','supplier','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','state','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','state','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','stockBuyed','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','stowaway','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','supplier','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','supplierAccount','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','supplierAgencyTerm','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','supplierAgencyTerm','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','supplierExpense','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financialBoss','supplierExpense','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','marketingBoss','ticketService','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ticketService','jgallego@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','sendingServiceWeekday','jenkins@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','ticketRequest','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','ticketParking','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','taxCode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','taxArea','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','taxClass','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','taxCode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','taxCode','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','salesPersonEvolution','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','postgresql','hr','calendar_employee','juan@10.5.1.2','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','ticket','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticket','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketCollection','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','ticketDms','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ticketDocumentation','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketDms','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','ektEntryAssign','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','intrastat','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','supplierAgencyTerm','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','entryConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','franceExpressConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','ticketLog','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','ticketCollection','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','ticketDms','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketObservation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','ticketPackaging','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketPackaging','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','ticketParking','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketPackingList','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketParking','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketPreviousPreparingList','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ticketRefund','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketRequest','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','ticketService','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','ticketServiceType','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','ticketStateToday','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','employee','claims_ratio','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','greugeType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','time','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketWeekly','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','till','juan@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','account','town','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','time','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerMana','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','salesPerson','defaulters','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','customer','travel','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','train','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','train','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','trainingCenter','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','trainingCourse','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','trainingCourseType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','travel','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','travelClonedWeekly','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','employee','facturacion_media_anual','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','travelObservation','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','tarifas','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','travelThermograph','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','tillConfig','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','till','juan@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','till','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','vehicleState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','vehicleInvoiceIn','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','vehicleEvent','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','vehicleDms','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','vehicle','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','vehicle','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminBoss','vehicle','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyer','Agencias','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','vehicleDms','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketState','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','vehicleInvoiceIn','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financialBoss','vehicleNotes','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','vehicleState','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','volumeConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','ticketTrackingState','alexm@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','warehouse','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','role','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workCenter','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','clientCredit','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','worker','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','workerAppTester','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financial','propertyGroup','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','worker','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerBusinessType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','workerDepartment','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','workerDepartment','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerDepartment','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerConfig__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','inventoryDiscrepancyDetail','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','sendingConfig','jenkins@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','entryConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','ticketPackagingStartingStock','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','ticketPackagingStartingStock','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerIrpf','juan@%','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerJourney','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerLabour','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','workerMana','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','workerMana','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','ticketPackaging','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','ticketPackagingStartingStock','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','claimManager','entryConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','officeBoss','ticketPackagingStartingStock','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerRelatives','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','ticketPackagingStartingStock','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','supplierPackaging','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerDocument','alexm@%','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','gestdoc','alexm@%','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ink','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','zone','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','XDiario','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','workerTimeControlMail','alexm@%','0000-00-00 00:00:00','Select,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','workerTimeControl','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','financial','Greuge_Evolution','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','officeBoss','Greuge_Evolution','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','claimManager','rotacion','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','sale','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','zonePromo__','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','accountingConfig','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','accountingType','alexm@%','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','agencyMode','alexm@%','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','buyerBoss','XDiario','alexm@%','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','cache','employee','visible','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','productionConfig','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','cache','employee','available','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','logistic','ekt','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','ticketCollection','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','clientChain','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','VMPSettings','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimResponsible','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','packingSiteLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hrBoss','recibida','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','util','grafana','debug','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','myOrder','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','mdbVersion','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','clientLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','calendar','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','campaign','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketService','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','report','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','buyer','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','defaulter','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','componentType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','clientManaCache','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','invoiceIn','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','deliveryInformation','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','bufferType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','grafana','role','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','supplyOffer','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketStateToday','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','routeComplement','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','saleVolume','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','component','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','train','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','ticketPalletized','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','autonomy','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionMistakeType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketParking','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemShelving','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','state','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','taxClass','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','salesByWeek','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','invoiceInDueDay','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','sectorProductivity','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','salesByclientSalesPerson','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','marketPlace','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','routeAction','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deviceProduction','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','invoiceOut','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','printer','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','mdbBranch','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','workerProductivity','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','config','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','grafana','userSession','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','receipt','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','buy','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','calendarHolidays','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','parking','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','role','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','errorLogApp','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','continent','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','lastRFID','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','farmingInvoiceIn','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','agencyMode','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','absenceType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','saleGroupDetail','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerMistakeType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','mdbVersionTree','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionTruck','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','routeConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimReason','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','log','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','failureLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','clientNewBorn','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','farming','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','grafana','order','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','packingSpeed','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expense','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerLabour','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','grafana','orderRow','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','movingLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','warehouse','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','sector','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','salesPersonGoal','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','movingState','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimResult','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','routesMonitor','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionPallet','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','ventas','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','intrastat','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','printQueueArgs','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','grafana','Greuge_Evolution','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','host','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','country','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','waste','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketTracking','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemCategory','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','saleTracking','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','producer','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','cache','grafana','stock','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','account','grafana','user','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','','Select'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deliveryMethod','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketCollection','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','lastHourProduction','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','warehouseAlias','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','zoneClosure','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','origin','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','referenceCurrent','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','thermograph','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','dms','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','dmsType','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','greenhouseBoss','property','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketLastState','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','myAddress','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','tag','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemTag','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','route','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemPackingType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','expedition','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','zoneEstimatedDelivery','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','payMethod','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemCost','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','worker','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','travel','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','entry','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','department','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','grafana','rutasBoard','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','address','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerDistributionCategory','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','client','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','zone','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','packingSite','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemTaxCountry','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','workerLabourDataByMonth','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketPackaging','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','bufferFreeLength','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','salesByItemTypeDay','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','collection','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','project','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','inventoryDiscrepancy','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','ektSubAddress','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','buyer','item_track','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','buyer','putOrder','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerAssist','parking','juan@10.5.1.2','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','maintenance','machine','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','calendarType','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','glsExpedition','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','clientType','juan@10.5.1.2','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionMistake','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deviceProductionLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesAssistant','workerTeam','juan@10.5.1.2','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','salesBoss','workerTeam','juan@10.5.1.2','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','vehicleState','juan@10.5.1.1','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','machineDetail','juan@10.5.1.1','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','machineDms','juan@10.5.1.1','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerJourney','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','productionError','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','professionalCategory','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','mdbApp','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','glsConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','clientContact','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','collectionVolumetry','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','administrative','item','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','workerIncome','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','tagAbbreviation','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','chronopostConfig','jenkins@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','chronopostSenderAddress','jenkins@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','chronopostServiceWeekday','jenkins@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','chronopostExpedition','root@localhost','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','sectorCollection','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','sendingService','jenkins@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','adminOfficer','tickets_gestdoc','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','maintenanceBos','moving','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','routeAction','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','bankErrorCode','jgallego@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','farming','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','farmingDms','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','farmingNotes','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','farmingInvoiceIn','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionBoss','routesMonitor','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','routeCommission','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionState','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','warehouse','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimBeginning','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','invoicing','vehiclePlateRegex','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','businessSchedule','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','clientRisk','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','businessCalendar','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','employee','item','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','vehicleNotes','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','vehicleDms','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','palletizerBoss','expeditionTruck','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','palletizerBoss','zoneEvent','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','palletizerBoss','routesMonitor','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','propertyNotes','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','propertyDms','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','adminOfficer','payment','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','payment','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','taxType','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','guest','autonomy','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionPlus','autonomy','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','routePalletized','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logisticBoss','warehouse','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','m3','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Cajas','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','tagAbbreviation','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemImageQueue','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','marketingBoss','parking','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','sectorCollection','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','supplier','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','defaulter','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceInTaxBookingAccount','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','business','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','dock','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','item','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','clientAnnualConsumption','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','parking','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','bankEntityConfig','carlosap@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','shelving','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','duaEntry','juan@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','fieldAcl','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','module','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','printConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','url','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','salix','developer','userConfigView','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimRedelivery','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','clientRisk','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','itemType','carlosap@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','buyer','sale','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','chain','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','routesMonitor','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','warehouse_pickup','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','cl_main','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Vehiculos','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','routeAction','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','ticket_observation','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Tickets_turno','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','jerarquia','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Impresoras','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','autoRadioLogCall','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','autoRadioConfig','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Recibos','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Rutas','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Movimientos','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','state','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','route','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','routeComplement','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','deliveryMethod','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','Tickets','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','expeditionRoute_Monitor','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','expeditionScan','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','expeditionPallet','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','province','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','expeditionTruck','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','v_botanic_export','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','itemCost','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','deliveryAssistant','m3','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','ticketDms','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','time','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','deliveryAssistant','v_Articles_botanical','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','workCenter','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','workerDepartment','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','zoneEvent','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bi','deliveryAssistant','rotacion','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','agency','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','agencyMode','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','vehicle','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','vehicleEvent','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','postCode','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','deliveryAssistant','town','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','','Update'); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claim','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','clientType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','supplierAccount','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerDepartment','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','pbx','grafana','cdr','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerTimeControlConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','workerMistake','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','edi','grafana','putOrder','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','saleMistake','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deviceProductionUser','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','contactChannel','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','deviceLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','vehicle','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','packaging','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','workerProductivityConfig','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','antenna','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','cmr','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','accounting','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','creditClassification','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','moving','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimDevelopment','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','expeditionLog','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','bs','grafana','compradores_evolution','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','currency','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimObservation','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','salesPreviousPreparated','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimState','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','company','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','buffer','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','greuge','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +/*!40000 ALTER TABLE `tables_priv` ENABLE KEYS */; + +/*!40000 ALTER TABLE `columns_priv` DISABLE KEYS */; +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','mailConfig','port','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','mailConfig','secure','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','mailConfig','host','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','employee','user','active','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','employee','user','role','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','employee','user','nickname','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','employee','user','name','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','employee','user','id','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','userSession','created','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','userSession','lastUpdate','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','userSession','userVisitFk','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','order','id','2022-08-03 23:44:43','References'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','config','testRestUri','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','config','restUri','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','config','defaultLang','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','pbx','employee','sip','extension','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','employee','config','id','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','pbx','employee','sip','user_id','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','tpvMerchant','description','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','tpvMerchant','companyFk','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','tpvMerchant','id','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','account','myUser','nickname','2022-08-03 23:44:43','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','account','myUser','email','2022-08-03 23:44:43','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','account','myUser','lang','2022-08-03 23:44:43','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','isActive','2022-08-03 23:44:43','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','id','2022-08-03 23:44:43','Insert'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','provinceFk','2022-08-03 23:44:43','Insert,Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','nickname','2022-08-03 23:44:43','Insert,Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','street','2022-08-03 23:44:43','Insert,Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','clientFk','2022-08-03 23:44:43','Insert'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','city','2022-08-03 23:44:43','Insert,Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myAddress','postalCode','2022-08-03 23:44:43','Insert,Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myClient','defaultAddressFk','2022-08-03 23:44:43','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','account','myClient','isToBeMailed','2022-08-03 23:44:43','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','guest','imageConfig','url','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn2008','guest','Paises','Id','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn2008','guest','Paises','Pais','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn2008','guest','Tintas','Id_Tinta','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn2008','guest','Tintas','name','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn2008','guest','tblContadores','dbproduccion','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','guest','config','pdfsDir','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','guest','config','testDomain','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','guest','config','productionDomain','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','hedera','guest','config','defaultForm','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','guest','agencyMode','id','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','guest','agencyMode','deliveryMethodFk','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','guest','agencyMode','web','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','guest','agencyMode','agencyFk','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','guest','agencyMode','description','2022-08-03 23:44:43','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','guest','config','dbproduccion','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','role','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','email','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','pbx','grafana','sip','user_id','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','pbx','grafana','sip','extension','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','name','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','active','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','id','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','supplierFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','dated','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','invoiceNumber','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','isExcludedFromAvailable','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','notes','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','isConfirmed','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','isOrdered','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','isRaid','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','commission','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','created','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','evaNotes','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','travelFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','currencyFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','companyFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','gestDocFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','invoiceInFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','isBlocked','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','loadPriority','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','kop','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','sub','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','pro','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','auction','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','invoiceAmount','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','buyerFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','typeFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','reference','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','observationEditorFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','entry','clonedFrom','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','routeFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','name','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','beachFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','ticketPacked','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','ticketFree','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','ticketProduction','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','packages','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','note','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','dated','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','dockFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','m3','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','priority','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','etd','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','m3boxes','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','bufferFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','routesMonitor','isPickingAllowed','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','productionBoss','routesMonitor','expeditionTruckFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','id','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','account','grafana','user','nickname','0000-00-00 00:00:00','Select'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','id','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','itemFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','ticketFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','concept','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','quantity','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','originalQuantity','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','discount','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','reserved','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','isPicked','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','isPriceFixed','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','created','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','isAdded','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','total','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','sale','editorFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','id','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','itemFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','ticketFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','concept','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','quantity','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','originalQuantity','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','discount','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','reserved','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','isPicked','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','isPriceFixed','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','created','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','isAdded','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','total','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','editorFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','deliveryAssistant','postCode','code','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','deliveryAssistant','postCode','townFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','deliveryAssistant','town','provinceFk','0000-00-00 00:00:00','Update'); +/*!40000 ALTER TABLE `columns_priv` ENABLE KEYS */; + +/*!40000 ALTER TABLE `procs_priv` DISABLE KEYS */; +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','guest','myorder_getavailable','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','guest','myOrder_calcCatalogFull','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myOrder_checkConfig','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myOrder_calcCatalogFromItem','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myOrder_getTax','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','android','log_add','PROCEDURE','jenkins@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','employee','item_listAllocation','PROCEDURE','z-developer@www1.static.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','mytpvtransaction_end','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myticket_list','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myTicket_getServices','PROCEDURE','root@10.2.3.180','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myticket_getrows','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myticket_getpackages','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myTicket_get','PROCEDURE','z-sysadmin@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myorder_confirm','PROCEDURE','juan@10.5.1.2','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myorder_additem','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','guest','myOrder_configureForGuest','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myOrder_create','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','grafana','zone_getaddresses','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','catalog_calcfrommyaddress','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','ext','buy_scan','PROCEDURE','juan@swarm-worker2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_loginWithKey','PROCEDURE','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_login','PROCEDURE','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_hasRole','FUNCTION','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_getName','FUNCTION','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_getId','FUNCTION','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','palletizerBoss','midnight','FUNCTION','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','account','myUser_logout','PROCEDURE','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','entryEditor','getinventoryDate','FUNCTION','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','grafana','zone_upcomingdeliveries','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','android','vn_now','FUNCTION','jenkins@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','entryEditor','entry_unlock','PROCEDURE','guillermo@10.5.1.4','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','agency','agencia_volume','PROCEDURE','root@10.1.4.166','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','account','zone_getAgency','PROCEDURE','juan@77.228.249.89','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','account','invoiceout_getpath','FUNCTION','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','employee','order_confirm','PROCEDURE','z-developer@www1.static.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myTpvTransaction_start','PROCEDURE','juan@77.227.99.220','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myticket_logaccess','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myorder_newwithdate','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myorder_newwithaddress','PROCEDURE','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myclient_getdebt','FUNCTION','root@pc-juan.dyn.verdnatura.es','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','hedera','account','myOrder_configure','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_hasRoleId','FUNCTION','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myUser_checkLogin','FUNCTION','jenkins@172.16.255.34','Execute','2022-08-03 23:44:43'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','lang','FUNCTION','juan@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','grafana','firstdayofmonth','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','financial','account_conciliacion_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','logistic','add_awb_component','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','buy_getVolumeByEntry','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','productionAssi','agencyModeImbalance','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','buy_getVolumeByEntry','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','entry_moveNotPrinted','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','buy_getVolume','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','stockbuyedbyworker','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','buy_getsplit','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','subordinategetlist','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','buy_afterUpsert','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','grafana','dayend','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','production','buffer_settypebyname','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','buyUltimate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','financialBoss','balance_create','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','buyUltimate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','employee','base_ticket','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','barcodeToItem','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticket_splititempackingtype','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','entry_getCommission','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','deliveryAssistant','expeditionstate_addbypallet','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','buy_tarifas_entry','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','entryEditor','buy_tarifas','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','claimManager','buy_tarifas_entry','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','mail_insert','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','entry_fixMisfit','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','employee','buy_tarifas_entry','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_CURDATE','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','financial','calculoremesas','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','hr','cc_to_iban','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','financial','cc_to_iban','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','marketingBoss','clientTaxArea','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','clientTaxArea','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','client_checkBalance','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','addressTaxArea','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesPerson','client_getSalesPersonByTicket','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','handmadeBoss','confection_control_source','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','travelDetail','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','claimManager','traslado','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','traslado','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','administrative','supplierStatement','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','supplierStatement','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','hrBoss','supplierStatement','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','hrBoss','red','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','salesPerson','red','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','administrative','intrastat_neto','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','productionAssi','confection_control_source','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','artificialBoss','confection_control_source','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','logistic','nz','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','deliveryAssistant','preordenarruta','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','financial','pay','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','bi','salesAssistant','defaultersFromDate','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','buy_updatepacking','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','buy_updategrouping','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','item_comparative','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','logistic','calculoremesas','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','entryEditor','item_getVolume','FUNCTION','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','clientgetmana','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','buy_scan','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','client_getSalesPersonByTicket','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','client_create','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','entryEditor','entry_isintrastat','FUNCTION','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','manager','collection_make','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','android','debugadd','PROCEDURE','jenkins@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','copyComponentsFromSaleList','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','duaEntryValueUpdate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','duaInvoiceInBooking','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelvinglog_get','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expedition_getstate','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','production','expedition_scan','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','historico_absoluto','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','historico_multiple','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','client_getDebt','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','logistic','f10_no_vincular','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','hrBoss','balance_create','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','cooler','buyultimate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','grafana','firstdayofyear','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','officeBoss','fustcontrol','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','claimManager','dayend','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','employee','log_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','employee','moving_between','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','bi','financial','defaultersfromdate','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','getuser','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','hasanynegativebase','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','marketingBoss','hasanynegativebase','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','hassomenegativebase','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','administrative','accountshorttostandard','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','logistic','raidupdate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','grafana','lastdayofweek','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','artificialBoss','raidupdate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','adminBoss','nest_delete','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','marketingBoss','invoicefromclient','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoicefromclient','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoicefromticket','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoiceindueday_calculate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','invoiceindueday_calculate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','entry_splitbyshelving','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoiceintaxmakebydua','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','invoiceintax_getfromentries','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoiceintax_getfromentries','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','adminBoss','nest_child_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','marketingBoss','invoiceoutbooking','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoiceoutbooking','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','clienttaxarea','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_add','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','invoicefromclient','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','hasanynegativebase','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','invoiceserial','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoiceserial','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_CURTIME','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','duaTaxBooking','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','adminBoss','invoiceout_newfromclient','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoiceout_newfromticket','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','marketingBoss','invoiceserial','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','clientgetmana','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','packingsite_startcollection','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','invoiceoutbooking','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','ticket_gettax','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','productionAssi','midnight','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','dipole','employee','expedition_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticketstateupdate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerBoss','itempacking','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesPerson','ticket_clone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','cache','employee','available_refresh','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','ticket_clone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerBoss','ticket_clone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','itemproposal','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','itemproposal_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','timebusiness_calculatebyuser','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','itemsale_byweek','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','itemsale_byweek','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','timecontrol_calculatebyuser','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','ticket_clone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','timecontrol_calculateall','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','manager','midnight','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','timebusiness_calculateall','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','cache','buyer','last_buy_refresh','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','supplierpackaging_reportsource','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','cache','buyer','stock_refresh','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','itemshelvingproblem','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','itemshelvingradar','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','cache','employee','visible_refresh','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','grafana','quarterfirstday','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','workertimecontrol_sendmailbydepartment','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','agency','item_getStock','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','employee','debugadd','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','buyer','dayend','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','invoiceindueday_calculate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','invoiceintax_getfromentries','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_get','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','zone_getstate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','worker_gethierarchy','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','workertimecontrol_weekcheckbreak','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','ticket_split','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','add_awb_component','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','saletracking_new','PROCEDURE','alexm@pc325.algemesi.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','ticketnotinvoicedbyclient','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerBoss','workerjourney_replace','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','artificialBoss','workerjourney_replace','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','workerjourney_replace','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','item_getinfo','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','item_getlack','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','workerjourney_replace','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','item_getpackage','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','workerdisable','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','client_getDebt','FUNCTION','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','developer','ticket_add','PROCEDURE','jenkins@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','workercalendar_calculateyear','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','workercalendar_calculatebusiness','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticketparking_findskipped','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticketcollection_getnopacked','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','supplier_checkbalance','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','item_valuateinventory','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','ledger_docompensation','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','ledger_next','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','invoicein_booking','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','supplierpackaging_reportsource','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','logshow','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyerBoss','supplierpackaging_reportsource','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','financialBoss','supplierexpenses','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','grafana','firstdayofweek','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','stockbuyed_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','mail_insert','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','duaParcialMake','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','palletizerBoss','packingsite_startcollection','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','sale_calculatecomponent','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesPerson','manaspellersrequery','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','adminBoss','packageinvoicing','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','packinglistswitch','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','previoussticker_get','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','productioncontrol','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','productionsectorlist','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','financialBoss','riskallclients','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','routemonitor_calculate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','developer','user_haspriv','FUNCTION','jgallego@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','salegroup_add','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','salepreparinglist','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','zone_getLanded','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','saletracking_del','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','manager','ekt_getEntry','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','duaTax_doRecalc','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticketGetTotal','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','adminBoss','tickettoinvoicebyaddress','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','ticket_canmerge','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','tickettotalvolume','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','tickettotalvolumeboxes','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','subordinategetlist','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','entry_clone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myuser_haspriv','FUNCTION','jgallego@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerAssist','ticket_canmerge','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','ticket_cloneweekly','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','ticket_closebyticket','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','ticket_getfromfloramondo','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticket_get','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','artificialBoss','ticket_getfromfloramondo','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','administrative','ticket_getfromfloramondo','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','ticket_getsplitlist','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','adminBoss','ticket_gettax','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','entryEditor','entry_lock','PROCEDURE','guillermo@10.5.1.4','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','developerBoss','role_syncPrivileges','PROCEDURE','juan@10.5.1.1','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','ticket_recalccomponents','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','entryDelivered','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerBoss','ticket_splitpackingcomplete','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','guest','myuser_hasroutinepriv','FUNCTION','jgallego@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','productionAssi','timebusiness_calculateall','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','timecontrol_geterror','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','logistic','travel_weeklyclone','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','workerTimeControl_add','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','coolerAssist','itemproposal','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','financial','company_getsuppliersdebt','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','agency','desglose_volume','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','bi','productionAssi','rutasanalyze','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','productionPlus','workerCreateExternal','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','adminBoss','XDiario_Quadrator','PROCEDURE','juan@10.5.1.2','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_NOW','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_UNIX_TIMESTAMP','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_UTC_DATE','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_UTC_TIME','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_UTC_TIMESTAMP','FUNCTION','juan@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_getsaledate','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','ticket_setState','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','invoicing','invoiceout_new','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','palletizer','ticket_setState','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','ledger_next','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','deliveryAssistant','workerjourney_replace','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','developerBoss','role_sync','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','deliveryAssistant','ticket_weightdeclaration','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','clientPackagingOverstock','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','salesAssistant','clientPackagingOverstockReturn','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_filterbuyer','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','deliveryAssistant','dayend','FUNCTION','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','deliveryAssistant','routeproposal','FUNCTION','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','developer','user_hasroutinepriv','FUNCTION','jgallego@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','account','grafana','user_hasRole','FUNCTION','jgallego@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','time_generate','PROCEDURE','jenkins@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_addbyclaim','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelvingtransfer','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_addlist','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_selfconsumption','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','item_getsimilar','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelvingsale_add','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','collection_printsticker','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','deviceproductionuser_getworker','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','ticket_printlabelprevious','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','ticket_isoutclosurezone','FUNCTION','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','workermachinery_isregistered','FUNCTION','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','ticketstatetoday_setstate','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','device_checklogin','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','worker_getfromhasmistake','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','sectorcollection_new','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','sectorcollection_get','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','setparking','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','shelvingparking_get','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','machine_getworkerplate','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','saletracking_addprevok','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','sectorcollectionsalegroup_add','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','saletracking_updateischecked','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','saletracking_addpreparedsalegroup','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','travel_updatepacking','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','freelance_getinfo','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','company_getfiscaldata','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expedition_getfromroute','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','machineworker_gethistorical','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemplacementsupplyaiming','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionstate_addbypallet','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','production','expeditionloading_add','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionpallet_list','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionpallet_printlabel','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionpallet_view','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionscan_add','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionscan_list','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expeditionscan_put','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','cmrpallet_add','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemtrash','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','item_getbalance','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','expedition_checkroute','FUNCTION','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','addnotefromdelivery','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','client_getSalesPerson','FUNCTION','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','buy_updatepacking','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','buy_updategrouping','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','delivery','buffer_settypebyname','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expedition_getstate','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','delivery','expedition_scan','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_get','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelvinglog_get','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_add','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_getsaledate','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_filterbuyer','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_addbyclaim','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelvingtransfer','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_addlist','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelving_selfconsumption','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','item_getsimilar','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemshelvingsale_add','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','collection_printsticker','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','deviceproductionuser_getworker','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','ticket_printlabelprevious','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','ticket_isoutclosurezone','FUNCTION','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','workermachinery_isregistered','FUNCTION','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','ticketstatetoday_setstate','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','device_checklogin','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','worker_getfromhasmistake','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','sectorcollection_new','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','sectorcollection_get','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','setparking','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','shelvingparking_get','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','machine_getworkerplate','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','saletracking_addprevok','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','sectorcollectionsalegroup_add','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','saletracking_updateischecked','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','saletracking_addpreparedsalegroup','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','travel_updatepacking','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','freelance_getinfo','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','company_getfiscaldata','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expedition_getfromroute','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','machineworker_gethistorical','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemplacementsupplyaiming','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionstate_addbypallet','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','srt','delivery','expeditionloading_add','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionpallet_list','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionpallet_printlabel','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionpallet_view','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionscan_add','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionscan_list','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expeditionscan_put','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','cmrpallet_add','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemtrash','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','item_getbalance','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','expedition_checkroute','FUNCTION','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','addnotefromdelivery','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemShelving_getinfo','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemShelving_getinfo','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','collection_get','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','item_comparative','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','sale_getBoxPickingList','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +/*!40000 ALTER TABLE `procs_priv` ENABLE KEYS */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +USE `mysql`; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +/*!40000 ALTER TABLE `global_priv` DISABLE KEYS */; +INSERT IGNORE INTO `global_priv` VALUES ('','account','{\"access\": 0, \"is_role\": true,\"version_id\":100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','adminBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','adminOfficer','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','administrative','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','agency','{\"access\": 0, \"max_questions\": 40000, \"max_updates\": 1000, \"max_connections\": 20000, \"max_user_connections\": 50, \"max_statement_time\": 0.000000, \"is_role\": true,\"version_id\":100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','android','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','artificialBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','assetManager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','buyer','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','buyerBoss','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','claimManager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','cooler','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','coolerAssist','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','coolerBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','customer','{\"access\": 0, \"max_questions\": 0, \"max_updates\": 30000, \"max_connections\": 300000, \"max_user_connections\": 400, \"max_statement_time\": 0.000000, \"is_role\": true,\"version_id\":100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','delivery','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','deliveryAssistant','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','deliveryBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','developer','{\"access\": 5909905728, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','developerBoss','{\"access\":33554432,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','employee','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','entryEditor','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','ext','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','financial','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','financialBoss','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','grafana','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','greenhouseBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','guest','{\"access\": 0, \"max_questions\": 40000, \"max_updates\": 1000, \"max_connections\": 150000, \"max_user_connections\": 200, \"max_statement_time\": 0.000000, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','handmadeBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','hedera-web','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','hr','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','hrBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','invoicing','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','itBoss','{\"access\": 541165846527, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','itManagement','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','itemPicker','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','logistic','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','logisticBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','maintenance','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','maintenanceBos','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','maintenanceBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','manager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','marketing','{\"access\": 0, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','marketingBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','officeBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','packager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','palletizer','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','palletizerBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','preservedBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','production','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','productionAssi','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','productionBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','productionPlus','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','root','{\"access\": 549755781119, \"version_id\": 100705, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','salesAssistant','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','salesBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','salesPerson','{\"access\": 0, \"is_role\": true,\"version_id\":100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','salesTeamBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','salix','{\"access\":33555456,\"version_id\":100707,\"is_role\":true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','sysadmin','{\"access\": 201326592, \"is_role\": true, \"version_id\": 100707}'); +/*!40000 ALTER TABLE `global_priv` ENABLE KEYS */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + diff --git a/db/dump/structure.sql b/db/dump/.dump/structure.sql similarity index 74% rename from db/dump/structure.sql rename to db/dump/.dump/structure.sql index 694f745ef..2b75f4369 100644 --- a/db/dump/structure.sql +++ b/db/dump/.dump/structure.sql @@ -1,6 +1,6 @@ --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.5.21-MariaDB, for debian-linux-gnu (x86_64) -- --- Host: db2.static.verdnatura.es Database: account +-- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ -- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log @@ -39,94 +39,6 @@ CREATE TABLE `account` ( CONSTRAINT `account_ibfk_3` FOREIGN KEY (`id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Users allowed to have an account'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_beforeInsert` - BEFORE INSERT ON `account` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_afterInsert` - AFTER INSERT ON `account` - FOR EACH ROW -BEGIN - INSERT IGNORE INTO userSync (`name`) - SELECT `name` FROM `user` WHERE 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_beforeUpdate` - BEFORE UPDATE ON `account` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_afterDelete` - AFTER DELETE ON `account` - FOR EACH ROW -BEGIN - INSERT INTO userLog - SET `action` = 'delete', - `changedModel` = 'Account', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - INSERT IGNORE INTO userSync (`name`) - SELECT `name` FROM `user` WHERE id = 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 `accountConfig` @@ -145,7 +57,7 @@ CREATE TABLE `accountConfig` ( `warn` smallint(6) NOT NULL COMMENT 'Warn to change password when elapsed (seconds)', `inact` smallint(6) NOT NULL COMMENT 'Maximum inactivity time (seconds)', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters for accounts'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters for accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -208,7 +120,7 @@ CREATE TABLE `ldapConfig` ( `userDn` varchar(255) DEFAULT NULL COMMENT 'The base DN for users', `groupDn` varchar(255) DEFAULT NULL COMMENT 'The base DN for groups', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='LDAP server configuration parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='LDAP server configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -228,72 +140,8 @@ CREATE TABLE `mailAlias` ( UNIQUE KEY `alias` (`alias`), KEY `mailAlias_fk_editor` (`editorFk`), CONSTRAINT `mailAlias_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Mail aliases'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Mail aliases'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailAlias_beforeInsert` - BEFORE INSERT ON `mailAlias` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailAlias_beforeUpdate` - BEFORE UPDATE ON `mailAlias` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailAlias_afterDelete` - AFTER DELETE ON `mailAlias` - FOR EACH ROW -BEGIN - INSERT INTO userLog - SET `action` = 'delete', - `changedModel` = 'MailAlias', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `mailAliasAccount` @@ -311,7 +159,7 @@ CREATE TABLE `mailAliasAccount` ( KEY `account` (`account`), CONSTRAINT `account` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `mailAlias` FOREIGN KEY (`mailAlias`) REFERENCES `mailAlias` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Mail alias that is assigned to each account'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Mail alias that is assigned to each account'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -328,7 +176,7 @@ CREATE TABLE `mailClientAccess__` ( `description` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mailFrom` (`client`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='@deprecated 2023-09-03'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='@deprecated 2023-09-03'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -342,7 +190,7 @@ CREATE TABLE `mailConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `domain` varchar(255) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -362,70 +210,6 @@ CREATE TABLE `mailForward` ( CONSTRAINT `mailForward_ibfk_1` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Mail forwarding'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailForward_beforeInsert` - BEFORE INSERT ON `mailForward` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailForward_beforeUpdate` - BEFORE UPDATE ON `mailForward` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailForward_afterDelete` - AFTER DELETE ON `mailForward` - FOR EACH ROW -BEGIN - INSERT INTO userLog - SET `action` = 'delete', - `changedModel` = 'MailForward', - `changedModelId` = OLD.account, - `userFk` = account.myUser_getId(); -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 `mailSenderAccess__` @@ -441,7 +225,7 @@ CREATE TABLE `mailSenderAccess__` ( `description` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mailFrom` (`sender`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='@deprecated 2023-09-03'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='@deprecated 2023-09-03'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -494,76 +278,8 @@ CREATE TABLE `role` ( UNIQUE KEY `name` (`name`), KEY `role_fk_editor` (`editorFk`), CONSTRAINT `role_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Roles'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Roles'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`role_beforeInsert` - BEFORE INSERT ON `role` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - CALL role_checkName(NEW.`name`); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`role_beforeUpdate` - BEFORE UPDATE ON `role` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - IF !(NEW.`name` <=> OLD.`name`) THEN - CALL role_checkName (NEW.`name`); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`role_afterDelete` - AFTER DELETE ON `role` - FOR EACH ROW -BEGIN - INSERT INTO roleLog - SET `action` = 'delete', - `changedModel` = 'Role', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `roleConfig` @@ -580,7 +296,7 @@ CREATE TABLE `roleConfig` ( `userHost` varchar(255) NOT NULL, `tplUser` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Role configuration parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Role configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -602,72 +318,8 @@ CREATE TABLE `roleInherit` ( CONSTRAINT `roleInherit_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `user` (`id`), CONSTRAINT `roleInherit_ibfk_1` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `roleInherit_ibfk_2` FOREIGN KEY (`inheritsFrom`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Role inheritance'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Role inheritance'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`roleInherit_beforeInsert` - BEFORE INSERT ON `roleInherit` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`roleInherit_beforeUpdate` - BEFORE UPDATE ON `roleInherit` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`roleInherit_afterDelete` - AFTER DELETE ON `roleInherit` - FOR EACH ROW -BEGIN - INSERT INTO roleLog - SET `action` = 'delete', - `changedModel` = 'RoleInherit', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `roleLog` @@ -694,7 +346,7 @@ CREATE TABLE `roleLog` ( KEY `roleLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `roleLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `roleLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -710,7 +362,7 @@ CREATE TABLE `roleRole` ( `inheritsFrom` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `role` (`role`,`inheritsFrom`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Calculated role inheritance'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Calculated role inheritance'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -729,7 +381,7 @@ CREATE TABLE `sambaConfig` ( `verifyCert` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT 'Whether to verify server certificate', `userDn` varchar(255) NOT NULL COMMENT 'Base DN for users without domain DN part', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters for accounts'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters for accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -744,11 +396,13 @@ CREATE TABLE `signInLog` ( `token` varchar(255) NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, `creationDate` timestamp NULL DEFAULT current_timestamp(), + `userName` varchar(30) NOT NULL, `ip` varchar(100) NOT NULL, + `owner` tinyint(1) DEFAULT 1, PRIMARY KEY (`id`), KEY `userFk` (`userFk`), CONSTRAINT `signInLog_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -792,142 +446,8 @@ CREATE TABLE `user` ( KEY `user_fk_editor` (`editorFk`), CONSTRAINT `user_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `user` (`id`), CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global users'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_beforeInsert` - BEFORE INSERT ON `user` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - CALL user_checkName(NEW.`name`); - - IF NEW.nickname = '' THEN - SET NEW.nickname = NEW.`name`; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_afterInsert` - AFTER INSERT ON `user` - FOR EACH ROW -BEGIN - CALL hedera.image_ref('user', NEW.image); - - INSERT IGNORE INTO userSync SET `name` = NEW.`name`; -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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_beforeUpdate` - BEFORE UPDATE ON `user` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF !(NEW.`name` <=> OLD.`name`) THEN - CALL user_checkName (NEW.`name`); - END IF; - - IF !(NEW.`password` <=> OLD.`password`) THEN - SET NEW.lastPassChange = util.VN_NOW(); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_afterUpdate` - AFTER UPDATE ON `user` - FOR EACH ROW -BEGIN - IF !(NEW.image <=> OLD.image) THEN - CALL hedera.image_unref('user', OLD.image); - CALL hedera.image_ref('user', NEW.image); - END IF; - - INSERT IGNORE INTO userSync SET `name` = NEW.`name`; - - IF !(OLD.`name` <=> NEW.`name`) THEN - INSERT IGNORE INTO userSync SET `name` = OLD.`name`; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_afterDelete` - AFTER DELETE ON `user` - FOR EACH ROW -BEGIN - INSERT INTO userLog - SET `action` = 'delete', - `changedModel` = 'User', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - CALL hedera.image_unref('user', OLD.image); - - INSERT IGNORE INTO userSync SET `name` = OLD.`name`; -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 `userConfig` @@ -940,7 +460,7 @@ CREATE TABLE `userConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `loginKey` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -968,7 +488,7 @@ CREATE TABLE `userLog` ( KEY `userLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `userLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -986,7 +506,7 @@ CREATE TABLE `userPassword` ( `nDigits` tinyint(3) unsigned NOT NULL COMMENT 'Minimum of digits', `nPunct` tinyint(3) unsigned NOT NULL COMMENT 'Minimum of symbols', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Restrictions on user passwords'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Restrictions on user passwords'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1005,27 +525,6 @@ CREATE TABLE `userSync` ( -- -- Dumping events for database 'account' -- -/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; -/*!50106 DROP EVENT IF EXISTS `role_sync` */; -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 = utf8mb3 */ ;; -/*!50003 SET character_set_results = utf8mb3 */ ;; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ;; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; -/*!50003 SET @saved_time_zone = @@time_zone */ ;; -/*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`salix`@`10.0.%.%`*/ /*!50106 EVENT `role_sync` ON SCHEDULE AT '2023-11-16 14:32:48' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL role_sync */ ;; -/*!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 */ ; -- -- Dumping routines for database 'account' @@ -1060,7 +559,7 @@ BEGIN SET vSignature = util.hmacSha2(256, CONCAT_WS('/', @userId, @userName), vKey); RETURN vSignature = @userSignature; END IF; - + RETURN FALSE; END ;; @@ -1089,7 +588,7 @@ BEGIN * @return The user id */ DECLARE vUser INT DEFAULT NULL; - + IF myUser_checkLogin() THEN SET vUser = @userId; @@ -1097,7 +596,7 @@ BEGIN SELECT id INTO vUser FROM user WHERE name = LEFT(USER(), INSTR(USER(), '@') - 1); END IF; - + RETURN vUser; END ;; DELIMITER ; @@ -1132,7 +631,7 @@ BEGIN ELSE SET vUser = LEFT(USER(), INSTR(USER(), '@') - 1); END IF; - + RETURN vUser; END ;; DELIMITER ; @@ -1150,7 +649,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_hasPriv`(vChain VARCHAR(100), +CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_hasPriv`(vChain VARCHAR(100), vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE') ) RETURNS tinyint(1) READS SQL DATA @@ -1285,10 +784,10 @@ BEGIN DECLARE vDigitChars TEXT DEFAULT '1234567890'; DECLARE vPunctChars TEXT DEFAULT '!$%&()=.'; - SELECT length, nAlpha, nUpper, nDigits, nPunct + SELECT length, nAlpha, nUpper, nDigits, nPunct INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword; - WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha + WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO SET vRandIndex = FLOOR((RAND() * 4) + 1); @@ -1363,7 +862,7 @@ BEGIN DECLARE vRole VARCHAR(255); SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole - FROM role r + FROM role r JOIN user u ON u.role = r.id JOIN roleConfig c WHERE u.name = vUserName; @@ -1390,16 +889,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `user_getNameFromId`(vSelf INT) RETUR BEGIN /** * Gets user name from it's id. - * + * * @param vSelf The user id * @return The user name */ DECLARE vName VARCHAR(30); - - SELECT `name` INTO vName - FROM user + + SELECT `name` INTO vName + FROM user WHERE id = vSelf; - + RETURN vName; END ;; DELIMITER ; @@ -1417,8 +916,8 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `user_hasPriv`(vChain VARCHAR(100), - vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE'), +CREATE DEFINER=`root`@`localhost` FUNCTION `user_hasPriv`(vChain VARCHAR(100), + vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE'), vUserFk INT ) RETURNS tinyint(1) READS SQL DATA @@ -1440,16 +939,20 @@ BEGIN SET vDb = SUBSTRING_INDEX(vChain, '.', 1); SET vChain = SUBSTRING(vChain, LENGTH(vDb) + 2); - SET vTableName = SUBSTRING_INDEX(vChain, '.', 1); - SET vColumnName = SUBSTRING(vChain, LENGTH(vTableName) + 2); - + IF LOCATE('.', vChain) > 0 THEN + SET vTableName = SUBSTRING_INDEX(vChain, '.', 1); + SET vColumnName = SUBSTRING(vChain, LENGTH(vTableName) + 2); + ELSE + SET vTableName = vChain; + END IF; + SELECT COUNT(*) INTO vChainExists FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = vDb - AND TABLE_NAME = vTableName - AND COLUMN_NAME = vColumnName - LIMIT 1; - + WHERE TABLE_SCHEMA = vDb + AND TABLE_NAME = vTableName + AND (COLUMN_NAME = vColumnName OR vColumnName IS NULL) + LIMIT 1; + IF NOT vChainExists THEN RETURN FALSE; END IF; @@ -1474,22 +977,22 @@ BEGIN SELECT hasPrivilege INTO vHasPrivilege FROM (SELECT JSON_VALUE(Priv, '$.access') & vPrivilegeFlag hasPrivilege - FROM mysql.global_priv gp + FROM mysql.global_priv gp JOIN tRole tr ON CONCAT(tr.name) = gp.User HAVING hasPrivilege LIMIT 1)sub; - + IF NOT vHasPrivilege THEN - SELECT sub.privilege = 'Y' INTO vHasPrivilege - FROM - (SELECT CASE vPrivilege - WHEN 'SELECT' THEN Select_priv - WHEN 'INSERT' THEN Insert_priv - WHEN 'UPDATE' THEN Update_priv - WHEN 'DELETE' THEN Delete_priv - END privilege - FROM mysql.db db + SELECT sub.privilege = 'Y' INTO vHasPrivilege + FROM + (SELECT CASE vPrivilege + WHEN 'SELECT' THEN Select_priv + WHEN 'INSERT' THEN Insert_priv + WHEN 'UPDATE' THEN Update_priv + WHEN 'DELETE' THEN Delete_priv + END privilege + FROM mysql.db db JOIN tRole tr ON tr.name = db.User WHERE db.Db = vDb)sub; @@ -1498,13 +1001,13 @@ BEGIN IF NOT vHasPrivilege THEN SELECT TRUE INTO vHasPrivilege - FROM tRole tr + FROM tRole tr LEFT JOIN ( SELECT User, Table_priv privilege FROM mysql.tables_priv WHERE Db = vDb AND Table_name = vTableName - UNION + UNION SELECT User, Column_priv FROM mysql.columns_priv WHERE Db = vDb @@ -1587,7 +1090,7 @@ BEGIN JOIN role r ON r.id = rr.inheritsFrom WHERE u.`name` = vUser AND r.id = vRoleId; - + RETURN vHasRole; END ;; DELIMITER ; @@ -1624,7 +1127,7 @@ BEGIN DECLARE vObject VARCHAR(50); DECLARE vChainExists BOOL; DECLARE vExecutePriv INT DEFAULT 262144; - -- 262144 = CONV(1000000000000000000, 2, 10) + -- 262144 = CONV(1000000000000000000, 2, 10) -- 1000000000000000000 execution permission expressed in binary base SET vDb = SUBSTRING_INDEX(vChain, '.', 1); @@ -1636,7 +1139,7 @@ BEGIN WHERE db = vDb AND `name` = vObject AND `type` = vType - LIMIT 1; + LIMIT 1; IF NOT vChainExists THEN RETURN FALSE; @@ -1651,18 +1154,18 @@ BEGIN JOIN roleRole rr ON rr.role = u.role JOIN `role` r ON r.id = rr.inheritsFrom WHERE u.id = vUserFk; - + SELECT TRUE INTO vHasPrivilege - FROM mysql.global_priv gp - JOIN tRole tr ON tr.name = gp.`User` + FROM mysql.global_priv gp + JOIN tRole tr ON tr.name = gp.`User` OR CONCAT('$', tr.name) = gp.`User` WHERE JSON_VALUE(gp.Priv, '$.access') >= vExecutePriv AND gp.Host = '' LIMIT 1; IF NOT vHasPrivilege THEN - SELECT TRUE INTO vHasPrivilege - FROM mysql.db db + SELECT TRUE INTO vHasPrivilege + FROM mysql.db db JOIN tRole tr ON tr.name = db.`User` WHERE db.Db = vDb AND db.Execute_priv = 'Y'; @@ -1670,7 +1173,7 @@ BEGIN IF NOT vHasPrivilege THEN SELECT TRUE INTO vHasPrivilege - FROM mysql.procs_priv pp + FROM mysql.procs_priv pp JOIN tRole tr ON tr.name = pp.`User` WHERE pp.Db = vDb AND pp.Routine_name = vObject @@ -1750,7 +1253,7 @@ BEGIN AND password = MD5(vPassword) AND active; - IF vAuthIsOk + IF vAuthIsOk THEN CALL myUser_loginWithName (vUserName); ELSE @@ -1811,7 +1314,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_loginWithName`(vUserName VAR BEGIN /** * Logs in using only the user name. This procedure is intended to be executed - * by users with a high level of privileges so that normal users should not have + * by users with a high level of privileges so that normal users should not have * execute permissions on it. * * @param vUserName The user name @@ -1847,7 +1350,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_logout`() BEGIN /** * Logouts the user. - */ + */ SET @userId = NULL; SET @userName = NULL; SET @userSignature = NULL; @@ -1945,9 +1448,9 @@ BEGIN SELECT COUNT(*) > 0 INTO vIsRoot FROM tmp.role t - JOIN role r ON r.id = t.id + JOIN role r ON r.id = t.id WHERE r.`name` = 'root'; - + IF vIsRoot THEN INSERT IGNORE INTO tmp.role (id) SELECT id FROM role; @@ -2666,7 +2169,7 @@ BEGIN IF vChr REGEXP '[[:alpha:]]' THEN SET vNAlpha = vNAlpha+1; - + IF vChr REGEXP '[A-Z]' THEN SET vNUpper = vNUpper+1; @@ -2702,6 +2205,1967 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `bi` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bi` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `bi`; + +-- +-- Table structure for table `Equalizator` +-- + +DROP TABLE IF EXISTS `Equalizator`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Equalizator` ( + `Vista` int(11) NOT NULL, + `Pedido` int(11) DEFAULT NULL, + `Impreso` int(11) DEFAULT NULL, + `Encajado` int(11) DEFAULT NULL, + PRIMARY KEY (`Vista`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Greuge_Evolution` +-- + +DROP TABLE IF EXISTS `Greuge_Evolution`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Greuge_Evolution` ( + `Id_Cliente` int(11) NOT NULL, + `Fecha` date NOT NULL, + `Greuge` decimal(10,2) NOT NULL DEFAULT 0.00, + `Ventas` decimal(10,2) NOT NULL DEFAULT 0.00, + `Fosil` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'greuge fósil, correspondiente a los clientes muertos', + `Recobro` decimal(10,2) NOT NULL DEFAULT 0.00, + PRIMARY KEY (`Id_Cliente`,`Fecha`), + KEY `greuge_evolution_idx1` (`Fecha`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacenamos la evolucion del greuge de los ultimos dias '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Greuge_comercial_recobro` +-- + +DROP TABLE IF EXISTS `Greuge_comercial_recobro`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Greuge_comercial_recobro` ( + `Id_Trabajador` int(11) NOT NULL, + `recobro` decimal(10,2) NOT NULL DEFAULT 0.00, + `peso_cartera` decimal(10,2) NOT NULL DEFAULT 0.00, + PRIMARY KEY (`Id_Trabajador`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Greuges_comercial_detail` +-- + +DROP TABLE IF EXISTS `Greuges_comercial_detail`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Greuges_comercial_detail` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Id_Trabajador` int(10) unsigned NOT NULL, + `Comentario` varchar(45) NOT NULL, + `Importe` decimal(10,2) NOT NULL, + `Fecha` datetime DEFAULT NULL, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ROW_FORMAT=COMPACT; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Ticket_Portes` +-- + +DROP TABLE IF EXISTS `Ticket_Portes`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Ticket_Portes` ( + `Id_Ticket` int(11) NOT NULL, + `rate` tinyint(4) NOT NULL COMMENT 'Tarifa', + `real_amount` double NOT NULL COMMENT 'Cantidad pactada con la agencia', + `payed_amount` double NOT NULL COMMENT 'Cantidad reflejada en el Ticket', + PRIMARY KEY (`Id_Ticket`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `XDiario_ALL` +-- + +DROP TABLE IF EXISTS `XDiario_ALL`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `XDiario_ALL` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `empresa_id` int(5) NOT NULL, + `SUBCTA` varchar(11) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `Eurodebe` double DEFAULT NULL, + `Eurohaber` double DEFAULT NULL, + `Fecha` date DEFAULT NULL, + `FECHA_EX` date DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `Cuenta` (`SUBCTA`), + KEY `empresa` (`empresa_id`), + KEY `Fecha` (`Fecha`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `analisis_grafico_simple` +-- + +DROP TABLE IF EXISTS `analisis_grafico_simple`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_grafico_simple` ( + `Año` smallint(5) unsigned NOT NULL, + `Semana` tinyint(3) unsigned NOT NULL, + `Importe` double DEFAULT NULL, + UNIQUE KEY `Año` (`Año`,`Semana`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `analisis_grafico_ventas` +-- + +DROP TABLE IF EXISTS `analisis_grafico_ventas`; +/*!50001 DROP VIEW IF EXISTS `analisis_grafico_ventas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `analisis_grafico_ventas` AS SELECT + 1 AS `Año`, + 1 AS `Semana`, + 1 AS `Importe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `analisis_ventas` +-- + +DROP TABLE IF EXISTS `analisis_ventas`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Familia` varchar(30) NOT NULL, + `Reino` varchar(45) NOT NULL, + `Comercial` varchar(3) NOT NULL, + `Comprador` varchar(3) NOT NULL, + `Provincia` varchar(30) NOT NULL, + `almacen` varchar(20) NOT NULL, + `Año` smallint(5) unsigned NOT NULL, + `Mes` tinyint(3) unsigned NOT NULL, + `Semana` tinyint(3) unsigned NOT NULL, + `Vista` varchar(45) DEFAULT NULL, + `Importe` double NOT NULL, + PRIMARY KEY (`id`), + KEY `Año` (`Año`,`Semana`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `analisis_ventas_almacen_evolution` +-- + +DROP TABLE IF EXISTS `analisis_ventas_almacen_evolution`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas_almacen_evolution` ( + `Semana` int(11) NOT NULL, + `Almacen` varchar(20) NOT NULL, + `Ventas` int(11) NOT NULL, + `Año` int(11) NOT NULL, + `Periodo` int(11) NOT NULL, + UNIQUE KEY `Almacen` (`Almacen`,`Periodo`), + KEY `Periodo` (`Periodo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `analisis_ventas_familia_evolution__` +-- + +DROP TABLE IF EXISTS `analisis_ventas_familia_evolution__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas_familia_evolution__` ( + `semana` int(11) NOT NULL, + `familia` varchar(50) NOT NULL, + `ventas` int(11) NOT NULL, + `año` int(11) NOT NULL, + `periodo` int(11) NOT NULL, + `typeFk` smallint(5) unsigned DEFAULT NULL, + UNIQUE KEY `familia` (`familia`,`periodo`), + KEY `periodo` (`periodo`), + KEY `analisis_ventas_familia_evolution_FK` (`typeFk`), + CONSTRAINT `analisis_ventas_familia_evolution_FK` FOREIGN KEY (`typeFk`) REFERENCES `vn`.`itemType` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5196 Deprecated 2023-06-05'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `analisis_ventas_provincia_evolution` +-- + +DROP TABLE IF EXISTS `analisis_ventas_provincia_evolution`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas_provincia_evolution` ( + `semana` int(11) NOT NULL, + `provincia` varchar(30) NOT NULL, + `ventas` int(11) NOT NULL, + `año` int(11) NOT NULL, + `periodo` int(11) NOT NULL, + `countryCode` varchar(2) NOT NULL, + UNIQUE KEY `provincia` (`provincia`,`periodo`), + KEY `periodo` (`periodo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `analisis_ventas_reino_evolution` +-- + +DROP TABLE IF EXISTS `analisis_ventas_reino_evolution`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas_reino_evolution` ( + `semana` int(11) NOT NULL, + `reino` varchar(20) NOT NULL, + `ventas` int(11) NOT NULL, + `año` int(11) NOT NULL, + `periodo` int(11) NOT NULL, + UNIQUE KEY `reino` (`reino`,`periodo`), + KEY `periodo` (`periodo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `analisis_ventas_simple` +-- + +DROP TABLE IF EXISTS `analisis_ventas_simple`; +/*!50001 DROP VIEW IF EXISTS `analisis_ventas_simple`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `analisis_ventas_simple` AS SELECT + 1 AS `Año`, + 1 AS `Semana`, + 1 AS `Importe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `analisis_ventas_vendedor_evolution` +-- + +DROP TABLE IF EXISTS `analisis_ventas_vendedor_evolution`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas_vendedor_evolution` ( + `semana` int(11) NOT NULL, + `vendedor` varchar(3) NOT NULL, + `ventas` int(11) NOT NULL, + `año` int(11) NOT NULL, + `periodo` int(11) NOT NULL, + UNIQUE KEY `vendedor` (`vendedor`,`periodo`), + KEY `periodo` (`periodo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `analisis_ventas_vista_evolution` +-- + +DROP TABLE IF EXISTS `analisis_ventas_vista_evolution`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `analisis_ventas_vista_evolution` ( + `semana` int(11) NOT NULL, + `vista` varchar(45) NOT NULL, + `ventas` int(11) NOT NULL, + `año` int(11) NOT NULL, + `periodo` int(11) NOT NULL, + UNIQUE KEY `vista` (`vista`,`periodo`), + KEY `periodo` (`periodo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `calidad_detalle` +-- + +DROP TABLE IF EXISTS `calidad_detalle`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `calidad_detalle` ( + `Id_Cliente` int(11) NOT NULL, + `calidad_parametros_id` int(2) NOT NULL, + `valor` int(3) DEFAULT NULL, + PRIMARY KEY (`Id_Cliente`,`calidad_parametros_id`), + KEY `calidad_parametros_detalle_idx` (`calidad_parametros_id`), + CONSTRAINT `calidad_parametros_detalle` FOREIGN KEY (`calidad_parametros_id`) REFERENCES `calidad_parametros` (`calidad_parametros_id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `calidad_parametros` +-- + +DROP TABLE IF EXISTS `calidad_parametros`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `calidad_parametros` ( + `calidad_parametros_id` int(2) NOT NULL, + `descripcion` varchar(45) NOT NULL, + PRIMARY KEY (`calidad_parametros_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `claims_ratio` +-- + +DROP TABLE IF EXISTS `claims_ratio`; +/*!50001 DROP VIEW IF EXISTS `claims_ratio`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `claims_ratio` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `Consumo`, + 1 AS `Reclamaciones`, + 1 AS `Ratio`, + 1 AS `recobro`, + 1 AS `inflacion` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `customerDebtInventory` +-- + +DROP TABLE IF EXISTS `customerDebtInventory`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `customerDebtInventory` ( + `Id_Cliente` int(11) NOT NULL, + `Debt` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'CREATE TABLE bi.customerDebtInventory\n\nSELECT Id_Cliente, sum(Euros) as Debt\n\nFROM \n(\nSELECT Id_Cliente, Entregado as Euros\n\nFROM Recibos \n\nWHERE Fechacobro < ''2017-01-01\n''\nUNION ALL\n\nSELECT Id_Cliente, - Importe \nFROM Facturas\nWHERE Fecha < ''2017-01-01''\n) sub \nGROUP BY Id_Cliente', + PRIMARY KEY (`Id_Cliente`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `customerRiskOverdue` +-- + +DROP TABLE IF EXISTS `customerRiskOverdue`; +/*!50001 DROP VIEW IF EXISTS `customerRiskOverdue`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `customerRiskOverdue` AS SELECT + 1 AS `customer_id`, + 1 AS `amount`, + 1 AS `company_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `defaulters` +-- + +DROP TABLE IF EXISTS `defaulters`; +/*!50001 DROP VIEW IF EXISTS `defaulters`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `defaulters` AS SELECT + 1 AS `client`, + 1 AS `date`, + 1 AS `amount`, + 1 AS `defaulterSince`, + 1 AS `hasChanged`, + 1 AS `frozened` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `defaulting` +-- + +DROP TABLE IF EXISTS `defaulting`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `defaulting` ( + `date` date NOT NULL, + `amount` double NOT NULL, + PRIMARY KEY (`date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `f_tvc` +-- + +DROP TABLE IF EXISTS `f_tvc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `f_tvc` ( + `Id_Ticket` int(11) NOT NULL, + PRIMARY KEY (`Id_Ticket`), + CONSTRAINT `id_ticket_to_comisionantes` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn`.`ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacenamos la lista de tickets para agilizar la consulta. Corresponde a los clientes REAL y en los almacenes COMISIONANTES'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `facturacion_media_anual` +-- + +DROP TABLE IF EXISTS `facturacion_media_anual`; +/*!50001 DROP VIEW IF EXISTS `facturacion_media_anual`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `facturacion_media_anual` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `Consumo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `last_Id_Cubo` +-- + +DROP TABLE IF EXISTS `last_Id_Cubo`; +/*!50001 DROP VIEW IF EXISTS `last_Id_Cubo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `last_Id_Cubo` AS SELECT + 1 AS `Id_Compra`, + 1 AS `Id_Article`, + 1 AS `warehouse_id`, + 1 AS `Id_Cubo`, + 1 AS `Packing` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `live_counter__` +-- + +DROP TABLE IF EXISTS `live_counter__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `live_counter__` ( + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + `amount` double NOT NULL, + PRIMARY KEY (`odbc_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5744 Deprecated 2023-06-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `partitioning_information__` +-- + +DROP TABLE IF EXISTS `partitioning_information__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `partitioning_information__` ( + `schema_name` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `table_name` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `date_field` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `table_depending` varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `execution_order` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`schema_name`,`table_name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5744 Deprecated 2023-06-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `primer_pedido__` +-- + +DROP TABLE IF EXISTS `primer_pedido__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `primer_pedido__` ( + `Id_Cliente` int(11) NOT NULL, + `Id_Ticket` int(11) NOT NULL, + `month` tinyint(1) NOT NULL, + `year` smallint(2) NOT NULL, + `total` decimal(10,2) NOT NULL DEFAULT 0.00, + PRIMARY KEY (`Id_Cliente`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5744 Deprecated 2023-06-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `rotacion` +-- + +DROP TABLE IF EXISTS `rotacion`; +/*!50001 DROP VIEW IF EXISTS `rotacion`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `rotacion` AS SELECT + 1 AS `Id_Article`, + 1 AS `warehouse_id`, + 1 AS `total`, + 1 AS `rotacion`, + 1 AS `cm3`, + 1 AS `almacenaje`, + 1 AS `manipulacion`, + 1 AS `auxiliar`, + 1 AS `mermas`, + 1 AS `cm3reparto`, + 1 AS `grams` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `rutasBoard` +-- + +DROP TABLE IF EXISTS `rutasBoard`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `rutasBoard` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `Id_Ruta` int(10) unsigned NOT NULL DEFAULT 0, + `Id_Agencia` int(11) NOT NULL DEFAULT 0, + `km__` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `Dia__` varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `Fecha` date NOT NULL, + `Terceros__` int(11) DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `Bultos` int(11) NOT NULL DEFAULT 0, + `Matricula__` varchar(10) DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `Tipo__` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `year__` int(4) DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `month__` int(2) DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `warehouse_id__` smallint(5) unsigned DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `coste_bulto__` decimal(10,2) unsigned DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + `teorico` decimal(10,2) NOT NULL DEFAULT 0.00, + `practico` decimal(10,2) NOT NULL DEFAULT 0.00, + `greuge` decimal(10,2) NOT NULL DEFAULT 0.00, + `m3__` decimal(10,1) unsigned DEFAULT NULL COMMENT '@deprecated 2023-11-01, refs #6087', + PRIMARY KEY (`id`), + UNIQUE KEY `rutasBoard_Ruta` (`Id_Ruta`), + KEY `rutasBoard_ix1` (`year__`), + KEY `rutasBoard_ix2` (`month__`), + KEY `rutasBoard_ix3` (`warehouse_id__`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Se usa en https://grafana.verdnatura.es/d/c089276b-5ab5-430f-aa76-e5d8e0e7fe2e/analisis-de-volumen-y-rendimiento-por-agencia?orgId=1'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `tarifa_componentes` +-- + +DROP TABLE IF EXISTS `tarifa_componentes`; +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tarifa_componentes` AS SELECT + 1 AS `Id_Componente`, + 1 AS `Componente`, + 1 AS `tarifa_componentes_series_id`, + 1 AS `tarifa_class`, + 1 AS `tax`, + 1 AS `is_renewable`, + 1 AS `code` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tarifa_componentes_series` +-- + +DROP TABLE IF EXISTS `tarifa_componentes_series`; +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tarifa_componentes_series` AS SELECT + 1 AS `tarifa_componentes_series_id`, + 1 AS `Serie`, + 1 AS `base`, + 1 AS `margen` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `tarifa_premisas__` +-- + +DROP TABLE IF EXISTS `tarifa_premisas__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tarifa_premisas__` ( + `Id_Premisa` int(11) NOT NULL AUTO_INCREMENT, + `premisa` varchar(45) NOT NULL, + PRIMARY KEY (`Id_Premisa`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5744 Deprecated 2023-06-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `tarifa_warehouse__` +-- + +DROP TABLE IF EXISTS `tarifa_warehouse__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tarifa_warehouse__` ( + `Id_Tarifa_Warehouse` int(11) NOT NULL AUTO_INCREMENT, + `warehouse_id` int(11) NOT NULL, + `Id_Premisa` int(11) NOT NULL, + `Valor` double NOT NULL, + PRIMARY KEY (`Id_Tarifa_Warehouse`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5744 Deprecated 2023-06-06\nAlmacena los valores de gasto por almacen'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `v_clientes_jerarquia` +-- + +DROP TABLE IF EXISTS `v_clientes_jerarquia`; +/*!50001 DROP VIEW IF EXISTS `v_clientes_jerarquia`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_clientes_jerarquia` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `Cliente`, + 1 AS `Comercial`, + 1 AS `Jefe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_ventas_contables` +-- + +DROP TABLE IF EXISTS `v_ventas_contables`; +/*!50001 DROP VIEW IF EXISTS `v_ventas_contables`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_ventas_contables` AS SELECT + 1 AS `year`, + 1 AS `month`, + 1 AS `importe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Dumping events for database 'bi' +-- + +-- +-- Dumping routines for database 'bi' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `nz` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `nz`(vData DOUBLE) RETURNS double + DETERMINISTIC +BEGIN +/** + * Devuelve 0, si el parámetro es NULL: + */ + DECLARE vResult DOUBLE; + + SET vResult = IFNULL(vData,0); + + RETURN vResult; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `analisis_ventas_evolution_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `analisis_ventas_evolution_add`() +BEGIN + DECLARE vPreviousPeriod INT; + DECLARE vCurrentPeriod INT; + DECLARE vLastPeriod INT; + DECLARE vMinPeriod INT DEFAULT 201400; + DECLARE vMaxPeriod INT; + DECLARE vYear INT; + DECLARE vWeek INT; + + SELECT t.period INTO vMaxPeriod + FROM vn.`time` t + WHERE t.dated = util.VN_CURDATE(); + + -- Almacen + + SET vCurrentPeriod = IFNULL(vLastPeriod, vMinPeriod); + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(Periodo) INTO vPreviousPeriod + FROM analisis_ventas_almacen_evolution + WHERE Periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_almacen_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_almacen_evolution(Almacen, Ventas, Semana,Año, Periodo) + SELECT Almacen, SUM(Ventas) AS Ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT almacen, SUM(Importe) AS Ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY almacen + UNION ALL + SELECT almacen, - SUM(Importe) AS Ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY almacen + UNION ALL + SELECT Almacen, Ventas + FROM analisis_ventas_almacen_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY Almacen; + END WHILE; + + -- Reino + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_reino_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_reino_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_reino_evolution(reino, ventas, semana,año, periodo) + SELECT reino, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT Reino, SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY Reino + UNION ALL + SELECT Reino, - SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY Reino + UNION ALL + SELECT reino, ventas + FROM analisis_ventas_reino_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY reino; + END WHILE; + + -- Provincia + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_provincia_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_provincia_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_provincia_evolution(provincia, countryCode, ventas, semana,año, periodo) + SELECT Provincia, code, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT a.Provincia, c.code, SUM(a.Importe) AS ventas + FROM analisis_ventas a + JOIN vn.province p ON p.name= a.provincia + JOIN vn.country c ON c.id = p.countryFk + WHERE vYear = a.Año + AND vWeek = a.Semana + GROUP BY a.Provincia + UNION ALL + SELECT a.Provincia, c.code, - SUM(a.Importe) AS ventas + FROM analisis_ventas a + JOIN vn.province p ON p.name= a.provincia + JOIN vn.country c ON c.id = p.countryFk + WHERE vYear - 1 = a.Año + AND vWeek = a.Semana + GROUP BY a.Provincia + UNION ALL + SELECT a.provincia,a.countryCode, a.ventas + FROM analisis_ventas_provincia_evolution a + WHERE a.Periodo = vPreviousPeriod + ) sub + GROUP BY Provincia; + + + END WHILE; + + -- Vista + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_vista_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_vista_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_vista_evolution(vista, ventas, semana,año, periodo) + SELECT vista, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT Vista, SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY Vista + UNION ALL + SELECT Vista, - SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY Vista + UNION ALL + SELECT vista, ventas + FROM analisis_ventas_vista_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY Vista; + END WHILE; + + -- Vendedor + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_vendedor_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_vendedor_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_vendedor_evolution(vendedor, ventas, semana,año, periodo) + SELECT Comercial AS vendedor, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT Comercial, SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY Comercial + UNION ALL + SELECT Comercial, - SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY Comercial + UNION ALL + SELECT vendedor, ventas + FROM analisis_ventas_vendedor_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY vendedor; + END WHILE; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `analisis_ventas_simple` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `analisis_ventas_simple`() +BEGIN +/** + * Vacia y rellena la tabla 'analisis_grafico_simple' desde 'analisis_grafico_ventas' + */ + TRUNCATE bi.analisis_grafico_simple; + + INSERT INTO bi.analisis_grafico_simple + SELECT * + FROM bi.analisis_grafico_ventas; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `analisis_ventas_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_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `analisis_ventas_update`() +BEGIN + DECLARE vLastMonth DATE; + + SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, util.VN_CURDATE())); + + DELETE FROM analisis_ventas + WHERE Año > YEAR(vLastMonth) + OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth)); + + INSERT INTO analisis_ventas ( + Familia, + Reino, + Comercial, + Comprador, + Provincia, + almacen, + Año, + Mes, + Semana, + Vista, + Importe + ) + SELECT + tp.Tipo AS Familia, + r.reino AS Reino, + tr.CodigoTrabajador AS Comercial, + tr2.CodigoTrabajador AS Comprador, + p.name AS Provincia, + w.name AS almacen, + tm.year AS Año, + tm.month AS Mes, + tm.week AS Semana, + v.vista AS Vista, + bt.importe AS Importe + FROM bs.ventas bt + LEFT JOIN vn2008.Tipos tp ON tp.tipo_id = bt.tipo_id + LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id + LEFT JOIN vn2008.Clientes c on c.Id_Cliente = bt.Id_Cliente + LEFT JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = c.Id_Trabajador + LEFT JOIN vn2008.Trabajadores tr2 ON tr2.Id_Trabajador = tp.Id_Trabajador + JOIN vn2008.time tm ON tm.date = bt.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = bt.Id_Movimiento + LEFT JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia + LEFT JOIN vn2008.Vistas v ON v.vista_id = a.Vista + LEFT JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.Id_Consigna + LEFT JOIN vn2008.province p ON p.province_id = cs.province_id + LEFT JOIN vn2008.warehouse w ON w.id = t.warehouse_id + WHERE bt.fecha >= vLastMonth AND r.mercancia; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `claim_ratio_routine` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `claim_ratio_routine`() +BEGIN + DECLARE vMonthToRefund INT DEFAULT 4; + + /* + * PAK 2015-11-20 + * Se trata de añadir a la tabla Greuges todos los + * cargos que luego vamos a utilizar para calcular el recobro + */ + + -- Reclamaciones demasiado sensibles + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, + Importe, Greuges_type_id,Id_Ticket) + SELECT cm.Fecha + , cm.Id_Cliente + , concat('Claim ',cm.id,' : ', m.Concepte) + ,round( -1 * ((sensib -1)/4) * Cantidad * + Preu * (100 - Descuento) / 100, 2) AS Reclamaciones + , 4 + , m.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca USING(Id_Movimiento) + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3; + + -- Reclamaciones que pasan a Maná + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, + Importe , Greuges_type_id,Id_Ticket) + SELECT cm.Fecha + , cm.Id_Cliente + , concat('Claim_mana ',cm.id,' : ', m.Concepte) + ,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2) + AS Reclamaciones + ,3 + ,m.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca USING(Id_Movimiento) + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3 + AND cm.mana; + + -- Marcamos para no repetir + UPDATE vn2008.cl_act ca + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + SET greuge = 1 + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3; + + -- Recobros + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + SELECT DISTINCT t.Id_Ticket + FROM vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Tickets_state ts ON ts.Id_Ticket = t.Id_Ticket + JOIN vn.ticketTracking tt ON tt.id = ts.inter_id + JOIN vn2008.state s ON s.id = tt.stateFk + WHERE mc.Id_Componente = 17 + AND mc.greuge = 0 + AND t.Fecha >= '2016-10-01' + AND t.Fecha < util.VN_CURDATE() + AND s.alert_level >= 3; + + DELETE g.* + FROM vn2008.Greuges g + JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket + WHERE Greuges_type_id = 2; + + INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, + Greuges_type_id, Id_Ticket) + SELECT Id_Cliente + ,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2) + AS dif + ,date(t.Fecha) + , 2 + ,tt.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc + ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17 + GROUP BY t.Id_Ticket + HAVING ABS(dif) > 1; + + UPDATE vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento + JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket + SET greuge = 1 + WHERE Id_Componente = 17; + + /* + * Recalculamos la ratio de las reclamaciones, que luego + * se va a utilizar en el recobro + */ + + REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) + SELECT Id_Cliente, 0,0,0,0 + FROM vn2008.Clientes; + + REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) + SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones, + round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0 + FROM bi.facturacion_media_anual fm + LEFT JOIN( + SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) * + Cantidad * Preu * (100 - Descuento) / 100)) + AS Reclamaciones + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca + ON ca.Id_Movimiento = m.Id_Movimiento + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND cm.cl_est_id = 3 + AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) + GROUP BY cm.Id_Cliente + ) claims ON claims.Id_Cliente = fm.Id_Cliente; + + + -- Calculamos el porcentaje del recobro para añadirlo al precio de venta + UPDATE bi.claims_ratio cr + JOIN ( + SELECT Id_Cliente, nz(SUM(Importe)) AS Greuge + FROM vn2008.Greuges + WHERE Fecha <= util.VN_CURDATE() + GROUP BY Id_Cliente + ) g ON g.Id_Cliente = cr.Id_Cliente + SET recobro = GREATEST(0,round(nz(Greuge) / + (nz(Consumo) * vMonthToRefund / 12 ) ,3)); + + -- Protección neonatos + UPDATE bi.claims_ratio cr + JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente + SET recobro = 0, Ratio = 0 + WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + + -- CLIENTE 7983, JULIAN SUAU + UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; + + -- CLIENTE 4358 + UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 4358; + + -- CLIENTE 5523, VERDECORA + UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; + + -- CLIENTE 15979, SERVEIS VETERINARIS + UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 15979; + + -- CLIENTE 5189 i 8942, son de CSR i son el mateix client + UPDATE bi.claims_ratio cr + JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro + FROM bi.claims_ratio + WHERE Id_Cliente IN ( 5189,8942) + ) sub + SET cr.recobro = sub.recobro + WHERE Id_Cliente IN ( 5189,8942); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() +BEGIN + DECLARE vDateShort DATETIME; + DECLARE vDateLong DATETIME; + DECLARE vOneYearAgo DATETIME; + + SET vDateShort = TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); + SET vDateLong = TIMESTAMPADD(MONTH, -18,util.VN_CURDATE()); + SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,util.VN_CURDATE()); + + DELETE FROM bi.Greuge_Evolution + WHERE (Fecha < vDateShort AND weekday(Fecha) != 1) + OR Fecha < vOneYearAgo; + + DELETE FROM bi.defaulters WHERE `date` < vDateLong; + DELETE FROM bi.defaulting WHERE `date` < vDateLong; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean_launcher` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean_launcher`() +BEGIN +/** + * Borra registros de las principales tablas (excepto de "ticket"). + */ + CALL vn2008.clean(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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `comparativa_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `comparativa_add`() +BEGIN + DECLARE lastCOMP INT; # Se trata de una variable para almacenar el ultimo valor del Periodo + DECLARE vMaxPeriod INT; + DECLARE vMaxWeek INT; + + SELECT t.period, t.`week` INTO vMaxPeriod, vMaxWeek + FROM vn.`time` t + WHERE t.dated = util.VN_CURDATE(); + + SELECT MAX(Periodo) INTO lastCOMP FROM vn2008.Comparativa; + -- Fijaremos las ventas con más de un mes de antiguedad en la tabla Comparativa + + IF lastCOMP < vMaxPeriod - 3 AND vMaxWeek > 3 THEN + + REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price) + SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe) + FROM bs.ventas v + JOIN vn2008.time tm ON tm.date = v.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento + JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id + JOIN vn2008.reinos r ON r.id = tp.reino_id + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE tm.period BETWEEN lastCOMP AND vMaxPeriod - 3 + AND t.Id_Cliente NOT IN(400,200) + AND t.warehouse_id NOT IN (0,13) + GROUP BY m.Id_Article, Periodo, t.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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `comparativa_add_manual` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `comparativa_add_manual`(IN vStarted DATE, IN vEnded DATE) +BEGIN +/** + * Recalcula la tabla Comparativa para dos valores dados + * + * @param vStarted fecha desde + * @param vEnded fecha hasta + */ + + DECLARE periodStart INT; + DECLARE periodEnd INT; + + -- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar + + SELECT t.period INTO periodStart + FROM vn.`time` t + WHERE t.dated = vStarted; + + SELECT t.period INTO periodEnd + FROM vn.`time` t + WHERE t.dated = vEnded; + + DELETE FROM vn2008.Comparativa + WHERE Periodo BETWEEN periodStart AND periodEnd; + + INSERT INTO vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price) + SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe) + FROM bs.ventas v + JOIN vn2008.time tm ON tm.date = v.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento + JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id + JOIN vn2008.reinos r ON r.id = tp.reino_id + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE tm.period BETWEEN periodStart AND periodEnd + AND t.Id_Cliente NOT IN(400,200) + AND t.warehouse_id NOT IN (0,13) + GROUP BY m.Id_Article, Periodo, t.warehouse_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `defaultersFromDate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `defaultersFromDate`(IN vDate DATE) +BEGIN + + SELECT t1.*, c.Cliente, w.code AS workerCode, c.pay_met_id,c.Vencimiento + FROM ( + -- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy + select * from( + select today.client, today.amount todayAmount, yesterday.amount yesterdayAmount, round(yesterday.amount - today.amount,2) as difference, defaulterSince + from + (select client, amount, defaulterSince + from defaulters + where date = vDate and hasChanged) today + join + (select client, amount + from defaulters + where date = TIMESTAMPADD(DAY,-1,vDate)) yesterday using(client) + + having today.amount > 0 and difference <> 0 + ) newDefaulters + )t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente + left join vn.worker w ON w.id = c.Id_Trabajador; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `defaulting` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `defaulting`(IN `vDate` DATE) +BEGIN + DECLARE vDone BOOLEAN; + DECLARE vClient INT; + DECLARE vAmount INT; + DECLARE vDued DATE; + DECLARE vAmountInvoice DECIMAL(10,2); + DECLARE vGraceDays INT; + DECLARE defaulters CURSOR FOR + SELECT client, amount, graceDays FROM bi.defaulters d + JOIN vn2008.Clientes c ON c.Id_Cliente = d.client + JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id + WHERE hasChanged AND date = vDate; + + DECLARE invoices CURSOR FOR + SELECT Vencimiento, importe FROM vn2008.Facturas f + WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE FROM bi.defaulters WHERE date = vDate; + + INSERT INTO bi.defaulters(client, date, amount) + SELECT c.id, vDate, IFNULL(FLOOR(SUM(cro.amount)),0) AS amount + FROM vn.`client` c + LEFT JOIN bi.customerRiskOverdue cro ON c.id = cro.customer_id + GROUP BY c.id; + + -- marcamos si ha cambiado y heredamos la fecha defaulterSince + UPDATE bi.defaulters d + LEFT JOIN ( + SELECT * FROM( + SELECT client, amount , defaulterSince, frozened FROM bi.defaulters + WHERE date <= TIMESTAMPADD(DAY,-1, vDate) + ORDER BY date DESC + LIMIT 10000000000000000000) t GROUP BY client + ) yesterday using(client) + SET d.hasChanged = (IFNULL(d.amount,0) <> IFNULL(yesterday.amount,0)), + d.defaulterSince = yesterday.defaulterSince, + d.frozened = yesterday.frozened + WHERE d.date = vDate ; + + OPEN defaulters; + defaulters: LOOP + SET vDone = FALSE; + SET vAmount = 0; + FETCH defaulters INTO vClient,vAmount, vGraceDays; + IF vDone THEN + LEAVE defaulters; + END IF; + OPEN invoices; + invoices:LOOP + + FETCH invoices INTO vDued, vAmountInvoice; + IF vDone THEN + LEAVE invoices; + END IF; + + IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN + SET vAmount = vAmount - vAmountInvoice; + IF vAmount <= 0 THEN + + UPDATE defaulters SET defaulterSince = vDued + WHERE client = vClient and date = vDate; + + SET vAmount = 0; + LEAVE invoices; + END IF; + END IF; + END LOOP; + CLOSE invoices; + END LOOP; + CLOSE defaulters; + + DELETE FROM defaulters + WHERE amount = 0 + AND hasChanged = FALSE + AND `date` = vDate; + + UPDATE defaulters d + JOIN vn.config ON TRUE + SET d.frozened = NULL + WHERE `date` = vDate + AND d.amount <= config.defaultersMaxAmount; + + CALL vn.clientFreeze(); + + -- actualizamos defaulting + DELETE FROM bi.defaulting WHERE date = vDate; + + INSERT INTO bi.defaulting(date, amount) + SELECT vDate, SUM(amount) + FROM bi.defaulters + WHERE date = vDate and amount > 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `defaulting_launcher` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `defaulting_launcher`() +BEGIN +/** + * Calcula la morosidad de los clientes. + */ + CALL bi.defaulting(util.VN_CURDATE()); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `facturacion_media_anual_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_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `facturacion_media_anual_update`() +BEGIN + TRUNCATE TABLE bs.clientAnnualConsumption; + + REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo) + SELECT clientFk, avg(Facturacion) + FROM ( + SELECT clientFk, YEAR(issued) year, MONTH(issued) month, sum(amount) as Facturacion + FROM vn.invoiceOut + WHERE issued BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND TIMESTAMPADD(DAY, - DAY(util.VN_CURDATE()),util.VN_CURDATE()) + GROUP BY clientFk, year, month + ) vol + GROUP BY clientFk; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `greuge_dif_porte_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `greuge_dif_porte_add`() +BEGIN + DECLARE datSTART DATETIME DEFAULT TIMESTAMPADD(DAY,-60,util.VN_CURDATE()); -- '2019-07-01' + DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.dp; + + -- Agencias que no cobran por volumen + CREATE TEMPORARY TABLE tmp.dp + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, + SUM((t.zonePrice - t.zoneBonus) * ebv.ratio) AS teorico, + 00000.00 as practico, + 00000.00 as greuge, + t.clientFk, + t.shipped + FROM + vn.ticket t + JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk + LEFT JOIN vn2008.expeditions e ON e.ticket_id = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.EsBulto + JOIN vn.zone z ON t.zoneFk = z.id + WHERE + t.shipped between datSTART AND datEND + AND cli.`real` + AND t.companyFk IN (442 , 567) + AND z.isVolumetric = FALSE + GROUP BY t.id; + + -- Agencias que cobran por volumen + INSERT INTO tmp.dp + SELECT sv.ticketFk, + SUM(IFNULL(sv.freight,0)) AS teorico, + 00000.00 as practico, + 00000.00 as greuge, + sv.clientFk, + sv.shipped + FROM vn.saleVolume sv + JOIN vn.zone z ON z.id = sv.zoneFk + AND sv.shipped BETWEEN datSTART AND datEND + AND z.isVolumetric != FALSE + GROUP BY sv.ticketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux; + + CREATE TEMPORARY TABLE tmp.dp_aux + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT dp.ticketFk, sum(Cantidad * Valor) as valor + FROM tmp.dp + JOIN vn2008.Movimientos m ON m.Id_Ticket = dp.ticketFk + JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento) + WHERE mc.Id_Componente = 15 + GROUP BY dp.ticketFk; + + UPDATE tmp.dp + JOIN tmp.dp_aux USING(ticketFk) + SET practico = IFNULL(valor,0); + + DROP TEMPORARY TABLE tmp.dp_aux; + + CREATE TEMPORARY TABLE tmp.dp_aux + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT dp.ticketFk, sum(Importe) Importe + FROM tmp.dp + JOIN vn2008.Greuges g ON g.Id_Ticket = dp.ticketFk + WHERE Greuges_type_id = 1 -- dif_porte + GROUP BY dp.ticketFk; + + UPDATE tmp.dp + JOIN tmp.dp_aux USING(ticketFk) + SET greuge = IFNULL(Importe,0); + + INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, Greuges_type_id, Id_Ticket) + SELECT dp.clientFk + , concat('dif_porte ', dp.ticketFk) + , round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe + , date(dp.shipped) + , 1 + ,dp.ticketFk + FROM tmp.dp + JOIN vn.client c ON c.id = dp.clientFk + WHERE ABS(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0)) > 1 + AND c.isRelevant; + + DROP TEMPORARY TABLE + tmp.dp, + tmp.dp_aux; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `Greuge_Evolution_Add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `Greuge_Evolution_Add`() +BEGIN +/* + Inserta en la tabla Greuge_Evolution el saldo acumulado de cada cliente, + así como las ventas acumuladas en los ultimos 365 dias, para poder controlar + su evolucion. +*/ + DECLARE datFEC DATE; + DECLARE datFEC_TOMORROW DATE; + DECLARE datFEC_LASTYEAR DATE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + + GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; + SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); + CALL vn.mail_insert( + 'jgallego@verdnatura.es,pako@verdnatura.es', + 'noreply@verdnatura.es', + 'Greuge_Evolution_Add', + CONCAT('ERROR ', IFNULL(@errno, 0), ': ', ifnull(@text, 'texto')) + ); + + END; + + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; + + DELETE FROM bi.Greuge_Evolution WHERE Fecha >= TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + + SELECT TIMESTAMPADD(DAY,1,MAX(Fecha)), + TIMESTAMPADD(DAY,2,MAX(Fecha)) + INTO datFEC, + datFEC_TOMORROW + FROM bi.Greuge_Evolution; + + SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); + + DELETE FROM bi.Greuge_Evolution WHERE Fecha >= datFEC; + + DROP TEMPORARY TABLE IF EXISTS maxInvoice; + + CREATE TEMPORARY TABLE maxInvoice + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha + FROM vn2008.Facturas + GROUP BY Id_Cliente + HAVING maxFecha < timestampadd(month,-2,datFEC); + + WHILE datFEC < util.VN_CURDATE() DO + + REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas, Fosil) + + SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 + FROM ( + SELECT Id_Cliente, sum(Importe) as Greuge + FROM vn2008.Greuges + where Fecha <= datFEC + group by Id_Cliente + ) sub + RIGHT JOIN + + ( + + SELECT Id_Cliente, sum(Ventas) as Ventas + FROM + ( + + SELECT Id_Cliente, IF (fecha != datFEC, -1,1) * (importe + recargo) as Ventas + FROM bs.ventas + WHERE fecha = datFEC or fecha = datFEC_LASTYEAR + + UNION ALL + + SELECT Id_Cliente, Ventas + FROM bi.Greuge_Evolution + WHERE Fecha = TIMESTAMPADD(DAY, -1, datFEC) + + ) sub + group by Id_Cliente + + ) v using(Id_Cliente) + ; + + -- Ahora calcularemos el greuge muerto + UPDATE bi.Greuge_Evolution ge + JOIN maxInvoice m using(Id_Cliente) + SET FOSIL = GREUGE + WHERE m.maxFecha < TIMESTAMPADD(MONTH,-2,ge.Fecha); + + -- Recobro + UPDATE bi.Greuge_Evolution ge + JOIN ( + SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe + FROM vn2008.Tickets t + JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna + JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento + WHERE t.Fecha >= datFEC + AND t.Fecha < datFEC_TOMORROW + AND mc.Id_Componente = 17 -- Recobro + GROUP BY cs.Id_Cliente + ) sub using(Id_Cliente) + SET Recobro = Importe + WHERE ge.Fecha = datFEC; + + SET datFEC = datFEC_TOMORROW; + SET datFEC_TOMORROW = TIMESTAMPADD(DAY,1,datFEC_TOMORROW); + SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS maxInvoice; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `nigthlyAnalisisVentas` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `nigthlyAnalisisVentas`() +BEGIN + CALL analisis_ventas_update; + CALL analisis_ventas_simple; + CALL analisis_ventas_evolution_add; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `rutasAnalyze` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `rutasAnalyze`( + vYear INT, + vMonth INT +) +BEGIN +/** + * Analiza los costes de las rutas de reparto + * y lo almacena en la tabla bi.rutasBoard + */ + DELETE FROM rutasBoard + WHERE YEAR(Fecha) = vYear + AND MONTH(Fecha) = vMonth; + + -- Rellenamos la tabla con los datos de las rutas VOLUMETRICAS, especialmente con los bultos "virtuales" + INSERT INTO rutasBoard( + Id_Ruta, + Id_Agencia, + Fecha, + bultos) + SELECT r.id, + r.agencyModeFk, + r.created, + SUM(sv.volume / ebv.m3) + FROM vn.route r + JOIN vn.ticket t ON t.routeFk = r.id + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.code = 'transportBox' + WHERE YEAR(r.created) = vYear AND MONTH(r.created) = vMonth + AND z.isVolumetric + GROUP BY r.id; + + -- Rellenamos la tabla con los datos de las rutas NO VOLUMETRICAS, especialmente con los bultos "virtuales" + INSERT INTO rutasBoard( + Id_Ruta, + Id_Agencia, + Fecha, + Bultos) + SELECT r.id, + r.agencyModeFk, + r.created, + SUM(t.packages) + FROM vn.route r + JOIN vn.ticket t ON t.routeFk = r.id + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE YEAR(r.created) = vYear + AND MONTH(r.created) = vMonth + AND NOT z.isVolumetric + GROUP BY r.id + ON DUPLICATE KEY UPDATE Bultos = Bultos + VALUES(Bultos); + + -- Coste PRACTICO de cada bulto, de acuerdo con los componentes de tipo AGENCIA en cada linea de venta + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(s.quantity * sc.value) totalPractice + FROM vn.route r + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.ticket t ON t.routeFk = r.id + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.saleComponent sc ON sc.saleFk = s.id + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE ct.code = 'FREIGHT' + AND tm.`year` = vYear + AND tm.`month` = vMonth + GROUP BY r.id + ) sub ON sub.routeFk = r.Id_Ruta + SET r.practico = IFNULL(sub.totalPractice / r.Bultos, 0); + + -- Coste TEORICO de una caja "virtual" para cada ruta, teniendo en cuenta que hay carros, pallets, etc + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(t.zonePrice/ ebv.ratio) / COUNT(*) averageTheoreticalVolume + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.expedition e ON e.ticketFk = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk + JOIN vn.address ad ON ad.id = t.addressFk + JOIN vn.client c ON c.id = ad.clientFk + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE tm.`year` = vYear + AND tm.`month` = vMonth + AND NOT z.isVolumetric + GROUP BY t.routeFk + ) sub ON r.Id_Ruta = sub.routeFk + SET r.teorico = IFNULL(sub.averageTheoreticalVolume, 0); + + -- Coste VOLUMETRICO TEORICO de una caja "virtual" para cada ruta + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(freight) averageTheoreticalVolume + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.saleVolume sf ON sf.ticketFk = t.id + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE tm.`year` = vYear + AND tm.`month` = vMonth + AND z.isVolumetric + GROUP BY t.routeFk + ) sub ON r.Id_Ruta = sub.routeFk + SET r.teorico = IFNULL(sub.averageTheoreticalVolume / r.Bultos, 0); + + -- La diferencia entre el teorico y el practico se deberia de cobrar en greuges, cada noche + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(g.amount) greuge + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.greuge g ON g.ticketFk = t.id + JOIN vn.greugeType gt ON gt.id = g.greugeTypeFk + WHERE tm.`year` = vYear + AND tm.`month` = vMonth + AND gt.code = 'freightDifference' + GROUP BY t.routeFk + ) sub ON r.Id_Ruta = sub.routeFk + SET r.greuge = sub.greuge / r.Bultos; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `rutasAnalyze_launcher` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `rutasAnalyze_launcher`() +BEGIN +/** + * Call rutasAnalyze + */ + CALL rutasAnalyze(YEAR(util.VN_CURDATE()), MONTH(util.VN_CURDATE())); +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 */ ; + -- -- Current Database: `bs` -- @@ -2710,6 +4174,21 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bs` /*!40100 DEFAULT CHARACTER SET utf USE `bs`; +-- +-- Temporary table structure for view `VentasPorCliente` +-- + +DROP TABLE IF EXISTS `VentasPorCliente`; +/*!50001 DROP VIEW IF EXISTS `VentasPorCliente`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `VentasPorCliente` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `VentaBasica`, + 1 AS `year`, + 1 AS `month` */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `bajasLaborales` -- @@ -2814,7 +4293,7 @@ CREATE TABLE `clientDiedPeriod` ( PRIMARY KEY (`id`), UNIQUE KEY `clientDiedPeriod_UN` (`countryFk`), CONSTRAINT `clientDiedPeriod_FK` FOREIGN KEY (`countryFk`) REFERENCES `vn`.`country` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define lo que es un periodo para los clientes de los diferentes países'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define lo que es un periodo para los clientes de los diferentes países'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2834,29 +4313,6 @@ CREATE TABLE `clientNewBorn` ( CONSTRAINT `clientNewBorn_fk1` FOREIGN KEY (`clientFk`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Listado de clientes que se consideran nuevos a efectos de cobrar la comision adicional del comercial'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `bs`.`clientNewBorn_BEFORE_UPDATE` - BEFORE UPDATE ON `clientNewBorn` - FOR EACH ROW -BEGIN - -- Si ha pasado un año o mas - IF TIMESTAMPDIFF(YEAR,NEW.lastShipped, OLD.lastShipped) THEN - SET NEW.firstShipped = NEW.lastShipped; - 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 */ ; -- -- Table structure for table `compradores__` @@ -2959,6 +4415,21 @@ CREATE TABLE `fondo_maniobra` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `horasSilla` +-- + +DROP TABLE IF EXISTS `horasSilla`; +/*!50001 DROP VIEW IF EXISTS `horasSilla`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `horasSilla` AS SELECT + 1 AS `Fecha`, + 1 AS `Departamento`, + 1 AS `Horas`, + 1 AS `Salarios` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `indicators` -- @@ -3020,7 +4491,7 @@ CREATE TABLE `inventoryDiscrepancy` ( `alert` int(11) NOT NULL DEFAULT 0, `quantity` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='This table collects the discrepancies between theorical inventory and located items'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='This table collects the discrepancies between theorical inventory and located items'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3040,7 +4511,7 @@ CREATE TABLE `inventoryDiscrepancyDetail` ( `alert` int(11) DEFAULT NULL COMMENT 'alert level for this discrepancy', PRIMARY KEY (`id`), UNIQUE KEY `inventoryDiscrepancyDetail_UN` (`warehouseFk`,`itemFk`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Last discrepancies'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Last discrepancies'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3097,7 +4568,7 @@ CREATE TABLE `m3` ( `dayName` varchar(12) DEFAULT NULL, `euros` decimal(10,2) DEFAULT 0.00, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3118,60 +4589,8 @@ CREATE TABLE `nightTask` ( `error` varchar(255) DEFAULT NULL, `errorCode` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `bs`.`nightTaskBeforeInsert` - BEFORE INSERT ON `nightTask` - FOR EACH ROW -BEGIN - - IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN - - CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `bs`.`nightTaskBeforeUpdate` - BEFORE UPDATE ON `nightTask` - FOR EACH ROW -BEGIN - - IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN - - CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); - - 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 */ ; -- -- Table structure for table `nightTaskConfig` @@ -3184,7 +4603,7 @@ CREATE TABLE `nightTaskConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `logMail` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3221,7 +4640,7 @@ CREATE TABLE `payMethodClient` ( KEY `FkDateClientPayMethod` (`dated`,`clientFk`), CONSTRAINT `FkClientPayMethod` FOREIGN KEY (`clientFk`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FkPayMethodClient` FOREIGN KEY (`payMethodFk`) REFERENCES `vn`.`payMethod` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3239,7 +4658,7 @@ CREATE TABLE `payMethodClientEvolution` ( `amount` decimal(10,2) NOT NULL, `equalizationTax` decimal(10,2) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3396,7 +4815,7 @@ CREATE TABLE `salesMonthlySnapshot___` ( `newClientScore` decimal(10,3) DEFAULT NULL, `teamBossPlus` decimal(10,3) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='@deprecated 2022-11'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='@deprecated 2022-11'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3416,7 +4835,7 @@ CREATE TABLE `salesPersonEvolution` ( PRIMARY KEY (`id`), KEY `salesPersonEvolution_salesPerson` (`salesPersonFk`), CONSTRAINT `salesPersonEvolution_salesPerson` FOREIGN KEY (`salesPersonFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Evolución Comerciales'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Evolución Comerciales'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3541,7 +4960,7 @@ CREATE TABLE `workerLabourDataByMonth` ( `permanent` int(5) NOT NULL COMMENT 'Número de empleados fijos', PRIMARY KEY (`id`), KEY `workerLabourDataByMonth_graph_idx` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3568,7 +4987,7 @@ CREATE TABLE `workerProductivity` ( CONSTRAINT `workerProductivity_FK_1` FOREIGN KEY (`stateFk`) REFERENCES `vn`.`state` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerProductivity_warehouseFk` FOREIGN KEY (`warehouseFk`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerProductivity_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3583,7 +5002,7 @@ CREATE TABLE `workerProductivityConfig` ( `minSeconsPackager` int(11) DEFAULT NULL, `minSeconsItemPicker` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3602,7 +5021,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `clientDied_recalc` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `clientDied_recalc` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN DECLARE vDone INT DEFAULT FALSE; DECLARE vCountryFk INT; DECLARE vDays INT; @@ -3640,7 +5059,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `inventoryDiscrepancy_launch` ON SCHEDULE EVERY 15 MINUTE STARTS '2023-07-18 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL bs.inventoryDiscrepancyDetail_replace() */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `inventoryDiscrepancy_launch` ON SCHEDULE EVERY 15 MINUTE STARTS '2023-07-18 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL bs.inventoryDiscrepancyDetail_replace() */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -3658,7 +5077,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `nightTask_launchAll` ON SCHEDULE EVERY 1 DAY STARTS '2022-02-08 04:14:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL bs.nightTask_launchAll */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `nightTask_launchAll` ON SCHEDULE EVERY 1 DAY STARTS '2022-02-08 04:14:00' ON COMPLETION PRESERVE ENABLE DO CALL bs.nightTask_launchAll */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -3686,11 +5105,11 @@ BEGIN DECLARE vTramo VARCHAR(20); DECLARE vHour INT; - + SET vHour = HOUR(vDateTime) ; - + SET vTramo = - CASE + CASE WHEN vHour BETWEEN 0 AND 14 THEN 'Mañana' WHEN vHour BETWEEN 15 AND 24 THEN 'Tarde' END ; @@ -3718,7 +5137,7 @@ BEGIN * Inserta en la tabla bancos_evolution los saldos acumulados de cada banco * * @param vStartingDate Fecha desde la cual se recalculan la tabla bs.bancos_evolution - */ + */ DECLARE vCurrentDate DATE; DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, util.VN_CURDATE()); IF IFNULL(vStartingDate,0) < TIMESTAMPADD(YEAR, -5, util.VN_CURDATE()) THEN @@ -3732,49 +5151,49 @@ BEGIN SELECT vCurrentDate, Id_Banco, deuda FROM bs.bancos_evolution WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate); - + WHILE vCurrentDate < vMaxDate DO -- insertar solo el dia de ayer INSERT INTO bs.bancos_evolution(Fecha ,Id_Banco, saldo) - SELECT vCurrentDate, Id_Banco, SUM(saldo) + SELECT vCurrentDate, Id_Banco, SUM(saldo) FROM ( SELECT Id_Banco ,saldo FROM bs.bancos_evolution WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate) -- los saldos acumulados del dia anterior UNION ALL - + SELECT c.Id_Banco, IFNULL(SUM(Entrada),0) - IFNULL(SUM(Salida),0) as saldo FROM vn2008.Cajas c JOIN vn2008.Bancos b using(Id_Banco) -- saldos de las cajas - JOIN vn.accountingType at2 ON at2.id = b.cash + JOIN vn.accountingType at2 ON at2.id = b.cash WHERE at2.code IN ('wireTransfer','fundingLine') AND Cajafecha = vCurrentDate AND (Serie = 'MB' OR at2.code = 'fundingLine') GROUP BY Id_Banco - )sub + )sub GROUP BY Id_Banco ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); - + SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate); END WHILE; - -- Ahora actualizamos la quilla + -- Ahora actualizamos la quilla UPDATE bs.bancos_evolution be JOIN ( SELECT bp.Id_Banco, - sum(bp.importe) as quilla, t.dated - FROM vn.time t + FROM vn.time t JOIN vn2008.Bancos_poliza bp ON t.dated between apertura AND IFNULL(cierre, t.dated) WHERE t.dated BETWEEN vStartingDate AND vMaxDate GROUP BY Id_Banco, t.dated ) sub ON be.Id_Banco = sub.Id_Banco AND sub.dated = be.Fecha - SET be.quilla = sub.quilla; + SET be.quilla = sub.quilla; -- pagos futuros no concilidados INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) SELECT t.dated, p.id_banco, - importe - FROM vn.time t + FROM vn.time t join vn2008.pago p ON p.fecha <= t.dated WHERE t.dated BETWEEN util.VN_CURDATE() AND vMaxDate AND p.fecha BETWEEN util.VN_CURDATE() AND vMaxDate @@ -3784,7 +5203,7 @@ BEGIN -- cobros futuros INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) SELECT t.dated, r.Id_Banco, SUM(Entregado) - FROM vn.time t + FROM vn.time t JOIN vn2008.Recibos r ON r.Fechacobro <= t.dated WHERE r.Fechacobro > util.VN_CURDATE() AND r.Fechacobro <= vMaxDate AND t.dated BETWEEN util.VN_CURDATE() AND vMaxDate @@ -3794,10 +5213,10 @@ BEGIN -- saldos de la tabla prevision INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) SELECT t.dated, sp.Id_Banco, SUM(Importe) - FROM vn.time t + FROM vn.time t JOIN vn2008.Saldos_Prevision sp ON sp.Fecha <= t.dated JOIN vn2008.Bancos b ON sp.Id_Banco = b.Id_Banco - JOIN vn.accountingType at2 ON at2.id = b.cash + JOIN vn.accountingType at2 ON at2.id = b.cash WHERE at2.code IN ('wireTransfer','fundingLine') AND t.dated BETWEEN vStartingDate AND vMaxDate GROUP BY t.dated, sp.Id_Banco @@ -3811,12 +5230,12 @@ BEGIN -- Deuda UPDATE bs.bancos_evolution be JOIN vn2008.Bancos b using(Id_Banco) - JOIN vn.accountingType at2 ON at2.id = b.cash + JOIN vn.accountingType at2 ON at2.id = b.cash SET be.deuda = IF(at2.code = 'fundingLine', be.saldo_aux, 0) , be.saldo = IF(at2.code = 'fundingLine', 0, be.saldo_aux) WHERE Fecha >= vStartingDate; - -- Liquidez + -- Liquidez update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate; -- Disponibilidad update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate; @@ -3839,14 +5258,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `campaignComparative`(vDateFrom DATE, vDateTo DATE) BEGIN - SELECT - workerName, - id, - name, - CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, - CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount + SELECT + workerName, + id, + name, + CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, + CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount FROM ( - (SELECT + (SELECT CONCAT(w.firstname, ' ', w.lastName) AS workerName, c.id, c.name, @@ -3855,11 +5274,11 @@ BEGIN FROM bs.ventas v INNER JOIN vn.`client` c ON v.Id_Cliente = c.id INNER JOIN vn.worker w ON c.salesPersonFk = w.id - WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) + WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR) GROUP BY w.id, v.Id_Cliente) UNION ALL - (SELECT + (SELECT CONCAT(w.firstname, ' ', w.lastName) AS workerName, c.id, c.name, @@ -3893,21 +5312,29 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `carteras_add`() -BEGIN -/** - * Inserta en @bs.carteras. - */ - DELETE FROM bs.carteras - WHERE Año >= YEAR(util.VN_CURDATE()) - 1; - - INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso) - SELECT t.year AS Año, t.month AS Mes, w.code AS CodigoTrabajador, SUM(v.importe) AS Peso - FROM vn.time t - JOIN bs.ventas v on t.dated = v.fecha - JOIN vn.client c on c.id = v.Id_Cliente - JOIN vn.worker w ON w.id = c.salesPersonFk - WHERE t.year >= YEAR(util.VN_CURDATE()) - 1 - GROUP BY w.code, t.year , t.month; +BEGIN +/** + * Inserta en la tabla @bs.carteras las ventas desde el año pasado + * agrupadas por trabajador, año y mes + */ + DECLARE vYear INT DEFAULT YEAR(util.VN_CURDATE()) - 1; + + DELETE FROM bs.carteras WHERE Año >= vYear; + + CALL util.time_generate( + MAKEDATE(vYear, 1), + (SELECT MAX(fecha) FROM ventas) + ); + + INSERT INTO carteras(Año, Mes , CodigoTrabajador, Peso) + SELECT t.`year`, t.`month`, w.code, SUM(v.importe) + FROM tmp.time t + JOIN ventas v on t.dated = v.fecha + JOIN vn.client c on c.id = v.Id_Cliente + JOIN vn.worker w ON w.id = c.salesPersonFk + GROUP BY w.code, t.`year`, t.`month`; + + DROP TEMPORARY TABLE tmp.time; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3926,18 +5353,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() BEGIN - DECLARE vFourYearsAgo DATETIME; - DECLARE vOneYearAgo DATETIME; - DECLARE vTwoYearAgo DATETIME; - DECLARE vThreeYearAgo DATETIME; + DECLARE vFourYearsAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; + DECLARE vOneYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; + DECLARE vTwoYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 3 YEAR; + DECLARE vThreeYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; + DECLARE vEighteenMonths DATE DEFAULT util.VN_CURDATE() - INTERVAL 18 MONTH; - - SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,util.VN_CURDATE()); - SET vTwoYearAgo = TIMESTAMPADD(YEAR, -2,util.VN_CURDATE()); - SET vThreeYearAgo = TIMESTAMPADD(YEAR, -3,util.VN_CURDATE()); - SET vFourYearsAgo = TIMESTAMPADD(YEAR, -4,util.VN_CURDATE()); - - DELETE FROM bs.clientNewBorn + DELETE FROM clientNewBorn WHERE lastShipped < vOneYearAgo; DELETE FROM ventas @@ -3949,14 +5371,17 @@ BEGIN DELETE FROM payMethodClientEvolution WHERE dated < vFourYearsAgo; - DELETE FROM bs.salesByclientSalesPerson + DELETE FROM salesByclientSalesPerson WHERE dated < vFourYearsAgo; - DELETE FROM bs.m3 + DELETE FROM m3 WHERE fecha < vTwoYearAgo; DELETE FROM salesByItemTypeDay WHERE dated < vThreeYearAgo; + + DELETE FROM waste + WHERE MAKEDATE(`year`, 1) + INTERVAL (`week` - 1) WEEK + INTERVAL 1 DAY < vEighteenMonths; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4052,16 +5477,16 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `clientNewBorn_recalc`() BLOCK1: BEGIN DECLARE vClientFk INT; - DECLARE vShipped DATE; + DECLARE vShipped DATE; DECLARE vPreviousShipped DATE; - DECLARE vDone boolean; - DECLARE cur cursor for - - SELECT clientFk, firstShipped - FROM bs.clientNewBorn; - - DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; - SET vDone := FALSE; + DECLARE vDone boolean; + DECLARE cur cursor for + + SELECT clientFk, firstShipped + FROM bs.clientNewBorn; + + DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; + SET vDone := FALSE; DELETE FROM bs.clientNewBorn WHERE isModified = FALSE; @@ -4073,7 +5498,7 @@ BLOCK1: BEGIN WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null GROUP BY c.id; OPEN cur; - + LOOP1: LOOP SET vDone := FALSE; FETCH cur INTO vClientFk, vShipped; @@ -4084,37 +5509,37 @@ BLOCK1: BEGIN END IF; BLOCK2: BEGIN - DECLARE vCurrentShipped DATE; - DECLARE vDone2 boolean; + DECLARE vCurrentShipped DATE; + DECLARE vDone2 boolean; DECLARE cur2 CURSOR FOR - SELECT shipped - FROM vn.ticket + SELECT shipped + FROM vn.ticket WHERE clientFk = vClientFk AND shipped <= util.VN_CURDATE() ORDER BY shipped DESC; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE; SET vDone2 := FALSE; OPEN cur2; - + SET vPreviousShipped := vShipped; LOOP2: LOOP SET vDone2 := FALSE; FETCH cur2 INTO vCurrentShipped; - + IF DATEDIFF(vPreviousShipped,vCurrentShipped) > 365 THEN - UPDATE bs.clientNewBorn - SET firstShipped = vPreviousShipped + UPDATE bs.clientNewBorn + SET firstShipped = vPreviousShipped WHERE clientFk= vClientFk; - + CLOSE cur2; - LEAVE LOOP2; + LEAVE LOOP2; END IF; - + SET vPreviousShipped := vCurrentShipped; IF vDone2 THEN - UPDATE bs.clientNewBorn - SET firstShipped = vCurrentShipped + UPDATE bs.clientNewBorn + SET firstShipped = vCurrentShipped WHERE clientFk= vClientFk; CLOSE cur2; LEAVE LOOP2; @@ -4124,14 +5549,14 @@ BLOCK1: BEGIN END BLOCK2; END LOOP LOOP1; - UPDATE bs.clientNewBorn cnb + UPDATE bs.clientNewBorn cnb LEFT JOIN (SELECT DISTINCT t.clientFk FROM vn.ticket t JOIN vn.productionConfig pc WHERE t.shipped BETWEEN util.VN_CURDATE() + INTERVAL -(`notBuyingMonths`) MONTH AND util.VN_CURDATE() + INTERVAL -(`pc`.`rookieDays`) DAY) notRookie ON notRookie.clientFk = cnb.clientFk - SET cnb.isRookie = ISNULL(notRookie.clientFk); - + SET cnb.isRookie = ISNULL(notRookie.clientFk); + END BLOCK1 ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4152,16 +5577,16 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `comercialesCompleto`(IN vWorker INT BEGIN DECLARE vAYearAgoStarted DATE DEFAULT DATE_FORMAT(TIMESTAMPADD(YEAR, - 1, vDate), '%Y-%m-01'); DECLARE vAYearAgoEnded DATE DEFAULT TIMESTAMPADD(YEAR, - 1, LAST_DAY(vDate)); - + CALL vn.worker_GetHierarchy(vWorker); - + INSERT IGNORE INTO tmp.workerHierarchyList (workerFk) SELECT wd2.workerFk FROM vn.workerDepartment wd2 WHERE wd2.workerFk = vWorker; - + -- Falta que en algunos casos solo tenga en cuenta los tipos afectados. - SELECT + SELECT c.Id_Cliente id_cliente, c.Cliente cliente, cr.recobro * 100 tarifa, @@ -4186,7 +5611,7 @@ BEGIN FROM vn2008.Clientes c LEFT JOIN - (SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge + (SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge FROM vn2008.Greuges g JOIN vn.`client` c ON c.id = g.Id_Cliente LEFT JOIN vn.worker w ON c.salesPersonFk = w.id @@ -4208,14 +5633,14 @@ BEGIN WHERE v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, vDate) AND vDate GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente LEFT JOIN - (SELECT + (SELECT Id_Cliente, SUM(importe) consumo FROM bs.ventas v INNER JOIN vn2008.Clientes c USING (Id_Cliente) LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador WHERE - (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + (c.Id_Trabajador = vWorker OR tr.boss = vWorker) AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(vDate) + 1, vDate) AND TIMESTAMPADD(DAY, - 1, vDate)) GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente LEFT JOIN @@ -4276,17 +5701,17 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_evolution_add`() BEGIN /** * Inserta en la tabla compradores_evolution las ventas acumuladas en los ultimos 365 dias - * + * */ DECLARE vDated DATE; DECLARE vCount INT DEFAULT 1; - SELECT MAX(fecha) + INTERVAL 1 DAY INTO vDated + SELECT MAX(fecha) + INTERVAL 1 DAY INTO vDated FROM compradores_evolution; IF vDated IS NULL THEN - - SELECT MIN(dated) INTO vDated + + SELECT MIN(dated) INTO vDated FROM sale; INSERT INTO compradores_evolution( @@ -4307,7 +5732,7 @@ BEGIN WHILE vDated < util.VN_CURDATE() DO SET vCount = vCount + 1; - + REPLACE compradores_evolution( Id_Trabajador, fecha, @@ -4319,18 +5744,18 @@ BEGIN SELECT Id_Trabajador, importe FROM compradores_evolution JOIN ( - SELECT DISTINCT it.workerFk - FROM vn.itemType it + SELECT DISTINCT it.workerFk + FROM vn.itemType it )sub2 ON sub2.workerFk = Id_Trabajador - WHERE fecha = vDated - INTERVAL 1 DAY + WHERE fecha = vDated - INTERVAL 1 DAY UNION ALL - SELECT it.workerFk, s.amount * IF(s.dated < vDated, -1, 1) + SELECT it.workerFk, s.amount * IF(s.dated < vDated, -1, 1) FROM sale s JOIN vn.itemType it ON it.id = s.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE s.dated IN (vDated, vDated - INTERVAL 1 YEAR) AND ic.merchandise - )sub + )sub GROUP BY Id_Trabajador; SET vDated = vDated + INTERVAL 1 DAY; @@ -4357,49 +5782,49 @@ BEGIN * Inserta en la tabla fondo_maniobra los saldos acumulados en los ultimos 365 dias */ DECLARE datFEC DATE DEFAULT '2015-01-01'; - - SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) - INTO datFEC + + SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) + INTO datFEC FROM bs.fondo_maniobra; - + WHILE datFEC < util.VN_CURDATE() DO - + IF DAY(datFEC) MOD 28 = 0 THEN -- esto solo sirve para no aburrirse mientras esperamos... SELECT datFEC; END IF; - + REPLACE bs.fondo_maniobra(Fecha, clientes_facturas, clientes_cobros,proveedores_facturas,proveedores_pagos, fondo) SELECT datFEC AS Fecha, Facturas, Cobros,Recibidas,Pagos, Facturas + Cobros + Recibidas + Pagos FROM ( SELECT SUM(io.amount) AS Facturas FROM vn.invoiceOut io - JOIN vn.client c ON io.clientFk = c.id + JOIN vn.client c ON io.clientFk = c.id WHERE c.isRelevant - AND io.companyFk <> 1381 + AND io.companyFk <> 1381 AND io.issued BETWEEN '2011-01-01' AND datFEC ) fac JOIN ( SELECT - SUM(r.amountPaid) AS Cobros - FROM vn.receipt r - JOIN vn.client c ON r.clientFk = c.id - WHERE c.isRelevant + FROM vn.receipt r + JOIN vn.client c ON r.clientFk = c.id + WHERE c.isRelevant AND r.companyFk <> 1381 AND r.payed BETWEEN '2011-01-01' AND datFEC ) cob JOIN ( SELECT - SUM(id.amount) AS Recibidas - FROM vn.invoiceIn ii - JOIN vn.invoiceInDueDay id ON ii.id = id.invoiceInFk + FROM vn.invoiceIn ii + JOIN vn.invoiceInDueDay id ON ii.id = id.invoiceInFk WHERE ii.companyFk <> 1381 AND ii.issued BETWEEN '2015-01-01' AND datFEC ) rec JOIN ( SELECT SUM(p.amount) AS Pagos - FROM vn.payment p - WHERE p.companyFk <>1381 + FROM vn.payment p + WHERE p.companyFk <>1381 AND p.received BETWEEN '2015-01-01' AND datFEC ) pag; - + UPDATE bs.fondo_maniobra JOIN ( SELECT AVG(fondo) AS media @@ -4407,7 +5832,7 @@ BEGIN WHERE fecha <= datFEC ) sub SET fondo_medio = media WHERE fecha = datFEC; - + SET datFEC = TIMESTAMPADD(DAY,1,datFEC); END WHILE; @@ -4431,7 +5856,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fruitsEvolution`() BEGIN -select Id_Cliente, +select Id_Cliente, Cliente, count(semana) as semanas, (w.code IS NOT NULL) isWorker from ( select distinct v.Id_Cliente, c.name as Cliente, week(fecha, 3) as semana @@ -4472,40 +5897,40 @@ BEGIN -- Ventas totales del ultimo año UPDATE indicators - SET lastYearSales = + SET lastYearSales = (SELECT SUM(importe + recargo) FROM ventas v JOIN vn2008.empresa e ON e.id = v.empresa_id JOIN vn2008.empresa_grupo eg ON eg.empresa_grupo_id = e.empresa_grupo WHERE fecha BETWEEN oneYearBefore AND vDated AND eg.grupo = 'Verdnatura' - ) + ) WHERE updated = vDated; - + -- Greuge total acumulado UPDATE indicators - SET totalGreuge = + SET totalGreuge = (SELECT SUM(amount) FROM vn.greuge WHERE shipped <= vDated - ) + ) WHERE updated = vDated; -- Tasa de morosidad con respecto a las ventas del último mes UPDATE indicators - SET latePaymentRate = - (SELECT SUM(amount) - FROM bi.defaulters + SET latePaymentRate = + (SELECT SUM(amount) + FROM bi.defaulters WHERE date = vDated AND amount > 0) / - (SELECT SUM(importe + recargo) - FROM ventas + (SELECT SUM(importe + recargo) + FROM ventas WHERE fecha BETWEEN oneMonthBefore AND vDated) WHERE updated = vDated; -- Número de trabajadores activos UPDATE indicators - SET countEmployee = + SET countEmployee = (SELECT CAST(SUM(ct.hoursWeek) / 40 AS DECIMAL (10, 2)) FROM vn.business b JOIN vn.calendarType ct ON ct.id = b.calendarTypeFk @@ -4524,7 +5949,7 @@ BEGIN -- Número de clientes que han comprado en los últimos 30 dias UPDATE indicators - SET lastMonthActiveClients = + SET lastMonthActiveClients = (SELECT COUNT(DISTINCT t.clientFk) FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated @@ -4533,9 +5958,9 @@ BEGIN -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores UPDATE indicators - SET lastMonthLostClients = + SET lastMonthLostClients = (SELECT COUNT(lm.clientFk) - FROM + FROM (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated @@ -4552,9 +5977,9 @@ BEGIN -- Número de clientes que han comprado en los últimos 30 dias, pero no compraron en los 30 anteriores UPDATE indicators - SET lastMonthNewClients = + SET lastMonthNewClients = (SELECT COUNT(cm.clientFk) - FROM + FROM (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated @@ -4580,7 +6005,7 @@ BEGIN -- Cálculo de las ventas agrupado por semanas SELECT week INTO vWeek - FROM vn.time + FROM vn.time WHERE dated = vDated; TRUNCATE salesByWeek; @@ -4594,12 +6019,12 @@ BEGIN -- Indicador Ventas semana actual UPDATE indicators i - JOIN salesByWeek s ON s.week= vWeek + JOIN salesByWeek s ON s.week= vWeek AND s.year = YEAR(vDated) SET i.thisWeekSales = s.sales WHERE updated = vDated; - -- Indicador ventas semana actual en el año pasado + -- Indicador ventas semana actual en el año pasado UPDATE indicators i JOIN salesByWeek s ON s.week = vWeek AND s.year = YEAR(vDated)-1 @@ -4630,15 +6055,15 @@ BEGIN SELECT IFNULL(TIMESTAMPADD(DAY,1,MAX(updated)), '2018-04-01') INTO vDated FROM bs.indicators; - + WHILE vDated < util.VN_CURDATE() DO - + CALL indicatorsUpdate(vDated); - + SELECT TIMESTAMPADD(DAY,1,MAX(updated)) INTO vDated FROM bs.indicators; - + END WHILE; END ;; @@ -4667,7 +6092,7 @@ BEGIN DECLARE vCalc INT; DECLARE vWarehouseFk INT; - DECLARE cWarehouses CURSOR FOR + DECLARE cWarehouses CURSOR FOR SELECT id FROM vn.warehouse WHERE isInventory; @@ -4680,13 +6105,13 @@ BEGIN read_loop: LOOP SET vDone = FALSE; FETCH cWarehouses INTO vWarehouseFk; - + IF vDone THEN LEAVE read_loop; END IF; - + CALL cache.visible_refresh(vCalc, FALSE, vWarehouseFk); - + CREATE OR REPLACE TEMPORARY TABLE tVisible SELECT itemFk, SUM(visible) totalVisible FROM vn.itemShelving ish @@ -4695,7 +6120,7 @@ BEGIN JOIN vn.sector sc ON sc.id = p.sectorFk WHERE sc.warehouseFk = vWarehouseFk GROUP BY itemFk; - + INSERT INTO inventoryDiscrepancyDetail( warehouseFk, itemFk, @@ -4767,15 +6192,15 @@ BEGIN DECLARE datSTART DATE; DECLARE datEND DATE; - + SELECT TIMESTAMPADD(WEEK, -1,MAX(fecha)) INTO datSTART FROM bs.m3; - + SET datEND = TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); - - DELETE FROM bs.m3 + + DELETE FROM bs.m3 WHERE fecha >= datSTART; - + INSERT INTO bs.m3 (fecha, provinceFk, warehouseFk, m3, year, month, week, day, dayName, euros) SELECT v.fecha, a.provinceFk, t.warehouseFk, sum(s.quantity * ic.cm3delivery) / 1000000 AS m3, tm.year, tm.month, tm.week, tm.day, dayname(v.fecha), sum(importe) @@ -4820,19 +6245,19 @@ BEGIN DECLARE vManaFromDays INT; DECLARE vManaToDays INT; - SELECT id INTO vManaId + SELECT id INTO vManaId FROM vn.component WHERE code = 'mana'; - - SELECT id INTO vManaAutoId + + SELECT id INTO vManaAutoId FROM vn.component WHERE code = 'autoMana'; - + SELECT id INTO vClaimManaId FROM vn.component WHERE code = 'manaClaim'; - - SELECT id INTO vManaBankId + + SELECT id INTO vManaBankId FROM vn.bank WHERE code = 'mana'; - - SELECT id INTO vManaGreugeTypeId + + SELECT id INTO vManaGreugeTypeId FROM vn.greugeType WHERE code = 'mana'; SELECT manaFromDays, manaToDays @@ -4840,17 +6265,17 @@ BEGIN FROM vn.salespersonConfig; SELECT MAX(dated) - INTO vFromDated + INTO vFromDated FROM vn.clientManaCache; DELETE FROM vn.clientManaCache WHERE dated = vFromDated; - + SELECT MAX(dated) - INTO vFromDated + INTO vFromDated FROM vn.clientManaCache; - + IF ISNULL(vFromDated) THEN SELECT manaDateFrom INTO vFromDated @@ -4860,20 +6285,20 @@ BEGIN WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO SELECT vFromDated + INTERVAL vManaToDays DAY, - vFromDated - INTERVAL vManaFromDays DAY - INTO + vFromDated - INTERVAL vManaFromDays DAY + INTO vToDated, vForDeleteDated; - + DELETE FROM vn.clientManaCache WHERE dated <= vForDeleteDated; INSERT INTO vn.clientManaCache(clientFk, mana, dated) - SELECT + SELECT Id_Cliente, SUM(mana), - vToDated - FROM + vToDated + FROM ( SELECT cs.Id_Cliente, Cantidad * Valor as mana FROM vn2008.Tickets t @@ -4881,19 +6306,19 @@ BEGIN JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento WHERE Id_Componente IN (vManaAutoId, vManaId, vClaimManaId) - AND t.Fecha > vFromDated + AND t.Fecha > vFromDated AND date(t.Fecha) <= vToDated UNION ALL SELECT r.Id_Cliente, - Entregado FROM vn2008.Recibos r WHERE Id_Banco = vManaBankId - AND Fechacobro > vFromDated + AND Fechacobro > vFromDated AND Fechacobro <= vToDated UNION ALL SELECT g.Id_Cliente, g.Importe FROM vn2008.Greuges g WHERE Greuges_type_id = vManaGreugeTypeId - AND Fecha > vFromDated + AND Fecha > vFromDated AND Fecha <= vToDated UNION ALL SELECT clientFk, mana @@ -4903,7 +6328,7 @@ BEGIN GROUP BY Id_Cliente HAVING Id_Cliente; - SET vFromDated = vToDated; + SET vFromDated = vToDated; END WHILE; END ;; DELIMITER ; @@ -4923,26 +6348,26 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `manaSpellers_actualize`() BEGIN -/** - * Recalcula el valor del campo con el modificador de precio +/** + * Recalcula el valor del campo con el modificador de precio * para el componente de maná automático. */ - UPDATE vn.workerMana wm + UPDATE vn.workerMana wm JOIN ( - SELECT c.lastSalesPersonFk, + SELECT c.lastSalesPersonFk, FLOOR(SUM(s.amount) / 12) amount FROM salesByclientSalesPerson s JOIN vn.client c ON c.id = s.clientFk WHERE s.dated BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR AND util.VN_CURDATE() GROUP BY c.lastSalesPersonFk - )avgPortfolioWeight ON avgPortfolioWeight.lastSalesPersonFk = wm.workerFk + )avgPortfolioWeight ON avgPortfolioWeight.lastSalesPersonFk = wm.workerFk JOIN vn.salespersonConfig spc - SET wm.pricesModifierRate = + SET wm.pricesModifierRate = IFNULL( GREATEST( - spc.manaMinRate, + spc.manaMinRate, LEAST( - spc.manaMaxRate, + spc.manaMaxRate, ROUND( - wm.amount / avgPortfolioWeight.amount, 3) ) ) @@ -4964,82 +6389,82 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nightTask_launchAll`() -BEGIN -/** - * Runs all nightly tasks. - */ - DECLARE vDone BOOL; - DECLARE vError VARCHAR(255); - DECLARE vErrorCode VARCHAR(255); - DECLARE vSchema VARCHAR(255); - DECLARE vProcedure VARCHAR(255); - DECLARE vLogMail VARCHAR(255); - DECLARE vNightTaskFk INT; - - DECLARE vQueue CURSOR FOR - SELECT id, `schema`, `procedure` - FROM nightTask - WHERE finished <= util.VN_CURDATE() - OR finished IS NULL - ORDER BY `order`; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SET max_sp_recursion_depth = 3; - - SELECT logMail INTO vLogMail - FROM nightTaskConfig LIMIT 1; - - OPEN vQueue; - l: LOOP - SET vDone = FALSE; - FETCH vQueue INTO vNightTaskFk, vSchema, vProcedure; - - IF vDone THEN - LEAVE l; - END IF; - - UPDATE nightTask - SET `started` = util.VN_NOW(), - `finished` = NULL, - `error` = NULL, - `errorCode` = NULL - WHERE id = vNightTaskFk; - - SET vError = NULL; - CALL nightTask_launchTask( - vSchema, - vProcedure, - vError, - vErrorCode - ); - - IF vError IS NOT NULL THEN - IF vLogMail IS NOT NULL THEN - CALL vn.mail_insert( - vLogMail, - NULL, - CONCAT('Nightly task failed (', vSchema, '.', vProcedure, ')'), - CONCAT( - '[', vErrorCode, '] ', vError, CHAR(13, 10), -- Line break - 'See ', SCHEMA(), '.nightTask table for more info.' - ) - ); - END IF; - - UPDATE nightTask - SET `error` = vError, - `errorCode` = vErrorCode - WHERE id = vNightTaskFk; - ELSE - UPDATE nightTask - SET finished = util.VN_NOW(), - lastFinished = util.VN_NOW() - WHERE id = vNightTaskFk; - END IF; - END LOOP; - CLOSE vQueue; +BEGIN +/** + * Runs all nightly tasks. + */ + DECLARE vDone BOOL; + DECLARE vError VARCHAR(255); + DECLARE vErrorCode VARCHAR(255); + DECLARE vSchema VARCHAR(255); + DECLARE vProcedure VARCHAR(255); + DECLARE vLogMail VARCHAR(255); + DECLARE vNightTaskFk INT; + + DECLARE vQueue CURSOR FOR + SELECT id, `schema`, `procedure` + FROM nightTask + WHERE finished <= util.VN_CURDATE() + OR finished IS NULL + ORDER BY `order`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SET max_sp_recursion_depth = 3; + + SELECT logMail INTO vLogMail + FROM nightTaskConfig LIMIT 1; + + OPEN vQueue; + l: LOOP + SET vDone = FALSE; + FETCH vQueue INTO vNightTaskFk, vSchema, vProcedure; + + IF vDone THEN + LEAVE l; + END IF; + + UPDATE nightTask + SET `started` = util.VN_NOW(), + `finished` = NULL, + `error` = NULL, + `errorCode` = NULL + WHERE id = vNightTaskFk; + + SET vError = NULL; + CALL nightTask_launchTask( + vSchema, + vProcedure, + vError, + vErrorCode + ); + + IF vError IS NOT NULL THEN + IF vLogMail IS NOT NULL THEN + CALL vn.mail_insert( + vLogMail, + NULL, + CONCAT('Nightly task failed (', vSchema, '.', vProcedure, ')'), + CONCAT( + '[', vErrorCode, '] ', vError, CHAR(13, 10), -- Line break + 'See ', SCHEMA(), '.nightTask table for more info.' + ) + ); + END IF; + + UPDATE nightTask + SET `error` = vError, + `errorCode` = vErrorCode + WHERE id = vNightTaskFk; + ELSE + UPDATE nightTask + SET finished = util.VN_NOW(), + lastFinished = util.VN_NOW() + WHERE id = vNightTaskFk; + END IF; + END LOOP; + CLOSE vQueue; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5078,7 +6503,7 @@ BEGIN vError = MESSAGE_TEXT, vErrorCode = RETURNED_SQLSTATE; - CALL util.exec(CONCAT('CALL `', vSchema ,'`.`', vProcedure ,'`')); + CALL util.exec(CONCAT('CALL `', vSchema ,'`.`', vProcedure ,'`')); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5097,22 +6522,22 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `payMethodClientAdd`() BEGIN - INSERT IGNORE INTO `bs`.`payMethodClient` (dated, payMethodFk, clientFk) + INSERT IGNORE INTO `bs`.`payMethodClient` (dated, payMethodFk, clientFk) SELECT util.VN_CURDATE(), c.payMethodFk, c.id - FROM vn.client c + FROM vn.client c JOIN vn.payMethod p ON c.payMethodFk = p.id; - + TRUNCATE `bs`.`payMethodClientEvolution` ; - + INSERT INTO `bs`.`payMethodClientEvolution` (dated, payMethodName, amountClient, amount, equalizationTax) - SELECT p.dated, pm.name, COUNT(p.clientFk), SUM(sub.importe) , SUM(sub.recargo) + SELECT p.dated, pm.name, COUNT(p.clientFk), SUM(sub.importe) , SUM(sub.recargo) FROM bs.payMethodClient p - JOIN (SELECT SUM(v.importe) AS importe, SUM(v.recargo) as recargo, v.fecha, v.Id_cliente + JOIN (SELECT SUM(v.importe) AS importe, SUM(v.recargo) as recargo, v.fecha, v.Id_cliente FROM bs.ventas v WHERE v.fecha>= (SELECT MIN(dated) FROM bs. payMethodClient) GROUP BY v.Id_cliente, v.fecha) sub ON sub.fecha = p.dated AND sub.Id_cliente = p.ClientFk JOIN vn.payMethod pm ON p.payMethodFk = pm.id - GROUP BY dated,payMethodFk; + GROUP BY dated,payMethodFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5132,12 +6557,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGraphic`(IN vItemFk INT, IN vTypeFk INT, IN vCategoryFk INT, IN vFromDate DATE, IN vToDate DATE, IN vProducerFk INT) BEGIN - + DECLARE vFromDateLastYear DATE; DECLARE vToDateLastYear DATE; DECLARE vFromDateTwoYearsAgo DATE; DECLARE vToDateTwoYearsAgo DATE; - + SET vItemFk = IFNULL(vItemFk,0); SET vTypeFk = IFNULL(vTypeFk, 0); SET vCategoryFk = IFNULL(vCategoryFk,0); @@ -5152,19 +6577,19 @@ BEGIN SELECT s.quantity, CAST(v.importe AS DECIMAL(10,0)) importe, v.fecha FROM bs.ventas v - JOIN vn.sale s ON s.id = v.Id_Movimiento - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.sale s ON s.id = v.Id_Movimiento + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE vItemFk IN (i.id, 0) AND vTypeFk IN (i.typeFk, 0) AND vCategoryFk IN (it.categoryFk, 0) AND vProducerFk IN (i.producerFk, 0) AND (v.fecha BETWEEN vFromDate AND vToDate OR v.fecha BETWEEN vFromDateLastYear AND vToDateLastYear - OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo + OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo ); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5183,21 +6608,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salePersonEvolutionAdd`(IN vDateStart DATETIME) BEGIN - DELETE FROM bs.salePersonEvolution + DELETE FROM bs.salePersonEvolution WHERE dated <= DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR); - - + + INSERT INTO bs.salePersonEvolution (dated, amount, equalizationTax, salesPersonFk) - SELECT fecha dated, - CAST(SUM(importe) AS DECIMAL(10,2) ) amount, + 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.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; + ORDER BY salesPersonFk,dated ASC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5219,7 +6644,7 @@ BEGIN /** * Agrupa las ventas por cliente/comercial/fecha en la tabla bs.salesByclientSalesPerson * El asociación cliente/comercial/fecha, se mantiene correcta en el tiempo - * + * * @param vDatedFrom el cálculo se realizará desde la fecha introducida hasta ayer */ @@ -5227,17 +6652,17 @@ BEGIN SET vDatedFrom = util.VN_CURDATE() - INTERVAL 1 MONTH; END IF; - UPDATE salesByclientSalesPerson + UPDATE salesByclientSalesPerson SET amount = 0, equalizationTax = 0, amountNewBorn = 0 WHERE dated BETWEEN vDatedFrom AND util.yesterday(); - - INSERT INTO salesByclientSalesPerson( - dated, - salesPersonFk, - clientFk, - amount, + + INSERT INTO salesByclientSalesPerson( + dated, + salesPersonFk, + clientFk, + amount, equalizationTax) SELECT s.dated, c.salesPersonFk, @@ -5246,7 +6671,7 @@ BEGIN SUM(s.surcharge) FROM sale s JOIN vn.client c on s.clientFk = c.id - WHERE s.dated BETWEEN vDatedFrom AND util.yesterday() + WHERE s.dated BETWEEN vDatedFrom AND util.yesterday() GROUP BY s.dated, c.salesPersonFk, s.clientFk ON DUPLICATE KEY UPDATE amount= VALUES(amount), equalizationTax= VALUES(equalizationTax); @@ -5419,8 +6844,8 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesByItemTypeDay_addLauncher`() -BEGIN - CALL bs.salesByItemTypeDay_add(util.VN_CURDATE() - INTERVAL 30 DAY, util.VN_CURDATE()); +BEGIN + CALL bs.salesByItemTypeDay_add(util.VN_CURDATE() - INTERVAL 30 DAY, util.VN_CURDATE()); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5440,35 +6865,35 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesPersonEvolution_add`() BEGIN /** - * Calcula los datos para los gráficos de evolución agrupado por salesPersonFk y día. + * Calcula los datos para los gráficos de evolución agrupado por salesPersonFk y día. * Recalcula automáticamente los 3 últimos meses para comprobar si hay algún cambio. */ DECLARE vDated DATE; DECLARE vCont INT DEFAULT 1; - SELECT MAX(dated) - INTERVAL 3 MONTH INTO vDated + SELECT MAX(dated) - INTERVAL 3 MONTH INTO vDated FROM salesPersonEvolution; - DELETE FROM salesPersonEvolution + DELETE FROM salesPersonEvolution WHERE dated >= vDated; IF ISNULL(vDated) THEN - SELECT MIN(dated) INTO vDated + SELECT MIN(dated) INTO vDated FROM salesByclientSalesPerson; - + INSERT INTO salesPersonEvolution( - salesPersonFk, - dated, - amount, - equalizationTax, + salesPersonFk, + dated, + amount, + equalizationTax, amountNewBorn ) - SELECT salesPersonFk, - dated, - amount, - equalizationTax, + SELECT salesPersonFk, + dated, + amount, + equalizationTax, amountNewBorn - FROM salesByclientSalesPerson + FROM salesByclientSalesPerson WHERE dated = vDated GROUP BY salesPersonFk; @@ -5476,21 +6901,21 @@ BEGIN END IF; WHILE vDated < util.VN_CURDATE() DO - + SET vCont = vCont + 1; REPLACE salesPersonEvolution(salesPersonFk, dated, amount) SELECT salesPersonFk, vDated, amount FROM(SELECT salesPersonFk, SUM(amount) amount FROM(SELECT salesPersonFk, amount - FROM salesPersonEvolution + FROM salesPersonEvolution WHERE dated = vDated - INTERVAL 1 DAY UNION ALL - SELECT salesPersonFk, amount - FROM salesByclientSalesPerson + SELECT salesPersonFk, amount + FROM salesByclientSalesPerson WHERE dated = vDated UNION ALL SELECT salesPersonFk, - amount - FROM salesByclientSalesPerson + FROM salesByclientSalesPerson WHERE dated = vDated - INTERVAL 1 YEAR )sub GROUP BY salesPersonFk @@ -5519,7 +6944,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vendedores_add_launcher`() BEGIN CALL bs.salesByclientSalesPerson_add(util.VN_CURDATE()- INTERVAL 45 DAY); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5543,7 +6968,7 @@ BEGIN /** * Añade las ventas que se realizaron entre * vStarted y vEnded -* +* * @param vStarted Fecha de inicio * @param vEnded Fecha de finalizacion * @@ -5551,7 +6976,7 @@ BEGIN DECLARE vStartingDate DATETIME; DECLARE vEndingDate DATETIME; - IF vStarted < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) + IF vStarted < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) OR vEnded < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) THEN CALL util.throw('fechaDemasiadoAntigua'); END IF; @@ -5560,8 +6985,8 @@ BEGIN SET vStartingDate = vStarted ; SET vEndingDate = util.dayEnd(vStartingDate); - DELETE - FROM sale + DELETE + FROM sale WHERE dated BETWEEN vStartingDate AND vEnded; WHILE vEndingDate <= vEnded DO @@ -5582,28 +7007,28 @@ BEGIN JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.address a ON a.id = t.addressFk + JOIN vn.address a ON a.id = t.addressFk JOIN vn.client cl ON cl.id = a.clientFk WHERE t.shipped BETWEEN vStartingDate AND vEndingDate AND s.quantity <> 0 AND s.discount <> 100 - AND ic.merchandise + AND ic.merchandise GROUP BY sc.saleFk HAVING IFNULL(importe,0) <> 0 OR IFNULL(recargo,0) <> 0; UPDATE sale s JOIN ( - SELECT s.id, + SELECT s.id, SUM(s.quantity * sc.value ) margen, s.quantity * s.price * (100 - s.discount ) / 100 pvp FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.saleComponent sc ON sc.saleFk = s.id - JOIN vn.component c ON c.id = sc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk WHERE t.shipped BETWEEN vStartingDate AND vEndingDate AND ct.isMargin = TRUE - GROUP BY s.id) sub ON sub.id = s.saleFk + GROUP BY s.id) sub ON sub.id = s.saleFk SET s.margin = sub.margen + s.amount + s.surcharge - sub.pvp; SET vStartingDate = TIMESTAMPADD(DAY,1, vStartingDate); @@ -5631,7 +7056,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_add_launcher`() BEGIN /** * Añade las ventas a la tabla bs.sale que se realizaron desde hace un mes hasta hoy - * + * */ DECLARE vCurDate DATE DEFAULT util.VN_CURDATE(); @@ -5655,7 +7080,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add`(IN vYear INT, IN vMonth INT) BEGIN - + /** * Reemplaza las ventas contables del último año. * Es el origen de datos para el balance de Entradas @@ -5667,8 +7092,8 @@ BEGIN DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; - DELETE FROM bs.ventas_contables - WHERE year = vYear + DELETE FROM bs.ventas_contables + WHERE year = vYear AND month = vMonth; DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; @@ -5679,7 +7104,7 @@ BEGIN FROM vn2008.Tickets t JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura WHERE year(f.Fecha) = vYear - AND month(f.Fecha) = vMonth; + AND month(f.Fecha) = vMonth; INSERT INTO bs.ventas_contables(year , month @@ -5689,7 +7114,7 @@ BEGIN , tipo_id , empresa_id , gasto) - + SELECT vYear , vMonth , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) @@ -5701,13 +7126,13 @@ BEGIN , tp.reino_id , a.tipo_id , t.empresa_id - , 7000000000 + , 7000000000 + IF(e.empresa_grupo = e2.empresa_grupo ,1 ,IF(e2.empresa_grupo,2,0) - ) * 1000000 + ) * 1000000 + tp.reino_id * 10000 as Gasto - FROM vn2008.Movimientos m + FROM vn2008.Movimientos m JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente @@ -5721,7 +7146,7 @@ BEGIN AND m.Descuento <> 100 AND a.tipo_id != TIPO_PATRIMONIAL GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto; - + INSERT INTO bs.ventas_contables(year , month , venta @@ -5740,17 +7165,17 @@ BEGIN ) as grupo , NULL , NULL - , t.companyFk + , t.companyFk , 7050000000 - FROM vn.ticketService ts + FROM vn.ticketService ts JOIN vn.ticket t ON ts.ticketFk = t.id - JOIN vn.address a on a.id = t.addressFk - JOIN vn.client cl on cl.id = a.clientFk + JOIN vn.address a on a.id = t.addressFk + JOIN vn.client cl on cl.id = a.clientFk JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id - JOIN vn.company c on c.id = t.companyFk + JOIN vn.company c on c.id = t.companyFk LEFT JOIN vn.company c2 on c2.clientFk = cl.id - GROUP BY grupo, t.companyFk ; - + GROUP BY grupo, t.companyFk ; + DROP TEMPORARY TABLE tmp.ticket_list; END ;; DELIMITER ; @@ -5770,13 +7195,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add_launcher`() BEGIN - + /** * Reemplaza las ventas contables del último año. * Es el origen de datos para el balance de Entradas * **/ - + CALL bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()))); END ;; @@ -5797,12 +7222,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT) BEGIN - + /** * Muestra las ventas (€) de cada cliente * dependiendo del año */ - + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; CREATE TEMPORARY TABLE tmp.ticket_list @@ -5811,8 +7236,8 @@ BEGIN FROM vn2008.Tickets t JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura WHERE year(f.Fecha) = vYear - AND month(f.Fecha) = vMonth; - + AND month(f.Fecha) = vMonth; + SELECT vYear Año, vMonth Mes, t.Id_Cliente, @@ -5822,7 +7247,7 @@ BEGIN IF(e2.empresa_grupo,2,0)) AS grupo, t.empresa_id empresa - FROM vn2008.Movimientos m + FROM vn2008.Movimientos m JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.Id_Consigna JOIN vn2008.Clientes c ON c.Id_Cliente = cs.Id_Cliente @@ -5836,9 +7261,9 @@ BEGIN AND m.Descuento <> 100 AND a.tipo_id != 188 GROUP BY t.Id_Cliente, grupo,t.empresa_id; - + DROP TEMPORARY TABLE tmp.ticket_list; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5857,7 +7282,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `vivosMuertos`() BEGIN - + /** * Devuelve el número de clientes nuevos y muertos, * dependiendo de la fecha actual. @@ -5868,9 +7293,9 @@ BEGIN SET @datSTART = TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); SET @datEND = TIMESTAMPADD(DAY,-DAY(util.VN_CURDATE()),util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos; - + CREATE TEMPORARY TABLE tmp.VivosMuertos SELECT c.Id_Cliente, tm.yearMonth, f.Compra, 0 as Nuevo, 0 as Muerto FROM vn2008.Clientes c @@ -5886,10 +7311,10 @@ BEGIN WHERE Fecha BETWEEN @datSTART AND @datEND) f ON f.yearMonth = tm.yearMonth AND f.Id_Cliente = c.Id_Cliente; - + UPDATE tmp.VivosMuertos vm JOIN - (SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente + (SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente FROM vn2008.Facturas f JOIN vn2008.time tm ON tm.date = f.Fecha WHERE Fecha BETWEEN @datSTART AND @datEND @@ -5897,9 +7322,9 @@ BEGIN AND fm.Id_Cliente = vm.Id_Cliente SET Nuevo = 1; - + SELECT max(yearMonth) INTO @lastYearMonth FROM tmp.VivosMuertos; - + UPDATE tmp.VivosMuertos vm JOIN ( SELECT MAX(tm.yearMonth) firstMonth, f.Id_Cliente @@ -5940,23 +7365,23 @@ BEGIN INTO vWeek, vYear FROM vn.time WHERE dated = util.VN_CURDATE(); - + REPLACE bs.waste SELECT *, 100 * mermas / total as porcentaje FROM ( - SELECT buyer, - year, + SELECT buyer, + year, week, family, itemFk, itemTypeFk, - floor(sum(value)) as total, + floor(sum(value)) as total, floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas - FROM vn.saleValue + FROM vn.saleValue where year = vYear and week = vWeek - + GROUP BY family, itemFk - + ) sub ORDER BY mermas DESC; END ;; @@ -5988,56 +7413,56 @@ BEGIN DECLARE vDateEnded DATE; DECLARE vCursor CURSOR FOR - SELECT util.firstDayOfMonth(t.dated), LAST_DAY(t.dated) + SELECT util.firstDayOfMonth(t.dated), LAST_DAY(t.dated) FROM vn.time t WHERE t.dated BETWEEN vDateStarted AND vDateEnded - GROUP BY year,month; + GROUP BY year,month; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + IF DAY(util.VN_CURDATE()) = 21 THEN - + SELECT util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 12 MONTH)), LAST_DAY(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - INTO vDateStarted, + INTO vDateStarted, vDateEnded; - - DELETE FROM workerLabourDataByMonth + + DELETE FROM workerLabourDataByMonth WHERE CONCAT(`year`, '-',`month`, '-01') BETWEEN vDateStarted AND vDateEnded; OPEN vCursor; l: LOOP SET vDone = FALSE; - + FETCH vCursor INTO vFristDay, vLastDay; - + IF vDone THEN LEAVE l; END IF; - + -- Altas periodo - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.workCenter wc ON wc.id = b.workCenterFk JOIN vn.worker w ON w.id = b.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk LEFT JOIN (SELECT b.id, b.workerFk FROM vn.business b - LEFT JOIN (SELECT ended, workerFk FROM vn.business) wl + LEFT JOIN (SELECT ended, workerFk FROM vn.business) wl ON wl.ended = DATE_SUB(b.started, INTERVAL 1 DAY) AND wl.workerFk = b.workerFk - WHERE b.started BETWEEN vFristDay AND vLastDay AND wl.ended + WHERE b.started BETWEEN vFristDay AND vLastDay AND wl.ended )sub ON sub.workerFk = b.workerFk WHERE wc.payrollCenterFk IS NOT NULL AND b.workCenterFk IS NOT NULL AND b.started BETWEEN vFristDay AND vLastDay AND sub.workerFk IS NULL - AND NOT w.isFreelance; + AND NOT w.isFreelance; -- Bajas periodo - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.worker w ON w.id = b.workerFk JOIN vn.workCenter wc ON wc.id = b.workCenterFk @@ -6048,12 +7473,12 @@ BEGIN AND b.ended BETWEEN vFristDay AND vLastDay AND wl.started IS NULL AND NOT w.isFreelance; - + -- Anterior al periodo SET vLastDay = LAST_DAY(DATE_SUB(vFristDay, INTERVAL 1 DAY)); - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.worker w ON w.id = b.workerFk JOIN vn.workCenter wc ON wc.id = b.workCenterFk @@ -6063,8 +7488,8 @@ BEGIN AND NOT w.isFreelance; -- Discapacidad - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.worker w ON w.id = b.workerFk JOIN vn.workCenter wc ON wc.id = b.workCenterFk @@ -6268,7 +7693,7 @@ CREATE TABLE `cache` ( `lifetime` time NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6292,7 +7717,7 @@ CREATE TABLE `cache_calc` ( KEY `cache_id` (`cache_id`), KEY `cacheName` (`cacheName`), KEY `expires` (`expires`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6361,7 +7786,7 @@ CREATE TABLE `prod_graphic_source` ( `graphCategory` int(11) NOT NULL DEFAULT 0, `Agencia` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6430,7 +7855,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `cacheCalc_clean` ON SCHEDULE EVERY 30 MINUTE STARTS '2022-01-28 09:29:18' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL cacheCalc_clean */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `cacheCalc_clean` ON SCHEDULE EVERY 30 MINUTE STARTS '2022-01-28 09:29:18' ON COMPLETION NOT PRESERVE ENABLE DO CALL cacheCalc_clean */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -6448,7 +7873,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `cache_clean` ON SCHEDULE EVERY 5 MINUTE STARTS '2022-01-28 09:29:18' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL cache_clean */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `cache_clean` ON SCHEDULE EVERY 5 MINUTE STARTS '2022-01-28 09:29:18' ON COMPLETION NOT PRESERVE ENABLE DO CALL cache_clean */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -6473,7 +7898,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addressFriendship_Update`() BEGIN - REPLACE cache.addressFriendship + REPLACE cache.addressFriendship SELECT addressFk1, addressFk2, count(*) friendship FROM ( @@ -6484,7 +7909,7 @@ BEGIN AND t2.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) AND t.addressFk != t2.addressFk) sub GROUP BY addressFk1, addressFk2; - + REPLACE cache.zoneAgencyFriendship SELECT r.agencyModeFk, t.zoneFk, count(*) friendship FROM vn.route r @@ -6658,12 +8083,12 @@ BEGIN FROM available a LEFT JOIN tCalc c ON c.id = a.calc_id WHERE c.id IS NULL; - + DELETE a FROM availableNoRaids a LEFT JOIN tCalc c ON c.id = a.calc_id WHERE c.id IS NULL; - + DROP TEMPORARY TABLE tCalc; END ;; DELIMITER ; @@ -6842,27 +8267,27 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_end`(IN `v_calc` INT) -BEGIN - DECLARE v_cache_name VARCHAR(255); - DECLARE v_params VARCHAR(255); - - -- Libera el bloqueo y actualiza la fecha de ultimo refresco. - - UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id - SET - cc.last_refresh = NOW(), - cc.expires = ADDTIME(NOW(), c.lifetime), - cc.connection_id = NULL - WHERE cc.id = v_calc; - - SELECT c.name, ca.params INTO v_cache_name, v_params - FROM cache c - JOIN cache_calc ca ON c.id = ca.cache_id - WHERE ca.id = v_calc; - - IF v_cache_name IS NOT NULL THEN - DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); - END IF; +BEGIN + DECLARE v_cache_name VARCHAR(255); + DECLARE v_params VARCHAR(255); + + -- Libera el bloqueo y actualiza la fecha de ultimo refresco. + + UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id + SET + cc.last_refresh = NOW(), + cc.expires = ADDTIME(NOW(), c.lifetime), + cc.connection_id = NULL + WHERE cc.id = v_calc; + + SELECT c.name, ca.params INTO v_cache_name, v_params + FROM cache c + JOIN cache_calc ca ON c.id = ca.cache_id + WHERE ca.id = v_calc; + + IF v_cache_name IS NOT NULL THEN + DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -6880,89 +8305,89 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_start`(OUT `v_calc` INT, INOUT `v_refresh` INT, IN `v_cache_name` VARCHAR(50), IN `v_params` VARCHAR(100)) -proc: BEGIN - DECLARE v_valid BOOL; - DECLARE v_lock_id VARCHAR(100); - DECLARE v_cache_id INT; - DECLARE v_expires DATETIME; - DECLARE v_clean_time DATETIME; - DECLARE vLastRefresh DATETIME; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - IF v_lock_id IS NOT NULL THEN - DO RELEASE_LOCK(v_lock_id); - END IF; - - RESIGNAL; - END; - - SET v_params = IFNULL(v_params, ''); - - -- Si el servidor se ha reiniciado invalida todos los calculos. - - SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; - - IF !v_valid - THEN - DELETE FROM cache_calc; - INSERT INTO cache_valid (valid) VALUES (TRUE); - END IF; - - -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. - - SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); - - IF !GET_LOCK(v_lock_id, 30) - THEN - SET v_calc = NULL; - SET v_refresh = FALSE; - LEAVE proc; - END IF; - - -- Comprueba si el calculo solicitado existe y esta actualizado. - - SELECT c.id, ca.id, ca.expires, ca.last_refresh - INTO v_cache_id, v_calc, v_expires, vLastRefresh - FROM cache c - LEFT JOIN cache_calc ca - ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' - WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; - - -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. - - IF !v_refresh AND NOW() < v_expires AND vLastRefresh >= CURDATE() - THEN - DO RELEASE_LOCK(v_lock_id); - SET v_refresh = FALSE; - LEAVE proc; - END IF; - - -- Si el calculo no existe le crea una entrada en la tabla de calculos. - - IF v_calc IS NULL - THEN - INSERT INTO cache_calc SET - cache_id = v_cache_id, - cacheName = v_cache_name, - params = v_params, - last_refresh = NULL, - expires = NULL, - connection_id = CONNECTION_ID(); - - SET v_calc = LAST_INSERT_ID(); - ELSE - UPDATE cache_calc - SET - last_refresh = NULL, - expires = NULL, - connection_id = CONNECTION_ID() - WHERE id = v_calc; - END IF; - - -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. - - SET v_refresh = TRUE; +proc: BEGIN + DECLARE v_valid BOOL; + DECLARE v_lock_id VARCHAR(100); + DECLARE v_cache_id INT; + DECLARE v_expires DATETIME; + DECLARE v_clean_time DATETIME; + DECLARE vLastRefresh DATETIME; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + IF v_lock_id IS NOT NULL THEN + DO RELEASE_LOCK(v_lock_id); + END IF; + + RESIGNAL; + END; + + SET v_params = IFNULL(v_params, ''); + + -- Si el servidor se ha reiniciado invalida todos los calculos. + + SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; + + IF !v_valid + THEN + DELETE FROM cache_calc; + INSERT INTO cache_valid (valid) VALUES (TRUE); + END IF; + + -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. + + SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); + + IF !GET_LOCK(v_lock_id, 30) + THEN + SET v_calc = NULL; + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Comprueba si el calculo solicitado existe y esta actualizado. + + SELECT c.id, ca.id, ca.expires, ca.last_refresh + INTO v_cache_id, v_calc, v_expires, vLastRefresh + FROM cache c + LEFT JOIN cache_calc ca + ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' + WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; + + -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. + + IF !v_refresh AND NOW() < v_expires AND vLastRefresh >= CURDATE() + THEN + DO RELEASE_LOCK(v_lock_id); + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Si el calculo no existe le crea una entrada en la tabla de calculos. + + IF v_calc IS NULL + THEN + INSERT INTO cache_calc SET + cache_id = v_cache_id, + cacheName = v_cache_name, + params = v_params, + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID(); + + SET v_calc = LAST_INSERT_ID(); + ELSE + UPDATE cache_calc + SET + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID() + WHERE id = v_calc; + END IF; + + -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. + + SET v_refresh = TRUE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -6992,7 +8417,7 @@ proc: BEGIN FROM cache c JOIN cache_calc ca ON c.id = ca.cache_id WHERE ca.id = v_calc; - + DELETE FROM cache_calc WHERE id = v_calc; IF v_cache_name IS NOT NULL THEN @@ -7088,7 +8513,7 @@ DECLARE rs CURSOR FOR DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; + SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; OPEN rs; @@ -7097,23 +8522,23 @@ DECLARE rs CURSOR FOR WHILE NOT done DO SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0); - + SET inicioProd = rsDeparture - rsHoras; - + IF inicioProd - resto < myTime THEN - + SET done = TRUE; - + ELSE - + SET departureLimit = rsDeparture; - + FETCH rs INTO rsDeparture, rsHoras , rsInicio; - + -- SELECT rsDeparture, rsHoras , rsInicio; - + END IF; - + END WHILE; SET departureLimit = IFNULL(departureLimit,24); @@ -7158,7 +8583,7 @@ proc: BEGIN DECLARE started DATE; DECLARE ended DATE; DECLARE vLastRefresh DATE; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (vCalc); @@ -7208,14 +8633,14 @@ proc: BEGIN DECLARE datEQ DATETIME; DECLARE timDIF TIME; DECLARE v_calc INT; - + CALL cache_calc_start (v_calc, v_refresh, 'prod_graphic', wh_id); - + IF !v_refresh THEN LEAVE proc; END IF; - + CALL vn2008.production_control_source(wh_id, 0); DELETE FROM prod_graphic_source; @@ -7233,8 +8658,8 @@ proc: BEGIN WHERE Fecha = util.VN_CURDATE() GROUP BY wh_id, graphCategory ; - - + + CALL cache_calc_end (v_calc); END ;; DELIMITER ; @@ -7255,11 +8680,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `stock_refresh`(v_refresh BOOL) proc: BEGIN /** - * Crea o actualiza la cache con el disponible hasta el día de + * Crea o actualiza la cache con el disponible hasta el dí­a de * ayer. Esta cache es usada como base para otros procedimientos - * como el cáculo del visible o del ATP. + * como el cálculo del visible o del ATP. * - * @param v_refresh %TRUE para forzar el recálculo de la cache + * @param v_refresh %TRUE para forzar el recálculo de la cache **/ DECLARE v_calc INT; DECLARE v_date_inv DATE; @@ -7279,23 +8704,23 @@ proc: BEGIN LEAVE proc; END IF; - SET v_date_inv = (SELECT inventoried FROM vn.config LIMIT 1); + SET v_date_inv = vn.getInventoryDate(); SET vCURDATE = util.VN_CURDATE(); - + DELETE FROM stock; - + INSERT INTO stock (item_id, warehouse_id, amount) SELECT item_id, warehouse_id, SUM(amount) amount FROM ( - SELECT itemFk AS item_id, warehouseFk AS warehouse_id, quantity AS amount + SELECT itemFk AS item_id, warehouseFk AS warehouse_id, quantity AS amount FROM vn.itemTicketOut WHERE shipped >= v_date_inv AND shipped < vCURDATE UNION ALL - SELECT itemFk ASitem_id, warehouseInFk AS warehouse_id, quantity AS amount + SELECT itemFk ASitem_id, warehouseInFk AS warehouse_id, quantity AS amount FROM vn.itemEntryIn WHERE landed >= v_date_inv AND landed < vCURDATE AND isVirtualStock is FALSE UNION ALL - SELECT itemFk AS item_id ,warehouseOutFk AS warehouse_id, quantity AS amount + SELECT itemFk AS item_id ,warehouseOutFk AS warehouse_id, quantity AS amount FROM vn.itemEntryOut WHERE shipped >= v_date_inv AND shipped < vCURDATE ) t @@ -7325,12 +8750,12 @@ BEGIN (INDEX (id)) ENGINE = MEMORY SELECT id FROM cache_calc; - + DELETE v FROM visible v LEFT JOIN tCalc c ON c.id = v.calc_id WHERE c.id IS NULL; - + DROP TEMPORARY TABLE tCalc; END ;; DELIMITER ; @@ -7389,6 +8814,235 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `dipole` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `dipole` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `dipole`; + +-- +-- Temporary table structure for view `expeditionControl` +-- + +DROP TABLE IF EXISTS `expeditionControl`; +/*!50001 DROP VIEW IF EXISTS `expeditionControl`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `expeditionControl` AS SELECT + 1 AS `fecha`, + 1 AS `total`, + 1 AS `leidas` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `expedition_PrintOut` +-- + +DROP TABLE IF EXISTS `expedition_PrintOut`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expedition_PrintOut` ( + `expeditionFk` int(11) NOT NULL, + `ticketFk` int(11) NOT NULL, + `addressFk` int(11) NOT NULL, + `street` varchar(100) NOT NULL DEFAULT ' ', + `postalCode` varchar(10) NOT NULL DEFAULT ' ', + `city` varchar(100) NOT NULL DEFAULT ' ', + `shopName` varchar(100) NOT NULL DEFAULT ' ', + `isPrinted` int(11) NOT NULL DEFAULT 0, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `printerFk` tinyint(3) unsigned NOT NULL DEFAULT 0, + `routeFk` int(11) NOT NULL DEFAULT 0, + `parkingCode` varchar(8) NOT NULL DEFAULT ' ', + `truckName` varchar(25) NOT NULL DEFAULT ' ', + `clientFk` int(11) NOT NULL, + `phone` varchar(15) DEFAULT NULL, + `province` varchar(20) NOT NULL, + `agency` varchar(100) DEFAULT NULL, + `m3` decimal(10,3) DEFAULT 0.000, + `workerCode` varchar(25) DEFAULT NULL, + `itemFk` int(11) DEFAULT NULL, + `quantity` int(11) DEFAULT NULL, + `longName` varchar(30) DEFAULT NULL, + `shelvingFk` varchar(5) DEFAULT NULL, + `comments` varchar(100) DEFAULT NULL, + PRIMARY KEY (`expeditionFk`), + KEY `expedition_PrintOut_FK` (`printerFk`), + CONSTRAINT `expedition_PrintOut_FK` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='listado de etiquetas a imprimir'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expedition_Read` +-- + +DROP TABLE IF EXISTS `expedition_Read`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expedition_Read` ( + `expeditionFk` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `readingPointFk` int(11) DEFAULT NULL, + PRIMARY KEY (`expeditionFk`), + KEY `expedition_Read_FK` (`readingPointFk`), + CONSTRAINT `expedition_Read_FK` FOREIGN KEY (`readingPointFk`) REFERENCES `readingPoint` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `printer` +-- + +DROP TABLE IF EXISTS `printer`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `printer` ( + `id` tinyint(3) unsigned NOT NULL, + `description` varchar(50) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `printer_FK` FOREIGN KEY (`id`) REFERENCES `vn`.`printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `readingPoint` +-- + +DROP TABLE IF EXISTS `readingPoint`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `readingPoint` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + `IsCeluveyorDoor` tinyint(1) NOT NULL COMMENT 'define si esta la antena en la entrada del celuveyor y ha de generar un movimiento', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping events for database 'dipole' +-- + +-- +-- Dumping routines for database 'dipole' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() +BEGIN + DECLARE vFromDated DATE; + + SET vFromDated = TIMESTAMPADD(WEEK, -2, util.VN_CURDATE()); + + DELETE FROM dipole.expedition_PrintOut + WHERE created < vFromDated; + + DELETE FROM dipole.expedition_Read + WHERE created < vFromDated; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_add`(vExpeditionFk INT, vPrinterFk INT, vIsPrinted BOOLEAN) +BEGIN +/** Insert records to print agency stickers and to inform sorter with new box + * + * param vExpeditionFk Id for vn.expedition + * param vPrinterFk Id for dipole.printer + * param vIsPrinted Value for field dipole.expedition_PrintOut.isPrinted + */ + INSERT INTO dipole.expedition_PrintOut(expeditionFk, + ticketFk, + addressFk, + street, + postalCode, + city, + shopName, + printerFk, + routeFk, + parkingCode, + truckName, + clientFk, + phone, + province, + agency, + workerCode, + isPrinted) + SELECT e.id, + e.ticketFk, + t.addressFk , + LEFT(a.street, 100), + a.postalCode , + LEFT (CONCAT(IFNULL(rm.beachFk,''),' ',a.city), 13), + a.nickname, + vPrinterFk, + IFNULL(right(`t`.`routeFk`, 3),0), + if (@vVolume := vn.ticketTotalVolume(t.id) > 1.5, @vVolume, IFNULL( rm.beachFk, 0)), + LEFT(IFNULL(et.description ,replace(`z`.`name`, 'ZONA ', 'Z')),14) truckName, + t.clientFk , + ifnull(c.mobile, ifnull(a.mobile, ifnull(c.phone, a.phone))), + LEFT(p.name, 20), + NULL, + w.code, + vIsPrinted + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + LEFT JOIN vn.beach b ON b.code = rm.beachFk + LEFT JOIN vn.`zone`z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON t.agencyModeFk = am.id + JOIN vn.client c ON t.clientFk = c.id + JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN vn.printer pr ON pr.id = vPrinterFk + JOIN vn.worker w ON w.id = e.workerFk + WHERE e.id = vExpeditionFk; + + INSERT INTO srt.expedition (id, + width, + `length`, + height, + stateFk) + SELECT e.id, + p.width * 10, + p.`depth` * 10, + p.height * 10, + es.id + FROM vn.expedition e + LEFT JOIN vn.packaging p ON p.id = e.packagingFk + JOIN srt.expeditionState es ON es.description = 'PRINTED' + WHERE e.id = vExpeditionFk; -- En esa tabla las medidas van en milímetros +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 */ ; + -- -- Current Database: `edi` -- @@ -7545,7 +9199,7 @@ CREATE TABLE `deliveryInformation` ( KEY `fgbSupplyResponse_idx3` (`LatestOrderDateTime`) USING BTREE, KEY `deliveryInformation_updated_IDX` (`updated`) USING BTREE, CONSTRAINT `fgbSupplyResponse` FOREIGN KEY (`supplyResponseID`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7629,7 +9283,7 @@ CREATE TABLE `ekt` ( KEY `ekt_batchNumber` (`batchNumber`) USING BTREE, KEY `ekt_vendorOrderNumber` (`vendorOrderNumber`) USING BTREE, KEY `ekt_sub_IDX` (`sub`) USING BTREE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7747,7 +9401,7 @@ CREATE TABLE `exchange` ( KEY `buy_edi_id` (`ektFk`), CONSTRAINT `exchange_ibfk_1` FOREIGN KEY (`mailFk`) REFERENCES `mail` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `exchange_ibfk_2` FOREIGN KEY (`ektFk`) REFERENCES `ekt` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7766,7 +9420,7 @@ CREATE TABLE `exchangeConfig` ( PRIMARY KEY (`id`), KEY `presale_id` (`presaleFk`), CONSTRAINT `exchangeConfig_ibfk_1` FOREIGN KEY (`presaleFk`) REFERENCES `exchangeType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuration parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7844,7 +9498,7 @@ CREATE TABLE `ftpConfig` ( `user` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `password` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuration parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7956,28 +9610,6 @@ CREATE TABLE `item_feature` ( PRIMARY KEY (`item_id`,`presentation_order`,`entry_date`,`change_date_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='/tmp/floricode/florecompc2/FY130916.txt'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`item_feature_bi` - BEFORE INSERT ON `item_feature` - FOR EACH ROW -BEGIN - IF NEW.expiry_date = '0000-00-00' THEN - SET NEW.expiry_date = 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 */ ; -- -- Table structure for table `item_free` @@ -8074,7 +9706,7 @@ CREATE TABLE `log` ( `fieldValue` varchar(100) DEFAULT NULL, `created` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8097,7 +9729,7 @@ CREATE TABLE `mail` ( UNIQUE KEY `mail_id` (`messageId`), KEY `sender_id` (`senderFk`), CONSTRAINT `mail_ibfk_2` FOREIGN KEY (`senderFk`) REFERENCES `mailSender` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8113,7 +9745,7 @@ CREATE TABLE `mailSender` ( `kop` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mail` (`mail`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='List of allowed mailers'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='List of allowed mailers'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8166,7 +9798,7 @@ CREATE TABLE `offerRefreshConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `dayRange` int(10) unsigned DEFAULT NULL COMMENT 'range of days to update the photos of an article in seconds', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8187,7 +9819,7 @@ CREATE TABLE `param` ( PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), UNIQUE KEY `name` (`name`,`subname`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Parameters to capture of every exchange'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Parameters to capture of every exchange'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8237,171 +9869,8 @@ CREATE TABLE `putOrder` ( KEY `supplyResponseID_idx` (`supplyResponseID`), KEY `putOrder_FK` (`saleFk`), CONSTRAINT `putOrder_FK` FOREIGN KEY (`saleFk`) REFERENCES `vn`.`sale` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`putOrder_BEFORE_INSERT` - BEFORE INSERT ON `putOrder` - FOR EACH ROW -BEGIN - - DECLARE nextID INT; - - SELECT 1 + MAX(id) INTO nextID FROM putOrder ; - - SET NEW.orderTradelineItemID = nextID; - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`BEFORE UPDATE` - BEFORE UPDATE ON `putOrder` - FOR EACH ROW -BEGIN - - DECLARE vError VARCHAR(100) DEFAULT 'Orderregel niet meer teruggevonden op basis van de orderps'; - DECLARE vVmpIdError INT DEFAULT 7; - DECLARE vVmpFk INT; - DECLARE vSupplyResponseNumberOfUnits INT; - - SELECT sr.vmpID INTO vVmpFk - FROM edi.supplyResponse sr - WHERE sr.id = NEW.supplyResponseID; - - IF NEW.OrderStatus = 3 - AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) - AND NEW.error = vError - AND vVmpFk = vVmpIdError - - THEN - - SET NEW.OrderStatus = 2; - - END IF; - - -- Error de disponible menor de lo solicitado - IF NEW.error LIKE 'error2602%' THEN - - SELECT NumberOfUnits INTO vSupplyResponseNumberOfUnits - FROM edi.supplyResponse sr - WHERE sr.ID = NEW.supplyResponseID; - - SET NEW.error = CONCAT('(',vSupplyResponseNumberOfUnits,') ', NEW.error); - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`putOrder_AFTER_UPDATE` - AFTER UPDATE ON `putOrder` - FOR EACH ROW -BEGIN - DECLARE vSaleFk INT; - DECLARE vOrderStatusDenied INT DEFAULT 3; - DECLARE vOrderStatusOK INT DEFAULT 2; - DECLARE vIsEktSender BOOLEAN; - - IF NEW.OrderStatus = vOrderStatusDenied AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN - - SELECT s.id INTO vSaleFk - FROM vn.sale s - JOIN vn.ticket t ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID - WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() - AND i.supplyResponseFk = NEW.supplyResponseID - LIMIT 1; - - UPDATE vn.sale s - JOIN vn.ticket t ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID - SET s.quantity = 0 - WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() - AND i.supplyResponseFk = NEW.supplyResponseID; - - INSERT INTO vn.mail (sender, `subject`, body) - SELECT IF(u.id IS NOT NULL AND c.email IS NOT NULL, - c.email, - CONCAT(account.user_getNameFromId(c.salesPersonFk), '@verdnatura.es') - ), - 'Producto no disponible en Floramondo', - CONCAT('El artículo ', s.concept, ' del ticket ', t.id , ' ha sido cancelado por Floramondo. ', - ' Se ha actualizado la cantidad de ', OLD.quantity,' a 0. ', - IF (u.id IS NOT NULL AND c.email IS NOT NULL , - CONCAT('https://shop.verdnatura.es/#!form=ecomerce%2Fticket&ticket=', t.id ), - CONCAT('https://salix.verdnatura.es/#!/ticket/', t.id ,'/summary'))) - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.`client` c ON c.id = t.clientFk - LEFT JOIN account.user u ON u.id= c.salesPersonFk AND u.name IN ('ruben', 'ismaelalcolea') - WHERE s.id = vSaleFk; - - END IF; - - - IF NEW.OrderStatus = vOrderStatusOK AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN - - SELECT v.isEktSender INTO vIsEktSender - FROM edi.VMPSettings v - JOIN edi.supplyResponse sr ON sr.vmpID = v.VMPID - WHERE sr.id = NEW.supplyResponseID; - - IF NOT vIsEktSender THEN - - CALL edi.ekt_add(NEW.id); - - END IF; - - IF NEW.barcode THEN - - INSERT IGNORE INTO vn.itemBarcode(itemFk, code) - SELECT i.id, NEW.barcode - FROM vn.item i - WHERE i.supplyResponseFk = NEW.supplyResponseID; - - 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 */ ; -- -- Table structure for table `specie` @@ -8571,41 +10040,8 @@ CREATE TABLE `supplyResponse` ( KEY `supplyResponse_updated_IDX` (`updated`) USING BTREE, CONSTRAINT `supplyResponse_fk2` FOREIGN KEY (`MarketPlaceID`) REFERENCES `marketPlace` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `supplyResponseputOrder_FK` FOREIGN KEY (`vmpID`) REFERENCES `VMPSettings` (`VMPID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`supplyResponse_AFTER_UPDATE` - AFTER UPDATE ON `supplyResponse` - FOR EACH ROW -BEGIN - - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - SET b.quantity = NEW.NumberOfItemsPerCask * NEW.NumberOfUnits, - b.stickers = NEW.NumberOfUnits - WHERE i.supplyResponseFk = NEW.ID - AND am.name = 'LOGIFLORA' - AND e.isRaid - AND tr.landed >= util.VN_CURDATE(); - -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 `supplyResponseLog` @@ -8624,7 +10060,7 @@ CREATE TABLE `supplyResponseLog` ( PRIMARY KEY (`id`), KEY `supplyResponseLog_FK` (`supplyResponseFk`), CONSTRAINT `supplyResponseLog_FK` FOREIGN KEY (`supplyResponseFk`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Esta tabla la utiliza la empresa LOGIFLORA. No kkear.'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Esta tabla la utiliza la empresa LOGIFLORA. No kkear.'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8716,7 +10152,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `floramondo` ON SCHEDULE EVERY 6 MINUTE STARTS '2022-01-28 09:52:45' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL edi.floramondo_offerRefresh() */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `floramondo` ON SCHEDULE EVERY 6 MINUTE STARTS '2022-01-28 09:52:45' ON COMPLETION NOT PRESERVE DISABLE DO CALL edi.floramondo_offerRefresh() */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -8741,7 +10177,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `imageName`(vPictureReference VARCHAR(255)) RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + SET vPictureReference = REPLACE(vPictureReference,'.',''); SET vPictureReference = REPLACE(vPictureReference,'/',''); @@ -8753,7 +10189,7 @@ BEGIN SET vPictureReference = REPLACE(vPictureReference,'?',''); SET vPictureReference = REPLACE(vPictureReference,'=',''); - + RETURN vPictureReference; END ;; @@ -8809,27 +10245,27 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deliveryInformation_Delete`() BEGIN - + DECLARE vID INT; DECLARE vGap INT DEFAULT 100; DECLARE vTope INT; - - SELECT MIN(ID), MAX(ID) + + SELECT MIN(ID), MAX(ID) INTO vID, vTope FROM edi.deliveryInformation; - WHILE vID <= vTope DO - + WHILE vID <= vTope DO + SET vID = vID + vGap; - - DELETE - FROM edi.deliveryInformation + + DELETE + FROM edi.deliveryInformation WHERE ID < vID AND EarliestDespatchDateTime IS NULL; - + END WHILE; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8848,15 +10284,15 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_add`(vPutOrderFk INT) BEGIN - + /** * Añade ekt para las ordenes de compra de proveedores que no envian el ekt por email - * + * * @param vPutOrderFk PutOrderId de donde coger los datos **/ - - INSERT INTO edi.ekt(entryYear, - deliveryNumber, + + INSERT INTO edi.ekt(entryYear, + deliveryNumber, fec, hor, item, @@ -8896,17 +10332,17 @@ BEGIN i.value10 s6, p.id putOrderFk, sr.Item_ArticleCode, - sr.vmpID + sr.vmpID FROM edi.putOrder p - JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID - JOIN edi.deliveryInformation di ON di.id = p.deliveryInformationID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN vn.origin o ON o.id = i.originFk + JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID + JOIN edi.deliveryInformation di ON di.id = p.deliveryInformationID + JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + JOIN vn.item i ON i.supplyResponseFk = sr.ID + JOIN vn.origin o ON o.id = i.originFk WHERE p.id = vPutOrderFk; - + CALL edi.ekt_load(LAST_INSERT_ID()); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8925,7 +10361,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_load`(IN `vSelf` INT) proc:BEGIN - + DECLARE vRef INT; DECLARE vBuy INT; DECLARE vItem INT; @@ -8950,51 +10386,51 @@ proc:BEGIN FROM edi.ekt e LEFT JOIN edi.item i ON e.ref = i.id LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk - LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID + LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID LEFT JOIN vn.ektEntryAssign eea ON eea.sub = e.sub LEFT JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id WHERE e.id = vSelf LIMIT 1; - + IF NOT vHasItemGroup THEN - + CALL vn.mail_insert('logistica@verdnatura.es', 'nocontestar@verdnatura.es', 'Nuevo grupo en Floramondo', vDescription); - + CALL vn.mail_insert('pako@verdnatura.es', 'nocontestar@verdnatura.es', CONCAT('Nuevo grupo en Floramondo: ', vDescription), vDescription); - + LEAVE proc; - + END IF; - + -- Asigna la entrada SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; - + -- Inserta el cubo si no existe IF vPackage = 800 THEN - + SET vHasToChangePackagingFk = TRUE; - + IF vItem THEN - + SELECT vn.item_getPackage(vItem) INTO vPackage ; - + ELSE - + SET vPackage = 8000 + vQty; INSERT IGNORE INTO vn.packaging(id, width, `depth`) SELECT vPackage, vc.ccLength / vQty, vc.ccWidth FROM vn.volumeConfig vc; - + END IF; - + ELSE - + INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z) SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10) FROM bucket WHERE bucket_id = vPackage; - + IF ROW_COUNT() > 0 THEN INSERT INTO vn2008.mail SET @@ -9003,27 +10439,27 @@ proc:BEGIN `to` = 'ekt@verdnatura.es'; END IF; END IF; - + -- Si es una compra de Logiflora obtiene el articulo IF vPutOrderFk THEN - + SELECT i.id INTO vItem FROM edi.putOrder po JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID WHERE po.id = vPutOrderFk LIMIT 1; - + END IF; INSERT IGNORE INTO item_track SET item_id = vRef; - + IF IFNULL(vItem,0) = 0 THEN - + -- Intenta obtener el artículo en base a los atributos holandeses - + SELECT b.id, IFNULL(b.itemOriginalFk ,b.itemFk) INTO vBuy, vItem - FROM edi.ekt e + FROM edi.ekt e JOIN edi.item_track t ON t.item_id = e.ref LEFT JOIN edi.ekt l ON l.ref = e.ref LEFT JOIN vn.buy b ON b.ektFk = l.id @@ -9044,19 +10480,19 @@ proc:BEGIN AND IF(t.pro, l.pro = e.pro, TRUE) AND IF(t.package, l.package = e.package, TRUE) AND IF(t.item, l.item = e.item, TRUE) - AND i.isFloramondo = vIsFloramondoDirect - ORDER BY l.now DESC, b.id ASC + AND i.isFloramondo = vIsFloramondoDirect + ORDER BY l.now DESC, b.id ASC LIMIT 1; END IF; - + -- Si no encuentra el articulo lo crea en el caso de las compras directas en Floramondo IF ISNULL(vItem) AND vIsFloramondoDirect THEN - + CALL edi.item_getNewByEkt(vSelf, vItem); - + END IF; - + INSERT INTO vn.buy ( entryFk @@ -9079,15 +10515,15 @@ proc:BEGIN ,e.qty stickers ,@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing ,IFNULL(b.`grouping`, e.pac) - ,@pac * e.qty + ,@pac * e.qty ,vForceToPacking ,IF(vHasToChangePackagingFk OR ISNULL(b.packagingFk), vPackage, b.packagingFk) ,(IFNULL(i.weightByPiece,0) * @pac)/1000 - FROM edi.ekt e + FROM edi.ekt e LEFT JOIN vn.buy b ON b.id = vBuy LEFT JOIN vn.item i ON i.id = b.itemFk LEFT JOIN vn.supplier s ON e.pro = s.id - JOIN vn2008.config cfg + JOIN vn2008.config cfg WHERE e.id = vSelf LIMIT 1; @@ -9095,36 +10531,36 @@ proc:BEGIN CREATE TEMPORARY TABLE tmp.buyRecalc SELECT buy.id - FROM vn.buy + FROM vn.buy WHERE ektFk = vSelf; CALL vn.buy_recalcPrices(); -- Si es una compra de Logiflora hay que informar la tabla vn.saleBuy IF vPutOrderFk THEN - + REPLACE vn.saleBuy(saleFk, buyFk, workerFk) SELECT po.saleFk, b.id, account.myUser_getId() FROM edi.putOrder po JOIN vn.buy b ON b.ektFk = vSelf WHERE po.id = vPutOrderFk; - + END IF; - -- Si es una compra directa en Floramondo hay que añadirlo al ticket + -- Si es una compra directa en Floramondo hay que añadirlo al ticket IF vIsFloramondoDirect THEN SELECT t.id INTO vTicketFk FROM vn.ticket t - JOIN vn.ektEntryAssign eea - ON eea.addressFk = t.addressFk + JOIN vn.ektEntryAssign eea + ON eea.addressFk = t.addressFk AND t.warehouseFk = eea.warehouseInFk - JOIN edi.ekt e - ON e.sub = eea.sub + JOIN edi.ekt e + ON e.sub = eea.sub AND e.id = vSelf WHERE e.fec = t.shipped LIMIT 1; - + IF ISNULL(vTicketFk) THEN INSERT INTO vn.ticket ( @@ -9152,8 +10588,8 @@ proc:BEGIN z.id, z.price, z.bonus - FROM edi.ekt e - JOIN vn.ektEntryAssign eea ON eea.sub = e.sub + FROM edi.ekt e + JOIN vn.ektEntryAssign eea ON eea.sub = e.sub JOIN vn.address a ON a.id = eea.addressFk JOIN vn.company c ON c.code = 'VNL' JOIN vn.`zone` z ON z.code = 'FLORAMONDO' @@ -9161,11 +10597,11 @@ proc:BEGIN LIMIT 1; SET vTicketFk = LAST_INSERT_ID(); - + INSERT INTO vn.ticketLog - SET originFk = vTicketFk, - userFk = account.myUser_getId(), - `action` = 'insert', + SET originFk = vTicketFk, + userFk = account.myUser_getId(), + `action` = 'insert', description = CONCAT('EktLoad ha creado el ticket:', ' ', vTicketFk); END IF; @@ -9175,9 +10611,9 @@ proc:BEGIN FROM edi.ekt e JOIN edi.floraHollandConfig fhc WHERE e.id = vSelf; - + SELECT LAST_INSERT_ID() INTO vSaleFk; - + REPLACE vn.saleBuy(saleFk, buyFk, workerFk) SELECT vSaleFk, b.id, account.myUser_getId() FROM vn.buy b @@ -9188,9 +10624,9 @@ proc:BEGIN FROM edi.ekt e JOIN vn.component c ON c.code = 'purchaseValue' WHERE e.id = vSelf; - + INSERT INTO vn.saleComponent(saleFk, componentFk, value) - SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin + SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin FROM edi.ekt e JOIN edi.floraHollandConfig fhc JOIN vn.component c ON c.code = 'margin' @@ -9331,7 +10767,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_scan`(vBarcode VARCHAR(512)) BEGIN /** * Busca transaciones a partir de un código de barras, las marca como escaneadas - * y las devuelve. + * y las devuelve. * Ver https://wiki.verdnatura.es/index.php/Ekt#Algoritmos_de_lectura * * @param vBarcode Código de compra de una etiqueta de subasta @@ -9370,19 +10806,19 @@ BEGIN ENGINE = MEMORY SELECT id ektFk FROM ekt LIMIT 0; - CASE + CASE WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e WHERE e.cps = vBarcode OR e.batchNumber = vBarcode; WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN INSERT INTO tmp.ekt - SELECT e.id + SELECT e.id FROM edi.ektRecent e - WHERE e.pro = MID(vBarcode,2,6) + WHERE e.pro = MID(vBarcode,2,6) AND CAST(e.ptd AS SIGNED) = MID(vBarcode,8,5); ELSE @@ -9397,7 +10833,7 @@ BEGIN -- Clásico de subasta -- Trade standard -- Trade que construye como la subasta - -- Trade como el anterior pero sin trade code + -- Trade como el anterior pero sin trade code INSERT INTO tmp.ekt SELECT id FROM ekt @@ -9418,9 +10854,9 @@ BEGIN -- BatchNumber largo IF NOT vIsFound THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e - WHERE e.batchNumber + WHERE e.batchNumber = LEFT(vBarcode,vUsefulAuctionLeftSegmentLength) AND e.batchNumber > 0; @@ -9430,7 +10866,7 @@ BEGIN -- Order Number IF NOT vIsFound THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e WHERE e.putOrderFk = vBarcode; @@ -9440,7 +10876,7 @@ BEGIN -- deliveryNumber incrustado IF NOT vIsFound THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e WHERE e.deliveryNumber = MID(vBarcode, 4, 13) @@ -9451,7 +10887,7 @@ BEGIN END CASE; IF vIsFound THEN - UPDATE ekt e + UPDATE ekt e JOIN tmp.ekt t ON t.ektFk = e.id SET e.scanned = TRUE; END IF; @@ -9472,524 +10908,524 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `floramondo_offerRefresh`() -proc: BEGIN - DECLARE vLanded DATETIME; - DECLARE vDone INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 10000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - DECLARE vDayRange INT; - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); - SET @isTriggerDisabled = FALSE; - RESIGNAL; - END; - - IF 'test' = (SELECT environment FROM util.config) THEN - LEAVE proc; - END IF; - - IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN - LEAVE proc; - END IF; - - SELECT dayRange INTO vDayRange - FROM offerRefreshConfig; - - IF vDayRange IS NULL THEN - CALL util.throw("Variable vDayRange not declared"); - END IF; - - SET vStartingTime = util.VN_NOW(); - - TRUNCATE edi.offerList; - - INSERT INTO edi.offerList(supplier, total) - SELECT v.name, COUNT(DISTINCT sr.ID) total - FROM edi.supplyResponse sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - WHERE sr.NumberOfUnits > 0 - AND sr.EmbalageCode != 999 - GROUP BY sr.vmpID; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(*) total - FROM edi.supplyOffer sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.`filter` = sub.total; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - CREATE OR REPLACE TEMPORARY TABLE tmp - (INDEX (`Item_ArticleCode`)) - ENGINE = MEMORY - SELECT t.* - FROM ( - SELECT * - FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, - NumberOfUnits DESC LIMIT 10000000000000000000) t - GROUP BY t.srId; - - CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), - INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), - INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) - ENGINE = MEMORY - SELECT so.*, - ev1.type_description s1Value, - ev2.type_description s2Value, - ev3.type_description s3Value, - ev4.type_description s4Value, - ev5.type_description s5Value, - ev6.type_description s6Value, - eif1.feature ef1, - eif2.feature ef2, - eif3.feature ef3, - eif4.feature ef4, - eif5.feature ef5, - eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 - AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 - AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 - AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 - AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 - AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 - AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature - AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature - AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature - AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature - AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature - AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature - AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - DELETE o - FROM edi.offer o - LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' - LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' - LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' - LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' - LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' - LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' - JOIN vn.floramondoConfig fc ON TRUE - WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) - OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) - OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) - OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) - OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) - OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk - AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk - AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) - SET i.supplyResponseFk = o.srID - WHERE (sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() - OR di.ID IS NULL) - AND it.isInventory - AND t.id IS NULL - AND po.id IS NULL; - - CREATE OR REPLACE TEMPORARY TABLE itemToInsert - ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF vDone THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item(id, - `name`, - longName, - subName, - expenseFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT iti.itemFk, - iti.product_name, - iti.product_name, - iti.company_name, - iti.expenseFk, - iti.itemTypeFk, - iti.intrastatFk, - iti.originFk, - iti.`srId`, - iti.NumberOfItemsPerCask, - iti.EmbalageCode, - iti.Quality, - TRUE - FROM itemToInsert iti; - - -- Inserta la foto de los articulos nuevos (prioridad alta) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL - AND i.image IS NULL; - - INSERT INTO edi.`log`(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - -- Inserta los tags sólo en los articulos nuevos - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.product_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.Quality IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.company_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s1Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s2Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s3Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s4Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s5Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s6Value IS NULL; - - INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id - AND tp.`description` = 'Hoofdkleur 1' - LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value - LEFT JOIN vn.itemInk ik ON ik.longName = i.longName - WHERE ink.name IS NOT NULL - OR ik.color IS NOT NULL; - - CREATE OR REPLACE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - DROP TABLE tmp.item; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF( - fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), - util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - -- Elimina la oferta obsoleta - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() - OR i.supplyResponseFk IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); - - IF vLanded IS NOT NULL THEN - -- Actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask - OR b.buyingValue <> o.price); - - -- Inserta el resto - SET vLastInserted := util.VN_NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy ( - entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packageFk, - deliveryFk) - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask quantity, - o.Price, - o.NumberOfUnits etiquetas, - o.NumberOfItemsPerCask packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, - 2, -- Obliga al Packing - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN edi.warehouseFloramondo wf - JOIN vn.packaging p ON p.id - LIKE o.embalageCode - LEFT JOIN vn.buy b ON b.itemFk = i.id - AND b.entryFk = wf.entryFk - WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL - - INSERT INTO vn.itemCost( - itemFk, - warehouseFk, - cm3, - cm3delivery) - SELECT b.itemFk, - wf.warehouseFk, - @cm3 := vn.buy_getUnitVolume(b.id), - IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) - FROM warehouseFloramondo wf - JOIN vn.volumeConfig vc - JOIN vn.buy b ON b.entryFk = wf.entryFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk - AND ic.warehouseFk = wf.warehouseFk - WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) - ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); - - CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'VNH' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.vnh = sub.total; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'ALGEMESI' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.algemesi = sub.total; - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - SET @isTriggerDisabled = FALSE; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - -- Refresca las fotos de los items existentes que mostramos (prioridad baja) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) - SELECT i.id, sr.PictureReference, 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN edi.supplyOffer so ON so.srId = sr.ID - JOIN hedera.image i2 ON i2.name = i.image - AND i2.collectionFk = 'catalog' - WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) - AND sr.NumberOfUnits; - - INSERT INTO edi.`log` - SET tableName = 'floramondo_offerRefresh', - fieldName = 'Tiempo de proceso', - fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); - - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); +proc: BEGIN + DECLARE vLanded DATETIME; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vFreeId INT; + DECLARE vSupplyResponseFk INT; + DECLARE vLastInserted DATETIME; + DECLARE vIsAuctionDay BOOLEAN; + DECLARE vMaxNewItems INT DEFAULT 10000; + DECLARE vStartingTime DATETIME; + DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; + DECLARE vDayRange INT; + + DECLARE cur1 CURSOR FOR + SELECT id + FROM edi.item_free; + + DECLARE cur2 CURSOR FOR + SELECT srId + FROM itemToInsert; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('edi.floramondo_offerRefresh'); + SET @isTriggerDisabled = FALSE; + RESIGNAL; + END; + + IF 'test' = (SELECT environment FROM util.config) THEN + LEAVE proc; + END IF; + + IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN + LEAVE proc; + END IF; + + SELECT dayRange INTO vDayRange + FROM offerRefreshConfig; + + IF vDayRange IS NULL THEN + CALL util.throw("Variable vDayRange not declared"); + END IF; + + SET vStartingTime = util.VN_NOW(); + + TRUNCATE edi.offerList; + + INSERT INTO edi.offerList(supplier, total) + SELECT v.name, COUNT(DISTINCT sr.ID) total + FROM edi.supplyResponse sr + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + WHERE sr.NumberOfUnits > 0 + AND sr.EmbalageCode != 999 + GROUP BY sr.vmpID; + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(*) total + FROM edi.supplyOffer sr + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.`filter` = sub.total; + + -- Elimina de la lista de items libres aquellos que ya existen + DELETE itf.* + FROM edi.item_free itf + JOIN vn.item i ON i.id = itf.id; + + CREATE OR REPLACE TEMPORARY TABLE tmp + (INDEX (`Item_ArticleCode`)) + ENGINE = MEMORY + SELECT t.* + FROM ( + SELECT * + FROM edi.supplyOffer + ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, + NumberOfUnits DESC LIMIT 10000000000000000000) t + GROUP BY t.srId; + + CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), + INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), + INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) + ENGINE = MEMORY + SELECT so.*, + ev1.type_description s1Value, + ev2.type_description s2Value, + ev3.type_description s3Value, + ev4.type_description s4Value, + ev5.type_description s5Value, + ev6.type_description s6Value, + eif1.feature ef1, + eif2.feature ef2, + eif3.feature ef3, + eif4.feature ef4, + eif5.feature ef5, + eif6.feature ef6 + FROM tmp so + LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode + AND eif1.presentation_order = 1 + AND eif1.expiry_date IS NULL + LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode + AND eif2.presentation_order = 2 + AND eif2.expiry_date IS NULL + LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode + AND eif3.presentation_order = 3 + AND eif3.expiry_date IS NULL + LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode + AND eif4.presentation_order = 4 + AND eif4.expiry_date IS NULL + LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode + AND eif5.presentation_order = 5 + AND eif5.expiry_date IS NULL + LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode + AND eif6.presentation_order = 6 + AND eif6.expiry_date IS NULL + LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature + AND so.s1 = ev1.type_value + LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature + AND so.s2 = ev2.type_value + LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature + AND so.s3 = ev3.type_value + LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature + AND so.s4 = ev4.type_value + LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature + AND so.s5 = ev5.type_value + LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature + AND so.s6 = ev6.type_value + ORDER BY Price; + + DROP TEMPORARY TABLE tmp; + + DELETE o + FROM edi.offer o + LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' + LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' + LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' + LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' + LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' + LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' + JOIN vn.floramondoConfig fc ON TRUE + WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) + OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) + OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) + OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) + OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) + OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); + + START TRANSACTION; + + -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos + UPDATE IGNORE edi.offer o + JOIN vn.item i + ON i.name = o.product_name + AND i.subname <=> o.company_name + AND i.value5 <=> o.s1Value + AND i.value6 <=> o.s2Value + AND i.value7 <=> o.s3Value + AND i.value8 <=> o.s4Value + AND i.value9 <=> o.s5Value + AND i.value10 <=> o.s6Value + AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask + AND i.EmbalageCode <=> o.EmbalageCode + AND i.quality <=> o.Quality + JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN vn.sale s ON s.itemFk = i.id + LEFT JOIN vn.ticket t ON t.id = s.ticketFk + AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) + LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk + AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) + SET i.supplyResponseFk = o.srID + WHERE (sr.ID IS NULL + OR sr.NumberOfUnits = 0 + OR di.LatestOrderDateTime < util.VN_NOW() + OR di.ID IS NULL) + AND it.isInventory + AND t.id IS NULL + AND po.id IS NULL; + + CREATE OR REPLACE TEMPORARY TABLE itemToInsert + ENGINE = MEMORY + SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk + FROM edi.offer o + LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId + WHERE i.id IS NULL + LIMIT vMaxNewItems; + + -- Reciclado de nº de item + OPEN cur1; + OPEN cur2; + + read_loop: LOOP + + FETCH cur2 INTO vSupplyResponseFk; + FETCH cur1 INTO vFreeId; + + IF vDone THEN + LEAVE read_loop; + END IF; + + UPDATE itemToInsert + SET itemFk = vFreeId + WHERE srId = vSupplyResponseFk; + + END LOOP; + + CLOSE cur1; + CLOSE cur2; + + -- Insertamos todos los items en Articles de la oferta + INSERT INTO vn.item(id, + `name`, + longName, + subName, + expenseFk, + typeFk, + intrastatFk, + originFk, + supplyResponseFk, + numberOfItemsPerCask, + embalageCode, + quality, + isFloramondo) + SELECT iti.itemFk, + iti.product_name, + iti.product_name, + iti.company_name, + iti.expenseFk, + iti.itemTypeFk, + iti.intrastatFk, + iti.originFk, + iti.`srId`, + iti.NumberOfItemsPerCask, + iti.EmbalageCode, + iti.Quality, + TRUE + FROM itemToInsert iti; + + -- Inserta la foto de los articulos nuevos (prioridad alta) + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) + SELECT i.id, PictureReference + FROM itemToInsert ii + JOIN vn.item i ON i.supplyResponseFk = ii.srId + WHERE PictureReference IS NOT NULL + AND i.image IS NULL; + + INSERT INTO edi.`log`(tableName, fieldName,fieldValue) + SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) + FROM vn.itemImageQueue + WHERE attempts = 0; + + -- Inserta si se añadiesen tags nuevos + INSERT IGNORE INTO vn.tag (name, ediTypeFk) + SELECT description, type_id FROM edi.type; + + -- Desabilita el trigger para recalcular los tags al final + SET @isTriggerDisabled = TRUE; + + -- Inserta los tags sólo en los articulos nuevos + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.product_name, 1 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Producto' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.product_name IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.Quality, 3 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Calidad' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.Quality IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.company_name, 4 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Productor' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.company_name IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s1Value, 5 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef1 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s1Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s2Value, 6 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef2 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s2Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s3Value, 7 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef3 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s3Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s4Value, 8 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef4 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s4Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s5Value, 9 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef5 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s5Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s6Value, 10 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef6 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s6Value IS NULL; + + INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 + FROM itemToInsert ii + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + JOIN vn.tag t ON t.`name` = 'Color' + LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode + LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id + AND tp.`description` = 'Hoofdkleur 1' + LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value + LEFT JOIN vn.itemInk ik ON ik.longName = i.longName + WHERE ink.name IS NOT NULL + OR ik.color IS NOT NULL; + + CREATE OR REPLACE TABLE tmp.item + (PRIMARY KEY (id)) + SELECT i.id FROM vn.item i + JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; + + CALL vn.item_refreshTags(); + + DROP TABLE tmp.item; + + SELECT MIN(LatestDeliveryDateTime) INTO vLanded + FROM edi.supplyResponse sr + JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + JOIN vn.floramondoConfig fc + WHERE mp.isLatestOrderDateTimeRelevant + AND di.LatestOrderDateTime > IF( + fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), + util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY); + + UPDATE vn.floramondoConfig + SET nextLanded = vLanded + WHERE vLanded IS NOT NULL; + + -- Elimina la oferta obsoleta + UPDATE vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID + LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk + SET b.quantity = 0 + WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() + OR i.supplyResponseFk IS NULL + OR sr.NumberOfUnits = 0) + AND am.name = 'LOGIFLORA' + AND e.isRaid; + + -- Localiza las entradas de cada almacen + UPDATE edi.warehouseFloramondo + SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); + + IF vLanded IS NOT NULL THEN + -- Actualiza la oferta existente + UPDATE vn.buy b + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.offer o ON i.supplyResponseFk = o.`srId` + SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, + b.buyingValue = o.price + WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask + OR b.buyingValue <> o.price); + + -- Inserta el resto + SET vLastInserted := util.VN_NOW(); + + -- Inserta la oferta + INSERT INTO vn.buy ( + entryFk, + itemFk, + quantity, + buyingValue, + stickers, + packing, + `grouping`, + groupingMode, + packagingFk, + deliveryFk) + SELECT wf.entryFk, + i.id, + o.NumberOfUnits * o.NumberOfItemsPerCask quantity, + o.Price, + o.NumberOfUnits etiquetas, + o.NumberOfItemsPerCask packing, + GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, + 2, -- Obliga al Packing + o.embalageCode, + o.diId + FROM edi.offer o + JOIN vn.item i ON i.supplyResponseFk = o.srId + JOIN edi.warehouseFloramondo wf + JOIN vn.packaging p ON p.id + LIKE o.embalageCode + LEFT JOIN vn.buy b ON b.itemFk = i.id + AND b.entryFk = wf.entryFk + WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL + + INSERT INTO vn.itemCost( + itemFk, + warehouseFk, + cm3, + cm3delivery) + SELECT b.itemFk, + wf.warehouseFk, + @cm3 := vn.buy_getUnitVolume(b.id), + IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) + FROM warehouseFloramondo wf + JOIN vn.volumeConfig vc + JOIN vn.buy b ON b.entryFk = wf.entryFk + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk + AND ic.warehouseFk = wf.warehouseFk + WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) + ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); + + CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc + SELECT b.id + FROM vn.buy b + JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk + WHERE b.created >= vLastInserted; + + CALL vn.buy_recalcPrices(); + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.warehouse w ON w.id = wf.warehouseFk + WHERE w.name = 'VNH' + AND b.quantity > 0 + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.vnh = sub.total; + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.warehouse w ON w.id = wf.warehouseFk + WHERE w.name = 'ALGEMESI' + AND b.quantity > 0 + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.algemesi = sub.total; + END IF; + + DROP TEMPORARY TABLE + edi.offer, + itemToInsert; + + SET @isTriggerDisabled = FALSE; + + COMMIT; + + -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias + UPDATE vn.item i + SET typeFk = 121 + WHERE i.longName LIKE 'Rosa Garden %' + AND typeFk = 17; + + UPDATE vn.item i + SET typeFk = 156 + WHERE i.longName LIKE 'Rosa ec %' + AND typeFk = 17; + + -- Refresca las fotos de los items existentes que mostramos (prioridad baja) + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) + SELECT i.id, sr.PictureReference, 100 + FROM edi.supplyResponse sr + JOIN vn.item i ON i.supplyResponseFk = sr.ID + JOIN edi.supplyOffer so ON so.srId = sr.ID + JOIN hedera.image i2 ON i2.name = i.image + AND i2.collectionFk = 'catalog' + WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) + AND sr.NumberOfUnits; + + INSERT INTO edi.`log` + SET tableName = 'floramondo_offerRefresh', + fieldName = 'Tiempo de proceso', + fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); + + DO RELEASE_LOCK('edi.floramondo_offerRefresh'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -10056,7 +11492,7 @@ BEGIN /** * Devuelve un número nuevo de item a partir de un registro de la tabla edi.ekt - * + * * @param vEktFk Identificador de la tabla edi.ekt */ @@ -10065,17 +11501,17 @@ BEGIN SELECT MIN(id) id INTO vItemFk FROM edi.item_free; - DELETE FROM edi.item_free + DELETE FROM edi.item_free WHERE id = vItemFk; - + COMMIT; - + IF ISNULL(vItemFk) THEN SELECT MAX(i.id) + 1 INTO vItemFk FROM vn.item i; END IF; - + INSERT INTO vn.item(id, `name`, longName, @@ -10101,118 +11537,118 @@ BEGIN least(IF((e.package = 800),((e.package * 10) + e.pac), e.package), IFNULL(idt.bucket_id, '999')) packageFk, e.cat, TRUE - FROM edi.ekt e - JOIN edi.item i ON i.id = e.`ref` - JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id - LEFT JOIN edi.item_defaultType idt ON idt.item_id = e.`ref` + FROM edi.ekt e + JOIN edi.item i ON i.id = e.`ref` + JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id + LEFT JOIN edi.item_defaultType idt ON idt.item_id = e.`ref` WHERE e.id = vEktFk; SET @isTriggerDisabled = TRUE; - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.item , 1 - FROM edi.ekt e + SELECT vItemFk, t.id , e.item , 1 + FROM edi.ekt e JOIN vn.tag t ON t.`name` = 'Producto' WHERE e.id = vEktFk AND NOT ISNULL(e.item); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.cat , 3 - FROM edi.ekt e + SELECT vItemFk, t.id , e.cat , 3 + FROM edi.ekt e JOIN vn.tag t ON t.`name` = 'Calidad' WHERE e.id = vEktFk AND NOT ISNULL(e.cat); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , s.company_name , 4 - FROM edi.ekt e + SELECT vItemFk, t.id , s.company_name , 4 + FROM edi.ekt e JOIN edi.supplier s ON s.supplier_id = e.pro JOIN vn.tag t ON t.`name` = 'Productor' WHERE e.id = vEktFk AND NOT ISNULL(s.company_name); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s1, 5 + SELECT vItemFk, t.id , e.s1, 5 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` - AND eif.presentation_order = 1 + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 1 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s1 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s1); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s2, 6 + SELECT vItemFk, t.id , e.s2, 6 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` - AND eif.presentation_order = 2 + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 2 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s2 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s2); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s3, 7 + SELECT vItemFk, t.id , e.s3, 7 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` - AND eif.presentation_order = 3 + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 3 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s3 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s3); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s4, 8 + SELECT vItemFk, t.id , e.s4, 8 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` AND eif.presentation_order = 4 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s4 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s4); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s5, 9 + SELECT vItemFk, t.id , e.s5, 9 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` AND eif.presentation_order = 5 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s5 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s5); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s6, 10 + SELECT vItemFk, t.id , e.s6, 10 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` AND eif.presentation_order = 6 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s6 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s6); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id, IFNULL(ink.name, ik.color), 11 - FROM edi.ekt e + SELECT vItemFk, t.id, IFNULL(ink.name, ik.color), 11 + FROM edi.ekt e JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = e.`ref` + LEFT JOIN edi.feature f ON f.item_id = e.`ref` LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id AND tp.`description` = 'Hoofdkleur 1' LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value LEFT JOIN vn.itemInk ik ON ik.longName = e.item WHERE e.id = vEktFk - AND ( ink.name IS NOT NULL + AND ( ink.name IS NOT NULL OR ik.color IS NOT NULL) LIMIT 1; @@ -10279,7 +11715,7 @@ BEGIN sender = vSender, senderFk = vSenderId, messageId = vMessageId; - + IF vIsDuplicated THEN SELECT id INTO vSelf FROM mail @@ -10354,7 +11790,7 @@ CREATE TABLE `config` ( `dmsDir` varchar(255) DEFAULT NULL COMMENT 'Directory where documents are allocated', PRIMARY KEY (`id`), KEY `jwtkey_IX` (`jwtKey`) COMMENT 'Prueba de Ernesto 3.8.2020. MySQL se queja de no tener indices. Si, se que solo tiene un registro pero molesta para depurar otros.' -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10368,7 +11804,7 @@ CREATE TABLE `contact` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `recipient` varchar(255) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10387,7 +11823,7 @@ CREATE TABLE `image` ( PRIMARY KEY (`id`), UNIQUE KEY `collection` (`collectionFk`,`name`), CONSTRAINT `image_ibfk_1` FOREIGN KEY (`collectionFk`) REFERENCES `imageCollection` (`name`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10416,7 +11852,7 @@ CREATE TABLE `imageCollection` ( KEY `role_id_readRoleFk` (`readRoleFk`), CONSTRAINT `role_id_readRoleFk` FOREIGN KEY (`readRoleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE, CONSTRAINT `role_id_writeRoleFk` FOREIGN KEY (`writeRoleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10435,7 +11871,7 @@ CREATE TABLE `imageCollectionSize` ( PRIMARY KEY (`id`), KEY `image_schema_id` (`collectionFk`), CONSTRAINT `imageCollectionSize_ibfk_1` FOREIGN KEY (`collectionFk`) REFERENCES `imageCollection` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10451,7 +11887,7 @@ CREATE TABLE `imageConfig` ( `useXsendfile` tinyint(4) NOT NULL COMMENT 'Whether to use the apache module XSendfile', `url` varchar(255) NOT NULL COMMENT 'Public URL where image are hosted', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Global image parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Global image parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10484,71 +11920,8 @@ CREATE TABLE `link` ( `link` varchar(255) NOT NULL, `image` varchar(30) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`link_afterInsert` - AFTER INSERT ON `link` - FOR EACH ROW -BEGIN - CALL image_ref('link', NEW.image); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`link_afterUpdate` - AFTER UPDATE ON `link` - FOR EACH ROW -BEGIN - IF !(NEW.image <=> OLD.image) THEN - CALL image_unref('link', OLD.image); - CALL image_ref('link', NEW.image); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`link_afterDelete` - AFTER DELETE ON `link` - FOR EACH ROW -BEGIN - CALL image_unref('link', OLD.image); -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 `location` @@ -10569,7 +11942,7 @@ CREATE TABLE `location` ( `phone` varchar(20) DEFAULT NULL, `language` char(2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10589,7 +11962,7 @@ CREATE TABLE `mailConfig` ( `user` varchar(50) DEFAULT NULL COMMENT 'SMTP user', `password` varchar(100) DEFAULT NULL COMMENT 'SMTP password, base64 encoded', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10636,7 +12009,7 @@ CREATE TABLE `menu` ( KEY `group_id` (`roleFk`), KEY `parent` (`parentFk`), CONSTRAINT `menu_ibfk_1` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10652,7 +12025,7 @@ CREATE TABLE `message` ( `description` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10969,71 +12342,8 @@ 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=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`news_afterInsert` - AFTER INSERT ON `news` - FOR EACH ROW -BEGIN - CALL image_ref('news', NEW.image); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`news_afterUpdate` - AFTER UPDATE ON `news` - FOR EACH ROW -BEGIN - IF !(NEW.image <=> OLD.image) THEN - CALL image_unref('news', OLD.image); - CALL image_ref('news', NEW.image); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`news_afterDelete` - AFTER DELETE ON `news` - FOR EACH ROW -BEGIN - CALL image_unref('news', OLD.image); -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 `newsTag` @@ -11087,93 +12397,8 @@ CREATE TABLE `order` ( CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn`.`address` (`id`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn`.`deliveryMethod` (`id`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn`.`agencyMode` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterInsert` - AFTER INSERT ON `order` - FOR EACH ROW -BEGIN - IF NEW.address_id = 2850 THEN - -- Fallo que se insertan no se sabe como tickets en este cliente - CALL vn.mail_insert( - 'jgallego@verdnatura.es', - 'noreply@verdnatura.es', - 'Creada order al address 2850', - CONCAT(account.myUser_getName(), ' ha creado la order ',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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` - AFTER UPDATE ON `order` - FOR EACH ROW -BEGIN - CALL stock.log_add('order', NEW.id, OLD.id); - - IF !(OLD.address_id <=> NEW.address_id) - OR !(OLD.company_id <=> NEW.company_id) - OR !(OLD.customer_id <=> NEW.customer_id) THEN - CALL order_requestRecalc(NEW.id); - END IF; - - IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN - -- Fallo que se actualiza no se sabe como tickets en este cliente - CALL vn.mail_insert( - 'jgallego@verdnatura.es', - 'noreply@verdnatura.es', - 'Actualizada order al address 2850', - CONCAT(account.myUser_getName(), ' ha creado la order ',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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!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` @@ -11200,7 +12425,7 @@ CREATE TABLE `orderConfig` ( CONSTRAINT `orderConfig_ibfk_1` FOREIGN KEY (`employeeFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `orderConfig_ibfk_3` FOREIGN KEY (`guestAgencyFk`) REFERENCES `vn`.`agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `orderConfig_ibfk_4` FOREIGN KEY (`defaultAgencyFk`) REFERENCES `vn`.`agencyMode` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11215,7 +12440,7 @@ CREATE TABLE `orderRecalc` ( `orderFk` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `orderRecalc_ibfk_1` (`orderFk`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue of changed orders to recalc it''s total'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue of changed orders to recalc it''s total'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11245,101 +12470,8 @@ CREATE TABLE `orderRow` ( CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON UPDATE CASCADE, CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `orderRow_ibfk_4` FOREIGN KEY (`saleFk`) REFERENCES `vn`.`sale` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_beforeInsert` - BEFORE INSERT ON `orderRow` - FOR EACH ROW -BEGIN - DECLARE vIsFirst BOOL; - - SELECT (first_row_stamp IS NULL) INTO vIsFirst - FROM `order` - WHERE id = NEW.orderFk; - - IF vIsFirst THEN - UPDATE `order` SET first_row_stamp = util.VN_NOW() - WHERE id = NEW.orderFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterInsert` - AFTER INSERT ON `orderRow` - FOR EACH ROW -BEGIN - CALL stock.log_add('orderRow', NEW.id, NULL); - CALL order_requestRecalc(NEW.orderFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterUpdate` - AFTER UPDATE ON `orderRow` - FOR EACH ROW -BEGIN - CALL stock.log_add('orderRow', NEW.id, OLD.id); - CALL order_requestRecalc(OLD.orderFk); - CALL order_requestRecalc(NEW.orderFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterDelete` - AFTER DELETE ON `orderRow` - FOR EACH ROW -BEGIN - CALL stock.log_add('orderRow', NULL, OLD.id); - CALL order_requestRecalc(OLD.orderFk); -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` @@ -11420,7 +12552,7 @@ CREATE TABLE `restPriv` ( PRIMARY KEY (`id`), KEY `role` (`role`), CONSTRAINT `restPriv_ibfk_1` FOREIGN KEY (`role`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11466,7 +12598,7 @@ CREATE TABLE `shelfConfig` ( CONSTRAINT `shelfConfig_ibfk_1` FOREIGN KEY (`family`) REFERENCES `vn`.`itemType` (`id`), CONSTRAINT `shelfConfig_ibfk_2` FOREIGN KEY (`shelf`) REFERENCES `shelf` (`id`) ON UPDATE CASCADE, CONSTRAINT `shelfConfig_ibfk_3` FOREIGN KEY (`warehouse`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11484,7 +12616,7 @@ CREATE TABLE `social` ( `priority` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `priority` (`priority`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11498,7 +12630,7 @@ CREATE TABLE `survey` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `question` varchar(255) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11557,7 +12689,7 @@ CREATE TABLE `tpvConfig` ( PRIMARY KEY (`id`), KEY `employee_id` (`employeeFk`), CONSTRAINT `employee_id` FOREIGN KEY (`employeeFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Virtual TPV parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Virtual TPV parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11590,7 +12722,7 @@ CREATE TABLE `tpvImapConfig` ( `successFolder` varchar(150) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, `errorFolder` varchar(150) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11674,7 +12806,7 @@ CREATE TABLE `tpvTransaction` ( CONSTRAINT `receipt_id` FOREIGN KEY (`receiptFk`) REFERENCES `vn`.`receipt` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_2` FOREIGN KEY (`merchantFk`) REFERENCES `tpvMerchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Transactions realized through the virtual TPV'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Transactions realized through the virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11709,7 +12841,7 @@ CREATE TABLE `visit` ( PRIMARY KEY (`id`), KEY `firstAgent` (`firstAgentFk`), CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgentFk`) REFERENCES `visitAgent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11729,7 +12861,7 @@ CREATE TABLE `visitAccess` ( KEY `visit_access_idx_agent` (`agentFk`), KEY `stamp` (`stamp`), CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agentFk`) REFERENCES `visitAgent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11754,7 +12886,7 @@ CREATE TABLE `visitAgent` ( KEY `firstAccess` (`firstAccessFk`), CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visitFk`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccessFk`) REFERENCES `visitAccess` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11774,7 +12906,7 @@ CREATE TABLE `visitUser` ( KEY `date_time` (`stamp`), KEY `user_id` (`userFk`), CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`accessFk`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11793,7 +12925,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `order_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2019-08-29 14:18:04' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL order_doRecalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `order_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2019-08-29 14:18:04' ON COMPLETION PRESERVE ENABLE DO CALL order_doRecalc */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -11857,7 +12989,7 @@ BEGIN IF vCount = 0 THEN RETURN FALSE; - END IF; + END IF; SELECT COUNT(*) > 0 INTO vHasRole @@ -11938,14 +13070,14 @@ BEGIN * @return tmp.ticketComponent * @return tmp.ticketLot * @return tmp.zoneGetShipped - */ + */ DECLARE vAgencyMode INT; - + SELECT a.agencyModeFk INTO vAgencyMode FROM myClient c JOIN vn.address a ON a.clientFk = c.id - WHERE a.id = vAddress; + WHERE a.id = vAddress; CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); @@ -11958,7 +13090,7 @@ BEGIN JOIN tmp.availableCalc a ON a.calcFk = c.calc_id WHERE c.available > 0 GROUP BY c.item_id; - + CALL vn.catalog_calculate(vDelivery, vAddress, vAgencyMode); DROP TEMPORARY TABLE tmp.item; @@ -12060,7 +13192,7 @@ BEGIN */ DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item - ENGINE = MEMORY + ENGINE = MEMORY SELECT vSelf itemFk; CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); @@ -12085,14 +13217,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getVisible` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible`( vWarehouse TINYINT, @@ -12100,7 +13232,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible`( vType INT, vPrefix VARCHAR(255)) BEGIN - + /** * Gets visible items of the specified type at specified date. * @@ -12109,22 +13241,22 @@ BEGIN * @param vType The type id * @param vPrefix The article prefix to filter or %NULL for all * @return tmp.itemVisible Visible items - */ + */ DECLARE vPrefixLen SMALLINT; DECLARE vFilter VARCHAR(255) DEFAULT NULL; - DECLARE vDateInv DATE DEFAULT vn2008.date_inv(); + DECLARE vDateInv DATE DEFAULT vn.getInventoryDate(); DECLARE EXIT HANDLER FOR 1114 BEGIN GET DIAGNOSTICS CONDITION 1 @message = MESSAGE_TEXT; CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, + 'cau@verdnatura.es', + NULL, CONCAT('hedera.item_getVisible error: ', @message), CONCAT( - 'warehouse: ', IFNULL(vWarehouse, ''), - ', Fecha:', IFNULL(vDate, ''), - ', tipo: ', IFNULL(vType,''), + 'warehouse: ', IFNULL(vWarehouse, ''), + ', Fecha:', IFNULL(vDate, ''), + ', tipo: ', IFNULL(vType,''), ', prefijo: ', IFNULL(vPrefix,''))); RESIGNAL; END; @@ -12203,7 +13335,7 @@ BEGIN IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, CEIL(s.quantity / t.packing) etiquetas FROM vn.item i - JOIN `filter` f ON f.itemFk = i.id + JOIN `filter` f ON f.itemFk = i.id JOIN currentStock s ON s.itemFk = i.id LEFT JOIN tmp t ON t.itemFk = i.id LEFT JOIN vn.packaging p ON p.id = t.packagingFk @@ -12680,15 +13812,15 @@ BEGIN START TRANSACTION; - SELECT a.agencyModeFk, a.id + SELECT a.agencyModeFk, a.id INTO vAgencyMode, vAddressFk - FROM vn.address a + FROM vn.address a WHERE a.id = vAddressFk; - + SELECT deliveryMethodFk INTO vDeliveryMethodId FROM vn.agencyMode am WHERE am.id = vAgencyMode; - + IF vCompany IS NULL THEN SELECT defaultCompanyFk INTO vCompany @@ -12706,7 +13838,7 @@ BEGIN company_id = vCompany; SET vSelf = LAST_INSERT_ID(); - + CALL order_checkConfig(vSelf); COMMIT; @@ -12752,15 +13884,15 @@ BEGIN START TRANSACTION; - SELECT a.agencyModeFk, a.id + SELECT a.agencyModeFk, a.id INTO vAgencyMode, vAddress FROM myClient c JOIN vn.address a ON a.id = c.defaultAddressFk; - + SELECT deliveryMethodFk INTO vDeliveryMethodId FROM vn.agencyMode am WHERE am.id = vAgencyMode; - + IF vCompany IS NULL THEN SELECT defaultCompanyFk INTO vCompany @@ -12778,7 +13910,7 @@ BEGIN company_id = vCompany; SET vSelf = LAST_INSERT_ID(); - + CALL order_checkConfig(vSelf); COMMIT; @@ -12961,7 +14093,7 @@ BEGIN SELECT t.id ticketFk FROM myTicket t WHERE shipped BETWEEN TIMESTAMP(vFrom) AND TIMESTAMP(vTo, '23:59:59'); - + CALL vn.ticketGetTotal(NULL); SELECT v.id, IFNULL(v.landed, v.shipped) landed, @@ -13122,7 +14254,7 @@ BEGIN ROLLBACK; RESIGNAL; END; - + CALL order_calcCatalogFromItem(vSelf, vItem); START TRANSACTION; @@ -13142,7 +14274,7 @@ BEGIN END IF; SELECT IFNULL(minQuantity, 0) INTO vMinQuantity - FROM vn.item + FROM vn.item WHERE id = vItem; IF vAmount < LEAST(vMinQuantity, vAvailable) THEN @@ -13235,10 +14367,10 @@ BEGIN CREATE TEMPORARY TABLE tmp.item (PRIMARY KEY (itemFk)) ENGINE = MEMORY - SELECT itemFk FROM orderRow + SELECT itemFk FROM orderRow WHERE orderFk = vSelf GROUP BY itemFk; - + CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); DROP TEMPORARY TABLE tmp.item; @@ -13541,14 +14673,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!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_unicode_ci */ ; +/*!50003 SET character_set_client = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_confirmWithUser`(vSelf INT, vUserId INT) BEGIN @@ -13613,7 +14745,7 @@ BEGIN END; -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, + SELECT o.date_send, o.address_id, o.note, a.clientFk, o.company_id, o.agency_id, c.isTaxDataChecked INTO vDelivery, vAddress, vNotes, vClientId, vCompanyId, vAgencyModeId, vIsTaxDataChecked @@ -13682,11 +14814,10 @@ BEGIN WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL - AND IFNULL(tls.alertLevel,0) = 0 + AND IFNULL(tls.alertLevel,0) = 0 LIMIT 1; -- Crea el ticket en el caso de no existir uno adecuado - IF vTicket IS NULL THEN @@ -13708,7 +14839,7 @@ BEGIN ELSE INSERT INTO vn.ticketTracking SET ticketFk = vTicket, - workerFk = vUserId, + userFk = vUserId, stateFk = TICKET_FREE; END IF; @@ -13722,7 +14853,7 @@ BEGIN THEN INSERT INTO vn.ticketObservation SET ticketFk = vTicket, - observationTypeFk = 4 /* salesperson */, + observationTypeFk = 4 /* salesperson */ , `description` = vNotes ON DUPLICATE KEY UPDATE `description` = CONCAT(VALUES(`description`),'. ', `description`); @@ -13942,7 +15073,7 @@ BEGIN INTO vDelivery, vAddress, vAgencyMode FROM `order` WHERE id = vSelf; - + CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable; @@ -13984,7 +15115,7 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; CREATE TEMPORARY TABLE tmp.addressCompany (INDEX (addressFk, companyFk)) - ENGINE = MEMORY + 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; @@ -14019,7 +15150,7 @@ BEGIN 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)) @@ -14028,7 +15159,7 @@ BEGIN SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax FROM tmp.orderTax GROUP BY orderFk, `code`; - + DROP TEMPORARY TABLE tmp.addressTaxArea; END ;; DELIMITER ; @@ -14098,7 +15229,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.`order` ENGINE = MEMORY SELECT vSelf orderFk; - + CALL order_getTax; SELECT IFNULL(SUM(taxableBase), 0.0), IFNULL(SUM(tax), 0.0) @@ -14189,7 +15320,7 @@ proc: BEGIN FROM orderRow r JOIN orderRowComponent c ON c.rowFk = r.id WHERE r.orderFk = vSelf; - + UPDATE orderRow r LEFT JOIN tmp.ticketComponentPrice p ON p.warehouseFk = r.warehouseFk @@ -14214,7 +15345,7 @@ proc: BEGIN ON t.id = c.componentFk AND (t.classRate IS NULL OR t.classRate = r.rate) WHERE r.orderFk = vSelf; - + CALL vn.ticketCalculatePurge; END IF; @@ -14742,13 +15873,13 @@ p: BEGIN AND DATE(FECHA) = vDate AND EURODEBE = vAmount LIMIT 1; - + -- Actualiza la transaccion UPDATE tpvTransaction SET response = NULL, status = 'started' WHERE id = vSelf; - + COMMIT; END ;; DELIMITER ; @@ -14781,7 +15912,7 @@ BEGIN UPDATE userSession SET userVisitFk = vUserVisit WHERE ssid = vSsid; - + DELETE FROM userSession WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, util.VN_NOW()); END ;; @@ -14905,7 +16036,7 @@ BEGIN UPDATE visitAgent SET firstAccessFk = vAccessId WHERE id = vAgentId; END IF; - + -- Returns the visit info SELECT vVisit visit, vAccessId access; @@ -14936,46 +16067,6 @@ CREATE TABLE `blacklist` ( PRIMARY KEY (`phone`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Hangup input calls from this list'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`blacklist_beforeInsert` - BEFORE INSERT ON `blacklist` - FOR EACH ROW -BEGIN - CALL phone_isValid(NEW.phone); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`blacklist_berforeUpdate` - BEFORE UPDATE ON `blacklist` - FOR EACH ROW -BEGIN - CALL phone_isValid(NEW.phone); -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 `cdr` @@ -15009,7 +16100,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15051,7 +16142,7 @@ CREATE TABLE `config` ( `sundayFestive` tinyint(4) NOT NULL, `countryPrefix` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15068,46 +16159,6 @@ CREATE TABLE `followme` ( CONSTRAINT `followme_ibfk_1` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`followme_beforeInsert` - BEFORE INSERT ON `followme` - FOR EACH ROW -BEGIN - CALL pbx.phone_isValid(NEW.phone); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`followme_beforeUpdate` - BEFORE UPDATE ON `followme` - FOR EACH ROW -BEGIN - CALL pbx.phone_isValid(NEW.phone); -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 */ ; -- -- Temporary table structure for view `followmeConf` @@ -15140,7 +16191,7 @@ CREATE TABLE `followmeConfig` ( `declineCall` char(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `timeout` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15175,48 +16226,8 @@ CREATE TABLE `queue` ( UNIQUE KEY `description` (`description`), KEY `config` (`config`), CONSTRAINT `queue_ibfk_1` FOREIGN KEY (`config`) REFERENCES `queueConfig` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queues'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queues'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queue_beforeInsert` - BEFORE INSERT ON `queue` - FOR EACH ROW -BEGIN - CALL queue_isValid(NEW.`name`); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queue_beforeUpdate` - BEFORE UPDATE ON `queue` - FOR EACH ROW -BEGIN - CALL queue_isValid(NEW.`name`); -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 */ ; -- -- Temporary table structure for view `queueConf` @@ -15252,7 +16263,7 @@ CREATE TABLE `queueConfig` ( `maxLen` int(10) unsigned NOT NULL, `ringInUse` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Default values for queues configuration'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Default values for queues configuration'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15271,7 +16282,7 @@ CREATE TABLE `queueMember` ( KEY `extension` (`extension`), CONSTRAINT `queueMember_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `queueMember_ibfk_2` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue members'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue members'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15303,48 +16314,8 @@ CREATE TABLE `queuePhone` ( PRIMARY KEY (`id`), UNIQUE KEY `queue` (`queue`,`phone`), CONSTRAINT `queuePhone_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queuePhone_beforeInsert` - BEFORE INSERT ON `queuePhone` - FOR EACH ROW -BEGIN - CALL phone_isValid(NEW.phone); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queuePhone_beforeUpdate` - BEFORE UPDATE ON `queuePhone` - FOR EACH ROW -BEGIN - CALL phone_isValid(NEW.phone); -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 `schedule` @@ -15362,7 +16333,7 @@ CREATE TABLE `schedule` ( PRIMARY KEY (`id`), KEY `queue` (`queue`), CONSTRAINT `schedule_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15383,96 +16354,6 @@ CREATE TABLE `sip` ( CONSTRAINT `sip_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='SIP accounts'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_beforeInsert` - BEFORE INSERT ON `sip` - FOR EACH ROW -BEGIN - CALL sip_isValid(NEW.extension); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_afterInsert` - AFTER INSERT ON `sip` - FOR EACH ROW -BEGIN - INSERT INTO sipReg - SET userId = NEW.user_id; - - INSERT IGNORE INTO `account`.userSync (`name`) - SELECT `name` FROM `account`.`user` - WHERE id = NEW.user_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_beforeUpdate` - BEFORE UPDATE ON `sip` - FOR EACH ROW -BEGIN - CALL sip_isValid(NEW.extension); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_afterUpdate` - AFTER UPDATE ON `sip` - FOR EACH ROW -BEGIN - IF !(OLD.extension <=> NEW.extension) - OR !(OLD.user_id <=> NEW.user_id) THEN - INSERT IGNORE INTO `account`.userSync (`name`) - SELECT `name` FROM `account`.`user` - WHERE id = NEW.user_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 */ ; -- -- Temporary table structure for view `sipConf` @@ -15542,7 +16423,7 @@ CREATE TABLE `sipConfig` ( `allow` varchar(100) DEFAULT 'g729;ilbc;gsm;ulaw;alaw', `qualify` enum('yes','no') DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Default values for SIP accounts'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Default values for SIP accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15618,7 +16499,7 @@ BEGIN WHILE vI < vLen DO SET vChr = SUBSTR(vPhone, vI + 1, 1); - + IF vChr REGEXP '^[0-9]$' THEN SET vNewPhone = CONCAT(vNewPhone, vChr); @@ -15626,7 +16507,7 @@ BEGIN THEN SET vNewPhone = CONCAT(vNewPhone, '00'); END IF; - + SET vI = vI + 1; END WHILE; @@ -15725,18 +16606,18 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sip_getExtension`(vUserId INT(10)) BEGIN - + /* * Devuelve la extensión pbx del usuario - * - * @param vUserId Id del usuario - * + * + * @param vUserId Id del usuario + * */ SELECT extension - FROM sip s + FROM sip s WHERE s.user_id = vUserId; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -15802,6 +16683,429 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `psico` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `psico` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `psico`; + +-- +-- Table structure for table `answer` +-- + +DROP TABLE IF EXISTS `answer`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `answer` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `text` varchar(155) NOT NULL, + `questionFk` int(11) NOT NULL, + `correct` tinyint(1) NOT NULL DEFAULT 0, + `order` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `answer_fk1_idx` (`questionFk`), + CONSTRAINT `answer_fk1` FOREIGN KEY (`questionFk`) REFERENCES `question` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `exam` +-- + +DROP TABLE IF EXISTS `exam`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `exam` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `duration` int(11) NOT NULL COMMENT 'minutos de duracion de la prueba', + `fellowFk` int(11) NOT NULL, + `examTypeFk` int(11) NOT NULL, + `started` datetime DEFAULT NULL, + `finished` datetime DEFAULT NULL, + `questionsCount` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `exam_fk1_idx` (`fellowFk`), + KEY `exam_fk2_idx` (`examTypeFk`), + CONSTRAINT `exam_fk1` FOREIGN KEY (`fellowFk`) REFERENCES `fellow` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `exam_fk2` FOREIGN KEY (`examTypeFk`) REFERENCES `examType` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `examQuestion` +-- + +DROP TABLE IF EXISTS `examQuestion`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `examQuestion` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `examFk` int(11) NOT NULL, + `questionFk` int(11) NOT NULL, + `answerFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `examQuestion_fk1_idx` (`examFk`), + KEY `examQuestion_fk2_idx` (`questionFk`), + KEY `examQuestion_fk3_idx` (`answerFk`), + CONSTRAINT `examQuestion_fk1` FOREIGN KEY (`examFk`) REFERENCES `exam` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `examQuestion_fk2` FOREIGN KEY (`questionFk`) REFERENCES `question` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `examQuestion_fk3` FOREIGN KEY (`answerFk`) REFERENCES `answer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `examType` +-- + +DROP TABLE IF EXISTS `examType`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `examType` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `examView` +-- + +DROP TABLE IF EXISTS `examView`; +/*!50001 DROP VIEW IF EXISTS `examView`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `examView` AS SELECT + 1 AS `text`, + 1 AS `examFk`, + 1 AS `questionFk`, + 1 AS `answerFk`, + 1 AS `id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `fellow` +-- + +DROP TABLE IF EXISTS `fellow`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `fellow` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `question` +-- + +DROP TABLE IF EXISTS `question`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `question` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `text` varchar(155) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `randomOrder` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `questionType` +-- + +DROP TABLE IF EXISTS `questionType`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `questionType` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `examTypeFk` int(11) NOT NULL, + `questionFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `questionTypeFk1_idx` (`examTypeFk`), + KEY `questionTypeFk2_idx` (`questionFk`), + CONSTRAINT `questionTypeFk1` FOREIGN KEY (`examTypeFk`) REFERENCES `examType` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `questionTypeFk2` FOREIGN KEY (`questionFk`) REFERENCES `question` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `results` +-- + +DROP TABLE IF EXISTS `results`; +/*!50001 DROP VIEW IF EXISTS `results`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `results` AS SELECT + 1 AS `examFk`, + 1 AS `aciertos`, + 1 AS `questionsCount`, + 1 AS `minutos`, + 1 AS `nota` */; +SET character_set_client = @saved_cs_client; + +-- +-- Dumping events for database 'psico' +-- + +-- +-- Dumping routines for database 'psico' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `answerSort` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `answerSort`() +BEGIN + + UPDATE answer + SET `order` = RAND() * 999999; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `examNew` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `examNew`(vFellow VARCHAR(50), vType INT, vQuestionsNumber INT, OUT vExamFk INT) +BEGIN + + DECLARE done BOOL DEFAULT FALSE; + DECLARE vFellowFk INT; + DECLARE vQuestionFk INT; + + DECLARE rs CURSOR FOR + SELECT q.id + FROM psico.question q + LEFT JOIN psico.questionType qt ON q.id = qt.questionFk + WHERE qt.examTypeFk = vType + ORDER BY randomOrder; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + IF vQuestionsNumber = 0 THEN + + SET vQuestionsNumber = 30; + + END IF; + + CALL psico.answerSort(); + + CALL psico.questionSort(); + + INSERT INTO psico.fellow(name) VALUES(vFellow); + + SELECT MAX(id) INTO vFellowFk FROM psico.fellow; + + INSERT INTO psico.exam(fellowFk, started, questionsCount,examTypeFk) VALUES(vFellowFk, util.VN_NOW(), vQuestionsNumber,vType); + + SELECT MAX(id) INTO vExamFk FROM psico.exam; + + OPEN rs; + + FETCH rs INTO vQuestionFk; + + WHILE NOT done AND vQuestionsNumber DO + + INSERT INTO psico.examQuestion(examFk, questionFk) + VALUES (vExamFk, vQuestionFk); + + + FETCH rs INTO vQuestionFk; + + SET vQuestionsNumber = vQuestionsNumber - 1; + + END WHILE; + + CLOSE rs; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `getExamQuestions` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `getExamQuestions`(vExamFk INT) +BEGIN + +SELECT p.text,p.examFk,p.questionFk,p.answerFk,p.id ,a.text AS answerText,a.correct, a.id AS answerFk +FROM psico.examView as p +INNER JOIN psico.answer as a ON p.questionFk = a.questionFk +WHERE examFk = vExamFk; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `getExamType` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `getExamType`() +BEGIN + +SELECT id,name +FROM psico.examType; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `questionSort` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `questionSort`() +BEGIN + + UPDATE question + SET randomOrder = RAND() * 999999; + +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 */ ; + +-- +-- Current Database: `rfid` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `rfid` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `rfid`; + +-- +-- Table structure for table `expedition_PrintOut` +-- + +DROP TABLE IF EXISTS `expedition_PrintOut`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expedition_PrintOut` ( + `expeditionFk` int(11) NOT NULL, + `ticketFk` int(11) NOT NULL, + `addressFk` int(11) NOT NULL, + `street` varchar(100) NOT NULL, + `postalCode` varchar(10) NOT NULL, + `city` varchar(100) NOT NULL, + `shopName` varchar(100) NOT NULL, + `isPrinted` tinyint(1) NOT NULL DEFAULT 0, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `printerFk` int(11) NOT NULL DEFAULT 1, + `routeFk` int(11) DEFAULT NULL, + `parkingCode` varchar(8) DEFAULT NULL, + `truckName` varchar(25) DEFAULT NULL, + PRIMARY KEY (`expeditionFk`), + KEY `expedition_PrintOut_FK` (`printerFk`), + CONSTRAINT `expedition_PrintOut_FK` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expedition_Read` +-- + +DROP TABLE IF EXISTS `expedition_Read`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expedition_Read` ( + `expeditionFk` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `readingPointFk` int(11) DEFAULT NULL, + PRIMARY KEY (`expeditionFk`), + KEY `expedition_Read_FK` (`readingPointFk`), + CONSTRAINT `expedition_Read_FK` FOREIGN KEY (`readingPointFk`) REFERENCES `readingPoint` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `printer` +-- + +DROP TABLE IF EXISTS `printer`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `printer` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(50) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `readingPoint` +-- + +DROP TABLE IF EXISTS `readingPoint`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `readingPoint` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping events for database 'rfid' +-- + +-- +-- Dumping routines for database 'rfid' +-- + -- -- Current Database: `sage` -- @@ -16122,7 +17426,7 @@ CREATE TABLE `config` ( `definitiveExportTransactionTypeFk` tinyint(4) DEFAULT NULL COMMENT 'Transacción Exportaciones definitivas', `shipmentTransactionTypeFk` tinyint(4) DEFAULT NULL COMMENT 'Transacción Envíos definitivos a Canarias, Ceuta y Melilla', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16317,30 +17621,8 @@ CREATE TABLE `movConta` ( KEY `ix_movconta` (`enlazadoSage`,`IdProcesoIME`), KEY `movConta_IdProcesoIME` (`IdProcesoIME`), KEY `movConta_Asiento2` (`Asiento`,`IdProcesoIME`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `sage`.`movConta_BEFORE_UPDATE` - BEFORE UPDATE ON `movConta` - FOR EACH ROW -BEGIN - IF NEW.enlazadoSage = TRUE THEN - UPDATE vn.XDiario SET enlazadoSage = TRUE WHERE ASIEN = NEW.Asiento; - 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 */ ; -- -- Table structure for table `movContaIVA` @@ -16438,7 +17720,7 @@ CREATE TABLE `pgcToSage` ( `accountTaxInput` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, `accountTaxOutput` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Tabla relaciona cuentas pgc con Código de IVA y Código de Transacción en Sage'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Tabla relaciona cuentas pgc con Código de IVA y Código de Transacción en Sage'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16524,22 +17806,22 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `company_getCode`(vCompanyFk INT) RET READS SQL DATA BEGIN /** - * Devuelve la correspondencía del código de empresa de sage. + * Devuelve la correspondencía del código de empresa de sage. * Tiene en cuenta el entorno - * + * * @param vSelf Id de empresa de verdnatura * @return Código de empresa sage */ DECLARE vCompanySageFk INT(2); - - SELECT IF(c.environment = 'production', - co.companyCode, + + SELECT IF(c.environment = 'production', + co.companyCode, co.companyCodeTest ) INTO vCompanySageFk FROM util.config c JOIN vn.company co WHERE co.id = vCompanyFk; - + RETURN vCompanySageFk; END ;; DELIMITER ; @@ -16558,12 +17840,12 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `accountingMovements_add`( - vYear INT, + vYear INT, vCompanyFk INT ) BEGIN /** - * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta + * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta * para poder ejecutar posteriormente el proceso de importación de datos de SQL Server * Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE * @vYear Año contable del que se quiere trasladar la información @@ -16879,8 +18161,8 @@ BEGIN mci.FechaFacturaOriginal = x.FECHA_EX, mci.SuFacturaNo = x.FACTURAEX, mci.FechaOperacion = x.FECHA_OP, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -16899,7 +18181,7 @@ BEGIN mci.CodigoIva2 = vTaxImportFk, mci.IvaDeducible2 = TRUE, mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -16917,8 +18199,8 @@ BEGIN mci.CodigoTransaccion3 = vDuaTransactionFk , mci.CodigoIva3 = vTaxImportSuperReducedFk, mci.IvaDeducible3 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -16952,14 +18234,14 @@ BEGIN OR CodigoTransaccion2 = vTransactionExportFk OR CodigoTransaccion3 = vTransactionExportFk OR CodigoTransaccion4 = vTransactionExportFk) - AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, + AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci); UPDATE movConta mc SET CodigoDivisa = 'USD', FactorCambio = TRUE, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, - ImporteAsiento / ImporteDivisa, + ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, + ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) WHERE enlazadoSage = FALSE AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio); @@ -17001,8 +18283,8 @@ BEGIN AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase) sub; IF vBookEntries IS NOT NULL THEN - SELECT util.notification_send ("book-entries-imported-incorrectly", - CONCAT('{"bookEntries":"', vBookEntries,'"}'), + SELECT util.notification_send ("book-entries-imported-incorrectly", + CONCAT('{"bookEntries":"', vBookEntries,'"}'), null); END IF; END ;; @@ -17083,8 +18365,8 @@ BEGIN IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla := IF(pr.Provincia IN ('CEUTA', 'MELILLA'), TRUE, FALSE), vCountryCeutaMelillaFk, IF (@isCanarias, vCountryCanariasCode, n.CodigoNacion)), n.CodigoNacion), IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla, vCountryCeutaMelillaCode, IF (@isCanarias, vCountryCanariasCode, n.SiglaNacion)), n.SiglaNacion), IF((c.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F'), - IF(cu.code = 'ES', - 1, + IF(cu.code = 'ES', + 1, IF((cu.isUeeMember AND c.isVies), 2, 4)), IFNULL(c.taxTypeSageFk,0), IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, @@ -17162,10 +18444,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceIn_add`(vInvoiceInFk INT, vX BEGIN /** * Traslada la info de contabilidad relacionada con las facturas recibidas - * + * * @vInvoiceInFk Factura recibida * @vXDiarioFk Id tabla XDiario - */ + */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBase DOUBLE; DECLARE vVat DOUBLE; @@ -17182,25 +18464,25 @@ BEGIN DECLARE vInvoiceTypeInformative VARCHAR(1); DECLARE vIsInformativeExportation BOOL DEFAULT FALSE; - DECLARE vCursor CURSOR FOR + DECLARE vCursor CURSOR FOR SELECT it.taxableBase, CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)), t.PorcentajeIva, it.transactionTypeSageFk, it.taxTypeSageFk, tty.isIntracommunity, - tt.ClaveOperacionDefecto + tt.ClaveOperacionDefecto FROM vn.invoiceIn i JOIN vn.invoiceInTax it ON it.InvoiceInFk = i.id JOIN TiposIva t ON t.CodigoIva = it.taxTypeSageFk JOIN taxType tty ON tty.id = t.CodigoIva JOIN TiposTransacciones tt ON tt.CodigoTransaccion = it.transactionTypeSageFk LEFT JOIN vn.dua d ON d.id = vInvoiceInFk - WHERE i.id = vInvoiceInFk + WHERE i.id = vInvoiceInFk AND d.id IS NULL; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + DELETE FROM movContaIVA WHERE id = vXDiarioFk; @@ -17223,22 +18505,22 @@ BEGIN vTaxCode, vIsIntracommunity, vOperationCode; - - IF vDone THEN + + IF vDone THEN LEAVE l; END IF; - SET vTransactionCodeOld = vTransactionCode; - SET vTaxCodeOld = vTaxCode; + SET vTransactionCodeOld = vTransactionCode; + SET vTaxCodeOld = vTaxCode; - IF vOperationCode IS NOT NULL THEN + IF vOperationCode IS NOT NULL THEN UPDATE movContaIVA SET ClaveOperacionFactura = vOperationCode WHERE id = vXDiarioFk; END IF; - + SET vCounter = vCounter + 1; - CASE vCounter + CASE vCounter WHEN 1 THEN UPDATE movContaIVA SET BaseIva1 = vBase, @@ -17274,31 +18556,31 @@ BEGIN WHERE id = vXDiarioFk; ELSE SELECT vXDiarioFk INTO vXDiarioFk; - END CASE; + END CASE; IF vIsIntracommunity THEN UPDATE movContaIVA SET Intracomunitaria = TRUE WHERE id = vXDiarioFk; END IF; - - SET vTransactionCodeOld = vTransactionCode; - SET vTaxCodeOld = vTaxCode; - + + SET vTransactionCodeOld = vTransactionCode; + SET vTaxCodeOld = vTaxCode; + END LOOP; CLOSE vCursor; SELECT d.ASIEN AND x.ASIEN IS NULL INTO vIsInformativeExportation FROM vn.dua d - LEFT JOIN vn.XDiario x ON x.ASIEN = d.ASIEN + LEFT JOIN vn.XDiario x ON x.ASIEN = d.ASIEN AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci WHERE d.ASIEN = ( SELECT ASIEN - FROM vn.XDiario + FROM vn.XDiario WHERE id = vXDiarioFk) LIMIT 1; - + UPDATE movContaIVA mci JOIN tmp.invoiceIn ii ON ii.id = vInvoiceInFk JOIN vn.XDiario x ON x.id = mci.id @@ -17310,13 +18592,13 @@ BEGIN mci.Serie = ii.serial, mci.Factura = ii.id, mci.FechaFactura = ii.issued, - mci.ImporteFactura = IFNULL(mci.BaseIva1, 0) + IFNULL(mci.CuotaIva1, 0) + - IFNULL(mci.BaseIva2, 0) + IFNULL(mci.CuotaIva2, 0) + - IFNULL(mci.BaseIva3, 0) + IFNULL(mci.CuotaIva3, 0) + + mci.ImporteFactura = IFNULL(mci.BaseIva1, 0) + IFNULL(mci.CuotaIva1, 0) + + IFNULL(mci.BaseIva2, 0) + IFNULL(mci.CuotaIva2, 0) + + IFNULL(mci.BaseIva3, 0) + IFNULL(mci.CuotaIva3, 0) + IFNULL(mci.BaseIva4, 0) + IFNULL(mci.CuotaIva4, 0), - mci.TipoFactura = IF(id.id, - IF( ii.serial = vSerialDua COLLATE utf8mb3_unicode_ci, vInvoiceTypeReceived, vInvoiceTypeInformative), - IF(vIsInformativeExportation,vInvoiceTypeInformative, vInvoiceTypeReceived)), + mci.TipoFactura = IF(id.id, + IF( ii.serial = vSerialDua COLLATE utf8mb3_unicode_ci, vInvoiceTypeReceived, vInvoiceTypeInformative), + IF(vIsInformativeExportation,vInvoiceTypeInformative, vInvoiceTypeReceived)), mci.CodigoCuentaFactura = x.SUBCTA, mci.CifDni = IF(LEFT(TRIM(s.nif), 2) = n.SiglaNacion, SUBSTRING(TRIM(s.nif), 3), s.nif), mci.Nombre = s.name, @@ -17344,7 +18626,7 @@ BEGIN JOIN (SELECT SUM(x2.BASEEURO) taxableBase, SUM(x2.EURODEBE) taxBase FROM vn.XDiario x1 JOIN vn.XDiario x2 ON x1.ASIEN = x2.ASIEN - WHERE x2.BASEEURO <> 0 + WHERE x2.BASEEURO <> 0 AND x1.id = vXDiarioFk )sub JOIN ClavesOperacion co ON co.Descripcion = 'Arrendamiento de locales de negocio' @@ -17352,8 +18634,8 @@ BEGIN mci.ClaveOperacionFactura = IF( t.Retencion = 'ARRENDAMIENTO Y SUBARRENDAMIENTO', co.ClaveOperacionFactura_, mci.ClaveOperacionFactura), mci.BaseRetencion = IF (t.Retencion = 'ACTIVIDADES AGRICOLAS O GANADERAS', sub.taxableBase + sub.taxBase, sub.taxableBase), mci.PorRetencion = t.PorcentajeRetencion, - mci.ImporteRetencion = iit.taxableBase * - 1 - WHERE mci.id = vXDiarioFk + mci.ImporteRetencion = iit.taxableBase * - 1 + WHERE mci.id = vXDiarioFk AND e.name = 'Retenciones' AND id.id IS NULL; @@ -17376,10 +18658,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceIn_manager`(vYear INT, vCompanyFk INT) BEGIN /** - * Traslada la info de contabilidad relacionada con las facturas recibidas - * + * Traslada la info de contabilidad relacionada con las facturas recibidas + * * @vYear Año contable del que se quiere trasladar la información - * @vCompany Empresa de la que se quiere trasladar datos + * @vCompany Empresa de la que se quiere trasladar datos */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; @@ -17391,22 +18673,22 @@ BEGIN DECLARE vAccountTaxOutstanding VARCHAR(10); DECLARE vInvoiceTypeSended VARCHAR(1); DECLARE vCursor CURSOR FOR - SELECT IFNULL(x.CLAVE, x.FACTURA) invoiceInFk, + SELECT IFNULL(x.CLAVE, x.FACTURA) invoiceInFk, x.id XDiarioFk - FROM vn.XDiario x + FROM vn.XDiario x JOIN(SELECT DISTINCT(x.ASIEN) FROM vn.XDiario x LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id LEFT JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id - WHERE(it.taxTypeSageFk IS NOT NULL OR x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci) - AND x.enlazadoSage = FALSE + WHERE(it.taxTypeSageFk IS NOT NULL OR x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci) + AND x.enlazadoSage = FALSE AND x.FECHA BETWEEN vDatedFrom AND vDatedTo - AND x.empresa_id = vCompanyFk + AND x.empresa_id = vCompanyFk ) sub ON sub.ASIEN = x.ASIEN WHERE x.CLAVE IS NOT NULL; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) INTO vDatedFrom, vDatedTo; @@ -17420,15 +18702,15 @@ BEGIN SELECT codeSage INTO vInvoiceTypeSended FROM invoiceType WHERE `code` ='sended'; - + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; CREATE TEMPORARY TABLE tmp.invoiceDua - SELECT x.id + SELECT x.id FROM vn.XDiario x JOIN vn.company c ON c.id = x.empresa_id JOIN (SELECT ASIEN - FROM vn.XDiario x - WHERE x.enlazadoSage = FALSE + FROM vn.XDiario x + WHERE x.enlazadoSage = FALSE AND x.SUBCTA = vAccountTaxOutstanding COLLATE utf8mb3_unicode_ci AND x.FECHA BETWEEN vDatedFrom AND vDatedTo )sub ON sub.ASIEN = x.ASIEN @@ -17446,7 +18728,7 @@ BEGIN FROM vn.invoiceIn i JOIN vn.currency c ON c.id = i.currencyFk WHERE i.bookEntried BETWEEN vDatedFrom AND vDatedTo - UNION ALL + UNION ALL SELECT d.id, d.code, vSerialDua COLLATE utf8mb3_unicode_ci, @@ -17454,8 +18736,8 @@ BEGIN d.issued, FALSE, '' -- EUROS - FROM vn.dua d - WHERE d.issued IS NOT NULL + FROM vn.dua d + WHERE d.issued IS NOT NULL AND code IS NOT NULL; OPEN vCursor; @@ -17463,7 +18745,7 @@ BEGIN l: LOOP FETCH vCursor INTO vInvoiceFk, vXDiarioFk; - IF vDone THEN + IF vDone THEN LEAVE l; END IF; CALL invoiceIn_add(vInvoiceFk, vXDiarioFk); @@ -17551,21 +18833,21 @@ BEGIN JOIN (SELECT x.ASIEN, x.id FROM vn.XDiario x JOIN(SELECT DISTINCT(x.ASIEN) ASIEN - FROM vn.XDiario x + FROM vn.XDiario x JOIN (SELECT DISTINCT(ASIEN) FROM vn.XDiario x - WHERE SUBCTA LIKE '472%' + WHERE SUBCTA LIKE '472%' AND x.enlazadoSage = FALSE AND x.empresa_id = vCompanyFk AND x.FECHA BETWEEN vDatedFrom AND vDatedTo ) sub ON sub.ASIEN = x.ASIEN WHERE x.SUBCTA LIKE '477%' )sub2 ON sub2.ASIEN = x.ASIEN - WHERE x.CONTRA IS NOT NULL + WHERE x.CONTRA IS NOT NULL AND x.SUBCTA LIKE '477%' GROUP BY x.ASIEN )sub3 ON sub3.ASIEN = x.ASIEN; - + INSERT INTO movContaIVA (`id`, `CodigoDivisa`, @@ -17636,9 +18918,9 @@ BEGIN `FechaGrabacion`, `Intracomunitaria`, `moveData`) - SELECT * + SELECT * FROM tmp.movContaIVA; - + DROP TEMPORARY TABLE tmp.movContaIVA; END ;; @@ -17660,10 +18942,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_add`(IN vInvoiceOutFk INT, IN vXDiarioFk INT) BEGIN /** - * Traslada la info de contabilidad relacionada con las facturas emitidas - * + * Traslada la info de contabilidad relacionada con las facturas emitidas + * * @vYear Año contable del que se quiere trasladar la información - * @vCompany Empresa de la que se quiere trasladar datos + * @vCompany Empresa de la que se quiere trasladar datos */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vMaxLengthName INT DEFAULT 35; @@ -17683,12 +18965,12 @@ BEGIN DECLARE vHasCustomsAccountingNote BOOL; DECLARE vCursor CURSOR FOR - SELECT oit.taxableBase, - oit.vat, - pgc.rate, - pgc.mod347, - pgcRE.rate, - oitRE.vat, + SELECT oit.taxableBase, + oit.vat, + pgc.rate, + pgc.mod347, + pgcRE.rate, + oitRE.vat, tc.transactionCode, tc.taxCode, tc.isIntracommunity, @@ -17697,7 +18979,7 @@ BEGIN JOIN vn.pgc ON pgc.code = oit.pgcFk LEFT JOIN vn.pgcEqu e ON e.vatFk = oit.pgcFk LEFT JOIN vn.pgcEqu eRE ON eRE.equFk = oit.pgcFk - LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk + LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk AND oitRE.pgcFk = e.equFk LEFT JOIN vn.pgc pgcRE ON pgcRE.code = oitRE.pgcFk LEFT JOIN vn.taxCode tc ON tc.code = pgc.code COLLATE 'utf8mb3_unicode_ci' @@ -17713,12 +18995,12 @@ BEGIN WHERE ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioFk); SELECT codeSage INTO vInvoiceTypeSended - FROM invoiceType + FROM invoiceType WHERE code = IF(vHasCustomsAccountingNote, 'informative', 'sended'); - + DELETE FROM movContaIVA WHERE id = vXDiarioFk; - + INSERT INTO movContaIVA(id) VALUES (vXDiarioFk); OPEN vCursor; @@ -17735,13 +19017,13 @@ BEGIN vIsIntracommunity, vOperationCode; - IF vDone THEN + IF vDone THEN LEAVE l; END IF; SET vCounter = vCounter + 1; - - CASE vCounter + + CASE vCounter WHEN 1 THEN UPDATE movContaIVA SET BaseIva1 = vBase, @@ -17782,7 +19064,7 @@ BEGIN CodigoTransaccion4 = vTransactionCode, CodigoIva4 = vTaxCode WHERE id = vXDiarioFk; - END CASE; + END CASE; UPDATE movContaIVA SET Exclusion347 = NOT vMod347, @@ -17793,7 +19075,7 @@ BEGIN END LOOP; CLOSE vCursor; - + UPDATE movContaIVA mci JOIN vn.invoiceOut i ON i.id = vInvoiceOutFk LEFT JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutFk @@ -17818,25 +19100,25 @@ BEGIN mci.MantenerAsiento = TRUE, mci.FechaFacturaOriginal = x.FECHA_EX WHERE mci.id = vXDiarioFk; - + SELECT correctedFk INTO vInvoiceOutCorrectedFk FROM vn.invoiceCorrection WHERE correctingFk = vInvoiceOutFk; - - IF vInvoiceOutCorrectedFk THEN + + IF vInvoiceOutCorrectedFk THEN UPDATE movContaIVA mci JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk - JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, + JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat, SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ FROM vn.invoiceOutTax iot - LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk + LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk ) tax JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' SET mci.TipoRectificativa = 2, - mci.ClaseAbonoRectificativas = 1, + mci.ClaseAbonoRectificativas = 1, mci.FechaFacturaOriginal = i.issued, mci.FechaOperacion = i.issued, mci.BaseImponibleOriginal = tax.taxableBase, @@ -17867,10 +19149,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_manager`(vYear INT, vCompanyFk INT) BEGIN /** - * Traslada la info de contabilidad relacionada con las facturas emitidas - * + * Traslada la info de contabilidad relacionada con las facturas emitidas + * * @vYear Año contable del que se quiere trasladar la información - * @vCompany Empresa de la que se quiere trasladar datos + * @vCompany Empresa de la que se quiere trasladar datos */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; @@ -17887,7 +19169,7 @@ BEGIN JOIN (SELECT x.ASIEN, CONCAT(x.SERIE, x.FACTURA) refFk FROM vn.XDiario x WHERE x.enlazadoSage = FALSE - AND x.FACTURA + AND x.FACTURA AND x.empresa_id = vCompanyFk AND x.FECHA BETWEEN vDatedFrom AND vDatedTo GROUP BY refFk @@ -17896,19 +19178,19 @@ BEGIN )sub2 ON sub2.refFk = i.ref; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) INTO vDatedFrom, vDatedTo; - + OPEN vCursor; l: LOOP FETCH vCursor INTO vInvoiceFk, vXDiarioFk; - IF vDone THEN + IF vDone THEN LEAVE l; END IF; - + CALL invoiceOut_add(vInvoiceFk, vXDiarioFk); END LOOP; @@ -17934,7 +19216,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `pgc_add`(vCompanyFk INT) BEGIN /** - * Añade cuentas del plan general contable para exportarlos a Sage + * Añade cuentas del plan general contable para exportarlos a Sage * @vCompanyFk Empresa de la que se quiere trasladar datos */ TRUNCATE TABLE planCuentasPGC; @@ -17944,25 +19226,25 @@ BEGIN CodigoCuenta, Cuenta, ClienteOProveedor) - SELECT * + SELECT * FROM (SELECT company_getCode(vCompanyFk) companyFk, e.id accountFk, UCASE(e.name), '' FROM vn.expense e - UNION + UNION SELECT company_getCode(vCompanyFk), - b.account, + b.account, UCASE(b.bank), - '' + '' FROM vn.bank b WHERE b.isActive AND b.`account` - UNION + UNION SELECT CodigoEmpresa, CodigoCuenta, Nombre, - ClienteOProveedor + ClienteOProveedor FROM clientesProveedores)sub GROUP BY companyFk, accountFk; END ;; @@ -17999,7 +19281,7 @@ CREATE TABLE `ACL` ( KEY `model_ix` (`model`(255)) COMMENT 'ernesto 3.8.2020. Mysql pide indices', KEY `property_ix` (`property`(255)), KEY `accessType_ix` (`accessType`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18102,7 +19384,7 @@ CREATE TABLE `accessTokenConfig` ( `courtesyTime` int(10) unsigned DEFAULT NULL, `renewInterval` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18149,7 +19431,7 @@ CREATE TABLE `fieldAcl` ( `actionType` set('insert','update','*') DEFAULT '*', `role` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18177,7 +19459,7 @@ CREATE TABLE `printConfig` ( `itRecipient` varchar(50) DEFAULT NULL COMMENT 'IT recipients for report mailing', `incidencesEmail` varchar(50) DEFAULT NULL COMMENT 'CAU destinatary email', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Print service config'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Print service config'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18209,7 +19491,7 @@ CREATE TABLE `userConfigView` ( `configuration` text DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uniqueUser_TableCode` (`userFk`,`tableCode`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18228,7 +19510,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `accessToken_prune` ON SCHEDULE EVERY 1 DAY STARTS '2023-03-14 05:14:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL salix.accessToken_prune */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `accessToken_prune` ON SCHEDULE EVERY 1 DAY STARTS '2023-03-14 05:14:00' ON COMPLETION PRESERVE ENABLE DO CALL salix.accessToken_prune */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -18264,6 +19546,3554 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `srt` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `srt` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `srt`; + +-- +-- Table structure for table `antenna` +-- + +DROP TABLE IF EXISTS `antenna`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `antenna` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lector de codigos RFID en el sorter'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `buffer` +-- + +DROP TABLE IF EXISTS `buffer`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `buffer` ( + `id` int(11) NOT NULL, + `x` int(11) DEFAULT NULL, + `y` int(11) DEFAULT NULL, + `size` int(11) DEFAULT NULL, + `length` int(11) DEFAULT NULL, + `stateFk` int(11) NOT NULL DEFAULT 1, + `typeFk` int(11) NOT NULL DEFAULT 0, + `isActive` tinyint(1) NOT NULL DEFAULT 1, + `code` varchar(3) DEFAULT NULL, + `stratus` int(11) NOT NULL COMMENT 'representa la altura del buffer', + `hasWorkerWaiting` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indica si hay un paletizador', + `reserve` varchar(100) DEFAULT NULL, + `routeFk` int(11) DEFAULT NULL COMMENT 'ruta que va a descargar por ahi', + `dayMinute` int(11) DEFAULT NULL COMMENT 'camion que va a descargar', + `lastUnloaded` datetime DEFAULT NULL COMMENT 'hora de la última descarga', + `hasStrapper` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'tiene una flejadora acoplada', + `typeDefaultFk` int(11) NOT NULL DEFAULT 1 COMMENT 'estado por defecto', + `motors` int(11) NOT NULL DEFAULT 1 COMMENT 'número de fotocélulas que corresponden con sectores de motor independientes', + PRIMARY KEY (`id`), + UNIQUE KEY `code_UNIQUE` (`code`), + KEY `buffer_FK` (`stateFk`), + KEY `buffer_FK_1` (`typeFk`), + CONSTRAINT `buffer_FK` FOREIGN KEY (`stateFk`) REFERENCES `bufferState` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `buffer_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `bufferType` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `bufferDayMinute` +-- + +DROP TABLE IF EXISTS `bufferDayMinute`; +/*!50001 DROP VIEW IF EXISTS `bufferDayMinute`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `bufferDayMinute` AS SELECT + 1 AS `bufferFk`, + 1 AS `expeditionFk`, + 1 AS `dayMinute`, + 1 AS `position`, + 1 AS `ETD`, + 1 AS `ticketFk`, + 1 AS `routeFk`, + 1 AS `zonaTicket`, + 1 AS `expeditionState` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `bufferFreeLength` +-- + +DROP TABLE IF EXISTS `bufferFreeLength`; +/*!50001 DROP VIEW IF EXISTS `bufferFreeLength`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `bufferFreeLength` AS SELECT + 1 AS `bufferFk`, + 1 AS `bufferName`, + 1 AS `freeLength`, + 1 AS `saturacion`, + 1 AS `state`, + 1 AS `stateFk`, + 1 AS `typeFk`, + 1 AS `typeName`, + 1 AS `stock`, + 1 AS `RealFreeLength` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `bufferGroup` +-- + +DROP TABLE IF EXISTS `bufferGroup`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bufferGroup` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `bufferFk` int(11) NOT NULL, + `group` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `bufferGroup_UN` (`bufferFk`), + CONSTRAINT `bufferGroup_FK` FOREIGN KEY (`bufferFk`) REFERENCES `buffer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Agrupación de buffers que sirven de salida para las mismas rutas'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `bufferPool` +-- + +DROP TABLE IF EXISTS `bufferPool`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bufferPool` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `bufferFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `bufferPool_fk1_idx` (`bufferFk`), + CONSTRAINT `bufferPool_fk1` FOREIGN KEY (`bufferFk`) REFERENCES `buffer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla se almacen los buffers que se quieren utilizar como destino de las cajas que entran, para forzar el envio a los mismos.'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `bufferState` +-- + +DROP TABLE IF EXISTS `bufferState`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bufferState` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(20) NOT NULL, + `isAvailable` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `bufferStock` +-- + +DROP TABLE IF EXISTS `bufferStock`; +/*!50001 DROP VIEW IF EXISTS `bufferStock`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `bufferStock` AS SELECT + 1 AS `expeditionFk`, + 1 AS `bufferFk`, + 1 AS `position`, + 1 AS `dayMinute`, + 1 AS `eta`, + 1 AS `ticketFk`, + 1 AS `routeFk`, + 1 AS `zonaTicket`, + 1 AS `truck`, + 1 AS `expeditionState`, + 1 AS `hasWorkerWaiting`, + 1 AS `isActive`, + 1 AS `bufferTruck`, + 1 AS `typeName`, + 1 AS `routeBuffer` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `bufferType` +-- + +DROP TABLE IF EXISTS `bufferType`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bufferType` ( + `id` int(11) NOT NULL, + `typeName` varchar(100) NOT NULL, + `isTarget` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'puede recibir cajas', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `config` +-- + +DROP TABLE IF EXISTS `config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `config` ( + `readingPointDelay` int(11) NOT NULL DEFAULT 5 COMMENT 'tiempo de espera de la antena para considerar la lectura como una nueva ', + `boxGap` int(11) NOT NULL COMMENT 'separacion teorica entre cajas en el buffer', + `freeLength` int(11) NOT NULL DEFAULT 1200 COMMENT 'espacio minimo para declarar el buffer no full', + `isRandomMoving` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'el movimiento aleatorio esta activado', + `bufferNoLabels` int(11) NOT NULL DEFAULT 22 COMMENT 'buffer destino para cajas sin etiqueta', + `bufferTwoLabels` int(11) NOT NULL DEFAULT 24 COMMENT 'buffer destino para cajas con 2 etiquetas o más', + `bufferWidthMargin` int(11) NOT NULL DEFAULT 100 COMMENT 'margen mínimo para que una caja pueda entrar en un buffer', + `bufferDefault` int(11) NOT NULL DEFAULT 26 COMMENT 'buffer por defecto si no se encuentra otro', + `bufferLength` int(11) NOT NULL DEFAULT 13000 COMMENT 'Longitud de los buffers, en mm', + `id` int(11) NOT NULL DEFAULT 1, + `maxBoxesInBuffer` int(11) NOT NULL DEFAULT 8 COMMENT 'max numero de cajas por buffer para declararlo full', + `isEnteringBlocked` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'bloquea la entrada de nuevas cajas al sorter', + `isAuto` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'deja el sorter en auto por un buffer', + `minBoxesToUnloading` int(11) NOT NULL DEFAULT 9 COMMENT 'num de cajas mínimo para generar una descarga', + `minutesBeforeTruckDeparture` int(11) NOT NULL DEFAULT 60 COMMENT 'minutos a descontar de la hora de partida del camion para descargar el sorter', + `groupingMode` enum('TRUCK','ROUTE','BUFFER','BUFFERGROUP') NOT NULL DEFAULT 'TRUCK', + `expedition_setDimensions` int(11) NOT NULL, + `lengthSensorSpacing` int(11) NOT NULL DEFAULT 0 COMMENT 'Separación entre sensores en milimetros - largo', + `widthSensorSpacing` int(11) NOT NULL DEFAULT 0 COMMENT 'Separación entre sensores en milimetros - ancho', + `enteringSecondsReserve` int(11) NOT NULL DEFAULT 0, + `lengthToFirstSensor` int(11) NOT NULL COMMENT 'Distancia a sumar en milímetros hasta primer sensor', + `widthToFirstSensor` int(11) NOT NULL COMMENT 'Distancia a sumar en milímetros hasta primer sensor ', + `movingMaxLife` int(11) NOT NULL DEFAULT 30 COMMENT 'Tiempo máximo (en minutos) que puede estar un registro en la tabla srt.moving', + `motorsMargin` int(11) DEFAULT 3 COMMENT 'margen de motores para considerar FULL el buffer', + `isBalanced` tinyint(1) NOT NULL DEFAULT 1, + `testMode` tinyint(1) NOT NULL DEFAULT 0, + `isAllowedUnloading` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Permite que se pueda cambiar el mode de los buffers a UNLOADING', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `enteringLog` +-- + +DROP TABLE IF EXISTS `enteringLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `enteringLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `expeditionFk` int(11) DEFAULT NULL, + `expeditionOutFk` int(11) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expedition` +-- + +DROP TABLE IF EXISTS `expedition`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expedition` ( + `id` int(11) NOT NULL, + `weight` decimal(10,2) DEFAULT NULL COMMENT 'peso en kg', + `width` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'ancho en milímetros', + `length` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'largo en milímetros', + `height` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'alto en milímetros', + `bufferFk` int(11) DEFAULT NULL COMMENT 'buffer', + `position` int(11) DEFAULT NULL COMMENT 'posicion con respecto al celuveyor', + `stateFk` int(11) NOT NULL DEFAULT 0, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `updated` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `expedition_fk_idx` (`bufferFk`), + KEY `expedition_fk2_idx` (`stateFk`), + CONSTRAINT `expedition_FK` FOREIGN KEY (`stateFk`) REFERENCES `expeditionState` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `expedition_FK_1` FOREIGN KEY (`bufferFk`) REFERENCES `buffer` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla se almacenan los datos físicos y la posicion de cada caja en el sorter'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expeditionLoading` +-- + +DROP TABLE IF EXISTS `expeditionLoading`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expeditionLoading` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `expeditionFk` int(11) NOT NULL, + `bufferFk` int(11) NOT NULL DEFAULT 24, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `expeditionLoading_UN` (`expeditionFk`), + KEY `expeditionLoading_FK` (`bufferFk`), + CONSTRAINT `expeditionLoading_FK` FOREIGN KEY (`bufferFk`) REFERENCES `buffer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `expeditionLoading_FK_1` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena las expediciones que van a entrar al sorter por los buffers en modo loading'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expeditionLog` +-- + +DROP TABLE IF EXISTS `expeditionLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expeditionLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `expeditionFk` int(11) DEFAULT NULL, + `bufferFk` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `action` varchar(3) NOT NULL, + `antennaFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `expeditionLog_FK_1` (`bufferFk`), + KEY `expeditionLog_FK_2` (`antennaFk`), + CONSTRAINT `expeditionLog_FK_1` FOREIGN KEY (`bufferFk`) REFERENCES `buffer` (`id`) ON UPDATE CASCADE, + CONSTRAINT `expeditionLog_FK_2` FOREIGN KEY (`antennaFk`) REFERENCES `antenna` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expeditionState` +-- + +DROP TABLE IF EXISTS `expeditionState`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expeditionState` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(45) NOT NULL, + `isMovable` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Estados que correponden a cajas paradas en el sorter', + `isInside` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `expeditionVolume` +-- + +DROP TABLE IF EXISTS `expeditionVolume`; +/*!50001 DROP VIEW IF EXISTS `expeditionVolume`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `expeditionVolume` AS SELECT + 1 AS `dayMinute`, + 1 AS `ETD`, + 1 AS `cajas`, + 1 AS `isReady`, + 1 AS `truck`, + 1 AS `zonaTicket`, + 1 AS `bufferTruck` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `failureLog` +-- + +DROP TABLE IF EXISTS `failureLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `failureLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `lastRFID` +-- + +DROP TABLE IF EXISTS `lastRFID`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `lastRFID` ( + `code` varchar(20) NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `antennaFk` int(11) NOT NULL, + `isConsulted` tinyint(1) NOT NULL DEFAULT 0, + `isChoosed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Es la lectura devuelta', + `id` int(11) NOT NULL AUTO_INCREMENT, + `antennaPort` int(11) DEFAULT NULL COMMENT 'puerto al que esta conectada la antena en el switch', + `peakRssi` int(11) DEFAULT NULL COMMENT 'intensidad media de lectura', + `seenCount` int(11) DEFAULT NULL COMMENT 'número de veces que se ha leido el mismo código', + PRIMARY KEY (`id`), + KEY `lastRFID_antennaFk_IDX` (`antennaFk`) USING BTREE, + CONSTRAINT `lastRFID_FK` FOREIGN KEY (`antennaFk`) REFERENCES `antenna` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='last codes read by the antennas'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `moving` +-- + +DROP TABLE IF EXISTS `moving`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `moving` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `expeditionFk` int(11) DEFAULT NULL, + `bufferFromFk` int(11) DEFAULT NULL, + `bufferToFk` int(11) DEFAULT NULL, + `stateFk` int(11) NOT NULL DEFAULT 1, + `isColliding` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Define si el movimiento colisiona con los que ya estan en marcha', + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `moving_UN` (`expeditionFk`), + KEY `moving_fk1_idx` (`expeditionFk`), + KEY `moving_fk2_idx` (`bufferFromFk`), + KEY `moving_fk3_idx` (`bufferToFk`), + KEY `moving_FK` (`stateFk`), + CONSTRAINT `moving_FK` FOREIGN KEY (`stateFk`) REFERENCES `movingState` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `moving_FK_1` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `moving_fk2` FOREIGN KEY (`bufferFromFk`) REFERENCES `buffer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `moving_fk3` FOREIGN KEY (`bufferToFk`) REFERENCES `buffer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `movingLast` +-- + +DROP TABLE IF EXISTS `movingLast`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `movingLast` ( + `id` int(11) NOT NULL, + `expeditionFk` int(11) DEFAULT NULL, + `bufferFromFk` int(11) DEFAULT NULL, + `bufferToFk` int(11) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `movingLog` +-- + +DROP TABLE IF EXISTS `movingLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `movingLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `expeditionFk` int(11) DEFAULT NULL, + `bufferFromFk` int(11) DEFAULT NULL, + `bufferToFk` int(11) DEFAULT NULL, + `stateFk` int(11) DEFAULT NULL, + `isColliding` tinyint(1) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `movingFk` int(11) NOT NULL, + `action` varchar(25) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `movingState` +-- + +DROP TABLE IF EXISTS `movingState`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `movingState` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(20) NOT NULL, + `isInterfering` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'afecta al calculo de los posibles movimientos', + `isRedirectable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'admite cambio de destino', + `isBeforeCelluveyor` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'define los estados que aún estan en el buffer origen', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `photocell` +-- + +DROP TABLE IF EXISTS `photocell`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `photocell` ( + `bufferFk` int(11) NOT NULL, + `position` int(11) NOT NULL COMMENT 'Posición relativa al celluveyor de dentro a fuera, siendo 1 la más cercana a este', + `isActive` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`bufferFk`,`position`), + CONSTRAINT `photocell_FK` FOREIGN KEY (`bufferFk`) REFERENCES `buffer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `routePalletized` +-- + +DROP TABLE IF EXISTS `routePalletized`; +/*!50001 DROP VIEW IF EXISTS `routePalletized`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `routePalletized` AS SELECT + 1 AS `routeFk`, + 1 AS `expediciones`, + 1 AS `paletizadas` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `routeVolume` +-- + +DROP TABLE IF EXISTS `routeVolume`; +/*!50001 DROP VIEW IF EXISTS `routeVolume`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `routeVolume` AS SELECT + 1 AS `dayMinute`, + 1 AS `ETD`, + 1 AS `cajas`, + 1 AS `isReady`, + 1 AS `routeFk`, + 1 AS `zonaTicket`, + 1 AS `bufferTruck`, + 1 AS `routeBuffer` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `sorterLog` +-- + +DROP TABLE IF EXISTS `sorterLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sorterLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + `action` varchar(25) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `ticketPalletized` +-- + +DROP TABLE IF EXISTS `ticketPalletized`; +/*!50001 DROP VIEW IF EXISTS `ticketPalletized`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketPalletized` AS SELECT + 1 AS `ticketFk`, + 1 AS `routeFk`, + 1 AS `expediciones`, + 1 AS `paletizadas` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `upperStickers` +-- + +DROP TABLE IF EXISTS `upperStickers`; +/*!50001 DROP VIEW IF EXISTS `upperStickers`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `upperStickers` AS SELECT + 1 AS `expeditionFk`, + 1 AS `expedition`, + 1 AS `ETD`, + 1 AS `ticketFk`, + 1 AS `routeFk`, + 1 AS `zonaTicket`, + 1 AS `truck`, + 1 AS `worker`, + 1 AS `labeler`, + 1 AS `expeditionCounter`, + 1 AS `m3`, + 1 AS `clientFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Dumping events for database 'srt' +-- +/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; +/*!50106 DROP EVENT IF EXISTS `moving_clean` */; +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 = utf8mb3 */ ;; +/*!50003 SET character_set_results = utf8mb3 */ ;; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `moving_clean` ON SCHEDULE EVERY 5 MINUTE STARTS '2022-01-21 00:00:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Llama a srt.moving_clean para que elimine y notifique de registr' DO BEGIN + + CALL srt.moving_clean(); + +END */ ;; +/*!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 */ ; + +-- +-- Dumping routines for database 'srt' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `bid` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `bid`(vCode VARCHAR(3)) RETURNS int(11) + DETERMINISTIC +BEGIN + + /** + * Devuelve el identificador de vn.buffer a partir del código + * + * @param vCode código de vn.buffer + * @return Identificador de vn.buffer + * + */ + + DECLARE vNumber INT; + DECLARE vLetter VARCHAR(1); + + IF LENGTH(vCode) < 3 THEN + + SET vCode = CONCAT('0',vCode); + + END IF; + + SELECT LEFT(vCode,2), RIGHT(vCode,1) INTO vNumber, vLetter; + + IF vLetter = 'A' THEN + + RETURN vNumber * 2; + + ELSE + + RETURN VNumber * 2 + 1; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `bufferPool_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `bufferPool_get`() RETURNS int(11) + READS SQL DATA +BEGIN + + /** + * Devuelve el primer bufferFk de la tabla srt.bufferPool + * + * @return Identificador de vn.buffer + * + */ + + DECLARE vBufferFk INT; + + DECLARE vBufferPoolFk INT; + + SELECT MIN(id) INTO vBufferPoolFk + FROM srt.bufferPool; + + IF vBufferPoolFk THEN + + SELECT bufferFk INTO vBufferFk + FROM srt.bufferPool + WHERE id = vBufferPoolFk; + + DELETE + FROM srt.bufferPool + WHERE id = vBufferPoolFk; + + ELSE + + RETURN 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `buffer_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `buffer_get`(vExpeditionFk INT) RETURNS int(11) + READS SQL DATA +BEGIN +/** + * Devuelve el buffer destino para una expedición + * + * @param vExpeditionFk Identificador de srt.expedition + * @return Identificador de srt.buffer + */ + DECLARE vBufferToFk INT; + DECLARE vBufferFromFk INT; + DECLARE vBufferGroup INT; + DECLARE vBufferStrapping INT; + + SELECT IFNULL(rm.bufferFk, c.bufferDefault), IFNULL(e.bufferFk,0) + INTO vBufferToFk, vBufferFromFk + FROM srt.expedition e + LEFT JOIN vn.expedition e2 ON e2.id = e.id + LEFT JOIN vn.ticket t ON t.id = e2.ticketFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN srt.config c + WHERE e.id = vExpeditionFk; + + SELECT `group` INTO vBufferGroup + FROM srt.bufferGroup + WHERE bufferFk = vBufferToFk; + + SELECT bg.bufferFk + INTO vBufferStrapping + FROM srt.bufferGroup bg + JOIN srt.buffer b ON b.id = bg.bufferFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE bt.typeName = 'STRAPPING' + AND bg.`group` = vBufferGroup + LIMIT 1; + + IF vBufferGroup THEN + SELECT sub.bufferFk INTO vBufferToFk + FROM ( + SELECT b.id bufferFk, + count(DISTINCT e.id) expeditions, + bs.description, + bt.typeName, + b.motors + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.bufferState bs ON bs.id = b.stateFk + JOIN srt.bufferGroup bg ON bg.bufferFk = b.id + LEFT JOIN srt.expedition e ON e.bufferFk = b.id + LEFT JOIN srt.moving m ON m.bufferFromFk = b.id + WHERE bg.`group` = vBufferGroup + AND b.id != vBufferFromFk + AND bt.isTarget + AND m.id IS NULL + GROUP BY b.id) sub + JOIN srt.config c + ORDER BY (sub.description = 'FREE') DESC, + (sub.typeName = ('STRAPPING')) DESC, + IF(c.isBalanced , sub.expeditions, -sub.expeditions), + ABS(sub.bufferFk - vBufferStrapping) + LIMIT 1; + END IF; + + RETURN vBufferToFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `buffer_getRandom` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `buffer_getRandom`() RETURNS int(11) + READS SQL DATA +BEGIN + + /* Devuelve de forma aleatoria, uno de entre los buffers que tienen flejadora + * + */ + + DECLARE vBufferFk INT; + + SELECT b.id INTO vBufferFk + FROM srt.buffer b + WHERE b.hasStrapper + ORDER BY RAND() + LIMIT 1; + + RETURN vBufferFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `buffer_getState` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `buffer_getState`(vSelf INT) RETURNS varchar(20) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + READS SQL DATA +BEGIN + + /** + * Devuelve una cadena con el estado del buffer + * + */ + + DECLARE vState VARCHAR(20); + + SELECT bs.description INTO vState + FROM srt.buffer b + JOIN srt.bufferState bs ON bs.id = b.stateFk + WHERE b.id = vSelf; + + RETURN vState; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `buffer_getType` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `buffer_getType`(vSelf INT) RETURNS varchar(20) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + READS SQL DATA +BEGIN + + /** + * Devuelve una cadena con el tipo del buffer + * + */ + + DECLARE vType VARCHAR(20); + + SELECT bt.typeName INTO vType + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE b.id = vSelf; + + RETURN vType; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `buffer_isFull` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `buffer_isFull`(vBufferFk INT) RETURNS tinyint(1) + READS SQL DATA +BEGIN + + /** + * Comprueba si un buffer está lleno + * + * @param vBufferFk Identificador de vn.buffer + * + */ + + DECLARE vBufferStock INT; + DECLARE vIsFull BOOL; + + SELECT COUNT(*) INTO vBufferStock + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e.bufferFk = vBufferFk + AND ISNULL(m.id); + + SELECT vBufferStock + COUNT(*) INTO vBufferStock + FROM srt.moving m + WHERE m.bufferToFk = vBufferFk; + + SELECT (vBufferStock >= maxBoxesInBuffer) INTO vIsFull + FROM srt.config; + + RETURN vIsFull; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `dayMinute` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `dayMinute`(vDateTime DATETIME) RETURNS int(11) + READS SQL DATA +BEGIN + + /* + * Devuelve el numero de minutos absoluto diario + * + * @vDateTime Fecha a analizar + * + */ + + RETURN HOUR(vDateTime) * 60 + MINUTE(vDateTime); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `expedition_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `expedition_check`(vExpeditionFk INT) RETURNS int(11) + READS SQL DATA +BEGIN + + /** + * Comprueba si existe una expedición, generando una aleatoria en caso contrario. + * + * @param vExpeditionFk Identificador de srt.expedition + * + */ + + DECLARE vExpeditionOutFk INT; + DECLARE vIsOnTheCelluveyor BOOL; + + SELECT id INTO vExpeditionOutFk + FROM srt.expedition + WHERE id = vExpeditionFk; + + SELECT COUNT(*) INTO vIsOnTheCelluveyor + FROM srt.moving m + JOIN srt.movingState ms ON ms.id = m.stateFk + WHERE m.expeditionFk = vExpeditionFk + AND ms.description != 'NEW'; + + IF ISNULL(vExpeditionOutFk) OR vIsOnTheCelluveyor THEN + + SELECT LEAST(-1,MIN(id)- 1) INTO vExpeditionOutFk + FROM srt.expedition; + + CASE vExpeditionFk + + WHEN 0 THEN -- Genera una EXP que termine en 0 + + SET vExpeditionOutFk = CEIL((vExpeditionOutFk - 10) / 10) * 10; + + WHEN 2 THEN -- Genera una EXP que termine en 2 + + SET vExpeditionOutFk = -2 + CEIL((vExpeditionOutFk - 10) / 10) * 10; + + ELSE -- Genera una EXP que termine en 9 + + SET vExpeditionOutFk = -9 + CEIL((vExpeditionOutFk - 10) / 10) * 10; + + END CASE; + + INSERT INTO srt.expedition(id,stateFk,width,`length`, height) + SELECT vExpeditionOutFk, es.id , p.width * 10, p.`depth` *10, p.height * 10 + FROM srt.expeditionState es + JOIN vn.packaging p ON p.id = '94' + WHERE es.description = 'ENTERING'; + + END IF; + + RETURN vExpeditionOutFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `expedition_getDayMinute` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `expedition_getDayMinute`(vExpeditionFk INT) RETURNS int(11) + READS SQL DATA +BEGIN + + /** + * Devuelve el minuto absoluto ( un dia tiene 24 x 60 minutos ) de salida del camión + * + * @param vExpeditionFk Identificador de srt.expedition + * + * @return vDayMinute Minuto absoluto diario + */ + + DECLARE vDayMinute INT; + + SELECT HOUR(IFNULL(et.ETD, z.`hour`)) * 60 + MINUTE(IFNULL(et.ETD, z.`hour`)) INTO vDayMinute + FROM vn.expedition e + JOIN vn.ticket t ON e.ticketFk = t.id + JOIN vn.`zone` z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON t.routeFk = rm.routeFk + LEFT JOIN vn.expeditionTruck et ON rm.expeditionTruckFk = et.id + WHERE e.id = vExpeditionFk; + + RETURN vDayMinute; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_getExpCount` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_getExpCount`(IN vBufferFk INT, OUT vExpCount INT) +BEGIN +/* Devuelve el número de expediciones de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @param vExpCount Número de expediciones + */ + SELECT COUNT(*) + INTO vExpCount + FROM srt.expedition + WHERE bufferFk = vBufferFk; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_getStateType` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_getStateType`(vBufferFk INT, OUT vStateFk INT, OUT vTypeFk INT) +BEGIN + + /** + * Devuelve el estado y el tipo de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @return vStateFk Identificador de srt.bufferState + * @return vTypeFk Identificador de srt.bufferType + * + */ + + SELECT b.stateFk, b.typeFk INTO vStateFk, vTypeFk + FROM srt.buffer b + WHERE b.id = vBufferFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_giveBack` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_giveBack`(vSelf INT) +BEGIN + + /* Devuelve una caja al celluveyor * + * + * @param vSelf Identificador de srt.buffer + */ + + DECLARE vExpeditionFk INT; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + WHERE e.bufferFk = vSelf + ORDER BY e.`position` + LIMIT 1; + + IF vExpeditionFk THEN + + CALL srt.expedition_relocate(vExpeditionFk, srt.buffer_get(vExpeditionFk)); + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_readPhotocell` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_readPhotocell`(vSelf INT, vNumber INT) +BEGIN +/** + * Establece el estado de un buffer en función del número de fotocélulas activas + * + * @param vSelf Identificador de srt.buffer + * @param vNumber Número de fotocélulas activas + */ + DECLARE vIsFull BOOL; + DECLARE vBoxes INT; + DECLARE vMotors INT; + DECLARE vMargin INT; + + SELECT ((COUNT(*) + vNumber + c.motorsMargin) >= b.motors AND b.motors > 1), COUNT(*), b.motors, c.motorsMargin + INTO vIsFull, vBoxes, vMotors, vMargin + FROM srt.buffer b + LEFT JOIN srt.moving m ON m.bufferToFk = b.id + JOIN srt.config c + WHERE b.id = vSelf; + + IF vIsFull THEN + CALL srt.buffer_setStateType(vSelf, 'FULL', NULL); + ELSE + CALL srt.buffer_setStateType(vSelf, 'FREE', 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_setEmpty` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_setEmpty`(vBufferFk INT) +BEGIN + + /** + * Actualiza a NULL el valor bufferFk de las expediciones que esten en ese buffer + * + * @param vBufferFk Identificador de srt.buffer + * + */ + + UPDATE srt.expedition e + SET e.bufferFk = NULL + WHERE e.bufferFk = vBufferFk; + + UPDATE srt.buffer b + SET b.typeFk = b.typeDefaultFk + WHERE b.id = vBufferFk; + + CALL srt.buffer_setStateType(vBufferFk, 'FREE', 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_setState` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_setState`(vBufferFk INT(11), vStateFk INT(11)) +BEGIN + + /** + * Cambia el estado de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @param vStateFk Identificador de srt.bufferState + * + */ + + UPDATE srt.buffer b + SET b.stateFk = vStateFk + WHERE b.id = vBufferFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_setStateType` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_setStateType`(vBufferFk INT, vState VARCHAR(25), vType VARCHAR(25)) +BEGIN + + /** + * Cambia el estado y el tipo de un buffer + * + * @param vBufferFk Identificador del buffer + * @param vState Estado + * @param vType Tipo + * + */ + + DECLARE vBufferStateFk INT; + DECLARE vBufferTypeFk INT; + + IF NOT ISNULL(vState) THEN + + SELECT bs.id INTO vBufferStateFk + FROM srt.bufferState bs + WHERE bs.description = vState; + + CALL srt.buffer_setState(vBufferFk, vBufferStateFk); + + END IF; + + IF NOT ISNULL(vType) THEN + + IF vType = 'DEFAULT' THEN + + SELECT b.typeDefaultFk INTO vBufferTypeFk + FROM srt.buffer b + WHERE b.id = vBufferFk; + + ELSE + + SELECT bt.id INTO vBufferTypeFk + FROM srt.bufferType bt + WHERE bt.typeName = vType; + + END IF; + + CALL srt.buffer_setType(vBufferFk, vBufferTypeFk); + + IF vType = 'UNLOADING' THEN + + UPDATE srt.buffer + SET lastUnloaded = util.VN_NOW() + WHERE id = vBufferFk; + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_setType` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_setType`(vBufferFk INT(11), vTypeFk INT(11)) +BEGIN +/** + * Cambia el tipo de un buffer, si está permitido + * + * @param vBufferFk Identificador de srt.buffer + * @param vTypeFk Identificador de srt.bufferType + * + */ + UPDATE srt.buffer b + JOIN srt.config c + JOIN srt.bufferType bt ON bt.typeName = 'UNLOADING' + SET b.typeFk = vTypeFk + WHERE b.id = vBufferFk + AND (vTypeFk <> bt.id OR c.isAllowedUnloading); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buffer_setTypeByName` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buffer_setTypeByName`(vBufferFk INT(11), vTypeName VARCHAR(100)) +BEGIN + + /** + * Cambia el tipo de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @param vTypeName Nombre Identificador de srt.bufferType + * + */ + + DECLARE vTypeFk INT; + + SELECT bt.id INTO vTypeFk + FROM srt.bufferType bt + WHERE bt.typeName = vTypeName; + + UPDATE srt.buffer b + SET b.typeFk = vTypeFk + WHERE b.id = vBufferFk; + + SELECT count(*) + FROM srt.buffer b + WHERE b.id = vBufferFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() +BEGIN + DECLARE vLastDated DATE DEFAULT TIMESTAMPADD(WEEK,-2,util.VN_CURDATE()); + + DELETE FROM srt.lastRFID + WHERE created < vLastDated; + + DELETE FROM srt.expedition + WHERE created < vLastDated; + + DELETE FROM srt.moving; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expeditionLoading_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionLoading_add`(vExpeditionFk INT, vBufferFk INT) +BEGIN + + DECLARE vMessage VARCHAR(50) DEFAULT ''; + + IF (SELECT COUNT(*) FROM srt.buffer WHERE id = vBufferFk) = 0 THEN + + SET vMessage = 'Buffer incorrecto'; + + END IF; + + IF (SELECT COUNT(*) FROM srt.expedition WHERE id = vExpeditionFk) = 0 THEN + + SET vMessage = 'Expedición no existe'; + + END IF; + + IF LENGTH(vMessage) = 0 THEN + + REPLACE srt.expeditionLoading (expeditionFk, bufferFk) + VALUES (vExpeditionFk, vBufferFk); + + SET vMessage = 'Registro añadido'; + + END IF; + + SELECT vMessage; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_arrived` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_arrived`(vExpeditionFk INT, vBufferFk INT, OUT vTypeFk INT) +BEGIN +/** + * La expedición ha entrado en un buffer, superando fc2 + * + * @param vExpeditionFk Identificador de srt.expedition + * @param vBufferFk Identificador de srt.buffer + * + * @return vTypeFk Identificador de srt.bufferType + * + */ + DECLARE vComingBoxes INT; + DECLARE vHasWorkerWaiting BOOL; + DECLARE vIsRandomMoving BOOL; + DECLARE vState VARCHAR(15); + DECLARE vType VARCHAR(15); + DECLARE visBufferWhithoutBoxesCount BOOL; + + IF vBufferFk = 1 THEN + SET vBufferFk = 0; + END IF; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'ARR'); + + SELECT COUNT(*) INTO vComingBoxes + FROM srt.moving m + WHERE m.bufferToFk = vBufferFk + AND m.expeditionFk != vExpeditionFk; + + SELECT b.hasWorkerWaiting, + c.isRandomMoving , + (bt.typeName = 'STRAPPING') OR vBufferFk IN (c.bufferNoLabels, c.bufferTwoLabels, c.bufferDefault) + INTO vHasWorkerWaiting, + vIsRandomMoving, + visBufferWhithoutBoxesCount + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.config c + WHERE b.id = vBufferFk + LIMIT 1; + + SET vState = IF(srt.buffer_isFull(vBufferFk), 'FULL', 'FREE'); + + SET vType = IF(vHasWorkerWaiting + AND NOT vComingBoxes + AND NOT vIsRandomMoving + AND vState = 'FULL', 'UNLOADING', 'ACCUMULATION'); + + IF NOT visBufferWhithoutBoxesCount THEN + CALL srt.buffer_setStateType(vBufferFk,vState,vType); + END IF; + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'STORED' + SET e.bufferFk = IF(visBufferWhithoutBoxesCount,0,vBufferFk), + e.`position` = 0, + e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + UPDATE srt.expedition e + SET e.`position` = e.`position` + 1 + WHERE e.bufferFk = vBufferFk + AND e.bufferFk > 0; + + INSERT INTO srt.movingLog(expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, movingFk, `action`) + SELECT expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, id, 'ARRIVED' + FROM srt.moving + WHERE expeditionFk = vExpeditionFk + ORDER BY id DESC + LIMIT 1; + + DELETE FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + + SELECT bt.id INTO vTypeFk + FROM srt.bufferType bt + JOIN srt.buffer b ON b.typeFk = bt.id + WHERE b.id = vBufferFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_bufferOut` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_bufferOut`(vBufferToFk INT) +BEGIN + + /** + * Selecciona y enruta las expediciones en el sorter hacia un buffer de salida, que sean de ese buffer + * + * @param vBufferToFk Identificador de srt.buffer + */ + + DECLARE vExpListFk INT; + + DECLARE vExpBufFk INT; + + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vExpList CURSOR FOR + SELECT bs.expeditionFk + FROM srt.bufferStock bs + JOIN srt.expedition e ON e.id = bs.expeditionFk + LEFT JOIN srt.moving m ON m.expeditionFk = bs.expeditionFk + WHERE bs.routeBuffer = vBufferToFk + AND ISNULL(m.expeditionFk) + AND bs.typeName = 'ACCUMULATION' + ORDER BY (vBufferToFk - e.bufferFk), + e.`position` ; + + DECLARE vExpBuf CURSOR FOR + SELECT e.id + FROM srt.expedition e + JOIN srt.expedition e2 ON e2.bufferFk = e.bufferFk + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e2.id = vExpListFk + AND ISNULL(m.expeditionFk) + AND e.`position` <= e2.`position` + ORDER BY e.`position`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vExpList; + + FETCH vExpList INTO vExpListFk; + + WHILE NOT vDone DO + + OPEN vExpBuf; + + FETCH vExpBuf INTO vExpBufFk; + + WHILE NOT vDone DO + + IF vExpBufFk = vExpListFk THEN + + CALL srt.expedition_relocate(vExpListFk, vBufferToFk); + + SET vDone = TRUE; + + ELSE + + CALL srt.expedition_relocate(vExpBufFk, NULL); + + SET vDone = FALSE; + + FETCH vExpBuf INTO vExpBufFk; + + END IF; + + END WHILE; + + CLOSE vExpBuf; + + SET vDone = FALSE; + + FETCH vExpList INTO vExpListFk; + + END WHILE; + + CLOSE vExpList; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_entering` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_entering`(vExpeditionFk INT, OUT vExpeditionOutFk INT ) +BEGIN + + /** + * Una expedición llega a la entrada del celuveyor y comunica su ID + * + * @param vExpeditionFk Identificador de srt.expedition + * + * @return vExpeditionOutFk Identificador de srt.expedition + * + */ + + DECLARE vBufferFk INT DEFAULT NULL; + + SET vExpeditionOutFk = srt.expedition_check(vExpeditionFk); + + IF vExpeditionOutFk < 0 THEN + + SELECT IF(vExpeditionOutFk MOD 10 = 0, c.bufferNoLabels, c.bufferTwoLabels) + INTO vBufferFk + FROM srt.config c; + + END IF; + + UPDATE srt.expedition e + SET e.bufferFk = 0 + WHERE id = vExpeditionOutFk; + + UPDATE srt.moving m + JOIN srt.movingState ms ON ms.description = 'NEW' + SET m.stateFk = ms.id + WHERE m.expeditionFk = vExpeditionOutFk; + + IF (SELECT isAuto FROM srt.config) THEN + + SELECT b.id INTO vBufferFk + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE b.isActive + ORDER BY (bt.typeName = 'STRAPPING') DESC, + b.hasWorkerWaiting DESC, + srt.buffer_IsFull(b.id), + b.stateFk, + b.typeFk, + b.lastUnloaded, + b.id DESC + LIMIT 1; + + END IF; +/* + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionOutFk, 0, 'ENT'); + + INSERT INTO srt.enteringLog(expeditionFk , expeditionOutFk ) + VALUES(vExpeditionFk, vExpeditionOutFk); +*/ + CALL srt.expedition_relocate(vExpeditionOutFk, vBufferFk); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_get` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_get`(vAntennaFk INT, OUT vExpeditionOutFk INT ) +BEGIN + + DECLARE vId INT; + DECLARE vCount INT; + DECLARE vCreatedMin DATETIME; + DECLARE vCreatedMax DATETIME; + DECLARE vSecondsScope INT DEFAULT 30; + + START TRANSACTION; + + SELECT count(DISTINCT lr.code) INTO vCount + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted; + + CASE vCount + + WHEN 0 THEN + + SET vExpeditionOutFk = srt.expedition_check(vCount); + + WHEN 1 THEN + + SELECT CAST(code AS DECIMAL(10,0)), lr.id + INTO vExpeditionOutFk, vId + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted + ORDER BY lr.seenCount DESC, lr.peakRssi + LIMIT 1; + + ELSE + + -- Descartamos aquellas lecturas que se han producido unos segundos antes. + SELECT MIN(created), MAX(created) INTO vCreatedMin, vCreatedMax + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted; + + UPDATE srt.lastRFID lr + JOIN (SELECT id, code + FROM srt.lastRFID + WHERE created + BETWEEN TIMESTAMPADD(SECOND, - vSecondsScope, vCreatedMin) + AND TIMESTAMPADD(SECOND, -1, vCreatedMin) + AND isChoosed = 1# + ) sub ON sub.code = lr.code AND sub.id != lr.id + SET lr.isConsulted = TRUE + WHERE lr.created BETWEEN vCreatedMin AND vCreatedMax + AND lr.antennaFk = vAntennaFk; + + SELECT CAST(code AS DECIMAL(10,0)), lr.id + INTO vExpeditionOutFk, vId + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted + ORDER BY lr.peakRssi DESC, lr.seenCount DESC # + LIMIT 1; + + END CASE; + + UPDATE srt.lastRFID + SET isChoosed = TRUE + WHERE id = vId; + + UPDATE srt.lastRFID + SET isConsulted = TRUE + WHERE antennaFk = vAntennaFk + AND NOT isConsulted; + + COMMIT; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`, antennaFk) VALUES(vExpeditionOutFk, 0, 'DIM', vAntennaFk); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_groupOut` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_groupOut`(vDayMinute INT, vBufferToFk INT) +BEGIN + + /** + * Selecciona y enruta las expediciones en el sorter hacia un buffer de salida, que sean de la hora pedida + * + * @param vDayMinute Minuto absoluto del dia + * @param vBufferToFk Identificador de srt.buffer + * + */ + + DECLARE vExpListFk INT; + + DECLARE vExpBufFk INT; + + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vExpList CURSOR FOR + SELECT bs.expeditionFk + FROM srt.bufferStock bs + JOIN srt.expedition e ON e.id = bs.expeditionFk + WHERE bs.dayMinute = vDayMinute + AND bs.expeditionState = 'STORED' + AND bs.isActive + AND bs.hasWorkerWaiting = FALSE + AND bs.typeName = 'ACCUMULATION' + ORDER BY (vBufferToFk - e.bufferFk), + e.`position`; + + DECLARE vExpBuf CURSOR FOR + SELECT e.id + FROM srt.expedition e + JOIN srt.expedition e2 ON e2.bufferFk = e.bufferFk + JOIN srt.expeditionState es ON es.id = e.stateFk + WHERE e2.id = vExpListFk + AND e.`position` <= e2.`position` + AND es.description = 'STORED' + ORDER BY e.`position`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vExpList; + + FETCH vExpList INTO vExpListFk; + + UPDATE srt.moving m + JOIN srt.movingState ms ON ms.id = m.stateFk + SET m.bufferToFk = vBufferToFk + WHERE m.expeditionFk = vExpListFk + AND ms.isRedirectable + AND m.bufferFromFk != vBufferToFk; + + WHILE NOT vDone DO + + OPEN vExpBuf; + + FETCH vExpBuf INTO vExpBufFk; + + WHILE NOT vDone DO + + IF vExpBufFk = vExpListFk THEN + + CALL srt.expedition_Relocate(vExpListFk, vBufferToFk); + + SET vDone = TRUE; + + ELSE + + CALL srt.expedition_Relocate(vExpBufFk, NULL); + + SET vDone = FALSE; + + FETCH vExpBuf INTO vExpBufFk; + + END IF; + + END WHILE; + + CLOSE vExpBuf; + + SET vDone = FALSE; + + FETCH vExpList INTO vExpListFk; + + END WHILE; + + CLOSE vExpList; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_in` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_in`(vBufferFk INT, OUT vExpeditionFk INT) +proc:BEGIN + + /** + * Ha entrado una caja en un buffer, por la zona de descarga. + * + * @param vBufferFk Identificador de srt.buffer + * + * @return vExpeditionFk Identificador de srt.expedition * + */ + + DECLARE vMaxPosition INT; + DECLARE vIsBufferFull BOOL; + DECLARE vBufferTypeFk INT; + DECLARE vBufferStateFk INT; + + SELECT el.expeditionFk INTO vExpeditionFk + FROM srt.expeditionLoading el + WHERE el.bufferFk = vBufferFk + ORDER BY id + LIMIT 1; + + IF vExpeditionFk THEN + + DELETE FROM srt.expeditionLoading + WHERE expeditionFk = vExpeditionFk; + + -- SET vExpeditionFk = srt.expedition_check(vExpeditionFk); + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'IN'); + + SELECT MAX(e.position) INTO vMaxPosition + FROM srt.expedition e + WHERE e.bufferFk = vBufferFk; + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'STORED' + SET e.bufferFk = vBufferFk, + e.`position` = IFNULL(vMaxPosition,0) + 1, + e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + SELECT bfl.freeLength < c.freeLength * 2 INTO vIsBufferFull + FROM srt.bufferFreeLength bfl + JOIN srt.config c + WHERE bfl.bufferFk = vBufferFk; + + IF vIsBufferFull THEN + + CALL srt.buffer_setStateType(vBufferFk, 'FREE','ACCUMULATION'); + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_moving` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_moving`(vBufferFk INT) +BEGIN + + /** + * Una expedición ha entrado en el celuveyor desde un buffer + * + * @param vBufferFk Identificador de srt.buffer + * + */ + + DECLARE vExpeditionFk INT; + DECLARE vPosition INT; + + SELECT min(`position`) INTO vPosition + FROM srt.expedition e + WHERE e.bufferFk = vBufferFk; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + WHERE e.`position` = vPosition + AND e.bufferFk = vBufferFk + LIMIT 1; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'MOV'); + + UPDATE srt.expedition e + JOIN srt.expeditionState es on es.description = 'MOVING' + JOIN srt.moving m ON m.expeditionFk = e.id + SET e.stateFk = es.id, + e.bufferFk = m.bufferToFk, + e.`position` = 0 + WHERE e.id = vExpeditionFk; + + SET @posicion := 0; + + UPDATE srt.expedition e + SET e.`position` = @posicion := @posicion + 1 + WHERE e.bufferFk = vBufferFk + AND e.id != vExpeditionFk + ORDER BY e.`position`; + + CALL srt.buffer_setStateType(vBufferFk, 'FREE', 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_out` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_out`(vBufferFk INT, OUT vTypeFk INT) +proc:BEGIN +/** + * Una expedición ha salido de un buffer por el extremo distal + * Se ignorará en caso de que el buffer esté en modo ACCUMULATION + * + * @param vBufferFk Identificador de srt.buffer + * + * @return vTypeFk Identificador de srt.bufferType + */ + + DECLARE vMaxPosition INT; + DECLARE vIsFree BOOL; + DECLARE vExpeditionFk INT; + DECLARE vBufferType VARCHAR(15); + + SELECT bt.typeName + INTO vBufferType + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE b.id = vBufferFk; + + IF vBufferType = 'ACCUMULATION' THEN + LEAVE proc; + END IF; + + SELECT MAX(e.`position`) INTO vMaxPosition + FROM srt.expedition e + WHERE e.bufferFk = vBufferFk; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + WHERE e.`position` = vMaxPosition + AND e.bufferFk = vBufferFk + LIMIT 1; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'OUT'); + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'OUT' + SET e.bufferFk = NULL, + e.`position` = NULL, + e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + SELECT (COUNT(*) = 0) INTO vIsFree + FROM srt.expedition e + JOIN srt.buffer b ON b.id = e.bufferFk + WHERE e.bufferFk = vBufferFk + AND e.`position` > 0; + + IF vIsFree AND vBufferType NOT IN('LOADING','STRAPPING') THEN + + UPDATE srt.buffer SET reserve = NULL, routeFk = NULL, dayMinute = NULL + WHERE id = vBufferFk; + + CALL srt.buffer_setStateType(vBufferFk,'FREE','DEFAULT'); + + END IF; + + SELECT b.typeFk INTO vTypeFk + FROM srt.buffer b + WHERE b.id = vBufferFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_outAll` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_outAll`(vBufferFk INT) +BEGIN + + /** + * Envia todas las expediciones al mismo buffer + * + * @param vBufferFk Identificador de vn.buffer + * + */ + + INSERT INTO srt.moving (expeditionFk, bufferFromFk, bufferToFk) + SELECT e.id, e.bufferFk, vBufferFk + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e.bufferFk > 0 + AND e.bufferFk != vBufferFk + AND ISNULL(m.expeditionFk); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_relocate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_relocate`(vExpeditionFk INT, vBufferToFk INT) +proc:BEGIN + + /** + * Asigna buffer destino nuevo para una expedición + * + * @param vExpeditionFk Identificacion de srt.expedition + * + * @param vBufferToFk Identificador de srt.buffer + * + */ + + DECLARE vBufferFromFk INT; + + START TRANSACTION; + + IF (SELECT COUNT(*) FROM srt.moving WHERE expeditionFk = vExpeditionFk) THEN + + LEAVE proc; + + END IF; + + SELECT e.bufferFk INTO vBufferFromFk + FROM srt.expedition e + WHERE e.id = vExpeditionFk; + + SET vBufferToFk = IFNULL(vBufferToFk, IFNULL(srt.bufferPool_get(), `srt`.`buffer_get`(vExpeditionFk))); + + IF vBufferFromFk = vBufferToFk THEN + + LEAVE proc; + + END IF; + + REPLACE srt.moving (expeditionFk, + bufferFromFk, + bufferToFk, + stateFk) + SELECT e.id, + e.bufferFk, + vBufferToFk, + ms.id + FROM srt.expedition e + JOIN srt.movingState ms ON ms.description = 'NEW' + LEFT JOIN srt.moving m ON m.expeditionFk + WHERE e.id = vExpeditionFk; + + UPDATE srt.expedition e + JOIN srt.expeditionState es on es.description = 'ENTERING' + JOIN srt.moving m ON m.expeditionFk = e.id + SET e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + COMMIT; + + IF srt.buffer_isFull(vBufferToFk) THEN + + CALL srt.buffer_setStateType(vBufferToFk,'FULL', 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_reset` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_reset`() +BEGIN + + DELETE FROM srt.moving; + DELETE FROM srt.expedition; + + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(3223666, NULL, 280.00, 900.00, 280.00, NULL, NULL, 1, '2021-08-25 11:32:16.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634827, NULL, 320.01, 1008.00, 330.00, 10, 54, 5, '2021-07-15 10:28:21.0', '2021-08-27 14:16:32.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634836, NULL, 310.01, 1110.00, 300.00, 2, 3, 5, '2021-07-15 10:31:45.0', '2021-08-27 12:07:46.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634840, NULL, 300.01, 1000.00, 230.00, 13, 2, 5, '2021-07-15 10:32:13.0', '2021-08-27 13:03:48.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634871, NULL, 320.01, 1080.00, 330.00, 2, 4, 5, '2021-07-15 10:36:30.0', '2021-08-27 12:07:46.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634872, NULL, 300.00, 900.00, 250.00, 5, 1, 5, '2021-07-15 10:36:49.0', '2021-08-27 12:29:57.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4637714, NULL, 260.01, 520.00, 210.00, NULL, NULL, 1, '2021-07-16 09:43:46.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4637715, NULL, 260.01, 520.00, 210.00, NULL, NULL, 1, '2021-07-16 09:43:51.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4637716, NULL, 260.01, 520.00, 210.00, 9, 1, 4, '2021-07-16 09:43:55.0', '2021-08-27 12:08:33.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651292, NULL, 250.01, 1010.00, 150.00, NULL, NULL, 1, '2021-07-22 09:00:56.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651293, NULL, 300.01, 980.00, 160.00, 0, 1, 5, '2021-07-22 09:03:44.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651295, NULL, 490.01, 1180.00, 250.00, 0, 1, 5, '2021-07-22 09:07:08.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651298, NULL, 260.01, 1040.00, 240.00, 0, 1, 5, '2021-07-22 09:15:57.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651300, NULL, 490.01, 1180.00, 250.00, 0, 1, 5, '2021-07-22 09:17:06.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651302, NULL, 490.01, 1180.00, 250.00, NULL, NULL, 1, '2021-07-22 09:18:04.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651303, NULL, 370.01, 840.00, 180.00, 0, 1, 5, '2021-07-22 09:19:45.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651304, NULL, 260.01, 1040.00, 260.00, 0, 1, 5, '2021-07-22 09:21:07.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651305, NULL, 260.01, 1040.00, 260.00, 2, 7, 5, '2021-07-22 09:23:26.0', '2021-08-27 12:07:46.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651306, NULL, 260.01, 1040.00, 260.00, NULL, NULL, 6, '2021-07-22 09:23:26.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651307, NULL, 490.01, 1180.00, 250.00, 26, 30, 5, '2021-07-22 09:24:57.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651308, NULL, 330.01, 1000.00, 170.00, 0, 1, 5, '2021-07-22 09:27:08.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651309, NULL, 290.01, 940.00, 230.00, NULL, NULL, 1, '2021-07-22 09:29:12.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651310, NULL, 290.01, 940.00, 230.00, 10, 1, 5, '2021-07-22 09:30:55.0', '2021-08-27 14:16:32.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651311, NULL, 290.01, 940.00, 230.00, 0, 1, 5, '2021-07-22 09:30:55.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651313, NULL, 490.01, 1180.00, 250.00, NULL, NULL, 6, '2021-07-22 09:32:43.0', '2021-08-27 10:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651314, NULL, 300.00, 900.00, 150.00, 13, 3, 5, '2021-07-22 09:34:20.0', '2021-08-27 13:03:48.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651317, NULL, 330.01, 960.00, 300.00, 0, 1, 5, '2021-07-22 09:35:38.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651321, NULL, 490.01, 1180.00, 250.00, 0, 1, 5, '2021-07-22 09:38:58.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651326, NULL, 260.01, 1040.00, 240.00, 0, 1, 5, '2021-07-22 09:41:42.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651327, NULL, 330.01, 960.00, 300.00, 0, 1, 5, '2021-07-22 09:42:51.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651329, NULL, 300.00, 900.00, 150.00, NULL, NULL, 6, '2021-07-22 09:43:54.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651333, NULL, 300.01, 1000.00, 230.00, 16, 1, 5, '2021-07-22 09:45:50.0', '2021-08-27 14:16:34.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651335, NULL, 300.01, 1000.00, 230.00, NULL, NULL, 6, '2021-07-22 09:47:25.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651337, NULL, 330.01, 960.00, 300.00, NULL, NULL, 6, '2021-07-22 09:48:15.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651342, NULL, 490.01, 1180.00, 250.00, NULL, NULL, 6, '2021-07-22 09:50:56.0', '2021-08-27 10:11:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651343, NULL, 490.01, 1180.00, 260.00, 26, 31, 5, '2021-07-22 09:52:18.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651356, NULL, 290.01, 940.00, 230.00, NULL, NULL, 6, '2021-07-22 09:54:35.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651357, NULL, 300.00, 900.00, 150.00, 0, 1, 5, '2021-07-22 09:54:40.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4682051, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:58:17.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4682052, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 08:58:17.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4682262, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:58:17.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691609, NULL, 280.00, 900.00, 280.00, 17, 1, 5, '2021-08-10 09:43:05.0', '2021-08-27 14:16:27.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691611, NULL, 280.00, 600.00, 700.00, NULL, NULL, 1, '2021-08-10 09:53:22.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691612, NULL, 280.00, 500.00, 430.00, 6, 1, 4, '2021-08-10 09:56:31.0', '2021-08-27 14:16:33.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691617, NULL, 280.00, 600.00, 700.00, NULL, NULL, 6, '2021-08-10 09:59:39.0', '2021-08-27 10:36:36.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691618, NULL, 330.00, 590.00, 650.00, 18, 1, 5, '2021-08-10 10:02:48.0', '2021-08-27 12:22:15.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691892, NULL, 280.00, 600.00, 800.00, NULL, NULL, 1, '2021-08-10 11:52:12.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691895, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-10 11:52:56.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691974, NULL, 330.00, 590.00, 1200.00, NULL, NULL, 1, '2021-08-10 12:18:20.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691990, NULL, 330.00, 590.00, 1200.00, NULL, NULL, 1, '2021-08-10 12:23:34.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701752, NULL, 490.00, 1180.00, 260.00, 27, 43, 5, '2021-08-16 07:55:04.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701753, NULL, 490.00, 1180.00, 260.00, 27, 44, 5, '2021-08-16 08:15:21.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701754, NULL, 490.00, 1180.00, 260.00, 27, 42, 5, '2021-08-16 08:18:48.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701755, NULL, 490.00, 1180.00, 260.00, 27, 46, 5, '2021-08-16 08:18:52.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701756, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:26:38.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701757, NULL, 490.00, 1180.00, 260.00, 31, 1, 4, '2021-08-16 08:29:07.0', '2021-08-27 14:16:11.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701758, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:41:56.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701759, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 6, '2021-08-16 08:45:52.0', '2021-08-27 09:28:11.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701760, NULL, 490.00, 1180.00, 260.00, 27, 45, 5, '2021-08-16 08:45:54.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701761, NULL, 490.00, 1180.00, 260.00, 28, 44, 5, '2021-08-16 08:45:54.0', '2021-08-27 14:16:27.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701762, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:55:14.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701763, NULL, 490.00, 1180.00, 260.00, 26, 27, 5, '2021-08-16 08:58:17.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701764, NULL, 490.00, 1180.00, 260.00, 26, 26, 5, '2021-08-16 09:04:36.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701765, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 6, '2021-08-16 09:06:22.0', '2021-08-27 12:44:44.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4704297, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 16:52:11.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4704312, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 16:55:02.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4704345, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 17:00:36.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4708347, NULL, 300.00, 900.00, 150.00, NULL, NULL, 1, '2021-08-18 11:38:42.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710866, NULL, 280.00, 600.00, 900.00, 0, 1, 5, '2021-08-19 07:40:52.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710867, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:44:27.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710868, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:45:47.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710869, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:48:06.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710870, NULL, 280.00, 600.00, 900.00, 0, 1, 5, '2021-08-19 07:50:36.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710871, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:53:33.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710872, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:56:13.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710873, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:58:42.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710874, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:00:10.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710875, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:02:33.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710876, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:05:59.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710877, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:08:27.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724421, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:33:31.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724454, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:37:58.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724463, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:39:45.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724474, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:42:08.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724484, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:43:21.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730464, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 09:57:17.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730467, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:04:06.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730472, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:27:15.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730473, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:27:27.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730474, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:30:13.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730476, NULL, 490.00, 1180.00, 260.00, 23, 1, 5, '2021-08-27 10:35:28.0', '2021-08-27 14:16:09.0'); + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'PRINTED' + SET e.stateFk = es.id, + e.weight = NULL, + e.bufferFk = NULL, + e.`position` = NULL; + + UPDATE srt.buffer b + JOIN srt.bufferState bs on bs.id = b.stateFk + SET stateFk = bs.id + WHERE bs.description = 'FREE'; + + UPDATE srt.config + SET isRandomMoving = FALSE; + + SET @dm := (24 * 60) - 10; + + UPDATE vn.expeditionTruck et + SET et.eta = timestampadd(MINUTE ,@dm := 1 + @dm,util.VN_CURDATE()) + WHERE description LIKE 'PRU%' ; + + DELETE FROM srt.movingLog ; + + DELETE FROM srt.expeditionLog WHERE created < timestampadd(week,-1,util.VN_CURDATE()); + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_routeOut` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_routeOut`(vRouteFk INT, vBufferToFk INT) +BEGIN + + /** + * Selecciona y enruta las expediciones en el sorter hacia un buffer de salida, que sean de la ruta pedida + * + * @param vRouteFk Identificador de vn.route + * @param vBufferToFk Identificador de srt.buffer + * + */ + + DECLARE vExpListFk INT; + + DECLARE vExpBufFk INT; + + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vExpList CURSOR FOR + SELECT bs.expeditionFk + FROM srt.bufferStock bs + JOIN srt.expedition e ON e.id = bs.expeditionFk + WHERE bs.routeFk = vRouteFk + AND bs.expeditionState = 'STORED' + AND bs.isActive + AND bs.hasWorkerWaiting = FALSE + ORDER BY (vBufferToFk - e.bufferFk), + e.`position` ; + + DECLARE vExpBuf CURSOR FOR + SELECT e.id + FROM srt.expedition e + JOIN srt.expedition e2 ON e2.bufferFk = e.bufferFk + JOIN srt.expeditionState es ON es.id = e.stateFk + WHERE e2.id = vExpListFk + AND e.`position` <= e2.`position` + AND es.description = 'STORED' + ORDER BY e.`position`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vExpList; + + FETCH vExpList INTO vExpListFk; + + WHILE NOT vDone DO + + OPEN vExpBuf; + + FETCH vExpBuf INTO vExpBufFk; + + WHILE NOT vDone DO + + IF vExpBufFk = vExpListFk THEN + + CALL srt.expedition_relocate(vExpListFk, vBufferToFk); + + SET vDone = TRUE; + + ELSE + + CALL srt.expedition_relocate(vExpBufFk, NULL); + + SET vDone = FALSE; + + FETCH vExpBuf INTO vExpBufFk; + + END IF; + + END WHILE; + + CLOSE vExpBuf; + + SET vDone = FALSE; + + FETCH vExpList INTO vExpListFk; + + END WHILE; + + CLOSE vExpList; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_scan` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_scan`(vSelf INT) +BEGIN + + /* Actualiza el estado de una expedicion a OUT, al ser escaneada manualmente + * + * @param vSelf Identificador de srt.expedition + * + */ + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'OUT' + SET e.stateFk = es.id, + e.`position` = NULL, + e.bufferFk = NULL + WHERE e.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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_setDimensions` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_setDimensions`( + vExpeditionFk INT, + vWeight DECIMAL(10,2), + vLength INT, + vWidth INT, + vHeight INT, + OUT vExpeditionOutFk INT) +BEGIN +/** + * Actualiza las dimensiones, peso y estado de una expedición + * + * @param vExpeditionFk Identificador de expedition + * @param vWeight Peso en kilos + * @param vLength Byte con el número de fotocélulas activadas a lo largo + * @param vWidth Byte con el número de fotocélulas activadas a lo ancho + * @param vHeight Altura de la caja en cm + * @return vExpeditionOutFk Identificador de expedition + */ + + DECLARE vWidthSensorsUsed INT; + DECLARE vLengthSensorsUsed INT; + + SET vExpeditionOutFk = expedition_check(vExpeditionFk); + + #primer bit a 1 a la izquierda - primer bit a 1 a la derecha + SET vWidthSensorsUsed = length(BIN(vWidth)) - LOG2(vWidth & -vWidth); + SET vLengthSensorsUsed = length(BIN(vLength)) - LOG2(vLength & -vLength); + + UPDATE expedition e + JOIN expeditionState es ON es.`description` = 'WEIGHED' + JOIN config c + SET weight = IFNULL(vWeight, 0), + stateFk = es.id, + width = IFNULL(c.widthToFirstSensor + (c.widthSensorSpacing * vWidthSensorsUsed), 0), + `length` = IFNULL(c.lengthToFirstSensor + (c.lengthSensorSpacing * vLengthSensorsUsed), 0), + height = IFNULL(vHeight * 10, 0) + WHERE e.id = vExpeditionOutFk; + + SET vExpeditionOutFk = vExpeditionFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_weighing` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_weighing`(vWeight DECIMAL(10,2), vExpeditionFk INT, OUT vExpeditionOutFk INT ) +BEGIN + + /** + * Actualiza el peso de una expedición + * + * @param vWeight Peso en kilos + * @param vExpeditionFk Identificador de srt.expedition + * + * @return vExpeditionOutFk Identificador de srt.expedition + */ + + SET vExpeditionOutFk = srt.expedition_check(vExpeditionFk); + + UPDATE srt.expedition e + JOIN srt.expeditionState es on es.description = 'WEIGHED' + SET weight = vWeight, + stateFk = es.id + WHERE e.id = vExpeditionOutFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `failureLog_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `failureLog_add`(vDescription VARCHAR(100)) +BEGIN + + /* Añade un registro a srt.failureLog + * + * @param vDescription descripción del fallo + */ + + INSERT INTO srt.failureLog(description) VALUES(vDescription); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `lastRFID_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `lastRFID_add`(vCode VARCHAR(20), vAntennaFk INT, vAntennaPortFk INT, vPeakRssi INT, vSeenCount INT) +BEGIN + + /* Insert a new record in lastRFID table + * + * @param vCode Char string read by the antenna + * @param vAntennaFk Identifier for srt.antenna table + */ + + INSERT INTO srt.lastRFID(code, antennaFk, antennaPort, peakRssi, seenCount) + VALUES(vCode, vAntennaFk, vAntennaPortFk , vPeakRssi , vSeenCount ); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `lastRFID_add_beta` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `lastRFID_add_beta`(vCode VARCHAR(20), vAntennaFk INT, vAntennaPortFk INT, vPeakRssi INT, vSeenCount INT) +BEGIN + + /* Insert a new record in lastRFID table + * + * @param vCode Char string read by the antenna + * @param vAntennaFk Identifier for srt.antenna table + */ + + INSERT INTO srt.lastRFID(code, antennaFk, antennaPort, peakRssi, seenCount) + VALUES(vCode, vAntennaFk, vAntennaPortFk , vPeakRssi , vSeenCount ); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `moving_between` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `moving_between`(vBufferA INT, vBufferB INT) +BEGIN + + DECLARE vExpeditionFk INT; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e.bufferFk = vBufferA + AND ISNULL(m.id) + ORDER BY e.`position` + LIMIT 1; + + IF ISNULL(vExpeditionFk) THEN + + SET vExpeditionFk = srt.expedition_check(0); + + UPDATE srt.expedition + SET bufferFk = vBufferA, `position` = 1 + WHERE id = vExpeditionFk; + + END IF; + + CALL `srt`.`expedition_Relocate`(vExpeditionFk, IFNULL(vBufferB,srt.buffer_get(vExpeditionFk))); + + SELECT * FROM srt.moving m ORDER BY 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `moving_clean` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `moving_clean`() +BEGIN +/** + * Elimina movimientos por inactividad + * + */ + DECLARE vExpeditionFk INT; + DECLARE vBufferToFk INT; + DECLARE vBufferFromFk INT; + DECLARE done BOOL DEFAULT FALSE; + + DECLARE cur CURSOR FOR + SELECT m.expeditionFk, m.bufferToFk, m.bufferFromFk + FROM srt.moving m + JOIN srt.config c + JOIN (SELECT bufferFk, SUM(isActive) hasBox + FROM srt.photocell + GROUP BY bufferFk) sub ON sub.bufferFk = m.bufferFromFk + WHERE m.created < TIMESTAMPADD(MINUTE, - c.movingMaxLife , util.VN_NOW()) + AND NOT sub.hasBox; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + OPEN cur; + + bucle: LOOP + + FETCH cur INTO vExpeditionFk, vBufferToFk, vBufferFromFk; + + IF done THEN + LEAVE bucle; + END IF; + + DELETE FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'OUT' + SET + bufferFk = NULL, + `position` = NULL, + stateFk = es.id + WHERE e.id = vExpeditionFk; + + UPDATE srt.expedition e + SET e.`position` = e.`position` - 1 + WHERE e.bufferFk = vBufferFromFk + AND e.`position` > 0; + + CALL vn.mail_insert( + 'pako@verdnatura.es, carles@verdnatura.es', + NULL, + CONCAT('Moving_clean. Expedition: ', vExpeditionFk, ' estaba parada'), + CONCAT('Expedition: ', vExpeditionFk,' vBufferToFk: ', vBufferToFk) + ); + + END LOOP bucle; + + CLOSE cur; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `moving_CollidingSet` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `moving_CollidingSet`() +BEGIN + + + UPDATE srt.moving + SET isColliding = FALSE; + + UPDATE srt.moving m1 + JOIN srt.buffer sf1 ON sf1.id = m1.bufferFromFk + JOIN srt.buffer st1 ON st1.id = m1.bufferToFk + JOIN srt.movingState ms1 ON ms1.id = m1.stateFk + JOIN srt.moving m2 + JOIN srt.buffer sf2 ON sf2.id = m2.bufferFromFk + JOIN srt.buffer st2 ON st2.id = m2.bufferToFk + JOIN srt.movingState ms2 ON ms2.id = m2.stateFk + SET m1.isColliding = TRUE + WHERE NOT ms1.isInterfering + AND ms2.isInterfering + AND (sf1.stratus = st2.stratus + OR + st1.stratus = sf2.stratus ) + ; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `moving_delete` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `moving_delete`(vExpeditionFk INT) +BEGIN + + /* Elimina un movimiento + * + * @param vExpeditionFk Identificador de srt.expedition + * + */ + + INSERT INTO srt.movingLog(expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, movingFk, `action`) + SELECT expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, id, 'DELETE' + FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + + DELETE FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `moving_groupOut` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `moving_groupOut`() +proc: BEGIN + + DECLARE vDayMinute INT; + DECLARE vRouteFk INT; + DECLARE vBufferToFk INT; + DECLARE vBufferFromFk INT; + DECLARE vBufferGroupFk INT; + DECLARE vDone INT DEFAULT FALSE; + DECLARE cur1 CURSOR FOR + SELECT DISTINCT b.id + FROM srt.buffer b + JOIN srt.bufferState bs ON bs.id = b.stateFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.bufferGroup bg ON bg.bufferFk = b.id + LEFT JOIN srt.moving m ON m.bufferToFk = b.id + WHERE bs.description = 'FREE' + AND b.isActive + AND bt.typeName = 'STRAPPING'; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + IF (SELECT (isAuto OR isRandomMoving) FROM srt.config) THEN + + LEAVE proc; + + END IF; + + CASE (SELECT groupingMode FROM srt.config) + + WHEN 'TRUCK' THEN + + SELECT min(ev.dayMinute) INTO vDayMinute + FROM srt.expeditionVolume ev + WHERE ev.isReady + AND ev.dayMinute + AND ev.bufferTruck; + + IF vDayMinute THEN + + SELECT min(ev.bufferTruck) INTO vBufferToFk + FROM srt.expeditionVolume ev + WHERE ev.dayMinute = vDayMinute; + + UPDATE srt.buffer + SET dayMinute = vDayMinute + WHERE id = vBufferToFk; + + CALL srt.expedition_groupOut(vDayMinute,vBufferToFk); + + END IF; + + WHEN 'ROUTE' THEN + + SELECT min(rv.dayMinute) INTO vDayMinute + FROM srt.routeVolume rv + LEFT JOIN srt.buffer b ON b.routeFk = rv.routeFk + WHERE rv.isReady + AND rv.dayMinute + AND rv.bufferTruck + AND ISNULL(b.id); + + IF vDayMinute THEN + + SELECT min(ev.bufferTruck) INTO vBufferToFk + FROM srt.expeditionVolume ev + WHERE ev.dayMinute = vDayMinute; + + SELECT rv.routeFk INTO vRouteFk + FROM srt.routeVolume rv + WHERE rv.dayMinute = vDayMinute + AND rv.isReady + ORDER BY dayMinute, cajas DESC + LIMIT 1; + + UPDATE srt.buffer + SET routeFk = vRouteFk + WHERE id = vBufferToFk; + + CALL srt.expedition_routeOut(vRouteFk,vBufferToFk); + + END IF; + + WHEN 'BUFFER' THEN + + SELECT rv.dayMinute, rv.routeBuffer + INTO vDayMinute, vBufferToFk + FROM srt.routeVolume rv + WHERE rv.isReady + AND rv.dayMinute + AND rv.routeBuffer + ORDER BY rv.dayMinute + LIMIT 1; + + IF vDayMinute THEN + + CALL srt.expedition_bufferOut(vBufferToFk); + + END IF; + + WHEN 'BUFFERGROUP' THEN + + -- En el caso de que haya cajas en buffers auxiliares y los principales esten libres, reenvia cajas + + OPEN cur1; + + read_loop: LOOP + + FETCH cur1 INTO vBufferToFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + SELECT bg.`group` INTO vBufferGroupFk + FROM srt.bufferGroup bg + WHERE bg.bufferFk = vBufferToFk; + + SELECT MAX(e.bufferFk) INTO vBufferFromFk + FROM srt.expedition e + JOIN srt.expeditionState es ON es.id = e.stateFk + JOIN srt.bufferGroup bg ON bg.bufferFk = e.bufferFk + LEFT JOIN srt.moving m ON m.bufferToFk = e.bufferFk + LEFT JOIN srt.moving mo ON mo.bufferFromFk = e.bufferFk + JOIN srt.buffer b on b.id = e.bufferFk + JOIN srt.bufferType bt on bt.id = b.typeFk + WHERE bg.`group` = vBufferGroupFk + AND ISNULL(m.bufferToFk) + AND ISNULL(mo.id) + AND bt.typeName = 'ACCUMULATION'; + IF vBufferFromFk THEN + + CALL srt.buffer_giveBack(vBufferFromFk); + + END IF; + + END LOOP; + + CLOSE cur1; + + END CASE; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `moving_next` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `moving_next`() +BEGIN + + DECLARE vExpeditionFk INT; + DECLARE vMovingFk INT; + DECLARE vSecondsFromLastRFIDReading INT; + + CALL srt.randomMoving_Launch(); + + CALL srt.moving_GroupOut(); + + CALL srt.moving_CollidingSet(); + + SELECT TIME_TO_SEC((TIMEDIFF(util.VN_NOW(),MAX(lr.created)))) + INTO vSecondsFromLastRFIDReading + FROM srt.lastRFID lr; + + + SELECT m.id INTO vMovingFk + FROM srt.moving m + JOIN srt.expedition e ON e.id = m.expeditionFk + JOIN srt.movingState ms ON ms.id = m.stateFk + JOIN srt.buffer b ON b.id = m.bufferToFk + JOIN srt.buffer b2 ON b2.id = m.bufferFromFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.bufferState bs ON bs.id = b.stateFk + JOIN srt.config c + WHERE NOT ms.isInterfering + AND NOT m.isColliding + AND (c.isEnteringBlocked = FALSE OR m.bufferFromFk > 0) + AND (e.`position` = 1 OR m.bufferFromFk = 0) + AND (vSecondsFromLastRFIDReading > c.enteringSecondsReserve OR m.bufferFromFk = 0) + AND (bs.description != 'FULL' OR m.bufferFromFk = 0) + ORDER BY (m.bufferFromFk = 0) DESC, + m.bufferFromFk DESC + LIMIT 1; + + SELECT m.expeditionFk + INTO vExpeditionFk + FROM moving m + WHERE m.id = vMovingFk; + + IF vExpeditionFk THEN + + SELECT m.expeditionFk, + m.bufferFromFk, + m.bufferToFk + FROM moving m + WHERE m.id = vMovingFk; + + UPDATE expedition e + JOIN expeditionState es ON es.description = 'MOVING' + SET e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + UPDATE srt.moving m + JOIN srt.movingState ms ON ms.description = 'MOVING' + SET m.stateFk = ms.id + WHERE m.id = vMovingFk; + + INSERT INTO srt.movingLog(expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, movingFk, `action`) + SELECT expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, id, 'NEXT' + FROM srt.moving + WHERE id = vMovingFk; + + ELSE + + SELECT 0 expeditionFk, 0 bufferFromFk, 0 bufferToFk; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `photocell_setActive` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `photocell_setActive`(vBufferFk int, vPosition int, vIsActive bool) +BEGIN + REPLACE srt.photocell VALUES (vbufferFk, vPosition, vIsActive); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `randomMoving` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `randomMoving`(vBufferMin INT, vBufferMax INT) +BEGIN + DECLARE vBufferOld INT DEFAULT 0; + DECLARE vBufferFk INT; + DECLARE vExpeditionFk INT; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + JOIN srt.buffer b ON b.id = e.bufferFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE e.bufferFk BETWEEN vBufferMin AND vBufferMax + AND m.id IS NULL + AND bt.typeName = 'ACCUMULATION' + AND b.isActive + ORDER BY e.`position`, e.updated + LIMIT 1; + + SELECT IFNULL(e.bufferFk,0) INTO vBufferOld + FROM srt.expedition e + WHERE e.id = vExpeditionFk; + + SELECT b.id INTO vBufferFk + FROM srt.buffer b + JOIN srt.bufferFreeLength bfl ON bfl.bufferFk = b.id + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.config c + LEFT JOIN srt.moving m ON m.bufferToFk = b.id + LEFT JOIN srt.moving m2 ON m2.bufferFromFk = b.id + WHERE ISNULL(m.bufferToFk) + AND ISNULL(m2.bufferFromFk) + AND b.id BETWEEN vBufferMin AND vBufferMax + AND b.id != vBufferOld + AND b.isActive + AND bt.typeName = 'ACCUMULATION' + AND bfl.freeLength > c.freeLength * 2 + ORDER BY (b.id = floor(MINUTE(util.VN_NOW())/2)) DESC + LIMIT 1; + + IF vBufferFk THEN + + INSERT INTO srt.moving (expeditionFk, bufferFromFk, bufferToFk) + SELECT e.id, e.bufferFk, vBufferFk + FROM srt.expedition e + WHERE e.id = vExpeditionFk; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `randomMoving_Launch` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `randomMoving_Launch`() +BEGIN + + DECLARE i INT DEFAULT 5; + + IF (SELECT count(*) FROM srt.moving) < 5 AND (SELECT isRandomMoving FROM srt.config) THEN + + WHILE i DO + + SET i = i - 1; + + -- CALL srt.randomMoving(22,35); + CALL srt.randomMoving(2,5); + + END WHILE; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `restart` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `restart`() +BEGIN + + /* + * Se ha pulsado el botón RESTART en la pantalla tàctil del sorter + */ + + DELETE FROM srt.moving + WHERE bufferFromFk = 0; + + INSERT INTO srt.sorterLog(`action`) VALUES('RESTART'); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `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_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `start`() +BEGIN + + /* + * Se ha pulsado el botón START en la pantalla tàctil del sorter + */ + + INSERT INTO srt.sorterLog(`action`) VALUES('START'); + + UPDATE srt.config SET isEnteringBlocked = FALSE ; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `stop` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `stop`() +BEGIN + + /* + * Se ha pulsado el botón STOP en la pantalla tàctil del sorter + */ + + INSERT INTO srt.sorterLog(`action`) VALUES('STOP'); + + UPDATE srt.config SET isEnteringBlocked = TRUE; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `test` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `test`() +BEGIN + + SELECT 'procedimiento ejecutado con éxito'; + +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 */ ; + -- -- Current Database: `stock` -- @@ -18297,67 +23127,6 @@ CREATE TABLE `inbound` ( KEY `isSync` (`isSync`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`inbound_beforeInsert` - BEFORE INSERT ON `inbound` - FOR EACH ROW -BEGIN - SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); - - CALL visible_log( - NEW.isPicked, - NEW.warehouseFk, - NEW.itemFk, - NEW.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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`inbound_afterDelete` - AFTER DELETE ON `inbound` - FOR EACH ROW -BEGIN - UPDATE outbound o - JOIN inboundPick ou ON ou.outboundFk = o.id - SET o.lack = o.lack + ou.quantity, - o.isSync = FALSE - WHERE ou.inboundFk = OLD.id; - - DELETE FROM inboundPick - WHERE inboundFk = OLD.id; - - CALL visible_log( - OLD.isPicked, - OLD.warehouseFk, - OLD.itemFk, - -OLD.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 */ ; -- -- Table structure for table `inboundPick` @@ -18420,68 +23189,6 @@ CREATE TABLE `outbound` ( KEY `isSync` (`isSync`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`outbound_beforeInsert` - BEFORE INSERT ON `outbound` - FOR EACH ROW -BEGIN - SET NEW.lack = NEW.quantity; - SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); - - CALL visible_log( - NEW.isPicked, - NEW.warehouseFk, - NEW.itemFk, - -NEW.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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`outbound_afterDelete` - AFTER DELETE ON `outbound` - FOR EACH ROW -BEGIN - UPDATE inbound i - JOIN inboundPick ou ON ou.inboundFk = i.id - SET i.available = i.available + ou.quantity, - i.isSync = FALSE - WHERE ou.outboundFk = OLD.id; - - DELETE FROM inboundPick - WHERE outboundFk = OLD.id; - - CALL visible_log( - OLD.isPicked, - OLD.warehouseFk, - OLD.itemFk, - OLD.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 */ ; -- -- Table structure for table `visible` @@ -18514,7 +23221,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `log_clean` ON SCHEDULE EVERY 1 DAY STARTS '2022-01-28 09:29:18' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL log_clean */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `log_clean` ON SCHEDULE EVERY 1 DAY STARTS '2022-01-28 09:29:18' ON COMPLETION PRESERVE ENABLE DO CALL log_clean */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -18646,7 +23353,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SET vSupplied = 0; OPEN vPicks; @@ -18662,7 +23369,7 @@ BEGIN SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity); SET vSupplied = vSupplied + vPickGranted; CALL inbound_removePick(vSelf, vOutboundFk, vPickGranted, vPickQuantity); - + UPDATE outbound SET isSync = FALSE, lack = lack + vPickGranted @@ -18742,7 +23449,7 @@ BEGIN END IF; SET vSupplied = LEAST(vAvailable, vLack); - + IF vSupplied > 0 THEN SET vAvailable = vAvailable - vSupplied; UPDATE outbound @@ -18755,7 +23462,7 @@ BEGIN SET vSupplied = vSupplied + vSuppliedFromRequest; SET vAvailable = vAvailable - vSuppliedFromRequest; END IF; - + IF vSupplied > 0 THEN CALL inbound_addPick(vSelf, vOutboundFk, vSupplied); END IF; @@ -18884,7 +23591,7 @@ 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; @@ -19355,7 +24062,7 @@ BEGIN SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity); SET vSupplied = vSupplied + vPickGranted; CALL inbound_removePick(vInboundFk, vSelf, vPickGranted, vPickQuantity); - + UPDATE inbound SET isSync = FALSE, available = available + vPickGranted @@ -19498,6 +24205,84 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `tmp` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `tmp` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `tmp`; + +-- +-- Dumping events for database 'tmp' +-- +/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; +/*!50106 DROP EVENT IF EXISTS `clean` */; +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 = utf8mb3 */ ;; +/*!50003 SET character_set_results = utf8mb3 */ ;; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `clean` ON SCHEDULE EVERY 1 HOUR STARTS '2022-03-01 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL tmp.clean */ ;; +/*!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 */ ; + +-- +-- Dumping routines for database 'tmp' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() +BEGIN + DECLARE vTableName VARCHAR(255); + DECLARE vDone BOOL; + + DECLARE cur CURSOR FOR + SELECT TABLE_NAME + FROM information_schema.TABLES + WHERE TABLE_SCHEMA = 'tmp' + AND CREATE_TIME < TIMESTAMPADD(DAY, 1, util.VN_NOW()); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vTableName; + + IF vDone THEN + LEAVE l; + END IF; + + CALL util.exec(CONCAT('DROP TABLE `tmp`.`', vTableName, '`')); + END LOOP; + CLOSE cur; +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 */ ; + -- -- Current Database: `util` -- @@ -19538,7 +24323,7 @@ CREATE TABLE `config` ( `mockTime` datetime DEFAULT NULL, `mockEnabled` tinyint(3) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration table'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration table'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19558,7 +24343,7 @@ CREATE TABLE `debug` ( `value` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `created` (`created`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Log de depuración'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Log de depuración'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19575,7 +24360,7 @@ CREATE TABLE `eventLog` ( `error` varchar(1024) NOT NULL, PRIMARY KEY (`id`), KEY `date` (`date`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Event scheduler error log'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Event scheduler error log'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19637,7 +24422,7 @@ CREATE TABLE `notificationConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `cleanDays` mediumint(9) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19660,7 +24445,7 @@ CREATE TABLE `notificationQueue` ( KEY `status` (`status`), CONSTRAINT `nnotificationQueue_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`name`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `notificationQueue_ibfk_2` FOREIGN KEY (`authorFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19680,7 +24465,7 @@ CREATE TABLE `notificationSubscription` ( KEY `notificationSubscription_ibfk_1` (`notificationFk`), CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19711,7 +24496,7 @@ CREATE TABLE `versionConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `realm` varchar(16) DEFAULT NULL COMMENT 'Data set on which the project runs', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19749,7 +24534,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `slowLog_prune` ON SCHEDULE EVERY 1 DAY STARTS '2021-10-08 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL util.slowLog_prune */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `slowLog_prune` ON SCHEDULE EVERY 1 DAY STARTS '2021-10-08 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL util.slowLog_prune */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -19809,11 +24594,11 @@ BEGIN WHILE vI < vLen DO SET vSpaceIni = vI; - + WHILE MID(vString, vI, 1) REGEXP '[[:space:]]' DO SET vI = vI + 1; END WHILE; - + SET vWordIni = vI; SET vI = vWordIni + 1; @@ -19850,11 +24635,11 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `crypt`(vText VARCHAR(255), vKey VARC BEGIN DECLARE vResult VARCHAR(255); - + CALL vn.crypt(vText, vKey, vResult); RETURN vResult; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -19876,11 +24661,11 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `cryptOff`(vText VARCHAR(255), vKey V BEGIN DECLARE vResult VARCHAR(255); - + CALL vn.cryptOff(vText, vKey, vResult); RETURN vResult; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -20048,7 +24833,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasDateOverlapped`(vSarted1 DATE, vEnded1 DATE, vSarted2 DATE, vEnded2 DATE) RETURNS tinyint(1) DETERMINISTIC -BEGIN +BEGIN RETURN GREATEST(vSarted1, vSarted2) <= LEAST(vEnded1,vEnded2); @@ -20077,7 +24862,7 @@ BEGIN */ DECLARE vHashlen INT UNSIGNED; DECLARE vOpad, vIpad TINYBLOB; - + CASE vAlg WHEN 224 THEN SET vHashlen = 64; WHEN 256 THEN SET vHashlen = 64; @@ -20085,16 +24870,16 @@ BEGIN WHEN 512 THEN SET vHashlen = 128; ELSE CALL throw ('WRONG_ALGORYTHM_IDENTIFICATOR_USED'); END CASE; - + IF LENGTH(vKey) > vHashlen THEN SET vKey = UNHEX(SHA2(vKey, vAlg)); END IF; - + SET vKey = RPAD(vKey, vHashlen, 0x00); - + SET vIpad = stringXor(vKey, 0x36); SET vOpad = stringXor(vKey, 0x5C); - + RETURN SHA2(CONCAT(vOpad, UNHEX(SHA2(CONCAT(vIpad, vMsg), vAlg))), vAlg); END ;; DELIMITER ; @@ -20117,7 +24902,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `isLeapYear`(vYear INT) RETURNS tinyi BEGIN RETURN (DAYOFYEAR(CONCAT(vYear, "-02-29")) IS NOT NULL); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -20276,7 +25061,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `midnight`() RETURNS datetime READS SQL DATA BEGIN - + RETURN TIMESTAMP(util.VN_CURDATE(), '23:59:59'); END ;; @@ -20404,7 +25189,7 @@ BEGIN * modo 3. */ DECLARE vYear INT DEFAULT FLOOR(vYearWeek / 100); - + IF vYearWeek < YEARWEEK(CONCAT(vYear, '-12-31'), 3) THEN RETURN vYearWeek + 1; ELSE @@ -20510,16 +25295,16 @@ BEGIN */ DECLARE vLen, vPos INT UNSIGNED; DECLARE vResult MEDIUMBLOB; - + SET vLen = LENGTH(vString); SET vPos = 1; SET vResult = ''; - + WHILE vPos <= vLen DO SET vResult = CONCAT(vResult, LPAD(HEX( ORD(SUBSTR(vString, vPos, 1)) ^ vConst), 2, '0')); SET vPos = vPos + 1; END WHILE; - + RETURN UNHEX(vResult); END ;; DELIMITER ; @@ -20790,11 +25575,11 @@ BEGIN IF vYear = vCurYear THEN RETURN 'curYear'; END IF; - + IF vYear = vCurYear - 1 THEN RETURN 'lastYear'; END IF; - + IF vYear = vCurYear - 2 THEN RETURN 'twoYearsAgo'; END IF; @@ -20877,7 +25662,7 @@ BEGIN * @param vValue Valor de la variable */ DECLARE vIndex INT DEFAULT INSTR(USER(), '@'); - + INSERT INTO debug SET `connectionId` = CONNECTION_ID(), `user` = LEFT(USER(), vIndex - 1), @@ -21261,7 +26046,7 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `time_createTable` */; +/*!50003 DROP PROCEDURE IF EXISTS `time_generate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -21269,18 +26054,41 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `time_createTable`(vStarted DATE, vEnded DATE) +CREATE DEFINER=`root`@`localhost` PROCEDURE `time_generate`(vStarted DATE, vEnded DATE) BEGIN +/** + * Generate a temporary table between the days passed as parameters + * + * @param vStarted Start date + * @param vEnded End date + * @table tmp.time (dated, dayed, weeked, monthed, yeared) + */ DECLARE vCurrentDate DATE; - DROP TEMPORARY TABLE IF EXISTS tmp.time; - CREATE TEMPORARY TABLE tmp.time (dated DATE PRIMARY KEY) ENGINE = MEMORY; - SET vCurrentDate = vStarted; - WHILE vCurrentDate <= vEnded DO - INSERT INTO tmp.time (dated) VALUES (vCurrentDate); - SET vCurrentDate = DATE_ADD(vCurrentDate, INTERVAL 1 DAY); - END WHILE; + CREATE OR REPLACE TEMPORARY TABLE tmp.time( + dated DATE PRIMARY KEY, + `day` INT, + `week` INT, + `month` INT, + `year` INT + ) ENGINE = MEMORY; + IF(vStarted > vEnded) THEN + CALL throw('The started cannot be later than the ended'); + END IF; + + SET vCurrentDate = vStarted; + + WHILE vCurrentDate <= vEnded DO + INSERT INTO tmp.time + SET dated = vCurrentDate, + `day` = DAY(vCurrentDate), + `week` = WEEK(vCurrentDate), + `month` = MONTH(vCurrentDate), + `year` = YEAR(vCurrentDate); + + SET vCurrentDate = vCurrentDate + INTERVAL 1 DAY; + END WHILE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -21397,94 +26205,8 @@ CREATE TABLE `XDiario` ( KEY `XDiario` (`enlazado`), KEY `enlazadoSage` (`enlazadoSage`), CONSTRAINT `XDiarioCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`XDiario_beforeInsert` - BEFORE INSERT ON `XDiario` - FOR EACH ROW -BEGIN - IF NEW.SUBCTA <=> '' THEN - SET NEW.SUBCTA = NULL; - END IF; - IF NEW.SUBCTA IS NOT NULL AND NOT LENGTH(NEW.SUBCTA) <=> 10 THEN - CALL util.throw('INVALID_STRING_LENGTH'); - END IF; - IF NEW.CONTRA <=> '' THEN - SET NEW.CONTRA = NULL; - END IF; - IF NEW.CONTRA IS NOT NULL AND NOT LENGTH(NEW.CONTRA) <=> 10 THEN - CALL util.throw('INVALID_STRING_LENGTH'); - END IF; - CALL XDiario_checkDate(NEW.FECHA); - CALL XDiario_checkDate(NEW.FECHA_EX); - CALL XDiario_checkDate(NEW.FECHA_OP); - CALL XDiario_checkDate(NEW.FECHA_RT); - CALL XDiario_checkDate(NEW.FECREGCON); -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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`XDiario_beforeUpdate` - BEFORE UPDATE ON `XDiario` - FOR EACH ROW -BEGIN - IF NOT NEW.SUBCTA <=> OLD.SUBCTA THEN - IF NEW.SUBCTA <=> '' THEN - SET NEW.SUBCTA = NULL; - END IF; - IF NEW.SUBCTA IS NOT NULL AND NOT LENGTH(NEW.SUBCTA) <=> 10 THEN - CALL util.throw('INVALID_STRING_LENGTH'); - END IF; - END IF; - IF NOT NEW.CONTRA <=> OLD.CONTRA THEN - IF NEW.CONTRA <=> '' THEN - SET NEW.CONTRA = NULL; - END IF; - IF NEW.CONTRA IS NOT NULL AND NOT LENGTH(NEW.CONTRA) <=> 10 THEN - CALL util.throw('INVALID_STRING_LENGTH'); - END IF; - END IF; - IF NOT NEW.FECHA <=> OLD.FECHA THEN - CALL XDiario_checkDate(NEW.FECHA); - END IF; - IF NOT NEW.FECHA_EX <=> OLD.FECHA_EX THEN - CALL XDiario_checkDate(NEW.FECHA_EX); - END IF; - IF NOT NEW.FECHA_OP <=> OLD.FECHA_OP THEN - CALL XDiario_checkDate(NEW.FECHA_OP); - END IF; - IF NOT NEW.FECHA_RT <=> OLD.FECHA_RT THEN - CALL XDiario_checkDate(NEW.FECHA_RT); - END IF; - IF NOT NEW.FECREGCON <=> OLD.FECREGCON THEN - CALL XDiario_checkDate(NEW.FECREGCON); - 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 */ ; -- -- Temporary table structure for view `__coolerPathDetail` @@ -21521,7 +26243,7 @@ CREATE TABLE `absenceType` ( `isNaturalDay` tinyint(1) DEFAULT 0 COMMENT 'Para el cálculo de los salarios de los repartidores', `isCalculate` tinyint(1) DEFAULT 0 COMMENT 'Para el cálculo de los salarios de los repartidores', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21563,7 +26285,7 @@ CREATE TABLE `accountingConfig` ( `minDate` date NOT NULL, `maxDate` date NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21646,146 +26368,8 @@ CREATE TABLE `address` ( CONSTRAINT `address_ibfk_3` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`) ON UPDATE CASCADE, CONSTRAINT `address_ibfk_4` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `address_incotermsFk` FOREIGN KEY (`incotermsFk`) REFERENCES `incoterms` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_beforeInsert` - BEFORE INSERT ON `address` - FOR EACH ROW -BEGIN - DECLARE vIsEqualizated BOOL; - - SET NEW.editorFk = account.myUser_getId(); - - IF (NEW.phone <> '') THEN - CALL pbx.phone_isValid(NEW.phone); - END IF; - - IF (NEW.mobile <> '') THEN - CALL pbx.phone_isValid(NEW.mobile); - END IF; - - IF NEW.isEqualizated IS NULL THEN - SELECT isEqualizated - INTO vIsEqualizated - FROM client - WHERE id = NEW.clientFk; - - SET NEW.isEqualizated = vIsEqualizated; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_beforeUpdate` - BEFORE UPDATE ON `address` - FOR EACH ROW -BEGIN - - SET NEW.editorFk = account.myUser_getId(); - - IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN - CALL pbx.phone_isValid(NEW.phone); - END IF; - - IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN - CALL pbx.phone_isValid(NEW.mobile); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_afterUpdate` - AFTER UPDATE ON `address` - FOR EACH ROW -BEGIN - -- Recargos de equivalencia distintos implican facturacion por consignatario - IF NEW.isEqualizated != OLD.isEqualizated THEN - IF - (SELECT COUNT(*) FROM - ( - SELECT DISTINCT (isEqualizated = FALSE) as Equ - FROM address - WHERE clientFk = NEW.clientFk - ) t1 - ) > 1 - THEN - UPDATE client - SET hasToInvoiceByAddress = TRUE - WHERE id = NEW.clientFk; - END IF; - END IF; - IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN - CALL util.throw ('Cannot desactivate the default address'); - END IF; - - IF NOT (NEW.isEqualizated <=> OLD.isEqualizated) THEN - INSERT IGNORE INTO ticketRecalc (ticketFk) - SELECT id FROM ticket t - WHERE t.addressFk = NEW.id - AND t.refFk 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_afterDelete` - AFTER DELETE ON `address` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'Address', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `addressFilter` @@ -21812,7 +26396,7 @@ CREATE TABLE `addressFilter` ( CONSTRAINT `addressFilter_FK` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `addressFilter_FK_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `addressFilter_FK_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Establece los criterios para habilitar las compras directas a Logiflora'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Establece los criterios para habilitar las compras directas a Logiflora'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21847,7 +26431,7 @@ CREATE TABLE `addressObservation` ( KEY `addressObservationFgn_idx` (`observationTypeFk`), CONSTRAINT `addressFgn` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `addressObservationFgn` FOREIGN KEY (`observationTypeFk`) REFERENCES `observationType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Observaciones de los consignatarios'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21886,28 +26470,8 @@ CREATE TABLE `agency` ( CONSTRAINT `agency_FK` FOREIGN KEY (`warehouseAliasFk`) REFERENCES `warehouseAlias` (`id`) ON UPDATE CASCADE, CONSTRAINT `agency_ibfk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `agency_ibfk_3` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`agency_afterInsert` - AFTER INSERT ON `agency` - FOR EACH ROW -BEGIN - INSERT INTO agencyMode(name,agencyFk) VALUES(NEW.name,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 */ ; -- -- Table structure for table `agencyExtraCharge` @@ -21961,7 +26525,7 @@ CREATE TABLE `agencyMode` ( KEY `agencyMode_code` (`code`), CONSTRAINT `agencyMode_agencyFk` FOREIGN KEY (`agencyFk`) REFERENCES `agency` (`id`) ON UPDATE CASCADE, CONSTRAINT `agencyMode_deliveryMethodFk` FOREIGN KEY (`deliveryMethodFk`) REFERENCES `deliveryMethod` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21980,7 +26544,22 @@ CREATE TABLE `agencyModeItemType` ( KEY `agencyModeItemType_FK_1` (`itemTypeFk`), CONSTRAINT `agencyModeItemType_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agencyModeItemType_FK_1` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Combinaciones prohibidas entre agencyMode e itemType al calcular el catálogo de items'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Combinaciones prohibidas entre agencyMode e itemType al calcular el catálogo de items'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `agencyModePricePercentage` +-- + +DROP TABLE IF EXISTS `agencyModePricePercentage`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `agencyModePricePercentage` ( + `agencyModeFk` int(11) NOT NULL, + `percentage` double NOT NULL, + PRIMARY KEY (`agencyModeFk`), + CONSTRAINT `agencyModePricePercentage_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22017,6 +26596,20 @@ CREATE TABLE `agencyTermConfig` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `agencyWarehouse` +-- + +DROP TABLE IF EXISTS `agencyWarehouse`; +/*!50001 DROP VIEW IF EXISTS `agencyWarehouse`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `agencyWarehouse` AS SELECT + 1 AS `agencyFk`, + 1 AS `warehouseFk`, + 1 AS `agencyType` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `alertLevel` -- @@ -22077,7 +26670,7 @@ CREATE TABLE `arcRead` ( UNIQUE KEY `arcRead_ip_UN` (`ip`), KEY `worker_printer_FK` (`printerFk`), CONSTRAINT `worker_printer_FK` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22094,7 +26687,7 @@ CREATE TABLE `assignedTicketToWorker` ( PRIMARY KEY (`id`), UNIQUE KEY `idWorker_UNIQUE` (`idWorker`), UNIQUE KEY `idTicket_UNIQUE` (`idTicket`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla para relacionar un ticket con el sacador del altillo '; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla para relacionar un ticket con el sacador del altillo '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22147,7 +26740,7 @@ CREATE TABLE `autoRadioLogCall` ( PRIMARY KEY (`id`), KEY `ticket_idx` (`ticketFk`), CONSTRAINT `ticket` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22169,78 +26762,8 @@ CREATE TABLE `autonomy` ( KEY `autonomy_FK_1` (`geoFk`), CONSTRAINT `autonomy_FK` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `autonomy_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Comunidades autónomas o su equivalente en otros paises. Agrupación de provincias, en una categoria inferior a country.'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Comunidades autónomas o su equivalente en otros paises. Agrupación de provincias, en una categoria inferior a country.'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_BI` - BEFORE INSERT ON `autonomy` - FOR EACH ROW -BEGIN - - SET NEW.geoFk = zoneGeo_new('autonomy', NEW.`name`, (SELECT geoFk FROM country WHERE id = NEW.countryFk)); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_BU` - BEFORE UPDATE ON `autonomy` - FOR EACH ROW -BEGIN - IF !(OLD.countryFk <=> NEW.countryFk) THEN - CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM country WHERE id = NEW.countryFk)); - END IF; - - IF !(OLD.`name` <=> NEW.`name`) THEN - UPDATE zoneGeo SET `name` = NEW.`name` - WHERE id = NEW.geoFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_AD` - AFTER DELETE ON `autonomy` - FOR EACH ROW -BEGIN - CALL zoneGeo_delete(OLD.geoFk); -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 `awb` @@ -22294,31 +26817,8 @@ CREATE TABLE `awb` ( CONSTRAINT `awb_FK_3` FOREIGN KEY (`invoiceInPaletizedFk`) REFERENCES `invoiceIn` (`id`) ON UPDATE CASCADE, CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`taxFk`) REFERENCES `taxCode` (`id`) ON UPDATE CASCADE, CONSTRAINT `awb_supplierFk` FOREIGN KEY (`transitoryFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`awb_bi` - BEFORE INSERT ON `awb` - FOR EACH ROW -BEGIN - - SET NEW.year= year(util.VN_CURDATE()); - - -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 */ ; -- -- Temporary table structure for view `awbVolume` @@ -22368,50 +26868,8 @@ CREATE TABLE `bankEntity` ( PRIMARY KEY (`id`), KEY `fg_entity1_idx` (`countryFk`), CONSTRAINT `fg_entity1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Entidades bancarias '; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Entidades bancarias '; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`bankEntity_beforeInsert` - BEFORE INSERT ON `bankEntity` - FOR EACH ROW -BEGIN - CALL bankEntity_checkBic(NEW.bic); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`bankEntity_beforeUpdate` - BEFORE UPDATE ON `bankEntity` - FOR EACH ROW -BEGIN - IF NOT (NEW.bic <=> OLD.bic) THEN - CALL bankEntity_checkBic(NEW.bic); - 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 */ ; -- -- Table structure for table `bankEntityConfig` @@ -22425,7 +26883,7 @@ CREATE TABLE `bankEntityConfig` ( `bicLength` tinyint(4) DEFAULT 11 COMMENT 'Tamaño del campo bic', `defaultBankId` int(11) NOT NULL DEFAULT 3117 COMMENT 'Id del banco por defecto', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22500,7 +26958,7 @@ CREATE TABLE `bionicConfig` ( `verdnaturaVolumeBox` int(11) NOT NULL, `itemCarryBox` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22527,7 +26985,31 @@ CREATE TABLE `bookingPlanner` ( CONSTRAINT `bookingPlanner_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `bookingPlanner_ibfk_2` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `bookingPlanner_ibfk_3` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `botanicExport__` +-- + +DROP TABLE IF EXISTS `botanicExport__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `botanicExport__` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `ediGenusFk` mediumint(8) unsigned NOT NULL, + `ediSpecieFk` mediumint(8) unsigned DEFAULT NULL, + `countryFk__` mediumint(8) unsigned DEFAULT NULL, + `restriction` enum('Sin restriccion','Importacion Prohibida','pasaporte fitosanitario','pasaporte individual','declaracion origen') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `description` varchar(45) DEFAULT NULL, + `isProtectedZone` tinyint(1) NOT NULL DEFAULT 0, + `code` enum('importProhibited','phytosanitaryPassport','individualPassport') DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `Id_Paises` (`countryFk__`), + KEY `botanicExport_ibfk_2_idx` (`ediGenusFk`), + KEY `botanicExport_ibfk_3_idx` (`ediSpecieFk`), + CONSTRAINT `botanicExport___ibfk_1` FOREIGN KEY (`countryFk__`) REFERENCES `country` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #4419 Deprecated 2023-07-20'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22561,7 +27043,7 @@ CREATE TABLE `budget` ( CONSTRAINT `budget_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budget_FK_2` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budget_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Master de presupuestos de project'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Master de presupuestos de project'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22580,7 +27062,7 @@ CREATE TABLE `budgetDms` ( KEY `budgetDms_FK_1` (`dmsFk`), CONSTRAINT `budgetDms_FK` FOREIGN KEY (`budgetFk`) REFERENCES `budget` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budgetDms_FK_1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Gestion documental de budget'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Gestion documental de budget'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22601,7 +27083,7 @@ CREATE TABLE `budgetInvoiceIn` ( KEY `budgetInvoiceIn_FK_1` (`invoiceInFk`), CONSTRAINT `budgetInvoiceIn_FK` FOREIGN KEY (`budgetFk`) REFERENCES `budget` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budgetInvoiceIn_FK_1` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Facturas relativas al presupuesto'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Facturas relativas al presupuesto'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22622,34 +27104,8 @@ CREATE TABLE `budgetNotes` ( KEY `budgetNotes_FK_2` (`userFk`), CONSTRAINT `budgetNotes_FK` FOREIGN KEY (`budgetFk`) REFERENCES `budget` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budgetNotes_FK_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Historico de budget'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Historico de budget'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`budgetNotes_BeforeInsert` - BEFORE INSERT ON `budgetNotes` - FOR EACH ROW -BEGIN - - IF ISNULL(NEW.userFk) THEN - - SET NEW.userFk = account.myUser_getId(); - - 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 */ ; -- -- Table structure for table `budgetState` @@ -22664,7 +27120,7 @@ CREATE TABLE `budgetState` ( `description` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `budgetState_UN` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22719,148 +27175,8 @@ CREATE TABLE `business` ( CONSTRAINT `business_workerBusinessCategoryFk` FOREIGN KEY (`workerBusinessCategoryFk`) REFERENCES `payrollCategories` (`id`) ON UPDATE CASCADE, CONSTRAINT `business_workerBusinessTypeFk` FOREIGN KEY (`workerBusinessTypeFk`) REFERENCES `workerBusinessType` (`id`) ON UPDATE CASCADE, CONSTRAINT `business_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_beforeInsert` - BEFORE INSERT ON `business` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.ended IS NULL THEN - SET NEW.payedHolidays = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_afterInsert` - AFTER INSERT ON `business` - FOR EACH ROW -BEGIN - CALL worker_updateBusiness(NEW.workerFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_beforeUpdate` - BEFORE UPDATE ON `business` - FOR EACH ROW -BEGIN - DECLARE isOverlapping BOOL; - - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.ended IS NULL THEN - SET NEW.payedHolidays = 0; - END IF; - - IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN - - SELECT COUNT(*) > 0 INTO isOverlapping - FROM business b - WHERE (util.hasDateOverlapped( - NEW.started, - IFNULL(NEW.ended, b.started), - b.started, - IFNULL(b.ended, NEW.started)) - OR (NEW.ended <=> NULL AND b.ended <=> NULL)) - AND b.id <> OLD.id - AND workerFk = OLD.workerFk; - - IF isOverlapping THEN - CALL util.throw ('IS_OVERLAPPING'); - 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_afterUpdate` - AFTER UPDATE ON `business` - FOR EACH ROW -BEGIN - CALL worker_updateBusiness(NEW.workerFk); - - IF NOT (OLD.workerFk <=> NEW.workerFk) THEN - CALL worker_updateBusiness(OLD.workerFk); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_afterDelete` - AFTER DELETE ON `business` - FOR EACH ROW -BEGIN - INSERT INTO workerLog - SET `action` = 'delete', - `changedModel` = 'Business', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - CALL worker_updateBusiness(OLD.workerFk); -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 */ ; -- -- Temporary table structure for view `businessCalendar` @@ -22888,7 +27204,7 @@ CREATE TABLE `businessReasonEnd` ( `id` tinyint(3) NOT NULL AUTO_INCREMENT, `reason` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22908,7 +27224,7 @@ CREATE TABLE `businessSchedule` ( UNIQUE KEY `day_id` (`weekday`,`started`,`ended`,`businessFk`), KEY `journey_business_id_idx` (`businessFk`), CONSTRAINT `journey_business_id` FOREIGN KEY (`businessFk`) REFERENCES `business` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22938,7 +27254,7 @@ CREATE TABLE `buy` ( `itemFk` int(11) NOT NULL DEFAULT 90, `quantity` int(11) DEFAULT 0, `dispatched` int(11) NOT NULL DEFAULT 0, - `buyingValue` decimal(10,3) NOT NULL DEFAULT 0.000, + `buyingValue` decimal(10,4) NOT NULL DEFAULT 0.0000, `freightValue` decimal(10,3) NOT NULL DEFAULT 0.000, `isIgnored` tinyint(1) NOT NULL DEFAULT 0, `stickers` int(11) NOT NULL DEFAULT 0, @@ -22986,319 +27302,8 @@ CREATE TABLE `buy` ( CONSTRAINT `buy_ibfk_2` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE, CONSTRAINT `buy_id` FOREIGN KEY (`entryFk`) REFERENCES `entry` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `buy_itemfk` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeInsert` - BEFORE INSERT ON `buy` - FOR EACH ROW -trig: BEGIN - DECLARE vWarehouse INT; - DECLARE vLanding DATE; - DECLARE vGrouping INT; - DECLARE vGroupingMode TINYINT; - DECLARE vGenericFk INT; - DECLARE vGenericInDate BOOL; - - IF @isModeInventory THEN - LEAVE trig; - END IF; - - IF NEW.printedStickers <> 0 THEN - CALL util.throw('it is not possible to create buy lines with printedstickers other than 0'); - END IF; - - SET NEW.editorFk = account.myUser_getId(); - - CALL buy_checkGrouping(NEW.`grouping`); - - SELECT t.warehouseInFk, t.landed INTO vWarehouse, vLanding - FROM entry e - JOIN travel t ON t.id = e.travelFk - WHERE e.id = NEW.entryFk; - - SELECT b.`grouping`, b.groupingMode INTO vGrouping, vGroupingMode - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed <= vLanding - AND b.itemFk = NEW.itemFk - 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` = vGrouping; - END IF; - - IF NEW.groupingMode IS NULL THEN - SET NEW.groupingMode = vGroupingMode; - END IF; - -- Generics - SELECT i.genericFk INTO vGenericFk - FROM item i - WHERE i.id = NEW.itemFk; - - IF vGenericFk THEN - SELECT COUNT(*) INTO vGenericInDate - FROM genericAllocation ga - JOIN entry e ON e.id = NEW.entryFk - JOIN travel tr on tr.id = e.travelFk - WHERE ga.itemFk = vGenericFk - AND tr.landed BETWEEN ga.startDated AND ga.endDated; - IF vGenericInDate THEN - SET NEW.itemOriginalFk = NEW.itemFk; - - SET NEW.itemFk = vGenericFk; - END IF; - END IF; - IF NEW.quantity < 0 THEN - SET NEW.isIgnored = TRUE; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterInsert` - AFTER INSERT ON `buy` - FOR EACH ROW -trig: BEGIN - IF @isModeInventory OR @isTriggerDisabled THEN - LEAVE trig; - END IF; - - CALL stock.log_add('buy', NEW.id, NULL); - - CALL buy_afterUpsert(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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeUpdate` - BEFORE UPDATE ON `buy` - FOR EACH ROW -trig:BEGIN - DECLARE vGenericFk INT; - DECLARE vGenericInDate BOOL; - DECLARE vIsInventory BOOL; - DECLARE vDefaultEntry INT; - - IF @isTriggerDisabled THEN - LEAVE trig; - END IF; - - SET NEW.editorFk = account.myUser_getId(); - - SELECT defaultEntry INTO vDefaultEntry - FROM entryConfig; - - IF (NOT OLD.entryFk <=> NEW.entryFk OR NOT OLD.printedStickers <=> NEW.printedStickers) - AND NEW.printedStickers <> 0 THEN - SELECT defaultEntry INTO vDefaultEntry - FROM entryConfig; - - IF NEW.entryFk = vDefaultEntry THEN - CALL util.throw('There can be no lines with printed labels on the default entry'); - END IF; - END IF; - - IF NOT NEW.`grouping` <=> OLD.`grouping` THEN - CALL buy_checkGrouping(NEW.`grouping`); - END IF; - - -- Generics - SELECT i.genericFk INTO vGenericFk - FROM item i - WHERE i.id = NEW.itemFk; - - IF vGenericFk THEN - SELECT COUNT(*) INTO vGenericInDate - FROM genericAllocation ga - JOIN entry e ON e.id = NEW.entryFk - JOIN travel tr on tr.id = e.travelFk - WHERE ga.itemFk = vGenericFk - AND tr.landed BETWEEN ga.startDated AND ga.endDated; - IF vGenericInDate THEN - SET NEW.itemOriginalFk = NEW.itemFk; - SET NEW.itemFk = vGenericFk; - END IF; - END IF; - - SELECT COUNT(*) INTO vIsInventory - FROM entry e - JOIN supplier s ON s.id = e.supplierFk - JOIN entryConfig ec ON ec.inventorySupplierFk = e.supplierFk - WHERE e.id = NEW.entryFk; - - IF vIsInventory THEN - IF NOT NEW.printedStickers <=> OLD.printedStickers THEN - CALL util.throw("Stickers cannot be modified if they are inventory"); - END IF; - END IF; - - IF NEW.quantity < 0 THEN - SET NEW.isIgnored = TRUE; - 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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterUpdate` - AFTER UPDATE ON `buy` - FOR EACH ROW -trig: BEGIN - DECLARE vLanded DATE; - DECLARE vBuyerFk INT; - DECLARE vIsBuyerToBeEmailed BOOL; - DECLARE vItemName VARCHAR(50); - - IF @isModeInventory OR @isTriggerDisabled THEN - LEAVE trig; - END IF; - - IF !(NEW.id <=> OLD.id) - OR !(NEW.entryFk <=> OLD.entryFk) - OR !(NEW.itemFk <=> OLD.itemFk) - OR !(NEW.quantity <=> OLD.quantity) - OR !(NEW.created <=> OLD.created) THEN - CALL stock.log_add('buy', NEW.id, OLD.id); - END IF; - - CALL buy_afterUpsert(NEW.id); - - SELECT w.isBuyerToBeEmailed, t.landed - INTO vIsBuyerToBeEmailed, vLanded - FROM entry e - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE e.id = NEW.entryFk; - - SELECT it.workerFk, i.longName - INTO vBuyerFk, vItemName - FROM itemCategory k - JOIN itemType it ON it.categoryFk = k.id - JOIN item i ON i.typeFk = it.id - WHERE i.id = OLD.itemFk; - - IF vIsBuyerToBeEmailed AND - vBuyerFk != account.myUser_getId() AND - vLanded = util.VN_CURDATE() THEN - IF !(NEW.itemFk <=> OLD.itemFk) OR - !(NEW.quantity <=> OLD.quantity) OR - !(NEW.packing <=> OLD.packing) OR - !(NEW.grouping <=> OLD.grouping) OR - !(NEW.packagingFk <=> OLD.packagingFk) OR - !(NEW.weight <=> OLD.weight) THEN - CALL vn.mail_insert( - CONCAT(account.user_getNameFromId(vBuyerFk),'@verdnatura.es'), - CONCAT(account.myUser_getName(),'@verdnatura.es'), - CONCAT('E ', NEW.entryFk ,' Se ha modificado item ', NEW.itemFk, ' ', vItemName), - 'Este email se ha generado automáticamente' - ); - 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeDelete` - BEFORE DELETE ON buy - FOR EACH ROW -BEGIN - IF OLD.printedStickers <> 0 THEN - CALL util.throw("it is not possible to delete buys with printed labels "); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterDelete` - AFTER DELETE ON `buy` - FOR EACH ROW -trig: BEGIN - DECLARE vValues VARCHAR(255); - - IF @isModeInventory OR @isTriggerDisabled THEN - LEAVE trig; - END IF; - - CALL stock.log_add('buy', NULL, OLD.id); - - INSERT INTO entryLog - SET `action` = 'delete', - `changedModel` = 'Buy', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - -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 `buyConfig` @@ -23378,7 +27383,7 @@ CREATE TABLE `calendar` ( KEY `id_index` (`id`), CONSTRAINT `calendar_FK` FOREIGN KEY (`dayOffTypeFk`) REFERENCES `absenceType` (`id`) ON UPDATE CASCADE, CONSTRAINT `calendar_businessFk` FOREIGN KEY (`businessFk`) REFERENCES `business` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23402,7 +27407,7 @@ CREATE TABLE `calendarHolidays` ( CONSTRAINT `calendarHolidaysNameFk` FOREIGN KEY (`calendarHolidaysNameFk`) REFERENCES `calendarHolidaysName` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `calendarholidaystypeFk` FOREIGN KEY (`calendarHolidaysTypeFk`) REFERENCES `calendarHolidaysType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workCenterFk` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23416,7 +27421,7 @@ CREATE TABLE `calendarHolidaysName` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23431,7 +27436,7 @@ CREATE TABLE `calendarHolidaysType` ( `name` varchar(50) NOT NULL, `hexColour` char(7) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23448,7 +27453,7 @@ CREATE TABLE `calendarType` ( `isPartial` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `hours_labour_hours_labour_id_key` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23465,7 +27470,7 @@ CREATE TABLE `campaign` ( `scopeDays` int(11) NOT NULL DEFAULT 15, PRIMARY KEY (`id`), UNIQUE KEY `campaign_dated_uindex` (`dated`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23480,7 +27485,7 @@ CREATE TABLE `category` ( `description` varchar(45) NOT NULL, `nick` varchar(3) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23498,7 +27503,7 @@ CREATE TABLE `chain` ( PRIMARY KEY (`id`), KEY `chain_FK` (`componentFk`), CONSTRAINT `chain_FK` FOREIGN KEY (`componentFk`) REFERENCES `component` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Grupos de clientes'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Grupos de clientes'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23522,7 +27527,7 @@ CREATE TABLE `chat` ( PRIMARY KEY (`id`), KEY `chat_FK` (`senderFk`), CONSTRAINT `chat_FK` FOREIGN KEY (`senderFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23539,7 +27544,7 @@ CREATE TABLE `chatConfig` ( `user` varchar(50) NOT NULL, `password` varchar(50) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23575,72 +27580,8 @@ CREATE TABLE `claim` ( CONSTRAINT `claim_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `claim_ibfk_3` FOREIGN KEY (`claimStateFk`) REFERENCES `claimState` (`id`) ON UPDATE CASCADE, CONSTRAINT `claim_ibfk_5` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Reclamaciones, tabla principal'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claim_beforeInsert` - BEFORE INSERT ON `claim` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claim_beforeUpdate` - BEFORE UPDATE ON `claim` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claim_afterDelete` - AFTER DELETE ON `claim` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'Claim', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `claimBeginning` @@ -23662,72 +27603,8 @@ CREATE TABLE `claimBeginning` ( CONSTRAINT `claimBeginning_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `claimBeginning_ibfk_7` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `claimBeginning_ibfk_8` FOREIGN KEY (`claimFk`) REFERENCES `claim` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalle de las reclamaciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimBeginning_beforeInsert` - BEFORE INSERT ON `claimBeginning` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimBeginning_beforeUpdate` - BEFORE UPDATE ON `claimBeginning` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimBeginning_afterDelete` - AFTER DELETE ON `claimBeginning` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'ClaimBeginning', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `claimConfig` @@ -23757,7 +27634,7 @@ CREATE TABLE `claimDestination` ( PRIMARY KEY (`id`), KEY `clSolAddressFk_idx` (`addressFk`), CONSTRAINT `clSolAddressFk` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Solucion ofrecida a la reclamación'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Solucion ofrecida a la reclamación'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23794,72 +27671,8 @@ CREATE TABLE `claimDevelopment` ( CONSTRAINT `claimDevelopment_ibfk_7` FOREIGN KEY (`claimReasonFk`) REFERENCES `claimReason` (`id`) ON UPDATE CASCADE, CONSTRAINT `claimDevelopment_ibfk_8` FOREIGN KEY (`claimResultFk`) REFERENCES `claimResult` (`id`) ON UPDATE CASCADE, CONSTRAINT `claimDevelopment_ibfk_9` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Causas de las reclamaciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Causas 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDevelopment_beforeInsert` - BEFORE INSERT ON `claimDevelopment` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDevelopment_beforeUpdate` - BEFORE UPDATE ON `claimDevelopment` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDevelopment_afterDelete` - AFTER DELETE ON `claimDevelopment` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'ClaimDevelopment', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `claimDms` @@ -23880,70 +27693,6 @@ CREATE TABLE `claimDms` ( CONSTRAINT `dmsFk` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDms_beforeInsert` - BEFORE INSERT ON `claimDms` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDms_beforeUpdate` - BEFORE UPDATE ON `claimDms` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDms_afterDelete` - AFTER DELETE ON `claimDms` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'ClaimDms', - `changedModelId` = OLD.claimFk, - `userFk` = account.myUser_getId(); -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 `claimEnd` @@ -23970,72 +27719,8 @@ CREATE TABLE `claimEnd` ( CONSTRAINT `claimEnd_ibfk_1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `claimEnd_ibfk_3` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `claimEnd_ibfk_4` FOREIGN KEY (`claimFk`) REFERENCES `claim` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Acciones en respuesta a 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimEnd_beforeInsert` - BEFORE INSERT ON `claimEnd` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimEnd_beforeUpdate` - BEFORE UPDATE ON `claimEnd` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimEnd_afterDelete` - AFTER DELETE ON `claimEnd` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'ClaimEnd', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `claimLog` @@ -24062,7 +27747,7 @@ CREATE TABLE `claimLog` ( KEY `claimLog_claimLog` (`originFk`,`creationDate`), CONSTRAINT `claimOriginFk` FOREIGN KEY (`originFk`) REFERENCES `claim` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `claimUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24087,72 +27772,8 @@ CREATE TABLE `claimObservation` ( CONSTRAINT `claimObservation_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `claimObservation_ibfk_1` FOREIGN KEY (`claimFk`) REFERENCES `claim` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `claimObservation_ibfk_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a una reclamación'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a una reclamación'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimObservation_beforeInsert` - BEFORE INSERT ON `claimObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimObservation_beforeUpdate` - BEFORE UPDATE ON `claimObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimObservation_afterDelete` - AFTER DELETE ON `claimObservation` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'ClaimObservation', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `claimRatio` @@ -24185,7 +27806,7 @@ CREATE TABLE `claimReason` ( `description` varchar(45) NOT NULL, `isTired` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Motivos de las fallos'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Motivos de las fallos'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24199,7 +27820,7 @@ CREATE TABLE `claimRedelivery` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Método por el cual el cliente nos devuelve la mercancía'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Método por el cual el cliente nos devuelve la mercancía'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24216,7 +27837,7 @@ CREATE TABLE `claimResponsible` ( `code` varchar(3) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `claimResponsible_UN` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Responsables de las causas'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Responsables de las causas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24230,7 +27851,7 @@ CREATE TABLE `claimResult` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Consecuencias de los motivos'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Consecuencias de los motivos'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24246,7 +27867,7 @@ CREATE TABLE `claimRma` ( `created` timestamp NOT NULL DEFAULT current_timestamp(), `workerFk` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24269,72 +27890,8 @@ CREATE TABLE `claimState` ( KEY `claimState_fk_editor` (`editorFk`), CONSTRAINT `claimState_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `roleFgn` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Estados posibles de las reclamaciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Estados posibles 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_beforeInsert` - BEFORE INSERT ON `claimState` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_beforeUpdate` - BEFORE UPDATE ON `claimState` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_afterDelete` - AFTER DELETE ON `claimState` - FOR EACH ROW -BEGIN - INSERT INTO claimLog - SET `action` = 'delete', - `changedModel` = 'ClaimState', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `client` @@ -24436,217 +27993,8 @@ CREATE TABLE `client` ( CONSTRAINT `client_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, CONSTRAINT `tipos_de_cliente` FOREIGN KEY (`clientTypeFk`) REFERENCES `clientType` (`id`) ON UPDATE CASCADE, CONSTRAINT `typeFk` FOREIGN KEY (`typeFk`) REFERENCES `clientType` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_beforeInsert` - BEFORE INSERT ON `client` - FOR EACH ROW -BEGIN - - SET NEW.editorFk = account.myUser_getId(); - - IF (NEW.phone <> '') THEN - CALL pbx.phone_isValid(NEW.phone); - END IF; - - IF (NEW.mobile <> '') THEN - CALL pbx.phone_isValid(NEW.mobile); - END IF; - - SET NEW.accountingAccount = 4300000000 + NEW.id; - - SET NEW.lastSalesPersonFk = NEW.salesPersonFk; -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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_AfterInsert` - AFTER INSERT ON `client` - FOR EACH ROW -BEGIN - IF NEW.credit IS NOT NULL AND NEW.credit THEN - INSERT INTO clientCredit - SET clientFk = NEW.id, - workerFk = NEW.editorFk, - amount = NEW.credit; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_beforeUpdate` - BEFORE UPDATE ON `client` - FOR EACH ROW -BEGIN - DECLARE vText VARCHAR(255) DEFAULT NULL; - DECLARE vPayMethodFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF NOT(NEW.credit <=> OLD.credit) THEN - INSERT INTO clientCredit - SET clientFk = NEW.id, - amount = NEW.credit, - workerFk = NEW.editorFk; - END IF; - -- Comprueba que el formato de los teléfonos es válido - - IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN - CALL pbx.phone_isValid(NEW.phone); - END IF; - - IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN - CALL pbx.phone_isValid(NEW.mobile); - END IF; - - SELECT id INTO vPayMethodFk - FROM vn.payMethod - WHERE code = 'bankDraft'; - - IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN - SET NEW.dueDay = 5; - END IF; - - -- Avisar al comercial si ha llegado la documentación sepa/core - - IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN - SET vText = 'Sepa de VNL'; - END IF; - - IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN - SET vText = 'Core de VNL'; - END IF; - - IF vText IS NOT NULL - THEN - INSERT INTO mail(receiver, replyTo, `subject`, body) - SELECT - CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'), - 'administracion@verdnatura.es', - CONCAT('Cliente ', NEW.id), - CONCAT('Recibida la documentación: ', vText) - FROM worker w - LEFT JOIN account.user u ON w.id = u.id AND u.active - LEFT JOIN account.account ac ON ac.id = u.id - WHERE w.id = NEW.salesPersonFk; - END IF; - - IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN - IF (SELECT COUNT(clientFk) - FROM clientProtected - WHERE clientFk = NEW.id - ) > 0 THEN - CALL util.throw("HAS_CLIENT_PROTECTED"); - END IF; - END IF; - - IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN - SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); - END IF; - - IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN - SET NEW.isTaxDataChecked = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_afterUpdate` - AFTER UPDATE ON `client` - FOR EACH ROW -BEGIN - IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN - UPDATE `address` SET isDefaultAddress = 0 - WHERE clientFk = NEW.id; - - UPDATE `address` SET isDefaultAddress = 1 - WHERE id = NEW.defaultAddressFk; - END IF; - - IF NOT (NEW.provinceFk <=> OLD.provinceFk) OR NOT (NEW.isVies <=> OLD.isVies) THEN - INSERT IGNORE INTO ticketRecalc (ticketFk) - SELECT id FROM ticket t - WHERE t.clientFk = NEW.id - AND t.refFk IS NULL; - END IF; - - IF NOT NEW.isActive THEN - UPDATE account.`user` - SET active = FALSE - WHERE id = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_afterDelete` - AFTER DELETE ON `client` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'Client', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `clientChain` @@ -24664,7 +28012,7 @@ CREATE TABLE `clientChain` ( KEY `clientChain_fk2_idx` (`chainFk`), CONSTRAINT `clientChain_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientChain_fk2` FOREIGN KEY (`chainFk`) REFERENCES `chain` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24691,7 +28039,7 @@ CREATE TABLE `clientConfig` ( KEY `clientNewConfigMandateType_FK` (`defaultMandateTypeFk`), CONSTRAINT `clientNewConfigMandateType_FK` FOREIGN KEY (`defaultMandateTypeFk`) REFERENCES `mandateType` (`id`), CONSTRAINT `clientNewConfigPayMethod_FK` FOREIGN KEY (`defaultPayMethodFk`) REFERENCES `payMethod` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24708,7 +28056,7 @@ CREATE TABLE `clientConsumptionQueue` ( `printed` datetime DEFAULT NULL, `status` varchar(50) DEFAULT '', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue for client consumption PDF mailing'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue for client consumption PDF mailing'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24729,52 +28077,8 @@ CREATE TABLE `clientContact` ( KEY `clientContact_FK` (`clientFk`), CONSTRAINT `clientContact_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientContact_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientContact_beforeInsert` - BEFORE INSERT ON `clientContact` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientContact_afterDelete` - AFTER DELETE ON `clientContact` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'ClientContact', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `clientCredit` @@ -24794,61 +28098,25 @@ CREATE TABLE `clientCredit` ( KEY `credit_ClienteFk` (`clientFk`), CONSTRAINT `credit_ClienteFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workers_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER clientCredit_AfterInsert -AFTER INSERT -ON clientCredit FOR EACH ROW -BEGIN - - DECLARE vSender VARCHAR(50); - - SELECT u.name INTO vSender - FROM account.`user` u - WHERE u.id = NEW.workerFk; - - IF vSender IN ('juanvi','pepe') THEN - - CALL `vn`.`mail_insert`('pako@verdnatura.es', - NULL, - CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €'), - CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €')); - - 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 */ ; - --- --- Table structure for table `clientCreditLimit` --- - -DROP TABLE IF EXISTS `clientCreditLimit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `clientCreditLimit` ( - `id` int(11) NOT NULL, - `maxAmount` int(10) unsigned NOT NULL, - `roleFk` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `clientCreditLimit_FK_idx` (`roleFk`), - CONSTRAINT `clientCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `clientDefaultCompany` +-- + +DROP TABLE IF EXISTS `clientDefaultCompany`; +/*!50001 DROP VIEW IF EXISTS `clientDefaultCompany`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `clientDefaultCompany` AS SELECT + 1 AS `id`, + 1 AS `clientFk`, + 1 AS `companyFk`, + 1 AS `started`, + 1 AS `finished` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `clientDms` -- @@ -24869,70 +28137,6 @@ CREATE TABLE `clientDms` ( CONSTRAINT `fk_clientes_gestdoc_3` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientDms_beforeInsert` - BEFORE INSERT ON `clientDms` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientDms_beforeUpdate` - BEFORE UPDATE ON `clientDms` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientDms_afterDelete` - AFTER DELETE ON `clientDms` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'ClientDms', - `changedModelId` = OLD.dmsFk, - `userFk` = account.myUser_getId(); -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 `clientInforma` @@ -24953,7 +28157,7 @@ CREATE TABLE `clientInforma` ( KEY `informaClientFk` (`clientFk`), CONSTRAINT `informa_ClienteFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `informa_workers_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='información proporcionada por Informa, se actualiza desde el hook de client (salix)'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='información proporcionada por Informa, se actualiza desde el hook de client (salix)'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24973,7 +28177,7 @@ CREATE TABLE `clientItemType` ( KEY `clientItemType_FK_1` (`itemTypeFk`), CONSTRAINT `clientItemType_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientItemType_FK_1` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='son familias de productos que se quieren sustraer a la oferta del cliente'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='son familias de productos que se quieren sustraer a la oferta del cliente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25001,7 +28205,7 @@ CREATE TABLE `clientLog` ( KEY `clientLog_clientLog` (`originFk`,`creationDate`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25057,72 +28261,8 @@ CREATE TABLE `clientObservation` ( CONSTRAINT `clientObservation_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `clientObservation_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientObservation_ibfk_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientObservation_beforeInsert` - BEFORE INSERT ON `clientObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientObservation_beforeUpdate` - BEFORE UPDATE ON `clientObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientObservation_afterDelete` - AFTER DELETE ON `clientObservation` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'ClientObservation', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `clientPackagingGifts` @@ -25164,11 +28304,8 @@ DROP TABLE IF EXISTS `clientProtected`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientProtected` ( `clientFk` int(11) NOT NULL, - `workerFk` int(10) unsigned NOT NULL, PRIMARY KEY (`clientFk`), - KEY `clientProtected_fk2_idx` (`workerFk`), - CONSTRAINT `clientProtected_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `clientProtected_fk2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `clientProtected_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de clientes y comerciales que no se van a ver afectados por las desagsignaciones mensuales automaticas'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -25214,72 +28351,8 @@ CREATE TABLE `clientSample` ( CONSTRAINT `clientSampleCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `clientSample_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientSample_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientSample_beforeInsert` - BEFORE INSERT ON `clientSample` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientSample_beforeUpdate` - BEFORE UPDATE ON `clientSample` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientSample_afterDelete` - AFTER DELETE ON `clientSample` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'ClientSample', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `clientSms` @@ -25297,7 +28370,7 @@ CREATE TABLE `clientSms` ( KEY `clientSms_FK_1` (`smsFk`), CONSTRAINT `clientSms_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, CONSTRAINT `clientSms_FK_1` FOREIGN KEY (`smsFk`) REFERENCES `sms` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25314,7 +28387,7 @@ CREATE TABLE `clientType` ( `isCreatedAsServed` tinyint(1) DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Establece categorias para poder agrupar las ventas'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Establece categorias para poder agrupar las ventas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25386,30 +28459,8 @@ CREATE TABLE `cmr` ( CONSTRAINT `cmr_fk1` FOREIGN KEY (`ticketFk__`) REFERENCES `ticket` (`id`), CONSTRAINT `cmr_fk3` FOREIGN KEY (`addressToFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `cmr_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`cmr_beforeDelete` - BEFORE DELETE ON `cmr` - FOR EACH ROW -BEGIN - IF NOT (OLD.companyFk <=> NULL AND OLD.addressFromFk <=> NULL AND OLD.packagesList <=> NULL) THEN - CALL util.throw("Can not delete cmr, fields required not empty"); - 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 */ ; -- -- Table structure for table `cmrConfig` @@ -25475,56 +28526,8 @@ CREATE TABLE `collection` ( CONSTRAINT `collection_FK2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `collection_id2` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `ticketCollection` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE` - BEFORE UPDATE ON `collection` - FOR EACH ROW -BEGIN - - DECLARE vStateFk INT; - DECLARE vTotalLines INT; - DECLARE vPickedLines INT; - - IF NEW.saleTotalCount <= NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount - OR NEW.salePickedCount != OLD.salePickedCount) - THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'PREPARED'; - - SET NEW.stateFk = vStateFk; - - END IF; - - IF NEW.saleTotalCount > NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'ON_PREPARATION'; - - SET NEW.stateFk = vStateFk; - - 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 */ ; -- -- Table structure for table `collectionColors` @@ -25544,48 +28547,8 @@ CREATE TABLE `collectionColors` ( UNIQUE KEY `collectionColors_UN` (`shelve`,`wagon`,`trainFk`), KEY `collectionColors_FK` (`trainFk`), CONSTRAINT `collectionColors_FK` FOREIGN KEY (`trainFk`) REFERENCES `train` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los colores para las baldas de las colecciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los colores para las baldas de las colecciones'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER vn.collectionColors_beforeInsert -BEFORE INSERT -ON collectionColors FOR EACH ROW -BEGIN - CALL util.checkHex(NEW.rgb); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionColors_beforeUpdate` - BEFORE UPDATE ON `collectionColors` - FOR EACH ROW -BEGIN - CALL util.checkHex(NEW.rgb); -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 `collectionHotbed` @@ -25599,7 +28562,7 @@ CREATE TABLE `collectionHotbed` ( `userFk` int(11) NOT NULL, `created` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25622,142 +28585,8 @@ CREATE TABLE `collectionVolumetry` ( KEY `collectionVolumetry_FK_1` (`trainFk`), CONSTRAINT `collectionVolumetry_FK` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE, CONSTRAINT `collectionVolumetry_FK_1` FOREIGN KEY (`trainFk`) REFERENCES `train` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionVolumetry_afterInsert` - AFTER INSERT ON `collectionVolumetry` - FOR EACH ROW -BEGIN - DECLARE vJSON JSON DEFAULT JSON_OBJECT(); - DECLARE vUserFk INT DEFAULT account.myUser_getId(); - - SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.level), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('lines', NEW.lines), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('liters', NEW.liters), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('height', NEW.height), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); - - SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'insert'), vJSON); - - SET vJSON = util.notification_send( - 'modified-collection-volumetry', - JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), - vUserFk - ); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionVolumetry_afterUpdate` - AFTER UPDATE ON `collectionVolumetry` - FOR EACH ROW -BEGIN - DECLARE vJSON JSON DEFAULT JSON_OBJECT(); - DECLARE vUserFk INT DEFAULT account.myUser_getId(); - - IF NOT (NEW.id <=> OLD.id) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); - END IF; - - IF NOT (NEW.`level` <=> OLD.`level`) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.`level`), vJSON); - END IF; - - IF NOT (NEW.`lines` <=> OLD.`lines`) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('lines', NEW.`lines`), vJSON); - END IF; - - IF NOT (NEW.liters <=> OLD.liters) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('liters', NEW.liters), vJSON); - END IF; - - IF NOT (NEW.height <=> OLD.height) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('height', NEW.height), vJSON); - END IF; - - IF NOT (NEW.itemPackingTypeFk <=> OLD.itemPackingTypeFk) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); - END IF; - - IF NOT (NEW.trainFk <=> OLD.trainFk) THEN - SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); - END IF; - - SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'update'), vJSON); - - SET vJSON = util.notification_send( - 'modified-collection-volumetry', - JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), - vUserFk - ); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionVolumetry_afterDelete` - AFTER DELETE ON `collectionVolumetry` - FOR EACH ROW -BEGIN - DECLARE vJSON JSON DEFAULT JSON_OBJECT(); - DECLARE vUserFk INT DEFAULT account.myUser_getId(); - - SET vJSON = JSON_MERGE(JSON_OBJECT('id', OLD.id), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('level', OLD.level), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('lines', OLD.lines), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('liters', OLD.liters), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('height', OLD.height), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', OLD.itemPackingTypeFk), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', OLD.trainFk), vJSON); - - SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); - SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'delete'), vJSON); - - SET vJSON = util.notification_send( - 'modified-collection-volumetry', - JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), - vUserFk - ); -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 `collectionWagon` @@ -25875,7 +28704,7 @@ CREATE TABLE `company` ( CONSTRAINT `empresa_cliente` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `empresa_fk4` FOREIGN KEY (`supplierAccountFk`) REFERENCES `supplierAccount` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_empresa_grupo` FOREIGN KEY (`companyGroupFk`) REFERENCES `companyGroup` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25889,7 +28718,7 @@ CREATE TABLE `companyGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25921,6 +28750,47 @@ SET character_set_client = utf8; 1 AS `footnotes` */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `comparative` +-- + +DROP TABLE IF EXISTS `comparative`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `comparative` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `timePeriod` int(11) DEFAULT NULL, + `itemFk` int(11) DEFAULT NULL, + `warehouseFk` smallint(6) unsigned DEFAULT NULL, + `quantity` int(11) DEFAULT NULL, + `price` int(11) DEFAULT NULL, + `countryFk` mediumint(8) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `comparative_UN` (`timePeriod`,`itemFk`,`warehouseFk`), + KEY `comparativeItem_FK` (`itemFk`), + KEY `comparativeWarehouse_FK` (`warehouseFk`), + KEY `comparativeCountry_FK` (`countryFk`), + CONSTRAINT `comparativeCountry_FK` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`), + CONSTRAINT `comparativeItem_FK` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`), + CONSTRAINT `comparativeWarehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `comparativeAddConfig` +-- + +DROP TABLE IF EXISTS `comparativeAddConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `comparativeAddConfig` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `period` int(10) unsigned DEFAULT NULL COMMENT 'The number of periods to be regressed for insertion in vn.comparative', + `week` int(10) unsigned DEFAULT NULL COMMENT 'The number of weeks to exceed for recalculating the last period', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `comparativeConfig` -- @@ -25935,7 +28805,36 @@ CREATE TABLE `comparativeConfig` ( `maxDayRange` int(10) unsigned DEFAULT NULL COMMENT 'El rango máximo de días antes de utilizar el rango de días predeterminado', `minDayRange` int(10) unsigned DEFAULT NULL COMMENT 'El rango mínimo de días antes de utilizar el rango de días predeterminado', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `comparativeFilter` +-- + +DROP TABLE IF EXISTS `comparativeFilter`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `comparativeFilter` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `userFk` int(10) unsigned NOT NULL, + `name` varchar(100) NOT NULL, + `buyer` int(11) DEFAULT NULL, + `itemFilter` varchar(255) DEFAULT NULL, + `isFloramondo` tinyint(4) DEFAULT NULL, + `warehouseFk` smallint(6) unsigned DEFAULT NULL, + `tintaFk` varchar(100) DEFAULT NULL, + `hasType` tinyint(1) DEFAULT 0, + `producerFilter` varchar(255) DEFAULT NULL, + `supplierFk` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `comparativeFilter_FK` (`userFk`), + KEY `comparativeFilter_FK_1` (`warehouseFk`), + KEY `comparativeFilter_FK_2` (`supplierFk`), + CONSTRAINT `comparativeFilter_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`), + CONSTRAINT `comparativeFilter_FK_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`), + CONSTRAINT `comparativeFilter_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25973,7 +28872,7 @@ CREATE TABLE `component` ( KEY `series_componentes_idx` (`typeFk`), KEY `comp` (`classRate`), CONSTRAINT `serie_componente` FOREIGN KEY (`typeFk`) REFERENCES `componentType` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -25991,7 +28890,7 @@ CREATE TABLE `componentType` ( `code` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `Serie_UNIQUE` (`type`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Permite organizar de forma ordenada los distintos componentes'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Permite organizar de forma ordenada los distintos componentes'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26005,7 +28904,7 @@ CREATE TABLE `confectionType` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26056,7 +28955,7 @@ CREATE TABLE `config` ( `mainWarehouseFk` smallint(6) unsigned NOT NULL DEFAULT 60, PRIMARY KEY (`id`), KEY `fechainv_idx` (`inventoried`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26070,7 +28969,7 @@ CREATE TABLE `contactChannel` ( `id` smallint(6) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Canal por el que nos ha conocido un cliente y se ha dado de'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Canal por el que nos ha conocido un cliente y se ha dado de'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26086,7 +28985,7 @@ CREATE TABLE `continent` ( `code` varchar(2) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `continent_name_uindex` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='World continents'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='World continents'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26112,7 +29011,7 @@ CREATE TABLE `conveyor` ( PRIMARY KEY (`id`), KEY `conveyor_fk1_idx` (`typeFk`), CONSTRAINT `conveyor_fk1` FOREIGN KEY (`typeFk`) REFERENCES `conveyorType` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26128,7 +29027,7 @@ CREATE TABLE `conveyorBuildingClass` ( `priority` int(11) NOT NULL DEFAULT 0, `weightThreshold` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tipo de caja para el montaje de pallets'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tipo de caja para el montaje de pallets'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26146,7 +29045,7 @@ CREATE TABLE `conveyorConfig` ( `height` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `itemName_UNIQUE` (`itemName`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26209,7 +29108,37 @@ CREATE TABLE `conveyorType` ( `description` varchar(45) DEFAULT NULL, `color` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `coolerPath` +-- + +DROP TABLE IF EXISTS `coolerPath`; +/*!50001 DROP VIEW IF EXISTS `coolerPath`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `coolerPath` AS SELECT + 1 AS `id`, + 1 AS `description` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `coolerPathDetail` +-- + +DROP TABLE IF EXISTS `coolerPathDetail`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `coolerPathDetail` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `coolerPathFk` int(11) NOT NULL DEFAULT 1, + `hallway` varchar(3) NOT NULL, + PRIMARY KEY (`coolerPathFk`,`hallway`), + UNIQUE KEY `cooler_path_detail_id_UNIQUE` (`id`), + CONSTRAINT `coolerPathDetail_FK` FOREIGN KEY (`coolerPathFk`) REFERENCES `vn2008`.`cooler_path` (`cooler_path_id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26258,124 +29187,8 @@ CREATE TABLE `country` ( CONSTRAINT `country_FK` FOREIGN KEY (`politicalCountryFk__`) REFERENCES `country` (`id`) ON UPDATE CASCADE, CONSTRAINT `country_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE, CONSTRAINT `currency_id_fk` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_beforeInsert` - BEFORE INSERT ON `country` - FOR EACH ROW -BEGIN - SET NEW.geoFk = zoneGeo_new('country', NEW.country, 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_AFTER_INSERT` - AFTER INSERT ON `country` - FOR EACH ROW -BEGIN - UPDATE sage.Naciones - SET countryFk = NEW.id - WHERE Nacion = NEW.country; - - IF ROW_COUNT() = 0 THEN - CALL mail_insert( - 'cau@verdnatura.es', - NULL, - 'Actualizar tabla sage.Naciones', - CONCAT('Se ha insertado un nuevo país en la tabla vn.conuntry. Para el correcto funcionamiento del sistema \n\t\t\t\tde contabilidad es necesario actualizar la columna sage.Naciones.countryFk con el valor del nuevo país. \n\t\t\t Hay que buscar el nuevo país: ', NEW.country, ' en la tabla sage.Naciones y actualizar el campo sage.Naciones.countryFk con el valor ', 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_beforeUpdate` - BEFORE UPDATE ON `country` - FOR EACH ROW -BEGIN - -- IF !(OLD.geoFk <=> NEW.geoFk) THEN - -- CALL zoneGeo_throwNotEditable; - -- 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_afterUpdate` - AFTER UPDATE ON `country` - FOR EACH ROW -BEGIN - IF !(OLD.country <=> NEW.country) THEN - UPDATE zoneGeo SET `name` = NEW.country - WHERE id = NEW.geoFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_afterDelete` - AFTER DELETE ON `country` - FOR EACH ROW -BEGIN - CALL zoneGeo_delete(OLD.geoFk); -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 `cplusCorrectingType` @@ -26388,10 +29201,9 @@ CREATE TABLE `cplusCorrectingType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `cplusRectificationType` -- @@ -26464,34 +29276,8 @@ CREATE TABLE `creditClassification` ( KEY `creditClassifClientFk_idx` (`client`), KEY `creditClassifdateEnd_idx` (`dateEnd`), CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`creditClassification_beforeUpdate` - BEFORE UPDATE ON `creditClassification` - FOR EACH ROW -BEGIN - IF NEW.client <> OLD.client THEN - CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT'); - END IF; - IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN - UPDATE `client` c - SET creditInsurance = NULL WHERE c.id = NEW.client; - 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 */ ; -- -- Table structure for table `creditInsurance` @@ -26512,53 +29298,8 @@ CREATE TABLE `creditInsurance` ( KEY `creditInsurance_creditClassificationFk` (`creditClassificationFk`), CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `creditInsurance_creditClassificationFk` FOREIGN KEY (`creditClassificationFk`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`creditInsurance_beforeInsert` - BEFORE INSERT ON `creditInsurance` - FOR EACH ROW -BEGIN - IF NEW.creditClassificationFk THEN - SET NEW.creditClassification = NEW.creditClassificationFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`creditInsurance_afterInsert` - AFTER INSERT ON `creditInsurance` - FOR EACH ROW -BEGIN - UPDATE `client` c - JOIN vn.creditClassification cc ON cc.client = c.id - SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification; - -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 `currency` @@ -26593,7 +29334,7 @@ CREATE TABLE `customsAgent` ( `email` varchar(150) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `nif_UNIQUE` (`nif`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26648,7 +29389,7 @@ CREATE TABLE `delivery` ( PRIMARY KEY (`id`), KEY `delivery_ticketFk_FK` (`ticketFk`), CONSTRAINT `delivery_ticketFk_FK` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26664,7 +29405,7 @@ CREATE TABLE `deliveryMethod` ( `code` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26679,7 +29420,7 @@ CREATE TABLE `deliveryPoint` ( `name` varchar(45) NOT NULL, `ubication` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26709,7 +29450,7 @@ CREATE TABLE `delivery_zip` ( KEY `postal_code_idx` (`postal_code`), KEY `admin_name3_idx` (`admin_name3`), KEY `admin_name2_idx` (`admin_name2`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26752,108 +29493,8 @@ CREATE TABLE `department` ( CONSTRAINT `department_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `department_FK_1` FOREIGN KEY (`parentFk`) REFERENCES `department` (`id`), CONSTRAINT `fk_department_Trabajadores1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_beforeInsert` - BEFORE INSERT ON `department` - FOR EACH ROW -BEGIN - UPDATE vn.department_recalc SET isChanged = TRUE; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_afterUpdate` - AFTER UPDATE ON `department` - FOR EACH ROW -BEGIN - IF !(OLD.parentFk <=> NEW.parentFk) THEN - UPDATE vn.department_recalc SET isChanged = TRUE; - END IF; - - IF !(OLD.twoFactor <=> NEW.twoFactor) THEN - UPDATE account.user u - JOIN vn.workerDepartment wd ON wd.workerFk = u.id - SET u.twoFactor = NEW.twoFactor - WHERE wd.departmentFk = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_beforeDelete` - BEFORE DELETE ON `department` - FOR EACH ROW -BEGIN - - UPDATE vn.business b - JOIN vn.department d ON d.id = b.departmentFk - SET b.departmentFk = d.parentFk - WHERE b.departmentFk = 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_afterDelete` - AFTER DELETE ON `department` - FOR EACH ROW -BEGIN - - UPDATE vn.department_recalc SET isChanged = TRUE; - - UPDATE vn.business b - JOIN vn.department d ON d.id = b.departmentFk - SET b.departmentFk = d.parentFk - WHERE b.departmentFk = 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 */ ; -- -- Temporary table structure for view `departmentTree` @@ -26879,7 +29520,7 @@ CREATE TABLE `department_recalc` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `isChanged` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26897,7 +29538,7 @@ CREATE TABLE `device` ( PRIMARY KEY (`id`), KEY `device_fk1_idx` (`userFk`), CONSTRAINT `device_fk1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26918,7 +29559,7 @@ CREATE TABLE `deviceLog` ( PRIMARY KEY (`id`), KEY `deviceLog_FK` (`userFk`), CONSTRAINT `deviceLog_FK` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26952,72 +29593,8 @@ CREATE TABLE `deviceProduction` ( CONSTRAINT `deviceProduction_FK` FOREIGN KEY (`stateFk`) REFERENCES `deviceProductionState` (`code`), CONSTRAINT `deviceProduction_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `deviceProduction_CHECK` CHECK (`android_id` regexp '[A-Za-z0-9]{16,}' or `android_id` is null) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProduction_beforeInsert` - BEFORE INSERT ON `deviceProduction` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProduction_beforeUpdate` - BEFORE UPDATE ON `deviceProduction` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProduction_afterDelete` - AFTER DELETE ON `deviceProduction` - FOR EACH ROW -BEGIN - INSERT INTO deviceProductionLog - SET `action` = 'delete', - `changedModel` = 'DeviceProduction', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `deviceProductionConfig` @@ -27031,33 +29608,8 @@ CREATE TABLE `deviceProductionConfig` ( `isAllUsersallowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Permite que cualquier usuario pueda loguearse', `isTractorHuntingMode` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Habilita el modo cazador para usuarios que no se han logeado un tractor para sacar', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionConfig_afterUpdate` - AFTER UPDATE ON `deviceProductionConfig` - FOR EACH ROW -BEGIN - IF NEW.isAllUsersAllowed = 1 OR NEW.isAllUsersAllowed = -1 THEN - SET @username := (SELECT account.myUser_getName()); - INSERT INTO vn.mail (receiver, subject, body) - VALUES ('cau@verdnatura.es', 'Se ha activado la autenticación sin restricciones en la app', - CONCAT('El usuario ', @username,' ha habilitado la opción para que todos los usuarios puedan acceder a la app sin restricciones')); - 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 */ ; -- -- Table structure for table `deviceProductionLog` @@ -27084,7 +29636,7 @@ CREATE TABLE `deviceProductionLog` ( KEY `deviceProductionLog_deviceProductionLog` (`originFk`,`creationDate`), CONSTRAINT `deviceProductionOriginFk` FOREIGN KEY (`originFk`) REFERENCES `deviceProduction` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `deviceProductionUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27102,46 +29654,6 @@ CREATE TABLE `deviceProductionModels` ( CONSTRAINT `deviceProductionModels_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionModels_beforeInsert` - BEFORE INSERT ON `deviceProductionModels` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionModels_beforeUpdate` - BEFORE UPDATE ON `deviceProductionModels` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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 `deviceProductionState` @@ -27159,46 +29671,6 @@ CREATE TABLE `deviceProductionState` ( CONSTRAINT `deviceProductionState_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionState_beforeInsert` - BEFORE INSERT ON `deviceProductionState` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionState_beforeUpdate` - BEFORE UPDATE ON `deviceProductionState` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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 `deviceProductionUser` @@ -27221,70 +29693,6 @@ CREATE TABLE `deviceProductionUser` ( CONSTRAINT `deviceProductionUser_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionUser_beforeInsert` - BEFORE INSERT ON `deviceProductionUser` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionUser_beforeUpdate` - BEFORE UPDATE ON `deviceProductionUser` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionUser_afterDelete` - AFTER DELETE ON `deviceProductionUser` - FOR EACH ROW -BEGIN - INSERT INTO deviceProductionLog - SET `action` = 'delete', - `changedModel` = 'DeviceProductionUser', - `changedModelId` = OLD.deviceProductionFk, - `userFk` = account.myUser_getId(); -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 `disabilityGrade` @@ -27297,7 +29705,7 @@ CREATE TABLE `disabilityGrade` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Grados de discapacidad Modelo 145 IRPF', `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27330,115 +29738,8 @@ CREATE TABLE `dms` ( CONSTRAINT `dms_dmsTypeFk` FOREIGN KEY (`dmsTypeFk`) REFERENCES `dmsType` (`id`) ON UPDATE CASCADE, CONSTRAINT `dms_warehouseFk` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `dms_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='document managment system'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeInsert` - BEFORE INSERT ON `dms` - FOR EACH ROW -BEGIN - DECLARE vHardCopyNumber INT; - DECLARE vDmsTypeCode INT; - - IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN - CALL util.throw('this warehouse has not dms'); - END IF; - - IF NEW.hasFile THEN - SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber - FROM dms - WHERE warehouseFk = NEW.warehouseFk; - - SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); - END IF; - - SELECT code INTO vDmsTypeCode - FROM dmsType WHERE NEW.dmsTypeFk = id; - IF (vDmsTypeCode ='ticket') THEN - UPDATE ticket SET isSigned = 1 WHERE id = NEW.reference; - 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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` - BEFORE UPDATE ON `dms` - FOR EACH ROW -BEGIN - DECLARE vHardCopyNumber INT; - - IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) - OR - (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN - - IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN - SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); - END IF; - - SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber - FROM dms - WHERE warehouseFk = NEW.warehouseFk; - - SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); - END IF; - - IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN - - SET NEW.hasFile = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeDelete` - BEFORE DELETE ON `dms` - FOR EACH ROW -BEGIN - DECLARE vCanNotBeDeleted INT; - SELECT COUNT(*) INTO vCanNotBeDeleted - FROM dmsType dt - WHERE NOT (code <=> 'trash') - AND dt.id = OLD.dmsTypeFk; - - IF vCanNotBeDeleted THEN - CALL util.throw('A dms can not 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 */ ; -- -- Table structure for table `dmsType` @@ -27460,9 +29761,30 @@ CREATE TABLE `dmsType` ( KEY `writeRoleFk` (`writeRoleFk`), CONSTRAINT `readRoleFk` FOREIGN KEY (`readRoleFk`) REFERENCES `account`.`role` (`id`), CONSTRAINT `writeRoleFk` FOREIGN KEY (`writeRoleFk`) REFERENCES `account`.`role` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `doc` +-- + +DROP TABLE IF EXISTS `doc`; +/*!50001 DROP VIEW IF EXISTS `doc`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `doc` AS SELECT + 1 AS `id`, + 1 AS `sref`, + 1 AS `brief`, + 1 AS `companyFk`, + 1 AS `order`, + 1 AS `file`, + 1 AS `original`, + 1 AS `workerFk`, + 1 AS `created`, + 1 AS `warehouseFk` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `dock` -- @@ -27495,7 +29817,7 @@ CREATE TABLE `docuware` ( PRIMARY KEY (`id`), KEY `docuware_FK` (`dmsTypeFk`), CONSTRAINT `docuware_FK` FOREIGN KEY (`dmsTypeFk`) REFERENCES `dmsType` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27510,7 +29832,7 @@ CREATE TABLE `docuwareConfig` ( `url` varchar(75) DEFAULT NULL, `cookie` varchar(1000) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27540,7 +29862,7 @@ CREATE TABLE `dua` ( CONSTRAINT `duaCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `dua_fk1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `dua_fk2` FOREIGN KEY (`awbFk`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27581,7 +29903,7 @@ CREATE TABLE `duaIntrastat` ( KEY `duaIntrastat_fk2_idx` (`duaFk`), CONSTRAINT `duaIntrastat_fk1` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE, CONSTRAINT `duaIntrastat_fk2` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27601,7 +29923,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 `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27623,50 +29945,8 @@ CREATE TABLE `duaTax` ( KEY `duaTax_fk3_idx` (`taxClassFk`), CONSTRAINT `duaTax_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaTax_fk3` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`duaTax_BEFORE_INSERT` - BEFORE INSERT ON `duaTax` - FOR EACH ROW -BEGIN - SET NEW.rate = duaTax_getRate(NEW.duaFk, NEW.taxClassFk); - SET NEW.tax = NEW.base * NEW.rate / 100; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`duaTax_BEFORE_UPDATE` - BEFORE UPDATE ON `duaTax` - FOR EACH ROW -BEGIN - SET NEW.rate = duaTax_getRate(NEW.duaFk, NEW.taxClassFk); - SET NEW.tax = NEW.base * NEW.rate / 100; -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 */ ; -- -- Temporary table structure for view `ediGenus` @@ -27740,48 +30020,8 @@ CREATE TABLE `ektEntryAssign` ( UNIQUE KEY `ektEntryAssign_ix1` (`kop`,`sub`,`pro`), KEY `ektEntryAssign_FK` (`addressFk`), CONSTRAINT `ektEntryAssign_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ektEntryAssign_afterInsert -AFTER INSERT -ON ektEntryAssign FOR EACH ROW - UPDATE entry SET reference = NEW.`ref` WHERE id = NEW.entryFk */;; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER vn.ektEntryAssign_afterUpdate - AFTER UPDATE ON ektEntryAssign - FOR EACH ROW -BEGIN - IF NOT(NEW.`ref` <=> OLD.`ref`) OR NOT(NEW.`entryFk` <=> OLD.`entryFk`) THEN - UPDATE entry SET reference = NEW.`ref` WHERE id = NEW.entryFk; - 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 */ ; -- -- Temporary table structure for view `ektSubAddress` @@ -27810,7 +30050,7 @@ CREATE TABLE `emergencyMedia` ( `name` varchar(45) DEFAULT NULL, `value` varchar(45) DEFAULT NULL COMMENT 'Table to save all emergency phones', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27905,190 +30145,8 @@ CREATE TABLE `entry` ( CONSTRAINT `entry_ibfk_6` FOREIGN KEY (`travelFk`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `entry_observationEditorFk` FOREIGN KEY (`observationEditorFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, CONSTRAINT `entry_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_beforeInsert` - BEFORE INSERT ON `entry` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - CALL supplier_checkIsActive(NEW.supplierFk); - SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); - SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_afterInsert` - AFTER INSERT ON `entry` - FOR EACH ROW -BEGIN - CALL travel_requestRecalc(NEW.travelFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_beforeUpdate` - BEFORE UPDATE ON `entry` - FOR EACH ROW -BEGIN - DECLARE vIsVirtual BOOL; - DECLARE vPrintedCount INT; - DECLARE vHasDistinctWarehouses BOOL; - - SET NEW.editorFk = account.myUser_getId(); - - IF !(NEW.travelFk <=> OLD.travelFk) THEN - SELECT COUNT(*) > 0 INTO vIsVirtual - FROM entryVirtual WHERE entryFk = NEW.id; - - SELECT !(o.warehouseInFk <=> n.warehouseInFk) - OR !(o.warehouseOutFk <=> n.warehouseOutFk) - INTO vHasDistinctWarehouses - FROM travel o, travel n - WHERE o.id = OLD.travelFk - AND n.id = NEW.travelFk; - - IF vIsVirtual AND vHasDistinctWarehouses THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'A cloned entry cannot be moved to a travel with different warehouses'; - END IF; - - IF NEW.travelFk IS NULL THEN - SELECT COUNT(*) INTO vPrintedCount - FROM buy - WHERE entryFk = OLD.id - AND printedStickers > 0; - - IF vPrintedCount > 0 THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'An entry that contains lines with printed labels cannot be deleted'; - END IF; - END IF; - END IF; - - IF NOT (NEW.supplierFk <=> OLD.supplierFk) THEN - CALL supplier_checkIsActive(NEW.supplierFk); - SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); - END IF; - - IF NOT (NEW.travelFk <=> OLD.travelFk) - OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN - SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_afterUpdate` - AFTER UPDATE ON `entry` - FOR EACH ROW -BEGIN - IF NOT(NEW.id <=> OLD.id) - OR NOT(NEW.travelFk <=> OLD.travelFk) - OR NOT(NEW.isRaid <=> OLD.isRaid) THEN - CALL stock.log_add('entry', NEW.id, OLD.id); - END IF; - - IF NOT (NEW.travelFk <=> OLD.travelFk) THEN - CALL travel_requestRecalc(OLD.travelFk); - CALL travel_requestRecalc(NEW.travelFk); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_beforeDelete` - BEFORE DELETE ON `entry` - FOR EACH ROW -BEGIN - DELETE FROM buy WHERE entryFk = 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_afterDelete` - AFTER DELETE ON `entry` - FOR EACH ROW -BEGIN - INSERT INTO entryLog - SET `action` = 'delete', - `changedModel` = 'Entry', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - CALL travel_requestRecalc(OLD.travelFk); -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 `entryConfig` @@ -28132,7 +30190,7 @@ CREATE TABLE `entryLog` ( KEY `entryLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `entry` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28155,72 +30213,8 @@ CREATE TABLE `entryObservation` ( CONSTRAINT `entryObservation_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `entry_id_entryFk` FOREIGN KEY (`entryFk`) REFERENCES `entry` (`id`), CONSTRAINT `observationType_id_observationTypeFk` FOREIGN KEY (`observationTypeFk`) REFERENCES `observationType` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entryObservation_beforeInsert` - BEFORE INSERT ON `entryObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entryObservation_beforeUpdate` - BEFORE UPDATE ON `entryObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entryObservation_afterDelete` - AFTER DELETE ON `entryObservation` - FOR EACH ROW -BEGIN - INSERT INTO entryLog - SET `action` = 'delete', - `changedModel` = 'EntryObservation', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `entryType` @@ -28281,7 +30275,7 @@ CREATE TABLE `envialiaCity` ( PRIMARY KEY (`id`), KEY `agencyFk` (`agencyFk`), KEY `postalCode` (`postalCode`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28317,7 +30311,7 @@ CREATE TABLE `errorLogApp` ( `date` datetime DEFAULT NULL, `workerFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Guarda un registro de errores e la app de almacén'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Guarda un registro de errores e la app de almacén'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28341,9 +30335,47 @@ CREATE TABLE `erte` ( `saturday` tinyint(1) DEFAULT NULL, `sunday` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `especialPrice` +-- + +DROP TABLE IF EXISTS `especialPrice`; +/*!50001 DROP VIEW IF EXISTS `especialPrice`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `especialPrice` AS SELECT + 1 AS `id`, + 1 AS `clientFk`, + 1 AS `itemFk`, + 1 AS `value` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `exchangeInsurance` +-- + +DROP TABLE IF EXISTS `exchangeInsurance`; +/*!50001 DROP VIEW IF EXISTS `exchangeInsurance`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `exchangeInsurance` AS SELECT + 1 AS `id`, + 1 AS `amount`, + 1 AS `dated`, + 1 AS `finished`, + 1 AS `entityFk`, + 1 AS `ref`, + 1 AS `rate`, + 1 AS `companyFk`, + 1 AS `financialProductTypefk`, + 1 AS `upperBarrier`, + 1 AS `lowerBarrier`, + 1 AS `strike` */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `exchangeInsuranceEntry` -- @@ -28372,6 +30404,20 @@ SET character_set_client = utf8; 1 AS `rate` */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `exchangeInsuranceInPrevious` +-- + +DROP TABLE IF EXISTS `exchangeInsuranceInPrevious`; +/*!50001 DROP VIEW IF EXISTS `exchangeInsuranceInPrevious`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `exchangeInsuranceInPrevious` AS SELECT + 1 AS `dated`, + 1 AS `amount`, + 1 AS `rate` */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `exchangeInsuranceOut` -- @@ -28386,6 +30432,25 @@ SET character_set_client = utf8; 1 AS `rate` */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `exchangeReportSource` +-- + +DROP TABLE IF EXISTS `exchangeReportSource`; +/*!50001 DROP VIEW IF EXISTS `exchangeReportSource`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `exchangeReportSource` AS SELECT + 1 AS `dated`, + 1 AS `amountIn`, + 1 AS `rateIn`, + 1 AS `amountOut`, + 1 AS `rateOut`, + 1 AS `amountEntry`, + 1 AS `rateEntry`, + 1 AS `rateECB` */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `exchangeReportSourcePrevious` -- @@ -28416,7 +30481,7 @@ CREATE TABLE `excuse` ( `txt` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL, `date` datetime NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28466,124 +30531,8 @@ CREATE TABLE `expedition` ( CONSTRAINT `expedition_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `expedition_ibfk_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`), CONSTRAINT `expedition_itemPackingTypeFk` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeInsert` - BEFORE INSERT ON `expedition` - FOR EACH ROW -BEGIN - DECLARE intcounter INT; - DECLARE vShipFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.freightItemFk IS NOT NULL THEN - - UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk; - - SELECT IFNULL(MAX(counter),0) +1 INTO intcounter - FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id - LEFT JOIN ticketState ts ON ts.ticket = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) - AND t1.warehouseFk = t2.warehouseFk - WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk - AND t1.agencyModeFk = t2.agencyModeFk; - - SET NEW.`counter` = intcounter; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeUpdate` - BEFORE UPDATE ON `expedition` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.counter <> OLD.counter THEN - IF (SELECT COUNT(*) FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) - WHERE t1.id = NEW.ticketFk AND counter = NEW.counter) > 0 THEN - SET NEW.id = NULL; - 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeDelete` - BEFORE DELETE ON `expedition` - FOR EACH ROW -BEGIN - UPDATE ticket t - SET packages = (SELECT COUNT(counter)-1 - FROM expedition e WHERE e.ticketFk = OLD.ticketFk and e.freightItemFk) - WHERE t.id = OLD.ticketFk; - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_afterDelete` - AFTER DELETE ON `expedition` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'Expedition', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `expeditionBoxVol` @@ -28675,36 +30624,8 @@ CREATE TABLE `expeditionPallet` ( PRIMARY KEY (`id`), KEY `expeditionPallet_fk1_idx` (`truckFk`), CONSTRAINT `expeditionPallet_fk1` FOREIGN KEY (`truckFk`) REFERENCES `expeditionTruck` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionPallet_BEFORE_INSERT` - BEFORE INSERT ON `expeditionPallet` - FOR EACH ROW -BEGIN - - DECLARE vNewPosition INT; - - SELECT MAX(position) + 1 INTO vNewPosition - FROM vn.expeditionPallet - WHERE truckFk = NEW.truckFk; - - SET NEW.position = IFNULL(vNewPosition,1); - -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 */ ; -- -- Temporary table structure for view `expeditionPallet_Print` @@ -28780,30 +30701,8 @@ CREATE TABLE `expeditionScan` ( CONSTRAINT `expeditionScan_fk1` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `expeditionScan_fk2` FOREIGN KEY (`palletFk`) REFERENCES `expeditionPallet` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `expeditionScan_fk3` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionScan_BEFORE_INSERT` - BEFORE INSERT ON `expeditionScan` - FOR EACH ROW -BEGIN - - SET NEW.workerFk = vn.getUser(); - -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 */ ; -- -- Temporary table structure for view `expeditionScan_Monitor` @@ -28843,52 +30742,8 @@ CREATE TABLE `expeditionState` ( KEY `expeditionState_FK_1` (`typeFk`), CONSTRAINT `expeditionState_FK` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `expeditionState_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `expeditionStateType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Historico de estados de las expediciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Historico de estados de las expediciones'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionState_BeforeInsert` - BEFORE INSERT ON `expeditionState` - FOR EACH ROW -BEGIN - SET NEW.userFk = IFNULL(NEW.userFk, account.myUser_getId()); -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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER expeditionState_AfterInsert -AFTER INSERT -ON expeditionState FOR EACH ROW -BEGIN - - UPDATE vn.expedition e - SET e.stateTypeFk = NEW.typeFk - WHERE e.id = NEW.expeditionFk; - -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 `expeditionStateType` @@ -28902,7 +30757,7 @@ CREATE TABLE `expeditionStateType` ( `description` varchar(100) NOT NULL, `code` varchar(100) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Posibles estados de una expedición'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Posibles estados de una expedición'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28988,52 +30843,8 @@ CREATE TABLE `expeditionTruck` ( CONSTRAINT `expeditionTruck_FK_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `expeditionTruck_FK_2` FOREIGN KEY (`roadmapFk`) REFERENCES `roadmap` (`id`) ON UPDATE CASCADE, CONSTRAINT `expeditionTruck_FK_3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Distintas paradas que hacen los trocales'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Distintas paradas que hacen los trocales'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionTruck_BEFORE_INSERT` - BEFORE INSERT ON `expeditionTruck` - FOR EACH ROW -BEGIN - - SET NEW.description = UCASE(NEW.description); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionTruck_BEFORE_UPDATE` - BEFORE UPDATE ON `expeditionTruck` - FOR EACH ROW -BEGIN - - SET NEW.description = UCASE(NEW.description); - -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 */ ; -- -- Temporary table structure for view `expeditionTruck_Control` @@ -29110,7 +30921,7 @@ CREATE TABLE `expense` ( `isWithheld` tinyint(4) NOT NULL DEFAULT 0, `code` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `expense_UN` (`code`) + UNIQUE KEY `expence_UN` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29136,7 +30947,7 @@ CREATE TABLE `farming` ( KEY `farmingCompany_Fk` (`companyFk`), CONSTRAINT `farmingCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`), CONSTRAINT `farming_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29175,7 +30986,7 @@ CREATE TABLE `farmingInvoiceIn` ( KEY `farmingInvoiceIn_FK_1` (`farmingFk`), CONSTRAINT `farmingInvoiceIn_FK` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`), CONSTRAINT `farmingInvoiceIn_FK_1` FOREIGN KEY (`farmingFk`) REFERENCES `farming` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29195,7 +31006,7 @@ CREATE TABLE `farmingNotes` ( KEY `farmingNotes_FK_1` (`farmingFk`), CONSTRAINT `farmingNotes_FK` FOREIGN KEY (`id`) REFERENCES `account`.`user` (`id`), CONSTRAINT `farmingNotes_FK_1` FOREIGN KEY (`farmingFk`) REFERENCES `farming` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29247,28 +31058,8 @@ CREATE TABLE `floramondoConfig` ( PRIMARY KEY (`id`), KEY `floramondoConfigWarehouseIn_idx` (`warehouseInFk`), CONSTRAINT `floramondoConfigWarehouseInFk` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`floramondoConfig_AFTER_INSERT` - AFTER INSERT ON `floramondoConfig` - FOR EACH ROW -BEGIN - CALL util.throw ("Tabla config no permite añadir más registros"); -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 `franceExpressConfig` @@ -29281,7 +31072,7 @@ CREATE TABLE `franceExpressConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `path` varchar(100) DEFAULT '\\\\server\\agencies\\franceexpress\\expeditions', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29297,7 +31088,7 @@ CREATE TABLE `fuelType` ( `code` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29312,7 +31103,7 @@ CREATE TABLE `gateArea` ( `name` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29348,7 +31139,7 @@ CREATE TABLE `genericAllocation` ( KEY `genericAllocation_longName_IDX` (`longName`) USING BTREE, KEY `genericAllocation_size_IDX` (`size`) USING BTREE, CONSTRAINT `genericAllocation_FK` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29363,7 +31154,7 @@ CREATE TABLE `genus` ( `name` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `genus_PK2` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29385,7 +31176,7 @@ CREATE TABLE `glsConfig` ( `weight` int(1) DEFAULT NULL, `density` int(11) NOT NULL DEFAULT 42, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29406,6 +31197,20 @@ CREATE TABLE `glsExpedition` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `grantGroup` +-- + +DROP TABLE IF EXISTS `grantGroup`; +/*!50001 DROP VIEW IF EXISTS `grantGroup`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `grantGroup` AS SELECT + 1 AS `id`, + 1 AS `description`, + 1 AS `observationTypeFk` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `greuge` -- @@ -29436,94 +31241,8 @@ CREATE TABLE `greuge` ( CONSTRAINT `greuge_FK_1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `greuge_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `greuges_type_fk` FOREIGN KEY (`greugeTypeFk`) REFERENCES `greugeType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ROW_FORMAT=COMPACT; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`gregue_beforeInsert` - BEFORE INSERT ON greuge - FOR EACH ROW -BEGIN - IF NEW.userFk IS NULL THEN - SET NEW.userFk = account.myUser_getId(); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`greuge_beforeInsert` - BEFORE INSERT ON `greuge` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`greuge_beforeUpdate` - BEFORE UPDATE ON `greuge` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`greuge_afterDelete` - AFTER DELETE ON `greuge` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'Greuge', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `greugeConfig` @@ -29539,7 +31258,7 @@ CREATE TABLE `greugeConfig` ( `maxPercentToWrong` decimal(10,2) DEFAULT NULL COMMENT 'Porcentaje del precio del ticket que es considerado error', `lastNotifyCheck` timestamp NULL DEFAULT NULL COMMENT 'Última ejecución del procedimiento que revisa los greuges anormales', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29554,7 +31273,7 @@ CREATE TABLE `greugeType` ( `name` varchar(45) NOT NULL, `code` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29589,28 +31308,8 @@ CREATE TABLE `host` ( CONSTRAINT `configHost_FK_4` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `configHost_FK_5` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`), CONSTRAINT `hostCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`host_beforeUpdate` - BEFORE UPDATE ON `host` - FOR EACH ROW -BEGIN - SET new.updated = util.VN_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 */ ; -- -- Table structure for table `improvedGeneralLog` @@ -29757,7 +31456,7 @@ CREATE TABLE `inventoryFailure` ( CONSTRAINT `inventoryFailure_fk3` FOREIGN KEY (`guiltyFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk4` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk5` FOREIGN KEY (`causeFk`) REFERENCES `inventoryFailureCause` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29771,7 +31470,7 @@ CREATE TABLE `inventoryFailureCause` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(100) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29831,7 +31530,7 @@ CREATE TABLE `invoiceCorrectionType` ( `description` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `description_UNIQUE` (`description`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29878,12 +31577,12 @@ CREATE TABLE `invoiceIn` ( KEY `recibida_ibfk_6` (`cplusRectificationTypeFk`), KEY `recibida_ibfk_7` (`siiTrascendencyInvoiceInFk`), KEY `invoiceIn_withholdingFk_idx` (`withholdingSageFk`), - KEY `invoiceIn_expenseFkDeductible_idx` (`expenseFkDeductible`), + KEY `invoiceIn_expenceFkDeductible_idx` (`expenseFkDeductible`), KEY `invoiceIn_fk_editor` (`editorFk`), KEY `invoiceIn_FK` (`currencyFk`), CONSTRAINT `invoiceInCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_FK` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON UPDATE CASCADE, - CONSTRAINT `invoiceIn_expenseFkDeductible` FOREIGN KEY (`expenseFkDeductible`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceIn_expenceFkDeductible` FOREIGN KEY (`expenseFkDeductible`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `invoiceIn_ibfk_3` FOREIGN KEY (`cplusSubjectOpFk`) REFERENCES `cplusSubjectOp` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `cplusTaxBreak` (`id`) ON UPDATE CASCADE, @@ -29892,176 +31591,8 @@ CREATE TABLE `invoiceIn` ( CONSTRAINT `invoiceIn_ibfk_7` FOREIGN KEY (`siiTrascendencyInvoiceInFk`) REFERENCES `siiTrascendencyInvoiceIn` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_withholdingFk` FOREIGN KEY (`withholdingSageFk`) REFERENCES `sage`.`TiposRetencion` (`CodigoRetencion`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_bi` - BEFORE INSERT ON `invoiceIn` - FOR EACH ROW -BEGIN - DECLARE vSerie CHAR(1) DEFAULT 'R'; - DECLARE vNumReceived INT; - DECLARE vIssuingCountry, vhostCountry INT; - DECLARE vActive TINYINT; - DECLARE vWithholdingSageFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier - WHERE id = NEW.supplierFk; - - SET NEW.withholdingSageFk = vWithholdingSageFk; - - SELECT countryFk, isActive INTO vIssuingCountry, vActive - FROM vn.supplier - WHERE id = NEW.supplierFk; - - SELECT countryFk INTO vhostCountry - FROM vn.supplier - WHERE id = NEW.companyFk; - - IF vActive = 0 THEN - CALL util.throw('INACTIVE_PROVIDER'); - END IF; - - IF (SELECT COUNT(*) FROM vn.invoiceIn - WHERE supplierRef = NEW.supplierRef - AND supplierFk = NEW.supplierFk - AND YEAR(issued) = YEAR(NEW.issued) - ) THEN - CALL util.throw('reference duplicated'); - END IF; - - SELECT CASE WHEN (SELECT account FROM vn.supplier where id = NEW.supplierFk) LIKE '___3______' THEN 'C' - WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' - WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' - WHEN (SELECT vIssuingCountry<>vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' - END INTO vSerie; - - SET NEW.serial = IFNULL(vSerie,'R'); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_bu` - BEFORE UPDATE ON `invoiceIn` - FOR EACH ROW -BEGIN - - DECLARE vWithholdingSageFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF (SELECT COUNT(*) FROM vn.invoiceIn - WHERE supplierRef = NEW.supplierRef - AND supplierFk = NEW.supplierFk - AND YEAR(issued) = YEAR(NEW.issued) - AND id <> NEW.id - ) THEN - CALL util.throw('reference duplicated'); - END IF; - - IF NEW.supplierFk != OLD.supplierFk THEN - CALL supplier_checkIsActive(NEW.supplierFk); - SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier - WHERE id = NEW.supplierFk; - SET NEW.withholdingSageFk = vWithholdingSageFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_au` - AFTER UPDATE ON `invoiceIn` - FOR EACH ROW -BEGIN - - IF NEW.issued != OLD.issued - OR NEW.currencyFk != OLD.currencyFk THEN - - UPDATE invoiceInTax iit - JOIN invoiceIn ii ON ii.id = iit.invoiceInFk - LEFT JOIN referenceRate rr ON rr.dated = ii.issued - AND rr.currencyFk = ii.currencyFk - SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value) - WHERE ii.id = NEW.id; - - UPDATE invoiceInDueDay iidd - JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk - LEFT JOIN referenceRate rr ON rr.dated = ii.issued - AND rr.currencyFk = ii.currencyFk - SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value) - WHERE ii.id = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_afterDelete` - AFTER DELETE ON `invoiceIn` - FOR EACH ROW -BEGIN - INSERT INTO invoiceInLog - SET `action` = 'delete', - `changedModel` = 'InvoiceIn', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `invoiceInConfig` @@ -30080,7 +31611,7 @@ CREATE TABLE `invoiceInConfig` ( PRIMARY KEY (`id`), KEY `invoiceInConfig_sageWithholdingFk` (`sageWithholdingFk`), CONSTRAINT `invoiceInConfig_sageWithholdingFk` FOREIGN KEY (`sageWithholdingFk`) REFERENCES `sage`.`TiposRetencion` (`CodigoRetencion`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30106,116 +31637,8 @@ CREATE TABLE `invoiceInDueDay` ( CONSTRAINT `invoiceInDueDay_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `invoiceInDueDay_ibfk_6` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInDueDay_ibfk_7` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInDueDay_beforeInsert` - BEFORE INSERT ON `invoiceInDueDay` - FOR EACH ROW -BEGIN - DECLARE vIsNotified BOOLEAN; - - SET NEW.editorFk = account.myUser_getId(); - - SELECT isNotified INTO vIsNotified - FROM vn.invoiceIn ii - JOIN vn.supplier s ON s.id = ii.supplierFk - JOIN vn.payMethod pm ON pm.id = s.payMethodFk - WHERE ii.id = NEW.invoiceInFk; - - IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) - THEN - CALL mail_insert( - 'begonya@verdnatura.es', - 'begonya@verdnatura.es', - 'Añadido vencimiento en el pasado', - CONCAT( - account.myUser_getName(), ' ha añadido un vencimiento de ', - NEW.amount, '€ en una fecha pasada en la recibida ', NEW.invoiceInFk - ) - ); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInDueDay_beforeUpdate` - BEFORE UPDATE ON `invoiceInDueDay` - FOR EACH ROW -BEGIN - DECLARE vIsNotified BOOLEAN; - - SET NEW.editorFk = account.myUser_getId(); - - SELECT isNotified INTO vIsNotified - FROM vn.invoiceIn ii - JOIN vn.supplier s ON s.id = ii.supplierFk - JOIN vn.payMethod pm ON pm.id = s.payMethodFk - WHERE ii.id = NEW.invoiceInFk; - - IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) - THEN - CALL mail_insert( - 'begonya@verdnatura.es', - 'begonya@verdnatura.es', - 'Añadido vencimiento en el pasado', - CONCAT( - account.myUser_getName(), ' ha añadido un vencimiento de ', - NEW.amount,'€ en una fecha pasada en la recibida ',NEW.invoiceInFk - ) - ); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInDueDay_afterDelete` - AFTER DELETE ON `invoiceInDueDay` - FOR EACH ROW -BEGIN - INSERT INTO invoiceInLog - SET `action` = 'delete', - `changedModel` = 'InvoiceInDueDay', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `invoiceInIntrastat` @@ -30239,7 +31662,7 @@ CREATE TABLE `invoiceInIntrastat` ( KEY `invoiceInIntrastat_FK` (`invoiceInFk`), CONSTRAINT `invoiceInIntrastat_FK` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE, CONSTRAINT `invoiceInIntrastat_ibfk_1` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30267,7 +31690,7 @@ CREATE TABLE `invoiceInLog` ( KEY `invoiceInLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `invoiceInLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30294,13 +31717,13 @@ CREATE TABLE `invoiceInSage` ( KEY `invoiceInSage_taxTypeSageFk` (`taxTypeSageFk`), KEY `invoiceInSage_transactionTypeSageFk` (`transactionTypeSageFk`), KEY `invoiceInSage_idx` (`expenseFk`), - CONSTRAINT `invoiceInSage_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_invoiceInSerialFk` FOREIGN KEY (`invoiceInSerialFk`) REFERENCES `invoiceInSerial` (`code`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_taxClassFk` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`code`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_taxTypeSageFk` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_withholdingSageFk` FOREIGN KEY (`withholdingSageFk`) REFERENCES `sage`.`TiposRetencion` (`CodigoRetencion`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relaciones de entrelas series de facturas recibidas y sus tipo de IVA con código Iva y codigo de Transación en Sage. Para precontabilizadar facturas recibidas'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relaciones de entrelas series de facturas recibidas y sus tipo de IVA con código Iva y codigo de Transación en Sage. Para precontabilizadar facturas recibidas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30348,82 +31771,13 @@ CREATE TABLE `invoiceInTax` ( KEY `invoiceInTax_transactionTypeSageFk_idx` (`transactionTypeSageFk`), KEY `invoiceInTax_idx` (`expenseFk`), KEY `invoiceInTax_fk_editor` (`editorFk`), - CONSTRAINT `invoiceInTax_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInTax_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInTax_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `invoiceInTax_ibfk_5` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInTax_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, CONSTRAINT `recibida_iva_taxTypeSageFk` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_beforeInsert` - BEFORE INSERT ON `invoiceInTax` - FOR EACH ROW -BEGIN - CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_beforeUpdate` - BEFORE UPDATE ON `invoiceInTax` - FOR EACH ROW -BEGIN - IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN - CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); - END IF; - - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_afterDelete` - AFTER DELETE ON `invoiceInTax` - FOR EACH ROW -BEGIN - INSERT INTO invoiceInLog - SET `action` = 'delete', - `changedModel` = 'InvoiceInTax', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `invoiceInTaxBookingAccount` @@ -30448,7 +31802,7 @@ CREATE TABLE `invoiceInTaxBookingAccount` ( CONSTRAINT `invoiceInTaxBookingAccount_fk1` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInTaxBookingAccount_fk2` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInTaxBookingAccount_fk3` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30493,113 +31847,8 @@ CREATE TABLE `invoiceOut` ( CONSTRAINT `invoiceOut_serial` FOREIGN KEY (`serial`) REFERENCES `invoiceOutSerial` (`code`), CONSTRAINT `invoice_bank_id` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeInsert` - BEFORE INSERT ON `invoiceOut` - FOR EACH ROW -BEGIN - DECLARE vRef CHAR(10) ; - - IF YEAR(NEW.issued) <= 2021 THEN - - SELECT CONCAT(NEW.serial, - IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , - RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 7,'0')) + 1) INTO vRef - FROM invoiceOut i - LEFT JOIN company c ON c.id = i.companyFk - WHERE i.serial = NEW.serial - AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) - AND c.id = NEW.companyFk; - ELSE - - SELECT CONCAT(NEW.serial, - IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , - RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 8,'0')) + 1) INTO vRef - FROM invoiceOut i - LEFT JOIN company c ON c.id = i.companyFk - WHERE i.serial = NEW.serial - AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) - AND c.id = NEW.companyFk; - END IF; - - SET NEW.ref = vRef; -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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_afterInsert` - AFTER INSERT ON `invoiceOut` - FOR EACH ROW -BEGIN - CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeUpdate` - BEFORE UPDATE ON `invoiceOut` - FOR EACH ROW -BEGIN -CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount); -CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeDelete` - BEFORE DELETE ON `invoiceOut` - FOR EACH ROW -BEGIN - CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount); -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 `invoiceOutConfig` @@ -30612,7 +31861,7 @@ CREATE TABLE `invoiceOutConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parallelism` int(10) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30629,11 +31878,11 @@ CREATE TABLE `invoiceOutExpense` ( `expenseFk` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `created` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), - KEY `invoiceOutExpense_FK_1_idx` (`invoiceOutFk`), - KEY `invoiceOutExpense_expenseFk_idx` (`expenseFk`), - CONSTRAINT `invoiceOutExpense_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `invoiceOutExpense_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; + KEY `invoiceOutExpence_FK_1_idx` (`invoiceOutFk`), + KEY `invoiceOutExpence_expenceFk_idx` (`expenseFk`), + CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `invoiceOutExpence_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */; -- @@ -30679,7 +31928,7 @@ CREATE TABLE `invoiceOutTax` ( KEY `pgcFk` (`pgcFk`), CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30703,7 +31952,7 @@ CREATE TABLE `invoiceOutTaxConfig` ( CONSTRAINT `invoiceOutTaxConfig_FK` FOREIGN KEY (`taxClassCodeFk`) REFERENCES `taxClass` (`code`), CONSTRAINT `invoiceOutTaxConfig_FK_1` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`), CONSTRAINT `invoiceOutTaxConfig_FK_2` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30793,159 +32042,19 @@ CREATE TABLE `item` ( KEY `item_size_IDX` (`size`) USING BTREE, KEY `item_size_IDX2` (`longName`) USING BTREE, KEY `item_lastUsed_IDX` (`lastUsed`) USING BTREE, - KEY `item_expenseFk_idx` (`expenseFk`), + KEY `item_expenceFk_idx` (`expenseFk`), KEY `item_fk_editor` (`editorFk`), CONSTRAINT `item_FK` FOREIGN KEY (`genericFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `item_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `itemType` (`id`), - CONSTRAINT `item_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `item_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_family` FOREIGN KEY (`family`) REFERENCES `itemFamily` (`code`) ON UPDATE CASCADE, CONSTRAINT `item_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `item_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `origin` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_ibfk_2` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE, CONSTRAINT `itemsupplyResponseFk` FOREIGN KEY (`supplyResponseFk`) REFERENCES `edi`.`supplyResponse` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_beforeInsert` - BEFORE INSERT ON `item` - FOR EACH ROW -BEGIN - DECLARE vItemPackingType VARCHAR(1); - - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.itemPackingTypeFk IS NULL THEN - SELECT itemPackingTypeFk INTO vItemPackingType - FROM vn.itemType it - WHERE id = NEW.typeFk; - - SET NEW.itemPackingTypeFk = vItemPackingType; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterInsert` - AFTER INSERT ON `item` - FOR EACH ROW -BEGIN - CALL hedera.image_ref('catalog', NEW.image); - - INSERT INTO vn.itemTaxCountry(itemFk, countryFk) VALUES - (NEW.id, 1), - (NEW.id, 5); - - DELETE ifr.* - FROM edi.item_free ifr - WHERE ifr.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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_beforeUpdate` - BEFORE UPDATE ON `item` - FOR EACH ROW -BEGIN - DECLARE vNewPackingShelve INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF ISNULL(NEW.packingShelve) AND NOT ISNULL(NEW.packingOut) THEN - SELECT NEW.packingOut * vc.shelveVolume / vc.standardFlowerBox - INTO vNewPackingShelve - FROM vn.volumeConfig vc; - - SET NEW.packingShelve = vNewPackingShelve; - END IF; - - IF NEW.itemPackingTypeFk = '' THEN - SET NEW.itemPackingTypeFk = 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterUpdate` - AFTER UPDATE ON `item` - FOR EACH ROW -BEGIN - IF !(NEW.image <=> OLD.image) THEN - CALL hedera.image_unref('catalog', OLD.image); - CALL hedera.image_ref('catalog', NEW.image); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterDelete` - AFTER DELETE ON `item` - FOR EACH ROW -BEGIN - CALL hedera.image_unref('catalog', OLD.image); - - IF OLD.isFloramondo THEN - INSERT IGNORE edi.item_free - SET id = OLD.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 */ ; -- -- Table structure for table `itemBarcode` @@ -30966,72 +32075,8 @@ CREATE TABLE `itemBarcode` ( KEY `itemBarcode_fk_editor` (`editorFk`), CONSTRAINT `itemBarcode_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `itemBarcode_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBarcode_beforeInsert` - BEFORE INSERT ON `itemBarcode` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBarcode_beforeUpdate` - BEFORE UPDATE ON `itemBarcode` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBarcode_afterDelete` - AFTER DELETE ON `itemBarcode` - FOR EACH ROW -BEGIN - INSERT INTO itemLog - SET `action` = 'delete', - `changedModel` = 'ItemBarcode', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `itemBotanical` @@ -31055,70 +32100,6 @@ CREATE TABLE `itemBotanical` ( CONSTRAINT `itemBotanical_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Sustituye a antiguo NomBotanic de Articles'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBotanical_beforeInsert` - BEFORE INSERT ON `itemBotanical` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBotanical_beforeUpdate` - BEFORE UPDATE ON `itemBotanical` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBotanical_afterDelete` - AFTER DELETE ON `itemBotanical` - FOR EACH ROW -BEGIN - INSERT INTO itemLog - SET `action` = 'delete', - `changedModel` = 'ItemBotanical', - `changedModelId` = OLD.itemFk, - `userFk` = account.myUser_getId(); -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 */ ; -- -- Temporary table structure for view `itemBotanicalWithGenus` @@ -31158,31 +32139,8 @@ CREATE TABLE `itemCategory` ( KEY `itemCategoryDisplayIdx` (`display`), KEY `itemCategory_FK` (`departmentFk`), CONSTRAINT `itemCategory_FK` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemCategory_AFTER_INSERT` - AFTER INSERT ON `itemCategory` - FOR EACH ROW -BEGIN - CALL mail_insert('cau@verdnatura.es', - NULL, - CONCAT('Se ha añadido la familia: ', NEW.name), - 'Hay que añadir la familia en el formulario gastos'); -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 `itemCategoryI18n` @@ -31224,7 +32182,7 @@ CREATE TABLE `itemCleanLog` ( `itemDeleted` int(11) DEFAULT NULL COMMENT 'Indica la cantidad de items que ha eliminado', `created` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31289,71 +32247,6 @@ CREATE TABLE `itemCost` ( CONSTRAINT `warehouse_id_rotaci` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena los valores de rotacion en los ultimos 365 dias'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemCost_beforeInsert` - BEFORE INSERT ON `itemCost` - FOR EACH ROW -BEGIN - IF NEW.itemFk IN (95, 98) THEN - SET NEW.cm3 = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemCost_beforeUpdate` - BEFORE UPDATE ON `itemCost` - FOR EACH ROW -BEGIN - IF NEW.itemFk IN (95, 98) THEN - SET NEW.cm3 = 0; - END IF; - - IF !(NEW.cm3delivery <=> OLD.cm3delivery) THEN - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.itemCost ic - JOIN vn.sale s ON s.itemFk = ic.itemFk - JOIN vn.ticket t ON t.id = s.ticketFk AND t.warehouseFk = ic.warehouseFk - JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE - AND ic.itemFk = NEW.itemFk - AND r.created >= util.VN_CURDATE() - GROUP BY r.id; - IF NEW.cm3Delivery = 0 AND NEW.warehouseFk = 60 THEN - CALL mail_insert( - 'jgallego@verdnatura.es', - NULL, - 'update cm3Delivery', - CONCAT('articulo: ', NEW.itemFk)); - 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 */ ; -- -- Temporary table structure for view `itemEntryIn` @@ -31452,7 +32345,7 @@ CREATE TABLE `itemLabel` ( `price` decimal(10,2) DEFAULT NULL, `labels` int(11) DEFAULT NULL COMMENT 'Tabla hecha para Ruben Espinosa, para sacar etiquetas en Holanda para un cliente.', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31480,7 +32373,7 @@ CREATE TABLE `itemLog` ( KEY `itemLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `itemLogItemFk` FOREIGN KEY (`originFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31540,7 +32433,7 @@ CREATE TABLE `itemPlacementSupply` ( 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, CONSTRAINT `itemPlacementSupply_fk4` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31644,141 +32537,8 @@ CREATE TABLE `itemShelving` ( CONSTRAINT `itemShelving_fk1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) 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 `packaging` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_INSERT` - BEFORE INSERT ON `itemShelving` - FOR EACH ROW -BEGIN - - SET NEW.userFk = account.myUser_getId(); - - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_AFTER_INSERT` - AFTER INSERT ON `itemShelving` - FOR EACH ROW -INSERT INTO vn.itemShelvingLog( itemShelvingFk, - workerFk, - accion, - itemFk, - shelvingFk, - visible, - `grouping`, - packing) - VALUES( NEW.id, - NEW.userFk, - 'CREA REGISTRO', - NEW.itemFk, - NEW.shelvingFk, - NEW.visible, - NEW.`grouping`, - NEW.packing - ) */;; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_UPDATE` - BEFORE UPDATE ON `itemShelving` - FOR EACH ROW -BEGIN - IF NEW.userFk IS NULL THEN - SET NEW.userFk = account.myUser_getId(); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_AFTER_UPDATE` - AFTER UPDATE ON `itemShelving` - FOR EACH ROW - - INSERT INTO itemShelvingLog - SET itemShelvingFk = NEW.id, - workerFk = account.myUser_getId(), - accion = 'CAMBIO', - itemFk = NEW.itemFk, - shelvingFk = NEW.shelvingFk, - visible = NEW.visible, - `grouping` = NEW.`grouping`, - packing = NEW.packing */;; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_DELETE` - BEFORE DELETE ON `itemShelving` - FOR EACH ROW -INSERT INTO vn.itemShelvingLog(itemShelvingFk, - workerFk, - accion, - shelvingFk, - itemFk) - VALUES( OLD.id, - account.myUser_getId(), - 'ELIMINADO', - OLD.shelvingFk, - OLD.itemFk) */;; -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 */ ; -- -- Temporary table structure for view `itemShelvingAvailable` @@ -31860,7 +32620,7 @@ CREATE TABLE `itemShelvingLog` ( KEY `itemShelving_Log_FK` (`itemShelvingFk`), KEY `itemShelvingLog_itemFk_IDX` (`itemFk`) USING BTREE, KEY `itemShelvingLog_shelvingFk_IDX` (`shelvingFk`) USING BTREE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31884,7 +32644,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 DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalle de los itemShelving afectados por las ordenes de reposicion de nicho'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalle de los itemShelving afectados por las ordenes de reposicion de nicho'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31933,32 +32693,8 @@ 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 `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelvingSale_fk3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalle del producto que se retira de los carros, relacionando la linea de movimiento correspondiente'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */; -/*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelvingSale_AFTER_INSERT` - AFTER INSERT ON `itemShelvingSale` - FOR EACH ROW -BEGIN - - UPDATE vn.sale - SET isPicked = TRUE - WHERE id = NEW.saleFk; - -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 */ ; -- -- Temporary table structure for view `itemShelvingSaleSum` @@ -32041,20 +32777,6 @@ SET character_set_client = utf8; 1 AS `removed` */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `itemShelvingStock_byWarehouse` --- - -DROP TABLE IF EXISTS `itemShelvingStock_byWarehouse`; -/*!50001 DROP VIEW IF EXISTS `itemShelvingStock_byWarehouse`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `itemShelvingStock_byWarehouse` AS SELECT - 1 AS `itemFk`, - 1 AS `visible`, - 1 AS `warehouseFk` */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `itemTag` -- @@ -32081,144 +32803,8 @@ CREATE TABLE `itemTag` ( CONSTRAINT `itemTagItemFk` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemTagTagFk` FOREIGN KEY (`tagFk`) REFERENCES `tag` (`id`) ON UPDATE CASCADE, CONSTRAINT `itemTag_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_beforeInsert` - BEFORE INSERT ON `itemTag` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - SET NEW.intValue = itemTag_getIntValue(NEW.`value`); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_afterInsert` - AFTER INSERT ON `itemTag` - FOR EACH ROW -trig: BEGIN - IF @isTriggerDisabled THEN - LEAVE trig; - END IF; - - CALL item_refreshFromTags(NEW.itemFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_beforeUpdate` - BEFORE UPDATE ON `itemTag` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF !(OLD.`value` <=> NEW.`value`) - OR !(OLD.intValue <=> NEW.intValue) THEN - SET NEW.intValue = itemTag_getIntValue(NEW.`value`); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_afterUpdate` - AFTER UPDATE ON `itemTag` - FOR EACH ROW -trig: BEGIN - DECLARE vItemFk INT; - DECLARE visTriggerDisabled BOOL; - - SELECT isItemTagTriggerDisabled INTO visTriggerDisabled - FROM vn.itemConfig; - - IF @isTriggerDisabled OR visTriggerDisabled THEN - LEAVE trig; - END IF; - - SET vItemFk = NEW.itemFk; - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - SELECT vItemFk id; - - CALL item_refreshTags(); - DROP TEMPORARY TABLE tmp.item; -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_afterDelete` - AFTER DELETE ON `itemTag` - FOR EACH ROW -trig: BEGIN - INSERT INTO itemLog - SET `action` = 'delete', - `changedModel` = 'ItemTag', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - IF @isTriggerDisabled THEN - LEAVE trig; - END IF; - - CALL item_refreshFromTags(OLD.itemFk); -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 */ ; -- -- Temporary table structure for view `itemTagged` @@ -32255,72 +32841,31 @@ CREATE TABLE `itemTaxCountry` ( CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemTaxCountry_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTaxCountry_beforeInsert` - BEFORE INSERT ON `itemTaxCountry` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTaxCountry_beforeUpdate` - BEFORE UPDATE ON `itemTaxCountry` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTaxCountry_afterDelete` - AFTER DELETE ON `itemTaxCountry` - FOR EACH ROW -BEGIN - INSERT INTO itemLog - SET `action` = 'delete', - `changedModel` = 'ItemTaxCountry', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 */ ; + +-- +-- Temporary table structure for view `itemTaxCountrySpain` +-- + +DROP TABLE IF EXISTS `itemTaxCountrySpain`; +/*!50001 DROP VIEW IF EXISTS `itemTaxCountrySpain`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `itemTaxCountrySpain` AS SELECT + 1 AS `id`, + 1 AS `name`, + 1 AS `typeFk`, + 1 AS `stems`, + 1 AS `description`, + 1 AS `intrastatFk`, + 1 AS `expenseFk`, + 1 AS `comment`, + 1 AS `relevancy`, + 1 AS `image`, + 1 AS `generic`, + 1 AS `taxClassFk` */; +SET character_set_client = @saved_cs_client; -- -- Temporary table structure for view `itemTicketOut` @@ -32393,38 +32938,8 @@ CREATE TABLE `itemType` ( CONSTRAINT `itemType_ibfk_1` FOREIGN KEY (`categoryFk`) REFERENCES `itemCategory` (`id`) ON UPDATE CASCADE, CONSTRAINT `temperatureFk` FOREIGN KEY (`temperatureFk`) REFERENCES `temperature` (`code`), CONSTRAINT `warehouseFk5` FOREIGN KEY (`warehouseFk__`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemType_beforeUpdate` - BEFORE UPDATE ON `itemType` - FOR EACH ROW -BEGIN - IF NEW.itemPackingTypeFk = '' THEN - - SET NEW.itemPackingTypeFk = NULL; - - END IF; - - IF NEW.itemPackingTypeFk != OLD.itemPackingTypeFk THEN - UPDATE vn.item - SET itemPackingTypeFk = NEW.itemPackingTypeFk - WHERE typeFk = 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 */ ; -- -- Table structure for table `itemTypeI18n` @@ -32470,7 +32985,7 @@ CREATE TABLE `itemTypeRestriction` ( UNIQUE KEY `itemTypeRestriction_UN` (`itemTypeFk`,`dated`), KEY `itemTypeRestriction_dated_IDX` (`dated`,`itemTypeFk`) USING BTREE, CONSTRAINT `itemTypeRestriction_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32491,7 +33006,7 @@ CREATE TABLE `itemTypeTag` ( KEY `itemTypeTagTag_idx` (`tagFk`), CONSTRAINT `itemTypeTagTag` FOREIGN KEY (`tagFk`) REFERENCES `tag` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `itemTypeTag_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32667,30 +33182,8 @@ CREATE TABLE `machine` ( CONSTRAINT `machine_FK` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `machine_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `machine_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Maquinaria industrial, vehículos y demás elementos amortizables'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Maquinaria industrial, vehículos y demás elementos amortizables'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`machine_BI` - BEFORE INSERT ON `machine` - FOR EACH ROW -BEGIN - - SET NEW.workerFk = vn.getUser(); - -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 `machineDetail` @@ -32714,7 +33207,7 @@ CREATE TABLE `machineDetail` ( CONSTRAINT `machineDetail_FK` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `machineDetail_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `machineDetail_FK_2` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32733,7 +33226,7 @@ CREATE TABLE `machineDms` ( KEY `machineDms_FK` (`dmsFk`), CONSTRAINT `machineDms_FK` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `machineDms_FK_1` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32754,7 +33247,7 @@ CREATE TABLE `machineWorker` ( KEY `machineWorker_FK` (`workerFk`), CONSTRAINT `machineWorker_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `machineWorker_FK_1` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Registros horarios de vehículos de almacén por empleado'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Registros horarios de vehículos de almacén por empleado'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32768,7 +33261,7 @@ CREATE TABLE `machineWorkerConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `maxHours` smallint(5) unsigned NOT NULL COMMENT 'Indicates how many hours a user record is reviewed to update or insert', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32799,34 +33292,8 @@ CREATE TABLE `mail` ( KEY `mail_FK` (`senderFk`), CONSTRAINT `mail_FK` FOREIGN KEY (`senderFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, CONSTRAINT `mail_FK_1` FOREIGN KEY (`recipientFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`mail_beforeInsert` - BEFORE INSERT ON `mail` - FOR EACH ROW -BEGIN - - IF NEW.sender IS NOT NULL THEN - - SET NEW.receiver = NEW.sender; - - 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 */ ; -- -- Table structure for table `mailTemplates` @@ -32840,7 +33307,7 @@ CREATE TABLE `mailTemplates` ( `name` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `attachmentPath` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32865,32 +33332,8 @@ CREATE TABLE `mandate` ( CONSTRAINT `mandateCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey3` FOREIGN KEY (`mandateTypeFk`) REFERENCES `mandateType` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`mandate_beforeInsert` - BEFORE INSERT ON `mandate` - FOR EACH ROW -BEGIN - IF (NEW.code IS NULL) THEN - SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT - FROM information_schema.TABLES - WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); - 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 */ ; -- -- Table structure for table `mandateType` @@ -32903,7 +33346,7 @@ CREATE TABLE `mandateType` ( `id` smallint(5) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32920,7 +33363,7 @@ CREATE TABLE `manuscript` ( `enabled` tinyint(1) NOT NULL DEFAULT 1, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32970,7 +33413,7 @@ CREATE TABLE `mdbConfig` ( `issueNumberRegex` varchar(255) NOT NULL, `chatDestination` varchar(255) NOT NULL COMMENT 'User (@) or channel (#) to send the message', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters for Access'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Global configuration parameters for Access'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33024,7 +33467,7 @@ CREATE TABLE `medicalCenter` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33049,7 +33492,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 `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33070,7 +33513,7 @@ CREATE TABLE `message` ( KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33092,7 +33535,7 @@ CREATE TABLE `messageInbox` ( PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33144,7 +33587,7 @@ CREATE TABLE `mistakeType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33164,7 +33607,7 @@ CREATE TABLE `mobileAppVersionControl` ( `versionBeta` varchar(45) DEFAULT NULL, `isVersionBetaCritical` tinyint(1) DEFAULT 0, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla para llevar el control de las Versions de las aplicaciones móvil '; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla para llevar el control de las Versions de las aplicaciones móvil '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33181,7 +33624,7 @@ CREATE TABLE `mrw` ( `shipped` date DEFAULT NULL, `price` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33251,7 +33694,7 @@ CREATE TABLE `noticeCategory` ( `requiredRole` int(11) NOT NULL DEFAULT 1, PRIMARY KEY (`id`), UNIQUE KEY `keyName_UNIQUE` (`keyName`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33284,7 +33727,7 @@ CREATE TABLE `observationType` ( `code` varchar(45) NOT NULL, `hasNewBornMessage` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indica aquellos que deben de recibir un mensaje advirtiendo de un cliente nuevo', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33322,55 +33765,15 @@ CREATE TABLE `operator` ( KEY `operator_FK_2` (`itemPackingTypeFk`), KEY `operator_FK_3` (`warehouseFk`), KEY `operator_FK_5` (`labelerFk`), + KEY `operator_FK_4` (`sectorFk`), CONSTRAINT `operator_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `operator_FK_1` FOREIGN KEY (`trainFk`) REFERENCES `train` (`id`) ON UPDATE CASCADE, CONSTRAINT `operator_FK_2` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `operator_FK_3` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `operator_FK_4` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON UPDATE CASCADE, CONSTRAINT `operator_FK_5` FOREIGN KEY (`labelerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`operator_beforeInsert` - BEFORE INSERT ON `operator` - FOR EACH ROW -BEGIN - CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`operator_beforeUpdate` - BEFORE UPDATE ON `operator` - FOR EACH ROW -BEGIN - IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN - CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); - 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 */ ; -- -- Temporary table structure for view `operatorWorkerCode` @@ -33422,7 +33825,7 @@ CREATE TABLE `origin` ( KEY `warehouse_id` (`warehouseFk`), KEY `Id_Paises` (`countryFk`), CONSTRAINT `origin_ibfk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33509,7 +33912,7 @@ CREATE TABLE `packageChecked` ( PRIMARY KEY (`id`), UNIQUE KEY `entryFk_UNIQUE` (`itemFk`), KEY `fkItem_idx` (`itemFk`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33584,46 +33987,6 @@ CREATE TABLE `packaging` ( CONSTRAINT `packaging_fk2` FOREIGN KEY (`freightItemFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packaging_beforeInsert` - BEFORE INSERT ON `packaging` - FOR EACH ROW -BEGIN - SET NEW.value = packaging_calculate(NEW.isPackageReturnable, NEW.packagingReturnFk, NEW.base, NEW.price, NEW.upload); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packaging_beforeUpdate` - BEFORE UPDATE ON `packaging` - FOR EACH ROW -BEGIN - SET NEW.value = packaging_calculate(NEW.isPackageReturnable, NEW.packagingReturnFk, NEW.base, NEW.price, NEW.upload); -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 `packagingConfig` @@ -33647,7 +34010,7 @@ CREATE TABLE `packagingConfig` ( KEY `packagingConfig_FK_1` (`defaultBigPackageFk`), CONSTRAINT `packagingConfig_FK` FOREIGN KEY (`defaultSmallPackageFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE, CONSTRAINT `packagingConfig_FK_1` FOREIGN KEY (`defaultBigPackageFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Altura mínima para preparar pedidos en preparacion previa'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Altura mínima para preparar pedidos en preparacion previa'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33673,7 +34036,7 @@ CREATE TABLE `packagingGifts` ( CONSTRAINT `PackagingGifts_FK` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`), CONSTRAINT `PackagingGifts_FK_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`), CONSTRAINT `PackagingGifts_FK_2` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33743,72 +34106,8 @@ CREATE TABLE `packingSite` ( CONSTRAINT `packingSite_FK_4` FOREIGN KEY (`printerRfidFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE, CONSTRAINT `packingSite_FK_5` FOREIGN KEY (`scannerFk`) REFERENCES `scanner` (`id`) ON UPDATE CASCADE, CONSTRAINT `packingSite_FK_6` FOREIGN KEY (`screenFk`) REFERENCES `screen` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packingSite_beforeInsert` - BEFORE INSERT ON `packingSite` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packingSite_beforeUpdate` - BEFORE UPDATE ON `packingSite` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packingSite_afterDelete` - AFTER DELETE ON `packingSite` - FOR EACH ROW -BEGIN - INSERT INTO packingSiteDeviceLog - SET `action` = 'delete', - `changedModel` = 'PackingSite', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `packingSiteAdvanced` @@ -33841,7 +34140,7 @@ CREATE TABLE `packingSiteConfig` ( `shinobiGroupKey` varchar(255) NOT NULL, `avgBoxingTime` int(3) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33898,7 +34197,7 @@ CREATE TABLE `packingSiteLog` ( CONSTRAINT `packingSiteLog_FK_1` FOREIGN KEY (`printerModelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE, CONSTRAINT `packingSiteLog_FK_2` FOREIGN KEY (`packingSiteFk`) REFERENCES `packingSite` (`code`) ON UPDATE CASCADE, CONSTRAINT `packingSiteLog_FK_4` FOREIGN KEY (`typeErrorFk`) REFERENCES `packingSiteTypeError` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33948,52 +34247,8 @@ 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=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla con los parkings del altillo'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`parking_BEFORE_INSERT` - BEFORE INSERT ON `parking` - FOR EACH ROW -BEGIN - - -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`parking_BEFORE_UPDATE` - BEFORE UPDATE ON `parking` - FOR EACH ROW -BEGIN - - -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; - -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 `payDem` @@ -34006,7 +34261,7 @@ CREATE TABLE `payDem` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `payDem` varchar(15) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34043,7 +34298,7 @@ CREATE TABLE `payMethod` ( `hasVerified` tinyint(1) DEFAULT 0, `graceMonthsDisableChecked` int(11) unsigned NOT NULL DEFAULT 0 COMMENT 'Deshabilita la comprobación de los datos bancarios de todos aquellos proveedores que no hayan recibido un pago en los meses especificados', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34083,178 +34338,31 @@ CREATE TABLE `payment` ( CONSTRAINT `payment_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`), CONSTRAINT `payment_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `payment_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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`@`localhost`*/ /*!50003 TRIGGER `payment_beforeInsert` BEFORE INSERT ON `payment` FOR EACH ROW -BEGIN - DECLARE cuenta_banco,cuenta_proveedor DOUBLE; - DECLARE vNewBookEntry INT; - DECLARE bolCASH BOOLEAN; - DECLARE isSupplierActive BOOLEAN; - -- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH - SELECT (at2.code = 'cash') INTO bolCASH - FROM vn.bank b - JOIN vn.accountingType at2 ON at2.id = b.cash - WHERE b.id = NEW.bankFk; +-- +-- Temporary table structure for view `paymentExchangeInsurance` +-- - IF bolCASH THEN - - SELECT account INTO cuenta_banco - FROM bank - WHERE id = NEW.bankFk; - - SELECT account INTO cuenta_proveedor - FROM supplier - WHERE id = NEW.supplierFk; - - CALL vn.ledger_next(vNewBookEntry); - - INSERT INTO XDiario ( ASIEN, - FECHA, - SUBCTA, - CONTRA, - CONCEPTO, - EURODEBE, - EUROHABER, - empresa_id) - SELECT vNewBookEntry, - NEW.received, - SUBCTA, - CONTRA, - NEW.concept, - EURODEBE, - EUROHABER, - NEW.companyFk - FROM ( SELECT cuenta_banco SUBCTA, - cuenta_proveedor CONTRA, - 0 EURODEBE, - NEW.amount + NEW.bankingFees EUROHABER - UNION ALL - SELECT cuenta_proveedor SUBCTA, - cuenta_banco CONTRA, - NEW.amount EURODEBE, - 0 EUROHABER) gf; - - IF NEW.bankingFees <> 0 THEN - INSERT INTO XDiario ( ASIEN, - FECHA, - SUBCTA, - CONTRA, - CONCEPTO, - EURODEBE, - EUROHABER, - empresa_id) - SELECT vNewBookEntry, - NEW.received, - IF(c.id = 1,6260000002, - IF(CEE = 1,6260000003,6260000004)), - cuenta_banco, - NEW.concept, - NEW.bankingFees, - 0, - NEW.companyFk - FROM supplier s - JOIN country c ON s.countryFk = c.id - WHERE s.id = NEW.supplierFk; - END IF; - END IF; - - SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received); - - SELECT isActive INTO isSupplierActive - FROM supplier - WHERE id = NEW.supplierFk; - - IF isSupplierActive = FALSE THEN - CALL util.throw('SUPPLIER_INACTIVE'); - END IF; - - IF ISNULL(NEW.workerFk) THEN - SET NEW.workerFk = account.myUser_getId(); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`payment_afterInsert` - AFTER INSERT ON `payment` - FOR EACH ROW -BEGIN - DECLARE vIsPayMethodChecked BOOLEAN; - DECLARE vEmail VARCHAR(150); - - SELECT isPayMethodChecked INTO vIsPayMethodChecked - FROM supplier - WHERE id = NEW.supplierFk; - - - IF vIsPayMethodChecked = FALSE THEN - - SELECT notificationEmail INTO vEmail - FROM department - WHERE name = 'FINANZAS'; - - CALL mail_insert( - vEmail, - NULL, - 'Pago con método sin verificar', - CONCAT( - 'Se ha realizado el pago ', - NEW.id, - ' al proveedor ', - NEW.supplierFk, - ' con el método de pago sin verificar.' - ) - ); - 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`@`localhost`*/ /*!50003 TRIGGER payment_beforeUpdate BEFORE UPDATE ON payment FOR EACH ROW -BEGIN - IF ISNULL(NEW.workerFk) THEN - SET NEW.workerFk = account.myUser_getId(); - 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 */ ; +DROP TABLE IF EXISTS `paymentExchangeInsurance`; +/*!50001 DROP VIEW IF EXISTS `paymentExchangeInsurance`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `paymentExchangeInsurance` AS SELECT + 1 AS `id`, + 1 AS `amount`, + 1 AS `created`, + 1 AS `dueDay`, + 1 AS `entityFk`, + 1 AS `ref`, + 1 AS `rate`, + 1 AS `companyFk`, + 1 AS `financialProductTypefk`, + 1 AS `upperBarrier`, + 1 AS `lowerBarrier`, + 1 AS `strike` */; +SET character_set_client = @saved_cs_client; -- -- Table structure for table `payrollCategories` @@ -34271,6 +34379,25 @@ CREATE TABLE `payrollCategories` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `payrollCenter` +-- + +DROP TABLE IF EXISTS `payrollCenter`; +/*!50001 DROP VIEW IF EXISTS `payrollCenter`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `payrollCenter` AS SELECT + 1 AS `codCenter`, + 1 AS `name`, + 1 AS `nss`, + 1 AS `street`, + 1 AS `city`, + 1 AS `postcode`, + 1 AS `companyFk`, + 1 AS `companyCode` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `pcs` -- @@ -34285,7 +34412,7 @@ CREATE TABLE `pcs` ( `pallet` int(11) DEFAULT NULL, `box` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34322,7 +34449,7 @@ CREATE TABLE `pedidosInternos` ( `idArticle` int(11) DEFAULT NULL, `quantity` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34490,97 +34617,6 @@ CREATE TABLE `postCode` ( CONSTRAINT `postCodeTownFk` FOREIGN KEY (`townFk`) REFERENCES `town` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_beforeInsert` - BEFORE INSERT ON `postCode` - FOR EACH ROW -BEGIN - SET NEW.geoFk = zoneGeo_new('postCode', NEW.`code`, - (SELECT geoFk FROM town WHERE id = NEW.townFk)); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_beforeUpdate` - BEFORE UPDATE ON `postCode` - FOR EACH ROW -BEGIN - -- IF !(OLD.geoFk <=> NEW.geoFk) THEN - -- CALL zoneGeo_throwNotEditable; - -- 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_afterUpdate` - AFTER UPDATE ON `postCode` - FOR EACH ROW -BEGIN - IF !(OLD.townFk <=> NEW.townFk) THEN - CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM town WHERE id = NEW.townFk)); - END IF; - - IF !(OLD.`code` <=> NEW.`code`) THEN - UPDATE zoneGeo SET `name` = NEW.`code` - WHERE id = NEW.geoFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_afterDelete` - AFTER DELETE ON `postCode` - FOR EACH ROW -BEGIN - CALL zoneGeo_delete(OLD.geoFk); -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 `ppe` @@ -34628,7 +34664,7 @@ CREATE TABLE `ppe` ( CONSTRAINT `ppe_fk5` FOREIGN KEY (`account`) REFERENCES `pgcMaster` (`code`) ON UPDATE CASCADE, CONSTRAINT `ppe_fk6` FOREIGN KEY (`endowment`) REFERENCES `pgcMaster` (`code`) ON UPDATE CASCADE, CONSTRAINT `ppe_fk7` FOREIGN KEY (`elementAccount`) REFERENCES `pgcMaster` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Property, plant & equipment\nInmvolizado, en español'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Property, plant & equipment\nInmvolizado, en español'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34648,7 +34684,7 @@ CREATE TABLE `ppeComponent` ( KEY `ppeComponent_fk2_idx` (`invoiceInFk`), CONSTRAINT `ppeComponent_fk1` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ppeComponent_fk2` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34667,7 +34703,7 @@ CREATE TABLE `ppeDMS` ( KEY `ppeDMS_fk2_idx` (`ppeFk`), CONSTRAINT `ppeDMS_fk1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ppeDMS_fk2` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34681,7 +34717,7 @@ CREATE TABLE `ppeGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tipo de inmovilizado'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tipo de inmovilizado'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34710,9 +34746,23 @@ CREATE TABLE `ppePlan` ( `rate` decimal(3,2) NOT NULL DEFAULT 1.00, `days` int(11) NOT NULL DEFAULT 365, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Plan de amortizacion para la tabla ppe'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Plan de amortizacion para la tabla ppe'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `preparationException` +-- + +DROP TABLE IF EXISTS `preparationException`; +/*!50001 DROP VIEW IF EXISTS `preparationException`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `preparationException` AS SELECT + 1 AS `exceptionDay`, + 1 AS `warehouseFk`, + 1 AS `percentage` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `priceFixed` -- @@ -34743,58 +34793,8 @@ CREATE TABLE `priceFixed` ( KEY `warehouse_id` (`warehouseFk`), CONSTRAINT `priceFixed_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `priceFixed_ibfk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`priceFixed_beforeInsert` - BEFORE INSERT ON `priceFixed` - FOR EACH ROW -BEGIN - DECLARE vDated DATE; - IF NEW.started > NEW.ended THEN - SET vDated = NEW.started; - SET NEW.started = NEW.ended; - SET NEW.ended = vDated; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`priceFixed_beforeUpdate` - BEFORE UPDATE ON `priceFixed` - FOR EACH ROW -BEGIN - DECLARE vDated DATE; - IF NEW.started > NEW.ended THEN - SET vDated = NEW.started; - SET NEW.started = NEW.ended; - SET NEW.ended = vDated; - 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 */ ; -- -- Table structure for table `printQueue` @@ -34825,7 +34825,7 @@ CREATE TABLE `printQueue` ( CONSTRAINT `printQueue_printerFk` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE, CONSTRAINT `printQueue_priorityFk` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE, CONSTRAINT `printQueue_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34889,7 +34889,7 @@ CREATE TABLE `printer` ( CONSTRAINT `printer_FK` FOREIGN KEY (`modelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE, CONSTRAINT `printer_FK_1` FOREIGN KEY (`paperSizeFk`) REFERENCES `paperSize` (`code`), CONSTRAINT `printer_sectorFk` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34934,7 +34934,7 @@ CREATE TABLE `producer` ( `created` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34966,9 +34966,12 @@ CREATE TABLE `productionConfig` ( `orderMode` enum('Location','Age') NOT NULL DEFAULT 'Location', `stockScopeDays` int(11) DEFAULT 1 COMMENT 'Días a futuro al revisar el stock', `shortageAddressFk` int(11) DEFAULT NULL COMMENT 'Consignatario por defecto para añadir un item de alta', + `clientSelfConsumptionFk` int(11) DEFAULT NULL COMMENT 'Cliente para crear el ticket de autoconsumo', PRIMARY KEY (`id`), KEY `productionConfig_FK` (`shortageAddressFk`), - CONSTRAINT `productionConfig_FK` FOREIGN KEY (`shortageAddressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE + KEY `productionConfig_FK_1` (`clientSelfConsumptionFk`), + CONSTRAINT `productionConfig_FK` FOREIGN KEY (`shortageAddressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, + CONSTRAINT `productionConfig_FK_1` FOREIGN KEY (`clientSelfConsumptionFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los parámetros que condicionan la producción'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -34994,7 +34997,7 @@ CREATE TABLE `productionError` ( `hourWorked` varchar(100) DEFAULT NULL, `dated` date DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35040,7 +35043,7 @@ CREATE TABLE `professionalCategory` ( `dayBreak` int(11) unsigned DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `prefessionalCategory_UN` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35054,7 +35057,7 @@ CREATE TABLE `profileType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(15) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35086,7 +35089,7 @@ CREATE TABLE `project` ( CONSTRAINT `project_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `project_FK_1` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `project_FK_3` FOREIGN KEY (`stateFk`) REFERENCES `projectState` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla master de proyectos'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla master de proyectos'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35107,34 +35110,8 @@ CREATE TABLE `projectNotes` ( KEY `projectNotes_FK_1` (`userFk`), CONSTRAINT `projectNotes_FK` FOREIGN KEY (`projectFk`) REFERENCES `project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `projectNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Historico de notas para project'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Historico de notas para project'; /*!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 = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER projectNotes_BeforeInsert -BEFORE INSERT -ON projectNotes FOR EACH ROW -BEGIN - - IF ISNULL(NEW.userFk) THEN - - SET NEW.userFk = account.myUser_getId(); - - 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 */ ; -- -- Table structure for table `projectState` @@ -35150,6 +35127,20 @@ CREATE TABLE `projectState` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `promissoryNote` +-- + +DROP TABLE IF EXISTS `promissoryNote`; +/*!50001 DROP VIEW IF EXISTS `promissoryNote`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `promissoryNote` AS SELECT + 1 AS `id`, + 1 AS `Concept`, + 1 AS `paymentFk` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `property` -- @@ -35191,7 +35182,7 @@ CREATE TABLE `property` ( CONSTRAINT `propertySupplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, CONSTRAINT `property_FK` FOREIGN KEY (`propertyGroupFk`) REFERENCES `propertyGroup` (`id`) ON UPDATE CASCADE, CONSTRAINT `property_FK_1` FOREIGN KEY (`townFk`) REFERENCES `town` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35210,7 +35201,7 @@ CREATE TABLE `propertyDms` ( KEY `propertyDms_FK_1` (`propertyFk`), CONSTRAINT `propertyDms_FK` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `propertyDms_FK_1` FOREIGN KEY (`propertyFk`) REFERENCES `property` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35224,7 +35215,7 @@ CREATE TABLE `propertyGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(100) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35245,7 +35236,7 @@ CREATE TABLE `propertyNotes` ( KEY `propertyNotes_FK` (`propertyFk`), CONSTRAINT `propertyNotes_FK` FOREIGN KEY (`propertyFk`) REFERENCES `property` (`id`), CONSTRAINT `propertyNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35273,107 +35264,8 @@ CREATE TABLE `province` ( CONSTRAINT `province_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `vn2008`.`zones` (`zone_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `warehouse_Id` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_beforeInsert` - BEFORE INSERT ON `province` - FOR EACH ROW -BEGIN - - SET NEW.geoFk = zoneGeo_new('province', NEW.`name`, - (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); - - SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_beforeUpdate` - BEFORE UPDATE ON `province` - FOR EACH ROW -BEGIN - - IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN - - SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate` - AFTER UPDATE ON `province` - FOR EACH ROW -BEGIN - IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN - CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); - END IF; - - IF !(OLD.`name` <=> NEW.`name`) THEN - UPDATE zoneGeo SET `name` = NEW.`name` - WHERE id = NEW.geoFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterDelete` - AFTER DELETE ON `province` - FOR EACH ROW -BEGIN - CALL zoneGeo_delete(OLD.geoFk); -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 `punchState` @@ -35439,72 +35331,8 @@ CREATE TABLE `rate` ( KEY `rate_fk_editor` (`editorFk`), CONSTRAINT `rate_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `tarifa_warehouse` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`rate_beforeInsert` - BEFORE INSERT ON `rate` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`rate_beforeUpdate` - BEFORE UPDATE ON `rate` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`rate_afterDelete` - AFTER DELETE ON `rate` - FOR EACH ROW -BEGIN - INSERT INTO rateLog - SET `action` = 'delete', - `changedModel` = 'Rate', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `rateConfig` @@ -35548,7 +35376,7 @@ CREATE TABLE `rateLog` ( KEY `rateLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `rateOriginFk` FOREIGN KEY (`originFk`) REFERENCES `rate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `rateUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35580,122 +35408,8 @@ CREATE TABLE `receipt` ( CONSTRAINT `receiptWorkerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `receipt_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibo_customer_id` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert` - BEFORE INSERT ON `receipt` - FOR EACH ROW -BEGIN - DECLARE vIsAutoConciliated BOOLEAN; - - IF NEW.isConciliate = FALSE THEN - SELECT isAutoConciliated INTO vIsAutoConciliated - FROM accounting a - JOIN accountingType at2 ON at2.id = a.accountingTypeFk - WHERE a.id = NEW.bankFk; - - SET NEW.isConciliate = vIsAutoConciliated; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterInsert` - AFTER INSERT ON `receipt` - FOR EACH ROW -CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid) */;; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeUpdate` - BEFORE UPDATE ON `receipt` - FOR EACH ROW -BEGIN - CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid); - CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid); - SET NEW.workerFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` - AFTER UPDATE ON `receipt` - FOR EACH ROW -BEGIN - IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN - CALL mail_insert( - 'finanzas@verdnatura.es', - NULL, - CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), - CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) - ); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeDelete` - BEFORE DELETE ON `receipt` - FOR EACH ROW -CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid) */;; -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 `recipe` @@ -35720,7 +35434,7 @@ CREATE TABLE `recipe` ( KEY `recipe_ix_2` (`itemFk`), KEY `recipe_FK` (`inkFk`), CONSTRAINT `recipe_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35741,7 +35455,7 @@ CREATE TABLE `recipe_log` ( KEY `recipe_log_ix3` (`selected_ItemFk`), CONSTRAINT `recipe_log_FK` FOREIGN KEY (`recipe_ItemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE, CONSTRAINT `recipe_log_FK_1` FOREIGN KEY (`selected_ItemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena las decisiones tomadas al generar recetas'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena las decisiones tomadas al generar recetas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35765,72 +35479,8 @@ CREATE TABLE `recovery` ( CONSTRAINT `cliente333` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, CONSTRAINT `cliente_cliente` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, CONSTRAINT `recovery_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla apuntaremos los acuerdos de recobro semanal a '; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla apuntaremos los acuerdos de recobro semanal a '; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`recovery_beforeInsert` - BEFORE INSERT ON `recovery` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`recovery_beforeUpdate` - BEFORE UPDATE ON `recovery` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`recovery_afterDelete` - AFTER DELETE ON `recovery` - FOR EACH ROW -BEGIN - INSERT INTO clientLog - SET `action` = 'delete', - `changedModel` = 'Recovery', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `referenceCurrent` @@ -35893,7 +35543,7 @@ CREATE TABLE `report` ( PRIMARY KEY (`id`), KEY `report_FK` (`paperSizeFk`), CONSTRAINT `report_FK` FOREIGN KEY (`paperSizeFk`) REFERENCES `paperSize` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35909,7 +35559,7 @@ CREATE TABLE `returnBuckets` ( `freightPackagingEmpty` double NOT NULL DEFAULT 0, `freightPackagingFull` double NOT NULL DEFAULT 0, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35955,6 +35605,23 @@ SET character_set_client = utf8; 1 AS `hasLogin` */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `roleCreditLimit` +-- + +DROP TABLE IF EXISTS `roleCreditLimit`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `roleCreditLimit` ( + `id` int(11) NOT NULL, + `maxAmount` int(10) unsigned NOT NULL, + `roleFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `clientCreditLimit_FK_idx` (`roleFk`), + CONSTRAINT `roleCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `route` -- @@ -35965,6 +35632,7 @@ DROP TABLE IF EXISTS `route`; CREATE TABLE `route` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `workerFk` int(10) unsigned DEFAULT NULL, + `firstEditorFk` int(10) unsigned NOT NULL COMMENT 'Usuario creador de la ruta', `created` date NOT NULL, `vehicleFk` int(10) unsigned DEFAULT NULL, `agencyModeFk` int(11) DEFAULT NULL, @@ -36001,172 +35669,8 @@ CREATE TABLE `route` ( CONSTRAINT `route_ibfk_1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `route_ibfk_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `route_invoiceInFk` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_beforeInsert` - BEFORE INSERT ON `route` - FOR EACH ROW -BEGIN - DECLARE vDefaultAgencyModeFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - SET NEW.commissionWorkCenterFk = ( - SELECT IFNULL(b.workCenterFK, r.defaultWorkCenterFk) - FROM vn.routeConfig r - LEFT JOIN vn.business b ON b.workerFk = account.myUser_getId() - AND NEW.created BETWEEN b.started AND IFNULL(b.ended, NEW.created)); - - IF ISNULL(NEW.agencyModeFk) THEN - SELECT r.agencyModeFk INTO vDefaultAgencyModeFk - FROM routeDefaultAgencyMode r - JOIN business b ON b.workCenterFk = r.workCenterFK - JOIN worker w ON w.businessFk = b.id - WHERE b.workerFk = account.myUser_getId(); - - SET NEW.agencyModeFk = vDefaultAgencyModeFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterInsert` - AFTER INSERT ON `route` - FOR EACH ROW -BEGIN - CALL route_calcCommission(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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_beforeUpdate` - BEFORE UPDATE ON `route` - FOR EACH ROW -BEGIN - DECLARE vKmMax INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.isOk <> FALSE AND OLD.isOk = FALSE THEN - SET NEW.m3 = ( SELECT SUM(litros)/1000 - FROM vn.saleVolume s - JOIN vn.ticket t ON s.ticketFk = t.id - WHERE t.routeFk = NEW.id); - END IF; - - IF NEW.kmEnd < NEW.kmStart AND NEW.kmEnd <> 0 THEN - CALL util.throw ('KmEnd menor que kmStart'); - END IF; - - SELECT kmMax INTO vKmMax - FROM routeConfig rc; - - IF ((NEW.kmEnd - NEW.kmStart) > vKmMax) AND NEW.kmEnd <> 0 THEN - CALL util.throw (CONCAT('The km can not exceed ', vKmMax)); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterUpdate` - AFTER UPDATE ON `route` - FOR EACH ROW -BEGIN - IF IFNULL(NEW.gestdocFk,0) <> IFNULL(OLD.gestdocFk,0) AND NEW.gestdocFk > 0 THEN - -- JGF 09/09/14 cuando se añade un gestdoc a una ruta, se le asigna automagicamente a todos sus Tickets - - -- Inserta el gestdoc en todos los tickets de la ruta - INSERT INTO ticketDms(ticketFk,dmsFk) - SELECT id, NEW.gestdocFk FROM ticket WHERE routeFk = NEW.id - ON DUPLICATE KEY UPDATE dmsFk = NEW.gestdocFk; - - -- Update del firmado - UPDATE ticket t - JOIN ticketDms tg ON t.id = tg.ticketFk - SET isSigned = 1 WHERE t.routeFk = NEW.id; - END IF; - - IF !(NEW.kmStart <=> OLD.kmStart) - OR !(NEW.kmEnd <=> OLD.kmEnd) - OR !(NEW.workerFk <=> OLD.workerFk) - OR !(NEW.m3 <=> OLD.m3) - OR !(NEW.agencyModeFk <=> OLD.agencyModeFk)THEN - CALL route_calcCommission(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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterDelete` - AFTER DELETE ON `route` - FOR EACH ROW -BEGIN - INSERT INTO routeLog - SET `action` = 'delete', - `changedModel` = 'Route', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `routeAction` @@ -36181,7 +35685,7 @@ CREATE TABLE `routeAction` ( `price` decimal(10,2) DEFAULT NULL, `isMainlineDelivered` tinyint(4) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36195,6 +35699,7 @@ CREATE TABLE `routeCommission` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `routeFk` int(10) unsigned NOT NULL, `workCenterFk` int(11) DEFAULT NULL, + `firstEditorFk` int(10) unsigned NOT NULL COMMENT 'Usuario creador de la ruta', `km` decimal(5,2) DEFAULT NULL, `m3` decimal(5,2) DEFAULT NULL, `yearlyKm` decimal(5,2) DEFAULT NULL, @@ -36205,9 +35710,10 @@ CREATE TABLE `routeCommission` ( PRIMARY KEY (`id`), KEY `routeCommission_routeFk_idx` (`routeFk`), KEY `routeCommission_workCenterFk_idx` (`workCenterFk`), + KEY `routeCommission_firstEditorFk` (`firstEditorFk`), CONSTRAINT `routeCommission_routeFk` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `routeCommission_workCenterFk` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36228,7 +35734,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 `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36334,7 +35840,7 @@ CREATE TABLE `routeLog` ( `action` set('insert','update','delete') NOT NULL, `creationDate` timestamp NULL DEFAULT current_timestamp(), `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `changedModel` enum('Route') NOT NULL DEFAULT 'Route', + `changedModel` enum('Route','RoutesMonitor') NOT NULL DEFAULT 'Route', `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), `changedModelId` int(11) NOT NULL, @@ -36345,7 +35851,7 @@ CREATE TABLE `routeLog` ( KEY `routeLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `routeLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `route` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `routeLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36377,7 +35883,7 @@ CREATE TABLE `routeMaster` ( PRIMARY KEY (`id`), KEY `fk_rutas_warehouse_id_idx` (`warehouseFk`), CONSTRAINT `routeMaster_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36408,9 +35914,27 @@ CREATE TABLE `routeUserPercentage__` ( PRIMARY KEY (`id`), KEY `routeUserPercentageFk_idx` (`workerFk`), CONSTRAINT `routeUserPercentageFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `routesControl` +-- + +DROP TABLE IF EXISTS `routesControl`; +/*!50001 DROP VIEW IF EXISTS `routesControl`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `routesControl` AS SELECT + 1 AS `routeFk`, + 1 AS `expeditions`, + 1 AS `scanned`, + 1 AS `pallets`, + 1 AS `lastScanned`, + 1 AS `description`, + 1 AS `eta` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `routesMonitor` -- @@ -36436,13 +35960,18 @@ CREATE TABLE `routesMonitor` ( `m3boxes` decimal(10,1) DEFAULT NULL, `bufferFk` int(11) DEFAULT NULL COMMENT 'Buffer del sorter por el que se quiere sacar esa ruta', `isPickingAllowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Los tickets de esta ruta se pueden preparar', + `editorFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`routeFk`), KEY `routesMonitor_FK` (`bufferFk`), KEY `routesMonitor_FK_2` (`beachFk`), KEY `routesMonitor_FK_1` (`dockFk`), + KEY `routesMonitor_FK_3` (`expeditionTruckFk`), + KEY `routesMonitor_fk_editor` (`editorFk`), CONSTRAINT `routesMonitor_FK` FOREIGN KEY (`bufferFk`) REFERENCES `srt`.`buffer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `routesMonitor_FK_1` FOREIGN KEY (`dockFk`) REFERENCES `dock` (`code`) ON UPDATE CASCADE, - CONSTRAINT `routesMonitor_FK_2` FOREIGN KEY (`beachFk`) REFERENCES `beach` (`code`) ON UPDATE CASCADE + CONSTRAINT `routesMonitor_FK_2` FOREIGN KEY (`beachFk`) REFERENCES `beach` (`code`) ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_FK_3` FOREIGN KEY (`expeditionTruckFk`) REFERENCES `expeditionTruck` (`id`) ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -36478,313 +36007,8 @@ CREATE TABLE `sale` ( CONSTRAINT `movement_ticket_id` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sale_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `sale_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_beforeInsert` - BEFORE INSERT ON `sale` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - SET NEW.originalQuantity = NEW.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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_afterInsert` - AFTER INSERT ON `sale` - FOR EACH ROW -BEGIN - IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN - CALL util.throw('Cannot insert a service item into a ticket'); - END IF; - - CALL stock.log_add('sale', NEW.id, NULL); - CALL ticket_requestRecalc(NEW.ticketFk); - - IF NEW.quantity > 0 THEN - - UPDATE vn.collection c - JOIN vn.ticketCollection tc ON tc.collectionFk = c.id - AND tc.ticketFk = NEW.ticketFk - JOIN vn.item i ON i.id = NEW.itemFk - AND (c.itemPackingTypeFk = i.itemPackingTypeFk - OR c.itemPackingTypeFk IS NULL) - SET c.saleTotalCount = c.saleTotalCount + 1; - - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE - AND s.id = NEW.id - AND r.created >= util.VN_CURDATE() - GROUP BY r.id; - END IF; - - IF NEW.quantity = 0 THEN - CALL util.debugAdd('saleZeroQuantity', - CONCAT('[', user(), ']', ' Inserted sale: ', 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_beforeUpdate` - BEFORE UPDATE ON `sale` - FOR EACH ROW -BEGIN -/* - IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN - CALL util.throw('Cannot insert a service item into a ticket'); - END IF; -*/ - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.discount > 100 THEN - SET NEW.discount = 0; - END IF; - - IF old.discount > 0 AND NEW.discount = 0 THEN - INSERT INTO ticketLog - SET originFk = NEW.ticketFk, userFk = account.myUser_getId(), `action` = 'insert', - description = CONCAT('Cambio de descuento del item :', ' ', new.itemFk, ' de ', old.discount ,' a 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_afterUpdate` - AFTER UPDATE ON `sale` - FOR EACH ROW -BEGIN - DECLARE vIsToSendMail BOOL; - DECLARE vUserRole VARCHAR(255); - - IF !(NEW.id <=> OLD.id) - OR !(NEW.ticketFk <=> OLD.ticketFk) - OR !(NEW.itemFk <=> OLD.itemFk) - OR !(NEW.quantity <=> OLD.quantity) - OR !(NEW.created <=> OLD.created) - OR !(NEW.isPicked <=> OLD.isPicked) THEN - CALL stock.log_add('sale', NEW.id, OLD.id); - END IF; - - IF !(NEW.price <=> OLD.price) - OR !(NEW.ticketFk <=> OLD.ticketFk) - OR !(NEW.itemFk <=> OLD.itemFk) - OR !(NEW.quantity <=> OLD.quantity) - OR !(NEW.discount <=> OLD.discount) THEN - CALL ticket_requestRecalc(NEW.ticketFk); - CALL ticket_requestRecalc(OLD.ticketFk); - END IF; - - IF !(OLD.ticketFk <=> NEW.ticketFk) THEN - UPDATE ticketRequest SET ticketFk = NEW.ticketFk - WHERE saleFk = NEW.id; - END IF; - - SELECT account.myUser_getName() INTO vUserRole; - SELECT account.user_getMysqlRole(vUserRole) INTO vUserRole; - - IF !(OLD.quantity <=> NEW.quantity) THEN - SELECT COUNT(*) INTO vIsToSendMail - FROM ticketTracking tt - JOIN vn.state s ON s.id = tt.stateFk - WHERE s.code='PACKED' - AND tt.ticketFk = OLD.ticketFk - AND vUserRole IN ('salesPerson', 'salesTeamBoss') - LIMIT 1; - - IF vIsToSendMail THEN - CALL vn.mail_insert('jefesventas@verdnatura.es', - 'noreply@verdnatura.es', - CONCAT('Ticket ', OLD.ticketFk ,' modificada cantidad tras encajado'), - CONCAT('Ticket ', OLD.ticketFk ,'.
', - 'Modificada la catidad de ', OLD.quantity, ' a ' , NEW.quantity, - ' del artículo ', OLD.itemFk, ' tras estado encajado del ticket.
', - 'Este email se ha generado automáticamente' ) - ); - END IF; - IF (OLD.quantity > NEW.quantity) THEN - INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT NEW.id, cm.id, sc.value - FROM saleComponent sc - JOIN component cd ON cd.id = sc.componentFk - JOIN component cm ON cm.code = 'mana' - WHERE saleFk = NEW.id AND cd.code = 'lastUnitsDiscount' - ON DUPLICATE KEY UPDATE value = sc.value + VALUES(value); - - DELETE sc.* - FROM vn.saleComponent sc - JOIN component c ON c.id = sc.componentFk - WHERE saleFk = NEW.id AND c.code = 'lastUnitsDiscount'; - END IF; - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE - AND s.id = NEW.id - AND r.created >= util.VN_CURDATE() - GROUP BY r.id; - END IF; - - IF !(ABS(NEW.isPicked) <=> ABS(OLD.isPicked)) AND NEW.quantity > 0 THEN - UPDATE vn.collection c - JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk - SET c.salePickedCount = c.salePickedCount + IF(NEW.isPicked != 0, 1, -1); - END IF; - - IF !(NEW.quantity <=> OLD.quantity) AND (NEW.quantity = 0 OR OLD.quantity = 0) THEN - UPDATE vn.collection c - JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk - SET c.saleTotalCount = c.saleTotalCount + IF(OLD.quantity = 0, 1, -1); - END IF; - - IF NEW.quantity = 0 THEN - CALL util.debugAdd('saleZeroQuantity', - CONCAT('[', user(), ']', ' Updated sale: ', 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_BEFORE_DELETE` - BEFORE DELETE ON `sale` - FOR EACH ROW -BEGIN - IF OLD.quantity > 0 THEN - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE - AND s.id = OLD.id - AND r.created >= util.VN_CURDATE() - GROUP BY r.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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_afterDelete` - AFTER DELETE ON `sale` - FOR EACH ROW -BEGIN - DECLARE vIsToSendMail BOOL; - DECLARE vUserRole VARCHAR(255); - - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'Sale', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - CALL stock.log_add('sale', NULL, OLD.id); - CALL ticket_requestRecalc(OLD.ticketFk); - - SELECT account.myUser_getName() INTO vUserRole; - SELECT account.user_getMysqlRole(vUserRole) INTO vUserRole; - - SELECT COUNT(*) INTO vIsToSendMail - FROM ticketTracking tt - JOIN vn.state s ON s.id = tt.stateFk - WHERE s.code='PACKED' - AND tt.ticketFk = OLD.ticketFk - AND vUserRole IN ('salesPerson', 'salesBoss') - LIMIT 1; - - IF vIsToSendMail THEN - CALL vn.mail_insert('jefesventas@verdnatura.es', - 'noreply@verdnatura.es', - CONCAT('Ticket ', OLD.ticketFk ,' eliminado artículo tras encajado' ), - CONCAT('Ticket ', OLD.ticketFk ,'.
', - 'Eliminado artículo ', OLD.itemFk, ' tras estado encajado del ticket.
Este email se ha generado automáticamente' ) - ); - END IF; - - IF OLD.quantity > 0 THEN - UPDATE vn.collection c - JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = OLD.ticketFk - JOIN vn.item i ON i.id = OLD.itemFk - AND (c.itemPackingTypeFk = i.itemPackingTypeFk - OR ISNULL(c.itemPackingTypeFk)) - SET c.saleTotalCount = c.saleTotalCount - 1, - c.salePickedCount = c.salePickedCount - ABS(OLD.isPicked); - 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 */ ; -- -- Table structure for table `saleBuy` @@ -36804,53 +36028,6 @@ CREATE TABLE `saleBuy` ( CONSTRAINT `saleBuy_FK_1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`BEFORE_INSERT` - BEFORE INSERT ON `saleBuy` - FOR EACH ROW -BEGIN - - SET NEW.workerFk = vn.getUser(); - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleBuy_AI` - AFTER INSERT ON `saleBuy` - FOR EACH ROW -BEGIN -/* Activar de nuevo cuando volvamos a vender fruta y verdura - * - UPDATE vn.sale s - SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk) - WHERE s.id = NEW.saleFk; -*/ -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 `saleCloned` @@ -36925,7 +36102,7 @@ CREATE TABLE `saleGoal` ( `goal` decimal(10,2) DEFAULT NULL, `goalType` smallint(6) DEFAULT NULL COMMENT 'grado', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36942,7 +36119,7 @@ CREATE TABLE `saleGroup` ( `parkingFk` int(11) DEFAULT NULL, `sectorFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='agrupa lineas de venta'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='agrupa lineas de venta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36961,7 +36138,7 @@ CREATE TABLE `saleGroupDetail` ( UNIQUE KEY `saleGroupDetail_UN` (`saleFk`), KEY `saleGroupDetail_FK_1` (`saleGroupFk`), CONSTRAINT `saleGroupDetail_ibfk_1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='relaciona sale y saleGroup'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='relaciona sale y saleGroup'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36999,7 +36176,7 @@ CREATE TABLE `saleMistake` ( CONSTRAINT `saleMistake_fk1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleMistake_fk2` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleMistake_fk3` FOREIGN KEY (`typeFk`) REFERENCES `mistakeType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37095,37 +36272,8 @@ CREATE TABLE `saleTracking` ( CONSTRAINT `saleTracking_FK` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleTracking_FK_1` FOREIGN KEY (`actionFk__`) REFERENCES `ticketTrackingState__` (`id`) ON UPDATE CASCADE, CONSTRAINT `saleTracking_FK_2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleTracking_After_Insert` - AFTER INSERT ON `saleTracking` - FOR EACH ROW -BEGIN - - IF NEW.isChecked THEN - - UPDATE vn.sale s - SET s.isPicked = TRUE - WHERE s.id = NEW.saleFk - AND s.isPicked = 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 */ ; -- -- Temporary table structure for view `saleValue` @@ -37300,7 +36448,7 @@ CREATE TABLE `salespersonConfig` ( `manaFromDays` int(11) NOT NULL DEFAULT 90 COMMENT 'Range of days from mana calculation', `manaToDays` int(11) NOT NULL DEFAULT 30 COMMENT 'Range of days to mana calculation', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37320,7 +36468,7 @@ CREATE TABLE `sample` ( `datepickerEnabled` tinyint(1) NOT NULL DEFAULT 0, `model` varchar(25) DEFAULT NULL COMMENT 'Model name in plural', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37337,7 +36485,7 @@ CREATE TABLE `scanner` ( PRIMARY KEY (`id`), KEY `scanner_FK` (`modelFk`), CONSTRAINT `scanner_FK` FOREIGN KEY (`modelFk`) REFERENCES `scannerModel` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37367,7 +36515,7 @@ CREATE TABLE `screen` ( PRIMARY KEY (`id`), KEY `screen_FK` (`modelFk`), CONSTRAINT `screen_FK` FOREIGN KEY (`modelFk`) REFERENCES `screenModel` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37406,16 +36554,19 @@ CREATE TABLE `sector` ( `isHideForPickers` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'sector a ocultar a los sacadores', `isReserve` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Sectores de reserva, como Albenfruit o Fuentes', `mainPrinterFk` tinyint(3) unsigned DEFAULT NULL, + `typeFk` int(10) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`), KEY `sector_fk1_idx` (`warehouseFk`), KEY `sector_report` (`reportFk`), KEY `sector_FK` (`sonFk`,`warehouseFk`), KEY `sector_FK_1` (`mainPrinterFk`), + KEY `sectorType_FK` (`typeFk`), + CONSTRAINT `sectorType_FK` FOREIGN KEY (`typeFk`) REFERENCES `sectorType` (`id`) ON UPDATE CASCADE, CONSTRAINT `sector_FK_1` FOREIGN KEY (`mainPrinterFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sector_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sector_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37435,7 +36586,7 @@ CREATE TABLE `sectorCollection` ( KEY `sectorCollection_FK_2` (`sectorFk`), CONSTRAINT `sectorCollection_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sectorCollection_FK_1` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Las lineas de preparacion de pedidos por sectores se agrupan bajo el identificador de esta tabla'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Las lineas de preparacion de pedidos por sectores se agrupan bajo el identificador de esta tabla'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37456,7 +36607,7 @@ CREATE TABLE `sectorCollectionSaleGroup` ( CONSTRAINT `sectorCollectionSaleGroup_ibfk_1` FOREIGN KEY (`sectorCollectionFk`) REFERENCES `sectorCollection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sectorCollectionSaleGroup_ibfk_2` FOREIGN KEY (`saleGroupFk`) REFERENCES `saleGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sectorCollectionSaleGroup_ibfk_3` FOREIGN KEY (`saleGroupFk`) REFERENCES `saleGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relaciona las lineas de venta con la coleccion del sector'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relaciona las lineas de venta con la coleccion del sector'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37479,7 +36630,21 @@ CREATE TABLE `sectorProductivity` ( `hourWorked` decimal(10,2) DEFAULT NULL, `dated` date DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `sectorType` +-- + +DROP TABLE IF EXISTS `sectorType`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sectorType` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37494,7 +36659,7 @@ CREATE TABLE `sendingConfig` ( `defaultWeight` int(11) NOT NULL DEFAULT 13, `defaultPackages` int(11) NOT NULL DEFAULT 1, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37525,7 +36690,7 @@ CREATE TABLE `sendingServiceWeekday` ( `weekdays` set('mon','tue','wed','thu','fri','sat','sun') NOT NULL, `params` varchar(20) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de parámetros por dia de SENDING'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de parámetros por dia de SENDING'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37549,89 +36714,6 @@ CREATE TABLE `sharingCart` ( CONSTRAINT `Trabajador_key` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingCart_beforeInsert` - BEFORE INSERT ON `sharingCart` - FOR EACH ROW -BEGIN - IF NEW.workerFk = NEW.workerSubstitute THEN - CALL util.throw ('worker and workerSubstitute must be different'); - ELSE - INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) - SELECT NEW.workerFk, NEW.workerSubstitute, dated - FROM time - WHERE dated BETWEEN NEW.started AND NEW.ended; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingCart_beforeUpdate` - BEFORE UPDATE ON `sharingCart` - FOR EACH ROW -BEGIN - IF NEW.workerFk = NEW.workerSubstitute THEN - CALL util.throw ('worker and workerSubstitute must be different'); - ELSE - DELETE sc FROM sharingCartDaily sc - WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND - sc.ownerFk = OLD.workerFk AND - sc.substituteFk = OLD.workerSubstitute; - - INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) - SELECT NEW.workerFk, NEW.workerSubstitute, dated - FROM time - WHERE dated BETWEEN NEW.started AND NEW.ended; - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingCart_beforeDelete` - BEFORE DELETE ON `sharingCart` - FOR EACH ROW -BEGIN - DELETE sc FROM sharingCartDaily sc - WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND - sc.ownerFk = OLD.workerFk AND - sc.substituteFk = OLD.workerSubstitute; -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 `sharingCartDaily` @@ -37651,7 +36733,7 @@ CREATE TABLE `sharingCartDaily` ( KEY `sharingCartDailySubstitute_idx` (`substituteFk`), CONSTRAINT `sharingCartDailySubstitute` FOREIGN KEY (`substituteFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sharingCartDailyWorker` FOREIGN KEY (`ownerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='para calcular las comisiones de las sustituciones de los comerciales'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='para calcular las comisiones de las sustituciones de los comerciales'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37674,48 +36756,6 @@ CREATE TABLE `sharingClient` ( CONSTRAINT `Trabajadores_key` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingClient_beforeInsert` - BEFORE INSERT ON `sharingClient` - FOR EACH ROW -BEGIN - SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); - SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingClient_beforeUpdate` - BEFORE UPDATE ON `sharingClient` - FOR EACH ROW -BEGIN - SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); - SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); -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 `shelving` @@ -37744,85 +36784,8 @@ CREATE TABLE `shelving` ( CONSTRAINT `shelving_fk1` FOREIGN KEY (`parkingFk`) REFERENCES `parking` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `shelving_fk2` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `shelving_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla usada para localizar el carro en el parking del altillo'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla usada para localizar el carro en el parking 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`shelving_beforeInsert` - BEFORE INSERT ON `shelving` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.code = "" THEN - CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`shelving_BEFORE_UPDATE` - BEFORE UPDATE ON `shelving` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.code = "" THEN - CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); - END IF; - - IF NOT(OLD.parkingFk <=> NEW.parkingFK) THEN - SET NEW.isMoving = FALSE; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`shelving_afterDelete` - AFTER DELETE ON `shelving` - FOR EACH ROW -BEGIN - INSERT INTO shelvingLog - SET `action` = 'delete', - `changedModel` = 'Shelving', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `shelvingLog` @@ -37849,7 +36812,7 @@ CREATE TABLE `shelvingLog` ( KEY `shelvingLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `shelvingLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `shelving` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `shelvingLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37926,7 +36889,7 @@ CREATE TABLE `silexACL` ( `role` varchar(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `module_UNIQUE` (`module`,`method`) USING BTREE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38020,7 +36983,7 @@ CREATE TABLE `sms` ( PRIMARY KEY (`id`), KEY `sms_FK` (`senderFk`), CONSTRAINT `sms_FK` FOREIGN KEY (`senderFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38036,7 +36999,7 @@ CREATE TABLE `smsConfig` ( `title` varchar(50) NOT NULL, `apiKey` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='SMS configuration parameters'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='SMS configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38056,82 +37019,6 @@ CREATE TABLE `solunionCAP` ( CONSTRAINT `solunionCAP` FOREIGN KEY (`creditInsurance`) REFERENCES `creditInsurance` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`solunionCAP_AFTER_INSERT` - AFTER INSERT ON `solunionCAP` - FOR EACH ROW -BEGIN - UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client - JOIN creditInsurance ci ON ci.creditClassification = cc.id - SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`solunionCAP_AFTER_UPDATE` - AFTER UPDATE ON `solunionCAP` - FOR EACH ROW -BEGIN - IF NEW.dateLeaving IS NOT NULL THEN - UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client - JOIN creditInsurance ci ON ci.creditClassification = cc.id - SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; - ELSE - UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client - JOIN creditInsurance ci ON ci.creditClassification = cc.id - SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`solunionCAP_BEFORE_DELETE` - BEFORE DELETE ON `solunionCAP` - FOR EACH ROW -BEGIN - UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client - JOIN creditInsurance ci ON ci.creditClassification = cc.id - SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; -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 `sorter` @@ -38174,7 +37061,7 @@ CREATE TABLE `specialLabels` ( `isVisible` tinyint(1) NOT NULL DEFAULT 0, `image` blob DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38195,7 +37082,7 @@ CREATE TABLE `specialPrice` ( KEY `Id_Cliente` (`clientFk`), CONSTRAINT `sp_article_id` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE, CONSTRAINT `sp_customer_id` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38210,48 +37097,8 @@ CREATE TABLE `specie` ( `name` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `specie_UN` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`specie_BEFORE_INSERT` - BEFORE INSERT ON `specie` - FOR EACH ROW -BEGIN - SET NEW.name = LCASE(NEW.name); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`specie_BEFORE_UPDATE` - BEFORE UPDATE ON `specie` - FOR EACH ROW -BEGIN - SET NEW.name = LCASE(NEW.name); -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 `specieGeoInvasive` @@ -38273,7 +37120,7 @@ CREATE TABLE `specieGeoInvasive` ( CONSTRAINT `specieGeoInvasive_FK` FOREIGN KEY (`genusFk`) REFERENCES `genus` (`id`) ON UPDATE CASCADE, CONSTRAINT `specieGeoInvasive_FK_1` FOREIGN KEY (`specieFk`) REFERENCES `specie` (`id`) ON UPDATE CASCADE, CONSTRAINT `specieGeoInvasive_FK_2` FOREIGN KEY (`zoneGeofk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Esta tabla recoge las prohibiciones de comerciar con especies invasoras de acuerdo con el Catálogo de Especies Exóticas Invasoras publicado por el Estado Español'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Esta tabla recoge las prohibiciones de comerciar con especies invasoras de acuerdo con el Catálogo de Especies Exóticas Invasoras publicado por el Estado Español'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38295,7 +37142,7 @@ CREATE TABLE `splitFilter` ( KEY `splitFilter_FK_1` (`clientFk`), CONSTRAINT `splitFilter_FK` FOREIGN KEY (`autonomyFk`) REFERENCES `autonomy` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `splitFilter_FK_1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='define los clientes que tienen split y el nombre a mostrar en la etiqueta'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='define los clientes que tienen split y el nombre a mostrar en la etiqueta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38315,7 +37162,7 @@ CREATE TABLE `starredModule` ( KEY `starred_moduleFk` (`moduleFk`), CONSTRAINT `starred_moduleFk` FOREIGN KEY (`moduleFk`) REFERENCES `salix`.`module` (`code`) ON UPDATE CASCADE, CONSTRAINT `starred_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38349,7 +37196,7 @@ CREATE TABLE `state` ( KEY `state_FK` (`nextStateFk`), CONSTRAINT `state_FK` FOREIGN KEY (`nextStateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE, CONSTRAINT `state_ibfk_1` FOREIGN KEY (`alertLevel`) REFERENCES `alertLevel` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38387,7 +37234,7 @@ CREATE TABLE `stockBuyed` ( PRIMARY KEY (`id`), KEY `stockBuyed_user_idx` (`userFk`), CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38472,108 +37319,8 @@ CREATE TABLE `supplier` ( CONSTRAINT `supplier_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `suppplier_supplierActivityFk` FOREIGN KEY (`supplierActivityFk`) REFERENCES `supplierActivity` (`code`) ON UPDATE CASCADE, CONSTRAINT `supplierAccountTooShort` CHECK (octet_length(`account`) = 10) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_beforeInsert` - BEFORE INSERT ON `supplier` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_beforeUpdate` - BEFORE UPDATE ON `supplier` - FOR EACH ROW -BEGIN - DECLARE vHasChange BOOL; - DECLARE vPayMethodChanged BOOL; - DECLARE vPayMethodHasVerified BOOL; - DECLARE vParams JSON; - DECLARE vOldPayMethodName VARCHAR(20); - DECLARE vNewPayMethodName VARCHAR(20); - - SET NEW.editorFk = account.myUser_getId(); - - SELECT hasVerified INTO vPayMethodHasVerified - FROM payMethod - WHERE id = NEW.payMethodFk; - - SET vPayMethodChanged = NOT(NEW.payMethodFk <=> OLD.payMethodFk); - - IF vPayMethodChanged THEN - SELECT name INTO vOldPayMethodName - FROM payMethod - WHERE id = OLD.payMethodFk; - SELECT name INTO vNewPayMethodName - FROM payMethod - WHERE id = NEW.payMethodFk; - - SET vParams = JSON_OBJECT( - 'name', NEW.name, - 'oldPayMethod', vOldPayMethodName, - 'newPayMethod', vNewPayMethodName - ); - SELECT util.notification_send('supplier-pay-method-update', vParams, NULL) INTO @id; - END IF; - - SET vHasChange = NOT(NEW.payDemFk <=> OLD.payDemFk AND NEW.payDay <=> OLD.payDay) OR vPayMethodChanged; - - IF vHasChange AND vPayMethodHasVerified THEN - SET NEW.isPayMethodChecked = FALSE; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_afterDelete` - AFTER DELETE ON `supplier` - FOR EACH ROW -BEGIN - INSERT INTO supplierLog - SET `action` = 'delete', - `changedModel` = 'Supplier', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `supplierAccount` @@ -38602,72 +37349,8 @@ CREATE TABLE `supplierAccount` ( CONSTRAINT `supplierAccount_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, CONSTRAINT `supplierAccount_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `supplierAccount_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAccount_beforeInsert` - BEFORE INSERT ON `supplierAccount` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAccount_beforeUpdate` - BEFORE UPDATE ON `supplierAccount` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAccount_afterDelete` - AFTER DELETE ON `supplierAccount` - FOR EACH ROW -BEGIN - INSERT INTO supplierLog - SET `action` = 'delete', - `changedModel` = 'SupplierAccount', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `supplierActivity` @@ -38710,70 +37393,6 @@ CREATE TABLE `supplierAddress` ( CONSTRAINT `supplierAddress_province_fk` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAddress_beforeInsert` - BEFORE INSERT ON `supplierAddress` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAddress_beforeUpdate` - BEFORE UPDATE ON `supplierAddress` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAddress_afterDelete` - AFTER DELETE ON `supplierAddress` - FOR EACH ROW -BEGIN - INSERT INTO supplierLog - SET `action` = 'delete', - `changedModel` = 'SupplierAddress', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `supplierAgencyTerm` @@ -38820,72 +37439,8 @@ CREATE TABLE `supplierContact` ( KEY `supplierContact_supplierFk` (`supplierFk`), CONSTRAINT `supplierContact_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `supplierContact_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierContact_beforeInsert` - BEFORE INSERT ON `supplierContact` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierContact_beforeUpdate` - BEFORE UPDATE ON `supplierContact` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierContact_afterDelete` - AFTER DELETE ON `supplierContact` - FOR EACH ROW -BEGIN - INSERT INTO supplierLog - SET `action` = 'delete', - `changedModel` = 'SupplierContact', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `supplierDebtConfig` @@ -38930,7 +37485,7 @@ CREATE TABLE `supplierExpense` ( CONSTRAINT `pago_moneda` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON UPDATE CASCADE, CONSTRAINT `supplierExpenseCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `supplierExpense_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38958,7 +37513,7 @@ CREATE TABLE `supplierLog` ( KEY `supplierLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `supplierLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, CONSTRAINT `supplierLog_supplierFk` FOREIGN KEY (`originFk`) REFERENCES `supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39035,30 +37590,8 @@ CREATE TABLE `tag` ( PRIMARY KEY (`id`), UNIQUE KEY `tagNameIdx` (`name`,`ediTypeFk`), UNIQUE KEY `tagEdiTypeFkIdx` (`ediTypeFk`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Categorias para etiquetar los productos'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Categorias para etiquetar los productos'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`tag_BEFORE_INSERT` - BEFORE INSERT ON `tag` - FOR EACH ROW -BEGIN - IF NEW.ediTypeFk IS NULL AND (SELECT COUNT(*) FROM tag WHERE `name` = NEW.`name`) THEN - CALL util.throw('name duplicated'); - 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 */ ; -- -- Table structure for table `tagAbbreviation` @@ -39133,7 +37666,7 @@ CREATE TABLE `taxClass` ( `code` varchar(1) NOT NULL DEFAULT 'R', PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39182,7 +37715,7 @@ CREATE TABLE `taxCode` ( KEY `codigo` (`code`), KEY `tipo_index` (`type`), CONSTRAINT `taxCode_ibfk_1` FOREIGN KEY (`taxTypeFk`) REFERENCES `taxType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39204,7 +37737,7 @@ CREATE TABLE `taxType` ( KEY `serie_id` (`serial`), KEY `Id_Pais` (`countryFk`), CONSTRAINT `taxType_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39303,249 +37836,8 @@ CREATE TABLE `ticket` ( CONSTRAINT `ticket_ibfk_8` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`), CONSTRAINT `ticket_ibfk_9` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tickets_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeInsert` - BEFORE INSERT ON `ticket` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_afterInsert` - AFTER INSERT ON `ticket` - FOR EACH ROW -BEGIN - - DECLARE vClientType VARCHAR(255); - DECLARE vStateCode VARCHAR(255); - DECLARE vTransferorFirstShipped DATE; - - -- Borrar cuando se cambie el insert ticket en la APP móvil - - SELECT typeFk INTO vClientType - FROM vn.`client` WHERE id = NEW.clientFk; - - IF vClientType = 'loses' THEN - SET vStateCode = 'DELIVERED'; - ELSE - SET vStateCode = 'FREE'; - END IF; - - CALL ticket_setState(NEW.id, vStateCode); - - IF YEAR(NEW.shipped) > 2000 THEN - - SELECT cnb.firstShipped INTO vTransferorFirstShipped - FROM bs.clientNewBorn cnb - JOIN `client` c ON c.transferorFk = cnb.clientFk - WHERE c.id = NEW.clientFk; - - INSERT INTO bs.clientNewBorn(clientFk, firstShipped, lastShipped) - VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, util.VN_CURDATE()), util.VN_CURDATE()) - ON DUPLICATE KEY UPDATE lastShipped = util.VN_CURDATE(); - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeUpdate` - BEFORE UPDATE ON `ticket` - FOR EACH ROW -BEGIN - DECLARE vNewTime TIME; - - SET NEW.editorFk = account.myUser_getId(); - - IF NOT (NEW.routeFk <=> OLD.routeFk) THEN - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.route r - WHERE r.isOk = FALSE - AND r.id IN (OLD.routeFk,NEW.routeFk) - AND r.created >= util.VN_CURDATE() - GROUP BY r.id; - END IF; - - IF NOT (DATE(NEW.shipped) <=> DATE(OLD.shipped)) THEN - IF YEAR(NEW.shipped) < 2000 THEN - SIGNAL SQLSTATE '46000' - SET MESSAGE_TEXT = 'Year cannot be lesser than 2000'; - END IF; - - IF YEAR(NEW.shipped) = 2000 THEN - SET NEW.isDeleted = TRUE; - END IF; - - END IF; - - IF NOT (NEW.isDeleted <=> OLD.isDeleted) AND NEW.isDeleted THEN - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.ticket t - JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE - AND t.id = NEW.id - AND r.created >= util.VN_CURDATE() - GROUP BY r.id; - SET NEW.shipped = DATE_FORMAT(NEW.shipped, '2000-%m-%d %T'); - SET NEW.landed = DATE_FORMAT(NEW.landed, '2000-%m-%d %T'); - SET NEW.routeFk = NULL; - SET NEW.zoneFk = NULL; - END IF; - - IF NEW.routeFk AND NEW.isDeleted THEN - CALL util.throw ('This ticket is deleted'); - END IF; - - IF NOT (NEW.routeFk <=> OLD.routeFk) AND NEW.routeFk IS NOT NULL THEN - SELECT MAX(TIME(shipped)) INTO vNewTime - FROM vn.ticket - WHERE routeFk = NEW.routeFk - HAVING MAX(TIME(shipped)) > TIME(NEW.shipped); - - IF vNewTime THEN - SET NEW.shipped = TIMESTAMP(DATE(NEW.shipped), vNewTime); - END IF; - INSERT IGNORE INTO zoneAgencyMode (agencyModeFk,zoneFk) - SELECT r.agencyModeFk, NEW.zoneFk FROM route r - WHERE r.id = NEW.routeFk; - - CALL vn.routeUpdateM3(NEW.routeFk); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_afterUpdate` - AFTER UPDATE ON `ticket` - FOR EACH ROW -BEGIN - - IF !(NEW.id <=> OLD.id) - OR !(NEW.warehouseFk <=> OLD.warehouseFk) - OR !(NEW.shipped <=> OLD.shipped) THEN - CALL stock.log_add('ticket', NEW.id, OLD.id); - END IF; - - IF !(NEW.clientFk <=> OLD.clientFk) - OR !(NEW.addressFk <=> OLD.addressFk) - OR !(NEW.companyFk <=> OLD.companyFk) THEN - CALL ticket_requestRecalc(NEW.id); - END IF; - - IF NEW.routeFk <> OLD.routeFk THEN - UPDATE expedition - SET hasNewRoute = TRUE - WHERE ticketFk = 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeDelete` - BEFORE DELETE ON `ticket` - FOR EACH ROW -BEGIN - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id - FROM vn.route r - WHERE r.isOk = FALSE - AND r.id = OLD.routeFk - AND r.created >= util.VN_CURDATE() - GROUP BY r.id; - - DELETE FROM sale WHERE ticketFk = OLD.id; - - DELETE FROM ticketDms WHERE ticketFk = 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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_afterDelete` - AFTER DELETE ON `ticket` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'Ticket', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `ticketCollection` @@ -39574,48 +37866,8 @@ CREATE TABLE `ticketCollection` ( CONSTRAINT `ticketCollection_FK` FOREIGN KEY (`smartTagFk`) REFERENCES `smartTag` (`code`) ON UPDATE CASCADE, CONSTRAINT `ticketCollection_fk1` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketCollection_fk2` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete -AFTER DELETE -ON ticketCollection FOR EACH ROW -BEGIN - - DECLARE vSalesRemaining INT; - - SELECT count(*) INTO vSalesRemaining - FROM vn.ticketCollection tc - JOIN sale s ON s.ticketFk = tc.ticketFk - WHERE collectionFk = OLD.collectionFk - AND tc.id != OLD.id; - - IF NOT vSalesRemaining THEN - - DELETE FROM vn.collection WHERE id = OLD.collectionFk; - - ELSE - - UPDATE vn.collection - SET saleTotalCount = vSalesRemaining - WHERE id = OLD.collectionFk; - - 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 */ ; -- -- Table structure for table `ticketConfig` @@ -39632,7 +37884,7 @@ CREATE TABLE `ticketConfig` ( `packingDelay` int(11) DEFAULT 1 COMMENT 'Horas que marcará el retraso respecto hora de cierre web del ticket', `daysForWarningClaim` int(11) NOT NULL DEFAULT 2 COMMENT 'dias restantes hasta que salte el aviso de reclamación fuera de plazo', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39654,98 +37906,6 @@ CREATE TABLE `ticketDms` ( CONSTRAINT `ticketDms_ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_beforeInsert` - BEFORE INSERT ON `ticketDms` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_beforeUpdate` - BEFORE UPDATE ON `ticketDms` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_beforeDelete` - BEFORE DELETE ON `ticketDms` - FOR EACH ROW -BEGIN - UPDATE dms - SET dmsTypeFk = (SELECT id - FROM dmsType - WHERE `code` = 'trash' - ) - WHERE id = OLD.dmsFk AND ( SELECT IF(COUNT(*) > 0, FALSE, TRUE) - FROM ticketDms - WHERE dmsFk = OLD.dmsFk - ) ; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_afterDelete` - AFTER DELETE ON `ticketDms` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'ticketDms', - `changedModelId` = OLD.ticketFk, - `userFk` = account.myUser_getId(); -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 `ticketDocumentation` @@ -39779,9 +37939,25 @@ CREATE TABLE `ticketDown` ( KEY `ticketDown_FK` (`collectionFk`), CONSTRAINT `ticketDown_FK` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketDown_fk1` FOREIGN KEY (`selected`) REFERENCES `ticketDown_SelectionType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Cola de impresion para los tickets que se van a solicitar al altillo'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Cola de impresion para los tickets que se van a solicitar al altillo'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `ticketDownBuffer` +-- + +DROP TABLE IF EXISTS `ticketDownBuffer`; +/*!50001 DROP VIEW IF EXISTS `ticketDownBuffer`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketDownBuffer` AS SELECT + 1 AS `ticketFk`, + 1 AS `created`, + 1 AS `selected`, + 1 AS `sacador`, + 1 AS `parking` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `ticketDown_SelectionType` -- @@ -39866,7 +38042,7 @@ CREATE TABLE `ticketLog` ( KEY `ticketLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketLog_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39933,72 +38109,8 @@ CREATE TABLE `ticketObservation` ( CONSTRAINT `ticketObservation_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `ticketObservation_ibfk_1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketObservation_ibfk_2` FOREIGN KEY (`observationTypeFk`) REFERENCES `observationType` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketObservation_beforeInsert` - BEFORE INSERT ON `ticketObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketObservation_beforeUpdate` - BEFORE UPDATE ON `ticketObservation` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketObservation_afterDelete` - AFTER DELETE ON `ticketObservation` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketObservation', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `ticketPackage` @@ -40040,74 +38152,8 @@ CREATE TABLE `ticketPackaging` ( CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk3` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_BEFORE_INSERT` - BEFORE INSERT ON `ticketPackaging` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - SET NEW.workerFk = account.myUser_getId(); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_beforeUpdate` - BEFORE UPDATE ON `ticketPackaging` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_afterDelete` - AFTER DELETE ON `ticketPackaging` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketPackaging', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `ticketPackagingStartingStock` @@ -40172,30 +38218,8 @@ CREATE TABLE `ticketParking` ( KEY `ticketParking_fk1_idx` (`parkingFk`), CONSTRAINT `ticketParking_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketParking_fk2` FOREIGN KEY (`parkingFk`) REFERENCES `parking` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena los distintos lugares donde puede estar aparcado cada uno de los prepedidos'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena los distintos lugares donde puede estar aparcado cada uno de los prepedidos'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketParking_BEFORE_INSERT` - BEFORE INSERT ON `ticketParking` - FOR EACH ROW -BEGIN - - SET NEW.workerFk = vn.getUser(); - -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 */ ; -- -- Temporary table structure for view `ticketPreviousPreparingList` @@ -40229,7 +38253,7 @@ CREATE TABLE `ticketRecalc` ( `ticketFk` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `ticketRecalc_ibfk_1` (`ticketFk`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue of changed tickets to recalc its total'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Queue of changed tickets to recalc its total'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40251,74 +38275,8 @@ CREATE TABLE `ticketRefund` ( CONSTRAINT `ticketRefund_FK` FOREIGN KEY (`refundTicketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketRefund_FK_1` FOREIGN KEY (`originalTicketFk`) REFERENCES `ticket` (`id`) ON UPDATE CASCADE, CONSTRAINT `ticketRefund_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeInsert` - BEFORE INSERT ON `ticketRefund` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeUpdate` - BEFORE UPDATE ON `ticketRefund` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_afterDelete` - AFTER DELETE ON `ticketRefund` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketRefund', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `ticketRequest` @@ -40364,96 +38322,8 @@ CREATE TABLE `ticketRequest` ( CONSTRAINT `fgnRequester` FOREIGN KEY (`requesterFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `fgnTicket` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketRequest_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRequest_beforeInsert` - BEFORE INSERT ON `ticketRequest` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.ticketFk IS NULL THEN - SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk); - END IF; - - IF NEW.requesterFk IS NULL THEN - SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode); - END IF; - - IF NEW.attenderFk IS NULL THEN - SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRequest_beforeUpdate` - BEFORE UPDATE ON `ticketRequest` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.saleFk <> OLD.saleFk THEN - SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk); - END IF; - - IF NEW.salesPersonCode <> OLD.salesPersonCode THEN - SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode); - END IF; - - IF NEW.buyerCode <> OLD.buyerCode THEN - SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRequest_afterDelete` - AFTER DELETE ON `ticketRequest` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketRequest', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `ticketService` @@ -40480,122 +38350,8 @@ CREATE TABLE `ticketService` ( CONSTRAINT `ticketServiceIvaGroup` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE, CONSTRAINT `ticketService_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `ticketService_ticketServiceType` FOREIGN KEY (`ticketServiceTypeFk`) REFERENCES `ticketServiceType` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Servicios asociadas a un ticket'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Servicios asociadas a un ticket'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_beforeInsert` - BEFORE INSERT ON `ticketService` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_ai` - AFTER INSERT ON `ticketService` - FOR EACH ROW -BEGIN - - CALL ticket_requestRecalc(NEW.ticketFk); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_beforeUpdate` - BEFORE UPDATE ON `ticketService` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_au` - AFTER UPDATE ON `ticketService` - FOR EACH ROW -BEGIN - IF !(NEW.price <=> OLD.price) - OR !(NEW.ticketFk <=> OLD.ticketFk) - OR !(NEW.quantity <=> OLD.quantity) THEN - CALL ticket_requestRecalc(NEW.ticketFk); - CALL ticket_requestRecalc(OLD.ticketFk); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_ad` - AFTER DELETE ON `ticketService` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketService', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - CALL ticket_requestRecalc(OLD.ticketFk); - -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 `ticketServiceType` @@ -40609,9 +38365,9 @@ CREATE TABLE `ticketServiceType` ( `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, `expenseFk` varchar(10) NOT NULL DEFAULT '7050000000', PRIMARY KEY (`id`), - KEY `ticketServiceType_expenseFk_idx` (`expenseFk`), - CONSTRAINT `ticketServiceType_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Lista de los posibles servicios a elegir'; + KEY `ticketServiceType_expenceFk_idx` (`expenseFk`), + CONSTRAINT `ticketServiceType_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Lista de los posibles servicios a elegir'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40673,6 +38429,35 @@ SET character_set_client = utf8; 1 AS `isPicked` */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `ticketToPrepare` +-- + +DROP TABLE IF EXISTS `ticketToPrepare`; +/*!50001 DROP VIEW IF EXISTS `ticketToPrepare`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketToPrepare` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `Id_Movimiento`, + 1 AS `Id_Movimiento_mark`, + 1 AS `Id_Trabjador`, + 1 AS `Id_Article`, + 1 AS `Concepte`, + 1 AS `subName`, + 1 AS `Cantidad`, + 1 AS `original_quantity`, + 1 AS `Hora`, + 1 AS `Departure`, + 1 AS `Minuto`, + 1 AS `agency_id`, + 1 AS `warehouse_id`, + 1 AS `province_id`, + 1 AS `picked`, + 1 AS `zoneFk`, + 1 AS `sectorFk` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `ticketTracking` -- @@ -40687,11 +38472,11 @@ CREATE TABLE `ticketTracking` ( `notes` varchar(255) DEFAULT NULL, `created` timestamp NULL DEFAULT current_timestamp(), `ticketFk` int(11) DEFAULT NULL, - `workerFk` int(10) unsigned DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, `supervisorFk` int(10) unsigned DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), - KEY `currante` (`workerFk`), + KEY `currante` (`userFk`), KEY `responsable` (`supervisorFk`), KEY `ticket` (`ticketFk`), KEY `inter_state` (`stateFk`), @@ -40700,172 +38485,11 @@ CREATE TABLE `ticketTracking` ( KEY `ticketTracking_created_IDX` (`created`) USING BTREE, CONSTRAINT `inter_state` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE, CONSTRAINT `responsable` FOREIGN KEY (`supervisorFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, - CONSTRAINT `ticketTracking_FK3` FOREIGN KEY (`workerFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, + CONSTRAINT `ticketTracking_FK3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, CONSTRAINT `ticketTracking_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `ticketTracking_ibfk_1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_beforeInsert` - BEFORE INSERT ON `ticketTracking` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_afterInsert` - AFTER INSERT ON `ticketTracking` - FOR EACH ROW -BEGIN - DECLARE vNumTicketsPrepared INT; - - REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) - SELECT NEW.ticketFk, NEW.id, `name` - FROM state - WHERE id = NEW.stateFk; -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_beforeUpdate` - BEFORE UPDATE ON `ticketTracking` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_afterUpdate` - AFTER UPDATE ON `ticketTracking` - FOR EACH ROW -BEGIN - DECLARE vTicketFk INT; - DECLARE vTicketTrackingFk INT; - DECLARE vStateName VARCHAR(15); - - IF NEW.stateFk <> OLD.stateFk THEN - REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) - SELECT NEW.ticketFk, NEW.id, `name` - FROM state - WHERE id = NEW.stateFk; - END IF; - - IF NEW.ticketFk <> OLD.ticketFk THEN - SELECT i.ticketFk, i.id, s.`name` - INTO vTicketFk, vTicketTrackingFk, vStateName - FROM ticketTracking i - JOIN state s ON i.stateFk = s.id - WHERE ticketFk = NEW.ticketFk - ORDER BY created DESC - LIMIT 1; - - IF vTicketFk > 0 THEN - REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name) - VALUES(vTicketFk, vTicketTrackingFk, vStateName); - 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_afterDelete` - AFTER DELETE ON `ticketTracking` - FOR EACH ROW -BEGIN - DECLARE vTicketFk INT; - DECLARE vTicketTrackingFk INT; - DECLARE vStateName VARCHAR(15); - - DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' - BEGIN - DELETE FROM vn.ticketLastState - WHERE ticketFk = OLD.ticketFk; - END; - - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketTracking', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); - - CALL util.debugAdd('deletedState', - CONCAT('interFk: ', OLD.id, - ' ticketFk: ', OLD.ticketFk, - ' stateFk: ', OLD.stateFk)); - - SELECT i.ticketFk, i.id, s.`name` - INTO vTicketFk, vTicketTrackingFk, vStateName - FROM ticketTracking i - JOIN state s ON i.stateFk = s.id - WHERE ticketFk = OLD.ticketFk - ORDER BY created DESC - LIMIT 1; - - IF vTicketFk > 0 THEN - REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name) - VALUES(vTicketFk, vTicketTrackingFk, vStateName); - 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 */ ; -- -- Table structure for table `ticketTrackingState__` @@ -40878,7 +38502,7 @@ CREATE TABLE `ticketTrackingState__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `action` varchar(15) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40908,7 +38532,7 @@ CREATE TABLE `ticketUpdateAction` ( `description` varchar(45) NOT NULL, `code` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla pondremos las distintas opciones que se ofrecen al comecial o al cliente al cambiar alguno de los parametros básicos de un ticket'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla pondremos las distintas opciones que se ofrecen al comecial o al cliente al cambiar alguno de los parametros básicos de un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40929,72 +38553,37 @@ CREATE TABLE `ticketWeekly` ( CONSTRAINT `Id_Ticket_fk` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agencyModeFk` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `ticketWeekly_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketWeekly_beforeInsert` - BEFORE INSERT ON `ticketWeekly` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketWeekly_beforeUpdate` - BEFORE UPDATE ON `ticketWeekly` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketWeekly_afterDelete` - AFTER DELETE ON `ticketWeekly` - FOR EACH ROW -BEGIN - INSERT INTO ticketLog - SET `action` = 'delete', - `changedModel` = 'TicketWeekly', - `changedModelId` = OLD.ticketFk, - `userFk` = account.myUser_getId(); -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 */ ; + +-- +-- Temporary table structure for view `ticketeToPreparePrepared` +-- + +DROP TABLE IF EXISTS `ticketeToPreparePrepared`; +/*!50001 DROP VIEW IF EXISTS `ticketeToPreparePrepared`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketeToPreparePrepared` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `Id_Movimiento`, + 1 AS `Id_Movimiento_mark`, + 1 AS `Id_Trabjador`, + 1 AS `Id_Article`, + 1 AS `Concepte`, + 1 AS `subName`, + 1 AS `Cantidad`, + 1 AS `original_quantity`, + 1 AS `Hora`, + 1 AS `Departure`, + 1 AS `Minuto`, + 1 AS `agency_id`, + 1 AS `warehouse_id`, + 1 AS `province_id`, + 1 AS `picked`, + 1 AS `trabajador`, + 1 AS `sectorFk` */; +SET character_set_client = @saved_cs_client; -- -- Table structure for table `till` @@ -41034,7 +38623,7 @@ CREATE TABLE `till` ( KEY `fk_Cajas_Proveedores_account1_idx` (`supplierAccountFk`), CONSTRAINT `till_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `till_ibfk_3` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41077,31 +38666,6 @@ CREATE TABLE `time` ( KEY `yearMonth` (`yearMonth`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla de referencia para las semanas, años y meses'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`time_AFTER_UPDATE` - AFTER UPDATE ON `time` - FOR EACH ROW -BEGIN - /*INSERT INTO vn.mail SET - `sender` = 'jgallego@verdnatura.es', - `replyTo` = 'jgallego@verdnatura.es', - `subject` = 'tabla time modificada', - `body` = CONCAT(account.myUser_getName(), ' ha modificado la tabla time ', - NEW.`dated`);*/ -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 `timeControlDevice` @@ -41116,7 +38680,7 @@ CREATE TABLE `timeControlDevice` ( `key` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41135,99 +38699,8 @@ CREATE TABLE `town` ( KEY `name_idx` (`name`), KEY `townProvinceFk` (`provinceFk`), CONSTRAINT `townProvinceFk` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_beforeInsert` - BEFORE INSERT ON `town` - FOR EACH ROW -BEGIN - SET NEW.geoFk = zoneGeo_new('town', NEW.`name`, - (SELECT geoFk FROM province WHERE id = NEW.provinceFk)); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_beforeUpdate` - BEFORE UPDATE ON `town` - FOR EACH ROW -BEGIN - -- IF !(OLD.geoFk <=> NEW.geoFk) THEN - -- CALL zoneGeo_throwNotEditable; - -- 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_afterUpdate` - AFTER UPDATE ON `town` - FOR EACH ROW -BEGIN - IF !(OLD.provinceFk <=> NEW.provinceFk) THEN - CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM province WHERE id = NEW.provinceFk)); - END IF; - - IF !(OLD.`name` <=> NEW.`name`) THEN - UPDATE zoneGeo SET `name` = NEW.`name` - WHERE id = NEW.geoFk; - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_afterDelete` - AFTER DELETE ON `town` - FOR EACH ROW -BEGIN - CALL zoneGeo_delete(OLD.geoFk); -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 */ ; -- -- Temporary table structure for view `tr2` @@ -41301,7 +38774,7 @@ CREATE TABLE `train` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define la configuración de los carros que se utilizan para sacar pedidos'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define la configuración de los carros que se utilizan para sacar pedidos'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41315,7 +38788,7 @@ CREATE TABLE `trainingCenter` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41344,7 +38817,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 `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41358,7 +38831,7 @@ CREATE TABLE `trainingCourseType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de las formaciones'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de las formaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41374,7 +38847,7 @@ CREATE TABLE `transitoryDuaUnified` ( PRIMARY KEY (`id`), KEY `transitoryDuaUnified_FK` (`supplierFk`), CONSTRAINT `transitoryDuaUnified_FK` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Transitarios que al contabilizar sus entradas sólo generan un único DUA para todos los proveedores'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Transitarios que al contabilizar sus entradas sólo generan un único DUA para todos los proveedores'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41419,141 +38892,8 @@ CREATE TABLE `travel` ( CONSTRAINT `travel_ibfk_1` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouseOutFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agencyFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_beforeInsert` - BEFORE INSERT ON `travel` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - CALL travel_checkDates(NEW.shipped, NEW.landed); - - -- Actualizar agencyFk y agencyModeFk - IF NEW.agencyFk THEN - SET NEW.agencyModeFk = NEW.agencyFk; - END IF; - - IF NEW.agencyModeFk THEN - SET NEW.agencyFk = NEW.agencyModeFk; - END IF; - - CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_beforeUpdate` - BEFORE UPDATE ON `travel` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - - IF ((NOT NEW.shipped <=> OLD.shipped ) - OR (NOT NEW.landed <=> OLD.landed ) - OR (NOT NEW.warehouseInFk <=> OLD.warehouseInFk ) - OR (NOT NEW.warehouseOutFk <=> OLD.warehouseOutFk )) - AND (OLD.totalEntries AND OLD.landed < CURDATE()) THEN - CALL util.throw("Cannot past travels with entries"); - END IF; - - IF NOT (NEW.landed <=> OLD.landed) - OR NOT (NEW.shipped <=> OLD.shipped) THEN - CALL travel_checkDates(NEW.shipped, NEW.landed); - END IF; - - -- Actualizar agencyFk y agencyModeFk - IF NOT (NEW.agencyFk <=> OLD.agencyFk)THEN - SET NEW.agencyModeFk = NEW.agencyFk; - END IF; - - IF NOT (NEW.agencyModeFk <=> OLD.agencyModeFk) THEN - SET NEW.agencyFk = NEW.agencyModeFk; - END IF; - - IF NOT (NEW.isReceived <=> OLD.isReceived) THEN - CALL travel_checkPackaging(NEW.id); - END IF; - - IF NOT (NEW.warehouseInFk <=> OLD.warehouseInFk) THEN - CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_afterUpdate` - AFTER UPDATE ON `travel` - FOR EACH ROW -BEGIN - CALL stock.log_add('travel', NEW.id, OLD.id); - - IF !(NEW.shipped <=> OLD.shipped) THEN - UPDATE entry - SET commission = entry_getCommission(travelFk, currencyFk,supplierFk) - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_afterDelete` - AFTER DELETE ON `travel` - FOR EACH ROW -BEGIN - INSERT INTO travelLog - SET `action` = 'delete', - `changedModel` = 'Travel', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `travelClonedWeekly` @@ -41586,7 +38926,7 @@ CREATE TABLE `travelClonedWeekly` ( CONSTRAINT `travelClonedWeekly_FK_2` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `travelClonedWeekly_FK_4` FOREIGN KEY (`travelFk`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `travelClonedWeekly_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41639,7 +38979,7 @@ CREATE TABLE `travelLog` ( KEY `travelLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `travelLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `travelLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41656,7 +38996,7 @@ CREATE TABLE `travelObservation` ( `description` text NOT NULL, `created` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Observaciones de travel'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Observaciones de travel'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41702,72 +39042,8 @@ CREATE TABLE `travelThermograph` ( CONSTRAINT `travelThermographTravelFgn` FOREIGN KEY (`travelFk`) REFERENCES `travel` (`id`), CONSTRAINT `travelThermographWarehouseFgn` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE, CONSTRAINT `travelThermograph_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Registra cada termografo que se ha introducido en cada travel'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Registra cada termografo que se ha introducido en cada travel'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_beforeInsert` - BEFORE INSERT ON `travelThermograph` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_beforeUpdate` - BEFORE UPDATE ON `travelThermograph` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_afterDelete` - AFTER DELETE ON `travelThermograph` - FOR EACH ROW -BEGIN - INSERT INTO travelLog - SET `action` = 'delete', - `changedModel` = 'TravelThermograph', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `trolley` @@ -41783,9 +39059,78 @@ CREATE TABLE `trolley` ( PRIMARY KEY (`id`), KEY `trolley_FK` (`workerFk`), CONSTRAINT `trolley_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `unary` +-- + +DROP TABLE IF EXISTS `unary`; +/*!50001 DROP VIEW IF EXISTS `unary`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `unary` AS SELECT + 1 AS `id`, + 1 AS `parent` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `unaryScan` +-- + +DROP TABLE IF EXISTS `unaryScan`; +/*!50001 DROP VIEW IF EXISTS `unaryScan`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `unaryScan` AS SELECT + 1 AS `unaryFk`, + 1 AS `name`, + 1 AS `created`, + 1 AS `type` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `unaryScanLine` +-- + +DROP TABLE IF EXISTS `unaryScanLine`; +/*!50001 DROP VIEW IF EXISTS `unaryScanLine`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `unaryScanLine` AS SELECT + 1 AS `id`, + 1 AS `code`, + 1 AS `created`, + 1 AS `unaryScanFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `unaryScanLineBuy` +-- + +DROP TABLE IF EXISTS `unaryScanLineBuy`; +/*!50001 DROP VIEW IF EXISTS `unaryScanLineBuy`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `unaryScanLineBuy` AS SELECT + 1 AS `unaryScanLineFk`, + 1 AS `itemFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `unaryScanLineExpedition` +-- + +DROP TABLE IF EXISTS `unaryScanLineExpedition`; +/*!50001 DROP VIEW IF EXISTS `unaryScanLineExpedition`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `unaryScanLineExpedition` AS SELECT + 1 AS `unaryScanLineFk`, + 1 AS `expeditionFk` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `userConfig` -- @@ -41902,48 +39247,8 @@ CREATE TABLE `vehicle` ( CONSTRAINT `vehicle_FK` FOREIGN KEY (`fuelTypeFk`) REFERENCES `fuelType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `vehicle_FK_1` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `vehicle_deliveryPointFk` FOREIGN KEY (`deliveryPointFk`) REFERENCES `deliveryPoint` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`vehicle_beforeInsert` - BEFORE INSERT ON `vehicle` - FOR EACH ROW -BEGIN - CALL vehicle_checkNumberPlate(NEW.numberPlate, NEW.countryCodeFk); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`vehicle_beforeUpdate` - BEFORE UPDATE ON `vehicle` - FOR EACH ROW -BEGIN - CALL vehicle_checkNumberPlate(NEW.numberPlate, NEW.countryCodeFk); -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 `vehicleConfig` @@ -41973,7 +39278,7 @@ CREATE TABLE `vehicleDms` ( KEY `vehicleDms_FK_1` (`dmsFk`), CONSTRAINT `vehicleDms_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `vehicleDms_FK_1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Gestion documental de vehicle'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Gestion documental de vehicle'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41997,7 +39302,7 @@ CREATE TABLE `vehicleEvent` ( KEY `vehicleEvent_FK_1` (`userFk`), CONSTRAINT `vehicleEvent_FK` FOREIGN KEY (`vehicleStateFk`) REFERENCES `vehicleState` (`id`), CONSTRAINT `vehicleEvent_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42017,7 +39322,7 @@ CREATE TABLE `vehicleInvoiceIn` ( KEY `vehicleInvoiceIn_FK_1` (`invoiceInFk`), CONSTRAINT `vehicleInvoiceIn_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`), CONSTRAINT `vehicleInvoiceIn_FK_1` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42038,7 +39343,7 @@ CREATE TABLE `vehicleNotes` ( KEY `vehicleNotes_FK` (`vehicleFk`), CONSTRAINT `vehicleNotes_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`), CONSTRAINT `vehicleNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42067,7 +39372,7 @@ CREATE TABLE `vehicleState` ( `state` varchar(100) NOT NULL, `hasToNotify` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42086,7 +39391,7 @@ CREATE TABLE `viaexpressConfig` ( `defaultWeight` decimal(10,2) NOT NULL, `deliveryType` varchar(5) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42162,7 +39467,7 @@ CREATE TABLE `wagonType` ( `divisible` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42219,7 +39524,7 @@ CREATE TABLE `wagonVolumetry` ( PRIMARY KEY (`id`), KEY `wagonVolumetry_FK_1` (`wagonFk`), CONSTRAINT `wagonVolumetry_FK_1` FOREIGN KEY (`wagonFk`) REFERENCES `wagon` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42272,54 +39577,8 @@ CREATE TABLE `warehouse` ( CONSTRAINT `warehouse_FK_1` FOREIGN KEY (`pickUpAgencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `warehouse_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`), CONSTRAINT `warehouse_ibfk_2` FOREIGN KEY (`aliasFk`) REFERENCES `warehouseAlias` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`warehouse_afterInsert` - BEFORE UPDATE ON `warehouse` - FOR EACH ROW -BEGIN - IF NEW.isFeedStock AND NEW.isInventory THEN - CALL util.throw("isFeedStock and isInventory cannot both be true"); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`warehouse_afterUpdate` - AFTER UPDATE ON `warehouse` - FOR EACH ROW -BEGIN - IF NEW.isFeedStock IS TRUE AND OLD.isFeedStock IS FALSE THEN - INSERT IGNORE INTO warehouseAlias(`name`) VALUES(NEW.`name`); - INSERT IGNORE INTO warehouseJoined(warehouseFk, warehouseAliasFk) - VALUES(NEW.id,LAST_INSERT_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 */ ; -- -- Table structure for table `warehouseAlias` @@ -42333,9 +39592,22 @@ CREATE TABLE `warehouseAlias` ( `name` varchar(15) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `warehouseJoined` +-- + +DROP TABLE IF EXISTS `warehouseJoined`; +/*!50001 DROP VIEW IF EXISTS `warehouseJoined`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `warehouseJoined` AS SELECT + 1 AS `warehouseFk`, + 1 AS `warehouseAliasFk` */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `workCenter` -- @@ -42427,72 +39699,8 @@ CREATE TABLE `worker` ( CONSTRAINT `worker_businessFk` FOREIGN KEY (`businessFk`) REFERENCES `business` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `worker_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `worker_ibfk_1` FOREIGN KEY (`id`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`worker_beforeInsert` - BEFORE INSERT ON `worker` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`worker_beforeUpdate` - BEFORE UPDATE ON `worker` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`worker_afterDelete` - AFTER DELETE ON `worker` - FOR EACH ROW -BEGIN - INSERT INTO workerLog - SET `action` = 'delete', - `changedModel` = 'Worker', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `workerAppTester` @@ -42526,7 +39734,7 @@ CREATE TABLE `workerBosses` ( KEY `fg_bossFk_worker_idx` (`bossFk`), CONSTRAINT `fg_bossFk_worker` FOREIGN KEY (`bossFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fg_workerFk_worker` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42544,7 +39752,7 @@ CREATE TABLE `workerBusinessAgreement` ( `started` date DEFAULT NULL, `ended` date DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42616,7 +39824,7 @@ CREATE TABLE `workerConfig` ( KEY `workerConfig_FK_1` (`payMethodFk`), CONSTRAINT `workerConfig_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerConfig_FK_1` FOREIGN KEY (`payMethodFk`) REFERENCES `payMethod` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42661,7 +39869,7 @@ CREATE TABLE `workerDistributionCategory` ( PRIMARY KEY (`id`), KEY `workerDistributionCategory_workerFk_idx` (`workerFk`), CONSTRAINT `workerDistributionCategory_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42684,72 +39892,8 @@ CREATE TABLE `workerDocument` ( CONSTRAINT `workerDocument_FK` FOREIGN KEY (`worker`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerDocument_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerDocument_beforeInsert` - BEFORE INSERT ON `workerDocument` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerDocument_beforeUpdate` - BEFORE UPDATE ON `workerDocument` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerDocument_afterDelete` - AFTER DELETE ON `workerDocument` - FOR EACH ROW -BEGIN - INSERT INTO workerLog - SET `action` = 'delete', - `changedModel` = 'WorkerDocument', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `workerEmergencyBoss` @@ -42763,7 +39907,7 @@ CREATE TABLE `workerEmergencyBoss` ( `name` varchar(45) DEFAULT NULL, `value` varchar(45) DEFAULT NULL COMMENT 'Table to save all responsible people phones', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42780,7 +39924,7 @@ CREATE TABLE `workerHourPrice` ( `nightInc` decimal(4,2) DEFAULT NULL, `extraInc` decimal(4,2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los acuerdos de los distintos convenios'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los acuerdos de los distintos convenios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42803,70 +39947,8 @@ CREATE TABLE `workerIncome` ( KEY `income_employee_workerFk_idx` (`workerFk`), CONSTRAINT `income_employeeId_incomeType` FOREIGN KEY (`incomeTypeFk`) REFERENCES `vn2008`.`payroll_conceptos` (`conceptoid`) ON UPDATE CASCADE, CONSTRAINT `income_employee_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerIncome_afterInsert` - AFTER INSERT ON `workerIncome` - FOR EACH ROW -BEGIN - CALL worker_updateBalance(NEW.workerFk,NEW.credit,NEW.debit); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerIncome_afterUpdate` - AFTER UPDATE ON `workerIncome` - FOR EACH ROW -BEGIN - CALL worker_updateBalance(NEW.workerFk,-OLD.credit,-OLD.debit); - - CALL worker_updateBalance(NEW.workerFk,NEW.credit,NEW.debit); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerIncome_afterDelete` - AFTER DELETE ON `workerIncome` - FOR EACH ROW -BEGIN - CALL worker_updateBalance(OLD.workerFk,-OLD.credit,-OLD.debit); -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 `workerIrpf` @@ -42928,7 +40010,7 @@ CREATE TABLE `workerJourney` ( KEY `workerJourney_businessFk` (`businessFk`), CONSTRAINT `fk_workerJourney_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerJourney_businessFk` FOREIGN KEY (`businessFk`) REFERENCES `business` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42974,7 +40056,7 @@ CREATE TABLE `workerLog` ( KEY `workerLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43040,7 +40122,7 @@ CREATE TABLE `workerMistake` ( KEY `workerMistake_fk2_idx` (`workerMistakeTypeFk`), CONSTRAINT `workerMistake_fk1` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workerMistake_fk2` FOREIGN KEY (`workerMistakeTypeFk`) REFERENCES `workerMistakeType` (`code`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43100,7 +40182,7 @@ CREATE TABLE `workerRelatives` ( KEY `workerRelatives_workerFk` (`workerFk`), CONSTRAINT `workerRelatives_disabilityGradeFk` FOREIGN KEY (`disabilityGradeFk`) REFERENCES `disabilityGrade` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerRelatives_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `workerIrpf` (`workerFk`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Modelo 145 IRPF apartado 2 y 3'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Modelo 145 IRPF apartado 2 y 3'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43123,7 +40205,7 @@ CREATE TABLE `workerShelving` ( CONSTRAINT `workerShelving_FK` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `workerShelving_FK_1` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON UPDATE CASCADE, CONSTRAINT `workerShelving_worker_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='utilizaremos el id para establecer la prioridad de los carros a asignar'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='utilizaremos el id para establecer la prioridad de los carros a asignar'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43179,7 +40261,7 @@ CREATE TABLE `workerTeam` ( KEY `user_idx` (`workerFk`), KEY `team_idx` (`team`), CONSTRAINT `user_team` FOREIGN KEY (`workerFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43217,30 +40299,8 @@ CREATE TABLE `workerTimeControl` ( KEY `timed_idx` (`timed`), CONSTRAINT `warehouseFk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerTimeControl_fk1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Fichadas'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Fichadas'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerTimeControl_AI` - AFTER INSERT ON `workerTimeControl` - FOR EACH ROW -BEGIN - IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN - CALL util.throw('date in the future'); - 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 */ ; -- -- Table structure for table `workerTimeControlConfig` @@ -43278,7 +40338,7 @@ CREATE TABLE `workerTimeControlConfig` ( `maxWorkShortCycle` int(10) unsigned DEFAULT 561600 COMMENT 'Máximo tiempo que un trabajador puede estar trabajando con el que adquirirá el derecho a un descanso semanal corto', `maxWorkLongCycle` int(10) unsigned DEFAULT 950400 COMMENT 'Máximo tiempo que un trabajador puede estar trabajando con el que adquirirá el derecho a un descanso semanal largo', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin COMMENT='All values in seconds'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin COMMENT='All values in seconds'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43294,7 +40354,7 @@ CREATE TABLE `workerTimeControlError` ( `description` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43333,7 +40393,7 @@ CREATE TABLE `workerTimeControlMail` ( UNIQUE KEY `workerFk_UNIQUE` (`workerFk`,`year`,`week`), KEY `workerFk_idx` (`workerFk`), CONSTRAINT `workerTimeControlMail_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Guarda las respuestas de mail de los correos generados automáticamente por la procedimiento workerTimeControl_sendMail'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Guarda las respuestas de mail de los correos generados automáticamente por la procedimiento workerTimeControl_sendMail'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43359,7 +40419,7 @@ CREATE TABLE `workerTimeControlParams` ( `mailErrorFolder` varchar(45) NOT NULL, `mailUser` varchar(45) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin COMMENT='All values in seconds'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin COMMENT='All values in seconds'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43389,7 +40449,7 @@ CREATE TABLE `workerTimeControlSchedule` ( `time` time DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `punique_trhf` (`time`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43457,30 +40517,8 @@ CREATE TABLE `workingHours` ( PRIMARY KEY (`id`), KEY `user_working_hour_idx` (`userId`), CONSTRAINT `user_working_hour` FOREIGN KEY (`userId`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workingHoursBeforeInsert` - BEFORE INSERT ON `workingHours` - FOR EACH ROW -BEGIN - IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = util.VN_CURDATE()) > 0 THEN - CALL util.throw ('ALREADY_LOGGED'); - 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 */ ; -- -- Table structure for table `zipConfig` @@ -43509,7 +40547,7 @@ CREATE TABLE `zone` ( `hour` datetime NOT NULL, `agencyModeFk` int(11) NOT NULL, `travelingDays` int(11) NOT NULL DEFAULT 1, - `price` double NOT NULL DEFAULT 0, + `price` double NOT NULL DEFAULT 0 CHECK (`price` > 0), `bonus` double NOT NULL DEFAULT 0, `isVolumetric` tinyint(1) NOT NULL DEFAULT 0, `inflation` decimal(5,2) NOT NULL DEFAULT 1.00, @@ -43523,72 +40561,8 @@ CREATE TABLE `zone` ( KEY `zone_fk_editor` (`editorFk`), CONSTRAINT `fk_zone_2` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `zone_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zone_beforeInsert` - BEFORE INSERT ON `zone` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zone_beforeUpdate` - BEFORE UPDATE ON `zone` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zone_afterDelete` - AFTER DELETE ON `zone` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'Zone', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `zoneAgencyMode` @@ -43606,7 +40580,7 @@ CREATE TABLE `zoneAgencyMode` ( KEY `zoneAgencyMode_FK_1` (`zoneFk`), CONSTRAINT `zoneAgencyMode_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneAgencyMode_FK_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='junta agencias con zonas para que al enrutar se puedan proponer tickets.'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='junta agencias con zonas para que al enrutar se puedan proponer tickets.'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43636,7 +40610,7 @@ CREATE TABLE `zoneConfig` ( `scope` int(10) unsigned NOT NULL, `forwardDays` int(10) NOT NULL DEFAULT 7 COMMENT 'days forward to show zone_upcomingDeliveries', PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43649,13 +40623,12 @@ SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `zoneEstimatedDelivery` AS SELECT 1 AS `zoneFk`, - 1 AS `hourTheoretical`, - 1 AS `totalVolume`, - 1 AS `remainingVolume`, - 1 AS `speed`, - 1 AS `hourEffective`, - 1 AS `minutesLess`, - 1 AS `etc` */; + 1 AS `zoneClosureHour`, + 1 AS `zoneHour`, + 1 AS `volume`, + 1 AS `hasToRecalcPrice`, + 1 AS `m3`, + 1 AS `minSpeed` */; SET character_set_client = @saved_cs_client; -- @@ -43684,72 +40657,8 @@ CREATE TABLE `zoneEvent` ( KEY `zoneEvent_fk_editor` (`editorFk`), CONSTRAINT `zoneEvent_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `zoneEvent_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneEvent_beforeInsert` - BEFORE INSERT ON `zoneEvent` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneEvent_beforeUpdate` - BEFORE UPDATE ON `zoneEvent` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneEvent_afterDelete` - AFTER DELETE ON `zoneEvent` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'zoneEvent', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `zoneExclusion` @@ -43771,76 +40680,8 @@ CREATE TABLE `zoneExclusion` ( KEY `zoneExclusion_fk_editor` (`editorFk`), CONSTRAINT `zoneExclusion_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `zoneExclusion_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_BI` - BEFORE INSERT ON `zoneExclusion` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - SET NEW.userFk = account.myUser_getId(); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_BU` - BEFORE UPDATE ON `zoneExclusion` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); - SET NEW.userFk = account.myUser_getId(); - -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_afterDelete` - AFTER DELETE ON `zoneExclusion` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'zoneExclusion', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 `zoneExclusionGeo` @@ -43858,7 +40699,7 @@ CREATE TABLE `zoneExclusionGeo` ( KEY `zoneExclusionGeo2_FK_1` (`geoFk`), CONSTRAINT `zoneExclusionGeo_FK` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE, CONSTRAINT `zoneExclusionGeo_FK_1` FOREIGN KEY (`zoneExclusionFk`) REFERENCES `zoneExclusion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43878,7 +40719,7 @@ CREATE TABLE `zoneFilter` ( KEY `zoneFilter_FK_1` (`itemTypeFk`), CONSTRAINT `zoneFilter_FK` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneFilter_FK_1` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='recoge los parámetros para filtrar determinados productos según la zona'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='recoge los parámetros para filtrar determinados productos según la zona'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43903,50 +40744,8 @@ CREATE TABLE `zoneGeo` ( KEY `name_idx` (`name`), KEY `parentFk` (`parentFk`), KEY `path` (`path`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneGeo_beforeInsert` - BEFORE INSERT ON `zoneGeo` - FOR EACH ROW -BEGIN - CALL zoneGeo_checkName(NEW.`name`); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneGeo_beforeUpdate` - BEFORE UPDATE ON `zoneGeo` - FOR EACH ROW -BEGIN - IF !(OLD.`name` <=> NEW.`name`) THEN - CALL zoneGeo_checkName(NEW.`name`); - 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 */ ; -- -- Table structure for table `zoneGeoRecalc` @@ -43959,7 +40758,7 @@ CREATE TABLE `zoneGeoRecalc` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `isChanged` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43982,72 +40781,8 @@ CREATE TABLE `zoneIncluded` ( CONSTRAINT `zoneIncluded_FK_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneIncluded_FK_2` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneIncluded_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneIncluded_beforeInsert` - BEFORE INSERT ON `zoneIncluded` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneIncluded_beforeUpdate` - BEFORE UPDATE ON `zoneIncluded` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneIncluded_afterDelete` - AFTER DELETE ON `zoneIncluded` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'zoneIncluded', - `changedModelId` = OLD.zoneFk, - `userFk` = account.myUser_getId(); -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 `zoneItemType` @@ -44093,7 +40828,7 @@ CREATE TABLE `zoneLog` ( KEY `zoneLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `zoneLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44115,72 +40850,8 @@ CREATE TABLE `zoneWarehouse` ( CONSTRAINT `zoneWarehouse_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `zoneWarehouse_fk_warehouse` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `zoneWarehouse_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneWarehouse_beforeInsert` - BEFORE INSERT ON `zoneWarehouse` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneWarehouse_beforeUpdate` - BEFORE UPDATE ON `zoneWarehouse` - FOR EACH ROW -BEGIN - SET NEW.editorFk = account.myUser_getId(); -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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneWarehouse_afterDelete` - AFTER DELETE ON `zoneWarehouse` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'ZoneWarehouse', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); -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 */ ; -- -- Dumping events for database 'vn' @@ -44198,7 +40869,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `clientsDisable` ON SCHEDULE EVERY 1 MONTH STARTS '2023-06-01 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `clientsDisable` ON SCHEDULE EVERY 1 MONTH STARTS '2023-06-01 00:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN UPDATE account.user u JOIN client c ON c.id = u.id JOIN clientType ct ON ct.id = c.typeFk @@ -44209,8 +40880,8 @@ DELIMITER ;; FROM client c LEFT JOIN ticket t ON t.clientFk = c.id WHERE c.salesPersonFk IS NOT NULL - OR t.created > util.VN_CURDATE() - INTERVAL 2 MONTH - OR shipped > util.VN_CURDATE() - INTERVAL 2 MONTH + OR t.created > util.VN_CURDATE() - INTERVAL 2 MONTH + OR shipped > util.VN_CURDATE() - INTERVAL 2 MONTH ); END */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; @@ -44230,7 +40901,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`jgallego`@`%`*/ /*!50106 EVENT `client_unassignSalesPerson` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:30:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL client_unassignSalesPerson */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`jgallego`@`%`*/ /*!50106 EVENT `client_unassignSalesPerson` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:30:00' ON COMPLETION PRESERVE DISABLE DO CALL client_unassignSalesPerson */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44248,7 +40919,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`@`localhost`*/ /*!50106 EVENT `collection_make` ON SCHEDULE EVERY 5 MINUTE STARTS '2022-09-15 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL vn.collection_make */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `collection_make` ON SCHEDULE EVERY 5 MINUTE STARTS '2022-09-15 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL vn.collection_make */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44266,7 +40937,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `department_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-11-15 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL vn.department_doCalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `department_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-11-15 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL vn.department_doCalc */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44284,7 +40955,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `envialiaThreHoldChecker` ON SCHEDULE EVERY 1 DAY STARTS '2022-01-28 09:52:46' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO BEGIN +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `envialiaThreHoldChecker` ON SCHEDULE EVERY 1 DAY STARTS '2022-01-28 09:52:46' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN DECLARE vActualNumber BIGINT; DECLARE vEndRange BIGINT; DECLARE vIsAlreadyNotified BOOLEAN; @@ -44330,7 +41001,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `greuge_notify` ON SCHEDULE EVERY 1 DAY STARTS '2023-01-01 00:07:00' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE COMMENT 'Notifies subscribed users of events in wrong greuges' DO CALL vn.greuge_notifyEvents() */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `greuge_notify` ON SCHEDULE EVERY 1 DAY STARTS '2023-01-01 00:07:00' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Notifies subscribed users of events in wrong greuges' DO CALL vn.greuge_notifyEvents() */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44348,9 +41019,9 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `itemImageQueue_check` ON SCHEDULE EVERY 1 HOUR STARTS '2023-07-28 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN - DELETE FROM itemImageQueue - WHERE attempts >= (SELECT downloadMaxAttempts FROM itemConfig); +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `itemImageQueue_check` ON SCHEDULE EVERY 1 HOUR STARTS '2023-07-28 00:00:00' ON COMPLETION PRESERVE ENABLE DO BEGIN + DELETE FROM itemImageQueue + WHERE attempts >= (SELECT downloadMaxAttempts FROM itemConfig); END */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; @@ -44369,7 +41040,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `mysqlConnectionsSorter_kill` ON SCHEDULE EVERY 1 MINUTE STARTS '2021-10-28 09:56:27' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL mysqlConnectionsSorter_kill() */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `mysqlConnectionsSorter_kill` ON SCHEDULE EVERY 1 MINUTE STARTS '2021-10-28 09:56:27' ON COMPLETION NOT PRESERVE ENABLE DO CALL mysqlConnectionsSorter_kill() */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44387,7 +41058,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `printQueue_check` ON SCHEDULE EVERY 10 MINUTE STARTS '2022-01-28 09:52:46' ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `printQueue_check` ON SCHEDULE EVERY 10 MINUTE STARTS '2022-01-28 09:52:46' ON COMPLETION PRESERVE ENABLE DO BEGIN DECLARE vCurrentCount INT; DECLARE vCheckSum INT; @@ -44496,7 +41167,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `route_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2021-07-08 07:32:23' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL route_doRecalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `route_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2021-07-08 07:32:23' ON COMPLETION PRESERVE ENABLE DO CALL route_doRecalc */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44514,7 +41185,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `sale_checkWithoutComponents` ON SCHEDULE EVERY 10 MINUTE STARTS '2020-05-04 11:56:23' ON COMPLETION PRESERVE DISABLE ON SLAVE DO call sale_checkNoComponents(DATE_ADD(util.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(util.VN_NOW(), INTERVAL -1 MINUTE)) */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `sale_checkWithoutComponents` ON SCHEDULE EVERY 10 MINUTE STARTS '2020-05-04 11:56:23' ON COMPLETION PRESERVE DISABLE DO call sale_checkNoComponents(DATE_ADD(util.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(util.VN_NOW(), INTERVAL -1 MINUTE)) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44532,7 +41203,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`@`localhost`*/ /*!50106 EVENT `ticket_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2022-01-28 09:29:18' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL ticket_doRecalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ticket_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2022-01-28 09:29:18' ON COMPLETION PRESERVE ENABLE DO CALL ticket_doRecalc */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44550,7 +41221,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `travel_doRecalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-05-17 10:52:29' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL travel_doRecalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!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 */ ;; @@ -44568,7 +41239,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `vehicle_notify` ON SCHEDULE EVERY 1 DAY STARTS '2022-01-01 00:07:00' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE COMMENT 'Notifies subscribed users of events in vehicles that are about t' DO CALL vn.vehicle_notifyEvents */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `vehicle_notify` ON SCHEDULE EVERY 1 DAY STARTS '2022-01-01 00:07:00' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Notifies subscribed users of events in vehicles that are about t' DO CALL vn.vehicle_notifyEvents */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44586,7 +41257,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `workerJourney_doRecalc` ON SCHEDULE EVERY 1 DAY STARTS '2023-07-22 04:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL workerJourney_replace(util.VN_CURDATE() - INTERVAL 1 WEEK, util.VN_CURDATE(), NULL) */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `workerJourney_doRecalc` ON SCHEDULE EVERY 1 DAY STARTS '2023-07-22 04:00:00' ON COMPLETION PRESERVE ENABLE DO CALL workerJourney_replace(util.VN_CURDATE() - INTERVAL 1 WEEK, util.VN_CURDATE(), NULL) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44604,7 +41275,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `worker_updateChangedBusiness` ON SCHEDULE EVERY 1 DAY STARTS '2000-01-01 00:00:05' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL worker_updateChangedBusiness */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `worker_updateChangedBusiness` ON SCHEDULE EVERY 1 DAY STARTS '2000-01-01 00:00:05' ON COMPLETION NOT PRESERVE ENABLE DO CALL worker_updateChangedBusiness */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44622,7 +41293,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`salix`@`10.0.%.%`*/ /*!50106 EVENT `zoneClosure_doRecalc` ON SCHEDULE AT '2023-11-13 07:15:54' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL zoneClosure_recalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`salix`@`10.0.%.%`*/ /*!50106 EVENT `zoneClosure_doRecalc` ON SCHEDULE AT '2023-11-13 07:15:54' ON COMPLETION NOT PRESERVE DISABLE DO CALL zoneClosure_recalc */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44640,7 +41311,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `zoneGeo_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-09-13 15:30:47' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL vn.zoneGeo_doCalc */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `zoneGeo_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-09-13 15:30:47' ON COMPLETION PRESERVE ENABLE DO CALL vn.zoneGeo_doCalc */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44715,7 +41386,7 @@ BEGIN DECLARE vGeoFk INT; SELECT p.geoFk INTO vGeoFk - FROM address a + FROM address a JOIN town t ON t.provinceFk = a.provinceFk JOIN postCode p ON p.townFk = t.id AND p.`code` = a.postalCode WHERE a.id = vSelf @@ -44742,12 +41413,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `barcodeToItem`(vBarcode VARCHAR(22)) RETURNS int(11) DETERMINISTIC BEGIN - + /** * Obtiene el id del artículo * * @param vBarcode código de barras - * + * * return id del item */ @@ -44757,35 +41428,35 @@ BEGIN FROM vn.item WHERE id = vBarcode OR comment = vBarcode LIMIT 1; - - IF vItemFk THEN + + IF vItemFk THEN RETURN vItemFk; END IF; - SELECT itemFk INTO vItemFk - FROM buy + SELECT itemFk INTO vItemFk + FROM buy WHERE id = vBarcode; - - IF vItemFk THEN + + IF vItemFk THEN RETURN vItemFk; END IF; - - SELECT itemFk INTO vItemFk - FROM itemBarcode + + SELECT itemFk INTO vItemFk + FROM itemBarcode WHERE code = vBarcode; - - IF vItemFk THEN + + IF vItemFk THEN RETURN vItemFk; END IF; - SELECT i.id INTO vItemFk + SELECT i.id INTO vItemFk FROM vn.item i WHERE i.name LIKE CONCAT('%',vBarcode,'%') ORDER BY i.id ASC LIMIT 1; - + RETURN vItemFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -44849,7 +41520,7 @@ BEGIN DECLARE vItem INT; DECLARE vPackaging VARCHAR(10); - SELECT itemFk, packageFk INTO vItem, vPackaging + SELECT itemFk, packagingFk INTO vItem, vPackaging FROM buy WHERE id = vSelf; @@ -44878,16 +41549,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `catalog_componentReverse`(vWarehouse DETERMINISTIC BEGIN /* Calcula los componentes para un cliente a partir de un coste y volumen - * @param vWarehouse + * @param vWarehouse * @param vCost Valor de coste del articulo * @param vM3 m3 del articulo - * @param vAddressFk + * @param vAddressFk * @param vZoneFk - * @return vRetailedPrice precio de venta sin iva + * @return vRetailedPrice precio de venta sin iva * @return tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) */ - - DECLARE vBoxVolume BIGINT; + + DECLARE vBoxVolume BIGINT; DECLARE vCustomer INT; DECLARE vComponentRecovery INT DEFAULT 17; DECLARE vComponentMana INT DEFAULT 39; @@ -44896,11 +41567,11 @@ BEGIN DECLARE vComponentCost INT DEFAULT 28; DECLARE vRetailedPrice DECIMAL(10,2); DECLARE vItem INT DEFAULT 98; - + SELECT volume INTO vBoxVolume FROM vn.packaging WHERE id = '94'; - + SELECT clientFk INTO vCustomer FROM address WHERE id = vAddressFk; DROP TEMPORARY TABLE IF EXISTS tmp.catalog_component; @@ -44924,7 +41595,7 @@ BEGIN -- Margen -- No se aplica margen, cau 12589 /* INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) - SELECT vWarehouse, vItem, vComponentMargin, (vCost / ((100 - rate2) / 100)) - vCost + SELECT vWarehouse, vItem, vComponentMargin, (vCost / ((100 - rate2) / 100)) - vCost FROM vn.rate WHERE dated <= util.VN_CURDATE() AND warehouseFk = vWarehouse @@ -44933,7 +41604,7 @@ BEGIN */ -- Recobro INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) - SELECT vWarehouse, vItem, vComponentRecovery, ROUND(LEAST(recobro,0.25), 3) + SELECT vWarehouse, vItem, vComponentRecovery, ROUND(LEAST(recobro,0.25), 3) FROM bi.claims_ratio WHERE Id_Cliente = vCustomer AND recobro > 0.009; @@ -44950,7 +41621,7 @@ BEGIN ROUND( vM3 * (z.price - z.bonus) - * z.inflation + * z.inflation / vBoxVolume, 4 ) FROM zone z @@ -45044,7 +41715,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `clientTaxArea`(vClientId INT, vCompa READS SQL DATA BEGIN /** -* Devuelve el area de un cliente, +* Devuelve el area de un cliente, * intracomunitario, extracomunitario o nacional. * * @param vClient Id del cliente @@ -45077,37 +41748,37 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getDebt`(`vClient` INT, `vDate` DATE) RETURNS decimal(10,2) READS SQL DATA -BEGIN -/** - * Returns the risk of a customer. - * - * @param vClient client id - * @param vDate date to check the risk - * @return Client risk - */ - DECLARE vDebt DECIMAL(10,2); - DECLARE vHasDebt BOOLEAN; - - SELECT COUNT(*) INTO vHasDebt - FROM `client` c - WHERE c.id = vClient AND c.typeFk = 'normal'; - - IF NOT vHasDebt THEN - RETURN 0; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt (clientFk INT); - INSERT INTO tmp.clientGetDebt SET clientFk = vClient; - - CALL vn.client_getDebt(vDate); - - SELECT risk INTO vDebt FROM tmp.risk; - - DROP TEMPORARY TABLE - tmp.clientGetDebt, - tmp.risk; - - RETURN vDebt; +BEGIN +/** + * Returns the risk of a customer. + * + * @param vClient client id + * @param vDate date to check the risk + * @return Client risk + */ + DECLARE vDebt DECIMAL(10,2); + DECLARE vHasDebt BOOLEAN; + + SELECT COUNT(*) INTO vHasDebt + FROM `client` c + WHERE c.id = vClient AND c.typeFk = 'normal'; + + IF NOT vHasDebt THEN + RETURN 0; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt (clientFk INT); + INSERT INTO tmp.clientGetDebt SET clientFk = vClient; + + CALL vn.client_getDebt(vDate); + + SELECT risk INTO vDebt FROM tmp.risk; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.risk; + + RETURN vDebt; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45183,8 +41854,8 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `client_getSalesPerson`(vClientFk INT 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 + * 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 @@ -45222,29 +41893,29 @@ BEGIN l: LOOP SELECT workerSubstitute INTO vWorkerSubstituteFk - FROM sharingCart + FROM sharingCart WHERE util.VN_CURDATE() BETWEEN started AND ended AND workerFk = vSalesPersonFk ORDER BY id LIMIT 1; - + IF vWorkerSubstituteFk IS NULL THEN LEAVE l; END IF; - + SELECT COUNT(*) > 0 INTO vLoop FROM tmp.stack WHERE substitute = vWorkerSubstituteFk; IF vLoop THEN LEAVE l; END IF; - + INSERT INTO tmp.stack SET substitute = vWorkerSubstituteFk; - + SET vSalesPersonFk = vWorkerSubstituteFk; END LOOP; - + DROP TEMPORARY TABLE tmp.stack; END IF; @@ -45278,11 +41949,11 @@ BEGIN **/ DECLARE vClientFk INT; DECLARE vDated DATE; - + SELECT clientFk, shipped INTO vClientFk, vDated FROM ticket WHERE id = vTicketFk; - + RETURN client_getSalesPerson(vClientFk, vDated); END ;; DELIMITER ; @@ -45313,12 +41984,12 @@ BEGIN **/ DECLARE vWorkerCode CHAR(3); DECLARE vSalesPersonFk INT; - + SET vSalesPersonFk = client_getSalesPerson(vClientFk, vDated); SELECT code INTO vWorkerCode - FROM worker + FROM worker WHERE id = vSalesPersonFk; RETURN vWorkerCode; @@ -45351,11 +42022,11 @@ BEGIN **/ DECLARE vClientFk INT; DECLARE vDated DATE; - + SELECT clientFk, shipped INTO vClientFk, vDated FROM ticket WHERE id = vTicketFk; - + RETURN client_getSalesPersonCode(vClientFk, vDated); END ;; DELIMITER ; @@ -45365,6 +42036,38 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `client_hasDifferentCountries` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `client_hasDifferentCountries`(vClientFk INT) RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Return if client have address in different countries. + * + * @param vClientFk The id client + * @return BOOL + **/ + RETURN (SELECT COUNT(DISTINCT c.id) > 1 + FROM `address` a + JOIN province p ON p.id = a.provinceFk + JOIN country c ON c.id = p.countryFk + WHERE a.clientFk = vClientFk + AND a.isActive); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `collection_isPacked` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45447,7 +42150,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `currentRate`(vCurrencyFk INT, vDated BEGIN DECLARE curRate DECIMAL(10,4); - + SELECT value INTO curRate FROM referenceRate WHERE dated <= vDated @@ -45478,23 +42181,23 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `deviceProductionUser_accessGranted`( BEGIN /* * Comprueba si el usuario puede entrar en la aplicacion de almacen con ese movil - * + * * */ - + /*DECLARE vIsGranted BOOLEAN; DECLARE vDeviceProductionFk INT(11) DEFAULT NULL; - SELECT dp.id INTO vDeviceProductionFk - FROM vn.deviceProduction dp + SELECT dp.id INTO vDeviceProductionFk + FROM vn.deviceProduction dp WHERE dp.android_id = android_id; IF vDeviceProductionFk THEN - - SELECT COUNT(*) INTO vIsGranted - FROM vn.deviceProductionUser dpu - WHERE dpu.userFk = vUserFK + + SELECT COUNT(*) INTO vIsGranted + FROM vn.deviceProductionUser dpu + WHERE dpu.userFk = vUserFK AND dpu.deviceProductionFk = vDeviceProductionFk; - + RETURN vIsGranted; END IF;*/ RETURN TRUE; @@ -45519,7 +42222,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `duaTax_getRate`(vDuaFk INT, vTaxClas BEGIN /** * Devuelve el rate para un Dua teniendo en cuenta la fecha de opreción del DUA - * + * * @param vDuaFk Identificador de la tabla dua * @param vTaxClassFk Identificador del IVA de la tabla invoiceInTaxBookingAccount */ @@ -45553,24 +42256,24 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getEntry`(vEktFk INT) RETURNS in READS SQL DATA BEGIN /** - * Devuelve el numero de entrada para el ekt - * + * Devuelve el numero de entrada para el ekt + * * @param vEktFk Identificador de edi.ekt - */ + */ DECLARE vTravelFk INT; DECLARE vEntryFk INT DEFAULT 0; DECLARE vEntryAssignFk INT; - SELECT ea.id + SELECT ea.id INTO vEntryAssignFk FROM edi.ekt e - JOIN vn.ektEntryAssign ea ON + JOIN vn.ektEntryAssign ea ON IFNULL(ea.sub, e.sub) <=> e.sub AND IFNULL(ea.kop, e.kop) <=> e.kop AND IFNULL(ea.pro, e.pro) <=> e.pro AND IFNULL(ea.auction, e.auction) <=> e.auction WHERE e.id = vEktFk - ORDER BY + ORDER BY IF(ea.sub,1,0) * 1000 + IF(ea.kop,1,0) * 100 + IF(ea.pro,1,0) * 10 + @@ -45581,7 +42284,7 @@ BEGIN IF vTravelFk THEN - SELECT MAX(e.id) + SELECT MAX(e.id) INTO vEntryFk FROM vn.entry e JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk @@ -45596,13 +42299,13 @@ BEGIN INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, reference, pro, auction) SELECT vTravelFk, ea.supplierFk, ea.companyFk, cu.id, ea.kop, ea.sub, ea.ref, ea.pro, ea.auction FROM vn.ektEntryAssign ea - JOIN vn.currency cu ON cu.code = 'EUR' + JOIN vn.currency cu ON cu.code = 'EUR' WHERE ea.id = vEntryAssignFk; SET vEntryFk = LAST_INSERT_ID(); END IF; - UPDATE vn.ektEntryAssign + UPDATE vn.ektEntryAssign SET entryFk = vEntryFk WHERE id = vEntryAssignFk; @@ -45636,7 +42339,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getTravel`(vEntryAssignFk INT, v BEGIN /** * Devuelve un vn.travel.id - * + * * @param vEntryAssignFk Identificador de vn.entryAssign */ DECLARE vTravelFk INT; @@ -45697,36 +42400,36 @@ BEGIN DECLARE vCurrentCommission INT; DECLARE vIsCurrencyUsd INT; DECLARE vLastEntryFk INT; - + SELECT count(*) INTO vIsCurrencyUsd FROM currency c WHERE c.code = 'USD' AND id = vCurrencyFk; - + IF NOT vIsCurrencyUsd THEN - + SELECT e.id INTO vLastEntryFk FROM vn.entry e JOIN vn.travel tr ON tr.id = e.travelFk WHERE e.supplierFk = vSupplierFk ORDER BY tr.landed DESC LIMIT 1; - + IF vLastEntryFk THEN - + SELECT commission INTO vCurrentCommission FROM vn.entry WHERE id = vLastEntryFk; - + ELSE - + SELECT commission INTO vCurrentCommission FROM supplier s WHERE s.id = vSupplierFk; - + END IF; - + RETURN vCurrentCommission; - + ELSE SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission @@ -45735,11 +42438,11 @@ BEGIN WHERE t.id = vTravelFk ORDER BY r.`dated` DESC LIMIT 1; - + RETURN IFNULL(vCommission, 0); - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45790,10 +42493,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getForLogiflora`(vLanded DATE, vWarehouseFk INT) RETURNS int(11) READS SQL DATA BEGIN - + /** * Devuelve una entrada para Logiflora. Si no existe la crea. - * + * * @param vLanded Fecha de llegada al almacén * @param vWarehouseFk Identificador de vn.warehouse */ @@ -45801,51 +42504,51 @@ BEGIN DECLARE vTravelFk INT; DECLARE vEntryFk INT; DECLARE previousEntryFk INT; - + SET vTravelFk = vn.travel_getForLogiflora(vLanded, vWarehouseFk); - + IF vLanded THEN - - SELECT IFNULL(MAX(id),0) INTO vEntryFk + + SELECT IFNULL(MAX(id),0) INTO vEntryFk FROM vn.entry - WHERE travelFk = vTravelFk + WHERE travelFk = vTravelFk AND isRaid; IF NOT vEntryFk THEN - + INSERT INTO vn.entry(travelFk, supplierFk, commission, companyFk, currencyFk, isRaid) SELECT vTravelFk, s.id, 4, c.id, cu.id, TRUE FROM vn.supplier s JOIN vn.company c ON c.code = 'VNL' JOIN vn.currency cu ON cu.code = 'EUR' WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; - - SELECT MAX(id) INTO vEntryFk + + SELECT MAX(id) INTO vEntryFk FROM vn.entry WHERE travelFk = vTravelFk; - + END IF; + + END IF; - END IF; - - SELECT entryFk INTO previousEntryFk + SELECT entryFk INTO previousEntryFk FROM edi.warehouseFloramondo wf WHERE wf.warehouseFk = vWarehouseFk; - + IF IFNULL(previousEntryFk,0) != vEntryFk THEN - - UPDATE buy b - SET b.printedStickers = 0 + + UPDATE buy b + SET b.printedStickers = 0 WHERE entryFk = previousEntryFk; DELETE FROM buy WHERE entryFk = previousEntryFk; - + DELETE FROM entry WHERE id = previousEntryFk; - + END IF; - + RETURN vEntryFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45878,21 +42581,21 @@ BEGIN SELECT IFNULL(a.isUeeMember, c.isUeeMember), c.id INTO vIsUeeSupplier, vSupplierCountry - FROM entry e - JOIN supplier s ON s.id = e.supplierFk - JOIN country c ON c.id = s.countryFk + FROM entry e + JOIN supplier s ON s.id = e.supplierFk + JOIN country c ON c.id = s.countryFk LEFT JOIN province p ON p.id = s.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk WHERE e.id = vSelf; - + SELECT IFNULL(a.isUeeMember, c.isUeeMember), c.id INTO vIsUeeCompany, vCompanyCountry - FROM entry e - JOIN supplier s ON s.id = e.companyFk - JOIN country c ON c.id = s.countryFk + FROM entry e + JOIN supplier s ON s.id = e.companyFk + JOIN country c ON c.id = s.countryFk LEFT JOIN province p ON p.id = s.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk - WHERE e.id = vSelf; + WHERE e.id = vSelf; RETURN vIsUeeCompany AND vIsUeeSupplier AND (vSupplierCountry <> vCompanyCountry); @@ -45957,17 +42660,17 @@ BEGIN DECLARE vHasDistinctRoutes BOOL; SELECT t.routeFk INTO vRouteFk - FROM vn.expedition e + FROM vn.expedition e JOIN vn.ticket t ON e.ticketFk = t.id WHERE e.id = vExpeditionFk; - + SELECT COUNT(*) > 0 INTO vHasDistinctRoutes FROM vn.expeditionScan es JOIN vn.expedition e ON es.expeditionFk = e.id JOIN vn.ticket t ON e.ticketFk = t.id WHERE es.palletFk = vPalletFk AND t.routeFk <> vRouteFk; - + RETURN vHasDistinctRoutes; END ;; @@ -46028,27 +42731,27 @@ BEGIN DECLARE vDeliveryType INTEGER DEFAULT 0; DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; DECLARE vCode VARCHAR(45); - + SELECT am.deliveryMethodFk - INTO vDeliveryType + INTO vDeliveryType FROM ticket t JOIN agencyMode am ON am.id = t.agencyModeFk WHERE t.id = vTicket; - + CASE vDeliveryType WHEN 1 THEN -- AGENCIAS SET vCode = 'DELIVERED'; - + WHEN 2 THEN -- REPARTO SET vCode = 'ON_DELIVERY'; - + ELSE -- MERCADO, OTROS SELECT MIN(t.warehouseFk <> w.id) INTO isWaitingForPickUp - FROM ticket t + FROM ticket t LEFT JOIN warehouse w ON w.pickUpagencyModeFk = t.agencyModeFk WHERE t.id = vTicket; - + IF isWaitingForPickUp THEN SET vCode = 'WAITING_FOR_PICKUP'; ELSE @@ -46078,28 +42781,28 @@ BEGIN DECLARE vDeliveryType INTEGER DEFAULT 0; DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; DECLARE vCode VARCHAR(45); - - SELECT + + SELECT a.Vista - INTO vDeliveryType + INTO vDeliveryType FROM vn2008.Tickets t JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia WHERE Id_Ticket = vTicket; - + CASE vDeliveryType WHEN 1 THEN -- AGENCIAS SET vCode = 'DELIVERED'; - + WHEN 2 THEN -- REPARTO SET vCode = 'ON_DELIVERY'; - + ELSE -- MERCADO, OTROS SELECT t.warehouse_id <> w.warehouse_id INTO isWaitingForPickUp - FROM vn2008.Tickets t - LEFT JOIN vn2008.warehouse_pickup w + FROM vn2008.Tickets t + LEFT JOIN vn2008.warehouse_pickup w ON w.agency_id = t.Id_Agencia AND w.warehouse_id = t.warehouse_id WHERE t.Id_Ticket = vTicket; - + IF isWaitingForPickUp THEN SET vCode = 'WAITING_FOR_PICKUP'; ELSE @@ -46153,8 +42856,8 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getInventoryDate`() RETURNS date DETERMINISTIC -BEGIN - RETURN vn2008.date_inv(); +BEGIN + RETURN (SELECT inventoried FROM config LIMIT 1); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46207,16 +42910,16 @@ BEGIN DECLARE vReturn DATE; DECLARE vDuaDate DATE; DECLARE vDuaDateDay INT; - + SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate; IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN - SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); + SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN - SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); + SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); END IF; - IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN + IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN IF util.isLeapYear(YEAR(vDuaDate)) THEN SET vPayDay = 29; ELSE @@ -46224,7 +42927,7 @@ BEGIN END IF; END IF; - SELECT DAY(vDuaDate) INTO vDuaDateDay; + SELECT DAY(vDuaDate) INTO vDuaDateDay; RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay))); END ;; DELIMITER ; @@ -46246,11 +42949,11 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `getShipmentHour`(vTicket INT) RETURN READS SQL DATA BEGIN DECLARE vShipmentHour INT; - + SELECT HOUR(shipped) INTO vShipmentHour FROM ticket WHERE id = vTicket; - + IF vShipmentHour = 0 THEN DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer; @@ -46265,11 +42968,11 @@ BEGIN JOIN agencyMode am on am.id = t.agencyModeFk JOIN address a on a.id = t.addressFk WHERE t.id = vTicket; - - SELECT Hora INTO vShipmentHour + + SELECT Hora INTO vShipmentHour FROM tmp.production_buffer; END IF; - + RETURN vShipmentHour; END ;; DELIMITER ; @@ -46294,12 +42997,12 @@ BEGIN SELECT rate3 INTO price FROM vn.priceFixed - WHERE itemFk = vItemFk + WHERE itemFk = vItemFk AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; - SELECT `value` INTO price + SELECT `value` INTO price FROM vn.specialPrice - WHERE itemFk = vItemFk + WHERE itemFk = vItemFk AND clientFk = vClientFk ; RETURN price; END ;; @@ -46323,7 +43026,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `getTicketTrolleyLabelCount`(vTicket BEGIN DECLARE vLabelCount INT DEFAULT 0; - SELECT labelCount INTO vLabelCount + SELECT labelCount INTO vLabelCount FROM ticketTrolley WHERE ticket = vTicket; @@ -46453,17 +43156,17 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `hasItemsInSector`(vTicketFk INT, vSe BEGIN DECLARE vItemCount INT; - + SELECT count(*) INTO vItemCount - FROM vn.sale s + FROM vn.sale s JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk WHERE s.ticketFk = vTicketFk AND p.sectorFk = vSectorFk; - + RETURN vItemCount; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46486,7 +43189,7 @@ BEGIN DECLARE vCountry INT; DECLARE hasSomeNegativeBase BOOLEAN; - SELECT s.countryFk + SELECT s.countryFk INTO vCountry FROM supplier s JOIN ticket t ON t.companyFk = s.id @@ -46495,9 +43198,9 @@ BEGIN SELECT COUNT(*) INTO hasSomeNegativeBase FROM ( SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase - FROM sale s + FROM sale s JOIN item i ON i.id = s.itemFk - JOIN itemTaxCountry itc + JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = vCountry WHERE s.ticketFk = vTicket GROUP BY itc.taxClassFk @@ -46527,12 +43230,12 @@ BEGIN DECLARE totalAmount DECIMAL(10,2); SELECT SUM(vat) INTO totalAmount - FROM ( + FROM ( SELECT iot.vat FROM invoiceOutTax iot JOIN invoiceOut io ON io.id = iot.invoiceOutFk WHERE io.ref = vInvoiceRef - UNION ALL + UNION ALL SELECT ioe.amount FROM invoiceOutExpense ioe JOIN invoiceOut io ON io.id = ioe.invoiceOutFk @@ -46563,23 +43266,23 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceOut_getMaxIssued`(vSerial VAR READS SQL DATA BEGIN /** - * Retorna la fecha a partir de la cual es válido emitir una factura + * Retorna la fecha a partir de la cual es válido emitir una factura * - * @param vSerial Serie de facturación + * @param vSerial Serie de facturación * @param vCompanyFk Empresa factura emitida * @param vYear Año contable * @return vInvoiceOutIssued fecha factura válida */ DECLARE vInvoiceOutIssued DATE; DECLARE vFirstDayOfYear DATE; - + SET vFirstDayOfYear := MAKEDATE(vYear, 1); - SELECT IFNULL(MAX(io.issued), vFirstDayOfYear) INTO vInvoiceOutIssued + SELECT IFNULL(MAX(io.issued), vFirstDayOfYear) INTO vInvoiceOutIssued FROM invoiceOut io WHERE io.serial = vSerial AND io.companyFk = vCompanyFk - AND io.issued BETWEEN vFirstDayOfYear + AND io.issued BETWEEN vFirstDayOfYear AND util.lastDayOfYear(vFirstDayOfYear); RETURN vInvoiceOutIssued; @@ -46605,7 +43308,7 @@ BEGIN DECLARE vIssued DATE; DECLARE vSerial VARCHAR(15); - SELECT issued, ref + SELECT issued, ref INTO vIssued, vSerial FROM invoiceOut WHERE id = vSelf; @@ -46677,9 +43380,9 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceSerial`(vClientFk INT, vCompa DETERMINISTIC BEGIN /** - * Obtiene la serie de de una factura + * Obtiene la serie de de una factura * dependiendo del area del cliente. - * + * * @param vClientFk Id del cliente * @param vCompanyFk Id de la empresa * @param vType Tipo de factura ["R", "M", "G"] @@ -46760,18 +43463,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `isLogifloraDay`(vShipped DATE, vWarehouse INT) RETURNS tinyint(1) DETERMINISTIC BEGIN - + DECLARE vIsLogifloraDay BOOLEAN; SELECT COUNT(*) INTO vIsLogifloraDay FROM edi.warehouseFloramondo wf - JOIN vn.floramondoConfig fc + JOIN vn.floramondoConfig fc WHERE wf.warehouseFk = vWarehouse AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded)) AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded)); - + RETURN vIsLogifloraDay; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46808,7 +43511,7 @@ BEGIN WHERE sl.scan_id = vScanId AND t.Id_Ruta ) t1; - + RETURN vDistinctRoutesInThePallet = 1; END ;; DELIMITER ; @@ -46832,20 +43535,20 @@ BEGIN DECLARE vPacking INTEGER DEFAULT 0; DECLARE vItemFk INTEGER; - + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - - SELECT IFNULL(packing,0) INTO vPacking - FROM vn.buy + + SELECT IFNULL(packing,0) INTO vPacking + FROM vn.buy WHERE id = CAST(vBarcode AS DECIMAL(18,0)); - - - - + + + + IF NOT vPacking THEN CALL cache.last_buy_refresh(FALSE); SELECT IFNULL(packing,1) INTO vPacking - FROM + FROM (SELECT packing , created FROM vn.itemShelving WHERE itemFk = vItemFk @@ -46858,11 +43561,11 @@ BEGIN ) packings ORDER BY created desc LIMIT 1; - + END IF; - + RETURN vPacking; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46887,11 +43590,11 @@ BEGIN DECLARE vColumn INT; DECLARE vClosestParkingFk INT; DECLARE vSectorFk INT; - + SELECT p.column, sectorFk INTO vColumn, vSectorFk FROM vn.parking p WHERE p.id = vParkingFk; - + SELECT itemShelvingFk INTO vClosestParkingFk FROM ( @@ -46901,12 +43604,12 @@ BEGIN JOIN vn.itemPlacementSupplyList ipsl ON ipsl.sectorFk = ispss.sectorFk AND ipsl.itemFk = ispss.itemFk WHERE p.sectorFk = vSectorFk AND ipsl.saldo > 0 - ) sub + ) sub ORDER BY distance LIMIT 1; - + RETURN vClosestParkingFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46928,17 +43631,17 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `itemsInSector_get`(vTicketFk INT, vS BEGIN DECLARE vItemCount INT; - + SELECT count(*) INTO vItemCount - FROM vn.sale s + FROM vn.sale s JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk WHERE s.ticketFk = vTicketFk AND p.sectorFk = vSectorFk; - + RETURN vItemCount; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47011,29 +43714,29 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `item_getPackage`(vItemFk INT) RETURNS varchar(50) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + DECLARE vDiameter INT; DECLARE vPackageFk VARCHAR(50); DECLARE vCoeficient DOUBLE DEFAULT 1.08; - + SELECT MAX(LEFT(value,3)) INTO vDiameter - FROM vn.itemTag it + FROM vn.itemTag it JOIN vn.tag t ON t.id = it.tagFk WHERE it.itemFk = vItemFk AND t.overwrite = 'diameter'; - + SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2))) INTO vPackageFk FROM vn.volumeConfig vc; - + INSERT IGNORE INTO vn.packaging(id, width, `depth`) - SELECT vPackageFk, - FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), + SELECT vPackageFk, + FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter)) FROM vn.volumeConfig vc; - + RETURN vPackageFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47070,7 +43773,7 @@ BEGIN FROM packaging p JOIN item i ON i.id = vSelf WHERE p.id = vPackaging; - + RETURN vVolume; END ;; @@ -47091,7 +43794,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `lastDayOfWeek`(vYear INT, vWeek INT) RETURNS date DETERMINISTIC -BEGIN +BEGIN /** * Returns the date of the last day of the week * @@ -47130,16 +43833,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `machine_checkPlate`(vPlate VARCHAR(1 BEGIN /** * Comprueba si existe matrícula - * + * * @param vPlate matrícula del vehículo * @return Devuelve TRUE en caso de que exista - * + * */ - + IF (SELECT COUNT(*) - FROM machine m + FROM machine m WHERE m.plate = vPlate - ) THEN + ) THEN RETURN TRUE; ELSE RETURN FALSE; @@ -47166,9 +43869,9 @@ BEGIN DECLARE result INT; DECLARE vSenderFk INT; - SELECT id INTO vSenderFk + SELECT id INTO vSenderFk FROM account.user WHERE `name` = account.myUser_getName(); - + RETURN (SELECT messageSendWithUser(vSenderFk, vRecipient, vMessage)); END ;; DELIMITER ; @@ -47195,9 +43898,9 @@ BEGIN DECLARE vSendDate DATETIME DEFAULT util.VN_NOW(); DECLARE vSender VARCHAR(255) CHARSET utf8; - SELECT `name` INTO vSender + SELECT `name` INTO vSender FROM account.user WHERE id = vSenderFK; - + SET vRecipient = LOWER(vRecipient); DROP TEMPORARY TABLE IF EXISTS tRecipients; @@ -47218,7 +43921,7 @@ BEGIN IF vCount = 0 THEN RETURN vCount; - END IF; + END IF; SET vUuid = UUID(); @@ -47229,7 +43932,7 @@ BEGIN message = vMessage, sendDate = vSendDate; - INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate) + INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate) SELECT vUuid, vSender, vRecipient, finalRecipient, vMessage, vSendDate FROM tRecipients; @@ -47303,7 +44006,7 @@ BEGIN -- Devuelte el volumen total de la orden sumada DECLARE vWarehouseId INTEGER; DECLARE vVolume DECIMAL(10,3); - + SELECT IFNULL(SUM(o.amount * ic.cm3delivery)/1000000,0) INTO vVolume FROM hedera.orderRow o JOIN item i ON i.id = o.itemFk @@ -47380,7 +44083,7 @@ BEGIN WHERE cb.id = packagingReturnFk; SET vValue = IF (vAmount IS NULL, - IFNULL(base,0), + IFNULL(base,0), vAmount / IFNULL(upload, 0) + IFNULL(base, 0)); ELSE SET vValue = IFNULL(price, 0) + IFNULL(base, 0); @@ -47441,20 +44144,20 @@ BEGIN DECLARE vRouteFk INT; DECLARE vAddressFk INT; - + DECLARE vLanded DATE; DECLARE vZoneFk INT; DECLARE vSignificativeFriendship INT DEFAULT 6; DECLARE vVolumeMax DECIMAL(5,1) DEFAULT 10; - + SELECT addressFk, zoneFk, landed INTO vAddressFk, vZoneFk, vLanded - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; - + -- Se inicia la selección de rutas posibles con aquellas cuyas agencias alguna vez han estado asociadas con nuestra zona DROP TEMPORARY TABLE IF EXISTS tmp.route; CREATE TEMPORARY TABLE tmp.route - SELECT r.id routeFk, + SELECT r.id routeFk, zf.friendship zoneFriendship FROM vn.route r JOIN cache.zoneAgencyFriendship zf ON zf.agencyModeFk = r.agencyModeFk @@ -47462,16 +44165,16 @@ BEGIN AND zf.zoneFk = vZoneFk AND r.created = vLanded ORDER BY friendship; - + -- Se eliminan aquellas que superan el volumen máximo DELETE r.* - FROM tmp.route r + FROM tmp.route r JOIN (SELECT routeFk, sum(volume) volume FROM vn.saleVolume WHERE landed = vLanded GROUP BY routeFk) sub ON sub.routeFk = r.routeFk WHERE sub.volume > vVolumeMax; - + -- Se ordenan las que quedan en función con la afinidad del resto de consignatarios de cada ruta SELECT routeFk INTO vRouteFk FROM @@ -47483,7 +44186,7 @@ BEGIN ORDER BY zoneFriendship DESC, friendshipSum DESC ) sub LIMIT 1; - + RETURN vRouteFk; END ;; DELIMITER ; @@ -47508,9 +44211,9 @@ BEGIN DECLARE vRouteFk INT; DECLARE vAddressFk INT; DECLARE vShipped DATETIME; - + SELECT addressFk, date(shipped) INTO vAddressFk, vShipped - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; SELECT routeFk INTO vRouteFk @@ -47524,7 +44227,7 @@ BEGIN ORDER BY friendshipSum DESC ) sub LIMIT 1; - + RETURN vRouteFk; END ;; DELIMITER ; @@ -47548,20 +44251,20 @@ BEGIN DECLARE vRouteFk INT; DECLARE vAddressFk INT; - + DECLARE vLanded DATE; DECLARE vZoneFk INT; DECLARE vSignificativeFriendship INT DEFAULT 6; DECLARE vVolumeMax DECIMAL(5,1) DEFAULT 10; - + SELECT addressFk, zoneFk, landed INTO vAddressFk, vZoneFk, vLanded - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; - + -- Se inicia la selección de rutas posibles con aquellas cuyas agencias alguna vez han estado asociadas con nuestra zona DROP TEMPORARY TABLE IF EXISTS tmp.route; CREATE TEMPORARY TABLE tmp.route - SELECT r.id routeFk, + SELECT r.id routeFk, zf.friendship zoneFriendship FROM vn.route r JOIN cache.zoneAgencyFriendship zf ON zf.agencyModeFk = r.agencyModeFk @@ -47569,16 +44272,16 @@ BEGIN AND zf.zoneFk = vZoneFk AND r.created = vLanded ORDER BY friendship; - + -- Se eliminan aquellas que superan el volumen máximo DELETE r.* - FROM tmp.route r + FROM tmp.route r JOIN (SELECT routeFk, sum(volume) volume FROM vn.saleVolume WHERE landed = vLanded GROUP BY routeFk) sub ON sub.routeFk = r.routeFk WHERE sub.volume > vVolumeMax; - + -- Se ordenan las que quedan en función con la afinidad del resto de consignatarios de cada ruta SELECT routeFk INTO vRouteFk FROM @@ -47590,7 +44293,7 @@ BEGIN ORDER BY zoneFriendship DESC, friendshipSum DESC ) sub LIMIT 1; - + RETURN vRouteFk; END ;; DELIMITER ; @@ -47611,26 +44314,26 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `specie_IsForbidden`(vItemFk INT, vAddressFk INT) RETURNS tinyint(1) READS SQL DATA BEGIN - + DECLARE vIsForbbiden BOOL; DECLARE vLeft INT; SELECT zg.lft INTO vLeft - FROM vn.address a - JOIN vn.zoneGeo zg ON zg.name = a.postalCode + FROM vn.address a + JOIN vn.zoneGeo zg ON zg.name = a.postalCode WHERE a.id = vAddressFk; - + SELECT sgi.isForbidden INTO vIsForbbiden - FROM vn.specieGeoInvasive sgi - JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk + FROM vn.specieGeoInvasive sgi + JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk JOIN vn.itemBotanical ib ON ib.genusFk = sgi.genusFk AND sgi.specieFk IN ('sp.',ib.specieFk) WHERE vLeft BETWEEN zg.lft AND zg.rgt AND ib.itemFk = vItemFk - ORDER BY zg.`depth` DESC + ORDER BY zg.`depth` DESC LIMIT 1; RETURN IFNULL(vIsForbbiden, FALSE); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47650,7 +44353,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `testCIF`(vCIF VARCHAR(9)) RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + DECLARE vLetraInicial VARCHAR(1); DECLARE vLetraFinal VARCHAR(1); DECLARE vParteNumerica VARCHAR(7); @@ -47662,60 +44365,60 @@ BEGIN SET vLetraInicial = SUBSTR(vCIF, 1, 1); SET vLetraFinal = SUBSTR(vCIF, 9, 1); SET vParteNumerica = SUBSTR(vCIF, 2, 7); - - WHILE i < 7 DO - + + WHILE i < 7 DO + SET i = i + 1; - + SET vNumero = CAST(SUBSTR(vParteNumerica, i, 1) AS DECIMAL(1,0)); - + IF i MOD 2 THEN - + SET vNumero = vNumero * 2; SET vNumero = vNumero MOD 10 + FLOOR(vNumero/10); - + END IF; - + SET vSuma = vSuma + vNumero; - + END WHILE; - + SET vSuma = vSuma MOD 10; - + IF vSuma > 0 THEN - + SET vSuma = 10 - vSuma; - + END IF; - + -- Comprobación de dígito de control IF CAST(vLetraFinal AS DECIMAL(1,0)) = vSuma THEN - + SET vResult = TRUE; - + END IF; - + IF vSuma = 0 THEN - + SET vSuma = 10; - + END IF; - + IF CHAR(64 + vSuma) = vLetraFinal THEN - + SET vResult = TRUE; - + END IF; - + -- Sólo se aceptan letras como caracter inicial IF ASCII(vLetraInicial) < 65 OR ASCII(vLetraInicial) > 87 THEN -- Ha de ser entre la A y la W - + SET vResult = FALSE; - + END IF; - + RETURN vResult; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47735,7 +44438,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `testNIE`(vNIE VARCHAR(9)) RETURNS tinyint(1) DETERMINISTIC BEGIN - + DECLARE vIndice INT; DECLARE vNumero VARCHAR(7); DECLARE vOperador VARCHAR(9); @@ -47744,45 +44447,45 @@ BEGIN DECLARE vLetraFinal VARCHAR(1); DECLARE vLetrasFinalesPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; DECLARE vLetraInicialEsIncorrecta BOOL DEFAULT FALSE; - + SET vLetraInicial = SUBSTR(vNIE, 1, 1); SET vLetraFinal = SUBSTR(vNIE, 9, 1); SET vNumero = SUBSTR(vNIE, 2, 7); CASE vLetraInicial - + WHEN 'X' THEN - + SET vOperador = "0"; - + WHEN 'Y' THEN - + SET vOperador = "1"; - + WHEN 'Z' THEN - + SET vOperador = "2"; - + ELSE - + SET vLetraInicialEsIncorrecta = TRUE; - + END CASE; - + SET vOperador = CONCAT(vOperador, vNumero); SET vParteNumerica = CAST(vOperador AS DECIMAL(8,0)); SET vIndice = Round(vParteNumerica Mod 23, 0) + 1; IF SUBSTR(vLetrasFinalesPosibles, vIndice, 1) = vLetraFinal AND vLetraInicialEsIncorrecta = FALSE THEN - + RETURN TRUE; - + ELSE - + RETURN FALSE; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47807,23 +44510,23 @@ BEGIN DECLARE vParteNumerica DECIMAL(8,0); DECLARE vLetra VARCHAR(1); DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; - + SET vLetra = SUBSTRING(vNIF, 9, 1); - + SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0)); - + SET vIndice = Round(vParteNumerica MOD 23, 0) + 1; - + If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then - + RETURN TRUE; - + ELSE - + RETURN FALSE; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47843,21 +44546,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketCollection_getNoPacked`(vCollectionFk INT) RETURNS varchar(100) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + /* * return message with tickets and collection if there is tickets of a collection without expeditions - * + * * @param vCollectionFk the collection to check * @return an array with collection and tickets without expeditions - * + * */ - + DECLARE vAnswer VARCHAR(100) DEFAULT ''; IF collection_isPacked(vCollectionFk) = FALSE THEN SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer FROM vn.ticketCollection tc - LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk WHERE tc.collectionFk = vCollectionFk AND ISNULL(e.id); END IF; @@ -47903,9 +44606,9 @@ BEGIN DROP TEMPORARY TABLE tmp.ticket, tmp.ticketTotal; - + RETURN vTotal; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47925,7 +44628,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_general_ci DETERMINISTIC BEGIN - + DECLARE vRestTicketsMaxOrder INT; DECLARE vRestTicketsMinOrder INT; DECLARE vRestTicketsPacking INT; @@ -47937,7 +44640,7 @@ BEGIN DECLARE vExpeditionsCount INT; DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE; -SELECT `order` +SELECT `order` INTO PACKING_ORDER FROM state WHERE code = 'PACKING'; @@ -47948,7 +44651,7 @@ SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0) LEFT JOIN ticketState ts on ts.ticket = t.id WHERE t.id = vTicketId; -SELECT (ag.`name` = 'VN_VALENCIA') +SELECT (ag.`name` = 'VN_VALENCIA') INTO vIsValenciaPath FROM vn2008.Rutas r JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia @@ -47962,7 +44665,7 @@ IF vIsValenciaPath THEN -- Rutas Valencia FROM expedition e JOIN ticket t ON t.id = e.ticketFk WHERE t.routeFk = vMyPath; - + SELECT MAX(ts.productionOrder), MIN(ts.productionOrder) INTO vRestTicketsMaxOrder, vRestTicketsMinOrder FROM ticket t @@ -47971,7 +44674,7 @@ IF vIsValenciaPath THEN -- Rutas Valencia AND t.warehouseFk = vMyWarehouse AND t.id != vTicketid; - SELECT COUNT(*) + SELECT COUNT(*) INTO vRestTicketsPacking FROM ticket t LEFT JOIN ticketState ts on t.id = ts.ticket @@ -48026,9 +44729,9 @@ BEGIN LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id WHERE ticketFk = vTicketFk ) sub; - + RETURN IFNULL(vSplitCounter,'--'); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48077,21 +44780,21 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ticketTotalVolumeBoxes`(vTicketId IN DETERMINISTIC BEGIN -/* +/* * Devuelve el volumen estimado del ticket sumado, en cajas * * vTicketId Numero de ticket - * + * */ DECLARE vVolumeBoxM3 DOUBLE; DECLARE vTicketTotalVolumeBoxes DECIMAL(10,1); DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; - + SELECT volume / 1000000 INTO vVolumeBoxM3 FROM packaging WHERE id = vVnBoxId; - + SET vTicketTotalVolumeBoxes = ticketTotalVolume(vTicketId) / vVolumeBoxM3; - + RETURN vTicketTotalVolumeBoxes; END ;; @@ -48116,7 +44819,7 @@ BEGIN DECLARE vWarehouseFk INT; SELECT warehouseFk INTO vWarehouseFk - FROM ticket + FROM ticket WHERE id = vTicketFk; RETURN vWarehouseFk; @@ -48139,18 +44842,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_CC_volume`(vTicketFk INT) RETURNS decimal(10,1) READS SQL DATA BEGIN - + DECLARE vCC DECIMAL(10,1); SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000) INTO vCC - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk JOIN vn.packaging p ON p.id = 'CC' - JOIN vn.volumeConfig vc + JOIN vn.volumeConfig vc WHERE sv.ticketFk = vTicketFk; - + RETURN vCC; END ;; @@ -48172,44 +44875,44 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_get`(vParamFk INT) RETURNS int(11) READS SQL DATA proc:BEGIN - + /* Devuelve el número de ticket o collection consultando en varias tablas posibles - * + * * @param vParamFk Número a validar * @return vValidFk Identificador validado */ - + DECLARE vValidFk INT; -- Tabla vn.saleGroup SELECT s.ticketFk INTO vValidFk FROM vn.sale s JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk + JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk WHERE sg.id = vParamFk AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()) LIMIT 1; - + IF vValidFk THEN - + RETURN vValidFk; - + LEAVE proc; - + END IF; -- Tabla vn.collection SELECT c.id INTO vValidFk - FROM vn.collection c + FROM vn.collection c WHERE c.id = vParamFk AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); - + IF vValidFk THEN - + RETURN vValidFk; - + LEAVE proc; - + END IF; -- Tabla vn.ticket @@ -48217,17 +44920,17 @@ proc:BEGIN FROM vn.ticket t WHERE t.id = vParamFk AND t.shipped > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); - + IF vValidFk THEN - + RETURN vValidFk; - + LEAVE proc; - + END IF; RETURN NULL; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48253,8 +44956,8 @@ BEGIN * @vTicketFk Id del ticket a calcular */ DECLARE deliveryPrice DECIMAL (10,2); - - IF (SELECT isVolumetric FROM ticket t JOIN zone z ON t.zoneFk = z.id + + IF (SELECT isVolumetric FROM ticket t JOIN zone z ON t.zoneFk = z.id WHERE t.id = vTicketFk) THEN SELECT SUM(sv.freight) INTO deliveryPrice FROM vn.saleVolume sv @@ -48265,7 +44968,7 @@ BEGIN LEFT JOIN expedition e ON e.ticketFk = t.id JOIN expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk WHERE t.id = vTicketFk; - + END IF; RETURN deliveryPrice; END ;; @@ -48289,16 +44992,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_getWeight`(vTicketFk INT) RET BEGIN /** * Devuelve el peso total del ticket - * + * * @return Total peso */ - + DECLARE vWeight DECIMAL(10,3); SELECT sum(weight) INTO vWeight FROM saleVolume WHERE ticketFk = vTicketFk; - + RETURN vWeight; END ;; @@ -48320,15 +45023,15 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_HasUbication`(vTicketFk INT) RETURNS tinyint(1) READS SQL DATA BEGIN - + DECLARE hasUbication BOOL; SELECT COUNT(*) INTO hasUbication FROM vn.ticket t JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - WHERE rm.beachFk + WHERE rm.beachFk AND t.id = vTicketFk; - + RETURN hasUbication; END ;; @@ -48477,7 +45180,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `timeWorkerControl_getDirection`(vUse READS SQL DATA BEGIN /** - * Verifica la dirección de la fichada + * Verifica la dirección de la fichada * @param vUserFk Identificador del trabajador * @param vTimed Hora de la fichada * @return Retorna sentido de la fichada 'in, out, middle' @@ -48490,40 +45193,40 @@ BEGIN DECLARE vDayStayMax INT; DECLARE vTimedSeconds INT; DECLARE vLastTimeIn INT; - + SELECT UNIX_TIMESTAMP(vTimed) INTO vTimedSeconds; - + SELECT dayStayMax INTO vDayStayMax FROM vn.workerTimeControlParams; SELECT timed, direction INTO vNext,vNextDirection - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND direction IN ('in','out') AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + SELECT timed, direction INTO vPrevious, vPreviousDirection - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND direction IN ('in','out') AND timed < vTimed ORDER BY timed DESC - LIMIT 1; - - IF (vTimedSeconds - UNIX_TIMESTAMP(vPrevious) + UNIX_TIMESTAMP(vNext) - vTimedSeconds)<= vDayStayMax AND vPreviousDirection = 'in' AND vNextDirection = 'out' THEN + LIMIT 1; + + IF (vTimedSeconds - UNIX_TIMESTAMP(vPrevious) + UNIX_TIMESTAMP(vNext) - vTimedSeconds)<= vDayStayMax AND vPreviousDirection = 'in' AND vNextDirection = 'out' THEN RETURN 'middle'; END IF; - - + + IF (vTimedSeconds> UNIX_TIMESTAMP(vPrevious)) THEN - IF vPreviousDirection = 'in' THEN + IF vPreviousDirection = 'in' THEN RETURN 'out'; ELSE SELECT UNIX_TIMESTAMP(MAX(timed)) INTO vLastTimeIn - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND direction ='in' AND timed < vPrevious; IF vTimedSeconds - vLastTimeIn <= vDayStayMax THEN @@ -48577,11 +45280,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `travel_getForLogiflora`(vLanded DATE, vWarehouseFk INT) RETURNS int(11) READS SQL DATA BEGIN - + /** * Devuelve un número de travel para compras de Logiflora a partir de la fecha de llegada y del almacén. * Si no existe lo genera. - * + * * @param vLanded Fecha de llegada al almacén * @param vWarehouseFk Identificador de vn.warehouse */ @@ -48589,8 +45292,8 @@ BEGIN DECLARE vTravelFk INT; IF vLanded THEN - - SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk + + SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk FROM vn.travel tr JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk @@ -48601,14 +45304,14 @@ BEGIN AND landed = vLanded; IF NOT vTravelFk THEN - + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) - SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id - FROM vn.warehouse wOut + SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id + FROM vn.warehouse wOut JOIN vn.agencyMode am ON am.name = 'LOGIFLORA' WHERE wOut.name = 'Holanda'; - - SELECT MAX(tr.id) INTO vTravelFk + + SELECT MAX(tr.id) INTO vTravelFk FROM vn.travel tr JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk @@ -48616,11 +45319,11 @@ BEGIN AND wOut.name = 'Holanda' AND landed = vLanded; END IF; - + END IF; - + RETURN vTravelFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48647,21 +45350,21 @@ BEGIN DECLARE vChar INT; SET vLength = length(vString); - + WHILE vLength > 0 DO - + SET vChar = MID(vString,vLength,1); - + SET vSeed = vSeed + ASCII(vChar); - + SET vLength = vLength - 1; - + END WHILE; SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; RETURN vCode; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48688,21 +45391,21 @@ BEGIN DECLARE vChar INT; SET vLength = length(vString); - + WHILE vLength > 0 DO - + SET vChar = MID(vString,vLength,1); - + SET vSeed = vSeed + ASCII(vChar); - + SET vLength = vLength - 1; - + END WHILE; SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; RETURN vCode; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48763,15 +45466,15 @@ BEGIN * @param vTimeOut * @return vNigthlyHours */ - DECLARE vNigthlyHours DECIMAL(5,2); + DECLARE vNigthlyHours DECIMAL(5,2); DECLARE vSecondsPerHour INT(4) DEFAULT 3600; - + SELECT GREATEST(0, TIMESTAMPDIFF(SECOND, - IF(TIME(vTimeIn) BETWEEN endNightlyHours AND startNightlyHours, - CONCAT(DATE(vTimeIn), ' ', startNightlyHours), + IF(TIME(vTimeIn) BETWEEN endNightlyHours AND startNightlyHours, + CONCAT(DATE(vTimeIn), ' ', startNightlyHours), vTimeIn), - IF(TIME(vTimeOut) BETWEEN endNightlyHours AND startNightlyHours, - CONCAT(DATE(vTimeOut), ' ', endNightlyHours), + IF(TIME(vTimeOut) BETWEEN endNightlyHours AND startNightlyHours, + CONCAT(DATE(vTimeOut), ' ', endNightlyHours), vTimeOut))) / vSecondsPerHour INTO vNigthlyHours FROM vn.workerTimeControlConfig; @@ -48803,47 +45506,47 @@ BEGIN SELECT dayStayMax INTO vDayStayMax FROM workerTimeControlParams; - + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; IF vDirection = 'out' THEN - + SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk + FROM workerTimeControl + WHERE userFk = vUserFk AND direction = 'in' AND timed < vTimed; - + UPDATE workerTimeControl wtc SET wtc.direction = 'middle' WHERE userFk = vUserFk AND direction = 'out' AND timed BETWEEN vLastIn AND vTimed; - + ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut + + SELECT COUNT(*) INTO vHasDirectionOut FROM workerTimeControl wtc - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); UPDATE workerTimeControl wtc SET wtc.direction = IF (vHasDirectionOut,'middle','out') WHERE userFk = vUserFk AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); END IF; END IF; - + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - + SET vLastInsertedId = LAST_INSERT_ID(); - + CALL workerTimeControlSOWP(vUserFk, vTimed); - + RETURN vLastInsertedId; END ;; DELIMITER ; @@ -48872,47 +45575,47 @@ BEGIN SELECT dayStayMax INTO vDayStayMax FROM workerTimeControlParams; - + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; IF vDirection = 'out' THEN - + SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk + FROM workerTimeControl + WHERE userFk = vUserFk AND direction = 'in' AND timed < vTimed; - + UPDATE workerTimeControl wtc SET wtc.direction = 'middle' WHERE userFk = vUserFk AND direction = 'out' AND timed BETWEEN vLastIn AND vTimed; - + ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut + + SELECT COUNT(*) INTO vHasDirectionOut FROM workerTimeControl wtc - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); UPDATE workerTimeControl wtc SET wtc.direction = IF (vHasDirectionOut,'middle','out') WHERE userFk = vUserFk AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); END IF; END IF; - + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - + SET vLastInsertedId = LAST_INSERT_ID(); - + CALL workerTimeControlSOWP(vUserFk, vTimed); - + RETURN vLastInsertedId; END ;; DELIMITER ; @@ -49023,17 +45726,17 @@ BEGIN * @return Devuelve TRUE en caso de que este trabajando. Si se encuentra en un descanso devolverá FALSE */ DECLARE vLastIn DATETIME ; - + SELECT MAX(timed) INTO vLastIn - FROM vn.workerTimeControl + FROM vn.workerTimeControl WHERE userFk = vWorkerFk AND direction = 'in'; - IF (SELECT MOD(COUNT(*),2) - FROM vn.workerTimeControl - WHERE userFk = vWorkerFk AND + IF (SELECT MOD(COUNT(*),2) + FROM vn.workerTimeControl + WHERE userFk = vWorkerFk AND timed >= vLastIn - ) THEN + ) THEN RETURN TRUE; ELSE RETURN FALSE; @@ -49127,7 +45830,7 @@ BEGIN SET `type` = vType, `name` = vName, parentFk = vParentFk; - + SET vSelf = LAST_INSERT_ID(); UPDATE zoneGeoRecalc SET isChanged = TRUE; @@ -49151,7 +45854,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addNoteFromDelivery`(idTicket INT,nota TEXT) BEGIN - + DECLARE observationTypeFk INT DEFAULT 3; /*3 = REPARTIDOR*/ INSERT INTO ticketObservation(ticketFk,observationTypeFk,description) @@ -49179,23 +45882,23 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `addressTaxArea`() READS SQL DATA BEGIN /** - * Devuelve el taxArea para un conjunto de Consignatarios y empresas, + * Devuelve el taxArea para un conjunto de Consignatarios y empresas, * * @table tmp.addressCompany(addressFk, companyFk) valores a calcular * @return tmp.addressTaxArea(addressFk,companyFk) */ - + DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; CREATE TEMPORARY TABLE tmp.addressTaxArea (PRIMARY KEY (addressFk, companyFk)) ENGINE = MEMORY - SELECT CASE - WHEN (NOT IFNULL(auClient.isUeeMember, cClient.isUeeMember) OR NOT cSupplier.isUeeMember) - AND NOT (auSupplier.id <=> auClient.id) THEN + SELECT CASE + WHEN (NOT IFNULL(auClient.isUeeMember, cClient.isUeeMember) OR NOT cSupplier.isUeeMember) + AND NOT (auSupplier.id <=> auClient.id) THEN 'WORLD' - WHEN cClient.isUeeMember AND cSupplier.isUeeMember AND c.countryFk != s.countryFk AND c.isVies THEN + WHEN cClient.isUeeMember AND cSupplier.isUeeMember AND c.countryFk != s.countryFk AND c.isVies THEN 'CEE' - WHEN a.isEqualizated AND cClient.code = 'ES' THEN + WHEN a.isEqualizated AND cClient.code = 'ES' THEN 'EQU' ELSE 'NATIONAL' @@ -49236,27 +45939,27 @@ BEGIN * @param vAddress id de la direccion * @param vWarehouse id del warehouse * @return vShipped la primera fecha disponible y vLanded la fecha de llegada/recojida -*/ +*/ DECLARE vAgency INT; DECLARE vShipped DATE; DECLARE vLanded DATE DEFAULT util.VN_CURDATE(); SELECT agencyFk INTO vAgency FROM agencyMode WHERE id= vAgencyMode; l: LOOP - + CALL agencyHourGetShipped(vLanded,vAddress,vAgency); - SELECT shipped INTO vShipped + SELECT shipped INTO vShipped FROM tmp.agencyHourGetShipped WHERE warehouseFk = vWarehouse LIMIT 1; - + IF vShipped THEN LEAVE l; END IF; - + SET vLanded = DATE_ADD(vLanded, INTERVAL +1 DAY); - + END LOOP; - + SELECT vShipped,vLanded; END ;; DELIMITER ; @@ -49307,7 +46010,7 @@ BEGIN LIMIT 1 ) t WHERE IF(vDated = util.VN_CURDATE(), t.maxHour > HOUR(util.VN_NOW()), TRUE) AND t.substractDay < 225; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -49330,14 +46033,14 @@ BEGIN * DEPRECATED usar zoneGetWarehouse * Devuelve el listado de agencias disponibles para la fecha, * dirección y warehouuse pasadas - * + * * @param vAddress no puede ser NULL * @param vWarehouse warehouse donde comprobaremos las agencias y fecha * @param vDate Fecha de recogida * @table agencyModeWarehouseList Listado de agencias disponibles */ DECLARE vAgency INT; - DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vDone BOOL DEFAULT FALSE; DECLARE vCur CURSOR FOR SELECT DISTINCT a.id FROM agency a @@ -49361,13 +46064,13 @@ BEGIN PRIMARY KEY(id) ) ENGINE = MEMORY; - + OPEN vCur; FETCH vCur INTO vAgency; WHILE NOT vDone DO - + INSERT INTO tmp.agencyModeWarehouseList SELECT am.id, am.name, am.description,am.deliveryMethodFk, TIMESTAMPADD(DAY, -ah.substractDay, vDate), w.name FROM agencyHour ah @@ -49396,7 +46099,7 @@ BEGIN END WHILE; CLOSE vCur; - + SELECT * FROM tmp.agencyModeWarehouseList; DROP TEMPORARY TABLE tmp.agencyModeWarehouseList; END ;; @@ -49422,9 +46125,9 @@ BEGIN CALL vn.agencyHourGetShipped(vDate, vAddress, vAgency); SELECT * FROM tmp.agencyHourGetShipped; - + DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -49462,7 +46165,7 @@ BEGIN DECLARE cWarehouses CURSOR FOR SELECT warehouseFk, shipped FROM tmp.zoneGetShipped; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -49471,7 +46174,7 @@ BEGIN CALL vn.zone_getShipped (vDate, vAddress, vAgencyMode, FALSE); DROP TEMPORARY TABLE IF EXISTS tmp.availableCalc; - CREATE TEMPORARY TABLE tmp.availableCalc( + CREATE TEMPORARY TABLE tmp.availableCalc( calcFk INT UNSIGNED, PRIMARY KEY (calcFk) ) @@ -49482,7 +46185,7 @@ BEGIN l: LOOP SET vDone = FALSE; FETCH cWarehouses INTO vWarehouse, vShipment; - + IF vDone THEN LEAVE l; END IF; @@ -49515,7 +46218,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `bankEntity_checkBic`(vBic VARCHAR(2 BEGIN /** * If the bic length is Incorrect throw exception - * + * * @param vBic bic code */ @@ -49523,7 +46226,7 @@ BEGIN SELECT bicLength INTO vConfigBicLenght FROM vn.bankEntityConfig bec; - + IF LENGTH(vBic) <> vConfigBicLenght THEN CALL util.throw(CONCAT('bic must be of length ', vConfigBicLenght )); END IF; @@ -49550,14 +46253,14 @@ BEGIN * Manda correo cuando caduca un seguro * de los leasing * -*/ +*/ INSERT INTO mail (receiver,replyTo,subject,body) SELECT 'administracion@verdnatura.es' receiver, 'noreply@verdnatura.es' replyTo, CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') subject, CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') body - FROM vn.bankPolicy bp - LEFT JOIN vn.supplier s + FROM vn.bankPolicy bp + LEFT JOIN vn.supplier s ON s.id = bp.supplierFk LEFT JOIN vn.bank b ON b.id = bp.bankFk @@ -49786,19 +46489,19 @@ BEGIN DECLARE vIsFeedStock BOOL; DECLARE vWeight DECIMAL(10,2); DECLARE vPacking INT; - - SELECT b.entryFk, - b.itemFk, - i.packingOut, - ic.merchandise, + + SELECT b.entryFk, + b.itemFk, + i.packingOut, + ic.merchandise, vc.standardFlowerBox, b.weight, - b.packing - INTO - vEntryFk, - vItemFk, - vPackingOut, - vIsMerchandise, + b.packing + INTO + vEntryFk, + vItemFk, + vPackingOut, + vIsMerchandise, vStandardFlowerBox, vWeight, vPacking @@ -49806,7 +46509,7 @@ BEGIN LEFT JOIN item i ON i.id = b.itemFk LEFT JOIN itemType it ON it.id = i.typeFk LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN packaging p ON p.id = b.packagingFk AND NOT p.isBox + LEFT JOIN packaging p ON p.id = b.packagingFk AND NOT p.isBox JOIN volumeConfig vc ON TRUE WHERE b.id = vSelf; @@ -49823,7 +46526,7 @@ BEGIN warehouseFk = vWarehouse, cm3 = buy_getUnitVolume(vSelf), cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf)); - + IF vWeight AND vPacking THEN UPDATE itemCost SET grams = vWeight * 1000 / vPacking @@ -49844,7 +46547,7 @@ BEGIN WHERE b.id = vSelf; END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -49891,10 +46594,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getSplit`(vSelf INT, vDated DATE) BEGIN /** - * Devuelve tantos registros como etiquetas se necesitan para cada uno de los cubos o cajas de - * las ventas correspondientes a la compra que se pasa como parámetro, en los almacenes que tienen + * Devuelve tantos registros como etiquetas se necesitan para cada uno de los cubos o cajas de + * las ventas correspondientes a la compra que se pasa como parámetro, en los almacenes que tienen * habilitada la venta de productos con stock virtual, aunque los productos pueden ser de cualquier tipo. - * + * * @param vSelf Identificador de vn.buy * @param vDated Fecha de preparación de las ventas que queremos etiquetar */ @@ -49969,7 +46672,7 @@ BEGIN WHILE vLabels >= vCounter DO INSERT INTO tmp.split SET - id = vSaleFk, + id = vSaleFk, labels = vLabels, counter = vCounter; @@ -49991,11 +46694,11 @@ BEGIN -- Devuelve los splits creados SELECT CONCAT(sp.counter,'/',sp.labels) labels, COALESCE(sfc.nickname, sfa.nickname, a.nickname) destination, - s.itemFk, - i.longName, - i.`size`, - vn.ticketSplitCounter(t.id) counter, - IF(sfa.id OR sfc.id, + s.itemFk, + i.longName, + i.`size`, + vn.ticketSplitCounter(t.id) counter, + IF(sfa.id OR sfc.id, a.nickname, CONCAT(a.id, ' ', p.`name`,' (', c.`code`,')')) destination2 FROM tmp.split sp @@ -50040,12 +46743,12 @@ BEGIN item_getVolume(b.itemFk, b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) carros , CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * item_getVolume(b.itemFk, b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) espais - FROM buy b + FROM buy b JOIN tmp.buy tb ON tb.buyFk = b.id JOIN volumeConfig vc JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk - LEFT JOIN temperature t ON t.code = it.temperatureFk + LEFT JOIN temperature t ON t.code = it.temperatureFk GROUP BY Temp; END ;; DELIMITER ; @@ -50065,21 +46768,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolumeByAgency`(vDated DATE, vAgencyFk INT) BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.buy; CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; - INSERT INTO tmp.buy + INSERT INTO tmp.buy SELECT b.id - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk WHERE t.landed = vDated AND t.agencyModeFk IN (0, vAgencyFk); CALL buy_getVolume(); DROP TEMPORARY TABLE tmp.buy; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -50098,19 +46801,19 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolumeByEntry`(vEntryFk INT) BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.buy; CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; - - INSERT INTO tmp.buy + + INSERT INTO tmp.buy SELECT b.id - FROM buy b - JOIN entry e ON e.id = b.entryFk + FROM buy b + JOIN entry e ON e.id = b.entryFk WHERE e.id = vEntryFk; CALL buy_getVolume(); DROP TEMPORARY TABLE tmp.buy; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -50118,14 +46821,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_recalcPrices` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_recalcPrices`() BEGIN @@ -50137,7 +46840,7 @@ BEGIN DECLARE vLanded DATE; DECLARE vWarehouseFk INT; DECLARE vHasNotPrice BOOL; - DECLARE vBuyingValue DECIMAL(10,3); + DECLARE vBuyingValue DECIMAL(10,4); DECLARE vPackagingFk VARCHAR(10); DECLARE vIsWarehouseFloramondo BOOL; @@ -50198,12 +46901,12 @@ BEGIN * inserta en tmp.buyRecalc las compras de un awb * * @param awbFk - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; CREATE TEMPORARY TABLE tmp.buyRecalc SELECT b.id - FROM buy b + FROM buy b JOIN entry e ON e.id = b.entryFk JOIN duaEntry de ON de.entryFk = e.id JOIN dua d ON d.id = de.duaFk @@ -50235,7 +46938,7 @@ BEGIN * Recalcula los precios de una compra * * @param vBuyFk - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; CREATE TEMPORARY TABLE tmp.buyRecalc @@ -50266,12 +46969,12 @@ BEGIN * Recalcula los precios de una entrada * * @param vEntryFk - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; CREATE TEMPORARY TABLE tmp.buyRecalc SELECT b.id - FROM buy b + FROM buy b WHERE b.entryFk = vEntryFk; CALL buy_recalcPrices(); @@ -50311,12 +47014,12 @@ BEGIN LIMIT 0; INSERT INTO tBuy(buyFk) - SELECT b.id + SELECT b.id FROM buy b JOIN tmp.ekt t ON t.ektFk = b.ektFk JOIN vn.entry en ON en.id = b.entryFk JOIN vn.travel tr ON tr.id = en.travelFk - JOIN vn.warehouse w ON w.id = tr.warehouseInFk + JOIN vn.warehouse w ON w.id = tr.warehouseInFk JOIN vn.country c ON c.id = w.countryFk AND c.code = 'NL'; SELECT b.id buy, i.doPhoto do_photo, b.stickers - CAST(b.printedStickers AS INT) stickersToPrint @@ -50382,7 +47085,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_updatePacking`(vWarehouseFk INT, vItemFk INT, vPacking INT) BEGIN /** - * Actualiza packing + * Actualiza packing * * @param vWarehouseFk warehouse del item * @param vItemFk id del item @@ -50392,8 +47095,8 @@ BEGIN UPDATE buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk - SET b.packing = vPacking - WHERE bu.warehouseFk = vWarehouseFk + SET b.packing = vPacking + WHERE bu.warehouseFk = vWarehouseFk AND bu.itemFk = vItemFk; DROP TEMPORARY TABLE tmp.buyUltimate; @@ -50432,7 +47135,7 @@ BEGIN */ DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item - ENGINE = MEMORY + ENGINE = MEMORY SELECT vItemFk itemFk; CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); @@ -50454,7 +47157,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calculate`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) -BEGIN +BEGIN /** * Calcula los articulos disponibles y sus precios * @@ -50462,7 +47165,7 @@ BEGIN * @param vLanded Fecha de recepcion de mercancia * @param vAddressFk Id del consignatario * @param vAgencyModeFk Id de la agencia - * @return tmp.ticketCalculateItem(itemFk, available, producer, + * @return tmp.ticketCalculateItem(itemFk, available, producer, * item, size, stems, category, inkFk, image, origin, price) * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk) * @return tmp.ticketComponent @@ -50497,22 +47200,22 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem; CREATE TEMPORARY TABLE tmp.ticketCalculateItem( - itemFk INT(11) NOT NULL, + itemFk INT(11) NOT NULL, available INT(11), - producer VARCHAR(50), - item VARCHAR(50), - size INT(10) UNSIGNED, - stems INT(11), - category VARCHAR(3), - inkFk VARCHAR(3), + producer VARCHAR(50), + item VARCHAR(50), + size INT(10) UNSIGNED, + stems INT(11), + category VARCHAR(3), + inkFk VARCHAR(3), image VARCHAR(50), - origin VARCHAR(3), + origin VARCHAR(3), price DECIMAL(10,2), priceKg DECIMAL(10,2), `grouping` INT(10) UNSIGNED, PRIMARY KEY `itemFk` (`itemFk`) ) ENGINE = MEMORY DEFAULT CHARSET=utf8; - + OPEN cTravelTree; l: LOOP @@ -50534,20 +47237,20 @@ BEGIN bu.buyFk, vZoneFk FROM `cache`.available a - LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id + LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id AND anr.calc_id = vAvailableNoRaidsCalc JOIN tmp.item i ON i.itemFk = a.item_id JOIN vn.item it ON it.id = i.itemFk JOIN vn.`zone` z ON z.id = vZoneFk - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id - LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk - LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id + LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk + LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID LEFT JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed FROM vn.addressFilter af - JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed - FROM vn.address ad - JOIN vn.province p ON p.id = ad.provinceFk + JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed + FROM vn.address ad + JOIN vn.province p ON p.id = ad.provinceFk WHERE ad.id = vAddressFk ) sub2 ON sub2.provinceFk <=> IFNULL(af.provinceFk, sub2.provinceFk) AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk) @@ -50564,13 +47267,13 @@ BEGIN JOIN vn.itemType itt ON itt.id = it.typeFk JOIN vn.itemCategory itc on itc.id = itt.categoryFk JOIN vn.address ad ON ad.id = vAddressFk - LEFT JOIN vn.clientItemType cit + LEFT JOIN vn.clientItemType cit ON cit.clientFk = ad.clientFk AND cit.itemTypeFk = itt.id - LEFT JOIN vn.zoneItemType zit + LEFT JOIN vn.zoneItemType zit ON zit.zoneFk = vZoneFk AND zit.itemTypeFk = itt.id - LEFT JOIN vn.agencyModeItemType ait + LEFT JOIN vn.agencyModeItemType ait ON ait.agencyModeFk = vAgencyModeFk AND ait.itemTypeFk = itt.id WHERE a.calc_id = vAvailableCalc @@ -50663,7 +47366,7 @@ BEGIN * Calcula los componentes de los articulos de tmp.ticketLot * * @param vZoneFk para calcular el transporte - * @param vAddressFk Consignatario + * @param vAddressFk Consignatario * @param vShipped dia de salida del pedido * @param vWarehouseFk warehouse de salida del pedido * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) @@ -50677,7 +47380,7 @@ BEGIN SELECT clientFk INTO vClientFK FROM address WHERE id = vAddressFk; - + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate (PRIMARY KEY (itemFk, warehouseFk)) ENGINE = MEMORY @@ -50689,7 +47392,7 @@ BEGIN IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing, IFNULL(pf.`grouping`, b.`grouping`) `grouping`, ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, - tl.buyFk, + tl.buyFk, i.typeFk, IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping FROM tmp.ticketLot tl @@ -50697,7 +47400,7 @@ BEGIN JOIN item i ON i.id = tl.itemFk JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN specialPrice sp ON sp.itemFk = i.id + LEFT JOIN specialPrice sp ON sp.itemFk = i.id AND sp.clientFk = vClientFk LEFT JOIN ( SELECT * FROM ( @@ -50716,7 +47419,7 @@ BEGIN LIMIT 10000000000000000000 ) tpf GROUP BY tpf.itemFk, tpf.warehouseFk - ) pf ON pf.itemFk = tl.itemFk + ) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.merchandise @@ -50748,10 +47451,10 @@ BEGIN FROM tmp.ticketComponent tc JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk GROUP BY tc.itemFk, warehouseFk; - + -- RECOBRO INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcb.warehouseFk, tcb.itemFk, c2.id, + SELECT tcb.warehouseFk, tcb.itemFk, c2.id, ROUND(tcb.base * LEAST( MAX(GREATEST(IFNULL(cr.priceIncreasing,0), @@ -50782,29 +47485,29 @@ BEGIN ROUND(base * wm.pricesModifierRate, 3) manaAuto FROM tmp.ticketComponentBase tcb JOIN `client` c on c.id = vClientFk - JOIN workerMana wm ON c.salesPersonFk = wm.workerFk + JOIN workerMana wm ON c.salesPersonFk = wm.workerFk JOIN vn.component c2 ON c2.code = 'autoMana' WHERE wm.isPricesModifierActivated HAVING manaAuto <> 0; - + -- Precios especiales INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, c2.id, GREATEST( - IFNULL(ROUND(tcb.base * c2.tax, 4), 0), + IFNULL(ROUND(tcb.base * c2.tax, 4), 0), IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3 ) cost FROM tmp.ticketComponentBase tcb JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount' - JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk + JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk JOIN vn.item i ON i.id = tcb.itemFk WHERE sp.value IS NULL AND i.supplyResponseFk IS NULL; - -- Individual + -- Individual INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, @@ -50815,10 +47518,10 @@ BEGIN JOIN vn.client c ON c.id = vClientFk JOIN vn.businessType bt ON bt.code = c.businessTypeFk WHERE bt.code = 'individual'; - + -- Venta por paquetes INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 + SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 FROM tmp.ticketComponentCalculate tcc JOIN vn.component c2 ON c2.code = 'salePerPackage' JOIN buy b ON b.id = tcc.buyFk @@ -50830,7 +47533,7 @@ BEGIN SELECT vZoneFk id; CALL zone_getOptionsForShipment(vShipped, TRUE); - + -- Reparto INSERT INTO tmp.ticketComponent SELECT tcc.warehouseFK, @@ -50844,7 +47547,7 @@ BEGIN JOIN agencyMode am ON am.id = z.agencyModeFk JOIN vn.volumeConfig vc JOIN vn.component c2 ON c2.code = 'delivery' - LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk + LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk AND ic.itemFk = tcc.itemFk HAVING cost <> 0; @@ -50897,9 +47600,9 @@ BEGIN CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price, CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg FROM tmp.ticketComponentCalculate tcc - JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk AND tcs.warehouseFk = tcc.warehouseFk - WHERE IFNULL(tcs.classRate, 1) = 1 + WHERE IFNULL(tcs.classRate, 1) = 1 AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0) GROUP BY tcs.warehouseFk, tcs.itemFk; @@ -50936,7 +47639,7 @@ BEGIN SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 ) t GROUP BY itemFk, warehouseFk, `grouping`; - + DROP TEMPORARY TABLE tmp.ticketComponentCalculate, tmp.ticketComponentSum, @@ -50961,7 +47664,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentPrepare`() BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; CREATE TEMPORARY TABLE tmp.ticketComponent ( `warehouseFk` INT UNSIGNED NOT NULL, @@ -50971,9 +47674,9 @@ BEGIN INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), UNIQUE `fkItemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC) )ENGINE=MEMORY DEFAULT CHARSET=utf8; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice; - CREATE TEMPORARY TABLE tmp.ticketComponentPrice ( + CREATE TEMPORARY TABLE tmp.ticketComponentPrice ( `warehouseFk` INT UNSIGNED NOT NULL, `itemFk` INT NOT NULL, `rate` INT NOT NULL, @@ -50982,7 +47685,7 @@ BEGIN `priceKg` DECIMAL(10,4), INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), UNIQUE `fkItemWarehouseRate` (`itemFk` ASC, `warehouseFk` ASC, `rate` ASC) - )ENGINE=MEMORY DEFAULT CHARSET=utf8; + )ENGINE=MEMORY DEFAULT CHARSET=utf8; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51001,7 +47704,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentPurge`() BEGIN - DROP TEMPORARY TABLE + DROP TEMPORARY TABLE tmp.ticketComponentPrice, tmp.ticketComponent, tmp.ticketLot; @@ -51056,7 +47759,7 @@ BEGIN DELETE FROM sms WHERE created < v18Month; DELETE FROM saleTracking WHERE created < vOneYearAgo; DELETE FROM ticketTracking WHERE created < v18Month; - DELETE tobs FROM ticketObservation tobs + DELETE tobs FROM ticketObservation tobs JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo; DELETE FROM sharingCart where ended < vDateShort; @@ -51135,12 +47838,12 @@ BEGIN FROM vn.travel t LEFT JOIN vn.entry e ON e.travelFk = t.id WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; - + UPDATE dms d - JOIN dmsType dt ON dt.id = d.dmsTypeFk - SET d.dmsTypeFk = vTrashId + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, util.VN_CURDATE()); - + -- borrar entradas sin compras DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; CREATE TEMPORARY TABLE tmp.entryToDelete @@ -51159,7 +47862,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.routeToDelete SELECT * FROM vn.route r - WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); + WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); UPDATE tmp.routeToDelete tmp JOIN vn.dms d ON d.id = tmp.gestdocFk @@ -51342,21 +48045,21 @@ BEGIN */ DECLARE vClientDebt DOUBLE; - + SELECT vn.client_getDebt(vClientFk, util.VN_CURDATE()) INTO vClientDebt; - + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) VALUES (vClientFk, 'Saldo pendiente', vClientDebt, util.VN_CURDATE(), 5); - + CALL vn.clientGreugeSpray(vClientFk, TRUE, '', TRUE); - + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) SELECT vClientFk, 'Liquidación cliente', sum(amount), util.VN_CURDATE(), 5 FROM vn.greuge WHERE clientFk = vClientFk; - - UPDATE vn.client - SET salesPersonFk = NULL + + UPDATE vn.client + SET salesPersonFk = NULL WHERE id = vClientFk; END ;; @@ -51447,33 +48150,33 @@ BEGIN DECLARE vIssued DATETIME; DECLARE vBalance DOUBLE DEFAULT 0.00; DECLARE cur CURSOR FOR - SELECT - created, - issued, + SELECT + created, + issued, ROUND(amount, 2) AS balance FROM invoiceOut - WHERE clientFk = vClientFk AND companyFk = vCompanyFk - UNION ALL - SELECT - created, - payed, + WHERE clientFk = vClientFk AND companyFk = vCompanyFk + UNION ALL + SELECT + created, + payed, ROUND(-1 * amountPaid, 2) AS balance - FROM receipt + FROM receipt WHERE clientFk = vClientFk AND companyFk = vCompanyFk ORDER BY issued, created; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + OPEN cur; - + proc: LOOP SET vDone = FALSE; - + FETCH cur INTO vCreated, vIssued, vBalance; IF vDate IS NULL THEN SET vDate=vIssued; END IF; - + IF vDone THEN LEAVE proc; END IF; @@ -51485,66 +48188,66 @@ BEGIN SET vDone = TRUE; END IF; END LOOP; - + CLOSE cur; - - SELECT - issued, - CAST(debtOut AS DECIMAL(10,2)) debtOut, + + SELECT + issued, + CAST(debtOut AS DECIMAL(10,2)) debtOut, CAST(debtIn AS DECIMAL(10,2)) debtIn, - ref, - companyFk, + ref, + companyFk, priority FROM - (SELECT - NULL AS issued, - SUM(amountUnpaid) AS debtOut, - NULL AS debtIn, - 'Saldo Anterior' AS ref, + (SELECT + NULL AS issued, + SUM(amountUnpaid) AS debtOut, + NULL AS debtIn, + 'Saldo Anterior' AS ref, companyFk, - 0 as priority - FROM - (SELECT SUM(amount) AS amountUnpaid, companyFk, 0 + 0 as priority + FROM + (SELECT SUM(amount) AS amountUnpaid, companyFk, 0 FROM invoiceOut - WHERE clientFk = vClientFK - AND issued < vDate - GROUP BY companyFk - - UNION ALL - - SELECT SUM(-1 * amountPaid), companyFk, 0 - FROM receipt - WHERE clientFk = vClientFK - AND payed < vDate - GROUP BY companyFk) AS transactions - GROUP BY companyFk - - UNION ALL - - SELECT - issued, - amount as debtOut, - NULL AS debtIn, + WHERE clientFk = vClientFK + AND issued < vDate + GROUP BY companyFk + + UNION ALL + + SELECT SUM(-1 * amountPaid), companyFk, 0 + FROM receipt + WHERE clientFk = vClientFK + AND payed < vDate + GROUP BY companyFk) AS transactions + GROUP BY companyFk + + UNION ALL + + SELECT + issued, + amount as debtOut, + NULL AS debtIn, ref, companyFk, - 1 - FROM invoiceOut - WHERE clientFk = vClientFK + 1 + FROM invoiceOut + WHERE clientFk = vClientFK AND issued >= vDate - UNION ALL - - SELECT - r.payed, - NULL as debtOut, - r.amountPaid, - r.invoiceFk, + UNION ALL + + SELECT + r.payed, + NULL as debtOut, + r.amountPaid, + r.invoiceFk, r.companyFk, - 0 + 0 FROM receipt r - WHERE r.clientFk = vClientFK - AND r.payed >= vDate) t - INNER JOIN `client` c ON c.id = vClientFK - HAVING debtOut <> 0 OR debtIn <> 0 + WHERE r.clientFk = vClientFK + AND r.payed >= vDate) t + INNER JOIN `client` c ON c.id = vClientFK + HAVING debtOut <> 0 OR debtIn <> 0 ORDER BY issued, priority DESC, debtIn; END ;; DELIMITER ; @@ -51602,13 +48305,13 @@ BEGIN WHERE id = vClientFk; ELSE - + SELECT id INTO vOwner FROM vn.worker WHERE code = vWorkerCode COLLATE utf8_general_ci; END IF; - + DROP TEMPORARY TABLE IF EXISTS tmp.clientList; CREATE TEMPORARY TABLE tmp.clientList SELECT DISTINCT t.clientFk, floor(cr.yearSale / 12) monthSale @@ -51620,7 +48323,7 @@ BEGIN AND t.shipped >= TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) AND c.id != vClientFk HAVING monthSale > 100; - + SELECT SUM(monthSale) INTO vTotalSale FROM tmp.clientList; @@ -51631,7 +48334,7 @@ BEGIN SELECT vClientFk, 'Reparto greuge', -vGreuge, util.VN_CURDATE(), vGreugeTypeFk; END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51826,11 +48529,11 @@ BEGIN LEFT JOIN clientProtected cp ON cp.clientFk = cd.clientFk JOIN client c ON c.id = cd.clientFk JOIN province p ON p.id = c.provinceFk - LEFT JOIN autonomy a ON a.id = p.autonomyFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk JOIN country co ON co.id = p.countryFk WHERE cd.warning = 'third' AND cp.clientFk IS NULL - AND co.code NOT IN ('PT') + AND co.code NOT IN ('PT') AND a.name <> 'Canarias' AND c.salesPersonFk IS NOT NULL; @@ -51941,7 +48644,7 @@ BEGIN JOIN client c ON c.accountingAccount = lc.account WHERE lc.`date` BETWEEN vDateFrom AND vDateTo )sub - GROUP BY companyFk, clientFk + GROUP BY companyFk, clientFk ) sub1 ON sub1.clientFk = c.id JOIN supplier s ON s.id = sub1.companyFk JOIN company co ON co.id = sub1.companyFk @@ -52218,9 +48921,9 @@ BEGIN DECLARE i INT DEFAULT 0; DECLARE c INT DEFAULT 0; DECLARE maxClientFk INT; - + DROP TEMPORARY TABLE IF EXISTS tmp.client; - + CREATE TEMPORARY TABLE tmp.`client` (id INT AUTO_INCREMENT, clientFk INT, @@ -52228,40 +48931,40 @@ BEGIN PRIMARY KEY(id), UNIQUE KEY clientFk (clientFk)) ENGINE = MEMORY; - + INSERT INTO tmp.client(clientFk) SELECT DISTINCT clientFk FROM vn.invoiceOut WHERE issued > TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); - + SELECT max(id) INTO maxClientFk FROM tmp.client; - - + + WHILE i < vNumber DO - + SET i = i + 1; - + WHILE c = 0 DO - + SELECT id INTO c FROM tmp.client WHERE id = floor(RAND() * maxClientFk) + 1 AND isSelected = FALSE LIMIT 1; - + END WHILE; - + -- SELECT i, maxClientFk, c; - - UPDATE tmp.client - SET isSelected = TRUE + + UPDATE tmp.client + SET isSelected = TRUE WHERE id = c; - + SET c = 0; - + END WHILE; - + SELECT c.id, c.name FROM tmp.client tc JOIN vn.client c ON c.id = tc.clientFk WHERE isSelected @@ -52591,15 +49294,15 @@ BEGIN DATE_FORMAT(util.VN_NOW(), '%H:%i' ), ' ', i.name - ) INTO vConcept + ) INTO vConcept FROM item i WHERE i.id = vItemFk; SELECT name INTO vItemName FROM item WHERE id = vBarccodeFk; - SELECT CONCAT('Añadido articulo ', + SELECT CONCAT('Añadido articulo ', vItemName, - ' cantidad:', + ' cantidad:', vQuantity ) INTO vDescription; @@ -52636,7 +49339,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_assign`(vUserFk INT, OUT vCollectionFk INT) -proc:BEGIN +proc:BEGIN /* Comprueba si existen colecciones libres que se ajustan al perfil del usuario * y le asigna la más antigua. * Añade un registro al semillero de colecciones @@ -52669,14 +49372,14 @@ proc:BEGIN FROM vn.collection c JOIN vn.ticketCollection tc ON tc.collectionFk = c.id JOIN vn.state s ON s.code = 'PRINTED_AUTO' - JOIN vn.productionConfig pc - WHERE c.workerFk IS NULL + JOIN vn.productionConfig pc + WHERE c.workerFk IS NULL AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; DELETE c.* FROM vn.collection c - JOIN vn.productionConfig pc - WHERE c.workerFk IS NULL + JOIN vn.productionConfig pc + WHERE c.workerFk IS NULL AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; -- Se a�ade registro al semillero @@ -52686,8 +49389,8 @@ proc:BEGIN -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion SELECT MIN(c.id) INTO vCollectionFk - FROM vn.collection c - JOIN vn.operator o + FROM vn.collection c + JOIN vn.operator o ON (o.itemPackingTypeFk = c.itemPackingTypeFk OR c.itemPackingTypeFk IS NULL) AND o.numberOfWagons = c.wagons AND o.trainFk = c.trainFk @@ -52734,18 +49437,18 @@ BEGIN SELECT c.id collectionFk, date(c.created) created, COUNT(DISTINCT tc.ticketFk) ticketTotalCount - FROM collection c - JOIN ticketCollection tc ON tc.collectionFk = c.id - JOIN sale s ON s.ticketFk = tc.ticketFk + FROM collection c + JOIN ticketCollection tc ON tc.collectionFk = c.id + JOIN sale s ON s.ticketFk = tc.ticketFk JOIN ticketState ts ON ts.ticketFk = tc.ticketFk JOIN state s2 ON s2.id = ts.stateFk JOIN productionConfig pc JOIN vn.state ss on ss.code = 'PREPARED' LEFT JOIN vn.saleTracking st on st.saleFk = s.id AND st.stateFk = ss.id - WHERE c.workerFk = vWorkerFk + WHERE c.workerFk = vWorkerFk AND TIMESTAMPDIFF(HOUR, c.created , util.VN_NOW()) < pc.pendingCollectionsAge AND s.quantity != 0 - AND s2.order < pc.pendingCollectionsOrder + AND s2.order < pc.pendingCollectionsOrder GROUP BY c.id HAVING COUNT(*) > COUNT(DISTINCT st.id); @@ -52772,15 +49475,15 @@ BEGIN * Selecciona los tickets de una colección/ticket * @param vParamFk ticketFk/collectionFk * @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observaciones - */ + */ DECLARE vItemPackingTypeFk VARCHAR(1); -- Si los sacadores son los de pruebas, pinta los colores SELECT itemPackingTypeFk INTO vItemPackingTypeFk - FROM vn.collection + FROM vn.collection WHERE id = vParamFk; - SELECT t.id ticketFk, + SELECT t.id ticketFk, IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`, am.name agencyName, t.warehouseFk, @@ -52790,20 +49493,20 @@ BEGIN FROM vn.ticket t LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 - LEFT JOIN vn.collectionColors cc - ON cc.wagon = tc.wagon - AND cc.shelve = tc.`level` + LEFT JOIN vn.collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk -- PAK 23/12/21 - LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN vn.client c ON c.id = t.clientFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 1 - WHERE t.id = vParamFk + WHERE t.id = vParamFk AND t.shipped >= util.yesterday() UNION ALL - SELECT t.id ticketFk, + SELECT t.id ticketFk, IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, am.name agencyName, t.warehouseFk, @@ -52813,15 +49516,15 @@ BEGIN FROM vn.ticket t JOIN vn.ticketCollection tc ON t.id = tc.ticketFk LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 - LEFT JOIN vn.collectionColors cc - ON cc.wagon = tc.wagon - AND cc.shelve = tc.`level` + LEFT JOIN vn.collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk -- PAK 23/12/21 - LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN vn.client c ON c.id = t.clientFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 1 WHERE tc.collectionFk = vParamFk; @@ -53184,8 +49887,8 @@ proc:BEGIN -- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo DELETE tt.* FROM tTrain tt - LEFT JOIN (SELECT DISTINCT wagon - FROM tTrain + LEFT JOIN (SELECT DISTINCT wagon + FROM tTrain WHERE ticketFk IS NOT NULL ) nn ON nn.wagon = tt.wagon WHERE nn.wagon IS NULL; @@ -53353,7 +50056,7 @@ BEGIN DECLARE vDone INT DEFAULT FALSE; DECLARE vCursor CURSOR FOR SELECT DISTINCT ticketFk - FROM ticketCollection tc + FROM ticketCollection tc WHERE tc.collectionFk = vSelf; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -53400,25 +50103,25 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `company_getFiscaldata`(workerFk INT) BEGIN - + DECLARE vCompanyFk INT; - - SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) + + SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) INTO vCompanyFk FROM vn.routeConfig rc LEFT JOIN userConfig uc ON uc.userFk = workerFk; - - + + SELECT s.name AS name , s.NIF AS nif , s.street AS street , s.city AS city , - s.postCode AS postCode - - FROM vn.company c + s.postCode AS postCode + + FROM vn.company c JOIN vn.worker w ON w.id = c.workerManagerFk - JOIN vn.supplier s ON s.id = c.id + JOIN vn.supplier s ON s.id = c.id WHERE c.id = vCompanyFk; END ;; DELIMITER ; @@ -53475,7 +50178,7 @@ BEGIN IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa) AS amount, p.dueDated < vStartingDate isBeforeStarting, p.currencyFk - FROM payment p + FROM payment p WHERE p.received > vStartDate AND p.companyFk = vSelf UNION ALL @@ -53483,9 +50186,9 @@ BEGIN r.companyFk, - IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue) AS Total, rv.dueDated < vStartingDate isBeforeStarting, - r.currencyFk - FROM invoiceIn r - INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk + r.currencyFk + FROM invoiceIn r + INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk WHERE r.issued > vStartDate AND r.isBooked AND r.companyFk = vSelf @@ -53537,11 +50240,11 @@ BEGIN -IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue), r.currencyFk, FALSE isPayment, - TRUE - FROM invoiceIn r + TRUE + FROM invoiceIn r LEFT JOIN tOpeningBalances si ON r.companyFk = si.companyFk AND r.supplierFk = si.supplierFk - AND r.currencyFk = si.currencyFk + AND r.currencyFk = si.currencyFk JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk WHERE rv.dueDated >= vStartingDate AND (si.closingBalances IS NULL OR si.closingBalances <> 0) @@ -53596,7 +50299,7 @@ BEGIN FROM tPendingDuedates WHERE balance < vInvalidBalances AND balance > - vInvalidBalances; - + DELETE vp.* FROM tPendingDuedates vp JOIN tRowsToDelete rd ON ( @@ -53624,9 +50327,9 @@ BEGIN FROM tPendingDuedates vp LEFT JOIN supplier s ON s.id = vp.supplierFk LEFT JOIN client c ON c.fi = s.nif - LEFT JOIN clientRisk cr ON cr.clientFk = c.id + LEFT JOIN clientRisk cr ON cr.clientFk = c.id AND cr.companyFk = vp.companyFk; - + DROP TEMPORARY TABLE tOpeningBalances; DROP TEMPORARY TABLE tPendingDuedates; DROP TEMPORARY TABLE tRowsToDelete; @@ -53638,6 +50341,78 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `comparative_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `comparative_add`() +BEGIN +/** + * Inserts sales records less than one month old in comparative. + */ + DECLARE vMaxPeriod INT; + DECLARE vPeriod INT; + DECLARE vWeek INT; + DECLARE vConfigPeriod INT; + DECLARE vConfigWeek INT; + + SELECT period, week INTO vConfigPeriod, vConfigWeek + FROM comparativeAddConfig; + + SELECT IFNULL(MAX(timePeriod), 0) INTO vMaxPeriod + FROM comparative; + + SELECT period - vConfigPeriod, + week + INTO vPeriod, + vWeek + FROM `time` + WHERE dated = util.VN_CURDATE(); + + IF vMaxPeriod < vPeriod + AND vWeek > vConfigWeek THEN + REPLACE comparative( + timePeriod, + itemFk, + warehouseFk, + quantity, + price, + countryFk + ) + SELECT tm.period, + s.itemFk, + t.warehouseFk, + sum(s.quantity), + sum(v.importe), + p.countryFk + FROM bs.ventas v + JOIN time tm ON tm.dated = v.fecha + JOIN sale s ON s.id = v.Id_Movimiento + JOIN itemType tp ON tp.id = v.tipo_id + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN ticket t ON t.id = s.ticketFk + JOIN client c ON c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN address ad ON ad.id = t.addressFk + LEFT JOIN province p ON p.id = ad.provinceFk + WHERE tm.period BETWEEN vMaxPeriod AND vPeriod + AND ct.code <> 'loses' + AND NOT w.code = 'inv' + GROUP BY p.countryFk, s.itemFk, tm.period, t.warehouseFk; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `conveyorExpedition_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53649,7 +50424,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `conveyorExpedition_Add`(vStarted DATETIME, vEnded DATETIME) BEGIN - + DECLARE startingMinute INT; TRUNCATE vn.conveyorExpedition; @@ -53666,23 +50441,23 @@ BEGIN conveyorBuildingClassFk) SELECT e.id, e.created, - 10 * p.depth as depth, + 10 * p.depth as depth, 10 * p.width as width, 10 * p.height as height, IFNULL(t.routeFk,am.agencyFk) routeFk, hour(e.created) * 60 + minute(e.created), IFNULL(et.description , a.name), IFNULL(t.routeFk,am.agencyFk) criterion, - IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass) + IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass) FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.packaging p ON p.id = e.packagingFk LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN vn.agency a ON a.id = am.agencyFk - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk - JOIN vn.packagingConfig pc + LEFT JOIN vn.agency a ON a.id = am.agencyFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + JOIN vn.packagingConfig pc WHERE t.warehouseFk IN (60,1,44) AND e.created BETWEEN vStarted AND vEnded AND p.height < 140 @@ -53691,8 +50466,8 @@ BEGIN SELECT MIN(productionMinute) INTO startingMinute FROM vn.conveyorExpedition ce ; - - UPDATE vn.conveyorExpedition + + UPDATE vn.conveyorExpedition SET productionMinute = productionMinute - startingMinute; END ;; @@ -53761,7 +50536,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `createPedidoInterno`(vItemFk INT,vQuantity INT) BEGIN - + UPDATE vn.item SET upToDown = vQuantity WHERE id = vItemFk; END ;; @@ -53784,52 +50559,52 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `crypt`(vText VARCHAR(255), vKey VAR BEGIN DECLARE vEncryptedText VARCHAR(255) DEFAULT ''; - + DECLARE vKeyLength INT; DECLARE vKeyPosition INT DEFAULT 1; DECLARE vKeyChar VARCHAR(1); - + DECLARE vTextLength INT; DECLARE vTextPosition INT DEFAULT 1; DECLARE vTextChar VARCHAR(1); - + DECLARE vEncryptedChar VARCHAR(1); DECLARE vEncryptedCharPosition INT; - + DECLARE vChain VARCHAR(255) DEFAULT '#$.-_0123456789abcdefghijklmnopqrstuvwxyz'; DECLARE vChainTextPosition INT; DECLARE vChainKeyPosition INT; DECLARE vChainLength INT; - + DECLARE vInvalidadChars VARCHAR(255) DEFAULT ''; - - SET vTextLength = LENGTH(vText); + + SET vTextLength = LENGTH(vText); SET vKeyLength = LENGTH(vKey); SET vChainLength = LENGTH(vChain); - + WHILE vTextPosition <= vTextLength DO - + SET vTextChar = MID(vText,vTextPosition,1); SET vKeyChar = MID(vKey,vKeyPosition,1); - + SET vChainTextPosition = LOCATE(vTextChar, vChain); SET vInvalidadChars = IF(vChainTextPosition, vInvalidadChars, CONCAT(vInvalidadChars,vTextChar)); SET vChainKeyPosition = LOCATE(vKeyChar, vChain); SET vEncryptedCharPosition = vChainTextPosition + vChainKeyPosition; - + IF vEncryptedCharPosition > vChainLength THEN - + SET vEncryptedCharPosition = vEncryptedCharPosition - vChainLength; - + END IF; - + SET vEncryptedChar = MID(vChain, vEncryptedCharPosition,1); - + SET vEncryptedText = CONCAT(vEncryptedText, vEncryptedChar); - + SET vKeyPosition = IF(vKeyPosition = vKeyLength, 1,vKeyPosition + 1); SET vTextPosition = vTextPosition + 1; - + END WHILE; SET vResult = IF(LENGTH(vInvalidadChars), CONCAT('Caracteres no válidos: ',vInvalidadChars),vEncryptedText); @@ -53854,49 +50629,49 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `cryptOff`(vText VARCHAR(255), vKey BEGIN DECLARE vUncryptedText VARCHAR(255) DEFAULT ''; - + DECLARE vKeyLength INT; DECLARE vKeyPosition INT DEFAULT 1; DECLARE vKeyChar VARCHAR(1); - + DECLARE vTextLength INT; DECLARE vTextPosition INT DEFAULT 1; DECLARE vTextChar VARCHAR(1); - + DECLARE vUncryptedChar VARCHAR(1); DECLARE vUncryptedCharPosition INT; - + DECLARE vChain VARCHAR(255) DEFAULT '#$.-_0123456789abcdefghijklmnopqrstuvwxyz'; DECLARE vChainTextPosition INT; DECLARE vChainKeyPosition INT; DECLARE vChainLength INT; - - SET vTextLength = LENGTH(vText); + + SET vTextLength = LENGTH(vText); SET vKeyLength = LENGTH(vKey); SET vChainLength = LENGTH(vChain); - + WHILE vTextPosition <= vTextLength DO - + SET vTextChar = MID(vText,vTextPosition,1); SET vKeyChar = MID(vKey,vKeyPosition,1); - + SET vChainTextPosition = LOCATE(vTextChar, vChain); SET vChainKeyPosition = LOCATE(vKeyChar, vChain); SET vUncryptedCharPosition = vChainTextPosition - vChainKeyPosition; - + IF vUncryptedCharPosition < 1 THEN - + SET vUncryptedCharPosition = vUncryptedCharPosition + vChainLength; - + END IF; - + SET vUncryptedChar = MID(vChain, vUncryptedCharPosition,1); - + SET vUncryptedText = CONCAT(vUncryptedText, vUncryptedChar); - + SET vKeyPosition = IF(vKeyPosition = vKeyLength, 1,vKeyPosition + 1); SET vTextPosition = vTextPosition + 1; - + END WHILE; SET vResult = vUncryptedText; @@ -53992,7 +50767,7 @@ BEGIN OR (vSelf IS NOT NULL AND parentFk = vSelf); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SET vSons = 0; OPEN vChildren; @@ -54003,11 +50778,11 @@ BEGIN IF vDone THEN LEAVE myLoop; END IF; - + SET vIndex = vIndex + 1; SET vLft = vIndex; SET vSons = vSons + 1; - + CALL department_calcTreeRec( vChildFk, CONCAT(vPath, vChildFk, '/'), @@ -54062,7 +50837,7 @@ proc: BEGIN SELECT isChanged INTO vIsChanged FROM department_recalc; - + IF vIsChanged THEN UPDATE department_recalc SET isChanged = FALSE; CALL vn.department_calcTree; @@ -54087,17 +50862,17 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_getHasMistake`() BEGIN - + /** * Obtiene los sectores a los cuales les ponemos errores * */ - + SELECT id, name FROM department WHERE hasToMistake <> FALSE; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54156,19 +50931,19 @@ BEGIN FROM department g JOIN tChilds c ON c.id = g.id WHERE g.parentFk IS NOT NULL; - + INSERT IGNORE INTO tNodes SELECT id FROM tParents; - + IF ROW_COUNT() = 0 THEN LEAVE myLoop; END IF; - + DELETE FROM tChilds; INSERT INTO tChilds SELECT id FROM tParents; END LOOP; - + DROP TEMPORARY TABLE tChilds, tParents; @@ -54235,12 +51010,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceProductionUser_exists`(vUserFk INT) BEGIN - + /* SELECT COUNT(*) AS UserExists - FROM vn.deviceProductionUser dpu + FROM vn.deviceProductionUser dpu WHERE dpu.userFk = vUserFk;*/ SELECT TRUE; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54312,10 +51087,10 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `device_checkLogin`(vUserFk INT, vAndroidID VARCHAR(50)) BEGIN - + /* * Comprueba si está registrado el dispositivo mediante su androidId - * + * * @param vUSerFk el id del user * @param vAndroidID es el identificador android_id del dispositivo */ @@ -54327,20 +51102,20 @@ BEGIN SELECT dpc.isAllUsersallowed INTO vIsAllUsersAllowed FROM vn.deviceProductionConfig dpc; - IF NOT vIsAllUsersAllowed THEN - + IF NOT vIsAllUsersAllowed THEN + SELECT COUNT(*) INTO vIsDepartment - FROM vn.workerDepartment dp + FROM vn.workerDepartment dp JOIN department d ON d.id = dp.departmentFk WHERE dp.workerFk = vUserFk AND d.hasToCheckLogin; - + IF vIsDepartment THEN SELECT COUNT(*) INTO vIsAuthorized - FROM vn.deviceProductionUser dpu + FROM vn.deviceProductionUser dpu JOIN vn.deviceProduction dp ON dp.id = dpu.deviceProductionFk WHERE dpu.userFk = vUserFk AND dp.android_id = vAndroidID; - + IF NOT vIsAuthorized THEN SET vMessage = 'Usuario no autorizado'; END IF; @@ -54370,15 +51145,15 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `duaEntryValueUpdate`(vDuaFk INT) BEGIN UPDATE duaEntry de - JOIN + JOIN ( SELECT b.entryFk, sum(b.quantity * b.buyingValue) as total FROM buy b JOIN duaEntry de ON de.entryFk = b.entryFk WHERE duaFk = vDuaFk GROUP BY b.entryFk ) sub ON sub.entryFk = de.entryFk - - LEFT JOIN + + LEFT JOIN (SELECT e.id, sum(iit.taxableBase) as euros FROM entry e JOIN invoiceInTax iit ON iit.invoiceInFk = e.invoiceInFk @@ -54386,11 +51161,11 @@ BEGIN WHERE de.duaFk = vDuaFk GROUP BY e.id ) sub2 ON sub2.id = de.entryFk - + SET de.value = sub.total, de.euroValue = sub2.euros WHERE duaFk = vDuaFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54414,7 +51189,7 @@ BEGIN DECLARE vInvoiceFk INT; DECLARE vASIEN BIGINT DEFAULT 0; DECLARE vCounter INT DEFAULT 0; - + DECLARE rs CURSOR FOR SELECT e.invoiceInFk FROM entry e @@ -54427,7 +51202,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN rs; - + UPDATE invoiceIn ii JOIN entry e ON e.invoiceInFk = ii.id JOIN duaEntry de ON de.entryFk = e.id @@ -54439,41 +51214,41 @@ BEGIN ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried), e.isConfirmed = TRUE WHERE d.id = vDuaFk; - + SELECT IFNULL(ASIEN,0) INTO vASIEN FROM dua WHERE id = vDuaFk; - + FETCH rs INTO vInvoiceFk; - + WHILE NOT done DO CALL invoiceIn_booking(vInvoiceFk); - + IF vCounter > 0 OR vASIEN > 0 THEN - + UPDATE vn2008.XDiario x JOIN vn.ledgerConfig lc ON lc.lastBookEntry = x.ASIEN SET x.ASIEN = vASIEN; - + ELSE - + SELECT lastBookEntry INTO vASIEN FROM vn.ledgerConfig; - + END IF; - + SET vCounter = vCounter + 1; - + FETCH rs INTO vInvoiceFk; END WHILE; - + CLOSE rs; - - UPDATE dua + + UPDATE dua SET ASIEN = vASIEN WHERE id = vDuaFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54499,9 +51274,9 @@ BEGIN SELECT awbFk,companyFk FROM dua WHERE id = vDuaFk; - + SELECT LAST_INSERT_ID() INTO vNewDuaFk; - + INSERT INTO duaEntry(duaFk, entryFk, value, customsValue) SELECT vNewDuaFk, entryFk, value, value - customsValue FROM duaEntry @@ -54530,11 +51305,11 @@ BEGIN DECLARE vBookDated DATE; DECLARE vDiff DECIMAL(10,2); DECLARE vApunte BIGINT; - + SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated - FROM dua + FROM dua WHERE id = vDuaFk; - + IF vBookNumber IS NULL OR NOT vBookNumber THEN CALL ledger_next(vBookNumber); END IF; @@ -54545,14 +51320,14 @@ BEGIN ASIEN, FECHA, SUBCTA, - CONCEPTO, + CONCEPTO, EUROHABER, SERIE, empresa_id, CLAVE, FACTURA) - SELECT + SELECT vBookNumber, d.bookEntried, '4700000999', @@ -54565,20 +51340,20 @@ BEGIN FROM duaTax dt JOIN dua d ON d.id = dt.duaFk WHERE dt.duaFk = vDuaFk; - + -- Apuntes por tipo de IVA y proveedor - + INSERT INTO XDiario( ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EURODEBE, BASEEURO, - CONCEPTO, - FACTURA, + CONCEPTO, + FACTURA, IVA, - AUXILIAR, + AUXILIAR, SERIE, FECHA_EX, FECHA_OP, @@ -54598,17 +51373,17 @@ BEGIN FECREGCON ) - SELECT + SELECT vBookNumber ASIEN, vBookDated FECHA, tr.account SUBCTA, '4330002067' CONTRA, sum(dt.tax) EURODEBE, - sum(dt.base) BASEEURO, + sum(dt.base) BASEEURO, CONCAT('DUA nº',d.code) CONCEPTO, d.id FACTURA, dt.rate IVA, - '*' AUXILIAR, + '*' AUXILIAR, 'D' SERIE, d.issued FECHA_EX, d.operated FECHA_OP, @@ -54635,10 +51410,10 @@ BEGIN WHERE ta.effectived <= vBookDated AND taxAreaFk = 'WORLD' ORDER BY ta.effectived DESC - LIMIT 10000000000000000000 + LIMIT 10000000000000000000 ) tba GROUP BY rate - ) tr ON tr.rate = dt.rate + ) tr ON tr.rate = dt.rate JOIN supplier s ON s.id = d.companyFk JOIN country c ON c.id = s.countryFk WHERE d.id = vDuaFk @@ -54647,16 +51422,16 @@ BEGIN SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte FROM XDiario WHERE ASIEN = vBookNumber; - + UPDATE XDiario SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA, - EURODEBE = EURODEBE - vDiff + EURODEBE = EURODEBE - vDiff WHERE id = vApunte; UPDATE dua SET ASIEN = vBookNumber WHERE id = vDuaFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54677,36 +51452,36 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `duaTax_doRecalc`(vDuaFk INT) BEGIN /** * Borra los valores de duaTax y los vuelve a crear en base a la tabla duaEntry - * + * * @param vDuaFk Id del dua a recalcular */ DELETE FROM duaTax WHERE duaFk = vDuaFk; - - INSERT INTO duaTax(duaFk, taxClassFk, base) + + INSERT INTO duaTax(duaFk, taxClassFk, base) SELECT vDuaFk, taxClassFk, SUM(sub.totalBase) FROM intrastat ist JOIN (SELECT i.intrastatFk, - CAST(SUM(b.quantity * - b.buyingValue * - de.customsValue / - de.value) - * di.totalAmount / + CAST(SUM(b.quantity * + b.buyingValue * + de.customsValue / + de.value) + * di.totalAmount / bi.totalAmount AS DECIMAL(10,2) ) totalBase - FROM buy b + FROM buy b JOIN item i ON i.id = b.itemFk JOIN entry e ON e.id = b.entryFk JOIN duaEntry de ON de.entryFk = e.id JOIN( SELECT i.intrastatFk, - CAST(SUM(b.quantity * - b.buyingValue * - de.customsValue / + CAST(SUM(b.quantity * + b.buyingValue * + de.customsValue / de.value) AS DECIMAL(10,2) ) totalAmount - FROM buy b + FROM buy b JOIN item i ON i.id = b.itemFk JOIN entry e ON e.id = b.entryFk JOIN duaEntry de ON de.entryFk = e.id @@ -54721,7 +51496,7 @@ BEGIN ) di ON di.intrastatFk = i.intrastatFk WHERE de.duaFk = vDuaFk GROUP BY i.intrastatFk - HAVING totalBase + HAVING totalBase )sub ON ist.id = sub.intrastatFk GROUP BY ist.taxClassFk; END ;; @@ -54742,13 +51517,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ediTables_Update`() BEGIN - - INSERT IGNORE INTO vn.genus(name) + + INSERT IGNORE INTO vn.genus(name) SELECT latin_genus_name FROM edi.genus ; - INSERT IGNORE INTO vn.specie(name) - SELECT LCASE(latin_species_name) + INSERT IGNORE INTO vn.specie(name) + SELECT LCASE(latin_species_name) FROM edi.specie ; END ;; DELIMITER ; @@ -54788,71 +51563,71 @@ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur1; read_loop: LOOP - + SET done = FALSE; SET vEntryFk = 0; - + FETCH cur1 INTO vId; - + IF done THEN LEAVE read_loop; END IF; - + SELECT IFNULL(e.id,0) INTO vEntryFk FROM vn.entry e JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyModeFk AND ea.supplierFk = e.supplierFk WHERE ea.id = vId AND tr.landed = vLanded LIMIT 1; - + IF NOT vEntryFk THEN - + SELECT IFNULL(e.id,0) INTO vEntryFk FROM vn.entry e JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyModeFk WHERE ea.id = vId AND tr.landed = vLanded AND ea.supplierFk IS NULL LIMIT 1; - + END IF; - + IF NOT vEntryFk THEN - + SET vTravelFk = 0; - - SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk + + SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk FROM vn.travel tr - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyModeFk WHERE ea.id = vId AND tr.landed = vLanded; - + IF NOT vTravelFk THEN - + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) SELECT vLanded, vLanded, warehouseInFk, warehouseOutFk, agencyModeFk - FROM vn.ektEntryAssign + FROM vn.ektEntryAssign WHERE id = vId; - - SELECT MAX(tr.id) INTO vTravelFk + + SELECT MAX(tr.id) INTO vTravelFk FROM vn.travel tr - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyFk WHERE ea.id = vId AND tr.landed = vLanded; - + END IF; - + INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk) SELECT vTravelFk, IFNULL(ea.supplierFk,s.id), c.id, cu.id FROM vn.supplier s @@ -54860,13 +51635,13 @@ OPEN cur1; JOIN vn.currency cu ON cu.code = 'EUR' JOIN vn.ektEntryAssign ea ON ea.id = vId WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; - - SELECT MAX(id) INTO vEntryFk + + SELECT MAX(id) INTO vEntryFk FROM vn.entry WHERE travelFk = vTravelFk; - + END IF; - + UPDATE vn.ektEntryAssign SET entryFk = vEntryFk WHERE id = vId; @@ -54874,7 +51649,7 @@ OPEN cur1; END LOOP; CLOSE cur1; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54894,18 +51669,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `energyMeter_record`(vInput INT, vActiveTime INT) BEGIN DECLARE vConsumption INT; - + SELECT consumption INTO vConsumption FROM energyInput WHERE input = vInput; - INSERT INTO vn.energyMeter - SET - `input` = vInput, - `period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'), + INSERT INTO vn.energyMeter + SET + `input` = vInput, + `period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'), `activeTime` = vActiveTime, `consumption` = CAST(IFNULL((vConsumption / 3600) * vActiveTime, 0) AS DECIMAL(10,2)) - ON DUPLICATE KEY UPDATE + ON DUPLICATE KEY UPDATE `activeTime` = `activeTime` + vActiveTime, `consumption` = `consumption` + CAST(VALUES(`consumption`) AS DECIMAL(10,2)); END ;; @@ -54928,28 +51703,28 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `entryDelivered`(vDated DATE, vEntry BEGIN DECLARE vTravelFk INT; - + SELECT travelFk INTO vTravelFk - FROM vn.entry + FROM vn.entry WHERE id = vEntryFk; - + IF (SELECT COUNT(*) FROM vn.entry WHERE travelFk = vTravelFk) = 1 THEN - + UPDATE vn.travel SET shipped = LEAST(shipped, vDated), landed = vDated WHERE id = vTravelFk; - + ELSE - + INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, ref, isDelivered, isReceived) SELECT LEAST(shipped, vDated), vDated, warehouseInFk, warehouseOutFk, agencyModeFk, CONCAT(account.myUser_getName(),' ', vEntryFk), TRUE, TRUE FROM vn.travel WHERE id = vTravelFk; - + SELECT LAST_INSERT_ID() INTO vTravelFk; - - UPDATE vn.entry - SET travelFk = vTravelFk + + UPDATE vn.entry + SET travelFk = vTravelFk WHERE id = vEntryFk; - + END IF; END ;; @@ -54975,29 +51750,29 @@ BEGIN DECLARE vEntry INT; DECLARE vBucket VARCHAR(10); DECLARE vSupplierFk INT; - + SET vSupplierFk = IF (vLandingWarehouse = 1, 850, 963); -- seleccionamos travel SELECT t.id, e.id INTO vTravel, vEntry FROM travel t LEFT JOIN entry e ON t.id = e.travelFk - WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse + WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse AND t.warehouseInFk = vLandingWarehouse AND t.agencyModeFk IS NULL AND e.supplierFk = vSupplierFk - LIMIT 1; - + LIMIT 1; + -- creamos el travel si es necesario IF IFNULL(vTravel, FALSE) = FALSE THEN INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk) VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse); SELECT LAST_INSERT_ID() INTO vTravel; END IF; - + -- creamos la Entrada si es necesario IF IFNULL(vEntry, FALSE) = FALSE THEN INSERT INTO entry (supplierFk, travelFk) VALUES (vSupplierFk, vTravel); -- proveedor 'CONFECCION ARTIFICIAL' SELECT LAST_INSERT_ID() INTO vEntry; END IF; - + -- creamos el cubo si es necesario SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; IF vBucket IS NULL THEN @@ -55007,7 +51782,7 @@ BEGIN SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; END IF; - INSERT INTO buy(itemFk,quantity, entryFk, packageFk, packing, stickers, buyingValue, price2, price3) + INSERT INTO buy(itemFk,quantity, entryFk, packagingFk, packing, stickers, buyingValue, price2, price3) SELECT itemFk, quantity, vEntry, @@ -55039,7 +51814,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_checkPackaging`(vEntryFk INT) BEGIN /** * Comprueba que los campos package y packaging no sean nulos - * + * * @param vEntryFk Id de entrada */ DECLARE vpackageOrPackingNull INT; @@ -55293,7 +52068,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55313,7 +52088,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55343,7 +52118,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_getRate`(vSelf INT) BEGIN /** - * Prepara una tabla con las tarifas aplicables en funcion de la fecha + * Prepara una tabla con las tarifas aplicables en funcion de la fecha * y el almacén * * @param vSelf Id de la tabla entry @@ -55353,7 +52128,7 @@ BEGIN DECLARE vWarehouseFk INT; SELECT t.landed, t.warehouseInFk INTO vDated, vWarehouseFk - FROM entry e + FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.id = vSelf; @@ -55460,7 +52235,7 @@ BEGIN containerFk, comissionValue, packageValue, - packageFk, + packagingFk, price1, price2, price3, @@ -55481,7 +52256,7 @@ BEGIN containerFk, comissionValue, packageValue, - packageFk, + packagingFk, price1, price2, price3, @@ -55492,7 +52267,7 @@ BEGIN FROM buy b WHERE b.entryFk = vSelf AND b.printedStickers != b.stickers; - + IF vChangeEntry THEN UPDATE buy SET stickers = printedStickers, @@ -55504,7 +52279,7 @@ BEGIN FROM item i WHERE i.description = 'MISFIT' LIMIT 1; - + INSERT INTO buy(entryFk, itemFk, quantity, @@ -55519,7 +52294,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55538,7 +52313,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55571,7 +52346,7 @@ BEGIN UPDATE entry SET gestDocFk = (SELECT gestDocFk FROM entry WHERE id = vSelf LIMIT 1) WHERE id = vNewEntryFk; - + INSERT INTO duaEntry (duaFk, entryFk) SELECT duaFk, vNewEntryFk FROM duaEntry WHERE entryFk = vSelf LIMIT 1; END ;; @@ -55645,12 +52420,12 @@ BEGIN */ DECLARE v_done BOOL DEFAULT FALSE; DECLARE vEntryFk INTEGER; - + DECLARE vCur CURSOR FOR SELECT id FROM tmp.recalcEntryCommision; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; + SET v_done = TRUE; OPEN vCur; @@ -55661,7 +52436,7 @@ BEGIN IF v_done THEN LEAVE l; END IF; - + CALL vn2008.buy_tarifas_entry(vEntryFk); END LOOP; @@ -55686,7 +52461,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitByShelving`(vShelvingFk BEGIN /** * Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr�cula - * + * * @param vShelvingFk Identificador de vn.shelving * @param vFromEntryFk Entrada origen * @param vToEntryFk Entrada destino @@ -55696,49 +52471,49 @@ BEGIN DECLARE vBuyStickers INT; DECLARE vDone BOOLEAN DEFAULT FALSE; - DECLARE cur CURSOR FOR + DECLARE cur CURSOR FOR SELECT bb.id buyFk, FLOOR(ish.visible / ish.packing) ishStickers, bb.stickers buyStickers FROM vn.itemShelving ish - JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM vn.buy b WHERE b.entryFk = vFromEntryFk ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk AND bb.stickers >= FLOOR(ish.visible / ish.packing) WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci GROUP BY ish.id; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Cantidades de la matrícula que exceden la de las entradas - SELECT ish.itemFk, - i.longName, + + -- Cantidades de la matrícula que exceden la de las entradas + SELECT ish.itemFk, + i.longName, FLOOR(ish.visible / ish.packing) AS etiEnMatricula, bb.stickers etiEnEntrada FROM vn.itemShelving ish - JOIN vn.item i ON i.id = ish.itemFk - LEFT JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b + JOIN vn.item i ON i.id = ish.itemFk + LEFT JOIN (SELECT b.id, b.itemFk, b.stickers + FROM vn.buy b WHERE b.entryFk = vFromEntryFk ORDER BY b.stickers DESC LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing) GROUP BY ish.id; - + OPEN cur; read_loop: LOOP SET vDone = FALSE; - + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; - + IF vDone THEN LEAVE read_loop; END IF; - + IF vIshStickers = vBuyStickers THEN UPDATE vn.buy SET entryFk = vToEntryFk @@ -55746,9 +52521,9 @@ BEGIN ELSE UPDATE vn.buy SET stickers = stickers - vIshStickers, - quantity = stickers * packing + quantity = stickers * packing WHERE id = vBuyFk; - + INSERT INTO vn.buy(entryFk, itemFk, quantity, @@ -55763,7 +52538,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55790,7 +52565,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55828,16 +52603,16 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitMisfit`(vSelf INT) BEGIN - + /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original * a la nueva */ - + DECLARE vNewEntryFk INT; DECLARE vBuyFk INT; SELECT MAX(b.id) INTO vBuyFk - FROM vn.buy b + FROM vn.buy b JOIN vn.item i ON i.id = b.itemFk WHERE b.entryFk = vSelf AND i.description = 'MISFIT'; @@ -55846,17 +52621,17 @@ BEGIN SELECT supplierFk, dated, travelFk, currencyFk, companyFk FROM vn.entry e WHERE e.id = vSelf; + + SET vNewEntryFk = LAST_INSERT_ID(); - SET vNewEntryFk = LAST_INSERT_ID(); - - UPDATE vn.buy b + UPDATE vn.buy b SET b.entryFk = vNewEntryFk WHERE b.entryFk = vSelf AND b.id > vBuyFk; - + SELECT vNewEntryFk; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55879,7 +52654,7 @@ BEGIN * Unlock the indicated entry * @vSelf params entry id */ - UPDATE `entry` + UPDATE `entry` SET lockerUserFk = NULL, locked = NULL WHERE id = vSelf; @@ -55910,21 +52685,21 @@ BEGIN DECLARE vComission INT; CREATE OR REPLACE TEMPORARY TABLE tmp.recalcEntryCommision - SELECT e.id + SELECT e.id FROM vn.entry e JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseInFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk WHERE t.shipped >= util.VN_CURDATE() AND e.currencyFk = vCurrency; SET vComission = currency_getCommission(vCurrency); - UPDATE vn.entry e + UPDATE vn.entry e JOIN tmp.recalcEntryCommision tmp ON tmp.id = e.id SET e.commission = vComission; - SELECT `name` INTO vCurrencyName - FROM currency + SELECT `name` INTO vCurrencyName + FROM currency WHERE id = vCurrency; CALL entry_recalc(); @@ -55960,7 +52735,7 @@ BEGIN DECLARE vRouteFk INT DEFAULT 0; SELECT t.routeFk INTO vRouteFk - FROM vn.expedition exp + FROM vn.expedition exp INNER JOIN ticket t on t.id = exp.ticketFk WHERE exp.id = vExpeditionFk; @@ -56163,14 +52938,14 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_printLabel`(vSelf INT) BEGIN /** - * Calls the report_print procedure and passes it + * Calls the report_print procedure and passes it * the necessary parameters for printing. * * @param vSelf expeditioPallet id. */ DECLARE vPrinterFk INT; DECLARE vUserFk INT DEFAULT account.myUser_getId(); - + SELECT o.labelerFk INTO vPrinterFk FROM operator o WHERE o.workerFk = vUserFk; @@ -56237,22 +53012,22 @@ BEGIN DECLARE vTotal INT DEFAULT 0; IF vPalletFk = 0 THEN -- Nuevo pallet - - INSERT INTO vn.expeditionPallet(truckFk) + + INSERT INTO vn.expeditionPallet(truckFk) VALUES(vTruckFk); - + SELECT LAST_INSERT_ID() INTO vPalletFk; - + END IF; - + SELECT COUNT(expeditionFk) INTO vTotal FROM vn.expeditionScan WHERE palletFk = vPalletFk; - + IF vTotal <> 0 THEN - SELECT expeditionFk, + SELECT expeditionFk, palletFk - FROM vn.expeditionScan + FROM vn.expeditionScan WHERE palletFk = vPalletFk; - ELSE + ELSE SELECT 0 expeditionFk,vPalletFk palletFk; END IF; END ;; @@ -56325,12 +53100,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionScan_Put`(vPalletFk INT, vExpeditionFk INT) BEGIN - - REPLACE vn.expeditionScan(expeditionFk, palletFk) + + REPLACE vn.expeditionScan(expeditionFk, palletFk) VALUES(vExpeditionFk, vPalletFk); - + SELECT LAST_INSERT_ID() INTO vPalletFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56349,32 +53124,32 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_add`(vParam INT, vStateCode VARCHAR(100)) BEGIN - + /** * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro - * + * * @param vParam Identificador de vn.expedition o de vn.route * @param vStateCode Corresponde a vn.expeditionStateType.code */ - + IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT e.id, est.id FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.expeditionStateType est ON est.code = vStateCode WHERE t.routeFk = vParam; - + ELSE - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT vParam, est.id FROM vn.expeditionStateType est WHERE est.code = vStateCode; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56406,7 +53181,7 @@ BEGIN SELECT e.id, est.id FROM vn.expedition e JOIN vn.expeditionStateType est ON est.code = vStateCode - JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk; END ;; @@ -56427,14 +53202,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByExpedition`(vExpeditionFk INT, vStateCode VARCHAR(100)) BEGIN - + /** * Inserta nuevos registros en la tabla vn.expeditionState - * + * * @param vExpeditionFk Identificador de vn.expedition * @param vStateCode Corresponde a vn.expeditionStateType.code */ - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT vExpeditionFk, est.id FROM vn.expeditionStateType est @@ -56460,7 +53235,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByPallet`(vPalle BEGIN /** * Inserta nuevos registros en la tabla vn.expeditionState - * + * * @param vPalletFk Identificador de vn.expedition * @param vStateCode Corresponde a vn.expeditionStateType.code */ @@ -56477,7 +53252,7 @@ BEGIN IF NOT hasExpeditions THEN DROP TEMPORARY TABLE tExpeditionScan; - CALL util.throw('palletDoesNotExist'); + CALL util.throw('palletDoesNotExist'); END IF; INSERT INTO vn.expeditionState(expeditionFk, typeFk) @@ -56502,21 +53277,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByRoute`(vRouteFk INT, vStateCode VARCHAR(100)) BEGIN - + /** * Inserta nuevos registros en la tabla vn.expeditionState, por rutas - * + * * @param vRouteFk Identificador de vn.route * @param vStateCode Corresponde a vn.expeditionStateType.code */ - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT e.id, est.id FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.expeditionStateType est ON est.code = vStateCode WHERE t.routeFk = vRouteFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56558,8 +53333,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionTruck_List`() BEGIN - SELECT id truckFk, - eta, + SELECT id truckFk, + eta, description Destino FROM expeditionTruck WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) @@ -56603,7 +53378,7 @@ BEGIN JOIN address a ON t.addressFk = a.id JOIN route r ON r.id = t.routeFk LEFT JOIN warehouse w ON t.warehouseFk = w.id - LEFT JOIN (SELECT sub.ticketFk, + LEFT JOIN (SELECT sub.ticketFk, CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeConcat FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items FROM ticket t @@ -56634,7 +53409,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_getState`(vExpeditionFk INT) BEGIN - + DECLARE vTicketsPendientes INT; DECLARE vEtiquetasTotales INT; DECLARE vEtiquetasEscaneadas INT; @@ -56644,24 +53419,24 @@ BEGIN FROM vn.ticket t JOIN vn.expedition e ON e.ticketFk = t.id WHERE e.id = vExpeditionFk; - + SELECT COUNT(*) INTO vTicketsPendientes FROM vn.ticket t LEFT JOIN vn.expedition e ON e.ticketFk = t.id WHERE t.routeFk = vRouteFk AND ISNULL(e.id); - + SELECT COUNT(*) INTO vEtiquetasTotales - FROM vn.expedition e + FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT COUNT(*) INTO vEtiquetasEscaneadas - FROM vn.expeditionScan es + FROM vn.expeditionScan es JOIN vn.expedition e ON e.id = es.expeditionFk - JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT e.ticketFk ticket, t.nickname cliente, a.city ciudad, @@ -56675,17 +53450,17 @@ BEGIN vTicketsPendientes AS ticketsPendientes, vEtiquetasTotales AS etiquetasTotales, vEtiquetasEscaneadas AS etiquetasEscaneadas - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.`zone`z ON z.id = t.zoneFk - LEFT JOIN vn.route r ON r.id = t.routeFk - LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk WHERE e.id = vExpeditionFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56704,12 +53479,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_StateGet`(vExpeditionFk INT) BEGIN - + /* Devuelve una "ficha" con todos los datos relativos a la expedición - * - * param vExpeditionFk + * + * param vExpeditionFk */ - + DECLARE vTicketsPendientes INT; DECLARE vEtiquetasTotales INT; DECLARE vEtiquetasEscaneadas INT; @@ -56720,34 +53495,34 @@ BEGIN FROM vn.ticket t JOIN vn.expedition e ON e.ticketFk = t.id WHERE e.id = vExpeditionFk; - + SELECT COUNT(*) INTO vTicketsPendientes FROM vn.ticket t LEFT JOIN vn.expedition e ON e.ticketFk = t.id WHERE t.routeFk = vRouteFk AND ISNULL(e.id); - + SELECT COUNT(*) INTO vEtiquetasTotales - FROM vn.expedition e + FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT COUNT(*) INTO vEtiquetasEscaneadas - FROM vn.expeditionScan es + FROM vn.expeditionScan es JOIN vn.expedition e ON e.id = es.expeditionFk - JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT COUNT(*) INTO vEtiquetasLeidasSorter - FROM srt.expedition e + FROM srt.expedition e JOIN vn.expedition ve ON ve.id = e.id LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id - JOIN vn.ticket t ON t.id = ve.ticketFk + JOIN vn.ticket t ON t.id = ve.ticketFk WHERE t.routeFk = vRouteFk AND e.created != e.updated - AND ISNULL(es.expeditionFk); - - + AND ISNULL(es.expeditionFk); + + SELECT e.ticketFk ticket, t.nickname cliente, a.city ciudad, @@ -56762,17 +53537,17 @@ BEGIN vEtiquetasTotales AS etiquetasTotales, vEtiquetasEscaneadas AS etiquetasEscaneadas, vEtiquetasLeidasSorter AS etiquetasSorter - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.`zone`z ON z.id = t.zoneFk - LEFT JOIN vn.route r ON r.id = t.routeFk - LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk WHERE e.id = vExpeditionFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56818,7 +53593,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControl`(vFromDated DATE, vToDated DATE) BEGIN - + DECLARE vSijsnerClientFk INT DEFAULT 19752; DECLARE vDateStart DATETIME; @@ -56827,68 +53602,68 @@ BEGIN SET vDateStart = vFromDated; SET vDateEnd = util.Dayend(vToDated); - SELECT p.id FustCode, - CAST(sent.stucks AS DECIMAL(10,0)) FH, - CAST(tp.stucks AS DECIMAL(10,0)) Tickets, - CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, + SELECT p.id FustCode, + CAST(sent.stucks AS DECIMAL(10,0)) FH, + CAST(tp.stucks AS DECIMAL(10,0)) Tickets, + CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo FROM vn.packaging p LEFT JOIN ( SELECT FustCode, sum(fustQuantity) stucks FROM ( SELECT IFNULL(pe.equivalentFk ,b.packagingFk) FustCode, s.quantity / b.packing AS fustQuantity - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk - JOIN vn.buy b ON b.id = lb.buy_id - JOIN vn.packaging p ON p.id = b.packagingFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk + JOIN vn.buy b ON b.id = lb.buy_id + JOIN vn.packaging p ON p.id = b.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk WHERE t.shipped BETWEEN vDateStart AND vDateEnd AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA') sub + AND p.isPackageReturnable + AND c.country = 'FRANCIA') sub GROUP BY FustCode) sent ON sent.FustCode = p.id LEFT JOIN ( SELECT FustCode, sum(quantity) stucks FROM ( SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk WHERE t.shipped BETWEEN vDateStart AND vDateEnd AND wa.name = 'VNH' - AND p.isPackageReturnable + AND p.isPackageReturnable AND c.country = 'FRANCIA' AND t.clientFk != vSijsnerClientFk - AND tp.quantity > 0) sub + AND tp.quantity > 0) sub GROUP BY FustCode) tp ON tp.FustCode = p.id LEFT JOIN ( SELECT FustCode, sum(quantity) stucks FROM ( SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) AND wa.name = 'VNH' - AND p.isPackageReturnable - AND t.clientFk = vSijsnerClientFk) sub + AND p.isPackageReturnable + AND t.clientFk = vSijsnerClientFk) sub GROUP BY FustCode) sj ON sj.FustCode = p.id - WHERE sent.stucks + WHERE sent.stucks OR tp.stucks OR sj.stucks; @@ -56910,7 +53685,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControlDetail`(vFromDated DATE, vToDated DATE) BEGIN - + DECLARE vSijsnerClientFk INT DEFAULT 19752; DECLARE vDateStart DATETIME; @@ -56918,29 +53693,29 @@ BEGIN SET vDateStart = vFromDated; SET vDateEnd = util.Dayend(vToDated); - + SELECT a.nickname shopName, - a.city , - IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, + a.city , + IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity, tp.ticketFk, CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated) AND wa.name = 'VNH' - AND p.isPackageReturnable + AND p.isPackageReturnable AND c.country = 'FRANCIA' AND t.clientFk != vSijsnerClientFk AND tp.quantity > 0; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56966,8 +53741,8 @@ DECLARE vTicketFk INT; DECLARE vSaleFk INT; DECLARE vClonTicket INT DEFAULT 0; -DECLARE cur1 CURSOR FOR -SELECT s.ticketFk, s.id +DECLARE cur1 CURSOR FOR +SELECT s.ticketFk, s.id FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.item i ON i.id = s.itemFk @@ -56983,17 +53758,17 @@ OPEN cur1; FETCH cur1 INTO vTicketFk, vSaleFk; WHILE done = 0 DO - + SELECT t.id INTO vClonTicket FROM vn.ticket t JOIN (SELECT addressFk, shipped FROM vn.ticket WHERE id = vTicketFk) sub USING(addressFk, shipped) WHERE t.warehouseFk = 44 LIMIT 1; - + SELECT vTicketFk, vClonTicket; - + IF vClonTicket = 0 THEN - + INSERT INTO ticket ( clientFk, shipped, @@ -57021,12 +53796,12 @@ FETCH cur1 INTO vTicketFk, vSaleFk; zonePrice, zoneBonus, routeFk - + FROM ticket WHERE id = vTicketFk; SET vClonTicket = LAST_INSERT_ID(); - + SELECT 'lstID', vClonTicket; /* INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) @@ -57036,20 +53811,20 @@ FETCH cur1 INTO vTicketFk, vSaleFk; WHERE t.id = vClonTicket; */ INSERT INTO ticketLog - SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert', + SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vClonTicket, ' clonando el ', vTicketFk); - + END IF; - + UPDATE vn.sale SET ticketFk = vClonTicket WHERE id = vSaleFk; SET vClonTicket = 0; - + SET done = 0; FETCH cur1 INTO vTicketFk, vSaleFk; - + END WHILE; CLOSE cur1; @@ -57074,8 +53849,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `getDayExpeditions`() BEGIN - SELECT - e.expeditions_id as expeditionFk, + SELECT + e.expeditions_id as expeditionFk, date_format(e.odbc_date,'%Y-%m-%d') as expeditionDate, e.ticket_id as ticketFk, t.routeFk as routeFk @@ -57152,7 +53927,7 @@ BEGIN SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL yearsToDelete YEAR) INTO vDated FROM vn.greugeConfig; - + INSERT INTO vn.greuge(clientFk, description, amount, shipped, created, greugeTypeFk) SELECT clientFk, 'Suma agrupada', SUM(amount), MAX(shipped), MAX(created), greugeTypeFk FROM vn.greuge @@ -57270,8 +54045,8 @@ DECLARE done BOOL DEFAULT FALSE; DECLARE vTicketFk INT; DECLARE rs CURSOR FOR - SELECT id FROM vn.ticket - WHERE shipped = util.yesterday() + SELECT id FROM vn.ticket + WHERE shipped = util.yesterday() AND clientFk = 400 AND warehouseFk IN (1,44); @@ -57282,13 +54057,13 @@ OPEN rs; FETCH rs INTO vTicketFk; WHILE NOT done DO - + INSERT INTO vn.inventoryFailure(dated, itemFk, quantity, value, warehouseFk, throwerFk) - SELECT t.shipped, - s.itemFk, - s.quantity, + SELECT t.shipped, + s.itemFk, + s.quantity, b.buyingValue + b.freightValue + b.packageValue + b.comissionValue, - t.warehouseFk, + t.warehouseFk, w.id FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id @@ -57299,7 +54074,7 @@ WHILE NOT done DO AND s.quantity > 0; FETCH rs INTO vTicketFk; - + END WHILE; @@ -57442,7 +54217,7 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.inventory ( itemFk INT(11) NOT NULL PRIMARY KEY, quantity int(11) DEFAULT '0', - buyingValue decimal(10,3) DEFAULT '0.000', + buyingValue decimal(10,4) DEFAULT '0.0000', freightValue decimal(10,3) DEFAULT '0.000', packing int(11) DEFAULT '0', `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', @@ -57640,7 +54415,7 @@ BEGIN b.id AS buyFk, b.entryFk, b.isIgnored, - b.price2, + b.price2, b.price3, b.stickers, b.packing, @@ -57654,20 +54429,20 @@ BEGIN s.id AS supplierFk, s.name AS supplier FROM itemType it - RIGHT JOIN (entry e + RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk RIGHT JOIN buy b ON b.entryFk = e.id LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk + LEFT JOIN ink ON ink.id = i.inkFk LEFT JOIN travel tr ON tr.id = e.travelFk LEFT JOIN warehouse w ON w.id = tr.warehouseInFk LEFT JOIN origin o ON o.id = i.originFk ) ON it.id = i.typeFk LEFT JOIN edi.ekt ek ON b.ektFk = ek.id WHERE (b.packagingFk = "--" OR b.price2 = 0 OR b.packing = 0 OR b.buyingValue = 0) AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())) AND s.name = 'INVENTARIO'; - + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOk; - CREATE TEMPORARY TABLE tmp.lastEntryOk + CREATE TEMPORARY TABLE tmp.lastEntryOk (PRIMARY KEY (buyFk)) SELECT i.id AS itemFk, @@ -57677,7 +54452,7 @@ BEGIN b.id AS buyFk, b.entryFk, b.isIgnored, - b.price2, + b.price2, b.price3, b.stickers, b.packing, @@ -57691,11 +54466,11 @@ BEGIN s.id AS supplierFk, s.name AS supplier FROM itemType it - RIGHT JOIN (entry e + RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk RIGHT JOIN buy b ON b.entryFk = e.id LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk + LEFT JOIN ink ON ink.id = i.inkFk LEFT JOIN travel tr ON tr.id = e.travelFk LEFT JOIN warehouse w ON w.id = tr.warehouseInFk LEFT JOIN origin o ON o.id = i.originFk @@ -57703,34 +54478,34 @@ BEGIN LEFT JOIN edi.ekt ek ON b.ektFk = ek.id WHERE b.packagingFk != "--" AND b.price2 != 0 AND b.packing != 0 AND b.buyingValue > 0 AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-2,util.VN_CURDATE())) ORDER BY tr.landed DESC; - + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOkGroup; - CREATE TEMPORARY TABLE tmp.lastEntryOkGroup + CREATE TEMPORARY TABLE tmp.lastEntryOkGroup (INDEX (warehouseFk,itemFk)) SELECT * FROM tmp.lastEntryOk tmp GROUP BY tmp.itemFk,tmp.warehouseFk; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.packagingFk = eo.packagingFk WHERE b.packagingFk = "--"; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.price2 = eo.price2 WHERE b.price2 = 0 ; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.packing = eo.packing WHERE b.packing = 0; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.buyingValue = eo.buyingValue WHERE b.buyingValue = 0; - + DROP TEMPORARY TABLE tmp.lastEntry; DROP TEMPORARY TABLE tmp.lastEntryOk; DROP TEMPORARY TABLE tmp.lastEntryOkGroup; @@ -57798,7 +54573,7 @@ BEGIN DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()); - SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate); + SET vMaxTicketDate = util.dayEnd(vMaxTicketDate); DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`; @@ -57890,7 +54665,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInDueDay_calculate`(vInvoiceInFk INT) BEGIN /** - * Calcula los vctos. de una factura recibida + * Calcula los vctos. de una factura recibida * En caso de haberlos informado previamente o que el proveedor sea español, no los recalculará * * @param vInvoiceInFk Factura recibida @@ -57911,46 +54686,46 @@ BEGIN WHERE ii.id = vInvoiceInFk; SELECT COUNT(*) INTO vHasDueDay - FROM invoiceInDueDay iid + FROM invoiceInDueDay iid WHERE iid.invoiceInFk = vInvoiceInFk; IF NOT vHasDueDay AND vCompanyCountryCode = 'ES' THEN SET @cont := 0; INSERT INTO invoiceInDueDay ( - invoiceInFk, - dueDated, - amount, + invoiceInFk, + dueDated, + amount, foreignValue ) SELECT vInvoiceInFk, - IF(payDay, + IF(payDay, IF(getNextDueDate(issued, pdd.detail, payDay) < created, created, - getNextDueDate(issued, pdd.detail, payDay)), + getNextDueDate(issued, pdd.detail, payDay)), GREATEST(created, issued + INTERVAL pdd.detail DAY)), - IF((@cont := @cont + 1) < cont, - TRUNCATE(venc / cont, 2), - venc - (TRUNCATE(venc / cont, 2) * (cont - 1))), - IF(@cont < cont, - TRUNCATE(foreignValue / cont, 2), - foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) - FROM ( - SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100) * vHasDueDayTax) - * iit.taxableBase) / COUNT(DISTINCT(pdd.detail)) venc, + IF((@cont := @cont + 1) < cont, + TRUNCATE(venc / cont, 2), + venc - (TRUNCATE(venc / cont, 2) * (cont - 1))), + IF(@cont < cont, + TRUNCATE(foreignValue / cont, 2), + foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) + FROM ( + SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100) * vHasDueDayTax) + * iit.taxableBase) / COUNT(DISTINCT(pdd.detail)) venc, SUM(iit.foreignValue) / COUNT(DISTINCT(pdd.detail)) foreignValue, - s.payDemFk, + s.payDemFk, ii.companyFk, COUNT(DISTINCT(pdd.detail)) cont, s.payDay, ii.issued, DATE(ii.created) + INTERVAL 2 DAY created - FROM invoiceIn ii - JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id - LEFT JOIN sage.TiposIva ti ON ti.CodigoIva= iit.taxTypeSageFk - JOIN supplier s ON s.id = ii.supplierFk - JOIN payDemDetail pdd ON pdd.id = s.payDemFk - WHERE ii.id = vInvoiceInFk + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + LEFT JOIN sage.TiposIva ti ON ti.CodigoIva= iit.taxTypeSageFk + JOIN supplier s ON s.id = ii.supplierFk + JOIN payDemDetail pdd ON pdd.id = s.payDemFk + WHERE ii.id = vInvoiceInFk GROUP BY ii.id )sub JOIN payDemDetail pdd ON pdd.id = sub.payDemFk @@ -57978,9 +54753,9 @@ BEGIN DELETE FROM invoiceInDueDay WHERE invoiceInFk = vInvoiceInFk; - + CALL invoiceInDueDay_calculate(vInvoiceInFk); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -58053,14 +54828,14 @@ BEGIN DECLARE vLines INT; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; - + SELECT COUNT(*) INTO vLines FROM invoiceInTax WHERE invoiceInFk = vInvoiceInFk; - - IF vLines >= vTaxRowLimit THEN + + IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); - END IF; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -58099,7 +54874,7 @@ BEGIN CALL invoiceInTax_getFromEntries(vInvoiceInFk); CALL invoiceInDueDay_calculate(vInvoiceInFk); - + FETCH rs INTO vInvoiceInFk; END WHILE; @@ -58131,7 +54906,7 @@ BEGIN SELECT MAX(rr.dated) INTO vDated FROM referenceRate rr JOIN invoiceIn ii ON ii.id = vId - WHERE rr.dated <= ii.issued + WHERE rr.dated <= ii.issued AND rr.currencyFk = ii.currencyFk ; IF vDated THEN @@ -58140,13 +54915,13 @@ BEGIN WHERE dated = vDated; END IF; - SELECT id INTO vExpenseFk - FROM vn.expense - WHERE `name` = 'Adquisición mercancia Extracomunitaria' - GROUP BY id + SELECT id INTO vExpenseFk + FROM vn.expense + WHERE `name` = 'Adquisición mercancia Extracomunitaria' + GROUP BY id LIMIT 1; - - DELETE FROM invoiceInTax + + DELETE FROM invoiceInTax WHERE invoiceInFk = vId; INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, foreignValue, taxTypeSageFk, transactionTypeSageFk) @@ -58160,9 +54935,9 @@ BEGIN JOIN entry e ON e.invoiceInFk = ii.id JOIN supplier s ON s.id = e.supplierFk JOIN buy b ON b.entryFk = e.id - LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk + LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk AND rr.dated = ii.issued - WHERE ii.id = vId + WHERE ii.id = vId HAVING taxableBase IS NOT NULL; END ;; DELIMITER ; @@ -58189,7 +54964,7 @@ BEGIN SELECT ii.bookEntried, iit.foreignValue, ii.companyFk, - ii.expenseFkDeductible, + ii.expenseFkDeductible, iit.taxableBase, iit.transactionTypeSageFk, ii.serial, @@ -58228,7 +55003,7 @@ BEGIN JOIN country c ON c.id = s.countryFk JOIN supplier sc ON sc.id = ii.companyFk JOIN country cc ON cc.id = sc.countryFk - JOIN invoiceInSerial iis ON iis.code = ii.serial + JOIN invoiceInSerial iis ON iis.code = ii.serial JOIN siiTypeInvoiceIn cit ON cit.id = ii.siiTypeInvoiceInFk LEFT JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id LEFT JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = iit.transactionTypeSageFk @@ -58251,18 +55026,18 @@ BEGIN NFACTICK, CLAVE, empresa_id) - SELECT + SELECT vBookNumber ASIEN, tii.bookEntried FECHA, tii.supplierAccount SUBCTA, - SUM(tii.taxableBase * - IF(tii.serial= 'R' AND ((tii.taxCode IS NULL OR tii.taxCode <> 'ISP21') - AND tii.taxTypeSageFk IS NOT NULL), - 1 + (tii.PorcentajeIva / 100), - 1)) EUROHABER, - CONCAT('s/fra', - RIGHT(tii.supplierRef, 8), - ':', + SUM(tii.taxableBase * + IF(tii.serial= 'R' AND ((tii.taxCode IS NULL OR tii.taxCode <> 'ISP21') + AND tii.taxTypeSageFk IS NOT NULL), + 1 + (tii.PorcentajeIva / 100), + 1)) EUROHABER, + CONCAT('s/fra', + RIGHT(tii.supplierRef, 8), + ':', LEFT(tii.supplierName, 10)) CONCEPTO, CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10,4)) CAMBIO, SUM(tii.foreignValue * IF(tii.serial = 'R', 1 + (tii.PorcentajeIva / 100), 1)) HABERME, @@ -58279,7 +55054,7 @@ BEGIN CONTRA, EURODEBE, EUROHABER, - CONCEPTO, + CONCEPTO, CAMBIO, DEBEME, HABERME, @@ -58291,9 +55066,9 @@ BEGIN tii.supplierAccount CONTRA, IF(tii.isWithheld AND tii.taxableBase < 0, NULL, ROUND(SUM(tii.taxableBase),2)) EURODEBE, IF(tii.isWithheld AND tii.taxableBase < 0, ROUND(SUM(-tii.taxableBase), 2), NULL) EUROHABER, - CONCAT('s/fra', - RIGHT(tii.supplierRef, 8), - ':', + CONCAT('s/fra', + RIGHT(tii.supplierRef, 8), + ':', LEFT(tii.supplierName, 10)) CONCEPTO, CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10, 4)) CAMBIO, IF(tii.isWithheld, NULL,ABS(ROUND(SUM(tii.foreignValue), 2))) DEBEME, @@ -58305,17 +55080,17 @@ BEGIN GROUP BY tii.expenseFk; -- Líneas de IVA - INSERT INTO XDiario( + INSERT INTO XDiario( ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EURODEBE, BASEEURO, CONCEPTO, - FACTURA, + FACTURA, IVA, - AUXILIAR, + AUXILIAR, SERIE, TIPOOPE, FECHA_EX, @@ -58364,28 +55139,28 @@ BEGIN tii.companyFk FROM tInvoiceIn tii LEFT JOIN ( - SELECT e.id + SELECT e.id FROM tInvoiceIn tii - JOIN expense e ON e.id = tii.expenseFk + JOIN expense e ON e.id = tii.expenseFk WHERE e.isWithheld LIMIT 1 - ) eWithheld ON TRUE - WHERE tii.taxTypeSageFk IS NOT NULL - AND (tii.taxCode IS NULL OR tii.taxCode NOT IN ('import10', 'import21')) + ) eWithheld ON TRUE + WHERE tii.taxTypeSageFk IS NOT NULL + AND (tii.taxCode IS NULL OR tii.taxCode NOT IN ('import10', 'import21')) GROUP BY tii.PorcentajeIva, tii.expenseFk; -- Línea iva inversor sujeto pasivo - INSERT INTO XDiario( + INSERT INTO XDiario( ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EUROHABER, BASEEURO, CONCEPTO, - FACTURA, + FACTURA, IVA, - AUXILIAR, + AUXILIAR, SERIE, TIPOOPE, FECHA_EX, @@ -58434,31 +55209,31 @@ BEGIN JOIN sage.config c WHERE tii.taxCode = 'ISP21' OR MID(tii.supplierAccount, 4, 1) = '1' AND tii.taxTypeSageFk IS NOT NULL - AND NOT(tii.isVies - AND c.nontaxableTransactionTypeFk = tii.transactionTypeSageFk + AND NOT(tii.isVies + AND c.nontaxableTransactionTypeFk = tii.transactionTypeSageFk AND tii.taxCode = 'nonTaxable') GROUP BY tii.PorcentajeIva, tii.expenseFk; - - -- Actualización del registro original + + -- Actualización del registro original UPDATE invoiceIn ii SET ii.isBooked = TRUE WHERE ii.id = vSelf; - + -- Problemas derivados de la precisión en los decimales al calcular los impuestos - UPDATE XDiario - SET EURODEBE = EURODEBE - + UPDATE XDiario + SET EURODEBE = EURODEBE - (SELECT IF(ABS(sub.difference) = 0.01, sub.difference, 0) FROM( - SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference + SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference FROM XDiario WHERE ASIEN = vBookNumber )sub ) - WHERE ASIEN = vBookNumber + WHERE ASIEN = vBookNumber AND EURODEBE <> 0 ORDER BY id DESC LIMIT 1; - + DROP TEMPORARY TABLE tInvoiceIn; END ;; DELIMITER ; @@ -58573,7 +55348,7 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS rs; CREATE TEMPORARY TABLE rs - SELECT + SELECT c.accountingAccount AS clientBookingAccount, io.amount as totalAmount, CONCAT('n/fra ', io.ref) as simpleConcept, @@ -58607,19 +55382,19 @@ BEGIN WHERE io.id = vInvoice; CALL vn.ledger_next(vBookNumber); - + -- Linea del cliente INSERT INTO XDiario( ASIEN, FECHA, - SUBCTA, + SUBCTA, EURODEBE, - CONCEPTO, + CONCEPTO, FECHA_EX, FECHA_OP, empresa_id ) - SELECT + SELECT vBookNumber AS ASIEN, rs.FECHA, rs.clientBookingAccount AS SUBCTA, @@ -58635,14 +55410,14 @@ BEGIN ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EUROHABER, - CONCEPTO, + CONCEPTO, FECHA_EX, FECHA_OP, empresa_id ) - SELECT + SELECT vBookNumber AS ASIEN, rs.FECHA, ioe.expenseFk AS SUBCTA, @@ -58656,8 +55431,8 @@ BEGIN JOIN invoiceOutExpense ioe WHERE ioe.invoiceOutFk = vInvoice; - SELECT GROUP_CONCAT(`name` SEPARATOR ',') - INTO vExpenseConcept + SELECT GROUP_CONCAT(`name` SEPARATOR ',') + INTO vExpenseConcept FROM expense e JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id WHERE ioe.invoiceOutFk = vInvoice; @@ -58667,7 +55442,7 @@ BEGIN ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EUROHABER, BASEEURO, CONCEPTO, @@ -58695,7 +55470,7 @@ BEGIN TIPORECTIF, empresa_id ) - SELECT + SELECT vBookNumber AS ASIEN, rs.FECHA, iot.pgcFk AS SUBCTA, @@ -58715,11 +55490,11 @@ BEGIN rs.FECHA_OP, rs.FECHA_EX, rs.TIPOOPE, - rs.NFACTICK, + rs.NFACTICK, rs.TERIDNIF, rs.TERNIF, rs.TERNOM, - pgc.mod340 AS L340, + pgc.mod340 AS L340, pgc.siiTrascendencyInvoiceOutFk AS TIPOCLAVE, pgc.cplusTaxBreakFk as TIPOEXENCI, rs.TIPONOSUJE, @@ -58727,13 +55502,13 @@ BEGIN rs.TIPORECTIF, rs.companyFk AS empresa_id FROM rs - JOIN invoiceOutTax iot + JOIN invoiceOutTax iot JOIN pgc ON pgc.code = iot.pgcFk LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado - LEFT JOIN pgc pgce ON pgce.code = pe.equFk + LEFT JOIN pgc pgce ON pgce.code = pe.equFk LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv. WHERE iot.invoiceOutFk = vInvoice; - + UPDATE invoiceOut SET booked = util.VN_CURDATE() WHERE id = vInvoice; @@ -58765,7 +55540,7 @@ BEGIN DECLARE done BOOL DEFAULT FALSE; - DECLARE rs CURSOR FOR + DECLARE rs CURSOR FOR SELECT io.id FROM invoiceOut io WHERE RIGHT(ref,7) BETWEEN 1724215 AND 1724224 @@ -58780,15 +55555,15 @@ BEGIN WHILE NOT done DO CALL invoiceOutBooking(vInvoice); - + FETCH rs INTO vInvoice ; - + SET vContador = vContador + 1; - + IF vContador MOD 50 = 0 THEN - + SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS; - + END IF; END WHILE; @@ -58816,7 +55591,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE) BEGIN -SELECT +SELECT c.socialName as RazonSocial, c.fi as NIF, io.ref as Factura, @@ -58828,7 +55603,7 @@ SELECT pgc.rate as Tipo, iot.vat as Cuota, pgc.name as Concepto - + FROM vn.invoiceOut io JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id JOIN vn.client c ON c.id = io.clientFk @@ -58978,14 +55753,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOut_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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET character_set_client = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new`( vSerial VARCHAR(255), @@ -59132,17 +55907,17 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador + SELECT s.id, ti.id ticket_id, vWorker Id_Trabajador FROM tmp.ticketToInvoice ti LEFT JOIN ticketState ts ON ti.id = ts.ticket JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); + WHERE IFNULL(ts.alertLevel, 0) < 3 and s.`code` = getAlert3State(ti.id); - INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT * FROM tmp.updateInter; CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); + CALL invoiceTaxMake(vNewInvoiceId, vTaxArea); UPDATE invoiceOut io JOIN ( @@ -59273,17 +56048,17 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_newFromClient`( - IN vClientFk INT, - IN vSerial CHAR(2), + IN vClientFk INT, + IN vSerial CHAR(2), IN vMaxShipped DATE, - IN vCompanyFk INT, + IN vCompanyFk INT, IN vTaxArea VARCHAR(25), - IN vRef VARCHAR(25), + IN vRef VARCHAR(25), OUT vInvoiceId INT) BEGIN /** * Factura los tickets de un cliente hasta una fecha dada - * @param vClientFk Id del cliente a facturar + * @param vClientFk Id del cliente a facturar * @param vSerial Serie de factura * @param vMaxShipped Fecha hasta la cual cogera tickets para facturar * @param vCompanyFk Id de la empresa desde la que se factura @@ -59302,11 +56077,11 @@ BEGIN IF NOT vIsRefEditable THEN CALL util.throw('serial non editable'); END IF; - END IF; + END IF; SELECT COUNT(*) INTO vIsExportation FROM vn.invoiceOutSerial - WHERE taxAreaFk = 'WORLD' + WHERE taxAreaFk = 'WORLD' AND `code` = vSerial; IF vIsExportation THEN @@ -59319,7 +56094,7 @@ BEGIN UPDATE invoiceOut SET `ref` = vRef - WHERE id = vInvoiceId + WHERE id = vInvoiceId AND vRef IS NOT NULL; IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN @@ -59348,7 +56123,7 @@ BEGIN * Factura un ticket * @param vTicketFk Id del ticket * @param vSerial Serie de factura - * @param vTaxArea Area de la factura en caso de querer forzarlo, + * @param vTaxArea Area de la factura en caso de querer forzarlo, * en la mayoria de los casos poner NULL * @return vInvoiceId */ @@ -59363,11 +56138,11 @@ BEGIN IF NOT vIsRefEditable THEN CALL util.throw('serial non editable'); END IF; - - UPDATE invoiceOut + + UPDATE invoiceOut SET `ref` = vRef WHERE id = vInvoiceId; - END IF; + END IF; IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN CALL invoiceOutBooking(vInvoiceId); @@ -59449,7 +56224,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemBarcode_update`(vItemFk INT,vCo BEGIN IF vDelete THEN DELETE FROM vn.itemBarcode WHERE itemFk = vItemFk AND code = vCode; -ELSE +ELSE INSERT INTO vn.itemBarcode(itemFk,code) VALUES (vItemFk,vCode); END IF; @@ -59473,33 +56248,33 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemFuentesBalance`(vDaysInFuture I BEGIN /* Se utiliza para calcular la necesidad de mover mercancia entre el almacén de fuentes y el nuestro - * + * * @param vDaysInFuture Rango de dias para calcular entradas y salidas - * + * */ - + DECLARE vWarehouseFk INT; SELECT s.warehouseFk INTO vWarehouseFk - FROM vn.sector s + FROM vn.sector s WHERE s.code = 'FUENTES_PICASSE'; - + CALL cache.stock_refresh(FALSE); - SELECT i.id itemFk, + SELECT i.id itemFk, i.longName, i.size, i.subName, - v.amount - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as visible, - fue.Fuentes, + v.amount - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as visible, + fue.Fuentes, alb.Albenfruit, - sale.venta, - IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, - IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) + sale.venta, + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, + IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as saldo - FROM vn.item i - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk LEFT JOIN ( SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Fuentes FROM vn.itemShelving ish @@ -59507,7 +56282,7 @@ BEGIN JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.code = 'FUENTES_PICASSE' - GROUP BY ish.itemFk + GROUP BY ish.itemFk ) fue ON fue.itemFk = i.id LEFT JOIN ( SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Albenfruit @@ -59516,7 +56291,7 @@ BEGIN JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.code = 'ALBENFRUIT' - GROUP BY ish.itemFk + GROUP BY ish.itemFk ) alb ON alb.itemFk = i.id LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk LEFT JOIN ( @@ -59541,9 +56316,9 @@ BEGIN AND warehouse_id = vWarehouseFk GROUP BY item_id ) mov ON mov.item_id = i.id - WHERE (v.amount OR fue.Fuentes OR alb.Albenfruit) + WHERE (v.amount OR fue.Fuentes OR alb.Albenfruit) AND i.itemPackingTypeFk = 'H' - AND ic.shortLife + AND ic.shortLife ; END ;; @@ -59565,7 +56340,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementFromTicket`(vTicket INT) BEGIN /** - * Llama a itemPlacementUpdateVisible + * Llama a itemPlacementUpdateVisible * de los articulos de la tabla temporal tmp.itemPlacement(itemFk) * @treturn tmp.itemPlacement * @param vTicket Id del Ticket @@ -59579,9 +56354,9 @@ BEGIN FROM ticket t JOIN sale s ON s.ticketFk = t.id WHERE t.id = vTicket; - + CALL itemPlacementUpdateVisible(); - + DROP TEMPORARY TABLE tmp.itemPlacement; END ;; DELIMITER ; @@ -59614,7 +56389,7 @@ BEGIN CAST(FLOOR(LEAST(ish.stock,quantity) / ish.packing) AS DECIMAL(10,0)), ' x ', ish.packing, - IF ( + IF ( LEAST(ish.stock,quantity) MOD ish.packing, CONCAT(' + ',CAST(LEAST(ish.stock,quantity) MOD ish.packing AS DECIMAL(10,0))), '' @@ -59645,7 +56420,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSupplyCloseOrder`(vId INT, vQuantity INT) BEGIN - UPDATE vn.itemPlacementSupply + UPDATE vn.itemPlacementSupply SET priority = 10 WHERE id = vId; @@ -59671,7 +56446,7 @@ BEGIN DECLARE vId INT; DECLARE vLastParkingFk INT; DECLARE vNextParkingFk INT; - + SELECT sh.parkingFk INTO vLastParkingFk FROM vn.itemShelvingPlacementSupply isps JOIN vn.itemShelving ish ON ish.id = isps.itemShelvingFk @@ -59679,9 +56454,9 @@ BEGIN WHERE isps.userFk = getUser() ORDER BY isps.created DESC LIMIT 1; - + SET vNextParkingFk = vn.itemShelvingPlacementSupply_ClosestGet(vLastParkingFk); - + SELECT ipsl.id INTO vId FROM vn.itemPlacementSupplyList ipsl JOIN vn.itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk @@ -59690,13 +56465,13 @@ BEGIN AND ipsl.sectorFk = vSector ORDER BY ipsl.repoUserFk DESC, ipsl.priority DESC, (ispss.parkingFk = vNextParkingFk) DESC, ispss.parking DESC, ipsl.created LIMIT 1; - + UPDATE vn.itemPlacementSupply SET repoUserFk = getUser() WHERE id = vId; - - SELECT * FROM vn.itemPlacementSupplyList - WHERE id = vId + + SELECT * FROM vn.itemPlacementSupplyList + WHERE id = vId AND sectorFk = vSector; END ;; @@ -59870,7 +56645,7 @@ BEGIN * @param vSaleFk id de la tabla sale * @param vMateFk articulo sustituto * @ param vQuantity cantidad que se va a sustituir - */ + */ DECLARE vTicketFk INT; DECLARE vItemFk INT; DECLARE vWarehouseFk SMALLINT; @@ -59879,41 +56654,41 @@ BEGIN DECLARE vBox INT; DECLARE vPacking INT; DECLARE vRoundQuantity INT DEFAULT 1; - + SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk WHERE s.id = vSaleFk; - + UPDATE vn.sale SET quantity = quantity - vQuantity WHERE id = vSaleFk; - + CALL vn.buyUltimate(vWarehouseFk, vDate); - + SELECT `grouping`, groupingMode, packing INTO vGrouping,vBox,vPacking FROM buy b JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; - + IF vBox = 2 AND vPacking > 0 THEN SET vRoundQuantity = vPacking; END IF; IF vBox = 1 AND vGrouping > 0 THEN SET vRoundQuantity = vGrouping; END IF; - + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept) SELECT vTicketFk, vMateFk, CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ',i.longName) FROM vn.item i WHERE id = vMateFk; - + SELECT LAST_INSERT_ID() INTO vSaleFk; - + CALL vn.sale_calculateComponent(vSaleFk, NULL); - + INSERT INTO vn.itemProposal(itemFk, mateFk, counter) VALUES(vItemFk, vMateFk, 1) ON DUPLICATE KEY UPDATE counter = counter + 1; @@ -59942,13 +56717,13 @@ BEGIN DECLARE vCalcFk INT; DECLARE vTypeFk INT; DECLARE vResultsMax INT DEFAULT 10; - + DECLARE vTag1 VARCHAR(25); DECLARE vTag5 VARCHAR(25); DECLARE vTag6 VARCHAR(25); DECLARE vTag7 VARCHAR(25); DECLARE vTag8 VARCHAR(25); - + DECLARE vValue1 VARCHAR(50); DECLARE vValue5 VARCHAR(50); DECLARE vValue6 VARCHAR(50); @@ -59958,16 +56733,16 @@ BEGIN SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped FROM vn.ticket WHERE id = vTicketFk; - + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 - FROM vn.item i + FROM vn.item i LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk WHERE i.id = vItemFk; - + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); - + SELECT i.id itemFk, i.longName, i.subName, @@ -59985,7 +56760,7 @@ BEGIN (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, a.available, IFNULL(ip.counter,0) counter - FROM vn.item i + FROM vn.item i JOIN cache.available a ON a.item_id = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 @@ -59999,7 +56774,7 @@ BEGIN (it1.value = vValue1 COLLATE utf8_general_ci) DESC, (i.tag5 = vTag5 COLLATE utf8_general_ci) DESC, (i.value5 = vValue5 COLLATE utf8_general_ci) DESC, - (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, + (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, (i.value6 = vValue6 COLLATE utf8_general_ci) DESC, (i.tag7 = vTag7 COLLATE utf8_general_ci) DESC, (i.value7 = vValue7 COLLATE utf8_general_ci) DESC, @@ -60035,7 +56810,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.item SELECT vItem id; - + CALL item_refreshTags(); DROP TEMPORARY TABLE tmp.item; @@ -60058,23 +56833,23 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSale_byWeek`(vWeek INT, IN vYear INT, vItemFk INT, vWarehouseFk INT) BEGIN - + DECLARE vStarted DATE; DECLARE vEnded DATETIME; SELECT MIN(dated), util.dayEnd(MAX(dated)) INTO vStarted, vEnded - FROM `time` t + FROM `time` t WHERE CONCAT(vYear, LPAD(vWeek, 2, 0)) = t.period; SELECT t.shipped, w.name warehouse, - s.ticketFk, + s.ticketFk, t.nickname client, - am.name agencyName, + am.name agencyName, wk.code salesPerson, s.itemFk, - IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept, - s.quantity, + IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept, + s.quantity, s.price, s.priceFixed, s.discount, @@ -60084,15 +56859,15 @@ BEGIN wk.id salesPersonFk FROM sale s JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk + JOIN warehouse w ON w.id = t.warehouseFk JOIN address a ON a.id = t.addressFk LEFT JOIN agencyMode am ON am.id = t.agencyModeFk JOIN `client` c ON c.id = a.clientFk - LEFT JOIN worker wk ON wk.id = c.salesPersonFk + LEFT JOIN worker wk ON wk.id = c.salesPersonFk LEFT JOIN ticketLastState tls ON tls.ticketFk = t.id - LEFT JOIN saleBuy sb ON sb.saleFk = s.id - LEFT JOIN buy b ON b.id = sb.buyFk - LEFT JOIN item ig ON ig.id = b.itemOriginalFk + LEFT JOIN saleBuy sb ON sb.saleFk = s.id + LEFT JOIN buy b ON b.id = sb.buyFk + LEFT JOIN item ig ON ig.id = b.itemOriginalFk WHERE s.itemFk = vItemFk AND t.shipped BETWEEN vStarted AND vEnded AND IF(vWarehouseFk = 0, w.hasComission , t.warehouseFk = vWarehouseFk) @@ -60119,9 +56894,9 @@ BEGIN DECLARE vItemFk INT; SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - + UPDATE vn.item SET minimum = min WHERE id = vItemFk; - + END ;; @@ -60143,8 +56918,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSearchShelving`(`vShelvingFk` VARCHAR(3)) BEGIN SELECT p.`column` AS col , p.`row` - FROM vn.shelving s - JOIN parking p ON s.parkingFk = p.id + FROM vn.shelving s + JOIN parking p ON s.parkingFk = p.id WHERE s.`code` = vShelvingFk COLLATE utf8_general_ci; END ;; DELIMITER ; @@ -60185,36 +56960,36 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingLog_get`(vShelvingFk VARCHAR(10) ) BEGIN - + /** * Devuelve el log de los item en cada carro * - * @param vShelvingFk Matrícula del carro - * + * @param vShelvingFk Matrícula del carro + * */ - - SELECT isl.itemShelvingFk, - isl.created, - isl.accion, - isl.itemFk, - isl.shelvingFk, - isl.quantity, + + SELECT isl.itemShelvingFk, + isl.created, + isl.accion, + isl.itemFk, + isl.shelvingFk, + isl.quantity, isl.visible, - isl.available, - isl.grouping, - isl.packing, - isl.stars, - item.longName, - item.size, - item.subName, - worker.code, + isl.available, + isl.grouping, + isl.packing, + isl.stars, + item.longName, + item.size, + item.subName, + worker.code, isl.accion - FROM item - JOIN itemShelvingLog isl ON item.id = isl.itemFk + FROM item + JOIN itemShelvingLog isl ON item.id = isl.itemFk JOIN worker ON isl.workerFk = worker.id WHERE shelvingFk = vShelvingFk OR isl.itemFk = vShelvingFk ORDER BY isl.created DESC; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60233,7 +57008,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22)) BEGIN - + DECLARE vItemFk INT; SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; @@ -60252,9 +57027,9 @@ BEGIN END IF; - IF (SELECT COUNT(*) FROM vn.itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk + IF (SELECT COUNT(*) FROM vn.itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk AND packing = vPacking) = 1 THEN UPDATE vn.itemShelving @@ -60284,8 +57059,8 @@ BEGIN LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk LEFT JOIN vn.buy b ON b.id = lb.buy_id WHERE i.id = vItemFk; - END IF; - + END IF; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60306,9 +57081,9 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMatch`(vEntryFk INT, vA BEGIN DECLARE vTravelFk INT; - - SELECT travelFk INTO vTravelFk - FROM entry + + SELECT travelFk INTO vTravelFk + FROM entry WHERE id = vEntryFk; SELECT i.id, i.longName, i.size, i.subName, b.stickers, ish.etiquetas, b.printed @@ -60321,7 +57096,7 @@ BEGIN GROUP BY itemFk ) b ON b.itemFk = i.id LEFT JOIN ( - SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas + SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas FROM itemShelving ish JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN parking pk ON pk.id = sh.parkingFk @@ -60361,7 +57136,7 @@ BEGIN UPDATE vn.itemShelving SET visible = visible - vQuantity WHERE id = vItemShelvingFk; - + END ;; DELIMITER ; @@ -60384,47 +57159,47 @@ BEGIN DECLARE vVisibleCache INT; DECLARE vWarehouseFk INT; - + SELECT warehouseFk INTO vWarehouseFk FROM vn.sector WHERE id = vSectorFk; CALL cache.visible_refresh (vVisibleCache, FALSE, vWarehouseFk); - - SELECT t.id as ticketFk, - CAST(s.quantity AS DECIMAL(10,0)) as Cantidad, - s.itemFk, - s.concept, - v.visible - GREATEST(0,iss.visible) + IFNULL(sub3.transit,0) as Nicho, + + SELECT t.id as ticketFk, + CAST(s.quantity AS DECIMAL(10,0)) as Cantidad, + s.itemFk, + s.concept, + v.visible - GREATEST(0,iss.visible) + IFNULL(sub3.transit,0) as Nicho, i.subName, - GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo, + GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo, s.id as saleFk, IFNULL(sub3.transit,0) transit, v.visible, s.isPicked, s.reserved, t.shipped, tst.productionOrder, mm.Id_Movimiento - FROM vn.ticket t + FROM vn.ticket t JOIN vn.ticketState tst ON tst.ticketFk = t.id JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN cache.visible v ON s.itemFk = v.item_id AND v.calc_id = vVisibleCache LEFT JOIN vn2008.Movimientos_mark mm ON mm.Id_Movimiento = s.id AND mm.stateFk = 26 - JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id + JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id LEFT JOIN - (SELECT itemFk, sum(saldo) as transit - FROM vn.itemPlacementSupplyList - WHERE saldo > 0 + (SELECT itemFk, sum(saldo) as transit + FROM vn.itemPlacementSupplyList + WHERE saldo > 0 AND sectorFk = vSectorFk GROUP BY itemFk) sub3 ON sub3.itemFk = i.id - WHERE v.visible + IFNULL(sub3.transit,0) - GREATEST(0,iss.visible) < s.quantity + WHERE v.visible + IFNULL(sub3.transit,0) - GREATEST(0,iss.visible) < s.quantity AND IFNULL(sub3.transit,0) < s.quantity - AND s.isPicked = FALSE + AND s.isPicked = FALSE AND s.reserved = FALSE - AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) + AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) AND tst.isPreviousPreparable = TRUE AND t.warehouseFk = vWarehouseFk AND iss.sectorFk = vSectorFk AND mm.Id_Movimiento IS NULL ORDER BY itemFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60443,7 +57218,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar`(vSectorFk INT) proc:BEGIN - + DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; DECLARE hasFatherSector BOOLEAN; @@ -60451,17 +57226,17 @@ proc:BEGIN DECLARE vWarehouseFk INT DEFAULT 0; DECLARE vSonSectorFk INT; DECLARE vWorkerFk INT; - - SELECT s.workerFk - INTO vWorkerFk + + SELECT s.workerFk + INTO vWorkerFk FROM vn.sector s WHERE s.id = vSectorFk; SELECT w.id, s.warehouseFk INTO vBuyerFk, vWarehouseFk - FROM vn.worker w + FROM vn.worker w JOIN vn.sector s ON s.code = w.code WHERE s.id = vSectorFk; - + SELECT s.id INTO vSectorFk FROM vn.sector s WHERE s.warehouseFk = vWarehouseFk @@ -60470,21 +57245,21 @@ proc:BEGIN SELECT COUNT(*) INTO hasFatherSector FROM vn.sector WHERE sonFk = vSectorFk; - + SELECT warehouseFk, sonFk INTO vWarehouseFk, vSonSectorFk FROM vn.sector WHERE id = vSectorFk; - + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar; - + IF hasFatherSector THEN CREATE TEMPORARY TABLE tmp.itemShelvingRadar (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT * + ENGINE = MEMORY + SELECT * FROM ( SELECT iss.itemFk, i.longName, @@ -60503,9 +57278,9 @@ proc:BEGIN LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk WHERE vSectorFk IN (iss.sectorFk, s.sonFk) GROUP BY iss.itemFk - + UNION ALL - + SELECT v.item_id, i.longName, i.size, @@ -60515,7 +57290,7 @@ proc:BEGIN 0 downstairs, IF(it.isPackaging, NULL, v.visible) visible, vSectorFk as sectorFk - FROM cache.visible v + FROM cache.visible v JOIN vn.item i on i.id = v.item_id JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk) LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk @@ -60524,8 +57299,8 @@ proc:BEGIN AND iss.itemFk IS NULL AND it.isInventory ) sub GROUP BY itemFk; - - SELECT ishr.*, + + SELECT ishr.*, CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho, CAST(downstairs - IFNULL(notPickedYed,0) AS DECIMAL(10,0)) as pendiente FROM tmp.itemShelvingRadar ishr @@ -60542,7 +57317,7 @@ proc:BEGIN ELSE CREATE TEMPORARY TABLE tmp.itemShelvingRadar (PRIMARY KEY (itemFk)) - ENGINE = MEMORY + ENGINE = MEMORY SELECT iss.itemFk, 0 `hour`, 0 `minute`, @@ -60554,7 +57329,7 @@ proc:BEGIN IFNULL(a.available,0) available, IFNULL(v.visible - iss.visible,0) dayEndVisible, IFNULL(v.visible - iss.visible,0) firstNegative, - IFNULL(v.visible - iss.visible,0) itemPlacementVisible, + IFNULL(v.visible - iss.visible,0) itemPlacementVisible, IFNULL(i.minimum * b.packing,0) itemPlacementSize, ips.onTheWay, iss.visible itemShelvingStock, @@ -60568,20 +57343,20 @@ proc:BEGIN LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk LEFT JOIN (SELECT itemFk, sum(saldo) as onTheWay - FROM vn.itemPlacementSupplyList - WHERE saldo > 0 + FROM vn.itemPlacementSupplyList + WHERE saldo > 0 GROUP BY itemFk ) ips ON ips.itemFk = i.id - WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk) - OR iss.sectorFk = vSectorFk; + WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk) + OR iss.sectorFk = vSectorFk; DROP TEMPORARY TABLE IF EXISTS tmp.itemOutTime; CREATE TEMPORARY TABLE tmp.itemOutTime SELECT *,SUM(amount) quantity - FROM + FROM (SELECT item_id itemFk, - amount, - IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours, + amount, + IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours, IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes FROM vn2008.item_out io JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.item_id @@ -60589,23 +57364,23 @@ proc:BEGIN JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk JOIN vn.state s ON s.id = ts.stateFk LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN (SELECT DISTINCT saleFk - FROM vn.saleTracking st - WHERE st.created > util.VN_CURDATE() + LEFT JOIN (SELECT DISTINCT saleFk + FROM vn.saleTracking st + WHERE st.created > util.VN_CURDATE() AND st.isChecked ) stPrevious ON `stPrevious`.`saleFk` = io.saleFk WHERE t.warehouseFk = vWarehouseFk - AND s.isPicked = 0 - AND NOT io.Reservado + AND s.isPicked = 0 + AND NOT io.Reservado AND stPrevious.saleFk IS NULL - AND io.dat >= util.VN_CURDATE() + AND io.dat >= util.VN_CURDATE() AND io.dat < util.VN_CURDATE() + INTERVAL 1 DAY ) sub GROUP BY itemFk, hours, minutes; - + INSERT INTO tmp.itemShelvingRadar (itemFk) SELECT itemFk FROM tmp.itemOutTime - ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity, + ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity, firstNegative = if (firstNegative < 0, firstNegative, firstNegative + quantity), `hour` = ifnull(if (firstNegative > 0 , `hour`, hours),0), `minute` = ifnull(if (firstNegative > 0, `minute`, minutes),0); @@ -60625,7 +57400,7 @@ proc:BEGIN END IF; DROP TEMPORARY TABLE tmp.itemShelvingRadar; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60649,24 +57424,24 @@ BEGIN DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); - + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item ENGINE = MEMORY SELECT DISTINCT itemFk - FROM vn.buy + FROM vn.buy WHERE entryFk = vEntryFk; - + DROP TEMPORARY TABLE IF EXISTS tmp.item2; CREATE TEMPORARY TABLE tmp.item2 ENGINE = MEMORY SELECT * FROM tmp.item; - - SELECT i.id as itemFk, + + SELECT i.id as itemFk, i.minimum, CAST(IFNULL(v.visible,0) - IFNULL(iss.visible,0) AS DECIMAL(10,0)) as enNicho, CAST(IFNULL(a.available,0) AS DECIMAL(10,0)) as disponible, @@ -60686,11 +57461,11 @@ BEGIN AND IFNULL(tst.productionOrder,0) < 5 GROUP BY s.itemFK ) ts ON ts.itemFk = i.id; - - + + DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.item2; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60714,34 +57489,34 @@ BEGIN DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); - + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item ENGINE = MEMORY SELECT DISTINCT itemFk - FROM vn.buy + FROM vn.buy WHERE entryFk = vEntryFk; - + DROP TEMPORARY TABLE IF EXISTS tmp.item2; CREATE TEMPORARY TABLE tmp.item2 ENGINE = MEMORY SELECT * FROM tmp.item; - - SELECT i.id as itemFk, + + SELECT i.id as itemFk, CAST(IFNULL(iss.visible,0) - IFNULL(v.visible,0) AS DECIMAL(10,0)) as outShelving FROM vn.item i JOIN tmp.item ti ON ti.itemFk = i.id LEFT JOIN cache.visible v ON v.calc_id = vCalcVisibleFk AND v.item_id = i.id LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = i.id; - - + + DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.item2; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60762,10 +57537,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_Add`(vItemShelving BEGIN /** * Añade línea a itemShelvingSale y regulariza el carro - * + * * @param vItemShelvingFk Id itemShelving * @param vSaleFk Id de sale - * @param vQuantity cantidad a regularizar + * @param vQuantity cantidad a regularizar */ INSERT INTO itemShelvingSale(itemShelvingFk, saleFk, @@ -60948,7 +57723,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_reserveBySale`( - vSelf INT , + vSelf INT , vQuantity INT, vUserFk INT ) @@ -60963,7 +57738,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale ENGINE = MEMORY SELECT vSelf saleFk, vUserFk userFk; - + CALL itemShelvingSale_reserve(); END ;; DELIMITER ; @@ -60989,12 +57764,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_setQuantity`( BEGIN /** * Gestiona la reserva de un itemShelvingFk, actualizando isPicked y quantity - * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. - * Si la reserva de la ubicación es fallida, se regulariza la situación - * - * @param vItemShelvingSaleFk Id itemShelvingSaleFK + * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. + * Si la reserva de la ubicación es fallida, se regulariza la situación + * + * @param vItemShelvingSaleFk Id itemShelvingSaleFK * @param vQuantity Cantidad real que se ha cogido de la ubicación - * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha + * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha * quedado vacio tras el movimiento */ DECLARE vSaleFk INT; @@ -61005,7 +57780,7 @@ BEGIN DECLARE vItemFk INT; DECLARE vUserFk INT; DECLARE vDone BOOLEAN DEFAULT FALSE; - DECLARE vSales CURSOR FOR + DECLARE vSales CURSOR FOR SELECT iss.saleFk, iss.userFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk @@ -61019,14 +57794,14 @@ BEGIN CALL util.throw('Booking completed'); END IF; - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk + SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk INTO vItemFk, vSaleFk, vItemShelvingFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk WHERE iss.id = vItemShelvingSaleFk AND NOT iss.isPicked; - - UPDATE itemShelvingSale + + UPDATE itemShelvingSale SET isPicked = TRUE, quantity = vQuantity WHERE id = vItemShelvingSaleFk; @@ -61051,10 +57826,10 @@ l: LOOP CALL itemShelvingSale_reserveWhitUser(); DROP TEMPORARY TABLE tmp.sale; - + END LOOP; CLOSE vSales; - + DELETE iss FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk @@ -61068,32 +57843,32 @@ l: LOOP WHERE saleFk = vSaleFk AND NOT isPicked; - IF vRemainingQuantity THEN + IF vRemainingQuantity THEN CALL itemShelvingSale_reserveBySale (vSaleFk, vRemainingQuantity, NULL); - + SELECT SUM(quantity) INTO vRemainingQuantity FROM itemShelvingSale WHERE saleFk = vSaleFk AND NOT isPicked; IF NOT vRemainingQuantity <=> 0 THEN - SELECT SUM(iss.quantity) + SELECT SUM(iss.quantity) INTO vReservedQuantity - FROM itemShelvingSale iss + FROM itemShelvingSale iss WHERE iss.saleFk = vSaleFk; - + CALL saleTracking_new( vSaleFk, - TRUE, - vReservedQuantity, - `account`.`myUser_getId`(), + TRUE, + vReservedQuantity, + `account`.`myUser_getId`(), NULL, 'PREPARED', TRUE); - + UPDATE sale s SET s.quantity = vReservedQuantity - WHERE s.id = vSaleFk ; + WHERE s.id = vSaleFk ; END IF; END IF; END ;; @@ -61172,7 +57947,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN - + /** * Añade registro o lo actualiza si ya existe. @@ -61184,7 +57959,7 @@ BEGIN * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra * @param vPacking el packing del producto, NULL para coger el de la ultima compra * @param vWarehouseFk indica el sector - * + * **/ DECLARE vItemFk INT; @@ -61194,21 +57969,21 @@ BEGIN IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); - INSERT INTO shelving(code, parkingFk) + INSERT INTO shelving(code, parkingFk) SELECT vShelvingFk, id - FROM parking + FROM parking WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; END IF; - IF (SELECT COUNT(*) FROM itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk + IF (SELECT COUNT(*) FROM itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk AND packing = vPacking) = 1 THEN UPDATE itemShelving SET visible = visible+vQuantity - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; ELSE CALL cache.last_buy_refresh(FALSE); @@ -61359,10 +58134,10 @@ proc:BEGIN * @return Lista de articulos */ DECLARE vCalcVisibleFk INT; - + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); - SELECT * FROM + SELECT * FROM (SELECT sub.itemFk, sub.longName, CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, @@ -61379,28 +58154,28 @@ proc:BEGIN 0 upstairs, SUM(IFNULL(iss.visible,0)) downstairs, IF(it.isPackaging, null, IFNULL(v.visible, 0)) visible, - ik.name + ik.name FROM itemShelvingStock iss JOIN sector s ON s.id = iss.sectorFk JOIN item i on i.id = iss.itemFk - LEFT JOIN ink ik ON ik.id = i.inkFk + LEFT JOIN ink ik ON ik.id = i.inkFk JOIN itemType it ON it.id = i.typeFk LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk WHERE s.warehouseFk = vWarehouseFk AND it.workerFk = vBuyerFk - GROUP BY itemFk + GROUP BY itemFk ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente FROM sale s LEFT JOIN saleTracking st ON st.saleFk = s.id - JOIN ticket t ON t.id = s.ticketFk + JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND st.saleFk IS NULL AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk - ) sub2 ON sub2.itemFk = sub.itemFk - UNION ALL + ) sub2 ON sub2.itemFk = sub.itemFk + UNION ALL SELECT v.item_id , i.longName, CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, @@ -61418,7 +58193,7 @@ proc:BEGIN LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente FROM sale s LEFT JOIN saleTracking st ON st.saleFk = s.id - JOIN ticket t ON t.id = s.ticketFk + JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) @@ -61451,12 +58226,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_get`(IN vSelf VARCHAR(8)) BEGIN /** -* Lista artículos de itemshelving +* Lista artículos de itemshelving * * @param vSelf matrícula del carro **/ - SELECT ish.itemFk item, - IFNULL(i.longName, CONCAT(i.name, ' ', i.size)) description, + SELECT ish.itemFk item, + IFNULL(i.longName, CONCAT(i.name, ' ', i.size)) description, ish.visible, CEIL(ish.visible/ish.packing) stickers, ish.packing, @@ -61494,7 +58269,7 @@ BEGIN * * @param vShelvingFk matricula del carro */ - SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder + SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder FROM itemShelving is2 JOIN shelving sh ON sh.code = is2.shelvingFk JOIN parking p ON p.id = sh.parkingFk @@ -61559,167 +58334,167 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_getSaleDate`(vShelvingFk VARCHAR(3)) -BEGIN - - /* Devuelve la mínima fecha en que se necesita cada producto en esa matrícula. - * - * @param vShelvingFk Matrícula del carro o pallet - */ - - DECLARE vWarehouseFk INT; - DECLARE vStockScopeDays INT; - - SELECT s.warehouseFk, stockScopeDays - INTO vWarehouseFk, vStockScopeDays - FROM sector s - JOIN operator o ON s.id = o.sectorFk - JOIN productionConfig pc - WHERE o.workerFk = account.myUser_getId(); - - IF vWarehouseFk IS NULL - THEN CALL util.throw('WarehouseFk not setted'); - END IF; - - IF vStockScopeDays IS NULL - THEN CALL util.throw('StockScopeDays not setted'); - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tmp.tItems - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT itemFk, SUM(visible) visible - FROM itemShelving - WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci - GROUP BY itemFk; - - CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay - (INDEX (itemFk, dated)) - ENGINE = MEMORY - SELECT dated, - SUM(t3.amount) OVER (PARTITION BY t3.itemFk ORDER BY dated) stock, - t3.itemFk - FROM ( - SELECT t.itemFk, dated, SUM(amount) amount - FROM ( - SELECT t2.itemFk, t2.amount, t2.dated - FROM ( - SELECT item_id itemFk, amount, util.VN_CURDATE() dated - FROM cache.stock s - JOIN tmp.tItems i ON i.itemFk = s.item_id - WHERE s.warehouse_id = vWarehouseFk - UNION ALL - SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE() - FROM itemShelving ish - JOIN tmp.tItems i ON i.itemFk = ish.itemFk - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON sh.parkingFk = p.id - JOIN sector s ON s.id = p.sectorFk - WHERE s.isReserve - GROUP BY ish.itemFk - UNION ALL - SELECT iei.itemFk, SUM(quantity), landed - FROM itemEntryIn iei - JOIN tmp.tItems i ON i.itemFk = iei.itemFk - WHERE iei.landed BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY - AND iei.warehouseInFk = vWarehouseFk - AND NOT isVirtualStock - GROUP BY iei.itemFk, iei.landed - UNION ALL - SELECT ieo.itemFk, SUM(quantity), shipped - FROM itemEntryOut ieo - JOIN tmp.tItems i ON i.itemFk = ieo.itemFk - WHERE ieo.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY - AND ieo.warehouseOutFk = vWarehouseFk - GROUP BY ieo.itemFk, ieo.shipped - UNION ALL - SELECT i.itemFk, SUM(ito.quantity), DATE(ito.shipped) - FROM itemTicketOut ito - JOIN tmp.tItems i ON i.itemFk = ito.itemFk - WHERE ito.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY - AND ito.warehouseFk = vWarehouseFk - GROUP BY ito.itemFk, ito.shipped - ) t2 - JOIN tmp.tItems i ON i.itemFk = t2.itemFk)t - GROUP BY t.itemFk, dated - ) t3; - - -- Se restan las entradas de hoy - UPDATE tmp.tStockByDay sbd - JOIN (SELECT iei.itemFk, SUM(quantity) todayEntry - FROM itemEntryIn iei - JOIN tmp.tItems i ON i.itemFk = iei.itemFk - WHERE iei.landed = util.VN_CURDATE() - AND iei.warehouseInFk = vWarehouseFk - AND NOT iei.isVirtualStock) sub ON sub.itemFk = sbd.itemFk - SET sbd.stock = sbd.stock - sub.todayEntry - WHERE sbd.dated = util.VN_CURDATE(); - - -- Se añaden las lineas de venta servidas - UPDATE tmp.tStockByDay sbd - JOIN (SELECT s.itemFK, SUM(quantity) amount - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - WHERE t.warehouseFk = vWarehouseFk - AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() - AND s.isPicked - GROUP BY s.itemFk) sub ON sub.itemFk = sbd.itemFk - SET sbd.stock = sbd.stock + sub.amount; - - -- Se añaden los items ubicados hoy - UPDATE tmp.tStockByDay sbd - JOIN (SELECT ish.itemFK, SUM(ish.visible) amount - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND NOT s.isReserve - AND ish.created BETWEEN util.VN_CURDATE() AND util.midnight() - GROUP BY ish.itemFk) sub ON sub.itemFk = sbd.itemFk - SET sbd.stock = sbd.stock + sub.amount; - - SELECT ts.itemFk, - i.longName, - IF(ts.stock<=0, ts.dated, NULL) dated, - ts.stock, - sub4.visible, - sub4.shelvingFk - FROM( - SELECT IFNULL(sub2.minDated, sub.minDated) dated, - IFNULL(sub2.itemFk, sub.itemFk) itemFk - FROM(SELECT sbd.itemFk, - MIN(dated) minDated, - sbd.stock - FROM tmp.tItems ti - LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk - GROUP BY itemFk)sub - LEFT JOIN ( - SELECT sbd.itemFk, - MIN(dated) minDated, - sbd.stock - FROM tmp.tItems ti - LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk - WHERE sbd.stock <= 0 - GROUP BY itemFk)sub2 ON sub2.itemFk =sub.itemFk - WHERE sub2.itemFk IS NOT NULL - OR (sub2.itemFk IS NULL AND sub.itemFk IS NOT NULL)) sub3 - LEFT JOIN tmp.tStockByDay ts ON ts.itemFk = sub3.itemFk AND ts.dated = sub3.dated - JOIN (SELECT ish.itemFk, - ish.visible, - p.sectorFk, - ish.shelvingFk - FROM itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = parkingFk - LEFT JOIN vn.sector s ON s.id = p.sectorFk - WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci - ) sub4 ON sub4.itemFk = ts.itemFk - LEFT JOIN sector s ON s.id = sub4.sectorFk - LEFT JOIN item i ON i.id = ts.itemFk - WHERE NOT s.isReserve; - - DROP TEMPORARY TABLE tmp.tStockByDay, tmp.tItems; - +BEGIN + + /* Devuelve la mínima fecha en que se necesita cada producto en esa matrícula. + * + * @param vShelvingFk Matrícula del carro o pallet + */ + + DECLARE vWarehouseFk INT; + DECLARE vStockScopeDays INT; + + SELECT s.warehouseFk, stockScopeDays + INTO vWarehouseFk, vStockScopeDays + FROM sector s + JOIN operator o ON s.id = o.sectorFk + JOIN productionConfig pc + WHERE o.workerFk = account.myUser_getId(); + + IF vWarehouseFk IS NULL + THEN CALL util.throw('WarehouseFk not setted'); + END IF; + + IF vStockScopeDays IS NULL + THEN CALL util.throw('StockScopeDays not setted'); + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.tItems + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT itemFk, SUM(visible) visible + FROM itemShelving + WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + GROUP BY itemFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay + (INDEX (itemFk, dated)) + ENGINE = MEMORY + SELECT dated, + SUM(t3.amount) OVER (PARTITION BY t3.itemFk ORDER BY dated) stock, + t3.itemFk + FROM ( + SELECT t.itemFk, dated, SUM(amount) amount + FROM ( + SELECT t2.itemFk, t2.amount, t2.dated + FROM ( + SELECT item_id itemFk, amount, util.VN_CURDATE() dated + FROM cache.stock s + JOIN tmp.tItems i ON i.itemFk = s.item_id + WHERE s.warehouse_id = vWarehouseFk + UNION ALL + SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE() + FROM itemShelving ish + JOIN tmp.tItems i ON i.itemFk = ish.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON sh.parkingFk = p.id + JOIN sector s ON s.id = p.sectorFk + WHERE s.isReserve + GROUP BY ish.itemFk + UNION ALL + SELECT iei.itemFk, SUM(quantity), landed + FROM itemEntryIn iei + JOIN tmp.tItems i ON i.itemFk = iei.itemFk + WHERE iei.landed BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND iei.warehouseInFk = vWarehouseFk + AND NOT isVirtualStock + GROUP BY iei.itemFk, iei.landed + UNION ALL + SELECT ieo.itemFk, SUM(quantity), shipped + FROM itemEntryOut ieo + JOIN tmp.tItems i ON i.itemFk = ieo.itemFk + WHERE ieo.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND ieo.warehouseOutFk = vWarehouseFk + GROUP BY ieo.itemFk, ieo.shipped + UNION ALL + SELECT i.itemFk, SUM(ito.quantity), DATE(ito.shipped) + FROM itemTicketOut ito + JOIN tmp.tItems i ON i.itemFk = ito.itemFk + WHERE ito.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND ito.warehouseFk = vWarehouseFk + GROUP BY ito.itemFk, ito.shipped + ) t2 + JOIN tmp.tItems i ON i.itemFk = t2.itemFk)t + GROUP BY t.itemFk, dated + ) t3; + + -- Se restan las entradas de hoy + UPDATE tmp.tStockByDay sbd + JOIN (SELECT iei.itemFk, SUM(quantity) todayEntry + FROM itemEntryIn iei + JOIN tmp.tItems i ON i.itemFk = iei.itemFk + WHERE iei.landed = util.VN_CURDATE() + AND iei.warehouseInFk = vWarehouseFk + AND NOT iei.isVirtualStock) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock - sub.todayEntry + WHERE sbd.dated = util.VN_CURDATE(); + + -- Se añaden las lineas de venta servidas + UPDATE tmp.tStockByDay sbd + JOIN (SELECT s.itemFK, SUM(quantity) amount + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.warehouseFk = vWarehouseFk + AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() + AND s.isPicked + GROUP BY s.itemFk) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock + sub.amount; + + -- Se añaden los items ubicados hoy + UPDATE tmp.tStockByDay sbd + JOIN (SELECT ish.itemFK, SUM(ish.visible) amount + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND NOT s.isReserve + AND ish.created BETWEEN util.VN_CURDATE() AND util.midnight() + GROUP BY ish.itemFk) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock + sub.amount; + + SELECT ts.itemFk, + i.longName, + IF(ts.stock<=0, ts.dated, NULL) dated, + ts.stock, + sub4.visible, + sub4.shelvingFk + FROM( + SELECT IFNULL(sub2.minDated, sub.minDated) dated, + IFNULL(sub2.itemFk, sub.itemFk) itemFk + FROM(SELECT sbd.itemFk, + MIN(dated) minDated, + sbd.stock + FROM tmp.tItems ti + LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk + GROUP BY itemFk)sub + LEFT JOIN ( + SELECT sbd.itemFk, + MIN(dated) minDated, + sbd.stock + FROM tmp.tItems ti + LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk + WHERE sbd.stock <= 0 + GROUP BY itemFk)sub2 ON sub2.itemFk =sub.itemFk + WHERE sub2.itemFk IS NOT NULL + OR (sub2.itemFk IS NULL AND sub.itemFk IS NOT NULL)) sub3 + LEFT JOIN tmp.tStockByDay ts ON ts.itemFk = sub3.itemFk AND ts.dated = sub3.dated + JOIN (SELECT ish.itemFk, + ish.visible, + p.sectorFk, + ish.shelvingFk + FROM itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = parkingFk + LEFT JOIN vn.sector s ON s.id = p.sectorFk + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + ) sub4 ON sub4.itemFk = ts.itemFk + LEFT JOIN sector s ON s.id = sub4.sectorFk + LEFT JOIN item i ON i.id = ts.itemFk + WHERE NOT s.isReserve; + + DROP TEMPORARY TABLE tmp.tStockByDay, tmp.tItems; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -61812,15 +58587,15 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_selfConsumption`( - vShelvingFk VARCHAR(10) COLLATE utf8_general_ci, - vItemFk INT, + vShelvingFk VARCHAR(10) COLLATE utf8_general_ci, + vItemFk INT, vQuantity INT ) -BEGIN +BEGIN /** - * Leave the indicated amount on the shelf + * Leave the indicated amount on the shelf * and create a ticket with the difference. - * + * * @param vShelvingFk id of the shelf where the item is located. * @param vItemFk article of which the self-consumption ticket is to be created. * @param vQuantity amount that will stay on the shelf @@ -61834,7 +58609,7 @@ BEGIN DECLARE vItemShelvingFk INT; SELECT c.id, - c.clientFk, + pc.clientSelfConsumptionFk, s.warehouseFk INTO vCompanyFk, vClientFk, @@ -61845,6 +58620,7 @@ BEGIN JOIN sector s ON s.warehouseFk = w.id JOIN parking p ON p.sectorFk = s.id JOIN shelving s2 ON s2.parkingFk = p.id + JOIN productionConfig pc ON TRUE WHERE s2.code = vShelvingFk; IF vClientFk IS NULL THEN @@ -61864,10 +58640,10 @@ BEGIN END IF; SELECT SUM(visible), id INTO vVisible, vItemShelvingFk - FROM itemShelving + FROM itemShelving WHERE shelvingFk = vShelvingFk AND itemFk = vItemFk; - + IF vVisible IS NULL THEN CALL util.throw('The item is not on the shelf.'); END IF; @@ -61920,9 +58696,9 @@ BEGIN * @param vGrouping el grouping del producto en itemShelving */ UPDATE itemShelving - SET visible = vVisible, - packing = vPacking, - grouping = vGrouping + SET visible = vVisible, + packing = vPacking, + grouping = vGrouping WHERE id = vShelf; END ;; @@ -61944,7 +58720,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagMake`(vItemFk INT) BEGIN -/* * Crea los tags usando la tabla plantilla itemTag +/* * Crea los tags usando la tabla plantilla itemTag * y si no existe a partir de la ficha del artículo. * @param vItemFk El item al que se le añaden los tags */ @@ -61954,33 +58730,33 @@ BEGIN DECLARE vProducer VARCHAR(50); DECLARE vOrigin VARCHAR(20); DECLARE vTypeFk INTEGER; - - DELETE FROM itemTag + + DELETE FROM itemTag WHERE itemFk = vItemFk; - - SELECT typeFk INTO vTypeFk + + SELECT typeFk INTO vTypeFk FROM item WHERE id = vItemFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT vItemFk, itt.tagFk, NULL, itt.priority FROM itemTag it LEFT JOIN itemTypeTag itt ON itt.itemTypeFk = vTypeFk WHERE it.itemFk = vItemFk; - + IF (SELECT COUNT(*) FROM itemTag WHERE itemFk = vItemFk LIMIT 1) = 0 THEN - SELECT ik.name, i.size, i.category, p.name, o.name + SELECT ik.name, i.size, i.category, p.name, o.name INTO vInk, vSize, vCategory, vProducer, vOrigin FROM item i LEFT JOIN ink ik ON ik.id = i.inkFk LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible LEFT JOIN origin o ON o.id = i.originFk WHERE i.id = vItemFk; - + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES(vItemFk, 1, vInk, 1); - + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES (vItemFk, 8, vSize, 2); @@ -61989,11 +58765,11 @@ BEGIN INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES(vItemFk, 37, vProducer, 4); - + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES(vItemFk, 35, vOrigin, 5); END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62014,12 +58790,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorder`(itemTypeFk INT) BEGIN SET @isTriggerDisabled = TRUE; - + -- No se puede usar temporary porque da error Error Code: 1137. No puedo reabrir tabla: 'i DROP TABLE IF EXISTS tmp.item; CREATE TABLE tmp.item SELECT DISTINCT i.id - FROM vn.item i + FROM vn.item i WHERE i.typeFk = itemTypeFk; UPDATE itemTag it @@ -62028,8 +58804,8 @@ BEGIN JOIN itemTypeTag itt ON itt.itemTypeFk = item.typeFk AND itt.tagFk = it.tagFk SET it.priority = itt.priority WHERE itt.itemTypeFk = itemTypeFk; - - CALL item_refreshTags(); + + CALL item_refreshTags(); SET @isTriggerDisabled = FALSE; @@ -62054,12 +58830,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorderByName`(vName VARCHAR BEGIN SET @isTriggerDisabled = TRUE; - + -- No se puede usar temporary porque da error Error Code: 1137. No puedo reabrir tabla: 'i DROP TABLE IF EXISTS tmp.item; CREATE TABLE tmp.item SELECT DISTINCT i.id - FROM vn.item i + FROM vn.item i WHERE i.`name` LIKE CONCAT(vName,'%'); UPDATE itemTag it @@ -62068,8 +58844,8 @@ BEGIN JOIN itemTypeTag itt ON itt.itemTypeFk = item.typeFk AND itt.tagFk = it.tagFk SET it.priority = itt.priority WHERE itt.itemTypeFk = itemTypeFk; - - CALL item_refreshTags(); + + CALL item_refreshTags(); SET @isTriggerDisabled = FALSE; @@ -62092,36 +58868,36 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTag_replace`(vItemFromFk INT, vItemToFk INT, vPicture VARCHAR(100)) BEGIN - + /* Reemplaza los tags de un artículo por los de otro, así como su imagen - * + * * @param vItemFromFk id de vn.item con el artículo del que se toman los tags * @param vItemToFk id de vn.item con el artículo del que se toman los tags * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk */ - DELETE FROM vn.itemTag + DELETE FROM vn.itemTag WHERE itemFk = vItemToFk; - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) SELECT vItemToFk, tagFk, value, priority - FROM vn.itemTag + FROM vn.itemTag WHERE itemFk = vItemFromFk; - + IF ISNULL(vPicture) THEN - - SELECT image INTO vPicture - FROM vn.item + + SELECT image INTO vPicture + FROM vn.item WHERE id = vItemFromFk; - + END IF; - UPDATE vn.item i + UPDATE vn.item i SET i.image = vPicture WHERE i.id = vItemToFk; - + CALL vn.itemRefreshTags(vItemToFk); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62146,9 +58922,9 @@ BEGIN SELECT DISTINCT id FROM vn.itemCategory WHERE merchandise <> FALSE; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN RESIGNAL; END; @@ -62159,45 +58935,45 @@ BEGIN INNER JOIN bs.ventas v ON v.Id_Movimiento = s.id WHERE v.fecha BETWEEN TIMESTAMPADD(DAY, - 7, util.VN_CURDATE()) AND util.VN_CURDATE() GROUP BY s.itemFk; - + DROP TABLE IF EXISTS tmp.topSeller; - CREATE TEMPORARY TABLE 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; + 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 */ ; @@ -62307,7 +59083,7 @@ SET tag6 = t.name, value6 = it.value WHERE it.priority = 2 AND (vItem IS NULL OR vItem = it.itemFk); -UPDATE item i +UPDATE item i JOIN itemTag it ON it.itemFk = i.id JOIN tag t ON t.id = it.tagFk SET tag7 = t.name, value7 = it.value @@ -62340,7 +59116,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_cleanFloramondo`() BEGIN /** -* Elimina todos los items repetidos de floramondo +* Elimina todos los items repetidos de floramondo * y los sustituye por el que tiene menor id */ DECLARE vItemFrom INT; @@ -62406,7 +59182,7 @@ BEGIN AND i2.EmbalageCode <=> i.EmbalageCode AND i2.quality <=> i.quality JOIN ( - SELECT DISTINCT b.itemFk + SELECT DISTINCT b.itemFk FROM buy b JOIN item i ON i.id = b.itemFk WHERE i.isFloramondo @@ -62414,7 +59190,7 @@ BEGIN )sub2 ON sub2.itemFk = GREATEST(i.id, i2.id) WHERE i.isFloramondo AND i.id <> i2.id; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION SET vDone = TRUE; BEGIN SET vDone = TRUE; @@ -62545,6 +59321,316 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_comparative` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_comparative`( + vDate DATETIME, + vDayRange TINYINT, + vWarehouseFk TINYINT, + vAvailableSince DATE, + vBuyerFk INT, + vIsFloramondo BOOL, + vCountryFk INT +) +proc: BEGIN +/** + * Genera una tabla de comparativa de artículos por itemType/comprador/fecha. + * Los datos se calculan en función de los parámetros proporcionados. + * + * @param vDate La fecha para la cual se generará la comparativa. + * @param vDayRange El rango de días a considerar para la comparativa. + * @param vWarehouseFk El identificador del almacén para filtrar los artículos. + * @param vAvailableSince La fecha de disponibilidad desde la cual se consideran los artículos disponibles. + * @param vBuyerFk El identificador del comprador para filtrar los artículos. + * @param vIsFloramondo Indica si se deben incluir solo los artículos de Floramondo (opcional). + * @param vCountryFk El identificador del país. + * @param tmp.comparativeFilterType(filterFk INT ,itemTypeFk INT) + * @return tmp.comparative + */ + + DECLARE vDayRangeStart DATE; + DECLARE vDayRangeEnd DATE; + DECLARE w1, w2, w3, w4, w5, w6, w7 INT; + DECLARE y1, y2, y3, y4, y5, y6, y7 INT; + DECLARE z1, z2, z3, z4, z5, z6, z7 INT; + DECLARE vPeriod INT; + DECLARE i INT DEFAULT 0; + DECLARE vHasTypeFilter BOOL; + DECLARE vWeekRange INT; + DECLARE vWeekCount TINYINT; + DECLARE vMaxDayRange INT; + DECLARE vMinDayRange INT; + DECLARE vDefaultDayRange INT; + + IF NOT(SELECT COUNT(*) FROM comparativeConfig)THEN + LEAVE proc; + END IF; + + SELECT weekRange, + weekRange * 2 + 1, + maxDayRange, + minDayRange, + defaultDayRange + INTO vWeekRange, + vWeekCount, + vMaxDayRange, + vMinDayRange, + vDefaultDayRange + FROM comparativeConfig; + + IF vDayRange < vMinDayRange OR vDayRange > vMaxDayRange THEN + SET vDayRange = vDefaultDayRange; + END IF; + + SELECT MIN(dated) INTO vDayRangeStart + FROM vn.time + WHERE dated <= vDate + GROUP BY period + ORDER BY dated desc + LIMIT 1 OFFSET vWeekRange; + + SELECT MAX(dated) INTO vDayRangeEnd + FROM vn.time + WHERE dated >= vDate + GROUP BY period + ORDER BY dated ASC + LIMIT 1 OFFSET vWeekRange; + + SELECT COUNT(itemTypeFk) > 0 INTO vHasTypeFilter + FROM tmp.comparativeFilterType; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemInventory + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT i.id + FROM item i + JOIN itemType t ON t.id = i.typeFk + JOIN itemCategory c ON c.id = t.categoryFk + LEFT JOIN worker w ON w.id = t.workerFk + WHERE (NOT vHasTypeFilter + OR t.id IN (SELECT itemTypeFk FROM tmp.comparativeFilterType)) + AND (vBuyerFk IS NULL + OR t.workerFk = vBuyerFk) + AND (vIsFloramondo IS NULL + OR i.isFloramondo = vIsFloramondo); + + IF vDate < util.VN_CURDATE() THEN + ALTER TABLE tmp.itemInventory + ADD `buy_id` INT NOT NULL DEFAULT 0, + ADD `buy_date` DATE DEFAULT '2000-01-01', + ADD `life` INT DEFAULT 0, + ADD `sd` INT DEFAULT 0, + ADD `avalaible` INT DEFAULT 0, + ADD `visible` INT DEFAULT 0; + ELSE + CALL multipleInventory(vAvailableSince, vWarehouseFk, vDayRange); + CALL item_multipleBuy(vDate, vWarehouseFk); + CALL item_multipleBuyByDate(vDate, vWarehouseFk); + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tTable ( + cy INT(6) PRIMARY KEY, + ly INT(6), + zy INT(6), + INDEX (ly) + ); + + REPEAT + SET i = i + 1; + + SELECT t.period INTO vPeriod + FROM vn.`time` t + WHERE t.dated = vDayRangeStart + INTERVAL (vWeekCount * (i - 1)) DAY; + + INSERT IGNORE INTO tTable(cy, ly, zy) VALUES(vPeriod, vPeriod - 100, vPeriod - 200); + UNTIL i = vWeekCount END REPEAT; + + SELECT cy, ly, zy INTO w1, y1, z1 FROM tTable LIMIT 1; + SELECT cy, ly, zy INTO w2, y2, z2 FROM tTable WHERE cy > w1 LIMIT 1; + SELECT cy, ly, zy INTO w3, y3, z3 FROM tTable WHERE cy > w2 LIMIT 1; + SELECT cy, ly, zy INTO w4, y4, z4 FROM tTable WHERE cy > w3 LIMIT 1; + SELECT cy, ly, zy INTO w5, y5, z5 FROM tTable WHERE cy > w4 LIMIT 1; + SELECT cy, ly, zy INTO w6, y6, z6 FROM tTable WHERE cy > w5 LIMIT 1; + SELECT cy, ly, zy INTO w7, y7, z7 FROM tTable WHERE cy > w6 LIMIT 1; + + -- Genera una tabla con los datos del año pasado. + + CREATE OR REPLACE TEMPORARY TABLE tLastYear + (KEY (lItemFk)) + ENGINE = MEMORY + SELECT c.itemFk lItemFk, + SUM(IF(c.timePeriod = y1, c.quantity, 0)) lweek1, + SUM(IF(c.timePeriod = y2, c.quantity, 0)) lweek2, + SUM(IF(c.timePeriod = y3, c.quantity, 0)) lweek3, + SUM(IF(c.timePeriod = y4, c.quantity, 0)) lweek4, + SUM(IF(c.timePeriod = y5, c.quantity, 0)) lweek5, + SUM(IF(c.timePeriod = y6, c.quantity, 0)) lweek6, + SUM(IF(c.timePeriod = y7, c.quantity, 0)) lweek7, + SUM(IF(c.timePeriod = y1, c.price, 0)) lprice1, + SUM(IF(c.timePeriod = y2, c.price, 0)) lprice2, + SUM(IF(c.timePeriod = y3, c.price, 0)) lprice3, + SUM(IF(c.timePeriod = y4, c.price, 0)) lprice4, + SUM(IF(c.timePeriod = y5, c.price, 0)) lprice5, + SUM(IF(c.timePeriod = y6, c.price, 0)) lprice6, + SUM(IF(c.timePeriod = y7, c.price, 0)) lprice7 + FROM tmp.itemInventory ai + JOIN comparative c ON c.itemFk = ai.id + JOIN warehouse w on w.id = c.warehouseFk + JOIN tTable wt ON c.timePeriod = wt.ly + WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk + AND w.isComparative + AND (vCountryFk IS NULL OR c.countryFk = vCountryFk) + GROUP BY ai.id; + + -- Genera una tabla con los datos de hace DOS años. + + CREATE OR REPLACE TEMPORARY TABLE tTwoYearsAgo + (KEY (tItemFk)) + ENGINE = MEMORY + SELECT c.itemFk tItemFk, + SUM(IF(c.timePeriod = z1, c.quantity, 0)) vlweek1, + SUM(IF(c.timePeriod = z2, c.quantity, 0)) vlweek2, + SUM(IF(c.timePeriod = z3, c.quantity, 0)) vlweek3, + SUM(IF(c.timePeriod = z4, c.quantity, 0)) vlweek4, + SUM(IF(c.timePeriod = z5, c.quantity, 0)) vlweek5, + SUM(IF(c.timePeriod = z6, c.quantity, 0)) vlweek6, + SUM(IF(c.timePeriod = z7, c.quantity, 0)) vlweek7, + SUM(IF(c.timePeriod = z1, c.price, 0)) vlprice1, + SUM(IF(c.timePeriod = z2, c.price, 0)) vlprice2, + SUM(IF(c.timePeriod = z3, c.price, 0)) vlprice3, + SUM(IF(c.timePeriod = z4, c.price, 0)) vlprice4, + SUM(IF(c.timePeriod = z5, c.price, 0)) vlprice5, + SUM(IF(c.timePeriod = z6, c.price, 0)) vlprice6, + SUM(IF(c.timePeriod = z7, c.price, 0)) vlprice7 + FROM tmp.itemInventory ai + JOIN comparative c ON c.itemFk = ai.id + JOIN warehouse w on w.id = c.warehouseFk + JOIN tTable wt ON c.timePeriod = wt.zy + WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk + AND w.isComparative + AND (vCountryFk IS NULL OR c.countryFk = vCountryFk) + GROUP BY ai.id; + + -- Genera una tabla con los datos de este año.ss + + CREATE OR REPLACE TEMPORARY TABLE tCurrentYear + (KEY (cItemFk)) + ENGINE = MEMORY + SELECT t.itemFk cItemFk, + SUM(IF(week = w1, total, 0)) cweek1, + SUM(IF(week = w2, total, 0)) cweek2, + SUM(IF(week = w3, total, 0)) cweek3, + SUM(IF(week = w4, total, 0)) cweek4, + SUM(IF(week = w5, total, 0)) cweek5, + SUM(IF(week = w6, total, 0)) cweek6, + SUM(IF(week = w7, total, 0)) cweek7, + SUM(IF(week = w1, price, 0)) cprice1, + SUM(IF(week = w2, price, 0)) cprice2, + SUM(IF(week = w3, price, 0)) cprice3, + SUM(IF(week = w4, price, 0)) cprice4, + SUM(IF(week = w5, price, 0)) cprice5, + SUM(IF(week = w6, price, 0)) cprice6, + SUM(IF(week = w7, price, 0)) cprice7 + FROM ( + SELECT s.itemFk, + ti.period `week`, + SUM(s.quantity) total, + TRUNCATE(SUM(s.quantity * s.priceFixed),0) price + FROM ticket t + JOIN sale s ON t.id = s.ticketFk + JOIN tmp.itemInventory it ON it.id = s.itemFk + JOIN time ti ON ti.dated = DATE(t.shipped) + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN warehouse w ON w.id = t.warehouseFk + STRAIGHT_JOIN address ad ON ad.id = t.addressFk + JOIN province p ON p.id = ad.provinceFk + JOIN `client` c ON c.id = ad.clientFk + WHERE t.shipped BETWEEN vDayRangeStart AND util.dayEnd(vDayRangeEnd) + AND c.typeFk IN ('Normal','handMaking') + AND w.id = COALESCE(vWarehouseFk, w.id) + AND w.isComparative + AND (vCountryFk IS NULL OR p.countryFk = vCountryFk) + GROUP BY i.id, week + ) t + GROUP BY t.itemFk; + + -- Genera la tabla con la comparativa. + CREATE OR REPLACE TEMPORARY TABLE tmp.comparative + ENGINE = MEMORY + SELECT it.subName productor, + b.packing, + b.buyingValue costefijo, + b.groupingMode caja, + it.image ArticleImage, + IFNULL(it.inkFk,"?") color, + tp.code tipo, + it.typeFk tipo_id, + o.code origen, + it.category categoria, + it.stems tallos, + it.size medida, + it.name article, + w.code codigoTrabajador, + tp.categoryFk reino_id, + ly.*, + cy.*, + zy.*, + it.*, + it.id Id_Article, + i.buy_id, + tp.life, + IFNULL(i.sd,0) sd, + i.avalaible, + i.visible, + i.buy_date, + e.id provider_id, + it.comment comments, + it.description itemDescription, + IF(cy.cItemFk IS NULL AND i.visible = 0 AND i.avalaible = 0 + AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) filtret, + IF(it.hasMinPrice, FORMAT(it.minPrice, 2), "") pvp, + s.company_name + FROM tmp.itemInventory i + JOIN item it ON it.id = i.id + LEFT JOIN itemType tp ON tp.id = it.typeFk + LEFT JOIN worker w ON w.id = tp.workerFk + LEFT JOIN buy b ON b.id = i.buy_id + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN origin o ON o.id = it.originFk + LEFT JOIN tLastYear ly ON ly.lItemFk = it.id + LEFT JOIN tCurrentYear cy ON cy.cItemFk = it.id + LEFT JOIN tTwoYearsAgo zy ON zy.tItemFk = it.id + LEFT JOIN edi.ekt e2 ON e2.id = b.ektFk + LEFT JOIN edi.supplier s ON s.supplier_id = e2.pro + WHERE i.avalaible + OR i.visible + OR i.sd + OR cy.cweek1 OR cy.cweek2 OR cy.cweek3 OR cy.cweek4 OR cy.cweek5 OR cy.cweek6 OR cy.cweek7 + OR ly.lweek1 OR ly.lweek2 OR ly.lweek3 OR ly.lweek4 OR ly.lweek5 OR ly.lweek6 OR ly.lweek7 + OR zy.vlweek1 OR zy.vlweek2 OR zy.vlweek3 OR zy.vlweek4 OR zy.vlweek5 OR zy.vlweek6 OR zy.vlweek7; + + -- Elimina las tablas temporales creadas... + DROP TEMPORARY TABLE IF EXISTS tmp.itemInventory, + tTwoYearsAgo, + tLastYear, + tCurrentYear, + tTable; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_deactivateUnused` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62598,50 +59684,50 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getAtp`(vDated DATE) -BEGIN -/** - * Calcula el valor mínimo acumulado para cada artículo ordenado por fecha y - * almacén. - * - * @param vDated Si no hay movimientos en la fecha indicada, debe devolver 0 - * @table tmp.itemCalc(itemFk, wareHouseFk, dated, quantity) - * @return tmp.itemAtp(itemFk, warehouseFk, quantity) - */ - CREATE OR REPLACE TEMPORARY TABLE tItemOrdered - (UNIQUE(itemFk, warehouseFk, dated)) - ENGINE = MEMORY - SELECT itemFk, warehouseFk, dated, SUM(quantity) quantity - FROM ( - SELECT itemFk, warehouseFk, dated, quantity - FROM tmp.itemCalc - UNION ALL - SELECT itemFk, warehouseFk, vDated, 0 - FROM (SELECT DISTINCT itemFk, warehouseFk FROM tmp.itemCalc) t2 - ) t1 - GROUP BY itemFk, warehouseFk, dated - ORDER BY itemFk, warehouseFk, dated; - - SET @lastItemFk := 0; - SET @lastWareHouseFk := 0; - SET @lastQuantity := 0; - - CREATE OR REPLACE TEMPORARY TABLE tmp.itemAtp - (INDEX (itemFk, wareHouseFk)) - SELECT itemFk, wareHouseFk, MIN(quantityAccumulated) quantity - FROM ( - SELECT - itemFk, - IF(itemFk <> @lastItemFk OR wareHouseFk <> @lastWareHouseFk, - @lastQuantity := quantity, - @lastQuantity := @lastQuantity + quantity) quantityAccumulated, - wareHouseFk, - @lastItemFk := itemFk, - @lastWareHouseFk := wareHouseFk - FROM tItemOrdered - )sub - GROUP BY itemFk, wareHouseFk; - - DROP TEMPORARY TABLE tItemOrdered; +BEGIN +/** + * Calcula el valor mínimo acumulado para cada artículo ordenado por fecha y + * almacén. + * + * @param vDated Si no hay movimientos en la fecha indicada, debe devolver 0 + * @table tmp.itemCalc(itemFk, wareHouseFk, dated, quantity) + * @return tmp.itemAtp(itemFk, warehouseFk, quantity) + */ + CREATE OR REPLACE TEMPORARY TABLE tItemOrdered + (UNIQUE(itemFk, warehouseFk, dated)) + ENGINE = MEMORY + SELECT itemFk, warehouseFk, dated, SUM(quantity) quantity + FROM ( + SELECT itemFk, warehouseFk, dated, quantity + FROM tmp.itemCalc + UNION ALL + SELECT itemFk, warehouseFk, vDated, 0 + FROM (SELECT DISTINCT itemFk, warehouseFk FROM tmp.itemCalc) t2 + ) t1 + GROUP BY itemFk, warehouseFk, dated + ORDER BY itemFk, warehouseFk, dated; + + SET @lastItemFk := 0; + SET @lastWareHouseFk := 0; + SET @lastQuantity := 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemAtp + (INDEX (itemFk, wareHouseFk)) + SELECT itemFk, wareHouseFk, MIN(quantityAccumulated) quantity + FROM ( + SELECT + itemFk, + IF(itemFk <> @lastItemFk OR wareHouseFk <> @lastWareHouseFk, + @lastQuantity := quantity, + @lastQuantity := @lastQuantity + quantity) quantityAccumulated, + wareHouseFk, + @lastItemFk := itemFk, + @lastWareHouseFk := wareHouseFk + FROM tItemOrdered + )sub + GROUP BY itemFk, wareHouseFk; + + DROP TEMPORARY TABLE tItemOrdered; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62667,13 +59753,13 @@ BEGIN /** * @vItemFk item a buscar * @vWarehouseFk almacen donde buscar - * @vDate Si la fecha es null, muestra el histórico desde el inventario. + * @vDate Si la fecha es null, muestra el histórico desde el inventario. * Si la fecha no es null, muestra histórico desde la fecha pasada. */ DECLARE vDateInventory DATETIME; IF vDate IS NULL THEN - SELECT inventoried INTO vDateInventory + SELECT inventoried INTO vDateInventory FROM config; ELSE SELECT mockUtcTime INTO vDateInventory @@ -62699,7 +59785,7 @@ BEGIN inventorySupplierFk INT(10) ); - INSERT INTO tItemDiary + INSERT INTO tItemDiary SELECT tr.landed shipped, b.quantity `in`, NULL `out`, @@ -62720,14 +59806,14 @@ BEGIN JOIN entry e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk JOIN supplier s ON s.id = e.supplierFk - JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() + JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() OR (util.VN_CURDATE() AND tr.isReceived), - 'DELIVERED', + 'DELIVERED', 'FREE') JOIN entryConfig ec WHERE tr.landed >= vDateInventory AND vWarehouseFk = tr.warehouseInFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) AND b.itemFk = vItemFk AND e.isExcludedFromAvailable = FALSE AND e.isRaid = FALSE @@ -62753,14 +59839,14 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk JOIN warehouse w ON w.id = tr.warehouseOutFk JOIN supplier s ON s.id = e.supplierFk - JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() + JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), - 'DELIVERED', + 'DELIVERED', 'FREE') JOIN entryConfig ec WHERE tr.shipped >= vDateInventory AND vWarehouseFk = tr.warehouseOutFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) AND b.itemFk = vItemFk AND e.isExcludedFromAvailable = FALSE AND w.isFeedStock = FALSE @@ -62789,12 +59875,12 @@ BEGIN JOIN client c ON c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), - 'DELIVERED', + 'DELIVERED', IF (t.shipped > util.dayEnd(util.VN_CURDATE()), 'FREE', IFNULL(ts.code, 'FREE'))) LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' - LEFT JOIN saleTracking stk ON stk.saleFk = s.id + LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id LEFT JOIN claimBeginning cb ON s.id = cb.saleFk WHERE t.shipped >= vDateInventory @@ -62810,7 +59896,7 @@ BEGIN `out` DESC; IF vDate IS NULL THEN - + SET @a := 0; SET @currentLineFk := 0; SET @shipped := ''; @@ -62825,9 +59911,9 @@ BEGIN `in` invalue, `out`, @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0) balance, - @currentLineFk := IF (@shipped < util.VN_CURDATE() + @currentLineFk := IF (@shipped < util.VN_CURDATE() OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')), - lineFk, + lineFk, @currentLineFk) lastPreparedLineFk, isTicket, lineFk, @@ -62859,25 +59945,25 @@ BEGIN 0 clientType, 0 claimFk UNION ALL - SELECT shipped, - alertlevel, - stateName, - origin, - reference, - clientFk, - name, `in`, - `out`, - @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), - 0, - isTicket, - lineFk, - isPicked, - clientType, + SELECT shipped, + alertlevel, + stateName, + origin, + reference, + clientFk, + name, `in`, + `out`, + @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), + 0, + isTicket, + lineFk, + isPicked, + clientType, claimFk FROM tItemDiary WHERE shipped >= vDate; END IF; - + DROP TEMPORARY TABLE tItemDiary; END ;; DELIMITER ; @@ -62984,7 +60070,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getLack`(IN vForce BOOLEAN, IN BEGIN /** * Calcula una tabla con el máximo negativo visible para cada producto y almacen - * + * * @param vForce Fuerza el recalculo del stock * @param vDays Numero de dias a considerar **/ @@ -62994,32 +60080,32 @@ BEGIN CALL item_getMinETD(); CALL item_zoneClosure(); - SELECT i.id itemFk, + SELECT i.id itemFk, i.longName, w.id warehouseFk, - p.`name` producer, + p.`name` producer, i.`size`, i.category, - w.name warehouse, + w.name warehouse, SUM(IFNULL(sub.amount,0)) lack, i.inkFk, IFNULL(im.timed, util.midnight()) timed, IFNULL(izc.timed, util.midnight()) minTimed - FROM (SELECT item_id, - warehouse_id, + FROM (SELECT item_id, + warehouse_id, amount FROM cache.stock WHERE amount > 0 UNION ALL - SELECT itemFk, - warehouseFk, + SELECT itemFk, + warehouseFk, amount FROM tmp.itemMinacum ) sub JOIN warehouse w ON w.id = sub.warehouse_id JOIN item i ON i.id = sub.item_id - LEFT JOIN producer p ON p.id = i.producerFk - JOIN itemType it ON it.id = i.typeFk + LEFT JOIN producer p ON p.id = i.producerFk + JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id @@ -63142,12 +60228,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getMinETD`() BEGIN - + /* Devuelve una tabla temporal con la primera ETD, para todos los artículos con salida hoy. - * + * * @return tmp.itemMinETD(itemFk, timed) */ - + DECLARE vMidnight DATETIME DEFAULT util.midnight(); DROP TEMPORARY TABLE IF EXISTS tmp.itemMinETD; @@ -63158,7 +60244,7 @@ BEGIN SELECT s.itemFk, MIN(TIME(IFNULL(z.`hour`,vMidnight))) timed FROM ticket t JOIN sale s ON s.ticketFk = t.id - LEFT JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN `zone` z ON z.id = t.zoneFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND vMidnight GROUP BY s.itemFk; END ;; @@ -63188,33 +60274,33 @@ BEGIN * @param vWarehouseFk warehouse id * @param vDate fecha para revisar disponible * @param vIsShowedByType para mostrar solo artículos de ese tipo - */ + */ DECLARE vCalcFk INT; DECLARE vTypeFk INT; - + DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag6 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag7 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag8 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - + DECLARE vValue1 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue5 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue6 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 FROM vn.item i LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk WHERE i.id = vItemFk; - + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDate); - + SELECT i.id itemFk, i.longName, i.subName, @@ -63247,7 +60333,7 @@ BEGIN ORDER BY counter DESC, (t1.name = vTag1) DESC, (it1.value = vValue1) DESC, - (i.tag6 = vTag6) DESC, + (i.tag6 = vTag6) DESC, (i.value6 = vValue6) DESC, (i.tag5 = vTag5) DESC, (i.value5 = vValue5) DESC, @@ -63256,7 +60342,7 @@ BEGIN (i.tag8 = vTag8) DESC, (i.value8 = vValue8) DESC LIMIT 30; - + END ;; DELIMITER ; @@ -63407,6 +60493,108 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_multipleBuy` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_multipleBuy`( + vDate DATETIME, + vWarehouseFk INT +) +BEGIN +/** + * Updates the tmp.itemInventory table, adding the buy id. + * + * @param tmp.itemInventory(buy_id) + * @param vDate -> Date of the purchase operation. + * @param vWarehouseFk -> Identifier of the warehouse (warehouseId). + */ + ALTER TABLE tmp.itemInventory ADD IF NOT EXISTS buy_id INT; + + CALL buyUltimate(vWarehouseFk, vDate); + + CREATE OR REPLACE TEMPORARY TABLE tmp + (KEY (itemFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT itemFk, buyFk + FROM tmp.buyUltimate + ORDER BY (vWarehouseFk = warehouseFk) DESC, landing DESC + LIMIT 10000000000000000000 + ) t + GROUP BY itemFk; + + UPDATE tmp.itemInventory ai + JOIN tmp t ON ai.id = t.itemFk + SET ai.buy_id = t.buyFk; + + DROP TEMPORARY TABLE tmp, tmp.buyUltimate; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_multipleBuyByDate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_multipleBuyByDate`( + vDated DATETIME, + vWarehouseFk TINYINT(3) +) +BEGIN +/** + * Updates the tmp.itemInventory table, adding the purchase date. + * + * @param tmp.itemInventory(buy_date) + * @param vDated -> end date + * @param vWarehouseFk -> warehouse id + */ + DECLARE vLastBuyScope INT; + SELECT comparativeLastBuyScope INTO vLastBuyScope + FROM config; + + ALTER TABLE tmp.itemInventory + ADD `buy_date` datetime NOT NULL; + + CREATE OR REPLACE TEMPORARY TABLE lastBuyScope + SELECT i.id, MAX(t.landed) lastLanded + FROM item i + JOIN buy b ON b.itemFk = i.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN supplier s ON s.id = e.supplierFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN (vDated + INTERVAL - vLastBuyScope DAY) AND vDated + AND NOT s.name = 'INVENTARIO' + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND w.isComparative + AND NOT e.isRaid + GROUP BY i.id; + + UPDATE tmp.itemInventory y + JOIN lastBuyScope lbs ON lbs.id = y.id + SET y.buy_date = lbs.lastLanded; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_refreshFromTags` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63541,11 +60729,11 @@ BEGIN * @param vBarcode del item * @param vReference referencia a actualizar */ - + DECLARE vItemFk INT; SELECT barcodeToItem(vBarcode) INTO vItemFk; - + UPDATE item SET comment = vReference WHERE id = vItemFk; END ;; @@ -63568,7 +60756,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_setGeneric`(vSelf INT) BEGIN /** * Asigna el código genérico a un item, salvo que sea un código de item genérico. - * + * * @param vSelf identificador de vn.item */ DECLARE vGenericFk INT; @@ -63578,7 +60766,7 @@ BEGIN SELECT itemFk, SUM(matches) = maxMatches `match` FROM ( SELECT ga.id gaid, ga.itemFk, - CASE + CASE WHEN t.code = 'nflowers' THEN it.value <=> ga.numFlores WHEN t.code = 'origin' THEN @@ -63609,13 +60797,13 @@ BEGIN AND (i.`size` = ga.`size` OR ga.`size` IS NULL) AND i.id != ga.itemFk WHERE i.id = vSelf - AND NOT i.isFloramondo) sub + AND NOT i.isFloramondo) sub GROUP BY gaid HAVING `match`) sub2 LIMIT 1; - UPDATE vn.item - SET genericFk = vGenericFk + UPDATE vn.item + SET genericFk = vGenericFk WHERE id = vSelf; END ;; DELIMITER ; @@ -63657,11 +60845,11 @@ BEGIN SELECT DEFAULT(companyFk) INTO vDefaultCompanyFk FROM vn.ticket LIMIT 1; - - IF vAddressFk IS NULL THEN + + IF vAddressFk IS NULL THEN SELECT pc.shortageAddressFk INTO vAddressShortage FROM productionConfig pc ; - ELSE + ELSE SET vAddressShortage = vAddressFk; END IF; @@ -63726,18 +60914,18 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_updatePackingShelve`(vSelf INT, vPacking INT) BEGIN - + /** * Actualiza el valor de item.packingShelve - * + * * @param vSelf Identificador de vn.item * @param vPacking Cantidad de unidades de venta que caben en una bandeja */ - - UPDATE vn.item i + + UPDATE vn.item i SET i.packingShelve = vPacking WHERE i.id = vSelf; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -63780,204 +60968,240 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_ValuateInventory`(IN vDated DATE, IN vIsDetailed BOOLEAN) +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_ValuateInventory`(vDated DATE, vIsDetailed BOOLEAN) BEGIN + DECLARE vInventoried DATE; + DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE; + DECLARE vInventoryClone DATE; + DECLARE vDateDayEnd DATETIME; + DECLARE vInventorySupplierFk INT; - DECLARE vInventoried DATE; - DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE; - DECLARE vInventoried2 DATE; - DECLARE vDateDayEnd DATETIME; - DECLARE vInventorySupplierFk INT; + SELECT inventorySupplierFk INTO vInventorySupplierFk + FROM entryConfig; + + SET vDateDayEnd = util.dayEnd(vDated); - SELECT inventorySupplierFk INTO vInventorySupplierFk - FROM entryConfig; + SELECT tr.landed INTO vInventoried + FROM travel tr + JOIN `entry` e ON e.travelFk = tr.id + JOIN entryConfig ec + WHERE landed <= vDateDayEnd + AND e.supplierFk = vInventorySupplierFk + ORDER BY tr.landed DESC + LIMIT 1; - SET vDateDayEnd = util.dayEnd(vDated); + SET vHasNotInventory = (vInventoried IS NULL); + + IF vHasNotInventory THEN + SELECT landed INTO vInventoryClone + FROM travel tr + JOIN `entry` e ON e.travelFk = tr.id + JOIN entryConfig ec + WHERE landed >= vDated + AND e.supplierFk = vInventorySupplierFk + ORDER BY landed ASC + LIMIT 1; - SELECT landed INTO vInventoried - FROM travel tr - JOIN entry E ON E.travelFk = tr.id - WHERE landed <= vDateDayEnd - AND E.supplierFk = vInventorySupplierFk - ORDER BY landed DESC - LIMIT 1; + SET vInventoried = vDated + INTERVAL 1 DAY; + SET vDateDayEnd = vInventoryClone; + END IF; - SET vHasNotInventory = IF (vInventoried is null, TRUE, FALSE); + CREATE OR REPLACE TEMPORARY TABLE tInventory( + warehouseFk SMALLINT, + itemFk BIGINT, + quantity INT, + cost DOUBLE DEFAULT 0, + total DOUBLE DEFAULT 0, + warehouseInventory VARCHAR(20), + PRIMARY KEY (warehouseInventory, itemFk) USING HASH + ) + ENGINE = MEMORY; + + -- Inventario inicial + IF vHasNotInventory THEN + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + SUM(b.quantity), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = warehouseInFk + JOIN entryConfig ec + WHERE landed = vDateDayEnd + AND e.supplierFk = vInventorySupplierFk + AND w.valuatedInventory + AND t.isInventory + GROUP BY tr.warehouseInFk, b.itemFk; + ELSE + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + SUM(b.quantity), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = warehouseInFk + JOIN entryConfig ec + WHERE landed = vInventoried + AND e.supplierFk = vInventorySupplierFk + AND w.valuatedInventory + AND t.isInventory + GROUP BY tr.warehouseInFk, b.itemFk; + END IF; - IF vHasNotInventory THEN + -- Añadimos las entradas + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + b.quantity * IF(vHasNotInventory, -1, 1), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = tr.warehouseInFk + JOIN entryConfig ec + WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd + AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE) + AND NOT e.isRaid + AND w.valuatedInventory + AND t.isInventory + AND e.supplierFk <> vInventorySupplierFk + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory, -1, 1)); - SELECT landed INTO vInventoried2 - FROM travel tr - JOIN entry E ON E.travelFk = tr.id - WHERE landed >= vDated - AND E.supplierFk = vInventorySupplierFk - ORDER BY landed ASC - LIMIT 1; + -- Descontamos las salidas + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseOutFk, + b.itemFk, + b.quantity * IF(vHasNotInventory, 1, -1), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = tr.warehouseOutFk + WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd + AND NOT e.isRaid + AND w.valuatedInventory + AND t.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory,1,-1)); - SET vInventoried = TIMESTAMPADD(DAY,1,vDated); - SET vDateDayEnd = vInventoried2; + -- Descontamos las lineas de venta + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT w.id, + s.itemFk, + s.quantity * IF(vHasNotInventory, 1, -1), + w.name + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN `client` c ON c.id = t.clientFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd + AND w.valuatedInventory + AND it.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 1, -1); - END IF; + -- Volver a poner lo que esta aun en las estanterias + IF vDated = util.VN_CURDATE() THEN + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT w.id, + s.itemFk, + s.quantity * IF(vHasNotInventory, 0, 1), + w.name + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN `client` c ON c.id = t.clientFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDated AND vDateDayEnd + AND NOT (s.isPicked OR t.isLabeled) + AND w.valuatedInventory + AND it.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 0, 1); + END IF; - DROP TEMPORARY TABLE IF EXISTS inv; + -- Mercancia en transito + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + b.quantity, + CONCAT(wOut.`name`, ' - ', wIn.`name`) + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + WHERE vDated >= tr.shipped AND vDated < tr.landed + AND NOT isRaid + AND wIn.valuatedInventory + AND t.isInventory + AND e.isConfirmed + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity); + + CALL vn.buyUltimate(NULL, vDateDayEnd); - CREATE TEMPORARY TABLE inv - (warehouseFk SMALLINT, - Id_Article BIGINT, - cantidad INT, - coste DOUBLE DEFAULT 0, - total DOUBLE DEFAULT 0, - Almacen VARCHAR(20), - PRIMARY KEY (Almacen, Id_Article) USING HASH) - ENGINE = MEMORY; + UPDATE tInventory i + JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk + JOIN buy b ON b.id = bu.buyFk + SET total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)), + cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0) + WHERE i.quantity; - IF vHasNotInventory = TRUE THEN + DELETE FROM tInventory + WHERE quantity IS NULL OR NOT quantity; - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, SUM(b.quantity), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = warehouseInFk - WHERE landed = vDateDayEnd - AND e.supplierFk = vInventorySupplierFk - AND w.valuatedInventory - AND t.isInventory - GROUP BY tr.warehouseInFk, b.itemFk; - - END IF; - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, - b.itemFk, - b.quantity * IF(vHasNotInventory,-1,1), - w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = tr.warehouseInFk - WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd - AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, trUE) - AND NOT e.isRaid - AND w.valuatedInventory - AND t.isInventory - AND e.supplierFk <> vInventorySupplierFk - ON DUPLICATE KEY UPDATE inv.cantidad = - inv.cantidad + (b.quantity * IF(vHasNotInventory,-1,1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseOutFk, b.itemFk, b.quantity * IF(vHasNotInventory,1,-1), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = tr.warehouseOutFk - WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd - AND NOT e.isRaid - AND w.valuatedInventory - AND t.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity * IF(vHasNotInventory,1,-1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,1,-1), w.`name` - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN `client` c ON c.id = t.clientFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd - AND w.valuatedInventory - AND it.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,1,-1); - - IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,0,1), w.`name` - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN `client` c ON c.id = t.clientFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDated AND vDateDayEnd - AND (s.isPicked <> 0 or t.isLabeled <> 0 ) - AND w.valuatedInventory - AND it.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,0,1); - - END IF; - - -- Mercancia en transito - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, b.quantity, CONCAT(wOut.`name`,' - ', wIn.`name`) - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk - WHERE vDated >= tr.shipped AND vDated < tr.landed - AND NOT isRaid - AND wIn.valuatedInventory - AND t.isInventory - AND e.isConfirmed - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity); - - CALL vn.buyUltimate(NULL,vDateDayEnd); - - UPDATE inv i - JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.Id_Article = bu.itemFk - JOIN buy b ON b.id = bu.buyFk - SET total = i.cantidad * (ifnull(b.buyingValue,0) + IFNULL(b.packageValue,0) + IFNULL(b.freightValue,0) + IFNULL(b.comissionValue,0)), - coste = ifnull(b.buyingValue,0) + IFNULL(b.packageValue,0) + IFNULL(b.freightValue,0) + IFNULL(b.comissionValue,0) - WHERE i.cantidad <> 0; - - DELETE FROM inv WHERE Cantidad IS NULL or Cantidad = 0; - - IF vIsDetailed THEN - - SELECT inv.warehouseFk, - i.id itemFk, - i.longName , - i.size, - inv.Cantidad, - tp.name Tipo, - ic.name Reino, - inv.coste, - cast(inv.total as decimal(10,2)) total, - almacen - FROM inv - JOIN warehouse w on w.id = warehouseFk - JOIN item i ON i.id = inv.Id_Article - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - WHERE w.valuatedInventory - and inv.total > 0 - order by inv.total desc; - - ELSE - - SELECT i.Almacen, ic.name as Reino, cast(i.total as decimal(10,2)) as Euros, w.code as Comprador,it.id - FROM inv i - JOIN warehouse wh on wh.id = warehouseFk - JOIN item it ON it.id = i.Id_Article - JOIN itemType itp ON itp.id = it.typeFk - LEFT JOIN worker w ON w.id = itp.workerFk - JOIN itemCategory ic ON ic.id = itp.categoryFk + IF vIsDetailed THEN + SELECT ti.warehouseFk, + i.id itemFk, + i.longName, + i.size, + ti.quantity, + tp.name Tipo, + ic.name Reino, + ti.cost, + CAST(ti.total AS DECIMAL(10, 2)) total, + ti.warehouseInventory almacen + FROM tInventory ti + JOIN warehouse w ON w.id = warehouseFk + JOIN item i ON i.id = ti.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + WHERE w.valuatedInventory + AND ti.total > 0 + ORDER BY ti.total DESC; + ELSE + SELECT i.warehouseInventory Almacen, + ic.name Reino, + CAST(i.total AS DECIMAL(10, 2)) Euros, + w.code Comprador, + it.id + FROM tInventory i + JOIN warehouse wh ON wh.id = warehouseFk + JOIN item it ON it.id = i.itemFk + JOIN itemType itp ON itp.id = it.typeFk + LEFT JOIN worker w ON w.id = itp.workerFk + JOIN itemCategory ic ON ic.id = itp.categoryFk WHERE wh.valuatedInventory - AND i.total > 0; + AND i.total > 0; + END IF; - END IF; - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE inv; + DROP TEMPORARY TABLE + tmp.buyUltimate, + tInventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -63996,10 +61220,10 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_zoneClosure`() BEGIN - -/* Devuelve una tabla temporal con la hora minima de un ticket sino tiene el de la zoneClosure y + +/* Devuelve una tabla temporal con la hora minima de un ticket sino tiene el de la zoneClosure y * si tampoco hay el de la zona , para todos los artículos con salida hoy. - * + * * @return tmp.itemZoneClosure(itemFk, timed) */ @@ -64010,7 +61234,7 @@ BEGIN MIN(DATE_FORMAT(IF(HOUR(t.shipped),t.shipped, IFNULL(zc.hour, z.HOUR)), '%H:%i') )timed - FROM ticket t + FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN `zone` z ON z.id = t.zoneFk LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk @@ -64043,37 +61267,37 @@ BEGIN * @param vConcept descripcion * @param vAmount cantidad que se compensa * @param vCompany empresa - * @param vOriginalAccount cuenta contable desde la cual se compensa - * - */ + * @param vOriginalAccount cuenta contable desde la cual se compensa + * + */ DECLARE vNewBookEntry INT; DECLARE vIsClientCompensation INT; DECLARE vClientFk INT; DECLARE vSupplierFk INT; DECLARE vIsOriginalAClient BOOL; DECLARE vPayMethodCompensation INT; - + CALL ledger_next(vNewBookEntry); SELECT COUNT(id) INTO vIsOriginalAClient FROM client WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci; - SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation - FROM client + SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation + FROM client WHERE accountingAccount LIKE vCompensationAccount COLLATE utf8_general_ci; - + SET @vAmount1:= 0.0; SET @vAmount2:= 0.0; - INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id) - VALUES ( vNewBookEntry, - vDated, - vOriginalAccount, - vCompensationAccount, - vConcept, + INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id) + VALUES ( vNewBookEntry, + vDated, + vOriginalAccount, + vCompensationAccount, + vConcept, @vAmount1:= IF( - (vIsOriginalAClient AND vAmount > 0) OR - (NOT vIsOriginalAClient AND vAmount < 0), - 0, + (vIsOriginalAClient AND vAmount > 0) OR + (NOT vIsOriginalAClient AND vAmount < 0), + 0, ABS(vAmount) ), @vAmount2:= IF(@vAmount1, @@ -64082,20 +61306,20 @@ BEGIN ), vCompanyFk ), - ( vNewBookEntry, - vDated, - vCompensationAccount, - vOriginalAccount, - vConcept, + ( vNewBookEntry, + vDated, + vCompensationAccount, + vOriginalAccount, + vConcept, @vAmount2, @vAmount1, vCompanyFk); - + IF vIsClientCompensation THEN IF vIsOriginalAClient THEN SET vAmount = -vAmount; END IF; - INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate) + INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate) VALUES (vConcept, vAmount, vDated, vBankFk, vCompanyFk, vClientFk, TRUE); ELSE IF NOT vIsOriginalAClient THEN @@ -64103,7 +61327,7 @@ BEGIN END IF; SELECT id INTO vSupplierFk FROM supplier WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci; SELECT id INTO vPayMethodCompensation FROM payMethod WHERE `code` = 'compensation'; - + INSERT INTO payment (received, dueDated, supplierFk, amount, bankFk, payMethodFk, concept, companyFk, isConciliated) VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE); END IF; @@ -64125,10 +61349,10 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ledger_next`(OUT vNewBookEntry INT) BEGIN - + UPDATE vn.ledgerConfig SET lastBookEntry = LAST_INSERT_ID(lastBookEntry + 1); SET vNewBookEntry = LAST_INSERT_ID(); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64154,15 +61378,15 @@ BEGIN * @param vEntity Nombre que hace referencia a la tabla. */ DECLARE vTableName VARCHAR(45); - + SET vTableName = CONCAT(vEntity, 'Log'); - + SET @qryLog := CONCAT( 'SELECT ot.id, ot.originFk, ot.userFk, u.name, ot.action, ot.creationDate, ot.description FROM ', vTableName, ' AS ot', ' INNER JOIN account.user u ON u.id = ot.userFk', ' WHERE ot.originFk = ', vOriginFk, ' ORDER BY ot.creationDate DESC' ); - + PREPARE stmt FROM @qryLog; EXECUTE stmt; END ;; @@ -64187,9 +61411,9 @@ BEGIN SET @buildingOrder := 0; SET @route := 0; set @cajas := 0; - + UPDATE tmp.sorter - SET buildingOrder = @buildingOrder := IF(@route = @route := routeFk, @buildingOrder, 0) + 1 + SET buildingOrder = @buildingOrder := IF(@route = @route := routeFk, @buildingOrder, 0) + 1 where date(created) = vDate order by routeFk, created, weight DESC; @@ -64207,23 +61431,23 @@ set @cajas := 0; UPDATE tmp.sorter SET lungGrow = IF(palletOrder = 0, -13, lungGrow); - + DELETE FROM tmp.lungSize WHERE dia = vDate; - + INSERT INTO tmp.lungSize(dia, hora,size) select vDate,hora, @cajas := @cajas + cajas as size from ( select IF(lungGrow BETWEEN -12 AND -1, ETD,time_format(created,"%H:%i")) as hora, sum(if(lungGrow <= 0, lungGrow, 1)) as cajas, @cajas := 0 - from tmp.sorter + from tmp.sorter where date(created) = vDate group by hora ) sub; - + SELECT * FROM tmp.lungSize WHERE dia = vDate; - - + + END ;; @@ -64244,23 +61468,23 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT) BEGIN - + /** * Inserta registro si el vWorkerFk no ha registrado nada en las últimas 12 horas * @param vPlate número de matrícula - * @param vWorkerFk id del worker - * -*/ - UPDATE vn.machineWorker mw - JOIN vn.machine m ON m.id = mw.machineFk + * @param vWorkerFk id del worker + * +*/ + UPDATE vn.machineWorker mw + JOIN vn.machine m ON m.id = mw.machineFk SET mw.outTimed = util.VN_NOW() WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate) AND ISNULL(mw.outTimed); - + INSERT INTO machineWorker (machineFk, workerFk) SELECT m.id, vWorkerFk FROM machine m - WHERE m.plate= vPlate; + WHERE m.plate= vPlate; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64280,21 +61504,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT) BEGIN /** - * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, + * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, * si es jefe de producción muestra el historial completo. - * + * * @param vPlate número de matrícula - * @param vWorkerFk id del trabajador - * + * @param vWorkerFk id del trabajador + * */ DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vWorkerFk); - SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed + SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed FROM machineWorker mw JOIN machine m ON m.plate = vPlate WHERE mw.machineFk = m.id AND mw.workerFk = IF(account.user_hasRole(vWorkerName, 'coolerAssist'), mw.workerFk, vWorkerFk) - ORDER BY mw.inTimed DESC; + ORDER BY mw.inTimed DESC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64313,13 +61537,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT) BEGIN - + /** - * Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate, - * + * Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate, + * * @param vPlate número de matrícula - * @param vWorkerFk id del trabajador - * + * @param vWorkerFk id del trabajador + * */ DECLARE vMachineFk INT(10); @@ -64328,24 +61552,24 @@ BEGIN SELECT m.id INTO vMachineFk FROM machine m WHERE m.plate = vPlate; - + SELECT maxHours INTO vMaxHours FROM machineWorkerConfig; - IF (SELECT COUNT(*) + IF (SELECT COUNT(*) FROM machineWorker m WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN - + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN + UPDATE machineWorker m SET m.outTimed = CURRENT_TIMESTAMP() - WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed) AND m.machineFk = vMachineFk; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64400,12 +61624,12 @@ BEGIN /** * Inserta en la tabla vn.mail * - * @param vReceiver Receptor del correo + * @param vReceiver Receptor del correo * @param vReplyTo A quién contestar el correo * @param vSubject Título del correo * @param vBody Cuerpo del correo */ - + DECLARE vIsRepeated BOOLEAN; SELECT COUNT(*) INTO vIsRepeated @@ -64446,12 +61670,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `makeNewItem`() BEGIN DECLARE newItemFk INT; - + SELECT getNewItemId() INTO newItemFk; - + INSERT INTO item(id,name,typeFk,originFk) SELECT newItemFk, 'Nuevo artículo', 78,39; - + SELECT newItemFk; @@ -64479,34 +61703,34 @@ BEGIN DECLARE vMinute INT DEFAULT 0; DECLARE vBoxes INT; - + DROP TEMPORARY TABLE IF EXISTS vn.pcsDay; CREATE TEMPORARY TABLE vn.pcsDay SELECT 0 as hh, 0 as mm, 0 as boxes; - + -- Creamos una tabla soporte para acumular las cajas a lo largo del dia WHILE vHour < 24 DO - + WHILE vMinute < 59 DO - + SET vMinute = vMinute + 1; - + INSERT INTO vn.pcsDay(hh,mm) VALUES(vHour, vMinute); - + END WHILE; - + SET vMinute = -1; SET vHour = vHour + 1; - + END WHILE; - + -- Acumulamos UPDATE vn.pcsDay pd LEFT JOIN (SELECT * FROM vn.pcs_graf WHERE dia = vDated) pg USING(hh,mm) SET pd.boxes = pd.boxes + pg.box; - + SELECT * FROM vn.pcsDay; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64543,7 +61767,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.client SELECT id - FROM client + FROM client WHERE salesPersonFk = vWorkerFk; CALL client_getMana(); @@ -64553,7 +61777,7 @@ BEGIN FROM tmp.clientMana ON DUPLICATE KEY UPDATE amount = VALUES(amount); - DROP TEMPORARY TABLE + DROP TEMPORARY TABLE tmp.client, tmp.clientMana; END ;; @@ -64572,196 +61796,197 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `multipleInventory`( - vDate DATE, - vWarehouseFk TINYINT, - vMaxDays TINYINT +CREATE DEFINER=`root`@`localhost` PROCEDURE `multipleInventory`( + vDate DATE, + vWarehouseFk TINYINT, + vMaxDays TINYINT ) -proc: BEGIN - DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; - DECLARE vDateFrom DATE DEFAULT vDate; - DECLARE vDateTo DATETIME; - DECLARE vDateToTomorrow DATETIME; - DECLARE vDefaultDayRange INT; - - IF vDate < util.VN_CURDATE() THEN - LEAVE proc; - END IF; - - IF vDate = util.VN_CURDATE() THEN - SELECT inventoried INTO vDateFrom - FROM config; - END IF; - - SELECT defaultDayRange INTO vDefaultDayRange - FROM comparativeConfig; - - SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; - SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; - - ALTER TABLE vn2008.article_inventory - ADD `avalaible` INT NOT NULL, - ADD `sd` INT NOT NULL, - ADD `rest` INT NOT NULL, - ADD `expected` INT NOT NULL, - ADD `inventory` INT NOT NULL, - ADD `visible` INT NOT NULL, - ADD `life` TINYINT NOT NULL DEFAULT '0'; - - -- Calculo del inventario - UPDATE vn2008.article_inventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, - s.quantity quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - ) sub2 - GROUP BY itemFk - ) sub ON ai.article_id = sub.Id_Article - SET ai.inventory = sub.Subtotal, - ai.visible = sub.Subtotal, - ai.avalaible = sub.Subtotal, - ai.sd = sub.Subtotal; - - -- Cálculo del visible - UPDATE vn2008.article_inventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, s.quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped >= vDate - AND t.shipped < vDateTomorrow - AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - ) sub2 - GROUP BY itemFk - ) sub ON ai.article_id = sub.Id_Article - SET ai.visible = ai.visible + sub.Subtotal; - - -- Calculo del disponible - CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc - (INDEX (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT sub.itemFk, - vWarehouseFk warehouseFk, - sub.dated, - SUM(sub.quantity) quantity - FROM ( - SELECT s.itemFk, - DATE(t.shipped) dated, - - s.quantity quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, t.landed, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, t.shipped, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - ) sub - GROUP BY sub.itemFk, sub.dated; - - CALL item_getAtp(vDate); - CALL vn2008.item_travel(vWarehouseFk, vDate); - UPDATE vn2008.article_inventory ai - JOIN ( - SELECT it.itemFk, - SUM(it.quantity) quantity, - im.quantity minQuantity - FROM tmp.itemCalc it - JOIN tmp.itemAtp im ON im.itemFk = it.itemFk - JOIN item i ON i.id = it.itemFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN vn2008.item_travel t ON t.wh = o.warehouseFk - WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, - t.landing, - vDateToTomorrow) - GROUP BY it.itemFk - ) sub ON sub.itemFk = ai.article_id - SET ai.avalaible = IF(sub.minQuantity > 0, - ai.avalaible, - ai.avalaible + sub.minQuantity), - ai.sd = ai.inventory + sub.quantity; - - DROP TEMPORARY TABLE - vn2008.item_travel, - tmp.itemCalc, - tmp.itemAtp; +proc: BEGIN + DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; + DECLARE vDateFrom DATE DEFAULT vDate; + DECLARE vDateTo DATETIME; + DECLARE vDateToTomorrow DATETIME; + DECLARE vDefaultDayRange INT; + + IF vDate < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + IF vDate = util.VN_CURDATE() THEN + SELECT inventoried INTO vDateFrom + FROM config; + END IF; + + SELECT defaultDayRange INTO vDefaultDayRange + FROM comparativeConfig; + + SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; + SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; + + ALTER TABLE tmp.itemInventory + ADD `avalaible` INT NOT NULL, + ADD `sd` INT NOT NULL, + ADD `rest` INT NOT NULL, + ADD `expected` INT NOT NULL, + ADD `inventory` INT NOT NULL, + ADD `visible` INT NOT NULL, + ADD `life` TINYINT NOT NULL DEFAULT '0'; + + -- Calculo del inventario + UPDATE tmp.itemInventory ai + JOIN ( + SELECT itemFk Id_Article, SUM(quantity) Subtotal + FROM ( + SELECT s.itemFk, - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + ) sub2 + GROUP BY itemFk + ) sub ON ai.id = sub.Id_Article + SET ai.inventory = sub.Subtotal, + ai.visible = sub.Subtotal, + ai.avalaible = sub.Subtotal, + ai.sd = sub.Subtotal; + + -- Cálculo del visible + UPDATE tmp.itemInventory ai + JOIN ( + SELECT itemFk Id_Article, SUM(quantity) Subtotal + FROM ( + SELECT s.itemFk, s.quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped >= vDate + AND t.shipped < vDateTomorrow + AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed = vDate + AND NOT t.isReceived + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped = vDate + AND NOT t.isReceived + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + ) sub2 + GROUP BY itemFk + ) sub ON ai.id = sub.Id_Article + SET ai.visible = ai.visible + sub.Subtotal; + + -- Calculo del disponible + CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT sub.itemFk, + vWarehouseFk warehouseFk, + sub.dated, + SUM(sub.quantity) quantity + FROM ( + SELECT s.itemFk, + DATE(t.shipped) dated, + - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, t.landed, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, t.shipped, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + ) sub + GROUP BY sub.itemFk, sub.dated; + + CALL item_getAtp(vDate); + CALL travel_upcomingArrivals(vWarehouseFk, vDate); + + UPDATE tmp.itemInventory ai + JOIN ( + SELECT it.itemFk, + SUM(it.quantity) quantity, + im.quantity minQuantity + FROM tmp.itemCalc it + JOIN tmp.itemAtp im ON im.itemFk = it.itemFk + JOIN item i ON i.id = it.itemFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN tmp.itemTravel t ON t.wh = o.warehouseFk + WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, + t.landing, + vDateToTomorrow) + GROUP BY it.itemFk + ) sub ON sub.itemFk = ai.id + SET ai.avalaible = IF(sub.minQuantity > 0, + ai.avalaible, + ai.avalaible + sub.minQuantity), + ai.sd = ai.inventory + sub.quantity; + + DROP TEMPORARY TABLE + tmp.itemTravel, + tmp.itemCalc, + tmp.itemAtp; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64782,20 +62007,20 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqlConnectionsSorter_kill`() BEGIN /** - * Elimina conexiones del usuario sorter con tiempo >= 30seg. Asociado al evento con el mismo nombre - */ - + * Elimina conexiones del usuario sorter con tiempo >= 30seg. Asociado al evento con el mismo nombre + */ + DECLARE vDone INT DEFAULT 0; DECLARE vProcesId INT; DECLARE vCursor CURSOR FOR - SELECT p.id + SELECT p.id FROM information_schema.processlist p - WHERE USER = 'sorter' + WHERE USER = 'sorter' AND TIME >= 30; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + OPEN vCursor; l: LOOP @@ -64832,7 +62057,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqlPreparedCount_check`() BEGIN DECLARE vPreparedCount INTEGER; - SELECT VARIABLE_VALUE INTO vPreparedCount + SELECT VARIABLE_VALUE INTO vPreparedCount FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME LIKE '%prepared_stmt_count%'; @@ -64840,7 +62065,7 @@ BEGIN CALL `vn`.`mail_insert`('cau@verdnatura.es', NULL, 'Problemas BBDD prepared_stmt_count', - CONCAT('Existen problemas con el servicio de Logiflora, prepared_stmt_count con valor: ', + CONCAT('Existen problemas con el servicio de Logiflora, prepared_stmt_count con valor: ', vPreparedCount, ', está próximo a exceder su límite. \r\n Hay que reiniciar el servicio LF.VMP.Service del servidor a3.') ); @@ -64867,37 +62092,37 @@ BEGIN DECLARE newShelving VARCHAR(3); DECLARE vCode VARCHAR(3); - + SELECT MAX(code) INTO vCode FROM vn.shelving WHERE isPrinted = FALSE; - + SET @a1 := ASCII(MID(vCode,1,1)); SET @a2 := ASCII(MID(vCode,2,1)); SET @a3 := ASCII(MID(vCode,3,1)) + 1; - + IF @a3 > 90 THEN - + SET @a3 = 65; SET @a2 = @a2 + 1; - + IF @a2 > 90 THEN - + SET @a2 = 65; SET @a1 = @a1 + 1; - + IF @a1 > 90 THEN - + SET @a1 = 65; - + END IF; - + END IF; - + END IF; SET newShelving = CHAR(@a1,@a2,@a3 USING utf8); - + INSERT INTO vn.shelving(code) VALUES(newShelving); END ;; @@ -64926,18 +62151,18 @@ BEGIN * @param descripcion Texto de la observacion */ DECLARE vTableName VARCHAR(45); - + SET vTableName = CONCAT(vTableCode,'Observation'); - + IF ISNULL(vTableName) THEN CALL util.throw('CODE_NOT_FOUND'); END IF; - + SET @qryLog := CONCAT( 'INSERT INTO ', vTableName, ' (originFk, userFk, description)', ' VALUES (', vOriginFk, ', ', account.myUser_getId(), ', "', vDescription, '")' ); - + PREPARE stmt FROM @qryLog; EXECUTE stmt; DEALLOCATE PREPARE stmt; @@ -64967,15 +62192,15 @@ BEGIN DECLARE vDeliveryMethod INT; DECLARE vClient INT; - + SELECT deliveryMethodFk INTO vDeliveryMethod - FROM vn.agencyMode + FROM vn.agencyMode WHERE id = vAgencyMode; - + SELECT clientFk INTO vClient FROM vn.address WHERE id = vAddress; - + INSERT INTO hedera.order(date_send,customer_id,delivery_method_id,agency_id,address_id,source_app) VALUES( vLanded,vClient ,vDeliveryMethod,vAgencyMode ,vAddress ,vSourceApp); @@ -65001,7 +62226,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `orderDelete`(IN vId INT) BEGIN DELETE FROM hedera.`order` where id = vId; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65028,7 +62253,7 @@ BEGIN DECLARE vOrderId INT; CALL vn.orderCreate(vLanded,vAgencyMode,vAddress,vSourceApp,vOrderId); SELECT vOrderId; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65048,7 +62273,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `orderListVolume`(IN vOrderId INT) BEGIN - SELECT + SELECT o.id, o.itemFk, i.description, @@ -65074,7 +62299,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `packageInvoicing`( +CREATE DEFINER=`root`@`localhost` PROCEDURE `packageInvoicing`( IN vClient INT, IN vDate DATE, IN vCompany INT, @@ -65093,20 +62318,20 @@ BEGIN SET vGraceDays = IF(vIsAllInvoiceable ,0, 30); SET vGraceDate = TIMESTAMPADD(DAY, - vGraceDays, vDate); - - /* Clientes especiales: + + /* Clientes especiales: 3240 MADEFLOR 992 JAVIER FELIU 4 TONI VENDRELL */ - + IF vClient IN (992, 3240, 4) THEN - + SET vGraceDays = 365; - + END IF; /* Fin clientes especiales */ - + SET vDateEnd = DATE_ADD(vDate, INTERVAL 1 DAY); DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoice; @@ -65130,22 +62355,22 @@ BEGIN FROM tmp.packageToInvoice GROUP BY itemFk HAVING totalQuantity > 0; - + SELECT COUNT(*) INTO vIsInvoiceable FROM tmp.packageToInvoicePositives; IF vIsInvoiceable THEN - CALL ticket_add(vClient, + CALL ticket_add(vClient, vDateEnd, - vWarehouse, - vCompany, - NULL, - NULL, - NULL, - vDateEnd, - account.myUser_getId(), + vWarehouse, + vCompany, + NULL, + NULL, + NULL, + vDateEnd, + account.myUser_getId(), TRUE, vNewTicket); @@ -65154,44 +62379,44 @@ BEGIN packagingFk, quantity, pvp) - SELECT vNewTicket, - pti.packagingFk, - - SUM(pti.quantity) AS totalQuantity, + SELECT vNewTicket, + pti.packagingFk, + - SUM(pti.quantity) AS totalQuantity, pti.price FROM tmp.packageToInvoice pti - LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk - WHERE ptip.itemFK IS NOT NULL + LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk + WHERE ptip.itemFK IS NOT NULL OR vIsAllInvoiceable GROUP BY packagingFk HAVING totalQuantity; INSERT INTO sale( ticketFk, - itemFk, - concept, - quantity, + itemFk, + concept, + quantity, price ) - SELECT vNewTicket, - pti.itemFk, - i.name as concept, - sum(pti.quantity) as totalQuantity, + SELECT vNewTicket, + pti.itemFk, + i.name as concept, + sum(pti.quantity) as totalQuantity, pti.price FROM tmp.packageToInvoice pti JOIN item i ON i.id = pti.itemFk LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk - WHERE ptip.itemFK IS NOT NULL + WHERE ptip.itemFK IS NOT NULL OR vIsAllInvoiceable GROUP BY pti.itemFk HAVING totalQuantity; - + INSERT INTO saleComponent(saleFk, componentFk, value) SELECT id, vComponentCost, price FROM sale WHERE ticketFk = vNewTicket; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65217,7 +62442,7 @@ BEGIN WHERE mm.valor = 1 -- Listo para imprimir AND mm.stateFk = 9 -- Encajando AND m.Id_Ticket = ticketFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65239,15 +62464,15 @@ BEGIN DECLARE valueFk INT; DECLARE encajando INT DEFAULT 9; - - SELECT valor INTO valueFk - FROM vn2008.Movimientos_mark - WHERE Id_Movimiento = saleFk + + SELECT valor INTO valueFk + FROM vn2008.Movimientos_mark + WHERE Id_Movimiento = saleFk AND stateFk = encajando; - + SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3; - - REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk) + + REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk) VALUES(saleFk,valueFk,account.myUser_getId(),encajando); @@ -65339,34 +62564,34 @@ BEGIN DECLARE vLetters VARCHAR(26) DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; DECLARE vMaxId INT; DECLARE vCode VARCHAR(8); - + SET vColumn = vFromColumn; SET vRow = vFromRow; SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - + SELECT MAX(id) INTO vMaxId FROM vn.parking; WHILE vColumn <= vToColumn DO - + WHILE vRow <= vToRow DO - + INSERT IGNORE INTO vn.parking(`column`, `row`, sectorFk, `code`, pickingOrder) VALUES (vColumn, vRow, vSectorFk, vCode, vColumn * 100 + vRow ) ON DUPLICATE KEY UPDATE `code` = vCode; - + SET vRow = vRow + 1; SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - + END WHILE; - + SET vRow = vFromRow; SET vColumn = vColumn + 1; - + SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - + END WHILE; - + SELECT * FROM vn.parking WHERE `column` BETWEEN vFromColumn AND vToColumn; END ;; @@ -65391,59 +62616,59 @@ BEGIN DECLARE vRow INT; DECLARE vCode VARCHAR(8); DECLARE i INT; - + IF vToRow < vFromRow THEN - + SET vRow = vFromRow; - + WHILE vRow >= vToRow DO - + SET i = 1; - + WHILE i <= vTrolleysByLine DO - + SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); - + INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) VALUES (vSectorFk, vCode, vPickingOrder + (i * 10)) ON DUPLICATE KEY UPDATE `code` = vCode; - + SET i = i + 1; - + END WHILE; - + SET vRow = vRow - 1; - + END WHILE; ELSE - + SET vRow = vFromRow; - + WHILE vRow <= vToRow DO - + SET i = 1; - + WHILE i <= vTrolleysByLine DO - + SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); - + INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) VALUES (vSectorFk, vCode, vPickingOrder + (i * 10) ) ON DUPLICATE KEY UPDATE `code` = vCode; - + SET i = i + 1; - + END WHILE; - + SET vRow = vRow + 1; - + END WHILE; - - + + END IF; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65467,28 +62692,28 @@ BEGIN DECLARE vColumn INT; DECLARE vLetters VARCHAR(200); DECLARE vLettersLength INT; - + SET vColumn = vStart; SET vRow = 1; SET vLetters = 'ABCDEF'; SET vLettersLength = LENGTH(vLetters); - + WHILE vColumn <= vEnd DO - + REPLACE vn.parking(`column`, `row`, `code`, sectorFk) VALUES(vColumn, vRow, CONCAT(vColumn,MID(vLetters,vRow,1)), vSectorFk); - + SET vRow = vRow + 1; - + IF vRow > vLettersLength THEN - + SET vRow = 1; SET vColumn = vColumn + 1; - + END IF; - + END WHILE; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65507,11 +62732,11 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_setOrder`(vWarehouseFk INT) BEGIN - + /* * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor */ - + UPDATE vn.parking p JOIN ( SELECT code, @@ -65520,15 +62745,15 @@ BEGIN SELECT c.prepOrder, p.code, @orden := 0, - IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , - CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication + IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , + CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication FROM vn.parking p - JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci - WHERE s.warehouseFk = vWarehouseFk) sub - ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code + WHERE s.warehouseFk = vWarehouseFk) sub + ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code SET p.pickingOrder = sub2.po; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65547,17 +62772,17 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `prepareClientList`() BEGIN - + /* * Require la tabla tmp.ticket(id,clientFk) */ - + DROP TEMPORARY TABLE IF EXISTS tmp.client; CREATE TEMPORARY TABLE tmp.client (PRIMARY KEY (id)) ENGINE = MEMORY SELECT DISTINCT clientFk id - FROM tmp.ticket; + FROM tmp.ticket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65685,14 +62910,14 @@ BEGIN /** * Comprueba si la impresora pertenece al sector * - * @param vLabelerFk id de la impresora + * @param vLabelerFk id de la impresora * @param vSector sector a comprobar */ DECLARE isPrinterInNewSector BOOL; IF vLabelerFk IS NOT NULL THEN SELECT COUNT(sectorFK) INTO isPrinterInNewSector - FROM vn.printer p + FROM vn.printer p WHERE id = vLabelerFk AND sectorFk = vSector; IF !isPrinterInNewSector THEN @@ -65716,7 +62941,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `productionControl`( - vWarehouseFk INT, + vWarehouseFk INT, vScopeDays INT ) proc: BEGIN @@ -65817,7 +63042,7 @@ proc: BEGIN LEFT JOIN parking pk ON pk.id = tp.parkingFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); - + UPDATE tmp.productionBuffer pb JOIN ( SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking @@ -65825,12 +63050,12 @@ proc: BEGIN JOIN sale s ON s.ticketFk = pb.ticketFk JOIN saleGroupDetail sgd ON sgd.saleFk = s.id JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - JOIN parking p ON p.id = sg.parkingFk + JOIN parking p ON p.id = sg.parkingFk GROUP BY pb.ticketFk ) t ON t.ticketFk = pb.ticketFk SET pb.previaParking = t.previaParking; - -- Problemas por ticket + -- Problemas por ticket ALTER TABLE tmp.productionBuffer CHANGE COLUMN `problem` `problem` VARCHAR(255), ADD COLUMN `collectionH` INT, @@ -66030,8 +63255,8 @@ BEGIN FROM saleMistake sm JOIN saleTracking st ON sm.saleFk = st.saleFk JOIN `state` s2 ON s2.id = st.stateFk - JOIN sale s ON s.id = sm.saleFk - JOIN ticket t on t.id = s.ticketFk + JOIN sale s ON s.id = sm.saleFk + JOIN ticket t on t.id = s.ticketFk WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') GROUP BY st.workerFk; @@ -66042,7 +63267,7 @@ BEGIN SELECT COUNT(t.id) errors, e.workerFk FROM vn.expeditionMistake pm - JOIN vn.expedition e ON e.id = pm.expeditionFk + JOIN vn.expedition e ON e.id = pm.expeditionFk JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo GROUP BY e.workerFk; @@ -66094,16 +63319,16 @@ BEGIN LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = t.workerFk JOIN (SELECT DISTINCT w.id -- Verificamos que son sacadores FROM vn.collection c - JOIN vn.state s ON s.id = c.stateFk + JOIN vn.state s ON s.id = c.stateFk JOIN vn.train tn ON tn.id = c.trainFk - JOIN vn.worker w ON w.id = c.workerFk + JOIN vn.worker w ON w.id = c.workerFk WHERE c.created BETWEEN vDatedFrom AND vDatedTo) sub ON sub.id = w.id GROUP BY w.id; CREATE OR REPLACE TEMPORARY TABLE itemPickerErrors -- Errores de los sacadores, derivadores de los revisadores ENGINE = MEMORY SELECT COUNT(c.ticketFk) errors, - tt.workerFk + tt.userFk FROM claimDevelopment cd JOIN claim c ON cd.claimFk = c.id JOIN ticket t ON c.ticketFk = t.id @@ -66113,10 +63338,10 @@ BEGIN WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.code = 'chk' AND s.code = 'ON_PREPARATION' - GROUP BY workerFk; + GROUP BY tt.userFk; UPDATE productionError ep - JOIN itemPickerErrors ipe ON ipe.workerFk = ep.userFk + JOIN itemPickerErrors ipe ON ipe.userFk = ep.userFk SET ep.error = ep.error + ipe.errors WHERE vDatedFrom = ep.dated AND ep.rol = 'Sacadores'; @@ -66308,7 +63533,6 @@ BEGIN JOIN vn.packagingConfig pc WHERE IF(s.isPreviousPreparedByPacking, i.`size` > pc.previousPreparationMinimumSize - AND isa.packing > 1 AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), TRUE) AND sgd.saleFk IS NULL @@ -66363,7 +63587,7 @@ BEGIN `yearMonth` INT ) ENGINE = MEMORY; - + WHILE vDated <= vEnded DO INSERT INTO tmp.rangeDate SET `dated` = vDated, @@ -66373,7 +63597,7 @@ BEGIN `day` = DAY(vDated), `week` = WEEK(vDated, 1), `yearMonth` = YEAR(vDated) * 100 + MONTH(vDated); - + SET vDated = DATE_ADD(vDated, INTERVAL 1 DAY); END WHILE; END ;; @@ -66462,7 +63686,7 @@ BEGIN CALL cache.available_refresh(vCalc, FALSE, vWarehouseFk, vDate); DROP TEMPORARY TABLE IF EXISTS tmp.recipeCook; - + CREATE TEMPORARY TABLE tmp.recipeCook SELECT *, @counter := IF(@element = element COLLATE utf8_general_ci , @counter + 1, 1) as counter, @@ -66480,22 +63704,22 @@ BEGIN IFNULL((i.inkFk = r.inkFk ) ,0) + IFNULL((i.size = r.size) ,0) + IFNULL((i.name LIKE CONCAT('%',r.name,'%')) ,0) - + IFNULL((i.longName LIKE CONCAT('%',r.longName,'%')),0) + + IFNULL((i.longName LIKE CONCAT('%',r.longName,'%')),0) + IFNULL((i.typeFk = r.typeFk),0) as matches, i.typeFk, rl.previousSelected - FROM vn.recipe r + FROM vn.recipe r JOIN vn.item i ON (IFNULL(i.name LIKE CONCAT('%',r.name,'%'), 0) OR IFNULL(i.longName LIKE CONCAT('%',r.longName,'%'),0)) OR i.typeFk <=> r.typeFk JOIN cache.available a ON a.item_id = i.id AND a.calc_id = vCalc LEFT JOIN (SELECT recipe_ItemFk, element as log_element, selected_ItemFk, count(*) as previousSelected FROM vn.recipe_log - GROUP BY recipe_ItemFk, element, selected_ItemFk) rl ON rl.recipe_ItemFk = r.itemFk + GROUP BY recipe_ItemFk, element, selected_ItemFk) rl ON rl.recipe_ItemFk = r.itemFk AND rl.log_element = r.element AND rl.selected_ItemFk = i.id WHERE r.itemFk = vItemFk - AND a.available > vBunchesQuantity * r.quantity + AND a.available > vBunchesQuantity * r.quantity UNION ALL SELECT 100 itemFk, CONCAT('? ',r.element,' ',IFNULL(r.size,''),' ',IFNULL(r.inkFk,'')) as longName, @@ -66512,15 +63736,15 @@ BEGIN WHERE r.itemFk = vItemFk GROUP BY r.element ) sub - + ORDER BY element, matches DESC, previousSelected DESC; - - SELECT * + + SELECT * FROM tmp.recipeCook WHERE counter < 6 - OR itemFk = 100 + OR itemFk = 100 ; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -66545,79 +63769,30 @@ BEGIN DECLARE vShipped DATE; DECLARE vEntryFk INT; DECLARE vTravelFk INT; - + CALL cache.last_buy_refresh(FALSE); - - SELECT warehouseFk, shipped + + SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; UPDATE vn.ticket t JOIN vn.item i ON i.id = vItemFk SET t.nickname = CONCAT(vQuantity,' ',i.longName) WHERE t.id = vTicketFk; - + SELECT b.buyingValue INTO vLastCost FROM vn.buy b JOIN cache.last_buy lb ON lb.buy_id = b.id WHERE lb.item_id = vItemFk ORDER BY (lb.warehouse_id = vWarehouseFk) DESC LIMIT 1; - + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) SELECT vTicketFk, 98, - vQuantity, i.longName, vLastCost FROM vn.item i WHERE i.id = vItemFk; - /* - SELECT tr.id INTO vTravelFk - FROM vn.travel tr - JOIN vn.warehouse w ON w.id = tr.warehouseOutFk - WHERE tr.warehouseInFk = vWarehouseFk - AND tr.landed = vShipped - AND w.name = 'Confeccion'; - - IF IFNULL(vTravelFk,0) = 0 THEN - - INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyFk) - SELECT vShipped, vShipped, vWarehouseFk, w.id, am.id - FROM vn.warehouse w - JOIN vn.agencyMode am - WHERE w.name = 'Confeccion' - AND am.name = 'DIRECTO PROVEEDOR'; - - SET vTravelFk = LAST_INSERT_ID(); - - END IF; - - SELECT e.id INTO vEntryFk - FROM vn.entry e - JOIN vn.supplier s ON s.id = supplierFk - WHERE e.travelFk = vTravelFk - AND s.name = 'Confeccion Natural' - AND e.isRaid = FALSE; - - IF IFNULL(vEntryFk,0) = 0 THEN - - INSERT INTO vn.entry(supplierFk, evaNotes, travelFk, companyFk) - SELECT s.id, t.nickname, vTravelFk, c.id - FROM vn.supplier s - JOIN vn.ticket t ON t.id = vTicketFk - JOIN vn.company c ON c.code = 'VNL' - WHERE s.name = 'Confeccion Natural'; - - SET vEntryFk = LAST_INSERT_ID(); - - END IF; - - INSERT INTO vn.buy(entryFk, itemFk, quantity, buyingValue, packageFk, packing, grouping) - SELECT vEntryFk, b.itemFk, vQuantity, b.buyingValue, b.packageFk, b.packing, b.grouping - FROM cache.last_buy lb - JOIN vn.buy b ON b.id = lb.buy_id - WHERE lb.item_id = vItemFk - ORDER BY (lb.warehouse_id = vWarehouseFk) DESC - LIMIT 1; -*/ END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -66711,7 +63886,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `report_print`( ) BEGIN /** - * Inserts in the print queue the report to be printed and the necessary parameters for this + * Inserts in the print queue the report to be printed and the necessary parameters for this * one taking into account the paper size of both the printer and the report. * * @param vReportName the report to be printed. @@ -66754,11 +63929,11 @@ BEGIN END IF; IF vReportFk IS NULL THEN - CALL util.throw('reportNotExists'); + CALL util.throw('reportNotExists'); END IF; IF vReportSize <> vPrinteSize THEN - CALL util.throw('incorrectSize'); + CALL util.throw('incorrectSize'); END IF; START TRANSACTION; @@ -66767,7 +63942,7 @@ BEGIN priorityFk = vPriorityFk, reportFk = vReportFk, workerFk = vUserFk; - + SET vPrintQueueFk = LAST_INSERT_ID(); WHILE vI < vLength DO @@ -66800,16 +63975,16 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `riskAllClients`(maxRiskDate DATE) BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; CREATE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY SELECT id Id_Cliente, null grade FROM vn.client; - + CALL vn2008.risk_vs_client_list(maxRiskDate); - - SELECT + + SELECT c.RazonSocial, c.Id_Cliente, c.Credito, @@ -66821,7 +63996,7 @@ BEGIN JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente GROUP BY c.Id_cliente; - + DROP TEMPORARY TABLE IF EXISTS tmp.risk; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END ;; @@ -66880,25 +64055,25 @@ BEGIN DECLARE vM3 INT; DECLARE vKg INT; DECLARE vMatricula varchar(50); - + SELECT sum(packages) as bultos INTO vPackages - FROM vn.ticket t + FROM vn.ticket t WHERE routeFk = vRouteFk; - + SELECT SUM(sv.physicalVolume), SUM(sv.physicalWeight) INTO vM3, vKg FROM vn.saleVolume sv WHERE sv.routeFk = vRouteFk; - + SELECT v.numberPlate as matricula INTO vMatricula - FROM vn.route r + FROM vn.route r JOIN vn.vehicle v ON r.vehicleFk = v.id WHERE r.id = vRouteFk; - + SELECT vRouteFk as Ruta, - vPackages as Bultos, + vPackages as Bultos, vM3 as m3, vKg as Kg, vMatricula as Matricula; @@ -66963,7 +64138,7 @@ BEGIN ) sub ON sub.routeFk = rm.routeFk SET rm.ticketFree = sub.ticketFree; - UPDATE routesMonitor rm + UPDATE routesMonitor rm JOIN( SELECT t.routeFk, COUNT(*) AS ticketPacked FROM vn.ticket t @@ -67049,11 +64224,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeSetOk`( vRouteFk INT) BEGIN - + UPDATE vn.route r SET r.isOk = 1 WHERE r.id = vRouteFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67092,15 +64267,18 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `route_calcCommission`(vSelf INT) -proc: BEGIN +CREATE DEFINER=`root`@`localhost` PROCEDURE `route_calcCommission`( + vSelf INT +) +BEGIN /** - * Calcula las comisión para una ruta y guarda los valores en la tabla routeCommission + * Calcula las comisión para una ruta y guarda los valores + * en la tabla vn.routeCommission. * - * @param vSelf id de ruta + * @param vSelf Id de ruta */ - DECLARE vIsUpdatable BOOL; - DECLARE vIsFreelance BOOL; + DECLARE vIsUpdatable, vIsFreelance BOOL DEFAULT 0; + DECLARE vAgencyModePricePercentage DOUBLE; SELECT r.created >= rc.cutoffDated INTO vIsUpdatable FROM route r @@ -67116,6 +64294,13 @@ proc: BEGIN JOIN worker w ON w.id = r.workerFk WHERE r.id = vSelf; + SELECT ampp.percentage INTO vAgencyModePricePercentage + FROM route r + JOIN agencyMode am ON am.id = r.agencyModeFk + JOIN agencyModePricePercentage ampp ON ampp.agencyModeFk = am.id + WHERE r.id = vSelf; + + -- Falta calcular el precio, a la espera de saber el/los campo/s exacto/s al que aplicarlo/s IF vIsFreelance THEN INSERT INTO routeCommission ( routeFk, @@ -67125,13 +64310,17 @@ proc: BEGIN cat5m3 ) SELECT vSelf, - r.commissionWorkCenterFk, - rc.freelanceM3 * IF( - IFNULL(r.m3, 0) >= rc.freelanceMinM3, + r.commissionWorkCenterFk, + IF(vAgencyModePricePercentage IS NOT NULL, + vAgencyModePricePercentage / 100, + rc.freelanceM3 + ) * + IF(IFNULL(r.m3, 0) >= rc.freelanceMinM3, IFNULL(r.m3, 0), - 0), - rc.distributionCat4M3 * IFNULL(r.m3, 0), - rc.distributionCat5M3 * IFNULL(r.m3, 0) + 0 + ), + rc.distributionCat4M3 * IFNULL(r.m3, 0), + rc.distributionCat5M3 * IFNULL(r.m3, 0) FROM route r JOIN vehicle v ON v.id = r.vehicleFk JOIN routeConfig rc @@ -67150,15 +64339,15 @@ proc: BEGIN cat5m3 ) SELECT vSelf, - r.commissionWorkCenterFk, - (r.kmEnd - r.kmStart) * - IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), - IFNULL(r.m3, 0) * - IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), - (r.kmEnd - r.kmStart) * rc.kmYearly, - IFNULL(r.m3, 0) * rc.m3Yearly, - rc.distributionCat4M3 * IFNULL(r.m3, 0), - rc.distributionCat5M3 * IFNULL(r.m3, 0) + r.commissionWorkCenterFk, + (r.kmEnd - r.kmStart) * + IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), + IFNULL(r.m3, 0) * + IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), + (r.kmEnd - r.kmStart) * rc.kmYearly, + IFNULL(r.m3, 0) * rc.m3Yearly, + rc.distributionCat4M3 * IFNULL(r.m3, 0), + rc.distributionCat5M3 * IFNULL(r.m3, 0) FROM route r JOIN vehicle v ON v.id = r.vehicleFk JOIN routeConfig rc @@ -67177,40 +64366,6 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `route_checkDeliveryMethod` */; -/*!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 */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `route_checkDeliveryMethod`(vSelf INT) -BEGIN -/** -* Comprueba si el deliveryMethod del agencyMode de la ruta es reparto -* -* @param vSelf Id de ruta -*/ - DECLARE vDeliveryMethod VARCHAR(45); - - SELECT dm.code INTO vDeliveryMethod - FROM route r - JOIN agencyMode am ON am.id = r.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE r.id = vSelf; - - IF vDeliveryMethod <> 'DELIVERY' THEN - CALL util.throw('Route tickets via delivery only'); - 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_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `route_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67224,7 +64379,7 @@ proc: BEGIN /** * Recalculates modified route. */ - + DECLARE vDone BOOL; DECLARE vRouteFk INT; @@ -67233,7 +64388,7 @@ proc: BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN DO RELEASE_LOCK('vn.route_doRecalc'); @@ -67311,13 +64466,13 @@ SELECT t.id Id, t.cmrFk FROM ticket t JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id + JOIN address a ON t.addressFk = a.id LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk LEFT JOIN ( SELECT t.addressFk, MAX(d.ticketFk) lastTicketFk FROM ticket t JOIN delivery d ON t.id = d.ticketFk - JOIN ticket ti ON ti.routeFk = vRouteFk + JOIN ticket ti ON ti.routeFk = vRouteFk AND ti.id = t.id AND ti.clientFk = t.clientFk GROUP BY addressFk @@ -67394,27 +64549,27 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleBuy_Add`(vSaleFk INT, vBuyFk INT) BEGIN - + /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad - * + * * @param vSaleFk clave primaria de vn.sale * @param vBuyFk clave primaria de vn.buy */ - /*IF (SELECT COUNT(*) + /*IF (SELECT COUNT(*) FROM vn.sale s JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE s.id = vSaleFk AND ic.code = 'fruit') THEN */ - - IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN - + + IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN + INSERT INTO vn.saleBuy (saleFk, buyFk) VALUES(vSaleFk, vBuyFk); - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67438,7 +64593,7 @@ BEGIN * * @param vSectorFk Identificador de vn.sector */ - INSERT INTO vn.saleGroup(userFk, sectorFk) + INSERT INTO vn.saleGroup(userFk, sectorFk) VALUES (account.myUser_getId(), vSectorFk); SELECT LAST_INSERT_ID(); @@ -67572,41 +64727,41 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleSplit`(vSaleFk INT, vQuantity INT) BEGIN - + DECLARE vNewSaleFk INT; - - INSERT INTO vn.sale(itemFk, - concept, - price, - discount, - quantity, - ticketFk, + + INSERT INTO vn.sale(itemFk, + concept, + price, + discount, + quantity, + ticketFk, isPriceFixed) - SELECT s.itemFk, - i.longName, - s.price, - s.discount, + SELECT s.itemFk, + i.longName, + s.price, + s.discount, vQuantity, - s.ticketFk, - s.isPriceFixed + s.ticketFk, + s.isPriceFixed FROM vn.sale s JOIN vn.item i ON i.id = s.itemFk WHERE s.id = vSaleFk; - + UPDATE vn.sale s JOIN vn.item i ON i.id = s.itemFk SET s.quantity = s.quantity - vQuantity, s.concept = i.longName WHERE s.id = vSaleFk; - + SELECT LAST_INSERT_ID() INTO vNewSaleFk; - - INSERT INTO vn.saleComponent( saleFk, - componentFk, + + INSERT INTO vn.saleComponent( saleFk, + componentFk, value) - SELECT vNewSaleFk, - componentFk, + SELECT vNewSaleFk, + componentFk, value - FROM vn.saleComponent + FROM vn.saleComponent WHERE saleFk = vSaleFk; END ;; @@ -67626,41 +64781,41 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sales_merge`(vTicketFk INT) -BEGIN - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve - SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE s.ticketFk = vTicketFk - AND it.isMergeable - GROUP BY s.itemFk, s.price, s.discount; - - START TRANSACTION; - - UPDATE sale s - JOIN tSalesToPreserve stp ON stp.id = s.id - SET quantity = newQuantity - WHERE s.ticketFk = vTicketFk; - - DELETE s.* - FROM sale s - LEFT JOIN tSalesToPreserve stp ON stp.id = s.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE s.ticketFk = vTicketFk - AND stp.id IS NULL - AND it.isMergeable; - - COMMIT; - - DROP TEMPORARY TABLE tSalesToPreserve; +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve + SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE s.ticketFk = vTicketFk + AND it.isMergeable + GROUP BY s.itemFk, s.price, s.discount; + + START TRANSACTION; + + UPDATE sale s + JOIN tSalesToPreserve stp ON stp.id = s.id + SET quantity = newQuantity + WHERE s.ticketFk = vTicketFk; + + DELETE s.* + FROM sale s + LEFT JOIN tSalesToPreserve stp ON stp.id = s.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE s.ticketFk = vTicketFk + AND stp.id IS NULL + AND it.isMergeable; + + COMMIT; + + DROP TEMPORARY TABLE tSalesToPreserve; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67695,17 +64850,17 @@ BEGIN OPEN cCur; myLoop: LOOP - + SET vDone = FALSE; - + FETCH cCur INTO vTicketFk; IF vDone THEN LEAVE myLoop; END IF; - + CALL vn.sales_merge(vTicketFk); - + END LOOP; CLOSE cCur; @@ -67836,9 +64991,9 @@ BEGIN DELETE st.* FROM vn.saleTracking st JOIN vn.state s ON s.id = st.stateFk - WHERE st.saleFk = vSaleFk + WHERE st.saleFk = vSaleFk AND s.code = vState COLLATE utf8_unicode_ci; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67855,12 +65010,12 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_new`( - vSaleFK INT, - vIsChecked BOOLEAN, - vOriginalQuantity INT, - vWorkerFk INT, - vAction VARCHAR(50), +CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_new`( + vSaleFK INT, + vIsChecked BOOLEAN, + vOriginalQuantity INT, + vWorkerFk INT, + vAction VARCHAR(50), vState VARCHAR(50), vIsScanned BOOLEAN) BEGIN @@ -67876,12 +65031,12 @@ BEGIN * @param vIsScanned Identificador si se ha escaneado automáticamente o manual */ - REPLACE vn.saleTracking(saleFk, - isChecked, - originalQuantity, - workerFk, + REPLACE vn.saleTracking(saleFk, + isChecked, + originalQuantity, + workerFk, stateFk, - isScanned) + isScanned) SELECT vSaleFK, vIsChecked, vOriginalQuantity, @@ -67908,27 +65063,27 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_updateIsChecked`(vSaleFK INT, vIsChecked BOOL, vIsScanned BOOL) BEGIN - + /** * Actualiza el estado del campo vn.saleTracking.isChecked y elimina las lineas de vn.itemShelving * si procede, en el caso de las preparaciones previas, por usuario - * + * * @param vSaleFk Identificador de vn.sale * @param vIsChecked Estado del registro */ - + UPDATE vn.saleTracking st JOIN vn.state s ON s.id = st.stateFk AND s.code = 'PREVIOUS_PREPARATION' SET st.isChecked = vIsChecked, st.isScanned = vIsScanned WHERE st.saleFk = vSaleFK AND st.workerFk = account.myUser_getId(); - + IF vIsChecked = FALSE THEN - - DELETE FROM vn.itemShelvingSale + + DELETE FROM vn.itemShelvingSale WHERE saleFk = vSaleFK; - + END IF; END ;; @@ -67954,14 +65109,14 @@ proc: BEGIN * * @param vSelf Id de la venta * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - */ + */ CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales SELECT s.id FROM sale s WHERE s.id = vSelf; - + CALL sale_recalcComponent(vOption); - + DROP TEMPORARY TABLE tmp.recalculateSales; END ;; DELIMITER ; @@ -68008,7 +65163,7 @@ BEGIN GROUP BY s.id; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; + SET v_done = TRUE; DROP TEMPORARY TABLE IF EXISTS tmp.coste; @@ -68016,7 +65171,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.coste (PRIMARY KEY (id)) ENGINE = MEMORY SELECT s.id - FROM sale s + FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemType tp ON tp.id = i.typeFk JOIN itemCategory ic ON ic.id = tp.categoryFk @@ -68035,17 +65190,17 @@ BEGIN IF v_done THEN LEAVE l; END IF; - + SELECT ticketFk, concept INTO vTicketFk, vConcept FROM sale WHERE id = vSaleFk; - + CALL sale_calculateComponent(vSaleFk, 1); END LOOP; CLOSE vCur; - DROP TEMPORARY TABLE tmp.coste; + DROP TEMPORARY TABLE tmp.coste; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68054,6 +65209,75 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `sale_getBoxPickingList` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getBoxPickingList`(vSectorFk INT, vDated DATE) +BEGIN +/** +* Returns a suitable boxPicking sales list +* +* @param vSectorFk Identifier for vn.sector table +* @param vDated Date for vn.tickets.shipping +* +* @return tmp.sale +*/ + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM sector + WHERE id = vSectorFk; + + CALL productionControl(vWarehouseFk, 0); + + SELECT + s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + s.quantity / i.packingOut stickers, + i.packingOut + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemShelving ish ON ish.itemFk = s.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk + JOIN agencyMode am ON am.id = pb.agencyModeFk + LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = p.sectorFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk + WHERE s.quantity MOD i.packingOut = 0 + AND pb.problem = "" + AND s.quantity > 0 + AND sgd.saleFk IS NULL + AND p.sectorFk = vSectorFk + AND ts.isPreviousPreparable + AND iss.visible >= s.quantity + AND ((rm.bufferFk AND rm.isPickingAllowed) + OR am.name = 'REC_ALGEMESI') + AND pb.shipped = vDated + GROUP BY s.id + ORDER BY etd; + + DROP TEMPORARY TABLE tmp.productionBuffer; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_getFromTicketOrCollection` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68131,7 +65355,7 @@ DECLARE vIsCollection BOOL; TRIM(CONCAT(LPAD(s.concept,30,' '), ' ', RPAD(IFNULL(i.size,''),5,' '))) line1, '' cel1, - TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, + TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1), CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)), CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2, @@ -68148,12 +65372,12 @@ DECLARE vIsCollection BOOL; JOIN sale s ON s.ticketFk = t.id JOIN ticket tt ON tt.id = t.id LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN buy b ON b.id = lb.buy_id JOIN item i ON i.id = s.itemFk LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id LEFT JOIN collection c ON c.id = tc.collectionFk - LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity - FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity + LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity + FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity FROM tmp.ticket2 t JOIN sale s ON s.ticketFk = t.id JOIN saleTracking st ON st.saleFk = s.id @@ -68165,7 +65389,7 @@ DECLARE vIsCollection BOOL; LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN parking p ON p.id = sg.parkingFk LEFT JOIN saleMistake sm ON sm.saleFk = s.id @@ -68217,8 +65441,8 @@ BEGIN DELETE tt.* FROM tmp.sale_getProblems tt JOIN ticketObservation tto ON tto.ticketFk = tt.ticketFk - JOIN observationType ot ON ot.id = tto.observationTypeFk - WHERE ot.code = 'administrative' + JOIN observationType ot ON ot.id = tto.observationTypeFk + WHERE ot.code = 'administrative' AND tto.description = 'Miriam'; CREATE OR REPLACE TEMPORARY TABLE tmp.sale_problems ( @@ -68250,7 +65474,7 @@ BEGIN -- Too Little INSERT INTO tmp.sale_problems(ticketFk, isTooLittle) - SELECT tp.ticketFk, TRUE + SELECT tp.ticketFk, TRUE FROM tmp.sale_getProblems tp JOIN ticket t ON t.id = tp.ticketFk JOIN ( @@ -68327,6 +65551,19 @@ BEGIN WHERE tr.isOK IS NULL ON DUPLICATE KEY UPDATE hasTicketRequest = TRUE; + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk; + -- Disponible, Faltas, Inventario y Retrasos OPEN vCursor; l: LOOP @@ -68339,25 +65576,28 @@ BEGIN -- Disponible: no va a haber suficiente producto para preparar todos los pedidos CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); - - -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida + + -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, - LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem, + SELECT tl.ticketFk, + LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem, s.id AS saleFk FROM tmp.ticket_list tl JOIN ticket t ON t.id = tl.ticketFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) < s.quantity AND IFNULL(av.available ,0) < s.quantity AND IFNULL(issw.visible, 0) < s.quantity @@ -68370,20 +65610,24 @@ BEGIN AND t.warehouseFk = vWarehouseFk GROUP BY tl.ticketFk) sub ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk; - + -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, LEFT(GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' '),250) problem, s.id AS saleFk + SELECT tl.ticketFk, + LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem, + s.id saleFk FROM tmp.ticket_list tl JOIN ticket t ON t.id = tl.ticketFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity AND s.quantity > 0 @@ -68397,21 +65641,26 @@ BEGIN GROUP BY tl.ticketFk ) sub ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; - + -- Retraso: Disponible suficiente, pero no visible ni ubicado INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, LEFT(GROUP_CONCAT('R: ',i.id, ' ', i.longName, ' '),250) problem, s.id AS saleFk + SELECT tl.ticketFk, + LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem, + s.id saleFk FROM tmp.ticket_list tl JOIN ticket t ON t.id = tl.ticketFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible, 0) < s.quantity AND IFNULL(av.available, 0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity @@ -68432,12 +65681,12 @@ BEGIN INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, + SELECT tl.ticketFk, s.id saleFk , - LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,''), ' '), 250) problem, + LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,''), ' '), 250) problem, MOD(s.quantity, b.`grouping`) hasRounding FROM tmp.ticket_list tl - JOIN ticket t ON t.id = tl.ticketFk + JOIN ticket t ON t.id = tl.ticketFk AND t.warehouseFk = vWarehouseFk JOIN sale s ON s.ticketFk = tl.ticketFk JOIN item i ON i.id = s.itemFk @@ -68445,11 +65694,11 @@ BEGIN JOIN buy b ON b.id = bu.buyFk GROUP BY tl.ticketFk HAVING hasRounding - ) sub + ) sub ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk; END LOOP; CLOSE vCursor; - + INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked) SELECT DISTINCT tl.ticketFk, FALSE FROM tmp.ticket_list tl @@ -68459,7 +65708,8 @@ BEGIN DROP TEMPORARY TABLE tmp.clientGetDebt, - tmp.ticket_list; + tmp.ticket_list, + tItemShelvingStock_byWarehouse; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68479,16 +65729,16 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getProblemsByTicket`(IN vTicketFk INT, IN vIsTodayRelative TINYINT(1)) BEGIN /** - * Calcula los problemas de cada venta + * Calcula los problemas de cada venta * para un conjunto de tickets. * * @return Problems result */ DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems; - CREATE TEMPORARY TABLE tmp.sale_getProblems + CREATE TEMPORARY TABLE tmp.sale_getProblems (INDEX (ticketFk)) ENGINE = MEMORY - SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped + SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped FROM ticket t WHERE t.id = vTicketFk; @@ -68517,7 +65767,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_PriceFix`(vTicketFk INT) BEGIN - + DELETE sc.* FROM vn.saleComponent sc JOIN vn.sale s ON s.id = sc.saleFk @@ -68553,52 +65803,52 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_recalcComponent`(vOption INT) proc: BEGIN /** - * Este procedimiento recalcula los componentes de un conjunto de sales, + * Este procedimiento recalcula los componentes de un conjunto de sales, * eliminando los componentes existentes e insertandolos de nuevo * * @param vOption si no se quiere forzar llamar con NULL * @table tmp.recalculateSales (id) - */ - DECLARE vShipped DATE; + */ + DECLARE vShipped DATE; DECLARE vWarehouseFk SMALLINT; DECLARE vAgencyModeFk INT; DECLARE vAddressFk INT; DECLARE vTicketFk INT; - DECLARE vLanded DATE; + DECLARE vLanded DATE; DECLARE vIsEditable BOOLEAN; DECLARE vZoneFk INTEGER; DECLARE vDone BOOL DEFAULT FALSE; - + DECLARE vCur CURSOR FOR SELECT DISTINCT s.ticketFk FROM tmp.recalculateSales rs JOIN vn.sale s ON s.id = rs.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + OPEN vCur; l: LOOP SET vDone = FALSE; - FETCH vCur INTO vTicketFk; - + FETCH vCur INTO vTicketFk; + IF vDone THEN LEAVE l; END IF; - SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, - t.zoneFk, - t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, + SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, + t.zoneFk, + t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, t.landed - INTO vIsEditable, - vZoneFk, - vWarehouseFk, - vShipped, - vAddressFk, - vAgencyModeFk, + INTO vIsEditable, + vZoneFk, + vWarehouseFk, + vShipped, + vAddressFk, + vAgencyModeFk, vLanded FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket @@ -68606,31 +65856,31 @@ proc: BEGIN WHERE t.id = vTicketFk; CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - + IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); END IF; - + IF vLanded IS NULL OR vZoneFk IS NULL THEN - + UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) WHERE t.id = vTicketFk AND t.landed IS NULL; - + IF vZoneFk IS NULL THEN SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; UPDATE ticket t SET t.zoneFk = vZoneFk WHERE t.id = vTicketFk AND t.zoneFk IS NULL; END IF; - + END IF; - + DROP TEMPORARY TABLE tmp.zoneGetLanded; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + CREATE OR REPLACE TEMPORARY TABLE tmp.sale (PRIMARY KEY (saleFk)) ENGINE = MEMORY SELECT s.id saleFk, vWarehouseFk warehouseFk @@ -68638,7 +65888,7 @@ proc: BEGIN JOIN tmp.recalculateSales rs ON s.id = rs.id WHERE s.ticketFk = vTicketFk; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk FROM sale s JOIN tmp.recalculateSales rs ON s.id = rs.id @@ -68652,15 +65902,15 @@ proc: BEGIN IF vOption IS NULL THEN SET vOption = IF(vIsEditable, 1, 6); END IF; - - CALL ticketComponentUpdateSale(vOption); + + CALL ticketComponentUpdateSale(vOption); CALL catalog_componentPurge(); - + DROP TEMPORARY TABLE tmp.buyUltimate; DROP TEMPORARY TABLE tmp.sale; - + END LOOP; - CLOSE vCur; + CLOSE vCur; END ;; DELIMITER ; @@ -68681,22 +65931,22 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollectionSaleGroup_add`(vSaleGroupFk INT, vSectorCollectionFk INT) BEGIN /** - * Inserta un nuevo registro en vn.sectorCollectionSaleGroup + * Inserta un nuevo registro en vn.sectorCollectionSaleGroup * Actualiza el usuario en vn.saleGroup y reemplaza los registros de vn.saleTracking - * + * * @param vSaleGroupFk Identificador de vn.saleGroup * @param vSectorCollectionFk Identificador de vn.sectorCollection */ REPLACE sectorCollectionSaleGroup - SET sectorCollectionFk = vSectorCollectionFk, + SET sectorCollectionFk = vSectorCollectionFk, saleGroupFk = vSaleGroupFk; - + UPDATE saleGroup sg JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk - SET sg.userFk = sc.userFk + SET sg.userFk = sc.userFk WHERE sg.id = vSaleGroupFk; - + INSERT IGNORE saleTracking( saleFk, isChecked, @@ -68708,8 +65958,8 @@ BEGIN sc.userFk, s.id FROM saleGroupDetail sgd - JOIN sectorCollectionSaleGroup scsg - ON scsg.saleGroupFk = sgd.saleGroupFk + JOIN sectorCollectionSaleGroup scsg + ON scsg.saleGroupFk = sgd.saleGroupFk JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk JOIN state s ON s.code = 'PREVIOUS_PREPARATION' WHERE sgd.saleGroupFk = vSaleGroupFk; @@ -68810,30 +66060,30 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_new`(vSectorFk INT) -BEGIN -/** - * Inserta una nueva colección, si el usuario no tiene ninguna vacia. - * Esto se hace para evitar que por error se generen colecciones sin sentido. - * - * @param vSectorFk Identificador de #vn.sector - */ - DECLARE hasEmptyCollections BOOL; - DECLARE vUserFk INT; - - SET vUserFk = account.myUser_getId(); - - SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections - FROM vn.sectorCollection sc - LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - WHERE ISNULL(scsg.id) - AND sc.userFk = vUserFk - AND sc.sectorFk = vSectorFk - AND sc.created >= util.VN_CURDATE(); - - IF NOT hasEmptyCollections THEN - INSERT INTO vn.sectorCollection(userFk, sectorFk) - VALUES(vUserFk, vSectorFk); - END IF; +BEGIN +/** + * Inserta una nueva colección, si el usuario no tiene ninguna vacia. + * Esto se hace para evitar que por error se generen colecciones sin sentido. + * + * @param vSectorFk Identificador de #vn.sector + */ + DECLARE hasEmptyCollections BOOL; + DECLARE vUserFk INT; + + SET vUserFk = account.myUser_getId(); + + SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections + FROM vn.sectorCollection sc + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + WHERE ISNULL(scsg.id) + AND sc.userFk = vUserFk + AND sc.sectorFk = vSectorFk + AND sc.created >= util.VN_CURDATE(); + + IF NOT hasEmptyCollections THEN + INSERT INTO vn.sectorCollection(userFk, sectorFk) + VALUES(vUserFk, vSectorFk); + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68877,7 +66127,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.previousErrors -- Errores de previa, derivadores de los revisadores (por reclamación) ENGINE = MEMORY - SELECT tt.workerFk, COUNT(c.ticketFk) errorsByClaim + SELECT tt.userFk, COUNT(c.ticketFk) errorsByClaim FROM claimDevelopment cd JOIN claim c ON cd.claimFk = c.id JOIN ticket t ON c.ticketFk = t.id @@ -68885,7 +66135,7 @@ BEGIN JOIN ticketTracking tt ON tt.ticketFk = t.id JOIN `state` s ON s.id = tt.stateFk WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.description = 'Revisadores' AND s.code = 'OK PREVIOUS' - GROUP BY workerFk; + GROUP BY cd.workerFk; DELETE FROM sectorProductivity WHERE dated = vDatedFrom @@ -68913,7 +66163,7 @@ BEGIN LEFT JOIN bs.workerProductivity wp ON wp.workerFk = w.id LEFT JOIN `state` s2 ON s2.id = wp.stateFk AND s2.code = 'OK PREVIOUS' LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = w.id - LEFT JOIN tmp.previousErrors pe ON pe.workerFk = w.id + LEFT JOIN tmp.previousErrors pe ON pe.userFk = w.id WHERE DATE(sc.created) = vDatedFrom AND wp.dated = vDatedFrom GROUP BY w.id; @@ -68969,7 +66219,7 @@ BEGIN SELECT s.warehouseFk FROM vn.sector s WHERE s.id = vSectorFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69064,10 +66314,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingChange`(IN `vShelvingO` VAR BEGIN UPDATE vn.itemShelving - SET shelvingFk = vShelvingD COLLATE utf8_unicode_ci - WHERE shelvingFk = vShelvingO COLLATE utf8_unicode_ci; - - + SET shelvingFk = vShelvingD COLLATE utf8_unicode_ci + WHERE shelvingFk = vShelvingO COLLATE utf8_unicode_ci; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69086,16 +66336,16 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingLog_get`(shelvingFk VARCHAR(10)) BEGIN - + /* Lista el log de un carro - * + * * @param shelvingFk matrícula del carro - * + * */ - + SELECT originFk, name, creationDate, description FROM shelvingLog sl - JOIN account.user u ON u.id = sl.userFk + JOIN account.user u ON u.id = sl.userFk WHERE sl.originFk = shelvingFk COLLATE utf8_general_ci ORDER BY creationDate DESC; @@ -69118,22 +66368,22 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingParking_get`(vShelvingFk VARCHAR(10), vWarehouseFk INT, vDayRange INT) BEGIN - -SELECT s.itemFk, + +SELECT s.itemFk, s.concept, - CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir, - CAST(IFNULL(ist.visible,0) AS DECIMAL(10,0)) as aparcado + CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir, + CAST(IFNULL(ist.visible,0) AS DECIMAL(10,0)) as aparcado FROM vn.sale s LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk AND ist.warehouseFk = vWarehouseFk JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk AND ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) AND iss.saleFk IS NULL AND t.warehouseFk = vWarehouseFk GROUP BY s.itemFk HAVING sinServir > aparcado; - + END ;; DELIMITER ; @@ -69178,12 +66428,12 @@ BEGIN DELETE FROM shelving WHERE length(code) > 3 AND parked < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - + DELETE FROM itemShelving WHERE visible <= 0 AND created < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); - DELETE ish.* + DELETE ish.* FROM itemShelving ish JOIN vn.shelving sh ON sh.code = ish.shelvingFk WHERE sh.parkingFk IS NULL @@ -69379,20 +66629,20 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `solunionRiskRequest`() BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; CREATE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY - SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc + SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification WHERE dateEnd IS NULL ORDER BY ci.creationDate DESC LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; - + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); - - SELECT + + SELECT c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, f.Consumo consumo_anual, c.Vencimiento, ci.grade @@ -69402,7 +66652,7 @@ BEGIN JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente GROUP BY Id_cliente; - + DROP TEMPORARY TABLE IF EXISTS tmp.risk; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END ;; @@ -69652,10 +66902,10 @@ BEGIN DECLARE vBossId INT; DECLARE vDone BOOL; DECLARE workerCur CURSOR FOR - SELECT workerFk - FROM tmp.subordinate + SELECT workerFk + FROM tmp.subordinate WHERE NOT isChecked; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR 1062 BEGIN @@ -69663,29 +66913,29 @@ BEGIN END; DROP TEMPORARY TABLE IF EXISTS tmp.subordinate; - + CREATE TEMPORARY TABLE tmp.subordinate (PRIMARY KEY (workerFk)) ENGINE = MEMORY SELECT vBossFk AS workerFk, 0 AS isChecked; - + WHILE (SELECT COUNT(*) FROM tmp.subordinate WHERE NOT isChecked) > 0 DO OPEN workerCur; workerLoop: LOOP SET vDone = FALSE; FETCH workerCur INTO vBossId; - + IF vDone THEN LEAVE workerLoop; END IF; - - INSERT INTO tmp.subordinate - SELECT id, 0 - FROM worker + + INSERT INTO tmp.subordinate + SELECT id, 0 + FROM worker WHERE bossFk = vBossId; - - UPDATE tmp.subordinate + + UPDATE tmp.subordinate SET isChecked = 1 WHERE workerFk = vBossId; END LOOP; @@ -69725,13 +66975,13 @@ BEGIN -- Calcula el balance inicial y final de cada proveedor INSERT INTO openingBalance SELECT MAX(dueDated), - supplierFk, - companyFk, + supplierFk, + companyFk, sum(amount) eurAmount, sum(divisa) foreignAmount FROM ( SELECT p.dueDated, - p.supplierFk, + p.supplierFk, p.companyFk, p.amount, p.divisa @@ -69747,7 +66997,7 @@ BEGIN SELECT iidd.dueDated, ii.supplierFk, ii.companyFk, - - iidd.amount, + - iidd.amount, - iidd.foreignValue FROM invoiceIn ii JOIN invoiceInDueDay iidd ON ii.id = iidd.invoiceInFk @@ -69755,14 +67005,14 @@ BEGIN JOIN company co ON co.id = ii.companyFk WHERE iidd.dueDated > '2014-12-31' AND iidd.dueDated <= vEnded - AND ii.isBooked AND co.`code` = 'VNL' + AND ii.isBooked AND co.`code` = 'VNL' AND c.`code` <> 'EUR' UNION ALL SELECT se.dueDated, se.supplierFk, se.companyFk, - - se.amount, + - se.amount, 0 FROM supplierExpense se JOIN currency c ON c.id = se.currencyFk @@ -69772,7 +67022,7 @@ BEGIN AND co.`code` = 'VNL' AND c.`code` <> 'EUR' ) sub GROUP BY companyFk, supplierFk; - + SELECT ob.dueDated , ob.supplierFk , ob.companyFk @@ -69930,7 +67180,7 @@ BEGIN - SUM(iid.amount) mysql, 0 sage FROM invoiceInDueDay iid - JOIN invoiceIn ii ON ii.id = iid.invoiceInFk + JOIN invoiceIn ii ON ii.id = iid.invoiceInFk WHERE IFNULL(ii.bookEntried, ii.issued) BETWEEN vDateFrom AND vDateTo AND ii.isBooked GROUP BY ii.id @@ -70025,8 +67275,8 @@ BEGIN JOIN ( SELECT p.supplierFk FROM supplier s JOIN payMethod pm ON pm.id = s.payMethodFk - JOIN (SELECT supplierFk,MAX(created) created - FROM payment + JOIN (SELECT supplierFk,MAX(created) created + FROM payment GROUP BY supplierFk) p ON p.supplierFk = s.id WHERE p.created < (util.VN_CURDATE() - INTERVAL pm.graceMonthsDisableChecked MONTH) AND pm.graceMonthsDisableChecked @@ -70071,15 +67321,15 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketBoxesView`(IN vTicketFk INT) BEGIN - - SELECT s.id, - s.itemFk, - s.concept, - floor(s.quantity / b.packing) as Cajas, - b.packing, - s.isPicked, + + SELECT s.id, + s.itemFk, + s.concept, + floor(s.quantity / b.packing) as Cajas, + b.packing, + s.isPicked, i.size - FROM ticket t + FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN cache.last_buy lb on lb.warehouse_id = t.warehouseFk AND lb.item_id = s.itemFk @@ -70090,7 +67340,7 @@ BEGIN AND p.isBox GROUP BY s.itemFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70112,7 +67362,7 @@ BEGIN DECLARE vDateStart DATETIME DEFAULT DATE(vDate); DECLARE vDateEnd DATETIME DEFAULT util.dayEnd(vDate); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketBuiltTime; CREATE TEMPORARY TABLE tmp.ticketBuiltTime @@ -70125,7 +67375,7 @@ BEGIN SELECT ticketFk, builtTime FROM ( - SELECT + SELECT ticketFk, created as builtTime FROM @@ -70133,13 +67383,13 @@ BEGIN WHERE created BETWEEN vDateStart AND vDateEnd ORDER BY ticketFk, created DESC LIMIT 10000000000000000000 - ) sub + ) sub GROUP BY ticketFk ) sub2 ON sub2.ticketFk = t.id WHERE t.shipped BETWEEN vDate AND util.dayEnd(vDate) AND t.clientFk NOT IN (50,400,200) AND t.companyFk = 442 - + ; END ;; @@ -70168,30 +67418,30 @@ BEGIN */ REPLACE INTO orderTicket(orderFk,ticketFk) - SELECT orderFk, vTicketNew - FROM orderTicket + SELECT orderFk, vTicketNew + FROM orderTicket WHERE ticketFk = vTicketOld; - + -- Bionizamos lineas con Preu = 0 CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id + SELECT id FROM sale WHERE ticketFk = vTicketNew AND price = 0; - + CALL sale_recalcComponent(1); -- Bionizamos lineas con Preu > 0 CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id + SELECT id FROM sale WHERE ticketFk = vTicketNew AND price > 0; - + CALL sale_recalcComponent(6); DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70214,12 +67464,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateFromType`( vLanded D vTypeFk INT) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (INDEX (itemFk)) - ENGINE = MEMORY + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY SELECT id itemFk FROM vn.item WHERE typeFk = vTypeFk; - + CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.ticketLot; @@ -70241,7 +67491,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculatePurge`() BEGIN - DROP TEMPORARY TABLE + DROP TEMPORARY TABLE tmp.ticketCalculateItem, tmp.ticketComponentPrice, tmp.ticketComponent, @@ -70265,56 +67515,56 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClon`(vTicketFk INT, vNewShipped DATE) BEGIN - + DECLARE done INT DEFAULT FALSE; - DECLARE vNewTicketFk INT; + DECLARE vNewTicketFk INT; DECLARE vOldSaleFk INT; DECLARE vNewSaleFk INT; - + DECLARE cur1 CURSOR FOR SELECT id FROM vn.sale WHERE ticketFk = vTicketFk; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - + SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); - + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); - - UPDATE vn.ticket + + UPDATE vn.ticket SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed), shipped = vNewShipped WHERE id = vNewTicketFk; - + OPEN cur1; - + read_loop: LOOP - + FETCH cur1 INTO vOldSaleFk; - + IF done THEN LEAVE read_loop; END IF; - + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed) SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed FROM vn.sale WHERE id = vOldSaleFk; - + SELECT max(id) INTO vNewSaleFk FROM vn.sale WHERE ticketFk = vNewTicketFk; - + INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge) SELECT vNewSaleFk, componentFk, value, isGreuge FROM vn.saleComponent WHERE saleFk = vOldSaleFk; - + END LOOP; CLOSE cur1; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70336,18 +67586,18 @@ BEGIN DECLARE vShipped DATE; DECLARE vMaxDated DATE; - - SELECT shipped, TIMESTAMPADD(YEAR,1,shipped) + + SELECT shipped, TIMESTAMPADD(YEAR,1,shipped) INTO vShipped, vMaxDated FROM vn.ticket WHERE id = vTicketFk; - + WHILE vShipped <= vMaxDated DO - + SET vShipped = TIMESTAMPADD(WEEK, 1, vShipped); - + CALL vn.ticketClon(vTicketFk, vShipped); - + END WHILE; END ;; @@ -70369,10 +67619,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_get`(vTicketFk INT) BEGIN - SELECT tc.collectionFk + SELECT tc.collectionFk FROM vn.ticketCollection tc WHERE ticketFk = vTicketFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70391,18 +67641,18 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_setUsedShelves`(vTicketFk INT, vUsedShelves INT) BEGIN - + /* * Inserta número de baldas que ocupa un ticket - * + * * @param vTicketFk Identificador de ticket * @param vUsedShelves Número de baldas */ - + UPDATE ticketCollection tc SET tc.usedShelves = vUsedShelves WHERE tc.ticketFk = vTicketFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70440,18 +67690,18 @@ BEGIN END; START TRANSACTION; - + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t + + UPDATE ticket t JOIN address a ON a.id = vAddressFk SET t.nickname = a.nickname WHERE t.id = vTicketFk; - + END IF; - + UPDATE ticket t - SET + SET t.clientFk = vClientFk, t.agencyModeFk = vAgencyModeFk, t.addressFk = vAddressFk, @@ -70462,12 +67712,12 @@ BEGIN t.isDeleted = vIsDeleted WHERE t.id = vTicketFk; - + IF vHasToBeUnrouted THEN UPDATE ticket t SET t.routeFk = NULL WHERE t.id = vTicketFk; END IF; - + IF vOption <> 8 THEN DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale @@ -70509,104 +67759,104 @@ BEGIN DECLARE vComponentFk INT; DECLARE vRenewComponents BOOLEAN; DECLARE vKeepPrices BOOLEAN; - + CASE vOption - WHEN 1 THEN + WHEN 1 THEN SET vRenewComponents = TRUE; SET vKeepPrices = FALSE; WHEN 2 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'debtCollection'; + SELECT id INTO vComponentFk FROM component WHERE `code` = 'debtCollection'; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; - WHEN 3 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'mana'; + WHEN 3 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'mana'; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 4 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'buyerDiscount'; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; - WHEN 4 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'buyerDiscount'; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - /* WHEN 5 THEN + /* WHEN 5 THEN SET vComponentFk = 35; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE;*/ - WHEN 6 THEN + WHEN 6 THEN SELECT id INTO vComponentFk FROM component WHERE `code` = 'imbalance'; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; WHEN 7 THEN REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk NOT IN (28, 29) GROUP BY s.id; - + REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) + SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk NOT IN (28, 29) GROUP BY s.id; - + SET vRenewComponents = FALSE; SET vKeepPrices = FALSE; WHEN 8 THEN - DELETE sc.* + DELETE sc.* FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; - + REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id; - + SET vRenewComponents = FALSE; SET vKeepPrices = FALSE; - WHEN 9 THEN + WHEN 9 THEN SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; END CASE; IF vRenewComponents THEN - DELETE sc.* - FROM tmp.sale tmps + DELETE sc.* + FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk JOIN `component` c ON c.id = sc.componentFk WHERE c.isRenewable; - + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT s.id, tc.componentFk, tc.cost - FROM sale s + FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); - - -- Añadir componente venta por paquete + + -- Añadir componente venta por paquete DROP TEMPORARY TABLE IF EXISTS tmp.sale2; CREATE TEMPORARY TABLE tmp.sale2 (PRIMARY KEY (saleFk)) - ENGINE = MEMORY + ENGINE = MEMORY SELECT * FROM tmp.sale; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent2; CREATE TEMPORARY TABLE tmp.ticketComponent2 - SELECT * FROM tmp.ticketComponent; - - REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT * FROM tmp.ticketComponent; + + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT t.id, t.componentFk, t.cost FROM ( SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto FROM vn.sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id JOIN vn.buy b ON b.id = buy_id JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' LEFT JOIN ( SELECT s.id FROM vn.sale s @@ -70617,8 +67867,8 @@ BEGIN ) tp ON tp.id = s.id WHERE tp.id IS NULL HAVING resto <> 0) t; - - DROP TEMPORARY TABLE IF EXISTS + + DROP TEMPORARY TABLE IF EXISTS tmp.sale2, tmp.ticketComponent2; END IF; @@ -70636,26 +67886,26 @@ BEGIN UPDATE sale s JOIN item i on i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk GROUP BY sc.saleFk) sc ON sc.saleFk = s.id SET s.price = sumValue / ((100 - s.discount) / 100) - WHERE it.code != 'PRT' ; - + WHERE it.code != 'PRT' ; + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id WHERE sc.componentFk != 21 - GROUP BY s.id + GROUP BY s.id HAVING ROUND(saleValue, 4) <> 0; END IF; - + UPDATE sale s JOIN ( - SELECT SUM(sc.value) sumValue, sc.saleFk + SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk JOIN `component` c ON c.id = sc.componentFk @@ -70669,10 +67919,10 @@ BEGIN JOIN sale s on s.id = sc.saleFk JOIN item i ON i.id = s.itemFk JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT'; - + WHERE it.code = 'PRT'; + INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 15, s.price + SELECT s.id, 15, s.price FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id JOIN item i ON i.id = s.itemFK @@ -70739,24 +67989,24 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticket ENGINE = MEMORY SELECT vTicketFk ticketFk; - + CALL vn.ticket_getTax(NULL); - SELECT + SELECT tt.ticketFk, CAST(tt.taxableBase AS DECIMAL(10, 2)) AS taxableBase, CAST(tt.rate * tt.taxableBase / 100 AS DECIMAL(10, 2)) AS tax, - pgc.*, + pgc.*, CAST(IF(pe.equFk IS NULL, taxableBase, 0) AS DECIMAL(10, 2)) AS Base, pgc.rate / 100 as vatPercent FROM tmp.ticketTax tt JOIN vn.pgc ON pgc.code = tt.pgcFk LEFT JOIN vn.pgcEqu pe ON pe.equFk = pgc.code; - + DROP TEMPORARY TABLE tmp.ticket; DROP TEMPORARY TABLE tmp.ticketTax; DROP TEMPORARY TABLE tmp.ticketAmount; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70794,29 +68044,29 @@ BEGIN JOIN ticket t ON t.id = tmpTicket.ticketFk; CALL addressTaxArea (); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; CREATE TEMPORARY TABLE tmp.ticketTax (INDEX (ticketFk)) ENGINE = MEMORY SELECT tmpTicket.ticketFk, bp.pgcFk, - SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) + SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) ) AS taxableBase, SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) ) * pgc.rate / 100 AS tax, tc.code - + FROM tmp.ticket tmpTicket JOIN sale s ON s.ticketFk = tmpTicket.ticketFk JOIN item i ON i.id = s.itemFk JOIN ticket t ON t.id = tmpTicket.ticketFk JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata + JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN itemTaxCountry itc + JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - JOIN bookingPlanner bp + JOIN bookingPlanner bp ON bp.countryFk = su.countryFk AND bp.taxAreaFk = ata.areaFk AND bp.taxClassFk = itc.taxClassFk @@ -70824,7 +68074,7 @@ BEGIN JOIN taxClass tc ON tc.id = bp.taxClassFk GROUP BY tmpTicket.ticketFk, pgc.code HAVING taxableBase != 0; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; CREATE TEMPORARY TABLE tmp.ticketAmount (INDEX (ticketFk)) @@ -70835,7 +68085,7 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70856,7 +68106,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTotal`(vTaxArea VARCHAR(25 BEGIN /** * Calcula el total con IVA para un conjunto de tickets. - * + * * @param vTaxArea * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular * @return tmp.ticketTotal Total para cada ticket @@ -70873,7 +68123,7 @@ BEGIN FROM tmp.ticket t LEFT JOIN tmp.ticketAmount ta ON t.ticketFk = ta.ticketFk GROUP BY ticketFk; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; END ;; @@ -70945,18 +68195,18 @@ BEGIN DECLARE vParked DATETIME; DECLARE vLevel INT; DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) + + SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) INTO vLevel, vCollectionFk FROM vn.ticketCollection WHERE ticketFk = vTicketFk LIMIT 1; - - SELECT created, parkingFk + + SELECT created, parkingFk INTO vParked, vParkingFk FROM vn.ticketParking WHERE ticketFk = vTicketFk; - + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp JOIN vn.parking p ON p.id = tp.parkingFk @@ -70983,7 +68233,7 @@ BEGIN AND sc.isPackagingArea AND tp.created < vParked AND t.packages <=> 0); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71004,7 +68254,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketNotInvoicedByClient`(vClientF BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - + CREATE TEMPORARY TABLE tmp.ticket SELECT id ticketFk FROM ticket @@ -71014,7 +68264,7 @@ BEGIN CALL vn.ticketGetTotal(NULL); - SELECT c.id, + SELECT c.id, c.name as Cliente, t.shipped as Fecha, t.id as Id_Ticket, @@ -71025,7 +68275,7 @@ BEGIN DROP TEMPORARY TABLE tmp.ticket, - tmp.ticketTotal; + tmp.ticketTotal; END ;; DELIMITER ; @@ -71045,21 +68295,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketObservation_addNewBorn`(vTicketFk INT) BEGIN - + /** * Inserta observaciones para los tickets con clientes nuevos o recuperados - * + * * @param vTicketFk Identificador de vn.ticket */ - + DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! '; INSERT INTO vn.ticketObservation(ticketFk, observationTypeFk, description) SELECT vTicketFk, ot.id, vDescription FROM vn.observationType ot WHERE ot.hasNewBornMessage - ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description); - + ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71099,7 +68349,7 @@ BEGIN DECLARE vComponentCost INT; DECLARE vDone INT DEFAULT FALSE; DECLARE vClientId INT; - + DECLARE vCursor CURSOR FOR SELECT DISTINCT clientFk FROM ( @@ -71116,31 +68366,31 @@ BEGIN RESIGNAL; END; - SELECT id INTO vWarehouseInventory - FROM warehouse + SELECT id INTO vWarehouseInventory + FROM warehouse WHERE `code`= 'inv'; - - SELECT id INTO vComponentCost - FROM component + + SELECT id INTO vComponentCost + FROM component WHERE `code`= 'purchaseValue'; - - SELECT packagingInvoicingDated INTO vDateStart - FROM ticketConfig; - + + SELECT packagingInvoicingDated INTO vDateStart + FROM ticketConfig; + IF vWarehouseInventory IS NULL THEN CALL util.throw('Warehouse inventory not set'); END IF; IF vComponentCost IS NULL THEN CALL util.throw('Component cost not set'); - END IF; + END IF; SET vDateEnd = vDated + INTERVAL 1 DAY; - + IF NOT vWithoutPeriodGrace THEN SET vGraceDate = vGraceDate -INTERVAL 1 MONTH; END IF; - + DROP TEMPORARY TABLE IF EXISTS tmp.packagingToInvoice; CREATE TEMPORARY TABLE tmp.packagingToInvoice (INDEX (clientFk)) @@ -71153,7 +68403,7 @@ BEGIN t.clientFk FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk - JOIN ticket t ON t.id = tp.ticketFk + JOIN ticket t ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk WHERE c.isActive AND (vClientFk IS NULL OR t.clientFk = vClientFk) @@ -71161,7 +68411,7 @@ BEGIN AND (tp.quantity < 0 OR (tp.quantity > 0 AND t.shipped < vGraceDate)) AND tp.quantity AND p.itemFk; - + OPEN vCursor; l: LOOP @@ -71174,25 +68424,25 @@ BEGIN START TRANSACTION; CALL ticket_add( - vClientId, + vClientId, vDateEnd, - vWarehouseInventory, - vCompanyFk, - NULL, - NULL, - NULL, - vDateEnd, - account.myUser_getId(), + vWarehouseInventory, + vCompanyFk, + NULL, + NULL, + NULL, + vDateEnd, + account.myUser_getId(), TRUE, vNewTicket); - + INSERT INTO ticketPackaging(ticketFk, packagingFk, quantity, pvp) SELECT vNewTicket, packagingFk, - SUM(quantity) totalQuantity, price - FROM tmp.packagingToInvoice + FROM tmp.packagingToInvoice WHERE clientFk = vClientId GROUP BY packagingFk HAVING IF(vWithoutPeriodGrace, totalQuantity <> 0, totalQuantity < 0); - + INSERT INTO sale(ticketFk, itemFk, concept, quantity, price) SELECT vNewTicket, pti.itemFk, i.name, SUM(pti.quantity) totalQuantity, pti.price FROM tmp.packagingToInvoice pti @@ -71200,12 +68450,12 @@ BEGIN WHERE pti.clientFk = vClientId GROUP BY pti.itemFk HAVING IF(vWithoutPeriodGrace, totalQuantity <> 0, totalQuantity > 0); - + INSERT INTO saleComponent(saleFk, componentFk, value) SELECT id, vComponentCost, price FROM sale WHERE ticketFk = vNewTicket; - + COMMIT; END LOOP; CLOSE vCursor; @@ -71229,37 +68479,37 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1)) BEGIN - + /** * Averigua los tickets que se han saltado por un error en el proceso encajado * @param vTicketFk Ticket * @param vItemPackingTypeFk Modo de encajado * @return un select con los tickets afectados - */ + */ DECLARE vParkingFk INT; DECLARE vParked DATETIME; DECLARE vLevel INT; DECLARE vWagon INT; DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) + + SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) INTO vLevel, vWagon, vCollectionFk FROM vn.ticketCollection tc JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk WHERE ticketFk = vTicketFk ORDER BY c.id DESC LIMIT 1; - - SELECT created, parkingFk + + SELECT created, parkingFk INTO vParked, vParkingFk FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk WHERE ticketFk = vTicketFk AND s.itemPackingTypeFk = vItemPackingTypeFk AND s.isPackagingArea ; - + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp JOIN vn.parking p ON p.id = tp.parkingFk @@ -71276,9 +68526,9 @@ BEGIN AND ( ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) OR - ( tc.collectionFk = vCollectionFk + ( tc.collectionFk = vCollectionFk AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) - OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) + OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) ) ) ) -- Etiquetas que no se han escaneado y ya estamos con una posterior @@ -71286,7 +68536,7 @@ BEGIN (s.alertLevel > 1 AND tp.parkingFk = vParkingFk AND sc.isPackagingArea - AND tp.created < vParked + AND tp.created < vParked AND t.packages <=> 0); END ;; DELIMITER ; @@ -71338,11 +68588,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketRequest_Add`(vDescription VARCHAR(255), vQuantity INT, vPrice DOUBLE, vTicketFk INT, vBuyerCode VARCHAR(3)) BEGIN - INSERT INTO vn.ticketRequest(description, - quantity, - price, - ticketFk, - buyerCode, + INSERT INTO vn.ticketRequest(description, + quantity, + price, + ticketFk, + buyerCode, requesterFk) VALUES(vDescription, vQuantity, @@ -71350,7 +68600,7 @@ BEGIN vTicketFk, vBuyerCode, vn.getUser()); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71369,26 +68619,26 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN - + /* Modifica el estado de un ticket de hoy - * + * * @param vTicketFk el id del ticket * @param vStateCode estado a modificar del ticket - * + * */ - + DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM state s - JOIN ticketStateToday tst ON tst.state = s.id + + SELECT s.alertLevel INTO vAlertLevel + FROM state s + JOIN ticketStateToday tst ON tst.state = s.id WHERE tst.ticket = vTicketFk LIMIT 1; - + IF vAlertLevel < 2 THEN - + CALL vn.ticket_setState(vTicketFk, vStateCode); - + END IF; END ;; @@ -71398,34 +68648,34 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketStateUpdate` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN - + /* * @deprecated:utilizar ticket_setState */ - + DECLARE vAlertLevel INT; - SELECT s.alertLevel INTO vAlertLevel + SELECT s.alertLevel INTO vAlertLevel FROM vn.state s JOIN vn.ticketState ts ON ts.stateFk = s.id WHERE ts.ticketFk = vTicketFk; - - IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN - - INSERT INTO ticketTracking(stateFk, ticketFk, workerFk) + + IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN + + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT id, vTicketFk, account.myUser_getId() - FROM vn.state + FROM vn.state WHERE `code` = vStateCode collate utf8_unicode_ci; END IF; @@ -71569,14 +68819,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_add` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_add`( vClientId INT @@ -71693,7 +68943,7 @@ BEGIN END IF; 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 ticketTracking(stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT id, vNewTicket, account.myUser_getId() FROM state WHERE `code` = 'DELIVERED'; @@ -71716,20 +68966,20 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN - + INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) - SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed + SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed FROM vn.ticket t JOIN vn.warehouse w ON w.name = 'INVENTARIO' WHERE t.id = vOriginalTicket; - + SELECT LAST_INSERT_ID() INTO vNewTicket; INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) - SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount + SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount FROM vn.sale s WHERE s.ticketFk = vOriginalTicket; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71759,8 +69009,7 @@ BEGIN SELECT inventoried INTO vDateInventory FROM config; - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock + CREATE OR REPLACE TEMPORARY TABLE tmp.stock (itemFk INT PRIMARY KEY, amount INT) ENGINE = MEMORY; @@ -71777,7 +69026,7 @@ BEGIN SELECT itemFk, quantity FROM itemEntryIn WHERE landed >= vDateInventory - AND landed < vDateFuture + AND landed <= vDateToAdvance AND isVirtualStock = FALSE AND warehouseInFk = vWarehouseFk UNION ALL @@ -71806,15 +69055,24 @@ BEGIN dest.totalWithVat, origin.totalWithVat futureTotalWithVat, dest.agency, + dest.agencyModeFk, origin.futureAgency, + origin.agencyModeFk futureAgencyModeFk, dest.lines, dest.liters, origin.futureLines - origin.hasStock AS notMovableLines, (origin.futureLines = origin.hasStock) AS isFullMovable, + dest.zoneFk, origin.futureZoneFk, origin.futureZoneName, origin.classColor futureClassColor, - dest.classColor + dest.classColor, + origin.clientFk futureClientFk, + origin.addressFk futureAddressFk, + origin.warehouseFk futureWarehouseFk, + origin.companyFk futureCompanyFk, + IFNULL(dest.nickname, origin.nickname) nickname, + dest.landed FROM ( SELECT s.ticketFk, @@ -71822,7 +69080,6 @@ BEGIN t.shipped, t.totalWithVat, st.name futureState, - t.addressFk, am.name futureAgency, count(s.id) futureLines, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, @@ -71830,7 +69087,13 @@ BEGIN SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, z.id futureZoneFk, z.name futureZoneName, - st.classColor + st.classColor, + t.clientFk, + t.nickname, + t.addressFk, + t.warehouseFk, + t.companyFk, + t.agencyModeFk FROM ticket t JOIN client c ON c.id = t.clientFk JOIN sale s ON s.ticketFk = t.id @@ -71846,10 +69109,9 @@ BEGIN AND t.warehouseFk = vWarehouseFk GROUP BY t.id ) origin - JOIN ( + LEFT JOIN ( SELECT t.id ticketFk, - t.addressFk, st.name state, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, t.shipped, @@ -71857,7 +69119,15 @@ BEGIN am.name agency, CAST(SUM(litros) AS DECIMAL(10,0)) liters, CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, - st.classColor + st.classColor, + t.clientFk, + t.nickname, + t.addressFk, + t.zoneFk, + t.warehouseFk, + t.companyFk, + t.landed, + t.agencyModeFk FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id @@ -71871,7 +69141,7 @@ BEGIN AND st.order <= 5 GROUP BY t.id ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock != 0; + WHERE origin.hasStock; DROP TEMPORARY TABLE tmp.stock; END ;; @@ -71979,7 +69249,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canMerge`(vDated DATE, vScop BEGIN /** * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * + * * @param vDated Fecha en cuestión * @param vScopeDays Dias en el futuro a sondear * @param vLitersMax Volumen máximo de los tickets a catapultar @@ -72060,10 +69330,10 @@ BEGIN * Comprueba que los tickets entre un rango de fechas tienen componentes * y recalcula sus componentes * - * @param vShippedFrom rango inicial de fecha + * @param vShippedFrom rango inicial de fecha * @param vShippedTo rango final de fecha */ - + CREATE OR REPLACE TEMPORARY TABLE tmp.coste (primary key (id)) ENGINE = MEMORY SELECT s.id @@ -72092,9 +69362,9 @@ BEGIN AND ic.merchandise; CALL vn.sale_recalcComponent(1); - + DROP TEMPORARY TABLE tmp.recalculateSales; - DROP TEMPORARY TABLE tmp.coste; + DROP TEMPORARY TABLE tmp.coste; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72102,14 +69372,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_Clone` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN @@ -72164,8 +69434,8 @@ BEGIN FROM ticketObservation WHERE ticketFk = vOriginalTicket; - INSERT INTO ticketTracking(ticketFk, stateFk, workerFk, created) - SELECT vNewTicket, stateFk, workerFk, created + INSERT INTO ticketTracking(ticketFk, stateFk, userFk, created) + SELECT vNewTicket, stateFk, userFk, created FROM ticketTracking WHERE ticketFk = vOriginalTicket ORDER BY created; @@ -72185,14 +69455,13 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_cloneWeekly`(vWeek INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_cloneWeekly`(vDateFrom DATE, vDateTo DATE) BEGIN DECLARE vIsDone BOOL; DECLARE vLanding DATE; DECLARE vShipment DATE; DECLARE vWarehouseFk INT; DECLARE vTicketFk INT; - DECLARE vWeekDay INT; DECLARE vClientFk INT; DECLARE vCompanyFk INT; DECLARE vAddressFk INT; @@ -72204,19 +69473,21 @@ BEGIN DECLARE rsTicket CURSOR FOR SELECT tt.ticketFk, - tt.weekDay, - t.clientFk, - t.warehouseFk, - t.companyFk, - t.addressFk, - tt.agencyModeFk - FROM ticketWeekly tt - JOIN ticket t ON tt.ticketFk = t.id; + t.clientFk, + t.warehouseFk, + t.companyFk, + t.addressFk, + tt.agencyModeFk, + ti.dated + FROM ticketWeekly tt + JOIN ticket t ON tt.ticketFk = t.id + JOIN tmp.time ti + WHERE WEEKDAY(ti.dated) = tt.weekDay; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; - - SET vYear = YEAR(util.VN_CURDATE()) + IF(vWeek < WEEK(util.VN_CURDATE()),1, 0); - + + CALL `util`.`time_generate`(vDateFrom,vDateTo); + OPEN rsTicket; myLoop: LOOP BEGIN @@ -72224,36 +69495,31 @@ BEGIN DECLARE vIsDuplicateMail BOOL; DECLARE vSubject VARCHAR(150); DECLARE vMessage TEXT; - + SET vIsDone = FALSE; - FETCH rsTicket INTO vTicketFk, vWeekDay, vClientFk, vWarehouseFk, vCompanyFk, vAddressFk, vAgencyModeFk; + FETCH rsTicket INTO vTicketFk,vClientFk, vWarehouseFk, vCompanyFk, vAddressFk, vAgencyModeFk,vShipment; IF vIsDone THEN LEAVE myLoop; END IF; - SELECT dated INTO vShipment - FROM `time` - WHERE `year` = vYear AND `week` = vWeek - AND WEEKDAY(dated) = vWeekDay; - -- busca si el ticket ya ha sido clonado IF EXISTS (SELECT TRUE FROM ticket tOrig JOIN sale saleOrig ON tOrig.id = saleOrig.ticketFk JOIN saleCloned sc ON sc.saleOriginalFk = saleOrig.id JOIN sale saleClon ON saleClon.id = sc.saleClonedFk JOIN ticket tClon ON tClon.id = saleClon.ticketFk - WHERE tOrig.id = vTicketFk - AND tClon.isDeleted = FALSE + WHERE tOrig.id = vTicketFk + AND tClon.isDeleted = FALSE AND DATE(tClon.shipped) = vShipment) THEN ITERATE myLoop; END IF; IF vAgencyModeFk IS NULL THEN - SELECT agencyModeFk INTO vAgencyModeFk + SELECT agencyModeFk INTO vAgencyModeFk FROM address - WHERE clientFk = vClientFk + WHERE clientFk = vClientFk AND isDefaultAddress; END IF; @@ -72274,8 +69540,8 @@ BEGIN FALSE, vNewTicket); - UPDATE ticket - SET clonedFrom = vTicketFk + UPDATE ticket + SET clonedFrom = vTicketFk WHERE id = vNewTicket; INSERT INTO sale (ticketFk, itemFk, concept, quantity, price, @@ -72294,7 +69560,7 @@ BEGIN INSERT IGNORE INTO saleCloned(saleOriginalFk, saleClonedFk) SELECT saleOriginal.id, saleClon.id FROM sale saleOriginal - JOIN sale saleClon ON saleOriginal.itemFk = saleClon.itemFk + JOIN sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity WHERE saleOriginal.ticketFk = vTicketFk AND saleClon.ticketFk = vNewTicket; @@ -72324,7 +69590,7 @@ BEGIN buyed, requesterFk, attenderFk, - vNewTicket + vNewTicket FROM ticketRequest WHERE ticketFk =vTicketFk; @@ -72339,26 +69605,26 @@ BEGIN INSERT INTO ticketObservation( ticketFk, observationTypeFk, - description) + description) VALUES( vNewTicket, vSalesPersonFK, CONCAT('turno desde ticket: ',vTicketFk)) - ON DUPLICATE KEY UPDATE description = + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); INSERT INTO ticketObservation(ticketFk, observationTypeFk, - description) + description) VALUES( vNewTicket, vItemPicker, 'ATENCION: Contiene lineas de TURNO') - ON DUPLICATE KEY UPDATE description = + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); IF (vLanding IS NULL) THEN - + SELECT e.email INTO vSalesPersonEmail FROM client c JOIN account.emailUser e ON e.userFk = c.salesPersonFk @@ -72366,8 +69632,8 @@ BEGIN SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicketFk,' para el dia: ', vShipment); - SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicketFk, - ' para el dia: ', vShipment, + SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicketFk, + ' para el dia: ', vShipment, ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket, ' pero ha que revisar las fechas y la agencia'); @@ -72387,6 +69653,7 @@ BEGIN END; END LOOP; CLOSE rsTicket; + DROP TEMPORARY TABLE IF EXISTS tmp.time; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72406,7 +69673,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_close`() BEGIN /** - * Realiza el cierre de todos los + * Realiza el cierre de todos los * tickets de la tabla tmp.ticket_close. * * @table tmp.ticket_close(ticketFk) Identificadores de los tickets a cerrar @@ -72424,7 +69691,7 @@ BEGIN DECLARE cur CURSOR FOR SELECT ticketFk FROM tmp.ticket_close; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN RESIGNAL; @@ -72434,7 +69701,7 @@ BEGIN proc: LOOP SET vDone = FALSE; - + FETCH cur INTO vCurTicketFk; IF vDone THEN @@ -72451,12 +69718,12 @@ BEGIN c.hasToInvoice INTO vClientFk, vIsTaxDataChecked, - vCompanyFk, + vCompanyFk, vShipped, vHasDailyInvoice, vWithPackage, vHasToInvoice - FROM ticket t + FROM ticket t JOIN `client` c ON c.id = t.clientFk JOIN province p ON p.id = c.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk @@ -72466,22 +69733,22 @@ BEGIN INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) (SELECT vCurTicketFk, p.id, COUNT(*) - FROM expedition e + FROM expedition e JOIN packaging p ON p.itemFk = e.freightItemFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage GROUP BY p.itemFk); -- No retornables o no catalogados - INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) + INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) (SELECT e.freightItemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.freightItemFk, vClientFk), 1 - FROM expedition e + FROM expedition e JOIN item i ON i.id = e.freightItemFk LEFT JOIN packaging p ON p.itemFk = i.id WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 AND getSpecialPrice(e.freightItemFk, vClientFk) > 0 GROUP BY e.freightItemFk); - + IF(vHasDailyInvoice) AND vHasToInvoice THEN -- Facturacion rapida @@ -72489,10 +69756,10 @@ BEGIN -- Facturar si está contabilizado IF vIsTaxDataChecked THEN CALL invoiceOut_newFromClient( - vClientFk, - (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), - vShipped, - vCompanyFk, + vClientFk, + (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), + vShipped, + vCompanyFk, NULL, NULL, vNewInvoiceId); @@ -72560,25 +69827,25 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentMakeUpdate`( - vTicketFk INT, + vTicketFk INT, vClientFk INT, - vNickname VARCHAR(50), + vNickname VARCHAR(50), vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, + vAddressFk INT, + vZoneFk INT, vWarehouseFk INT, - vCompanyFk INT, + vCompanyFk INT, vShipped DATETIME, - vLanded DATE, + vLanded DATE, vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, + vHasToBeUnrouted BOOLEAN, vOption INT) BEGIN - + /** * Modifica en el ticket los campos que se le pasan por parámetro * y cambia sus componentes - * + * * @param vTicketFk Id del ticket a modificar * @param vClientFk nuevo cliente * @param vNickname nuevo alias @@ -72593,29 +69860,29 @@ BEGIN * @param vHasToBeUnrouted si se le elimina la ruta al ticket * @param vOption opcion para el case del proc ticketComponentUpdateSale */ - + DECLARE vPrice DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2); CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t + + UPDATE ticket t JOIN address a ON a.id = vAddressFk SET t.nickname = a.nickname WHERE t.id = vTicketFk; - + END IF; CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); - SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus FROM tmp.zoneGetShipped WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; - + UPDATE ticket t - SET + SET t.clientFk = vClientFk, t.nickname = vNickname, t.agencyModeFk = vAgencyModeFk, @@ -72630,12 +69897,12 @@ BEGIN t.isDeleted = vIsDeleted WHERE t.id = vTicketFk; - + IF vHasToBeUnrouted THEN UPDATE ticket t SET t.routeFk = NULL WHERE t.id = vTicketFk; END IF; - + IF vOption <> 8 THEN DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale @@ -72673,7 +69940,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentPreview`( vTicketFk INT, - vLanded DATE, + vLanded DATE, vAddressFk INT, vZoneFk INT, vWarehouseFk SMALLINT) @@ -72689,7 +69956,7 @@ BEGIN * * @return tmp.ticketComponentPreview (warehouseFk, itemFk, componentFk, cost) */ - DECLARE vHasDataChanged BOOL DEFAULT FALSE; + DECLARE vHasDataChanged BOOL DEFAULT FALSE; DECLARE vHasAddressChanged BOOL; DECLARE vHasZoneChanged BOOL DEFAULT FALSE; DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; @@ -72700,8 +69967,8 @@ BEGIN DECLARE vHasChangeAll BOOL DEFAULT FALSE; - SELECT DATE(landed) <> vLanded, - addressFk <> vAddressFk, + SELECT DATE(landed) <> vLanded, + addressFk <> vAddressFk, zoneFk <> vZoneFk, warehouseFk <> vWarehouseFk INTO @@ -72724,15 +69991,15 @@ BEGIN SET vAgencyModeTypeRateFk = 6; END IF; - SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped + SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped FROM zone WHERE id = vZoneFk; - + CALL buyUltimate(vWarehouseFk, vShipped); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( - SELECT + CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( + SELECT vWarehouseFk AS warehouseFk, NULL AS available, s.itemFk, @@ -72752,9 +70019,9 @@ BEGIN JOIN sale s ON s.id = sc.saleFk JOIN ticket t ON t.id = s.ticketFk JOIN `component` c ON c.id = sc.componentFk - WHERE s.ticketFk = vTicketFk - AND (c.isRenewable = FALSE - OR + WHERE s.ticketFk = vTicketFk + AND (c.isRenewable = FALSE + OR (NOT vHasChangeAll AND (NOT (c.typeFk <=> vAddressTypeRateFk OR c.typeFk <=> vAgencyModeTypeRateFk)))); @@ -72833,55 +70100,59 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_DelayTruckSplit`(vTicketFk INT) -BEGIN - - /* - * Splita las lineas de ticket que no estan ubicadas - * - */ - - DECLARE vNewTicketFk INT; - DECLARE vTotalLines INT; - DECLARE vLinesToSplit INT; - - DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit; - - SELECT COUNT(*) INTO vTotalLines - FROM vn.sale - WHERE ticketFk = vTicketFk; - - CREATE TEMPORARY TABLE tmp.SalesToSplit - SELECT s.id saleFk - FROM vn.ticket t - JOIN vn.sale s ON t.id = s.ticketFk - LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = s.itemFk AND issw.warehouseFk = t.warehouseFk - WHERE s.quantity > IFNULL(issw.visible, 0) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND t.id = vTicketFk; - - SELECT COUNT(*) INTO vLinesToSplit - FROM tmp.SalesToSplit; - - IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN - - SET vNewTicketFk = vTicketFk; - - ELSE - - CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); - - UPDATE vn.sale s - JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id - SET s.ticketFk = vNewTicketFk; - - END IF; - - CALL vn.ticketStateUpdate(vNewTicketFk, 'FIXING'); - - DROP TEMPORARY TABLE tmp.SalesToSplit; - +BEGIN +/** + * Splita las lineas de ticket que no estan ubicadas + * + * @param vTicketFk Id ticket + */ + DECLARE vNewTicketFk INT; + DECLARE vTotalLines INT; + DECLARE vLinesToSplit INT; + + DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit; + + SELECT COUNT(*) INTO vTotalLines + FROM sale + WHERE ticketFk = vTicketFk; + + CREATE TEMPORARY TABLE tmp.SalesToSplit + SELECT s.id saleFk + FROM ticket t + JOIN sale s ON t.id = s.ticketFk + LEFT JOIN ( + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk + ) issw ON issw.itemFk = s.itemFk + AND issw.warehouseFk = t.warehouseFk + WHERE s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND t.id = vTicketFk; + + SELECT COUNT(*) INTO vLinesToSplit + FROM tmp.SalesToSplit; + + IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN + SET vNewTicketFk = vTicketFk; + ELSE + CALL ticket_Clone(vTicketFk, vNewTicketFk); + UPDATE sale s + JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id + SET s.ticketFk = vNewTicketFk; + END IF; + + CALL ticketStateUpdate(vNewTicketFk, 'FIXING'); + + DROP TEMPORARY TABLE tmp.SalesToSplit; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72899,91 +70170,91 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_doCmr`(vSelf INT) -BEGIN -/** -* Crea u actualiza la información del CMR asociado con -* un ticket específico en caso de que sea necesario. -* -* @param vSelf El id del ticket -*/ - DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT; - SELECT cmrFk INTO vCmrFk - FROM ticket - WHERE id = vSelf; - - CREATE OR REPLACE TEMPORARY TABLE tTicket - SELECT wo.firstName, - v.numberPlate, - com.id companyFk, - a.id addressFk, - c2.defaultAddressFk, - su.id supplierFk, - t.landed - FROM ticket t - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN `state` s ON s.id = ts.stateFk - JOIN alertLevel al ON al.id = s.alertLevel - JOIN client c ON c.id = t.clientFk - JOIN `address` a ON a.id = t.addressFk - JOIN province p ON p.id = a.provinceFk - JOIN country co ON co.id = p.countryFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - JOIN warehouse w ON w.id = t.warehouseFk - JOIN company com ON com.id = t.companyFk - JOIN client c2 ON c2.id = com.clientFk - JOIN supplierAccount sa ON sa.id = com.supplierAccountFk - JOIN supplier su ON su.id = sa.supplierFk - LEFT JOIN route r ON r.id = t.routeFk - LEFT JOIN worker wo ON wo.id = r.workerFk - LEFT JOIN vehicle v ON v.id = r.vehicleFk - WHERE t.shipped BETWEEN util.yesterday() AND util.dayEnd(util.VN_CURDATE()) - AND al.code IN ('PACKED', 'DELIVERED') - AND co.code <> 'ES' - AND am.name <> 'ABONO' - AND w.code = 'ALG' - AND dm.code = 'DELIVERY' - AND t.id = vSelf - GROUP BY t.id; - - START TRANSACTION; - - IF vCmrFk THEN - UPDATE cmr c - JOIN tTicket t - SET c.senderInstruccions = t.firstName, - c.truckPlate = t.numberPlate, - c.companyFk = t.companyFk, - c.addressToFk = t.addressFk, - c.addressFromFk = t.defaultAddressFk, - c.supplierFk = t.supplierFk, - c.ead = t.landed - WHERE id = vCmrFk; - ELSE - SELECT MAX(id) INTO vPreviousCmrFk FROM cmr; - - INSERT INTO cmr ( - senderInstruccions, - truckPlate, - companyFk, - addressToFk, - addressFromFk, - supplierFk, - ead - ) - SELECT * FROM tTicket; - - SELECT MAX(id) INTO vCurrentCmrFk FROM cmr; - - IF vPreviousCmrFk <> vCurrentCmrFk THEN - UPDATE ticket - SET cmrFk = vCurrentCmrFk - WHERE id = vSelf; - END IF; - END IF; - - COMMIT; - DROP TEMPORARY TABLE tTicket; +BEGIN +/** +* Crea u actualiza la información del CMR asociado con +* un ticket específico en caso de que sea necesario. +* +* @param vSelf El id del ticket +*/ + DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT; + SELECT cmrFk INTO vCmrFk + FROM ticket + WHERE id = vSelf; + + CREATE OR REPLACE TEMPORARY TABLE tTicket + SELECT wo.firstName, + v.numberPlate, + com.id companyFk, + a.id addressFk, + c2.defaultAddressFk, + su.id supplierFk, + t.landed + FROM ticket t + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN `state` s ON s.id = ts.stateFk + JOIN alertLevel al ON al.id = s.alertLevel + JOIN client c ON c.id = t.clientFk + JOIN `address` a ON a.id = t.addressFk + JOIN province p ON p.id = a.provinceFk + JOIN country co ON co.id = p.countryFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN company com ON com.id = t.companyFk + JOIN client c2 ON c2.id = com.clientFk + JOIN supplierAccount sa ON sa.id = com.supplierAccountFk + JOIN supplier su ON su.id = sa.supplierFk + LEFT JOIN route r ON r.id = t.routeFk + LEFT JOIN worker wo ON wo.id = r.workerFk + LEFT JOIN vehicle v ON v.id = r.vehicleFk + WHERE t.shipped BETWEEN util.yesterday() AND util.dayEnd(util.VN_CURDATE()) + AND al.code IN ('PACKED', 'DELIVERED') + AND co.code <> 'ES' + AND am.name <> 'ABONO' + AND w.code = 'ALG' + AND dm.code = 'DELIVERY' + AND t.id = vSelf + GROUP BY t.id; + + START TRANSACTION; + + IF vCmrFk THEN + UPDATE cmr c + JOIN tTicket t + SET c.senderInstruccions = t.firstName, + c.truckPlate = t.numberPlate, + c.companyFk = t.companyFk, + c.addressToFk = t.addressFk, + c.addressFromFk = t.defaultAddressFk, + c.supplierFk = t.supplierFk, + c.ead = t.landed + WHERE id = vCmrFk; + ELSE + SELECT MAX(id) INTO vPreviousCmrFk FROM cmr; + + INSERT INTO cmr ( + senderInstruccions, + truckPlate, + companyFk, + addressToFk, + addressFromFk, + supplierFk, + ead + ) + SELECT * FROM tTicket; + + SELECT MAX(id) INTO vCurrentCmrFk FROM cmr; + + IF vPreviousCmrFk <> vCurrentCmrFk THEN + UPDATE ticket + SET cmrFk = vCurrentCmrFk + WHERE id = vSelf; + END IF; + END IF; + + COMMIT; + DROP TEMPORARY TABLE tTicket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73216,37 +70487,37 @@ BEGIN * @param vTicketFk -> Ticket * @param vDatedNew -> Nueva fecha * @return Sales con Movible -*/ +*/ DECLARE vDatedOld DATETIME; SET vDatedNew = DATE_ADD(vDatedNew, INTERVAL 1 DAY); SELECT t.shipped INTO vDatedOld - FROM ticket t + FROM ticket t WHERE t.id = vTicketFk; - CALL item_getStock(vWarehouseFk, vDatedNew, NULL); + CALL item_getStock(vWarehouseFk, vDatedNew, NULL); CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(DATE_SUB(vDatedOld, INTERVAL 1 DAY), vDatedNew), NULL); - - SELECT s.id, - s.itemFk, - s.quantity, - s.concept, - s.price, + + SELECT s.id, + s.itemFk, + s.quantity, + s.concept, + s.price, s.reserved, - s.discount, - i.image, - i.subName, + s.discount, + i.image, + i.subName, il.stock + IFNULL(im.amount, 0) AS movable FROM ticket t JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk + JOIN item i ON i.id = s.itemFk LEFT JOIN tmp.itemMinacum im ON im.itemFk = s.itemFk AND im.warehouseFk = vWarehouseFk LEFT JOIN tmp.itemList il ON il.itemFk = s.itemFk WHERE t.id = vTicketFk; DROP TEMPORARY TABLE IF EXISTS tmp.itemList; - DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; - + DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73274,7 +70545,7 @@ BEGIN */ CALL sale_getProblems(vIsTodayRelative); - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems (PRIMARY KEY (ticketFk)) ENGINE = MEMORY SELECT ticketFk, @@ -73346,16 +70617,32 @@ BEGIN problem VARCHAR(1), INDEX(ticketFk)) ENGINE = MEMORY; + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk; + INSERT INTO tmp.salesToSplit(saleFk, ticketFk, problem) SELECT s.id, s.ticketFk, 'F' FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) < s.quantity AND IFNULL(av.available ,0) < s.quantity AND IFNULL(issw.visible, 0) < s.quantity @@ -73365,26 +70652,28 @@ BEGIN AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; - + INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem) SELECT s.id, s.ticketFk, 'I' - FROM ticket t + FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND ic.merchandise = TRUE + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; - + INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem) SELECT s.id, s.ticketFk, 'R' FROM ticket t @@ -73392,20 +70681,23 @@ BEGIN JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) < s.quantity AND IFNULL(av.available ,0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND ic.merchandise = TRUE + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; - + CREATE OR REPLACE TEMPORARY TABLE tTicketsToSplit( ticketFk INT PRIMARY KEY, problems VARCHAR(100), @@ -73420,18 +70712,18 @@ BEGIN GROUP_CONCAT(DISTINCT ss.problem ORDER BY ss.problem) problems, t.addressFk, GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - DATE_FORMAT(IF(HOUR(t.shipped), - t.shipped, + DATE_FORMAT(IF(HOUR(t.shipped), + t.shipped, IFNULL(zc.hour, z.HOUR)),'%H:%i') etd FROM tmp.salesToSplit ss JOIN ticket t ON t.id = ss.ticketFk JOIN sale s ON s.id = ss.saleFk JOIN item i ON i.id = s.itemFk LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk - LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN zone z ON z.id = t.zoneFk GROUP BY ss.ticketFk; - SELECT ts.*, + SELECT ts.*, t.id ticketFuture, st.name state, zc.`hour` tfEtd, @@ -73442,22 +70734,24 @@ BEGIN FROM tTicketsToSplit ts LEFT JOIN ticketState ts2 ON ts2.ticketFk = ts.ticketFk LEFT JOIN `state` st ON st.id = ts2.stateFk - LEFT JOIN ticket t ON t.id != ts.ticketFk + LEFT JOIN ticket t ON t.id != ts.ticketFk AND t.addressFk = ts.addressFk AND t.shipped BETWEEN vDated AND util.dayend(vDated) LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = vDated LEFT JOIN sale s ON s.ticketFk = t.id LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN ticketState tst ON tst.ticketFk = t.id + LEFT JOIN ticketState tst ON tst.ticketFk = t.id LEFT JOIN state st2 ON st2.id = tst.stateFk - WHERE (t.id IS NULL + WHERE (t.id IS NULL OR (vDated > util.VN_CURDATE()) OR (vDated = util.VN_CURDATE() AND vHour >= zc.`hour`)) AND ts.etd <= vHour GROUP BY ts.ticketFk, t.id ORDER BY ts.etd, ts.ticketFk; - - DROP TEMPORARY TABLE tTicketsToSplit; + + DROP TEMPORARY TABLE + tTicketsToSplit, + tItemShelvingStock_byWarehouse; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73493,7 +70787,7 @@ BEGIN JOIN ticket t ON t.id = tmpTicket.ticketFk; CALL addressTaxArea (); - + IF vTaxArea IS NOT NULL THEN UPDATE tmp.addressTaxArea SET areaFk = vTaxArea; @@ -73565,8 +70859,8 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticketAmount (INDEX (ticketFk)) ENGINE = MEMORY - SELECT ticketFk, - taxableBase, + SELECT ticketFk, + taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax, code FROM tmp.ticketTax @@ -73646,11 +70940,11 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getWithParameters`( - vClientFk INT, + vClientFk INT, vWarehouseFk INT, - vShipped DATE, - vAddressFk INT, - vCompanyFk INT, + vShipped DATE, + vAddressFk INT, + vCompanyFk INT, vAgencyModeFk INT, OUT vTicketFk INT ) @@ -73664,8 +70958,8 @@ BEGIN * @param vAddressFk Consignatario * @param vCompanyFk Empresa * @param vAgencyModeFk agencia - */ - + */ + SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.clientFk <=> vClientFk @@ -73675,7 +70969,7 @@ BEGIN AND (t.companyFk <=> vCompanyFk OR vCompanyFk IS NULL) AND (t.agencyModeFk <=> vAgencyModeFk OR vAgencyModeFk IS NULL) LIMIT 1; - + IF vTicketFk IS NULL THEN CALL vn.ticket_add( vClientFk, @@ -73715,24 +71009,24 @@ BEGIN DECLARE vAddressFk INT; DECLARE vAgencyModeFk INT; DECLARE vWarehouseFk INT; - DECLARE vCursor CURSOR FOR + DECLARE vCursor CURSOR FOR SELECT id, landed, addressFk, agencyModeFk, warehouseFk FROM vn.ticket WHERE shipped > '2020-01-01' AND zoneFk is null; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET vDone = 1; - + OPEN vCursor; REPEAT FETCH vCursor INTO vFechedTicket, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk; CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); - + UPDATE vn.ticket t JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = vWarehouseFk SET t.zoneFk = zgs.zoneFk WHERE t.id = vFechedTicket; - + UNTIL vDone END REPEAT; DROP TEMPORARY TABLE tmp.zoneGetShipped; - + CLOSE vCursor; END ;; DELIMITER ; @@ -73752,14 +71046,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_priceDifference`( vTicketFk INT, - vLanded DATE, + vLanded DATE, vAddressFk INT, vZoneFk INT, vWarehouseFk INT) BEGIN /** * Devuelve las diferencias de precio de los movimientos de un ticket. - * + * * @param vTicketFk Id del ticket * @param vLanded Fecha de recepcion * @param vAddressFk Id del consignatario @@ -73768,26 +71062,26 @@ BEGIN */ CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); - SELECT s.itemFk, - i.name, - i.size, - i.category, - IFNULL(s.quantity, 0) AS quantity, - IFNULL(s.price, 0) AS price, + SELECT s.itemFk, + i.name, + i.size, + i.category, + IFNULL(s.quantity, 0) AS quantity, + IFNULL(s.price, 0) AS price, ROUND(SUM(tc.cost), 2) AS newPrice, s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference, s.id AS saleFk FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = vWarehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk - WHERE t.id = vTicketFk - AND IF(sc.componentFk IS NULL - AND c.classRate IS NOT NULL, FALSE, TRUE) + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE t.id = vTicketFk + AND IF(sc.componentFk IS NULL + AND c.classRate IS NOT NULL, FALSE, TRUE) GROUP BY s.id ORDER BY s.id; DROP TEMPORARY TABLE tmp.ticketComponentPreview; @@ -73810,7 +71104,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_printLabelPrevious`(vTicketFk INT) BEGIN /** - * Calls the report_print procedure and passes it + * Calls the report_print procedure and passes it * the necessary parameters for printing. * * @param vTicketFk id ticket to print. @@ -73818,18 +71112,18 @@ BEGIN DECLARE vPrinterFk INT; DECLARE vSaleGroup INT; DECLARE vUserFk INT DEFAULT account.myUser_getId(); - + SELECT sg.id, o.labelerFk INTO vSaleGroup, vPrinterFk FROM saleGroup sg JOIN sector sc ON sc.id = sg.sectorFk - JOIN saleGroupDetail sgd ON sg.id = sgd.saleGroupFk + JOIN saleGroupDetail sgd ON sg.id = sgd.saleGroupFk JOIN sale s ON sgd.saleFk = s.id JOIN ticket t ON s.ticketFk = t.id JOIN operator o ON o.workerFk = vUserFk - WHERE sc.id = o.sectorFk + WHERE sc.id = o.sectorFk AND t.id = vTicketFk LIMIT 1; - + CALL report_print( 'LabelPrevia', vPrinterFk, @@ -73863,12 +71157,12 @@ proc:BEGIN */ DECLARE hasInvoice BOOL; - SELECT COUNT(*) INTO hasInvoice - FROM ticket + SELECT COUNT(*) INTO hasInvoice + FROM ticket WHERE id = vSelf AND refFk IS NOT NULL; - - IF hasInvoice THEN + + IF hasInvoice THEN LEAVE proc; END IF; @@ -73956,14 +71250,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setNextState` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setNextState`(vSelf INT) BEGIN @@ -73983,7 +71277,7 @@ BEGIN FROM state WHERE id = vStateFk; - INSERT INTO ticketTracking(stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) VALUES (vNewStateFk, vSelf, account.myUser_getId()); END ;; DELIMITER ; @@ -74047,14 +71341,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setPreviousState` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setPreviousState`(vTicketFk INT) BEGIN @@ -74079,7 +71373,7 @@ BEGIN ORDER BY id DESC LIMIT 1; - INSERT INTO ticketTracking(stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT s.nextStateFk, tt.ticketFk, account.myUser_getId() FROM ticketTracking tt JOIN vn.state s ON tt.stateFk = s.id @@ -74127,14 +71421,14 @@ BEGIN ORDER BY tt.created DESC LIMIT 1; - SELECT id INTO vPackedAlertLevel FROM alertLevel WHERE code = 'PACKED'; + SELECT id INTO vPackedAlertLevel FROM alertLevel WHERE code = 'PACKED'; IF vStateCode = 'OK' AND vZoneFk IS NULL THEN CALL util.throw('ASSIGN_ZONE_FIRST'); END IF; SET vCanChangeState = ( - vStateCode <> 'ON_CHECKING' OR + vStateCode <> 'ON_CHECKING' OR vticketAlertLevel < vPackedAlertLevel )AND NOT ( vTicketStateCode IN ('CHECKED', 'CHECKING') @@ -74142,11 +71436,11 @@ BEGIN ); IF vCanChangeState THEN - INSERT INTO ticketTracking (stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking (stateFk, ticketFk, userFk) SELECT id, vSelf, account.myUser_getId() FROM state WHERE `code` = vStateCode COLLATE utf8_unicode_ci; - + IF vStateCode = 'PACKED' THEN CALL ticket_doCmr(vSelf); END IF; @@ -74186,40 +71480,40 @@ proc:BEGIN SELECT COUNT(*) INTO vProblemLines FROM tmp.salesToSplit WHERE ticketFk = vTicketFk; - + SELECT count(*) INTO vTotalLines - FROM vn.sale s + FROM vn.sale s WHERE s.ticketFk = vTicketFk; - + SET vHasFullProblem = (vTotalLines = vProblemLines); -- Ticket completo IF vHasFullProblem THEN - + UPDATE vn.ticket SET landed = vDated + INTERVAL 1 DAY, shipped = vDated, nickname = CONCAT('(',DAY(util.VN_CURDATE()),') ', nickname ) WHERE id = vTicketFk; - + SELECT CONCAT("Se ha cambiado el ticket ", vTicketFk, " al dia ", vDated); LEAVE proc; - + END IF; -- Ticket a futuro existe IF vTicketFutureFk THEN - - UPDATE vn.sale s + + UPDATE vn.sale s JOIN tmp.salesToSplit ss ON s.id = ss.saleFk SET s.ticketFk = vTicketFutureFk, s.concept = CONCAT('(s) ', s.concept) WHERE ss.ticketFk = vTicketFk; - - SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, + + SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, " al ticket existente ", vTicketFutureFk,"(", vDated,")"); LEAVE proc; - + END IF; -- Ticket nuevo @@ -74231,18 +71525,18 @@ proc:BEGIN t.landed = vDated + INTERVAL 1 DAY, t.shipped = vDated, t.agencyModeFk = pc.defautlAgencyMode, - t.zoneFk = pc.defaultZone + t.zoneFk = pc.defaultZone WHERE t.id = vTicketFutureFk; - - UPDATE vn.sale s - JOIN tmp.salesToSplit sts ON sts.saleFk = s.id + + UPDATE vn.sale s + JOIN tmp.salesToSplit sts ON sts.saleFk = s.id SET s.ticketFk = vTicketFutureFk, s.concept = CONCAT('(s) ', s.concept) WHERE sts.ticketFk = vTicketFk; CALL vn.ticketStateUpdate(vTicketFutureFk, 'FIXING'); - SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, + SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, " al nuevo ticket ", vTicketFutureFk,"(", vDated,")"); END ;; DELIMITER ; @@ -74351,7 +71645,7 @@ proc:BEGIN SELECT itemPackingTypeFk INTO vItemPackingTypeFk FROM tmp.saleGroup sg WHERE NOT ISNULL(sg.itemPackingTypeFk) - ORDER BY sg.totalLitros + ORDER BY sg.itemPackingTypeFk LIMIT 1; UPDATE vn.sale s @@ -74381,43 +71675,43 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_splitPackingComplete`(vTicketFk INT, vSectorFk INT) BEGIN - + DECLARE vNeedToSplit BOOLEAN; DECLARE vNewTicketFk INT; - + DROP TEMPORARY TABLE IF EXISTS tmpSale; - + CREATE TEMPORARY TABLE tmpSale SELECT DISTINCT s.id - FROM vn.ticket t + FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk + JOIN vn.item i ON i.id = s.itemFk LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = vSectorFk - JOIN vn.packagingConfig pc + JOIN vn.packagingConfig pc WHERE t.id = vTicketFk AND ( s.quantity MOD IFNULL(iss.packing,1) != 0 - OR + OR IFNULL(iss.packing,1) = 1 - OR + OR i.`size` <= pc.previousPreparationMinimumSize ); - - SELECT COUNT(*) + + SELECT COUNT(*) INTO vNeedToSplit - FROM tmpSale; - + FROM tmpSale; + IF vNeedToSplit THEN - + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); - + UPDATE vn.sale s - JOIN vn.tmpSale ts ON ts.id = s.id + JOIN vn.tmpSale ts ON ts.id = s.id SET s.ticketFk = vNewTicketFk; - + END IF; - + DROP TEMPORARY TABLE tmpSale; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74448,7 +71742,7 @@ BEGIN WHERE ot.description = 'Peso Aduana' AND t.clientFk = vClientFk AND t.shipped BETWEEN vDated AND util.dayend(vDated); - + SELECT sum(IF(sv.physicalWeight = 0, sv.weight, sv.physicalWeight)) INTO vTheorycalWeight FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id @@ -74457,9 +71751,9 @@ BEGIN JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk WHERE t.clientFk = vClientFk AND t.shipped BETWEEN vDated AND util.dayend(vDated); - + SET vRatio = vRealWeight / vTheorycalWeight; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketWeight; CREATE TEMPORARY TABLE tmp.ticketWeight @@ -74480,7 +71774,7 @@ BEGIN AND t.shipped BETWEEN vDated AND util.dayend(vDated) GROUP BY ib.ediBotanic, o.code; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74599,18 +71893,18 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateAll`(vDatedFr BEGIN /** - * @param vDatedFrom Fecha desde + * @param vDatedFrom Fecha desde * @param vDatedTo Fecha hasta */ - CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` SELECT w.id userFk FROM vn.worker w; - + CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74630,21 +71924,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /** - * @param vDepartmentFk + * @param vDepartmentFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT DISTINCT b.workerFk userFk - FROM business AS b - WHERE (b.started BETWEEN vDatedFrom AND vDatedTo + FROM business AS b + WHERE (b.started BETWEEN vDatedFrom AND vDatedTo OR IFNULL(b.ended, vDatedTo) BETWEEN vDatedFrom AND vDatedTo OR (b.started <= vDatedFrom AND b.ended >= vDatedTo) ) AND b.departmentFk = vDepartmentFk ORDER BY b.ended DESC; - + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; @@ -74669,19 +71963,19 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByUser`(vUser BEGIN /** - * @param vUserFk + * @param vUserFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ - + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk - FROM account.user - WHERE id = vUserFk; + FROM account.user + WHERE id = vUserFk; CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); - + DROP TEMPORARY TABLE tmp.`user`; END ;; @@ -74708,14 +72002,14 @@ BEGIN * @param vDatedFrom Fecha desde * @param vDatedTo Fecha hasta */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` SELECT w.id userFk FROM worker w WHERE w.id = vWorkerFk; - + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); - + DROP TEMPORARY TABLE tmp.`user`; END ;; @@ -74725,32 +72019,32 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_calculate` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculate`( - vDatedFrom DATETIME, + vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /* * Agrupa por trabajador y día, el tiempo de trabajo y descanso retribuido(si tiene). * Los registros horarios incorrectos (tmp.timeControlError) no se considerarán. - * Si un trabajador ha trabajado más de un cierto umbral de tiempo (vTimeToBreakTime) - * y no ha tenido descansos que superen un parámetro determinado(vMaxTimeToBreak), + * Si un trabajador ha trabajado más de un cierto umbral de tiempo (vTimeToBreakTime) + * y no ha tenido descansos que superen un parámetro determinado(vMaxTimeToBreak), * se le añadirá un tiempo de descanso (vBreakTime) a sus horas trabajadas. * El tiempo de descanso solo se añade si el trabajador realmente disfrutó del descanso. * Si disfrutó de menos tiempo de descanso, solo se añade el tiempo que disfrutó. - * + * * @param vDatedFrom - * @param vDatedTo + * @param vDatedTo * - * @return tmp.timeControlCalculate + * @return tmp.timeControlCalculate * (workerFk, dated, timeWorkSeconds, timeWorkSexagesimal, timeWorkDecimal, timed) */ DECLARE vHourSeconds INTEGER; @@ -74882,7 +72176,7 @@ BEGIN ), accumulated AS ( SELECT SUM(IF(isOdd, 0, gapTime)) OVER (PARTITION BY userFk,dated ORDER BY userFk,timed) accumulatedWorkTime, - SUM(IF(NOT isOdd OR breakPoint, 0, IFNULL(gapTime, 0))) + SUM(IF(NOT isOdd OR breakPoint OR gapTime >= vMaxTimeToBreak OR gapTime IS NULL, 0, gapTime)) OVER (PARTITION BY realDay ORDER BY realDay,timed) accumulatedBreakTime, IF(realDay <> @oldrealDay OR (isOdd AND gapTime >= vMaxTimeToBreak), @accumulatedForBreakTime := 0, @@ -74897,7 +72191,7 @@ BEGIN SELECT userFk, dated, MAX(accumulatedWorkTime) + - IF(MAX(accumulatedForBreakTime) >= vTimeToBreakTime, + IF(MAX(accumulatedForBreakTime) + LEAST(vBreakTime, MAX(accumulatedBreakTime)) >= vTimeToBreakTime, LEAST(vBreakTime, MAX(accumulatedBreakTime)), 0) timeWorkSeconds FROM accumulated @@ -74949,14 +72243,14 @@ BEGIN * @param vDatedTo Fecha hasta */ - CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` SELECT w.id userFk FROM vn.worker w; - + CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74976,21 +72270,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /** - * @param vDepartmentFk + * @param vDepartmentFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT DISTINCT b.workerFk userFk - FROM business AS b - WHERE (b.started BETWEEN vDatedFrom AND vDatedTo + FROM business AS b + WHERE (b.started BETWEEN vDatedFrom AND vDatedTo OR IFNULL(b.ended, vDatedTo) BETWEEN vDatedFrom AND vDatedTo OR (b.started <= vDatedFrom AND b.ended >= vDatedTo) ) AND b.departmentFk = vDepartmentFk ORDER BY b.ended DESC; - + CALL timeControl_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; @@ -75015,19 +72309,19 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByUser`(vUserF BEGIN /** - * @param vUserFk + * @param vUserFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ - + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk - FROM account.user - WHERE id = vUserFk; + FROM account.user + WHERE id = vUserFk; CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); - + DROP TEMPORARY TABLE tmp.`user`; END ;; @@ -75085,12 +72379,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_getError`(vDatedFrom DA BEGIN /* * @param vDatedFrom - * @param vDatedTo + * @param vDatedTo * @table tmp.`user`(userFk) * Fichadas incorrectas de las cuales no se puede calcular horas trabajadas * @return tmp.timeControlError (id) */ - DECLARE vDayMaxTime INTEGER; + DECLARE vDayMaxTime INTEGER; SET @journeyCounter := 0; SET @lastUserFk := NULL; @@ -75098,16 +72392,16 @@ BEGIN SELECT dayMaxTime INTO vDayMaxTime FROM workerTimeControlConfig LIMIT 1; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; - CREATE TEMPORARY TABLE tmp.timeControl + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; + CREATE TEMPORARY TABLE tmp.timeControl (INDEX(id), INDEX(journeyCounter)) ENGINE = MEMORY SELECT sub.id, - sub.direction, + sub.direction, sub.timed, IF(sub.direction = 'in' OR @hasOut OR sub.userFk <> @lastUserFk, @journeyCounter := @journeyCounter + 1, @journeyCounter) journeyCounter, - @lastUserFk := sub.userFk workerFk, - IF(sub.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE) + @lastUserFk := sub.userFk workerFk, + IF(sub.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE) FROM ( SELECT DISTINCT wtc.id, wtc.direction, @@ -75118,36 +72412,36 @@ BEGIN WHERE wtc.timed BETWEEN DATE_SUB(vDatedFrom, INTERVAL 1 DAY) AND DATE_ADD(vDatedTo, INTERVAL 1 DAY) ORDER BY wtc.userFk, wtc.timed ) sub; - - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; CREATE TEMPORARY TABLE tmp.timeControlAux (INDEX(id), INDEX(journeyCounter)) ENGINE = MEMORY SELECT * FROM tmp.timeControl; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlError; - CREATE TEMPORARY TABLE tmp.timeControlError + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlError; + CREATE TEMPORARY TABLE tmp.timeControlError (INDEX(id)) ENGINE = MEMORY - SELECT id + SELECT id FROM tmp.timeControlAux tca JOIN ( - SELECT journeyCounter, + SELECT journeyCounter, UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork, - SUM(direction = 'in') totalIn, + SUM(direction = 'in') totalIn, SUM(direction = 'out') totalOut, timed FROM tmp.timeControl GROUP BY journeyCounter - HAVING COUNT(*) MOD 2 = 1 - OR totalIn <> 1 - OR totalOut <> 1 + HAVING COUNT(*) MOD 2 = 1 + OR totalIn <> 1 + OR totalOut <> 1 OR timeWork >= vDayMaxTime )sub ON sub.journeyCounter = tca.journeyCounter WHERE sub.timed BETWEEN vDatedFrom AND vDatedTo; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75170,7 +72464,7 @@ proc: BEGIN * deprecated call workerTimeControl_check */ CALL vn.workerTimeControl_check(vUserFk,vDated,vTabletFk); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75226,12 +72520,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travelVolume`(vTravelFk INT) BEGIN - - SELECT w1.name AS ORI, - w2.name AS DES, + + SELECT w1.name AS ORI, + w2.name AS DES, tr.shipped shipment, tr.landed landing, - a.name Agencia, + a.name Agencia, s.name Proveedor, e.id Id_Entrada, e.invoiceNumber Referencia, @@ -75239,18 +72533,18 @@ BEGIN vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) AS CC, CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) AS espais - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.travel tr ON tr.id = e.travelFk + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.travel tr ON tr.id = e.travelFk JOIN vn.agencyMode a ON a.id = tr.agencyModeFk - JOIN vn.warehouse w1 ON w1.id = tr.warehouseInFk - JOIN vn.warehouse w2 ON w2.id = tr.warehouseOutFk - JOIN vn.volumeConfig vc - JOIN vn.item i ON i.id = b.itemFk + JOIN vn.warehouse w1 ON w1.id = tr.warehouseInFk + JOIN vn.warehouse w2 ON w2.id = tr.warehouseOutFk + JOIN vn.volumeConfig vc + JOIN vn.item i ON i.id = b.itemFk JOIN vn.itemType it ON it.id = i.typeFk WHERE tr.id = vTravelFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75306,11 +72600,11 @@ BEGIN * @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 IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75374,7 +72668,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_checkWarehouseIsFeedStock`(v proc: BEGIN /* * Check that the warehouse is not Feed Stock - * + * * @vWarehouseFk param warehouse id */ IF vWarehouseFk IS NULL THEN @@ -75462,13 +72756,13 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_cloneWithEntries`( - IN vTravelFk INT, - IN vDateStart DATE, + IN vTravelFk INT, + IN vDateStart DATE, IN vDateEnd DATE, IN vWarehouseOutFk INT, - IN vWarehouseInFk INT, - IN vRef VARCHAR(255), - IN vAgencyModeFk INT, + IN vWarehouseInFk INT, + IN vRef VARCHAR(255), + IN vAgencyModeFk INT, OUT vNewTravelFk INT) BEGIN /** @@ -75492,29 +72786,29 @@ BEGIN FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.travelFk = vTravelFk; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN + BEGIN ROLLBACK; RESIGNAL; END; - + START TRANSACTION; INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk FROM travel WHERE id = vTravelFk; - + SET vNewTravelFk = LAST_INSERT_ID(); SET vDone = FALSE; SET @isModeInventory = TRUE; OPEN vRsEntry; - + l: LOOP SET vDone = FALSE; FETCH vRsEntry INTO vAuxEntryFk; @@ -75556,36 +72850,36 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_doRecalc`() -proc: BEGIN -/** -* Recounts the number of entries of changed travels. -*/ - DECLARE vTravelFk INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('vn.ticket_doRecalc'); - END; - - IF !GET_LOCK('vn.travel_doRecalc', 0) THEN - LEAVE proc; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tTravel - ENGINE = MEMORY - SELECT travelFk FROM travelRecalc; - - UPDATE travel t - JOIN tTravel tt ON tt.travelFk = t.id - SET t.totalEntries = ( - SELECT COUNT(e.id) - FROM entry e - WHERE e.travelFk = t.id - ); - - DELETE tr FROM travelRecalc tr JOIN tTravel t ON tr.travelFk = t.travelFk; - DROP TEMPORARY TABLE tTravel; - DO RELEASE_LOCK('vn.travel_doRecalc'); +proc: BEGIN +/** +* Recounts the number of entries of changed travels. +*/ + DECLARE vTravelFk INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.ticket_doRecalc'); + END; + + IF !GET_LOCK('vn.travel_doRecalc', 0) THEN + LEAVE proc; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tTravel + ENGINE = MEMORY + SELECT travelFk FROM travelRecalc; + + UPDATE travel t + JOIN tTravel tt ON tt.travelFk = t.id + SET t.totalEntries = ( + SELECT COUNT(e.id) + FROM entry e + WHERE e.travelFk = t.id + ); + + DELETE tr FROM travelRecalc tr JOIN tTravel t ON tr.travelFk = t.travelFk; + DROP TEMPORARY TABLE tTravel; + DO RELEASE_LOCK('vn.travel_doRecalc'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75612,10 +72906,10 @@ BEGIN WHERE id = vSelf; SELECT e.id entryFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - JOIN buy b ON b.entryFk = e.id - WHERE t.id = vTravelFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + JOIN buy b ON b.entryFk = e.id + WHERE t.id = vTravelFk AND (b.packing IS NULL OR b.packagingFk IS NULL); END ;; DELIMITER ; @@ -75638,7 +72932,7 @@ BEGIN /* * Desplaza al dia siguiente los travels que contengan redadas y avisa a los compradores - * + * */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vWorkerName VARCHAR(50); @@ -75650,7 +72944,7 @@ BEGIN SELECT GROUP_CONCAT( DISTINCT CONCAT('https://salix.verdnatura.es/#!/travel/', ttr.id, '/summary ') ORDER BY ttr.id SEPARATOR '\n\r'), u.name FROM tmp.travel ttr - JOIN entry e ON e.travelFk = ttr.id + JOIN entry e ON e.travelFk = ttr.id JOIN buy b ON b.entryFk = e.id JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk @@ -75658,19 +72952,19 @@ BEGIN GROUP BY u.name; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; - + DROP TEMPORARY TABLE IF EXISTS tmp.travel; CREATE TEMPORARY TABLE tmp.travel SELECT tr.id,tr.landed FROM travel tr - JOIN entry e ON e.travelFk = tr.id + JOIN entry e ON e.travelFk = tr.id WHERE tr.landed = util.tomorrow() AND e.isRaid GROUP BY tr.id; @@ -75728,7 +73022,7 @@ proc: BEGIN IF vSelf IS NULL THEN LEAVE proc; END IF; - + INSERT IGNORE INTO travelRecalc SET travelFk = vSelf; END ;; DELIMITER ; @@ -75738,6 +73032,100 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `travel_upcomingArrivals` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_upcomingArrivals`( + vWarehouseFk INT, + vDate DATETIME +) +BEGIN +/** + * Procedure to track and organize the movement of items between warehouses, + * where 'warehouseINFk' is @vWarehouseFk. + * Uses temporary tables to process and store the travel data of the items. + * + * @params vWarehouseFk warehouse id + * @params vDate selected landed date + * @return tmp.itemTravel + */ + DECLARE vTravelFk INT; + DECLARE vWarehouseOutFk INT; + DECLARE vShipment DATETIME; + DECLARE vDateStart DATETIME; + + CREATE OR REPLACE TEMPORARY TABLE tTravelTop + (PRIMARY KEY (wh_in,wh_out,landing,shipment)) + ENGINE = MEMORY + SELECT 0 id, + vWarehouseFk wh_in, + vWarehouseFk wh_out, + FALSE ok, + vDate landing, + vDate shipment; + + REPEAT + SET vTravelFk = NULL; + + SELECT id, + wh_out, + shipment, + landing + INTO vTravelFk, + vWarehouseOutFk, + vShipment, + vDateStart + FROM tTravelTop + WHERE ok = FALSE LIMIT 1; + + UPDATE tTravelTop + SET ok = TRUE + WHERE id = vTravelFk; + + INSERT IGNORE INTO tTravelTop + SELECT id, + vWarehouseFk, + warehouseOutFk, + FALSE, + IF(vTravelFk, vDateStart, landed), + shipped shipment + FROM travel + WHERE warehouseOutFk = vWarehouseOutFk + AND IF(vTravelFk, landed <= vShipment, landed >= vShipment) + AND shipped >= util.VN_CURDATE() + AND NOT isDelivered; + UNTIL vTravelFk IS NULL END REPEAT; + + DELETE FROM tTravelTop WHERE id = 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemTravel + (KEY (wh)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT wh_out wh, + landing + FROM tTravelTop + WHERE wh_out <> vWarehouseFk + ORDER BY landing + LIMIT 10000000000000000000 + ) t + GROUP BY wh; + + DROP TEMPORARY TABLE tTravelTop; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_updatePacking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75754,10 +73142,10 @@ BEGIN * @param vItemFk id del item * @param vPacking nuevo packing */ - + DECLARE vAuctionWarehouseFk INT; DECLARE vMainWarehouseFk INT; - + SELECT warehouseFk INTO vAuctionWarehouseFk FROM auctionConfig; @@ -75817,7 +73205,7 @@ BEGIN FROM travelClonedWeekly WHERE travelFk; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; SET vCounter = vSinceWeek; @@ -75879,12 +73267,12 @@ BEGIN /* * Plantilla para modificar reemplazar todos los tags * por los valores que tienen los articulos - * + * * @param vTypeFk tipo a modificar - * + * */ - DELETE it.* - FROM itemTag it + DELETE it.* + FROM itemTag it JOIN item i ON i.id = it.itemFk WHERE i.typeFk = vTypeFk; @@ -75893,40 +73281,40 @@ BEGIN FROM item i JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci WHERE i.typeFk = vTypeFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, i.category, 5 FROM item i JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci WHERE i.typeFk = vTypeFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, ink.name, 2 FROM item i JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci JOIN ink ON ink.id = i.inkFk WHERE i.typeFk = vTypeFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, p.name, 3 FROM item i JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci JOIN producer p ON p.id = i.producerFk - WHERE i.typeFk = vTypeFk; - + WHERE i.typeFk = vTypeFk; + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, o.name, 4 FROM item i JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci JOIN origin o ON o.id = i.originFk WHERE i.typeFk = vTypeFk; - /* + /* INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, i.stems, 6 FROM item i JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci - WHERE i.typeFk = vTypeFk; - */ + WHERE i.typeFk = vTypeFk; + */ -- CALL itemTagArrangedUpdate(NULL); END ;; @@ -75949,7 +73337,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `updatePedidosInternos`(vItemFk INT) BEGIN UPDATE vn.item SET upToDown = 0 WHERE item.id = vItemFk; - + END ;; DELIMITER ; @@ -75977,7 +73365,7 @@ BEGIN SELECT vp.regex INTO vRegex FROM vehiclePlateRegex vp WHERE vp.countryCodeFk = vCountryCodeFk; - + IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN CALL util.throw(CONCAT('Error: la matricula ', vNumberPlate, ' no es valida para ',vCountryCodeFk)); END IF; @@ -76010,7 +73398,7 @@ proc:BEGIN ROLLBACK; RESIGNAL; END; - + SELECT eventEarlyDays INTO vEventEarlyDays FROM vehicleConfig; @@ -76028,7 +73416,7 @@ proc:BEGIN IF NOT vHasEvents THEN LEAVE proc; END IF; - + START TRANSACTION; SELECT util.notification_send('vehicle-event-expired', @@ -76063,21 +73451,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_getMisfit`(vSectorFk INT) BEGIN - + /* Devuelve una tabla temporal con los descuadres entre el visible teórico y lo ubicado en la práctica - * + * * @param vSectorFk Identificador de vn.sector - * + * * @return tmp.stockMisfit(itemFk, visible, parked) */ - + DECLARE vCalcVisibleFk INT; DECLARE vWarehouseFk INT; SELECT warehouseFk INTO vWarehouseFk - FROM vn.sector s + FROM vn.sector s WHERE s.id = vSectorFk; - + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, vWarehouseFk); DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; @@ -76090,17 +73478,17 @@ BEGIN INSERT INTO tmp.stockMisfit(itemFk, parked) SELECT iss.itemFk , sum(iss.visible ) - FROM vn.itemShelvingStock iss - JOIN vn.sector s ON s.id = iss.sectorFk + FROM vn.itemShelvingStock iss + JOIN vn.sector s ON s.id = iss.sectorFk WHERE vSectorFk IN (s.id, s.sonFk) GROUP BY iss.itemFk; - + INSERT INTO tmp.stockMisfit(itemFk, visible) - SELECT v.item_id , v.visible - FROM cache.visible v - WHERE v.calc_id = vCalcVisibleFk + SELECT v.item_id , v.visible + FROM cache.visible v + WHERE v.calc_id = vCalcVisibleFk ON DUPLICATE KEY UPDATE visible = v.visible; - + DELETE FROM tmp.stockMisfit WHERE visible = parked; @@ -76124,17 +73512,17 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `warehouseFitting`(IN vWhOrigin INT BEGIN DECLARE vCacheVisibleOriginFk INT; DECLARE vCacheVisibleDestinyFk INT; - + CALL cache.visible_refresh(vCacheVisibleOriginFk, FALSE, vWhOrigin); CALL cache.visible_refresh(vCacheVisibleDestinyFk, FALSE, vWhDestiny); - + SELECT i.id itemFk, i.longName, i.size, i.subName, vOrigin.visible AS Origen, vDestiny.visible Destino - + FROM vn.item i JOIN vn.itemType it ON it.id = i.typeFk LEFT JOIN cache.visible vOrigin ON vOrigin.calc_id = vCacheVisibleOriginFk AND vOrigin.item_id = i.id @@ -76163,13 +73551,13 @@ BEGIN DECLARE vWhOrigin INT; DECLARE vWhDestiny INT; - + SELECT warehouseInFk, warehouseOutFk INTO vWhDestiny, vWhOrigin FROM vn.travel WHERE id = vTravelFk; - + CALL vn.warehouseFitting(vWhOrigin, vWhDestiny); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76233,7 +73621,7 @@ BEGIN * Calcula los días y horas de vacaciones en función de un contrato y año * * @param vYear - * @param vBusinessFk + * @param vBusinessFk * @return tmp.workerCalendarCalculateBusiness (days, hours, daysEnjoyed, hoursEnjoyed) */ DECLARE vStarted DATE; @@ -76245,17 +73633,17 @@ BEGIN DECLARE vPayedHolidays DECIMAL(5,2); DECLARE vDifDays INT; - SELECT IF(b.started < CONCAT(vYear,"-01-01"), CONCAT(vYear,"-01-01"),b.started), - IF(b.ended IS NULL OR YEAR(b.ended)>vYear , CONCAT(vYear,"-12-31"), b.ended), + SELECT IF(b.started < CONCAT(vYear,"-01-01"), CONCAT(vYear,"-01-01"),b.started), + IF(b.ended IS NULL OR YEAR(b.ended)>vYear , CONCAT(vYear,"-12-31"), b.ended), IF(wbt.hasHolidayEntitlement, w.days, 0), c.hoursWeek, IF(YEAR(b.ended) = vYear, b.payedHolidays, 0) payedHolidays - INTO vStarted, - vEnded, - vDaysHoliday, + INTO vStarted, + vEnded, + vDaysHoliday, vHoursWeek, vPayedHolidays - FROM business b + FROM business b JOIN workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk JOIN workCenterHoliday w ON w.workcenterFk = b.workcenterFk LEFT JOIN calendarType c ON c.id = b.calendarTypeFk @@ -76263,23 +73651,23 @@ BEGIN AND w.year = vYear; DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateBusiness; - + IF vStarted < vEnded THEN SET vDifDays = DAYOFYEAR(vEnded) - DAYOFYEAR(vStarted) + 1; - SELECT IFNULL(SUM(a.holidayEntitlementRate), 0), + SELECT IFNULL(SUM(a.holidayEntitlementRate), 0), SUM(-(a.discountRate - 1)) + vPayedHolidays - INTO vDaysToSubtract, - vDaysHolidayEnjoyed + INTO vDaysToSubtract, + vDaysHolidayEnjoyed FROM calendar c JOIN absenceType a ON a.id = c.dayOffTypeFk JOIN business b ON b.id = c.businessFk - WHERE b.id = vBusinessFk + WHERE b.id = vBusinessFk AND YEAR(c.dated) = vYear; END IF; - CREATE TEMPORARY TABLE tmp.workerCalendarCalculateBusiness + CREATE TEMPORARY TABLE tmp.workerCalendarCalculateBusiness ENGINE = MEMORY SELECT @days := IFNULL(ROUND((vDaysHoliday * (vDifDays - vDaysToSubtract) / IF(util.isLeapYear(vYear) , 366, 365)), 1), 0) days, @days * (vHoursWeek / 5) hours, @@ -76307,32 +73695,32 @@ BEGIN /** * Calcula los días y horas de vacaciones en función de un trabajador y año * - * @param vYear - * @param vWorkerFk + * @param vYear + * @param vWorkerFk * @return tmp.workerCalendarCalculateYear (days, hours, daysEnjoyed, hoursEnjoyed) - */ + */ DECLARE vDone BOOL; DECLARE vBusinessFk INT; DECLARE cur CURSOR FOR - SELECT b.id + SELECT b.id FROM business b - WHERE vYear BETWEEN YEAR(b.started) AND IFNULL(YEAR(b.ended), vYear) + WHERE vYear BETWEEN YEAR(b.started) AND IFNULL(YEAR(b.ended), vYear) AND b.workerFk = vWorkerFk; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - + SET vDone = TRUE; + DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateYear; CREATE TEMPORARY TABLE tmp.workerCalendarCalculateYear - (days DEC(5,2), + (days DEC(5,2), hours DEC(5,2), - daysEnjoyed DEC(5,2), - hoursEnjoyed DEC(5,2)) + daysEnjoyed DEC(5,2), + hoursEnjoyed DEC(5,2)) ENGINE = MEMORY; INSERT INTO tmp.workerCalendarCalculateYear VALUES(0, 0, 0, 0); - + OPEN cur; l: LOOP @@ -76345,12 +73733,12 @@ BEGIN CALL workerCalendar_calculateBusiness(vYear, vBusinessFk); UPDATE tmp.workerCalendarCalculateYear w - JOIN tmp.workerCalendarCalculateBusiness wc + JOIN tmp.workerCalendarCalculateBusiness wc SET w.days = w.days + wc.days, w.hours = w.hours + wc.hours, w.daysEnjoyed = w.daysEnjoyed + wc.daysEnjoyed, w.hoursEnjoyed = w.hoursEnjoyed + wc.hoursEnjoyed; - + DROP TEMPORARY TABLE tmp.workerCalendarCalculateBusiness; END LOOP; @@ -76421,20 +73809,20 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.workerDepartmentByDate; CREATE TEMPORARY TABLE tmp.workerDepartmentByDate ENGINE = MEMORY - SELECT w.id userFk, - w.lastName name, - w.firstName firstname, - d.name department, + SELECT w.id userFk, + w.lastName name, + w.firstName firstname, + d.name department, d.id departmentFk, - b.started, - d.isProduction, + b.started, + d.isProduction, CAST(12 * b.amount / ct.hoursWeek / 52 AS DECIMAL(10,2)) costeHora, w.fi nif FROM business b JOIN calendarType ct ON ct.id = b.calendarTypeFk JOIN department d ON d.id = b.departmentFk JOIN worker w ON w.id = b.workerFk - WHERE b.started <= vDate + WHERE b.started <= vDate AND (b.ended > vDate OR b.ended IS NULL); END ;; DELIMITER ; @@ -76458,21 +73846,26 @@ mainLabel:BEGIN IF (SELECT COUNT(*) FROM workerDisableExcluded WHERE workerFk = vUserId AND (dated > util.VN_CURDATE() OR dated IS NULL)) > 0 THEN LEAVE mainLabel; END IF; + + DELETE cp FROM clientProtected cp + JOIN client c ON c.id = cp.clientFk + WHERE c.salesPersonFk = vUserId; + DELETE FROM account.account WHERE id = vUserId; - UPDATE account.user + UPDATE account.user SET role = 2 - WHERE id = vUserId; + WHERE id = vUserId; - DELETE FROM pbx.sip - WHERE user_id = vUserId; + DELETE FROM pbx.sip + WHERE user_id = vUserId; UPDATE `client` c JOIN payMethod p ON p.name = 'CONTADO' SET c.credit = 0, c.payMethodFk = p.id, hasCoreVnl = FALSE WHERE c.id = vUserId; - + UPDATE `client` c SET c.salesPersonFk = null WHERE c.salesPersonFk = vUserId; @@ -76501,12 +73894,12 @@ BEGIN SELECT b.workerFk FROM business b JOIN vn.worker w ON w.id = b.workerFk - JOIN account.account a ON a.id = b.workerFk - LEFT JOIN (SELECT b.workerFk + JOIN account.account a ON a.id = b.workerFk + LEFT JOIN (SELECT b.workerFk FROM business b WHERE (ended IS NULL OR ended >=util.VN_CURDATE()) )sub ON sub.workerFk = a.id - LEFT JOIN vn.workerDisableExcluded wd ON wd.workerFk = b.workerFk + LEFT JOIN vn.workerDisableExcluded wd ON wd.workerFk = b.workerFk WHERE sub.workerFk IS NULL AND wd.workerFk IS NULL GROUP BY w.id; @@ -76524,7 +73917,7 @@ BEGIN END WHILE; CLOSE rs; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76588,19 +73981,19 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace`( - vDatedFrom DATE, - vDatedTo DATE, + vDatedFrom DATE, + vDatedTo DATE, vWorkerFk INT) BEGIN /** - * Actualiza la tabla workerJourney para que actue como caché permanente revisable + * Actualiza la tabla workerJourney para que actue como caché permanente revisable * de las jornadas laborales. * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl * @param vWorkerFk, en caso de pasar 0 ó NULL se aplica a todos - */ + */ DECLARE vDatedTimeTo DATETIME; - DECLARE vMaxTimePerDay INT; + DECLARE vMaxTimePerDay INT; DECLARE vMinHoursToBreak DECIMAL(10,2); DECLARE vBreakHours DECIMAL(10,2); DECLARE vMonthByYear INT; @@ -76608,57 +74001,57 @@ BEGIN DECLARE vMonthsByYear INT DEFAULT 12; DECLARE vDaysByWeek INT DEFAULT 5; DECLARE vDatedFromYesterday DATETIME; - DECLARE vDatedToTomorrow DATETIME; - - SELECT DATE_SUB(vDatedFrom, INTERVAL 1 DAY), DATE_ADD(vDatedTo, INTERVAL 1 DAY) + DECLARE vDatedToTomorrow DATETIME; + + SELECT DATE_SUB(vDatedFrom, INTERVAL 1 DAY), DATE_ADD(vDatedTo, INTERVAL 1 DAY) INTO vDatedFromYesterday, vDatedToTomorrow; SET vDatedTimeTo = util.dayEnd(vDatedTo); - - SELECT minHoursToBreak, breakHours, maxTimePerDay + + SELECT minHoursToBreak, breakHours, maxTimePerDay INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay FROM workerTimeControlConfig; DELETE FROM workerJourney - WHERE dated BETWEEN vDatedFrom AND vDatedTo + WHERE dated BETWEEN vDatedFrom AND vDatedTo AND NOT isPaid AND NOT isUpdated - AND (vWorkerFk IS NULL OR userFK = vWorkerFk); + AND (vWorkerFk IS NULL OR userFK = vWorkerFk); - -- Se inserta todos los días del periodo por worker y business en el rango de fechas. + -- Se inserta todos los días del periodo por worker y business en el rango de fechas. INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) SELECT b.workerFk, t.dated, b.id - FROM business b + FROM business b JOIN time t ON t.dated BETWEEN b.started AND IFNULL(b.ended,util.VN_CURDATE()) WHERE t.dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR b.workerFk = vWorkerFk) ORDER BY b.workerFk, t.dated, b.id; - + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; IF vWorkerFk THEN CALL timeControl_calculateByUser(vWorkerFk, vDatedFrom , vDatedTimeTo); - CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` - SELECT vWorkerFk userFk; + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` + SELECT vWorkerFk userFk; ELSE CALL timeControl_calculateAll(vDatedFrom, vDatedTimeTo); - CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT id userFk FROM worker w; - END IF; + END IF; UPDATE workerJourney wj JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk - SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, - t.timeWorkDecimal - vBreakHours, + SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, + t.timeWorkDecimal - vBreakHours, t.timeWorkDecimal) AS DECIMAL (10,2)), wj.lunch = IF(t.timeWorkDecimal >= vMinHoursToBreak , vBreakHours , 0) WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo AND NOT wj.isPaid AND NOT wj.isUpdated AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk); - - -- NOCTURNIDAD + + -- NOCTURNIDAD CALL timeControl_getError(vDatedFrom, vDatedTimeTo); SET @vIsOdd := TRUE; @@ -76668,9 +74061,9 @@ BEGIN CREATE TEMPORARY TABLE tmp.workerTimeControl (INDEX (userFk), INDEX (timed)) ENGINE = MEMORY - SELECT DISTINCT(wtc.id), - wtc.userFk, - wtc.timed, + SELECT DISTINCT(wtc.id), + wtc.userFk, + wtc.timed, wtc.direction FROM workerTimeControl wtc JOIN tmp.`user` w ON w.userFk = wtc.userFk @@ -76680,10 +74073,10 @@ BEGIN AND (vWorkerFk IS NULL OR wtc.userFk = vWorkerFk) ORDER BY wtc.userFk, wtc.timed ASC; - SELECT MAX(id) INTO @vCont + SELECT MAX(id) INTO @vCont FROM tmp.workerTimeControl; - DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlAux; + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlAux; CREATE TEMPORARY TABLE tmp.workerTimeControlAux ( `id` int(11) , `userFk` int(10) unsigned , @@ -76705,9 +74098,9 @@ BEGIN DATE(@lastTimed) dated, @lastUserFk lastUserFk, IF(direction ='middle', @vIsOdd := NOT @vIsOdd, FALSE) isOdd, - IF(@vIsOdd - AND @lastDirection = 'middle' - AND (DATE(@lastTimed) <> date(timed) + IF(@vIsOdd + AND @lastDirection = 'middle' + AND (DATE(@lastTimed) <> date(timed) OR @lastUserFk <> userFk), TRUE, FALSE) hasBreak, @lastTimed := wtc.timed, @lastUserFk := userFk, @@ -76721,16 +74114,16 @@ BEGIN SET @lastDirection := NULL; INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) - SELECT @vCont:= @vCont + 1, - lastUserFk, - DATE_ADD(sub.dated, INTERVAL 1 DAY), + SELECT @vCont:= @vCont + 1, + lastUserFk, + DATE_ADD(sub.dated, INTERVAL 1 DAY), 'middle' FROM (SELECT IF(@lastUserFk <> userFk, @vIsOdd := TRUE, NULL), DATE(@lastTimed) dated, @lastUserFk lastUserFk, IF(direction ='middle', @vIsOdd := NOT @vIsOdd, FALSE) isOdd, - IF(@vIsOdd - AND @lastDirection = 'middle' + IF(@vIsOdd + AND @lastDirection = 'middle' AND (DATE(@lastTimed)<>date(timed) OR @lastUserFk<>userFk), TRUE, FALSE) hasBreak, @lastTimed := wtc.timed, @@ -76743,7 +74136,7 @@ BEGIN -- Cambio de dia INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) SELECT @vCont:= @vCont + 1, - wtc.userFk, + wtc.userFk, util.dayEnd(date(wtc.timed)), 'out' FROM workerTimeControl wtc @@ -76754,8 +74147,8 @@ BEGIN GROUP BY wtc.userFk, DATE(wtc.timed); INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) - SELECT @vCont:= @vCont + 1, - wtc.userFk, + SELECT @vCont:= @vCont + 1, + wtc.userFk, DATE_ADD(date(wtc.timed), INTERVAL 1 DAY), 'in' FROM workerTimeControl wtc @@ -76781,8 +74174,8 @@ BEGIN IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed), IF(direction='in', @vDated := DATE(wtc.timed), @vDated ) dated, wtc.userFk, - IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay, - workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed), + IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay, + workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed), 0) NigthlyHours, @lastUserFk := userFk FROM (SELECT DISTINCT(wtc.id), wtc.userFk, wtc.timed, wtc.direction @@ -76795,7 +74188,7 @@ BEGIN ) wtc ORDER BY wtc.userFk, wtc.timed )sub - WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo + WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo GROUP BY userFk, sub.dated )night ON night.userFk = wj.userFk AND night.dated = wj.dated SET wj.nocturn = night.NigthlyHours @@ -76807,8 +74200,8 @@ BEGIN UPDATE workerJourney wj JOIN business b ON b.id = wj.businessFk JOIN calendarType ct ON ct.id = b.calendarTypeFk - SET wj.priceOrdinaryHour = - (vMonthsByYear * b.amount) / + SET wj.priceOrdinaryHour = + (vMonthsByYear * b.amount) / (vWeeksByYear * ct.hoursWeek), wj.contractJourney = ct.hoursWeek / vDaysByWeek WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo @@ -76816,7 +74209,7 @@ BEGIN AND NOT wj.isPaid AND NOT isUpdated; - -- Precio Extras, Vacaciones y Nocturnas + -- Precio Extras, Vacaciones y Nocturnas UPDATE workerJourney wj JOIN(SELECT MAX(w.dated), t.dated, w.holidayInc, w.nightInc, w.extraInc FROM time t @@ -76840,12 +74233,12 @@ BEGIN WHERE ct.isPartial AND wj.dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid + AND NOT wj.isPaid AND NOT wj.isUpdated; -- Ausencias UPDATE workerJourney wj - JOIN businessCalendar bc ON bc.businessFk = wj.businessFk + JOIN businessCalendar bc ON bc.businessFk = wj.businessFk AND bc.dated = wj.dated JOIN absenceType ab ON ab.id = bc.absenceTypeFk SET wj.permission = ab.permissionRate * wj.contractJourney, @@ -76860,7 +74253,7 @@ BEGIN UPDATE workerJourney SET holiday = IF(DAYNAME(dated)='sábado', 0, total), contractJourney = 0 - WHERE DAYNAME(dated) IN ('sábado', 'domingo') + WHERE DAYNAME(dated) IN ('sábado', 'domingo') AND dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR userFk = vWorkerFk) AND NOT isPaid @@ -76869,8 +74262,8 @@ BEGIN -- Festivos por centro de trabajo UPDATE workerJourney wj JOIN calendarHolidays ch ON ch.dated = wj.dated - JOIN business b ON b.id = wj.businessFk - AND b.workcenterFk = ch.workcenterFk + JOIN business b ON b.id = wj.businessFk + AND b.workcenterFk = ch.workcenterFk SET wj.holiday = wj.total, wj.permission = wj.contractJourney, wj.contractJourney = 0 @@ -76880,7 +74273,7 @@ BEGIN AND NOT wj.isUpdated; -- Horas extras - UPDATE workerJourney + UPDATE workerJourney SET extra = lunch + total - contractJourney WHERE dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR userFk = vWorkerFk) @@ -76910,15 +74303,15 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerMistakeType_get`() BEGIN - + /** * Obtiene los tipos de error para los trabajadores */ - - SELECT code, description - FROM workerMistakeType + + SELECT code, description + FROM workerMistakeType ORDER BY description; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76945,7 +74338,7 @@ BEGIN * */ INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk) - VALUES(vWorkerFk, vWorkerMistakeTypeFk); + VALUES(vWorkerFk, vWorkerMistakeTypeFk); END ;; DELIMITER ; @@ -76968,11 +74361,11 @@ BEGIN /*INSERT INTO workerTimeControl(userFk, timed, manual, warehouseFk) VALUES(vUserFk, vDated, FALSE, vWarehouseFk); - + CALL vn.workerTimeControlSOWP(vUserFk , vDated);*/ - + CALL vn.workerTimeControl_add(vUserFk,vWarehouseFk,util.VN_NOW(),FALSE); - + END ;; DELIMITER ; @@ -76998,8 +74391,8 @@ BEGIN * */ - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -77048,13 +74441,13 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlSOWP`(IN vUserFk INT, IN vDated DATE) BEGIN SET @order := 0; - - UPDATE workerTimeControl - SET `order` = @order := @order + 1 - WHERE vUserFk =userFk + + UPDATE workerTimeControl + SET `order` = @order := @order + 1 + WHERE vUserFk =userFk AND vDated = DATE(timed) ORDER BY timed; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -77073,8 +74466,8 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) BEGIN - - + + SELECT workerTimeControl_add(vUserFk,vWarehouseFk,vTimed,vIsManual); END ;; DELIMITER ; @@ -77162,73 +74555,73 @@ proc: BEGIN DECLARE vTo VARCHAR(50) DEFAULT NULL; DECLARE vUserName VARCHAR(50) DEFAULT NULL; DECLARE vBody VARCHAR(255) DEFAULT NULL; - - SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax + + SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax FROM workerTimeControlParams; SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk + FROM workerTimeControl + WHERE userFk = vUserFk AND direction = 'in'; - + SELECT MAX(timed) INTO vLastOut - FROM workerTimeControl - WHERE userFk = vUserFk - AND direction = 'out'; + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'out'; SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo FROM account.user u - WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); - + WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); + SELECT CONCAT(firstName,' ',lastName) INTO vUserName FROM worker w WHERE w.id = vUserFk; IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA - - -- VERIFICAR DESCANSO DIARIO - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN + + -- VERIFICAR DESCANSO DIARIO + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN SELECT "Descansos 12 h" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 12 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; - END IF; - + END IF; + -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ - IF (SELECT MOD(COUNT(*),2) -- <>0 - FROM workerTimeControl + IF (SELECT MOD(COUNT(*),2) -- <>0 + FROM workerTimeControl WHERE userFk = vUserFk AND timed >= vLastIn - ) THEN + ) THEN SELECT "Dias con fichadas impares" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; - + -- VERIFICAR VACACIONES SELECT at2.name INTO vCalendarStateType - FROM calendar c + FROM calendar c JOIN business b ON b.id = c.businessFk JOIN absenceType at2 ON at2.id = c.dayOffTypeFk WHERE c.dated = util.VN_CURDATE() AND at2.isAllowedToWork = FALSE AND b.workerFk = vUserFk LIMIT 1; - + IF(LENGTH(vCalendarStateType)) THEN SELECT vCalendarStateType AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - + LEAVE proc; + END IF; - + -- VERIFICAR CONTRATO EN VIGOR IF (SELECT COUNT(*) FROM business b @@ -77240,44 +74633,44 @@ proc: BEGIN -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - + LEAVE proc; + END IF; -- VERIFICAR DESCANSO SEMANAL SET @vHasBreakWeek:= FALSE; - SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); - + SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); + DROP TEMPORARY TABLE IF EXISTS tmp.trash; CREATE TEMPORARY TABLE tmp.trash SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, @vLastTimed:= UNIX_TIMESTAMP(timed) - FROM workerTimeControl + FROM workerTimeControl WHERE timed>= (util.VN_NOW() - INTERVAL vWeekScope SECOND) AND userFk= vUserFk AND direction IN ('in','out') - ORDER BY timed ASC; - - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA + ORDER BY timed ASC; + + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA SELECT "Descansos 36 h" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 36 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; END IF; + + DROP TEMPORARY TABLE tmp.trash; - DROP TEMPORARY TABLE tmp.trash; - - ELSE -- DIA ACTUAL - + ELSE -- DIA ACTUAL + -- VERIFICA QUE EL TIEMPO EFECTIVO NO SUPERE EL MÁXIMO - SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked + SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked FROM workerTimeControl wtc - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND timed >= vLastIn ORDER BY timed; - IF vTimedWorked > vDayWorkMax THEN + IF vTimedWorked > vDayWorkMax THEN SELECT "Jornadas" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Jornadas") INTO vBody; @@ -77300,10 +74693,10 @@ proc: BEGIN -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; END IF;*/ - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -77323,7 +74716,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_checkBreak`(vStarted DATE) BEGIN /** - * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas * El sistema verificará el descanso corto en la siguiente semana * o el largo en las 2 siguientes semanas a partir de la fecha dada * @param vStarted día inicio de la semana en el que se quiere verificar @@ -77334,27 +74727,27 @@ BEGIN DECLARE vShortWeekBreak INT; DECLARE vLongWeekBreak INT; - SELECT util.dayEnd(DATE_ADD(vStarted, INTERVAL shortWeekDays DAY)), + SELECT util.dayEnd(DATE_ADD(vStarted, INTERVAL shortWeekDays DAY)), util.dayEnd(DATE_ADD(vStarted, INTERVAL longWeekDays DAY)), - shortWeekBreak, + shortWeekBreak, longWeekBreak INTO vShortEnded, vLongEnded, vShortWeekBreak, vLongWeekBreak FROM workerTimeControlConfig; - + SET @previousTimed:= UNIX_TIMESTAMP(vStarted); SET @lastUserFk := NULL; - + -- Descanso corto en la semana - + DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY(workerFk)) ENGINE = MEMORY SELECT DISTINCT userFk workerFk - FROM workerTimeControl + FROM workerTimeControl WHERE timed BETWEEN vStarted AND vShortEnded AND direction IN ('in', 'out'); - + DROP TEMPORARY TABLE IF EXISTS tmp.worker2; CREATE TEMPORARY TABLE tmp.worker2 (PRIMARY KEY(workerFk)) @@ -77367,28 +74760,28 @@ BEGIN SELECT sub2.userFk workerFk FROM(SELECT sub.userFk, IF(sub.userFk <> @lastUserFk, - @previousTimed:= sub.timed, + @previousTimed:= sub.timed, FALSE), - IF(sub.timed - @previousTimed >= vShortWeekBreak, - TRUE, + IF(sub.timed - @previousTimed >= vShortWeekBreak, + TRUE, FALSE) hasShortWeekBreak, @previousTimed:= sub.timed, @lastUserFk:= sub.userFk FROM ( SELECT userFk, UNIX_TIMESTAMP(timed) timed - FROM workerTimeControl + FROM workerTimeControl WHERE timed BETWEEN vStarted AND vShortEnded AND direction IN ('in', 'out') - UNION + UNION SELECT w.workerFk, UNIX_TIMESTAMP(IFNULL( - MIN(wtc.timed), + MIN(wtc.timed), DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND))) FROM tmp.worker w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND wtc.timed BETWEEN vShortEnded - AND DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN vShortEnded + AND DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND) GROUP BY w.workerFk UNION SELECT w.workerFk, @@ -77396,10 +74789,10 @@ BEGIN MAX(wtc.timed), DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND))) FROM tmp.worker2 w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND wtc.timed BETWEEN - DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN + DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND) AND vStarted GROUP BY w.workerFk ORDER BY userFk, timed @@ -77409,7 +74802,7 @@ BEGIN GROUP BY sub2.userFk HAVING NOT SUM(hasShortWeekBreak); - -- Descanso largo en las 2 siguientes semanas + -- Descanso largo en las 2 siguientes semanas DROP TEMPORARY TABLE tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY(workerFk)) @@ -77429,12 +74822,12 @@ BEGIN (PRIMARY KEY(workerFk)) ENGINE = MEMORY SELECT sub2.userFk workerFk - FROM(SELECT userFk, + FROM(SELECT userFk, IF(userFk <> @lastUserFk, - @previousTimed:= timed, + @previousTimed:= timed, TRUE), - IF(timed - @previousTimed >= vLongWeekBreak, - TRUE, + IF(timed - @previousTimed >= vLongWeekBreak, + TRUE, FALSE) hasLongWeekBreak, @previousTimed:= timed, @lastUserFk:= userFk @@ -77443,24 +74836,24 @@ BEGIN JOIN tmp.workerWithoutShortWeekBreak wws ON wws.workerFk = wtc.userFk WHERE timed BETWEEN vStarted AND vLongEnded AND direction IN ('in', 'out') - UNION + UNION SELECT w.workerFk, - UNIX_TIMESTAMP(IFNULL(MIN(wtc.timed), + UNIX_TIMESTAMP(IFNULL(MIN(wtc.timed), DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND))) FROM tmp.worker w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND timed BETWEEN vLongEnded - AND DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN vLongEnded + AND DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND) GROUP BY w.workerFk UNION - SELECT w.workerFk, - UNIX_TIMESTAMP(IFNULL(MAX(wtc.timed), + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL(MAX(wtc.timed), DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND))) FROM tmp.worker2 w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND timed BETWEEN DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND) AND vStarted GROUP BY w.workerFk ORDER BY userFk, timed @@ -77504,14 +74897,14 @@ BEGIN * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá * fichada a la tabla vn.workerTimeControl */ - + DECLARE vLastIn DATETIME; DECLARE vLastOut DATETIME; DECLARE vNextIn DATETIME; DECLARE vNextOut DATETIME; DECLARE vNextDirection ENUM('in', 'out'); DECLARE vLastDirection ENUM('in', 'out'); - DECLARE vDayMaxTime INTEGER; + DECLARE vDayMaxTime INTEGER; DECLARE vDayBreak INT; DECLARE vShortWeekBreak INT; DECLARE vLongWeekBreak INT; @@ -77538,7 +74931,7 @@ BEGIN WHERE w.id = vWorkerFk; SELECT `description` INTO vErrorMessage - FROM workerTimeControlError + FROM workerTimeControlError WHERE `code` = vErrorCode; IF vErrorMessage IS NULL THEN @@ -77550,7 +74943,7 @@ BEGIN ' no ha podido fichar por el siguiente problema: ', vErrorMessage) INTO vErrorMessage; - + CALL mail_insert( vMailTo, vMailTo, 'Error al fichar', vErrorMessage); END; @@ -77583,19 +74976,19 @@ BEGIN JOIN workerTimeControlConfig wc WHERE b.workerFk = vWorkerFk AND vDated BETWEEN b.started AND IFNULL(b.ended, vDated); - + -- CONTRATO EN VIGOR IF vDayBreak IS NULL THEN SET vErrorCode = 'INACTIVE_BUSINESS'; CALL util.throw(vErrorCode); END IF; - + -- FICHADAS A FUTURO IF vTimed > util.VN_NOW() + INTERVAL 1 MINUTE THEN SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE'; CALL util.throw(vErrorCode); END IF; - + -- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR CALL timeBusiness_calculateByWorker(vWorkerFk, vDated, vDated); SELECT isAllowedToWork INTO vIsAllowedToWork @@ -77622,7 +75015,7 @@ BEGIN ) THEN SET vIsError = TRUE; END IF; - + DROP TEMPORARY TABLE tmp.workerTimeControlDirection; IF vIsError THEN SET vErrorCode = 'WRONG_DIRECTION'; @@ -77637,7 +75030,7 @@ BEGIN AND timed < vTimed ORDER BY timed DESC LIMIT 1; - + IF (SELECT IF(vDirection = 'in', MOD(COUNT(*), 2) , IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE)) @@ -77648,7 +75041,7 @@ BEGIN SET vErrorCode = 'ODD_WORKERTIMECONTROL'; CALL util.throw(vErrorCode); END IF; - + -- DESCANSO DIARIO SELECT timed INTO vLastOut FROM workerTimeControl @@ -77657,7 +75050,7 @@ BEGIN AND timed < vTimed ORDER BY timed DESC LIMIT 1; - + SELECT timed INTO vNextIn FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77665,7 +75058,7 @@ BEGIN AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + CASE vDirection WHEN 'in' THEN IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN @@ -77687,7 +75080,7 @@ BEGIN IF (vDirection IN('in', 'out')) THEN -- VERIFICA MAXIMO TIEMPO DESDE ENTRADA HASTA LA SALIDA - + SELECT timed INTO vNextOut FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77695,7 +75088,7 @@ BEGIN AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + SELECT direction INTO vNextDirection FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77703,7 +75096,7 @@ BEGIN AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + SELECT direction INTO vLastDirection FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77711,34 +75104,34 @@ BEGIN AND timed < vTimed ORDER BY timed ASC LIMIT 1; - - IF (vDirection ='in' - AND vNextDirection = 'out' + + IF (vDirection ='in' + AND vNextDirection = 'out' AND UNIX_TIMESTAMP(vNextOut) - UNIX_TIMESTAMP(vTimed) > vDayMaxTime) OR - (vDirection ='out' + (vDirection ='out' AND vLastDirection = 'in' AND UNIX_TIMESTAMP(vTimed) -UNIX_TIMESTAMP(vLastIn) > vDayMaxTime) THEN SET vErrorCode = 'DAY_MAX_TIME'; CALL util.throw(vErrorCode); END IF; - + -- VERIFICA DESCANSO SEMANAL - + WITH wtc AS( - (SELECT timed - FROM vn.workerTimeControl + (SELECT timed + FROM vn.workerTimeControl WHERE userFk = vWorkerFk AND direction IN ('in', 'out') - AND timed BETWEEN vTimed - INTERVAL (vWeekScope * 2) SECOND + AND timed BETWEEN vTimed - INTERVAL (vWeekScope * 2) SECOND AND vTimed + INTERVAL (vWeekScope * 2) SECOND ) - UNION + UNION (SELECT vTimed) ), wtcGap AS( SELECT timed, - TIMESTAMPDIFF(SECOND, LAG(timed) OVER (ORDER BY timed), timed) gap + TIMESTAMPDIFF(SECOND, LAG(timed) OVER (ORDER BY timed), timed) gap FROM wtc ORDER BY timed - ), wtcBreak AS( + ), wtcBreak AS( SELECT timed, IF(IFNULL(gap, 0) > vShortWeekBreak, TRUE, FALSE) hasShortBreak, IF(IFNULL(gap, 0) > vLongWeekBreak, TRUE, FALSE) hasLongBreak @@ -77749,21 +75142,21 @@ BEGIN SUM(hasShortBreak) OVER (ORDER BY timed) breakCounter , LEAD(hasLongBreak) OVER (ORDER BY timed) nextHasLongBreak FROM wtcBreak - )SELECT TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed)) > vMaxWorkLongCycle OR - (TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed))> vMaxWorkShortCycle + )SELECT TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed)) > vMaxWorkLongCycle OR + (TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed))> vMaxWorkShortCycle AND NOT SUM(IFNULL(nextHasLongBreak, 1))) hasError INTO vIsError FROM wtcBreakCounter GROUP BY breakCounter HAVING hasError LIMIT 1; - + IF vIsError THEN SET vErrorCode = 'BREAK_WEEK'; CALL util.throw(vErrorCode); END IF; END IF; - + -- SE PERMITE FICHAR INSERT INTO workerTimeControl(userFk, timed, direction, `manual`) VALUES(vWorkerFk, vTimed, vDirection, vIsManual); @@ -77792,27 +75185,27 @@ BEGIN * Devuelve que direcciones de fichadas son lógicas a partir de la anterior fichada * @param vWorkerFk Identificador del trabajador * @return (option1, option2) - * Los valores posibles de retorno son ('in', 'inMiddle', 'outMiddle', 'out') + * Los valores posibles de retorno son ('in', 'inMiddle', 'outMiddle', 'out') */ DECLARE vLastIn DATETIME ; DECLARE vIsMiddleOdd BOOLEAN ; - IF (vTimed IS NULL) THEN + IF (vTimed IS NULL) THEN SET vTimed = util.VN_NOW(); END IF; - + SELECT timed INTO vLastIn - FROM workerTimeControl + FROM workerTimeControl WHERE userFk = vWorkerFk - AND direction = 'in' + AND direction = 'in' AND timed < vTimed ORDER BY timed DESC LIMIT 1; - + SELECT (COUNT(*)mod 2 = 1) INTO vIsMiddleOdd - FROM workerTimeControl + FROM workerTimeControl WHERE userFk = vWorkerFk - AND direction = 'middle' + AND direction = 'middle' AND timed BETWEEN vLastIn AND util.VN_NOW(); DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlDirection; @@ -77861,7 +75254,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_getClockIn`( - vUserFk INT, + vUserFk INT, vDated DATE) BEGIN /** @@ -77871,9 +75264,9 @@ BEGIN * @param vDated Fecha proporcionada */ CALL timeControl_calculateByWorker( - vUserFk, + vUserFk, DATE_SUB(vDated, INTERVAL 6 DAY), util.dayEnd(vDated)); - + SET @position := 0; SET @lastDated := NULL; @@ -77890,7 +75283,7 @@ BEGIN MAX(2daysAgoDirection) 2daysAgoDirection, MAX(1daysAgo) 1daysAgo, MAX(1daysAgoDirection) 1daysAgoDirection, - MAX(0daysAgo) 0daysAgo, + MAX(0daysAgo) 0daysAgo, MAX(0daysAgoDirection) 0daysAgoDirection FROM(SELECT IF(daysAgo = 6, timed, '') 6daysAgo, IF(daysAgo = 5, timed, '') 5daysAgo, @@ -77910,7 +75303,7 @@ BEGIN direction, position FROM(SELECT DATEDIFF(vDated, timed) daysAgo, - TIME_FORMAT(timed,'%H:%i') timed, + TIME_FORMAT(timed,'%H:%i') timed, IF(DATE(timed) <> @lastDated, @position := 0, NULL), @position := @position+1 position, @lastDated := DATE(timed), @@ -77922,18 +75315,18 @@ BEGIN LIMIT 10000000000000000000 )sub )sub2 - GROUP BY position) sub3 + GROUP BY position) sub3 JOIN (SELECT MAX(IF(daysAgo = 6, timeWorkSeconds, 0)) 6daysAgoTotal, MAX(IF(daysAgo = 5, timeWorkSeconds, 0)) 5daysAgoTotal, MAX(IF(daysAgo = 4, timeWorkSeconds, 0)) 4daysAgoTotal, MAX(IF(daysAgo = 3, timeWorkSeconds, 0)) 3daysAgoTotal, MAX(IF(daysAgo = 2, timeWorkSeconds, 0)) 2daysAgoTotal, MAX(IF(daysAgo = 1, timeWorkSeconds, 0)) 1daysAgoTotal, - MAX(IF(daysAgo = 0, timeWorkSeconds, 0)) 0daysAgoTotal + MAX(IF(daysAgo = 0, timeWorkSeconds, 0)) 0daysAgoTotal FROM (SELECT DATEDIFF(vDated, dated) daysAgo, timeWorkSeconds FROM tmp.timeControlCalculate) sub4)sub5 ON TRUE; - + DROP TEMPORARY TABLE tmp.timeControlCalculate; END ;; DELIMITER ; @@ -77997,45 +75390,45 @@ BEGIN DECLARE vDirectionPrevious VARCHAR(6); DECLARE vTimedPrevious DATETIME; - SELECT direction INTO vDirectionRemove - FROM vn.workerTimeControl - WHERE userFk = vUserFk + SELECT direction INTO vDirectionRemove + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND timed = vTimed ; IF vDirectionRemove = 'out' THEN - + SELECT timed, direction INTO vTimedPrevious, vDirectionPrevious - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND timed < vTimed ORDER BY timed DESC - LIMIT 1; - + LIMIT 1; + IF vDirectionPrevious = "middle" THEN - UPDATE vn.workerTimeControl + UPDATE vn.workerTimeControl SET direction = "out" WHERE userFk = vUserFk AND timed = vTimedPrevious; END IF; - + ELSE IF vDirectionRemove = 'in' THEN - UPDATE vn.workerTimeControl + UPDATE vn.workerTimeControl SET direction = "in" WHERE userFk = vUserFk AND timed > vTimed ORDER BY timed ASC - LIMIT 1; + LIMIT 1; END IF; - + END IF; - + DELETE FROM vn.workerTimeControl - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND timed = vTimed; - + CALL vn.workerTimeControlSOWP(vUserFk, vTimed); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78063,31 +75456,31 @@ proc: BEGIN UPDATE vn.workerTimeControl SET direction = 'middle'; /*2- poner los out*/ -UPDATE vn.workerTimeControl wtc - JOIN +UPDATE vn.workerTimeControl wtc + JOIN (SELECT userFk,MAX(timed) maxTimed FROM (SELECT id, userFk, timed, date(timed) dated - FROM vn.workerTimeControl - ) sub + FROM vn.workerTimeControl + ) sub GROUP BY userFk,dated )sub SET direction = "out" - WHERE wtc.userFk = sub.userFk + WHERE wtc.userFk = sub.userFk AND wtc.timed = sub.maxTimed; - - /*3- poner los in*/ -UPDATE vn.workerTimeControl wtc - JOIN + + /*3- poner los in*/ +UPDATE vn.workerTimeControl wtc + JOIN (SELECT userFk,MIN(timed) maxTimed FROM (SELECT id, userFk, timed, date(timed) dated - FROM vn.workerTimeControl - ) sub + FROM vn.workerTimeControl + ) sub GROUP BY userFk,dated )sub SET direction = "in" - WHERE wtc.userFk = sub.userFk - AND wtc.timed = sub.maxTimed ; - + WHERE wtc.userFk = sub.userFk + AND wtc.timed = sub.maxTimed ; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78160,7 +75553,7 @@ BEGIN AND w.businessFk GROUP BY tm.userFk,t.dated ORDER BY tm.userFk,t.dated; - + INSERT INTO vn.mail (receiver, replyTo, subject, body) SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', WEEK(vDatedFrom), ' año ', YEAR(vDatedFrom)) , CONCAT(' @@ -78252,7 +75645,7 @@ BEGIN IF (DAYNAME(util.VN_CURDATE()) = 'miércoles') THEN SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL 9 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(), INTERVAL 3 DAY), ' 23:59:59') INTO vDatedFrom, vDatedTo; - + CALL vn.workerTimeControl_sendMailByDepartment(vDatedFrom, vDatedTo, NULL); END IF; END ;; @@ -78302,9 +75695,9 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_weekCheckBreak`(vStarted DATE, vEnded DATE) BEGIN /** - * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas - * El sistema verificará el descanso corto en la siguiente semana - * o el largo en las 2 siguientes semanas a partir de las fechas dadas + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * El sistema verificará el descanso corto en la siguiente semana + * o el largo en las 2 siguientes semanas a partir de las fechas dadas * @param vStarted día inicio para verificar * @param vEnded día final para verificar * @return tmp.workerWithoutWeekBreak (workerFk) @@ -78326,10 +75719,10 @@ BEGIN CALL workerTimeControl_checkBreak(vStarted); INSERT IGNORE INTO tmp.workerWithoutWeekBreakInWeek - SELECT workerFk + SELECT workerFk FROM tmp.workerWithoutWeekBreak; DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreak; - SET vStarted = DATE_ADD(vStarted, INTERVAL 1 DAY); + SET vStarted = DATE_ADD(vStarted, INTERVAL 1 DAY); END WHILE; END ;; @@ -78367,7 +75760,7 @@ BEGIN DECLARE vDepartmentFk INT; DECLARE isEnabled BOOLEAN DEFAULT TRUE; - SELECT COUNT(*) INTO vHasSignedToday + SELECT COUNT(*) INTO vHasSignedToday FROM workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; SET @day := 0; @@ -78380,16 +75773,16 @@ BEGIN SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas FROM ( - SELECT @lastTimed fichada_anterior, + SELECT @lastTimed fichada_anterior, timed, CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, IF(day(timed) != @day, 1, 0) as jornadas, @day := day(timed) dia_del_mes, - @lastTimed := timed fichada_actual + @lastTimed := timed fichada_actual FROM ( SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed - FROM + FROM (SELECT TIMESTAMPADD(DAY, -11, util.VN_NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior UNION ALL SELECT timed, userFk @@ -78397,18 +75790,18 @@ BEGIN WHERE userFk = vUserFk AND timed >= TIMESTAMPADD(DAY, -10,vDated) UNION ALL - SELECT IF(vHasSignedToday, '2000-01-01 00:00', util.VN_NOW()) as timed, vUserFk + SELECT IF(vHasSignedToday, '2000-01-01 00:00', util.VN_NOW()) as timed, vUserFk ) sub4 ORDER BY timed ) sub - + ) sub2 WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) ) sub3 ; SELECT IFNULL(SUM(impar),0) into vImpares FROM ( - SELECT day(timed) as dayNumber, + SELECT day(timed) as dayNumber, count(*) mod 2 as impar FROM vn.workerTimeControl wtc WHERE userFk = vUserFk @@ -78425,29 +75818,29 @@ BEGIN AND at2.isAllowedToWork = FALSE AND b.workerFk = vUserFk LIMIT 1; - + -- Contrato en vigor SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork FROM business b WHERE b.workerFk = vUserFk AND b.started <= vDated AND IFNULL(b.ended, vDated) >= vDated; - + -- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) IF vTabletFk <> '0' THEN -- 1 Obtener el departamento del usuario SELECT wtcu.departmentFk INTO vDepartmentFk FROM workerTimeControlUserInfo wtcu WHERE wtcu.userFk = vUserFk; - -- 2 Comprobar si la tablet pertenece al departamento + -- 2 Comprobar si la tablet pertenece al departamento SELECT COUNT(td.tabletFk) INTO isEnabled FROM tabletDepartment td WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; - + END IF; - + IF vJornadas IS NOT NULL THEN - + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis UNION ALL SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis @@ -78456,9 +75849,9 @@ BEGIN UNION ALL SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis UNION ALL - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, - '' as Cantidad, - IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, + IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis UNION ALL SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; @@ -78472,7 +75865,7 @@ BEGIN UNION ALL SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis UNION ALL - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis UNION ALL SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; @@ -78502,11 +75895,11 @@ BEGIN * @param vDepartmentFk id del departamento * */ - - SELECT w.id,w.firstName, w.lastName,d.name - FROM worker w - JOIN workerDepartment wd ON wd.workerFk = w.id - JOIN department d ON d.id = wd.departmentFk + + SELECT w.id,w.firstName, w.lastName,d.name + FROM worker w + JOIN workerDepartment wd ON wd.workerFk = w.id + JOIN department d ON d.id = wd.departmentFk WHERE d.id = vDepartmentFk ORDER BY firstName; @@ -78526,46 +75919,30 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getHierarchy`(vBoss INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getHierarchy`(vUserFk INT) BEGIN - DECLARE EXIT HANDLER FOR 1062 BEGIN - CALL util.throw('INFINITE_LOOP'); - END; - - DROP TEMPORARY TABLE IF EXISTS workerHierarchy; - CREATE TEMPORARY TABLE workerHierarchy +/** + * Retorna una tabla temporal con los trabajadores que tiene + * el usuario por debajo en la jerarquía de la empresa. + * + * @param vUserFk Id de usuario. + * @return tmp.workerHierarchyList + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.workerHierarchyList (PRIMARY KEY (workerFk)) ENGINE = MEMORY - SELECT vBoss AS workerFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.workerHierarchyList; - CREATE TEMPORARY TABLE tmp.workerHierarchyList - (PRIMARY KEY (workerFk)) - ENGINE = MEMORY - SELECT vBoss AS workerFk, 0 AS isChecked; - - - WHILE (SELECT COUNT(*) FROM tmp.workerHierarchyList WHERE NOT isChecked) > 0 DO - - INSERT INTO tmp.workerHierarchyList - SELECT w.id, 0 - FROM worker w - JOIN workerHierarchy wh ON wh.workerFk = w.bossFk; - - UPDATE tmp.workerHierarchyList whl - JOIN workerHierarchy wh ON wh.workerFk = whl.workerFk - SET whl.isChecked = 1; - - TRUNCATE workerHierarchy; - - INSERT INTO workerHierarchy - SELECT workerFk - FROM tmp.workerHierarchyList - WHERE NOT isChecked; - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS workerHierarchy; + WITH RECURSIVE workerHierarchy AS ( + SELECT id workerFk, bossFk, 0 depth + FROM vn.worker + WHERE id = vUserFk + UNION ALL + SELECT w.id, w.bossFk, wh.depth + 1 + FROM vn.worker w + JOIN workerHierarchy wh ON w.bossFk = wh.workerFk + ) + SELECT * + FROM workerHierarchy + ORDER BY depth, workerFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78591,7 +75968,7 @@ BEGIN SELECT s.id,s.description,s.warehouseFk FROM sector s - JOIN operator o ON o.sectorFk = s.id + JOIN operator o ON o.sectorFk = s.id WHERE o.workerFk = account.myUser_getId(); END ;; @@ -78689,8 +76066,8 @@ BEGIN DECLARE vDone BOOL; DECLARE vCursor CURSOR FOR - SELECT DISTINCT b.workerFk - FROM business b + SELECT DISTINCT b.workerFk + FROM business b WHERE b.started > vBusinessUpdated AND b.started <= vCurdate OR b.ended >= vBusinessUpdated AND b.ended < vCurdate; @@ -78733,10 +76110,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workingHours`(username varchar(255), logon boolean) BEGIN DECLARE userid int(11); - + SELECT vn.getUserId(username) INTO userid; SELECT username, userid; - IF userid IS NOT NULL THEN + IF userid IS NOT NULL THEN IF (logon) THEN CALL vn.workingHoursTimeIn(userid); ELSE @@ -78805,17 +76182,17 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `wrongEqualizatedClient`() BEGIN SELECT clientFk, c.name, c.isActive, c.isTaxDataChecked, count(ie) as num FROM vn.client c - JOIN + JOIN ( - SELECT DISTINCT + SELECT DISTINCT `a`.`clientFk` , a.isEqualizated = 0 as ie - + FROM `vn`.`address` `a` ) sub ON sub.clientFk = c.id WHERE c.hasToInvoiceByAddress = FALSE - + GROUP BY clientFk HAVING num > 1 UNION ALL @@ -78899,27 +76276,27 @@ proc: BEGIN SELECT scope INTO vScope FROM zoneConfig; - + DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE tmp.zone (INDEX (id)) ENGINE = MEMORY SELECT id FROM zone; - + TRUNCATE TABLE zoneClosure; - + WHILE vCounter <= vScope DO - + CALL zone_getOptionsForShipment(vShipped, TRUE); - + REPLACE zoneClosure(zoneFk, dated, `hour`) - SELECT zoneFk, vShipped, `hour` + SELECT zoneFk, vShipped, `hour` FROM tmp.zoneOption; - + SET vCounter = vCounter + 1; SET vShipped = TIMESTAMPADD(DAY, 1, vShipped); END WHILE; - + -- DROP TEMPORARY TABLE tmp.zone; DO RELEASE_LOCK('vn.zoneClosure_recalc'); END ;; @@ -79013,7 +76390,7 @@ BEGIN OR (vSelf IS NOT NULL AND parentFk = vSelf); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SET vSons = 0; OPEN vChildren; @@ -79024,11 +76401,11 @@ BEGIN IF vDone THEN LEAVE myLoop; END IF; - + SET vIndex = vIndex + 1; SET vLft = vIndex; SET vSons = vSons + 1; - + CALL zoneGeo_calcTreeRec( vChildFk, CONCAT(vPath, vChildFk, '/'), @@ -79131,7 +76508,7 @@ proc: BEGIN SELECT isChanged INTO vIsChanged FROM zoneGeoRecalc; - + IF vIsChanged THEN UPDATE zoneGeoRecalc SET isChanged = FALSE; CALL vn.zoneGeo_calcTree; @@ -79387,7 +76764,7 @@ proc:BEGIN * @table tmp.closedZones(zoneFk, warehouseFk); */ DROP TEMPORARY TABLE IF EXISTS tmp.closedZones; - + CREATE TEMPORARY TABLE tmp.closedZones ( `zoneFk` int(11) NOT NULL, `warehouseFk` smallint(6) unsigned NOT NULL, @@ -79429,7 +76806,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getCollisions`() BEGIN /** - * Calcula si para un mismo codigo postal y dia + * Calcula si para un mismo codigo postal y dia * hay mas de una zona configurada y manda correo * */ @@ -79438,16 +76815,16 @@ BEGIN DECLARE vIsDone INT DEFAULT FALSE; DECLARE vTableCollisions TEXT; DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE tmp.zone - SELECT z.id + SELECT z.id FROM zone z JOIN agencyMode am ON am.id = z.agencyModeFk JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE dm.code IN ('AGENCY','DELIVERY'); + WHERE dm.code IN ('AGENCY','DELIVERY'); CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE); @@ -79462,7 +76839,7 @@ BEGIN PRIMARY KEY zoneFkk (zoneFk, geoFk), INDEX(geoFk)) ENGINE = MyISAM; - + OPEN cur1; cur1Loop: LOOP SET vIsDone = FALSE; @@ -79470,40 +76847,40 @@ BEGIN IF vIsDone THEN LEAVE cur1Loop; END IF; - + CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE); - myLoop: LOOP + myLoop: LOOP SET vGeoFk = NULL; - SELECT geoFk INTO vGeoFk + SELECT geoFk INTO vGeoFk FROM tmp.zoneNodes zn WHERE NOT isChecked LIMIT 1; - + IF vGeoFk IS NULL THEN LEAVE myLoop; END IF; - + CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE); UPDATE tmp.zoneNodes - SET isChecked = TRUE + SET isChecked = TRUE WHERE geoFk = vGeoFk; END LOOP; END LOOP; CLOSE cur1; - DELETE FROM tmp.zoneNodes + DELETE FROM tmp.zoneNodes WHERE sons > 0; - + DROP TEMPORARY TABLE IF EXISTS geoCollision; CREATE TEMPORARY TABLE geoCollision SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk FROM tmp.zoneNodes zn JOIN zone z ON z.id = zn.zoneFk - JOIN zoneWarehouse zw ON z.id = zw.zoneFk + JOIN zoneWarehouse zw ON z.id = zw.zoneFk GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk HAVING count(*) > 1; - + SELECT ' @@ -79513,39 +76890,39 @@ BEGIN ' INTO vTableCollisions; - - INSERT INTO mail (receiver,replyTo,subject,body) + + INSERT INTO mail (receiver,replyTo,subject,body) SELECT 'pepe@verdnatura.es' receiver, 'noreply@verdnatura.es' replyTo, CONCAT('Colisiones en zonas ', util.VN_CURDATE()) subject, CONCAT(vTableCollisions, GROUP_CONCAT(sub.td SEPARATOR ''), '
C.PostalAlmacén Salix
') body - FROM(SELECT + FROM(SELECT CONCAT(' ', zn.name, ' ', zoneFk,' ', z.price,' ', z.name,' ', w.name, ' - ', CONCAT('' - 'https://salix.verdnatura.es/#!/zone/', + 'https://salix.verdnatura.es/#!/zone/', zoneFk, '/location?q=%7B%22search%22:%22', - zn.name, + zn.name, '%22%7D'),' ') td FROM tmp.zoneNodes zn JOIN zone z ON z.id = zn.zoneFk JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk JOIN warehouse w ON w.id = gc.warehouseFk) sub; - - DROP TEMPORARY TABLE - geoCollision, + + DROP TEMPORARY TABLE + geoCollision, tmp.zone, tmp.zoneNodes; END ;; @@ -79652,18 +77029,18 @@ BEGIN DECLARE vChildFk INT DEFAULT vGeoFk; DECLARE vParentFk INT; DECLARE vLevel INT DEFAULT 1; - + DROP TEMPORARY TABLE IF EXISTS tNodes; CREATE TEMPORARY TABLE tNodes (PRIMARY KEY (id)) ENGINE = MEMORY SELECT vGeoFk id, vLevel `level`; - + myLoop: LOOP SELECT parentFk INTO vParentFk FROM zoneGeo WHERE id = vChildFk; - + SET vChildFk = vParentFk; SET vLevel = vLevel + 1; @@ -79671,7 +77048,7 @@ BEGIN SELECT vChildFk, vLevel FROM DUAL WHERE vChildFk IS NOT NULL; - + IF ROW_COUNT() = 0 THEN LEAVE myLoop; END IF; @@ -79770,126 +77147,126 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves`( - vSelf INT, - vParentFk INT, - vSearch VARCHAR(255), - vHasInsert BOOL +CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves`( + vSelf INT, + vParentFk INT, + vSearch VARCHAR(255), + vHasInsert BOOL ) -BEGIN -/** - * Devuelve las ubicaciones incluidas en la ruta y que sean hijos de parentFk. - * @param vSelf Id de la zona - * @param vParentFk Id del geo a calcular - * @param vSearch Cadena a buscar - * @param vHasInsert Indica si inserta en tmp.zoneNodes - * Optional @table tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) - */ - DECLARE vIsNumber BOOL; - DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; - - CREATE OR REPLACE TEMPORARY TABLE tNodes - (UNIQUE (id)) - ENGINE = MEMORY - SELECT id - FROM zoneGeo - LIMIT 0; - - IF vIsSearch THEN - SET vIsNumber = vSearch REGEXP '^[0-9]+$'; - - INSERT INTO tNodes - SELECT id - FROM zoneGeo - WHERE (vIsNumber AND `name` = vSearch) - OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) - LIMIT 1000; - - ELSEIF vParentFk IS NULL THEN - INSERT INTO tNodes - SELECT geoFk - FROM zoneIncluded - WHERE zoneFk = vSelf; - END IF; - - IF vParentFk IS NULL THEN - CREATE OR REPLACE TEMPORARY TABLE tChilds - (INDEX(id)) - ENGINE = MEMORY - SELECT id FROM tNodes; - - CREATE OR REPLACE TEMPORARY TABLE tParents - (INDEX(id)) - ENGINE = MEMORY - SELECT id FROM zoneGeo LIMIT 0; - - myLoop: LOOP - DELETE FROM tParents; - INSERT INTO tParents - SELECT parentFk id - FROM zoneGeo g - JOIN tChilds c ON c.id = g.id - WHERE g.parentFk IS NOT NULL; - - INSERT IGNORE INTO tNodes - SELECT id FROM tParents; - - IF NOT ROW_COUNT() THEN - LEAVE myLoop; - END IF; - - DELETE FROM tChilds; - INSERT INTO tChilds - SELECT id FROM tParents; - END LOOP; - - DROP TEMPORARY TABLE tChilds, tParents; - END IF; - - IF NOT vIsSearch THEN - INSERT IGNORE INTO tNodes - SELECT id - FROM zoneGeo - WHERE parentFk <=> vParentFk; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tZones - SELECT g.id, - g.name, - g.parentFk, - g.sons, - NOT g.sons OR `type` = 'country' isChecked, - i.isIncluded selected, - g.`depth`, - vSelf - FROM zoneGeo g - JOIN tNodes n ON n.id = g.id - LEFT JOIN zoneIncluded i ON i.geoFk = g.id - AND i.zoneFk = vSelf - ORDER BY g.`depth`, selected DESC, g.name; - - IF vHasInsert THEN - INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) - SELECT id, - name, - parentFk, - sons, - isChecked, - vSelf - FROM tZones - WHERE selected - OR (selected IS NULL AND vParentFk IS NOT NULL); - ELSE - SELECT id, - name, - parentFk, - sons, - selected - FROM tZones - ORDER BY `depth`, selected DESC, name; - END IF; - - DROP TEMPORARY TABLE tNodes, tZones; +BEGIN +/** + * Devuelve las ubicaciones incluidas en la ruta y que sean hijos de parentFk. + * @param vSelf Id de la zona + * @param vParentFk Id del geo a calcular + * @param vSearch Cadena a buscar + * @param vHasInsert Indica si inserta en tmp.zoneNodes + * Optional @table tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + */ + DECLARE vIsNumber BOOL; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; + + CREATE OR REPLACE TEMPORARY TABLE tNodes + (UNIQUE (id)) + ENGINE = MEMORY + SELECT id + FROM zoneGeo + LIMIT 0; + + IF vIsSearch THEN + SET vIsNumber = vSearch REGEXP '^[0-9]+$'; + + INSERT INTO tNodes + SELECT id + FROM zoneGeo + WHERE (vIsNumber AND `name` = vSearch) + OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) + LIMIT 1000; + + ELSEIF vParentFk IS NULL THEN + INSERT INTO tNodes + SELECT geoFk + FROM zoneIncluded + WHERE zoneFk = vSelf; + END IF; + + IF vParentFk IS NULL THEN + CREATE OR REPLACE TEMPORARY TABLE tChilds + (INDEX(id)) + ENGINE = MEMORY + SELECT id FROM tNodes; + + CREATE OR REPLACE TEMPORARY TABLE tParents + (INDEX(id)) + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + myLoop: LOOP + DELETE FROM tParents; + INSERT INTO tParents + SELECT parentFk id + FROM zoneGeo g + JOIN tChilds c ON c.id = g.id + WHERE g.parentFk IS NOT NULL; + + INSERT IGNORE INTO tNodes + SELECT id FROM tParents; + + IF NOT ROW_COUNT() THEN + LEAVE myLoop; + END IF; + + DELETE FROM tChilds; + INSERT INTO tChilds + SELECT id FROM tParents; + END LOOP; + + DROP TEMPORARY TABLE tChilds, tParents; + END IF; + + IF NOT vIsSearch THEN + INSERT IGNORE INTO tNodes + SELECT id + FROM zoneGeo + WHERE parentFk <=> vParentFk; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tZones + SELECT g.id, + g.name, + g.parentFk, + g.sons, + NOT g.sons OR `type` = 'country' isChecked, + i.isIncluded selected, + g.`depth`, + vSelf + FROM zoneGeo g + JOIN tNodes n ON n.id = g.id + LEFT JOIN zoneIncluded i ON i.geoFk = g.id + AND i.zoneFk = vSelf + ORDER BY g.`depth`, selected DESC, g.name; + + IF vHasInsert THEN + INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + SELECT id, + name, + parentFk, + sons, + isChecked, + vSelf + FROM tZones + WHERE selected + OR (selected IS NULL AND vParentFk IS NOT NULL); + ELSE + SELECT id, + name, + parentFk, + sons, + selected + FROM tZones + ORDER BY `depth`, selected DESC, name; + END IF; + + DROP TEMPORARY TABLE tNodes, tZones; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -79914,7 +77291,7 @@ BEGIN * @table tmp.zone(id) The zones ids * @param vLanded The delivery date * @return tmp.zoneOption The computed options - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; CREATE TEMPORARY TABLE tmp.zoneOption ENGINE = MEMORY @@ -79955,13 +77332,13 @@ BEGIN END LIMIT 10000000000000000000 ) t - GROUP BY zoneFk; - + GROUP BY zoneFk; + DELETE t FROM tmp.zoneOption t JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id WHERE eg.zoneExclusionFk IS NULL; - + IF NOT vShowExpiredZones THEN DELETE FROM tmp.zoneOption WHERE shipped < util.VN_CURDATE() @@ -79993,7 +77370,7 @@ BEGIN * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options */ DECLARE vHour TIME DEFAULT TIME(util.VN_NOW()); - + DROP TEMPORARY TABLE IF EXISTS tLandings; CREATE TEMPORARY TABLE tLandings (INDEX (eventFk)) @@ -80072,48 +77449,48 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getPostalCode`(vSelf INT) -BEGIN -/** - * Devuelve los códigos postales incluidos en una zona - */ - DECLARE vGeoFk INT DEFAULT NULL; - - CREATE OR REPLACE TEMPORARY TABLE tmp.zoneNodes ( - geoFk INT, - name VARCHAR(100), - parentFk INT, - sons INT, - isChecked BOOL DEFAULT 0, - zoneFk INT, - PRIMARY KEY zoneNodesPk (zoneFk, geoFk), - INDEX(geoFk)) - ENGINE = MEMORY; - - CALL zone_getLeaves(vSelf, NULL , NULL, TRUE); - - UPDATE tmp.zoneNodes - SET isChecked = 0 - WHERE parentFk IS NULL; - - myLoop: LOOP - SET vGeoFk = NULL; - SELECT geoFk INTO vGeoFk - FROM tmp.zoneNodes - WHERE NOT isChecked - LIMIT 1; - - CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE); - UPDATE tmp.zoneNodes - SET isChecked = TRUE - WHERE geoFk = vGeoFk; - - IF vGeoFk IS NULL THEN - LEAVE myLoop; - END IF; - END LOOP; - - DELETE FROM tmp.zoneNodes - WHERE sons > 0; +BEGIN +/** + * Devuelve los códigos postales incluidos en una zona + */ + DECLARE vGeoFk INT DEFAULT NULL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.zoneNodes ( + geoFk INT, + name VARCHAR(100), + parentFk INT, + sons INT, + isChecked BOOL DEFAULT 0, + zoneFk INT, + PRIMARY KEY zoneNodesPk (zoneFk, geoFk), + INDEX(geoFk)) + ENGINE = MEMORY; + + CALL zone_getLeaves(vSelf, NULL , NULL, TRUE); + + UPDATE tmp.zoneNodes + SET isChecked = 0 + WHERE parentFk IS NULL; + + myLoop: LOOP + SET vGeoFk = NULL; + SELECT geoFk INTO vGeoFk + FROM tmp.zoneNodes + WHERE NOT isChecked + LIMIT 1; + + CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE); + UPDATE tmp.zoneNodes + SET isChecked = TRUE + WHERE geoFk = vGeoFk; + + IF vGeoFk IS NULL THEN + LEAVE myLoop; + END IF; + END LOOP; + + DELETE FROM tmp.zoneNodes + WHERE sons > 0; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -80144,7 +77521,7 @@ BEGIN DECLARE vZoneGeo INT; SELECT address_getGeo(vAddressFk) INTO vZoneGeo; - + CALL vn.zone_getFromGeo(vZoneGeo); CALL vn.zone_getOptionsForLanding(vLanded, vShowExpiredZones); CALL vn.zone_excludeFromGeo(vZoneGeo); @@ -80164,7 +77541,7 @@ BEGIN FROM tmp.zoneOption zo JOIN vn.zoneWarehouse zw ON zw.zoneFk = zo.zoneFk JOIN vn.`zone` z ON z.id = zo.zoneFk - LEFT JOIN tmp.closedZones cz + LEFT JOIN tmp.closedZones cz ON cz.warehouseFk = zw.warehouseFk AND cz.zoneFk = zw.zoneFk AND zo.shipped = util.VN_CURDATE() @@ -80198,9 +77575,9 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getState`(vDated DATE) BEGIN /** * Devuelve las zonas y el estado para la fecha solicitada - * + * * @param vDated Fecha en cuestión - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE tmp.zone ( @@ -80214,7 +77591,7 @@ BEGIN CALL vn.zone_getOptionsForShipment(vDated, TRUE); CALL vn.zone_getClosed(); - + SELECT zo.zoneFk, zo.`hour`etd, (zo.`hour` <= TIME(util.VN_NOW())) isLate, @@ -80224,11 +77601,11 @@ BEGIN FROM tmp.zoneOption zo JOIN vn.zone z ON z.id = zo.zoneFk JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id - LEFT JOIN tmp.closedZones cz - ON cz.warehouseFk = zw.warehouseFk + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk AND cz.zoneFk = zo.zoneFk; - - DROP TEMPORARY TABLE + + DROP TEMPORARY TABLE tmp.closedZones, tmp.zoneOption, tmp.zone; @@ -80254,21 +77631,21 @@ BEGIN /** * Devuelve el listado de agencias disponibles para la fecha, * dirección y almacén pasados. - * + * * @param vAddress * @param vWarehouse warehouse * @param vLanded Fecha de recogida * @select Listado de agencias disponibles */ - + CALL zone_getFromGeo(address_getGeo(vAddress)); CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, + + SELECT am.id agencyModeFk, + am.name agencyMode, + am.description, am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, + TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, zw.warehouseFk, z.id zoneFk FROM tmp.zoneOption zo @@ -80278,11 +77655,11 @@ BEGIN WHERE zw.warehouseFk = vWarehouse GROUP BY z.agencyModeFk ORDER BY agencyMode; - + DROP TEMPORARY TABLE tmp.zone, tmp.zoneOption; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -80303,7 +77680,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_upcomingDeliveries`() BEGIN DECLARE vForwardDays INT; - + SELECT forwardDays INTO vForwardDays FROM zoneConfig; CALL util.time_createTable(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); @@ -80319,7 +77696,7 @@ BEGIN JOIN zoneEvent e ON e.zoneFk = z.id JOIN tmp.time ti ON ti.dated BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY, vForwardDays, util.VN_CURDATE()); - DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; CREATE TEMPORARY TABLE tmp.zoneOption ENGINE = MEMORY SELECT * @@ -80360,7 +77737,7 @@ BEGIN JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id WHERE eg.zoneExclusionFk IS NULL; - + SELECT MAX(zo.`hour`) `hour`, zg.`name`, zo.shipped, zo.zoneFk FROM tmp.zoneOption zo JOIN `zone` z ON z.id = zo.zoneFk @@ -80371,7 +77748,7 @@ BEGIN WHERE dm.code = 'DELIVERY' GROUP BY shipped, zg.`name` ORDER BY shipped, zg.`name`; - + DROP TEMPORARY TABLE tmp.time, tLandings; END ;; DELIMITER ; @@ -80380,6 +77757,13338 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Current Database: `vn2008` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vn2008` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci */; + +USE `vn2008`; + +-- +-- Temporary table structure for view `Agencias` +-- + +DROP TABLE IF EXISTS `Agencias`; +/*!50001 DROP VIEW IF EXISTS `Agencias`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Agencias` AS SELECT + 1 AS `Id_Agencia`, + 1 AS `Agencia`, + 1 AS `description`, + 1 AS `Vista`, + 1 AS `m3`, + 1 AS `web`, + 1 AS `agency_id`, + 1 AS `inflacion`, + 1 AS `is_volumetric`, + 1 AS `send_mail`, + 1 AS `tpv`, + 1 AS `code`, + 1 AS `show_AgencyName`, + 1 AS `isRiskFree` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Agencias_province` +-- + +DROP TABLE IF EXISTS `Agencias_province`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Agencias_province` ( + `province_id` smallint(6) unsigned NOT NULL, + `agency_id` smallint(5) unsigned NOT NULL, + `zona` tinyint(4) NOT NULL, + `warehouse_id` smallint(6) unsigned NOT NULL, + `route` tinyint(4) NOT NULL COMMENT 'Etiqueta zeleris', + `isVolumetric` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`province_id`,`agency_id`,`warehouse_id`), + KEY `warehouse_id` (`warehouse_id`), + KEY `agency_id` (`agency_id`), + CONSTRAINT `Agencias_province_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `vn`.`province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `Agencias_province_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `Agencias_province_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `vn`.`agency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Articles` +-- + +DROP TABLE IF EXISTS `Articles`; +/*!50001 DROP VIEW IF EXISTS `Articles`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Articles` AS SELECT + 1 AS `Id_Article`, + 1 AS `Article`, + 1 AS `tipo_id`, + 1 AS `Medida`, + 1 AS `Color`, + 1 AS `Categoria`, + 1 AS `Tallos`, + 1 AS `id_origen`, + 1 AS `description`, + 1 AS `producer_id`, + 1 AS `Codintrastat`, + 1 AS `caja`, + 1 AS `expenseFk`, + 1 AS `comments`, + 1 AS `relevancy`, + 1 AS `Foto`, + 1 AS `generic`, + 1 AS `density`, + 1 AS `PVP`, + 1 AS `Min`, + 1 AS `isActive`, + 1 AS `longName`, + 1 AS `subName`, + 1 AS `tag5`, + 1 AS `value5`, + 1 AS `tag6`, + 1 AS `value6`, + 1 AS `tag7`, + 1 AS `value7`, + 1 AS `tag8`, + 1 AS `value8`, + 1 AS `tag9`, + 1 AS `value9`, + 1 AS `tag10`, + 1 AS `value10`, + 1 AS `minimum`, + 1 AS `upToDown`, + 1 AS `hasKgPrice`, + 1 AS `Equivalente`, + 1 AS `Imprimir`, + 1 AS `Familia__`, + 1 AS `do_photo`, + 1 AS `odbc_date`, + 1 AS `isFloramondo`, + 1 AS `supplyResponseFk`, + 1 AS `stemMultiplier`, + 1 AS `itemPackingTypeFk`, + 1 AS `packingOut` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Articles_botanical` +-- + +DROP TABLE IF EXISTS `Articles_botanical`; +/*!50001 DROP VIEW IF EXISTS `Articles_botanical`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Articles_botanical` AS SELECT + 1 AS `Id_Article`, + 1 AS `genus_id`, + 1 AS `specie_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Baldas` +-- + +DROP TABLE IF EXISTS `Baldas`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Baldas` ( + `Id_Estanterias` int(11) NOT NULL, + `Id_Baldas` int(11) NOT NULL, + `h` int(11) NOT NULL, + PRIMARY KEY (`Id_Estanterias`,`Id_Baldas`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Bancos` +-- + +DROP TABLE IF EXISTS `Bancos`; +/*!50001 DROP VIEW IF EXISTS `Bancos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Bancos` AS SELECT + 1 AS `Id_Banco`, + 1 AS `Banco`, + 1 AS `Cuenta`, + 1 AS `cash`, + 1 AS `entity_id`, + 1 AS `activo`, + 1 AS `currencyFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Bancos_poliza` +-- + +DROP TABLE IF EXISTS `Bancos_poliza`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Bancos_poliza` ( + `poliza_id` int(11) NOT NULL AUTO_INCREMENT, + `referencia` varchar(45) DEFAULT NULL, + `importe` double NOT NULL, + `com_dispuesto` double DEFAULT NULL, + `com_no_dispuesto` double DEFAULT NULL, + `com_anual` double DEFAULT NULL, + `apertura` date NOT NULL, + `cierre` date DEFAULT NULL, + `Id_Banco` int(11) NOT NULL, + `empresa_id` int(10) unsigned NOT NULL DEFAULT 442, + `supplierFk` int(10) unsigned DEFAULT NULL, + `description` varchar(255) DEFAULT NULL, + `hasGuarantee` tinyint(1) NOT NULL DEFAULT 0, + `dmsFk` int(11) DEFAULT NULL, + `notaryFk` int(10) unsigned DEFAULT NULL, + `currencyFk` tinyint(3) unsigned DEFAULT 2, + `amortizationTypeFk` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `periodicityTypeFk` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `insuranceExpired` date DEFAULT NULL, + PRIMARY KEY (`poliza_id`), + KEY `Id_Banco_Poliza_idx` (`Id_Banco`), + KEY `Id_Poliza_Empresa_idx` (`empresa_id`), + KEY `bankSupplierIdx1_idx` (`supplierFk`), + KEY `bankDmsIdx2_idx` (`dmsFk`), + KEY `bankNotaryIdx3_idx` (`notaryFk`), + KEY `asdf_idx` (`amortizationTypeFk`), + KEY `bankPeriodicityIdx4_idx` (`periodicityTypeFk`), + CONSTRAINT `Bancos_polizaCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON UPDATE CASCADE, + CONSTRAINT `Bancos_poliza_notaryFk` FOREIGN KEY (`notaryFk`) REFERENCES `vn`.`supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `Bancos_poliza_supplierFk` FOREIGN KEY (`supplierFk`) REFERENCES `vn`.`supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `Id_Banco_Poliza` FOREIGN KEY (`Id_Banco`) REFERENCES `vn`.`accounting` (`id`) ON UPDATE CASCADE, + CONSTRAINT `asdf` FOREIGN KEY (`amortizationTypeFk`) REFERENCES `vn`.`amortizationType` (`code`) ON UPDATE CASCADE, + CONSTRAINT `bankDmsIdx2` FOREIGN KEY (`dmsFk`) REFERENCES `vn`.`dms` (`id`) ON UPDATE CASCADE, + CONSTRAINT `bankPeriodicityIdx4` FOREIGN KEY (`periodicityTypeFk`) REFERENCES `vn`.`periodicityType` (`code`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Brasa` +-- + +DROP TABLE IF EXISTS `Brasa`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Brasa` ( + `Id_Cliente` int(10) unsigned NOT NULL DEFAULT 0, + `Cliente` varchar(50) NOT NULL, + `Vista` int(10) unsigned NOT NULL DEFAULT 0, + `Reg` bigint(21) unsigned NOT NULL DEFAULT 0, + `Consumo` double NOT NULL, + `Grupo` int(10) unsigned NOT NULL, + PRIMARY KEY (`Id_Cliente`), + KEY `Index_1` (`Id_Cliente`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Cajas` +-- + +DROP TABLE IF EXISTS `Cajas`; +/*!50001 DROP VIEW IF EXISTS `Cajas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Cajas` AS SELECT + 1 AS `Id_Caja`, + 1 AS `Cajafecha`, + 1 AS `Serie`, + 1 AS `Concepto`, + 1 AS `Entrada`, + 1 AS `Salida`, + 1 AS `Id_Banco`, + 1 AS `empresa_id`, + 1 AS `Partida`, + 1 AS `InForeignValue`, + 1 AS `OutForeignValue`, + 1 AS `Id_Trabajador`, + 1 AS `id_calculated`, + 1 AS `Numero`, + 1 AS `linked`, + 1 AS `odbc_date`, + 1 AS `ok`, + 1 AS `warehouse_id`, + 1 AS `conciliado`, + 1 AS `Proveedores_account_Id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Clases` +-- + +DROP TABLE IF EXISTS `Clases`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Clases` ( + `Id_Clase` int(11) NOT NULL DEFAULT 0, + `Clase` varchar(50) DEFAULT NULL, + PRIMARY KEY (`Id_Clase`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Clientes` +-- + +DROP TABLE IF EXISTS `Clientes`; +/*!50001 DROP VIEW IF EXISTS `Clientes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Clientes` AS SELECT + 1 AS `id_cliente`, + 1 AS `cliente`, + 1 AS `if`, + 1 AS `razonSocial`, + 1 AS `contacto`, + 1 AS `domicilio`, + 1 AS `poblacion`, + 1 AS `codPostal`, + 1 AS `telefono`, + 1 AS `movil`, + 1 AS `real`, + 1 AS `e-mail`, + 1 AS `iban`, + 1 AS `vencimiento`, + 1 AS `Cuenta`, + 1 AS `RE`, + 1 AS `province_id`, + 1 AS `invoice`, + 1 AS `credito`, + 1 AS `Id_Pais`, + 1 AS `activo`, + 1 AS `gestdoc_id`, + 1 AS `calidad`, + 1 AS `pay_met_id`, + 1 AS `created`, + 1 AS `mail`, + 1 AS `chanel_id`, + 1 AS `sepaVnl`, + 1 AS `coreVnl`, + 1 AS `coreVnh`, + 1 AS `hasLcr`, + 1 AS `default_address`, + 1 AS `risk_calculated`, + 1 AS `clientes_tipo_id`, + 1 AS `invoiceByAddress`, + 1 AS `contabilizado`, + 1 AS `congelado`, + 1 AS `creditInsurance`, + 1 AS `isCreatedAsServed`, + 1 AS `hasInvoiceSimplified`, + 1 AS `Id_Trabajador`, + 1 AS `vies`, + 1 AS `EYPBC`, + 1 AS `bankEntityFk`, + 1 AS `typeFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Clientes_dits` +-- + +DROP TABLE IF EXISTS `Clientes_dits`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Clientes_dits` ( + `idClientes_dits` int(11) NOT NULL AUTO_INCREMENT, + `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, + `value_old` varchar(100) DEFAULT NULL, + `value_new` varchar(100) DEFAULT NULL, + PRIMARY KEY (`idClientes_dits`), + KEY `idaccion_dits` (`idaccion_dits`), + CONSTRAINT `Clientes_dits_ibfk_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Clientes_empresa` +-- + +DROP TABLE IF EXISTS `Clientes_empresa`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Clientes_empresa` ( + `Id_Clientes_empresa` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `Id_Cliente` int(11) NOT NULL, + `empresa_id` int(10) unsigned NOT NULL, + `fecha_ini` date NOT NULL, + `fecha_fin` date NOT NULL, + PRIMARY KEY (`Id_Clientes_empresa`), + KEY `empresa_id_idx` (`empresa_id`), + CONSTRAINT `Clientes_empresaCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON DELETE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Empresa por defecto para crear los tickets'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Clientes_event` +-- + +DROP TABLE IF EXISTS `Clientes_event`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Clientes_event` ( + `Id_Cliente` int(11) NOT NULL, + `quantity` tinyint(3) unsigned NOT NULL, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`Id_Cliente`), + CONSTRAINT `Clientes_event_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Clientes_potenciales` +-- + +DROP TABLE IF EXISTS `Clientes_potenciales`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Clientes_potenciales` ( + `id` int(11) NOT NULL, + `PAIS` varchar(12) DEFAULT NULL, + `ACTIVIDAD` varchar(10) DEFAULT NULL, + `NOMBRE` varchar(45) NOT NULL DEFAULT '', + `PROVINCIA` varchar(25) DEFAULT NULL, + `POBLACION` varchar(45) NOT NULL DEFAULT '', + `CP` varchar(10) DEFAULT NULL, + `DIR_POSTAL` varchar(45) NOT NULL DEFAULT '', + `TELEFONO` varchar(12) NOT NULL DEFAULT '', + `TELEFONO2` varchar(12) NOT NULL DEFAULT '', + `FAX` varchar(12) NOT NULL DEFAULT '', + `E-MAIL` varchar(45) DEFAULT NULL, + `pagweb` varchar(45) DEFAULT NULL, + `SERVICIOS` varchar(45) DEFAULT NULL, + `state_id` smallint(6) DEFAULT 0 COMMENT '0 no se ha hecho nada\n1 ya existe el cliente\n2 cliente conseguido\n3 desestimado', + `Id_Trabajador` smallint(6) DEFAULT NULL, + `Notas` varchar(255) DEFAULT NULL, + `odbc_date` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`NOMBRE`,`POBLACION`,`DIR_POSTAL`,`TELEFONO`,`TELEFONO2`,`FAX`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Colores__` +-- + +DROP TABLE IF EXISTS `Colores__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Colores__` ( + `Id_Color` int(11) NOT NULL DEFAULT 0, + `Color` varchar(50) DEFAULT NULL, + PRIMARY KEY (`Id_Color`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #5903 deprecated 2023-06-30'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Comparativa` +-- + +DROP TABLE IF EXISTS `Comparativa`; +/*!50001 DROP VIEW IF EXISTS `Comparativa`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Comparativa` AS SELECT + 1 AS `Periodo`, + 1 AS `Id_Article`, + 1 AS `warehouse_id`, + 1 AS `Cantidad`, + 1 AS `price`, + 1 AS `countryFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Comparativa__` +-- + +DROP TABLE IF EXISTS `Comparativa__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Comparativa__` ( + `Periodo` int(11) NOT NULL, + `Id_Article` bigint(20) NOT NULL, + `warehouse_id` int(11) NOT NULL, + `Cantidad` mediumint(9) NOT NULL DEFAULT 0, + `price` mediumint(8) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`Periodo`,`Id_Article`,`warehouse_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='20/11/2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Compres` +-- + +DROP TABLE IF EXISTS `Compres`; +/*!50001 DROP VIEW IF EXISTS `Compres`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Compres` AS SELECT + 1 AS `Id_Compra`, + 1 AS `Id_Entrada`, + 1 AS `Id_Article`, + 1 AS `Costefijo`, + 1 AS `Cantidad`, + 1 AS `Id_Cubo`, + 1 AS `Etiquetas`, + 1 AS `Portefijo`, + 1 AS `Embalajefijo`, + 1 AS `Comisionfija`, + 1 AS `Packing`, + 1 AS `grouping`, + 1 AS `caja`, + 1 AS `Nicho`, + 1 AS `Tarifa1`, + 1 AS `Tarifa2`, + 1 AS `Tarifa3`, + 1 AS `PVP`, + 1 AS `Vida`, + 1 AS `punteo`, + 1 AS `buy_edi_id`, + 1 AS `odbc_date`, + 1 AS `Novincular`, + 1 AS `isPickedOff`, + 1 AS `Id_Trabajador`, + 1 AS `weight`, + 1 AS `dispatched`, + 1 AS `container_id`, + 1 AS `itemOriginalFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Compres_mark` +-- + +DROP TABLE IF EXISTS `Compres_mark`; +/*!50001 DROP VIEW IF EXISTS `Compres_mark`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Compres_mark` AS SELECT + 1 AS `Id_Compra`, + 1 AS `comment`, + 1 AS `mark`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Compres_ok` +-- + +DROP TABLE IF EXISTS `Compres_ok`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Compres_ok` ( + `Id_Compra` int(11) NOT NULL, + `valor` tinyint(3) unsigned NOT NULL DEFAULT 0, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `original_quantity` double DEFAULT NULL, + `Id_Trabajador` int(10) unsigned NOT NULL, + `Id_Accion` varchar(45) NOT NULL, + `Id_Compra_ok` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`Id_Compra_ok`), + KEY `Id_Movimiento` (`Id_Compra`), + KEY `Id_Accion` (`Id_Accion`), + KEY `Compres_ok_Id_Trabajador_idx` (`Id_Trabajador`), + CONSTRAINT `Compres_ok_Id_Trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn`.`worker` (`id`), + CONSTRAINT `Compres_ok_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `vn`.`buy` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Consignatarios` +-- + +DROP TABLE IF EXISTS `Consignatarios`; +/*!50001 DROP VIEW IF EXISTS `Consignatarios`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Consignatarios` AS SELECT + 1 AS `id_consigna`, + 1 AS `Id_cliente`, + 1 AS `domicilio`, + 1 AS `poblacion`, + 1 AS `codPostal`, + 1 AS `province_id`, + 1 AS `telefono`, + 1 AS `movil`, + 1 AS `consignatario`, + 1 AS `predeterminada`, + 1 AS `longitude`, + 1 AS `latitude`, + 1 AS `Id_Agencia`, + 1 AS `isEqualizated`, + 1 AS `active` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Consignatarios_devices` +-- + +DROP TABLE IF EXISTS `Consignatarios_devices`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Consignatarios_devices` ( + `Id_Consigna` int(11) NOT NULL, + `serialNumber` varchar(45) NOT NULL, + `notas` varchar(45) DEFAULT NULL, + PRIMARY KEY (`Id_Consigna`,`serialNumber`), + CONSTRAINT `Condigna_devices` FOREIGN KEY (`Id_Consigna`) REFERENCES `vn`.`address` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Conteo` +-- + +DROP TABLE IF EXISTS `Conteo`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Conteo` ( + `Id_Conteo` int(11) NOT NULL AUTO_INCREMENT, + `Id_Article` int(11) NOT NULL, + `Fecha` timestamp NOT NULL DEFAULT current_timestamp(), + `dispositivo` varchar(15) DEFAULT NULL, + `warehouse_id` int(10) unsigned NOT NULL DEFAULT 1, + PRIMARY KEY (`Id_Conteo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Cubos` +-- + +DROP TABLE IF EXISTS `Cubos`; +/*!50001 DROP VIEW IF EXISTS `Cubos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Cubos` AS SELECT + 1 AS `Id_Cubo`, + 1 AS `Volumen`, + 1 AS `X`, + 1 AS `Y`, + 1 AS `Z`, + 1 AS `Retornable`, + 1 AS `odbc_date`, + 1 AS `item_id`, + 1 AS `pvp`, + 1 AS `bultoCubico`, + 1 AS `Valor`, + 1 AS `idCubos_Retorno`, + 1 AS `Bajan`, + 1 AS `Suben`, + 1 AS `Base`, + 1 AS `box`, + 1 AS `costeRetorno` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Cubos_Retorno` +-- + +DROP TABLE IF EXISTS `Cubos_Retorno`; +/*!50001 DROP VIEW IF EXISTS `Cubos_Retorno`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Cubos_Retorno` AS SELECT + 1 AS `idCubos_Retorno`, + 1 AS `Soporte`, + 1 AS `Vacio`, + 1 AS `Lleno` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Enlaces Facturas__` +-- + +DROP TABLE IF EXISTS `Enlaces Facturas__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Enlaces Facturas__` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `Asiento` int(11) DEFAULT 0, + `Apunte` int(11) DEFAULT 0, + `Data` datetime DEFAULT NULL, + `Concepto` varchar(40) DEFAULT NULL, + `Cuenta` varchar(10) DEFAULT NULL, + `Debe` double DEFAULT NULL, + `Haber` double DEFAULT NULL, + `Contrapartida` varchar(10) DEFAULT NULL, + `Contabilizado` tinyint(1) NOT NULL DEFAULT 0, + `empresa_id` int(10) unsigned NOT NULL DEFAULT 442, + PRIMARY KEY (`id`), + KEY `empresa_id` (`empresa_id`), + CONSTRAINT `EnlacesFacturas__Company_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Entradas` +-- + +DROP TABLE IF EXISTS `Entradas`; +/*!50001 DROP VIEW IF EXISTS `Entradas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Entradas` AS SELECT + 1 AS `Id_Entrada`, + 1 AS `Id_Proveedor`, + 1 AS `Referencia`, + 1 AS `reference`, + 1 AS `Inventario`, + 1 AS `Confirmada`, + 1 AS `Pedida`, + 1 AS `Redada`, + 1 AS `comision`, + 1 AS `odbc_date`, + 1 AS `Notas_Eva`, + 1 AS `travel_id`, + 1 AS `Id_Moneda`, + 1 AS `empresa_id`, + 1 AS `gestdoc_id`, + 1 AS `recibida_id`, + 1 AS `Fecha`, + 1 AS `Anotadoencaja`, + 1 AS `loadPriority`, + 1 AS `sub`, + 1 AS `kop`, + 1 AS `pro`, + 1 AS `invoiceAmount`, + 1 AS `buyerFk`, + 1 AS `typeFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Entradas_Auto` +-- + +DROP TABLE IF EXISTS `Entradas_Auto`; +/*!50001 DROP VIEW IF EXISTS `Entradas_Auto`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Entradas_Auto` AS SELECT + 1 AS `Id_Entrada` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Entradas_dits__` +-- + +DROP TABLE IF EXISTS `Entradas_dits__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Entradas_dits__` ( + `idEntrada_dits` int(11) NOT NULL AUTO_INCREMENT, + `idaccion_dits` int(11) NOT NULL, + `ODBC_DATE` timestamp NOT NULL DEFAULT current_timestamp(), + `Id_Ticket` int(11) NOT NULL, + `Id_Trabajador` int(10) unsigned DEFAULT NULL, + `value_old` varchar(100) DEFAULT NULL, + `value_new` varchar(100) DEFAULT NULL, + PRIMARY KEY (`idEntrada_dits`), + KEY `fgkey_entradas_1_idx` (`idaccion_dits`), + KEY `fgkey_entradas_2_idx` (`Id_Ticket`), + KEY `fgkey_entradas_3_idx` (`Id_Trabajador`), + CONSTRAINT `Entradas_dits___ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn`.`entry` (`id`) 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 `vn`.`worker` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='refs #6039 @deprecated 2023-08-04'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Entradas_kop` +-- + +DROP TABLE IF EXISTS `Entradas_kop`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Entradas_kop` ( + `Id_Entradas_kop` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `Id_Entrada` int(11) NOT NULL, + `kop` int(11) DEFAULT NULL, + `sub` mediumint(8) unsigned DEFAULT NULL, + PRIMARY KEY (`Id_Entradas_kop`), + KEY `entradas_entradas_kop_idx` (`Id_Entrada`), + CONSTRAINT `entradas_entradas_kop` FOREIGN KEY (`Id_Entrada`) REFERENCES `vn`.`entry` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Entradas_orden` +-- + +DROP TABLE IF EXISTS `Entradas_orden`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Entradas_orden` ( + `Id_Entrada` int(11) NOT NULL, + `orden` int(11) NOT NULL DEFAULT 1 COMMENT '1.- Ordenar por articulo\n2.- Ordenar por compra\n', + PRIMARY KEY (`Id_Entrada`), + CONSTRAINT `entradas_entradas_orden` FOREIGN KEY (`Id_Entrada`) REFERENCES `vn`.`entry` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Entradas_stack__` +-- + +DROP TABLE IF EXISTS `Entradas_stack__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Entradas_stack__` ( + `Id_Entrada` int(11) NOT NULL, + `label_number` smallint(6) DEFAULT 0, + PRIMARY KEY (`Id_Entrada`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Entradas_turno__` +-- + +DROP TABLE IF EXISTS `Entradas_turno__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Entradas_turno__` ( + `Id_Entrada` int(11) NOT NULL, + `weekDay` tinyint(2) NOT NULL DEFAULT 0, + PRIMARY KEY (`Id_Entrada`), + CONSTRAINT `entrada_entrada_turno` FOREIGN KEY (`Id_Entrada`) REFERENCES `vn`.`entry` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `EnvioMasivo__` +-- + +DROP TABLE IF EXISTS `EnvioMasivo__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `EnvioMasivo__` ( + `Id` int(11) NOT NULL AUTO_INCREMENT, + `Cliente` varchar(40) NOT NULL, + `Direccion` varchar(80) NOT NULL, + `CP` varchar(5) NOT NULL, + `Poblacion` varchar(40) NOT NULL, + `Telefono` varchar(9) NOT NULL, + `Bultos` int(11) NOT NULL, + `Observaciones` varchar(40) DEFAULT NULL, + `IdTicket` int(11) NOT NULL, + PRIMARY KEY (`Id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Equipos` +-- + +DROP TABLE IF EXISTS `Equipos`; +/*!50001 DROP VIEW IF EXISTS `Equipos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Equipos` AS SELECT + 1 AS `alias`, + 1 AS `descripcion`, + 1 AS `trabajador_id`, + 1 AS `windowsSerial` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Espionajes` +-- + +DROP TABLE IF EXISTS `Espionajes`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Espionajes` ( + `idEspionaje` int(11) NOT NULL AUTO_INCREMENT, + `Id_Trabajador` varchar(45) DEFAULT NULL, + `Fecha` date DEFAULT NULL, + `HoraEntrada` time DEFAULT NULL, + `HoraSalida` time DEFAULT NULL, + `Id_Equipo` int(11) DEFAULT NULL, + PRIMARY KEY (`idEspionaje`), + KEY `index` (`Id_Trabajador`,`Fecha`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Estados` +-- + +DROP TABLE IF EXISTS `Estados`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Estados` ( + `Id_Estado` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, + `Estado` varchar(50) DEFAULT NULL, + PRIMARY KEY (`Id_Estado`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Estanterias__` +-- + +DROP TABLE IF EXISTS `Estanterias__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Estanterias__` ( + `Id_Estanterias` int(11) NOT NULL AUTO_INCREMENT, + `w` int(11) DEFAULT NULL, + `d` int(11) DEFAULT NULL, + `modelo` varchar(255) DEFAULT NULL, + PRIMARY KEY (`Id_Estanterias`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Estanterias_distri__` +-- + +DROP TABLE IF EXISTS `Estanterias_distri__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Estanterias_distri__` ( + `idEstanterias_distri` int(11) NOT NULL, + `posinicial` int(11) NOT NULL, + `posfinal` int(11) NOT NULL, + `Id_Estanterias` int(11) NOT NULL, + PRIMARY KEY (`Id_Estanterias`,`idEstanterias_distri`), + KEY `Estanterias_fgkey1_idx` (`Id_Estanterias`), + KEY `est_distrib_fgkey1_idx` (`idEstanterias_distri`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Estanterias_distri_name__` +-- + +DROP TABLE IF EXISTS `Estanterias_distri_name__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Estanterias_distri_name__` ( + `idEstanterias_distri` int(11) NOT NULL AUTO_INCREMENT, + `Descripcion` varchar(255) NOT NULL, + PRIMARY KEY (`idEstanterias_distri`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Facturas` +-- + +DROP TABLE IF EXISTS `Facturas`; +/*!50001 DROP VIEW IF EXISTS `Facturas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Facturas` AS SELECT + 1 AS `factura_id`, + 1 AS `Id_Factura`, + 1 AS `Serie`, + 1 AS `Fecha`, + 1 AS `Importe`, + 1 AS `Id_Cliente`, + 1 AS `odbc_date`, + 1 AS `empresa_id`, + 1 AS `Vencimiento`, + 1 AS `booked`, + 1 AS `Id_Banco`, + 1 AS `siiTypeInvoiceOutFk`, + 1 AS `cplusTaxBreakFk`, + 1 AS `cplusSubjectOpFk`, + 1 AS `siiTrascendencyInvoiceOutFk`, + 1 AS `pdf` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Familias` +-- + +DROP TABLE IF EXISTS `Familias`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Familias` ( + `Familia` varchar(3) NOT NULL, + `Subcuenta` varchar(10) DEFAULT NULL, + `Descripcion` varchar(50) DEFAULT NULL, + PRIMARY KEY (`Familia`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Forms` +-- + +DROP TABLE IF EXISTS `Forms`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Forms` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `titulo` varchar(50) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Gastos` +-- + +DROP TABLE IF EXISTS `Gastos`; +/*!50001 DROP VIEW IF EXISTS `Gastos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Gastos` AS SELECT + 1 AS `Id_Gasto`, + 1 AS `Gasto`, + 1 AS `isWithheld` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Greuges` +-- + +DROP TABLE IF EXISTS `Greuges`; +/*!50001 DROP VIEW IF EXISTS `Greuges`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Greuges` AS SELECT + 1 AS `Id`, + 1 AS `Id_Cliente`, + 1 AS `Comentario`, + 1 AS `Importe`, + 1 AS `Fecha`, + 1 AS `odbc_date`, + 1 AS `Greuges_type_id`, + 1 AS `Id_Ticket` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Greuges_type` +-- + +DROP TABLE IF EXISTS `Greuges_type`; +/*!50001 DROP VIEW IF EXISTS `Greuges_type`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Greuges_type` AS SELECT + 1 AS `Greuges_type_id`, + 1 AS `name` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Grupos` +-- + +DROP TABLE IF EXISTS `Grupos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Grupos` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `Grupo` varchar(45) NOT NULL, + `observation_type_id` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Impresoras` +-- + +DROP TABLE IF EXISTS `Impresoras`; +/*!50001 DROP VIEW IF EXISTS `Impresoras`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Impresoras` AS SELECT + 1 AS `Id_impresora`, + 1 AS `Ruta`, + 1 AS `Impresora`, + 1 AS `referencia`, + 1 AS `isLabeler` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Informes` +-- + +DROP TABLE IF EXISTS `Informes`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Informes` ( + `Id_Informe` tinyint(3) unsigned NOT NULL, + `Informe` varchar(50) DEFAULT NULL, + PRIMARY KEY (`Id_Informe`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Intrastat` +-- + +DROP TABLE IF EXISTS `Intrastat`; +/*!50001 DROP VIEW IF EXISTS `Intrastat`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Intrastat` AS SELECT + 1 AS `Codintrastat`, + 1 AS `Definicion`, + 1 AS `iva_group_id`, + 1 AS `iva_codigo_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Jefes__` +-- + +DROP TABLE IF EXISTS `Jefes__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Jefes__` ( + `Id_Trabajador` int(10) unsigned NOT NULL, + `Id_Jefe` int(10) unsigned NOT NULL, + `Departamento` varchar(45) NOT NULL, + PRIMARY KEY (`Id_Trabajador`,`Id_Jefe`), + KEY `trabajador_jefe_idx` (`Id_Jefe`), + CONSTRAINT `trabajador_jefe` FOREIGN KEY (`Id_Jefe`) REFERENCES `vn`.`worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `trabajador_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn`.`worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Monedas` +-- + +DROP TABLE IF EXISTS `Monedas`; +/*!50001 DROP VIEW IF EXISTS `Monedas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Monedas` AS SELECT + 1 AS `Id_Moneda`, + 1 AS `Moneda`, + 1 AS `Descripcion`, + 1 AS `Cambio` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Monitoring` +-- + +DROP TABLE IF EXISTS `Monitoring`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Monitoring` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `equipo_id` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `user_id` int(10) unsigned NOT NULL, + `form_id` int(11) NOT NULL, + `cliente_id` int(11) NOT NULL, + `ticket_id` int(11) NOT NULL, + `ODBC_TIME` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `equipo_id` (`equipo_id`,`user_id`,`form_id`,`cliente_id`,`ticket_id`), + KEY `user_id` (`user_id`), + KEY `form_id` (`form_id`), + KEY `cliente_id` (`cliente_id`), + KEY `ticket_id` (`ticket_id`), + CONSTRAINT `Monitoring_FK` FOREIGN KEY (`equipo_id`) REFERENCES `vn`.`host` (`code`) ON UPDATE CASCADE, + CONSTRAINT `Monitoring_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `vn`.`worker` (`id`), + CONSTRAINT `Monitoring_ibfk_3` FOREIGN KEY (`form_id`) REFERENCES `Forms` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Movimientos` +-- + +DROP TABLE IF EXISTS `Movimientos`; +/*!50001 DROP VIEW IF EXISTS `Movimientos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Movimientos` AS SELECT + 1 AS `Id_Movimiento`, + 1 AS `Id_Article`, + 1 AS `Id_Ticket`, + 1 AS `Concepte`, + 1 AS `Cantidad`, + 1 AS `Preu`, + 1 AS `Descuento`, + 1 AS `Reservado`, + 1 AS `OK`, + 1 AS `odbc_date`, + 1 AS `CostFixat`, + 1 AS `PrecioFijado`, + 1 AS `quantity`, + 1 AS `isAdded` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Movimientos_avisar` +-- + +DROP TABLE IF EXISTS `Movimientos_avisar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Movimientos_avisar` ( + `Id_Movimiento` int(11) NOT NULL, + `Id_Remitente` int(11) DEFAULT NULL, + PRIMARY KEY (`Id_Movimiento`), + KEY `Movimiento` (`Id_Movimiento`), + KEY `Remitente` (`Id_Remitente`), + CONSTRAINT `Id_Movimientos_avisar_fk` FOREIGN KEY (`Id_Movimiento`) REFERENCES `vn`.`sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Movimientos_componentes` +-- + +DROP TABLE IF EXISTS `Movimientos_componentes`; +/*!50001 DROP VIEW IF EXISTS `Movimientos_componentes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Movimientos_componentes` AS SELECT + 1 AS `Id_Movimiento`, + 1 AS `Id_Componente`, + 1 AS `Valor`, + 1 AS `created`, + 1 AS `greuge` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Movimientos_mark` +-- + +DROP TABLE IF EXISTS `Movimientos_mark`; +/*!50001 DROP VIEW IF EXISTS `Movimientos_mark`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Movimientos_mark` AS SELECT + 1 AS `Id_Movimiento`, + 1 AS `valor`, + 1 AS `odbc_date`, + 1 AS `original_quantity`, + 1 AS `Id_Trabajador`, + 1 AS `Id_Movimiento_mark`, + 1 AS `stateFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Movimientos_revisar` +-- + +DROP TABLE IF EXISTS `Movimientos_revisar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Movimientos_revisar` ( + `Id_Movimiento` int(11) NOT NULL, + `Comentario` varchar(255) DEFAULT NULL, + `Revisado` tinyint(1) NOT NULL DEFAULT 0, + `Id_Remitente` int(11) DEFAULT NULL, + `Id_Destinatario` int(11) DEFAULT NULL, + PRIMARY KEY (`Id_Movimiento`), + KEY `Remitente` (`Id_Remitente`), + KEY `Destinatario` (`Id_Destinatario`), + CONSTRAINT `Movimientos_revisar_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `vn`.`sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Objetivos__` +-- + +DROP TABLE IF EXISTS `Objetivos__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Objetivos__` ( + `Periodo` int(11) NOT NULL, + `Objetivo` double NOT NULL, + PRIMARY KEY (`Periodo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Ordenes` +-- + +DROP TABLE IF EXISTS `Ordenes`; +/*!50001 DROP VIEW IF EXISTS `Ordenes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Ordenes` AS SELECT + 1 AS `Id_ORDEN`, + 1 AS `ORDEN`, + 1 AS `requesterFk`, + 1 AS `attenderFk`, + 1 AS `CANTIDAD`, + 1 AS `Id_ARTICLE`, + 1 AS `PRECIOMAX`, + 1 AS `isOk`, + 1 AS `Id_Movimiento`, + 1 AS `ticketFk`, + 1 AS `COMENTARIO`, + 1 AS `odbc_date`, + 1 AS `datORDEN`, + 1 AS `datTICKET`, + 1 AS `CodVENDEDOR`, + 1 AS `CodCOMPRADOR`, + 1 AS `Id_CLIENTE`, + 1 AS `TOTAL`, + 1 AS `datCOMPRA` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Origen` +-- + +DROP TABLE IF EXISTS `Origen`; +/*!50001 DROP VIEW IF EXISTS `Origen`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Origen` AS SELECT + 1 AS `id`, + 1 AS `Abreviatura`, + 1 AS `Origen`, + 1 AS `Id_Paises`, + 1 AS `warehouse_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Pagares` +-- + +DROP TABLE IF EXISTS `Pagares`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Pagares` ( + `kk_Vencimiento` datetime DEFAULT NULL, + `kk_Importe` double DEFAULT 0, + `Fechaemision` timestamp NOT NULL DEFAULT current_timestamp(), + `Id_Pagare` int(11) NOT NULL AUTO_INCREMENT, + `Concepto` varchar(50) DEFAULT NULL, + `kk_id_proveedor` int(11) DEFAULT NULL, + `kk_empresa_id` smallint(5) unsigned DEFAULT NULL, + `pago_id` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`Id_Pagare`), + KEY `empresa_id` (`kk_empresa_id`), + KEY `pago_id` (`pago_id`), + CONSTRAINT `Pagares_ibfk_2` FOREIGN KEY (`pago_id`) REFERENCES `vn`.`payment` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Paises` +-- + +DROP TABLE IF EXISTS `Paises`; +/*!50001 DROP VIEW IF EXISTS `Paises`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Paises` AS SELECT + 1 AS `Id`, + 1 AS `Pais`, + 1 AS `CEE`, + 1 AS `isUeeMember`, + 1 AS `Codigo`, + 1 AS `Id_Moneda`, + 1 AS `geoFk`, + 1 AS `ibanLength`, + 1 AS `hasDailyInvoice` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Permisos__` +-- + +DROP TABLE IF EXISTS `Permisos__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Permisos__` ( + `Id_Grupo` int(10) unsigned NOT NULL, + `Id_Trabajador` int(10) unsigned NOT NULL, + `empresa_id` int(10) unsigned NOT NULL DEFAULT 442, + PRIMARY KEY (`Id_Grupo`,`Id_Trabajador`), + KEY `empresa_id` (`empresa_id`), + KEY `Permisos_ibfk_3_idx` (`Id_Trabajador`), + CONSTRAINT `PermisosCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `Permisos___ibfk_2` FOREIGN KEY (`Id_Grupo`) REFERENCES `Grupos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `Permisos___ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn`.`worker` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `PreciosEspeciales` +-- + +DROP TABLE IF EXISTS `PreciosEspeciales`; +/*!50001 DROP VIEW IF EXISTS `PreciosEspeciales`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `PreciosEspeciales` AS SELECT + 1 AS `Id_PrecioEspecial`, + 1 AS `Id_Cliente`, + 1 AS `Id_Article`, + 1 AS `PrecioEspecial` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Prioridades` +-- + +DROP TABLE IF EXISTS `Prioridades`; +/*!50001 DROP VIEW IF EXISTS `Prioridades`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Prioridades` AS SELECT + 1 AS `Id_Prioridad`, + 1 AS `Prioridad` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Proveedores` +-- + +DROP TABLE IF EXISTS `Proveedores`; +/*!50001 DROP VIEW IF EXISTS `Proveedores`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Proveedores` AS SELECT + 1 AS `Id_Proveedor`, + 1 AS `Proveedor`, + 1 AS `cuenta`, + 1 AS `pais_id`, + 1 AS `NIF`, + 1 AS `Agricola`, + 1 AS `Telefono`, + 1 AS `cuentaret`, + 1 AS `ComisionProveedor`, + 1 AS `odbc_time`, + 1 AS `postcode_id`, + 1 AS `active`, + 1 AS `Domicilio`, + 1 AS `Localidad`, + 1 AS `province_id`, + 1 AS `codpos`, + 1 AS `pay_met_id`, + 1 AS `pay_dem_id`, + 1 AS `Alias`, + 1 AS `oficial`, + 1 AS `workerFk`, + 1 AS `pay_day`, + 1 AS `serious`, + 1 AS `notas`, + 1 AS `taxTypeSageFk`, + 1 AS `withholdingSageFk`, + 1 AS `isTrucker`, + 1 AS `transactionTypeSageFk`, + 1 AS `supplierActivityFk`, + 1 AS `healthRegister`, + 1 AS `isPayMethodChecked` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Proveedores_cargueras` +-- + +DROP TABLE IF EXISTS `Proveedores_cargueras`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Proveedores_cargueras` ( + `Id_Proveedor` int(10) unsigned NOT NULL, + PRIMARY KEY (`Id_Proveedor`), + CONSTRAINT `Proveedores_cargueras_supplierFk` FOREIGN KEY (`Id_Proveedor`) REFERENCES `vn`.`supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla de espcializacion para señalar las compañias que prestan servicio de transitario'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Proveedores_comunicados` +-- + +DROP TABLE IF EXISTS `Proveedores_comunicados`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Proveedores_comunicados` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Id_Proveedor` int(10) unsigned NOT NULL, + `escrito_id` int(11) NOT NULL, + `fecha` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + KEY `Proveedor` (`Id_Proveedor`), + KEY `Escrito` (`escrito_id`), + CONSTRAINT `Proveedores_comunicados_ibfk_4` FOREIGN KEY (`escrito_id`) REFERENCES `Proveedores_escritos` (`id`) ON UPDATE CASCADE, + CONSTRAINT `Proveedores_comunicados_supplierFk` FOREIGN KEY (`Id_Proveedor`) REFERENCES `vn`.`supplier` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Proveedores_escritos` +-- + +DROP TABLE IF EXISTS `Proveedores_escritos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Proveedores_escritos` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `escrito` varchar(45) NOT NULL, + `informe` varchar(45) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Proveedores_gestdoc` +-- + +DROP TABLE IF EXISTS `Proveedores_gestdoc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Proveedores_gestdoc` ( + `Id_Proveedor` int(11) NOT NULL, + `gestdoc_id` int(11) NOT NULL, + PRIMARY KEY (`Id_Proveedor`,`gestdoc_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Recibos` +-- + +DROP TABLE IF EXISTS `Recibos`; +/*!50001 DROP VIEW IF EXISTS `Recibos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Recibos` AS SELECT + 1 AS `Id`, + 1 AS `Id_Factura`, + 1 AS `Entregado`, + 1 AS `Fechacobro`, + 1 AS `Id_Trabajador`, + 1 AS `Id_Banco`, + 1 AS `Id_Cliente`, + 1 AS `odbc_date`, + 1 AS `empresa_id`, + 1 AS `conciliado` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Recibos_recorded__` +-- + +DROP TABLE IF EXISTS `Recibos_recorded__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Recibos_recorded__` ( + `Id_Recibos` int(11) NOT NULL, + `recorded` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Marcado si se ha contabilizado', + PRIMARY KEY (`Id_Recibos`), + CONSTRAINT `Recibos_recorded___ibfk_1` FOREIGN KEY (`Id_Recibos`) REFERENCES `vn`.`receipt` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Remesas` +-- + +DROP TABLE IF EXISTS `Remesas`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Remesas` ( + `Id_Remesa` int(11) NOT NULL AUTO_INCREMENT, + `Fecha Remesa` datetime DEFAULT NULL, + `Banco` int(11) DEFAULT 0, + `empresa_id` int(10) unsigned NOT NULL DEFAULT 442, + PRIMARY KEY (`Id_Remesa`), + KEY `Id_Banco` (`Banco`), + KEY `empresa_id` (`empresa_id`), + CONSTRAINT `RemesasCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON UPDATE CASCADE, + CONSTRAINT `Remesas_ibfk_2` FOREIGN KEY (`Banco`) REFERENCES `vn`.`accounting` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Reservas__` +-- + +DROP TABLE IF EXISTS `Reservas__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Reservas__` ( + `Id_Reserva` int(11) NOT NULL AUTO_INCREMENT, + `Id_Ticket` int(11) DEFAULT 0, + `Fecha` datetime DEFAULT NULL, + `Alias` varchar(50) DEFAULT NULL, + `article` varchar(50) DEFAULT NULL, + `medida` varchar(50) DEFAULT NULL, + `categoria` varchar(50) DEFAULT NULL, + `color` varchar(50) DEFAULT NULL, + `origen` varchar(50) DEFAULT NULL, + `cantidad` int(11) DEFAULT 0, + `Id_Article` double DEFAULT 0, + `buyFk` int(11) NOT NULL, + `grouping` int(11) DEFAULT NULL, + `packing` int(11) DEFAULT NULL, + PRIMARY KEY (`Id_Reserva`), + KEY `Id_1` (`Id_Ticket`), + KEY `Id_Article` (`Id_Article`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Rutas` +-- + +DROP TABLE IF EXISTS `Rutas`; +/*!50001 DROP VIEW IF EXISTS `Rutas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Rutas` AS SELECT + 1 AS `Id_Ruta`, + 1 AS `Id_Trabajador`, + 1 AS `Fecha`, + 1 AS `Id_Vehiculo`, + 1 AS `Id_Agencia`, + 1 AS `Hora`, + 1 AS `ok`, + 1 AS `km_start`, + 1 AS `km_end`, + 1 AS `date_start`, + 1 AS `date_end`, + 1 AS `gestdoc_id`, + 1 AS `cost`, + 1 AS `m3`, + 1 AS `description` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Rutas_Master` +-- + +DROP TABLE IF EXISTS `Rutas_Master`; +/*!50001 DROP VIEW IF EXISTS `Rutas_Master`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Rutas_Master` AS SELECT + 1 AS `id`, + 1 AS `warehouse_id`, + 1 AS `km`, + 1 AS `bultos`, + 1 AS `vehiculos_coste`, + 1 AS `personal_coste`, + 1 AS `vehiculos_numero`, + 1 AS `personal_numero`, + 1 AS `gasoil`, + 1 AS `autonomos`, + 1 AS `año`, + 1 AS `mes`, + 1 AS `gastos`, + 1 AS `bultos_autonomos`, + 1 AS `coste_km`, + 1 AS `coste_bulto`, + 1 AS `coste_bulto_autonomo`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Rutas_monitor` +-- + +DROP TABLE IF EXISTS `Rutas_monitor`; +/*!50001 DROP VIEW IF EXISTS `Rutas_monitor`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Rutas_monitor` AS SELECT + 1 AS `Id_Ruta`, + 1 AS `name`, + 1 AS `Ubicacion`, + 1 AS `pedidosEncajados`, + 1 AS `pedidosLibres`, + 1 AS `pedidosProduccion`, + 1 AS `bultos`, + 1 AS `notas`, + 1 AS `fecha`, + 1 AS `dockFk`, + 1 AS `m3`, + 1 AS `priority`, + 1 AS `etd`, + 1 AS `expeditionTruckFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Saldos_Prevision` +-- + +DROP TABLE IF EXISTS `Saldos_Prevision`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Saldos_Prevision` ( + `Saldos_Prevision_id` int(11) NOT NULL AUTO_INCREMENT, + `Descripcion` varchar(45) DEFAULT NULL, + `Importe` double NOT NULL DEFAULT 0, + `Fecha` date NOT NULL, + `Id_Banco` int(11) DEFAULT NULL, + `empresa_id` int(10) unsigned NOT NULL DEFAULT 442, + PRIMARY KEY (`Saldos_Prevision_id`), + KEY `Fecha_indice` (`Fecha`), + KEY `banco_prevision_idx` (`Id_Banco`), + KEY `empresa_prevision_idx` (`empresa_id`), + CONSTRAINT `Saldos_PrevisionCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON UPDATE CASCADE, + CONSTRAINT `banco_prevision` FOREIGN KEY (`Id_Banco`) REFERENCES `vn`.`accounting` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Series` +-- + +DROP TABLE IF EXISTS `Series`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Series` ( + `Id_Serie` varchar(2) NOT NULL, + `Serie` varchar(30) DEFAULT NULL, + `Cuenta` varchar(10) DEFAULT NULL, + PRIMARY KEY (`Id_Serie`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Split_lines` +-- + +DROP TABLE IF EXISTS `Split_lines`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Split_lines` ( + `Id_Split_lines` int(11) NOT NULL AUTO_INCREMENT, + `Id_Split` int(11) NOT NULL, + `Id_Article` int(11) DEFAULT NULL, + `Id_Compra` int(11) DEFAULT NULL, + PRIMARY KEY (`Id_Split_lines`), + KEY `Id_Split` (`Id_Split`), + KEY `Id_Compra` (`Id_Compra`), + CONSTRAINT `Id_Compra` FOREIGN KEY (`Id_Compra`) REFERENCES `vn`.`buy` (`id`) 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 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `Splits` +-- + +DROP TABLE IF EXISTS `Splits`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Splits` ( + `Id_Split` int(11) NOT NULL AUTO_INCREMENT, + `Id_Ticket` int(11) DEFAULT NULL, + `Id_Entrada` int(11) DEFAULT NULL, + `Fecha` datetime DEFAULT NULL, + `Notas` varchar(255) DEFAULT NULL, + PRIMARY KEY (`Id_Split`), + KEY `Id_Entrada` (`Id_Entrada`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Tickets` +-- + +DROP TABLE IF EXISTS `Tickets`; +/*!50001 DROP VIEW IF EXISTS `Tickets`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Tickets` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `Id_Cliente`, + 1 AS `warehouse_id`, + 1 AS `Fecha`, + 1 AS `landing`, + 1 AS `Alias`, + 1 AS `Factura`, + 1 AS `Id_Consigna`, + 1 AS `Localizacion`, + 1 AS `Solucion`, + 1 AS `Id_Ruta`, + 1 AS `empresa_id`, + 1 AS `Id_Agencia`, + 1 AS `Prioridad`, + 1 AS `Bultos`, + 1 AS `isDeleted`, + 1 AS `odbc_date`, + 1 AS `Id_Trabajador`, + 1 AS `Observaciones`, + 1 AS `Firmado`, + 1 AS `Etiquetasemitidas`, + 1 AS `PedidoImpreso`, + 1 AS `Hora`, + 1 AS `blocked`, + 1 AS `priority`, + 1 AS `boxed`, + 1 AS `zoneFk`, + 1 AS `totalWithVat`, + 1 AS `totalWithoutVat` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Tickets_stack` +-- + +DROP TABLE IF EXISTS `Tickets_stack`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Tickets_stack` ( + `Id_Ticket` int(11) NOT NULL, + `orden` smallint(5) unsigned NOT NULL, + `label_number` smallint(6) DEFAULT 0, + `preparado` tinyint(4) DEFAULT 0, + PRIMARY KEY (`Id_Ticket`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Orden para imprimir los F5.Se borra autom. lo de 2 meses'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Tickets_state` +-- + +DROP TABLE IF EXISTS `Tickets_state`; +/*!50001 DROP VIEW IF EXISTS `Tickets_state`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Tickets_state` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `inter_id`, + 1 AS `state_name` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Tickets_turno` +-- + +DROP TABLE IF EXISTS `Tickets_turno`; +/*!50001 DROP VIEW IF EXISTS `Tickets_turno`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Tickets_turno` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `weekDay` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Tintas` +-- + +DROP TABLE IF EXISTS `Tintas`; +/*!50001 DROP VIEW IF EXISTS `Tintas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Tintas` AS SELECT + 1 AS `Id_Tinta`, + 1 AS `name`, + 1 AS `Tinta`, + 1 AS `Orden`, + 1 AS `ball`, + 1 AS `cargex`, + 1 AS `colorHex` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Tipos` +-- + +DROP TABLE IF EXISTS `Tipos`; +/*!50001 DROP VIEW IF EXISTS `Tipos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Tipos` AS SELECT + 1 AS `tipo_id`, + 1 AS `Id_Tipo`, + 1 AS `Tipo`, + 1 AS `Orden`, + 1 AS `reino_id`, + 1 AS `Id_Trabajador`, + 1 AS `life`, + 1 AS `isPackaging`, + 1 AS `density`, + 1 AS `inventory`, + 1 AS `odbc_date`, + 1 AS `confeccion`, + 1 AS `Temperatura`, + 1 AS `promo`, + 1 AS `maneuver`, + 1 AS `target`, + 1 AS `top_margin`, + 1 AS `profit` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Tipos_f11` +-- + +DROP TABLE IF EXISTS `Tipos_f11`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Tipos_f11` ( + `f11_id` tinyint(4) NOT NULL AUTO_INCREMENT, + `description` varchar(15) NOT NULL, + PRIMARY KEY (`f11_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `Trabajadores` +-- + +DROP TABLE IF EXISTS `Trabajadores`; +/*!50001 DROP VIEW IF EXISTS `Trabajadores`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Trabajadores` AS SELECT + 1 AS `Id_Trabajador`, + 1 AS `Nombre`, + 1 AS `user_id`, + 1 AS `phone`, + 1 AS `boss`, + 1 AS `Foto`, + 1 AS `DniExpiration`, + 1 AS `CodigoTrabajador`, + 1 AS `Apellidos`, + 1 AS `hasMachineryAuthorized`, + 1 AS `sub`, + 1 AS `marital_status` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Tramos` +-- + +DROP TABLE IF EXISTS `Tramos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Tramos` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `Tramo` time NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `Tramo` (`Tramo`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `V_edi_item_track` +-- + +DROP TABLE IF EXISTS `V_edi_item_track`; +/*!50001 DROP VIEW IF EXISTS `V_edi_item_track`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `V_edi_item_track` AS SELECT + 1 AS `item_id`, + 1 AS `s1`, + 1 AS `s2`, + 1 AS `s3`, + 1 AS `s4`, + 1 AS `s5`, + 1 AS `s6`, + 1 AS `kop`, + 1 AS `pac`, + 1 AS `cat`, + 1 AS `ori`, + 1 AS `pro`, + 1 AS `sub`, + 1 AS `package`, + 1 AS `item` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Vehiculos` +-- + +DROP TABLE IF EXISTS `Vehiculos`; +/*!50001 DROP VIEW IF EXISTS `Vehiculos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Vehiculos` AS SELECT + 1 AS `Id_Vehiculo`, + 1 AS `Matricula`, + 1 AS `Marca`, + 1 AS `Modelo`, + 1 AS `empresa_id`, + 1 AS `warehouseFk`, + 1 AS `description`, + 1 AS `m3`, + 1 AS `active`, + 1 AS `deliveryPointFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `Vehiculos_consumo` +-- + +DROP TABLE IF EXISTS `Vehiculos_consumo`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Vehiculos_consumo` ( + `Vehiculos_consumo_id` int(11) NOT NULL AUTO_INCREMENT, + `Id_Vehiculo` int(10) unsigned NOT NULL, + `fecha` date NOT NULL, + `km` int(20) unsigned NOT NULL, + `litros` double unsigned NOT NULL, + `precio` double unsigned NOT NULL, + `adblue` decimal(10,2) NOT NULL DEFAULT 0.00, + `peajes` double DEFAULT NULL, + `descuento` double DEFAULT NULL, + `silla` int(11) NOT NULL DEFAULT 0 COMMENT 'indica si han repostado en la gasolinera de la rotonda', + `odbc_date` timestamp NULL DEFAULT current_timestamp(), + `otros` double DEFAULT NULL, + `fuelTypeFk` varchar(45) DEFAULT NULL, + `proveedoresFk` int(10) unsigned DEFAULT NULL, + `liters100km` decimal(10,2) DEFAULT NULL COMMENT 'se rellena en Vehiculos_consumo_beforeInsert y son los litros consumidos a los 100 kilometros', + `gasoline` decimal(10,2) NOT NULL DEFAULT 0.00, + PRIMARY KEY (`Vehiculos_consumo_id`,`Id_Vehiculo`), + KEY `fk_Vehiculos_consumo_Vehiculos_idx` (`Id_Vehiculo`), + KEY `fuelTypeFk_idx` (`fuelTypeFk`), + KEY `proveedoresFk_idx` (`proveedoresFk`), + CONSTRAINT `Vehiculos_consumo_supplierFk` FOREIGN KEY (`proveedoresFk`) REFERENCES `vn`.`supplier` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_Vehiculos_consumo_Vehiculos` FOREIGN KEY (`Id_Vehiculo`) REFERENCES `vn`.`vehicle` (`id`) ON UPDATE CASCADE, + CONSTRAINT `fuelTypeFk` FOREIGN KEY (`fuelTypeFk`) REFERENCES `vn`.`fuelType` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */; + +-- +-- Temporary table structure for view `VerEspionaje` +-- + +DROP TABLE IF EXISTS `VerEspionaje`; +/*!50001 DROP VIEW IF EXISTS `VerEspionaje`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `VerEspionaje` AS SELECT + 1 AS `CodigoTrabajador`, + 1 AS `Fecha`, + 1 AS `HoraEntrada`, + 1 AS `HoraSalida`, + 1 AS `Id_Equipo`, + 1 AS `Id_Trabajador` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `Vistas` +-- + +DROP TABLE IF EXISTS `Vistas`; +/*!50001 DROP VIEW IF EXISTS `Vistas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `Vistas` AS SELECT + 1 AS `vista_id`, + 1 AS `code`, + 1 AS `vista` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `XDiario` +-- + +DROP TABLE IF EXISTS `XDiario`; +/*!50001 DROP VIEW IF EXISTS `XDiario`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `XDiario` AS SELECT + 1 AS `id`, + 1 AS `ASIEN`, + 1 AS `FECHA`, + 1 AS `SUBCTA`, + 1 AS `CONTRA`, + 1 AS `CONCEPTO`, + 1 AS `EURODEBE`, + 1 AS `EUROHABER`, + 1 AS `BASEEURO`, + 1 AS `SERIE`, + 1 AS `FACTURA`, + 1 AS `IVA`, + 1 AS `RECEQUIV`, + 1 AS `CLAVE`, + 1 AS `CAMBIO`, + 1 AS `DEBEME`, + 1 AS `HABERME`, + 1 AS `AUXILIAR`, + 1 AS `MONEDAUSO`, + 1 AS `TIPOOPE`, + 1 AS `NFACTICK`, + 1 AS `TERIDNIF`, + 1 AS `TERNIF`, + 1 AS `TERNOM`, + 1 AS `OPBIENES`, + 1 AS `L340`, + 1 AS `enlazado`, + 1 AS `FECHA_EX`, + 1 AS `LRECT349`, + 1 AS `empresa_id`, + 1 AS `LDIFADUAN`, + 1 AS `METAL`, + 1 AS `METALIMP`, + 1 AS `CLIENTE`, + 1 AS `METALEJE`, + 1 AS `FECHA_OP`, + 1 AS `FACTURAEX`, + 1 AS `TIPOCLAVE`, + 1 AS `TIPOEXENCI`, + 1 AS `TIPONOSUJE`, + 1 AS `TIPOFACT`, + 1 AS `TIPORECTIF`, + 1 AS `SERIE_RT`, + 1 AS `FACTU_RT`, + 1 AS `BASEIMP_RT`, + 1 AS `BASEIMP_RF`, + 1 AS `RECTIFICA`, + 1 AS `FECHA_RT`, + 1 AS `created`, + 1 AS `updated`, + 1 AS `FECREGCON`, + 1 AS `enlazadoSage` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `accion_dits` +-- + +DROP TABLE IF EXISTS `accion_dits`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `accion_dits` ( + `idaccion_dits` int(11) NOT NULL AUTO_INCREMENT, + `accion` varchar(255) DEFAULT NULL, + PRIMARY KEY (`idaccion_dits`), + UNIQUE KEY `accion_UNIQUE` (`accion`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `account_conciliacion` +-- + +DROP TABLE IF EXISTS `account_conciliacion`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `account_conciliacion` ( + `idaccount_conciliacion` int(11) NOT NULL AUTO_INCREMENT, + `Id_Proveedores_account` mediumint(8) unsigned NOT NULL, + `Fechaoperacion` datetime NOT NULL, + `FechaValor` datetime NOT NULL, + `importe` double NOT NULL, + `Concepto` varchar(255) DEFAULT NULL, + `DebeHaber` smallint(6) NOT NULL, + `id_calculated` varchar(255) DEFAULT NULL, + `odbc_date` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`idaccount_conciliacion`), + UNIQUE KEY `idaccount_conciliacion_UNIQUE` (`idaccount_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 `vn`.`supplierAccount` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `account_detail` +-- + +DROP TABLE IF EXISTS `account_detail`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `account_detail` ( + `account_detail_id` int(11) NOT NULL AUTO_INCREMENT, + `value` varchar(50) NOT NULL, + `account_detail_type_id` int(11) NOT NULL, + `Id_Proveedores_account` mediumint(8) unsigned NOT NULL, + PRIMARY KEY (`account_detail_id`), + KEY `fk_account_detail_account_detail_type1_idx` (`account_detail_type_id`), + KEY `fk_account_detail_Proveedores_account1_idx` (`Id_Proveedores_account`), + CONSTRAINT `fk_account_detail_account_detail_type1` FOREIGN KEY (`account_detail_type_id`) REFERENCES `account_detail_type` (`account_detail_type_id`) ON UPDATE CASCADE, + CONSTRAINT `fk_account_detail_account_id_proveedores_account` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `vn`.`supplierAccount` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `account_detail_type` +-- + +DROP TABLE IF EXISTS `account_detail_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `account_detail_type` ( + `account_detail_type_id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(255) DEFAULT NULL, + PRIMARY KEY (`account_detail_type_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `agencia_descuadre` +-- + +DROP TABLE IF EXISTS `agencia_descuadre`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `agencia_descuadre` ( + `agencia_descuadre_id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Id_Ticket` int(11) NOT NULL, + `date` date NOT NULL, + `price` double(7,2) NOT NULL, + `Consignatario` varchar(50) NOT NULL, + `Tipo` varchar(30) NOT NULL, + PRIMARY KEY (`agencia_descuadre_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `agency` +-- + +DROP TABLE IF EXISTS `agency`; +/*!50001 DROP VIEW IF EXISTS `agency`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `agency` AS SELECT + 1 AS `agency_id`, + 1 AS `name`, + 1 AS `warehouse_id`, + 1 AS `warehouse_alias_id`, + 1 AS `propios`, + 1 AS `workCenterFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `agency_hour` +-- + +DROP TABLE IF EXISTS `agency_hour`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `agency_hour` ( + `agency_hour_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `week_day` tinyint(3) unsigned DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', + `agency_id` smallint(5) unsigned DEFAULT NULL, + `warehouse_id` smallint(5) unsigned DEFAULT NULL, + `province_id` smallint(5) unsigned DEFAULT NULL, + `subtract_day` tinyint(10) unsigned NOT NULL COMMENT 'dias a restar de la Fecha de entrega', + `max_hour` tinyint(3) unsigned NOT NULL COMMENT 'maxima hora hasta la cual se pueden hacer pedidos', + PRIMARY KEY (`agency_hour_id`), + UNIQUE KEY `week_day` (`week_day`,`agency_id`,`warehouse_id`,`province_id`,`max_hour`), + KEY `agency_id` (`agency_id`), + KEY `warehouse_id` (`warehouse_id`), + KEY `province_id` (`province_id`), + CONSTRAINT `agency_hour_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `vn`.`agency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `agency_hour_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `agency_hour_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `vn`.`province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `agency_warehouse` +-- + +DROP TABLE IF EXISTS `agency_warehouse`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `agency_warehouse` ( + `agency_id` smallint(5) unsigned NOT NULL, + `warehouse_id` smallint(5) unsigned NOT NULL DEFAULT 1, + `Vista` tinyint(3) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`agency_id`,`warehouse_id`), + KEY `warehouse_id` (`warehouse_id`), + CONSTRAINT `agency_warehouse_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `vn`.`agency` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `agency_warehouse_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Indica la vista para cada agencia'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `airline` +-- + +DROP TABLE IF EXISTS `airline`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `airline` ( + `airline_id` smallint(2) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(20) NOT NULL, + PRIMARY KEY (`airline_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `airport` +-- + +DROP TABLE IF EXISTS `airport`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `airport` ( + `airport_id` varchar(3) NOT NULL, + `name` varchar(30) DEFAULT NULL, + PRIMARY KEY (`airport_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `albaran` +-- + +DROP TABLE IF EXISTS `albaran`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `albaran` ( + `albaran_id` int(11) NOT NULL AUTO_INCREMENT, + `ref` varchar(45) DEFAULT NULL, + `note` varchar(150) DEFAULT NULL, + `fecha` date NOT NULL, + `fecha_entrega` date DEFAULT NULL, + `valor` double DEFAULT NULL, + `Id_Proveedor` int(10) unsigned NOT NULL, + `empresa_id` int(10) unsigned NOT NULL, + `warehouse_id` smallint(6) unsigned NOT NULL, + `albaran_state_id` int(11) NOT NULL, + `Id_Trabajador` int(10) unsigned NOT NULL COMMENT 'Id_Trabajador hace referencia a la persona que ha introducido el albarán', + `Id_Responsable` int(10) unsigned NOT NULL, + `department_id` int(11) NOT NULL, + `recibida_id` mediumint(8) unsigned DEFAULT NULL, + `farmingFk` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`albaran_id`), + KEY `fk_albaran_Proveedores_idx` (`Id_Proveedor`), + KEY `fk_albaran_empresa1_idx` (`empresa_id`), + KEY `fk_albaran_warehouse1_idx` (`warehouse_id`), + KEY `fk_albaran_albaran_state1_idx` (`albaran_state_id`), + KEY `fk_albaran_Trabajadores1_idx` (`Id_Trabajador`), + KEY `fk_albaran_Trabajadores2_idx` (`Id_Responsable`), + KEY `fk_albaran_department1_idx` (`department_id`), + KEY `fk_albaran_recibida_idx` (`recibida_id`), + KEY `albaran_FK` (`farmingFk`), + CONSTRAINT `albaranCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON UPDATE CASCADE, + CONSTRAINT `albaran_FK` FOREIGN KEY (`farmingFk`) REFERENCES `vn`.`farming` (`id`), + CONSTRAINT `albaran_supplierFk` FOREIGN KEY (`Id_Proveedor`) REFERENCES `vn`.`supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `fk_albaran_Trabajadores1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `fk_albaran_Trabajadores2` FOREIGN KEY (`Id_Responsable`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `fk_albaran_albaran_state1` FOREIGN KEY (`albaran_state_id`) REFERENCES `albaran_state` (`albaran_state_id`) ON UPDATE CASCADE, + CONSTRAINT `fk_albaran_recibida` FOREIGN KEY (`recibida_id`) REFERENCES `vn`.`invoiceIn` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `fk_albaran_warehouse1` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `albaran_gestdoc` +-- + +DROP TABLE IF EXISTS `albaran_gestdoc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `albaran_gestdoc` ( + `gestdoc_id` int(11) NOT NULL, + `albaran_id` int(11) NOT NULL, + PRIMARY KEY (`gestdoc_id`,`albaran_id`), + KEY `fk_albaran_gestdoc_gestdoc1_idx` (`gestdoc_id`), + KEY `fk_albaran_gestdoc_albaran1_idx` (`albaran_id`), + CONSTRAINT `albaran_gestdoc_FK` FOREIGN KEY (`gestdoc_id`) REFERENCES `vn`.`dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_albaran_gestdoc_albaran1` FOREIGN KEY (`albaran_id`) REFERENCES `albaran` (`albaran_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `albaran_state` +-- + +DROP TABLE IF EXISTS `albaran_state`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `albaran_state` ( + `albaran_state_id` int(11) NOT NULL AUTO_INCREMENT, + `state` varchar(45) NOT NULL, + PRIMARY KEY (`albaran_state_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `awb` +-- + +DROP TABLE IF EXISTS `awb`; +/*!50001 DROP VIEW IF EXISTS `awb`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `awb` AS SELECT + 1 AS `id`, + 1 AS `codigo`, + 1 AS `bultos`, + 1 AS `peso`, + 1 AS `MYSQL_TIME`, + 1 AS `transitario_id`, + 1 AS `iva_id`, + 1 AS `duakk`, + 1 AS `gestdoc_id`, + 1 AS `importe`, + 1 AS `carguera_id`, + 1 AS `m3`, + 1 AS `stems`, + 1 AS `flight_id`, + 1 AS `volume_weight`, + 1 AS `hb`, + 1 AS `rate`, + 1 AS `booked`, + 1 AS `issued`, + 1 AS `operated`, + 1 AS `bookEntried`, + 1 AS `invoiceInFk`, + 1 AS `isChecked`, + 1 AS `isTransitoryChecked`, + 1 AS `year`, + 1 AS `invoiceInPaletizedFk`, + 1 AS `observation`, + 1 AS `hasFreightPrepaid`, + 1 AS `propertyNumber` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `awb_component` +-- + +DROP TABLE IF EXISTS `awb_component`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_component` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `awb_id` smallint(11) unsigned DEFAULT NULL, + `Id_Proveedor` int(11) NOT NULL, + `Fecha` date NOT NULL, + `awb_component_type_id` mediumint(3) unsigned DEFAULT NULL, + `awb_role_id` tinyint(1) unsigned NOT NULL DEFAULT 1, + `awb_unit_id` varchar(10) DEFAULT NULL, + `value` decimal(10,2) DEFAULT NULL, + `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT 2, + `recibida_id` mediumint(8) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_idx` (`awb_id`,`Id_Proveedor`,`awb_component_type_id`,`Fecha`), + KEY `Id_Moneda` (`Id_Moneda`), + KEY `awb_component_fk` (`awb_component_type_id`), + KEY `awb_role_fk` (`awb_role_id`), + KEY `awb_unit_fk` (`awb_unit_id`), + CONSTRAINT `Id_Monedafk` FOREIGN KEY (`Id_Moneda`) REFERENCES `vn`.`currency` (`id`) ON DELETE CASCADE, + 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 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `awb_component_template` +-- + +DROP TABLE IF EXISTS `awb_component_template`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_component_template` ( + `awb_component_template_id` int(11) NOT NULL AUTO_INCREMENT, + `carguera_id` int(11) DEFAULT NULL, + `airport_in` varchar(3) DEFAULT NULL, + `airport_out` varchar(3) DEFAULT NULL, + `airline_id` smallint(2) unsigned DEFAULT NULL, + `awb_component_type_id` mediumint(3) unsigned NOT NULL, + `Fecha` date NOT NULL, + `awb_role_id` tinyint(1) unsigned NOT NULL, + `awb_unit_id` varchar(10) DEFAULT NULL, + `value` decimal(10,3) DEFAULT NULL, + `max_value` decimal(10,2) unsigned DEFAULT NULL, + `min_value` decimal(10,2) unsigned DEFAULT NULL, + `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT 2, + `days` varchar(7) DEFAULT NULL, + PRIMARY KEY (`awb_component_template_id`), + UNIQUE KEY `carguera_id_UNIQUE` (`carguera_id`,`airport_in`,`airport_out`,`airline_id`,`awb_component_type_id`,`Fecha`,`days`), + KEY `Id_Moneda` (`Id_Moneda`), + KEY `airline_idx` (`airline_id`), + KEY `role_idx` (`awb_role_id`), + KEY `awb_unit_fk1` (`awb_unit_id`), + KEY `awb_component_template_FK` (`awb_component_type_id`), + CONSTRAINT `Id_Moneda` FOREIGN KEY (`Id_Moneda`) REFERENCES `vn`.`currency` (`id`) ON UPDATE CASCADE, + CONSTRAINT `awb_component_template_FK` FOREIGN KEY (`awb_component_type_id`) REFERENCES `awb_component_type` (`awb_component_type_id`) ON UPDATE CASCADE, + CONSTRAINT `awb_component_template_FK_1` FOREIGN KEY (`airline_id`) REFERENCES `airline` (`airline_id`) 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 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `awb_component_type` +-- + +DROP TABLE IF EXISTS `awb_component_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_component_type` ( + `awb_component_type_id` mediumint(3) unsigned NOT NULL AUTO_INCREMENT, + `description` varchar(45) DEFAULT NULL, + `hasStems` tinyint(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`awb_component_type_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT=' '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `awb_gestdoc` +-- + +DROP TABLE IF EXISTS `awb_gestdoc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_gestdoc` ( + `awb_gestdoc_id` int(11) NOT NULL AUTO_INCREMENT, + `awb_id` smallint(11) unsigned NOT NULL, + `gestdoc_id` int(11) NOT NULL, + PRIMARY KEY (`awb_gestdoc_id`), + KEY `awb_gestdoc_awb_fk` (`awb_id`), + KEY `awb_gestdoc_gestdoc_fk` (`gestdoc_id`), + CONSTRAINT `awb_gestdoc_awb_fk` FOREIGN KEY (`awb_id`) REFERENCES `vn`.`awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `awb_gestdoc_gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `vn`.`dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `awb_recibida` +-- + +DROP TABLE IF EXISTS `awb_recibida`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_recibida` ( + `awb_id` smallint(5) unsigned NOT NULL, + `recibida_id` mediumint(8) unsigned NOT NULL, + `dua` varchar(18) DEFAULT NULL, + PRIMARY KEY (`recibida_id`), + KEY `awb_id` (`awb_id`), + CONSTRAINT `awb_recibida_ibfk_1` FOREIGN KEY (`awb_id`) REFERENCES `vn`.`awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `awb_recibida_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `vn`.`invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `awb_role` +-- + +DROP TABLE IF EXISTS `awb_role`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_role` ( + `awb_role_id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(45) DEFAULT NULL, + PRIMARY KEY (`awb_role_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT=' '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `awb_unit` +-- + +DROP TABLE IF EXISTS `awb_unit`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `awb_unit` ( + `awb_unit_id` varchar(10) NOT NULL DEFAULT '', + `operation` varchar(45) DEFAULT NULL, + PRIMARY KEY (`awb_unit_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='tipos de unidades'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `balance_nest_tree` +-- + +DROP TABLE IF EXISTS `balance_nest_tree`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `balance_nest_tree` ( + `lft` int(11) DEFAULT NULL, + `rgt` int(11) DEFAULT NULL, + `name` text DEFAULT NULL, + `id` int(11) NOT NULL AUTO_INCREMENT, + `Id_Gasto` varchar(10) DEFAULT NULL, + `isSelected` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `barcodes` +-- + +DROP TABLE IF EXISTS `barcodes`; +/*!50001 DROP VIEW IF EXISTS `barcodes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `barcodes` AS SELECT + 1 AS `id`, + 1 AS `Id_Article`, + 1 AS `code` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `bionic_updating_options` +-- + +DROP TABLE IF EXISTS `bionic_updating_options`; +/*!50001 DROP VIEW IF EXISTS `bionic_updating_options`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `bionic_updating_options` AS SELECT + 1 AS `buo_id`, + 1 AS `description` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `businessReasonEnd` +-- + +DROP TABLE IF EXISTS `businessReasonEnd`; +/*!50001 DROP VIEW IF EXISTS `businessReasonEnd`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `businessReasonEnd` AS SELECT + 1 AS `id`, + 1 AS `reason` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `buySource` +-- + +DROP TABLE IF EXISTS `buySource`; +/*!50001 DROP VIEW IF EXISTS `buySource`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `buySource` AS SELECT + 1 AS `Id_Entrada`, + 1 AS `isPickedOff`, + 1 AS `tarifa0`, + 1 AS `kop`, + 1 AS `Id_Compra`, + 1 AS `tipo_id`, + 1 AS `Id_Article`, + 1 AS `Medida`, + 1 AS `Tallos`, + 1 AS `Etiquetas`, + 1 AS `Id_Cubo`, + 1 AS `Costefijo`, + 1 AS `Packing`, + 1 AS `Grouping`, + 1 AS `Cantidad`, + 1 AS `Tarifa2`, + 1 AS `Tarifa3`, + 1 AS `Punteo`, + 1 AS `Caja`, + 1 AS `Imprimir`, + 1 AS `Article`, + 1 AS `Tinta`, + 1 AS `id_origen`, + 1 AS `PVP`, + 1 AS `Id_Accion`, + 1 AS `pro`, + 1 AS `Min`, + 1 AS `Novincular`, + 1 AS `Portefijo`, + 1 AS `Importe`, + 1 AS `Vida`, + 1 AS `reference`, + 1 AS `Id_Trabajador`, + 1 AS `S1`, + 1 AS `S2`, + 1 AS `S3`, + 1 AS `S4`, + 1 AS `S5`, + 1 AS `S6`, + 1 AS `price_fixed`, + 1 AS `producer_id`, + 1 AS `tag1`, + 1 AS `tag2`, + 1 AS `tag3`, + 1 AS `tag4`, + 1 AS `tag5`, + 1 AS `tag6`, + 1 AS `tag7`, + 1 AS `company_name`, + 1 AS `weightPacking`, + 1 AS `packingOut`, + 1 AS `itemOriginalFk`, + 1 AS `itemOriginalName`, + 1 AS `gramsMax`, + 1 AS `minQuantity` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `buy_edi` +-- + +DROP TABLE IF EXISTS `buy_edi`; +/*!50001 DROP VIEW IF EXISTS `buy_edi`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `buy_edi` AS SELECT + 1 AS `id`, + 1 AS `barcode`, + 1 AS `entry_year`, + 1 AS `delivery_number`, + 1 AS `fec`, + 1 AS `hor`, + 1 AS `now`, + 1 AS `ptj`, + 1 AS `ref`, + 1 AS `item`, + 1 AS `pac`, + 1 AS `qty`, + 1 AS `ori`, + 1 AS `cat`, + 1 AS `agj`, + 1 AS `kop`, + 1 AS `ptd`, + 1 AS `sub`, + 1 AS `pro`, + 1 AS `pri`, + 1 AS `package`, + 1 AS `auction`, + 1 AS `klo`, + 1 AS `k01`, + 1 AS `k02`, + 1 AS `k03`, + 1 AS `k04`, + 1 AS `s1`, + 1 AS `s2`, + 1 AS `s3`, + 1 AS `s4`, + 1 AS `s5`, + 1 AS `s6`, + 1 AS `ok`, + 1 AS `trolley_id`, + 1 AS `putOrderFk`, + 1 AS `scanned` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `buy_edi_k012` +-- + +DROP TABLE IF EXISTS `buy_edi_k012`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `buy_edi_k012` ( + `buy_edi_k012_id` smallint(6) unsigned NOT NULL, + `description` varchar(50) NOT NULL, + PRIMARY KEY (`buy_edi_k012_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Características negativas de los articulos de subasta'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `buy_edi_k03` +-- + +DROP TABLE IF EXISTS `buy_edi_k03`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `buy_edi_k03` ( + `buy_edi_k03_id` tinyint(3) unsigned NOT NULL, + `description` varchar(50) NOT NULL, + PRIMARY KEY (`buy_edi_k03_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Características fitosanitarias de los articulos de subasta'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `buy_edi_k04` +-- + +DROP TABLE IF EXISTS `buy_edi_k04`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `buy_edi_k04` ( + `buy_edi_k04_id` tinyint(3) unsigned NOT NULL, + `description` varchar(50) NOT NULL, + PRIMARY KEY (`buy_edi_k04_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Características calidad de los articulos de subasta'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `call_information` +-- + +DROP TABLE IF EXISTS `call_information`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `call_information` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `Descripcio` text NOT NULL, + `Conclusio` tinyint(3) unsigned NOT NULL, + `Id_Cliente` int(11) NOT NULL, + `fecha` date NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `call_option` +-- + +DROP TABLE IF EXISTS `call_option`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `call_option` ( + `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, + `descripcion` varchar(20) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `cdr` +-- + +DROP TABLE IF EXISTS `cdr`; +/*!50001 DROP VIEW IF EXISTS `cdr`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cdr` AS SELECT + 1 AS `calldate`, + 1 AS `clid`, + 1 AS `src`, + 1 AS `dst`, + 1 AS `dcontext`, + 1 AS `channel`, + 1 AS `dstchannel`, + 1 AS `lastapp`, + 1 AS `lastdata`, + 1 AS `duration`, + 1 AS `billsec`, + 1 AS `disposition`, + 1 AS `amaflags`, + 1 AS `accountcode`, + 1 AS `uniqueid`, + 1 AS `userfield` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `chanel` +-- + +DROP TABLE IF EXISTS `chanel`; +/*!50001 DROP VIEW IF EXISTS `chanel`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `chanel` AS SELECT + 1 AS `chanel_id`, + 1 AS `name` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_act` +-- + +DROP TABLE IF EXISTS `cl_act`; +/*!50001 DROP VIEW IF EXISTS `cl_act`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_act` AS SELECT + 1 AS `id`, + 1 AS `Id_Movimiento`, + 1 AS `cl_main_id`, + 1 AS `Id_Trabajador`, + 1 AS `cl_sol_id`, + 1 AS `greuge` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_cau` +-- + +DROP TABLE IF EXISTS `cl_cau`; +/*!50001 DROP VIEW IF EXISTS `cl_cau`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_cau` AS SELECT + 1 AS `id`, + 1 AS `cl_main_id`, + 1 AS `cl_res_id`, + 1 AS `Id_Trabajador`, + 1 AS `cl_mot_id`, + 1 AS `cl_con_id`, + 1 AS `cl_dev`, + 1 AS `cl_sol` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_con` +-- + +DROP TABLE IF EXISTS `cl_con`; +/*!50001 DROP VIEW IF EXISTS `cl_con`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_con` AS SELECT + 1 AS `id`, + 1 AS `consecuencia` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `cl_dep` +-- + +DROP TABLE IF EXISTS `cl_dep`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cl_dep` ( + `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, + `departamento` varchar(20) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='ELIMINAR Departamentos para las quejas'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `cl_det` +-- + +DROP TABLE IF EXISTS `cl_det`; +/*!50001 DROP VIEW IF EXISTS `cl_det`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_det` AS SELECT + 1 AS `id`, + 1 AS `cl_main_id`, + 1 AS `Id_Movimiento`, + 1 AS `numero` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_dev` +-- + +DROP TABLE IF EXISTS `cl_dev`; +/*!50001 DROP VIEW IF EXISTS `cl_dev`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_dev` AS SELECT + 1 AS `id`, + 1 AS `devolucion` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_est` +-- + +DROP TABLE IF EXISTS `cl_est`; +/*!50001 DROP VIEW IF EXISTS `cl_est`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_est` AS SELECT + 1 AS `id`, + 1 AS `estado`, + 1 AS `roleFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_main` +-- + +DROP TABLE IF EXISTS `cl_main`; +/*!50001 DROP VIEW IF EXISTS `cl_main`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_main` AS SELECT + 1 AS `id`, + 1 AS `Fecha`, + 1 AS `cl_est_id`, + 1 AS `notas`, + 1 AS `Id_Cliente`, + 1 AS `Id_Trabajador`, + 1 AS `sensib`, + 1 AS `mana`, + 1 AS `ticketFk`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_mot` +-- + +DROP TABLE IF EXISTS `cl_mot`; +/*!50001 DROP VIEW IF EXISTS `cl_mot`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_mot` AS SELECT + 1 AS `id`, + 1 AS `motivo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `cl_pet` +-- + +DROP TABLE IF EXISTS `cl_pet`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cl_pet` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `peticion` varchar(15) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='ELIMINAR Peticiones de los cliente en relacion a las quejas'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `cl_que` +-- + +DROP TABLE IF EXISTS `cl_que`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cl_que` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `queja` varchar(25) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='ELIMINAR Queja por linea de las reclamaciones'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `cl_res` +-- + +DROP TABLE IF EXISTS `cl_res`; +/*!50001 DROP VIEW IF EXISTS `cl_res`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_res` AS SELECT + 1 AS `id`, + 1 AS `responsable`, + 1 AS `sensibility` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `cl_sol` +-- + +DROP TABLE IF EXISTS `cl_sol`; +/*!50001 DROP VIEW IF EXISTS `cl_sol`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cl_sol` AS SELECT + 1 AS `id`, + 1 AS `solucion`, + 1 AS `addressFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `client_observation` +-- + +DROP TABLE IF EXISTS `client_observation`; +/*!50001 DROP VIEW IF EXISTS `client_observation`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `client_observation` AS SELECT + 1 AS `client_observation_id`, + 1 AS `Id_Cliente`, + 1 AS `Id_Trabajador`, + 1 AS `text`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `clientes_gestdoc` +-- + +DROP TABLE IF EXISTS `clientes_gestdoc`; +/*!50001 DROP VIEW IF EXISTS `clientes_gestdoc`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `clientes_gestdoc` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `gest_doc_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `clientes_regalos_enc` +-- + +DROP TABLE IF EXISTS `clientes_regalos_enc`; +/*!50001 DROP VIEW IF EXISTS `clientes_regalos_enc`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `clientes_regalos_enc` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `Id_Regalo`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `clientes_regalos_lista_enc` +-- + +DROP TABLE IF EXISTS `clientes_regalos_lista_enc`; +/*!50001 DROP VIEW IF EXISTS `clientes_regalos_lista_enc`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `clientes_regalos_lista_enc` AS SELECT + 1 AS `Id_Regalo`, + 1 AS `Descripcion`, + 1 AS `foto`, + 1 AS `activo`, + 1 AS `datstart`, + 1 AS `datend`, + 1 AS `warehouse_id`, + 1 AS `province_id`, + 1 AS `countryFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `clientes_tipo` +-- + +DROP TABLE IF EXISTS `clientes_tipo`; +/*!50001 DROP VIEW IF EXISTS `clientes_tipo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `clientes_tipo` AS SELECT + 1 AS `clientes_tipo_id`, + 1 AS `code`, + 1 AS `tipo`, + 1 AS `isCreatedAsServed` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `commission` +-- + +DROP TABLE IF EXISTS `commission`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `commission` ( + `commisision_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, + `percentage` tinyint(3) unsigned NOT NULL, + `value` float unsigned NOT NULL, + PRIMARY KEY (`commisision_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `config` +-- + +DROP TABLE IF EXISTS `config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `config` ( + `id` int(11) NOT NULL, + `generic_item` int(11) NOT NULL COMMENT 'Id del artículo genérico', + `edi_entry` int(11) NOT NULL COMMENT 'Entrada usada para los EKTs', + `lastMana` int(11) NOT NULL DEFAULT 0, + `lastNicho` varchar(10) DEFAULT NULL, + `lastReserve` varchar(10) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `config_host` +-- + +DROP TABLE IF EXISTS `config_host`; +/*!50001 DROP VIEW IF EXISTS `config_host`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `config_host` AS SELECT + 1 AS `config_host_id`, + 1 AS `warehouse`, + 1 AS `empresaId`, + 1 AS `caja`, + 1 AS `Id_Impresora`, + 1 AS `route_days_before`, + 1 AS `route_days_after` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `config_host_forms` +-- + +DROP TABLE IF EXISTS `config_host_forms`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `config_host_forms` ( + `config_host_id` varchar(30) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `formname` varchar(56) NOT NULL, + `x` int(8) NOT NULL, + `y` int(8) NOT NULL, + `h` int(8) NOT NULL, + `l` int(8) NOT NULL, + `odbc_date` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`config_host_id`,`formname`), + CONSTRAINT `config_host_forms_FK` FOREIGN KEY (`config_host_id`) REFERENCES `vn`.`host` (`code`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Registra las posiciones de los formularios'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `consignatarios_observation` +-- + +DROP TABLE IF EXISTS `consignatarios_observation`; +/*!50001 DROP VIEW IF EXISTS `consignatarios_observation`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `consignatarios_observation` AS SELECT + 1 AS `consignatarios_observation_id`, + 1 AS `Id_Consigna`, + 1 AS `observation_type_id`, + 1 AS `text` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `container` +-- + +DROP TABLE IF EXISTS `container`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `container` ( + `container_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `Continente` varchar(10) DEFAULT NULL, + PRIMARY KEY (`container_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `cooler_path` +-- + +DROP TABLE IF EXISTS `cooler_path`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cooler_path` ( + `cooler_path_id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(45) DEFAULT NULL, + PRIMARY KEY (`cooler_path_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Define el orden en que se imprimen los F5'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `cooler_path_detail` +-- + +DROP TABLE IF EXISTS `cooler_path_detail`; +/*!50001 DROP VIEW IF EXISTS `cooler_path_detail`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `cooler_path_detail` AS SELECT + 1 AS `cooler_path_detail_id`, + 1 AS `cooler_path_id`, + 1 AS `pasillo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `cp` +-- + +DROP TABLE IF EXISTS `cp`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cp` ( + `cp_id` int(11) NOT NULL AUTO_INCREMENT, + `cpd` int(11) NOT NULL, + `cph` int(11) NOT NULL, + `zone_id` smallint(6) DEFAULT NULL, + `town` varchar(45) NOT NULL, + PRIMARY KEY (`cp_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relacio de codis postals i el municipi al qual se asigna'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `credit` +-- + +DROP TABLE IF EXISTS `credit`; +/*!50001 DROP VIEW IF EXISTS `credit`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `credit` AS SELECT + 1 AS `id`, + 1 AS `Id_Cliente`, + 1 AS `Id_Trabajador`, + 1 AS `amount`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `credit_card` +-- + +DROP TABLE IF EXISTS `credit_card`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `credit_card` ( + `credit_card_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `Id_Cliente` int(10) NOT NULL, + `number` varchar(20) NOT NULL, + `expiration_month` tinyint(2) unsigned zerofill NOT NULL, + `expiration_year` tinyint(2) unsigned zerofill NOT NULL, + `priority` tinyint(3) unsigned NOT NULL DEFAULT 1, + `obs` varchar(45) DEFAULT NULL, + PRIMARY KEY (`credit_card_id`), + KEY `Id_Cliente` (`Id_Cliente`), + CONSTRAINT `credit_card_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `cyc` +-- + +DROP TABLE IF EXISTS `cyc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cyc` ( + `Id_Cliente` int(11) NOT NULL, + `Riesgo` double DEFAULT NULL, + `Fecha` timestamp NOT NULL DEFAULT current_timestamp(), + `cyc_id` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`cyc_id`), + KEY `Cliente` (`Id_Cliente`), + CONSTRAINT `Cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn`.`client` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Detalla los clientes que estan clasificados en Credito y Cau'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `cyc_declaration` +-- + +DROP TABLE IF EXISTS `cyc_declaration`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cyc_declaration` ( + `factura_id` int(10) unsigned NOT NULL, + `Riesgo` double DEFAULT NULL, + `Fecha` date NOT NULL, + `Vencimiento` int(10) NOT NULL DEFAULT 0, + PRIMARY KEY (`factura_id`), + CONSTRAINT `Factura` FOREIGN KEY (`factura_id`) REFERENCES `vn`.`invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Registro de las facturas declaradas a cyc'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `definitivo` +-- + +DROP TABLE IF EXISTS `definitivo`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `definitivo` ( + `definitivo_id` int(11) NOT NULL, + `empresa_id` int(11) NOT NULL, + `desde` bigint(20) NOT NULL, + `hasta` bigint(20) NOT NULL, + `fecha` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`definitivo_id`,`empresa_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `deliveryPoint` +-- + +DROP TABLE IF EXISTS `deliveryPoint`; +/*!50001 DROP VIEW IF EXISTS `deliveryPoint`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `deliveryPoint` AS SELECT + 1 AS `id`, + 1 AS `name`, + 1 AS `ubication` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `device_user` +-- + +DROP TABLE IF EXISTS `device_user`; +/*!50001 DROP VIEW IF EXISTS `device_user`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `device_user` AS SELECT + 1 AS `device_id`, + 1 AS `user_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `dock` +-- + +DROP TABLE IF EXISTS `dock`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `dock` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `code` varchar(5) NOT NULL, + `xPos` int(11) DEFAULT NULL, + `yPos` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `code_UNIQUE` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Soporta la estructura de muelles de paletizacion'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `duaDismissed` +-- + +DROP TABLE IF EXISTS `duaDismissed`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `duaDismissed` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `ticketFk` varchar(45) NOT NULL, + PRIMARY KEY (`id`,`ticketFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `edi_article` +-- + +DROP TABLE IF EXISTS `edi_article`; +/*!50001 DROP VIEW IF EXISTS `edi_article`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_article` AS SELECT + 1 AS `id`, + 1 AS `product_name`, + 1 AS `name`, + 1 AS `plant_id`, + 1 AS `group_id`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_bucket` +-- + +DROP TABLE IF EXISTS `edi_bucket`; +/*!50001 DROP VIEW IF EXISTS `edi_bucket`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_bucket` AS SELECT + 1 AS `bucket_id`, + 1 AS `bucket_type_id`, + 1 AS `description`, + 1 AS `x_size`, + 1 AS `y_size`, + 1 AS `z_size`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_bucket_type` +-- + +DROP TABLE IF EXISTS `edi_bucket_type`; +/*!50001 DROP VIEW IF EXISTS `edi_bucket_type`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_bucket_type` AS SELECT + 1 AS `bucket_type_id`, + 1 AS `description`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_feature` +-- + +DROP TABLE IF EXISTS `edi_feature`; +/*!50001 DROP VIEW IF EXISTS `edi_feature`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_feature` AS SELECT + 1 AS `item_id`, + 1 AS `feature_type_id`, + 1 AS `feature_value`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_genus` +-- + +DROP TABLE IF EXISTS `edi_genus`; +/*!50001 DROP VIEW IF EXISTS `edi_genus`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_genus` AS SELECT + 1 AS `genus_id`, + 1 AS `latin_genus_name`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_item_feature` +-- + +DROP TABLE IF EXISTS `edi_item_feature`; +/*!50001 DROP VIEW IF EXISTS `edi_item_feature`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_item_feature` AS SELECT + 1 AS `item_id`, + 1 AS `presentation_order`, + 1 AS `feature`, + 1 AS `regulation_type`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_plant` +-- + +DROP TABLE IF EXISTS `edi_plant`; +/*!50001 DROP VIEW IF EXISTS `edi_plant`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_plant` AS SELECT + 1 AS `plant_id`, + 1 AS `genus_id`, + 1 AS `specie_id`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_specie` +-- + +DROP TABLE IF EXISTS `edi_specie`; +/*!50001 DROP VIEW IF EXISTS `edi_specie`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_specie` AS SELECT + 1 AS `specie_id`, + 1 AS `genus_id`, + 1 AS `latin_species_name`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_supplier` +-- + +DROP TABLE IF EXISTS `edi_supplier`; +/*!50001 DROP VIEW IF EXISTS `edi_supplier`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_supplier` AS SELECT + 1 AS `supplier_id`, + 1 AS `company_name` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `edi_testigos` +-- + +DROP TABLE IF EXISTS `edi_testigos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `edi_testigos` ( + `id` smallint(6) NOT NULL AUTO_INCREMENT, + `table` varchar(25) NOT NULL, + `field` varchar(32) NOT NULL, + `testigo` varchar(5) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `edi_type` +-- + +DROP TABLE IF EXISTS `edi_type`; +/*!50001 DROP VIEW IF EXISTS `edi_type`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_type` AS SELECT + 1 AS `type_id`, + 1 AS `type_group_id`, + 1 AS `description`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `edi_value` +-- + +DROP TABLE IF EXISTS `edi_value`; +/*!50001 DROP VIEW IF EXISTS `edi_value`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `edi_value` AS SELECT + 1 AS `type_id`, + 1 AS `type_value`, + 1 AS `type_description`, + 1 AS `entry_date`, + 1 AS `expiry_date`, + 1 AS `change_date_time` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `emp_day_pay` +-- + +DROP TABLE IF EXISTS `emp_day_pay`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `emp_day_pay` ( + `id` smallint(5) unsigned NOT NULL, + `emp_day_pay` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`,`emp_day_pay`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `empresa` +-- + +DROP TABLE IF EXISTS `empresa`; +/*!50001 DROP VIEW IF EXISTS `empresa`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `empresa` AS SELECT + 1 AS `id`, + 1 AS `abbreviation`, + 1 AS `Id_Proveedores_account`, + 1 AS `gerente_id`, + 1 AS `digito_factura`, + 1 AS `phytosanitary`, + 1 AS `CodigoEmpresa`, + 1 AS `empresa_grupo`, + 1 AS `morosidad`, + 1 AS `baja`, + 1 AS `registro`, + 1 AS `alta`, + 1 AS `logo`, + 1 AS `oficial`, + 1 AS `cyc`, + 1 AS `rgb`, + 1 AS `mail`, + 1 AS `cuno`, + 1 AS `ODBC_DATE`, + 1 AS `Id_Cliente` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `empresa_grupo` +-- + +DROP TABLE IF EXISTS `empresa_grupo`; +/*!50001 DROP VIEW IF EXISTS `empresa_grupo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `empresa_grupo` AS SELECT + 1 AS `empresa_grupo_id`, + 1 AS `grupo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `entrySource` +-- + +DROP TABLE IF EXISTS `entrySource`; +/*!50001 DROP VIEW IF EXISTS `entrySource`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `entrySource` AS SELECT + 1 AS `gestdoc_id`, + 1 AS `Id_Entrada`, + 1 AS `invoiceNumber`, + 1 AS `reference`, + 1 AS `Inventario`, + 1 AS `Confirmada`, + 1 AS `Pedida`, + 1 AS `Redada`, + 1 AS `notas`, + 1 AS `Id_Proveedor`, + 1 AS `shipment`, + 1 AS `landing`, + 1 AS `wh_in`, + 1 AS `wh_out`, + 1 AS `Agencia`, + 1 AS `comision`, + 1 AS `warehouse_id`, + 1 AS `warehouse_id_out`, + 1 AS `anotadoencaja`, + 1 AS `invoiceInFk`, + 1 AS `empresa_id`, + 1 AS `Id_Moneda`, + 1 AS `TravelFk`, + 1 AS `sub`, + 1 AS `kop`, + 1 AS `pro`, + 1 AS `invoiceAmount`, + 1 AS `buyerCode`, + 1 AS `typeFk`, + 1 AS `observationWorkerCode` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `escritos` +-- + +DROP TABLE IF EXISTS `escritos`; +/*!50001 DROP VIEW IF EXISTS `escritos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `escritos` AS SELECT + 1 AS `id`, + 1 AS `abrev`, + 1 AS `descripcion`, + 1 AS `visible`, + 1 AS `hasCompany` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `escritos_det` +-- + +DROP TABLE IF EXISTS `escritos_det`; +/*!50001 DROP VIEW IF EXISTS `escritos_det`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `escritos_det` AS SELECT + 1 AS `id`, + 1 AS `Id_Cliente`, + 1 AS `escritos_id`, + 1 AS `fecha`, + 1 AS `Id_Trabajador`, + 1 AS `userFk`, + 1 AS `empresa_id`, + 1 AS `saldo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `expeditions` +-- + +DROP TABLE IF EXISTS `expeditions`; +/*!50001 DROP VIEW IF EXISTS `expeditions`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `expeditions` AS SELECT + 1 AS `expeditions_id`, + 1 AS `agency_id`, + 1 AS `ticket_id`, + 1 AS `EsBulto`, + 1 AS `odbc_date`, + 1 AS `counter`, + 1 AS `workerFk`, + 1 AS `externalId`, + 1 AS `Id_article` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `expeditions_deleted` +-- + +DROP TABLE IF EXISTS `expeditions_deleted`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expeditions_deleted` ( + `expeditions_id` int(11) NOT NULL AUTO_INCREMENT, + `agency_id` int(11) NOT NULL, + `ticket_id` int(10) NOT NULL, + `EsBulto` int(11) DEFAULT 1, + `odbc_date` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `reembolso` bit(1) DEFAULT b'0', + `recogida` bit(1) DEFAULT b'0', + `Id_Article` int(11) DEFAULT NULL, + `counter` smallint(5) unsigned NOT NULL, + `checked` tinyint(4) NOT NULL DEFAULT 0, + `completed` tinyint(4) DEFAULT 0, + `expedicion` varchar(45) DEFAULT NULL, + `Id_Trabajador` int(11) DEFAULT NULL, + PRIMARY KEY (`expeditions_id`), + KEY `index1` (`agency_id`), + KEY `index2` (`EsBulto`), + KEY `index3` (`odbc_date`), + KEY `index4` (`ticket_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `expeditions_pictures` +-- + +DROP TABLE IF EXISTS `expeditions_pictures`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `expeditions_pictures` ( + `Id_Article` int(11) NOT NULL, + `NoImprimirEtiqueta` bit(1) DEFAULT b'0', + PRIMARY KEY (`Id_Article`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `filtros` +-- + +DROP TABLE IF EXISTS `filtros`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `filtros` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `sql` varchar(255) NOT NULL, + `Estanteria` tinyint(1) DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `financialProductType` +-- + +DROP TABLE IF EXISTS `financialProductType`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `financialProductType` ( + `id` varchar(2) NOT NULL, + `description` varchar(45) NOT NULL, + `isAcumulattor` tinyint(4) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `description_UNIQUE` (`description`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Distintos tipos de productos financieros: seguros de cambio, polizas de credito, acumuladores....'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `flight` +-- + +DROP TABLE IF EXISTS `flight`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `flight` ( + `flight_id` varchar(10) NOT NULL, + `duration` tinyint(2) unsigned NOT NULL, + `route` varchar(20) DEFAULT NULL, + `days` varchar(7) DEFAULT NULL, + `airline_id` smallint(2) unsigned DEFAULT NULL, + `airport_out` varchar(3) NOT NULL, + `airport_in` varchar(3) NOT NULL, + PRIMARY KEY (`flight_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `form_query` +-- + +DROP TABLE IF EXISTS `form_query`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `form_query` ( + `form_query_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `query` varchar(50) NOT NULL, + `response1` varchar(10) NOT NULL, + `response2` varchar(10) NOT NULL, + `type_id` enum('gest_doc') NOT NULL, + PRIMARY KEY (`form_query_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `gastos_resumen` +-- + +DROP TABLE IF EXISTS `gastos_resumen`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `gastos_resumen` ( + `Id_Gasto` varchar(10) NOT NULL, + `year` int(4) NOT NULL, + `month` int(2) NOT NULL, + `importe` decimal(10,2) DEFAULT NULL, + `empresa_id` int(11) NOT NULL, + PRIMARY KEY (`Id_Gasto`,`year`,`month`,`empresa_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Sirve para resumir los gastos que se ponen a mano en el contaplus'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `gestdoc` +-- + +DROP TABLE IF EXISTS `gestdoc`; +/*!50001 DROP VIEW IF EXISTS `gestdoc`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `gestdoc` AS SELECT + 1 AS `id`, + 1 AS `gesttip_id`, + 1 AS `file`, + 1 AS `contentType`, + 1 AS `trabajador_id`, + 1 AS `warehouse_id`, + 1 AS `emp_id`, + 1 AS `orden`, + 1 AS `original`, + 1 AS `sref`, + 1 AS `brief`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `gesttip` +-- + +DROP TABLE IF EXISTS `gesttip`; +/*!50001 DROP VIEW IF EXISTS `gesttip`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `gesttip` AS SELECT + 1 AS `id`, + 1 AS `tipo`, + 1 AS `path`, + 1 AS `readRoleFk`, + 1 AS `writeRoleFk`, + 1 AS `code` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `guillen` +-- + +DROP TABLE IF EXISTS `guillen`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `guillen` ( + `bulto` tinyint(3) unsigned NOT NULL, + `1` float unsigned NOT NULL, + `2` float unsigned NOT NULL, + `re_exp` float unsigned NOT NULL, + PRIMARY KEY (`bulto`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `guillen_carry` +-- + +DROP TABLE IF EXISTS `guillen_carry`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `guillen_carry` ( + `carry` tinyint(3) unsigned NOT NULL, + `1` float unsigned NOT NULL, + `2` float unsigned NOT NULL, + `re_exp` float unsigned NOT NULL, + PRIMARY KEY (`carry`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `integra2` +-- + +DROP TABLE IF EXISTS `integra2`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `integra2` ( + `postal_code` mediumint(8) unsigned NOT NULL, + `frequency` tinyint(3) unsigned NOT NULL, + `warehouse_id` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`postal_code`,`frequency`,`warehouse_id`), + KEY `postal_code` (`postal_code`), + KEY `warehouse_id` (`warehouse_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `integra2_escala` +-- + +DROP TABLE IF EXISTS `integra2_escala`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `integra2_escala` ( + `province_id` smallint(6) unsigned NOT NULL, + `warehouse_id` smallint(6) unsigned NOT NULL, + PRIMARY KEY (`province_id`,`warehouse_id`), + KEY `warehouse_escala_idx` (`warehouse_id`), + CONSTRAINT `province_escala` FOREIGN KEY (`province_id`) REFERENCES `vn`.`province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `warehouse_escala` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `integra2_province` +-- + +DROP TABLE IF EXISTS `integra2_province`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `integra2_province` ( + `province_id` smallint(6) unsigned NOT NULL, + `franquicia` varchar(65) NOT NULL, + PRIMARY KEY (`province_id`), + CONSTRAINT `integra2_province_id` FOREIGN KEY (`province_id`) REFERENCES `vn`.`province` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `intervalos__` +-- + +DROP TABLE IF EXISTS `intervalos__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `intervalos__` ( + `id` int(11) NOT NULL, + `hour` time NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `intrastat_data` +-- + +DROP TABLE IF EXISTS `intrastat_data`; +/*!50001 DROP VIEW IF EXISTS `intrastat_data`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `intrastat_data` AS SELECT + 1 AS `id`, + 1 AS `recibida_id`, + 1 AS `neto`, + 1 AS `intrastat_id`, + 1 AS `importe`, + 1 AS `unidades`, + 1 AS `Paises_Id`, + 1 AS `odbc_date`, + 1 AS `valorestadistico` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `invoiceCorrection` +-- + +DROP TABLE IF EXISTS `invoiceCorrection`; +/*!50001 DROP VIEW IF EXISTS `invoiceCorrection`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `invoiceCorrection` AS SELECT + 1 AS `correctingFk`, + 1 AS `correctedFk`, + 1 AS `cplusRectificationTypeFk`, + 1 AS `siiTypeInvoiceOutFk`, + 1 AS `invoiceCorrectionTypeFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `invoice_observation` +-- + +DROP TABLE IF EXISTS `invoice_observation`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `invoice_observation` ( + `invoice_observation_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `desde` date NOT NULL, + `hasta` date NOT NULL, + `serie` varchar(1) NOT NULL DEFAULT '0', + `empresa_id` smallint(5) unsigned NOT NULL DEFAULT 0, + `text` text NOT NULL, + PRIMARY KEY (`invoice_observation_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `itemTag` +-- + +DROP TABLE IF EXISTS `itemTag`; +/*!50001 DROP VIEW IF EXISTS `itemTag`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `itemTag` AS SELECT + 1 AS `id`, + 1 AS `itemFk`, + 1 AS `tagFk`, + 1 AS `value`, + 1 AS `priority` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `item_entry_in` +-- + +DROP TABLE IF EXISTS `item_entry_in`; +/*!50001 DROP VIEW IF EXISTS `item_entry_in`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `item_entry_in` AS SELECT + 1 AS `warehouse_id`, + 1 AS `warehouse_id_out`, + 1 AS `dat`, + 1 AS `item_id`, + 1 AS `amount`, + 1 AS `received`, + 1 AS `isVirtualStock`, + 1 AS `entryFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `item_entry_out` +-- + +DROP TABLE IF EXISTS `item_entry_out`; +/*!50001 DROP VIEW IF EXISTS `item_entry_out`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `item_entry_out` AS SELECT + 1 AS `warehouse_id`, + 1 AS `dat`, + 1 AS `item_id`, + 1 AS `amount`, + 1 AS `delivered`, + 1 AS `entryFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `item_out` +-- + +DROP TABLE IF EXISTS `item_out`; +/*!50001 DROP VIEW IF EXISTS `item_out`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `item_out` AS SELECT + 1 AS `warehouse_id`, + 1 AS `dat`, + 1 AS `item_id`, + 1 AS `amount`, + 1 AS `ok`, + 1 AS `Reservado`, + 1 AS `invoice`, + 1 AS `saleFk`, + 1 AS `ticketFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `iva_codigo` +-- + +DROP TABLE IF EXISTS `iva_codigo`; +/*!50001 DROP VIEW IF EXISTS `iva_codigo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `iva_codigo` AS SELECT + 1 AS `id`, + 1 AS `fecha`, + 1 AS `codigo`, + 1 AS `iva_tipo_id`, + 1 AS `iva`, + 1 AS `recargo`, + 1 AS `tipo`, + 1 AS `link`, + 1 AS `isActive`, + 1 AS `updated`, + 1 AS `transactionCode` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `iva_group` +-- + +DROP TABLE IF EXISTS `iva_group`; +/*!50001 DROP VIEW IF EXISTS `iva_group`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `iva_group` AS SELECT + 1 AS `iva_group_id`, + 1 AS `description`, + 1 AS `code` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `iva_group_codigo` +-- + +DROP TABLE IF EXISTS `iva_group_codigo`; +/*!50001 DROP VIEW IF EXISTS `iva_group_codigo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `iva_group_codigo` AS SELECT + 1 AS `iva_group_id`, + 1 AS `date`, + 1 AS `iva_codigo_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `iva_tipo` +-- + +DROP TABLE IF EXISTS `iva_tipo`; +/*!50001 DROP VIEW IF EXISTS `iva_tipo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `iva_tipo` AS SELECT + 1 AS `id`, + 1 AS `alias`, + 1 AS `isAccrued`, + 1 AS `serie_id`, + 1 AS `TIPOOPE`, + 1 AS `descripcion`, + 1 AS `Id_Pais` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `jerarquia` +-- + +DROP TABLE IF EXISTS `jerarquia`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `jerarquia` ( + `worker_id` int(10) unsigned NOT NULL, + `boss_id` int(10) unsigned NOT NULL, + `vinculado` tinyint(3) unsigned NOT NULL DEFAULT 0, + PRIMARY KEY (`worker_id`,`boss_id`), + KEY `worker_trabajador` (`worker_id`), + KEY `jerarquiaBossFk_idx` (`boss_id`), + CONSTRAINT `jerarquiaBossFk` FOREIGN KEY (`boss_id`) REFERENCES `account`.`account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `jerarquiaWorkerFk` FOREIGN KEY (`worker_id`) REFERENCES `account`.`account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `language` +-- + +DROP TABLE IF EXISTS `language`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `language` ( + `code` varchar(10) NOT NULL, + `name` varchar(20) NOT NULL, + `active` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `link` +-- + +DROP TABLE IF EXISTS `link`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `link` ( + `Id_Cliente` int(11) NOT NULL, + `Id_Proveedor` int(11) NOT NULL, + PRIMARY KEY (`Id_Cliente`,`Id_Proveedor`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `mail` +-- + +DROP TABLE IF EXISTS `mail`; +/*!50001 DROP VIEW IF EXISTS `mail`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `mail` AS SELECT + 1 AS `id`, + 1 AS `senderFk`, + 1 AS `recipientFk`, + 1 AS `to`, + 1 AS `reply_to`, + 1 AS `subject`, + 1 AS `text`, + 1 AS `plainTextBody`, + 1 AS `path`, + 1 AS `DATE_ODBC`, + 1 AS `sent`, + 1 AS `error` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `mail_templates__` +-- + +DROP TABLE IF EXISTS `mail_templates__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mail_templates__` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `countryCode` char(2) NOT NULL DEFAULT 'ES', + `name` varchar(25) NOT NULL, + `subject` varchar(50) NOT NULL, + `body` text NOT NULL, + `attachment` text DEFAULT NULL, + PRIMARY KEY (`id`,`countryCode`,`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Deprecated 27-02-2023'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `mandato` +-- + +DROP TABLE IF EXISTS `mandato`; +/*!50001 DROP VIEW IF EXISTS `mandato`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `mandato` AS SELECT + 1 AS `id`, + 1 AS `Id_Cliente`, + 1 AS `empresa_id`, + 1 AS `Id_mandato`, + 1 AS `FAlta`, + 1 AS `Fbaja`, + 1 AS `idmandato_tipo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `mandato_tipo` +-- + +DROP TABLE IF EXISTS `mandato_tipo`; +/*!50001 DROP VIEW IF EXISTS `mandato_tipo`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `mandato_tipo` AS SELECT + 1 AS `idmandato_tipo`, + 1 AS `Nombre` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `movement_label` +-- + +DROP TABLE IF EXISTS `movement_label`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `movement_label` ( + `Id_movimiento` int(11) NOT NULL, + `label` mediumint(8) unsigned NOT NULL, + `stem` mediumint(8) unsigned NOT NULL, + `created` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`Id_movimiento`), + CONSTRAINT `movement_label_ibfk_1` FOREIGN KEY (`Id_movimiento`) REFERENCES `vn`.`sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `nichos` +-- + +DROP TABLE IF EXISTS `nichos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `nichos` ( + `id` varchar(5) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `observation_type` +-- + +DROP TABLE IF EXISTS `observation_type`; +/*!50001 DROP VIEW IF EXISTS `observation_type`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `observation_type` AS SELECT + 1 AS `observation_type_id`, + 1 AS `description` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `order` +-- + +DROP TABLE IF EXISTS `order`; +/*!50001 DROP VIEW IF EXISTS `order`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `order` AS SELECT + 1 AS `id`, + 1 AS `date_make`, + 1 AS `date_send`, + 1 AS `customer_id`, + 1 AS `delivery_method_id`, + 1 AS `agency_id`, + 1 AS `address_id`, + 1 AS `note`, + 1 AS `confirmed`, + 1 AS `is_bionic`, + 1 AS `source_app` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `order_Tickets` +-- + +DROP TABLE IF EXISTS `order_Tickets`; +/*!50001 DROP VIEW IF EXISTS `order_Tickets`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `order_Tickets` AS SELECT + 1 AS `order_id`, + 1 AS `Id_Ticket` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `order_component` +-- + +DROP TABLE IF EXISTS `order_component`; +/*!50001 DROP VIEW IF EXISTS `order_component`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `order_component` AS SELECT + 1 AS `order_row_id`, + 1 AS `component_id`, + 1 AS `price` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `order_row` +-- + +DROP TABLE IF EXISTS `order_row`; +/*!50001 DROP VIEW IF EXISTS `order_row`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `order_row` AS SELECT + 1 AS `id`, + 1 AS `order_id`, + 1 AS `item_id`, + 1 AS `warehouse_id`, + 1 AS `shipment`, + 1 AS `amount`, + 1 AS `price`, + 1 AS `rate`, + 1 AS `created`, + 1 AS `Id_Movimiento` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `pago` +-- + +DROP TABLE IF EXISTS `pago`; +/*!50001 DROP VIEW IF EXISTS `pago`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `pago` AS SELECT + 1 AS `id`, + 1 AS `fecha`, + 1 AS `dueDated`, + 1 AS `id_proveedor`, + 1 AS `importe`, + 1 AS `id_moneda`, + 1 AS `divisa`, + 1 AS `id_banco`, + 1 AS `pay_met_id`, + 1 AS `empresa_id`, + 1 AS `conciliado`, + 1 AS `g_bancarios`, + 1 AS `concepte`, + 1 AS `odbc_date` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `pago_sdc` +-- + +DROP TABLE IF EXISTS `pago_sdc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `pago_sdc` ( + `pago_sdc_id` int(11) NOT NULL AUTO_INCREMENT, + `importe` decimal(10,2) NOT NULL, + `fecha` date NOT NULL, + `vencimiento` date NOT NULL, + `entity_id` int(10) unsigned NOT NULL, + `ref` varchar(45) DEFAULT NULL, + `rate` decimal(10,4) NOT NULL, + `empresa_id` int(10) unsigned NOT NULL DEFAULT 442, + `financialProductTypefk` varchar(2) NOT NULL DEFAULT 'SC', + `pago_sdccol` varchar(45) DEFAULT NULL, + `upperBarrier` decimal(10,2) DEFAULT NULL, + `lowerBarrier` decimal(10,2) DEFAULT NULL, + `strike` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`pago_sdc_id`), + KEY `empresa_sdc_idx` (`empresa_id`), + KEY `financial_type_fk_idx` (`financialProductTypefk`), + KEY `pago_sdc_entity_fk_idx` (`entity_id`), + CONSTRAINT `financial_type_fk` FOREIGN KEY (`financialProductTypefk`) REFERENCES `financialProductType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `pago_sdcCompany_Fk` FOREIGN KEY (`empresa_id`) REFERENCES `vn`.`company` (`id`) ON UPDATE CASCADE, + CONSTRAINT `pago_sdc_entity_fk` FOREIGN KEY (`entity_id`) REFERENCES `vn`.`bankEntity` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Seguros de cambio'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `pay_dem` +-- + +DROP TABLE IF EXISTS `pay_dem`; +/*!50001 DROP VIEW IF EXISTS `pay_dem`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `pay_dem` AS SELECT + 1 AS `id`, + 1 AS `pay_dem` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `pay_dem_det` +-- + +DROP TABLE IF EXISTS `pay_dem_det`; +/*!50001 DROP VIEW IF EXISTS `pay_dem_det`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `pay_dem_det` AS SELECT + 1 AS `id`, + 1 AS `detalle` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `pay_met` +-- + +DROP TABLE IF EXISTS `pay_met`; +/*!50001 DROP VIEW IF EXISTS `pay_met`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `pay_met` AS SELECT + 1 AS `id`, + 1 AS `name`, + 1 AS `graceDays`, + 1 AS `deudaviva`, + 1 AS `solucion`, + 1 AS `isNotified` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `payroll_basess` +-- + +DROP TABLE IF EXISTS `payroll_basess`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_basess` ( + `id_payroll_Basess` int(11) NOT NULL AUTO_INCREMENT, + `empresa_id` int(10) NOT NULL, + `id_tipobasess` int(11) NOT NULL, + `valor` double NOT NULL, + `fechadesde` date NOT NULL, + `fechahasta` date DEFAULT NULL, + `contratotemporal` tinyint(1) DEFAULT 0, + PRIMARY KEY (`id_payroll_Basess`), + KEY `payroll_basess_1_idx` (`id_tipobasess`), + KEY `payroll_basess_2_idx` (`empresa_id`), + CONSTRAINT `payroll_basess_1` FOREIGN KEY (`id_tipobasess`) REFERENCES `payroll_tipobasess` (`id_payroll_tipobasess`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `payroll_basess_2` FOREIGN KEY (`empresa_id`) REFERENCES `payroll_centros` (`empresa_id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payroll_bonificaciones` +-- + +DROP TABLE IF EXISTS `payroll_bonificaciones`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_bonificaciones` ( + `codtrabajador` int(11) NOT NULL, + `codempresa` int(11) NOT NULL, + `Fecha` date NOT NULL, + `bonificacionSS` double NOT NULL, + PRIMARY KEY (`codtrabajador`,`codempresa`,`Fecha`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `payroll_categorias` +-- + +DROP TABLE IF EXISTS `payroll_categorias`; +/*!50001 DROP VIEW IF EXISTS `payroll_categorias`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `payroll_categorias` AS SELECT + 1 AS `codcategoria`, + 1 AS `Tarifa`, + 1 AS `descripcion` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `payroll_centros` +-- + +DROP TABLE IF EXISTS `payroll_centros`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_centros` ( + `cod_centro` int(11) NOT NULL, + `Centro` varchar(255) NOT NULL, + `nss_cotizacion` varchar(15) NOT NULL, + `domicilio` varchar(255) NOT NULL, + `poblacion` varchar(45) NOT NULL, + `cp` varchar(5) NOT NULL, + `empresa_id` int(10) NOT NULL, + `codempresa` int(11) DEFAULT NULL, + PRIMARY KEY (`cod_centro`,`empresa_id`), + KEY `payroll_centros_ix1` (`empresa_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payroll_conceptos` +-- + +DROP TABLE IF EXISTS `payroll_conceptos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_conceptos` ( + `conceptoid` int(11) NOT NULL, + `concepto` varchar(255) DEFAULT NULL, + `isSalaryAgreed` tinyint(1) NOT NULL DEFAULT 0, + `isVariable` tinyint(1) NOT NULL, + `isException` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Excepciones a tener en cuenta al importar conceptos en el proceso de importación de ficheros A3.', + PRIMARY KEY (`conceptoid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payroll_datos` +-- + +DROP TABLE IF EXISTS `payroll_datos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_datos` ( + `codtrabajador` int(11) NOT NULL, + `codempresa` int(10) NOT NULL, + `Fecha` date NOT NULL, + `conceptoid` int(11) NOT NULL, + `orden` tinyint(4) DEFAULT NULL, + `dias` smallint(6) DEFAULT NULL, + `Importe` decimal(8,2) NOT NULL, + `DH` tinyint(4) DEFAULT NULL, + `T_Paga` tinyint(4) NOT NULL, + `TributaIRPF` tinyint(4) NOT NULL, + PRIMARY KEY (`codtrabajador`,`codempresa`,`conceptoid`,`Fecha`), + KEY `fgkey_payrolldatos_1_idx` (`conceptoid`), + CONSTRAINT `fgkey_payrolldatos_1` FOREIGN KEY (`conceptoid`) REFERENCES `payroll_conceptos` (`conceptoid`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payroll_embargos` +-- + +DROP TABLE IF EXISTS `payroll_embargos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_embargos` ( + `codtrabajador` int(11) NOT NULL, + `codempresa` int(10) NOT NULL, + `conceptoid` int(11) NOT NULL, + `Fecha` date NOT NULL, + `pagado` double NOT NULL, + `pendiente` double DEFAULT NULL, + `total` double NOT NULL, + PRIMARY KEY (`codtrabajador`,`codempresa`,`Fecha`,`conceptoid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payroll_employee` +-- + +DROP TABLE IF EXISTS `payroll_employee`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_employee` ( + `CodTrabajador` int(11) NOT NULL, + `nss` varchar(23) NOT NULL, + `codpuesto` int(10) NOT NULL, + `codempresa` int(10) NOT NULL, + `codcontrato` int(10) NOT NULL, + `FAntiguedad` date NOT NULL, + `grupotarifa` int(10) NOT NULL, + `codcategoria` int(10) NOT NULL, + `ContratoTemporal` tinyint(1) NOT NULL DEFAULT 0, + `workerFk` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`CodTrabajador`,`codempresa`), + KEY `sajvgfh_idx` (`codpuesto`), + KEY `payroll_employee_workerFk_idx` (`workerFk`), + CONSTRAINT `payroll_employee_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payroll_tipobasess` +-- + +DROP TABLE IF EXISTS `payroll_tipobasess`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payroll_tipobasess` ( + `id_payroll_tipobasess` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id_payroll_tipobasess`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `payrroll_apEmpresarial` +-- + +DROP TABLE IF EXISTS `payrroll_apEmpresarial`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `payrroll_apEmpresarial` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `codTrabajador` int(11) NOT NULL, + `Fecha` date NOT NULL, + `CosteEmpresaAT` decimal(8,2) NOT NULL, + `costeEmpresaCC` decimal(8,2) NOT NULL, + `costeEmpresaDesempleo` decimal(8,2) NOT NULL, + `costeEmpresaFP` decimal(8,2) NOT NULL, + `costeEmpresaFogasa` decimal(8,2) NOT NULL, + `costeEmpresaExtra` decimal(8,2) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `person_user` +-- + +DROP TABLE IF EXISTS `person_user`; +/*!50001 DROP VIEW IF EXISTS `person_user`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `person_user` AS SELECT + 1 AS `id`, + 1 AS `mysql_user_id`, + 1 AS `name`, + 1 AS `password`, + 1 AS `active`, + 1 AS `last_pass_change` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `person_user_idtrabajador` +-- + +DROP TABLE IF EXISTS `person_user_idtrabajador`; +/*!50001 DROP VIEW IF EXISTS `person_user_idtrabajador`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `person_user_idtrabajador` AS SELECT + 1 AS `Id_Trabajador` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `plantpassport` +-- + +DROP TABLE IF EXISTS `plantpassport`; +/*!50001 DROP VIEW IF EXISTS `plantpassport`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `plantpassport` AS SELECT + 1 AS `producer_id`, + 1 AS `plantpassport_authority_id`, + 1 AS `number`, + 1 AS `isRequested` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `plantpassport_authority` +-- + +DROP TABLE IF EXISTS `plantpassport_authority`; +/*!50001 DROP VIEW IF EXISTS `plantpassport_authority`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `plantpassport_authority` AS SELECT + 1 AS `plantpassport_authority_id`, + 1 AS `denomination`, + 1 AS `Paises_Id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `preparation_exception` +-- + +DROP TABLE IF EXISTS `preparation_exception`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `preparation_exception` ( + `exception_day` date NOT NULL COMMENT 'preparation day', + `warehouse_id` smallint(6) unsigned DEFAULT NULL, + `percentage` tinyint(2) NOT NULL DEFAULT 0, + UNIQUE KEY `exception_day_UNIQUE` (`exception_day`), + UNIQUE KEY `warehouse_id_UNIQUE` (`warehouse_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `price_fixed` +-- + +DROP TABLE IF EXISTS `price_fixed`; +/*!50001 DROP VIEW IF EXISTS `price_fixed`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `price_fixed` AS SELECT + 1 AS `item_id`, + 1 AS `rate_0`, + 1 AS `rate_1`, + 1 AS `rate_2`, + 1 AS `rate_3`, + 1 AS `date_start`, + 1 AS `date_end`, + 1 AS `bonus`, + 1 AS `warehouse_id`, + 1 AS `odbc_date`, + 1 AS `price_fixed_id`, + 1 AS `grouping`, + 1 AS `Packing`, + 1 AS `caja` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `producer` +-- + +DROP TABLE IF EXISTS `producer`; +/*!50001 DROP VIEW IF EXISTS `producer`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `producer` AS SELECT + 1 AS `producer_id`, + 1 AS `name`, + 1 AS `visible` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `proveedores_clientes` +-- + +DROP TABLE IF EXISTS `proveedores_clientes`; +/*!50001 DROP VIEW IF EXISTS `proveedores_clientes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `proveedores_clientes` AS SELECT + 1 AS `Id_Proveedor`, + 1 AS `Proveedor`, + 1 AS `Id_Cliente`, + 1 AS `Cliente` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `province` +-- + +DROP TABLE IF EXISTS `province`; +/*!50001 DROP VIEW IF EXISTS `province`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `province` AS SELECT + 1 AS `province_id`, + 1 AS `name`, + 1 AS `Paises_Id`, + 1 AS `warehouse_id`, + 1 AS `zone`, + 1 AS `geoFk` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `rec_translator` +-- + +DROP TABLE IF EXISTS `rec_translator`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `rec_translator` ( + `Id_Article` int(11) NOT NULL, + `denominacion` varchar(85) NOT NULL, + PRIMARY KEY (`Id_Article`,`denominacion`), + KEY `id_article_rec_idx` (`Id_Article`), + CONSTRAINT `id_article_rec` FOREIGN KEY (`Id_Article`) REFERENCES `vn`.`item` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Equipara las denominaciones de las fincas de ecuador con nuestro Id_Article'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `recibida` +-- + +DROP TABLE IF EXISTS `recibida`; +/*!50001 DROP VIEW IF EXISTS `recibida`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `recibida` AS SELECT + 1 AS `id`, + 1 AS `num_recibida`, + 1 AS `serie`, + 1 AS `proveedor_id`, + 1 AS `fecha`, + 1 AS `sref`, + 1 AS `contabilizada`, + 1 AS `moneda_id`, + 1 AS `MYSQL_TIME`, + 1 AS `empresa_id`, + 1 AS `gestdoc_id`, + 1 AS `dateBooking`, + 1 AS `dateOperation`, + 1 AS `siiTypeInvoiceInFk`, + 1 AS `cplusRectificationTypeFk`, + 1 AS `cplusSubjectOpFk`, + 1 AS `cplusTaxBreakFk`, + 1 AS `siiTrascendencyInvoiceInFk`, + 1 AS `bookEntried`, + 1 AS `isVatDeductible`, + 1 AS `withholdingSageFk`, + 1 AS `expenseFkDeductible` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `recibida_agricola` +-- + +DROP TABLE IF EXISTS `recibida_agricola`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `recibida_agricola` ( + `recibida_id` mediumint(8) unsigned NOT NULL, + `num` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`recibida_id`), + CONSTRAINT `recibida_agricola_ibfk_1` FOREIGN KEY (`recibida_id`) REFERENCES `vn`.`invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `recibida_intrastat` +-- + +DROP TABLE IF EXISTS `recibida_intrastat`; +/*!50001 DROP VIEW IF EXISTS `recibida_intrastat`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `recibida_intrastat` AS SELECT + 1 AS `recibida_id`, + 1 AS `Codintrastat`, + 1 AS `importe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `recibida_iva` +-- + +DROP TABLE IF EXISTS `recibida_iva`; +/*!50001 DROP VIEW IF EXISTS `recibida_iva`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `recibida_iva` AS SELECT + 1 AS `id`, + 1 AS `recibida_id`, + 1 AS `iva_id`, + 1 AS `bi`, + 1 AS `gastos_id`, + 1 AS `divisa`, + 1 AS `taxTypeSageFk`, + 1 AS `transactionTypeSageFk`, + 1 AS `MYSQL_TIME` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `recibida_vencimiento` +-- + +DROP TABLE IF EXISTS `recibida_vencimiento`; +/*!50001 DROP VIEW IF EXISTS `recibida_vencimiento`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `recibida_vencimiento` AS SELECT + 1 AS `id`, + 1 AS `recibida_id`, + 1 AS `fecha`, + 1 AS `banco_id`, + 1 AS `cantidad`, + 1 AS `divisa`, + 1 AS `stamp` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `recovery` +-- + +DROP TABLE IF EXISTS `recovery`; +/*!50001 DROP VIEW IF EXISTS `recovery`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `recovery` AS SELECT + 1 AS `recovery_id`, + 1 AS `Id_Cliente`, + 1 AS `dstart`, + 1 AS `dend`, + 1 AS `amount`, + 1 AS `period` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `reference_min` +-- + +DROP TABLE IF EXISTS `reference_min`; +/*!50001 DROP VIEW IF EXISTS `reference_min`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `reference_min` AS SELECT + 1 AS `date`, + 1 AS `rate`, + 1 AS `moneda_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `reference_rate` +-- + +DROP TABLE IF EXISTS `reference_rate`; +/*!50001 DROP VIEW IF EXISTS `reference_rate`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `reference_rate` AS SELECT + 1 AS `moneda_id`, + 1 AS `date`, + 1 AS `rate` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `reinos` +-- + +DROP TABLE IF EXISTS `reinos`; +/*!50001 DROP VIEW IF EXISTS `reinos`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `reinos` AS SELECT + 1 AS `id`, + 1 AS `reino`, + 1 AS `display`, + 1 AS `color`, + 1 AS `icon`, + 1 AS `mercancia`, + 1 AS `orden`, + 1 AS `efimero` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `rounding` +-- + +DROP TABLE IF EXISTS `rounding`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `rounding` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `amount` double NOT NULL DEFAULT 0, + `price` double DEFAULT 0, + `discount` double NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `route` +-- + +DROP TABLE IF EXISTS `route`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `route` ( + `agency_id` smallint(5) unsigned NOT NULL, + `week_day` tinyint(3) unsigned NOT NULL COMMENT 'weekday de access el domingo = 1, sabado = 7. Intentar cambiar al de Mysql Lunes = 0', + PRIMARY KEY (`agency_id`,`week_day`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `scan` +-- + +DROP TABLE IF EXISTS `scan`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `scan` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `lft` int(11) NOT NULL, + `rgt` int(11) NOT NULL, + `name` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `scanTree` +-- + +DROP TABLE IF EXISTS `scanTree`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `scanTree` ( + `id` int(11) NOT NULL DEFAULT 0, + `name` varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `lft` int(11) NOT NULL, + `rgt` int(11) NOT NULL, + `depth` bigint(22) NOT NULL DEFAULT 0, + `sons` int(11) DEFAULT 0, + `lastScanned` datetime DEFAULT NULL, + `routeCount` int(11) DEFAULT NULL, + `minRoute` int(11) DEFAULT NULL, + `maxRoute` int(11) DEFAULT NULL, + `scanned` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `lft_rgt_depth` (`lft`,`rgt`,`depth`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `scan_line` +-- + +DROP TABLE IF EXISTS `scan_line`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `scan_line` ( + `scan_line_id` int(11) NOT NULL AUTO_INCREMENT, + `scan_id` int(11) NOT NULL, + `code` varchar(45) NOT NULL, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + 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 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 `Id_Trabajador`, + 1 AS `datSTART`, + 1 AS `datEND`, + 1 AS `Id_Suplente`, + 1 AS `odbc_date` */; +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 `Id_Trabajador`, + 1 AS `datSTART`, + 1 AS `datEND`, + 1 AS `Id_Cliente` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `sms` +-- + +DROP TABLE IF EXISTS `sms`; +/*!50001 DROP VIEW IF EXISTS `sms`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `sms` AS SELECT + 1 AS `id`, + 1 AS `Id_trabajador`, + 1 AS `from`, + 1 AS `to`, + 1 AS `text`, + 1 AS `sent`, + 1 AS `response`, + 1 AS `DATE_ODBC` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `sort_merge_results_ernesto` +-- + +DROP TABLE IF EXISTS `sort_merge_results_ernesto`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sort_merge_results_ernesto` ( + `hora` datetime NOT NULL, + `uptime` int(11) DEFAULT NULL, + `log_output` varchar(5) DEFAULT NULL, + `uptime_since_flush` int(11) DEFAULT NULL, + `smp_old` int(11) DEFAULT NULL, + `smp_new` int(11) DEFAULT NULL, + `smp` int(11) DEFAULT NULL, + `smp_hour` int(11) DEFAULT NULL, + `connections` int(11) DEFAULT NULL, + `Threads_created` int(11) DEFAULT NULL, + `Threads_cached` int(11) DEFAULT NULL, + `Thread_cache_size` int(11) DEFAULT NULL, + `comment` varchar(255) DEFAULT NULL, + `TABLE_OPEN_CACHE_OVERFLOWS` int(11) DEFAULT NULL, + `TABLE_OPEN_CACHE_MISSES` int(11) DEFAULT NULL, + `TABLE_OPEN_CACHE_HITS` int(11) DEFAULT NULL, + `table_open_cache` int(11) DEFAULT NULL, + `table_open_cache_instances` int(11) DEFAULT NULL, + `open_tables` int(11) DEFAULT NULL, + `opened_tables` int(11) DEFAULT NULL, + `Innodb_os_log_written` double DEFAULT NULL, + `table_definition_cache` int(11) DEFAULT NULL, + `Open_table_definitions` int(11) DEFAULT NULL, + `sort_buffer_size` int(11) DEFAULT NULL, + `join_buffer_size` int(11) DEFAULT NULL, + `read_rnd_buffer_size` int(11) DEFAULT NULL, + `tmp_table_size` int(11) DEFAULT NULL, + `max_heap_table_size` int(11) DEFAULT NULL, + `created_tmp_disk_tables` int(11) DEFAULT NULL, + `created_tmp_tables` int(11) DEFAULT NULL, + `Created_tmp_files` int(11) DEFAULT NULL, + `OpenTablesxUptimeDivOpened` float DEFAULT NULL, + `innodb_open_files` int(11) DEFAULT NULL, + `Innodb_num_open_files` int(11) DEFAULT NULL, + `open_files_limit` int(11) DEFAULT NULL, + `query_cache_size` int(11) DEFAULT NULL, + `query_cache_type` varchar(3) DEFAULT NULL, + `trx_rseg_history_len` int(11) DEFAULT NULL, + `Qcache_hits` int(11) DEFAULT NULL, + `Qcache_inserts` int(11) DEFAULT NULL, + `Qcache_not_cached` int(11) DEFAULT NULL, + PRIMARY KEY (`hora`), + UNIQUE KEY `hora_UNIQUE` (`hora`), + KEY `uptime` (`uptime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `state` +-- + +DROP TABLE IF EXISTS `state`; +/*!50001 DROP VIEW IF EXISTS `state`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `state` AS SELECT + 1 AS `id`, + 1 AS `name`, + 1 AS `order`, + 1 AS `alert_level`, + 1 AS `code`, + 1 AS `sectorProdPriority`, + 1 AS `nextStateFk`, + 1 AS `isPreviousPreparable`, + 1 AS `isPicked` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tag` +-- + +DROP TABLE IF EXISTS `tag`; +/*!50001 DROP VIEW IF EXISTS `tag`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tag` AS SELECT + 1 AS `id`, + 1 AS `name`, + 1 AS `isFree`, + 1 AS `isQuantitatif`, + 1 AS `sourceTable`, + 1 AS `unit` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tarifa_componentes` +-- + +DROP TABLE IF EXISTS `tarifa_componentes`; +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tarifa_componentes` AS SELECT + 1 AS `Id_Componente`, + 1 AS `Componente`, + 1 AS `tarifa_componentes_series_id`, + 1 AS `tarifa_class`, + 1 AS `tax`, + 1 AS `is_renewable` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tarifa_componentes_series` +-- + +DROP TABLE IF EXISTS `tarifa_componentes_series`; +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tarifa_componentes_series` AS SELECT + 1 AS `tarifa_componentes_series_id`, + 1 AS `Serie`, + 1 AS `base` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tarifas` +-- + +DROP TABLE IF EXISTS `tarifas`; +/*!50001 DROP VIEW IF EXISTS `tarifas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tarifas` AS SELECT + 1 AS `tarifa_id`, + 1 AS `fecha`, + 1 AS `warehouse_id`, + 1 AS `t0`, + 1 AS `t1`, + 1 AS `t2`, + 1 AS `t3` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tblContadores` +-- + +DROP TABLE IF EXISTS `tblContadores`; +/*!50001 DROP VIEW IF EXISTS `tblContadores`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tblContadores` AS SELECT + 1 AS `id`, + 1 AS `ochoa`, + 1 AS `nfactura`, + 1 AS `FechaInventario`, + 1 AS `HistoricoArticulo`, + 1 AS `week_goal`, + 1 AS `Rutafotos`, + 1 AS `numCaja`, + 1 AS `CodigoRojo`, + 1 AS `Tablet_Hora`, + 1 AS `t0`, + 1 AS `t1`, + 1 AS `t2`, + 1 AS `t3`, + 1 AS `cc`, + 1 AS `palet`, + 1 AS `campaign`, + 1 AS `campaign_life`, + 1 AS `truck_days`, + 1 AS `tasa_transporte`, + 1 AS `escaner_path`, + 1 AS `turnoimpreso`, + 1 AS `truck_length`, + 1 AS `fuel_consumption`, + 1 AS `petrol`, + 1 AS `maintenance`, + 1 AS `hour_price`, + 1 AS `meter_price`, + 1 AS `km_price`, + 1 AS `route_option`, + 1 AS `dbproduccion`, + 1 AS `mdbServer`, + 1 AS `fakeEmail`, + 1 AS `defaultersMaxAmount`, + 1 AS `ASIEN` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `tblIVA` +-- + +DROP TABLE IF EXISTS `tblIVA`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tblIVA` ( + `tipoiva` varchar(50) NOT NULL, + `iva` smallint(6) NOT NULL DEFAULT 0, + `cuenta` double DEFAULT 0, + `cuentaRE` double DEFAULT 0, + `cuentaivaRE` double DEFAULT 0, + `REQ` double DEFAULT 0, + PRIMARY KEY (`tipoiva`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `template_bionic_component` +-- + +DROP TABLE IF EXISTS `template_bionic_component`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `template_bionic_component` ( + `warehouse_id` smallint(5) unsigned NOT NULL, + `item_id` int(11) NOT NULL, + `component_id` int(10) unsigned NOT NULL, + `cost` decimal(10,4) NOT NULL, + UNIQUE KEY `item_warehouse_component` (`item_id`,`warehouse_id`,`component_id`) USING HASH, + KEY `item_warehouse` (`item_id`,`warehouse_id`) USING BTREE +) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `template_bionic_lot` +-- + +DROP TABLE IF EXISTS `template_bionic_lot`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `template_bionic_lot` ( + `warehouse_id` smallint(5) unsigned NOT NULL, + `item_id` int(11) NOT NULL, + `available` double DEFAULT NULL, + `buy_id` int(11) DEFAULT NULL, + `fix` tinyint(3) unsigned DEFAULT 0, + UNIQUE KEY `warehouse_id` (`warehouse_id`,`item_id`), + KEY `item_id` (`item_id`) +) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `template_bionic_price` +-- + +DROP TABLE IF EXISTS `template_bionic_price`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `template_bionic_price` ( + `warehouse_id` smallint(5) unsigned NOT NULL, + `item_id` int(11) NOT NULL, + `rate` tinyint(3) unsigned NOT NULL, + `items` int(11) DEFAULT NULL, + `grouping` int(11) DEFAULT NULL, + `price` decimal(10,2) DEFAULT NULL, + UNIQUE KEY `warehouse_id` (`warehouse_id`,`item_id`,`rate`), + KEY `item_id` (`item_id`) USING BTREE +) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `thermograph` +-- + +DROP TABLE IF EXISTS `thermograph`; +/*!50001 DROP VIEW IF EXISTS `thermograph`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `thermograph` AS SELECT + 1 AS `thermograph_id`, + 1 AS `model` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `ticketCreationData` +-- + +DROP TABLE IF EXISTS `ticketCreationData`; +/*!50001 DROP VIEW IF EXISTS `ticketCreationData`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketCreationData` AS SELECT + 1 AS `DiadelaSemana`, + 1 AS `Hora`, + 1 AS `Fecha`, + 1 AS `Dispositivo` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `ticketMRW` +-- + +DROP TABLE IF EXISTS `ticketMRW`; +/*!50001 DROP VIEW IF EXISTS `ticketMRW`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketMRW` AS SELECT + 1 AS `id_Agencia`, + 1 AS `empresa_id`, + 1 AS `Consignatario`, + 1 AS `DOMICILIO`, + 1 AS `POBLACION`, + 1 AS `CODPOSTAL`, + 1 AS `telefono`, + 1 AS `movil`, + 1 AS `IF`, + 1 AS `Id_Ticket`, + 1 AS `warehouse_id`, + 1 AS `Id_Consigna`, + 1 AS `CodigoPais`, + 1 AS `Fecha`, + 1 AS `province_id`, + 1 AS `landing` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `ticket_location__` +-- + +DROP TABLE IF EXISTS `ticket_location__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `ticket_location__` ( + `Id_Ticket` int(11) NOT NULL, + `longitude` decimal(11,7) DEFAULT NULL, + `latitude` decimal(11,7) DEFAULT NULL, + PRIMARY KEY (`Id_Ticket`), + CONSTRAINT `Id_Ticket_Location` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn`.`ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `ticket_observation` +-- + +DROP TABLE IF EXISTS `ticket_observation`; +/*!50001 DROP VIEW IF EXISTS `ticket_observation`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticket_observation` AS SELECT + 1 AS `ticket_observation_id`, + 1 AS `Id_Ticket`, + 1 AS `observation_type_id`, + 1 AS `text` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `tickets_gestdoc` +-- + +DROP TABLE IF EXISTS `tickets_gestdoc`; +/*!50001 DROP VIEW IF EXISTS `tickets_gestdoc`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tickets_gestdoc` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `gestdoc_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `time` +-- + +DROP TABLE IF EXISTS `time`; +/*!50001 DROP VIEW IF EXISTS `time`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `time` AS SELECT + 1 AS `date`, + 1 AS `period`, + 1 AS `month`, + 1 AS `year`, + 1 AS `day`, + 1 AS `week`, + 1 AS `yearMonth` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `tipsa` +-- + +DROP TABLE IF EXISTS `tipsa`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tipsa` ( + `kilos` tinyint(3) unsigned NOT NULL, + `importe` double unsigned NOT NULL, + `zona` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`kilos`,`zona`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `tmpNEWTARIFAS` +-- + +DROP TABLE IF EXISTS `tmpNEWTARIFAS`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tmpNEWTARIFAS` ( + `Id_Cliente` int(11) NOT NULL, + `Cliente` varchar(50) NOT NULL, + `Consumo_medio_mensual` double(17,0) DEFAULT NULL, + `Tarifa_Actual` int(11) DEFAULT 0, + `Nueva_Tarifa` int(11) DEFAULT NULL, + `Id_Trabajador` int(11) DEFAULT 20, + PRIMARY KEY (`Id_Cliente`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `tr2` +-- + +DROP TABLE IF EXISTS `tr2`; +/*!50001 DROP VIEW IF EXISTS `tr2`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `tr2` AS SELECT + 1 AS `id`, + 1 AS `shipped`, + 1 AS `shipmentHour`, + 1 AS `landed`, + 1 AS `landingHour`, + 1 AS `warehouseInFk`, + 1 AS `warehouseOutFk`, + 1 AS `agencyFk`, + 1 AS `ref`, + 1 AS `isDelivered`, + 1 AS `isReceived`, + 1 AS `m3`, + 1 AS `kg`, + 1 AS `cargoSupplierFk`, + 1 AS `totalEntries` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `transport` +-- + +DROP TABLE IF EXISTS `transport`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `transport` ( + `wday` tinyint(4) NOT NULL, + PRIMARY KEY (`wday`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `travel` +-- + +DROP TABLE IF EXISTS `travel`; +/*!50001 DROP VIEW IF EXISTS `travel`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `travel` AS SELECT + 1 AS `id`, + 1 AS `shipment`, + 1 AS `shipment_hour`, + 1 AS `landing`, + 1 AS `landing_hour`, + 1 AS `warehouse_id`, + 1 AS `warehouse_id_out`, + 1 AS `agency_id`, + 1 AS `ref`, + 1 AS `delivered`, + 1 AS `received`, + 1 AS `m3`, + 1 AS `kg`, + 1 AS `cargoSupplierFk`, + 1 AS `totalEntries`, + 1 AS `appointment` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `travel_pattern` +-- + +DROP TABLE IF EXISTS `travel_pattern`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `travel_pattern` ( + `travel_pattern_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `week_start` tinyint(3) unsigned NOT NULL, + `week_end` tinyint(3) unsigned NOT NULL, + `warehouse_out` smallint(5) unsigned NOT NULL, + `warehouse_in` smallint(5) unsigned NOT NULL, + `agency_id` int(11) NOT NULL, + `day_out` tinyint(3) unsigned NOT NULL, + `duration` tinyint(3) unsigned NOT NULL, + `ref` varchar(20) NOT NULL, + `cargoSupplierFk` int(10) unsigned DEFAULT NULL, + `kg` decimal(10,0) unsigned DEFAULT NULL, + `travelFk` int(10) unsigned DEFAULT NULL COMMENT 'travel origen para clonar ademas sus entradas', + PRIMARY KEY (`travel_pattern_id`), + KEY `warehouse_out` (`warehouse_out`), + KEY `warehouse_in` (`warehouse_in`), + KEY `agency_id` (`agency_id`), + KEY `travel_pattern_ibfk_6_idx` (`cargoSupplierFk`), + KEY `travel_pattern_FK` (`travelFk`), + CONSTRAINT `travel_pattern_FK` FOREIGN KEY (`travelFk`) REFERENCES `vn`.`travel` (`id`) ON UPDATE CASCADE, + CONSTRAINT `travel_pattern_ibfk_3` FOREIGN KEY (`warehouse_out`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `travel_pattern_ibfk_4` FOREIGN KEY (`agency_id`) REFERENCES `vn`.`agencyMode` (`id`) ON UPDATE CASCADE, + CONSTRAINT `travel_pattern_ibfk_5` FOREIGN KEY (`warehouse_in`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `travel_pattern_supplierFk` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `vn`.`supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `travel_reserve` +-- + +DROP TABLE IF EXISTS `travel_reserve`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `travel_reserve` ( + `travel_reserve_id` int(11) NOT NULL AUTO_INCREMENT, + `travel_id` int(11) unsigned NOT NULL, + `Id_Trabajador` int(11) NOT NULL, + `reserved` decimal(4,1) DEFAULT NULL, + `buyed` decimal(4,1) DEFAULT NULL, + `askingfor` decimal(4,1) DEFAULT NULL, + `odbc_date` timestamp NULL DEFAULT current_timestamp(), + `labeled` decimal(4,1) unsigned NOT NULL DEFAULT 0.0, + PRIMARY KEY (`Id_Trabajador`,`travel_id`), + UNIQUE KEY `travel_reserve_id_UNIQUE` (`travel_reserve_id`), + KEY `travel_travel_reserve_idx` (`travel_id`), + KEY `traveL_buyer_id_idx` (`Id_Trabajador`), + CONSTRAINT `travel_reserve_ibfk_1` FOREIGN KEY (`travel_id`) REFERENCES `vn`.`travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='En esta tabla almacenamos los m3 que cada comprador tiene asignados, por travel.'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `travel_thermograph` +-- + +DROP TABLE IF EXISTS `travel_thermograph`; +/*!50001 DROP VIEW IF EXISTS `travel_thermograph`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `travel_thermograph` AS SELECT + 1 AS `thermograph_id`, + 1 AS `odbc_date`, + 1 AS `warehouse_id`, + 1 AS `travel_id`, + 1 AS `temperature`, + 1 AS `result`, + 1 AS `gestdoc_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `trolley` +-- + +DROP TABLE IF EXISTS `trolley`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `trolley` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `fecha` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `ref` varchar(4) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `turn__` +-- + +DROP TABLE IF EXISTS `turn__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `turn__` ( + `number` int(11) NOT NULL, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`number`,`odbc_date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unary` +-- + +DROP TABLE IF EXISTS `unary`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unary` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `parent` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `idunary_UNIQUE` (`id`), + KEY `unary_parent_idx` (`parent`), + CONSTRAINT `unary_parent` FOREIGN KEY (`parent`) REFERENCES `unary` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unaryScanFilter` +-- + +DROP TABLE IF EXISTS `unaryScanFilter`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unaryScanFilter` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `filter` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unary_scan` +-- + +DROP TABLE IF EXISTS `unary_scan`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unary_scan` ( + `unary_id` int(11) NOT NULL, + `name` varchar(45) DEFAULT NULL, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + `type` set('BUYS','EXPEDITIONS') NOT NULL, + PRIMARY KEY (`unary_id`), + KEY `scan_unary_idx` (`unary_id`), + CONSTRAINT `unary_scan` FOREIGN KEY (`unary_id`) REFERENCES `unary` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unary_scan_line` +-- + +DROP TABLE IF EXISTS `unary_scan_line`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unary_scan_line` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `code` varchar(45) NOT NULL, + `odbc_date` timestamp NOT NULL DEFAULT current_timestamp(), + `unary_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `id_UNIQUE` (`id`), + KEY `unary_line_idx` (`unary_id`), + CONSTRAINT `unary_line` FOREIGN KEY (`unary_id`) REFERENCES `unary_scan` (`unary_id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unary_scan_line_buy` +-- + +DROP TABLE IF EXISTS `unary_scan_line_buy`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unary_scan_line_buy` ( + `scan_line_id` int(11) NOT NULL, + `Id_Article` int(11) NOT NULL, + PRIMARY KEY (`scan_line_id`), + UNIQUE KEY `scan_line_id_UNIQUE` (`scan_line_id`), + KEY `Id_Article_buy_idx` (`Id_Article`), + CONSTRAINT `Id_Article_buy` FOREIGN KEY (`Id_Article`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `scan_line_id_patriarcal` FOREIGN KEY (`scan_line_id`) REFERENCES `unary_scan_line` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unary_scan_line_expedition` +-- + +DROP TABLE IF EXISTS `unary_scan_line_expedition`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unary_scan_line_expedition` ( + `scan_line_id` int(11) NOT NULL, + `expedition_id` int(11) NOT NULL, + PRIMARY KEY (`scan_line_id`), + UNIQUE KEY `scan_line_id_UNIQUE` (`scan_line_id`), + KEY `expedition_id_scan_idx` (`expedition_id`), + CONSTRAINT `expedition_id_scan` FOREIGN KEY (`expedition_id`) REFERENCES `vn`.`expedition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `unary_source` +-- + +DROP TABLE IF EXISTS `unary_source`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `unary_source` ( + `name` varchar(100) NOT NULL, + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `v_Articles_botanical` +-- + +DROP TABLE IF EXISTS `v_Articles_botanical`; +/*!50001 DROP VIEW IF EXISTS `v_Articles_botanical`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_Articles_botanical` AS SELECT + 1 AS `itemFk`, + 1 AS `ediBotanic` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_account` +-- + +DROP TABLE IF EXISTS `v_account`; +/*!50001 DROP VIEW IF EXISTS `v_account`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_account` AS SELECT + 1 AS `user_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_analisis_ventas` +-- + +DROP TABLE IF EXISTS `v_analisis_ventas`; +/*!50001 DROP VIEW IF EXISTS `v_analisis_ventas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_analisis_ventas` AS SELECT + 1 AS `Familia`, + 1 AS `Reino`, + 1 AS `Comercial`, + 1 AS `Comprador`, + 1 AS `Provincia`, + 1 AS `almacen`, + 1 AS `Año`, + 1 AS `Mes`, + 1 AS `Semana`, + 1 AS `Vista`, + 1 AS `Importe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_barcodes` +-- + +DROP TABLE IF EXISTS `v_barcodes`; +/*!50001 DROP VIEW IF EXISTS `v_barcodes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_barcodes` AS SELECT + 1 AS `code`, + 1 AS `Id_Article` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_compres` +-- + +DROP TABLE IF EXISTS `v_compres`; +/*!50001 DROP VIEW IF EXISTS `v_compres`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_compres` AS SELECT + 1 AS `Familia`, + 1 AS `reino_id`, + 1 AS `Id_Compra`, + 1 AS `Id_Entrada`, + 1 AS `Id_Article`, + 1 AS `Cantidad`, + 1 AS `Costefijo`, + 1 AS `Portefijo`, + 1 AS `Novincular`, + 1 AS `Etiquetas`, + 1 AS `Packing`, + 1 AS `grouping`, + 1 AS `Comisionfija`, + 1 AS `Embalajefijo`, + 1 AS `Id_Cubo`, + 1 AS `Tarifa1`, + 1 AS `Tarifa2`, + 1 AS `Tarifa3`, + 1 AS `PVP`, + 1 AS `Vida`, + 1 AS `Id_Trabajador`, + 1 AS `punteo`, + 1 AS `odbc_date`, + 1 AS `Inventario`, + 1 AS `Id_Proveedor`, + 1 AS `Fecha`, + 1 AS `Confirmada`, + 1 AS `Redada`, + 1 AS `empresa_id`, + 1 AS `travel_id`, + 1 AS `Pedida`, + 1 AS `recibida_id`, + 1 AS `id`, + 1 AS `shipment`, + 1 AS `landing`, + 1 AS `warehouse_id`, + 1 AS `warehouse_id_out`, + 1 AS `agency_id`, + 1 AS `ref`, + 1 AS `delivered`, + 1 AS `received`, + 1 AS `Article`, + 1 AS `Medida`, + 1 AS `Tallos`, + 1 AS `caja`, + 1 AS `Categoria`, + 1 AS `id_origen`, + 1 AS `Tipo`, + 1 AS `tipo_id`, + 1 AS `Color`, + 1 AS `Min`, + 1 AS `Coste`, + 1 AS `fuente`, + 1 AS `cm3`, + 1 AS `producer_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_departure_limit` +-- + +DROP TABLE IF EXISTS `v_departure_limit`; +/*!50001 DROP VIEW IF EXISTS `v_departure_limit`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_departure_limit` AS SELECT + 1 AS `warehouse_id`, + 1 AS `fecha`, + 1 AS `hora`, + 1 AS `minSpeed` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_descuadre_bionic` +-- + +DROP TABLE IF EXISTS `v_descuadre_bionic`; +/*!50001 DROP VIEW IF EXISTS `v_descuadre_bionic`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_descuadre_bionic` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `Alias`, + 1 AS `Concepte`, + 1 AS `suma_componente`, + 1 AS `Preu`, + 1 AS `Descuento`, + 1 AS `diferencia`, + 1 AS `Fecha`, + 1 AS `benvenut` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_empresa` +-- + +DROP TABLE IF EXISTS `v_empresa`; +/*!50001 DROP VIEW IF EXISTS `v_empresa`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_empresa` AS SELECT + 1 AS `logo`, + 1 AS `id`, + 1 AS `registro`, + 1 AS `gerente_id`, + 1 AS `alta`, + 1 AS `Nombre`, + 1 AS `Apellidos`, + 1 AS `Proveedor`, + 1 AS `Domicilio`, + 1 AS `CP`, + 1 AS `Localidad`, + 1 AS `NIF`, + 1 AS `Telefono`, + 1 AS `Alias`, + 1 AS `abbreviation` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_inter` +-- + +DROP TABLE IF EXISTS `v_inter`; +/*!50001 DROP VIEW IF EXISTS `v_inter`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_inter` AS SELECT + 1 AS `inter_id`, + 1 AS `state_id`, + 1 AS `nota`, + 1 AS `odbc_date`, + 1 AS `Id_Ticket`, + 1 AS `Id_Trabajador`, + 1 AS `Id_supervisor` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_jerarquia` +-- + +DROP TABLE IF EXISTS `v_jerarquia`; +/*!50001 DROP VIEW IF EXISTS `v_jerarquia`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_jerarquia` AS SELECT + 1 AS `Id_Trabajador`, + 1 AS `boss_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_miriam` +-- + +DROP TABLE IF EXISTS `v_miriam`; +/*!50001 DROP VIEW IF EXISTS `v_miriam`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_miriam` AS SELECT + 1 AS `Id_Article`, + 1 AS `Concepte`, + 1 AS `Cantidad`, + 1 AS `Preu`, + 1 AS `Descuento`, + 1 AS `Fecha`, + 1 AS `Id_Cliente`, + 1 AS `Importe` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_price_fixed` +-- + +DROP TABLE IF EXISTS `v_price_fixed`; +/*!50001 DROP VIEW IF EXISTS `v_price_fixed`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_price_fixed` AS SELECT + 1 AS `warehouse_id`, + 1 AS `item_id`, + 1 AS `rate_0`, + 1 AS `rate_1`, + 1 AS `rate_2`, + 1 AS `rate_3`, + 1 AS `date_start`, + 1 AS `date_end`, + 1 AS `bonus`, + 1 AS `grouping`, + 1 AS `Packing`, + 1 AS `caja` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_price_fixed_group` +-- + +DROP TABLE IF EXISTS `v_price_fixed_group`; +/*!50001 DROP VIEW IF EXISTS `v_price_fixed_group`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_price_fixed_group` AS SELECT + 1 AS `warehouse_id`, + 1 AS `item_id`, + 1 AS `rate_0`, + 1 AS `rate_1`, + 1 AS `rate_2`, + 1 AS `rate_3`, + 1 AS `date_start`, + 1 AS `date_end`, + 1 AS `bonus`, + 1 AS `grouping`, + 1 AS `Packing`, + 1 AS `caja` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_ticket_amount` +-- + +DROP TABLE IF EXISTS `v_ticket_amount`; +/*!50001 DROP VIEW IF EXISTS `v_ticket_amount`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_ticket_amount` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `amount` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_ventes` +-- + +DROP TABLE IF EXISTS `v_ventes`; +/*!50001 DROP VIEW IF EXISTS `v_ventes`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_ventes` AS SELECT + 1 AS `Agencia`, + 1 AS `Categoria`, + 1 AS `tipo_id`, + 1 AS `Medida`, + 1 AS `Article`, + 1 AS `Color`, + 1 AS `Id_Cliente`, + 1 AS `Tipo`, + 1 AS `Factura`, + 1 AS `warehouse_id`, + 1 AS `Id_Movimiento`, + 1 AS `Id_Article`, + 1 AS `Familia`, + 1 AS `Id_Ticket`, + 1 AS `Concepte`, + 1 AS `Cantidad`, + 1 AS `quantity`, + 1 AS `Preu`, + 1 AS `Descuento`, + 1 AS `CostFixat`, + 1 AS `Reservado`, + 1 AS `OK`, + 1 AS `PrecioFijado`, + 1 AS `odbc_date`, + 1 AS `Fecha`, + 1 AS `FechaCompleta`, + 1 AS `Alias`, + 1 AS `Id_Consigna`, + 1 AS `Importe`, + 1 AS `Origen`, + 1 AS `reino_id`, + 1 AS `invoice`, + 1 AS `producer_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_warehouse` +-- + +DROP TABLE IF EXISTS `v_warehouse`; +/*!50001 DROP VIEW IF EXISTS `v_warehouse`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_warehouse` AS SELECT + 1 AS `id`, + 1 AS `almacen` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_xsubclien` +-- + +DROP TABLE IF EXISTS `v_xsubclien`; +/*!50001 DROP VIEW IF EXISTS `v_xsubclien`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_xsubclien` AS SELECT + 1 AS `Id_Cliente`, + 1 AS `empresa_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_xsubcuentas` +-- + +DROP TABLE IF EXISTS `v_xsubcuentas`; +/*!50001 DROP VIEW IF EXISTS `v_xsubcuentas`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_xsubcuentas` AS SELECT + 1 AS `COD`, + 1 AS `TITULO`, + 1 AS `NIF`, + 1 AS `DOMICILIO`, + 1 AS `POBLACION`, + 1 AS `PROVINCIA`, + 1 AS `CODPOSTAL`, + 1 AS `country_code`, + 1 AS `empresa_id`, + 1 AS `EMAIL`, + 1 AS `IDNIF` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `v_xsubprov` +-- + +DROP TABLE IF EXISTS `v_xsubprov`; +/*!50001 DROP VIEW IF EXISTS `v_xsubprov`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `v_xsubprov` AS SELECT + 1 AS `proveedor_id`, + 1 AS `empresa_id` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `versiones` +-- + +DROP TABLE IF EXISTS `versiones`; +/*!50001 DROP VIEW IF EXISTS `versiones`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `versiones` AS SELECT + 1 AS `programa`, + 1 AS `version`, + 1 AS `critical` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `viaxpress` +-- + +DROP TABLE IF EXISTS `viaxpress`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `viaxpress` ( + `codigo_postal` varchar(5) NOT NULL, + `zona` tinyint(4) NOT NULL DEFAULT 2, + `m_t` tinyint(4) NOT NULL DEFAULT 0, + `POBLACION` varchar(25) NOT NULL, + `PROVINCIA` varchar(20) NOT NULL, + PRIMARY KEY (`codigo_postal`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `vnCreditClassification` +-- + +DROP TABLE IF EXISTS `vnCreditClassification`; +/*!50001 DROP VIEW IF EXISTS `vnCreditClassification`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `vnCreditClassification` AS SELECT + 1 AS `id`, + 1 AS `client`, + 1 AS `dateStart`, + 1 AS `dateEnd` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `vnCreditInsurance` +-- + +DROP TABLE IF EXISTS `vnCreditInsurance`; +/*!50001 DROP VIEW IF EXISTS `vnCreditInsurance`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `vnCreditInsurance` AS SELECT + 1 AS `id`, + 1 AS `creditClassification`, + 1 AS `credit`, + 1 AS `creationDate`, + 1 AS `grade` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `vnSolunionCAP` +-- + +DROP TABLE IF EXISTS `vnSolunionCAP`; +/*!50001 DROP VIEW IF EXISTS `vnSolunionCAP`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `vnSolunionCAP` AS SELECT + 1 AS `creditInsurance`, + 1 AS `dateStart`, + 1 AS `dateEnd`, + 1 AS `dateLeaving` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `warehouse` +-- + +DROP TABLE IF EXISTS `warehouse`; +/*!50001 DROP VIEW IF EXISTS `warehouse`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `warehouse` AS SELECT + 1 AS `id`, + 1 AS `name`, + 1 AS `inventario`, + 1 AS `fuente`, + 1 AS `is_comparative`, + 1 AS `comisionantes`, + 1 AS `reserve`, + 1 AS `isManaged`, + 1 AS `tpv`, + 1 AS `hasStowaway`, + 1 AS `hasDms`, + 1 AS `address_name`, + 1 AS `delay`, + 1 AS `Id_Paises`, + 1 AS `zone_label`, + 1 AS `valuatedInventory`, + 1 AS `hasConfectionTeam` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `warehouse_alias` +-- + +DROP TABLE IF EXISTS `warehouse_alias`; +/*!50001 DROP VIEW IF EXISTS `warehouse_alias`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `warehouse_alias` AS SELECT + 1 AS `warehouse_alias_id`, + 1 AS `alias` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `warehouse_filtro` +-- + +DROP TABLE IF EXISTS `warehouse_filtro`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `warehouse_filtro` ( + `warehouse_id` smallint(6) unsigned NOT NULL, + `Id_Trabajador` int(11) NOT NULL, + `ok` tinyint(3) unsigned DEFAULT 1, + PRIMARY KEY (`Id_Trabajador`,`warehouse_id`), + KEY `wh_worker_idx` (`Id_Trabajador`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Tabla que permite filtrar los almacenes que muestra la comparativa, recordando la selección personal del usuario'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `warehouse_group` +-- + +DROP TABLE IF EXISTS `warehouse_group`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `warehouse_group` ( + `warehouse_alias_id` smallint(5) unsigned NOT NULL DEFAULT 22, + `warehouse_id` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`warehouse_alias_id`,`warehouse_id`), + KEY `warehosue_group_ware_idx` (`warehouse_id`), + CONSTRAINT `warehosue_group_ware` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `warehouse_group_alias` FOREIGN KEY (`warehouse_alias_id`) REFERENCES `vn`.`warehouseAlias` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Agrupa warehouses '; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `warehouse_joined` +-- + +DROP TABLE IF EXISTS `warehouse_joined`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `warehouse_joined` ( + `warehouse_id` smallint(5) unsigned NOT NULL, + `warehouse_alias_id` smallint(5) unsigned NOT NULL, + PRIMARY KEY (`warehouse_id`,`warehouse_alias_id`), + CONSTRAINT `warehouse_joined_ibfk_3` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `warehouse_lc` +-- + +DROP TABLE IF EXISTS `warehouse_lc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `warehouse_lc` ( + `whin` smallint(6) unsigned NOT NULL, + `whout` smallint(6) unsigned NOT NULL, + `m3` double NOT NULL DEFAULT 15, + `days` int(11) NOT NULL DEFAULT 1, + PRIMARY KEY (`whin`,`whout`), + KEY `whout_wh_idx` (`whout`), + CONSTRAINT `whin_wh` FOREIGN KEY (`whin`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `whout_wh` FOREIGN KEY (`whout`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Warehouses cost for linking'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `warehouse_pickup` +-- + +DROP TABLE IF EXISTS `warehouse_pickup`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `warehouse_pickup` ( + `warehouse_id` smallint(5) unsigned NOT NULL, + `agency_id` int(11) DEFAULT NULL, + PRIMARY KEY (`warehouse_id`), + UNIQUE KEY `agency_id` (`agency_id`,`warehouse_id`), + CONSTRAINT `warehouse_pickup_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `warehouse_pickup_ibfk_2` FOREIGN KEY (`agency_id`) REFERENCES `vn`.`agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `wh_selection` +-- + +DROP TABLE IF EXISTS `wh_selection`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `wh_selection` ( + `Id_Trabajador` int(10) unsigned NOT NULL, + `warehouse_id` smallint(6) unsigned NOT NULL, + PRIMARY KEY (`Id_Trabajador`,`warehouse_id`), + KEY `Trabajadores` (`Id_Trabajador`), + KEY `Warehouse` (`warehouse_id`), + CONSTRAINT `Trabajadores` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `Warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Permite que los usuarios seleccionen los almacenes que van a'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `widget` +-- + +DROP TABLE IF EXISTS `widget`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `widget` ( + `widget_id` int(11) NOT NULL, + `chr` int(11) NOT NULL, + PRIMARY KEY (`widget_id`), + UNIQUE KEY `chr_UNIQUE` (`chr`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `wks` +-- + +DROP TABLE IF EXISTS `wks`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `wks` ( + `wk` int(10) unsigned NOT NULL, + `yr` int(10) unsigned NOT NULL, + `vwk` int(10) unsigned NOT NULL, + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `comments` text DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `workcenter_holiday` +-- + +DROP TABLE IF EXISTS `workcenter_holiday`; +/*!50001 DROP VIEW IF EXISTS `workcenter_holiday`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `workcenter_holiday` AS SELECT + 1 AS `workcenter_id`, + 1 AS `day`, + 1 AS `year` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `workerDocument` +-- + +DROP TABLE IF EXISTS `workerDocument`; +/*!50001 DROP VIEW IF EXISTS `workerDocument`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `workerDocument` AS SELECT + 1 AS `id`, + 1 AS `worker`, + 1 AS `document`, + 1 AS `isReadableByWorker` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `workerTeam` +-- + +DROP TABLE IF EXISTS `workerTeam`; +/*!50001 DROP VIEW IF EXISTS `workerTeam`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `workerTeam` AS SELECT + 1 AS `team`, + 1 AS `id`, + 1 AS `user` */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `zoneNickname` +-- + +DROP TABLE IF EXISTS `zoneNickname`; +/*!50001 DROP VIEW IF EXISTS `zoneNickname`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `zoneNickname` AS SELECT + 1 AS `warehouse_id`, + 1 AS `agency_id`, + 1 AS `zona`, + 1 AS `alias` */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `zones` +-- + +DROP TABLE IF EXISTS `zones`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `zones` ( + `zone_id` tinyint(4) NOT NULL, + `name` varchar(45) NOT NULL, + `printingOrder` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`zone_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Zonas de reparto'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping events for database 'vn2008' +-- +/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; +/*!50106 DROP EVENT IF EXISTS `raidUpdate` */; +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 = utf8mb3 */ ;; +/*!50003 SET character_set_results = utf8mb3 */ ;; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `raidUpdate` ON SCHEDULE EVERY 1 DAY STARTS '2017-12-29 00:05:00' ON COMPLETION PRESERVE ENABLE DO CALL raidUpdate */ ;; +/*!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 */ ; + +-- +-- Dumping routines for database 'vn2008' +-- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `cc_to_iban` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `cc_to_iban`(cc VARCHAR(20)) RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN + DECLARE iban VARCHAR(4); + select + CONCAT('ES', + RIGHT( + concat(0, + 98- + mod( + concat( + mod( + concat( + mod( + concat( + mod( + substring(cc,1,8), + 97), + substring(cc,9,8) + ), + 97), + substring( + concat( + cc, + 142800 + ), + 17, + 8 + ) + ), + 97), + substring( + concat( + cc, + 142800 + ), + 25, + 2 + ) + ), + 97) + ) + ,2) + )into iban; +RETURN iban; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `intrastat_neto` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `intrastat_neto`(intINSTRASTAT INTEGER,intUNIDADES INTEGER) RETURNS double + DETERMINISTIC +BEGIN + + DECLARE n DOUBLE; + + SELECT ROUND(intUNIDADES / (SUM(MEDIA) / COUNT(media)), 2) INTO n FROM + (SELECT *, unidades / neto MEDIA + FROM intrastat_data + WHERE intrastat_id = intINSTRASTAT AND neto + AND unidades > 0 + ORDER BY odbc_date DESC + LIMIT 20) t; + -- JGF 01/06 per a evitar Kg en negatiu + RETURN n/2; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `nz` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `nz`(dblCANTIDAD DOUBLE) RETURNS double + DETERMINISTIC +BEGIN + + DECLARE dblRESULT DOUBLE; + + SET dblRESULT = IFNULL(dblCANTIDAD,0); + + RETURN dblRESULT; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `red` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `red`(intCANTIDAD DOUBLE) RETURNS double + DETERMINISTIC +BEGIN + + DECLARE n DOUBLE; + + SET n = SIGN(intCANTIDAD) * TRUNCATE( (ABS(intCANTIDAD) * 100) + 0.5001 ,0) /100 ; + + RETURN n; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `account_conciliacion_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `account_conciliacion_add`() +BEGIN + UPDATE account_conciliacion ac + JOIN + ( + SELECT idaccount_conciliacion, @c:= if(@id = id_calculated, @c + 1, 1) contador, + @id:= id_calculated as id_calculated, concat(id_calculated,'(',@c,')') as new_id + FROM account_conciliacion + JOIN + ( + select id_calculated, count(*) rep, @c:= 0, @id:= concat('-',id_calculated) + from account_conciliacion + group by id_calculated + having rep > 1 + ) sub using(id_calculated) + ) sub2 using(idaccount_conciliacion) + SET ac.id_calculated = sub2.new_id; + + INSERT INTO Cajas(Cajafecha, Partida, Serie, Concepto, Entrada, + Salida, Id_Banco,empresa_id, warehouse_id, + Proveedores_account_id, id_calculated, InForeignValue, OutForeignValue, Id_Trabajador) + SELECT Fechaoperacion, TRUE, 'MB', ac.Concepto, IF(DebeHaber = 2 AND currencyFk = 1, importe,null), + IF(DebeHaber = 1 AND currencyFk = 1, importe, null), a.id, sa.supplierFk, 1, + ac.Id_Proveedores_account, ac.id_calculated, IF(DebeHaber = 2 AND NOT currencyFk = 1, importe, null), + IF(DebeHaber = 1 AND NOT currencyFk = 1, importe, null), account.myUser_getId() + FROM account_conciliacion ac + JOIN vn.supplierAccount sa on sa.id = ac.Id_Proveedores_account + JOIN vn.accounting a ON a.id = sa.accountingFk + LEFT JOIN Cajas c on c.id_calculated = ac.id_calculated + WHERE c.Id_Caja IS 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `add_awb_component` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `add_awb_component`(IN vAwbFk SMALLINT) +BEGIN + + DECLARE vShipped DATE; + DECLARE vHasStems BOOLEAN; + + SELECT tr.shipped, IF(a.stems, TRUE, FALSE) + INTO vShipped, vHasStems + FROM vn.travel tr + JOIN vn.entry e ON e.travelFk = tr.id + JOIN vn.duaEntry de ON de.entryFk = e.id + JOIN vn.dua d ON d.id = de.duaFk + JOIN vn.awb a ON a.id = d.awbFk + WHERE awbFk = vAwbFk + LIMIT 1; + + INSERT IGNORE INTO awb_component (awb_id,Id_Proveedor,awb_component_type_id,awb_role_id,awb_unit_id,value,Id_Moneda) + SELECT id, Id_Proveedor, awb_component_type_id, awb_role_id,awb_unit_id, LEAST(GREATEST(value1, IFNULL(min_value, value1)), IFNULL(max_value, value1)), Id_Moneda + FROM ( + SELECT a.id, + IFNULL(act.carguera_id, + CASE awb_role_id + WHEN 1 THEN a.carguera_id + WHEN 2 THEN a.transitario_id + WHEN 3 THEN f.airline_id + END + ) Id_Proveedor, + act.awb_component_type_id, + act.awb_role_id, + act.awb_unit_id, + value * + CASE awb_unit_id + WHEN '1000Tj-20' THEN ((CAST(stems AS SIGNED) - 20000)/1000) + (min_value / value) + WHEN '1000Tj-10' THEN ((CAST(stems AS SIGNED) - 10000)/1000) + (min_value / value) + WHEN '100GW' THEN peso/100 + WHEN 'AWB' THEN 1 -- No action + WHEN 'FB' THEN hb/2 + WHEN 'GW' THEN peso + WHEN 'TW' THEN GREATEST(peso,volume_weight) + WHEN 'PN' THEN LEAST(90, value + a.propertyNumber * 10) + END value1, + value, + act.Id_Moneda, + act.min_value, + act.max_value + FROM awb a + JOIN flight f ON f.flight_id = a.flight_id + LEFT JOIN awb_component_template act ON + ((IFNULL(act.carguera_id, a.carguera_id) = a.carguera_id AND awb_role_id = 1) + OR (IFNULL(act.carguera_id, a.transitario_id) = a.transitario_id AND awb_role_id = 2) + OR (IFNULL(act.airline_id, f.airline_id) = f.airline_id AND awb_role_id = 3) + OR (awb_role_id = 4)) + AND IFNULL(act.airport_out, f.airport_out) = f.airport_out + AND IFNULL(act.airport_in, f.airport_in) = f.airport_in + AND IFNULL(act.airline_id, f.airline_id) = f.airline_id + AND INSTR(IFNULL(act.days, WEEKDAY(vShipped) + 1),WEEKDAY(vShipped) + 1) + JOIN awb_component_type acty ON acty.awb_component_type_id = act.awb_component_type_id + WHERE a.id = vAwbFk AND Fecha <= vShipped + AND (vHasStems = TRUE OR acty.hasStems) + ORDER BY Fecha DESC, act.days DESC LIMIT 10000000000000000000 + ) t; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `agencia_descuadre` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `agencia_descuadre`(vFrom DATE, vTo DATE, vAgencyModeFk INT, vWarehouseAlias INT) +BEGIN + DECLARE vToDayEnd DATETIME; + + SET vToDayEnd = util.dayEnd(vTo); + + SELECT t.id ticketFk,t.addressFk, + v.amount AS VN, v.amount - shipping_charge AS Difer, + e.shipping_charge AS teorico, t.packages, t.clientFk, t.zoneFk, a.provinceFk + + FROM vn.ticket t + LEFT JOIN + (SELECT ticketFk, SUM(amount) amount,shipped + FROM vn.sale_freightComponent + WHERE shipped BETWEEN vFrom AND vToDayEnd + GROUP BY ticketFk) v ON t.id = v.ticketFk + LEFT JOIN (SELECT t.id, SUM(t.zonePrice * ebv.ratio) shipping_charge + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk + WHERE t.shipped BETWEEN vFrom AND vToDayEnd + GROUP BY t.id + ) e ON t.id = e.id + JOIN vn.address a ON a.id = t.addressFk + JOIN warehouse_group wg ON wg.warehouse_id = t.warehouseFk + WHERE DATE(t.shipped) BETWEEN vFrom AND vToDayEnd + AND t.agencyModeFk = vAgencyModeFk + AND wg.warehouse_alias_id = vWarehouseAlias; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `agencia_volume` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `agencia_volume`() +BEGIN + DECLARE vStarted DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE()); + DECLARE vEnded DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE(), '23:59:59'); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_PackagingEstimated; + CREATE TEMPORARY TABLE tmp.ticket_PackagingEstimated + ( + ticketFk INT PRIMARY KEY + ,boxes INT DEFAULT 0 + ); + + INSERT INTO tmp.ticket_PackagingEstimated(ticketFk, boxes) + SELECT sv.ticketFk, CEIL(1000 * sum(sv.volume) / vc.standardFlowerBox) + FROM vn.ticket t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.volumeConfig vc + WHERE t.shipped BETWEEN vStarted AND vEnded + AND IFNULL(t.packages,0) = 0 + GROUP BY t.id; + SELECT * FROM + ( + SELECT ag.id agency_id, + CONCAT(RPAD(c.country, 16,' _') ,' ',ag.name) Agencia, + count(*) expediciones, + sum(t.packages) Bultos, + sum(tpe.boxes) Faltan + FROM vn.ticket t + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.country c ON w.countryFk = c.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN tmp.ticket_PackagingEstimated tpe ON tpe.ticketFk = t.id + WHERE t.shipped BETWEEN vStarted AND vEnded + AND ag.isOwn = FALSE + GROUP BY ag.id + ) sub + ORDER BY Agencia; + + DROP TEMPORARY TABLE tmp.ticket_PackagingEstimated; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `agencyModeImbalance` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyModeImbalance`(vStarted DATE, vEnded DATE) +BEGIN +/** + * Devuelve el valor de los precios teorico, practico de las agencias + * y si ademas es de mrw lo compara con su fichero previamente procesado + * + * @param vEktFk Identificador de edi.ekt + */ + DECLARE vEndedDayEnd DATETIME; + + SET vEndedDayEnd = util.dayEnd(vEnded); + + SELECT t.id ticketFk,t.addressFk, + CAST(v.amount AS DECIMAL (10,2)) AS VN, + CAST(v.amount - e.shipping_charge AS DECIMAL (10,2)) AS Difer, + CAST(mrwPrice AS DECIMAL (10,2)) mrwPrice, + CAST(e.shipping_charge - mrwPrice AS DECIMAL (10,2)) mrwDifference, + CAST(e.shipping_charge AS DECIMAL (10,2)) AS teorico, + CAST(e.extraCharge AS DECIMAL (10,2)) AS extraCharge, + t.packages, t.clientFk, + t.zoneFk, a.provinceFk, mrwCount + FROM vn.ticket t + LEFT JOIN + (SELECT ticketFk, SUM(amount) amount, fc.shipped + FROM vn.sale_freightComponent fc + JOIN vn.ticket t ON t.id = fc.ticketFk + JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk + WHERE fc.shipped BETWEEN vStarted AND vEndedDayEnd + GROUP BY ticketFk) v ON t.id = v.ticketFk + LEFT JOIN (SELECT t.id, + SUM(t.zonePrice) shipping_charge, + SUM(IFNULL(aex.price,0)) extraCharge + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + LEFT JOIN vn.packaging p ON p.id = e.packagingFk + JOIN tmp.agencyMode amc ON amc.agencyModeFk = t.agencyModeFk + JOIN vn.agencyMode am ON am.id = amc.agencyModeFk + LEFT JOIN vn.agencyExtraCharge aex ON p.width+p.depth+p.height BETWEEN aex.sizeMin AND aex.sizeMax AND aex.agencyFk = am.agencyFk + WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd + GROUP BY t.id + ) e ON t.id = e.id + LEFT JOIN (SELECT ticketFk, SUM(price) mrwPrice, COUNT(*) mrwCount + FROM vn.mrw + GROUP BY ticketFk) mrw ON mrw.ticketFk = t.id + JOIN vn.address a ON a.id = t.addressFk + JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk + WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `article` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `article`() +BEGIN +/** + * Crea la tabla temporal: article_inventory + */ + DROP TEMPORARY TABLE IF EXISTS article_inventory; + CREATE TEMPORARY TABLE article_inventory + ( + `article_id` INT(11) NOT NULL PRIMARY KEY, + `future` DATETIME + ) + ENGINE = MEMORY; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `article_available_single` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `article_available_single`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT) +BEGIN + +/* CALL bionic_available_single (v_wh, v_date,id_single,0);*/ + + + SELECT available AS minimo FROM tmp.item + WHERE item_id = id_single; +-- ixen totes les linies en lloc d'una sola + DROP TEMPORARY TABLE IF EXISTS tmp.item; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `article_multiple_buy` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `article_multiple_buy`(v_date DATETIME, wh INT) +BEGIN + CALL vn.item_multipleBuy(v_date, wh); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `article_multiple_buy_date` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `article_multiple_buy_date`( + IN vDated DATETIME, + IN vWarehouseFk TINYINT(3) +) +BEGIN + CALL vn.item_multipleBuyByDate(vDated, vWarehouseFk); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `availableTraslate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `availableTraslate`( + vWarehouseLanding INT, + vDated DATE, + vWarehouseShipment INT) +proc: BEGIN + DECLARE vDatedFrom DATE; + DECLARE vDatedTo DATETIME; + DECLARE vDatedReserve DATETIME; + DECLARE vDatedInventory DATE; + + IF vDated < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + CALL vn.item_getStock (vWarehouseLanding, vDated, NULL); + + -- Calcula algunos parámetros necesarios + SET vDatedFrom = TIMESTAMP(vDated, '00:00:00'); + SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59'); + SELECT FechaInventario INTO vDatedInventory FROM tblContadores; + SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vDatedReserve + FROM hedera.orderConfig; + + -- Calcula el ultimo dia de vida para cada producto + DROP TEMPORARY TABLE IF EXISTS itemRange; + CREATE TEMPORARY TABLE itemRange + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT c.itemFk, MAX(t.landed) dated + FROM vn.buy c + JOIN vn.entry e ON c.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDatedInventory AND vDatedFrom + AND t.warehouseInFk = vWarehouseLanding + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + GROUP BY c.itemFk; + + -- Tabla con el ultimo dia de last_buy para cada producto que hace un replace de la anterior + CALL vn.buyUltimate(vWarehouseShipment, util.VN_CURDATE()); + + INSERT INTO itemRange + SELECT t.itemFk, tr.landed + FROM tmp.buyUltimate t + JOIN vn.buy b ON b.id = t.buyFk + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + LEFT JOIN itemRange i ON t.itemFk = i.itemFk + WHERE t.warehouseFk = vWarehouseShipment + AND NOT e.isRaid + ON DUPLICATE KEY UPDATE itemRange.dated = GREATEST(itemRange.dated, tr.landed); + + DROP TEMPORARY TABLE IF EXISTS itemRangeLive; + CREATE TEMPORARY TABLE itemRangeLive + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT ir.itemFk, TIMESTAMP(TIMESTAMPADD(DAY, it.life, ir.dated), '23:59:59') dated + FROM itemRange ir + JOIN vn.item i ON i.id = ir.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + HAVING dated >= vDatedFrom OR dated IS NULL; + + -- Calcula el ATP + DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc; + CREATE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk,warehouseFk)) + ENGINE = MEMORY + SELECT i.item_id itemFk, vWarehouseLanding warehouseFk, i.dat dated, i.amount quantity + FROM item_out i + JOIN itemRangeLive ir ON ir.itemFK = i.item_id + WHERE i.dat >= vDatedFrom + AND (ir.dated IS NULL OR i.dat <= ir.dated) + AND i.warehouse_id = vWarehouseLanding + UNION ALL + SELECT b.itemFk, vWarehouseLanding, t.landed, b.quantity + FROM vn.buy b + JOIN vn.entry e ON b.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN itemRangeLive ir ON ir.itemFk = b.itemFk + WHERE NOT e.isExcludedFromAvailable + AND b.quantity <> 0 + AND NOT e.isRaid + AND t.warehouseInFk = vWarehouseLanding + AND t.landed >= vDatedFrom + AND (ir.dated IS NULL OR t.landed <= ir.dated) + UNION ALL + SELECT i.item_id, vWarehouseLanding, i.dat, i.amount + FROM item_entry_out i + JOIN itemRangeLive ir ON ir.itemFk = i.item_id + WHERE i.dat >= vDatedFrom + AND (ir.dated IS NULL OR i.dat <= ir.dated) + AND i.warehouse_id = vWarehouseLanding + UNION ALL + SELECT r.item_id, vWarehouseLanding, r.shipment, -r.amount + FROM hedera.order_row r + JOIN hedera.`order` o ON o.id = r.order_id + JOIN itemRangeLive ir ON ir.itemFk = r.item_id + WHERE r.shipment >= vDatedFrom + AND (ir.dated IS NULL OR r.shipment <= ir.dated) + AND r.warehouse_id = vWarehouseLanding + AND r.created >= vDatedReserve + AND NOT o.confirmed; + + CALL vn.item_getAtp(vDated); + + DROP TEMPORARY TABLE IF EXISTS availableTraslate; + CREATE TEMPORARY TABLE availableTraslate + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT t.item_id, SUM(stock) available + FROM ( + SELECT ti.itemFk item_id, stock + FROM tmp.itemList ti + JOIN itemRange ir ON ir.itemFk = ti.itemFk + UNION ALL + SELECT itemFk, quantity + FROM tmp.itemAtp + ) t + GROUP BY t.item_id + HAVING available <> 0; + + DROP TEMPORARY TABLE tmp.itemList, itemRange, itemRangeLive; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `balance_create` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `balance_create`( + IN vStartingMonth INT, + IN vEndingMonth INT, + IN vCompany INT, + IN vIsConsolidated BOOLEAN, + IN vInterGroupSalesIncluded BOOLEAN) +BEGIN + DECLARE intGAP INT DEFAULT 7; + DECLARE vYears INT DEFAULT 2; + DECLARE vYear TEXT; + DECLARE vOneYearAgo TEXT; + DECLARE vTwoYearsAgo TEXT; + DECLARE vQuery TEXT; + DECLARE vConsolidatedGroup INT; + DECLARE vStartingDate DATE DEFAULT '2020-01-01'; + DECLARE vCurYear INT DEFAULT YEAR(util.VN_CURDATE()); + DECLARE vStartingYear INT DEFAULT vCurYear - 2; + DECLARE vTable TEXT; + + SET vTable = util.quoteIdentifier('balance_nest_tree'); + SET vYear = util.quoteIdentifier(vCurYear); + SET vOneYearAgo = util.quoteIdentifier(vCurYear-1); + SET vTwoYearsAgo = util.quoteIdentifier(vCurYear-2); + + -- Solicitamos la tabla tmp.nest, como base para el balance + DROP TEMPORARY TABLE IF EXISTS tmp.nest; + + EXECUTE IMMEDIATE CONCAT( + 'CREATE TEMPORARY TABLE tmp.nest + SELECT node.id + ,CONCAT( REPEAT(REPEAT(" ",?), COUNT(parent.id) - 1), node.name) AS name + ,node.lft + ,node.rgt + ,COUNT(parent.id) - 1 as depth + ,cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons + FROM ', vTable, ' AS node, + ', vTable, ' AS parent + WHERE node.lft BETWEEN parent.lft AND parent.rgt + GROUP BY node.id + ORDER BY node.lft') + USING intGAP; + + DROP TEMPORARY TABLE IF EXISTS tmp.balance; + CREATE TEMPORARY TABLE tmp.balance + SELECT * FROM tmp.nest; + + DROP TEMPORARY TABLE IF EXISTS tmp.empresas_receptoras; + DROP TEMPORARY TABLE IF EXISTS tmp.empresas_emisoras; + + SELECT empresa_grupo INTO vConsolidatedGroup + FROM empresa + WHERE id = vCompany; + + CREATE TEMPORARY TABLE tmp.empresas_receptoras + SELECT id as empresa_id + FROM vn2008.empresa + WHERE id = vCompany + OR empresa_grupo = IF(vIsConsolidated, vConsolidatedGroup, NULL); + + CREATE TEMPORARY TABLE tmp.empresas_emisoras + SELECT Id_Proveedor as empresa_id FROM vn2008.Proveedores p; + + IF vInterGroupSalesIncluded = FALSE THEN + + DELETE ee.* + FROM tmp.empresas_emisoras ee + JOIN vn2008.empresa e on e.id = ee.empresa_id + WHERE e.empresa_grupo = vConsolidatedGroup; + + END IF; + + -- Se calculan las facturas que intervienen, para luego poder servir el desglose desde aqui + DROP TEMPORARY TABLE IF EXISTS tmp.balance_desglose; + CREATE TEMPORARY TABLE tmp.balance_desglose + SELECT er.empresa_id receptora_id, + ee.empresa_id emisora_id, + year(IFNULL(r.bookEntried,IFNULL(r.dateBooking, r.Fecha))) `year`, + month(IFNULL(r.bookEntried,IFNULL(r.dateBooking, r.Fecha))) `month`, + gastos_id Id_Gasto, + SUM(bi) importe + FROM recibida r + JOIN recibida_iva ri on ri.recibida_id = r.id + JOIN tmp.empresas_receptoras er on er.empresa_id = r.empresa_id + JOIN tmp.empresas_emisoras ee ON ee.empresa_id = r.proveedor_id + WHERE IFNULL(r.bookEntried,IFNULL(r.dateBooking, r.Fecha)) >= vStartingDate + AND r.contabilizada + GROUP BY Id_Gasto, year, month, emisora_id, receptora_id; + + INSERT INTO tmp.balance_desglose( + receptora_id, + emisora_id, + year, + month, + Id_Gasto, + importe) + SELECT gr.empresa_id, + gr.empresa_id, + year, + month, + Id_Gasto, + SUM(importe) + FROM gastos_resumen gr + JOIN tmp.empresas_receptoras er on gr.empresa_id = er.empresa_id + WHERE year >= vStartingYear + AND month BETWEEN vStartingMonth AND vEndingMonth + GROUP BY Id_Gasto, year, month, gr.empresa_id; + + DELETE FROM tmp.balance_desglose + WHERE month < vStartingMonth + OR month > vEndingMonth; + + -- Ahora el balance + EXECUTE IMMEDIATE CONCAT( + 'ALTER TABLE tmp.balance + ADD COLUMN ', vTwoYearsAgo ,' INT(10) NULL , + ADD COLUMN ', vOneYearAgo ,' INT(10) NULL , + ADD COLUMN ', vYear,' INT(10) NULL , + ADD COLUMN Id_Gasto VARCHAR(10) NULL, + ADD COLUMN Gasto VARCHAR(45) NULL'); + + -- Añadimos los gastos, para facilitar el formulario + UPDATE tmp.balance b + JOIN vn2008.balance_nest_tree bnt on bnt.id = b.id + JOIN (SELECT Id_Gasto, Gasto + FROM vn2008.Gastos + GROUP BY Id_Gasto) g ON g.Id_Gasto = bnt.Id_Gasto COLLATE utf8_general_ci + SET b.Id_Gasto = g.Id_Gasto COLLATE utf8_general_ci + , b.Gasto = g.Gasto COLLATE utf8_general_ci ; + + -- Rellenamos los valores de primer nivel, los que corresponden a los gastos simples + WHILE vYears >= 0 DO + SET vQuery = CONCAT( + 'UPDATE tmp.balance b + JOIN + (SELECT Id_Gasto, SUM(Importe) as Importe + FROM tmp.balance_desglose + WHERE year = ? + GROUP BY Id_Gasto + ) sub on sub.Id_Gasto = b.Id_Gasto COLLATE utf8_general_ci + SET ', util.quoteIdentifier(vCurYear - vYears), ' = - Importe'); + + EXECUTE IMMEDIATE vQuery + USING vCurYear - vYears; + + SET vYears = vYears - 1; + END WHILE; + + -- Añadimos las ventas + EXECUTE IMMEDIATE CONCAT( + 'UPDATE tmp.balance b + JOIN ( + SELECT SUM(IF(year = ?, venta, 0)) y2, + SUM(IF(year = ?, venta, 0)) y1, + SUM(IF(year = ?, venta, 0)) y0, + c.Gasto + FROM bs.ventas_contables c + JOIN tmp.empresas_receptoras er on er.empresa_id = c.empresa_id + WHERE month BETWEEN ? AND ? + GROUP BY c.Gasto + ) sub ON sub.Gasto = b.Id_Gasto COLLATE utf8_general_ci + SET b.', vTwoYearsAgo, '= IFNULL(b.', vTwoYearsAgo, ', 0) + sub.y2, + b.', vOneYearAgo, '= IFNULL(b.', vOneYearAgo, ', 0) + sub.y1, + b.', vYear, '= IFNULL(b.', vYear, ', 0) + sub.y0') + USING vCurYear-2, + vCurYear-1, + vCurYear, + vStartingMonth, + vEndingMonth; + + -- Ventas intra grupo + IF NOT vInterGroupSalesIncluded THEN + + SELECT lft, rgt INTO @grupoLft, @grupoRgt + FROM tmp.balance b + WHERE TRIM(b.`name`) = 'Grupo'; + + DELETE + FROM tmp.balance + WHERE lft BETWEEN @grupoLft AND @grupoRgt; + + END IF; + + -- Rellenamos el valor de los padres con la suma de los hijos + DROP TEMPORARY TABLE IF EXISTS tmp.balance_aux; + CREATE TEMPORARY TABLE tmp.balance_aux + SELECT * FROM tmp.balance; + + EXECUTE IMMEDIATE + CONCAT('UPDATE tmp.balance b + JOIN ( + SELECT b1.id, + b1.name, + SUM(b2.', vYear,') thisYear, + SUM(b2.', vOneYearAgo,') oneYearAgo, + SUM(b2.', vTwoYearsAgo,') twoYearsAgo + FROM tmp.nest b1 + JOIN tmp.balance_aux b2 on b2.lft BETWEEN b1.lft and b1.rgt + GROUP BY b1.id)sub ON sub.id = b.id + SET b.', vYear, ' = thisYear, + b.', vOneYearAgo, ' = oneYearAgo, + b.', vTwoYearsAgo, ' = twoYearsAgo'); + + SELECT *, CONCAT('',ifnull(Id_Gasto,'')) newgasto + FROM tmp.balance; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `base_ticket` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `base_ticket`(IN Id_Ticket INT) +BEGIN + SELECT + red(SUM(Cantidad * Preu * (100 - Descuento) / 100)) AS base + FROm + Movimientos m + INNER JOIN Tickets t USING (Id_Ticket) + WHERE t.Id_Ticket = Id_Ticket; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `bionic_available_types_filter` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `bionic_available_types_filter`( + v_date DATE, + v_consigna INT, + v_agencia INT) +BEGIN +/** + * Este procedimiento devuelve una tabla t_bionic_available_types + * que debe de ser borrar por quien la llame, y se conecta con la tabla articlelist + * que tambien hay que eliminar. + * + * @param vDatefecha de recepcion de mercancia + * @table t_bionic_available_types + */ + + CALL vn.catalog_Calculate(v_date, v_consigna, v_agencia); + + -- Introducimos los valores en una tabla temporal + DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types; + + CALL check_table_existence('articlelist'); + + IF @table_exists THEN + call util.throw('No usar articlelist'); + END IF; + + CREATE TEMPORARY TABLE t_bionic_available_types + SELECT a.tipo_id, t.Tipo, r.reino, count(*) as item_count + FROM tmp.ticketCalculateItem tci + JOIN vn2008.Articles a ON tci.itemFk = a.Id_Article + JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id + JOIN vn2008.reinos r ON r.id = t.reino_id + WHERE tci.available > 0 + GROUP BY a.tipo_id; + + DROP TEMPORARY TABLE tmp.ticketCalculateItem; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_label` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_label`(IN entry_id_ INT, IN groupby TINYINT(1)) +BEGIN + + DECLARE done INT DEFAULT 0; + DECLARE label INT; + DECLARE id INT; + DECLARE recordset CURSOR FOR SELECT Compres.Etiquetas, Compres.Id_Compra FROM Compres INNER JOIN + (SELECT e.Id_entrada FROM Entradas e INNER JOIN ( + SELECT Id_Entrada,Inventario,Id_proveedor,travel_id,Id_Agencia FROM Entradas e1 INNER JOIN travel t ON e1.travel_id = t.id WHERE Id_Entrada = entry_id_) y + ON y.Inventario = e.Inventario AND e.travel_id = y.travel_id AND e.Id_proveedor = y.Id_proveedor AND y.Id_Agencia = e.Id_Agencia + WHERE (0 OR e.Id_Entrada = entry_id_)) entry_label + ON Compres.Id_Entrada = entry_label.Id_entrada + INNER JOIN Articles ON Compres.Id_Article = Articles.Id_Article WHERE Articles.Imprimir <> FALSE; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + DROP TEMPORARY TABLE IF EXISTS `buy_label_source`; + + CREATE TEMPORARY TABLE `buy_label_source` + ( + `buy_id` INT(11) NOT NULL + ) + + ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + OPEN recordset; + + REPEAT + + FETCH recordset INTO label, id; + WHILE label > 0 DO + + SET label = label - 1; + INSERT INTO buy_label_source (buy_id) VALUES (id); + + END WHILE; + + UNTIL done END REPEAT; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_split` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_split`(IN `v_buy` INT, IN `v_entry` INT) +BEGIN + + -- DEPRECATED use vn.buySplit + + DECLARE v_item INT; + DECLARE v_packing INT; + DECLARE v_remaining INT; + DECLARE v_labels INT; + DECLARE v_remainder INT; + DECLARE v_is_buy INT; + DECLARE v_id INT; + DECLARE v_amount INT; + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vNameCharMax INT DEFAULT 16; + + DECLARE cur CURSOR FOR + SELECT TRUE, c.Id_Compra, c.Cantidad - IFNULL((c.Vida * c.Packing), 0) + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE c.Id_Article = v_item + AND DATE(t.shipment) = util.VN_CURDATE() AND t.warehouse_id_out IN (7, 40) + AND t.warehouse_id NOT IN (60) + AND NOT e.redada AND NOT e.Inventario + AND IFNULL(c.Vida, 0) < c.Etiquetas + UNION ALL + SELECT FALSE, m.Id_Movimiento, m.Cantidad - IFNULL(l.stem, 0) + FROM Movimientos m + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + LEFT JOIN movement_label l ON l.Id_Movimiento = m.Id_Movimiento + WHERE m.Id_Article = v_item + AND t.Fecha >= util.VN_CURDATE() AND t.warehouse_id IN (7, 40) + AND NOT t.Etiquetasemitidas + AND IFNULL(l.stem, 0) < m.Cantidad + LOCK IN SHARE MODE; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + -- Obtiene los datos de la compra + + SELECT Id_Article, Packing, Cantidad + INTO v_item, v_packing, v_remaining + FROM Compres WHERE Id_Compra = v_buy; + + -- Crea splits de los tickets + + DROP TEMPORARY TABLE IF EXISTS tmp.split; + CREATE TEMPORARY TABLE tmp.split + ( + is_buy BOOL, + id INT, + labels INT, + remainder INT + ) + ENGINE = MEMORY; + + OPEN cur; + + l: LOOP + SET v_done = FALSE; + FETCH cur INTO v_is_buy, v_id, v_amount; + + IF v_done OR v_remaining = 0 THEN + LEAVE l; + END IF; + + SET v_amount = LEAST(v_amount, v_remaining); + SET v_remaining = v_remaining - v_amount; + SET v_labels = v_amount DIV v_packing; + + INSERT INTO tmp.split + VALUES (v_is_buy, v_id, v_labels, v_amount % v_packing); + + IF v_is_buy + THEN + UPDATE Compres + SET Vida = Vida + v_labels + WHERE Id_Compra = v_id; + ELSE + INSERT INTO movement_label + SET + Id_Movimiento = v_id, + stem = v_amount, + label = v_labels + ON DUPLICATE KEY UPDATE + stem = stem + VALUES(stem), + label = label + VALUES(label); + END IF; + END LOOP; + + CLOSE cur; + + -- Crea los movimientos de almacén a silla + + CALL buy_transfer (v_buy, v_entry); + + UPDATE Compres SET dispatched = Vida * Packing + WHERE Id_Compra = v_buy; + + -- Devuelve los splits creados + + DROP TEMPORARY TABLE IF EXISTS tmp.aux; + CREATE TEMPORARY TABLE tmp.aux + ENGINE = MEMORY + SELECT s.labels, s.remainder, w.`name` destination, + a.Id_Article, a.Article, a.Medida, ' ' counter, ' ' destination2 + FROM tmp.split s + JOIN Compres c ON c.Id_Compra = s.id + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + JOIN warehouse w ON t.warehouse_id = w.id + WHERE s.is_buy; + + INSERT INTO tmp.aux + SELECT s.labels, s.remainder, IF(p.`name` IN ('BARCELONA','TARRAGONA','GIRONA','LLEIDA','LÉRIDA') AND t.Id_Cliente != 93, '<< VILASSAR >>',o.Consignatario), + a.Id_Article, a.Article, a.Medida, + vn.ticketSplitCounter(t.Id_Ticket), IF(p.`name` IN ('BARCELONA','TARRAGONA','GIRONA','LLEIDA','LÉRIDA') AND t.Id_Cliente != 93, o.Consignatario,CONCAT(o.id_consigna, ' ', p.`name`,' (', c.`code`,')')) + /*UCASE(CONCAT(p.`name`,' (', c.`code`, ')'))*/ + FROM tmp.split s + JOIN Movimientos m ON m.Id_Movimiento = s.id + JOIN Articles a ON a.Id_Article = m.Id_Article + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN Consignatarios o ON o.Id_Consigna = t.Id_Consigna + JOIN vn.province p ON p.id = o.province_id + JOIN vn.country c ON c.id = p.countryFk + WHERE NOT s.is_buy; + + SELECT * FROM tmp.aux; + + -- Limpia y confirma cambios + + DROP TEMPORARY TABLE + tmp.split, + tmp.aux; + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas`(vBuyFk INT) +BEGIN + CALL vn.buy_recalcPricesByBuy(vBuyFk); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_entry` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_entry`(IN vEntryFk INT(11)) +BEGIN +/** + * Recalcula los precios de una entrada + * + * @param vEntryFk + */ + CALL vn.buy_recalcPricesByEntry(vEntryFk); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_recalcular_almacen` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_recalcular_almacen`(IN wh_id INT, IN datFEC DATE) +BEGIN + +DECLARE done INT DEFAULT 0; +DECLARE idE INT; + +DECLARE cur1 CURSOR FOR +SELECT Id_Entrada +FROM Entradas +JOIN travel ON travel.id = travel_id +WHERE landing >= datFEC AND wh_id IN (0,warehouse_id); + +DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; + +OPEN cur1; + +REPEAT + + FETCH cur1 INTO idE; + + IF NOT done THEN + + Call buy_tarifas_entry(idE); + + + + END IF; + + +UNTIL done END REPEAT; + + CLOSE cur1; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_transfer` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_transfer`(IN `v_buy` INT, IN `entryFk` INT) +proc: BEGIN +/** + * Traslada la cantidad restante de una compra de Holanda + * al almacén de Silla. + */ + DECLARE v_wh INT; + DECLARE v_fv INT; + DECLARE v_amount INT; + DECLARE v_item INT; + DECLARE v_holland_wh INT DEFAULT 7; + DECLARE vIsIgnored BOOL DEFAULT FALSE; + DECLARE vDestinationWarehouse INT; + + -- Comprueba que es mercancía que llega al almacén de Holanda + + SELECT t.warehouse_id, IF(tp.warehouseFk=1,1,0), tp.warehouseFk, c.Id_Article, c.Novincular + INTO v_wh, v_fv, vDestinationWarehouse, v_item, vIsIgnored + FROM Compres c + JOIN Entradas e ON c.Id_Entrada = e.Id_Entrada + JOIN travel t ON t.id = e.travel_id + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + WHERE c.Id_Compra = v_buy; + + IF v_wh != v_holland_wh THEN + LEAVE proc; + END IF; + + IF entryFk IS NULL THEN + LEAVE proc; + END IF; + + -- Calcula la cantidad a trasladar + + SELECT IFNULL(SUM(amount), 0) INTO v_amount + FROM ( + SELECT SUM(c.Cantidad) amount + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE c.Id_Article = v_item + AND t.landing = util.VN_CURDATE() + AND t.warehouse_id = v_holland_wh + UNION ALL + SELECT -SUM(c.Cantidad) + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE c.Id_Article = v_item + AND t.shipment = util.VN_CURDATE() + AND t.warehouse_id_out = v_holland_wh + UNION ALL + SELECT -SUM(Cantidad) + FROM Movimientos m + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE m.Id_Article = v_item + AND t.Fecha = util.VN_CURDATE() + AND t.warehouse_id = v_holland_wh + ) t; + + IF v_amount <= 0 THEN + LEAVE proc; + END IF; + + -- Si la linea tiene no vincular hay que buscar la anterior válida + IF vIsIgnored THEN + CALL buyUltimate(vDestinationWarehouse, util.VN_CURDATE()); + SELECT buyFk INTO v_buy + FROM tmp.buyUltimate + LIMIT 1; + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; + END IF; + + -- Crea la nueva línea de compra con el translado + + INSERT INTO Compres ( + Id_Article, Etiquetas, Cantidad, Id_Entrada, + Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, + Embalajefijo, Comisionfija, buy_edi_id) + SELECT c.Id_Article, + v_amount DIV c.Packing, + v_amount, + entryFk, + c.Id_Cubo, + c.Packing, + c.`grouping`, + c.caja, + @cost := IFNULL(c.Costefijo, 0) + IFNULL(c.Comisionfija, 0) + IFNULL(c.Portefijo, 0), + @porte := ROUND((@cm3:= vn.item_getVolume(c.Id_Article, c.Id_Cubo)) * a.m3 / 1000000 / c.Packing, 3), + c.EmbalajeFijo, + @comision := ROUND(c.Costefijo * e.comision / 100, 3), + c.buy_edi_id + FROM Compres c + JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo + JOIN Entradas e ON e.Id_Entrada = entryFk + JOIN travel t ON t.id = e.travel_id + JOIN Agencias a ON t.agency_id = a.Id_Agencia + WHERE c.Id_Compra = v_buy; + + CALL buy_tarifas (LAST_INSERT_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `cacheReset` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `cacheReset`(vCacheName VARCHAR(10), vParams VARCHAR(15)) +BEGIN + + UPDATE cache.cache_calc + SET expires = util.VN_NOW() + WHERE cacheName = vCacheName collate utf8_unicode_ci + AND params = vParams collate utf8_unicode_ci; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `Cajas_Saldo_Detalle` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `Cajas_Saldo_Detalle`() +BEGIN + + Select Proveedores.Id_Proveedor, Proveedor, Fecha, round(Importe) as Importe + from Proveedores + join + ( + select Fecha, sub.Id_Proveedor, sum(Importe) as Importe + from + + ( + + select round(sum(Importe),2) as Importe, TIMESTAMPADD(DAY,-1,util.VN_CURDATE()) as Fecha, Id_Proveedor + from pago + join Proveedores using(Id_Proveedor) + where Fecha >= '2011-01-01' + and Id_Proveedor NOT IN (select id from empresa) + group by Id_Proveedor + + union all + + select IFNULL(-1 * round(sum(rv.Cantidad / if(Id_Moneda = 2,rate,1)),2),0) AS Vto, TIMESTAMPADD(DAY,-1,util.VN_CURDATE()), proveedor_id + from recibida_vencimiento rv + join recibida r on r.id = rv.recibida_id + join reference_rate rr on rr.`date` = rv.fecha + join Proveedores P on P.Id_Proveedor = r.proveedor_id + join Paises PS on PS.Id = P.pais_id + where rv.fecha between '2011-01-01' and util.VN_CURDATE()-1 + and Id_Proveedor NOT IN (select id from empresa) + group by proveedor_id + + union all + + select -1 * round(rv.Cantidad / if(Id_Moneda = 2,(SELECT value FROM vn.referenceRate ORDER BY dated DESC LIMIT 1),1),2) AS Vto, rv.fecha, proveedor_id + from recibida_vencimiento rv + join recibida r on r.id = rv.recibida_id + join Proveedores P on P.Id_Proveedor = r.proveedor_id + join Paises PS on PS.Id = P.pais_id + where rv.fecha >= util.VN_CURDATE() + and Id_Proveedor NOT IN (select id from empresa) + + union all + + select @remesas:= @pago:= @saldo:= 0.0000, util.VN_CURDATE(), @prov:= 0) sub + group by Fecha,Id_Proveedor + ) sub2 using(Id_Proveedor) + having Importe < -100 + ; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `CalculoRemesas` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `CalculoRemesas`(IN vFechaRemesa DATE) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS; + CREATE TEMPORARY TABLE TMP_REMESAS + SELECT + CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1, + cli.Id_Cliente, + cli.Cliente, + cli.`IF` as NIF, + c.PaymentDate as Vencimiento, + 0 ImporteFac, + cast(c.Recibo as decimal(10,2)) as ImporteRec, + 0 as ImporteActual, + c.companyFk empresa_id, + cli.RazonSocial, + cast(c.Recibo as decimal(10,2)) as ImporteTotal, + cast(c.Recibo as decimal(10,2)) as Saldo, + p.Proveedor as Empresa, + e.abbreviation as EMP, + cli.cuenta, + iban AS Iban, + CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe, + sepavnl as SEPA, + corevnl as RecibidoCORE, + hasLcr, + be.bic, + be.`name` entityName + FROM Clientes cli + JOIN + (SELECT risk.companyFk, + c.Id_Cliente, + sum(risk.amount) as Recibo, + IF((c.Vencimiento + graceDays) mod 30.001 <= day(vFechaRemesa) + ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-1,vFechaRemesa))) + ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-2,vFechaRemesa))) + ) as PaymentDate + FROM Clientes c + JOIN pay_met pm on pm.id = pay_met_id + JOIN + ( + SELECT companyFk, clientFk, amount + FROM Clientes c + JOIN vn.clientRisk cr ON cr.clientFk = c.Id_Cliente + WHERE pay_met_id = 4 + + UNION ALL + + SELECT empresa_id, Id_Cliente, - Importe + FROM Facturas f + JOIN Clientes c using(Id_Cliente) + JOIN pay_met pm on pm.id = pay_met_id + WHERE f.Vencimiento > vFechaRemesa + AND pay_met_id = 4 AND pm.deudaviva + AND Importe > 0 + + ) risk ON c.Id_Cliente = risk.clientFk + GROUP BY risk.companyFk, Id_Cliente + HAVING Recibo > 10 + ) c on c.Id_Cliente = cli.Id_Cliente + JOIN Proveedores p on p.Id_Proveedor = c.companyFk + JOIN empresa e on e.id = c.companyFk + LEFT JOIN vn.bankEntity be ON be.id = cli.bankEntityFk; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `camiones` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `camiones`(vWarehouse INT, vDate DATE) +BEGIN + SELECT Temperatura + ,ROUND(SUM(Etiquetas * volume)) AS cm3 + ,ROUND(SUM(IF(scanned, Etiquetas, 0) * volume)) AS cm3s + ,ROUND(SUM(Vida * volume)) AS cm3e + FROM ( + SELECT t.Temperatura, c.Etiquetas, b.scanned, c.Vida, + IF(cu.Volumen > 0, cu.Volumen, cu.x * cu.y * IF(cu.z > 0, cu.z, a.Medida + 10)) volume + FROM Compres c + LEFT JOIN buy_edi b ON b.id = c.buy_edi_id + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos t ON t.tipo_id = a.tipo_id + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel tr ON tr.id = e.travel_id + JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo + WHERE tr.warehouse_id = vWarehouse + AND tr.landing = vDate + ) sub + GROUP BY Temperatura; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `check_table_existence` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `check_table_existence`(IN table_name CHAR(64)) +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' SET @err = 1; + SET @err = 0; + SET @table_name = table_name; + SET @sqlString = CONCAT('SELECT NULL FROM ',@table_name); + PREPARE stmt1 FROM @sqlString; + IF (@err = 1) THEN + SET @table_exists = 0; + ELSE + SET @table_exists = 1; + DEALLOCATE PREPARE stmt1; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`(IN `v_full` TINYINT(1)) +proc: BEGIN + DECLARE vDate DATETIME; + DECLARE vDate18 DATETIME; + DECLARE vDate26 DATETIME; + DECLARE vDate8 DATE; + DECLARE vDate6 DATE; + DECLARE vDate3 DATE; + DECLARE vDate2000 DATE; + DECLARE vRangeDeleteTicket INT; + DECLARE vStrtable VARCHAR(15) DEFAULT NULL; + + SET vDate = util.VN_CURDATE() - INTERVAL 2 MONTH; + SET vDate18 = util.VN_CURDATE() - INTERVAL 18 MONTH; + SET vDate26 = util.VN_CURDATE() - INTERVAL 26 MONTH; + SET vDate3 = util.VN_CURDATE() - INTERVAL 3 MONTH; + SET vDate8 = util.VN_CURDATE() - INTERVAL 8 DAY; + SET vDate6 = util.VN_CURDATE() - INTERVAL 6 DAY; + SET vDate2000 = util.VN_CURDATE() + INTERVAL (2000 - YEAR(util.VN_CURDATE())) YEAR; + SET vRangeDeleteTicket = 60; + + DELETE FROM Rutas_monitor WHERE fecha < vDate; + DELETE FROM cdr WHERE calldate < vDate18; + DELETE FROM Monitoring WHERE ODBC_TIME < vDate; + DELETE FROM Conteo WHERE Fecha < vDate; + DELETE FROM XDiario WHERE FECHA < vDate3 OR FECHA IS NULL; + DELETE FROM mail WHERE DATE_ODBC < vDate; + DELETE FROM expeditions_deleted WHERE odbc_date < vDate26; + DELETE FROM sms WHERE DATE_ODBC < vDate18; + DELETE FROM Movimientos_mark WHERE odbc_date < vDate; + DELETE FROM Splits WHERE Fecha < vDate18; + + DELETE ts + FROM Tickets_stack ts + JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket + WHERE t.Fecha < vDate; + + DELETE tobs + FROM ticket_observation tobs + JOIN Tickets t ON tobs.Id_Ticket = t.Id_Ticket + WHERE t.Fecha < vDate; + + DELETE tobs + FROM movement_label tobs + JOIN Movimientos m ON tobs.Id_Movimiento = m.Id_Movimiento + JOIN Tickets t ON m.Id_Ticket = t.Id_Ticket WHERE t.Fecha < vDate; + + DELETE FROM Remesas WHERE `Fecha Remesa` < vDate18; + DELETE FROM sharingcart where datEND < vDate; + DELETE FROM sharingclient where datEND < vDate; + + DELETE tt.* + FROM Tickets_turno tt + LEFT JOIN Movimientos m USING(Id_Ticket) + WHERE m.Id_Article IS NULL; + + DELETE FROM cl_main WHERE Fecha < vDate18; + DELETE FROM hedera.`order` WHERE date_send < vDate18; + DELETE FROM vn.message WHERE sendDate < vDate; + DELETE FROM travel_reserve WHERE odbc_date < vDate; + + DELETE FROM cache.departure_limit WHERE Fecha < util.VN_CURDATE() - INTERVAL 1 MONTH; + + DELETE cm + FROM Compres_mark cm + JOIN Compres c ON c.Id_Compra = cm.Id_Compra + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE t.landing <= vDate; + + DELETE co + FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE t.landing <= vDate; + DELETE FROM scan WHERE odbc_date < vDate6 AND id <> 1; + + IF v_full THEN + CREATE OR REPLACE TEMPORARY TABLE tTicketDelete + SELECT DISTINCT tl.originFk ticketFk + FROM vn.ticketLog tl + JOIN (SELECT MAX(tl.id)ids + FROM vn.ticket t + JOIN vn.ticketLog tl ON tl.originFk = t.id + WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' + AND t.isDeleted + GROUP BY t.id + )sub ON sub.ids = tl.id + WHERE tl.creationDate <= util.VN_CURDATE() - INTERVAL 60 DAY; + + DELETE t + FROM vn.ticket t + JOIN tTicketDelete tmp ON tmp.ticketFk = t.id; + + DROP TEMPORARY TABLE tTicketDelete; + END IF; + + -- Tickets Nulos PAK 11/10/2016 + UPDATE Tickets + SET empresa_id = 965 + WHERE Id_Cliente = 31 + AND empresa_id != 965; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `clean_launcher` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `clean_launcher`() +BEGIN + CALL clean(TRUE); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `cobro` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `cobro`(IN datFEC DATE + , IN idCLI INT + , IN dblIMPORTE DOUBLE + , IN idCAJA INT + , IN idPAYMET INT + , IN strCONCEPTO VARCHAR(40) + , IN idEMP INT + , IN idWH INT + , IN idTRABAJADOR INT) +BEGIN + + DECLARE bolCASH BOOLEAN; + DECLARE cuenta_banco BIGINT; + DECLARE cuenta_cliente BIGINT; + DECLARE max_asien INT; + -- XDIARIO + -- No se asientan los cobros directamente, salvo en el caso de las cajas de CASH + SELECT (at2.code = 'cash') INTO bolCASH FROM Bancos b JOIN vn.accountingType at2 ON at2.id = b.cash WHERE b.Id_Banco = idCAJA; + IF bolCASH THEN + SELECT Cuenta INTO cuenta_banco + FROM Bancos + WHERE Id_Banco = idCAJA; + SELECT Cuenta INTO cuenta_cliente + FROM Clientes + WHERE Id_Cliente = idCLI; + CALL vn.ledger_next(max_asien); + INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id) + SELECT max_asien,datFEC,SUBCTA,CONTRA,strCONCEPTO,EURODEBE,EUROHABER,idEMP + FROM(SELECT cuenta_banco SUBCTA, cuenta_cliente CONTRA, 0 EURODEBE, dblIMPORTE EUROHABER + UNION ALL + SELECT cuenta_cliente SUBCTA, cuenta_banco CONTRA, dblIMPORTE EURODEBE, 0 EUROHABER + ) gf; + END IF; + + -- CAJERA + INSERT INTO Cajas(Id_Trabajador, + Id_Banco, + Entrada, + Concepto, + Cajafecha, + Serie, + Partida, + Numero, + empresa_id, + warehouse_id + ) + VALUES (idTRABAJADOR, + idCAJA, + dblIMPORTE, + strCONCEPTO, + datFEC, + 'A', + TRUE, + idCLI, + idEMP, + idWH + ); + + -- RECIBO + INSERT INTO Recibos(Entregado, + Fechacobro, + Id_Trabajador, + Id_Banco, + Id_Cliente, + Id_Factura, + empresa_id + ) + VALUES ( dblIMPORTE, + datFEC, + idTRABAJADOR, + idCAJA, + idCLI, + strCONCEPTO, + idEMP + ); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `comercial_caducado` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `comercial_caducado`() +BEGIN + +-- Este procedimiento le pasa los clientes al jefe de ventas cuando llevan dos meses inactivos + +IF day(util.VN_CURDATE()) = 5 then -- solo se ejecuta los dias 5 de cada mes + + Update Clientes + join + ( + Select c.Id_Cliente + from Clientes c + join jerarquia j on j.worker_id = c.Id_Trabajador -- este filtro es para que solo toque los de los comerciales + + join + ( + select Id_Cliente, sum(Importe) as Saldo + from + ( + select Id_Cliente, Importe from Facturas + union all + select Id_Cliente, - Entregado from Recibos + ) sub + group by Id_Cliente + ) sindeuda on sindeuda.Id_Cliente = c.Id_Cliente + + left join + ( + select distinct Id_Cliente + from Facturas + where Fecha BETWEEN util.VN_CURDATE() - INTERVAL 12 MONTH AND util.VN_CURDATE() + ) f on f.Id_Cliente = c.Id_Cliente + + left join + ( + select distinct Id_Cliente + from Tickets + where Fecha between util.VN_CURDATE() - INTERVAL 2 DAY AND util.VN_CURDATE() + INTERVAL 200 DAY + + ) tic_vivos on tic_vivos.Id_Cliente = c.Id_Cliente + + where c.Created < util.VN_CURDATE() - INTERVAL 2 MONTH -- este filtro respeta a los recien nacidos.... + and j.boss_id = 87 -- sólo afecta a los comerciales de Alfredo + and f.Id_Cliente is null -- comprueba que no tenga facturas en los dos ultimos meses + and sindeuda.Saldo < 10 -- sólo cambia a los clientes con deuda escasa o nula + and tic_vivos.Id_Cliente is null -- si tiene tickets vivos, lo respeta + + + ) sub using(Id_Cliente) + + set Id_Trabajador = 87 ;-- Alfredo Giner; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `CompresTriggerBeforeDelete` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `CompresTriggerBeforeDelete`(oldId INT, oldEntrada INT) +BEGIN + + DECLARE hasToRecalculate BOOLEAN; + DECLARE newWarehouse INT; + + SELECT Id_Compra INTO hasToRecalculate FROM vn.lastBuy lb + WHERE lb.id = oldId LIMIT 1; + + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel t + JOIN Entradas e ON t.id = e.travel_id + WHERE e.Id_Entrada = oldEntrada; + + CALL vn.lastBuyRefresh(newWarehouse); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `compresTriggerBeforeInsert` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `compresTriggerBeforeInsert`(newNoVincular INT, newEntrada INT, newCompra INT, newItem INT) +BEGIN + DECLARE newWarehouse INTEGER; + + IF newNoVincular = FALSE THEN + + UPDATE travel t + JOIN vn.lastBuy lb ON newItem = lb.item AND t.warehouse_id = lb.warehouse + JOIN Entradas e ON e.travel_id = t.id + SET lb.id = newCompra + WHERE e.Id_Entrada = newEntrada AND t.landing > lb.landing AND t.landing <= util.VN_CURDATE(); + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `compresTriggerBeforeUpdate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `compresTriggerBeforeUpdate`(vOldEntrada INT, vNewEntrada INT, oldItem INT, + newItem INT, newNoVincular BOOLEAN, newCompra INT) +BEGIN + DECLARE newWarehouse INTEGER; + DECLARE hasToRecalculate BOOLEAN; + + IF newNoVincular = FALSE THEN + IF oldItem <> newItem OR vOldEntrada <> vNewEntrada THEN + SELECT Id_Compra INTO hasToRecalculate FROM travel t + JOIN Entradas e ON e.travel_id = t.id + JOIN vn.lastBuy lb ON lb.id = newCompra + WHERE e.Id_Entrada = vOldEntrada LIMIT 1; + + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel t + JOIN Entradas e ON t.id = e.travel_id + WHERE e.Id_Entrada = vOldEntrada; + CALL vn.lastBuyRefresh(newWarehouse); + END IF; + END IF; + IF vOldEntrada <> vNewEntrada THEN + + UPDATE Entradas oldEntrada + JOIN travel oldTravel ON oldEntrada.travel_id = oldtravel.id + JOIN Entradas newEntrada ON newEntrada.Id_Entrada = vNewEntrada + JOIN travel newTravel ON newTravel.id = newEntrada.travel_id + JOIN vn.lastBuy lb ON newItem = lb.item AND newTravel.warehouse_id = lb.warehouse + SET lb.id = newCompra + WHERE oldEntrada.Id_Entrada = vOldEntrada AND oldTravel.warehouse_id <> newTravel.warehouse_id + AND newTravel.landing > lb.landing AND newTravel.landing <= util.VN_CURDATE(); + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `confection_control_source` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `confection_control_source`(vDated DATE, vScopeDays TINYINT) +BEGIN + + DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(vDated,'23:59:59'); + DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight); + DECLARE maxAlertLevel INT DEFAULT 2; + + DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer; + + CREATE TEMPORARY TABLE tmp.production_buffer + ENGINE = MEMORY + SELECT + date(t.Fecha) as Fecha, + hour(t.Fecha) as Hora, + hour(t.Fecha) as Departure, + t.Id_Ticket, + m.Id_Movimiento, + m.Cantidad, + m.Concepte, + ABS(m.Reservado) Reservado, + i.Categoria, + tp.Tipo, + t.Alias as Cliente, + wh.name as Almacen, + t.warehouse_id, + cs.province_id, + a.agency_id, + ct.description as Taller, + stock.visible, + stock.available + FROM vn2008.Tickets t + JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia + JOIN vn2008.warehouse wh ON wh.id = t.warehouse_id + JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket + JOIN vn2008.Articles i ON i.Id_Article = m.Id_Article + JOIN vn2008.Tipos tp ON tp.tipo_id = i.tipo_id + JOIN vn.confectionType ct ON ct.id = tp.confeccion + JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna + LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket + LEFT JOIN + ( + SELECT item_id, sum(visible) visible, sum(available) available + FROM + ( + SELECT a.item_id, 0 as visible, a.available + FROM cache.cache_calc cc + LEFT JOIN cache.available a ON a.calc_id = cc.id + WHERE cc.cache_id IN (2,8) + AND cc.params IN (concat("1/", util.VN_CURDATE()),concat("44/", util.VN_CURDATE())) + + UNION ALL + + SELECT v.item_id, v.visible, 0 as available + FROM cache.cache_calc cc + LEFT JOIN cache.visible v ON v.calc_id = cc.id + where cc.cache_id IN (2,8) and cc.params IN ("1","44") + ) sub + GROUP BY item_id + ) stock ON stock.item_id = m.Id_Article + WHERE tp.confeccion + AND tls.alertLevel < maxAlertLevel + AND wh.hasConfectionTeam + AND t.Fecha BETWEEN vDated AND vEndingDate + AND m.Cantidad > 0; + + -- Entradas + + INSERT INTO tmp.production_buffer( + Fecha, + Id_Ticket, + Cantidad, + Concepte, + Categoria, + Cliente, + Almacen, + Taller + ) + SELECT + tr.shipment AS Fecha, + e.Id_Entrada AS Id_Ticket, + c.Cantidad, + a.Article, + a.Categoria, + whi.name as Cliente, + who.name as Almacen, + ct.description as Taller + FROM vn2008.Compres c + JOIN vn2008.Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN vn2008.travel tr ON tr.id = e.travel_id + JOIN vn2008.warehouse whi ON whi.id = tr.warehouse_id + JOIN vn2008.warehouse who ON who.id = tr.warehouse_id_out + JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article + JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id + JOIN vn.confectionType ct ON ct.id = tp.confeccion + WHERE who.hasConfectionTeam + AND tp.confeccion + AND tr.shipment BETWEEN vDated AND vEndingDate; + + + SELECT * FROM tmp.production_buffer; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `createBouquet` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `createBouquet`( + vName VARCHAR(50), + vType int, + vSize int, + vColour VARCHAR(5), + OUT vItem INT(11) +) +BEGIN + + DECLARE vTaxClass VARCHAR(1); + DECLARE vIntrastatFk INT(11); + + -- COMPROBAMOS SI EXISTE UN ARTÍCULO IGUAL. + SELECT Id_Article INTO vItem + FROM Articles + WHERE (Id_Article BETWEEN 161000 AND 169000) + AND Article LIKE CONCAT('%', vName) + AND tipo_id = vType + AND Medida = vSize + AND Color = vColour + LIMIT 1; + + -- SI NO EXISTE CREAMOS UNO NUEVO + IF vItem IS NULL THEN + + -- OBTENER EL ID ENTRE 161000 Y 169000 DEL SIGUIENTE ARTÍCULO + SELECT (IF(MAX(Id_Article) IS NULL, 161000, (MAX(Id_Article) + 1))) INTO vItem FROM Articles WHERE Id_Article BETWEEN 161000 AND 169000; + + -- INSERTAR EL ARTÍCULO + INSERT INTO vn.item (id, `name`, typeFk, size, inkFk, originFk, intrastatFk) + VALUES ( + vItem, + vName, + vType, + vSize, + vColour, + 1, + 06031970 + ); + + SELECT id INTO vTaxClass FROM vn.taxClass WHERE `code` = 'G'; + SELECT id INTO vIntrastatFk FROM vn.intrastat + WHERE description LIKE 'Flores,follaje y frutos artificiales: otras%'; + + UPDATE vn.itemTaxCountry SET taxClassFk = vTaxClass WHERE itemFk = LAST_INSERT_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `credit_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_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `credit_update`() +BEGIN + +DECLARE dblDiferencia DOUBLE DEFAULT 10.0; +DECLARE dblImporteRec,auxdblImporteRec DOUBLE DEFAULT 0.0; +DECLARE dblImporteFac,auxdblImporteFac DOUBLE DEFAULT 0.0; +DECLARE intIdRecibo,auxintIdRecibo INT (11) DEFAULT 0; +DECLARE intId_Cliente,auxintId_Cliente,intId_ClienteRec,auxintId_ClienteRec INT DEFAULT 0; +DECLARE bitFin,bitFinRecord,bitFinRecord1 BIT DEFAULT 0; +DECLARE datFechaVencimiento DATE DEFAULT util.VN_CURDATE(); +DECLARE intEmpresa_id INT DEFAULT 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `customerDebtEvolution` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `customerDebtEvolution`(IN vCustomer INT) +BEGIN + +SELECT * FROM +( + SELECT day, date, @s:= round(IFNULL(Euros,0) + @s,2) as Saldo, Euros, Credito, 0 as Cero + FROM + ( + SELECT day, date, IFNULL(Euros,0) as Euros, Credito + FROM time + JOIN (SELECT @s:= 0, - Credito as Credito FROM Clientes WHERE Id_Cliente = vCustomer) c + LEFT JOIN + (SELECT Euros, date(Fecha) as Fecha FROM + ( + SELECT Fechacobro as Fecha, Entregado as Euros + FROM Recibos + WHERE Id_Cliente = vCustomer + AND Fechacobro >= '2017-01-01' + UNION ALL + SELECT vn.getDueDate(f.Fecha,c.Vencimiento), - Importe + FROM Facturas f + JOIN Clientes c ON f.Id_Cliente = c.Id_Cliente + WHERE f.Id_Cliente = vCustomer + AND Fecha >= '2017-01-01' + UNION ALL + SELECT '2016-12-31', Debt + FROM bi.customerDebtInventory + WHERE Id_Cliente = vCustomer + UNION ALL + SELECT Fecha, - SUM(Cantidad * Preu * (100 - Descuento ) * 1.10 / 100) + FROM Tickets t + JOIN Movimientos m on m.Id_Ticket = t.Id_Ticket + WHERE Id_Cliente = vCustomer + AND Factura IS NULL + AND Fecha >= '2017-01-01' + GROUP BY Fecha + ) sub2 + ORDER BY Fecha + )sub ON time.date = sub.Fecha + WHERE time.date BETWEEN '2016-12-31' AND util.VN_CURDATE() + ORDER BY date + ) sub3 +)sub4 +; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `desglose_volume` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `desglose_volume`(IN vAgencyFk INT) +BEGIN + + DECLARE vStarted DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE()); + DECLARE vEnded DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE(), '23:59:59'); + DECLARE vIsHolland BOOL; + + SELECT (wa.name = 'Holanda') INTO vIsHolland + FROM vn.agency a + JOIN vn.warehouseAlias wa ON wa.id = a.warehouseAliasFk + WHERE a.id = vAgencyFk; + + IF vIsHolland THEN + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_PackagingEstimated; + CREATE TEMPORARY TABLE tmp.ticket_PackagingEstimated + ( + ticketFk INT PRIMARY KEY + ,carros DECIMAL(5,1) DEFAULT 0 + ); + + INSERT INTO tmp.ticket_PackagingEstimated(ticketFk, carros) + SELECT sv.ticketFk, ROUND(vc.dutchCompressionRate * sum(sv.volume) / vc.trolleyM3,0) + FROM vn.ticket t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.volumeConfig vc + WHERE t.shipped BETWEEN vStarted AND vEnded + AND am.agencyFk = vAgencyFk + GROUP BY t.id; + + SELECT a.nickname Provincia, + count(*) expediciones, + 0 Bultos, + sum(tpe.carros) Prevision + FROM vn.ticket t + JOIN vn.address a ON a.id = t.addressFk + JOIN tmp.ticket_PackagingEstimated tpe ON tpe.ticketFk = t.id + GROUP BY a.nickname; + + ELSE + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_PackagingEstimated; + CREATE TEMPORARY TABLE tmp.ticket_PackagingEstimated + ( + ticketFk INT PRIMARY KEY + ,boxes INT DEFAULT 0 + ); + + INSERT INTO tmp.ticket_PackagingEstimated(ticketFk, boxes) + SELECT sv.ticketFk, CEIL(1000 * sum(sv.volume) / vc.standardFlowerBox) + FROM vn.ticket t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.volumeConfig vc + WHERE t.shipped BETWEEN vStarted AND vEnded + AND IFNULL(t.packages,0) = 0 + AND am.agencyFk = vAgencyFk + GROUP BY t.id; + + + SELECT p.name Provincia, + count(*) expediciones, + sum(t.packages) Bultos, + sum(tpe.boxes) Prevision + FROM vn.ticket t + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON a.provinceFk = p.id + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN tmp.ticket_PackagingEstimated tpe ON tpe.ticketFk = t.id + WHERE t.warehouseFk = 60 + AND t.shipped BETWEEN vStarted AND vEnded + AND am.agencyFk = vAgencyFk + GROUP BY p.name; + + END IF; + SELECT * FROM tmp.ticket_PackagingEstimated; + DROP TEMPORARY TABLE tmp.ticket_PackagingEstimated; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `emailYesterdayPurchasesByConsigna` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `emailYesterdayPurchasesByConsigna`(IN v_Date DATE, IN v_Client_Id INT) +BEGIN + + DECLARE MyIdTicket BIGINT; + DECLARE MyAlias VARCHAR(50); + DECLARE MyDomicilio VARCHAR(255); + DECLARE MyPoblacion VARCHAR(25); + DECLARE MyImporte DOUBLE; + DECLARE MyMailTo VARCHAR(250); + DECLARE MyMailReplyTo VARCHAR(250); + DECLARE done INT DEFAULT FALSE; + DECLARE emptyList INT DEFAULT 0; + DECLARE txt TEXT; + + DECLARE rs CURSOR FOR + SELECT t.Id_Ticket, Alias, cast(amount as decimal(10,2)) Importe, Domicilio, POBLACION + FROM Tickets t + JOIN Consignatarios cs ON t.Id_Consigna = cs.Id_Consigna + JOIN v_ticket_amount v ON v.Id_Ticket = t.Id_Ticket + WHERE t.Fecha BETWEEN v_Date AND util.dayEnd(v_Date) + AND t.Id_Cliente = v_Client_Id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + SET v_Date = IFNULL(v_Date, util.yesterday()); + + OPEN rs; + + FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion; + + SET emptyList = done; + + SET txt = CONCAT('

', + '

Relación de envíos.

', + '

Dia: ', v_Date, '

'); + + WHILE NOT done DO + + SET txt = CONCAT(txt, '

', + ' + + + + + + +
+ Ticket ', MyIdTicket,' ', MyImporte, ' €
' + , ' ', MyAlias, '
' + , ' ', MyDomicilio, '(', MyPoblacion, ')'); + + FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion; + + END WHILE; + + SET txt = CONCAT( + txt, + '', + '', + '
', + '

Puede acceder al detalle de los albaranes haciendo click sobre el número de Ticket', + '

Muchas gracias por su confianza

', + '

'); + + -- Envío del email + IF emptyList = 0 THEN + + SELECT CONCAT(`e-mail`,',pako@verdnatura.es') INTO MyMailTo + FROM Clientes + WHERE Id_Cliente = v_Client_Id AND `e-mail`>''; + + IF v_Client_Id = 7818 THEN -- LOEWE + SET MyMailTo = 'isabel@elisabethblumen.com,emunozca@loewe.es,pako@verdnatura.es'; + END IF; + + CALL vn.mail_insert( + IFNULL(MyMailTo,'pako.natek@gmail.com'), + 'pako@verdnatura.es', + 'Resumen de pedidos preparados', + txt + ); + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `emailYesterdayPurchasesLauncher` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `emailYesterdayPurchasesLauncher`() +BEGIN + +DECLARE done INT DEFAULT 0; +DECLARE vMyClientId INT; + +DECLARE rs CURSOR FOR +SELECT Id_Cliente +FROM Clientes +WHERE EYPBC != 0; + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + +OPEN rs; + +FETCH rs INTO vMyClientId; + +WHILE NOT done DO + + CALL emailYesterdayPurchasesByConsigna(util.yesterday(), vMyClientId); + + FETCH rs INTO vMyClientId; + +END WHILE; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `embalajes_stocks` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `embalajes_stocks`(IN idPEOPLE INT, IN bolCLIENT BOOLEAN) +BEGIN + +if bolCLIENT then + + select m.Id_Article, Article, - cast(sum(m.Cantidad) as decimal) as Saldo + from Movimientos m + join Articles a on m.Id_Article = a.Id_Article + join Tipos tp on tp.tipo_id = a.tipo_id + join Tickets t using(Id_Ticket) + join Consignatarios cs using(Id_Consigna) + where cs.Id_Cliente = idPEOPLE + and Tipo = 'Contenedores' + and t.Fecha > '2010-01-01' + group by m.Id_Article; + +else + +select Id_Article, Article, sum(Cantidad) as Saldo +from +(select Id_Article, Cantidad +from Compres c +join Articles a using(Id_Article) +join Tipos tp using(tipo_id) +join Entradas e using(Id_Entrada) +join travel tr on tr.id = travel_id +where Id_Proveedor = idPEOPLE +and landing >= '2010-01-01' +and reino_id = 6 + +union all + +select Id_Article, - Cantidad +from Movimientos m +join Articles a using(Id_Article) +join Tipos tp using(tipo_id) +join Tickets t using(Id_Ticket) +join Consignatarios cs using(Id_Consigna) +join proveedores_clientes pc on pc.Id_Cliente = cs.Id_Cliente +where Id_Proveedor = idPEOPLE +and reino_id = 6 +and t.Fecha > '2010-01-01') mov + +join Articles a using(Id_Article) +group by Id_Article; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `embalajes_stocks_detalle` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `embalajes_stocks_detalle`(IN idPEOPLE INT, IN idARTICLE INT, IN bolCLIENT BOOLEAN) +BEGIN + + +if bolCLIENT then + + select m.Id_Article + , Article + , IF(Cantidad < 0, - Cantidad, NULL) as Entrada + , IF(Cantidad < 0, NULL, Cantidad) as Salida + , 'T' as Tabla + , t.Id_Ticket as Registro + , t.Fecha + , w.name as Almacen + , cast(Preu as Decimal(5,2)) Precio + , c.Cliente as Proveedor + , abbreviation as Empresa + from Movimientos m + join Articles a using(Id_Article) + join Tickets t using(Id_Ticket) + join empresa e on e.id = t.empresa_id + join warehouse w on w.id = t.warehouse_id + join Consignatarios cs using(Id_Consigna) + join Clientes c on c.Id_Cliente = cs.Id_Cliente + where cs.Id_Cliente = idPEOPLE + and m.Id_Article = idARTICLE + and t.Fecha > '2010-01-01'; + +else + +select Id_Article, Tabla, Registro, Fecha, Article +, w.name as Almacen, Entrada, Salida, Proveedor, cast(Precio as Decimal(5,2)) Precio + +from + +(select Id_Article + , IF(Cantidad > 0, Cantidad, NULL) as Entrada + , IF(Cantidad > 0, NULL,- Cantidad) as Salida + , 'E' as Tabla + , Id_Entrada as Registro + , landing as Fecha + , tr.warehouse_id + , Costefijo as Precio +from Compres c +join Entradas e using(Id_Entrada) +join travel tr on tr.id = travel_id +where Id_Proveedor = idPEOPLE +and Id_Article = idARTICLE +and landing >= '2010-01-01' + +union all + +select Id_Article + , IF(Cantidad < 0, - Cantidad, NULL) as Entrada + , IF(Cantidad < 0, NULL, Cantidad) as Salida + , 'T' + , Id_Ticket + , Fecha + , t.warehouse_id + , Preu +from Movimientos m +join Tickets t using(Id_Ticket) +join Consignatarios cs using(Id_Consigna) +join proveedores_clientes pc on pc.Id_Cliente = cs.Id_Cliente +where Id_Proveedor = idPEOPLE +and Id_Article = idARTICLE +and t.Fecha > '2010-01-01') mov + +join Articles a using(Id_Article) +join Proveedores p on Id_Proveedor = idPEOPLE +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `EntradasTriggerBeforeDelete` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `EntradasTriggerBeforeDelete`(oldTravel INT, oldId INT) +BEGIN + + DECLARE hasToRecalculate BOOLEAN; + DECLARE newWarehouse INT; + + SELECT Id_Compra INTO hasToRecalculate FROM Compres c + JOIN vn.lastBuy lb ON lb.id = c.Id_Compra + WHERE c.Id_Entrada = newId LIMIT 1; + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel WHERE id = oldTravel; + CALL vn.lastBuyRefresh(newWarehouse); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `EntradasTriggerBeforeUpdate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `EntradasTriggerBeforeUpdate`(oldTravel INT, newTravel INT, oldRedada BOOLEAN, + newRedada BOOLEAN, newId INT) +BEGIN + DECLARE newWarehouse INTEGER; + DECLARE hasToRecalculate BOOLEAN; + + IF oldRedada <> newRedada OR newTravel IS NULL THEN + + SELECT Id_Compra INTO hasToRecalculate FROM Compres c + JOIN vn.lastBuy lb ON lb.id = c.Id_Compra + WHERE c.Id_Entrada = newId LIMIT 1; + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel WHERE id = newtravel; + CALL vn.lastBuyRefresh(newWarehouse); + END IF; + END IF; + + IF newTravel <> oldTravel AND newTravel IS NOT NULL THEN + UPDATE travel t + JOIN Compres c ON c.Id_Entrada = newId + JOIN vn.lastBuy lb ON c.Id_Article = lb.item AND t.warehouse_id = lb.warehouse + SET lb.id = c.Id_Compra + WHERE t.id = newTravel AND t.landing BETWEEN vn.getInventoryDate() AND util.yesterday() + AND t.landing > lb.landing; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `entryFromOrder` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `entryFromOrder`(IN vShipmentWarehouse INTEGER, IN vLandingWarehouse INTEGER, IN vItem INTEGER, + IN vAmount INTEGER,IN vVolume INTEGER,vCost DECIMAL(10,2), IN vRetailedPrice DECIMAL(10,2), vInOutDate DATE) +BEGIN + + DECLARE vTravel INT; + DECLARE vEntry INT; + DECLARE vBucket VARCHAR(10); + + -- seleccionamos travel + SELECT id, Id_Entrada INTO vTravel, vEntry + FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id + WHERE t.landing = vInOutDate AND t.shipment = vInOutDate AND t.warehouse_id_out = vShipmentWarehouse + AND t.warehouse_id = vLandingWarehouse AND agency_id = 15 + LIMIT 1; + + -- creamos el travel si es necesario + IF NOT IFNULL(vTravel,0) THEN + INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) + VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse, 15); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + -- creamos la Entrada si es necesario + IF NOT IFNULL(vEntry,0) THEN + INSERT INTO Entradas (Id_Proveedor, travel_id) + VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' + SELECT LAST_INSERT_ID() INTO vEntry; + END IF; + + -- creamos el cubo si es necesario + SELECT Id_Cubo INTO vBucket FROM Cubos WHERE Volumen = vVolume LIMIT 1; + + IF NOT IFNULL(vBucket,'') > '' THEN + INSERT INTO Cubos (Id_Cubo, Volumen) + VALUES (CONCAT('dm',vVolume/1000), vVolume); + SELECT LAST_INSERT_ID() INTO vBucket; + END IF; + + INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, Embalajefijo, + Comisionfija, Tarifa2, Tarifa3) + VALUES(vItem, + vAmount, + vEntry, + vBucket, + 1, + 1, + 0, + vCost, + 0, + 0, + 0, + vRetailedPrice, + vRetailedPrice); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `entryFromTicket` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `entryFromTicket`(IN vTicket INTEGER, IN vLandingWarehouse INTEGER) +BEGIN + + DECLARE vShipmentWarehouse INT; + DECLARE vLandingDate DATE; + DECLARE vShipmentDate DATE; + DECLARE vTravel INT; + DECLARE vEntry INT; + + SELECT warehouse_id, Fecha, Fecha INTO vShipmentWarehouse, vShipmentDate, vLandingDate + FROM Tickets + WHERE Id_Ticket = vTicket; + + -- seleccionamos travel + SELECT id, Id_Entrada INTO vTravel, vEntry + FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id + WHERE t.landing = vLandingDate + AND t.shipment = vShipmentDate + AND t.warehouse_id_out = vShipmentWarehouse + AND t.warehouse_id = vLandingWarehouse + AND agency_id = 15 + LIMIT 1; + + -- creamos el travel si es necesario + IF vTravel IS NULL THEN + SELECT vLandingDate; + INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) + VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, 15); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + + -- creamos la Entrada si es necesario + IF vEntry IS NULL THEN + INSERT INTO Entradas (Id_Proveedor, travel_id) + VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' + SELECT LAST_INSERT_ID() INTO vEntry; + END IF; + + CALL vn.buyUltimate(vShipmentWarehouse,vShipmentDate); + + INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, Embalajefijo, Comisionfija, Tarifa2, Tarifa3) + SELECT m.Id_Article, + m.Cantidad, + vEntry, + c.Id_Cubo, + c.Packing, + IF(c.`grouping`,c.`grouping`,1), + c.caja, + Costefijo, + c.Portefijo, + c.Embalajefijo, + c.Comisionfija, + m.Preu Tarifa2, + m.Preu Tarifa3 + FROM Movimientos m + JOIN Articles a ON m.Id_Article = a.Id_Article + LEFT JOIN tmp.buyUltimate b ON m.Id_Article = b.itemFk AND b.warehouseFk = vShipmentWarehouse + LEFT JOIN Compres c ON c.Id_Compra = b.buyFk + WHERE m.Id_Ticket = vTicket; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `eti_to_print` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `eti_to_print`(IN idENTRADA INT, IN idPRODUCER INT) +BEGIN + +select Vida as Impresas + ,Etiquetas as bultos + ,Packing + ,Id_Article + ,CONCAT(Article,' ',Medida,' ', Categoria) as Articat + ,p.name as marca + ,Proveedor + ,Id_Entrada + ,Id_Compra +from Compres c +join Entradas e using(Id_Entrada) +join Proveedores using(Id_Proveedor) +join travel tr on tr.id = e.travel_id +join Articles a using(Id_Article) +left join producer p using(producer_id) +where Id_Entrada = idENTRADA + and idPRODUCER in (0,a.producer_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `f10_no_vincular` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `f10_no_vincular`(lngEntrada INTEGER) +BEGIN + DECLARE datFecha DATE DEFAULT util.VN_CURDATE(); + +-- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo + DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_; + CREATE TEMPORARY TABLE IF NOT EXISTS f10_no_vincular_ + SELECT c.Id_Entrada,c.Id_Compra,c.Id_Article, c.Novincular, c.Packing, be.pri + FROM Compres c + JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha + LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = c.Id_Entrada + WHERE + ((ek.Id_Entrada IS NOT NULL AND ek.sub IS NULL) + OR (c.Id_Entrada = 9200 AND be.ok <> FALSE) + OR c.Id_Entrada = lngEntrada) AND Id_Article <> 90; + + -- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing; + CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Packing + SELECT * FROM ( + SELECT * FROM f10_no_vincular_ + ORDER BY pri DESC + LIMIT 10000000000000000000) t + GROUP BY Id_Article,Packing + HAVING count(Id_Compra) > 1 AND BIT_OR(Id_Entrada = 9200); + + UPDATE Compres c + JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha + JOIN f10_mismo_Packing f ON f.Id_Article = c.Id_Article AND c.Packing = f.Packing + LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = f.Id_Entrada + SET c.Novincular = IF(c.Id_Compra = f.Id_Compra,0,1) + WHERE + ((ek.Id_Entrada IS NOT NULL AND ek.sub IS NULL) + OR (c.Id_Entrada = 9200 AND be.ok <> FALSE) + OR c.Id_Entrada = lngEntrada); + +-- Modifica el Id_Articulo si hay dos entradas con packing y el mismo Id_Articulo + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo; + CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Articulo + SELECT Id_Article FROM ( + SELECT * FROM ( + SELECT * FROM f10_no_vincular_ + ORDER BY Id_Entrada = 9200 DESC + LIMIT 10000000000000000000) t + GROUP BY Id_Article,Packing ) t + GROUP BY Id_Article HAVING COUNT(*) > 1 AND BIT_OR(Id_Entrada = 9200); + SELECT 4; + UPDATE Compres c + JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha + JOIN f10_mismo_Articulo f ON f.Id_Article = c.Id_Article + LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = c.Id_Entrada + SET c.Id_Article = 90 + WHERE c.Id_Entrada = 9200 AND be.ok <> FALSE; + + DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_; + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing; + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `Facturas_Saltos` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `Facturas_Saltos`(IN datSTART DATE , IN datEND DATE) +BEGIN + + +DECLARE strSER1 VARCHAR(2); +DECLARE strSER2 VARCHAR(2); +DECLARE intEMP1 INT; +DECLARE intEMP2 INT; +DECLARE v_done BOOLEAN DEFAULT FALSE; +DECLARE strFAC1 VARCHAR(11); +DECLARE strFAC2 VARCHAR(11); + + +DECLARE rs CURSOR FOR + SELECT Id_Factura, empresa_id, Serie + FROM Facturas + WHERE Fecha BETWEEN datSTART AND datEND + ORDER BY empresa_id, Serie, Id_Factura; + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; + +OPEN rs; + +DROP TEMPORARY TABLE IF EXISTS Facturas_Saltarinas; + +CREATE TEMPORARY TABLE Facturas_Saltarinas +(Factura_Inicial VARCHAR(11), + Factura_Final VARCHAR(11), + Empresa VARCHAR(3), + Serie VARCHAR(1)); + +FETCH rs INTO strFAC1, intEMP1, strSER1; + +IF NOT v_done THEN + + FETCH rs INTO strFAC2, intEMP2, strSER2; + +END IF; + +WHILE NOT v_done DO + + IF strSER1 = strSER2 AND intEMP1 = intEMP2 AND right(strFAC2,5) - right(strFAC1,5) > 1 then + + INSERT INTO Facturas_Saltarinas(Factura_Inicial, Factura_Final, Empresa, Serie) + SELECT strFAC1, strFAC2, abbreviation, strSER1 + FROM empresa + WHERE id = intEMP1; + + END IF; + + SET strFAC1 = strFAC2; + SET intEMP1 = intEMP2; + SET STRSER1 = strSER2; + + FETCH rs INTO strFAC2, intEMP2, strSER2; + +END WHILE; + +SELECT * FROM Facturas_Saltarinas; + +CLOSE rs; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `historico_absoluto` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `historico_absoluto`(IN idART INT, IN wh INT, IN datfecha DATETIME) +BEGIN + + DECLARE inv_calculado INT; + DECLARE inv INT; + DECLARE today DATETIME; + DECLARE fecha_inv DATETIME; + + SET today = util.VN_CURDATE(); + + CREATE OR REPLACE TEMPORARY TABLE historico_pasado + SELECT * + FROM ( + SELECT TR.landing Fecha, + C.Cantidad Entrada, + NULL Salida, + (TR.received != FALSE) OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5 + FROM Compres C -- mirar perque no entra en received + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + INNER JOIN Proveedores P USING (Id_Proveedor) + WHERE TR.landing >= '2001-01-01' + AND Id_proveedor <> 4 + AND wh IN (TR.warehouse_id , 0) + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT TR.shipment Fecha, + NULL Entrada, + C.Cantidad Salida, + TR.delivered OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5 + FROM Compres C + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + INNER JOIN Proveedores P USING (Id_Proveedor) + WHERE TR.shipment >= '2001-01-01' + AND wh = TR.warehouse_id_out + AND Id_Proveedor <> 4 + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT T.Fecha Fecha, + NULL Entrada, + M.Cantidad Salida, + (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK, + T.Alias Alias, + T.Factura Referencia, + T.Id_Ticket, + T.PedidoImpreso + FROM Movimientos M + INNER JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente + WHERE T.Fecha >= '2001-01-01' + AND M.Id_Article = idART + AND wh IN (T.warehouse_id , 0) + ) t1 + ORDER BY Fecha, Entrada DESC, OK DESC; + + SELECT sum(Entrada) - sum(Salida) INTO inv_calculado + FROM historico_pasado + WHERE Fecha < datfecha; + + SELECT p1.*, NULL v_virtual + FROM( + SELECT datfecha Fecha, + inv_calculado Entrada, + NULL Salida, + 1 OK, + 'Inventario calculado' Alias, + '' Referencia, 0 id, + 1 F5 + UNION ALL + SELECT * + FROM historico_pasado + WHERE Fecha >= datfecha + ) p1; + + DROP TEMPORARY TABLE historico_pasado; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `historico_joined` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `historico_joined`(IN idART INT, IN wh_joined INT, IN v_virtual INT) +BEGIN + DECLARE datFEC DATETIME; + + SELECT Fechainventario INTO datFEC FROM tblContadores; + SET @a = 0; + SELECT DATE(Fecha) Fecha, + Entrada, + Salida, + OK, + Alias, + Referencia, + id, + @a := @a + IFNULL(Entrada,0) - IFNULL(Salida,0) acumulado, + F5, + v_virtual, + CodigoTrabajador + FROM + ( SELECT TR.landing Fecha, + C.Cantidad Entrada, + NULL Salida, + (TR.received != FALSE) OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5, + tra.CodigoTrabajador + FROM Compres C + JOIN Entradas E USING (Id_Entrada) + JOIN travel TR ON TR.id = E.travel_id + JOIN Proveedores P USING (Id_Proveedor) + LEFT JOIN Articles a ON a.Id_Article = C.Id_Article + LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id + LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador + LEFT JOIN warehouse_joined wj ON wj.warehouse_id = TR.warehouse_id + WHERE TR.landing >= datFEC + AND wh_joined IN (wj.warehouse_alias_id , 0) + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT TR.shipment Fecha, + NULL Entrada, + C.Cantidad Salida, + TR.delivered OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5, + tra.CodigoTrabajador + FROM Compres C + JOIN Entradas E USING (Id_Entrada) + JOIN travel TR ON TR.id = E.travel_id + JOIN Proveedores P USING (Id_Proveedor) + LEFT JOIN Articles a ON a.Id_Article = C.Id_Article + LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id + LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador + LEFT JOIN warehouse_joined wj ON wj.warehouse_id = TR.warehouse_id_out + WHERE TR.shipment >= datFEC + AND wh_joined IN (wj.warehouse_alias_id,0) + AND Id_Proveedor <> 4 + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT T.Fecha Fecha, + NULL Entrada, + M.Cantidad Salida, + (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK, + T.Alias Alias, + T.Localizacion Referencia, + T.Id_Ticket id, + T.PedidoImpreso EtiquetasEmitidas, + tr.CodigoTrabajador + FROM Movimientos M + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente + LEFT JOIN Trabajadores tr ON tr.Id_Trabajador = C.Id_Trabajador + LEFT JOIN warehouse_joined wj ON wj.warehouse_id = T.warehouse_id + WHERE T.Fecha >= datFEC + AND M.Id_Article = idART + AND wh_joined IN (wj.warehouse_alias_id , 0) + ) AS Historico + ORDER BY Fecha, Entrada DESC, OK DESC; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `historico_multiple` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `historico_multiple`(IN vItemFk INT) +BEGIN + + DECLARE vDateInventory DATETIME; + + SELECT Fechainventario INTO vDateInventory FROM tblContadores; + + SET @a = 0; + + DROP TEMPORARY TABLE IF EXISTS hm1; + + CREATE TEMPORARY TABLE hm1 + SELECT DATE(Fecha) as Fecha, + Entrada, + Salida, + OK, + Referencia, + Historia.id, + + wh, + + `name` as wh_name + + FROM + + ( SELECT TR.landing as Fecha, + C.Cantidad as Entrada, + NULL as Salida, + + IF(warehouse_id = 44, 1, warehouse_id) as wh, + (TR.received != FALSE) as OK, + E.Referencia as Referencia, + E.Id_Entrada as id + + + + FROM Compres C + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + WHERE TR.landing >= vDateInventory + AND C.Id_Article = vItemFk + AND E.Redada = 0 + + AND C.Cantidad <> 0 + + UNION ALL + + SELECT TR.shipment as Fecha, + NULL as Entrada, + C.Cantidad as Salida, + warehouse_id_out as wh, + TR.delivered as OK, + E.Referencia as Referencia, + E.Id_Entrada as id + + FROM Compres C + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + WHERE TR.shipment >= vDateInventory + AND C.Id_Article = vItemFk + + AND E.Redada = 0 + + AND C.Cantidad <> 0 + + UNION ALL + + SELECT T.Fecha as Fecha, + NULL as Entrada, + M.Cantidad as Salida, + warehouse_id as wh, + (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) as OK, + T.Factura as Referencia, + T.Id_Ticket as id + + FROM Movimientos M + INNER JOIN Tickets T USING (Id_Ticket) + WHERE T.Fecha >= vDateInventory + AND M.Id_Article = vItemFk + + ) AS Historia + + INNER JOIN warehouse ON warehouse.id = Historia.wh + ORDER BY Fecha, Entrada DESC, OK DESC; + + + DROP TEMPORARY TABLE IF EXISTS hm2; + DROP TEMPORARY TABLE IF EXISTS hm3; + DROP TEMPORARY TABLE IF EXISTS hm4; + DROP TEMPORARY TABLE IF EXISTS hm5; + DROP TEMPORARY TABLE IF EXISTS hm6; + DROP TEMPORARY TABLE IF EXISTS hm7; + DROP TEMPORARY TABLE IF EXISTS hm8; + CREATE TEMPORARY TABLE hm2 SELECT * FROM hm1 WHERE wh = 19; + CREATE TEMPORARY TABLE hm3 SELECT * FROM hm1 WHERE wh = 7; + CREATE TEMPORARY TABLE hm4 SELECT * FROM hm1 WHERE wh = 60; + CREATE TEMPORARY TABLE hm5 SELECT * FROM hm1 WHERE wh = 5; + CREATE TEMPORARY TABLE hm6 SELECT * FROM hm1 WHERE wh = 17; + CREATE TEMPORARY TABLE hm7 SELECT * FROM hm1 WHERE wh = 37; + CREATE TEMPORARY TABLE hm8 SELECT * FROM hm1 WHERE wh = 55; + + SELECT * FROM + + ( + + SELECT Fecha, Entrada as BOGEntrada, Salida as BOGSalida, OK as BOGOK, Referencia as BOGReferencia, id as BOGid, + + NULL AS VNHEntrada, NULL AS VNHSalida, NULL AS VNHOK, NULL AS VNHReferencia, NULL AS VNHid, + + NULL AS ALGEntrada, NULL AS ALGSalida, NULL AS ALGOK, NULL AS ALGReferencia, NULL AS ALGid, + + NULL AS MADEntrada, NULL AS MADSalida, NULL AS MADOK, NULL AS MADReferencia, NULL AS MADid, + + NULL AS MCFEntrada, NULL AS MCFSalida, NULL AS MCFOK, NULL AS MCFReferencia, NULL AS MCFid, + + NULL AS VILEntrada, NULL AS VILSalida, NULL AS VILOK, NULL AS VILReferencia, NULL AS VILid, + + NULL AS BAREntrada, NULL AS BARSalida, NULL AS BAROK, NULL AS BARReferencia, NULL AS BARid + + FROM hm2 + + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + ,Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm3 + + + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm4 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm5 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm6 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + + + FROM hm7 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + + FROM hm8 + + ) sub + + ORDER BY Fecha, BOGEntrada IS NULL, VNHEntrada IS NULL, ALGEntrada IS NULL, MADEntrada IS NULL, MCFEntrada IS NULL, VILEntrada IS NULL, BAREntrada IS 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `InsertarEspionaje` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertarEspionaje`(intIdTrabajador INT(11),intIdEquipo int) +BEGIN + +DECLARE intNReg TINYINT DEFAULT 0; + +SELECT Count(*) AS NReg +INTO intNReg +FROM Espionajes +WHERE Fecha=Current_date +AND Id_Trabajador=intIdTrabajador; + +IF (intNReg=0) THEN + INSERT INTO Espionajes (Id_Trabajador,Fecha,HoraEntrada,Id_Equipo) + VALUES (intIdTrabajador,CURRENT_DATE,CURRENT_TIME,intIdEquipo); +ELSE + UPDATE Espionajes + SET HoraSalida=CURRENT_TIME + WHERE Id_Trabajador=intIdTrabajador + AND Fecha=util.VN_CURDATE(); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `inventario_valorado` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `inventario_valorado`(IN vDated DATE, IN vIsDetailed BOOLEAN) +BEGIN + +/** + * DEPRECATED usar item_ValuateInventory + */ + DECLARE vInventoried DATE; + DECLARE vHasNotInventory BOOLEAN DEFAULT 0; + DECLARE vInventoried2 DATE; + DECLARE vDateDayEnd DATETIME; + + SET vDateDayEnd = util.dayEnd(vDated); + SELECT landing INTO vInventoried + FROM travel tr + JOIN Entradas E ON E.travel_id = tr.id + WHERE landing <= vDateDayEnd + AND E.Id_Proveedor = 4 + ORDER BY landing DESC + LIMIT 1; + + SET vHasNotInventory = IF (vInventoried is null, TRUE, FALSE); + + IF vHasNotInventory THEN + + SELECT landing INTO vInventoried2 + FROM travel tr + JOIN Entradas E ON E.travel_id = tr.id + WHERE landing >= vDated + AND E.Id_Proveedor = 4 + ORDER BY landing ASC + LIMIT 1; + + SET vInventoried = TIMESTAMPADD(DAY,1,vDated); + SET vDateDayEnd = vInventoried2; + + END IF; + + DROP TEMPORARY TABLE IF EXISTS inv; + + CREATE TEMPORARY TABLE inv + (warehouseFk SMALLINT, + Id_Article BIGINT, + cantidad INT, + coste DOUBLE DEFAULT 0, + total DOUBLE DEFAULT 0, + Almacen VARCHAR(20), + PRIMARY KEY (Almacen, Id_Article) USING HASH) + ENGINE = MEMORY; + + IF vHasNotInventory = TRUE THEN + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id, C.Id_Article, SUM(C.Cantidad), w.`name` + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id + WHERE landing = vDateDayEnd + AND E.Id_Proveedor = 4 + AND w.valuatedInventory + AND t.inventory + GROUP BY tr.warehouse_id, C.Id_Article; + + END IF; + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id, C.Id_Article, C.Cantidad * IF(vHasNotInventory,-1,1), w.`name` + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = tr.warehouse_id + WHERE landing BETWEEN vInventoried AND vDateDayEnd + AND IF(landing = util.VN_CURDATE(), tr.received, trUE) + AND NOT redada + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(vHasNotInventory,-1,1)); + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id_out, C.Id_Article, C.Cantidad * IF(vHasNotInventory,1,-1), w.`name` + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id_out + WHERE shipment BETWEEN vInventoried AND vDateDayEnd + AND NOT redada + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(vHasNotInventory,1,-1)); + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT w.id, M.Id_Article, M.Cantidad * IF(vHasNotInventory,1,-1), w.`name` + FROM Movimientos M + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C USING(Id_Cliente) + JOIN Articles A USING(Id_Article) + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id + WHERE T.Fecha BETWEEN vInventoried AND vDateDayEnd + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(vHasNotInventory,1,-1); + + IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT w.id, M.Id_Article, M.Cantidad * IF(vHasNotInventory,0,1), w.`name` + FROM Movimientos M + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C USING(Id_Cliente) + JOIN Articles A USING(Id_Article) + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id + WHERE T.Fecha BETWEEN vDated AND vDateDayEnd + AND (M.OK <> 0 or T.Etiquetasemitidas <> 0 ) + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(vHasNotInventory,0,1); + + END IF; + + -- Mercancia en transito + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id, C.Id_Article, C.Cantidad, CONCAT(wOut.`name`,' - ', wIn.`name`) + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse wIn ON wIn.id = tr.warehouse_id + JOIN warehouse wOut ON wOut.id = tr.warehouse_id_out + WHERE vDated >= shipment AND vDated < landing + AND NOT redada + AND wIn.valuatedInventory + AND t.inventory + AND E.Confirmada + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad); + + CALL vn.buyUltimate(NULL,vDateDayEnd); + + UPDATE inv i + JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.Id_Article = bu.itemFk + JOIN Compres C ON C.Id_Compra = bu.buyFk + SET total = i.cantidad * (ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0)), + coste = ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0) + WHERE i.cantidad <> 0; + + DELETE FROM inv WHERE Cantidad IS NULL or Cantidad = 0; + + IF vIsDetailed THEN + + SELECT inv.warehouseFk, a.Id_Article, a.Article, a.Medida, inv.Cantidad, tp.Id_Tipo, + tp.reino_id, inv.coste, cast(inv.total as decimal(10,2)) total, Almacen + FROM inv + JOIN warehouse w on w.id = warehouseFk + JOIN Articles a ON a.Id_Article = inv.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + WHERE w.valuatedInventory + and inv.total > 0 + order by inv.total desc; + + ELSE + + SELECT i.Almacen, r.reino as Reino, cast(i.total as decimal(10,2)) as Euros, tr.Codigotrabajador as Comprador,A.Id_Article + FROM inv i + JOIN warehouse w on w.id = warehouseFk + JOIN Articles A USING(Id_Article) + JOIN Tipos t USING(tipo_id) + LEFT JOIN Trabajadores tr ON tr.Id_trabajador = t.Id_trabajador + JOIN reinos r ON r.id = t.reino_id + WHERE w.valuatedInventory + AND i.total > 0; + + END IF; + DROP TEMPORARY TABLE tmp.buyUltimate; + DROP TEMPORARY TABLE inv; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_buy` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_buy`(IN v_wh TINYINT, IN v_date DATETIME) +BEGIN + DECLARE date_inv DATE; + ALTER TABLE item + ADD buy_id INT UNSIGNED; + + IF v_date < (SELECT vn.getInventoryDate()) THEN + SELECT MIN(landing) INTO date_inv FROM travel t INNER JOIN Entradas e ON e.travel_id = t.id + WHERE warehouse_id_out = 13 AND landing <= v_date; + ELSE + SET date_inv = vn.getInventoryDate(); + END IF; + UPDATE item i INNER JOIN ( + SELECT * FROM ( + SELECT c.Id_Article item_id, c.Id_Compra id + FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) + INNER JOIN travel t ON t.id = e.travel_id + WHERE t.landing BETWEEN date_inv AND v_date + AND c.Novincular = FALSE + AND c.Tarifa2 >= 0 + ORDER BY v_wh = t.warehouse_id DESC, t.landing DESC + LIMIT 10000000000000000000 + ) t + GROUP BY item_id + ) t + ON i.id = t.item_id + SET i.buy_id = t.id; + + CREATE INDEX buy USING HASH ON item (buy_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_express` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_express`(IN intWH INT, IN datFEC DATE) +BEGIN + +DECLARE datINV DATE; + + + +SELECT FechaInventario INTO datINV FROM tblContadores LIMIT 1; + + +SELECT sub1.Id_Article, Visible, Tarifa2 +FROM +(SELECT Id_Article, SUM(Cantidad) as Visible +FROM Compres C +JOIN Entradas E USING(Id_Entrada) +JOIN travel T ON T.id = E.travel_id +WHERE shipment >= datINV +AND landing <= datFEC +AND Redada = 0 +AND warehouse_id = intWH +GROUP BY Id_Article) sub1 +JOIN +( +SELECT * FROM +( +SELECT Id_Article, Tarifa2 +FROM Compres C +JOIN Entradas E USING(Id_Entrada) +JOIN travel T ON T.id = E.travel_id +WHERE shipment >= datINV +AND landing <= datFEC +AND Redada = 0 +AND Novincular = 0 +AND warehouse_id = intWH +ORDER BY landing DESC LIMIT 10000000000000000000) sub +GROUP BY Id_Article) sub2 USING(Id_Article); + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_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 = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_new`() +BEGIN + CREATE TEMPORARY TABLE item + ( + item_id INT UNSIGNED NOT NULL, + UNIQUE KEY USING HASH (item_id) + ) + ENGINE = MEMORY; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ListaTicketsEncajados` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `ListaTicketsEncajados`(IN intId_Trabajador int) +BEGIN + +SELECT Agencia,Consignatario, ti.Id_Ticket, ts.worker Id_Trabajador,IFNULL(ncajas,0) AS ncajas, +IFNULL(nbultos,0) AS nbultos,IFNULL(notros,0) AS notros,ts.code AS Estado +FROM Tickets ti +INNER JOIN Consignatarios ON ti.Id_Consigna = Consignatarios.Id_consigna +INNER JOIN Agencias ON ti.Id_Agencia = Agencias.Id_Agencia +LEFT JOIN (select Ticket_Id,count(*) as ncajas from expeditions where Id_Article=94 group by ticket_id) sub1 on ti.Id_Ticket=sub1.Ticket_Id +LEFT JOIN (select Ticket_Id,count(*) as nbultos from expeditions where Id_Article is null group by ticket_id) sub2 on ti.Id_Ticket=sub2.Ticket_Id +LEFT JOIN (select Ticket_Id,count(*) as notros from expeditions where Id_Article >0 group by ticket_id) sub3 on ti.Id_Ticket=sub3.Ticket_Id +INNER JOIN vn.ticketState ts ON ti.Id_ticket = ts.ticket +WHERE ti.Fecha=util.VN_CURDATE() and +ts.worker=intId_Trabajador +group by ti.Id_Ticket; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `malpagantes` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `malpagantes`() +BEGIN + +set @cliente := 0; +set @saldo := 0; + +Select Id_Cliente, Cliente from +Clientes +join +(select distinct Id_Cliente +from Facturas +where Fecha > '2015-01-01') cli using(Id_Cliente) +left join +( +select distinct Id_Cliente +from +( +select Fecha + , @saldo := IF(@cliente = Id_Cliente, @saldo + Importe, Importe) Saldo + , @cliente := Id_Cliente as Id_Cliente +from +( +select Id_Cliente, Fecha, Importe from + +( +select Id_Cliente, -1 * Importe Importe, Fecha +from Facturas +union all +select Id_Cliente, Entregado, Fechacobro +from Recibos +) sub +order by Id_Cliente, Fecha +) sub2 +) sub3 +where Saldo > -1 +and Fecha > '2015-01-01' + +) sub4 using(Id_Cliente) +where sub4.Id_Cliente is 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `mensaje` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `mensaje`(IN idREM INT, IN idDES INT, IN strMSG LONGTEXT) +BEGIN + +/*DECLARE lngLASTID BIGINT;*/ + +-- Caso sencillo + +INSERT INTO Mensajes(Mensaje, Fecha, Remitente, Destinatario) +VALUES(strMSG, util.VN_NOW(), idREM, idDES); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `msg` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `msg`(IN memTXT VARCHAR(255), IN idREM INTEGER, idDES INTEGER) +BEGIN + DECLARE last_ID INTEGER; + DECLARE codDES CHAR(3); + + SELECT CodigoTrabajador INTO codDES FROM Trabajadores WHERE Id_Trabajador = idDES; + + INSERT INTO Mensajes(Mensaje,Fecha,Remitente,Destinatario) + VALUES(memTXT, util.VN_NOW(),idREM, idDES); + + SELECT LAST_INSERT_ID() INTO last_ID; + + + INSERT INTO Incidencias(Incidencia,Id_Trabajador,Destino,Fecha,Fecha_Mod) + VALUES (CONCAT('@@ ',last_ID),idREM,codDES,util.VN_NOW(),util.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `nest_child_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `nest_child_add`( + vTable VARCHAR(45) + ,vChild VARCHAR(45) + ,vFatherId INT +) +BEGIN + DECLARE vMyLeft INT; + + SET vTable = util.quoteIdentifier(vTable); + + DROP TEMPORARY TABLE IF EXISTS aux; + CREATE TEMPORARY TABLE aux + SELECT 0 as lft; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux + SET lft = (SELECT lft + FROM ', vTable, + ' WHERE id = ?)') + USING vFatherId; + + SELECT lft INTO vMyLeft FROM aux; + DROP TEMPORARY TABLE aux; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, ' + SET rgt = rgt + 2 + WHERE rgt > ? + ORDER BY rgt DESC') + USING vMyLeft; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, ' + SET lft = lft + 2 + WHERE lft > ? + ORDER BY lft DESC') + USING vMyLeft; + + EXECUTE IMMEDIATE CONCAT( + 'INSERT INTO ', vTable, ' (name, lft, rgt) + VALUES(?, ? + 1, ? + 2)') + USING vChild, + vMyLeft, + vMyLeft; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `nest_delete` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `nest_delete`( + vTable VARCHAR(45) + ,vNodeId INT +) +BEGIN + DECLARE vMyRight INT; + DECLARE vMyLeft INT; + DECLARE vMyWidth INT; + + DROP TEMPORARY TABLE IF EXISTS aux; + CREATE TEMPORARY TABLE aux + SELECT 0 rgt, 0 lft, 0 wdt; + + SET vTable = util.quoteIdentifier(vTable); + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.rgt = t.rgt, + a.lft = t.lft, + a.wdt = t.rgt - t.lft + 1 + WHERE t.id = ?') + USING vNodeId; + + SELECT rgt, lft, wdt + INTO vMyRight, vMyLeft, vMyWidth + FROM aux; + + DROP TEMPORARY TABLE aux; + + EXECUTE IMMEDIATE CONCAT( + 'DELETE FROM ', vTable, + ' WHERE lft BETWEEN ? AND ?') + USING vMyLeft, vMyRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + ' SET rgt = rgt - ? + WHERE rgt > ? + ORDER BY rgt') + USING vMyWidth,vMyRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + ' SET lft = lft - ? + WHERE lft > ? + ORDER BY lft') + USING vMyWidth, vMyRight; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `nest_move` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `nest_move`( + vTable VARCHAR(45) + ,idNODE INT + ,idFATHER INT +) +BEGIN + DECLARE myRight INT; + DECLARE myLeft INT; + DECLARE myWidth INT; + DECLARE fatherRight INT; + DECLARE fatherLeft INT; + DECLARE gap INT; + + SET vTable = util.quoteIdentifier(vTable); + + DROP TEMPORARY TABLE IF EXISTS aux; + CREATE TEMPORARY TABLE aux + SELECT 0 as rgt, 0 as lft, 0 as wdt, 0 as frg, 0 as flf; + + -- Averiguamos el ancho de la rama + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.wdt = t.rgt - t.lft + 1 + WHERE t.id = ?') + USING idNODE; + + -- Averiguamos la posicion del nuevo padre + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.frg = t.rgt, + a.flf = t.lft + WHERE t.id = ?') + USING idFATHER; + + SELECT wdt, frg, flf INTO myWidth, fatherRight, fatherLeft + FROM aux; + + -- 1º Incrementamos los valores de todos los nodos a la derecha del punto de inserción (fatherRight) , para hacer sitio + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET rgt = rgt + ? + WHERE rgt >= ? + ORDER BY rgt DESC') + USING myWidth, + fatherRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET lft = lft + ? + WHERE lft >= ? + ORDER BY lft DESC') + USING myWidth, + fatherRight; + + -- Es preciso recalcular los valores del nodo en el caso de que estuviera a la derecha del nuevo padre + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.rgt = t.rgt, + a.lft = t.lft + WHERE t.id = ?') + USING idNODE; + + SELECT lft, rgt, frg - lft INTO myLeft, myRight, gap + FROM aux; + + -- 2º Incrementamos el valor de todos los nodos a trasladar hasta alcanzar su nueva posicion + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET lft = lft + ? + WHERE lft BETWEEN ? AND ? + ORDER BY lft DESC') + USING gap, + myLeft, + myRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET rgt = rgt + ? + WHERE rgt BETWEEN ? AND ? + ORDER BY rgt DESC') + USING gap, + myLeft, + myRight; + + -- 3º Restaremos a todos los nodos resultantes, a la derecha de la posicion arrancada el ancho de la rama escindida + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET lft = lft - ? + WHERE lft > ? + ORDER BY lft') + USING myWidth, + myLeft; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET rgt = rgt - ? + WHERE rgt > ? + ORDER BY rgt') + USING myWidth, + myRight; + + DROP TEMPORARY TABLE aux; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `newItem` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `newItem`(IN vTicket INTEGER, IN vVolume INTEGER, IN vQuantity INTEGER) +BEGIN + + DECLARE vLandingWarehouse INT; + DECLARE vLandingDate DATE; + DECLARE vShipmentDate DATE; + DECLARE vTravel INT; + DECLARE vEntry INT; + + SELECT warehouse_id, Fecha, landing INTO vLandingWarehouse, vShipmentDate, vLandingDate FROM Tickets WHERE Id_Ticket = vTicket; + + -- seleccionamos travel + SELECT id, Id_Entrada INTO vTravel, vEntry + FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id + WHERE t.landing = vLandingDate AND t.shipment = vShipmentDate AND t.warehouse_id_out = vLandingWarehouse AND t.warehouse_id = vWarehouse + AND t.delivered = FALSE ; -- agency ?? + + -- creamos el travel si es necesario + IF NOT vTravel THEN + INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) + VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, a); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + + -- creamos la Entrada si es necesario + IF NOT vEntry THEN + INSERT INTO Entradas (Id_Proveedor, travel_id) + VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' + SELECT LAST_INSERT_ID() INTO vEntry; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `niching` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `niching`(IN i_ini INT, IN i_end INT +, IN i_bal INT, IN i_col INT ) +BEGIN + +DECLARE i INT(5); +DECLARE j INT(5); + +DROP TEMPORARY TABLE IF EXISTS labels; + +CREATE TEMPORARY TABLE `labels` + (`label` VARCHAR(15) NULL) +ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +WHILE i_ini <= i_end DO + + SET i = i_bal; + + WHILE i > 0 DO + + + + SET j = i_col; + IF j = 0 THEN + INSERT INTO labels(label) + VALUES (CONCAT(i_ini,IF(i=0,' ',char(64 + i)))); + ELSE + + WHILE j > 0 DO + + INSERT INTO labels(label) + VALUES (CONCAT(i_ini,char(64 + i), j)); + + SET j = j - 1; + + END WHILE; + END IF; + SET i = i - 1; + + END WHILE; + +SET i_ini = i_ini + 1; + +END WHILE; + +SELECT CONCAT('*',label,'*') as label, label as id FROM labels; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `notify_passport` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `notify_passport`( + IN vItemFk INT, + IN vStickers SMALLINT, + IN vPacking SMALLINT, + IN vBuyFk INT +) +BEGIN + -- DPRECATED use vn.buy_notifyPassport + CALL vn.buy_notifyPassport(vBuyFk, vItemFk, vStickers, vPacking); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `pay` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `pay`(IN datFEC DATE + , IN idPROV INT + , IN dblIMPORTE DOUBLE + , IN idMONEDA INT + , IN dblDIVISA DOUBLE + , IN idCAJA INT + , IN idPAYMET INT + , IN dblGASTOS DOUBLE + , IN strCONCEPTO VARCHAR(40) + , IN idEMP INT) +BEGIN + + -- Registro en la tabla Cajas + INSERT INTO Cajas ( Concepto + , Serie + , Numero + , Salida + , Cajafecha + , Partida + , Id_Banco + , Id_Trabajador + ,empresa_id + ,conciliado) + + SELECT CONCAT('n/pago a ', Proveedor) + , 'R' + , idPROV + , dblIMPORTE + , datFEC + , 1 + , idCAJA + , account.myUser_getId() + , idEMP + , 1 + FROM Proveedores + WHERE Id_Proveedor = idPROV; + + -- Registro en la tabla pago + INSERT INTO pago(fecha + , dueDated + , id_proveedor + , importe + , id_moneda + , divisa + , id_banco + , pay_met_id + , g_bancarios + , concepte + , empresa_id) + + VALUES(datFEC + , datFEC + , idPROV + , dblIMPORTE + , idMONEDA + , IF(dblDIVISA = 0, NULL, dblDIVISA) + , idCAJA + , idPAYMET + , dblGASTOS + , strCONCEPTO + , idEMP); + + SELECT LAST_INSERT_ID() as pago_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `percentil` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `percentil`() +BEGIN + +DECLARE max_range INT; + +DROP TEMPORARY TABLE IF EXISTS previa; + +CREATE TEMPORARY TABLE previa +SELECT @posicion:= @posicion +1 as Posicion, Id_Cliente, Total FROM ( +SELECT Id_Cliente, Total FROM ( +SELECT Id_Cliente, SUM(Importe) as Total +FROM Facturas +INNER JOIN Clientes USING(Id_Cliente) +INNER JOIN (SELECT @posicion := 0) sub_pos +WHERE invoice +AND YEAR(Fecha) = YEAR(util.VN_CURDATE()) +GROUP BY Id_Cliente) sub +ORDER BY Total +) sub2; + +SELECT COUNT(*) INTO max_range FROM previa; + +UPDATE Clientes SET percentil = 0; + +UPDATE Clientes INNER JOIN previa USING(Id_Cliente) +SET Clientes.percentil = ROUND(Posicion *100 / max_range,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `preOrdenarRuta` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `preOrdenarRuta`(IN vRutaId INT) +BEGIN +/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta + * vRutaId id ruta + * DEPRECATED use vn.routeGressPriority +*/ + +UPDATE Tickets mt +JOIN ( + SELECT tt.Id_Consigna, round(ifnull(avg(t.Prioridad),0),0) as Prioridad + from Tickets t + JOIN Tickets tt on tt.Id_Consigna = t.Id_Consigna + where t.Fecha > TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) + AND tt.Id_Ruta = vRutaId + GROUP BY Id_Consigna + ) sub ON sub.Id_Consigna = mt.Id_Consigna + SET mt.Prioridad = sub.Prioridad + WHERE mt.Id_Ruta = vRutaId; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `prepare_client_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 = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `prepare_client_list`() +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente + FROM tmp.ticket_list; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `prepare_ticket_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 = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `prepare_ticket_list`(vStartingDate DATETIME, vEndingDate DATETIME) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + ENGINE = MEMORY + SELECT t.Id_Ticket, c.Id_Cliente + FROM Tickets t + LEFT JOIN vn.ticketState ts ON ts.ticket = t.Id_Ticket + JOIN Clientes c ON c.Id_Cliente = t.Id_Cliente + WHERE c.typeFk IN ('normal','handMaking','internalUse') + AND ( + Fecha BETWEEN util.today() AND vEndingDate + OR ( + ts.alertLevel < 3 + AND t.Fecha >= vStartingDate + AND t.Fecha < util.today() + ) + ); +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `proc_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 = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_end`() +BEGIN + +UPDATE stat SET `end` = util.VN_NOW() +WHERE id = (SELECT id FROM lastid); + +DROP TEMPORARY TABLE IF EXISTS lastid; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `proc_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_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_start`(IN v_proc_id INT) +BEGIN + +INSERT INTO stat(proc_id) VALUES(v_proc_id); + + +DROP TEMPORARY TABLE IF EXISTS lastid; +CREATE TEMPORARY TABLE lastid +SELECT last_insert_id() 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `prueba_miguel` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `prueba_miguel`() +BEGIN +select 1; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `quadre_clientes` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `quadre_clientes`(IN datFEC DATETIME) +BEGIN + + + DECLARE datSTART DATE; + SET datFEC = TIMESTAMP(datFEC,'23:59:59'); + SELECT util.firstDayOfYear(datFEC) INTO datSTART; + + SELECT P2.Alias, C.Id_Cliente, C.Cuenta, Gestion, Contaplus, Gestion - Contaplus as Diferencia, empresa_id, Cliente + + FROM Clientes C + + JOIN pay_met pm ON pm.id = C.pay_met_id + + JOIN + + ( + + SELECT empresa_id, Id_Cliente, round(sum(Gestion),2) as Gestion, round(sum(Contaplus),2) as Contaplus + + FROM + + ( + SELECT empresa_id, Id_Cliente, Gestion, 0 as Contaplus + + FROM + + ( + SELECT empresa_id, Id_Cliente, -1 * Importe as Gestion + FROM Facturas + WHERE Fecha BETWEEN datSTART AND datFEC + UNION ALL + SELECT empresa_id, Id_Cliente, Entregado + FROM Recibos + WHERE Fechacobro BETWEEN datSTART AND datFEC + ) G + + WHERE empresa_id <> 965 + + UNION ALL + + SELECT empresa_id, Id_Cliente, 0, round(nz(Eurohaber) - nz(Eurodebe),2) as Contaplus + + FROM bi.XDiario_ALL XD + + JOIN Clientes C ON C.Cuenta = XD.SUBCTA + + WHERE Fecha BETWEEN datSTART AND datFEC + + ) sub1 + + GROUP BY empresa_id, Id_Cliente + + ) sub2 USING(Id_Cliente) + + JOIN Proveedores P2 ON P2.Id_Proveedor = sub2.empresa_id + + WHERE pm.deudaviva -- Cliente de perdidas no vale la pena revisarlo + + HAVING ABS(Diferencia) > 0.05 + + ORDER BY Cliente; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `quadre_clientes_detalle` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `quadre_clientes_detalle`(IN idC INT, IN idE INT, IN datFEC DATETIME) +BEGIN + +DECLARE datSTART DATE; + +SET datSTART = util.firstDayOfYear(datFEC); +SET datFEC = TIMESTAMP(datFEC,'23:59:59'); + +-- Creamos una tabla para almacenar las facturas del cliente, junto con el numero de veces que se repite. +DROP TEMPORARY TABLE IF EXISTS qFACTURAS; + +CREATE TEMPORARY TABLE qFACTURAS +(Fecha DATETIME, + TPVcount INT, + Factura DECIMAL(10,2) SIGNED, + Recibo DECIMAL(10,2) SIGNED, + CPcount INT, + Debe DECIMAL(10,2) SIGNED, + Haber DECIMAL(10,2) SIGNED, + Control INT DEFAULT 0, + PRIMARY KEY(Fecha, TPVcount, Factura, Recibo, CPcount, Debe, Haber)) + ENGINE = InnoDB +; + +-- Insertamos las facturas y los recibos de gestion. +INSERT INTO qFACTURAS + + SELECT Fecha, COUNT(*) as TPVcount, round(Importe,2) as Factura, 0 as Recibo, COUNT(*)as CPcount,round(Importe,2) as Debe, 0 as Haber, 1 as Control + FROM Facturas + WHERE Id_Cliente = idC AND empresa_id = idE AND Fecha BETWEEN datSTART AND datFEC + GROUP BY Fecha, round(Importe,2) + UNION ALL + SELECT Fechacobro as Fecha, COUNT(*) as TPVcount, 0 as Factura, round(Entregado,2) as Recibo,COUNT(*) as CPCount, 0 as Debe, round(Entregado,2) as Haber, 3 as Control + FROM Recibos + WHERE Id_Cliente = idC AND empresa_id = idE AND Fechacobro BETWEEN datSTART AND datFEC + GROUP BY Fechacobro, round(Entregado,2); + +-- Insertamos los asientos de contabilidad, marcando con control = -1 las repetidas. +INSERT INTO qFACTURAS + SELECT * + FROM ( + SELECT Fecha, COUNT(*) as TPVcount, round(Eurodebe,2) as Factura, round(Eurohaber,2) as Recibo, COUNT(*) as CPcount, round(Eurodebe,2) as Debe, round(Eurohaber,2) as Haber, 2 as Control + FROM bi.XDiario_ALL XD + JOIN Clientes C ON C.Cuenta = XD.SUBCTA + WHERE Id_Cliente = idC AND empresa_id = idE AND Fecha BETWEEN datSTART AND datFEC + AND (Eurodebe <> 0 OR Eurohaber <>0) + GROUP BY Fecha, round(Eurodebe,2), round(Eurohaber,2) + ) sub + + ON DUPLICATE KEY UPDATE Control = -1; + + + +-- Eliminamos las repetidas +-- DELETE FROM qFACTURAS WHERE Control = -1; + +-- Arreglamos las buenas +UPDATE qFACTURAS SET TPVcount = 0, Factura = 0, Recibo = 0 WHERE Control = 2; +UPDATE qFACTURAS SET CPcount = 0, Debe = 0, Haber = 0 WHERE Control IN (1,3); + +-- Mostramos el resultado +SELECT *, @saldo := @saldo + TPVcount * (Factura + Recibo) - CPCount * ( Debe + Haber ) as Saldo +FROM qFACTURAS +JOIN (SELECT @saldo := 0) truqui ; +DROP TEMPORARY TABLE IF EXISTS qFACTURAS; + + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `raidUpdate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `raidUpdate`() +BEGIN + + UPDATE Entradas e + JOIN Entradas_Auto ea USING (Id_Entrada) + JOIN travel t ON t.id = e.travel_id + JOIN ( + SELECT * + FROM ( + SELECT id, landing, warehouse_id, warehouse_id_out + FROM travel + JOIN ( + SELECT warehouse_id, warehouse_id_out + FROM Entradas_Auto ea + JOIN Entradas e USING(Id_Entrada) + JOIN travel t ON t.id = e.travel_id + GROUP BY warehouse_id, warehouse_id_out + ) t USING (warehouse_id, warehouse_id_out) + WHERE shipment > util.VN_CURDATE() AND delivered = FALSE + ORDER BY landing + LIMIT 10000000000000000000 + ) t + GROUP BY warehouse_id, warehouse_id_out + ) t USING (warehouse_id, warehouse_id_out) + SET e.travel_id = t.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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `rateView` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `rateView`() +BEGIN + + SELECT + t.year as año, + t.month as mes, + pagos.dolares, + pagos.cambioPractico, + CAST(sum(divisa) / sum(bi) as DECIMAL(5,4)) as cambioTeorico, + pagos.cambioOficial + FROM recibida r + JOIN time t ON t.date = r.fecha + JOIN recibida_iva ri ON r.id = ri.recibida_id + JOIN + ( + SELECT + t.year as Año, + t.month as Mes, + cast(sum(divisa) as DECIMAL(10,2)) as dolares, + cast(sum(divisa) / sum(importe) as DECIMAL(5,4)) as cambioPractico, + cast(rr.rate * 0.998 as DECIMAL(5,4)) as cambioOficial + FROM pago p + JOIN time t ON t.date = p.fecha + JOIN reference_rate rr ON rr.date = p.fecha AND moneda_id = 2 + WHERE divisa + AND fecha >= '2015-01-11' + GROUP BY t.year, t.month + ) pagos ON t.year = pagos.Año AND t.month = pagos.Mes + WHERE moneda_id = 2 + AND fecha >= '2015-01-01' + AND divisa + AND bi + GROUP BY t.year, t.month; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `recibidaIvaInsert` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `recibidaIvaInsert`(IN vId INT) +BEGIN + + DECLARE vRate DOUBLE DEFAULT 1; + DECLARE vDated DATE; + + SELECT MAX(rr.date) INTO vDated + FROM reference_rate rr + JOIN recibida r ON r.id = vId + WHERE rr.date <= r.fecha + AND rr.moneda_id = r.moneda_id ; + + IF vDated THEN + + SELECT rate INTO vRate + FROM reference_rate + WHERE `date` = vDated; + END IF; + + DELETE FROM recibida_iva WHERE recibida_id = vId; + + INSERT INTO recibida_iva(recibida_id, bi, gastos_id, divisa, taxTypeSageFk, transactionTypeSageFk) + SELECT r.id, + SUM(Costefijo * Cantidad) / IFNULL(vRate,1) bi, + 6003000000, + IF(r.moneda_id = 1,NULL,SUM(Costefijo * Cantidad )) divisa, + taxTypeSageFk, + transactionTypeSageFk + FROM recibida r + JOIN Entradas e ON e.recibida_id = r.id + JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor + JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + LEFT JOIN reference_rate rr ON rr.moneda_id = r.moneda_id AND rr.date = r.fecha + WHERE r.id = vId + HAVING bi IS NOT 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `recobro_credito` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `recobro_credito`() +BEGIN + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + INSERT INTO vn.clientCredit(clientFk, amount) + SELECT c.id, 0 + FROM vn.`client` c + JOIN vn.payMethod pm ON pm.id = c.payMethodFk + WHERE c.credit <> 0 AND pm.`code` = 'card'; + + UPDATE vn.`client` c + JOIN vn.payMethod pm ON pm.id = c.payMethodFk + SET credit = 0 + WHERE pm.`code` = 'card'; + + DROP TEMPORARY TABLE IF EXISTS clientes_credit; + CREATE TEMPORARY TABLE clientes_credit + SELECT Id_Cliente, if (Credito > Recobro ,Credito - Recobro,0) AS newCredit + FROM ( + SELECT r.Id_Cliente, r.amount AS Recobro, + timestampadd(DAY, period, UltimaFecha) AS Deadline, sub2.amount AS Credito + FROM vn2008.recovery r + JOIN ( + SELECT Id_Cliente, amount , odbc_date AS UltimaFecha + FROM ( + SELECT * FROM credit + ORDER BY odbc_date DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY Id_Cliente + ) sub2 USING(Id_Cliente) + WHERE dend IS NULL or dend >= util.VN_CURDATE() + GROUP BY Id_Cliente + HAVING Deadline <= util.VN_CURDATE() + ) sub3 + WHERE Credito > 0; + + UPDATE Clientes + JOIN clientes_credit USING(Id_Cliente) + SET Clientes.Credito = newCredit; + + INSERT INTO credit(Id_Cliente, amount, Id_Trabajador) + SELECT Id_Cliente, newCredit, NULL + FROM clientes_credit; + + DROP TEMPORARY TABLE clientes_credit; + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `risk_vs_client_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 = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `risk_vs_client_list`(maxRiskDate DATE) +BEGIN +/** + * Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list + * + * @deprecated usar vn.client_getDebt + * @param maxRiskDate Fecha maxima de los registros + * @return table tmp.risk + */ + DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(util.VN_CURDATE()) - 60, util.VN_CURDATE()); + DECLARE endingDate DATETIME; + DECLARE MAX_RISK_ALLOWED INT DEFAULT 200; + + SET maxRiskDate = IFNULL(maxRiskDate, util.VN_CURDATE()); + SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59'); + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2; + CREATE TEMPORARY TABLE tmp.client_list_2 + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * + FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3; + CREATE TEMPORARY TABLE tmp.client_list_3 + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * + FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar; + CREATE TEMPORARY TABLE tmp.tickets_sin_facturar + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT t.Id_Cliente, floor(IF(cl.isVies, 1, 1.1) * sum(Cantidad * Preu * (100 - Descuento) / 100)) as total + FROM Movimientos m + JOIN Tickets t on m.Id_Ticket = t.Id_Ticket + JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente + JOIN vn.client cl ON cl.id = t.Id_Cliente + WHERE Factura IS NULL + AND Fecha BETWEEN startingDate AND endingDate + GROUP BY t.Id_Cliente; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + CREATE TEMPORARY TABLE tmp.risk + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo + FROM Clientes c + JOIN ( + SELECT clientFk, SUM(amount) amount,SUM(amount) saldo + FROM vn.clientRisk + JOIN tmp.client_list on Id_Cliente = clientFk + GROUP BY clientFk + UNION ALL + SELECT Id_Cliente, SUM(Entregado),SUM(Entregado) + FROM Recibos + JOIN tmp.client_list_2 using(Id_Cliente) + WHERE Fechacobro > endingDate + GROUP BY Id_Cliente + UNION ALL + SELECT Id_Cliente, total,0 + FROM tmp.tickets_sin_facturar + UNION ALL + SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)) + FROM hedera.tpvTransaction t + JOIN tmp.client_list_3 on Id_Cliente = t.clientFk + WHERE t.receiptFk IS NULL + AND t.status = 'ok' + GROUP BY t.clientFk + ) t ON c.Id_Cliente = t.clientFk + WHERE c.activo != FALSE + GROUP BY c.Id_Cliente; + + DELETE r.* + FROM tmp.risk r + JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente + JOIN vn2008.pay_met pm on pm.id = c.pay_met_id + WHERE IFNULL(r.saldo,0) < 10 + AND r.risk <= MAX_RISK_ALLOWED + AND pm.`name` = 'TARJETA'; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `Rutas_Graph` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `Rutas_Graph`() +BEGIN + + DECLARE datSTART DATE DEFAULT TIMESTAMPADD(DAY,-3,util.VN_CURDATE()); + DECLARE datEND DATE; + + SET datEND = util.dayEnd(timestampadd(DAY,3,util.VN_CURDATE())); + + CALL vn.buyUltimate(NULL, datSTART); + + SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(buy_id)) / 1000000 AS DECIMAL(5,1)) AS m3, Agencia, w.name AS Almacen, DATE(R.Fecha) AS Fecha_Ruta + FROM vn2008.Rutas R + JOIN vn2008.Agencias a ON a.Id_Agencia = R.Id_Agencia + JOIN vn2008.Tickets t USING(Id_Ruta) + JOIN vn2008.warehouse w ON w.id = t.warehouse_id + JOIN vn2008.Movimientos m USING(Id_Ticket) + JOIN cache.last_buy b ON m.Id_Article = b.item_id AND t.warehouse_id = b.warehouse_id + WHERE R.Fecha BETWEEN datSTART AND datEND + GROUP BY Agencia, Almacen, Fecha_Ruta + UNION ALL + SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(buy_id)) / 1000000 AS decimal(5,1)) AS m3 ,Agencia, w.name AS Almacen, timestampadd(DAY,1,t.Fecha) AS Fecha + FROM vn2008.Tickets t + JOIN warehouse w ON w.id = warehouse_id + JOIN Agencias a USING(Id_Agencia) + JOIN vn2008.Movimientos m USING(Id_Ticket) + JOIN cache.last_buy b ON m.Id_Article = b.item_id AND t.warehouse_id = b.warehouse_id + LEFT JOIN warehouse_pickup wp ON wp.agency_id = t.Id_Agencia and wp.warehouse_id = t.warehouse_id + JOIN warehouse_pickup is_rec ON is_rec.agency_id = t.Id_Agencia + WHERE t.Fecha BETWEEN TIMESTAMPADD(DAY,-1,datSTART) AND TIMESTAMPADD(DAY,-1,datEND) + AND wp.agency_id IS NULL + GROUP BY Agencia, Almacen, timestampadd(DAY,1,t.Fecha) + -- JGF 2016-05-05 + UNION ALL + SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(Id_Compra)) / 1000000 AS decimal(5,1)) AS m3 ,a.Agencia, w.name AS Almacen, timestampadd(DAY,1,t.shipment) AS Fecha + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + JOIN Agencias a ON a.Id_Agencia = t.agency_id + JOIN warehouse w ON w.id = t.warehouse_id_out + JOIN warehouse_pickup wp ON wp.warehouse_id = t.warehouse_id_out + WHERE t.shipment BETWEEN TIMESTAMPADD(DAY,-1,datSTART) AND TIMESTAMPADD(DAY,-1,datEND) + GROUP BY a.Agencia, Almacen, Fecha; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `scan_rutas_view` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `scan_rutas_view`() +BEGIN + + +/* muestra las rutas agrupadas de los ultimos tres dias, así como una lista de los tickets sin enrutar, agrpados por agencia y fecha*/ + +select Fecha, Id_Ruta, Matricula, sub.m3, CodigoTrabajador, Agencia, Bultos, w.name as Almacen +from +( +select r.Fecha, Id_Ruta, r.Id_Trabajador, r.Id_Agencia, Id_Vehiculo, sum(m3) m3, sum(Bultos) Bultos, warehouse_id +from Rutas r +join Tickets t using(Id_Ruta) +where r.Fecha >= timestampadd(day,-3,util.VN_CURDATE()) +group by Id_Ruta, warehouse_id + +union all + +select ifnull(landing,Fecha), dayofmonth(Fecha) * 100000 + Id_Agencia ruta , count(*) as m3, Id_Agencia, null, null, sum(Bultos), warehouse_id +from Tickets +where Id_Ruta is null +and Fecha between timestampadd(day,-3,util.VN_CURDATE()) and util.dayEnd(util.VN_CURDATE()) +group by ruta, warehouse_id +) sub +left join Vehiculos using(Id_Vehiculo) +left join Agencias using(Id_Agencia) +left join Trabajadores using(Id_Trabajador) +left join warehouse w on w.id = sub.warehouse_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `sort_merge_passes_ernesto` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `sort_merge_passes_ernesto`() +BEGIN +declare i INT; +declare SMP INT; +DECLARE SMP_RATE INT; +DECLARE SMP_OLD INT; +DECLARE SMP_NEW INT; + +SET i = 0; +loop1: REPEAT + SET i = i + 1; + SET @SleepTime = 300; + + SELECT variable_value INTO @SMP_OLD FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes'; + + SELECT SLEEP(@SleepTime) INTO @NiCasoAEsteSLEEP_EsNormal; + + SELECT variable_value INTO @SMP_NEW FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes'; + SET @SMP = @SMP_NEW - @SMP_OLD; + SET @SMP_RATE = @SMP * 3600 / @SleepTime; + + Select VARIABLE_value into @connections from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'connections'; + Select VARIABLE_value into @Threads_created from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_created'; + Select VARIABLE_value into @Threads_cached from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_cached'; + Select VARIABLE_value into @Innodb_os_log_written from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Innodb_os_log_written'; + + Select VARIABLE_value into @Created_tmp_disk_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Created_tmp_disk_tables'; + Select VARIABLE_value into @created_tmp_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'created_tmp_tables'; + Select VARIABLE_value into @Created_tmp_files from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Created_tmp_files'; + Select VARIABLE_value into @opened_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'opened_tables'; + Select VARIABLE_value into @open_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'open_tables'; + Select VARIABLE_value into @TABLE_OPEN_CACHE_OVERFLOWS from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_OVERFLOWS'; + Select VARIABLE_value into @TABLE_OPEN_CACHE_MISSES from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_MISSES'; + Select VARIABLE_value into @TABLE_OPEN_CACHE_HITS from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_HITS'; + Select VARIABLE_value into @Uptime_since_flush_status from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Uptime_since_flush_status'; + Select VARIABLE_value into @Uptime from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Uptime'; + Select VARIABLE_value into @Qcache_hits from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_hits'; + Select VARIABLE_value into @Qcache_inserts from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_inserts'; + Select VARIABLE_value into @Qcache_not_cached from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_not_cached'; + Select VARIABLE_value into @Innodb_num_open_files from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Innodb_num_open_files'; + Select VARIABLE_value into @Open_table_definitions from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Open_table_definitions'; + select count into @trx_rseg_history_len from information_schema.innodb_metrics where name = 'trx_rseg_history_len'; + + Select @@global.table_definition_cache into @table_definition_cache; + Select @@global.table_open_cache into @table_open_cache; + Select @@global.table_open_cache_instances into @table_open_cache_instances; + Select @@global.thread_cache_size into @Thread_cache_size; + Select @@global.sort_buffer_size into @sort_buffer_size; + select @@global.join_buffer_size into @join_buffer_size; + select @@global.read_rnd_buffer_size into @read_rnd_buffer_size; + select @@global.tmp_table_size into @tmp_table_size; + select @@global.max_heap_table_size into @max_heap_table_size; + Select @@global.open_files_limit into @open_files_limit; + Select @@global.innodb_open_files into @innodb_open_files; + Select @@global.query_cache_size into @query_cache_size; + Select @@global.query_cache_type into @query_cache_type; + select @@global.log_output into @log_output; + + SELECT (Open_tables * Uptime / Opened_Tables) AS OpenTablesxUptimeDivOpened INTO @OpenTablesxUptimeDivOpened FROM + (SELECT variable_value Uptime FROM information_schema.global_status + WHERE variable_name = 'Uptime_since_flush_status') up, + (SELECT variable_value Open_tables FROM information_schema.global_status + WHERE variable_name = 'Open_tables') opn, + (SELECT IF(variable_value=0,1,variable_value) Opened_tables + FROM information_schema.global_status + WHERE variable_name = 'Opened_tables') opnd; + + INSERT INTO sort_merge_results_ernesto (hora, uptime, uptime_since_flush, smp_old, smp_new, smp, smp_hour,connections, Threads_created, Threads_cached, Thread_cache_size, sort_buffer_size, opened_tables, + Created_tmp_disk_tables, created_tmp_tables, Innodb_os_log_written, table_definition_cache, table_open_cache, table_open_cache_instances, open_tables, TABLE_OPEN_CACHE_OVERFLOWS, TABLE_OPEN_CACHE_MISSES, + TABLE_OPEN_CACHE_HITS, tmp_table_size, max_heap_table_size, OpenTablesxUptimeDivOpened, join_buffer_size, open_files_limit, innodb_open_files, Created_tmp_files, query_cache_size, query_cache_type, Qcache_hits, + Qcache_inserts, Qcache_not_cached, Innodb_num_open_files, Open_table_definitions, read_rnd_buffer_size, log_output, trx_rseg_history_len) + VALUES (util.VN_NOW(), @uptime, @uptime_since_flush, @SMP_OLD, @SMP_NEW, @SMP, @SMP_RATE, @connections, @Threads_created, @Threads_cached, @Thread_cache_size, @sort_buffer_size, @opened_tables, + @Created_tmp_disk_tables, @created_tmp_tables, @Innodb_os_log_written, @table_definition_cache, @table_open_cache, @table_open_cache_instances, @open_tables, @TABLE_OPEN_CACHE_OVERFLOWS, @TABLE_OPEN_CACHE_MISSES, + @TABLE_OPEN_CACHE_HITS, @tmp_table_size, @max_heap_table_size, @OpenTablesxUptimeDivOpened, @join_buffer_size, @open_files_limit, @innodb_open_files, @Created_tmp_files, @query_cache_size, @query_cache_type, @Qcache_hits, + @Qcache_inserts, @Qcache_not_cached, @Innodb_num_open_files, @Open_table_definitions, @read_rnd_buffer_size, @log_output, @trx_rseg_history_len); + + if (i mod 3 = 0) then + SELECT * FROM sort_merge_results_ernesto order by hora desc limit 20; + End if; + + UNTIL i >= 12 * 24 +END REPEAT; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `splitAnthuriums2016` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `splitAnthuriums2016`() +BEGIN + +DECLARE vStartingDate DATETIME DEFAULT '2016-10-18'; +DECLARE vEndingDate DATETIME DEFAULT '2016-10-31 23:59:00'; +DECLARE vMyTicket INT; +DECLARE vNewTicket INT; +-- DECLARE SILLA_PCA INT DEFAULT 44; +DECLARE done INT DEFAULT 0; + +DECLARE rs CURSOR FOR +SELECT DISTINCT Id_Ticket +FROM Movimientos m +JOIN Tickets t using(Id_Ticket) +JOIN Articles a using(Id_Article) +JOIN Tipos tp using(tipo_id) +WHERE t.Fecha between vStartingDate and vEndingDate +AND warehouse_id = 1 +AND + ( + Id_Tipo = 'ANT' + OR + ( Id_Article = 100 + AND + Concepte LIKE 'ANT%') + ); + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + +OPEN rs; + +FETCH rs INTO vMyTicket; + + + +WHILE NOT done DO + + + INSERT INTO Tickets(Id_Cliente + , warehouse_id + , Fecha + , Alias + , Id_Consigna + , Id_Trabajador + , Id_Ruta + , empresa_id + , Id_Agencia + , landing) + SELECT Id_Cliente + , SILLA_PCA as warehouse_id + , Fecha + , Alias + , Id_Consigna + , Id_Trabajador + , Id_Ruta + , empresa_id + , Id_Agencia + , landing + FROM Tickets + WHERE Id_Ticket = vMyTicket; + + SELECT LAST_INSERT_ID() INTO vNewTicket; + + -- SELECT vMyTicket, vNewTicket; SET done = 1; + UPDATE Movimientos m + JOIN Articles a using(Id_Article) + JOIN Tipos tp using(tipo_id) + SET Id_Ticket = vNewTicket + WHERE Id_Ticket = vMyTicket + AND ( + Id_Tipo = 'ANT' + OR + ( m.Id_Article = 100 + AND + Concepte LIKE 'ANT%') + ); + + FETCH rs INTO vMyTicket; + +END WHILE; + +CLOSE rs; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `subordinate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `subordinate`(IN `vWorker` INT, IN `vBaseCase` BOOLEAN) + NO SQL +BEGIN + -- deprecated usar vn.worker_GetHierarch + DECLARE vAuxWorker INT; + + IF vBaseCase THEN + SET @@max_sp_recursion_depth = 5 ; + DROP TEMPORARY TABLE IF EXISTS subordinate; + CREATE TEMPORARY TABLE subordinate + (INDEX (Id_Trabajador)) + ENGINE = MEMORY + SELECT vWorker Id_Trabajador, TRUE visited, 0 boss; + END IF; + + INSERT INTO subordinate + SELECT Id_Trabajador, FALSE, vWorker + FROM Trabajadores WHERE boss = vWorker; + + IF (SELECT COUNT(*) FROM subordinate WHERE NOT visited AND vWorker = boss LIMIT 1) > 0 THEN + SELECT Id_Trabajador INTO vAuxWorker + FROM subordinate + WHERE NOT visited AND vWorker = boss LIMIT 1; + + REPEAT + CALL subordinate(vAuxWorker, FALSE); + UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = vAuxWorker; + SET vAuxWorker = 0; + + SELECT Id_Trabajador INTO vAuxWorker + FROM subordinate + WHERE NOT visited + AND vWorker = boss + LIMIT 1; + + UNTIL vAuxWorker = 0 + END REPEAT; + END IF; + + IF vWorker = 2 THEN + INSERT INTO subordinate + SET Id_Trabajador = vWorker, visited = TRUE, boss = vWorker; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `suppliersDebt` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `suppliersDebt`() +BEGIN + SELECT abbreviation as Empresa, Proveedor, Euros, divisa, empresa_id, proveedor_id + FROM + ( + SELECT empresa_id, + proveedor_id, + cast(sum(Euros) AS DECIMAL(10,2)) as Euros, + cast(sum(divisa) AS DECIMAL(10,2)) as divisa + FROM + ( + SELECT empresa_id, + proveedor_id, + -1 * cantidad as Euros, + -1 * divisa as divisa + FROM recibida_vencimiento rv + INNER JOIN recibida r ON r.id = rv.recibida_id + WHERE r.fecha > '2014-12-31' + + UNION ALL + + SELECT empresa_id, + id_proveedor, + importe, + divisa + FROM pago + WHERE fecha > '2014-12-31' + ) sub + GROUP BY empresa_id, proveedor_id + ) sub2 + JOIN Proveedores p ON p.Id_Proveedor = sub2.proveedor_id + JOIN empresa e ON e.id = sub2.empresa_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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `supplierStatement` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `supplierStatement`(vSupplierFk INT, vCurrencyFk INT, vCompanyFk INT, vOrderBy VARCHAR(15), vOnlyConciliated BIT) +BEGIN + SET @saldo_eur:= 0; + SET @saldo_div:= 0; +select vOnlyConciliated; + DROP TEMPORARY TABLE IF EXISTS tmp.supplierStatement; + + CREATE TEMPORARY TABLE tmp.supplierStatement ENGINE = MEMORY + SELECT + *, + @saldo_eur:= round(@saldo_eur + IFNULL(Pago_Euros, 0) - IFNULL(Fac_Euros, 0) ,2 ) AS saldo_eur, + @saldo_div:= round(@saldo_div + IFNULL(Pago_Divisas, 0) - IFNULL(Fac_Divisas, 0) ,2 ) AS saldo_div + FROM + (SELECT * FROM + (SELECT + NULL as banco_id, + r.empresa_id, + r.serie, + r.id, + CASE + WHEN vOrderBy = 'issued' THEN r.fecha + WHEN vOrderBy = 'bookEntried' THEN r.bookEntried + WHEN vOrderBy = 'booked' THEN r.dateBooking + WHEN vOrderBy = 'dueDate' THEN rv.fecha + END AS fecha, + CONCAT('S/Fra ', r.sref) sref, + if(r.moneda_id > 1,round(sum(divisa) / sum(cantidad),3),NULL) val_cambio, + CAST(sum(cantidad) as DECIMAL(10,2)) as Fac_Euros, + CAST(sum(divisa) as DECIMAL(10,2)) as Fac_Divisas, + NULL AS Pago_Euros, + NULL AS Pago_Divisas, + r.moneda_id, + r.contabilizada, + Moneda, + NULL as pago_sdc_id, + 'invoiceIn' statementType + FROM + recibida r + JOIN recibida_vencimiento rv on rv.recibida_id = r.id + JOIN Monedas m on m.Id_Moneda = r.moneda_id + WHERE + r.fecha > '2014-12-31' + AND r.proveedor_id = vSupplierFk + AND vCurrencyFk IN (r.moneda_id, 0) + AND vCompanyFk IN (r.empresa_id,0) + AND (vOnlyConciliated = r.contabilizada OR NOT vOnlyConciliated) + GROUP BY rv.id + + UNION ALL + SELECT + p.id_banco, + p.empresa_id, + NULL, + p.id, + CASE + WHEN vOrderBy = 'issued' THEN p.Fecha + WHEN vOrderBy = 'bookEntried' THEN p.Fecha + WHEN vOrderBy = 'booked' THEN p.Fecha + WHEN vOrderBy = 'dueDate' THEN p.dueDated + END AS fecha, + CONCAT(IFNULL(name, ''), IF(pre.concepto <> '', CONCAT(' : ', pre.concepto), '')), + if(p.id_moneda > 1, p.divisa / importe, NULL) tip_cambio, + NULL, + NULL, + p.importe, + p.divisa, + p.id_moneda, + p.conciliado, + Moneda, + NULL as pago_sdc_id, + 'payment' statementType + FROM + pago p + LEFT JOIN Monedas ON Monedas.Id_Moneda = p.id_moneda + LEFT JOIN Bancos ON p.id_banco = Bancos.Id_banco + LEFT JOIN pay_met pm ON p.pay_met_id = pm.id + LEFT JOIN Pagares pre ON pre.pago_id = p.id + WHERE + Fecha > '2014-12-31' + AND p.Id_Proveedor = vSupplierFk + AND vCurrencyFk IN (p.id_moneda,0) + AND vCompanyFk IN (p.empresa_id,0) + AND (vOnlyConciliated = p.conciliado OR NOT vOnlyConciliated) + UNION ALL + SELECT + NULL, + companyFk, + NULL, + se.id, + CASE + WHEN vOrderBy = 'issued' THEN se.dated + WHEN vOrderBy = 'bookEntried' THEN se.dated + WHEN vOrderBy = 'booked' THEN se.dated + WHEN vOrderBy = 'dueDate' THEN se.dueDated + END AS fecha, + se.description, + 1 tip_cambio, + amount, + NULL, + NULL, + NULL, + currencyFk, + isConciliated, + c.`code`, + NULL, + 'expense' statementType + FROM vn.supplierExpense se + JOIN vn.currency c on c.id= se.currencyFk + WHERE se.supplierFk = vSupplierFk + AND vCurrencyFk IN (se.currencyFk,0) + AND vCompanyFk IN (se.companyFk,0) + AND (vOnlyConciliated = se.isConciliated OR NOT vOnlyConciliated) + ) AS SUB + ORDER BY (fecha is null and NOT contabilizada),fecha, IF(vOrderBy = 'dueDate', id, NULL) LIMIT 10000000000000000000) t; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `top_seller` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `top_seller`() +BEGIN + + drop table if exists top_sellers_min; + create temporary table top_sellers_min ENGINE = MEMORY + select a.Id_Article , tip.reino_id as Reino, count(m.Id_Article) as contados + from Movimientos m + inner join Tickets t + on m.Id_Ticket = t.Id_Ticket + inner join Articles a + on a.Id_Article = m.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tip.reino_id + where t.Fecha between timestampadd(day,-7,util.VN_CURDATE()) and util.VN_CURDATE() + group by m.Id_Article; + + drop table if exists top_seller; + create temporary table top_seller ENGINE = MEMORY + select a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 1 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 2 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 3 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 4 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 5 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 7 + order by contados desc + limit 5; + + drop table if exists top_sellers_min; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `Trabuque` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `Trabuque`(IN intIDTICKET BIGINT, IN dblINCREMENTO DOUBLE ) +BEGIN + + + +#Vamos a calcular el porcentaje a incrementar las cantidades de las lineas de movimiento para inflar / desinflar la base final + +DECLARE dblBASE_INICIAL DOUBLE DEFAULT 0; +DECLARE dblBASE_FINAL DOUBLE DEFAULT 0; +DECLARE dblAUMENTO DOUBLE DEFAULT 1; + + +SELECT SUM(Cantidad * Preu * (100 - Descuento) / 100) +INTO dblBASE_INICIAL +FROM Movimientos +WHERE Id_Ticket = intIDTICKET; + +SET dblBASE_FINAL = dblBASE_INICIAL; + + +#Eliminamos lineas a 0 + +DELETE FROM Movimientos WHERE Cantidad = 0 AND Id_Ticket = intIDTICKET; + +# Vamos a ir probando incrementos paulatinos hasta que encontremos el que supera lo pedido, teniendo en cuenta el sentido del incremento + +IF dblINCREMENTO < 0 THEN + + + + WHILE (dblBASE_FINAL > dblBASE_INICIAL + dblINCREMENTO) or (dblAUMENTO < 0 ) DO + + SET dblAUMENTO = dblAUMENTO - 0.01; + + SELECT SUM(IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) * Preu * (100 - Descuento) / 100) + INTO dblBASE_FINAL + FROM Movimientos + WHERE Id_Ticket = intIDTICKET; + + END WHILE; + +ELSE + + WHILE dblBASE_FINAL < dblBASE_INICIAL + dblINCREMENTO DO + + SET dblAUMENTO = dblAUMENTO + 0.01; + + SELECT SUM(IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) * Preu * (100 - Descuento) / 100) + INTO dblBASE_FINAL + FROM Movimientos + WHERE Id_Ticket = intIDTICKET; + + END WHILE; + +END IF; + +UPDATE Movimientos +SET Cantidad = IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) +WHERE Id_Ticket = intIDTICKET; + +SELECT tipoiva + , ROUND(SUM(Cantidad * Preu * (100 - Descuento) / 100),2) as Base + , ROUND(ROUND(SUM(Cantidad * Preu * (100 - Descuento) / 100),2) * iva / 100,2) as Cuota +FROM Movimientos M +INNER JOIN Articles A USING(Id_Article) +INNER JOIN tblIVA USING(tipoiva) +WHERE Id_Ticket = intIDTICKET +GROUP BY tipoiva; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `traslado` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `traslado`(IN i_entrada INTEGER) +BEGIN + DECLARE dateShipment DATE; + DECLARE dateLanding DATE; + DECLARE warehouseShipment INTEGER; + DECLARE warehouseLanding INTEGER; + DECLARE v_calc_visible INTEGER; + DECLARE vInventoryDate DATE; + + SET vInventoryDate := vn.getInventoryDate(); + SELECT shipment, landing, warehouse_id_out, warehouse_id + INTO dateShipment, dateLanding, warehouseShipment, warehouseLanding + FROM travel t JOIN Entradas e ON t.id = e.travel_id + WHERE Id_Entrada = i_entrada; + + CALL vn.rate_getPrices(dateShipment, warehouseLanding); + + -- Traslado en almacen origen + + DROP TEMPORARY TABLE IF EXISTS buy_edi_temp; + CREATE TEMPORARY TABLE buy_edi_temp + (KEY (Id_Article), INDEX(Id_Compra)) ENGINE = MEMORY + SELECT * + FROM (SELECT c.Id_Article, c.Id_Compra + FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) + INNER JOIN travel t ON t.id = e.travel_id + WHERE t.landing BETWEEN vInventoryDate AND dateShipment + AND c.Novincular = FALSE + AND c.Tarifa2 >= 0 + ORDER BY (warehouseShipment = t.warehouse_id) DESC, t.landing DESC + LIMIT 10000000000000000000) t + GROUP BY Id_Article; + + IF dateShipment >= util.VN_CURDATE() THEN + CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseShipment); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + + CREATE TEMPORARY TABLE tmp.item ( + `itemFk` int(10) unsigned NOT NULL, + `visible` int(11) NOT NULL DEFAULT 0, + `available` int(11) NOT NULL DEFAULT 0, + `visibleLanding` int(11) NOT NULL DEFAULT 0, + `availableLanding` int(11) NOT NULL DEFAULT 0, + UNIQUE INDEX i USING HASH (itemFk) + ) ENGINE = MEMORY; + + INSERT INTO tmp.item(itemFk, visible) + SELECT item_id itemFk, visible + FROM `cache`.visible + WHERE calc_id = v_calc_visible + AND visible; + + CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseLanding); + + INSERT INTO tmp.item(itemFk, visibleLanding) + SELECT item_id, `visible` + FROM `cache`.`visible` v + WHERE v.calc_id = v_calc_visible + AND v.`visible` + ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`; + + CALL availableTraslate(warehouseShipment, dateShipment, NULL); + + INSERT INTO tmp.item(itemFk, available) + SELECT a.item_id, a.available + FROM availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE available = a.available; + + CALL availableTraslate(warehouseLanding, dateLanding, warehouseShipment); + + INSERT INTO tmp.item(itemFk, availableLanding) + SELECT a.item_id, a.available + FROM availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE availableLanding = a.available; + ELSE + CALL vn.item_getStock(warehouseShipment, dateShipment, NULL); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item (UNIQUE INDEX i USING HASH (itemFk)) ENGINE = MEMORY + SELECT itemFk, `visible`, available , 0 visibleLanding, 0 availableLanding + FROM tmp.itemList; + + DROP TEMPORARY TABLE tmp.itemList; + END IF; + + CALL vn.buyUltimateFromInterval(warehouseLanding,vInventoryDate, dateLanding); + + DROP TEMPORARY TABLE IF EXISTS Traslados; + CREATE TEMPORARY TABLE Traslados ENGINE = MEMORY + SELECT tp.Id_Tipo AS Tipo, + tp.reino_id, + ar.tipo_id, + ar.Id_Article AS article_id, + ar.Article, + ar.Medida, + ar.Categoria, + ar.Color, + Origen.abreviatura as Origen, + CE.Cantidad, + ar.Tallos, + CAST(AIM.visible AS DECIMAL(10,0)) as vis1, + CAST(AIM.available AS DECIMAL(10,0)) as dis1, + CAST(AIM.visibleLanding AS DECIMAL(10,0)) as vis2, + CAST(AIM.availableLanding AS DECIMAL(10,0)) as dis2, + COALESCE(CE.`grouping`, C.`grouping`) as `grouping`, + COALESCE(CE.Packing, C.Packing) as Packing, + COALESCE(cl.caja, CE.caja, C.caja) as caja, + IFNULL(p.name, P2.Alias) AS Productor, + C.Id_Cubo, + 1 Tinta, + CE.Id_Compra, + CE.Etiquetas, + C.buy_edi_id, + tp.Id_Trabajador, + CB.Volumen, + IFNULL(CB.x,0) x, + IFNULL(CB.y,0) y, + IFNULL(CB.z,0) z, + IFNULL(C.Costefijo,0) Costefijo, + IFNULL(C.Comisionfija,0) Comisionfija, + IFNULL(C.Portefijo,0) Portefijo, + A.m3, + E.comision, + CB.Retornable, + IFNULL(CEB.Valor,CB.Valor) Valor, + r.rate3 t3, r.rate2 t2, tp.promo, + C.`grouping` groupingOrigin, + C.Packing PackingOrigin, + C.Id_Compra CompraOrigin, + CB.costeRetorno, + C.weight + FROM Articles ar + JOIN tmp.item AIM ON AIM.itemFk = ar.Id_Article + LEFT JOIN producer p ON p.producer_id = ar.producer_id + LEFT JOIN Tipos tp ON tp.tipo_id = ar.tipo_id + JOIN vn.itemCategory ic ON ic.id = tp.reino_id + LEFT JOIN Origen ON Origen.id = ar.id_origen + LEFT JOIN buy_edi_temp lb ON lb.Id_Article = ar.Id_Article + LEFT JOIN Compres C ON C.Id_Compra = lb.Id_Compra + LEFT JOIN Cubos CB ON CB.Id_Cubo = C.Id_Cubo + LEFT JOIN Entradas E2 ON E2.Id_Entrada = C.Id_Entrada + LEFT JOIN Proveedores P2 ON P2.Id_Proveedor = E2.Id_Proveedor + LEFT JOIN Entradas E ON E.Id_Entrada = i_entrada + LEFT JOIN travel TR ON TR.id = E.travel_id + LEFT JOIN Agencias A ON A.Id_Agencia = TR.agency_id + LEFT JOIN Compres CE ON CE.Id_Article = ar.Id_Article AND CE.Id_Entrada = i_entrada + LEFT JOIN Cubos CEB ON CEB.Id_Cubo = CE.Id_Cubo + LEFT JOIN tmp.rate r ON TRUE + LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = ar.Id_Article + LEFT JOIN Compres cl ON cl.Id_Compra = bufi.buyFk + WHERE ic.display + AND E.Redada = FALSE + AND (AIM.visible != 0 OR AIM.available != 0) + ORDER BY tipo_id, Article, article_id, Medida, Categoria, Origen; + + CREATE INDEX tindex USING HASH ON Traslados (article_id); + + SELECT t.*, + Cantidad - MOD(Cantidad , `grouping`) as Subcantidad, + MOD(Cantidad , `grouping`) as Soll, + ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) / Packing,0) as cm3, + Costefijo + Comisionfija + Portefijo AS Cost, + @porte := ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) * m3 / 1000000 / Packing ,3) AS Porte, + @comision := ROUND((Costefijo + Comisionfija + Portefijo) * comision / 100 ,3) AS Comision, + ROUND(@embalaje := (costeRetorno + IF(Retornable != 0, 0, Valor)) / packing ,3) AS Embalaje, + @coste := IFNULL((Costefijo + Comisionfija + Portefijo),0) + IFNULL(@embalaje,0) + IFNULL(@porte,0) + IFNULL(@comision,0) AS Coste, + @t3 := ROUND(@coste / ( (100 - t3 - t.promo)/100),2) AS Tarifa3, + ROUND(@t3 * (1 + ((t2 - t3)/100)),2) AS Tarifa2, + 0 selected + FROM Traslados t; + + DROP TEMPORARY TABLE Traslados; + DROP TEMPORARY TABLE tmp.item; + DROP TEMPORARY TABLE buy_edi_temp; + DROP TEMPORARY TABLE tmp.buyUltimateFromInterval; + DROP TEMPORARY TABLE tmp.rate; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `travelDetail` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `travelDetail`() +BEGIN +/** + * Returns the details of the travels that have a departure warehouse in Ecuador or Colombia. + */ + DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; + SELECT IFNULL(CONCAT(" ",Entrada),travel) travelAndEntry, + travel, + Entrada, + IsTravel, + Agencia, + ref, + shipment, + OrigenCajas, + landing, + Destino, + Etiquetas, + Notas_Eva, + kg, + loadedKg, + volumeKg, + loadPriority, + invoiceAmount, + Carguera, + reference + FROM + (SELECT TRUE IsTravel, + tr.id travel, + NULL Entrada, + ag.Agencia, + tr.ref, + tr.shipment, + wo.name OrigenCajas, + tr.landing, + w.name Destino, + SUM(c.Etiquetas) Etiquetas, + NULL Notas_Eva, + tr.kg, + CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg, + CAST( + SUM(vc.aerealVolumetricDensity * + c.Etiquetas * + IF(cb.Volumen, + cb.Volumen, + cb.X * cb.Y * cb.Z + ) / 1000000 + ) AS INT + ) volumeKg, + NULL loadPriority, + NULL invoiceAmount, + pc.Alias Carguera, + NULL reference + FROM travel tr + LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk + LEFT JOIN Entradas e ON e.travel_id = tr.id + LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo + LEFT JOIN Articles a ON a.Id_Article = c.Id_Article + LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id + JOIN warehouse w ON w.id = tr.warehouse_id + JOIN warehouse wo ON wo.id = tr.warehouse_id_out + JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id + JOIN vn.volumeConfig vc + WHERE tr.landing >= vDateFrom + AND (wo.name="Colombia" OR wo.name="Ecuador") + GROUP BY tr.id + UNION ALL + SELECT 0 IsTravel, + e.travel_id travel, + e.Id_Entrada, + p.Proveedor, + e.Referencia, + tr.shipment, + wo.name OrigenCajas, + tr.landing, + w.name Destino, + SUM(Etiquetas) Etiquetas, + e.Notas_Eva, + NULL kg, + CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg, + CAST( + SUM(vc.aerealVolumetricDensity * + c.Etiquetas * + IF(cb.Volumen, + cb.Volumen, + cb.X * cb.Y * cb.Z + ) / 1000000 + ) AS INT + ) volumeKg, + loadPriority, + e.invoiceAmount, + pc.Alias carguera, + e.reference + FROM Entradas e + JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor + JOIN travel tr ON tr.id = e.travel_id + LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk + JOIN warehouse w ON w.id = tr.warehouse_id + JOIN warehouse wo ON wo.id = tr.warehouse_id_out + JOIN vn.volumeConfig vc + WHERE tr.landing >= vDateFrom + AND (wo.name="Colombia" OR wo.name="Ecuador") + GROUP BY e.Id_Entrada + ) sub + ORDER BY landing ASC, + shipment ASC, + travel, + IsTravel DESC, + (loadPriority > 0) DESC, + loadPriority, + Agencia, + Notas_Eva; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `travel_tree_shipment` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_tree_shipment`(v_date DATE, v_consigna INT, v_agency INT, v_warehouse INT) +BEGIN +/** +* DEPRECATED usar vn.agencyHourGetLanded +* + * Devuelve una tabla temporal con el dia de recepcion para v_date. + * + * @param v_date Fecha de preparacion de mercancia + * @param v_consigna Id de consignatario, %NULL para recogida + * @param v_agency Id agencia + * @table travel_tree_shipment Datos de recepción + */ + DROP TEMPORARY TABLE IF EXISTS travel_tree_shipment; + CREATE TEMPORARY TABLE travel_tree_shipment + ENGINE = MEMORY + SELECT v_warehouse warehouse_id, v_envio landing FROM ( + SELECT * FROM ( + SELECT v_warehouse, TIMESTAMPADD(DAY, subtract_day, v_date) v_envio, subtract_day, ah.max_hour + FROM agency_hour ah + LEFT JOIN Consignatarios c ON c.Id_Consigna = v_consigna + WHERE (week_day = weekday(TIMESTAMPADD(DAY, subtract_day, v_date)) OR week_day IS NULL) + AND (ah.agency_id = v_agency OR ah.agency_id IS NULL) + AND ah.warehouse_id = v_warehouse + AND (ah.province_id = c.province_id OR ah.province_id IS NULL OR v_consigna IS NULL) + ORDER BY ( + (ah.week_day IS NOT NULL) + + (ah.agency_id IS NOT NULL) + + (- ah.subtract_day) + + ((ah.province_id IS NOT NULL)*3) + ) DESC + ) t + LIMIT 1 + ) t + WHERE IF(v_date = util.VN_CURDATE(), max_hour > HOUR(util.VN_NOW()), TRUE) AND subtract_day < 225; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_delete` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_delete`(v_node INT, v_delete bool) +BEGIN +/** + * Borra un nodo. Se puede indicar si se quieren mantener los hijos. + * En este caso los hijos pasan al padre del nodo. + * Si no tiene padre, los hijos pasaran a ser padres. + * + * @v_node: Nodo que se quiere borrar. + * @v_delete: Se indica si se borran los nodos. + **/ + + DECLARE v_parent INT; + + SELECT parent + INTO v_parent + FROM unary + WHERE id = v_node; + + IF(v_delete = FALSE) THEN + UPDATE unary + SET parent = v_parent + WHERE parent = v_node; + END IF; + + DELETE FROM unary + WHERE id = v_node; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_insert` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_insert`(OUT v_unary INT, v_parent INT) +BEGIN + + /** + * Inserta un nuevo nodo. Se puede indicar el padre. + * + * @v_parent: Nodo padre. + * @v_unary: Id del nuevo nodo. + **/ + + INSERT INTO unary(parent) VALUES(v_parent); + + SELECT last_insert_id() INTO v_unary; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_leaves` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_leaves`(v_top INT) +BEGIN +/** + * A partir de un nodo devuelve todos sus descendientes. + * + * @table tmp.tree Tabla con los ids de los nodos descendientes; + **/ + DECLARE v_count INT; + DECLARE v_parent INT; + DECLARE v_depth INT DEFAULT 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.tree; + CREATE TEMPORARY TABLE tmp.tree + (INDEX (id)) + ENGINE = MEMORY + SELECT v_top id, v_parent parent, v_depth depth; + + DROP TEMPORARY TABLE IF EXISTS tmp.parent; + CREATE TEMPORARY TABLE tmp.parent + ENGINE = MEMORY + SELECT v_top id; + + l: LOOP + + SET v_depth = v_depth + 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.child; + CREATE TEMPORARY TABLE tmp.child + ENGINE = MEMORY + SELECT c.`id`, c.parent + FROM `unary` c + JOIN tmp.parent p ON c.`parent` = p.id; + + DROP TEMPORARY TABLE tmp.parent; + CREATE TEMPORARY TABLE tmp.parent + ENGINE = MEMORY + SELECT c.id, c.parent + FROM tmp.child c + LEFT JOIN tmp.tree t ON t.id = c.id + WHERE t.id IS NULL; + + INSERT INTO tmp.tree + SELECT id, parent, v_depth FROM tmp.parent; + + SELECT COUNT(*) INTO v_count + FROM tmp.parent; + + IF v_count = 0 THEN + LEAVE l; + END IF; + END LOOP; + + DROP TEMPORARY TABLE + tmp.parent, + tmp.child; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_scan_ident` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_scan_ident`(v_top INT, v_space INT) +BEGIN +/** + * A partir de un nodo devuelve el id y el nombre del nodod y sus hijos. + * El nombre viene identado segun el numero de espacios multiplicado por la profundiad del nodo. + * + * v_top: Id del nodo padre. + * v_space: Spacios a dejar al identar, + * @table tmp.tree_ident Tabla con los ids de los nodos descendientes y su nombre identado; + **/ + + DROP TEMPORARY TABLE IF EXISTS tmp.tree_ident; + CALL tree_leaves(v_top); + + CREATE TEMPORARY TABLE tmp.tree_ident + ENGINE = MEMORY + SELECT t.id, + CONCAT( REPEAT(REPEAT(" ",v_space), t.depth), sp.name) AS name + FROM tmp.tree t + INNER JOIN unary_scan sp + ON t.id = sp.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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_scan_insert` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_scan_insert`(v_name VARCHAR(45), v_parent INT, v_type VARCHAR(45)) +BEGIN + + /** + * Inserta un nuevo nodo de tipo unary_scan. Se puede indicar el padre. + * + * @v_name: Nombre del nodo. + * @v_parent: Nodo padre. + * @v_type: Tipo del nodo a crear. + **/ + + DECLARE v_unary INT; + + CALL unary_insert(v_unary, v_parent); + + INSERT INTO unary_scan(name, unary_id, type) VALUES(v_name, v_unary, v_type); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_tops` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_tops`() +BEGIN +/** + * Devuelve todos los nodos que no tienen padre. + * + * @table tmp.tree Tabla con los ids de los nodos que no tienen padre; + **/ + + DROP TEMPORARY TABLE IF EXISTS tmp.tree; + CREATE TEMPORARY TABLE tmp.tree + ENGINE = MEMORY + SELECT s.`unary_id` AS id, s.name, s.odbc_date, s.type + FROM `unary_scan` s + INNER JOIN `unary` u ON s.unary_id = u.id + WHERE u.parent IS 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `unary_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_unicode_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `unary_update`(v_node INT, v_new_parent INT, v_move bool) +BEGIN +/** + * Cambia el padre de un nodo. Se puede indicar si se quieren mover los hijos. + * En este caso los hijos pasan al padre del nodo. + * Si no tiene padre, los hijos pasaran a ser padres. + * + * @v_node: Nodo que se quiere mover. + * @v_new_parent: Padre al que se quiere mover el nodo. + * @v_move: Se indica si se mueven los nodos. + **/ + + DECLARE v_parent INT; + + SELECT parent + INTO v_parent + FROM unary + WHERE id = v_node; + + IF(v_move = TRUE) THEN + UPDATE unary + SET parent = v_parent + WHERE parent = v_node; + END IF; + + UPDATE unary + SET parent = v_new_parent + WHERE id = v_node; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `Vehiculos_consumo_calculateLiters100km` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `Vehiculos_consumo_calculateLiters100km`() +BEGIN + DECLARE vConsumptionVehicleId INT; + DECLARE vDone BOOL; + DECLARE vOldKm INT; + DECLARE vOldLiters INT; + DECLARE vNewKm INT; + DECLARE vVehicleId INT; + + DECLARE cur CURSOR FOR + SELECT Vehiculos_consumo_id, Id_Vehiculo, km FROM vn2008.Vehiculos_consumo; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vConsumptionVehicleId, vVehicleId, vNewKm; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT km, litros INTO vOldKm, vOldLiters + FROM Vehiculos_consumo + WHERE Id_Vehiculo = vVehicleId + AND Vehiculos_consumo_id < vConsumptionVehicleId + ORDER BY Vehiculos_consumo_id DESC + LIMIT 1; + + UPDATE Vehiculos_consumo + SET liters100km = vOldLiters/((vNewKm-vOldKm)*0.01) + WHERE Vehiculos_consumo_id = vConsumptionVehicleId; + + END LOOP; + + CLOSE cur; + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `XDiario_Quadrator` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `XDiario_Quadrator`() +BEGIN + INSERT INTO vn.mail (receiver, subject, body) + SELECT 'cau@verdnatura.es', + 'asientos descuadrados', + group_concat(CONCAT(' Asiento: ', ASIEN, '- importe:', quadre) SEPARATOR ' \r\n ') + FROM ( + SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) quadre + FROM XDiario + WHERE enlazado = FALSE + GROUP BY ASIEN + HAVING ABS(SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0))) > 0.01 + ) t + HAVING count(*) > 0; + + UPDATE XDiario XD + INNER JOIN( + SELECT XD.id, SUBCTA, Quadre FROM XDiario XD + INNER JOIN ( + SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) as Quadre + FROM XDiario + WHERE enlazado = FALSE + GROUP BY ASIEN + HAVING Quadre != 0 + ) sub USING(ASIEN) + WHERE SUBCTA > '5999999999' + GROUP BY ASIEN + ) sub2 USING(id) + SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre), + Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre); + +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 */ ; + -- -- Current Database: `account` -- @@ -80459,12 +91168,252 @@ USE `account`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Current Database: `bi` +-- + +USE `bi`; + +-- +-- Final view structure for view `analisis_grafico_ventas` +-- + +/*!50001 DROP VIEW IF EXISTS `analisis_grafico_ventas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `analisis_grafico_ventas` AS select `analisis_ventas`.`Año` AS `Año`,`analisis_ventas`.`Semana` AS `Semana`,sum(`analisis_ventas`.`Importe`) AS `Importe` from `analisis_ventas` group by `analisis_ventas`.`Año`,`analisis_ventas`.`Semana` */; +/*!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 `analisis_ventas_simple` +-- + +/*!50001 DROP VIEW IF EXISTS `analisis_ventas_simple`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `analisis_ventas_simple` AS select `analisis_ventas`.`Año` AS `Año`,`analisis_ventas`.`Semana` AS `Semana`,sum(`analisis_ventas`.`Importe`) AS `Importe` from `analisis_ventas` group by `analisis_ventas`.`Año`,`analisis_ventas`.`Semana` */; +/*!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 `claims_ratio` +-- + +/*!50001 DROP VIEW IF EXISTS `claims_ratio`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `claims_ratio` AS select `cr`.`clientFk` AS `Id_Cliente`,`cr`.`yearSale` AS `Consumo`,`cr`.`claimAmount` AS `Reclamaciones`,`cr`.`claimingRate` AS `Ratio`,`cr`.`priceIncreasing` AS `recobro`,`cr`.`packingRate` AS `inflacion` from `vn`.`claimRatio` `cr` */; +/*!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 `customerRiskOverdue` +-- + +/*!50001 DROP VIEW IF EXISTS `customerRiskOverdue`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `customerRiskOverdue` AS select `cr`.`clientFk` AS `customer_id`,`cr`.`amount` AS `amount`,`cr`.`companyFk` AS `company_id` from (((`vn`.`clientRisk` `cr` join `vn`.`company` `co` on(`co`.`id` = `cr`.`companyFk`)) join `vn`.`client` `c` on(`cr`.`clientFk` = `c`.`id`)) join `vn`.`payMethod` `pm` on(`pm`.`id` = `c`.`payMethodFk`)) where `cr`.`amount` <> 0 and `co`.`isDefaulter` <> 0 and `pm`.`outstandingDebt` <> 0 and `c`.`typeFk` = 'normal' union all select `i`.`clientFk` AS `Id_Cliente`,-round(`i`.`amount`,2) AS `importe`,`i`.`companyFk` AS `empresa_id` from (((`vn`.`invoiceOut` `i` join `vn`.`client` `c` on(`i`.`clientFk` = `c`.`id`)) join `vn`.`company` `co` on(`co`.`id` = `i`.`companyFk`)) join `vn`.`payMethod` `pm` on(`pm`.`id` = `c`.`payMethodFk`)) where `i`.`issued` > `util`.`VN_CURDATE`() + interval -101 day and `i`.`dued` + interval `pm`.`graceDays` day > `util`.`VN_CURDATE`() and `i`.`amount` > 0 and `co`.`isDefaulter` <> 0 and `pm`.`outstandingDebt` <> 0 and `c`.`typeFk` = 'normal' */; +/*!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 `defaulters` +-- + +/*!50001 DROP VIEW IF EXISTS `defaulters`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `defaulters` AS select `d`.`clientFk` AS `client`,`d`.`created` AS `date`,`d`.`amount` AS `amount`,`d`.`defaulterSinced` AS `defaulterSince`,`d`.`hasChanged` AS `hasChanged`,`d`.`frozened` AS `frozened` from `bs`.`defaulter` `d` */; +/*!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 `facturacion_media_anual` +-- + +/*!50001 DROP VIEW IF EXISTS `facturacion_media_anual`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `facturacion_media_anual` AS select `cac`.`clientFk` AS `Id_Cliente`,`cac`.`invoiced` AS `Consumo` from `bs`.`clientAnnualConsumption` `cac` */; +/*!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 `last_Id_Cubo` +-- + +/*!50001 DROP VIEW IF EXISTS `last_Id_Cubo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `last_Id_Cubo` AS select `C`.`Id_Compra` AS `Id_Compra`,`C`.`Id_Article` AS `Id_Article`,`tr`.`warehouse_id` AS `warehouse_id`,`C`.`Id_Cubo` AS `Id_Cubo`,`C`.`Packing` AS `Packing` from ((`vn2008`.`Compres` `C` join `vn2008`.`Entradas` `E` on(`C`.`Id_Entrada` = `E`.`Id_Entrada`)) join `vn2008`.`travel` `tr` on(`E`.`travel_id` = `tr`.`id`)) where `C`.`Id_Cubo` is not null and `C`.`Id_Cubo` <> '--' and `tr`.`landing` > `util`.`VN_CURDATE`() - interval 18 month order by `C`.`Id_Compra` desc */; +/*!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 `rotacion` +-- + +/*!50001 DROP VIEW IF EXISTS `rotacion`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `rotacion` AS select `ic`.`itemFk` AS `Id_Article`,`ic`.`warehouseFk` AS `warehouse_id`,`ic`.`quantity` AS `total`,`ic`.`rotation` AS `rotacion`,`ic`.`cm3` AS `cm3`,`ic`.`storage` AS `almacenaje`,`ic`.`handling` AS `manipulacion`,`ic`.`extraCharge` AS `auxiliar`,`ic`.`wasted` AS `mermas`,`ic`.`cm3delivery` AS `cm3reparto`,`ic`.`grams` AS `grams` from `vn`.`itemCost` `ic` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `tarifa_componentes` +-- + +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tarifa_componentes` AS select `c`.`id` AS `Id_Componente`,`c`.`name` AS `Componente`,`c`.`typeFk` AS `tarifa_componentes_series_id`,`c`.`classRate` AS `tarifa_class`,`c`.`tax` AS `tax`,`c`.`isRenewable` AS `is_renewable`,`c`.`code` AS `code` from `vn`.`component` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `tarifa_componentes_series` +-- + +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tarifa_componentes_series` AS select `ct`.`id` AS `tarifa_componentes_series_id`,`ct`.`type` AS `Serie`,`ct`.`isBase` AS `base`,`ct`.`isMargin` AS `margen` from `vn`.`componentType` `ct` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `v_clientes_jerarquia` +-- + +/*!50001 DROP VIEW IF EXISTS `v_clientes_jerarquia`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_clientes_jerarquia` AS select `c`.`id_cliente` AS `Id_Cliente`,`c`.`cliente` AS `Cliente`,`t`.`CodigoTrabajador` AS `Comercial`,`tj`.`CodigoTrabajador` AS `Jefe` from (((`vn2008`.`Clientes` `c` join `vn2008`.`Trabajadores` `t` on(`t`.`Id_Trabajador` = `c`.`Id_Trabajador`)) join `vn2008`.`jerarquia` on(`vn2008`.`jerarquia`.`worker_id` = `c`.`Id_Trabajador`)) join `vn2008`.`Trabajadores` `tj` on(`tj`.`Id_Trabajador` = `vn2008`.`jerarquia`.`boss_id`)) */; +/*!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 `v_ventas_contables` +-- + +/*!50001 DROP VIEW IF EXISTS `v_ventas_contables`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_ventas_contables` AS select `time`.`year` AS `year`,`time`.`month` AS `month`,cast(sum(`m`.`Cantidad` * `m`.`Preu` * (100 - `m`.`Descuento`) / 100) as decimal(10,0)) AS `importe` from (((`vn2008`.`Tickets` `t` join `bi`.`f_tvc` on(`t`.`Id_Ticket` = `bi`.`f_tvc`.`Id_Ticket`)) join `vn2008`.`Movimientos` `m` on(`t`.`Id_Ticket` = `m`.`Id_Ticket`)) join `vn2008`.`time` on(`time`.`date` = cast(`t`.`Fecha` as date))) where `t`.`Fecha` >= '2014-01-01' group by `time`.`year`,`time`.`month` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Current Database: `bs` -- USE `bs`; +-- +-- Final view structure for view `VentasPorCliente` +-- + +/*!50001 DROP VIEW IF EXISTS `VentasPorCliente`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `VentasPorCliente` AS select `v`.`Id_Cliente` AS `Id_Cliente`,round(sum(`v`.`importe`),0) AS `VentaBasica`,`t`.`year` AS `year`,`t`.`month` AS `month` from (`vn2008`.`time` `t` join `bs`.`ventas` `v` on(`v`.`fecha` = `t`.`date`)) group by `v`.`Id_Cliente`,`t`.`year`,`t`.`month` */; +/*!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 `bajasLaborales` -- @@ -80483,6 +91432,24 @@ USE `bs`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `horasSilla` +-- + +/*!50001 DROP VIEW IF EXISTS `horasSilla`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `horasSilla` AS select `wj`.`dated` AS `Fecha`,`d`.`name` AS `Departamento`,cast(sum(`wj`.`total`) as decimal(10,2)) AS `Horas`,cast(sum((`wj`.`total` + `wj`.`lunch`) * `wj`.`priceOrdinaryHour`) as decimal(10,2)) AS `Salarios` from ((`vn`.`workerJourney` `wj` join `vn`.`business` `b` on(`b`.`id` = `wj`.`businessFk`)) join `vn`.`department` `d` on(`d`.`id` = `b`.`departmentFk`)) where `d`.`name` in ('CAMARA','ENCAJADO','PALETIZADORES','PRODUCCION','SACADORES') group by `wj`.`dated`,`d`.`name` */; +/*!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 `lastIndicators` -- @@ -80579,6 +91546,30 @@ USE `bs`; USE `cache`; +-- +-- Current Database: `dipole` +-- + +USE `dipole`; + +-- +-- Final view structure for view `expeditionControl` +-- + +/*!50001 DROP VIEW IF EXISTS `expeditionControl`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `expeditionControl` AS select cast(`epo`.`created` as date) AS `fecha`,count(0) AS `total`,count(`er`.`expeditionFk`) AS `leidas` from (`expedition_PrintOut` `epo` left join `expedition_Read` `er` on(`er`.`expeditionFk` = `epo`.`expeditionFk`)) group by cast(`epo`.`created` as date) */; +/*!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: `edi` -- @@ -81089,6 +92080,54 @@ USE `pbx`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Current Database: `psico` +-- + +USE `psico`; + +-- +-- Final view structure for view `examView` +-- + +/*!50001 DROP VIEW IF EXISTS `examView`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `examView` AS select `q`.`text` AS `text`,`eq`.`examFk` AS `examFk`,`eq`.`questionFk` AS `questionFk`,`eq`.`answerFk` AS `answerFk`,`eq`.`id` AS `id` from (`question` `q` join `examQuestion` `eq` on(`q`.`id` = `eq`.`questionFk`)) */; +/*!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 `results` +-- + +/*!50001 DROP VIEW IF EXISTS `results`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `results` AS select `eq`.`examFk` AS `examFk`,sum(`a`.`correct` * `a`.`correct`) AS `aciertos`,`e`.`questionsCount` AS `questionsCount`,hour(timediff(`e`.`finished`,`e`.`started`)) * 60 + minute(timediff(`e`.`finished`,`e`.`started`)) AS `minutos`,least(3,3 * (`e`.`questionsCount` * 0.5) / (hour(timediff(`e`.`finished`,`e`.`started`)) * 60 + minute(timediff(`e`.`finished`,`e`.`started`)))) + 7 * sum(`a`.`correct` * `a`.`correct`) / `e`.`questionsCount` AS `nota` from ((`exam` `e` join `examQuestion` `eq` on(`eq`.`examFk` = `e`.`id`)) join `answer` `a` on(`eq`.`answerFk` = `a`.`id`)) group by `eq`.`examFk`,`e`.`questionsCount` */; +/*!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: `rfid` +-- + +USE `rfid`; + -- -- Current Database: `sage` -- @@ -81209,12 +92248,168 @@ USE `salix`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Current Database: `srt` +-- + +USE `srt`; + +-- +-- Final view structure for view `bufferDayMinute` +-- + +/*!50001 DROP VIEW IF EXISTS `bufferDayMinute`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `bufferDayMinute` AS select `b`.`id` AS `bufferFk`,`e`.`id` AS `expeditionFk`,`srt`.`dayMinute`(ifnull(`et`.`eta`,`z`.`hour`)) AS `dayMinute`,`e`.`position` AS `position`,ifnull(`et`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) minute) AS `ETD`,`e2`.`ticketFk` AS `ticketFk`,ifnull(`t`.`routeFk`,`t`.`agencyModeFk`) AS `routeFk`,`z`.`name` AS `zonaTicket`,`es`.`description` AS `expeditionState` from ((((((((`srt`.`buffer` `b` left join `srt`.`expedition` `e` on(`b`.`id` = `e`.`bufferFk`)) left join `srt`.`expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `srt`.`bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) left join `vn`.`expedition` `e2` on(`e2`.`id` = `e`.`id`)) left join `vn`.`ticket` `t` on(`e2`.`ticketFk` = `t`.`id`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`expeditionTruck` `et` on(`rm`.`expeditionTruckFk` = `et`.`id`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) where `b`.`isActive` <> 0 */; +/*!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 `bufferFreeLength` +-- + +/*!50001 DROP VIEW IF EXISTS `bufferFreeLength`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `bufferFreeLength` AS select cast(`b`.`id` as decimal(10,0)) AS `bufferFk`,`b`.`code` AS `bufferName`,cast(`b`.`length` - sum(ifnull(`e`.`length`,900) + 500) as decimal(10,0)) AS `freeLength`,cast(sum(ifnull(`e`.`length`,900) + 500) as decimal(10,0)) AS `saturacion`,`bs`.`description` AS `state`,`b`.`stateFk` AS `stateFk`,`b`.`typeFk` AS `typeFk`,`bt`.`typeName` AS `typeName`,count(`e`.`id`) AS `stock`,cast(`b`.`length` - sum(if(`es`.`description` = 'STORED',`e`.`length` + 500,0)) as decimal(10,0)) AS `RealFreeLength` from ((((`buffer` `b` left join `expedition` `e` on(`e`.`bufferFk` = `b`.`id`)) left join `expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) join `bufferState` `bs` on(`bs`.`id` = `b`.`stateFk`)) group by `b`.`id` */; +/*!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 `bufferStock` +-- + +/*!50001 DROP VIEW IF EXISTS `bufferStock`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `bufferStock` AS select `e`.`id` AS `expeditionFk`,`e`.`bufferFk` AS `bufferFk`,`e`.`position` AS `position`,`srt`.`dayMinute`(ifnull(`et`.`eta`,`z`.`hour`)) AS `dayMinute`,ifnull(`et`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) + 120 minute) AS `eta`,`ve`.`ticketFk` AS `ticketFk`,ifnull(`t`.`routeFk`,`t`.`agencyModeFk`) AS `routeFk`,`z`.`name` AS `zonaTicket`,`et`.`description` AS `truck`,`es`.`description` AS `expeditionState`,`b`.`hasWorkerWaiting` AS `hasWorkerWaiting`,`b`.`isActive` AS `isActive`,if(`et`.`id` is null,`c`.`bufferDefault`,`et`.`bufferFk`) AS `bufferTruck`,`bt`.`typeName` AS `typeName`,`rm`.`bufferFk` AS `routeBuffer` from (((((((((`srt`.`expedition` `e` left join `vn`.`expedition` `ve` on(`ve`.`id` = `e`.`id`)) join `srt`.`expeditionState` `es` on(`es`.`id` = `e`.`stateFk`)) join `srt`.`buffer` `b` on(`b`.`id` = `e`.`bufferFk`)) left join `vn`.`ticket` `t` on(`t`.`id` = `ve`.`ticketFk`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`expeditionTruck` `et` on(`rm`.`expeditionTruckFk` = `et`.`id`)) join `srt`.`config` `c`) join `srt`.`bufferType` `bt` on(`bt`.`id` = `b`.`typeFk`)) where `bt`.`typeName` <> 'DISABLED' */; +/*!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 `expeditionVolume` +-- + +/*!50001 DROP VIEW IF EXISTS `expeditionVolume`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`juan`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `expeditionVolume` AS select `bs`.`dayMinute` AS `dayMinute`,`bs`.`eta` AS `ETD`,count(0) AS `cajas`,`bs`.`eta` + interval -`c`.`minutesBeforeTruckDeparture` minute < `util`.`VN_NOW`() or count(0) >= `c`.`minBoxesToUnloading` AS `isReady`,`bs`.`truck` AS `truck`,`bs`.`zonaTicket` AS `zonaTicket`,`bs`.`bufferTruck` AS `bufferTruck` from (`srt`.`bufferStock` `bs` join `srt`.`config` `c`) where `bs`.`expeditionState` = 'STORED' and `bs`.`isActive` <> 0 and `bs`.`hasWorkerWaiting` = 0 and `bs`.`typeName` = 'ACCUMULATION' group by `bs`.`dayMinute` */; +/*!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 `routePalletized` +-- + +/*!50001 DROP VIEW IF EXISTS `routePalletized`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `routePalletized` AS select `t`.`routeFk` AS `routeFk`,count(distinct `e`.`id`) AS `expediciones`,sum(`es`.`description` <=> 'OUT' or `esc`.`expeditionFk` is not null) AS `paletizadas` from ((((((`vn`.`ticket` `t` left join `vn`.`expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) left join `srt`.`expedition` `e2` on(`e2`.`id` = `e`.`id`)) left join `srt`.`expeditionState` `es` on(`es`.`id` = `e2`.`stateFk`)) left join `vn`.`expeditionScan` `esc` on(`esc`.`expeditionFk` = `e`.`id`)) join `vn`.`ticketCollection` `tc` on(`tc`.`ticketFk` = `t`.`id`)) join `vn`.`collection` `c` on(`c`.`id` = `tc`.`collectionFk`)) where `t`.`shipped` between `util`.`yesterday`() and `util`.`tomorrow`() and `c`.`itemPackingTypeFk` = 'H' group by `t`.`routeFk` */; +/*!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 `routeVolume` +-- + +/*!50001 DROP VIEW IF EXISTS `routeVolume`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`juan`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `routeVolume` AS select `bs`.`dayMinute` AS `dayMinute`,`bs`.`eta` AS `ETD`,count(0) AS `cajas`,`bs`.`eta` + interval -`c`.`minutesBeforeTruckDeparture` minute < `util`.`VN_NOW`() or count(0) >= `c`.`minBoxesToUnloading` AS `isReady`,`bs`.`routeFk` AS `routeFk`,`bs`.`zonaTicket` AS `zonaTicket`,`bs`.`bufferTruck` AS `bufferTruck`,`bs`.`routeBuffer` AS `routeBuffer` from (`srt`.`bufferStock` `bs` join `srt`.`config` `c`) where `bs`.`expeditionState` = 'STORED' and `bs`.`isActive` <> 0 and `bs`.`hasWorkerWaiting` = 0 group by `bs`.`routeFk` */; +/*!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 `ticketPalletized` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketPalletized`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketPalletized` AS select `t`.`id` AS `ticketFk`,`t`.`routeFk` AS `routeFk`,count(distinct `e`.`id`) AS `expediciones`,sum(`es`.`description` <=> 'OUT' or `esc`.`expeditionFk` is not null) AS `paletizadas` from ((((((`vn`.`ticket` `t` left join `vn`.`expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) left join `srt`.`expedition` `e2` on(`e2`.`id` = `e`.`id`)) left join `srt`.`expeditionState` `es` on(`es`.`id` = `e2`.`stateFk`)) left join `vn`.`expeditionScan` `esc` on(`esc`.`expeditionFk` = `e`.`id`)) join `vn`.`ticketCollection` `tc` on(`tc`.`ticketFk` = `t`.`id`)) join `vn`.`collection` `c` on(`c`.`id` = `tc`.`collectionFk`)) where `t`.`shipped` between `util`.`yesterday`() and `util`.`tomorrow`() and `c`.`itemPackingTypeFk` = 'H' group by `t`.`id` */; +/*!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 `upperStickers` +-- + +/*!50001 DROP VIEW IF EXISTS `upperStickers`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `upperStickers` AS select `e`.`id` AS `expeditionFk`,`e`.`id` MOD 10000 AS `expedition`,ifnull(`et`.`eta`,`util`.`VN_CURDATE`() + interval `srt`.`dayMinute`(`z`.`hour`) + 120 minute) AS `ETD`,`ve`.`ticketFk` AS `ticketFk`,right(ifnull(`t`.`routeFk`,`t`.`agencyModeFk`),3) AS `routeFk`,`z`.`name` AS `zonaTicket`,`et`.`description` AS `truck`,`epo`.`workerCode` AS `worker`,`p`.`name` AS `labeler`,`ve`.`counter` AS `expeditionCounter`,`vn`.`ticketTotalVolume`(`t`.`id`) AS `m3`,`t`.`clientFk` AS `clientFk` from (((((((`srt`.`expedition` `e` left join `vn`.`expedition` `ve` on(`ve`.`id` = `e`.`id`)) left join `vn`.`ticket` `t` on(`t`.`id` = `ve`.`ticketFk`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`routesMonitor` `rm` on(`t`.`routeFk` = `rm`.`routeFk`)) left join `vn`.`expeditionTruck` `et` on(`rm`.`expeditionTruckFk` = `et`.`id`)) join `dipole`.`expedition_PrintOut` `epo` on(`epo`.`expeditionFk` = `e`.`id`)) join `vn`.`printer` `p` on(`p`.`id` = `epo`.`printerFk`)) */; +/*!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: `stock` -- USE `stock`; +-- +-- Current Database: `tmp` +-- + +USE `tmp`; + -- -- Current Database: `util` -- @@ -81299,6 +92494,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `agencyWarehouse` +-- + +/*!50001 DROP VIEW IF EXISTS `agencyWarehouse`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `agencyWarehouse` AS select `a`.`agency_id` AS `agencyFk`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`Vista` AS `agencyType` from `vn2008`.`agency_warehouse` `a` */; +/*!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 `annualAverageInvoiced` -- @@ -81425,6 +92638,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `clientDefaultCompany` +-- + +/*!50001 DROP VIEW IF EXISTS `clientDefaultCompany`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `clientDefaultCompany` AS select `t`.`Id_Clientes_empresa` AS `id`,`t`.`Id_Cliente` AS `clientFk`,`t`.`empresa_id` AS `companyFk`,`t`.`fecha_ini` AS `started`,`t`.`fecha_fin` AS `finished` from `vn2008`.`Clientes_empresa` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `clientLost` -- @@ -81479,6 +92710,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `coolerPath` +-- + +/*!50001 DROP VIEW IF EXISTS `coolerPath`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `coolerPath` AS select `c`.`cooler_path_id` AS `id`,`c`.`description` AS `description` from `vn2008`.`cooler_path` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `defaulter` -- @@ -81515,6 +92764,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `doc` +-- + +/*!50001 DROP VIEW IF EXISTS `doc`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `doc` AS select `g`.`id` AS `id`,`g`.`sref` AS `sref`,`g`.`brief` AS `brief`,`g`.`emp_id` AS `companyFk`,`g`.`orden` AS `order`,`g`.`file` AS `file`,`g`.`original` AS `original`,`g`.`trabajador_id` AS `workerFk`,`g`.`odbc_date` AS `created`,`g`.`warehouse_id` AS `warehouseFk` 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 `ediGenus` -- @@ -81569,6 +92836,42 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `especialPrice` +-- + +/*!50001 DROP VIEW IF EXISTS `especialPrice`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `especialPrice` AS select `p`.`Id_PrecioEspecial` AS `id`,`p`.`Id_Cliente` AS `clientFk`,`p`.`Id_Article` AS `itemFk`,`p`.`PrecioEspecial` AS `value` from `vn2008`.`PreciosEspeciales` `p` */; +/*!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 `exchangeInsurance` +-- + +/*!50001 DROP VIEW IF EXISTS `exchangeInsurance`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `exchangeInsurance` AS select `vn2008`.`pago_sdc`.`pago_sdc_id` AS `id`,`vn2008`.`pago_sdc`.`importe` AS `amount`,`vn2008`.`pago_sdc`.`fecha` AS `dated`,`vn2008`.`pago_sdc`.`vencimiento` AS `finished`,`vn2008`.`pago_sdc`.`entity_id` AS `entityFk`,`vn2008`.`pago_sdc`.`ref` AS `ref`,`vn2008`.`pago_sdc`.`rate` AS `rate`,`vn2008`.`pago_sdc`.`empresa_id` AS `companyFk`,`vn2008`.`pago_sdc`.`financialProductTypefk` AS `financialProductTypefk`,`vn2008`.`pago_sdc`.`upperBarrier` AS `upperBarrier`,`vn2008`.`pago_sdc`.`lowerBarrier` AS `lowerBarrier`,`vn2008`.`pago_sdc`.`strike` AS `strike` from `vn2008`.`pago_sdc` */; +/*!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 `exchangeInsuranceEntry` -- @@ -81605,6 +92908,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `exchangeInsuranceInPrevious` +-- + +/*!50001 DROP VIEW IF EXISTS `exchangeInsuranceInPrevious`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `exchangeInsuranceInPrevious` AS select `ei`.`finished` AS `dated`,`ei`.`amount` AS `amount`,`ei`.`rate` AS `rate` from `vn`.`exchangeInsurance` `ei` where `ei`.`amount` <> 0 and `ei`.`financialProductTypefk` = 'SC' */; +/*!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 `exchangeInsuranceOut` -- @@ -81623,6 +92944,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `exchangeReportSource` +-- + +/*!50001 DROP VIEW IF EXISTS `exchangeReportSource`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `exchangeReportSource` AS select `e`.`dated` AS `dated`,cast(sum(`e`.`amountIn`) as decimal(10,2)) AS `amountIn`,cast(sum(`e`.`rateIn`) as decimal(10,4)) AS `rateIn`,cast(sum(`e`.`amountOut`) as decimal(10,2)) AS `amountOut`,cast(sum(`e`.`rateOut`) as decimal(10,4)) AS `rateOut`,cast(sum(`e`.`amountEntry`) as decimal(10,2)) AS `amountEntry`,cast(sum(`e`.`rateEntry`) as decimal(10,4)) AS `rateEntry`,cast(ifnull(`rr`.`value`,`rrc`.`simulatedValue`) as decimal(10,4)) AS `rateECB` from ((`vn`.`exchangeReportSourcePrevious` `e` left join `vn`.`referenceRate` `rr` on(`rr`.`dated` = `e`.`dated`)) join `vn`.`referenceRateConfig` `rrc` on(1)) group by `e`.`dated` order by `e`.`dated` */; +/*!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 `exchangeReportSourcePrevious` -- @@ -81875,6 +93214,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `grantGroup` +-- + +/*!50001 DROP VIEW IF EXISTS `grantGroup`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `grantGroup` AS select `vn2008`.`Grupos`.`id` AS `id`,`vn2008`.`Grupos`.`Grupo` AS `description`,`vn2008`.`Grupos`.`observation_type_id` AS `observationTypeFk` from `vn2008`.`Grupos` */; +/*!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 `inkL10n` -- @@ -82199,24 +93556,6 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `itemShelvingStock_byWarehouse` --- - -/*!50001 DROP VIEW IF EXISTS `itemShelvingStock_byWarehouse`*/; -/*!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 = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStock_byWarehouse` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,`s`.`warehouseFk` AS `warehouseFk` from (((`itemShelving` `ish` join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) group by `ish`.`itemFk`,`s`.`warehouseFk` */; -/*!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 `itemTagged` -- @@ -82235,6 +93574,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `itemTaxCountrySpain` +-- + +/*!50001 DROP VIEW IF EXISTS `itemTaxCountrySpain`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `itemTaxCountrySpain` AS select `i`.`id` AS `id`,`i`.`name` AS `name`,`i`.`typeFk` AS `typeFk`,`i`.`stems` AS `stems`,`i`.`description` AS `description`,`i`.`intrastatFk` AS `intrastatFk`,`i`.`expenseFk` AS `expenseFk`,`i`.`comment` AS `comment`,`i`.`relevancy` AS `relevancy`,`i`.`image` AS `image`,`i`.`generic` AS `generic`,`itc`.`taxClassFk` AS `taxClassFk` from (`item` `i` join `itemTaxCountry` `itc` on(`itc`.`itemFk` = `i`.`id`)) where `itc`.`countryFk` = 1 */; +/*!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 `itemTicketOut` -- @@ -82469,6 +93826,42 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `paymentExchangeInsurance` +-- + +/*!50001 DROP VIEW IF EXISTS `paymentExchangeInsurance`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `paymentExchangeInsurance` AS select `p`.`pago_sdc_id` AS `id`,`p`.`importe` AS `amount`,`p`.`fecha` AS `created`,`p`.`vencimiento` AS `dueDay`,`p`.`entity_id` AS `entityFk`,`p`.`ref` AS `ref`,`p`.`rate` AS `rate`,`p`.`empresa_id` AS `companyFk`,`p`.`financialProductTypefk` AS `financialProductTypefk`,`p`.`upperBarrier` AS `upperBarrier`,`p`.`lowerBarrier` AS `lowerBarrier`,`p`.`strike` AS `strike` from `vn2008`.`pago_sdc` `p` */; +/*!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 `payrollCenter` +-- + +/*!50001 DROP VIEW IF EXISTS `payrollCenter`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `payrollCenter` AS select `b`.`cod_centro` AS `codCenter`,`b`.`Centro` AS `name`,`b`.`nss_cotizacion` AS `nss`,`b`.`domicilio` AS `street`,`b`.`poblacion` AS `city`,`b`.`cp` AS `postcode`,`b`.`empresa_id` AS `companyFk`,`b`.`codempresa` AS `companyCode` from `vn2008`.`payroll_centros` `b` */; +/*!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 `personMedia` -- @@ -82505,6 +93898,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `preparationException` +-- + +/*!50001 DROP VIEW IF EXISTS `preparationException`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `preparationException` AS select `p`.`exception_day` AS `exceptionDay`,`p`.`warehouse_id` AS `warehouseFk`,`p`.`percentage` AS `percentage` from `vn2008`.`preparation_exception` `p` */; +/*!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 `productionVolume` -- @@ -82541,6 +93952,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `promissoryNote` +-- + +/*!50001 DROP VIEW IF EXISTS `promissoryNote`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `promissoryNote` AS select `p`.`Id_Pagare` AS `id`,`p`.`Concepto` AS `Concept`,`p`.`pago_id` AS `paymentFk` from `vn2008`.`Pagares` `p` */; +/*!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 `role` -- @@ -82559,6 +93988,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `routesControl` +-- + +/*!50001 DROP VIEW IF EXISTS `routesControl`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `routesControl` AS select `t`.`routeFk` AS `routeFk`,count(`e`.`id`) AS `expeditions`,count(`es`.`id`) AS `scanned`,count(distinct `es`.`palletFk`) AS `pallets`,max(`es`.`scanned`) AS `lastScanned`,max(`et`.`description`) AS `description`,max(`et`.`eta`) AS `eta` from ((((`ticket` `t` join `expedition` `e` on(`t`.`id` = `e`.`ticketFk`)) left join `expeditionScan` `es` on(`es`.`expeditionFk` = `e`.`id`)) left join `expeditionPallet` `ep` on(`ep`.`id` = `es`.`palletFk`)) left join `expeditionTruck` `et` on(`et`.`id` = `ep`.`truckFk`)) where `t`.`shipped` >= `util`.`VN_CURDATE`() and `t`.`routeFk` <> 0 group by `t`.`routeFk` order by max(`et`.`eta`) */; +/*!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 `saleCost` -- @@ -82811,6 +94258,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `ticketDownBuffer` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketDownBuffer`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketDownBuffer` AS select `td`.`ticketFk` AS `ticketFk`,`td`.`created` AS `created`,`td`.`selected` AS `selected`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `sacador`,`pk`.`code` AS `parking` from ((((`ticketDown` `td` join `ticketParking` `tp` on(`tp`.`ticketFk` = `td`.`ticketFk`)) join `parking` `pk` on(`pk`.`id` = `tp`.`parkingFk`)) join `ticketStateToday` `tst` on(`tst`.`ticket` = `td`.`ticketFk`)) join `worker` `w` on(`w`.`id` = `tst`.`worker`)) where `td`.`selected` = 2 */; +/*!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 `ticketLastUpdated` -- @@ -82927,12 +94392,12 @@ USE `vn`; /*!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 = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 SET character_set_client = utf8mb3 */; +/*!50001 SET character_set_results = utf8mb3 */; +/*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketState` AS select `tt`.`created` AS `updated`,`tt`.`stateFk` AS `stateFk`,`tt`.`workerFk` AS `workerFk`,`tls`.`ticketFk` AS `ticketFk`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alertLevel` AS `alertLevel`,`s`.`code` AS `code`,`tls`.`ticketFk` AS `ticket`,`tt`.`workerFk` AS `worker`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from ((`ticketLastState` `tls` join `ticketTracking` `tt` on(`tt`.`id` = `tls`.`ticketTrackingFk`)) join `state` `s` on(`s`.`id` = `tt`.`stateFk`)) */; +/*!50001 VIEW `ticketState` AS select `tt`.`created` AS `updated`,`tt`.`stateFk` AS `stateFk`,`tt`.`userFk` AS `workerFk`,`tls`.`ticketFk` AS `ticketFk`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alertLevel` AS `alertLevel`,`s`.`code` AS `code`,`tls`.`ticketFk` AS `ticket`,`tt`.`userFk` AS `worker`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from ((`ticketLastState` `tls` join `ticketTracking` `tt` on(`tt`.`id` = `tls`.`ticketTrackingFk`)) join `state` `s` on(`s`.`id` = `tt`.`stateFk`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82945,12 +94410,48 @@ USE `vn`; /*!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 = utf8mb3 */; +/*!50001 SET character_set_results = utf8mb3 */; +/*!50001 SET collation_connection = utf8mb3_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code`,`ts`.`updated` AS `updated`,`ts`.`isPicked` AS `isPicked` from (`ticketState` `ts` join `ticket` `t` on(`t`.`id` = `ts`.`ticket`)) where `t`.`shipped` between `util`.`VN_CURDATE`() and `MIDNIGHT`(`util`.`VN_CURDATE`()) */; +/*!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 `ticketToPrepare` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketToPrepare`*/; +/*!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 = utf8mb4 */; /*!50001 SET character_set_results = utf8mb4 */; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code`,`ts`.`updated` AS `updated`,`ts`.`isPicked` AS `isPicked` from (`ticketState` `ts` join `ticket` `t` on(`t`.`id` = `ts`.`ticket`)) where `t`.`shipped` between `util`.`VN_CURDATE`() and `MIDNIGHT`(`util`.`VN_CURDATE`()) */; +/*!50001 VIEW `ticketToPrepare` AS select `m`.`Id_Ticket` AS `Id_Ticket`,`mk`.`Id_Movimiento` AS `Id_Movimiento`,`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,`mk`.`Id_Trabajador` AS `Id_Trabjador`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`art`.`subName` AS `subName`,`mk`.`original_quantity` - ifnull(`is`.`quantity`,0) AS `Cantidad`,`mk`.`original_quantity` AS `original_quantity`,if(hour(`t`.`shipped`),hour(`t`.`shipped`),hour(`z`.`hour`)) AS `Hora`,hour(`t`.`shipped`) AS `Departure`,minute(`t`.`shipped`) AS `Minuto`,`am`.`agencyFk` AS `agency_id`,`t`.`warehouseFk` AS `warehouse_id`,`a`.`provinceFk` AS `province_id`,`is`.`quantity` AS `picked`,`t`.`zoneFk` AS `zoneFk`,`p`.`sectorFk` AS `sectorFk` from ((((((((((`vn2008`.`Movimientos_mark` `mk` join `vn2008`.`Movimientos` `m` on(`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`)) join `vn`.`ticket` `t` on(`m`.`Id_Ticket` = `t`.`id`)) join `vn`.`agencyMode` `am` on(`am`.`id` = `t`.`agencyModeFk`)) join `vn`.`address` `a` on(`a`.`id` = `t`.`addressFk`)) left join `vn`.`itemShelvingSale` `is` on(`is`.`saleFk` = `mk`.`Id_Movimiento`)) left join `vn`.`itemShelving` `ish` on(`ish`.`id` = `is`.`itemShelvingFk`)) left join `vn`.`shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) left join `vn`.`parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) left join `vn2008`.`Articles` `art` on(`art`.`Id_Article` = `m`.`Id_Article`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) where `mk`.`stateFk` = 26 and `mk`.`valor` <> 1 */; +/*!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 `ticketeToPreparePrepared` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketeToPreparePrepared`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketeToPreparePrepared` AS select `m`.`Id_Ticket` AS `Id_Ticket`,`mk`.`Id_Movimiento` AS `Id_Movimiento`,`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,`mk`.`Id_Trabajador` AS `Id_Trabjador`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`art`.`subName` AS `subName`,`mk`.`original_quantity` - ifnull(`is`.`quantity`,0) AS `Cantidad`,`mk`.`original_quantity` AS `original_quantity`,hour(`t`.`shipped`) AS `Hora`,hour(`t`.`shipped`) AS `Departure`,minute(`t`.`shipped`) AS `Minuto`,`am`.`agencyFk` AS `agency_id`,`t`.`warehouseFk` AS `warehouse_id`,`a`.`provinceFk` AS `province_id`,`is`.`quantity` AS `picked`,`t`.`CodigoTrabajador` AS `trabajador`,`is`.`sectorFk` AS `sectorFk` from ((((((((`vn2008`.`Movimientos_mark` `mk` join `vn`.`state` `st` on(`st`.`id` = `mk`.`stateFk`)) join `vn2008`.`Movimientos` `m` on(`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`)) join `vn`.`ticket` `t` on(`m`.`Id_Ticket` = `t`.`id`)) join `vn`.`agencyMode` `am` on(`am`.`id` = `t`.`agencyModeFk`)) join `vn`.`address` `a` on(`a`.`id` = `t`.`addressFk`)) left join `vn`.`itemShelvingSaleSum` `is` on(`is`.`saleFk` = `mk`.`Id_Movimiento`)) join `vn2008`.`Articles` `art` on(`art`.`Id_Article` = `m`.`Id_Article`)) left join `vn2008`.`Trabajadores` `t` on(`t`.`Id_Trabajador` = `mk`.`Id_Trabajador`)) where `st`.`code` like 'PREVIOUS_PREPARATION' */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83009,6 +94510,114 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `unary` +-- + +/*!50001 DROP VIEW IF EXISTS `unary`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `unary` AS select `a`.`id` AS `id`,`a`.`parent` AS `parent` from `vn2008`.`unary` `a` */; +/*!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 `unaryScan` +-- + +/*!50001 DROP VIEW IF EXISTS `unaryScan`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `unaryScan` AS select `u`.`unary_id` AS `unaryFk`,`u`.`name` AS `name`,`u`.`odbc_date` AS `created`,`u`.`type` AS `type` from `vn2008`.`unary_scan` `u` */; +/*!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 `unaryScanLine` +-- + +/*!50001 DROP VIEW IF EXISTS `unaryScanLine`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `unaryScanLine` AS select `u`.`id` AS `id`,`u`.`code` AS `code`,`u`.`odbc_date` AS `created`,`u`.`unary_id` AS `unaryScanFk` from `vn2008`.`unary_scan_line` `u` */; +/*!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 `unaryScanLineBuy` +-- + +/*!50001 DROP VIEW IF EXISTS `unaryScanLineBuy`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `unaryScanLineBuy` AS select `u`.`scan_line_id` AS `unaryScanLineFk`,`u`.`Id_Article` AS `itemFk` from `vn2008`.`unary_scan_line_buy` `u` */; +/*!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 `unaryScanLineExpedition` +-- + +/*!50001 DROP VIEW IF EXISTS `unaryScanLineExpedition`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `unaryScanLineExpedition` AS select `u`.`scan_line_id` AS `unaryScanLineFk`,`u`.`expedition_id` AS `expeditionFk` from `vn2008`.`unary_scan_line_expedition` `u` */; +/*!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 `warehouseJoined` +-- + +/*!50001 DROP VIEW IF EXISTS `warehouseJoined`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `warehouseJoined` AS select `wj`.`warehouse_id` AS `warehouseFk`,`wj`.`warehouse_alias_id` AS `warehouseAliasFk` from `vn2008`.`warehouse_joined` `wj` */; +/*!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 `workerBusinessDated` -- @@ -83202,7 +94811,3271 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `zoneEstimatedDelivery` AS SELECT `t`.`zoneFk` AS `zoneFk`, `zc`.`hour` AS `zoneClosureHour`, `z`.`hour` AS `zoneHour`, `sv`.`volume` AS `volume`, `al`.`hasToRecalcPrice` AS `hasToRecalcPrice`, `lhp`.`m3` AS `m3`, `dl`.`minSpeed` AS `minSpeed` FROM ((((((((((`vn`.`ticket` `t` JOIN `vn`.`ticketStateToday` `tst` ON (`tst`.`ticket` = `t`.`id`)) JOIN `vn`.`state` `s` ON (`s`.`id` = `tst`.`state`)) JOIN `vn`.`saleVolume` `sv` ON (`sv`.`ticketFk` = `t`.`id`)) LEFT JOIN `vn`.`lastHourProduction` `lhp` ON (`lhp`.`warehouseFk` = `t`.`warehouseFk`)) JOIN `vn`.`warehouse` `w` ON (`w`.`id` = `t`.`warehouseFk`)) JOIN `vn`.`warehouseAlias` `wa` ON (`wa`.`id` = `w`.`aliasFk`)) STRAIGHT_JOIN `vn`.`zone` `z` ON (`z`.`id` = `t`.`zoneFk`)) LEFT JOIN `vn`.`zoneClosure` `zc` ON (`zc`.`zoneFk` = `t`.`zoneFk` AND `zc`.`dated` = `util`.`VN_CURDATE`())) LEFT JOIN `cache`.`departure_limit` `dl` ON (`dl`.`warehouse_id` = `t`.`warehouseFk` AND `dl`.`fecha` = `util`.`VN_CURDATE`())) JOIN `vn`.`alertLevel` `al` ON (`al`.`id` = `s`.`alertLevel`)) WHERE `w`.`hasProduction` <> 0 AND CAST(`t`.`shipped` AS date) = `util`.`VN_CURDATE`() */; +/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,`zc`.`hour` AS `zoneClosureHour`,`z`.`hour` AS `zoneHour`,`sv`.`volume` AS `volume`,`al`.`hasToRecalcPrice` AS `hasToRecalcPrice`,`lhp`.`m3` AS `m3`,`dl`.`minSpeed` AS `minSpeed` from ((((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on(`tst`.`ticket` = `t`.`id`)) join `vn`.`state` `s` on(`s`.`id` = `tst`.`state`)) join `vn`.`saleVolume` `sv` on(`sv`.`ticketFk` = `t`.`id`)) left join `vn`.`lastHourProduction` `lhp` on(`lhp`.`warehouseFk` = `t`.`warehouseFk`)) join `vn`.`warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `vn`.`warehouseAlias` `wa` on(`wa`.`id` = `w`.`aliasFk`)) straight_join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`zoneClosure` `zc` on(`zc`.`zoneFk` = `t`.`zoneFk` and `zc`.`dated` = `util`.`VN_CURDATE`())) left join `cache`.`departure_limit` `dl` on(`dl`.`warehouse_id` = `t`.`warehouseFk` and `dl`.`fecha` = `util`.`VN_CURDATE`())) join `vn`.`alertLevel` `al` on(`al`.`id` = `s`.`alertLevel`)) where `w`.`hasProduction` <> 0 and cast(`t`.`shipped` as date) = `util`.`VN_CURDATE`() */; +/*!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: `vn2008` +-- + +USE `vn2008`; + +-- +-- Final view structure for view `Agencias` +-- + +/*!50001 DROP VIEW IF EXISTS `Agencias`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Agencias` AS select `am`.`id` AS `Id_Agencia`,`am`.`name` AS `Agencia`,`am`.`description` AS `description`,`am`.`deliveryMethodFk` AS `Vista`,`am`.`m3` AS `m3`,`am`.`web` AS `web`,`am`.`agencyFk` AS `agency_id`,`am`.`inflation` AS `inflacion`,`am`.`isVolumetric` AS `is_volumetric`,`am`.`reportMail` AS `send_mail`,`am`.`isActive` AS `tpv`,`am`.`code` AS `code`,`am`.`showAgencyName` AS `show_AgencyName`,`am`.`isRiskFree` AS `isRiskFree` from `vn`.`agencyMode` `am` */; +/*!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 `Articles` +-- + +/*!50001 DROP VIEW IF EXISTS `Articles`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Articles` AS select `i`.`id` AS `Id_Article`,`i`.`name` AS `Article`,`i`.`typeFk` AS `tipo_id`,`i`.`size` AS `Medida`,`i`.`inkFk` AS `Color`,`i`.`category` AS `Categoria`,`i`.`stems` AS `Tallos`,`i`.`originFk` AS `id_origen`,`i`.`description` AS `description`,`i`.`producerFk` AS `producer_id`,`i`.`intrastatFk` AS `Codintrastat`,`i`.`box` AS `caja`,`i`.`expenseFk` AS `expenseFk`,`i`.`comment` AS `comments`,`i`.`relevancy` AS `relevancy`,`i`.`image` AS `Foto`,`i`.`generic` AS `generic`,`i`.`density` AS `density`,`i`.`minPrice` AS `PVP`,`i`.`hasMinPrice` AS `Min`,`i`.`isActive` AS `isActive`,`i`.`longName` AS `longName`,`i`.`subName` AS `subName`,`i`.`tag5` AS `tag5`,`i`.`value5` AS `value5`,`i`.`tag6` AS `tag6`,`i`.`value6` AS `value6`,`i`.`tag7` AS `tag7`,`i`.`value7` AS `value7`,`i`.`tag8` AS `tag8`,`i`.`value8` AS `value8`,`i`.`tag9` AS `tag9`,`i`.`value9` AS `value9`,`i`.`tag10` AS `tag10`,`i`.`value10` AS `value10`,`i`.`minimum` AS `minimum`,`i`.`upToDown` AS `upToDown`,`i`.`hasKgPrice` AS `hasKgPrice`,`i`.`equivalent` AS `Equivalente`,`i`.`isToPrint` AS `Imprimir`,`i`.`family` AS `Familia__`,`i`.`doPhoto` AS `do_photo`,`i`.`created` AS `odbc_date`,`i`.`isFloramondo` AS `isFloramondo`,`i`.`supplyResponseFk` AS `supplyResponseFk`,`i`.`stemMultiplier` AS `stemMultiplier`,`i`.`itemPackingTypeFk` AS `itemPackingTypeFk`,`i`.`packingOut` AS `packingOut` from `vn`.`item` `i` */; +/*!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 `Articles_botanical` +-- + +/*!50001 DROP VIEW IF EXISTS `Articles_botanical`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Articles_botanical` AS select `ab`.`itemFk` AS `Id_Article`,`ab`.`genusFk` AS `genus_id`,`ab`.`specieFk` AS `specie_id` from `vn`.`itemBotanical` `ab` */; +/*!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 `Bancos` +-- + +/*!50001 DROP VIEW IF EXISTS `Bancos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Bancos` AS select `b`.`id` AS `Id_Banco`,`b`.`bank` AS `Banco`,`b`.`account` AS `Cuenta`,`b`.`cash` AS `cash`,`b`.`entityFk` AS `entity_id`,`b`.`isActive` AS `activo`,`b`.`currencyFk` AS `currencyFk` from `vn`.`bank` `b` */; +/*!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 `Cajas` +-- + +/*!50001 DROP VIEW IF EXISTS `Cajas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Cajas` AS select `t`.`id` AS `Id_Caja`,`t`.`dated` AS `Cajafecha`,`t`.`serie` AS `Serie`,`t`.`concept` AS `Concepto`,`t`.`in` AS `Entrada`,`t`.`out` AS `Salida`,`t`.`bankFk` AS `Id_Banco`,`t`.`companyFk` AS `empresa_id`,`t`.`isAccountable` AS `Partida`,`t`.`InForeignValue` AS `InForeignValue`,`t`.`OutForeignValue` AS `OutForeignValue`,`t`.`workerFk` AS `Id_Trabajador`,`t`.`calculatedCode` AS `id_calculated`,`t`.`number` AS `Numero`,`t`.`isLinked` AS `linked`,`t`.`created` AS `odbc_date`,`t`.`isOk` AS `ok`,`t`.`warehouseFk` AS `warehouse_id`,`t`.`isConciliate` AS `conciliado`,`t`.`supplierAccountFk` AS `Proveedores_account_Id` from `vn`.`till` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Clientes` +-- + +/*!50001 DROP VIEW IF EXISTS `Clientes`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Clientes` AS select `c`.`id` AS `id_cliente`,`c`.`name` AS `cliente`,`c`.`fi` AS `if`,`c`.`socialName` AS `razonSocial`,`c`.`contact` AS `contacto`,`c`.`street` AS `domicilio`,`c`.`city` AS `poblacion`,`c`.`postcode` AS `codPostal`,`c`.`phone` AS `telefono`,`c`.`mobile` AS `movil`,`c`.`isRelevant` AS `real`,`c`.`email` AS `e-mail`,`c`.`iban` AS `iban`,`c`.`dueDay` AS `vencimiento`,`c`.`accountingAccount` AS `Cuenta`,`c`.`isEqualizated` AS `RE`,`c`.`provinceFk` AS `province_id`,`c`.`hasToInvoice` AS `invoice`,`c`.`credit` AS `credito`,`c`.`countryFk` AS `Id_Pais`,`c`.`isActive` AS `activo`,`c`.`gestdocFk` AS `gestdoc_id`,`c`.`quality` AS `calidad`,`c`.`payMethodFk` AS `pay_met_id`,`c`.`created` AS `created`,`c`.`isToBeMailed` AS `mail`,`c`.`contactChannelFk` AS `chanel_id`,`c`.`hasSepaVnl` AS `sepaVnl`,`c`.`hasCoreVnl` AS `coreVnl`,`c`.`hasCoreVnh` AS `coreVnh`,`c`.`hasLcr` AS `hasLcr`,`c`.`defaultAddressFk` AS `default_address`,`c`.`riskCalculated` AS `risk_calculated`,`c`.`clientTypeFk` AS `clientes_tipo_id`,`c`.`hasToInvoiceByAddress` AS `invoiceByAddress`,`c`.`isTaxDataChecked` AS `contabilizado`,`c`.`isFreezed` AS `congelado`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`isCreatedAsServed` AS `isCreatedAsServed`,`c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified`,`c`.`salesPersonFk` AS `Id_Trabajador`,`c`.`isVies` AS `vies`,`c`.`eypbc` AS `EYPBC`,`c`.`bankEntityFk` AS `bankEntityFk`,`c`.`typeFk` AS `typeFk` from `vn`.`client` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Comparativa` +-- + +/*!50001 DROP VIEW IF EXISTS `Comparativa`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Comparativa` AS select `c`.`timePeriod` AS `Periodo`,`c`.`itemFk` AS `Id_Article`,`c`.`warehouseFk` AS `warehouse_id`,`c`.`quantity` AS `Cantidad`,`c`.`price` AS `price`,`c`.`countryFk` AS `countryFk` from `vn`.`comparative` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Compres` +-- + +/*!50001 DROP VIEW IF EXISTS `Compres`*/; +/*!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 = utf8mb3 */; +/*!50001 SET character_set_results = utf8mb3 */; +/*!50001 SET collation_connection = utf8mb3_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Compres` AS select `c`.`id` AS `Id_Compra`,`c`.`entryFk` AS `Id_Entrada`,`c`.`itemFk` AS `Id_Article`,`c`.`buyingValue` AS `Costefijo`,`c`.`quantity` AS `Cantidad`,`c`.`packagingFk` AS `Id_Cubo`,`c`.`stickers` AS `Etiquetas`,`c`.`freightValue` AS `Portefijo`,`c`.`packageValue` AS `Embalajefijo`,`c`.`comissionValue` AS `Comisionfija`,`c`.`packing` AS `Packing`,`c`.`grouping` AS `grouping`,`c`.`groupingMode` AS `caja`,`c`.`location` AS `Nicho`,`c`.`price1` AS `Tarifa1`,`c`.`price2` AS `Tarifa2`,`c`.`price3` AS `Tarifa3`,`c`.`minPrice` AS `PVP`,`c`.`printedStickers` AS `Vida`,`c`.`isChecked` AS `punteo`,`c`.`ektFk` AS `buy_edi_id`,`c`.`created` AS `odbc_date`,`c`.`isIgnored` AS `Novincular`,`c`.`isPickedOff` AS `isPickedOff`,`c`.`workerFk` AS `Id_Trabajador`,`c`.`weight` AS `weight`,`c`.`dispatched` AS `dispatched`,`c`.`containerFk` AS `container_id`,`c`.`itemOriginalFk` AS `itemOriginalFk` from `vn`.`buy` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Compres_mark` +-- + +/*!50001 DROP VIEW IF EXISTS `Compres_mark`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Compres_mark` AS select `bm`.`id` AS `Id_Compra`,`bm`.`comment` AS `comment`,`bm`.`mark` AS `mark`,`bm`.`odbcDate` AS `odbc_date` from `vn`.`buyMark` `bm` */; +/*!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 `Consignatarios` +-- + +/*!50001 DROP VIEW IF EXISTS `Consignatarios`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Consignatarios` AS select `a`.`id` AS `id_consigna`,`a`.`clientFk` AS `Id_cliente`,`a`.`street` AS `domicilio`,`a`.`city` AS `poblacion`,`a`.`postalCode` AS `codPostal`,`a`.`provinceFk` AS `province_id`,`a`.`phone` AS `telefono`,`a`.`mobile` AS `movil`,`a`.`nickname` AS `consignatario`,`a`.`isDefaultAddress` AS `predeterminada`,`a`.`longitude` AS `longitude`,`a`.`latitude` AS `latitude`,`a`.`agencyModeFk` AS `Id_Agencia`,`a`.`isEqualizated` AS `isEqualizated`,`a`.`isActive` AS `active` from `vn`.`address` `a` */; +/*!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 `Cubos` +-- + +/*!50001 DROP VIEW IF EXISTS `Cubos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Cubos` AS select `p`.`id` AS `Id_Cubo`,`p`.`volume` AS `Volumen`,`p`.`width` AS `X`,`p`.`depth` AS `Y`,`p`.`height` AS `Z`,`p`.`isPackageReturnable` AS `Retornable`,`p`.`created` AS `odbc_date`,`p`.`itemFk` AS `item_id`,`p`.`price` AS `pvp`,`p`.`cubicPackage` AS `bultoCubico`,`p`.`value` AS `Valor`,`p`.`packagingReturnFk` AS `idCubos_Retorno`,`p`.`lower` AS `Bajan`,`p`.`upload` AS `Suben`,`p`.`base` AS `Base`,`p`.`isBox` AS `box`,`p`.`returnCost` AS `costeRetorno` from `vn`.`packaging` `p` */; +/*!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 `Cubos_Retorno` +-- + +/*!50001 DROP VIEW IF EXISTS `Cubos_Retorno`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Cubos_Retorno` AS select `rb`.`id` AS `idCubos_Retorno`,`rb`.`freightContainerType` AS `Soporte`,`rb`.`freightPackagingEmpty` AS `Vacio`,`rb`.`freightPackagingFull` AS `Lleno` from `vn`.`returnBuckets` `rb` */; +/*!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 `Entradas` +-- + +/*!50001 DROP VIEW IF EXISTS `Entradas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Entradas` AS select `e`.`id` AS `Id_Entrada`,`e`.`supplierFk` AS `Id_Proveedor`,`e`.`invoiceNumber` AS `Referencia`,`e`.`reference` AS `reference`,`e`.`isExcludedFromAvailable` AS `Inventario`,`e`.`isConfirmed` AS `Confirmada`,`e`.`isOrdered` AS `Pedida`,`e`.`isRaid` AS `Redada`,`e`.`commission` AS `comision`,`e`.`created` AS `odbc_date`,`e`.`evaNotes` AS `Notas_Eva`,`e`.`travelFk` AS `travel_id`,`e`.`currencyFk` AS `Id_Moneda`,`e`.`companyFk` AS `empresa_id`,`e`.`gestDocFk` AS `gestdoc_id`,`e`.`invoiceInFk` AS `recibida_id`,`e`.`dated` AS `Fecha`,`e`.`isBooked` AS `Anotadoencaja`,`e`.`loadPriority` AS `loadPriority`,`e`.`sub` AS `sub`,`e`.`kop` AS `kop`,`e`.`pro` AS `pro`,`e`.`invoiceAmount` AS `invoiceAmount`,`e`.`buyerFk` AS `buyerFk`,`e`.`typeFk` AS `typeFk` from `vn`.`entry` `e` */; +/*!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 `Entradas_Auto` +-- + +/*!50001 DROP VIEW IF EXISTS `Entradas_Auto`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Entradas_Auto` AS select `ev`.`entryFk` AS `Id_Entrada` from `vn`.`entryVirtual` `ev` */; +/*!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 `Equipos` +-- + +/*!50001 DROP VIEW IF EXISTS `Equipos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Equipos` AS select `h`.`code` AS `alias`,`h`.`description` AS `descripcion`,`h`.`workerFk` AS `trabajador_id`,`h`.`windowsSerial` AS `windowsSerial` from `vn`.`host` `h` */; +/*!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 `Facturas` +-- + +/*!50001 DROP VIEW IF EXISTS `Facturas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Facturas` AS select `io`.`id` AS `factura_id`,`io`.`ref` AS `Id_Factura`,`io`.`serial` AS `Serie`,`io`.`issued` AS `Fecha`,`io`.`amount` AS `Importe`,`io`.`clientFk` AS `Id_Cliente`,`io`.`created` AS `odbc_date`,`io`.`companyFk` AS `empresa_id`,`io`.`dued` AS `Vencimiento`,`io`.`booked` AS `booked`,`io`.`bankFk` AS `Id_Banco`,`io`.`siiTypeInvoiceOutFk` AS `siiTypeInvoiceOutFk`,`io`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,`io`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,`io`.`siiTrascendencyInvoiceOutFk` AS `siiTrascendencyInvoiceOutFk`,`io`.`hasPdf` AS `pdf` from `vn`.`invoiceOut` `io` */; +/*!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 `Gastos` +-- + +/*!50001 DROP VIEW IF EXISTS `Gastos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Gastos` AS select `e`.`id` AS `Id_Gasto`,`e`.`name` AS `Gasto`,`e`.`isWithheld` AS `isWithheld` from `vn`.`expense` `e` */; +/*!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 `Greuges` +-- + +/*!50001 DROP VIEW IF EXISTS `Greuges`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Greuges` AS select `g`.`Id` AS `Id`,`g`.`clientFk` AS `Id_Cliente`,`g`.`description` AS `Comentario`,`g`.`amount` AS `Importe`,`g`.`shipped` AS `Fecha`,`g`.`created` AS `odbc_date`,`g`.`greugeTypeFk` AS `Greuges_type_id`,`g`.`ticketFk` AS `Id_Ticket` from `vn`.`greuge` `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 `Greuges_type` +-- + +/*!50001 DROP VIEW IF EXISTS `Greuges_type`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Greuges_type` AS select `gt`.`id` AS `Greuges_type_id`,`gt`.`name` AS `name` from `vn`.`greugeType` `gt` */; +/*!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 `Impresoras` +-- + +/*!50001 DROP VIEW IF EXISTS `Impresoras`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Impresoras` AS select `vn`.`printer`.`id` AS `Id_impresora`,`vn`.`printer`.`path` AS `Ruta`,`vn`.`printer`.`name` AS `Impresora`,`vn`.`printer`.`reference` AS `referencia`,`vn`.`printer`.`isLabeler` AS `isLabeler` from `vn`.`printer` */; +/*!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 `Intrastat` +-- + +/*!50001 DROP VIEW IF EXISTS `Intrastat`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Intrastat` AS select `i`.`id` AS `Codintrastat`,`i`.`description` AS `Definicion`,`i`.`taxClassFk` AS `iva_group_id`,`i`.`taxCodeFk` AS `iva_codigo_id` from `vn`.`intrastat` `i` */; +/*!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 `Monedas` +-- + +/*!50001 DROP VIEW IF EXISTS `Monedas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Monedas` AS select `c`.`id` AS `Id_Moneda`,`c`.`code` AS `Moneda`,`c`.`name` AS `Descripcion`,`c`.`ratio` AS `Cambio` from `vn`.`currency` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Movimientos` +-- + +/*!50001 DROP VIEW IF EXISTS `Movimientos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Movimientos` AS select `m`.`id` AS `Id_Movimiento`,`m`.`itemFk` AS `Id_Article`,`m`.`ticketFk` AS `Id_Ticket`,`m`.`concept` AS `Concepte`,`m`.`quantity` AS `Cantidad`,`m`.`price` AS `Preu`,`m`.`discount` AS `Descuento`,`m`.`reserved` AS `Reservado`,`m`.`isPicked` AS `OK`,`m`.`created` AS `odbc_date`,`m`.`priceFixed` AS `CostFixat`,`m`.`isPriceFixed` AS `PrecioFijado`,`m`.`originalQuantity` AS `quantity`,`m`.`isAdded` AS `isAdded` from `vn`.`sale` `m` */; +/*!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 `Movimientos_componentes` +-- + +/*!50001 DROP VIEW IF EXISTS `Movimientos_componentes`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Movimientos_componentes` AS select `sc`.`saleFk` AS `Id_Movimiento`,`sc`.`componentFk` AS `Id_Componente`,`sc`.`value` AS `Valor`,`sc`.`created` AS `created`,`sc`.`isGreuge` AS `greuge` from `vn`.`saleComponent` `sc` */; +/*!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 `Movimientos_mark` +-- + +/*!50001 DROP VIEW IF EXISTS `Movimientos_mark`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Movimientos_mark` AS select `mm`.`saleFk` AS `Id_Movimiento`,`mm`.`isChecked` AS `valor`,`mm`.`created` AS `odbc_date`,`mm`.`originalQuantity` AS `original_quantity`,`mm`.`workerFk` AS `Id_Trabajador`,`mm`.`id` AS `Id_Movimiento_mark`,`mm`.`stateFk` AS `stateFk` from `vn`.`saleTracking` `mm` */; +/*!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 `Ordenes` +-- + +/*!50001 DROP VIEW IF EXISTS `Ordenes`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Ordenes` AS select `tr`.`id` AS `Id_ORDEN`,`tr`.`description` AS `ORDEN`,`tr`.`requesterFk` AS `requesterFk`,`tr`.`attenderFk` AS `attenderFk`,`tr`.`quantity` AS `CANTIDAD`,`tr`.`itemFk` AS `Id_ARTICLE`,`tr`.`price` AS `PRECIOMAX`,`tr`.`isOk` AS `isOk`,`tr`.`saleFk` AS `Id_Movimiento`,`tr`.`ticketFk` AS `ticketFk`,`tr`.`response` AS `COMENTARIO`,`tr`.`created` AS `odbc_date`,`tr`.`ordered` AS `datORDEN`,`tr`.`shipped` AS `datTICKET`,`tr`.`salesPersonCode` AS `CodVENDEDOR`,`tr`.`buyerCode` AS `CodCOMPRADOR`,`tr`.`clientFk` AS `Id_CLIENTE`,`tr`.`total` AS `TOTAL`,`tr`.`buyed` AS `datCOMPRA` from `vn`.`ticketRequest` `tr` */; +/*!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 `Origen` +-- + +/*!50001 DROP VIEW IF EXISTS `Origen`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Origen` AS select `o`.`id` AS `id`,`o`.`code` AS `Abreviatura`,`o`.`name` AS `Origen`,`o`.`countryFk` AS `Id_Paises`,`o`.`warehouseFk` AS `warehouse_id` from `vn`.`origin` `o` */; +/*!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 `Paises` +-- + +/*!50001 DROP VIEW IF EXISTS `Paises`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Paises` AS select `c`.`id` AS `Id`,`c`.`country` AS `Pais`,`c`.`CEE` AS `CEE`,`c`.`isUeeMember` AS `isUeeMember`,`c`.`code` AS `Codigo`,`c`.`currencyFk` AS `Id_Moneda`,`c`.`geoFk` AS `geoFk`,`c`.`ibanLength` AS `ibanLength`,`c`.`hasDailyInvoice` AS `hasDailyInvoice` from `vn`.`country` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `PreciosEspeciales` +-- + +/*!50001 DROP VIEW IF EXISTS `PreciosEspeciales`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `PreciosEspeciales` AS select `sp`.`id` AS `Id_PrecioEspecial`,`sp`.`clientFk` AS `Id_Cliente`,`sp`.`itemFk` AS `Id_Article`,`sp`.`value` AS `PrecioEspecial` from `vn`.`specialPrice` `sp` */; +/*!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 `Prioridades` +-- + +/*!50001 DROP VIEW IF EXISTS `Prioridades`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Prioridades` AS select `qp`.`id` AS `Id_Prioridad`,`qp`.`priority` AS `Prioridad` from `vn`.`queuePriority` `qp` */; +/*!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 `Proveedores` +-- + +/*!50001 DROP VIEW IF EXISTS `Proveedores`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Proveedores` AS select `s`.`id` AS `Id_Proveedor`,`s`.`name` AS `Proveedor`,`s`.`account` AS `cuenta`,`s`.`countryFk` AS `pais_id`,`s`.`nif` AS `NIF`,`s`.`isFarmer` AS `Agricola`,`s`.`phone` AS `Telefono`,`s`.`retAccount` AS `cuentaret`,`s`.`commission` AS `ComisionProveedor`,`s`.`created` AS `odbc_time`,`s`.`postcodeFk` AS `postcode_id`,`s`.`isActive` AS `active`,`s`.`street` AS `Domicilio`,`s`.`city` AS `Localidad`,`s`.`provinceFk` AS `province_id`,`s`.`postCode` AS `codpos`,`s`.`payMethodFk` AS `pay_met_id`,`s`.`payDemFk` AS `pay_dem_id`,`s`.`nickname` AS `Alias`,`s`.`isOfficial` AS `oficial`,`s`.`workerFk` AS `workerFk`,`s`.`payDay` AS `pay_day`,`s`.`isSerious` AS `serious`,`s`.`note` AS `notas`,`s`.`taxTypeSageFk` AS `taxTypeSageFk`,`s`.`withholdingSageFk` AS `withholdingSageFk`,`s`.`isTrucker` AS `isTrucker`,`s`.`transactionTypeSageFk` AS `transactionTypeSageFk`,`s`.`supplierActivityFk` AS `supplierActivityFk`,`s`.`healthRegister` AS `healthRegister`,`s`.`isPayMethodChecked` AS `isPayMethodChecked` from `vn`.`supplier` `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 `Recibos` +-- + +/*!50001 DROP VIEW IF EXISTS `Recibos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Recibos` AS select `r`.`Id` AS `Id`,`r`.`invoiceFk` AS `Id_Factura`,`r`.`amountPaid` AS `Entregado`,`r`.`payed` AS `Fechacobro`,`r`.`workerFk` AS `Id_Trabajador`,`r`.`bankFk` AS `Id_Banco`,`r`.`clientFk` AS `Id_Cliente`,`r`.`created` AS `odbc_date`,`r`.`companyFk` AS `empresa_id`,`r`.`isConciliate` AS `conciliado` from `vn`.`receipt` `r` */; +/*!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 `Rutas` +-- + +/*!50001 DROP VIEW IF EXISTS `Rutas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Rutas` AS select `r`.`id` AS `Id_Ruta`,`r`.`workerFk` AS `Id_Trabajador`,`r`.`created` AS `Fecha`,`r`.`vehicleFk` AS `Id_Vehiculo`,`r`.`agencyModeFk` AS `Id_Agencia`,`r`.`time` AS `Hora`,`r`.`isOk` AS `ok`,`r`.`kmStart` AS `km_start`,`r`.`kmEnd` AS `km_end`,`r`.`started` AS `date_start`,`r`.`finished` AS `date_end`,`r`.`gestdocFk` AS `gestdoc_id`,`r`.`cost` AS `cost`,`r`.`m3` AS `m3`,`r`.`description` AS `description` from `vn`.`route` `r` */; +/*!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 `Rutas_Master` +-- + +/*!50001 DROP VIEW IF EXISTS `Rutas_Master`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Rutas_Master` AS select `rm`.`id` AS `id`,`rm`.`warehouseFk` AS `warehouse_id`,`rm`.`km` AS `km`,`rm`.`packages` AS `bultos`,`rm`.`vehicleCost` AS `vehiculos_coste`,`rm`.`staffCost` AS `personal_coste`,`rm`.`vehicle` AS `vehiculos_numero`,`rm`.`staff` AS `personal_numero`,`rm`.`fuel` AS `gasoil`,`rm`.`freelancers` AS `autonomos`,`rm`.`year` AS `año`,`rm`.`month` AS `mes`,`rm`.`expense` AS `gastos`,`rm`.`freelancersPackages` AS `bultos_autonomos`,`rm`.`kmCost` AS `coste_km`,`rm`.`packageCost` AS `coste_bulto`,`rm`.`freelancerPackageCost` AS `coste_bulto_autonomo`,`rm`.`created` AS `odbc_date` from `vn`.`routeMaster` `rm` */; +/*!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 `Rutas_monitor` +-- + +/*!50001 DROP VIEW IF EXISTS `Rutas_monitor`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Rutas_monitor` AS select `vn`.`routesMonitor`.`routeFk` AS `Id_Ruta`,`vn`.`routesMonitor`.`name` AS `name`,`vn`.`routesMonitor`.`beachFk` AS `Ubicacion`,`vn`.`routesMonitor`.`ticketPacked` AS `pedidosEncajados`,`vn`.`routesMonitor`.`ticketFree` AS `pedidosLibres`,`vn`.`routesMonitor`.`ticketProduction` AS `pedidosProduccion`,`vn`.`routesMonitor`.`packages` AS `bultos`,`vn`.`routesMonitor`.`note` AS `notas`,`vn`.`routesMonitor`.`dated` AS `fecha`,`vn`.`routesMonitor`.`dockFk` AS `dockFk`,`vn`.`routesMonitor`.`m3` AS `m3`,`vn`.`routesMonitor`.`priority` AS `priority`,`vn`.`routesMonitor`.`etd` AS `etd`,`vn`.`routesMonitor`.`expeditionTruckFk` AS `expeditionTruckFk` from `vn`.`routesMonitor` */; +/*!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 `Tickets` +-- + +/*!50001 DROP VIEW IF EXISTS `Tickets`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Tickets` AS select `t`.`id` AS `Id_Ticket`,`t`.`clientFk` AS `Id_Cliente`,`t`.`warehouseFk` AS `warehouse_id`,`t`.`shipped` AS `Fecha`,`t`.`landed` AS `landing`,`t`.`nickname` AS `Alias`,`t`.`refFk` AS `Factura`,`t`.`addressFk` AS `Id_Consigna`,`t`.`location` AS `Localizacion`,`t`.`solution` AS `Solucion`,`t`.`routeFk` AS `Id_Ruta`,`t`.`companyFk` AS `empresa_id`,`t`.`agencyModeFk` AS `Id_Agencia`,`t`.`priority` AS `Prioridad`,`t`.`packages` AS `Bultos`,`t`.`isDeleted` AS `isDeleted`,`t`.`created` AS `odbc_date`,`t`.`workerFk` AS `Id_Trabajador`,`t`.`observations` AS `Observaciones`,`t`.`isSigned` AS `Firmado`,`t`.`isLabeled` AS `Etiquetasemitidas`,`t`.`isPrinted` AS `PedidoImpreso`,`t`.`hour` AS `Hora`,`t`.`isBlocked` AS `blocked`,`t`.`hasPriority` AS `priority`,`t`.`isBoxed` AS `boxed`,`t`.`zoneFk` AS `zoneFk`,`t`.`totalWithVat` AS `totalWithVat`,`t`.`totalWithoutVat` AS `totalWithoutVat` from `vn`.`ticket` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Tickets_state` +-- + +/*!50001 DROP VIEW IF EXISTS `Tickets_state`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Tickets_state` AS select `t`.`ticketFk` AS `Id_Ticket`,`t`.`ticketTrackingFk` AS `inter_id`,`t`.`name` AS `state_name` from `vn`.`ticketLastState` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `Tickets_turno` +-- + +/*!50001 DROP VIEW IF EXISTS `Tickets_turno`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Tickets_turno` AS select `tw`.`ticketFk` AS `Id_Ticket`,`tw`.`weekDay` AS `weekDay` from `vn`.`ticketWeekly` `tw` */; +/*!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 `Tintas` +-- + +/*!50001 DROP VIEW IF EXISTS `Tintas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Tintas` AS select `i`.`id` AS `Id_Tinta`,`i`.`name` AS `name`,`i`.`picture` AS `Tinta`,`i`.`showOrder` AS `Orden`,`i`.`ball` AS `ball`,`i`.`isCargex` AS `cargex`,`i`.`hex` AS `colorHex` from `vn`.`ink` `i` */; +/*!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 `Tipos` +-- + +/*!50001 DROP VIEW IF EXISTS `Tipos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Tipos` AS select `it`.`id` AS `tipo_id`,`it`.`code` AS `Id_Tipo`,`it`.`name` AS `Tipo`,`it`.`order` AS `Orden`,`it`.`categoryFk` AS `reino_id`,`it`.`workerFk` AS `Id_Trabajador`,`it`.`life` AS `life`,`it`.`isPackaging` AS `isPackaging`,`it`.`density` AS `density`,`it`.`isInventory` AS `inventory`,`it`.`created` AS `odbc_date`,`it`.`making` AS `confeccion`,`it`.`temperatureFk` AS `Temperatura`,`it`.`promo` AS `promo`,`it`.`maneuver` AS `maneuver`,`it`.`target` AS `target`,`it`.`topMargin` AS `top_margin`,`it`.`profit` AS `profit` from `vn`.`itemType` `it` */; +/*!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 `Trabajadores` +-- + +/*!50001 DROP VIEW IF EXISTS `Trabajadores`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Trabajadores` AS select `w`.`id` AS `Id_Trabajador`,`w`.`firstName` AS `Nombre`,`w`.`id` AS `user_id`,`w`.`phone` AS `phone`,`w`.`bossFk` AS `boss`,NULL AS `Foto`,`w`.`fiDueDate` AS `DniExpiration`,`w`.`code` AS `CodigoTrabajador`,`w`.`lastName` AS `Apellidos`,`w`.`hasMachineryAuthorized` AS `hasMachineryAuthorized`,`w`.`sub` AS `sub`,`w`.`maritalStatus` AS `marital_status` from `vn`.`worker` `w` */; +/*!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 `V_edi_item_track` +-- + +/*!50001 DROP VIEW IF EXISTS `V_edi_item_track`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `V_edi_item_track` AS select `edi`.`item_track`.`item_id` AS `item_id`,`edi`.`item_track`.`s1` AS `s1`,`edi`.`item_track`.`s2` AS `s2`,`edi`.`item_track`.`s3` AS `s3`,`edi`.`item_track`.`s4` AS `s4`,`edi`.`item_track`.`s5` AS `s5`,`edi`.`item_track`.`s6` AS `s6`,`edi`.`item_track`.`kop` AS `kop`,`edi`.`item_track`.`pac` AS `pac`,`edi`.`item_track`.`cat` AS `cat`,`edi`.`item_track`.`ori` AS `ori`,`edi`.`item_track`.`pro` AS `pro`,`edi`.`item_track`.`sub` AS `sub`,`edi`.`item_track`.`package` AS `package`,`edi`.`item_track`.`item` AS `item` from `edi`.`item_track` */; +/*!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 `Vehiculos` +-- + +/*!50001 DROP VIEW IF EXISTS `Vehiculos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Vehiculos` AS select `v`.`id` AS `Id_Vehiculo`,`v`.`numberPlate` AS `Matricula`,`v`.`tradeMark` AS `Marca`,`v`.`model` AS `Modelo`,`v`.`companyFk` AS `empresa_id`,`v`.`warehouseFk` AS `warehouseFk`,`v`.`description` AS `description`,`v`.`m3` AS `m3`,`v`.`isActive` AS `active`,`v`.`deliveryPointFk` AS `deliveryPointFk` from `vn`.`vehicle` `v` */; +/*!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 `VerEspionaje` +-- + +/*!50001 DROP VIEW IF EXISTS `VerEspionaje`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `VerEspionaje` AS select `Trabajadores`.`CodigoTrabajador` AS `CodigoTrabajador`,`vn2008`.`Espionajes`.`Fecha` AS `Fecha`,`vn2008`.`Espionajes`.`HoraEntrada` AS `HoraEntrada`,`vn2008`.`Espionajes`.`HoraSalida` AS `HoraSalida`,`vn2008`.`Espionajes`.`Id_Equipo` AS `Id_Equipo`,`Trabajadores`.`Id_Trabajador` AS `Id_Trabajador` from (`vn2008`.`Espionajes` join `vn2008`.`Trabajadores` on(`vn2008`.`Espionajes`.`Id_Trabajador` = `Trabajadores`.`Id_Trabajador`)) order by `Trabajadores`.`CodigoTrabajador`,`vn2008`.`Espionajes`.`Fecha` */; +/*!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 `Vistas` +-- + +/*!50001 DROP VIEW IF EXISTS `Vistas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `Vistas` AS select `dm`.`id` AS `vista_id`,`dm`.`code` AS `code`,`dm`.`description` AS `vista` from `vn`.`deliveryMethod` `dm` */; +/*!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 `XDiario` +-- + +/*!50001 DROP VIEW IF EXISTS `XDiario`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `XDiario` AS select `d`.`id` AS `id`,`d`.`ASIEN` AS `ASIEN`,`d`.`FECHA` AS `FECHA`,`d`.`SUBCTA` AS `SUBCTA`,`d`.`CONTRA` AS `CONTRA`,`d`.`CONCEPTO` AS `CONCEPTO`,`d`.`EURODEBE` AS `EURODEBE`,`d`.`EUROHABER` AS `EUROHABER`,`d`.`BASEEURO` AS `BASEEURO`,`d`.`SERIE` AS `SERIE`,`d`.`FACTURA` AS `FACTURA`,`d`.`IVA` AS `IVA`,`d`.`RECEQUIV` AS `RECEQUIV`,`d`.`CLAVE` AS `CLAVE`,`d`.`CAMBIO` AS `CAMBIO`,`d`.`DEBEME` AS `DEBEME`,`d`.`HABERME` AS `HABERME`,`d`.`AUXILIAR` AS `AUXILIAR`,`d`.`MONEDAUSO` AS `MONEDAUSO`,`d`.`TIPOOPE` AS `TIPOOPE`,`d`.`NFACTICK` AS `NFACTICK`,`d`.`TERIDNIF` AS `TERIDNIF`,`d`.`TERNIF` AS `TERNIF`,`d`.`TERNOM` AS `TERNOM`,`d`.`OPBIENES` AS `OPBIENES`,`d`.`L340` AS `L340`,`d`.`enlazado` AS `enlazado`,`d`.`FECHA_EX` AS `FECHA_EX`,`d`.`LRECT349` AS `LRECT349`,`d`.`empresa_id` AS `empresa_id`,`d`.`LDIFADUAN` AS `LDIFADUAN`,`d`.`METAL` AS `METAL`,`d`.`METALIMP` AS `METALIMP`,`d`.`CLIENTE` AS `CLIENTE`,`d`.`METALEJE` AS `METALEJE`,`d`.`FECHA_OP` AS `FECHA_OP`,`d`.`FACTURAEX` AS `FACTURAEX`,`d`.`TIPOCLAVE` AS `TIPOCLAVE`,`d`.`TIPOEXENCI` AS `TIPOEXENCI`,`d`.`TIPONOSUJE` AS `TIPONOSUJE`,`d`.`TIPOFACT` AS `TIPOFACT`,`d`.`TIPORECTIF` AS `TIPORECTIF`,`d`.`SERIE_RT` AS `SERIE_RT`,`d`.`FACTU_RT` AS `FACTU_RT`,`d`.`BASEIMP_RT` AS `BASEIMP_RT`,`d`.`BASEIMP_RF` AS `BASEIMP_RF`,`d`.`RECTIFICA` AS `RECTIFICA`,`d`.`FECHA_RT` AS `FECHA_RT`,`d`.`created` AS `created`,`d`.`updated` AS `updated`,`d`.`FECREGCON` AS `FECREGCON`,`d`.`enlazadoSage` AS `enlazadoSage` from `vn`.`XDiario` `d` */; +/*!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 `agency` +-- + +/*!50001 DROP VIEW IF EXISTS `agency`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `agency` AS select `a`.`id` AS `agency_id`,`a`.`name` AS `name`,`a`.`warehouseFk` AS `warehouse_id`,`a`.`warehouseAliasFk` AS `warehouse_alias_id`,`a`.`isOwn` AS `propios`,`a`.`workCenterFk` AS `workCenterFk` from `vn`.`agency` `a` */; +/*!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 `awb` +-- + +/*!50001 DROP VIEW IF EXISTS `awb`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `awb` AS select `a`.`id` AS `id`,`a`.`code` AS `codigo`,`a`.`package` AS `bultos`,`a`.`weight` AS `peso`,`a`.`created` AS `MYSQL_TIME`,`a`.`transitoryFk` AS `transitario_id`,`a`.`taxFk` AS `iva_id`,`a`.`duakk` AS `duakk`,`a`.`docFk` AS `gestdoc_id`,`a`.`amount` AS `importe`,`a`.`freightFk` AS `carguera_id`,`a`.`m3` AS `m3`,`a`.`stems` AS `stems`,`a`.`flightFk` AS `flight_id`,`a`.`volumeWeight` AS `volume_weight`,`a`.`hb` AS `hb`,`a`.`rate` AS `rate`,`a`.`booked` AS `booked`,`a`.`issued` AS `issued`,`a`.`operated` AS `operated`,`a`.`bookEntried` AS `bookEntried`,`a`.`invoiceInFk` AS `invoiceInFk`,`a`.`isChecked` AS `isChecked`,`a`.`isTransitoryChecked` AS `isTransitoryChecked`,`a`.`year` AS `year`,`a`.`invoiceInPaletizedFk` AS `invoiceInPaletizedFk`,`a`.`observation` AS `observation`,`a`.`hasFreightPrepaid` AS `hasFreightPrepaid`,`a`.`propertyNumber` AS `propertyNumber` from `vn`.`awb` `a` */; +/*!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 `barcodes` +-- + +/*!50001 DROP VIEW IF EXISTS `barcodes`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `barcodes` AS select `b`.`id` AS `id`,`b`.`itemFk` AS `Id_Article`,`b`.`code` AS `code` from `vn`.`itemBarcode` `b` */; +/*!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 `bionic_updating_options` +-- + +/*!50001 DROP VIEW IF EXISTS `bionic_updating_options`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `bionic_updating_options` AS select `t`.`id` AS `buo_id`,`t`.`description` AS `description` from `vn`.`ticketUpdateAction` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `businessReasonEnd` +-- + +/*!50001 DROP VIEW IF EXISTS `businessReasonEnd`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `businessReasonEnd` AS select `b`.`id` AS `id`,`b`.`reason` AS `reason` from `vn`.`businessReasonEnd` `b` */; +/*!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 `buySource` +-- + +/*!50001 DROP VIEW IF EXISTS `buySource`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `buySource` AS select `b`.`entryFk` AS `Id_Entrada`,`b`.`isPickedOff` AS `isPickedOff`,NULL AS `tarifa0`,`e`.`kop` AS `kop`,`b`.`id` AS `Id_Compra`,`i`.`typeFk` AS `tipo_id`,`b`.`itemFk` AS `Id_Article`,`i`.`size` AS `Medida`,`i`.`stems` AS `Tallos`,`b`.`stickers` AS `Etiquetas`,`b`.`packagingFk` AS `Id_Cubo`,`b`.`buyingValue` AS `Costefijo`,`b`.`packing` AS `Packing`,`b`.`grouping` AS `Grouping`,`b`.`quantity` AS `Cantidad`,`b`.`price2` AS `Tarifa2`,`b`.`price3` AS `Tarifa3`,`b`.`isChecked` AS `Punteo`,`b`.`groupingMode` AS `Caja`,`i`.`isToPrint` AS `Imprimir`,`i`.`name` AS `Article`,`vn`.`ink`.`picture` AS `Tinta`,`i`.`originFk` AS `id_origen`,`i`.`minPrice` AS `PVP`,NULL AS `Id_Accion`,`s`.`company_name` AS `pro`,`i`.`hasMinPrice` AS `Min`,`b`.`isIgnored` AS `Novincular`,`b`.`freightValue` AS `Portefijo`,round(`b`.`buyingValue` * `b`.`quantity`,2) AS `Importe`,`b`.`printedStickers` AS `Vida`,`i`.`comment` AS `reference`,`b`.`workerFk` AS `Id_Trabajador`,`e`.`s1` AS `S1`,`e`.`s2` AS `S2`,`e`.`s3` AS `S3`,`e`.`s4` AS `S4`,`e`.`s5` AS `S5`,`e`.`s6` AS `S6`,0 AS `price_fixed`,`i`.`producerFk` AS `producer_id`,`i`.`subName` AS `tag1`,`i`.`value5` AS `tag2`,`i`.`value6` AS `tag3`,`i`.`value7` AS `tag4`,`i`.`value8` AS `tag5`,`i`.`value9` AS `tag6`,`i`.`value10` AS `tag7`,`s`.`company_name` AS `company_name`,`b`.`weight` AS `weightPacking`,`i`.`packingOut` AS `packingOut`,`b`.`itemOriginalFk` AS `itemOriginalFk`,`io`.`longName` AS `itemOriginalName`,`it`.`gramsMax` AS `gramsMax`,`i`.`minQuantity` AS `minQuantity` from ((((((`vn`.`item` `i` join `vn`.`itemType` `it` on(`it`.`id` = `i`.`typeFk`)) left join `vn`.`ink` on(`vn`.`ink`.`id` = `i`.`inkFk`)) left join `vn`.`buy` `b` on(`b`.`itemFk` = `i`.`id`)) left join `vn`.`item` `io` on(`io`.`id` = `b`.`itemOriginalFk`)) left join `edi`.`ekt` `e` on(`e`.`id` = `b`.`ektFk`)) left join `edi`.`supplier` `s` on(`e`.`pro` = `s`.`supplier_id`)) */; +/*!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 `buy_edi` +-- + +/*!50001 DROP VIEW IF EXISTS `buy_edi`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `buy_edi` AS select `t`.`id` AS `id`,`t`.`barcode` AS `barcode`,`t`.`entryYear` AS `entry_year`,`t`.`deliveryNumber` AS `delivery_number`,`t`.`fec` AS `fec`,`t`.`hor` AS `hor`,`t`.`now` AS `now`,`t`.`ptj` AS `ptj`,`t`.`ref` AS `ref`,`t`.`item` AS `item`,`t`.`pac` AS `pac`,`t`.`qty` AS `qty`,`t`.`ori` AS `ori`,`t`.`cat` AS `cat`,`t`.`agj` AS `agj`,`t`.`kop` AS `kop`,`t`.`ptd` AS `ptd`,`t`.`sub` AS `sub`,`t`.`pro` AS `pro`,`t`.`pri` AS `pri`,`t`.`package` AS `package`,`t`.`auction` AS `auction`,`t`.`klo` AS `klo`,`t`.`k1` AS `k01`,`t`.`k2` AS `k02`,`t`.`k3` AS `k03`,`t`.`k4` AS `k04`,`t`.`s1` AS `s1`,`t`.`s2` AS `s2`,`t`.`s3` AS `s3`,`t`.`s4` AS `s4`,`t`.`s5` AS `s5`,`t`.`s6` AS `s6`,`t`.`ok` AS `ok`,`t`.`trolleyFk` AS `trolley_id`,`t`.`putOrderFk` AS `putOrderFk`,`t`.`scanned` AS `scanned` from `edi`.`ekt` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cdr` +-- + +/*!50001 DROP VIEW IF EXISTS `cdr`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cdr` AS select `c`.`call_date` AS `calldate`,`c`.`clid` AS `clid`,`c`.`src` AS `src`,`c`.`dst` AS `dst`,`c`.`dcontext` AS `dcontext`,`c`.`channel` AS `channel`,`c`.`dst_channel` AS `dstchannel`,`c`.`last_app` AS `lastapp`,`c`.`last_data` AS `lastdata`,`c`.`duration` AS `duration`,`c`.`billsec` AS `billsec`,`c`.`disposition` AS `disposition`,`c`.`ama_flags` AS `amaflags`,`c`.`account_code` AS `accountcode`,`c`.`unique_id` AS `uniqueid`,`c`.`user_field` AS `userfield` from `pbx`.`cdr` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `chanel` +-- + +/*!50001 DROP VIEW IF EXISTS `chanel`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `chanel` AS select `c`.`id` AS `chanel_id`,`c`.`name` AS `name` from `vn`.`contactChannel` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_act` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_act`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_act` AS select `c`.`id` AS `id`,`c`.`saleFk` AS `Id_Movimiento`,`c`.`claimFk` AS `cl_main_id`,`c`.`workerFk` AS `Id_Trabajador`,`c`.`claimDestinationFk` AS `cl_sol_id`,`c`.`isGreuge` AS `greuge` from `vn`.`claimEnd` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_cau` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_cau`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_cau` AS select `c`.`id` AS `id`,`c`.`claimFk` AS `cl_main_id`,`c`.`claimResponsibleFk` AS `cl_res_id`,`c`.`workerFk` AS `Id_Trabajador`,`c`.`claimReasonFk` AS `cl_mot_id`,`c`.`claimResultFk` AS `cl_con_id`,`c`.`claimRedeliveryFk` AS `cl_dev`,`c`.`claimDestinationFk` AS `cl_sol` from `vn`.`claimDevelopment` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_con` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_con`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_con` AS select `c`.`id` AS `id`,`c`.`description` AS `consecuencia` from `vn`.`claimResult` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_det` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_det`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_det` AS select `c`.`id` AS `id`,`c`.`claimFk` AS `cl_main_id`,`c`.`saleFk` AS `Id_Movimiento`,`c`.`quantity` AS `numero` from `vn`.`claimBeginning` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_dev` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_dev`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_dev` AS select `c`.`id` AS `id`,`c`.`description` AS `devolucion` from `vn`.`claimRedelivery` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_est` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_est`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_est` AS select `c`.`id` AS `id`,`c`.`description` AS `estado`,`c`.`roleFk` AS `roleFk` from `vn`.`claimState` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_main` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_main`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_main` AS select `c`.`id` AS `id`,`c`.`ticketCreated` AS `Fecha`,`c`.`claimStateFk` AS `cl_est_id`,`c`.`observation` AS `notas`,`c`.`clientFk` AS `Id_Cliente`,`c`.`workerFk` AS `Id_Trabajador`,`c`.`responsibility` AS `sensib`,`c`.`isChargedToMana` AS `mana`,`c`.`ticketFk` AS `ticketFk`,`c`.`created` AS `odbc_date` from `vn`.`claim` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_mot` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_mot`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_mot` AS select `c`.`id` AS `id`,`c`.`description` AS `motivo` from `vn`.`claimReason` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_res` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_res`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_res` AS select `c`.`id` AS `id`,`c`.`description` AS `responsable`,`c`.`responsability` AS `sensibility` from `vn`.`claimResponsible` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `cl_sol` +-- + +/*!50001 DROP VIEW IF EXISTS `cl_sol`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cl_sol` AS select `c`.`id` AS `id`,`c`.`description` AS `solucion`,`c`.`addressFk` AS `addressFk` from `vn`.`claimDestination` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `client_observation` +-- + +/*!50001 DROP VIEW IF EXISTS `client_observation`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `client_observation` AS select `co`.`id` AS `client_observation_id`,`co`.`clientFk` AS `Id_Cliente`,`co`.`workerFk` AS `Id_Trabajador`,`co`.`text` AS `text`,`co`.`created` AS `odbc_date` from `vn`.`clientObservation` `co` */; +/*!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 `clientes_gestdoc` +-- + +/*!50001 DROP VIEW IF EXISTS `clientes_gestdoc`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `clientes_gestdoc` AS select `cd`.`clientFk` AS `Id_Cliente`,`cd`.`dmsFk` AS `gest_doc_id` from `vn`.`clientDms` `cd` */; +/*!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 `clientes_regalos_enc` +-- + +/*!50001 DROP VIEW IF EXISTS `clientes_regalos_enc`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `clientes_regalos_enc` AS select `cpg`.`clientFk` AS `Id_Cliente`,`cpg`.`giftFk` AS `Id_Regalo`,`cpg`.`added` AS `odbc_date` from `vn`.`clientPackagingGifts` `cpg` */; +/*!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 `clientes_regalos_lista_enc` +-- + +/*!50001 DROP VIEW IF EXISTS `clientes_regalos_lista_enc`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `clientes_regalos_lista_enc` AS select `pg`.`id` AS `Id_Regalo`,`pg`.`description` AS `Descripcion`,`pg`.`photo` AS `foto`,if(`util`.`VN_CURDATE`() between `pg`.`started` and `pg`.`ended`,1,0) AS `activo`,`pg`.`started` AS `datstart`,`pg`.`ended` AS `datend`,ifnull(`pg`.`warehouseFk`,0) AS `warehouse_id`,ifnull(`pg`.`provinceFk`,0) AS `province_id`,ifnull(`pg`.`countryFk`,0) AS `countryFk` from `vn`.`packagingGifts` `pg` */; +/*!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 `clientes_tipo` +-- + +/*!50001 DROP VIEW IF EXISTS `clientes_tipo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `clientes_tipo` AS select `ct`.`id` AS `clientes_tipo_id`,`ct`.`code` AS `code`,`ct`.`type` AS `tipo`,`ct`.`isCreatedAsServed` AS `isCreatedAsServed` from `vn`.`clientType` `ct` */; +/*!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 `config_host` +-- + +/*!50001 DROP VIEW IF EXISTS `config_host`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `config_host` AS select `vn`.`host`.`code` AS `config_host_id`,`vn`.`host`.`warehouseFk` AS `warehouse`,`vn`.`host`.`companyFk` AS `empresaId`,`vn`.`host`.`bankFk` AS `caja`,`vn`.`host`.`printerFk` AS `Id_Impresora`,`vn`.`host`.`routeDaysBefore` AS `route_days_before`,`vn`.`host`.`routeDaysAfter` AS `route_days_after` from `vn`.`host` */; +/*!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 `consignatarios_observation` +-- + +/*!50001 DROP VIEW IF EXISTS `consignatarios_observation`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `consignatarios_observation` AS select `co`.`id` AS `consignatarios_observation_id`,`co`.`addressFk` AS `Id_Consigna`,`co`.`observationTypeFk` AS `observation_type_id`,`co`.`description` AS `text` from `vn`.`addressObservation` `co` */; +/*!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 `cooler_path_detail` +-- + +/*!50001 DROP VIEW IF EXISTS `cooler_path_detail`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `cooler_path_detail` AS select `cpd`.`id` AS `cooler_path_detail_id`,`cpd`.`coolerPathFk` AS `cooler_path_id`,`cpd`.`hallway` AS `pasillo` from `vn`.`coolerPathDetail` `cpd` */; +/*!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 `credit` +-- + +/*!50001 DROP VIEW IF EXISTS `credit`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `credit` AS select `c`.`id` AS `id`,`c`.`clientFk` AS `Id_Cliente`,`c`.`workerFk` AS `Id_Trabajador`,`c`.`amount` AS `amount`,`c`.`created` AS `odbc_date` from `vn`.`clientCredit` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `deliveryPoint` +-- + +/*!50001 DROP VIEW IF EXISTS `deliveryPoint`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `deliveryPoint` AS select `dp`.`id` AS `id`,`dp`.`name` AS `name`,`dp`.`ubication` AS `ubication` from `vn`.`deliveryPoint` `dp` */; +/*!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 `device_user` +-- + +/*!50001 DROP VIEW IF EXISTS `device_user`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `device_user` AS select `dpu`.`deviceProductionFk` AS `device_id`,`dpu`.`userFk` AS `user_id` from `vn`.`deviceProductionUser` `dpu` */; +/*!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 `edi_article` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_article`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_article` AS select `edi`.`item`.`id` AS `id`,`edi`.`item`.`product_name` AS `product_name`,`edi`.`item`.`name` AS `name`,`edi`.`item`.`plant_id` AS `plant_id`,`edi`.`item`.`group_id` AS `group_id`,`edi`.`item`.`entry_date` AS `entry_date`,`edi`.`item`.`expiry_date` AS `expiry_date`,`edi`.`item`.`change_date_time` AS `change_date_time` from `edi`.`item` */; +/*!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 `edi_bucket` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_bucket`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_bucket` AS select cast(`edi`.`bucket`.`bucket_id` as char charset utf8mb3) collate utf8mb3_general_ci AS `bucket_id`,`edi`.`bucket`.`bucket_type_id` AS `bucket_type_id`,`edi`.`bucket`.`description` AS `description`,`edi`.`bucket`.`x_size` AS `x_size`,`edi`.`bucket`.`y_size` AS `y_size`,`edi`.`bucket`.`z_size` AS `z_size`,`edi`.`bucket`.`entry_date` AS `entry_date`,`edi`.`bucket`.`expiry_date` AS `expiry_date`,`edi`.`bucket`.`change_date_time` AS `change_date_time` from `edi`.`bucket` */; +/*!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 `edi_bucket_type` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_bucket_type`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_bucket_type` AS select `edi`.`bucket_type`.`bucket_type_id` AS `bucket_type_id`,`edi`.`bucket_type`.`description` AS `description`,`edi`.`bucket_type`.`entry_date` AS `entry_date`,`edi`.`bucket_type`.`expiry_date` AS `expiry_date`,`edi`.`bucket_type`.`change_date_time` AS `change_date_time` from `edi`.`bucket_type` */; +/*!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 `edi_feature` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_feature`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_feature` AS select `edi`.`feature`.`item_id` AS `item_id`,`edi`.`feature`.`feature_type_id` AS `feature_type_id`,`edi`.`feature`.`feature_value` AS `feature_value`,`edi`.`feature`.`entry_date` AS `entry_date`,`edi`.`feature`.`expiry_date` AS `expiry_date`,`edi`.`feature`.`change_date_time` AS `change_date_time` from `edi`.`feature` */; +/*!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 `edi_genus` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_genus`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_genus` AS select `edi`.`genus`.`genus_id` AS `genus_id`,`edi`.`genus`.`latin_genus_name` AS `latin_genus_name`,`edi`.`genus`.`entry_date` AS `entry_date`,`edi`.`genus`.`expiry_date` AS `expiry_date`,`edi`.`genus`.`change_date_time` AS `change_date_time` from `edi`.`genus` */; +/*!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 `edi_item_feature` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_item_feature`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_item_feature` AS select `edi`.`item_feature`.`item_id` AS `item_id`,`edi`.`item_feature`.`presentation_order` AS `presentation_order`,`edi`.`item_feature`.`feature` AS `feature`,`edi`.`item_feature`.`regulation_type` AS `regulation_type`,`edi`.`item_feature`.`entry_date` AS `entry_date`,`edi`.`item_feature`.`expiry_date` AS `expiry_date`,`edi`.`item_feature`.`change_date_time` AS `change_date_time` from `edi`.`item_feature` */; +/*!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 `edi_plant` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_plant`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_plant` AS select `edi`.`plant`.`plant_id` AS `plant_id`,`edi`.`plant`.`genus_id` AS `genus_id`,`edi`.`plant`.`specie_id` AS `specie_id`,`edi`.`plant`.`entry_date` AS `entry_date`,`edi`.`plant`.`expiry_date` AS `expiry_date`,`edi`.`plant`.`change_date_time` AS `change_date_time` from `edi`.`plant` */; +/*!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 `edi_specie` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_specie`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_specie` AS select `edi`.`specie`.`specie_id` AS `specie_id`,`edi`.`specie`.`genus_id` AS `genus_id`,`edi`.`specie`.`latin_species_name` AS `latin_species_name`,`edi`.`specie`.`entry_date` AS `entry_date`,`edi`.`specie`.`expiry_date` AS `expiry_date`,`edi`.`specie`.`change_date_time` AS `change_date_time` from `edi`.`specie` */; +/*!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 `edi_supplier` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_supplier`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_supplier` AS select `edi`.`supplier`.`supplier_id` AS `supplier_id`,`edi`.`supplier`.`company_name` AS `company_name` from `edi`.`supplier` */; +/*!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 `edi_type` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_type`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_type` AS select `edi`.`type`.`type_id` AS `type_id`,`edi`.`type`.`type_group_id` AS `type_group_id`,`edi`.`type`.`description` AS `description`,`edi`.`type`.`entry_date` AS `entry_date`,`edi`.`type`.`expiry_date` AS `expiry_date`,`edi`.`type`.`change_date_time` AS `change_date_time` from `edi`.`type` */; +/*!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 `edi_value` +-- + +/*!50001 DROP VIEW IF EXISTS `edi_value`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `edi_value` AS select `edi`.`value`.`type_id` AS `type_id`,`edi`.`value`.`type_value` AS `type_value`,`edi`.`value`.`type_description` AS `type_description`,`edi`.`value`.`entry_date` AS `entry_date`,`edi`.`value`.`expiry_date` AS `expiry_date`,`edi`.`value`.`change_date_time` AS `change_date_time` from `edi`.`value` */; +/*!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 `empresa` +-- + +/*!50001 DROP VIEW IF EXISTS `empresa`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `empresa` AS select `c`.`id` AS `id`,`c`.`code` AS `abbreviation`,`c`.`supplierAccountFk` AS `Id_Proveedores_account`,`c`.`workerManagerFk` AS `gerente_id`,`c`.`sage200Company` AS `digito_factura`,`c`.`phytosanitary` AS `phytosanitary`,`c`.`companyCode` AS `CodigoEmpresa`,`c`.`companyGroupFk` AS `empresa_grupo`,`c`.`isDefaulter` AS `morosidad`,`c`.`expired` AS `baja`,`c`.`register` AS `registro`,`c`.`registered` AS `alta`,`c`.`logo` AS `logo`,`c`.`isOfficial` AS `oficial`,`c`.`hasCyc` AS `cyc`,`c`.`rgb` AS `rgb`,`c`.`email` AS `mail`,`c`.`stamp` AS `cuno`,`c`.`created` AS `ODBC_DATE`,`c`.`clientFk` AS `Id_Cliente` from `vn`.`company` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `empresa_grupo` +-- + +/*!50001 DROP VIEW IF EXISTS `empresa_grupo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `empresa_grupo` AS select `vn`.`companyGroup`.`id` AS `empresa_grupo_id`,`vn`.`companyGroup`.`code` AS `grupo` from `vn`.`companyGroup` */; +/*!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 `entrySource` +-- + +/*!50001 DROP VIEW IF EXISTS `entrySource`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `entrySource` AS select `e`.`gestDocFk` AS `gestdoc_id`,`e`.`id` AS `Id_Entrada`,`e`.`invoiceNumber` AS `invoiceNumber`,`e`.`reference` AS `reference`,`e`.`isExcludedFromAvailable` AS `Inventario`,`e`.`isConfirmed` AS `Confirmada`,`e`.`isOrdered` AS `Pedida`,`e`.`isRaid` AS `Redada`,`e`.`evaNotes` AS `notas`,`e`.`supplierFk` AS `Id_Proveedor`,`tr`.`shipped` AS `shipment`,`tr`.`landed` AS `landing`,`w2`.`name` AS `wh_in`,`w1`.`name` AS `wh_out`,`am`.`name` AS `Agencia`,`e`.`commission` AS `comision`,`tr`.`warehouseInFk` AS `warehouse_id`,`w1`.`id` AS `warehouse_id_out`,`e`.`isBooked` AS `anotadoencaja`,`e`.`invoiceInFk` AS `invoiceInFk`,`e`.`companyFk` AS `empresa_id`,`e`.`currencyFk` AS `Id_Moneda`,`tr`.`id` AS `TravelFk`,`e`.`sub` AS `sub`,`e`.`kop` AS `kop`,`e`.`pro` AS `pro`,`e`.`invoiceAmount` AS `invoiceAmount`,`w`.`code` AS `buyerCode`,`e`.`typeFk` AS `typeFk`,`w3`.`code` AS `observationWorkerCode` from (((((((`vn`.`entry` `e` left join `vn`.`travel` `tr` on(`e`.`travelFk` = `tr`.`id`)) left join `vn`.`agencyMode` `am` on(`am`.`id` = `tr`.`agencyModeFk`)) left join `vn`.`warehouse` `w1` on(`tr`.`warehouseOutFk` = `w1`.`id`)) left join `vn`.`warehouse` `w2` on(`tr`.`warehouseInFk` = `w2`.`id`)) left join `vn`.`supplier` `s` on(`e`.`supplierFk` = `s`.`id`)) left join `vn`.`worker` `w` on(`w`.`id` = `e`.`buyerFk`)) left join `vn`.`worker` `w3` on(`w3`.`id` = `e`.`observationEditorFk`)) */; +/*!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 `escritos` +-- + +/*!50001 DROP VIEW IF EXISTS `escritos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `escritos` AS select `s`.`id` AS `id`,`s`.`code` AS `abrev`,`s`.`description` AS `descripcion`,`s`.`isVisible` AS `visible`,`s`.`hasCompany` AS `hasCompany` from `vn`.`sample` `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 `escritos_det` +-- + +/*!50001 DROP VIEW IF EXISTS `escritos_det`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `escritos_det` AS select `cs`.`id` AS `id`,`cs`.`clientFk` AS `Id_Cliente`,`cs`.`typeFk` AS `escritos_id`,`cs`.`created` AS `fecha`,`cs`.`workerFk` AS `Id_Trabajador`,`cs`.`userFk` AS `userFk`,`cs`.`companyFk` AS `empresa_id`,`cs`.`balance` AS `saldo` from `vn`.`clientSample` `cs` */; +/*!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 `expeditions` +-- + +/*!50001 DROP VIEW IF EXISTS `expeditions`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `expeditions` AS select `e`.`id` AS `expeditions_id`,`e`.`agencyModeFk` AS `agency_id`,`e`.`ticketFk` AS `ticket_id`,`e`.`freightItemFk` AS `EsBulto`,`e`.`created` AS `odbc_date`,`e`.`counter` AS `counter`,`e`.`workerFk` AS `workerFk`,`e`.`externalId` AS `externalId`,`p`.`itemFk` AS `Id_article` from (`vn`.`expedition` `e` left join `vn`.`packaging` `p` on(`p`.`id` = `e`.`packagingFk`)) */; +/*!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 `gestdoc` +-- + +/*!50001 DROP VIEW IF EXISTS `gestdoc`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `gestdoc` AS select `d`.`id` AS `id`,`d`.`dmsTypeFk` AS `gesttip_id`,`d`.`file` AS `file`,`d`.`contentType` AS `contentType`,`d`.`workerFk` AS `trabajador_id`,`d`.`warehouseFk` AS `warehouse_id`,`d`.`companyFk` AS `emp_id`,`d`.`hardCopyNumber` AS `orden`,`d`.`hasFile` AS `original`,`d`.`reference` AS `sref`,`d`.`description` AS `brief`,`d`.`created` AS `odbc_date` from `vn`.`dms` `d` */; +/*!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 `gesttip` +-- + +/*!50001 DROP VIEW IF EXISTS `gesttip`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `gesttip` AS select `g`.`id` AS `id`,`g`.`name` AS `tipo`,`g`.`path` AS `path`,`g`.`readRoleFk` AS `readRoleFk`,`g`.`writeRoleFk` AS `writeRoleFk`,`g`.`code` AS `code` from `vn`.`dmsType` `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 `intrastat_data` +-- + +/*!50001 DROP VIEW IF EXISTS `intrastat_data`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `intrastat_data` AS select `ii`.`id` AS `id`,`ii`.`invoiceInFk` AS `recibida_id`,`ii`.`net` AS `neto`,`ii`.`intrastatFk` AS `intrastat_id`,`ii`.`amount` AS `importe`,`ii`.`stems` AS `unidades`,`ii`.`countryFk` AS `Paises_Id`,`ii`.`dated` AS `odbc_date`,`ii`.`statisticalValue` AS `valorestadistico` from `vn`.`invoiceInIntrastat` `ii` */; +/*!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 `invoiceCorrection` +-- + +/*!50001 DROP VIEW IF EXISTS `invoiceCorrection`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `invoiceCorrection` AS select `ic`.`correctingFk` AS `correctingFk`,`ic`.`correctedFk` AS `correctedFk`,`ic`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,`ic`.`siiTypeInvoiceOutFk` AS `siiTypeInvoiceOutFk`,`ic`.`invoiceCorrectionTypeFk` AS `invoiceCorrectionTypeFk` from `vn`.`invoiceCorrection` `ic` */; +/*!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 `itemTag` +-- + +/*!50001 DROP VIEW IF EXISTS `itemTag`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `itemTag` AS select `i`.`id` AS `id`,`i`.`itemFk` AS `itemFk`,`i`.`tagFk` AS `tagFk`,`i`.`value` AS `value`,`i`.`priority` AS `priority` from `vn`.`itemTag` `i` */; +/*!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 `item_entry_in` +-- + +/*!50001 DROP VIEW IF EXISTS `item_entry_in`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `item_entry_in` AS select `t`.`warehouse_id` AS `warehouse_id`,`t`.`warehouse_id_out` AS `warehouse_id_out`,`t`.`landing` AS `dat`,`m`.`Id_Article` AS `item_id`,`m`.`Cantidad` AS `amount`,`t`.`received` AS `received`,`e`.`Redada` AS `isVirtualStock`,`e`.`Id_Entrada` AS `entryFk` from ((`vn2008`.`Compres` `m` join `vn2008`.`Entradas` `e` on(`m`.`Id_Entrada` = `e`.`Id_Entrada`)) join `vn2008`.`travel` `t` on(`e`.`travel_id` = `t`.`id`)) where `e`.`Inventario` = 0 and `m`.`Cantidad` <> 0 */; +/*!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 `item_entry_out` +-- + +/*!50001 DROP VIEW IF EXISTS `item_entry_out`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `item_entry_out` AS select `t`.`warehouse_id_out` AS `warehouse_id`,`t`.`shipment` AS `dat`,`m`.`Id_Article` AS `item_id`,-`m`.`Cantidad` AS `amount`,`t`.`delivered` <> 0 or ifnull(`co`.`valor`,0) AS `delivered`,`e`.`Id_Entrada` AS `entryFk` from (((`vn2008`.`Compres` `m` join `vn2008`.`Entradas` `e` on(`m`.`Id_Entrada` = `e`.`Id_Entrada`)) join `vn2008`.`travel` `t` on(`e`.`travel_id` = `t`.`id`)) left join `vn2008`.`Compres_ok` `co` on(`co`.`Id_Compra` = `m`.`Id_Compra` and `co`.`Id_Accion` = 3 and `co`.`valor` <> 0)) where `e`.`Inventario` = 0 and `e`.`Redada` = 0 and `m`.`Cantidad` <> 0 */; +/*!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 `item_out` +-- + +/*!50001 DROP VIEW IF EXISTS `item_out`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `item_out` AS select `t`.`warehouse_id` AS `warehouse_id`,`t`.`Fecha` AS `dat`,`m`.`Id_Article` AS `item_id`,-`m`.`Cantidad` AS `amount`,`m`.`OK` AS `ok`,`m`.`Reservado` AS `Reservado`,`t`.`Factura` AS `invoice`,`m`.`Id_Movimiento` AS `saleFk`,`m`.`Id_Ticket` AS `ticketFk` from (`vn2008`.`Movimientos` `m` join `vn2008`.`Tickets` `t` on(`m`.`Id_Ticket` = `t`.`Id_Ticket`)) where `m`.`Cantidad` <> 0 */; +/*!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 `iva_codigo` +-- + +/*!50001 DROP VIEW IF EXISTS `iva_codigo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `iva_codigo` AS select `tc`.`id` AS `id`,`tc`.`dated` AS `fecha`,`tc`.`code` AS `codigo`,`tc`.`taxTypeFk` AS `iva_tipo_id`,`tc`.`rate` AS `iva`,`tc`.`equalizationTax` AS `recargo`,`tc`.`type` AS `tipo`,`tc`.`link` AS `link`,`tc`.`isActive` AS `isActive`,`tc`.`updated` AS `updated`,`tc`.`transactionCode` AS `transactionCode` from `vn`.`taxCode` `tc` */; +/*!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 `iva_group` +-- + +/*!50001 DROP VIEW IF EXISTS `iva_group`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `iva_group` AS select `tc`.`id` AS `iva_group_id`,`tc`.`description` AS `description`,`tc`.`code` AS `code` from `vn`.`taxClass` `tc` */; +/*!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 `iva_group_codigo` +-- + +/*!50001 DROP VIEW IF EXISTS `iva_group_codigo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `iva_group_codigo` AS select `tcc`.`taxClassFk` AS `iva_group_id`,`tcc`.`effectived` AS `date`,`tcc`.`taxCodeFk` AS `iva_codigo_id` from `vn`.`taxClassCode` `tcc` */; +/*!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 `iva_tipo` +-- + +/*!50001 DROP VIEW IF EXISTS `iva_tipo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `iva_tipo` AS select `tt`.`id` AS `id`,`tt`.`nickname` AS `alias`,`tt`.`isAccrued` AS `isAccrued`,`tt`.`serial` AS `serie_id`,`tt`.`TIPOOPE` AS `TIPOOPE`,`tt`.`description` AS `descripcion`,`tt`.`countryFk` AS `Id_Pais` from `vn`.`taxType` `tt` */; +/*!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 `mail` +-- + +/*!50001 DROP VIEW IF EXISTS `mail`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `mail` AS select `m`.`id` AS `id`,`m`.`senderFk` AS `senderFk`,`m`.`recipientFk` AS `recipientFk`,`m`.`receiver` AS `to`,`m`.`replyTo` AS `reply_to`,`m`.`subject` AS `subject`,`m`.`body` AS `text`,`m`.`plainTextBody` AS `plainTextBody`,`m`.`attachment` AS `path`,`m`.`creationDate` AS `DATE_ODBC`,`m`.`sent` AS `sent`,`m`.`status` AS `error` from `vn`.`mail` `m` */; +/*!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 `mandato` +-- + +/*!50001 DROP VIEW IF EXISTS `mandato`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `mandato` AS select `m`.`id` AS `id`,`m`.`clientFk` AS `Id_Cliente`,`m`.`companyFk` AS `empresa_id`,`m`.`code` AS `Id_mandato`,`m`.`created` AS `FAlta`,`m`.`finished` AS `Fbaja`,`m`.`mandateTypeFk` AS `idmandato_tipo` from `vn`.`mandate` `m` */; +/*!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 `mandato_tipo` +-- + +/*!50001 DROP VIEW IF EXISTS `mandato_tipo`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `mandato_tipo` AS select `m`.`id` AS `idmandato_tipo`,`m`.`name` AS `Nombre` from `vn`.`mandateType` `m` */; +/*!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 `observation_type` +-- + +/*!50001 DROP VIEW IF EXISTS `observation_type`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `observation_type` AS select `co`.`id` AS `observation_type_id`,`co`.`description` AS `description` from `vn`.`observationType` `co` */; +/*!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 `order` +-- + +/*!50001 DROP VIEW IF EXISTS `order`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `order` AS select `hedera`.`order`.`id` AS `id`,`hedera`.`order`.`date_make` AS `date_make`,`hedera`.`order`.`date_send` AS `date_send`,`hedera`.`order`.`customer_id` AS `customer_id`,`hedera`.`order`.`delivery_method_id` AS `delivery_method_id`,`hedera`.`order`.`agency_id` AS `agency_id`,`hedera`.`order`.`address_id` AS `address_id`,`hedera`.`order`.`note` AS `note`,`hedera`.`order`.`confirmed` AS `confirmed`,`hedera`.`order`.`is_bionic` AS `is_bionic`,`hedera`.`order`.`source_app` AS `source_app` from `hedera`.`order` */; +/*!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 `order_Tickets` +-- + +/*!50001 DROP VIEW IF EXISTS `order_Tickets`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `order_Tickets` AS select `ot`.`orderFk` AS `order_id`,`ot`.`ticketFk` AS `Id_Ticket` from `vn`.`orderTicket` `ot` */; +/*!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 `order_component` +-- + +/*!50001 DROP VIEW IF EXISTS `order_component`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `order_component` AS select `c`.`order_row_id` AS `order_row_id`,`c`.`component_id` AS `component_id`,`c`.`price` AS `price` from `hedera`.`order_component` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `order_row` +-- + +/*!50001 DROP VIEW IF EXISTS `order_row`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `order_row` AS select `order_row`.`id` AS `id`,`order_row`.`order_id` AS `order_id`,`order_row`.`item_id` AS `item_id`,`order_row`.`warehouse_id` AS `warehouse_id`,`order_row`.`shipment` AS `shipment`,`order_row`.`amount` AS `amount`,`order_row`.`price` AS `price`,`order_row`.`rate` AS `rate`,`order_row`.`created` AS `created`,`order_row`.`Id_Movimiento` AS `Id_Movimiento` from `hedera`.`order_row` */; +/*!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 `pago` +-- + +/*!50001 DROP VIEW IF EXISTS `pago`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `pago` AS select `p`.`id` AS `id`,`p`.`received` AS `fecha`,`p`.`dueDated` AS `dueDated`,`p`.`supplierFk` AS `id_proveedor`,`p`.`amount` AS `importe`,`p`.`currencyFk` AS `id_moneda`,`p`.`divisa` AS `divisa`,`p`.`bankFk` AS `id_banco`,`p`.`payMethodFk` AS `pay_met_id`,`p`.`companyFk` AS `empresa_id`,`p`.`isConciliated` AS `conciliado`,`p`.`bankingFees` AS `g_bancarios`,`p`.`concept` AS `concepte`,`p`.`created` AS `odbc_date` from `vn`.`payment` `p` */; +/*!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 `pay_dem` +-- + +/*!50001 DROP VIEW IF EXISTS `pay_dem`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `pay_dem` AS select `pd`.`id` AS `id`,`pd`.`payDem` AS `pay_dem` from `vn`.`payDem` `pd` */; +/*!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 `pay_dem_det` +-- + +/*!50001 DROP VIEW IF EXISTS `pay_dem_det`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `pay_dem_det` AS select `pdd`.`id` AS `id`,`pdd`.`detail` AS `detalle` from `vn`.`payDemDetail` `pdd` */; +/*!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 `pay_met` +-- + +/*!50001 DROP VIEW IF EXISTS `pay_met`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `pay_met` AS select `pm`.`id` AS `id`,`pm`.`name` AS `name`,`pm`.`graceDays` AS `graceDays`,`pm`.`outstandingDebt` AS `deudaviva`,`pm`.`solution` AS `solucion`,`pm`.`isNotified` AS `isNotified` from `vn`.`payMethod` `pm` */; +/*!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 `payroll_categorias` +-- + +/*!50001 DROP VIEW IF EXISTS `payroll_categorias`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `payroll_categorias` AS select `pc`.`id` AS `codcategoria`,`pc`.`rate` AS `Tarifa`,`pc`.`description` AS `descripcion` from `vn`.`payrollCategories` `pc` */; +/*!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 `person_user` +-- + +/*!50001 DROP VIEW IF EXISTS `person_user`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `person_user` AS select `u`.`id` AS `id`,`u`.`role` AS `mysql_user_id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`active` AS `active`,`u`.`lastPassChange` AS `last_pass_change` from `account`.`user` `u` */; +/*!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 `person_user_idtrabajador` +-- + +/*!50001 DROP VIEW IF EXISTS `person_user_idtrabajador`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `person_user_idtrabajador` AS select `t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn2008`.`person_user` `p` join `vn2008`.`Trabajadores` `t` on(`p`.`id` = `t`.`user_id`)) where `t`.`user_id` = `account`.`myUser_getId`() */; +/*!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 `plantpassport` +-- + +/*!50001 DROP VIEW IF EXISTS `plantpassport`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `plantpassport` AS select `pp`.`producerFk` AS `producer_id`,`pp`.`plantpassportAuthorityFk` AS `plantpassport_authority_id`,`pp`.`number` AS `number`,`pp`.`isRequested` AS `isRequested` from `vn`.`plantpassport` `pp` */; +/*!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 `plantpassport_authority` +-- + +/*!50001 DROP VIEW IF EXISTS `plantpassport_authority`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `plantpassport_authority` AS select `ppa`.`id` AS `plantpassport_authority_id`,`ppa`.`denomination` AS `denomination`,`ppa`.`countryFk` AS `Paises_Id` from `vn`.`plantpassportAuthority` `ppa` */; +/*!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 `price_fixed` +-- + +/*!50001 DROP VIEW IF EXISTS `price_fixed`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `price_fixed` AS select `pf`.`itemFk` AS `item_id`,`pf`.`rate0` AS `rate_0`,`pf`.`rate1` AS `rate_1`,`pf`.`rate2` AS `rate_2`,`pf`.`rate3` AS `rate_3`,`pf`.`started` AS `date_start`,`pf`.`ended` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`warehouseFk` AS `warehouse_id`,`pf`.`created` AS `odbc_date`,`pf`.`id` AS `price_fixed_id`,`pf`.`grouping` AS `grouping`,`pf`.`packing` AS `Packing`,`pf`.`box` AS `caja` from `vn`.`priceFixed` `pf` */; +/*!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 `producer` +-- + +/*!50001 DROP VIEW IF EXISTS `producer`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `producer` AS select `p`.`id` AS `producer_id`,`p`.`name` AS `name`,`p`.`isVisible` AS `visible` from `vn`.`producer` `p` */; +/*!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 `proveedores_clientes` +-- + +/*!50001 DROP VIEW IF EXISTS `proveedores_clientes`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `proveedores_clientes` AS select `Proveedores`.`Id_Proveedor` AS `Id_Proveedor`,`Proveedores`.`Proveedor` AS `Proveedor`,`Clientes`.`id_cliente` AS `Id_Cliente`,`Clientes`.`cliente` AS `Cliente` from (`vn2008`.`Proveedores` join `vn2008`.`Clientes` on(`Proveedores`.`NIF` = `Clientes`.`if`)) */; +/*!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 `province` +-- + +/*!50001 DROP VIEW IF EXISTS `province`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `province` AS select `p`.`id` AS `province_id`,`p`.`name` AS `name`,`p`.`countryFk` AS `Paises_Id`,`p`.`warehouseFk` AS `warehouse_id`,`p`.`zoneFk` AS `zone`,`p`.`geoFk` AS `geoFk` from `vn`.`province` `p` */; +/*!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 `recibida` +-- + +/*!50001 DROP VIEW IF EXISTS `recibida`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `recibida` AS select `r`.`id` AS `id`,`r`.`serialNumber` AS `num_recibida`,`r`.`serial` AS `serie`,`r`.`supplierFk` AS `proveedor_id`,`r`.`issued` AS `fecha`,`r`.`supplierRef` AS `sref`,`r`.`isBooked` AS `contabilizada`,`r`.`currencyFk` AS `moneda_id`,`r`.`created` AS `MYSQL_TIME`,`r`.`companyFk` AS `empresa_id`,`r`.`docFk` AS `gestdoc_id`,`r`.`booked` AS `dateBooking`,`r`.`operated` AS `dateOperation`,`r`.`siiTypeInvoiceInFk` AS `siiTypeInvoiceInFk`,`r`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,`r`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,`r`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,`r`.`siiTrascendencyInvoiceInFk` AS `siiTrascendencyInvoiceInFk`,`r`.`bookEntried` AS `bookEntried`,`r`.`isVatDeductible` AS `isVatDeductible`,`r`.`withholdingSageFk` AS `withholdingSageFk`,`r`.`expenseFkDeductible` AS `expenseFkDeductible` from `vn`.`invoiceIn` `r` */; +/*!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 `recibida_intrastat` +-- + +/*!50001 DROP VIEW IF EXISTS `recibida_intrastat`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `recibida_intrastat` AS select `i`.`invoiceInFk` AS `recibida_id`,`i`.`intrastatFk` AS `Codintrastat`,`i`.`amount` AS `importe` from `vn`.`invoiceInIntrastat` `i` */; +/*!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 `recibida_iva` +-- + +/*!50001 DROP VIEW IF EXISTS `recibida_iva`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `recibida_iva` AS select `i`.`id` AS `id`,`i`.`invoiceInFk` AS `recibida_id`,`i`.`taxCodeFk` AS `iva_id`,`i`.`taxableBase` AS `bi`,`i`.`expenseFk` AS `gastos_id`,`i`.`foreignValue` AS `divisa`,`i`.`taxTypeSageFk` AS `taxTypeSageFk`,`i`.`transactionTypeSageFk` AS `transactionTypeSageFk`,`i`.`created` AS `MYSQL_TIME` from `vn`.`invoiceInTax` `i` */; +/*!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 `recibida_vencimiento` +-- + +/*!50001 DROP VIEW IF EXISTS `recibida_vencimiento`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `recibida_vencimiento` AS select `r`.`id` AS `id`,`r`.`invoiceInFk` AS `recibida_id`,`r`.`dueDated` AS `fecha`,`r`.`bankFk` AS `banco_id`,`r`.`amount` AS `cantidad`,`r`.`foreignValue` AS `divisa`,`r`.`created` AS `stamp` from `vn`.`invoiceInDueDay` `r` */; +/*!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 `recovery` +-- + +/*!50001 DROP VIEW IF EXISTS `recovery`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `recovery` AS select `r`.`id` AS `recovery_id`,`r`.`clientFk` AS `Id_Cliente`,`r`.`started` AS `dstart`,`r`.`finished` AS `dend`,`r`.`amount` AS `amount`,`r`.`period` AS `period` from `vn`.`recovery` `r` */; +/*!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 `reference_min` +-- + +/*!50001 DROP VIEW IF EXISTS `reference_min`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `reference_min` AS select `rc`.`dated` AS `date`,`rc`.`value` AS `rate`,`rc`.`currencyFk` AS `moneda_id` from `vn`.`referenceCurrent` `rc` */; +/*!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 `reference_rate` +-- + +/*!50001 DROP VIEW IF EXISTS `reference_rate`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `reference_rate` AS select `rr`.`currencyFk` AS `moneda_id`,`rr`.`dated` AS `date`,`rr`.`value` AS `rate` from `vn`.`referenceRate` `rr` */; +/*!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 `reinos` +-- + +/*!50001 DROP VIEW IF EXISTS `reinos`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `reinos` AS select `r`.`id` AS `id`,`r`.`name` AS `reino`,`r`.`display` AS `display`,`r`.`color` AS `color`,`r`.`icon` AS `icon`,`r`.`merchandise` AS `mercancia`,`r`.`order` AS `orden`,`r`.`shortLife` AS `efimero` from `vn`.`itemCategory` `r` */; +/*!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 `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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `sharingcart` AS select `sc`.`id` AS `id`,`sc`.`workerFk` AS `Id_Trabajador`,`sc`.`started` AS `datSTART`,`sc`.`ended` AS `datEND`,`sc`.`workerSubstitute` AS `Id_Suplente`,`sc`.`created` AS `odbc_date` from `vn`.`sharingCart` `sc` */; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `sharingclient` AS select `sc`.`id` AS `id`,`sc`.`workerFk` AS `Id_Trabajador`,`sc`.`started` AS `datSTART`,`sc`.`ended` AS `datEND`,`sc`.`clientFk` AS `Id_Cliente` from `vn`.`sharingClient` `sc` */; +/*!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 `sms` +-- + +/*!50001 DROP VIEW IF EXISTS `sms`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `sms` AS select `t`.`id` AS `id`,`t`.`senderFk` AS `Id_trabajador`,`t`.`sender` AS `from`,`t`.`destination` AS `to`,`t`.`message` AS `text`,`t`.`statusCode` AS `sent`,`t`.`status` AS `response`,`t`.`created` AS `DATE_ODBC` from `vn`.`sms` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `state` +-- + +/*!50001 DROP VIEW IF EXISTS `state`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `state` AS select `s`.`id` AS `id`,`s`.`name` AS `name`,`s`.`order` AS `order`,`s`.`alertLevel` AS `alert_level`,`s`.`code` AS `code`,`s`.`sectorProdPriority` AS `sectorProdPriority`,`s`.`nextStateFk` AS `nextStateFk`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from `vn`.`state` `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 `tag` +-- + +/*!50001 DROP VIEW IF EXISTS `tag`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tag` AS select `t`.`id` AS `id`,`t`.`name` AS `name`,`t`.`isFree` AS `isFree`,`t`.`isQuantitatif` AS `isQuantitatif`,`t`.`sourceTable` AS `sourceTable`,`t`.`unit` AS `unit` from `vn`.`tag` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `tarifa_componentes` +-- + +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tarifa_componentes` AS select `tarifa_componentes`.`Id_Componente` AS `Id_Componente`,`tarifa_componentes`.`Componente` AS `Componente`,`tarifa_componentes`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`,`tarifa_componentes`.`tarifa_class` AS `tarifa_class`,`tarifa_componentes`.`tax` AS `tax`,`tarifa_componentes`.`is_renewable` AS `is_renewable` from `bi`.`tarifa_componentes` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `tarifa_componentes_series` +-- + +/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tarifa_componentes_series` AS select `tarifa_componentes_series`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`,`tarifa_componentes_series`.`Serie` AS `Serie`,`tarifa_componentes_series`.`base` AS `base` from `bi`.`tarifa_componentes_series` */; +/*!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 `tarifas` +-- + +/*!50001 DROP VIEW IF EXISTS `tarifas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tarifas` AS select `r`.`id` AS `tarifa_id`,`r`.`dated` AS `fecha`,`r`.`warehouseFk` AS `warehouse_id`,`r`.`rate0` AS `t0`,`r`.`rate1` AS `t1`,`r`.`rate2` AS `t2`,`r`.`rate3` AS `t3` from `vn`.`rate` `r` */; +/*!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 `tblContadores` +-- + +/*!50001 DROP VIEW IF EXISTS `tblContadores`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tblContadores` AS select `c`.`id` AS `id`,`c`.`ochoa` AS `ochoa`,`c`.`invoiceOutFk` AS `nfactura`,`c`.`inventoried` AS `FechaInventario`,`c`.`itemLog` AS `HistoricoArticulo`,`c`.`weekGoal` AS `week_goal`,`c`.`photosPath` AS `Rutafotos`,`c`.`cashBoxNumber` AS `numCaja`,`c`.`redCode` AS `CodigoRojo`,`c`.`TabletTime` AS `Tablet_Hora`,`c`.`t0` AS `t0`,`c`.`t1` AS `t1`,`c`.`t2` AS `t2`,`c`.`t3` AS `t3`,`c`.`cc` AS `cc`,`c`.`palet` AS `palet`,`c`.`campaign` AS `campaign`,`c`.`campaignLife` AS `campaign_life`,`c`.`truckDays` AS `truck_days`,`c`.`transportCharges` AS `tasa_transporte`,`c`.`escanerPath` AS `escaner_path`,`c`.`printedTurn` AS `turnoimpreso`,`c`.`truckLength` AS `truck_length`,`c`.`fuelConsumption` AS `fuel_consumption`,`c`.`petrol` AS `petrol`,`c`.`maintenance` AS `maintenance`,`c`.`hourPrice` AS `hour_price`,`c`.`meterPrice` AS `meter_price`,`c`.`kmPrice` AS `km_price`,`c`.`routeOption` AS `route_option`,`c`.`dbproduccion` AS `dbproduccion`,`c`.`mdbServer` AS `mdbServer`,`c`.`fakeEmail` AS `fakeEmail`,`c`.`defaultersMaxAmount` AS `defaultersMaxAmount`,`c`.`ASIEN` AS `ASIEN` from `vn`.`config` `c` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `thermograph` +-- + +/*!50001 DROP VIEW IF EXISTS `thermograph`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `thermograph` AS select `t`.`id` AS `thermograph_id`,`t`.`model` AS `model` from `vn`.`thermograph` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `ticketCreationData` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketCreationData`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketCreationData` AS select dayname(`h`.`confirm_date`) AS `DiadelaSemana`,hour(`h`.`confirm_date`) AS `Hora`,cast(`h`.`confirm_date` as date) AS `Fecha`,`h`.`source_app` AS `Dispositivo` from `hedera`.`order` `h` where `h`.`confirm_date` <> 0 */; +/*!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 `ticketMRW` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketMRW`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketMRW` AS select `Tickets`.`Id_Agencia` AS `id_Agencia`,`Tickets`.`empresa_id` AS `empresa_id`,`Consignatarios`.`consignatario` AS `Consignatario`,`Consignatarios`.`domicilio` AS `DOMICILIO`,`Consignatarios`.`poblacion` AS `POBLACION`,`Consignatarios`.`codPostal` AS `CODPOSTAL`,`Consignatarios`.`telefono` AS `telefono`,`Consignatarios`.`movil` AS `movil`,`Clientes`.`if` AS `IF`,`Tickets`.`Id_Ticket` AS `Id_Ticket`,`Tickets`.`warehouse_id` AS `warehouse_id`,`Consignatarios`.`id_consigna` AS `Id_Consigna`,`Paises`.`Codigo` AS `CodigoPais`,`Tickets`.`Fecha` AS `Fecha`,`province`.`province_id` AS `province_id`,`Tickets`.`landing` AS `landing` from ((((`vn2008`.`Clientes` join `vn2008`.`Consignatarios` on(`Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente`)) join `vn2008`.`Tickets` on(`Consignatarios`.`id_consigna` = `Tickets`.`Id_Consigna`)) join `vn2008`.`province` on(`Consignatarios`.`province_id` = `province`.`province_id`)) join `vn2008`.`Paises` on(`province`.`Paises_Id` = `Paises`.`Id`)) */; +/*!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 `ticket_observation` +-- + +/*!50001 DROP VIEW IF EXISTS `ticket_observation`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticket_observation` AS select `to`.`id` AS `ticket_observation_id`,`to`.`ticketFk` AS `Id_Ticket`,`to`.`observationTypeFk` AS `observation_type_id`,`to`.`description` AS `text` from `vn`.`ticketObservation` `to` */; +/*!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 `tickets_gestdoc` +-- + +/*!50001 DROP VIEW IF EXISTS `tickets_gestdoc`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tickets_gestdoc` AS select `td`.`ticketFk` AS `Id_Ticket`,`td`.`dmsFk` AS `gestdoc_id` from `vn`.`ticketDms` `td` */; +/*!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 `time` +-- + +/*!50001 DROP VIEW IF EXISTS `time`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `time` AS select `t`.`dated` AS `date`,`t`.`period` AS `period`,`t`.`month` AS `month`,`t`.`year` AS `year`,`t`.`day` AS `day`,`t`.`week` AS `week`,`t`.`yearMonth` AS `yearMonth` from `vn`.`time` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `tr2` +-- + +/*!50001 DROP VIEW IF EXISTS `tr2`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `tr2` AS select `vn`.`travel`.`id` AS `id`,`vn`.`travel`.`shipped` AS `shipped`,`vn`.`travel`.`shipmentHour` AS `shipmentHour`,`vn`.`travel`.`landed` AS `landed`,`vn`.`travel`.`landingHour` AS `landingHour`,`vn`.`travel`.`warehouseInFk` AS `warehouseInFk`,`vn`.`travel`.`warehouseOutFk` AS `warehouseOutFk`,`vn`.`travel`.`agencyModeFk` AS `agencyFk`,`vn`.`travel`.`ref` AS `ref`,`vn`.`travel`.`isDelivered` AS `isDelivered`,`vn`.`travel`.`isReceived` AS `isReceived`,`vn`.`travel`.`m3` AS `m3`,`vn`.`travel`.`kg` AS `kg`,`vn`.`travel`.`cargoSupplierFk` AS `cargoSupplierFk`,`vn`.`travel`.`totalEntries` AS `totalEntries` from `vn`.`travel` */; +/*!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 `travel` +-- + +/*!50001 DROP VIEW IF EXISTS `travel`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `travel` AS select `t`.`id` AS `id`,`t`.`shipped` AS `shipment`,`t`.`shipmentHour` AS `shipment_hour`,`t`.`landed` AS `landing`,`t`.`landingHour` AS `landing_hour`,`t`.`warehouseInFk` AS `warehouse_id`,`t`.`warehouseOutFk` AS `warehouse_id_out`,`t`.`agencyModeFk` AS `agency_id`,`t`.`ref` AS `ref`,`t`.`isDelivered` AS `delivered`,`t`.`isReceived` AS `received`,`t`.`m3` AS `m3`,`t`.`kg` AS `kg`,`t`.`cargoSupplierFk` AS `cargoSupplierFk`,`t`.`totalEntries` AS `totalEntries`,`t`.`appointment` AS `appointment` from `vn`.`travel` `t` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `travel_thermograph` +-- + +/*!50001 DROP VIEW IF EXISTS `travel_thermograph`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `travel_thermograph` AS select `tt`.`thermographFk` AS `thermograph_id`,`tt`.`created` AS `odbc_date`,`tt`.`warehouseFk` AS `warehouse_id`,`tt`.`travelFk` AS `travel_id`,`tt`.`temperatureFk` AS `temperature`,`tt`.`result` AS `result`,`tt`.`dmsFk` AS `gestdoc_id` from `vn`.`travelThermograph` `tt` */; +/*!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 `v_Articles_botanical` +-- + +/*!50001 DROP VIEW IF EXISTS `v_Articles_botanical`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_Articles_botanical` AS select `ib`.`itemFk` AS `itemFk`,concat(`g`.`name`,' ',ifnull(`s`.`name`,'')) AS `ediBotanic` from (((`vn`.`itemBotanical` `ib` left join `vn`.`genus` `g` on(`g`.`id` = `ib`.`genusFk`)) left join `vn`.`specie` `s` on(`s`.`id` = `ib`.`specieFk`)) left join `vn`.`ediSpecie` `es` on(`es`.`id` = `ib`.`specieFk`)) */; +/*!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 `v_account` +-- + +/*!50001 DROP VIEW IF EXISTS `v_account`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_account` AS select `a`.`id` AS `user_id` from `account`.`account` `a` */; +/*!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 `v_analisis_ventas` +-- + +/*!50001 DROP VIEW IF EXISTS `v_analisis_ventas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_analisis_ventas` AS select `bi`.`analisis_ventas`.`Familia` AS `Familia`,`bi`.`analisis_ventas`.`Reino` AS `Reino`,`bi`.`analisis_ventas`.`Comercial` AS `Comercial`,`bi`.`analisis_ventas`.`Comprador` AS `Comprador`,`bi`.`analisis_ventas`.`Provincia` AS `Provincia`,`bi`.`analisis_ventas`.`almacen` AS `almacen`,`bi`.`analisis_ventas`.`Año` AS `Año`,`bi`.`analisis_ventas`.`Mes` AS `Mes`,`bi`.`analisis_ventas`.`Semana` AS `Semana`,`bi`.`analisis_ventas`.`Vista` AS `Vista`,`bi`.`analisis_ventas`.`Importe` AS `Importe` from `bi`.`analisis_ventas` */; +/*!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 `v_barcodes` +-- + +/*!50001 DROP VIEW IF EXISTS `v_barcodes`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_barcodes` AS select `Articles`.`Id_Article` AS `code`,`Articles`.`Id_Article` AS `Id_Article` from `vn2008`.`Articles` union all select `barcodes`.`code` AS `code`,`barcodes`.`Id_Article` AS `Id_Article` from `vn2008`.`barcodes` union all select `c`.`Id_Compra` AS `Id_Compra`,`c`.`Id_Article` AS `Id_Article` from ((`vn2008`.`Compres` `c` join `vn2008`.`Entradas` `e` on(`c`.`Id_Entrada` = `e`.`Id_Entrada`)) join `vn2008`.`travel` `tr` on(`tr`.`id` = `e`.`travel_id`)) where `tr`.`landing` >= `util`.`VN_CURDATE`() + interval -15 day */; +/*!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 `v_compres` +-- + +/*!50001 DROP VIEW IF EXISTS `v_compres`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_compres` AS select `TP`.`Id_Tipo` AS `Familia`,`RN`.`id` AS `reino_id`,`C`.`Id_Compra` AS `Id_Compra`,`C`.`Id_Entrada` AS `Id_Entrada`,`C`.`Id_Article` AS `Id_Article`,`C`.`Cantidad` AS `Cantidad`,`C`.`Costefijo` AS `Costefijo`,`C`.`Portefijo` AS `Portefijo`,`C`.`Novincular` AS `Novincular`,`C`.`Etiquetas` AS `Etiquetas`,`C`.`Packing` AS `Packing`,`C`.`grouping` AS `grouping`,`C`.`Comisionfija` AS `Comisionfija`,`C`.`Embalajefijo` AS `Embalajefijo`,`C`.`Id_Cubo` AS `Id_Cubo`,`C`.`Tarifa1` AS `Tarifa1`,`C`.`Tarifa2` AS `Tarifa2`,`C`.`Tarifa3` AS `Tarifa3`,`C`.`PVP` AS `PVP`,`C`.`Vida` AS `Vida`,`C`.`Id_Trabajador` AS `Id_Trabajador`,`C`.`punteo` AS `punteo`,`C`.`odbc_date` AS `odbc_date`,`E`.`Inventario` AS `Inventario`,`E`.`Id_Proveedor` AS `Id_Proveedor`,`E`.`Fecha` AS `Fecha`,`E`.`Confirmada` AS `Confirmada`,`E`.`Redada` AS `Redada`,`E`.`empresa_id` AS `empresa_id`,`E`.`travel_id` AS `travel_id`,`E`.`Pedida` AS `Pedida`,`E`.`recibida_id` AS `recibida_id`,`TR`.`id` AS `id`,`TR`.`shipment` AS `shipment`,`TR`.`landing` AS `landing`,`TR`.`warehouse_id` AS `warehouse_id`,`TR`.`warehouse_id_out` AS `warehouse_id_out`,`TR`.`agency_id` AS `agency_id`,`TR`.`ref` AS `ref`,`TR`.`delivered` AS `delivered`,`TR`.`received` AS `received`,`A`.`Article` AS `Article`,`A`.`Medida` AS `Medida`,`A`.`Tallos` AS `Tallos`,`C`.`caja` AS `caja`,`A`.`Categoria` AS `Categoria`,`A`.`id_origen` AS `id_origen`,`TP`.`Id_Tipo` AS `Tipo`,`A`.`tipo_id` AS `tipo_id`,`A`.`Color` AS `Color`,`A`.`Min` AS `Min`,`C`.`Costefijo` + `C`.`Embalajefijo` + `C`.`Comisionfija` + `C`.`Portefijo` AS `Coste`,`W_OUT`.`fuente` AS `fuente`,if(`cb`.`Volumen` > 0,`cb`.`Volumen`,`cb`.`X` * `cb`.`Y` * if(`cb`.`Z` = 0,`A`.`Medida` + 10,`cb`.`Z`)) * `C`.`Etiquetas` AS `cm3`,`A`.`producer_id` AS `producer_id` from ((((((((`vn2008`.`Compres` `C` join `vn2008`.`Entradas` `E` on(`C`.`Id_Entrada` = `E`.`Id_Entrada`)) join `vn2008`.`travel` `TR` on(`TR`.`id` = `E`.`travel_id`)) join `vn2008`.`warehouse` `W_IN` on(`W_IN`.`id` = `TR`.`warehouse_id`)) join `vn2008`.`warehouse` `W_OUT` on(`W_OUT`.`id` = `TR`.`warehouse_id_out`)) join `vn2008`.`Articles` `A` on(`C`.`Id_Article` = `A`.`Id_Article`)) join `vn2008`.`Tipos` `TP` on(`A`.`tipo_id` = `TP`.`tipo_id`)) join `vn2008`.`reinos` `RN` on(`RN`.`id` = `TP`.`reino_id`)) join `vn2008`.`Cubos` `cb` on(`cb`.`Id_Cubo` = `C`.`Id_Cubo`)) where `W_IN`.`fuente` = 0 and `E`.`Inventario` = 0 and `E`.`Redada` = 0 */; +/*!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 `v_departure_limit` +-- + +/*!50001 DROP VIEW IF EXISTS `v_departure_limit`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_departure_limit` AS select `cache`.`departure_limit`.`warehouse_id` AS `warehouse_id`,`cache`.`departure_limit`.`fecha` AS `fecha`,`cache`.`departure_limit`.`hora` AS `hora`,`cache`.`departure_limit`.`minSpeed` AS `minSpeed` from `cache`.`departure_limit` */; +/*!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 `v_descuadre_bionic` +-- + +/*!50001 DROP VIEW IF EXISTS `v_descuadre_bionic`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_descuadre_bionic` AS select `t`.`Id_Ticket` AS `Id_Ticket`,`t`.`Alias` AS `Alias`,`m`.`Concepte` AS `Concepte`,sum(`mc`.`Valor`) AS `suma_componente`,`m`.`Preu` AS `Preu`,`m`.`Descuento` AS `Descuento`,`m`.`Preu` * (100 - `m`.`Descuento`) / 100 - sum(`mc`.`Valor`) AS `diferencia`,`t`.`Fecha` AS `Fecha`,`m`.`Preu` > 0 and `tp`.`reino_id` <> 6 and `a`.`tipo_id` not in (7,115) AS `benvenut` from ((((((`vn2008`.`Movimientos` `m` join `vn2008`.`Tickets` `t` on(`m`.`Id_Ticket` = `t`.`Id_Ticket`)) join `vn2008`.`Clientes` `c` on(`t`.`Id_Cliente` = `c`.`id_cliente`)) join `vn2008`.`warehouse` `w` on(`w`.`id` = `t`.`warehouse_id`)) join `vn2008`.`Articles` `a` on(`m`.`Id_Article` = `a`.`Id_Article`)) join `vn2008`.`Tipos` `tp` on(`a`.`tipo_id` = `tp`.`tipo_id`)) left join `vn2008`.`Movimientos_componentes` `mc` on(`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`)) where `t`.`Fecha` >= '2015-09-01' and `t`.`empresa_id` in (442,791,567) and `w`.`reserve` <> 0 and `c`.`real` <> 0 and `tp`.`reino_id` <> 6 group by `m`.`Id_Movimiento` having abs(`diferencia`) > 0.01 or `diferencia` is null */; +/*!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 `v_empresa` +-- + +/*!50001 DROP VIEW IF EXISTS `v_empresa`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_empresa` AS select `e`.`logo` AS `logo`,`e`.`id` AS `id`,`e`.`registro` AS `registro`,`e`.`gerente_id` AS `gerente_id`,`e`.`alta` AS `alta`,`t`.`Nombre` AS `Nombre`,`t`.`Apellidos` AS `Apellidos`,`p`.`Proveedor` AS `Proveedor`,`p`.`Domicilio` AS `Domicilio`,`p`.`codpos` AS `CP`,`p`.`Localidad` AS `Localidad`,`p`.`NIF` AS `NIF`,`p`.`Telefono` AS `Telefono`,`p`.`Alias` AS `Alias`,`e`.`abbreviation` AS `abbreviation` from ((`vn2008`.`empresa` `e` join `vn2008`.`Trabajadores` `t` on(`t`.`Id_Trabajador` = `e`.`gerente_id`)) join `vn2008`.`Proveedores` `p` on(`p`.`Id_Proveedor` = `e`.`id`)) */; +/*!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 `v_inter` +-- + +/*!50001 DROP VIEW IF EXISTS `v_inter`*/; +/*!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 = utf8mb3 */; +/*!50001 SET character_set_results = utf8mb3 */; +/*!50001 SET collation_connection = utf8mb3_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_inter` AS select `tt`.`id` AS `inter_id`,`tt`.`stateFk` AS `state_id`,`tt`.`notes` AS `nota`,`tt`.`created` AS `odbc_date`,`tt`.`ticketFk` AS `Id_Ticket`,`tt`.`userFk` AS `Id_Trabajador`,`tt`.`supervisorFk` AS `Id_supervisor` from `vn`.`ticketTracking` `tt` */; +/*!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 `v_jerarquia` +-- + +/*!50001 DROP VIEW IF EXISTS `v_jerarquia`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_jerarquia` AS select `jerarquia`.`worker_id` AS `Id_Trabajador`,`jerarquia`.`boss_id` AS `boss_id` from `jerarquia` union all select distinct `jerarquia`.`boss_id` AS `Id_Trabajador`,`jerarquia`.`boss_id` AS `boss_id` from `jerarquia` */; +/*!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 `v_miriam` +-- + +/*!50001 DROP VIEW IF EXISTS `v_miriam`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_miriam` AS select `M`.`Id_Article` AS `Id_Article`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,`T`.`Fecha` AS `Fecha`,`T`.`Id_Cliente` AS `Id_Cliente`,`M`.`Cantidad` * `M`.`Preu` * (100 - `M`.`Descuento`) / 100 AS `Importe` from (((`vn2008`.`Tickets` `T` join `vn2008`.`Movimientos` `M` on(`T`.`Id_Ticket` = `M`.`Id_Ticket`)) join `vn2008`.`Articles` `A` on(`M`.`Id_Article` = `A`.`Id_Article`)) join `vn2008`.`Tipos` `TP` on(`A`.`tipo_id` = `TP`.`tipo_id`)) where `T`.`Fecha` >= '2011-01-01' and `A`.`tipo_id` = 7 */; +/*!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 `v_price_fixed` +-- + +/*!50001 DROP VIEW IF EXISTS `v_price_fixed`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_price_fixed` AS select `pf`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from `vn2008`.`price_fixed` `pf` where `pf`.`warehouse_id` < 1000 union all select `wg`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from (`vn2008`.`price_fixed` `pf` join `vn2008`.`warehouse_group` `wg`) where `wg`.`warehouse_alias_id` + 1000 = `pf`.`warehouse_id` */; +/*!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 `v_price_fixed_group` +-- + +/*!50001 DROP VIEW IF EXISTS `v_price_fixed_group`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_price_fixed_group` AS select `pf`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from `vn2008`.`v_price_fixed` `pf` group by `pf`.`warehouse_id`,`pf`.`item_id`,`pf`.`date_start`,`pf`.`date_end` */; +/*!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 `v_ticket_amount` +-- + +/*!50001 DROP VIEW IF EXISTS `v_ticket_amount`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_ticket_amount` AS select `Movimientos`.`Id_Ticket` AS `Id_Ticket`,sum(`Movimientos`.`Cantidad` * `Movimientos`.`Preu` * (100 - `Movimientos`.`Descuento`) / 100) AS `amount` from (`vn2008`.`Movimientos` join `vn2008`.`Tickets` on(`Movimientos`.`Id_Ticket` = `Tickets`.`Id_Ticket`)) where `Tickets`.`Fecha` >= `util`.`VN_CURDATE`() + interval -6 month group by `Movimientos`.`Id_Ticket` */; +/*!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 `v_ventes` +-- + +/*!50001 DROP VIEW IF EXISTS `v_ventes`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_ventes` AS select `Agencias`.`Agencia` AS `Agencia`,`A`.`Categoria` AS `Categoria`,`A`.`tipo_id` AS `tipo_id`,`A`.`Medida` AS `Medida`,`A`.`Article` AS `Article`,`A`.`Color` AS `Color`,`CS`.`Id_cliente` AS `Id_Cliente`,`TP`.`Id_Tipo` AS `Tipo`,`T`.`Factura` AS `Factura`,`T`.`warehouse_id` AS `warehouse_id`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`M`.`Id_Article` AS `Id_Article`,`TP`.`Id_Tipo` AS `Familia`,`M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`quantity` AS `quantity`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,if(`T`.`Fecha` >= '2015-10-01',`M`.`CostFixat`,`M`.`Preu` * (100 - `M`.`Descuento`) / 100) AS `CostFixat`,`M`.`Reservado` AS `Reservado`,`M`.`OK` AS `OK`,`M`.`PrecioFijado` AS `PrecioFijado`,`M`.`odbc_date` AS `odbc_date`,cast(`T`.`Fecha` as date) AS `Fecha`,`T`.`Fecha` AS `FechaCompleta`,`CS`.`consignatario` AS `Alias`,`T`.`Id_Consigna` AS `Id_Consigna`,`M`.`Cantidad` * `M`.`Preu` * (100 - `M`.`Descuento`) / 100 AS `Importe`,`O`.`Origen` AS `Origen`,`TP`.`reino_id` AS `reino_id`,`C`.`invoice` AS `invoice`,`A`.`producer_id` AS `producer_id` from ((((((((`vn2008`.`Movimientos` `M` join `vn2008`.`Tickets` `T` on(`M`.`Id_Ticket` = `T`.`Id_Ticket`)) join `vn2008`.`Consignatarios` `CS` on(`CS`.`id_consigna` = `T`.`Id_Consigna`)) join `vn2008`.`Clientes` `C` on(`CS`.`Id_cliente` = `C`.`id_cliente`)) join `vn2008`.`Articles` `A` on(`M`.`Id_Article` = `A`.`Id_Article`)) join `vn2008`.`Origen` `O` on(`O`.`id` = `A`.`id_origen`)) join `vn2008`.`Tipos` `TP` on(`A`.`tipo_id` = `TP`.`tipo_id`)) join `vn2008`.`reinos` `r` on(`TP`.`reino_id` = `r`.`id`)) join `vn2008`.`Agencias` on(`Agencias`.`Id_Agencia` = `T`.`Id_Agencia`)) where `T`.`Fecha` >= '2013-01-01' and `C`.`real` > 0 and `r`.`id` <> 6 */; +/*!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 `v_warehouse` +-- + +/*!50001 DROP VIEW IF EXISTS `v_warehouse`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_warehouse` AS select `warehouse`.`id` AS `id`,`warehouse`.`name` AS `almacen` from `vn2008`.`warehouse` union all select 1000 + `warehouse_alias`.`warehouse_alias_id` AS `warehouse_alias_id`,concat(`warehouse_alias`.`alias`,'(G)') AS `concat(alias, '(G)')` from `vn2008`.`warehouse_alias` */; +/*!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 `v_xsubclien` +-- + +/*!50001 DROP VIEW IF EXISTS `v_xsubclien`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_xsubclien` AS select distinct `Facturas`.`Id_Cliente` AS `Id_Cliente`,`Facturas`.`empresa_id` AS `empresa_id` from `vn2008`.`Facturas` where `Facturas`.`Fecha` > `util`.`VN_CURDATE`() + interval -2 month union select `Recibos`.`Id_Cliente` AS `Id_Cliente`,`Recibos`.`empresa_id` AS `empresa_id` from `vn2008`.`Recibos` where `Recibos`.`Fechacobro` > `util`.`VN_CURDATE`() + interval -2 month */; +/*!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 `v_xsubcuentas` +-- + +/*!50001 DROP VIEW IF EXISTS `v_xsubcuentas`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_xsubcuentas` AS select `Clientes`.`Cuenta` AS `COD`,`Clientes`.`razonSocial` AS `TITULO`,concat(if(`p`.`CEE` = 1 and ascii(left(`Clientes`.`if`,1)) < 58,`p`.`Codigo`,''),`Clientes`.`if`) AS `NIF`,`Clientes`.`domicilio` AS `DOMICILIO`,`Clientes`.`poblacion` AS `POBLACION`,`province`.`name` AS `PROVINCIA`,`Clientes`.`codPostal` AS `CODPOSTAL`,`p`.`Codigo` AS `country_code`,`v_xsubclien`.`empresa_id` AS `empresa_id`,substr(`Clientes`.`e-mail`,1,coalesce(nullif(locate(',',`Clientes`.`e-mail`),0),99) - 1) AS `EMAIL`,if(`p`.`CEE` = 0 or `p`.`CEE` = 1 and `Clientes`.`vies` = 0,1,if(`p`.`CEE` = 1 and `Clientes`.`vies` <> 0,2,4)) AS `IDNIF` from (((`vn2008`.`Clientes` join `vn2008`.`v_xsubclien` on(`Clientes`.`id_cliente` = `v_xsubclien`.`Id_Cliente`)) left join `vn2008`.`Paises` `p` on(`p`.`Id` = `Clientes`.`Id_Pais`)) join `vn2008`.`province` on(`Clientes`.`province_id` = `province`.`province_id`)) group by `Clientes`.`id_cliente`,`v_xsubclien`.`empresa_id` union all select `Proveedores`.`cuenta` AS `Cuenta`,`Proveedores`.`Proveedor` AS `Proveedor`,concat(if(`p`.`CEE` = 1 and ascii(left(`Proveedores`.`NIF`,1)) < 58,`p`.`Codigo`,''),`Proveedores`.`NIF`) AS `NIF`,`Proveedores`.`Domicilio` AS `Domicilio`,`Proveedores`.`Localidad` AS `Localidad`,`prov`.`name` AS `Provincia`,`Proveedores`.`codpos` AS `CP`,`p`.`Codigo` AS `country_code`,`v_xsubprov`.`empresa_id` AS `empresa_id`,substr(`c`.`email`,1,coalesce(nullif(locate(',',`c`.`email`),0),99) - 1) AS `EMAIL`,if(`p`.`CEE` = 0,1,if(`p`.`CEE` = 1,2,4)) AS `IDNIF` from ((((`vn2008`.`Proveedores` join `vn2008`.`v_xsubprov` on(`Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id`)) left join `vn2008`.`Paises` `p` on(`p`.`Id` = `Proveedores`.`pais_id`)) left join `vn2008`.`province` `prov` on(`prov`.`province_id` = `Proveedores`.`province_id`)) left join `vn`.`supplierContact` `c` on(`c`.`supplierFk` = `Proveedores`.`Id_Proveedor`)) where `Proveedores`.`oficial` <> 0 group by `v_xsubprov`.`proveedor_id`,`v_xsubprov`.`empresa_id` union all select `Gastos`.`Id_Gasto` collate utf8mb3_unicode_ci AS `Id_Gasto`,`Gastos`.`Gasto` collate utf8mb3_unicode_ci AS `Gasto`,NULL AS `NULL`,NULL AS `My_exp_NULL`,NULL AS `My_exp_1_NULL`,NULL AS `My_exp_2_NULL`,NULL AS `My_exp_3_NULL`,NULL AS `country_code`,`e`.`id` AS `id`,NULL AS `EMAIL`,1 AS `IDNIF` from (`vn2008`.`Gastos` join `vn2008`.`empresa` `e` on(`e`.`id` = 442)) union all select `Bancos`.`Cuenta` AS `Cuenta`,`Bancos`.`Banco` AS `Banco`,NULL AS `NULL`,NULL AS `My_exp_NULL`,NULL AS `My_exp_1_NULL`,NULL AS `My_exp_2_NULL`,NULL AS `My_exp_3_NULL`,NULL AS `country_code`,`e`.`id` AS `id`,NULL AS `EMAIL`,1 AS `IDNIF` from (`vn2008`.`Bancos` join `vn2008`.`empresa` `e` on(`e`.`id` = 442)) union all select lpad(right(`Proveedores`.`cuenta`,5),10,'47510000') AS `Cuenta`,`Proveedores`.`Proveedor` AS `Proveedor`,`Proveedores`.`NIF` AS `NIF`,`Proveedores`.`Domicilio` AS `Domicilio`,`Proveedores`.`Localidad` AS `Localidad`,`prov`.`name` AS `Provincia`,`Proveedores`.`codpos` AS `CP`,`p`.`Codigo` AS `country_code`,`v_xsubprov`.`empresa_id` AS `empresa_id`,substr(`c`.`email`,1,coalesce(nullif(locate(',',`c`.`email`),0),99) - 1) AS `EMAIL`,if(`p`.`CEE` = 0,1,if(`p`.`CEE` = 1,2,4)) AS `IDNIF` from ((((`vn2008`.`Proveedores` join `vn2008`.`v_xsubprov` on(`Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id`)) left join `vn2008`.`Paises` `p` on(`p`.`Id` = `Proveedores`.`pais_id`)) left join `vn2008`.`province` `prov` on(`prov`.`province_id` = `Proveedores`.`province_id`)) left join `vn`.`supplierContact` `c` on(`c`.`supplierFk` = `Proveedores`.`Id_Proveedor`)) where (`Proveedores`.`cuenta` like '_____3____' or `Proveedores`.`cuenta` like '_____2____') and `Proveedores`.`oficial` = 1 group by `v_xsubprov`.`proveedor_id`,`v_xsubprov`.`empresa_id` */; +/*!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 `v_xsubprov` +-- + +/*!50001 DROP VIEW IF EXISTS `v_xsubprov`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v_xsubprov` AS select `recibida`.`proveedor_id` AS `proveedor_id`,`recibida`.`empresa_id` AS `empresa_id` from `vn2008`.`recibida` where `recibida`.`fecha` > `util`.`VN_CURDATE`() + interval -3 month group by `recibida`.`proveedor_id`,`recibida`.`empresa_id` union all select `pago`.`id_proveedor` AS `id_proveedor`,`pago`.`empresa_id` AS `empresa_id` from `vn2008`.`pago` where `pago`.`fecha` > `util`.`VN_CURDATE`() + interval -3 month group by `pago`.`id_proveedor`,`pago`.`empresa_id` */; +/*!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 `versiones` +-- + +/*!50001 DROP VIEW IF EXISTS `versiones`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `versiones` AS select `m`.`app` AS `programa`,`m`.`version` AS `version`,0 AS `critical` from `vn`.`mdbVersion` `m` where `m`.`branchFk` = 'master' */; +/*!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 `vnCreditClassification` +-- + +/*!50001 DROP VIEW IF EXISTS `vnCreditClassification`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `vnCreditClassification` AS select `vn`.`creditClassification`.`id` AS `id`,`vn`.`creditClassification`.`client` AS `client`,`vn`.`creditClassification`.`dateStart` AS `dateStart`,`vn`.`creditClassification`.`dateEnd` AS `dateEnd` from `vn`.`creditClassification` */; +/*!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 `vnCreditInsurance` +-- + +/*!50001 DROP VIEW IF EXISTS `vnCreditInsurance`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `vnCreditInsurance` AS select `vn`.`creditInsurance`.`id` AS `id`,`vn`.`creditInsurance`.`creditClassification` AS `creditClassification`,`vn`.`creditInsurance`.`credit` AS `credit`,`vn`.`creditInsurance`.`creationDate` AS `creationDate`,`vn`.`creditInsurance`.`grade` AS `grade` from `vn`.`creditInsurance` */; +/*!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 `vnSolunionCAP` +-- + +/*!50001 DROP VIEW IF EXISTS `vnSolunionCAP`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `vnSolunionCAP` AS select `vn`.`solunionCAP`.`creditInsurance` AS `creditInsurance`,`vn`.`solunionCAP`.`dateStart` AS `dateStart`,`vn`.`solunionCAP`.`dateEnd` AS `dateEnd`,`vn`.`solunionCAP`.`dateLeaving` AS `dateLeaving` from `vn`.`solunionCAP` */; +/*!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 `warehouse` +-- + +/*!50001 DROP VIEW IF EXISTS `warehouse`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `warehouse` AS select `w`.`id` AS `id`,`w`.`name` AS `name`,`w`.`isInventory` AS `inventario`,`w`.`isFeedStock` AS `fuente`,`w`.`isComparative` AS `is_comparative`,`w`.`hasComission` AS `comisionantes`,`w`.`hasAvailable` AS `reserve`,`w`.`isManaged` AS `isManaged`,`w`.`isForTicket` AS `tpv`,`w`.`hasStowaway` AS `hasStowaway`,`w`.`hasDms` AS `hasDms`,`w`.`addressName` AS `address_name`,`w`.`delay` AS `delay`,`w`.`countryFk` AS `Id_Paises`,`w`.`labelZone` AS `zone_label`,`w`.`valuatedInventory` AS `valuatedInventory`,`w`.`hasConfectionTeam` AS `hasConfectionTeam` from `vn`.`warehouse` `w` */; +/*!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 `warehouse_alias` +-- + +/*!50001 DROP VIEW IF EXISTS `warehouse_alias`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `warehouse_alias` AS select `wa`.`id` AS `warehouse_alias_id`,`wa`.`name` AS `alias` from `vn`.`warehouseAlias` `wa` */; +/*!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 `workcenter_holiday` +-- + +/*!50001 DROP VIEW IF EXISTS `workcenter_holiday`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `workcenter_holiday` AS select `wh`.`workCenterFk` AS `workcenter_id`,`wh`.`days` AS `day`,`wh`.`year` AS `year` from `vn`.`workCenterHoliday` `wh` */; +/*!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 `workerDocument` +-- + +/*!50001 DROP VIEW IF EXISTS `workerDocument`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `workerDocument` AS select `vn`.`workerDocument`.`id` AS `id`,`vn`.`workerDocument`.`worker` AS `worker`,`vn`.`workerDocument`.`document` AS `document`,`vn`.`workerDocument`.`isReadableByWorker` AS `isReadableByWorker` from `vn`.`workerDocument` */; +/*!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 `workerTeam` +-- + +/*!50001 DROP VIEW IF EXISTS `workerTeam`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `workerTeam` AS select `wt`.`team` AS `team`,`wt`.`id` AS `id`,`wt`.`workerFk` AS `user` from `vn`.`workerTeam` `wt` */; +/*!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 `zoneNickname` +-- + +/*!50001 DROP VIEW IF EXISTS `zoneNickname`*/; +/*!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 = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `zoneNickname` AS select `ap`.`warehouse_id` AS `warehouse_id`,`ap`.`agency_id` AS `agency_id`,`ap`.`zona` AS `zona`,concat('ZONA ',`ap`.`zona`,' ',if(`ap`.`zona` = 20,'Madrid',`p`.`name`)) AS `alias` from (`vn2008`.`Agencias_province` `ap` join `vn2008`.`province` `p` on(`p`.`province_id` = `ap`.`province_id`)) group by `ap`.`zona`,`ap`.`warehouse_id`,`ap`.`agency_id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83216,4 +98089,4 @@ USE `vn`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 10:10:52 +-- Dump completed on 2024-01-04 8:19:06 diff --git a/db/dump/Dockerfile b/db/dump/Dockerfile new file mode 100644 index 000000000..72bcf54d5 --- /dev/null +++ b/db/dump/Dockerfile @@ -0,0 +1,5 @@ +FROM mariadb:10.7.7 + +ENV TZ Europe/Madrid + +COPY db.cnf /etc/mysql/conf.d/z99-local.cnf diff --git a/db/dump/db.cnf b/db/dump/db.cnf new file mode 100644 index 000000000..3dafaf514 --- /dev/null +++ b/db/dump/db.cnf @@ -0,0 +1,9 @@ +[mysqld] +log-bin = bin.log +max_binlog_size = 1GB +binlog_row_image = noblob +binlog_format = row +expire_logs_days = 2 + +binlog-ignore-db = tmp +binlog-ignore-db = PERCONA_SCHEMA diff --git a/db/dump/dump.after.sql b/db/dump/dump.after.sql new file mode 100644 index 000000000..f1a121b2a --- /dev/null +++ b/db/dump/dump.after.sql @@ -0,0 +1 @@ +-- Executed after dump diff --git a/db/dump/dump.before.sql b/db/dump/dump.before.sql new file mode 100644 index 000000000..24168fe60 --- /dev/null +++ b/db/dump/dump.before.sql @@ -0,0 +1 @@ +-- Executed before dump diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql deleted file mode 100644 index 3e46c8e04..000000000 --- a/db/dump/dumpedFixtures.sql +++ /dev/null @@ -1,793 +0,0 @@ - -USE `util`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: util --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `config` --- - -LOCK TABLES `config` WRITE; -/*!40000 ALTER TABLE `config` DISABLE KEYS */; -INSERT INTO `config` VALUES (1,'234604',0,'production',NULL,'2001-01-01 11:00:00',NULL,0); -/*!40000 ALTER TABLE `config` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `version` --- - -LOCK TABLES `version` WRITE; -/*!40000 ALTER TABLE `version` DISABLE KEYS */; -INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL),('vn-database','10761','6c1146271aa71f7c3332e11d50d6812752391ea4','2023-11-20 11:55:47','10778'); -/*!40000 ALTER TABLE `version` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `versionLog` --- - -LOCK TABLES `versionLog` WRITE; -/*!40000 ALTER TABLE `versionLog` DISABLE KEYS */; -INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL),('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL),('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL),('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL),('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL),('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL),('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL),('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL),('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL),('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL),('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL),('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL),('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL),('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL),('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL),('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL),('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL),('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL),('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL),('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL),('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL),('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL),('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL),('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL),('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL),('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL),('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL),('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL),('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL),('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL),('vn-database','10097','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL),('vn-database','10103','00-awbVolume.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10104','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10105','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL),('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL),('vn-database','10113','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL),('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL),('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL),('vn-database','10119','00-AfegirFKPart1.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10119','01-AfegirFkPart2.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10125','00-firstScript.sql','jenkins@10.0.2.68','2022-05-18 18:44:30',NULL,NULL),('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL),('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL),('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL),('vn-database','10132','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10133','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 14:32:30',NULL,NULL),('vn-database','10134','00-firstScript.sql','jenkins@10.0.2.69','2022-05-06 07:45:25',NULL,NULL),('vn-database','10135','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10136','00-workerTimeControl.sql','jenkins@10.0.2.69','2022-05-09 13:51:12',NULL,NULL),('vn-database','10138','00-firstScript.sql','jenkins@10.0.2.69','2022-05-10 13:58:05',NULL,NULL),('vn-database','10139','00-firstScript.sql','jenkins@10.0.2.68','2022-05-16 14:32:37',NULL,NULL),('vn-database','10139','01-secondScript.sql','jenkins@10.0.2.68','2022-05-17 12:16:13',NULL,NULL),('vn-database','10141','00-firstScript.sql','jenkins@10.0.2.70','2022-05-12 08:27:31',NULL,NULL),('vn-database','10142','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10143','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10144','00-AfegirFKPArt1.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10144','00-firstScript.sql','jenkins@10.0.2.68','2022-05-13 09:44:25',NULL,NULL),('vn-database','10147','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10149','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10150','00-firstScript.sql','jenkins@10.0.2.68','2022-05-17 09:57:16',NULL,NULL),('vn-database','10152','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10153','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10154','00-compressionKk.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10157','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:35',NULL,NULL),('vn-database','10158','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10160','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:30:50',NULL,NULL),('vn-database','10163','00-firstScript.sql','jenkins@10.0.2.68','2022-05-23 08:17:14',NULL,NULL),('vn-database','10164','00-borrarSectorsDesus.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10165','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10166','00-firstScript.sql','jenkins@10.0.2.68','2022-05-24 16:11:21',NULL,NULL),('vn-database','10167','00-renameVnActiveContrat.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10168','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','00-createTableBankEntityConfig.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','02-addNotNullToBankEntityBic.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10171','00-volumeConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 14:11:11',NULL,NULL),('vn-database','10171','01-itemWeight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL),('vn-database','10171','02-agencymode.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL),('vn-database','10172','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10174','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10175','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10177','00-crearTablaSpecialLabels.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10178','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10179','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10183','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10184','00-firstScript.sql','jenkins@10.0.2.68','2022-06-03 08:05:34',NULL,NULL),('vn-database','10185','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 09:07:45',NULL,NULL),('vn-database','10186','00-desactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:31:23',NULL,NULL),('vn-database','10186','01-alter_Table_buy.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','02-alter_table_entryConfig.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','04-regularizar_Sticker_Inventario.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10186','09-reactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10187','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 12:37:31',NULL,NULL),('vn-database','10188','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 14:03:36',NULL,NULL),('vn-database','10189','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10191','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10193','00-delete.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:35',NULL,NULL),('vn-database','10193','01-botanicExport.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:43',NULL,NULL),('vn-database','10193','02-item.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','03-autonomy.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','03-turn.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','04-country.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10194','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10195','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10200','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10201','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10202','00-Remove_FK_to_ediGenus.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10203','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10204','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10205','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:21',NULL,NULL),('vn-database','10207','00-Alter_table_entry.sql','jenkins@10.0.2.69','2022-06-16 07:22:50',NULL,NULL),('vn-database','10207','01-Update_invoiceAmount.sql','jenkins@10.0.2.69','2022-06-16 07:23:00',NULL,NULL),('vn-database','10208','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10209','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 08:47:40',NULL,NULL),('vn-database','10210','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 17:39:17',1046,'Base de datos no seleccionada'),('vn-database','10211','01-firstScript.sql','jenkins@10.0.2.69','2022-06-17 07:11:27',NULL,NULL),('vn-database','10215','00-renameIsInventory.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10216','00-firstScript.sql','jenkins@10.0.2.69','2022-06-23 11:15:28',NULL,NULL),('vn-database','10216','01-batchIndex.sql','jenkins@10.0.2.70','2022-06-27 18:10:55',NULL,NULL),('vn-database','10219','00-AddCollectionFkOnPackingSite.sql','jenkins@10.0.2.70','2022-06-29 09:23:42',NULL,NULL),('vn-database','10219','01-AddFkToCollectionFk.sql','jenkins@10.0.2.70','2022-06-29 09:23:43',NULL,NULL),('vn-database','10220','00-createPersonalProtectionEquipment.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10222','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:12:40',NULL,NULL),('vn-database','10223','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:52',NULL,NULL),('vn-database','10224','00-cosetes.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-21 12:03:45',NULL,NULL),('vn-database','10229','00-firstScript.sql','jenkins@10.0.2.69','2022-07-01 11:59:34',NULL,NULL),('vn-database','10231','01-tablaEktConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:25:39',NULL,NULL),('vn-database','10233','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10235','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10236','00-firstScript.sql','jenkins@10.0.2.69','2022-07-05 12:11:40',NULL,NULL),('vn-database','10237','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10238','00-worker_mobileExtension.sql','jenkins@10.0.2.69','2022-07-14 09:14:09',NULL,NULL),('vn-database','10239','00-firstScript.sql','jenkins@10.0.2.69','2022-07-07 21:51:58',NULL,NULL),('vn-database','10241','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-29 08:14:01',NULL,NULL),('vn-database','10242','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL),('vn-database','10243','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL),('vn-database','10245','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL),('vn-database','10247','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL),('vn-database','10248','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-20 17:27:51',NULL,NULL),('vn-database','10250','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:40',NULL,NULL),('vn-database','10253','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:57',NULL,NULL),('vn-database','10254','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10256','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10258','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL),('vn-database','10259','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-02 08:54:56',NULL,NULL),('vn-database','10261','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-22 08:42:20',NULL,NULL),('vn-database','10262','00-createTablepackagingWithFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','01-alterTablePackagingConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','02-insertsInicials.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','03-createTablepackingWithoutFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10263','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10265','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10267','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10267','01-fixMerge.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10275','00-improvedGeneralLog.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 09:55:56',NULL,NULL),('vn-database','10277','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL),('vn-database','10278','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 17:51:41',NULL,NULL),('vn-database','10279','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10281','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10282','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10283','00-alterTable.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10284','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-04 16:59:08',NULL,NULL),('vn-database','10285','00-firstScript.sql','jenkins@swarm-worker3.static.verdnatura.es','2022-08-05 09:19:33',NULL,NULL),('vn-database','10287','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL),('vn-database','10288','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL),('vn-database','10289','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:36',NULL,NULL),('vn-database','10291','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-10 14:19:34',NULL,NULL),('vn-database','10293','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL),('vn-database','10297','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-16 12:43:36',NULL,NULL),('vn-database','10298','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-13 21:04:13',NULL,NULL),('vn-database','10299','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','00-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','01-drop.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','02-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','00-CreateTableEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','01-insertDataEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','02-alterTableEntry.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:22',NULL,NULL),('vn-database','10303','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:23',NULL,NULL),('vn-database','10304','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:48',NULL,NULL),('vn-database','10304','01-altertableticket.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:51',NULL,NULL),('vn-database','10305','00-ektAssign.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:24:52',NULL,NULL),('vn-database','10306','00-deliveryInformation.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:25',NULL,NULL),('vn-database','10307','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:26',NULL,NULL),('vn-database','10308','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:26:43',NULL,NULL),('vn-database','10309','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:54',NULL,NULL),('vn-database','10310','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL),('vn-database','10311','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:55',NULL,NULL),('vn-database','10312','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL),('vn-database','10313','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:27:21',NULL,NULL),('vn-database','10314','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:19',NULL,NULL),('vn-database','10315','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10317','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10318','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10319','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:41',NULL,NULL),('vn-database','10320','00-operator.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL),('vn-database','10320','01-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL),('vn-database','10320','02-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10321','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 11:11:12',NULL,NULL),('vn-database','10322','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-09 09:19:05',NULL,NULL),('vn-database','10326','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10328','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10329','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10330','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10332','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10334','00-collectionHotbed.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10334','01-saleGroupDetail.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10335','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10336','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10337','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10339','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-19 09:41:19',NULL,NULL),('vn-database','10340','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10341','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10342','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10343','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:35:30',NULL,NULL),('vn-database','10345','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL),('vn-database','10347','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10347','01-addVirtualField.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10349','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10350','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-30 10:11:56',NULL,NULL),('vn-database','10352','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL),('vn-database','10353','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10354','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10356','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10356','01-orderConfigFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10356','02-orderConfigDrop.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10357','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10359','00-improvedGeneralLog_collate.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL),('vn-database','10360','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL),('vn-database','10361','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 11:16:07',NULL,NULL),('vn-database','10362','00-dropUdfs.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-10 11:01:15',NULL,NULL),('vn-database','10363','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10365','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-13 19:30:46',NULL,NULL),('vn-database','10368','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10369','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-14 13:38:06',NULL,NULL),('vn-database','10370','00-deleteForeignKey.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:41',NULL,NULL),('vn-database','10370','01-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:47',NULL,NULL),('vn-database','10370','02-deleteTable.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL),('vn-database','10370','03-accion.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL),('vn-database','10370','04-inter.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL),('vn-database','10371','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10372','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL),('vn-database','10373','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-19 08:31:58',NULL,NULL),('vn-database','10378','00-rename_routeUserPercentage.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10379','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:16',NULL,NULL),('vn-database','10382','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10383','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL),('vn-database','10384','00-business_workcenterFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10385','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL),('vn-database','10386','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL),('vn-database','10387','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-16 14:05:33',NULL,NULL),('vn-database','10388','00-resizeUtilVerionLogCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10388','01-resizeUtilVersionCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10390','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:16',NULL,NULL),('vn-database','10391','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10394','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:24',NULL,NULL),('vn-database','10395','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10396','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 15:36:38',NULL,NULL),('vn-database','10397','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10399','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10400','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10402','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-21 14:11:31',NULL,NULL),('vn-database','10404','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10405','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:22',NULL,NULL),('vn-database','10407','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL),('vn-database','10408','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10409','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL),('vn-database','10412','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-30 12:45:44',NULL,NULL),('vn-database','10413','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL),('vn-database','10416','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL),('vn-database','10420','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:25',NULL,NULL),('vn-database','10421','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:26',NULL,NULL),('vn-database','10426','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:40',NULL,NULL),('vn-database','10428','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10431','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:22',NULL,NULL),('vn-database','10433','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10434','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10435','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-13 07:30:10',NULL,NULL),('vn-database','10436','00-createFkWorker.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:59',NULL,NULL),('vn-database','10436','01-addStateToWorkerProductivity.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL),('vn-database','10436','02-DeprecateVnSaleTrackingState.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL),('vn-database','10436','03-DeprecateColumnVnSaleTrackingActionFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10436','04-DropSchemaVnControl.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10436','05-RemoveFkWorkerProductivity.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-17 14:51:19',NULL,NULL),('vn-database','10439','00-fixRole.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:26',NULL,NULL),('vn-database','10440','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10444','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10445','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10448','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10450','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-27 08:28:04',NULL,NULL),('vn-database','10451','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-06 08:08:32',NULL,NULL),('vn-database','10452','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10453','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 14:04:37',NULL,NULL),('vn-database','10454','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10455','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10456','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:30',NULL,NULL),('vn-database','10457','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:33',NULL,NULL),('vn-database','10458','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10459','00-alterTableUtilConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','01-createFunctionCurdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','02-createFunctionMockTime.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','03-createFunctionMockTimeBase.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','04-createFunctionNow.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10460','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10461','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10463','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-03 12:59:26',NULL,NULL),('vn-database','10468','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10469','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10470','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10471','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10472','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10477','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:31',NULL,NULL),('vn-database','10478','00-dropBasket.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10478','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10478','01-orderConfigured.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:16',NULL,NULL),('vn-database','10478','02-configuredUpdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL),('vn-database','10478','99-privileges.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL),('vn-database','10480','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 15:09:26',NULL,NULL),('vn-database','10481','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 16:37:22',NULL,NULL),('vn-database','10482','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-21 10:00:28',NULL,NULL),('vn-database','10485','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10488','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10491','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL),('vn-database','10492','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL),('vn-database','10493','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10495','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:19',NULL,NULL),('vn-database','10498','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:38',NULL,NULL),('vn-database','10500','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 07:06:03',NULL,NULL),('vn-database','10501','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 10:52:24',NULL,NULL),('vn-database','10502','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10504','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL),('vn-database','10506','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10506','01-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10506','02-secondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10506','03-thirdScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10507','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:35:23',NULL,NULL),('vn-database','10508','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:43',NULL,NULL),('vn-database','10510','00-dropBusinessFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','01-createTableProfessionalCategory.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','02-exportToNewTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','03-RecreateFK.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL),('vn-database','10510','04-kkPostgresqlTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL),('vn-database','10511','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10512','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:52',NULL,NULL),('vn-database','10513','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:56',NULL,NULL),('vn-database','10514','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10516','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10521','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 06:58:13',NULL,NULL),('vn-database','10522','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10523','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10524','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL),('vn-database','10524','01-rateEditorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL),('vn-database','10525','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 12:42:50',NULL,NULL),('vn-database','10526','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:57',NULL,NULL),('vn-database','10528','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:00',NULL,NULL),('vn-database','10530','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-23 14:49:30',NULL,NULL),('vn-database','10531','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:47:10',NULL,NULL),('vn-database','10532','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:17:38',NULL,NULL),('vn-database','10533','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:04',NULL,NULL),('vn-database','10537','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-29 15:18:36',NULL,NULL),('vn-database','10538','00-createChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','01-createChronopostService.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','02-createChronopostExpedition.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','03-createChronopostSenderAddress.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','04-addgrantPrivilegies.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','05-updateChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 11:54:57',NULL,NULL),('vn-database','10539','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:07',NULL,NULL),('vn-database','10540','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10545','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-11 08:31:03',NULL,NULL),('vn-database','10546','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL),('vn-database','10547','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:21:58',NULL,NULL),('vn-database','10549','00-updateUpdateLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:29:22',NULL,NULL),('vn-database','10549','01-updateInsertLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:11',NULL,NULL),('vn-database','10549','02-updateDeleteLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:51',NULL,NULL),('vn-database','10549','03-deleteEmptyLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:31:34',NULL,NULL),('vn-database','10549','04-optimizeLogTables.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:33:58',NULL,NULL),('vn-database','10550','00-editorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:42:33',NULL,NULL),('vn-database','10550','01-originFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10552','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-13 08:25:10',NULL,NULL),('vn-database','10554','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL),('vn-database','10557','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-17 07:45:56',NULL,NULL),('vn-database','10559','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-18 10:53:50',NULL,NULL),('vn-database','10560','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-17 09:19:31',NULL,NULL),('vn-database','10562','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10563','00-delivery_ticketFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 09:30:53',NULL,NULL),('vn-database','10566','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:08:41',NULL,NULL),('vn-database','10567','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:18:06',NULL,NULL),('vn-database','10568','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10569','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-24 09:14:35',NULL,NULL),('vn-database','10570','00-createSendingConfig.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','01-createSendingServiceWeekday.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','02-createSendingService.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','03-permisos.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10571','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL),('vn-database','10573','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:23',NULL,NULL),('vn-database','10575','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-26 11:27:32',NULL,NULL),('vn-database','10577','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-27 14:00:12',NULL,NULL),('vn-database','10578','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10579','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-28 11:27:36',NULL,NULL),('vn-database','10580','00-itemTypeDropConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:18:52',NULL,NULL),('vn-database','10580','01-itemTypeAddConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:19:10',NULL,NULL),('vn-database','10581','00-itemTypeAutoIncrement.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 19:06:46',NULL,NULL),('vn-database','10582','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10583','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10584','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10585','00-ticketLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:20:10',NULL,NULL),('vn-database','10585','01-entryLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:21:12',NULL,NULL),('vn-database','10585','02-claimLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:36',NULL,NULL),('vn-database','10585','03-clientLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:54',NULL,NULL),('vn-database','10585','04-invoiceInLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:55',NULL,NULL),('vn-database','10585','05-itemLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:29:46',NULL,NULL),('vn-database','10585','06-routeLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:18',NULL,NULL),('vn-database','10585','07-shelvingLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL),('vn-database','10585','08-supplierLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL),('vn-database','10585','09-travelLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:41',NULL,NULL),('vn-database','10585','10-workerLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:42',NULL,NULL),('vn-database','10585','11-zoneLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:43',NULL,NULL),('vn-database','10585','12-userLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10585','13-roleLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10587','00-arcRead_addMinimum.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-16 13:13:15',NULL,NULL),('vn-database','10593','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10596','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10597','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10598','00-workerLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','01-supplierLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','02-workerTimeControlLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','03-workerClockLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10599','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10601','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-17 09:26:26',NULL,NULL),('vn-database','10602','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 08:52:15',NULL,NULL),('vn-database','10606','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 09:26:00',NULL,NULL),('vn-database','10608','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 12:36:31',NULL,NULL),('vn-database','10609','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 08:28:07',NULL,NULL),('vn-database','10610','00-updateCompanyId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:07',NULL,NULL),('vn-database','10610','01-updateSupplierId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:39',NULL,NULL),('vn-database','10610','02-invoiceOutCompany.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 09:49:55',NULL,NULL),('vn-database','10611','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-19 14:39:41',NULL,NULL),('vn-database','10613','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10614','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL),('vn-database','10615','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL),('vn-database','10616','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL),('vn-database','10616','01-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL),('vn-database','10617','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:41',NULL,NULL),('vn-database','10618','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 12:55:56',NULL,NULL),('vn-database','10619','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10620','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:20:53',NULL,NULL),('vn-database','10624','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-30 19:01:10',NULL,NULL),('vn-database','10625','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10626','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 13:32:32',NULL,NULL),('vn-database','10628','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10630','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-02 13:30:58',NULL,NULL),('vn-database','10631','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-05 08:37:25',NULL,NULL),('vn-database','10632','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10633','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10634','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-06 12:15:55',NULL,NULL),('vn-database','10637','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:19',NULL,NULL),('vn-database','10640','00-companyFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL),('vn-database','10640','00-updateCompany.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-07 14:22:13',1205,'Tiempo de espera de bloqueo excedido; intente rearrancar la transacción'),('vn-database','10640','01-companyFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL),('vn-database','10640','02-companyFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:47:04',NULL,NULL),('vn-database','10640','04-supplierFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:48:30',NULL,NULL),('vn-database','10640','05-supplierFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:53:17',NULL,NULL),('vn-database','10640','06-supplierFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 15:06:00',NULL,NULL),('vn-database','10642','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10643','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-09 15:04:35',NULL,NULL),('vn-database','10644','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:18',NULL,NULL),('vn-database','10645','00-addNewFields.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL),('vn-database','10645','01-updateCollectionWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL),('vn-database','10645','02-updateWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10645','03-addFieldToPackingSite.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10647','00-renombrarTabla.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10648','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10649','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-16 10:59:06',NULL,NULL),('vn-database','10652','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10653','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:20',NULL,NULL),('vn-database','10655','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:24',NULL,NULL),('vn-database','10656','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10657','00-renameErrorProduction.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','01-changeNightTask.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','02-addCodeToClaimResponsible.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','03-grantSelectGrafana.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10658','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:27',NULL,NULL),('vn-database','10659','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10661','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL),('vn-database','10662','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:33',NULL,NULL),('vn-database','10663','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL),('vn-database','10665','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-30 08:52:51',NULL,NULL),('vn-database','10666','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL),('vn-database','10667','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10668','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10671','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-25 14:56:50',NULL,NULL),('vn-database','10675','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10676','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10677','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL),('vn-database','10678','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10679','00-tables.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10680','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-18 14:58:36',NULL,NULL),('vn-database','10682','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10683','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10684','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10685','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:53:55',NULL,NULL),('vn-database','10690','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-27 10:52:26',NULL,NULL),('vn-database','10691','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-31 13:37:21',NULL,NULL),('vn-database','10692','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10693','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10694','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 09:50:53',NULL,NULL),('vn-database','10695','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 13:40:16',NULL,NULL),('vn-database','10696','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 16:54:57',NULL,NULL),('vn-database','10698','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-03 08:53:12',NULL,NULL),('vn-database','10699','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 15:24:30',NULL,NULL),('vn-database','10700','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:11',NULL,NULL),('vn-database','10701','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10702','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 12:50:46',NULL,NULL),('vn-database','10704','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:14',NULL,NULL),('vn-database','10705','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-16 14:16:05',NULL,NULL),('vn-database','10707','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-21 12:31:18',NULL,NULL),('vn-database','10708','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL),('vn-database','10712','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL),('vn-database','10714','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-28 13:01:45',NULL,NULL),('vn-database','10716','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL),('vn-database','10717','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:28:54',NULL,NULL),('vn-database','10718','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10719','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-01 12:53:30',NULL,NULL),('vn-database','10720','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL),('vn-database','10721','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10722','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-09 13:00:29',NULL,NULL),('vn-database','10725','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-12 14:15:14',NULL,NULL),('vn-database','10726','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 15:32:20',NULL,NULL),('vn-database','10727','00-addPrinterField.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','01-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','02-createTableScreen.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','03-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','04-createTableScanner.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','05-createTablePackingSiteDeviceLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','06-alterTablePrinterModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','07-AddFieldsToPackingSite.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:30',NULL,NULL),('vn-database','10730','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-15 11:42:48',NULL,NULL),('vn-database','10733','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:54:00',NULL,NULL),('vn-database','10736','00-workerBossNull.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-22 00:02:05',NULL,NULL),('vn-database','10739','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-10 10:19:07',NULL,NULL),('vn-database','10740','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10741','01-refactorCplusTrascendency472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','02-refactorCplusTrascendency477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','03-refactorCplusInvoiceType477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','04-refactorCplusInvoiceType472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','05-fixes.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10744','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-13 09:23:19',NULL,NULL),('vn-database','10746','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-16 18:22:46',NULL,NULL),('vn-database','10747','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL),('vn-database','10748','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL),('vn-database','10748','01-SecondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10749','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-22 16:08:17',NULL,NULL),('vn-database','10750','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-23 13:04:17',NULL,NULL),('vn-database','10750','00-ticket_addGrants.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10751','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10752','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-24 14:07:54',NULL,NULL),('vn-database','10753','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-24 14:37:21',NULL,NULL),('vn-database','10754','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10755','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:35',NULL,NULL),('vn-database','10756','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-03 07:14:38',NULL,NULL),('vn-database','10757','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:57',NULL,NULL),('vn-database','10761','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:58',NULL,NULL); -/*!40000 ALTER TABLE `versionLog` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 -USE `account`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: account --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `role` --- - -LOCK TABLES `role` WRITE; -/*!40000 ALTER TABLE `role` DISABLE KEYS */; -INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 07:04:58','2023-06-08 16:47:57',NULL),(2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 07:04:58','2023-06-02 20:33:28',NULL),(3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(9,'developer','Desarrolladores del sistema',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(11,'account','Privilegios relacionados con el login',0,'2017-05-19 07:04:58','2017-09-20 17:06:35',NULL),(13,'teamBoss','Jefe de equipo/departamento',1,'2017-05-19 07:04:58','2021-06-30 13:29:30',NULL),(15,'logistic','Departamento de compras, responsables de la logistica',1,'2017-05-19 07:04:58','2018-02-12 10:50:10',NULL),(16,'logisticBoss','Jefe del departamento de logística',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(17,'adminBoss','Jefe del departamento de administración',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(18,'salesPerson','Departamento de ventas',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(19,'salesBoss','Jefe del departamento de ventas',1,'2017-05-19 07:04:58','2017-08-16 12:38:27',NULL),(20,'manager','Gerencia',1,'2017-06-01 14:57:02','2022-07-29 07:36:15',NULL),(21,'salesAssistant','Jefe auxiliar de ventas',1,'2017-08-16 12:40:52','2017-08-16 12:40:52',NULL),(22,'teamManager','Jefe de departamento con privilegios de auxiliar de venta.',1,'2017-09-07 09:08:12','2017-09-07 09:08:12',NULL),(30,'financialBoss','Director finaciero',1,'2017-09-21 11:05:36','2017-09-21 11:05:36',NULL),(31,'freelancer','Trabajadores por cuenta ajena',1,'2017-10-10 12:57:26','2017-10-10 12:59:27',NULL),(32,'ett','Trabajadores de empresa temporal',1,'2017-10-10 12:58:58','2017-10-10 12:59:20',NULL),(33,'invoicing','Personal con acceso a facturación',0,'2018-01-29 16:43:34','2018-01-29 16:43:34',NULL),(34,'agencyBoss','Jefe/a del departamento de agencias',1,'2018-01-29 16:44:39','2018-02-23 07:58:53',NULL),(35,'buyer','Departamento de compras',1,'2018-02-12 10:35:42','2018-02-12 10:35:42',NULL),(36,'replenisher','Trabajadores de camara',1,'2018-02-16 14:07:10','2019-04-12 05:38:08',NULL),(37,'hr','Gestor/a de recursos humanos',1,'2018-02-22 17:34:53','2018-02-22 17:34:53',NULL),(38,'hrBoss','Jefe/a de recursos humanos',1,'2018-02-22 17:35:09','2018-02-22 17:35:09',NULL),(39,'adminAssistant','Jefe auxiliar administrativo',1,'2018-02-23 10:37:36','2018-02-23 10:38:41',NULL),(40,'handmade','Departamento de confección',1,'2018-02-23 11:14:53','2018-02-23 11:39:12',NULL),(41,'handmadeBoss','Jefe de departamento de confección',1,'2018-02-23 11:15:09','2018-02-23 11:39:26',NULL),(42,'artificial','Departamento de artificial',1,'2018-02-23 11:39:59','2018-02-23 11:39:59',NULL),(43,'artificialBoss','Jefe del departamento de artificial',1,'2018-02-23 11:40:16','2018-02-23 11:40:16',NULL),(44,'accessory','Departamento de complementos',1,'2018-02-23 11:41:12','2018-02-23 11:41:12',NULL),(45,'accessoryBoss','Jefe del departamento de complementos',1,'2018-02-23 11:41:23','2018-02-23 11:41:23',NULL),(47,'cooler','Empleados de cámara',1,'2018-02-23 13:08:18','2018-02-23 13:08:18',NULL),(48,'coolerBoss','Jefe de cámara',1,'2018-02-23 13:12:01','2023-03-13 08:49:43',NULL),(49,'production','Empleado de producción',1,'2018-02-26 15:28:23','2021-02-12 09:42:35',NULL),(50,'productionBoss','Jefe de producción',1,'2018-02-26 15:34:12','2018-02-26 15:34:12',NULL),(51,'marketing','Departamento de marketing',1,'2018-03-01 07:28:39','2018-03-01 07:28:39',NULL),(52,'marketingBoss','Jefe del departamento de marketing',1,'2018-03-01 07:28:57','2018-03-01 07:28:57',NULL),(53,'insurance','Gestor de seguros de cambio',0,'2018-03-05 07:44:35','2019-02-01 13:47:57',NULL),(54,'itemPicker','Sacador en cámara',1,'2018-03-05 12:08:17','2018-03-05 12:08:17',NULL),(55,'itemPickerBoss','Jefe de sacadores',1,'2018-03-05 12:08:31','2018-03-05 12:08:31',NULL),(56,'delivery','Personal de reparto',1,'2018-05-30 06:07:02','2018-05-30 06:07:02',NULL),(57,'deliveryBoss','Jefe de personal de reparto',1,'2018-05-30 06:07:19','2018-05-30 06:07:19',NULL),(58,'packager','Departamento encajadores',1,'2019-01-21 12:43:45','2019-01-21 12:43:45',NULL),(59,'packagerBoss','Jefe departamento encajadores',1,'2019-01-21 12:44:10','2019-01-21 12:44:10',NULL),(60,'productionAssi','Tareas relacionadas con producción y administración',1,'2019-01-29 13:29:01','2019-01-29 13:29:01',NULL),(61,'replenisherBos','Jefe de Complementos/Camara',1,'2019-07-01 06:44:07','2019-07-01 06:44:07',NULL),(62,'noLogin','Role without login access to MySQL',0,'2019-07-01 06:50:19','2019-07-02 13:42:05',NULL),(64,'balanceSheet','Consulta de Balance',0,'2019-07-16 12:12:08','2019-07-16 12:12:08',NULL),(65,'officeBoss','Jefe de filial',1,'2019-08-02 06:54:26','2019-08-02 06:54:26',NULL),(66,'sysadmin','Administrador de sistema',1,'2019-08-08 06:58:56','2019-08-08 06:58:56',NULL),(67,'adminOfficer','categoria profesional oficial de administración',1,'2020-01-03 08:09:23','2020-01-03 08:09:23',NULL),(69,'coolerAssist','Asistente de cámara con permiso compras',1,'2020-02-05 12:36:09','2023-03-13 08:50:07',NULL),(70,'trainee','Alumno de prácticas',1,'2020-03-04 11:00:25','2020-03-04 11:00:25',NULL),(71,'checker','Rol de revisor con privilegios de itemPicker',1,'2020-10-02 10:50:07','2020-10-02 10:50:07',NULL),(72,'claimManager','Personal de reclamaciones',1,'2020-10-13 10:01:32','2020-10-26 07:29:46',NULL),(73,'financial','Departamento de finanzas',1,'2020-11-16 09:30:27','2020-11-16 09:30:27',NULL),(74,'userPhotos','Privilegios para subir fotos de usuario',1,'2021-02-03 10:24:27','2021-02-03 10:24:27',NULL),(75,'catalogPhotos','Privilegios para subir fotos del catálogo',1,'2021-02-03 10:24:27','2021-02-03 10:24:27',NULL),(76,'chat','Rol para utilizar el rocket chat',1,'2020-11-27 13:06:50','2020-12-17 07:49:41',NULL),(100,'root','Rol con todos los privilegios',0,'2018-04-23 14:33:36','2020-11-12 06:50:07',NULL),(101,'buyerBoss','Jefe del departamento de compras',1,'2021-06-16 09:53:17','2021-06-16 09:53:17',NULL),(102,'preservedBoss','Responsable preservado',1,'2021-09-14 13:45:37','2021-09-14 13:45:37',NULL),(103,'it','Departamento de informática',1,'2021-11-11 09:48:22','2021-11-11 09:48:22',NULL),(104,'itBoss','Jefe de departamento de informática',1,'2021-11-11 09:48:49','2021-11-11 09:48:49',NULL),(105,'grant','Adjudicar roles a usuarios',1,'2021-11-11 12:41:09','2021-11-11 12:41:09',NULL),(106,'ext','Usuarios externos de la Base de datos',1,'2021-11-23 14:51:16','2021-11-23 14:51:16',NULL),(107,'productionPlus','Creado para pepe por orden de Juanvi',1,'2022-02-08 06:47:10','2022-02-08 06:47:10',NULL),(108,'system','System user',1,'2022-05-16 08:09:51','2022-05-16 08:09:51',NULL),(109,'salesTeamBoss','Jefe de equipo de comerciales',1,'2022-06-14 13:45:56','2022-06-14 13:45:56',NULL),(110,'palletizer','Paletizadores',1,'2022-12-02 12:56:22','2022-12-02 12:56:30',NULL),(111,'entryEditor','Entry editor',1,'2023-01-13 11:21:55','2023-01-13 11:21:55',NULL),(112,'maintenance','Personal de mantenimiento',1,'2023-01-19 06:23:35','2023-01-19 06:23:35',NULL),(114,'maintenanceBos','Jefe de mantenimiento',1,'2023-01-19 06:31:16','2023-05-17 11:07:21',NULL),(115,'itManagement','TI management',1,'2023-03-29 07:27:55','2023-03-29 07:28:04',NULL),(119,'palletizerBoss','Jefe de paletizadores',1,'2023-06-07 11:51:54','2023-06-07 11:51:54',NULL),(120,'developerBoss','Jefe de proyecto de desarrollo',1,'2023-06-19 07:07:21','2023-06-19 07:07:21',21709),(121,'buyerSalesAssistant','Rol para compradores que también son responsables de ventas',1,'2023-06-23 14:48:19','2023-06-23 14:48:19',NULL),(122,'logisticAssistant','Jefe auxiliar de logística',1,'2023-06-26 07:21:15','2023-06-26 07:21:15',NULL),(123,'deliveryAssistant','Jefe auxiliar repartos',1,'2023-10-05 06:47:48','2023-10-05 06:47:48',10578),(124,'hrBuyer','Recursos Humanos con Buyer',1,'2023-10-23 11:50:43','2023-10-23 11:50:43',NULL),(125,'claimViewer','Trabajadores que consulta las reclamaciones ',1,'2023-11-16 08:14:46','2023-11-16 08:14:46',10578),(126,'greenhouseBoss','Jefe de invernadero',1,'2023-11-16 13:32:13','2023-11-16 13:32:13',NULL); -/*!40000 ALTER TABLE `role` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `roleInherit` --- - -LOCK TABLES `roleInherit` WRITE; -/*!40000 ALTER TABLE `roleInherit` DISABLE KEYS */; -INSERT INTO `roleInherit` VALUES (1,1,2,NULL),(2,1,3,NULL),(3,1,70,NULL),(4,2,11,NULL),(5,3,11,NULL),(6,5,1,NULL),(8,5,33,NULL),(10,11,6,NULL),(11,13,1,NULL),(12,15,35,NULL),(16,17,20,NULL),(17,17,37,NULL),(18,17,39,NULL),(19,17,64,NULL),(20,18,1,NULL),(21,19,21,NULL),(22,20,13,NULL),(23,20,16,NULL),(24,20,65,NULL),(25,21,13,NULL),(26,21,18,NULL),(27,21,53,NULL),(28,22,13,NULL),(29,22,21,NULL),(30,30,5,NULL),(31,30,20,NULL),(32,30,22,NULL),(33,30,53,NULL),(34,30,64,NULL),(35,31,1,NULL),(36,32,1,NULL),(37,34,1,NULL),(38,34,13,NULL),(39,34,33,NULL),(40,35,1,NULL),(41,36,44,NULL),(42,36,47,NULL),(43,37,1,NULL),(44,38,37,NULL),(45,38,64,NULL),(46,39,5,NULL),(47,39,21,NULL),(48,39,57,NULL),(49,40,1,NULL),(50,40,49,NULL),(51,41,13,NULL),(52,41,35,NULL),(53,41,40,NULL),(54,42,35,NULL),(55,42,49,NULL),(56,43,13,NULL),(57,43,42,NULL),(58,44,1,NULL),(59,45,13,NULL),(60,45,44,NULL),(61,47,1,NULL),(62,48,13,NULL),(63,48,47,NULL),(64,49,36,NULL),(65,49,58,NULL),(66,50,13,NULL),(67,50,21,NULL),(70,50,57,NULL),(72,51,1,NULL),(73,52,13,NULL),(74,52,19,NULL),(76,52,51,NULL),(77,53,1,NULL),(78,54,1,NULL),(79,55,13,NULL),(80,55,54,NULL),(81,56,1,NULL),(84,58,1,NULL),(85,59,13,NULL),(87,60,5,NULL),(91,61,13,NULL),(92,61,36,NULL),(94,65,35,NULL),(97,67,5,NULL),(98,67,37,NULL),(99,69,35,NULL),(101,70,11,NULL),(102,71,1,NULL),(103,71,58,NULL),(105,72,18,NULL),(106,73,5,NULL),(107,73,64,NULL),(108,73,19,NULL),(109,59,50,NULL),(115,39,76,NULL),(117,65,76,NULL),(118,30,76,NULL),(124,5,76,NULL),(125,37,76,NULL),(126,38,76,NULL),(128,42,76,NULL),(129,35,76,NULL),(130,60,76,NULL),(131,21,76,NULL),(132,18,76,NULL),(133,50,76,NULL),(134,20,76,NULL),(135,41,76,NULL),(136,17,76,NULL),(137,52,76,NULL),(139,37,74,NULL),(140,51,74,NULL),(141,51,75,NULL),(142,35,75,NULL),(143,15,49,NULL),(145,17,67,NULL),(146,38,13,NULL),(147,101,35,NULL),(148,101,13,NULL),(150,15,56,NULL),(152,69,47,NULL),(153,48,35,NULL),(154,102,1,NULL),(167,9,103,NULL),(168,66,9,NULL),(169,104,100,NULL),(172,103,76,NULL),(173,103,1,NULL),(174,103,44,NULL),(175,103,45,NULL),(176,103,11,NULL),(177,103,39,NULL),(178,103,17,NULL),(179,103,5,NULL),(180,103,67,NULL),(181,103,3,NULL),(182,103,34,NULL),(183,103,42,NULL),(184,103,43,NULL),(185,103,64,NULL),(186,103,35,NULL),(187,103,101,NULL),(188,103,75,NULL),(189,103,71,NULL),(190,103,72,NULL),(191,103,47,NULL),(192,103,69,NULL),(193,103,48,NULL),(194,103,2,NULL),(195,103,56,NULL),(196,103,57,NULL),(197,103,32,NULL),(198,103,73,NULL),(199,103,30,NULL),(200,103,31,NULL),(201,103,6,NULL),(202,103,40,NULL),(203,103,41,NULL),(204,103,37,NULL),(205,103,38,NULL),(206,103,53,NULL),(207,103,33,NULL),(210,103,54,NULL),(211,103,55,NULL),(212,103,15,NULL),(213,103,16,NULL),(215,103,51,NULL),(216,103,52,NULL),(218,103,65,NULL),(219,103,58,NULL),(220,103,59,NULL),(221,103,102,NULL),(222,103,49,NULL),(223,103,60,NULL),(224,103,50,NULL),(225,103,36,NULL),(226,103,61,NULL),(228,103,21,NULL),(229,103,19,NULL),(230,103,18,NULL),(231,103,13,NULL),(232,103,22,NULL),(233,103,70,NULL),(234,103,74,NULL),(237,66,103,NULL),(238,103,20,NULL),(239,106,11,NULL),(240,107,60,NULL),(241,21,72,NULL),(242,20,9,NULL),(246,102,35,NULL),(247,108,1,NULL),(248,102,13,NULL),(249,109,18,NULL),(250,109,13,NULL),(251,51,21,NULL),(253,48,49,NULL),(254,110,1,NULL),(255,110,76,NULL),(256,48,69,NULL),(257,47,111,NULL),(258,43,111,NULL),(259,72,111,NULL),(260,35,111,NULL),(261,5,111,NULL),(262,112,1,NULL),(263,114,112,NULL),(264,51,35,NULL),(265,72,49,NULL),(266,101,18,NULL),(268,65,57,NULL),(269,65,59,NULL),(270,65,49,NULL),(271,65,18,NULL),(272,65,13,NULL),(273,60,35,NULL),(275,50,59,NULL),(276,60,49,NULL),(280,5,53,NULL),(281,5,18,NULL),(282,50,60,NULL),(283,5,21,NULL),(285,58,76,NULL),(287,69,58,NULL),(288,115,66,NULL),(290,104,115,NULL),(291,115,103,NULL),(297,21,33,NULL),(298,49,54,NULL),(299,112,49,NULL),(300,114,13,NULL),(302,5,35,NULL),(303,69,49,NULL),(306,119,110,NULL),(307,1,76,NULL),(309,120,9,NULL),(310,120,66,NULL),(311,120,13,25508),(312,115,120,NULL),(314,43,18,NULL),(315,121,35,NULL),(316,121,21,NULL),(317,122,15,NULL),(318,16,122,NULL),(319,37,49,NULL),(320,37,18,NULL),(328,57,123,10578),(329,123,33,NULL),(330,123,56,NULL),(332,103,112,NULL),(333,57,13,NULL),(334,60,123,NULL),(335,124,37,NULL),(336,124,35,NULL),(337,103,124,NULL),(338,35,125,10578),(339,57,125,10578),(340,41,125,10578),(341,18,125,10578),(346,126,15,NULL),(347,102,49,NULL); -/*!40000 ALTER TABLE `roleInherit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `roleRole` --- - -LOCK TABLES `roleRole` WRITE; -/*!40000 ALTER TABLE `roleRole` DISABLE KEYS */; -INSERT INTO `roleRole` VALUES (326595,1,1),(326596,1,2),(326597,1,3),(326601,1,6),(326600,1,11),(326598,1,70),(326599,1,76),(326602,2,2),(326604,2,6),(326603,2,11),(326605,3,3),(326607,3,6),(326606,3,11),(326609,5,1),(326623,5,2),(326622,5,3),(326608,5,5),(326629,5,6),(326625,5,11),(326619,5,13),(326610,5,18),(326611,5,21),(326612,5,33),(326613,5,35),(326628,5,36),(326631,5,44),(326630,5,47),(326624,5,49),(326614,5,53),(326627,5,54),(326626,5,58),(326621,5,70),(326618,5,72),(326617,5,75),(326615,5,76),(326616,5,111),(326620,5,125),(326632,6,6),(326635,9,1),(326636,9,2),(326637,9,3),(326638,9,5),(326639,9,6),(326633,9,9),(326640,9,11),(326641,9,13),(326642,9,15),(326643,9,16),(326644,9,17),(326645,9,18),(326646,9,19),(326647,9,20),(326648,9,21),(326649,9,22),(326650,9,30),(326651,9,31),(326652,9,32),(326653,9,33),(326654,9,34),(326655,9,35),(326656,9,36),(326657,9,37),(326658,9,38),(326659,9,39),(326660,9,40),(326661,9,41),(326662,9,42),(326663,9,43),(326664,9,44),(326665,9,45),(326666,9,47),(326667,9,48),(326668,9,49),(326669,9,50),(326670,9,51),(326671,9,52),(326672,9,53),(326673,9,54),(326674,9,55),(326675,9,56),(326676,9,57),(326677,9,58),(326678,9,59),(326679,9,60),(326680,9,61),(326681,9,64),(326682,9,65),(326683,9,67),(326684,9,69),(326685,9,70),(326686,9,71),(326687,9,72),(326688,9,73),(326689,9,74),(326690,9,75),(326691,9,76),(326692,9,101),(326693,9,102),(326634,9,103),(326699,9,111),(326694,9,112),(326698,9,122),(326696,9,123),(326695,9,124),(326697,9,125),(326701,11,6),(326700,11,11),(326703,13,1),(326704,13,2),(326705,13,3),(326709,13,6),(326708,13,11),(326702,13,13),(326706,13,70),(326707,13,76),(326716,15,1),(326726,15,2),(326725,15,3),(326728,15,6),(326727,15,11),(326710,15,15),(326711,15,35),(326719,15,36),(326723,15,44),(326722,15,47),(326712,15,49),(326720,15,54),(326713,15,56),(326721,15,58),(326724,15,70),(326715,15,75),(326714,15,76),(326717,15,111),(326718,15,125),(326737,16,1),(326747,16,2),(326746,16,3),(326749,16,6),(326748,16,11),(326731,16,15),(326729,16,16),(326732,16,35),(326740,16,36),(326744,16,44),(326743,16,47),(326733,16,49),(326741,16,54),(326734,16,56),(326742,16,58),(326745,16,70),(326736,16,75),(326735,16,76),(326738,16,111),(326730,16,122),(326739,16,125),(326758,17,1),(326774,17,2),(326773,17,3),(326765,17,5),(326799,17,6),(326762,17,9),(326798,17,11),(326761,17,13),(326797,17,15),(326760,17,16),(326750,17,17),(326757,17,18),(326796,17,19),(326751,17,20),(326766,17,21),(326795,17,22),(326794,17,30),(326793,17,31),(326792,17,32),(326779,17,33),(326791,17,34),(326776,17,35),(326770,17,36),(326752,17,37),(326790,17,38),(326753,17,39),(326789,17,40),(326788,17,41),(326787,17,42),(326786,17,43),(326785,17,44),(326784,17,45),(326800,17,47),(326801,17,48),(326763,17,49),(326802,17,50),(326803,17,51),(326804,17,52),(326780,17,53),(326769,17,54),(326805,17,55),(326806,17,56),(326767,17,57),(326768,17,58),(326775,17,59),(326807,17,60),(326808,17,61),(326754,17,64),(326759,17,65),(326755,17,67),(326809,17,69),(326772,17,70),(326810,17,71),(326782,17,72),(326811,17,73),(326764,17,74),(326812,17,75),(326756,17,76),(326813,17,101),(326814,17,102),(326778,17,103),(326781,17,111),(326815,17,112),(326777,17,122),(326783,17,123),(326816,17,124),(326771,17,125),(326818,18,1),(326823,18,2),(326822,18,3),(326825,18,6),(326824,18,11),(326817,18,18),(326821,18,70),(326819,18,76),(326820,18,125),(326837,19,1),(326843,19,2),(326842,19,3),(326847,19,6),(326846,19,11),(326828,19,13),(326829,19,18),(326826,19,19),(326827,19,21),(326830,19,33),(326840,19,36),(326845,19,44),(326844,19,47),(326835,19,49),(326831,19,53),(326839,19,54),(326838,19,58),(326841,19,70),(326832,19,72),(326833,19,76),(326834,19,111),(326836,19,125),(326857,20,1),(326869,20,2),(326868,20,3),(326867,20,5),(326866,20,6),(326849,20,9),(326865,20,11),(326850,20,13),(326864,20,15),(326851,20,16),(326863,20,17),(326855,20,18),(326862,20,19),(326848,20,20),(326870,20,21),(326871,20,22),(326872,20,30),(326873,20,31),(326874,20,32),(326875,20,33),(326876,20,34),(326854,20,35),(326877,20,36),(326878,20,37),(326879,20,38),(326880,20,39),(326881,20,40),(326882,20,41),(326883,20,42),(326884,20,43),(326885,20,44),(326886,20,45),(326887,20,47),(326888,20,48),(326859,20,49),(326889,20,50),(326890,20,51),(326891,20,52),(326892,20,53),(326893,20,54),(326894,20,55),(326895,20,56),(326860,20,57),(326896,20,58),(326861,20,59),(326897,20,60),(326898,20,61),(326899,20,64),(326852,20,65),(326900,20,67),(326901,20,69),(326902,20,70),(326903,20,71),(326904,20,72),(326905,20,73),(326906,20,74),(326907,20,75),(326853,20,76),(326908,20,101),(326909,20,102),(326858,20,103),(326913,20,111),(326910,20,112),(326856,20,122),(326914,20,123),(326911,20,124),(326912,20,125),(326925,21,1),(326931,21,2),(326930,21,3),(326935,21,6),(326934,21,11),(326916,21,13),(326917,21,18),(326915,21,21),(326918,21,33),(326928,21,36),(326933,21,44),(326932,21,47),(326923,21,49),(326919,21,53),(326927,21,54),(326926,21,58),(326929,21,70),(326920,21,72),(326921,21,76),(326922,21,111),(326924,21,125),(326940,22,1),(326950,22,2),(326949,22,3),(326957,22,6),(326954,22,11),(326937,22,13),(326939,22,18),(326938,22,21),(326936,22,22),(326941,22,33),(326953,22,36),(326956,22,44),(326955,22,47),(326946,22,49),(326942,22,53),(326952,22,54),(326951,22,58),(326948,22,70),(326943,22,72),(326944,22,76),(326945,22,111),(326947,22,125),(326970,30,1),(326984,30,2),(326983,30,3),(326959,30,5),(326995,30,6),(326971,30,9),(326996,30,11),(326972,30,13),(326994,30,15),(326973,30,16),(326993,30,17),(326969,30,18),(326992,30,19),(326960,30,20),(326968,30,21),(326961,30,22),(326958,30,30),(326991,30,31),(326990,30,32),(326967,30,33),(326989,30,34),(326966,30,35),(326988,30,36),(326987,30,37),(326986,30,38),(326997,30,39),(326998,30,40),(326999,30,41),(327000,30,42),(327001,30,43),(327002,30,44),(327003,30,45),(327004,30,47),(327005,30,48),(326976,30,49),(327006,30,50),(327007,30,51),(327008,30,52),(326962,30,53),(327009,30,54),(327010,30,55),(327011,30,56),(326975,30,57),(327012,30,58),(326985,30,59),(327013,30,60),(327014,30,61),(326963,30,64),(326974,30,65),(327015,30,67),(327016,30,69),(326982,30,70),(327017,30,71),(326980,30,72),(327018,30,73),(327019,30,74),(326979,30,75),(326964,30,76),(327020,30,101),(327021,30,102),(326978,30,103),(326965,30,111),(327022,30,112),(326977,30,122),(327024,30,123),(327023,30,124),(326981,30,125),(327026,31,1),(327027,31,2),(327028,31,3),(327032,31,6),(327031,31,11),(327025,31,31),(327029,31,70),(327030,31,76),(327034,32,1),(327035,32,2),(327036,32,3),(327040,32,6),(327039,32,11),(327033,32,32),(327037,32,70),(327038,32,76),(327041,33,33),(327043,34,1),(327048,34,2),(327047,34,3),(327051,34,6),(327050,34,11),(327044,34,13),(327045,34,33),(327042,34,34),(327046,34,70),(327049,34,76),(327053,35,1),(327060,35,2),(327059,35,3),(327062,35,6),(327061,35,11),(327052,35,35),(327058,35,70),(327054,35,75),(327055,35,76),(327056,35,111),(327057,35,125),(327067,36,1),(327069,36,2),(327068,36,3),(327073,36,6),(327072,36,11),(327063,36,36),(327064,36,44),(327065,36,47),(327070,36,70),(327071,36,76),(327066,36,111),(327075,37,1),(327084,37,2),(327083,37,3),(327091,37,6),(327089,37,11),(327076,37,18),(327080,37,36),(327074,37,37),(327088,37,44),(327087,37,47),(327077,37,49),(327085,37,54),(327086,37,58),(327082,37,70),(327078,37,74),(327079,37,76),(327090,37,111),(327081,37,125),(327100,38,1),(327104,38,2),(327103,38,3),(327112,38,6),(327110,38,11),(327093,38,13),(327099,38,18),(327105,38,36),(327094,38,37),(327092,38,38),(327109,38,44),(327108,38,47),(327098,38,49),(327106,38,54),(327107,38,58),(327095,38,64),(327102,38,70),(327097,38,74),(327096,38,76),(327111,38,111),(327101,38,125),(327121,39,1),(327133,39,2),(327132,39,3),(327114,39,5),(327140,39,6),(327137,39,11),(327124,39,13),(327120,39,18),(327115,39,21),(327119,39,33),(327118,39,35),(327136,39,36),(327113,39,39),(327139,39,44),(327138,39,47),(327129,39,49),(327122,39,53),(327135,39,54),(327128,39,56),(327116,39,57),(327134,39,58),(327131,39,70),(327125,39,72),(327130,39,75),(327117,39,76),(327123,39,111),(327126,39,123),(327127,39,125),(327142,40,1),(327145,40,2),(327144,40,3),(327155,40,6),(327153,40,11),(327148,40,36),(327141,40,40),(327152,40,44),(327151,40,47),(327143,40,49),(327149,40,54),(327150,40,58),(327146,40,70),(327147,40,76),(327154,40,111),(327165,41,1),(327170,41,2),(327169,41,3),(327175,41,6),(327174,41,11),(327157,41,13),(327158,41,35),(327167,41,36),(327159,41,40),(327156,41,41),(327173,41,44),(327172,41,47),(327162,41,49),(327166,41,54),(327171,41,58),(327168,41,70),(327164,41,75),(327160,41,76),(327163,41,111),(327161,41,125),(327182,42,1),(327191,42,2),(327190,42,3),(327193,42,6),(327192,42,11),(327177,42,35),(327184,42,36),(327176,42,42),(327188,42,44),(327187,42,47),(327178,42,49),(327185,42,54),(327186,42,58),(327189,42,70),(327181,42,75),(327179,42,76),(327180,42,111),(327183,42,125),(327202,43,1),(327208,43,2),(327207,43,3),(327214,43,6),(327213,43,11),(327195,43,13),(327196,43,18),(327199,43,35),(327204,43,36),(327197,43,42),(327194,43,43),(327212,43,44),(327211,43,47),(327203,43,49),(327209,43,54),(327210,43,58),(327206,43,70),(327205,43,75),(327201,43,76),(327198,43,111),(327200,43,125),(327216,44,1),(327217,44,2),(327218,44,3),(327222,44,6),(327221,44,11),(327215,44,44),(327219,44,70),(327220,44,76),(327226,45,1),(327228,45,2),(327227,45,3),(327232,45,6),(327231,45,11),(327224,45,13),(327225,45,44),(327223,45,45),(327229,45,70),(327230,45,76),(327234,47,1),(327237,47,2),(327236,47,3),(327241,47,6),(327240,47,11),(327233,47,47),(327238,47,70),(327239,47,76),(327235,47,111),(327252,48,1),(327259,48,2),(327258,48,3),(327261,48,6),(327260,48,11),(327243,48,13),(327244,48,35),(327253,48,36),(327256,48,44),(327245,48,47),(327242,48,48),(327246,48,49),(327254,48,54),(327255,48,58),(327247,48,69),(327257,48,70),(327251,48,75),(327250,48,76),(327249,48,111),(327248,48,125),(327266,49,1),(327272,49,2),(327271,49,3),(327275,49,6),(327274,49,11),(327263,49,36),(327268,49,44),(327267,49,47),(327262,49,49),(327264,49,54),(327265,49,58),(327270,49,70),(327269,49,76),(327273,49,111),(327288,50,1),(327301,50,2),(327300,50,3),(327290,50,5),(327305,50,6),(327304,50,11),(327277,50,13),(327287,50,18),(327278,50,21),(327286,50,33),(327291,50,35),(327295,50,36),(327303,50,44),(327302,50,47),(327292,50,49),(327276,50,50),(327285,50,53),(327294,50,54),(327297,50,56),(327279,50,57),(327293,50,58),(327280,50,59),(327281,50,60),(327299,50,70),(327284,50,72),(327296,50,75),(327282,50,76),(327298,50,111),(327283,50,123),(327289,50,125),(327307,51,1),(327316,51,2),(327315,51,3),(327328,51,6),(327324,51,11),(327312,51,13),(327317,51,18),(327308,51,21),(327318,51,33),(327309,51,35),(327327,51,36),(327330,51,44),(327329,51,47),(327323,51,49),(327306,51,51),(327319,51,53),(327326,51,54),(327325,51,58),(327314,51,70),(327320,51,72),(327310,51,74),(327311,51,75),(327313,51,76),(327321,51,111),(327322,51,125),(327339,52,1),(327345,52,2),(327344,52,3),(327355,52,6),(327351,52,11),(327332,52,13),(327342,52,18),(327333,52,19),(327338,52,21),(327341,52,33),(327337,52,35),(327354,52,36),(327357,52,44),(327356,52,47),(327350,52,49),(327334,52,51),(327331,52,52),(327346,52,53),(327353,52,54),(327352,52,58),(327343,52,70),(327347,52,72),(327336,52,74),(327340,52,75),(327335,52,76),(327348,52,111),(327349,52,125),(327359,53,1),(327360,53,2),(327361,53,3),(327365,53,6),(327364,53,11),(327358,53,53),(327362,53,70),(327363,53,76),(327367,54,1),(327368,54,2),(327369,54,3),(327373,54,6),(327372,54,11),(327366,54,54),(327370,54,70),(327371,54,76),(327377,55,1),(327379,55,2),(327378,55,3),(327383,55,6),(327382,55,11),(327375,55,13),(327376,55,54),(327374,55,55),(327380,55,70),(327381,55,76),(327385,56,1),(327386,56,2),(327387,56,3),(327391,56,6),(327390,56,11),(327384,56,56),(327388,56,70),(327389,56,76),(327398,57,1),(327401,57,2),(327400,57,3),(327404,57,6),(327403,57,11),(327393,57,13),(327397,57,33),(327396,57,56),(327392,57,57),(327399,57,70),(327402,57,76),(327394,57,123),(327395,57,125),(327406,58,1),(327409,58,2),(327408,58,3),(327412,58,6),(327411,58,11),(327405,58,58),(327410,58,70),(327407,58,76),(327417,59,1),(327425,59,2),(327424,59,3),(327430,59,5),(327442,59,6),(327439,59,11),(327414,59,13),(327422,59,18),(327416,59,21),(327421,59,33),(327431,59,35),(327435,59,36),(327441,59,44),(327440,59,47),(327432,59,49),(327415,59,50),(327426,59,53),(327434,59,54),(327437,59,56),(327418,59,57),(327433,59,58),(327413,59,59),(327419,59,60),(327423,59,70),(327427,59,72),(327436,59,75),(327420,59,76),(327438,59,111),(327428,59,123),(327429,59,125),(327453,60,1),(327467,60,2),(327466,60,3),(327444,60,5),(327469,60,6),(327468,60,11),(327464,60,13),(327452,60,18),(327451,60,21),(327450,60,33),(327445,60,35),(327457,60,36),(327462,60,44),(327461,60,47),(327446,60,49),(327449,60,53),(327458,60,54),(327460,60,56),(327459,60,58),(327443,60,60),(327465,60,70),(327463,60,72),(327455,60,75),(327447,60,76),(327454,60,111),(327448,60,123),(327456,60,125),(327474,61,1),(327478,61,2),(327477,61,3),(327482,61,6),(327481,61,11),(327471,61,13),(327472,61,36),(327473,61,44),(327475,61,47),(327470,61,61),(327476,61,70),(327479,61,76),(327480,61,111),(327483,62,62),(327484,64,64),(327499,65,1),(327510,65,2),(327509,65,3),(327511,65,5),(327515,65,6),(327514,65,11),(327486,65,13),(327487,65,18),(327503,65,21),(327505,65,33),(327488,65,35),(327495,65,36),(327507,65,44),(327506,65,47),(327489,65,49),(327501,65,50),(327513,65,53),(327494,65,54),(327504,65,56),(327490,65,57),(327493,65,58),(327491,65,59),(327502,65,60),(327485,65,65),(327508,65,70),(327512,65,72),(327497,65,75),(327492,65,76),(327496,65,111),(327500,65,123),(327498,65,125),(327520,66,1),(327519,66,2),(327521,66,3),(327522,66,5),(327523,66,6),(327517,66,9),(327524,66,11),(327525,66,13),(327526,66,15),(327527,66,16),(327528,66,17),(327529,66,18),(327530,66,19),(327531,66,20),(327532,66,21),(327533,66,22),(327534,66,30),(327535,66,31),(327536,66,32),(327537,66,33),(327538,66,34),(327539,66,35),(327540,66,36),(327541,66,37),(327542,66,38),(327543,66,39),(327544,66,40),(327545,66,41),(327546,66,42),(327547,66,43),(327548,66,44),(327549,66,45),(327550,66,47),(327551,66,48),(327552,66,49),(327553,66,50),(327554,66,51),(327555,66,52),(327556,66,53),(327557,66,54),(327558,66,55),(327559,66,56),(327560,66,57),(327561,66,58),(327562,66,59),(327563,66,60),(327564,66,61),(327565,66,64),(327566,66,65),(327516,66,66),(327567,66,67),(327568,66,69),(327569,66,70),(327570,66,71),(327571,66,72),(327572,66,73),(327573,66,74),(327574,66,75),(327575,66,76),(327576,66,101),(327577,66,102),(327518,66,103),(327583,66,111),(327578,66,112),(327582,66,122),(327580,66,123),(327579,66,124),(327581,66,125),(327588,67,1),(327606,67,2),(327605,67,3),(327585,67,5),(327610,67,6),(327609,67,11),(327602,67,13),(327587,67,18),(327589,67,21),(327590,67,33),(327591,67,35),(327599,67,36),(327586,67,37),(327608,67,44),(327607,67,47),(327595,67,49),(327592,67,53),(327598,67,54),(327597,67,58),(327584,67,67),(327604,67,70),(327601,67,72),(327596,67,74),(327600,67,75),(327593,67,76),(327594,67,111),(327603,67,125),(327619,69,1),(327626,69,2),(327625,69,3),(327628,69,6),(327627,69,11),(327612,69,35),(327621,69,36),(327623,69,44),(327613,69,47),(327614,69,49),(327622,69,54),(327615,69,58),(327611,69,69),(327624,69,70),(327618,69,75),(327617,69,76),(327616,69,111),(327620,69,125),(327631,70,6),(327630,70,11),(327629,70,70),(327633,71,1),(327636,71,2),(327635,71,3),(327640,71,6),(327639,71,11),(327634,71,58),(327637,71,70),(327632,71,71),(327638,71,76),(327647,72,1),(327655,72,2),(327654,72,3),(327657,72,6),(327656,72,11),(327642,72,18),(327648,72,36),(327652,72,44),(327651,72,47),(327643,72,49),(327649,72,54),(327650,72,58),(327653,72,70),(327641,72,72),(327646,72,76),(327644,72,111),(327645,72,125),(327664,73,1),(327676,73,2),(327675,73,3),(327659,73,5),(327682,73,6),(327678,73,11),(327672,73,13),(327663,73,18),(327660,73,19),(327662,73,21),(327665,73,33),(327666,73,35),(327681,73,36),(327684,73,44),(327683,73,47),(327677,73,49),(327667,73,53),(327680,73,54),(327679,73,58),(327661,73,64),(327674,73,70),(327671,73,72),(327658,73,73),(327670,73,75),(327668,73,76),(327669,73,111),(327673,73,125),(327685,74,74),(327686,75,75),(327687,76,76),(327689,100,1),(327690,100,2),(327691,100,3),(327692,100,5),(327693,100,6),(327694,100,9),(327695,100,11),(327696,100,13),(327697,100,15),(327698,100,16),(327699,100,17),(327700,100,18),(327701,100,19),(327702,100,20),(327703,100,21),(327704,100,22),(327705,100,30),(327706,100,31),(327707,100,32),(327708,100,33),(327709,100,34),(327710,100,35),(327711,100,36),(327712,100,37),(327713,100,38),(327714,100,39),(327715,100,40),(327716,100,41),(327717,100,42),(327718,100,43),(327719,100,44),(327720,100,45),(327721,100,47),(327722,100,48),(327723,100,49),(327724,100,50),(327725,100,51),(327726,100,52),(327727,100,53),(327728,100,54),(327729,100,55),(327730,100,56),(327731,100,57),(327732,100,58),(327733,100,59),(327734,100,60),(327735,100,61),(327736,100,62),(327737,100,64),(327738,100,65),(327739,100,66),(327740,100,67),(327741,100,69),(327742,100,70),(327743,100,71),(327744,100,72),(327745,100,73),(327746,100,74),(327747,100,75),(327748,100,76),(327688,100,100),(327749,100,101),(327750,100,102),(327751,100,103),(327752,100,104),(327753,100,105),(327754,100,106),(327755,100,107),(327756,100,108),(327757,100,109),(327758,100,110),(327759,100,111),(327760,100,112),(327761,100,114),(327762,100,115),(327763,100,119),(327770,100,120),(327764,100,121),(327765,100,122),(327768,100,123),(327766,100,124),(327769,100,125),(327767,100,126),(327777,101,1),(327782,101,2),(327781,101,3),(327784,101,6),(327783,101,11),(327772,101,13),(327773,101,18),(327774,101,35),(327780,101,70),(327778,101,75),(327776,101,76),(327771,101,101),(327779,101,111),(327775,101,125),(327786,102,1),(327793,102,2),(327792,102,3),(327803,102,6),(327802,102,11),(327787,102,13),(327788,102,35),(327797,102,36),(327801,102,44),(327800,102,47),(327789,102,49),(327798,102,54),(327799,102,58),(327791,102,70),(327794,102,75),(327790,102,76),(327785,102,102),(327795,102,111),(327796,102,125),(327805,103,1),(327806,103,2),(327807,103,3),(327808,103,5),(327809,103,6),(327867,103,9),(327810,103,11),(327811,103,13),(327812,103,15),(327813,103,16),(327814,103,17),(327815,103,18),(327816,103,19),(327817,103,20),(327818,103,21),(327819,103,22),(327820,103,30),(327821,103,31),(327822,103,32),(327823,103,33),(327824,103,34),(327825,103,35),(327826,103,36),(327827,103,37),(327828,103,38),(327829,103,39),(327830,103,40),(327831,103,41),(327832,103,42),(327833,103,43),(327834,103,44),(327835,103,45),(327836,103,47),(327837,103,48),(327838,103,49),(327839,103,50),(327840,103,51),(327841,103,52),(327842,103,53),(327843,103,54),(327844,103,55),(327845,103,56),(327846,103,57),(327847,103,58),(327848,103,59),(327849,103,60),(327850,103,61),(327851,103,64),(327852,103,65),(327853,103,67),(327854,103,69),(327855,103,70),(327856,103,71),(327857,103,72),(327858,103,73),(327859,103,74),(327860,103,75),(327861,103,76),(327862,103,101),(327863,103,102),(327804,103,103),(327870,103,111),(327864,103,112),(327869,103,122),(327866,103,123),(327865,103,124),(327868,103,125),(327878,104,1),(327877,104,2),(327880,104,3),(327881,104,5),(327882,104,6),(327879,104,9),(327883,104,11),(327884,104,13),(327885,104,15),(327886,104,16),(327887,104,17),(327888,104,18),(327889,104,19),(327890,104,20),(327891,104,21),(327892,104,22),(327893,104,30),(327894,104,31),(327895,104,32),(327896,104,33),(327897,104,34),(327898,104,35),(327899,104,36),(327900,104,37),(327901,104,38),(327902,104,39),(327903,104,40),(327904,104,41),(327905,104,42),(327906,104,43),(327907,104,44),(327908,104,45),(327909,104,47),(327910,104,48),(327911,104,49),(327912,104,50),(327913,104,51),(327914,104,52),(327915,104,53),(327916,104,54),(327917,104,55),(327918,104,56),(327919,104,57),(327920,104,58),(327921,104,59),(327922,104,60),(327923,104,61),(327948,104,62),(327924,104,64),(327925,104,65),(327875,104,66),(327926,104,67),(327927,104,69),(327928,104,70),(327929,104,71),(327930,104,72),(327931,104,73),(327932,104,74),(327933,104,75),(327934,104,76),(327872,104,100),(327935,104,101),(327936,104,102),(327874,104,103),(327871,104,104),(327945,104,105),(327944,104,106),(327951,104,107),(327953,104,108),(327952,104,109),(327949,104,110),(327942,104,111),(327937,104,112),(327947,104,114),(327873,104,115),(327950,104,119),(327876,104,120),(327943,104,121),(327941,104,122),(327939,104,123),(327938,104,124),(327940,104,125),(327946,104,126),(327954,105,105),(327957,106,6),(327956,106,11),(327955,106,106),(327969,107,1),(327983,107,2),(327982,107,3),(327960,107,5),(327985,107,6),(327984,107,11),(327980,107,13),(327968,107,18),(327967,107,21),(327966,107,33),(327961,107,35),(327973,107,36),(327978,107,44),(327977,107,47),(327962,107,49),(327965,107,53),(327974,107,54),(327976,107,56),(327975,107,58),(327959,107,60),(327981,107,70),(327979,107,72),(327971,107,75),(327963,107,76),(327958,107,107),(327970,107,111),(327964,107,123),(327972,107,125),(327987,108,1),(327988,108,2),(327989,108,3),(327993,108,6),(327992,108,11),(327990,108,70),(327991,108,76),(327986,108,108),(327998,109,1),(328002,109,2),(328001,109,3),(328004,109,6),(328003,109,11),(327995,109,13),(327996,109,18),(328000,109,70),(327997,109,76),(327994,109,109),(327999,109,125),(328006,110,1),(328009,110,2),(328008,110,3),(328012,110,6),(328011,110,11),(328010,110,70),(328007,110,76),(328005,110,110),(328013,111,111),(328015,112,1),(328018,112,2),(328017,112,3),(328028,112,6),(328026,112,11),(328021,112,36),(328025,112,44),(328024,112,47),(328016,112,49),(328022,112,54),(328023,112,58),(328019,112,70),(328020,112,76),(328027,112,111),(328014,112,112),(328033,114,1),(328035,114,2),(328034,114,3),(328045,114,6),(328043,114,11),(328030,114,13),(328038,114,36),(328042,114,44),(328041,114,47),(328032,114,49),(328039,114,54),(328040,114,58),(328036,114,70),(328037,114,76),(328044,114,111),(328031,114,112),(328029,114,114),(328051,115,1),(328050,115,2),(328053,115,3),(328054,115,5),(328055,115,6),(328052,115,9),(328056,115,11),(328057,115,13),(328058,115,15),(328059,115,16),(328060,115,17),(328061,115,18),(328062,115,19),(328063,115,20),(328064,115,21),(328065,115,22),(328066,115,30),(328067,115,31),(328068,115,32),(328069,115,33),(328070,115,34),(328071,115,35),(328072,115,36),(328073,115,37),(328074,115,38),(328075,115,39),(328076,115,40),(328077,115,41),(328078,115,42),(328079,115,43),(328080,115,44),(328081,115,45),(328082,115,47),(328083,115,48),(328084,115,49),(328085,115,50),(328086,115,51),(328087,115,52),(328088,115,53),(328089,115,54),(328090,115,55),(328091,115,56),(328092,115,57),(328093,115,58),(328094,115,59),(328095,115,60),(328096,115,61),(328097,115,64),(328098,115,65),(328047,115,66),(328099,115,67),(328100,115,69),(328101,115,70),(328102,115,71),(328103,115,72),(328104,115,73),(328105,115,74),(328106,115,75),(328107,115,76),(328108,115,101),(328109,115,102),(328048,115,103),(328115,115,111),(328110,115,112),(328046,115,115),(328049,115,120),(328114,115,122),(328112,115,123),(328111,115,124),(328113,115,125),(328118,119,1),(328121,119,2),(328120,119,3),(328124,119,6),(328123,119,11),(328122,119,70),(328119,119,76),(328117,119,110),(328116,119,119),(328225,120,1),(328229,120,2),(328228,120,3),(328227,120,5),(328230,120,6),(328222,120,9),(328231,120,11),(328223,120,13),(328232,120,15),(328233,120,16),(328234,120,17),(328235,120,18),(328236,120,19),(328237,120,20),(328238,120,21),(328239,120,22),(328240,120,30),(328241,120,31),(328242,120,32),(328243,120,33),(328244,120,34),(328245,120,35),(328246,120,36),(328247,120,37),(328248,120,38),(328249,120,39),(328250,120,40),(328251,120,41),(328252,120,42),(328253,120,43),(328254,120,44),(328255,120,45),(328256,120,47),(328257,120,48),(328258,120,49),(328259,120,50),(328260,120,51),(328261,120,52),(328262,120,53),(328263,120,54),(328264,120,55),(328265,120,56),(328266,120,57),(328267,120,58),(328268,120,59),(328269,120,60),(328270,120,61),(328271,120,64),(328272,120,65),(328224,120,66),(328273,120,67),(328274,120,69),(328275,120,70),(328276,120,71),(328277,120,72),(328278,120,73),(328279,120,74),(328280,120,75),(328281,120,76),(328282,120,101),(328283,120,102),(328226,120,103),(328289,120,111),(328284,120,112),(328221,120,120),(328288,120,122),(328286,120,123),(328285,120,124),(328287,120,125),(328134,121,1),(328140,121,2),(328139,121,3),(328146,121,6),(328142,121,11),(328129,121,13),(328128,121,18),(328126,121,21),(328130,121,33),(328127,121,35),(328145,121,36),(328148,121,44),(328147,121,47),(328141,121,49),(328131,121,53),(328144,121,54),(328143,121,58),(328138,121,70),(328132,121,72),(328135,121,75),(328133,121,76),(328136,121,111),(328125,121,121),(328137,121,125),(328156,122,1),(328166,122,2),(328165,122,3),(328168,122,6),(328167,122,11),(328150,122,15),(328151,122,35),(328159,122,36),(328163,122,44),(328162,122,47),(328152,122,49),(328160,122,54),(328153,122,56),(328161,122,58),(328164,122,70),(328155,122,75),(328154,122,76),(328157,122,111),(328149,122,122),(328158,122,125),(328213,123,1),(328215,123,2),(328214,123,3),(328219,123,6),(328218,123,11),(328211,123,33),(328212,123,56),(328216,123,70),(328217,123,76),(328210,123,123),(328173,124,1),(328185,124,2),(328184,124,3),(328189,124,6),(328188,124,11),(328177,124,18),(328170,124,35),(328182,124,36),(328171,124,37),(328187,124,44),(328186,124,47),(328178,124,49),(328181,124,54),(328180,124,58),(328183,124,70),(328179,124,74),(328172,124,75),(328174,124,76),(328175,124,111),(328169,124,124),(328176,124,125),(328220,125,125),(328197,126,1),(328207,126,2),(328206,126,3),(328209,126,6),(328208,126,11),(328191,126,15),(328192,126,35),(328200,126,36),(328204,126,44),(328203,126,47),(328193,126,49),(328201,126,54),(328194,126,56),(328202,126,58),(328205,126,70),(328196,126,75),(328195,126,76),(328198,126,111),(328199,126,125),(328190,126,126); -/*!40000 ALTER TABLE `roleRole` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `userPassword` --- - -LOCK TABLES `userPassword` WRITE; -/*!40000 ALTER TABLE `userPassword` DISABLE KEYS */; -INSERT INTO `userPassword` VALUES (1,7,1,0,2,1); -/*!40000 ALTER TABLE `userPassword` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `accountConfig` --- - -LOCK TABLES `accountConfig` WRITE; -/*!40000 ALTER TABLE `accountConfig` DISABLE KEYS */; -INSERT INTO `accountConfig` VALUES (1,'/mnt/homes','/bin/bash',10000,5,60,5,30); -/*!40000 ALTER TABLE `accountConfig` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `mailConfig` --- - -LOCK TABLES `mailConfig` WRITE; -/*!40000 ALTER TABLE `mailConfig` DISABLE KEYS */; -INSERT INTO `mailConfig` VALUES (1,'verdnatura.es'); -/*!40000 ALTER TABLE `mailConfig` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 -USE `salix`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: salix --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `ACL` --- - -LOCK TABLES `ACL` WRITE; -/*!40000 ALTER TABLE `ACL` DISABLE KEYS */; -INSERT INTO `ACL` VALUES (3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(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','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(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'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','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'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(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,'Ticket','state','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','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','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(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','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','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','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(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','*','*','ALLOW','ROLE','logisticBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryAssistant'),(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,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','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'),(165,'TicketDms','*','*','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryAssistant'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','find','READ','ALLOW','ROLE','hr'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','READ','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','refund','WRITE','ALLOW','ROLE','invoicing'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'),(299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'),(302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'),(303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'),(304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'),(305,'EducationLevel','*','*','ALLOW','ROLE','employee'),(306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'),(308,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(309,'Zone','getZoneClosing','*','ALLOW','ROLE','employee'),(310,'ExpeditionState','*','READ','ALLOW','ROLE','employee'),(311,'Expense','*','READ','ALLOW','ROLE','employee'),(312,'Expense','*','WRITE','ALLOW','ROLE','administrative'),(314,'SupplierActivity','*','READ','ALLOW','ROLE','employee'),(315,'SupplierActivity','*','WRITE','ALLOW','ROLE','administrative'),(316,'Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee'),(317,'ClientUnpaid','*','*','ALLOW','ROLE','administrative'),(318,'MdbVersion','*','*','ALLOW','ROLE','developer'),(319,'ItemType','*','READ','ALLOW','ROLE','employee'),(320,'ItemType','*','WRITE','ALLOW','ROLE','buyer'),(321,'InvoiceOut','refund','WRITE','ALLOW','ROLE','invoicing'),(322,'InvoiceOut','refund','WRITE','ALLOW','ROLE','salesAssistant'),(323,'InvoiceOut','refund','WRITE','ALLOW','ROLE','claimManager'),(324,'Ticket','refund','WRITE','ALLOW','ROLE','invoicing'),(325,'Ticket','refund','WRITE','ALLOW','ROLE','salesAssistant'),(326,'Ticket','refund','WRITE','ALLOW','ROLE','claimManager'),(327,'Sale','refund','WRITE','ALLOW','ROLE','salesAssistant'),(328,'Sale','refund','WRITE','ALLOW','ROLE','claimManager'),(329,'TicketRefund','*','WRITE','ALLOW','ROLE','invoicing'),(330,'ClaimObservation','*','WRITE','ALLOW','ROLE','salesPerson'),(331,'ClaimObservation','*','READ','ALLOW','ROLE','salesPerson'),(332,'Client','setPassword','WRITE','ALLOW','ROLE','salesPerson'),(333,'Client','updateUser','WRITE','ALLOW','ROLE','salesPerson'),(334,'ShelvingLog','*','READ','ALLOW','ROLE','employee'),(335,'ZoneExclusionGeo','*','READ','ALLOW','ROLE','employee'),(336,'ZoneExclusionGeo','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(337,'Parking','*','*','ALLOW','ROLE','employee'),(338,'Shelving','*','*','ALLOW','ROLE','employee'),(339,'OsTicket','*','*','ALLOW','ROLE','employee'),(340,'OsTicketConfig','*','*','ALLOW','ROLE','it'),(341,'ClientConsumptionQueue','*','WRITE','ALLOW','ROLE','employee'),(342,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','employee'),(343,'Ticket','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'),(344,'Ticket','deliveryNoteCsvPdf','READ','ALLOW','ROLE','employee'),(345,'Ticket','deliveryNoteCsvEmail','READ','ALLOW','ROLE','employee'),(346,'Client','campaignMetricsPdf','READ','ALLOW','ROLE','employee'),(347,'Client','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'),(348,'Client','clientWelcomeHtml','READ','ALLOW','ROLE','employee'),(349,'Client','clientWelcomeEmail','WRITE','ALLOW','ROLE','employee'),(350,'Client','creditRequestPdf','READ','ALLOW','ROLE','employee'),(351,'Client','creditRequestHtml','READ','ALLOW','ROLE','employee'),(352,'Client','creditRequestEmail','WRITE','ALLOW','ROLE','employee'),(353,'Client','printerSetupHtml','READ','ALLOW','ROLE','employee'),(354,'Client','printerSetupEmail','WRITE','ALLOW','ROLE','employee'),(355,'Client','sepaCoreEmail','WRITE','ALLOW','ROLE','employee'),(356,'Client','letterDebtorPdf','READ','ALLOW','ROLE','employee'),(357,'Client','letterDebtorStHtml','READ','ALLOW','ROLE','employee'),(358,'Client','letterDebtorStEmail','WRITE','ALLOW','ROLE','employee'),(359,'Client','letterDebtorNdHtml','READ','ALLOW','ROLE','employee'),(360,'Client','letterDebtorNdEmail','WRITE','ALLOW','ROLE','employee'),(361,'Client','clientDebtStatementPdf','READ','ALLOW','ROLE','employee'),(362,'Client','clientDebtStatementHtml','READ','ALLOW','ROLE','employee'),(363,'Client','clientDebtStatementEmail','WRITE','ALLOW','ROLE','employee'),(364,'Client','incotermsAuthorizationPdf','READ','ALLOW','ROLE','employee'),(365,'Client','incotermsAuthorizationHtml','READ','ALLOW','ROLE','employee'),(366,'Client','incotermsAuthorizationEmail','WRITE','ALLOW','ROLE','employee'),(367,'Client','consumptionSendQueued','WRITE','ALLOW','ROLE','system'),(368,'InvoiceOut','invoiceEmail','WRITE','ALLOW','ROLE','employee'),(369,'InvoiceOut','exportationPdf','READ','ALLOW','ROLE','employee'),(370,'InvoiceOut','sendQueued','WRITE','ALLOW','ROLE','system'),(371,'Ticket','invoiceCsvPdf','READ','ALLOW','ROLE','employee'),(372,'Ticket','invoiceCsvEmail','WRITE','ALLOW','ROLE','employee'),(373,'Supplier','campaignMetricsPdf','READ','ALLOW','ROLE','employee'),(374,'Supplier','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'),(375,'Travel','extraCommunityPdf','READ','ALLOW','ROLE','employee'),(376,'Travel','extraCommunityEmail','WRITE','ALLOW','ROLE','employee'),(377,'Entry','entryOrderPdf','READ','ALLOW','ROLE','employee'),(378,'OsTicket','osTicketReportEmail','WRITE','ALLOW','ROLE','system'),(379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system'),(380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee'),(381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager'),(382,'Item','labelPdf','READ','ALLOW','ROLE','employee'),(383,'Sector','*','READ','ALLOW','ROLE','employee'),(384,'Sector','*','WRITE','ALLOW','ROLE','employee'),(385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee'),(386,'Route','driverRouteEmail','WRITE','ALLOW','ROLE','employee'),(387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','customer'),(388,'Supplier','newSupplier','WRITE','ALLOW','ROLE','administrative'),(389,'ClaimRma','*','READ','ALLOW','ROLE','claimManager'),(390,'ClaimRma','*','WRITE','ALLOW','ROLE','claimManager'),(391,'Notification','*','WRITE','ALLOW','ROLE','system'),(392,'Boxing','*','*','ALLOW','ROLE','employee'),(393,'Url','*','READ','ALLOW','ROLE','employee'),(394,'Url','*','WRITE','ALLOW','ROLE','it'),(395,'ItemShelving','*','READ','ALLOW','ROLE','employee'),(396,'ItemShelving','*','WRITE','ALLOW','ROLE','production'),(397,'ItemShelvingPlacementSupplyStock','*','READ','ALLOW','ROLE','employee'),(398,'NotificationQueue','*','*','ALLOW','ROLE','employee'),(399,'InvoiceOut','clientsToInvoice','WRITE','ALLOW','ROLE','invoicing'),(400,'InvoiceOut','invoiceClient','WRITE','ALLOW','ROLE','invoicing'),(401,'Sale','editTracked','WRITE','ALLOW','ROLE','production'),(402,'Sale','editFloramondo','WRITE','ALLOW','ROLE','salesAssistant'),(403,'Receipt','balanceCompensationEmail','WRITE','ALLOW','ROLE','employee'),(404,'Receipt','balanceCompensationPdf','READ','ALLOW','ROLE','employee'),(405,'Ticket','getTicketsFuture','READ','ALLOW','ROLE','employee'),(406,'Ticket','merge','WRITE','ALLOW','ROLE','employee'),(407,'Sale','editFloramondo','WRITE','ALLOW','ROLE','logistic'),(408,'ZipConfig','*','*','ALLOW','ROLE','employee'),(409,'Item','*','WRITE','ALLOW','ROLE','administrative'),(410,'Sale','editCloned','WRITE','ALLOW','ROLE','buyer'),(411,'Sale','editCloned','WRITE','ALLOW','ROLE','salesAssistant'),(414,'MdbVersion','*','READ','ALLOW','ROLE','$everyone'),(416,'TicketLog','getChanges','READ','ALLOW','ROLE','employee'),(417,'Ticket','getTicketsAdvance','READ','ALLOW','ROLE','employee'),(418,'EntryLog','*','READ','ALLOW','ROLE','administrative'),(419,'Sale','editTracked','WRITE','ALLOW','ROLE','buyer'),(420,'MdbBranch','*','READ','ALLOW','ROLE','$everyone'),(421,'ItemShelvingSale','*','*','ALLOW','ROLE','employee'),(422,'Docuware','checkFile','READ','ALLOW','ROLE','employee'),(423,'Docuware','download','READ','ALLOW','ROLE','salesPerson'),(424,'Docuware','upload','WRITE','ALLOW','ROLE','productionAssi'),(425,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','salesPerson'),(426,'TpvTransaction','confirm','WRITE','ALLOW','ROLE','$everyone'),(427,'TpvTransaction','start','WRITE','ALLOW','ROLE','$authenticated'),(428,'TpvTransaction','end','WRITE','ALLOW','ROLE','$authenticated'),(429,'ItemConfig','*','READ','ALLOW','ROLE','employee'),(431,'Tag','onSubmit','WRITE','ALLOW','ROLE','employee'),(432,'Worker','updateAttributes','WRITE','ALLOW','ROLE','hr'),(433,'Worker','createAbsence','*','ALLOW','ROLE','employee'),(434,'Worker','updateAbsence','WRITE','ALLOW','ROLE','employee'),(435,'Worker','deleteAbsence','*','ALLOW','ROLE','employee'),(436,'Worker','new','WRITE','ALLOW','ROLE','hr'),(438,'Client','getClientOrSupplierReference','READ','ALLOW','ROLE','employee'),(439,'NotificationSubscription','*','*','ALLOW','ROLE','employee'),(440,'NotificationAcl','*','READ','ALLOW','ROLE','employee'),(441,'MdbApp','*','READ','ALLOW','ROLE','$everyone'),(442,'MdbApp','*','*','ALLOW','ROLE','developer'),(443,'ItemConfig','*','*','ALLOW','ROLE','employee'),(444,'DeviceProduction','*','*','ALLOW','ROLE','hr'),(445,'DeviceProductionModels','*','*','ALLOW','ROLE','hr'),(446,'DeviceProductionState','*','*','ALLOW','ROLE','hr'),(447,'DeviceProductionUser','*','*','ALLOW','ROLE','hr'),(448,'DeviceProduction','*','*','ALLOW','ROLE','productionAssi'),(449,'DeviceProductionModels','*','*','ALLOW','ROLE','productionAssi'),(450,'DeviceProductionState','*','*','ALLOW','ROLE','productionAssi'),(451,'DeviceProductionUser','*','*','ALLOW','ROLE','productionAssi'),(452,'Worker','deallocatePDA','*','ALLOW','ROLE','hr'),(453,'Worker','allocatePDA','*','ALLOW','ROLE','hr'),(454,'Worker','deallocatePDA','*','ALLOW','ROLE','productionAssi'),(455,'Worker','allocatePDA','*','ALLOW','ROLE','productionAssi'),(456,'Zone','*','*','ALLOW','ROLE','deliveryAssistant'),(458,'Operator','*','READ','ALLOW','ROLE','employee'),(459,'Operator','*','WRITE','ALLOW','ROLE','employee'),(460,'InvoiceIn','getSerial','READ','ALLOW','ROLE','administrative'),(461,'Ticket','saveSign','WRITE','ALLOW','ROLE','employee'),(462,'InvoiceOut','negativeBases','READ','ALLOW','ROLE','administrative'),(463,'InvoiceOut','negativeBasesCsv','READ','ALLOW','ROLE','administrative'),(464,'WorkerObservation','*','*','ALLOW','ROLE','hr'),(465,'ClientInforma','*','READ','ALLOW','ROLE','employee'),(466,'ClientInforma','*','WRITE','ALLOW','ROLE','financial'),(467,'Receipt','receiptEmail','*','ALLOW','ROLE','salesAssistant'),(468,'Client','setRating','WRITE','ALLOW','ROLE','financial'),(470,'Client','addressesPropagateRe','*','ALLOW','ROLE','employee'),(471,'Client','canBeInvoiced','*','ALLOW','ROLE','employee'),(472,'Client','canCreateTicket','*','ALLOW','ROLE','employee'),(473,'Client','consumption','*','ALLOW','ROLE','employee'),(474,'Client','createAddress','*','ALLOW','ROLE','employee'),(475,'Client','createWithUser','*','ALLOW','ROLE','employee'),(476,'Client','extendedListFilter','*','ALLOW','ROLE','employee'),(477,'Client','getAverageInvoiced','*','ALLOW','ROLE','employee'),(478,'Client','getCard','*','ALLOW','ROLE','employee'),(479,'Client','getDebt','*','ALLOW','ROLE','employee'),(480,'Client','getMana','*','ALLOW','ROLE','employee'),(481,'Client','transactions','*','ALLOW','ROLE','employee'),(482,'Client','hasCustomerRole','*','ALLOW','ROLE','employee'),(483,'Client','isValidClient','*','ALLOW','ROLE','employee'),(484,'Client','lastActiveTickets','*','ALLOW','ROLE','employee'),(485,'Client','sendSms','*','ALLOW','ROLE','employee'),(486,'Client','setPassword','*','ALLOW','ROLE','employee'),(487,'Client','summary','*','ALLOW','ROLE','employee'),(488,'Client','updateAddress','*','ALLOW','ROLE','employee'),(489,'Client','updateFiscalData','*','ALLOW','ROLE','employee'),(491,'Client','uploadFile','*','ALLOW','ROLE','employee'),(492,'Client','campaignMetricsPdf','*','ALLOW','ROLE','employee'),(493,'Client','campaignMetricsEmail','*','ALLOW','ROLE','employee'),(494,'Client','clientWelcomeHtml','*','ALLOW','ROLE','employee'),(495,'Client','clientWelcomeEmail','*','ALLOW','ROLE','employee'),(496,'Client','printerSetupHtml','*','ALLOW','ROLE','employee'),(497,'Client','printerSetupEmail','*','ALLOW','ROLE','employee'),(498,'Client','sepaCoreEmail','*','ALLOW','ROLE','employee'),(499,'Client','letterDebtorPdf','*','ALLOW','ROLE','employee'),(500,'Client','letterDebtorStHtml','*','ALLOW','ROLE','employee'),(501,'Client','letterDebtorStEmail','*','ALLOW','ROLE','employee'),(502,'Client','letterDebtorNdHtml','*','ALLOW','ROLE','employee'),(503,'Client','letterDebtorNdEmail','*','ALLOW','ROLE','employee'),(504,'Client','clientDebtStatementPdf','*','ALLOW','ROLE','employee'),(505,'Client','clientDebtStatementHtml','*','ALLOW','ROLE','employee'),(506,'Client','clientDebtStatementEmail','*','ALLOW','ROLE','employee'),(507,'Client','creditRequestPdf','*','ALLOW','ROLE','employee'),(508,'Client','creditRequestHtml','*','ALLOW','ROLE','employee'),(509,'Client','creditRequestEmail','*','ALLOW','ROLE','employee'),(510,'Client','incotermsAuthorizationPdf','*','ALLOW','ROLE','employee'),(511,'Client','incotermsAuthorizationHtml','*','ALLOW','ROLE','employee'),(512,'Client','incotermsAuthorizationEmail','*','ALLOW','ROLE','employee'),(513,'Client','consumptionSendQueued','*','ALLOW','ROLE','employee'),(514,'Client','filter','*','ALLOW','ROLE','employee'),(515,'Client','getClientOrSupplierReference','*','ALLOW','ROLE','employee'),(516,'Client','upsert','*','ALLOW','ROLE','employee'),(518,'Client','replaceById','*','ALLOW','ROLE','employee'),(519,'Client','updateAttributes','*','ALLOW','ROLE','employee'),(520,'Client','updateAttributes','*','ALLOW','ROLE','employee'),(521,'Client','deleteById','*','ALLOW','ROLE','employee'),(522,'Client','replaceOrCreate','*','ALLOW','ROLE','employee'),(523,'Client','updateAll','*','ALLOW','ROLE','employee'),(524,'Client','upsertWithWhere','*','ALLOW','ROLE','employee'),(525,'Defaulter','observationEmail','WRITE','ALLOW','ROLE','employee'),(527,'VnUser','acl','READ','ALLOW','ROLE','account'),(528,'VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'),(530,'Account','exists','READ','ALLOW','ROLE','account'),(531,'Account','exists','READ','ALLOW','ROLE','account'),(532,'UserLog','*','READ','ALLOW','ROLE','employee'),(533,'RoleLog','*','READ','ALLOW','ROLE','employee'),(534,'WagonType','*','*','ALLOW','ROLE','productionAssi'),(535,'WagonTypeColor','*','*','ALLOW','ROLE','productionAssi'),(536,'WagonTypeTray','*','*','ALLOW','ROLE','productionAssi'),(537,'WagonConfig','*','*','ALLOW','ROLE','productionAssi'),(538,'CollectionWagon','*','*','ALLOW','ROLE','productionAssi'),(539,'CollectionWagonTicket','*','*','ALLOW','ROLE','productionAssi'),(540,'Wagon','*','*','ALLOW','ROLE','productionAssi'),(541,'WagonType','createWagonType','*','ALLOW','ROLE','productionAssi'),(542,'WagonType','deleteWagonType','*','ALLOW','ROLE','productionAssi'),(543,'WagonType','editWagonType','*','ALLOW','ROLE','productionAssi'),(544,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'),(545,'Agency','find','READ','ALLOW','ROLE','employee'),(546,'Agency','seeExpired','READ','ALLOW','ROLE','coolerAssist'),(547,'WorkerLog','models','READ','ALLOW','ROLE','hr'),(548,'Ticket','editDiscount','WRITE','ALLOW','ROLE','claimManager'),(549,'Ticket','editDiscount','WRITE','ALLOW','ROLE','salesPerson'),(550,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','salesAssistant'),(551,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','deliveryAssistant'),(552,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','buyer'),(553,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','claimManager'),(554,'Ticket','deleteTicketWithPartPrepared','WRITE','ALLOW','ROLE','salesAssistant'),(555,'Ticket','editZone','WRITE','ALLOW','ROLE','deliveryAssistant'),(556,'State','editableStates','READ','ALLOW','ROLE','employee'),(557,'State','seeEditableStates','READ','ALLOW','ROLE','administrative'),(558,'State','seeEditableStates','READ','ALLOW','ROLE','production'),(559,'State','isSomeEditable','READ','ALLOW','ROLE','salesPerson'),(560,'State','isAllEditable','READ','ALLOW','ROLE','production'),(561,'State','isAllEditable','READ','ALLOW','ROLE','administrative'),(562,'Agency','seeExpired','READ','ALLOW','ROLE','administrative'),(563,'Agency','seeExpired','READ','ALLOW','ROLE','productionBoss'),(564,'Claim','createAfterDeadline','WRITE','ALLOW','ROLE','claimManager'),(565,'Client','editAddressLogifloraAllowed','WRITE','ALLOW','ROLE','salesAssistant'),(566,'Client','editFiscalDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'),(567,'Client','editVerifiedDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'),(568,'Client','editCredit','WRITE','ALLOW','ROLE','financialBoss'),(569,'Client','zeroCreditEditor','WRITE','ALLOW','ROLE','financialBoss'),(570,'InvoiceOut','canCreatePdf','WRITE','ALLOW','ROLE','invoicing'),(571,'Supplier','editPayMethodCheck','WRITE','ALLOW','ROLE','financial'),(572,'Worker','isTeamBoss','WRITE','ALLOW','ROLE','teamBoss'),(573,'Worker','forceIsSubordinate','READ','ALLOW','ROLE','hr'),(574,'Claim','editState','WRITE','ALLOW','ROLE','claimManager'),(577,'Claim','findOne','READ','ALLOW','ROLE','salesPerson'),(579,'Claim','updateClaim','WRITE','ALLOW','ROLE','salesPerson'),(580,'Claim','regularizeClaim','WRITE','ALLOW','ROLE','claimManager'),(581,'Claim','updateClaimDestination','WRITE','ALLOW','ROLE','claimManager'),(582,'Claim','downloadFile','READ','ALLOW','ROLE','claimManager'),(583,'Claim','deleteById','WRITE','ALLOW','ROLE','claimManager'),(585,'Claim','logs','READ','ALLOW','ROLE','claimManager'),(586,'Ticket','find','READ','ALLOW','ROLE','employee'),(587,'Ticket','findById','READ','ALLOW','ROLE','employee'),(588,'Ticket','findOne','READ','ALLOW','ROLE','employee'),(589,'Ticket','getVolume','READ','ALLOW','ROLE','employee'),(590,'Ticket','getTotalVolume','READ','ALLOW','ROLE','employee'),(591,'Ticket','summary','READ','ALLOW','ROLE','employee'),(592,'Ticket','priceDifference','READ','ALLOW','ROLE','employee'),(593,'Ticket','componentUpdate','WRITE','ALLOW','ROLE','employee'),(594,'Ticket','new','WRITE','ALLOW','ROLE','employee'),(595,'Ticket','isEditable','READ','ALLOW','ROLE','employee'),(596,'Ticket','setDeleted','WRITE','ALLOW','ROLE','salesPerson'),(597,'Ticket','restore','WRITE','ALLOW','ROLE','employee'),(598,'Ticket','getSales','READ','ALLOW','ROLE','employee'),(599,'Ticket','getSalesPersonMana','READ','ALLOW','ROLE','employee'),(600,'Ticket','filter','READ','ALLOW','ROLE','employee'),(601,'Ticket','makeInvoice','WRITE','ALLOW','ROLE','employee'),(602,'Ticket','updateEditableTicket','WRITE','ALLOW','ROLE','employee'),(603,'Ticket','updateDiscount','WRITE','ALLOW','ROLE','employee'),(604,'Ticket','transferSales','WRITE','ALLOW','ROLE','employee'),(605,'Ticket','sendSms','WRITE','ALLOW','ROLE','employee'),(606,'Ticket','isLocked','READ','ALLOW','ROLE','employee'),(607,'Ticket','freightCost','READ','ALLOW','ROLE','employee'),(608,'Ticket','getComponentsSum','READ','ALLOW','ROLE','employee'),(609,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','delivery'),(610,'Ticket','deliveryNoteCsv','READ','ALLOW','ROLE','employee'),(611,'State','find','READ','ALLOW','ROLE','employee'),(612,'State','findById','READ','ALLOW','ROLE','employee'),(613,'State','findOne','READ','ALLOW','ROLE','employee'),(614,'Worker','find','READ','ALLOW','ROLE','employee'),(615,'Worker','findById','READ','ALLOW','ROLE','employee'),(616,'Worker','findOne','READ','ALLOW','ROLE','employee'),(617,'Worker','filter','READ','ALLOW','ROLE','employee'),(618,'Worker','getWorkedHours','READ','ALLOW','ROLE','employee'),(619,'Worker','active','READ','ALLOW','ROLE','employee'),(620,'Worker','activeWithRole','READ','ALLOW','ROLE','employee'),(621,'Worker','uploadFile','WRITE','ALLOW','ROLE','hr'),(622,'Worker','contracts','READ','ALLOW','ROLE','employee'),(623,'Worker','holidays','READ','ALLOW','ROLE','employee'),(624,'Worker','activeContract','READ','ALLOW','ROLE','employee'),(625,'Worker','activeWithInheritedRole','READ','ALLOW','ROLE','employee'),(626,'Ticket','collectionLabel','READ','ALLOW','ROLE','employee'),(628,'Ticket','expeditionPalletLabel','READ','ALLOW','ROLE','employee'),(629,'Ticket','editDiscount','WRITE','ALLOW','ROLE','artificialBoss'),(630,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesTeamBoss'),(635,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','administrative'),(636,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesPerson'),(637,'Claim','downloadFile','READ','ALLOW','ROLE','salesPerson'),(638,'Agency','seeExpired','READ','ALLOW','ROLE','artificialBoss'),(639,'Agency','seeExpired','READ','ALLOW','ROLE','logisticAssistant'),(654,'Ticket','editZone','WRITE','ALLOW','ROLE','logisticAssistant'),(655,'Entry','addFromPackaging','WRITE','ALLOW','ROLE','production'),(656,'Entry','addFromBuy','WRITE','ALLOW','ROLE','production'),(657,'Supplier','getItemsPackaging','READ','ALLOW','ROLE','production'),(658,'Ticket','closeAll','WRITE','ALLOW','ROLE','system'),(659,'Account','*','*','ALLOW','ROLE','developerBoss'),(664,'MailForward','*','*','ALLOW','ROLE','itManagement'),(665,'Role','*','READ','ALLOW','ROLE','employee'),(666,'Role','*','WRITE','ALLOW','ROLE','it'),(667,'VnUser','*','*','ALLOW','ROLE','itManagement'),(668,'VnUser','__get__preview','READ','ALLOW','ROLE','employee'),(669,'VnUser','preview','*','ALLOW','ROLE','employee'),(670,'VnUser','create','*','ALLOW','ROLE','itManagement'),(671,'VnUser','renewToken','WRITE','ALLOW','ROLE','employee'),(672,'PackingSiteAdvanced','*','*','ALLOW','ROLE','production'),(673,'InvoiceOut','makePdfAndNotify','WRITE','ALLOW','ROLE','invoicing'),(674,'InvoiceOutConfig','*','READ','ALLOW','ROLE','invoicing'),(676,'Ticket','invoiceTickets','WRITE','ALLOW','ROLE','employee'),(680,'MailAliasAccount','*','READ','ALLOW','ROLE','employee'),(681,'MailAliasAccount','create','WRITE','ALLOW','ROLE','employee'),(682,'MailAliasAccount','deleteById','WRITE','ALLOW','ROLE','employee'),(683,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','itManagement'),(684,'WorkerDisableExcluded','*','READ','ALLOW','ROLE','itManagement'),(685,'WorkerDisableExcluded','*','WRITE','ALLOW','ROLE','itManagement'),(686,'MailForward','*','*','ALLOW','ROLE','hr'),(687,'ClientSms','find','READ','ALLOW','ROLE','employee'),(688,'ClientSms','create','WRITE','ALLOW','ROLE','employee'),(689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'),(690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'),(691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'),(692,'ExpeditionTruck','*','*','ALLOW','ROLE','palletizerBoss'),(693,'ExpeditionTruck','*','*','ALLOW','ROLE','productionBoss'),(694,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','marketingBoss'),(695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'),(696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'),(697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'),(698,'Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer'),(699,'TicketSms','find','READ','ALLOW','ROLE','salesPerson'),(701,'Docuware','upload','WRITE','ALLOW','ROLE','deliveryAssistant'),(702,'Ticket','docuwareDownload','READ','ALLOW','ROLE','salesPerson'),(703,'Worker','search','READ','ALLOW','ROLE','employee'),(704,'ExpeditionState','addExpeditionState','WRITE','ALLOW','ROLE','delivery'),(705,'SaleGroupDetail','deleteById','WRITE','ALLOW','ROLE','employee'),(706,'Ticket','setDeleted','WRITE','ALLOW','ROLE','buyer'),(707,'DeviceLog','create','WRITE','ALLOW','ROLE','employee'),(708,'Collection','getTickets','WRITE','ALLOW','ROLE','employee'),(709,'Client','findOne','READ','ALLOW','ROLE','employee'),(710,'Client','findById','READ','ALLOW','ROLE','employee'),(711,'Client','find','READ','ALLOW','ROLE','employee'),(712,'Client','exists','READ','ALLOW','ROLE','employee'),(713,'Client','__get__addresses','READ','ALLOW','ROLE','employee'),(714,'ExpeditionMistakeType','*','READ','ALLOW','ROLE','employee'),(715,'WorkerMistakeType','*','READ','ALLOW','ROLE','employee'),(716,'ExpeditionMistake','*','WRITE','ALLOW','ROLE','employee'),(717,'WorkerMistake','*','WRITE','ALLOW','ROLE','coolerBoss'),(718,'MistakesTypes','*','WRITE','ALLOW','ROLE','coolerBoss'),(719,'MistakeType','*','READ','ALLOW','ROLE','employee'),(720,'MachineWorker','*','READ','ALLOW','ROLE','coolerAssist'),(721,'Printer','*','READ','ALLOW','ROLE','employee'),(722,'SaleMistake','*','WRITE','ALLOW','ROLE','production'),(723,'Item','setVisibleDiscard','WRITE','ALLOW','ROLE','employee'),(724,'Address','getAddress','READ','ALLOW','ROLE','employee'),(725,'Account','findOne','READ','ALLOW','ROLE','employee'),(726,'Account','findById','READ','ALLOW','ROLE','employee'),(727,'Account','find','READ','ALLOW','ROLE','employee'),(728,'Account','exists','READ','ALLOW','ROLE','employee'),(729,'Sale','refund','WRITE','ALLOW','ROLE','buyer'),(730,'Ticket','setDeleted','WRITE','ALLOW','ROLE','deliveryAssistant'),(732,'Sale','isInPreparing','*','ALLOW','ROLE','production'),(733,'Train','*','READ','ALLOW','ROLE','production'),(734,'WorkerDepartment','*','*','ALLOW','ROLE','employee'),(735,'VnUser','higherPrivileges','*','ALLOW','ROLE','itManagement'),(736,'VnUser','mediumPrivileges','*','ALLOW','ROLE','hr'),(737,'VnUser','updateUser','*','ALLOW','ROLE','employee'),(738,'TicketCollection','*','WRITE','ALLOW','ROLE','production'),(739,'Worker','setPassword','*','ALLOW','ROLE','employee'),(740,'Url','getByUser','READ','ALLOW','ROLE','$everyone'),(741,'Claim','__get__lines','READ','ALLOW','ROLE','claimViewer'),(742,'AddressShortage','*','READ','ALLOW','ROLE','production'),(743,'Claim','filter','READ','ALLOW','ROLE','claimViewer'),(744,'Claim','find','READ','ALLOW','ROLE','claimViewer'),(745,'Claim','findById','READ','ALLOW','ROLE','claimViewer'),(746,'Claim','getSummary','READ','ALLOW','ROLE','claimViewer'),(747,'CplusRectificationType','*','READ','ALLOW','ROLE','administrative'),(748,'SiiTypeInvoiceOut','*','READ','ALLOW','ROLE','administrative'),(749,'InvoiceCorrectionType','*','READ','ALLOW','ROLE','administrative'),(750,'InvoiceOut','transferInvoice','WRITE','ALLOW','ROLE','administrative'); -/*!40000 ALTER TABLE `ACL` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `fieldAcl` --- - -LOCK TABLES `fieldAcl` WRITE; -/*!40000 ALTER TABLE `fieldAcl` DISABLE KEYS */; -INSERT INTO `fieldAcl` VALUES (1,'Client','name','update','employee'),(2,'Client','contact','update','employee'),(3,'Client','email','update','employee'),(4,'Client','phone','update','employee'),(5,'Client','mobile','update','employee'),(6,'Client','contactChannelFk','update','employee'),(7,'Client','socialName','update','salesPerson'),(8,'Client','fi','update','salesPerson'),(9,'Client','street','update','salesPerson'),(10,'Client','postcode','update','salesPerson'),(11,'Client','city','update','salesPerson'),(12,'Client','countryFk','update','salesPerson'),(13,'Client','provinceFk','update','salesPerson'),(14,'Client','isActive','update','salesPerson'),(15,'Client','salesPersonFk','update','salesAssistant'),(16,'Client','hasToInvoice','update','salesPerson'),(17,'Client','isToBeMailed','update','salesPerson'),(18,'Client','isEqualizated','update','salesPerson'),(19,'Client','isFreezed','update','salesPerson'),(20,'Client','isVies','update','salesPerson'),(21,'Client','hasToInvoiceByAddress','update','salesPerson'),(22,'Client','isTaxDataChecked','update','salesAssistant'),(23,'Client','payMethodFk','update','salesAssistant'),(24,'Client','dueDay','update','salesAssistant'),(25,'Client','iban','update','salesAssistant'),(26,'Client','bankEntityFk','update','salesAssistant'),(27,'Client','hasLcr','update','salesAssistant'),(28,'Client','hasCoreVnl','update','salesAssistant'),(29,'Client','hasSepaVnl','update','salesAssistant'),(30,'Client','credit','update','teamBoss'),(31,'BankEntity','*','insert','salesAssistant'),(32,'Address','isDefaultAddress','*','employee'),(33,'Address','nickname','*','employee'),(34,'Address','postalCode','*','employee'),(35,'Address','provinceFk','*','employee'),(36,'Address','agencyModeFk','*','employee'),(37,'Address','phone','*','employee'),(38,'Address','mobile','*','employee'),(39,'Address','street','*','employee'),(40,'Address','city','*','employee'),(41,'Address','isActive','*','employee'),(42,'Address','isEqualizated','*','salesAssistant'),(43,'Address','clientFk','insert','employee'),(44,'ClientObservation','*','insert','employee'),(45,'Recovery','*','insert','administrative'),(46,'Recovery','finished','update','administrative'),(47,'CreditClassification','finished','update','creditInsurance'),(48,'Account','*','update','employee'),(49,'Greuge','*','insert','salesAssistant'),(50,'ClientSample','*','insert','employee'),(51,'Item','*','*','buyer'),(52,'Item','*','*','marketingBoss'),(53,'ItemBotanical','*','*','buyer'),(54,'ClaimEnd','*','*','salesAssistant'),(55,'Receipt','*','*','administrative'),(56,'ClaimBeginning','*','*','salesAssistant'),(57,'TicketRequest','*','*','salesPerson'),(58,'ClaimBeginning','*','*','salesAssistant'),(59,'TicketRequest','*','*','salesPerson'),(60,'ClaimBeginning','*','*','salesAssistant'),(61,'TicketRequest','*','*','salesPerson'),(62,'ClaimBeginning','*','*','salesAssistant'),(63,'TicketRequest','*','*','salesPerson'),(64,'ClaimBeginning','*','*','salesAssistant'); -/*!40000 ALTER TABLE `fieldAcl` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `module` --- - -LOCK TABLES `module` WRITE; -/*!40000 ALTER TABLE `module` DISABLE KEYS */; -INSERT INTO `module` VALUES ('account'),('claim'),('customer'),('entry'),('invoiceIn'),('invoiceOut'),('item'),('monitor'),('order'),('route'),('shelving'),('supplier'),('ticket'),('travel'),('wagon'),('worker'),('zone'); -/*!40000 ALTER TABLE `module` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `defaultViewConfig` --- - -LOCK TABLES `defaultViewConfig` WRITE; -/*!40000 ALTER TABLE `defaultViewConfig` DISABLE KEYS */; -INSERT INTO `defaultViewConfig` VALUES ('itemsIndex','{\"intrastat\":false,\"stemMultiplier\":false,\"landed\":false,\"producer\":false}'),('latestBuys','{\"intrastat\":false,\"description\":false,\"density\":false,\"isActive\":false,\n \"freightValue\":false,\"packageValue\":false,\"isIgnored\":false,\"price2\":false,\"ektFk\":false,\"weight\":false,\n \"size\":false,\"comissionValue\":false,\"landing\":false}'),('ticketsMonitor','{\"id\":false}'),('clientsDetail','{\"id\":true,\"phone\":true,\"city\":true,\"socialName\":true,\"salesPersonFk\":true,\"email\":true,\"name\":false,\"fi\":false,\"credit\":false,\"creditInsurance\":false,\"mobile\":false,\"street\":false,\"countryFk\":false,\"provinceFk\":false,\"postcode\":false,\"created\":false,\"businessTypeFk\":false,\"payMethodFk\":false,\"sageTaxTypeFk\":false,\"sageTransactionTypeFk\":false,\"isActive\":false,\"isVies\":false,\"isTaxDataChecked\":false,\"isEqualizated\":false,\"isFreezed\":false,\"hasToInvoice\":false,\"hasToInvoiceByAddress\":false,\"isToBeMailed\":false,\"hasLcr\":false,\"hasCoreVnl\":false,\"hasSepaVnl\":false}'); -/*!40000 ALTER TABLE `defaultViewConfig` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 -USE `vn`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: vn --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `agencyTermConfig` --- - -LOCK TABLES `agencyTermConfig` WRITE; -/*!40000 ALTER TABLE `agencyTermConfig` DISABLE KEYS */; -INSERT INTO `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios'); -/*!40000 ALTER TABLE `agencyTermConfig` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `alertLevel` --- - -LOCK TABLES `alertLevel` WRITE; -/*!40000 ALTER TABLE `alertLevel` DISABLE KEYS */; -INSERT INTO `alertLevel` VALUES ('FREE',0,1),('ON_PREPARATION',1,1),('PACKED',2,0),('DELIVERED',3,0); -/*!40000 ALTER TABLE `alertLevel` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `bookingPlanner` --- - -LOCK TABLES `bookingPlanner` WRITE; -/*!40000 ALTER TABLE `bookingPlanner` DISABLE KEYS */; -INSERT INTO `bookingPlanner` VALUES (5,'2017-06-30 22:00:00','4770000002','WORLD',7,4,1),(6,'2017-06-30 22:00:00','4770000010','NATIONAL',3,1,1),(8,'2017-06-30 22:00:00','4770000021','NATIONAL',1,2,1),(9,'2017-06-30 22:00:00','4770000101','EQU',3,1,1),(11,'2017-06-30 22:00:00','4770000110','EQU',4,1,1),(12,'2017-06-30 22:00:00','4770000215','EQU',1,2,1),(13,'2017-06-30 22:00:00','4770000521','EQU',2,2,1),(15,'2017-06-30 22:00:00','4771000000','CEE',3,1,1),(16,'2017-06-30 22:00:00','4771000001','CEE',8,3,1),(19,'2017-07-05 11:54:58','4770000020','NATIONAL',7,4,1),(20,'2017-07-05 12:09:24','4771000000','CEE',1,2,1),(21,'2017-07-05 12:09:24','4771000000','CEE',7,4,1),(22,'2017-07-05 12:12:14','4770000002','WORLD',3,1,1),(23,'2017-07-05 12:12:14','4770000002','WORLD',1,2,1),(24,'2017-07-06 08:07:21','4770000002','WORLD',7,4,5),(25,'2017-07-06 08:07:21','HolandaRED','NATIONAL',3,1,5),(27,'2017-07-06 08:07:21','HolandaGEN','NATIONAL',1,2,5),(32,'2017-07-06 08:07:21','4771000000','CEE',3,1,5),(33,'2017-07-06 08:07:21','4771000001','CEE',8,3,5),(34,'2017-07-06 08:07:21','4770000020','NATIONAL',7,4,5),(35,'2017-07-06 08:07:21','4771000000','CEE',1,2,5),(36,'2017-07-06 08:07:21','4771000000','CEE',7,4,5),(37,'2017-07-06 08:07:21','4770000002','WORLD',3,1,5),(38,'2017-07-06 08:07:21','4770000002','WORLD',1,2,5),(82,'2019-01-01 11:51:56','4770000504','EQU',5,5,1),(83,'2019-09-11 10:54:03','4770000405','EQU',6,5,1),(84,'2019-09-11 10:58:17','4770000004','NATIONAL',5,5,1),(85,'2019-09-18 22:00:00','4771000000','CEE',5,5,1),(86,'2021-10-13 22:00:00','4770000002','WORLD',5,5,1); -/*!40000 ALTER TABLE `bookingPlanner` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `businessType` --- - -LOCK TABLES `businessType` WRITE; -/*!40000 ALTER TABLE `businessType` DISABLE KEYS */; -INSERT INTO `businessType` VALUES ('decoration','Decoración'),('events','Eventos'),('florist','Floristería'),('gardenCentre','Vivero'),('gardening','Jardinería'),('individual','Particular'),('mortuary','Funeraria'),('officialOrganism','Organismo oficial'),('others','Otros'),('otherSector','Profesional de otro sector'),('restoration','Restauración'),('trainingCentre','Centro de formación'),('wholesaler','Mayorista'),('worker','Trabajador'); -/*!40000 ALTER TABLE `businessType` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `siiTypeInvoiceIn` --- - -LOCK TABLES `siiTypeInvoiceIn` WRITE; -/*!40000 ALTER TABLE `siiTypeInvoiceIn` DISABLE KEYS */; -INSERT INTO `siiTypeInvoiceIn` VALUES (1,'F1','Factura'),(2,'F2','Factura simplificada (ticket)'),(3,'F3','Factura emitida en sustitución de facturas simplificadas facturadas y declaradas'),(4,'F4','Asiento resumen de facturas'),(5,'F5','Importaciones (DUA)'),(6,'F6','Otros justificantes contables'),(7,'R1','Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)'),(8,'R2','Factura rectificativa (Art. 80.3)'),(9,'R3','Factura rectificativa (Art. 80.4)'),(10,'R4','Factura rectificativa (Resto)'),(11,'R5','Factura rectificativa en facturas simplificadas'); -/*!40000 ALTER TABLE `siiTypeInvoiceIn` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `siiTypeInvoiceOut` --- - -LOCK TABLES `siiTypeInvoiceOut` WRITE; -/*!40000 ALTER TABLE `siiTypeInvoiceOut` DISABLE KEYS */; -INSERT INTO `siiTypeInvoiceOut` VALUES (1,'F1','Factura'),(2,'F2','Factura simplificada (ticket)'),(3,'F3','Factura emitida en sustitución de facturas simplificadas facturadas y declaradas'),(4,'F4','Asiento resumen de facturas'),(5,'R1','Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)'),(6,'R2','Factura rectificativa (Art. 80.3)'),(7,'R3','Factura rectificativa (Art. 80.4)'),(8,'R4','Factura rectificativa (Resto)'),(9,'R5','Factura rectificativa en facturas simplificadas'); -/*!40000 ALTER TABLE `siiTypeInvoiceOut` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `cplusRectificationType` --- - -LOCK TABLES `cplusRectificationType` WRITE; -/*!40000 ALTER TABLE `cplusRectificationType` DISABLE KEYS */; -INSERT INTO `cplusRectificationType` VALUES (1,'Campo vacio'),(2,'I – Por diferencias'),(3,'S – Por sustitución'); -/*!40000 ALTER TABLE `cplusRectificationType` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `cplusSubjectOp` --- - -LOCK TABLES `cplusSubjectOp` WRITE; -/*!40000 ALTER TABLE `cplusSubjectOp` DISABLE KEYS */; -INSERT INTO `cplusSubjectOp` VALUES (1,'Campo vacio'),(2,'S1 – Sujeta – No exenta'),(3,'S2 – Sujeta – No exenta – Inv. Suj. Pasivo'); -/*!40000 ALTER TABLE `cplusSubjectOp` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `cplusTaxBreak` --- - -LOCK TABLES `cplusTaxBreak` WRITE; -/*!40000 ALTER TABLE `cplusTaxBreak` DISABLE KEYS */; -INSERT INTO `cplusTaxBreak` VALUES (1,'Campo vacio'),(2,'E1 - Exenta por el artículo 20'),(3,'E2 - Exenta por el artículo 21'),(4,'E3 - Exenta por el artículo 22'),(5,'E4 - Exenta por el artículo 24'),(6,'E5 - Exenta por el artículo 25'),(7,'E6 - Exenta por otros'); -/*!40000 ALTER TABLE `cplusTaxBreak` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `siiTrascendencyInvoiceIn` --- - -LOCK TABLES `siiTrascendencyInvoiceIn` WRITE; -/*!40000 ALTER TABLE `siiTrascendencyInvoiceIn` DISABLE KEYS */; -INSERT INTO `siiTrascendencyInvoiceIn` VALUES (1,'Operación de régimen general'),(2,'Operaciones por las que los empresarios satisfacen compensaciones REAGYP'),(3,'Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (135 - 139 de LIVA)'),(4,'Régimen especial oro de inversión'),(5,'Régimen especial agencias de viajes'),(6,'Régimen especial grupo de entidades en IVA (Nivel Avanzado)'),(7,'Régimen especial criterio de caja'),(8,'Operaciones sujetas al IPSI / IGIC'),(9,'Adquisiciones intracomunitarias de bienes y prestaciones de servicios'),(12,'Operaciones de arrendamiento de local de negocio'),(13,'Factura correspondiente a una importación (informada sin asociar a un DUA)'),(14,'Primer semestre 2017'); -/*!40000 ALTER TABLE `siiTrascendencyInvoiceIn` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `claimResponsible` --- - -LOCK TABLES `claimResponsible` WRITE; -/*!40000 ALTER TABLE `claimResponsible` DISABLE KEYS */; -INSERT INTO `claimResponsible` VALUES (1,'Compradores',0,'buy'),(2,'Proveedor',0,'sup'),(3,'Entradores',0,'ent'),(4,'Camareros',0,'bar'),(6,'Sacadores',0,'pic'),(7,'Revisadores',0,'chk'),(8,'Calidad general',0,'qas'),(9,'Encajadores',0,'pck'),(10,'Clima',0,'wea'),(11,'Comerciales',1,'com'),(12,'Clientes',1,'cli'),(13,'Administración',0,'adm'),(14,'Agencia',0,'age'),(15,'Repartidores',0,'del'),(16,'Informatica',0,'ite'),(17,'Transp.origen',0,'tra'),(18,'Confeccion',0,'con'),(19,'OTROS',0,'oth'),(21,'Gerencia',0,'man'),(22,'Paletizadores',0,'pal'),(23,'Preparación Previa',0,'pre'),(24,'Almacén PCA',0,'war'),(25,'Huelga',0,'str'); -/*!40000 ALTER TABLE `claimResponsible` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `claimReason` --- - -LOCK TABLES `claimReason` WRITE; -/*!40000 ALTER TABLE `claimReason` DISABLE KEYS */; -INSERT INTO `claimReason` VALUES (1,'Prisas',0),(2,'Novato',0),(3,'Exceso de confianza',0),(4,'Exceso de celo',0),(5,'Indiferencia',0),(6,'Extraviado o Hurto',0),(7,'Incompetencia',0),(8,'Ubicación erronea',0),(9,'Dat.Inctos/Pak.conf',0),(10,'Datos duplicados',0),(11,'Fallo stock',0),(12,'Innovación',0),(13,'Distracción',1),(15,'Portes indebidos',0),(16,'Baja calidad',0),(17,'Defectuoso',0),(19,'Endiñado',0),(20,'Calor',0),(21,'Frio',0),(22,'Cambiado',0),(24,'Cansancio',1),(25,'Mal etiquetado',1),(26,'Cantidad malentendido',0),(30,'No revisado',1),(34,'Error fotografia',0),(40,'Fallo Personal VN',0),(41,'Fallo Personal Cliente',0),(42,'Otros',0),(43,'Precio alto',0),(44,'Abuso de confianza',0),(45,'Retraso Agencia',0),(46,'Delicado',0),(47,'Seco',0),(48,'Retraso Reparto',0),(49,'Mal Embalado',0),(50,'Tumbado',0),(51,'Enfermo/Plaga',0),(52,'Mala gestión comercial',0),(53,'Mala gestión comprador',0),(54,'A2',0),(55,'Entrega 48h o más',0); -/*!40000 ALTER TABLE `claimReason` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `claimRedelivery` --- - -LOCK TABLES `claimRedelivery` WRITE; -/*!40000 ALTER TABLE `claimRedelivery` DISABLE KEYS */; -INSERT INTO `claimRedelivery` VALUES (1,'Cliente'),(2,'No dev./No especif.'),(3,'Reparto'),(4,'Agencia'),(5,'Tour'),(6,'Fuera Peninsula'); -/*!40000 ALTER TABLE `claimRedelivery` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `claimResult` --- - -LOCK TABLES `claimResult` WRITE; -/*!40000 ALTER TABLE `claimResult` DISABLE KEYS */; -INSERT INTO `claimResult` VALUES (1,'Otros daños'),(2,'Roces'),(3,'Humedad'),(4,'Deshidratacion'),(5,'Error identidad'),(6,'Incompleto (Faltas)'),(7,'Error packing'),(8,'Error color'),(9,'Error medida'),(10,'Error origen'),(11,'Envejecido'),(12,'Venta Perdida'),(13,'Duplicacion'),(14,'Rechazado'),(15,'Rotura'),(16,'Deterioro/Estropeado'),(17,'Podrido'),(18,'Baboso'),(19,'Cocido'),(20,'Congelado'),(21,'Machacado'),(22,'Error precio'),(23,'Manchado'),(24,'No entregado'),(25,'Cobro indebido'),(26,'Decepcion/Esperaba mas'),(27,'Otros'),(28,'Baboso/Cocido'),(29,'Video Camara'); -/*!40000 ALTER TABLE `claimResult` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `component` --- - -LOCK TABLES `component` WRITE; -/*!40000 ALTER TABLE `component` DISABLE KEYS */; -INSERT INTO `component` VALUES (10,'Precios Especiales',4,NULL,NULL,1,'specialPrices',0),(14,'porte extra por dia semana',6,NULL,NULL,1,'extraCostPerWeekDay',0),(15,'reparto',6,NULL,NULL,1,'delivery',1),(17,'recobro',5,NULL,NULL,1,'debtCollection',0),(21,'ajuste',4,NULL,NULL,1,'adjustment',0),(22,'venta por paquete',9,1,NULL,0,'salePerPackage',0),(23,'venta por caja',9,2,NULL,0,'salePerBox',0),(28,'valor de compra',1,NULL,NULL,1,'purchaseValue',1),(29,'margen',4,NULL,NULL,1,'margin',1),(32,'descuento ultimas unidades',9,3,-0.05,0,'lastUnitsDiscount',0),(33,'venta por caja',9,1,NULL,0,'salePerBox',0),(34,'descuento comprador',4,NULL,NULL,1,'buyerDiscount',0),(35,'cartera comprador',10,NULL,NULL,1,NULL,0),(36,'descuadre',4,NULL,NULL,1,'imbalance',0),(37,'maná',7,4,NULL,0,'mana',0),(38,'embolsado',9,NULL,NULL,1,'bagged',0),(39,'maná auto',7,NULL,NULL,1,'autoMana',0),(40,'cambios Santos 2016',4,NULL,NULL,1,NULL,0),(41,'bonificacion porte',6,NULL,NULL,1,'freightCharge',0),(42,'promocion Francia',4,NULL,NULL,1,'frenchOffer',0),(43,'promocion Floramondo',4,NULL,NULL,1,'floramondoPromo',0),(44,'rappel cadena',2,NULL,NULL,1,'rappel',0),(45,'maná reclamacion',7,4,NULL,0,'manaClaim',0),(46,'recargo a particular',2,NULL,0.25,0,'individual',0),(47,'promocion Italia',4,NULL,NULL,1,'italianOffer',0),(48,'fusión de lineas',4,NULL,NULL,1,'lineFusion',0); -/*!40000 ALTER TABLE `component` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `componentType` --- - -LOCK TABLES `componentType` WRITE; -/*!40000 ALTER TABLE `componentType` DISABLE KEYS */; -INSERT INTO `componentType` VALUES (1,'coste',1,0,'COST'),(2,'com ventas',1,1,NULL),(3,'com compras',1,1,NULL),(4,'empresa',1,1,'MARGIN'),(5,'cliente',0,0,NULL),(6,'agencia',0,0,'FREIGHT'),(7,'cartera_comercial',0,0,'MANA'),(8,'cartera_producto',0,1,NULL),(9,'maniobra',1,0,NULL),(10,'cartera_comprador',0,1,NULL),(11,'errores',0,1,NULL),(12,'otros',0,1,NULL); -/*!40000 ALTER TABLE `componentType` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `continent` --- - -LOCK TABLES `continent` WRITE; -/*!40000 ALTER TABLE `continent` DISABLE KEYS */; -INSERT INTO `continent` VALUES (1,'Asia','AS'),(2,'América','AM'),(3,'África','AF'),(4,'Europa','EU'),(5,'Oceanía','OC'); -/*!40000 ALTER TABLE `continent` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `department` --- - -LOCK TABLES `department` WRITE; -/*!40000 ALTER TABLE `department` DISABLE KEYS */; -INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,106,763,0,0,0,0,31,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL),(22,'shopping','COMPRAS',2,3,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(23,'CMA','CAMARA',13,14,NULL,72,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL,NULL),(31,'it','INFORMATICA',4,5,NULL,72,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL,NULL),(34,NULL,'CONTABILIDAD',6,7,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(35,NULL,'FINANZAS',8,9,NULL,0,0,0,1,0,1,'/1/',NULL,1,'begonya@verdnatura.es',1,0,0,0,NULL,NULL),(36,NULL,'LABORAL',10,11,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(37,'PROD','PRODUCCION',12,27,NULL,72,1,1,1,7,1,'/1/',NULL,0,NULL,0,1,1,1,NULL,NULL),(38,NULL,'SACADO',15,16,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(39,NULL,'ENCAJADO',17,18,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(41,NULL,'ADMINISTRACION',28,29,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(43,'VT','VENTAS',30,53,NULL,0,0,0,1,11,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL),(44,'management','GERENCIA',54,55,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(45,'logistic','LOGISTICA',56,57,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(46,'delivery','REPARTO',58,59,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL),(48,NULL,'ALMACENAJE',60,61,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(49,NULL,'PROPIEDAD',62,63,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(52,NULL,'CARGA AEREA',64,65,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',66,67,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(54,NULL,'ORNAMENTALES',68,69,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(55,NULL,'TALLER NATURAL',70,73,14548,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,1,1,0,1118,NULL),(56,NULL,'TALLER ARTIFICIAL',71,72,8470,72,0,0,2,0,55,'/1/55/',NULL,0,NULL,0,1,1,0,1927,NULL),(58,'CMP','CAMPOS',74,77,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(59,NULL,'MANTENIMIENTO',78,79,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL),(60,NULL,'RECLAMACIONES',80,81,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,1,0,0,NULL,NULL),(61,NULL,'VNH',82,85,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(66,NULL,'VERDNAMADRID',86,87,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(68,NULL,'COMPLEMENTOS',19,20,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,0,0,NULL,NULL),(69,NULL,'VERDNABARNA',88,89,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(80,NULL,'EQUIPO J VALLES',31,32,4250,72,0,0,2,0,43,'/1/43/','jvp_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(86,NULL,'LIMPIEZA',90,91,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(89,NULL,'COORDINACION',92,93,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(90,NULL,'TRAILER',83,84,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL),(91,NULL,'ARTIFICIAL',21,22,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(92,NULL,'EQUIPO SILVERIO',33,34,1203,0,0,0,2,0,43,'/1/43/','sdc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(93,NULL,'CONFECCION',94,95,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL,NULL),(94,NULL,'EQUIPO J BROCAL',35,36,3797,0,0,0,2,0,43,'/1/43/','jes_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(95,NULL,'EQUIPO C ZAMBRANO',37,38,4667,0,0,0,2,0,43,'/1/43/','czg_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(96,NULL,'EQUIPO C LOPEZ',39,40,4661,0,0,0,2,0,43,'/1/43/','cla_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(115,NULL,'EQUIPO CLAUDI',41,42,3810,0,0,0,2,0,43,'/1/43/','csr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',43,44,7102,0,0,0,2,0,43,'/1/43/','ebt_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(124,NULL,'CONTROL INTERNO',96,97,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL),(125,NULL,'EQUIPO MIRIAM MAR',45,46,1118,0,0,0,2,0,43,'/1/43/','mir_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(126,NULL,'PRESERVADO',98,99,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,NULL,NULL),(128,NULL,'PALETIZADO',23,24,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(130,NULL,'REVISION',25,26,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(131,NULL,'INVERNADERO',75,76,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL),(132,NULL,'EQUIPO DC',47,48,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(133,'franceTeam','EQUIPO FRANCIA',49,50,1731,72,0,0,2,0,43,'/1/43/','fra_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(134,NULL,'EQUIPO RODRI',51,52,6264,0,0,0,2,0,43,'/1/43/','rhr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(135,'routers','ENRUTADORES',100,101,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(136,'heavyVehicles','VEHICULOS PESADOS',102,103,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(137,'sorter','SORTER',104,105,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -/*!40000 ALTER TABLE `department` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `docuware` --- - -LOCK TABLES `docuware` WRITE; -/*!40000 ALTER TABLE `docuware` DISABLE KEYS */; -INSERT INTO `docuware` VALUES (1,'deliveryNote','Albaranes cliente','find','find','N__ALBAR_N',NULL),(2,'deliveryNote','Albaranes cliente','store','Archivar','N__ALBAR_N',NULL),(3,'hr','RRHH','find','Búsqueda','N__DOCUMENTO',3); -/*!40000 ALTER TABLE `docuware` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `itemPackingType` --- - -LOCK TABLES `itemPackingType` WRITE; -/*!40000 ALTER TABLE `itemPackingType` DISABLE KEYS */; -INSERT INTO `itemPackingType` VALUES ('F','Fruta y Verdura',0),('H','Horizontal',1),('P','Pienso',0),('V','Vertical',1); -/*!40000 ALTER TABLE `itemPackingType` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `pgc` --- - -LOCK TABLES `pgc` WRITE; -/*!40000 ALTER TABLE `pgc` DISABLE KEYS */; -INSERT INTO `pgc` VALUES ('4722000000',0.00,'Importación Exento ',1,0,0,1,0),('4722000010',10.00,'Importación Reducido ',1,0,0,1,0),('4722000021',21.00,'Importación General ',1,0,0,1,0),('4770000001',8.00,'Reducido',1,1,1,1,0),('4770000002',0.00,'Extra-Community supply',3,1,0,2,0),('4770000004',4.00,'Super reducido',1,1,1,1,0),('4770000010',10.00,'Reducido',1,1,1,1,0),('4770000020',0.00,'Exento',7,1,1,1,0),('4770000021',21.00,'General',1,1,1,1,0),('4770000101',10.00,'Reducido ',1,1,1,1,0),('4770000108',8.00,'Reducido',1,1,1,1,0),('4770000110',1.40,'Rec. Eq. Reducido',1,0,0,1,1),('4770000215',21.00,'General',1,1,1,1,0),('4770000405',0.50,'Rec. Eq. Super Reducido',1,0,0,1,1),('4770000504',4.00,'Super reducido',1,1,1,1,0),('4770000521',5.20,'Rec. Eq. General',1,0,0,1,1),('4770000701',1.00,'Rec. Eq. Reducido',1,0,0,1,1),('4771000000',0.00,'Intra-Community supply',6,1,1,1,0),('4771000001',0.00,'Intra-Community services',7,1,1,1,0),('HolandaGEN',21.00,'General',1,0,0,1,0),('HolandaRED',9.00,'Reducido',1,0,0,1,0),('IGIC cero',0.00,'Cero',1,0,0,1,0),('IGIC gener',6.50,'General',1,0,0,1,0),('IGIC reduc',3.00,'Reducido',1,0,0,1,0); -/*!40000 ALTER TABLE `pgc` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `sample` --- - -LOCK TABLES `sample` WRITE; -/*!40000 ALTER TABLE `sample` DISABLE KEYS */; -INSERT INTO `sample` VALUES (1,'Carta_1','Aviso inicial por saldo deudor',0,0,1,0,NULL),(2,'Carta_2','Reiteracion de aviso por saldo deudor',0,0,1,0,NULL),(3,'Cred_Up','Notificación de aumento de crédito',0,0,1,0,NULL),(4,'Cred_down','Notificación de reducción de crédito',0,0,1,0,NULL),(5,'Pet_CC','Petición de datos bancarios B2B',0,0,1,0,NULL),(6,'SolCredito','Solicitud de crédito',0,0,1,0,NULL),(7,'LeyPago','Ley de pagos',0,0,1,0,NULL),(8,'Pet_CC_Core','Petición de datos bancarios CORE',0,0,1,0,NULL),(9,'nueva_alta','Documento de nueva alta de cliente',0,0,1,0,NULL),(10,'client_welcome','Email de bienvenida para nuevo cliente',0,0,1,0,NULL),(11,'setup_printer','Email de instalación de impresora',0,0,1,0,NULL),(12,'client-welcome','Bienvenida como nuevo cliente',1,0,1,0,'Clients'),(13,'printer-setup','Instalación y configuración de impresora de coronas',1,0,1,0,'Clients'),(14,'sepa-core','Solicitud de domiciliación bancaria',1,1,0,0,'Clients'),(15,'letter-debtor-st','Aviso inicial por saldo deudor',1,1,1,0,'Clients'),(16,'letter-debtor-nd','Aviso reiterado por saldo deudor',1,1,1,0,'Clients'),(17,'client-lcr','Email de solicitud de datos bancarios LCR',0,1,1,0,NULL),(18,'client-debt-statement','Extracto del cliente',1,0,1,1,'Clients'),(19,'credit-request','Solicitud de crédito',1,1,1,0,'Clients'),(20,'incoterms-authorization','Autorización de incoterms',1,1,1,0,'Clients'); -/*!40000 ALTER TABLE `sample` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `state` --- - -LOCK TABLES `state` WRITE; -/*!40000 ALTER TABLE `state` DISABLE KEYS */; -INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1,'alert'),(2,'Libre',2,0,'FREE',NULL,2,0,0,0,0,0,0,4,1,'notice'),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0,'success'),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0,'success'),(5,'Preparación',6,1,'ON_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0,'warning'),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1,'alert'),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0,'warning'),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0,NULL),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0,NULL),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0,NULL),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1,'alert'),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0,NULL),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0,'warning'),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0,NULL),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0,NULL),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0,'success'),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0,'success'),(22,'Pte. Ampliar',2,0,'EXPANDABLE',NULL,22,0,0,0,0,0,0,4,1,'alert'),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1,'success'),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1,'success'),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0,'alert'),(26,'Prep Previa',5,0,'PREVIOUS_PREPARATION',1,28,1,0,0,1,0,0,2,0,'warning'),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0,'success'),(28,'Previa OK',3,0,'OK PREVIOUS',3,28,1,0,1,1,1,1,3,0,'warning'),(29,'Previa Impreso',4,0,'PRINTED PREVIOUS',2,29,1,0,1,0,0,1,2,0,'success'),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0,'success'),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,2,0,'success'),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0,'warning'),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0,'success'),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1,'alert'),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0,NULL),(36,'Previa Revisando',3,0,'PREVIOUS_CONTROL',2,37,1,0,0,4,0,1,2,0,'warning'),(37,'Previa Revisado',3,0,'PREVIOUS_CONTROLLED',2,29,1,0,1,0,0,1,2,0,'warning'),(38,'Prep Cámara',6,1,'COOLER_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'),(41,'Prep Parcial',6,1,'PARTIAL_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'); -/*!40000 ALTER TABLE `state` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `ticketUpdateAction` --- - -LOCK TABLES `ticketUpdateAction` WRITE; -/*!40000 ALTER TABLE `ticketUpdateAction` DISABLE KEYS */; -INSERT INTO `ticketUpdateAction` VALUES (1,'Cambiar los precios en el ticket','changePrice'),(3,'Convertir en maná','turnInMana'); -/*!40000 ALTER TABLE `ticketUpdateAction` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `volumeConfig` --- - -LOCK TABLES `volumeConfig` WRITE; -/*!40000 ALTER TABLE `volumeConfig` DISABLE KEYS */; -INSERT INTO `volumeConfig` VALUES (2.67,1.60,0.8,150,0.30,120,57,2.0,50,200,10,167.0); -/*!40000 ALTER TABLE `volumeConfig` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `workCenter` --- - -LOCK TABLES `workCenter` WRITE; -/*!40000 ALTER TABLE `workCenter` DISABLE KEYS */; -INSERT INTO `workCenter` VALUES (1,'Silla',20,859,1,'Av espioca 100',552703,NULL),(2,'Mercaflor',19,NULL,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL,NULL),(4,'VNH',NULL,NULL,NULL,NULL,NULL,NULL),(5,'Madrid',28,2869,5,'Av constitución 3',554145,0.50),(6,'Vilassar',88,88038,NULL,'Cami del Crist, 33',556412,NULL),(7,'Tenerife',NULL,NULL,NULL,NULL,NULL,NULL),(8,'Silla-Agrario',26,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,1354,60,'Fenollars, 2',523549,NULL),(10,'Rubi',88,NULL,84,'Av. de la Llana, 131',549722,0.50); -/*!40000 ALTER TABLE `workCenter` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `companyI18n` --- - -LOCK TABLES `companyI18n` WRITE; -/*!40000 ALTER TABLE `companyI18n` DISABLE KEYS */; -INSERT INTO `companyI18n` VALUES (442,'en','In compliance with the provisions of Organic Law 15/1999, on the Protection of Personal Data, we inform you that the personal data you provide will be included in automated files of VERDNATURA LEVANTE SL, being able at all times to exercise the rights of access, rectification, cancellation and opposition, communicating it in writing to the registered office of the entity. The purpose of the file is administrative management, accounting, and billing.'),(442,'fr','Conformément aux dispositions de la loi organique 15/1999 sur la protection des données personnelles, nous vous informons que les données personnelles que vous fournissez seront incluses dans des dossiers. VERDNATURA LEVANTE S.L., vous pouvez à tout moment, exercer les droits d``accès, de rectification, d``annulation et d``opposition, en communiquant par écrit au siège social de la société. Le dossier a pour objet la gestion administrative, la comptabilité et la facturation.'),(442,'pt','Em cumprimento do disposto na lei Orgânica 15/1999, de Protecção de Dados de Carácter Pessoal, comunicamos que os dados pessoais que facilite se incluirão nos ficheiros automatizados de VERDNATURA LEVANTE S.L., podendo em todo momento exercer os direitos de acesso, rectificação, cancelação e oposição, comunicando por escrito ao domicílio social da entidade. A finalidade do ficheiro é a gestão administrativa, contabilidade e facturação.'); -/*!40000 ALTER TABLE `companyI18n` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `workerTimeControlError` --- - -LOCK TABLES `workerTimeControlError` WRITE; -/*!40000 ALTER TABLE `workerTimeControlError` DISABLE KEYS */; -INSERT INTO `workerTimeControlError` VALUES (1,'IS_NOT_ALLOWED_FUTURE','No se permite fichar a futuro'),(2,'INACTIVE_BUSINESS','No hay un contrato en vigor'),(3,'IS_NOT_ALLOWED_WORK','No está permitido trabajar'),(4,'ODD_WORKERTIMECONTROL','Fichadas impares'),(5,'DAY_MAX_TIME','Superado el tiempo máximo entre entrada y salida'),(6,'BREAK_DAY','Descanso diario'),(7,'BREAK_WEEK','Descanso semanal'),(8,'WRONG_DIRECTION','Dirección incorrecta'),(9,'UNDEFINED_ERROR','Error sin definir'); -/*!40000 ALTER TABLE `workerTimeControlError` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `silexACL` --- - -LOCK TABLES `silexACL` WRITE; -/*!40000 ALTER TABLE `silexACL` DISABLE KEYS */; -INSERT INTO `silexACL` VALUES (1,'workerTimeControl','clockIn','$everyone'),(2,'workerTimeControl','getClockIn','$everyone'),(3,'workerTimeControl','login','$everyone'),(4,'security','device_checkLogin','employee'),(5,'security','getVersion','employee'),(6,'security','login','employee'),(7,'delivery','addNote','employee'),(8,'delivery','expeditionState_add','employee'),(9,'delivery','expeditionState_addByExpedition','employee'),(10,'delivery','expeditionState_addByExpeditionMulti','employee'),(11,'delivery','expeditionState_addByRoute','employee'),(12,'delivery','expedition_getLog','employee'),(13,'delivery','getExpeditionFromRoute','employee'),(14,'delivery','getInfo','employee'),(15,'delivery','getInfoCompany','employee'),(16,'delivery','getInfoFreelance','employee'),(17,'delivery','getWorkers','employee'),(18,'delivery','get_routes','employee'),(19,'delivery','get_tickets','employee'),(20,'delivery','get_version','employee'),(21,'delivery','saveLoadersWorkers','employee'),(22,'delivery','save_sign','employee'),(23,'delivery','setRouteOk','employee'),(24,'delivery','updateExpeditionChecked','employee'),(25,'delivery','update_routes','employee'),(26,'almacennew','barcodes_edit','employee'),(27,'almacennew','barcodeToItem','employee'),(28,'almacennew','buffer_setTypeByName','employee'),(29,'almacennew','buy_updateGrouping','employee'),(30,'almacennew','buy_updatePacking','employee'),(31,'almacennew','checkRouteExpeditionScanPut','employee'),(32,'almacennew','clearShelvingList','employee'),(33,'almacennew','collectionAddItem','employee'),(34,'almacennew','collectionGet','employee'),(35,'almacennew','collectionIncreaseQuantity','employee'),(36,'almacennew','collectionMissingTrash','employee'),(37,'almacennew','collectionNew','employee'),(38,'almacennew','collectionStickerPrint','employee'),(39,'almacennew','collection_getTickets','employee'),(40,'almacennew','collection_printSticker','employee'),(41,'almacennew','department_getHasMistake','employee'),(42,'almacennew','deviceLog_add','employee'),(43,'almacennew','deviceProductionUser_getWorker','employee'),(44,'almacennew','deviceProduction_getnameDevice','employee'),(45,'almacennew','expeditionLoading_add','employee'),(46,'almacennew','expeditionPalletDel','employee'),(47,'almacennew','expeditionPalletList','employee'),(48,'almacennew','expeditionPalletPrintSet','employee'),(49,'almacennew','expeditionPalletView','employee'),(50,'almacennew','expeditionScanAdd','employee'),(51,'almacennew','expeditionScanDel','employee'),(52,'almacennew','expeditionScanList','employee'),(53,'almacennew','expeditionScanPut','employee'),(54,'almacennew','expeditionState_addByPallet','employee'),(55,'almacennew','expeditionTruckAdd','employee'),(56,'almacennew','expeditionTruckList','employee'),(57,'almacennew','expedition_getState','employee'),(58,'almacennew','expedition_scan','employee'),(59,'almacennew','faultsReview','employee'),(60,'almacennew','faultsReview_isChecked','employee'),(61,'almacennew','getItemUbication','employee'),(62,'almacennew','get_ItemPackingType','employee'),(63,'almacennew','itemDiary','employee'),(64,'almacennew','itemPlacementSupplyAiming','employee'),(65,'almacennew','itemPlacementSupplyCloseOrder','employee'),(66,'almacennew','itemPlacementSupplyGetOrder','employee'),(68,'almacennew','itemShelvingBuyerGet','employee'),(69,'almacennew','itemShelvingBuyerTask','employee'),(70,'almacennew','itemShelvingDelete','employee'),(71,'almacennew','itemShelvingList','employee'),(72,'almacennew','itemShelvingLog_get','employee'),(73,'almacennew','itemShelvingMake','employee'),(74,'almacennew','itemShelvingMakeEdit','employee'),(75,'almacennew','itemShelvingMake_multi','employee'),(76,'almacennew','itemShelvingPlacementSupplyAdd','employee'),(77,'almacennew','itemShelvingSaleSupplyAdd','employee'),(78,'almacennew','itemShelvingStarsUpdate','employee'),(79,'almacennew','itemShelvingTransfer','employee'),(80,'almacennew','itemShelving_addByClaim','employee'),(81,'almacennew','itemShelving_filterBuyer','employee'),(82,'almacennew','itemShelving_getSaleDate','employee'),(83,'almacennew','itemTrash','employee'),(84,'almacennew','item_card','employee'),(85,'almacennew','item_getSimilar','employee'),(86,'almacennew','item_placement_save','employee'),(87,'almacennew','item_saveReference','employee'),(88,'almacennew','item_updatePackingShelve','employee'),(89,'almacennew','machineWorker_add','employee'),(90,'almacennew','machineWorker_getHistorical','employee'),(91,'almacennew','machineWorker_update','employee'),(92,'almacennew','machineWorker_Worker','employee'),(93,'almacennew','machine_checkPlate','employee'),(94,'almacennew','machine_getWorkerPlate','employee'),(95,'almacennew','mistakeType','employee'),(96,'almacennew','printer_get','employee'),(97,'almacennew','qr_getCall','developer'),(98,'almacennew','saleMistakeAdd','employee'),(99,'almacennew','saleMove','employee'),(100,'almacennew','saleParking_add','employee'),(101,'almacennew','saleTrackingDel','employee'),(102,'almacennew','saleTrackingReplace','employee'),(103,'almacennew','saleTracking_add','employee'),(104,'almacennew','saleTracking_addPrevOK','employee'),(105,'almacennew','saleTracking_updateIsChecked','employee'),(106,'almacennew','sectorCollectionSaleGroup_add','employee'),(107,'almacennew','sectorCollection_get','employee'),(108,'almacennew','sectorCollection_getSale','employee'),(109,'almacennew','sectorCollection_new','employee'),(110,'almacennew','sector_get','employee'),(111,'almacennew','shelvingChange','employee'),(112,'almacennew','shelvingLog_get','employee'),(113,'almacennew','shelvingPark','employee'),(114,'almacennew','shelvingParking_get','employee'),(115,'almacennew','shelvingPriorityUpdate','employee'),(116,'almacennew','sip_getExtension','employee'),(117,'almacennew','ticketCollection_setUsedShelves','employee'),(118,'almacennew','ticketOrCollection_checkFullyControlled','employee'),(119,'almacennew','ticketToPrePrepare','employee'),(120,'almacennew','ticket_checkFullyControlled','employee'),(121,'almacennew','ticket_setState','employee'),(122,'almacennew','update_ItemPackingType','employee'),(123,'almacennew','workerMachinery_isRegistered','employee'),(124,'almacennew','workerMistakeType_get','employee'),(125,'almacennew','workerMistake_Add','coolerBoss'),(126,'almacennew','workerShelving_add','employee'),(127,'almacennew','workerShelving_delete','employee'),(128,'almacennew','worker_getFromHasMistake','employee'),(129,'almacennew','worker_getId','employee'),(130,'almacennew','worker_getPrinter','employee'),(131,'almacennew','worker_getSector','employee'),(132,'almacennew','worker_updatePrinter','employee'),(133,'almacennew','worker_updateSector','employee'),(134,'almacennew','itemShelving_updateFromSale','employee'),(135,'almacennew','collection_getUncheckedTicket','employee'),(136,'almacennew','itemShelving_return','employee'),(137,'almacennew','itemShelving_merge','employee'),(139,'delivery','get_expeditionsSummary','employee'),(140,'almacennew','cmrExpeditionPallet_add','employee'),(141,'delivery','route_getExpeditionSummary','employee'),(142,'almacennew','item_saveStems','employee'),(143,'almacennew','debug_add','employee'),(144,'almacennew','operator_getNumberOfWagons','employee'),(145,'almacennew','operator_add','employee'),(146,'almacennew','expeditionPallet_get','employee'),(147,'almacennew','worker_isF11Allowed','employee'),(148,'almacennew','train_get','employee'),(149,'almacennew','saleTracking_mark','employee'),(150,'almacennew','operator_updateItemPackingType','employee'),(151,'almacennew','operator_updateTrain','employee'),(152,'almacennew','operator_getTrain','employee'),(153,'almacennew','operator_getItemPackingType','employee'),(154,'almacennew','collection_assign','employee'),(155,'almacennew','itemPacking_get','employee'),(156,'almacennew','shelvingLog_add','employee'),(157,'almacennew','collection_get','employee'),(158,'delivery','get_routesFromExpedition','employee'),(160,'almacennew','expeditionMistakeType_get','employee'),(161,'almacennew','expeditionMistake_add','employee'),(162,'almacennew','itemShelving_addList','employee'),(163,'almacennew','cmrPallet_add','employee'),(164,'almacennew','ticket_isOutClosureZone','employee'),(165,'almacennew','itemShelving_selfConsumption','employee'),(166,'almacennew','ticket_printLabelPrevious','employee'),(167,'almacennew','travel_updatePacking','employee'),(168,'app','status','$everyone'); -/*!40000 ALTER TABLE `silexACL` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 -USE `cache`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: cache --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `cache` --- - -LOCK TABLES `cache` WRITE; -/*!40000 ALTER TABLE `cache` DISABLE KEYS */; -INSERT INTO `cache` VALUES (1,'equalizator','00:19:00'),(2,'available','00:06:00'),(3,'stock','00:30:00'),(4,'last_buy','23:59:00'),(5,'weekly_sales','12:00:00'),(6,'bionic','00:06:00'),(7,'sales','00:04:00'),(8,'visible','00:04:00'),(9,'item_range','00:03:00'),(10,'barcodes','01:00:00'),(11,'prod_graphic','00:17:00'),(12,'ticketShipping','00:01:00'),(13,'availableNoRaids','00:06:00'),(14,'lastBuy','23:59:00'); -/*!40000 ALTER TABLE `cache` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 -USE `hedera`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: hedera --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `browser` --- - -LOCK TABLES `browser` WRITE; -/*!40000 ALTER TABLE `browser` DISABLE KEYS */; -INSERT INTO `browser` VALUES ('Chrome',49),('Edge',79),('Firefox',69),('Opera',36),('Safari',11); -/*!40000 ALTER TABLE `browser` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `imageCollection` --- - -LOCK TABLES `imageCollection` WRITE; -/*!40000 ALTER TABLE `imageCollection` DISABLE KEYS */; -INSERT INTO `imageCollection` VALUES (1,'catalog','Artículo',3840,2160,'Item','image','vn','item','image',1,75),(4,'link','Enlace',200,200,'Link','image','hedera','link','image',1,9),(5,'news','Noticias',800,1200,'New','image','hedera','news','image',1,9),(6,'user','Usuario',800,1200,'VnUser','image','account','user','image',1,74); -/*!40000 ALTER TABLE `imageCollection` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `imageCollectionSize` --- - -LOCK TABLES `imageCollectionSize` WRITE; -/*!40000 ALTER TABLE `imageCollectionSize` DISABLE KEYS */; -INSERT INTO `imageCollectionSize` VALUES (2,1,50,50,1),(3,1,200,200,1),(5,5,200,200,1),(6,1,70,70,1),(8,5,50,50,1),(9,1,1600,900,0),(13,6,160,160,1),(14,6,520,520,1),(15,6,1600,1600,1),(16,1,500,500,1); -/*!40000 ALTER TABLE `imageCollectionSize` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `language` --- - -LOCK TABLES `language` WRITE; -/*!40000 ALTER TABLE `language` DISABLE KEYS */; -INSERT INTO `language` VALUES ('ca','Català','Catalan',1),('en','English','English',1),('es','Español','Spanish',1),('fr','Français','French',1),('mn','Португалий','Mongolian',1),('pt','Português','Portuguese',1); -/*!40000 ALTER TABLE `language` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `link` --- - -LOCK TABLES `link` WRITE; -/*!40000 ALTER TABLE `link` DISABLE KEYS */; -INSERT INTO `link` VALUES (16,'Printing server','Manage the CUPS printing server','http://printnatura.verdnatura.es','printer'),(20,'Webmail','Verdnatura webmail','https://webmail.verdnatura.es/','mail'),(23,'Verdnatura Beta','Trial version of the web page','https://test-shop.verdnatura.es/','vn'),(25,'Shared folder','Shared folder','https://cdn.verdnatura.es/share','backup'),(29,'phpMyAdmin','Manage MySQL database','https://pma.verdnatura.es/','pma'),(30,'Nagios','Monitoring system','https://nagios.verdnatura.es/','nagios'),(33,'Gitea','Version control system','https://gitea.verdnatura.es/','git'),(34,'Wiknatura','Verdnatura wiki page','https://wiki.verdnatura.es/','wiki'),(35,'phpLDAPadmin','Manage the LDAP database','https://pla.verdnatura.es/','pla'),(36,'Applications','Access applications repository','https://cdn.verdnatura.es/vn-access','access'),(37,'Jenkins','CI and CD system','https://jenkins.verdnatura.es','jenkins'),(38,'osTicket','User service center','https://cau.verdnatura.es','osticket'),(39,'Redmine','Flexible project management','https://redmine.verdnatura.es','redmine'),(40,'Grafana','Analytics & monitoring solution','https://grafana.verdnatura.es','grafana'),(41,'Rocket.Chat','Communications platform','https://chat.verdnatura.es','rocketchat'),(42,'Salix','ERP software','https://salix.verdnatura.es','salix'),(43,'Docker','Container management','https://docker.verdnatura.es','docker'),(44,'Proxmox','Virtual environment','https://mox.verdnatura.es','proxmox'),(45,'Shinobi','Network video recorder','https://shinobi.verdnatura.es','shinobi'),(46,'DokuWiki','Internal documentation','https://doku.verdnatura.es','dokuwiki'); -/*!40000 ALTER TABLE `link` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `location` --- - -LOCK TABLES `location` WRITE; -/*!40000 ALTER TABLE `location` DISABLE KEYS */; -INSERT INTO `location` VALUES (2,'39.2095886','-0.4173501','Valencia','Calle Fenollar, 2','46680','Algemesi','Valencia','963 242 100','es'),(3,'40.4564969','-3.4875829','Madrid','Avenida de la Constitución, 3 - Nave E','28850','Torrejón de Ardoz','Madrid','963 242 100',NULL),(4,'41.4962045','2.3765504','Barcelona','Camí del crist, 33','08340','Vilassar de Mar','Barcelona','607 562 391','ca'),(5,'52.2612312','4.7818154','Holland','Aalsmeer Flower Auction','1430 BA','Legmeerdijk 313','Aalsmeer','Nederland','nl'),(6,'43.4375416','5.2261456','Marseille','ruben@verdnatura.es','13054','Marigname','Marseille','+33 781 533 900','fr'); -/*!40000 ALTER TABLE `location` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `menu` --- - -LOCK TABLES `menu` WRITE; -/*!40000 ALTER TABLE `menu` DISABLE KEYS */; -INSERT INTO `menu` VALUES (1,'Home','cms/home',6,NULL,1),(2,'Orders',NULL,11,NULL,1),(3,'Catalog','ecomerce/catalog',6,NULL,2),(7,'Administration',NULL,1,NULL,2),(8,'Users','admin/users',1,7,2),(9,'Connections','admin/connections',1,7,2),(11,'Agencies','agencies/packages',3,NULL,2),(12,'News','news/news',1,7,3),(15,'Photos','admin/photos',1,7,3),(17,'Configuration',NULL,11,NULL,3),(19,'Control panel','admin/links',1,7,1),(21,'Basket','ecomerce/basket',11,NULL,1),(22,'Last orders','ecomerce/orders',11,2,2),(23,'Invoices','ecomerce/invoices',11,2,2),(24,'Account','account/conf',11,17,1),(25,'Addresses','account/address-list',11,17,2),(26,'Shelves','reports/shelves',1,29,1),(28,'Visits','admin/visits',1,7,2),(29,'Reports',NULL,1,NULL,2),(30,'Items','admin/items',1,7,3),(31,'Pending orders','ecomerce/pending',11,2,1); -/*!40000 ALTER TABLE `menu` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `message` --- - -LOCK TABLES `message` WRITE; -/*!40000 ALTER TABLE `message` DISABLE KEYS */; -INSERT INTO `message` VALUES (1,'ORDER_DATE_HOLIDAY','Orders for holidays are not possible'),(2,'ORDER_EMPTY','The order is empty'),(3,'ORDER_UNAVAILABLE','Some items are no longer available, please check the quantities highlighted in red'),(4,'SURVEY_MAX_ONE_VOTE','Only one vote per survey is possible'),(5,'ORDER_MAX_EXCEEDED','You have exceeded the maximum number of unconfirmed orders, please delete or confirm started orders'),(6,'LOGIN_INCORRECT','Incorrect username or password. Case-sensitive.'),(7,'ORDER_DATE_PAST','The order date must be today or later'),(8,'ORDER_DATE_LAST','No more orders can be made for today, please postpone your order for tomorrow or later'),(9,'ORDER_DATE_SUNDAY','Orders for Sunday cannot be confirmed'),(10,'ORDER_DATE_SATURATED','We are overwhelmed with orders, please select another delivery or pick-up date'),(11,'USER_DISCONNECTED','You have been disconnected from the server, please log in again'),(12,'UNAUTH_ACTION','Action not allowed'),(13,'ORDER_INVALID_AGENCY','The shipping agency is not valid'),(14,'ORDER_EMPTY_ADDRESS','Please select a shipping address'),(15,'ORDER_AMOUNT_ROUNDED','This item is sold in bundles, the quantity has been rounded'),(17,'orderOutdated','The order configuration is incorrect, please reconfigure it to continue shopping'),(18,'orderNotOwnedByUser','The order belongs to another user'),(19,'orderConfirmed','The order has already been confirmed and cannot be modified'),(20,'clientNotVerified','Incomplete tax data, please contact your sales representative'),(21,'quantityLessThanMin','The quantity cannot be less than the minimum'); -/*!40000 ALTER TABLE `message` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `metatag` --- - -LOCK TABLES `metatag` WRITE; -/*!40000 ALTER TABLE `metatag` DISABLE KEYS */; -INSERT INTO `metatag` VALUES (2,'title','Verdnatura Levante SL, mayorista de flores, plantas y complementos para floristería y decoración'),(3,'description','Verdnatura Levante SL, mayorista de flores, plantas y complementos para floristería y decoración. Envío a toda España, pedidos por internet o por teléfono.'),(4,'keywords','verdnatura, mayorista, floristería, flores, verdes, plantas, ramos, complementos, artificial, natural, decoración, rosas, helecho, fern, clavel, lilium, orquídea, tulipan, crisantemo, cala, gerbera, hiedra, eucaliptus, cinerea, aralia'),(6,'revisit-after','15 days'),(7,'rating','general'),(8,'author','Juan Ferrer Toribio'),(9,'owner','Verdnatura Levante S.L.'),(10,'robots','index, follow'); -/*!40000 ALTER TABLE `metatag` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `newsTag` --- - -LOCK TABLES `newsTag` WRITE; -/*!40000 ALTER TABLE `newsTag` DISABLE KEYS */; -INSERT INTO `newsTag` VALUES ('course','Curso'),('new','Noticia'),('offer','Oferta'); -/*!40000 ALTER TABLE `newsTag` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `restPriv` --- - -LOCK TABLES `restPriv` WRITE; -/*!40000 ALTER TABLE `restPriv` DISABLE KEYS */; -INSERT INTO `restPriv` VALUES (1,'tpv/transaction',2),(3,'image/upload',1),(5,'user/supplant',104),(10,'misc/captcha',NULL),(11,'core/log',NULL),(14,'core/query',NULL),(15,'user/recover-password',NULL),(16,'user/restore-password',NULL),(17,'dms/invoice',2),(18,'image/thumb',NULL),(19,'misc/contact',NULL),(20,'misc/production',NULL),(21,'tpv/confirm-post',NULL),(22,'tpv/confirm-soap',NULL),(23,'client/supplant',18),(24,'client/supplant',35),(25,'user/logout',NULL); -/*!40000 ALTER TABLE `restPriv` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `social` --- - -LOCK TABLES `social` WRITE; -/*!40000 ALTER TABLE `social` DISABLE KEYS */; -INSERT INTO `social` VALUES (1,'Blog','https://blog.verdnatura.es/','blog.svg',0),(3,'Facebook','http://www.facebook.com/verdnatura','facebook.svg',2),(4,'YouTube','http://www.youtube.com/user/verdnatura','youtube.svg',2),(5,'Twitter','https://twitter.com/Verdnatura','twitter.svg',1),(6,'Instagram','https://www.instagram.com/verdnatura','instagram.svg',2),(7,'Linkedin','https://www.linkedin.com/company/verdnatura','linkedin.svg',1),(8,'Pinterest','https://es.pinterest.com/verdnatura/','pinterest.svg',1); -/*!40000 ALTER TABLE `social` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `tpvError` --- - -LOCK TABLES `tpvError` WRITE; -/*!40000 ALTER TABLE `tpvError` DISABLE KEYS */; -INSERT INTO `tpvError` VALUES ('SIS0007','Error al desmontar el XML de entrada'),('SIS0008','Error falta Ds_Merchant_MerchantCode'),('SIS0009','Error de formato en Ds_Merchant_MerchantCode'),('SIS0010','Error falta Ds_Merchant_Terminal'),('SIS0011','Error de formato en Ds_Merchant_Terminal'),('SIS0014','Error de formato en Ds_Merchant_Order'),('SIS0015','Error falta Ds_Merchant_Currency'),('SIS0016','Error de formato en Ds_Merchant_Currency'),('SIS0017','Error no se admite operaciones en pesetas'),('SIS0018','Error falta Ds_Merchant_Amount'),('SIS0019','Error de formato en Ds_Merchant_Amount'),('SIS0020','Error falta Ds_Merchant_MerchantSignature'),('SIS0021','Error la Ds_Merchant_MerchantSignature viene vacía'),('SIS0022','Error de formato en Ds_Merchant_TransactionType'),('SIS0023','Error Ds_Merchant_TransactionType desconocido'),('SIS0024','Error Ds_Merchant_ConsumerLanguage tiene más de 3 posiciones'),('SIS0026','Error No existe el comercio / terminal enviado'),('SIS0027','Error Moneda enviada por el comercio es diferente a la que tiene asignada para ese terminal'),('SIS0028','Error Comercio / terminal está dado de baja'),('SIS0030','Error en un pago con tarjeta ha llegado un tipo de operación no valido'),('SIS0031','Método de pago no definido'),('SIS0034','Error de acceso a la Base de Datos'),('SIS0038','Error en java'),('SIS0040','Error el comercio / terminal no tiene ningún método de pago asignado'),('SIS0041','Error en el cálculo de la firma de datos del comercio'),('SIS0042','La firma enviada no es correcta'),('SIS0046','El BIN de la tarjeta no está dado de alta'),('SIS0051','Error número de pedido repetido'),('SIS0054','Error no existe operación sobre la que realizar la devolución'),('SIS0055','Error no existe más de un pago con el mismo número de pedido'),('SIS0056','La operación sobre la que se desea devolver no está autorizada'),('SIS0057','El importe a devolver supera el permitido'),('SIS0058','Inconsistencia de datos, en la validación de una confirmación'),('SIS0059','Error no existe operación sobre la que realizar la devolución'),('SIS0060','Ya existe una confirmación asociada a la preautorización'),('SIS0061','La preautorización sobre la que se desea confirmar no está autorizada'),('SIS0062','El importe a confirmar supera el permitido'),('SIS0063','Error. Número de tarjeta no disponible'),('SIS0064','Error. El número de tarjeta no puede tener más de 19 posiciones'),('SIS0065','Error. El número de tarjeta no es numérico'),('SIS0066','Error. Mes de caducidad no disponible'),('SIS0067','Error. El mes de la caducidad no es numérico'),('SIS0068','Error. El mes de la caducidad no es válido'),('SIS0069','Error. Año de caducidad no disponible'),('SIS0070','Error. El Año de la caducidad no es numérico'),('SIS0071','Tarjeta caducada'),('SIS0072','Operación no anulable'),('SIS0074','Error falta Ds_Merchant_Order'),('SIS0075','Error el Ds_Merchant_Order tiene menos de 4 posiciones o más de 12'),('SIS0076','Error el Ds_Merchant_Order no tiene las cuatro primeras posiciones numéricas'),('SIS0078','Método de pago no disponible'),('SIS0079','Error al realizar el pago con tarjeta'),('SIS0081','La sesión es nueva, se han perdido los datos almacenados'),('SIS0089','El valor de Ds_Merchant_ExpiryDate no ocupa 4 posiciones'),('SIS0092','El valor de Ds_Merchant_ExpiryDate es nulo'),('SIS0093','Tarjeta no encontrada en la tabla de rangos'),('SIS0112','Error. El tipo de transacción especificado en Ds_Merchant_Transaction_Type no esta permitido'),('SIS0115','Error no existe operación sobre la que realizar el pago de la cuota'),('SIS0116','La operación sobre la que se desea pagar una cuota no es una operación válida'),('SIS0117','La operación sobre la que se desea pagar una cuota no está autorizada'),('SIS0118','Se ha excedido el importe total de las cuotas'),('SIS0119','Valor del campo Ds_Merchant_DateFrecuency no válido'),('SIS0120','Valor del campo Ds_Merchant_CargeExpiryDate no válido'),('SIS0121','Valor del campo Ds_Merchant_SumTotal no válido'),('SIS0122','Valor del campo Ds_merchant_DateFrecuency o Ds_Merchant_SumTotal tiene formato incorrecto'),('SIS0123','Se ha excedido la fecha tope para realizar transacciones'),('SIS0124','No ha transcurrido la frecuencia mínima en un pago recurrente sucesivo'),('SIS0132','La fecha de Confirmación de Autorización no puede superar en más de 7 días a la de Preautorización'),('SIS0139','Error el pago recurrente inicial está duplicado SIS0142 Tiempo excedido para el pago'),('SIS0216','Error Ds_Merchant_CVV2 tiene mas de 3/4 posiciones'),('SIS0217','Error de formato en Ds_Merchant_CVV2'),('SIS0221','Error el CVV2 es obligatorio'),('SIS0222','Ya existe una anulación asociada a la preautorización'),('SIS0223','La preautorización que se desea anular no está autorizada'),('SIS0225','Error no existe operación sobre la que realizar la anulación'),('SIS0226','Inconsistencia de datos, en la validación de una anulación'),('SIS0227','Valor del campo Ds_Merchan_TransactionDate no válido'),('SIS0252','El comercio no permite el envío de tarjeta'),('SIS0253','La tarjeta no cumple el check-digit'),('SIS0261','Operación detenida por superar el control de restricciones en la entrada al SIS'),('SIS0274','Tipo de operación desconocida o no permitida por esta entrada al SIS'),('SIS9915','A petición del usuario se ha cancelado el pago'); -/*!40000 ALTER TABLE `tpvError` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `tpvResponse` --- - -LOCK TABLES `tpvResponse` WRITE; -/*!40000 ALTER TABLE `tpvResponse` DISABLE KEYS */; -INSERT INTO `tpvResponse` VALUES (101,'Tarjeta Caducada'),(102,'Tarjeta en excepción transitoria o bajo sospecha de fraude'),(104,'Operación no permitida para esa tarjeta o terminal'),(106,'Intentos de PIN excedidos'),(116,'Disponible Insuficiente'),(118,'Tarjeta no Registrada'),(125,'Tarjeta no efectiva'),(129,'Código de seguridad (CVV2/CVC2) incorrecto'),(180,'Tarjeta ajena al servicio'),(184,'Error en la autenticación del titular'),(190,'Denegación sin especificar motivo'),(191,'Fecha de caducidad errónea'),(202,'Tarjeta en excepción transitoria o bajo sospecha de fraude con retirada de tarjeta'),(904,'Comercio no registrado en FUC'),(909,'Error de sistema'),(912,'Emisor no Disponible'),(913,'Pedido repetido'),(944,'Sesión Incorrecta'),(950,'Operación de devolución no permitida'),(9064,'Número de posiciones de la tarjeta incorrecto'),(9078,'No existe método de pago válido para esa tarjeta'),(9093,'Tarjeta no existente'),(9094,'Rechazo servidores internacionales'),(9104,'A petición del usuario se ha cancelado el pago'),(9218,'El comercio no permite op. seguras por entrada /operaciones'),(9253,'Tarjeta no cumple el check-digit'),(9256,'El comercio no puede realizar preautorizaciones'),(9257,'Esta tarjeta no permite operativa de preautorizaciones'),(9261,'Operación detenida por superar el control de restricciones en la entrada al SIS'),(9912,'Emisor no Disponible'),(9913,'Error en la confirmación que el comercio envía al TPV Virtual (solo aplicable en la opción de sincronización SOAP)'),(9914,'Confirmación “KO” del comercio (solo aplicable en la opción de sincronización SOAP)'),(9915,'A petición del usuario se ha cancelado el pago'),(9928,'Anulación de autorización en diferido realizada por el SIS (proceso batch)'),(9929,'Anulación de autorización en diferido realizada por el comercio'),(9998,'Operación en proceso de solicitud de datos de tarjeta'),(9999,'Operación que ha sido redirigida al emisora autenticar'); -/*!40000 ALTER TABLE `tpvResponse` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 -USE `sage`; --- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: db2.static.verdnatura.es Database: sage --- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Dumping data for table `TiposIva` --- - -LOCK TABLES `TiposIva` WRITE; -/*!40000 ALTER TABLE `TiposIva` DISABLE KEYS */; -INSERT INTO `TiposIva` VALUES (2,0,'Operaciones no sujetas',0.0000000000,0.0000000000,0.0000000000,'','4770000020','','','','','','','95B21A93-5910-489D-83BB-C32788C9B19D','','','','','','','','','',0),(4,0,'I.V.A. 4%',0.0000000000,4.0000000000,0.0000000000,'4720000004','4770000004','','6310000000','','','','','9E6160D5-984E-4643-ACBC-1EBC3BF73360','','','','','','','','','',0),(5,0,'I.V.A. 4% y R.E. 0.5%',0.0000000000,4.0000000000,0.5000000000,'','4770000504','4770000405','','','','','','DBEFA562-63FB-4FFC-8171-64F0C6F065FF','','','','','','','','','',0),(6,0,'H.P. IVA 4% CEE',0.0000000000,4.0000000000,0.0000000000,'4721000004','4771000004','','','','','','','DD0ECBA8-2EF5-425E-911B-623580BADA77','','','','','','','','','',0),(7,0,'H.P. IVA 10% CEE',0.0000000000,10.0000000000,0.0000000000,'4721000011','4771000010','','','','','','','593208CD-6F28-4489-B6EC-907AD689EAC9','','','','','','','','','',0),(8,0,'H.P. IVA 21% CEE',0.0000000000,21.0000000000,0.0000000000,'4721000021','4771000021','','','','','','','27061852-9BC1-4C4F-9B6E-69970E208F23','','','','','','','','','',0),(10,0,'I.V.A. 10% Nacional',0.0000000000,10.0000000000,0.0000000000,'4720000011','4770000010','','6290000553','','','','','828A9D6F-5C01-4C3A-918A-B2E4482830D3','','','','','','','','','',0),(11,0,'I.V.A. 10% y R.E. 1,4%',0.0000000000,10.0000000000,1.4000000000,'','4770000101','4770000110','','','','','','C1F2D910-83A1-4191-A76C-8B3D7AB98348','','','','','','','','','',0),(16,0,'I.V.A. Adqui. servicios CEE',0.0000000000,21.0000000000,0.0000000000,'4721000015','4771000016','','','','','','','E3EDE961-CE8F-41D4-9E6C-D8BCD32275A1','','','','','','','','','',0),(18,0,'H.P. Iva Importación 0% ISP',0.0000000000,0.0000000000,0.0000000000,'4720000005','4770000005','','','','','','','27AD4158-2349-49C2-B53A-A4E0EFAC5D09','','','','','','','','','',0),(20,0,'I.V.A 0% Nacional',0.0000000000,0.0000000000,0.0000000000,'4720000000','','','','','','','','B90B0FBD-E513-4F04-9721-C873504E08DF','','','','','','','','','',0),(21,0,'I.V.A. 21%',0.0000000000,21.0000000000,0.0000000000,'4720000021','4770000021','4770000000','','','','','','BA8C4E28-DCFA-4F7B-AE4F-CA044626B55E','','','','','','','','','',0),(22,0,'IVA 10% importaciones',0.0000000000,10.0000000000,0.0000000000,'4722000010','','','','','','','','540450A8-4B41-4607-96D1-E7F296FB6933','','','','','','','','','',0),(26,0,'I.V.A. 21% y R.E. 5,2%',0.0000000000,21.0000000000,5.2000000000,'4720000021','4770000215','4770000521','631000000','','','','','2BC0765F-7739-49AE-A5F0-28B648B81677','','','','','','','','','',0),(90,0,'IVA 21% importaciones',0.0000000000,21.0000000000,0.0000000000,'4722000021','','','','','','','','EB675F91-5FF2-4E26-A31E-EEB674125945','','','','','','','','','',0),(91,0,'IVA 0% importaciones',0.0000000000,0.0000000000,0.0000000000,'4723000000','','','','','','','','5E5EFA56-2A99-4D54-A16B-5D818274CA18','','','','','','','','','',0),(92,0,'8.5% comp. ganadera o pesquera',0.0000000000,8.5000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0),(93,0,'12% com. agrícola o forestal',0.0000000000,12.0000000000,0.0000000000,'4720000012','','','','','','','','267B1DDB-247F-4A71-AB95-3349FEFC5F92','','','','','','','','','',0),(94,0,'10,5% com. ganadera o pesquera',0.0000000000,10.5000000000,0.0000000000,'4770000000','4720000000','631000000','477000000','','','','','','','','','','','','','','',0),(100,0,'HP IVA SOPORTADO 5%',0.0000000000,5.0000000000,0.0000000000,'4720000055','','','','','','','','3AD36CB2-4172-4CC9-9F87-2BF2B56AAC80','','','','','','','','','',0),(108,0,'I.V.A. 8%',0.0000000000,8.0000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0),(109,0,'I.V.A. 8% y R.E. 1%',0.0000000000,8.0000000000,1.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0),(110,0,'HP IVA Devengado Exento CEE',0.0000000000,0.0000000000,0.0000000000,'','4771000000','','','','','','','C605BC32-E161-42FD-83F3-3A66B1FBE399','','','','','','','','','',0),(111,0,'H.P. Iva Devengado Exento Ser',0.0000000000,0.0000000000,0.0000000000,'','4771000001','','','','','','','F1AEC4DC-AFE5-498E-A713-2648FFB6DA32','','','','','','','','','',0),(112,0,'H.P. IVA Devengado en exportac',0.0000000000,0.0000000000,0.0000000000,'','4770000002','','','','','','','F980AE74-BF75-4F4C-927F-0CCCE0DB8D15','','','','','','','','','',0),(113,0,'HP DEVENGADO 21 ISP ',0.0000000000,21.0000000000,0.0000000000,'4720000006','4770000006','','','','','','','728D7A76-E936-438C-AF05-3CA38FE16EA5','','','','','','','','','',0),(114,0,'HP.IVA NO DEDUCIBLE 10%',0.0000000000,0.0000000000,0.0000000000,'4720000026','','','','','','','','','','','','','','','','','',0),(115,0,'H.P. IVA Soportado Impor 4% ',0.0000000000,4.0000000000,0.0000000000,'4722000004','','','','','','','','','','','','','','','','','',0); -/*!40000 ALTER TABLE `TiposIva` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `TiposTransacciones` --- - -LOCK TABLES `TiposTransacciones` WRITE; -/*!40000 ALTER TABLE `TiposTransacciones` DISABLE KEYS */; -INSERT INTO `TiposTransacciones` VALUES (1,'Rég.general/Oper.interiores bienes y serv.corrien.','',0,''),(2,'Régimen especial de bienes usados','E',0,''),(3,'Régimen especial de obj. de arte y antigüedades','E',0,''),(4,'Régimen especial agencias de viaje','',0,''),(5,'Régimen especial determinación proporcional','E',0,''),(6,'Oper.en rég.simplificado art.37.1.2º Rgto.IVA','E',0,''),(7,'Oper.en rég.simplificado art.37.1.1º Rgto.IVA','E',0,''),(8,'Oper.en rég.de agricultura, ganadería y pesca','E',0,''),(9,'Oper.en rég.especial de recargo de equivalencia','E',0,''),(10,'Entregas intracomunitarias','E',0,''),(11,'Entregas intermediarias intracomunitarias','E',0,''),(12,'Operaciones sujetas con derecho a devolución','E',0,''),(13,'Prest. Serv. No sujetas derecho devolución','E',0,''),(14,'Exportaciones definitivas','E',0,''),(15,'Envíos definitivos a Canarias, Ceuta y Melilla','E',0,''),(16,'Devoluciones en régimen de viajeros','E',0,''),(17,'Operaciones con áreas exentas','E',0,''),(18,'Operaciones exentas con derecho a deducción','E',0,''),(19,'Operaciones exentas sin derecho a deducción','E',0,''),(20,'Adquisic.intracomunitarias de bienes y serv.corr.','',-1,'P'),(21,'Adquisic.intracomunitarias de bienes de inversión','',-1,'P'),(22,'Adquisic.intermediarias intracomunitarias','',-1,'P'),(23,'Modif.autorizadas en quiebras y susp.de pagos','',0,''),(24,'Entrega de bienes inmuebles no habituales','E',0,''),(25,'Entrega de bienes de inversión','E',0,''),(26,'Op.finan. y Entregas oro inversión, no habituales','E',0,''),(27,'Inversión sujeto pasivo','',-1,'I'),(28,'Prestaciones intracomunitarias de servicios','E',0,''),(29,'Adquisiciones intracomunitarias de servicios','',-1,'I'),(30,'Operaciones interiores de bienes de inversión','R',0,''),(31,'Importaciones de bienes y servicios corrientes','R',0,''),(32,'Importaciones de bienes de inversión','R',0,''),(33,'Operaciones que generan inversión sujeto pasivo','E',0,''),(35,'Compensaciones en rég.de agricultura, gan.y pesca','R',0,''),(36,'Regularización de inversiones','R',0,''),(37,'Operaciones exentas','R',0,''),(38,'Operaciones no sujetas','',0,''),(39,'Gastos devengados op interiores (País Vasco)','R',0,''),(40,'Gastos Adq.intracom. bienes (País Vasco)','',-1,'P'),(42,'Gastos Adq.intermediarias intracom. (País Vasco)','',-1,'P'),(47,'Gastos Inversión sujeto pasivo (País Vasco)','',-1,'I'),(49,'Gastos Adq. intracom. servicios (País Vasco)','',-1,'I'),(51,'Gastos Importaciones (País Vasco)','R',0,''),(53,'Adquisiciones a agencias de viajes en rég.especial','R',0,''),(54,'Entregas intrac.posteriores a importaciones','E',0,''),(55,'Entregas intrac.post.impor.con representante','E',0,''),(56,'Import. bienes y serv. corrientes pdte. liquidar','R',0,''),(57,'Import. bienes de inversión pdte. liquidar','R',0,''),(58,'Servicios prestados por Internet desde España','E',0,''),(59,'Servicios prestados por Internet fuera de España','E',0,''),(60,'Régimen depósito distinto al aduanero','',0,''),(61,'Adquisición de bienes de inversión con ISP','',-1,'I'),(62,'Prest. Serv. Interiores clientes comunit./extranj.','',0,''),(63,'Prest. Serv. Ex. con derecho a deducc. comu./extr.','E',0,''),(64,'Prest. Serv. Ex. sin derecho a deducc. comu./extr.','E',0,''),(65,'Entregas No sujetas derecho devolución','E',0,''),(66,'Operaciones exentas art. 25 ley 19/1994 (Canarias)','',0,''),(67,'Entrega de bienes exenta \"Zona Especial Canaria\"','',0,''),(68,'Prestac. servicios exenta \"Zona Especial Canaria\"','',0,''); -/*!40000 ALTER TABLE `TiposTransacciones` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `TiposRetencion` --- - -LOCK TABLES `TiposRetencion` WRITE; -/*!40000 ALTER TABLE `TiposRetencion` DISABLE KEYS */; -INSERT INTO `TiposRetencion` VALUES (1,'RETENCION ESTIMACION OBJETIVA',1.0000000000,'4730000000','4751000000',NULL,NULL,NULL,'03811652-0F3A-44A1-AE1C-B19624525D7F'),(2,'ACTIVIDADES AGRICOLAS O GANADERAS',2.0000000000,'4730000000','4751000000',NULL,NULL,NULL,'F3F91EF3-FED6-444D-B03C-75B639D13FB4'),(9,'ACTIVIDADES PROFESIONALES 2 PRIMEROS AÑOS',9.0000000000,'4730000000','4751000000',NULL,NULL,NULL,'73F95642-E951-4C91-970A-60C503A4792B'),(15,'ACTIVIDADES PROFESIONALES',15.0000000000,'4730000000','4751000000','6',NULL,NULL,'F6BDE0EE-3B01-4023-8FFF-A73AE9AC50D7'),(19,'ARRENDAMIENTO Y SUBARRENDAMIENTO',19.0000000000,'4730000000','4751000000','8',NULL,NULL,'09B033AE-16E5-4057-8D4A-A7710C8A4FB9'); -/*!40000 ALTER TABLE `TiposRetencion` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping data for table `taxType` --- - -LOCK TABLES `taxType` WRITE; -/*!40000 ALTER TABLE `taxType` DISABLE KEYS */; -INSERT INTO `taxType` VALUES (2,'nonTaxable',0),(4,'national4',0),(5,NULL,0),(6,NULL,1),(7,NULL,1),(8,NULL,1),(10,'national10',0),(11,NULL,0),(16,'CEEServices21',1),(18,NULL,0),(20,'national0',0),(21,'national21',0),(22,'import10',0),(26,NULL,0),(90,'import21',0),(91,NULL,0),(92,NULL,0),(93,NULL,0),(94,NULL,0),(100,NULL,0),(108,NULL,0),(109,NULL,0),(110,NULL,1),(111,NULL,0),(112,NULL,0),(113,'ISP21',0),(114,NULL,0),(115,'import4',0); -/*!40000 ALTER TABLE `taxType` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2023-11-20 12:26:42 diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql new file mode 100644 index 000000000..0f0edef86 --- /dev/null +++ b/db/dump/fixtures.after.sql @@ -0,0 +1,341 @@ +-- Extract modified tables from fixtures: +-- awk 'match($0, /INSERT INTO `(\w+)`\.`(\w+)`/, ary) {print ary[1]" - "ary[2]}' dump/fixtures.sql | sort -u + +CALL `cache`.`last_buy_refresh`(FALSE); + +SET foreign_key_checks = 0; + +-- XXX: vn-database + +INSERT INTO util.config (environment, mockTime, mockUtcTime, mockEnabled) + VALUES ('local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE); + +INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk) + VALUES(1, NULL, 1, 300, 1); + +-- XXX: eti + +INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,agencyFk,`ref`,m3,kg,cargoSupplierFk) + VALUES (9,'2022-05-20','2022-05-20',13,4,1,'nine travel',69.0,600,1); + +INSERT INTO vn.entry (id, supplierFk, dated, invoiceNumber, evaNotes, travelFk, companyFk) + VALUES + (9, 1, '0000-00-00 00:00:00', 'Movement 9', 'observation nine', 8, 442), + (10, 1, '0000-00-00 00:00:00', 'Movement 10', 'observation ten', 9, 442); + +INSERT INTO vn.buy (id,entryFk,itemFk,quantity,dispatched,buyingValue,freightValue,isIgnored,stickers,packing,`grouping`,groupingMode,comissionValue,packageValue,packagingFk,price1,price2,price3,minPrice,printedStickers,workerFk,isChecked,isPickedOff,created,`__cm2`,weight) + VALUES + (16,8,1,100,0,50.0,1.5,0,1,1,1,0,0.0,1.5,'4',0.0,99.6,99.4,0.0,0,0,1,0,'2022-06-20 00:00:00',0,1.0), + (17,9,2,450,0,5.0,1.0,0,1,10,10,0,0.0,1.0,'3',0.0,7.3,7.0,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), + (18,9,15,500,0,55.0,1.0,0,1,1,1,0,0.0,1.0,'5',0.0,78.3,75.6,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), + (19,10,11,5000,0,50.0,1.0,0,1,1,1,1,0.0,1.0,'4',0.0,99.6,99.4,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5); + +INSERT INTO vn2008.Splits (Id_Split,Id_Ticket,Id_Entrada,Fecha,Notas) + VALUES + (1,7,2,'00-00-0000 00:00:00.000','nota1'), + (2,10,6,'00-00-0000 00:00:00.000','nota2'), + (3,15,7,'00-00-0000 00:00:00.000','nota3'), + (4,22,10,'00-00-0000 00:00:00.000','nota4'); + +-- XXX: ent + +-- XXX: enc + +INSERT INTO vn.mdbVersion (app, branchFk, version) + VALUES('enc', 'master', 1); + +UPDATE vn.warehouse + SET isForTicket = 1, addressFk = 118 + WHERE id = 1; + +UPDATE vn.packaging + SET freightItemFk = 1, isBox = 1 + WHERE id = '94'; + +INSERT INTO `vn`.`packagingConfig`(`upperGap`, `defaultSmallPackageFk`, `defaultBigPackageFk`) + VALUES + ('10', 1, 2); + +UPDATE vn.packaging SET freightItemFk=1 WHERE id='1'; +UPDATE vn.packaging SET freightItemFk=1 WHERE id='2'; + +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('1', 1); + + +INSERT INTO vn.cmrConfig (dayOfMonth, landingDays) + VALUES(5, 1); + +UPDATE vn.supplier + SET isTrucker = 1 + WHERE id = 2; + +INSERT INTO vn.cmr (id, truckPlate, observations, senderInstruccions, paymentInstruccions, specialAgreements, created, companyFk, addressToFk, addressFromFk, supplierFk, packagesList, merchandiseDetail, state, landed, ead) + VALUES (2, NULL, NULL, NULL, 'Carriage paid', NULL, '2022-06-27 13:31:11.000', 442, 3, 2, 2, NULL, NULL, NULL, NULL, NULL); + +-- XXX: tpv + +UPDATE `vn`.`claimRatio` SET `claimAmount` = '10' WHERE (`clientFk` = '1101'); + +UPDATE `util`.`config` SET `environment` = 'local' WHERE (`id` = '1'); + +INSERT INTO `vn`.`agency` (`name`, `warehouseFk`, `warehouseAliasFk`, `isOwn`, `isAnyVolumeAllowed`) VALUES + ('Agencia', '1', '1', '1', '1'), + ('Otra agencia ', '1', '2', '0', '0'); + +INSERT INTO `vn`.`expedition` (`agencyModeFk`, `ticketFk`, `isBox`, `counter`, `workerFk`, `externalId`, `packagingFk`, `hostFk`, `itemPackingTypeFk`, `hasNewRoute`) VALUES + ('1', '1', 1, '1', '1', '1', '1', 'pc00', 'F', 0), + ('1', '1', 1, '2', '1', '1', '1', 'pc00', 'F', 0); + +INSERT INTO vn.client (id,name,defaultAddressFk,street,fi,email,dueDay,isTaxDataChecked,accountingAccount,city,provinceFk,postcode,socialName,contact,credit,countryFk,quality,riskCalculated) VALUES + (100,'root',110,'Valle de la muerte','74974747G','root@mydomain.com',0,1,'4300000078','ALGEMESI',1,'46680','rootSocial','rootContact',500.0,1,10,'2025-01-01'); + +INSERT INTO vn.address (clientFk,street,city,provinceFk,postalCode,nickname,isEqualizated,isLogifloraAllowed,isDefaultAddress) VALUES + (100,'rootStreet','ALGEMESI',3,'46680','root',0,0,1); + +INSERT INTO vn.ticket (clientFk,warehouseFk,shipped,nickname,refFk,addressFk,routeFk,companyFk,agencyModeFk,landed,zoneFk, totalWithVat, totalWithoutVat) VALUES + (100,1,'2025-07-06 00:00:00','Saco de patatas',NULL,103,6,442,1,'2025-07-06',13, 500, 450), + (100,1,'2021-07-06 00:00:00','Alubias de la abuelita Enrriqueta','T4444444',103,6,442,1,'2021-07-06',13, 1000, 900); + +INSERT INTO vn.receipt (invoiceFk,amountPaid,payed,workerFk,bankFk,clientFk,isConciliate,companyFk) VALUES + ('Cobro mental',999.0,'2021-06-21 00:00:00',9,3,100,1,442), + ('Cobro web',50.0,'2022-06-21 00:00:00',9,3,100,1,567); + +INSERT INTO vn.workerBosses (workerFk,bossFk) VALUES + (44,100), + (70,100), + (47,100), + (58,100), + (1106,100); + +UPDATE vn.agencyMode + SET deliveryMethodFk=1 + WHERE id=1; + +UPDATE vn.agencyMode + SET deliveryMethodFk=2 + WHERE id=2; + +INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) VALUES + (100, 3, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 3, NULL, 1, 567, 1, '2022-07-12', 0, 0, 5, NULL, NULL, NULL, NULL, NULL), + (100, 4, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 4, NULL, 1, 567, 1, '2022-07-12', 0, 0, 6, NULL, NULL, NULL, NULL, NULL), + (100, 5, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 5, NULL, 1, 567, 1, '2022-07-12', 0, 0, 1, NULL, NULL, NULL, NULL, NULL); + +INSERT INTO vn.sector (description,warehouseFk) VALUES + ('Sector One',1); + +INSERT INTO vn.saleGroup (userFk,parkingFk,sectorFk) VALUES + (100,1,1); + +INSERT INTO vn.saleGroupDetail (saleFk,saleGroupFk) VALUES + (32,1); + +INSERT INTO vn.itemShelving (id,itemFk,visible,shelvingFk,`grouping`,packing,packagingFk,userFk) VALUES + (4,1,5,'HEJ',12,12,'2',100); + +INSERT INTO vn.beach (code,warehouseFk) VALUES + ('TEST',1); + +INSERT INTO vn.routesMonitor (routeFk,name,beachFk,m3,expeditionTruckFk) VALUES + (1,'TEST','TEST',1.0,1); + +INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) + VALUES (1101, 1, '2022-07-19 10:00:00', 'Bruce Wayne', NULL, 1, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-19 08:14:37', 1, NULL, 1, 1, 1, 442, 1, '2022-07-06', 0, 0, 13, 5.00, 1.00, 80.00, 75.00, NULL); + +INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded) + VALUES (1, 24, 'Ranged weapon longbow 2m', 1.00, NULL, 8.07, 0, 0.00, 0, 0, 0, '2022-07-06 00:00:00', 0); + +INSERT INTO vn2008.zones (zone_id,name,printingOrder) + VALUES (1,'zone Test',1); + +-- XXX: lab + +INSERT INTO `hedera`.`imageConfig` (`maxSize`,`url`) + VALUES + ('20', '//verdnatura.es/vn-image-data'); + +INSERT INTO `vn`.`businessReasonEnd` (`id`, `reason`) + VALUES + ('1', 'Baja voluntaria'), + ('2', 'No supera PP empresa'), + ('3', 'Despido'); + +INSERT INTO `vn2008`.`payroll_categorias` (`codcategoria`, `descripcion`, `Tarifa`) + VALUES + ('11', 'INFORMATICA', '2'), + ('12', 'AUX INFORMATICA', '7'); + +INSERT INTO `vn`.`occupationCode` (`code`, `name`) + VALUES + ('a', 'Personal en trabajaos exclusivos de oficina'), + ('b', 'Representantes de comercio'), + ('c', 'Personal de oficios en trabajos de construcción en general, y en instalac.,edificios y obras'); + +INSERT INTO `vn2008`.`payroll_employee` (`CodTrabajador`,`nss`,`codpuesto`,`codempresa`,`codcontrato`,`FAntiguedad`,`grupotarifa`,`codcategoria`,`ContratoTemporal`) + VALUES + (36,'46/10515497-58',6,20,189,'2009-01-02',5,10,0), + (43,'46/10235353-50',7,20,189,'2009-04-21',5,10,0), + (76,'46/10250562-30',1,20,189,'2009-09-07',9,5,0), + (1106,'46/10297768-94',4,20,100,'2021-03-09',7,18,0), + (1107,'46/1627085-11',15,20,402,'2021-03-15',9,6,1), + (1108,'46/10446901-41',25,20,502,'2021-03-22',10,29,1), + (1109,'46/10552113-8',3,20,402,'2021-03-23',9,9,1), + (1110,'46/10723579-75',3,20,402,'2021-03-23',9,9,1); + +INSERT INTO `vn`.`trainingCourseType` (`id`, `name`) + VALUES + ('1', 'Curso 1'), + ('2', 'Curso 2'); + +INSERT INTO `vn`.`trainingCenter` (`id`, `name`) + VALUES + ('1', 'Centro curso 1'), + ('2', 'Centro Curso 2'); + +INSERT INTO `vn`.`medicalCenter` (`id`, `name`) + VALUES + ('1', 'Centro médico 1'), + ('2', 'Centro médico 2'); + +INSERT INTO `vn`.`disabilityGrade` (`id`, `description`) + VALUES + ('1', 'Grado 1'), + ('2', 'Grado 2'); + +INSERT INTO `vn`.`absenceType` (`id`,`name`,`rgb`,`color`,`permissionRate`,`code`,`isAllowedToWork`,`isPrintable`,`discountRate`,`holidayEntitlementRate`) + VALUES + (7,'Excedencia','#C71585',16711935,0.00,'leave',0,0,1.00,1.00), + (10,'Baja mutua','#00ffff',16776960,1.00,'insurance',0,0,1.00,0.00), + (11,'Permiso retribuido','#0080ff',16744448,1.00,NULL,0,1,1.00,0.00), + (12,'Visita médico','#ff80ff',16744703,1.00,NULL,0,0,1.00,0.00), + (13,'Visita mutua','#808040',4227200,0.00,NULL,0,0,1.00,0.00), + (14,'Maternidad/Paternidad','#008040',4227072,1.00,'maternity',0,1,1.00,0.00), + (16,'Visita comercial','#00ff00',65280,1.00,NULL,0,1,1.00,0.00), + (17,'Compensar','#dbec40',4844763,0.00,NULL,0,1,1.00,0.00), + (18,'Parte','#0af5a0',10747402,1.00,'proof',0,0,1.00,0.00), + (19,'Descanso','#664208',4798193,0.00,NULL,0,0,1.00,0.00), + (22,'Sin justificar','#8B3E2F',3096203,1.00,NULL,1,1,1.00,0.00); + +-- XXX: app + +INSERT INTO vn.deviceProductionModels (code) + VALUES('TC210K'); + +INSERT INTO vn.deviceProduction (id, imei, modelFk, macWifi, serialNumber, android_id, purchased) + VALUES(100, NULL, 'TC210K', '78B8D67298A6', '21114523025303', NULL, '1900-01-01'); + +INSERT INTO vn.deviceProductionUser (deviceProductionFk, userFk, created) + VALUES(100, 9, NULL); + +INSERT INTO vn.expeditionStateType (id, description, code) + VALUES(15, 'Perdida', 'LOST'); + +INSERT INTO vn.expedition (agencyModeFk,ticketFk,isBox,counter,hostFk,hasNewRoute) + VALUES (1,21,1,1,'',0); + +INSERT INTO vn.sectorCollection (id, created, userFk, sectorFk) + VALUES(18, '2022-07-29 09:03:31', 9, 1); + +INSERT INTO vn.saleGroup (id, created, userFk, parkingFk, sectorFk) + VALUES(3, '2022-07-29 07:18:49', 9, NULL, 1); + +INSERT INTO vn.sectorCollectionSaleGroup (id, created, sectorCollectionFk, saleGroupFk) + VALUES(7, '2022-07-29 09:05:37', 18, 3); + +INSERT INTO vn.saleGroupDetail (created, saleFk, saleGroupFk) + VALUES + ( '2022-07-29 07:26:44', 14, 3), + ( '2022-07-29 07:26:44', 15, 3); + +INSERT INTO vn.saleTracking (saleFk, isChecked, created, originalQuantity, workerFk, id, stateFk) + VALUES + (15, 1, '2022-07-29 07:56:16', 10.0, 9, 6, 26); + +INSERT INTO vn.ticket (id, clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) + VALUES + (3000001, 1110, 1, '2022-07-28 21:00:00', 'ATELIER ART FLORAL', NULL, 129, NULL, NULL, 0, 0, 0, 1, NULL, 0, '2022-07-28 20:27:14', 1, NULL, 1, 16, 1, 442, 1, '2022-07-29', 0, 0, 1, 4.00, 0.00, 41.68, 37.42, NULL); + +INSERT INTO vn.collection (id, created, workerFk, stateFk, itemPackingTypeFk, saleTotalCount, salePickedCount, trainFk) + VALUES + (600001, '2022-07-28 20:04:24', 9, 5, NULL, 5, 5, 1); + +INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded) + VALUES + ( 1, 3000001, 'Ranged weapon longbow 2m', 5.00, NULL, 100.39, 0, 0.00, 0, 1, 0, '2022-06-13 00:00:00', 0); + +INSERT INTO vn.collectionColors(code, shelve, wagon, trainFk) + VALUES + ( 'ROJO', 1, 1, 1); + +INSERT INTO vn.ticketCollection (ticketFk, collectionFk, created, `level`, wagon, smartTagFk, usedShelves, itemCount, liters) + VALUES + (3000001, 600001, '2022-07-28 20:04:24', 1, 1, NULL, NULL, 6, 122); + +INSERT INTO vn.itemShelving (itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, buyFk) + VALUES + ( 1, 'HEJ', 4, '2022-07-13 10:33:34', 12, 12, NULL, 9 , 1), + ( 1, 'GVC', 10, '2022-07-13 10:33:34', 12, 12, NULL, 100, 2), + ( 1, 'UXN', 20, '2022-07-13 10:33:34', 12, 12, NULL, 100, 3); + +INSERT INTO vn.operator (workerFk, numberOfWagons, trainFk, itemPackingTypeFk, warehouseFk) + VALUES + (9, 1, 1, 'V', 1); + +-- XXX: web + +INSERT INTO `hedera`.`config` (`cookieLife`, `defaultForm`) + VALUES (15,'cms/home'); + +INSERT INTO `hedera`.`imageConfig` (`maxSize`, `url`) + VALUES (20, '//verdnatura.es/vn-image-data'); + +INSERT INTO `hedera`.`orderConfig` (`employeeFk`, `guestMethod`, `guestAgencyFk`, `defaultCompanyFk`) + VALUES (1, 'PICKUP', 1, 442); + +INSERT INTO `hedera`.`news` (`title`,`text`, `image`, `userFk`, `created`, `priority`, `tag`) + VALUES + ('Foo new', 'Hi, welcome to Verdnatura''s webshop', 'sd', 9, '2022-01-01 00:00:00', 1, 'new'), + ('Bar new', 'Here you can buy any plant you want', 'sd', 9, '2022-01-02 00:00:00', 1, 'new'); + +UPDATE `vn`.`agencyMode` SET `description` = `name`; + +INSERT INTO `hedera`.`tpvConfig` (currency, terminal, transactionType, maxAmount, employeeFk, `url`, testMode, testUrl, testKey, merchantUrl) + VALUES (978, 1, 0, 2000, 9, 'https://sis.redsys.es/sis/realizarPago', 0, 'https://sis-t.redsys.es:25443/sis/realizarPago', 'sq7HjrUOBfKmC576ILgskD5srU870gJ7', NULL); + +INSERT INTO hedera.tpvMerchantEnable (merchantFk, companyFk) + VALUES (1, 442); + +-- XXX + +SET foreign_key_checks = 1; + +INSERT INTO `account`.`userConfig` (`id`, `loginKey`) + VALUES (1, 'loginKey'); + +UPDATE `account`.`roleConfig` + SET `mysqlPassword` = TO_BASE64('nightmare'); + +CREATE USER 'any'@'%' IDENTIFIED BY 'nightmare'; +UPDATE `mysql`.`global_priv` SET `Host` = '' + WHERE `User` = 'any' AND `Host` = '%'; + +USE account; + +CALL role_sync; + +SELECT rolePrefix INTO @rolePrefix FROM roleConfig; + +SET @genRoleHost = '%'; +SET @prefixLen = CHAR_LENGTH(@rolePrefix); +SET @prefixedLike = CONCAT(@rolePrefix, '%'); + +INSERT INTO mysql.global_priv (`User`, `Host`, `Priv`) + SELECT SUBSTR(`User`, @prefixLen + 1), `Host`, `Priv` + FROM mysql.global_priv + WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost; + +INSERT INTO mysql.roles_mapping (`User`, `Host`, `Role`, `Admin_option`) + SELECT SUBSTR(`User`, @prefixLen + 1), `Host`, `Role`, `Admin_option` + FROM mysql.roles_mapping + WHERE `User` LIKE @prefixedLike AND `Host` = @genRoleHost; + +FLUSH PRIVILEGES; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql new file mode 100644 index 000000000..9894275a3 --- /dev/null +++ b/db/dump/fixtures.before.sql @@ -0,0 +1,2998 @@ +/** + * BE CAREFUL! This file is periodically overwritten from: + * https://gitea.verdnatura.es/verdnatura/salix/raw/branch/master/db/dump/fixtures.sql + * + * Any change made here wich is not in source file will be lost! + */ +SET foreign_key_checks = 0; + +CREATE SCHEMA IF NOT EXISTS `vn2008`; +CREATE SCHEMA IF NOT EXISTS `tmp`; + +UPDATE `util`.`config` + SET `environment`= 'development'; + +-- FOR MOCK vn.time + +DROP PROCEDURE IF EXISTS `vn`.`mockVnTime`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`mockVnTime`() +BEGIN + + DECLARE vDate DATE; + SET vDate = '2000-01-01'; + + WHILE ( YEAR(vDate) <= 2002 ) DO + INSERT IGNORE INTO vn.`time` (dated, period, `month`, `year`, `day`, week, yearMonth, salesYear) + VALUES (vDate, CONCAT(YEAR(vDate), (WEEK(vDate)+1)), MONTH(vDate), YEAR(vDate), DAY(vDate), WEEK(vDate)+1, CONCAT(YEAR(vDate), MONTH(vDate)), YEAR(vDate)); + + SET vDate = DATE_ADD(vDate, INTERVAL 1 DAY); + END WHILE; + +END$$ +DELIMITER ; + +CALL `vn`.`mockVnTime`(); +DROP PROCEDURE IF EXISTS `vn`.`mockVnTime`; +-- END MOCK vn.time + +ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1; +ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1; +ALTER TABLE `vn`.`zoneGeo` AUTO_INCREMENT = 1; +ALTER TABLE `vn`.`ticket` AUTO_INCREMENT = 1; + +INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`) + VALUES + ('DEFAULT_TOKEN', '1209600', CURDATE(), 66); + +INSERT INTO `salix`.`printConfig` (`id`, `itRecipient`, `incidencesEmail`) + VALUES + (1, 'it@gotamcity.com', 'incidences@gotamcity.com'); + +INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) + VALUES + ('1', '6'); + +INSERT INTO `vn`.`bionicConfig` (`generalInflationCoeficient`, `minimumDensityVolumetricWeight`, `verdnaturaVolumeBox`, `itemCarryBox`) + VALUES + (1.30, 167.00, 138000, 71); + +INSERT INTO `vn`.`chatConfig` (`host`, `api`) + VALUES + ('https://chat.verdnatura.es', 'https://chat.verdnatura.es/api/v1'); + +INSERT IGNORE INTO `vn`.`greugeConfig`(`id`, `freightPickUpPrice`) + VALUES + ('1', '11'); + +UPDATE `account`.`role` SET id = 100 WHERE id = 0; + +INSERT INTO `account`.`roleConfig`(`id`, `mysqlPassword`, `rolePrefix`, `userPrefix`, `userHost`, `tplUser`) + VALUES + (1, 'mysqlPassword', '$', '!', '%', 'any'); + +CALL `account`.`role_sync`; + +INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `role`,`active`,`email`, `lang`, `image`, `password`) + SELECT id, name, CONCAT(name, 'Nick'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2' + FROM `account`.`role` + ORDER BY id; + +INSERT INTO `account`.`account`(`id`) + SELECT `u`.`id` + FROM `account`.`user` `u` + JOIN `account`.`role` `r` ON `u`.`role` = `r`.`id` + WHERE `r`.`name` <> 'customer'; + +INSERT INTO `vn`.`educationLevel` (`id`, `name`) + VALUES + (1, 'ESTUDIOS PRIMARIOS COMPLETOS'), + (2, 'ENSEÑANZAS DE BACHILLERATO'); + +INSERT INTO `vn`.`worker` + SET `id` = 9, + `code` = 009, + `firstName` = 'developer', + `lastName` = 'developer', + `bossFk` = 9; + +INSERT IGNORE INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`) + SELECT id,UPPER(LPAD(role, 3, '0')), name, name, 9 + FROM `account`.`user`; + +UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 20; +UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 1 OR id = 9; +UPDATE `vn`.`worker` SET bossFk = 19 WHERE id = 18; + +DELETE FROM `vn`.`worker` WHERE firstName ='customer'; + +INSERT INTO `hedera`.`tpvConfig`(`id`, `currency`, `terminal`, `transactionType`, `maxAmount`, `employeeFk`, `testUrl`) + VALUES + (1, 978, 1, 0, 2000, 9, 0); + +INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`) + VALUES + (1101, 'BruceWayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1102, 'PetterParker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'PetterParker@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1103, 'ClarkKent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'ClarkKent@mydomain.com', 'fr', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1104, 'TonyStark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'TonyStark@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1105, 'MaxEisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1106, 'DavidCharlesHaller', 'David Charles Haller', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'DavidCharlesHaller@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1107, 'HankPym', 'Hank Pym', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'HankPym@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1108, 'CharlesXavier', 'Charles Xavier', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'CharlesXavier@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1109, 'BruceBanner', 'Bruce Banner', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'BruceBanner@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), + (1110, 'JessicaJones', 'Jessica Jones', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'JessicaJones@mydomain.com', 'en', NULL), + (1111, 'Missing', 'Missing', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 0, NULL, 'en', NULL), + (1112, 'Trash', 'Trash', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 0, NULL, 'en', NULL); + +UPDATE account.`user` + SET passExpired = DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR) + WHERE name = 'maintenance'; + +INSERT INTO `account`.`mailAlias`(`id`, `alias`, `description`, `isPublic`) + VALUES + (1, 'general', 'General mailing list', FALSE), + (2, 'it' , 'IT department' , TRUE), + (3, 'sales' , 'Sales department' , TRUE); + +INSERT INTO `account`.`mailAliasAccount`(`mailAlias`, `account`) + VALUES + (1, 1), + (1, 18), + (3, 18), + (1, 9), + (2, 9); + +INSERT INTO `account`.`mailForward`(`account`, `forwardTo`) + VALUES + (1, 'employee@domain.local'); + + + +INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`) + VALUES + (1, 'EUR', 'Euro', 1), + (2, 'USD', 'Dollar USA', 1.4), + (3, 'GBP', 'Libra', 1), + (4, 'JPY', 'Yen Japones', 1); + +INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`) + VALUES + (1, 'España', 1, 'ES', 1, 24, 4, 0, 1), + (2, 'Italia', 1, 'IT', 1, 27, 4, 0, 1), + (3, 'Alemania', 1, 'DE', 1, 22, 4, 0, 1), + (4, 'Rumania', 1, 'RO', 1, 24, 4, 0, 1), + (5, 'Holanda', 1, 'NL', 1, 18, 4, 0, 1), + (8, 'Portugal', 1, 'PT', 1, 27, 4, 0, 1), + (13,'Ecuador', 0, 'EC', 1, 24, 2, 1, 2), + (19,'Francia', 1, 'FR', 1, 27, 4, 0, 1), + (30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2); + +INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) + VALUES + (1, 'Main Warehouse'), + (2, 'Gotham'); + +INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`, `hasProduction`, isOrigin, isDestiny) + VALUES + (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1), + (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 2, 13, 1, 1, 0), + (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0), + (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1, 0, 1), + (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1, 0, 0), + (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 2, 1, 0, 0, 0), + (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0, 0, 0); + + +INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`) + VALUES + (1, 'First sector', 1, 'FIRST'), + (2, 'Second sector', 2, 'SECOND'); + +INSERT INTO vn.printerModel (code) + VALUES ('pcode1'), + ('pcode2'); + +INSERT INTO vn.screenModel (code) + VALUES ('scode1'), + ('scode2'); + +INSERT INTO vn.screen (name,modelFk) + VALUES ('screen1','scode1'), + ('screen1','scode2'); + +INSERT INTO vn.scannerModel (code) + VALUES ('sscode1'), + ('sscode2'); + +INSERT INTO vn.scanner (name,modelFk) + VALUES ('scanner1','sscode1'), + ('scanner2','sscode2'); + + +INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `modelFk`, `isLabeler`, `sectorFk`, `ipAddress`) + VALUES + (1, 'printer1', 'path1','pcode1', 0, 1 , NULL), + (2, 'printer2', 'path2','pcode1', 1, 1 , NULL), + (4, 'printer4', 'path4','pcode2', 0, 1, '10.1.10.4'); + +UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1; + +INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`,`bossFk`, `phone`) + VALUES + (1106, 'LGN', 'David Charles', 'Haller', 19, 432978106), + (1107, 'ANT', 'Hank' , 'Pym' , 19, 432978107), + (1108, 'DCX', 'Charles' , 'Xavier', 19, 432978108), + (1109, 'HLK', 'Bruce' , 'Banner', 19, 432978109), + (1110, 'JJJ', 'Jessica' , 'Jones' , 19, 432978110); + +INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`) + VALUES + ('1', 700, '01', 1, '700-01', 70001), + ('2', 700, '02', 2, '700-02', 70002), + ('3', 100, '01', 1, '100-01', 1), + (32397, 100, '02', 1, 'A-47-1', 1165), + (34831, 200, '01', 1, 'K-26-2', 20220), + (34965, 200, '02', 2, 'L-08-4', 21800), + (39096, 200, '03', 2, 'LR-02-3', 99999); + +INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `userFk`, `isRecyclable`) + VALUES + ('AA6', 34965, 1, 0, NULL, 0), + ('AA7', 34965, 1, 0, NULL, 0), + ('AA8', 34965, 1, 0, NULL, 0), + ('AA9', NULL, 1, 0, NULL, 0), + ('AAA', NULL, 0, 0, 1109, 1), + ('AAB', NULL, 0, 0, 1109, 1), + ('AAC', NULL, 1, 99, 1109, 1), + ('AAD', NULL, 0, 0, 1109, 1), + ('AAE', 39096, 1, 0, 1109, 1), + ('AAF', 34831, 1, 0, 1109, 1), + ('GVC', 1, 0, 1, 1106, 1), + ('HEJ', 2, 0, 1, 1106, 1), + ('UXN', 1, 0, 1, 1106, 1); + +INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`, `maxAmount`, `daysInFuture`) + VALUES + (1, 'CC and credit policies', 'Transfers', 'wireTransfer', NULL, 1), + (2, 'Cash', 'Cash', 'cash', 1000, 0), + (3, 'Credit card', 'Credit Card', 'creditCard', NULL, 0), + (4, 'Finalcial lines', NULL, NULL, NULL, 0), + (5, 'Other products', NULL, NULL, NULL, 0), + (6, 'Loans', NULL, NULL, NULL, 0), + (7, 'Leasing', NULL, NULL, NULL, 0), + (8, 'Compensations', 'Compensations', 'compensation', NULL, 0); + +INSERT INTO `vn`.`bankEntity`(`id`, `countryFk`, `name`, `bic`) + VALUES + (128, 1, 'The Best Bank', 'BBKKESMMMMMM'), + (2100, 1, 'Caixa Bank', 'CAIXESBB'); + +INSERT INTO `vn`.`accounting`(`id`, `bank`, `account`, `accountingTypeFk`, `entityFk`, `isActive`, `currencyFk`, `code`) + VALUES + (1, 'Pay on receipt', '5720000001', 3, 128, 1, 1, 'payOnReceipt'), + (2, 'Cash', '5700000001', 2, 128, 1, 1, 'cash'), + (3, 'Compensation', '4000000000', 8, 128, 1, 1, 'compensation'), + (4, 'Transfers', '4000000001', 1, 128, 1, 1, 'transfers'), + (3117, 'Caixa Rural d''Algemesi', '5720000000', 8, 2100, 1, 1, 'cra'); + +INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`) + VALUES + (1, 'AGENCY', 'Agencia'), + (2, 'DELIVERY', 'Reparto'), + (3, 'PICKUP', 'Recogida'), + (4, 'OTHER', 'Otros'); + +INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `warehouseAliasFk`) + VALUES + (1, 'inhouse pickup' , 1, 1), + (2, 'Super-Man delivery' , 1, 1), + (3, 'Teleportation device' , 1, 1), + (4, 'Entanglement' , 1, 1), + (5, 'Quantum break device' , 1, 1), + (6, 'Walking' , 1, 1), + (7, 'Gotham247' , 1, 1), + (8, 'Gotham247Expensive' , 1, 1), + (9, 'Refund' , 1, 1), + (10, 'Other agency' , 1, 1); + +UPDATE `vn`.`agencyMode` SET `id` = 1 WHERE `name` = 'inhouse pickup'; +UPDATE `vn`.`agencyMode` SET `id` = 2 WHERE `name` = 'Super-Man delivery'; +UPDATE `vn`.`agencyMode` SET `id` = 3 WHERE `name` = 'Teleportation device'; +UPDATE `vn`.`agencyMode` SET `id` = 4 WHERE `name` = 'Entanglement'; +UPDATE `vn`.`agencyMode` SET `id` = 5 WHERE `name` = 'Quantum break device'; +UPDATE `vn`.`agencyMode` SET `id` = 6 WHERE `name` = 'Walking'; +UPDATE `vn`.`agencyMode` SET `id` = 7 WHERE `name` = 'Gotham247'; +UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Gotham247Expensive'; +UPDATE `vn`.`agencyMode` SET `id` = 23 WHERE `name` = 'Refund'; +UPDATE `vn`.`agencyMode` SET `id` = 10 WHERE `name` = 'Other agency'; + +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 3 WHERE `id` = 1; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 3; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 4; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 5; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 6; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 7; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23; +UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10; + +UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com'; + +UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; + +INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`, `hasVerified`) + VALUES + (1, NULL, 'PayMethod one', 0, 001, 0, 0, 0), + (2, NULL, 'PayMethod two', 10, 001, 0, 0, 1), + (3, 'compensation', 'PayMethod three', 0, 001, 0, 0, 0), + (4, NULL, 'PayMethod with IBAN', 0, 001, 1, 0, 0), + (5, NULL, 'PayMethod five', 10, 001, 0, 0, 0), + (8,'wireTransfer', 'WireTransfer', 5, 001, 1, 1, 0); + +INSERT INTO `vn`.`payDem`(`id`, `payDem`) + VALUES + (1, 10), + (2, 20), + (7, 0); + +INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`) + VALUES + (1, 'Autonomy one', 1), + (2, 'Autonomy two', 1), + (3, 'Autonomy three', 2), + (4, 'Autonomy four', 13); + + +INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `autonomyFk`, `warehouseFk`) + VALUES + (1, 'Province one', 1, 1, NULL), + (2, 'Province two', 1, 1, NULL), + (3, 'Province three', 30, 2, NULL), + (4, 'Province four', 2, 3, NULL), + (5, 'Province five', 13, 4, NULL); + +INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) + VALUES + (1, 'Valencia', 1), + (2, 'Gotham', 1), + (3, 'Algemesi', 1), + (4, 'Alzira', 1), + (5, 'Quito', 5); + +INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) + VALUES + ('46000', 1, 6), + ('46460', 2, 6), + ('46680', 3, 6), + ('46600', 4, 7), + ('EC170150', 5, 8); + +INSERT INTO `vn`.`clientType`(`id`, `code`, `type`) + VALUES + (1, 'normal', 'Normal'), + (2, 'internalUse', 'Autoconsumo'), + (3, 'handMaking', 'Confección'), + (4, 'loses', 'Mermas'); + +INSERT INTO `vn`.`cplusTerIdNif`(`id`, `description`) + VALUES + (1, 'NIF'); + +INSERT INTO `vn`.`contactChannel`(`id`, `name`) + VALUES + (1, 'Rumors on the streets'), + (2, 'Metropolis newspaper'), + (3, 'Daily Bugle'), + (4, 'GCN Channel'), + (5, 'The Newspaper'); + +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`) + VALUES + (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), + (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), + (1103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street, Apartament 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), + (1104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), + (1105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist'), + (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist'), + (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1, 'florist'), + (1108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist'), + (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'), + (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'), + (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others'), + (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others'); + +INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 + FROM `account`.`role` `r` + WHERE `r`.`hasLogin` = 1; + +INSERT INTO `vn`.`clientManaCache`(`clientFk`, `mana`, `dated`) + VALUES + (1101, 50, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (1102, 100, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (1103, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (1104, -30, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)); + +INSERT INTO `vn`.`mandateType`(`id`, `name`) + VALUES + (1, 'B2B'), + (2, 'CORE'), + (3, 'LCR'); + +INSERT INTO `vn`.`clientConfig`(`id`, `riskTolerance`, `maxCreditRows`, `maxPriceIncreasingRatio`, `riskScope`, `defaultPayMethodFk`, `defaultDueDay`, `defaultCredit`, `defaultIsTaxDataChecked`, `defaultHasCoreVnl`, `defaultMandateTypeFk`) + VALUES + (1, 200, 10, 0.25, 2, 4, 5, 300.00, 1, 1, 2); + + +INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`, `isDefaultAddress`) + VALUES + (1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1), + (2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1), + (3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1), + (4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1 , 1104, 2, NULL, NULL, 0, 1), + (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1), + (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1), + (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1), + (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), + (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1), + (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1), + (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1), + (12, 'Trash', 'New York city', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1112, 10, NULL, NULL, 0, 1), + (101, 'Somewhere in Thailand', 'address 01', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (102, 'Somewhere in Poland', 'address 02', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), + (103, 'Somewhere in Japan', 'address 03', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), + (104, 'Somewhere in Spain', 'address 04', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), + (105, 'Somewhere in Potugal', 'address 05', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (106, 'Somewhere in UK', 'address 06', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (107, 'Somewhere in Valencia', 'address 07', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (108, 'Somewhere in Gotham', 'address 08', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), + (109, 'Somewhere in London', 'address 09', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (110, 'Somewhere in Algemesi', 'address 10', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (111, 'Somewhere in Carlet', 'address 11', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (112, 'Somewhere in Campanar', 'address 12', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (113, 'Somewhere in Malilla', 'address 13', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (114, 'Somewhere in France', 'address 14', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (115, 'Somewhere in Birmingham', 'address 15', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (116, 'Somewhere in Scotland', 'address 16', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (117, 'Somewhere in nowhere', 'address 17', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (118, 'Somewhere over the rainbow', 'address 18', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (119, 'Somewhere in Alberic', 'address 19', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (120, 'Somewhere in Montortal', 'address 20', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), + (121, 'the bat cave', 'address 21', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 0), + (122, 'NY roofs', 'address 22', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 0), + (123, 'The phone box', 'address 23', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 0), + (124, 'Stark tower Gotham', 'address 24', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 0), + (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0), + (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0), + (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0), + (128, 'Cerebro', 'address 28', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), + (129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0), + (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0); + +INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`) + SELECT name, CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, 1, id, 2, 1 + FROM `account`.`role` `r` + WHERE `r`.`hasLogin` = 1; + +UPDATE `vn`.`client` SET defaultAddressFk = 1 WHERE id = 1101; +UPDATE `vn`.`client` SET defaultAddressFk = 2 WHERE id = 1102; +UPDATE `vn`.`client` SET defaultAddressFk = 3 WHERE id = 1103; +UPDATE `vn`.`client` SET defaultAddressFk = 4 WHERE id = 1104; +UPDATE `vn`.`client` SET defaultAddressFk = 5 WHERE id = 1105; +UPDATE `vn`.`client` SET defaultAddressFk = 6 WHERE id = 1106; +UPDATE `vn`.`client` SET defaultAddressFk = 7 WHERE id = 1107; +UPDATE `vn`.`client` SET defaultAddressFk = 8 WHERE id = 1108; +UPDATE `vn`.`client` SET defaultAddressFk = 9 WHERE id = 1109; +UPDATE `vn`.`client` SET defaultAddressFk = 10 WHERE id = 1110; +UPDATE `vn`.`client` SET defaultAddressFk = 11 WHERE id = 200; +UPDATE `vn`.`client` SET defaultAddressFk = 12 WHERE id = 400; + +DROP TEMPORARY TABLE IF EXISTS tmp.address; + +CREATE TEMPORARY TABLE tmp.address + SELECT * FROM `vn`.`address`; + + UPDATE `vn`.`client` `c` + JOIN `tmp`.`address` `a` ON `a`.`clientFk` = `c`.`id` + SET `c`.`defaultAddressFk` = `a`.`id` + WHERE `defaultAddressFk` IS NULL; +DROP TEMPORARY TABLE tmp.address; + +INSERT INTO `vn`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`) + VALUES + (1, 9999999, 20), + (2, 10000, 21), + (3, 600, 13); + +INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`) + VALUES + (1, 1101, 1, 'Madness, as you know, is like gravity, all it takes is a little push', util.VN_CURDATE()), + (2, 1102, 1, 'With great power, comes great responsibility', util.VN_CURDATE()), + (3, 1103, 3, 'this is a job for Super-Man!', util.VN_CURDATE()), + (4, 1104, 3, 'yes... I am Iron-Man', util.VN_CURDATE()), + (5, 1105, 5, 'They do understand. Our mutant powers make us superior', util.VN_CURDATE()), + (6, 1106, 5, 'My name is Legion, for we are many!', util.VN_CURDATE()), + (7, 1107, 9, 'I think our first move should be calling the Avengers..', util.VN_CURDATE()), + (8, 1108, 9, 'Just because someone stumbles and loses their path, does not mean they are lost forever.', util.VN_CURDATE()), + (9, 1109, 18, 'HULK SMASH! ...', util.VN_CURDATE()), + (10, 1110, 18, 'They say everyone is born a hero. But if you let it, life will push you over the line until you are the villain.', util.VN_CURDATE()); + +INSERT INTO `vn`.`observationType`(`id`,`description`, `code`) + VALUES + (1, 'ItemPicker', 'itemPicker'), + (2, 'Packager', 'packager'), + (3, 'Delivery', 'delivery'), + (4, 'SalesPerson', 'salesPerson'), + (5, 'Administrative', 'administrative'), + (6, 'Weight', 'weight'), + (7, 'InvoiceOut', 'invoiceOut'); + +INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) + VALUES + (1, 121, 1, 'under the floor'), + (2, 121, 2, 'wears leather and goes out at night'), + (3, 121, 3, 'care with the dog'), + (5, 122, 5, 'Delivery after 10am'); + +INSERT INTO `vn`.`creditClassification`(`id`, `client`, `dateStart`, `dateEnd`) + VALUES + (1, 1101, util.VN_CURDATE(), util.VN_CURDATE()), + (2, 1102, util.VN_CURDATE(), util.VN_CURDATE()), + (3, 1103, util.VN_CURDATE(), util.VN_CURDATE()), + (4, 1104, util.VN_CURDATE(), util.VN_CURDATE()), + (5, 1105, util.VN_CURDATE(), util.VN_CURDATE()); + +INSERT INTO `vn`.`creditInsurance`(`id`, `creditClassificationFk`, `credit`, `creationDate`, `grade`) + VALUES + (1, 1, 3000, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL), + (2, 2, 6000, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL), + (3, 3, 10000, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL); + +INSERT INTO `vn`.`companyGroup`(`id`, `code`) + VALUES + (1, 'wayneIndustries'), + (2, 'verdnatura'); + +INSERT INTO `vn`.`supplierActivity`(`code`, `name`) + VALUES + ('animals', 'Food and complements for pets'), + ('complements', 'Other complements'), + ('flowerPlants', 'Wholesale of flowers and plants'), + ('vegetablesFruits', 'Fruit and vegetable trade'); + +INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`, `commission`, `created`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`, `taxTypeSageFk`, `withholdingSageFk`, `transactionTypeSageFk`, `workerFk`, `supplierActivityFk`, `isPayMethodChecked`, `healthRegister`) + VALUES + (1, 'Plants SL', 'Plants nick', 4100000001, 1, '06089160W', 0, util.VN_CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), + (2, 'Farmer King', 'The farmer', 4000020002, 1, '87945234L', 0, util.VN_CURDATE(), 1, 'supplier address 2', 'GOTHAM', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), + (69, 'Packaging', 'Packaging nick', 4100000069, 1, '94935005K', 0, util.VN_CURDATE(), 1, 'supplier address 5', 'ASGARD', 3, 46600, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), + (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, util.VN_CURDATE(), 1, 'supplier address 3', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), + (567, 'Holland', 'Holland nick', 4000020567, 1, '14364089Z', 0, util.VN_CURDATE(), 1, 'supplier address 6', 'ASGARD', 3, 46600, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), + (791, 'Bros SL', 'Bros nick', 5115000791, 1, '37718083S', 0, util.VN_CURDATE(), 1, 'supplier address 7', 'ASGARD', 3, 46600, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), + (1381, 'Ornamentales', 'Ornamentales', 7185001381, 1, '07972486L', 0, util.VN_CURDATE(), 1, 'supplier address 4', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'); + +INSERT INTO `vn`.`supplierAddress`(`id`, `supplierFk`, `nickname`, `street`, `provinceFk`, `postalCode`, `city`, `phone`, `mobile`) + VALUES + (1, 1, 'Ace Chemicals', 'The Midtown', 1, '46000', 'Gotham', '111111111', '222222222'), + (2, 1, 'Arkham Asylum', 'Grand Avenue', 1, '46000', 'Gotham', '111111111', '222222222'), + (3, 2, 'Wayne Tower', 'Grand Avenue', 1, '46000', 'Gotham', '111111111', '222222222'), + (4, 2, 'Bank of Gotham', 'Founders Island', 1, '46000', 'Gotham', '111111111', '222222222'), + (5, 442, 'GCR building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'), + (6, 442, 'The Gotham Tonight building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'); + +INSERT INTO `vn`.`supplierContact`(`id`, `supplierFk`, `phone`, `mobile`, `email`, `observation`, `name`) + VALUES + (1, 1, 123121212, 654789123, 'supplier1@email.es', 'observation1', 'the boss'), + (2, 1, 987456132, NULL, NULL, NULL, 'the salesperson'), + (3, 2, 321654987, NULL, 'supplier2@email.es', NULL, NULL), + (4, 442, 321654987, NULL, NULL, 'observation442', NULL); + +INSERT INTO `vn`.`supplierAccount`(`id`, `supplierFk`, `iban`, `bankEntityFk`) + VALUES + (241, 442, 'ES111122333344111122221111', 128); + +INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `sage200Company`, `expired`, `companyGroupFk`, `phytosanitary` , `clientFk`) + VALUES + (69 , 'CCs', NULL, 30, NULL, 0, NULL, 1, NULL , NULL), + (442 , 'VNL', 241, 30, 2 , 1, NULL, 2, 'VNL Company - Plant passport' , 1101), + (567 , 'VNH', NULL, 30, NULL, 4, NULL, 1, 'VNH Company - Plant passport' , NULL), + (791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', 1, NULL , NULL), + (1381, 'ORN', NULL, 30, NULL, 7, NULL, 1, 'ORN Company - Plant passport' , NULL); + +INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) + VALUES + ('CEE', 1, 10), + ('EQU', 0, 1), + ('NATIONAL', 0, 1), + ('WORLD', 2, 15); + +INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) + VALUES + ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), + ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), + ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), + ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'quick'), + ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); + +INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) + VALUES + (1, 'T', 1014.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), + (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), + (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), + (4, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), + (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0); + +UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; +UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2; +UPDATE `vn`.`invoiceOut` SET ref = 'T3333333' WHERE id = 3; +UPDATE `vn`.`invoiceOut` SET ref = 'T4444444' WHERE id = 4; +UPDATE `vn`.`invoiceOut` SET ref = 'A1111111' WHERE id = 5; + + +INSERT INTO vn.siiTrascendencyInvoiceOut (id, description) + VALUES + (1, 'Operación de régimen general'), + (2, 'Exportación'), + (3, 'Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (135 - 139 de LIVA)'), + (4, 'Régimen especial oro de inversión'), + (5, 'Régimen especial agencias de viajes'), + (6, 'Régimen especial grupo de entidades en IVA (Nivel Avanzado)'), + (7, 'Régimen especial criterio de caja'), + (8, 'Operaciones sujetas al IPSI / IGIC'), + (9, 'Facturación de las prestaciones de servicios de agencias de viaje que actúan como mediadoras en nombre y por cuenta ajena (D.A.4ª RD 1619/2012)'), + (10, 'Cobros por cuenta de terceros de honorarios profesionales o de Dº derivados de la propiedad industrial, de autor u otros por cuenta de sus socios, asociados,colegiados efectuados por sociedades, asociaciones, colegios profesionales u otras entidades '), + (11, 'Operaciones de arrendamiento de local de negocio sujetas a retención'), + (12, 'Operaciones de arrendamiento de local de negocio no sujetos a retención'), + (13, 'Operaciones de arrendamiento de local de negocio sujetas y no sujetas a retención'), + (14, 'Factura con IVA pendiente de devengo (certificaciones de obra cuyo destinatario sea una Administración Pública)'), + (15, 'Factura con IVA pendiente de devengo - operaciones de tracto sucesivo'), + (16, 'Primer semestre 2017'); + + +INSERT INTO vn.invoiceOutConfig + SET parallelism = 8; + +INSERT INTO `vn`.`invoiceOutTax` (`invoiceOutFk`, `taxableBase`, `vat`, `pgcFk`) + VALUES + (1, 895.76, 89.58, 4722000010), + (1, 33.80, 7.10, 4722000021), + (2, 110.33, 11.03, 4770000010), + (3, 8.07, 0.81, 4770000010), + (4, 8.07, 0.81, 4770000010), + (5, 8.07, 0.81, 4770000010); + +INSERT INTO `vn`.`expense`(`id`, `name`, `isWithheld`) + VALUES + (2000000000, 'Inmovilizado pendiente', 0), + (2000000001, 'Compra de bienes de inmovilizado', 0), + (4751000000, 'Retenciones', 1), + (4751000001, 'Retencion', 0), + (6210000567, 'Alquiler VNH', 0), + (6240000000, 'Transportes de ventas rutas', 0), + (7001000000, 'Mercaderia', 0), + (7050000000, 'Prestacion de servicios', 1); + + +INSERT INTO `vn`.`invoiceOutExpense`(`id`, `invoiceOutFk`, `amount`, `expenseFk`, `created`) + VALUES + (1, 1, 813.06, 2000000000, util.VN_CURDATE()), + (2, 1, 33.80, 4751000000, util.VN_CURDATE()), + (3, 1, 70.70, 6210000567, util.VN_CURDATE()), + (4, 2, 110.33, 2000000000, util.VN_CURDATE()), + (5, 3, 8.07, 2000000000, util.VN_CURDATE()), + (6, 4, 8.07, 2000000000, util.VN_CURDATE()), + (7, 5, 8.07, 2000000000, util.VN_CURDATE()); + +INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `itemMaxSize`) + VALUES + (1, 'Zone pickup A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), + (2, 'Zone pickup B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), + (3, 'Zone 247 A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), + (4, 'Zone 247 B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), + (5, 'Zone expensive A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), + (6, 'Zone expensive B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), + (7, 'Zone refund', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 100), + (8, 'Zone others', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 100), + (9, 'Zone superMan', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 0, 0, 100), + (10, 'Zone teleportation', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 0, 0, 100), + (11, 'Zone pickup C', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), + (12, 'Zone entanglement', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 0, 0, 100), + (13, 'Zone quantum break', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 0, 0, 100); + +INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) + VALUES + (1, 1, 1), + (2, 2, 2), + (3, 3, 1), + (4, 4, 2), + (5, 5, 1), + (6, 6, 2), + (7, 7, 1), + (8, 8, 1), + (9, 9, 1), + (10, 10, 3), + (11, 11, 5), + (12, 12, 4), + (13, 13, 5); + +INSERT INTO `vn`.`zoneClosure` (`zoneFk`, `dated`, `hour`) + VALUES + (1, util.VN_CURDATE(), '23:59'), + (2, util.VN_CURDATE(), '23:59'), + (3, util.VN_CURDATE(), '23:59'), + (4, util.VN_CURDATE(), '23:59'), + (5, util.VN_CURDATE(), '23:59'), + (6, util.VN_CURDATE(), '23:59'), + (7, util.VN_CURDATE(), '23:59'), + (8, util.VN_CURDATE(), '23:59'), + (9, util.VN_CURDATE(), '23:59'), + (10, util.VN_CURDATE(), '23:59'), + (11, util.VN_CURDATE(), '23:59'), + (12, util.VN_CURDATE(), '23:59'), + (13, util.VN_CURDATE(), '23:59'); + +INSERT INTO `vn`.`zoneConfig` (`scope`) VALUES ('1'); + +INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`) + VALUES + (1, '1899-12-30 12:15:00', 56, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1), + (2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9), + (3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10), + (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12), + (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13), + (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3), + (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5); + +INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`) + VALUES + (1 , 3, 1, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1), + (2 , 1, 1, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2), + (3 , 1, 7, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL), + (4 , 3, 2, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL), + (5 , 3, 3, 3, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL), + (6 , 1, 3, 3, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL), + (7 , NULL, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (8 , NULL, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Bat cave', 121, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (9 , NULL, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (10, 1, 1, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (11, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (12, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (13, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (14, 1, 2, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1104, 'Malibu Point', 4, NULL, 0, 9, 5, 1, util.VN_CURDATE(), NULL), + (15, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 'An incredibly long alias for testing purposes', 125, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (16, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (17, 1, 7, 2, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (18, 1, 4, 4, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 'Cerebro', 128, NULL, 0, 12, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +12 HOUR), NULL), + (19, 1, 5, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 1, NULL, 5, 1, util.VN_CURDATE(), NULL), + (20, 1, 5, 5, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), + (21, NULL, 5, 5, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), + (22, NULL, 5, 5, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), + (23, NULL, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'address 21', 121, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), + (24 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), + (25 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (26 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (28, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (29, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (30, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (31, 1, 8, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (32, 1, 8, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL); + +INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) + VALUES + (1, 11, 1, 'ready'), + (2, 2, 2, 'do it fast please'), + (3, 3, 5, 'Faster faster fasteeeeeer!!!'), + (4, 4, 5, 'Deliver before 8am'), + (5, 13, 5, 'You can run from the disappointments you are trying to forget. But its only when you embrace your past that you truly move forward. Maybe I never get to go home again, but I found my way there. And I am glad I did.'), + (6, 14, 5, 'Careful, armed warhead'), + (7, 23, 1, 'under the floor'), + (8, 23, 2, 'wears leather and goes out at night'), + (9, 23, 5, 'care with the dog'), + (10, 23, 4, 'Reclama ticket: 8'), + (11, 24, 4, 'Reclama ticket: 7'), + (12, 11, 3, 'Delivery after 10am'), + (13, 1, 7, 'observation of ticket one'), + (14, 2, 7, 'observation of ticket two'); + +-- FIX for state hours on local, inter_afterInsert +-- UPDATE vncontrol.inter SET odbc_date = DATE_ADD(util.VN_CURDATE(), INTERVAL -10 SECOND); + +INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) + VALUES + (1, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), + (2, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), + (3, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -2 MONTH)), + (4, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -3 MONTH)), + (5, 16, 18, DATE_ADD(util.VN_NOW(), INTERVAL -4 MONTH)), + (6, 16, 18, DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), + (7, 10, 18, util.VN_NOW()), + (8, 5, 19, util.VN_NOW()), + (9, 5, 19, util.VN_NOW()), + (10, 5, 19, util.VN_NOW()), + (11, 3, 19, util.VN_NOW()), + (12, 3, 19, util.VN_NOW()), + (13, 3, 19, util.VN_NOW()), + (14, 3, 19, util.VN_NOW()), + (15, 2, 19, util.VN_NOW()), + (16, 3, 19, util.VN_NOW()), + (17, 2, 19, util.VN_NOW()), + (18, 2, 19, util.VN_NOW()), + (19, 2, 19, util.VN_NOW()), + (20, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), + (21, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), + (22, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), + (23, 16, 21, util.VN_NOW()), + (24, 16, 21, util.VN_NOW()); + +INSERT INTO `vn`.`deliveryPoint` (`id`, `name`, `ubication`) + VALUES + (1, 'Gotham','1007 Mountain Drive, Gotham'); + +INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk`, `warehouseFk`, `description`, `m3`, `isActive`, `deliveryPointFk`) + VALUES + (1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 1), + (2, '1111-IMK', 'STARK INDUSTRIES', 'MARK-III', 442, 1, 'Iron-Man Heavy Armor MARK-III', 18, 1, 1), + (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1), + (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1), + (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1), + (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1); + +INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, `inventoried`) + VALUES + (1, 'beta-server', 'nightmare@mydomain.com', '200', DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH)); + +INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) + VALUES + (1, 'Diff', 'diff'), + (2, 'Recover', 'recover'), + (3, 'Mana', 'mana'), + (4, 'Reclaim', 'reclaim'), + (5, 'Heritage', 'heritage'), + (6, 'Miscellaneous', 'miscellaneous'), + (7, 'Freight Pickup', 'freightPickUp'); + +INSERT INTO `vn`.`greuge`(`id`, `clientFk`, `description`, `amount`, `shipped`, `created`, `greugeTypeFk`, `ticketFk`) + VALUES + (1, 1101, 'some diff charges', -19.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 1, 1), + (2, 1101, 'more diff charges', 60, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 2, 1), + (3, 1101, 'even more! diff charges', -9.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 3, 1), + (4, 1101, 'insane diff charges', 60, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 4, 1), + (5, 1101, 'gargantuous diff charges', -9.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 5, 1), + (6, 1101, 'diff charges', 88.30, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 6, 1), + (7, 1101, 'unaffordable diff charges', -39.12, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 1, 1), + (8, 1101, 'some recovery charges', 29.35, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 2, 1), + (9, 1101, 'some manna charges', -9.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 3, 1), + (10, 1101, 'some claim charges', 13.13, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 4, 1), + (11, 1101, 'some heritage charges', -15.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 5, 1), + (12, 1101, 'some miscellaneous charges', 58.00, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 6, 1); + +INSERT INTO `vn`.`mandate`(`id`, `clientFk`, `companyFk`, `code`, `created`, `mandateTypeFk`) + VALUES + (1, 1102, 442, '1-1', util.VN_CURDATE(), 2); + +INSERT INTO `vn`.`itemCategory`(`id`, `name`, `display`, `color`, `icon`, `code`) + VALUES + (1, 'Plant', 1, 'B92A26', 'icon-plant', 'plant'), + (2, 'Flower', 2, 'dcf711', 'icon-flower', 'flower'), + (3, 'Logistic', 0, 'b9f711', NULL, 'logistical'), + (4, 'Handmade', 1, NULL, 'icon-handmade', 'handmade'), + (5, 'Artificial', 1, NULL, 'icon-artificial', 'artificial'), + (6, 'Green', 1, NULL, 'icon-greenery', 'greenery'), + (7, 'Accessories', 1, NULL, 'icon-accessory', 'accessory'), + (8, 'Fruit', 1, NULL, 'icon-fruit', 'fruit'); + +INSERT INTO `vn`.`temperature`(`code`, `name`, `description`) + VALUES + ('warm', 'Warm', 'Warm'), + ('cool', 'Cool', 'Cool'); + +INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `life`, `workerFk`, `isPackaging`, `temperatureFk`, `isFragile`) + VALUES + (1, 'CRI', 'Crisantemo', 2, 31, 35, 0, 'cool', 0), + (2, 'ITG', 'Anthurium', 1, 31, 35, 0, 'cool', 1), + (3, 'WPN', 'Paniculata', 2, 31, 35, 0, 'cool', 0), + (4, 'PRT', 'Delivery ports', 3, NULL, 35, 1, 'warm', 0), + (5, 'CON', 'Container', 3, NULL, 35, 1, 'warm', 0), + (6, 'ALS', 'Alstroemeria', 1, 31, 16, 0, 'warm', 1); + +INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`) + VALUES + ('YEL', 'Yellow', 1, 1, 'F4D03F'), + ('BLU', 'Blue', 1, 2, '5DADE2'), + ('RED', 'Red', 1, 3, 'EC7063'), + ('SLV', 'Silver', 1, 4, 'CACFD2'), + ('BRW', 'Brown', 1, 5, 'DC7633'), + ('BLK', 'Black', 1, 6, '000000'), + ('BAS', 'Blue/Silver', 1, 7, '5DADE2'); + +INSERT INTO `vn`.`origin`(`id`,`code`, `name`) + VALUES + (1, 'SPA', 'Spain'), + (2, 'HOL', 'Holand'), + (3, 'VLC', 'Valencia'); + +INSERT INTO `vn`.`producer`(`id`, `name`) + VALUES + (1, 'Marvel Studios'), + (2, 'Nordic Mythology'); + +INSERT INTO `vn`.`taxType`(`id`, `nickname`, `isAccrued`, `serial`, `TIPOOPE`, `description`, `countryFk`) + VALUES + (1, 'National', 1, 'R', 'I', 'national VAT', 1), + (2, 'European', 0, 'E', 'I', 'europe VAT', 1); + +INSERT INTO `vn`.`taxCode`(`id`, `dated`, `code`, `taxTypeFk`, `rate`, `equalizationTax`, `type`, `link`, `isActive`, `updated`, `transactionCode`) + VALUES + (1 , util.VN_CURDATE(), '1111111111', 1, 7.0 , 0.0, 'R', 1, 1, util.VN_CURDATE(), 1), + (2 , util.VN_CURDATE(), '2222222222', 2, 16.0, 0.0, 'G', 2, 1, util.VN_CURDATE(), 1), + (21 , util.VN_CURDATE(), '3333333333', 1, 7.0, 0.0, 'R', 3, 1, util.VN_CURDATE(), 1), + (108, util.VN_CURDATE(), '4444444444', 2, 8.0 , 0.0, 'R', 4, 1, util.VN_CURDATE(), 1); + +INSERT INTO `vn`.`taxClass`(`id`, `description`, `code`) + VALUES + (1, 'Reduced VAT', 'R'), + (2, 'General VAT', 'G'); + +INSERT INTO `vn`.`taxClassCode`(`taxClassFk`, `effectived`, `taxCodeFk`) + VALUES + (1, util.VN_CURDATE(), 1), + (1, util.VN_CURDATE(), 21), + (2, util.VN_CURDATE(), 2); + +INSERT INTO `vn`.`intrastat`(`id`, `description`, `taxClassFk`, `taxCodeFk`) + VALUES + (05080000, 'Coral y materiales similares', 2, 2), + (06021010, 'Plantas vivas: Esqueje/injerto, Vid', 1, 1); + +INSERT INTO `vn`.`itemFamily`(`code`, `description`) + VALUES + ('EMB', 'Packagings'), + ('SER', 'Services'), + ('VT', 'Sales'); + +INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenseFk`, + `comment`, `relevancy`, `image`, `subName`, `minPrice`, `stars`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`, `weightByPiece`) + VALUES + (1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 1, 'EMB', 0, NULL, 'V', 0, 15,3), + (2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 2, 'VT', 0, NULL, 'H', 0, 10,2), + (3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, 5,5), + (4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL,NULL), + (10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 2, 'VT', 1, NULL, NULL, 1, NULL,NULL), + (14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL,NULL), + (15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), + (16, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), + (71, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL); + +-- Update the taxClass after insert of the items +UPDATE `vn`.`itemTaxCountry` SET `taxClassFk` = 2 + WHERE `itemFk` IN(4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 71); + +INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`, `started`, `ended`, `bonus`, `warehouseFk`, `created`) + VALUES + (1, 1, 0, 0, 2.5, 2, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()), + (2, 3, 10, 10, 10, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()), + (3, 13, 8.5, 10, 7.5, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 1, 2, util.VN_CURDATE()); + +INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`) + VALUES + (71,0.141,1); + +INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPackageReturnable`, `created`, `itemFk`, `price`) + VALUES + (1, 0.00, 10, 10, 0, 1, util.VN_CURDATE(), 6, 1.50), + (2, 100.00, 20, 20, 0, 1, util.VN_CURDATE(), 7, 1.00), + (3, 14000.00, 0, 0, 0, 1, util.VN_CURDATE(), NULL, 0), + (4, 218000.00, 0, 0, 0, 0, util.VN_CURDATE(), NULL, 0), + (5, 292000.00, 0, 0, 0, 0, util.VN_CURDATE(), NULL, 0), + (94, 140875.00, 49.00, 115.00, 25.00, 0, util.VN_CURDATE(), 71, 0.00), + ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, util.VN_CURDATE(), 15, 90.00), + ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, util.VN_CURDATE(), 16, 0.00); + +INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) + VALUES + (1, 'En reparto', 'ON DELIVERY'), + (2, 'Entregada', 'DELIVERED'), + (3, 'Perdida', 'LOST'); + + +INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, `created`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`, `hostFk`) + VALUES + (1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, 'UR9000006041', 94, 1, 'pc1'), + (2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 18, 'UR9000006041', 94, 1, NULL), + (3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 18, 'UR9000006041', 94, 2, NULL), + (4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 18, 'UR9000006041', 94, 2, NULL), + (5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 3, NULL), + (6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 18, NULL, 94, 3, NULL), + (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), + (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), + (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), + (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (13, 1, 10,71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); + + +INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) + VALUES + (1, util.VN_CURDATE(), 1, 1, 1), + (2, util.VN_CURDATE(), 2, 1, 1), + (3, util.VN_CURDATE(), 3, 1, 1), + (4, util.VN_CURDATE(), 3, 2, 1106), + (5, util.VN_CURDATE(), 5, 1, 1106), + (6, util.VN_CURDATE(), 5, 3, 1106); + +INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) + VALUES + (1, 1, 2, 2, util.VN_CURDATE(), NULL), + (2, 2, 2, 1, util.VN_CURDATE(), NULL), + (3, 3, 2, 4, util.VN_CURDATE(), NULL); + +INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`) + VALUES + (1, 1, 1, 'Ranged weapon longbow 2m', 5, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (2, 2, 1, 'Melee weapon combat fist 15cm', 10, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (3, 1, 1, 'Ranged weapon longbow 2m', 2, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (4, 4, 1, 'Melee weapon heavy shield 1x0.5m', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (5, 1, 2, 'Ranged weapon longbow 2m', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (6, 1, 3, 'Ranged weapon longbow 2m', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), + (7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.44, 0, 0, 0, util.VN_CURDATE()), + (8, 4, 11, 'Melee weapon heavy shield 1x0.5m', 10, 1.79, 0, 0, 0, util.VN_CURDATE()), + (9, 1, 16, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), + (10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, util.VN_CURDATE()), + (11, 1, 16, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), + (12, 4, 16, 'Melee weapon heavy shield 1x0.5m', 20, 1.71, 0, 0, 0, util.VN_CURDATE()), + (13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE()), + (14, 1, 8, 'Ranged weapon longbow 2m', 2, 103.49, 0, 0, 0, util.VN_CURDATE()), + (15, 1, 19, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), + (16, 2, 20, 'Melee weapon combat fist 15cm', 20, 7.07, 0, 0, 0, util.VN_CURDATE()), + (17, 2, 22, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), + (18, 4, 22, 'Melee weapon heavy shield 1x0.5m', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), + (19, 1, 4, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), + (20, 1, 5, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), + (21, 1, 6, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (22, 1, 7, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (23, 1, 9, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (24, 1, 10, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (25, 4, 12, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (26, 4, 13, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (27, 4, 14, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (28, 4, 15, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (29, 4, 17, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (30, 4, 18, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE()), + (32, 1, 24, 'Ranged weapon longbow 2m', -1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE()), + (34, 4, 28, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (35, 4, 29, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (37, 4, 31, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (36, 4, 30, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (38, 2, 32, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), + (39, 1, 32, 'Ranged weapon longbow 2m', 2, 103.49, 0, 0, 0, util.VN_CURDATE()); + +INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) + VALUES + (1, 28, 50), + (1, 29, 49.4), + (1, 39, 0.994), + (2, 28, 5), + (2, 29, 2), + (2, 39, 0.07), + (3, 28, 50), + (3, 29, 49.4), + (3, 39, 0.994), + (4, 28, 1.25), + (4, 29, 0.42), + (4, 39, 0.017), + (5, 17, 9.94), + (5, 28, 50), + (5, 29, 49.4), + (5, 39, 0.994), + (6, 17, 9.94), + (6, 28, 50), + (6, 29, 49.4), + (6, 39, 0.994), + (7, 15, 0.0199), + (7, 17, 0.35), + (7, 28, 5), + (7, 29, 2), + (7, 39, 0.07), + (8, 15, 0.0199), + (8, 17, 0.084), + (8, 28, 1.25), + (8, 29, 0.42), + (8, 39, 0.017), + (9, 15, 3.0949), + (9, 21, 0.001), + (9, 28, 53), + (9, 29, 46.4), + (9, 39, 0.994), + (10, 15, 0.0199), + (10, 28, 7), + (10, 29, 0), + (10, 39, 0.07), + (11, 15, 3.0949), + (11, 21, 0.001), + (11, 28, 53), + (11, 29, 46.4), + (11, 39, 0.994), + (12, 15, 0.0199), + (12, 21, 0.003), + (12, 28, 2.25), + (12, 29, -0.58), + (12, 39, 0.017), + (13, 15, 0.114), + (13, 28, 5), + (13, 29, 2), + (13, 39, 0.07), + (14, 15, 3.0949), + (14, 28, 50), + (14, 29, 49.4), + (14, 39, 0.994), + (15, 15, 3.0949), + (15, 28, 50), + (15, 29, 49.4), + (15, 39, 0.994), + (16, 28, 5), + (16, 29, 2), + (16, 39, 0.07), + (17, 28, 5), + (17, 29, 2), + (17, 39, 0.07), + (18, 28, 1.25), + (18, 29, 0.42), + (18, 39, 0.017), + (19, 17, 0.7), + (19, 22, 0.3), + (19, 28, 5), + (19, 29, 2), + (19, 39, 0.02), + (20, 17, 0.7), + (20, 22, 0.3), + (20, 28, 5), + (20, 29, 2), + (20, 39, 0.02), + (21, 17, 0.7), + (21, 22, 0.3), + (21, 28, 5), + (21, 29, 2), + (21, 39, 0.02), + (22, 17, 0.7), + (22, 22, 0.3), + (22, 28, 5), + (22, 29, 2), + (22, 39, 0.02), + (23, 17, 0.7), + (23, 22, 0.3), + (23, 28, 5), + (23, 29, 2), + (23, 39, 0.02), + (24, 17, 0.7), + (24, 22, 0.3), + (24, 28, 5), + (24, 29, 2), + (24, 39, 0.02), + (25, 17, 0.033), + (25, 28, 1.25), + (25, 29, 0.42), + (25, 39, 0.017), + (26, 17, 0.033), + (26, 28, 1.25), + (26, 29, 0.42), + (26, 39, 0.017), + (27, 17, 0.033), + (27, 28, 1.25), + (27, 29, 0.42), + (27, 39, 0.017), + (28, 17, 0.033), + (28, 28, 1.25), + (28, 29, 0.42), + (28, 39, 0.017), + (29, 17, 0.033), + (29, 28, 1.25), + (29, 29, 0.42), + (29, 39, 0.017), + (30, 17, 0.033), + (30, 28, 1.25), + (30, 29, 0.42), + (30, 39, 0.017), + (31, 28, 5), + (31, 29, 2), + (31, 36, 0.01), + (31, 39, 0.07), + (32, 28, 50), + (32, 29, 49.4), + (32, 36, -92.324), + (32, 39, 0.994); + +INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`, `userFk`) + VALUES + (2, 'GVC', 1, 1, 1, 1106), + (4, 'HEJ', 1, 1, 1, 1106), + (1, 'UXN', 2, 12, 12, 1106); + +INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) + VALUES + ('1', '1', '1', util.VN_CURDATE(), '1106'), + ('2', '2', '5', util.VN_CURDATE(), '1106'), + ('1', '7', '1', util.VN_CURDATE(), '1106'), + ('2', '8', '5', util.VN_CURDATE(), '1106'); + +INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `id`, `stateFk`) + VALUES + (1, 0, util.VN_CURDATE(), 5, 55, 1, 14), + (1, 1, util.VN_CURDATE(), 5, 54, 2, 8), + (2, 1, util.VN_CURDATE(), 10, 40, 3, 8), + (3, 1, util.VN_CURDATE(), 2, 40, 4, 8), + (31, 1, util.VN_CURDATE(), -5, 40, 5, 8); + +INSERT INTO `vn`.`itemBarcode`(`id`, `itemFk`, `code`) + VALUES + (1, 1, 1111111111), + (2, 1, 2222222222), + (3, 1, 3333333333), + (4, 2, 4444444444); + +INSERT INTO `vn`.`train`(`id`, `name`) + VALUES + (1, 'Train1'), + (2, 'Train2'); + +INSERT INTO `vn`.`operator` (`workerFk`, `numberOfWagons`, `trainFk`, `itemPackingTypeFk`, `warehouseFk`, `sectorFk`, `labelerFk`) + VALUES + ('1106', '1', '1', 'H', '1', '1', '1'), + ('1107', '1', '1', 'V', '1', '1', '1'); + +INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`) + VALUES + (1, 1106, 5, DATE_ADD(util.VN_CURDATE(),INTERVAL +1 DAY), 1), + (2, 1106, 14, util.VN_CURDATE(), 1); + +INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) + VALUES + (1, 1, 1), + (2, 1, NULL), + (3, 2, NULL), + (23, 1, NULL); + +INSERT INTO `vn`.`genus`(`id`, `name`) + VALUES + (1, 'Abelia'), + (2, 'Abies'), + (3, 'Abutilon'); + +INSERT INTO `vn`.`specie`(`id`, `name`) + VALUES + (1, 'grandiflora'), + (2, 'procera'), + (3, 'decurrens'), + (4, 'dealbata'); + +INSERT INTO `vn`.`itemBotanical`(`itemFk`, `genusFk`, `specieFk`) + VALUES + (1, 1, 1), + (2, 2, 2), + (3, 2, NULL), + (4, 2, 1); + +INSERT INTO `vn`.`tag`(`id`, `code`, `name`, `isFree`, `isQuantitatif`, `sourceTable`, `unit`, `ediTypeFk`, `overwrite`) + VALUES + (1, 'color', 'Color', 0, 0, 'ink', NULL, NULL, 'inkFk'), + (2, NULL, 'Forma', 1, 0, NULL, NULL,NULL, NULL), + (3, NULL, 'Material', 1, 0, NULL, NULL,NULL, NULL), + (4, NULL, 'Longitud', 1, 1, NULL, 'mm', NULL, 'size'), + (5, NULL, 'Diámetro', 1, 1, NULL, 'mm',NULL, 'diameter'), + (7, NULL, 'Ancho de la base', 1, 1, NULL, 'mm',NULL, NULL), + (23, 'stems', 'Tallos', 1, 1, NULL, NULL, NULL, 'stems'), + (27, NULL, 'Longitud(cm)', 1, 1, NULL, 'cm', NULL, NULL), + (36, 'producer', 'Proveedor', 1, 0, NULL, NULL, NULL, 'producer'), + (56, NULL, 'Genero', 1, 0, NULL, NULL, NULL, NULL), + (58, NULL, 'Variedad', 1, 0, NULL, NULL, NULL, NULL), + (67, 'category', 'Categoria', 1, 0, NULL, NULL, NULL, NULL), + (92, NULL, 'Nombre temporal', 1, 0, NULL, NULL, NULL, NULL); + +INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`) + VALUES + (1, 1, 56, 'Ranged weapon', 1), + (2, 1, 58, 'longbow', 2), + (3, 1, 27, '2m', 3), + (4, 1, 36, 'Stark Industries', 4), + (5, 1, 1, 'Brown', 5), + (6, 1, 67, '+1 precission', 6), + (7, 1, 23, '1', 7), + (8, 2, 56, 'Melee weapon', 1), + (9, 2, 58, 'combat fist', 2), + (10, 2, 27, '15cm', 3), + (11, 2, 36, 'Stark Industries', 4), + (12, 2, 1, 'Silver', 5), + (13, 2, 67, 'Concussion', 6), + (14, 2, 23, '2', 7), + (15, 3, 56, 'Ranged weapon', 1), + (16, 3, 58, 'sniper rifle', 2), + (17, 3, 4, '300mm', 3), + (18, 3, 36, 'Stark Industries', 4), + (19, 3, 1, 'Green', 5), + (20, 3, 67, 'precission', 6), + (21, 3, 23, '3', 7), + (22, 4, 56, 'Melee weapon', 1), + (23, 4, 58, 'heavy shield', 2), + (24, 4, 4, '1x0.5m', 3), + (25, 4, 36, 'Stark Industries', 4), + (26, 4, 1, 'Black', 5), + (27, 4, 67, 'containtment', 6), + (28, 4, 23, '4', 7), + (29, 5, 56, 'Ranged weapon', 1), + (30, 5, 58, 'pistol', 2), + (31, 5, 27, '9mm', 3), + (32, 5, 36, 'Stark Industries', 4), + (33, 5, 1, 'Silver', 5), + (34, 5, 67, 'rapid fire', 6), + (35, 5, 23, '5', 7), + (36, 6, 56, 'Container', 1), + (37, 6, 58, 'ammo box', 2), + (38, 6, 27, '1m', 3), + (39, 6, 36, 'Stark Industries', 4), + (40, 6, 1, 'Green', 5), + (41, 6, 67, 'supply', 6), + (42, 6, 23, '6', 7), + (43, 7, 56, 'Container', 1), + (44, 7, 58, 'medical box', 2), + (45, 7, 27, '1m', 3), + (46, 7, 36, 'Stark Industries', 4), + (47, 7, 1, 'White', 5), + (48, 7, 67, 'supply', 6), + (49, 7, 23, '7', 7), + (50, 8, 56, 'Ranged Reinforced weapon', 1), + (51, 8, 58, '+1 longbow', 2), + (52, 8, 27, '2m', 3), + (53, 8, 36, 'Stark Industries', 4), + (54, 8, 1, 'Brown', 5), + (55, 8, 67, 'precission', 6), + (56, 8, 23, '8', 7), + (57, 9, 56, 'Melee Reinforced weapon', 1), + (58, 9, 58, 'combat fist', 2), + (59, 9, 27, '15cm', 3), + (60, 9, 36, 'Stark Industries', 4), + (61, 9, 1, 'Silver', 5), + (62, 9, 67, 'Concussion', 6), + (63, 9, 23, '9', 7), + (64, 10, 56, 'Ranged Reinforced weapon', 1), + (65, 10, 58, 'sniper rifle', 2), + (66, 10, 4, '300mm', 3), + (67, 10, 36, 'Stark Industries', 4), + (68, 10, 1, 'Green', 5), + (69, 10, 67, 'precission', 6), + (70, 10, 23, '10', 7), + (71, 11, 56, 'Melee Reinforced weapon', 1), + (72, 11, 58, 'heavy shield', 2), + (73, 11, 4, '1x0.5m', 3), + (74, 11, 36, 'Stark Industries', 4), + (75, 11, 1, 'Black', 5), + (76, 11, 67, 'containtment', 6), + (77, 11, 23, '11', 7), + (78, 12, 56, 'Ranged Reinforced weapon', 1), + (79, 12, 58, 'pistol', 2), + (80, 12, 27, '9mm', 3), + (81, 12, 36, 'Stark Industries', 4), + (82, 12, 1, 'Silver', 5), + (83, 12, 67, 'rapid fire', 6), + (84, 12, 23, '12', 7), + (85, 13, 56, 'Chest', 1), + (86, 13, 58, 'ammo box', 2), + (87, 13, 27, '1m', 3), + (88, 13, 36, 'Stark Industries', 4), + (89, 13, 1, 'Green', 5), + (90, 13, 67, 'supply', 6), + (91, 13, 23, '13', 7), + (92, 14, 56, 'Chest', 1), + (93, 14, 58, 'medical box', 2), + (94, 14, 27, '1m', 3), + (95, 14, 36, 'Stark Industries', 4), + (96, 14, 1, 'White', 5), + (97, 14, 67, 'supply', 6), + (98, 14, 23, '1', 7), + (99, 15, 92, 'Trolley', 2), + (100, 16, 92, 'Pallet', 2), + (101, 71, 92, 'Shipping cost', 2); + +INSERT INTO `vn`.`itemTypeTag`(`id`, `itemTypeFk`, `tagFk`, `priority`) + VALUES + (1, 1, 1, 0), + (2, 2, 2, 0), + (3, 3, 3, 0), + (4, 1, 4, 4), + (5, 1, 5, 5); + +CALL `vn`.`itemRefreshTags`(NULL); + +INSERT INTO `vn`.`itemLog` (`id`, `originFk`, `userFk`, `action`, `description`, `changedModel`, `oldInstance`, `newInstance`, `changedModelId`, `changedModelValue`) + VALUES + ('1', '1', '1', 'insert', 'We made a change!', 'Item', '{}', '{}', 1, '1'); + +INSERT INTO `vn`.`recovery`(`id`, `clientFk`, `started`, `finished`, `amount`, `period`) + VALUES + (1, 1101, DATE_ADD(util.VN_CURDATE(),INTERVAL -7 MONTH), DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), 50, 7), + (2, 1102, DATE_ADD(util.VN_CURDATE(),INTERVAL -5 MONTH), util.VN_CURDATE(), 100, 1), + (3, 1102, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(),INTERVAL 1 MONTH), 50, 7), + (4, 1103, util.VN_CURDATE(), NULL, 50, 7); + +INSERT INTO `bs`.`clientAnnualConsumption`(`clientFk`, `invoiced`) + VALUES + (1101, 1500), + (1102, 100), + (1103, 1000), + (1104, 500), + (1105, 5000); + +INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`) + VALUES + (1, 2, 'available', CONCAT_WS('/',1,util.VN_CURDATE()), util.VN_NOW(), DATE_ADD(util.VN_NOW(),INTERVAL 15 MINUTE), util.VN_CURDATE(), NULL), + (2, 4, 'last_buy', CONCAT_WS('/',1,util.VN_CURDATE()), util.VN_NOW(), DATE_ADD(util.VN_NOW(),INTERVAL 15 MINUTE), util.VN_CURDATE(), NULL), + (3, 8, 'visible', CONCAT_WS('/',1,util.VN_CURDATE()), util.VN_NOW(), DATE_ADD(util.VN_NOW(),INTERVAL 15 MINUTE), util.VN_CURDATE(), NULL); + +INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) + VALUES + (1, 0), + (2, 1), + (3, 2), + (4, 4), + (5, 6), + (15, 6); + +INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`) + VALUES + (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1), + (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2), + (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1), + (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2), + (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1), + (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2); + +INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) + VALUES + (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 1', 0, 0, ''), + (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'IN2002', 'Movement 2', 0, 0, 'observation two'), + (3, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 0, 442, 'IN2003', 'Movement 3', 0, 0, 'observation three'), + (4, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'IN2004', 'Movement 4', 0, 0, 'observation four'), + (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 0, 'observation five'), + (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 0, 'observation six'), + (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'), + (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''); + +INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWaste`, `rate`) + VALUES + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation', 1, 1, '1062', '51', '4.8'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Colombia', 2, 1, '35074', '687', '2.0'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Mini', 3, 1, '1777', '13', '0.7'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Short', 4, 1, '3182', '59', '0.6'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Crisantemo', 5, 1, '1747', '13', '0.7'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Lilium Oriental', 6, 1, '7182', '59', '0.6'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Alstroemeria', 7, 1, '1777', '13', '0.7'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Cymbidium', 1, 1, '4181', '59', '0.6'), + ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Cymbidium', 2, 1, '7268', '59', '0.6'), + ('DavidCharlesHaller', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Containers', 2, 1, '-74', '0', '0.0'), + ('DavidCharlesHaller', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Packagings', 3, 1, '-7', '0', '0.0'), + ('DavidCharlesHaller', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Freight', 4, 1, '1100', '0', '0.0'), + ('HankPym', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Funeral Accessories', 5, 1, '848', '-187', '-22.1'), + ('HankPym', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Miscellaneous Accessories', 6, 1, '186', '0', '0.0'), + ('HankPym', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Adhesives', 7, 1, '277', '0', '0.0'); + +INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagingFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`, `printedStickers`,`isChecked`,`isIgnored`,`weight`, `created`) + VALUES + (1, 1, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), + (2, 2, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (3, 3, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 0, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE()), + (4, 2, 2, 5, 450, 3, 1, 1.000, 1.000, 0.000, 10, 10, 0, NULL, 0.00, 7.30, 7.00, 0, 1, 0, 2.5, util.VN_CURDATE()), + (5, 3, 3, 55, 500, 5, 1, 1.000, 1.000, 0.000, 1, 1, 0, NULL, 0.00, 78.3, 75.6, 0, 1, 0, 2.5, util.VN_CURDATE()), + (6, 4, 8, 50, 1000, 4, 1, 1.000, 1.000, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 2.5, util.VN_CURDATE()), + (7, 4, 9, 20, 1000, 3, 1, 0.500, 0.500, 0.000, 10, 10, 1, NULL, 0.00, 30.50, 29.00, 0, 1, 0, 2.5, util.VN_CURDATE()), + (8, 4, 4, 1.25, 1000, 3, 1, 0.500, 0.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 2.5, util.VN_CURDATE()), + (9, 4, 4, 1.25, 1000, 3, 1, 0.500, 0.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), + (10, 5, 1, 50, 10, 4, 1, 2.500, 2.500, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), + (11, 5, 4, 1.25, 10, 3, 1, 2.500, 2.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), + (12, 6, 4, 1.25, 0, 3, 1, 2.500, 2.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), + (13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), + (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), + (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()); + +INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) + VALUES + (1, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 3, 1, 121, 442, NULL, 'TPV', 1,'155.89', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (2, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1104, 3, 1, 124, 442, NULL, 'WEB', 1,'100.10', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (3, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 1, 2, 124, 442, NULL, 'ANDROID', 1,'107.25', DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), + (4, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 1, 2, 124, 442, NULL, 'SALIX', 1,'10.01', DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), + (5, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 1, 3, 124, 442, NULL, 'SALIX', 1,'10.01', DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), + (6, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 1, 3, 1, 442, NULL, 'SALIX', 1,'10.01', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 2, 7, 1, 442, NULL, 'SALIX', 0,'10.01', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 2, 7, 121, 442, NULL, 'SALIX', 0,'123.53', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (9, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 2, 7, 124, 442, NULL, 'SALIX', 0,'10.01', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (10, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 3, 1, 2, 442, NULL, 'SALIX', 0,'10.01', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (11, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 2, 7, 122, 442, NULL, 'SALIX', 0,'60.90', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (12, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 3, 1, 3, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (13, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 1, 2, 123, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (14, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 1, 2, 4, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (15, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 1, 3, 125, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (16, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 2, 7, 126, 442, NULL, 'SALIX', 0,'155.89', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (17, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1107, 1, 4, 127, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (18, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 1, 4, 128, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (19, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 1, 5, 129, 442, NULL, 'SALIX', 0,'16.50', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), + (20, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 1, 5, 101, 442, NULL, 'SALIX', 0,'21.45', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), + (21, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 1, 5, 102, 442, NULL, 'SALIX', 0,'0.00', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), + (22, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 1, 5, 103, 442, NULL, 'SALIX', 0,'148.50', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)); + +INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`) + VALUES + (1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1), + (2, 1, 2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 10, 1.07, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2), + (3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3), + (4, 1, 4, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 20, 3.06, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4), + (5, 2, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 10, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5), + (6, 3, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 15, 6.50, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 6), + (7, 11, 2, 1, util.VN_CURDATE(), 15, 1.30, 0, util.VN_CURDATE(), 7), + (8, 11, 4, 1, util.VN_CURDATE(), 10, 3.26, 0, util.VN_CURDATE(), 8), + (9, 16, 1, 1, util.VN_CURDATE(), 5, 9.10, 0, util.VN_CURDATE(), 9), + (10, 16, 2, 1, util.VN_CURDATE(), 10, 1.07, 0, util.VN_CURDATE(), 10), + (11, 16, 1, 1, util.VN_CURDATE(), 2, 9.10, 0, util.VN_CURDATE(), 11), + (12, 16, 4, 1, util.VN_CURDATE(), 20, 3.06, 0, util.VN_CURDATE(), 12), + (13, 8, 2, 1, util.VN_CURDATE(), 15, 1.30, 0, util.VN_CURDATE(), 13), + (14, 8, 1, 1, util.VN_CURDATE(), 10, 9.28, 0, util.VN_CURDATE(), 14), + (15, 19, 1, 1, util.VN_CURDATE(), 10, 1.50, 0, util.VN_CURDATE(), 15), + (16, 20, 2, 1, util.VN_CURDATE(), 15, 1.30, 0, util.VN_CURDATE(), 16), + (17, 22, 2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 30, 2.30, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 17), + (18, 22, 4, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 20, 3.00, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 18), + (19, 4, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 19), + (20, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 20), + (21, 6, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 21), + (22, 7, 1, 1, util.VN_CURDATE(), 1, 9.10, 0, util.VN_CURDATE(), 22), + (23, 9, 1, 1, util.VN_CURDATE(), 1, 9.10, 0, util.VN_CURDATE(), 23), + (24, 10, 1, 1, util.VN_CURDATE(), 1, 9.10, 0, util.VN_CURDATE(), 24), + (25, 12, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 25), + (26, 13, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 26), + (27, 14, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 27), + (28, 15, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 28), + (29, 17, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 29), + (30, 18, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 30); + +INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`) + VALUES + (1, 15, 0.58), + (1, 23, 6.5), + (1, 28, 20.72), + (1, 29, -18.72), + (1, 39, 0.02), + (2, 15, 0.058), + (2, 21, 0.002), + (2, 28, 5.6), + (2, 29, -4.6), + (2, 39, 0.01), + (3, 15, 0.58), + (3, 23, 6.5), + (3, 28, 20.72), + (3, 29, -18.72), + (3, 39, 0.02), + (4, 15, 0.051), + (4, 21, -0.001), + (4, 28, 20.72), + (4, 29, -19.72), + (4, 37, 2), + (4, 39, 0.01), + (5, 15, 0.58), + (5, 23, 6.5), + (5, 28, 20.72), + (5, 29, -18.72), + (5, 39, 0.02), + (6, 23, 6.5), + (7, 15, 0.0114), + (7, 28, 5.6), + (7, 29, -4.6), + (7, 39, 0.01), + (8, 15, 0.0016), + (8, 28, 20.72), + (8, 29, -19.72), + (8, 37, 2), + (8, 39, 0.01), + (9, 15, 0.58), + (9, 23, 6.5), + (9, 28, 20.72), + (9, 29, -18.72), + (9, 39, 0.02), + (10, 15, 0.058), + (10, 21, 0.002), + (10, 28, 5.6), + (10, 29, -4.6), + (10, 39, 0.01), + (11, 15, 0.58), + (11, 23, 6.5), + (11, 28, 20.72), + (11, 29, -18.72), + (11, 39, 0.02), + (12, 15, 0.051), + (12, 22, -0.001), + (12, 28, 20.72), + (12, 29, -19.72), + (12, 37, 2), + (12, 39, 0.01), + (13, 15, 0.2899), + (13, 28, 5.6), + (13, 29, -4.6), + (13, 39, 0.01), + (14, 15, 0.58), + (14, 23, 6.5), + (14, 28, 20.72), + (14, 29, -18.72), + (14, 39, 0.02), + (15, 15, 0.58), + (15, 23, 6.5), + (15, 28, 20.72), + (15, 29, -18.72), + (15, 39, 0.02), + (16, 15, 0.058), + (16, 21, 0.002), + (16, 28, 5.6), + (16, 29, -4.6), + (16, 39, 0.01), + (17, 15, 0.058), + (17, 21, 0.002), + (17, 28, 5.6), + (17, 29, -4.6), + (17, 39, 0.01), + (18, 15, 0.051), + (18, 22, -0.001), + (18, 28, 20.72), + (18, 29, -19.72), + (18, 37, 2), + (18, 39, 0.01), + (19, 15, 0.58), + (19, 23, 6.5), + (19, 28, 20.72), + (19, 29, -18.72), + (19, 39, 0.02), + (20, 15, 0.58), + (20, 23, 6.5), + (20, 28, 20.72), + (20, 29, -18.72), + (20, 39, 0.02), + (21, 15, 0.58), + (21, 23, 6.5), + (21, 28, 20.72), + (21, 29, -18.72), + (21, 39, 0.02), + (22, 15, 0.58), + (22, 23, 6.5), + (22, 28, 20.72), + (22, 29, -18.72), + (22, 39, 0.02), + (23, 15, 0.58), + (23, 23, 6.5), + (23, 28, 20.72), + (23, 29, -18.72), + (23, 39, 0.02), + (24, 15, 0.58), + (24, 23, 6.5), + (24, 28, 20.72), + (24, 29, -18.72), + (24, 39, 0.02), + (25, 15, 0.051), + (25, 22, -0.001), + (25, 28, 20.72), + (25, 29, -19.72), + (25, 37, 2), + (25, 39, 0.01), + (26, 15, 0.051), + (26, 22, -0.001), + (26, 28, 20.72), + (26, 29, -19.72), + (26, 37, 2), + (26, 39, 0.01), + (27, 15, 0.051), + (27, 22, -0.001), + (27, 28, 20.72), + (27, 29, -19.72), + (27, 37, 2), + (27, 39, 0.01), + (28, 15, 0.051), + (28, 22, -0.001), + (28, 28, 20.72), + (28, 29, -19.72), + (28, 37, 2), + (28, 39, 0.01), + (29, 15, 0.051), + (29, 22, -0.001), + (29, 28, 20.72), + (29, 29, -19.72), + (29, 37, 2), + (29, 39, 0.01), + (30, 15, 0.051), + (30, 22, -0.001), + (30, 28, 20.72), + (30, 29, -19.72), + (30, 37, 2), + (30, 39, 0.01); + +INSERT INTO `hedera`.`visit`(`id`, `firstAgentFk`) + VALUES + (1, NULL), + (2, NULL), + (3, NULL), + (4, NULL), + (5, NULL), + (6, NULL), + (7, NULL), + (8, NULL), + (9, NULL), + (10, NULL), + (11, NULL); + +INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`) + VALUES + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, 5), + (6, 6), + (7, 7), + (8, 8), + (9, 9), + (10, 10), + (11, 11); + +INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`) + VALUES + (1, 1, util.VN_CURDATE()), + (2, 2, util.VN_CURDATE()), + (3, 3, util.VN_CURDATE()), + (4, 4, util.VN_CURDATE()), + (5, 5, util.VN_CURDATE()), + (6, 6, util.VN_CURDATE()), + (7, 7, util.VN_CURDATE()), + (8, 8, util.VN_CURDATE()), + (9, 9, util.VN_CURDATE()), + (10, 10, util.VN_CURDATE()), + (11, 11, util.VN_CURDATE()); + +INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`) + VALUES + (1, 1, 1101, util.VN_CURDATE()), + (2, 2, 1101, util.VN_CURDATE()), + (3, 3, 1101, util.VN_CURDATE()), + (4, 4, 1102, util.VN_CURDATE()), + (5, 5, 1102, util.VN_CURDATE()), + (6, 6, 1102, util.VN_CURDATE()), + (7, 7, 1103, util.VN_CURDATE()), + (8, 8, 1103, util.VN_CURDATE()), + (9, 9, 1103, util.VN_CURDATE()), + (10, 10, 1102, DATE_SUB(util.VN_CURDATE(), INTERVAL 1 DAY)), + (11, 11, 1103, DATE_SUB(util.VN_CURDATE(), INTERVAL 1 DAY)); + +INSERT INTO `hedera`.`userSession`(`created`, `lastUpdate`, `ssid`, `data`, `userVisitFk`) + VALUES + (util.VN_CURDATE(), util.VN_CURDATE(), '121', 'data', 1), + (util.VN_CURDATE(), util.VN_CURDATE(), '122', 'data', 2), + (util.VN_CURDATE(), util.VN_CURDATE(), '123', 'data', 3), + (util.VN_CURDATE(), util.VN_CURDATE(), '124', 'data', 4), + (util.VN_CURDATE(), util.VN_CURDATE(), '125', 'data', 5), + (util.VN_CURDATE(), util.VN_CURDATE(), '126', 'data', 6), + (util.VN_CURDATE(), util.VN_CURDATE(), '127', 'data', 7), + (util.VN_CURDATE(), util.VN_CURDATE(), '128', 'data', 8), + (util.VN_CURDATE(), util.VN_CURDATE(), '129', 'data', 9); + +INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`) + VALUES + (1, 1101, 'contact 1', 666777888), + (2, 1101, 'contact 2', 111222333), + (3, 1101, 'contact 3', 222333444), + (4, 1102, 'contact 1', 876543219); + +INSERT INTO `vn`.`workerManaExcluded`(`workerFk`) + VALUES + (9); +/* + el mana de los trabajadores lo podemos poner a mano en la tabla si lo calculamos antes, + pero si hazemos alguna modificacion en alguna tabla que utiliza para calcularlo ya no seria correcto + + La otra manera es poner el calculo con los 2 trabajadores que utilizamos ahora mismo para los tickets +*/ + +call vn.manaSpellersRequery(19); +call vn.manaSpellersRequery(18); + +INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk`, `userFk`, `companyFk`) + VALUES + (1, 1101, 1, util.VN_CURDATE(), 18, 18, 442), + (2, 1101, 1, util.VN_CURDATE(), 18, 18, 442), + (3, 1101, 2, util.VN_CURDATE(), 18, 18, 442), + (4, 1102, 2, util.VN_CURDATE(), 18, 18, 567), + (5, 1102, 3, util.VN_CURDATE(), 19, 19, 567); + +INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`, `hasToNotify`) + VALUES + ( 1, 'pending', 'Pendiente', 1, 1, 0), + ( 2, 'managed', 'Gestionado', 72, 5, 0), + ( 3, 'resolved', 'Resuelto', 72, 7, 0), + ( 4, 'canceled', 'Anulado', 72, 6, 1), + ( 5, 'incomplete', 'Incompleta', 1, 3, 1), + ( 6, 'mana', 'Mana', 72, 4, 0), + ( 7, 'lack', 'Faltas', 72, 2, 0); + +INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`, `ticketFk`) + VALUES + (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183', 11), + (2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL, 16), + (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL, 7), + (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL, 8); + +INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) + VALUES + (1, 18, 'Cu nam labores lobortis definiebas, ei aliquyam salutatus persequeris quo, cum eu nemore fierent dissentiunt. Per vero dolor id, vide democritum scribentur eu vim, pri erroribus temporibus ex.', util.VN_CURDATE()), + (2, 18, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', util.VN_CURDATE()), + (3, 18, 'An vim commodo dolorem volutpat, cu expetendis voluptatum usu, et mutat consul adversarium his. His natum numquam legimus an, diam fabulas mei ut. Melius fabellas sadipscing vel id. Partem diceret mandamus mea ne, has te tempor nostrud. Aeque nostro eum no.', util.VN_CURDATE()), + (4, 18, 'Wisi forensibus mnesarchum in cum. Per id impetus abhorreant, his no magna definiebas, inani rationibus in quo. Ut vidisse dolores est, ut quis nominavi mel. Ad pri quod apeirian concludaturque.', util.VN_CURDATE()); + +INSERT INTO `vn`.`claimBeginning`(`id`, `claimFk`, `saleFk`, `quantity`) + VALUES + (1, 1, 7, 5), + (2, 2, 10, 10), + (3, 3, 22, 1), + (4, 4, 13, 5); + +INSERT INTO `vn`.`claimDestination`(`id`, `description`, `addressFk`) + VALUES + (1, 'Bueno', NULL), + (2, 'Basura/Perd.', 12), + (3, 'Confeccion', NULL), + (4, 'Reclam.PRAG', 12), + (5, 'Corregido', 11); + +INSERT INTO `vn`.`claimDevelopment`(`id`, `claimFk`, `claimResponsibleFk`, `workerFk`, `claimReasonFk`, `claimResultFk`, `claimRedeliveryFk`, `claimDestinationFk`) + VALUES + (1, 1, 1, 21, 1, 1, 2, 5), + (2, 1, 2, 21, 7, 2, 2, 5), + (3, 2, 7, 21, 9, 3, 2, 5), + (4, 3, 7, 21, 15, 8, 2, 5), + (5, 4, 7, 21, 7, 8, 2, 5); + +INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestinationFk`) + VALUES + (1, 31, 4, 21, 2), + (2, 32, 3, 21, 3); + +INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`) + VALUES + (1, 50), + (2, 30); + +INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`) + VALUES + (1101, 500, NULL, 0.00, 0.00, 1.00), + (1102, 1000, 2.00, 0.01, 0.05, 1.00), + (1103, 2000, 0.00, 0.00, 0.02, 1.00), + (1104, 2500, 150.00, 0.02, 0.10, 1.00); + +INSERT INTO vn.claimRma (`id`, `code`, `created`, `workerFk`) + VALUES + (1, '02676A049183', DEFAULT, 1106), + (2, '02676A049183', DEFAULT, 1106), + (3, '02676A049183', DEFAULT, 1107), + (4, '02676A049183', DEFAULT, 1107), + (5, '01837B023653', DEFAULT, 1106); + +INSERT INTO `vn`.`claimLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`) + VALUES + (1, 18, 'update', 'Claim', '{"hasToPickUp":false}', '{"hasToPickUp":true}', 1, NULL), + (1, 18, 'update', 'ClaimObservation', '{}', '{"claimFk":1,"text":"Waiting for customer"}', 1, NULL), + (1, 18, 'insert', 'ClaimBeginning', '{}', '{"claimFk":1,"saleFk":1,"quantity":10}', 1, NULL), + (1, 18, 'insert', 'ClaimDms', '{}', '{"claimFk":1,"dmsFk":1}', 1, NULL); + +INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`) + VALUES + (1, 'Arkham Bank', 442, 1, 'h12387193H10238'), + (2, 'NewYork Bank', 442, 1, '7981ugsgd1hsdad'); + +INSERT INTO `hedera`.`tpvTransaction`(`id`,`merchantFk`, `clientFk`,`receiptFk`, `amount`, `response`, `errorCode`, `status`, `created`) + VALUES + (1, 1, 1101, NULL, 2000, NULL, 'SIS0042', 'ok', util.VN_CURDATE()), + (2, 1, 1101, NULL, 1000, NULL, 'SIS0051', 'started', util.VN_CURDATE()), + (3, 2, 1101, NULL, 7268, NULL, NULL, 'ok', util.VN_CURDATE()), + (4, 2, 1101, NULL, 4698, NULL, NULL, 'started', util.VN_CURDATE()), + (5, 1, 1104, NULL, 2000, NULL, 'SIS0043', 'ok', util.VN_CURDATE()), + (6, 2, 1104, NULL, 4000, NULL, 'SIS0044', 'started', util.VN_CURDATE()); + +INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`) + VALUES + (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, 5), + (6, 6), + (7, 7), + (8, 8), + (9, 9), + (10, 10), + (11, 11), + (12, 12), + (13, 13), + (14, 14), + (15, 15), + (16, 16), + (17, 17), + (18, 18), + (19, 19), + (20, 20), + (21, 21), + (22, 22); + +INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`) + VALUES + (1, 1, 69), + (5, 1, 442), + (9, 1, 442), + (18, 3, 567); + +INSERT INTO `vn`.`receipt`(`id`, `invoiceFk`, `amountPaid`, `payed`, `workerFk`, `bankFk`, `clientFk`, `created`, `companyFk`, `isConciliate`) + VALUES + (1, 'Cobro web', 100.50, util.VN_CURDATE(), 9, 1, 1101, util.VN_CURDATE(), 442, 1), + (2, 'Cobro web', 200.50, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), 9, 1, 1101, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), 442, 1), + (3, 'Cobro en efectivo', 300.00, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), 9, 1, 1102, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), 442, 0), + (4, 'Cobro en efectivo', 400.00, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 9, 1, 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 442, 0), + (5, 'Compensación', 400.00, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 9, 3, 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 442, 0); + +INSERT INTO `vn`.`workerTeam`(`id`, `team`, `workerFk`) + VALUES + (1, 1, 9), + (2, 2, 18), + (3, 2, 19), + (4, 3, 1101), + (5, 3, 1102), + (6, 4, 1103), + (7, 4, 1104); + +INSERT INTO `vn`.`ticketRequest`(`id`, `description`, `requesterFk`, `attenderFk`, `quantity`, `itemFk`, `price`, `isOk`, `saleFk`, `ticketFk`, `created`) + VALUES + (1, 'Ranged weapon longbow 2m', 18, 35, 5, 1, 9.10, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), + (2, 'Melee weapon combat first 15cm', 18, 35, 10, 2, 1.07, 0, NULL, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), + (3, 'Melee weapon heavy shield 1x0.5m', 18, 35, 20, NULL, 3.06, NULL, NULL, 23, util.VN_CURDATE()), + (4, 'Melee weapon combat first 15cm', 18, 35, 15, NULL, 1.30, NULL, NULL, 11, util.VN_CURDATE()), + (5, 'Melee weapon combat first 15cm', 18, 35, 15, 4, 1.30, 0, NULL, 18, util.VN_CURDATE()); + +INSERT INTO `vn`.`ticketServiceType`(`id`, `name`, `expenseFk`) + VALUES + (1, 'Porte Agencia', 7001000000), + (2, 'Portes Retorno', 7001000000), + (3, 'Porte Carry', 7001000000), + (4, 'Cargo FITOSANITARIO', 4751000000), + (5, 'Documentos', 2000000000); + +INSERT INTO `vn`.`ticketService`(`id`, `description`, `quantity`, `price`, `taxClassFk`, `ticketFk`, `ticketServiceTypeFk`) + VALUES + (1, 'Documentos', 1, 2.00, 1, 1, 1), + (2, 'Porte Agencia', 1, 10.00, 1, 2, 1), + (3, 'Documentos', 1, 5.50, 1, 11, 1), + (4, 'Documentos', 1, 2.00, 1, 9, 1), + (5, 'Documentos', 1, 2.00, 1, 8, 1); + +INSERT INTO `pbx`.`sip`(`user_id`, `extension`) + VALUES + (1, 1010), + (3, 1101), + (5, 1102), + (9, 1201); + +INSERT INTO `vn`.`professionalCategory` (`id`, `name`, `level`, `dayBreak`) + VALUES + (1, 'employee', NULL, NULL), + (2, 'florist', NULL, NULL); + +INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) + VALUES + (1, 'General schedule', 40, 0); + + +DROP TEMPORARY TABLE IF EXISTS tmp.worker; +CREATE TEMPORARY TABLE tmp.worker + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT w.id, w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-25') as started, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)), '-12-25') as ended, CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` + FROM `vn`.`worker` `w`; + +INSERT INTO `vn`.`business`(`id`, `workerFk`, `companyCodeFk`, `started`, `ended`, `workerBusiness`, `reasonEndFk`, `notes`, `departmentFk`, `workerBusinessProfessionalCategoryFk`, `calendarTypeFk`, `isHourlyLabor`, `workerBusinessAgreementFk`, `workcenterFk`) + SELECT * FROM tmp.worker; + +DROP TEMPORARY TABLE IF EXISTS tmp.worker; +CREATE TEMPORARY TABLE tmp.worker + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT '1111' as 'id', w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-12-25') as started, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-24') as ended, CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` + FROM `vn`.`worker` `w` + WHERE `w`.`id` = 1109; + +INSERT INTO `vn`.`business` (`id`, `workerFk`, `companyCodeFk`, `started`, `ended`, `workerBusiness`, `reasonEndFk`, `notes`, `departmentFk`, `workerBusinessProfessionalCategoryFk`, `calendarTypeFk`, `isHourlyLabor`, `workerBusinessAgreementFk`, `workcenterFk`) + SELECT * FROM tmp.worker; + +DROP TEMPORARY TABLE IF EXISTS tmp.worker; + +UPDATE `vn`.`business` + SET `payedHolidays`= 8 + WHERE `id`= 1106; + +UPDATE `vn`.`business` b + SET b.`workerBusinessProfessionalCategoryFk` = 2 + WHERE b.`workerFk` = 1110; + +UPDATE `vn`.`business` b + SET b.`departmentFk` = 43 + WHERE b.id IN(18, 19); + +INSERT INTO `vn`.`workCenterHoliday` (`workCenterFk`, `days`, `year`) + VALUES + ('1', '27.5', YEAR(util.VN_CURDATE())), + ('5', '22', YEAR(util.VN_CURDATE())), + ('1', '24.5', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR))), + ('5', '23', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR))); + +INSERT INTO `vn`.`workerBusinessType` (`id`, `name`, `isFullTime`, `isPermanent`, `hasHolidayEntitlement`) + VALUES + (1, 'CONTRATO HOLANDA', 1, 0, 1), + (100, 'INDEFINIDO A TIEMPO COMPLETO', 1, 1, 1), + (109, 'CONVERSION DE TEMPORAL EN INDEFINIDO T.COMPLETO', 1, 1, 1); + +UPDATE `vn`.`business` b + SET `rate` = 7, + `workerBusinessTypeFk` = 100, + `amount` = 900.50 + WHERE b.id = 1; + +UPDATE `vn`.`business` b + SET `rate` = 7, + `workerBusinessTypeFk` = 100, + `amount` = 1263.03 + WHERE b.id = 1106; + +UPDATE `vn`.`business` b + SET `rate` = 7, + `workerBusinessTypeFk` = 100, + `amount` = 2000 + WHERE b.id = 1107; + +UPDATE `vn`.`business` b + SET `rate` = 7, + `workerBusinessTypeFk` = 100, + `amount` = 1500 + WHERE b.id = 1108; + +INSERT INTO `vn`.`absenceType` (`id`, `name`, `rgb`, `code`, `holidayEntitlementRate`, `discountRate`) + VALUES + (1, 'Holidays', '#FF4444', 'holiday', 0, 0), + (2, 'Leave of absence', '#C71585', 'absence', 0, 1), + (6, 'Half holiday', '#E65F00', 'halfHoliday', 0, 0.5), + (15, 'Half Paid Leave', '#5151c0', 'halfPaidLeave', 0, 1), + (20, 'Furlough', '#97B92F', 'furlough', 1, 1), + (21, 'Furlough half day', '#778899', 'halfFurlough', 0.5, 1); + +INSERT INTO `vn`.`calendar` (`businessFk`, `dayOffTypeFk`, `dated`) + VALUES + (1, 6, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 10 DAY))), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 10 DAY))), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 11 DAY))), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -12 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 12 DAY))), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -20 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 20 DAY))), + (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -13 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 8 DAY))), + (1106, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -14 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 9 DAY))), + (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 7 DAY))), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 10 DAY))), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 11 DAY))), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -12 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 12 DAY))), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -20 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 20 DAY))), + (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -13 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 8 DAY))), + (1107, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -14 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 9 DAY))), + (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 7 DAY))), + (1107, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL - 16 DAY)); + +INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`, `apiKey`) + VALUES + ('1', 'https://api.gateway360.com/api/3.0/sms/send', 'Verdnatura', '5715476da95b46d686a5a255e6459523'); + +INSERT INTO `vn`.`sharingClient`(`id`, `workerFk`, `started`, `ended`, `clientFk`) + VALUES + (1, 19, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY), 1101), + (2, 18, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY), 1106); + +INSERT INTO `vn`.`sharingCart`(`id`, `workerFk`, `started`, `ended`, `workerSubstitute`, `created`) + VALUES + (1, 18, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY), 19, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY)); + +CALL `vn`.zoneGeo_calcTree(); -- this is an auto calculate for table vn.zoneGeo, columns: path,lft,rgt,depth,sons + +INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`) + VALUES + (1, 3, 0), + (1, 4, 0), + (1, 5, 0), + (1, 1, 1), + (2, 3, 0), + (2, 4, 0), + (2, 5, 0), + (2, 1, 1), + (3, 3, 0), + (3, 4, 0), + (3, 5, 0), + (3, 1, 1), + (4, 3, 0), + (4, 4, 0), + (4, 5, 0), + (4, 1, 1), + (5, 3, 1), + (5, 4, 0), + (5, 5, 1), + (5, 1, 1), + (6, 3, 1), + (6, 4, 0), + (6, 5, 1), + (6, 1, 1), + (7, 3, 0), + (7, 4, 0), + (7, 5, 0), + (7, 1, 1), + (8, 3, 0), + (8, 4, 0), + (8, 5, 0), + (8, 1, 1), + (9, 7, 1), + (10, 14, 1); + +INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) + VALUES + (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=2, 2, 9) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=3, 3, 10) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=4, 4, 11) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=5, 5, 12) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=6, 6, 13) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=2, 2, 9) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=3, 3, 10) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=4, 4, 11) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=5, 5, 12) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=6, 6, 13) - DAYOFWEEK(util.VN_CURDATE())) DAY)), + (3, 'day', util.VN_CURDATE()), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), + (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), + (4, 'day', util.VN_CURDATE()), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), + (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), + (5, 'day', util.VN_CURDATE()), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), + (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), + (6, 'day', util.VN_CURDATE()), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), + (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), + (7, 'day', util.VN_CURDATE()), + (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), + (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), + (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), + (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), + (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), + (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)); + +INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`) + VALUES + (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'), + (10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); + +INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`) + VALUES + (9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)); + +INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`) + VALUES + (1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in', 0), + (1106, CONCAT(util.VN_CURDATE(), ' 10:00'), TRUE, 'middle', 0), + (1106, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 0), + (1106, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 0), + (1107, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in', 1), + (1107, CONCAT(util.VN_CURDATE(), ' 10:00'), TRUE, 'middle', 1), + (1107, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 1), + (1107, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 1); + +INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`) + VALUES + (1, 'Facturas Recibidas', 'recibidas', NULL, NULL, 'invoiceIn'), + (2, 'Doc oficial', 'oficial', NULL, NULL, 'officialDoc'), + (3, 'Laboral', 'laboral', 37, 37, 'hhrrData'), + (4, 'Albaranes recibidos', 'entradas', NULL, NULL, 'deliveryNote'), + (5, 'Otros', 'otros', 1, 1, 'miscellaneous'), + (6, 'Pruebas', 'pruebas', NULL, NULL, 'tests'), + (7, 'IAE Clientes', 'IAE_Clientes', 1, 1, 'economicActivitiesTax'), + (8, 'Fiscal', 'fiscal', NULL, NULL, 'fiscal'), + (9, 'Vehiculos', 'vehiculos', NULL, NULL, 'vehicles'), + (10, 'Plantillas', 'plantillas', NULL, NULL, 'templates'), + (11, 'Contratos', 'contratos', NULL, NULL, 'contracts'), + (12, 'ley de pagos', 'ley pagos', 1, 1, 'paymentsLaw'), + (13, 'Basura', 'basura', 1, 1, 'trash'), + (14, 'Ticket', 'tickets', 1, 1, 'ticket'), + (15, 'Presupuestos', 'Presupuestos', NULL, NULL, 'budgets'), + (16, 'Logistica', 'logistica', NULL, NULL, 'logistics'), + (17, 'cmr', 'cmr', NULL, NULL, 'cmr'), + (18, 'dua', 'dua', NULL, NULL, 'dua'), + (19, 'inmovilizado', 'inmovilizado', NULL, NULL, 'fixedAssets'), + (20, 'Reclamación', 'reclamacion', 1, 1, 'claim'); + +INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) + VALUES + (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', util.VN_CURDATE()), + (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', util.VN_CURDATE()), + (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', util.VN_CURDATE()), + (4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', util.VN_CURDATE()), + (5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', util.VN_CURDATE()), + (6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', util.VN_CURDATE()), + (7, 20, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()), + (8, 20, '8.mp4', 'video/mp4', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()); + +INSERT INTO `vn`.`claimDms`(`claimFk`, `dmsFk`) + VALUES + (1, 7), + (1, 8); + +INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`) + VALUES + (11, 1); + +INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`) + VALUES + (1104, 2), + (1104, 3); + +INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`,`isReadableByWorker`) + VALUES + (1, 1106, 4, TRUE), + (2, 1107, 3, FALSE); + +INSERT INTO `vn`.`device` (`sn`, `model`, `userFk`) + VALUES + ('aaa', 'android', '9'); + +INSERT INTO `vn`.`queuePriority`(`id`, `priority`, `code`) + VALUES + (1, 'Alta', 'high'), + (2, 'Normal', 'normal'), + (3, 'Baja', 'low'); + +INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`, `weekMaxBreak`, `weekMaxScope`, `askInOut`) + VALUES + (1, 43200, 129600, 734400, 43200, 50400, 259200, 1296000, 36000); + +INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11'); + +INSERT INTO `vn`.`thermograph`(`id`, `model`) + VALUES + ('TMM190901395', 'TEMPMATE'), + ('TL.BBA85422', 'TL30'), + ('TZ1905012010', 'DISPOSABLE'), + ('138350-0', 'DISPOSABLE'); + + +INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `result`, `dmsFk`) + VALUES + ('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', 'Ok', NULL), + ('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL), + ('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL), + ('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5), + ('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5), + ('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL); + +REPLACE INTO `vn`.`incoterms`(`code`, `name`) + VALUES + ('FAS', 'Free Alongside Ship'); + +REPLACE INTO `vn`.`customsAgent`(`id`, `fiscalName`, `street`, `nif`, `phone`, `email`) + VALUES + (1, 'Agent one', '1007 Mountain Drive, Gotham', 'N1111111111', '111111111', 'agentone@gotham.com'), + (2, 'Agent two', '1007 Mountain Drive, Gotham', 'N2222222222', '222222222', 'agenttwo@gotham.com'); + +INSERT INTO `vn`.`tablet`(`uuid`, `name`, `place`, `macwifi`) + VALUES + ('1', 'TEST', 'ON THE FIXTURES', '0'), + ('2', 'DEV', 'OTHER TABLET', '0'); + +INSERT INTO `vn`.`tabletDepartment`(`tabletFk`, `departmentFk`) + VALUES + (1, 23), + (2, 1); + +INSERT INTO `vn`.`campaign`(`code`, `dated`) + VALUES + ('valentinesDay', CONCAT(YEAR(util.VN_CURDATE()), '-02-14')), + ('valentinesDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-02-14')), + ('valentinesDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-02-14')), + ('valentinesDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -3 YEAR)), '-02-14')), + ('mothersDay', CONCAT(YEAR(util.VN_CURDATE()), '-05-05')), + ('mothersDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-05-05')), + ('mothersDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-05-05')), + ('mothersDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -3 YEAR)), '-05-05')), + ('allSaints', CONCAT(YEAR(util.VN_CURDATE()), '-11-01')), + ('allSaints', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-11-01')), + ('allSaints', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-11-01')), + ('allSaints', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -3 YEAR)), '-11-01')); + +INSERT INTO `hedera`.`imageCollectionSize`(`id`, `collectionFk`,`width`, `height`) + VALUES + (1, 4, 160, 160); + +INSERT INTO `vn`.`rateConfig`(`rate0`, `rate1`, `rate2`, `rate3`) + VALUES + (36, 31, 25, 21); + +INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate3`) + VALUES + (DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), + (util.VN_CURDATE(), 1, 12, 17, 22, 27); + +INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) + VALUES + (1, '07546501420', 67, 671, util.VN_CURDATE(), 1761, 1, 1), + (2, '07546491421', 252, 2769, util.VN_CURDATE(), 5231, 1, 1), + (3, '07546500823', 102, 1495, util.VN_CURDATE(), 3221, 1, 1), + (4, '99610288821', 252, 2777, util.VN_CURDATE(), 3641, 1, 1), + (5, '07546500834', 229, 3292, util.VN_CURDATE(), 6601, 2, 1), + (6, '22101929561', 37, 458, util.VN_CURDATE(), 441, 2, 1), + (7, '07546491432', 258, 3034, util.VN_CURDATE(), 6441, 2, 1), + (8, '99610288644', 476, 4461, util.VN_CURDATE(), 5751, 442, 1), + (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), + (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); + +INSERT INTO `vn`.`dua` (id, code, awbFk, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) + VALUES + (1, '19ES0028013A481523', 1, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), + (2, '21ES00280136115760', 2, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1376.20, 442), + (3, '19ES00280131956004', 3, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 3, 14268.50, 442), + (4, '19ES00280131955995', 4, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 8242.50, 442), + (5, '19ES00280132022070', 5, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 10012.49, 442), + (6, '19ES00280132032308', 6, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 19914.25, 442), + (7, '19ES00280132025489', 7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1934.06, 442), + (8, '19ES00280132025490', 8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 3618.52, 442), + (9, '19ES00280132025491', 9, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 7126.23, 442), + (10, '19ES00280132025492', 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 4631.45, 442); + +REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`) + VALUES + (1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1), + (2, 1002, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1235, 1, 442, 1), + (3, 1003, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1236, 0, 442, 1), + (4, 1004, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1237, 0, 442, 1), + (5, 1005, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1238, 1, 442, 1), + (6, 1006, 'R', 2, util.VN_CURDATE(), util.VN_CURDATE(), 1239, 0, 442, 1), + (7, 1007, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1240, 1, 442, 1), + (8, 1008, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1241, 1, 442, 1), + (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 1, 442, 1), + (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 1, 442, 1); + +INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`, `daysAgo`) + VALUES + (1, -2, '2% retention', 2, 45); + +INSERT INTO `vn`.`invoiceInDueDay`(`invoiceInFk`, `dueDated`, `bankFk`, `amount`) + VALUES + (1, util.VN_CURDATE(), 1, 336.99), + (1, util.VN_CURDATE(), 1, 15.25), + (2, util.VN_CURDATE(), 1, 168), + (2, util.VN_CURDATE(), 1, 55.17), + (3, util.VN_CURDATE(), 1, 87.95), + (3, util.VN_CURDATE(), 1, 7.65), + (4, util.VN_CURDATE(), 1, 373.27), + (4, util.VN_CURDATE(), 1, 73.36), + (5, util.VN_CURDATE(), 1, 64.23), + (6, util.VN_CURDATE(), 1, 32.95), + (7, util.VN_CURDATE(), 1, 58.64); + +INSERT INTO `vn`.`duaInvoiceIn`(`id`, `duaFk`, `invoiceInFk`) + VALUES + (1, 1, 1), + (2, 2, 2), + (3, 3, 3), + (4, 4, 4), + (5, 5, 5), + (6, 6, 6), + (7, 7, 7), + (8, 8, 8), + (9, 9, 9), + (10, 10, 10); + +INSERT INTO `vn`.`invoiceInTax` (`invoiceInFk`, `taxableBase`, `expenseFk`, `foreignValue`, `taxTypeSageFk`, `transactionTypeSageFk`) + VALUES + (1, 99.99, '2000000000', NULL, NULL, NULL), + (2, 999.99, '2000000000', NULL, NULL, NULL), + (3, 1000.50, '2000000000', NULL, NULL, NULL), + (4, 0.50, '2000000000', NULL, NULL, NULL), + (5, 150.50, '2000000000', NULL, NULL, NULL), + (1, 252.25, '4751000000', NULL, 7, 61), + (2, 223.17, '6210000567', NULL, 8, 20), + (3, 95.60, '7001000000', NULL, 8, 35), + (4, 446.63, '7001000000', NULL, 6, 61), + (5, 64.23, '6210000567', NULL, 8, 20), + (6, 29.95, '7001000000', NULL, 7, 20), + (7, 58.64, '6210000567', NULL, 8, 20); + +INSERT INTO `vn`.`invoiceInIntrastat` (`invoiceInFk`, `net`, `intrastatFk`, `amount`, `stems`, `countryFk`) + VALUES + (1, 30.50, 5080000, 10.00, 162, 5), + (1, 10, 6021010, 20.00, 205, 5), + (2, 13.20, 5080000, 15.00, 580, 5), + (2, 16.10, 6021010, 25.00, 80, 5); + +INSERT INTO `vn`.`ticketRecalc`(`ticketFk`) + SELECT t.id + FROM vn.ticket t + LEFT JOIN vn.ticketRecalc tr ON tr.ticketFk = t.id + WHERE tr.ticketFk IS NULL; + +CALL `vn`.`ticket_doRecalc`(); + +UPDATE `vn`.`ticket` + SET refFk = 'T1111111' + WHERE id IN (1,2); + +UPDATE `vn`.`ticket` + SET refFk = 'T2222222' + WHERE id = 3; + +UPDATE `vn`.`ticket` + SET refFk = 'T3333333' + WHERE id = 4; + +UPDATE `vn`.`ticket` + SET refFk = 'T4444444' + WHERE id = 5; + +UPDATE `vn`.`ticket` + SET refFk = 'A1111111' + WHERE id = 6; + +INSERT INTO `vn`.`zoneAgencyMode`(`id`, `agencyModeFk`, `zoneFk`) + VALUES + (1, 1, 1), + (2, 1, 2), + (3, 6, 5), + (4, 7, 1); + +INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `userFk`, `price`, `driverName`) + VALUES + (1, 'val-algemesi', 'RE-001', 'PO-001', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'), + (2, 'alg-valencia', 'RE-002', 'PO-002', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'), + (3, 'alz-algemesi', 'RE-003', 'PO-003', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman'); + +INSERT INTO `vn`.`expeditionTruck` (`id`, `roadmapFk`, `warehouseFk`, `eta`, `description`, `userFk`) + VALUES + (1, 1, 1, DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY), 'Best truck in fleet', 1), + (2, 1, 2, DATE_ADD(util.VN_NOW(), INTERVAL '1 2' DAY_HOUR), 'Second truck in fleet', 1), + (3, 1, 3, DATE_ADD(util.VN_NOW(), INTERVAL '1 4' DAY_HOUR), 'Third truck in fleet', 1), + (4, 2, 1, DATE_ADD(util.VN_NOW(), INTERVAL 3 DAY), 'Truck red', 1); + +INSERT INTO `vn`.`expeditionPallet` (`id`, `truckFk`, `built`, `position`, `isPrint`) + VALUES + (1, 1, util.VN_CURDATE(), 1, 1); + +INSERT INTO `vn`.`expeditionScan` (`id`, `expeditionFk`, `scanned`, `palletFk`) + VALUES + (1, 1, util.VN_CURDATE(), 1), + (2, 2, util.VN_CURDATE(), 1), + (3, 3, util.VN_CURDATE(), 1), + (4, 4, util.VN_CURDATE(), 1), + (5, 5, util.VN_CURDATE(), 1), + (6, 6, util.VN_CURDATE(), 1), + (7, 7, util.VN_CURDATE(), 1), + (8, 8, util.VN_CURDATE(), 1), + (9, 9, util.VN_CURDATE(), 1), + (10, 10, util.VN_CURDATE(), 1); + +CALL `cache`.`last_buy_refresh`(FALSE); + +UPDATE `vn`.`item` SET `genericFk` = 9 + WHERE `id` = 2; + +INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced`) + VALUES + (1101, 500, util.VN_CURDATE(), util.VN_CURDATE()), + (1102, 500, util.VN_CURDATE(), util.VN_CURDATE()), + (1103, 500, util.VN_CURDATE(), util.VN_CURDATE()), + (1107, 500, util.VN_CURDATE(), util.VN_CURDATE()), + (1109, 500, util.VN_CURDATE(), util.VN_CURDATE()); + +UPDATE `vn`.`route` + SET `invoiceInFk`=1 + WHERE `id`=1; + +UPDATE `vn`.`route` + SET `invoiceInFk`=2 + WHERE `id`=2; + +INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`) + VALUES + (1, 501.95, util.VN_CURDATE(), 2, 1101), + (2, 70.7, util.VN_CURDATE(), 2, 1101), + (3, 200.78, util.VN_CURDATE(), 2, 1101), + (4, 33.8, util.VN_CURDATE(), 1, 1101), + (30, 34.4, util.VN_CURDATE(), 1, 1108); + +INSERT INTO `vn`.`docuwareConfig` (`url`) + VALUES + ('http://docuware.url/'); + +INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`) + VALUES + (1, 'dayOfIT'); + +INSERT INTO `vn`.`calendarHolidaysType` (`id`, `name`, `hexColour`) + VALUES + (1, 'National', '#4169E1'); + +INSERT INTO `vn`.`calendarHolidays` (`id`, `calendarHolidaysTypeFk`, `dated`, `calendarHolidaysNameFk`, `workCenterFk`) + VALUES + (1, 1, CONCAT(YEAR(util.VN_CURDATE()), '-12-09'), 1, 1); + +INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackages`, `kmPrice`, `packagePrice`, `routePrice`, `minimumKm`, `minimumM3`, `m3Price`) + VALUES + (1, 1, 0, 0.00, 0.00, NULL, 0, 0.00, 23), + (2, 1, 60, 0.00, 0.00, NULL, 0, 5.00, 33), + (3, 2, 0, 15.00, 0.00, NULL, 0, 0.00, 0), + (4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0), + (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); + +INSERT INTO `vn`.`chat` (`senderFk`, `recipient`, `dated`, `checkUserStatus`, `message`, `status`, `attempts`) + VALUES + (1101, '@PetterParker', util.VN_CURDATE(), 1, 'First test message', 0, 'sent'), + (1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 'pending'); + + +INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`) + VALUES + ('delivery', '9.2', 0), + ('warehouse', '8.1', 0); + +INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`) + VALUES + ('RE-001', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442), + ('RE-002', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442); + +INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`) + VALUES + (1106, 1, util.VN_CURDATE(), util.VN_CURDATE()), + (1106, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), + (1106, 2, util.VN_CURDATE(), NULL), + (1106, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)); + +INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`) +VALUES + (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=7, 7, 14) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100), + (2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=8, 8, 15) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100); + +INSERT INTO `vn`.`zoneExclusionGeo` (`zoneExclusionFk`, `geoFk`) + VALUES + (2, 1); + +INSERT INTO `vn`.`mdbBranch` (`name`) + VALUES + ('test'), + ('master'); + +INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`) + VALUES + ('tpv', 'test', '1'), + ('lab', 'master', '1'); + +INSERT INTO `vn`.`accountingConfig` (`id`, `minDate`, `maxDate`) + VALUES + (1, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-01-01'), CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)), '-01-01')); + + +INSERT INTO `vn`.`saleGroup` (`userFk`, `parkingFk`, `sectorFk`) + VALUES + (1, 1, 1); + +INSERT INTO `vn`.`saleGroupDetail` (`saleFk`, `saleGroupFk`) + VALUES + (31, 1); + +INSERT INTO `vn`.`sectorCollection` (`userFk`, `sectorFk`) + VALUES + (1, 1); + +INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk`) + VALUES + (1, 1); + +INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`) + VALUES + (1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13, 28800, 32400); + +INSERT INTO `vn`.`host` (`id`, `code`, `description`, `warehouseFk`, `bankFk`) + VALUES + (1, 'pc1', 'pc host', 1, 1); + +INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`, `printerFk`) + VALUES + (1, 'h1', 1, '', 1); + +INSERT INTO vn.packingSiteLog (packingSiteFk, hostFk, workerFk, printerModelFk) VALUES('h1', '1', 1, 'pcode1'); + +INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGroupKey`, `avgBoxingTime`) + VALUES + ('', 'SHINNOBI_TOKEN', 'GROUP_TOKEN', 6000); +INSERT INTO `util`.`notificationConfig` + SET `cleanDays` = 90; + +INSERT INTO `util`.`notification` (`id`, `name`, `description`) + VALUES + (1, 'print-email', 'notification fixture one'), + (2, 'invoice-electronic', 'A electronic invoice has been generated'), + (3, 'not-main-printer-configured', 'A printer distinct than main has been configured'), + (4, 'supplier-pay-method-update', 'A supplier pay method has been updated'), + (5, 'modified-entry', 'An entry has been modified'); + +INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) + VALUES + (1, 9); + +INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) + VALUES + (1, 'print-email', '{"id": "1"}', 9, 'pending', util.VN_CURDATE()), + (2, 'print-email', '{"id": "2"}', null, 'pending', util.VN_CURDATE()), + (3, 'print-email', null, null, 'pending', util.VN_CURDATE()); + +INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) + VALUES + (1, 1109), + (1, 1110), + (2, 1109), + (1,9), + (1,3); + + +INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) + VALUES + (1, 9); + +INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) + VALUES + (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6); + +INSERT INTO `vn`.`collection` (`id`, `created`, `workerFk`, `stateFk`, `itemPackingTypeFk`, `saleTotalCount`, `salePickedCount`, `trainFk`, `sectorFk`, `wagons`) + VALUES + (3, util.VN_NOW(), 1107, 5, NULL, 0, 0, 1, NULL, NULL); + +INSERT INTO `vn`.`itemConfig` (`id`, `isItemTagTriggerDisabled`, `monthToDeactivate`, `wasteRecipients`, `validPriorities`, `defaultPriority`, `defaultTag`, `warehouseFk`) + VALUES + (0, 0, 24, '', '[1,2,3]', 2, 56, 60); + +INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`) + VALUES + (9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL); + +INSERT INTO `vn`.`saleCloned` (`saleClonedFk`, `saleOriginalFk`) + VALUES + (29, 25); + +UPDATE `account`.`user` + SET `hasGrant` = 1 + WHERE `id` = 66; + +INSERT INTO `vn`.`ticketLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`) + VALUES + (7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 1, NULL), + (7, 18, 'update', 'Ticket', '{"quantity":1,"concept":"Chest ammo box"}', '{"quantity":10,"concept":"Chest ammo box"}', 1, NULL), + (7, 18, 'update', 'Sale', '{"price":3}', '{"price":5}', 1, NULL), + (7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 1x0.5m de '5' a '10'"), + (16, 9, 'update', 'Sale', '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', '{"quantity":8,"concept":"Shield", "price": 10.5, "itemFk": 1}' , 5689, 'Shield'); + + +INSERT INTO `vn`.`ticketLog` (originFk, userFk, `action`, creationDate, changedModel, changedModelId, changedModelValue, oldInstance, newInstance, description) + VALUES + (1, NULL, 'delete', '2001-06-09 11:00:04', 'Ticket', 45, 'Spider Man' , NULL, NULL, NULL), + (1, 18, 'select', '2001-06-09 11:00:03', 'Ticket', 45, 'Spider Man' , NULL, NULL, NULL), + (1, NULL, 'update', '2001-05-09 10:00:02', 'Sale', 69854, 'Armor' , '{"isPicked": false}','{"isPicked": true}', NULL), + (1, 18, 'update', '2001-01-01 10:05:01', 'Sale', 69854, 'Armor' , NULL, NULL, 'Armor quantity changed from ''15'' to ''10'''), + (1, NULL, 'delete', '2001-01-01 10:00:10', 'Sale', 5689, 'Shield' , '{"quantity":10,"concept":"Shield"}', NULL, NULL), + (1, 18, 'insert', '2000-12-31 15:00:05', 'Sale', 69854, 'Armor' , NULL,'{"quantity":15,"concept":"Armor", "price": 345.99, "itemFk": 2}', NULL), + (1, 18, 'update', '2000-12-28 08:40:45', 'Ticket', 45, 'Spider Man' , '{"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"isBlocked":false,"hasPriority":false,"companyFk":442,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}','{"warehouseFk":61,"shipped":"2023-05-17T22:00:00.000Z","nickname":"Spider Man","isSigned":false,"isLabeled":false,"isPrinted":false,"packages":1,"hour":0,"isBlocked":true,"hasPriority":true,"companyFk":443,"landed":"2023-05-18T22:00:00.000Z","isBoxed":false,"isDeleted":false,"zoneFk":713,"zonePrice":13,"zoneBonus":1}', NULL), + (1, 18, 'select', '2000-12-27 03:40:30', 'Ticket', 45, NULL , NULL, NULL, NULL), + (1, 18, 'insert', '2000-04-10 09:40:15', 'Sale', 5689, 'Shield' , NULL, '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', NULL), + (1, 18, 'insert', '1999-05-09 10:00:00', 'Ticket', 45, 'Super Man' , NULL, '{"id":45,"clientFk":8608,"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","addressFk":48637,"isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"created":"2023-05-16T11:42:56.000Z","isBlocked":false,"hasPriority":false,"companyFk":442,"agencyModeFk":639,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}', NULL); +INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) + VALUES + (0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', '1,6', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all'); + +INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) + VALUES + ('foo', 'master', NULL, NULL), + ('bar', 'test', 9, util.VN_NOW()); + +INSERT INTO `vn`.`profileType` (`id`, `name`) + VALUES + (1, 'working'); + +INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) + VALUES + ('lilium', 'development', 'http://localhost:9000/#/'), + ('salix', 'development', 'http://localhost:5000/#!/'); + +INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`) + VALUES + (3, 'invoice', NULL, 'InvoiceOuts/{refFk}/invoice-out-pdf'); + +INSERT INTO `vn`.`payDemDetail` (`id`, `detail`) + VALUES + (1, 1); + +INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk`, `businessTypeFk`) + VALUES + (1, NULL, 1, 4, 'worker'); + +INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) + VALUES + (1, 12), + (8, 10); + +INSERT INTO `vn`.`deviceProductionModels` (`code`) + VALUES + ('BLACKVIEW'), + ('DODGEE'), + ('ZEBRA'); + +INSERT INTO `vn`.`deviceProductionState` (`code`, `description`) + VALUES + ('active', 'activo'), + ('idle', 'inactivo'), + ('lost', 'perdida'), + ('repair', 'reparación'), + ('retired', 'retirada'); + +INSERT INTO `vn`.`deviceProduction` (`imei`, `modelFk`, `macWifi`, `serialNumber`, `android_id`, `purchased`, `stateFk`, `isInScalefusion`, `description`) + VALUES + ('ime1', 'BLACKVIEW', 'macWifi1', 'serialNumber1', 'androidId0000001', util.VN_NOW(), 'active', 0, NULL), + ('ime2', 'DODGEE', 'macWifi2', 'serialNumber2', 'androidId0000002', util.VN_NOW(), 'idle', 0, NULL), + ('ime3', 'ZEBRA', 'macWifi3', 'serialNumber3', 'androidId0000003', util.VN_NOW(), 'active', 0, NULL), + ('ime4', 'BLACKVIEW', 'macWifi4', 'serialNumber4', 'androidId0000004', util.VN_NOW(), 'idle', 0, NULL); + +INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `created`) + VALUES + (1, 1, util.VN_NOW()), + (3, 3, util.VN_NOW()); + +INSERT INTO `vn`.`workerTimeControlMail` (`id`, `workerFk`, `year`, `week`, `state`, `updated`, `sendedCounter`, `reason`) + VALUES + (1, 9, 2000, 49, 'REVISE', util.VN_NOW(), 1, 'test2'), + (2, 9, 2000, 50, 'SENDED', util.VN_NOW(), 1, NULL), + (3, 9, 2000, 51, 'CONFIRMED', util.VN_NOW(), 1, NULL), + (4, 9, 2001, 1, 'SENDED', util.VN_NOW(), 1, NULL); + +INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`) + VALUES + (1, 1350, 1900, 200, 50, 6); + +INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) + VALUES + (1, 'white', '#ffffff'), + (2, 'red', '#ff0000'), + (3, 'green', '#00ff00'), + (4, 'blue', '#0000ff'); + +INSERT INTO `vn`.`wagonType` (`id`, `name`, `divisible`) + VALUES + (1, 'Wagon Type #1', 1); + +INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`) + VALUES + (1, 1, 100, 1), + (2, 1, 50, 2), + (3, 1, 0, 3); + +INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `renewInterval`) + VALUES + (1, 21600, 300); + +INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`) + VALUES + (1, 1, 1, 1, 442); + +INSERT INTO `vn`.`buyConfig` (`id`, `monthsAgo`) + VALUES + (1, 6); + +INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `taxAreaFk`) + VALUES + ('C', 'Asgard', 1, 'WORLD'), + ('E', 'Midgard', 1, 'CEE'), + ('R', 'Jotunheim', 1, 'NATIONAL'), + ('W', 'Vanaheim', 1, 'WORLD'); + + +INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) + VALUES + (1, 0, 0, 'marvel.com'); diff --git a/db/dump/mockDate.sql b/db/dump/mockDate.sql index 5d4d0c351..1ed5d76be 100644 --- a/db/dump/mockDate.sql +++ b/db/dump/mockDate.sql @@ -1,22 +1,17 @@ - DELIMITER $$ - -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTime`() RETURNS datetime - DETERMINISTIC +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION util.mockTime() + RETURNS DATETIME + DETERMINISTIC BEGIN - RETURN CONVERT_TZ('@mockDate', 'utc', 'Europe/Madrid'); -END$$ - -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockUtcTime`() RETURNS datetime - DETERMINISTIC -BEGIN - RETURN CONVERT_TZ('@mockDate', 'utc', 'Europe/Madrid'); -END$$ - -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTimeBase`(vIsUtc BOOL) RETURNS datetime - DETERMINISTIC -BEGIN - RETURN CONVERT_TZ('@mockDate', 'utc', 'Europe/Madrid'); + RETURN @mockDate; END$$ DELIMITER ; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION util.mockUtcTime() + RETURNS DATETIME + DETERMINISTIC +BEGIN + RETURN @mockDate; +END$$ +DELIMITER ; diff --git a/db/export-data.sh b/db/export-data.sh deleted file mode 100755 index 97092da4f..000000000 --- a/db/export-data.sh +++ /dev/null @@ -1,109 +0,0 @@ -#!/bin/bash - -DUMPED_FILE="dump/dumpedFixtures.sql" -INI_FILE="config.production.ini" - -dump_tables() { - SCHEMA=$1 - echo "USE \`$SCHEMA\`;" >> "$DUMPED_FILE" - mysqldump --defaults-file="$INI_FILE" --no-create-info --skip-triggers $@ >> "$DUMPED_FILE" -} - -echo "" > "$DUMPED_FILE" - -TABLES=( - util - config - version - versionLog -) -dump_tables ${TABLES[@]} - -TABLES=( - account - role - roleInherit - roleRole - userPassword - accountConfig - mailConfig -) -dump_tables ${TABLES[@]} - -TABLES=( - salix - ACL - fieldAcl - module - defaultViewConfig -) -dump_tables ${TABLES[@]} - -TABLES=( - vn - agencyTermConfig - alertLevel - bookingPlanner - businessType - siiTypeInvoiceIn - siiTypeInvoiceOut - cplusRectificationType - cplusSubjectOp - cplusTaxBreak - siiTrascendencyInvoiceIn - claimResponsible - claimReason - claimRedelivery - claimResult - component - componentType - continent - department - docuware - itemPackingType - pgc - sample - state - ticketUpdateAction - volumeConfig - workCenter - companyI18n - workerTimeControlError - silexACL -) -dump_tables ${TABLES[@]} - -TABLES=( - cache - cache -) -dump_tables ${TABLES[@]} - -TABLES=( - hedera - browser - imageCollection - imageCollectionSize - language - link - location - menu - message - metatag - newsTag - restPriv - social - tpvError - tpvResponse - -) -dump_tables ${TABLES[@]} - -TABLES=( - sage - TiposIva - TiposTransacciones - TiposRetencion - taxType -) -dump_tables ${TABLES[@]} diff --git a/db/export-structure.sh b/db/export-structure.sh deleted file mode 100755 index 4ecbfa7e8..000000000 --- a/db/export-structure.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -SCHEMAS=( - account - bs - cache - edi - hedera - pbx - sage - salix - stock - util - vn -) - -IGNORETABLES=( - --ignore-table=bi.last_Id_Cubo - --ignore-table=bi.v_clientes_jerarquia - --ignore-table=bi.v_ventas_contables - --ignore-table=bs.horasSilla - --ignore-table=bs.productionIndicators - --ignore-table=bs.VentasPorCliente - --ignore-table=bs.v_ventas - --ignore-table=vn.accounting__ - --ignore-table=vn.agencyModeZone - --ignore-table=vn.agencyProvince - --ignore-table=vn.agencyWarehouse - --ignore-table=vn.botanicExport__ - --ignore-table=vn.clientDefaultCompany - --ignore-table=vn.color - --ignore-table=vn.comparative - --ignore-table=vn.comparativeFilter - --ignore-table=vn.coolerPath - --ignore-table=vn.coolerPathDetail - --ignore-table=vn.config__ - --ignore-table=vn.department__ - --ignore-table=vn.doc - --ignore-table=vn.entity - --ignore-table=vn.especialPrice - --ignore-table=vn.exchangeInsurance - --ignore-table=vn.exchangeInsuranceInPrevious - --ignore-table=vn.exchangeReportSource - --ignore-table=vn.grant - --ignore-table=vn.grantGroup - --ignore-table=vn.invoiceCorrection__ - --ignore-table=vn.itemTaxCountrySpain - --ignore-table=vn.itemShelvingPlacementSupplyStock__ - --ignore-table=vn.itemFreeNumber__ - --ignore-table=vn.mail__ - --ignore-table=vn.manaSpellers - --ignore-table=vn.outgoingInvoiceKk - --ignore-table=vn.paymentExchangeInsurance - --ignore-table=vn.payrollCenter - --ignore-table=vn.plantpassport__ - --ignore-table=vn.plantpassportAuthority__ - --ignore-table=vn.preparationException - --ignore-table=vn.priceFixed__ - --ignore-table=vn.printingQueue - --ignore-table=vn.printServerQueue__ - --ignore-table=vn.promissoryNote - --ignore-table=vn.referenceRate__ - --ignore-table=vn.routesControl - --ignore-table=vn.salesToPrePrepare - --ignore-table=vn.specialPrice__ - --ignore-table=vn.ticketDownBuffer - --ignore-table=vn.ticketeToPreparePrepared - --ignore-table=vn.ticketObservation__ - --ignore-table=vn.ticketRequest__ - --ignore-table=vn.ticket_print__ - --ignore-table=vn.ticketToPrepare - --ignore-table=vn.till__ - --ignore-table=vn.travelThermograph__ - --ignore-table=vn.travel_cloneWeekly - --ignore-table=vn.unary - --ignore-table=vn.unaryScan - --ignore-table=vn.unaryScanLine - --ignore-table=vn.unaryScanLineBuy - --ignore-table=vn.unaryScanLineExpedition - --ignore-table=vn.warehouseAlias__ - --ignore-table=vn.warehouseJoined - --ignore-table=vn.workerTeam__ - --ignore-table=vn.XDiario__ - --ignore-table=sage.movContaCopia -) -mysqldump \ - --defaults-file=config.production.ini \ - --default-character-set=utf8 \ - --no-data --comments \ - --triggers --routines --events \ - --databases \ - ${SCHEMAS[@]} \ - ${IGNORETABLES[@]} \ - | sed 's/ AUTO_INCREMENT=[0-9]* //g' \ - > dump/structure.sql diff --git a/db/import-changes.sh b/db/import-changes.sh deleted file mode 100755 index 5461f003b..000000000 --- a/db/import-changes.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/bash - -FORCE=FALSE - -usage() { - echo "[ERROR] Usage: $0 [-f] [environment]" - exit 1 -} - -while getopts ":f" option -do - case $option in - f) - FORCE=TRUE - ;; - \?|:) - usage - ;; - esac -done - -shift $(($OPTIND - 1)) - -ENV=$1 -DIR="$(dirname "${BASH_SOURCE[0]}")" - -# Production protection - -if [ "$ENV" == "production" ]; then - echo "" - echo " ( ( ) ( ( ) ) " - echo " )\ ))\ ) ( /( )\ ) ( ))\ ) ( /( ( /( " - echo "(()/(()/( )\()|()/( ( )\ ) /(()/( )\()) )\())" - echo " /(_))(_)|(_)\ /(_)) )\ (((_) ( )(_))(_)|(_)\ ((_)\ " - echo "(_))(_)) ((_|_))_ _ ((_))\___(_(_()|_)) ((_) _((_)" - echo "| _ \ _ \ / _ \| \| | | ((/ __|_ _|_ _| / _ \| \| |" - echo "| _/ /| (_) | |) | |_| || (__ | | | | | (_) | . |" - echo "|_| |_|_\ \___/|___/ \___/ \___| |_| |___| \___/|_|\_|" - echo "" - - if [ "$FORCE" != "TRUE" ]; then - read -p "[INTERACTIVE] Are you sure? (Default: no) [yes|no]: " ANSWER - - if [ "$ANSWER" != "yes" ]; then - echo "[INFO] Aborting changes." - exit - fi - fi -fi - -# Configuration file - -if [ -z "$ENV" ]; then - INI_FILE="$DIR/config.ini" -else - INI_FILE="$DIR/config.$ENV.ini" -fi - -if [ ! -f "$INI_FILE" ]; then - echo "[ERROR] Config file doesn't exists: $INI_FILE" - exit 2 -fi - -echo "[INFO] Using config file: $INI_FILE" - -# Fetching database version - -GET_VERSION="SELECT dbVersion FROM util.config LIMIT 1" -DB_VERSION=`echo "$GET_VERSION" | mysql --defaults-file="$INI_FILE" --silent --raw` - -echo "[INFO] Current database version: $DB_VERSION" - -if [[ ! "$DB_VERSION" =~ ^[0-9]+$ ]]; then - echo "[ERROR] Cannot fetch the database version." - exit 3 -fi - -# Applying changes - -N_CHANGES=0 - -for DIR_PATH in "$DIR/changes/"*; do - DIR_NAME=$(basename $DIR_PATH) - DIR_VERSION=${DIR_NAME:0:6} - - if [[ ! "$DIR_NAME" =~ ^[0-9]{6}$ ]]; then - echo "[WARN] Ignoring wrong directory name: $DIR_NAME" - continue - fi - if [ "$DB_VERSION" -ge "$DIR_VERSION" ]; then - echo "[INFO] Ignoring already applied version: $DIR_NAME" - continue - fi - - echo "[INFO] Applying version: $DIR_NAME" - - for FILE in "$DIR_PATH/"*; do - FILE_NAME=$(basename "$FILE") - - if [[ ! "$FILE_NAME" =~ ^[0-9]{2}-[a-zA-Z0-9_]+\.sql$ ]]; then - echo "[WARN] Ignoring wrong file name: $FILE_NAME" - continue - fi - - echo "[INFO] -> $FILE_NAME" - mysql --defaults-file="$INI_FILE" --comments < $FILE - N_CHANGES=$((N_CHANGES + 1)) - done - - UPDATE_VERSION="UPDATE util.config SET dbVersion='$DIR_VERSION'" - echo "$UPDATE_VERSION" | mysql --defaults-file="$INI_FILE" -done - -if [ "$N_CHANGES" -eq "0" ]; then - echo "[INFO] No changes applied." -else - echo "[INFO] Changes applied succesfully." -fi - diff --git a/db/remotes/ca.pem b/db/remotes/ca.pem new file mode 100644 index 000000000..50204e199 --- /dev/null +++ b/db/remotes/ca.pem @@ -0,0 +1,23 @@ +-----BEGIN CERTIFICATE----- +MIIDvzCCAqegAwIBAgIUG3Pd897tVM9pYLpPJFsulfk1z9EwDQYJKoZIhvcNAQEL +BQAwaDELMAkGA1UEBhMCRVMxDjAMBgNVBAgMBVNwYWluMREwDwYDVQQHDAhWYWxl +bmNpYTEeMBwGA1UECgwVVmVyZG5hdHVyYSBMZXZhbnRlIFNMMRYwFAYDVQQDDA1W +ZXJkbmF0dXJhIENBMB4XDTIwMTEwNjEyNTE0NVoXDTQwMTEwMTEyNTE0NVowaDEL +MAkGA1UEBhMCRVMxDjAMBgNVBAgMBVNwYWluMREwDwYDVQQHDAhWYWxlbmNpYTEe +MBwGA1UECgwVVmVyZG5hdHVyYSBMZXZhbnRlIFNMMRYwFAYDVQQDDA1WZXJkbmF0 +dXJhIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArKqvodZFH2RN +fSJ5tzNlxdcrSKl3iLF7ImeU/WlXXnUKxdsXFTq+HbychOc6fYOzTccvUxcgBz14 +j1ikqF98NLqEHy1vR5tfUGWLuNIQQ+aEaycuZupeCVNxo9LZ5L2HOJvBZdrhFE92 +op9BRNiNV4yqS+nkIvUyo4YJljUYAyVG5ZQAd5bEC5DXwehBaNkCcpIipWkYuFGh +3UpHd85FCcmEXXBuyMQhb7FYiqcK9yRfky10jf6K6JyxYBvHCnna5/rDFqQZthWU +CgIfIS090EEKkIBqUNsuLdhFSZGFXXBgVwslmAynoDF4CUddFrpyAhQmg5DND96W +EHbW4K+3vQIDAQABo2EwXzAOBgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB +/zAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwHQYDVR0OBBYEFD36Jl1/ +uks1Ai3Gzijjd00VkPQJMA0GCSqGSIb3DQEBCwUAA4IBAQCDovHrdChX5e6/wGrr +8g8Xs1j2Lph9tIVtbP+mm9tsIvd8GV2LZIxEiw9GKdSZcx0vivT8Y2dM2b8pjkUY +8a7/ByLhEhxSDKcMk0cHwfD4zdhKcQBVb7DIYmBXLaiKlGFG04407klCRomzU+5y +SEte8AsCGmz7MOkDQ2IjghF5iM+Cagktlya3u2uefXN4CF81VOJlm5nICrc1ltPM +RsqTl8uxrgNxvqlODxC5kMePMulcJF3ybmhZwNqjraV4HupuwphedpaUypUQTSxp +mcUbG0MFkFnVF812ZN8QvNdmnguJ8o5Fzb6PvtEDgnJpU9CPQaqqec5ILMjBETFz +U438 +-----END CERTIFICATE----- diff --git a/db/config.ini b/db/remotes/docker.ini similarity index 53% rename from db/config.ini rename to db/remotes/docker.ini index 0d496dedd..f628fd3d1 100644 --- a/db/config.ini +++ b/db/remotes/docker.ini @@ -1,6 +1,5 @@ [client] -host = localhost +host = host.docker.internal port = 3306 user = root password = root -default-character-set=utf8 \ No newline at end of file diff --git a/db/remotes/local.ini b/db/remotes/local.ini new file mode 100644 index 000000000..126871f6a --- /dev/null +++ b/db/remotes/local.ini @@ -0,0 +1,5 @@ +[client] +host = 127.0.0.1 +port = 3306 +user = root +password = root diff --git a/db/remotes/old-ca.pem b/db/remotes/old-ca.pem new file mode 100644 index 000000000..a1c6710ce --- /dev/null +++ b/db/remotes/old-ca.pem @@ -0,0 +1,26 @@ +-----BEGIN CERTIFICATE----- +MIIEXTCCA0WgAwIBAgIURUPRgeHoKVUN5MQywkR+C7+CXgkwDQYJKoZIhvcNAQEL +BQAwgbYxCzAJBgNVBAYTAkVTMR0wGwYDVQQIDBRDb211bmlkYWQgVmFsZW5jaWFu +YTERMA8GA1UEBwwIVmFsZW5jaWExHjAcBgNVBAoMFVZlcmRuYXR1cmEgTGV2YW50 +ZSBTTDEUMBIGA1UECwwLSW5mb3JtYXRpY2ExFjAUBgNVBAMMDXZlcmRuYXR1cmEu +ZXMxJzAlBgkqhkiG9w0BCQEWGGhvc3RtYXN0ZXJAdmVyZG5hdHVyYS5lczAeFw0y +MjA4MDMyMDI2NTlaFw00MjA3MjkyMDI2NTlaMIG2MQswCQYDVQQGEwJFUzEdMBsG +A1UECAwUQ29tdW5pZGFkIFZhbGVuY2lhbmExETAPBgNVBAcMCFZhbGVuY2lhMR4w +HAYDVQQKDBVWZXJkbmF0dXJhIExldmFudGUgU0wxFDASBgNVBAsMC0luZm9ybWF0 +aWNhMRYwFAYDVQQDDA12ZXJkbmF0dXJhLmVzMScwJQYJKoZIhvcNAQkBFhhob3N0 +bWFzdGVyQHZlcmRuYXR1cmEuZXMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCsqq+h1kUfZE19Inm3M2XF1ytIqXeIsXsiZ5T9aVdedQrF2xcVOr4dvJyE +5zp9g7NNxy9TFyAHPXiPWKSoX3w0uoQfLW9Hm19QZYu40hBD5oRrJy5m6l4JU3Gj +0tnkvYc4m8Fl2uEUT3ain0FE2I1XjKpL6eQi9TKjhgmWNRgDJUbllAB3lsQLkNfB +6EFo2QJykiKlaRi4UaHdSkd3zkUJyYRdcG7IxCFvsViKpwr3JF+TLXSN/oronLFg +G8cKedrn+sMWpBm2FZQKAh8hLT3QQQqQgGpQ2y4t2EVJkYVdcGBXCyWYDKegMXgJ +R10WunICFCaDkM0P3pYQdtbgr7e9AgMBAAGjYTBfMA4GA1UdDwEB/wQEAwIBhjAP +BgNVHRMBAf8EBTADAQH/MB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAd +BgNVHQ4EFgQUPfomXX+6SzUCLcbOKON3TRWQ9AkwDQYJKoZIhvcNAQELBQADggEB +AEoDI+hUiV+pWpmh188b0f47fdLw+Zh1/AfQUj6dnVM6oXPDBjgbuhV8GiL0YtZX +i+rmeelLunmeBg0nYjaeF31x0ZIwl0slDN8PFkcPzhAOYwv9QWWgHKBxIQrJ/Vtp +0xSsWmyxyw7Ax+pSEXOM9kSKMZQZOPpE/G9yoA0rMF80DgSHc2DBl2BBOFC+VPdE +j4JbK9iL8fpyRJccsRFy9OQ/0hhKUQyLhahz577o5ZX4IjxLxcfHKxrJGVJeVXYD +mRGOnabIeJQfTGviEdnkyH2DdLxi7y6aKMlPWnutRutcsyJS6hOGlhFsyGJVN6lU +umCc9ZVn7zD1QWO7GVY2qao= +-----END CERTIFICATE----- diff --git a/db/routines/account/functions/myUser_checkLogin.sql b/db/routines/account/functions/myUser_checkLogin.sql new file mode 100644 index 000000000..ed55f0d13 --- /dev/null +++ b/db/routines/account/functions/myUser_checkLogin.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_checkLogin`() + RETURNS tinyint(1) + DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Checks that variables @userId and @userName haven't been altered. + * + * @return %TRUE if they are unaltered or unset, otherwise %FALSE + */ + DECLARE vSignature VARCHAR(128); + DECLARE vKey VARCHAR(255); + + IF @userId IS NOT NULL + AND @userName IS NOT NULL + AND @userSignature IS NOT NULL + THEN + SELECT loginKey INTO vKey FROM userConfig; + SET vSignature = util.hmacSha2(256, CONCAT_WS('/', @userId, @userName), vKey); + RETURN vSignature = @userSignature; + END IF; + + RETURN FALSE; + +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/myUser_getId.sql b/db/routines/account/functions/myUser_getId.sql new file mode 100644 index 000000000..bc86c87dc --- /dev/null +++ b/db/routines/account/functions/myUser_getId.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_getId`() + RETURNS int(11) + DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Returns the current user id. + * + * @return The user id + */ + DECLARE vUser INT DEFAULT NULL; + + IF myUser_checkLogin() + THEN + SET vUser = @userId; + ELSE + SELECT id INTO vUser FROM user + WHERE name = LEFT(USER(), INSTR(USER(), '@') - 1); + END IF; + + RETURN vUser; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/myUser_getName.sql b/db/routines/account/functions/myUser_getName.sql new file mode 100644 index 000000000..541f7c086 --- /dev/null +++ b/db/routines/account/functions/myUser_getName.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_getName`() + RETURNS varchar(30) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC + NO SQL +BEGIN +/** + * Returns the current user name. + * + * @return The user name + */ + DECLARE vUser VARCHAR(30) DEFAULT NULL; + + IF myUser_checkLogin() + THEN + SET vUser = @userName; + ELSE + SET vUser = LEFT(USER(), INSTR(USER(), '@') - 1); + END IF; + + RETURN vUser; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/myUser_hasPriv.sql b/db/routines/account/functions/myUser_hasPriv.sql new file mode 100644 index 000000000..b53580d74 --- /dev/null +++ b/db/routines/account/functions/myUser_hasPriv.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_hasPriv`(vChain VARCHAR(100), + vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE') +) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Search if my user has privileges on table or column + * + * @param vChain string passed with this syntax dbName.tableName[.columnName] + * @param vPrivilege privileges to check ('SELECT','INSERT','UPDATE','DELETE') + * @return vHasPrivilege + */ + RETURN user_hasPriv(vChain, vPrivilege, myUser_getId()); +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/myUser_hasRole.sql b/db/routines/account/functions/myUser_hasRole.sql new file mode 100644 index 000000000..8cc8aafb5 --- /dev/null +++ b/db/routines/account/functions/myUser_hasRole.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_hasRole`(vRoleName VARCHAR(255)) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Checks if current user has/inherits a role. + * + * @param vRoleName Role to check + * @return %TRUE if it has role, %FALSE otherwise + */ + RETURN user_hasRole(myUser_getName(), vRoleName); +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/myUser_hasRoleId.sql b/db/routines/account/functions/myUser_hasRoleId.sql new file mode 100644 index 000000000..d059b095d --- /dev/null +++ b/db/routines/account/functions/myUser_hasRoleId.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_hasRoleId`(vRoleId INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Checks if current user has/inherits a role. + * + * @param vRoleName Role id to check + * @return %TRUE if it has role, %FALSE otherwise + */ + RETURN user_hasRoleId(myUser_getName(), vRoleId); +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/myUser_hasRoutinePriv.sql b/db/routines/account/functions/myUser_hasRoutinePriv.sql new file mode 100644 index 000000000..9e9563a5f --- /dev/null +++ b/db/routines/account/functions/myUser_hasRoutinePriv.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`myUser_hasRoutinePriv`(vType ENUM('PROCEDURE', 'FUNCTION'), + vChain VARCHAR(100) +) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Search if my user has privileges on routines + * + * @param vType procedure or function + * @param vChain string passed with this syntax dbName.tableName + * @return vHasPrivilege + */ + RETURN user_hasRoutinePriv(vType, vChain, myUser_getId()); +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/passwordGenerate.sql b/db/routines/account/functions/passwordGenerate.sql new file mode 100644 index 000000000..952a8912c --- /dev/null +++ b/db/routines/account/functions/passwordGenerate.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`passwordGenerate`() + RETURNS text CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Generates a random password that meets the minimum requirements. + * + * @return Generated password + */ + DECLARE vMinLength TINYINT; + DECLARE vMinAlpha TINYINT; + DECLARE vMinUpper TINYINT; + DECLARE vMinDigits TINYINT; + DECLARE vMinPunct TINYINT; + DECLARE vAlpha TINYINT DEFAULT 0; + DECLARE vUpper TINYINT DEFAULT 0; + DECLARE vDigits TINYINT DEFAULT 0; + DECLARE vPunct TINYINT DEFAULT 0; + DECLARE vRandIndex INT; + DECLARE vPwd TEXT DEFAULT ''; + + DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz'; + DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + DECLARE vDigitChars TEXT DEFAULT '1234567890'; + DECLARE vPunctChars TEXT DEFAULT '!$%&()=.'; + + SELECT length, nAlpha, nUpper, nDigits, nPunct + INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword; + + WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha + OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO + SET vRandIndex = FLOOR((RAND() * 4) + 1); + + CASE + WHEN vRandIndex = 1 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1)); + SET vAlpha = vAlpha + 1; + WHEN vRandIndex = 2 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1)); + SET vUpper = vUpper + 1; + WHEN vRandIndex = 3 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1)); + SET vDigits = vDigits + 1; + WHEN vRandIndex = 4 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1)); + SET vPunct = vPunct + 1; + END CASE; + END WHILE; + RETURN vPwd; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/toUnixDays.sql b/db/routines/account/functions/toUnixDays.sql new file mode 100644 index 000000000..db908060b --- /dev/null +++ b/db/routines/account/functions/toUnixDays.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`toUnixDays`(vDate DATE) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Devuelve el timestamp unix en días de una fecha. + * + * @param vData La fecha + * @return Unix timestamp en días + */ + RETURN UNIX_TIMESTAMP(vDate) DIV 86400; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/user_getMysqlRole.sql b/db/routines/account/functions/user_getMysqlRole.sql new file mode 100644 index 000000000..91540bc6b --- /dev/null +++ b/db/routines/account/functions/user_getMysqlRole.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`user_getMysqlRole`(vUserName VARCHAR(255)) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN +/** + * From a username, it returns the associated MySQL wich should be used when + * using external authentication systems. + * + * @param vUserName The user name + * @return The associated MySQL role + */ + DECLARE vRole VARCHAR(255); + + SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole + FROM role r + JOIN user u ON u.role = r.id + JOIN roleConfig c + WHERE u.name = vUserName; + + RETURN vRole; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/user_getNameFromId.sql b/db/routines/account/functions/user_getNameFromId.sql new file mode 100644 index 000000000..b06facd7a --- /dev/null +++ b/db/routines/account/functions/user_getNameFromId.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`user_getNameFromId`(vSelf INT) + RETURNS varchar(30) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN +/** + * Gets user name from it's id. + * + * @param vSelf The user id + * @return The user name + */ + DECLARE vName VARCHAR(30); + + SELECT `name` INTO vName + FROM user + WHERE id = vSelf; + + RETURN vName; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/user_hasPriv.sql b/db/routines/account/functions/user_hasPriv.sql new file mode 100644 index 000000000..83bdfaa19 --- /dev/null +++ b/db/routines/account/functions/user_hasPriv.sql @@ -0,0 +1,109 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`user_hasPriv`(vChain VARCHAR(100), + vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE'), + vUserFk INT +) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Search if the user has privileges on table or column + * + * @param vChain string passed with this syntax dbName.tableName[.columnName] + * @param vPrivilege privileges to check('SELECT','INSERT','UPDATE','DELETE') + * @param vUserFk user to check + * @return vHasPrivilege + */ + DECLARE vHasPrivilege BOOL DEFAULT FALSE; + DECLARE vDb VARCHAR(50); + DECLARE vTableName VARCHAR(50); + DECLARE vColumnName VARCHAR(50); + DECLARE vPrivilegeFlag INT; + DECLARE vChainExists BOOL; + + SET vDb = SUBSTRING_INDEX(vChain, '.', 1); + SET vChain = SUBSTRING(vChain, LENGTH(vDb) + 2); + IF LOCATE('.', vChain) > 0 THEN + SET vTableName = SUBSTRING_INDEX(vChain, '.', 1); + SET vColumnName = SUBSTRING(vChain, LENGTH(vTableName) + 2); + ELSE + SET vTableName = vChain; + END IF; + + SELECT COUNT(*) INTO vChainExists + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = vDb + AND TABLE_NAME = vTableName + AND (COLUMN_NAME = vColumnName OR vColumnName IS NULL) + LIMIT 1; + + IF NOT vChainExists THEN + RETURN FALSE; + END IF; + + CASE vPrivilege + WHEN 'Select' THEN SET vPrivilegeFlag = 1; + WHEN 'Insert' THEN SET vPrivilegeFlag = 2; + WHEN 'Update' THEN SET vPrivilegeFlag = 4; + WHEN 'Delete' THEN SET vPrivilegeFlag = 8; + ELSE BEGIN END; + END CASE; + + DROP TEMPORARY TABLE IF EXISTS tRole; + CREATE TEMPORARY TABLE tRole + (INDEX (`name`)) + ENGINE = MEMORY + SELECT r.`name` + FROM user u + JOIN roleRole rr ON rr.role = u.role + JOIN `role` r ON r.id = rr.inheritsFrom + WHERE u.id = vUserFk; + + SELECT hasPrivilege INTO vHasPrivilege + FROM (SELECT JSON_VALUE(Priv, '$.access') & vPrivilegeFlag hasPrivilege + FROM mysql.global_priv gp + JOIN tRole tr ON CONCAT(tr.name) = gp.User + HAVING hasPrivilege + LIMIT 1)sub; + + IF NOT vHasPrivilege THEN + + SELECT sub.privilege = 'Y' INTO vHasPrivilege + FROM + (SELECT CASE vPrivilege + WHEN 'SELECT' THEN Select_priv + WHEN 'INSERT' THEN Insert_priv + WHEN 'UPDATE' THEN Update_priv + WHEN 'DELETE' THEN Delete_priv + END privilege + FROM mysql.db db + JOIN tRole tr ON tr.name = db.User + WHERE db.Db = vDb)sub; + + END IF; + + IF NOT vHasPrivilege THEN + + SELECT TRUE INTO vHasPrivilege + FROM tRole tr + LEFT JOIN ( + SELECT User, Table_priv privilege + FROM mysql.tables_priv + WHERE Db = vDb + AND Table_name = vTableName + UNION + SELECT User, Column_priv + FROM mysql.columns_priv + WHERE Db = vDb + AND Table_name = vTableName + AND Column_name = vColumnName + )sub ON sub.`User` = tr.name + WHERE sub.privilege = vPrivilege; + END IF; + + DROP TEMPORARY TABLE tRole; + + RETURN vHasPrivilege; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/user_hasRole.sql b/db/routines/account/functions/user_hasRole.sql new file mode 100644 index 000000000..fb88efeec --- /dev/null +++ b/db/routines/account/functions/user_hasRole.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`user_hasRole`(vUserName VARCHAR(255), vRoleName VARCHAR(255)) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Checks if user has/inherits a role. + * + * @param vUserName The user name + * @param vRoleName Role to check + * @return %TRUE if it has role, %FALSE otherwise + */ + DECLARE vHasRole BOOL DEFAULT FALSE; + + SELECT COUNT(*) > 0 INTO vHasRole + FROM user u + JOIN roleRole rr ON rr.role = u.role + JOIN role r ON r.id = rr.inheritsFrom + WHERE u.`name` = vUserName + AND r.`name` = vRoleName COLLATE 'utf8_unicode_ci'; + + RETURN vHasRole; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/user_hasRoleId.sql b/db/routines/account/functions/user_hasRoleId.sql new file mode 100644 index 000000000..a35624d3d --- /dev/null +++ b/db/routines/account/functions/user_hasRoleId.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`user_hasRoleId`(vUser VARCHAR(255), vRoleId INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Checks if user has/inherits a role. + * + * @param vUserName The user name + * @param vRoleId Role id to check + * @return %TRUE if it has role, %FALSE otherwise + */ + DECLARE vHasRole BOOL DEFAULT FALSE; + + SELECT COUNT(*) > 0 INTO vHasRole + FROM user u + JOIN roleRole rr ON rr.role = u.role + JOIN role r ON r.id = rr.inheritsFrom + WHERE u.`name` = vUser + AND r.id = vRoleId; + + RETURN vHasRole; +END$$ +DELIMITER ; diff --git a/db/routines/account/functions/user_hasRoutinePriv.sql b/db/routines/account/functions/user_hasRoutinePriv.sql new file mode 100644 index 000000000..6f87f160c --- /dev/null +++ b/db/routines/account/functions/user_hasRoutinePriv.sql @@ -0,0 +1,81 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `account`.`user_hasRoutinePriv`(vType ENUM('PROCEDURE', 'FUNCTION'), + vChain VARCHAR(100), + vUserFk INT +) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Search if the user has privileges on routines. + * + * @param vType procedure or function + * @param vChain string passed with this syntax dbName.tableName + * @param vUserFk user to ckeck + * @return vHasPrivilege + */ + DECLARE vHasPrivilege BOOL DEFAULT FALSE; + DECLARE vDb VARCHAR(50); + DECLARE vObject VARCHAR(50); + DECLARE vChainExists BOOL; + DECLARE vExecutePriv INT DEFAULT 262144; + -- 262144 = CONV(1000000000000000000, 2, 10) + -- 1000000000000000000 execution permission expressed in binary base + + SET vDb = SUBSTRING_INDEX(vChain, '.', 1); + SET vChain = SUBSTRING(vChain, LENGTH(vDb) + 2); + SET vObject = SUBSTRING_INDEX(vChain, '.', 1); + + SELECT COUNT(*) INTO vChainExists + FROM mysql.proc + WHERE db = vDb + AND `name` = vObject + AND `type` = vType + LIMIT 1; + + IF NOT vChainExists THEN + RETURN FALSE; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tRole; + CREATE TEMPORARY TABLE tRole + (INDEX (`name`)) + ENGINE = MEMORY + SELECT r.`name` + FROM user u + JOIN roleRole rr ON rr.role = u.role + JOIN `role` r ON r.id = rr.inheritsFrom + WHERE u.id = vUserFk; + + SELECT TRUE INTO vHasPrivilege + FROM mysql.global_priv gp + JOIN tRole tr ON tr.name = gp.`User` + OR CONCAT('$', tr.name) = gp.`User` + WHERE JSON_VALUE(gp.Priv, '$.access') >= vExecutePriv + AND gp.Host = '' + LIMIT 1; + + IF NOT vHasPrivilege THEN + SELECT TRUE INTO vHasPrivilege + FROM mysql.db db + JOIN tRole tr ON tr.name = db.`User` + WHERE db.Db = vDb + AND db.Execute_priv = 'Y'; + END IF; + + IF NOT vHasPrivilege THEN + SELECT TRUE INTO vHasPrivilege + FROM mysql.procs_priv pp + JOIN tRole tr ON tr.name = pp.`User` + WHERE pp.Db = vDb + AND pp.Routine_name = vObject + AND pp.Routine_type = vType + AND pp.Proc_priv = 'Execute' + LIMIT 1; + END IF; + + DROP TEMPORARY TABLE tRole; + RETURN vHasPrivilege; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/account_enable.sql b/db/routines/account/procedures/account_enable.sql new file mode 100644 index 000000000..9f43c97a3 --- /dev/null +++ b/db/routines/account/procedures/account_enable.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`account_enable`(vSelf INT) +BEGIN +/** + * Enables an account and sets up email configuration. + */ + UPDATE user + SET active = TRUE + WHERE id = vSelf; + + INSERT IGNORE INTO account + SET id = vSelf; + + INSERT IGNORE INTO mailAliasAccount (mailAlias, account) + SELECT id, vSelf + FROM mailAlias + WHERE alias = 'general'; + + INSERT IGNORE INTO mailForward (account, forwardTo) + SELECT vSelf, email + FROM user + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/myUser_login.sql b/db/routines/account/procedures/myUser_login.sql new file mode 100644 index 000000000..be547292e --- /dev/null +++ b/db/routines/account/procedures/myUser_login.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`myUser_login`(vUserName VARCHAR(255), vPassword VARCHAR(255)) + READS SQL DATA +BEGIN +/** + * Logs in using the user credentials. + * + * @param vUserName The user name + * @param vPassword The user password + */ + DECLARE vAuthIsOk BOOLEAN DEFAULT FALSE; + + SELECT COUNT(*) = 1 INTO vAuthIsOk FROM user + WHERE name = vUserName + AND password = MD5(vPassword) + AND active; + + IF vAuthIsOk + THEN + CALL myUser_loginWithName (vUserName); + ELSE + CALL util.throw ('INVALID_CREDENTIALS'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/myUser_loginWithKey.sql b/db/routines/account/procedures/myUser_loginWithKey.sql new file mode 100644 index 000000000..67d8c9923 --- /dev/null +++ b/db/routines/account/procedures/myUser_loginWithKey.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`myUser_loginWithKey`(vUserName VARCHAR(255), vKey VARCHAR(255)) + READS SQL DATA +BEGIN +/** + * Logs in using the user name and MySQL master key. + * + * @param vUserName The user name + * @param vKey The MySQL master key + */ + DECLARE vLoginKey VARCHAR(255); + + SELECT loginKey INTO vLoginKey FROM userConfig; + + IF vLoginKey = vKey THEN + CALL myUser_loginWithName(vUserName); + ELSE + CALL util.throw('INVALID_KEY'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/myUser_loginWithName.sql b/db/routines/account/procedures/myUser_loginWithName.sql new file mode 100644 index 000000000..522da77dd --- /dev/null +++ b/db/routines/account/procedures/myUser_loginWithName.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`myUser_loginWithName`(vUserName VARCHAR(255)) + READS SQL DATA +BEGIN +/** + * Logs in using only the user name. This procedure is intended to be executed + * by users with a high level of privileges so that normal users should not have + * execute permissions on it. + * + * @param vUserName The user name + */ + DECLARE vUserId INT DEFAULT NULL; + DECLARE vKey VARCHAR(255); + + SELECT id INTO vUserId FROM user + WHERE name = vUserName; + + SELECT loginKey INTO vKey FROM userConfig; + + SET @userId = vUserId; + SET @userName = vUserName; + SET @userSignature = util.hmacSha2(256, CONCAT_WS('/', vUserId, vUserName), vKey); +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/myUser_logout.sql b/db/routines/account/procedures/myUser_logout.sql new file mode 100644 index 000000000..a1d7db361 --- /dev/null +++ b/db/routines/account/procedures/myUser_logout.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`myUser_logout`() +BEGIN +/** + * Logouts the user. + */ + SET @userId = NULL; + SET @userName = NULL; + SET @userSignature = NULL; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/role_checkName.sql b/db/routines/account/procedures/role_checkName.sql new file mode 100644 index 000000000..55d9d80a9 --- /dev/null +++ b/db/routines/account/procedures/role_checkName.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`role_checkName`(vRoleName VARCHAR(255)) +BEGIN +/** + * Checks that role name meets the necessary syntax requirements, otherwise it + * throws an exception. + * Role name must be written in camelCase. + * + * @param vRoleName The role name + */ + IF BINARY vRoleName NOT REGEXP '^[a-z][a-zA-Z]+$' THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Role name must be written in camelCase'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/role_getDescendents.sql b/db/routines/account/procedures/role_getDescendents.sql new file mode 100644 index 000000000..ecd4a8790 --- /dev/null +++ b/db/routines/account/procedures/role_getDescendents.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`role_getDescendents`(vSelf INT) +BEGIN +/** + * Gets the identifiers of all the subroles implemented by a role (Including + * itself). + * + * @param vSelf The role identifier + * @table tmp.role Subroles implemented by the role + */ + DECLARE vIsRoot BOOL; + + DROP TEMPORARY TABLE IF EXISTS + tmp.role, parents, childs; + + CREATE TEMPORARY TABLE tmp.role + (UNIQUE (id)) + ENGINE = MEMORY + SELECT vSelf AS id; + + CREATE TEMPORARY TABLE parents + ENGINE = MEMORY + SELECT vSelf AS id; + + CREATE TEMPORARY TABLE childs + LIKE parents; + + REPEAT + DELETE FROM childs; + INSERT INTO childs + SELECT DISTINCT r.inheritsFrom id + FROM parents p + JOIN roleInherit r ON r.role = p.id + LEFT JOIN tmp.role t ON t.id = r.inheritsFrom + WHERE t.id IS NULL; + + DELETE FROM parents; + INSERT INTO parents + SELECT * FROM childs; + + INSERT INTO tmp.role + SELECT * FROM childs; + + UNTIL ROW_COUNT() <= 0 + END REPEAT; + + -- If it is root all the roles are added + + SELECT COUNT(*) > 0 INTO vIsRoot + FROM tmp.role t + JOIN role r ON r.id = t.id + WHERE r.`name` = 'root'; + + IF vIsRoot THEN + INSERT IGNORE INTO tmp.role (id) + SELECT id FROM role; + END IF; + + -- Cleaning + + DROP TEMPORARY TABLE + parents, childs; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/role_sync.sql b/db/routines/account/procedures/role_sync.sql new file mode 100644 index 000000000..139193a31 --- /dev/null +++ b/db/routines/account/procedures/role_sync.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`role_sync`() +BEGIN +/** + * Synchronize the @roleRole table with the current role hierarchy. This + * procedure must be called every time the @roleInherit table is modified so + * that the changes made on it are effective. + */ + DECLARE vRoleId INT; + DECLARE vDone BOOL; + + DECLARE cur CURSOR FOR + SELECT id FROM role; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tRoleRole; + CREATE TEMPORARY TABLE tRoleRole + ENGINE = MEMORY + SELECT * FROM roleRole LIMIT 0; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vRoleId; + + IF vDone THEN + LEAVE l; + END IF; + + CALL role_getDescendents(vRoleId); + + INSERT INTO tRoleRole (role, inheritsFrom) + SELECT vRoleId, id FROM tmp.role; + + DROP TEMPORARY TABLE tmp.role; + END LOOP; + + CLOSE cur; + + START TRANSACTION; + DELETE FROM roleRole; + INSERT INTO roleRole SELECT * FROM tRoleRole; + COMMIT; + + DROP TEMPORARY TABLE tRoleRole; + + CALL role_syncPrivileges; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/role_syncPrivileges.sql b/db/routines/account/procedures/role_syncPrivileges.sql new file mode 100644 index 000000000..cf265b4bd --- /dev/null +++ b/db/routines/account/procedures/role_syncPrivileges.sql @@ -0,0 +1,565 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`role_syncPrivileges`() +BEGIN +/** + * Synchronizes permissions of MySQL role users based on role hierarchy. + * The computed role users of permission mix will be named according to + * pattern [vGenRolePrefix][roleName]. + * + * If [vTplUser]@[vRoleHost] user exists, it will be taken as a template for + * basic attributes. + * + * Warning! This procedure should only be called when MySQL privileges + * are modified. If role hierarchy is modified, you must call the role_sync() + * procedure wich calls this internally. + */ + DECLARE vIsMariaDb BOOL DEFAULT VERSION() LIKE '%MariaDB%'; + DECLARE vVersion INT DEFAULT SUBSTRING_INDEX(VERSION(), '.', 1); + DECLARE vTplUser VARCHAR(255); + DECLARE vRoleHost VARCHAR(255); + DECLARE vUserPrefix VARCHAR(2); + DECLARE vUserHost VARCHAR(255); + DECLARE vGenRolePrefix VARCHAR(2); + DECLARE vGenRoleHost VARCHAR(255); + DECLARE vPrefixedLike VARCHAR(255); + DECLARE vPassword VARCHAR(255) DEFAULT ''; + + SELECT rolePrefix, userPrefix, userHost, tplUser + INTO vGenRolePrefix, vUserPrefix, vUserHost, vTplUser + FROM roleConfig; + + -- Deletes computed role users + + SET vPrefixedLike = CONCAT(vGenRolePrefix, '%'); + SET vGenRoleHost = vUserHost; + + IF vIsMariaDb THEN + SET vRoleHost = ''; + + DELETE FROM mysql.global_priv + WHERE `User` LIKE vPrefixedLike; + + DELETE FROM mysql.roles_mapping + WHERE `User` LIKE vPrefixedLike + OR ( + `Role` LIKE vPrefixedLike + AND (`User`, `Host`) = ('root', 'localhost') + ); + ELSE + SET vRoleHost = 'localhost'; + + DELETE FROM mysql.user + WHERE `User` LIKE vPrefixedLike; + END IF; + + DELETE FROM mysql.db + WHERE `User` LIKE vPrefixedLike; + + DELETE FROM mysql.tables_priv + WHERE `User` LIKE vPrefixedLike; + + DELETE FROM mysql.columns_priv + WHERE `User` LIKE vPrefixedLike; + + DELETE FROM mysql.procs_priv + WHERE `User` LIKE vPrefixedLike; + + DELETE FROM mysql.proxies_priv + WHERE `Proxied_user` LIKE vPrefixedLike; + + -- Temporary tables + + DROP TEMPORARY TABLE IF EXISTS tRole; + CREATE TEMPORARY TABLE tRole + (INDEX (id)) + ENGINE = MEMORY + SELECT + id, + `name` `role`, + CONCAT(vGenRolePrefix, `name`) prefixedRole + FROM `role` + WHERE hasLogin; + + -- Get role inheritance + + DROP TEMPORARY TABLE IF EXISTS tRoleInherit; + CREATE TEMPORARY TABLE tRoleInherit + (INDEX (inheritsFrom)) + ENGINE = MEMORY + SELECT + r.prefixedRole, + ri.`name` inheritsFrom + FROM tRole r + JOIN `roleRole` rr ON rr.role = r.id + JOIN `role` ri ON ri.id = rr.inheritsFrom + JOIN mysql.`user` u + ON u.`User` = ri.`name` AND u.`Host` = vRoleHost; + + -- Recreate role users + + IF vIsMariaDb THEN + -- Roles + + INSERT INTO mysql.global_priv (`Host`, `User`, `Priv`) + SELECT vRoleHost, prefixedRole, + JSON_OBJECT( + 'is_role', TRUE, + 'access', 0 + ) + FROM tRole r + UNION + SELECT vRoleHost, CONCAT(vGenRolePrefix, 'root'), + JSON_OBJECT( + 'is_role', TRUE, + 'access', 0 + ); + + INSERT INTO mysql.roles_mapping (`Host`, `User`, `Role`, `Admin_option`) + SELECT vRoleHost, prefixedRole, inheritsFrom, 'N' + FROM tRoleInherit + UNION + SELECT vRoleHost, CONCAT(vGenRolePrefix, 'root'), prefixedRole, 'Y' + FROM tRole; + + INSERT INTO mysql.roles_mapping (`Host`, `User`, `Role`, `Admin_option`) + SELECT 'localhost', 'root', prefixedRole, 'Y' + FROM tRole + UNION + SELECT 'localhost', 'root', CONCAT(vGenRolePrefix, 'root'), 'Y'; + + -- Role users + + INSERT INTO mysql.global_priv ( + `User`, + `Host`, + `Priv` + ) + SELECT + r.prefixedRole, + vGenRoleHost, + JSON_MERGE_PATCH( + IFNULL(t.`Priv`, '{}'), + IFNULL(u.`Priv`, '{}'), + JSON_OBJECT( + 'mysql_old_password', JSON_VALUE(t.`Priv`, '$.mysql_old_password'), + 'mysql_native_password', JSON_VALUE(t.`Priv`, '$.mysql_native_password'), + 'authentication_string', JSON_VALUE(t.`Priv`, '$.authentication_string'), + 'ssl_type', JSON_VALUE(t.`Priv`, '$.ssl_type'), + 'default_role', r.prefixedRole, + 'access', 0, + 'is_role', FALSE + ) + ) + FROM tRole r + LEFT JOIN mysql.global_priv t + ON (t.`User`, t.Host) = (vTplUser, vRoleHost) + LEFT JOIN mysql.global_priv u + ON (u.`User`, u.Host) = (r.`role`, vRoleHost); + + INSERT INTO mysql.roles_mapping (`Host`, `User`, `Role`, `Admin_option`) + SELECT vGenRoleHost, prefixedRole, prefixedRole, 'N' + FROM tRole; + + -- Accounts + + DROP TEMPORARY TABLE IF EXISTS tAccounts; + CREATE TEMPORARY TABLE tAccounts + (INDEX (`name`)) + ENGINE = MEMORY + SELECT p.`User` `name`, r.prefixedRole + FROM mysql.global_priv p + JOIN `user` u ON u.`name` = p.`User` + JOIN tRole r ON r.`id` = u.`role` + WHERE JSON_EXTRACT(p.`Priv`, '$.autogenerated') = 'true'; + + UPDATE mysql.global_priv p + JOIN tAccounts c ON c.`name` = p.`User` + SET p.`Priv` = JSON_SET(p.`Priv`, '$.default_role', c.prefixedRole) + WHERE p.`Host` = vUserHost; + + UPDATE IGNORE mysql.roles_mapping m + JOIN tAccounts c ON c.`name` = m.`User` + SET m.`Role` = c.prefixedRole + WHERE m.`Host` = vUserHost; + + DROP TEMPORARY TABLE tAccounts; + ELSE + DROP TEMPORARY TABLE IF EXISTS tUser; + CREATE TEMPORARY TABLE tUser + SELECT + r.prefixedRole `User`, + vGenRoleHost `Host`, + IFNULL(t.`authentication_string`, + '') `authentication_string`, + IFNULL(t.`plugin`, + 'mysql_native_password') `plugin`, + IFNULL(IF('' != u.`ssl_type`, + u.`ssl_type`, t.`ssl_type`), + '') `ssl_type`, + IFNULL(IF('' != u.`ssl_cipher`, + u.`ssl_cipher`, t.`ssl_cipher`), + '') `ssl_cipher`, + IFNULL(IF('' != u.`x509_issuer`, + u.`x509_issuer`, t.`x509_issuer`), + '') `x509_issuer`, + IFNULL(IF('' != u.`x509_subject`, + u.`x509_subject`, t.`x509_subject`), + '') `x509_subject`, + IFNULL(IF(0 != u.`max_questions`, + u.`max_questions`, t.`max_questions`), + 0) `max_questions`, + IFNULL(IF(0 != u.`max_updates`, + u.`max_updates`, t.`max_updates`), + 0) `max_updates`, + IFNULL(IF(0 != u.`max_connections`, + u.`max_connections`, t.`max_connections`), + 0) `max_connections`, + IFNULL(IF(0 != u.`max_user_connections`, + u.`max_user_connections`, t.`max_user_connections`), + 0) `max_user_connections` + FROM tRole r + LEFT JOIN mysql.user t + ON t.`User` = vTplUser + AND t.`Host` = vRoleHost + LEFT JOIN mysql.user u + ON u.`User` = r.role + AND u.`Host` = vRoleHost; + + IF vVersion <= 5 THEN + SELECT `Password` INTO vPassword + FROM mysql.user + WHERE `User` = vTplUser + AND `Host` = vRoleHost; + + INSERT INTO mysql.user ( + `User`, + `Host`, + `Password`, + `authentication_string`, + `plugin`, + `ssl_type`, + `ssl_cipher`, + `x509_issuer`, + `x509_subject`, + `max_questions`, + `max_updates`, + `max_connections`, + `max_user_connections` + ) + SELECT + `User`, + `Host`, + vPassword, + `authentication_string`, + `plugin`, + `ssl_type`, + `ssl_cipher`, + `x509_issuer`, + `x509_subject`, + `max_questions`, + `max_updates`, + `max_connections`, + `max_user_connections` + FROM tUser; + ELSE + INSERT INTO mysql.user ( + `User`, + `Host`, + `authentication_string`, + `plugin`, + `ssl_type`, + `ssl_cipher`, + `x509_issuer`, + `x509_subject`, + `max_questions`, + `max_updates`, + `max_connections`, + `max_user_connections` + ) + SELECT + `User`, + `Host`, + `authentication_string`, + `plugin`, + `ssl_type`, + `ssl_cipher`, + `x509_issuer`, + `x509_subject`, + `max_questions`, + `max_updates`, + `max_connections`, + `max_user_connections` + FROM tUser; + END IF; + + DROP TEMPORARY TABLE tUser; + + -- Proxy privileges + + INSERT INTO mysql.proxies_priv ( + `User`, + `Host`, + `Proxied_user`, + `Proxied_host`, + `Grantor` + ) + SELECT + '', + vUserHost, + prefixedRole, + vGenRoleHost, + CONCAT(prefixedRole, '@', vGenRoleHost) + FROM tRole; + + -- Global privileges + + DROP TEMPORARY TABLE IF EXISTS tUserPriv; + CREATE TEMPORARY TABLE tUserPriv + (INDEX (prefixedRole)) + ENGINE = MEMORY + SELECT + r.prefixedRole, + MAX(u.`Select_priv`) `Select_priv`, + MAX(u.`Insert_priv`) `Insert_priv`, + MAX(u.`Update_priv`) `Update_priv`, + MAX(u.`Delete_priv`) `Delete_priv`, + MAX(u.`Create_priv`) `Create_priv`, + MAX(u.`Drop_priv`) `Drop_priv`, + MAX(u.`Reload_priv`) `Reload_priv`, + MAX(u.`Shutdown_priv`) `Shutdown_priv`, + MAX(u.`Process_priv`) `Process_priv`, + MAX(u.`File_priv`) `File_priv`, + MAX(u.`Grant_priv`) `Grant_priv`, + MAX(u.`References_priv`) `References_priv`, + MAX(u.`Index_priv`) `Index_priv`, + MAX(u.`Alter_priv`) `Alter_priv`, + MAX(u.`Show_db_priv`) `Show_db_priv`, + MAX(u.`Super_priv`) `Super_priv`, + MAX(u.`Create_tmp_table_priv`) `Create_tmp_table_priv`, + MAX(u.`Lock_tables_priv`) `Lock_tables_priv`, + MAX(u.`Execute_priv`) `Execute_priv`, + MAX(u.`Repl_slave_priv`) `Repl_slave_priv`, + MAX(u.`Repl_client_priv`) `Repl_client_priv`, + MAX(u.`Create_view_priv`) `Create_view_priv`, + MAX(u.`Show_view_priv`) `Show_view_priv`, + MAX(u.`Create_routine_priv`) `Create_routine_priv`, + MAX(u.`Alter_routine_priv`) `Alter_routine_priv`, + MAX(u.`Create_user_priv`) `Create_user_priv`, + MAX(u.`Event_priv`) `Event_priv`, + MAX(u.`Trigger_priv`) `Trigger_priv`, + MAX(u.`Create_tablespace_priv`) `Create_tablespace_priv` + FROM tRoleInherit r + JOIN mysql.user u + ON u.`User` = r.inheritsFrom + AND u.`Host`= vRoleHost + GROUP BY r.prefixedRole; + + UPDATE mysql.user u + JOIN tUserPriv t + ON u.`User` = t.prefixedRole + AND u.`Host` = vGenRoleHost + SET + u.`Select_priv` + = t.`Select_priv`, + u.`Insert_priv` + = t.`Insert_priv`, + u.`Update_priv` + = t.`Update_priv`, + u.`Delete_priv` + = t.`Delete_priv`, + u.`Create_priv` + = t.`Create_priv`, + u.`Drop_priv` + = t.`Drop_priv`, + u.`Reload_priv` + = t.`Reload_priv`, + u.`Shutdown_priv` + = t.`Shutdown_priv`, + u.`Process_priv` + = t.`Process_priv`, + u.`File_priv` + = t.`File_priv`, + u.`Grant_priv` + = t.`Grant_priv`, + u.`References_priv` + = t.`References_priv`, + u.`Index_priv` + = t.`Index_priv`, + u.`Alter_priv` + = t.`Alter_priv`, + u.`Show_db_priv` + = t.`Show_db_priv`, + u.`Super_priv` + = t.`Super_priv`, + u.`Create_tmp_table_priv` + = t.`Create_tmp_table_priv`, + u.`Lock_tables_priv` + = t.`Lock_tables_priv`, + u.`Execute_priv` + = t.`Execute_priv`, + u.`Repl_slave_priv` + = t.`Repl_slave_priv`, + u.`Repl_client_priv` + = t.`Repl_client_priv`, + u.`Create_view_priv` + = t.`Create_view_priv`, + u.`Show_view_priv` + = t.`Show_view_priv`, + u.`Create_routine_priv` + = t.`Create_routine_priv`, + u.`Alter_routine_priv` + = t.`Alter_routine_priv`, + u.`Create_user_priv` + = t.`Create_user_priv`, + u.`Event_priv` + = t.`Event_priv`, + u.`Trigger_priv` + = t.`Trigger_priv`, + u.`Create_tablespace_priv` + = t.`Create_tablespace_priv`; + + DROP TEMPORARY TABLE tUserPriv; + + -- Schema level privileges + + INSERT INTO mysql.db ( + `User`, + `Host`, + `Db`, + `Select_priv`, + `Insert_priv`, + `Update_priv`, + `Delete_priv`, + `Create_priv`, + `Drop_priv`, + `Grant_priv`, + `References_priv`, + `Index_priv`, + `Alter_priv`, + `Create_tmp_table_priv`, + `Lock_tables_priv`, + `Create_view_priv`, + `Show_view_priv`, + `Create_routine_priv`, + `Alter_routine_priv`, + `Execute_priv`, + `Event_priv`, + `Trigger_priv` + ) + SELECT + r.prefixedRole, + vGenRoleHost, + t.`Db`, + MAX(t.`Select_priv`), + MAX(t.`Insert_priv`), + MAX(t.`Update_priv`), + MAX(t.`Delete_priv`), + MAX(t.`Create_priv`), + MAX(t.`Drop_priv`), + MAX(t.`Grant_priv`), + MAX(t.`References_priv`), + MAX(t.`Index_priv`), + MAX(t.`Alter_priv`), + MAX(t.`Create_tmp_table_priv`), + MAX(t.`Lock_tables_priv`), + MAX(t.`Create_view_priv`), + MAX(t.`Show_view_priv`), + MAX(t.`Create_routine_priv`), + MAX(t.`Alter_routine_priv`), + MAX(t.`Execute_priv`), + MAX(t.`Event_priv`), + MAX(t.`Trigger_priv`) + FROM tRoleInherit r + JOIN mysql.db t + ON t.`User` = r.inheritsFrom + AND t.`Host`= vRoleHost + GROUP BY r.prefixedRole, t.`Db`; + + -- Table level privileges + + INSERT INTO mysql.tables_priv ( + `User`, + `Host`, + `Db`, + `Table_name`, + `Grantor`, + `Timestamp`, + `Table_priv`, + `Column_priv` + ) + SELECT + r.prefixedRole, + vGenRoleHost, + t.`Db`, + t.`Table_name`, + t.`Grantor`, + MAX(t.`Timestamp`), + IFNULL(GROUP_CONCAT(NULLIF(t.`Table_priv`, '')), ''), + IFNULL(GROUP_CONCAT(NULLIF(t.`Column_priv`, '')), '') + FROM tRoleInherit r + JOIN mysql.tables_priv t + ON t.`User` = r.inheritsFrom + AND t.`Host`= vRoleHost + GROUP BY r.prefixedRole, t.`Db`, t.`Table_name`; + + -- Column level privileges + + INSERT INTO mysql.columns_priv ( + `User`, + `Host`, + `Db`, + `Table_name`, + `Column_name`, + `Timestamp`, + `Column_priv` + ) + SELECT + r.prefixedRole, + vGenRoleHost, + t.`Db`, + t.`Table_name`, + t.`Column_name`, + MAX(t.`Timestamp`), + IFNULL(GROUP_CONCAT(NULLIF(t.`Column_priv`, '')), '') + FROM tRoleInherit r + JOIN mysql.columns_priv t + ON t.`User` = r.inheritsFrom + AND t.`Host`= vRoleHost + GROUP BY r.prefixedRole, t.`Db`, t.`Table_name`, t.`Column_name`; + + -- Routine privileges + + INSERT IGNORE INTO mysql.procs_priv ( + `User`, + `Host`, + `Db`, + `Routine_name`, + `Routine_type`, + `Grantor`, + `Timestamp`, + `Proc_priv` + ) + SELECT + r.prefixedRole, + vGenRoleHost, + t.`Db`, + t.`Routine_name`, + t.`Routine_type`, + t.`Grantor`, + t.`Timestamp`, + t.`Proc_priv` + FROM tRoleInherit r + JOIN mysql.procs_priv t + ON t.`User` = r.inheritsFrom + AND t.`Host`= vRoleHost; + END IF; + + -- Cleanup + + DROP TEMPORARY TABLE + tRole, + tRoleInherit; + + FLUSH PRIVILEGES; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/user_checkName.sql b/db/routines/account/procedures/user_checkName.sql new file mode 100644 index 000000000..4f954ad00 --- /dev/null +++ b/db/routines/account/procedures/user_checkName.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`user_checkName`(vUserName VARCHAR(255)) +BEGIN +/** + * Checks that username meets the necessary syntax requirements, otherwise it + * throws an exception. + * The user name must only contain lowercase letters or, starting with second + * character, numbers or underscores. + */ + IF vUserName NOT REGEXP '^[a-z0-9_-]*$' THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'INVALID_USER_NAME'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/procedures/user_checkPassword.sql b/db/routines/account/procedures/user_checkPassword.sql new file mode 100644 index 000000000..eb0990533 --- /dev/null +++ b/db/routines/account/procedures/user_checkPassword.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `account`.`user_checkPassword`(vPassword VARCHAR(255)) +BEGIN +/** + * Comprueba si la contraseña cumple los requisitos de seguridad + * establecidos. Lanza una excepción si no se cumplen. + * + * @param vPassword Contraseña a comprobar + */ + DECLARE vChr CHAR(1); + DECLARE vPasswordOk TINYINT; + DECLARE vI TINYINT DEFAULT 1; + DECLARE vNAlpha TINYINT DEFAULT 0; + DECLARE vNUpper TINYINT DEFAULT 0; + DECLARE vNDigits TINYINT DEFAULT 0; + DECLARE vNPunct TINYINT DEFAULT 0; + + WHILE vI <= CHAR_LENGTH(vPassword) + DO + SET vChr = SUBSTRING(vPassword, vI, 1); + + IF vChr REGEXP '[[:alpha:]]' + THEN + SET vNAlpha = vNAlpha+1; + + IF vChr REGEXP '[A-Z]' + THEN + SET vNUpper = vNUpper+1; + END IF; + ELSEIF vChr REGEXP '[[:digit:]]' + THEN + SET vNDigits = vNDigits+1; + ELSEIF vChr REGEXP '[[:punct:]]' + THEN + SET vNPunct = vNPunct+1; + END IF; + + SET vI = vI+1; + END WHILE; + + SELECT + CHAR_LENGTH(vPassword) >= length + AND vNAlpha >= nAlpha + AND vNUpper >= nUpper + AND vNDigits >= nDigits + AND vNPunct >= nPunct + INTO vPasswordOk + FROM userPassword LIMIT 1; + + IF NOT vPasswordOk THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Password does not meet requirements'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/account_afterDelete.sql b/db/routines/account/triggers/account_afterDelete.sql new file mode 100644 index 000000000..be0e5901f --- /dev/null +++ b/db/routines/account/triggers/account_afterDelete.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`account_afterDelete` + AFTER DELETE ON `account` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'Account', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + INSERT IGNORE INTO userSync (`name`) + SELECT `name` FROM `user` WHERE id = OLD.id; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/account_afterInsert.sql b/db/routines/account/triggers/account_afterInsert.sql new file mode 100644 index 000000000..be2959ab6 --- /dev/null +++ b/db/routines/account/triggers/account_afterInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`account_afterInsert` + AFTER INSERT ON `account` + FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync (`name`) + SELECT `name` FROM `user` WHERE id = NEW.id; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/account_beforeInsert.sql b/db/routines/account/triggers/account_beforeInsert.sql new file mode 100644 index 000000000..43b611990 --- /dev/null +++ b/db/routines/account/triggers/account_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`account_beforeInsert` + BEFORE INSERT ON `account` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/account_beforeUpdate.sql b/db/routines/account/triggers/account_beforeUpdate.sql new file mode 100644 index 000000000..bbcea028d --- /dev/null +++ b/db/routines/account/triggers/account_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`account_beforeUpdate` + BEFORE UPDATE ON `account` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/mailAlias_afterDelete.sql b/db/routines/account/triggers/mailAlias_afterDelete.sql new file mode 100644 index 000000000..fe944246d --- /dev/null +++ b/db/routines/account/triggers/mailAlias_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAlias_afterDelete` + AFTER DELETE ON `mailAlias` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'MailAlias', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/mailAlias_beforeInsert.sql b/db/routines/account/triggers/mailAlias_beforeInsert.sql new file mode 100644 index 000000000..37a9546ca --- /dev/null +++ b/db/routines/account/triggers/mailAlias_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAlias_beforeInsert` + BEFORE INSERT ON `mailAlias` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/mailAlias_beforeUpdate.sql b/db/routines/account/triggers/mailAlias_beforeUpdate.sql new file mode 100644 index 000000000..e3940cfda --- /dev/null +++ b/db/routines/account/triggers/mailAlias_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAlias_beforeUpdate` + BEFORE UPDATE ON `mailAlias` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/mailForward_afterDelete.sql b/db/routines/account/triggers/mailForward_afterDelete.sql new file mode 100644 index 000000000..cb02b746d --- /dev/null +++ b/db/routines/account/triggers/mailForward_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailForward_afterDelete` + AFTER DELETE ON `mailForward` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'MailForward', + `changedModelId` = OLD.account, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/mailForward_beforeInsert.sql b/db/routines/account/triggers/mailForward_beforeInsert.sql new file mode 100644 index 000000000..bc4e5ef17 --- /dev/null +++ b/db/routines/account/triggers/mailForward_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailForward_beforeInsert` + BEFORE INSERT ON `mailForward` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/mailForward_beforeUpdate.sql b/db/routines/account/triggers/mailForward_beforeUpdate.sql new file mode 100644 index 000000000..88594979a --- /dev/null +++ b/db/routines/account/triggers/mailForward_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailForward_beforeUpdate` + BEFORE UPDATE ON `mailForward` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/roleInherit_afterDelete.sql b/db/routines/account/triggers/roleInherit_afterDelete.sql new file mode 100644 index 000000000..c7c82eedb --- /dev/null +++ b/db/routines/account/triggers/roleInherit_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`roleInherit_afterDelete` + AFTER DELETE ON `roleInherit` + FOR EACH ROW +BEGIN + INSERT INTO roleLog + SET `action` = 'delete', + `changedModel` = 'RoleInherit', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/roleInherit_beforeInsert.sql b/db/routines/account/triggers/roleInherit_beforeInsert.sql new file mode 100644 index 000000000..77932c12d --- /dev/null +++ b/db/routines/account/triggers/roleInherit_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`roleInherit_beforeInsert` + BEFORE INSERT ON `roleInherit` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/roleInherit_beforeUpdate.sql b/db/routines/account/triggers/roleInherit_beforeUpdate.sql new file mode 100644 index 000000000..05aef0b95 --- /dev/null +++ b/db/routines/account/triggers/roleInherit_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`roleInherit_beforeUpdate` + BEFORE UPDATE ON `roleInherit` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/role_afterDelete.sql b/db/routines/account/triggers/role_afterDelete.sql new file mode 100644 index 000000000..be382cba6 --- /dev/null +++ b/db/routines/account/triggers/role_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`role_afterDelete` + AFTER DELETE ON `role` + FOR EACH ROW +BEGIN + INSERT INTO roleLog + SET `action` = 'delete', + `changedModel` = 'Role', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/role_beforeInsert.sql b/db/routines/account/triggers/role_beforeInsert.sql new file mode 100644 index 000000000..f68a211a7 --- /dev/null +++ b/db/routines/account/triggers/role_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`role_beforeInsert` + BEFORE INSERT ON `role` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL role_checkName(NEW.`name`); +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/role_beforeUpdate.sql b/db/routines/account/triggers/role_beforeUpdate.sql new file mode 100644 index 000000000..a2f471b64 --- /dev/null +++ b/db/routines/account/triggers/role_beforeUpdate.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`role_beforeUpdate` + BEFORE UPDATE ON `role` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + IF !(NEW.`name` <=> OLD.`name`) THEN + CALL role_checkName (NEW.`name`); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/user_afterDelete.sql b/db/routines/account/triggers/user_afterDelete.sql new file mode 100644 index 000000000..eabe60d8c --- /dev/null +++ b/db/routines/account/triggers/user_afterDelete.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_afterDelete` + AFTER DELETE ON `user` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'User', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL hedera.image_unref('user', OLD.image); + + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/user_afterInsert.sql b/db/routines/account/triggers/user_afterInsert.sql new file mode 100644 index 000000000..31f992c16 --- /dev/null +++ b/db/routines/account/triggers/user_afterInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_afterInsert` + AFTER INSERT ON `user` + FOR EACH ROW +BEGIN + CALL hedera.image_ref('user', NEW.image); + + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/user_afterUpdate.sql b/db/routines/account/triggers/user_afterUpdate.sql new file mode 100644 index 000000000..7fb4e644f --- /dev/null +++ b/db/routines/account/triggers/user_afterUpdate.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_afterUpdate` + AFTER UPDATE ON `user` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL hedera.image_unref('user', OLD.image); + CALL hedera.image_ref('user', NEW.image); + END IF; + + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; + + IF !(OLD.`name` <=> NEW.`name`) THEN + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/user_beforeInsert.sql b/db/routines/account/triggers/user_beforeInsert.sql new file mode 100644 index 000000000..6cafa8b3f --- /dev/null +++ b/db/routines/account/triggers/user_beforeInsert.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_beforeInsert` + BEFORE INSERT ON `user` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + CALL user_checkName(NEW.`name`); + + IF NEW.nickname = '' THEN + SET NEW.nickname = NEW.`name`; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/triggers/user_beforeUpdate.sql b/db/routines/account/triggers/user_beforeUpdate.sql new file mode 100644 index 000000000..849dfbd91 --- /dev/null +++ b/db/routines/account/triggers/user_beforeUpdate.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`user_beforeUpdate` + BEFORE UPDATE ON `user` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF !(NEW.`name` <=> OLD.`name`) THEN + CALL user_checkName (NEW.`name`); + END IF; + + IF !(NEW.`password` <=> OLD.`password`) THEN + SET NEW.lastPassChange = util.VN_NOW(); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/account/views/accountDovecot.sql b/db/routines/account/views/accountDovecot.sql new file mode 100644 index 000000000..1e30946f3 --- /dev/null +++ b/db/routines/account/views/accountDovecot.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `account`.`accountDovecot` +AS SELECT `u`.`name` AS `name`, + `u`.`password` AS `password` +FROM ( + `account`.`user` `u` + JOIN `account`.`account` `a` ON(`a`.`id` = `u`.`id`) + ) +WHERE `u`.`active` <> 0 diff --git a/db/routines/account/views/emailUser.sql b/db/routines/account/views/emailUser.sql new file mode 100644 index 000000000..dcb435454 --- /dev/null +++ b/db/routines/account/views/emailUser.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `account`.`emailUser` +AS SELECT `u`.`id` AS `userFk`, + concat(`u`.`name`, '@', `mc`.`domain`) AS `email` +FROM ( + `account`.`user` `u` + JOIN `account`.`mailConfig` `mc` + ) diff --git a/db/routines/account/views/myRole.sql b/db/routines/account/views/myRole.sql new file mode 100644 index 000000000..68364f0bc --- /dev/null +++ b/db/routines/account/views/myRole.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `account`.`myRole` +AS SELECT `r`.`inheritsFrom` AS `id` +FROM ( + `account`.`roleRole` `r` + JOIN `account`.`user` `u` ON(`u`.`role` = `r`.`role`) + ) +WHERE `u`.`id` = `myUser_getId`() diff --git a/db/routines/account/views/myUser.sql b/db/routines/account/views/myUser.sql new file mode 100644 index 000000000..f520d893b --- /dev/null +++ b/db/routines/account/views/myUser.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `account`.`myUser` +AS SELECT `u`.`id` AS `id`, + `u`.`name` AS `name`, + `u`.`active` AS `active`, + `u`.`email` AS `email`, + `u`.`nickname` AS `nickname`, + `u`.`lang` AS `lang`, + `u`.`role` AS `role`, + `u`.`recoverPass` AS `recoverPass` +FROM `account`.`user` `u` +WHERE `u`.`name` = `myUser_getName`() +WITH CASCADED CHECK OPTION diff --git a/db/routines/bi/functions/nz.sql b/db/routines/bi/functions/nz.sql new file mode 100644 index 000000000..0d047703a --- /dev/null +++ b/db/routines/bi/functions/nz.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `bi`.`nz`(vData DOUBLE) + RETURNS double + DETERMINISTIC +BEGIN +/** + * Devuelve 0, si el parámetro es NULL: + */ + DECLARE vResult DOUBLE; + + SET vResult = IFNULL(vData,0); + + RETURN vResult; + +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/Greuge_Evolution_Add.sql b/db/routines/bi/procedures/Greuge_Evolution_Add.sql new file mode 100644 index 000000000..83033cbf8 --- /dev/null +++ b/db/routines/bi/procedures/Greuge_Evolution_Add.sql @@ -0,0 +1,115 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`Greuge_Evolution_Add`() +BEGIN +/* + Inserta en la tabla Greuge_Evolution el saldo acumulado de cada cliente, + así como las ventas acumuladas en los ultimos 365 dias, para poder controlar + su evolucion. +*/ + DECLARE datFEC DATE; + DECLARE datFEC_TOMORROW DATE; + DECLARE datFEC_LASTYEAR DATE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + + GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; + SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); + CALL vn.mail_insert( + 'jgallego@verdnatura.es,pako@verdnatura.es', + 'noreply@verdnatura.es', + 'Greuge_Evolution_Add', + CONCAT('ERROR ', IFNULL(@errno, 0), ': ', ifnull(@text, 'texto')) + ); + + END; + + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; + + DELETE FROM bi.Greuge_Evolution WHERE Fecha >= TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + + SELECT TIMESTAMPADD(DAY,1,MAX(Fecha)), + TIMESTAMPADD(DAY,2,MAX(Fecha)) + INTO datFEC, + datFEC_TOMORROW + FROM bi.Greuge_Evolution; + + SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); + + DELETE FROM bi.Greuge_Evolution WHERE Fecha >= datFEC; + + DROP TEMPORARY TABLE IF EXISTS maxInvoice; + + CREATE TEMPORARY TABLE maxInvoice + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha + FROM vn2008.Facturas + GROUP BY Id_Cliente + HAVING maxFecha < timestampadd(month,-2,datFEC); + + WHILE datFEC < util.VN_CURDATE() DO + + REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas, Fosil) + + SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 + FROM ( + SELECT Id_Cliente, sum(Importe) as Greuge + FROM vn2008.Greuges + where Fecha <= datFEC + group by Id_Cliente + ) sub + RIGHT JOIN + + ( + + SELECT Id_Cliente, sum(Ventas) as Ventas + FROM + ( + + SELECT Id_Cliente, IF (fecha != datFEC, -1,1) * (importe + recargo) as Ventas + FROM bs.ventas + WHERE fecha = datFEC or fecha = datFEC_LASTYEAR + + UNION ALL + + SELECT Id_Cliente, Ventas + FROM bi.Greuge_Evolution + WHERE Fecha = TIMESTAMPADD(DAY, -1, datFEC) + + ) sub + group by Id_Cliente + + ) v using(Id_Cliente) + ; + + -- Ahora calcularemos el greuge muerto + UPDATE bi.Greuge_Evolution ge + JOIN maxInvoice m using(Id_Cliente) + SET FOSIL = GREUGE + WHERE m.maxFecha < TIMESTAMPADD(MONTH,-2,ge.Fecha); + + -- Recobro + UPDATE bi.Greuge_Evolution ge + JOIN ( + SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe + FROM vn2008.Tickets t + JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna + JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento + WHERE t.Fecha >= datFEC + AND t.Fecha < datFEC_TOMORROW + AND mc.Id_Componente = 17 -- Recobro + GROUP BY cs.Id_Cliente + ) sub using(Id_Cliente) + SET Recobro = Importe + WHERE ge.Fecha = datFEC; + + SET datFEC = datFEC_TOMORROW; + SET datFEC_TOMORROW = TIMESTAMPADD(DAY,1,datFEC_TOMORROW); + SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS maxInvoice; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/analisis_ventas_evolution_add.sql b/db/routines/bi/procedures/analisis_ventas_evolution_add.sql new file mode 100644 index 000000000..fca749681 --- /dev/null +++ b/db/routines/bi/procedures/analisis_ventas_evolution_add.sql @@ -0,0 +1,232 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`analisis_ventas_evolution_add`() +BEGIN + DECLARE vPreviousPeriod INT; + DECLARE vCurrentPeriod INT; + DECLARE vLastPeriod INT; + DECLARE vMinPeriod INT DEFAULT 201400; + DECLARE vMaxPeriod INT; + DECLARE vYear INT; + DECLARE vWeek INT; + + SELECT t.period INTO vMaxPeriod + FROM vn.`time` t + WHERE t.dated = util.VN_CURDATE(); + + -- Almacen + + SET vCurrentPeriod = IFNULL(vLastPeriod, vMinPeriod); + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(Periodo) INTO vPreviousPeriod + FROM analisis_ventas_almacen_evolution + WHERE Periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_almacen_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_almacen_evolution(Almacen, Ventas, Semana,Año, Periodo) + SELECT Almacen, SUM(Ventas) AS Ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT almacen, SUM(Importe) AS Ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY almacen + UNION ALL + SELECT almacen, - SUM(Importe) AS Ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY almacen + UNION ALL + SELECT Almacen, Ventas + FROM analisis_ventas_almacen_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY Almacen; + END WHILE; + + -- Reino + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_reino_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_reino_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_reino_evolution(reino, ventas, semana,año, periodo) + SELECT reino, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT Reino, SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY Reino + UNION ALL + SELECT Reino, - SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY Reino + UNION ALL + SELECT reino, ventas + FROM analisis_ventas_reino_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY reino; + END WHILE; + + -- Provincia + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_provincia_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_provincia_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_provincia_evolution(provincia, countryCode, ventas, semana,año, periodo) + SELECT Provincia, code, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT a.Provincia, c.code, SUM(a.Importe) AS ventas + FROM analisis_ventas a + JOIN vn.province p ON p.name= a.provincia + JOIN vn.country c ON c.id = p.countryFk + WHERE vYear = a.Año + AND vWeek = a.Semana + GROUP BY a.Provincia + UNION ALL + SELECT a.Provincia, c.code, - SUM(a.Importe) AS ventas + FROM analisis_ventas a + JOIN vn.province p ON p.name= a.provincia + JOIN vn.country c ON c.id = p.countryFk + WHERE vYear - 1 = a.Año + AND vWeek = a.Semana + GROUP BY a.Provincia + UNION ALL + SELECT a.provincia,a.countryCode, a.ventas + FROM analisis_ventas_provincia_evolution a + WHERE a.Periodo = vPreviousPeriod + ) sub + GROUP BY Provincia; + + + END WHILE; + + -- Vista + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_vista_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_vista_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_vista_evolution(vista, ventas, semana,año, periodo) + SELECT vista, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT Vista, SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY Vista + UNION ALL + SELECT Vista, - SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY Vista + UNION ALL + SELECT vista, ventas + FROM analisis_ventas_vista_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY Vista; + END WHILE; + + -- Vendedor + + SET vCurrentPeriod = vMinPeriod; + + WHILE vCurrentPeriod < vMaxPeriod + DO + SELECT MAX(periodo) INTO vPreviousPeriod + FROM analisis_ventas_vendedor_evolution + WHERE periodo < vMaxPeriod; + + SELECT MIN(period) INTO vCurrentPeriod + FROM vn2008.time + WHERE period > vPreviousPeriod; + + SET vYear = FLOOR(vCurrentPeriod / 100); + SET vWeek = vCurrentPeriod - (vYear * 100); + + DELETE FROM analisis_ventas_vendedor_evolution + WHERE Periodo = vCurrentPeriod; + + REPLACE analisis_ventas_vendedor_evolution(vendedor, ventas, semana,año, periodo) + SELECT Comercial AS vendedor, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod + FROM ( + SELECT Comercial, SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear = Año + AND vWeek = Semana + GROUP BY Comercial + UNION ALL + SELECT Comercial, - SUM(Importe) AS ventas + FROM analisis_ventas + WHERE vYear - 1 = Año + AND vWeek = Semana + GROUP BY Comercial + UNION ALL + SELECT vendedor, ventas + FROM analisis_ventas_vendedor_evolution + WHERE Periodo = vPreviousPeriod + ) sub + GROUP BY vendedor; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/analisis_ventas_simple.sql b/db/routines/bi/procedures/analisis_ventas_simple.sql new file mode 100644 index 000000000..5c67584ee --- /dev/null +++ b/db/routines/bi/procedures/analisis_ventas_simple.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`analisis_ventas_simple`() +BEGIN +/** + * Vacia y rellena la tabla 'analisis_grafico_simple' desde 'analisis_grafico_ventas' + */ + TRUNCATE bi.analisis_grafico_simple; + + INSERT INTO bi.analisis_grafico_simple + SELECT * + FROM bi.analisis_grafico_ventas; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/analisis_ventas_update.sql b/db/routines/bi/procedures/analisis_ventas_update.sql new file mode 100644 index 000000000..bd330597d --- /dev/null +++ b/db/routines/bi/procedures/analisis_ventas_update.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`analisis_ventas_update`() +BEGIN + DECLARE vLastMonth DATE; + + SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, util.VN_CURDATE())); + + DELETE FROM analisis_ventas + WHERE Año > YEAR(vLastMonth) + OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth)); + + INSERT INTO analisis_ventas ( + Familia, + Reino, + Comercial, + Comprador, + Provincia, + almacen, + Año, + Mes, + Semana, + Vista, + Importe + ) + SELECT + tp.Tipo AS Familia, + r.reino AS Reino, + tr.CodigoTrabajador AS Comercial, + tr2.CodigoTrabajador AS Comprador, + p.name AS Provincia, + w.name AS almacen, + tm.year AS Año, + tm.month AS Mes, + tm.week AS Semana, + v.vista AS Vista, + bt.importe AS Importe + FROM bs.ventas bt + LEFT JOIN vn2008.Tipos tp ON tp.tipo_id = bt.tipo_id + LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id + LEFT JOIN vn2008.Clientes c on c.Id_Cliente = bt.Id_Cliente + LEFT JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = c.Id_Trabajador + LEFT JOIN vn2008.Trabajadores tr2 ON tr2.Id_Trabajador = tp.Id_Trabajador + JOIN vn2008.time tm ON tm.date = bt.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = bt.Id_Movimiento + LEFT JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia + LEFT JOIN vn2008.Vistas v ON v.vista_id = a.Vista + LEFT JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.Id_Consigna + LEFT JOIN vn2008.province p ON p.province_id = cs.province_id + LEFT JOIN vn2008.warehouse w ON w.id = t.warehouse_id + WHERE bt.fecha >= vLastMonth AND r.mercancia; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql new file mode 100644 index 000000000..4616bcb9e --- /dev/null +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -0,0 +1,168 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`claim_ratio_routine`() +BEGIN + DECLARE vMonthToRefund INT DEFAULT 4; + + /* + * PAK 2015-11-20 + * Se trata de añadir a la tabla Greuges todos los + * cargos que luego vamos a utilizar para calcular el recobro + */ + + -- Reclamaciones demasiado sensibles + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, + Importe, Greuges_type_id,Id_Ticket) + SELECT cm.Fecha + , cm.Id_Cliente + , concat('Claim ',cm.id,' : ', m.Concepte) + ,round( -1 * ((sensib -1)/4) * Cantidad * + Preu * (100 - Descuento) / 100, 2) AS Reclamaciones + , 4 + , m.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca USING(Id_Movimiento) + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3; + + -- Reclamaciones que pasan a Maná + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, + Importe , Greuges_type_id,Id_Ticket) + SELECT cm.Fecha + , cm.Id_Cliente + , concat('Claim_mana ',cm.id,' : ', m.Concepte) + ,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2) + AS Reclamaciones + ,3 + ,m.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca USING(Id_Movimiento) + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3 + AND cm.mana; + + -- Marcamos para no repetir + UPDATE vn2008.cl_act ca + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + SET greuge = 1 + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3; + + -- Recobros + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + SELECT DISTINCT t.Id_Ticket + FROM vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Tickets_state ts ON ts.Id_Ticket = t.Id_Ticket + JOIN vn.ticketTracking tt ON tt.id = ts.inter_id + JOIN vn2008.state s ON s.id = tt.stateFk + WHERE mc.Id_Componente = 17 + AND mc.greuge = 0 + AND t.Fecha >= '2016-10-01' + AND t.Fecha < util.VN_CURDATE() + AND s.alert_level >= 3; + + DELETE g.* + FROM vn2008.Greuges g + JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket + WHERE Greuges_type_id = 2; + + INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, + Greuges_type_id, Id_Ticket) + SELECT Id_Cliente + ,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2) + AS dif + ,date(t.Fecha) + , 2 + ,tt.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc + ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17 + GROUP BY t.Id_Ticket + HAVING ABS(dif) > 1; + + UPDATE vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento + JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket + SET greuge = 1 + WHERE Id_Componente = 17; + + /* + * Recalculamos la ratio de las reclamaciones, que luego + * se va a utilizar en el recobro + */ + + REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) + SELECT Id_Cliente, 0,0,0,0 + FROM vn2008.Clientes; + + REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) + SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones, + round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0 + FROM bi.facturacion_media_anual fm + LEFT JOIN( + SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) * + Cantidad * Preu * (100 - Descuento) / 100)) + AS Reclamaciones + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca + ON ca.Id_Movimiento = m.Id_Movimiento + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND cm.cl_est_id = 3 + AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) + GROUP BY cm.Id_Cliente + ) claims ON claims.Id_Cliente = fm.Id_Cliente; + + + -- Calculamos el porcentaje del recobro para añadirlo al precio de venta + UPDATE bi.claims_ratio cr + JOIN ( + SELECT Id_Cliente, nz(SUM(Importe)) AS Greuge + FROM vn2008.Greuges + WHERE Fecha <= util.VN_CURDATE() + GROUP BY Id_Cliente + ) g ON g.Id_Cliente = cr.Id_Cliente + SET recobro = GREATEST(0,round(nz(Greuge) / + (nz(Consumo) * vMonthToRefund / 12 ) ,3)); + + -- Protección neonatos + UPDATE bi.claims_ratio cr + JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente + SET recobro = 0, Ratio = 0 + WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + + -- CLIENTE 7983, JULIAN SUAU + UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; + + -- CLIENTE 4358 + UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 4358; + + -- CLIENTE 5523, VERDECORA + UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; + + -- CLIENTE 15979, SERVEIS VETERINARIS + UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 15979; + + -- CLIENTE 5189 i 8942, son de CSR i son el mateix client + UPDATE bi.claims_ratio cr + JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro + FROM bi.claims_ratio + WHERE Id_Cliente IN ( 5189,8942) + ) sub + SET cr.recobro = sub.recobro + WHERE Id_Cliente IN ( 5189,8942); +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/clean.sql b/db/routines/bi/procedures/clean.sql new file mode 100644 index 000000000..ba43b609c --- /dev/null +++ b/db/routines/bi/procedures/clean.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`clean`() +BEGIN + DECLARE vDateShort DATETIME; + DECLARE vDateLong DATETIME; + DECLARE vOneYearAgo DATETIME; + + SET vDateShort = TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); + SET vDateLong = TIMESTAMPADD(MONTH, -18,util.VN_CURDATE()); + SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,util.VN_CURDATE()); + + DELETE FROM bi.Greuge_Evolution + WHERE (Fecha < vDateShort AND weekday(Fecha) != 1) + OR Fecha < vOneYearAgo; + + DELETE FROM bi.defaulters WHERE `date` < vDateLong; + DELETE FROM bi.defaulting WHERE `date` < vDateLong; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/clean_launcher.sql b/db/routines/bi/procedures/clean_launcher.sql new file mode 100644 index 000000000..9eea34584 --- /dev/null +++ b/db/routines/bi/procedures/clean_launcher.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`clean_launcher`() +BEGIN +/** + * Borra registros de las principales tablas (excepto de "ticket"). + */ + CALL vn2008.clean(0); +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/comparativa_add.sql b/db/routines/bi/procedures/comparativa_add.sql new file mode 100644 index 000000000..4297c8aff --- /dev/null +++ b/db/routines/bi/procedures/comparativa_add.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`comparativa_add`() +BEGIN + DECLARE lastCOMP INT; # Se trata de una variable para almacenar el ultimo valor del Periodo + DECLARE vMaxPeriod INT; + DECLARE vMaxWeek INT; + + SELECT t.period, t.`week` INTO vMaxPeriod, vMaxWeek + FROM vn.`time` t + WHERE t.dated = util.VN_CURDATE(); + + SELECT MAX(Periodo) INTO lastCOMP FROM vn2008.Comparativa; + -- Fijaremos las ventas con más de un mes de antiguedad en la tabla Comparativa + + IF lastCOMP < vMaxPeriod - 3 AND vMaxWeek > 3 THEN + + REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price) + SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe) + FROM bs.ventas v + JOIN vn2008.time tm ON tm.date = v.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento + JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id + JOIN vn2008.reinos r ON r.id = tp.reino_id + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE tm.period BETWEEN lastCOMP AND vMaxPeriod - 3 + AND t.Id_Cliente NOT IN(400,200) + AND t.warehouse_id NOT IN (0,13) + GROUP BY m.Id_Article, Periodo, t.warehouse_id; + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/comparativa_add_manual.sql b/db/routines/bi/procedures/comparativa_add_manual.sql new file mode 100644 index 000000000..281e15b23 --- /dev/null +++ b/db/routines/bi/procedures/comparativa_add_manual.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`comparativa_add_manual`(IN vStarted DATE, IN vEnded DATE) +BEGIN +/** + * Recalcula la tabla Comparativa para dos valores dados + * + * @param vStarted fecha desde + * @param vEnded fecha hasta + */ + + DECLARE periodStart INT; + DECLARE periodEnd INT; + + -- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar + + SELECT t.period INTO periodStart + FROM vn.`time` t + WHERE t.dated = vStarted; + + SELECT t.period INTO periodEnd + FROM vn.`time` t + WHERE t.dated = vEnded; + + DELETE FROM vn2008.Comparativa + WHERE Periodo BETWEEN periodStart AND periodEnd; + + INSERT INTO vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price) + SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe) + FROM bs.ventas v + JOIN vn2008.time tm ON tm.date = v.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento + JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id + JOIN vn2008.reinos r ON r.id = tp.reino_id + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE tm.period BETWEEN periodStart AND periodEnd + AND t.Id_Cliente NOT IN(400,200) + AND t.warehouse_id NOT IN (0,13) + GROUP BY m.Id_Article, Periodo, t.warehouse_id; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/defaultersFromDate.sql b/db/routines/bi/procedures/defaultersFromDate.sql new file mode 100644 index 000000000..267c90dab --- /dev/null +++ b/db/routines/bi/procedures/defaultersFromDate.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`defaultersFromDate`(IN vDate DATE) +BEGIN + + SELECT t1.*, c.Cliente, w.code AS workerCode, c.pay_met_id,c.Vencimiento + FROM ( + -- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy + select * from( + select today.client, today.amount todayAmount, yesterday.amount yesterdayAmount, round(yesterday.amount - today.amount,2) as difference, defaulterSince + from + (select client, amount, defaulterSince + from defaulters + where date = vDate and hasChanged) today + join + (select client, amount + from defaulters + where date = TIMESTAMPADD(DAY,-1,vDate)) yesterday using(client) + + having today.amount > 0 and difference <> 0 + ) newDefaulters + )t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente + left join vn.worker w ON w.id = c.Id_Trabajador; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/defaulting.sql b/db/routines/bi/procedures/defaulting.sql new file mode 100644 index 000000000..50600e554 --- /dev/null +++ b/db/routines/bi/procedures/defaulting.sql @@ -0,0 +1,98 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`defaulting`(IN `vDate` DATE) +BEGIN + DECLARE vDone BOOLEAN; + DECLARE vClient INT; + DECLARE vAmount INT; + DECLARE vDued DATE; + DECLARE vAmountInvoice DECIMAL(10,2); + DECLARE vGraceDays INT; + DECLARE defaulters CURSOR FOR + SELECT client, amount, graceDays FROM bi.defaulters d + JOIN vn2008.Clientes c ON c.Id_Cliente = d.client + JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id + WHERE hasChanged AND date = vDate; + + DECLARE invoices CURSOR FOR + SELECT Vencimiento, importe FROM vn2008.Facturas f + WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE FROM bi.defaulters WHERE date = vDate; + + INSERT INTO bi.defaulters(client, date, amount) + SELECT c.id, vDate, IFNULL(FLOOR(SUM(cro.amount)),0) AS amount + FROM vn.`client` c + LEFT JOIN bi.customerRiskOverdue cro ON c.id = cro.customer_id + GROUP BY c.id; + + -- marcamos si ha cambiado y heredamos la fecha defaulterSince + UPDATE bi.defaulters d + LEFT JOIN ( + SELECT * FROM( + SELECT client, amount , defaulterSince, frozened FROM bi.defaulters + WHERE date <= TIMESTAMPADD(DAY,-1, vDate) + ORDER BY date DESC + LIMIT 10000000000000000000) t GROUP BY client + ) yesterday using(client) + SET d.hasChanged = (IFNULL(d.amount,0) <> IFNULL(yesterday.amount,0)), + d.defaulterSince = yesterday.defaulterSince, + d.frozened = yesterday.frozened + WHERE d.date = vDate ; + + OPEN defaulters; + defaulters: LOOP + SET vDone = FALSE; + SET vAmount = 0; + FETCH defaulters INTO vClient,vAmount, vGraceDays; + IF vDone THEN + LEAVE defaulters; + END IF; + OPEN invoices; + invoices:LOOP + + FETCH invoices INTO vDued, vAmountInvoice; + IF vDone THEN + LEAVE invoices; + END IF; + + IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN + SET vAmount = vAmount - vAmountInvoice; + IF vAmount <= 0 THEN + + UPDATE defaulters SET defaulterSince = vDued + WHERE client = vClient and date = vDate; + + SET vAmount = 0; + LEAVE invoices; + END IF; + END IF; + END LOOP; + CLOSE invoices; + END LOOP; + CLOSE defaulters; + + DELETE FROM defaulters + WHERE amount = 0 + AND hasChanged = FALSE + AND `date` = vDate; + + UPDATE defaulters d + JOIN vn.config ON TRUE + SET d.frozened = NULL + WHERE `date` = vDate + AND d.amount <= config.defaultersMaxAmount; + + CALL vn.clientFreeze(); + + -- actualizamos defaulting + DELETE FROM bi.defaulting WHERE date = vDate; + + INSERT INTO bi.defaulting(date, amount) + SELECT vDate, SUM(amount) + FROM bi.defaulters + WHERE date = vDate and amount > 0; + +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/defaulting_launcher.sql b/db/routines/bi/procedures/defaulting_launcher.sql new file mode 100644 index 000000000..585abdc09 --- /dev/null +++ b/db/routines/bi/procedures/defaulting_launcher.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`defaulting_launcher`() +BEGIN +/** + * Calcula la morosidad de los clientes. + */ + CALL bi.defaulting(util.VN_CURDATE()); +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/facturacion_media_anual_update.sql b/db/routines/bi/procedures/facturacion_media_anual_update.sql new file mode 100644 index 000000000..b956f353a --- /dev/null +++ b/db/routines/bi/procedures/facturacion_media_anual_update.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`facturacion_media_anual_update`() +BEGIN + TRUNCATE TABLE bs.clientAnnualConsumption; + + REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo) + SELECT clientFk, avg(Facturacion) + FROM ( + SELECT clientFk, YEAR(issued) year, MONTH(issued) month, sum(amount) as Facturacion + FROM vn.invoiceOut + WHERE issued BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND TIMESTAMPADD(DAY, - DAY(util.VN_CURDATE()),util.VN_CURDATE()) + GROUP BY clientFk, year, month + ) vol + GROUP BY clientFk; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/greuge_dif_porte_add.sql b/db/routines/bi/procedures/greuge_dif_porte_add.sql new file mode 100644 index 000000000..c81e41661 --- /dev/null +++ b/db/routines/bi/procedures/greuge_dif_porte_add.sql @@ -0,0 +1,93 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`greuge_dif_porte_add`() +BEGIN + DECLARE datSTART DATETIME DEFAULT TIMESTAMPADD(DAY,-60,util.VN_CURDATE()); -- '2019-07-01' + DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.dp; + + -- Agencias que no cobran por volumen + CREATE TEMPORARY TABLE tmp.dp + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, + SUM((t.zonePrice - t.zoneBonus) * ebv.ratio) AS teorico, + 00000.00 as practico, + 00000.00 as greuge, + t.clientFk, + t.shipped + FROM + vn.ticket t + JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk + LEFT JOIN vn2008.expeditions e ON e.ticket_id = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.EsBulto + JOIN vn.zone z ON t.zoneFk = z.id + WHERE + t.shipped between datSTART AND datEND + AND cli.`real` + AND t.companyFk IN (442 , 567) + AND z.isVolumetric = FALSE + GROUP BY t.id; + + -- Agencias que cobran por volumen + INSERT INTO tmp.dp + SELECT sv.ticketFk, + SUM(IFNULL(sv.freight,0)) AS teorico, + 00000.00 as practico, + 00000.00 as greuge, + sv.clientFk, + sv.shipped + FROM vn.saleVolume sv + JOIN vn.zone z ON z.id = sv.zoneFk + AND sv.shipped BETWEEN datSTART AND datEND + AND z.isVolumetric != FALSE + GROUP BY sv.ticketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux; + + CREATE TEMPORARY TABLE tmp.dp_aux + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT dp.ticketFk, sum(Cantidad * Valor) as valor + FROM tmp.dp + JOIN vn2008.Movimientos m ON m.Id_Ticket = dp.ticketFk + JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento) + WHERE mc.Id_Componente = 15 + GROUP BY dp.ticketFk; + + UPDATE tmp.dp + JOIN tmp.dp_aux USING(ticketFk) + SET practico = IFNULL(valor,0); + + DROP TEMPORARY TABLE tmp.dp_aux; + + CREATE TEMPORARY TABLE tmp.dp_aux + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT dp.ticketFk, sum(Importe) Importe + FROM tmp.dp + JOIN vn2008.Greuges g ON g.Id_Ticket = dp.ticketFk + WHERE Greuges_type_id = 1 -- dif_porte + GROUP BY dp.ticketFk; + + UPDATE tmp.dp + JOIN tmp.dp_aux USING(ticketFk) + SET greuge = IFNULL(Importe,0); + + INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, Greuges_type_id, Id_Ticket) + SELECT dp.clientFk + , concat('dif_porte ', dp.ticketFk) + , round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe + , date(dp.shipped) + , 1 + ,dp.ticketFk + FROM tmp.dp + JOIN vn.client c ON c.id = dp.clientFk + WHERE ABS(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0)) > 1 + AND c.isRelevant; + + DROP TEMPORARY TABLE + tmp.dp, + tmp.dp_aux; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/nigthlyAnalisisVentas.sql b/db/routines/bi/procedures/nigthlyAnalisisVentas.sql new file mode 100644 index 000000000..c21a3bae5 --- /dev/null +++ b/db/routines/bi/procedures/nigthlyAnalisisVentas.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`nigthlyAnalisisVentas`() +BEGIN + CALL analisis_ventas_update; + CALL analisis_ventas_simple; + CALL analisis_ventas_evolution_add; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/rutasAnalyze.sql b/db/routines/bi/procedures/rutasAnalyze.sql new file mode 100644 index 000000000..8b56fa74d --- /dev/null +++ b/db/routines/bi/procedures/rutasAnalyze.sql @@ -0,0 +1,127 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`rutasAnalyze`( + vYear INT, + vMonth INT +) +BEGIN +/** + * Analiza los costes de las rutas de reparto + * y lo almacena en la tabla bi.rutasBoard + */ + DELETE FROM rutasBoard + WHERE YEAR(Fecha) = vYear + AND MONTH(Fecha) = vMonth; + + -- Rellenamos la tabla con los datos de las rutas VOLUMETRICAS, especialmente con los bultos "virtuales" + INSERT INTO rutasBoard( + Id_Ruta, + Id_Agencia, + Fecha, + bultos) + SELECT r.id, + r.agencyModeFk, + r.created, + SUM(sv.volume / ebv.m3) + FROM vn.route r + JOIN vn.ticket t ON t.routeFk = r.id + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.code = 'transportBox' + WHERE YEAR(r.created) = vYear AND MONTH(r.created) = vMonth + AND z.isVolumetric + GROUP BY r.id; + + -- Rellenamos la tabla con los datos de las rutas NO VOLUMETRICAS, especialmente con los bultos "virtuales" + INSERT INTO rutasBoard( + Id_Ruta, + Id_Agencia, + Fecha, + Bultos) + SELECT r.id, + r.agencyModeFk, + r.created, + SUM(t.packages) + FROM vn.route r + JOIN vn.ticket t ON t.routeFk = r.id + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE YEAR(r.created) = vYear + AND MONTH(r.created) = vMonth + AND NOT z.isVolumetric + GROUP BY r.id + ON DUPLICATE KEY UPDATE Bultos = Bultos + VALUES(Bultos); + + -- Coste PRACTICO de cada bulto, de acuerdo con los componentes de tipo AGENCIA en cada linea de venta + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(s.quantity * sc.value) totalPractice + FROM vn.route r + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.ticket t ON t.routeFk = r.id + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.saleComponent sc ON sc.saleFk = s.id + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE ct.code = 'FREIGHT' + AND tm.`year` = vYear + AND tm.`month` = vMonth + GROUP BY r.id + ) sub ON sub.routeFk = r.Id_Ruta + SET r.practico = IFNULL(sub.totalPractice / r.Bultos, 0); + + -- Coste TEORICO de una caja "virtual" para cada ruta, teniendo en cuenta que hay carros, pallets, etc + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(t.zonePrice/ ebv.ratio) / COUNT(*) averageTheoreticalVolume + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.expedition e ON e.ticketFk = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk + JOIN vn.address ad ON ad.id = t.addressFk + JOIN vn.client c ON c.id = ad.clientFk + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE tm.`year` = vYear + AND tm.`month` = vMonth + AND NOT z.isVolumetric + GROUP BY t.routeFk + ) sub ON r.Id_Ruta = sub.routeFk + SET r.teorico = IFNULL(sub.averageTheoreticalVolume, 0); + + -- Coste VOLUMETRICO TEORICO de una caja "virtual" para cada ruta + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(freight) averageTheoreticalVolume + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.saleVolume sf ON sf.ticketFk = t.id + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE tm.`year` = vYear + AND tm.`month` = vMonth + AND z.isVolumetric + GROUP BY t.routeFk + ) sub ON r.Id_Ruta = sub.routeFk + SET r.teorico = IFNULL(sub.averageTheoreticalVolume / r.Bultos, 0); + + -- La diferencia entre el teorico y el practico se deberia de cobrar en greuges, cada noche + UPDATE rutasBoard r + JOIN ( + SELECT t.routeFk, + SUM(g.amount) greuge + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + JOIN vn.`time` tm ON tm.dated = r.created + JOIN vn.greuge g ON g.ticketFk = t.id + JOIN vn.greugeType gt ON gt.id = g.greugeTypeFk + WHERE tm.`year` = vYear + AND tm.`month` = vMonth + AND gt.code = 'freightDifference' + GROUP BY t.routeFk + ) sub ON r.Id_Ruta = sub.routeFk + SET r.greuge = sub.greuge / r.Bultos; +END$$ +DELIMITER ; diff --git a/db/routines/bi/procedures/rutasAnalyze_launcher.sql b/db/routines/bi/procedures/rutasAnalyze_launcher.sql new file mode 100644 index 000000000..bc50b7905 --- /dev/null +++ b/db/routines/bi/procedures/rutasAnalyze_launcher.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`rutasAnalyze_launcher`() +BEGIN +/** + * Call rutasAnalyze + */ + CALL rutasAnalyze(YEAR(util.VN_CURDATE()), MONTH(util.VN_CURDATE())); +END$$ +DELIMITER ; diff --git a/db/routines/bi/views/analisis_grafico_ventas.sql b/db/routines/bi/views/analisis_grafico_ventas.sql new file mode 100644 index 000000000..f5956f27a --- /dev/null +++ b/db/routines/bi/views/analisis_grafico_ventas.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`analisis_grafico_ventas` +AS SELECT `bi`.`analisis_ventas`.`Año` AS `Año`, + `bi`.`analisis_ventas`.`Semana` AS `Semana`, + sum(`bi`.`analisis_ventas`.`Importe`) AS `Importe` +FROM `bi`.`analisis_ventas` +GROUP BY `bi`.`analisis_ventas`.`Año`, + `bi`.`analisis_ventas`.`Semana` diff --git a/db/routines/bi/views/analisis_ventas_simple.sql b/db/routines/bi/views/analisis_ventas_simple.sql new file mode 100644 index 000000000..109378c8a --- /dev/null +++ b/db/routines/bi/views/analisis_ventas_simple.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`analisis_ventas_simple` +AS SELECT `bi`.`analisis_ventas`.`Año` AS `Año`, + `bi`.`analisis_ventas`.`Semana` AS `Semana`, + sum(`bi`.`analisis_ventas`.`Importe`) AS `Importe` +FROM `bi`.`analisis_ventas` +GROUP BY `bi`.`analisis_ventas`.`Año`, + `bi`.`analisis_ventas`.`Semana` diff --git a/db/routines/bi/views/claims_ratio.sql b/db/routines/bi/views/claims_ratio.sql new file mode 100644 index 000000000..cfd9b6231 --- /dev/null +++ b/db/routines/bi/views/claims_ratio.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`claims_ratio` +AS SELECT `cr`.`clientFk` AS `Id_Cliente`, + `cr`.`yearSale` AS `Consumo`, + `cr`.`claimAmount` AS `Reclamaciones`, + `cr`.`claimingRate` AS `Ratio`, + `cr`.`priceIncreasing` AS `recobro`, + `cr`.`packingRate` AS `inflacion` +FROM `vn`.`claimRatio` `cr` diff --git a/db/routines/bi/views/customerRiskOverdue.sql b/db/routines/bi/views/customerRiskOverdue.sql new file mode 100644 index 000000000..27ef7ca47 --- /dev/null +++ b/db/routines/bi/views/customerRiskOverdue.sql @@ -0,0 +1,40 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`customerRiskOverdue` +AS SELECT `cr`.`clientFk` AS `customer_id`, + `cr`.`amount` AS `amount`, + `cr`.`companyFk` AS `company_id` +FROM ( + ( + ( + `vn`.`clientRisk` `cr` + JOIN `vn`.`company` `co` ON(`co`.`id` = `cr`.`companyFk`) + ) + JOIN `vn`.`client` `c` ON(`cr`.`clientFk` = `c`.`id`) + ) + JOIN `vn`.`payMethod` `pm` ON(`pm`.`id` = `c`.`payMethodFk`) + ) +WHERE `cr`.`amount` <> 0 + AND `co`.`isDefaulter` <> 0 + AND `pm`.`outstandingDebt` <> 0 + AND `c`.`typeFk` = 'normal' +UNION ALL +SELECT `i`.`clientFk` AS `Id_Cliente`, + - round(`i`.`amount`, 2) AS `importe`, + `i`.`companyFk` AS `empresa_id` +FROM ( + ( + ( + `vn`.`invoiceOut` `i` + JOIN `vn`.`client` `c` ON(`i`.`clientFk` = `c`.`id`) + ) + JOIN `vn`.`company` `co` ON(`co`.`id` = `i`.`companyFk`) + ) + JOIN `vn`.`payMethod` `pm` ON(`pm`.`id` = `c`.`payMethodFk`) + ) +WHERE `i`.`issued` > `util`.`VN_CURDATE`() + INTERVAL -101 DAY + AND `i`.`dued` + INTERVAL `pm`.`graceDays` DAY > `util`.`VN_CURDATE`() + AND `i`.`amount` > 0 + AND `co`.`isDefaulter` <> 0 + AND `pm`.`outstandingDebt` <> 0 + AND `c`.`typeFk` = 'normal' diff --git a/db/routines/bi/views/defaulters.sql b/db/routines/bi/views/defaulters.sql new file mode 100644 index 000000000..927503245 --- /dev/null +++ b/db/routines/bi/views/defaulters.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`defaulters` +AS SELECT `d`.`clientFk` AS `client`, + `d`.`created` AS `date`, + `d`.`amount` AS `amount`, + `d`.`defaulterSinced` AS `defaulterSince`, + `d`.`hasChanged` AS `hasChanged`, + `d`.`frozened` AS `frozened` +FROM `bs`.`defaulter` `d` diff --git a/db/routines/bi/views/facturacion_media_anual.sql b/db/routines/bi/views/facturacion_media_anual.sql new file mode 100644 index 000000000..2e0c2ca6e --- /dev/null +++ b/db/routines/bi/views/facturacion_media_anual.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`facturacion_media_anual` +AS SELECT `cac`.`clientFk` AS `Id_Cliente`, + `cac`.`invoiced` AS `Consumo` +FROM `bs`.`clientAnnualConsumption` `cac` diff --git a/db/routines/bi/views/last_Id_Cubo.sql b/db/routines/bi/views/last_Id_Cubo.sql new file mode 100644 index 000000000..758b524fd --- /dev/null +++ b/db/routines/bi/views/last_Id_Cubo.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`last_Id_Cubo` +AS SELECT `C`.`Id_Compra` AS `Id_Compra`, + `C`.`Id_Article` AS `Id_Article`, + `tr`.`warehouse_id` AS `warehouse_id`, + `C`.`Id_Cubo` AS `Id_Cubo`, + `C`.`Packing` AS `Packing` +FROM ( + ( + `vn2008`.`Compres` `C` + JOIN `vn2008`.`Entradas` `E` ON(`C`.`Id_Entrada` = `E`.`Id_Entrada`) + ) + JOIN `vn2008`.`travel` `tr` ON(`E`.`travel_id` = `tr`.`id`) + ) +WHERE `C`.`Id_Cubo` IS NOT NULL + AND `C`.`Id_Cubo` <> '--' + AND `tr`.`landing` > `util`.`VN_CURDATE`() - INTERVAL 18 MONTH +ORDER BY `C`.`Id_Compra` DESC diff --git a/db/routines/bi/views/rotacion.sql b/db/routines/bi/views/rotacion.sql new file mode 100644 index 000000000..65a5db923 --- /dev/null +++ b/db/routines/bi/views/rotacion.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`rotacion` +AS SELECT `ic`.`itemFk` AS `Id_Article`, + `ic`.`warehouseFk` AS `warehouse_id`, + `ic`.`quantity` AS `total`, + `ic`.`rotation` AS `rotacion`, + `ic`.`cm3` AS `cm3`, + `ic`.`storage` AS `almacenaje`, + `ic`.`handling` AS `manipulacion`, + `ic`.`extraCharge` AS `auxiliar`, + `ic`.`wasted` AS `mermas`, + `ic`.`cm3delivery` AS `cm3reparto`, + `ic`.`grams` AS `grams` +FROM `vn`.`itemCost` `ic` diff --git a/db/routines/bi/views/tarifa_componentes.sql b/db/routines/bi/views/tarifa_componentes.sql new file mode 100644 index 000000000..42ea9fa81 --- /dev/null +++ b/db/routines/bi/views/tarifa_componentes.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`tarifa_componentes` +AS SELECT `c`.`id` AS `Id_Componente`, + `c`.`name` AS `Componente`, + `c`.`typeFk` AS `tarifa_componentes_series_id`, + `c`.`classRate` AS `tarifa_class`, + `c`.`tax` AS `tax`, + `c`.`isRenewable` AS `is_renewable`, + `c`.`code` AS `code` +FROM `vn`.`component` `c` diff --git a/db/routines/bi/views/tarifa_componentes_series.sql b/db/routines/bi/views/tarifa_componentes_series.sql new file mode 100644 index 000000000..f231ae420 --- /dev/null +++ b/db/routines/bi/views/tarifa_componentes_series.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`tarifa_componentes_series` +AS SELECT `ct`.`id` AS `tarifa_componentes_series_id`, + `ct`.`type` AS `Serie`, + `ct`.`isBase` AS `base`, + `ct`.`isMargin` AS `margen` +FROM `vn`.`componentType` `ct` diff --git a/db/routines/bi/views/v_clientes_jerarquia.sql b/db/routines/bi/views/v_clientes_jerarquia.sql new file mode 100644 index 000000000..e8e4e1e69 --- /dev/null +++ b/db/routines/bi/views/v_clientes_jerarquia.sql @@ -0,0 +1,21 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`v_clientes_jerarquia` +AS SELECT `c`.`id_cliente` AS `Id_Cliente`, + `c`.`cliente` AS `Cliente`, + `t`.`CodigoTrabajador` AS `Comercial`, + `tj`.`CodigoTrabajador` AS `Jefe` +FROM ( + ( + ( + `vn2008`.`Clientes` `c` + JOIN `vn2008`.`Trabajadores` `t` ON(`t`.`Id_Trabajador` = `c`.`Id_Trabajador`) + ) + JOIN `vn2008`.`jerarquia` ON( + `vn2008`.`jerarquia`.`worker_id` = `c`.`Id_Trabajador` + ) + ) + JOIN `vn2008`.`Trabajadores` `tj` ON( + `tj`.`Id_Trabajador` = `vn2008`.`jerarquia`.`boss_id` + ) + ) diff --git a/db/routines/bi/views/v_ventas_contables.sql b/db/routines/bi/views/v_ventas_contables.sql new file mode 100644 index 000000000..373fcdd3f --- /dev/null +++ b/db/routines/bi/views/v_ventas_contables.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bi`.`v_ventas_contables` +AS SELECT `time`.`year` AS `year`, + `time`.`month` AS `month`, + cast( + sum( + `m`.`Cantidad` * `m`.`Preu` * (100 - `m`.`Descuento`) / 100 + ) AS decimal(10, 0) + ) AS `importe` +FROM ( + ( + ( + `vn2008`.`Tickets` `t` + JOIN `bi`.`f_tvc` ON(`t`.`Id_Ticket` = `bi`.`f_tvc`.`Id_Ticket`) + ) + JOIN `vn2008`.`Movimientos` `m` ON(`t`.`Id_Ticket` = `m`.`Id_Ticket`) + ) + JOIN `vn2008`.`time` ON(`time`.`date` = cast(`t`.`Fecha` AS date)) + ) +WHERE `t`.`Fecha` >= '2014-01-01' +GROUP BY `time`.`year`, + `time`.`month` diff --git a/db/routines/bs/events/clientDied_recalc.sql b/db/routines/bs/events/clientDied_recalc.sql new file mode 100644 index 000000000..db912658a --- /dev/null +++ b/db/routines/bs/events/clientDied_recalc.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `bs`.`clientDied_recalc` + ON SCHEDULE EVERY 1 DAY + STARTS '2023-06-01 03:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + DECLARE vDone INT DEFAULT FALSE; + DECLARE vCountryFk INT; + DECLARE vDays INT; + + DECLARE cur CURSOR FOR + SELECT countryFk, days + FROM clientDiedPeriod; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + read_loop: LOOP + SET vDone = FALSE; + FETCH cur INTO vCountryFk, vDays; + IF vDone THEN + LEAVE read_loop; + END IF; + CALL clientDied_recalc(vDays, (SELECT code FROM vn.country WHERE id = vCountryFk)); + END LOOP; + CLOSE cur; +END$$ +DELIMITER ; diff --git a/db/routines/bs/events/inventoryDiscrepancy_launch.sql b/db/routines/bs/events/inventoryDiscrepancy_launch.sql new file mode 100644 index 000000000..3ee165846 --- /dev/null +++ b/db/routines/bs/events/inventoryDiscrepancy_launch.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `bs`.`inventoryDiscrepancy_launch` + ON SCHEDULE EVERY 15 MINUTE + STARTS '2023-07-18 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL bs.inventoryDiscrepancyDetail_replace()$$ +DELIMITER ; diff --git a/db/routines/bs/events/nightTask_launchAll.sql b/db/routines/bs/events/nightTask_launchAll.sql new file mode 100644 index 000000000..1a55ca1a3 --- /dev/null +++ b/db/routines/bs/events/nightTask_launchAll.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `bs`.`nightTask_launchAll` + ON SCHEDULE EVERY 1 DAY + STARTS '2022-02-08 04:14:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL bs.nightTask_launchAll$$ +DELIMITER ; diff --git a/db/routines/bs/functions/tramo.sql b/db/routines/bs/functions/tramo.sql new file mode 100644 index 000000000..0415cfc92 --- /dev/null +++ b/db/routines/bs/functions/tramo.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `bs`.`tramo`(vDateTime DATETIME) + RETURNS varchar(20) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + NOT DETERMINISTIC + NO SQL +BEGIN + + DECLARE vTramo VARCHAR(20); + DECLARE vHour INT; + + SET vHour = HOUR(vDateTime) ; + + SET vTramo = + CASE + WHEN vHour BETWEEN 0 AND 14 THEN 'Mañana' + WHEN vHour BETWEEN 15 AND 24 THEN 'Tarde' + END ; + +RETURN vTramo; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/bancos_evolution_add.sql b/db/routines/bs/procedures/bancos_evolution_add.sql new file mode 100644 index 000000000..f0a3b3709 --- /dev/null +++ b/db/routines/bs/procedures/bancos_evolution_add.sql @@ -0,0 +1,112 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`bancos_evolution_add`(vStartingDate DATE) +BEGIN +/** + * Inserta en la tabla bancos_evolution los saldos acumulados de cada banco + * + * @param vStartingDate Fecha desde la cual se recalculan la tabla bs.bancos_evolution + */ + DECLARE vCurrentDate DATE; + DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, util.VN_CURDATE()); + IF IFNULL(vStartingDate,0) < TIMESTAMPADD(YEAR, -5, util.VN_CURDATE()) THEN + CALL util.throw('invalid date'); + END IF; + DELETE FROM bs.bancos_evolution WHERE Fecha >= vStartingDate; + + SET vCurrentDate = vStartingDate; + + INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) + SELECT vCurrentDate, Id_Banco, deuda + FROM bs.bancos_evolution + WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate); + + WHILE vCurrentDate < vMaxDate DO +-- insertar solo el dia de ayer + INSERT INTO bs.bancos_evolution(Fecha ,Id_Banco, saldo) + SELECT vCurrentDate, Id_Banco, SUM(saldo) + FROM ( + SELECT Id_Banco ,saldo + FROM bs.bancos_evolution + WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate) -- los saldos acumulados del dia anterior + UNION ALL + + SELECT c.Id_Banco, IFNULL(SUM(Entrada),0) - IFNULL(SUM(Salida),0) as saldo + FROM vn2008.Cajas c + JOIN vn2008.Bancos b using(Id_Banco) -- saldos de las cajas + JOIN vn.accountingType at2 ON at2.id = b.cash + WHERE at2.code IN ('wireTransfer','fundingLine') + AND Cajafecha = vCurrentDate + AND (Serie = 'MB' OR at2.code = 'fundingLine') + GROUP BY Id_Banco + )sub + GROUP BY Id_Banco + ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); + + SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate); + + END WHILE; + + -- Ahora actualizamos la quilla + UPDATE bs.bancos_evolution be + JOIN + ( + SELECT bp.Id_Banco, - sum(bp.importe) as quilla, t.dated + FROM vn.time t + JOIN vn2008.Bancos_poliza bp ON t.dated between apertura AND IFNULL(cierre, t.dated) + WHERE t.dated BETWEEN vStartingDate AND vMaxDate + GROUP BY Id_Banco, t.dated + ) sub ON be.Id_Banco = sub.Id_Banco AND sub.dated = be.Fecha + SET be.quilla = sub.quilla; + + -- pagos futuros no concilidados + INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) + SELECT t.dated, p.id_banco, - importe + FROM vn.time t + join vn2008.pago p ON p.fecha <= t.dated + WHERE t.dated BETWEEN util.VN_CURDATE() AND vMaxDate + AND p.fecha BETWEEN util.VN_CURDATE() AND vMaxDate + AND NOT conciliado + ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); + + -- cobros futuros + INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) + SELECT t.dated, r.Id_Banco, SUM(Entregado) + FROM vn.time t + JOIN vn2008.Recibos r ON r.Fechacobro <= t.dated + WHERE r.Fechacobro > util.VN_CURDATE() AND r.Fechacobro <= vMaxDate + AND t.dated BETWEEN util.VN_CURDATE() AND vMaxDate + GROUP BY t.dated, r.Id_Banco + ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); + + -- saldos de la tabla prevision + INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) + SELECT t.dated, sp.Id_Banco, SUM(Importe) + FROM vn.time t + JOIN vn2008.Saldos_Prevision sp ON sp.Fecha <= t.dated + JOIN vn2008.Bancos b ON sp.Id_Banco = b.Id_Banco + JOIN vn.accountingType at2 ON at2.id = b.cash + WHERE at2.code IN ('wireTransfer','fundingLine') + AND t.dated BETWEEN vStartingDate AND vMaxDate + GROUP BY t.dated, sp.Id_Banco + ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); + + -- Utilizamos el saldo_auxiliar para calcular lo dispuesto en las polizas + UPDATE bs.bancos_evolution be + SET saldo_aux = saldo + WHERE Fecha >= vStartingDate; + + -- Deuda + UPDATE bs.bancos_evolution be + JOIN vn2008.Bancos b using(Id_Banco) + JOIN vn.accountingType at2 ON at2.id = b.cash + SET be.deuda = IF(at2.code = 'fundingLine', be.saldo_aux, 0) + , be.saldo = IF(at2.code = 'fundingLine', 0, be.saldo_aux) + WHERE Fecha >= vStartingDate; + + -- Liquidez + update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate; + -- Disponibilidad + update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/campaignComparative.sql b/db/routines/bs/procedures/campaignComparative.sql new file mode 100644 index 000000000..6b4b983b5 --- /dev/null +++ b/db/routines/bs/procedures/campaignComparative.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`campaignComparative`(vDateFrom DATE, vDateTo DATE) +BEGIN + SELECT + workerName, + id, + name, + CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, + CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount + FROM ( + (SELECT + CONCAT(w.firstname, ' ', w.lastName) AS workerName, + c.id, + c.name, + SUM(v.importe) AS previousAmmount, + 0 currentAmmount + FROM bs.ventas v + INNER JOIN vn.`client` c ON v.Id_Cliente = c.id + INNER JOIN vn.worker w ON c.salesPersonFk = w.id + WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) + AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR) + GROUP BY w.id, v.Id_Cliente) + UNION ALL + (SELECT + CONCAT(w.firstname, ' ', w.lastName) AS workerName, + c.id, + c.name, + 0 AS previousAmmount, + SUM(s.quantity * s.price) AS currentAmmount + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.worker w ON c.salesPersonFk = w.id + WHERE t.shipped BETWEEN vDateFrom + AND vDateTo + GROUP BY w.id, c.id) + ) comparative + GROUP BY workerName, id + HAVING (previousAmmount <> 0 OR currentAmmount <> 0) + ORDER BY workerName, id; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/carteras_add.sql b/db/routines/bs/procedures/carteras_add.sql new file mode 100644 index 000000000..6de377371 --- /dev/null +++ b/db/routines/bs/procedures/carteras_add.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`carteras_add`() +BEGIN +/** + * Inserta en la tabla @bs.carteras las ventas desde el año pasado + * agrupadas por trabajador, año y mes + */ + DECLARE vYear INT DEFAULT YEAR(util.VN_CURDATE()) - 1; + + DELETE FROM bs.carteras WHERE Año >= vYear; + + CALL util.time_generate( + MAKEDATE(vYear, 1), + (SELECT MAX(fecha) FROM ventas) + ); + + INSERT INTO carteras(Año, Mes , CodigoTrabajador, Peso) + SELECT t.`year`, t.`month`, w.code, SUM(v.importe) + FROM tmp.time t + JOIN ventas v on t.dated = v.fecha + JOIN vn.client c on c.id = v.Id_Cliente + JOIN vn.worker w ON w.id = c.salesPersonFk + GROUP BY w.code, t.`year`, t.`month`; + + DROP TEMPORARY TABLE tmp.time; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/clean.sql b/db/routines/bs/procedures/clean.sql new file mode 100644 index 000000000..3c29553f5 --- /dev/null +++ b/db/routines/bs/procedures/clean.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`clean`() +BEGIN + DECLARE vFourYearsAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; + DECLARE vOneYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; + DECLARE vTwoYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 3 YEAR; + DECLARE vThreeYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; + DECLARE vEighteenMonths DATE DEFAULT util.VN_CURDATE() - INTERVAL 18 MONTH; + + DELETE FROM clientNewBorn + WHERE lastShipped < vOneYearAgo; + + DELETE FROM ventas + WHERE fecha < vFourYearsAgo; + + DELETE FROM payMethodClient + WHERE dated < vOneYearAgo; + + DELETE FROM payMethodClientEvolution + WHERE dated < vFourYearsAgo; + + DELETE FROM salesByclientSalesPerson + WHERE dated < vFourYearsAgo; + + DELETE FROM m3 + WHERE fecha < vTwoYearAgo; + + DELETE FROM salesByItemTypeDay + WHERE dated < vThreeYearAgo; + + DELETE FROM waste + WHERE MAKEDATE(`year`, 1) + INTERVAL (`week` - 1) WEEK + INTERVAL 1 DAY < vEighteenMonths; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/clientDied_recalc.sql b/db/routines/bs/procedures/clientDied_recalc.sql new file mode 100644 index 000000000..1b5cb5ac8 --- /dev/null +++ b/db/routines/bs/procedures/clientDied_recalc.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`clientDied_recalc`( + vDays INT, + vCountryCode VARCHAR(2) +) +BEGIN +/** + * Recalcula los clientes inactivos y hace insert en la tabla clientDied + * estableciendo hasta 3 avisos en función del periodo y el código de país. + * + * @param vDays El número de días a considerar para la inactividad del cliente + * @param vCountryCode El código del país para filtrar los clientes + */ + DECLARE vFirstPeriod , vSecondPeriod, vThridPeriod DATE; + SET vFirstPeriod = util.VN_CURDATE() - INTERVAL vDays DAY; + SET vSecondPeriod = util.VN_CURDATE() - INTERVAL vDays * 2 DAY; + SET vThridPeriod = util.VN_CURDATE() - INTERVAL vDays * 3 DAY; + + DELETE cd.* FROM clientDied cd + JOIN ( + SELECT c.id FROM vn.client c + JOIN vn.country co ON co.id = c.countryFk + WHERE co.code = vCountryCode + ) sub ON sub.id = cd.clientFk; + + INSERT INTO clientDied (clientFk, lastInvoiced, warning) + SELECT c.id, + sub.lastShipped, + CASE + WHEN lastShipped < vThridPeriod OR lastShipped IS NULL THEN 'third' + WHEN lastShipped < vSecondPeriod THEN 'second' + WHEN lastShipped < vFirstPeriod THEN 'first' + END + FROM vn.client c + JOIN vn.country co ON co .id = c.countryFk + JOIN vn.worker w ON w.id = c.salesPersonFk + JOIN vn.worker b ON b.id = w.bossFk + JOIN vn.workerMana wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN ( + SELECT c.id, DATE(MAX(t.shipped)) lastShipped + FROM vn.client c + LEFT JOIN vn.ticket t ON t.clientFk = c.id + LEFT JOIN vn.country co ON co.id = c.countryFk + WHERE co.code = vCountryCode + AND (t.shipped <= util.VN_CURDATE() OR t.shipped IS NULL) + GROUP BY c.id + ) sub ON sub.id = c.id + LEFT JOIN vn.clientObservation cob ON cob.clientFk = c.id + AND cob.created > vThridPeriod + WHERE (sub.lastShipped < vFirstPeriod OR sub.lastShipped IS NULL) + AND c.created < vThridPeriod + AND co.code = vCountryCode + AND cob.`text` IS NULL + AND c.id NOT IN ( + SELECT DISTINCT clientFk + FROM vn.ticket + WHERE refFk IS NULL + AND shipped >= vFirstPeriod + ) + GROUP BY c.id; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/clientNewBorn_recalc.sql b/db/routines/bs/procedures/clientNewBorn_recalc.sql new file mode 100644 index 000000000..1c89b5745 --- /dev/null +++ b/db/routines/bs/procedures/clientNewBorn_recalc.sql @@ -0,0 +1,87 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`clientNewBorn_recalc`() +BLOCK1: BEGIN + + DECLARE vClientFk INT; + DECLARE vShipped DATE; + DECLARE vPreviousShipped DATE; + DECLARE vDone boolean; + DECLARE cur cursor for + + SELECT clientFk, firstShipped + FROM bs.clientNewBorn; + + DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; + SET vDone := FALSE; + + DELETE FROM bs.clientNewBorn WHERE isModified = FALSE; + + INSERT INTO clientNewBorn(clientFk, firstShipped, lastShipped) + SELECT c.id, MAX(t.shipped), MAX(t.shipped) + FROM vn.client c + JOIN vn.ticket t on t.clientFk = c.id + LEFT JOIN clientNewBorn cb on cb.clientFk = c.id + WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null + GROUP BY c.id; + OPEN cur; + + LOOP1: LOOP + SET vDone := FALSE; + FETCH cur INTO vClientFk, vShipped; + + IF vDone THEN + CLOSE cur; + LEAVE LOOP1; + END IF; + + BLOCK2: BEGIN + DECLARE vCurrentShipped DATE; + DECLARE vDone2 boolean; + DECLARE cur2 CURSOR FOR + SELECT shipped + FROM vn.ticket + WHERE clientFk = vClientFk AND shipped <= util.VN_CURDATE() + ORDER BY shipped DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE; + SET vDone2 := FALSE; + OPEN cur2; + + SET vPreviousShipped := vShipped; + LOOP2: LOOP + SET vDone2 := FALSE; + FETCH cur2 INTO vCurrentShipped; + + IF DATEDIFF(vPreviousShipped,vCurrentShipped) > 365 THEN + UPDATE bs.clientNewBorn + SET firstShipped = vPreviousShipped + WHERE clientFk= vClientFk; + + CLOSE cur2; + LEAVE LOOP2; + END IF; + + SET vPreviousShipped := vCurrentShipped; + + IF vDone2 THEN + UPDATE bs.clientNewBorn + SET firstShipped = vCurrentShipped + WHERE clientFk= vClientFk; + CLOSE cur2; + LEAVE LOOP2; + END IF; + + END LOOP LOOP2; + END BLOCK2; + END LOOP LOOP1; + + UPDATE bs.clientNewBorn cnb + LEFT JOIN (SELECT DISTINCT t.clientFk + FROM vn.ticket t + JOIN vn.productionConfig pc + WHERE t.shipped BETWEEN util.VN_CURDATE() + INTERVAL -(`notBuyingMonths`) MONTH + AND util.VN_CURDATE() + INTERVAL -(`pc`.`rookieDays`) DAY) notRookie ON notRookie.clientFk = cnb.clientFk + SET cnb.isRookie = ISNULL(notRookie.clientFk); + +END BLOCK1$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/comercialesCompleto.sql b/db/routines/bs/procedures/comercialesCompleto.sql new file mode 100644 index 000000000..323d5cd00 --- /dev/null +++ b/db/routines/bs/procedures/comercialesCompleto.sql @@ -0,0 +1,111 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`comercialesCompleto`(IN vWorker INT, vDate DATE) +BEGIN + DECLARE vAYearAgoStarted DATE DEFAULT DATE_FORMAT(TIMESTAMPADD(YEAR, - 1, vDate), '%Y-%m-01'); + DECLARE vAYearAgoEnded DATE DEFAULT TIMESTAMPADD(YEAR, - 1, LAST_DAY(vDate)); + + CALL vn.worker_GetHierarchy(vWorker); + + INSERT IGNORE INTO tmp.workerHierarchyList (workerFk) + SELECT wd2.workerFk + FROM vn.workerDepartment wd2 + WHERE wd2.workerFk = vWorker; + + -- Falta que en algunos casos solo tenga en cuenta los tipos afectados. + SELECT + c.Id_Cliente id_cliente, + c.Cliente cliente, + cr.recobro * 100 tarifa, + c.Telefono telefono, + c.movil, + c.POBLACION poblacion, + p.`name` provincia, + vn2008.red(f.futur) futur, + c.Credito credito, + pm.`name` forma_pago, + vn2008.red(c365 / 12) consumo_medio365, + vn2008.red(c365) consumo365, + vn2008.red(CmLy.peso) peso_mes_año_pasado, + vn2008.red(CmLy.peso * 1.19) objetivo, + tr.CodigoTrabajador, + vn2008.red(mes_actual.consumo) consumoMes, + vn2008.red(IFNULL(mes_actual.consumo, 0) - IFNULL(CmLy.peso * 1.19, 0)) como_lo_llevo, + DATE(LastTicket) ultimo_ticket, + dead.muerto, + g.Greuge, + cr.recobro + FROM + vn2008.Clientes c + LEFT JOIN + (SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge + FROM vn2008.Greuges g + JOIN vn.`client` c ON c.id = g.Id_Cliente + LEFT JOIN vn.worker w ON c.salesPersonFk = w.id + WHERE (c.salesPersonFk = vWorker OR w.bossFk = vWorker) + GROUP BY Id_Cliente + ) g ON g.Id_Cliente = c.Id_Cliente + LEFT JOIN + vn2008.province p ON p.province_id = c.province_id + JOIN + vn2008.pay_met pm ON pm.id = c.pay_met_id + LEFT JOIN + vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador + LEFT JOIN + bi.claims_ratio cr on cr.Id_Cliente = c.Id_Cliente + LEFT JOIN + (SELECT v.Id_Cliente, SUM(importe) c365 -- optimizat de 6s /5.3s/ 4.7s a 0.3/0.4/0.3 + FROM bs.ventas v + JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente + WHERE v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, vDate) AND vDate + GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente + LEFT JOIN + (SELECT + Id_Cliente, SUM(importe) consumo + FROM + bs.ventas v + INNER JOIN vn2008.Clientes c USING (Id_Cliente) + LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador + WHERE + (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(vDate) + 1, vDate) AND TIMESTAMPADD(DAY, - 1, vDate)) + GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente + LEFT JOIN + (SELECT t.Id_Cliente, SUM(m.preu * m.Cantidad * (1 - m.Descuento / 100)) futur + FROM vn2008.Tickets t + JOIN vn2008.Clientes c ON c.Id_Cliente = t.Id_Cliente + JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket + LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador + WHERE + (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + AND t.Fecha BETWEEN vDate AND util.dayEnd(LAST_DAY(vDate)) + GROUP BY Id_Cliente) f ON c.Id_Cliente = f.Id_Cliente + LEFT JOIN + (SELECT MAX(t.Fecha) LastTicket, c.Id_Cliente + FROM vn2008.Tickets t + JOIN vn2008.Clientes c ON c.Id_cliente = t.Id_Cliente + LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador + WHERE + (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + GROUP BY t.Id_Cliente) LastTicket ON LastTicket.Id_Cliente = c.Id_Cliente + LEFT JOIN + ( + SELECT SUM(importe) peso, c.Id_Cliente + FROM bs.ventas v + JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente + LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador + WHERE fecha BETWEEN vAYearAgoStarted and vAYearAgoEnded + AND (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + GROUP BY c.Id_Cliente) CmLy ON CmLy.Id_Cliente = c.Id_Cliente + LEFT JOIN + (SELECT c.Id_Cliente, + IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto + FROM vn2008.Facturas f + JOIN vn2008.Clientes c ON c.Id_cliente = f.Id_Cliente + LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador + WHERE (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente + JOIN tmp.workerHierarchyList s ON s.workerFk = c.Id_Trabajador; + + DROP TEMPORARY TABLE tmp.workerHierarchyList; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/compradores_evolution_add.sql b/db/routines/bs/procedures/compradores_evolution_add.sql new file mode 100644 index 000000000..e9b073e28 --- /dev/null +++ b/db/routines/bs/procedures/compradores_evolution_add.sql @@ -0,0 +1,66 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`compradores_evolution_add`() +BEGIN +/** + * Inserta en la tabla compradores_evolution las ventas acumuladas en los ultimos 365 dias + * + */ + DECLARE vDated DATE; + DECLARE vCount INT DEFAULT 1; + + SELECT MAX(fecha) + INTERVAL 1 DAY INTO vDated + FROM compradores_evolution; + + IF vDated IS NULL THEN + + SELECT MIN(dated) INTO vDated + FROM sale; + + INSERT INTO compradores_evolution( + Id_Trabajador, + fecha, + importe) + SELECT it.workerFk, + vDated, + SUM(s.amount) + FROM sale s + JOIN vn.itemType it ON it.id = s.typeFk + WHERE s.dated = vDated + GROUP BY it.workerFk; + + SET vDated = vDated + INTERVAL 1 DAY; + END IF; + + WHILE vDated < util.VN_CURDATE() DO + + SET vCount = vCount + 1; + + REPLACE compradores_evolution( + Id_Trabajador, + fecha, + importe) + SELECT Id_Trabajador, + vDated, + SUM(importe) + FROM( + SELECT Id_Trabajador, importe + FROM compradores_evolution + JOIN ( + SELECT DISTINCT it.workerFk + FROM vn.itemType it + )sub2 ON sub2.workerFk = Id_Trabajador + WHERE fecha = vDated - INTERVAL 1 DAY + UNION ALL + SELECT it.workerFk, s.amount * IF(s.dated < vDated, -1, 1) + FROM sale s + JOIN vn.itemType it ON it.id = s.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE s.dated IN (vDated, vDated - INTERVAL 1 YEAR) + AND ic.merchandise + )sub + GROUP BY Id_Trabajador; + + SET vDated = vDated + INTERVAL 1 DAY; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/fondo_evolution_add.sql b/db/routines/bs/procedures/fondo_evolution_add.sql new file mode 100644 index 000000000..3ca91e647 --- /dev/null +++ b/db/routines/bs/procedures/fondo_evolution_add.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`fondo_evolution_add`() +BEGIN +/** + * Inserta en la tabla fondo_maniobra los saldos acumulados en los ultimos 365 dias + */ + DECLARE datFEC DATE DEFAULT '2015-01-01'; + + SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) + INTO datFEC + FROM bs.fondo_maniobra; + + WHILE datFEC < util.VN_CURDATE() DO + + IF DAY(datFEC) MOD 28 = 0 THEN -- esto solo sirve para no aburrirse mientras esperamos... + SELECT datFEC; + END IF; + + REPLACE bs.fondo_maniobra(Fecha, clientes_facturas, clientes_cobros,proveedores_facturas,proveedores_pagos, fondo) + SELECT datFEC AS Fecha, Facturas, Cobros,Recibidas,Pagos, Facturas + Cobros + Recibidas + Pagos + FROM ( + SELECT SUM(io.amount) AS Facturas + FROM vn.invoiceOut io + JOIN vn.client c ON io.clientFk = c.id + WHERE c.isRelevant + AND io.companyFk <> 1381 + AND io.issued BETWEEN '2011-01-01' AND datFEC + ) fac + JOIN ( + SELECT - SUM(r.amountPaid) AS Cobros + FROM vn.receipt r + JOIN vn.client c ON r.clientFk = c.id + WHERE c.isRelevant + AND r.companyFk <> 1381 + AND r.payed BETWEEN '2011-01-01' AND datFEC + ) cob + JOIN ( + SELECT - SUM(id.amount) AS Recibidas + FROM vn.invoiceIn ii + JOIN vn.invoiceInDueDay id ON ii.id = id.invoiceInFk + WHERE ii.companyFk <> 1381 + AND ii.issued BETWEEN '2015-01-01' AND datFEC + ) rec + JOIN ( + SELECT SUM(p.amount) AS Pagos + FROM vn.payment p + WHERE p.companyFk <>1381 + AND p.received BETWEEN '2015-01-01' AND datFEC + ) pag; + + UPDATE bs.fondo_maniobra + JOIN ( + SELECT AVG(fondo) AS media + FROM bs.fondo_maniobra + WHERE fecha <= datFEC + ) sub + SET fondo_medio = media WHERE fecha = datFEC; + + SET datFEC = TIMESTAMPADD(DAY,1,datFEC); + + END WHILE; + + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/fruitsEvolution.sql b/db/routines/bs/procedures/fruitsEvolution.sql new file mode 100644 index 000000000..c689f4b76 --- /dev/null +++ b/db/routines/bs/procedures/fruitsEvolution.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`fruitsEvolution`() +BEGIN +select Id_Cliente, + Cliente, count(semana) as semanas, (w.code IS NOT NULL) isWorker +from ( +select distinct v.Id_Cliente, c.name as Cliente, week(fecha, 3) as semana +from bs.ventas v +join vn.itemType it ON it.id = v.tipo_id +join vn.client c ON c.id = v.Id_Cliente +where it.categoryFk = 12 +and v.fecha > '2020-01-01') sub +left join vn.worker w ON w.id = sub.Id_Cliente +group by Id_Cliente; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/indicatorsUpdate.sql b/db/routines/bs/procedures/indicatorsUpdate.sql new file mode 100644 index 000000000..b2a3ee8b3 --- /dev/null +++ b/db/routines/bs/procedures/indicatorsUpdate.sql @@ -0,0 +1,150 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`indicatorsUpdate`(vDated DATE) +BEGIN + + DECLARE oneYearBefore DATE DEFAULT TIMESTAMPADD(YEAR,-1, vDated); + DECLARE twoMonthsBefore DATE DEFAULT TIMESTAMPADD(DAY,-60, vDated); + DECLARE oneMonthBefore DATE DEFAULT TIMESTAMPADD(DAY,-30, vDated); + DECLARE vWeek INT; + + REPLACE indicators(updated) + VALUES(vDated); + + -- Ventas totales del ultimo año + UPDATE indicators + SET lastYearSales = + (SELECT SUM(importe + recargo) + FROM ventas v + JOIN vn2008.empresa e ON e.id = v.empresa_id + JOIN vn2008.empresa_grupo eg ON eg.empresa_grupo_id = e.empresa_grupo + WHERE fecha BETWEEN oneYearBefore AND vDated + AND eg.grupo = 'Verdnatura' + ) + WHERE updated = vDated; + + -- Greuge total acumulado + UPDATE indicators + SET totalGreuge = + (SELECT SUM(amount) + FROM vn.greuge + WHERE shipped <= vDated + ) + WHERE updated = vDated; + + -- Tasa de morosidad con respecto a las ventas del último mes + UPDATE indicators + SET latePaymentRate = + (SELECT SUM(amount) + FROM bi.defaulters + WHERE date = vDated AND amount > 0) + / + (SELECT SUM(importe + recargo) + FROM ventas + WHERE fecha BETWEEN oneMonthBefore AND vDated) + WHERE updated = vDated; + + -- Número de trabajadores activos + UPDATE indicators + SET countEmployee = + (SELECT CAST(SUM(ct.hoursWeek) / 40 AS DECIMAL (10, 2)) + FROM vn.business b + JOIN vn.calendarType ct ON ct.id = b.calendarTypeFk + WHERE vDated BETWEEN b.started AND IFNULL(b.ended, vDated) + AND b.companyCodeFk = 'VNL' + ) + WHERE updated = vDated; + + -- Maná medio acumulado por comercial + UPDATE indicators + SET averageMana = + (SELECT AVG(amount) + FROM vn.workerMana + ) + WHERE updated = vDated; + + -- Número de clientes que han comprado en los últimos 30 dias + UPDATE indicators + SET lastMonthActiveClients = + (SELECT COUNT(DISTINCT t.clientFk) + FROM vn.ticket t + WHERE t.shipped BETWEEN oneMonthBefore AND vDated + ) + WHERE updated = vDated; + + -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores + UPDATE indicators + SET lastMonthLostClients = + (SELECT COUNT(lm.clientFk) + FROM + (SELECT DISTINCT t.clientFk + FROM vn.ticket t + WHERE t.shipped BETWEEN oneMonthBefore AND vDated + ) cm + RIGHT JOIN + (SELECT DISTINCT t.clientFk + FROM vn.ticket t + WHERE t.shipped >= twoMonthsBefore + AND t.shipped < oneMonthBefore + ) lm ON lm.clientFk = cm.clientFk + WHERE cm.clientFk IS NULL + ) + WHERE updated = vDated; + + -- Número de clientes que han comprado en los últimos 30 dias, pero no compraron en los 30 anteriores + UPDATE indicators + SET lastMonthNewClients = + (SELECT COUNT(cm.clientFk) + FROM + (SELECT DISTINCT t.clientFk + FROM vn.ticket t + WHERE t.shipped BETWEEN oneMonthBefore AND vDated + ) cm + LEFT JOIN + (SELECT DISTINCT t.clientFk + FROM vn.ticket t + WHERE t.shipped >= twoMonthsBefore + AND t.shipped < oneMonthBefore + ) lm ON lm.clientFk = cm.clientFk + WHERE lm.clientFk IS NULL + ) + WHERE updated = vDated; + + -- Porcentaje de autopedidos sobre los pedidos totales + UPDATE indicators + SET lastMonthWebBuyingRate = + (SELECT (SUM(source_app != '') - SUM(source_app = 'TPV')) / SUM(source_app != '') + FROM hedera.`order` + WHERE date_send BETWEEN oneMonthBefore AND vDated + ) + WHERE updated = vDated; + + -- Cálculo de las ventas agrupado por semanas + SELECT week INTO vWeek + FROM vn.time + WHERE dated = vDated; + + TRUNCATE salesByWeek; + + INSERT INTO salesByWeek (week, year, sales) + SELECT t.week, t.year, SUM(v.importe + v.recargo) sales + FROM ventas v + LEFT JOIN vn.time t ON t.dated = fecha + GROUP BY t.week, t.year + ORDER BY t.week, t.year; + + -- Indicador Ventas semana actual + UPDATE indicators i + JOIN salesByWeek s ON s.week= vWeek + AND s.year = YEAR(vDated) + SET i.thisWeekSales = s.sales + WHERE updated = vDated; + + -- Indicador ventas semana actual en el año pasado + UPDATE indicators i + JOIN salesByWeek s ON s.week = vWeek + AND s.year = YEAR(vDated)-1 + SET i.lastYearWeekSales = s.sales + WHERE updated = vDated; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/indicatorsUpdateLauncher.sql b/db/routines/bs/procedures/indicatorsUpdateLauncher.sql new file mode 100644 index 000000000..8ede28ec8 --- /dev/null +++ b/db/routines/bs/procedures/indicatorsUpdateLauncher.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`indicatorsUpdateLauncher`() +BEGIN + + DECLARE vDated DATE; + + SELECT IFNULL(TIMESTAMPADD(DAY,1,MAX(updated)), '2018-04-01') + INTO vDated + FROM bs.indicators; + + WHILE vDated < util.VN_CURDATE() DO + + CALL indicatorsUpdate(vDated); + + SELECT TIMESTAMPADD(DAY,1,MAX(updated)) + INTO vDated + FROM bs.indicators; + + END WHILE; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/inventoryDiscrepancyDetail_replace.sql b/db/routines/bs/procedures/inventoryDiscrepancyDetail_replace.sql new file mode 100644 index 000000000..863005373 --- /dev/null +++ b/db/routines/bs/procedures/inventoryDiscrepancyDetail_replace.sql @@ -0,0 +1,92 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`inventoryDiscrepancyDetail_replace`() +BEGIN +/** + * Replace all records in table inventoryDiscrepancyDetail and insert new + * records into inventoryDiscrepancy for all inventory warehouses. + */ + DECLARE vDone INT DEFAULT FALSE; + DECLARE vCalc INT; + DECLARE vWarehouseFk INT; + + DECLARE cWarehouses CURSOR FOR + SELECT id + FROM vn.warehouse + WHERE isInventory; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + TRUNCATE TABLE inventoryDiscrepancyDetail; + + OPEN cWarehouses; + read_loop: LOOP + SET vDone = FALSE; + FETCH cWarehouses INTO vWarehouseFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + CALL cache.visible_refresh(vCalc, FALSE, vWarehouseFk); + + CREATE OR REPLACE TEMPORARY TABLE tVisible + SELECT itemFk, SUM(visible) totalVisible + 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 sc ON sc.id = p.sectorFk + WHERE sc.warehouseFk = vWarehouseFk + GROUP BY itemFk; + + INSERT INTO inventoryDiscrepancyDetail( + warehouseFk, + itemFk, + theorical, + visible, + notPicked, + alert) + SELECT vWarehouseFk warehouseFk, + v.item_id itemFk, + v.visible, + tv.totalVisible, + s.notPicked, + CASE + WHEN s.notPicked > IFNULL(tv.totalVisible, 0) THEN 0 + WHEN v.visible > IFNULL((tv.totalVisible * 2), 0) THEN 1 + WHEN v.visible > tv.totalVisible THEN 2 + ELSE 3 + END alert + FROM cache.visible v + LEFT JOIN tVisible tv ON tv.itemFk = v.item_id + JOIN ( + SELECT s.itemFk, SUM(s.quantity) notPicked + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.alertLevel al ON al.id = ts.alertLevel + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s.isPicked = FALSE + AND al.code = 'FREE' + AND t.warehouseFk = vWarehouseFk + GROUP BY s.itemFk + HAVING notPicked + ) s ON s.itemFk = v.item_id + WHERE v.calc_id = vCalc + AND NOT v.visible <=> tv.totalVisible; + + END LOOP; + CLOSE cWarehouses; + + INSERT INTO inventoryDiscrepancy( + warehouseFk, + alert, + quantity) + SELECT warehouseFk, + alert, + COUNT(*) + FROM inventoryDiscrepancyDetail + GROUP BY warehouseFk, alert; + + DROP TEMPORARY TABLE IF EXISTS tVisible; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/m3Add.sql b/db/routines/bs/procedures/m3Add.sql new file mode 100644 index 000000000..0ec2c8ce2 --- /dev/null +++ b/db/routines/bs/procedures/m3Add.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`m3Add`() +BEGIN + + DECLARE datSTART DATE; + DECLARE datEND DATE; + + SELECT TIMESTAMPADD(WEEK, -1,MAX(fecha)) INTO datSTART + FROM bs.m3; + + SET datEND = TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); + + DELETE FROM bs.m3 + WHERE fecha >= datSTART; + + INSERT INTO bs.m3 (fecha, provinceFk, warehouseFk, m3, year, month, week, day, dayName, euros) + SELECT v.fecha, a.provinceFk, t.warehouseFk, sum(s.quantity * ic.cm3delivery) / 1000000 AS m3, + tm.year, tm.month, tm.week, tm.day, dayname(v.fecha), sum(importe) + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN bs.ventas v ON v.Id_Movimiento = s.id -- Filtra solo por ventas "buenas" + JOIN vn.time tm ON tm.dated = v.fecha + JOIN vn.itemCost ic ON ic.itemFk = s.itemFk AND ic.warehouseFk = t.warehouseFk + JOIN vn.address a ON a.id = t.addressFk + WHERE v.fecha BETWEEN datSTART AND datEND + AND s.quantity > 0 -- evita abonos + AND t.companyFk = 442 -- Verdnatura + GROUP BY t.warehouseFk, v.fecha, a.provinceFk; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/manaCustomerUpdate.sql b/db/routines/bs/procedures/manaCustomerUpdate.sql new file mode 100644 index 000000000..1e9cb8429 --- /dev/null +++ b/db/routines/bs/procedures/manaCustomerUpdate.sql @@ -0,0 +1,101 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`manaCustomerUpdate`() +BEGIN + DECLARE vToDated DATE; + DECLARE vFromDated DATE; + DECLARE vForDeleteDated DATE; + DECLARE vManaId INT; + DECLARE vManaAutoId INT; + DECLARE vClaimManaId INT; + DECLARE vManaBankId INT; + DECLARE vManaGreugeTypeId INT; + DECLARE vManaFromDays INT; + DECLARE vManaToDays INT; + + SELECT id INTO vManaId + FROM vn.component WHERE code = 'mana'; + + SELECT id INTO vManaAutoId + FROM vn.component WHERE code = 'autoMana'; + + SELECT id INTO vClaimManaId + FROM vn.component WHERE code = 'manaClaim'; + + SELECT id INTO vManaBankId + FROM vn.bank WHERE code = 'mana'; + + SELECT id INTO vManaGreugeTypeId + FROM vn.greugeType WHERE code = 'mana'; + + SELECT manaFromDays, manaToDays + INTO vManaFromDays, vManaToDays + FROM vn.salespersonConfig; + + SELECT MAX(dated) + INTO vFromDated + FROM vn.clientManaCache; + + DELETE + FROM vn.clientManaCache + WHERE dated = vFromDated; + + SELECT MAX(dated) + INTO vFromDated + FROM vn.clientManaCache; + + IF ISNULL(vFromDated) THEN + SELECT manaDateFrom + INTO vFromDated + FROM vn.salespersonConfig; + END IF; + + WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO + SELECT + vFromDated + INTERVAL vManaToDays DAY, + vFromDated - INTERVAL vManaFromDays DAY + INTO + vToDated, + vForDeleteDated; + + DELETE FROM vn.clientManaCache + WHERE dated <= vForDeleteDated; + + INSERT INTO vn.clientManaCache(clientFk, mana, dated) + SELECT + Id_Cliente, + SUM(mana), + vToDated + FROM + ( + SELECT cs.Id_Cliente, Cantidad * Valor as mana + FROM vn2008.Tickets t + JOIN vn2008.Consignatarios cs using(Id_Consigna) + JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento + WHERE Id_Componente IN (vManaAutoId, vManaId, vClaimManaId) + AND t.Fecha > vFromDated + AND date(t.Fecha) <= vToDated + UNION ALL + SELECT r.Id_Cliente, - Entregado + FROM vn2008.Recibos r + WHERE Id_Banco = vManaBankId + AND Fechacobro > vFromDated + AND Fechacobro <= vToDated + UNION ALL + SELECT g.Id_Cliente, g.Importe + FROM vn2008.Greuges g + WHERE Greuges_type_id = vManaGreugeTypeId + AND Fecha > vFromDated + AND Fecha <= vToDated + UNION ALL + SELECT clientFk, mana + FROM vn.clientManaCache + WHERE dated = vFromDated + ) sub + GROUP BY Id_Cliente + HAVING Id_Cliente; + + SET vFromDated = vToDated; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/manaSpellers_actualize.sql b/db/routines/bs/procedures/manaSpellers_actualize.sql new file mode 100644 index 000000000..20b0f84f8 --- /dev/null +++ b/db/routines/bs/procedures/manaSpellers_actualize.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`manaSpellers_actualize`() +BEGIN +/** + * Recalcula el valor del campo con el modificador de precio + * para el componente de maná automático. + */ + UPDATE vn.workerMana wm + JOIN ( + SELECT c.lastSalesPersonFk, + FLOOR(SUM(s.amount) / 12) amount + FROM salesByclientSalesPerson s + JOIN vn.client c ON c.id = s.clientFk + WHERE s.dated BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR AND util.VN_CURDATE() + GROUP BY c.lastSalesPersonFk + )avgPortfolioWeight ON avgPortfolioWeight.lastSalesPersonFk = wm.workerFk + JOIN vn.salespersonConfig spc + SET wm.pricesModifierRate = + IFNULL( + GREATEST( + spc.manaMinRate, + LEAST( + spc.manaMaxRate, + ROUND( - wm.amount / avgPortfolioWeight.amount, 3) + ) + ) + ,0); +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/nightTask_launchAll.sql b/db/routines/bs/procedures/nightTask_launchAll.sql new file mode 100644 index 000000000..59899ee03 --- /dev/null +++ b/db/routines/bs/procedures/nightTask_launchAll.sql @@ -0,0 +1,80 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`nightTask_launchAll`() +BEGIN +/** + * Runs all nightly tasks. + */ + DECLARE vDone BOOL; + DECLARE vError VARCHAR(255); + DECLARE vErrorCode VARCHAR(255); + DECLARE vSchema VARCHAR(255); + DECLARE vProcedure VARCHAR(255); + DECLARE vLogMail VARCHAR(255); + DECLARE vNightTaskFk INT; + + DECLARE vQueue CURSOR FOR + SELECT id, `schema`, `procedure` + FROM nightTask + WHERE finished <= util.VN_CURDATE() + OR finished IS NULL + ORDER BY `order`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SET max_sp_recursion_depth = 3; + + SELECT logMail INTO vLogMail + FROM nightTaskConfig LIMIT 1; + + OPEN vQueue; + l: LOOP + SET vDone = FALSE; + FETCH vQueue INTO vNightTaskFk, vSchema, vProcedure; + + IF vDone THEN + LEAVE l; + END IF; + + UPDATE nightTask + SET `started` = util.VN_NOW(), + `finished` = NULL, + `error` = NULL, + `errorCode` = NULL + WHERE id = vNightTaskFk; + + SET vError = NULL; + CALL nightTask_launchTask( + vSchema, + vProcedure, + vError, + vErrorCode + ); + + IF vError IS NOT NULL THEN + IF vLogMail IS NOT NULL THEN + CALL vn.mail_insert( + vLogMail, + NULL, + CONCAT('Nightly task failed (', vSchema, '.', vProcedure, ')'), + CONCAT( + '[', vErrorCode, '] ', vError, CHAR(13, 10), -- Line break + 'See ', SCHEMA(), '.nightTask table for more info.' + ) + ); + END IF; + + UPDATE nightTask + SET `error` = vError, + `errorCode` = vErrorCode + WHERE id = vNightTaskFk; + ELSE + UPDATE nightTask + SET finished = util.VN_NOW(), + lastFinished = util.VN_NOW() + WHERE id = vNightTaskFk; + END IF; + END LOOP; + CLOSE vQueue; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/nightTask_launchTask.sql b/db/routines/bs/procedures/nightTask_launchTask.sql new file mode 100644 index 000000000..aa4c540e8 --- /dev/null +++ b/db/routines/bs/procedures/nightTask_launchTask.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`nightTask_launchTask`( + vSchema VARCHAR(255), + vProcedure VARCHAR(255), + OUT vError VARCHAR(255), + OUT vErrorCode VARCHAR(255) +) +BEGIN +/** + * Runs an specific procedure from nightly tasks, if an error + * occurs, instead of throw it, #vError and #vErrorCode variables + * are setted. + * + * @param vSchema The procedure schema + * @param vProcedure The procedure name + * @param vError The error message, if any + * @param vErrorCode The error code, if any + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + GET DIAGNOSTICS CONDITION 1 + vError = MESSAGE_TEXT, + vErrorCode = RETURNED_SQLSTATE; + + CALL util.exec(CONCAT('CALL `', vSchema ,'`.`', vProcedure ,'`')); +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/payMethodClientAdd.sql b/db/routines/bs/procedures/payMethodClientAdd.sql new file mode 100644 index 000000000..0c19f453a --- /dev/null +++ b/db/routines/bs/procedures/payMethodClientAdd.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`payMethodClientAdd`() +BEGIN + INSERT IGNORE INTO `bs`.`payMethodClient` (dated, payMethodFk, clientFk) + SELECT util.VN_CURDATE(), c.payMethodFk, c.id + FROM vn.client c + JOIN vn.payMethod p ON c.payMethodFk = p.id; + + TRUNCATE `bs`.`payMethodClientEvolution` ; + + INSERT INTO `bs`.`payMethodClientEvolution` (dated, payMethodName, amountClient, amount, equalizationTax) + SELECT p.dated, pm.name, COUNT(p.clientFk), SUM(sub.importe) , SUM(sub.recargo) + FROM bs.payMethodClient p + JOIN (SELECT SUM(v.importe) AS importe, SUM(v.recargo) as recargo, v.fecha, v.Id_cliente + FROM bs.ventas v + WHERE v.fecha>= (SELECT MIN(dated) FROM bs. payMethodClient) + GROUP BY v.Id_cliente, v.fecha) sub ON sub.fecha = p.dated AND sub.Id_cliente = p.ClientFk + JOIN vn.payMethod pm ON p.payMethodFk = pm.id + GROUP BY dated,payMethodFk; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/saleGraphic.sql b/db/routines/bs/procedures/saleGraphic.sql new file mode 100644 index 000000000..e1e387980 --- /dev/null +++ b/db/routines/bs/procedures/saleGraphic.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`saleGraphic`(IN vItemFk INT, IN vTypeFk INT, IN vCategoryFk INT, IN vFromDate DATE, + IN vToDate DATE, IN vProducerFk INT) +BEGIN + + DECLARE vFromDateLastYear DATE; + DECLARE vToDateLastYear DATE; + DECLARE vFromDateTwoYearsAgo DATE; + DECLARE vToDateTwoYearsAgo DATE; + + SET vItemFk = IFNULL(vItemFk,0); + SET vTypeFk = IFNULL(vTypeFk, 0); + SET vCategoryFk = IFNULL(vCategoryFk,0); + SET vFromDate = IFNULL(vFromDate,util.VN_CURDATE()); + SET vToDate = IFNULL(vToDate,util.VN_CURDATE()); + SET vProducerFk = IFNULL(vProducerFk,0); + + SET vFromDateLastYear = TIMESTAMPADD(YEAR,-1,vFromDate); + SET vToDateLastYear = TIMESTAMPADD(YEAR,-1,vToDate); + SET vFromDateTwoYearsAgo = TIMESTAMPADD(YEAR,-2,vFromDate); + SET vToDateTwoYearsAgo = TIMESTAMPADD(YEAR,-2,vToDate); + + SELECT s.quantity, CAST(v.importe AS DECIMAL(10,0)) importe, v.fecha + FROM bs.ventas v + JOIN vn.sale s ON s.id = v.Id_Movimiento + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE vItemFk IN (i.id, 0) + AND vTypeFk IN (i.typeFk, 0) + AND vCategoryFk IN (it.categoryFk, 0) + AND vProducerFk IN (i.producerFk, 0) + AND (v.fecha BETWEEN vFromDate AND vToDate + OR v.fecha BETWEEN vFromDateLastYear AND vToDateLastYear + OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo + ); + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/salePersonEvolutionAdd.sql b/db/routines/bs/procedures/salePersonEvolutionAdd.sql new file mode 100644 index 000000000..33e31b699 --- /dev/null +++ b/db/routines/bs/procedures/salePersonEvolutionAdd.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`salePersonEvolutionAdd`(IN vDateStart DATETIME) +BEGIN + DELETE FROM bs.salePersonEvolution + WHERE dated <= DATE_SUB(util.VN_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 ; diff --git a/db/routines/bs/procedures/salesByItemTypeDay_add.sql b/db/routines/bs/procedures/salesByItemTypeDay_add.sql new file mode 100644 index 000000000..5c12081a0 --- /dev/null +++ b/db/routines/bs/procedures/salesByItemTypeDay_add.sql @@ -0,0 +1,132 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`salesByItemTypeDay_add`( + vDateStart DATE, + vDateEnd DATE +) +BEGIN +/** + * Almacena datos relativos a las ventas de artículos + * agrupados por reino, familia y día + * + * @param vDateStart + * @param vDateEnd + */ + DELETE FROM salesByItemTypeDay + WHERE dated BETWEEN vDateStart AND vDateEnd; + + INSERT INTO salesByItemTypeDay (itemTypeFk, dated, `references`, stems) + SELECT it.id itemTypeFk, + bs.dated, + COUNT(DISTINCT(i.id)) `references`, + SUM(i.stems * s.quantity) stems + FROM sale bs + JOIN vn.itemType it ON it.id = bs.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.sale s ON s.id = bs.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk + WHERE ic.merchandise + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY it.id, bs.dated; + + INSERT INTO salesByItemTypeDay (itemTypeFk, dated, trash, faults) + SELECT it.id itemTypeFk, + DATE(t.shipped) dated, + SUM(IF(c.name = 'FALTAS', i.stems * s.quantity, 0)) trash, + SUM(IF(c.name = 'BASURA', IFNULL(i.stems, 1) * s.quantity, 0)) faults + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.client c ON c.id = t.clientFk + WHERE c.name IN ('BASURA', 'FALTAS') + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY it.id, dated + ON DUPLICATE KEY UPDATE + trash = VALUES(trash), + faults = VALUES(faults); + + INSERT INTO salesByItemTypeDay (itemTypeFk, dated, accepted, claimed) + SELECT it.id itemTypeFk, + DATE(t.shipped) dated, + SUM( + (cb.quantity * s.price * (100 - s.discount) / 100) * + ((cc.maxResponsibility - c.responsibility ) / 4 ) + ) accepted, + SUM(cb.quantity * s.price * (100 - s.discount) / 100) claimed + FROM vn.claim c + JOIN vn.claimBeginning cb ON cb.claimFk = c.id + JOIN vn.sale s ON s.id = cb.saleFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.claimConfig cc + WHERE ic.merchandise + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY it.id, dated + ON DUPLICATE KEY UPDATE + accepted = VALUES(accepted), + claimed = VALUES(claimed); + + INSERT INTO salesByItemTypeDay (itemTypeFk, dated, sale, buy) + SELECT itemTypeFk, + dated, + CAST(SUM(sale) AS DECIMAL(10,2)) sale, + CAST(SUM(buy) AS DECIMAL(10,2)) buy + FROM ( + SELECT it.id itemTypeFk, + bs.dated, + SUM(amount) sale, + 0 buy + FROM sale bs + JOIN vn.itemType it ON it.id = bs.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.client c ON c.id = bs.clientFk + JOIN vn.sale s ON s.id = bs.saleFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + WHERE ic.merchandise + AND t.shipped BETWEEN vDateStart AND vDateEnd + GROUP BY it.id, bs.dated + UNION ALL + SELECT it.id, + t.landed, + 0, + SUM(b.buyingValue * b.quantity) + FROM vn.entry e + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.buy b ON b.entryFk = e.id + JOIN vn.item i ON i.id = b.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE ic.merchandise + AND t.landed BETWEEN vDateStart AND vDateEnd + GROUP BY it.id, t.landed + ) sub + GROUP BY itemTypeFk, dated + ON DUPLICATE KEY UPDATE + sale = VALUES(sale), + buy = VALUES(buy); + + INSERT INTO salesByItemTypeDay (itemTypeFk, dated, costComponent, marginComponent) + SELECT it.id itemTypeFk, + DATE(t.shipped) dated, + SUM(s.quantity * IF(c.code = 'purchaseValue', sc.value, 0)) costComponent, + SUM(s.quantity * IF(ct.isMargin, sc.value, 0)) marginComponent + FROM vn.ticket t + JOIN vn.sale s ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.saleComponent sc ON sc.saleFk = s.id + STRAIGHT_JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY it.id, dated + ON DUPLICATE KEY UPDATE + costComponent = VALUES(costComponent), + marginComponent = VALUES(marginComponent); +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/salesByItemTypeDay_addLauncher.sql b/db/routines/bs/procedures/salesByItemTypeDay_addLauncher.sql new file mode 100644 index 000000000..3424bac74 --- /dev/null +++ b/db/routines/bs/procedures/salesByItemTypeDay_addLauncher.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`salesByItemTypeDay_addLauncher`() +BEGIN + CALL bs.salesByItemTypeDay_add(util.VN_CURDATE() - INTERVAL 30 DAY, util.VN_CURDATE()); +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/salesByclientSalesPerson_add.sql b/db/routines/bs/procedures/salesByclientSalesPerson_add.sql new file mode 100644 index 000000000..eb441c07b --- /dev/null +++ b/db/routines/bs/procedures/salesByclientSalesPerson_add.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`salesByclientSalesPerson_add`(vDatedFrom DATE) +BEGIN +/** + * Agrupa las ventas por cliente/comercial/fecha en la tabla bs.salesByclientSalesPerson + * El asociación cliente/comercial/fecha, se mantiene correcta en el tiempo + * + * @param vDatedFrom el cálculo se realizará desde la fecha introducida hasta ayer + */ + + IF vDatedFrom IS NULL THEN + SET vDatedFrom = util.VN_CURDATE() - INTERVAL 1 MONTH; + END IF; + + UPDATE salesByclientSalesPerson + SET amount = 0, + equalizationTax = 0, + amountNewBorn = 0 + WHERE dated BETWEEN vDatedFrom AND util.yesterday(); + + INSERT INTO salesByclientSalesPerson( + dated, + salesPersonFk, + clientFk, + amount, + equalizationTax) + SELECT s.dated, + c.salesPersonFk, + s.clientFk, + SUM(s.amount), + SUM(s.surcharge) + FROM sale s + JOIN vn.client c on s.clientFk = c.id + WHERE s.dated BETWEEN vDatedFrom AND util.yesterday() + GROUP BY s.dated, c.salesPersonFk, s.clientFk + ON DUPLICATE KEY UPDATE amount= VALUES(amount), + equalizationTax= VALUES(equalizationTax); + + UPDATE salesByclientSalesPerson s + JOIN vn.newBornSales n ON n.dated = s.dated AND + n.clientFk = s.clientFk + SET s.amountNewBorn = n.amount + WHERE n.dated BETWEEN vDatedFrom AND util.yesterday(); + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/salesPersonEvolution_add.sql b/db/routines/bs/procedures/salesPersonEvolution_add.sql new file mode 100644 index 000000000..ea150e182 --- /dev/null +++ b/db/routines/bs/procedures/salesPersonEvolution_add.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`salesPersonEvolution_add`() +BEGIN +/** + * Calcula los datos para los gráficos de evolución agrupado por salesPersonFk y día. + * Recalcula automáticamente los 3 últimos meses para comprobar si hay algún cambio. + */ + DECLARE vDated DATE; + DECLARE vCont INT DEFAULT 1; + + SELECT MAX(dated) - INTERVAL 3 MONTH INTO vDated + FROM salesPersonEvolution; + + DELETE FROM salesPersonEvolution + WHERE dated >= vDated; + + IF ISNULL(vDated) THEN + SELECT MIN(dated) INTO vDated + FROM salesByclientSalesPerson; + + INSERT INTO salesPersonEvolution( + salesPersonFk, + dated, + amount, + equalizationTax, + amountNewBorn + ) + SELECT salesPersonFk, + dated, + amount, + equalizationTax, + amountNewBorn + FROM salesByclientSalesPerson + WHERE dated = vDated + GROUP BY salesPersonFk; + + SET vDated = vDated + INTERVAL 1 DAY; + END IF; + + WHILE vDated < util.VN_CURDATE() DO + + SET vCont = vCont + 1; + REPLACE salesPersonEvolution(salesPersonFk, dated, amount) + SELECT salesPersonFk, vDated, amount + FROM(SELECT salesPersonFk, SUM(amount) amount + FROM(SELECT salesPersonFk, amount + FROM salesPersonEvolution + WHERE dated = vDated - INTERVAL 1 DAY + UNION ALL + SELECT salesPersonFk, amount + FROM salesByclientSalesPerson + WHERE dated = vDated + UNION ALL + SELECT salesPersonFk, - amount + FROM salesByclientSalesPerson + WHERE dated = vDated - INTERVAL 1 YEAR + )sub + GROUP BY salesPersonFk + )sub + GROUP BY salesPersonFk; + + SET vDated = vDated + INTERVAL 1 DAY; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/vendedores_add_launcher.sql b/db/routines/bs/procedures/vendedores_add_launcher.sql new file mode 100644 index 000000000..c0718a659 --- /dev/null +++ b/db/routines/bs/procedures/vendedores_add_launcher.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vendedores_add_launcher`() +BEGIN + + CALL bs.salesByclientSalesPerson_add(util.VN_CURDATE()- INTERVAL 45 DAY); + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/ventas_add.sql b/db/routines/bs/procedures/ventas_add.sql new file mode 100644 index 000000000..fcb00e092 --- /dev/null +++ b/db/routines/bs/procedures/ventas_add.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_add`( + IN vStarted DATETIME, + IN vEnded DATETIME) +BEGIN +/** +* Añade las ventas que se realizaron entre +* vStarted y vEnded +* +* @param vStarted Fecha de inicio +* @param vEnded Fecha de finalizacion +* +**/ + DECLARE vStartingDate DATETIME; + DECLARE vEndingDate DATETIME; + + IF vStarted < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) + OR vEnded < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) THEN + CALL util.throw('fechaDemasiadoAntigua'); + END IF; + + SET vEnded = util.dayEnd(vEnded); + SET vStartingDate = vStarted ; + SET vEndingDate = util.dayEnd(vStartingDate); + + DELETE + FROM sale + WHERE dated BETWEEN vStartingDate AND vEnded; + + WHILE vEndingDate <= vEnded DO + + REPLACE ventas(Id_Movimiento, importe, recargo, fecha, tipo_id, Id_Cliente, empresa_id) + SELECT saleFk, + SUM(IF(ct.isBase, s.quantity * sc.value, 0)) importe, + SUM(IF(ct.isBase, 0, s.quantity * sc.value)) recargo, + vStartingDate, + i.typeFk, + a.clientFk, + t.companyFk + FROM vn.saleComponent sc + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.sale s ON s.id = sc.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.client cl ON cl.id = a.clientFk + WHERE t.shipped BETWEEN vStartingDate AND vEndingDate + AND s.quantity <> 0 + AND s.discount <> 100 + AND ic.merchandise + GROUP BY sc.saleFk + HAVING IFNULL(importe,0) <> 0 OR IFNULL(recargo,0) <> 0; + + UPDATE sale s + JOIN ( + SELECT s.id, + SUM(s.quantity * sc.value ) margen, + s.quantity * s.price * (100 - s.discount ) / 100 pvp + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.saleComponent sc ON sc.saleFk = s.id + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE t.shipped BETWEEN vStartingDate AND vEndingDate + AND ct.isMargin = TRUE + GROUP BY s.id) sub ON sub.id = s.saleFk + SET s.margin = sub.margen + s.amount + s.surcharge - sub.pvp; + + SET vStartingDate = TIMESTAMPADD(DAY,1, vStartingDate); + SET vEndingDate = util.dayEnd(vStartingDate); + + END WHILE; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/ventas_add_launcher.sql b/db/routines/bs/procedures/ventas_add_launcher.sql new file mode 100644 index 000000000..0d9e89a89 --- /dev/null +++ b/db/routines/bs/procedures/ventas_add_launcher.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_add_launcher`() +BEGIN +/** + * Añade las ventas a la tabla bs.sale que se realizaron desde hace un mes hasta hoy + * + */ + + DECLARE vCurDate DATE DEFAULT util.VN_CURDATE(); + CALL ventas_add(vCurDate - INTERVAL 1 MONTH, vCurDate); + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/ventas_contables_add.sql b/db/routines/bs/procedures/ventas_contables_add.sql new file mode 100644 index 000000000..d8e963e3e --- /dev/null +++ b/db/routines/bs/procedures/ventas_contables_add.sql @@ -0,0 +1,102 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_contables_add`(IN vYear INT, IN vMonth INT) +BEGIN + + /** + * Reemplaza las ventas contables del último año. + * Es el origen de datos para el balance de Entradas + * + * @param vYear Año a reemplazar + * @param vMonth Mes a reemplazar + * + **/ + + DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; + + DELETE FROM bs.ventas_contables + WHERE year = vYear + AND month = vMonth; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + ENGINE = MEMORY + SELECT Id_Ticket + FROM vn2008.Tickets t + JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura + WHERE year(f.Fecha) = vYear + AND month(f.Fecha) = vMonth; + + INSERT INTO bs.ventas_contables(year + , month + , venta + , grupo + , reino_id + , tipo_id + , empresa_id + , gasto) + + SELECT vYear + , vMonth + , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) + , IF( + e.empresa_grupo = e2.empresa_grupo + ,1 + ,IF(e2.empresa_grupo,2,0) + ) as grupo + , tp.reino_id + , a.tipo_id + , t.empresa_id + , 7000000000 + + IF(e.empresa_grupo = e2.empresa_grupo + ,1 + ,IF(e2.empresa_grupo,2,0) + ) * 1000000 + + tp.reino_id * 10000 as Gasto + FROM vn2008.Movimientos m + JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna + JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente + JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket + JOIN vn2008.Articles a on m.Id_Article = a.Id_Article + JOIN vn2008.empresa e on e.id = t.empresa_id + LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente + JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id + WHERE Cantidad <> 0 + AND Preu <> 0 + AND m.Descuento <> 100 + AND a.tipo_id != TIPO_PATRIMONIAL + GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto; + + INSERT INTO bs.ventas_contables(year + , month + , venta + , grupo + , reino_id + , tipo_id + , empresa_id + , gasto) + SELECT vYear + , vMonth + , sum(ts.quantity * ts.price) + , IF( + c.companyGroupFk = c2.companyGroupFk + ,1 + ,IF(c2.companyGroupFk, 2, 0) + ) as grupo + , NULL + , NULL + , t.companyFk + , 7050000000 + FROM vn.ticketService ts + JOIN vn.ticket t ON ts.ticketFk = t.id + JOIN vn.address a on a.id = t.addressFk + JOIN vn.client cl on cl.id = a.clientFk + JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id + JOIN vn.company c on c.id = t.companyFk + LEFT JOIN vn.company c2 on c2.clientFk = cl.id + GROUP BY grupo, t.companyFk ; + + DROP TEMPORARY TABLE tmp.ticket_list; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/ventas_contables_add_launcher.sql b/db/routines/bs/procedures/ventas_contables_add_launcher.sql new file mode 100644 index 000000000..ac74c47bf --- /dev/null +++ b/db/routines/bs/procedures/ventas_contables_add_launcher.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_contables_add_launcher`() +BEGIN + + /** + * Reemplaza las ventas contables del último año. + * Es el origen de datos para el balance de Entradas + * + **/ + + CALL bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()))); + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/ventas_contables_por_cliente.sql b/db/routines/bs/procedures/ventas_contables_por_cliente.sql new file mode 100644 index 000000000..9f1399025 --- /dev/null +++ b/db/routines/bs/procedures/ventas_contables_por_cliente.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT) +BEGIN + + /** + * Muestra las ventas (€) de cada cliente + * dependiendo del año + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + SELECT Id_Ticket + FROM vn2008.Tickets t + JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura + WHERE year(f.Fecha) = vYear + AND month(f.Fecha) = vMonth; + + SELECT vYear Año, + vMonth Mes, + t.Id_Cliente, + round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) Venta, + IF(e.empresa_grupo = e2.empresa_grupo, + 1, + IF(e2.empresa_grupo,2,0)) + AS grupo, + t.empresa_id empresa + FROM vn2008.Movimientos m + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.Id_Consigna + JOIN vn2008.Clientes c ON c.Id_Cliente = cs.Id_Cliente + JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket + JOIN vn2008.Articles a ON m.Id_Article = a.Id_Article + JOIN vn2008.empresa e ON e.id = t.empresa_id + LEFT JOIN vn2008.empresa e2 ON e2.Id_Cliente = c.Id_Cliente + JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id + WHERE Cantidad <> 0 + AND Preu <> 0 + AND m.Descuento <> 100 + AND a.tipo_id != 188 + GROUP BY t.Id_Cliente, grupo,t.empresa_id; + + DROP TEMPORARY TABLE tmp.ticket_list; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/vivosMuertos.sql b/db/routines/bs/procedures/vivosMuertos.sql new file mode 100644 index 000000000..1743eda64 --- /dev/null +++ b/db/routines/bs/procedures/vivosMuertos.sql @@ -0,0 +1,63 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vivosMuertos`() +BEGIN + + /** + * Devuelve el número de clientes nuevos y muertos, + * dependiendo de la fecha actual. + * + * @param @datSTART Fecha de inicio a buscar + * @param @datEND Fecha de finalización a buscar + */ + + SET @datSTART = TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + SET @datEND = TIMESTAMPADD(DAY,-DAY(util.VN_CURDATE()),util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos; + + CREATE TEMPORARY TABLE tmp.VivosMuertos + SELECT c.Id_Cliente, tm.yearMonth, f.Compra, 0 as Nuevo, 0 as Muerto + FROM vn2008.Clientes c + JOIN + (SELECT DISTINCT yearMonth + FROM vn2008.time + WHERE date BETWEEN @datSTART + AND @datEND ) tm + LEFT JOIN + (SELECT DISTINCT tm.yearMonth, f.Id_Cliente , 1 as Compra + FROM vn2008.Facturas f + JOIN vn2008.time tm ON tm.date = f.Fecha + WHERE Fecha BETWEEN @datSTART + AND @datEND) f ON f.yearMonth = tm.yearMonth + AND f.Id_Cliente = c.Id_Cliente; + + UPDATE tmp.VivosMuertos vm + JOIN + (SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente + FROM vn2008.Facturas f + JOIN vn2008.time tm ON tm.date = f.Fecha + WHERE Fecha BETWEEN @datSTART AND @datEND + GROUP BY f.Id_Cliente ) fm ON fm.firstMonth = vm.yearMonth + AND fm.Id_Cliente = vm.Id_Cliente + + SET Nuevo = 1; + + SELECT max(yearMonth) INTO @lastYearMonth FROM tmp.VivosMuertos; + + UPDATE tmp.VivosMuertos vm + JOIN ( + SELECT MAX(tm.yearMonth) firstMonth, f.Id_Cliente + FROM vn2008.Facturas f + JOIN vn2008.time tm ON tm.date = f.Fecha + WHERE Fecha BETWEEN @datSTART AND @datEND + GROUP BY f.Id_Cliente ) fm ON fm.firstMonth = vm.yearMonth + AND fm.Id_Cliente = vm.Id_Cliente + + SET Muerto = 1 + + WHERE yearMonth < @lastYearMonth; + + SELECT * FROM tmp.VivosMuertos; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql new file mode 100644 index 000000000..ac6690129 --- /dev/null +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`() +BEGIN + DECLARE vWeek INT; + DECLARE vYear INT; + + SELECT week, year + INTO vWeek, vYear + FROM vn.time + WHERE dated = util.VN_CURDATE(); + + REPLACE bs.waste + SELECT *, 100 * mermas / total as porcentaje + FROM ( + SELECT buyer, + year, + week, + family, + itemFk, + itemTypeFk, + floor(sum(value)) as total, + floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas + FROM vn.saleValue + where year = vYear and week = vWeek + + GROUP BY family, itemFk + + ) sub + ORDER BY mermas DESC; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/workerLabour_getData.sql b/db/routines/bs/procedures/workerLabour_getData.sql new file mode 100644 index 000000000..1f5a39fe0 --- /dev/null +++ b/db/routines/bs/procedures/workerLabour_getData.sql @@ -0,0 +1,106 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`workerLabour_getData`() +BEGIN +/** + * Carga los datos de la plantilla de trabajadores, altas y bajas en la tabla workerLabourDataByMonth para facilitar el cálculo del gráfico en grafana. + * Se carga el día 21 de cada mes, elimina los registros del último año y los vuelve a calcular + */ + DECLARE vFristDay DATE; + DECLARE vLastDay DATE; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vDateStarted DATE; + DECLARE vDateEnded DATE; + + DECLARE vCursor CURSOR FOR + SELECT util.firstDayOfMonth(t.dated), LAST_DAY(t.dated) + FROM vn.time t + WHERE t.dated BETWEEN vDateStarted AND vDateEnded + GROUP BY year,month; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + IF DAY(util.VN_CURDATE()) = 21 THEN + + SELECT util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 12 MONTH)), + LAST_DAY(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) + INTO vDateStarted, + vDateEnded; + + DELETE FROM workerLabourDataByMonth + WHERE CONCAT(`year`, '-',`month`, '-01') BETWEEN vDateStarted AND vDateEnded; + + OPEN vCursor; + + l: LOOP + SET vDone = FALSE; + + FETCH vCursor INTO vFristDay, vLastDay; + + IF vDone THEN + LEAVE l; + END IF; + + -- Altas periodo + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + FROM vn.business b + JOIN vn.workCenter wc ON wc.id = b.workCenterFk + JOIN vn.worker w ON w.id = b.workerFk + LEFT JOIN vn.workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk + LEFT JOIN (SELECT b.id, b.workerFk + FROM vn.business b + LEFT JOIN (SELECT ended, workerFk FROM vn.business) wl + ON wl.ended = DATE_SUB(b.started, INTERVAL 1 DAY) AND wl.workerFk = b.workerFk + WHERE b.started BETWEEN vFristDay AND vLastDay AND wl.ended + )sub ON sub.workerFk = b.workerFk + WHERE wc.payrollCenterFk IS NOT NULL + AND b.workCenterFk IS NOT NULL + AND b.started BETWEEN vFristDay AND vLastDay + AND sub.workerFk IS NULL + AND NOT w.isFreelance; + + -- Bajas periodo + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + FROM vn.business b + JOIN vn.worker w ON w.id = b.workerFk + JOIN vn.workCenter wc ON wc.id = b.workCenterFk + LEFT JOIN vn.workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk + LEFT JOIN (SELECT started, workerFk FROM vn.business) wl ON wl.started >= b.ended + AND wl.workerFk = b.workerFk + WHERE wc.payrollCenterFk IS NOT NULL + AND b.ended BETWEEN vFristDay AND vLastDay + AND wl.started IS NULL + AND NOT w.isFreelance; + + -- Anterior al periodo + SET vLastDay = LAST_DAY(DATE_SUB(vFristDay, INTERVAL 1 DAY)); + + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + FROM vn.business b + JOIN vn.worker w ON w.id = b.workerFk + JOIN vn.workCenter wc ON wc.id = b.workCenterFk + LEFT JOIN vn.workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk + WHERE wc.payrollCenterFk IS NOT NULL + AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) + AND NOT w.isFreelance; + + -- Discapacidad + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + FROM vn.business b + JOIN vn.worker w ON w.id = b.workerFk + JOIN vn.workCenter wc ON wc.id = b.workCenterFk + LEFT JOIN vn.workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk + WHERE wc.payrollCenterFk IS NOT NULL + AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) + AND w.isDisable + AND NOT w.isFreelance; + + END LOOP; + CLOSE vCursor; + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/bs/procedures/workerProductivity_add.sql b/db/routines/bs/procedures/workerProductivity_add.sql new file mode 100644 index 000000000..3d7dbdca9 --- /dev/null +++ b/db/routines/bs/procedures/workerProductivity_add.sql @@ -0,0 +1,99 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`workerProductivity_add`() +BEGIN + DECLARE vDateFrom DATE; + SELECT DATE_SUB(util.VN_CURDATE(),INTERVAL 30 DAY) INTO vDateFrom; + + DELETE FROM workerProductivity + WHERE dated >= vDateFrom; + + -- SACADORES Y ARTIFICIAL + INSERT INTO workerProductivity(dated, wareHouseFk, workerFk, volume, seconds, stateFk) + SELECT sub.dated, + sub.warehouseFk, + sub.workerFk, + SUM(sub.volume), + SUM(sub.seconds), + sub.stateFk + FROM(SELECT t.warehouseFk warehouseFk, + st.workerFk, + DATE(t.shipped) dated, + SUM((ic.cm3delivery * s.quantity)/1000000) volume, + TIME_TO_SEC(TIMEDIFF( MAX(st.created),MIN(st.created))) + wc.minSeconsItemPicker seconds, + s2.id stateFk + FROM vn.saleTracking st + LEFT JOIN vn.salesPreviousPreparated sp ON sp.saleFk = st.saleFk + JOIN vn.sale s ON s.id = st.saleFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.itemCost ic ON ic.warehouseFk = t.warehouseFk AND ic.itemFk = s.itemFk + JOIN vn.worker w ON w.id = st.workerFk + JOIN vn.state s2 ON s2.id = st.stateFk + LEFT JOIN vn.workerDepartment wd ON wd.workerFk = st.workerFk + JOIN workerProductivityConfig wc ON TRUE + WHERE t.shipped >= vDateFrom + AND ISNULL(sp.saleFk) + AND (s2.code IN ('OK PREVIOUS', 'PREVIOUS_PREPARATION', 'PREPARED', 'OK')) + GROUP BY t.id, t.warehouseFk, st.workerFk + ) sub + GROUP BY sub.warehouseFk, sub.workerFk, sub.dated; + + -- ENCAJADORES + INSERT INTO workerProductivity(dated, wareHouseFk, workerFk, volume, seconds, stateFk) + SELECT sub2.shipped, + sub2.warehouseFk, + sub2.workerFK, + SUM(sub2.volume), + SUM(sub2.seconds), + s2.id stateFk + FROM (SELECT t.warehouseFk, + SUM(s.volume) volume, + sub.workerFk, + DATE(t.shipped) shipped, + sub.seconds + w.minSeconsPackager seconds, + s.saleFk + FROM vn.saleVolume s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN(SELECT e.workerFk, e.ticketFk,TIME_TO_SEC(TIMEDIFF( MAX(e.created), MIN(e.created))) seconds + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE e.workerFk IS NOT NULL AND + t.shipped >= vDateFrom + GROUP BY e.ticketFk + )sub ON sub.ticketFk = t.id + JOIN workerProductivityConfig w ON TRUE + GROUP BY s.ticketFk, t.warehouseFk + )sub2 + JOIN vn.state s2 ON s2.code IN ('PACKING','PACKED') + GROUP BY sub2.warehouseFk,sub2.workerFk, sub2.shipped; + + -- REVISADORES + INSERT INTO workerProductivity(dated, wareHouseFk, workerFk, volume, seconds, stateFk) + SELECT sub2.shipped, + sub2.warehouseFk, + sub2.workerFK, + SUM(sub2.volume), + SUM(sub2.seconds), + sub2.stateFk + FROM (SELECT t.warehouseFk, + SUM(s.volume) volume, + sub.workerFk, + DATE(t.shipped) shipped, + sub.seconds + w.minSeconsPackager seconds, + sub.stateFk + FROM vn.saleVolume s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN(SELECT st.workerFk, t.id ticketFk,TIME_TO_SEC(TIMEDIFF( MAX(st.created), MIN(st.created))) seconds, s2.id stateFk + FROM vn.saleTracking st + JOIN vn.state s2 ON s2.id = st.stateFk + JOIN vn.sale s ON s.id = st.saleFk + JOIN vn.ticket t ON s.ticketFk = t.id + WHERE s2.code = 'CHECKED' + AND t.shipped >= vDateFrom + GROUP BY t.id + )sub ON sub.ticketFk = t.id + JOIN workerProductivityConfig w ON TRUE + GROUP BY s.ticketFk, t.warehouseFk + )sub2 + GROUP BY sub2.warehouseFk,sub2.workerFk, sub2.shipped; +END$$ +DELIMITER ; diff --git a/db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql b/db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql new file mode 100644 index 000000000..ac68eedb8 --- /dev/null +++ b/db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`clientNewBorn_BEFORE_UPDATE` + BEFORE UPDATE ON `clientNewBorn` + FOR EACH ROW +BEGIN + -- Si ha pasado un año o mas + IF TIMESTAMPDIFF(YEAR,NEW.lastShipped, OLD.lastShipped) THEN + SET NEW.firstShipped = NEW.lastShipped; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/bs/triggers/nightTaskBeforeInsert.sql b/db/routines/bs/triggers/nightTaskBeforeInsert.sql new file mode 100644 index 000000000..b32aaf7f5 --- /dev/null +++ b/db/routines/bs/triggers/nightTaskBeforeInsert.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`nightTaskBeforeInsert` + BEFORE INSERT ON `nightTask` + FOR EACH ROW +BEGIN + + IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN + + CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/triggers/nightTaskBeforeUpdate.sql b/db/routines/bs/triggers/nightTaskBeforeUpdate.sql new file mode 100644 index 000000000..fd7fdc0df --- /dev/null +++ b/db/routines/bs/triggers/nightTaskBeforeUpdate.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`nightTaskBeforeUpdate` + BEFORE UPDATE ON `nightTask` + FOR EACH ROW +BEGIN + + IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN + + CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/bs/views/VentasPorCliente.sql b/db/routines/bs/views/VentasPorCliente.sql new file mode 100644 index 000000000..579d3b955 --- /dev/null +++ b/db/routines/bs/views/VentasPorCliente.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`VentasPorCliente` +AS SELECT `v`.`Id_Cliente` AS `Id_Cliente`, + round(sum(`v`.`importe`), 0) AS `VentaBasica`, + `t`.`year` AS `year`, + `t`.`month` AS `month` +FROM ( + `vn2008`.`time` `t` + JOIN `bs`.`ventas` `v` ON(`v`.`fecha` = `t`.`date`) + ) +GROUP BY `v`.`Id_Cliente`, + `t`.`year`, + `t`.`month` diff --git a/db/routines/bs/views/bajasLaborales.sql b/db/routines/bs/views/bajasLaborales.sql new file mode 100644 index 000000000..31f870d06 --- /dev/null +++ b/db/routines/bs/views/bajasLaborales.sql @@ -0,0 +1,31 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`bajasLaborales` +AS SELECT `w`.`firstName` AS `firstname`, + `w`.`lastName` AS `name`, + `b`.`id` AS `businessFk`, + max(`c`.`dated`) AS `lastDate`, + max(IFNULL(`b`.`ended`, `util`.`VN_CURDATE`())) AS `endContract`, + `at`.`name` AS `type`, + cast(COUNT(0) AS decimal(10, 0)) AS `dias`, + `w`.`id` AS `userFk` +FROM ( + ( + ( + `vn`.`calendar` `c` + JOIN `vn`.`business` `b` ON(`b`.`id` = `c`.`businessFk`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `b`.`workerFk`) + ) + JOIN `vn`.`absenceType` `at` ON(`at`.`id` = `c`.`dayOffTypeFk`) + ) +WHERE `c`.`dated` >= `util`.`VN_CURDATE`() + INTERVAL -1 year + AND `at`.`name` NOT IN ( + 'Vacaciones', + 'Vacaciones 1/2 día', + 'Compensar', + 'Festivo' + ) +GROUP BY `w`.`id`, + `at`.`id` +HAVING `endContract` >= `util`.`VN_CURDATE`() diff --git a/db/routines/bs/views/horasSilla.sql b/db/routines/bs/views/horasSilla.sql new file mode 100644 index 000000000..973108e8a --- /dev/null +++ b/db/routines/bs/views/horasSilla.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`horasSilla` +AS SELECT `wj`.`dated` AS `Fecha`, + `d`.`name` AS `Departamento`, + cast(sum(`wj`.`total`) AS decimal(10, 2)) AS `Horas`, + cast( + sum( + (`wj`.`total` + `wj`.`lunch`) * `wj`.`priceOrdinaryHour` + ) AS decimal(10, 2) + ) AS `Salarios` +FROM ( + ( + `vn`.`workerJourney` `wj` + JOIN `vn`.`business` `b` ON(`b`.`id` = `wj`.`businessFk`) + ) + JOIN `vn`.`department` `d` ON(`d`.`id` = `b`.`departmentFk`) + ) +WHERE `d`.`name` IN ( + 'CAMARA', + 'ENCAJADO', + 'PALETIZADORES', + 'PRODUCCION', + 'SACADORES' + ) +GROUP BY `wj`.`dated`, + `d`.`name` diff --git a/db/routines/bs/views/lastIndicators.sql b/db/routines/bs/views/lastIndicators.sql new file mode 100644 index 000000000..3fa04abd3 --- /dev/null +++ b/db/routines/bs/views/lastIndicators.sql @@ -0,0 +1,39 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`lastIndicators` +AS SELECT `i`.`updated` AS `updated`, + `i`.`lastYearSales` AS `lastYearSales`, + `i`.`lastYearSales` - `yi`.`lastYearSales` AS `incLastYearSales`, + `i`.`totalGreuge` AS `totalGreuge`, + `i`.`totalGreuge` - `yi`.`totalGreuge` AS `incTotalGreuge`, + `i`.`latePaymentRate` AS `latePaymentRate`, + `i`.`latePaymentRate` - `yi`.`latePaymentRate` AS `incLatePaymentRate`, + `i`.`countEmployee` AS `countEmployee`, + `i`.`countEmployee` - `yi`.`countEmployee` AS `incCountEmployee`, + `i`.`averageMana` AS `averageMana`, + `i`.`averageMana` - `yi`.`averageMana` AS `incAverageMana`, + `i`.`bankingPool` AS `bankingPool`, + `i`.`bankingPool` - `yi`.`bankingPool` AS `incbankingPool`, + `i`.`lastMonthActiveClients` AS `lastMonthActiveClients`, + `i`.`lastMonthActiveClients` - `yi`.`lastMonthActiveClients` AS `incLastMonthActiveClients`, + `i`.`lastMonthLostClients` AS `lastMonthLostClients`, + `i`.`lastMonthLostClients` - `yi`.`lastMonthLostClients` AS `incLastMonthLostClients`, + `i`.`lastMonthNewClients` AS `lastMonthNewClients`, + `i`.`lastMonthNewClients` - `yi`.`lastMonthNewClients` AS `incLastMonthNewClients`, + `i`.`lastMonthWebBuyingRate` AS `lastMonthWebBuyingRate`, + `i`.`lastMonthWebBuyingRate` - `yi`.`lastMonthWebBuyingRate` AS `incLastMonthWebBuyingRate`, + `i`.`thisWeekSales` AS `thisWeekSales`, + `i`.`lastYearWeekSales` AS `lastYearWeekSales` +FROM ( + `bs`.`indicators` `i` + JOIN `bs`.`indicators` `yi` ON( + `yi`.`updated` = ( + SELECT max(`bs`.`indicators`.`updated`) + INTERVAL -1 DAY + FROM `bs`.`indicators` + ) + ) + ) +WHERE `i`.`updated` = ( + SELECT max(`bs`.`indicators`.`updated`) + FROM `bs`.`indicators` + ) diff --git a/db/routines/bs/views/packingSpeed.sql b/db/routines/bs/views/packingSpeed.sql new file mode 100644 index 000000000..517706b15 --- /dev/null +++ b/db/routines/bs/views/packingSpeed.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`packingSpeed` +AS SELECT HOUR(`e`.`created`) AS `hora`, + MINUTE(`e`.`created`) AS `minuto`, + IFNULL( + `p`.`volume`, + `p`.`width` * `p`.`height` * `p`.`depth` + ) AS `cm3`, + `t`.`warehouseFk` AS `warehouse_id`, + `e`.`created` AS `odbc_date` +FROM ( + ( + `vn`.`expedition` `e` + JOIN `vn`.`packaging` `p` ON(`p`.`id` = `e`.`packagingFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `e`.`ticketFk`) + ) +WHERE `e`.`created` BETWEEN `util`.`VN_CURDATE`() AND `util`.`dayend`(`util`.`VN_CURDATE`()) diff --git a/db/routines/bs/views/s1_ticketDetail.sql b/db/routines/bs/views/s1_ticketDetail.sql new file mode 100644 index 000000000..77fbcdcd9 --- /dev/null +++ b/db/routines/bs/views/s1_ticketDetail.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`s1_ticketDetail` +AS SELECT `s`.`ticketFk` AS `ticketFk`, + cast( + sum(`s`.`price` * `s`.`quantity`) AS decimal(10, 2) + ) AS `ticketAmount`, + COUNT(`s`.`id`) AS `ticketLines`, + cast(sum(`sv`.`volume`) AS decimal(10, 2)) AS `ticketM3`, + cast(`t`.`shipped` AS date) AS `shipped` +FROM ( + ( + `vn`.`ticket` `t` + JOIN `vn`.`sale` `s` ON(`s`.`ticketFk` = `t`.`id`) + ) + JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`) + ) +WHERE `t`.`shipped` BETWEEN '2021-09-01' AND '2021-10-31 23:59' +GROUP BY `s`.`ticketFk` diff --git a/db/routines/bs/views/s21_saleDetail.sql b/db/routines/bs/views/s21_saleDetail.sql new file mode 100644 index 000000000..778994bfb --- /dev/null +++ b/db/routines/bs/views/s21_saleDetail.sql @@ -0,0 +1,42 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`s21_saleDetail` +AS SELECT dayofmonth(`t`.`shipped`) AS `dia`, + year(`t`.`shipped`) AS `año`, + MONTH(`t`.`shipped`) AS `mes`, + `s`.`concept` AS `concepto`, + `s`.`quantity` AS `unidades`, + `s`.`price` AS `precio`, + `s`.`quantity` * `s`.`price` AS `venta`, + `it`.`name` AS `familia`, + `w`.`code` AS `comprador`, + `s`.`itemFk` AS `itemFk`, + `s`.`ticketFk` AS `ticketFk`, + `sv`.`volume` AS `volume` +FROM ( + ( + ( + ( + ( + ( + `vn`.`sale` `s` + JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`) + ) + JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `it`.`workerFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`) + ) + JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`) + ) +WHERE ( + `t`.`shipped` BETWEEN '2020-10-21' AND '2020-10-28' + OR `t`.`shipped` BETWEEN '2019-10-21' AND '2019-10-28' + OR `t`.`shipped` BETWEEN '2021-09-1' AND '2021-10-28' + ) + AND `t`.`warehouseFk` IN (1, 60) + AND `c`.`isRelevant` <> 0 + AND `s`.`quantity` > 0 diff --git a/db/routines/bs/views/ventas.sql b/db/routines/bs/views/ventas.sql new file mode 100644 index 000000000..1fab2e91b --- /dev/null +++ b/db/routines/bs/views/ventas.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `bs`.`ventas` +AS SELECT `s`.`saleFk` AS `Id_Movimiento`, + `s`.`amount` AS `importe`, + `s`.`surcharge` AS `recargo`, + `s`.`dated` AS `fecha`, + `s`.`typeFk` AS `tipo_id`, + `s`.`clientFk` AS `Id_Cliente`, + `s`.`companyFk` AS `empresa_id`, + `s`.`margin` AS `margen` +FROM `bs`.`sale` `s` diff --git a/db/routines/cache/events/cacheCalc_clean.sql b/db/routines/cache/events/cacheCalc_clean.sql new file mode 100644 index 000000000..e13bae98b --- /dev/null +++ b/db/routines/cache/events/cacheCalc_clean.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `cache`.`cacheCalc_clean` + ON SCHEDULE EVERY 30 MINUTE + STARTS '2022-01-28 09:29:18.000' + ON COMPLETION NOT PRESERVE + ENABLE +DO CALL cacheCalc_clean$$ +DELIMITER ; diff --git a/db/routines/cache/events/cache_clean.sql b/db/routines/cache/events/cache_clean.sql new file mode 100644 index 000000000..c5e247bd4 --- /dev/null +++ b/db/routines/cache/events/cache_clean.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `cache`.`cache_clean` + ON SCHEDULE EVERY 5 MINUTE + STARTS '2022-01-28 09:29:18.000' + ON COMPLETION NOT PRESERVE + ENABLE +DO CALL cache_clean$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/addressFriendship_Update.sql b/db/routines/cache/procedures/addressFriendship_Update.sql new file mode 100644 index 000000000..f7fab8b9b --- /dev/null +++ b/db/routines/cache/procedures/addressFriendship_Update.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`addressFriendship_Update`() +BEGIN + + REPLACE cache.addressFriendship + SELECT addressFk1, addressFk2, count(*) friendship + FROM + ( + SELECT t.routeFk, t.zoneFk, t.addressFk addressFk1, t2.addressFk addressFk2 + FROM vn.ticket t + JOIN vn.ticket t2 USING(routeFk, zoneFk) + WHERE t.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) + AND t2.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) + AND t.addressFk != t2.addressFk) sub + GROUP BY addressFk1, addressFk2; + + REPLACE cache.zoneAgencyFriendship + SELECT r.agencyModeFk, t.zoneFk, count(*) friendship + FROM vn.route r + JOIN vn.ticket t ON t.routeFk = r.id + WHERE t.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) + AND r.agencyModeFk + AND t.routeFk + AND t.zoneFk + GROUP BY agencyModeFk, zoneFk; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/availableNoRaids_refresh.sql b/db/routines/cache/procedures/availableNoRaids_refresh.sql new file mode 100644 index 000000000..383e35436 --- /dev/null +++ b/db/routines/cache/procedures/availableNoRaids_refresh.sql @@ -0,0 +1,123 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`availableNoRaids_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDated` DATE) +proc: BEGIN + DECLARE vStartDate DATE; + DECLARE vEndDate DATETIME; + DECLARE vReserveDate DATETIME; + DECLARE vParams CHAR(100); + DECLARE vInventoryDate DATE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL cache_calc_unlock (vCalc); + RESIGNAL; + END; + + IF vDated < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + SET vParams = CONCAT_WS('/', vWarehouse, vDated); + CALL vn.item_getStock (vWarehouse, vDated, NULL); + CALL cache_calc_start (vCalc, vRefresh, 'availableNoRaids', vParams); + + IF !vRefresh THEN + LEAVE proc; + END IF; + + -- Calcula algunos parametros necesarios + + SET vStartDate = TIMESTAMP(vDated, '00:00:00'); + SET vEndDate = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59'); + + SELECT inventoried INTO vInventoryDate FROM vn.config; + + SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vReserveDate + FROM hedera.orderConfig; + + -- Calcula el ultimo dia de vida para cada producto + + DROP TEMPORARY TABLE IF EXISTS tItemRange; + CREATE TEMPORARY TABLE tItemRange + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT c.itemFk, IF(it.life IS NULL, NULL, + TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) AS ended + FROM ( + SELECT b.itemFk, MAX(t.landed) landing + FROM vn.buy b + JOIN vn.entry e ON b.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk + JOIN vn.supplier s ON s.id = e.supplierFk + WHERE t.landed BETWEEN vInventoryDate AND vStartDate + AND t.warehouseInFk = vWarehouse + AND s.name != 'INVENTARIO' + AND NOT e.isRaid + GROUP BY b.itemFk + ) c + JOIN vn.item i ON i.id = c.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + HAVING ended >= vStartDate OR ended IS NULL; + + -- Calcula el ATP + + DELETE FROM availableNoRaids WHERE calc_id = vCalc; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc; + CREATE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk, warehouseFk)) + SELECT itemFk, vWarehouse warehouseFk, DATE(dated) dated, SUM(quantity) quantity + FROM ( + SELECT i.itemFk, i.shipped dated, i.quantity + FROM vn.itemTicketOut i + JOIN tItemRange ir ON ir.itemFk = i.itemFk + WHERE i.shipped >= vStartDate + AND (ir.ended IS NULL OR i.shipped <= ir.ended) + AND i.warehouseFk = vWarehouse + UNION ALL + SELECT i.itemFk, i.landed, i.quantity + FROM vn.itemEntryIn i + JOIN tItemRange ir ON ir.itemFk = i.itemFk + WHERE i.landed >= vStartDate + AND (ir.ended IS NULL OR i.landed <= ir.ended) + AND i.warehouseInFk = vWarehouse + AND i.isVirtualStock = FALSE + UNION ALL + SELECT i.itemFk, i.shipped, i.quantity + FROM vn.itemEntryOut i + JOIN tItemRange ir ON ir.itemFk = i.itemFk + WHERE i.shipped >= vStartDate + AND (ir.ended IS NULL OR i.shipped <= ir.ended) + AND i.warehouseOutFk = vWarehouse + UNION ALL + SELECT r.item_id, r.shipment, -r.amount + FROM hedera.order_row r + JOIN hedera.`order` o ON o.id = r.order_id + JOIN tItemRange ir ON ir.itemFk = r.item_id + WHERE r.shipment >= vStartDate + AND (ir.ended IS NULL OR r.shipment <= ir.ended) + AND r.warehouse_id = vWarehouse + AND r.created >= vReserveDate + AND NOT o.confirmed + ) t + GROUP BY itemFk, dated; + + CALL vn.item_getAtp(vDated); + + INSERT INTO availableNoRaids (calc_id, item_id, available) + SELECT vCalc, sub.itemFk, SUM(sub.quantity) + FROM ( + SELECT il.itemFk, stock quantity + FROM tmp.itemList il + JOIN tItemRange ir ON ir.itemFk = il.itemFk + UNION ALL + SELECT itemFk, quantity + FROM tmp.itemAtp + )sub + GROUP BY sub.itemFk; + + DROP TEMPORARY TABLE tmp.itemCalc, tItemRange; + CALL cache_calc_end (vCalc); +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/available_clean.sql b/db/routines/cache/procedures/available_clean.sql new file mode 100644 index 000000000..bb1f7302c --- /dev/null +++ b/db/routines/cache/procedures/available_clean.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_clean`() +BEGIN + DROP TEMPORARY TABLE IF EXISTS tCalc; + CREATE TEMPORARY TABLE tCalc + (INDEX (id)) + ENGINE = MEMORY + SELECT id FROM cache_calc; + + DELETE a + FROM available a + LEFT JOIN tCalc c ON c.id = a.calc_id + WHERE c.id IS NULL; + + DELETE a + FROM availableNoRaids a + LEFT JOIN tCalc c ON c.id = a.calc_id + WHERE c.id IS NULL; + + DROP TEMPORARY TABLE tCalc; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/available_refresh.sql b/db/routines/cache/procedures/available_refresh.sql new file mode 100644 index 000000000..cae0458ff --- /dev/null +++ b/db/routines/cache/procedures/available_refresh.sql @@ -0,0 +1,127 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDated` DATE) +proc: BEGIN + DECLARE vStartDate DATE; + DECLARE vReserveDate DATETIME; + DECLARE vParams CHAR(100); + DECLARE vInventoryDate DATE; + DECLARE vIsLogifloraDay BOOLEAN; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL cache_calc_unlock (vCalc); + RESIGNAL; + END; + + IF vDated < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + CALL vn.item_getStock(vWarehouse, vDated, NULL); + + SET vParams = CONCAT_WS('/', vWarehouse, vDated); + CALL cache_calc_start (vCalc, vRefresh, 'available', vParams); + + IF !vRefresh THEN + LEAVE proc; + END IF; + + -- Invoca al procedimiento que genera el stock virtual de Logiflora, si coincide con la peticion de refresco del disponible + IF vn.isLogifloraDay(vDated, vWarehouse) THEN + -- CALL edi.floramondo_offerRefresh; + SET vIsLogifloraDay = TRUE; + ELSE + SET vIsLogifloraDay = FALSE; + END IF; + + -- Calcula algunos parámetros necesarios + SET vStartDate = TIMESTAMP(vDated, '00:00:00'); + SELECT inventoried INTO vInventoryDate FROM vn.config; + SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vReserveDate + FROM hedera.orderConfig; + + -- Calcula el ultimo dia de vida para cada producto + DROP TEMPORARY TABLE IF EXISTS itemRange; + CREATE TEMPORARY TABLE itemRange + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT c.itemFk, + IF(it.life IS NULL, + NULL, + TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) ended + FROM ( + SELECT b.itemFk, MAX(t.landed) landing + FROM vn.buy b + JOIN vn.entry e ON b.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vInventoryDate AND vStartDate + AND t.warehouseInFk = vWarehouse + AND NOT e.isExcludedFromAvailable + GROUP BY b.itemFk + ) c + JOIN vn.item i ON i.id = c.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + HAVING ended >= vStartDate OR ended IS NULL; + + -- Calcula el ATP + DELETE FROM available WHERE calc_id = vCalc; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc; + CREATE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk,warehouseFk)) + ENGINE = MEMORY + SELECT itemFk, vWarehouse warehouseFk, DATE(dated) dated, SUM(quantity) quantity + FROM (SELECT i.itemFk, i.shipped dated, i.quantity + FROM vn.itemTicketOut i + JOIN itemRange ir ON ir.itemFk = i.itemFk + WHERE i.shipped >= vStartDate + AND (ir.ended IS NULL OR i.shipped <= ir.ended) + AND i.warehouseFk = vWarehouse + UNION ALL + SELECT i.itemFk, i.landed, i.quantity + FROM vn.itemEntryIn i + JOIN itemRange ir ON ir.itemFk = i.itemFk + LEFT JOIN edi.warehouseFloramondo wf ON wf.entryFk = i.entryFk + WHERE i.landed >= vStartDate + AND (ir.ended IS NULL OR i.landed <= ir.ended) + AND i.warehouseInFk = vWarehouse + AND (ISNULL(wf.entryFk) OR vIsLogifloraDay) + UNION ALL + SELECT i.itemFk, i.shipped, i.quantity + FROM vn.itemEntryOut i + JOIN itemRange ir ON ir.itemFk = i.itemFk + WHERE i.shipped >= vStartDate + AND (ir.ended IS NULL OR i.shipped <= ir.ended) + AND i.warehouseOutFk = vWarehouse + UNION ALL + SELECT r.item_id, r.shipment, -r.amount + FROM hedera.order_row r + JOIN hedera.`order` o ON o.id = r.order_id + JOIN itemRange ir ON ir.itemFk = r.item_id + WHERE r.shipment >= vStartDate + AND (ir.ended IS NULL OR r.shipment <= ir.ended) + AND r.warehouse_id = vWarehouse + AND r.created >= vReserveDate + AND NOT o.confirmed + ) t + GROUP BY itemFk, dated; + + CALL vn.item_getAtp(vDated); + + INSERT INTO available (calc_id, item_id, available) + SELECT vCalc, sub.itemFk, SUM(sub.quantity) + FROM ( + SELECT ir.itemFk, stock quantity + FROM tmp.itemList il + JOIN itemRange ir ON ir.itemFk = il.itemFk + UNION ALL + SELECT itemFk, quantity + FROM tmp.itemAtp + )sub + GROUP BY sub.itemFk; + + DROP TEMPORARY TABLE tmp.itemCalc, itemRange; + CALL cache_calc_end (vCalc); +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/cacheCalc_clean.sql b/db/routines/cache/procedures/cacheCalc_clean.sql new file mode 100644 index 000000000..5c588687e --- /dev/null +++ b/db/routines/cache/procedures/cacheCalc_clean.sql @@ -0,0 +1,7 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`cacheCalc_clean`() +BEGIN + DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, NOW()); + DELETE FROM cache_calc WHERE expires < vCleanTime; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/cache_calc_end.sql b/db/routines/cache/procedures/cache_calc_end.sql new file mode 100644 index 000000000..b3a25532b --- /dev/null +++ b/db/routines/cache/procedures/cache_calc_end.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`cache_calc_end`(IN `v_calc` INT) +BEGIN + DECLARE v_cache_name VARCHAR(255); + DECLARE v_params VARCHAR(255); + + -- Libera el bloqueo y actualiza la fecha de ultimo refresco. + + UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id + SET + cc.last_refresh = NOW(), + cc.expires = ADDTIME(NOW(), c.lifetime), + cc.connection_id = NULL + WHERE cc.id = v_calc; + + SELECT c.name, ca.params INTO v_cache_name, v_params + FROM cache c + JOIN cache_calc ca ON c.id = ca.cache_id + WHERE ca.id = v_calc; + + IF v_cache_name IS NOT NULL THEN + DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/cache_calc_start.sql b/db/routines/cache/procedures/cache_calc_start.sql new file mode 100644 index 000000000..701bb1a68 --- /dev/null +++ b/db/routines/cache/procedures/cache_calc_start.sql @@ -0,0 +1,87 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`cache_calc_start`(OUT `v_calc` INT, INOUT `v_refresh` INT, IN `v_cache_name` VARCHAR(50), IN `v_params` VARCHAR(100)) +proc: BEGIN + DECLARE v_valid BOOL; + DECLARE v_lock_id VARCHAR(100); + DECLARE v_cache_id INT; + DECLARE v_expires DATETIME; + DECLARE v_clean_time DATETIME; + DECLARE vLastRefresh DATETIME; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + IF v_lock_id IS NOT NULL THEN + DO RELEASE_LOCK(v_lock_id); + END IF; + + RESIGNAL; + END; + + SET v_params = IFNULL(v_params, ''); + + -- Si el servidor se ha reiniciado invalida todos los calculos. + + SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; + + IF !v_valid + THEN + DELETE FROM cache_calc; + INSERT INTO cache_valid (valid) VALUES (TRUE); + END IF; + + -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. + + SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); + + IF !GET_LOCK(v_lock_id, 30) + THEN + SET v_calc = NULL; + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Comprueba si el calculo solicitado existe y esta actualizado. + + SELECT c.id, ca.id, ca.expires, ca.last_refresh + INTO v_cache_id, v_calc, v_expires, vLastRefresh + FROM cache c + LEFT JOIN cache_calc ca + ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' + WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; + + -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. + + IF !v_refresh AND NOW() < v_expires AND vLastRefresh >= CURDATE() + THEN + DO RELEASE_LOCK(v_lock_id); + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Si el calculo no existe le crea una entrada en la tabla de calculos. + + IF v_calc IS NULL + THEN + INSERT INTO cache_calc SET + cache_id = v_cache_id, + cacheName = v_cache_name, + params = v_params, + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID(); + + SET v_calc = LAST_INSERT_ID(); + ELSE + UPDATE cache_calc + SET + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID() + WHERE id = v_calc; + END IF; + + -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. + + SET v_refresh = TRUE; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/cache_calc_unlock.sql b/db/routines/cache/procedures/cache_calc_unlock.sql new file mode 100644 index 000000000..5dc46d925 --- /dev/null +++ b/db/routines/cache/procedures/cache_calc_unlock.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`cache_calc_unlock`(IN `v_calc` INT) +proc: BEGIN + DECLARE v_cache_name VARCHAR(50); + DECLARE v_params VARCHAR(100); + + IF v_calc IS NULL THEN + LEAVE proc; + END IF; + + SELECT c.name, ca.params INTO v_cache_name, v_params + FROM cache c + JOIN cache_calc ca ON c.id = ca.cache_id + WHERE ca.id = v_calc; + + DELETE FROM cache_calc WHERE id = v_calc; + + IF v_cache_name IS NOT NULL THEN + DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/cache_clean.sql b/db/routines/cache/procedures/cache_clean.sql new file mode 100644 index 000000000..0fca75e63 --- /dev/null +++ b/db/routines/cache/procedures/cache_clean.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`cache_clean`() + NO SQL +BEGIN + CALL available_clean; + CALL visible_clean; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/clean.sql b/db/routines/cache/procedures/clean.sql new file mode 100644 index 000000000..95841a713 --- /dev/null +++ b/db/routines/cache/procedures/clean.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`clean`() +BEGIN + DECLARE vDateShort DATETIME; + + SET vDateShort = TIMESTAMPADD(MONTH, -1, util.VN_CURDATE()); + + DELETE FROM cache.departure_limit WHERE Fecha < vDateShort; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/departure_timing.sql b/db/routines/cache/procedures/departure_timing.sql new file mode 100644 index 000000000..778c2cd74 --- /dev/null +++ b/db/routines/cache/procedures/departure_timing.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`departure_timing`(vWarehouseId INT) +BEGIN + +DECLARE done BOOL DEFAULT FALSE; +DECLARE rsDeparture INT; +DECLARE rsHoras DECIMAL(5,2); +DECLARE rsInicio DECIMAL(5,2); +DECLARE resto DECIMAL(5,2); +DECLARE horasProd DECIMAL(5,2); +DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00; +DECLARE myTime DECIMAL(5,2); +DECLARE departureLimit INT; +DECLARE myMinSpeed DECIMAL(10,2); +DECLARE vLoadingDelay DECIMAL(5) DEFAULT 2; + +DECLARE rs CURSOR FOR + SELECT Departure + , Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(dp.minSpeed,0))) AS Horas + , util.VN_CURDATE()+(Departure + vLoadingDelay -(Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(minSpeed,0))))/24) AS InicioPreparacion + FROM tmp.production_buffer pb + LEFT JOIN vn.lastHourProduction lhp ON lhp.warehouseFk = pb.warehouse_id + LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = util.VN_CURDATE() + WHERE pb.Fecha = util.VN_CURDATE() + AND pb.graphCategory > 1 + AND IFNULL(Departure,0) > 0 + GROUP BY Departure + ORDER BY Departure DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; + + OPEN rs; + + FETCH rs INTO rsDeparture, rsHoras , rsInicio; + + WHILE NOT done DO + + SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0); + + SET inicioProd = rsDeparture - rsHoras; + + IF inicioProd - resto < myTime THEN + + SET done = TRUE; + + ELSE + + SET departureLimit = rsDeparture; + + FETCH rs INTO rsDeparture, rsHoras , rsInicio; + + -- SELECT rsDeparture, rsHoras , rsInicio; + + END IF; + + END WHILE; + + SET departureLimit = IFNULL(departureLimit,24); + SET departureLimit = IF(departureLimit = 0, 24, departureLimit); + + SELECT minSpeed INTO myMinSpeed + FROM cache.departure_limit + WHERE warehouse_id = vWarehouseId + AND fecha = util.VN_CURDATE(); + + REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed) + VALUES (vWarehouseId, util.VN_CURDATE(), departureLimit, IFNULL(myMinSpeed,0)); + + CLOSE rs; + +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/last_buy_refresh.sql b/db/routines/cache/procedures/last_buy_refresh.sql new file mode 100644 index 000000000..49ef4ee5e --- /dev/null +++ b/db/routines/cache/procedures/last_buy_refresh.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`last_buy_refresh`(vRefresh BOOL) +proc: BEGIN +/** + * Crea o actualiza la cache con la última compra y fecha de cada + * artículo hasta ayer. Para obtener la última compra hasta una fecha + * determinada utilizar el procedimiento vn.buyUltimate(). + * + * @param vRefresh %TRUE para forzar el recálculo de la cache + */ + DECLARE vCalc INT; + DECLARE started DATE; + DECLARE ended DATE; + DECLARE vLastRefresh DATE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL cache_calc_unlock (vCalc); + RESIGNAL; + END; + + CALL cache_calc_start (vCalc, vRefresh, 'last_buy', NULL); + + IF !vRefresh + THEN + LEAVE proc; + END IF; + + -- TODO: ¿Se puede usar la fecha del ultimo inventario? + SELECT inventoried INTO started FROM vn.config LIMIT 1; + SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE()); + + CALL vn.buyUltimateFromInterval(NULL, started, ended); + + DELETE FROM last_buy; + + INSERT INTO last_buy (item_id, warehouse_id, buy_id, landing) + SELECT itemFk, warehouseFk, buyFk, landed + FROM tmp.buyUltimateFromInterval; + + DROP TEMPORARY TABLE tmp.buyUltimateFromInterval; + + CALL cache_calc_end (vCalc); +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/prod_graphic_refresh.sql b/db/routines/cache/procedures/prod_graphic_refresh.sql new file mode 100644 index 000000000..edeeba436 --- /dev/null +++ b/db/routines/cache/procedures/prod_graphic_refresh.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`prod_graphic_refresh`(v_refresh BOOL, wh_id INT) +proc: BEGIN + DECLARE datEQ DATETIME; + DECLARE timDIF TIME; + DECLARE v_calc INT; + + CALL cache_calc_start (v_calc, v_refresh, 'prod_graphic', wh_id); + + IF !v_refresh + THEN + LEAVE proc; + END IF; + + CALL vn2008.production_control_source(wh_id, 0); + + DELETE FROM prod_graphic_source; + + INSERT INTO prod_graphic_source (warehouse_id, graphCategory, m3, hora, `order`, Agencia) + SELECT + wh_id, + st.graphCategory, + CAST(SUM(m3) AS DECIMAL(10,0)) as m3, + pb.Hora, + pb.state_order, + pb.Agencia + FROM tmp.production_buffer pb + JOIN vn.state st ON st.id = pb.state + WHERE Fecha = util.VN_CURDATE() + GROUP BY wh_id, graphCategory + ; + + + CALL cache_calc_end (v_calc); +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/stock_refresh.sql b/db/routines/cache/procedures/stock_refresh.sql new file mode 100644 index 000000000..5ddc6c20e --- /dev/null +++ b/db/routines/cache/procedures/stock_refresh.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`stock_refresh`(v_refresh BOOL) +proc: BEGIN +/** + * Crea o actualiza la cache con el disponible hasta el dí­a de + * ayer. Esta cache es usada como base para otros procedimientos + * como el cálculo del visible o del ATP. + * + * @param v_refresh %TRUE para forzar el recálculo de la cache + **/ + DECLARE v_calc INT; + DECLARE v_date_inv DATE; + DECLARE vCURDATE DATE; + DECLARE v_last_refresh DATETIME; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL cache_calc_unlock (v_calc); + RESIGNAL; + END; + + CALL cache_calc_start (v_calc, v_refresh, 'stock', NULL); + + IF !v_refresh + THEN + LEAVE proc; + END IF; + + SET v_date_inv = vn.getInventoryDate(); + SET vCURDATE = util.VN_CURDATE(); + + DELETE FROM stock; + + INSERT INTO stock (item_id, warehouse_id, amount) + SELECT item_id, warehouse_id, SUM(amount) amount FROM + ( + SELECT itemFk AS item_id, warehouseFk AS warehouse_id, quantity AS amount + FROM vn.itemTicketOut + WHERE shipped >= v_date_inv AND shipped < vCURDATE + UNION ALL + SELECT itemFk ASitem_id, warehouseInFk AS warehouse_id, quantity AS amount + FROM vn.itemEntryIn + WHERE landed >= v_date_inv AND landed < vCURDATE AND isVirtualStock is FALSE + UNION ALL + SELECT itemFk AS item_id ,warehouseOutFk AS warehouse_id, quantity AS amount + FROM vn.itemEntryOut + WHERE shipped >= v_date_inv AND shipped < vCURDATE + ) t + GROUP BY item_id, warehouse_id HAVING amount != 0; + + CALL cache_calc_end (v_calc); +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/visible_clean.sql b/db/routines/cache/procedures/visible_clean.sql new file mode 100644 index 000000000..b6f03c563 --- /dev/null +++ b/db/routines/cache/procedures/visible_clean.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_clean`() +BEGIN + DROP TEMPORARY TABLE IF EXISTS tCalc; + CREATE TEMPORARY TABLE tCalc + (INDEX (id)) + ENGINE = MEMORY + SELECT id FROM cache_calc; + + DELETE v + FROM visible v + LEFT JOIN tCalc c ON c.id = v.calc_id + WHERE c.id IS NULL; + + DROP TEMPORARY TABLE tCalc; +END$$ +DELIMITER ; diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql new file mode 100644 index 000000000..63b42dfd9 --- /dev/null +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) +proc: BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL cache_calc_unlock (v_calc); + RESIGNAL; + END; + + CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); + + IF !v_refresh THEN + LEAVE proc; + END IF; + + -- Calculamos el stock hasta ayer + + CALL `cache`.stock_refresh(false); + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT item_id, amount stock, amount visible FROM `cache`.stock + WHERE warehouse_id = v_warehouse; + + -- Calculamos los movimientos confirmados de hoy + CALL vn.item_GetVisible(v_warehouse, NULL); + DELETE FROM visible WHERE calc_id = v_calc; + + INSERT INTO visible (calc_id, item_id,visible) + SELECT v_calc, item_id, visible FROM tmp.itemVisible; + + CALL cache_calc_end (v_calc); + + DROP TEMPORARY TABLE tmp.itemVisible; +END$$ +DELIMITER ; diff --git a/db/routines/dipole/procedures/clean.sql b/db/routines/dipole/procedures/clean.sql new file mode 100644 index 000000000..a9af64e15 --- /dev/null +++ b/db/routines/dipole/procedures/clean.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `dipole`.`clean`() +BEGIN + DECLARE vFromDated DATE; + + SET vFromDated = TIMESTAMPADD(WEEK, -2, util.VN_CURDATE()); + + DELETE FROM dipole.expedition_PrintOut + WHERE created < vFromDated; + + DELETE FROM dipole.expedition_Read + WHERE created < vFromDated; +END$$ +DELIMITER ; diff --git a/db/routines/dipole/procedures/expedition_add.sql b/db/routines/dipole/procedures/expedition_add.sql new file mode 100644 index 000000000..a88c4d25a --- /dev/null +++ b/db/routines/dipole/procedures/expedition_add.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `dipole`.`expedition_add`(vExpeditionFk INT, vPrinterFk INT, vIsPrinted BOOLEAN) +BEGIN +/** Insert records to print agency stickers and to inform sorter with new box + * + * param vExpeditionFk Id for vn.expedition + * param vPrinterFk Id for dipole.printer + * param vIsPrinted Value for field dipole.expedition_PrintOut.isPrinted + */ + INSERT INTO dipole.expedition_PrintOut(expeditionFk, + ticketFk, + addressFk, + street, + postalCode, + city, + shopName, + printerFk, + routeFk, + parkingCode, + truckName, + clientFk, + phone, + province, + agency, + workerCode, + isPrinted) + SELECT e.id, + e.ticketFk, + t.addressFk , + LEFT(a.street, 100), + a.postalCode , + LEFT (CONCAT(IFNULL(rm.beachFk,''),' ',a.city), 13), + a.nickname, + vPrinterFk, + IFNULL(right(`t`.`routeFk`, 3),0), + if (@vVolume := vn.ticketTotalVolume(t.id) > 1.5, @vVolume, IFNULL( rm.beachFk, 0)), + LEFT(IFNULL(et.description ,replace(`z`.`name`, 'ZONA ', 'Z')),14) truckName, + t.clientFk , + ifnull(c.mobile, ifnull(a.mobile, ifnull(c.phone, a.phone))), + LEFT(p.name, 20), + NULL, + w.code, + vIsPrinted + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + LEFT JOIN vn.beach b ON b.code = rm.beachFk + LEFT JOIN vn.`zone`z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON t.agencyModeFk = am.id + JOIN vn.client c ON t.clientFk = c.id + JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN vn.printer pr ON pr.id = vPrinterFk + JOIN vn.worker w ON w.id = e.workerFk + WHERE e.id = vExpeditionFk; + + INSERT INTO srt.expedition (id, + width, + `length`, + height, + stateFk) + SELECT e.id, + p.width * 10, + p.`depth` * 10, + p.height * 10, + es.id + FROM vn.expedition e + LEFT JOIN vn.packaging p ON p.id = e.packagingFk + JOIN srt.expeditionState es ON es.description = 'PRINTED' + WHERE e.id = vExpeditionFk; -- En esa tabla las medidas van en milímetros +END$$ +DELIMITER ; diff --git a/db/routines/dipole/views/expeditionControl.sql b/db/routines/dipole/views/expeditionControl.sql new file mode 100644 index 000000000..e26e83440 --- /dev/null +++ b/db/routines/dipole/views/expeditionControl.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `dipole`.`expeditionControl` +AS SELECT cast(`epo`.`created` AS date) AS `fecha`, + COUNT(0) AS `total`, + COUNT(`er`.`expeditionFk`) AS `leidas` +FROM ( + `dipole`.`expedition_PrintOut` `epo` + LEFT JOIN `dipole`.`expedition_Read` `er` ON(`er`.`expeditionFk` = `epo`.`expeditionFk`) + ) +GROUP BY cast(`epo`.`created` AS date) diff --git a/db/routines/edi/events/floramondo.sql b/db/routines/edi/events/floramondo.sql new file mode 100644 index 000000000..0a38f3537 --- /dev/null +++ b/db/routines/edi/events/floramondo.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `edi`.`floramondo` + ON SCHEDULE EVERY 6 MINUTE + STARTS '2022-01-28 09:52:45.000' + ON COMPLETION NOT PRESERVE + DISABLE +DO CALL edi.floramondo_offerRefresh()$$ +DELIMITER ; diff --git a/db/routines/edi/functions/imageName.sql b/db/routines/edi/functions/imageName.sql new file mode 100644 index 000000000..f2e52558f --- /dev/null +++ b/db/routines/edi/functions/imageName.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `edi`.`imageName`(vPictureReference VARCHAR(255)) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + + SET vPictureReference = REPLACE(vPictureReference,'.',''); + + SET vPictureReference = REPLACE(vPictureReference,'/',''); + + SET vPictureReference = REPLACE(vPictureReference,'%',''); + + SET vPictureReference = REPLACE(vPictureReference,':',''); + + SET vPictureReference = REPLACE(vPictureReference,'?',''); + + SET vPictureReference = REPLACE(vPictureReference,'=',''); + + RETURN vPictureReference; + +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/clean.sql b/db/routines/edi/procedures/clean.sql new file mode 100644 index 000000000..71dd576e9 --- /dev/null +++ b/db/routines/edi/procedures/clean.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`clean`() +BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + DELETE FROM ekt + WHERE fec < (util.VN_CURDATE() - INTERVAL 4 YEAR); + + DELETE IGNORE sr.* + FROM supplyResponse sr + LEFT JOIN deliveryInformation di ON sr.ID = di.supplyResponseID + WHERE di.LatestOrderDateTime < (util.VN_CURDATE() - INTERVAL 1 WEEK) + OR di.ID IS NULL; + + DELETE FROM putOrder + WHERE created < (util.VN_CURDATE() - INTERVAL 1 MONTH); +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/deliveryInformation_Delete.sql b/db/routines/edi/procedures/deliveryInformation_Delete.sql new file mode 100644 index 000000000..b4f51515a --- /dev/null +++ b/db/routines/edi/procedures/deliveryInformation_Delete.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`deliveryInformation_Delete`() +BEGIN + + DECLARE vID INT; + DECLARE vGap INT DEFAULT 100; + DECLARE vTope INT; + + SELECT MIN(ID), MAX(ID) + INTO vID, vTope + FROM edi.deliveryInformation; + + WHILE vID <= vTope DO + + SET vID = vID + vGap; + + DELETE + FROM edi.deliveryInformation + WHERE ID < vID + AND EarliestDespatchDateTime IS NULL; + + END WHILE; + + +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/ekt_add.sql b/db/routines/edi/procedures/ekt_add.sql new file mode 100644 index 000000000..1cc67bb93 --- /dev/null +++ b/db/routines/edi/procedures/ekt_add.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_add`(vPutOrderFk INT) +BEGIN + +/** + * Añade ekt para las ordenes de compra de proveedores que no envian el ekt por email + * + * @param vPutOrderFk PutOrderId de donde coger los datos + **/ + + INSERT INTO edi.ekt(entryYear, + deliveryNumber, + fec, + hor, + item, + pac, + qty, + ori, + cat, + pro, + pri, + package, + s1, + s2, + s3, + s4, + s5, + s6, + putOrderFk, + `ref`, + kop) + SELECT year(util.VN_CURDATE()) entryYear, + p.id deliveryNumber , + DATE(di.LatestDeliveryDateTime) fec, + HOUR(di.LatestDeliveryDateTime) hor, + i.longName item, + sr.NumberOfItemsPerCask pac, + p.quantity qty, + o.code ori, + i.category cat, + mp.supplierFk pro, + sr.Price pri, + sr.EmbalageCode package, + i.value5 s1, + i.value6 s2, + i.value7 s3, + i.value8 s4, + i.value9 s5, + i.value10 s6, + p.id putOrderFk, + sr.Item_ArticleCode, + sr.vmpID + FROM edi.putOrder p + JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID + JOIN edi.deliveryInformation di ON di.id = p.deliveryInformationID + JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + JOIN vn.item i ON i.supplyResponseFk = sr.ID + JOIN vn.origin o ON o.id = i.originFk + WHERE p.id = vPutOrderFk; + + CALL edi.ekt_load(LAST_INSERT_ID()); + +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/ekt_load.sql b/db/routines/edi/procedures/ekt_load.sql new file mode 100644 index 000000000..d07f45ba8 --- /dev/null +++ b/db/routines/edi/procedures/ekt_load.sql @@ -0,0 +1,277 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_load`(IN `vSelf` INT) +proc:BEGIN + + DECLARE vRef INT; + DECLARE vBuy INT; + DECLARE vItem INT; + DECLARE vQty INT; + DECLARE vPackage INT; + DECLARE vPutOrderFk INT; + DECLARE vIsLot BOOLEAN; + DECLARE vForceToPacking INT DEFAULT 2; + DECLARE vEntryFk INT; + DECLARE vHasToChangePackagingFk BOOLEAN; + DECLARE vIsFloramondoDirect BOOLEAN; + DECLARE vTicketFk INT; + DECLARE vHasItemGroup BOOL; + DECLARE vDescription VARCHAR(255); + DECLARE vSaleFk INT; + + -- Carga los datos necesarios del EKT + + SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), + CONCAT(e.`ref`, ' ', e.item, ' ', e.sub, ' EktFk:', e.id) + INTO vRef, vQty, vPackage, vPutOrderFk, vItem, vIsFloramondoDirect, vHasItemGroup, vDescription + FROM edi.ekt e + LEFT JOIN edi.item i ON e.ref = i.id + LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk + LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID + LEFT JOIN vn.ektEntryAssign eea ON eea.sub = e.sub + LEFT JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id + WHERE e.id = vSelf + LIMIT 1; + + IF NOT vHasItemGroup THEN + + CALL vn.mail_insert('logistica@verdnatura.es', 'nocontestar@verdnatura.es', 'Nuevo grupo en Floramondo', vDescription); + + CALL vn.mail_insert('pako@verdnatura.es', 'nocontestar@verdnatura.es', CONCAT('Nuevo grupo en Floramondo: ', vDescription), vDescription); + + LEAVE proc; + + END IF; + + -- Asigna la entrada + SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; + + -- Inserta el cubo si no existe + + IF vPackage = 800 THEN + + SET vHasToChangePackagingFk = TRUE; + + IF vItem THEN + + SELECT vn.item_getPackage(vItem) INTO vPackage ; + + ELSE + + SET vPackage = 8000 + vQty; + + INSERT IGNORE INTO vn.packaging(id, width, `depth`) + SELECT vPackage, vc.ccLength / vQty, vc.ccWidth + FROM vn.volumeConfig vc; + + END IF; + + ELSE + + INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z) + SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10) + FROM bucket WHERE bucket_id = vPackage; + + IF ROW_COUNT() > 0 + THEN + INSERT INTO vn2008.mail SET + `subject` = 'Cubo añadido', + `text` = CONCAT('Se ha añadido el cubo: ', vPackage), + `to` = 'ekt@verdnatura.es'; + END IF; + END IF; + + -- Si es una compra de Logiflora obtiene el articulo + IF vPutOrderFk THEN + + SELECT i.id INTO vItem + FROM edi.putOrder po + JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID + WHERE po.id = vPutOrderFk + LIMIT 1; + + END IF; + + INSERT IGNORE INTO item_track SET + item_id = vRef; + + IF IFNULL(vItem,0) = 0 THEN + + -- Intenta obtener el artículo en base a los atributos holandeses + + SELECT b.id, IFNULL(b.itemOriginalFk ,b.itemFk) INTO vBuy, vItem + FROM edi.ekt e + JOIN edi.item_track t ON t.item_id = e.ref + LEFT JOIN edi.ekt l ON l.ref = e.ref + LEFT JOIN vn.buy b ON b.ektFk = l.id + LEFT JOIN vn.item i ON i.id = b.itemFk + JOIN vn2008.config cfg + WHERE e.id = vSelf + AND l.id != vSelf + AND b.itemFk != cfg.generic_item + AND IF(t.s1, l.s1 = e.s1, TRUE) + AND IF(t.s2, l.s2 = e.s2, TRUE) + AND IF(t.s3, l.s3 = e.s3, TRUE) + AND IF(t.s4, l.s4 = e.s4, TRUE) + AND IF(t.s5, l.s5 = e.s5, TRUE) + AND IF(t.s6, l.s6 = e.s6, TRUE) + AND IF(t.pac, l.pac = e.pac, TRUE) + AND IF(t.cat, l.cat = e.cat, TRUE) + AND IF(t.ori, l.ori = e.ori, TRUE) + AND IF(t.pro, l.pro = e.pro, TRUE) + AND IF(t.package, l.package = e.package, TRUE) + AND IF(t.item, l.item = e.item, TRUE) + AND i.isFloramondo = vIsFloramondoDirect + ORDER BY l.now DESC, b.id ASC + LIMIT 1; + + END IF; + + -- Si no encuentra el articulo lo crea en el caso de las compras directas en Floramondo + IF ISNULL(vItem) AND vIsFloramondoDirect THEN + + CALL edi.item_getNewByEkt(vSelf, vItem); + + END IF; + + INSERT INTO vn.buy + ( + entryFk + ,ektFk + ,buyingValue + ,itemFk + ,stickers + ,packing + ,`grouping` + ,quantity + ,groupingMode + ,packagingFk + ,weight + ) + SELECT + vEntryFk + ,vSelf + ,(@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue + ,IFNULL(vItem, cfg.generic_item) itemFk + ,e.qty stickers + ,@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing + ,IFNULL(b.`grouping`, e.pac) + ,@pac * e.qty + ,vForceToPacking + ,IF(vHasToChangePackagingFk OR ISNULL(b.packagingFk), vPackage, b.packagingFk) + ,(IFNULL(i.weightByPiece,0) * @pac)/1000 + FROM edi.ekt e + LEFT JOIN vn.buy b ON b.id = vBuy + LEFT JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.supplier s ON e.pro = s.id + JOIN vn2008.config cfg + WHERE e.id = vSelf + LIMIT 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; + + CREATE TEMPORARY TABLE tmp.buyRecalc + SELECT buy.id + FROM vn.buy + WHERE ektFk = vSelf; + + CALL vn.buy_recalcPrices(); + + -- Si es una compra de Logiflora hay que informar la tabla vn.saleBuy + IF vPutOrderFk THEN + + REPLACE vn.saleBuy(saleFk, buyFk, workerFk) + SELECT po.saleFk, b.id, account.myUser_getId() + FROM edi.putOrder po + JOIN vn.buy b ON b.ektFk = vSelf + WHERE po.id = vPutOrderFk; + + END IF; + -- Si es una compra directa en Floramondo hay que añadirlo al ticket + + IF vIsFloramondoDirect THEN + + SELECT t.id INTO vTicketFk + FROM vn.ticket t + JOIN vn.ektEntryAssign eea + ON eea.addressFk = t.addressFk + AND t.warehouseFk = eea.warehouseInFk + JOIN edi.ekt e + ON e.sub = eea.sub + AND e.id = vSelf + WHERE e.fec = t.shipped + LIMIT 1; + + IF ISNULL(vTicketFk) THEN + + INSERT INTO vn.ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus + ) + SELECT + a.clientFk, + e.fec, + a.id, + a.agencyModeFk, + a.nickname, + eea.warehouseInFk, + c.id, + e.fec, + z.id, + z.price, + z.bonus + FROM edi.ekt e + JOIN vn.ektEntryAssign eea ON eea.sub = e.sub + JOIN vn.address a ON a.id = eea.addressFk + JOIN vn.company c ON c.code = 'VNL' + JOIN vn.`zone` z ON z.code = 'FLORAMONDO' + WHERE e.id = vSelf + LIMIT 1; + + SET vTicketFk = LAST_INSERT_ID(); + + INSERT INTO vn.ticketLog + SET originFk = vTicketFk, + userFk = account.myUser_getId(), + `action` = 'insert', + description = CONCAT('EktLoad ha creado el ticket:', ' ', vTicketFk); + + END IF; + + INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, price) + SELECT vItem, vTicketFk, e.item, e.qty * e.pac, e.pri * ( 1 + fhc.floramondoMargin ) + FROM edi.ekt e + JOIN edi.floraHollandConfig fhc + WHERE e.id = vSelf; + + SELECT LAST_INSERT_ID() INTO vSaleFk; + + REPLACE vn.saleBuy(saleFk, buyFk, workerFk) + SELECT vSaleFk, b.id, account.myUser_getId() + FROM vn.buy b + WHERE b.ektFk = vSelf; + + INSERT INTO vn.saleComponent(saleFk, componentFk, value) + SELECT vSaleFk, c.id, e.pri + FROM edi.ekt e + JOIN vn.component c ON c.code = 'purchaseValue' + WHERE e.id = vSelf; + + INSERT INTO vn.saleComponent(saleFk, componentFk, value) + SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin + FROM edi.ekt e + JOIN edi.floraHollandConfig fhc + JOIN vn.component c ON c.code = 'margin' + WHERE e.id = vSelf; + END IF; + DROP TEMPORARY TABLE tmp.buyRecalc; +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/ekt_loadNotBuy.sql b/db/routines/edi/procedures/ekt_loadNotBuy.sql new file mode 100644 index 000000000..52697adc0 --- /dev/null +++ b/db/routines/edi/procedures/ekt_loadNotBuy.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_loadNotBuy`() +BEGIN +/** + * Ejecuta ekt_load para aquellos ekt de hoy que no tienen vn.buy + */ + DECLARE vEktFk INTEGER; + DECLARE done BOOL; + + DECLARE cursor1 CURSOR FOR + SELECT e.id + FROM edi.ekt e + LEFT JOIN vn.buy b ON b.ektFk = e.id + WHERE e.fec >= util.VN_CURDATE() + AND ISNULL(b.ektFk); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + OPEN cursor1; + bucle: LOOP + + FETCH cursor1 INTO vEktFk; + + IF done THEN + LEAVE bucle; + END IF; + + CALL edi.ekt_load(vEktFk); + + END LOOP bucle; + CLOSE cursor1; +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/ekt_refresh.sql b/db/routines/edi/procedures/ekt_refresh.sql new file mode 100644 index 000000000..0e9ed7d3c --- /dev/null +++ b/db/routines/edi/procedures/ekt_refresh.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_refresh`( + `vSelf` INT, vMailFk INT) +BEGIN +/** + * Updates a transaction, generates it's barcode. + */ + DECLARE vRewriteKop INT DEFAULT NULL; + DECLARE vTruncatePutOrder INT DEFAULT NULL; + DECLARE vBarcode CHAR(15) DEFAULT NULL; + DECLARE vKop INT; + DECLARE vPutOrderFk BIGINT; + + SELECT kop, putOrderFk + INTO vKop, vPutOrderFk + FROM ekt + WHERE id = vSelf; + + -- Generates the barcode + + SELECT CONCAT( + LPAD(IFNULL(auction,0), 3, 0), + LPAD(IFNULL(klo, 99), 2, 0), + LPAD(DAYOFYEAR(fec), 3, 0), + COALESCE(agj, RIGHT(batchNumber,7), id)) + INTO vBarcode + FROM ekt + WHERE id = vSelf; + + -- Rewrites the kop parameter + + IF vKop IS NULL THEN + SELECT defaultKop INTO vKop FROM exchangeConfig; + END IF; + + SELECT e.kop INTO vRewriteKop + FROM mailSender e + JOIN mail m ON m.senderFk = e.id + WHERE m.id = vMailFk; + + SET vKop = IFNULL(vRewriteKop, vKop); + + -- Format order id + + SET vTruncatePutOrder = vPutOrderFk MOD 1000000; + + -- Refresh EKT + + UPDATE ekt SET + barcode = vBarcode + ,kop = vKop + ,putOrderFk = vTruncatePutOrder + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/ekt_scan.sql b/db/routines/edi/procedures/ekt_scan.sql new file mode 100644 index 000000000..456e329e0 --- /dev/null +++ b/db/routines/edi/procedures/ekt_scan.sql @@ -0,0 +1,131 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_scan`(vBarcode VARCHAR(512)) +BEGIN +/** + * Busca transaciones a partir de un código de barras, las marca como escaneadas + * y las devuelve. + * Ver https://wiki.verdnatura.es/index.php/Ekt#Algoritmos_de_lectura + * + * @param vBarcode Código de compra de una etiqueta de subasta + * @param vLabels Cantidad escaneada + * @table tmp.ekt(ektFk) Transacciones escaneadas + */ + DECLARE vIsFound BOOL; + DECLARE vUsefulAuctionLeftSegmentLength INT; + DECLARE vStandardBarcodeLength INT; + DECLARE vFloridayBarcodeLength INT; + DECLARE vFloramondoBarcodeLength INT; + DECLARE vAuction INT; + DECLARE vKlo INT; + DECLARE vFec DATE; + DECLARE vShortAgj INT; + DECLARE vLongAgj INT; + DECLARE vXtraLongAgj INT; + DECLARE vDefaultKlo INT; + + SELECT + ec.usefulAuctionLeftSegmentLength, + ec.standardBarcodeLength, + ec.floridayBarcodeLength, + ec.floramondoBarcodeLength, + ec.defaultKlo + INTO + vUsefulAuctionLeftSegmentLength, + vStandardBarcodeLength, + vFloridayBarcodeLength, + vFloramondoBarcodeLength, + vDefaultKlo + FROM edi.ektConfig ec; + + DROP TEMPORARY TABLE IF EXISTS tmp.ekt; + CREATE TEMPORARY TABLE tmp.ekt + ENGINE = MEMORY + SELECT id ektFk FROM ekt LIMIT 0; + + CASE + WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN + INSERT INTO tmp.ekt + SELECT id + FROM edi.ektRecent e + WHERE e.cps = vBarcode + OR e.batchNumber = vBarcode; + + WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN + INSERT INTO tmp.ekt + SELECT e.id + FROM edi.ektRecent e + WHERE e.pro = MID(vBarcode,2,6) + AND CAST(e.ptd AS SIGNED) = MID(vBarcode,8,5); + + ELSE + SET vBarcode = LPAD(vBarcode,vStandardBarcodeLength,'0'); + SET vAuction = MID(vBarcode, 1, 3); + SET vKlo = MID(vBarcode, 4, 2); + SET vFec = MAKEDATE(YEAR(util.VN_CURDATE()), MID(vBarcode, 6, 3)); + SET vShortAgj = MID(vBarcode, 9, 5); + SET vLongAgj = MID(vBarcode, 9, 7); + SET vXtraLongAgj = MID(vBarcode, 9, 8); + + -- Clásico de subasta + -- Trade standard + -- Trade que construye como la subasta + -- Trade como el anterior pero sin trade code + INSERT INTO tmp.ekt + SELECT id + FROM ekt + WHERE fec = vFec + AND (( + vKlo = vDefaultKlo + AND (klo = vKlo OR klo IS NULL OR klo = 0) + AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj)) + OR (klo = vKlo + AND auction = vAuction + AND agj = vShortAgj) + ) + ORDER BY agj DESC + LIMIT 1; + + SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; + + -- BatchNumber largo + IF NOT vIsFound THEN + INSERT INTO tmp.ekt + SELECT id + FROM edi.ektRecent e + WHERE e.batchNumber + = LEFT(vBarcode,vUsefulAuctionLeftSegmentLength) + AND e.batchNumber > 0; + + SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; + END IF; + + -- Order Number + IF NOT vIsFound THEN + INSERT INTO tmp.ekt + SELECT id + FROM edi.ektRecent e + WHERE e.putOrderFk = vBarcode; + + SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; + END IF; + + -- deliveryNumber incrustado + IF NOT vIsFound THEN + INSERT INTO tmp.ekt + SELECT id + FROM edi.ektRecent e + WHERE e.deliveryNumber + = MID(vBarcode, 4, 13) + AND e.deliveryNumber > 0; + + SELECT COUNT(*) FROM tmp.ekt INTO vIsFound; + END IF; + END CASE; + + IF vIsFound THEN + UPDATE ekt e + JOIN tmp.ekt t ON t.ektFk = e.id + SET e.scanned = TRUE; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql new file mode 100644 index 000000000..26e09ebaf --- /dev/null +++ b/db/routines/edi/procedures/floramondo_offerRefresh.sql @@ -0,0 +1,522 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() +proc: BEGIN + DECLARE vLanded DATETIME; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vFreeId INT; + DECLARE vSupplyResponseFk INT; + DECLARE vLastInserted DATETIME; + DECLARE vIsAuctionDay BOOLEAN; + DECLARE vMaxNewItems INT DEFAULT 10000; + DECLARE vStartingTime DATETIME; + DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; + DECLARE vDayRange INT; + + DECLARE cur1 CURSOR FOR + SELECT id + FROM edi.item_free; + + DECLARE cur2 CURSOR FOR + SELECT srId + FROM itemToInsert; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('edi.floramondo_offerRefresh'); + SET @isTriggerDisabled = FALSE; + RESIGNAL; + END; + + IF 'test' = (SELECT environment FROM util.config) THEN + LEAVE proc; + END IF; + + IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN + LEAVE proc; + END IF; + + SELECT dayRange INTO vDayRange + FROM offerRefreshConfig; + + IF vDayRange IS NULL THEN + CALL util.throw("Variable vDayRange not declared"); + END IF; + + SET vStartingTime = util.VN_NOW(); + + TRUNCATE edi.offerList; + + INSERT INTO edi.offerList(supplier, total) + SELECT v.name, COUNT(DISTINCT sr.ID) total + FROM edi.supplyResponse sr + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + WHERE sr.NumberOfUnits > 0 + AND sr.EmbalageCode != 999 + GROUP BY sr.vmpID; + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(*) total + FROM edi.supplyOffer sr + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.`filter` = sub.total; + + -- Elimina de la lista de items libres aquellos que ya existen + DELETE itf.* + FROM edi.item_free itf + JOIN vn.item i ON i.id = itf.id; + + CREATE OR REPLACE TEMPORARY TABLE tmp + (INDEX (`Item_ArticleCode`)) + ENGINE = MEMORY + SELECT t.* + FROM ( + SELECT * + FROM edi.supplyOffer + ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, + NumberOfUnits DESC LIMIT 10000000000000000000) t + GROUP BY t.srId; + + CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), + INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), + INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) + ENGINE = MEMORY + SELECT so.*, + ev1.type_description s1Value, + ev2.type_description s2Value, + ev3.type_description s3Value, + ev4.type_description s4Value, + ev5.type_description s5Value, + ev6.type_description s6Value, + eif1.feature ef1, + eif2.feature ef2, + eif3.feature ef3, + eif4.feature ef4, + eif5.feature ef5, + eif6.feature ef6 + FROM tmp so + LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode + AND eif1.presentation_order = 1 + AND eif1.expiry_date IS NULL + LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode + AND eif2.presentation_order = 2 + AND eif2.expiry_date IS NULL + LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode + AND eif3.presentation_order = 3 + AND eif3.expiry_date IS NULL + LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode + AND eif4.presentation_order = 4 + AND eif4.expiry_date IS NULL + LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode + AND eif5.presentation_order = 5 + AND eif5.expiry_date IS NULL + LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode + AND eif6.presentation_order = 6 + AND eif6.expiry_date IS NULL + LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature + AND so.s1 = ev1.type_value + LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature + AND so.s2 = ev2.type_value + LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature + AND so.s3 = ev3.type_value + LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature + AND so.s4 = ev4.type_value + LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature + AND so.s5 = ev5.type_value + LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature + AND so.s6 = ev6.type_value + ORDER BY Price; + + DROP TEMPORARY TABLE tmp; + + DELETE o + FROM edi.offer o + LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' + LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' + LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' + LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' + LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' + LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' + JOIN vn.floramondoConfig fc ON TRUE + WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) + OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) + OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) + OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) + OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) + OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); + + START TRANSACTION; + + -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos + UPDATE IGNORE edi.offer o + JOIN vn.item i + ON i.name = o.product_name + AND i.subname <=> o.company_name + AND i.value5 <=> o.s1Value + AND i.value6 <=> o.s2Value + AND i.value7 <=> o.s3Value + AND i.value8 <=> o.s4Value + AND i.value9 <=> o.s5Value + AND i.value10 <=> o.s6Value + AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask + AND i.EmbalageCode <=> o.EmbalageCode + AND i.quality <=> o.Quality + JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN vn.sale s ON s.itemFk = i.id + LEFT JOIN vn.ticket t ON t.id = s.ticketFk + AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) + LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk + AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) + SET i.supplyResponseFk = o.srID + WHERE (sr.ID IS NULL + OR sr.NumberOfUnits = 0 + OR di.LatestOrderDateTime < util.VN_NOW() + OR di.ID IS NULL) + AND it.isInventory + AND t.id IS NULL + AND po.id IS NULL; + + CREATE OR REPLACE TEMPORARY TABLE itemToInsert + ENGINE = MEMORY + SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk + FROM edi.offer o + LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId + WHERE i.id IS NULL + LIMIT vMaxNewItems; + + -- Reciclado de nº de item + OPEN cur1; + OPEN cur2; + + read_loop: LOOP + + FETCH cur2 INTO vSupplyResponseFk; + FETCH cur1 INTO vFreeId; + + IF vDone THEN + LEAVE read_loop; + END IF; + + UPDATE itemToInsert + SET itemFk = vFreeId + WHERE srId = vSupplyResponseFk; + + END LOOP; + + CLOSE cur1; + CLOSE cur2; + + -- Insertamos todos los items en Articles de la oferta + INSERT INTO vn.item(id, + `name`, + longName, + subName, + expenseFk, + typeFk, + intrastatFk, + originFk, + supplyResponseFk, + numberOfItemsPerCask, + embalageCode, + quality, + isFloramondo) + SELECT iti.itemFk, + iti.product_name, + iti.product_name, + iti.company_name, + iti.expenseFk, + iti.itemTypeFk, + iti.intrastatFk, + iti.originFk, + iti.`srId`, + iti.NumberOfItemsPerCask, + iti.EmbalageCode, + iti.Quality, + TRUE + FROM itemToInsert iti; + + -- Inserta la foto de los articulos nuevos (prioridad alta) + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) + SELECT i.id, PictureReference + FROM itemToInsert ii + JOIN vn.item i ON i.supplyResponseFk = ii.srId + WHERE PictureReference IS NOT NULL + AND i.image IS NULL; + + INSERT INTO edi.`log`(tableName, fieldName,fieldValue) + SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) + FROM vn.itemImageQueue + WHERE attempts = 0; + + -- Inserta si se añadiesen tags nuevos + INSERT IGNORE INTO vn.tag (name, ediTypeFk) + SELECT description, type_id FROM edi.type; + + -- Desabilita el trigger para recalcular los tags al final + SET @isTriggerDisabled = TRUE; + + -- Inserta los tags sólo en los articulos nuevos + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.product_name, 1 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Producto' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.product_name IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.Quality, 3 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Calidad' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.Quality IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.company_name, 4 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Productor' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.company_name IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s1Value, 5 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef1 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s1Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s2Value, 6 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef2 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s2Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s3Value, 7 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef3 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s3Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s4Value, 8 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef4 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s4Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s5Value, 9 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef5 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s5Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s6Value, 10 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef6 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s6Value IS NULL; + + INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 + FROM itemToInsert ii + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + JOIN vn.tag t ON t.`name` = 'Color' + LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode + LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id + AND tp.`description` = 'Hoofdkleur 1' + LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value + LEFT JOIN vn.itemInk ik ON ik.longName = i.longName + WHERE ink.name IS NOT NULL + OR ik.color IS NOT NULL; + + CREATE OR REPLACE TABLE tmp.item + (PRIMARY KEY (id)) + SELECT i.id FROM vn.item i + JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; + + CALL vn.item_refreshTags(); + + DROP TABLE tmp.item; + + SELECT MIN(LatestDeliveryDateTime) INTO vLanded + FROM edi.supplyResponse sr + JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + JOIN vn.floramondoConfig fc + WHERE mp.isLatestOrderDateTimeRelevant + AND di.LatestOrderDateTime > IF( + fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), + util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY); + + UPDATE vn.floramondoConfig + SET nextLanded = vLanded + WHERE vLanded IS NOT NULL; + + -- Elimina la oferta obsoleta + UPDATE vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID + LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk + SET b.quantity = 0 + WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() + OR i.supplyResponseFk IS NULL + OR sr.NumberOfUnits = 0) + AND am.name = 'LOGIFLORA' + AND e.isRaid; + + -- Localiza las entradas de cada almacen + UPDATE edi.warehouseFloramondo + SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); + + IF vLanded IS NOT NULL THEN + -- Actualiza la oferta existente + UPDATE vn.buy b + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.offer o ON i.supplyResponseFk = o.`srId` + SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, + b.buyingValue = o.price + WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask + OR b.buyingValue <> o.price); + + -- Inserta el resto + SET vLastInserted := util.VN_NOW(); + + -- Inserta la oferta + INSERT INTO vn.buy ( + entryFk, + itemFk, + quantity, + buyingValue, + stickers, + packing, + `grouping`, + groupingMode, + packagingFk, + deliveryFk) + SELECT wf.entryFk, + i.id, + o.NumberOfUnits * o.NumberOfItemsPerCask quantity, + o.Price, + o.NumberOfUnits etiquetas, + o.NumberOfItemsPerCask packing, + GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, + 2, -- Obliga al Packing + o.embalageCode, + o.diId + FROM edi.offer o + JOIN vn.item i ON i.supplyResponseFk = o.srId + JOIN edi.warehouseFloramondo wf + JOIN vn.packaging p ON p.id + LIKE o.embalageCode + LEFT JOIN vn.buy b ON b.itemFk = i.id + AND b.entryFk = wf.entryFk + WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL + + INSERT INTO vn.itemCost( + itemFk, + warehouseFk, + cm3, + cm3delivery) + SELECT b.itemFk, + wf.warehouseFk, + @cm3 := vn.buy_getUnitVolume(b.id), + IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) + FROM warehouseFloramondo wf + JOIN vn.volumeConfig vc + JOIN vn.buy b ON b.entryFk = wf.entryFk + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk + AND ic.warehouseFk = wf.warehouseFk + WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) + ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); + + CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc + SELECT b.id + FROM vn.buy b + JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk + WHERE b.created >= vLastInserted; + + CALL vn.buy_recalcPrices(); + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.warehouse w ON w.id = wf.warehouseFk + WHERE w.name = 'VNH' + AND b.quantity > 0 + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.vnh = sub.total; + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.warehouse w ON w.id = wf.warehouseFk + WHERE w.name = 'ALGEMESI' + AND b.quantity > 0 + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.algemesi = sub.total; + END IF; + + DROP TEMPORARY TABLE + edi.offer, + itemToInsert; + + SET @isTriggerDisabled = FALSE; + + COMMIT; + + -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias + UPDATE vn.item i + SET typeFk = 121 + WHERE i.longName LIKE 'Rosa Garden %' + AND typeFk = 17; + + UPDATE vn.item i + SET typeFk = 156 + WHERE i.longName LIKE 'Rosa ec %' + AND typeFk = 17; + + -- Refresca las fotos de los items existentes que mostramos (prioridad baja) + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) + SELECT i.id, sr.PictureReference, 100 + FROM edi.supplyResponse sr + JOIN vn.item i ON i.supplyResponseFk = sr.ID + JOIN edi.supplyOffer so ON so.srId = sr.ID + JOIN hedera.image i2 ON i2.name = i.image + AND i2.collectionFk = 'catalog' + WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) + AND sr.NumberOfUnits; + + INSERT INTO edi.`log` + SET tableName = 'floramondo_offerRefresh', + fieldName = 'Tiempo de proceso', + fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); + + DO RELEASE_LOCK('edi.floramondo_offerRefresh'); +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/item_freeAdd.sql b/db/routines/edi/procedures/item_freeAdd.sql new file mode 100644 index 000000000..cb572e1b1 --- /dev/null +++ b/db/routines/edi/procedures/item_freeAdd.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`item_freeAdd`() +BEGIN +/** + * Rellena la tabla item_free con los id ausentes en vn.item + * + */ + DECLARE vMaxItem INT; + + SELECT MAX(id) + INTO vMaxItem + FROM vn.item; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemBusy; + CREATE TEMPORARY TABLE tmp.itemBusy + (id INT PRIMARY KEY) + SELECT i.id + FROM vn.item i + WHERE i.isFloramondo + UNION ALL + SELECT ifr.id + FROM edi.item_free ifr; + + INSERT INTO edi.item_free(id) + SELECT i.id + FROM vn.item i + LEFT JOIN tmp.itemBusy ib ON ib.id = i.id + WHERE i.isFloramondo AND ib.id is null; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemBusy; +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/item_getNewByEkt.sql b/db/routines/edi/procedures/item_getNewByEkt.sql new file mode 100644 index 000000000..a80d04817 --- /dev/null +++ b/db/routines/edi/procedures/item_getNewByEkt.sql @@ -0,0 +1,186 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`item_getNewByEkt`(vEktFk INT, OUT vItemFk INT) +BEGIN + +/** + * Devuelve un número nuevo de item a partir de un registro de la tabla edi.ekt + * + * @param vEktFk Identificador de la tabla edi.ekt + */ + + START TRANSACTION; + + SELECT MIN(id) id INTO vItemFk + FROM edi.item_free; + + DELETE FROM edi.item_free + WHERE id = vItemFk; + + COMMIT; + + IF ISNULL(vItemFk) THEN + SELECT MAX(i.id) + 1 + INTO vItemFk + FROM vn.item i; + END IF; + + INSERT INTO vn.item(id, + `name`, + longName, + subName, + expenseFk, + typeFk, + intrastatFk, + originFk, + numberOfItemsPerCask, + embalageCode, + quality, + isFloramondo + ) + SELECT vItemFk, + e.item, + e.item, + e.item, + igto.expenseFk, + igto.itemTypeFk, + igto.intrastatFk, + igto.originFk, + e.pac, + least(IF((e.package = 800),((e.package * 10) + e.pac), e.package), IFNULL(idt.bucket_id, '999')) packageFk, + e.cat, + TRUE + FROM edi.ekt e + JOIN edi.item i ON i.id = e.`ref` + JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id + LEFT JOIN edi.item_defaultType idt ON idt.item_id = e.`ref` + WHERE e.id = vEktFk; + + SET @isTriggerDisabled = TRUE; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.item , 1 + FROM edi.ekt e + JOIN vn.tag t ON t.`name` = 'Producto' + WHERE e.id = vEktFk + AND NOT ISNULL(e.item); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.cat , 3 + FROM edi.ekt e + JOIN vn.tag t ON t.`name` = 'Calidad' + WHERE e.id = vEktFk + AND NOT ISNULL(e.cat); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , s.company_name , 4 + FROM edi.ekt e + JOIN edi.supplier s ON s.supplier_id = e.pro + JOIN vn.tag t ON t.`name` = 'Productor' + WHERE e.id = vEktFk + AND NOT ISNULL(s.company_name); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.s1, 5 + FROM edi.ekt e + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 1 + AND eif.expiry_date IS NULL + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + AND e.s1 = ev.type_value + JOIN vn.tag t ON t.ediTypeFk = eif.feature + WHERE e.id = vEktFk + AND NOT ISNULL(e.s1); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.s2, 6 + FROM edi.ekt e + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 2 + AND eif.expiry_date IS NULL + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + AND e.s2 = ev.type_value + JOIN vn.tag t ON t.ediTypeFk = eif.feature + WHERE e.id = vEktFk + AND NOT ISNULL(e.s2); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.s3, 7 + FROM edi.ekt e + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 3 + AND eif.expiry_date IS NULL + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + AND e.s3 = ev.type_value + JOIN vn.tag t ON t.ediTypeFk = eif.feature + WHERE e.id = vEktFk + AND NOT ISNULL(e.s3); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.s4, 8 + FROM edi.ekt e + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 4 + AND eif.expiry_date IS NULL + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + AND e.s4 = ev.type_value + JOIN vn.tag t ON t.ediTypeFk = eif.feature + WHERE e.id = vEktFk + AND NOT ISNULL(e.s4); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.s5, 9 + FROM edi.ekt e + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 5 + AND eif.expiry_date IS NULL + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + AND e.s5 = ev.type_value + JOIN vn.tag t ON t.ediTypeFk = eif.feature + WHERE e.id = vEktFk + AND NOT ISNULL(e.s5); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id , e.s6, 10 + FROM edi.ekt e + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 6 + AND eif.expiry_date IS NULL + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + AND e.s6 = ev.type_value + JOIN vn.tag t ON t.ediTypeFk = eif.feature + WHERE e.id = vEktFk + AND NOT ISNULL(e.s6); + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, t.id, IFNULL(ink.name, ik.color), 11 + FROM edi.ekt e + JOIN vn.tag t ON t.`name` = 'Color' + LEFT JOIN edi.feature f ON f.item_id = e.`ref` + LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id AND tp.`description` = 'Hoofdkleur 1' + LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value + LEFT JOIN vn.itemInk ik ON ik.longName = e.item + WHERE e.id = vEktFk + AND ( ink.name IS NOT NULL + OR ik.color IS NOT NULL) + LIMIT 1; + + DROP TABLE IF EXISTS tmp.item; + + CREATE TABLE tmp.item + (PRIMARY KEY (id)) + SELECT vItemFk id ; + + CALL vn.item_refreshTags(); + + SET @isTriggerDisabled = FALSE; + + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) + SELECT vItemFk, sr.PictureReference + FROM edi.ekt e + JOIN edi.supplyResponse sr ON e.ref = sr.Item_ArticleCode + WHERE e.id = vEktFk + AND NOT sr.PictureReference IS NULL + ORDER BY sr.created DESC + LIMIT 1; +END$$ +DELIMITER ; diff --git a/db/routines/edi/procedures/mail_new.sql b/db/routines/edi/procedures/mail_new.sql new file mode 100644 index 000000000..7bbf3f5cf --- /dev/null +++ b/db/routines/edi/procedures/mail_new.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`mail_new`( + vMessageId VARCHAR(100) + ,vSender VARCHAR(150) + ,OUT vSelf INT +) +BEGIN +/** + * Registers a mail message. + * + * @param vMessageId Message-ID of email + * @param vSender Id of mail sender + * @param vSelf The created message id + */ + DECLARE vSenderId INT; + DECLARE vIsDuplicated BOOL; + DECLARE duplicateKey CONDITION FOR 1062; + + DECLARE CONTINUE HANDLER FOR duplicateKey + SET vIsDuplicated = TRUE; + + SELECT id INTO vSenderId + FROM mailSender + WHERE mail = vSender; + + SET vIsDuplicated = FALSE; + INSERT INTO mail SET + sender = vSender, + senderFk = vSenderId, + messageId = vMessageId; + + IF vIsDuplicated THEN + SELECT id INTO vSelf + FROM mail + WHERE messageId = vMessageId; + ELSE + SET vSelf = LAST_INSERT_ID(); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/edi/triggers/BEFORE UPDATE.sql b/db/routines/edi/triggers/BEFORE UPDATE.sql new file mode 100644 index 000000000..1ba9b4b0f --- /dev/null +++ b/db/routines/edi/triggers/BEFORE UPDATE.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`BEFORE UPDATE` + BEFORE UPDATE ON `putOrder` + FOR EACH ROW +BEGIN + + DECLARE vError VARCHAR(100) DEFAULT 'Orderregel niet meer teruggevonden op basis van de orderps'; + DECLARE vVmpIdError INT DEFAULT 7; + DECLARE vVmpFk INT; + DECLARE vSupplyResponseNumberOfUnits INT; + + SELECT sr.vmpID INTO vVmpFk + FROM edi.supplyResponse sr + WHERE sr.id = NEW.supplyResponseID; + + IF NEW.OrderStatus = 3 + AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) + AND NEW.error = vError + AND vVmpFk = vVmpIdError + + THEN + + SET NEW.OrderStatus = 2; + + END IF; + + -- Error de disponible menor de lo solicitado + IF NEW.error LIKE 'error2602%' THEN + + SELECT NumberOfUnits INTO vSupplyResponseNumberOfUnits + FROM edi.supplyResponse sr + WHERE sr.ID = NEW.supplyResponseID; + + SET NEW.error = CONCAT('(',vSupplyResponseNumberOfUnits,') ', NEW.error); + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/edi/triggers/item_feature_bi.sql b/db/routines/edi/triggers/item_feature_bi.sql new file mode 100644 index 000000000..81d16d0c8 --- /dev/null +++ b/db/routines/edi/triggers/item_feature_bi.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`item_feature_bi` + BEFORE INSERT ON `item_feature` + FOR EACH ROW +BEGIN + IF NEW.expiry_date = '0000-00-00' THEN + SET NEW.expiry_date = NULL; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql b/db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql new file mode 100644 index 000000000..fa34425c9 --- /dev/null +++ b/db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql @@ -0,0 +1,75 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_AFTER_UPDATE` + AFTER UPDATE ON `putOrder` + FOR EACH ROW +BEGIN + DECLARE vSaleFk INT; + DECLARE vOrderStatusDenied INT DEFAULT 3; + DECLARE vOrderStatusOK INT DEFAULT 2; + DECLARE vIsEktSender BOOLEAN; + + IF NEW.OrderStatus = vOrderStatusDenied AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN + + SELECT s.id INTO vSaleFk + FROM vn.sale s + JOIN vn.ticket t ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() + AND i.supplyResponseFk = NEW.supplyResponseID + LIMIT 1; + + UPDATE vn.sale s + JOIN vn.ticket t ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID + SET s.quantity = 0 + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() + AND i.supplyResponseFk = NEW.supplyResponseID; + + INSERT INTO vn.mail (sender, `subject`, body) + SELECT IF(u.id IS NOT NULL AND c.email IS NOT NULL, + c.email, + CONCAT(account.user_getNameFromId(c.salesPersonFk), '@verdnatura.es') + ), + 'Producto no disponible en Floramondo', + CONCAT('El artículo ', s.concept, ' del ticket ', t.id , ' ha sido cancelado por Floramondo. ', + ' Se ha actualizado la cantidad de ', OLD.quantity,' a 0. ', + IF (u.id IS NOT NULL AND c.email IS NOT NULL , + CONCAT('https://shop.verdnatura.es/#!form=ecomerce%2Fticket&ticket=', t.id ), + CONCAT('https://salix.verdnatura.es/#!/ticket/', t.id ,'/summary'))) + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.`client` c ON c.id = t.clientFk + LEFT JOIN account.user u ON u.id= c.salesPersonFk AND u.name IN ('ruben', 'ismaelalcolea') + WHERE s.id = vSaleFk; + + END IF; + + + IF NEW.OrderStatus = vOrderStatusOK AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN + + SELECT v.isEktSender INTO vIsEktSender + FROM edi.VMPSettings v + JOIN edi.supplyResponse sr ON sr.vmpID = v.VMPID + WHERE sr.id = NEW.supplyResponseID; + + IF NOT vIsEktSender THEN + + CALL edi.ekt_add(NEW.id); + + END IF; + + IF NEW.barcode THEN + + INSERT IGNORE INTO vn.itemBarcode(itemFk, code) + SELECT i.id, NEW.barcode + FROM vn.item i + WHERE i.supplyResponseFk = NEW.supplyResponseID; + + END IF; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql b/db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql new file mode 100644 index 000000000..c1ac76df5 --- /dev/null +++ b/db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_BEFORE_INSERT` + BEFORE INSERT ON `putOrder` + FOR EACH ROW +BEGIN + + DECLARE nextID INT; + + SELECT 1 + MAX(id) INTO nextID FROM putOrder ; + + SET NEW.orderTradelineItemID = nextID; + +END$$ +DELIMITER ; diff --git a/db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql b/db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql new file mode 100644 index 000000000..f4115cbb3 --- /dev/null +++ b/db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`supplyResponse_AFTER_UPDATE` + AFTER UPDATE ON `supplyResponse` + FOR EACH ROW +BEGIN + + UPDATE vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID + SET b.quantity = NEW.NumberOfItemsPerCask * NEW.NumberOfUnits, + b.stickers = NEW.NumberOfUnits + WHERE i.supplyResponseFk = NEW.ID + AND am.name = 'LOGIFLORA' + AND e.isRaid + AND tr.landed >= util.VN_CURDATE(); + +END$$ +DELIMITER ; diff --git a/db/routines/edi/views/ektRecent.sql b/db/routines/edi/views/ektRecent.sql new file mode 100644 index 000000000..3e41490ab --- /dev/null +++ b/db/routines/edi/views/ektRecent.sql @@ -0,0 +1,57 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `edi`.`ektRecent` +AS SELECT `e`.`id` AS `id`, + `e`.`barcode` AS `barcode`, + `e`.`entryYear` AS `entryYear`, + `e`.`batchNumber` AS `batchNumber`, + `e`.`deliveryNumber` AS `deliveryNumber`, + `e`.`vendorOrderNumber` AS `vendorOrderNumber`, + `e`.`fec` AS `fec`, + `e`.`hor` AS `hor`, + `e`.`now` AS `now`, + `e`.`ptj` AS `ptj`, + `e`.`ref` AS `ref`, + `e`.`item` AS `item`, + `e`.`pac` AS `pac`, + `e`.`qty` AS `qty`, + `e`.`ori` AS `ori`, + `e`.`cat` AS `cat`, + `e`.`agj` AS `agj`, + `e`.`kop` AS `kop`, + `e`.`ptd` AS `ptd`, + `e`.`sub` AS `sub`, + `e`.`pro` AS `pro`, + `e`.`pri` AS `pri`, + `e`.`package` AS `package`, + `e`.`auction` AS `auction`, + `e`.`klo` AS `klo`, + `e`.`k1` AS `k1`, + `e`.`k2` AS `k2`, + `e`.`k3` AS `k3`, + `e`.`k4` AS `k4`, + `e`.`s1` AS `s1`, + `e`.`s2` AS `s2`, + `e`.`s3` AS `s3`, + `e`.`s4` AS `s4`, + `e`.`s5` AS `s5`, + `e`.`s6` AS `s6`, + `e`.`ok` AS `ok`, + `e`.`trolleyFk` AS `trolleyFk`, + `e`.`putOrderFk` AS `putOrderFk`, + `e`.`scanned` AS `scanned`, + `e`.`cps` AS `cps`, + `e`.`dp` AS `dp`, + `e`.`sender` AS `sender`, + `ec`.`usefulAuctionLeftSegmentLength` AS `usefulAuctionLeftSegmentLength`, + `ec`.`standardBarcodeLength` AS `standardBarcodeLength`, + `ec`.`floridayBarcodeLength` AS `floridayBarcodeLength`, + `ec`.`floramondoBarcodeLength` AS `floramondoBarcodeLength`, + `ec`.`defaultKlo` AS `defaultKlo`, + `ec`.`ektRecentScopeDays` AS `ektRecentScopeDays` +FROM ( + `edi`.`ekt` `e` + JOIN `edi`.`ektConfig` `ec` + ) +WHERE `e`.`entryYear` = year(`util`.`VN_CURDATE`()) + AND `e`.`fec` >= `util`.`VN_CURDATE`() + INTERVAL - `ec`.`ektRecentScopeDays` DAY diff --git a/db/routines/edi/views/errorList.sql b/db/routines/edi/views/errorList.sql new file mode 100644 index 000000000..4e7cbc840 --- /dev/null +++ b/db/routines/edi/views/errorList.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `edi`.`errorList` +AS SELECT `po`.`id` AS `id`, + `c`.`name` AS `name`, + `i`.`longName` AS `longName`, + `po`.`quantity` AS `quantity`, + left(`po`.`error`, 4) AS `stock`, + `po`.`error` AS `error`, + `po`.`deliveryInformationID` AS `deliveryInformationID`, + `po`.`supplyResponseID` AS `supplyResponseID`, + `po`.`OrderTradeLineDateTime` AS `OrderTradeLineDateTime`, + `po`.`EndUserPartyGLN` AS `EndUserPartyGLN` +FROM ( + ( + `edi`.`putOrder` `po` + LEFT JOIN `vn`.`client` `c` ON(`c`.`id` = `po`.`EndUserPartyGLN`) + ) + LEFT JOIN `vn`.`item` `i` ON(`i`.`supplyResponseFk` = `po`.`supplyResponseID`) + ) +WHERE `po`.`OrderTradeLineDateTime` > `util`.`VN_CURDATE`() + INTERVAL -12 HOUR + AND `po`.`OrderStatus` = 3 + AND left(`po`.`error`, 4) <> '(0) ' diff --git a/db/routines/edi/views/supplyOffer.sql b/db/routines/edi/views/supplyOffer.sql new file mode 100644 index 000000000..c4a8582a1 --- /dev/null +++ b/db/routines/edi/views/supplyOffer.sql @@ -0,0 +1,113 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `edi`.`supplyOffer` +AS SELECT `sr`.`vmpID` AS `vmpID`, + `di`.`ID` AS `diId`, + `sr`.`ID` AS `srId`, + `sr`.`Item_ArticleCode` AS `Item_ArticleCode`, + `sr`.`VBNOmschrijving` AS `product_name`, + `s`.`company_name` AS `company_name`, + cast(`sr`.`Price` AS decimal(10, 3)) AS `Price`, + `sr`.`Quality` AS `Quality`, + `sr`.`s1` AS `s1`, + `sr`.`s2` AS `s2`, + `sr`.`s3` AS `s3`, + `sr`.`s4` AS `s4`, + `sr`.`s5` AS `s5`, + `sr`.`s6` AS `s6`, + `sr`.`NumberOfUnits` AS `NumberOfUnits`, + least( + IF( + `sr`.`EmbalageCode` = 800, + `sr`.`EmbalageCode` * 10 + `sr`.`NumberOfItemsPerCask`, + `sr`.`EmbalageCode` + ), + IFNULL(`idt`.`bucket_id`, '999') + ) AS `EmbalageCode`, + `di`.`LatestDeliveryDateTime` AS `LatestDeliveryDateTime`, + `di`.`EarliestDespatchDateTime` AS `EarliestDespatchDateTime`, + `di`.`FirstOrderDateTime` AS `FirstOrderDateTime`, + `di`.`LatestOrderDateTime` AS `LatestOrderDateTime`, + `sr`.`NumberOfItemsPerCask` AS `NumberOfItemsPerCask`, + `sr`.`NumberOfLayersPerTrolley` AS `NumberOfLayersPerTrolley`, + `sr`.`MinimumNumberToOrder` AS `MinimumNumberToOrder`, + `sr`.`MaximumNumberToOrder` AS `MaximumNumberToOrder`, + `sr`.`IncrementalOrderableQuantity` AS `IncrementalOrderableQuantity`, + `sr`.`PackingPrice` AS `PackingPrice`, + `sr`.`MarketPlaceID` AS `MarketPlaceID`, + `sr`.`PictureReference` AS `PictureReference`, + `sr`.`updated` AS `supplyResponseUpdated`, + `i`.`group_id` AS `group_id`, + `mp`.`name` AS `marketPlace`, + `di`.`DeliveryPrice` AS `DeliveryPrice`, + `di`.`ChargeAmount` AS `ChargeAmount`, + `di`.`MinimumQuantity` AS `MinimumQuantity`, + `di`.`MaximumQuantity Integer` AS `MaximumQuantity`, + cast( + `sr`.`MinimumNumberToOrder` * CASE + `sr`.`MinimumOrderUnitType` + WHEN 1 THEN 1 + WHEN 2 THEN `sr`.`NumberOfItemsPerCask` / `sr`.`NumberBunchesPerCask` + WHEN 3 THEN `sr`.`NumberOfItemsPerCask` + WHEN 4 THEN floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` + WHEN 5 THEN floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` * `sr`.`NumberOfLayersPerTrolley` + END AS decimal(10, 0) + ) AS `OrderUnit`, + cast( + `sr`.`IncrementalOrderableQuantity` * CASE + `sr`.`IncrementalOrderableQuantityType` + WHEN 1 THEN 1 + WHEN 2 THEN `sr`.`NumberOfItemsPerCask` / `sr`.`NumberBunchesPerCask` + WHEN 3 THEN `sr`.`NumberOfItemsPerCask` + WHEN 4 THEN floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` + WHEN 5 THEN floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` * `sr`.`NumberOfLayersPerTrolley` + END AS decimal(10, 0) + ) AS `IncrementalOrderUnit`, + `mp`.`isEarlyBird` AS `isEarlyBird`, + `v`.`isVNHSupplier` AS `isVNHSupplier`, + `igo`.`expenseFk` AS `expenseFk`, + `igo`.`intrastatFk` AS `intrastatFk`, + `igo`.`originFk` AS `originFk`, + IFNULL(`idt`.`itemTypeFk`, `igo`.`itemTypeFk`) AS `itemTypeFk` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + `edi`.`deliveryInformation` `di` + JOIN `edi`.`supplyResponse` `sr` ON(`sr`.`ID` = `di`.`supplyResponseID`) + ) + LEFT JOIN `edi`.`supplier` `s` ON(`s`.`glnAddressCode` = `sr`.`SupplierGLN`) + ) + JOIN `edi`.`bucket` `b` ON(`b`.`bucket_id` = `sr`.`EmbalageCode`) + ) + JOIN `edi`.`item` `i` ON(`i`.`id` = `sr`.`Item_ArticleCode`) + ) + JOIN `edi`.`marketPlace` `mp` ON(`mp`.`id` = `sr`.`MarketPlaceID`) + ) + JOIN `vn`.`floramondoConfig` `fm` + ) + LEFT JOIN `edi`.`item_defaultType` `idt` ON(`idt`.`item_id` = `i`.`id`) + ) + JOIN `edi`.`VMPSettings` `v` ON(`v`.`VMPID` = `sr`.`vmpID`) + ) + JOIN `edi`.`item_groupToOffer` `igo` ON(`igo`.`group_code` = `i`.`group_id`) + ) +WHERE `v`.`isBlocked` = 0 + AND `s`.`isBanned` = 0 + AND `sr`.`NumberOfUnits` > 0 + AND CURRENT_TIMESTAMP() BETWEEN `di`.`FirstOrderDateTime` AND `di`.`LatestOrderDateTime` + AND `mp`.`isOffered` = 1 + AND `di`.`LatestDeliveryDateTime` BETWEEN cast(`fm`.`nextLanded` AS date) + AND concat( + cast(`fm`.`nextLanded` AS date), + ' ', + `fm`.`MaxLatestDeliveryHour` + ) + AND `sr`.`NumberOfItemsPerCask` > 1 +GROUP BY `sr`.`ID` +HAVING `EmbalageCode` <> 999 diff --git a/db/routines/hedera/events/order_doRecalc.sql b/db/routines/hedera/events/order_doRecalc.sql new file mode 100644 index 000000000..d355e1a55 --- /dev/null +++ b/db/routines/hedera/events/order_doRecalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `hedera`.`order_doRecalc` + ON SCHEDULE EVERY 10 SECOND + STARTS '2019-08-29 14:18:04.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL order_doRecalc$$ +DELIMITER ; diff --git a/db/routines/hedera/functions/myClient_getDebt.sql b/db/routines/hedera/functions/myClient_getDebt.sql new file mode 100644 index 000000000..7f981904e --- /dev/null +++ b/db/routines/hedera/functions/myClient_getDebt.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `hedera`.`myClient_getDebt`(vDate DATE) + RETURNS decimal(10,2) + DETERMINISTIC +BEGIN +/** + * Calcula el saldo del cliente actual. + * + * @return Saldo del cliente + */ + RETURN vn.client_getDebt(account.myUser_getId(), vDate); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/functions/myUser_checkRestPriv.sql b/db/routines/hedera/functions/myUser_checkRestPriv.sql new file mode 100644 index 000000000..874499ce9 --- /dev/null +++ b/db/routines/hedera/functions/myUser_checkRestPriv.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `hedera`.`myUser_checkRestPriv`(vMethodPath VARCHAR(255)) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Checks if the current user has permission to run a REST service. + * + * @param vMethodPath Route of the REST service + * @return %TRUE if it has permissions, otherwise %FALSE + */ + DECLARE vCount INT; + DECLARE vHasRole INT DEFAULT NULL; + + SELECT COUNT(*) INTO vCount FROM restPriv + WHERE methodPath = vMethodPath; + + IF vCount = 0 THEN + RETURN FALSE; + END IF; + + SELECT COUNT(*) > 0 + INTO vHasRole + FROM restPriv + WHERE methodPath = vMethodPath + AND (`role` IS NULL OR account.myUser_hasRoleId(`role`)) + LIMIT 1; + + RETURN vHasRole; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/functions/order_getTotal.sql b/db/routines/hedera/functions/order_getTotal.sql new file mode 100644 index 000000000..2edb6340d --- /dev/null +++ b/db/routines/hedera/functions/order_getTotal.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `hedera`.`order_getTotal`(vSelf INT) + RETURNS decimal(10,2) + DETERMINISTIC + READS SQL DATA +BEGIN +/** +* Obtiene el total de un pedido con el IVA y el recargo de +* equivalencia incluidos. +* +* @param vSelf El identificador del pedido +* @return El total del pedido +*/ + DECLARE vTotal DECIMAL(10,2); + + DROP TEMPORARY TABLE IF EXISTS tmp.`order`; + CREATE TEMPORARY TABLE tmp.`order` + ENGINE = MEMORY + SELECT vSelf orderFk; + + CALL order_getTotal; + + SELECT total INTO vTotal FROM tmp.orderTotal; + + DROP TEMPORARY TABLE + tmp.`order`, + tmp.orderTotal; + + RETURN vTotal; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql b/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql new file mode 100644 index 000000000..c9a9db5e0 --- /dev/null +++ b/db/routines/hedera/procedures/catalog_calcFromMyAddress.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`catalog_calcFromMyAddress`(vDelivery DATE, vAddress INT) +BEGIN +/** + * Gets the available items list. + * + * @param vDelivery Delivery date + * @param vAddress Address id + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + DECLARE vAgencyMode INT; + + SELECT a.agencyModeFk + INTO vAgencyMode + FROM myClient c + JOIN vn.address a ON a.clientFk = c.id + WHERE a.id = vAddress; + + CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT c.item_id itemFk + FROM `cache`.available c + JOIN tmp.availableCalc a ON a.calcFk = c.calc_id + WHERE c.available > 0 + GROUP BY c.item_id; + + CALL vn.catalog_calculate(vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/image_ref.sql b/db/routines/hedera/procedures/image_ref.sql new file mode 100644 index 000000000..4c6e925fe --- /dev/null +++ b/db/routines/hedera/procedures/image_ref.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`image_ref`( + vCollection VARCHAR(255), + vName VARCHAR(255) +) +proc: BEGIN +/** + * Increases the reference count of an image. + * + * @param vCollection The collection name + * @param vName The image name + */ + IF vName IS NULL THEN + LEAVE proc; + END IF; + + INSERT INTO `image` + SET `collectionFk` = vCollection, + `name` = vName, + `updated` = util.VN_UNIX_TIMESTAMP(), + `nRefs` = 1 + ON DUPLICATE KEY UPDATE + `nRefs` = nRefs + 1; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/image_unref.sql b/db/routines/hedera/procedures/image_unref.sql new file mode 100644 index 000000000..146fc486b --- /dev/null +++ b/db/routines/hedera/procedures/image_unref.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`image_unref`( + vCollection VARCHAR(255), + vName VARCHAR(255) +) +BEGIN +/** + * Decreases the reference count of an image. + * + * @param vCollection The collection name + * @param vName The image name + */ + UPDATE image SET nRefs = GREATEST(CAST(nRefs AS SIGNED) - 1, 0) + WHERE `name` = vName + AND collectionFk = vCollection; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/item_calcCatalog.sql b/db/routines/hedera/procedures/item_calcCatalog.sql new file mode 100644 index 000000000..81b3adf5a --- /dev/null +++ b/db/routines/hedera/procedures/item_calcCatalog.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_calcCatalog`( + vSelf INT, + vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT) +BEGIN +/** + * Calculates available and price for a single item. + * + * @param vItemFk The item id + * @return List of available lots + */ + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + ENGINE = MEMORY + SELECT vSelf itemFk; + + CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); + + SELECT l.warehouseFk, w.name warehouse, + p.`grouping`, p.price, p.rate, l.available + FROM tmp.ticketLot l + JOIN tmp.ticketComponentPrice p ON p.warehouseFk = l.warehouseFk + JOIN vn.warehouse w ON w.id = p.warehouseFk + ORDER BY warehouseFk, `grouping`; + + DROP TEMPORARY TABLE + tmp.ticketCalculateItem, + tmp.ticketComponentPrice, + tmp.ticketComponent, + tmp.ticketLot, + tmp.zoneGetShipped; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/item_getVisible.sql b/db/routines/hedera/procedures/item_getVisible.sql new file mode 100644 index 000000000..8e25eaab3 --- /dev/null +++ b/db/routines/hedera/procedures/item_getVisible.sql @@ -0,0 +1,124 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_getVisible`( + vWarehouse TINYINT, + vDate DATE, + vType INT, + vPrefix VARCHAR(255)) +BEGIN + +/** + * Gets visible items of the specified type at specified date. + * + * @param vWarehouse The warehouse id + * @param vDate The visible date + * @param vType The type id + * @param vPrefix The article prefix to filter or %NULL for all + * @return tmp.itemVisible Visible items + */ + DECLARE vPrefixLen SMALLINT; + DECLARE vFilter VARCHAR(255) DEFAULT NULL; + DECLARE vDateInv DATE DEFAULT vn.getInventoryDate(); + DECLARE EXIT HANDLER FOR 1114 + BEGIN + GET DIAGNOSTICS CONDITION 1 + @message = MESSAGE_TEXT; + CALL vn.mail_insert( + 'cau@verdnatura.es', + NULL, + CONCAT('hedera.item_getVisible error: ', @message), + CONCAT( + 'warehouse: ', IFNULL(vWarehouse, ''), + ', Fecha:', IFNULL(vDate, ''), + ', tipo: ', IFNULL(vType,''), + ', prefijo: ', IFNULL(vPrefix,''))); + RESIGNAL; + END; + SET vPrefixLen = IFNULL(LENGTH(vPrefix), 0) + 1; + + IF vPrefixLen > 1 THEN + SET vFilter = CONCAT(vPrefix, '%'); + END IF; + + DROP TEMPORARY TABLE IF EXISTS `filter`; + CREATE TEMPORARY TABLE `filter` + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT id itemFk FROM vn.item + WHERE typeFk = vType + AND (vFilter IS NULL OR `name` LIKE vFilter); + + DROP TEMPORARY TABLE IF EXISTS currentStock; + CREATE TEMPORARY TABLE currentStock + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT itemFk, SUM(quantity) quantity + FROM ( + SELECT b.itemFk, b.quantity + 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 BETWEEN vDateInv AND vDate + AND t.warehouseInFk = vWarehouse + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, -b.quantity + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() + AND t.warehouseOutFk = vWarehouse + AND NOT e.isRaid + AND t.isDelivered + UNION ALL + SELECT m.itemFk, -m.quantity + FROM vn.sale m + JOIN vn.ticket t ON t.id = m.ticketFk + JOIN vn.ticketState s ON s.ticketFk = t.id + WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() + AND t.warehouseFk = vWarehouse + AND s.alertLevel = 3 + ) t + GROUP BY itemFk + HAVING quantity > 0; + + DROP TEMPORARY TABLE IF EXISTS tmp; + CREATE TEMPORARY TABLE tmp + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT b.itemFk, b.packagingFk, b.packing + 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 BETWEEN vDateInv AND vDate + AND NOT b.isIgnored + AND b.price2 >= 0 + AND b.packagingFk IS NOT NULL + ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC + LIMIT 10000000000000000000 + ) t GROUP BY itemFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemVisible; + CREATE TEMPORARY TABLE tmp.itemVisible + ENGINE = MEMORY + SELECT i.id Id_Article, + SUBSTRING(i.`name`, vPrefixLen) Article, + t.packing, p.id Id_Cubo, + IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, + CEIL(s.quantity / t.packing) etiquetas + FROM vn.item i + JOIN `filter` f ON f.itemFk = i.id + JOIN currentStock s ON s.itemFk = i.id + LEFT JOIN tmp t ON t.itemFk = i.id + LEFT JOIN vn.packaging p ON p.id = t.packagingFk + WHERE CEIL(s.quantity / t.packing) > 0 + -- FIXME: Column Cubos.box not included in view vn.packaging + /* AND p.box */ ; + + DROP TEMPORARY TABLE + `filter`, + currentStock, + tmp; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/item_listAllocation.sql b/db/routines/hedera/procedures/item_listAllocation.sql new file mode 100644 index 000000000..4a9c723f5 --- /dev/null +++ b/db/routines/hedera/procedures/item_listAllocation.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_listAllocation`(IN `vWh` TINYINT, IN `vDate` DATE, IN `vType` INT, IN `vPrefix` VARCHAR(255), IN `vUseIds` BOOLEAN) +BEGIN +/** + * Lists visible items and it's box sizes of the specified + * type at specified date. + * + * @param vWh The warehouse id + * @param vDate The visible date + * @param vType The type id + * @param vPrefix The article prefix to filter or %NULL for all + * @param vUseIds Whether to order the result by item id + * @select List of visible items with it's box sizes + */ + CALL item_getVisible(vWh, vDate, vType, vPrefix); + + IF vUseIds + THEN + SELECT * FROM tmp.itemVisible + ORDER BY Id_Article; + ELSE + SELECT * FROM tmp.itemVisible + ORDER BY Article, packing; + END IF; + + DROP TEMPORARY TABLE tmp.itemVisible; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_addItem.sql b/db/routines/hedera/procedures/myOrder_addItem.sql new file mode 100644 index 000000000..b5ea34ea2 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_addItem.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_addItem`( + vSelf INT, + vWarehouse INT, + vItem INT, + vAmount INT) +BEGIN + CALL myOrder_checkMine(vSelf); + CALL order_addItem(vSelf, vWarehouse, vItem, vAmount); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_calcCatalogFromItem.sql b/db/routines/hedera/procedures/myOrder_calcCatalogFromItem.sql new file mode 100644 index 000000000..05c2a41f2 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_calcCatalogFromItem.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_calcCatalogFromItem`(vSelf INT, vItem INT) +BEGIN +/** + * Gets the availability and prices for the given item + * using current user order parameters. + * + * @table tmp.item(itemFk) + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + CALL myOrder_checkMine(vSelf); + CALL order_calcCatalogFromItem(vSelf, vItem); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_calcCatalogFull.sql b/db/routines/hedera/procedures/myOrder_calcCatalogFull.sql new file mode 100644 index 000000000..b83286a2b --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_calcCatalogFull.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_calcCatalogFull`(vSelf INT) +BEGIN +/** + * Gets the availability and prices for the given items + * using current user order parameters. + * + * @table tmp.item(itemFk) + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + CALL myOrder_checkMine(vSelf); + CALL order_calcCatalogFull(vSelf); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_checkConfig.sql b/db/routines/hedera/procedures/myOrder_checkConfig.sql new file mode 100644 index 000000000..ca810805c --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_checkConfig.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_checkConfig`(vSelf INT) +proc: 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 + */ + CALL myOrder_checkMine(vSelf); + CALL order_checkConfig(vSelf); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_checkMine.sql b/db/routines/hedera/procedures/myOrder_checkMine.sql new file mode 100644 index 000000000..7e00b2f7f --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_checkMine.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_checkMine`(vSelf INT) +proc: BEGIN +/** + * Check that order is owned by current user, otherwise throws an error. + * + * @param vSelf The order id + */ + DECLARE vIsMine BOOL; + + SELECT COUNT(*) > 0 INTO vIsMine + FROM `order` + WHERE id = vSelf + AND customer_id = account.myUser_getId(); + + IF NOT vIsMine THEN + CALL util.throw('orderNotOwnedByUser'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_configure.sql b/db/routines/hedera/procedures/myOrder_configure.sql new file mode 100644 index 000000000..185384fc0 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_configure.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_configure`( + vSelf INT, + vDelivery DATE, + vDeliveryMethod VARCHAR(45), + vAgency INT, + vAddress INT) +BEGIN +/** + * Creates an order with passed parameters. If passed parameters are wrong + * it returns an error. + * + * @param vSelf The order id + * @param vDelivery Delivery date + * @param vDeliveryMethod Delivery method code + * @param vAgency Agency id + * @param vAddress Address id, @NULL for pickup + */ + CALL myOrder_checkMine(vSelf); + + IF vAddress IS NOT NULL + AND NOT (SELECT COUNT(*) FROM myAddress WHERE id = vAddress) THEN + CALL util.throw('addressNotOwnedByUser'); + END IF; + + CALL order_configure( + vSelf, + vDelivery, + vDeliveryMethod, + vAgency, + vAddress + ); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_configureForGuest.sql b/db/routines/hedera/procedures/myOrder_configureForGuest.sql new file mode 100644 index 000000000..9d4ede5e0 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_configureForGuest.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_configureForGuest`(OUT vSelf INT) +BEGIN + DECLARE vMethod VARCHAR(255); + DECLARE vAgency INT; + DECLARE vAddress INT; + DECLARE vDate DATE; + + SELECT cf.guestMethod, cf.guestAgencyFk, cl.defaultAddressFk + INTO vMethod, vAgency, vAddress + FROM orderConfig cf + JOIN myClient cl + LIMIT 1; + + SET vDate = TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); + + IF WEEKDAY(vDate) BETWEEN 5 AND 6 THEN + SET vDate = TIMESTAMPADD(DAY, 7 - WEEKDAY(vDate), vDate); + END IF; + + SELECT id INTO vSelf + FROM myOrder + WHERE NOT isConfirmed + ORDER BY id DESC + LIMIT 1; + + IF vSelf IS NULL THEN + CALL myOrder_create( + vSelf, + vDate, + vMethod, + vAgency, + vAddress + ); + ELSE + CALL myOrder_configure( + vSelf, + vDate, + vMethod, + vAgency, + vAddress + ); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_confirm.sql b/db/routines/hedera/procedures/myOrder_confirm.sql new file mode 100644 index 000000000..2117ea448 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_confirm.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_confirm`(vSelf INT) +BEGIN + CALL myOrder_checkMine(vSelf); + CALL order_checkConfig(vSelf); + CALL order_confirm(vSelf); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_create.sql b/db/routines/hedera/procedures/myOrder_create.sql new file mode 100644 index 000000000..251948bc6 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_create.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_create`( + OUT vSelf INT, + vDelivery DATE, + vDeliveryMethod VARCHAR(45), + vAgency INT, + vAddress INT) +proc: BEGIN +/** + * Creates a new order for the current user. If passed parameters are wrong + * it returns an error. + * + * @param vDelivery Delivery date + * @param vDeliveryMethod Delivery method code + * @param vAgency Agency id + * @param vAddress Address id, @NULL for pickup + */ + DECLARE vCompany INT; + + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + + INSERT INTO `order` + SET customer_id = account.myUser_getId(), + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + CALL myOrder_configure( + vSelf, + vDelivery, + vDeliveryMethod, + vAgency, + vAddress + ); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_getAvailable.sql b/db/routines/hedera/procedures/myOrder_getAvailable.sql new file mode 100644 index 000000000..00ac60563 --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_getAvailable.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_getAvailable`(vSelf INT) +BEGIN +/** + * Gets the available items list. + * + * @param vSelf The order id + * @table tmp.itemAvailable + */ + CALL myOrder_checkMine(vSelf); + CALL order_getAvailable(vSelf); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_getTax.sql b/db/routines/hedera/procedures/myOrder_getTax.sql new file mode 100644 index 000000000..826a37efd --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_getTax.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_getTax`(vSelf INT) + READS SQL DATA +BEGIN +/** + * Returns the taxes for the current client order. + * + * @treturn tmp.orderTax + */ + CALL myOrder_checkMine(vSelf); + + DROP TEMPORARY TABLE IF EXISTS tmp.`order`; + CREATE TEMPORARY TABLE tmp.`order` + ENGINE = MEMORY + SELECT vSelf orderFk; + + CALL order_getTax(); + + DROP TEMPORARY TABLE IF EXISTS tmp.`order`; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_newWithAddress.sql b/db/routines/hedera/procedures/myOrder_newWithAddress.sql new file mode 100644 index 000000000..ec3f07d9f --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_newWithAddress.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_newWithAddress`( + OUT vSelf INT, + vLandingDate DATE, + vAddressFk INT) +BEGIN +/** + * Crea una nueva orden para el usuario actual especificando + * una fecha de entrega. + * + * @param vSelf Id de la nueva orden + * @param vLandingDate Fecha de entrega + */ + DECLARE vCompany INT; + DECLARE vDeliveryMethodId INT; + DECLARE vAgencyMode INT; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + SET vSelf = NULL; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT a.agencyModeFk, a.id + INTO vAgencyMode, vAddressFk + FROM vn.address a + WHERE a.id = vAddressFk; + + SELECT deliveryMethodFk INTO vDeliveryMethodId + FROM vn.agencyMode am + WHERE am.id = vAgencyMode; + + IF vCompany IS NULL + THEN + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + END IF; + + INSERT INTO `order` + SET + customer_id = account.myUser_getId(), + date_send = vLandingDate, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgencyMode, + address_id = vAddressFk, + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + + CALL order_checkConfig(vSelf); + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myOrder_newWithDate.sql b/db/routines/hedera/procedures/myOrder_newWithDate.sql new file mode 100644 index 000000000..4d1837e2b --- /dev/null +++ b/db/routines/hedera/procedures/myOrder_newWithDate.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myOrder_newWithDate`( + OUT vSelf INT, + vLandingDate DATE) +BEGIN +/** + * Crea una nueva orden para el usuario actual especificando + * una fecha de entrega. + * + * @param vSelf Id de la nueva orden + * @param vLandingDate Fecha de entrega + */ + DECLARE vCompany INT; + DECLARE vDeliveryMethodId INT; + DECLARE vAgencyMode INT; + DECLARE vAddress INT; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + SET vSelf = NULL; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT a.agencyModeFk, a.id + INTO vAgencyMode, vAddress + FROM myClient c + JOIN vn.address a ON a.id = c.defaultAddressFk; + + SELECT deliveryMethodFk INTO vDeliveryMethodId + FROM vn.agencyMode am + WHERE am.id = vAgencyMode; + + IF vCompany IS NULL + THEN + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + END IF; + + INSERT INTO `order` + SET + customer_id = account.myUser_getId(), + date_send = vLandingDate, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgencyMode, + address_id = vAddress, + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + + CALL order_checkConfig(vSelf); + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTicket_get.sql b/db/routines/hedera/procedures/myTicket_get.sql new file mode 100644 index 000000000..7d203aca6 --- /dev/null +++ b/db/routines/hedera/procedures/myTicket_get.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_get`(vSelf INT) +BEGIN +/** + * Returns a current user ticket header. + * + * @param vSelf The ticket identifier + */ + DECLARE vTaxBase DECIMAL(10,2); + DECLARE vTax DECIMAL(10,2); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + SELECT id ticketFk FROM myTicket + WHERE id = vSelf; + + CALL vn.ticket_getTax(NULL); + + SELECT IFNULL(SUM(taxableBase), 0.0), IFNULL(SUM(tax), 0.0) + INTO vTaxBase, vTax + FROM tmp.ticketAmount; + + SELECT t.id, t.landed, t.shipped, t.refFk, t.nickname, + ag.description agency, m.code method, + a.street, a.postalCode, a.city, p.name province, + vTaxBase taxBase, vTaxBase + vTax AS total + FROM tmp.ticket v + JOIN vn.ticket t ON t.id = v.ticketFk + JOIN vn.address a ON a.id = t.addressFk + 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 = vSelf; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticketTax, + tmp.ticketAmount; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTicket_getPackages.sql b/db/routines/hedera/procedures/myTicket_getPackages.sql new file mode 100644 index 000000000..8ed486dff --- /dev/null +++ b/db/routines/hedera/procedures/myTicket_getPackages.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_getPackages`(vSelf INT) +BEGIN +/** + * Returns a current user ticket packages. + * + * @param vSelf The ticket identifier + * @select The ticket packages + */ + SELECT i.image, im.updated, i.id, i.name, tp.quantity + FROM myTicket t + 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 + LEFT JOIN image im + ON im.collectionFk = 'catalog' + AND im.name = i.image + WHERE t.id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTicket_getRows.sql b/db/routines/hedera/procedures/myTicket_getRows.sql new file mode 100644 index 000000000..0a99ce892 --- /dev/null +++ b/db/routines/hedera/procedures/myTicket_getRows.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_getRows`(vSelf INT) +BEGIN + SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount, + i.category, i.size, i.stems, i.inkFk, + i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7, + i.image, im.updated + FROM myTicketRow r + JOIN vn.item i ON i.id = r.itemFk + LEFT JOIN image im + ON im.collectionFk = 'catalog' + AND im.name = i.image + WHERE r.ticketFk = vSelf + ORDER BY r.concept; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTicket_getServices.sql b/db/routines/hedera/procedures/myTicket_getServices.sql new file mode 100644 index 000000000..56ca52c19 --- /dev/null +++ b/db/routines/hedera/procedures/myTicket_getServices.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_getServices`(vSelf INT) +BEGIN +/** + * Returns a current user ticket services. + * + * @param vSelf The ticket identifier + * @select The ticket services + */ + SELECT id, description, quantity, price + FROM myTicketService + WHERE ticketFk = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTicket_list.sql b/db/routines/hedera/procedures/myTicket_list.sql new file mode 100644 index 000000000..b063ce25c --- /dev/null +++ b/db/routines/hedera/procedures/myTicket_list.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_list`(vFrom DATE, vTo DATE) +BEGIN +/** + * Returns the current user list of tickets between two dates reange. + * Also returns the total price with tax of every ticket. + * + * @param vFrom From date, if %NULL current date minus 25 days + * @param vTo To date, if %NULL current date + * @select The tickets list + */ + SET vFrom = IFNULL(vFrom, DATE_FORMAT(TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()), '%Y-%m-01')); + SET vTo = IFNULL(vTo, TIMESTAMPADD(YEAR, 1, util.VN_CURDATE())); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk + FROM myTicket t + WHERE shipped BETWEEN TIMESTAMP(vFrom) AND TIMESTAMP(vTo, '23:59:59'); + + CALL vn.ticketGetTotal(NULL); + + SELECT v.id, IFNULL(v.landed, v.shipped) landed, + v.shipped, v.companyFk, v.nickname, + a.city, ag.description agency, t.total + FROM tmp.ticket i + JOIN vn.ticket v ON v.id = i.ticketFk + JOIN vn.address a ON a.id = v.addressFk + JOIN vn.agencyMode ag ON ag.id = v.agencyModeFk + JOIN tmp.ticketTotal t ON t.ticketFk = i.ticketFk + ORDER BY IFNULL(v.landed, v.shipped) DESC, i.ticketFk DESC; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticketTotal; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTicket_logAccess.sql b/db/routines/hedera/procedures/myTicket_logAccess.sql new file mode 100644 index 000000000..1dcee8dd6 --- /dev/null +++ b/db/routines/hedera/procedures/myTicket_logAccess.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTicket_logAccess`(vSelf INT) +BEGIN +/** + * Logs an access to a ticket. + * + * @param vSelf The ticket identifier + */ + INSERT INTO vn.ticketLog + (originFk, userFk, `action`, description) + SELECT vSelf, account.myUser_getId(), 'select', 'Accede a ticket' + FROM myTicket t + WHERE t.id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTpvTransaction_end.sql b/db/routines/hedera/procedures/myTpvTransaction_end.sql new file mode 100644 index 000000000..3884f0e37 --- /dev/null +++ b/db/routines/hedera/procedures/myTpvTransaction_end.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTpvTransaction_end`( + vSelf INT, + vStatus VARCHAR(12)) +BEGIN +/** + * See tpvTransaction_start() for more info. + * + * @param vSelf Transaction indentifier + * @param vStatus The status, 'ok' o 'ko' + */ + DECLARE vIsOwned BOOL; + + SELECT COUNT(*) > 0 INTO vIsOwned + FROM myTpvTransaction WHERE id = vSelf; + + IF NOT vIsOwned THEN + CALL util.throw('transactionNotOwnedByUser'); + END IF; + + CALL tpvTransaction_end(vSelf, vStatus); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/myTpvTransaction_start.sql b/db/routines/hedera/procedures/myTpvTransaction_start.sql new file mode 100644 index 000000000..71bae97fa --- /dev/null +++ b/db/routines/hedera/procedures/myTpvTransaction_start.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`myTpvTransaction_start`( + vAmount INT, + vCompany INT) +BEGIN +/** + * See tpvTransaction_start() for more info. + * + * @param vAmount Amount to pay in cents + * @param vCompany The company identifier + */ + CALL tpvTransaction_start(vAmount, vCompany, account.myUser_getId()); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_addItem.sql b/db/routines/hedera/procedures/order_addItem.sql new file mode 100644 index 000000000..d9c15c0eb --- /dev/null +++ b/db/routines/hedera/procedures/order_addItem.sql @@ -0,0 +1,114 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_addItem`( + vSelf INT, + vWarehouse INT, + vItem INT, + vAmount INT) +BEGIN +/** + * Adds an item to the order, checking availability and grouping. + * + * @param vSelf The order id + * @param vWarehouse The warehouse id + * @param vItem The item id + * @param vAmount The amount to add + */ + DECLARE vRow INT; + DECLARE vAdd INT; + DECLARE vAvailable INT; + DECLARE vMinQuantity 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.ticketComponentPrice + WHERE warehouseFk = vWarehouse + AND itemFk = vItem + ORDER BY `grouping` DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + CALL order_calcCatalogFromItem(vSelf, vItem); + START TRANSACTION; + + CALL order_checkEditable(vSelf); + + SELECT shipped INTO vShipment + FROM tmp.zoneGetShipped + WHERE warehouseFk = vWarehouse; + + SELECT IFNULL(available, 0) INTO vAvailable + FROM tmp.ticketLot + WHERE warehouseFk = vWarehouse + AND itemFk = vItem; + + IF vAmount > vAvailable THEN + CALL util.throw ('ORDER_ROW_UNAVAILABLE'); + END IF; + + SELECT IFNULL(minQuantity, 0) INTO vMinQuantity + FROM vn.item + WHERE id = vItem; + + IF vAmount < LEAST(vMinQuantity, vAvailable) THEN + CALL util.throw ('quantityLessThanMin'); + 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 orderRow SET + orderFk = vSelf, + itemFk = vItem, + warehouseFk = vWarehouse, + shipment = vShipment, + rate = vRate, + amount = vAdd, + price = vPrice; + + SET vRow = LAST_INSERT_ID(); + + INSERT INTO orderRowComponent (rowFk, componentFk, price) + SELECT vRow, c.componentFk, c.cost + FROM tmp.ticketComponent c + JOIN vn.component t + ON t.id = c.componentFk + AND (t.classRate IS NULL OR t.classRate = vRate) + WHERE c.warehouseFk = vWarehouse + AND c.itemFk = vItem; + END LOOP; + + CLOSE cur; + + IF vAmount > 0 THEN + CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING'); + END IF; + + COMMIT; + CALL vn.ticketCalculatePurge; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_calcCatalog.sql b/db/routines/hedera/procedures/order_calcCatalog.sql new file mode 100644 index 000000000..53ede1b57 --- /dev/null +++ b/db/routines/hedera/procedures/order_calcCatalog.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_calcCatalog`(vSelf INT) +BEGIN +/** + * Gets the availability and prices for order items. + * + * @param vSelf The order id + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + */ + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + + SELECT date_send, address_id, agency_id + INTO vDate, vAddress, vAgencyMode + FROM `order` + WHERE id = vSelf; + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT itemFk FROM orderRow + WHERE orderFk = vSelf + GROUP BY itemFk; + + CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_calcCatalogFromItem.sql b/db/routines/hedera/procedures/order_calcCatalogFromItem.sql new file mode 100644 index 000000000..517e9dab9 --- /dev/null +++ b/db/routines/hedera/procedures/order_calcCatalogFromItem.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_calcCatalogFromItem`(vSelf INT, vItem INT) +BEGIN +/** + * Gets the availability and prices for the given item + * using the order parameters. + * + * @param vSelf The order id + * @table tmp.item(itemFk) + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + + SELECT date_send, address_id, agency_id + INTO vDate, vAddress, vAgencyMode + FROM `order` + WHERE id = vSelf; + + CALL vn.catalog_calcFromItem(vDate, vAddress, vAgencyMode, vItem); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_calcCatalogFull.sql b/db/routines/hedera/procedures/order_calcCatalogFull.sql new file mode 100644 index 000000000..52d22ba30 --- /dev/null +++ b/db/routines/hedera/procedures/order_calcCatalogFull.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_calcCatalogFull`(vSelf INT) +BEGIN +/** + * Gets the availability and prices for the given items + * using the order parameters. + * + * @param vSelf The order id + * @table tmp.item(itemFk) + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + + SELECT date_send, address_id, agency_id + INTO vDate, vAddress, vAgencyMode + FROM `order` + WHERE id = vSelf; + + CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); + + IF account.myUser_getName() = 'visitor' THEN + UPDATE tmp.ticketCalculateItem + SET price = NULL; + UPDATE tmp.ticketComponent + SET cost = 0; + UPDATE tmp.ticketComponentPrice + SET price = 0, priceKg = NULL; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_checkConfig.sql b/db/routines/hedera/procedures/order_checkConfig.sql new file mode 100644 index 000000000..9dbea1a76 --- /dev/null +++ b/db/routines/hedera/procedures/order_checkConfig.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_checkConfig`(vSelf INT) +BEGIN +/** + * Comprueba que la configuración del pedido es correcta. + * + * @param vSelf Identificador del pedido + */ + DECLARE vDeliveryMethod VARCHAR(255); + DECLARE vLanded DATE; + DECLARE vAgencyMode INT; + DECLARE vAddress INT; + DECLARE vIsAvailable BOOL; + DECLARE vIsActive BOOL; + DECLARE vClientFk INT; + DECLARE vConfigured DATETIME; + + CALL order_checkEditable(vSelf); + + -- Obtiene los datos del pedido + + SELECT d.code, o.date_send, o.agency_id, o.address_id, customer_id, configured + INTO vDeliveryMethod, vLanded, vAgencyMode, vAddress, vClientFk, vConfigured + FROM `order` o + JOIN vn.deliveryMethod d ON d.id = o.delivery_method_id + WHERE o.id = vSelf; + + -- Comprueba que no ha caducado la configuración + + IF vConfigured IS NULL OR vConfigured < TIMESTAMPADD(DAY, -1, util.VN_NOW()) THEN + CALL util.throw('orderOutdated'); + END IF; + + -- Comprueba que se ha seleccionado una dirección + + IF vDeliveryMethod IN ('AGENCY', 'DELIVERY') AND vAddress IS NULL THEN + CALL util.throw ('ORDER_EMPTY_ADDRESS'); + END IF; + + -- Comprueba que el cliente esté activo + + SELECT isActive INTO vIsActive + FROM vn.client + WHERE id = vClientFk; + + IF NOT vIsActive THEN + CALL util.throw ('CLIENT_NOT_ACTIVE'); + END IF; + + -- Comprueba que la agencia es correcta + + CALL vn.zone_getAgency(vAddress, vLanded); + + SELECT COUNT(*) > 0 INTO vIsAvailable + FROM tmp.zoneGetAgency + WHERE agencyModeFk = vAgencyMode; + + IF NOT vIsAvailable THEN + CALL util.throw ('ORDER_INVALID_AGENCY'); + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetAgency; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_checkEditable.sql b/db/routines/hedera/procedures/order_checkEditable.sql new file mode 100644 index 000000000..512e6e6f1 --- /dev/null +++ b/db/routines/hedera/procedures/order_checkEditable.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_checkEditable`(vSelf INT) +BEGIN +/** + * Cheks if order is editable. + * + * @param vSelf The order id + */ + DECLARE vIsConfirmed BOOL; + + SELECT confirmed INTO vIsConfirmed + FROM `order` WHERE id = vSelf; + + IF vIsConfirmed THEN + CALL util.throw('orderConfirmed'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_configure.sql b/db/routines/hedera/procedures/order_configure.sql new file mode 100644 index 000000000..b03acec08 --- /dev/null +++ b/db/routines/hedera/procedures/order_configure.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_configure`( + vSelf INT, + vDelivery DATE, + vDeliveryMethod VARCHAR(45), + vAgency INT, + vAddress INT) +BEGIN +/** + * Creates an order with passed parameters. If passed parameters are wrong + * it returns an error. + * + * @param vSelf The order id + * @param vDelivery Delivery date + * @param vDeliveryMethod Delivery method code + * @param vAgency Agency id + * @param vAddress Address id, @NULL for pickup + */ + 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; + + CALL order_checkEditable(vSelf); + + 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; + + UPDATE `order` + SET date_send = vDelivery, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgency, + address_id = vAddress, + configured = util.VN_NOW() + WHERE + id = vSelf; + + CALL order_update(vSelf); + CALL order_checkConfig(vSelf); + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_confirm.sql b/db/routines/hedera/procedures/order_confirm.sql new file mode 100644 index 000000000..6fd53b4ea --- /dev/null +++ b/db/routines/hedera/procedures/order_confirm.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirm`(vSelf INT) +BEGIN +/** + * Confirms an order, creating each of its tickets on + * the corresponding date and store. + * + * @param vSelf The order identifier + */ + DECLARE vUser INT DEFAULT account.myUser_getId(); + CALL order_confirmWithUser(vSelf, vUser); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_confirmWithUser.sql b/db/routines/hedera/procedures/order_confirmWithUser.sql new file mode 100644 index 000000000..0aeaaf65b --- /dev/null +++ b/db/routines/hedera/procedures/order_confirmWithUser.sql @@ -0,0 +1,296 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirmWithUser`(vSelf INT, vUserId INT) +BEGIN +/** + * Confirms an order, creating each of its tickets on the corresponding + * date, store and user. + * + * @param vSelf The order identifier + * @param vUser The user identifier + */ + DECLARE vOk BOOL; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vWarehouse INT; + DECLARE vShipment DATE; + 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 vPriceFixed DECIMAL(10,2); + DECLARE vDelivery DATE; + DECLARE vAddress INT; + DECLARE vIsConfirmed BOOL; + DECLARE vClientId INT; + DECLARE vCompanyId INT; + DECLARE vAgencyModeId INT; + DECLARE TICKET_FREE INT DEFAULT 2; + DECLARE vCalc INT; + DECLARE vIsLogifloraItem BOOL; + DECLARE vOldQuantity INT; + DECLARE vNewQuantity INT; + DECLARE vIsTaxDataChecked BOOL; + + DECLARE cDates CURSOR FOR + SELECT zgs.shipped, r.warehouse_id + FROM `order` o + JOIN order_row r ON r.order_id = o.id + LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id + WHERE o.id = vSelf AND r.amount != 0 + GROUP BY r.warehouse_id; + + DECLARE cRows CURSOR FOR + SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo + FROM order_row r + JOIN vn.item i ON i.id = r.item_id + WHERE r.amount != 0 + AND r.warehouse_id = vWarehouse + AND r.order_id = vSelf + ORDER BY r.rate DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + -- Carga los datos del pedido + SELECT o.date_send, o.address_id, o.note, a.clientFk, + o.company_id, o.agency_id, c.isTaxDataChecked + INTO vDelivery, vAddress, vNotes, vClientId, + vCompanyId, vAgencyModeId, vIsTaxDataChecked + FROM hedera.`order` o + JOIN vn.address a ON a.id = o.address_id + JOIN vn.client c ON c.id = a.clientFk + WHERE o.id = vSelf; + + -- Verifica si el cliente tiene los datos comprobados + IF NOT vIsTaxDataChecked THEN + CALL util.throw ('clientNotVerified'); + END IF; + + -- Carga las fechas de salida de cada almacen + CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE); + + -- Trabajador que realiza la accion + IF vUserId IS NULL THEN + SELECT employeeFk INTO vUserId FROM orderConfig; + END IF; + + START TRANSACTION; + + CALL order_checkEditable(vSelf); + + -- Check order is not empty + + SELECT COUNT(*) > 0 INTO vOk + FROM order_row WHERE order_id = vSelf AND amount > 0; + + IF NOT vOk THEN + CALL util.throw ('ORDER_EMPTY'); + END IF; + + -- Crea los tickets del pedido + + OPEN cDates; + + lDates: + LOOP + SET vTicket = NULL; + SET vDone = FALSE; + FETCH cDates INTO vShipment, vWarehouse; + + IF vDone THEN + LEAVE lDates; + END IF; + + -- Busca un ticket existente que coincida con los parametros + WITH tPrevia AS + (SELECT DISTINCT s.ticketFk + FROM vn.sale s + JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) + ) + SELECT t.id INTO vTicket + FROM vn.ticket t + LEFT JOIN tPrevia tp ON tp.ticketFk = t.id + LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id + JOIN hedera.`order` o + ON o.address_id = t.addressFk + AND vWarehouse = t.warehouseFk + AND o.date_send = t.landed + AND DATE(t.shipped) = vShipment + WHERE o.id = vSelf + AND t.refFk IS NULL + AND tp.ticketFk IS NULL + AND IFNULL(tls.alertLevel,0) = 0 + LIMIT 1; + + -- Crea el ticket en el caso de no existir uno adecuado + IF vTicket IS NULL + THEN + + SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); + + CALL vn.ticket_add( + vClientId, + vShipment, + vWarehouse, + vCompanyId, + vAddress, + vAgencyModeId, + NULL, + vDelivery, + vUserId, + TRUE, + vTicket + ); + ELSE + INSERT INTO vn.ticketTracking + SET ticketFk = vTicket, + userFk = vUserId, + stateFk = TICKET_FREE; + END IF; + + INSERT IGNORE INTO vn.orderTicket + SET orderFk = vSelf, + ticketFk = vTicket; + + -- Añade las notas + + IF vNotes IS NOT NULL AND vNotes != '' + THEN + INSERT INTO vn.ticketObservation SET + ticketFk = vTicket, + observationTypeFk = 4 /* salesperson */ , + `description` = vNotes + ON DUPLICATE KEY UPDATE + `description` = CONCAT(VALUES(`description`),'. ', `description`); + END IF; + + -- Añade los movimientos y sus componentes + + OPEN cRows; + + lRows: LOOP + SET vDone = FALSE; + FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; + + IF vDone THEN + LEAVE lRows; + END IF; + + SET vSale = NULL; + + SELECT s.id, s.quantity INTO vSale, vOldQuantity + FROM vn.sale s + WHERE ticketFk = vTicket + AND price = vPrice + AND itemFk = vItem + AND discount = 0 + LIMIT 1; + + IF vSale THEN + UPDATE vn.sale + SET quantity = quantity + vAmount, + originalQuantity = quantity + WHERE id = vSale; + + SELECT s.quantity INTO vNewQuantity + FROM vn.sale s + WHERE id = vSale; + ELSE + -- Obtiene el coste + SELECT SUM(rc.`price`) valueSum INTO vPriceFixed + FROM orderRowComponent rc + JOIN vn.component c ON c.id = rc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk AND ct.isBase + WHERE rc.rowFk = vRowId; + + INSERT INTO vn.sale + SET itemFk = vItem, + ticketFk = vTicket, + concept = vConcept, + quantity = vAmount, + price = vPrice, + priceFixed = vPriceFixed, + isPriceFixed = TRUE; + + SET vSale = LAST_INSERT_ID(); + + INSERT INTO vn.saleComponent + (saleFk, componentFk, `value`) + SELECT vSale, rc.componentFk, rc.price + FROM orderRowComponent rc + JOIN vn.component c ON c.id = rc.componentFk + WHERE rc.rowFk = vRowId + GROUP BY vSale, rc.componentFk; + END IF; + + UPDATE order_row SET Id_Movimiento = vSale + WHERE id = vRowId; + + -- Inserta en putOrder si la compra es de Floramondo + IF vIsLogifloraItem THEN + CALL cache.availableNoRaids_refresh(vCalc,FALSE,vWarehouse,vShipment); + + SET @available := 0; + + SELECT GREATEST(0,available) INTO @available + FROM cache.availableNoRaids + WHERE calc_id = vCalc + AND item_id = vItem; + + UPDATE cache.availableNoRaids + SET available = GREATEST(0,available - vAmount) + WHERE item_id = vItem + AND calc_id = vCalc; + + INSERT INTO edi.putOrder ( + deliveryInformationID, + supplyResponseId, + quantity , + EndUserPartyId, + EndUserPartyGLN, + FHAdminNumber, + saleFk + ) + SELECT di.ID, + i.supplyResponseFk, + CEIL((vAmount - @available)/ sr.NumberOfItemsPerCask), + o.address_id , + vClientId, + IFNULL(ca.fhAdminNumber, fhc.defaultAdminNumber), + vSale + FROM edi.deliveryInformation di + JOIN vn.item i ON i.supplyResponseFk = di.supplyResponseID + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientId + JOIN edi.floraHollandConfig fhc + JOIN hedera.`order` o ON o.id = vSelf + WHERE i.id = vItem + AND di.LatestOrderDateTime > util.VN_NOW() + AND vAmount > @available + LIMIT 1; + END IF; + END LOOP; + + CLOSE cRows; + END LOOP; + + CLOSE cDates; + + UPDATE `order` SET confirmed = TRUE, confirm_date = util.VN_NOW() + WHERE id = vSelf; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_doRecalc.sql b/db/routines/hedera/procedures/order_doRecalc.sql new file mode 100644 index 000000000..4c0ee0499 --- /dev/null +++ b/db/routines/hedera/procedures/order_doRecalc.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_doRecalc`() +proc: BEGIN +/** + * Recalculates modified orders. + */ + DECLARE vDone BOOL; + DECLARE vOrderFk INT; + + DECLARE cCur CURSOR FOR + SELECT DISTINCT orderFk FROM tOrder; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('hedera.order_doRecalc'); + ROLLBACK; + RESIGNAL; + END; + + IF !GET_LOCK('hedera.order_doRecalc', 0) THEN + LEAVE proc; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tOrder; + CREATE TEMPORARY TABLE tOrder + ENGINE = MEMORY + SELECT id, orderFk FROM orderRecalc; + + OPEN cCur; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cCur INTO vOrderFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL order_recalc(vOrderFk); + END LOOP; + + CLOSE cCur; + + DELETE o FROM orderRecalc o JOIN tOrder t ON t.id = o.id; + + DROP TEMPORARY TABLE tOrder; + + DO RELEASE_LOCK('hedera.order_doRecalc'); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_getAvailable.sql b/db/routines/hedera/procedures/order_getAvailable.sql new file mode 100644 index 000000000..2b7d60e33 --- /dev/null +++ b/db/routines/hedera/procedures/order_getAvailable.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_getAvailable`(vSelf INT) +BEGIN +/** + * Gets the available items list. + * + * @param vSelf The order id + * @table tmp.itemAvailable + */ + DECLARE vDelivery DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + + SELECT date_send, address_id, agency_id + INTO vDelivery, vAddress, vAgencyMode + FROM `order` + WHERE id = vSelf; + + CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); + + DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable; + CREATE TEMPORARY TABLE tmp.itemAvailable + (INDEX (id)) + ENGINE = MEMORY + SELECT DISTINCT a.item_id id + FROM `cache`.available a + JOIN tmp.availableCalc c ON c.calcFk = a.calc_id + WHERE a.available > 0; + + DROP TEMPORARY TABLE tmp.availableCalc; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_getTax.sql b/db/routines/hedera/procedures/order_getTax.sql new file mode 100644 index 000000000..d24ffe7ef --- /dev/null +++ b/db/routines/hedera/procedures/order_getTax.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_getTax`() + READS SQL DATA +BEGIN +/** + * Calcula el IVA, y el recargo de equivalencia de un pedido + * desglosados por tipos. + * + * @param vOrder El identificador del pedido + * @return 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, `code`, + SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax + FROM tmp.orderTax + GROUP BY orderFk, `code`; + + DROP TEMPORARY TABLE tmp.addressTaxArea; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_getTotal.sql b/db/routines/hedera/procedures/order_getTotal.sql new file mode 100644 index 000000000..c0b8d40ae --- /dev/null +++ b/db/routines/hedera/procedures/order_getTotal.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_getTotal`() +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 orden + */ + CALL order_getTax; + + 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 + tmp.orderTax, + tmp.orderAmount; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_recalc.sql b/db/routines/hedera/procedures/order_recalc.sql new file mode 100644 index 000000000..1398b49f6 --- /dev/null +++ b/db/routines/hedera/procedures/order_recalc.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_recalc`(vSelf INT) +BEGIN +/** + * Recalculates the order total. + * + * @param vSelf The order id + */ + DECLARE vTaxableBase DECIMAL(10,2); + DECLARE vTax DECIMAL(10,2); + + DROP TEMPORARY TABLE IF EXISTS tmp.`order`; + CREATE TEMPORARY TABLE tmp.`order` + ENGINE = MEMORY + SELECT vSelf orderFk; + + CALL order_getTax; + + SELECT IFNULL(SUM(taxableBase), 0.0), IFNULL(SUM(tax), 0.0) + INTO vTaxableBase, vTax + FROM tmp.orderAmount; + + UPDATE `order` + SET taxableBase = vTaxableBase, + tax = vTax, + total = vTaxableBase + vTax + WHERE id = vSelf; + + DROP TEMPORARY TABLE + tmp.`order`, + tmp.orderTax; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_requestRecalc.sql b/db/routines/hedera/procedures/order_requestRecalc.sql new file mode 100644 index 000000000..4bcb1010e --- /dev/null +++ b/db/routines/hedera/procedures/order_requestRecalc.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_requestRecalc`(vSelf INT) +proc: BEGIN +/** + * Adds a request to recalculate the order total. + * + * @param vSelf The order identifier + */ + IF vSelf IS NULL THEN + LEAVE proc; + END IF; + + INSERT INTO orderRecalc SET orderFk = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/order_update.sql b/db/routines/hedera/procedures/order_update.sql new file mode 100644 index 000000000..207cad09f --- /dev/null +++ b/db/routines/hedera/procedures/order_update.sql @@ -0,0 +1,67 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_update`(vSelf INT) +proc: BEGIN +/** + * Actualiza las líneas de un pedido. + * + * @param vSelf Id del pedido + */ + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + DECLARE vNRows INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT COUNT(*) INTO vNRows + FROM orderRow WHERE orderFk = vSelf; + + IF vNRows > 0 + THEN + CALL order_calcCatalog(vSelf); + + DELETE c + FROM orderRow r + JOIN orderRowComponent c ON c.rowFk = r.id + WHERE r.orderFk = vSelf; + + UPDATE orderRow r + LEFT JOIN tmp.ticketComponentPrice p + ON p.warehouseFk = r.warehouseFk + AND p.itemFk = r.itemFk + AND p.rate = r.rate + LEFT JOIN tmp.zoneGetShipped t + ON t.warehouseFk = r.warehouseFk + SET + r.price = p.price, + r.amount = IF(p.itemFk IS NOT NULL, + r.amount + IF(@m := MOD(r.amount, p.`grouping`), p.`grouping` - @m, 0), 0), + r.shipment = t.shipped + WHERE r.orderFk = vSelf; + + INSERT INTO orderRowComponent(rowFk, componentFk, price) + SELECT r.id, c.componentFk, c.cost + FROM orderRow r + JOIN tmp.ticketComponent c + ON c.warehouseFk = r.warehouseFk + AND c.itemFk = r.itemFk + JOIN vn.component t + ON t.id = c.componentFk + AND (t.classRate IS NULL OR t.classRate = r.rate) + WHERE r.orderFk = vSelf; + + CALL vn.ticketCalculatePurge; + END IF; + + UPDATE `order` SET date_make = util.VN_NOW() + WHERE id = vSelf; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/survey_vote.sql b/db/routines/hedera/procedures/survey_vote.sql new file mode 100644 index 000000000..46c31393a --- /dev/null +++ b/db/routines/hedera/procedures/survey_vote.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`survey_vote`(vAnswer INT) +BEGIN + DECLARE vSurvey INT; + DECLARE vCount TINYINT; + DECLARE EXIT HANDLER FOR 1062 + CALL util.throw('You cannot vote twice to the same survey'); + + SELECT durveyFk INTO vSurvey + FROM surveyAnswer WHERE id = vAnswer; + + INSERT INTO surveyVote SET + surveyFk = vSurvey, + userFk = account.myUser_getId(); + + UPDATE surveyAnswer SET votes = votes + 1 + WHERE id = vAnswer; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/tpvTransaction_confirm.sql b/db/routines/hedera/procedures/tpvTransaction_confirm.sql new file mode 100644 index 000000000..e4a8c932f --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_confirm.sql @@ -0,0 +1,112 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_confirm`( + vAmount INT + ,vOrder INT + ,vMerchant INT + ,vCurrency INT + ,vResponse INT + ,vErrorCode VARCHAR(10) +) +BEGIN +/** + * Confirma una transacción previamente iniciada, reescribiendo + * sus datos por los confirmados por el banco (solo si estos difieren). + * Genera el recibo y su correspondiente entrada en caja. + * + * @param vAmount Cantidad confirmada + * @param vOrder Identificador de transacción + * @param vMerchant Identificador de comercio + * @param vCurrency Identificador de moneda + * @param vResponse Identificador de respuesta del banco + * @param vErrorCode Código de error del banco, si lo hubiera + */ + DECLARE vReceipt INT; + DECLARE vStatus VARCHAR(10); + DECLARE vCustomer INT; + DECLARE vBank INT; + DECLARE vCompany INT; + DECLARE vEmployee INT; + DECLARE vIsDuplicated BOOLEAN; + DECLARE vDate DATE; + DECLARE vConcept VARCHAR(25) DEFAULT 'Cobro Web'; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT COUNT(*) > 0 INTO vIsDuplicated + FROM tpvTransaction + WHERE id = vOrder AND response IS NOT NULL + FOR UPDATE; + + IF vIsDuplicated THEN + CALL util.throw('Transaction already confirmed'); + END IF; + + IF vResponse BETWEEN 0 AND 99 THEN + SELECT + t.clientFk + ,m.bankFk + ,m.companyFk + ,c.employeeFk + ,DATE(t.created) + INTO + vCustomer + ,vBank + ,vCompany + ,vEmployee + ,vDate + FROM tpvMerchant m + JOIN tpvConfig c + LEFT JOIN tpvTransaction t ON t.id = vOrder + WHERE m.id = vMerchant; + + INSERT INTO vn.receipt + SET + amountPaid = vAmount / 100 + ,payed = vDate + ,workerFk = vEmployee + ,bankFk = vBank + ,clientFk = vCustomer + ,companyFk = vCompany + ,invoiceFk = vConcept + ,isConciliate = TRUE; + + SET vReceipt = LAST_INSERT_ID(); + SET vStatus = 'ok'; + + -- Código redundante + + DO vn.till_new( + vCustomer + ,vBank + ,vAmount / 100 + ,vConcept + ,vDate + ,'A' + ,TRUE + ,vCustomer + ,vCompany + ,vEmployee + ); + ELSE + SET vReceipt = NULL; + SET vStatus = 'ko'; + END IF; + + UPDATE tpvTransaction + SET merchantFk = vMerchant + ,receiptFk = vReceipt + ,amount = vAmount + ,response = vResponse + ,errorCode = vErrorCode + ,status = vStatus + WHERE id = vOrder; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/tpvTransaction_confirmAll.sql b/db/routines/hedera/procedures/tpvTransaction_confirmAll.sql new file mode 100644 index 000000000..b6a71af01 --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_confirmAll.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_confirmAll`(vDate DATE) +BEGIN +/** + * Confirma todas las transacciones confirmadas por el cliente pero no + * por el banco para una fecha dada. + * + * @param vDate Fecha deseada + */ + DECLARE vOrder INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; + DECLARE vDateIni DATETIME DEFAULT TIMESTAMP(vDate, '00:00:00'); + DECLARE vDateEnd DATETIME DEFAULT TIMESTAMP(vDate, '23:59:59'); + + DECLARE cTransactions CURSOR FOR + SELECT id + FROM tpvTransaction + WHERE created BETWEEN vDateIni AND vDateEnd + AND status = 'ok' + AND response IS NULL; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cTransactions; + + l: LOOP + FETCH cTransactions INTO vOrder; + + IF vDone THEN + LEAVE l; + END IF; + + CALL tpvTransaction_confirmById (vOrder); + END LOOP l; + + CLOSE cTransactions; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/tpvTransaction_confirmById.sql b/db/routines/hedera/procedures/tpvTransaction_confirmById.sql new file mode 100644 index 000000000..7cbdb65c6 --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_confirmById.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_confirmById`(vOrder INT) +BEGIN +/** + * Confirma manualmente una transacción espedificando su identificador. + * + * @param vOrder Identificador de la transacción + */ + DECLARE vAmount INT; + DECLARE vMerchant INT; + DECLARE vCurrency INT; + + SELECT amount, merchantFk, currency + INTO vAmount, vMerchant, vCurrency + FROM tpvTransaction t + JOIN tpvMerchant m ON m.id = t.merchantFk + JOIN tpvConfig c + WHERE t.id = vOrder; + + CALL tpvTransaction_confirm( + vAmount + ,vOrder + ,vMerchant + ,vCurrency + ,0 + ,NULL + ); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/tpvTransaction_confirmFromExport.sql b/db/routines/hedera/procedures/tpvTransaction_confirmFromExport.sql new file mode 100644 index 000000000..7ca0e44e2 --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_confirmFromExport.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_confirmFromExport`() +BEGIN +/** + * Confirms multiple transactions comming from Redsys "canales" exported CSV. + * + * @table tmp.transactions(id, isAuthorization, amount) The list of exported transactions + */ + DECLARE vDone BOOL; + DECLARE vTransactionId INT; + DECLARE vAmount INT; + DECLARE vConfirmedAmount INT; + + DECLARE cur CURSOR FOR + SELECT * FROM tPendingTransactions; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tPendingTransactions + ENGINE = MEMORY + SELECT t.id, t.amount, tt.amount confirmedAmount + FROM tmp.transactions t + JOIN hedera.tpvTransaction tt ON tt.id = t.id + WHERE t.isAuthorization + AND tt.response IS NULL; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vTransactionId, vAmount, vConfirmedAmount; + + IF vDone THEN + LEAVE l; + END IF; + + IF NOT (vAmount <=> vConfirmedAmount) THEN + CALL util.throw(CONCAT( + 'Transaction ', vTransactionId ,', source amount "', vAmount , + '" does not match confirmed amount "', vConfirmedAmount ,'"' + )); + END IF; + + CALL tpvTransaction_confirmById(vTransactionId); + END LOOP; + + CLOSE cur; + + SELECT id, amount FROM tPendingTransactions; + + DROP TEMPORARY TABLE tPendingTransactions; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/tpvTransaction_end.sql b/db/routines/hedera/procedures/tpvTransaction_end.sql new file mode 100644 index 000000000..ec0a0224d --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_end.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_end`( + vSelf INT, + vStatus VARCHAR(12)) +BEGIN +/** + * Ends a transaction by setting its status to 'ok' or 'ko' depending on + * if this has been done correctly. + * This procedure must be called directly by the client when the transaction + * ends, it is only valid until the arrival of the definitive notification from + * the payment platform. + * + * @param vSelf Transaction indentifier + * @param vStatus The status, 'ok' o 'ko' + */ + IF vStatus IN ('ok', 'ko') THEN + UPDATE tpvTransaction SET `status` = vStatus + WHERE id = vSelf AND response IS NULL; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/tpvTransaction_start.sql b/db/routines/hedera/procedures/tpvTransaction_start.sql new file mode 100644 index 000000000..55fd922da --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_start.sql @@ -0,0 +1,71 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_start`( + vAmount INT, + vCompany INT, + vUser INT) +BEGIN +/** + * Start a new transaction with the virtual TPV, generating an identifier + * of transaction and returning the parameters that should be sent to the + * payment platform. + * + * @param vAmount Amount to pay in cents + * @param vCompany The company identifier + * @select Parameters that will be sent to payment platform + */ + DECLARE vSelf CHAR(12); + DECLARE vMerchant INT; + DECLARE vUrl VARCHAR(255); + DECLARE vKey VARCHAR(50); + DECLARE vEnvironment VARCHAR(255); + + 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 environment INTO vEnvironment + FROM util.config; + + IF vEnvironment = 'production' 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 tpvTransaction + SET merchantFk = vMerchant, + clientFk = vUser, + 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 ; diff --git a/db/routines/hedera/procedures/tpvTransaction_undo.sql b/db/routines/hedera/procedures/tpvTransaction_undo.sql new file mode 100644 index 000000000..ed72dd76d --- /dev/null +++ b/db/routines/hedera/procedures/tpvTransaction_undo.sql @@ -0,0 +1,81 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`tpvTransaction_undo`(vSelf INT) +p: BEGIN + DECLARE vCustomer INT; + DECLARE vAmount DOUBLE; + DECLARE vReceipt INT; + DECLARE vDate DATE; + DECLARE vBank INT; + DECLARE vAccount VARCHAR(12); + DECLARE vSubaccount VARCHAR(12); + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT + t.clientFk + ,t.amount / 100 + ,t.receiptFk + ,DATE(t.created) + ,m.bankFk + INTO + vCustomer + ,vAmount + ,vReceipt + ,vDate + ,vBank + FROM tpvTransaction t + JOIN tpvMerchant m ON m.id = t.merchantFk + JOIN tpvConfig c + WHERE t.id = vSelf + FOR UPDATE; + + -- Elimina el recibo + + DELETE FROM vn.receipt + WHERE id = vReceipt LIMIT 1; + + -- Elimina la entrada de cajas + + DELETE FROM vn.till + WHERE bankFk = vBank + AND DATE(dated) = vDate + AND `in` = vAmount + LIMIT 1; + + -- Elimina los asientos contables + + SELECT accountingAccount INTO vSubaccount + FROM vn.`client` WHERE id = vCustomer; + + SELECT account INTO vAccount + FROM vn.bank WHERE id = vBank; + + DELETE FROM vn.XDiario + WHERE SUBCTA = vSubaccount + AND CONTRA = vAccount + AND DATE(FECHA) = vDate + AND EUROHABER = vAmount + LIMIT 1; + + DELETE FROM vn.XDiario + WHERE CONTRA = vSubaccount + AND SUBCTA = vAccount + AND DATE(FECHA) = vDate + AND EURODEBE = vAmount + LIMIT 1; + + -- Actualiza la transaccion + + UPDATE tpvTransaction + SET response = NULL, status = 'started' + WHERE id = vSelf; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/visitUser_new.sql b/db/routines/hedera/procedures/visitUser_new.sql new file mode 100644 index 000000000..3c299f209 --- /dev/null +++ b/db/routines/hedera/procedures/visitUser_new.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`visitUser_new`( + vAccess INT + ,vSsid VARCHAR(64) +) +BEGIN + DECLARE vUserVisit INT; + + INSERT INTO visitUser SET + accessFk = vAccess, + userFk = account.myUser_getId(); + + SET vUserVisit = LAST_INSERT_ID(); + + UPDATE userSession SET userVisitFk = vUserVisit + WHERE ssid = vSsid; + + DELETE FROM userSession + WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, util.VN_NOW()); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/visit_listByBrowser.sql b/db/routines/hedera/procedures/visit_listByBrowser.sql new file mode 100644 index 000000000..2fa45b8f2 --- /dev/null +++ b/db/routines/hedera/procedures/visit_listByBrowser.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`visit_listByBrowser`(vFrom DATE, vTo DATE) +BEGIN +/** + * Lists visits grouped by browser. + * + * @param vFrom The from date + * @param vTo The to date + * @select The list of visits + */ + SELECT browser, + MIN(CAST(version AS DECIMAL(4, 1))) minVersion, + MAX(CAST(version AS DECIMAL(4, 1))) maxVersion, + MAX(c.stamp) lastVisit, + COUNT(DISTINCT c.id) visits, + SUM(a.firstAccessFk = c.id AND v.firstAgentFk = a.id) newVisits + FROM visitUser e + JOIN visitAccess c ON c.id = e.accessFk + JOIN visitAgent a ON a.id = c.agentFk + JOIN visit v ON v.id = a.visitFk + WHERE c.stamp BETWEEN TIMESTAMP(vFrom,'00:00:00') AND TIMESTAMP(vTo,'23:59:59') + GROUP BY browser ORDER BY visits DESC; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/visit_register.sql b/db/routines/hedera/procedures/visit_register.sql new file mode 100644 index 000000000..80b6f16a9 --- /dev/null +++ b/db/routines/hedera/procedures/visit_register.sql @@ -0,0 +1,75 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`visit_register`( + vVisit INT + ,vPlatform VARCHAR(30) + ,vBrowser VARCHAR(30) + ,vVersion VARCHAR(15) + ,vJavascript TINYINT + ,vCookies TINYINT + ,vAgent VARCHAR(255) + ,vIp INT + ,vReferer VARCHAR(255) +) +BEGIN + DECLARE vFirstVisit TINYINT DEFAULT FALSE; + DECLARE vFirstAgent TINYINT DEFAULT FALSE; + DECLARE vAgentId INT DEFAULT NULL; + DECLARE vAccessId INT DEFAULT NULL; + + -- Registers the visit + + IF vVisit IS NULL || (SELECT COUNT(*) FROM visit WHERE id = vVisit) = 0 + THEN + INSERT INTO visit SET id = DEFAULT; + SET vVisit = LAST_INSERT_ID(); + SET vFirstVisit = TRUE; + END IF; + + SELECT id INTO vAgentId FROM visitAgent + WHERE visitFk = vVisit + AND (agent = vAgent OR (vAgent IS NULL AND agent IS NULL)) + LIMIT 1; + + -- Registers the user agent + + IF vAgentId IS NULL + THEN + INSERT INTO visitAgent SET + visitFk = vVisit + ,platform = vPlatform + ,browser = vBrowser + ,version = vVersion + ,javascript = vJavascript + ,cookies = vCookies + ,agent = vAgent; + + SET vAgentId = LAST_INSERT_ID(); + SET vFirstAgent = TRUE; + END IF; + + IF vFirstVisit + THEN + UPDATE visit SET firstAgentFk = vAgentId + WHERE id = vVisit; + END IF; + + -- Registers the user access + + INSERT INTO visitAccess SET + agentFk = vAgentId + ,ip = vIp + ,referer = vReferer; + + SET vAccessId = LAST_INSERT_ID(); + + IF vFirstAgent + THEN + UPDATE visitAgent SET firstAccessFk = vAccessId + WHERE id = vAgentId; + END IF; + + -- Returns the visit info + + SELECT vVisit visit, vAccessId access; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/link_afterDelete.sql b/db/routines/hedera/triggers/link_afterDelete.sql new file mode 100644 index 000000000..571540cba --- /dev/null +++ b/db/routines/hedera/triggers/link_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`link_afterDelete` + AFTER DELETE ON `link` + FOR EACH ROW +BEGIN + CALL image_unref('link', OLD.image); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/link_afterInsert.sql b/db/routines/hedera/triggers/link_afterInsert.sql new file mode 100644 index 000000000..e3f163a9e --- /dev/null +++ b/db/routines/hedera/triggers/link_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`link_afterInsert` + AFTER INSERT ON `link` + FOR EACH ROW +BEGIN + CALL image_ref('link', NEW.image); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/link_afterUpdate.sql b/db/routines/hedera/triggers/link_afterUpdate.sql new file mode 100644 index 000000000..7ffe2a335 --- /dev/null +++ b/db/routines/hedera/triggers/link_afterUpdate.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`link_afterUpdate` + AFTER UPDATE ON `link` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL image_unref('link', OLD.image); + CALL image_ref('link', NEW.image); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/news_afterDelete.sql b/db/routines/hedera/triggers/news_afterDelete.sql new file mode 100644 index 000000000..07a0403e0 --- /dev/null +++ b/db/routines/hedera/triggers/news_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`news_afterDelete` + AFTER DELETE ON `news` + FOR EACH ROW +BEGIN + CALL image_unref('news', OLD.image); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/news_afterInsert.sql b/db/routines/hedera/triggers/news_afterInsert.sql new file mode 100644 index 000000000..61e6078ef --- /dev/null +++ b/db/routines/hedera/triggers/news_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`news_afterInsert` + AFTER INSERT ON `news` + FOR EACH ROW +BEGIN + CALL image_ref('news', NEW.image); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/news_afterUpdate.sql b/db/routines/hedera/triggers/news_afterUpdate.sql new file mode 100644 index 000000000..15ea32f1d --- /dev/null +++ b/db/routines/hedera/triggers/news_afterUpdate.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`news_afterUpdate` + AFTER UPDATE ON `news` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL image_unref('news', OLD.image); + CALL image_ref('news', NEW.image); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/orderRow_afterDelete.sql b/db/routines/hedera/triggers/orderRow_afterDelete.sql new file mode 100644 index 000000000..10b5ae9e3 --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_afterDelete.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterDelete` + AFTER DELETE ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NULL, OLD.id); + CALL order_requestRecalc(OLD.orderFk); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/orderRow_afterInsert.sql b/db/routines/hedera/triggers/orderRow_afterInsert.sql new file mode 100644 index 000000000..7e8d5f341 --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_afterInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert` + AFTER INSERT ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NEW.id, NULL); + CALL order_requestRecalc(NEW.orderFk); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/orderRow_afterUpdate.sql b/db/routines/hedera/triggers/orderRow_afterUpdate.sql new file mode 100644 index 000000000..33f4ae84e --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_afterUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterUpdate` + AFTER UPDATE ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NEW.id, OLD.id); + CALL order_requestRecalc(OLD.orderFk); + CALL order_requestRecalc(NEW.orderFk); +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/orderRow_beforeInsert.sql b/db/routines/hedera/triggers/orderRow_beforeInsert.sql new file mode 100644 index 000000000..0c9f31bab --- /dev/null +++ b/db/routines/hedera/triggers/orderRow_beforeInsert.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_beforeInsert` + BEFORE INSERT ON `orderRow` + FOR EACH ROW +BEGIN + DECLARE vIsFirst BOOL; + + SELECT (first_row_stamp IS NULL) INTO vIsFirst + FROM `order` + WHERE id = NEW.orderFk; + + IF vIsFirst THEN + UPDATE `order` SET first_row_stamp = util.VN_NOW() + WHERE id = NEW.orderFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/order_afterInsert.sql b/db/routines/hedera/triggers/order_afterInsert.sql new file mode 100644 index 000000000..2fe83ee8f --- /dev/null +++ b/db/routines/hedera/triggers/order_afterInsert.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`order_afterInsert` + AFTER INSERT ON `order` + FOR EACH ROW +BEGIN + IF NEW.address_id = 2850 THEN + -- Fallo que se insertan no se sabe como tickets en este cliente + CALL vn.mail_insert( + 'jgallego@verdnatura.es', + 'noreply@verdnatura.es', + 'Creada order al address 2850', + CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) + ); + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/order_afterUpdate.sql b/db/routines/hedera/triggers/order_afterUpdate.sql new file mode 100644 index 000000000..a4549549a --- /dev/null +++ b/db/routines/hedera/triggers/order_afterUpdate.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`order_afterUpdate` + AFTER UPDATE ON `order` + FOR EACH ROW +BEGIN + CALL stock.log_add('order', NEW.id, OLD.id); + + IF !(OLD.address_id <=> NEW.address_id) + OR !(OLD.company_id <=> NEW.company_id) + OR !(OLD.customer_id <=> NEW.customer_id) THEN + CALL order_requestRecalc(NEW.id); + END IF; + + IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN + -- Fallo que se actualiza no se sabe como tickets en este cliente + CALL vn.mail_insert( + 'jgallego@verdnatura.es', + 'noreply@verdnatura.es', + 'Actualizada order al address 2850', + CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) + ); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/triggers/order_beforeDelete.sql b/db/routines/hedera/triggers/order_beforeDelete.sql new file mode 100644 index 000000000..eb602be89 --- /dev/null +++ b/db/routines/hedera/triggers/order_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`order_beforeDelete` + BEFORE DELETE ON `order` + FOR EACH ROW +BEGIN + DELETE FROM orderRow WHERE orderFk = OLD.id; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/views/mainAccountBank.sql b/db/routines/hedera/views/mainAccountBank.sql new file mode 100644 index 000000000..3130a1614 --- /dev/null +++ b/db/routines/hedera/views/mainAccountBank.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`mainAccountBank` +AS SELECT `e`.`name` AS `name`, + `a`.`iban` AS `iban` +FROM ( + ( + `hedera`.`mainAccount` `c` + JOIN `vn`.`supplierAccount` `a` ON(`a`.`id` = `c`.`accountFk`) + ) + JOIN `vn`.`bankEntity` `e` ON(`e`.`id` = `a`.`bankEntityFk`) + ) diff --git a/db/routines/hedera/views/messageL10n.sql b/db/routines/hedera/views/messageL10n.sql new file mode 100644 index 000000000..6488de6a9 --- /dev/null +++ b/db/routines/hedera/views/messageL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`messageL10n` +AS SELECT `m`.`code` AS `code`, + IFNULL(`mi`.`description`, `m`.`description`) AS `description` +FROM ( + `hedera`.`message` `m` + LEFT JOIN `hedera`.`messageI18n` `mi` ON( + `mi`.`code` = `m`.`code` + AND `mi`.`lang` = `util`.`LANG`() + ) + ) diff --git a/db/routines/hedera/views/myAddress.sql b/db/routines/hedera/views/myAddress.sql new file mode 100644 index 000000000..ee8d87759 --- /dev/null +++ b/db/routines/hedera/views/myAddress.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myAddress` +AS SELECT `t`.`id` AS `id`, + `t`.`clientFk` AS `clientFk`, + `t`.`street` AS `street`, + `t`.`city` AS `city`, + `t`.`postalCode` AS `postalCode`, + `t`.`provinceFk` AS `provinceFk`, + `t`.`nickname` AS `nickname`, + `t`.`isDefaultAddress` AS `isDefaultAddress`, + `t`.`isActive` AS `isActive`, + `t`.`longitude` AS `longitude`, + `t`.`latitude` AS `latitude`, + `t`.`agencyModeFk` AS `agencyModeFk` +FROM `vn`.`address` `t` +WHERE `t`.`clientFk` = `account`.`myUser_getId`() +WITH CASCADED CHECK OPTION diff --git a/db/routines/hedera/views/myBasketDefaults.sql b/db/routines/hedera/views/myBasketDefaults.sql new file mode 100644 index 000000000..475212da1 --- /dev/null +++ b/db/routines/hedera/views/myBasketDefaults.sql @@ -0,0 +1,26 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myBasketDefaults` +AS SELECT coalesce(`dm`.`code`, `cm`.`code`) AS `deliveryMethod`, + coalesce(`ad`.`agencyModeFk`, `oc`.`defaultAgencyFk`) AS `agencyModeFk`, + `c`.`defaultAddressFk` AS `addressFk`, + `oc`.`defaultAgencyFk` AS `defaultAgencyFk` +FROM ( + ( + ( + ( + ( + ( + `hedera`.`orderConfig` `oc` + JOIN `vn`.`agencyMode` `ca` ON(`ca`.`id` = `oc`.`defaultAgencyFk`) + ) + JOIN `vn`.`deliveryMethod` `cm` ON(`cm`.`id` = `ca`.`deliveryMethodFk`) + ) + LEFT JOIN `vn`.`client` `c` ON(`c`.`id` = `account`.`myUser_getId`()) + ) + LEFT JOIN `vn`.`address` `ad` ON(`ad`.`id` = `c`.`defaultAddressFk`) + ) + LEFT JOIN `vn`.`agencyMode` `a` ON(`a`.`id` = `ad`.`agencyModeFk`) + ) + LEFT JOIN `vn`.`deliveryMethod` `dm` ON(`dm`.`id` = `a`.`deliveryMethodFk`) + ) diff --git a/db/routines/hedera/views/myClient.sql b/db/routines/hedera/views/myClient.sql new file mode 100644 index 000000000..ef7159549 --- /dev/null +++ b/db/routines/hedera/views/myClient.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myClient` +AS SELECT `c`.`id` AS `id`, + `c`.`isToBeMailed` AS `isToBeMailed`, + `c`.`defaultAddressFk` AS `defaultAddressFk`, + `c`.`credit` AS `credit` +FROM `vn`.`client` `c` +WHERE `c`.`id` = `account`.`myUser_getId`() +WITH CASCADED CHECK OPTION diff --git a/db/routines/hedera/views/myInvoice.sql b/db/routines/hedera/views/myInvoice.sql new file mode 100644 index 000000000..dd1a917ad --- /dev/null +++ b/db/routines/hedera/views/myInvoice.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myInvoice` +AS SELECT `i`.`id` AS `id`, + `i`.`ref` AS `ref`, + `i`.`issued` AS `issued`, + `i`.`amount` AS `amount`, + `i`.`hasPdf` AS `hasPdf` +FROM `vn`.`invoiceOut` `i` +WHERE `i`.`clientFk` = `account`.`myUser_getId`() diff --git a/db/routines/hedera/views/myMenu.sql b/db/routines/hedera/views/myMenu.sql new file mode 100644 index 000000000..94e58835d --- /dev/null +++ b/db/routines/hedera/views/myMenu.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myMenu` +AS SELECT `t`.`id` AS `id`, + `t`.`path` AS `path`, + `t`.`description` AS `description`, + `t`.`parentFk` AS `parentFk` +FROM ( + `hedera`.`menu` `t` + JOIN `account`.`myRole` `r` ON(`r`.`id` = `t`.`roleFk`) + ) +ORDER BY `t`.`parentFk`, + `t`.`displayOrder`, + `t`.`id` diff --git a/db/routines/hedera/views/myOrder.sql b/db/routines/hedera/views/myOrder.sql new file mode 100644 index 000000000..78becd884 --- /dev/null +++ b/db/routines/hedera/views/myOrder.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myOrder` +AS SELECT `o`.`id` AS `id`, + `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`, + `o`.`source_app` AS `sourceApp`, + `o`.`confirmed` AS `isConfirmed`, + `o`.`date_make` AS `created`, + `o`.`first_row_stamp` AS `firstRowStamp`, + `o`.`confirm_date` AS `confirmed`, + `o`.`taxableBase` AS `taxableBase`, + `o`.`tax` AS `tax`, + `o`.`total` AS `total` +FROM `hedera`.`order` `o` +WHERE `o`.`customer_id` = `account`.`myUser_getId`() + AND `o`.`source_app` = 'WEB' + AND `o`.`confirmed` = 0 +WITH CASCADED CHECK OPTION diff --git a/db/routines/hedera/views/myOrderRow.sql b/db/routines/hedera/views/myOrderRow.sql new file mode 100644 index 000000000..af42b0745 --- /dev/null +++ b/db/routines/hedera/views/myOrderRow.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myOrderRow` +AS SELECT `orw`.`id` AS `id`, + `orw`.`order_id` AS `orderFk`, + `orw`.`item_id` AS `itemFk`, + `orw`.`warehouse_id` AS `warehouseFk`, + `orw`.`shipment` AS `shipped`, + `orw`.`amount` AS `amount`, + `orw`.`price` AS `price`, + `orw`.`rate` AS `rate`, + `orw`.`created` AS `created`, + `orw`.`Id_Movimiento` AS `saleFk` +FROM `hedera`.`order_row` `orw` +WHERE `orw`.`order_id` IN ( + SELECT `myOrder`.`id` + FROM `hedera`.`myOrder` + ) +WITH CASCADED CHECK OPTION diff --git a/db/routines/hedera/views/myOrderTicket.sql b/db/routines/hedera/views/myOrderTicket.sql new file mode 100644 index 000000000..fa8220b55 --- /dev/null +++ b/db/routines/hedera/views/myOrderTicket.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myOrderTicket` +AS SELECT `o`.`id` AS `orderFk`, + `ot`.`ticketFk` AS `ticketFk` +FROM ( + `hedera`.`myOrder` `o` + JOIN `hedera`.`orderTicket` `ot` ON(`ot`.`orderFk` = `o`.`id`) + ) diff --git a/db/routines/hedera/views/myTicket.sql b/db/routines/hedera/views/myTicket.sql new file mode 100644 index 000000000..f17cda9a4 --- /dev/null +++ b/db/routines/hedera/views/myTicket.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myTicket` +AS SELECT `t`.`id` AS `id`, + `t`.`clientFk` AS `clientFk`, + `t`.`warehouseFk` AS `warehouseFk`, + `t`.`shipped` AS `shipped`, + `t`.`landed` AS `landed`, + `t`.`nickname` AS `nickname`, + `t`.`agencyModeFk` AS `agencyModeFk`, + `t`.`refFk` AS `refFk`, + `t`.`addressFk` AS `addressFk`, + `t`.`location` AS `location`, + `t`.`companyFk` AS `companyFk` +FROM `vn`.`ticket` `t` +WHERE `t`.`clientFk` = `account`.`myUser_getId`() diff --git a/db/routines/hedera/views/myTicketRow.sql b/db/routines/hedera/views/myTicketRow.sql new file mode 100644 index 000000000..5afff812b --- /dev/null +++ b/db/routines/hedera/views/myTicketRow.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myTicketRow` +AS SELECT `s`.`id` AS `id`, + `s`.`itemFk` AS `itemFk`, + `s`.`ticketFk` AS `ticketFk`, + `s`.`concept` AS `concept`, + `s`.`quantity` AS `quantity`, + `s`.`price` AS `price`, + `s`.`discount` AS `discount`, + `s`.`reserved` AS `reserved`, + `s`.`isPicked` AS `isPicked` +FROM ( + `vn`.`sale` `s` + JOIN `hedera`.`myTicket` `t` ON(`s`.`ticketFk` = `t`.`id`) + ) +WITH CASCADED CHECK OPTION diff --git a/db/routines/hedera/views/myTicketService.sql b/db/routines/hedera/views/myTicketService.sql new file mode 100644 index 000000000..feb839873 --- /dev/null +++ b/db/routines/hedera/views/myTicketService.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myTicketService` +AS SELECT `s`.`id` AS `id`, + `s`.`description` AS `description`, + `s`.`quantity` AS `quantity`, + `s`.`price` AS `price`, + `s`.`taxClassFk` AS `taxClassFk`, + `s`.`ticketFk` AS `ticketFk`, + `s`.`ticketServiceTypeFk` AS `ticketServiceTypeFk` +FROM ( + `vn`.`ticketService` `s` + JOIN `hedera`.`myTicket` `t` ON(`s`.`ticketFk` = `t`.`id`) + ) +WITH CASCADED CHECK OPTION diff --git a/db/routines/hedera/views/myTicketState.sql b/db/routines/hedera/views/myTicketState.sql new file mode 100644 index 000000000..530441e3b --- /dev/null +++ b/db/routines/hedera/views/myTicketState.sql @@ -0,0 +1,21 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myTicketState` +AS SELECT `t`.`id` AS `id`, + `t`.`clientFk` AS `clientFk`, + `t`.`warehouseFk` AS `warehouseFk`, + `t`.`shipped` AS `shipped`, + `t`.`landed` AS `landed`, + `t`.`nickname` AS `nickname`, + `t`.`agencyModeFk` AS `agencyModeFk`, + `t`.`refFk` AS `refFk`, + `t`.`addressFk` AS `addressFk`, + `t`.`location` AS `location`, + `t`.`companyFk` AS `companyFk`, + `ts`.`alertLevel` AS `alertLevel`, + `ts`.`code` AS `code` +FROM ( + `vn`.`ticket` `t` + LEFT JOIN `vn`.`ticketState` `ts` ON(`ts`.`ticketFk` = `t`.`id`) + ) +WHERE `t`.`clientFk` = `account`.`myUser_getId`() diff --git a/db/routines/hedera/views/myTpvTransaction.sql b/db/routines/hedera/views/myTpvTransaction.sql new file mode 100644 index 000000000..98694065f --- /dev/null +++ b/db/routines/hedera/views/myTpvTransaction.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`myTpvTransaction` +AS SELECT `t`.`id` AS `id`, + `t`.`merchantFk` AS `merchantFk`, + `t`.`clientFk` AS `clientFk`, + `t`.`receiptFk` AS `receiptFk`, + `t`.`amount` AS `amount`, + `t`.`response` AS `response`, + `t`.`status` AS `status`, + `t`.`created` AS `created` +FROM `hedera`.`tpvTransaction` `t` +WHERE `t`.`clientFk` = `account`.`myUser_getId`() diff --git a/db/routines/hedera/views/orderTicket.sql b/db/routines/hedera/views/orderTicket.sql new file mode 100644 index 000000000..c35077935 --- /dev/null +++ b/db/routines/hedera/views/orderTicket.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`orderTicket` +AS SELECT `b`.`orderFk` AS `orderFk`, + `b`.`ticketFk` AS `ticketFk` +FROM `vn`.`orderTicket` `b` diff --git a/db/routines/hedera/views/order_component.sql b/db/routines/hedera/views/order_component.sql new file mode 100644 index 000000000..b3eb7522b --- /dev/null +++ b/db/routines/hedera/views/order_component.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`order_component` +AS SELECT `t`.`rowFk` AS `order_row_id`, + `t`.`componentFk` AS `component_id`, + `t`.`price` AS `price` +FROM `hedera`.`orderRowComponent` `t` diff --git a/db/routines/hedera/views/order_row.sql b/db/routines/hedera/views/order_row.sql new file mode 100644 index 000000000..f69fd98a3 --- /dev/null +++ b/db/routines/hedera/views/order_row.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `hedera`.`order_row` +AS SELECT `t`.`id` AS `id`, + `t`.`orderFk` AS `order_id`, + `t`.`itemFk` AS `item_id`, + `t`.`warehouseFk` AS `warehouse_id`, + `t`.`shipment` AS `shipment`, + `t`.`amount` AS `amount`, + `t`.`price` AS `price`, + `t`.`rate` AS `rate`, + `t`.`created` AS `created`, + `t`.`saleFk` AS `Id_Movimiento` +FROM `hedera`.`orderRow` `t` diff --git a/db/routines/pbx/functions/clientFromPhone.sql b/db/routines/pbx/functions/clientFromPhone.sql new file mode 100644 index 000000000..dc18810aa --- /dev/null +++ b/db/routines/pbx/functions/clientFromPhone.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `pbx`.`clientFromPhone`(vPhone VARCHAR(255)) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * @deprecated Use vn.client_getFromPhone() + */ + RETURN vn.client_getFromPhone(vPhone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/functions/phone_format.sql b/db/routines/pbx/functions/phone_format.sql new file mode 100644 index 000000000..dc697386a --- /dev/null +++ b/db/routines/pbx/functions/phone_format.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `pbx`.`phone_format`(vPhone VARCHAR(255)) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN + DECLARE vI INT DEFAULT 0; + DECLARE vChr VARCHAR(1); + DECLARE vLen INT DEFAULT LENGTH(vPhone); + DECLARE vNewPhone VARCHAR(255) DEFAULT ''; + + WHILE vI < vLen + DO + SET vChr = SUBSTR(vPhone, vI + 1, 1); + + IF vChr REGEXP '^[0-9]$' + THEN + SET vNewPhone = CONCAT(vNewPhone, vChr); + ELSEIF vChr = '+' AND vI = 0 + THEN + SET vNewPhone = CONCAT(vNewPhone, '00'); + END IF; + + SET vI = vI + 1; + END WHILE; + + IF vNewPhone REGEXP '^0+$' OR vNewPhone = '' THEN + RETURN NULL; + END IF; + + IF vNewPhone REGEXP '^0034' THEN + SET vNewPhone = SUBSTR(vNewPhone, 5); + END IF; + + RETURN vNewPhone; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/procedures/phone_isValid.sql b/db/routines/pbx/procedures/phone_isValid.sql new file mode 100644 index 000000000..083a3e54b --- /dev/null +++ b/db/routines/pbx/procedures/phone_isValid.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`phone_isValid`(vPhone VARCHAR(255)) +BEGIN +/** + * Check if an phone has the correct format and + * throws an exception if it hasn't. + * + * @param vPhone The phone number + */ + DECLARE vIsValid BOOL; + + SET vIsValid = vPhone IS NULL + OR (vPhone REGEXP '^[0-9]+$' + AND vPhone NOT REGEXP '^0+$' + AND vPhone NOT REGEXP '^0034'); + + IF NOT vIsValid THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Phone format is invalid'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/procedures/queue_isValid.sql b/db/routines/pbx/procedures/queue_isValid.sql new file mode 100644 index 000000000..52c752e09 --- /dev/null +++ b/db/routines/pbx/procedures/queue_isValid.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`queue_isValid`(vQueue VARCHAR(255)) +BEGIN +/** + * Check if an queue has the correct format and + * throws an exception if it hasn't. + * + * @param vQueue The queue number + */ + DECLARE vIsValid BOOL; + + SET vIsValid = vQueue IS NULL + OR vQueue REGEXP '^[1-9][0-9]00$'; + + IF NOT vIsValid THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Queue format is invalid'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/procedures/sip_getExtension.sql b/db/routines/pbx/procedures/sip_getExtension.sql new file mode 100644 index 000000000..25047fa1f --- /dev/null +++ b/db/routines/pbx/procedures/sip_getExtension.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`sip_getExtension`(vUserId INT(10)) +BEGIN + + /* + * Devuelve la extensión pbx del usuario + * + * @param vUserId Id del usuario + * + */ + + SELECT extension + FROM sip s + WHERE s.user_id = vUserId; + +END$$ +DELIMITER ; diff --git a/db/routines/pbx/procedures/sip_isValid.sql b/db/routines/pbx/procedures/sip_isValid.sql new file mode 100644 index 000000000..4a0182bcc --- /dev/null +++ b/db/routines/pbx/procedures/sip_isValid.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`sip_isValid`(vExtension VARCHAR(255)) +BEGIN +/** + * Check if an extension has the correct format and + * throws an exception if it hasn't. + * + * @param vExtension The extension + */ + DECLARE vIsValid BOOL; + + SET vIsValid = vExtension IS NULL + OR (vExtension REGEXP '^[0-9]{4}$' + AND MOD(vExtension, 100) != 0); + + IF NOT vIsValid THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Extension format is invalid'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/procedures/sip_setPassword.sql b/db/routines/pbx/procedures/sip_setPassword.sql new file mode 100644 index 000000000..14e0b05c5 --- /dev/null +++ b/db/routines/pbx/procedures/sip_setPassword.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`sip_setPassword`( + vUser VARCHAR(255), + vPassword VARCHAR(255) +) +BEGIN + UPDATE sip SET + md5Secret = MD5(CONCAT(extension, ':asterisk:', vPassword)) + WHERE user_id = vUser; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/blacklist_beforeInsert.sql b/db/routines/pbx/triggers/blacklist_beforeInsert.sql new file mode 100644 index 000000000..ff55c2647 --- /dev/null +++ b/db/routines/pbx/triggers/blacklist_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`blacklist_beforeInsert` + BEFORE INSERT ON `blacklist` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/blacklist_berforeUpdate.sql b/db/routines/pbx/triggers/blacklist_berforeUpdate.sql new file mode 100644 index 000000000..84f2c4bbb --- /dev/null +++ b/db/routines/pbx/triggers/blacklist_berforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`blacklist_berforeUpdate` + BEFORE UPDATE ON `blacklist` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/followme_beforeInsert.sql b/db/routines/pbx/triggers/followme_beforeInsert.sql new file mode 100644 index 000000000..69f11c5e6 --- /dev/null +++ b/db/routines/pbx/triggers/followme_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`followme_beforeInsert` + BEFORE INSERT ON `followme` + FOR EACH ROW +BEGIN + CALL pbx.phone_isValid(NEW.phone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/followme_beforeUpdate.sql b/db/routines/pbx/triggers/followme_beforeUpdate.sql new file mode 100644 index 000000000..697c18974 --- /dev/null +++ b/db/routines/pbx/triggers/followme_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`followme_beforeUpdate` + BEFORE UPDATE ON `followme` + FOR EACH ROW +BEGIN + CALL pbx.phone_isValid(NEW.phone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/queuePhone_beforeInsert.sql b/db/routines/pbx/triggers/queuePhone_beforeInsert.sql new file mode 100644 index 000000000..debe9c201 --- /dev/null +++ b/db/routines/pbx/triggers/queuePhone_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`queuePhone_beforeInsert` + BEFORE INSERT ON `queuePhone` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/queuePhone_beforeUpdate.sql b/db/routines/pbx/triggers/queuePhone_beforeUpdate.sql new file mode 100644 index 000000000..9734cc277 --- /dev/null +++ b/db/routines/pbx/triggers/queuePhone_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`queuePhone_beforeUpdate` + BEFORE UPDATE ON `queuePhone` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/queue_beforeInsert.sql b/db/routines/pbx/triggers/queue_beforeInsert.sql new file mode 100644 index 000000000..4644dea89 --- /dev/null +++ b/db/routines/pbx/triggers/queue_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`queue_beforeInsert` + BEFORE INSERT ON `queue` + FOR EACH ROW +BEGIN + CALL queue_isValid(NEW.`name`); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/queue_beforeUpdate.sql b/db/routines/pbx/triggers/queue_beforeUpdate.sql new file mode 100644 index 000000000..a2923045e --- /dev/null +++ b/db/routines/pbx/triggers/queue_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`queue_beforeUpdate` + BEFORE UPDATE ON `queue` + FOR EACH ROW +BEGIN + CALL queue_isValid(NEW.`name`); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/sip_afterInsert.sql b/db/routines/pbx/triggers/sip_afterInsert.sql new file mode 100644 index 000000000..7f0643a98 --- /dev/null +++ b/db/routines/pbx/triggers/sip_afterInsert.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`sip_afterInsert` + AFTER INSERT ON `sip` + FOR EACH ROW +BEGIN + INSERT INTO sipReg + SET userId = NEW.user_id; + + INSERT IGNORE INTO `account`.userSync (`name`) + SELECT `name` FROM `account`.`user` + WHERE id = NEW.user_id; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/sip_afterUpdate.sql b/db/routines/pbx/triggers/sip_afterUpdate.sql new file mode 100644 index 000000000..d14df040c --- /dev/null +++ b/db/routines/pbx/triggers/sip_afterUpdate.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`sip_afterUpdate` + AFTER UPDATE ON `sip` + FOR EACH ROW +BEGIN + IF !(OLD.extension <=> NEW.extension) + OR !(OLD.user_id <=> NEW.user_id) THEN + INSERT IGNORE INTO `account`.userSync (`name`) + SELECT `name` FROM `account`.`user` + WHERE id = NEW.user_id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/sip_beforeInsert.sql b/db/routines/pbx/triggers/sip_beforeInsert.sql new file mode 100644 index 000000000..832232119 --- /dev/null +++ b/db/routines/pbx/triggers/sip_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`sip_beforeInsert` + BEFORE INSERT ON `sip` + FOR EACH ROW +BEGIN + CALL sip_isValid(NEW.extension); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/triggers/sip_beforeUpdate.sql b/db/routines/pbx/triggers/sip_beforeUpdate.sql new file mode 100644 index 000000000..e23b8e22e --- /dev/null +++ b/db/routines/pbx/triggers/sip_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`sip_beforeUpdate` + BEFORE UPDATE ON `sip` + FOR EACH ROW +BEGIN + CALL sip_isValid(NEW.extension); +END$$ +DELIMITER ; diff --git a/db/routines/pbx/views/cdrConf.sql b/db/routines/pbx/views/cdrConf.sql new file mode 100644 index 000000000..adf24c87d --- /dev/null +++ b/db/routines/pbx/views/cdrConf.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `pbx`.`cdrConf` +AS SELECT `c`.`call_date` AS `calldate`, + `c`.`clid` AS `clid`, + `c`.`src` AS `src`, + `c`.`dst` AS `dst`, + `c`.`dcontext` AS `dcontext`, + `c`.`channel` AS `channel`, + `c`.`dst_channel` AS `dstchannel`, + `c`.`last_app` AS `lastapp`, + `c`.`last_data` AS `lastdata`, + `c`.`duration` AS `duration`, + `c`.`billsec` AS `billsec`, + `c`.`disposition` AS `disposition`, + `c`.`ama_flags` AS `amaflags`, + `c`.`account_code` AS `accountcode`, + `c`.`unique_id` AS `uniqueid`, + `c`.`user_field` AS `userfield` +FROM `pbx`.`cdr` `c` diff --git a/db/routines/pbx/views/followmeConf.sql b/db/routines/pbx/views/followmeConf.sql new file mode 100644 index 000000000..75eb25ff2 --- /dev/null +++ b/db/routines/pbx/views/followmeConf.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `pbx`.`followmeConf` +AS SELECT `f`.`extension` AS `name`, + `c`.`music` AS `music`, + `c`.`context` AS `context`, + `c`.`takeCall` AS `takecall`, + `c`.`declineCall` AS `declinecall` +FROM ( + `pbx`.`followme` `f` + JOIN `pbx`.`followmeConfig` `c` + ) diff --git a/db/routines/pbx/views/followmeNumberConf.sql b/db/routines/pbx/views/followmeNumberConf.sql new file mode 100644 index 000000000..c83b639a8 --- /dev/null +++ b/db/routines/pbx/views/followmeNumberConf.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `pbx`.`followmeNumberConf` +AS SELECT `f`.`extension` AS `name`, + 1 AS `ordinal`, + `f`.`phone` AS `phonenumber`, + `c`.`timeout` AS `timeout` +FROM ( + `pbx`.`followme` `f` + JOIN `pbx`.`followmeConfig` `c` + ) diff --git a/db/routines/pbx/views/queueConf.sql b/db/routines/pbx/views/queueConf.sql new file mode 100644 index 000000000..07c241589 --- /dev/null +++ b/db/routines/pbx/views/queueConf.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `pbx`.`queueConf` +AS SELECT `q`.`name` AS `name`, + `c`.`strategy` AS `strategy`, + `c`.`timeout` AS `timeout`, + `c`.`retry` AS `retry`, + `c`.`weight` AS `weight`, + `c`.`maxLen` AS `maxlen`, + `c`.`ringInUse` AS `ringinuse` +FROM ( + `pbx`.`queue` `q` + JOIN `pbx`.`queueConfig` `c` ON(`q`.`config` = `c`.`id`) + ) diff --git a/db/routines/pbx/views/queueMemberConf.sql b/db/routines/pbx/views/queueMemberConf.sql new file mode 100644 index 000000000..7007daa1e --- /dev/null +++ b/db/routines/pbx/views/queueMemberConf.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `pbx`.`queueMemberConf` +AS SELECT `m`.`id` AS `uniqueid`, + `m`.`queue` AS `queue_name`, + concat('SIP/', `m`.`extension`) AS `interface`, + 0 AS `paused` +FROM `pbx`.`queueMember` `m` +UNION ALL +SELECT `p`.`id` AS `id`, + `p`.`queue` AS `queue`, + concat('Local/', `p`.`phone`, '@outgoing') AS `phone`, + 0 AS `paused` +FROM `pbx`.`queuePhone` `p` diff --git a/db/routines/pbx/views/sipConf.sql b/db/routines/pbx/views/sipConf.sql new file mode 100644 index 000000000..443cf7bee --- /dev/null +++ b/db/routines/pbx/views/sipConf.sql @@ -0,0 +1,40 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `pbx`.`sipConf` +AS SELECT `s`.`user_id` AS `id`, + `s`.`extension` AS `name`, + `s`.`extension` AS `regexten`, + NULL AS `callbackextension`, + `s`.`md5Secret` AS `md5secret`, + `u`.`nickname` AS `callerid`, + `c`.`host` AS `host`, + `c`.`deny` AS `deny`, + `c`.`permit` AS `permit`, + `c`.`type` AS `type`, + `c`.`context` AS `context`, + `c`.`incomingLimit` AS `incominglimit`, + `c`.`pickupGroup` AS `pickupgroup`, + `c`.`directMedia` AS `directmedia`, + `c`.`insecure` AS `insecure`, + `c`.`transport` AS `transport`, + `c`.`nat` AS `nat`, + `c`.`disallow` AS `disallow`, + `c`.`allow` AS `allow`, + `r`.`ipAddr` AS `ipaddr`, + `r`.`regSeconds` AS `regseconds`, + `r`.`port` AS `port`, + `r`.`defaultUser` AS `defaultuser`, + `r`.`userAgent` AS `useragent`, + `r`.`lastMs` AS `lastms`, + `r`.`fullContact` AS `fullcontact`, + `r`.`regServer` AS `regserver` +FROM ( + ( + ( + `pbx`.`sip` `s` + JOIN `account`.`user` `u` ON(`u`.`id` = `s`.`user_id`) + ) + LEFT JOIN `pbx`.`sipReg` `r` ON(`s`.`user_id` = `r`.`userId`) + ) + JOIN `pbx`.`sipConfig` `c` + ) diff --git a/db/routines/psico/procedures/answerSort.sql b/db/routines/psico/procedures/answerSort.sql new file mode 100644 index 000000000..75a317b37 --- /dev/null +++ b/db/routines/psico/procedures/answerSort.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `psico`.`answerSort`() +BEGIN + + UPDATE answer + SET `order` = RAND() * 999999; + + +END$$ +DELIMITER ; diff --git a/db/routines/psico/procedures/examNew.sql b/db/routines/psico/procedures/examNew.sql new file mode 100644 index 000000000..4f27212f6 --- /dev/null +++ b/db/routines/psico/procedures/examNew.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `psico`.`examNew`(vFellow VARCHAR(50), vType INT, vQuestionsNumber INT, OUT vExamFk INT) +BEGIN + + DECLARE done BOOL DEFAULT FALSE; + DECLARE vFellowFk INT; + DECLARE vQuestionFk INT; + + DECLARE rs CURSOR FOR + SELECT q.id + FROM psico.question q + LEFT JOIN psico.questionType qt ON q.id = qt.questionFk + WHERE qt.examTypeFk = vType + ORDER BY randomOrder; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + IF vQuestionsNumber = 0 THEN + + SET vQuestionsNumber = 30; + + END IF; + + CALL psico.answerSort(); + + CALL psico.questionSort(); + + INSERT INTO psico.fellow(name) VALUES(vFellow); + + SELECT MAX(id) INTO vFellowFk FROM psico.fellow; + + INSERT INTO psico.exam(fellowFk, started, questionsCount,examTypeFk) VALUES(vFellowFk, util.VN_NOW(), vQuestionsNumber,vType); + + SELECT MAX(id) INTO vExamFk FROM psico.exam; + + OPEN rs; + + FETCH rs INTO vQuestionFk; + + WHILE NOT done AND vQuestionsNumber DO + + INSERT INTO psico.examQuestion(examFk, questionFk) + VALUES (vExamFk, vQuestionFk); + + + FETCH rs INTO vQuestionFk; + + SET vQuestionsNumber = vQuestionsNumber - 1; + + END WHILE; + + CLOSE rs; + + +END$$ +DELIMITER ; diff --git a/db/routines/psico/procedures/getExamQuestions.sql b/db/routines/psico/procedures/getExamQuestions.sql new file mode 100644 index 000000000..9ab1eb6d0 --- /dev/null +++ b/db/routines/psico/procedures/getExamQuestions.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `psico`.`getExamQuestions`(vExamFk INT) +BEGIN + +SELECT p.text,p.examFk,p.questionFk,p.answerFk,p.id ,a.text AS answerText,a.correct, a.id AS answerFk +FROM psico.examView as p +INNER JOIN psico.answer as a ON p.questionFk = a.questionFk +WHERE examFk = vExamFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/psico/procedures/getExamType.sql b/db/routines/psico/procedures/getExamType.sql new file mode 100644 index 000000000..d829950e6 --- /dev/null +++ b/db/routines/psico/procedures/getExamType.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `psico`.`getExamType`() +BEGIN + +SELECT id,name +FROM psico.examType; + +END$$ +DELIMITER ; diff --git a/db/routines/psico/procedures/questionSort.sql b/db/routines/psico/procedures/questionSort.sql new file mode 100644 index 000000000..56c5ef4a9 --- /dev/null +++ b/db/routines/psico/procedures/questionSort.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `psico`.`questionSort`() +BEGIN + + UPDATE question + SET randomOrder = RAND() * 999999; + +END$$ +DELIMITER ; diff --git a/db/routines/psico/views/examView.sql b/db/routines/psico/views/examView.sql new file mode 100644 index 000000000..1aa768919 --- /dev/null +++ b/db/routines/psico/views/examView.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `psico`.`examView` +AS SELECT `q`.`text` AS `text`, + `eq`.`examFk` AS `examFk`, + `eq`.`questionFk` AS `questionFk`, + `eq`.`answerFk` AS `answerFk`, + `eq`.`id` AS `id` +FROM ( + `psico`.`question` `q` + JOIN `psico`.`examQuestion` `eq` ON(`q`.`id` = `eq`.`questionFk`) + ) diff --git a/db/routines/psico/views/results.sql b/db/routines/psico/views/results.sql new file mode 100644 index 000000000..1d7945d32 --- /dev/null +++ b/db/routines/psico/views/results.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `psico`.`results` +AS SELECT `eq`.`examFk` AS `examFk`, + sum(`a`.`correct` * `a`.`correct`) AS `aciertos`, + `e`.`questionsCount` AS `questionsCount`, + HOUR(timediff(`e`.`finished`, `e`.`started`)) * 60 + MINUTE(timediff(`e`.`finished`, `e`.`started`)) AS `minutos`, + least( + 3, + 3 * (`e`.`questionsCount` * 0.5) / ( + HOUR(timediff(`e`.`finished`, `e`.`started`)) * 60 + MINUTE(timediff(`e`.`finished`, `e`.`started`)) + ) + ) + 7 * sum(`a`.`correct` * `a`.`correct`) / `e`.`questionsCount` AS `nota` +FROM ( + ( + `psico`.`exam` `e` + JOIN `psico`.`examQuestion` `eq` ON(`eq`.`examFk` = `e`.`id`) + ) + JOIN `psico`.`answer` `a` ON(`eq`.`answerFk` = `a`.`id`) + ) +GROUP BY `eq`.`examFk`, + `e`.`questionsCount` diff --git a/db/routines/sage/functions/company_getCode.sql b/db/routines/sage/functions/company_getCode.sql new file mode 100644 index 000000000..bdb8c17fb --- /dev/null +++ b/db/routines/sage/functions/company_getCode.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `sage`.`company_getCode`(vCompanyFk INT) + RETURNS int(2) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Devuelve la correspondencía del código de empresa de sage. + * Tiene en cuenta el entorno + * + * @param vSelf Id de empresa de verdnatura + * @return Código de empresa sage + */ + DECLARE vCompanySageFk INT(2); + + SELECT IF(c.environment = 'production', + co.companyCode, + co.companyCodeTest + ) INTO vCompanySageFk + FROM util.config c + JOIN vn.company co + WHERE co.id = vCompanyFk; + + RETURN vCompanySageFk; +END$$ +DELIMITER ; diff --git a/db/.archive/225201/00-accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql similarity index 86% rename from db/.archive/225201/00-accountingMovements_add.sql rename to db/routines/sage/procedures/accountingMovements_add.sql index 12dc176bc..ab0477823 100644 --- a/db/.archive/225201/00-accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -1,11 +1,12 @@ -DROP PROCEDURE IF EXISTS `sage`.`accountingMovements_add`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `sage`.`accountingMovements_add`(vYear INT, vCompanyFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`accountingMovements_add`( + vYear INT, + vCompanyFk INT +) BEGIN /** - * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta para poder ejecutar posteriormente el proceso de importación de datos de SQL Server + * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta + * para poder ejecutar posteriormente el proceso de importación de datos de SQL Server * Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE * @vYear Año contable del que se quiere trasladar la información * @vCompanyFk Empresa de la que se quiere trasladar datos @@ -31,34 +32,31 @@ BEGIN FROM Naciones WHERE Nacion ='CEUTA Y MELILLA'; - SELECT CodigoTransaccion INTO vDuaTransactionFk - FROM TiposTransacciones - WHERE Transaccion = 'Import. bienes y serv. corrientes pdte. liquidar'; + SELECT pendingServiceTransactionTypeFk INTO vDuaTransactionFk + FROM config; - SELECT CodigoIva INTO vTaxImportFk - FROM TiposIva - WHERE Iva = 'IVA 21% importaciones'; + SELECT id INTO vTaxImportFk + FROM taxType + WHERE code = 'import21'; - SELECT CodigoIva INTO vTaxImportReducedFk - FROM TiposIva - WHERE Iva = 'IVA 10% importaciones'; + SELECT id INTO vTaxImportReducedFk + FROM taxType + WHERE code = 'import10'; - SELECT CodigoIva INTO vTaxImportSuperReducedFk - FROM TiposIva - WHERE Iva = 'H.P. IVA Soportado Impor 4%'; + SELECT id INTO vTaxImportSuperReducedFk + FROM taxType + WHERE code = 'import4'; - SELECT CodigoTransaccion INTO vTransactionExportFk - FROM TiposTransacciones - WHERE Transaccion = 'Exportaciones definitivas'; + SELECT definitiveExportTransactionTypeFk INTO vTransactionExportFk + FROM config; - SELECT CodigoTransaccion INTO vTransactionExportTaxFreeFk - FROM TiposTransacciones - WHERE Transaccion = 'Envíos definitivos a Canarias, Ceuta y Melilla'; + SELECT shipmentTransactionTypeFk INTO vTransactionExportTaxFreeFk + FROM config; SELECT codeSage INTO vInvoiceTypeInformativeCode FROM invoiceType WHERE code ='informative'; - SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) + SELECT MAKEDATE(vYear, 1), MAKEDATE(vYear + 1, 1) - INTERVAL 1 DAY INTO vDatedFrom, vDatedTo; TRUNCATE movContaIVA; @@ -163,7 +161,8 @@ BEGIN YEAR(x.FECHA) Ejercicio, company_getCode(vCompanyFk) AS CodigoEmpresa, x.ASIEN Asiento, - IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL), 'D', 'H') CargoAbono, + IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL), + 'D', 'H') CargoAbono, x.SUBCTA CodigoCuenta, x.CONTRA Contrapartida, x.FECHA FechaAsiento, @@ -310,7 +309,8 @@ BEGIN -- DUAS UPDATE movConta mci JOIN vn.XDiario x ON x.ASIEN = mci.Asiento - JOIN TiposIva ti ON ti.CodigoIva = x.IVA + JOIN TiposIva ti ON ti.PorcentajeIva = x.IVA + JOIN taxType tt ON tt.id = ti.CodigoIva JOIN vn.pgcMaster pm ON pm.code = mci.CodigoCuenta COLLATE utf8mb3_unicode_ci SET mci.BaseIva1 = x.BASEEURO, mci.PorIva1 = x.IVA, @@ -321,15 +321,18 @@ BEGIN mci.FechaFacturaOriginal = x.FECHA_EX, mci.SuFacturaNo = x.FACTURAEX, mci.FechaOperacion = x.FECHA_OP, - mci.ImporteFactura = mci.ImporteFactura + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci - AND ti.Iva = 'I.V.A. 10% Nacional'; + AND tt.code = 'national10'; UPDATE movConta mci JOIN vn.XDiario x ON x.ASIEN = mci.Asiento - JOIN TiposIva ti ON ti.CodigoIva = x.IVA + JOIN TiposIva ti ON ti.PorcentajeIva = x.IVA + JOIN taxType tt ON tt.id = ti.CodigoIva JOIN vn.pgcMaster pm ON pm.code = mci.CodigoCuenta COLLATE utf8mb3_unicode_ci SET mci.BaseIva2 = x.BASEEURO , mci.PorIva2 = x.IVA, @@ -337,15 +340,18 @@ BEGIN mci.CodigoTransaccion2 = vDuaTransactionFk , mci.CodigoIva2 = vTaxImportFk, mci.IvaDeducible2 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci - AND ti.Iva = 'I.V.A. 21%'; + AND tt.code = 'national21'; UPDATE movConta mci JOIN vn.XDiario x ON x.ASIEN = mci.Asiento - JOIN TiposIva ti ON ti.CodigoIva = x.IVA + JOIN TiposIva ti ON ti.PorcentajeIva = x.IVA + JOIN taxType tt ON tt.id = ti.CodigoIva JOIN vn.pgcMaster pm ON pm.code = mci.CodigoCuenta COLLATE utf8mb3_unicode_ci SET mci.BaseIva3 = x.BASEEURO , mci.PorIva3 = x.IVA, @@ -353,11 +359,13 @@ BEGIN mci.CodigoTransaccion3 = vDuaTransactionFk , mci.CodigoIva3 = vTaxImportSuperReducedFk, mci.IvaDeducible3 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci - AND ti.Iva = 'I.V.A. 4%'; + AND tt.code = 'national4'; -- Rectificativas UPDATE movConta mci @@ -386,12 +394,15 @@ BEGIN OR CodigoTransaccion2 = vTransactionExportFk OR CodigoTransaccion3 = vTransactionExportFk OR CodigoTransaccion4 = vTransactionExportFk) - AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci); + AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, + vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci); UPDATE movConta mc SET CodigoDivisa = 'USD', FactorCambio = TRUE, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) + ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, + ImporteAsiento / ImporteDivisa, + ImporteCambio) AS DECIMAL( 10, 2))) WHERE enlazadoSage = FALSE AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio); @@ -432,7 +443,9 @@ BEGIN AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase) sub; IF vBookEntries IS NOT NULL THEN - SELECT util.notification_send ("book-entries-imported-incorrectly", CONCAT('{"bookEntries":"', vBookEntries,'"}'), null); + SELECT util.notification_send ("book-entries-imported-incorrectly", + CONCAT('{"bookEntries":"', vBookEntries,'"}'), + null); END IF; END$$ DELIMITER ; diff --git a/db/.archive/230801/01-sage_supplierAdd.sql b/db/routines/sage/procedures/clientSupplier_add.sql similarity index 86% rename from db/.archive/230801/01-sage_supplierAdd.sql rename to db/routines/sage/procedures/clientSupplier_add.sql index 66cb0aff1..7a0aec6e2 100644 --- a/db/.archive/230801/01-sage_supplierAdd.sql +++ b/db/routines/sage/procedures/clientSupplier_add.sql @@ -1,8 +1,5 @@ -DROP PROCEDURE IF EXISTS `sage`.`clientSupplier_add`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clientSupplier_add`(vCompanyFk INT) BEGIN /** * Prepara los datos de clientes y proveedores para exportarlos a Sage @@ -55,8 +52,8 @@ BEGIN c.socialName, IFNULL(c.street, ''), c.accountingAccount, - TRIM(IF(c.isVies, CONCAT(cu.code,c.fi), c.fi)), - IF(n.NacionCEE,TRIM(IF(cu.code = LEFT(c.fi, 2), c.fi, CONCAT(cu.code,c.fi))) , ''), + @fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)), + IF(c.isVies, CONCAT(cu.code, @fi ), TRIM(c.fi)), IFNULL(c.postcode, ''), IFNULL(c.city, ''), IFNULL(pr.CodigoProvincia, ''), @@ -64,8 +61,8 @@ BEGIN IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla := IF(pr.Provincia IN ('CEUTA', 'MELILLA'), TRUE, FALSE), vCountryCeutaMelillaFk, IF (@isCanarias, vCountryCanariasCode, n.CodigoNacion)), n.CodigoNacion), IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla, vCountryCeutaMelillaCode, IF (@isCanarias, vCountryCanariasCode, n.SiglaNacion)), n.SiglaNacion), IF((c.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F'), - IF(cu.code IN('ES','EX'), - 1, + IF(cu.code = 'ES', + 1, IF((cu.isUeeMember AND c.isVies), 2, 4)), IFNULL(c.taxTypeSageFk,0), IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, @@ -93,8 +90,8 @@ BEGIN s.name, IFNULL(s.street, ''), s.account, - TRIM(IF(s.isVies, CONCAT(co.code,s.nif), s.nif)), - IF(n.NacionCEE, TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif))), ''), + @nif := IF(co.code = LEFT(TRIM(s.nif), 2), MID(TRIM(s.nif), 3, LENGTH(TRIM(s.nif))-1), TRIM(s.nif)), + IF(s.isVies, CONCAT(co.code, @nif), TRIM(s.nif)), IFNULL(s.postCode,''), IFNULL(s.city, ''), IFNULL(pr.CodigoProvincia, ''), @@ -102,7 +99,7 @@ BEGIN n.CodigoNacion, n.SiglaNacion COLLATE utf8mb3_unicode_ci, IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F'), - IF(co.country IN ('España', 'España exento'), 1,IF(co.isUeeMember = 1, 2, 4)), + IF(co.code = 'ES', 1, IF(co.isUeeMember, 2, 4)), IFNULL(s.taxTypeSageFk, 0), n.Nacion, IFNULL(sc.phone, ''), diff --git a/db/routines/sage/procedures/invoiceIn_add.sql b/db/routines/sage/procedures/invoiceIn_add.sql new file mode 100644 index 000000000..a2690deb0 --- /dev/null +++ b/db/routines/sage/procedures/invoiceIn_add.sql @@ -0,0 +1,202 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`invoiceIn_add`(vInvoiceInFk INT, vXDiarioFk INT) +BEGIN +/** + * Traslada la info de contabilidad relacionada con las facturas recibidas + * + * @vInvoiceInFk Factura recibida + * @vXDiarioFk Id tabla XDiario + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vBase DOUBLE; + DECLARE vVat DOUBLE; + DECLARE vRate DOUBLE; + DECLARE vTransactionCode INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vTransactionCodeOld INT; + DECLARE vTaxCode INT; + DECLARE vTaxCodeOld INT; + DECLARE vOperationCode VARCHAR(1); + DECLARE vIsIntracommunity BOOL DEFAULT FALSE; + DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; + DECLARE vInvoiceTypeReceived VARCHAR(1); + DECLARE vInvoiceTypeInformative VARCHAR(1); + DECLARE vIsInformativeExportation BOOL DEFAULT FALSE; + + DECLARE vCursor CURSOR FOR + SELECT it.taxableBase, + CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)), + t.PorcentajeIva, + it.transactionTypeSageFk, + it.taxTypeSageFk, + tty.isIntracommunity, + tt.ClaveOperacionDefecto + FROM vn.invoiceIn i + JOIN vn.invoiceInTax it ON it.InvoiceInFk = i.id + JOIN TiposIva t ON t.CodigoIva = it.taxTypeSageFk + JOIN taxType tty ON tty.id = t.CodigoIva + JOIN TiposTransacciones tt ON tt.CodigoTransaccion = it.transactionTypeSageFk + LEFT JOIN vn.dua d ON d.id = vInvoiceInFk + WHERE i.id = vInvoiceInFk + AND d.id IS NULL; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE FROM movContaIVA + WHERE id = vXDiarioFk; + + SELECT codeSage INTO vInvoiceTypeReceived + FROM invoiceType WHERE code ='received'; + + SELECT codeSage INTO vInvoiceTypeInformative + FROM invoiceType WHERE code ='informative'; + + INSERT INTO movContaIVA(id, LibreA1) + VALUES (vXDiarioFk, vInvoiceInFk); + + OPEN vCursor; + + l: LOOP + FETCH vCursor INTO vBase, + vVat, + vRate, + vTransactionCode, + vTaxCode, + vIsIntracommunity, + vOperationCode; + + IF vDone THEN + LEAVE l; + END IF; + + SET vTransactionCodeOld = vTransactionCode; + SET vTaxCodeOld = vTaxCode; + + IF vOperationCode IS NOT NULL THEN + UPDATE movContaIVA + SET ClaveOperacionFactura = vOperationCode + WHERE id = vXDiarioFk; + END IF; + + SET vCounter = vCounter + 1; + CASE vCounter + WHEN 1 THEN + UPDATE movContaIVA + SET BaseIva1 = vBase, + PorIva1 = vRate, + CuotaIva1 = vVat, + CodigoTransaccion1 = vTransactionCode, + CodigoIva1 = vTaxCode + WHERE id = vXDiarioFk; + + WHEN 2 THEN + UPDATE movContaIVA + SET BaseIva2 = vBase, + PorIva2 = vRate, + CuotaIva2 = vVat, + CodigoTransaccion2 = vTransactionCode, + CodigoIva2 = vTaxCode + WHERE id = vXDiarioFk; + WHEN 3 THEN + UPDATE movContaIVA + SET BaseIva3 = vBase, + PorIva3 = vRate, + CuotaIva3 = vVat, + CodigoTransaccion3 = vTransactionCode, + CodigoIva3 = vTaxCode + WHERE id = vXDiarioFk; + WHEN 4 THEN + UPDATE movContaIVA + SET BaseIva4 = vBase, + PorIva4 = vRate, + CuotaIva4 = vVat, + CodigoTransaccion4 = vTransactionCode, + CodigoIva4 = vTaxCode + WHERE id = vXDiarioFk; + ELSE + SELECT vXDiarioFk INTO vXDiarioFk; + END CASE; + + IF vIsIntracommunity THEN + UPDATE movContaIVA + SET Intracomunitaria = TRUE + WHERE id = vXDiarioFk; + END IF; + + SET vTransactionCodeOld = vTransactionCode; + SET vTaxCodeOld = vTaxCode; + + END LOOP; + + CLOSE vCursor; + + SELECT d.ASIEN AND x.ASIEN IS NULL INTO vIsInformativeExportation + FROM vn.dua d + LEFT JOIN vn.XDiario x ON x.ASIEN = d.ASIEN + AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci + WHERE d.ASIEN = ( + SELECT ASIEN + FROM vn.XDiario + WHERE id = vXDiarioFk) + LIMIT 1; + + UPDATE movContaIVA mci + JOIN tmp.invoiceIn ii ON ii.id = vInvoiceInFk + JOIN vn.XDiario x ON x.id = mci.id + LEFT JOIN tmp.invoiceDua id ON id.id = mci.id + JOIN vn.supplier s ON s.id = ii.supplierFk + JOIN Naciones n ON n.countryFk = s.countryFk + SET mci.CodigoDivisa = ii.currencyFk, + mci.Año = YEAR(ii.issued), + mci.Serie = ii.serial, + mci.Factura = ii.id, + mci.FechaFactura = ii.issued, + mci.ImporteFactura = IFNULL(mci.BaseIva1, 0) + IFNULL(mci.CuotaIva1, 0) + + IFNULL(mci.BaseIva2, 0) + IFNULL(mci.CuotaIva2, 0) + + IFNULL(mci.BaseIva3, 0) + IFNULL(mci.CuotaIva3, 0) + + IFNULL(mci.BaseIva4, 0) + IFNULL(mci.CuotaIva4, 0), + mci.TipoFactura = IF(id.id, + IF( ii.serial = vSerialDua COLLATE utf8mb3_unicode_ci, vInvoiceTypeReceived, vInvoiceTypeInformative), + IF(vIsInformativeExportation,vInvoiceTypeInformative, vInvoiceTypeReceived)), + mci.CodigoCuentaFactura = x.SUBCTA, + mci.CifDni = IF(LEFT(TRIM(s.nif), 2) = n.SiglaNacion, SUBSTRING(TRIM(s.nif), 3), s.nif), + mci.Nombre = s.name, + mci.SiglaNacion = n.SiglaNacion, + mci.EjercicioFactura = YEAR(ii.issued), + mci.FechaOperacion = ii.issued, + mci.MantenerAsiento = TRUE, + mci.SuFacturaNo = ii.supplierRef, + mci.IvaDeducible1 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva1, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + mci.IvaDeducible2 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva2, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + mci.IvaDeducible3 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva3, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + mci.IvaDeducible4 = IF(id.id, FALSE, IF(IFNULL(mci.BaseIva4, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + mci.FechaFacturaOriginal = x.FECHA_EX + WHERE mci.id = vXDiarioFk; + + -- RETENCIONES + UPDATE movContaIVA mci + JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk + JOIN vn.XDiario x ON x.id = mci.id + JOIN vn.supplier s ON s.id = supplierFk + JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id + JOIN vn.expense e ON e.id = iit.expenseFk + JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk + LEFT JOIN tmp.invoiceDua id ON id.id = mci.id + JOIN (SELECT SUM(x2.BASEEURO) taxableBase, SUM(x2.EURODEBE) taxBase + FROM vn.XDiario x1 + JOIN vn.XDiario x2 ON x1.ASIEN = x2.ASIEN + WHERE x2.BASEEURO <> 0 + AND x1.id = vXDiarioFk + )sub + JOIN ClavesOperacion co ON co.Descripcion = 'Arrendamiento de locales de negocio' + SET mci.CodigoRetencion = t.CodigoRetencion, + mci.ClaveOperacionFactura = IF( t.Retencion = 'ARRENDAMIENTO Y SUBARRENDAMIENTO', co.ClaveOperacionFactura_, mci.ClaveOperacionFactura), + mci.BaseRetencion = IF (t.Retencion = 'ACTIVIDADES AGRICOLAS O GANADERAS', sub.taxableBase + sub.taxBase, sub.taxableBase), + mci.PorRetencion = t.PorcentajeRetencion, + mci.ImporteRetencion = iit.taxableBase * - 1 + WHERE mci.id = vXDiarioFk + AND e.name = 'Retenciones' + AND id.id IS NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/sage/procedures/invoiceIn_manager.sql b/db/routines/sage/procedures/invoiceIn_manager.sql new file mode 100644 index 000000000..f9bf0e92f --- /dev/null +++ b/db/routines/sage/procedures/invoiceIn_manager.sql @@ -0,0 +1,271 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`invoiceIn_manager`(vYear INT, vCompanyFk INT) +BEGIN +/** + * Traslada la info de contabilidad relacionada con las facturas recibidas + * + * @vYear Año contable del que se quiere trasladar la información + * @vCompany Empresa de la que se quiere trasladar datos + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vInvoiceFk INT; + DECLARE vXDiarioFk INT; + DECLARE vDatedFrom DATETIME; + DECLARE vDatedTo DATETIME; + DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; + DECLARE vAccountVNL VARCHAR(10); + DECLARE vAccountTaxOutstanding VARCHAR(10); + DECLARE vInvoiceTypeSended VARCHAR(1); + DECLARE vCursor CURSOR FOR + SELECT IFNULL(x.CLAVE, x.FACTURA) invoiceInFk, + x.id XDiarioFk + FROM vn.XDiario x + JOIN(SELECT DISTINCT(x.ASIEN) + FROM vn.XDiario x + LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id + LEFT JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id + WHERE(it.taxTypeSageFk IS NOT NULL OR x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci) + AND x.enlazadoSage = FALSE + AND x.FECHA BETWEEN vDatedFrom AND vDatedTo + AND x.empresa_id = vCompanyFk + ) sub ON sub.ASIEN = x.ASIEN + WHERE x.CLAVE IS NOT NULL; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) + INTO vDatedFrom, vDatedTo; + + SELECT accountingAccount INTO vAccountVNL + FROM vn.`client` + WHERE name='VNL'; + + SELECT code INTO vAccountTaxOutstanding + FROM vn.pgcMaster + WHERE description = 'HP Iva pendiente'; + + SELECT codeSage INTO vInvoiceTypeSended + FROM invoiceType WHERE `code` ='sended'; + + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; + CREATE TEMPORARY TABLE tmp.invoiceDua + SELECT x.id + FROM vn.XDiario x + JOIN vn.company c ON c.id = x.empresa_id + JOIN (SELECT ASIEN + FROM vn.XDiario x + WHERE x.enlazadoSage = FALSE + AND x.SUBCTA = vAccountTaxOutstanding COLLATE utf8mb3_unicode_ci + AND x.FECHA BETWEEN vDatedFrom AND vDatedTo + )sub ON sub.ASIEN = x.ASIEN + WHERE NOT x.CONTRA <=> vAccountVNL; + + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceIn; + CREATE TEMPORARY TABLE tmp.invoiceIn + SELECT i.id, + i.supplierRef, + i.serial COLLATE utf8mb3_unicode_ci serial, + i.supplierFk, + i.issued, + IF(expenseFkDeductible, FALSE, i.isVatDeductible) isVatDeductible, + IF(c.code = 'EUR', '',c.`code`) currencyFk + FROM vn.invoiceIn i + JOIN vn.currency c ON c.id = i.currencyFk + WHERE i.bookEntried BETWEEN vDatedFrom AND vDatedTo + UNION ALL + SELECT d.id, + d.code, + vSerialDua COLLATE utf8mb3_unicode_ci, + d.companyFk , + d.issued, + FALSE, + '' -- EUROS + FROM vn.dua d + WHERE d.issued IS NOT NULL + AND code IS NOT NULL; + + OPEN vCursor; + + l: LOOP + FETCH vCursor INTO vInvoiceFk, vXDiarioFk; + + IF vDone THEN + LEAVE l; + END IF; + CALL invoiceIn_add(vInvoiceFk, vXDiarioFk); + END LOOP; + + CLOSE vCursor; + + DROP TEMPORARY TABLE tmp.invoiceDua; + DROP TEMPORARY TABLE tmp.invoiceIn; + + -- ASIENTOS CON IVA SOPORTADO 472. y 477. hay que informar 2 líneas la info de facturas una como tipo de factura emitida y otra como recibida + DROP TEMPORARY TABLE IF EXISTS tmp.movContaIVA; + CREATE TEMPORARY TABLE tmp.movContaIVA + SELECT sub3.id, + mci.CodigoDivisa, + mci.BaseIva1, + mci.PorBaseCorrectora1, + mci.PorIva1, + mci.CuotaIva1, + mci.PorRecargoEquivalencia1, + mci.RecargoEquivalencia1, + mci.CodigoTransaccion1, + mci.CodigoIva1, + mci.BaseIva2, + mci.PorBaseCorrectora2, + mci.PorIva2, + mci.CuotaIva2, + mci.PorRecargoEquivalencia2, + mci.RecargoEquivalencia2, + mci.CodigoTransaccion2, + mci.CodigoIva2, + mci.BaseIva3, + mci.PorBaseCorrectora3, + mci.PorIva3, + mci.CuotaIva3, + mci.PorRecargoEquivalencia3, + mci.RecargoEquivalencia3, + mci.CodigoTransaccion3, + mci.CodigoIva3, + mci.BaseIva4, + mci.PorBaseCorrectora4, + mci.PorIva4, + mci.CuotaIva4, + mci.PorRecargoEquivalencia4, + mci.RecargoEquivalencia4, + mci.CodigoTransaccion4, + mci.CodigoIva4, + mci.Año, + mci.Serie, + mci.Factura, + mci.SuFacturaNo, + mci.FechaFactura, + mci.ImporteFactura, + vInvoiceTypeSended, + mci.CodigoCuentaFactura, + mci.CifDni, + mci.Nombre, + mci.CodigoRetencion, + mci.BaseRetencion, + mci.PorRetencion, + mci.ImporteRetencion, + mci.SiglaNacion, + mci.EjercicioFactura, + x.FECHA, + mci.Exclusion347, + mci.MantenerAsiento, + mci.Metalico347, + mci.ClaveOperacionFactura, + mci.TipoRectificativa, + mci.FechaFacturaOriginal, + mci.CuotaIvaOriginal, + mci.BaseImponibleOriginal, + mci.ClaseAbonoRectificativas, + mci.RecargoEquivalenciaOriginal, + mci.LibreA1, + mci.IvaDeducible1, + mci.IvaDeducible2, + mci.IvaDeducible3, + mci.IvaDeducible4, + mci.FechaGrabacion, + mci.Intracomunitaria, + mci.moveData + FROM movContaIVA mci + JOIN vn.XDiario x ON x.id = mci.id + JOIN (SELECT x.ASIEN, x.id + FROM vn.XDiario x + JOIN(SELECT DISTINCT(x.ASIEN) ASIEN + FROM vn.XDiario x + JOIN (SELECT DISTINCT(ASIEN) + FROM vn.XDiario x + WHERE SUBCTA LIKE '472%' + AND x.enlazadoSage = FALSE + AND x.empresa_id = vCompanyFk + AND x.FECHA BETWEEN vDatedFrom AND vDatedTo + ) sub ON sub.ASIEN = x.ASIEN + WHERE x.SUBCTA LIKE '477%' + )sub2 ON sub2.ASIEN = x.ASIEN + WHERE x.CONTRA IS NOT NULL + AND x.SUBCTA LIKE '477%' + GROUP BY x.ASIEN + )sub3 ON sub3.ASIEN = x.ASIEN; + + INSERT INTO movContaIVA + (`id`, + `CodigoDivisa`, + `BaseIva1`, + `PorBaseCorrectora1`, + `PorIva1`, + `CuotaIva1`, + `PorRecargoEquivalencia1`, + `RecargoEquivalencia1`, + `CodigoTransaccion1`, + `CodigoIva1`, + `BaseIva2`, + `PorBaseCorrectora2`, + `PorIva2`, + `CuotaIva2`, + `PorRecargoEquivalencia2`, + `RecargoEquivalencia2`, + `CodigoTransaccion2`, + `CodigoIva2`, + `BaseIva3`, + `PorBaseCorrectora3`, + `PorIva3`, + `CuotaIva3`, + `PorRecargoEquivalencia3`, + `RecargoEquivalencia3`, + `CodigoTransaccion3`, + `CodigoIva3`, + `BaseIva4`, + `PorBaseCorrectora4`, + `PorIva4`, + `CuotaIva4`, + `PorRecargoEquivalencia4`, + `RecargoEquivalencia4`, + `CodigoTransaccion4`, + `CodigoIva4`, + `Año`, + `Serie`, + `Factura`, + `SuFacturaNo`, + `FechaFactura`, + `ImporteFactura`, + `TipoFactura`, + `CodigoCuentaFactura`, + `CifDni`, + `Nombre`, + `CodigoRetencion`, + `BaseRetencion`, + `PorRetencion`, + `ImporteRetencion`, + `SiglaNacion`, + `EjercicioFactura`, + `FechaOperacion`, + `Exclusion347`, + `MantenerAsiento`, + `Metalico347`, + `ClaveOperacionFactura`, + `TipoRectificativa`, + `FechaFacturaOriginal`, + `CuotaIvaOriginal`, + `BaseImponibleOriginal`, + `ClaseAbonoRectificativas`, + `RecargoEquivalenciaOriginal`, + `LibreA1`, + `IvaDeducible1`, + `IvaDeducible2`, + `IvaDeducible3`, + `IvaDeducible4`, + `FechaGrabacion`, + `Intracomunitaria`, + `moveData`) + SELECT * + FROM tmp.movContaIVA; + + DROP TEMPORARY TABLE tmp.movContaIVA; + +END$$ +DELIMITER ; diff --git a/db/routines/sage/procedures/invoiceOut_add.sql b/db/routines/sage/procedures/invoiceOut_add.sql new file mode 100644 index 000000000..95d6a56dd --- /dev/null +++ b/db/routines/sage/procedures/invoiceOut_add.sql @@ -0,0 +1,194 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`invoiceOut_add`(IN vInvoiceOutFk INT, IN vXDiarioFk INT) +BEGIN +/** + * Traslada la info de contabilidad relacionada con las facturas emitidas + * + * @vYear Año contable del que se quiere trasladar la información + * @vCompany Empresa de la que se quiere trasladar datos + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vMaxLengthName INT DEFAULT 35; + DECLARE vBase DOUBLE; + DECLARE vVat DOUBLE; + DECLARE vRate DOUBLE; + DECLARE vMod347 DOUBLE; + DECLARE vTaxEqu DOUBLE; + DECLARE vRateEqu DOUBLE; + DECLARE vTransactionCode INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vInvoiceOutCorrectedFk INT; + DECLARE vTaxCode INT; + DECLARE vIsIntracommunity BOOL DEFAULT FALSE; + DECLARE vInvoiceTypeSended VARCHAR(1); + DECLARE vOperationCode VARCHAR(1); + DECLARE vHasCustomsAccountingNote BOOL; + + DECLARE vCursor CURSOR FOR + SELECT oit.taxableBase, + oit.vat, + pgc.rate, + pgc.mod347, + pgcRE.rate, + oitRE.vat, + tc.transactionCode, + tc.taxCode, + tc.isIntracommunity, + tc.operationcode + FROM vn.invoiceOutTax oit + JOIN vn.pgc ON pgc.code = oit.pgcFk + LEFT JOIN vn.pgcEqu e ON e.vatFk = oit.pgcFk + LEFT JOIN vn.pgcEqu eRE ON eRE.equFk = oit.pgcFk + LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk + AND oitRE.pgcFk = e.equFk + LEFT JOIN vn.pgc pgcRE ON pgcRE.code = oitRE.pgcFk + LEFT JOIN vn.taxCode tc ON tc.code = pgc.code COLLATE 'utf8mb3_unicode_ci' + WHERE eRE.equFk IS NULL + AND oit.invoiceOutFk = vInvoiceOutFk + GROUP BY pgc.code; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT COUNT(*) INTO vHasCustomsAccountingNote + FROM vn.XDiario x + JOIN config c ON c.pendingTaxAccount = x.SUBCTA + WHERE ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioFk); + + SELECT codeSage INTO vInvoiceTypeSended + FROM invoiceType + WHERE code = IF(vHasCustomsAccountingNote, 'informative', 'sended'); + + DELETE FROM movContaIVA + WHERE id = vXDiarioFk; + + INSERT INTO movContaIVA(id) VALUES (vXDiarioFk); + + OPEN vCursor; + + l: LOOP + FETCH vCursor INTO vBase, + vVat, + vRate, + vMod347, + vTaxEqu, + vRateEqu, + vTransactionCode, + vTaxCode, + vIsIntracommunity, + vOperationCode; + + IF vDone THEN + LEAVE l; + END IF; + + SET vCounter = vCounter + 1; + + CASE vCounter + WHEN 1 THEN + UPDATE movContaIVA + SET BaseIva1 = vBase, + PorIva1 = vRate, + CuotaIva1 = vVat, + PorRecargoEquivalencia1 = vTaxEqu, + RecargoEquivalencia1 = vRateEqu, + CodigoTransaccion1 = vTransactionCode, + CodigoIva1 = vTaxCode + WHERE id = vXDiarioFk; + WHEN 2 THEN + UPDATE movContaIVA + SET BaseIva2 = vBase, + PorIva2 = vRate, + CuotaIva2 = vVat, + PorRecargoEquivalencia2 = vTaxEqu, + RecargoEquivalencia2 =vRateEqu, + CodigoTransaccion2 = vTransactionCode, + CodigoIva2 = vTaxCode + WHERE id = vXDiarioFk; + WHEN 3 THEN + UPDATE movContaIVA + SET BaseIva3 = vBase, + PorIva3 = vRate, + CuotaIva3 = vVat, + PorRecargoEquivalencia3 = vTaxEqu, + RecargoEquivalencia3 = vRateEqu, + CodigoTransaccion3 = vTransactionCode, + CodigoIva3 = vTaxCode + WHERE id = vXDiarioFk; + WHEN 4 THEN + UPDATE movContaIVA + SET BaseIva4 = vBase, + PorIva4 = vRate, + CuotaIva4 = vVat, + PorRecargoEquivalencia4 = vTaxEqu, + RecargoEquivalencia4 = vRateEqu, + CodigoTransaccion4 = vTransactionCode, + CodigoIva4 = vTaxCode + WHERE id = vXDiarioFk; + END CASE; + + UPDATE movContaIVA + SET Exclusion347 = NOT vMod347, + Intracomunitaria = vIsIntracommunity, + ClaveOperacionFactura = vOperationCode + WHERE id = vXDiarioFk; + + END LOOP; + + CLOSE vCursor; + + UPDATE movContaIVA mci + JOIN vn.invoiceOut i ON i.id = vInvoiceOutFk + LEFT JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutFk + LEFT JOIN vn.invoiceOut ioc ON ioc.id = ic.correctingFk + JOIN vn.XDiario x ON x.id = mci.id + JOIN vn.client c ON c.id = i.clientFk + JOIN Naciones n ON n.countryFk = c.countryFk + JOIN vn.invoiceOutSerial ios ON ios.code = i.serial + JOIN vn.taxArea ta ON ta.code = ios.taxAreaFk + SET mci.Año = YEAR(i.issued), + mci.Serie = i.serial, + mci.Factura = RIGHT(i.ref, LENGTH(i.ref) -1), + mci.FechaFactura = i.issued, + mci.ImporteFactura = i.amount, + mci.TipoFactura = vInvoiceTypeSended, + mci.CodigoCuentaFactura = x.SUBCTA, + mci.CifDni = c.fi, + mci.Nombre = SUBSTR(c.socialName, 1, vMaxLengthName), + mci.SiglaNacion = n.SiglaNacion, + mci.EjercicioFactura = YEAR(i.issued), + mci.FechaOperacion = i.issued, + mci.MantenerAsiento = TRUE, + mci.FechaFacturaOriginal = x.FECHA_EX + WHERE mci.id = vXDiarioFk; + + SELECT correctedFk INTO vInvoiceOutCorrectedFk + FROM vn.invoiceCorrection + WHERE correctingFk = vInvoiceOutFk; + + IF vInvoiceOutCorrectedFk THEN + UPDATE movContaIVA mci + JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk + JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk + JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, + SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat, + SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ + FROM vn.invoiceOutTax iot + LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk + WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk + ) tax + JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' + SET mci.TipoRectificativa = 2, + mci.ClaseAbonoRectificativas = 1, + mci.FechaFacturaOriginal = i.issued, + mci.FechaOperacion = i.issued, + mci.BaseImponibleOriginal = tax.taxableBase, + mci.CuotaIvaOriginal = tax.vat, + mci.RecargoEquivalenciaOriginal = tax.equ, + mci.ClaveOperacionFactura = co.ClaveOperacionFactura_ + WHERE mci.id = vXDiarioFk + AND i.id = vInvoiceOutCorrectedFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/sage/procedures/invoiceOut_manager.sql b/db/routines/sage/procedures/invoiceOut_manager.sql new file mode 100644 index 000000000..58c0f2a21 --- /dev/null +++ b/db/routines/sage/procedures/invoiceOut_manager.sql @@ -0,0 +1,54 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`invoiceOut_manager`(vYear INT, vCompanyFk INT) +BEGIN +/** + * Traslada la info de contabilidad relacionada con las facturas emitidas + * + * @vYear Año contable del que se quiere trasladar la información + * @vCompany Empresa de la que se quiere trasladar datos + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vInvoiceFk INT; + DECLARE vXDiarioFk INT; + DECLARE vDatedFrom DATETIME; + DECLARE vDatedTo DATETIME; + + DECLARE vCursor CURSOR FOR + SELECT i.id, + sub2.XDiarioFk + FROM vn.invoiceOut i + JOIN (SELECT MIN(x.id) XDiarioFk, x.ASIEN, sub.refFk + FROM vn.XDiario x + JOIN (SELECT x.ASIEN, CONCAT(x.SERIE, x.FACTURA) refFk + FROM vn.XDiario x + WHERE x.enlazadoSage = FALSE + AND x.FACTURA + AND x.empresa_id = vCompanyFk + AND x.FECHA BETWEEN vDatedFrom AND vDatedTo + GROUP BY refFk + ) sub ON sub.ASIEN = x.ASIEN + GROUP BY refFk + )sub2 ON sub2.refFk = i.ref; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) + INTO vDatedFrom, vDatedTo; + + OPEN vCursor; + + l: LOOP + FETCH vCursor INTO vInvoiceFk, vXDiarioFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL invoiceOut_add(vInvoiceFk, vXDiarioFk); + + END LOOP; + + CLOSE vCursor; + +END$$ +DELIMITER ; diff --git a/db/routines/sage/procedures/pgc_add.sql b/db/routines/sage/procedures/pgc_add.sql new file mode 100644 index 000000000..6dd5bc72d --- /dev/null +++ b/db/routines/sage/procedures/pgc_add.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`pgc_add`(vCompanyFk INT) +BEGIN +/** + * Añade cuentas del plan general contable para exportarlos a Sage + * @vCompanyFk Empresa de la que se quiere trasladar datos + */ + TRUNCATE TABLE planCuentasPGC; + + INSERT INTO planCuentasPGC + (CodigoEmpresa, + CodigoCuenta, + Cuenta, + ClienteOProveedor) + SELECT * + FROM (SELECT company_getCode(vCompanyFk) companyFk, + e.id accountFk, + UCASE(e.name), + '' + FROM vn.expense e + UNION + SELECT company_getCode(vCompanyFk), + b.account, + UCASE(b.bank), + '' + FROM vn.bank b + WHERE b.isActive + AND b.`account` + UNION + SELECT CodigoEmpresa, + CodigoCuenta, + Nombre, + ClienteOProveedor + FROM clientesProveedores)sub + GROUP BY companyFk, accountFk; +END$$ +DELIMITER ; diff --git a/db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql b/db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql new file mode 100644 index 000000000..0b7a30fe1 --- /dev/null +++ b/db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `sage`.`movConta_BEFORE_UPDATE` + BEFORE UPDATE ON `movConta` + FOR EACH ROW +BEGIN + IF NEW.enlazadoSage = TRUE THEN + UPDATE vn.XDiario SET enlazadoSage = TRUE WHERE ASIEN = NEW.Asiento; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/sage/views/clientLastTwoMonths.sql b/db/routines/sage/views/clientLastTwoMonths.sql new file mode 100644 index 000000000..059cb0780 --- /dev/null +++ b/db/routines/sage/views/clientLastTwoMonths.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `sage`.`clientLastTwoMonths` +AS SELECT `vn`.`invoiceOut`.`clientFk` AS `clientFk`, + `vn`.`invoiceOut`.`companyFk` AS `companyFk` +FROM `vn`.`invoiceOut` +WHERE `vn`.`invoiceOut`.`issued` > `util`.`VN_CURDATE`() - INTERVAL 2 MONTH +UNION +SELECT `vn`.`receipt`.`clientFk` AS `clientFk`, + `vn`.`receipt`.`companyFk` AS `companyFk` +FROM `vn`.`receipt` +WHERE `vn`.`receipt`.`payed` > `util`.`VN_CURDATE`() - INTERVAL 2 MONTH diff --git a/db/routines/sage/views/supplierLastThreeMonths.sql b/db/routines/sage/views/supplierLastThreeMonths.sql new file mode 100644 index 000000000..f841fd98c --- /dev/null +++ b/db/routines/sage/views/supplierLastThreeMonths.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `sage`.`supplierLastThreeMonths` +AS SELECT `vn`.`invoiceIn`.`supplierFk` AS `supplierFk`, + `vn`.`invoiceIn`.`companyFk` AS `companyFk` +FROM `vn`.`invoiceIn` +WHERE `vn`.`invoiceIn`.`issued` > `util`.`VN_CURDATE`() - INTERVAL 3 MONTH +UNION +SELECT `vn`.`payment`.`supplierFk` AS `supplierFk`, + `vn`.`payment`.`companyFk` AS `companyFk` +FROM `vn`.`payment` +WHERE `vn`.`payment`.`received` > `util`.`VN_CURDATE`() + INTERVAL -3 MONTH diff --git a/db/routines/salix/events/accessToken_prune.sql b/db/routines/salix/events/accessToken_prune.sql new file mode 100644 index 000000000..28b04699f --- /dev/null +++ b/db/routines/salix/events/accessToken_prune.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `salix`.`accessToken_prune` + ON SCHEDULE EVERY 1 DAY + STARTS '2023-03-14 05:14:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL salix.accessToken_prune$$ +DELIMITER ; diff --git a/db/routines/salix/procedures/accessToken_prune.sql b/db/routines/salix/procedures/accessToken_prune.sql new file mode 100644 index 000000000..f1a8a0fe8 --- /dev/null +++ b/db/routines/salix/procedures/accessToken_prune.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `salix`.`accessToken_prune`() +BEGIN +/** + * Borra de la tabla salix.AccessToken todos aquellos tokens que hayan caducado + */ + DELETE FROM salix.AccessToken + WHERE outdated < NOW(); +END$$ +DELIMITER ; diff --git a/db/routines/salix/views/Account.sql b/db/routines/salix/views/Account.sql new file mode 100644 index 000000000..080e3e50b --- /dev/null +++ b/db/routines/salix/views/Account.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `salix`.`Account` +AS SELECT `u`.`id` AS `id`, + `u`.`name` AS `name`, + `u`.`password` AS `password`, + `u`.`role` AS `roleFk`, + `u`.`active` AS `active`, + `u`.`email` AS `email`, + `u`.`created` AS `created`, + `u`.`updated` AS `updated` +FROM `account`.`user` `u` diff --git a/db/routines/salix/views/Role.sql b/db/routines/salix/views/Role.sql new file mode 100644 index 000000000..b04ad82a6 --- /dev/null +++ b/db/routines/salix/views/Role.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `salix`.`Role` +AS SELECT `r`.`id` AS `id`, + `r`.`name` AS `name`, + `r`.`description` AS `description`, + `r`.`created` AS `created`, + `r`.`modified` AS `modified` +FROM `account`.`role` `r` diff --git a/db/routines/salix/views/RoleMapping.sql b/db/routines/salix/views/RoleMapping.sql new file mode 100644 index 000000000..48500a05e --- /dev/null +++ b/db/routines/salix/views/RoleMapping.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `salix`.`RoleMapping` +AS SELECT `u`.`id` * 1000 + `r`.`inheritsFrom` AS `id`, + 'USER' AS `principalType`, + `u`.`id` AS `principalId`, + `r`.`inheritsFrom` AS `roleId` +FROM ( + `account`.`user` `u` + JOIN `account`.`roleRole` `r` ON(`r`.`role` = `u`.`role`) + ) diff --git a/db/routines/salix/views/User.sql b/db/routines/salix/views/User.sql new file mode 100644 index 000000000..e03803870 --- /dev/null +++ b/db/routines/salix/views/User.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `salix`.`User` +AS SELECT `account`.`user`.`id` AS `id`, + `account`.`user`.`realm` AS `realm`, + `account`.`user`.`name` AS `username`, + `account`.`user`.`password` AS `password`, + `account`.`user`.`email` AS `email`, + `account`.`user`.`emailVerified` AS `emailVerified`, + `account`.`user`.`verificationToken` AS `verificationToken` +FROM `account`.`user` diff --git a/db/routines/srt/events/moving_clean.sql b/db/routines/srt/events/moving_clean.sql new file mode 100644 index 000000000..a6f7792a2 --- /dev/null +++ b/db/routines/srt/events/moving_clean.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `srt`.`moving_clean` + ON SCHEDULE EVERY 5 MINUTE + STARTS '2022-01-21 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE + COMMENT 'Llama a srt.moving_clean para que elimine y notifique de registr' +DO BEGIN + + CALL srt.moving_clean(); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/bid.sql b/db/routines/srt/functions/bid.sql new file mode 100644 index 000000000..ee4ffc7d3 --- /dev/null +++ b/db/routines/srt/functions/bid.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`bid`(vCode VARCHAR(3)) + RETURNS int(11) + DETERMINISTIC +BEGIN + + /** + * Devuelve el identificador de vn.buffer a partir del código + * + * @param vCode código de vn.buffer + * @return Identificador de vn.buffer + * + */ + + DECLARE vNumber INT; + DECLARE vLetter VARCHAR(1); + + IF LENGTH(vCode) < 3 THEN + + SET vCode = CONCAT('0',vCode); + + END IF; + + SELECT LEFT(vCode,2), RIGHT(vCode,1) INTO vNumber, vLetter; + + IF vLetter = 'A' THEN + + RETURN vNumber * 2; + + ELSE + + RETURN VNumber * 2 + 1; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/bufferPool_get.sql b/db/routines/srt/functions/bufferPool_get.sql new file mode 100644 index 000000000..1576381f5 --- /dev/null +++ b/db/routines/srt/functions/bufferPool_get.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`bufferPool_get`() + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Devuelve el primer bufferFk de la tabla srt.bufferPool + * + * @return Identificador de vn.buffer + * + */ + + DECLARE vBufferFk INT; + + DECLARE vBufferPoolFk INT; + + SELECT MIN(id) INTO vBufferPoolFk + FROM srt.bufferPool; + + IF vBufferPoolFk THEN + + SELECT bufferFk INTO vBufferFk + FROM srt.bufferPool + WHERE id = vBufferPoolFk; + + DELETE + FROM srt.bufferPool + WHERE id = vBufferPoolFk; + + ELSE + + RETURN NULL; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/buffer_get.sql b/db/routines/srt/functions/buffer_get.sql new file mode 100644 index 000000000..55150bd99 --- /dev/null +++ b/db/routines/srt/functions/buffer_get.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`buffer_get`(vExpeditionFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Devuelve el buffer destino para una expedición + * + * @param vExpeditionFk Identificador de srt.expedition + * @return Identificador de srt.buffer + */ + DECLARE vBufferToFk INT; + DECLARE vBufferFromFk INT; + DECLARE vBufferGroup INT; + DECLARE vBufferStrapping INT; + + SELECT IFNULL(rm.bufferFk, c.bufferDefault), IFNULL(e.bufferFk,0) + INTO vBufferToFk, vBufferFromFk + FROM srt.expedition e + LEFT JOIN vn.expedition e2 ON e2.id = e.id + LEFT JOIN vn.ticket t ON t.id = e2.ticketFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN srt.config c + WHERE e.id = vExpeditionFk; + + SELECT `group` INTO vBufferGroup + FROM srt.bufferGroup + WHERE bufferFk = vBufferToFk; + + SELECT bg.bufferFk + INTO vBufferStrapping + FROM srt.bufferGroup bg + JOIN srt.buffer b ON b.id = bg.bufferFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE bt.typeName = 'STRAPPING' + AND bg.`group` = vBufferGroup + LIMIT 1; + + IF vBufferGroup THEN + SELECT sub.bufferFk INTO vBufferToFk + FROM ( + SELECT b.id bufferFk, + count(DISTINCT e.id) expeditions, + bs.description, + bt.typeName, + b.motors + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.bufferState bs ON bs.id = b.stateFk + JOIN srt.bufferGroup bg ON bg.bufferFk = b.id + LEFT JOIN srt.expedition e ON e.bufferFk = b.id + LEFT JOIN srt.moving m ON m.bufferFromFk = b.id + WHERE bg.`group` = vBufferGroup + AND b.id != vBufferFromFk + AND bt.isTarget + AND m.id IS NULL + GROUP BY b.id) sub + JOIN srt.config c + ORDER BY (sub.description = 'FREE') DESC, + (sub.typeName = ('STRAPPING')) DESC, + IF(c.isBalanced , sub.expeditions, -sub.expeditions), + ABS(sub.bufferFk - vBufferStrapping) + LIMIT 1; + END IF; + + RETURN vBufferToFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/buffer_getRandom.sql b/db/routines/srt/functions/buffer_getRandom.sql new file mode 100644 index 000000000..bc7229594 --- /dev/null +++ b/db/routines/srt/functions/buffer_getRandom.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`buffer_getRandom`() + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /* Devuelve de forma aleatoria, uno de entre los buffers que tienen flejadora + * + */ + + DECLARE vBufferFk INT; + + SELECT b.id INTO vBufferFk + FROM srt.buffer b + WHERE b.hasStrapper + ORDER BY RAND() + LIMIT 1; + + RETURN vBufferFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/buffer_getState.sql b/db/routines/srt/functions/buffer_getState.sql new file mode 100644 index 000000000..b5c4ac2e4 --- /dev/null +++ b/db/routines/srt/functions/buffer_getState.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`buffer_getState`(vSelf INT) + RETURNS varchar(20) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Devuelve una cadena con el estado del buffer + * + */ + + DECLARE vState VARCHAR(20); + + SELECT bs.description INTO vState + FROM srt.buffer b + JOIN srt.bufferState bs ON bs.id = b.stateFk + WHERE b.id = vSelf; + + RETURN vState; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/buffer_getType.sql b/db/routines/srt/functions/buffer_getType.sql new file mode 100644 index 000000000..4b4194b3c --- /dev/null +++ b/db/routines/srt/functions/buffer_getType.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`buffer_getType`(vSelf INT) + RETURNS varchar(20) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Devuelve una cadena con el tipo del buffer + * + */ + + DECLARE vType VARCHAR(20); + + SELECT bt.typeName INTO vType + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE b.id = vSelf; + + RETURN vType; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/buffer_isFull.sql b/db/routines/srt/functions/buffer_isFull.sql new file mode 100644 index 000000000..a1ae08484 --- /dev/null +++ b/db/routines/srt/functions/buffer_isFull.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`buffer_isFull`(vBufferFk INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Comprueba si un buffer está lleno + * + * @param vBufferFk Identificador de vn.buffer + * + */ + + DECLARE vBufferStock INT; + DECLARE vIsFull BOOL; + + SELECT COUNT(*) INTO vBufferStock + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e.bufferFk = vBufferFk + AND ISNULL(m.id); + + SELECT vBufferStock + COUNT(*) INTO vBufferStock + FROM srt.moving m + WHERE m.bufferToFk = vBufferFk; + + SELECT (vBufferStock >= maxBoxesInBuffer) INTO vIsFull + FROM srt.config; + + RETURN vIsFull; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/dayMinute.sql b/db/routines/srt/functions/dayMinute.sql new file mode 100644 index 000000000..ab66dd7d2 --- /dev/null +++ b/db/routines/srt/functions/dayMinute.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`dayMinute`(vDateTime DATETIME) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /* + * Devuelve el numero de minutos absoluto diario + * + * @vDateTime Fecha a analizar + * + */ + + RETURN HOUR(vDateTime) * 60 + MINUTE(vDateTime); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/expedition_check.sql b/db/routines/srt/functions/expedition_check.sql new file mode 100644 index 000000000..314cafd96 --- /dev/null +++ b/db/routines/srt/functions/expedition_check.sql @@ -0,0 +1,60 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`expedition_check`(vExpeditionFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Comprueba si existe una expedición, generando una aleatoria en caso contrario. + * + * @param vExpeditionFk Identificador de srt.expedition + * + */ + + DECLARE vExpeditionOutFk INT; + DECLARE vIsOnTheCelluveyor BOOL; + + SELECT id INTO vExpeditionOutFk + FROM srt.expedition + WHERE id = vExpeditionFk; + + SELECT COUNT(*) INTO vIsOnTheCelluveyor + FROM srt.moving m + JOIN srt.movingState ms ON ms.id = m.stateFk + WHERE m.expeditionFk = vExpeditionFk + AND ms.description != 'NEW'; + + IF ISNULL(vExpeditionOutFk) OR vIsOnTheCelluveyor THEN + + SELECT LEAST(-1,MIN(id)- 1) INTO vExpeditionOutFk + FROM srt.expedition; + + CASE vExpeditionFk + + WHEN 0 THEN -- Genera una EXP que termine en 0 + + SET vExpeditionOutFk = CEIL((vExpeditionOutFk - 10) / 10) * 10; + + WHEN 2 THEN -- Genera una EXP que termine en 2 + + SET vExpeditionOutFk = -2 + CEIL((vExpeditionOutFk - 10) / 10) * 10; + + ELSE -- Genera una EXP que termine en 9 + + SET vExpeditionOutFk = -9 + CEIL((vExpeditionOutFk - 10) / 10) * 10; + + END CASE; + + INSERT INTO srt.expedition(id,stateFk,width,`length`, height) + SELECT vExpeditionOutFk, es.id , p.width * 10, p.`depth` *10, p.height * 10 + FROM srt.expeditionState es + JOIN vn.packaging p ON p.id = '94' + WHERE es.description = 'ENTERING'; + + END IF; + + RETURN vExpeditionOutFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/functions/expedition_getDayMinute.sql b/db/routines/srt/functions/expedition_getDayMinute.sql new file mode 100644 index 000000000..7a8fae686 --- /dev/null +++ b/db/routines/srt/functions/expedition_getDayMinute.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `srt`.`expedition_getDayMinute`(vExpeditionFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Devuelve el minuto absoluto ( un dia tiene 24 x 60 minutos ) de salida del camión + * + * @param vExpeditionFk Identificador de srt.expedition + * + * @return vDayMinute Minuto absoluto diario + */ + + DECLARE vDayMinute INT; + + SELECT HOUR(IFNULL(et.ETD, z.`hour`)) * 60 + MINUTE(IFNULL(et.ETD, z.`hour`)) INTO vDayMinute + FROM vn.expedition e + JOIN vn.ticket t ON e.ticketFk = t.id + JOIN vn.`zone` z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON t.routeFk = rm.routeFk + LEFT JOIN vn.expeditionTruck et ON rm.expeditionTruckFk = et.id + WHERE e.id = vExpeditionFk; + + RETURN vDayMinute; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_getExpCount.sql b/db/routines/srt/procedures/buffer_getExpCount.sql new file mode 100644 index 000000000..5ead3d421 --- /dev/null +++ b/db/routines/srt/procedures/buffer_getExpCount.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_getExpCount`(IN vBufferFk INT, OUT vExpCount INT) +BEGIN +/* Devuelve el número de expediciones de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @param vExpCount Número de expediciones + */ + SELECT COUNT(*) + INTO vExpCount + FROM srt.expedition + WHERE bufferFk = vBufferFk; +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_getStateType.sql b/db/routines/srt/procedures/buffer_getStateType.sql new file mode 100644 index 000000000..bba8202db --- /dev/null +++ b/db/routines/srt/procedures/buffer_getStateType.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_getStateType`(vBufferFk INT, OUT vStateFk INT, OUT vTypeFk INT) +BEGIN + + /** + * Devuelve el estado y el tipo de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @return vStateFk Identificador de srt.bufferState + * @return vTypeFk Identificador de srt.bufferType + * + */ + + SELECT b.stateFk, b.typeFk INTO vStateFk, vTypeFk + FROM srt.buffer b + WHERE b.id = vBufferFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_giveBack.sql b/db/routines/srt/procedures/buffer_giveBack.sql new file mode 100644 index 000000000..f8d349914 --- /dev/null +++ b/db/routines/srt/procedures/buffer_giveBack.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_giveBack`(vSelf INT) +BEGIN + + /* Devuelve una caja al celluveyor * + * + * @param vSelf Identificador de srt.buffer + */ + + DECLARE vExpeditionFk INT; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + WHERE e.bufferFk = vSelf + ORDER BY e.`position` + LIMIT 1; + + IF vExpeditionFk THEN + + CALL srt.expedition_relocate(vExpeditionFk, srt.buffer_get(vExpeditionFk)); + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_readPhotocell.sql b/db/routines/srt/procedures/buffer_readPhotocell.sql new file mode 100644 index 000000000..2bf2cfa1d --- /dev/null +++ b/db/routines/srt/procedures/buffer_readPhotocell.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_readPhotocell`(vSelf INT, vNumber INT) +BEGIN +/** + * Establece el estado de un buffer en función del número de fotocélulas activas + * + * @param vSelf Identificador de srt.buffer + * @param vNumber Número de fotocélulas activas + */ + DECLARE vIsFull BOOL; + DECLARE vBoxes INT; + DECLARE vMotors INT; + DECLARE vMargin INT; + + SELECT ((COUNT(*) + vNumber + c.motorsMargin) >= b.motors AND b.motors > 1), COUNT(*), b.motors, c.motorsMargin + INTO vIsFull, vBoxes, vMotors, vMargin + FROM srt.buffer b + LEFT JOIN srt.moving m ON m.bufferToFk = b.id + JOIN srt.config c + WHERE b.id = vSelf; + + IF vIsFull THEN + CALL srt.buffer_setStateType(vSelf, 'FULL', NULL); + ELSE + CALL srt.buffer_setStateType(vSelf, 'FREE', NULL); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_setEmpty.sql b/db/routines/srt/procedures/buffer_setEmpty.sql new file mode 100644 index 000000000..e97d397ed --- /dev/null +++ b/db/routines/srt/procedures/buffer_setEmpty.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_setEmpty`(vBufferFk INT) +BEGIN + + /** + * Actualiza a NULL el valor bufferFk de las expediciones que esten en ese buffer + * + * @param vBufferFk Identificador de srt.buffer + * + */ + + UPDATE srt.expedition e + SET e.bufferFk = NULL + WHERE e.bufferFk = vBufferFk; + + UPDATE srt.buffer b + SET b.typeFk = b.typeDefaultFk + WHERE b.id = vBufferFk; + + CALL srt.buffer_setStateType(vBufferFk, 'FREE', NULL); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_setState.sql b/db/routines/srt/procedures/buffer_setState.sql new file mode 100644 index 000000000..f0f136942 --- /dev/null +++ b/db/routines/srt/procedures/buffer_setState.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_setState`(vBufferFk INT(11), vStateFk INT(11)) +BEGIN + + /** + * Cambia el estado de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @param vStateFk Identificador de srt.bufferState + * + */ + + UPDATE srt.buffer b + SET b.stateFk = vStateFk + WHERE b.id = vBufferFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_setStateType.sql b/db/routines/srt/procedures/buffer_setStateType.sql new file mode 100644 index 000000000..954a380ac --- /dev/null +++ b/db/routines/srt/procedures/buffer_setStateType.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_setStateType`(vBufferFk INT, vState VARCHAR(25), vType VARCHAR(25)) +BEGIN + + /** + * Cambia el estado y el tipo de un buffer + * + * @param vBufferFk Identificador del buffer + * @param vState Estado + * @param vType Tipo + * + */ + + DECLARE vBufferStateFk INT; + DECLARE vBufferTypeFk INT; + + IF NOT ISNULL(vState) THEN + + SELECT bs.id INTO vBufferStateFk + FROM srt.bufferState bs + WHERE bs.description = vState; + + CALL srt.buffer_setState(vBufferFk, vBufferStateFk); + + END IF; + + IF NOT ISNULL(vType) THEN + + IF vType = 'DEFAULT' THEN + + SELECT b.typeDefaultFk INTO vBufferTypeFk + FROM srt.buffer b + WHERE b.id = vBufferFk; + + ELSE + + SELECT bt.id INTO vBufferTypeFk + FROM srt.bufferType bt + WHERE bt.typeName = vType; + + END IF; + + CALL srt.buffer_setType(vBufferFk, vBufferTypeFk); + + IF vType = 'UNLOADING' THEN + + UPDATE srt.buffer + SET lastUnloaded = util.VN_NOW() + WHERE id = vBufferFk; + + END IF; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_setType.sql b/db/routines/srt/procedures/buffer_setType.sql new file mode 100644 index 000000000..7d6c508dc --- /dev/null +++ b/db/routines/srt/procedures/buffer_setType.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_setType`(vBufferFk INT(11), vTypeFk INT(11)) +BEGIN +/** + * Cambia el tipo de un buffer, si está permitido + * + * @param vBufferFk Identificador de srt.buffer + * @param vTypeFk Identificador de srt.bufferType + * + */ + UPDATE srt.buffer b + JOIN srt.config c + JOIN srt.bufferType bt ON bt.typeName = 'UNLOADING' + SET b.typeFk = vTypeFk + WHERE b.id = vBufferFk + AND (vTypeFk <> bt.id OR c.isAllowedUnloading); +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/buffer_setTypeByName.sql b/db/routines/srt/procedures/buffer_setTypeByName.sql new file mode 100644 index 000000000..9365d5399 --- /dev/null +++ b/db/routines/srt/procedures/buffer_setTypeByName.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`buffer_setTypeByName`(vBufferFk INT(11), vTypeName VARCHAR(100)) +BEGIN + + /** + * Cambia el tipo de un buffer + * + * @param vBufferFk Identificador de srt.buffer + * @param vTypeName Nombre Identificador de srt.bufferType + * + */ + + DECLARE vTypeFk INT; + + SELECT bt.id INTO vTypeFk + FROM srt.bufferType bt + WHERE bt.typeName = vTypeName; + + UPDATE srt.buffer b + SET b.typeFk = vTypeFk + WHERE b.id = vBufferFk; + + SELECT count(*) + FROM srt.buffer b + WHERE b.id = vBufferFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/clean.sql b/db/routines/srt/procedures/clean.sql new file mode 100644 index 000000000..3d02ae0cd --- /dev/null +++ b/db/routines/srt/procedures/clean.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`clean`() +BEGIN + DECLARE vLastDated DATE DEFAULT TIMESTAMPADD(WEEK,-2,util.VN_CURDATE()); + + DELETE FROM srt.lastRFID + WHERE created < vLastDated; + + DELETE FROM srt.expedition + WHERE created < vLastDated; + + DELETE FROM srt.moving; +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expeditionLoading_add.sql b/db/routines/srt/procedures/expeditionLoading_add.sql new file mode 100644 index 000000000..7fb53c2c6 --- /dev/null +++ b/db/routines/srt/procedures/expeditionLoading_add.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expeditionLoading_add`(vExpeditionFk INT, vBufferFk INT) +BEGIN + + DECLARE vMessage VARCHAR(50) DEFAULT ''; + + IF (SELECT COUNT(*) FROM srt.buffer WHERE id = vBufferFk) = 0 THEN + + SET vMessage = 'Buffer incorrecto'; + + END IF; + + IF (SELECT COUNT(*) FROM srt.expedition WHERE id = vExpeditionFk) = 0 THEN + + SET vMessage = 'Expedición no existe'; + + END IF; + + IF LENGTH(vMessage) = 0 THEN + + REPLACE srt.expeditionLoading (expeditionFk, bufferFk) + VALUES (vExpeditionFk, vBufferFk); + + SET vMessage = 'Registro añadido'; + + END IF; + + SELECT vMessage; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_arrived.sql b/db/routines/srt/procedures/expedition_arrived.sql new file mode 100644 index 000000000..2d2c093bc --- /dev/null +++ b/db/routines/srt/procedures/expedition_arrived.sql @@ -0,0 +1,83 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_arrived`(vExpeditionFk INT, vBufferFk INT, OUT vTypeFk INT) +BEGIN +/** + * La expedición ha entrado en un buffer, superando fc2 + * + * @param vExpeditionFk Identificador de srt.expedition + * @param vBufferFk Identificador de srt.buffer + * + * @return vTypeFk Identificador de srt.bufferType + * + */ + DECLARE vComingBoxes INT; + DECLARE vHasWorkerWaiting BOOL; + DECLARE vIsRandomMoving BOOL; + DECLARE vState VARCHAR(15); + DECLARE vType VARCHAR(15); + DECLARE visBufferWhithoutBoxesCount BOOL; + + IF vBufferFk = 1 THEN + SET vBufferFk = 0; + END IF; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'ARR'); + + SELECT COUNT(*) INTO vComingBoxes + FROM srt.moving m + WHERE m.bufferToFk = vBufferFk + AND m.expeditionFk != vExpeditionFk; + + SELECT b.hasWorkerWaiting, + c.isRandomMoving , + (bt.typeName = 'STRAPPING') OR vBufferFk IN (c.bufferNoLabels, c.bufferTwoLabels, c.bufferDefault) + INTO vHasWorkerWaiting, + vIsRandomMoving, + visBufferWhithoutBoxesCount + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.config c + WHERE b.id = vBufferFk + LIMIT 1; + + SET vState = IF(srt.buffer_isFull(vBufferFk), 'FULL', 'FREE'); + + SET vType = IF(vHasWorkerWaiting + AND NOT vComingBoxes + AND NOT vIsRandomMoving + AND vState = 'FULL', 'UNLOADING', 'ACCUMULATION'); + + IF NOT visBufferWhithoutBoxesCount THEN + CALL srt.buffer_setStateType(vBufferFk,vState,vType); + END IF; + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'STORED' + SET e.bufferFk = IF(visBufferWhithoutBoxesCount,0,vBufferFk), + e.`position` = 0, + e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + UPDATE srt.expedition e + SET e.`position` = e.`position` + 1 + WHERE e.bufferFk = vBufferFk + AND e.bufferFk > 0; + + INSERT INTO srt.movingLog(expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, movingFk, `action`) + SELECT expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, id, 'ARRIVED' + FROM srt.moving + WHERE expeditionFk = vExpeditionFk + ORDER BY id DESC + LIMIT 1; + + DELETE FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + + SELECT bt.id INTO vTypeFk + FROM srt.bufferType bt + JOIN srt.buffer b ON b.typeFk = bt.id + WHERE b.id = vBufferFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_bufferOut.sql b/db/routines/srt/procedures/expedition_bufferOut.sql new file mode 100644 index 000000000..69e1fb791 --- /dev/null +++ b/db/routines/srt/procedures/expedition_bufferOut.sql @@ -0,0 +1,82 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_bufferOut`(vBufferToFk INT) +BEGIN + + /** + * Selecciona y enruta las expediciones en el sorter hacia un buffer de salida, que sean de ese buffer + * + * @param vBufferToFk Identificador de srt.buffer + */ + + DECLARE vExpListFk INT; + + DECLARE vExpBufFk INT; + + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vExpList CURSOR FOR + SELECT bs.expeditionFk + FROM srt.bufferStock bs + JOIN srt.expedition e ON e.id = bs.expeditionFk + LEFT JOIN srt.moving m ON m.expeditionFk = bs.expeditionFk + WHERE bs.routeBuffer = vBufferToFk + AND ISNULL(m.expeditionFk) + AND bs.typeName = 'ACCUMULATION' + ORDER BY (vBufferToFk - e.bufferFk), + e.`position` ; + + DECLARE vExpBuf CURSOR FOR + SELECT e.id + FROM srt.expedition e + JOIN srt.expedition e2 ON e2.bufferFk = e.bufferFk + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e2.id = vExpListFk + AND ISNULL(m.expeditionFk) + AND e.`position` <= e2.`position` + ORDER BY e.`position`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vExpList; + + FETCH vExpList INTO vExpListFk; + + WHILE NOT vDone DO + + OPEN vExpBuf; + + FETCH vExpBuf INTO vExpBufFk; + + WHILE NOT vDone DO + + IF vExpBufFk = vExpListFk THEN + + CALL srt.expedition_relocate(vExpListFk, vBufferToFk); + + SET vDone = TRUE; + + ELSE + + CALL srt.expedition_relocate(vExpBufFk, NULL); + + SET vDone = FALSE; + + FETCH vExpBuf INTO vExpBufFk; + + END IF; + + END WHILE; + + CLOSE vExpBuf; + + SET vDone = FALSE; + + FETCH vExpList INTO vExpListFk; + + END WHILE; + + CLOSE vExpList; + + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_entering.sql b/db/routines/srt/procedures/expedition_entering.sql new file mode 100644 index 000000000..f1b773edb --- /dev/null +++ b/db/routines/srt/procedures/expedition_entering.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_entering`(vExpeditionFk INT, OUT vExpeditionOutFk INT ) +BEGIN + + /** + * Una expedición llega a la entrada del celuveyor y comunica su ID + * + * @param vExpeditionFk Identificador de srt.expedition + * + * @return vExpeditionOutFk Identificador de srt.expedition + * + */ + + DECLARE vBufferFk INT DEFAULT NULL; + + SET vExpeditionOutFk = srt.expedition_check(vExpeditionFk); + + IF vExpeditionOutFk < 0 THEN + + SELECT IF(vExpeditionOutFk MOD 10 = 0, c.bufferNoLabels, c.bufferTwoLabels) + INTO vBufferFk + FROM srt.config c; + + END IF; + + UPDATE srt.expedition e + SET e.bufferFk = 0 + WHERE id = vExpeditionOutFk; + + UPDATE srt.moving m + JOIN srt.movingState ms ON ms.description = 'NEW' + SET m.stateFk = ms.id + WHERE m.expeditionFk = vExpeditionOutFk; + + IF (SELECT isAuto FROM srt.config) THEN + + SELECT b.id INTO vBufferFk + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE b.isActive + ORDER BY (bt.typeName = 'STRAPPING') DESC, + b.hasWorkerWaiting DESC, + srt.buffer_IsFull(b.id), + b.stateFk, + b.typeFk, + b.lastUnloaded, + b.id DESC + LIMIT 1; + + END IF; +/* + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionOutFk, 0, 'ENT'); + + INSERT INTO srt.enteringLog(expeditionFk , expeditionOutFk ) + VALUES(vExpeditionFk, vExpeditionOutFk); +*/ + CALL srt.expedition_relocate(vExpeditionOutFk, vBufferFk); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_get.sql b/db/routines/srt/procedures/expedition_get.sql new file mode 100644 index 000000000..91a0e2ace --- /dev/null +++ b/db/routines/srt/procedures/expedition_get.sql @@ -0,0 +1,77 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_get`(vAntennaFk INT, OUT vExpeditionOutFk INT ) +BEGIN + + DECLARE vId INT; + DECLARE vCount INT; + DECLARE vCreatedMin DATETIME; + DECLARE vCreatedMax DATETIME; + DECLARE vSecondsScope INT DEFAULT 30; + + START TRANSACTION; + + SELECT count(DISTINCT lr.code) INTO vCount + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted; + + CASE vCount + + WHEN 0 THEN + + SET vExpeditionOutFk = srt.expedition_check(vCount); + + WHEN 1 THEN + + SELECT CAST(code AS DECIMAL(10,0)), lr.id + INTO vExpeditionOutFk, vId + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted + ORDER BY lr.seenCount DESC, lr.peakRssi + LIMIT 1; + + ELSE + + -- Descartamos aquellas lecturas que se han producido unos segundos antes. + SELECT MIN(created), MAX(created) INTO vCreatedMin, vCreatedMax + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted; + + UPDATE srt.lastRFID lr + JOIN (SELECT id, code + FROM srt.lastRFID + WHERE created + BETWEEN TIMESTAMPADD(SECOND, - vSecondsScope, vCreatedMin) + AND TIMESTAMPADD(SECOND, -1, vCreatedMin) + AND isChoosed = 1# + ) sub ON sub.code = lr.code AND sub.id != lr.id + SET lr.isConsulted = TRUE + WHERE lr.created BETWEEN vCreatedMin AND vCreatedMax + AND lr.antennaFk = vAntennaFk; + + SELECT CAST(code AS DECIMAL(10,0)), lr.id + INTO vExpeditionOutFk, vId + FROM srt.lastRFID lr + WHERE lr.antennaFk = vAntennaFk + AND NOT isConsulted + ORDER BY lr.peakRssi DESC, lr.seenCount DESC # + LIMIT 1; + + END CASE; + + UPDATE srt.lastRFID + SET isChoosed = TRUE + WHERE id = vId; + + UPDATE srt.lastRFID + SET isConsulted = TRUE + WHERE antennaFk = vAntennaFk + AND NOT isConsulted; + + COMMIT; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`, antennaFk) VALUES(vExpeditionOutFk, 0, 'DIM', vAntennaFk); +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_groupOut.sql b/db/routines/srt/procedures/expedition_groupOut.sql new file mode 100644 index 000000000..5c4540ff6 --- /dev/null +++ b/db/routines/srt/procedures/expedition_groupOut.sql @@ -0,0 +1,91 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_groupOut`(vDayMinute INT, vBufferToFk INT) +BEGIN + + /** + * Selecciona y enruta las expediciones en el sorter hacia un buffer de salida, que sean de la hora pedida + * + * @param vDayMinute Minuto absoluto del dia + * @param vBufferToFk Identificador de srt.buffer + * + */ + + DECLARE vExpListFk INT; + + DECLARE vExpBufFk INT; + + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vExpList CURSOR FOR + SELECT bs.expeditionFk + FROM srt.bufferStock bs + JOIN srt.expedition e ON e.id = bs.expeditionFk + WHERE bs.dayMinute = vDayMinute + AND bs.expeditionState = 'STORED' + AND bs.isActive + AND bs.hasWorkerWaiting = FALSE + AND bs.typeName = 'ACCUMULATION' + ORDER BY (vBufferToFk - e.bufferFk), + e.`position`; + + DECLARE vExpBuf CURSOR FOR + SELECT e.id + FROM srt.expedition e + JOIN srt.expedition e2 ON e2.bufferFk = e.bufferFk + JOIN srt.expeditionState es ON es.id = e.stateFk + WHERE e2.id = vExpListFk + AND e.`position` <= e2.`position` + AND es.description = 'STORED' + ORDER BY e.`position`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vExpList; + + FETCH vExpList INTO vExpListFk; + + UPDATE srt.moving m + JOIN srt.movingState ms ON ms.id = m.stateFk + SET m.bufferToFk = vBufferToFk + WHERE m.expeditionFk = vExpListFk + AND ms.isRedirectable + AND m.bufferFromFk != vBufferToFk; + + WHILE NOT vDone DO + + OPEN vExpBuf; + + FETCH vExpBuf INTO vExpBufFk; + + WHILE NOT vDone DO + + IF vExpBufFk = vExpListFk THEN + + CALL srt.expedition_Relocate(vExpListFk, vBufferToFk); + + SET vDone = TRUE; + + ELSE + + CALL srt.expedition_Relocate(vExpBufFk, NULL); + + SET vDone = FALSE; + + FETCH vExpBuf INTO vExpBufFk; + + END IF; + + END WHILE; + + CLOSE vExpBuf; + + SET vDone = FALSE; + + FETCH vExpList INTO vExpListFk; + + END WHILE; + + CLOSE vExpList; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_in.sql b/db/routines/srt/procedures/expedition_in.sql new file mode 100644 index 000000000..c6f75876c --- /dev/null +++ b/db/routines/srt/procedures/expedition_in.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_in`(vBufferFk INT, OUT vExpeditionFk INT) +proc:BEGIN + + /** + * Ha entrado una caja en un buffer, por la zona de descarga. + * + * @param vBufferFk Identificador de srt.buffer + * + * @return vExpeditionFk Identificador de srt.expedition * + */ + + DECLARE vMaxPosition INT; + DECLARE vIsBufferFull BOOL; + DECLARE vBufferTypeFk INT; + DECLARE vBufferStateFk INT; + + SELECT el.expeditionFk INTO vExpeditionFk + FROM srt.expeditionLoading el + WHERE el.bufferFk = vBufferFk + ORDER BY id + LIMIT 1; + + IF vExpeditionFk THEN + + DELETE FROM srt.expeditionLoading + WHERE expeditionFk = vExpeditionFk; + + -- SET vExpeditionFk = srt.expedition_check(vExpeditionFk); + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'IN'); + + SELECT MAX(e.position) INTO vMaxPosition + FROM srt.expedition e + WHERE e.bufferFk = vBufferFk; + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'STORED' + SET e.bufferFk = vBufferFk, + e.`position` = IFNULL(vMaxPosition,0) + 1, + e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + SELECT bfl.freeLength < c.freeLength * 2 INTO vIsBufferFull + FROM srt.bufferFreeLength bfl + JOIN srt.config c + WHERE bfl.bufferFk = vBufferFk; + + IF vIsBufferFull THEN + + CALL srt.buffer_setStateType(vBufferFk, 'FREE','ACCUMULATION'); + + END IF; + + END IF; + + + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_moving.sql b/db/routines/srt/procedures/expedition_moving.sql new file mode 100644 index 000000000..1277ed2bd --- /dev/null +++ b/db/routines/srt/procedures/expedition_moving.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_moving`(vBufferFk INT) +BEGIN + + /** + * Una expedición ha entrado en el celuveyor desde un buffer + * + * @param vBufferFk Identificador de srt.buffer + * + */ + + DECLARE vExpeditionFk INT; + DECLARE vPosition INT; + + SELECT min(`position`) INTO vPosition + FROM srt.expedition e + WHERE e.bufferFk = vBufferFk; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + WHERE e.`position` = vPosition + AND e.bufferFk = vBufferFk + LIMIT 1; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'MOV'); + + UPDATE srt.expedition e + JOIN srt.expeditionState es on es.description = 'MOVING' + JOIN srt.moving m ON m.expeditionFk = e.id + SET e.stateFk = es.id, + e.bufferFk = m.bufferToFk, + e.`position` = 0 + WHERE e.id = vExpeditionFk; + + SET @posicion := 0; + + UPDATE srt.expedition e + SET e.`position` = @posicion := @posicion + 1 + WHERE e.bufferFk = vBufferFk + AND e.id != vExpeditionFk + ORDER BY e.`position`; + + CALL srt.buffer_setStateType(vBufferFk, 'FREE', NULL); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_out.sql b/db/routines/srt/procedures/expedition_out.sql new file mode 100644 index 000000000..5e6608561 --- /dev/null +++ b/db/routines/srt/procedures/expedition_out.sql @@ -0,0 +1,68 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_out`(vBufferFk INT, OUT vTypeFk INT) +proc:BEGIN +/** + * Una expedición ha salido de un buffer por el extremo distal + * Se ignorará en caso de que el buffer esté en modo ACCUMULATION + * + * @param vBufferFk Identificador de srt.buffer + * + * @return vTypeFk Identificador de srt.bufferType + */ + + DECLARE vMaxPosition INT; + DECLARE vIsFree BOOL; + DECLARE vExpeditionFk INT; + DECLARE vBufferType VARCHAR(15); + + SELECT bt.typeName + INTO vBufferType + FROM srt.buffer b + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE b.id = vBufferFk; + + IF vBufferType = 'ACCUMULATION' THEN + LEAVE proc; + END IF; + + SELECT MAX(e.`position`) INTO vMaxPosition + FROM srt.expedition e + WHERE e.bufferFk = vBufferFk; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + WHERE e.`position` = vMaxPosition + AND e.bufferFk = vBufferFk + LIMIT 1; + + INSERT INTO srt.expeditionLog (expeditionFk, bufferFk, `action`) + VALUES(vExpeditionFk, vBufferFk, 'OUT'); + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'OUT' + SET e.bufferFk = NULL, + e.`position` = NULL, + e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + SELECT (COUNT(*) = 0) INTO vIsFree + FROM srt.expedition e + JOIN srt.buffer b ON b.id = e.bufferFk + WHERE e.bufferFk = vBufferFk + AND e.`position` > 0; + + IF vIsFree AND vBufferType NOT IN('LOADING','STRAPPING') THEN + + UPDATE srt.buffer SET reserve = NULL, routeFk = NULL, dayMinute = NULL + WHERE id = vBufferFk; + + CALL srt.buffer_setStateType(vBufferFk,'FREE','DEFAULT'); + + END IF; + + SELECT b.typeFk INTO vTypeFk + FROM srt.buffer b + WHERE b.id = vBufferFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_outAll.sql b/db/routines/srt/procedures/expedition_outAll.sql new file mode 100644 index 000000000..ffe925c9d --- /dev/null +++ b/db/routines/srt/procedures/expedition_outAll.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_outAll`(vBufferFk INT) +BEGIN + + /** + * Envia todas las expediciones al mismo buffer + * + * @param vBufferFk Identificador de vn.buffer + * + */ + + INSERT INTO srt.moving (expeditionFk, bufferFromFk, bufferToFk) + SELECT e.id, e.bufferFk, vBufferFk + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e.bufferFk > 0 + AND e.bufferFk != vBufferFk + AND ISNULL(m.expeditionFk); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_relocate.sql b/db/routines/srt/procedures/expedition_relocate.sql new file mode 100644 index 000000000..0f940beff --- /dev/null +++ b/db/routines/srt/procedures/expedition_relocate.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_relocate`(vExpeditionFk INT, vBufferToFk INT) +proc:BEGIN + + /** + * Asigna buffer destino nuevo para una expedición + * + * @param vExpeditionFk Identificacion de srt.expedition + * + * @param vBufferToFk Identificador de srt.buffer + * + */ + + DECLARE vBufferFromFk INT; + + START TRANSACTION; + + IF (SELECT COUNT(*) FROM srt.moving WHERE expeditionFk = vExpeditionFk) THEN + + LEAVE proc; + + END IF; + + SELECT e.bufferFk INTO vBufferFromFk + FROM srt.expedition e + WHERE e.id = vExpeditionFk; + + SET vBufferToFk = IFNULL(vBufferToFk, IFNULL(srt.bufferPool_get(), `srt`.`buffer_get`(vExpeditionFk))); + + IF vBufferFromFk = vBufferToFk THEN + + LEAVE proc; + + END IF; + + REPLACE srt.moving (expeditionFk, + bufferFromFk, + bufferToFk, + stateFk) + SELECT e.id, + e.bufferFk, + vBufferToFk, + ms.id + FROM srt.expedition e + JOIN srt.movingState ms ON ms.description = 'NEW' + LEFT JOIN srt.moving m ON m.expeditionFk + WHERE e.id = vExpeditionFk; + + UPDATE srt.expedition e + JOIN srt.expeditionState es on es.description = 'ENTERING' + JOIN srt.moving m ON m.expeditionFk = e.id + SET e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + COMMIT; + + IF srt.buffer_isFull(vBufferToFk) THEN + + CALL srt.buffer_setStateType(vBufferToFk,'FULL', NULL); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_reset.sql b/db/routines/srt/procedures/expedition_reset.sql new file mode 100644 index 000000000..712c93e18 --- /dev/null +++ b/db/routines/srt/procedures/expedition_reset.sql @@ -0,0 +1,309 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_reset`() +BEGIN + + DELETE FROM srt.moving; + DELETE FROM srt.expedition; + + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(3223666, NULL, 280.00, 900.00, 280.00, NULL, NULL, 1, '2021-08-25 11:32:16.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634827, NULL, 320.01, 1008.00, 330.00, 10, 54, 5, '2021-07-15 10:28:21.0', '2021-08-27 14:16:32.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634836, NULL, 310.01, 1110.00, 300.00, 2, 3, 5, '2021-07-15 10:31:45.0', '2021-08-27 12:07:46.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634840, NULL, 300.01, 1000.00, 230.00, 13, 2, 5, '2021-07-15 10:32:13.0', '2021-08-27 13:03:48.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634871, NULL, 320.01, 1080.00, 330.00, 2, 4, 5, '2021-07-15 10:36:30.0', '2021-08-27 12:07:46.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4634872, NULL, 300.00, 900.00, 250.00, 5, 1, 5, '2021-07-15 10:36:49.0', '2021-08-27 12:29:57.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4637714, NULL, 260.01, 520.00, 210.00, NULL, NULL, 1, '2021-07-16 09:43:46.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4637715, NULL, 260.01, 520.00, 210.00, NULL, NULL, 1, '2021-07-16 09:43:51.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4637716, NULL, 260.01, 520.00, 210.00, 9, 1, 4, '2021-07-16 09:43:55.0', '2021-08-27 12:08:33.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651292, NULL, 250.01, 1010.00, 150.00, NULL, NULL, 1, '2021-07-22 09:00:56.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651293, NULL, 300.01, 980.00, 160.00, 0, 1, 5, '2021-07-22 09:03:44.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651295, NULL, 490.01, 1180.00, 250.00, 0, 1, 5, '2021-07-22 09:07:08.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651298, NULL, 260.01, 1040.00, 240.00, 0, 1, 5, '2021-07-22 09:15:57.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651300, NULL, 490.01, 1180.00, 250.00, 0, 1, 5, '2021-07-22 09:17:06.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651302, NULL, 490.01, 1180.00, 250.00, NULL, NULL, 1, '2021-07-22 09:18:04.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651303, NULL, 370.01, 840.00, 180.00, 0, 1, 5, '2021-07-22 09:19:45.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651304, NULL, 260.01, 1040.00, 260.00, 0, 1, 5, '2021-07-22 09:21:07.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651305, NULL, 260.01, 1040.00, 260.00, 2, 7, 5, '2021-07-22 09:23:26.0', '2021-08-27 12:07:46.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651306, NULL, 260.01, 1040.00, 260.00, NULL, NULL, 6, '2021-07-22 09:23:26.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651307, NULL, 490.01, 1180.00, 250.00, 26, 30, 5, '2021-07-22 09:24:57.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651308, NULL, 330.01, 1000.00, 170.00, 0, 1, 5, '2021-07-22 09:27:08.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651309, NULL, 290.01, 940.00, 230.00, NULL, NULL, 1, '2021-07-22 09:29:12.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651310, NULL, 290.01, 940.00, 230.00, 10, 1, 5, '2021-07-22 09:30:55.0', '2021-08-27 14:16:32.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651311, NULL, 290.01, 940.00, 230.00, 0, 1, 5, '2021-07-22 09:30:55.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651313, NULL, 490.01, 1180.00, 250.00, NULL, NULL, 6, '2021-07-22 09:32:43.0', '2021-08-27 10:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651314, NULL, 300.00, 900.00, 150.00, 13, 3, 5, '2021-07-22 09:34:20.0', '2021-08-27 13:03:48.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651317, NULL, 330.01, 960.00, 300.00, 0, 1, 5, '2021-07-22 09:35:38.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651321, NULL, 490.01, 1180.00, 250.00, 0, 1, 5, '2021-07-22 09:38:58.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651326, NULL, 260.01, 1040.00, 240.00, 0, 1, 5, '2021-07-22 09:41:42.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651327, NULL, 330.01, 960.00, 300.00, 0, 1, 5, '2021-07-22 09:42:51.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651329, NULL, 300.00, 900.00, 150.00, NULL, NULL, 6, '2021-07-22 09:43:54.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651333, NULL, 300.01, 1000.00, 230.00, 16, 1, 5, '2021-07-22 09:45:50.0', '2021-08-27 14:16:34.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651335, NULL, 300.01, 1000.00, 230.00, NULL, NULL, 6, '2021-07-22 09:47:25.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651337, NULL, 330.01, 960.00, 300.00, NULL, NULL, 6, '2021-07-22 09:48:15.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651342, NULL, 490.01, 1180.00, 250.00, NULL, NULL, 6, '2021-07-22 09:50:56.0', '2021-08-27 10:11:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651343, NULL, 490.01, 1180.00, 260.00, 26, 31, 5, '2021-07-22 09:52:18.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651356, NULL, 290.01, 940.00, 230.00, NULL, NULL, 6, '2021-07-22 09:54:35.0', '2021-08-27 10:01:00.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4651357, NULL, 300.00, 900.00, 150.00, 0, 1, 5, '2021-07-22 09:54:40.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4682051, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:58:17.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4682052, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 08:58:17.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4682262, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:58:17.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691609, NULL, 280.00, 900.00, 280.00, 17, 1, 5, '2021-08-10 09:43:05.0', '2021-08-27 14:16:27.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691611, NULL, 280.00, 600.00, 700.00, NULL, NULL, 1, '2021-08-10 09:53:22.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691612, NULL, 280.00, 500.00, 430.00, 6, 1, 4, '2021-08-10 09:56:31.0', '2021-08-27 14:16:33.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691617, NULL, 280.00, 600.00, 700.00, NULL, NULL, 6, '2021-08-10 09:59:39.0', '2021-08-27 10:36:36.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691618, NULL, 330.00, 590.00, 650.00, 18, 1, 5, '2021-08-10 10:02:48.0', '2021-08-27 12:22:15.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691892, NULL, 280.00, 600.00, 800.00, NULL, NULL, 1, '2021-08-10 11:52:12.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691895, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-10 11:52:56.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691974, NULL, 330.00, 590.00, 1200.00, NULL, NULL, 1, '2021-08-10 12:18:20.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4691990, NULL, 330.00, 590.00, 1200.00, NULL, NULL, 1, '2021-08-10 12:23:34.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701752, NULL, 490.00, 1180.00, 260.00, 27, 43, 5, '2021-08-16 07:55:04.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701753, NULL, 490.00, 1180.00, 260.00, 27, 44, 5, '2021-08-16 08:15:21.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701754, NULL, 490.00, 1180.00, 260.00, 27, 42, 5, '2021-08-16 08:18:48.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701755, NULL, 490.00, 1180.00, 260.00, 27, 46, 5, '2021-08-16 08:18:52.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701756, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:26:38.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701757, NULL, 490.00, 1180.00, 260.00, 31, 1, 4, '2021-08-16 08:29:07.0', '2021-08-27 14:16:11.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701758, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:41:56.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701759, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 6, '2021-08-16 08:45:52.0', '2021-08-27 09:28:11.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701760, NULL, 490.00, 1180.00, 260.00, 27, 45, 5, '2021-08-16 08:45:54.0', '2021-08-27 14:08:31.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701761, NULL, 490.00, 1180.00, 260.00, 28, 44, 5, '2021-08-16 08:45:54.0', '2021-08-27 14:16:27.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701762, NULL, 490.00, 1180.00, 260.00, 0, 1, 5, '2021-08-16 08:55:14.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701763, NULL, 490.00, 1180.00, 260.00, 26, 27, 5, '2021-08-16 08:58:17.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701764, NULL, 490.00, 1180.00, 260.00, 26, 26, 5, '2021-08-16 09:04:36.0', '2021-08-27 14:08:37.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4701765, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 6, '2021-08-16 09:06:22.0', '2021-08-27 12:44:44.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4704297, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 16:52:11.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4704312, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 16:55:02.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4704345, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-16 17:00:36.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4708347, NULL, 300.00, 900.00, 150.00, NULL, NULL, 1, '2021-08-18 11:38:42.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710866, NULL, 280.00, 600.00, 900.00, 0, 1, 5, '2021-08-19 07:40:52.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710867, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:44:27.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710868, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:45:47.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710869, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:48:06.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710870, NULL, 280.00, 600.00, 900.00, 0, 1, 5, '2021-08-19 07:50:36.0', '2021-08-27 13:08:45.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710871, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:53:33.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710872, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:56:13.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710873, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 07:58:42.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710874, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:00:10.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710875, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:02:33.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710876, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:05:59.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4710877, NULL, 280.00, 600.00, 900.00, NULL, NULL, 1, '2021-08-19 08:08:27.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724421, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:33:31.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724454, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:37:58.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724463, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:39:45.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724474, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:42:08.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4724484, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-25 11:43:21.0', '2021-08-27 08:41:01.0'); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730464, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 09:57:17.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730467, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:04:06.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730472, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:27:15.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730473, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:27:27.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730474, NULL, 490.00, 1180.00, 260.00, NULL, NULL, 1, '2021-08-27 10:30:13.0', NULL); + INSERT INTO srt.expedition + (id, weight, width, `length`, height, bufferFk, `position`, stateFk, created, updated) + VALUES(4730476, NULL, 490.00, 1180.00, 260.00, 23, 1, 5, '2021-08-27 10:35:28.0', '2021-08-27 14:16:09.0'); + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'PRINTED' + SET e.stateFk = es.id, + e.weight = NULL, + e.bufferFk = NULL, + e.`position` = NULL; + + UPDATE srt.buffer b + JOIN srt.bufferState bs on bs.id = b.stateFk + SET stateFk = bs.id + WHERE bs.description = 'FREE'; + + UPDATE srt.config + SET isRandomMoving = FALSE; + + SET @dm := (24 * 60) - 10; + + UPDATE vn.expeditionTruck et + SET et.eta = timestampadd(MINUTE ,@dm := 1 + @dm,util.VN_CURDATE()) + WHERE description LIKE 'PRU%' ; + + DELETE FROM srt.movingLog ; + + DELETE FROM srt.expeditionLog WHERE created < timestampadd(week,-1,util.VN_CURDATE()); + + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_routeOut.sql b/db/routines/srt/procedures/expedition_routeOut.sql new file mode 100644 index 000000000..d40384e1f --- /dev/null +++ b/db/routines/srt/procedures/expedition_routeOut.sql @@ -0,0 +1,83 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_routeOut`(vRouteFk INT, vBufferToFk INT) +BEGIN + + /** + * Selecciona y enruta las expediciones en el sorter hacia un buffer de salida, que sean de la ruta pedida + * + * @param vRouteFk Identificador de vn.route + * @param vBufferToFk Identificador de srt.buffer + * + */ + + DECLARE vExpListFk INT; + + DECLARE vExpBufFk INT; + + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vExpList CURSOR FOR + SELECT bs.expeditionFk + FROM srt.bufferStock bs + JOIN srt.expedition e ON e.id = bs.expeditionFk + WHERE bs.routeFk = vRouteFk + AND bs.expeditionState = 'STORED' + AND bs.isActive + AND bs.hasWorkerWaiting = FALSE + ORDER BY (vBufferToFk - e.bufferFk), + e.`position` ; + + DECLARE vExpBuf CURSOR FOR + SELECT e.id + FROM srt.expedition e + JOIN srt.expedition e2 ON e2.bufferFk = e.bufferFk + JOIN srt.expeditionState es ON es.id = e.stateFk + WHERE e2.id = vExpListFk + AND e.`position` <= e2.`position` + AND es.description = 'STORED' + ORDER BY e.`position`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vExpList; + + FETCH vExpList INTO vExpListFk; + + WHILE NOT vDone DO + + OPEN vExpBuf; + + FETCH vExpBuf INTO vExpBufFk; + + WHILE NOT vDone DO + + IF vExpBufFk = vExpListFk THEN + + CALL srt.expedition_relocate(vExpListFk, vBufferToFk); + + SET vDone = TRUE; + + ELSE + + CALL srt.expedition_relocate(vExpBufFk, NULL); + + SET vDone = FALSE; + + FETCH vExpBuf INTO vExpBufFk; + + END IF; + + END WHILE; + + CLOSE vExpBuf; + + SET vDone = FALSE; + + FETCH vExpList INTO vExpListFk; + + END WHILE; + + CLOSE vExpList; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_scan.sql b/db/routines/srt/procedures/expedition_scan.sql new file mode 100644 index 000000000..e3fcfddef --- /dev/null +++ b/db/routines/srt/procedures/expedition_scan.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_scan`(vSelf INT) +BEGIN + + /* Actualiza el estado de una expedicion a OUT, al ser escaneada manualmente + * + * @param vSelf Identificador de srt.expedition + * + */ + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'OUT' + SET e.stateFk = es.id, + e.`position` = NULL, + e.bufferFk = NULL + WHERE e.id = vSelf; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_setDimensions.sql b/db/routines/srt/procedures/expedition_setDimensions.sql new file mode 100644 index 000000000..0b4fea28f --- /dev/null +++ b/db/routines/srt/procedures/expedition_setDimensions.sql @@ -0,0 +1,43 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_setDimensions`( + vExpeditionFk INT, + vWeight DECIMAL(10,2), + vLength INT, + vWidth INT, + vHeight INT, + OUT vExpeditionOutFk INT) +BEGIN +/** + * Actualiza las dimensiones, peso y estado de una expedición + * + * @param vExpeditionFk Identificador de expedition + * @param vWeight Peso en kilos + * @param vLength Byte con el número de fotocélulas activadas a lo largo + * @param vWidth Byte con el número de fotocélulas activadas a lo ancho + * @param vHeight Altura de la caja en cm + * @return vExpeditionOutFk Identificador de expedition + */ + + DECLARE vWidthSensorsUsed INT; + DECLARE vLengthSensorsUsed INT; + + SET vExpeditionOutFk = expedition_check(vExpeditionFk); + + #primer bit a 1 a la izquierda - primer bit a 1 a la derecha + SET vWidthSensorsUsed = length(BIN(vWidth)) - LOG2(vWidth & -vWidth); + SET vLengthSensorsUsed = length(BIN(vLength)) - LOG2(vLength & -vLength); + + UPDATE expedition e + JOIN expeditionState es ON es.`description` = 'WEIGHED' + JOIN config c + SET weight = IFNULL(vWeight, 0), + stateFk = es.id, + width = IFNULL(c.widthToFirstSensor + (c.widthSensorSpacing * vWidthSensorsUsed), 0), + `length` = IFNULL(c.lengthToFirstSensor + (c.lengthSensorSpacing * vLengthSensorsUsed), 0), + height = IFNULL(vHeight * 10, 0) + WHERE e.id = vExpeditionOutFk; + + SET vExpeditionOutFk = vExpeditionFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/expedition_weighing.sql b/db/routines/srt/procedures/expedition_weighing.sql new file mode 100644 index 000000000..bb35edb27 --- /dev/null +++ b/db/routines/srt/procedures/expedition_weighing.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expedition_weighing`(vWeight DECIMAL(10,2), vExpeditionFk INT, OUT vExpeditionOutFk INT ) +BEGIN + + /** + * Actualiza el peso de una expedición + * + * @param vWeight Peso en kilos + * @param vExpeditionFk Identificador de srt.expedition + * + * @return vExpeditionOutFk Identificador de srt.expedition + */ + + SET vExpeditionOutFk = srt.expedition_check(vExpeditionFk); + + UPDATE srt.expedition e + JOIN srt.expeditionState es on es.description = 'WEIGHED' + SET weight = vWeight, + stateFk = es.id + WHERE e.id = vExpeditionOutFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/failureLog_add.sql b/db/routines/srt/procedures/failureLog_add.sql new file mode 100644 index 000000000..b572e8503 --- /dev/null +++ b/db/routines/srt/procedures/failureLog_add.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`failureLog_add`(vDescription VARCHAR(100)) +BEGIN + + /* Añade un registro a srt.failureLog + * + * @param vDescription descripción del fallo + */ + + INSERT INTO srt.failureLog(description) VALUES(vDescription); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/lastRFID_add.sql b/db/routines/srt/procedures/lastRFID_add.sql new file mode 100644 index 000000000..ec3c83d98 --- /dev/null +++ b/db/routines/srt/procedures/lastRFID_add.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`lastRFID_add`(vCode VARCHAR(20), vAntennaFk INT, vAntennaPortFk INT, vPeakRssi INT, vSeenCount INT) +BEGIN + + /* Insert a new record in lastRFID table + * + * @param vCode Char string read by the antenna + * @param vAntennaFk Identifier for srt.antenna table + */ + + INSERT INTO srt.lastRFID(code, antennaFk, antennaPort, peakRssi, seenCount) + VALUES(vCode, vAntennaFk, vAntennaPortFk , vPeakRssi , vSeenCount ); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/lastRFID_add_beta.sql b/db/routines/srt/procedures/lastRFID_add_beta.sql new file mode 100644 index 000000000..bbeb32410 --- /dev/null +++ b/db/routines/srt/procedures/lastRFID_add_beta.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`lastRFID_add_beta`(vCode VARCHAR(20), vAntennaFk INT, vAntennaPortFk INT, vPeakRssi INT, vSeenCount INT) +BEGIN + + /* Insert a new record in lastRFID table + * + * @param vCode Char string read by the antenna + * @param vAntennaFk Identifier for srt.antenna table + */ + + INSERT INTO srt.lastRFID(code, antennaFk, antennaPort, peakRssi, seenCount) + VALUES(vCode, vAntennaFk, vAntennaPortFk , vPeakRssi , vSeenCount ); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/moving_CollidingSet.sql b/db/routines/srt/procedures/moving_CollidingSet.sql new file mode 100644 index 000000000..69c4f9d9e --- /dev/null +++ b/db/routines/srt/procedures/moving_CollidingSet.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_CollidingSet`() +BEGIN + + + UPDATE srt.moving + SET isColliding = FALSE; + + UPDATE srt.moving m1 + JOIN srt.buffer sf1 ON sf1.id = m1.bufferFromFk + JOIN srt.buffer st1 ON st1.id = m1.bufferToFk + JOIN srt.movingState ms1 ON ms1.id = m1.stateFk + JOIN srt.moving m2 + JOIN srt.buffer sf2 ON sf2.id = m2.bufferFromFk + JOIN srt.buffer st2 ON st2.id = m2.bufferToFk + JOIN srt.movingState ms2 ON ms2.id = m2.stateFk + SET m1.isColliding = TRUE + WHERE NOT ms1.isInterfering + AND ms2.isInterfering + AND (sf1.stratus = st2.stratus + OR + st1.stratus = sf2.stratus ) + ; +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/moving_between.sql b/db/routines/srt/procedures/moving_between.sql new file mode 100644 index 000000000..41822d341 --- /dev/null +++ b/db/routines/srt/procedures/moving_between.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_between`(vBufferA INT, vBufferB INT) +BEGIN + + DECLARE vExpeditionFk INT; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + WHERE e.bufferFk = vBufferA + AND ISNULL(m.id) + ORDER BY e.`position` + LIMIT 1; + + IF ISNULL(vExpeditionFk) THEN + + SET vExpeditionFk = srt.expedition_check(0); + + UPDATE srt.expedition + SET bufferFk = vBufferA, `position` = 1 + WHERE id = vExpeditionFk; + + END IF; + + CALL `srt`.`expedition_Relocate`(vExpeditionFk, IFNULL(vBufferB,srt.buffer_get(vExpeditionFk))); + + SELECT * FROM srt.moving m ORDER BY id; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/moving_clean.sql b/db/routines/srt/procedures/moving_clean.sql new file mode 100644 index 000000000..b8fae7ff4 --- /dev/null +++ b/db/routines/srt/procedures/moving_clean.sql @@ -0,0 +1,63 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_clean`() +BEGIN +/** + * Elimina movimientos por inactividad + * + */ + DECLARE vExpeditionFk INT; + DECLARE vBufferToFk INT; + DECLARE vBufferFromFk INT; + DECLARE done BOOL DEFAULT FALSE; + + DECLARE cur CURSOR FOR + SELECT m.expeditionFk, m.bufferToFk, m.bufferFromFk + FROM srt.moving m + JOIN srt.config c + JOIN (SELECT bufferFk, SUM(isActive) hasBox + FROM srt.photocell + GROUP BY bufferFk) sub ON sub.bufferFk = m.bufferFromFk + WHERE m.created < TIMESTAMPADD(MINUTE, - c.movingMaxLife , util.VN_NOW()) + AND NOT sub.hasBox; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + OPEN cur; + + bucle: LOOP + + FETCH cur INTO vExpeditionFk, vBufferToFk, vBufferFromFk; + + IF done THEN + LEAVE bucle; + END IF; + + DELETE FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + + UPDATE srt.expedition e + JOIN srt.expeditionState es ON es.description = 'OUT' + SET + bufferFk = NULL, + `position` = NULL, + stateFk = es.id + WHERE e.id = vExpeditionFk; + + UPDATE srt.expedition e + SET e.`position` = e.`position` - 1 + WHERE e.bufferFk = vBufferFromFk + AND e.`position` > 0; + + CALL vn.mail_insert( + 'pako@verdnatura.es, carles@verdnatura.es', + NULL, + CONCAT('Moving_clean. Expedition: ', vExpeditionFk, ' estaba parada'), + CONCAT('Expedition: ', vExpeditionFk,' vBufferToFk: ', vBufferToFk) + ); + + END LOOP bucle; + + CLOSE cur; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/moving_delete.sql b/db/routines/srt/procedures/moving_delete.sql new file mode 100644 index 000000000..38491105a --- /dev/null +++ b/db/routines/srt/procedures/moving_delete.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_delete`(vExpeditionFk INT) +BEGIN + + /* Elimina un movimiento + * + * @param vExpeditionFk Identificador de srt.expedition + * + */ + + INSERT INTO srt.movingLog(expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, movingFk, `action`) + SELECT expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, id, 'DELETE' + FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + + DELETE FROM srt.moving + WHERE expeditionFk = vExpeditionFk; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/moving_groupOut.sql b/db/routines/srt/procedures/moving_groupOut.sql new file mode 100644 index 000000000..d901f0ca9 --- /dev/null +++ b/db/routines/srt/procedures/moving_groupOut.sql @@ -0,0 +1,145 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_groupOut`() +proc: BEGIN + + DECLARE vDayMinute INT; + DECLARE vRouteFk INT; + DECLARE vBufferToFk INT; + DECLARE vBufferFromFk INT; + DECLARE vBufferGroupFk INT; + DECLARE vDone INT DEFAULT FALSE; + DECLARE cur1 CURSOR FOR + SELECT DISTINCT b.id + FROM srt.buffer b + JOIN srt.bufferState bs ON bs.id = b.stateFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.bufferGroup bg ON bg.bufferFk = b.id + LEFT JOIN srt.moving m ON m.bufferToFk = b.id + WHERE bs.description = 'FREE' + AND b.isActive + AND bt.typeName = 'STRAPPING'; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + IF (SELECT (isAuto OR isRandomMoving) FROM srt.config) THEN + + LEAVE proc; + + END IF; + + CASE (SELECT groupingMode FROM srt.config) + + WHEN 'TRUCK' THEN + + SELECT min(ev.dayMinute) INTO vDayMinute + FROM srt.expeditionVolume ev + WHERE ev.isReady + AND ev.dayMinute + AND ev.bufferTruck; + + IF vDayMinute THEN + + SELECT min(ev.bufferTruck) INTO vBufferToFk + FROM srt.expeditionVolume ev + WHERE ev.dayMinute = vDayMinute; + + UPDATE srt.buffer + SET dayMinute = vDayMinute + WHERE id = vBufferToFk; + + CALL srt.expedition_groupOut(vDayMinute,vBufferToFk); + + END IF; + + WHEN 'ROUTE' THEN + + SELECT min(rv.dayMinute) INTO vDayMinute + FROM srt.routeVolume rv + LEFT JOIN srt.buffer b ON b.routeFk = rv.routeFk + WHERE rv.isReady + AND rv.dayMinute + AND rv.bufferTruck + AND ISNULL(b.id); + + IF vDayMinute THEN + + SELECT min(ev.bufferTruck) INTO vBufferToFk + FROM srt.expeditionVolume ev + WHERE ev.dayMinute = vDayMinute; + + SELECT rv.routeFk INTO vRouteFk + FROM srt.routeVolume rv + WHERE rv.dayMinute = vDayMinute + AND rv.isReady + ORDER BY dayMinute, cajas DESC + LIMIT 1; + + UPDATE srt.buffer + SET routeFk = vRouteFk + WHERE id = vBufferToFk; + + CALL srt.expedition_routeOut(vRouteFk,vBufferToFk); + + END IF; + + WHEN 'BUFFER' THEN + + SELECT rv.dayMinute, rv.routeBuffer + INTO vDayMinute, vBufferToFk + FROM srt.routeVolume rv + WHERE rv.isReady + AND rv.dayMinute + AND rv.routeBuffer + ORDER BY rv.dayMinute + LIMIT 1; + + IF vDayMinute THEN + + CALL srt.expedition_bufferOut(vBufferToFk); + + END IF; + + WHEN 'BUFFERGROUP' THEN + + -- En el caso de que haya cajas en buffers auxiliares y los principales esten libres, reenvia cajas + + OPEN cur1; + + read_loop: LOOP + + FETCH cur1 INTO vBufferToFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + SELECT bg.`group` INTO vBufferGroupFk + FROM srt.bufferGroup bg + WHERE bg.bufferFk = vBufferToFk; + + SELECT MAX(e.bufferFk) INTO vBufferFromFk + FROM srt.expedition e + JOIN srt.expeditionState es ON es.id = e.stateFk + JOIN srt.bufferGroup bg ON bg.bufferFk = e.bufferFk + LEFT JOIN srt.moving m ON m.bufferToFk = e.bufferFk + LEFT JOIN srt.moving mo ON mo.bufferFromFk = e.bufferFk + JOIN srt.buffer b on b.id = e.bufferFk + JOIN srt.bufferType bt on bt.id = b.typeFk + WHERE bg.`group` = vBufferGroupFk + AND ISNULL(m.bufferToFk) + AND ISNULL(mo.id) + AND bt.typeName = 'ACCUMULATION'; + IF vBufferFromFk THEN + + CALL srt.buffer_giveBack(vBufferFromFk); + + END IF; + + END LOOP; + + CLOSE cur1; + + END CASE; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/moving_next.sql b/db/routines/srt/procedures/moving_next.sql new file mode 100644 index 000000000..6c76b8373 --- /dev/null +++ b/db/routines/srt/procedures/moving_next.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`moving_next`() +BEGIN + + DECLARE vExpeditionFk INT; + DECLARE vMovingFk INT; + DECLARE vSecondsFromLastRFIDReading INT; + + CALL srt.randomMoving_Launch(); + + CALL srt.moving_GroupOut(); + + CALL srt.moving_CollidingSet(); + + SELECT TIME_TO_SEC((TIMEDIFF(util.VN_NOW(),MAX(lr.created)))) + INTO vSecondsFromLastRFIDReading + FROM srt.lastRFID lr; + + + SELECT m.id INTO vMovingFk + FROM srt.moving m + JOIN srt.expedition e ON e.id = m.expeditionFk + JOIN srt.movingState ms ON ms.id = m.stateFk + JOIN srt.buffer b ON b.id = m.bufferToFk + JOIN srt.buffer b2 ON b2.id = m.bufferFromFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.bufferState bs ON bs.id = b.stateFk + JOIN srt.config c + WHERE NOT ms.isInterfering + AND NOT m.isColliding + AND (c.isEnteringBlocked = FALSE OR m.bufferFromFk > 0) + AND (e.`position` = 1 OR m.bufferFromFk = 0) + AND (vSecondsFromLastRFIDReading > c.enteringSecondsReserve OR m.bufferFromFk = 0) + AND (bs.description != 'FULL' OR m.bufferFromFk = 0) + ORDER BY (m.bufferFromFk = 0) DESC, + m.bufferFromFk DESC + LIMIT 1; + + SELECT m.expeditionFk + INTO vExpeditionFk + FROM moving m + WHERE m.id = vMovingFk; + + IF vExpeditionFk THEN + + SELECT m.expeditionFk, + m.bufferFromFk, + m.bufferToFk + FROM moving m + WHERE m.id = vMovingFk; + + UPDATE expedition e + JOIN expeditionState es ON es.description = 'MOVING' + SET e.stateFk = es.id + WHERE e.id = vExpeditionFk; + + UPDATE srt.moving m + JOIN srt.movingState ms ON ms.description = 'MOVING' + SET m.stateFk = ms.id + WHERE m.id = vMovingFk; + + INSERT INTO srt.movingLog(expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, movingFk, `action`) + SELECT expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, id, 'NEXT' + FROM srt.moving + WHERE id = vMovingFk; + + ELSE + + SELECT 0 expeditionFk, 0 bufferFromFk, 0 bufferToFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/photocell_setActive.sql b/db/routines/srt/procedures/photocell_setActive.sql new file mode 100644 index 000000000..c89e9dc9d --- /dev/null +++ b/db/routines/srt/procedures/photocell_setActive.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`photocell_setActive`(vBufferFk int, vPosition int, vIsActive bool) +BEGIN + REPLACE srt.photocell VALUES (vbufferFk, vPosition, vIsActive); +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/randomMoving.sql b/db/routines/srt/procedures/randomMoving.sql new file mode 100644 index 000000000..b4bdd6591 --- /dev/null +++ b/db/routines/srt/procedures/randomMoving.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`randomMoving`(vBufferMin INT, vBufferMax INT) +BEGIN + DECLARE vBufferOld INT DEFAULT 0; + DECLARE vBufferFk INT; + DECLARE vExpeditionFk INT; + + SELECT e.id INTO vExpeditionFk + FROM srt.expedition e + LEFT JOIN srt.moving m ON m.expeditionFk = e.id + JOIN srt.buffer b ON b.id = e.bufferFk + JOIN srt.bufferType bt ON bt.id = b.typeFk + WHERE e.bufferFk BETWEEN vBufferMin AND vBufferMax + AND m.id IS NULL + AND bt.typeName = 'ACCUMULATION' + AND b.isActive + ORDER BY e.`position`, e.updated + LIMIT 1; + + SELECT IFNULL(e.bufferFk,0) INTO vBufferOld + FROM srt.expedition e + WHERE e.id = vExpeditionFk; + + SELECT b.id INTO vBufferFk + FROM srt.buffer b + JOIN srt.bufferFreeLength bfl ON bfl.bufferFk = b.id + JOIN srt.bufferType bt ON bt.id = b.typeFk + JOIN srt.config c + LEFT JOIN srt.moving m ON m.bufferToFk = b.id + LEFT JOIN srt.moving m2 ON m2.bufferFromFk = b.id + WHERE ISNULL(m.bufferToFk) + AND ISNULL(m2.bufferFromFk) + AND b.id BETWEEN vBufferMin AND vBufferMax + AND b.id != vBufferOld + AND b.isActive + AND bt.typeName = 'ACCUMULATION' + AND bfl.freeLength > c.freeLength * 2 + ORDER BY (b.id = floor(MINUTE(util.VN_NOW())/2)) DESC + LIMIT 1; + + IF vBufferFk THEN + + INSERT INTO srt.moving (expeditionFk, bufferFromFk, bufferToFk) + SELECT e.id, e.bufferFk, vBufferFk + FROM srt.expedition e + WHERE e.id = vExpeditionFk; + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/randomMoving_Launch.sql b/db/routines/srt/procedures/randomMoving_Launch.sql new file mode 100644 index 000000000..031e54873 --- /dev/null +++ b/db/routines/srt/procedures/randomMoving_Launch.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`randomMoving_Launch`() +BEGIN + + DECLARE i INT DEFAULT 5; + + IF (SELECT count(*) FROM srt.moving) < 5 AND (SELECT isRandomMoving FROM srt.config) THEN + + WHILE i DO + + SET i = i - 1; + + -- CALL srt.randomMoving(22,35); + CALL srt.randomMoving(2,5); + + END WHILE; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/restart.sql b/db/routines/srt/procedures/restart.sql new file mode 100644 index 000000000..96adb3bfa --- /dev/null +++ b/db/routines/srt/procedures/restart.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`restart`() +BEGIN + + /* + * Se ha pulsado el botón RESTART en la pantalla tàctil del sorter + */ + + DELETE FROM srt.moving + WHERE bufferFromFk = 0; + + INSERT INTO srt.sorterLog(`action`) VALUES('RESTART'); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/start.sql b/db/routines/srt/procedures/start.sql new file mode 100644 index 000000000..8e5250796 --- /dev/null +++ b/db/routines/srt/procedures/start.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`start`() +BEGIN + + /* + * Se ha pulsado el botón START en la pantalla tàctil del sorter + */ + + INSERT INTO srt.sorterLog(`action`) VALUES('START'); + + UPDATE srt.config SET isEnteringBlocked = FALSE ; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/stop.sql b/db/routines/srt/procedures/stop.sql new file mode 100644 index 000000000..a6fd12bb2 --- /dev/null +++ b/db/routines/srt/procedures/stop.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`stop`() +BEGIN + + /* + * Se ha pulsado el botón STOP en la pantalla tàctil del sorter + */ + + INSERT INTO srt.sorterLog(`action`) VALUES('STOP'); + + UPDATE srt.config SET isEnteringBlocked = TRUE; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/procedures/test.sql b/db/routines/srt/procedures/test.sql new file mode 100644 index 000000000..59a76eb81 --- /dev/null +++ b/db/routines/srt/procedures/test.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`test`() +BEGIN + + SELECT 'procedimiento ejecutado con éxito'; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/triggers/expedition_BU.sql b/db/routines/srt/triggers/expedition_BU.sql new file mode 100644 index 000000000..fb557d151 --- /dev/null +++ b/db/routines/srt/triggers/expedition_BU.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `srt`.`expedition_BU` + BEFORE UPDATE ON `expedition` + FOR EACH ROW +BEGIN + + SET NEW.updated = util.VN_NOW(); + +END$$ +DELIMITER ; diff --git a/db/routines/srt/triggers/moving_AI.sql b/db/routines/srt/triggers/moving_AI.sql new file mode 100644 index 000000000..6c2dcf961 --- /dev/null +++ b/db/routines/srt/triggers/moving_AI.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `srt`.`moving_AI` + AFTER INSERT ON `moving` + FOR EACH ROW +BEGIN + + INSERT INTO srt.movingLog(movingFk, expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, `action`) + VALUES(NEW.id, NEW.expeditionFk, NEW.bufferFromFk, NEW.bufferToFk, NEW.stateFk, NEW.isColliding, 'NEW2'); + + DELETE FROM srt.movingLast; + + INSERT INTO srt.movingLast (id, expeditionFk, bufferFromFk, bufferToFk) + VALUES(NEW.id, NEW.expeditionFk, NEW.bufferFromFk, NEW.bufferToFk); + + IF srt.buffer_isFull(NEW.bufferToFk) THEN + + CALL srt.buffer_setStateType(NEW.bufferToFk, 'FULL',NULL); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/srt/views/bufferDayMinute.sql b/db/routines/srt/views/bufferDayMinute.sql new file mode 100644 index 000000000..8ee732c56 --- /dev/null +++ b/db/routines/srt/views/bufferDayMinute.sql @@ -0,0 +1,41 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `srt`.`bufferDayMinute` +AS SELECT `b`.`id` AS `bufferFk`, + `e`.`id` AS `expeditionFk`, + `srt`.`dayMinute`(IFNULL(`et`.`eta`, `z`.`hour`)) AS `dayMinute`, + `e`.`position` AS `position`, + IFNULL( + `et`.`eta`, + `util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) MINUTE + ) AS `ETD`, + `e2`.`ticketFk` AS `ticketFk`, + IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`) AS `routeFk`, + `z`.`name` AS `zonaTicket`, + `es`.`description` AS `expeditionState` +FROM ( + ( + ( + ( + ( + ( + ( + ( + `srt`.`buffer` `b` + LEFT JOIN `srt`.`expedition` `e` ON(`b`.`id` = `e`.`bufferFk`) + ) + LEFT JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e`.`stateFk`) + ) + JOIN `srt`.`bufferType` `bt` ON(`bt`.`id` = `b`.`typeFk`) + ) + LEFT JOIN `vn`.`expedition` `e2` ON(`e2`.`id` = `e`.`id`) + ) + LEFT JOIN `vn`.`ticket` `t` ON(`e2`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`rm`.`expeditionTruckFk` = `et`.`id`) + ) + LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) +WHERE `b`.`isActive` <> 0 diff --git a/db/routines/srt/views/bufferFreeLength.sql b/db/routines/srt/views/bufferFreeLength.sql new file mode 100644 index 000000000..4edf1db47 --- /dev/null +++ b/db/routines/srt/views/bufferFreeLength.sql @@ -0,0 +1,39 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `srt`.`bufferFreeLength` +AS SELECT cast(`b`.`id` AS decimal(10, 0)) AS `bufferFk`, + `b`.`code` AS `bufferName`, + cast( + `b`.`length` - sum(IFNULL(`e`.`length`, 900) + 500) AS decimal(10, 0) + ) AS `freeLength`, + cast( + sum(IFNULL(`e`.`length`, 900) + 500) AS decimal(10, 0) + ) AS `saturacion`, + `bs`.`description` AS `state`, + `b`.`stateFk` AS `stateFk`, + `b`.`typeFk` AS `typeFk`, + `bt`.`typeName` AS `typeName`, + COUNT(`e`.`id`) AS `stock`, + cast( + `b`.`length` - sum( + IF( + `es`.`description` = 'STORED', + `e`.`length` + 500, + 0 + ) + ) AS decimal(10, 0) + ) AS `RealFreeLength` +FROM ( + ( + ( + ( + `srt`.`buffer` `b` + LEFT JOIN `srt`.`expedition` `e` ON(`e`.`bufferFk` = `b`.`id`) + ) + LEFT JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e`.`stateFk`) + ) + JOIN `srt`.`bufferType` `bt` ON(`bt`.`id` = `b`.`typeFk`) + ) + JOIN `srt`.`bufferState` `bs` ON(`bs`.`id` = `b`.`stateFk`) + ) +GROUP BY `b`.`id` diff --git a/db/routines/srt/views/bufferStock.sql b/db/routines/srt/views/bufferStock.sql new file mode 100644 index 000000000..6f9d7e2fe --- /dev/null +++ b/db/routines/srt/views/bufferStock.sql @@ -0,0 +1,54 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `srt`.`bufferStock` +AS SELECT `e`.`id` AS `expeditionFk`, + `e`.`bufferFk` AS `bufferFk`, + `e`.`position` AS `position`, + `srt`.`dayMinute`(IFNULL(`et`.`eta`, `z`.`hour`)) AS `dayMinute`, + IFNULL( + `et`.`eta`, + `util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) + 120 MINUTE + ) AS `eta`, + `ve`.`ticketFk` AS `ticketFk`, + IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`) AS `routeFk`, + `z`.`name` AS `zonaTicket`, + `et`.`description` AS `truck`, + `es`.`description` AS `expeditionState`, + `b`.`hasWorkerWaiting` AS `hasWorkerWaiting`, + `b`.`isActive` AS `isActive`, + IF( + `et`.`id` IS NULL, + `c`.`bufferDefault`, + `et`.`bufferFk` + ) AS `bufferTruck`, + `bt`.`typeName` AS `typeName`, + `rm`.`bufferFk` AS `routeBuffer` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + `srt`.`expedition` `e` + LEFT JOIN `vn`.`expedition` `ve` ON(`ve`.`id` = `e`.`id`) + ) + JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e`.`stateFk`) + ) + JOIN `srt`.`buffer` `b` ON(`b`.`id` = `e`.`bufferFk`) + ) + LEFT JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ve`.`ticketFk`) + ) + LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) + LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`rm`.`expeditionTruckFk` = `et`.`id`) + ) + JOIN `srt`.`config` `c` + ) + JOIN `srt`.`bufferType` `bt` ON(`bt`.`id` = `b`.`typeFk`) + ) +WHERE `bt`.`typeName` <> 'DISABLED' diff --git a/db/routines/srt/views/expeditionVolume.sql b/db/routines/srt/views/expeditionVolume.sql new file mode 100644 index 000000000..f6e2ff5bf --- /dev/null +++ b/db/routines/srt/views/expeditionVolume.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`juan`@`%` + SQL SECURITY DEFINER + VIEW `srt`.`expeditionVolume` +AS SELECT `bs`.`dayMinute` AS `dayMinute`, + `bs`.`eta` AS `ETD`, + COUNT(0) AS `cajas`, + `bs`.`eta` + INTERVAL - `c`.`minutesBeforeTruckDeparture` MINUTE < `util`.`VN_NOW`() + OR COUNT(0) >= `c`.`minBoxesToUnloading` AS `isReady`, + `bs`.`truck` AS `truck`, + `bs`.`zonaTicket` AS `zonaTicket`, + `bs`.`bufferTruck` AS `bufferTruck` +FROM ( + `srt`.`bufferStock` `bs` + JOIN `srt`.`config` `c` + ) +WHERE `bs`.`expeditionState` = 'STORED' + AND `bs`.`isActive` <> 0 + AND `bs`.`hasWorkerWaiting` = 0 + AND `bs`.`typeName` = 'ACCUMULATION' +GROUP BY `bs`.`dayMinute` diff --git a/db/routines/srt/views/routePalletized.sql b/db/routines/srt/views/routePalletized.sql new file mode 100644 index 000000000..15b493c6a --- /dev/null +++ b/db/routines/srt/views/routePalletized.sql @@ -0,0 +1,31 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `srt`.`routePalletized` +AS SELECT `t`.`routeFk` AS `routeFk`, + COUNT(DISTINCT `e`.`id`) AS `expediciones`, + sum( + `es`.`description` <=> 'OUT' + OR `esc`.`expeditionFk` IS NOT NULL + ) AS `paletizadas` +FROM ( + ( + ( + ( + ( + ( + `vn`.`ticket` `t` + LEFT JOIN `vn`.`expedition` `e` ON(`e`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `srt`.`expedition` `e2` ON(`e2`.`id` = `e`.`id`) + ) + LEFT JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e2`.`stateFk`) + ) + LEFT JOIN `vn`.`expeditionScan` `esc` ON(`esc`.`expeditionFk` = `e`.`id`) + ) + JOIN `vn`.`ticketCollection` `tc` ON(`tc`.`ticketFk` = `t`.`id`) + ) + JOIN `vn`.`collection` `c` ON(`c`.`id` = `tc`.`collectionFk`) + ) +WHERE `t`.`shipped` BETWEEN `util`.`yesterday`() AND `util`.`tomorrow`() + AND `c`.`itemPackingTypeFk` = 'H' +GROUP BY `t`.`routeFk` diff --git a/db/routines/srt/views/routeVolume.sql b/db/routines/srt/views/routeVolume.sql new file mode 100644 index 000000000..252bb79e2 --- /dev/null +++ b/db/routines/srt/views/routeVolume.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`juan`@`%` + SQL SECURITY DEFINER + VIEW `srt`.`routeVolume` +AS SELECT `bs`.`dayMinute` AS `dayMinute`, + `bs`.`eta` AS `ETD`, + COUNT(0) AS `cajas`, + `bs`.`eta` + INTERVAL - `c`.`minutesBeforeTruckDeparture` MINUTE < `util`.`VN_NOW`() + OR COUNT(0) >= `c`.`minBoxesToUnloading` AS `isReady`, + `bs`.`routeFk` AS `routeFk`, + `bs`.`zonaTicket` AS `zonaTicket`, + `bs`.`bufferTruck` AS `bufferTruck`, + `bs`.`routeBuffer` AS `routeBuffer` +FROM ( + `srt`.`bufferStock` `bs` + JOIN `srt`.`config` `c` + ) +WHERE `bs`.`expeditionState` = 'STORED' + AND `bs`.`isActive` <> 0 + AND `bs`.`hasWorkerWaiting` = 0 +GROUP BY `bs`.`routeFk` diff --git a/db/routines/srt/views/ticketPalletized.sql b/db/routines/srt/views/ticketPalletized.sql new file mode 100644 index 000000000..04ac24291 --- /dev/null +++ b/db/routines/srt/views/ticketPalletized.sql @@ -0,0 +1,32 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `srt`.`ticketPalletized` +AS SELECT `t`.`id` AS `ticketFk`, + `t`.`routeFk` AS `routeFk`, + COUNT(DISTINCT `e`.`id`) AS `expediciones`, + sum( + `es`.`description` <=> 'OUT' + OR `esc`.`expeditionFk` IS NOT NULL + ) AS `paletizadas` +FROM ( + ( + ( + ( + ( + ( + `vn`.`ticket` `t` + LEFT JOIN `vn`.`expedition` `e` ON(`e`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `srt`.`expedition` `e2` ON(`e2`.`id` = `e`.`id`) + ) + LEFT JOIN `srt`.`expeditionState` `es` ON(`es`.`id` = `e2`.`stateFk`) + ) + LEFT JOIN `vn`.`expeditionScan` `esc` ON(`esc`.`expeditionFk` = `e`.`id`) + ) + JOIN `vn`.`ticketCollection` `tc` ON(`tc`.`ticketFk` = `t`.`id`) + ) + JOIN `vn`.`collection` `c` ON(`c`.`id` = `tc`.`collectionFk`) + ) +WHERE `t`.`shipped` BETWEEN `util`.`yesterday`() AND `util`.`tomorrow`() + AND `c`.`itemPackingTypeFk` = 'H' +GROUP BY `t`.`id` diff --git a/db/routines/srt/views/upperStickers.sql b/db/routines/srt/views/upperStickers.sql new file mode 100644 index 000000000..d7e7b9898 --- /dev/null +++ b/db/routines/srt/views/upperStickers.sql @@ -0,0 +1,40 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `srt`.`upperStickers` +AS SELECT `e`.`id` AS `expeditionFk`, + `e`.`id` MOD 10000 AS `expedition`, + IFNULL( + `et`.`eta`, + `util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) + 120 MINUTE + ) AS `ETD`, + `ve`.`ticketFk` AS `ticketFk`, + right(IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`), 3) AS `routeFk`, + `z`.`name` AS `zonaTicket`, + `et`.`description` AS `truck`, + `epo`.`workerCode` AS `worker`, + `p`.`name` AS `labeler`, + `ve`.`counter` AS `expeditionCounter`, + `vn`.`ticketTotalVolume`(`t`.`id`) AS `m3`, + `t`.`clientFk` AS `clientFk` +FROM ( + ( + ( + ( + ( + ( + ( + `srt`.`expedition` `e` + LEFT JOIN `vn`.`expedition` `ve` ON(`ve`.`id` = `e`.`id`) + ) + LEFT JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ve`.`ticketFk`) + ) + LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) + LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`rm`.`expeditionTruckFk` = `et`.`id`) + ) + JOIN `dipole`.`expedition_PrintOut` `epo` ON(`epo`.`expeditionFk` = `e`.`id`) + ) + JOIN `vn`.`printer` `p` ON(`p`.`id` = `epo`.`printerFk`) + ) diff --git a/db/routines/stock/events/log_clean.sql b/db/routines/stock/events/log_clean.sql new file mode 100644 index 000000000..973561a89 --- /dev/null +++ b/db/routines/stock/events/log_clean.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `stock`.`log_clean` + ON SCHEDULE EVERY 1 DAY + STARTS '2022-01-28 09:29:18.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL log_clean$$ +DELIMITER ; diff --git a/db/routines/stock/events/log_syncNoWait.sql b/db/routines/stock/events/log_syncNoWait.sql new file mode 100644 index 000000000..954d37219 --- /dev/null +++ b/db/routines/stock/events/log_syncNoWait.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `stock`.`log_syncNoWait` + ON SCHEDULE EVERY 5 SECOND + STARTS '2017-06-27 17:15:02.000' + ON COMPLETION NOT PRESERVE + DISABLE +DO CALL log_syncNoWait$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/inbound_addPick.sql b/db/routines/stock/procedures/inbound_addPick.sql new file mode 100644 index 000000000..d867b5641 --- /dev/null +++ b/db/routines/stock/procedures/inbound_addPick.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`inbound_addPick`( + vSelf INT, + vOutboundFk INT, + vQuantity INT +) +BEGIN + INSERT INTO inboundPick + SET + inboundFk = vSelf, + outboundFk = vOutboundFk, + quantity = vQuantity + ON DUPLICATE KEY UPDATE + quantity = quantity + vQuantity; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/inbound_removePick.sql b/db/routines/stock/procedures/inbound_removePick.sql new file mode 100644 index 000000000..e125ee8a7 --- /dev/null +++ b/db/routines/stock/procedures/inbound_removePick.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`inbound_removePick`( + vSelf INT, + vOutboundFk INT, + vQuantity INT, + vTotalQuantity INT +) +BEGIN + IF vQuantity < vTotalQuantity THEN + UPDATE inboundPick + SET quantity = quantity - vQuantity + WHERE inboundFk = vSelf + AND outboundFk = vOutboundFk; + ELSE + DELETE FROM inboundPick + WHERE inboundFk = vSelf + AND outboundFk = vOutboundFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/inbound_requestQuantity.sql b/db/routines/stock/procedures/inbound_requestQuantity.sql new file mode 100644 index 000000000..5d814ce2c --- /dev/null +++ b/db/routines/stock/procedures/inbound_requestQuantity.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`inbound_requestQuantity`( + vSelf INT, + vRequested INT, + vDated DATETIME, + OUT vSupplied INT) +BEGIN +/** + * Disassociates inbound picks after the given date until the + * demanded quantity is satisfied. + * + * @param vSelf The inbound reference + * @param vRequested The requested quantity + * @param vDate The starting date for the associated outbounds + * @param vSupplied The supplied quantity + */ + DECLARE vOutboundFk INT; + DECLARE vPickQuantity INT; + DECLARE vPickGranted INT; + DECLARE vDone BOOL; + + DECLARE vPicks CURSOR FOR + SELECT p.outboundFk, p.quantity + FROM inboundPick p + JOIN outbound o ON o.id = p.outboundFk + WHERE p.inboundFk = vSelf + AND o.dated > vDated + ORDER BY o.dated DESC, o.created DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SET vSupplied = 0; + + OPEN vPicks; + + myLoop: LOOP + SET vDone = FALSE; + FETCH vPicks INTO vOutboundFk, vPickQuantity; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity); + SET vSupplied = vSupplied + vPickGranted; + CALL inbound_removePick(vSelf, vOutboundFk, vPickGranted, vPickQuantity); + + UPDATE outbound + SET isSync = FALSE, + lack = lack + vPickGranted + WHERE id = vOutboundFk; + + IF vSupplied >= vRequested THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE vPicks; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/inbound_sync.sql b/db/routines/stock/procedures/inbound_sync.sql new file mode 100644 index 000000000..fc672d920 --- /dev/null +++ b/db/routines/stock/procedures/inbound_sync.sql @@ -0,0 +1,84 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`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 vWarehouse INT; + DECLARE vQuantity INT; + DECLARE vAvailable INT; + DECLARE vSupplied INT; + DECLARE vSuppliedFromRequest INT; + DECLARE vOutboundFk INT; + DECLARE vLack INT; + DECLARE vHasPicks BOOL; + DECLARE vDone BOOL; + + DECLARE vOutbounds CURSOR FOR + SELECT id, lack, lack < quantity + 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; + END IF; + + OPEN vOutbounds; + + myLoop: LOOP + SET vDone = FALSE; + FETCH vOutbounds INTO vOutboundFk, vLack, vHasPicks; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vSupplied = LEAST(vAvailable, vLack); + + IF vSupplied > 0 THEN + SET vAvailable = vAvailable - vSupplied; + UPDATE outbound + SET lack = lack - vSupplied + WHERE id = vOutboundFk; + END IF; + + IF vHasPicks AND vAvailable > 0 THEN + CALL outbound_requestQuantity(vOutboundFk, vAvailable, vDated, vSuppliedFromRequest); + SET vSupplied = vSupplied + vSuppliedFromRequest; + SET vAvailable = vAvailable - vSuppliedFromRequest; + END IF; + + IF vSupplied > 0 THEN + CALL inbound_addPick(vSelf, vOutboundFk, vSupplied); + END IF; + + IF vAvailable <= 0 THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE vOutbounds; + + UPDATE inbound + SET isSync = TRUE, + available = vAvailable + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/log_add.sql b/db/routines/stock/procedures/log_add.sql new file mode 100644 index 000000000..2b75c7f72 --- /dev/null +++ b/db/routines/stock/procedures/log_add.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`log_add`(IN `vTableName` VARCHAR(255), IN `vNewId` VARCHAR(255), IN `vOldId` VARCHAR(255)) +proc: BEGIN + -- XXX: Disabled while testing + LEAVE proc; + + IF vOldId IS NOT NULL AND !(vOldId <=> vNewId) THEN + INSERT IGNORE INTO `log` SET + tableName = vTableName, + tableId = vOldId, + operation = 'delete'; + END IF; + + IF vNewId IS NOT NULL THEN + INSERT IGNORE INTO `log` SET + tableName = vTableName, + tableId = vNewId, + operation = 'insert'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/log_clean.sql b/db/routines/stock/procedures/log_clean.sql new file mode 100644 index 000000000..56634b371 --- /dev/null +++ b/db/routines/stock/procedures/log_clean.sql @@ -0,0 +1,7 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`log_clean`() +BEGIN + DELETE FROM inbound WHERE dated = vn.getInventoryDate(); + DELETE FROM outbound WHERE dated = vn.getInventoryDate(); +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/log_delete.sql b/db/routines/stock/procedures/log_delete.sql new file mode 100644 index 000000000..e3b631b4e --- /dev/null +++ b/db/routines/stock/procedures/log_delete.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`log_delete`(vTableName VARCHAR(255), vTableId INT) +proc: BEGIN +/** + * 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 ; diff --git a/db/routines/stock/procedures/log_refreshAll.sql b/db/routines/stock/procedures/log_refreshAll.sql new file mode 100644 index 000000000..eab91f8e9 --- /dev/null +++ b/db/routines/stock/procedures/log_refreshAll.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`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.`inboundPick`; + 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 ; diff --git a/db/routines/stock/procedures/log_refreshBuy.sql b/db/routines/stock/procedures/log_refreshBuy.sql new file mode 100644 index 000000000..62fa73435 --- /dev/null +++ b/db/routines/stock/procedures/log_refreshBuy.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`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 ; diff --git a/db/routines/stock/procedures/log_refreshOrder.sql b/db/routines/stock/procedures/log_refreshOrder.sql new file mode 100644 index 000000000..49225ddf0 --- /dev/null +++ b/db/routines/stock/procedures/log_refreshOrder.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`log_refreshOrder`( + `vTableName` VARCHAR(255), + `vTableId` INT) +BEGIN + DECLARE vExpireTime INT DEFAULT 20; + DECLARE vExpired DATETIME DEFAULT TIMESTAMPADD(MINUTE, -vExpireTime, util.VN_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.shipment >= vn.getInventoryDate() + 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 ; diff --git a/db/routines/stock/procedures/log_refreshSale.sql b/db/routines/stock/procedures/log_refreshSale.sql new file mode 100644 index 000000000..0499fc711 --- /dev/null +++ b/db/routines/stock/procedures/log_refreshSale.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`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 ; diff --git a/db/routines/stock/procedures/log_sync.sql b/db/routines/stock/procedures/log_sync.sql new file mode 100644 index 000000000..5b03b6ab0 --- /dev/null +++ b/db/routines/stock/procedures/log_sync.sql @@ -0,0 +1,123 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`log_sync`(vSync BOOL) +proc: BEGIN + DECLARE vDone BOOL; + DECLARE vLogId INT; + DECLARE vHasPendingSync BOOL; + DECLARE vOperation VARCHAR(255); + DECLARE vTableName VARCHAR(255); + DECLARE vTableId VARCHAR(255); + DECLARE vInboundFk INT; + DECLARE vOutboundFk INT; + + DECLARE cInbound CURSOR FOR + SELECT id FROM inbound + WHERE !isSync + ORDER BY dated; + + DECLARE cOutbound CURSOR FOR + SELECT id FROM outbound + WHERE !isSync + ORDER BY dated; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + -- 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 + FOR UPDATE; + + IF vDone THEN + COMMIT; + LEAVE opsLoop; + END IF; + + 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 !vSync THEN + LEAVE proc; + END IF; + + -- Deletes expired outbounds + + DELETE FROM outbound WHERE expired <= util.VN_NOW(); + + -- Attaches desync inbounds + + REPEAT + OPEN cInbound; + SET vHasPendingSync = FALSE; + + inboundLoop: LOOP + SET vDone = FALSE; + FETCH cInbound INTO vInboundFk; + + IF vDone THEN + LEAVE inboundLoop; + END IF; + + START TRANSACTION; + CALL inbound_sync(vInboundFk); + COMMIT; + + SET vHasPendingSync = TRUE; + END LOOP; + + CLOSE cInbound; + UNTIL !vHasPendingSync END REPEAT; + + -- Attaches desync outbounds + + REPEAT + OPEN cOutbound; + SET vHasPendingSync = FALSE; + + outboundLoop: LOOP + SET vDone = FALSE; + FETCH cOutbound INTO vOutboundFk; + + IF vDone THEN + LEAVE outboundLoop; + END IF; + + START TRANSACTION; + CALL outbound_sync(vOutboundFk); + COMMIT; + + SET vHasPendingSync = TRUE; + END LOOP; + + CLOSE cOutbound; + UNTIL !vHasPendingSync END REPEAT; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/log_syncNoWait.sql b/db/routines/stock/procedures/log_syncNoWait.sql new file mode 100644 index 000000000..00cc215fd --- /dev/null +++ b/db/routines/stock/procedures/log_syncNoWait.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`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 ; diff --git a/db/routines/stock/procedures/outbound_requestQuantity.sql b/db/routines/stock/procedures/outbound_requestQuantity.sql new file mode 100644 index 000000000..7ddc3545c --- /dev/null +++ b/db/routines/stock/procedures/outbound_requestQuantity.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`outbound_requestQuantity`( + vSelf INT, + vRequested INT, + vDated DATETIME, + OUT vSupplied INT) +BEGIN +/** + * Disassociates outbound picks after the given date until the + * demanded quantity is satisfied. + * + * @param vSelf The outbound reference + * @param vRequested The requested quantity + * @param vDate The starting date for the associated inbounds + * @param vSupplied The supplied quantity + */ + DECLARE vInboundFk INT; + DECLARE vPickQuantity INT; + DECLARE vPickGranted INT; + DECLARE vDone BOOL; + + DECLARE vPicks CURSOR FOR + SELECT p.inboundFk, p.quantity + FROM inboundPick p + JOIN inbound i ON i.id = p.inboundFk + WHERE p.outboundFk = vSelf + AND i.dated > vDated + ORDER BY i.dated DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SET vSupplied = 0; + + OPEN vPicks; + + myLoop: LOOP + SET vDone = FALSE; + FETCH vPicks INTO vInboundFk, vPickQuantity; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity); + SET vSupplied = vSupplied + vPickGranted; + CALL inbound_removePick(vInboundFk, vSelf, vPickGranted, vPickQuantity); + + UPDATE inbound + SET isSync = FALSE, + available = available + vPickGranted + WHERE id = vInboundFk; + + IF vSupplied >= vRequested THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE vPicks; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/outbound_sync.sql b/db/routines/stock/procedures/outbound_sync.sql new file mode 100644 index 000000000..c79bde45f --- /dev/null +++ b/db/routines/stock/procedures/outbound_sync.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`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 vSupplied INT; + DECLARE vSuppliedFromRequest INT; + DECLARE vInboundFk INT; + DECLARE vAvailable INT; + DECLARE vHasPicks BOOL; + DECLARE vDone BOOL; + + DECLARE vInbounds CURSOR FOR + SELECT id, available, available < quantity + 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 vInbounds; + + myLoop: LOOP + SET vDone = FALSE; + FETCH vInbounds INTO vInboundFk, vAvailable, vHasPicks; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vSupplied = LEAST(vLack, vAvailable); + + IF vSupplied > 0 THEN + SET vLack = vLack - vSupplied; + UPDATE inbound + SET available = available - vSupplied + WHERE id = vInboundFk; + END IF; + + IF vHasPicks AND vLack > 0 THEN + CALL inbound_requestQuantity(vInboundFk, vLack, vDated, vSuppliedFromRequest); + SET vSupplied = vSupplied + vSuppliedFromRequest; + SET vLack = vLack - vSuppliedFromRequest; + END IF; + + IF vSupplied > 0 THEN + CALL inbound_addPick(vInboundFk, vSelf, vSupplied); + END IF; + + IF vLack = 0 THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE vInbounds; + + UPDATE outbound + SET isSync = TRUE, + lack = vLack + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/stock/procedures/visible_log.sql b/db/routines/stock/procedures/visible_log.sql new file mode 100644 index 000000000..2867f1186 --- /dev/null +++ b/db/routines/stock/procedures/visible_log.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`visible_log`( + vIsPicked BOOL, + vWarehouseFk INT, + vItemFk INT, + vQuantity INT +) +proc: BEGIN + IF !vIsPicked THEN + LEAVE proc; + END IF; + + INSERT INTO visible + SET itemFk = vItemFk, + warehouseFk = vWarehouseFk, + quantity = vQuantity + ON DUPLICATE KEY UPDATE + quantity = quantity + VALUES(quantity); +END$$ +DELIMITER ; diff --git a/db/routines/stock/triggers/inbound_afterDelete.sql b/db/routines/stock/triggers/inbound_afterDelete.sql new file mode 100644 index 000000000..b485299b0 --- /dev/null +++ b/db/routines/stock/triggers/inbound_afterDelete.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `stock`.`inbound_afterDelete` + AFTER DELETE ON `inbound` + FOR EACH ROW +BEGIN + UPDATE outbound o + JOIN inboundPick ou ON ou.outboundFk = o.id + SET o.lack = o.lack + ou.quantity, + o.isSync = FALSE + WHERE ou.inboundFk = OLD.id; + + DELETE FROM inboundPick + WHERE inboundFk = OLD.id; + + CALL visible_log( + OLD.isPicked, + OLD.warehouseFk, + OLD.itemFk, + -OLD.quantity + ); +END$$ +DELIMITER ; diff --git a/db/routines/stock/triggers/inbound_beforeInsert.sql b/db/routines/stock/triggers/inbound_beforeInsert.sql new file mode 100644 index 000000000..8aabb0682 --- /dev/null +++ b/db/routines/stock/triggers/inbound_beforeInsert.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `stock`.`inbound_beforeInsert` + BEFORE INSERT ON `inbound` + FOR EACH ROW +BEGIN + SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); + + CALL visible_log( + NEW.isPicked, + NEW.warehouseFk, + NEW.itemFk, + NEW.quantity + ); +END$$ +DELIMITER ; diff --git a/db/routines/stock/triggers/outbound_afterDelete.sql b/db/routines/stock/triggers/outbound_afterDelete.sql new file mode 100644 index 000000000..dce0aed7a --- /dev/null +++ b/db/routines/stock/triggers/outbound_afterDelete.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `stock`.`outbound_afterDelete` + AFTER DELETE ON `outbound` + FOR EACH ROW +BEGIN + UPDATE inbound i + JOIN inboundPick ou ON ou.inboundFk = i.id + SET i.available = i.available + ou.quantity, + i.isSync = FALSE + WHERE ou.outboundFk = OLD.id; + + DELETE FROM inboundPick + WHERE outboundFk = OLD.id; + + CALL visible_log( + OLD.isPicked, + OLD.warehouseFk, + OLD.itemFk, + OLD.quantity + ); +END$$ +DELIMITER ; diff --git a/db/routines/stock/triggers/outbound_beforeInsert.sql b/db/routines/stock/triggers/outbound_beforeInsert.sql new file mode 100644 index 000000000..e41edae43 --- /dev/null +++ b/db/routines/stock/triggers/outbound_beforeInsert.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `stock`.`outbound_beforeInsert` + BEFORE INSERT ON `outbound` + FOR EACH ROW +BEGIN + SET NEW.lack = NEW.quantity; + SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); + + CALL visible_log( + NEW.isPicked, + NEW.warehouseFk, + NEW.itemFk, + -NEW.quantity + ); +END$$ +DELIMITER ; diff --git a/db/routines/tmp/events/clean.sql b/db/routines/tmp/events/clean.sql new file mode 100644 index 000000000..34b7139cc --- /dev/null +++ b/db/routines/tmp/events/clean.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `tmp`.`clean` + ON SCHEDULE EVERY 1 HOUR + STARTS '2022-03-01 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL tmp.clean$$ +DELIMITER ; diff --git a/db/routines/tmp/procedures/clean.sql b/db/routines/tmp/procedures/clean.sql new file mode 100644 index 000000000..a15f98311 --- /dev/null +++ b/db/routines/tmp/procedures/clean.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `tmp`.`clean`() +BEGIN + DECLARE vTableName VARCHAR(255); + DECLARE vDone BOOL; + + DECLARE cur CURSOR FOR + SELECT TABLE_NAME + FROM information_schema.TABLES + WHERE TABLE_SCHEMA = 'tmp' + AND CREATE_TIME < TIMESTAMPADD(DAY, 1, util.VN_NOW()); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vTableName; + + IF vDone THEN + LEAVE l; + END IF; + + CALL util.exec(CONCAT('DROP TABLE `tmp`.`', vTableName, '`')); + END LOOP; + CLOSE cur; +END$$ +DELIMITER ; diff --git a/db/routines/util/events/slowLog_prune.sql b/db/routines/util/events/slowLog_prune.sql new file mode 100644 index 000000000..aa9b0c184 --- /dev/null +++ b/db/routines/util/events/slowLog_prune.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `util`.`slowLog_prune` + ON SCHEDULE EVERY 1 DAY + STARTS '2021-10-08 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL util.slowLog_prune$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_CURDATE.sql b/db/routines/util/functions/VN_CURDATE.sql new file mode 100644 index 000000000..692f097a0 --- /dev/null +++ b/db/routines/util/functions/VN_CURDATE.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_CURDATE`() + RETURNS date + DETERMINISTIC +BEGIN +/** + * @return The mock date + */ + RETURN DATE(mockTime()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_CURTIME.sql b/db/routines/util/functions/VN_CURTIME.sql new file mode 100644 index 000000000..ae66ea500 --- /dev/null +++ b/db/routines/util/functions/VN_CURTIME.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_CURTIME`() + RETURNS time + DETERMINISTIC +BEGIN +/** + * @return The mock curtime + */ + RETURN TIME(mockTime()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_NOW.sql b/db/routines/util/functions/VN_NOW.sql new file mode 100644 index 000000000..47b1bb4fd --- /dev/null +++ b/db/routines/util/functions/VN_NOW.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_NOW`() + RETURNS datetime + DETERMINISTIC +BEGIN +/** + * @return The mock datetime + */ + RETURN mockTime(); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_UNIX_TIMESTAMP.sql b/db/routines/util/functions/VN_UNIX_TIMESTAMP.sql new file mode 100644 index 000000000..717459862 --- /dev/null +++ b/db/routines/util/functions/VN_UNIX_TIMESTAMP.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_UNIX_TIMESTAMP`() + RETURNS int(11) + DETERMINISTIC +BEGIN + /** + * @return The mock time in unix timestamp format + */ + RETURN UNIX_TIMESTAMP(mocktime()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_UTC_DATE.sql b/db/routines/util/functions/VN_UTC_DATE.sql new file mode 100644 index 000000000..2b40b7dc2 --- /dev/null +++ b/db/routines/util/functions/VN_UTC_DATE.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_UTC_DATE`() + RETURNS date + DETERMINISTIC +BEGIN +/** + * @return The mock Date in UTC format + */ + RETURN DATE(mockUtcTime()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_UTC_TIME.sql b/db/routines/util/functions/VN_UTC_TIME.sql new file mode 100644 index 000000000..930333d23 --- /dev/null +++ b/db/routines/util/functions/VN_UTC_TIME.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_UTC_TIME`() + RETURNS time + DETERMINISTIC +BEGIN +/** + * @return The mock time in utc format + */ + RETURN TIME(mockUtcTime()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/VN_UTC_TIMESTAMP.sql b/db/routines/util/functions/VN_UTC_TIMESTAMP.sql new file mode 100644 index 000000000..97d125874 --- /dev/null +++ b/db/routines/util/functions/VN_UTC_TIMESTAMP.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`VN_UTC_TIMESTAMP`() + RETURNS datetime + DETERMINISTIC +BEGIN +/* + * @return The mock utc datetime + */ + RETURN mockUtcTime(); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/accountShortToStandard.sql b/db/routines/util/functions/accountShortToStandard.sql new file mode 100644 index 000000000..71e360bf3 --- /dev/null +++ b/db/routines/util/functions/accountShortToStandard.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`accountShortToStandard`(vAccount VARCHAR(10)) + RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + RETURN REPLACE(vAccount, '.', REPEAT('0', 11 - LENGTH(vAccount))); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/capitalizeFirst.sql b/db/routines/util/functions/capitalizeFirst.sql new file mode 100644 index 000000000..859777de2 --- /dev/null +++ b/db/routines/util/functions/capitalizeFirst.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`capitalizeFirst`(vString VARCHAR(255)) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC + NO SQL +BEGIN +/** + * Pass the first letter of every word in a string to uppercase. + * + * @param vString String to tranform + * @return Transformed string + */ + DECLARE vNewString VARCHAR(255) DEFAULT ''; + DECLARE vI INT DEFAULT 1; + DECLARE vSpaceIni, vWordIni INT; + DECLARE vLen INT DEFAULT CHAR_LENGTH(vString); + + WHILE vI < vLen + DO + SET vSpaceIni = vI; + + WHILE MID(vString, vI, 1) REGEXP '[[:space:]]' DO + SET vI = vI + 1; + END WHILE; + + SET vWordIni = vI; + SET vI = vWordIni + 1; + + WHILE vI <= vLen AND MID(vString, vI, 1) NOT REGEXP '[[:space:]]' DO + SET vI = vI + 1; + END WHILE; + + SET vNewString = CONCAT(vNewString + ,MID(vString, vSpaceIni, vWordIni - vSpaceIni) + ,UPPER(MID(vString, vWordIni, 1)) + ,MID(vString, vWordIni + 1, vI - vWordIni - 1) + ); + END WHILE; + + RETURN vNewString; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/crypt.sql b/db/routines/util/functions/crypt.sql new file mode 100644 index 000000000..664563cd0 --- /dev/null +++ b/db/routines/util/functions/crypt.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`crypt`(vText VARCHAR(255), vKey VARCHAR(255)) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vResult VARCHAR(255); + + CALL vn.crypt(vText, vKey, vResult); + + RETURN vResult; + +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/cryptOff.sql b/db/routines/util/functions/cryptOff.sql new file mode 100644 index 000000000..bc281e4ec --- /dev/null +++ b/db/routines/util/functions/cryptOff.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`cryptOff`(vText VARCHAR(255), vKey VARCHAR(255)) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vResult VARCHAR(255); + + CALL vn.cryptOff(vText, vKey, vResult); + + RETURN vResult; + +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/dayEnd.sql b/db/routines/util/functions/dayEnd.sql new file mode 100644 index 000000000..1da4dcfe6 --- /dev/null +++ b/db/routines/util/functions/dayEnd.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`dayEnd`(vDated DATE) + RETURNS datetime + DETERMINISTIC + NO SQL +BEGIN +/** + * Formats a date to the end of the day. + * + * @param vDated The date to format + * @return The formatted date + */ + RETURN TIMESTAMP(vDated, '23:59:59'); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/firstDayOfMonth.sql b/db/routines/util/functions/firstDayOfMonth.sql new file mode 100644 index 000000000..77971c7b8 --- /dev/null +++ b/db/routines/util/functions/firstDayOfMonth.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`firstDayOfMonth`(vDate DATE) + RETURNS date + DETERMINISTIC + NO SQL +BEGIN +/** + * Returns the date formatted to the first day of month. + * + * @param vDate The date to format + * @return The formatted date + */ + RETURN TIMESTAMPADD(DAY, - DAY(vDate) + 1, vDate) ; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/firstDayOfYear.sql b/db/routines/util/functions/firstDayOfYear.sql new file mode 100644 index 000000000..710c3a688 --- /dev/null +++ b/db/routines/util/functions/firstDayOfYear.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`firstDayOfYear`(vDate DATE) + RETURNS date + DETERMINISTIC + NO SQL +BEGIN +/** + * Returns the date formatted to the first day of year. + * + * @param vDate The date to format + * @return The formatted date + */ + RETURN DATE_FORMAT(vDate, '%Y-01-01'); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/formatRow.sql b/db/routines/util/functions/formatRow.sql new file mode 100644 index 000000000..b119df015 --- /dev/null +++ b/db/routines/util/functions/formatRow.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`formatRow`(vType CHAR(3), vValues VARCHAR(512)) + RETURNS varchar(512) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + DECLARE vRow VARCHAR(512); + + IF vValues IS NOT NULL THEN + SET vRow = CONCAT(' + + ', vType ,' + ', REPLACE(vValues, ',', '') ,' + + '); + ELSE + SET vRow = ''; + END IF; + + RETURN vRow; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/formatTable.sql b/db/routines/util/functions/formatTable.sql new file mode 100644 index 000000000..00a2b50bf --- /dev/null +++ b/db/routines/util/functions/formatTable.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`formatTable`(vFields VARCHAR(512), vOldValues VARCHAR(512), vNewValues VARCHAR(512)) + RETURNS text CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + DECLARE vTable TEXT; + + SET vTable = CONCAT(' + + + + + + ', formatRow('old', vOldValues) ,' + ', formatRow('new', vNewValues) ,' + +
type', REPLACE(vFields, ',', '') ,' +
+ '); + + RETURN vTable; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/hasDateOverlapped.sql b/db/routines/util/functions/hasDateOverlapped.sql new file mode 100644 index 000000000..9441e201c --- /dev/null +++ b/db/routines/util/functions/hasDateOverlapped.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`hasDateOverlapped`(vSarted1 DATE, vEnded1 DATE, vSarted2 DATE, vEnded2 DATE) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + RETURN GREATEST(vSarted1, vSarted2) <= LEAST(vEnded1,vEnded2); + +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/hmacSha2.sql b/db/routines/util/functions/hmacSha2.sql new file mode 100644 index 000000000..78611c118 --- /dev/null +++ b/db/routines/util/functions/hmacSha2.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`hmacSha2`(`vAlg` SMALLINT, `vMsg` MEDIUMBLOB, `vKey` MEDIUMBLOB) + RETURNS varchar(128) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC + NO SQL +BEGIN +/** + * HMAC function based on SHA2 algorythms. + */ + DECLARE vHashlen INT UNSIGNED; + DECLARE vOpad, vIpad TINYBLOB; + + CASE vAlg + WHEN 224 THEN SET vHashlen = 64; + WHEN 256 THEN SET vHashlen = 64; + WHEN 384 THEN SET vHashlen = 128; + WHEN 512 THEN SET vHashlen = 128; + ELSE CALL throw ('WRONG_ALGORYTHM_IDENTIFICATOR_USED'); + END CASE; + + IF LENGTH(vKey) > vHashlen THEN + SET vKey = UNHEX(SHA2(vKey, vAlg)); + END IF; + + SET vKey = RPAD(vKey, vHashlen, 0x00); + + SET vIpad = stringXor(vKey, 0x36); + SET vOpad = stringXor(vKey, 0x5C); + + RETURN SHA2(CONCAT(vOpad, UNHEX(SHA2(CONCAT(vIpad, vMsg), vAlg))), vAlg); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/isLeapYear.sql b/db/routines/util/functions/isLeapYear.sql new file mode 100644 index 000000000..2c7c96f3d --- /dev/null +++ b/db/routines/util/functions/isLeapYear.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`isLeapYear`(vYear INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + RETURN (DAYOFYEAR(CONCAT(vYear, "-02-29")) IS NOT NULL); + +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/json_removeNulls.sql b/db/routines/util/functions/json_removeNulls.sql new file mode 100644 index 000000000..5fa741380 --- /dev/null +++ b/db/routines/util/functions/json_removeNulls.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`json_removeNulls`(vObject JSON) + RETURNS longtext CHARSET utf8mb4 COLLATE utf8mb4_bin + DETERMINISTIC +BEGIN +/** + * Elimina las propiedades con valor NULL de un objeto. + * + * @param vObject El objeto en formato JSON + * @return El objeto JSON sin propiedades a NULL + */ + DECLARE vKeys JSON; + DECLARE vPath VARCHAR(255); + DECLARE vValue VARCHAR(255); + DECLARE i INT DEFAULT 0; + DECLARE vCount INT; + + SET vKeys = JSON_KEYS(vObject); + SET vCount = JSON_LENGTH(vKeys); + + WHILE i < vCount DO + SET vPath = CONCAT('$.', JSON_VALUE(vKeys, CONCAT('$[',i,']'))); + SET vValue = JSON_VALUE(vObject, vPath); + IF vValue IS NULL THEN + SET vObject = JSON_REMOVE(vObject, vPath); + END IF; + SET i := i + 1; + END WHILE; + + RETURN vObject; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/lang.sql b/db/routines/util/functions/lang.sql new file mode 100644 index 000000000..3431cdcc7 --- /dev/null +++ b/db/routines/util/functions/lang.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`lang`() + RETURNS char(2) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC + NO SQL +BEGIN +/** + * Returns the current language code. + * + * @return The language code + */ + RETURN IFNULL(@lang, SUBSTR(@@lc_messages, 1, 2)); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/lastDayOfYear.sql b/db/routines/util/functions/lastDayOfYear.sql new file mode 100644 index 000000000..52607ae21 --- /dev/null +++ b/db/routines/util/functions/lastDayOfYear.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`lastDayOfYear`(vDate DATE) + RETURNS date + DETERMINISTIC + NO SQL +BEGIN +/** + * Returns the date formatted to the first day of year. + * + * @param vDate The date to format + * @return The formatted date + */ + RETURN DATE_FORMAT(vDate, '%Y-12-31'); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/log_formatDate.sql b/db/routines/util/functions/log_formatDate.sql new file mode 100644 index 000000000..84c269027 --- /dev/null +++ b/db/routines/util/functions/log_formatDate.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`log_formatDate`(vInstance JSON) + RETURNS longtext CHARSET utf8mb4 COLLATE utf8mb4_bin + DETERMINISTIC +BEGIN + DECLARE vKeys JSON; + DECLARE vPath VARCHAR(255); + DECLARE vValue VARCHAR(255); + DECLARE i INT DEFAULT 0; + DECLARE vCount INT; + + IF vInstance IS NULL THEN + RETURN NULL; + END IF; + + SET vKeys = JSON_KEYS(vInstance); + SET vCount = JSON_LENGTH(vInstance); + + WHILE i < vCount DO + SET vPath = CONCAT('$.', JSON_VALUE(vKeys, CONCAT('$[', i ,']'))); + SET vValue = JSON_VALUE(vInstance, vPath); + IF vValue REGEXP '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}$' THEN + SET vInstance = JSON_SET(vInstance, vPath, DATE_FORMAT(CONVERT_TZ(vValue, '+01:00', '+00:00'), '%Y-%m-%dT%T.%fZ')); + END IF; + SET i := i + 1; + END WHILE; + + RETURN vInstance; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/midnight.sql b/db/routines/util/functions/midnight.sql new file mode 100644 index 000000000..c80abdbb0 --- /dev/null +++ b/db/routines/util/functions/midnight.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`midnight`() + RETURNS datetime + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + RETURN TIMESTAMP(util.VN_CURDATE(), '23:59:59'); + +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/mockTime.sql b/db/routines/util/functions/mockTime.sql new file mode 100644 index 000000000..ab7859e7d --- /dev/null +++ b/db/routines/util/functions/mockTime.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTime`() + RETURNS datetime + DETERMINISTIC +BEGIN +/** + * Returns current dateTime + * + * @return current datetime + */ + RETURN NOW(); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/mockTimeBase.sql b/db/routines/util/functions/mockTimeBase.sql new file mode 100644 index 000000000..7b3ea1a4a --- /dev/null +++ b/db/routines/util/functions/mockTimeBase.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTimeBase`(vIsUtc BOOL) + RETURNS datetime + DETERMINISTIC +BEGIN +/** + * Returns the date formatted to utc if vIsUtc or config.mocTz if not + * + * @param vIsUtc If date must be returned as UTC format + * @return The formatted mock time + */ +DECLARE vMockUtcTime DATETIME; + DECLARE vMockTz VARCHAR(255); + + SELECT mockUtcTime, mockTz + INTO vMockUtcTime, vMockTz + FROM config + LIMIT 1; + + IF vIsUtc OR vMockTz IS NULL THEN + RETURN vMockUtcTime; + ELSE + RETURN CONVERT_TZ(vMockUtcTime, '+00:00', vMockTz); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/mockUtcTime.sql b/db/routines/util/functions/mockUtcTime.sql new file mode 100644 index 000000000..e79c3b241 --- /dev/null +++ b/db/routines/util/functions/mockUtcTime.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`mockUtcTime`() + RETURNS datetime + DETERMINISTIC +BEGIN +/** + * Returns the UTC datetime in mockTime format or timeStamp depending on config table + * + * @return The UTC datetime format + */ +-- FIXME: #5041 Commented because there is slowness when querying a table +/* + DECLARE vMockEnabled BOOL; + + SELECT mockEnabled INTO vMockEnabled FROM config LIMIT 1; + + IF vMockEnabled THEN + RETURN mockTimeBase(TRUE); + ELSE + RETURN UTC_TIMESTAMP(); + END IF; +*/ + RETURN UTC_TIMESTAMP(); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/nextWeek.sql b/db/routines/util/functions/nextWeek.sql new file mode 100644 index 000000000..f764201aa --- /dev/null +++ b/db/routines/util/functions/nextWeek.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`nextWeek`(vYearWeek INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * A partir de un perido año/semana en formato AAAASS devuelve el siguiente + * periodo. Esta función trabaja de la misma forma que la función WEEK() en + * modo 3. + */ + DECLARE vYear INT DEFAULT FLOOR(vYearWeek / 100); + + IF vYearWeek < YEARWEEK(CONCAT(vYear, '-12-31'), 3) THEN + RETURN vYearWeek + 1; + ELSE + RETURN ((vYear + 1) * 100) + 1; + END IF; +END$$ +DELIMITER ; diff --git a/db/.archive/224702/00-notificationProc.sql b/db/routines/util/functions/notification_send.sql similarity index 66% rename from db/.archive/224702/00-notificationProc.sql rename to db/routines/util/functions/notification_send.sql index 2cf11b4f1..981cde2d6 100644 --- a/db/.archive/224702/00-notificationProc.sql +++ b/db/routines/util/functions/notification_send.sql @@ -1,8 +1,8 @@ -DROP FUNCTION IF EXISTS `util`.`notification_send`; DELIMITER $$ -CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`notification_send`(vNotificationName VARCHAR(255), vParams TEXT, vAuthorFk INT) - RETURNS INT - MODIFIES SQL DATA +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`notification_send`(vNotificationName VARCHAR(255), vParams TEXT, vAuthorFk INT) + RETURNS int(11) + NOT DETERMINISTIC + MODIFIES SQL DATA BEGIN /** * Sends a notification. diff --git a/db/routines/util/functions/quarterFirstDay.sql b/db/routines/util/functions/quarterFirstDay.sql new file mode 100644 index 000000000..b8239ffc8 --- /dev/null +++ b/db/routines/util/functions/quarterFirstDay.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`quarterFirstDay`(vYear INT, vQuarter INT) + RETURNS date + DETERMINISTIC +BEGIN + RETURN CONCAT(vYear,"-", ((vQuarter - 1) * 3) + 1, "-01"); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/quoteIdentifier.sql b/db/routines/util/functions/quoteIdentifier.sql new file mode 100644 index 000000000..1c0c4c543 --- /dev/null +++ b/db/routines/util/functions/quoteIdentifier.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`quoteIdentifier`(vString TEXT) + RETURNS text CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC + NO SQL +BEGIN + RETURN CONCAT('`', REPLACE(vString, '`', '``'), '`'); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/stringXor.sql b/db/routines/util/functions/stringXor.sql new file mode 100644 index 000000000..252cd0040 --- /dev/null +++ b/db/routines/util/functions/stringXor.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`stringXor`(vString MEDIUMBLOB, vConst TINYINT UNSIGNED) + RETURNS mediumblob + DETERMINISTIC + NO SQL +BEGIN +/** + * Returns XOR of binary string and an 8-bit constant. + */ + DECLARE vLen, vPos INT UNSIGNED; + DECLARE vResult MEDIUMBLOB; + + SET vLen = LENGTH(vString); + SET vPos = 1; + SET vResult = ''; + + WHILE vPos <= vLen DO + SET vResult = CONCAT(vResult, LPAD(HEX( ORD(SUBSTR(vString, vPos, 1)) ^ vConst), 2, '0')); + SET vPos = vPos + 1; + END WHILE; + + RETURN UNHEX(vResult); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/today.sql b/db/routines/util/functions/today.sql new file mode 100644 index 000000000..d57b04071 --- /dev/null +++ b/db/routines/util/functions/today.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`today`() + RETURNS date + DETERMINISTIC +BEGIN +/** + * Devuelve la fecha actual. Usar en lugar de la función nativa + * util.VN_CURDATE() en aquellos que se necesite rendimiento ya que la + * la última no es determinista. + * + * @return La fecha actual + */ + RETURN util.VN_CURDATE(); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/tomorrow.sql b/db/routines/util/functions/tomorrow.sql new file mode 100644 index 000000000..71fbcf8f5 --- /dev/null +++ b/db/routines/util/functions/tomorrow.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`tomorrow`() + RETURNS date + DETERMINISTIC +BEGIN +/** + * Devuelve la fecha de mañana. + * + * @return La fecha de mañana + */ + RETURN TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/twoDaysAgo.sql b/db/routines/util/functions/twoDaysAgo.sql new file mode 100644 index 000000000..2612ed689 --- /dev/null +++ b/db/routines/util/functions/twoDaysAgo.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`twoDaysAgo`() + RETURNS date + DETERMINISTIC +BEGIN +/** + * Devuelve la fecha de antes de ayer. + * + * @return La fecha de antes de ayer + */ + RETURN TIMESTAMPADD(DAY, -2, util.VN_CURDATE()); +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/yearRelativePosition.sql b/db/routines/util/functions/yearRelativePosition.sql new file mode 100644 index 000000000..e62e50eb4 --- /dev/null +++ b/db/routines/util/functions/yearRelativePosition.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`yearRelativePosition`(vYear INT) + RETURNS varchar(20) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN +/** + * Devuelve la posicion del año relativa al año actual. + * Se utiliza como cabecera en informes de balances. + * + * @param vYear Año a evaluar + * @return La posicion relativa del año + */ + DECLARE vCurYear INT DEFAULT YEAR(util.VN_CURDATE()); + + IF vYear = vCurYear THEN + RETURN 'curYear'; + END IF; + + IF vYear = vCurYear - 1 THEN + RETURN 'lastYear'; + END IF; + + IF vYear = vCurYear - 2 THEN + RETURN 'twoYearsAgo'; + END IF; + + RETURN 'other'; +END$$ +DELIMITER ; diff --git a/db/routines/util/functions/yesterday.sql b/db/routines/util/functions/yesterday.sql new file mode 100644 index 000000000..a1938ab10 --- /dev/null +++ b/db/routines/util/functions/yesterday.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`yesterday`() + RETURNS date + DETERMINISTIC +BEGIN +/** + * Devuelve la fecha de ayer. + * + * @return La fecha de ayer + */ + RETURN TIMESTAMPADD(DAY, -1, util.VN_CURDATE()); +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/checkHex.sql b/db/routines/util/procedures/checkHex.sql new file mode 100644 index 000000000..3cd5452e8 --- /dev/null +++ b/db/routines/util/procedures/checkHex.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`checkHex`(vParam VARCHAR(255)) +BEGIN +/** + * Comprueba si vParam es un número hexadecimal que empieza por # y tiene una longitud total de 7 dígitos + * + * @param expresión a comprobar + */ + IF vParam NOT REGEXP ('^#[0-9a-f]{6}$') THEN + CALL util.throw('Invalid RGB format'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/debugAdd.sql b/db/routines/util/procedures/debugAdd.sql new file mode 100644 index 000000000..8c690376e --- /dev/null +++ b/db/routines/util/procedures/debugAdd.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`debugAdd`(vVariable VARCHAR(255), vValue VARCHAR(255)) + MODIFIES SQL DATA +BEGIN +/** + * Añade una entrada de depuración en la tabla @debug. + * + * @param vVariable Nombre de variable + * @param vValue Valor de la variable + */ + DECLARE vIndex INT DEFAULT INSTR(USER(), '@'); + + INSERT INTO debug SET + `connectionId` = CONNECTION_ID(), + `user` = LEFT(USER(), vIndex - 1), + `host` = RIGHT(USER(), CHAR_LENGTH(USER()) - vIndex), + `variable` = vVariable, + `value` = vValue; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/exec.sql b/db/routines/util/procedures/exec.sql new file mode 100644 index 000000000..ca66884a5 --- /dev/null +++ b/db/routines/util/procedures/exec.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`exec`(vSqlQuery TEXT) + SQL SECURITY INVOKER +BEGIN +/** + * Executes a string with an SQL query. + * + * @param vSqlQuery The SQL string + */ + SET @sqlQuery = vSqlQuery; + + PREPARE stmt FROM @sqlQuery; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + + SET @sqlQuery = NULL; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/log_add.sql b/db/routines/util/procedures/log_add.sql new file mode 100644 index 000000000..a5b1519c4 --- /dev/null +++ b/db/routines/util/procedures/log_add.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`log_add`( + vSchema VARCHAR(45), + vEntity VARCHAR(45), + vChangedModel VARCHAR(45), + vOriginFk INT, + vChangedModelId INT, + vActionCode VARCHAR(45), + vOldInstance JSON, + vNewInstance JSON) +BEGIN +/** + * Guarda las acciones realizadas por el usuario + * + * @param vOriginFk Id del registro de origen + * @param vActionCode Código de la acción {insert | delete | update} + * @param vScheme Esquema al que pertenece la tabla. + * @param vEntity Nombre que hace referencia a la tabla. + * @param vOldInstance Valores antiguos + * @param vNewInstance Valores nuevos + */ + CALL util.log_addWithUser(vSchema, vEntity, + vChangedModel, vOriginFk, vChangedModelId, vActionCode, vOldInstance, vNewInstance, account.myUser_getId()); +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/log_addWithUser.sql b/db/routines/util/procedures/log_addWithUser.sql new file mode 100644 index 000000000..2e20821a6 --- /dev/null +++ b/db/routines/util/procedures/log_addWithUser.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`log_addWithUser`( + vSchema VARCHAR(45), + vEntity VARCHAR(45), + vChangedModel VARCHAR(45), + vOriginFk INT, + vChangedModelId INT, + vActionCode VARCHAR(45), + vOldInstance JSON, + vNewInstance JSON, + vUserId INT) +BEGIN +/** + * Guarda las acciones realizadas por el usuario + * + * @param vScheme Esquema al que pertenece la tabla. + * @param vEntity Nombre que hace referencia a la tabla donde se insertará el log + * @param vChangedModel Nombre que hace referencia a la tabla que se modifica + * @param vOriginFk Id del registro de la tabla origen + * @param vChangedModelId Id del registro de la tabla a la que se realiza la acción + * @param vActionCode Código de la acción {insert | delete | update} + * @param vOldInstance JSON que contiene los valores viejos + * @param vNewInstance JSON que contiene los valores nuevos + * @param vUserId Id del usuario que realiza la acción + */ + DECLARE vTableName VARCHAR(255) DEFAULT CONCAT(IFNULL(vEntity, ''), 'Log'); + + SET vSchema = util.quoteIdentifier(vSchema); + SET vTableName = util.quoteIdentifier(vTableName); + + CALL util.log_cleanInstances(vActionCode, vOldInstance, vNewInstance); + + EXECUTE IMMEDIATE CONCAT( + 'INSERT INTO ', vSchema, '.', vTableName, ' SET changedModel = ?, originFk = ?, changedModelId= ?, action = ?, oldInstance = ?, newInstance = ?, userFk = ?' + ) USING vChangedModel, vOriginFk, vChangedModelId, vActionCode, vOldInstance, vNewInstance, vUserId; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/log_cleanInstances.sql b/db/routines/util/procedures/log_cleanInstances.sql new file mode 100644 index 000000000..756a8d1f3 --- /dev/null +++ b/db/routines/util/procedures/log_cleanInstances.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`log_cleanInstances`( + vActionCode VARCHAR(45), + INOUT vOldInstance JSON, + INOUT vNewInstance JSON) +BEGIN +/** + * Cleans both instances removing nulls and keys whose values are the same. + * + * @param vActionCode The action code {insert | delete | update} + * @param vOldInstance JSON containing the old values + * @param vNewInstance JSON containing the new values + */ + DECLARE vKeys JSON; + DECLARE vPath VARCHAR(255); + DECLARE vOldValue JSON; + DECLARE vNewValue JSON; + DECLARE vOld JSON; + DECLARE vNew JSON; + DECLARE i INT DEFAULT 0; + DECLARE vCount INT; + + CASE vActionCode + WHEN 'insert' THEN + SET vNewInstance = json_removeNulls(vNewInstance); + WHEN 'update' THEN + SET vOld = '{}'; + SET vNew = '{}'; + SET vKeys = JSON_KEYS(vNewInstance); + SET vCount = JSON_LENGTH(vKeys); + WHILE i < vCount DO + SET vPath = CONCAT('$.', JSON_VALUE(vKeys, CONCAT('$[',i,']'))); + SET vOldValue = JSON_EXTRACT(vOldInstance, vPath); + SET vNewValue = JSON_EXTRACT(vNewInstance, vPath); + IF NOT (vOldValue <=> vNewValue) THEN + IF vOldValue IS NOT NULL AND vOldValue <> 'null' THEN + SET vOld = JSON_SET(vOld, vPath, JSON_COMPACT(vOldValue)); + END IF; + IF vNewValue IS NOT NULL THEN + SET vNew = JSON_SET(vNew, vPath, JSON_COMPACT(vNewValue)); + END IF; + END IF; + SET i := i + 1; + END WHILE; + SET vOldInstance = vOld; + SET vNewInstance = vNew; + WHEN 'delete' THEN + SET vOldInstance = json_removeNulls(vOldInstance); + ELSE BEGIN END; + END CASE; + + SET vOldInstance = log_formatDate(vOldInstance); + SET vNewInstance = log_formatDate(vNewInstance); +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/procNoOverlap.sql b/db/routines/util/procedures/procNoOverlap.sql new file mode 100644 index 000000000..9bb2f109e --- /dev/null +++ b/db/routines/util/procedures/procNoOverlap.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`procNoOverlap`(procName VARCHAR(255)) + SQL SECURITY INVOKER +proc: BEGIN +/** + * call procedure without overlap + */ + DECLARE vIsChanged BOOL; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK(procName); + RESIGNAL; + END; + + IF !GET_LOCK(procName, 0) THEN + LEAVE proc; + END IF; + + CALL exec(CONCAT('CALL ', procName)); + + DO RELEASE_LOCK(procName); +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/proc_changedPrivs.sql b/db/routines/util/procedures/proc_changedPrivs.sql new file mode 100644 index 000000000..220652d1a --- /dev/null +++ b/db/routines/util/procedures/proc_changedPrivs.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`proc_changedPrivs`() +BEGIN + SELECT s.* + FROM proc_privs s + LEFT JOIN mysql.procs_priv p + ON p.`Host` = s.`Host` + AND p.`Host` = s.`Host` + AND p.`Db` = s.`Db` + AND p.`User` = s.`User` + AND p.`Routine_name` = s.`Routine_name` + AND p.`Routine_type` = s.`Routine_type` + WHERE p.Proc_priv IS NULL; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/proc_restorePrivs.sql b/db/routines/util/procedures/proc_restorePrivs.sql new file mode 100644 index 000000000..0d502a6db --- /dev/null +++ b/db/routines/util/procedures/proc_restorePrivs.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`proc_restorePrivs`() +BEGIN +/** + * Restores the privileges saved by proc_savePrivs(). + * This procedure should be called after modifying a procedure, + * for more info see proc_savePrivs(). + */ + INSERT IGNORE INTO mysql.procs_priv + SELECT * FROM proc_privs; + + FLUSH PRIVILEGES; + DROP TEMPORARY TABLE proc_privs; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/proc_savePrivs.sql b/db/routines/util/procedures/proc_savePrivs.sql new file mode 100644 index 000000000..75c289f7b --- /dev/null +++ b/db/routines/util/procedures/proc_savePrivs.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`proc_savePrivs`() +BEGIN +/** + * Saves routine privileges, used to simplify the task of keeping + * routine privileges when they are modified due to the lack of + * CREATE OR REPLACE [PROCEDURE|FUNCTION]. + * This procedure should be called before modifying a routine, to + * restore the saved privileges use proc_restorePrivs(). + */ + CREATE TEMPORARY TABLE proc_privs + ENGINE = MEMORY + SELECT * FROM mysql.procs_priv; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/slowLog_prune.sql b/db/routines/util/procedures/slowLog_prune.sql new file mode 100644 index 000000000..7294be2f6 --- /dev/null +++ b/db/routines/util/procedures/slowLog_prune.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`slowLog_prune`() +BEGIN +/** + * Prunes MySQL slow query log table deleting all records older than one week. + */ + DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log; + DECLARE vSqlLogBin INT DEFAULT @@SESSION.sql_log_bin; + + SET sql_log_bin = OFF; + SET GLOBAL slow_query_log = OFF; + + RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`; + + DELETE FROM `mysql`.`slow_log_temp` + WHERE start_time < TIMESTAMPADD(WEEK, -1, util.VN_NOW()); + + RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`; + + SET GLOBAL slow_query_log = vSlowQueryLog; + SET sql_log_bin = vSqlLogBin; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/throw.sql b/db/routines/util/procedures/throw.sql new file mode 100644 index 000000000..260915e0d --- /dev/null +++ b/db/routines/util/procedures/throw.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`throw`(vMessage CHAR(55)) +BEGIN +/** + * Throws a user-defined exception. + * + * @param vMessage The error message + */ + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = vMessage; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/time_generate.sql b/db/routines/util/procedures/time_generate.sql new file mode 100644 index 000000000..14cc1edc5 --- /dev/null +++ b/db/routines/util/procedures/time_generate.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`time_generate`(vStarted DATE, vEnded DATE) +BEGIN +/** + * Generate a temporary table between the days passed as parameters + * + * @param vStarted Start date + * @param vEnded End date + * @table tmp.time (dated, dayed, weeked, monthed, yeared) + */ + DECLARE vCurrentDate DATE; + + CREATE OR REPLACE TEMPORARY TABLE tmp.time( + dated DATE PRIMARY KEY, + `day` INT, + `week` INT, + `month` INT, + `year` INT + ) ENGINE = MEMORY; + + IF(vStarted > vEnded) THEN + CALL throw('The started cannot be later than the ended'); + END IF; + + SET vCurrentDate = vStarted; + + WHILE vCurrentDate <= vEnded DO + INSERT INTO tmp.time + SET dated = vCurrentDate, + `day` = DAY(vCurrentDate), + `week` = WEEK(vCurrentDate), + `month` = MONTH(vCurrentDate), + `year` = YEAR(vCurrentDate); + + SET vCurrentDate = vCurrentDate + INTERVAL 1 DAY; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/warn.sql b/db/routines/util/procedures/warn.sql new file mode 100644 index 000000000..e1dd33c9c --- /dev/null +++ b/db/routines/util/procedures/warn.sql @@ -0,0 +1,7 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`warn`(vCode CHAR(35)) +BEGIN + DECLARE w VARCHAR(1) DEFAULT '__'; + SET @warn = vCode; +END$$ +DELIMITER ; diff --git a/db/routines/util/views/eventLogGrouped.sql b/db/routines/util/views/eventLogGrouped.sql new file mode 100644 index 000000000..8615458b5 --- /dev/null +++ b/db/routines/util/views/eventLogGrouped.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `util`.`eventLogGrouped` +AS SELECT max(`t`.`date`) AS `lastHappened`, + COUNT(0) AS `nErrors`, + `t`.`event` AS `event`, + `t`.`error` AS `error` +FROM `util`.`eventLog` `t` +GROUP BY `t`.`event`, + `t`.`error` +ORDER BY max(`t`.`date`) DESC diff --git a/db/routines/vn/events/client_unassignSalesPerson.sql b/db/routines/vn/events/client_unassignSalesPerson.sql new file mode 100644 index 000000000..4ca8b7de9 --- /dev/null +++ b/db/routines/vn/events/client_unassignSalesPerson.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`jgallego`@`%` EVENT `vn`.`client_unassignSalesPerson` + ON SCHEDULE EVERY 1 DAY + STARTS '2023-06-01 03:30:00.000' + ON COMPLETION PRESERVE + DISABLE +DO CALL client_unassignSalesPerson$$ +DELIMITER ; diff --git a/db/routines/vn/events/clientsDisable.sql b/db/routines/vn/events/clientsDisable.sql new file mode 100644 index 000000000..00cd4ed8b --- /dev/null +++ b/db/routines/vn/events/clientsDisable.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`clientsDisable` + ON SCHEDULE EVERY 1 MONTH + STARTS '2023-06-01 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + UPDATE account.user u + JOIN client c ON c.id = u.id + JOIN clientType ct ON ct.id = c.typeFk + SET u.active = FALSE + WHERE ct.code = 'normal' + AND u.id NOT IN ( + SELECT DISTINCT c.id + FROM client c + LEFT JOIN ticket t ON t.clientFk = c.id + WHERE c.salesPersonFk IS NOT NULL + OR t.created > util.VN_CURDATE() - INTERVAL 2 MONTH + OR shipped > util.VN_CURDATE() - INTERVAL 2 MONTH + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/events/collection_make.sql b/db/routines/vn/events/collection_make.sql new file mode 100644 index 000000000..1c6bd0fcb --- /dev/null +++ b/db/routines/vn/events/collection_make.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`collection_make` + ON SCHEDULE EVERY 5 MINUTE + STARTS '2022-09-15 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL vn.collection_make$$ +DELIMITER ; diff --git a/db/routines/vn/events/department_doCalc.sql b/db/routines/vn/events/department_doCalc.sql new file mode 100644 index 000000000..b3ce49fa5 --- /dev/null +++ b/db/routines/vn/events/department_doCalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`department_doCalc` + ON SCHEDULE EVERY 15 SECOND + STARTS '2019-11-15 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL vn.department_doCalc$$ +DELIMITER ; diff --git a/db/routines/vn/events/envialiaThreHoldChecker.sql b/db/routines/vn/events/envialiaThreHoldChecker.sql new file mode 100644 index 000000000..a5440ef67 --- /dev/null +++ b/db/routines/vn/events/envialiaThreHoldChecker.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`envialiaThreHoldChecker` + ON SCHEDULE EVERY 1 DAY + STARTS '2022-01-28 09:52:46.000' + ON COMPLETION NOT PRESERVE + ENABLE +DO BEGIN + DECLARE vActualNumber BIGINT; + DECLARE vEndRange BIGINT; + DECLARE vIsAlreadyNotified BOOLEAN; + DECLARE vNotificationThrehold INT; + + SELECT actualNumber, endRange, isAlreadyNotified, notificationThrehold + INTO vActualNumber, vEndRange, vIsAlreadyNotified, vNotificationThrehold + FROM envialiaConfig; + + IF (vActualNumber+vNotificationThrehold) >= vEndRange AND + vIsAlreadyNotified = FALSE + THEN + CALL mail_insert( + 'cau@verdnatura.es', + NULL, + 'Hablar con envialia, acercandonos al numero final del rango permitido para las etiquetas', + CONCAT('Numero actual: ', vActualNumber, ' , numero final: ',vEndRange) + ); + UPDATE envialiaConfig SET isAlreadyNotified = TRUE; + END IF; + + IF (vActualNumber+vNotificationThrehold) < vEndRange AND + vIsAlreadyNotified = TRUE + THEN + UPDATE envialiaConfig SET isAlreadyNotified = FALSE; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/events/greuge_notify.sql b/db/routines/vn/events/greuge_notify.sql new file mode 100644 index 000000000..8c23dbe36 --- /dev/null +++ b/db/routines/vn/events/greuge_notify.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`greuge_notify` + ON SCHEDULE EVERY 1 DAY + STARTS '2023-01-01 00:07:00.000' + ON COMPLETION NOT PRESERVE + ENABLE + COMMENT 'Notifies subscribed users of events in wrong greuges' +DO CALL vn.greuge_notifyEvents()$$ +DELIMITER ; diff --git a/db/routines/vn/events/itemImageQueue_check.sql b/db/routines/vn/events/itemImageQueue_check.sql new file mode 100644 index 000000000..680faa37f --- /dev/null +++ b/db/routines/vn/events/itemImageQueue_check.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`itemImageQueue_check` + ON SCHEDULE EVERY 1 HOUR + STARTS '2023-07-28 00:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + DELETE FROM itemImageQueue + WHERE attempts >= (SELECT downloadMaxAttempts FROM itemConfig); +END$$ +DELIMITER ; diff --git a/db/routines/vn/events/mysqlConnectionsSorter_kill.sql b/db/routines/vn/events/mysqlConnectionsSorter_kill.sql new file mode 100644 index 000000000..1f5d46b18 --- /dev/null +++ b/db/routines/vn/events/mysqlConnectionsSorter_kill.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`mysqlConnectionsSorter_kill` + ON SCHEDULE EVERY 1 MINUTE + STARTS '2021-10-28 09:56:27.000' + ON COMPLETION NOT PRESERVE + ENABLE +DO CALL mysqlConnectionsSorter_kill()$$ +DELIMITER ; diff --git a/db/routines/vn/events/printQueue_check.sql b/db/routines/vn/events/printQueue_check.sql new file mode 100644 index 000000000..262ddc7c8 --- /dev/null +++ b/db/routines/vn/events/printQueue_check.sql @@ -0,0 +1,84 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`printQueue_check` + ON SCHEDULE EVERY 10 MINUTE + STARTS '2022-01-28 09:52:46.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + + DECLARE vCurrentCount INT; + DECLARE vCheckSum INT; + DECLARE vIsAlreadyNotified BOOLEAN; + DECLARE vTableQueue TEXT; + DECLARE vLineQueue TEXT; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vPrintQueueLimit INT; + + DECLARE vCur CURSOR FOR + SELECT CONCAT('\n\t\t\t\t\t\t\t', IFNULL(pq.id, ''), '\n\t\t\t\t\t\t\t', IFNULL(p.path, ''),'\n\t\t\t\t\t\t\t', IFNULL(r.name, ''),'\n\t\t\t\t\t\t\t', IFNULL(pq.statusCode, ''),'\n\t\t\t\t\t\t\t', IFNULL(w.firstname, ''), " ", IFNULL(w.lastName, ''),'\n\t\t\t\t\t\t\t', IFNULL(pq.`error`, ''),'\n\t\t\t\t\t\t') + FROM printQueue pq + LEFT JOIN worker w ON w.id = pq.workerFk + LEFT JOIN printer p ON p.id = pq.printerFk + LEFT JOIN report r ON r.id = pq.reportFk + JOIN printQueueConfig + LIMIT vPrintQueueLimit; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SELECT printQueueLimit INTO vPrintQueueLimit + FROM printQueueConfig; + + SELECT COUNT(*), IFNULL(SUM(id),0) INTO vCurrentCount, vCheckSum + FROM printQueue WHERE statusCode = 'queued'; + + SELECT isAlreadyNotified INTO vIsAlreadyNotified + FROM printingQueueCheck; + + IF (SELECT lastCount FROM printingQueueCheck) = vCurrentCount AND + (SELECT lastCheckSum FROM printingQueueCheck) = vCheckSum AND + vIsAlreadyNotified = FALSE AND vCurrentCount > 0 + THEN + + SELECT '\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t' INTO vTableQueue; + + OPEN vCur; + + l: LOOP + + SET vDone = FALSE; + + FETCH vCur INTO vLineQueue; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT CONCAT(vTableQueue, vLineQueue) INTO vTableQueue; + + END LOOP; + + CLOSE vCur; + + CALL mail_insert( + 'cau@verdnatura.es', + NULL, + 'Servidor de impresion parado', + CONCAT('Hay ', vCurrentCount, ' lineas bloqueadas', vTableQueue, '
Id ColaRuta ImpresoraInformeEstadoTrabajadorError
') + ); + + UPDATE printingQueueCheck SET isAlreadyNotified = TRUE; + END IF; + + IF (SELECT lastCount FROM printingQueueCheck) > vCurrentCount AND + vIsAlreadyNotified = TRUE + THEN + UPDATE printingQueueCheck SET isAlreadyNotified = FALSE; + END IF; + + UPDATE printingQueueCheck + SET lastCount = vCurrentCount, + lastCheckSum = vCheckSum; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/events/route_doRecalc.sql b/db/routines/vn/events/route_doRecalc.sql new file mode 100644 index 000000000..62f75a3bc --- /dev/null +++ b/db/routines/vn/events/route_doRecalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`route_doRecalc` + ON SCHEDULE EVERY 10 SECOND + STARTS '2021-07-08 07:32:23.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL route_doRecalc$$ +DELIMITER ; diff --git a/db/routines/vn/events/sale_checkWithoutComponents.sql b/db/routines/vn/events/sale_checkWithoutComponents.sql new file mode 100644 index 000000000..b67a6f4fa --- /dev/null +++ b/db/routines/vn/events/sale_checkWithoutComponents.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`sale_checkWithoutComponents` + ON SCHEDULE EVERY 10 MINUTE + STARTS '2020-05-04 11:56:23.000' + ON COMPLETION PRESERVE + DISABLE +DO call sale_checkNoComponents(DATE_ADD(util.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(util.VN_NOW(), INTERVAL -1 MINUTE))$$ +DELIMITER ; diff --git a/db/routines/vn/events/ticket_doRecalc.sql b/db/routines/vn/events/ticket_doRecalc.sql new file mode 100644 index 000000000..9209c5715 --- /dev/null +++ b/db/routines/vn/events/ticket_doRecalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`ticket_doRecalc` + ON SCHEDULE EVERY 10 SECOND + STARTS '2022-01-28 09:29:18.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL ticket_doRecalc$$ +DELIMITER ; diff --git a/db/routines/vn/events/travel_doRecalc.sql b/db/routines/vn/events/travel_doRecalc.sql new file mode 100644 index 000000000..a08ecc068 --- /dev/null +++ b/db/routines/vn/events/travel_doRecalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`travel_doRecalc` + ON SCHEDULE EVERY 15 SECOND + STARTS '2019-05-17 10:52:29.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL travel_doRecalc$$ +DELIMITER ; diff --git a/db/routines/vn/events/vehicle_notify.sql b/db/routines/vn/events/vehicle_notify.sql new file mode 100644 index 000000000..d974e1817 --- /dev/null +++ b/db/routines/vn/events/vehicle_notify.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`vehicle_notify` + ON SCHEDULE EVERY 1 DAY + STARTS '2022-01-01 00:07:00.000' + ON COMPLETION NOT PRESERVE + ENABLE + COMMENT 'Notifies subscribed users of events in vehicles that are about t' +DO CALL vn.vehicle_notifyEvents$$ +DELIMITER ; diff --git a/db/routines/vn/events/workerJourney_doRecalc.sql b/db/routines/vn/events/workerJourney_doRecalc.sql new file mode 100644 index 000000000..61077fc5b --- /dev/null +++ b/db/routines/vn/events/workerJourney_doRecalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`workerJourney_doRecalc` + ON SCHEDULE EVERY 1 DAY + STARTS '2023-07-22 04:00:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL workerJourney_replace(util.VN_CURDATE() - INTERVAL 1 WEEK, util.VN_CURDATE(), NULL)$$ +DELIMITER ; diff --git a/db/routines/vn/events/worker_updateChangedBusiness.sql b/db/routines/vn/events/worker_updateChangedBusiness.sql new file mode 100644 index 000000000..02f7af8aa --- /dev/null +++ b/db/routines/vn/events/worker_updateChangedBusiness.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`worker_updateChangedBusiness` + ON SCHEDULE EVERY 1 DAY + STARTS '2000-01-01 00:00:05.000' + ON COMPLETION NOT PRESERVE + ENABLE +DO CALL worker_updateChangedBusiness$$ +DELIMITER ; diff --git a/db/routines/vn/events/zoneGeo_doCalc.sql b/db/routines/vn/events/zoneGeo_doCalc.sql new file mode 100644 index 000000000..579141e13 --- /dev/null +++ b/db/routines/vn/events/zoneGeo_doCalc.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`zoneGeo_doCalc` + ON SCHEDULE EVERY 15 SECOND + STARTS '2019-09-13 15:30:47.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL vn.zoneGeo_doCalc$$ +DELIMITER ; diff --git a/db/routines/vn/functions/MIDNIGHT.sql b/db/routines/vn/functions/MIDNIGHT.sql new file mode 100644 index 000000000..c2df0c0c6 --- /dev/null +++ b/db/routines/vn/functions/MIDNIGHT.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`MIDNIGHT`(vDate DATE) + RETURNS datetime + DETERMINISTIC +BEGIN + RETURN TIMESTAMP(vDate,'23:59:59'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/addressTaxArea.sql b/db/routines/vn/functions/addressTaxArea.sql new file mode 100644 index 000000000..3586dd4ce --- /dev/null +++ b/db/routines/vn/functions/addressTaxArea.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`addressTaxArea`(vAddresId INT, vCompanyId INT) + RETURNS varchar(25) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN +/** + * Devuelve el area de un Consignatario, + * intracomunitario, extracomunitario, nacional o recargo de equivalencia. + * Asumimos que no tenemos ninguna empresa + * + * @param vAddresId Id del Consignatario + * @param vCompanyId Compañia desde la que se factura + * @return Código de area + */ + DECLARE vTaxArea VARCHAR(25); + + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany + SELECT vAddresId addressFk, vCompanyId companyFk; + + CALL vn.addressTaxArea(); + SELECT areaFk INTO vTaxArea FROM tmp.addressTaxArea; + DROP TEMPORARY TABLE + tmp.addressCompany, + tmp.addressTaxArea; + + RETURN vTaxArea; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/address_getGeo.sql b/db/routines/vn/functions/address_getGeo.sql new file mode 100644 index 000000000..1a9f5ddb8 --- /dev/null +++ b/db/routines/vn/functions/address_getGeo.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`address_getGeo`(vSelf INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Returns the geo for the passed address. + * + * @param vSelf The address id + * @return The geo id + */ + DECLARE vGeoFk INT; + + SELECT p.geoFk INTO vGeoFk + FROM address a + JOIN town t ON t.provinceFk = a.provinceFk + JOIN postCode p ON p.townFk = t.id AND p.`code` = a.postalCode + WHERE a.id = vSelf + ORDER BY (a.city SOUNDS LIKE t.`name`) DESC + LIMIT 1; + + RETURN vGeoFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/barcodeToItem.sql b/db/routines/vn/functions/barcodeToItem.sql new file mode 100644 index 000000000..ee0315118 --- /dev/null +++ b/db/routines/vn/functions/barcodeToItem.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`barcodeToItem`(vBarcode VARCHAR(22)) + RETURNS int(11) + DETERMINISTIC +BEGIN + +/** + * Obtiene el id del artículo + * + * @param vBarcode código de barras + * + * return id del item + */ + + DECLARE vItemFk INT; + + SELECT id INTO vItemFk + FROM vn.item + WHERE id = vBarcode OR comment = vBarcode + LIMIT 1; + + IF vItemFk THEN + RETURN vItemFk; + END IF; + + SELECT itemFk INTO vItemFk + FROM buy + WHERE id = vBarcode; + + IF vItemFk THEN + RETURN vItemFk; + END IF; + + SELECT itemFk INTO vItemFk + FROM itemBarcode + WHERE code = vBarcode; + + IF vItemFk THEN + RETURN vItemFk; + END IF; + + SELECT i.id INTO vItemFk + FROM vn.item i + WHERE i.name LIKE CONCAT('%',vBarcode,'%') + ORDER BY i.id ASC + LIMIT 1; + + RETURN vItemFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/buy_getUnitVolume.sql b/db/routines/vn/functions/buy_getUnitVolume.sql new file mode 100644 index 000000000..baf300450 --- /dev/null +++ b/db/routines/vn/functions/buy_getUnitVolume.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`buy_getUnitVolume`(vSelf INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Calculates the unit volume occupied by a buy. + * + * @param vSelf The buy id + * @return The unit volume in cubic centimeters + */ + DECLARE vItem INT; + DECLARE vPackaging VARCHAR(10); + DECLARE vPacking INT; + + SELECT itemFk, packagingFk, packing + INTO vItem, vPackaging, vPacking + FROM buy + WHERE id = vSelf; + + RETURN IFNULL(ROUND(item_getVolume(vItem, vPackaging) / vPacking), 0); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/buy_getVolume.sql b/db/routines/vn/functions/buy_getVolume.sql new file mode 100644 index 000000000..c29c0a57c --- /dev/null +++ b/db/routines/vn/functions/buy_getVolume.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`buy_getVolume`(vSelf INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Calculates the volume occupied by a buy. + * + * @param vSelf The buy id + * @return The volume in cubic centimeters + */ + DECLARE vItem INT; + DECLARE vPackaging VARCHAR(10); + + SELECT itemFk, packagingFk INTO vItem, vPackaging + FROM buy + WHERE id = vSelf; + + RETURN item_getVolume(vItem, vPackaging); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/catalog_componentReverse.sql b/db/routines/vn/functions/catalog_componentReverse.sql new file mode 100644 index 000000000..f37b20890 --- /dev/null +++ b/db/routines/vn/functions/catalog_componentReverse.sql @@ -0,0 +1,95 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`catalog_componentReverse`(vWarehouse INT, + vCost DECIMAL(10,3), + vM3 DECIMAL(10,3), + vAddressFk INT, + vZoneFk INT) + RETURNS decimal(10,3) + DETERMINISTIC +BEGIN + /* Calcula los componentes para un cliente a partir de un coste y volumen + * @param vWarehouse + * @param vCost Valor de coste del articulo + * @param vM3 m3 del articulo + * @param vAddressFk + * @param vZoneFk + * @return vRetailedPrice precio de venta sin iva + * @return tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) + */ + + DECLARE vBoxVolume BIGINT; + DECLARE vCustomer INT; + DECLARE vComponentRecovery INT DEFAULT 17; + DECLARE vComponentMana INT DEFAULT 39; + DECLARE vDeliveryComponent INT DEFAULT 15; + DECLARE vComponentMargin INT DEFAULT 29; + DECLARE vComponentCost INT DEFAULT 28; + DECLARE vRetailedPrice DECIMAL(10,2); + DECLARE vItem INT DEFAULT 98; + + SELECT volume INTO vBoxVolume + FROM vn.packaging + WHERE id = '94'; + + SELECT clientFk INTO vCustomer FROM address WHERE id = vAddressFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.catalog_component; + CREATE TEMPORARY TABLE tmp.catalog_component ( + `warehouseFk` INT UNSIGNED NOT NULL, + `itemFk` INT NOT NULL, + `componentFk` INT UNSIGNED NOT NULL, + `cost` DECIMAL(10,4) NOT NULL, + INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), + UNIQUE INDEX `itemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC)); + + -- Cost + INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) + SELECT vWarehouse, vItem, vComponentCost, vCost + FROM vn.rate + WHERE dated <= util.VN_CURDATE() + AND warehouseFk = vWarehouse + ORDER BY dated DESC + LIMIT 1; + + -- Margen + -- No se aplica margen, cau 12589 +/* INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) + SELECT vWarehouse, vItem, vComponentMargin, (vCost / ((100 - rate2) / 100)) - vCost + FROM vn.rate + WHERE dated <= util.VN_CURDATE() + AND warehouseFk = vWarehouse + ORDER BY dated DESC + LIMIT 1; + */ + -- Recobro + INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) + SELECT vWarehouse, vItem, vComponentRecovery, ROUND(LEAST(recobro,0.25), 3) + FROM bi.claims_ratio + WHERE Id_Cliente = vCustomer AND recobro > 0.009; + + -- Componente de maná automático, en función del maná acumulado por el comercial. + INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) + SELECT vWarehouse, vItem, vComponentMana, ROUND(wm.pricesModifierRate, 3) + FROM client c + JOIN vn.workerMana wm ON c.salesPersonFk = wm.workerFk + WHERE wm.isPricesModifierActivated AND c.id = vCustomer LIMIT 1; + + -- Reparto + INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) + SELECT vWarehouse, vItem, vDeliveryComponent, + ROUND( + vM3 + * (z.price - z.bonus) + * z.inflation + / vBoxVolume, 4 + ) + FROM zone z + WHERE z.id = vZoneFk; + + -- Precio de venta + SELECT SUM(cost) INTO vRetailedPrice + FROM tmp.catalog_component; + + RETURN vRetailedPrice; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/clientGetMana.sql b/db/routines/vn/functions/clientGetMana.sql new file mode 100644 index 000000000..fa983c2b2 --- /dev/null +++ b/db/routines/vn/functions/clientGetMana.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`clientGetMana`(vClient INT) + RETURNS decimal(10,2) + DETERMINISTIC +BEGIN +/** + * Devuelve el mana del cliente. + * + * @param vClient Id del cliente + * @return Mana del cliente + */ + DECLARE vMana DECIMAL(10,2); + + CREATE OR REPLACE TEMPORARY TABLE tmp.client + SELECT vClient id; + + CALL client_getMana(); + + SET vMana = (SELECT mana + FROM tmp.clientMana); + + DROP TEMPORARY TABLE + tmp.client, + tmp.clientMana; + + RETURN IFNULL(vMana,0); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/clientGetSalesPerson.sql b/db/routines/vn/functions/clientGetSalesPerson.sql new file mode 100644 index 000000000..4b8601be3 --- /dev/null +++ b/db/routines/vn/functions/clientGetSalesPerson.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`clientGetSalesPerson`(vClientFk INT, vDated DATE) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * DEPRECATED: use client_getSalesPerson + **/ + RETURN client_getSalesPerson(vClientFk, vDated); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/clientTaxArea.sql b/db/routines/vn/functions/clientTaxArea.sql new file mode 100644 index 000000000..f03520b0b --- /dev/null +++ b/db/routines/vn/functions/clientTaxArea.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`clientTaxArea`(vClientId INT, vCompanyId INT) + RETURNS varchar(25) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** +* Devuelve el area de un cliente, +* intracomunitario, extracomunitario o nacional. +* +* @param vClient Id del cliente +* @param vCompanyFk Compañia desde la que se factura +* @return Código de area +*/ + DECLARE vTaxArea VARCHAR(25); + + SELECT addressTaxArea(defaultAddressFk, vCompanyId) + INTO vTaxArea + FROM client + WHERE id = vClientId; + + RETURN vTaxArea; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_getDebt.sql b/db/routines/vn/functions/client_getDebt.sql new file mode 100644 index 000000000..8c715d2db --- /dev/null +++ b/db/routines/vn/functions/client_getDebt.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_getDebt`(`vClient` INT, `vDate` DATE) + RETURNS decimal(10,2) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Returns the risk of a customer. + * + * @param vClient client id + * @param vDate date to check the risk + * @return Client risk + */ + DECLARE vDebt DECIMAL(10,2); + DECLARE vHasDebt BOOLEAN; + + SELECT COUNT(*) INTO vHasDebt + FROM `client` c + WHERE c.id = vClient AND c.typeFk = 'normal'; + + IF NOT vHasDebt THEN + RETURN 0; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt (clientFk INT); + INSERT INTO tmp.clientGetDebt SET clientFk = vClient; + + CALL vn.client_getDebt(vDate); + + SELECT risk INTO vDebt FROM tmp.risk; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.risk; + + RETURN vDebt; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_getFromPhone.sql b/db/routines/vn/functions/client_getFromPhone.sql new file mode 100644 index 000000000..c6ded691b --- /dev/null +++ b/db/routines/vn/functions/client_getFromPhone.sql @@ -0,0 +1,43 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_getFromPhone`(vPhone VARCHAR(255)) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Searchs a customer associated to the phone number. + * + * @param vPhone The phone number + * @return The client id or %NULL if not found + */ + DECLARE vClient INT DEFAULT NULL; + + -- SET vPhone = vPhone COLLATE 'utf8_unicode_ci'; + + DROP TEMPORARY TABLE IF EXISTS tClient; + CREATE TEMPORARY TABLE tClient + ENGINE = MEMORY + SELECT id clientFk + FROM `client` + WHERE phone = vPhone + OR mobile = vPhone + UNION + SELECT clientFk + FROM address + WHERE phone = vPhone + OR mobile = vPhone + UNION + SELECT clientFk + FROM vn.clientContact + WHERE phone = vPhone; + + SELECT t.clientFk INTO vClient + FROM tClient t + JOIN `client` c ON c.id = t.clientFk + WHERE c.isActive + LIMIT 1; + + DROP TEMPORARY TABLE tClient; + + RETURN vClient; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_getSalesPerson.sql b/db/routines/vn/functions/client_getSalesPerson.sql new file mode 100644 index 000000000..c53816f7f --- /dev/null +++ b/db/routines/vn/functions/client_getSalesPerson.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_getSalesPerson`(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 vSalesPersonFk INT DEFAULT NULL; + DECLARE vWorkerSubstituteFk INT DEFAULT NULL; + DECLARE vLoop BOOLEAN; + + -- Obtiene el comercial original y el de sharingclient + + SELECT c.salesPersonFk, s.workerFk + INTO vSalesPersonFk, vWorkerSubstituteFk + 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 vWorkerSubstituteFk IS NOT NULL + THEN + SET vSalesPersonFk = vWorkerSubstituteFk; + ELSEIF vSalesPersonFk IS NOT NULL + THEN + DROP TEMPORARY TABLE IF EXISTS tmp.stack; + CREATE TEMPORARY TABLE tmp.stack + (INDEX (substitute)) + ENGINE = MEMORY + SELECT vSalesPersonFk substitute; + + l: LOOP + SELECT workerSubstitute INTO vWorkerSubstituteFk + FROM sharingCart + WHERE util.VN_CURDATE() BETWEEN started AND ended + AND workerFk = vSalesPersonFk + ORDER BY id + LIMIT 1; + + IF vWorkerSubstituteFk IS NULL THEN + LEAVE l; + END IF; + + SELECT COUNT(*) > 0 INTO vLoop + FROM tmp.stack WHERE substitute = vWorkerSubstituteFk; + + IF vLoop THEN + LEAVE l; + END IF; + + INSERT INTO tmp.stack SET + substitute = vWorkerSubstituteFk; + + SET vSalesPersonFk = vWorkerSubstituteFk; + END LOOP; + + DROP TEMPORARY TABLE tmp.stack; + END IF; + + RETURN vSalesPersonFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_getSalesPersonByTicket.sql b/db/routines/vn/functions/client_getSalesPersonByTicket.sql new file mode 100644 index 000000000..640df11ce --- /dev/null +++ b/db/routines/vn/functions/client_getSalesPersonByTicket.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_getSalesPersonByTicket`(vTicketFk INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Dado un id ticket, devuelve su comercial. + * Para más información ir a client_getSalesPerson() + * + * @param vClientFk El id del cliente + * @param vDated Fecha a comprobar + * @return El id del comercial para la fecha dada + **/ + DECLARE vClientFk INT; + DECLARE vDated DATE; + + SELECT clientFk, shipped + INTO vClientFk, vDated + FROM ticket WHERE id = vTicketFk; + + RETURN client_getSalesPerson(vClientFk, vDated); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_getSalesPersonCode.sql b/db/routines/vn/functions/client_getSalesPersonCode.sql new file mode 100644 index 000000000..69b8424d8 --- /dev/null +++ b/db/routines/vn/functions/client_getSalesPersonCode.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_getSalesPersonCode`(vClientFk INT, vDated DATE) + RETURNS varchar(3) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN +/** + * Dado un id cliente y una fecha, devuelve su comercial. + * Para más información ir a client_getSalesPerson() + * + * @param vClientFk El id del cliente + * @param vDated Fecha a comprobar + * @return El código del comercial para la fecha dada + **/ + DECLARE vWorkerCode CHAR(3); + DECLARE vSalesPersonFk INT; + + SET vSalesPersonFk = client_getSalesPerson(vClientFk, vDated); + + SELECT code + INTO vWorkerCode + FROM worker + WHERE id = vSalesPersonFk; + + RETURN vWorkerCode; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_getSalesPersonCodeByTicket.sql b/db/routines/vn/functions/client_getSalesPersonCodeByTicket.sql new file mode 100644 index 000000000..3ec5a8e9d --- /dev/null +++ b/db/routines/vn/functions/client_getSalesPersonCodeByTicket.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_getSalesPersonCodeByTicket`(vTicketFk INT) + RETURNS varchar(3) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN +/** + * Dado un id ticket, devuelve su comercial. + * Para más información ir a client_getSalesPerson() + * + * @param vClientFk El id del cliente + * @param vDated Fecha a comprobar + * @return El código del comercial para la fecha dada + **/ + DECLARE vClientFk INT; + DECLARE vDated DATE; + + SELECT clientFk, shipped + INTO vClientFk, vDated + FROM ticket WHERE id = vTicketFk; + + RETURN client_getSalesPersonCode(vClientFk, vDated); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/client_hasDifferentCountries.sql b/db/routines/vn/functions/client_hasDifferentCountries.sql new file mode 100644 index 000000000..a90b774c7 --- /dev/null +++ b/db/routines/vn/functions/client_hasDifferentCountries.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`client_hasDifferentCountries`(vClientFk INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Return if client have address in different countries. + * + * @param vClientFk The id client + * @return BOOL + **/ + RETURN (SELECT COUNT(DISTINCT c.id) > 1 + FROM `address` a + JOIN province p ON p.id = a.provinceFk + JOIN country c ON c.id = p.countryFk + WHERE a.clientFk = vClientFk + AND a.isActive); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/collection_isPacked.sql b/db/routines/vn/functions/collection_isPacked.sql new file mode 100644 index 000000000..9f148273f --- /dev/null +++ b/db/routines/vn/functions/collection_isPacked.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`collection_isPacked`(vSelf INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Check if collection is packed. + * + * @param vSelf the collection to check + * @return true if the collection is packed + */ + DECLARE vTicketsWithoutExpeditions INT; + + SELECT (COUNT(*) > 0) INTO vTicketsWithoutExpeditions + FROM vn.ticketCollection tc + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vSelf + AND ISNULL(e.id); + + RETURN NOT vTicketsWithoutExpeditions; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/currency_getCommission.sql b/db/routines/vn/functions/currency_getCommission.sql new file mode 100644 index 000000000..b0a591c23 --- /dev/null +++ b/db/routines/vn/functions/currency_getCommission.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`currency_getCommission`(vSelf INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Devuelve el tipo de cambio en el dia de hoy dada el tipo de moneda + * + * @param vSelf id del tipo de moneda + * @return devuelve la comision + */ + DECLARE vCommission INT; + + SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission + FROM referenceCurrent r + WHERE r.currencyFk = vSelf + AND r.`dated` <= util.VN_CURDATE() + ORDER BY r.`dated` DESC + LIMIT 1; + + RETURN vCommission; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/currentRate.sql b/db/routines/vn/functions/currentRate.sql new file mode 100644 index 000000000..57870fca4 --- /dev/null +++ b/db/routines/vn/functions/currentRate.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`currentRate`(vCurrencyFk INT, vDated DATE) + RETURNS decimal(10,4) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE curRate DECIMAL(10,4); + + SELECT value INTO curRate + FROM referenceRate + WHERE dated <= vDated + AND currencyFk = vCurrencyFk + ORDER BY dated DESC + LIMIT 1; + +RETURN curRate; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/deviceProductionUser_accessGranted.sql b/db/routines/vn/functions/deviceProductionUser_accessGranted.sql new file mode 100644 index 000000000..a2d39a0ab --- /dev/null +++ b/db/routines/vn/functions/deviceProductionUser_accessGranted.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`deviceProductionUser_accessGranted`(vUserFK INT(10) , android_id VARCHAR(50)) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + /* + * Comprueba si el usuario puede entrar en la aplicacion de almacen con ese movil + * + * */ + + /*DECLARE vIsGranted BOOLEAN; + DECLARE vDeviceProductionFk INT(11) DEFAULT NULL; + + SELECT dp.id INTO vDeviceProductionFk + FROM vn.deviceProduction dp + WHERE dp.android_id = android_id; + + IF vDeviceProductionFk THEN + + SELECT COUNT(*) INTO vIsGranted + FROM vn.deviceProductionUser dpu + WHERE dpu.userFk = vUserFK + AND dpu.deviceProductionFk = vDeviceProductionFk; + + RETURN vIsGranted; + END IF;*/ + RETURN TRUE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/duaTax_getRate.sql b/db/routines/vn/functions/duaTax_getRate.sql new file mode 100644 index 000000000..a11015066 --- /dev/null +++ b/db/routines/vn/functions/duaTax_getRate.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`duaTax_getRate`(vDuaFk INT, vTaxClassFk INT) + RETURNS decimal(5,2) + DETERMINISTIC +BEGIN +/** + * Devuelve el rate para un Dua teniendo en cuenta la fecha de opreción del DUA + * + * @param vDuaFk Identificador de la tabla dua + * @param vTaxClassFk Identificador del IVA de la tabla invoiceInTaxBookingAccount + */ + RETURN ( + SELECT rate + FROM dua d + JOIN supplier s ON s.id = d.companyFk + JOIN invoiceInTaxBookingAccount iit ON iit.countryFk = s.countryFk + AND iit.taxClassFk = vTaxClassFk + AND iit.effectived <= IFNULL( d.operated, util.VN_CURDATE()) + WHERE d.id = vDuaFk + ORDER BY effectived DESC + LIMIT 1); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ekt_getEntry.sql b/db/routines/vn/functions/ekt_getEntry.sql new file mode 100644 index 000000000..c629098a6 --- /dev/null +++ b/db/routines/vn/functions/ekt_getEntry.sql @@ -0,0 +1,71 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ekt_getEntry`(vEktFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Devuelve el numero de entrada para el ekt + * + * @param vEktFk Identificador de edi.ekt + */ + DECLARE vTravelFk INT; + DECLARE vEntryFk INT DEFAULT 0; + DECLARE vEntryAssignFk INT; + + SELECT ea.id + INTO vEntryAssignFk + FROM edi.ekt e + JOIN vn.ektEntryAssign ea ON + IFNULL(ea.sub, e.sub) <=> e.sub AND + IFNULL(ea.kop, e.kop) <=> e.kop AND + IFNULL(ea.pro, e.pro) <=> e.pro AND + IFNULL(ea.auction, e.auction) <=> e.auction + WHERE e.id = vEktFk + ORDER BY + IF(ea.sub,1,0) * 1000 + + IF(ea.kop,1,0) * 100 + + IF(ea.pro,1,0) * 10 + + IF(ea.auction,1,0) DESC + LIMIT 1; + + SET vTravelFk = vn.ekt_getTravel(vEntryAssignFk, vEktFk); + + IF vTravelFk THEN + + SELECT MAX(e.id) + INTO vEntryFk + FROM vn.entry e + JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk + WHERE e.travelFk = vTravelFk + AND e.sub <=> ea.sub + AND e.kop <=> ea.kop + AND e.pro <=> ea.pro + AND e.auction <=> ea.auction + AND e.companyFk <=> ea.companyFk; + + IF vEntryFk IS NULL THEN + INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, reference, pro, auction) + SELECT vTravelFk, ea.supplierFk, ea.companyFk, cu.id, ea.kop, ea.sub, ea.ref, ea.pro, ea.auction + FROM vn.ektEntryAssign ea + JOIN vn.currency cu ON cu.code = 'EUR' + WHERE ea.id = vEntryAssignFk; + + SET vEntryFk = LAST_INSERT_ID(); + END IF; + + UPDATE vn.ektEntryAssign + SET entryFk = vEntryFk + WHERE id = vEntryAssignFk; + + ELSE + + SELECT ec.defaultEntry INTO vEntryFk + FROM vn.entryConfig ec; + + INSERT IGNORE INTO vn.entry(id) VALUES(vEntryFk); + END IF; + + RETURN vEntryFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ekt_getTravel.sql b/db/routines/vn/functions/ekt_getTravel.sql new file mode 100644 index 000000000..4cf7f5631 --- /dev/null +++ b/db/routines/vn/functions/ekt_getTravel.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ekt_getTravel`(vEntryAssignFk INT, vEktFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Devuelve un vn.travel.id + * + * @param vEntryAssignFk Identificador de vn.entryAssign + */ + DECLARE vTravelFk INT; + + IF vEntryAssignFk IS NOT NULL THEN + SELECT MAX(tr.id) INTO vTravelFk + FROM vn.travel tr + JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk + JOIN edi.ekt e ON e.id = vEktFk + WHERE ea.warehouseOutFk = tr.warehouseOutFk + AND ea.warehouseInFk = tr.warehouseInFk + AND ea.agencyModeFk = tr.agencyModeFk + AND tr.landed = e.fec; + + IF vTravelFk IS NULL THEN + + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) + SELECT e.fec, e.fec, ea.warehouseInFk, ea.warehouseOutFk, ea.agencyModeFk + FROM edi.ekt e + JOIN vn.ektEntryAssign ea ON ea.kop = e.kop + WHERE e.id = vEktFk + ORDER BY + IF(ea.sub,1,0) * 1000 + + IF(ea.kop,1,0) * 100 + + IF(ea.pro,1,0) * 10 + + IF(ea.auction,1,0) DESC + LIMIT 1; + + SET vTravelFk = LAST_INSERT_ID(); + + END IF; + END IF; + + RETURN vTravelFk; +END$$ +DELIMITER ; diff --git a/db/.archive/232401/.gitkeep b/db/routines/vn/functions/entry_count similarity index 100% rename from db/.archive/232401/.gitkeep rename to db/routines/vn/functions/entry_count diff --git a/db/routines/vn/functions/entry_getCommission.sql b/db/routines/vn/functions/entry_getCommission.sql new file mode 100644 index 000000000..62946407a --- /dev/null +++ b/db/routines/vn/functions/entry_getCommission.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`entry_getCommission`(vTravelFk INT, + vCurrencyFk INT, + vSupplierFk INT +) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vCommission INT; + DECLARE vCurrentCommission INT; + DECLARE vIsCurrencyUsd INT; + DECLARE vLastEntryFk INT; + + SELECT count(*) INTO vIsCurrencyUsd + FROM currency c + WHERE c.code = 'USD' AND id = vCurrencyFk; + + IF NOT vIsCurrencyUsd THEN + + SELECT e.id INTO vLastEntryFk + FROM vn.entry e + JOIN vn.travel tr ON tr.id = e.travelFk + WHERE e.supplierFk = vSupplierFk + ORDER BY tr.landed DESC + LIMIT 1; + + IF vLastEntryFk THEN + + SELECT commission INTO vCurrentCommission + FROM vn.entry + WHERE id = vLastEntryFk; + + ELSE + + SELECT commission INTO vCurrentCommission + FROM supplier s + WHERE s.id = vSupplierFk; + + END IF; + + RETURN vCurrentCommission; + + ELSE + + SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission + FROM travel t + LEFT JOIN referenceCurrent r ON r.currencyFk = vCurrencyFk AND r.`dated` <= t.shipped + WHERE t.id = vTravelFk + ORDER BY r.`dated` DESC + LIMIT 1; + + RETURN IFNULL(vCommission, 0); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/entry_getCurrency.sql b/db/routines/vn/functions/entry_getCurrency.sql new file mode 100644 index 000000000..4cfce19db --- /dev/null +++ b/db/routines/vn/functions/entry_getCurrency.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`entry_getCurrency`(vCurrency INT, + vSupplierFk INT +) + RETURNS int(11) + NOT DETERMINISTIC + 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 ; diff --git a/db/routines/vn/functions/entry_getForLogiflora.sql b/db/routines/vn/functions/entry_getForLogiflora.sql new file mode 100644 index 000000000..71f0b585c --- /dev/null +++ b/db/routines/vn/functions/entry_getForLogiflora.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`entry_getForLogiflora`(vLanded DATE, vWarehouseFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Devuelve una entrada para Logiflora. Si no existe la crea. + * + * @param vLanded Fecha de llegada al almacén + * @param vWarehouseFk Identificador de vn.warehouse + */ + + DECLARE vTravelFk INT; + DECLARE vEntryFk INT; + DECLARE previousEntryFk INT; + + SET vTravelFk = vn.travel_getForLogiflora(vLanded, vWarehouseFk); + + IF vLanded THEN + + SELECT IFNULL(MAX(id),0) INTO vEntryFk + FROM vn.entry + WHERE travelFk = vTravelFk + AND isRaid; + + IF NOT vEntryFk THEN + + INSERT INTO vn.entry(travelFk, supplierFk, commission, companyFk, currencyFk, isRaid) + SELECT vTravelFk, s.id, 4, c.id, cu.id, TRUE + FROM vn.supplier s + JOIN vn.company c ON c.code = 'VNL' + JOIN vn.currency cu ON cu.code = 'EUR' + WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; + + SELECT MAX(id) INTO vEntryFk + FROM vn.entry + WHERE travelFk = vTravelFk; + + END IF; + + END IF; + + SELECT entryFk INTO previousEntryFk + FROM edi.warehouseFloramondo wf + WHERE wf.warehouseFk = vWarehouseFk; + + IF IFNULL(previousEntryFk,0) != vEntryFk THEN + + UPDATE buy b + SET b.printedStickers = 0 + WHERE entryFk = previousEntryFk; + + DELETE FROM buy WHERE entryFk = previousEntryFk; + + DELETE FROM entry WHERE id = previousEntryFk; + + END IF; + + RETURN vEntryFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/entry_isIntrastat.sql b/db/routines/vn/functions/entry_isIntrastat.sql new file mode 100644 index 000000000..8d46b4a02 --- /dev/null +++ b/db/routines/vn/functions/entry_isIntrastat.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`entry_isIntrastat`(vSelf INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** +* Devuelve si el proveedor de la entrada es de la CEE +* +* @param vSelf Id de la entrada +* @return true si es de la CEE +*/ + DECLARE vIsUeeSupplier BOOLEAN; + DECLARE vIsUeeCompany BOOLEAN; + DECLARE vSupplierCountry INT; + DECLARE vCompanyCountry INT; + + SELECT IFNULL(a.isUeeMember, c.isUeeMember), c.id + INTO vIsUeeSupplier, vSupplierCountry + FROM entry e + JOIN supplier s ON s.id = e.supplierFk + JOIN country c ON c.id = s.countryFk + LEFT JOIN province p ON p.id = s.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + WHERE e.id = vSelf; + + SELECT IFNULL(a.isUeeMember, c.isUeeMember), c.id + INTO vIsUeeCompany, vCompanyCountry + FROM entry e + JOIN supplier s ON s.id = e.companyFk + JOIN country c ON c.id = s.countryFk + LEFT JOIN province p ON p.id = s.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + WHERE e.id = vSelf; + + + RETURN vIsUeeCompany AND vIsUeeSupplier AND (vSupplierCountry <> vCompanyCountry); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/entry_isInventoryOrPrevious.sql b/db/routines/vn/functions/entry_isInventoryOrPrevious.sql new file mode 100644 index 000000000..4acbf060d --- /dev/null +++ b/db/routines/vn/functions/entry_isInventoryOrPrevious.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`entry_isInventoryOrPrevious`(vSelf INT) + RETURNS int(11) + DETERMINISTIC +BEGIN + DECLARE vIsInventoryOrPrevious BOOL; + + SELECT ec.inventorySupplierFk = e.supplierFk OR t.landed < c.inventoried + INTO vIsInventoryOrPrevious + FROM entry e + JOIN travel t ON e.travelFk = t.id + JOIN entryConfig ec + JOIN config c + WHERE e.id = vSelf; + + RETURN vIsInventoryOrPrevious; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/expedition_checkRoute.sql b/db/routines/vn/functions/expedition_checkRoute.sql new file mode 100644 index 000000000..9b2929797 --- /dev/null +++ b/db/routines/vn/functions/expedition_checkRoute.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`expedition_checkRoute`(vPalletFk INT,vExpeditionFk INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** +* Comprueba si las expediciones del pallet son todas +* de la misma ruta. +* +* @param vExpeditionFk numero de expedition a comprobar +* @param vPalletFk numero de pallet +* @return vHasDistinctRoutes +*/ + DECLARE vRouteFk INT; + DECLARE vHasDistinctRoutes BOOL; + + SELECT t.routeFk INTO vRouteFk + FROM vn.expedition e + JOIN vn.ticket t ON e.ticketFk = t.id + WHERE e.id = vExpeditionFk; + + SELECT COUNT(*) > 0 INTO vHasDistinctRoutes + FROM vn.expeditionScan es + JOIN vn.expedition e ON es.expeditionFk = e.id + JOIN vn.ticket t ON e.ticketFk = t.id + WHERE es.palletFk = vPalletFk + AND t.routeFk <> vRouteFk; + + RETURN vHasDistinctRoutes; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/firstDayOfWeek.sql b/db/routines/vn/functions/firstDayOfWeek.sql new file mode 100644 index 000000000..25ab4480c --- /dev/null +++ b/db/routines/vn/functions/firstDayOfWeek.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`firstDayOfWeek`(vYear INT, vWeek INT) + RETURNS date + DETERMINISTIC +BEGIN +/** + * Returns the date of the first day of the week + * + * @param vYear The year + * @param vWeek The week number + * @return Date of the first day of the week + */ + DECLARE vDate DATE; + + SELECT dated INTO vDate + FROM `time` + WHERE `year` = vYear + AND `week` = vWeek + ORDER BY dated + LIMIT 1; + + RETURN vDate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getAlert3State.sql b/db/routines/vn/functions/getAlert3State.sql new file mode 100644 index 000000000..f3a7aae53 --- /dev/null +++ b/db/routines/vn/functions/getAlert3State.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getAlert3State`(vTicket INT) + RETURNS varchar(45) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vDeliveryType INTEGER DEFAULT 0; + DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; + DECLARE vCode VARCHAR(45); + + SELECT am.deliveryMethodFk + INTO vDeliveryType + FROM ticket t + JOIN agencyMode am ON am.id = t.agencyModeFk + WHERE t.id = vTicket; + + CASE vDeliveryType + WHEN 1 THEN -- AGENCIAS + SET vCode = 'DELIVERED'; + + WHEN 2 THEN -- REPARTO + SET vCode = 'ON_DELIVERY'; + + ELSE -- MERCADO, OTROS + SELECT MIN(t.warehouseFk <> w.id) INTO isWaitingForPickUp + FROM ticket t + LEFT JOIN warehouse w + ON w.pickUpagencyModeFk = t.agencyModeFk + WHERE t.id = vTicket; + + IF isWaitingForPickUp THEN + SET vCode = 'WAITING_FOR_PICKUP'; + ELSE + SET vCode = 'DELIVERED'; + END IF; + END CASE; + RETURN vCode; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getAlert3StateTest.sql b/db/routines/vn/functions/getAlert3StateTest.sql new file mode 100644 index 000000000..6a14d80d4 --- /dev/null +++ b/db/routines/vn/functions/getAlert3StateTest.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getAlert3StateTest`(vTicket INT) + RETURNS varchar(45) CHARSET latin1 COLLATE latin1_swedish_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vDeliveryType INTEGER DEFAULT 0; + DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; + DECLARE vCode VARCHAR(45); + + SELECT + a.Vista + INTO vDeliveryType + FROM vn2008.Tickets t + JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia + WHERE Id_Ticket = vTicket; + + CASE vDeliveryType + WHEN 1 THEN -- AGENCIAS + SET vCode = 'DELIVERED'; + + WHEN 2 THEN -- REPARTO + SET vCode = 'ON_DELIVERY'; + + ELSE -- MERCADO, OTROS + SELECT t.warehouse_id <> w.warehouse_id INTO isWaitingForPickUp + FROM vn2008.Tickets t + LEFT JOIN vn2008.warehouse_pickup w + ON w.agency_id = t.Id_Agencia AND w.warehouse_id = t.warehouse_id + WHERE t.Id_Ticket = vTicket; + + IF isWaitingForPickUp THEN + SET vCode = 'WAITING_FOR_PICKUP'; + ELSE + SET vCode = 'DELIVERED'; + END IF; + END CASE; + RETURN vCode; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getDueDate.sql b/db/routines/vn/functions/getDueDate.sql new file mode 100644 index 000000000..694117a52 --- /dev/null +++ b/db/routines/vn/functions/getDueDate.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getDueDate`(vDated DATE, vDayToPay INT) + RETURNS date + NOT DETERMINISTIC + NO SQL +BEGIN + DECLARE vDued DATE; + + IF vDayToPay = 0 THEN + RETURN vDated; + END IF; + + SET vDued = TIMESTAMPADD(DAY,vDayToPay MOD 30, LAST_DAY(TIMESTAMPADD(MONTH, vDayToPay DIV 30, vDated))); + + RETURN vDued; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getInventoryDate.sql b/db/routines/vn/functions/getInventoryDate.sql new file mode 100644 index 000000000..b67f1c384 --- /dev/null +++ b/db/routines/vn/functions/getInventoryDate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getInventoryDate`() + RETURNS date + DETERMINISTIC +BEGIN + RETURN (SELECT inventoried FROM config LIMIT 1); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getNewItemId.sql b/db/routines/vn/functions/getNewItemId.sql new file mode 100644 index 000000000..2cb9b275b --- /dev/null +++ b/db/routines/vn/functions/getNewItemId.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getNewItemId`() + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE newItemId INT; + + SELECT i1.id + 1 INTO newItemId + FROM item i1 + LEFT JOIN item i2 ON i1.id + 1 = i2.id + WHERE i2.id IS NULL + ORDER BY i1.id + LIMIT 1; + + RETURN newItemId; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getNextDueDate.sql b/db/routines/vn/functions/getNextDueDate.sql new file mode 100644 index 000000000..8e8691ec5 --- /dev/null +++ b/db/routines/vn/functions/getNextDueDate.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getNextDueDate`(vDated DATE, vGapDays INT, vPayDay INT) + RETURNS date + NOT DETERMINISTIC + NO SQL +BEGIN + + DECLARE vReturn DATE; + DECLARE vDuaDate DATE; + DECLARE vDuaDateDay INT; + + SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate; + + IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN + SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); + ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN + SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); + END IF; + + IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN + IF util.isLeapYear(YEAR(vDuaDate)) THEN + SET vPayDay = 29; + ELSE + SET vPayDay = 28; + END IF; + END IF; + + SELECT DAY(vDuaDate) INTO vDuaDateDay; + RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay))); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getShipmentHour.sql b/db/routines/vn/functions/getShipmentHour.sql new file mode 100644 index 000000000..9eca04ac4 --- /dev/null +++ b/db/routines/vn/functions/getShipmentHour.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getShipmentHour`(vTicket INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vShipmentHour INT; + + SELECT HOUR(shipped) INTO vShipmentHour + FROM ticket + WHERE id = vTicket; + + IF vShipmentHour = 0 + THEN + DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer; + CREATE TEMPORARY TABLE tmp.production_buffer + ENGINE = MEMORY + SELECT am.agencyFk as agency_id + , t.warehouseFk as warehouse_id + , a.provinceFk as province_id + , 0 as Hora + , 0 as Departure + FROM ticket t + JOIN agencyMode am on am.id = t.agencyModeFk + JOIN address a on a.id = t.addressFk + WHERE t.id = vTicket; + + SELECT Hora INTO vShipmentHour + FROM tmp.production_buffer; + END IF; + + RETURN vShipmentHour; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getSpecialPrice.sql b/db/routines/vn/functions/getSpecialPrice.sql new file mode 100644 index 000000000..f3b340cfe --- /dev/null +++ b/db/routines/vn/functions/getSpecialPrice.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getSpecialPrice`(vItemFk int(11),vClientFk int(11)) + RETURNS decimal(10,2) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE price DECIMAL(10,2); + + SELECT rate3 INTO price + FROM vn.priceFixed + WHERE itemFk = vItemFk + AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; + + SELECT `value` INTO price + FROM vn.specialPrice + WHERE itemFk = vItemFk + AND clientFk = vClientFk ; +RETURN price; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getTicketTrolleyLabelCount.sql b/db/routines/vn/functions/getTicketTrolleyLabelCount.sql new file mode 100644 index 000000000..b978db73a --- /dev/null +++ b/db/routines/vn/functions/getTicketTrolleyLabelCount.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getTicketTrolleyLabelCount`(vTicket INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vLabelCount INT DEFAULT 0; + + SELECT labelCount INTO vLabelCount + FROM ticketTrolley + WHERE ticket = vTicket; + + SET vLabelCount = vLabelCount +1 ; + + REPLACE ticketTrolley(ticket,labelCount) + SELECT vTicket, vLabelCount; + + RETURN vlabelCount; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getUser.sql b/db/routines/vn/functions/getUser.sql new file mode 100644 index 000000000..eb85b8346 --- /dev/null +++ b/db/routines/vn/functions/getUser.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getUser`() + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * @deprecated Use account.userGetId() + */ + RETURN account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/getUserId.sql b/db/routines/vn/functions/getUserId.sql new file mode 100644 index 000000000..9afcb8912 --- /dev/null +++ b/db/routines/vn/functions/getUserId.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`getUserId`(userName varchar(30)) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vUser INT; + + SELECT id INTO vUser + FROM account.user + WHERE `name` = userName; + + RETURN vUser; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/hasAnyNegativeBase.sql b/db/routines/vn/functions/hasAnyNegativeBase.sql new file mode 100644 index 000000000..3b96a3d22 --- /dev/null +++ b/db/routines/vn/functions/hasAnyNegativeBase.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyNegativeBase`() + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + +/* Calcula si existe alguna base imponible negativa +* Requiere la tabla temporal tmp.ticketToInvoice(id) +* +* returns BOOLEAN +*/ + DECLARE hasAnyNegativeBase BOOLEAN; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM tmp.ticketToInvoice; + + CALL ticket_getTax(NULL); + + SELECT COUNT(*) INTO hasAnyNegativeBase + FROM( + SELECT SUM(taxableBase) as taxableBase + FROM tmp.ticketTax + GROUP BY pgcFk + HAVING taxableBase < 0 + ) t; + + DROP TEMPORARY TABLE tmp.ticketTax; + DROP TEMPORARY TABLE tmp.ticket; + + RETURN hasAnyNegativeBase; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/hasItemsInSector.sql b/db/routines/vn/functions/hasItemsInSector.sql new file mode 100644 index 000000000..4aa4edb9c --- /dev/null +++ b/db/routines/vn/functions/hasItemsInSector.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasItemsInSector`(vTicketFk INT, vSectorFk INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + DECLARE vItemCount INT; + + SELECT count(*) INTO vItemCount + FROM vn.sale s + JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + WHERE s.ticketFk = vTicketFk + AND p.sectorFk = vSectorFk; + + RETURN vItemCount; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/hasSomeNegativeBase.sql b/db/routines/vn/functions/hasSomeNegativeBase.sql new file mode 100644 index 000000000..ea7efe777 --- /dev/null +++ b/db/routines/vn/functions/hasSomeNegativeBase.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasSomeNegativeBase`(vTicket INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vCountry INT; + DECLARE hasSomeNegativeBase BOOLEAN; + + SELECT s.countryFk + INTO vCountry + FROM supplier s + JOIN ticket t ON t.companyFk = s.id + WHERE t.id = vTicket; + + SELECT COUNT(*) INTO hasSomeNegativeBase + FROM ( + SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemTaxCountry itc + ON itc.itemFk = i.id AND itc.countryFk = vCountry + WHERE s.ticketFk = vTicket + GROUP BY itc.taxClassFk + HAVING taxableBase < 0 + ) t1 ; + + RETURN hasSomeNegativeBase; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/invoiceOutAmount.sql b/db/routines/vn/functions/invoiceOutAmount.sql new file mode 100644 index 000000000..6c66a46f3 --- /dev/null +++ b/db/routines/vn/functions/invoiceOutAmount.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOutAmount`(vInvoiceRef VARCHAR(15)) + RETURNS decimal(10,2) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE totalAmount DECIMAL(10,2); + + SELECT SUM(vat) INTO totalAmount + FROM ( + SELECT iot.vat + FROM invoiceOutTax iot + JOIN invoiceOut io ON io.id = iot.invoiceOutFk + WHERE io.ref = vInvoiceRef + UNION ALL + SELECT ioe.amount + FROM invoiceOutExpense ioe + JOIN invoiceOut io ON io.id = ioe.invoiceOutFk + WHERE io.ref = vInvoiceRef + ) t1; + + RETURN totalAmount; +END$$ +DELIMITER ; diff --git a/db/.archive/231001/01-invoiceOut_getMaxIssued.sql b/db/routines/vn/functions/invoiceOut_getMaxIssued.sql similarity index 83% rename from db/.archive/231001/01-invoiceOut_getMaxIssued.sql rename to db/routines/vn/functions/invoiceOut_getMaxIssued.sql index e120b949d..dc1a59eaa 100644 --- a/db/.archive/231001/01-invoiceOut_getMaxIssued.sql +++ b/db/routines/vn/functions/invoiceOut_getMaxIssued.sql @@ -1,13 +1,11 @@ -DROP FUNCTION IF EXISTS `vn`.`invoiceOut_getMaxIssued`; - DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getMaxIssued`( - vSerial VARCHAR(2), +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getMaxIssued`(vSerial VARCHAR(2), vCompanyFk INT, vYear INT -) RETURNS DATE - READS SQL DATA +) + RETURNS date + NOT DETERMINISTIC + READS SQL DATA BEGIN /** * Retorna la fecha a partir de la cual es válido emitir una factura @@ -31,4 +29,4 @@ BEGIN RETURN vInvoiceOutIssued; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/functions/invoiceOut_getPath.sql b/db/routines/vn/functions/invoiceOut_getPath.sql new file mode 100644 index 000000000..1e174a4cf --- /dev/null +++ b/db/routines/vn/functions/invoiceOut_getPath.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getPath`(vSelf INT) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN + DECLARE vIssued DATE; + DECLARE vSerial VARCHAR(15); + + SELECT issued, ref + INTO vIssued, vSerial + FROM invoiceOut WHERE id = vSelf; + + RETURN CONCAT_WS('/' + ,'invoice' + ,YEAR(vIssued) + ,MONTH(vIssued) + ,DAY(vIssued) + ,CONCAT(YEAR(vIssued), vSerial, '.pdf') + ); +END$$ +DELIMITER ; diff --git a/db/.archive/231001/00-invoiceOut_getWeight.sql b/db/routines/vn/functions/invoiceOut_getWeight.sql similarity index 75% rename from db/.archive/231001/00-invoiceOut_getWeight.sql rename to db/routines/vn/functions/invoiceOut_getWeight.sql index 3f34b6fb7..1302c0341 100644 --- a/db/.archive/231001/00-invoiceOut_getWeight.sql +++ b/db/routines/vn/functions/invoiceOut_getWeight.sql @@ -1,11 +1,9 @@ -DROP FUNCTION IF EXISTS `vn`.`invoiceOut_getWeight`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getWeight`( - vInvoiceRef VARCHAR(15) -)RETURNS decimal(10,2) - READS SQL DATA +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getWeight`(vInvoiceRef VARCHAR(15) +) + RETURNS decimal(10,2) + NOT DETERMINISTIC + READS SQL DATA BEGIN /** * Calcula el peso de una factura emitida diff --git a/db/routines/vn/functions/invoiceSerial.sql b/db/routines/vn/functions/invoiceSerial.sql new file mode 100644 index 000000000..66448ac9c --- /dev/null +++ b/db/routines/vn/functions/invoiceSerial.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(1)) + RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN + /** + * Obtiene la serie de de una factura + * dependiendo del area del cliente. + * + * @param vClientFk Id del cliente + * @param vCompanyFk Id de la empresa + * @param vType Tipo de factura ["R", "M", "G"] + * @return Serie de la factura + */ + DECLARE vTaxArea VARCHAR(25); + DECLARE vSerie CHAR(1); + + IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN + RETURN 'S'; + END IF; + + SELECT clientTaxArea(vClientFk, vCompanyFk) INTO vTaxArea; + SELECT invoiceSerialArea(vType,vTaxArea) INTO vSerie; + RETURN vSerie; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/invoiceSerialArea.sql b/db/routines/vn/functions/invoiceSerialArea.sql new file mode 100644 index 000000000..02edd83f2 --- /dev/null +++ b/db/routines/vn/functions/invoiceSerialArea.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerialArea`(vType CHAR(1), vTaxArea VARCHAR(25)) + RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + DECLARE vSerie CHAR(1); + + IF vType = 'R' THEN + SELECT + CASE vTaxArea + WHEN 'CEE' THEN 'H' + WHEN 'WORLD' THEN 'E' + ELSE 'T' + END INTO vSerie; + -- Factura multiple + ELSEIF vType = 'M' THEN + SELECT + CASE vTaxArea + WHEN 'CEE' THEN 'H' + WHEN 'WORLD' THEN 'E' + ELSE 'M' + END INTO vSerie; + -- Factura global + ELSEIF vType = 'G' THEN + SELECT + CASE vTaxArea + WHEN 'CEE' THEN 'V' + WHEN 'WORLD' THEN 'X' + ELSE 'A' + END INTO vSerie; + END IF; + RETURN vSerie; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/isLogifloraDay.sql b/db/routines/vn/functions/isLogifloraDay.sql new file mode 100644 index 000000000..8e9c9b264 --- /dev/null +++ b/db/routines/vn/functions/isLogifloraDay.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`isLogifloraDay`(vShipped DATE, vWarehouse INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + DECLARE vIsLogifloraDay BOOLEAN; + + SELECT COUNT(*) INTO vIsLogifloraDay + FROM edi.warehouseFloramondo wf + JOIN vn.floramondoConfig fc + WHERE wf.warehouseFk = vWarehouse + AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded)) + AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded)); + + RETURN vIsLogifloraDay; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/isPalletHomogeneus.sql b/db/routines/vn/functions/isPalletHomogeneus.sql new file mode 100644 index 000000000..39c6461ae --- /dev/null +++ b/db/routines/vn/functions/isPalletHomogeneus.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`isPalletHomogeneus`(vExpedition INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vScanId INT; + DECLARE vDistinctRoutesInThePallet INT; + + SELECT scan_id INTO vScanId + FROM vn2008.scan_line + WHERE code = vExpedition + LIMIT 1; + + SELECT COUNT(*) INTO vDistinctRoutesInThePallet + FROM ( + SELECT DISTINCT t.Id_Ruta + FROM vn2008.scan_line sl + JOIN vn2008.expeditions e ON e.expeditions_id = sl.code + JOIN vn2008.Tickets t ON t.Id_Ticket = e.ticket_id + WHERE sl.scan_id = vScanId + AND t.Id_Ruta + ) t1; + + RETURN vDistinctRoutesInThePallet = 1; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/itemPacking.sql b/db/routines/vn/functions/itemPacking.sql new file mode 100644 index 000000000..6856c12cd --- /dev/null +++ b/db/routines/vn/functions/itemPacking.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`itemPacking`(vBarcode VARCHAR(22), vWarehouseFk INT) + RETURNS int(11) + DETERMINISTIC +BEGIN + + DECLARE vPacking INTEGER DEFAULT 0; + DECLARE vItemFk INTEGER; + + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; + + SELECT IFNULL(packing,0) INTO vPacking + FROM vn.buy + WHERE id = CAST(vBarcode AS DECIMAL(18,0)); + + + + + IF NOT vPacking THEN + CALL cache.last_buy_refresh(FALSE); + SELECT IFNULL(packing,1) INTO vPacking + FROM + (SELECT packing , created + FROM vn.itemShelving + WHERE itemFk = vItemFk + UNION ALL + SELECT b.packing, landing + FROM vn.buy b + JOIN cache.last_buy lb ON lb.buy_id = b.id + WHERE lb.warehouse_id = vWarehouseFk + AND b.itemFk = vItemFk + ) packings + ORDER BY created desc + LIMIT 1; + + END IF; + + RETURN vPacking; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/itemShelvingPlacementSupply_ClosestGet.sql b/db/routines/vn/functions/itemShelvingPlacementSupply_ClosestGet.sql new file mode 100644 index 000000000..6b5fc3ae3 --- /dev/null +++ b/db/routines/vn/functions/itemShelvingPlacementSupply_ClosestGet.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`itemShelvingPlacementSupply_ClosestGet`(vParkingFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /* Devuelve el parking más cercano.*/ + DECLARE vColumn INT; + DECLARE vClosestParkingFk INT; + DECLARE vSectorFk INT; + + SELECT p.column, sectorFk INTO vColumn, vSectorFk + FROM vn.parking p + WHERE p.id = vParkingFk; + + SELECT itemShelvingFk INTO vClosestParkingFk + FROM + ( + SELECT ABS(p.column - vColumn) as distance, itemShelvingFk + FROM vn.itemShelvingPlacementSupplyStock ispss + JOIN vn.parking p ON p.id = ispss.parkingFk + JOIN vn.itemPlacementSupplyList ipsl ON ipsl.sectorFk = ispss.sectorFk AND ipsl.itemFk = ispss.itemFk + WHERE p.sectorFk = vSectorFk + AND ipsl.saldo > 0 + ) sub + ORDER BY distance + LIMIT 1; + + RETURN vClosestParkingFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/itemTag_getIntValue.sql b/db/routines/vn/functions/itemTag_getIntValue.sql new file mode 100644 index 000000000..fa5a03552 --- /dev/null +++ b/db/routines/vn/functions/itemTag_getIntValue.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`itemTag_getIntValue`(vValue VARCHAR(255)) + RETURNS int(11) + DETERMINISTIC +BEGIN + IF vValue NOT REGEXP '^-?[0-9]+' THEN + RETURN NULL; + END IF; + + RETURN CAST(vValue AS SIGNED); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/item_getFhImage.sql b/db/routines/vn/functions/item_getFhImage.sql new file mode 100644 index 000000000..13e02e8fe --- /dev/null +++ b/db/routines/vn/functions/item_getFhImage.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`item_getFhImage`(itemFk INT) + RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + DECLARE vImageUrl VARCHAR(255); + SELECT sr.PictureReference INTO vImageUrl + FROM vn.buy b + JOIN edi.ekt e ON b.ektFk = e.id + JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref` + JOIN vn.item i ON i.id = b.itemFk + WHERE b.itemFk = itemFk + ORDER BY (sr.EmbalageCode = e.package) DESC + LIMIT 1; + RETURN vImageUrl; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/item_getPackage.sql b/db/routines/vn/functions/item_getPackage.sql new file mode 100644 index 000000000..894abe4cf --- /dev/null +++ b/db/routines/vn/functions/item_getPackage.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`item_getPackage`(vItemFk INT) + RETURNS varchar(50) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + + DECLARE vDiameter INT; + DECLARE vPackageFk VARCHAR(50); + DECLARE vCoeficient DOUBLE DEFAULT 1.08; + + SELECT MAX(LEFT(value,3)) INTO vDiameter + FROM vn.itemTag it + JOIN vn.tag t ON t.id = it.tagFk + WHERE it.itemFk = vItemFk + AND t.overwrite = 'diameter'; + + SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2))) + INTO vPackageFk + FROM vn.volumeConfig vc; + + INSERT IGNORE INTO vn.packaging(id, width, `depth`) + SELECT vPackageFk, + FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), + FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter)) + FROM vn.volumeConfig vc; + + RETURN vPackageFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/item_getVolume.sql b/db/routines/vn/functions/item_getVolume.sql new file mode 100644 index 000000000..afcb32c93 --- /dev/null +++ b/db/routines/vn/functions/item_getVolume.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`item_getVolume`(vSelf INT, vPackaging VARCHAR(10)) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Calculates the volume occupied by an item together + * with its packaging. + * + * @param vSelf The item id + * @param vPackaging The packaging id + * @return The volume in cubic centimeters + */ + DECLARE vVolume INT; + + SELECT SUM(IF(p.volume > 0, + p.volume, + p.width * p.depth * IF(IFNULL(p.height,0), p.height, IFNULL(i.size,60) + 10) + )) INTO vVolume + FROM packaging p + JOIN item i ON i.id = vSelf + WHERE p.id = vPackaging; + + RETURN vVolume; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/itemsInSector_get.sql b/db/routines/vn/functions/itemsInSector_get.sql new file mode 100644 index 000000000..9054087b3 --- /dev/null +++ b/db/routines/vn/functions/itemsInSector_get.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`itemsInSector_get`(vTicketFk INT, vSectorFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vItemCount INT; + + SELECT count(*) INTO vItemCount + FROM vn.sale s + JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + WHERE s.ticketFk = vTicketFk + AND p.sectorFk = vSectorFk; + + RETURN vItemCount; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/lastDayOfWeek.sql b/db/routines/vn/functions/lastDayOfWeek.sql new file mode 100644 index 000000000..464bf5afe --- /dev/null +++ b/db/routines/vn/functions/lastDayOfWeek.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`lastDayOfWeek`(vYear INT, vWeek INT) + RETURNS date + DETERMINISTIC +BEGIN +/** + * Returns the date of the last day of the week + * + * @param vYear The year + * @param vWeek The week number + * @return Date of the first day of the week + */ + DECLARE vDate DATE; + + SELECT dated INTO vDate + FROM `time` + WHERE `year` = vYear + AND `week` = vWeek + ORDER BY dated DESC + LIMIT 1; + + RETURN vDate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/machine_checkPlate.sql b/db/routines/vn/functions/machine_checkPlate.sql new file mode 100644 index 000000000..d08ed97c5 --- /dev/null +++ b/db/routines/vn/functions/machine_checkPlate.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`machine_checkPlate`(vPlate VARCHAR(10)) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Comprueba si existe matrícula + * + * @param vPlate matrícula del vehículo + * @return Devuelve TRUE en caso de que exista + * + */ + + IF (SELECT COUNT(*) + FROM machine m + WHERE m.plate = vPlate + ) THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/messageSend.sql b/db/routines/vn/functions/messageSend.sql new file mode 100644 index 000000000..8a95118e7 --- /dev/null +++ b/db/routines/vn/functions/messageSend.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`messageSend`(vRecipient VARCHAR(255) CHARSET utf8, vMessage TEXT CHARSET utf8) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE result INT; + DECLARE vSenderFk INT; + + SELECT id INTO vSenderFk + FROM account.user WHERE `name` = account.myUser_getName(); + + RETURN (SELECT messageSendWithUser(vSenderFk, vRecipient, vMessage)); +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/messageSendWithUser.sql b/db/routines/vn/functions/messageSendWithUser.sql new file mode 100644 index 000000000..1d5b730a8 --- /dev/null +++ b/db/routines/vn/functions/messageSendWithUser.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`messageSendWithUser`(vSenderFK INT, vRecipient VARCHAR(255) CHARSET utf8, vMessage TEXT CHARSET utf8) + RETURNS int(11) + DETERMINISTIC +BEGIN + + DECLARE vCount INT; + DECLARE vUuid VARCHAR(255); + DECLARE vSendDate DATETIME DEFAULT util.VN_NOW(); + DECLARE vSender VARCHAR(255) CHARSET utf8; + + SELECT `name` INTO vSender + FROM account.user WHERE id = vSenderFK; + + SET vRecipient = LOWER(vRecipient); + + DROP TEMPORARY TABLE IF EXISTS tRecipients; + CREATE TEMPORARY TABLE tRecipients + SELECT u.name finalRecipient + FROM account.mailAlias a + JOIN account.mailAliasAccount aa ON aa.mailAlias = a.id + JOIN account.user u ON u.id = aa.account + WHERE a.alias = vRecipient COLLATE utf8_unicode_ci + AND u.name != vSender + AND u.active + UNION + SELECT u.name FROM account.user u + WHERE u.name = vRecipient + AND u.active; + + SELECT COUNT(*) INTO vCount FROM tRecipients; + + IF vCount = 0 THEN + RETURN vCount; + END IF; + + SET vUuid = UUID(); + + INSERT INTO message + SET uuid = vUuid, + sender = vSender, + recipient = vRecipient, + message = vMessage, + sendDate = vSendDate; + + INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate) + SELECT vUuid, vSender, vRecipient, finalRecipient, vMessage, vSendDate + FROM tRecipients; + + DROP TEMPORARY TABLE tRecipients; + RETURN vCount; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/nz.sql b/db/routines/vn/functions/nz.sql new file mode 100644 index 000000000..71c017b78 --- /dev/null +++ b/db/routines/vn/functions/nz.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`nz`(vQuantity DOUBLE) + RETURNS double + DETERMINISTIC +BEGIN + + DECLARE vResult DOUBLE; + + SET vResult = IFNULL(vQuantity,0); + + RETURN vResult; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/orderTotalVolume.sql b/db/routines/vn/functions/orderTotalVolume.sql new file mode 100644 index 000000000..962baa8ec --- /dev/null +++ b/db/routines/vn/functions/orderTotalVolume.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`orderTotalVolume`(vOrderId INT) + RETURNS decimal(10,3) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + -- Devuelte el volumen total de la orden sumada + DECLARE vWarehouseId INTEGER; + DECLARE vVolume DECIMAL(10,3); + + SELECT IFNULL(SUM(o.amount * ic.cm3delivery)/1000000,0) INTO vVolume + FROM hedera.orderRow o + JOIN item i ON i.id = o.itemFk + JOIN itemCost ic on ic.itemFk = o.itemFk AND ic.warehouseFk = o.warehouseFk + WHERE o.orderFk = vOrderId; + + RETURN vVolume; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/orderTotalVolumeBoxes.sql b/db/routines/vn/functions/orderTotalVolumeBoxes.sql new file mode 100644 index 000000000..cbc0e94ac --- /dev/null +++ b/db/routines/vn/functions/orderTotalVolumeBoxes.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`orderTotalVolumeBoxes`(vOrderId INT) + RETURNS decimal(10,3) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Devuelve el volumen estimado del ticket sumado, en cajas + * + * @param vOrder Id del pedido + */ + DECLARE vVolumeBoxM3 DOUBLE; + DECLARE vOrderTotalVolumeBoxes DECIMAL(10,1); + DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; + + SELECT volume / 1000000 + INTO vVolumeBoxM3 + FROM packaging + WHERE id = vVnBoxId; + + SET vOrderTotalVolumeBoxes = orderTotalVolume(vOrderId) / vVolumeBoxM3; + + RETURN vOrderTotalVolumeBoxes; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/packaging_calculate.sql b/db/routines/vn/functions/packaging_calculate.sql new file mode 100644 index 000000000..c9aaf07b9 --- /dev/null +++ b/db/routines/vn/functions/packaging_calculate.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`packaging_calculate`(isPackageReturnable TINYINT(1), + packagingReturnFk INT(11), + base DECIMAL(10,2), + price DECIMAL(10,2), + upload VARCHAR(255)) + RETURNS decimal(10,2) + DETERMINISTIC +BEGIN + DECLARE vAmount INT DEFAULT NULL; + DECLARE vValue DECIMAL(10,2); + + IF isPackageReturnable THEN + SELECT cb.freightPackagingFull INTO vAmount + FROM returnBuckets cb + WHERE cb.id = packagingReturnFk; + + SET vValue = IF (vAmount IS NULL, + IFNULL(base,0), + vAmount / IFNULL(upload, 0) + IFNULL(base, 0)); + ELSE + SET vValue = IFNULL(price, 0) + IFNULL(base, 0); + END IF; + + RETURN vValue; +END$$ +DELIMITER ; diff --git a/db/.archive/230201/00-priceFixed_getRate2.sql b/db/routines/vn/functions/priceFixed_getRate2.sql similarity index 69% rename from db/.archive/230201/00-priceFixed_getRate2.sql rename to db/routines/vn/functions/priceFixed_getRate2.sql index cf36efb57..d97a20e59 100644 --- a/db/.archive/230201/00-priceFixed_getRate2.sql +++ b/db/routines/vn/functions/priceFixed_getRate2.sql @@ -1,9 +1,7 @@ -DROP FUNCTION IF EXISTS `vn`.`priceFixed_getRate2`; - DELIMITER $$ -$$ -CREATE FUNCTION `vn`.`priceFixed_getRate2`(vFixedPriceFk INT, vRate3 DOUBLE) -RETURNS DOUBLE +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`priceFixed_getRate2`(vFixedPriceFk INT, vRate3 DOUBLE) + RETURNS double + NOT DETERMINISTIC BEGIN DECLARE vWarehouse INT; diff --git a/db/routines/vn/functions/routeProposal.sql b/db/routines/vn/functions/routeProposal.sql new file mode 100644 index 000000000..81b5d9048 --- /dev/null +++ b/db/routines/vn/functions/routeProposal.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`routeProposal`(vTicketFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vRouteFk INT; + DECLARE vAddressFk INT; + + DECLARE vLanded DATE; + DECLARE vZoneFk INT; + DECLARE vSignificativeFriendship INT DEFAULT 6; + DECLARE vVolumeMax DECIMAL(5,1) DEFAULT 10; + + SELECT addressFk, zoneFk, landed INTO vAddressFk, vZoneFk, vLanded + FROM vn.ticket + WHERE id = vTicketFk; + + -- Se inicia la selección de rutas posibles con aquellas cuyas agencias alguna vez han estado asociadas con nuestra zona + DROP TEMPORARY TABLE IF EXISTS tmp.route; + CREATE TEMPORARY TABLE tmp.route + SELECT r.id routeFk, + zf.friendship zoneFriendship + FROM vn.route r + JOIN cache.zoneAgencyFriendship zf ON zf.agencyModeFk = r.agencyModeFk + WHERE friendship >= vSignificativeFriendship + AND zf.zoneFk = vZoneFk + AND r.created = vLanded + ORDER BY friendship; + + -- Se eliminan aquellas que superan el volumen máximo + DELETE r.* + FROM tmp.route r + JOIN (SELECT routeFk, sum(volume) volume + FROM vn.saleVolume + WHERE landed = vLanded + GROUP BY routeFk) sub ON sub.routeFk = r.routeFk + WHERE sub.volume > vVolumeMax; + + -- Se ordenan las que quedan en función con la afinidad del resto de consignatarios de cada ruta + SELECT routeFk INTO vRouteFk + FROM + (SELECT r.routeFk, r.zoneFriendship, sum(af.friendship) friendshipSum + FROM tmp.route r + LEFT JOIN vn.ticket t ON t.routeFk = r.routeFk + LEFT JOIN cache.addressFriendship af ON af.addressFk2 = t.addressFk AND af.addressFk1 = vAddressFk + GROUP BY routeFk + ORDER BY zoneFriendship DESC, friendshipSum DESC + ) sub + LIMIT 1; + + RETURN vRouteFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/routeProposal_.sql b/db/routines/vn/functions/routeProposal_.sql new file mode 100644 index 000000000..b4559c10c --- /dev/null +++ b/db/routines/vn/functions/routeProposal_.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`routeProposal_`(vTicketFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vRouteFk INT; + DECLARE vAddressFk INT; + DECLARE vShipped DATETIME; + + SELECT addressFk, date(shipped) INTO vAddressFk, vShipped + FROM vn.ticket + WHERE id = vTicketFk; + + SELECT routeFk INTO vRouteFk + FROM + (SELECT t.routeFk, sum(af.friendship) friendshipSum + FROM vn.ticket t + JOIN cache.addressFriendship af ON af.addressFk2 = t.addressFk AND af.addressFk1 = vAddressFk + WHERE t.shipped BETWEEN vShipped and MIDNIGHT(vShipped) + AND t.routeFk + GROUP BY routeFk + ORDER BY friendshipSum DESC + ) sub + LIMIT 1; + + RETURN vRouteFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/routeProposal_beta.sql b/db/routines/vn/functions/routeProposal_beta.sql new file mode 100644 index 000000000..4ec17d3ed --- /dev/null +++ b/db/routines/vn/functions/routeProposal_beta.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`routeProposal_beta`(vTicketFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vRouteFk INT; + DECLARE vAddressFk INT; + + DECLARE vLanded DATE; + DECLARE vZoneFk INT; + DECLARE vSignificativeFriendship INT DEFAULT 6; + DECLARE vVolumeMax DECIMAL(5,1) DEFAULT 10; + + SELECT addressFk, zoneFk, landed INTO vAddressFk, vZoneFk, vLanded + FROM vn.ticket + WHERE id = vTicketFk; + + -- Se inicia la selección de rutas posibles con aquellas cuyas agencias alguna vez han estado asociadas con nuestra zona + DROP TEMPORARY TABLE IF EXISTS tmp.route; + CREATE TEMPORARY TABLE tmp.route + SELECT r.id routeFk, + zf.friendship zoneFriendship + FROM vn.route r + JOIN cache.zoneAgencyFriendship zf ON zf.agencyModeFk = r.agencyModeFk + WHERE friendship >= vSignificativeFriendship + AND zf.zoneFk = vZoneFk + AND r.created = vLanded + ORDER BY friendship; + + -- Se eliminan aquellas que superan el volumen máximo + DELETE r.* + FROM tmp.route r + JOIN (SELECT routeFk, sum(volume) volume + FROM vn.saleVolume + WHERE landed = vLanded + GROUP BY routeFk) sub ON sub.routeFk = r.routeFk + WHERE sub.volume > vVolumeMax; + + -- Se ordenan las que quedan en función con la afinidad del resto de consignatarios de cada ruta + SELECT routeFk INTO vRouteFk + FROM + (SELECT r.routeFk, r.zoneFriendship, sum(af.friendship) friendshipSum + FROM tmp.route r + LEFT JOIN vn.ticket t ON t.routeFk = r.routeFk + LEFT JOIN cache.addressFriendship af ON af.addressFk2 = t.addressFk AND af.addressFk1 = vAddressFk + GROUP BY routeFk + ORDER BY zoneFriendship DESC, friendshipSum DESC + ) sub + LIMIT 1; + + RETURN vRouteFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/specie_IsForbidden.sql b/db/routines/vn/functions/specie_IsForbidden.sql new file mode 100644 index 000000000..5e7275ae7 --- /dev/null +++ b/db/routines/vn/functions/specie_IsForbidden.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`specie_IsForbidden`(vItemFk INT, vAddressFk INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vIsForbbiden BOOL; + DECLARE vLeft INT; + + SELECT zg.lft INTO vLeft + FROM vn.address a + JOIN vn.zoneGeo zg ON zg.name = a.postalCode + WHERE a.id = vAddressFk; + + SELECT sgi.isForbidden INTO vIsForbbiden + FROM vn.specieGeoInvasive sgi + JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk + JOIN vn.itemBotanical ib ON ib.genusFk = sgi.genusFk AND sgi.specieFk IN ('sp.',ib.specieFk) + WHERE vLeft BETWEEN zg.lft AND zg.rgt + AND ib.itemFk = vItemFk + ORDER BY zg.`depth` DESC + LIMIT 1; + + RETURN IFNULL(vIsForbbiden, FALSE); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/testCIF.sql b/db/routines/vn/functions/testCIF.sql new file mode 100644 index 000000000..ba2cc8345 --- /dev/null +++ b/db/routines/vn/functions/testCIF.sql @@ -0,0 +1,73 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`testCIF`(vCIF VARCHAR(9)) + RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + + DECLARE vLetraInicial VARCHAR(1); + DECLARE vLetraFinal VARCHAR(1); + DECLARE vParteNumerica VARCHAR(7); + DECLARE vSuma INT DEFAULT 0; + DECLARE vNumero INT DEFAULT 0; + DECLARE i INT DEFAULT 0; + DECLARE vResult BOOL DEFAULT FALSE; + + SET vLetraInicial = SUBSTR(vCIF, 1, 1); + SET vLetraFinal = SUBSTR(vCIF, 9, 1); + SET vParteNumerica = SUBSTR(vCIF, 2, 7); + + WHILE i < 7 DO + + SET i = i + 1; + + SET vNumero = CAST(SUBSTR(vParteNumerica, i, 1) AS DECIMAL(1,0)); + + IF i MOD 2 THEN + + SET vNumero = vNumero * 2; + SET vNumero = vNumero MOD 10 + FLOOR(vNumero/10); + + END IF; + + SET vSuma = vSuma + vNumero; + + END WHILE; + + SET vSuma = vSuma MOD 10; + + IF vSuma > 0 THEN + + SET vSuma = 10 - vSuma; + + END IF; + + -- Comprobación de dígito de control + IF CAST(vLetraFinal AS DECIMAL(1,0)) = vSuma THEN + + SET vResult = TRUE; + + END IF; + + IF vSuma = 0 THEN + + SET vSuma = 10; + + END IF; + + IF CHAR(64 + vSuma) = vLetraFinal THEN + + SET vResult = TRUE; + + END IF; + + -- Sólo se aceptan letras como caracter inicial + IF ASCII(vLetraInicial) < 65 OR ASCII(vLetraInicial) > 87 THEN -- Ha de ser entre la A y la W + + SET vResult = FALSE; + + END IF; + + RETURN vResult; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/testNIE.sql b/db/routines/vn/functions/testNIE.sql new file mode 100644 index 000000000..6843becad --- /dev/null +++ b/db/routines/vn/functions/testNIE.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`testNIE`(vNIE VARCHAR(9)) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + DECLARE vIndice INT; + DECLARE vNumero VARCHAR(7); + DECLARE vOperador VARCHAR(9); + DECLARE vParteNumerica DECIMAL(8,0); + DECLARE vLetraInicial VARCHAR(1); + DECLARE vLetraFinal VARCHAR(1); + DECLARE vLetrasFinalesPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; + DECLARE vLetraInicialEsIncorrecta BOOL DEFAULT FALSE; + + SET vLetraInicial = SUBSTR(vNIE, 1, 1); + SET vLetraFinal = SUBSTR(vNIE, 9, 1); + SET vNumero = SUBSTR(vNIE, 2, 7); + + CASE vLetraInicial + + WHEN 'X' THEN + + SET vOperador = "0"; + + WHEN 'Y' THEN + + SET vOperador = "1"; + + WHEN 'Z' THEN + + SET vOperador = "2"; + + ELSE + + SET vLetraInicialEsIncorrecta = TRUE; + + END CASE; + + SET vOperador = CONCAT(vOperador, vNumero); + SET vParteNumerica = CAST(vOperador AS DECIMAL(8,0)); + SET vIndice = Round(vParteNumerica Mod 23, 0) + 1; + + IF SUBSTR(vLetrasFinalesPosibles, vIndice, 1) = vLetraFinal AND vLetraInicialEsIncorrecta = FALSE THEN + + RETURN TRUE; + + ELSE + + RETURN FALSE; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/testNIF.sql b/db/routines/vn/functions/testNIF.sql new file mode 100644 index 000000000..5b6654312 --- /dev/null +++ b/db/routines/vn/functions/testNIF.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`testNIF`(vNIF VARCHAR(9)) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + DECLARE vIndice INT; + DECLARE vParteNumerica DECIMAL(8,0); + DECLARE vLetra VARCHAR(1); + DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; + + SET vLetra = SUBSTRING(vNIF, 9, 1); + + SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0)); + + SET vIndice = Round(vParteNumerica MOD 23, 0) + 1; + + If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then + + RETURN TRUE; + + ELSE + + RETURN FALSE; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketCollection_getNoPacked.sql b/db/routines/vn/functions/ticketCollection_getNoPacked.sql new file mode 100644 index 000000000..a9f04cc88 --- /dev/null +++ b/db/routines/vn/functions/ticketCollection_getNoPacked.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketCollection_getNoPacked`(vCollectionFk INT) + RETURNS varchar(100) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + DETERMINISTIC +BEGIN + + /* + * return message with tickets and collection if there is tickets of a collection without expeditions + * + * @param vCollectionFk the collection to check + * @return an array with collection and tickets without expeditions + * + */ + + DECLARE vAnswer VARCHAR(100) DEFAULT ''; + + IF collection_isPacked(vCollectionFk) = FALSE THEN + SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer + FROM vn.ticketCollection tc + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND ISNULL(e.id); + END IF; + + RETURN vAnswer; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketGetTotal.sql b/db/routines/vn/functions/ticketGetTotal.sql new file mode 100644 index 000000000..ced02e3c5 --- /dev/null +++ b/db/routines/vn/functions/ticketGetTotal.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketGetTotal`(vTicketId INT) + RETURNS decimal(10,2) + DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Calcula el total con IVA de un ticket. + * + * @param vTicketId Identificador del ticket + * @return Total del ticket + */ + DECLARE vTotal DECIMAL(10,2); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + SELECT vTicketId ticketFk; + + CALL ticketGetTotal(NULL); + + SELECT total INTO vTotal FROM tmp.ticketTotal; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticketTotal; + + RETURN vTotal; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketPositionInPath.sql b/db/routines/vn/functions/ticketPositionInPath.sql new file mode 100644 index 000000000..9bd2c110e --- /dev/null +++ b/db/routines/vn/functions/ticketPositionInPath.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketPositionInPath`(vTicketId INT) + RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN + + DECLARE vRestTicketsMaxOrder INT; + DECLARE vRestTicketsMinOrder INT; + DECLARE vRestTicketsPacking INT; + DECLARE vMyProductionOrder INT; + DECLARE vPosition VARCHAR(10) DEFAULT 'MID'; + DECLARE vMyPath INT; + DECLARE vMyWarehouse INT; + DECLARE PACKING_ORDER INT; + DECLARE vExpeditionsCount INT; + DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE; + +SELECT `order` + INTO PACKING_ORDER + FROM state + WHERE code = 'PACKING'; + +SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0) + INTO vMyPath, vMyWarehouse, vMyProductionOrder + FROM ticket t + LEFT JOIN ticketState ts on ts.ticketFk = t.id + WHERE t.id = vTicketId; + +SELECT (ag.`name` = 'VN_VALENCIA') + INTO vIsValenciaPath + FROM vn2008.Rutas r + JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia + JOIN vn2008.agency ag on ag.agency_id = a.agency_id + WHERE r.Id_Ruta = vMyPath; + +IF vIsValenciaPath THEN -- Rutas Valencia + + SELECT COUNT(*) + INTO vExpeditionsCount + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vMyPath; + + SELECT MAX(ts.productionOrder), MIN(ts.productionOrder) + INTO vRestTicketsMaxOrder, vRestTicketsMinOrder + FROM ticket t + LEFT JOIN ticketState ts on t.id = ts.ticketFk + WHERE t.routeFk = vMyPath + AND t.warehouseFk = vMyWarehouse + AND t.id != vTicketid; + + SELECT COUNT(*) + INTO vRestTicketsPacking + FROM ticket t + LEFT JOIN ticketState ts on t.id = ts.ticketFk + WHERE ts.productionOrder = PACKING_ORDER + AND t.routeFk = vMyPath + AND t.warehouseFk = vMyWarehouse + AND t.id != vTicketid; + + IF vExpeditionsCount = 1 THEN + SET vPosition = 'FIRST'; + ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN + SET vPosition = 'LAST'; + ELSEIF vRestTicketsPacking THEN + SET vPosition = 'SHARED'; + ELSE + SET vPosition = 'MID'; + END IF; + +ELSE + SET vPosition = 'MID'; + +END IF; + +RETURN vPosition; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketSplitCounter.sql b/db/routines/vn/functions/ticketSplitCounter.sql new file mode 100644 index 000000000..a04c4f8a9 --- /dev/null +++ b/db/routines/vn/functions/ticketSplitCounter.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketSplitCounter`(vTicketFk INT) + RETURNS varchar(15) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vSplitCounter VARCHAR(15); + + SELECT CONCAT(printedStickers,'/',Total, IF(printedStickers = Total ,' LS','')) INTO vSplitCounter + FROM + ( + SELECT count(l.Id_Movimiento) as printedStickers, COUNT(*) as Total + FROM vn.sale s + LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id + WHERE ticketFk = vTicketFk + ) sub; + + RETURN IFNULL(vSplitCounter,'--'); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketTotalVolume.sql b/db/routines/vn/functions/ticketTotalVolume.sql new file mode 100644 index 000000000..dc861ab6c --- /dev/null +++ b/db/routines/vn/functions/ticketTotalVolume.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketTotalVolume`(vTicketId INT) + RETURNS decimal(10,3) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + -- Devuelte el volumen total del ticket sumado + + DECLARE vVolume DECIMAL(10,3); + + SELECT SUM(volume) INTO vVolume + FROM saleVolume + WHERE ticketFk = vTicketId; + RETURN vVolume; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketTotalVolumeBoxes.sql b/db/routines/vn/functions/ticketTotalVolumeBoxes.sql new file mode 100644 index 000000000..eb529bab9 --- /dev/null +++ b/db/routines/vn/functions/ticketTotalVolumeBoxes.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketTotalVolumeBoxes`(vTicketId INT) + RETURNS decimal(10,1) + DETERMINISTIC +BEGIN + +/* + * Devuelve el volumen estimado del ticket sumado, en cajas + * + * vTicketId Numero de ticket + * + */ + + DECLARE vVolumeBoxM3 DOUBLE; + DECLARE vTicketTotalVolumeBoxes DECIMAL(10,1); + DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; + + SELECT volume / 1000000 INTO vVolumeBoxM3 FROM packaging WHERE id = vVnBoxId; + + SET vTicketTotalVolumeBoxes = ticketTotalVolume(vTicketId) / vVolumeBoxM3; + + RETURN vTicketTotalVolumeBoxes; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticketWarehouseGet.sql b/db/routines/vn/functions/ticketWarehouseGet.sql new file mode 100644 index 000000000..705949f24 --- /dev/null +++ b/db/routines/vn/functions/ticketWarehouseGet.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketWarehouseGet`(vTicketFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM ticket + WHERE id = vTicketFk; + + RETURN vWarehouseFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticket_CC_volume.sql b/db/routines/vn/functions/ticket_CC_volume.sql new file mode 100644 index 000000000..2572ae12d --- /dev/null +++ b/db/routines/vn/functions/ticket_CC_volume.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_CC_volume`(vTicketFk INT) + RETURNS decimal(10,1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE vCC DECIMAL(10,1); + + SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000) + INTO vCC + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.packaging p ON p.id = 'CC' + JOIN vn.volumeConfig vc + WHERE sv.ticketFk = vTicketFk; + + RETURN vCC; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticket_HasUbication.sql b/db/routines/vn/functions/ticket_HasUbication.sql new file mode 100644 index 000000000..344a34aa9 --- /dev/null +++ b/db/routines/vn/functions/ticket_HasUbication.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_HasUbication`(vTicketFk INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + DECLARE hasUbication BOOL; + + SELECT COUNT(*) INTO hasUbication + FROM vn.ticket t + JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + WHERE rm.beachFk + AND t.id = vTicketFk; + + RETURN hasUbication; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticket_get.sql b/db/routines/vn/functions/ticket_get.sql new file mode 100644 index 000000000..1f0e9a25a --- /dev/null +++ b/db/routines/vn/functions/ticket_get.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_get`(vParamFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +proc:BEGIN + + /* Devuelve el número de ticket o collection consultando en varias tablas posibles + * + * @param vParamFk Número a validar + * @return vValidFk Identificador validado + */ + + DECLARE vValidFk INT; + + -- Tabla vn.saleGroup + SELECT s.ticketFk INTO vValidFk + FROM vn.sale s + JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk + WHERE sg.id = vParamFk + AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()) + LIMIT 1; + + IF vValidFk THEN + + RETURN vValidFk; + + LEAVE proc; + + END IF; + + -- Tabla vn.collection + SELECT c.id INTO vValidFk + FROM vn.collection c + WHERE c.id = vParamFk + AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); + + IF vValidFk THEN + + RETURN vValidFk; + + LEAVE proc; + + END IF; + + -- Tabla vn.ticket + SELECT t.id INTO vValidFk + FROM vn.ticket t + WHERE t.id = vParamFk + AND t.shipped > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); + + IF vValidFk THEN + + RETURN vValidFk; + + LEAVE proc; + + END IF; + + RETURN NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticket_getFreightCost.sql b/db/routines/vn/functions/ticket_getFreightCost.sql new file mode 100644 index 000000000..61905aff2 --- /dev/null +++ b/db/routines/vn/functions/ticket_getFreightCost.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_getFreightCost`(vTicketFk INT) + RETURNS decimal(10,2) + DETERMINISTIC +BEGIN +/** + * Devuelve el coste de transportar un ticket. + * + * @vTicketFk Id del ticket a calcular + */ + DECLARE deliveryPrice DECIMAL (10,2); + + IF (SELECT isVolumetric FROM ticket t JOIN zone z ON t.zoneFk = z.id + WHERE t.id = vTicketFk) THEN + SELECT SUM(sv.freight) INTO deliveryPrice + FROM vn.saleVolume sv + WHERE sv.ticketFk = vTicketFk; + ELSE + SELECT SUM((t.zonePrice - t.zoneBonus) * ebv.ratio) INTO deliveryPrice + FROM vn.ticket t + LEFT JOIN expedition e ON e.ticketFk = t.id + JOIN expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk + WHERE t.id = vTicketFk; + + END IF; + RETURN deliveryPrice; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticket_getWeight.sql b/db/routines/vn/functions/ticket_getWeight.sql new file mode 100644 index 000000000..32f84cac7 --- /dev/null +++ b/db/routines/vn/functions/ticket_getWeight.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_getWeight`(vTicketFk INT) + RETURNS decimal(10,3) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Devuelve el peso total del ticket + * + * @return Total peso + */ + + DECLARE vWeight DECIMAL(10,3); + + SELECT sum(weight) INTO vWeight + FROM saleVolume + WHERE ticketFk = vTicketFk; + + RETURN vWeight; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/ticket_isOutClosureZone.sql b/db/routines/vn/functions/ticket_isOutClosureZone.sql new file mode 100644 index 000000000..ebddcf505 --- /dev/null +++ b/db/routines/vn/functions/ticket_isOutClosureZone.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isOutClosureZone`(vSelf INT) + RETURNS tinyint(1) + DETERMINISTIC +BEGIN +/** + * Devuelve true/false si la hora actual supera la hora del cierre del ticket más el tiempo configurado en packingDelay + * + * @param vSelf Ticket id + * @return true o false + */ + DECLARE vIsTicketInTime BOOL; + + SELECT TIMEDIFF(CURRENT_TIME(), zc.hour + INTERVAL tc.packingDelay HOUR) > 0 INTO vIsTicketInTime + FROM vn.ticket t + JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk + LEFT JOIN vn.ticketConfig tc ON TRUE + WHERE t.id = vSelf + AND zc.dated = util.VN_CURDATE(); + + RETURN vIsTicketInTime; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/till_new.sql b/db/routines/vn/functions/till_new.sql new file mode 100644 index 000000000..cfca5945d --- /dev/null +++ b/db/routines/vn/functions/till_new.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`till_new`(vClient INT + ,vBank INT + ,vAmount DOUBLE + ,vConcept VARCHAR(25) + ,vDated DATE + ,vSerie CHAR(1) + ,vBatch TINYINT + ,vNumber INT + ,vCompany SMALLINT + ,vWorker INT +) + RETURNS int(11) + DETERMINISTIC +BEGIN + DECLARE vAccount VARCHAR(12); + DECLARE vSubaccount VARCHAR(12); + DECLARE vAsiento INT DEFAULT NULL; + + -- Inserta el registro en cajas + + INSERT INTO till + SET + workerFk = vWorker + ,bankFk = vBank + ,`in` = vAmount + ,concept = vConcept + ,dated = vDated + ,serie = vSerie + ,isAccountable = vBatch + ,`number` = vNumber + ,companyFk = vCompany; + + -- Inserta los asientos contables + + SELECT account INTO vAccount + FROM bank WHERE id = vBank; + + SELECT accountingAccount INTO vSubaccount + FROM `client` WHERE id = vClient; + + SET vAsiento = xdiario_new + ( + vAsiento + ,vDated + ,vAccount + ,vSubaccount + ,vConcept + ,vAmount + ,0 + ,0 + ,NULL -- Serie + ,NULL -- Factura + ,NULL -- IVA + ,NULL -- Recargo + ,FALSE -- Auxiliar + ,vCompany + ); + DO xdiario_new + ( + vAsiento + ,vDated + ,vSubaccount + ,vAccount + ,vConcept + ,0 + ,vAmount + ,0 + ,NULL -- Serie + ,NULL -- Factura + ,NULL -- IVA + ,NULL -- Recargo + ,FALSE -- Auxiliar + ,vCompany + ); + + RETURN NULL; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/timeWorkerControl_getDirection.sql b/db/routines/vn/functions/timeWorkerControl_getDirection.sql new file mode 100644 index 000000000..518e4aeb5 --- /dev/null +++ b/db/routines/vn/functions/timeWorkerControl_getDirection.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`timeWorkerControl_getDirection`(vUserFk INT, vTimed DATETIME) + RETURNS varchar(6) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Verifica la dirección de la fichada + * @param vUserFk Identificador del trabajador + * @param vTimed Hora de la fichada + * @return Retorna sentido de la fichada 'in, out, middle' + */ + + DECLARE vPrevious DATETIME ; + DECLARE vNext DATETIME ; + DECLARE vPreviousDirection VARCHAR(3) ; + DECLARE vNextDirection VARCHAR(3) ; + DECLARE vDayStayMax INT; + DECLARE vTimedSeconds INT; + DECLARE vLastTimeIn INT; + + SELECT UNIX_TIMESTAMP(vTimed) INTO vTimedSeconds; + + SELECT dayStayMax INTO vDayStayMax + FROM vn.workerTimeControlParams; + + SELECT timed, direction INTO vNext,vNextDirection + FROM vn.workerTimeControl + WHERE userFk = vUserFk + AND direction IN ('in','out') + AND timed > vTimed + ORDER BY timed ASC + LIMIT 1; + + SELECT timed, direction INTO vPrevious, vPreviousDirection + FROM vn.workerTimeControl + WHERE userFk = vUserFk + AND direction IN ('in','out') + AND timed < vTimed + ORDER BY timed DESC + LIMIT 1; + + IF (vTimedSeconds - UNIX_TIMESTAMP(vPrevious) + UNIX_TIMESTAMP(vNext) - vTimedSeconds)<= vDayStayMax AND vPreviousDirection = 'in' AND vNextDirection = 'out' THEN + RETURN 'middle'; + END IF; + + + IF (vTimedSeconds> UNIX_TIMESTAMP(vPrevious)) THEN + IF vPreviousDirection = 'in' THEN + RETURN 'out'; + ELSE + SELECT UNIX_TIMESTAMP(MAX(timed)) INTO vLastTimeIn + FROM vn.workerTimeControl + WHERE userFk = vUserFk + AND direction ='in' + AND timed < vPrevious; + IF vTimedSeconds - vLastTimeIn <= vDayStayMax THEN + RETURN 'out'; + END IF; + END IF; + END IF; + + RETURN 'in'; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/time_getSalesYear.sql b/db/routines/vn/functions/time_getSalesYear.sql new file mode 100644 index 000000000..658a1112a --- /dev/null +++ b/db/routines/vn/functions/time_getSalesYear.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`time_getSalesYear`(vMonth INT, vYear INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +DECLARE vSalesYear INT; +SELECT salesYear INTO vSalesYear +FROM `time` +WHERE `month` = vMonth AND `year` = vYear +LIMIT 1; +RETURN vSalesYear; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/travel_getForLogiflora.sql b/db/routines/vn/functions/travel_getForLogiflora.sql new file mode 100644 index 000000000..cb3f0dac0 --- /dev/null +++ b/db/routines/vn/functions/travel_getForLogiflora.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`travel_getForLogiflora`(vLanded DATE, vWarehouseFk INT) + RETURNS int(11) + NOT DETERMINISTIC + READS SQL DATA +BEGIN + + /** + * Devuelve un número de travel para compras de Logiflora a partir de la fecha de llegada y del almacén. + * Si no existe lo genera. + * + * @param vLanded Fecha de llegada al almacén + * @param vWarehouseFk Identificador de vn.warehouse + */ + + DECLARE vTravelFk INT; + + IF vLanded THEN + + SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk + FROM vn.travel tr + JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + WHERE wIn.id = vWarehouseFk + AND wOut.name = 'Holanda' + AND am.name = 'LOGIFLORA' + AND landed = vLanded; + + IF NOT vTravelFk THEN + + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) + SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id + FROM vn.warehouse wOut + JOIN vn.agencyMode am ON am.name = 'LOGIFLORA' + WHERE wOut.name = 'Holanda'; + + SELECT MAX(tr.id) INTO vTravelFk + FROM vn.travel tr + JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk + WHERE wIn.id = vWarehouseFk + AND wOut.name = 'Holanda' + AND landed = vLanded; + END IF; + + END IF; + + RETURN vTravelFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/validationCode.sql b/db/routines/vn/functions/validationCode.sql new file mode 100644 index 000000000..75d603d24 --- /dev/null +++ b/db/routines/vn/functions/validationCode.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`validationCode`(vString VARCHAR(255)) + RETURNS int(11) + DETERMINISTIC +BEGIN + + DECLARE vSeed DOUBLE DEFAULT 0; + DECLARE vCode INT; + DECLARE vLength INT; + DECLARE vChar INT; + + SET vLength = length(vString); + + WHILE vLength > 0 DO + + SET vChar = MID(vString,vLength,1); + + SET vSeed = vSeed + ASCII(vChar); + + SET vLength = vLength - 1; + + END WHILE; + + SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; + + RETURN vCode; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/validationCode_beta.sql b/db/routines/vn/functions/validationCode_beta.sql new file mode 100644 index 000000000..0e27a4722 --- /dev/null +++ b/db/routines/vn/functions/validationCode_beta.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`validationCode_beta`(vString VARCHAR(255)) + RETURNS int(11) + DETERMINISTIC +BEGIN + + DECLARE vSeed DOUBLE DEFAULT 0; + DECLARE vCode INT; + DECLARE vLength INT; + DECLARE vChar INT; + + SET vLength = length(vString); + + WHILE vLength > 0 DO + + SET vChar = MID(vString,vLength,1); + + SET vSeed = vSeed + ASCII(vChar); + + SET vLength = vLength - 1; + + END WHILE; + + SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; + + RETURN vCode; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/workerMachinery_isRegistered.sql b/db/routines/vn/functions/workerMachinery_isRegistered.sql new file mode 100644 index 000000000..89a1c44ac --- /dev/null +++ b/db/routines/vn/functions/workerMachinery_isRegistered.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`workerMachinery_isRegistered`(vWorkerFk VARCHAR(10)) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo) + * + * @param vWorkerFk id del trabajador + * @return Devuelve TRUE/FALSE en caso de que haya o no registros + */ + IF (SELECT COUNT(*) + FROM machineWorker m + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), util.VN_NOW()) AND ISNULL(m.outTimed)) + THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/workerNigthlyHours_calculate.sql b/db/routines/vn/functions/workerNigthlyHours_calculate.sql new file mode 100644 index 000000000..0828b30f9 --- /dev/null +++ b/db/routines/vn/functions/workerNigthlyHours_calculate.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`workerNigthlyHours_calculate`(vTimeIn DATETIME, vTimeOut DATETIME) + RETURNS decimal(5,2) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Calcula el número decimal de horas nocturnas comprendidas entre 2 horas dadas + * + * @param vTimeIn + * @param vTimeOut + * @return vNigthlyHours + */ + DECLARE vNigthlyHours DECIMAL(5,2); + DECLARE vSecondsPerHour INT(4) DEFAULT 3600; + + SELECT GREATEST(0, TIMESTAMPDIFF(SECOND, + IF(TIME(vTimeIn) BETWEEN endNightlyHours AND startNightlyHours, + CONCAT(DATE(vTimeIn), ' ', startNightlyHours), + vTimeIn), + IF(TIME(vTimeOut) BETWEEN endNightlyHours AND startNightlyHours, + CONCAT(DATE(vTimeOut), ' ', endNightlyHours), + vTimeOut))) / vSecondsPerHour INTO vNigthlyHours + FROM vn.workerTimeControlConfig; + + RETURN vNigthlyHours; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/workerTimeControl_add.sql b/db/routines/vn/functions/workerTimeControl_add.sql new file mode 100644 index 000000000..63c40d7f2 --- /dev/null +++ b/db/routines/vn/functions/workerTimeControl_add.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`workerTimeControl_add`(vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) + RETURNS int(11) + DETERMINISTIC +BEGIN + DECLARE vDirection VARCHAR(6); + DECLARE vLastIn DATETIME; + DECLARE vDayStayMax INT; + DECLARE vHasDirectionOut INT; + DECLARE vLastInsertedId INT; + + SELECT dayStayMax INTO vDayStayMax + FROM workerTimeControlParams; + + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; + + IF vDirection = 'out' THEN + + SELECT MAX(timed) INTO vLastIn + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'in' + AND timed < vTimed; + + UPDATE workerTimeControl wtc + SET wtc.direction = 'middle' + WHERE userFk = vUserFk + AND direction = 'out' + AND timed BETWEEN vLastIn AND vTimed; + + ELSE IF vDirection = 'in' THEN + + SELECT COUNT(*) INTO vHasDirectionOut + FROM workerTimeControl wtc + WHERE userFk = vUserFk + AND direction = 'out' + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + + UPDATE workerTimeControl wtc + SET wtc.direction = IF (vHasDirectionOut,'middle','out') + WHERE userFk = vUserFk + AND direction = 'in' + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + + END IF; + END IF; + + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) + VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); + + SET vLastInsertedId = LAST_INSERT_ID(); + + CALL workerTimeControlSOWP(vUserFk, vTimed); + + RETURN vLastInsertedId; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/workerTimeControl_addDirection.sql b/db/routines/vn/functions/workerTimeControl_addDirection.sql new file mode 100644 index 000000000..4d935e895 --- /dev/null +++ b/db/routines/vn/functions/workerTimeControl_addDirection.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`workerTimeControl_addDirection`(vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) + RETURNS int(11) + DETERMINISTIC +BEGIN + DECLARE vDirection VARCHAR(6); + DECLARE vLastIn DATETIME; + DECLARE vDayStayMax INT; + DECLARE vHasDirectionOut INT; + DECLARE vLastInsertedId INT; + + SELECT dayStayMax INTO vDayStayMax + FROM workerTimeControlParams; + + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; + + IF vDirection = 'out' THEN + + SELECT MAX(timed) INTO vLastIn + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'in' + AND timed < vTimed; + + UPDATE workerTimeControl wtc + SET wtc.direction = 'middle' + WHERE userFk = vUserFk + AND direction = 'out' + AND timed BETWEEN vLastIn AND vTimed; + + ELSE IF vDirection = 'in' THEN + + SELECT COUNT(*) INTO vHasDirectionOut + FROM workerTimeControl wtc + WHERE userFk = vUserFk + AND direction = 'out' + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + + UPDATE workerTimeControl wtc + SET wtc.direction = IF (vHasDirectionOut,'middle','out') + WHERE userFk = vUserFk + AND direction = 'in' + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + + END IF; + END IF; + + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) + VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); + + SET vLastInsertedId = LAST_INSERT_ID(); + + CALL workerTimeControlSOWP(vUserFk, vTimed); + + RETURN vLastInsertedId; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/worker_getCode.sql b/db/routines/vn/functions/worker_getCode.sql new file mode 100644 index 000000000..d3d63dccc --- /dev/null +++ b/db/routines/vn/functions/worker_getCode.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`worker_getCode`() + RETURNS varchar(3) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + NOT DETERMINISTIC + READS SQL DATA +BEGIN + DECLARE vUserCode VARCHAR(3) CHARSET utf8 COLLATE utf8_unicode_ci; + + SELECT code INTO vUserCode + FROM worker + WHERE id = account.myUser_getId(); + + RETURN vUserCode; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/worker_isBoss.sql b/db/routines/vn/functions/worker_isBoss.sql new file mode 100644 index 000000000..7efada705 --- /dev/null +++ b/db/routines/vn/functions/worker_isBoss.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`worker_isBoss`(vUserId INT) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Comprueba por jerarquía si el trabajador actual es jefe + * de un trabajador en concreto. + * + * @param vSelf Id del trabajador que se desea comprobar. + * @return Revuelve verdadero si es jefe del empleado por escala jerárquica. + */ + DECLARE vWorkerId INT; + DECLARE vBossId INT; + + SELECT id INTO vWorkerId + FROM worker + WHERE id = vSelf; + IF vWorkerId IS NULL THEN + CALL util.throw('USER_NOT_FOUND'); + END IF; + + DROP TEMPORARY TABLE IF EXISTS tCheckedWorker; + CREATE TEMPORARY TABLE tCheckedWorker + (PRIMARY KEY (workerFk)) + ENGINE = MEMORY + SELECT id workerFk FROM worker LIMIT 0; + LOOP + SELECT bossFk INTO vBossId + FROM worker + WHERE id = vWorkerId; + IF (SELECT COUNT(*) FROM tCheckedWorker WHERE workerFk = vBossId) THEN + CALL util.throw('INFINITE_LOOP'); + END IF; + IF vBossId = vWorkerId THEN + RETURN FALSE; + ELSEIF vBossId = account.myUser_getId() THEN + RETURN TRUE; + ELSE + INSERT INTO tCheckedWorker VALUES (vWorkerId); + SET vWorkerId = vBossId; + END IF; + END LOOP; + DROP TEMPORARY TABLE tCheckedWorker; + RETURN FALSE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/worker_isWorking.sql b/db/routines/vn/functions/worker_isWorking.sql new file mode 100644 index 000000000..3db333bd0 --- /dev/null +++ b/db/routines/vn/functions/worker_isWorking.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`worker_isWorking`(vWorkerFk INT) + RETURNS tinyint(1) + NOT DETERMINISTIC + READS SQL DATA +BEGIN +/** + * Comprueba si el trabajador está trabajando en el momento de la consulta + * @return Devuelve TRUE en caso de que este trabajando. Si se encuentra en un descanso devolverá FALSE + */ + DECLARE vLastIn DATETIME ; + + SELECT MAX(timed) INTO vLastIn + FROM vn.workerTimeControl + WHERE userFk = vWorkerFk AND + direction = 'in'; + + IF (SELECT MOD(COUNT(*),2) + FROM vn.workerTimeControl + WHERE userFk = vWorkerFk AND + timed >= vLastIn + ) THEN + RETURN TRUE; + ELSE + RETURN FALSE; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/xdiario_new.sql b/db/routines/vn/functions/xdiario_new.sql new file mode 100644 index 000000000..06e6e57b2 --- /dev/null +++ b/db/routines/vn/functions/xdiario_new.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(vAsiento INT, + vDated DATE, + vSubaccount VARCHAR(12), + vAccount VARCHAR(12), + vConcept VARCHAR(25), + vDebit DOUBLE, + vCredit DOUBLE, + vEuro DOUBLE, + vSerie CHAR(1), + vInvoice VARCHAR(8), + vVat DOUBLE, + vRe DOUBLE, + vAux TINYINT, + vCompany INT +) + RETURNS int(11) + NOT DETERMINISTIC + NO SQL +BEGIN + IF vAsiento IS NULL THEN + CALL vn.ledger_next(vAsiento); + END IF; + + INSERT INTO XDiario + SET ASIEN = vAsiento, + FECHA = vDated, + SUBCTA = vSubaccount, + CONTRA = vAccount, + CONCEPTO = vConcept, + EURODEBE = vDebit, + EUROHABER = vCredit, + BASEEURO = vEuro, + SERIE = vSerie, + FACTURA = vInvoice, + IVA = vVat, + RECEQUIV = vRe, + AUXILIAR = IF(vAux = FALSE, NULL, '*'), + MONEDAUSO = 2, + empresa_id = vCompany; + + RETURN vAsiento; +END$$ +DELIMITER ; diff --git a/db/routines/vn/functions/zoneGeo_new.sql b/db/routines/vn/functions/zoneGeo_new.sql new file mode 100644 index 000000000..65b045962 --- /dev/null +++ b/db/routines/vn/functions/zoneGeo_new.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`zoneGeo_new`(vType VARCHAR(255), vName VARCHAR(255), vParentFk INT) + RETURNS int(11) + NOT DETERMINISTIC + NO SQL +BEGIN +/** + * Creates a new node a node from the #zoneGeo table. + * Also sets a mark to force the tree recalculation. + * + * @param vType The node type + * @param vName The node name + * @param vParentFk The parent node identifier + * @return The new node identifier + */ + DECLARE vSelf INT; + + INSERT INTO zoneGeo + SET `type` = vType, + `name` = vName, + parentFk = vParentFk; + + SET vSelf = LAST_INSERT_ID(); + + UPDATE zoneGeoRecalc SET isChanged = TRUE; + + RETURN vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/XDiario_checkDate.sql b/db/routines/vn/procedures/XDiario_checkDate.sql new file mode 100644 index 000000000..b481d1f36 --- /dev/null +++ b/db/routines/vn/procedures/XDiario_checkDate.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_checkDate`(vDate DATE) +proc: BEGIN +/** + * Comprueba si la fecha pasada esta en el rango + * de fecha de contabilidad + * + * @param vDate Fecha para comparar + */ + DECLARE vIsInvalid BOOL; + + IF vDate IS NULL THEN + LEAVE proc; + END IF; + + SELECT COUNT(*) = 0 INTO vIsInvalid + FROM accountingConfig + WHERE vDate BETWEEN minDate AND maxDate; + + IF vIsInvalid THEN + CALL util.throw ('Fecha fuera de rango'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/addNoteFromDelivery.sql b/db/routines/vn/procedures/addNoteFromDelivery.sql new file mode 100644 index 000000000..61295b7db --- /dev/null +++ b/db/routines/vn/procedures/addNoteFromDelivery.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`addNoteFromDelivery`(idTicket INT,nota TEXT) +BEGIN + + DECLARE observationTypeFk INT DEFAULT 3; /*3 = REPARTIDOR*/ + + INSERT INTO ticketObservation(ticketFk,observationTypeFk,description) + VALUES (idTicket,observationTypeFk,nota) + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/addressTaxArea.sql b/db/routines/vn/procedures/addressTaxArea.sql new file mode 100644 index 000000000..5deb01fa4 --- /dev/null +++ b/db/routines/vn/procedures/addressTaxArea.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`addressTaxArea`() + READS SQL DATA +BEGIN +/** + * Devuelve el taxArea para un conjunto de Consignatarios y empresas, + * + * @table tmp.addressCompany(addressFk, companyFk) valores a calcular + * @return tmp.addressTaxArea(addressFk,companyFk) + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; + CREATE TEMPORARY TABLE tmp.addressTaxArea + (PRIMARY KEY (addressFk, companyFk)) + ENGINE = MEMORY + SELECT CASE + WHEN (NOT IFNULL(auClient.isUeeMember, cClient.isUeeMember) OR NOT cSupplier.isUeeMember) + AND NOT (auSupplier.id <=> auClient.id) THEN + 'WORLD' + WHEN cClient.isUeeMember AND cSupplier.isUeeMember AND c.countryFk != s.countryFk AND c.isVies THEN + 'CEE' + WHEN a.isEqualizated AND cClient.code = 'ES' THEN + 'EQU' + ELSE + 'NATIONAL' + END AS areaFk, ac.addressFk, ac.companyFk + FROM tmp.addressCompany ac + JOIN address a ON a.id = ac.addressFk + JOIN `client` c ON c.id = a.clientFk + JOIN country cClient ON cClient.id = c.countryFk + LEFT JOIN province pClient ON pClient.id = c.provinceFk + LEFT JOIN autonomy auClient ON auClient.id = pClient.autonomyFk + JOIN supplier s ON s.id = ac.companyFk + JOIN country cSupplier ON cSupplier.id = s.countryFk + LEFT JOIN province pSupplier ON pSupplier.id = s.provinceFk + LEFT JOIN autonomy auSupplier ON auSupplier.id = pSupplier.autonomyFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/agencyHourGetFirstShipped.sql b/db/routines/vn/procedures/agencyHourGetFirstShipped.sql new file mode 100644 index 000000000..4bd1c4222 --- /dev/null +++ b/db/routines/vn/procedures/agencyHourGetFirstShipped.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`agencyHourGetFirstShipped`(vAgencyMode INT, vAddress INT, vWarehouse INT) +BEGIN +/** + * DEPRECATED usar zoneGetFirstShipped +* Devuelve la primera fecha de envio disponible para una agencia en una direccion y un warehouse +* +* @param vAgencyMode id de la agencia en vn.agencyMode +* @param vAddress id de la direccion +* @param vWarehouse id del warehouse +* @return vShipped la primera fecha disponible y vLanded la fecha de llegada/recojida +*/ +DECLARE vAgency INT; +DECLARE vShipped DATE; +DECLARE vLanded DATE DEFAULT util.VN_CURDATE(); + SELECT agencyFk INTO vAgency FROM agencyMode WHERE id= vAgencyMode; + + l: LOOP + + CALL agencyHourGetShipped(vLanded,vAddress,vAgency); + SELECT shipped INTO vShipped + FROM tmp.agencyHourGetShipped + WHERE warehouseFk = vWarehouse LIMIT 1; + + IF vShipped THEN + LEAVE l; + END IF; + + SET vLanded = DATE_ADD(vLanded, INTERVAL +1 DAY); + + END LOOP; + + SELECT vShipped,vLanded; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/agencyHourGetLanded.sql b/db/routines/vn/procedures/agencyHourGetLanded.sql new file mode 100644 index 000000000..ee48388a0 --- /dev/null +++ b/db/routines/vn/procedures/agencyHourGetLanded.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`agencyHourGetLanded`(vDated DATE, vAddress INT, vAgency INT, vWarehouse INT) +BEGIN +/** + * DEPRECATED usar zoneGetLanded + * Devuelve una tabla temporal con el dia de recepcion para vDated. + * + * @param vDated Fecha de preparacion de mercancia + * @param vAddress Id de consignatario, %NULL para recogida + * @param vAgency Id agencia + * @table tmp.agencyHourGetLanded Datos de recepción + */ + DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetLanded; + CREATE TEMPORARY TABLE tmp.agencyHourGetLanded + ENGINE = MEMORY + SELECT vWarehouse warehouseFk, landed FROM ( + SELECT * FROM ( + SELECT vWarehouse, TIMESTAMPADD(DAY, ah.substractDay, vDated) landed, ah.substractDay, ah.maxHour + FROM agencyHour ah + LEFT JOIN address a ON a.id = vAddress + WHERE (ah.weekDay = WEEKDAY(TIMESTAMPADD(DAY, ah.substractDay, vDated)) OR ah.weekDay IS NULL) + AND (ah.agencyFk = vAgency OR ah.agencyFk IS NULL) + AND ah.warehouseFk = vWarehouse + AND (ah.provinceFk = a.provinceFk OR ah.provinceFk IS NULL OR vAddress IS NULL) + ORDER BY ( + (ah.weekDay IS NOT NULL) + + (ah.agencyFk IS NOT NULL) + + (- ah.substractDay) + + ((ah.provinceFk IS NOT NULL)*3) + ) DESC + ) t + LIMIT 1 + ) t + WHERE IF(vDated = util.VN_CURDATE(), t.maxHour > HOUR(util.VN_NOW()), TRUE) AND t.substractDay < 225; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/agencyHourGetWarehouse.sql b/db/routines/vn/procedures/agencyHourGetWarehouse.sql new file mode 100644 index 000000000..7fc524fce --- /dev/null +++ b/db/routines/vn/procedures/agencyHourGetWarehouse.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`agencyHourGetWarehouse`(vAddress INT, vDate DATE, vWarehouse INT) +BEGIN +/** + * DEPRECATED usar zoneGetWarehouse + * Devuelve el listado de agencias disponibles para la fecha, + * dirección y warehouuse pasadas + * + * @param vAddress no puede ser NULL + * @param vWarehouse warehouse donde comprobaremos las agencias y fecha + * @param vDate Fecha de recogida + * @table agencyModeWarehouseList Listado de agencias disponibles + */ + DECLARE vAgency INT; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vCur CURSOR FOR + SELECT DISTINCT a.id + FROM agency a + JOIN agencyHour ah ON ah.agencyFk = a.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + IF vAddress IS NULL + THEN + CALL util.throw ('Address cannot be null'); + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.agencyModeWarehouseList; + CREATE TEMPORARY TABLE tmp.agencyModeWarehouseList ( + id INT NOT NULL, + agency VARCHAR(20), + description VARCHAR(45), + deliveryMethodFk VARCHAR(45), + shipped DATE, + warehouse VARCHAR(45), + PRIMARY KEY(id) + ) + ENGINE = MEMORY; + + OPEN vCur; + FETCH vCur INTO vAgency; + + WHILE NOT vDone + DO + + INSERT INTO tmp.agencyModeWarehouseList + SELECT am.id, am.name, am.description,am.deliveryMethodFk, TIMESTAMPADD(DAY, -ah.substractDay, vDate), w.name + FROM agencyHour ah + LEFT JOIN address a ON a.id = vAddress + JOIN agencyMode am ON am.agencyFk = vAgency + JOIN warehouse w on w.id = ah.warehouseFk + WHERE ah.warehouseFk = vWarehouse + AND (weekDay = WEEKDAY(vDate) + OR weekDay IS NULL) + AND (ah.agencyFk = vAgency + OR ah.agencyFk IS NULL) + AND (ah.provinceFk = a.provinceFk + OR ah.provinceFk IS NULL + OR vAddress IS NULL) + AND TIMESTAMPADD(DAY, -ah.substractDay, vDate) >= util.VN_CURDATE() + AND IF(TIMESTAMPADD(DAY, -ah.substractDay, vDate) = util.VN_CURDATE(), ah.maxHour > HOUR(util.VN_NOW()), TRUE) + ORDER BY ( + (ah.weekDay IS NOT NULL) + + (ah.agencyFk IS NOT NULL) + + ((ah.provinceFk IS NOT NULL) * 3) + ) DESC + LIMIT 1; + + + FETCH vCur INTO vAgency; + END WHILE; + + CLOSE vCur; + + SELECT * FROM tmp.agencyModeWarehouseList; + DROP TEMPORARY TABLE tmp.agencyModeWarehouseList; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/agencyHourListGetShipped.sql b/db/routines/vn/procedures/agencyHourListGetShipped.sql new file mode 100644 index 000000000..b4cf35f77 --- /dev/null +++ b/db/routines/vn/procedures/agencyHourListGetShipped.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`agencyHourListGetShipped`(vDate DATE, vAddress INT, vAgency INT) +BEGIN + /* * DEPRECATED usar zoneGetShipped +*/ + CALL vn.agencyHourGetShipped(vDate, vAddress, vAgency); + + SELECT * FROM tmp.agencyHourGetShipped; + + DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/available_calc.sql b/db/routines/vn/procedures/available_calc.sql new file mode 100644 index 000000000..8c806d41d --- /dev/null +++ b/db/routines/vn/procedures/available_calc.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`available_calc`( + vDate DATE, + vAddress INT, + vAgencyMode INT) +BEGIN +/** + * Calculates the available for all available stores + * according to the given parameters. + * + * @param vDate The delivery date + * @param vAddress The delivery address id + * @param vAgencyMode The shipping agency + * @return tmp.availableCalc(calcFk) The available cache ids + */ + DECLARE vCalcFk INT; + DECLARE vShipment DATE; + DECLARE vWarehouse INT; + DECLARE vDone BOOL; + + DECLARE cWarehouses CURSOR FOR + SELECT warehouseFk, shipped FROM tmp.zoneGetShipped; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + -- Establecemos los almacenes y las fechas que van a entrar al disponible + + CALL vn.zone_getShipped (vDate, vAddress, vAgencyMode, FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.availableCalc; + CREATE TEMPORARY TABLE tmp.availableCalc( + calcFk INT UNSIGNED, + PRIMARY KEY (calcFk) + ) + ENGINE = MEMORY; + + OPEN cWarehouses; + + l: LOOP + SET vDone = FALSE; + FETCH cWarehouses INTO vWarehouse, vShipment; + + IF vDone THEN + LEAVE l; + END IF; + + CALL `cache`.available_refresh(vCalcFk, FALSE, vWarehouse, vShipment); + + INSERT IGNORE INTO tmp.availableCalc + SET calcFk = vCalcFk; + END LOOP; + + CLOSE cWarehouses; + DROP TEMPORARY TABLE tmp.zoneGetShipped; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/bankEntity_checkBic.sql b/db/routines/vn/procedures/bankEntity_checkBic.sql new file mode 100644 index 000000000..2f05ae654 --- /dev/null +++ b/db/routines/vn/procedures/bankEntity_checkBic.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`bankEntity_checkBic`(vBic VARCHAR(255)) +BEGIN + /** + * If the bic length is Incorrect throw exception + * + * @param vBic bic code + */ + + DECLARE vConfigBicLenght INT; + + SELECT bicLength INTO vConfigBicLenght + FROM vn.bankEntityConfig bec; + + IF LENGTH(vBic) <> vConfigBicLenght THEN + CALL util.throw(CONCAT('bic must be of length ', vConfigBicLenght )); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/bankPolicy_notifyExpired.sql b/db/routines/vn/procedures/bankPolicy_notifyExpired.sql new file mode 100644 index 000000000..6bdc6f759 --- /dev/null +++ b/db/routines/vn/procedures/bankPolicy_notifyExpired.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`bankPolicy_notifyExpired`() +BEGIN +/** +* +* Manda correo cuando caduca un seguro +* de los leasing +* +*/ + INSERT INTO mail (receiver,replyTo,subject,body) + SELECT 'administracion@verdnatura.es' receiver, + 'noreply@verdnatura.es' replyTo, + CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') subject, + CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') body + FROM vn.bankPolicy bp + LEFT JOIN vn.supplier s + ON s.id = bp.supplierFk + LEFT JOIN vn.bank b + ON b.id = bp.bankFk + WHERE bp.insuranceExpired = util.VN_CURDATE(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql new file mode 100644 index 000000000..404a8fdab --- /dev/null +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(vWarehouseFk SMALLINT, vDated DATE) +BEGIN +/** + * Calcula las últimas compras realizadas hasta una fecha + * + * @param vWarehouseFk Id del almacén + * @param vDated Compras hasta fecha + * @return tmp.buyUltimate + */ + CALL cache.last_buy_refresh (FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; + CREATE TEMPORARY TABLE tmp.buyUltimate + (PRIMARY KEY (itemFk, warehouseFk), + INDEX(itemFk)) + ENGINE = MEMORY + SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing + FROM cache.last_buy + WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; + + CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); + + REPLACE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed <= vDated; + + INSERT IGNORE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed > vDated; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql new file mode 100644 index 000000000..e9d30f4c9 --- /dev/null +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -0,0 +1,129 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE) +BEGIN +/** + * Calcula las últimas compras realizadas + * desde un rango de fechas. + * + * @param vWarehouseFk Id del almacén si es NULL se actualizan todos + * @param vStarted Fecha inicial + * @param vEnded Fecha fin + * @return tmp.buyUltimateFromInterval + */ + IF vEnded IS NULL THEN + SET vEnded = vStarted; + END IF; + + IF vEnded < vStarted THEN + SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); + END IF; + + -- Item + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; + CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval + (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) + ENGINE = MEMORY + SELECT itemFk, + warehouseFk, + buyFk, + MAX(landed) landed + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND b.quantity > 0 + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + GROUP BY itemFk, warehouseInFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + GROUP BY itemFk, warehouseInFk; + + -- ItemOriginal + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT itemFk, + warehouseFk, + buyFk, + MAX(landed) landed + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + itemOriginalFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND b.quantity > 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemOriginalFk, warehouseFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND itemOriginalFk + GROUP BY itemOriginalFk, warehouseInFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + AND itemOriginalFk + GROUP BY itemOriginalFk, warehouseInFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_afterUpsert.sql b/db/routines/vn/procedures/buy_afterUpsert.sql new file mode 100644 index 000000000..ed98cb595 --- /dev/null +++ b/db/routines/vn/procedures/buy_afterUpsert.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`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 vPackingOut DECIMAL(10,2); + DECLARE vWarehouse INT; + DECLARE vStandardFlowerBox INT; + DECLARE vWarehouseOut INT; + DECLARE vIsMerchandise BOOL; + DECLARE vIsFeedStock BOOL; + DECLARE vWeight DECIMAL(10,2); + DECLARE vPacking INT; + + SELECT b.entryFk, + b.itemFk, + i.packingOut, + ic.merchandise, + vc.standardFlowerBox, + b.weight, + b.packing + INTO + vEntryFk, + vItemFk, + vPackingOut, + vIsMerchandise, + vStandardFlowerBox, + vWeight, + vPacking + FROM buy b + LEFT JOIN item i ON i.id = b.itemFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN packaging p ON p.id = b.packagingFk AND NOT p.isBox + JOIN volumeConfig vc ON TRUE + WHERE b.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; + + IF vIsMerchandise THEN + + REPLACE itemCost SET + itemFk = vItemFk, + warehouseFk = vWarehouse, + cm3 = buy_getUnitVolume(vSelf), + cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf)); + + IF vWeight AND vPacking THEN + UPDATE itemCost SET + grams = vWeight * 1000 / vPacking + WHERE itemFk = vItemFk + AND warehouseFk = vWarehouse; + END IF; + END IF; + + SELECT isFeedStock INTO vIsFeedStock + FROM warehouse WHERE id = vWarehouseOut; + + IF vIsFeedStock THEN + INSERT IGNORE INTO producer(`name`) + SELECT es.company_name + FROM buy b + JOIN edi.ekt be ON be.id = b.ektFk + JOIN edi.supplier es ON es.supplier_id = be.pro + WHERE b.id = vSelf; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_checkGrouping.sql b/db/routines/vn/procedures/buy_checkGrouping.sql new file mode 100644 index 000000000..11c727fb1 --- /dev/null +++ b/db/routines/vn/procedures/buy_checkGrouping.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`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 ; diff --git a/db/routines/vn/procedures/buy_getSplit.sql b/db/routines/vn/procedures/buy_getSplit.sql new file mode 100644 index 000000000..73cc1dda7 --- /dev/null +++ b/db/routines/vn/procedures/buy_getSplit.sql @@ -0,0 +1,128 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getSplit`(vSelf INT, vDated DATE) +BEGIN +/** + * Devuelve tantos registros como etiquetas se necesitan para cada uno de los cubos o cajas de + * las ventas correspondientes a la compra que se pasa como parámetro, en los almacenes que tienen + * habilitada la venta de productos con stock virtual, aunque los productos pueden ser de cualquier tipo. + * + * @param vSelf Identificador de vn.buy + * @param vDated Fecha de preparación de las ventas que queremos etiquetar + */ + DECLARE vItemFk INT; + DECLARE vPacking INT; + DECLARE vRemaining INT; + DECLARE vLabels INT; + DECLARE vSaleFk INT; + DECLARE vAmount INT; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vCounter INT DEFAULT 1; + + DECLARE cur CURSOR FOR + SELECT s.id, s.quantity - IFNULL(l.stem, 0) + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + LEFT JOIN vn.saleLabel l ON l.saleFk = s.id + WHERE s.itemFk = vItemFk + AND t.shipped >= vDated + AND w.isLogiflora + AND IFNULL(l.stem, 0) < s.quantity + ORDER BY s.quantity = vRemaining DESC + LOCK IN SHARE MODE; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + -- Obtiene los datos de la compra + + SELECT itemFk, packing, quantity + INTO vItemFk, vPacking, vRemaining + FROM vn.buy WHERE id = vSelf; + + -- Crea splits de los tickets + CREATE OR REPLACE TEMPORARY TABLE tmp.split + ( + id INT, + labels INT DEFAULT 0, + counter INT DEFAULT 0 + ) + ENGINE = MEMORY; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + + FETCH cur INTO vSaleFk, vAmount; + + IF vDone OR vRemaining = 0 THEN + LEAVE l; + END IF; + + SET vAmount = LEAST(vAmount, vRemaining); + + SET vRemaining = vRemaining - vAmount; + + SET vLabels = vAmount DIV vPacking; + + -- Se inserta una linea por cada etiqueta + SET vCounter = 1; + + WHILE vLabels >= vCounter DO + INSERT INTO tmp.split + SET + id = vSaleFk, + labels = vLabels, + counter = vCounter; + + SET vCounter = vCounter + 1; + END WHILE; + + INSERT INTO vn.saleLabel + SET + saleFk = vSaleFk, + stem = vAmount, + label = vLabels + ON DUPLICATE KEY UPDATE + stem = stem + VALUES(stem), + label = label + VALUES(label); + END LOOP; + + CLOSE cur; + + -- Devuelve los splits creados + SELECT CONCAT(sp.counter,'/',sp.labels) labels, + COALESCE(sfc.nickname, sfa.nickname, a.nickname) destination, + s.itemFk, + i.longName, + i.`size`, + vn.ticketSplitCounter(t.id) counter, + IF(sfa.id OR sfc.id, + a.nickname, + CONCAT(a.id, ' ', p.`name`,' (', c.`code`,')')) destination2 + FROM tmp.split sp + JOIN vn.sale s ON sp.id = s.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.country c ON c.id = p.countryFk + LEFT JOIN vn.splitFilter sfa ON sfa.autonomyFk = p.autonomyFk + LEFT JOIN vn.splitFilter sfc ON sfc.clientFk = t.clientFk; + + -- Limpia y confirma cambios + DROP TEMPORARY TABLE + tmp.split; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getVolume.sql b/db/routines/vn/procedures/buy_getVolume.sql new file mode 100644 index 000000000..633be7ec0 --- /dev/null +++ b/db/routines/vn/procedures/buy_getVolume.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getVolume`() +BEGIN +/** + * Cálculo de volumen en líneas de compra + * @table tmp.buy(buyFk) + */ + SELECT t.name Temp, + CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * + item_getVolume(b.itemFk, b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) carros , + CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * + item_getVolume(b.itemFk, b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) espais + FROM buy b + JOIN tmp.buy tb ON tb.buyFk = b.id + JOIN volumeConfig vc + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN temperature t ON t.code = it.temperatureFk + GROUP BY Temp; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getVolumeByAgency.sql b/db/routines/vn/procedures/buy_getVolumeByAgency.sql new file mode 100644 index 000000000..2f63c2bdf --- /dev/null +++ b/db/routines/vn/procedures/buy_getVolumeByAgency.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getVolumeByAgency`(vDated DATE, vAgencyFk INT) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.buy; + CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; + + INSERT INTO tmp.buy + SELECT b.id + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed = vDated + AND t.agencyModeFk IN (0, vAgencyFk); + + CALL buy_getVolume(); + DROP TEMPORARY TABLE tmp.buy; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_getVolumeByEntry.sql b/db/routines/vn/procedures/buy_getVolumeByEntry.sql new file mode 100644 index 000000000..e9a2bca2e --- /dev/null +++ b/db/routines/vn/procedures/buy_getVolumeByEntry.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getVolumeByEntry`(vEntryFk INT) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.buy; + CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; + + INSERT INTO tmp.buy + SELECT b.id + FROM buy b + JOIN entry e ON e.id = b.entryFk + WHERE e.id = vEntryFk; + + CALL buy_getVolume(); + DROP TEMPORARY TABLE tmp.buy; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_recalcPrices.sql b/db/routines/vn/procedures/buy_recalcPrices.sql new file mode 100644 index 000000000..35eb00cf1 --- /dev/null +++ b/db/routines/vn/procedures/buy_recalcPrices.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPrices`() +BEGIN +/** + * Recalcula los precios para las compras insertadas en tmp.buyRecalc + * + * @param tmp.buyRecalc (id) + */ + DECLARE vLanded DATE; + DECLARE vWarehouseFk INT; + DECLARE vHasNotPrice BOOL; + DECLARE vBuyingValue DECIMAL(10,4); + DECLARE vPackagingFk VARCHAR(10); + DECLARE vIsWarehouseFloramondo BOOL; + + SELECT t.landed, t.warehouseInFk, (w.`name` = 'Floramondo') + INTO vLanded, vWarehouseFk, vIsWarehouseFloramondo + FROM tmp.buyRecalc br + JOIN buy b ON b.id = br.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + LIMIT 1; + + CALL rate_getPrices(vLanded, vWarehouseFk); + + UPDATE buy b + JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id) + LEFT JOIN packaging p ON p.id = b.packagingFk + JOIN item i ON i.id = b.itemFk + JOIN entry e ON e.id = b.entryFk + JOIN itemType it ON it.id = i.typeFk + JOIN travel tr ON tr.id = e.travelFk + JOIN agencyMode am ON am.id = tr.agencyModeFk + JOIN tmp.rate r + JOIN volumeConfig vc + SET b.freightValue = @PF:= IFNULL(((am.m3 * @m3:= item_getVolume(b.itemFk, b.packagingFk) / 1000000) + / b.packing) * IF(am.hasWeightVolumetric, GREATEST(b.weight / @m3 / vc.aerealVolumetricDensity, 1), 1), 0), + b.comissionValue = @CF:= ROUND(IFNULL(e.commission * b.buyingValue / 100, 0), 3), + b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)), + b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 + b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2), + b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2); + + SELECT (b.buyingValue = b.price2), b.buyingValue, b.packagingFk + INTO vHasNotPrice, vBuyingValue, vPackagingFk + FROM vn.buy b + WHERE b.id = @buyId AND b.buyingValue <> 0.01; + + DROP TEMPORARY TABLE tmp.rate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_recalcPricesByAwb.sql b/db/routines/vn/procedures/buy_recalcPricesByAwb.sql new file mode 100644 index 000000000..bc0c9bcb3 --- /dev/null +++ b/db/routines/vn/procedures/buy_recalcPricesByAwb.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByAwb`(IN awbFk varchar(18)) +BEGIN +/** + * inserta en tmp.buyRecalc las compras de un awb + * + * @param awbFk + */ + DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; + + CREATE TEMPORARY TABLE tmp.buyRecalc + SELECT b.id + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN duaEntry de ON de.entryFk = e.id + JOIN dua d ON d.id = de.duaFk + JOIN awb a ON a.id = d.awbFk + WHERE a.code = awbFk; + + CALL buy_recalcPrices(); + + DROP TEMPORARY TABLE tmp.buyRecalc; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_recalcPricesByBuy.sql b/db/routines/vn/procedures/buy_recalcPricesByBuy.sql new file mode 100644 index 000000000..b963bae14 --- /dev/null +++ b/db/routines/vn/procedures/buy_recalcPricesByBuy.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByBuy`(IN vBuyFk INT(11)) +BEGIN +/** + * Recalcula los precios de una compra + * + * @param vBuyFk + */ + DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; + + CREATE TEMPORARY TABLE tmp.buyRecalc + SELECT vBuyFk id; + + CALL buy_recalcPrices(); + + DROP TEMPORARY TABLE tmp.buyRecalc; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_recalcPricesByEntry.sql b/db/routines/vn/procedures/buy_recalcPricesByEntry.sql new file mode 100644 index 000000000..db0fc0690 --- /dev/null +++ b/db/routines/vn/procedures/buy_recalcPricesByEntry.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPricesByEntry`(IN vEntryFk INT(11)) +BEGIN +/** + * Recalcula los precios de una entrada + * + * @param vEntryFk + */ + DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; + + CREATE TEMPORARY TABLE tmp.buyRecalc + SELECT b.id + FROM buy b + WHERE b.entryFk = vEntryFk; + + CALL buy_recalcPrices(); + + DROP TEMPORARY TABLE tmp.buyRecalc; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_scan.sql b/db/routines/vn/procedures/buy_scan.sql new file mode 100644 index 000000000..0d4e8fcdb --- /dev/null +++ b/db/routines/vn/procedures/buy_scan.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_scan`(vBarcode VARCHAR(512)) +BEGIN +/** + * Busca compras a partir de un código de barras de subasta, las marca como + * escaneadas y como etiquetas impresas y las devuelve. + * + * @param vBarcode Código de compra de una etiqueta de subasta + * @select (buy, do_photo) Identificadores de compra escaneados + */ + CALL edi.ekt_scan(vBarcode); + + DROP TEMPORARY TABLE IF EXISTS tBuy; + CREATE TEMPORARY TABLE tBuy + SELECT id buyFk + FROM vn.buy b + LIMIT 0; + + INSERT INTO tBuy(buyFk) + SELECT b.id + FROM buy b + JOIN tmp.ekt t ON t.ektFk = b.ektFk + JOIN vn.entry en ON en.id = b.entryFk + JOIN vn.travel tr ON tr.id = en.travelFk + JOIN vn.warehouse w ON w.id = tr.warehouseInFk + JOIN vn.country c ON c.id = w.countryFk AND c.code = 'NL'; + + SELECT b.id buy, i.doPhoto do_photo, b.stickers - CAST(b.printedStickers AS INT) stickersToPrint + FROM tBuy tb + JOIN vn.buy b ON tb.buyFk = b.id + JOIN vn.item i ON i.id = b.itemFk; + + UPDATE vn.buy b + JOIN tBuy tb ON tb.buyFk = b.id + SET b.printedStickers = b.stickers; + + DROP TEMPORARY TABLE tmp.ekt, tBuy; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_updateGrouping.sql b/db/routines/vn/procedures/buy_updateGrouping.sql new file mode 100644 index 000000000..fb7adc0a3 --- /dev/null +++ b/db/routines/vn/procedures/buy_updateGrouping.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_updateGrouping`(vWarehouseFk INT, vItemFk INT, vGrouping INT) +BEGIN +/** + * Actualiza el grouping de las últimas compras de un artículo + * + * @param vWarehouseFk Id del almacén + * @param vItemFk Id del Artículo + * @param vGrouping Cantidad de grouping + */ + CALL vn.buyUltimate(vWarehouseFk, util.VN_CURDATE()); + + UPDATE vn.buy b + JOIN tmp.buyUltimate bu ON b.id = bu.buyFk + SET b.`grouping` = vGrouping + WHERE bu.warehouseFk = vWarehouseFk + AND bu.itemFk = vItemFk; + + DROP TEMPORARY TABLE tmp.buyUltimate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buy_updatePacking.sql b/db/routines/vn/procedures/buy_updatePacking.sql new file mode 100644 index 000000000..d86edc98f --- /dev/null +++ b/db/routines/vn/procedures/buy_updatePacking.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_updatePacking`(vWarehouseFk INT, vItemFk INT, vPacking INT) +BEGIN +/** + * Actualiza packing + * + * @param vWarehouseFk warehouse del item + * @param vItemFk id del item + * @param vPacking packing a actualizar + */ + CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); + + UPDATE buy b + JOIN tmp.buyUltimate bu ON b.id = bu.buyFk + SET b.packing = vPacking + WHERE bu.warehouseFk = vWarehouseFk + AND bu.itemFk = vItemFk; + + DROP TEMPORARY TABLE tmp.buyUltimate; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_calcFromItem.sql b/db/routines/vn/procedures/catalog_calcFromItem.sql new file mode 100644 index 000000000..aeeaccb08 --- /dev/null +++ b/db/routines/vn/procedures/catalog_calcFromItem.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_calcFromItem`( + vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT, + vItemFk INT) +BEGIN +/** + * Calculates available and price for a single item. + * + * @param vItemFk The item id + * @return tmp.ticketCalculateItem + * @return tmp.ticketComponentPrice + * @return tmp.ticketComponent + * @return tmp.ticketLot + * @return tmp.zoneGetShipped + */ + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + ENGINE = MEMORY + SELECT vItemFk itemFk; + + CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); + DROP TEMPORARY TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_calculate.sql b/db/routines/vn/procedures/catalog_calculate.sql new file mode 100644 index 000000000..698328770 --- /dev/null +++ b/db/routines/vn/procedures/catalog_calculate.sql @@ -0,0 +1,186 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_calculate`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) +BEGIN +/** + * Calcula los articulos disponibles y sus precios + * + * @table tmp.item(itemFk) Listado de artículos a calcular + * @param vLanded Fecha de recepcion de mercancia + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id de la agencia + * @return tmp.ticketCalculateItem(itemFk, available, producer, + * item, size, stems, category, inkFk, image, origin, price) + * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk) + * @return tmp.ticketComponent + * @return tmp.ticketComponentPrice + */ + DECLARE vAvailableCalc INT; + DECLARE vAvailableNoRaidsCalc INT; + DECLARE vShipped DATE; + DECLARE vWarehouseFk SMALLINT; + DECLARE vZoneFk INT; + DECLARE vDone BOOL; + DECLARE cTravelTree CURSOR FOR + SELECT zoneFk, warehouseFk, shipped FROM tmp.zoneGetShipped; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; + CREATE TEMPORARY TABLE tmp.ticketLot( + `warehouseFk` smallint(5) unsigned NOT NULL, + `itemFk` int(11) NOT NULL, + `available` double DEFAULT NULL, + `buyFk` int(11) DEFAULT NULL, + `fix` tinyint(3) unsigned DEFAULT '0', -- este campo parece obsoleto + `zoneFk` int(11) NOT NULL, + KEY `itemFk` (`itemFk`), + KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH + ) ENGINE=MEMORY DEFAULT CHARSET=utf8; + + CALL catalog_componentPrepare(); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem; + CREATE TEMPORARY TABLE tmp.ticketCalculateItem( + itemFk INT(11) NOT NULL, + available INT(11), + producer VARCHAR(50), + item VARCHAR(50), + size INT(10) UNSIGNED, + stems INT(11), + category VARCHAR(3), + inkFk VARCHAR(3), + image VARCHAR(50), + origin VARCHAR(3), + price DECIMAL(10,2), + priceKg DECIMAL(10,2), + `grouping` INT(10) UNSIGNED, + PRIMARY KEY `itemFk` (`itemFk`) + ) ENGINE = MEMORY DEFAULT CHARSET=utf8; + + OPEN cTravelTree; + + l: LOOP + SET vDone = FALSE; + FETCH cTravelTree INTO vZoneFk, vWarehouseFk, vShipped; + + IF vDone THEN + LEAVE l; + END IF; + + CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped); + CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped); + CALL vn.buyUltimate(vWarehouseFk, vShipped); + + INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk) + SELECT vWarehouseFk, + a.item_id, + IFNULL(a.available, 0), + bu.buyFk, + vZoneFk + FROM `cache`.available a + LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id + AND anr.calc_id = vAvailableNoRaidsCalc + JOIN tmp.item i ON i.itemFk = a.item_id + JOIN vn.item it ON it.id = i.itemFk + JOIN vn.`zone` z ON z.id = vZoneFk + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id + LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk + LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + LEFT JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed + FROM vn.addressFilter af + JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed + FROM vn.address ad + JOIN vn.province p ON p.id = ad.provinceFk + WHERE ad.id = vAddressFk + ) sub2 ON sub2.provinceFk <=> IFNULL(af.provinceFk, sub2.provinceFk) + AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk) + AND sub2.isLogifloraAllowed <=> IFNULL(af.isLogifloraAllowed, sub2.isLogifloraAllowed) + WHERE vWarehouseFk = af.warehouseFk + AND (vShipped < af.beforeDated + OR ISNULL(af.beforeDated) + OR vShipped > af.afterDated + OR ISNULL(af.afterDated)) + ) sub ON sub.isVNHSupplier = v.isVNHSupplier + AND (sub.isEarlyBird = mp.isEarlyBird OR ISNULL(sub.isEarlyBird)) + JOIN vn.agencyMode am ON am.id = vAgencyModeFk + JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN vn.itemType itt ON itt.id = it.typeFk + JOIN vn.itemCategory itc on itc.id = itt.categoryFk + JOIN vn.address ad ON ad.id = vAddressFk + LEFT JOIN vn.clientItemType cit + ON cit.clientFk = ad.clientFk + AND cit.itemTypeFk = itt.id + LEFT JOIN vn.zoneItemType zit + ON zit.zoneFk = vZoneFk + AND zit.itemTypeFk = itt.id + LEFT JOIN vn.agencyModeItemType ait + ON ait.agencyModeFk = vAgencyModeFk + AND ait.itemTypeFk = itt.id + WHERE a.calc_id = vAvailableCalc + AND a.available > 0 + AND (sub.itemAllowed OR NOT it.isFloramondo OR anr.available > 0) + AND (ag.isAnyVolumeAllowed OR NOT itt.isUnconventionalSize) + AND (itc.isReclining OR it.`size` IS NULL OR it.`size` < z.itemMaxSize OR z.itemMaxSize IS NULL) + AND cit.id IS NULL + AND zit.id IS NULL + AND ait.id IS NULL; + + DROP TEMPORARY TABLE tmp.buyUltimate; + + CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + INSERT INTO tmp.ticketCalculateItem ( + itemFk, + available, + producer, + item, + size, + stems, + category, + inkFk, + image, + origin, + price, + priceKg, + `grouping`) + SELECT + tl.itemFk, + SUM(tl.available) available, + p.name producer, + i.name item, + i.size size, + i.stems, + i.category, + i.inkFk, + i.image, + o.code origin, + bl.price, + bl.priceKg, + bl.`grouping` + FROM tmp.ticketLot tl + JOIN item i ON tl.itemFk = i.id + LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible + JOIN origin o ON o.id = i.originFk + JOIN ( + SELECT price, itemFk, priceKg, MIN(`grouping`) `grouping` + FROM ( + SELECT price, itemFk, priceKg, `grouping` + FROM tmp.ticketComponentPrice + WHERE warehouseFk = vWarehouseFk + ORDER BY (rate = 2) DESC, price + LIMIT 10000000000000000000 + ) sub + GROUP BY itemFk + ) bl ON bl.itemFk = tl.itemFk + WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk + GROUP BY tl.itemFk + ON DUPLICATE KEY UPDATE available = available + VALUES(available); + + END LOOP; + + CLOSE cTravelTree; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql new file mode 100644 index 000000000..64bb74430 --- /dev/null +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -0,0 +1,294 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_componentCalculate`( + vZoneFk INT, + vAddressFk INT, + vShipped DATE, + vWarehouseFk INT +) +BEGIN +/** + * Calcula los componentes de los articulos de tmp.ticketLot + * + * @param vZoneFk para calcular el transporte + * @param vAddressFk Consignatario + * @param vShipped dia de salida del pedido + * @param vWarehouseFk warehouse de salida del pedido + * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) + * @table tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + * + * @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg) + */ + DECLARE vClientFk INT; + DECLARE vVNHWarehouseFk INT DEFAULT 7; + + SELECT clientFk INTO vClientFK + FROM address + WHERE id = vAddressFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate + (PRIMARY KEY (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT tl.itemFk, + tl.warehouseFk, + tl.available, + IF(i.hasMinPrice, GREATEST(i.minPrice,IFNULL(pf.rate2, b.price2)),IFNULL(pf.rate2, b.price2)) rate2, + IF(i.hasMinPrice, GREATEST(i.minPrice,IFNULL(pf.rate3, b.price3)),IFNULL(pf.rate3, b.price3)) rate3, + IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing, + IFNULL(pf.`grouping`, b.`grouping`) `grouping`, + ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, + tl.buyFk, + i.typeFk, + IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping + FROM tmp.ticketLot tl + JOIN buy b ON b.id = tl.buyFk + JOIN item i ON i.id = tl.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN specialPrice sp ON sp.itemFk = i.id + AND sp.clientFk = vClientFk + LEFT JOIN ( + SELECT * FROM ( + SELECT pf.itemFk, + pf.`grouping`, + pf.packing, + pf.box, + pf.rate2, + pf.rate3, + zw.warehouseFk + FROM priceFixed pf + JOIN zoneWarehouse zw ON zw.zoneFk = vZoneFk + AND zw.warehouseFk IN (pf.warehouseFk,0) + WHERE vShipped BETWEEN pf.started AND pf.ended + ORDER BY pf.itemFk, pf.warehouseFk DESC + LIMIT 10000000000000000000 + ) tpf + GROUP BY tpf.itemFk, tpf.warehouseFk + ) pf ON pf.itemFk = tl.itemFk + AND pf.warehouseFk = tl.warehouseFk + WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 + AND ic.merchandise + AND tl.zoneFk = vZoneFk + AND tl.warehouseFk = vWarehouseFk; + + -- Coste + INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT tcc.warehouseFk, + tcc.itemFk, + c2.id, + b.buyingValue + b.freightValue + b.packageValue + b.comissionValue + FROM tmp.ticketComponentCalculate tcc + JOIN vn.component c2 ON c2.code = 'purchaseValue' + JOIN buy b ON b.id = tcc.buyFk; + + -- Margen + INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT tcc.warehouseFk, + tcc.itemFk, + c2.id, + tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue + FROM tmp.ticketComponentCalculate tcc + JOIN vn.component c2 ON c2.code = 'margin' + JOIN buy b ON b.id = tcc.buyFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY + SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk + FROM tmp.ticketComponent tc + JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk + GROUP BY tc.itemFk, warehouseFk; + + -- RECOBRO + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT tcb.warehouseFk, tcb.itemFk, c2.id, + ROUND(tcb.base * + LEAST( + MAX(GREATEST(IFNULL(cr.priceIncreasing,0), + IFNULL(cr1.priceIncreasing,0), + IFNULL(cr2.priceIncreasing,0)) + ), + cc.maxPriceIncreasingRatio), + 3) + FROM tmp.ticketComponentBase tcb + JOIN vn.component c2 ON c2.code = 'debtCollection' + JOIN vn.clientConfig cc + JOIN claimRatio cr ON cr.clientFk = vClientFk + LEFT JOIN clientYoke cy1 ON cy1.leftOx = cr.clientFk + LEFT JOIN claimRatio cr1 ON cr1.clientFk = cy1.rightOx + LEFT JOIN clientYoke cy2 ON cy2.rightOx = cr.clientFk + LEFT JOIN claimRatio cr2 ON cr2.clientFk = cy2.leftOx + WHERE GREATEST( + IFNULL(cr.priceIncreasing,0), + IFNULL(cr1.priceIncreasing,0), + IFNULL(cr2.priceIncreasing,0)) > 0.009 + GROUP BY tcb.itemFk; + + -- Mana auto + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT tcb.warehouseFk, + tcb.itemFk, + c2.id, + ROUND(base * wm.pricesModifierRate, 3) manaAuto + FROM tmp.ticketComponentBase tcb + JOIN `client` c on c.id = vClientFk + JOIN workerMana wm ON c.salesPersonFk = wm.workerFk + JOIN vn.component c2 ON c2.code = 'autoMana' + WHERE wm.isPricesModifierActivated + HAVING manaAuto <> 0; + + -- Precios especiales + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT tcb.warehouseFk, + tcb.itemFk, + c2.id, + GREATEST( + IFNULL(ROUND(tcb.base * c2.tax, 4), 0), + IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3 + ) cost + FROM tmp.ticketComponentBase tcb + JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount' + JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk + LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk + JOIN vn.item i ON i.id = tcb.itemFk + WHERE sp.value IS NULL + AND i.supplyResponseFk IS NULL; + + -- Individual + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT tcb.warehouseFk, + tcb.itemFk, + c2.id, + IFNULL(ROUND(tcb.base * c2.tax, 4), 0) cost + FROM tmp.ticketComponentBase tcb + JOIN vn.component c2 ON c2.code = 'individual' + JOIN vn.client c ON c.id = vClientFk + JOIN vn.businessType bt ON bt.code = c.businessTypeFk + WHERE bt.code = 'individual'; + + -- Venta por paquetes + INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) + SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 + FROM tmp.ticketComponentCalculate tcc + JOIN vn.component c2 ON c2.code = 'salePerPackage' + JOIN buy b ON b.id = tcc.buyFk + LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk + WHERE sp.value IS NULL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id)) + ENGINE = MEMORY + SELECT vZoneFk id; + + CALL zone_getOptionsForShipment(vShipped, TRUE); + + -- Reparto + INSERT INTO tmp.ticketComponent + SELECT tcc.warehouseFK, + tcc.itemFk, + c2.id, + z.inflation * ROUND(ic.cm3delivery * (IFNULL(zo.price,5000) - IFNULL(zo.bonus,0)) / (1000 * vc.standardFlowerBox) , 4) cost + FROM tmp.ticketComponentCalculate tcc + JOIN item i ON i.id = tcc.itemFk + JOIN tmp.zoneOption zo ON zo.zoneFk = vZoneFk + JOIN zone z ON z.id = vZoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN vn.volumeConfig vc + JOIN vn.component c2 ON c2.code = 'delivery' + LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk + AND ic.itemFk = tcc.itemFk + HAVING cost <> 0; + + DROP TEMPORARY TABLE tmp.zoneOption; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY + SELECT * FROM tmp.ticketComponent; + + -- Precio especial + INSERT INTO tmp.ticketComponent + SELECT tcc.warehouseFk, + tcc.itemFk, + c2.id, + sp.value - SUM(tcc.cost) sumCost + FROM tmp.ticketComponentCopy tcc + JOIN component c ON c.id = tcc.componentFk + JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk + JOIN vn.component c2 ON c2.code = 'specialPrices' + WHERE c.classRate IS NULL + AND tcc.warehouseFk = vWarehouseFk + GROUP BY tcc.itemFk, tcc.warehouseFk + HAVING ABS(sumCost) > 0.001; + + -- Rappel + INSERT INTO tmp.ticketComponent + SELECT tcc.warehouseFk, + tcc.itemFk, + IFNULL(c.componentFk ,c2.id), + SUM(tcc.cost) * ((1/(1-c.rappel/100)) -1) sumCost + FROM tmp.ticketComponentCopy tcc + JOIN vn.clientChain cc ON cc.clientFk = vClientFk + JOIN vn.`chain` c ON c.id = cc.chainFk + JOIN vn.component c2 ON c2.code = 'rappel' + WHERE tcc.warehouseFk = vWarehouseFk + GROUP BY tcc.itemFk, tcc.warehouseFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentSum + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT SUM(cost) sumCost, tc.itemFk, tc.warehouseFk, c.classRate + FROM tmp.ticketComponent tc + JOIN component c ON c.id = tc.componentFk + GROUP BY tc.itemFk, tc.warehouseFk, c.classRate; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY + SELECT tcc.warehouseFk, + tcc.itemFk, + 1 rate, + IF(tcc.groupingMode = 1, tcc.`grouping`, 1) `grouping`, + CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price, + CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg + FROM tmp.ticketComponentCalculate tcc + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + AND tcs.warehouseFk = tcc.warehouseFk + WHERE IFNULL(tcs.classRate, 1) = 1 + AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0) + GROUP BY tcs.warehouseFk, tcs.itemFk; + + INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg) + SELECT tcc.warehouseFk, + tcc.itemFk, + 2 rate, + tcc.packing `grouping`, + SUM(tcs.sumCost) price, + SUM(tcs.sumCost) / weightGrouping priceKg + FROM tmp.ticketComponentCalculate tcc + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + AND tcs.warehouseFk = tcc.warehouseFk + WHERE tcc.available IS NULL + OR (IFNULL(tcs.classRate, 2) = 2 + AND tcc.packing > 0 AND tcc.available >= tcc.packing) + GROUP BY tcs.warehouseFk, tcs.itemFk; + + INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, `grouping`, price, priceKg) + SELECT tcc.warehouseFk, + tcc.itemFk, + 3 rate, + tcc.available `grouping`, + SUM(tcs.sumCost) price, + SUM(tcs.sumCost) / weightGrouping priceKg + FROM tmp.ticketComponentCalculate tcc + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + AND tcs.warehouseFk = tcc.warehouseFk + WHERE IFNULL(tcs.classRate, 3) = 3 + GROUP BY tcs.warehouseFk, tcs.itemFk; + + INSERT INTO tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg) + SELECT * FROM ( + SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 + ) t + GROUP BY itemFk, warehouseFk, `grouping`; + + DROP TEMPORARY TABLE + tmp.ticketComponentCalculate, + tmp.ticketComponentSum, + tmp.ticketComponentBase, + tmp.ticketComponentRate, + tmp.ticketComponentCopy; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_componentPrepare.sql b/db/routines/vn/procedures/catalog_componentPrepare.sql new file mode 100644 index 000000000..2e58a28e2 --- /dev/null +++ b/db/routines/vn/procedures/catalog_componentPrepare.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_componentPrepare`() +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent ( + `warehouseFk` INT UNSIGNED NOT NULL, + `itemFk` INT NOT NULL, + `componentFk` INT UNSIGNED NOT NULL, + `cost` DECIMAL(10,4) NOT NULL, + INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), + UNIQUE `fkItemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC) + )ENGINE=MEMORY DEFAULT CHARSET=utf8; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice; + CREATE TEMPORARY TABLE tmp.ticketComponentPrice ( + `warehouseFk` INT UNSIGNED NOT NULL, + `itemFk` INT NOT NULL, + `rate` INT NOT NULL, + `grouping` INT UNSIGNED NOT NULL, + `price` DECIMAL(10,4) NOT NULL, + `priceKg` DECIMAL(10,4), + INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), + UNIQUE `fkItemWarehouseRate` (`itemFk` ASC, `warehouseFk` ASC, `rate` ASC) + )ENGINE=MEMORY DEFAULT CHARSET=utf8; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/catalog_componentPurge.sql b/db/routines/vn/procedures/catalog_componentPurge.sql new file mode 100644 index 000000000..c6a19ba62 --- /dev/null +++ b/db/routines/vn/procedures/catalog_componentPurge.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`catalog_componentPurge`() +BEGIN + DROP TEMPORARY TABLE + tmp.ticketComponentPrice, + tmp.ticketComponent, + tmp.ticketLot; +END$$ +DELIMITER ; diff --git a/db/.archive/230201/00-kkearSaleChecked.sql b/db/routines/vn/procedures/clean.sql similarity index 83% rename from db/.archive/230201/00-kkearSaleChecked.sql rename to db/routines/vn/procedures/clean.sql index 3ea107da5..1734bea98 100644 --- a/db/.archive/230201/00-kkearSaleChecked.sql +++ b/db/routines/vn/procedures/clean.sql @@ -1,25 +1,24 @@ -DELETE FROM `salix`.`ACL` WHERE model="SaleChecked"; -DROP TABLE IF EXISTS `vn`.`saleChecked`; -DROP PROCEDURE IF EXISTS `vn`.`clean`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean`() BEGIN DECLARE vDateShort DATETIME; DECLARE vOneYearAgo DATE; DECLARE vFourYearsAgo DATE; + DECLARE vFiveYearsAgo DATE; DECLARE v18Month DATE; DECLARE v26Month DATE; DECLARE v3Month DATE; DECLARE vTrashId VARCHAR(15); + DECLARE v5Years DATE; SET vDateShort = util.VN_CURDATE() - INTERVAL 2 MONTH; SET vOneYearAgo = util.VN_CURDATE() - INTERVAL 1 YEAR; SET vFourYearsAgo = util.VN_CURDATE() - INTERVAL 4 YEAR; + SET vFiveYearsAgo = util.VN_CURDATE() - INTERVAL 5 YEAR; SET v18Month = util.VN_CURDATE() - INTERVAL 18 MONTH; SET v26Month = util.VN_CURDATE() - INTERVAL 26 MONTH; SET v3Month = util.VN_CURDATE() - INTERVAL 3 MONTH; + SET v5Years = util.VN_CURDATE() - INTERVAL 5 YEAR; DELETE FROM ticketParking WHERE created < vDateShort; DELETE FROM routesMonitor WHERE dated < vDateShort; @@ -35,13 +34,18 @@ BEGIN DELETE FROM sms WHERE created < v18Month; DELETE FROM saleTracking WHERE created < vOneYearAgo; DELETE FROM ticketTracking WHERE created < v18Month; - DELETE tobs FROM ticketObservation tobs + DELETE tobs FROM ticketObservation tobs JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo; DELETE FROM sharingCart where ended < vDateShort; DELETE FROM sharingClient where ended < vDateShort; DELETE tw.* FROM ticketWeekly tw - LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL; + LEFT JOIN sale s ON s.ticketFk = tw.ticketFk + LEFT JOIN ticketRequest tr ON tr.ticketFk = tw.ticketFk + LEFT JOIN ticketService ts ON ts.ticketFk = tw.ticketFk + WHERE s.id IS NULL + AND tr.id IS NULL + AND ts.id IS NULL; DELETE FROM claim WHERE ticketCreated < vFourYearsAgo; DELETE FROM message WHERE sendDate < vDateShort; -- Robert ubicacion anterior de trevelLog comentario para debug @@ -52,12 +56,14 @@ BEGIN JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk WHERE t.landed <= vDateShort; - DELETE FROM vn.buy WHERE created < vDateShort AND entryFk = 9200; + DELETE b FROM vn.buy b + JOIN vn.entryConfig e ON e.defaultEntry = b.entryFk + WHERE b.created < vDateShort; DELETE FROM vn.itemShelvingLog WHERE created < vDateShort; DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort; DELETE FROM vn.itemCleanLog WHERE created < util.VN_NOW() - INTERVAL 1 YEAR; DELETE FROM printQueue WHERE statusCode = 'printed' AND created < vDateShort; - + DELETE FROM ticketLog WHERE creationDate <= vFiveYearsAgo; -- Equipos duplicados DELETE w.* FROM workerTeam w @@ -80,7 +86,7 @@ BEGIN c.created < vDateShort; DELETE FROM vn.expeditionTruck - WHERE ETD < v3Month; + WHERE eta < v3Month; -- borrar travels sin entradas DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; @@ -107,12 +113,12 @@ BEGIN FROM vn.travel t LEFT JOIN vn.entry e ON e.travelFk = t.id WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; - + UPDATE dms d - JOIN dmsType dt ON dt.id = d.dmsTypeFk - SET d.dmsTypeFk = vTrashId + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, util.VN_CURDATE()); - + -- borrar entradas sin compras DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; CREATE TEMPORARY TABLE tmp.entryToDelete @@ -131,9 +137,9 @@ BEGIN CREATE TEMPORARY TABLE tmp.routeToDelete SELECT * FROM vn.route r - WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); + WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); - UPDATE tmp.routeToDelete tmp + UPDATE tmp.routeToDelete tmp JOIN vn.dms d ON d.id = tmp.gestdocFk SET d.dmsTypeFk = vTrashId; @@ -146,7 +152,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.duaToDelete SELECT * FROM vn.dua - WHERE operated < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + WHERE operated < TIMESTAMPADD(YEAR,-2,CURDATE()); UPDATE tmp.duaToDelete tm JOIN vn.dms d ON d.id = tm.gestdocFk @@ -169,5 +175,10 @@ BEGIN CALL shelving_clean; + DELETE FROM chat WHERE dated < v5Years; + + DELETE tt FROM ticketTracking tt JOIN vn.ticket t ON tt.ticketFk = t.id + WHERE t.shipped <= vDateShort; + END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/clean_logiflora.sql b/db/routines/vn/procedures/clean_logiflora.sql new file mode 100644 index 000000000..dd08410fd --- /dev/null +++ b/db/routines/vn/procedures/clean_logiflora.sql @@ -0,0 +1,81 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean_logiflora`() +BEGIN +/** + * Elimina las compras y los artículos residuales de logiflora. + */ + DECLARE vDone INT DEFAULT FALSE; + DECLARE vBuyFk INT; + DECLARE vItemFk INT; + + DECLARE cur1 CURSOR FOR SELECT id FROM tBuy; + DECLARE cur2 CURSOR FOR SELECT id FROM tItem; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + CREATE OR REPLACE TEMPORARY TABLE tBuy + ENGINE = MEMORY + SELECT b.id + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN agencyMode am ON am.id = tr.agencyModeFk + WHERE NOT b.quantity + AND am.code = 'logiflora' + AND e.isRaid; + + START TRANSACTION; + + OPEN cur1; + read_loop: LOOP + SET vDone = FALSE; + FETCH cur1 INTO vBuyFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + DELETE FROM buy WHERE id = vBuyFk; + END LOOP; + CLOSE cur1; + + CREATE OR REPLACE TEMPORARY TABLE tItem + ENGINE = MEMORY + SELECT DISTINCT i.id + FROM item i + LEFT JOIN hedera.orderRow o ON o.itemFk = i.id + LEFT JOIN sale s ON s.itemFk = i.id + LEFT JOIN buy b ON b.itemFk = i.id + LEFT JOIN bs.waste w ON w.itemFk = i.id + WHERE i.supplyResponseFk + AND o.id IS NULL + AND b.id IS NULL + AND s.id IS NULL + AND w.itemFk IS NULL + AND i.created < (util.VN_CURDATE() - INTERVAL (SELECT daysToKeepItem FROM floramondoConfig) DAY); + + OPEN cur2; + read_loop: LOOP + SET vDone = FALSE; + + FETCH cur2 INTO vItemFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + DELETE FROM item WHERE id = vItemFk; + END LOOP; + CLOSE cur2; + + COMMIT; + + DROP TEMPORARY TABLE tBuy, tItem; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clearShelvingList.sql b/db/routines/vn/procedures/clearShelvingList.sql new file mode 100644 index 000000000..dbaca2747 --- /dev/null +++ b/db/routines/vn/procedures/clearShelvingList.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clearShelvingList`(vShelvingFk VARCHAR(8)) +BEGIN + UPDATE vn.itemShelving + SET visible = 0 + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk COLLATE utf8_unicode_ci; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientDebtSpray.sql b/db/routines/vn/procedures/clientDebtSpray.sql new file mode 100644 index 000000000..687c08fe2 --- /dev/null +++ b/db/routines/vn/procedures/clientDebtSpray.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientDebtSpray`(vClientFk INT) +BEGIN + + /* Reparte el saldo de un cliente en greuge en la cartera que corresponde, y desasigna el comercial + * + * + */ + + DECLARE vClientDebt DOUBLE; + + SELECT vn.client_getDebt(vClientFk, util.VN_CURDATE()) INTO vClientDebt; + + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) + VALUES (vClientFk, 'Saldo pendiente', vClientDebt, util.VN_CURDATE(), 5); + + CALL vn.clientGreugeSpray(vClientFk, TRUE, '', TRUE); + + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) + SELECT vClientFk, 'Liquidación cliente', sum(amount), util.VN_CURDATE(), 5 + FROM vn.greuge + WHERE clientFk = vClientFk; + + UPDATE vn.client + SET salesPersonFk = NULL + WHERE id = vClientFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientFreeze.sql b/db/routines/vn/procedures/clientFreeze.sql new file mode 100644 index 000000000..c89db2316 --- /dev/null +++ b/db/routines/vn/procedures/clientFreeze.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientFreeze`() +BEGIN +/** + * Congela diariamente aquellos clientes que son morosos sin recobro, + * pero que no sean trabajadores, + * y que el riesgo no sea menor que cero + * hasta que no se gire la remesa no se congelan a los clientes de giro + */ + DECLARE vIsRemittanced BOOLEAN; + + SELECT id into vIsRemittanced + FROM receipt + WHERE invoiceFk LIKE 'REMESA%' + AND payed > util.firstDayOfMonth(util.VN_CURDATE()) + LIMIT 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + (INDEX (clientFk)) + SELECT clientFk + FROM bs.defaulter + WHERE created = util.VN_CURDATE() + AND amount; + + CALL client_getDebt(util.VN_CURDATE()); + + UPDATE client c + JOIN bi.defaulters d ON d.client = c.id AND d.date = util.VN_CURDATE() + JOIN config ON TRUE + LEFT JOIN recovery r ON r.clientFk = c.id AND r.finished IS NULL + LEFT JOIN payMethod pm ON pm.id = c.payMethodFk + LEFT JOIN tmp.risk rk ON rk.clientFk = c.id + SET c.isFreezed = TRUE, + d.frozened = util.VN_CURDATE() + WHERE (d.amount > config.defaultersMaxAmount + AND rk.risk > 0) + AND c.typeFk = 'normal' + AND r.id IS NULL + AND (vIsRemittanced OR pm.code <> 'bankDraft'); + + DROP TEMPORARY TABLE tmp.clientGetDebt; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientGetDebtDiary.sql b/db/routines/vn/procedures/clientGetDebtDiary.sql new file mode 100644 index 000000000..bd7a0b292 --- /dev/null +++ b/db/routines/vn/procedures/clientGetDebtDiary.sql @@ -0,0 +1,117 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientGetDebtDiary`(vClientFK INT, vCompanyFk INT) +BEGIN +/** + * Devuelve el registro de deuda + * + * @param vClientFK Id del cliente + * @param vCompanyFk Id de la empresa + */ + DECLARE vDone BOOL; + DECLARE vDate DATETIME; + DECLARE vTotalBalance DOUBLE DEFAULT 0.00; + DECLARE vCreated DATETIME; + DECLARE vIssued DATETIME; + DECLARE vBalance DOUBLE DEFAULT 0.00; + DECLARE cur CURSOR FOR + SELECT + created, + issued, + ROUND(amount, 2) AS balance + FROM invoiceOut + WHERE clientFk = vClientFk AND companyFk = vCompanyFk + UNION ALL + SELECT + created, + payed, + ROUND(-1 * amountPaid, 2) AS balance + FROM receipt + WHERE clientFk = vClientFk AND companyFk = vCompanyFk + ORDER BY issued, created; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + + proc: LOOP + SET vDone = FALSE; + + FETCH cur INTO vCreated, vIssued, vBalance; + + IF vDate IS NULL THEN + SET vDate=vIssued; + END IF; + + IF vDone THEN + LEAVE proc; + END IF; + + SET vTotalBalance = vTotalBalance + vBalance; + + IF CAST(ABS(vTotalBalance) AS UNSIGNED) = 0 THEN + SET vDate = vIssued; + SET vDone = TRUE; + END IF; + END LOOP; + + CLOSE cur; + + SELECT + issued, + CAST(debtOut AS DECIMAL(10,2)) debtOut, + CAST(debtIn AS DECIMAL(10,2)) debtIn, + ref, + companyFk, + priority + FROM + (SELECT + NULL AS issued, + SUM(amountUnpaid) AS debtOut, + NULL AS debtIn, + 'Saldo Anterior' AS ref, + companyFk, + 0 as priority + FROM + (SELECT SUM(amount) AS amountUnpaid, companyFk, 0 + FROM invoiceOut + WHERE clientFk = vClientFK + AND issued < vDate + GROUP BY companyFk + + UNION ALL + + SELECT SUM(-1 * amountPaid), companyFk, 0 + FROM receipt + WHERE clientFk = vClientFK + AND payed < vDate + GROUP BY companyFk) AS transactions + GROUP BY companyFk + + UNION ALL + + SELECT + issued, + amount as debtOut, + NULL AS debtIn, + ref, + companyFk, + 1 + FROM invoiceOut + WHERE clientFk = vClientFK + AND issued >= vDate + UNION ALL + + SELECT + r.payed, + NULL as debtOut, + r.amountPaid, + r.invoiceFk, + r.companyFk, + 0 + FROM receipt r + WHERE r.clientFk = vClientFK + AND r.payed >= vDate) t + INNER JOIN `client` c ON c.id = vClientFK + HAVING debtOut <> 0 OR debtIn <> 0 + ORDER BY issued, priority DESC, debtIn; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientGreugeSpray.sql b/db/routines/vn/procedures/clientGreugeSpray.sql new file mode 100644 index 000000000..c337e2dd3 --- /dev/null +++ b/db/routines/vn/procedures/clientGreugeSpray.sql @@ -0,0 +1,73 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientGreugeSpray`(IN vClientFk INT, IN onlyForHisOwner BOOL, IN vWorkerCode VARCHAR(3), IN vWithMana BOOLEAN) +BEGIN + + DECLARE vGreuge DECIMAL(10,2); + DECLARE vOwner INT; + DECLARE vTotalSale INT; + DECLARE vGreugeTypeFk INT DEFAULT 5; -- HERENCIA + DECLARE vGreugeTypeMana INT DEFAULT 3;-- Maná + DECLARE vMana DECIMAL(10,2); + + SELECT vn.clientGetMana(vClientFk) INTO vMana; + + IF vWithMana AND vMana THEN + + INSERT INTO vn.greuge( clientFk, + description, + amount, + shipped, + greugeTypeFk) + VALUES( vClientFk, + 'Desasignación', + -1 * vMana, + util.VN_CURDATE(), + vGreugeTypeMana); + + END IF; + + SELECT sum(amount) INTO vGreuge + FROM vn.greuge + WHERE clientFk = vClientFk; + + IF vGreuge != 0 THEN + + IF LENGTH(vWorkerCode) = 0 THEN + + SELECT salesPersonFk INTO vOwner + FROM vn.client + WHERE id = vClientFk; + + ELSE + + SELECT id INTO vOwner + FROM vn.worker + WHERE code = vWorkerCode COLLATE utf8_general_ci; + + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientList; + CREATE TEMPORARY TABLE tmp.clientList + SELECT DISTINCT t.clientFk, floor(cr.yearSale / 12) monthSale + FROM vn.ticket t + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.workerMana wm ON wm.workerFk = c.salesPersonFk + JOIN vn.claimRatio cr ON cr.clientFk = c.id + WHERE wm.workerFk = IF(onlyForHisOwner, vOwner, wm.workerFk) + AND t.shipped >= TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) + AND c.id != vClientFk + HAVING monthSale > 100; + + SELECT SUM(monthSale) INTO vTotalSale + FROM tmp.clientList; + + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) + SELECT clientFk, CONCAT('Cliente: ',vClientFk), vGreuge * monthSale / vTotalSale, util.VN_CURDATE(), vGreugeTypeFk + FROM tmp.clientList + UNION ALL + SELECT vClientFk, 'Reparto greuge', -vGreuge, util.VN_CURDATE(), vGreugeTypeFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientPackagingOverstock.sql b/db/routines/vn/procedures/clientPackagingOverstock.sql new file mode 100644 index 000000000..fcd34c41b --- /dev/null +++ b/db/routines/vn/procedures/clientPackagingOverstock.sql @@ -0,0 +1,92 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientPackagingOverstock`(vClientFk INT, vGraceDays INT) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.clientPackagingOverstock; + CREATE TEMPORARY TABLE tmp.clientPackagingOverstock + ENGINE = MEMORY + SELECT itemFk, + sum(GotfromClient) - sum(SenttoClient) as devueltos, + sum(InvoicedtoClient) - sum(InvoicedfromClient) as facturados, + LEAST( + sum(GotfromClient) - sum(SenttoClient), + sum(InvoicedtoClient) - sum(InvoicedfromClient) + ) as abonables + FROM + ( + SELECT t.*, + IF(@month = month, 0, 1) monthEnd, + @month := month + FROM + ( + SELECT x.id as ticketFk, + date(x.shipped) as shipped, + x.itemFk, + IFNULL(cast(sum(x.InvoicedtoClient) as DECIMAL(10,0)),0) InvoicedtoClient, + IFNULL(cast(sum(x.InvoicedfromClient) as DECIMAL(10,0)),0) InvoicedfromClient, + IFNULL(cast(sum(x.SenttoClient) as DECIMAL(10,0)),0) SenttoClient, + IFNULL(cast(sum(x.GotfromClient) as DECIMAL(10,0)),0) GotfromClient, + i.name as concept, + x.refFk as invoice, + month(shipped) month, + x.companyFk + FROM + ( + SELECT t.id, + t.shipped, + IFNULL(pe.equivalentFk, s.itemFk) itemFk, + IF(s.quantity > 0, s.quantity, NULL) InvoicedtoClient, + IF(s.quantity < 0, -s.quantity, NULL) InvoicedfromClient, + NULL SenttoClient, + NULL GotfromClient, + t.refFk, + @month := 0 month, + t.companyFk + FROM sale s + JOIN ticket t on t.id = s.ticketFk + JOIN packaging p ON p.itemFk = s.itemFk + LEFT JOIN packageEquivalentItem pe ON pe.itemFk = s.itemFk + WHERE t.clientFk = vClientFk + AND t.shipped > '2017-11-30' + AND p.isPackageReturnable + UNION ALL + SELECT NULL, + '2017-11-30', + IFNULL(pe.equivalentFk, tps.itemFk) itemFk, + tps.sent InvoicedtoClient, + tps.returned InvoicedfromClient, + NULL SenttoClient, + NULL GotfromClient, + 'Histórico', + NULL, + NULL + FROM ticketPackagingStartingStock tps + LEFT JOIN packageEquivalentItem pe ON pe.itemFk = tps.itemFk + WHERE tps.clientFk = vClientFk + AND tps.isForgetable = FALSE + UNION ALL + SELECT t.id, + t.shipped, + IFNULL(pe.equivalentFk, p.itemFk) itemFk, + NULL, + NULL, + IF(tp.quantity > 0 AND t.shipped <= TIMESTAMPADD(DAY, - vGraceDays, CURDATE()), tp.quantity, NULL) SenttoClient, + IF(tp.quantity < 0, -tp.quantity, NULL) GotfromClient, + NULL AS refFk, + NULL, + t.companyFk + FROM ticketPackaging tp + JOIN ticket t on t.id = tp.ticketFk + JOIN packaging p ON p.id = tp.packagingFk + LEFT JOIN packageEquivalentItem pe ON pe.itemFk = p.itemFk + WHERE t.clientFk = vClientFk + AND t.shipped > '2017-11-21' ) x + + JOIN item i ON x.itemFk = i.id + GROUP BY x.id, x.itemFk + ) t + ORDER BY itemFk, shipped DESC + LIMIT 10000000000000000000 + ) t2 + GROUP BY itemFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientPackagingOverstockReturn.sql b/db/routines/vn/procedures/clientPackagingOverstockReturn.sql new file mode 100644 index 000000000..ac37bbc8d --- /dev/null +++ b/db/routines/vn/procedures/clientPackagingOverstockReturn.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientPackagingOverstockReturn`(vClientFk INT, vGraceDays INT) +BEGIN + DECLARE vNewTicket INT DEFAULT 0; + DECLARE vWarehouseFk INT; + + CALL vn.clientPackagingOverstock(vClientFk,vGraceDays); + + SELECT id INTO vWarehouseFk + FROM vn.warehouse + WHERE hasConfectionTeam; + + CALL vn.ticket_add( + vClientFk + ,CURDATE() + ,vWarehouseFk -- Algemesi + ,442 -- Verdnatura + ,NULL -- address + ,NULL -- agencia + ,NULL -- route + ,CURDATE() + ,account.myUser_getId() + ,TRUE + ,vNewTicket); + + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) + SELECT vNewTicket, cpo.itemFk, - cpo.abonables, i.longName, p.price + FROM tmp.clientPackagingOverstock cpo + JOIN vn.item i ON i.id = cpo.itemFk + JOIN vn.packaging p ON p.itemFk = cpo.itemFk + WHERE cpo.abonables > 0; + INSERT INTO vn.ticketPackaging(ticketFk, packagingFk, quantity) + SELECT vNewTicket, p.id, cpo.abonables + FROM tmp.clientPackagingOverstock cpo + JOIN vn.packaging p ON p.itemFk = cpo.itemFk + WHERE cpo.abonables > 0; + + SELECT vNewTicket; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientRemoveWorker.sql b/db/routines/vn/procedures/clientRemoveWorker.sql new file mode 100644 index 000000000..15d247c67 --- /dev/null +++ b/db/routines/vn/procedures/clientRemoveWorker.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientRemoveWorker`() +BEGIN + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vClientFk INT; + DECLARE rs CURSOR FOR + SELECT c.clientFk + FROM tmp.clientGetDebt c + LEFT JOIN clientRisk r ON r.clientFk = c.clientFk + GROUP BY c.clientFk + HAVING SUM(IFNULL(r.amount,0)) = 0; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + SELECT cd.clientFk + FROM bs.clientDied cd + LEFT JOIN clientProtected cp ON cp.clientFk = cd.clientFk + JOIN client c ON c.id = cd.clientFk + JOIN province p ON p.id = c.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + JOIN country co ON co.id = p.countryFk + WHERE cd.warning = 'third' + AND cp.clientFk IS NULL + AND co.code NOT IN ('PT') + AND a.name <> 'Canarias' + AND c.salesPersonFk IS NOT NULL; + + OPEN rs; + FETCH rs INTO vClientFk; + WHILE NOT vDone DO + CALL vn.clientGreugeSpray(vClientFk, TRUE, '',TRUE); + UPDATE vn.client SET salesPersonFk = NULL WHERE id = vClientFk; + FETCH rs INTO vClientFk; + END WHILE; + CLOSE rs; + DROP TEMPORARY TABLE tmp.clientGetDebt; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/clientRisk_update.sql b/db/routines/vn/procedures/clientRisk_update.sql new file mode 100644 index 000000000..30ab3265f --- /dev/null +++ b/db/routines/vn/procedures/clientRisk_update.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientRisk_update`(vClientId INT, vCompanyId INT, vAmount DECIMAL(10,2)) +BEGIN + IF vAmount IS NOT NULL + THEN + INSERT INTO clientRisk + SET + clientFk = vClientId, + companyFk = vCompanyId, + amount = vAmount + ON DUPLICATE KEY UPDATE + amount = amount + VALUES(amount); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/client_RandomList.sql b/db/routines/vn/procedures/client_RandomList.sql new file mode 100644 index 000000000..2bd0d609b --- /dev/null +++ b/db/routines/vn/procedures/client_RandomList.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_RandomList`(vNumber INT) +BEGIN + + DECLARE i INT DEFAULT 0; + DECLARE c INT DEFAULT 0; + DECLARE maxClientFk INT; + + DROP TEMPORARY TABLE IF EXISTS tmp.client; + + CREATE TEMPORARY TABLE tmp.`client` + (id INT AUTO_INCREMENT, + clientFk INT, + isSelected TINYINT(1) NOT NULL DEFAULT 0, + PRIMARY KEY(id), + UNIQUE KEY clientFk (clientFk)) + ENGINE = MEMORY; + + INSERT INTO tmp.client(clientFk) + SELECT DISTINCT clientFk + FROM vn.invoiceOut + WHERE issued > TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); + + SELECT max(id) INTO maxClientFk + FROM tmp.client; + + + WHILE i < vNumber DO + + SET i = i + 1; + + WHILE c = 0 DO + + SELECT id INTO c + FROM tmp.client + WHERE id = floor(RAND() * maxClientFk) + 1 + AND isSelected = FALSE + LIMIT 1; + + END WHILE; + + -- SELECT i, maxClientFk, c; + + UPDATE tmp.client + SET isSelected = TRUE + WHERE id = c; + + SET c = 0; + + END WHILE; + + SELECT c.id, c.name FROM tmp.client tc + JOIN vn.client c ON c.id = tc.clientFk + WHERE isSelected + ORDER BY clientFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/client_checkBalance.sql b/db/routines/vn/procedures/client_checkBalance.sql new file mode 100644 index 000000000..ca8792ba4 --- /dev/null +++ b/db/routines/vn/procedures/client_checkBalance.sql @@ -0,0 +1,68 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_checkBalance`(IN vDateTo DATETIME, IN vIsConciliated BOOL) +BEGIN +/** + * Compara los datos de nuestros clientes con + * los que hay en la base de datos de sage + * + * @param vDateTo + * @param vIsConciliated + * @table tmp.ledgerComparative (id, date, account, debit, credit, companyFk) + */ + DECLARE vDateFrom DATE; + DECLARE vMaxTolerance DECIMAL(10,2); + + SELECT util.firstDayOfYear(vDateTo), util.dayEnd(vDateTo), maxTolerance + INTO vDateFrom, vDateTo, vMaxTolerance + FROM vn.ledgerConfig; + + SELECT s.nickname, + c.id, + c.accountingAccount, + sub1.mysql, + sub1.sage, + sub1.mysql - sub1.sage difference, + sub1.companyFk, + c.name + FROM client c + JOIN payMethod pm ON pm.id = c.payMethodFk + JOIN (SELECT sub.companyFk, + sub.clientFk, + CAST(ROUND(SUM(sub.mysql), 2) AS DECIMAL(10,2)) mysql, + CAST(ROUND(SUM(sub.sage), 2) AS DECIMAL(10,2)) sage + FROM(SELECT io.companyFk, + io.clientFk, + - io.amount mysql, + 0 sage + FROM invoiceOut io + WHERE issued BETWEEN vDateFrom AND vDateTo + UNION ALL + SELECT r.companyFk, + r.clientFk, + r.amountPaid, + 0 + FROM receipt r + WHERE payed BETWEEN vDateFrom AND vDateTo + AND IF(vIsConciliated,r.isConciliate, TRUE) = TRUE + UNION ALL + SELECT lc.companyFk, + c.id, + 0, + - (NZ(lc.credit) - NZ(lc.debit)) + FROM tmp.ledgerComparative lc + JOIN client c ON c.accountingAccount = lc.account + WHERE lc.`date` BETWEEN vDateFrom AND vDateTo + )sub + GROUP BY companyFk, clientFk + ) sub1 ON sub1.clientFk = c.id + JOIN supplier s ON s.id = sub1.companyFk + JOIN company co ON co.id = sub1.companyFk + LEFT JOIN clientUnpaid cu ON cu.clientFk = c.id + AND cu.dated BETWEEN vDateFrom AND vDateTo + WHERE pm.outstandingDebt + AND co.code <> 'BLK' + AND cu.clientFk IS NULL + HAVING ABS(difference) > vMaxTolerance + ORDER BY c.name; +END$$ +DELIMITER ; diff --git a/db/.archive/233202/00-client_create_upper.sql b/db/routines/vn/procedures/client_create.sql similarity index 100% rename from db/.archive/233202/00-client_create_upper.sql rename to db/routines/vn/procedures/client_create.sql diff --git a/db/routines/vn/procedures/client_getDebt.sql b/db/routines/vn/procedures/client_getDebt.sql new file mode 100644 index 000000000..ad7b5b7d2 --- /dev/null +++ b/db/routines/vn/procedures/client_getDebt.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_getDebt`(vDate DATE) +BEGIN +/** + * Calculates the risk for active clients + * + * @table tmp.clientGetDebt(clientFk) + * @param vDate Maximum date of records + * @return tmp.risk + */ + + DECLARE vStarted DATETIME; + DECLARE vEnded DATETIME; + + SELECT util.VN_CURDATE() - INTERVAL riskScope MONTH INTO vStarted + FROM clientConfig; + + SET vEnded = util.dayEnd(IFNULL(vDate, util.VN_CURDATE())); + + CREATE OR REPLACE TEMPORARY TABLE tClientRisk + ENGINE = MEMORY + SELECT cr.clientFk, SUM(cr.amount) amount + FROM clientRisk cr + JOIN tmp.clientGetDebt c ON c.clientFk = cr.clientFk + GROUP BY cr.clientFk; + + INSERT INTO tClientRisk + SELECT c.clientFk, SUM(r.amountPaid) + FROM receipt r + JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk + WHERE r.payed > vEnded + GROUP BY c.clientFk; + + INSERT INTO tClientRisk + SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)) + FROM hedera.tpvTransaction t + JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk + WHERE t.receiptFk IS NULL + AND t.status = 'ok' + GROUP BY t.clientFk; + + INSERT INTO tClientRisk + SELECT t.clientFk, SUM(totalWithVat) + FROM ticket t + JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk + WHERE refFk IS NULL + AND shipped BETWEEN vStarted AND vEnded + GROUP BY t.clientFk; + + -- refs #6351 BUG: No cambiar a CREATE OR REPLACE + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + CREATE TEMPORARY TABLE tmp.risk + (PRIMARY KEY (clientFk)) + ENGINE = MEMORY + SELECT clientFk, SUM(amount) risk + FROM client c + JOIN tClientRisk cr ON cr.clientFk = c.id + GROUP BY c.id; + + DROP TEMPORARY TABLE tClientRisk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/client_getMana.sql b/db/routines/vn/procedures/client_getMana.sql new file mode 100644 index 000000000..99b00c6df --- /dev/null +++ b/db/routines/vn/procedures/client_getMana.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_getMana`() +BEGIN +/** + * Devuelve el mana de los clientes de la tabla tmp.client(id) + * @return tmp.clientMana(id, mana) + * + */ + DECLARE vFromDated DATE; + + DELETE tc FROM tmp.client tc + JOIN client c ON c.id = tc.id + WHERE c.typeFk <> 'normal'; + + SELECT MAX(dated) INTO vFromDated + FROM clientManaCache; + + CREATE OR REPLACE TEMPORARY TABLE tmp.clientMana + SELECT id, SUM(mana) mana + FROM + ( + SELECT tc.id, cmc.mana + FROM clientManaCache cmc + JOIN tmp.client tc ON tc.id = cmc.clientFk + WHERE cmc.dated = vFromDated + UNION ALL + SELECT tc.id, s.quantity * value + FROM ticket t + JOIN address a ON a.id = t.addressFk + JOIN tmp.client tc ON tc.id = a.clientFk + JOIN sale s on s.ticketFk = t.id + JOIN saleComponent sc on sc.saleFk = s.id + JOIN component comp ON sc.componentFk = comp.id + JOIN componentType ct ON ct.id = comp.typeFk AND ct.code = 'mana' + WHERE t.shipped > vFromDated + AND t.shipped < util.tomorrow() + UNION ALL + SELECT tc.id, -amountPaid + FROM receipt r + JOIN `client` c ON c.id = r.clientFk + JOIN tmp.client tc ON tc.id = c.id + JOIN bank b ON r.bankFk = b.id AND b.code = 'mana' + WHERE r.payed > vFromDated + AND r.payed <= util.VN_CURDATE() + UNION ALL + SELECT tc.id, g.amount + FROM greuge g + JOIN `client` c ON c.id = g.clientFk + JOIN tmp.client tc ON tc.id = c.id + JOIN greugeType gt ON gt.id = g.greugeTypeFk AND gt.code = 'mana' + WHERE g.shipped > vFromDated + AND g.shipped <= util.VN_CURDATE() + ) sub + GROUP BY id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/client_unassignSalesPerson.sql b/db/routines/vn/procedures/client_unassignSalesPerson.sql new file mode 100644 index 000000000..8c624204e --- /dev/null +++ b/db/routines/vn/procedures/client_unassignSalesPerson.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_unassignSalesPerson`() +BEGIN +/** + * Elimina la asignación de salesPersonFk de la ficha del clientes + * que no han realizado una compra en los últimos 3 meses y reparte + * su greuge entre el resto de clientes + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vClientFk INT; + DECLARE vCursor CURSOR FOR + SELECT c.clientFk + FROM tClientList c + LEFT JOIN clientRisk r ON r.clientFk = c.clientFk + GROUP BY c.clientFk + HAVING NOT SUM(IFNULL(r.amount, 0)); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tClientList + SELECT c.clientFk + FROM bs.clientDied cd + JOIN client c ON c.id = cd.id + LEFT JOIN clientProtected cp ON cp.clientFk = c.id + LEFT JOIN salesPersonProtected sp ON sp.salesPersonFk = c.salesPersonFk + JOIN province p ON p.id = c.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + JOIN country co ON co.id = p.countryFk + WHERE cd.warning = 'third' + AND cp.clientFk IS NULL + AND sp.salesPersonFk IS NULL + AND a.name <> 'Canarias' + AND c.salesPersonFk IS NOT NULL; + + OPEN vCursor; + l: LOOP + SET vDone = FALSE; + FETCH vCursor INTO vClientFk; + IF vDone THEN + LEAVE l; + END IF; + CALL clientGreugeSpray(vClientFk, TRUE, '', TRUE); + UPDATE client + SET salesPersonFk = NULL + WHERE id = vClientFk; + END LOOP; + CLOSE vCursor; + + DROP TEMPORARY TABLE tClientList; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/cmrPallet_add.sql b/db/routines/vn/procedures/cmrPallet_add.sql new file mode 100644 index 000000000..2267cd312 --- /dev/null +++ b/db/routines/vn/procedures/cmrPallet_add.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`cmrPallet_add`(vExpeditionPalletFk INT, vCmrFk INT) +BEGIN +/** + * Añade registro a tabla cmrPallet. + * + * @param vExpeditionPalletFk Id de expeditionPallet + * @param vCmrFk Id de cmrPallet + */ + DECLARE vIsACurrentExpeditionPallet BOOL; + DECLARE vIsACurrentCMR BOOL; + DECLARE vYesterday DATE; + + SET vYesterday = util.yesterday(); + + SELECT COUNT(*) INTO vIsACurrentExpeditionPallet + FROM vn.expeditionPallet cp + WHERE cp.id = vExpeditionPalletFk + AND cp.built >= vYesterday; + + IF !vIsACurrentExpeditionPallet THEN + CALL util.throw('expeditionPalletNotExist'); + END IF; + + SELECT COUNT(*) INTO vIsACurrentCMR + FROM vn.cmr c + WHERE c.id = vCmrFk + AND c.created >= vYesterday; + + IF vIsACurrentCMR THEN + INSERT INTO cmrPallet (cmrFk, expeditionPalletFk) + VALUES(vCmrFk, vExpeditionPalletFk); + ELSE + Call util.throw('cmrNotExist'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collectionPlacement_get.sql b/db/routines/vn/procedures/collectionPlacement_get.sql new file mode 100644 index 000000000..db452ec2a --- /dev/null +++ b/db/routines/vn/procedures/collectionPlacement_get.sql @@ -0,0 +1,150 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collectionPlacement_get`( + vParamFk INT(11), + vIsPicker bool) +BEGIN +/** + * Devuelve el listado de ubicaciones a las que hay que ir + * para preparar una colección o ticket de manera ordenada + * + * @param vParamFk Identificador de collection o Identificador de ticket + * @param vIsPicker Booleano para distinguer el sacador del revisador + */ + DECLARE vCalcFk INT; + DECLARE vWarehouseFk INT; + DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); + + CREATE OR REPLACE TEMPORARY TABLE tSale + (INDEX(ticketFk), INDEX(saleFk), INDEX(itemFk)) + ENGINE = MEMORY + SELECT s.ticketFk, s.id saleFk, s.itemFk, s.quantity + FROM ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vParamFk + UNION ALL + SELECT s.ticketFk, s.id, s.itemFk, s.quantity + FROM sale s + WHERE s.ticketFk = vParamFk; + + SELECT t.warehouseFk + INTO vWarehouseFk + FROM ticket t + JOIN tSale ts ON ts.ticketFk = t.id + JOIN warehouse w ON w.id = t.warehouseFk + LIMIT 1; + + CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); + + CREATE OR REPLACE TEMPORARY TABLE tGrouping + (INDEX(itemFk)) + ENGINE = MEMORY + SELECT b.itemFk, + CASE b.groupingMode + WHEN 0 THEN 1 + WHEN 2 THEN b.packing + ELSE b.`grouping` + END `grouping` + FROM buy b + JOIN cache.last_buy lb ON lb.buy_id = b.id + WHERE lb.warehouse_id = vWarehouseFk + GROUP BY b.itemFk; + + CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList + (INDEX(saleFk), INDEX(`order`)) + ENGINE = MEMORY + SELECT ts.saleFk, + ts.itemFk, + CAST(0 AS DECIMAL(10,0)) saleOrder, + IF(ish.visible > 0 OR iss.id, 1, 100000) * + IFNULL(p2.pickingOrder, p.pickingOrder) `order`, + TO_SECONDS(IF(iss.id, + iss.created - INTERVAL vCurrentYear YEAR, + ish.created - INTERVAL YEAR(ish.created) YEAR)) priority, + CONCAT( + IF(iss.id, + CONCAT('< ', IFNULL(wk.`code`, '---'),' > '), + ''), + p.`code`) COLLATE utf8_general_ci placement, + sh.priority shelvingPriority, + sh.code COLLATE utf8_general_ci shelving, + ish.created, + ish.visible, + IFNULL( + IF(st.description = 'previousByPacking', ish.packing, g.`grouping`), + 1) `grouping`, + st.description = 'previousPrepared' isPreviousPrepared, + iss.id itemShelvingSaleFk, + ts.ticketFk, + iss.id, + st.saleFk salePreviousPrepared, + iss.userFk, + ts.quantity + FROM tSale ts + LEFT JOIN (SELECT DISTINCT saleFk + FROM saleTracking st + JOIN state s ON s.id = st.stateFk + WHERE st.isChecked + AND s.semaphore = 1) st ON st.saleFk = ts.saleFk + JOIN itemShelving ish ON ish.itemFk = ts.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector sc ON sc.id = p.sectorFk + JOIN sectorType st ON st.id = sc.typeFk + JOIN warehouse w ON w.id = sc.warehouseFk + LEFT JOIN tGrouping g ON g.itemFk = ts.itemFk + LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk + AND iss.itemShelvingFk = ish.id + LEFT JOIN worker wk ON wk.id = iss.userFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = ts.saleFk + LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk + LEFT JOIN parking p2 ON p2.id = sg.parkingFk + WHERE w.id = vWarehouseFk + AND NOT sc.isHideForPickers + HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL; + + CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList2 + (INDEX(saleFk), INDEX(olderPriority)) + ENGINE = MEMORY + SELECT saleFk, priority olderPriority + FROM (SELECT saleFk, priority + FROM tSalePlacementList + ORDER BY isPreviousPrepared DESC, + itemShelvingSaleFk IS NULL DESC, + visible >= quantity DESC, + visible > 0 DESC, + IFNULL(shelvingPriority, 0) DESC, + priority + LIMIT 10000000000000000000 + )sub + GROUP BY saleFk; + + UPDATE tSalePlacementList tsp + JOIN (SELECT s1.saleFk, `order` saleOrder + FROM tSalePlacementList s1 + JOIN tSalePlacementList2 s2 ON s2.saleFk = s1.saleFk + AND s2.olderPriority = s1.priority + ) sub ON sub.saleFk = tsp.saleFk + SET tsp.saleOrder = sub.saleOrder; + + -- Anula el orden de antigüedad y ordena por ubicación + UPDATE tSalePlacementList + SET saleOrder = `order`; + + SELECT spl.* + FROM tSalePlacementList spl + JOIN sale s ON s.id = spl.saleFk + ORDER BY saleOrder, + isPreviousPrepared DESC, + itemShelvingSaleFk DESC, + IF(vIsPicker, visible = 0, TRUE), + s.quantity <= spl.visible DESC, + shelvingPriority DESC, + priority; + + DROP TEMPORARY TABLE + tSale, + tGrouping, + tSalePlacementList, + tSalePlacementList2; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_addItem.sql b/db/routines/vn/procedures/collection_addItem.sql new file mode 100644 index 000000000..c19d88684 --- /dev/null +++ b/db/routines/vn/procedures/collection_addItem.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_addItem`( + vBarccodeFk INT, + vQuantity INT, + vTicketFk INT +) +BEGIN +/** + * Add a sales line to the ticket with the indicated amount. + * + * @param vBarcodeFk barcode on the item label + * @param vQuantity quantity to be added to the ticket + * @param vTicketFk ticket to which the sales line is added + */ + DECLARE vConcept VARCHAR(50); + DECLARE vItemFk INT; + DECLARE vSaleFk INT; + DECLARE vDescription VARCHAR(50); + DECLARE vItemName VARCHAR(50); + + SELECT barcodeToItem(vBarccodeFk) INTO vItemFk; + + SELECT CONCAT(getUser(), + ' ', + DATE_FORMAT(util.VN_NOW(), '%H:%i' ), + ' ', + i.name + ) INTO vConcept + FROM item i + WHERE i.id = vItemFk; + + SELECT name INTO vItemName FROM item WHERE id = vBarccodeFk; + + SELECT CONCAT('Añadido articulo ', + vItemName, + ' cantidad:', + vQuantity + ) INTO vDescription; + + INSERT INTO ticketLog + SET originFk = vTicketFk, + userFk = getUser(), + `action` = 'update', + `description` = vDescription; + + INSERT INTO sale + SET itemFk = vItemFk, + ticketFk = vTicketFk, + concept = vConcept, + quantity = vQuantity, + isAdded = TRUE; + + SELECT LAST_INSERT_ID() INTO vSaleFk; + + CALL sale_calculateComponent(vSaleFk, NULL); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql new file mode 100644 index 000000000..038f8f9a3 --- /dev/null +++ b/db/routines/vn/procedures/collection_assign.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_assign`(vUserFk INT, OUT vCollectionFk INT) +proc:BEGIN +/* Comprueba si existen colecciones libres que se ajustan al perfil del usuario + * y le asigna la más antigua. + * Añade un registro al semillero de colecciones + */ + DECLARE vHasTooMuchCollections BOOL; + DECLARE vLockTime INT DEFAULT 15; + + -- Si hay colecciones sin terminar, sale del proceso + CALL vn.collection_get(vUserFk); + + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 + INTO vHasTooMuchCollections + FROM tCollection + JOIN vn.productionConfig pc ; + + DROP TEMPORARY TABLE tCollection; + + IF vHasTooMuchCollections THEN + CALL util.throw('Hay colecciones pendientes'); + LEAVE proc; + END IF; + + IF NOT GET_LOCK('collection_assign',vLockTime) THEN + LEAVE proc; + END IF; + + -- Se eliminan las colecciones sin asignar que estan obsoletas + INSERT INTO ticketTracking(stateFk, ticketFk) + SELECT s.id, tc.ticketFk + FROM vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id + JOIN vn.state s ON s.code = 'PRINTED_AUTO' + JOIN vn.productionConfig pc + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + + DELETE c.* + FROM vn.collection c + JOIN vn.productionConfig pc + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + + -- Se a�ade registro al semillero + INSERT INTO vn.collectionHotbed(userFk) + VALUES(vUserFk); + + -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion + SELECT MIN(c.id) + INTO vCollectionFk + FROM vn.collection c + JOIN vn.operator o + ON (o.itemPackingTypeFk = c.itemPackingTypeFk OR c.itemPackingTypeFk IS NULL) + AND o.numberOfWagons = c.wagons + AND o.trainFk = c.trainFk + AND o.warehouseFk = c.warehouseFk + AND c.workerFk IS NULL + WHERE o.workerFk = vUserFk; + + IF vCollectionFk IS NULL THEN + CALL vn.collection_new(vUserFk, vCollectionFk); + END IF; + + UPDATE vn.collection + SET workerFk = vUserFk + WHERE id = vCollectionFk; + + DO RELEASE_LOCK('collection_assign'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_get.sql b/db/routines/vn/procedures/collection_get.sql new file mode 100644 index 000000000..372d963c0 --- /dev/null +++ b/db/routines/vn/procedures/collection_get.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_get`(vWorkerFk INT) +BEGIN +/** + * Obtiene colección del sacador si tiene líneas pendientes. + * + * @param vWorkerFk id del worker. + * @table Devuelve tabla temporal con las colecciones pendientes + */ + DROP TEMPORARY TABLE IF EXISTS tCollection; + + CREATE TEMPORARY TABLE tCollection + SELECT c.id collectionFk, + date(c.created) created, + COUNT(DISTINCT tc.ticketFk) ticketTotalCount + FROM collection c + JOIN ticketCollection tc ON tc.collectionFk = c.id + JOIN sale s ON s.ticketFk = tc.ticketFk + JOIN ticketState ts ON ts.ticketFk = tc.ticketFk + JOIN state s2 ON s2.id = ts.stateFk + JOIN productionConfig pc + JOIN vn.state ss on ss.code = 'PREPARED' + LEFT JOIN vn.saleTracking st on st.saleFk = s.id AND st.stateFk = ss.id + WHERE c.workerFk = vWorkerFk + AND TIMESTAMPDIFF(HOUR, c.created , util.VN_NOW()) < pc.pendingCollectionsAge + AND s.quantity != 0 + AND s2.order < pc.pendingCollectionsOrder + GROUP BY c.id + HAVING COUNT(*) > COUNT(DISTINCT st.id); + + SELECT * FROM tCollection; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_getTickets.sql b/db/routines/vn/procedures/collection_getTickets.sql new file mode 100644 index 000000000..0a71ada78 --- /dev/null +++ b/db/routines/vn/procedures/collection_getTickets.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_getTickets`(vParamFk INT) +BEGIN +/** + * Selecciona los tickets de una colección/ticket + * @param vParamFk ticketFk/collectionFk + * @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observaciones + */ + DECLARE vItemPackingTypeFk VARCHAR(1); + + -- Si los sacadores son los de pruebas, pinta los colores + SELECT itemPackingTypeFk INTO vItemPackingTypeFk + FROM vn.collection + WHERE id = vParamFk; + + SELECT t.id ticketFk, + IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`, + am.name agencyName, + t.warehouseFk, + w.id salesPersonFk, + IFNULL(tob.description,'') observaciones, + cc.rgb + FROM vn.ticket t + LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 + LEFT JOIN vn.collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` + AND cc.trainFk = c2.trainFk -- PAK 23/12/21 + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id + AND tob.observationTypeFk = 1 + WHERE t.id = vParamFk + AND t.shipped >= util.yesterday() + UNION ALL + SELECT t.id ticketFk, + IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, + am.name agencyName, + t.warehouseFk, + w.id salesPersonFk, + IFNULL(tob.description, '') observaciones, + IF(!(vItemPackingTypeFk <=> 'V'), cc.rgb, NULL) `rgb` + FROM vn.ticket t + JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 + LEFT JOIN vn.collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` + AND cc.trainFk = c2.trainFk -- PAK 23/12/21 + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id + AND tob.observationTypeFk = 1 + WHERE tc.collectionFk = vParamFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_kill.sql b/db/routines/vn/procedures/collection_kill.sql new file mode 100644 index 000000000..f80fea512 --- /dev/null +++ b/db/routines/vn/procedures/collection_kill.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_kill`(vSelf INT) +BEGIN +/** + * Elimina una coleccion y coloca sus tickets en OK + */ + INSERT INTO ticketTracking(stateFk, ticketFk) + SELECT s.id, ticketFk + FROM vn.ticketCollection tc + JOIN vn.state s ON s.code = 'OK' + WHERE tc.collectionFk = vSelf; + + DELETE FROM vn.collection + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_make.sql b/db/routines/vn/procedures/collection_make.sql new file mode 100644 index 000000000..b5b728000 --- /dev/null +++ b/db/routines/vn/procedures/collection_make.sql @@ -0,0 +1,68 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_make`() +proc:BEGIN +/** + * Genera colecciones de tickets sin asignar trabajador a partir de la tabla + * vn.collectionHotbed. + */ + DECLARE vUserFk INT; + DECLARE vCounter INT; + DECLARE vMaxCollectionWithoutUser INT; + DECLARE vHasEnoughFreeCollections BOOL; + DECLARE vDone INT DEFAULT FALSE; + + DECLARE cur1 CURSOR FOR + SELECT DISTINCT userFk + FROM vn.collectionHotbed; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT maxCollectionWithoutUser + INTO vMaxCollectionWithoutUser + FROM vn.productionConfig pc; + + SELECT (vMaxCollectionWithoutUser - COUNT(*)) <= 0 + INTO vHasEnoughFreeCollections + FROM vn.collection c + JOIN vn.operator o + ON o.numberOfWagons = c.wagons + AND o.trainFk = c.trainFk + AND o.itemPackingTypeFk = c.itemPackingTypeFk + WHERE c.workerFk IS NULL + AND o.workerFk = vUserFk; + + IF vHasEnoughFreeCollections THEN + LEAVE proc; + END IF; + + OPEN cur1; + + read_loop: LOOP + + SET vDone = FALSE; + + FETCH cur1 INTO vUserFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + SET vCounter = vMaxCollectionWithoutUser; + + WHILE vCounter > 0 DO + + SET vCounter = vCounter - 1; + + CALL vn.collection_new(vUserFk, @vCollectionFk); + + END WHILE; + + DELETE + FROM vn.collectionHotbed + WHERE userFk = vUserFk; + + END LOOP; + + CLOSE cur1; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql new file mode 100644 index 000000000..8bb382db1 --- /dev/null +++ b/db/routines/vn/procedures/collection_new.sql @@ -0,0 +1,303 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_new`(vUserFk INT, OUT vCollectionFk INT) +proc:BEGIN +/** + * Genera colecciones de tickets sin asignar trabajador. + * + * @param vUserFk Identificador de account.user + */ + DECLARE vWarehouseFk INT; + DECLARE vWagons INT; + DECLARE vTrainFk INT; + DECLARE vMaxTickets INT; + DECLARE vStateFk VARCHAR(45); + DECLARE vFirstTicketFk INT; + DECLARE vHour INT; + DECLARE vMinute INT; + DECLARE vWorkerCode VARCHAR(3); + DECLARE vWagonCounter INT DEFAULT 0; + DECLARE vTicketFk INT; + DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE vHasAssignedTickets BOOLEAN; + DECLARE vHasUniqueCollectionTime BOOL; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vLockName VARCHAR(215); + DECLARE vLockTime INT DEFAULT 15; + DECLARE vFreeWagonFk INT; + DECLARE cur1 CURSOR FOR + SELECT ticketFk + FROM tmp.productionBuffer + WHERE ticketFk <> vFirstTicketFk + ORDER BY + HH, + mm, + productionOrder DESC, + m3 DESC, + agency, + zona, + routeFk, + ticketFk + LIMIT vMaxTickets; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT + pc.ticketTrolleyMax * o.numberOfWagons, + pc.hasUniqueCollectionTime, + w.code, + o.warehouseFk, + o.itemPackingTypeFk, + st.code, + CONCAT('collection_new', o.warehouseFk, ':',o.itemPackingTypeFk), + o.numberOfWagons, + o.trainFk + INTO + vMaxTickets, + vHasUniqueCollectionTime, + vWorkerCode, + vWarehouseFk, + vItemPackingTypeFk, + vStateFk, + vLockName, + vWagons, + vTrainFk + FROM productionConfig pc + JOIN worker w ON w.id = vUserFk + JOIN state st ON st.`code` = 'ON_PREPARATION' + JOIN operator o ON o.workerFk = vUserFk; + + IF NOT GET_LOCK(vLockName,vLockTime) THEN + LEAVE proc; + END IF; + + -- Se prepara el tren, con tantos vagones como sea necesario. + CREATE OR REPLACE TEMPORARY TABLE tTrain + (wagon INT, + shelve INT, + liters INT, + `lines`INT, + height INT, + ticketFk INT, + PRIMARY KEY(wagon, shelve)) + ENGINE = MEMORY; + + WHILE vWagons > vWagonCounter DO + SET vWagonCounter = vWagonCounter + 1; + + INSERT INTO tTrain(wagon, shelve, liters, `lines`, height) + SELECT vWagonCounter, cv.`level` , cv.liters , cv.`lines` , cv.height + FROM collectionVolumetry cv + WHERE cv.trainFk = vTrainFk + AND cv.itemPackingTypeFk = vItemPackingTypeFk; + END WHILE; + + -- Esto desaparecerá cuando tengamos la table cache.ticket + CALL productionControl(vWarehouseFk, 0); + + ALTER TABLE tmp.productionBuffer + ADD COLUMN liters INT, + ADD COLUMN height INT; + + -- Se obtiene nº de colección. + INSERT INTO collection + SET itemPackingTypeFk = vItemPackingTypeFk, + trainFk = vTrainFk, + wagons = vWagons, + warehouseFk = vWarehouseFk; + + SELECT LAST_INSERT_ID() INTO vCollectionFk; + + -- Los tickets de recogida en Algemesí sólo se sacan si están asignados. + -- Los pedidos con riesgo no se sacan aunque se asignen. + DELETE pb.* + FROM tmp.productionBuffer pb + JOIN state s ON s.id = pb.state + WHERE (pb.agency = 'REC_ALGEMESI' + AND s.code <> 'PICKER_DESIGNED') + OR pb.problem LIKE '%RIESGO%'; + + -- Comprobamos si hay tickets asignados. En ese caso, nos centramos + -- exclusivamente en esos tickets y los sacamos independientemente + -- de problemas o tamaños + SELECT COUNT(*) INTO vHasAssignedTickets + FROM tmp.productionBuffer pb + JOIN state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode; + + -- Se dejan en la tabla tmp.productionBuffer sólo aquellos tickets adecuados + IF vHasAssignedTickets THEN + DELETE pb.* + FROM tmp.productionBuffer pb + JOIN state s ON s.id = pb.state + WHERE s.code <> 'PICKER_DESIGNED' + OR pb.workerCode <> vWorkerCode; + ELSE + DELETE pb.* + FROM tmp.productionBuffer pb + JOIN state s ON s.id = pb.state + JOIN agencyMode am ON am.id = pb.agencyModeFk + JOIN agency a ON a.id = am.agencyFk + JOIN productionConfig pc + WHERE pb.shipped <> util.VN_CURDATE() + OR (pb.ubicacion IS NULL AND a.isOwn = TRUE) + OR (s.isPreparable = FALSE AND s.isPrintable = FALSE) + OR pb.collectionH IS NOT NULL + OR pb.collectionV IS NOT NULL + OR pb.collectionN IS NOT NULL + OR (pb.H = 0 AND pb.V > 0 AND vItemPackingTypeFk = 'H') + OR (pb.V = 0 AND vItemPackingTypeFk = 'V') + OR (pc.isPreviousPreparationRequired AND pb.previousWithoutParking) + OR LENGTH(pb.problem) > 0; + END IF; + + -- Es importante que el primer ticket se coja en todos los casos + SELECT ticketFk, HH, mm + INTO vFirstTicketFk, vHour, vMinute + FROM tmp.productionBuffer + ORDER BY + HH, + mm, + productionOrder DESC, + m3 DESC, + agency, + zona, + routeFk, + ticketFk + LIMIT 1; + + -- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede + IF vHasUniqueCollectionTime THEN + DELETE + FROM tmp.productionBuffer + WHERE HH <> vHour + OR mm <> vMinute; + END IF; + + SET vTicketFk = vFirstTicketFk; + + OPEN cur1; + + read_loop: LOOP + SET vDone = FALSE; + + CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk); + + DROP TEMPORARY TABLE tmp.ticketIPT; + + UPDATE tmp.productionBuffer pb + JOIN (SELECT @litros:= SUM(litros) liters, COUNT(*) `lines`, MAX(i.`size`) height + FROM saleVolume sv + JOIN sale s ON s.id = sv.saleFk + JOIN item i ON i.id = s.itemFk + WHERE sv.ticketFk = vTicketFk ) sub + SET pb.liters = sub.liters, pb.`lines` = sub.`lines`, pb.height = sub.height + WHERE pb.ticketFk = vTicketFk; + + UPDATE tTrain tt + JOIN tmp.productionBuffer pb ON pb.ticketFk = vTicketFk + SET tt.ticketFk = pb.ticketFk + WHERE tt.liters >= pb.liters + AND tt.`lines` >= pb.`lines` + AND (tt.height >= pb.height OR vItemPackingTypeFk <> 'V') + AND tt.ticketFk IS NULL + ORDER BY + wagon, + shelve, + tt.liters, + tt.`lines`, + tt.height + LIMIT 1; + + -- Si no le encuentra una balda adecuada, intentamos darle un carro entero + -- si queda alguno libre + + IF NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN + SELECT tt.wagon + INTO vFreeWagonFk + FROM tTrain tt + LEFT JOIN (SELECT DISTINCT wagon + FROM tTrain + WHERE ticketFk IS NOT NULL + ) nn ON nn.wagon = tt.wagon + WHERE nn.wagon IS NULL + ORDER BY wagon + LIMIT 1; + + IF vFreeWagonFk THEN + UPDATE tTrain + SET ticketFk = vFirstTicketFk + WHERE wagon = vFreeWagonFk; + + -- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo + DELETE tt.* + FROM tTrain tt + LEFT JOIN (SELECT DISTINCT wagon + FROM tTrain + WHERE ticketFk IS NOT NULL + ) nn ON nn.wagon = tt.wagon + WHERE nn.wagon IS NULL; + END IF; + END IF; + + FETCH cur1 INTO vTicketFk; + + IF vDone OR NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk IS NULL) THEN + LEAVE read_loop; + END IF; + END LOOP; + + CLOSE cur1; + + IF (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN + UPDATE collection c + JOIN state st ON st.code = 'ON_PREPARATION' + SET c.stateFk = st.id + WHERE c.id = vCollectionFk; + + -- Asigna las bandejas + INSERT IGNORE INTO ticketCollection(ticketFk, collectionFk, `level`, wagon, liters) + SELECT tt.ticketFk, vCollectionFk, tt.shelve, tt.wagon, tt.liters + FROM tTrain tt + WHERE tt.ticketFk IS NOT NULL + ORDER BY tt.wagon, tt.shelve; + + -- Actualiza el estado de los tickets + + CALL collection_setState(vCollectionFk, vStateFk); + + -- Aviso para la preparacion previa + INSERT INTO ticketDown(ticketFk, collectionFk) + SELECT tc.ticketFk, tc.collectionFk + FROM ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + CALL sales_mergeByCollection(vCollectionFk); + + UPDATE collection c + JOIN (SELECT count(*) saleTotalCount , + sum(s.isPicked != 0) salePickedCount + FROM ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND s.quantity > 0 + ) sub + SET c.saleTotalCount = sub.saleTotalCount, + c.salePickedCount = sub.salePickedCount + WHERE c.id = vCollectionFk; + + ELSE + + -- CALL util.throw('No ha sido posible obtener colección'); + DELETE FROM collection WHERE id = vCollectionFk; + SET vCollectionFk = NULL; + + END IF; + + DO RELEASE_LOCK(vLockName); + + DROP TEMPORARY TABLE + tTrain, + tmp.productionBuffer; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_printSticker.sql b/db/routines/vn/procedures/collection_printSticker.sql new file mode 100644 index 000000000..50259152d --- /dev/null +++ b/db/routines/vn/procedures/collection_printSticker.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_printSticker`( + vSelf INT, + vLabelCount INT +) +BEGIN +/** + * Prints a yellow label from a collection or a ticket + * + * @param vSelf collection or ticket + * @param vLabelCount number of times the collection has been printed + */ + DECLARE vPrintArgs JSON DEFAULT JSON_OBJECT('collectionOrTicketFk', vSelf); + + IF vLabelCount IS NULL THEN + INSERT INTO ticketTrolley + SELECT ticketFk, 1 + FROM ticketCollection + WHERE collectionFk = vSelf + ON DUPLICATE KEY UPDATE labelCount = labelCount + 1; + ELSE + SET vPrintArgs = JSON_MERGE_PATCH(vPrintArgs, JSON_OBJECT('labelCount', vLabelCount)); + END IF; + + CALL report_print( + 'LabelCollection', + (SELECT o.labelerFk FROM operator o WHERE o.workerFk = account.myUser_getId()), + account.myUser_getId(), + vPrintArgs, + 'high' + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_setParking.sql b/db/routines/vn/procedures/collection_setParking.sql new file mode 100644 index 000000000..73aa87bfb --- /dev/null +++ b/db/routines/vn/procedures/collection_setParking.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN +/** + * Aparca una colección en un parking. + * + * @param vCollectionFk Id de la colección + * @param vParkingFk Id del parking + */ + REPLACE vn.ticketParking(ticketFk, parkingFk) + SELECT tc.ticketFk, vParkingFk + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_setState.sql b/db/routines/vn/procedures/collection_setState.sql new file mode 100644 index 000000000..2d33c53d6 --- /dev/null +++ b/db/routines/vn/procedures/collection_setState.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setState`(vSelf INT, vStateCode VARCHAR(255) COLLATE utf8_general_ci) +BEGIN +/** + * Modifica el estado de los tickets de una colección. + * + * @param vSelf el id del colección + * @param vStateCode estado a modificar de los tickets + */ + DECLARE vTicketFk INT; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vCursor CURSOR FOR + SELECT DISTINCT ticketFk + FROM ticketCollection tc + WHERE tc.collectionFk = vSelf; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + OPEN vCursor; + + read_loop: LOOP + + FETCH vCursor INTO vTicketFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + CALL ticket_setState(vTicketFk, vStateCode); + + END LOOP; + + CLOSE vCursor; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/company_getFiscaldata.sql b/db/routines/vn/procedures/company_getFiscaldata.sql new file mode 100644 index 000000000..7c56382e9 --- /dev/null +++ b/db/routines/vn/procedures/company_getFiscaldata.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`company_getFiscaldata`(workerFk INT) +BEGIN + +DECLARE vCompanyFk INT; + + SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) + INTO vCompanyFk + FROM vn.routeConfig rc + LEFT JOIN userConfig uc ON uc.userFk = workerFk; + + + SELECT + s.name AS name , + s.NIF AS nif , + s.street AS street , + s.city AS city , + s.postCode AS postCode + + FROM vn.company c + JOIN vn.worker w ON w.id = c.workerManagerFk + JOIN vn.supplier s ON s.id = c.id + WHERE c.id = vCompanyFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/company_getSuppliersDebt.sql b/db/routines/vn/procedures/company_getSuppliersDebt.sql new file mode 100644 index 000000000..f6bfc229d --- /dev/null +++ b/db/routines/vn/procedures/company_getSuppliersDebt.sql @@ -0,0 +1,197 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`company_getSuppliersDebt`(vSelf INT, vMonthsAgo INT) +BEGIN +/** + * Generates a temporary table containing outstanding payments to suppliers. + * + * @param vSelf company id + * @param vMonthAgo time interval to be consulted + */ + DECLARE vStartingDate DATETIME DEFAULT TIMESTAMPADD (MONTH,- vMonthsAgo,util.VN_CURDATE()); + DECLARE vCurrencyEuroFk INT; + DECLARE vStartDate DATE; + DECLARE vInvalidBalances DOUBLE; + + SELECT dated, invalidBalances INTO vStartDate, vInvalidBalances FROM supplierDebtConfig; + SELECT id INTO vCurrencyEuroFk FROM currency WHERE code = 'EUR'; + + DROP TEMPORARY TABLE IF EXISTS tOpeningBalances; + CREATE TEMPORARY TABLE tOpeningBalances ( + supplierFk INT NOT NULL, + companyFk INT NOT NULL, + openingBalances DOUBLE NOT NULL, + closingBalances DOUBLE NOT NULL, + currencyFk INT NOT NULL, + PRIMARY KEY (supplierFk, companyFk, currencyFk) + ) ENGINE = MEMORY; + + -- Calculates the opening and closing balance for each supplier + INSERT INTO tOpeningBalances + SELECT supplierFk, + companyFk, + SUM(amount * isBeforeStarting) AS openingBalances, + SUM(amount) closingBalances, + currencyFk + FROM ( + SELECT p.supplierFk, + p.companyFk, + IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa) AS amount, + p.dueDated < vStartingDate isBeforeStarting, + p.currencyFk + FROM payment p + WHERE p.received > vStartDate + AND p.companyFk = vSelf + UNION ALL + SELECT r.supplierFk, + r.companyFk, + - IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue) AS Total, + rv.dueDated < vStartingDate isBeforeStarting, + r.currencyFk + FROM invoiceIn r + INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk + WHERE r.issued > vStartDate + AND r.isBooked + AND r.companyFk = vSelf + ) sub GROUP BY companyFk, supplierFk, currencyFk; + + DROP TEMPORARY TABLE IF EXISTS tPendingDuedates; + CREATE TEMPORARY TABLE tPendingDuedates ( + id INT auto_increment, + expirationId INT, + dated DATE, + supplierFk INT NOT NULL, + companyFk INT NOT NULL, + amount DECIMAL(10, 2) NOT NULL, + currencyFk INT NOT NULL, + pending DECIMAL(10, 2) DEFAULT 0, + balance DECIMAL(10, 2) DEFAULT 0, + endingBalance DECIMAL(10, 2) DEFAULT 0, + isPayment BOOLEAN, + isReconciled BOOLEAN, + PRIMARY KEY (id), + INDEX (supplierFk, companyFk, currencyFk) + ) ENGINE = MEMORY; + + INSERT INTO tPendingDuedates ( + expirationId, + dated, + supplierFk, + companyFk, + amount, + currencyFk, + isPayment, + isReconciled + )SELECT p.id, + p.dueDated, + p.supplierFk, + p.companyFk, + IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa), + p.currencyFk, + TRUE isPayment, + p.isConciliated + FROM payment p + WHERE p.dueDated >= vStartingDate + AND p.companyFk = vSelf + UNION ALL + SELECT r.id, + rv.dueDated, + r.supplierFk, + r.companyFk, + -IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue), + r.currencyFk, + FALSE isPayment, + TRUE + FROM invoiceIn r + LEFT JOIN tOpeningBalances si ON r.companyFk = si.companyFk + AND r.supplierFk = si.supplierFk + AND r.currencyFk = si.currencyFk + JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk + WHERE rv.dueDated >= vStartingDate + AND (si.closingBalances IS NULL OR si.closingBalances <> 0) + AND r.isBooked + AND r.companyFk = vSelf + ORDER BY supplierFk, companyFk, companyFk, dueDated, isPayment DESC, id; + -- Now, we calculate the outstanding amount for each receipt in descending order + SET @risk := 0.0; + SET @supplier := 0.0; + SET @company := 0.0; + SET @moneda := 0.0; + SET @pending := 0.0; + SET @day := util.VN_CURDATE(); + + UPDATE tPendingDuedates vp + LEFT JOIN tOpeningBalances si ON vp.companyFk = si.companyFk + AND vp.supplierFk = si.supplierFk + AND vp.currencyFk = si.currencyFk + SET vp.balance = @risk := ( + IF ( + @company <> vp.companyFk + OR @supplier <> vp.supplierFk + OR @moneda <> vp.currencyFk, + IFNULL(si.openingBalances, 0), + @risk + ) + + vp.amount + ), + -- if there is a change of company or supplier or currency, the balance is reset + vp.pending = @pending := IF ( + @company <> vp.companyFk + OR @supplier <> vp.supplierFk + OR @moneda <> vp.currencyFk + OR @day <> vp.dated, + vp.amount * (NOT vp.isPayment), + @pending + vp.amount + ), + vp.companyFk = @company := vp.companyFk, + vp.supplierFk = @supplier := vp.supplierFk, + vp.currencyFk = @moneda := vp.currencyFk, + vp.dated = @day := vp.dated, + vp.balance = @risk, + vp.pending = @pending; + + CREATE OR REPLACE TEMPORARY TABLE tRowsToDelete ENGINE = MEMORY + SELECT expirationId, + dated, + supplierFk, + companyFk, + currencyFk, + balance + FROM tPendingDuedates + WHERE balance < vInvalidBalances + AND balance > - vInvalidBalances; + + DELETE vp.* + FROM tPendingDuedates vp + JOIN tRowsToDelete rd ON ( + vp.dated < rd.dated + OR (vp.dated = rd.dated AND vp.expirationId <= rd.expirationId) + ) + AND vp.supplierFk = rd.supplierFk + AND vp.companyFk = rd.companyFk + AND vp.currencyFk = rd.currencyFk + WHERE vp.isPayment = FALSE; + + SELECT vp.expirationId, + vp.dated, + vp.supplierFk, + vp.companyFk, + vp.currencyFk, + vp.amount, + vp.pending, + vp.balance, + s.payMethodFk, + vp.isPayment, + vp.isReconciled, + vp.endingBalance, + cr.amount clientRiskAmount + FROM tPendingDuedates vp + LEFT JOIN supplier s ON s.id = vp.supplierFk + LEFT JOIN client c ON c.fi = s.nif + LEFT JOIN clientRisk cr ON cr.clientFk = c.id + AND cr.companyFk = vp.companyFk; + + DROP TEMPORARY TABLE tOpeningBalances; + DROP TEMPORARY TABLE tPendingDuedates; + DROP TEMPORARY TABLE tRowsToDelete; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/comparative_add.sql b/db/routines/vn/procedures/comparative_add.sql new file mode 100644 index 000000000..349d26db5 --- /dev/null +++ b/db/routines/vn/procedures/comparative_add.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`comparative_add`() +BEGIN +/** + * Inserts sales records less than one month old in comparative. + */ + DECLARE vMaxPeriod INT; + DECLARE vPeriod INT; + DECLARE vWeek INT; + DECLARE vConfigPeriod INT; + DECLARE vConfigWeek INT; + + SELECT period, week INTO vConfigPeriod, vConfigWeek + FROM comparativeAddConfig; + + SELECT IFNULL(MAX(timePeriod), 0) INTO vMaxPeriod + FROM comparative; + + SELECT period - vConfigPeriod, + week + INTO vPeriod, + vWeek + FROM `time` + WHERE dated = util.VN_CURDATE(); + + IF vMaxPeriod < vPeriod + AND vWeek > vConfigWeek THEN + REPLACE comparative( + timePeriod, + itemFk, + warehouseFk, + quantity, + price, + countryFk + ) + SELECT tm.period, + s.itemFk, + t.warehouseFk, + sum(s.quantity), + sum(v.importe), + p.countryFk + FROM bs.ventas v + JOIN time tm ON tm.dated = v.fecha + JOIN sale s ON s.id = v.Id_Movimiento + JOIN itemType tp ON tp.id = v.tipo_id + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN ticket t ON t.id = s.ticketFk + JOIN client c ON c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN address ad ON ad.id = t.addressFk + LEFT JOIN province p ON p.id = ad.provinceFk + WHERE tm.period BETWEEN vMaxPeriod AND vPeriod + AND ct.code <> 'loses' + AND NOT w.code = 'inv' + GROUP BY p.countryFk, s.itemFk, tm.period, t.warehouseFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/conveyorExpedition_Add.sql b/db/routines/vn/procedures/conveyorExpedition_Add.sql new file mode 100644 index 000000000..c57c2ea37 --- /dev/null +++ b/db/routines/vn/procedures/conveyorExpedition_Add.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`conveyorExpedition_Add`(vStarted DATETIME, vEnded DATETIME) +BEGIN + + + DECLARE startingMinute INT; + + TRUNCATE vn.conveyorExpedition; + + INSERT INTO vn.conveyorExpedition( expeditionFk, + created, + length, + width, + height, + routeFk, + productionMinute, + truck, + criterion, + conveyorBuildingClassFk) + SELECT e.id, + e.created, + 10 * p.depth as depth, + 10 * p.width as width, + 10 * p.height as height, + IFNULL(t.routeFk,am.agencyFk) routeFk, + hour(e.created) * 60 + minute(e.created), + IFNULL(et.description , a.name), + IFNULL(t.routeFk,am.agencyFk) criterion, + IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass) + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.packaging p ON p.id = e.packagingFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.agency a ON a.id = am.agencyFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + JOIN vn.packagingConfig pc + WHERE t.warehouseFk IN (60,1,44) + AND e.created BETWEEN vStarted AND vEnded + AND p.height < 140 + AND p.width < 60 + AND p.depth < 125; + + SELECT MIN(productionMinute) INTO startingMinute + FROM vn.conveyorExpedition ce ; + + UPDATE vn.conveyorExpedition + SET productionMinute = productionMinute - startingMinute; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql new file mode 100644 index 000000000..17cf487b1 --- /dev/null +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`copyComponentsFromSaleList`(vTargetTicketFk INT) +BEGIN + +/* Copy sales and components to the target ticket +* +* ¡¡¡¡ Requires tmp.saleList(saleFk, itemFk, quantity, concept, price, discount, orden) !!!!! +* +* param VTargetTicketFk id del ticket a rellenar +*/ + + INSERT INTO vn.sale(ticketFk, itemFk, quantity,concept,price,discount) + SELECT vTargetTicketFk, itemFk, quantity,concept,price,discount + FROM tmp.saleList + ORDER BY orden; + + SET @order = 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; + + CREATE TEMPORARY TABLE tmp.newSaleList + SELECT id as saleFk, @order := @order + 1 as orden + FROM vn.sale + WHERE ticketFk = vTargetTicketFk + ORDER BY saleFk; + + INSERT INTO vn.saleComponent(saleFk,componentFk,value) + SELECT ns.saleFk, sc.componentFk, sc.value + FROM vn.saleComponent sc + JOIN tmp.saleList s ON s.saleFk = sc.saleFk + JOIN tmp.newSaleList ns ON ns.orden = s.orden; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/createPedidoInterno.sql b/db/routines/vn/procedures/createPedidoInterno.sql new file mode 100644 index 000000000..ecc5e57a5 --- /dev/null +++ b/db/routines/vn/procedures/createPedidoInterno.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`createPedidoInterno`(vItemFk INT,vQuantity INT) +BEGIN + + + UPDATE vn.item SET upToDown = vQuantity WHERE id = vItemFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/crypt.sql b/db/routines/vn/procedures/crypt.sql new file mode 100644 index 000000000..b3517b1ad --- /dev/null +++ b/db/routines/vn/procedures/crypt.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`crypt`(vText VARCHAR(255), vKey VARCHAR(255), OUT vResult VARCHAR(255) ) +BEGIN + + DECLARE vEncryptedText VARCHAR(255) DEFAULT ''; + + DECLARE vKeyLength INT; + DECLARE vKeyPosition INT DEFAULT 1; + DECLARE vKeyChar VARCHAR(1); + + DECLARE vTextLength INT; + DECLARE vTextPosition INT DEFAULT 1; + DECLARE vTextChar VARCHAR(1); + + DECLARE vEncryptedChar VARCHAR(1); + DECLARE vEncryptedCharPosition INT; + + DECLARE vChain VARCHAR(255) DEFAULT '#$.-_0123456789abcdefghijklmnopqrstuvwxyz'; + DECLARE vChainTextPosition INT; + DECLARE vChainKeyPosition INT; + DECLARE vChainLength INT; + + DECLARE vInvalidadChars VARCHAR(255) DEFAULT ''; + + SET vTextLength = LENGTH(vText); + SET vKeyLength = LENGTH(vKey); + SET vChainLength = LENGTH(vChain); + + WHILE vTextPosition <= vTextLength DO + + SET vTextChar = MID(vText,vTextPosition,1); + SET vKeyChar = MID(vKey,vKeyPosition,1); + + SET vChainTextPosition = LOCATE(vTextChar, vChain); + SET vInvalidadChars = IF(vChainTextPosition, vInvalidadChars, CONCAT(vInvalidadChars,vTextChar)); + SET vChainKeyPosition = LOCATE(vKeyChar, vChain); + SET vEncryptedCharPosition = vChainTextPosition + vChainKeyPosition; + + IF vEncryptedCharPosition > vChainLength THEN + + SET vEncryptedCharPosition = vEncryptedCharPosition - vChainLength; + + END IF; + + SET vEncryptedChar = MID(vChain, vEncryptedCharPosition,1); + + SET vEncryptedText = CONCAT(vEncryptedText, vEncryptedChar); + + SET vKeyPosition = IF(vKeyPosition = vKeyLength, 1,vKeyPosition + 1); + SET vTextPosition = vTextPosition + 1; + + END WHILE; + + SET vResult = IF(LENGTH(vInvalidadChars), CONCAT('Caracteres no válidos: ',vInvalidadChars),vEncryptedText); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/cryptOff.sql b/db/routines/vn/procedures/cryptOff.sql new file mode 100644 index 000000000..e0677a0e2 --- /dev/null +++ b/db/routines/vn/procedures/cryptOff.sql @@ -0,0 +1,54 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`cryptOff`(vText VARCHAR(255), vKey VARCHAR(255), OUT vResult VARCHAR(255)) +BEGIN + + DECLARE vUncryptedText VARCHAR(255) DEFAULT ''; + + DECLARE vKeyLength INT; + DECLARE vKeyPosition INT DEFAULT 1; + DECLARE vKeyChar VARCHAR(1); + + DECLARE vTextLength INT; + DECLARE vTextPosition INT DEFAULT 1; + DECLARE vTextChar VARCHAR(1); + + DECLARE vUncryptedChar VARCHAR(1); + DECLARE vUncryptedCharPosition INT; + + DECLARE vChain VARCHAR(255) DEFAULT '#$.-_0123456789abcdefghijklmnopqrstuvwxyz'; + DECLARE vChainTextPosition INT; + DECLARE vChainKeyPosition INT; + DECLARE vChainLength INT; + + SET vTextLength = LENGTH(vText); + SET vKeyLength = LENGTH(vKey); + SET vChainLength = LENGTH(vChain); + + WHILE vTextPosition <= vTextLength DO + + SET vTextChar = MID(vText,vTextPosition,1); + SET vKeyChar = MID(vKey,vKeyPosition,1); + + SET vChainTextPosition = LOCATE(vTextChar, vChain); + SET vChainKeyPosition = LOCATE(vKeyChar, vChain); + SET vUncryptedCharPosition = vChainTextPosition - vChainKeyPosition; + + IF vUncryptedCharPosition < 1 THEN + + SET vUncryptedCharPosition = vUncryptedCharPosition + vChainLength; + + END IF; + + SET vUncryptedChar = MID(vChain, vUncryptedCharPosition,1); + + SET vUncryptedText = CONCAT(vUncryptedText, vUncryptedChar); + + SET vKeyPosition = IF(vKeyPosition = vKeyLength, 1,vKeyPosition + 1); + SET vTextPosition = vTextPosition + 1; + + END WHILE; + + SET vResult = vUncryptedText; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/department_calcTree.sql b/db/routines/vn/procedures/department_calcTree.sql new file mode 100644 index 000000000..5a265bd41 --- /dev/null +++ b/db/routines/vn/procedures/department_calcTree.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`department_calcTree`() +BEGIN +/** + * Calculates the #path, #lft, #rgt, #sons and #depth columns of + * the #department table. To build the tree, it uses the #parentFk + * column. + */ + DECLARE vIndex INT DEFAULT 0; + DECLARE vSons INT; + + DROP TEMPORARY TABLE IF EXISTS tNestedTree; + CREATE TEMPORARY TABLE tNestedTree + SELECT id, path, lft, rgt, depth, sons + FROM department LIMIT 0; + + SET max_sp_recursion_depth = 5; + CALL department_calcTreeRec(NULL, '/', 0, vIndex, vSons); + SET max_sp_recursion_depth = 0; + + UPDATE department z + JOIN tNestedTree t ON t.id = z.id + SET z.path = t.path, + z.lft = t.lft, + z.rgt = t.rgt, + z.depth = t.depth, + z.sons = t.sons; + + DROP TEMPORARY TABLE tNestedTree; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/department_calcTreeRec.sql b/db/routines/vn/procedures/department_calcTreeRec.sql new file mode 100644 index 000000000..77054b17f --- /dev/null +++ b/db/routines/vn/procedures/department_calcTreeRec.sql @@ -0,0 +1,69 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`department_calcTreeRec`( + vSelf INT, + vPath VARCHAR(255), + vDepth INT, + INOUT vIndex INT, + OUT vSons INT +) +BEGIN +/** + * Calculates and sets the #path, #lft, #rgt, #sons and #depth + * columns for all children of the passed node. Once calculated + * the last node rgt index and the number of sons are returned. + * To update it's children, this procedure calls itself recursively + * for each one. + * + * @vSelf The node identifier + * @vPath The initial path + * @vDepth The initial depth + * @vIndex The initial lft index + * @vSons The number of direct sons + */ + DECLARE vChildFk INT; + DECLARE vLft INT; + DECLARE vMySons INT; + DECLARE vDone BOOL; + DECLARE vChildren CURSOR FOR + SELECT id FROM department + WHERE (vSelf IS NULL AND parentFk IS NULL) + OR (vSelf IS NOT NULL AND parentFk = vSelf); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SET vSons = 0; + + OPEN vChildren; + myLoop: LOOP + SET vDone = FALSE; + FETCH vChildren INTO vChildFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vIndex = vIndex + 1; + SET vLft = vIndex; + SET vSons = vSons + 1; + + CALL department_calcTreeRec( + vChildFk, + CONCAT(vPath, vChildFk, '/'), + vDepth + 1, + vIndex, + vMySons + ); + + SET vIndex = vIndex + 1; + + INSERT INTO tNestedTree + SET id = vChildFk, + path = vPath, + lft = vLft, + rgt = vIndex, + depth = vDepth, + sons = vMySons; + END LOOP; + CLOSE vChildren; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/department_doCalc.sql b/db/routines/vn/procedures/department_doCalc.sql new file mode 100644 index 000000000..915b9f191 --- /dev/null +++ b/db/routines/vn/procedures/department_doCalc.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`department_doCalc`() +proc: BEGIN +/** + * Recalculates the department tree. + */ + DECLARE vIsChanged BOOL; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.department_doCalc'); + RESIGNAL; + END; + + IF !GET_LOCK('vn.department_doCalc', 0) THEN + LEAVE proc; + END IF; + + SELECT isChanged INTO vIsChanged + FROM department_recalc; + + IF vIsChanged THEN + UPDATE department_recalc SET isChanged = FALSE; + CALL vn.department_calcTree; + END IF; + + DO RELEASE_LOCK('vn.department_doCalc'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/department_getHasMistake.sql b/db/routines/vn/procedures/department_getHasMistake.sql new file mode 100644 index 000000000..394105a16 --- /dev/null +++ b/db/routines/vn/procedures/department_getHasMistake.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`department_getHasMistake`() +BEGIN + +/** + * Obtiene los sectores a los cuales les ponemos errores + * + */ + + SELECT id, name + FROM department + WHERE hasToMistake <> FALSE; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/department_getLeaves.sql b/db/routines/vn/procedures/department_getLeaves.sql new file mode 100644 index 000000000..7f1e3cc35 --- /dev/null +++ b/db/routines/vn/procedures/department_getLeaves.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`department_getLeaves`( + vParentFk INT, + vSearch VARCHAR(255) +) +BEGIN + DECLARE vIsNumber BOOL; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != ''; + + DROP TEMPORARY TABLE IF EXISTS tNodes; + CREATE TEMPORARY TABLE tNodes + (UNIQUE (id)) + ENGINE = MEMORY + SELECT id FROM department LIMIT 0; + + IF vIsSearch THEN + SET vIsNumber = vSearch REGEXP '^[0-9]+$'; + + INSERT INTO tNodes + SELECT id FROM department + WHERE (vIsNumber AND `name` = vSearch) + OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) + LIMIT 1000; + END IF; + + IF vParentFk IS NULL THEN + DROP TEMPORARY TABLE IF EXISTS tChilds; + CREATE TEMPORARY TABLE tChilds + ENGINE = MEMORY + SELECT id FROM tNodes; + + DROP TEMPORARY TABLE IF EXISTS tParents; + CREATE TEMPORARY TABLE tParents + ENGINE = MEMORY + SELECT id FROM department LIMIT 0; + + myLoop: LOOP + DELETE FROM tParents; + INSERT INTO tParents + SELECT parentFk id + FROM department g + JOIN tChilds c ON c.id = g.id + WHERE g.parentFk IS NOT NULL; + + INSERT IGNORE INTO tNodes + SELECT id FROM tParents; + + IF ROW_COUNT() = 0 THEN + LEAVE myLoop; + END IF; + + DELETE FROM tChilds; + INSERT INTO tChilds + SELECT id FROM tParents; + END LOOP; + + DROP TEMPORARY TABLE + tChilds, + tParents; + END IF; + + IF !vIsSearch THEN + INSERT IGNORE INTO tNodes + SELECT id FROM department + WHERE parentFk <=> vParentFk; + END IF; + + SELECT d.id, + d.`name`, + d.parentFk, + d.sons + FROM department d + JOIN tNodes n ON n.id = d.id + ORDER BY depth, `name`; + + DROP TEMPORARY TABLE tNodes; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/deviceLog_add.sql b/db/routines/vn/procedures/deviceLog_add.sql new file mode 100644 index 000000000..8d2310633 --- /dev/null +++ b/db/routines/vn/procedures/deviceLog_add.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`deviceLog_add`(vWorkerFk INT, vAppName VARCHAR(45), vAppVersion VARCHAR(45), vAndroid_id VARCHAR(64)) +BEGIN +/** + * Inserta registro en tabla devicelog el log del usuario conectado. + * + * @param vAppName es el nombre de la app + * @param vAppVersion es la versión de la app + * @param vAndroid_id es el android_id del dispositivo que se ha logueado + */ + INSERT INTO deviceLog (userFK, nameApp, versionApp, android_id) + VALUES(vWorkerFk, vAppName, vAppVersion, vAndroid_id); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/deviceProductionUser_exists.sql b/db/routines/vn/procedures/deviceProductionUser_exists.sql new file mode 100644 index 000000000..f5be6e94f --- /dev/null +++ b/db/routines/vn/procedures/deviceProductionUser_exists.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`deviceProductionUser_exists`(vUserFk INT) +BEGIN + +/* SELECT COUNT(*) AS UserExists + FROM vn.deviceProductionUser dpu + WHERE dpu.userFk = vUserFk;*/ + SELECT TRUE; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/deviceProductionUser_getWorker.sql b/db/routines/vn/procedures/deviceProductionUser_getWorker.sql new file mode 100644 index 000000000..b18339108 --- /dev/null +++ b/db/routines/vn/procedures/deviceProductionUser_getWorker.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`deviceProductionUser_getWorker`(vAndroid_id VARCHAR(64)) +BEGIN +/** + * Selecciona si hay registrado un device con un android_id + * + * @param vAndroid_id el número android_id del dispositivo + */ + SELECT account.user_getNameFromId(dpu.userFk) + FROM deviceProductionUser dpu + JOIN deviceProduction dp ON dpu.deviceProductionFk = dp.id + WHERE dp.android_id = vAndroid_id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/deviceProduction_getnameDevice.sql b/db/routines/vn/procedures/deviceProduction_getnameDevice.sql new file mode 100644 index 000000000..c8a5abfaf --- /dev/null +++ b/db/routines/vn/procedures/deviceProduction_getnameDevice.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`deviceProduction_getnameDevice`(vAndroid_id VARCHAR(64)) +BEGIN +/** + * Selecciona el id del dispositivo que corresponde al vAndroid_id. + * + * @param vAndroid_id el número android_id del dispositivo + */ + SELECT dp.id + FROM deviceProduction dp + WHERE dp.android_id = vAndroid_id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/device_checkLogin.sql b/db/routines/vn/procedures/device_checkLogin.sql new file mode 100644 index 000000000..db566a068 --- /dev/null +++ b/db/routines/vn/procedures/device_checkLogin.sql @@ -0,0 +1,43 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`device_checkLogin`(vUserFk INT, vAndroidID VARCHAR(50)) +BEGIN + +/* + * Comprueba si está registrado el dispositivo mediante su androidId + * + * @param vUSerFk el id del user + * @param vAndroidID es el identificador android_id del dispositivo + */ + DECLARE vIsAuthorized BOOL DEFAULT TRUE; + DECLARE vIsDepartment BOOL; + DECLARE vIsAllUsersAllowed BOOL; + DECLARE vMessage VARCHAR(200); + + SELECT dpc.isAllUsersallowed INTO vIsAllUsersAllowed + FROM vn.deviceProductionConfig dpc; + + IF NOT vIsAllUsersAllowed THEN + + SELECT COUNT(*) INTO vIsDepartment + FROM vn.workerDepartment dp + JOIN department d ON d.id = dp.departmentFk + WHERE dp.workerFk = vUserFk AND d.hasToCheckLogin; + + IF vIsDepartment THEN + SELECT COUNT(*) INTO vIsAuthorized + FROM vn.deviceProductionUser dpu + JOIN vn.deviceProduction dp ON dp.id = dpu.deviceProductionFk + WHERE dpu.userFk = vUserFk + AND dp.android_id = vAndroidID; + + IF NOT vIsAuthorized THEN + SET vMessage = 'Usuario no autorizado'; + END IF; + END IF; + + END IF; + + SELECT vIsAuthorized,vMessage; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/duaEntryValueUpdate.sql b/db/routines/vn/procedures/duaEntryValueUpdate.sql new file mode 100644 index 000000000..f688191de --- /dev/null +++ b/db/routines/vn/procedures/duaEntryValueUpdate.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaEntryValueUpdate`(vDuaFk INT) +BEGIN + + UPDATE duaEntry de + JOIN + ( SELECT b.entryFk, sum(b.quantity * b.buyingValue) as total + FROM buy b + JOIN duaEntry de ON de.entryFk = b.entryFk + WHERE duaFk = vDuaFk + GROUP BY b.entryFk + ) sub ON sub.entryFk = de.entryFk + + LEFT JOIN + (SELECT e.id, sum(iit.taxableBase) as euros + FROM entry e + JOIN invoiceInTax iit ON iit.invoiceInFk = e.invoiceInFk + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk + GROUP BY e.id + ) sub2 ON sub2.id = de.entryFk + + SET de.value = sub.total, + de.euroValue = sub2.euros + WHERE duaFk = vDuaFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql new file mode 100644 index 000000000..9e794f0ed --- /dev/null +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaInvoiceInBooking`(vDuaFk INT) +BEGIN + + DECLARE done BOOL DEFAULT FALSE; + DECLARE vInvoiceFk INT; + DECLARE vASIEN BIGINT DEFAULT 0; + DECLARE vCounter INT DEFAULT 0; + + DECLARE rs CURSOR FOR + SELECT e.invoiceInFk + FROM entry e + JOIN duaEntry de ON de.entryFk = e.id + JOIN invoiceIn ii ON ii.id = e.invoiceInFk + WHERE de.duaFk = vDuaFk + AND de.customsValue + AND ii.isBooked = FALSE; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + UPDATE invoiceIn ii + JOIN entry e ON e.invoiceInFk = ii.id + JOIN duaEntry de ON de.entryFk = e.id + JOIN dua d ON d.id = de.duaFk + SET ii.isBooked = TRUE, + ii.booked = IFNULL(ii.booked,d.booked), + ii.operated = IFNULL(ii.operated,d.operated), + ii.issued = IFNULL(ii.issued,d.issued), + ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried), + e.isConfirmed = TRUE + WHERE d.id = vDuaFk; + + SELECT IFNULL(ASIEN,0) INTO vASIEN + FROM dua + WHERE id = vDuaFk; + + FETCH rs INTO vInvoiceFk; + + WHILE NOT done DO + + CALL invoiceIn_booking(vInvoiceFk); + + IF vCounter > 0 OR vASIEN > 0 THEN + + UPDATE vn2008.XDiario x + JOIN vn.ledgerConfig lc ON lc.lastBookEntry = x.ASIEN + SET x.ASIEN = vASIEN; + + ELSE + + SELECT lastBookEntry INTO vASIEN FROM vn.ledgerConfig; + + END IF; + + SET vCounter = vCounter + 1; + + FETCH rs INTO vInvoiceFk; + + END WHILE; + + CLOSE rs; + + UPDATE dua + SET ASIEN = vASIEN + WHERE id = vDuaFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/duaParcialMake.sql b/db/routines/vn/procedures/duaParcialMake.sql new file mode 100644 index 000000000..9504cd38a --- /dev/null +++ b/db/routines/vn/procedures/duaParcialMake.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaParcialMake`(vDuaFk INT) +BEGIN + + DECLARE vNewDuaFk INT; + + INSERT INTO dua(awbFk,companyFk) + SELECT awbFk,companyFk + FROM dua + WHERE id = vDuaFk; + + SELECT LAST_INSERT_ID() INTO vNewDuaFk; + + INSERT INTO duaEntry(duaFk, entryFk, value, customsValue) + SELECT vNewDuaFk, entryFk, value, value - customsValue + FROM duaEntry + WHERE duaFk = vDuaFk + AND value != customsValue; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/duaTaxBooking.sql b/db/routines/vn/procedures/duaTaxBooking.sql new file mode 100644 index 000000000..1fef11e96 --- /dev/null +++ b/db/routines/vn/procedures/duaTaxBooking.sql @@ -0,0 +1,136 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaTaxBooking`(vDuaFk INT) +BEGIN + DECLARE vBookNumber INT; + DECLARE vBookDated DATE; + DECLARE vDiff DECIMAL(10,2); + DECLARE vApunte BIGINT; + + SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated + FROM dua + WHERE id = vDuaFk; + + IF vBookNumber IS NULL OR NOT vBookNumber THEN + CALL ledger_next(vBookNumber); + END IF; + + -- Apunte de la aduana + + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONCEPTO, + EUROHABER, + SERIE, + empresa_id, + CLAVE, + FACTURA) + + SELECT + vBookNumber, + d.bookEntried, + '4700000999', + CONCAT('DUA ',d.`code`), + sum(dt.base * dt.rate / 100) EUROHABER, + 'R', + d.companyFk, + vDuaFk, + vDuaFk + FROM duaTax dt + JOIN dua d ON d.id = dt.duaFk + WHERE dt.duaFk = vDuaFk; + + -- Apuntes por tipo de IVA y proveedor + + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EURODEBE, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + AUXILIAR, + SERIE, + FECHA_EX, + FECHA_OP, + FACTURAEX, + NFACTICK, + L340, + LDIFADUAN, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + TERIDNIF, + TERNIF, + TERNOM, + empresa_id, + FECREGCON + ) + + SELECT + vBookNumber ASIEN, + vBookDated FECHA, + tr.account SUBCTA, + '4330002067' CONTRA, + sum(dt.tax) EURODEBE, + sum(dt.base) BASEEURO, + CONCAT('DUA nº',d.code) CONCEPTO, + d.id FACTURA, + dt.rate IVA, + '*' AUXILIAR, + 'D' SERIE, + d.issued FECHA_EX, + d.operated FECHA_OP, + d.code FACTURAEX, + 1 NFACTICK, + 1 L340, + TRUE LDIFADUAN, + 1 TIPOCLAVE, + 1 TIPOEXENCI, + 1 TIPONOSUJE, + 5 TIPOFACT, + 1 TIPORECTIF, + IF(c.code = 'ES', 1, 4) TERIDNIF, + s.nif TERNIF, + s.name TERNOM, + d.companyFk, + d.booked FECREGCON + FROM duaTax dt + JOIN dua d ON dt.duaFk = d.id + JOIN (SELECT account, rate + FROM + (SELECT rate, account + FROM invoiceInTaxBookingAccount ta + WHERE ta.effectived <= vBookDated + AND taxAreaFk = 'WORLD' + ORDER BY ta.effectived DESC + LIMIT 10000000000000000000 + ) tba + GROUP BY rate + ) tr ON tr.rate = dt.rate + JOIN supplier s ON s.id = d.companyFk + JOIN country c ON c.id = s.countryFk + WHERE d.id = vDuaFk + GROUP BY dt.rate; + + SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte + FROM XDiario + WHERE ASIEN = vBookNumber; + + UPDATE XDiario + SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA, + EURODEBE = EURODEBE - vDiff + WHERE id = vApunte; + + UPDATE dua + SET ASIEN = vBookNumber + WHERE id = vDuaFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/duaTax_doRecalc.sql b/db/routines/vn/procedures/duaTax_doRecalc.sql new file mode 100644 index 000000000..e2d2b347f --- /dev/null +++ b/db/routines/vn/procedures/duaTax_doRecalc.sql @@ -0,0 +1,54 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaTax_doRecalc`(vDuaFk INT) +BEGIN +/** + * Borra los valores de duaTax y los vuelve a crear en base a la tabla duaEntry + * + * @param vDuaFk Id del dua a recalcular + */ + DELETE FROM duaTax + WHERE duaFk = vDuaFk; + + INSERT INTO duaTax(duaFk, taxClassFk, base) + SELECT vDuaFk, taxClassFk, SUM(sub.totalBase) + FROM intrastat ist + JOIN + (SELECT i.intrastatFk, + CAST(SUM(b.quantity * + b.buyingValue * + de.customsValue / + de.value) + * di.totalAmount / + bi.totalAmount AS DECIMAL(10,2) + ) totalBase + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN entry e ON e.id = b.entryFk + JOIN duaEntry de ON de.entryFk = e.id + JOIN( + SELECT i.intrastatFk, + CAST(SUM(b.quantity * + b.buyingValue * + de.customsValue / + de.value) AS DECIMAL(10,2) + ) totalAmount + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN entry e ON e.id = b.entryFk + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk + GROUP BY i.intrastatFk + ) bi ON bi.intrastatFk = i.intrastatFk + JOIN( + SELECT intrastatFk, SUM(amount) totalAmount + FROM duaIntrastat + WHERE duaFk = vDuaFk + GROUP BY intrastatFK + ) di ON di.intrastatFk = i.intrastatFk + WHERE de.duaFk = vDuaFk + GROUP BY i.intrastatFk + HAVING totalBase + )sub ON ist.id = sub.intrastatFk + GROUP BY ist.taxClassFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ediTables_Update.sql b/db/routines/vn/procedures/ediTables_Update.sql new file mode 100644 index 000000000..3f0c6df04 --- /dev/null +++ b/db/routines/vn/procedures/ediTables_Update.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ediTables_Update`() +BEGIN + + INSERT IGNORE INTO vn.genus(name) + SELECT latin_genus_name + FROM edi.genus ; + + INSERT IGNORE INTO vn.specie(name) + SELECT LCASE(latin_species_name) + FROM edi.specie ; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ektEntryAssign_setEntry.sql b/db/routines/vn/procedures/ektEntryAssign_setEntry.sql new file mode 100644 index 000000000..441555ad5 --- /dev/null +++ b/db/routines/vn/procedures/ektEntryAssign_setEntry.sql @@ -0,0 +1,112 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ektEntryAssign_setEntry`() +BEGIN + +DECLARE done INT DEFAULT FALSE; +DECLARE vEntryFk INT; +DECLARE vTravelFk INT; +DECLARE vId INT; +DECLARE vLanded DATE DEFAULT util.VN_CURDATE(); + +DECLARE cur1 CURSOR FOR SELECT id FROM vn.ektEntryAssign; + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + IF HOUR(util.VN_NOW()) > 12 THEN + + SET vLanded = TIMESTAMPADD(DAY,1,vLanded); + + END IF; + +OPEN cur1; + + read_loop: LOOP + + SET done = FALSE; + SET vEntryFk = 0; + + FETCH cur1 INTO vId; + + IF done THEN + LEAVE read_loop; + END IF; + + SELECT IFNULL(e.id,0) INTO vEntryFk + FROM vn.entry e + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + AND ea.warehouseInFk = tr.warehouseInFk + AND ea.agencyModeFk = tr.agencyModeFk + AND ea.supplierFk = e.supplierFk + WHERE ea.id = vId + AND tr.landed = vLanded + LIMIT 1; + + IF NOT vEntryFk THEN + + SELECT IFNULL(e.id,0) INTO vEntryFk + FROM vn.entry e + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + AND ea.warehouseInFk = tr.warehouseInFk + AND ea.agencyModeFk = tr.agencyModeFk + WHERE ea.id = vId + AND tr.landed = vLanded + AND ea.supplierFk IS NULL + LIMIT 1; + + END IF; + + IF NOT vEntryFk THEN + + SET vTravelFk = 0; + + SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk + FROM vn.travel tr + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + AND ea.warehouseInFk = tr.warehouseInFk + AND ea.agencyModeFk = tr.agencyModeFk + WHERE ea.id = vId + AND tr.landed = vLanded; + + IF NOT vTravelFk THEN + + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) + SELECT vLanded, vLanded, warehouseInFk, warehouseOutFk, agencyModeFk + FROM vn.ektEntryAssign + WHERE id = vId; + + SELECT MAX(tr.id) INTO vTravelFk + FROM vn.travel tr + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + AND ea.warehouseInFk = tr.warehouseInFk + AND ea.agencyModeFk = tr.agencyFk + WHERE ea.id = vId + AND tr.landed = vLanded; + + END IF; + + INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk) + SELECT vTravelFk, IFNULL(ea.supplierFk,s.id), c.id, cu.id + FROM vn.supplier s + JOIN vn.company c ON c.code = 'VNL' + JOIN vn.currency cu ON cu.code = 'EUR' + JOIN vn.ektEntryAssign ea ON ea.id = vId + WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; + + SELECT MAX(id) INTO vEntryFk + FROM vn.entry + WHERE travelFk = vTravelFk; + + END IF; + + UPDATE vn.ektEntryAssign + SET entryFk = vEntryFk + WHERE id = vId; + + END LOOP; + + CLOSE cur1; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/energyMeter_record.sql b/db/routines/vn/procedures/energyMeter_record.sql new file mode 100644 index 000000000..113f73e19 --- /dev/null +++ b/db/routines/vn/procedures/energyMeter_record.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`energyMeter_record`(vInput INT, vActiveTime INT) +BEGIN + DECLARE vConsumption INT; + + SELECT consumption INTO vConsumption + FROM energyInput + WHERE input = vInput; + + INSERT INTO vn.energyMeter + SET + `input` = vInput, + `period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'), + `activeTime` = vActiveTime, + `consumption` = CAST(IFNULL((vConsumption / 3600) * vActiveTime, 0) AS DECIMAL(10,2)) + ON DUPLICATE KEY UPDATE + `activeTime` = `activeTime` + vActiveTime, + `consumption` = `consumption` + CAST(VALUES(`consumption`) AS DECIMAL(10,2)); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entryDelivered.sql b/db/routines/vn/procedures/entryDelivered.sql new file mode 100644 index 000000000..e948770e8 --- /dev/null +++ b/db/routines/vn/procedures/entryDelivered.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entryDelivered`(vDated DATE, vEntryFk INT) +BEGIN + + DECLARE vTravelFk INT; + + SELECT travelFk INTO vTravelFk + FROM vn.entry + WHERE id = vEntryFk; + + IF (SELECT COUNT(*) FROM vn.entry WHERE travelFk = vTravelFk) = 1 THEN + + UPDATE vn.travel SET shipped = LEAST(shipped, vDated), landed = vDated + WHERE id = vTravelFk; + + ELSE + + INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, ref, isDelivered, isReceived) + SELECT LEAST(shipped, vDated), vDated, warehouseInFk, warehouseOutFk, agencyModeFk, CONCAT(account.myUser_getName(),' ', vEntryFk), TRUE, TRUE + FROM vn.travel WHERE id = vTravelFk; + + SELECT LAST_INSERT_ID() INTO vTravelFk; + + UPDATE vn.entry + SET travelFk = vTravelFk + WHERE id = vEntryFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entryWithItem.sql b/db/routines/vn/procedures/entryWithItem.sql new file mode 100644 index 000000000..30dd99fbf --- /dev/null +++ b/db/routines/vn/procedures/entryWithItem.sql @@ -0,0 +1,54 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entryWithItem`(vShipmentWarehouse INT, vLandingWarehouse INT,vSale INT, vVolume INT, netCost DECIMAL(10,2), vInOutDate DATE) +BEGIN + + DECLARE vTravel INT; + DECLARE vEntry INT; + DECLARE vBucket VARCHAR(10); + DECLARE vSupplierFk INT; + + SET vSupplierFk = IF (vLandingWarehouse = 1, 850, 963); + -- seleccionamos travel + SELECT t.id, e.id INTO vTravel, vEntry + FROM travel t LEFT JOIN entry e ON t.id = e.travelFk + WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse + AND t.warehouseInFk = vLandingWarehouse AND t.agencyModeFk IS NULL AND e.supplierFk = vSupplierFk + LIMIT 1; + + -- creamos el travel si es necesario + IF IFNULL(vTravel, FALSE) = FALSE THEN + INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk) + VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + + -- creamos la Entrada si es necesario + IF IFNULL(vEntry, FALSE) = FALSE THEN + INSERT INTO entry (supplierFk, travelFk) + VALUES (vSupplierFk, vTravel); -- proveedor 'CONFECCION ARTIFICIAL' + SELECT LAST_INSERT_ID() INTO vEntry; + END IF; + + -- creamos el cubo si es necesario + SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; + IF vBucket IS NULL THEN + INSERT INTO packaging (id, volume) + VALUES (CONCAT('dm',vVolume/1000), vVolume); + -- SELECT LAST_INSERT_ID() INTO vBucket; + SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; + END IF; + + INSERT INTO buy(itemFk,quantity, entryFk, packagingFk, packing, stickers, buyingValue, price2, price3) + SELECT itemFk, + quantity, + vEntry, + vBucket, + 1 packing, + quantity, + netCost, + s.price, + s.price + FROM sale s + WHERE s.id = vSale; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_checkPackaging.sql b/db/routines/vn/procedures/entry_checkPackaging.sql new file mode 100644 index 000000000..7ba47b3d5 --- /dev/null +++ b/db/routines/vn/procedures/entry_checkPackaging.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkPackaging`(vEntryFk INT) +BEGIN +/** + * Comprueba que los campos package y packaging no sean nulos + * + * @param vEntryFk Id de entrada + */ + DECLARE vpackageOrPackingNull INT; + + SELECT count(*) INTO vpackageOrPackingNull + FROM buy b + WHERE b.entryFk = vEntryFk + AND (b.packing IS NULL OR b.packagingFk IS NULL); + + IF vpackageOrPackingNull THEN + CALL util.throw("packageOrPackingNull"); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql new file mode 100644 index 000000000..4f38447c8 --- /dev/null +++ b/db/routines/vn/procedures/entry_clone.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_clone`(vSelf INT) +BEGIN +/** + * clones an entry. + * + * @param vSelf The entry id + */ + DECLARE vNewEntryFk INT; + + START TRANSACTION; + + CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL); + CALL entry_copyBuys(vSelf, vNewEntryFk); + + COMMIT; + + SELECT vNewEntryFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_cloneHeader.sql b/db/routines/vn/procedures/entry_cloneHeader.sql new file mode 100644 index 000000000..6a6df9194 --- /dev/null +++ b/db/routines/vn/procedures/entry_cloneHeader.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_cloneHeader`( + vSelf INT, + OUT vNewEntryFk INT, + vTravelFk INT +) +BEGIN +/** + * Clones an entry header. + * + * @param vSelf The entry id + * @param vTravelFk Travel for the new entry or %NULL to use the source entry travel + * @param vNewEntryFk The new entry id + */ + INSERT INTO entry( + travelFk, + supplierFk, + dated, + isExcludedFromAvailable, + isRaid, + commission, + currencyFk, + companyFk, + clonedFrom, + typeFk + ) + SELECT IFNULL(vTravelFk, travelFk), + supplierFk, + dated, + isExcludedFromAvailable, + isRaid, + commission, + currencyFk, + companyFk, + vSelf, + typeFk + FROM entry + WHERE id = vSelf; + + SET vNewEntryFk = LAST_INSERT_ID(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_cloneWithoutBuy.sql b/db/routines/vn/procedures/entry_cloneWithoutBuy.sql new file mode 100644 index 000000000..8d75d8d51 --- /dev/null +++ b/db/routines/vn/procedures/entry_cloneWithoutBuy.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_cloneWithoutBuy`(vSelf INT, OUT vNewEntryFk INT) +BEGIN +/** + * Clona una entrada sin compras + * + * @param vSelf Identificador de vn.entry + * @param vNewEntryFk Identificador de la nueva entrada + */ + START TRANSACTION; + + CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL); + + UPDATE entry d JOIN entry s ON s.id = vSelf + SET d.`reference` = s.`reference`, + d.loadPriority = s.loadPriority + WHERE d.id = vNewEntryFk; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_copyBuys.sql b/db/routines/vn/procedures/entry_copyBuys.sql new file mode 100644 index 000000000..a00fbc846 --- /dev/null +++ b/db/routines/vn/procedures/entry_copyBuys.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_copyBuys`(vSelf INT, vCopyTo INT) +BEGIN +/** + * Copies an entry buys to another buy. + * + * @param vSelf The entry id + * @param vCopyTo The destination entry id + */ + INSERT INTO buy( + entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packagingFk, + price1, + price2, + price3, + minPrice, + isChecked, + location, + weight, + itemOriginalFk + ) + SELECT vCopyTo, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packagingFk, + price1, + price2, + price3, + minPrice, + isChecked, + location, + weight, + itemOriginalFk + FROM buy + WHERE entryFk = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_fixMisfit.sql b/db/routines/vn/procedures/entry_fixMisfit.sql new file mode 100644 index 000000000..3e57d362e --- /dev/null +++ b/db/routines/vn/procedures/entry_fixMisfit.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_fixMisfit`( + vSelf INT +) +BEGIN +/** + * Arregla el descuadre de una entrada, agregando registros en vn.buy + * para compensar la diferencia * entre las etiquetas impresas y las esperadas + * + * @param vSelf Identificador de la entrada + */ + INSERT INTO vn.buy(entryFk, itemFk) + SELECT vSelf, i.id + FROM vn.item i + WHERE i.description = 'MISFIT' + LIMIT 1; + + INSERT INTO vn.buy( + entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + weight) + SELECT vSelf, + itemFk, + SUM(CAST(printedStickers AS INT) - stickers) * packing quantity, + buyingValue, + freightValue, + TRUE isIgnored, + CAST(printedStickers AS INT) - stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + weight + FROM buy b + WHERE b.entryFk = vSelf + AND b.printedStickers <> b.stickers + GROUP BY itemFk + HAVING quantity; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_getRate.sql b/db/routines/vn/procedures/entry_getRate.sql new file mode 100644 index 000000000..2220ef999 --- /dev/null +++ b/db/routines/vn/procedures/entry_getRate.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getRate`(vSelf INT) +BEGIN +/** + * Prepara una tabla con las tarifas aplicables en funcion de la fecha + * y el almacén + * + * @param vSelf Id de la tabla entry + * @return tmp.rate (rate0, rate1, rate2, rate3) + */ + DECLARE vDated DATE; + DECLARE vWarehouseFk INT; + + SELECT t.landed, t.warehouseInFk INTO vDated, vWarehouseFk + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.id = vSelf; + + CALL rate_getPrices(vDated, vWarehouseFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_lock.sql b/db/routines/vn/procedures/entry_lock.sql new file mode 100644 index 000000000..8ec50323b --- /dev/null +++ b/db/routines/vn/procedures/entry_lock.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_lock`(vSelf INT) +BEGIN +/** + * Lock the indicated entry + * @vSelf params entry id + */ + UPDATE `entry` + SET lockerUserFk = account.myUser_getId(), + locked = util.VN_NOW() + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_moveNotPrinted.sql b/db/routines/vn/procedures/entry_moveNotPrinted.sql new file mode 100644 index 000000000..526ae9d43 --- /dev/null +++ b/db/routines/vn/procedures/entry_moveNotPrinted.sql @@ -0,0 +1,177 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_moveNotPrinted`(vSelf INT, + vDays INT, + vChangeEntry BOOL, + OUT vNewEntryFk INT) +BEGIN +/** + * Crea una entrada a futuro y divide las lineas de buy de + * la entrada original en función de las etiquetas impresas + * + * @param vSelf Identificador de entry + * @param vDays Número de dias a futuro que se quiere la nueva entrada + * @param vChangeEntry Si se modifica la entrada original + * + * @return vNewEntryFk Identificador de la nueva entrada + */ + DECLARE vNewTravelFk INT; + DECLARE vTravelFk INT; + DECLARE vInvoiceAmountOldEntryFk DECIMAL(10,2); + DECLARE vInvoiceAmountNewEntry DECIMAL(10,2); + DECLARE vIsOrdered BOOL; + DECLARE vIsConfirmed BOOL; + DECLARE vInvoiceNumber VARCHAR(50); + DECLARE vTypeFk VARCHAR(100); + + SELECT travelFk, isOrdered, isConfirmed, invoiceNumber, typeFk INTO vTravelFk, vIsOrdered, vIsConfirmed, vInvoiceNumber, vTypeFk + FROM entry + WHERE id = vSelf; + + CALL travel_clone(vTravelFk, vDays, vNewTravelFk); + CALL entry_cloneWithoutBuy(vSelf, vNewEntryFk); + + UPDATE entry e + SET e.travelFk = vNewTravelFk, + e.evaNotes = CONCAT('No impresas de: ', vSelf, ' ', IFNULL(e.evaNotes,'')), + e.isOrdered = vIsOrdered, + e.isConfirmed = vIsConfirmed, + e.invoiceNumber = vInvoiceNumber, + e.typeFk = vTypeFk + WHERE e.id = vNewEntryFk; + + IF vChangeEntry THEN + UPDATE buy b + SET b.entryFk = vNewEntryFk + WHERE b.printedStickers = 0 + AND b.entryFk = vSelf; + END IF; + + INSERT INTO buy(entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + weight, + itemOriginalFk) + SELECT vNewEntryFk, + itemFk, + ((stickers - CAST(printedStickers AS INT)) * packing) quantity, + buyingValue, + freightValue, + isIgnored, + (stickers - CAST(printedStickers AS INT)) stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + weight, + itemOriginalFk + FROM buy b + WHERE b.entryFk = vSelf + AND b.printedStickers != b.stickers; + + IF vChangeEntry THEN + UPDATE buy + SET stickers = printedStickers, + quantity = printedStickers * packing + WHERE entryFk = vSelf; + ELSE + INSERT INTO buy(entryFk, itemFk) + SELECT vSelf, i.id + FROM item i + WHERE i.description = 'MISFIT' + LIMIT 1; + + INSERT INTO buy(entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice) + SELECT vSelf, + itemFk, + (CAST(printedStickers AS INT) - stickers) * packing quantity, + buyingValue, + freightValue, + TRUE isIgnored, + CAST(printedStickers AS INT) - stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice + FROM buy + WHERE entryFk = vSelf + AND printedStickers != stickers; + END IF; + + SELECT SUM(IFNULL(b.buyingValue * b.quantity, 0)) INTO vInvoiceAmountOldEntryFk + FROM buy b + WHERE b.entryFk = vSelf; + + UPDATE entry e + JOIN buy b ON b.entryFk = e.id + SET e.reference = CONCAT(e.reference,'(1)'), + e.invoiceAmount = vInvoiceAmountOldEntryFk + WHERE e.id = vSelf; + + SELECT SUM(IFNULL(b.buyingValue * b.quantity, 0)) INTO vInvoiceAmountNewEntry + FROM buy b + WHERE b.entryFk = vNewEntryFk; + + UPDATE entry e + JOIN buy b ON b.entryFk = e.id + SET e.reference = CONCAT(e.reference,'(2)'), + e.invoiceAmount = vInvoiceAmountNewEntry + WHERE e.id = vNewEntryFk; + + UPDATE entry + SET gestDocFk = (SELECT gestDocFk FROM entry WHERE id = vSelf LIMIT 1) + WHERE id = vNewEntryFk; + + INSERT INTO duaEntry (duaFk, entryFk) + SELECT duaFk, vNewEntryFk FROM duaEntry WHERE entryFk = vSelf LIMIT 1; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_notifyChanged.sql b/db/routines/vn/procedures/entry_notifyChanged.sql new file mode 100644 index 000000000..11e6fe4c0 --- /dev/null +++ b/db/routines/vn/procedures/entry_notifyChanged.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_notifyChanged`(vSelf INT, vBuyFk INT, vOldValues VARCHAR(512), vNewValues VARCHAR(512)) +BEGIN + DECLARE vEmail VARCHAR(255); + DECLARE vFields VARCHAR(100); + DECLARE vMessage TEXT; + + SELECT e.mailToNotify INTO vEmail + FROM entryConfig e + LIMIT 1; + + SET vFields = CONCAT_WS(',', + 'entryFk', + 'itemFk', + 'quantity', + 'price1', + 'price2', + 'price3' + ); + SET vMessage = util.formatTable(vFields, vOldValues, vNewValues); + + CALL mail_insert( + vEmail, + NULL, + CONCAT( + 'Se ha modificado una línea de la entrada ', vSelf + ,' siendo inventario o anterior al mismo' + ), + vMessage + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_recalc.sql b/db/routines/vn/procedures/entry_recalc.sql new file mode 100644 index 000000000..2410d380d --- /dev/null +++ b/db/routines/vn/procedures/entry_recalc.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_recalc`() +BEGIN +/** + * Comprueba que las ventas creadas entre un rango de fechas tienen componentes + * + * @param vCreatedFrom inicio del rango + * @param vCreatedTo fin del rango + */ + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vEntryFk INTEGER; + + DECLARE vCur CURSOR FOR + SELECT id FROM tmp.recalcEntryCommision; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + OPEN vCur; + + l: LOOP + SET v_done = FALSE; + FETCH vCur INTO vEntryFk; + + IF v_done THEN + LEAVE l; + END IF; + + CALL vn2008.buy_tarifas_entry(vEntryFk); + END LOOP; + + CLOSE vCur; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql new file mode 100644 index 000000000..b7d9c77b3 --- /dev/null +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -0,0 +1,131 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_splitByShelving`(vShelvingFk VARCHAR(3), vFromEntryFk INT, vToEntryFk INT) +BEGIN +/** + * Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr�cula + * + * @param vShelvingFk Identificador de vn.shelving + * @param vFromEntryFk Entrada origen + * @param vToEntryFk Entrada destino + */ + DECLARE vBuyFk INT; + DECLARE vIshStickers INT; + DECLARE vBuyStickers INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; + + DECLARE cur CURSOR FOR + SELECT bb.id buyFk, + FLOOR(ish.visible / ish.packing) ishStickers, + bb.stickers buyStickers + FROM vn.itemShelving ish + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM vn.buy b + WHERE b.entryFk = vFromEntryFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + AND bb.stickers >= FLOOR(ish.visible / ish.packing) + WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci + GROUP BY ish.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + -- Cantidades de la matrícula que exceden la de las entradas + SELECT ish.itemFk, + i.longName, + FLOOR(ish.visible / ish.packing) AS etiEnMatricula, + bb.stickers etiEnEntrada + FROM vn.itemShelving ish + JOIN vn.item i ON i.id = ish.itemFk + LEFT JOIN (SELECT b.id, b.itemFk, b.stickers + FROM vn.buy b + WHERE b.entryFk = vFromEntryFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci + AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing) + GROUP BY ish.id; + + OPEN cur; + + read_loop: LOOP + SET vDone = FALSE; + + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + + IF vDone THEN + LEAVE read_loop; + END IF; + + IF vIshStickers = vBuyStickers THEN + UPDATE vn.buy + SET entryFk = vToEntryFk + WHERE id = vBuyFk; + ELSE + UPDATE vn.buy + SET stickers = stickers - vIshStickers, + quantity = stickers * packing + WHERE id = vBuyFk; + + INSERT INTO vn.buy(entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + isChecked, + isPickedOff, + ektFk, + weight, + deliveryFk, + itemOriginalFk) + SELECT + vToEntryFk, + itemFk, + vIshStickers * packing, + buyingValue, + freightValue, + isIgnored, + vIshStickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + isChecked, + isPickedOff, + ektFk, + weight, + deliveryFk, + itemOriginalFk + FROM vn.buy + WHERE id = vBuyFk; + + UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); + END IF; + END LOOP; + + CLOSE cur; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_splitMisfit.sql b/db/routines/vn/procedures/entry_splitMisfit.sql new file mode 100644 index 000000000..476c52689 --- /dev/null +++ b/db/routines/vn/procedures/entry_splitMisfit.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_splitMisfit`(vSelf INT) +BEGIN + + /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original + * a la nueva + */ + + DECLARE vNewEntryFk INT; + DECLARE vBuyFk INT; + + SELECT MAX(b.id) INTO vBuyFk + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + WHERE b.entryFk = vSelf + AND i.description = 'MISFIT'; + + INSERT INTO vn.entry(supplierFk, dated, travelFk, currencyFk, companyFk) + SELECT supplierFk, dated, travelFk, currencyFk, companyFk + FROM vn.entry e + WHERE e.id = vSelf; + + SET vNewEntryFk = LAST_INSERT_ID(); + + UPDATE vn.buy b + SET b.entryFk = vNewEntryFk + WHERE b.entryFk = vSelf + AND b.id > vBuyFk; + + SELECT vNewEntryFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_unlock.sql b/db/routines/vn/procedures/entry_unlock.sql new file mode 100644 index 000000000..1dab48974 --- /dev/null +++ b/db/routines/vn/procedures/entry_unlock.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_unlock`(vSelf INT) +BEGIN +/** + * Unlock the indicated entry + * @vSelf params entry id + */ + UPDATE `entry` + SET lockerUserFk = NULL, + locked = NULL + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/.archive/232601/00-entry_updateComission.sql b/db/routines/vn/procedures/entry_updateComission.sql similarity index 96% rename from db/.archive/232601/00-entry_updateComission.sql rename to db/routines/vn/procedures/entry_updateComission.sql index 5a25d72e8..1bef79bd3 100644 --- a/db/.archive/232601/00-entry_updateComission.sql +++ b/db/routines/vn/procedures/entry_updateComission.sql @@ -1,5 +1,4 @@ DELIMITER $$ -$$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_updateComission`(vCurrency INT) BEGIN /** @@ -32,9 +31,9 @@ BEGIN SELECT util.notification_send( 'entry-update-comission', JSON_OBJECT('currencyName', vCurrencyName, 'referenceCurrent', vComission), - account.myUser_getId() + NULL ); DROP TEMPORARY TABLE tmp.recalcEntryCommision; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionGetFromRoute.sql b/db/routines/vn/procedures/expeditionGetFromRoute.sql new file mode 100644 index 000000000..46c3c5d70 --- /dev/null +++ b/db/routines/vn/procedures/expeditionGetFromRoute.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionGetFromRoute`( + vExpeditionFk INT) +BEGIN +/** + * Get all expeditions from route + */ + DECLARE vRouteFk INT DEFAULT 0; + + SELECT t.routeFk INTO vRouteFk + FROM vn.expedition exp + INNER JOIN ticket t on t.id = exp.ticketFk + WHERE exp.id = vExpeditionFk; + + SELECT exp.id, + exp.ticketFk, + t.routeFk, + t.packages bultos, + ts.alertLevel, + a.street, + a.city, + a.postalCode, + a.id addressFk, + w.name warehouse + FROM vn.expedition exp + INNER JOIN ticket t ON t.id = exp.ticketFk + INNER JOIN vn.ticketState ts ON ts.ticketFk = exp.ticketFk + LEFT JOIN vn.address a ON t.addressFk = a.id + LEFT JOIN vn.warehouse w ON t.warehouseFk = w.id + WHERE t.routeFk = vRouteFk AND exp.freightItemFk > 0; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionPallet_Del.sql b/db/routines/vn/procedures/expeditionPallet_Del.sql new file mode 100644 index 000000000..451815ca0 --- /dev/null +++ b/db/routines/vn/procedures/expeditionPallet_Del.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_Del`(vPalletFk INT) +BEGIN + + DELETE FROM vn.expeditionPallet + WHERE id = vPalletFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionPallet_List.sql b/db/routines/vn/procedures/expeditionPallet_List.sql new file mode 100644 index 000000000..db7cd6f0e --- /dev/null +++ b/db/routines/vn/procedures/expeditionPallet_List.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_List`(vTruckFk INT) +BEGIN + + SELECT ep.id Pallet, + count(DISTINCT t.routeFk) Rutas, + count(DISTINCT e.id) Eti + FROM vn.expeditionPallet ep + LEFT JOIN vn.expeditionScan es ON es.palletFk = ep.id + LEFT JOIN vn.expedition e ON e.id = es.expeditionFk + LEFT JOIN vn.ticket t ON t.id = e.ticketFk + WHERE ep.truckFk = vTruckFk + GROUP BY ep.id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionPallet_View.sql b/db/routines/vn/procedures/expeditionPallet_View.sql new file mode 100644 index 000000000..fe410b2fb --- /dev/null +++ b/db/routines/vn/procedures/expeditionPallet_View.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_View`(vPalletFk INT) +BEGIN + + SELECT ep.id Pallet, + t.routeFk Rutas, + count(*) Cajas + FROM vn.expeditionPallet ep + LEFT JOIN vn.expeditionScan es ON es.palletFk = ep.id + LEFT JOIN vn.expedition e ON e.id = es.expeditionFk + LEFT JOIN vn.ticket t ON t.id = e.ticketFk + WHERE ep.id = vPalletFk + GROUP BY t.routeFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql new file mode 100644 index 000000000..9fbb60100 --- /dev/null +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -0,0 +1,100 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_build`(IN vExpeditions JSON, IN vArcId INT, IN vWorkerFk INT, OUT vPalletFk INT) +BEGIN +/** Construye un pallet de expediciones. + * + * Primero comprueba si esas expediciones ya pertenecen a otro pallet, + * en cuyo caso actualiza ese pallet. + * + * @param vExpeditions JSON_ARRAY con esta estructura [exp1, exp2, exp3, ...] + * @param vArcId INT Identificador de vn.arcRead + * @param vWorkerFk INT Identificador de vn.worker + * @param out vPalletFk Identificador de vn.expeditionPallet + */ + DECLARE vCounter INT; + DECLARE vExpeditionFk INT; + DECLARE vTruckFk INT; + DECLARE vPrinterFk INT; + + DROP TEMPORARY TABLE IF EXISTS tExpedition; + CREATE TEMPORARY TABLE tExpedition + SELECT + e.id expeditionFk, + r.id routeFk, + ep.id palletFk + FROM + vn.expedition e, + vn.route r, + vn.expeditionPallet ep + LIMIT 0; + + ALTER TABLE tExpedition ADD PRIMARY KEY (expeditionFk); + + SET vCounter = JSON_LENGTH(vExpeditions); + + WHILE vCounter DO + SET vCounter = vCounter - 1; + + SET vExpeditionFk = JSON_EXTRACT(vExpeditions,CONCAT("$[", vCounter, "]")); + + INSERT IGNORE INTO tExpedition(expeditionFk, routeFk, palletFk) + SELECT vExpeditionFk, t.routeFk, es.palletFk + FROM vn.expedition e + LEFT JOIN vn.ticket t ON t.id = e.ticketFk + LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id + WHERE e.id = vExpeditionFk; + END WHILE; + + SELECT palletFk INTO vPalletFk + FROM ( + SELECT palletFk, count(*) n + FROM tExpedition + WHERE palletFk > 0 + GROUP BY palletFk + ORDER BY n DESC + LIMIT 100 ) sub + LIMIT 1; + + IF vPalletFk IS NULL THEN + SELECT expeditionTruckFk + INTO vTruckFk + FROM ( + SELECT rm.expeditionTruckFk, count(*) n + FROM vn.routesMonitor rm + JOIN tExpedition e ON e.routeFk = rm.routeFk + GROUP BY expeditionTruckFk + ORDER BY n DESC + LIMIT 1) sub; + + IF vTruckFk IS NULL THEN + CALL util.throw ('TRUCK_NOT_AVAILABLE'); + END IF; + + INSERT INTO vn.expeditionPallet(truckFk) + VALUES(vTruckFk); + + SET vPalletFk = LAST_INSERT_ID(); + END IF; + + INSERT INTO vn.expeditionScan(expeditionFk, palletFk, workerFk) + SELECT expeditionFk, vPalletFk, vWorkerFk + FROM tExpedition + ON DUPLICATE KEY UPDATE palletFk = vPalletFk, workerFk = vWorkerFk; + + SELECT printerFk INTO vPrinterFk + FROM vn.arcRead + WHERE id = vArcId; + + CALL vn.report_print( + 'LabelPalletExpedition', + vPrinterFk, + account.myUser_getId(), + JSON_OBJECT('palletFk', vPalletFk, 'userFk', account.myUser_getId()), + 'high' + ); + + UPDATE vn.expeditionPallet SET isPrint = TRUE WHERE id = vPalletFk; + + DROP TEMPORARY TABLE tExpedition; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionPallet_printLabel.sql b/db/routines/vn/procedures/expeditionPallet_printLabel.sql new file mode 100644 index 000000000..ada11daab --- /dev/null +++ b/db/routines/vn/procedures/expeditionPallet_printLabel.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionPallet_printLabel`(vSelf INT) +BEGIN +/** + * Calls the report_print procedure and passes it + * the necessary parameters for printing. + * + * @param vSelf expeditioPallet id. + */ + DECLARE vPrinterFk INT; + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SELECT o.labelerFk INTO vPrinterFk + FROM operator o + WHERE o.workerFk = vUserFk; + + CALL vn.report_print( + 'LabelPalletExpedition', + vPrinterFk, + account.myUser_getId(), + JSON_OBJECT('palletFk', vSelf, 'userFk', vUserFk), + 'high' + ); + + UPDATE vn.expeditionPallet + SET isPrint = TRUE + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionScan_Add.sql b/db/routines/vn/procedures/expeditionScan_Add.sql new file mode 100644 index 000000000..6ab19e8d0 --- /dev/null +++ b/db/routines/vn/procedures/expeditionScan_Add.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionScan_Add`(vPalletFk INT, vTruckFk INT) +BEGIN + + DECLARE vTotal INT DEFAULT 0; + + IF vPalletFk = 0 THEN -- Nuevo pallet + + INSERT INTO vn.expeditionPallet(truckFk) + VALUES(vTruckFk); + + SELECT LAST_INSERT_ID() INTO vPalletFk; + + END IF; + + SELECT COUNT(expeditionFk) INTO vTotal FROM vn.expeditionScan WHERE palletFk = vPalletFk; + + IF vTotal <> 0 THEN + SELECT expeditionFk, + palletFk + FROM vn.expeditionScan + WHERE palletFk = vPalletFk; + ELSE + SELECT 0 expeditionFk,vPalletFk palletFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionScan_Del.sql b/db/routines/vn/procedures/expeditionScan_Del.sql new file mode 100644 index 000000000..ecbfdad4b --- /dev/null +++ b/db/routines/vn/procedures/expeditionScan_Del.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionScan_Del`(vScanFk INT) +BEGIN + + DELETE FROM vn.expeditionScan + WHERE id = vScanFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionScan_List.sql b/db/routines/vn/procedures/expeditionScan_List.sql new file mode 100644 index 000000000..b0d53053f --- /dev/null +++ b/db/routines/vn/procedures/expeditionScan_List.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionScan_List`(vPalletFk INT) +BEGIN + + SELECT es.id, + t.routeFk Ruta, + t.id Ticket, + e.counter Caja, + es.expeditionFk + FROM vn.expeditionScan es + JOIN vn.expedition e ON e.id = es.expeditionFk + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE es.palletFk = vPalletFk + ORDER BY Ruta, Ticket, Caja; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionScan_Put.sql b/db/routines/vn/procedures/expeditionScan_Put.sql new file mode 100644 index 000000000..9744a7cd7 --- /dev/null +++ b/db/routines/vn/procedures/expeditionScan_Put.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionScan_Put`(vPalletFk INT, vExpeditionFk INT) +BEGIN + + REPLACE vn.expeditionScan(expeditionFk, palletFk) + VALUES(vExpeditionFk, vPalletFk); + + SELECT LAST_INSERT_ID() INTO vPalletFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionState_add.sql b/db/routines/vn/procedures/expeditionState_add.sql new file mode 100644 index 000000000..299f11b04 --- /dev/null +++ b/db/routines/vn/procedures/expeditionState_add.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionState_add`(vParam INT, vStateCode VARCHAR(100)) +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro + * + * @param vParam Identificador de vn.expedition o de vn.route + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT e.id, est.id + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.expeditionStateType est ON est.code = vStateCode + WHERE t.routeFk = vParam; + + ELSE + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT vParam, est.id + FROM vn.expeditionStateType est + WHERE est.code = vStateCode; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionState_addByAdress.sql b/db/routines/vn/procedures/expeditionState_addByAdress.sql new file mode 100644 index 000000000..1d8de9745 --- /dev/null +++ b/db/routines/vn/procedures/expeditionState_addByAdress.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionState_addByAdress`(vAdressFk INT, vRouteFk INT, vStateCode VARCHAR(100)) +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState + * + * @param vAdressFk Identificador de vn.ticket + * @param vRouteFk Identificador de vn.route + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT e.id, est.id + FROM vn.expedition e + JOIN vn.expeditionStateType est ON est.code = vStateCode + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionState_addByExpedition.sql b/db/routines/vn/procedures/expeditionState_addByExpedition.sql new file mode 100644 index 000000000..6fbc205e5 --- /dev/null +++ b/db/routines/vn/procedures/expeditionState_addByExpedition.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionState_addByExpedition`(vExpeditionFk INT, vStateCode VARCHAR(100)) +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState + * + * @param vExpeditionFk Identificador de vn.expedition + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT vExpeditionFk, est.id + FROM vn.expeditionStateType est + WHERE est.code = vStateCode; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionState_addByPallet.sql b/db/routines/vn/procedures/expeditionState_addByPallet.sql new file mode 100644 index 000000000..af99b444d --- /dev/null +++ b/db/routines/vn/procedures/expeditionState_addByPallet.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionState_addByPallet`(vPalletFk INT, vStateCode VARCHAR(100)) +BEGIN +/** + * Inserta nuevos registros en la tabla vn.expeditionState + * + * @param vPalletFk Identificador de vn.expedition + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + DECLARE hasExpeditions BOOL; + + DROP TEMPORARY TABLE IF EXISTS tExpeditionScan; + CREATE TEMPORARY TABLE tExpeditionScan + SELECT expeditionFk, est.id typeFk + FROM vn.expeditionScan e + JOIN vn.expeditionStateType est ON est.code = vStateCode + WHERE e.palletFk = vPalletFk; + + SELECT COUNT(*) INTO hasExpeditions FROM tExpeditionScan; + + IF NOT hasExpeditions THEN + DROP TEMPORARY TABLE tExpeditionScan; + CALL util.throw('palletDoesNotExist'); + END IF; + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT expeditionFk, typeFk + FROM tExpeditionScan; + DROP TEMPORARY TABLE tExpeditionScan; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionState_addByRoute.sql b/db/routines/vn/procedures/expeditionState_addByRoute.sql new file mode 100644 index 000000000..5e438287b --- /dev/null +++ b/db/routines/vn/procedures/expeditionState_addByRoute.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionState_addByRoute`(vRouteFk INT, vStateCode VARCHAR(100)) +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState, por rutas + * + * @param vRouteFk Identificador de vn.route + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT e.id, est.id + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.expeditionStateType est ON est.code = vStateCode + WHERE t.routeFk = vRouteFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionTruck_Add.sql b/db/routines/vn/procedures/expeditionTruck_Add.sql new file mode 100644 index 000000000..e4009ca47 --- /dev/null +++ b/db/routines/vn/procedures/expeditionTruck_Add.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionTruck_Add`(vHour VARCHAR(5), vDescription VARCHAR(45)) +BEGIN + + INSERT INTO vn.expeditionTruck(eta,description) + VALUES(CONCAT(util.VN_CURDATE(), ' ', vHour), vDescription); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expeditionTruck_List.sql b/db/routines/vn/procedures/expeditionTruck_List.sql new file mode 100644 index 000000000..2434f9274 --- /dev/null +++ b/db/routines/vn/procedures/expeditionTruck_List.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionTruck_List`() +BEGIN + + SELECT id truckFk, + eta, + description Destino + FROM expeditionTruck + WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + ORDER BY eta; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expedition_StateGet.sql b/db/routines/vn/procedures/expedition_StateGet.sql new file mode 100644 index 000000000..17fcf91e5 --- /dev/null +++ b/db/routines/vn/procedures/expedition_StateGet.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expedition_StateGet`(vExpeditionFk INT) +BEGIN + + /* Devuelve una "ficha" con todos los datos relativos a la expedición + * + * param vExpeditionFk + */ + + DECLARE vTicketsPendientes INT; + DECLARE vEtiquetasTotales INT; + DECLARE vEtiquetasEscaneadas INT; + DECLARE vEtiquetasLeidasSorter INT; + DECLARE vRouteFk INT; + + SELECT t.routeFk INTO vRouteFk + FROM vn.ticket t + JOIN vn.expedition e ON e.ticketFk = t.id + WHERE e.id = vExpeditionFk; + + SELECT COUNT(*) INTO vTicketsPendientes + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + WHERE t.routeFk = vRouteFk + AND ISNULL(e.id); + + SELECT COUNT(*) INTO vEtiquetasTotales + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vRouteFk; + + SELECT COUNT(*) INTO vEtiquetasEscaneadas + FROM vn.expeditionScan es + JOIN vn.expedition e ON e.id = es.expeditionFk + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vRouteFk; + + SELECT COUNT(*) INTO vEtiquetasLeidasSorter + FROM srt.expedition e + JOIN vn.expedition ve ON ve.id = e.id + LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id + JOIN vn.ticket t ON t.id = ve.ticketFk + WHERE t.routeFk = vRouteFk + AND e.created != e.updated + AND ISNULL(es.expeditionFk); + + + SELECT e.ticketFk ticket, + t.nickname cliente, + a.city ciudad, + p.name provincia, + z.name zonaTicket, + am.name zonaRuta, + t.routeFk ruta, + rm.beachFk ubicacion, + et.eta , + et.description camion, + vTicketsPendientes AS ticketsPendientes, + vEtiquetasTotales AS etiquetasTotales, + vEtiquetasEscaneadas AS etiquetasEscaneadas, + vEtiquetasLeidasSorter AS etiquetasSorter + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + WHERE e.id = vExpeditionFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expedition_getFromRoute.sql b/db/routines/vn/procedures/expedition_getFromRoute.sql new file mode 100644 index 000000000..2b4de5662 --- /dev/null +++ b/db/routines/vn/procedures/expedition_getFromRoute.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expedition_getFromRoute`(vRouteFk INT) +BEGIN +/** + * Obtiene las expediciones a partir de una ruta + * @param vRouteFk Id de la ruta + */ + SELECT e.id, + e.ticketFk, + t.routeFk, + ts.alertLevel, + a.street, + a.city, + a.postalCode, + t.addressFk, + a.nickname, + sub2.itemPackingTypeConcat, + est.code + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + JOIN ticketState ts ON ts.ticketFk = e.ticketFk + JOIN address a ON t.addressFk = a.id + JOIN route r ON r.id = t.routeFk + LEFT JOIN warehouse w ON t.warehouseFk = w.id + LEFT JOIN (SELECT sub.ticketFk, + CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeConcat + FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id,i.itemPackingTypeFk)sub + GROUP BY sub.ticketFk + ) sub2 ON sub2.ticketFk = t.id + LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk + WHERE t.routeFk = vRouteFk AND e.freightItemFk <> FALSE + ORDER BY r.created, t.priority DESC; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/expedition_getState.sql b/db/routines/vn/procedures/expedition_getState.sql new file mode 100644 index 000000000..96e247e4d --- /dev/null +++ b/db/routines/vn/procedures/expedition_getState.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expedition_getState`(vExpeditionFk INT) +BEGIN + + DECLARE vTicketsPendientes INT; + DECLARE vEtiquetasTotales INT; + DECLARE vEtiquetasEscaneadas INT; + DECLARE vRouteFk INT; + + SELECT t.routeFk INTO vRouteFk + FROM vn.ticket t + JOIN vn.expedition e ON e.ticketFk = t.id + WHERE e.id = vExpeditionFk; + + SELECT COUNT(*) INTO vTicketsPendientes + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + WHERE t.routeFk = vRouteFk + AND ISNULL(e.id); + + SELECT COUNT(*) INTO vEtiquetasTotales + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vRouteFk; + + SELECT COUNT(*) INTO vEtiquetasEscaneadas + FROM vn.expeditionScan es + JOIN vn.expedition e ON e.id = es.expeditionFk + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vRouteFk; + + SELECT e.ticketFk ticket, + t.nickname cliente, + a.city ciudad, + p.name provincia, + z.name zonaTicket, + am.name zonaRuta, + t.routeFk ruta, + rm.beachFk ubicacion, + et.eta , + et.description camion, + vTicketsPendientes AS ticketsPendientes, + vEtiquetasTotales AS etiquetasTotales, + vEtiquetasEscaneadas AS etiquetasEscaneadas + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + WHERE e.id = vExpeditionFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/freelance_getInfo.sql b/db/routines/vn/procedures/freelance_getInfo.sql new file mode 100644 index 000000000..0f85ab4bd --- /dev/null +++ b/db/routines/vn/procedures/freelance_getInfo.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`freelance_getInfo`(workerFk INT) +BEGIN + SELECT s.name, s.street, s.city, s.nif, s.postCode + FROM route r + JOIN agencyMode am ON r.agencyModeFk = am.id + JOIN agency a ON am.agencyFk = a.id + JOIN supplierAgencyTerm sat ON a.id = sat.agencyFk + JOIN supplier s ON sat.supplierFk = s.id + WHERE r.workerFk = workerFk + ORDER BY r.id DESC + LIMIT 1; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/fustControl.sql b/db/routines/vn/procedures/fustControl.sql new file mode 100644 index 000000000..506354b20 --- /dev/null +++ b/db/routines/vn/procedures/fustControl.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`fustControl`(vFromDated DATE, vToDated DATE) +BEGIN + + DECLARE vSijsnerClientFk INT DEFAULT 19752; + + DECLARE vDateStart DATETIME; + DECLARE vDateEnd DATETIME; + + SET vDateStart = vFromDated; + SET vDateEnd = util.Dayend(vToDated); + + SELECT p.id FustCode, + CAST(sent.stucks AS DECIMAL(10,0)) FH, + CAST(tp.stucks AS DECIMAL(10,0)) Tickets, + CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, + CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo + FROM vn.packaging p + LEFT JOIN ( + SELECT FustCode, sum(fustQuantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,b.packagingFk) FustCode, s.quantity / b.packing AS fustQuantity + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk + JOIN vn.buy b ON b.id = lb.buy_id + JOIN vn.packaging p ON p.id = b.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA') sub + GROUP BY FustCode) sent ON sent.FustCode = p.id + LEFT JOIN ( + SELECT FustCode, sum(quantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA' + AND t.clientFk != vSijsnerClientFk + AND tp.quantity > 0) sub + GROUP BY FustCode) tp ON tp.FustCode = p.id + LEFT JOIN ( + SELECT FustCode, sum(quantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id + WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND t.clientFk = vSijsnerClientFk) sub + GROUP BY FustCode) sj ON sj.FustCode = p.id + WHERE sent.stucks + OR tp.stucks + OR sj.stucks; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/fustControlDetail.sql b/db/routines/vn/procedures/fustControlDetail.sql new file mode 100644 index 000000000..a48a3531b --- /dev/null +++ b/db/routines/vn/procedures/fustControlDetail.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`fustControlDetail`(vFromDated DATE, vToDated DATE) +BEGIN + + DECLARE vSijsnerClientFk INT DEFAULT 19752; + + DECLARE vDateStart DATETIME; + DECLARE vDateEnd DATETIME; + + SET vDateStart = vFromDated; + SET vDateEnd = util.Dayend(vToDated); + + SELECT a.nickname shopName, + a.city , + IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, + tp.quantity, + tp.ticketFk, + CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk + WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated) + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA' + AND t.clientFk != vSijsnerClientFk + AND tp.quantity > 0; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/fv_pca.sql b/db/routines/vn/procedures/fv_pca.sql new file mode 100644 index 000000000..b8e7343ef --- /dev/null +++ b/db/routines/vn/procedures/fv_pca.sql @@ -0,0 +1,101 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`fv_pca`() +BEGIN + +DECLARE done INT DEFAULT FALSE; + +DECLARE vTicketFk INT; +DECLARE vSaleFk INT; +DECLARE vClonTicket INT DEFAULT 0; + +DECLARE cur1 CURSOR FOR +SELECT s.ticketFk, s.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + WHERE t.shipped BETWEEN '2020-10-18' AND '2020-10-31' + AND it.code IN ('ANT','ANS','ORQ','TRO') + and t.warehouseFk = 1; + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + +OPEN cur1; + +FETCH cur1 INTO vTicketFk, vSaleFk; + + WHILE done = 0 DO + + SELECT t.id INTO vClonTicket + FROM vn.ticket t + JOIN (SELECT addressFk, shipped FROM vn.ticket WHERE id = vTicketFk) sub USING(addressFk, shipped) + WHERE t.warehouseFk = 44 + LIMIT 1; + + SELECT vTicketFk, vClonTicket; + + IF vClonTicket = 0 THEN + + INSERT INTO ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk + ) + SELECT + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + 44, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk + + FROM ticket + WHERE id = vTicketFk; + + SET vClonTicket = LAST_INSERT_ID(); + + SELECT 'lstID', vClonTicket; + /* + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT vTicketFk, ao.observationTypeFk, ao.description + FROM addressObservation ao + JOIN ticket t ON t.addressFk = ao.addressFk + WHERE t.id = vClonTicket; +*/ + INSERT INTO ticketLog + SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert', + description = CONCAT('Ha creado el ticket:', ' ', vClonTicket, ' clonando el ', vTicketFk); + + END IF; + + UPDATE vn.sale + SET ticketFk = vClonTicket + WHERE id = vSaleFk; + + SET vClonTicket = 0; + + SET done = 0; + FETCH cur1 INTO vTicketFk, vSaleFk; + + END WHILE; + + CLOSE cur1; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/getDayExpeditions.sql b/db/routines/vn/procedures/getDayExpeditions.sql new file mode 100644 index 000000000..949cf4e5b --- /dev/null +++ b/db/routines/vn/procedures/getDayExpeditions.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getDayExpeditions`() +BEGIN + + SELECT + e.expeditions_id as expeditionFk, + date_format(e.odbc_date,'%Y-%m-%d') as expeditionDate, + e.ticket_id as ticketFk, + t.routeFk as routeFk + FROM vn2008.expeditions e + INNER JOIN vn.ticket t ON t.id = e.ticket_id + WHERE DATE(odbc_date) = util.VN_CURDATE(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/getInfoDelivery.sql b/db/routines/vn/procedures/getInfoDelivery.sql new file mode 100644 index 000000000..c240560e9 --- /dev/null +++ b/db/routines/vn/procedures/getInfoDelivery.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getInfoDelivery`(vRouteFk INT) +BEGIN + SELECT s.name, s.street, s.city, s.nif, s.postCode FROM vn.route r + JOIN vn.agencyMode am ON r.agencyModeFk = am.id + JOIN vn.agency a ON am.agencyFk = a.id + JOIN vn.supplier s ON a.supplierFk = s.id + WHERE r.id = vRouteFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/getPedidosInternos.sql b/db/routines/vn/procedures/getPedidosInternos.sql new file mode 100644 index 000000000..973e110ef --- /dev/null +++ b/db/routines/vn/procedures/getPedidosInternos.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getPedidosInternos`() +BEGIN + + SELECT id,name as description,upToDown as quantity FROM vn.item WHERE upToDown; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/greuge_add.sql b/db/routines/vn/procedures/greuge_add.sql new file mode 100644 index 000000000..b2241ab83 --- /dev/null +++ b/db/routines/vn/procedures/greuge_add.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`greuge_add`() +BEGIN +/** + * Group inserts into vn.greuge and then deletes the records just inserted + */ + DECLARE vDated DATE; + + SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL yearsToDelete YEAR) INTO vDated + FROM vn.greugeConfig; + + INSERT INTO vn.greuge(clientFk, description, amount, shipped, created, greugeTypeFk) + SELECT clientFk, 'Suma agrupada', SUM(amount), MAX(shipped), MAX(created), greugeTypeFk + FROM vn.greuge + WHERE shipped <= vDated AND description <> 'Suma agrupada' + GROUP BY clientFk, greugeTypeFk; + + DELETE + FROM vn.greuge + WHERE shipped <= vDated AND description <> 'Suma agrupada'; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/greuge_notifyEvents.sql b/db/routines/vn/procedures/greuge_notifyEvents.sql new file mode 100644 index 000000000..ec00c1bde --- /dev/null +++ b/db/routines/vn/procedures/greuge_notifyEvents.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`greuge_notifyEvents`() +BEGIN +/** + * Notify to detect wrong greuges. + */ + DECLARE vTimeStart DATETIME; + DECLARE vTimeEnd DATETIME; + DECLARE vMaxPercentToWrong DECIMAL(10,2); + DECLARE vJSON JSON; + DECLARE vArray JSON; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vHasData BOOL DEFAULT FALSE; + DECLARE vCounter INT DEFAULT 0; + DECLARE myCur CURSOR FOR + SELECT JSON_OBJECT( + 'ticketId', g.ticketFk, + 'clientId', g.clientFk, + 'description', g.description, + 'amount', g.amount + ) + FROM greuge g + JOIN greugeType gt ON gt.id = g.greugeTypeFk + JOIN ticket t ON t.id = g.ticketFk + WHERE g.created BETWEEN vTimeStart AND util.dayEnd(vTimeEnd) + AND g.amount > (t.totalWithVat * (vMaxPercentToWrong / 100)) + AND gt.code = 'freightDifference' + AND SIGN(t.totalWithVat) + ORDER BY g.clientFk; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT IFNULL(DATE(lastNotifyCheck), util.VN_CURDATE()) INTO vTimeStart + FROM greugeConfig; + + SET vTimeEnd = util.VN_NOW(); + + SELECT maxPercentToWrong INTO vMaxPercentToWrong + FROM greugeConfig + LIMIT 1; + + IF vMaxPercentToWrong IS NULL THEN + CALL util.throw('Greuge max percent to wrong is not configured'); + END IF; + + SET vArray = JSON_ARRAY(); + + OPEN myCur; + myCur: LOOP + FETCH myCur INTO vJSON; + + IF vDone THEN + LEAVE myCur; + END IF; + + SET vArray = JSON_MERGE(vArray, vJSON); + SET vCounter = vCounter + 1; + SET vHasData = TRUE; + END LOOP; + CLOSE myCur; + + IF vHasData THEN + SELECT util.notification_send( + 'greuge-wrong', + JSON_OBJECT('tickets', JSON_EXTRACT(vArray, '$')), + account.myUser_getId() + ); + END IF; + + UPDATE greugeConfig + SET lastNotifyCheck = vTimeEnd; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/inventoryFailureAdd.sql b/db/routines/vn/procedures/inventoryFailureAdd.sql new file mode 100644 index 000000000..38765cbda --- /dev/null +++ b/db/routines/vn/procedures/inventoryFailureAdd.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`inventoryFailureAdd`() +BEGIN + +DECLARE done BOOL DEFAULT FALSE; +DECLARE vTicketFk INT; + +DECLARE rs CURSOR FOR + SELECT id FROM vn.ticket + WHERE shipped = util.yesterday() + AND clientFk = 400 + AND warehouseFk IN (1,44); + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + +OPEN rs; + +FETCH rs INTO vTicketFk; + +WHILE NOT done DO + + INSERT INTO vn.inventoryFailure(dated, itemFk, quantity, value, warehouseFk, throwerFk) + SELECT t.shipped, + s.itemFk, + s.quantity, + b.buyingValue + b.freightValue + b.packageValue + b.comissionValue, + t.warehouseFk, + w.id + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + LEFT JOIN cache.last_buy lb ON lb.warehouse_id = t.warehouseFk AND item_id = s.itemFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.worker w ON w.code = LEFT(s.concept, 3) + WHERE t.id = vTicketFk + AND s.quantity > 0; + + FETCH rs INTO vTicketFk; + +END WHILE; + + +CLOSE rs; + + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/inventoryMake.sql b/db/routines/vn/procedures/inventoryMake.sql new file mode 100644 index 000000000..0def763dc --- /dev/null +++ b/db/routines/vn/procedures/inventoryMake.sql @@ -0,0 +1,265 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`inventoryMake`(vDate DATE, vWh INT) +proc: BEGIN +/** +* Recalcula los inventarios de todos los almacenes, si vWh = 0 +* +* @param vDate Fecha de los nuevos inventarios +* @param vWh almacen al cual hacer el inventario +*/ + + DECLARE vDone BOOL; + DECLARE vEntryFk INT; + DECLARE vTravelFk INT; + DECLARE vDateLastInventory DATE; + DECLARE vDateYesterday DATETIME DEFAULT vDate - INTERVAL 1 SECOND; + DECLARE vWarehouseOutFkInventory INT; + DECLARE vInventorySupplierFk INT; + DECLARE vAgencyModeFkInventory INT; + + DECLARE cWarehouses CURSOR FOR + SELECT id + FROM warehouse + WHERE isInventory + AND vWh IN (0,id); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cWarehouses; + SET @isModeInventory := TRUE; + l: LOOP + + SET vDone = FALSE; + FETCH cWarehouses INTO vWh; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT w.id INTO vWarehouseOutFkInventory + FROM warehouse w + WHERE w.code = 'inv'; + + SELECT inventorySupplierFk INTO vInventorySupplierFk + FROM entryConfig; + + SELECT am.id INTO vAgencyModeFkInventory + FROM agencyMode am + where code = 'inv'; + + SELECT MAX(landed) INTO vDateLastInventory + FROM travel tr + JOIN entry e ON e.travelFk = tr.id + JOIN buy b ON b.entryFk = e.id + WHERE warehouseOutFk = vWarehouseOutFkInventory + AND landed < vDate + AND e.supplierFk = vInventorySupplierFk + AND warehouseInFk = vWh + AND NOT isRaid; + + IF vDateLastInventory IS NULL THEN + SELECT inventoried INTO vDateLastInventory FROM config; + END IF; + + -- Generamos travel, si no existe. + SET vTravelFK = 0; + + SELECT id INTO vTravelFk + FROM travel + WHERE warehouseOutFk = vWarehouseOutFkInventory + AND warehouseInFk = vWh + AND landed = vDate + AND agencyModeFk = vAgencyModeFkInventory + AND ref = 'inventario' + LIMIT 1; + + IF NOT vTravelFK THEN + + INSERT INTO travel SET + warehouseOutFk = vWarehouseOutFkInventory, + warehouseInFk = vWh, + shipped = vDate, + landed = vDate, + agencyModeFk = vAgencyModeFkInventory, + ref = 'inventario', + isDelivered = TRUE, + isReceived = TRUE; + + SELECT LAST_INSERT_ID() INTO vTravelFk; + + END IF; + + -- Generamos entrada si no existe, o la vaciamos. + SET vEntryFk = 0; + + SELECT id INTO vEntryFk + FROM entry + WHERE supplierFk = vInventorySupplierFk + AND travelFk = vTravelFk; + + IF NOT vEntryFk THEN + + INSERT INTO entry SET + supplierFk = vInventorySupplierFk, + isConfirmed = TRUE, + isOrdered = TRUE, + travelFk = vTravelFk; + + SELECT LAST_INSERT_ID() INTO vEntryFk; + + ELSE + + DELETE FROM buy WHERE entryFk = vEntryFk; + + END IF; + + -- Preparamos tabla auxilar + CREATE OR REPLACE TEMPORARY TABLE tmp.inventory ( + itemFk INT(11) NOT NULL PRIMARY KEY, + quantity int(11) DEFAULT '0', + buyingValue decimal(10,4) DEFAULT '0.0000', + freightValue decimal(10,3) DEFAULT '0.000', + packing int(11) DEFAULT '0', + `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', + groupingMode tinyint(4) NOT NULL DEFAULT 0 , + comissionValue decimal(10,3) DEFAULT '0.000', + packageValue decimal(10,3) DEFAULT '0.000', + packageFk varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', + price1 decimal(10,2) DEFAULT '0.00', + price2 decimal(10,2) DEFAULT '0.00', + price3 decimal(10,2) DEFAULT '0.00', + minPrice decimal(10,2) DEFAULT '0.00', + producer varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + INDEX (itemFK)) ENGINE = MEMORY; + + -- Compras + INSERT INTO tmp.inventory(itemFk,quantity) + SELECT b.itemFk, SUM(b.quantity) + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.warehouseInFk = vWh + AND tr.landed BETWEEN vDateLastInventory + AND vDateYesterday + AND NOT isRaid + GROUP BY b.itemFk; + SELECT vDateLastInventory , vDateYesterday; + + -- Traslados + INSERT INTO tmp.inventory(itemFk, quantity) + SELECT itemFk, quantityOut + FROM ( + SELECT b.itemFk,- SUM(b.quantity) quantityOut + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.warehouseOutFk = vWh + AND tr.shipped BETWEEN vDateLastInventory + AND vDateYesterday + AND NOT isRaid + GROUP BY b.itemFk + ) sub + ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity, 0) + sub.quantityOut; + + -- Ventas + INSERT INTO tmp.inventory(itemFk,quantity) + SELECT itemFk, saleOut + FROM ( + SELECT s.itemFk, - SUM(s.quantity) saleOut + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.warehouseFk = vWh + AND t.shipped BETWEEN vDateLastInventory AND vDateYesterday + GROUP BY s.itemFk + ) sub + ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity,0) + sub.saleOut; + + -- Actualiza valores de la ultima compra + UPDATE tmp.inventory inv + JOIN cache.last_buy lb ON lb.item_id = inv.itemFk AND lb.warehouse_id = vWh + JOIN buy b ON b.id = lb.buy_id + JOIN item i ON i.id = b.itemFk + LEFT JOIN producer p ON p.id = i.producerFk + SET inv.buyingValue = b.buyingValue, + inv.freightValue = b.freightValue, + inv.packing = b.packing, + inv.`grouping`= b.`grouping`, + inv.groupingMode = b.groupingMode, + inv.comissionValue = b.comissionValue, + inv.packageValue = b.packageValue, + inv.packageFk = b.packagingFk, + inv.price1 = b.price1, + inv.price2 = b.price2, + inv.price3 = b.price3, + inv.minPrice = b.minPrice, + inv.producer = p.name; + + INSERT INTO buy( itemFk, + quantity, + buyingValue, + freightValue, + packing, + `grouping`, + groupingMode, + comissionValue, + packageValue, + packagingFk, + price1, + price2, + price3, + minPrice, + entryFk) + SELECT itemFk, + GREATEST(quantity, 0), + buyingValue, + freightValue, + packing, + `grouping`, + groupingMode, + comissionValue, + packageValue, + packageFk, + price1, + price2, + price3, + minPrice, + vEntryFk + FROM tmp.inventory; + + SELECT vWh, COUNT(*), util.VN_NOW() FROM tmp.inventory; + + -- Actualizamos el campo lastUsed de item + UPDATE item i + JOIN tmp.inventory i2 ON i2.itemFk = i.id + SET i.lastUsed = NOW() + WHERE i2.quantity; + + -- DROP TEMPORARY TABLE tmp.inventory; + + END LOOP; + + CLOSE cWarehouses; + + UPDATE config SET inventoried = vDate; + SET @isModeInventory := FALSE; + + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + CREATE TEMPORARY TABLE tmp.entryToDelete + (INDEX(entryId) USING BTREE) ENGINE = MEMORY + SELECT e.id as entryId, + t.id as travelId + FROM travel t + JOIN `entry` e ON e.travelFk = t.id + WHERE e.supplierFk = vInventorySupplierFk + AND t.shipped <= util.VN_CURDATE() - INTERVAL 12 DAY + AND (DAY(t.shipped) <> 1 OR shipped < util.VN_CURDATE() - INTERVAL 12 DAY); + + DELETE e + FROM `entry` e + JOIN tmp.entryToDelete tmp ON tmp.entryId = e.id; + + DELETE IGNORE t + FROM travel t + JOIN tmp.entryToDelete tmp ON tmp.travelId = t.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/inventoryMakeLauncher.sql b/db/routines/vn/procedures/inventoryMakeLauncher.sql new file mode 100644 index 000000000..6f362f70e --- /dev/null +++ b/db/routines/vn/procedures/inventoryMakeLauncher.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`inventoryMakeLauncher`() +BEGIN +/** + * Recalcula los inventarios de todos los almacenes. + */ + + call vn.inventoryMake(TIMESTAMPADD(DAY, -10, util.VN_CURDATE()), 0); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/inventory_repair.sql b/db/routines/vn/procedures/inventory_repair.sql new file mode 100644 index 000000000..ea65ac37d --- /dev/null +++ b/db/routines/vn/procedures/inventory_repair.sql @@ -0,0 +1,111 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`inventory_repair`() +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntry; + CREATE TEMPORARY TABLE tmp.lastEntry + (PRIMARY KEY (buyFk)) + SELECT + i.id AS itemFk, + w.id AS warehouseFk, + w.name AS warehouse, + tr.landed, + b.id AS buyFk, + b.entryFk, + b.isIgnored, + b.price2, + b.price3, + b.stickers, + b.packing, + b.grouping, + b.groupingMode, + b.weight, + i.stems, + b.quantity, + b.buyingValue, + b.packagingFk , + s.id AS supplierFk, + s.name AS supplier + FROM itemType it + RIGHT JOIN (entry e + LEFT JOIN supplier s ON s.id = e.supplierFk + RIGHT JOIN buy b ON b.entryFk = e.id + LEFT JOIN item i ON i.id = b.itemFk + LEFT JOIN ink ON ink.id = i.inkFk + LEFT JOIN travel tr ON tr.id = e.travelFk + LEFT JOIN warehouse w ON w.id = tr.warehouseInFk + LEFT JOIN origin o ON o.id = i.originFk + ) ON it.id = i.typeFk + LEFT JOIN edi.ekt ek ON b.ektFk = ek.id + WHERE (b.packagingFk = "--" OR b.price2 = 0 OR b.packing = 0 OR b.buyingValue = 0) AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())) AND s.name = 'INVENTARIO'; + + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOk; + CREATE TEMPORARY TABLE tmp.lastEntryOk + (PRIMARY KEY (buyFk)) + SELECT + i.id AS itemFk, + w.id AS warehouseFk, + w.name AS warehouse, + tr.landed, + b.id AS buyFk, + b.entryFk, + b.isIgnored, + b.price2, + b.price3, + b.stickers, + b.packing, + b.grouping, + b.groupingMode, + b.weight, + i.stems, + b.quantity, + b.buyingValue, + b.packagingFk, + s.id AS supplierFk, + s.name AS supplier + FROM itemType it + RIGHT JOIN (entry e + LEFT JOIN supplier s ON s.id = e.supplierFk + RIGHT JOIN buy b ON b.entryFk = e.id + LEFT JOIN item i ON i.id = b.itemFk + LEFT JOIN ink ON ink.id = i.inkFk + LEFT JOIN travel tr ON tr.id = e.travelFk + LEFT JOIN warehouse w ON w.id = tr.warehouseInFk + LEFT JOIN origin o ON o.id = i.originFk + ) ON it.id = i.typeFk + LEFT JOIN edi.ekt ek ON b.ektFk = ek.id + WHERE b.packagingFk != "--" AND b.price2 != 0 AND b.packing != 0 AND b.buyingValue > 0 AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-2,util.VN_CURDATE())) + ORDER BY tr.landed DESC; + + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOkGroup; + CREATE TEMPORARY TABLE tmp.lastEntryOkGroup + (INDEX (warehouseFk,itemFk)) + SELECT * + FROM tmp.lastEntryOk tmp + GROUP BY tmp.itemFk,tmp.warehouseFk; + + UPDATE buy b + JOIN tmp.lastEntry lt ON lt.buyFk = b.id + JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk + SET b.packagingFk = eo.packagingFk WHERE b.packagingFk = "--"; + + UPDATE buy b + JOIN tmp.lastEntry lt ON lt.buyFk = b.id + JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk + SET b.price2 = eo.price2 WHERE b.price2 = 0 ; + + UPDATE buy b + JOIN tmp.lastEntry lt ON lt.buyFk = b.id + JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk + SET b.packing = eo.packing WHERE b.packing = 0; + + UPDATE buy b + JOIN tmp.lastEntry lt ON lt.buyFk = b.id + JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk + SET b.buyingValue = eo.buyingValue WHERE b.buyingValue = 0; + + DROP TEMPORARY TABLE tmp.lastEntry; + DROP TEMPORARY TABLE tmp.lastEntryOk; + DROP TEMPORARY TABLE tmp.lastEntryOkGroup; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceExpenseMake.sql b/db/routines/vn/procedures/invoiceExpenseMake.sql new file mode 100644 index 000000000..a1fe69ff5 --- /dev/null +++ b/db/routines/vn/procedures/invoiceExpenseMake.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceExpenseMake`(IN vInvoice INT) +BEGIN +/* Inserta las partidas de gasto correspondientes a la factura + * REQUIERE tabla tmp.ticketToInvoice + * @param vInvoice Numero de factura + */ + DELETE FROM invoiceOutExpense + WHERE invoiceOutFk = vInvoice; + + INSERT INTO invoiceOutExpense(invoiceOutFk, expenseFk, amount) + SELECT vInvoice, + expenseFk, + SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount + FROM tmp.ticketToInvoice t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + GROUP BY i.expenseFk + HAVING amount != 0; + + INSERT INTO invoiceOutExpense(invoiceOutFk, expenseFk, amount) + SELECT vInvoice, + tst.expenseFk, + SUM(ROUND(ts.quantity * ts.price ,2)) amount + FROM tmp.ticketToInvoice t + JOIN ticketService ts ON ts.ticketFk = t.id + JOIN ticketServiceType tst ON tst.id = ts.ticketServiceTypeFk + HAVING amount != 0; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceFromAddress.sql b/db/routines/vn/procedures/invoiceFromAddress.sql new file mode 100644 index 000000000..bde7afd8c --- /dev/null +++ b/db/routines/vn/procedures/invoiceFromAddress.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceFromAddress`(vMaxTicketDate DATETIME,vAddress INT,vCompany INT) +BEGIN + + DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()); + + SET vMaxTicketDate = util.dayEnd(vMaxTicketDate); + + DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`; + + CREATE TEMPORARY TABLE `tmp.``ticketToInvoice` + (PRIMARY KEY (`id`)) + ENGINE = MEMORY + SELECT Id_Ticket id FROM vn2008.Tickets WHERE (Fecha BETWEEN vMinDateTicket + AND vMaxTicketDate) AND Id_Consigna = vAddress + AND Factura IS NULL AND empresa_id = vCompany; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceFromClient.sql b/db/routines/vn/procedures/invoiceFromClient.sql new file mode 100644 index 000000000..29cee5d4f --- /dev/null +++ b/db/routines/vn/procedures/invoiceFromClient.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceFromClient`( + IN vMaxTicketDate datetime, + IN vClientFk INT, + IN vCompanyFk INT) +BEGIN + DECLARE vMinTicketDate DATE; + + SET vMinTicketDate = util.firstDayOfYear(vMaxTicketDate - INTERVAL 1 YEAR); + SET vMaxTicketDate = util.dayend(vMaxTicketDate); + + DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`; + CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice` + (PRIMARY KEY (`id`)) + ENGINE = MEMORY + SELECT id FROM ticket t + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND t.companyFk = vCompanyFk + AND t.shipped BETWEEN vMinTicketDate AND vMaxTicketDate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceFromTicket.sql b/db/routines/vn/procedures/invoiceFromTicket.sql new file mode 100644 index 000000000..e5ea00e62 --- /dev/null +++ b/db/routines/vn/procedures/invoiceFromTicket.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceFromTicket`(IN vTicket INT) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`; + + CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice` + (PRIMARY KEY (`id`)) + ENGINE = MEMORY + SELECT id FROM vn.ticket + WHERE id = vTicket AND refFk IS NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceInDueDay_calculate.sql b/db/routines/vn/procedures/invoiceInDueDay_calculate.sql new file mode 100644 index 000000000..e51b5f64d --- /dev/null +++ b/db/routines/vn/procedures/invoiceInDueDay_calculate.sql @@ -0,0 +1,73 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInDueDay_calculate`(vInvoiceInFk INT) +BEGIN +/** + * Calcula los vctos. de una factura recibida + * En caso de haberlos informado previamente o que el proveedor sea español, no los recalculará + * + * @param vInvoiceInFk Factura recibida + */ + DECLARE vCompanyCountryCode VARCHAR(3); + DECLARE vHasDueDayTax BOOL; + DECLARE vHasDueDay BOOL; + + SELECT c.code, IFNULL(a.isUeeMember, TRUE AND co.code ='ES') + INTO vCompanyCountryCode, vHasDueDayTax + FROM invoiceIn ii + JOIN supplier su ON su.id = ii.companyFk + LEFT JOIN country c ON c.id = su.countryFk + LEFT JOIN supplier s ON s.id = ii.supplierFk + LEFT JOIN country co ON co.id = s.countryFk + LEFT JOIN province p ON p.id = s.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + WHERE ii.id = vInvoiceInFk; + + SELECT COUNT(*) INTO vHasDueDay + FROM invoiceInDueDay iid + WHERE iid.invoiceInFk = vInvoiceInFk; + + IF NOT vHasDueDay AND vCompanyCountryCode = 'ES' THEN + + SET @cont := 0; + INSERT INTO invoiceInDueDay ( + invoiceInFk, + dueDated, + amount, + foreignValue + ) + SELECT vInvoiceInFk, + IF(payDay, + IF(getNextDueDate(issued, pdd.detail, payDay) < created, + created, + getNextDueDate(issued, pdd.detail, payDay)), + GREATEST(created, issued + INTERVAL pdd.detail DAY)), + IF((@cont := @cont + 1) < cont, + TRUNCATE(venc / cont, 2), + venc - (TRUNCATE(venc / cont, 2) * (cont - 1))), + IF(@cont < cont, + TRUNCATE(foreignValue / cont, 2), + foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) + FROM ( + SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100) * vHasDueDayTax) + * iit.taxableBase) / COUNT(DISTINCT(pdd.detail)) venc, + SUM(iit.foreignValue) / COUNT(DISTINCT(pdd.detail)) foreignValue, + s.payDemFk, + ii.companyFk, + COUNT(DISTINCT(pdd.detail)) cont, + s.payDay, + ii.issued, + DATE(ii.created) + INTERVAL 2 DAY created + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + LEFT JOIN sage.TiposIva ti ON ti.CodigoIva= iit.taxTypeSageFk + JOIN supplier s ON s.id = ii.supplierFk + JOIN payDemDetail pdd ON pdd.id = s.payDemFk + WHERE ii.id = vInvoiceInFk + GROUP BY ii.id + )sub + JOIN payDemDetail pdd ON pdd.id = sub.payDemFk + GROUP BY pdd.detail; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceInDueDay_recalc.sql b/db/routines/vn/procedures/invoiceInDueDay_recalc.sql new file mode 100644 index 000000000..7d2b0a5ed --- /dev/null +++ b/db/routines/vn/procedures/invoiceInDueDay_recalc.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInDueDay_recalc`(vInvoiceInFk INT) +BEGIN + + DELETE FROM invoiceInDueDay + WHERE invoiceInFk = vInvoiceInFk; + + CALL invoiceInDueDay_calculate(vInvoiceInFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceInTaxMakeByDua.sql b/db/routines/vn/procedures/invoiceInTaxMakeByDua.sql new file mode 100644 index 000000000..f41504669 --- /dev/null +++ b/db/routines/vn/procedures/invoiceInTaxMakeByDua.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTaxMakeByDua`(vDuaFk INT) +BEGIN + + DECLARE done BOOL DEFAULT FALSE; + DECLARE vInvoiceInFk INT; + + DECLARE rs CURSOR FOR + SELECT invoiceInFk + FROM entry e + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + FETCH rs INTO vInvoiceInFk; + + WHILE NOT done DO + + CALL vn2008.recibidaIvaInsert(vInvoiceInFk); + CALL invoiceInDueDay_recalc(vInvoiceInFk); + + FETCH rs INTO vInvoiceInFk; + + END WHILE; + + CLOSE rs; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql new file mode 100644 index 000000000..e9461369a --- /dev/null +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_afterUpsert`(vInvoiceInFk INT) +BEGIN +/** + * Triggered actions when a invoiceInTax is updated or inserted. + * + * @param vInvoiceInFk The invoiceIn id + */ + DECLARE vTaxRowLimit INT; + DECLARE vLines INT; + + SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; + + SELECT COUNT(*) INTO vLines + FROM invoiceInTax + WHERE invoiceInFk = vInvoiceInFk; + + IF vLines >= vTaxRowLimit THEN + CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceInTax_getFromDua.sql b/db/routines/vn/procedures/invoiceInTax_getFromDua.sql new file mode 100644 index 000000000..c7574f72f --- /dev/null +++ b/db/routines/vn/procedures/invoiceInTax_getFromDua.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromDua`(vDuaFk INT) +BEGIN + + DECLARE done BOOL DEFAULT FALSE; + DECLARE vInvoiceInFk INT; + + DECLARE rs CURSOR FOR + SELECT invoiceInFk + FROM entry e + JOIN duaEntry de ON de.entryFk = e.id + WHERE de.duaFk = vDuaFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + FETCH rs INTO vInvoiceInFk; + + WHILE NOT done DO + + CALL invoiceInTax_getFromEntries(vInvoiceInFk); + CALL invoiceInDueDay_calculate(vInvoiceInFk); + + FETCH rs INTO vInvoiceInFk; + + END WHILE; + + CLOSE rs; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceInTax_getFromEntries.sql b/db/routines/vn/procedures/invoiceInTax_getFromEntries.sql new file mode 100644 index 000000000..14cc43e15 --- /dev/null +++ b/db/routines/vn/procedures/invoiceInTax_getFromEntries.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(IN vId INT) +BEGIN + DECLARE vRate DOUBLE DEFAULT 1; + DECLARE vDated DATE; + DECLARE vExpenseFk VARCHAR(10); + + SELECT MAX(rr.dated) INTO vDated + FROM referenceRate rr + JOIN invoiceIn ii ON ii.id = vId + WHERE rr.dated <= ii.issued + AND rr.currencyFk = ii.currencyFk ; + + IF vDated THEN + SELECT `value` INTO vRate + FROM referenceRate + WHERE dated = vDated; + END IF; + + SELECT id INTO vExpenseFk + FROM vn.expense + WHERE `name` = 'Adquisición mercancia Extracomunitaria' + GROUP BY id + LIMIT 1; + + DELETE FROM invoiceInTax + WHERE invoiceInFk = vId; + + INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, foreignValue, taxTypeSageFk, transactionTypeSageFk) + SELECT ii.id, + SUM(b.buyingValue * b.quantity) / IFNULL(vRate,1) taxableBase, + vExpenseFk, + IF(ii.currencyFk = 1,NULL,SUM(b.buyingValue * b.quantity )) divisa, + taxTypeSageFk, + transactionTypeSageFk + FROM invoiceIn ii + JOIN entry e ON e.invoiceInFk = ii.id + JOIN supplier s ON s.id = e.supplierFk + JOIN buy b ON b.entryFk = e.id + LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk + AND rr.dated = ii.issued + WHERE ii.id = vId + HAVING taxableBase IS NOT NULL; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql new file mode 100644 index 000000000..a75b2269a --- /dev/null +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -0,0 +1,283 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(vSelf INT) +BEGIN + DECLARE vBookNumber INT; + + CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn + ENGINE = MEMORY + SELECT ii.bookEntried, + iit.foreignValue, + ii.companyFk, + ii.expenseFkDeductible, + iit.taxableBase, + iit.transactionTypeSageFk, + ii.serial, + ii.issued, + ii.operated, + ii.supplierRef, + ii.siiTrascendencyInvoiceInFk, + ii.cplusTaxBreakFk, + ii.cplusSubjectOpFk, + ii.siiTypeInvoiceInFk, + ii.cplusRectificationTypeFk, + ii.booked, + IFNULL(a.isUeeMember, c.isUeeMember) isUeeMember, + (c.id = cc.id) isSameCountry, + s.account supplierAccount, + s.name supplierName, + s.nif, + s.IsVies, + iit.taxTypeSageFk, + tt.code taxCode, + ti.Iva, + ti.CuentaIvaSoportado, + ti.PorcentajeIva, + ti.CuentaIvaRepercutido, + ttr.ClaveOperacionDefecto, + iis.cplusTerIdNifFk, + cit.id invoicesCount, + e.code, + e.isWithheld, + e.id expenseFk, + e.name expenseName + FROM invoiceIn ii + JOIN supplier s ON s.id = ii.supplierFk + LEFT JOIN province p ON p.id = s.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + JOIN country c ON c.id = s.countryFk + JOIN supplier sc ON sc.id = ii.companyFk + JOIN country cc ON cc.id = sc.countryFk + JOIN invoiceInSerial iis ON iis.code = ii.serial + JOIN siiTypeInvoiceIn cit ON cit.id = ii.siiTypeInvoiceInFk + LEFT JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + LEFT JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = iit.transactionTypeSageFk + LEFT JOIN expense e ON e.id = iit.expenseFk + LEFT JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk + LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva + WHERE ii.id = vSelf; + + CALL vn.ledger_next(vBookNumber); + + -- Apunte del proveedor + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + EUROHABER, + CONCEPTO, + CAMBIO, + HABERME, + NFACTICK, + CLAVE, + empresa_id) + SELECT + vBookNumber ASIEN, + tii.bookEntried FECHA, + tii.supplierAccount SUBCTA, + SUM(tii.taxableBase * + IF(tii.serial= 'R' AND ((tii.taxCode IS NULL OR tii.taxCode <> 'ISP21') + AND tii.taxTypeSageFk IS NOT NULL), + 1 + (tii.PorcentajeIva / 100), + 1)) EUROHABER, + CONCAT('s/fra', + RIGHT(tii.supplierRef, 8), + ':', + LEFT(tii.supplierName, 10)) CONCEPTO, + CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10,4)) CAMBIO, + SUM(tii.foreignValue * IF(tii.serial = 'R', 1 + (tii.PorcentajeIva / 100), 1)) HABERME, + tii.invoicesCount NFACTICK, + vSelf CLAVE, + tii.companyFk empresa_id + FROM tInvoiceIn tii; + + -- Línea de Gastos + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EURODEBE, + EUROHABER, + CONCEPTO, + CAMBIO, + DEBEME, + HABERME, + NFACTICK, + empresa_id) + SELECT vBookNumber ASIEN, + tii.bookEntried FECHA, + IF(tii.isWithheld, LPAD(RIGHT(tii.supplierAccount, 5), 10, tii.expenseFk),tii.expenseFk) SUBCTA, + tii.supplierAccount CONTRA, + IF(tii.isWithheld AND tii.taxableBase < 0, NULL, ROUND(SUM(tii.taxableBase),2)) EURODEBE, + IF(tii.isWithheld AND tii.taxableBase < 0, ROUND(SUM(-tii.taxableBase), 2), NULL) EUROHABER, + CONCAT('s/fra', + RIGHT(tii.supplierRef, 8), + ':', + LEFT(tii.supplierName, 10)) CONCEPTO, + CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10, 4)) CAMBIO, + IF(tii.isWithheld, NULL,ABS(ROUND(SUM(tii.foreignValue), 2))) DEBEME, + IF(tii.isWithheld, ABS(ROUND(SUM(tii.foreignValue), 2)) ,NULL) HABERME, + tii.invoicesCount NFACTICK, + tii.companyFk empresa_id + FROM tInvoiceIn tii + WHERE tii.code IS NULL OR tii.code <> 'suplido' + GROUP BY tii.expenseFk; + + -- Líneas de IVA + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EURODEBE, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + AUXILIAR, + SERIE, + TIPOOPE, + FECHA_EX, + FECHA_OP, + NFACTICK, + FACTURAEX, + L340, + LRECT349, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + TERIDNIF, + TERNIF, + TERNOM, + FECREGCON, + empresa_id) + SELECT vBookNumber ASIEN, + tii.bookEntried FECHA, + IF(tii.expenseFkDeductible>0, tii.expenseFkDeductible, tii.CuentaIvaSoportado) SUBCTA, + tii.supplierAccount CONTRA, + SUM(ROUND(tii.PorcentajeIva * tii.taxableBase / 100, 2)) EURODEBE, + SUM(tii.taxableBase) BASEEURO, + GROUP_CONCAT(DISTINCT tii.expenseName SEPARATOR ', ') CONCEPTO, + vSelf FACTURA, + tii.PorcentajeIva IVA, + IF(tii.isUeeMember AND eWithheld.id IS NULL, '', '*') AUXILIAR, + tii.serial SERIE, + tii.ClaveOperacionDefecto, + tii.issued FECHA_EX, + tii.operated FECHA_OP, + tii.invoicesCount NFACTICK, + tii.supplierRef FACTURAEX, + TRUE L340, + (tii.isSameCountry OR NOT tii.isUeeMember) LRECT349, + tii.siiTrascendencyInvoiceInFk TIPOCLAVE, + tii.cplusTaxBreakFk TIPOEXENCI, + tii.cplusSubjectOpFk TIPONOSUJE, + tii.siiTypeInvoiceInFk TIPOFACT, + tii.cplusRectificationTypeFk TIPORECTIF, + tii.cplusTerIdNifFk TERIDNIF, + tii.nif TERNIF, + tii.supplierName TERNOM, + tii.booked FECREGCON, + tii.companyFk + FROM tInvoiceIn tii + LEFT JOIN ( + SELECT e.id + FROM tInvoiceIn tii + JOIN expense e ON e.id = tii.expenseFk + WHERE e.isWithheld + LIMIT 1 + ) eWithheld ON TRUE + WHERE tii.taxTypeSageFk IS NOT NULL + AND (tii.taxCode IS NULL OR tii.taxCode NOT IN ('import10', 'import21')) + GROUP BY tii.PorcentajeIva, tii.expenseFk; + + -- Línea iva inversor sujeto pasivo + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EUROHABER, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + AUXILIAR, + SERIE, + TIPOOPE, + FECHA_EX, + FECHA_OP, + NFACTICK, + FACTURAEX, + L340, + LRECT349, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + TERIDNIF, + TERNIF, + TERNOM, + empresa_id) + SELECT vBookNumber ASIEN, + tii.bookEntried FECHA, + tii.CuentaIvaRepercutido SUBCTA, + tii.supplierAccount CONTRA, + SUM(ROUND(tii.PorcentajeIva * tii.taxableBase / 100,2)) EUROHABER, + ROUND(SUM(tii.taxableBase),2) BASEEURO, + GROUP_CONCAT(DISTINCT tii.expenseName SEPARATOR ', ') CONCEPTO, + vSelf FACTURA, + tii.PorcentajeIva IVA, + '*' AUXILIAR, + tii.serial SERIE, + tii.ClaveOperacionDefecto, + tii.issued FECHA_EX, + tii.operated FECHA_OP, + tii.invoicesCount NFACTICK, + tii.supplierRef FACTURAEX, + FALSE L340, + (tii.isSameCountry OR NOT tii.isUeeMember) LRECT349, + 1 TIPOCLAVE, + tii.cplusTaxBreakFk TIPOEXENCI, + tii.cplusSubjectOpFk TIPONOSUJE, + tii.siiTypeInvoiceInFk TIPOFACT, + tii.cplusRectificationTypeFk TIPORECTIF, + tii.cplusTerIdNifFk TERIDNIF, + tii.nif TERNIF, + tii.supplierName TERNOM, + tii.companyFk + FROM tInvoiceIn tii + JOIN sage.config c + WHERE tii.taxCode = 'ISP21' OR MID(tii.supplierAccount, 4, 1) = '1' + AND tii.taxTypeSageFk IS NOT NULL + AND NOT(tii.isVies + AND c.nontaxableTransactionTypeFk = tii.transactionTypeSageFk + AND tii.taxCode = 'nonTaxable') + GROUP BY tii.PorcentajeIva, tii.expenseFk; + + -- Actualización del registro original + UPDATE invoiceIn ii + SET ii.isBooked = TRUE + WHERE ii.id = vSelf; + + -- Problemas derivados de la precisión en los decimales al calcular los impuestos + UPDATE XDiario + SET EURODEBE = EURODEBE - + (SELECT IF(ABS(sub.difference) = 0.01, sub.difference, 0) + FROM( + SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference + FROM XDiario + WHERE ASIEN = vBookNumber + )sub + ) + WHERE ASIEN = vBookNumber + AND EURODEBE <> 0 + ORDER BY id DESC + LIMIT 1; + + DROP TEMPORARY TABLE tInvoiceIn; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOutAgain.sql b/db/routines/vn/procedures/invoiceOutAgain.sql new file mode 100644 index 000000000..82cebc18d --- /dev/null +++ b/db/routines/vn/procedures/invoiceOutAgain.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutAgain`(IN vInvoiceRef VARCHAR(15), vTaxArea VARCHAR(25)) +BEGIN + +/* Para tickets ya facturados, vuelve a repetir el proceso de facturación. +* +* @param vInvoiceFk Numero de factura +* @param vTaxArea Numero de factura +*/ + + DECLARE vInvoiceFk INT; + DECLARE vCountry INT; + DECLARE vTaxArea VARCHAR(15); + DECLARE vSpainCountryCode INT DEFAULT 1; + + SELECT id INTO vInvoiceFk + FROM invoiceOut + WHERE ref = vInvoiceRef; + + UPDATE invoiceOut + SET hasPdf = 0 + WHERE id = vInvoiceFk; + + SELECT s.countryFk INTO vCountry + FROM supplier s + JOIN invoiceOut io ON io.companyFk = s.id + WHERE io.id = vInvoiceFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice; + + CREATE TEMPORARY TABLE tmp.ticketToInvoice + SELECT id + FROM ticket + WHERE refFk = vInvoiceRef; + + CALL invoiceExpenseMake(vInvoiceFk); + + CALL invoiceTaxMake(vInvoiceFk,vTaxArea); + + UPDATE invoiceOut io + JOIN ( + SELECT SUM(amount) AS total + FROM invoiceOutExpense + WHERE invoiceOutFk = vInvoiceFk + ) base + JOIN ( + SELECT SUM(vat) AS total + FROM invoiceOutTax + WHERE invoiceOutFk = vInvoiceFk + ) vat + SET io.amount = base.total + vat.total + WHERE io.id = vInvoiceFk; + + CALL vn.invoiceOutBooking(vInvoiceFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOutBooking.sql b/db/routines/vn/procedures/invoiceOutBooking.sql new file mode 100644 index 000000000..bd109e1ec --- /dev/null +++ b/db/routines/vn/procedures/invoiceOutBooking.sql @@ -0,0 +1,194 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutBooking`(IN vInvoice INT) +BEGIN +/* Asienta la factura emitida +* +* param vInvoice factura_id +*/ + DECLARE vBookNumber INT; + DECLARE vExpenseConcept VARCHAR(50); + DECLARE vSpainCountryFk INT; + DECLARE vOldBookNumber INT; + + SELECT id INTO vSpainCountryFk FROM country WHERE code = 'ES'; + + SELECT ASIEN + INTO vOldBookNumber + FROM XDiario x + JOIN invoiceOut io ON io.id = vInvoice + WHERE x.SERIE = io.serial + AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1) + LIMIT 1; + + DELETE + FROM XDiario + WHERE ASIEN = vOldBookNumber; + + DROP TEMPORARY TABLE IF EXISTS rs; + CREATE TEMPORARY TABLE rs + SELECT + c.accountingAccount AS clientBookingAccount, + io.amount as totalAmount, + CONCAT('n/fra ', io.ref) as simpleConcept, + CONCAT('n/fra ', io.ref, ' ', c.name) as Concept, + io.serial AS SERIE, + io.issued AS FECHA_EX, + io.issued AS FECHA_OP, + io.issued AS FECHA, + 1 AS NFACTICK, + IF(ic.correctingFk,'D','') AS TIPOOPE, + io.siiTrascendencyInvoiceOutFk AS TIPOCLAVE, + io.cplusTaxBreakFk AS TIPOEXENCI, + io.cplusSubjectOpFk AS TIPONOSUJE, + io.siiTypeInvoiceOutFk AS TIPOFACT, + ic.cplusRectificationTypeFk AS TIPORECTIF, + io.companyFk, + RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum, + IF(c.countryFk = vSpainCountryFk, vSpainCountryFk, IF(ct.isUeeMember,2,4)) AS TERIDNIF, + CONCAT(IF(ct.isUeeMember AND c.countryFk <> vSpainCountryFk,ct.code,''),c.fi) AS TERNIF, + c.socialName AS TERNOM, + ior.serial AS SERIE_RT, + RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT, + ior.issued AS FECHA_RT, + IF(ior.id,TRUE,FALSE) AS RECTIFICA + FROM invoiceOut io + JOIN invoiceOutSerial ios ON ios.code = io.serial + JOIN client c ON c.id = io.clientFk + JOIN country ct ON ct.id = c.countryFk + LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id + LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk + WHERE io.id = vInvoice; + + CALL vn.ledger_next(vBookNumber); + + -- Linea del cliente + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + EURODEBE, + CONCEPTO, + FECHA_EX, + FECHA_OP, + empresa_id + ) + SELECT + vBookNumber AS ASIEN, + rs.FECHA, + rs.clientBookingAccount AS SUBCTA, + rs.totalAmount AS EURODEBE, + rs.simpleConcept AS CONCEPTO, + rs.FECHA_EX, + rs.FECHA_OP, + rs.companyFk AS empresa_id + FROM rs; + + -- Lineas de gasto + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EUROHABER, + CONCEPTO, + FECHA_EX, + FECHA_OP, + empresa_id + ) + SELECT + vBookNumber AS ASIEN, + rs.FECHA, + ioe.expenseFk AS SUBCTA, + rs.clientBookingAccount AS CONTRA, + ioe.amount AS EUROHABER, + rs.Concept AS CONCEPTO, + rs.FECHA_EX, + rs.FECHA_OP, + rs.companyFk AS empresa_id + FROM rs + JOIN invoiceOutExpense ioe + WHERE ioe.invoiceOutFk = vInvoice; + + SELECT GROUP_CONCAT(`name` SEPARATOR ',') + INTO vExpenseConcept + FROM expense e + JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id + WHERE ioe.invoiceOutFk = vInvoice; + + -- Lineas de IVA + INSERT INTO XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EUROHABER, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + RECEQUIV, + AUXILIAR, + SERIE, + SERIE_RT, + FACTU_RT, + RECTIFICA, + FECHA_RT, + FECHA_OP, + FECHA_EX, + TIPOOPE, + NFACTICK, + TERIDNIF, + TERNIF, + TERNOM, + L340, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + empresa_id + ) + SELECT + vBookNumber AS ASIEN, + rs.FECHA, + iot.pgcFk AS SUBCTA, + rs.clientBookingAccount AS CONTRA, + iot.vat AS EUROHABER, + iot.taxableBase AS BASEEURO, + CONCAT(vExpenseConcept,' : ',rs.Concept) AS CONCEPTO, + rs.invoiceNum AS FACTURA, + IF(pe2.equFk,0,pgc.rate) AS IVA, + IF(pe2.equFk,0,pgce.rate) AS RECEQUIV, + IF(pgc.mod347,'','*') AS AUXILIAR, + rs.SERIE, + rs.SERIE_RT, + rs.FACTU_RT, + rs.RECTIFICA, + rs.FECHA_RT, + rs.FECHA_OP, + rs.FECHA_EX, + rs.TIPOOPE, + rs.NFACTICK, + rs.TERIDNIF, + rs.TERNIF, + rs.TERNOM, + pgc.mod340 AS L340, + pgc.siiTrascendencyInvoiceOutFk AS TIPOCLAVE, + pgc.cplusTaxBreakFk as TIPOEXENCI, + rs.TIPONOSUJE, + rs.TIPOFACT, + rs.TIPORECTIF, + rs.companyFk AS empresa_id + FROM rs + JOIN invoiceOutTax iot + JOIN pgc ON pgc.code = iot.pgcFk + LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado + LEFT JOIN pgc pgce ON pgce.code = pe.equFk + LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv. + WHERE iot.invoiceOutFk = vInvoice; + + UPDATE invoiceOut + SET booked = util.VN_CURDATE() + WHERE id = vInvoice; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOutBookingRange.sql b/db/routines/vn/procedures/invoiceOutBookingRange.sql new file mode 100644 index 000000000..57d973f01 --- /dev/null +++ b/db/routines/vn/procedures/invoiceOutBookingRange.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutBookingRange`() +BEGIN + +/* Reasentar facturas +*/ + + + DECLARE vInvoice INT; + DECLARE vContador INT DEFAULT 0; + + DECLARE done BOOL DEFAULT FALSE; + + DECLARE rs CURSOR FOR + SELECT io.id + FROM invoiceOut io + WHERE RIGHT(ref,7) BETWEEN 1724215 AND 1724224 + AND serial = 'T'; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + FETCH rs INTO vInvoice; + + WHILE NOT done DO + + CALL invoiceOutBooking(vInvoice); + + FETCH rs INTO vInvoice ; + + SET vContador = vContador + 1; + + IF vContador MOD 50 = 0 THEN + + SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS; + + END IF; + + END WHILE; + + CLOSE rs; + + SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOutListByCompany.sql b/db/routines/vn/procedures/invoiceOutListByCompany.sql new file mode 100644 index 000000000..09ebfc1a4 --- /dev/null +++ b/db/routines/vn/procedures/invoiceOutListByCompany.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE) +BEGIN + +SELECT + c.socialName as RazonSocial, + c.fi as NIF, + io.ref as Factura, + io.serial as Serie, + io.issued as Fecha, + io.amount as Importe, + c.id as Id_Cliente, + iot.taxableBase as Base, + pgc.rate as Tipo, + iot.vat as Cuota, + pgc.name as Concepto + + FROM vn.invoiceOut io + JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id + JOIN vn.client c ON c.id = io.clientFk + JOIN vn.pgc ON pgc.code = iot.pgcFk + WHERE io.companyFk = vCompany + AND io.issued BETWEEN vStarted AND vEnded + ORDER BY io.ref DESC; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOutTaxAndExpense.sql b/db/routines/vn/procedures/invoiceOutTaxAndExpense.sql new file mode 100644 index 000000000..c263fe8d3 --- /dev/null +++ b/db/routines/vn/procedures/invoiceOutTaxAndExpense.sql @@ -0,0 +1,76 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutTaxAndExpense`() +BEGIN + +/* Para tickets ya facturados, vuelve a repetir el proceso de facturación. +* +* @param vInvoice Numero de factura +*/ + + DECLARE vInvoice INT; + DECLARE vInvoiceRef VARCHAR(15); + DECLARE vCountry INT; + DECLARE vTaxArea VARCHAR(15); + DECLARE vContador INT DEFAULT 0; + + DECLARE done BOOL DEFAULT FALSE; + + DECLARE rs CURSOR FOR + SELECT id,ref + FROM invoiceOut io + + WHERE issued >= '2017-07-01' + AND companyFk = 1381 + AND io.amount IS NULL + ; + + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + FETCH rs INTO vInvoice ,vInvoiceRef; + + WHILE NOT done DO + + SELECT s.countryFk + INTO vCountry + FROM supplier s + JOIN invoiceOut io ON io.companyFk = s.id + WHERE io.id = vInvoice; + + SELECT IF(c.isEqualizated AND i.taxAreaFk = 'NATIONAL','EQU',i.taxAreaFk) + INTO vTaxArea + FROM invoiceOutSerial i + JOIN invoiceOut io ON io.serial = i.code + JOIN client c ON c.id = io.clientFk + WHERE io.id = vInvoice; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice; + + CREATE TEMPORARY TABLE tmp.ticketToInvoice + SELECT id + FROM ticket + WHERE refFk = vInvoiceRef; + + CALL invoiceExpenseMake(vInvoice); + CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea); + + FETCH rs INTO vInvoice ,vInvoiceRef; + + SET vContador = vContador + 1; + + IF vContador MOD 50 = 0 THEN + + SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS; + + END IF; + + END WHILE; + + CLOSE rs; + + SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOut_exportationFromClient.sql b/db/routines/vn/procedures/invoiceOut_exportationFromClient.sql new file mode 100644 index 000000000..5fce7c428 --- /dev/null +++ b/db/routines/vn/procedures/invoiceOut_exportationFromClient.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_exportationFromClient`( + vMaxTicketDate DATETIME, + vClientFk INT, + vCompanyFk INT) +BEGIN +/** + * Genera tabla temporal tmp.ticketToInvoice necesaría para el proceso de facturación + * Los abonos quedan excluidos en las exportaciones + * + * @param vMaxTicketDate Fecha hasta la cual cogerá tickets para facturar + * @param vClientFk Id del cliente a facturar + * @param vCompanyFk Id de la empresa desde la que se factura + */ + DECLARE vMinTicketDate DATE; + SET vMinTicketDate = util.firstDayOfYear(vMaxTicketDate - INTERVAL 1 YEAR); + SET vMaxTicketDate = util.dayend(vMaxTicketDate); + + DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`; + CREATE TEMPORARY TABLE `tmp`.`ticketToInvoice` + (PRIMARY KEY (`id`)) + ENGINE = MEMORY + SELECT t.id + FROM ticket t + JOIN agencyMode am ON am.id = t.agencyModeFk + WHERE t.clientFk = vClientFk + AND t.refFk IS NULL + AND t.companyFk = vCompanyFk + AND t.shipped BETWEEN vMinTicketDate AND vMaxTicketDate + AND (am.`code` IS NULL OR am.`code` <> 'refund'); +END$$ +DELIMITER ; diff --git a/db/.archive/232001/00-invoiceOut_new.sql b/db/routines/vn/procedures/invoiceOut_new.sql similarity index 90% rename from db/.archive/232001/00-invoiceOut_new.sql rename to db/routines/vn/procedures/invoiceOut_new.sql index 175c31b74..8c35ce75f 100644 --- a/db/.archive/232001/00-invoiceOut_new.sql +++ b/db/routines/vn/procedures/invoiceOut_new.sql @@ -1,8 +1,5 @@ -DROP PROCEDURE IF EXISTS `vn`.`invoiceOut_new`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( vSerial VARCHAR(255), vInvoiceDate DATE, vTaxArea VARCHAR(25), @@ -35,6 +32,13 @@ BEGIN DECLARE vIsCEESerial BOOL DEFAULT FALSE; DECLARE vIsCorrectInvoiceDate BOOL; DECLARE vMaxShipped DATE; + DECLARE vDone BOOL; + DECLARE vTicketFk INT; + DECLARE vCursor CURSOR FOR + SELECT id + FROM tmp.ticketToInvoice; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); @@ -120,23 +124,37 @@ BEGIN FROM invoiceOut WHERE id = vNewInvoiceId; + OPEN vCursor; + l: LOOP + SET vDone = FALSE; + FETCH vCursor INTO vTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL ticket_recalc(vTicketFk, vTaxArea); + + END LOOP; + CLOSE vCursor; + UPDATE ticket t JOIN tmp.ticketToInvoice ti ON ti.id = t.id SET t.refFk = vNewRef; DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador + SELECT s.id, ti.id ticket_id, vWorker Id_Trabajador FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticket + LEFT JOIN ticketState ts ON ti.id = ts.ticketFk JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); + WHERE IFNULL(ts.alertLevel, 0) < 3 and s.`code` = getAlert3State(ti.id); - INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT * FROM tmp.updateInter; CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); + CALL invoiceTaxMake(vNewInvoiceId, vTaxArea); UPDATE invoiceOut io JOIN ( diff --git a/db/routines/vn/procedures/invoiceOut_newFromClient.sql b/db/routines/vn/procedures/invoiceOut_newFromClient.sql new file mode 100644 index 000000000..e6fc7b78a --- /dev/null +++ b/db/routines/vn/procedures/invoiceOut_newFromClient.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_newFromClient`( + IN vClientFk INT, + IN vSerial CHAR(2), + IN vMaxShipped DATE, + IN vCompanyFk INT, + IN vTaxArea VARCHAR(25), + IN vRef VARCHAR(25), + OUT vInvoiceId INT) +BEGIN +/** + * Factura los tickets de un cliente hasta una fecha dada + * @param vClientFk Id del cliente a facturar + * @param vSerial Serie de factura + * @param vMaxShipped Fecha hasta la cual cogera tickets para facturar + * @param vCompanyFk Id de la empresa desde la que se factura + * @param vTaxArea Tipo de iva en relacion a la empresa y al cliente, NULL por defecto + * @param vRef Referencia de la factura en caso que se quiera forzar, NULL por defecto + * @return vInvoiceId factura + */ + DECLARE vIsRefEditable BOOLEAN; + DECLARE vIsExportation BOOLEAN; + + IF vRef IS NOT NULL THEN + SELECT isRefEditable INTO vIsRefEditable + FROM invoiceOutSerial + WHERE code = vSerial; + + IF NOT vIsRefEditable THEN + CALL util.throw('serial non editable'); + END IF; + END IF; + + SELECT COUNT(*) INTO vIsExportation + FROM vn.invoiceOutSerial + WHERE taxAreaFk = 'WORLD' + AND `code` = vSerial; + + IF vIsExportation THEN + CALL invoiceOut_exportationFromClient(vMaxShipped, vClientFk, vCompanyFk); + ELSE + CALL invoiceFromClient(vMaxShipped, vClientFk, vCompanyFk); + END IF; + + CALL invoiceOut_new(vSerial, util.VN_CURDATE(), vTaxArea, vInvoiceId); + + UPDATE invoiceOut + SET `ref` = vRef + WHERE id = vInvoiceId + AND vRef IS NOT NULL; + + IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN + CALL invoiceOutBooking(vInvoiceId); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceOut_newFromTicket.sql b/db/routines/vn/procedures/invoiceOut_newFromTicket.sql new file mode 100644 index 000000000..3ee7cd678 --- /dev/null +++ b/db/routines/vn/procedures/invoiceOut_newFromTicket.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_newFromTicket`(IN vTicketFk int, IN vSerial char(2), IN vTaxArea varchar(25), + IN vRef varchar(25), OUT vInvoiceId int) +BEGIN +/** + * Factura un ticket + * @param vTicketFk Id del ticket + * @param vSerial Serie de factura + * @param vTaxArea Area de la factura en caso de querer forzarlo, + * en la mayoria de los casos poner NULL + * @return vInvoiceId + */ + DECLARE vIsRefEditable BOOLEAN; + CALL invoiceFromTicket(vTicketFk); + CALL invoiceOut_new(vSerial, util.VN_CURDATE(), vTaxArea, vInvoiceId); + + IF vRef IS NOT NULL THEN + SELECT isRefEditable INTO vIsRefEditable + FROM invoiceOutSerial + WHERE code = vSerial; + IF NOT vIsRefEditable THEN + CALL util.throw('serial non editable'); + END IF; + + UPDATE invoiceOut + SET `ref` = vRef + WHERE id = vInvoiceId; + END IF; + + IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN + CALL invoiceOutBooking(vInvoiceId); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/invoiceTaxMake.sql b/db/routines/vn/procedures/invoiceTaxMake.sql new file mode 100644 index 000000000..30296dc26 --- /dev/null +++ b/db/routines/vn/procedures/invoiceTaxMake.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceTaxMake`(vInvoice INT, vTaxArea VARCHAR(25)) +BEGIN +/** + * Factura un conjunto de tickets. + * + * @param vInvoice, vTaxAreaFk + * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular + * @return tmp.ticketAmount + * @return tmp.ticketTax Impuesto desglosado para cada ticket. + */ + DELETE FROM invoiceOutTax + WHERE invoiceOutFk = vInvoice; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM tmp.ticketToInvoice; + + CALL ticket_getTax(vTaxArea); + + INSERT INTO invoiceOutTax( + invoiceOutFk, + pgcFk, + taxableBase, + vat + ) + SELECT vInvoice, + pgcFk, + SUM(taxableBase) as BASE, + CAST(SUM(taxableBase) * rate / 100 AS DECIMAL (10,2)) + FROM tmp.ticketTax + GROUP BY pgcFk + HAVING BASE + ORDER BY priority; + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketTax; + DROP TEMPORARY TABLE tmp.ticketAmount; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemBarcode_update.sql b/db/routines/vn/procedures/itemBarcode_update.sql new file mode 100644 index 000000000..e2f13dc93 --- /dev/null +++ b/db/routines/vn/procedures/itemBarcode_update.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemBarcode_update`(vItemFk INT,vCode VARCHAR(22), vDelete BOOL) +BEGIN +IF vDelete THEN + DELETE FROM vn.itemBarcode WHERE itemFk = vItemFk AND code = vCode; +ELSE + INSERT INTO vn.itemBarcode(itemFk,code) VALUES (vItemFk,vCode); +END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemFuentesBalance.sql b/db/routines/vn/procedures/itemFuentesBalance.sql new file mode 100644 index 000000000..d793841ee --- /dev/null +++ b/db/routines/vn/procedures/itemFuentesBalance.sql @@ -0,0 +1,80 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemFuentesBalance`(vDaysInFuture INT) +BEGIN + + /* Se utiliza para calcular la necesidad de mover mercancia entre el almacén de fuentes y el nuestro + * + * @param vDaysInFuture Rango de dias para calcular entradas y salidas + * + */ + + DECLARE vWarehouseFk INT; + + SELECT s.warehouseFk INTO vWarehouseFk + FROM vn.sector s + WHERE s.code = 'FUENTES_PICASSE'; + + CALL cache.stock_refresh(FALSE); + + SELECT i.id itemFk, + i.longName, + i.size, + i.subName, + v.amount - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as visible, + fue.Fuentes, + alb.Albenfruit, + sale.venta, + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, + IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) + - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as saldo + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN ( + SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Fuentes + 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 s.code = 'FUENTES_PICASSE' + GROUP BY ish.itemFk + ) fue ON fue.itemFk = i.id + LEFT JOIN ( + SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Albenfruit + 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 s.code = 'ALBENFRUIT' + GROUP BY ish.itemFk + ) alb ON alb.itemFk = i.id + LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta + FROM vn2008.item_out + WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE())) + AND warehouse_id = vWarehouseFk + GROUP BY item_id + ) sale ON sale.item_id = i.id + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra + FROM vn2008.item_entry_in + WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE())) + AND warehouse_id = vWarehouseFk + AND isVirtualStock = FALSE + GROUP BY item_id + ) buy ON buy.item_id = i.id + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado + FROM vn2008.item_entry_out + WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE())) + AND warehouse_id = vWarehouseFk + GROUP BY item_id + ) mov ON mov.item_id = i.id + WHERE (v.amount OR fue.Fuentes OR alb.Albenfruit) + AND i.itemPackingTypeFk = 'H' + AND ic.shortLife + ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemPlacementFromTicket.sql b/db/routines/vn/procedures/itemPlacementFromTicket.sql new file mode 100644 index 000000000..1a1a735e5 --- /dev/null +++ b/db/routines/vn/procedures/itemPlacementFromTicket.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementFromTicket`(vTicket INT) +BEGIN +/** + * Llama a itemPlacementUpdateVisible + * de los articulos de la tabla temporal tmp.itemPlacement(itemFk) + * @treturn tmp.itemPlacement + * @param vTicket Id del Ticket + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.itemPlacement; + CREATE TEMPORARY TABLE tmp.itemPlacement + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT s.itemFk + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + WHERE t.id = vTicket; + + CALL itemPlacementUpdateVisible(); + + DROP TEMPORARY TABLE tmp.itemPlacement; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemPlacementSupplyAiming.sql b/db/routines/vn/procedures/itemPlacementSupplyAiming.sql new file mode 100644 index 000000000..ee9125a7b --- /dev/null +++ b/db/routines/vn/procedures/itemPlacementSupplyAiming.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyAiming`(vShelvingFk VARCHAR(10), quantity INT, vItemFk INT) +BEGIN + + SELECT ish.itemFk, + ish.longName, + ish.size, + ish.subName, + ish.itemShelvingFk, + ish.shelving, + ish.stock, + LEAST(ish.stock,quantity) as total, + CONCAT( + CAST(FLOOR(LEAST(ish.stock,quantity) / ish.packing) AS DECIMAL(10,0)), + ' x ', + ish.packing, + IF ( + LEAST(ish.stock,quantity) MOD ish.packing, + CONCAT(' + ',CAST(LEAST(ish.stock,quantity) MOD ish.packing AS DECIMAL(10,0))), + '' + ), + ' = ', + LEAST(ish.stock,quantity) + ) as proposal + FROM vn.itemShelvingPlacementSupplyStock ish + WHERE ish.shelving = vShelvingFk COLLATE utf8_general_ci + AND ish.itemFk = vItemFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemPlacementSupplyCloseOrder.sql b/db/routines/vn/procedures/itemPlacementSupplyCloseOrder.sql new file mode 100644 index 000000000..9c4457a5e --- /dev/null +++ b/db/routines/vn/procedures/itemPlacementSupplyCloseOrder.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyCloseOrder`(vId INT, vQuantity INT) +BEGIN + + UPDATE vn.itemPlacementSupply + SET priority = 10 + WHERE id = vId; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemPlacementSupplyGetOrder.sql b/db/routines/vn/procedures/itemPlacementSupplyGetOrder.sql new file mode 100644 index 000000000..b23f69fe7 --- /dev/null +++ b/db/routines/vn/procedures/itemPlacementSupplyGetOrder.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyGetOrder`(vSector INT ) +BEGIN + + DECLARE vId INT; + DECLARE vLastParkingFk INT; + DECLARE vNextParkingFk INT; + + SELECT sh.parkingFk INTO vLastParkingFk + FROM vn.itemShelvingPlacementSupply isps + JOIN vn.itemShelving ish ON ish.id = isps.itemShelvingFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + WHERE isps.userFk = getUser() + ORDER BY isps.created DESC + LIMIT 1; + + SET vNextParkingFk = vn.itemShelvingPlacementSupply_ClosestGet(vLastParkingFk); + + SELECT ipsl.id INTO vId + FROM vn.itemPlacementSupplyList ipsl + JOIN vn.itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk + WHERE ipsl.saldo > 0 + AND (ipsl.repoUserFk is NULL OR ipsl.repoUserFk = getUser()) + AND ipsl.sectorFk = vSector + ORDER BY ipsl.repoUserFk DESC, ipsl.priority DESC, (ispss.parkingFk = vNextParkingFk) DESC, ispss.parking DESC, ipsl.created + LIMIT 1; + + UPDATE vn.itemPlacementSupply + SET repoUserFk = getUser() + WHERE id = vId; + + SELECT * FROM vn.itemPlacementSupplyList + WHERE id = vId + AND sectorFk = vSector; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemPlacementSupplyStockGetTargetList.sql b/db/routines/vn/procedures/itemPlacementSupplyStockGetTargetList.sql new file mode 100644 index 000000000..424e3438d --- /dev/null +++ b/db/routines/vn/procedures/itemPlacementSupplyStockGetTargetList.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemPlacementSupplyStockGetTargetList`(vItemFk INT,vSectorFk INT) +BEGIN +/** + * Devuelve la lista de ubicaciones para itemFk en ese sector. Se utiliza en la preparación previa. + * Este proc se llama a continuacion de ticketToPrePrepare + * + * @param vItemFk Identificador de vn.item + * @param vSectorFk Identificador de vn.sector + */ + DECLARE vWarehouseAliasFk INT; + + SELECT w.aliasFk INTO vWarehouseAliasFk + FROM vn.sector s + JOIN vn.warehouse w ON w.id = s.warehouseFk + WHERE s.id = vSectorFk; + + SELECT ish.shelvingFk shelving, + p.code parking, + sum(ish.visible) as stockTotal, + ish.created, + p.pickingOrder + 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 sc ON sc.id = p.sectorFk + JOIN vn.warehouse w ON w.id = sc.warehouseFk + WHERE w.aliasFk = vWarehouseAliasFk + AND ish.visible > 0 + AND ish.itemFk = vItemFk + GROUP BY ish.id + ORDER BY (sc.id = vSectorFk) DESC, sh.priority DESC, ish.created, p.pickingOrder; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemProposal.sql b/db/routines/vn/procedures/itemProposal.sql new file mode 100644 index 000000000..74d356d77 --- /dev/null +++ b/db/routines/vn/procedures/itemProposal.sql @@ -0,0 +1,87 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal`(vItemFk INT, vTicketFk INT,vShowType BOOL) +BEGIN + +/** + * Propone articulos disponible ordenado, con la cantidad de veces usado y segun sus caracteristicas + * + * @param vItemFk item id + * @param vTicketFk ticket id + * @param vShowType mostrar tipos + */ + + DECLARE vWarehouseFk INT; + DECLARE vShipped DATE; + DECLARE vCalcFk INT; + DECLARE vTypeFk INT; + + DECLARE vTag1 VARCHAR(25); + DECLARE vTag5 VARCHAR(25); + DECLARE vTag6 VARCHAR(25); + DECLARE vTag7 VARCHAR(25); + DECLARE vTag8 VARCHAR(25); + + DECLARE vValue1 VARCHAR(50); + DECLARE vValue5 VARCHAR(50); + DECLARE vValue6 VARCHAR(50); + DECLARE vValue7 VARCHAR(50); + DECLARE vValue8 VARCHAR(50); + + SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped + FROM vn.ticket + WHERE id = vTicketFk; + + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value + INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 + FROM vn.item i + LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 + LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + WHERE i.id = vItemFk; + + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); + + SELECT i.id itemFk, + i.longName, + i.subName, + i.tag5, + i.value5, + (i.value5 <=> vValue5 COLLATE utf8_general_ci) match5, + i.tag6, + i.value6, + (i.value6 <=> vValue6 COLLATE utf8_general_ci) match6, + i.tag7, + i.value7, + (i.value7 <=> vValue7 COLLATE utf8_general_ci) match7, + i.tag8, + i.value8, + (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, + a.available, + IFNULL(ip.counter,0) counter, + IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity, + iss.visible located + FROM item i + JOIN cache.available a ON a.item_id = i.id + LEFT JOIN itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk + LEFT JOIN itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 + LEFT JOIN tag t1 ON t1.id = it1.tagFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id AND iss.warehouseFk = vWarehouseFk + WHERE a.calc_id = vCalcFk + AND available > 0 + AND IF(vShowType,i.typeFk = vTypeFk,true) + AND i.id != vItemFk + ORDER BY counter DESC, + (t1.name = vTag1 COLLATE utf8_general_ci) DESC, + (it1.value = vValue1 COLLATE utf8_general_ci) DESC, + (i.tag5 = vTag5 COLLATE utf8_general_ci) DESC, + (i.value5 = vValue5 COLLATE utf8_general_ci) DESC, + (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, + (i.value6 = vValue6 COLLATE utf8_general_ci) DESC, + (i.tag7 = vTag7 COLLATE utf8_general_ci) DESC, + (i.value7 = vValue7 COLLATE utf8_general_ci) DESC, + (i.tag8 = vTag8 COLLATE utf8_general_ci) DESC, + (i.value8 = vValue8 COLLATE utf8_general_ci) DESC; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemProposal_Add.sql b/db/routines/vn/procedures/itemProposal_Add.sql new file mode 100644 index 000000000..537cecb1c --- /dev/null +++ b/db/routines/vn/procedures/itemProposal_Add.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal_Add`(vSaleFk INT, vMateFk INT, vQuantity INT) +BEGIN +/** + * Añade un nuevo articulo para sustituir a otro, y actualiza la memoria de sustituciones. + * + * @param vSaleFk id de la tabla sale + * @param vMateFk articulo sustituto + * @ param vQuantity cantidad que se va a sustituir + */ + DECLARE vTicketFk INT; + DECLARE vItemFk INT; + DECLARE vWarehouseFk SMALLINT; + DECLARE vDate DATE; + DECLARE vGrouping INT; + DECLARE vBox INT; + DECLARE vPacking INT; + DECLARE vRoundQuantity INT DEFAULT 1; + + SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk + INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + WHERE s.id = vSaleFk; + + UPDATE vn.sale + SET quantity = quantity - vQuantity + WHERE id = vSaleFk; + + CALL vn.buyUltimate(vWarehouseFk, vDate); + + SELECT `grouping`, groupingMode, packing + INTO vGrouping,vBox,vPacking + FROM buy b + JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk + WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; + + IF vBox = 2 AND vPacking > 0 THEN + SET vRoundQuantity = vPacking; + END IF; + IF vBox = 1 AND vGrouping > 0 THEN + SET vRoundQuantity = vGrouping; + END IF; + + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept) + SELECT vTicketFk, vMateFk, CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ',i.longName) + FROM vn.item i + WHERE id = vMateFk; + + SELECT LAST_INSERT_ID() INTO vSaleFk; + + CALL vn.sale_calculateComponent(vSaleFk, NULL); + + INSERT INTO vn.itemProposal(itemFk, mateFk, counter) + VALUES(vItemFk, vMateFk, 1) + ON DUPLICATE KEY UPDATE counter = counter + 1; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemProposal_beta.sql b/db/routines/vn/procedures/itemProposal_beta.sql new file mode 100644 index 000000000..4a6f761a9 --- /dev/null +++ b/db/routines/vn/procedures/itemProposal_beta.sql @@ -0,0 +1,76 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal_beta`(vItemFk INT, vTicketFk INT) +BEGIN + + DECLARE vWarehouseFk INT; + DECLARE vShipped DATE; + DECLARE vCalcFk INT; + DECLARE vTypeFk INT; + DECLARE vResultsMax INT DEFAULT 10; + + DECLARE vTag1 VARCHAR(25); + DECLARE vTag5 VARCHAR(25); + DECLARE vTag6 VARCHAR(25); + DECLARE vTag7 VARCHAR(25); + DECLARE vTag8 VARCHAR(25); + + DECLARE vValue1 VARCHAR(50); + DECLARE vValue5 VARCHAR(50); + DECLARE vValue6 VARCHAR(50); + DECLARE vValue7 VARCHAR(50); + DECLARE vValue8 VARCHAR(50); + + SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped + FROM vn.ticket + WHERE id = vTicketFk; + + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value + INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 + FROM vn.item i + LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 + LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + WHERE i.id = vItemFk; + + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); + + SELECT i.id itemFk, + i.longName, + i.subName, + i.tag5, + i.value5, + (i.value5 <=> vValue5 COLLATE utf8_general_ci) match5, + i.tag6, + i.value6, + (i.value6 <=> vValue6 COLLATE utf8_general_ci) match6, + i.tag7, + i.value7, + (i.value7 <=> vValue7 COLLATE utf8_general_ci) match7, + i.tag8, + i.value8, + (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, + a.available, + IFNULL(ip.counter,0) counter + FROM vn.item i + JOIN cache.available a ON a.item_id = i.id + LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk + LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 + LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + WHERE a.calc_id = vCalcFk + AND available > 0 + AND i.typeFk = vTypeFk + AND i.id != vItemFk + ORDER BY counter DESC, + (t1.name = vTag1 COLLATE utf8_general_ci) DESC, + (it1.value = vValue1 COLLATE utf8_general_ci) DESC, + (i.tag5 = vTag5 COLLATE utf8_general_ci) DESC, + (i.value5 = vValue5 COLLATE utf8_general_ci) DESC, + (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, + (i.value6 = vValue6 COLLATE utf8_general_ci) DESC, + (i.tag7 = vTag7 COLLATE utf8_general_ci) DESC, + (i.value7 = vValue7 COLLATE utf8_general_ci) DESC, + (i.tag8 = vTag8 COLLATE utf8_general_ci) DESC, + (i.value8 = vValue8 COLLATE utf8_general_ci) DESC + LIMIT vResultsMax; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemRefreshTags.sql b/db/routines/vn/procedures/itemRefreshTags.sql new file mode 100644 index 000000000..21af20c0f --- /dev/null +++ b/db/routines/vn/procedures/itemRefreshTags.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemRefreshTags`(IN vItem INT) +BEGIN +/** + * Crea la tabla temporal necesaria para el procedimiento item_refreshTags + * + * @param vItem Articulo a modificar + * @param temporary table tmp.item(id) del articulo + **/ + DROP TEMPORARY TABLE IF EXISTS tmp.item; + + CREATE TEMPORARY TABLE tmp.item + SELECT vItem id; + + CALL item_refreshTags(); + + DROP TEMPORARY TABLE tmp.item; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemSale_byWeek.sql b/db/routines/vn/procedures/itemSale_byWeek.sql new file mode 100644 index 000000000..bc43b7b16 --- /dev/null +++ b/db/routines/vn/procedures/itemSale_byWeek.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemSale_byWeek`(vWeek INT, IN vYear INT, vItemFk INT, vWarehouseFk INT) +BEGIN + + DECLARE vStarted DATE; + DECLARE vEnded DATETIME; + + SELECT MIN(dated), util.dayEnd(MAX(dated)) INTO vStarted, vEnded + FROM `time` t + WHERE CONCAT(vYear, LPAD(vWeek, 2, 0)) = t.period; + + SELECT t.shipped, + w.name warehouse, + s.ticketFk, + t.nickname client, + am.name agencyName, + wk.code salesPerson, + s.itemFk, + IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept, + s.quantity, + s.price, + s.priceFixed, + s.discount, + tls.name stateName, + sb.buyFk, + s.id saleFk, + wk.id salesPersonFk + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN address a ON a.id = t.addressFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN `client` c ON c.id = a.clientFk + LEFT JOIN worker wk ON wk.id = c.salesPersonFk + LEFT JOIN ticketLastState tls ON tls.ticketFk = t.id + LEFT JOIN saleBuy sb ON sb.saleFk = s.id + LEFT JOIN buy b ON b.id = sb.buyFk + LEFT JOIN item ig ON ig.id = b.itemOriginalFk + WHERE s.itemFk = vItemFk + AND t.shipped BETWEEN vStarted AND vEnded + AND IF(vWarehouseFk = 0, w.hasComission , t.warehouseFk = vWarehouseFk) + ORDER BY t.shipped, t.id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemSaveMin.sql b/db/routines/vn/procedures/itemSaveMin.sql new file mode 100644 index 000000000..510638348 --- /dev/null +++ b/db/routines/vn/procedures/itemSaveMin.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemSaveMin`(min INT,vBarcode VARCHAR(22)) +BEGIN + + DECLARE vItemFk INT; + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; + + UPDATE vn.item SET minimum = min WHERE id = vItemFk; + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemSearchShelving.sql b/db/routines/vn/procedures/itemSearchShelving.sql new file mode 100644 index 000000000..8c2c6c7c8 --- /dev/null +++ b/db/routines/vn/procedures/itemSearchShelving.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemSearchShelving`(`vShelvingFk` VARCHAR(3)) +BEGIN + SELECT p.`column` AS col , p.`row` + FROM vn.shelving s + JOIN parking p ON s.parkingFk = p.id + WHERE s.`code` = vShelvingFk COLLATE utf8_general_ci; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingDelete.sql b/db/routines/vn/procedures/itemShelvingDelete.sql new file mode 100644 index 000000000..f895782d3 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingDelete`(vId INT) +BEGIN + + DELETE FROM vn.itemShelving WHERE id = vId; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingLog_get.sql b/db/routines/vn/procedures/itemShelvingLog_get.sql new file mode 100644 index 000000000..ad67ea5cd --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingLog_get.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingLog_get`(vShelvingFk VARCHAR(10) ) +BEGIN + +/** + * Devuelve el log de los item en cada carro + * + * @param vShelvingFk Matrícula del carro + * + */ + + SELECT isl.itemShelvingFk, + isl.created, + isl.accion, + isl.itemFk, + isl.shelvingFk, + isl.quantity, + isl.visible, + isl.available, + isl.grouping, + isl.packing, + isl.stars, + item.longName, + item.size, + item.subName, + worker.code, + isl.accion + FROM item + JOIN itemShelvingLog isl ON item.id = isl.itemFk + JOIN worker ON isl.workerFk = worker.id + WHERE shelvingFk = vShelvingFk OR isl.itemFk = vShelvingFk + ORDER BY isl.created DESC; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingMakeFromDate.sql b/db/routines/vn/procedures/itemShelvingMakeFromDate.sql new file mode 100644 index 000000000..2dde68829 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingMakeFromDate.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` 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; + + IF (SELECT COUNT(*) FROM vn.itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk + AND packing = vPacking) = 1 THEN + + UPDATE vn.itemShelving + SET visible = visible+vQuantity, + created = vCreated + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk + AND packing = vPacking; + + ELSE + CALL cache.last_buy_refresh(FALSE); + INSERT INTO itemShelving( itemFk, + shelvingFk, + visible, + created, + `grouping`, + packing, + packagingFk) + SELECT vItemFk, + vShelvingFk, + vQuantity, + vCreated, + IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) `grouping`, + IF(vPacking = 0, b.packing, vPacking) packing, + IF(vPackagingFk = '', b.packagingFk, vPackagingFk) packaging + FROM vn.item i + LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + WHERE i.id = vItemFk; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingMatch.sql b/db/routines/vn/procedures/itemShelvingMatch.sql new file mode 100644 index 000000000..9a10c2b87 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingMatch.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingMatch`(vEntryFk INT, vAllTravel BOOLEAN, vFromTimed DATETIME, vToTimed DATETIME) +BEGIN + + DECLARE vTravelFk INT; + + SELECT travelFk INTO vTravelFk + FROM entry + WHERE id = vEntryFk; + + SELECT i.id, i.longName, i.size, i.subName, b.stickers, ish.etiquetas, b.printed + FROM item i + JOIN ( + SELECT itemFk, sum(stickers) AS stickers, sum(printedStickers) as printed + FROM buy b + JOIN entry e ON e.id = b.entryFk + WHERE IF(vAllTravel , travelFk = vTravelFk, b.entryFk = vEntryFk) + GROUP BY itemFk + ) b ON b.itemFk = i.id + LEFT JOIN ( + SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking pk ON pk.id = sh.parkingFk + WHERE ish.created BETWEEN vFromTimed AND vToTimed + GROUP BY itemFk + ) ish ON ish.itemFk = id + WHERE b.stickers OR ish.etiquetas; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql b/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql new file mode 100644 index 000000000..c3fc59624 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingPlacementSupplyAdd.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingPlacementSupplyAdd`(vItemShelvingFk INT, vItemPlacementSupplyFk INT, vQuantity INT) +BEGIN + + INSERT INTO vn.itemShelvingPlacementSupply( itemShelvingFk, + itemPlacementSupplyFk, + quantity, + userFk) + VALUES (vItemShelvingFk, + vItemPlacementSupplyFk, + vQuantity, + getUser()); + + UPDATE vn.itemShelving + SET visible = visible - vQuantity + WHERE id = vItemShelvingFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingProblem.sql b/db/routines/vn/procedures/itemShelvingProblem.sql new file mode 100644 index 000000000..01d9d6b5a --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingProblem.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingProblem`(vSectorFk INT) +BEGIN + + DECLARE vVisibleCache INT; + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM vn.sector + WHERE id = vSectorFk; + + CALL cache.visible_refresh (vVisibleCache, FALSE, vWarehouseFk); + + SELECT t.id as ticketFk, + CAST(s.quantity AS DECIMAL(10,0)) as Cantidad, + s.itemFk, + s.concept, + v.visible - GREATEST(0,iss.visible) + IFNULL(sub3.transit,0) as Nicho, + i.subName, + GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo, + s.id as saleFk, + IFNULL(sub3.transit,0) transit, + v.visible, s.isPicked, s.reserved, t.shipped, tst.productionOrder, mm.Id_Movimiento + FROM vn.ticket t + JOIN vn.ticketState tst ON tst.ticketFk = t.id + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN cache.visible v ON s.itemFk = v.item_id AND v.calc_id = vVisibleCache + LEFT JOIN vn2008.Movimientos_mark mm ON mm.Id_Movimiento = s.id AND mm.stateFk = 26 + JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id + LEFT JOIN + (SELECT itemFk, sum(saldo) as transit + FROM vn.itemPlacementSupplyList + WHERE saldo > 0 + AND sectorFk = vSectorFk + GROUP BY itemFk) sub3 ON sub3.itemFk = i.id + WHERE v.visible + IFNULL(sub3.transit,0) - GREATEST(0,iss.visible) < s.quantity + AND IFNULL(sub3.transit,0) < s.quantity + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) + AND tst.isPreviousPreparable = TRUE + AND t.warehouseFk = vWarehouseFk + AND iss.sectorFk = vSectorFk + AND mm.Id_Movimiento IS NULL + ORDER BY itemFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingRadar.sql b/db/routines/vn/procedures/itemShelvingRadar.sql new file mode 100644 index 000000000..778bd9910 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingRadar.sql @@ -0,0 +1,188 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingRadar`(vSectorFk INT) +proc:BEGIN + + DECLARE vCalcVisibleFk INT; + DECLARE vCalcAvailableFk INT; + DECLARE hasFatherSector BOOLEAN; + DECLARE vBuyerFk INT DEFAULT 0; + DECLARE vWarehouseFk INT DEFAULT 0; + DECLARE vSonSectorFk INT; + DECLARE vWorkerFk INT; + + SELECT s.workerFk + INTO vWorkerFk + FROM vn.sector s + WHERE s.id = vSectorFk; + + SELECT w.id, s.warehouseFk INTO vBuyerFk, vWarehouseFk + FROM vn.worker w + JOIN vn.sector s ON s.code = w.code + WHERE s.id = vSectorFk; + + SELECT s.id INTO vSectorFk + FROM vn.sector s + WHERE s.warehouseFk = vWarehouseFk + AND s.isMain; + + SELECT COUNT(*) INTO hasFatherSector + FROM vn.sector + WHERE sonFk = vSectorFk; + + SELECT warehouseFk, sonFk INTO vWarehouseFk, vSonSectorFk + FROM vn.sector + WHERE id = vSectorFk; + + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); + CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar; + + IF hasFatherSector THEN + CREATE TEMPORARY TABLE tmp.itemShelvingRadar + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT iss.itemFk, + i.longName, + i.size, + i.subName producer, + IFNULL(a.available,0) available, + SUM(IF(s.sonFk = vSectorFk, IFNULL(iss.visible,0), 0)) upstairs, + SUM(IF(iss.sectorFk = vSectorFk, IFNULL(iss.visible,0), 0)) downstairs, + IF(it.isPackaging, NULL, IFNULL(v.visible,0)) as visible, + vSectorFk sectorFk + FROM vn.itemShelvingStock iss + JOIN vn.sector s ON s.id = iss.sectorFk + JOIN vn.item i on i.id = iss.itemFk + JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk) + LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk + LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk + WHERE vSectorFk IN (iss.sectorFk, s.sonFk) + GROUP BY iss.itemFk + + UNION ALL + + SELECT v.item_id, + i.longName, + i.size, + i.subName producer, + IFNULL(a.available,0) as available, + 0 upstairs, + 0 downstairs, + IF(it.isPackaging, NULL, v.visible) visible, + vSectorFk as sectorFk + FROM cache.visible v + JOIN vn.item i on i.id = v.item_id + JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk) + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk + LEFT JOIN cache.available a ON a.item_id = v.item_id AND a.calc_id = vCalcAvailableFk + WHERE v.calc_id = vCalcVisibleFk + AND iss.itemFk IS NULL + AND it.isInventory + ) sub GROUP BY itemFk; + + SELECT ishr.*, + CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho, + CAST(downstairs - IFNULL(notPickedYed,0) AS DECIMAL(10,0)) as pendiente + FROM tmp.itemShelvingRadar ishr + JOIN vn.item i ON i.id = ishr.itemFk + LEFT JOIN (SELECT s.itemFk, sum(s.quantity) as notPickedYed + FROM vn.ticket t + JOIN vn.ticketStateToday tst ON tst.ticketFk = t.id + JOIN vn.sale s ON s.ticketFk = t.id + WHERE t.warehouseFk = vWarehouseFk + AND tst.alertLevel = 0 + GROUP BY s.itemFk + ) sub ON sub.itemFk = ishr.itemFk + ORDER BY i.typeFk, i.longName; + ELSE + CREATE TEMPORARY TABLE tmp.itemShelvingRadar + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT iss.itemFk, + 0 `hour`, + 0 `minute`, + '--' itemPlacementCode, + i.longName, + i.size, + i.subName producer, + i.upToDown, + IFNULL(a.available,0) available, + IFNULL(v.visible - iss.visible,0) dayEndVisible, + IFNULL(v.visible - iss.visible,0) firstNegative, + IFNULL(v.visible - iss.visible,0) itemPlacementVisible, + IFNULL(i.minimum * b.packing,0) itemPlacementSize, + ips.onTheWay, + iss.visible itemShelvingStock, + IFNULL(v.visible,0) visible, + b.isPickedOff, + iss.sectorFk + FROM vn.itemShelvingStock iss + JOIN vn.item i on i.id = iss.itemFk + LEFT JOIN cache.last_buy lb ON lb.item_id = iss.itemFk AND lb.warehouse_id = vWarehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk + LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk + LEFT JOIN (SELECT itemFk, sum(saldo) as onTheWay + FROM vn.itemPlacementSupplyList + WHERE saldo > 0 + GROUP BY itemFk + ) ips ON ips.itemFk = i.id + WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk) + OR iss.sectorFk = vSectorFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemOutTime; + CREATE TEMPORARY TABLE tmp.itemOutTime + SELECT *,SUM(amount) quantity + FROM + (SELECT item_id itemFk, + amount, + IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours, + IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes + FROM vn2008.item_out io + JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.item_id + JOIN vn.ticket t on t.id= io.ticketFk + JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk + JOIN vn.state s ON s.id = ts.stateFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN (SELECT DISTINCT saleFk + FROM vn.saleTracking st + WHERE st.created > util.VN_CURDATE() + AND st.isChecked + ) stPrevious ON `stPrevious`.`saleFk` = io.saleFk + WHERE t.warehouseFk = vWarehouseFk + AND s.isPicked = 0 + AND NOT io.Reservado + AND stPrevious.saleFk IS NULL + AND io.dat >= util.VN_CURDATE() + AND io.dat < util.VN_CURDATE() + INTERVAL 1 DAY + ) sub + GROUP BY itemFk, hours, minutes; + + INSERT INTO tmp.itemShelvingRadar (itemFk) + SELECT itemFk FROM tmp.itemOutTime + ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity, + firstNegative = if (firstNegative < 0, firstNegative, firstNegative + quantity), + `hour` = ifnull(if (firstNegative > 0 , `hour`, hours),0), + `minute` = ifnull(if (firstNegative > 0, `minute`, minutes),0); + + UPDATE tmp.itemShelvingRadar isr + JOIN (SELECT s.itemFk, sum(s.quantity) amount + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN ticketLastState tls ON tls.ticketFk = t.id + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND tls.name = 'Prep Camara' + GROUP BY s.itemFk) sub ON sub.itemFk = isr.itemFk + SET isr.dayEndVisible = dayEndVisible + sub.amount, + firstNegative = firstNegative + sub.amount; + + SELECT * FROM tmp.itemShelvingRadar; + END IF; + + DROP TEMPORARY TABLE tmp.itemShelvingRadar; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingRadar_Entry.sql b/db/routines/vn/procedures/itemShelvingRadar_Entry.sql new file mode 100644 index 000000000..c0b4fcda2 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingRadar_Entry.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingRadar_Entry`(vEntryFk INT) +BEGIN + + DECLARE vWarehouseFk INT DEFAULT 1; + DECLARE vCalcVisibleFk INT; + DECLARE vCalcAvailableFk INT; + DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); + + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); + CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + ENGINE = MEMORY + SELECT DISTINCT itemFk + FROM vn.buy + WHERE entryFk = vEntryFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.item2; + CREATE TEMPORARY TABLE tmp.item2 + ENGINE = MEMORY + SELECT * + FROM tmp.item; + + SELECT i.id as itemFk, + i.minimum, + CAST(IFNULL(v.visible,0) - IFNULL(iss.visible,0) AS DECIMAL(10,0)) as enNicho, + CAST(IFNULL(a.available,0) AS DECIMAL(10,0)) as disponible, + CAST(IFNULL(v.visible,0) - IFNULL(iss.visible,0) - ts.todaySold AS DECIMAL(10,0)) as finalDia + FROM vn.item i + JOIN tmp.item ti ON ti.itemFk = i.id + LEFT JOIN cache.visible v ON v.calc_id = vCalcVisibleFk AND v.item_id = i.id + LEFT JOIN cache.available a ON i.id = a.item_id AND a.calc_id = vCalcAvailableFk + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = i.id + LEFT JOIN ( SELECT s.itemFk, sum(s.quantity) as todaySold + FROM vn.sale s + JOIN tmp.item2 ti ON ti.itemFk = s.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.ticketState tst ON tst.ticketFk = t.id + WHERE t.shipped BETWEEN util.VN_CURDATE() AND vTodayDayEnd + AND t.warehouseFk = vWarehouseFk + AND IFNULL(tst.productionOrder,0) < 5 + GROUP BY s.itemFK + ) ts ON ts.itemFk = i.id; + + + DROP TEMPORARY TABLE tmp.item; + DROP TEMPORARY TABLE tmp.item2; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingRadar_Entry_State_beta.sql b/db/routines/vn/procedures/itemShelvingRadar_Entry_State_beta.sql new file mode 100644 index 000000000..c8b5d4bb4 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingRadar_Entry_State_beta.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingRadar_Entry_State_beta`(vEntryFk INT) +BEGIN + + DECLARE vWarehouseFk INT DEFAULT 1; + DECLARE vCalcVisibleFk INT; + DECLARE vCalcAvailableFk INT; + DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); + + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); + CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + ENGINE = MEMORY + SELECT DISTINCT itemFk + FROM vn.buy + WHERE entryFk = vEntryFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.item2; + CREATE TEMPORARY TABLE tmp.item2 + ENGINE = MEMORY + SELECT * + FROM tmp.item; + + SELECT i.id as itemFk, + CAST(IFNULL(iss.visible,0) - IFNULL(v.visible,0) AS DECIMAL(10,0)) as outShelving + FROM vn.item i + JOIN tmp.item ti ON ti.itemFk = i.id + LEFT JOIN cache.visible v ON v.calc_id = vCalcVisibleFk AND v.item_id = i.id + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = i.id; + + + DROP TEMPORARY TABLE tmp.item; + DROP TEMPORARY TABLE tmp.item2; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_Add.sql b/db/routines/vn/procedures/itemShelvingSale_Add.sql new file mode 100644 index 000000000..80eb4efca --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_Add.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_Add`(vItemShelvingFk INT, vSaleFk INT, vQuantity INT) +BEGIN +/** + * Añade línea a itemShelvingSale y regulariza el carro + * + * @param vItemShelvingFk Id itemShelving + * @param vSaleFk Id de sale + * @param vQuantity cantidad a regularizar + */ + INSERT INTO itemShelvingSale(itemShelvingFk, + saleFk, + quantity, + userFk) + VALUES (vItemShelvingFk, + vSaleFk, + vQuantity, + getUser()); + + UPDATE itemShelving + SET visible = visible - vQuantity + WHERE id = vItemShelvingFk; + + UPDATE vn.saleTracking + SET isChecked = 1 + WHERE saleFk = vSaleFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_reserve.sql b/db/routines/vn/procedures/itemShelvingSale_reserve.sql new file mode 100644 index 000000000..afe65bd78 --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_reserve.sql @@ -0,0 +1,92 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserve`() +BEGIN +/** + * Reserva cantidades con ubicaciones para un conjunto de sales del mismo + * almacen. + * + * @table tmp.sale(saleFk, userFk) + */ + DECLARE vCalcFk INT; + DECLARE vWarehouseFk INT; + DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); + DECLARE vLastPickingOrder INT; + + SELECT t.warehouseFk, MAX(p.pickingOrder) + INTO vWarehouseFk, vLastPickingOrder + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN tmp.sale ts ON ts.saleFk = s.id + LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk + LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + LEFT JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = sh.parkingFk + WHERE t.warehouseFk IS NOT NULL; + + IF vWarehouseFk IS NULL THEN + CALL util.throw('Warehouse not set'); + END IF; + + CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); + + SET @outstanding = 0; + SET @oldsaleFk = 0; + + CREATE OR REPLACE TEMPORARY TABLE tSalePlacementQuantity + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT saleFk, userFk, quantityToReserve, itemShelvingFk + FROM( SELECT saleFk, + sub.userFk, + itemShelvingFk , + IF(saleFk <> @oldsaleFk, @outstanding := quantity, @outstanding), + @qtr := LEAST(@outstanding, available) quantityToReserve, + @outStanding := @outStanding - @qtr, + @oldsaleFk := saleFk + FROM( + SELECT ts.saleFk, + ts.userFk, + s.quantity, + ish.id itemShelvingFk, + ish.visible - IFNULL(ishr.reservedQuantity, 0) available + FROM tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + JOIN itemShelving ish ON ish.itemFk = s.itemFk + LEFT JOIN ( + SELECT itemShelvingFk, SUM(quantity) reservedQuantity + FROM itemShelvingSale + WHERE NOT isPicked + GROUP BY itemShelvingFk) ishr ON ishr.itemShelvingFk = ish.id + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector sc ON sc.id = p.sectorFk + JOIN warehouse w ON w.id = sc.warehouseFk + JOIN productionConfig pc + WHERE w.id = vWarehouseFk + AND NOT sc.isHideForPickers + ORDER BY + s.id, + p.pickingOrder >= vLastPickingOrder, + sh.priority DESC, + ish.visible >= s.quantity DESC, + s.quantity MOD ish.grouping = 0 DESC, + ish.grouping DESC, + IF(pc.orderMode = 'Location', p.pickingOrder, ish.created) + )sub + )sub2 + WHERE quantityToReserve > 0; + + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk) + SELECT itemShelvingFk, + saleFk, + quantityToReserve, + IFNULL(userFk, getUser()) + FROM tSalePlacementQuantity spl; + + DROP TEMPORARY TABLE tmp.sale; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql b/db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql new file mode 100644 index 000000000..9a97130dd --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_reserveByCollection.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserveByCollection`( + vCollectionFk INT(11) +) +BEGIN +/** + * Reserva cantidades con ubicaciones para el contenido de una colección + * + * @param vCollectionFk Identificador de collection + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk)) + ENGINE = MEMORY + SELECT s.id saleFk, NULL userFk + FROM ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + LEFT JOIN ( + SELECT DISTINCT saleFk + FROM saleTracking st + JOIN state s ON s.id = st.stateFk + WHERE st.isChecked + AND s.semaphore = 1)st ON st.saleFk = s.id + WHERE tc.collectionFk = vCollectionFk + AND st.saleFk IS NULL + AND NOT s.isPicked; + + CALL itemShelvingSale_reserve(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql b/db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql new file mode 100644 index 000000000..fb245062e --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_reserveBySale.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reserveBySale`( + vSelf INT , + vQuantity INT, + vUserFk INT +) +BEGIN +/** + * Reserva cantida y ubicación para una saleFk + * + * @param vSelf Identificador de la venta + * @param vQuantity Cantidad a reservar + * @param vUserFk Id de usuario que realiza la reserva + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + ENGINE = MEMORY + SELECT vSelf saleFk, vUserFk userFk; + + CALL itemShelvingSale_reserve(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql new file mode 100644 index 000000000..b792534fb --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -0,0 +1,118 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setQuantity`( + vItemShelvingSaleFk INT(10), + vQuantity DECIMAL(10,0), + vIsItemShelvingSaleEmpty BOOLEAN +) +BEGIN +/** + * Gestiona la reserva de un itemShelvingFk, actualizando isPicked y quantity + * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. + * Si la reserva de la ubicación es fallida, se regulariza la situación + * + * @param vItemShelvingSaleFk Id itemShelvingSaleFK + * @param vQuantity Cantidad real que se ha cogido de la ubicación + * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha + * quedado vacio tras el movimiento + */ + DECLARE vSaleFk INT; + DECLARE vCursorSaleFk INT; + DECLARE vItemShelvingFk INT; + DECLARE vReservedQuantity INT; + DECLARE vRemainingQuantity INT; + DECLARE vItemFk INT; + DECLARE vUserFk INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; + DECLARE vSales CURSOR FOR + SELECT iss.saleFk, iss.userFk + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.id = vItemShelvingSaleFk + AND s.itemFk = vItemFk + AND NOT iss.isPicked; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + IF (SELECT isPicked FROM itemShelvingSale WHERE id = vItemShelvingSaleFk) THEN + CALL util.throw('Booking completed'); + END IF; + + SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk + INTO vItemFk, vSaleFk, vItemShelvingFk + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.id = vItemShelvingSaleFk + AND NOT iss.isPicked; + + UPDATE itemShelvingSale + SET isPicked = TRUE, + quantity = vQuantity + WHERE id = vItemShelvingSaleFk; + + UPDATE itemShelving + SET visible = IF(vIsItemShelvingSaleEmpty, 0, GREATEST(0,visible - vQuantity)) + WHERE id = vItemShelvingFk; + + IF vIsItemShelvingSaleEmpty THEN + OPEN vSales; +l: LOOP + SET vDone = FALSE; + FETCH vSales INTO vCursorSaleFk, vUserFk; + IF vDone THEN + LEAVE l; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk, userFk)) + ENGINE = MEMORY + SELECT vCursorSaleFk, vUserFk; + + CALL itemShelvingSale_reserveWhitUser(); + DROP TEMPORARY TABLE tmp.sale; + + END LOOP; + CLOSE vSales; + + DELETE iss + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.id = vItemShelvingSaleFk + AND s.itemFk = vItemFk + AND NOT iss.isPicked; + END IF; + + SELECT SUM(quantity) INTO vRemainingQuantity + FROM itemShelvingSale + WHERE saleFk = vSaleFk + AND NOT isPicked; + + IF vRemainingQuantity THEN + CALL itemShelvingSale_reserveBySale (vSaleFk, vRemainingQuantity, NULL); + + SELECT SUM(quantity) INTO vRemainingQuantity + FROM itemShelvingSale + WHERE saleFk = vSaleFk + AND NOT isPicked; + + IF NOT vRemainingQuantity <=> 0 THEN + SELECT SUM(iss.quantity) + INTO vReservedQuantity + FROM itemShelvingSale iss + WHERE iss.saleFk = vSaleFk; + + CALL saleTracking_new( + vSaleFk, + TRUE, + vReservedQuantity, + `account`.`myUser_getId`(), + NULL, + 'PREPARED', + TRUE); + + UPDATE sale s + SET s.quantity = vReservedQuantity + WHERE s.id = vSaleFk ; + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingTransfer.sql b/db/routines/vn/procedures/itemShelvingTransfer.sql new file mode 100644 index 000000000..326f8108b --- /dev/null +++ b/db/routines/vn/procedures/itemShelvingTransfer.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingTransfer`(vItemShelvingFk INT, vShelvingFk VARCHAR(3)) +BEGIN +/** + * Transfiere producto de una ubicación a otra, fusionando si coincide el + * packing y la fecha. + * + * @param vItemShelvingFk Identificador de itemShelving + * @param vShelvingFk Identificador de shelving + */ + DECLARE vNewItemShelvingFk INT DEFAULT 0; + + SELECT MAX(ish.id) + INTO vNewItemShelvingFk + FROM itemShelving ish + JOIN ( + SELECT + itemFk, + packing, + created + FROM itemShelving + WHERE id = vItemShelvingFk + ) ish2 + ON ish2.itemFk = ish.itemFk + AND ish2.packing = ish.packing + AND date(ish2.created) = date(ish.created) + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci; + + IF vNewItemShelvingFk THEN + UPDATE itemShelving ish + JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk + SET ish.visible = ish.visible + ish2.visible + WHERE ish.id = vNewItemShelvingFk; + + DELETE FROM itemShelving + WHERE id = vItemShelvingFk; + ELSE + UPDATE itemShelving + SET shelvingFk = vShelvingFk + WHERE id = vItemShelvingFk; + END IF; + + SELECT true; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql new file mode 100644 index 000000000..02762fa0b --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -0,0 +1,63 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) +BEGIN + + +/** + * Añade registro o lo actualiza si ya existe. + * + * @param vShelvingFk matrícula del carro + * @param vBarcode el id del registro + * @param vQuantity indica la cantidad del producto + * @param vPackagingFk el packaging del producto en itemShelving, NULL para coger el de la ultima compra + * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra + * @param vPacking el packing del producto, NULL para coger el de la ultima compra + * @param vWarehouseFk indica el sector + * + **/ + + DECLARE vItemFk INT; + + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN + + INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); + INSERT INTO shelving(code, parkingFk) + SELECT vShelvingFk, id + FROM parking + WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; + + END IF; + + IF (SELECT COUNT(*) FROM itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk + AND packing = vPacking) = 1 THEN + + UPDATE itemShelving + SET visible = visible+vQuantity + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; + + ELSE + CALL cache.last_buy_refresh(FALSE); + INSERT INTO itemShelving( itemFk, + shelvingFk, + visible, + grouping, + packing, + packagingFk) + + SELECT vItemFk, + vShelvingFk, + vQuantity, + IFNULL(vGrouping, b.grouping), + IFNULL(vPacking, b.packing), + IFNULL(vPackagingFk, b.packagingFk) + FROM item i + LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN buy b ON b.id = lb.buy_id + WHERE i.id = vItemFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_addByClaim.sql b/db/routines/vn/procedures/itemShelving_addByClaim.sql new file mode 100644 index 000000000..851162952 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_addByClaim.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_addByClaim`(vClaimFk INT, vShelvingFk VARCHAR(3)) +BEGIN +/** + * Insert items of claim into itemShelving. + * + * @param vClaimFk The claim + * @param vShelvingFk The shelving + * @table tmp.buyUltimate + */ + DECLARE vWarehouseFk INT; + + SELECT t.warehouseFk INTO vWarehouseFk + FROM claim c + JOIN ticket t ON t.id = c.ticketFk + WHERE c.id = vClaimFk; + + CALL buyUltimate (vWarehouseFk, util.VN_CURDATE()); + + INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible) + SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible + FROM claim c + JOIN claimBeginning cb ON c.id = cb.claimFk + JOIN sale s ON s.id = cb.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk AND bu.warehouseFk = t.warehouseFk + JOIN buy b ON b.id = bu.buyFk + WHERE c.id = vClaimFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_addList.sql b/db/routines/vn/procedures/itemShelving_addList.sql new file mode 100644 index 000000000..c07dd985c --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_addList.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(vShelvingFk VARCHAR(3), vList TEXT, vIsChecking BOOL, vWarehouseFk INT) +BEGIN +/* Recorre cada elemento en la colección vList. + * Si el parámetro isChecking = FALSE, llama a itemShelving_add. + * + * Cuando es TRUE sólo inserta los elementos de la colección que no están ya en + * ese shelving, actualizando los valores del campo vn.itemShelving.isChecked + * + * param vShelvingFk Identificador de vn.shelving + * param vList JSON array con esta estructura: '[value1, value2, ...]' + * param vIsChecking Define si hay que añadir o comprobar los items + * param vWarehouseFk Identificador de vn.warehouse + */ + DECLARE vListLength INT DEFAULT JSON_LENGTH(vList); + DECLARE vCounter INT DEFAULT 0; + DECLARE vBarcode VARCHAR(22); + DECLARE vPath VARCHAR(6); + DECLARE vItemFk INT; + DECLARE vIsChecked BOOL; + + WHILE vCounter < vListLength DO + SET vPath = CONCAT('$[',vCounter,']'); + SET vBarcode = JSON_EXTRACT(vList,vPath); + SET vIsChecked = NULL; + IF vIsChecking THEN + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + SELECT COUNT(*) INTO vIsChecked + FROM vn.itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk; + END IF; + + IF NOT (vIsChecking AND vIsChecked) THEN + CALL vn.itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk); + END IF; + + UPDATE vn.itemShelving + SET isChecked = vIsChecked + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk; + + SET vCounter = vCounter + 1; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql new file mode 100644 index 000000000..4ddaf3d12 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -0,0 +1,86 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_filterBuyer`(vBuyerFk INT, vWarehouseFk INT) +proc:BEGIN +/** + * Lista de articulos filtrados por comprador + * + * @param vBuyerFk Comprador a filtrar + * @param vWarehouseFk Warehouse + * @return Lista de articulos + */ + DECLARE vCalcVisibleFk INT; + + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); + + SELECT * FROM + (SELECT sub.itemFk, + sub.longName, + CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer, + sub.upstairs, + sub.downstairs, + sub.visible, + CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho, + sub.name itemColour + FROM (SELECT iss.itemFk, + CONCAT(i.longName, ' ', i.size,' ', IFNULL(i.subName,'') ) longName, + '' size, + CONCAT(iss.parkingCode, ' ', iss.shelvingFk) producer, + 0 upstairs, + SUM(IFNULL(iss.visible,0)) downstairs, + IF(it.isPackaging, null, IFNULL(v.visible, 0)) visible, + ik.name + FROM itemShelvingStock iss + JOIN sector s ON s.id = iss.sectorFk + JOIN item i on i.id = iss.itemFk + LEFT JOIN ink ik ON ik.id = i.inkFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk + WHERE s.warehouseFk = vWarehouseFk + AND it.workerFk = vBuyerFk + GROUP BY itemFk + ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente + FROM sale s + LEFT JOIN saleTracking st ON st.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN client c on c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND st.saleFk IS NULL + AND ct.code IN ('normal', 'trust') + GROUP BY s.itemFk + ) sub2 ON sub2.itemFk = sub.itemFk + UNION ALL + SELECT v.item_id , + i.longName, + CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, + 0, + 0, + v.visible, + v.visible nicho, + ik.name itemColour + FROM cache.visible v + JOIN item i ON i.id = v.item_id + LEFT JOIN ink ik ON ik.id = i.inkFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk + LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente + FROM sale s + LEFT JOIN saleTracking st ON st.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN client c on c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND st.saleFk IS NULL + AND ct.code IN ('normal', 'trust') + GROUP BY s.itemFk + ) sub5 ON sub5.itemFk = v.item_id + WHERE v.calc_id = vCalcVisibleFk + AND iss.itemFk IS NULL + AND it.workerFk = vBuyerFk + ) sub3 + WHERE nicho + ORDER BY producer; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_get.sql b/db/routines/vn/procedures/itemShelving_get.sql new file mode 100644 index 000000000..98f865994 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_get.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_get`(IN vSelf VARCHAR(8)) +BEGIN +/** +* Lista artículos de itemshelving +* +* @param vSelf matrícula del carro +**/ + SELECT ish.itemFk item, + IFNULL(i.longName, CONCAT(i.name, ' ', i.size)) description, + ish.visible, + CEIL(ish.visible/ish.packing) stickers, + ish.packing, + ish.grouping, + p.code, + ish.id, + s.priority, + ish.isChecked + FROM itemShelving ish + JOIN item i ON i.id = ish.itemFk + JOIN shelving s ON vSelf = s.code COLLATE utf8_unicode_ci + LEFT JOIN parking p ON s.parkingFk = p.id + WHERE ish.shelvingFk COLLATE utf8_unicode_ci = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_getAlternatives.sql b/db/routines/vn/procedures/itemShelving_getAlternatives.sql new file mode 100644 index 000000000..de30d46ac --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_getAlternatives.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getAlternatives`(vShelvingFk VARCHAR(10)) +BEGIN +/** + * Devuelve un listado de posibles ubicaciones alternativas a ubicar los item de la matricula + * del carro que se le ha pasado. + * + * @param vShelvingFk matricula del carro + */ + SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder + FROM itemShelving is2 + JOIN shelving sh ON sh.code = is2.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + LEFT JOIN operator o ON o.sectorFk = s.id AND o.workerFk = account.myUser_getId() + JOIN warehouse wh ON wh.id = s.warehouseFk + JOIN itemShelving is3 ON is3.itemFk = is2.itemFk AND is3.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + WHERE is2.shelvingFk <> vShelvingFk COLLATE utf8_unicode_ci + GROUP BY is2.id + ORDER BY p.pickingOrder DESC; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_getInfo.sql b/db/routines/vn/procedures/itemShelving_getInfo.sql new file mode 100644 index 000000000..a5749bd26 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_getInfo.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getInfo`(vItemFk VARCHAR(22)) +BEGIN +/** + * Muestra información realtiva a la ubicación de un item + * + * @param vItemFk Id del item + */ + SELECT vn.barcodeToItem(vItemFk) + INTO vItemFk; + + SELECT pk.code Parking, + sh.code Matricula, + ish.visible visible, + ish.created created, + ish.itemFk itemFk, + sh.priority + FROM vn.itemShelving ish + JOIN vn.shelving sh ON sh.`code` = ish.shelvingFk + JOIN vn.parking pk ON pk.id = sh.parkingFk + WHERE ish.itemFk = vItemFk + ORDER BY sh.priority DESC, created ASC; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_getSaleDate.sql b/db/routines/vn/procedures/itemShelving_getSaleDate.sql new file mode 100644 index 000000000..a9f9466cf --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_getSaleDate.sql @@ -0,0 +1,165 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getSaleDate`(vShelvingFk VARCHAR(3)) +BEGIN + + /* Devuelve la mínima fecha en que se necesita cada producto en esa matrícula. + * + * @param vShelvingFk Matrícula del carro o pallet + */ + + DECLARE vWarehouseFk INT; + DECLARE vStockScopeDays INT; + + SELECT s.warehouseFk, stockScopeDays + INTO vWarehouseFk, vStockScopeDays + FROM sector s + JOIN operator o ON s.id = o.sectorFk + JOIN productionConfig pc + WHERE o.workerFk = account.myUser_getId(); + + IF vWarehouseFk IS NULL + THEN CALL util.throw('WarehouseFk not setted'); + END IF; + + IF vStockScopeDays IS NULL + THEN CALL util.throw('StockScopeDays not setted'); + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.tItems + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT itemFk, SUM(visible) visible + FROM itemShelving + WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + GROUP BY itemFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay + (INDEX (itemFk, dated)) + ENGINE = MEMORY + SELECT dated, + SUM(t3.amount) OVER (PARTITION BY t3.itemFk ORDER BY dated) stock, + t3.itemFk + FROM ( + SELECT t.itemFk, dated, SUM(amount) amount + FROM ( + SELECT t2.itemFk, t2.amount, t2.dated + FROM ( + SELECT item_id itemFk, amount, util.VN_CURDATE() dated + FROM cache.stock s + JOIN tmp.tItems i ON i.itemFk = s.item_id + WHERE s.warehouse_id = vWarehouseFk + UNION ALL + SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE() + FROM itemShelving ish + JOIN tmp.tItems i ON i.itemFk = ish.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON sh.parkingFk = p.id + JOIN sector s ON s.id = p.sectorFk + WHERE s.isReserve + GROUP BY ish.itemFk + UNION ALL + SELECT iei.itemFk, SUM(quantity), landed + FROM itemEntryIn iei + JOIN tmp.tItems i ON i.itemFk = iei.itemFk + WHERE iei.landed BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND iei.warehouseInFk = vWarehouseFk + AND NOT isVirtualStock + GROUP BY iei.itemFk, iei.landed + UNION ALL + SELECT ieo.itemFk, SUM(quantity), shipped + FROM itemEntryOut ieo + JOIN tmp.tItems i ON i.itemFk = ieo.itemFk + WHERE ieo.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND ieo.warehouseOutFk = vWarehouseFk + GROUP BY ieo.itemFk, ieo.shipped + UNION ALL + SELECT i.itemFk, SUM(ito.quantity), DATE(ito.shipped) + FROM itemTicketOut ito + JOIN tmp.tItems i ON i.itemFk = ito.itemFk + WHERE ito.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND ito.warehouseFk = vWarehouseFk + GROUP BY ito.itemFk, ito.shipped + ) t2 + JOIN tmp.tItems i ON i.itemFk = t2.itemFk)t + GROUP BY t.itemFk, dated + ) t3; + + -- Se restan las entradas de hoy + UPDATE tmp.tStockByDay sbd + JOIN (SELECT iei.itemFk, SUM(quantity) todayEntry + FROM itemEntryIn iei + JOIN tmp.tItems i ON i.itemFk = iei.itemFk + WHERE iei.landed = util.VN_CURDATE() + AND iei.warehouseInFk = vWarehouseFk + AND NOT iei.isVirtualStock) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock - sub.todayEntry + WHERE sbd.dated = util.VN_CURDATE(); + + -- Se añaden las lineas de venta servidas + UPDATE tmp.tStockByDay sbd + JOIN (SELECT s.itemFK, SUM(quantity) amount + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.warehouseFk = vWarehouseFk + AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() + AND s.isPicked + GROUP BY s.itemFk) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock + sub.amount; + + -- Se añaden los items ubicados hoy + UPDATE tmp.tStockByDay sbd + JOIN (SELECT ish.itemFK, SUM(ish.visible) amount + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND NOT s.isReserve + AND ish.created BETWEEN util.VN_CURDATE() AND util.midnight() + GROUP BY ish.itemFk) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock + sub.amount; + + SELECT ts.itemFk, + i.longName, + IF(ts.stock<=0, ts.dated, NULL) dated, + ts.stock, + sub4.visible, + sub4.shelvingFk + FROM( + SELECT IFNULL(sub2.minDated, sub.minDated) dated, + IFNULL(sub2.itemFk, sub.itemFk) itemFk + FROM(SELECT sbd.itemFk, + MIN(dated) minDated, + sbd.stock + FROM tmp.tItems ti + LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk + GROUP BY itemFk)sub + LEFT JOIN ( + SELECT sbd.itemFk, + MIN(dated) minDated, + sbd.stock + FROM tmp.tItems ti + LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk + WHERE sbd.stock <= 0 + GROUP BY itemFk)sub2 ON sub2.itemFk =sub.itemFk + WHERE sub2.itemFk IS NOT NULL + OR (sub2.itemFk IS NULL AND sub.itemFk IS NOT NULL)) sub3 + LEFT JOIN tmp.tStockByDay ts ON ts.itemFk = sub3.itemFk AND ts.dated = sub3.dated + JOIN (SELECT ish.itemFk, + ish.visible, + p.sectorFk, + ish.shelvingFk + FROM itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = parkingFk + LEFT JOIN vn.sector s ON s.id = p.sectorFk + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + ) sub4 ON sub4.itemFk = ts.itemFk + LEFT JOIN sector s ON s.id = sub4.sectorFk + LEFT JOIN item i ON i.id = ts.itemFk + WHERE NOT s.isReserve; + + DROP TEMPORARY TABLE tmp.tStockByDay, tmp.tItems; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_inventory.sql b/db/routines/vn/procedures/itemShelving_inventory.sql new file mode 100644 index 000000000..ce2934426 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_inventory.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_inventory`(vParkingFromFk VARCHAR(8), vParkingToFk VARCHAR(8)) +BEGIN +/** + * Devuelve un listado de ubicaciones a revisar + * + * @param vParkingFromFk Parking de partida, identificador de parking + * @param vParkingToFk Parking de llegada, identificador de parking + */ + DECLARE vSectorFk INT; + DECLARE vPickingOrderFrom INT; + DECLARE vPickingOrderTo INT; + + SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom + FROM parking p + WHERE p.code = vParkingFromFk COLLATE 'utf8mb3_general_ci'; + + SELECT p.pickingOrder INTO vPickingOrderTo + FROM parking p + WHERE p.code = vParkingToFk COLLATE 'utf8mb3_general_ci'; + + CALL visible_getMisfit(vSectorFk); + + SELECT ish.id, + p.pickingOrder, + p.code parking, + ish.shelvingFk, + ish.itemFk, + i.longName, + ish.visible, + p.sectorFk, + it.workerFk buyer, + CONCAT('http:',ic.url, '/catalog/1600x900/',i.image) urlImage, + ish.isChecked, + CASE + WHEN s.notPrepared > sm.parked THEN 0 + WHEN sm.visible > sm.parked THEN 1 + ELSE 2 + END priority + FROM itemShelving ish + JOIN item i ON i.id = ish.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN ( + SELECT s.itemFk, sum(s.quantity) notPrepared + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN config c ON c.mainWarehouseFk = w.id + WHERE t.shipped BETWEEN util.VN_CURDATE() + AND util.dayEnd(util.VN_CURDATE()) + AND s.isPicked = FALSE + GROUP BY s.itemFk + ) s ON s.itemFk = i.id + JOIN hedera.imageConfig ic + WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo + AND p.sectorFk = vSectorFk + ORDER BY p.pickingOrder; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_selfConsumption.sql b/db/routines/vn/procedures/itemShelving_selfConsumption.sql new file mode 100644 index 000000000..aa6c34199 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_selfConsumption.sql @@ -0,0 +1,86 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_selfConsumption`( + vShelvingFk VARCHAR(10) COLLATE utf8_general_ci, + vItemFk INT, + vQuantity INT +) +BEGIN +/** + * Leave the indicated amount on the shelf + * and create a ticket with the difference. + * + * @param vShelvingFk id of the shelf where the item is located. + * @param vItemFk article of which the self-consumption ticket is to be created. + * @param vQuantity amount that will stay on the shelf + */ + DECLARE vVisible INT; + DECLARE vClientFk INT; + DECLARE vTicketFk INT; + DECLARE vWarehouseFk INT; + DECLARE vCompanyFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vItemShelvingFk INT; + + SELECT c.id, + pc.clientSelfConsumptionFk, + s.warehouseFk + INTO vCompanyFk, + vClientFk, + vWarehouseFk + FROM company c + JOIN address a ON a.clientFk = c.clientFk + JOIN warehouse w ON w.addressFk = a.id + JOIN sector s ON s.warehouseFk = w.id + JOIN parking p ON p.sectorFk = s.id + JOIN shelving s2 ON s2.parkingFk = p.id + JOIN productionConfig pc ON TRUE + WHERE s2.code = vShelvingFk; + + IF vClientFk IS NULL THEN + CALL util.throw('The company does not have a customer assigned'); + END IF; + + IF vQuantity IS NULL OR vQuantity < 0 THEN + CALL util.throw('The shelf cannot have NULL or negative quantities'); + END IF; + + IF vShelvingFk IS NULL THEN + CALL util.throw('The shelf is necessary'); + END IF; + + IF vItemFk IS NULL THEN + CALL util.throw('The article is required to create the ticket.'); + END IF; + + SELECT SUM(visible), id INTO vVisible, vItemShelvingFk + FROM itemShelving + WHERE shelvingFk = vShelvingFk + AND itemFk = vItemFk; + + IF vVisible IS NULL THEN + CALL util.throw('The item is not on the shelf.'); + END IF; + + CALL ticket_getWithParameters( + vClientFk, + vWarehouseFk, + CURDATE(), + NULL, + vCompanyFk, + NULL, + vTicketFk + ); + + INSERT INTO sale (itemFk, ticketFk, quantity, concept) + SELECT vItemFk, vTicketFk, (vVisible - vQuantity), longName + FROM item + WHERE id = vItemFk; + + UPDATE itemShelving + SET visible = IF(id = vItemShelvingFk, vQuantity, 0) + WHERE shelvingFk = vShelvingFk + AND itemFk = vItemFk; + + CALL vn.ticket_setState(vTicketFk, 'DELIVERED'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_update.sql b/db/routines/vn/procedures/itemShelving_update.sql new file mode 100644 index 000000000..079add704 --- /dev/null +++ b/db/routines/vn/procedures/itemShelving_update.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_update`(vVisible INT, vPacking INT, vShelf INT ,vGrouping INT ) +BEGIN +/** + * Actualiza itemShelving. + * + * @param vVisible la cantidad visible del registro a actualizar + * @param vShelf el id del registro a actualizar + * @param vPacking el packing del del producto en itemShelving + * @param vGrouping el grouping del producto en itemShelving + */ + UPDATE itemShelving + SET visible = vVisible, + packing = vPacking, + grouping = vGrouping + WHERE id = vShelf; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemTagMake.sql b/db/routines/vn/procedures/itemTagMake.sql new file mode 100644 index 000000000..6d34ecb78 --- /dev/null +++ b/db/routines/vn/procedures/itemTagMake.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTagMake`(vItemFk INT) +BEGIN + +/* * Crea los tags usando la tabla plantilla itemTag + * y si no existe a partir de la ficha del artículo. + * @param vItemFk El item al que se le añaden los tags +*/ + DECLARE vInk VARCHAR(50); + DECLARE vSize INTEGER; + DECLARE vCategory VARCHAR(3); + DECLARE vProducer VARCHAR(50); + DECLARE vOrigin VARCHAR(20); + DECLARE vTypeFk INTEGER; + + DELETE FROM itemTag + WHERE itemFk = vItemFk; + + SELECT typeFk INTO vTypeFk + FROM item + WHERE id = vItemFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT vItemFk, itt.tagFk, NULL, itt.priority + FROM itemTag it + LEFT JOIN itemTypeTag itt ON itt.itemTypeFk = vTypeFk + WHERE it.itemFk = vItemFk; + + IF (SELECT COUNT(*) FROM itemTag WHERE itemFk = vItemFk LIMIT 1) = 0 THEN + + SELECT ik.name, i.size, i.category, p.name, o.name + INTO vInk, vSize, vCategory, vProducer, vOrigin + FROM item i + LEFT JOIN ink ik ON ik.id = i.inkFk + LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible + LEFT JOIN origin o ON o.id = i.originFk + WHERE i.id = vItemFk; + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + VALUES(vItemFk, 1, vInk, 1); + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + VALUES (vItemFk, 8, vSize, 2); + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + VALUES(vItemFk, 47, vCategory, 3); + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + VALUES(vItemFk, 37, vProducer, 4); + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + VALUES(vItemFk, 35, vOrigin, 5); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemTagReorder.sql b/db/routines/vn/procedures/itemTagReorder.sql new file mode 100644 index 000000000..bba3cfe03 --- /dev/null +++ b/db/routines/vn/procedures/itemTagReorder.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTagReorder`(itemTypeFk INT) +BEGIN + + SET @isTriggerDisabled = TRUE; + + -- No se puede usar temporary porque da error Error Code: 1137. No puedo reabrir tabla: 'i + DROP TABLE IF EXISTS tmp.item; + CREATE TABLE tmp.item + SELECT DISTINCT i.id + FROM vn.item i + WHERE i.typeFk = itemTypeFk; + + UPDATE itemTag it + JOIN tmp.item i ON i.id = it.itemFk + JOIN vn.item ON item.id = i.id + JOIN itemTypeTag itt ON itt.itemTypeFk = item.typeFk AND itt.tagFk = it.tagFk + SET it.priority = itt.priority + WHERE itt.itemTypeFk = itemTypeFk; + + CALL item_refreshTags(); + + SET @isTriggerDisabled = FALSE; + + DROP TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemTagReorderByName.sql b/db/routines/vn/procedures/itemTagReorderByName.sql new file mode 100644 index 000000000..89dc92740 --- /dev/null +++ b/db/routines/vn/procedures/itemTagReorderByName.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTagReorderByName`(vName VARCHAR(255)) +BEGIN + + SET @isTriggerDisabled = TRUE; + + -- No se puede usar temporary porque da error Error Code: 1137. No puedo reabrir tabla: 'i + DROP TABLE IF EXISTS tmp.item; + CREATE TABLE tmp.item + SELECT DISTINCT i.id + FROM vn.item i + WHERE i.`name` LIKE CONCAT(vName,'%'); + + UPDATE itemTag it + JOIN tmp.item i ON i.id = it.itemFk + JOIN vn.item ON item.id = i.id + JOIN itemTypeTag itt ON itt.itemTypeFk = item.typeFk AND itt.tagFk = it.tagFk + SET it.priority = itt.priority + WHERE itt.itemTypeFk = itemTypeFk; + + CALL item_refreshTags(); + + SET @isTriggerDisabled = FALSE; + + DROP TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemTag_replace.sql b/db/routines/vn/procedures/itemTag_replace.sql new file mode 100644 index 000000000..b32285072 --- /dev/null +++ b/db/routines/vn/procedures/itemTag_replace.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTag_replace`(vItemFromFk INT, vItemToFk INT, vPicture VARCHAR(100)) +BEGIN + + /* Reemplaza los tags de un artículo por los de otro, así como su imagen + * + * @param vItemFromFk id de vn.item con el artículo del que se toman los tags + * @param vItemToFk id de vn.item con el artículo del que se toman los tags + * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk + */ + + DELETE FROM vn.itemTag + WHERE itemFk = vItemToFk; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemToFk, tagFk, value, priority + FROM vn.itemTag + WHERE itemFk = vItemFromFk; + + IF ISNULL(vPicture) THEN + + SELECT image INTO vPicture + FROM vn.item + WHERE id = vItemFromFk; + + END IF; + + UPDATE vn.item i + SET i.image = vPicture + WHERE i.id = vItemToFk; + + CALL vn.itemRefreshTags(vItemToFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/itemTopSeller.sql b/db/routines/vn/procedures/itemTopSeller.sql new file mode 100644 index 000000000..f42cf67cf --- /dev/null +++ b/db/routines/vn/procedures/itemTopSeller.sql @@ -0,0 +1,63 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`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, util.VN_CURDATE()) AND util.VN_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 ; diff --git a/db/changes/234001/00-item_setVisibleDiscard.sql b/db/routines/vn/procedures/itemTrash.sql similarity index 67% rename from db/changes/234001/00-item_setVisibleDiscard.sql rename to db/routines/vn/procedures/itemTrash.sql index 6ee66a947..bbb30b78a 100644 --- a/db/changes/234001/00-item_setVisibleDiscard.sql +++ b/db/routines/vn/procedures/itemTrash.sql @@ -1,32 +1,27 @@ - DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setVisibleDiscard`( - vItemFk INT, +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTrash`( + vItemFk INT, vWarehouseFk INT, vQuantity INT, - vAddressFk INT) - + vIsTrash BOOLEAN) BEGIN DECLARE vTicketFk INT; DECLARE vClientFk INT; - DECLARE vCompanyVnlFk INT; + DECLARE vCompanyVnlFk INT DEFAULT 442; DECLARE vCalc INT; SELECT barcodeToItem(vItemFk) INTO vItemFk; - SELECT DEFAULT(companyFk) INTO vCompanyVnlFk - FROM vn.ticket LIMIT 1; - - SELECT a.clientFk INTO vClientFk - FROM address a - WHERE a.id = vAddressFk; + SELECT IF(vIsTrash, 200, 400) INTO vClientFk; SELECT t.id INTO vTicketFk FROM ticket t - JOIN address a ON a.id = t.addressFk + JOIN address a ON a.id=t.addressFk WHERE t.warehouseFk = vWarehouseFk - AND a.id = vAddressFk - AND DATE(t.shipped) = util.VN_CURDATE(); + AND t.clientFk = vClientFk + AND DATE(t.shipped) = util.VN_CURDATE() + AND a.isDefaultAddress + LIMIT 1; CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); @@ -36,7 +31,7 @@ BEGIN util.VN_CURDATE(), vWarehouseFk, vCompanyVnlFk, - vAddressFk, + NULL, NULL, NULL, util.VN_CURDATE(), @@ -48,7 +43,7 @@ BEGIN INSERT INTO sale(ticketFk, itemFk, concept, quantity) SELECT vTicketFk, vItemFk, - CONCAT(longName,' ', getWorkerCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)), + CONCAT(longName,' ',worker_getCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)), vQuantity FROM item WHERE id = vItemFk; @@ -59,4 +54,3 @@ BEGIN AND item_id = vItemFk; END$$ DELIMITER ; - diff --git a/db/routines/vn/procedures/itemUpdateTag.sql b/db/routines/vn/procedures/itemUpdateTag.sql new file mode 100644 index 000000000..59529e2b0 --- /dev/null +++ b/db/routines/vn/procedures/itemUpdateTag.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemUpdateTag`(IN vItem BIGINT) +BEGIN + + +UPDATE item i +JOIN producer p ON p.id = i.producerFk +SET i.subName = p.name +WHERE p.isVisible +AND (vItem IS NULL OR vItem = i.id); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag5 = t.name, value5 = it.value +WHERE it.priority = 1 +AND (vItem IS NULL OR vItem = i.id); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag6 = t.name, value6 = it.value +WHERE it.priority = 2 +AND (vItem IS NULL OR vItem = it.itemFk); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag7 = t.name, value7 = it.value +WHERE it.priority = 3 +AND (vItem IS NULL OR vItem = it.itemFk); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag8 = t.name, value8 = it.value +WHERE it.priority = 4 +AND (vItem IS NULL OR vItem = it.itemFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_GetVisible.sql b/db/routines/vn/procedures/item_GetVisible.sql new file mode 100644 index 000000000..ca5e43107 --- /dev/null +++ b/db/routines/vn/procedures/item_GetVisible.sql @@ -0,0 +1,43 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_GetVisible`(vWarehouse SMALLINT, vItem INT) +BEGIN + DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); + + INSERT INTO tmp.itemVisible (item_id, visible) + SELECT item_id, SUM(amount) amount + FROM ( + SELECT i.itemFk AS item_id, quantity AS amount + FROM itemTicketOut i + LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk + JOIN state s ON s.id = ts.stateFk + LEFT JOIN (SELECT DISTINCT saleFk + FROM saleTracking st + JOIN state s ON s.id = st.stateFk + WHERE st.created > util.VN_CURDATE() + AND (s.isPicked OR st.isChecked) + ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk + WHERE i.warehouseFk = vWarehouse + AND (vItem IS NULL OR i.itemFk = vItem) + AND (s.isPicked OR i.reserved OR stPrevious.saleFk ) + AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow + UNION ALL + SELECT iei.itemFk, quantity + FROM itemEntryIn iei + WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/) + AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow + AND iei.warehouseInFk = vWarehouse + AND (vItem IS NULL OR iei.itemFk = vItem) + AND iei.isVirtualStock is FALSE + UNION ALL + SELECT itemFk, quantity + FROM itemEntryOut + WHERE isDelivered != FALSE + AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow + AND warehouseOutFk = vWarehouse + AND (vItem IS NULL OR itemFk = vItem) + ) t + GROUP BY item_id + ON DUPLICATE KEY UPDATE + visible = IFNULL(stock,0) + VALUES(visible); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_ValuateInventory.sql b/db/routines/vn/procedures/item_ValuateInventory.sql new file mode 100644 index 000000000..bfd96fa82 --- /dev/null +++ b/db/routines/vn/procedures/item_ValuateInventory.sql @@ -0,0 +1,237 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_ValuateInventory`(vDated DATE, vIsDetailed BOOLEAN) +BEGIN + DECLARE vInventoried DATE; + DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE; + DECLARE vInventoryClone DATE; + DECLARE vDateDayEnd DATETIME; + DECLARE vInventorySupplierFk INT; + + SELECT inventorySupplierFk INTO vInventorySupplierFk + FROM entryConfig; + + SET vDateDayEnd = util.dayEnd(vDated); + + SELECT tr.landed INTO vInventoried + FROM travel tr + JOIN `entry` e ON e.travelFk = tr.id + JOIN entryConfig ec + WHERE landed <= vDateDayEnd + AND e.supplierFk = vInventorySupplierFk + ORDER BY tr.landed DESC + LIMIT 1; + + SET vHasNotInventory = (vInventoried IS NULL); + + IF vHasNotInventory THEN + SELECT landed INTO vInventoryClone + FROM travel tr + JOIN `entry` e ON e.travelFk = tr.id + JOIN entryConfig ec + WHERE landed >= vDated + AND e.supplierFk = vInventorySupplierFk + ORDER BY landed ASC + LIMIT 1; + + SET vInventoried = vDated + INTERVAL 1 DAY; + SET vDateDayEnd = vInventoryClone; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tInventory( + warehouseFk SMALLINT, + itemFk BIGINT, + quantity INT, + cost DOUBLE DEFAULT 0, + total DOUBLE DEFAULT 0, + warehouseInventory VARCHAR(20), + PRIMARY KEY (warehouseInventory, itemFk) USING HASH + ) + ENGINE = MEMORY; + + -- Inventario inicial + IF vHasNotInventory THEN + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + SUM(b.quantity), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = warehouseInFk + JOIN entryConfig ec + WHERE landed = vDateDayEnd + AND e.supplierFk = vInventorySupplierFk + AND w.valuatedInventory + AND t.isInventory + GROUP BY tr.warehouseInFk, b.itemFk; + ELSE + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + SUM(b.quantity), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = warehouseInFk + JOIN entryConfig ec + WHERE landed = vInventoried + AND e.supplierFk = vInventorySupplierFk + AND w.valuatedInventory + AND t.isInventory + GROUP BY tr.warehouseInFk, b.itemFk; + END IF; + + -- Añadimos las entradas + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + b.quantity * IF(vHasNotInventory, -1, 1), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = tr.warehouseInFk + JOIN entryConfig ec + WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd + AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE) + AND NOT e.isRaid + AND w.valuatedInventory + AND t.isInventory + AND e.supplierFk <> vInventorySupplierFk + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory, -1, 1)); + + -- Descontamos las salidas + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseOutFk, + b.itemFk, + b.quantity * IF(vHasNotInventory, 1, -1), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = tr.warehouseOutFk + WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd + AND NOT e.isRaid + AND w.valuatedInventory + AND t.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory,1,-1)); + + -- Descontamos las lineas de venta + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT w.id, + s.itemFk, + s.quantity * IF(vHasNotInventory, 1, -1), + w.name + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN `client` c ON c.id = t.clientFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd + AND w.valuatedInventory + AND it.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 1, -1); + + -- Volver a poner lo que esta aun en las estanterias + IF vDated = util.VN_CURDATE() THEN + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT w.id, + s.itemFk, + s.quantity * IF(vHasNotInventory, 0, 1), + w.name + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN `client` c ON c.id = t.clientFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDated AND vDateDayEnd + AND NOT (s.isPicked OR t.isLabeled) + AND w.valuatedInventory + AND it.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 0, 1); + END IF; + + -- Mercancia en transito + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + b.quantity, + CONCAT(wOut.`name`, ' - ', wIn.`name`) + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + WHERE vDated >= tr.shipped AND vDated < tr.landed + AND NOT isRaid + AND wIn.valuatedInventory + AND t.isInventory + AND e.isConfirmed + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity); + + CALL vn.buyUltimate(NULL, vDateDayEnd); + + UPDATE tInventory i + JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk + JOIN buy b ON b.id = bu.buyFk + SET total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)), + cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0) + WHERE i.quantity; + + DELETE FROM tInventory + WHERE quantity IS NULL OR NOT quantity; + + IF vIsDetailed THEN + SELECT ti.warehouseFk, + i.id itemFk, + i.longName, + i.size, + ti.quantity, + tp.name Tipo, + ic.name Reino, + ti.cost, + CAST(ti.total AS DECIMAL(10, 2)) total, + ti.warehouseInventory almacen + FROM tInventory ti + JOIN warehouse w ON w.id = warehouseFk + JOIN item i ON i.id = ti.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + WHERE w.valuatedInventory + AND ti.total > 0 + ORDER BY ti.total DESC; + ELSE + SELECT i.warehouseInventory Almacen, + ic.name Reino, + CAST(i.total AS DECIMAL(10, 2)) Euros, + w.code Comprador, + it.id + FROM tInventory i + JOIN warehouse wh ON wh.id = warehouseFk + JOIN item it ON it.id = i.itemFk + JOIN itemType itp ON itp.id = it.typeFk + LEFT JOIN worker w ON w.id = itp.workerFk + JOIN itemCategory ic ON ic.id = itp.categoryFk + WHERE wh.valuatedInventory + AND i.total > 0; + END IF; + + DROP TEMPORARY TABLE + tmp.buyUltimate, + tInventory; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_cleanFloramondo.sql b/db/routines/vn/procedures/item_cleanFloramondo.sql new file mode 100644 index 000000000..cae06ee54 --- /dev/null +++ b/db/routines/vn/procedures/item_cleanFloramondo.sql @@ -0,0 +1,203 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_cleanFloramondo`() +BEGIN +/** +* Elimina todos los items repetidos de floramondo +* y los sustituye por el que tiene menor id +*/ + DECLARE vItemFrom INT; + DECLARE vItemEnd INT; + DECLARE vItemOld INT; + DECLARE vItemNew INT; + DECLARE vCurrentItem INT; + DECLARE vQuantity INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vIsStop BOOL DEFAULT FALSE; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE curItemClean CURSOR FOR + SELECT GREATEST(i.id, i2.id) idOld, + LEAST(i.id, i2.id) idNew + FROM item i + JOIN ( + SELECT i.id, + i.name, + i.subname, + i.value5, + i.value6, + i.value7, + i.value8, + i.value9, + i.value10, + i.NumberOfItemsPerCask, + i.EmbalageCode, + i.quality + FROM item i + LEFT JOIN ( + SELECT i.id, + sr.NumberOfUnits, + MAX(di.LatestOrderDateTime) lodt + FROM item i + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.deliveryInformation di ON di.supplyResponseID = i.supplyResponseFk + GROUP BY i.id + )sub ON sub.id = i.id + WHERE i.isFloramondo + AND (i.supplyResponseFk IS NULL + OR sub.NumberOfUnits = 0 + OR sub.lodt < util.VN_NOW()) + GROUP BY i.name, + i.subname, + i.value5, + i.value6, + i.value7, + i.value8, + i.value9, + i.value10, + i.NumberOfItemsPerCask, + i.EmbalageCode, + i.quality + ) i2 ON i2.name <=> i.name + AND i2.subname <=> i.subname + AND i2.value5 <=> i.value5 + AND i2.value6 <=> i.value6 + AND i2.value7 <=> i.value7 + AND i2.value8 <=> i.value8 + AND i2.value9 <=> i.value9 + AND i2.value10 <=> i.value10 + AND i2.NumberOfItemsPerCask <=> i.NumberOfItemsPerCask + AND i2.EmbalageCode <=> i.EmbalageCode + AND i2.quality <=> i.quality + JOIN ( + SELECT DISTINCT b.itemFk + FROM buy b + JOIN item i ON i.id = b.itemFk + WHERE i.isFloramondo + AND NOT b.printedStickers + )sub2 ON sub2.itemFk = GREATEST(i.id, i2.id) + WHERE i.isFloramondo + AND i.id <> i2.id; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION SET vDone = TRUE; + BEGIN + SET vDone = TRUE; + ROLLBACK; + RESIGNAL; + END; + + SET @isModeInventory:= TRUE; + + OPEN curItemClean; + curItemClean: LOOP + + FETCH curItemClean INTO vItemOld, vItemNew; + + START TRANSACTION; + + # Deletes + UPDATE IGNORE itemCost + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + DELETE FROM itemCost + WHERE itemFk = vItemOld; + + DELETE FROM vn2008.rec_translator + WHERE Id_Article = vItemOld; + + DELETE FROM bs.waste + WHERE itemFk = vItemOld; + + DELETE FROM priceFixed + WHERE itemFk = vItemOld; + + DELETE FROM itemMatchProperties + WHERE itemFk = vItemOld; + + DELETE FROM itemBotanical + WHERE itemFk = vItemOld; + + DELETE FROM itemProposal + WHERE itemFk = vItemOld; + + SET @isTriggerDisabled := TRUE; + DELETE FROM itemTag + WHERE itemFk = vItemOld; + SET @isTriggerDisabled := FALSE; + + DELETE FROM itemBarcode + WHERE itemFk = vItemOld; + + DELETE FROM itemTaxCountry + WHERE itemFk = vItemOld; + + # Updates + UPDATE buy + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE sale + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE specialPrice + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE packaging + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE packaging + SET freightItemFk = vItemNew + WHERE freightItemFk = vItemOld; + + UPDATE hedera.orderRow + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE itemLog + SET originFk = vItemNew + WHERE originFk = vItemOld; + + UPDATE itemShelving + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE ticketPackagingStartingStock + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE inventoryFailure + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE genericAllocation + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + UPDATE itemPlacementSupply + SET itemFk = vItemNew + WHERE itemFk = vItemOld; + + # Mantenemos la imagen si el nuevo no tiene + UPDATE vn.item itemNew + LEFT JOIN item itemOld ON itemOld.id = vItemOld + AND itemOld.image IS NOT NULL + SET itemNew.image = itemOld.image + WHERE itemNew.id = vItemNew + AND itemNew.image IS NULL; + + # Eliminamos el item sustituido + DELETE FROM item + WHERE id = vItemOld; + + COMMIT; + + SET vCounter = vCounter + 1; + + END LOOP; + CLOSE curItemClean; + + SET @isModeInventory:= FALSE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_comparative.sql b/db/routines/vn/procedures/item_comparative.sql new file mode 100644 index 000000000..e72188363 --- /dev/null +++ b/db/routines/vn/procedures/item_comparative.sql @@ -0,0 +1,297 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_comparative`( + vDate DATETIME, + vDayRange TINYINT, + vWarehouseFk TINYINT, + vAvailableSince DATE, + vBuyerFk INT, + vIsFloramondo BOOL, + vCountryFk INT +) +proc: BEGIN +/** + * Genera una tabla de comparativa de artículos por itemType/comprador/fecha. + * Los datos se calculan en función de los parámetros proporcionados. + * + * @param vDate La fecha para la cual se generará la comparativa. + * @param vDayRange El rango de días a considerar para la comparativa. + * @param vWarehouseFk El identificador del almacén para filtrar los artículos. + * @param vAvailableSince La fecha de disponibilidad desde la cual se consideran los artículos disponibles. + * @param vBuyerFk El identificador del comprador para filtrar los artículos. + * @param vIsFloramondo Indica si se deben incluir solo los artículos de Floramondo (opcional). + * @param vCountryFk El identificador del país. + * @param tmp.comparativeFilterType(filterFk INT ,itemTypeFk INT) + * @return tmp.comparative + */ + + DECLARE vDayRangeStart DATE; + DECLARE vDayRangeEnd DATE; + DECLARE w1, w2, w3, w4, w5, w6, w7 INT; + DECLARE y1, y2, y3, y4, y5, y6, y7 INT; + DECLARE z1, z2, z3, z4, z5, z6, z7 INT; + DECLARE vPeriod INT; + DECLARE i INT DEFAULT 0; + DECLARE vHasTypeFilter BOOL; + DECLARE vWeekRange INT; + DECLARE vWeekCount TINYINT; + DECLARE vMaxDayRange INT; + DECLARE vMinDayRange INT; + DECLARE vDefaultDayRange INT; + + IF NOT(SELECT COUNT(*) FROM comparativeConfig)THEN + LEAVE proc; + END IF; + + SELECT weekRange, + weekRange * 2 + 1, + maxDayRange, + minDayRange, + defaultDayRange + INTO vWeekRange, + vWeekCount, + vMaxDayRange, + vMinDayRange, + vDefaultDayRange + FROM comparativeConfig; + + IF vDayRange < vMinDayRange OR vDayRange > vMaxDayRange THEN + SET vDayRange = vDefaultDayRange; + END IF; + + SELECT MIN(dated) INTO vDayRangeStart + FROM vn.time + WHERE dated <= vDate + GROUP BY period + ORDER BY dated desc + LIMIT 1 OFFSET vWeekRange; + + SELECT MAX(dated) INTO vDayRangeEnd + FROM vn.time + WHERE dated >= vDate + GROUP BY period + ORDER BY dated ASC + LIMIT 1 OFFSET vWeekRange; + + SELECT COUNT(itemTypeFk) > 0 INTO vHasTypeFilter + FROM tmp.comparativeFilterType; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemInventory + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT i.id + FROM item i + JOIN itemType t ON t.id = i.typeFk + JOIN itemCategory c ON c.id = t.categoryFk + LEFT JOIN worker w ON w.id = t.workerFk + WHERE (NOT vHasTypeFilter + OR t.id IN (SELECT itemTypeFk FROM tmp.comparativeFilterType)) + AND (vBuyerFk IS NULL + OR t.workerFk = vBuyerFk) + AND (vIsFloramondo IS NULL + OR i.isFloramondo = vIsFloramondo); + + IF vDate < util.VN_CURDATE() THEN + ALTER TABLE tmp.itemInventory + ADD `buy_id` INT NOT NULL DEFAULT 0, + ADD `buy_date` DATE DEFAULT '2000-01-01', + ADD `life` INT DEFAULT 0, + ADD `sd` INT DEFAULT 0, + ADD `avalaible` INT DEFAULT 0, + ADD `visible` INT DEFAULT 0; + ELSE + CALL multipleInventory(vAvailableSince, vWarehouseFk, vDayRange); + CALL item_multipleBuy(vDate, vWarehouseFk); + CALL item_multipleBuyByDate(vDate, vWarehouseFk); + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tTable ( + cy INT(6) PRIMARY KEY, + ly INT(6), + zy INT(6), + INDEX (ly) + ); + + REPEAT + SET i = i + 1; + + SELECT t.period INTO vPeriod + FROM vn.`time` t + WHERE t.dated = vDayRangeStart + INTERVAL (vWeekCount * (i - 1)) DAY; + + INSERT IGNORE INTO tTable(cy, ly, zy) VALUES(vPeriod, vPeriod - 100, vPeriod - 200); + UNTIL i = vWeekCount END REPEAT; + + SELECT cy, ly, zy INTO w1, y1, z1 FROM tTable LIMIT 1; + SELECT cy, ly, zy INTO w2, y2, z2 FROM tTable WHERE cy > w1 LIMIT 1; + SELECT cy, ly, zy INTO w3, y3, z3 FROM tTable WHERE cy > w2 LIMIT 1; + SELECT cy, ly, zy INTO w4, y4, z4 FROM tTable WHERE cy > w3 LIMIT 1; + SELECT cy, ly, zy INTO w5, y5, z5 FROM tTable WHERE cy > w4 LIMIT 1; + SELECT cy, ly, zy INTO w6, y6, z6 FROM tTable WHERE cy > w5 LIMIT 1; + SELECT cy, ly, zy INTO w7, y7, z7 FROM tTable WHERE cy > w6 LIMIT 1; + + -- Genera una tabla con los datos del año pasado. + + CREATE OR REPLACE TEMPORARY TABLE tLastYear + (KEY (lItemFk)) + ENGINE = MEMORY + SELECT c.itemFk lItemFk, + SUM(IF(c.timePeriod = y1, c.quantity, 0)) lweek1, + SUM(IF(c.timePeriod = y2, c.quantity, 0)) lweek2, + SUM(IF(c.timePeriod = y3, c.quantity, 0)) lweek3, + SUM(IF(c.timePeriod = y4, c.quantity, 0)) lweek4, + SUM(IF(c.timePeriod = y5, c.quantity, 0)) lweek5, + SUM(IF(c.timePeriod = y6, c.quantity, 0)) lweek6, + SUM(IF(c.timePeriod = y7, c.quantity, 0)) lweek7, + SUM(IF(c.timePeriod = y1, c.price, 0)) lprice1, + SUM(IF(c.timePeriod = y2, c.price, 0)) lprice2, + SUM(IF(c.timePeriod = y3, c.price, 0)) lprice3, + SUM(IF(c.timePeriod = y4, c.price, 0)) lprice4, + SUM(IF(c.timePeriod = y5, c.price, 0)) lprice5, + SUM(IF(c.timePeriod = y6, c.price, 0)) lprice6, + SUM(IF(c.timePeriod = y7, c.price, 0)) lprice7 + FROM tmp.itemInventory ai + JOIN comparative c ON c.itemFk = ai.id + JOIN warehouse w on w.id = c.warehouseFk + JOIN tTable wt ON c.timePeriod = wt.ly + WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk + AND w.isComparative + AND (vCountryFk IS NULL OR c.countryFk = vCountryFk) + GROUP BY ai.id; + + -- Genera una tabla con los datos de hace DOS años. + + CREATE OR REPLACE TEMPORARY TABLE tTwoYearsAgo + (KEY (tItemFk)) + ENGINE = MEMORY + SELECT c.itemFk tItemFk, + SUM(IF(c.timePeriod = z1, c.quantity, 0)) vlweek1, + SUM(IF(c.timePeriod = z2, c.quantity, 0)) vlweek2, + SUM(IF(c.timePeriod = z3, c.quantity, 0)) vlweek3, + SUM(IF(c.timePeriod = z4, c.quantity, 0)) vlweek4, + SUM(IF(c.timePeriod = z5, c.quantity, 0)) vlweek5, + SUM(IF(c.timePeriod = z6, c.quantity, 0)) vlweek6, + SUM(IF(c.timePeriod = z7, c.quantity, 0)) vlweek7, + SUM(IF(c.timePeriod = z1, c.price, 0)) vlprice1, + SUM(IF(c.timePeriod = z2, c.price, 0)) vlprice2, + SUM(IF(c.timePeriod = z3, c.price, 0)) vlprice3, + SUM(IF(c.timePeriod = z4, c.price, 0)) vlprice4, + SUM(IF(c.timePeriod = z5, c.price, 0)) vlprice5, + SUM(IF(c.timePeriod = z6, c.price, 0)) vlprice6, + SUM(IF(c.timePeriod = z7, c.price, 0)) vlprice7 + FROM tmp.itemInventory ai + JOIN comparative c ON c.itemFk = ai.id + JOIN warehouse w on w.id = c.warehouseFk + JOIN tTable wt ON c.timePeriod = wt.zy + WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk + AND w.isComparative + AND (vCountryFk IS NULL OR c.countryFk = vCountryFk) + GROUP BY ai.id; + + -- Genera una tabla con los datos de este año.ss + + CREATE OR REPLACE TEMPORARY TABLE tCurrentYear + (KEY (cItemFk)) + ENGINE = MEMORY + SELECT t.itemFk cItemFk, + SUM(IF(week = w1, total, 0)) cweek1, + SUM(IF(week = w2, total, 0)) cweek2, + SUM(IF(week = w3, total, 0)) cweek3, + SUM(IF(week = w4, total, 0)) cweek4, + SUM(IF(week = w5, total, 0)) cweek5, + SUM(IF(week = w6, total, 0)) cweek6, + SUM(IF(week = w7, total, 0)) cweek7, + SUM(IF(week = w1, price, 0)) cprice1, + SUM(IF(week = w2, price, 0)) cprice2, + SUM(IF(week = w3, price, 0)) cprice3, + SUM(IF(week = w4, price, 0)) cprice4, + SUM(IF(week = w5, price, 0)) cprice5, + SUM(IF(week = w6, price, 0)) cprice6, + SUM(IF(week = w7, price, 0)) cprice7 + FROM ( + SELECT s.itemFk, + ti.period `week`, + SUM(s.quantity) total, + TRUNCATE(SUM(s.quantity * s.priceFixed),0) price + FROM ticket t + JOIN sale s ON t.id = s.ticketFk + JOIN tmp.itemInventory it ON it.id = s.itemFk + JOIN time ti ON ti.dated = DATE(t.shipped) + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN warehouse w ON w.id = t.warehouseFk + STRAIGHT_JOIN address ad ON ad.id = t.addressFk + JOIN province p ON p.id = ad.provinceFk + JOIN `client` c ON c.id = ad.clientFk + WHERE t.shipped BETWEEN vDayRangeStart AND util.dayEnd(vDayRangeEnd) + AND c.typeFk IN ('Normal','handMaking') + AND w.id = COALESCE(vWarehouseFk, w.id) + AND w.isComparative + AND (vCountryFk IS NULL OR p.countryFk = vCountryFk) + GROUP BY i.id, week + ) t + GROUP BY t.itemFk; + + -- Genera la tabla con la comparativa. + CREATE OR REPLACE TEMPORARY TABLE tmp.comparative + ENGINE = MEMORY + SELECT it.subName productor, + b.packing, + b.buyingValue costefijo, + b.groupingMode caja, + it.image ArticleImage, + IFNULL(it.inkFk,"?") color, + tp.code tipo, + it.typeFk tipo_id, + o.code origen, + it.category categoria, + it.stems tallos, + it.size medida, + it.name article, + w.code codigoTrabajador, + tp.categoryFk reino_id, + ly.*, + cy.*, + zy.*, + it.*, + it.id Id_Article, + i.buy_id, + tp.life, + IFNULL(i.sd,0) sd, + i.avalaible, + i.visible, + i.buy_date, + e.id provider_id, + it.comment comments, + it.description itemDescription, + IF(cy.cItemFk IS NULL AND i.visible = 0 AND i.avalaible = 0 + AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) filtret, + IF(it.hasMinPrice, FORMAT(it.minPrice, 2), "") pvp, + s.company_name + FROM tmp.itemInventory i + JOIN item it ON it.id = i.id + LEFT JOIN itemType tp ON tp.id = it.typeFk + LEFT JOIN worker w ON w.id = tp.workerFk + LEFT JOIN buy b ON b.id = i.buy_id + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN origin o ON o.id = it.originFk + LEFT JOIN tLastYear ly ON ly.lItemFk = it.id + LEFT JOIN tCurrentYear cy ON cy.cItemFk = it.id + LEFT JOIN tTwoYearsAgo zy ON zy.tItemFk = it.id + LEFT JOIN edi.ekt e2 ON e2.id = b.ektFk + LEFT JOIN edi.supplier s ON s.supplier_id = e2.pro + WHERE i.avalaible + OR i.visible + OR i.sd + OR cy.cweek1 OR cy.cweek2 OR cy.cweek3 OR cy.cweek4 OR cy.cweek5 OR cy.cweek6 OR cy.cweek7 + OR ly.lweek1 OR ly.lweek2 OR ly.lweek3 OR ly.lweek4 OR ly.lweek5 OR ly.lweek6 OR ly.lweek7 + OR zy.vlweek1 OR zy.vlweek2 OR zy.vlweek3 OR zy.vlweek4 OR zy.vlweek5 OR zy.vlweek6 OR zy.vlweek7; + + -- Elimina las tablas temporales creadas... + DROP TEMPORARY TABLE IF EXISTS tmp.itemInventory, + tTwoYearsAgo, + tLastYear, + tCurrentYear, + tTable; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_deactivateUnused.sql b/db/routines/vn/procedures/item_deactivateUnused.sql new file mode 100644 index 000000000..68a6b4978 --- /dev/null +++ b/db/routines/vn/procedures/item_deactivateUnused.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_deactivateUnused`() +BEGIN +/** + * Cambia a false el campo isActive de la tabla vn.item para todos aquellos + * items que no se han comprado en los últimos meses configurados en + * @vn.itemConfig.monthToDeactivate + */ + DECLARE vMonthToDeactivate INT; + + SELECT monthToDeactivate INTO vMonthToDeactivate + FROM vn.itemConfig; + + DROP TEMPORARY TABLE IF EXISTS tmp.buyMaxCreated; + CREATE TEMPORARY TABLE tmp.buyMaxCreated + ENGINE = MEMORY + SELECT b.itemFk, + MAX(b.created) created + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + WHERE i.isActive + GROUP BY itemFk; + + UPDATE vn.item i + JOIN tmp.buyMaxCreated bmc ON bmc.itemFk = i.id + SET i.isActive = FALSE + WHERE bmc.created < util.VN_CURDATE() - INTERVAL vMonthToDeactivate MONTH; + + DROP TEMPORARY TABLE IF EXISTS tmp.buyMaxCreated; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getAtp.sql b/db/routines/vn/procedures/item_getAtp.sql new file mode 100644 index 000000000..bbf13d396 --- /dev/null +++ b/db/routines/vn/procedures/item_getAtp.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getAtp`(vDated DATE) +BEGIN +/** + * Calcula el valor mínimo acumulado para cada artículo ordenado por fecha y + * almacén. + * + * @param vDated Si no hay movimientos en la fecha indicada, debe devolver 0 + * @table tmp.itemCalc(itemFk, wareHouseFk, dated, quantity) + * @return tmp.itemAtp(itemFk, warehouseFk, quantity) + */ + CREATE OR REPLACE TEMPORARY TABLE tItemOrdered + (UNIQUE(itemFk, warehouseFk, dated)) + ENGINE = MEMORY + SELECT itemFk, warehouseFk, dated, SUM(quantity) quantity + FROM ( + SELECT itemFk, warehouseFk, dated, quantity + FROM tmp.itemCalc + UNION ALL + SELECT itemFk, warehouseFk, vDated, 0 + FROM (SELECT DISTINCT itemFk, warehouseFk FROM tmp.itemCalc) t2 + ) t1 + GROUP BY itemFk, warehouseFk, dated + ORDER BY itemFk, warehouseFk, dated; + + SET @lastItemFk := 0; + SET @lastWareHouseFk := 0; + SET @lastQuantity := 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemAtp + (INDEX (itemFk, wareHouseFk)) + SELECT itemFk, wareHouseFk, MIN(quantityAccumulated) quantity + FROM ( + SELECT + itemFk, + IF(itemFk <> @lastItemFk OR wareHouseFk <> @lastWareHouseFk, + @lastQuantity := quantity, + @lastQuantity := @lastQuantity + quantity) quantityAccumulated, + wareHouseFk, + @lastItemFk := itemFk, + @lastWareHouseFk := wareHouseFk + FROM tItemOrdered + )sub + GROUP BY itemFk, wareHouseFk; + + DROP TEMPORARY TABLE tItemOrdered; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql new file mode 100644 index 000000000..5fe57f2a4 --- /dev/null +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -0,0 +1,224 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`( + vItemFk INT, + vWarehouseFk INT, + vDate DATETIME +) +BEGIN +/** + * @vItemFk item a buscar + * @vWarehouseFk almacen donde buscar + * @vDate Si la fecha es null, muestra el histórico desde el inventario. + * Si la fecha no es null, muestra histórico desde la fecha pasada. + */ + DECLARE vDateInventory DATETIME; + + IF vDate IS NULL THEN + SELECT inventoried INTO vDateInventory + FROM config; + ELSE + SELECT mockUtcTime INTO vDateInventory + FROM util.config; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tItemDiary( + shipped DATE, + `in` INT(11), + `out` INT(11), + alertLevel INT(11), + stateName VARCHAR(20), + `name` VARCHAR(50), + reference VARCHAR(50), + origin INT(11), + clientFk INT(11), + isPicked INT(11), + isTicket TINYINT(1), + lineFk INT(11), + `order` TINYINT(3) UNSIGNED, + clientType VARCHAR(20), + claimFk INT(10) UNSIGNED, + inventorySupplierFk INT(10) + ); + + INSERT INTO tItemDiary + SELECT tr.landed shipped, + b.quantity `in`, + NULL `out`, + st.alertLevel , + st.name stateName, + s.name `name`, + e.invoiceNumber reference, + e.id origin, + s.id clientFk, + IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, + FALSE isTicket, + b.id lineFk, + NULL `order`, + NULL clientType, + NULL claimFk, + ec.inventorySupplierFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN supplier s ON s.id = e.supplierFk + JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() + OR (util.VN_CURDATE() AND tr.isReceived), + 'DELIVERED', + 'FREE') + JOIN entryConfig ec + WHERE tr.landed >= vDateInventory + AND vWarehouseFk = tr.warehouseInFk + AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND b.itemFk = vItemFk + AND e.isExcludedFromAvailable = FALSE + AND e.isRaid = FALSE + UNION ALL + SELECT tr.shipped, + NULL, + b.quantity, + st.alertLevel, + st.name, + s.name, + e.invoiceNumber, + e.id, + s.id, + IF(st.`code` = 'DELIVERED' , TRUE, FALSE), + FALSE, + b.id, + NULL, + NULL, + NULL, + ec.inventorySupplierFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN warehouse w ON w.id = tr.warehouseOutFk + JOIN supplier s ON s.id = e.supplierFk + JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() + OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), + 'DELIVERED', + 'FREE') + JOIN entryConfig ec + WHERE tr.shipped >= vDateInventory + AND vWarehouseFk = tr.warehouseOutFk + AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND b.itemFk = vItemFk + AND e.isExcludedFromAvailable = FALSE + AND w.isFeedStock = FALSE + AND e.isRaid = FALSE + UNION ALL + SELECT DATE(t.shipped), + NULL, + s.quantity, + st2.alertLevel, + st2.name, + t.nickname, + t.refFk, + t.id, + t.clientFk, + stk.id, + TRUE, + s.id, + st.`order`, + ct.`code`, + cb.claimFk, + NULL + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN ticketState ts ON ts.ticketFk = t.id + LEFT JOIN state st ON st.`code` = ts.`code` + JOIN client c ON c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), + 'DELIVERED', + IF (t.shipped > util.dayEnd(util.VN_CURDATE()), + 'FREE', + IFNULL(ts.code, 'FREE'))) + LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' + LEFT JOIN saleTracking stk ON stk.saleFk = s.id + AND stk.stateFk = stPrep.id + LEFT JOIN claimBeginning cb ON s.id = cb.saleFk + WHERE t.shipped >= vDateInventory + AND s.itemFk = vItemFk + AND vWarehouseFk =t.warehouseFk + ORDER BY shipped, + (inventorySupplierFk = clientFk) DESC, + alertLevel DESC, + isTicket, + `order` DESC, + isPicked DESC, + `in` DESC, + `out` DESC; + + IF vDate IS NULL THEN + + SET @a := 0; + SET @currentLineFk := 0; + SET @shipped := ''; + + SELECT DATE(@shipped:= shipped) shipped, + alertLevel, + stateName, + origin, + reference, + clientFk, + name, + `in` invalue, + `out`, + @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0) balance, + @currentLineFk := IF (@shipped < util.VN_CURDATE() + OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')), + lineFk, + @currentLineFk) lastPreparedLineFk, + isTicket, + lineFk, + isPicked, + clientType, + claimFk + FROM tItemDiary + LEFT JOIN alertLevel a ON a.id = tItemDiary.alertLevel; + + ELSE + SELECT SUM(`in`) - SUM(`out`) INTO @a + FROM tItemDiary + WHERE shipped < vDate; + + SELECT vDate shipped, + 0 alertLevel, + 0 stateName, + 0 origin, + '' reference, + 0 clientFk, + 'Inventario calculado', + @a invalue, + NULL `out`, + @a balance, + 0 lastPreparedLineFk, + 0 isTicket, + 0 lineFk, + 0 isPicked, + 0 clientType, + 0 claimFk + UNION ALL + SELECT shipped, + alertlevel, + stateName, + origin, + reference, + clientFk, + name, `in`, + `out`, + @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), + 0, + isTicket, + lineFk, + isPicked, + clientType, + claimFk + FROM tItemDiary + WHERE shipped >= vDate; + END IF; + + DROP TEMPORARY TABLE tItemDiary; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getInfo.sql b/db/routines/vn/procedures/item_getInfo.sql new file mode 100644 index 000000000..50ab880a0 --- /dev/null +++ b/db/routines/vn/procedures/item_getInfo.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getInfo`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT) +BEGIN +/** + * Devuelve información relativa al item correspondiente del vBarcode pasado + * + * @param vBarcode código relativo al ítem + * @param vWarehouseFk código del almacén + */ + DECLARE vCacheVisibleFk INT; + DECLARE vCacheAvailableFk INT; + DECLARE vVisibleItemShelving INT; + DECLARE vItemFk INT; + + CALL cache.visible_refresh(vCacheVisibleFk, FALSE, vWarehouseFk); + CALL cache.available_refresh(vCacheAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); + + SELECT barcodeToItem(vBarcode) INTO vItemFk; + SELECT SUM(visible) INTO vVisibleItemShelving + FROM itemShelvingStock + WHERE itemFk = vItemFk + AND warehouseFk = vWarehouseFk; + + SELECT i.id, + i.longName, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7, + i.image, + i.`size`, + i.stems, + i.category, + i.minimum `min`, + p.name producer, + o.code origin, + v.visible - IFNULL(vVisibleItemShelving, 0) unlocated, + a.available, + vVisibleItemShelving, + v.visible, + b.`grouping`, + b.packing, + CONCAT('http:', ic.url, '/catalog/200x200/', i.image) urlImage200, + CONCAT('http:', ic.url, '/catalog/1600x900/', i.image) urlImage, + i.itemPackingTypeFk, + i.comment reference, + u.name buyer, + IFNULL(b.buyingValue, 0) + + IFNULL(b.freightValue, 0) + + IFNULL(b.comissionValue, 0) + + IFNULL(b.packageValue, 0) itemCost + FROM item i + LEFT JOIN producer p ON p.id = i.producerFk + LEFT JOIN origin o ON o.id = i.originFk + 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 tmp.buyUltimate bu ON bu.itemFk = i.id + LEFT JOIN buy b ON b.id = bu.buyFk + AND bu.warehouseFk = vWarehouseFk + JOIN itemType it ON it.id = i.typeFk + JOIN account.user u ON u.id = it.workerFk + JOIN hedera.imageConfig ic + WHERE i.id = vItemFk; + + DROP TEMPORARY TABLE tmp.buyUltimate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getLack.sql b/db/routines/vn/procedures/item_getLack.sql new file mode 100644 index 000000000..b2e3e425c --- /dev/null +++ b/db/routines/vn/procedures/item_getLack.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getLack`(IN vForce BOOLEAN, IN vDays INT) +BEGIN +/** + * Calcula una tabla con el máximo negativo visible para cada producto y almacen + * + * @param vForce Fuerza el recalculo del stock + * @param vDays Numero de dias a considerar +**/ + + CALL `cache`.stock_refresh(vForce); + CALL item_getMinacum(NULL, util.VN_CURDATE(), vDays, NULL); + CALL item_getMinETD(); + CALL item_zoneClosure(); + + SELECT i.id itemFk, + i.longName, + w.id warehouseFk, + p.`name` producer, + i.`size`, + i.category, + w.name warehouse, + SUM(IFNULL(sub.amount,0)) lack, + i.inkFk, + IFNULL(im.timed, util.midnight()) timed, + IFNULL(izc.timed, util.midnight()) minTimed + FROM (SELECT item_id, + warehouse_id, + amount + FROM cache.stock + WHERE amount > 0 + UNION ALL + SELECT itemFk, + warehouseFk, + amount + FROM tmp.itemMinacum + ) sub + JOIN warehouse w ON w.id = sub.warehouse_id + JOIN item i ON i.id = sub.item_id + LEFT JOIN producer p ON p.id = i.producerFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id + LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id + WHERE w.isForTicket + AND ic.display + AND it.code != 'GEN' + GROUP BY i.id, w.id + HAVING lack < 0; + + DROP TEMPORARY TABLE tmp.itemMinacum; + DROP TEMPORARY TABLE tmp.itemMinETD; + DROP TEMPORARY TABLE tmp.itemZoneClosure; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getMinETD.sql b/db/routines/vn/procedures/item_getMinETD.sql new file mode 100644 index 000000000..3876587fe --- /dev/null +++ b/db/routines/vn/procedures/item_getMinETD.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinETD`() +BEGIN + +/* Devuelve una tabla temporal con la primera ETD, para todos los artículos con salida hoy. + * + * @return tmp.itemMinETD(itemFk, timed) + */ + + DECLARE vMidnight DATETIME DEFAULT util.midnight(); + + DROP TEMPORARY TABLE IF EXISTS tmp.itemMinETD; + + CREATE TEMPORARY TABLE tmp.itemMinETD + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT s.itemFk, MIN(TIME(IFNULL(z.`hour`,vMidnight))) timed + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN `zone` z ON z.id = t.zoneFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND vMidnight + GROUP BY s.itemFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql new file mode 100644 index 000000000..ed987637c --- /dev/null +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinacum`(IN vWarehouseFk TINYINT, IN vDatedFrom DATETIME, IN vRange INT, IN vItemFk INT) +BEGIN +/** + * Cálculo del mínimo acumulado, para un item/almacén especificado, en caso de + * NULL para todo. + * + * @param vWarehouseFk -> warehouseFk + * @param vDatedFrom -> fecha inicio + * @param vRange -> número de días a considerar + * @param vItemFk -> Identificador de item + * @return tmp.itemMinacum +*/ + DECLARE vDatedTo DATETIME; + + SET vDatedFrom = TIMESTAMP(DATE(vDatedFrom), '00:00:00'); + SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, vRange, vDatedFrom), '23:59:59'); + + DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc; + CREATE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk, warehouseFk)) + SELECT sub.itemFk, + sub.dated, + CAST(SUM(sub.quantity) AS SIGNED) quantity, + sub.warehouseFk + FROM (SELECT s.itemFk, + DATE(t.shipped) dated, + -s.quantity quantity, + t.warehouseFk + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + AND s.quantity != 0 + AND (vItemFk IS NULL OR s.itemFk = vItemFk) + AND (vWarehouseFk IS NULL OR t.warehouseFk = vWarehouseFk) + UNION ALL + SELECT b.itemFk, + t.landed, + b.quantity, + t.warehouseInFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + LEFT JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vDatedFrom AND vDatedTo + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND !e.isExcludedFromAvailable + AND b.quantity != 0 + AND (vItemFk IS NULL OR b.itemFk = vItemFk) + UNION ALL + SELECT b.itemFk, + t.shipped, + -b.quantity, + t.warehouseOutFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + LEFT JOIN travel t ON t.id = e.travelFk + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk) + AND !e.isExcludedFromAvailable + AND b.quantity != 0 + AND (vItemFk IS NULL OR b.itemFk = vItemFk) + AND !e.isRaid + ) sub + GROUP BY sub.itemFk, sub.warehouseFk, sub.dated; + + CALL item_getAtp(vDatedFrom); + DROP TEMPORARY TABLE tmp.itemCalc; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; + CREATE TEMPORARY TABLE tmp.itemMinacum + (INDEX(itemFk)) + ENGINE = MEMORY + SELECT i.itemFk, + i.warehouseFk, + i.quantity amount + FROM tmp.itemAtp i + HAVING amount != 0; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql new file mode 100644 index 000000000..7cc9ad63e --- /dev/null +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -0,0 +1,84 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getSimilar`(vItemFk INT, vWarehouseFk INT, vDate DATE, vIsShowedByType BOOL) +BEGIN + +/** + * Propone articulos similares para posible cambio, + * ordenado con la cantidad de veces usado y segun sus caracteristicas + * + * @param vItemFk item id + * @param vWarehouseFk warehouse id + * @param vDate fecha para revisar disponible + * @param vIsShowedByType para mostrar solo artículos de ese tipo + */ + + DECLARE vCalcFk INT; + DECLARE vTypeFk INT; + + DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vTag6 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vTag7 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vTag8 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + + DECLARE vValue1 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vValue5 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vValue6 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; + + + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value + INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 + FROM vn.item i + LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 + LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + WHERE i.id = vItemFk; + + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDate); + + SELECT i.id itemFk, + i.longName, + i.subName, + i.tag5, + i.value5, + (i.value5 <=> vValue5) match5, + i.tag6, + i.value6, + (i.value6 <=> vValue6) match6, + i.tag7, + i.value7, + (i.value7 <=> vValue7) match7, + i.tag8, + i.value8, + (i.value8 <=> vValue8) match8, + a.available, + IFNULL(ip.counter,0) counter, + IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity + FROM vn.item i + JOIN cache.available a ON a.item_id = i.id + LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk + LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 + LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + WHERE a.calc_id = vCalcFk + AND available > 0 + AND IF(vIsShowedByType, i.typeFk = vTypeFk, TRUE) + AND i.id != vItemFk + ORDER BY counter DESC, + (t1.name = vTag1) DESC, + (it1.value = vValue1) DESC, + (i.tag6 = vTag6) DESC, + (i.value6 = vValue6) DESC, + (i.tag5 = vTag5) DESC, + (i.value5 = vValue5) DESC, + (i.tag7 = vTag7) DESC, + (i.value7 = vValue7) DESC, + (i.tag8 = vTag8) DESC, + (i.value8 = vValue8) DESC + LIMIT 30; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_getStock.sql b/db/routines/vn/procedures/item_getStock.sql new file mode 100644 index 000000000..c7df75ef2 --- /dev/null +++ b/db/routines/vn/procedures/item_getStock.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getStock`( + vWarehouseFk SMALLINT, + vDated DATE, + vItemFk INT +) +BEGIN +/** + * Calcula el stock de un artículo de un vWarehouseFk, + * desde la fecha del inventario hasta vDated + * + * @param vWarehouse Warehouse id + * @param vDated Max date to filter + * @param vItemFk Item id + * + * @return tmp.itemList(itemFk, stock, visible, available) + */ + DECLARE vIsLogifloraDay BOOL DEFAULT vn.isLogifloraDay(vDated, vWarehouseFk); + + SET vDated = TIMESTAMP(vDated, '00:00:00'); + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemList + (UNIQUE INDEX i USING HASH (itemFk)) + ENGINE = MEMORY + SELECT itemFk, + SUM(quantity) stock, + SUM(quantity) visible, + SUM(quantity) available + FROM ( + SELECT itemFk, quantity + FROM itemTicketOut + WHERE shipped >= util.VN_CURDATE() + AND shipped < vDated + AND warehouseFk = vWarehouseFk + AND (vItemFk IS NULL OR itemFk = vItemFk) + UNION ALL + SELECT iei.itemFk, iei.quantity + FROM itemEntryIn iei + LEFT JOIN edi.warehouseFloramondo wf ON wf.entryFk = iei.entryFk + JOIN item i ON i.id = iei.itemFk + WHERE iei.landed >= util.VN_CURDATE() + AND iei.landed < vDated + AND iei.warehouseInFk = vWarehouseFk + AND (vItemFk IS NULL OR iei.itemFk = vItemFk) + AND (wf.entryFk IS NULL OR vIsLogifloraDay) + AND NOT (iei.landed > util.VN_CURDATE() AND i.isFloramondo) + UNION ALL + SELECT ieo.itemFk, ieo.quantity + FROM itemEntryOut ieo + JOIN item i ON i.id = ieo.itemFk + WHERE ieo.shipped >= util.VN_CURDATE() + AND ieo.shipped < vDated + AND ieo.warehouseOutFk = vWarehouseFk + AND (vItemFk IS NULL OR ieo.itemFk = vItemFk) + AND NOT (ieo.shipped > util.VN_CURDATE() AND i.isFloramondo) + ) sub + GROUP BY itemFk + HAVING stock; + + CALL cache.stock_refresh(FALSE); + + INSERT INTO tmp.itemList(itemFk, stock, visible, available) + SELECT item_id, amount, amount, amount + FROM cache.stock + WHERE warehouse_id = vWarehouseFk + AND (vItemFk IS NULL OR vItemFk = item_id) + ON DUPLICATE KEY UPDATE + stock = stock + VALUES(stock), + visible = visible + VALUES(visible), + available = available + VALUES(available); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_multipleBuy.sql b/db/routines/vn/procedures/item_multipleBuy.sql new file mode 100644 index 000000000..ba49f8d36 --- /dev/null +++ b/db/routines/vn/procedures/item_multipleBuy.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_multipleBuy`( + vDate DATETIME, + vWarehouseFk INT +) +BEGIN +/** + * Updates the tmp.itemInventory table, adding the buy id. + * + * @param tmp.itemInventory(buy_id) + * @param vDate -> Date of the purchase operation. + * @param vWarehouseFk -> Identifier of the warehouse (warehouseId). + */ + ALTER TABLE tmp.itemInventory ADD IF NOT EXISTS buy_id INT; + + CALL buyUltimate(vWarehouseFk, vDate); + + CREATE OR REPLACE TEMPORARY TABLE tmp + (KEY (itemFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT itemFk, buyFk + FROM tmp.buyUltimate + ORDER BY (vWarehouseFk = warehouseFk) DESC, landing DESC + LIMIT 10000000000000000000 + ) t + GROUP BY itemFk; + + UPDATE tmp.itemInventory ai + JOIN tmp t ON ai.id = t.itemFk + SET ai.buy_id = t.buyFk; + + DROP TEMPORARY TABLE tmp, tmp.buyUltimate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_multipleBuyByDate.sql b/db/routines/vn/procedures/item_multipleBuyByDate.sql new file mode 100644 index 000000000..d508afca4 --- /dev/null +++ b/db/routines/vn/procedures/item_multipleBuyByDate.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_multipleBuyByDate`( + vDated DATETIME, + vWarehouseFk TINYINT(3) +) +BEGIN +/** + * Updates the tmp.itemInventory table, adding the purchase date. + * + * @param tmp.itemInventory(buy_date) + * @param vDated -> end date + * @param vWarehouseFk -> warehouse id + */ + DECLARE vLastBuyScope INT; + SELECT comparativeLastBuyScope INTO vLastBuyScope + FROM config; + + ALTER TABLE tmp.itemInventory + ADD `buy_date` datetime NOT NULL; + + CREATE OR REPLACE TEMPORARY TABLE lastBuyScope + SELECT i.id, MAX(t.landed) lastLanded + FROM item i + JOIN buy b ON b.itemFk = i.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN supplier s ON s.id = e.supplierFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN (vDated + INTERVAL - vLastBuyScope DAY) AND vDated + AND NOT s.name = 'INVENTARIO' + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND w.isComparative + AND NOT e.isRaid + GROUP BY i.id; + + UPDATE tmp.itemInventory y + JOIN lastBuyScope lbs ON lbs.id = y.id + SET y.buy_date = lbs.lastLanded; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_refreshFromTags.sql b/db/routines/vn/procedures/item_refreshFromTags.sql new file mode 100644 index 000000000..398c01d8e --- /dev/null +++ b/db/routines/vn/procedures/item_refreshFromTags.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_refreshFromTags`(vSelf INT) +BEGIN +/** + * Updates item attributes with its corresponding tags. + * + * @param vSelf The item id + */ + DECLARE vTags JSON; + DECLARE vValues JSON; + DECLARE vAbbrs JSON; + DECLARE vOverwrites JSON; + + SELECT JSON_OBJECTAGG(`priority`, t.`name`), + JSON_OBJECTAGG(`priority`, it.`value`), + JSON_OBJECTAGG(`priority`, IFNULL(a.abbreviation, it.`value`)), + JSON_OBJECTAGG(`overwrite`, it.`value`) + INTO vTags, vValues, vAbbrs, vOverwrites + FROM itemTag it + JOIN tag t ON t.id = it.tagFk + LEFT JOIN tagAbbreviation a ON a.`value` = it.`value` + AND (a.tagFk IS NULL OR a.tagFk = t.id) + WHERE it.itemFk = vSelf; + + UPDATE item i + LEFT JOIN ink k ON k.name = JSON_VALUE(vOverwrites, '$.inkFk') + LEFT JOIN origin o ON o.name = JSON_VALUE(vOverwrites, '$.originFk') + LEFT JOIN producer p ON p.name = JSON_VALUE(vOverwrites, '$.producerFk') + SET i.`name` = CONCAT_WS(' ', + JSON_VALUE(vAbbrs, '$.1'), + JSON_VALUE(vAbbrs, '$.2'), + IF(i.isFloramondo, NULL, JSON_VALUE(vAbbrs, '$.3')) + ), + i.longName = CONCAT_WS(' ', + JSON_VALUE(vValues, '$.1'), + JSON_VALUE(vValues, '$.2'), + JSON_VALUE(vValues, '$.3') + ), + i.subname = JSON_VALUE(vValues, '$.4'), + i.size = JSON_VALUE(vOverwrites, '$.size'), + i.stems = IFNULL(JSON_VALUE(vOverwrites, '$.stems'),i.stems), + i.category = JSON_VALUE(vOverwrites, '$.category'), + i.tag5 = JSON_VALUE(vTags, '$.5'), + i.tag6 = JSON_VALUE(vTags, '$.6'), + i.tag7 = JSON_VALUE(vTags, '$.7'), + i.tag8 = JSON_VALUE(vTags, '$.8'), + i.tag9 = JSON_VALUE(vTags, '$.9'), + i.tag10 = JSON_VALUE(vTags, '$.10'), + i.value5 = JSON_VALUE(vValues, '$.5'), + i.value6 = JSON_VALUE(vValues, '$.6'), + i.value7 = JSON_VALUE(vValues, '$.7'), + i.value8 = JSON_VALUE(vValues, '$.8'), + i.value9 = JSON_VALUE(vValues, '$.9'), + i.value10 = JSON_VALUE(vValues, '$.10'), + i.producerFk = p.id, + i.inkFk = k.id, + i.originFk = IFNULL(o.id, i.originFk) + WHERE i.id = vSelf; + + CALL item_setGeneric(vSelf); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_refreshTags.sql b/db/routines/vn/procedures/item_refreshTags.sql new file mode 100644 index 000000000..84ace0883 --- /dev/null +++ b/db/routines/vn/procedures/item_refreshTags.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_refreshTags`() +BEGIN +/** + * Update item table, tag "cache" fields + * + * @param temporary table tmp.item(id) of the article + */ + DECLARE vDone BOOL; + DECLARE vItemFk INT; + DECLARE vCur CURSOR FOR SELECT id FROM tmp.item; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCur; + + l: LOOP + SET vDone = FALSE; + FETCH vCur INTO vItemFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL item_refreshFromTags(vItemFk); + END LOOP; + + CLOSE vCur; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_saveReference.sql b/db/routines/vn/procedures/item_saveReference.sql new file mode 100644 index 000000000..52416b637 --- /dev/null +++ b/db/routines/vn/procedures/item_saveReference.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_saveReference`(vBarcode VARCHAR(22), vReference VARCHAR(150)) +BEGIN + +/** + * Actualiza la referencia del item + * + * @param vBarcode del item + * @param vReference referencia a actualizar + */ + + DECLARE vItemFk INT; + + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + UPDATE item SET comment = vReference WHERE id = vItemFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_setGeneric.sql b/db/routines/vn/procedures/item_setGeneric.sql new file mode 100644 index 000000000..9a78b1349 --- /dev/null +++ b/db/routines/vn/procedures/item_setGeneric.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setGeneric`(vSelf INT) +BEGIN +/** + * Asigna el código genérico a un item, salvo que sea un código de item genérico. + * + * @param vSelf identificador de vn.item + */ + DECLARE vGenericFk INT; + + SELECT itemFk INTO vGenericFk + FROM ( + SELECT itemFk, SUM(matches) = maxMatches `match` + FROM ( + SELECT ga.id gaid, ga.itemFk, + CASE + WHEN t.code = 'nflowers' THEN + it.value <=> ga.numFlores + WHEN t.code = 'origin' THEN + it.value <=> ga.origin + WHEN t.code = 'quality' THEN + it.value <=> ga.quality + WHEN t.code = 'color' THEN + it.value <=> ga.color + WHEN t.code = 'category' THEN + it.value <=> ga.category + WHEN t.code = 'producer' THEN + it.value <=> ga.productor + ELSE + 0 + END matches, + (NOT ISNULL(ga.origin)) + + (NOT ISNULL(ga.color)) + + (NOT ISNULL(ga.quality)) + + (NOT ISNULL(ga.numFlores)) + + (NOT ISNULL(ga.category)) + + (NOT ISNULL(ga.productor)) maxMatches + FROM vn.item i + JOIN vn.itemTag it ON it.itemFk = i.id + JOIN vn.tag t ON t.id = it.tagFk + JOIN vn.genericAllocation ga + ON (i.typeFk = ga.typeFk OR ga.typeFk IS NULL) + AND (i.longName = ga.longName OR ga.longName IS NULL) + AND (i.`size` = ga.`size` OR ga.`size` IS NULL) + AND i.id != ga.itemFk + WHERE i.id = vSelf + AND NOT i.isFloramondo) sub + GROUP BY gaid + HAVING `match`) sub2 + LIMIT 1; + + UPDATE vn.item + SET genericFk = vGenericFk + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/changes/234601/00-addressShortage.sql b/db/routines/vn/procedures/item_setVisibleDiscard.sql similarity index 65% rename from db/changes/234601/00-addressShortage.sql rename to db/routines/vn/procedures/item_setVisibleDiscard.sql index 57c07d480..1cc2a8871 100644 --- a/db/changes/234601/00-addressShortage.sql +++ b/db/routines/vn/procedures/item_setVisibleDiscard.sql @@ -1,24 +1,4 @@ - --- Place your SQL code here - -ALTER TABLE `vn`.`productionConfig` ADD shortageAddressFk int(11) COMMENT 'Consignatario por defecto para añadir un item de alta'; -ALTER TABLE `vn`.`productionConfig` ADD CONSTRAINT productionConfig_FK FOREIGN KEY (shortageAddressFk) REFERENCES vn.address(id) ON DELETE RESTRICT ON UPDATE CASCADE; - -ALTER TABLE `vn`.`sale` MODIFY COLUMN originalQuantity double(9,1) DEFAULT NULL NULL COMMENT 'Se utiliza para notificar a través de rocket los cambios de quantity'; - -INSERT INTO `salix`.`ACL` ( model, property, accessType, permission, principalType, principalId) VALUES( 'AddressShortage', '*', 'READ', 'ALLOW', 'ROLE', 'production'); - --- vn.addressShortage definition - -CREATE TABLE `vn`.`addressShortage` ( - `addressFk` int(11) NOT NULL, - PRIMARY KEY (`addressFk`), - CONSTRAINT `addressShortage_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - - DELIMITER $$ - CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setVisibleDiscard`( vItemFk INT, vWarehouseFk INT, diff --git a/db/routines/vn/procedures/item_updatePackingShelve.sql b/db/routines/vn/procedures/item_updatePackingShelve.sql new file mode 100644 index 000000000..23e449ef5 --- /dev/null +++ b/db/routines/vn/procedures/item_updatePackingShelve.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_updatePackingShelve`(vSelf INT, vPacking INT) +BEGIN + + /** + * Actualiza el valor de item.packingShelve + * + * @param vSelf Identificador de vn.item + * @param vPacking Cantidad de unidades de venta que caben en una bandeja + */ + + UPDATE vn.item i + SET i.packingShelve = vPacking + WHERE i.id = vSelf; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_updatePackingType.sql b/db/routines/vn/procedures/item_updatePackingType.sql new file mode 100644 index 000000000..12a5e687b --- /dev/null +++ b/db/routines/vn/procedures/item_updatePackingType.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_updatePackingType`(vItem INT, vItemPackingTypeFk VARCHAR(1)) +BEGIN +/** + * Update the packing type of an item + * + * @param vItem id del item a actualizar + * @param vItemPackingTypeFk packing type + */ + UPDATE item SET itemPackingTypeFk = vItemPackingTypeFk WHERE id = vItem; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/item_zoneClosure.sql b/db/routines/vn/procedures/item_zoneClosure.sql new file mode 100644 index 000000000..c555e5df2 --- /dev/null +++ b/db/routines/vn/procedures/item_zoneClosure.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_zoneClosure`() +BEGIN + +/* Devuelve una tabla temporal con la hora minima de un ticket sino tiene el de la zoneClosure y + * si tampoco hay el de la zona , para todos los artículos con salida hoy. + * + * @return tmp.itemZoneClosure(itemFk, timed) + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemZoneClosure + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT s.itemFk, + MIN(DATE_FORMAT(IF(HOUR(t.shipped),t.shipped, + IFNULL(zc.hour, z.HOUR)), '%H:%i') + )timed + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND CONCAT(util.VN_CURDATE(), ' 23:59:59') + GROUP BY s.itemFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ledger_doCompensation.sql b/db/routines/vn/procedures/ledger_doCompensation.sql new file mode 100644 index 000000000..e45db376c --- /dev/null +++ b/db/routines/vn/procedures/ledger_doCompensation.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_doCompensation`(vDated DATE, vCompensationAccount VARCHAR(10) , vBankFk VARCHAR(10), vConcept VARCHAR(255), vAmount DECIMAL(10,2), vCompanyFk INT, vOriginalAccount VARCHAR(10)) +BEGIN +/** + * Compensa un pago o un recibo insertando en contabilidad + * + * @param vDated fecha en la cual se anota + * @param vCompensationAccount cuenta contable contra la que se compensa + * @param vBankFk banco de la compensacion + * @param vConcept descripcion + * @param vAmount cantidad que se compensa + * @param vCompany empresa + * @param vOriginalAccount cuenta contable desde la cual se compensa + * + */ + DECLARE vNewBookEntry INT; + DECLARE vIsClientCompensation INT; + DECLARE vClientFk INT; + DECLARE vSupplierFk INT; + DECLARE vIsOriginalAClient BOOL; + DECLARE vPayMethodCompensation INT; + + CALL ledger_next(vNewBookEntry); + + SELECT COUNT(id) INTO vIsOriginalAClient FROM client WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci; + + SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation + FROM client + WHERE accountingAccount LIKE vCompensationAccount COLLATE utf8_general_ci; + + SET @vAmount1:= 0.0; + SET @vAmount2:= 0.0; + + INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id) + VALUES ( vNewBookEntry, + vDated, + vOriginalAccount, + vCompensationAccount, + vConcept, + @vAmount1:= IF( + (vIsOriginalAClient AND vAmount > 0) OR + (NOT vIsOriginalAClient AND vAmount < 0), + 0, + ABS(vAmount) + ), + @vAmount2:= IF(@vAmount1, + 0, + ABS(vAmount) + ), + vCompanyFk + ), + ( vNewBookEntry, + vDated, + vCompensationAccount, + vOriginalAccount, + vConcept, + @vAmount2, + @vAmount1, + vCompanyFk); + + IF vIsClientCompensation THEN + IF vIsOriginalAClient THEN + SET vAmount = -vAmount; + END IF; + INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate) + VALUES (vConcept, vAmount, vDated, vBankFk, vCompanyFk, vClientFk, TRUE); + ELSE + IF NOT vIsOriginalAClient THEN + SET vAmount = -vAmount; + END IF; + SELECT id INTO vSupplierFk FROM supplier WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci; + SELECT id INTO vPayMethodCompensation FROM payMethod WHERE `code` = 'compensation'; + + INSERT INTO payment (received, dueDated, supplierFk, amount, bankFk, payMethodFk, concept, companyFk, isConciliated) + VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ledger_next.sql b/db/routines/vn/procedures/ledger_next.sql new file mode 100644 index 000000000..a45ebdd29 --- /dev/null +++ b/db/routines/vn/procedures/ledger_next.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(OUT vNewBookEntry INT) +BEGIN + + UPDATE vn.ledgerConfig SET lastBookEntry = LAST_INSERT_ID(lastBookEntry + 1); + SET vNewBookEntry = LAST_INSERT_ID(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/logShow.sql b/db/routines/vn/procedures/logShow.sql new file mode 100644 index 000000000..836d3b0c4 --- /dev/null +++ b/db/routines/vn/procedures/logShow.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`logShow`(vOriginFk INT, vEntity VARCHAR(45)) +BEGIN +/** + * Muestra las acciones realizadas por el usuario + * + * @param vOriginFk Id del registro de origen + * @param vEntity Nombre que hace referencia a la tabla. + */ + DECLARE vTableName VARCHAR(45); + + SET vTableName = CONCAT(vEntity, 'Log'); + + SET @qryLog := CONCAT( + 'SELECT ot.id, ot.originFk, ot.userFk, u.name, ot.action, ot.creationDate, ot.description FROM ', vTableName, ' AS ot', + ' INNER JOIN account.user u ON u.id = ot.userFk', + ' WHERE ot.originFk = ', vOriginFk, ' ORDER BY ot.creationDate DESC' + ); + + PREPARE stmt FROM @qryLog; + EXECUTE stmt; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/lungSize_generator.sql b/db/routines/vn/procedures/lungSize_generator.sql new file mode 100644 index 000000000..e13e83650 --- /dev/null +++ b/db/routines/vn/procedures/lungSize_generator.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`lungSize_generator`(vDate DATE) +BEGIN + +SET @buildingOrder := 0; +SET @route := 0; +set @cajas := 0; + + UPDATE tmp.sorter + SET buildingOrder = @buildingOrder := IF(@route = @route := routeFk, @buildingOrder, 0) + 1 + where date(created) = vDate + order by routeFk, created, weight DESC; + + update tmp.sorter + SET palletOrder = buildingOrder mod 14, lungGrow = buildingOrder mod 14 + WHERE date(created) = vDate; + + UPDATE tmp.sorter + JOIN ( + SELECT routeFk, max(id) maxid + FROM tmp.sorter + where date(created) = vDate + GROUP BY routeFk) sub ON sub.maxid = id + SET lungGrow = 1 - palletOrder ; + + UPDATE tmp.sorter + SET lungGrow = IF(palletOrder = 0, -13, lungGrow); + + DELETE FROM tmp.lungSize WHERE dia = vDate; + + INSERT INTO tmp.lungSize(dia, hora,size) + select vDate,hora, @cajas := @cajas + cajas as size + from + ( + select IF(lungGrow BETWEEN -12 AND -1, ETD,time_format(created,"%H:%i")) as hora, sum(if(lungGrow <= 0, lungGrow, 1)) as cajas, @cajas := 0 + from tmp.sorter + where date(created) = vDate + group by hora + ) sub; + + SELECT * FROM tmp.lungSize + WHERE dia = vDate; + + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/machineWorker_add.sql b/db/routines/vn/procedures/machineWorker_add.sql new file mode 100644 index 000000000..b2a7c7e19 --- /dev/null +++ b/db/routines/vn/procedures/machineWorker_add.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT) +BEGIN + +/** + * Inserta registro si el vWorkerFk no ha registrado nada en las últimas 12 horas + * @param vPlate número de matrícula + * @param vWorkerFk id del worker + * +*/ + UPDATE vn.machineWorker mw + JOIN vn.machine m ON m.id = mw.machineFk + SET mw.outTimed = util.VN_NOW() + WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate) + AND ISNULL(mw.outTimed); + + INSERT INTO machineWorker (machineFk, workerFk) + SELECT m.id, vWorkerFk + FROM machine m + WHERE m.plate= vPlate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/machineWorker_getHistorical.sql b/db/routines/vn/procedures/machineWorker_getHistorical.sql new file mode 100644 index 000000000..47fcec5b6 --- /dev/null +++ b/db/routines/vn/procedures/machineWorker_getHistorical.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT) +BEGIN +/** + * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, + * si es jefe de producción muestra el historial completo. + * + * @param vPlate número de matrícula + * @param vWorkerFk id del trabajador + * +*/ + DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vWorkerFk); + + SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed + FROM machineWorker mw + JOIN machine m ON m.plate = vPlate + WHERE mw.machineFk = m.id + AND mw.workerFk = IF(account.user_hasRole(vWorkerName, 'coolerAssist'), mw.workerFk, vWorkerFk) + ORDER BY mw.inTimed DESC; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/machineWorker_update.sql b/db/routines/vn/procedures/machineWorker_update.sql new file mode 100644 index 000000000..064aa8931 --- /dev/null +++ b/db/routines/vn/procedures/machineWorker_update.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT) +BEGIN + +/** + * Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate, + * + * @param vPlate número de matrícula + * @param vWorkerFk id del trabajador + * +*/ + + DECLARE vMachineFk INT(10); + DECLARE vMaxHours INT(10); + + SELECT m.id INTO vMachineFk + FROM machine m + WHERE m.plate = vPlate; + + SELECT maxHours INTO vMaxHours + FROM machineWorkerConfig; + + IF (SELECT COUNT(*) + FROM machineWorker m + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN + + UPDATE machineWorker m + SET m.outTimed = CURRENT_TIMESTAMP() + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) + AND ISNULL(m.outTimed) + AND m.machineFk = vMachineFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/machine_getWorkerPlate.sql b/db/routines/vn/procedures/machine_getWorkerPlate.sql new file mode 100644 index 000000000..4a50e0334 --- /dev/null +++ b/db/routines/vn/procedures/machine_getWorkerPlate.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`machine_getWorkerPlate`(vWorkerFk INT) +BEGIN +/** + * Selecciona la matrícula del vehículo del workerfk + * + * @param vWorkerFk el id del trabajador + */ + SELECT m.plate + FROM machine m + JOIN machineWorker mw ON mw.machineFk = m.id + WHERE mw.inTimed >= TIMESTAMPADD(HOUR , -12,util.VN_NOW()) + AND ISNULL(mw.outTimed) + AND mw.workerFk = vWorkerFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/mail_insert.sql b/db/routines/vn/procedures/mail_insert.sql new file mode 100644 index 000000000..5c5c2e9fd --- /dev/null +++ b/db/routines/vn/procedures/mail_insert.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`mail_insert`( + vReceiver VARCHAR(255), + vReplyTo VARCHAR(50), + vSubject VARCHAR(100), + vBody TEXT) +BEGIN +/** + * Inserta en la tabla vn.mail + * + * @param vReceiver Receptor del correo + * @param vReplyTo A quién contestar el correo + * @param vSubject Título del correo + * @param vBody Cuerpo del correo + */ + + DECLARE vIsRepeated BOOLEAN; + + SELECT COUNT(*) INTO vIsRepeated + FROM vn.mail + WHERE creationDate >= util.VN_CURDATE() + AND `receiver` = vReceiver + AND `replyTo` = vReplyTo + AND `subject` = vSubject + AND !sent; + + IF NOT vIsRepeated THEN + + INSERT INTO vn.mail SET + `receiver` = vReceiver, + `replyTo` = vReplyTo, + `subject` = vSubject, + `body` = IFNULL(vBody,vSubject); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/makeNewItem.sql b/db/routines/vn/procedures/makeNewItem.sql new file mode 100644 index 000000000..5995f43b7 --- /dev/null +++ b/db/routines/vn/procedures/makeNewItem.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`makeNewItem`() +BEGIN + + DECLARE newItemFk INT; + + SELECT getNewItemId() INTO newItemFk; + + INSERT INTO item(id,name,typeFk,originFk) + SELECT newItemFk, 'Nuevo artículo', 78,39; + + SELECT newItemFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/makePCSGraf.sql b/db/routines/vn/procedures/makePCSGraf.sql new file mode 100644 index 000000000..31b4a42e7 --- /dev/null +++ b/db/routines/vn/procedures/makePCSGraf.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`makePCSGraf`(vDated DATE) +BEGIN + + + DECLARE vHour INT DEFAULT 0; + DECLARE vMinute INT DEFAULT 0; + DECLARE vBoxes INT; + + + DROP TEMPORARY TABLE IF EXISTS vn.pcsDay; + CREATE TEMPORARY TABLE vn.pcsDay + SELECT 0 as hh, 0 as mm, 0 as boxes; + + -- Creamos una tabla soporte para acumular las cajas a lo largo del dia + WHILE vHour < 24 DO + + WHILE vMinute < 59 DO + + SET vMinute = vMinute + 1; + + INSERT INTO vn.pcsDay(hh,mm) VALUES(vHour, vMinute); + + END WHILE; + + SET vMinute = -1; + SET vHour = vHour + 1; + + END WHILE; + + -- Acumulamos + UPDATE vn.pcsDay pd + LEFT JOIN (SELECT * FROM vn.pcs_graf WHERE dia = vDated) pg USING(hh,mm) + SET pd.boxes = pd.boxes + pg.box; + + SELECT * FROM vn.pcsDay; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/manaSpellersRequery.sql b/db/routines/vn/procedures/manaSpellersRequery.sql new file mode 100644 index 000000000..30b91b4f1 --- /dev/null +++ b/db/routines/vn/procedures/manaSpellersRequery.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`manaSpellersRequery`(vWorkerFk INTEGER) +`whole_proc`: +BEGIN +/** + * Guarda en workerMana el mana consumido por un trabajador + * + * @param vWorkerFk Id Trabajador + */ + DECLARE vWorkerIsExcluded BOOLEAN; + + SELECT COUNT(*) INTO vWorkerIsExcluded + FROM workerManaExcluded + WHERE workerFk = vWorkerFk; + + IF vWorkerIsExcluded THEN + LEAVE whole_proc; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.client + SELECT id + FROM client + WHERE salesPersonFk = vWorkerFk; + + CALL client_getMana(); + + INSERT INTO workerMana (workerFk, amount) + SELECT vWorkerFk, sum(mana) + FROM tmp.clientMana + ON DUPLICATE KEY UPDATE amount = VALUES(amount); + + DROP TEMPORARY TABLE + tmp.client, + tmp.clientMana; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql new file mode 100644 index 000000000..2a28aa9a0 --- /dev/null +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -0,0 +1,194 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventory`( + vDate DATE, + vWarehouseFk TINYINT, + vMaxDays TINYINT +) +proc: BEGIN + DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; + DECLARE vDateFrom DATE DEFAULT vDate; + DECLARE vDateTo DATETIME; + DECLARE vDateToTomorrow DATETIME; + DECLARE vDefaultDayRange INT; + + IF vDate < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + IF vDate = util.VN_CURDATE() THEN + SELECT inventoried INTO vDateFrom + FROM config; + END IF; + + SELECT defaultDayRange INTO vDefaultDayRange + FROM comparativeConfig; + + SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; + SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; + + ALTER TABLE tmp.itemInventory + ADD `avalaible` INT NOT NULL, + ADD `sd` INT NOT NULL, + ADD `rest` INT NOT NULL, + ADD `expected` INT NOT NULL, + ADD `inventory` INT NOT NULL, + ADD `visible` INT NOT NULL, + ADD `life` TINYINT NOT NULL DEFAULT '0'; + + -- Calculo del inventario + UPDATE tmp.itemInventory ai + JOIN ( + SELECT itemFk Id_Article, SUM(quantity) Subtotal + FROM ( + SELECT s.itemFk, - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + ) sub2 + GROUP BY itemFk + ) sub ON ai.id = sub.Id_Article + SET ai.inventory = sub.Subtotal, + ai.visible = sub.Subtotal, + ai.avalaible = sub.Subtotal, + ai.sd = sub.Subtotal; + + -- Cálculo del visible + UPDATE tmp.itemInventory ai + JOIN ( + SELECT itemFk Id_Article, SUM(quantity) Subtotal + FROM ( + SELECT s.itemFk, s.quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped >= vDate + AND t.shipped < vDateTomorrow + AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed = vDate + AND NOT t.isReceived + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped = vDate + AND NOT t.isReceived + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + ) sub2 + GROUP BY itemFk + ) sub ON ai.id = sub.Id_Article + SET ai.visible = ai.visible + sub.Subtotal; + + -- Calculo del disponible + CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT sub.itemFk, + vWarehouseFk warehouseFk, + sub.dated, + SUM(sub.quantity) quantity + FROM ( + SELECT s.itemFk, + DATE(t.shipped) dated, + - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, t.landed, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, t.shipped, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + ) sub + GROUP BY sub.itemFk, sub.dated; + + CALL item_getAtp(vDate); + CALL travel_upcomingArrivals(vWarehouseFk, vDate); + + UPDATE tmp.itemInventory ai + JOIN ( + SELECT it.itemFk, + SUM(it.quantity) quantity, + im.quantity minQuantity + FROM tmp.itemCalc it + JOIN tmp.itemAtp im ON im.itemFk = it.itemFk + JOIN item i ON i.id = it.itemFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN tmp.itemTravel t ON t.wh = o.warehouseFk + WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, + t.landing, + vDateToTomorrow) + GROUP BY it.itemFk + ) sub ON sub.itemFk = ai.id + SET ai.avalaible = IF(sub.minQuantity > 0, + ai.avalaible, + ai.avalaible + sub.minQuantity), + ai.sd = ai.inventory + sub.quantity; + + DROP TEMPORARY TABLE + tmp.itemTravel, + tmp.itemCalc, + tmp.itemAtp; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/mysqlConnectionsSorter_kill.sql b/db/routines/vn/procedures/mysqlConnectionsSorter_kill.sql new file mode 100644 index 000000000..129b356f2 --- /dev/null +++ b/db/routines/vn/procedures/mysqlConnectionsSorter_kill.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`mysqlConnectionsSorter_kill`() +BEGIN + +/** + * Elimina conexiones del usuario sorter con tiempo >= 30seg. Asociado al evento con el mismo nombre + */ + + DECLARE vDone INT DEFAULT 0; + DECLARE vProcesId INT; + + DECLARE vCursor CURSOR FOR + SELECT p.id + FROM information_schema.processlist p + WHERE USER = 'sorter' + AND TIME >= 30; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCursor; + + l: LOOP + + FETCH vCursor INTO vProcesId; + + IF vDone THEN + LEAVE l; + END IF; + + KILL vProcesId; + + END LOOP; + + CLOSE vCursor; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/mysqlPreparedCount_check.sql b/db/routines/vn/procedures/mysqlPreparedCount_check.sql new file mode 100644 index 000000000..b0c78946d --- /dev/null +++ b/db/routines/vn/procedures/mysqlPreparedCount_check.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`mysqlPreparedCount_check`() +BEGIN + DECLARE vPreparedCount INTEGER; + + SELECT VARIABLE_VALUE INTO vPreparedCount + FROM INFORMATION_SCHEMA.GLOBAL_STATUS + WHERE VARIABLE_NAME LIKE '%prepared_stmt_count%'; + + IF(vPreparedCount >= 40000) THEN + CALL `vn`.`mail_insert`('cau@verdnatura.es', + NULL, + 'Problemas BBDD prepared_stmt_count', + CONCAT('Existen problemas con el servicio de Logiflora, prepared_stmt_count con valor: ', + vPreparedCount, + ', está próximo a exceder su límite. \r\n Hay que reiniciar el servicio LF.VMP.Service del servidor a3.') + ); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/nextShelvingCodeMake.sql b/db/routines/vn/procedures/nextShelvingCodeMake.sql new file mode 100644 index 000000000..d76d6276b --- /dev/null +++ b/db/routines/vn/procedures/nextShelvingCodeMake.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`nextShelvingCodeMake`() +BEGIN + + DECLARE newShelving VARCHAR(3); + DECLARE vCode VARCHAR(3); + + SELECT MAX(code) INTO vCode + FROM vn.shelving + WHERE isPrinted = FALSE; + + SET @a1 := ASCII(MID(vCode,1,1)); + SET @a2 := ASCII(MID(vCode,2,1)); + SET @a3 := ASCII(MID(vCode,3,1)) + 1; + + IF @a3 > 90 THEN + + SET @a3 = 65; + SET @a2 = @a2 + 1; + + IF @a2 > 90 THEN + + SET @a2 = 65; + SET @a1 = @a1 + 1; + + IF @a1 > 90 THEN + + SET @a1 = 65; + + END IF; + + END IF; + + END IF; + + SET newShelving = CHAR(@a1,@a2,@a3 USING utf8); + + INSERT INTO vn.shelving(code) VALUES(newShelving); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/observationAdd.sql b/db/routines/vn/procedures/observationAdd.sql new file mode 100644 index 000000000..960cf0bfe --- /dev/null +++ b/db/routines/vn/procedures/observationAdd.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`observationAdd`(vOriginFk INT, vTableCode VARCHAR(45), vDescription TEXT) +BEGIN +/** + * Guarda las observaciones realizadas por el usuario + * + * @param vOriginFk Id del registro de origen + * @param vTypeCode Código que referencia a la tabla. + * @param descripcion Texto de la observacion + */ + DECLARE vTableName VARCHAR(45); + + SET vTableName = CONCAT(vTableCode,'Observation'); + + IF ISNULL(vTableName) THEN + CALL util.throw('CODE_NOT_FOUND'); + END IF; + + SET @qryLog := CONCAT( + 'INSERT INTO ', vTableName, ' (originFk, userFk, description)', + ' VALUES (', vOriginFk, ', ', account.myUser_getId(), ', "', vDescription, '")' + ); + + PREPARE stmt FROM @qryLog; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/orderCreate.sql b/db/routines/vn/procedures/orderCreate.sql new file mode 100644 index 000000000..8f732dad6 --- /dev/null +++ b/db/routines/vn/procedures/orderCreate.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`orderCreate`( + vLanded DATE, + vAgencyMode INT, + vAddress INT, + vSourceApp VARCHAR(10), + OUT vOrderId INT) +BEGIN + + DECLARE vDeliveryMethod INT; + DECLARE vClient INT; + + SELECT deliveryMethodFk INTO vDeliveryMethod + FROM vn.agencyMode + WHERE id = vAgencyMode; + + SELECT clientFk INTO vClient + FROM vn.address + WHERE id = vAddress; + + INSERT INTO hedera.order(date_send,customer_id,delivery_method_id,agency_id,address_id,source_app) + VALUES( vLanded,vClient ,vDeliveryMethod,vAgencyMode ,vAddress ,vSourceApp); + + SET vOrderId = LAST_INSERT_ID(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/orderDelete.sql b/db/routines/vn/procedures/orderDelete.sql new file mode 100644 index 000000000..4264191da --- /dev/null +++ b/db/routines/vn/procedures/orderDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`orderDelete`(IN vId INT) +BEGIN + + DELETE FROM hedera.`order` where id = vId; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/orderListCreate.sql b/db/routines/vn/procedures/orderListCreate.sql new file mode 100644 index 000000000..12396ea90 --- /dev/null +++ b/db/routines/vn/procedures/orderListCreate.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`orderListCreate`( + vLanded DATE, + vAgencyMode INT, + vAddress INT, + vSourceApp VARCHAR(10)) +BEGIN + + DECLARE vOrderId INT; + CALL vn.orderCreate(vLanded,vAgencyMode,vAddress,vSourceApp,vOrderId); + SELECT vOrderId; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/orderListVolume.sql b/db/routines/vn/procedures/orderListVolume.sql new file mode 100644 index 000000000..6eb641f83 --- /dev/null +++ b/db/routines/vn/procedures/orderListVolume.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`orderListVolume`(IN vOrderId INT) +BEGIN + + SELECT + o.id, + o.itemFk, + i.description, + o.amount, + round(ic.cm3delivery * o.amount / 1000000,3) as volume + FROM hedera.orderRow o + JOIN item i ON i.id = o.itemFk + JOIN itemCost ic ON ic.itemFk = o.itemFk AND ic.warehouseFk = o.warehouseFk + WHERE o.orderFk = vOrderId; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/packageInvoicing.sql b/db/routines/vn/procedures/packageInvoicing.sql new file mode 100644 index 000000000..7dae8dcf2 --- /dev/null +++ b/db/routines/vn/procedures/packageInvoicing.sql @@ -0,0 +1,121 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packageInvoicing`( + IN vClient INT, + IN vDate DATE, + IN vCompany INT, + IN vIsAllInvoiceable BOOLEAN, + OUT vNewTicket INT(11) + ) +BEGIN + + DECLARE vGraceDays INT; + DECLARE vDateStart DATE DEFAULT '2017-11-21'; + DECLARE vIsInvoiceable BOOLEAN; + DECLARE vWarehouse INT DEFAULT 13; + DECLARE vComponentCost INT DEFAULT 28; + DECLARE vGraceDate DATE; + DECLARE vDateEnd DATE; + + SET vGraceDays = IF(vIsAllInvoiceable ,0, 30); + SET vGraceDate = TIMESTAMPADD(DAY, - vGraceDays, vDate); + + /* Clientes especiales: + 3240 MADEFLOR + 992 JAVIER FELIU + 4 TONI VENDRELL + */ + + IF vClient IN (992, 3240, 4) THEN + + SET vGraceDays = 365; + + END IF; + /* Fin clientes especiales */ + + SET vDateEnd = DATE_ADD(vDate, INTERVAL 1 DAY); + + DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoice; + + CREATE TEMPORARY TABLE tmp.packageToInvoice + SELECT p.itemFk, + tp.packagingFk, + IF(tp.quantity < 0 OR t.shipped < vGraceDate, tp.quantity, 0) quantity, + tp.ticketFk, + p.price + FROM ticketPackaging tp + JOIN packaging p ON p.id = tp.packagingFk + JOIN ticket t ON t.id = tp.ticketFk + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND t.clientFk = vClient; + + DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoicePositives; + + CREATE TEMPORARY TABLE tmp.packageToInvoicePositives + SELECT itemFk, sum(quantity) as totalQuantity + FROM tmp.packageToInvoice + GROUP BY itemFk + HAVING totalQuantity > 0; + + SELECT COUNT(*) + INTO vIsInvoiceable + FROM tmp.packageToInvoicePositives; + + IF vIsInvoiceable THEN + + CALL ticket_add(vClient, + vDateEnd, + vWarehouse, + vCompany, + NULL, + NULL, + NULL, + vDateEnd, + account.myUser_getId(), + TRUE, + vNewTicket); + + INSERT INTO ticketPackaging( + ticketFk, + packagingFk, + quantity, + pvp) + SELECT vNewTicket, + pti.packagingFk, + - SUM(pti.quantity) AS totalQuantity, + pti.price + FROM tmp.packageToInvoice pti + LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk + WHERE ptip.itemFK IS NOT NULL + OR vIsAllInvoiceable + GROUP BY packagingFk + HAVING totalQuantity; + + INSERT INTO sale( + ticketFk, + itemFk, + concept, + quantity, + price + ) + SELECT vNewTicket, + pti.itemFk, + i.name as concept, + sum(pti.quantity) as totalQuantity, + pti.price + FROM tmp.packageToInvoice pti + JOIN item i ON i.id = pti.itemFk + LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk + WHERE ptip.itemFK IS NOT NULL + OR vIsAllInvoiceable + GROUP BY pti.itemFk + HAVING totalQuantity; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT id, vComponentCost, price + FROM sale + WHERE ticketFk = vNewTicket; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/packingListPrinted.sql b/db/routines/vn/procedures/packingListPrinted.sql new file mode 100644 index 000000000..473ead5be --- /dev/null +++ b/db/routines/vn/procedures/packingListPrinted.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingListPrinted`(ticketFk INT) +BEGIN + + UPDATE vn2008.Movimientos_mark mm + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mm.Id_Movimiento + SET mm.valor = 2 -- Impreso + WHERE mm.valor = 1 -- Listo para imprimir + AND mm.stateFk = 9 -- Encajando + AND m.Id_Ticket = ticketFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/packingListSwitch.sql b/db/routines/vn/procedures/packingListSwitch.sql new file mode 100644 index 000000000..65384827c --- /dev/null +++ b/db/routines/vn/procedures/packingListSwitch.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingListSwitch`(saleFk INT) +BEGIN + + DECLARE valueFk INT; + DECLARE encajando INT DEFAULT 9; + + SELECT valor INTO valueFk + FROM vn2008.Movimientos_mark + WHERE Id_Movimiento = saleFk + AND stateFk = encajando; + + SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3; + + REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk) + VALUES(saleFk,valueFk,account.myUser_getId(),encajando); + + +END$$ +DELIMITER ; diff --git a/db/.archive/232601/00-packingSiteAdvanced.sql b/db/routines/vn/procedures/packingSite_startCollection.sql similarity index 60% rename from db/.archive/232601/00-packingSiteAdvanced.sql rename to db/routines/vn/procedures/packingSite_startCollection.sql index 0e33744cd..53edd89f1 100644 --- a/db/.archive/232601/00-packingSiteAdvanced.sql +++ b/db/routines/vn/procedures/packingSite_startCollection.sql @@ -1,22 +1,5 @@ -CREATE TABLE `vn`.`packingSiteAdvanced` ( - `ticketFk` int(11), - `workerFk` int(10) unsigned, - PRIMARY KEY (`ticketFk`), - KEY `packingSiteAdvanced_FK_1` (`workerFk`), - CONSTRAINT `packingSiteAdvanced_FK` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `packingSiteAdvanced_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('PackingSiteAdvanced', '*', '*', 'ALLOW', 'ROLE', 'production'); - - DROP PROCEDURE IF EXISTS `vn`.`packingSite_startCollection`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingSite_startCollection`(vSelf INT, vTicketFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packingSite_startCollection`(vSelf INT, vTicketFk INT) proc: BEGIN /** * @param vSelf packingSite id @@ -66,6 +49,3 @@ proc: BEGIN WHERE id = vSelf; END$$ DELIMITER ; - - - diff --git a/db/routines/vn/procedures/parking_add.sql b/db/routines/vn/procedures/parking_add.sql new file mode 100644 index 000000000..17772424e --- /dev/null +++ b/db/routines/vn/procedures/parking_add.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`parking_add`(vFromColumn INT, vToColumn INT, vFromRow INT, vToRow INT, vSectorFk INT, vIsLetterMode BOOLEAN) +BEGIN + + DECLARE vColumn INT; + DECLARE vRow INT; + DECLARE vLetters VARCHAR(26) DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + DECLARE vMaxId INT; + DECLARE vCode VARCHAR(8); + + SET vColumn = vFromColumn; + SET vRow = vFromRow; + SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); + + SELECT MAX(id) INTO vMaxId + FROM vn.parking; + + WHILE vColumn <= vToColumn DO + + WHILE vRow <= vToRow DO + + INSERT IGNORE INTO vn.parking(`column`, `row`, sectorFk, `code`, pickingOrder) + VALUES (vColumn, vRow, vSectorFk, vCode, vColumn * 100 + vRow ) + ON DUPLICATE KEY UPDATE `code` = vCode; + + SET vRow = vRow + 1; + SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); + + END WHILE; + + SET vRow = vFromRow; + SET vColumn = vColumn + 1; + + SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); + + END WHILE; + + SELECT * FROM vn.parking WHERE `column` BETWEEN vFromColumn AND vToColumn; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/parking_algemesi.sql b/db/routines/vn/procedures/parking_algemesi.sql new file mode 100644 index 000000000..6ea13193d --- /dev/null +++ b/db/routines/vn/procedures/parking_algemesi.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`parking_algemesi`(vFromRow INT, vToRow INT, vSectorFk INT, vLetter VARCHAR(1), vPickingOrder INT, vTrolleysByLine INT) +BEGIN + + DECLARE vRow INT; + DECLARE vCode VARCHAR(8); + DECLARE i INT; + + IF vToRow < vFromRow THEN + + SET vRow = vFromRow; + + WHILE vRow >= vToRow DO + + SET i = 1; + + WHILE i <= vTrolleysByLine DO + + SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); + + INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) + VALUES (vSectorFk, vCode, vPickingOrder + (i * 10)) + ON DUPLICATE KEY UPDATE `code` = vCode; + + SET i = i + 1; + + END WHILE; + + SET vRow = vRow - 1; + + END WHILE; + + ELSE + + SET vRow = vFromRow; + + WHILE vRow <= vToRow DO + + SET i = 1; + + WHILE i <= vTrolleysByLine DO + + SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); + + INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) + VALUES (vSectorFk, vCode, vPickingOrder + (i * 10) ) + ON DUPLICATE KEY UPDATE `code` = vCode; + + SET i = i + 1; + + END WHILE; + + SET vRow = vRow + 1; + + END WHILE; + + + END IF; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/parking_new.sql b/db/routines/vn/procedures/parking_new.sql new file mode 100644 index 000000000..327e3a4b0 --- /dev/null +++ b/db/routines/vn/procedures/parking_new.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`parking_new`(vStart INT, vEnd INT, vSectorFk INT) +BEGIN + + DECLARE vRow INT; + DECLARE vColumn INT; + DECLARE vLetters VARCHAR(200); + DECLARE vLettersLength INT; + + SET vColumn = vStart; + SET vRow = 1; + SET vLetters = 'ABCDEF'; + SET vLettersLength = LENGTH(vLetters); + + WHILE vColumn <= vEnd DO + + REPLACE vn.parking(`column`, `row`, `code`, sectorFk) + VALUES(vColumn, vRow, CONCAT(vColumn,MID(vLetters,vRow,1)), vSectorFk); + + SET vRow = vRow + 1; + + IF vRow > vLettersLength THEN + + SET vRow = 1; + SET vColumn = vColumn + 1; + + END IF; + + END WHILE; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/parking_setOrder.sql b/db/routines/vn/procedures/parking_setOrder.sql new file mode 100644 index 000000000..241f855f7 --- /dev/null +++ b/db/routines/vn/procedures/parking_setOrder.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`parking_setOrder`(vWarehouseFk INT) +BEGIN + + /* + * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor + */ + + UPDATE vn.parking p + JOIN ( + SELECT code, + @orden := @orden + 10 AS po + FROM ( + SELECT c.prepOrder, + p.code, + @orden := 0, + IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , + CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication + FROM vn.parking p + JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci + WHERE s.warehouseFk = vWarehouseFk) sub + ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code + SET p.pickingOrder = sub2.po; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/prepareClientList.sql b/db/routines/vn/procedures/prepareClientList.sql new file mode 100644 index 000000000..486152fd6 --- /dev/null +++ b/db/routines/vn/procedures/prepareClientList.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`prepareClientList`() +BEGIN + + /* + * Require la tabla tmp.ticket(id,clientFk) + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.client; + CREATE TEMPORARY TABLE tmp.client + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT DISTINCT clientFk id + FROM tmp.ticket; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/prepareTicketList.sql b/db/routines/vn/procedures/prepareTicketList.sql new file mode 100644 index 000000000..f0f47f9a2 --- /dev/null +++ b/db/routines/vn/procedures/prepareTicketList.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`prepareTicketList`(vStartingDate DATETIME, vEndingDate DATETIME) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket; + CREATE TEMPORARY TABLE tmp.productionTicket + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, t.clientFk + FROM vn.ticket t + LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.client c ON c.id = t.clientFk + WHERE c.typeFk IN ('normal','handMaking','internalUse') + AND ( + t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate + OR ( + ts.alertLevel < 3 + AND t.shipped >= vStartingDate + AND t.shipped < util.VN_CURDATE() + ) + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/previousSticker_get.sql b/db/routines/vn/procedures/previousSticker_get.sql new file mode 100644 index 000000000..05f7de250 --- /dev/null +++ b/db/routines/vn/procedures/previousSticker_get.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`previousSticker_get`(vSaleGroupFk INT) +BEGIN +/** + * Devuelve los campos a imprimir en una etiqueta de preparación previa. + * Actualiza el valor de vn.saleGroup.parkingFk en el caso de que exista un + * saleGroup del mismo ticket con parking, del mismo sector, para que todos se + * pongan juntos. + * + * @param vSaleGroupFk Identificador de vn.saleGroup + */ + DECLARE vTicketFk INT; + DECLARE vParkingFk INT; + DECLARE vSectorFk INT; + + SELECT s.ticketFk + INTO vTicketFk + FROM vn.saleGroupDetail sgd + JOIN vn.sale s ON s.id = sgd.saleFk + WHERE sgd.saleGroupFk = vSaleGroupFk + LIMIT 1; + + SELECT sg.parkingFk, sc.sectorFk + INTO vParkingFk, vSectorFk + FROM vn.saleGroup sg + JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id + JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk + JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id + JOIN vn.sale s ON s.id = sgd.saleFk + WHERE s.ticketFk = vTicketFk + AND sg.parkingFk IS NOT NULL + LIMIT 1; + + UPDATE vn.saleGroup sg + SET sg.parkingFk = vParkingFk + WHERE sg.id = vSaleGroupFk + AND sg.sectorFk = vSectorFk; + + SELECT sgd.saleGroupFk, + t.id ticketFk, + p.code as location, + t.observations, + IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour, + IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute , + IFNULL(MAX(i.itemPackingTypeFk),'H') itemPackingTypeFk , + count(*) items, + sc.description sector + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk + JOIN vn.sector sc ON sc.id = sg.sectorFk + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.parking p ON p.id = sg.parkingFk + LEFT JOIN vn.`zone` z ON z.id = t.zoneFk + WHERE sgd.saleGroupFk = vSaleGroupFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/printer_checkSector.sql b/db/routines/vn/procedures/printer_checkSector.sql new file mode 100644 index 000000000..40728a81a --- /dev/null +++ b/db/routines/vn/procedures/printer_checkSector.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`printer_checkSector`(vLabelerFk tinyint(3) unsigned, vSector INT(11)) +BEGIN +/** + * Comprueba si la impresora pertenece al sector + * + * @param vLabelerFk id de la impresora + * @param vSector sector a comprobar + */ + DECLARE isPrinterInNewSector BOOL; + + IF vLabelerFk IS NOT NULL THEN + SELECT COUNT(sectorFK) INTO isPrinterInNewSector + FROM vn.printer p + WHERE id = vLabelerFk AND sectorFk = vSector; + + IF !isPrinterInNewSector THEN + CALL util.throw("PrinterNotInSameSector"); + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql new file mode 100644 index 000000000..51af98e0b --- /dev/null +++ b/db/routines/vn/procedures/productionControl.sql @@ -0,0 +1,263 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionControl`( + vWarehouseFk INT, + vScopeDays INT +) +proc: BEGIN +/** + * Devuelve un listado de tickets con parámetros relativos a la producción de los días en rango. + * + * @param vWarehouseFk Identificador de warehouse + * @param vScopeDays Número de días desde hoy en adelante que entran en el cálculo. + * + * @return Table tmp.productionBuffer + */ + DECLARE vEndingDate DATETIME; + DECLARE vIsTodayRelative BOOLEAN; + + SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY + INTO vEndingDate + FROM productionConfig; + + SELECT isTodayRelative INTO vIsTodayRelative + FROM worker + WHERE id = getUser(); -- Cambiar por account.myUser_getId(), falta dar permisos + + CALL prepareTicketList(util.yesterday(), vEndingDate); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + SELECT * FROM tmp.productionTicket; + + CALL prepareClientList(); + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems + (INDEX (ticketFk)) ENGINE = MEMORY + SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped + FROM tmp.productionTicket tt + JOIN ticket t ON t.id = tt.ticketFk; + + CALL ticket_getProblems(vIsTodayRelative); + + CREATE OR REPLACE TEMPORARY TABLE tmp.productionBuffer + (PRIMARY KEY(ticketFk), previaParking VARCHAR(255)) + ENGINE = MEMORY + SELECT tt.ticketFk, + tt.clientFk, + t.warehouseFk, + t.nickname, + t.packages, + IF(HOUR(t.shipped), HOUR(t.shipped), COALESCE(HOUR(zc.hour),HOUR(z.hour))) HH, + COALESCE(HOUR(zc.hour), HOUR(z.hour)) Departure, + COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) mm, + t.routeFk, + IF(dm.code = 'DELIVERY', z.`id`, 0) zona, + t.nickname addressNickname, + a.postalCode, + a.city, + p.name province, + CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency, + am.id agencyModeFk, + 0 `lines`, + CAST( 0 AS DECIMAL(5,2)) m3, + CAST( 0 AS DECIMAL(5,2)) preparationRate, + "" problem, + IFNULL(tls.state,2) state, + w.code workerCode, + DATE(t.shipped) shipped, + wk.code salesPersonCode, + p.id provinceFk, + tls.productionOrder, + IFNULL(tls.alertLevel, 0) alertLevel, + t.isBoxed palletized, + IF(rm.isPickingAllowed, rm.bufferFk, NULL) ubicacion, + tlu.lastUpdated, + IFNULL(st.graphCategory, 0) graphCategory, + pk.code parking, + 0 H, + 0 V, + 0 N, + st.isOk, + ag.isOwn, + rm.bufferFk + FROM tmp.productionTicket tt + JOIN ticket t ON tt.ticketFk = t.id + LEFT JOIN ticketStateToday tst ON tst.ticket = t.id + LEFT JOIN state st ON st.id = tst.state + LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN worker wk ON wk.id = c.salesPersonFk + JOIN address a ON a.id = t.addressFk + LEFT JOIN province p ON p.id = a.provinceFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN agency ag ON ag.id = am.agencyFk + LEFT JOIN ticketState tls ON tls.ticketFk = tt.ticketFk + LEFT JOIN ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk + LEFT JOIN worker w ON w.id = tls.userFk + LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + AND DATE(t.shipped) = zc.dated + LEFT JOIN ticketParking tp ON tp.ticketFk = t.id + LEFT JOIN parking pk ON pk.id = tp.parkingFk + WHERE t.warehouseFk = vWarehouseFk + AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); + + UPDATE tmp.productionBuffer pb + JOIN ( + SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking + FROM tmp.productionBuffer pb + JOIN sale s ON s.ticketFk = pb.ticketFk + JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN saleGroup sg ON sg.id = sgd.saleGroupFk + JOIN parking p ON p.id = sg.parkingFk + GROUP BY pb.ticketFk + ) t ON t.ticketFk = pb.ticketFk + SET pb.previaParking = t.previaParking; + + -- Problemas por ticket + ALTER TABLE tmp.productionBuffer + CHANGE COLUMN `problem` `problem` VARCHAR(255), + ADD COLUMN `collectionH` INT, + ADD COLUMN `collectionV` INT, + ADD COLUMN `collectionN` INT; + + UPDATE tmp.productionBuffer pb + JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk + SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage, ''), + IFNULL(tp.itemDelay, ''), + IFNULL(tp.itemLost, ''), + IF(tp.isFreezed, ' CONGELADO',''), + IF(tp.hasHighRisk, ' RIESGO',''), + IF(tp.hasTicketRequest, ' COD 100',''), + IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), + IF(tp.hasComponentLack, ' COMPONENTES', ''), + IF(HOUR(util.VN_NOW()) < pb.HH AND tp.isTooLittle, ' PEQUEÑO', '') + ) AS char(255))); + + -- Clientes Nuevos o Recuperados + UPDATE tmp.productionBuffer pb + LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk + JOIN productionConfig pc + SET pb.problem = TRIM(CAST(CONCAT('NUEVO ', pb.problem) AS CHAR(255))) + WHERE (cnb.clientFk IS NULL OR cnb.isRookie) + AND pc.rookieDays; + + -- Líneas y volumen por ticket + UPDATE tmp.productionBuffer pb + JOIN ( + SELECT tt.ticketFk, + COUNT(*) `lines`, + SUM(sv.volume) m3, + IFNULL(SUM(IF(sv.isPicked, sv.volume, 0)) / SUM(sv.volume), 0) rate + FROM tmp.productionTicket tt + JOIN saleVolume sv ON sv.ticketFk = tt.ticketFk + GROUP BY tt.ticketFk + ) m ON m.ticketFk = pb.ticketFk + SET pb.`lines` = m.`lines`, + pb.m3 = m.m3, + pb.preparationRate = m.rate; + + DELETE FROM tmp.productionBuffer + WHERE NOT `lines`; + + -- Lineas por linea de encajado + UPDATE tmp.productionBuffer pb + JOIN ( + SELECT ticketFk, + SUM(sub.H) H, + SUM(sub.V) V, + SUM(sub.N) N + FROM ( + SELECT t.ticketFk, + SUM(i.itemPackingTypeFk = 'H') H, + SUM(i.itemPackingTypeFk = 'V') V, + SUM(i.itemPackingTypeFk IS NULL) N + FROM tmp.productionTicket t + JOIN sale s ON s.ticketFk = t.ticketFk + JOIN item i ON i.id = s.itemFk + GROUP BY t.ticketFk, i.itemPackingTypeFk + ) sub + GROUP BY ticketFk + ) sub2 ON sub2.ticketFk = pb.ticketFk + SET pb.H = sub2.H, + pb.V = sub2.V, + pb.N = sub2.N; + + -- Colecciones segun tipo de encajado + UPDATE tmp.productionBuffer pb + JOIN ticketCollection tc ON pb.ticketFk = tc.ticketFk + SET pb.collectionH = IF(pb.H, tc.collectionFk, NULL), + pb.collectionV = IF(pb.V, tc.collectionFk, NULL), + pb.collectionN = IF(pb.N, tc.collectionFk, NULL); + + -- Previa pendiente + ALTER TABLE tmp.productionBuffer + ADD previousWithoutParking BOOL DEFAULT FALSE; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketWithPrevia + (ticketFk INT PRIMARY KEY, + salesCount INT DEFAULT 0, + salesInParkingCount INT DEFAULT 0) + ENGINE = MEMORY; + + -- Insertamos todos los tickets que tienen productos parkineados + -- en sectores de previa, segun el sector + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock + (PRIMARY KEY(itemFk, sectorFk)) + ENGINE = MEMORY + SELECT ish.itemFk, + p.sectorFk, + st.description = 'previousPrepared' isPreviousPrepared, + sc.itemPackingTypeFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector sc ON sc.id = p.sectorFk + JOIN sectorType st ON st.id = sc.typeFk + WHERE p.sectorFk + AND ish.visible + GROUP BY ish.itemFk, p.sectorFk; + + INSERT INTO tmp.ticketWithPrevia(ticketFk, salesCount) + SELECT pb.ticketFk, COUNT(DISTINCT s.id) + FROM tmp.productionBuffer pb + JOIN sale s ON s.ticketFk = pb.ticketFk + JOIN tItemShelvingStock iss ON iss.itemFk = s.itemFk + JOIN sector sc ON sc.id = iss.sectorFk + JOIN item i ON i.id = iss.itemFk + WHERE iss.isPreviousPrepared + AND (sc.itemPackingTypeFk IS NULL + OR (i.itemPackingTypeFk IS NULL AND NOT pb.V) + OR sc.itemPackingTypeFk = i.itemPackingTypeFk) + AND s.quantity > 0 + GROUP BY pb.ticketFk; + + -- Se calcula la cantidad de productos que estan ya preparados porque su saleGroup está aparcado + UPDATE tmp.ticketWithPrevia twp + JOIN ( + SELECT pb.ticketFk, COUNT(DISTINCT s.id) salesInParkingCount + FROM tmp.productionBuffer pb + JOIN sale s ON s.ticketFk = pb.ticketFk + JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN saleGroup sg ON sg.id = sgd.saleGroupFk + WHERE sg.parkingFk IS NOT NULL + AND s.quantity > 0 + GROUP BY pb.ticketFk + ) sub ON twp.ticketFk = sub.ticketFk + SET twp.salesInParkingCount = sub.salesInParkingCount; + + -- Marcamos como pendientes aquellos que no coinciden las cantidades + UPDATE tmp.productionBuffer pb + JOIN tmp.ticketWithPrevia twp ON twp.ticketFk = pb.ticketFk + SET pb.previousWithoutParking = TRUE + WHERE twp.salesCount > twp.salesInParkingCount; + + DROP TEMPORARY TABLE + tmp.productionTicket, + tmp.ticket, + tmp.risk, + tmp.ticket_problems, + tmp.ticketWithPrevia, + tItemShelvingStock; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/productionError_add.sql b/db/routines/vn/procedures/productionError_add.sql new file mode 100644 index 000000000..5e0ce93f0 --- /dev/null +++ b/db/routines/vn/procedures/productionError_add.sql @@ -0,0 +1,158 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionError_add`() +BEGIN + DECLARE vDatedFrom DATETIME; + DECLARE vDatedTo DATETIME; +/** + * Rellena la tabla vn.productionError con estadisticas de encajadores, revisores y sacadores. Se ejecuta en el nightTask + */ + SELECT util.VN_CURDATE() - INTERVAL 1 DAY, util.dayend(util.VN_CURDATE() - INTERVAL 1 DAY) INTO vDatedFrom, vDatedTo; + CALL timeControl_calculateAll(vDatedFrom, vDatedTo); + + -- Rellena la tabla tmp.errorsByClaim con encajadores, revisores y sacadores + CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByClaim + ENGINE = MEMORY + SELECT COUNT(c.ticketFk) errors, + cd.workerFk + FROM claimDevelopment cd + JOIN claim c ON cd.claimFk = c.id + JOIN ticket t ON c.ticketFk = t.id + JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + AND cr.code IN ('pic', 'chk', 'pck') + GROUP BY cd.workerFk; + + -- Genera la tabla tmp.volume con encajadores, sacadores y revisores + CREATE OR REPLACE TEMPORARY TABLE tmp.volume + ENGINE = MEMORY + SELECT SUM(w.volume) volume, + w.workerFk + FROM bs.workerProductivity w + WHERE w.dated BETWEEN vDatedFrom AND vDatedTo + GROUP BY w.workerFk; + + -- Rellena la tabla tmp.errorsByChecker con fallos de revisores + CREATE OR REPLACE TEMPORARY TABLE tmp.errorsByChecker + ENGINE = MEMORY + SELECT st.workerFk, + COUNT(t.id) errors + FROM saleMistake sm + JOIN saleTracking st ON sm.saleFk = st.saleFk + JOIN `state` s2 ON s2.id = st.stateFk + JOIN sale s ON s.id = sm.saleFk + JOIN ticket t on t.id = s.ticketFk + WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) + AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') + GROUP BY st.workerFk; + + -- Rellena la tabla tmp.expeditionErrors con fallos de expediciones + CREATE OR REPLACE TEMPORARY TABLE tmp.expeditionErrors + ENGINE = MEMORY + SELECT COUNT(t.id) errors, + e.workerFk + FROM vn.expeditionMistake pm + JOIN vn.expedition e ON e.id = pm.expeditionFk + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + GROUP BY e.workerFk; + + -- Genera la tabla tmp.total para sacadores y revisores + CREATE OR REPLACE TEMPORARY TABLE tmp.total + ENGINE = MEMORY + SELECT st.workerFk, + COUNT(DISTINCT t.id) ticketCount, + COUNT(s.id) lineCount + FROM saleTracking st + JOIN `state` s2 ON s2.id = st.stateFk + JOIN sale s ON s.id = st.saleFk + JOIN ticket t ON s.ticketFk = t.id + WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) + AND s2.code IN ('OK','PREVIOUS_PREPARATION','PREPARED','CHECKED') + GROUP BY st.workerFk; + + -- Rellena la tabla vn.productionError con sacadores + INSERT INTO productionError(userFk, + firstname, + lastname, + rol, + ticketNumber, + lineNumber, + error, + volume, + hourStart, + hourEnd, + hourWorked, + dated) + SELECT w.id, + w.firstName, + w.lastName, + "Sacadores", + t.ticketCount totalTickets, + t.lineCount, + IFNULL(ec.errors,0) + IFNULL(ec2.errors,0) errors, + v.volume volume, + SUBSTRING(tc.tableTimed, 1, 5) hourStart, + SUBSTRING(tc.tableTimed, LENGTH(tc.tableTimed)-4, 5) hourEnd, + IFNULL(CAST(tc.timeWorkDecimal AS DECIMAL (10,2)) , 0) hourWorked, + vDatedFrom dated + FROM tmp.total t + LEFT JOIN worker w ON w.id = t.workerFk + LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = t.workerFk + LEFT JOIN tmp.errorsByClaim ec ON ec.workerFk = t.workerFk + LEFT JOIN tmp.volume v ON v.workerFk = t.workerFk + LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = t.workerFk + JOIN (SELECT DISTINCT w.id -- Verificamos que son sacadores + FROM vn.collection c + JOIN vn.state s ON s.id = c.stateFk + JOIN vn.train tn ON tn.id = c.trainFk + JOIN vn.worker w ON w.id = c.workerFk + WHERE c.created BETWEEN vDatedFrom AND vDatedTo) sub ON sub.id = w.id + GROUP BY w.id; + + CREATE OR REPLACE TEMPORARY TABLE itemPickerErrors -- Errores de los sacadores, derivadores de los revisadores + ENGINE = MEMORY + SELECT COUNT(c.ticketFk) errors, + tt.userFk + FROM claimDevelopment cd + JOIN claim c ON cd.claimFk = c.id + JOIN ticket t ON c.ticketFk = t.id + JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id + JOIN ticketTracking tt ON tt.ticketFk = t.id + JOIN `state` s ON s.id = tt.stateFk + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + AND cr.code = 'chk' + AND s.code = 'ON_PREPARATION' + GROUP BY tt.userFk; + + UPDATE productionError ep + JOIN itemPickerErrors ipe ON ipe.userFk = ep.userFk + SET ep.error = ep.error + ipe.errors + WHERE vDatedFrom = ep.dated AND ep.rol = 'Sacadores'; + + DROP TEMPORARY TABLE itemPickerErrors; + + -- Rellena la tabla vn.productionError con revisores + CALL productionError_addCheckerPackager(vDatedFrom, vDatedTo, "Revisadores"); + + -- Genera la tabla tmp.total para encajadores + CREATE OR REPLACE TEMPORARY TABLE tmp.total + ENGINE = MEMORY + SELECT e.workerFk, + COUNT(DISTINCT t.id) ticketCount, + COUNT(s.id) lineCount + FROM expedition e + JOIN ticket t ON e.ticketFk = t.id + JOIN sale s ON s.ticketFk = t.id + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + GROUP BY e.workerFk; + + -- Rellena la tabla vn.productionError con encajadores + CALL productionError_addCheckerPackager(vDatedFrom, vDatedTo, "Encajadores"); + + DROP TEMPORARY TABLE tmp.errorsByClaim, + tmp.volume, + tmp.errorsByChecker, + tmp.expeditionErrors, + tmp.total; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/productionError_addCheckerPackager.sql b/db/routines/vn/procedures/productionError_addCheckerPackager.sql new file mode 100644 index 000000000..dd75f797b --- /dev/null +++ b/db/routines/vn/procedures/productionError_addCheckerPackager.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionError_addCheckerPackager`( + vDatedFrom DATETIME, + vDatedTo DATETIME, + vRol VARCHAR(50)) +BEGIN +/** + * Rellena la tabla vn.productionError con rol + * + * @param vDatedFrom Fecha desde + * @param vDatedTo Fecha hasta + * @param vRol rol a insertar + */ + INSERT INTO productionError(userFk, + firstname, + lastname, + rol, + ticketNumber, + lineNumber, + error, + volume, + hourStart, + hourEnd, + hourWorked, + dated) + SELECT w.id, + w.firstName, + w.lastName, + vRol, + t.ticketCount totalTickets, + t.lineCount, + IFNULL(ec.errors,0) + IFNULL(ec2.errors,0) + IFNULL(pe.errors,0) errors, + NULL volume, + SUBSTRING(tc.tableTimed, 1, 5) hourStart, + SUBSTRING(tc.tableTimed, LENGTH(tc.tableTimed)-4, 5) hourEnd, + IFNULL(CAST(tc.timeWorkDecimal AS DECIMAL (10,2)) , 0) hourWorked, + vDatedFrom dated + FROM tmp.total t + LEFT JOIN worker w ON w.id = t.workerFk + LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = t.workerFk + LEFT JOIN tmp.errorsByClaim ec ON ec.workerFk = t.workerFk + LEFT JOIN tmp.volume v ON v.workerFk = t.workerFk + LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = t.workerFk + LEFT JOIN tmp.expeditionErrors pe ON pe.workerFk = t.workerFk + GROUP BY w.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/productionSectorList.sql b/db/routines/vn/procedures/productionSectorList.sql new file mode 100644 index 000000000..ea047b376 --- /dev/null +++ b/db/routines/vn/procedures/productionSectorList.sql @@ -0,0 +1,108 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionSectorList`(vSectorFk INT) +BEGIN +/** + * Devuelve el listado de sale que se puede preparar en previa para ese sector + * + * @param vSectorFk Identificador de sector + */ + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM sector + WHERE id = vSectorFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.whiteTicket; + CREATE TEMPORARY TABLE tmp.whiteTicket + (ticketFk INT PRIMARY KEY) + SELECT s.ticketFk , count(*) AS saleNum, sum(ISNULL(i.itemPackingTypeFk)) iptNull + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, util.VN_CURDATE()) + GROUP BY s.ticketFk + HAVING saleNum = iptNull; + + DROP TEMPORARY TABLE IF EXISTS tmp.sectorTypeTicket; + CREATE TEMPORARY TABLE tmp.sectorTypeTicket + (ticketFk INT PRIMARY KEY) + SELECT s.ticketFk , sum(i.itemPackingTypeFk <=> sc.itemPackingTypeFk) iptSector + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + JOIN sector sc ON sc.id = vSectorFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, util.VN_CURDATE()) + GROUP BY s.ticketFk + HAVING iptSector; + + CALL productionControl(vWarehouseFk, 0); + + SELECT 0,999999,0 INTO @sameTicket, @ticket, @litrosTicket; + + SELECT @litrosTicket := IF(sub.ticketFk = @ticket, @litrosTicket + Litros, Litros) as LitrosTicket, + @sameTicket := IF(sub.ticketFk = @ticket, @sameTicket, IF(@sameTicket, 0 , 1)) as sameTicket, + sub.*, + @ticket := ticketFk AS lastTicket + FROM ( + SELECT * FROM ( + SELECT isa.saleFk, + isa.Modificado, + isa.ticketFk, + isa.isPicked, + isa.itemFk, + isa.quantity, + isa.concept, + i.itemPackingTypeFk, + isa.`size`, + isa.Estado, + isa.sectorProdPriority, + isa.available, + isa.sectorFk, + isa.matricula, + isa.parking, + isa.itemShelving, + isa.Agency, + isa.shipped, + isa.`grouping`, + isa.packing, + isa.`hour`, + isa.isPreviousPreparable, + isa.physicalVolume, + isa.warehouseFk , + sum(isa.available) as totalAvailable, + IF (HOUR(isa.shipped),HOUR(isa.shipped), HOUR(isa.`hour`)) Hora, + IF (MINUTE(isa.shipped),MINUTE(isa.shipped), MINUTE(isa.`hour`)) Minuto, + i.subName, + CAST(isa.physicalVolume * 1000 AS DECIMAL(10,0)) as Litros + FROM itemShelvingAvailable isa + JOIN item i ON i.id = isa.itemFk + JOIN sector s ON s.id = isa.sectorFk AND s.warehouseFk = isa.warehouseFk + JOIN sectorType st ON st.id = s.typeFk + JOIN ticket t ON t.id = isa.ticketFk + LEFT JOIN tmp.whiteTicket wt ON wt.ticketFk = isa.ticketFk + LEFT JOIN tmp.sectorTypeTicket stt ON stt.ticketFk = isa.ticketFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = isa.saleFk + JOIN client c ON c.id = t.clientFk + JOIN tmp.productionBuffer pb ON pb.ticketFk = t.id + JOIN packagingConfig pc + WHERE IF(st.description = 'previousByPacking', + i.`size` > pc.previousPreparationMinimumSize + AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), + TRUE) + AND sgd.saleFk IS NULL + AND isa.sectorFk = vSectorFk + AND isa.quantity > 0 + AND pb.problem = "" + AND (i.itemPackingTypeFk <=> s.itemPackingTypeFk + OR ISNULL(s.itemPackingTypeFk) + OR wt.ticketFk + OR (stt.ticketFk AND ISNULL(i.itemPackingTypeFk))) + GROUP BY saleFk + HAVING isa.quantity <= totalAvailable + ) sub2 + ORDER BY Hora, Minuto, ticketFk LIMIT 10000000000000000000 + ) sub; + DROP TEMPORARY TABLE tmp.whiteTicket; + DROP TEMPORARY TABLE tmp.sectorTypeTicket; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/rangeDateInfo.sql b/db/routines/vn/procedures/rangeDateInfo.sql new file mode 100644 index 000000000..502248686 --- /dev/null +++ b/db/routines/vn/procedures/rangeDateInfo.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rangeDateInfo`(vStarted DATE, vEnded DATE) +BEGIN +/** + * Crea una tabla temporal con las fechas + * desde una fecha inicial a una final + * @param vStarted fecha inicial + * @param vEnded fecha final + */ + DECLARE vDated DATE DEFAULT vStarted; + + DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate; + CREATE TEMPORARY TABLE tmp.rangeDate( + `dated` DATE, + `period` INT, + `month` INT, + `year` INT, + `day` INT, + `week` INT, + `yearMonth` INT + ) + ENGINE = MEMORY; + + WHILE vDated <= vEnded DO + INSERT INTO tmp.rangeDate + SET `dated` = vDated, + `period` = YEAR(vDated) * 100 + WEEK(vDated, 1), + `month` = MONTH(vDated), + `year` = YEAR(vDated), + `day` = DAY(vDated), + `week` = WEEK(vDated, 1), + `yearMonth` = YEAR(vDated) * 100 + MONTH(vDated); + + SET vDated = DATE_ADD(vDated, INTERVAL 1 DAY); + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/rate_getPrices.sql b/db/routines/vn/procedures/rate_getPrices.sql new file mode 100644 index 000000000..c82ad918e --- /dev/null +++ b/db/routines/vn/procedures/rate_getPrices.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rate_getPrices`( + vDated DATE, + vWarehouseFk INT +) +BEGIN +/** + * Prepara una tabla con las tarifas aplicables + * en funcion de la fecha y el almacén. + * + * @param vDated Fecha para la cual calcula la tarifa + * @param vWarehouseFk Warehouse para el cual calcula la tarifa + * @return tmp.rate (rate0, rate1, rate2, rate3) + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.rate + ENGINE = MEMORY + SELECT rate0, + rate1, + rate2, + rate3 + FROM( + (SELECT 1 `order`, + rate0, + rate1, + rate2, + rate3 + FROM rate + WHERE dated <= vDated + AND warehouseFk = vWarehouseFk + ORDER BY dated DESC + LIMIT 1 + ) + UNION + (SELECT 2, + rate0, + rate1, + rate2, + rate3 + FROM rateConfig + ) + ORDER BY `order` ASC + LIMIT 1 + )sub; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/recipe_Cook.sql b/db/routines/vn/procedures/recipe_Cook.sql new file mode 100644 index 000000000..9371ef820 --- /dev/null +++ b/db/routines/vn/procedures/recipe_Cook.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`recipe_Cook`(vItemFk INT, vBunchesQuantity INT, vDate DATE) +BEGIN + + DECLARE vCalc INT; + DECLARE vWarehouseFk INT DEFAULT 1; -- Silla FV + + SET @element := ''; + SET @counter := 0; + + CALL cache.available_refresh(vCalc, FALSE, vWarehouseFk, vDate); + + DROP TEMPORARY TABLE IF EXISTS tmp.recipeCook; + + CREATE TEMPORARY TABLE tmp.recipeCook + SELECT *, + @counter := IF(@element = element COLLATE utf8_general_ci , @counter + 1, 1) as counter, + @element := element COLLATE utf8_general_ci + FROM + ( + SELECT i.id itemFk, + CONCAT(i.longName, ' (ref: ',i.id,')') longName, + i.size, + i.inkFk, + a.available, + r.element, + vBunchesQuantity * r.quantity as quantity, + r.itemFk as bunchItemFk, + IFNULL((i.inkFk = r.inkFk ) ,0) + + IFNULL((i.size = r.size) ,0) + + IFNULL((i.name LIKE CONCAT('%',r.name,'%')) ,0) + + IFNULL((i.longName LIKE CONCAT('%',r.longName,'%')),0) + + IFNULL((i.typeFk = r.typeFk),0) as matches, + i.typeFk, + rl.previousSelected + FROM vn.recipe r + JOIN vn.item i ON (IFNULL(i.name LIKE CONCAT('%',r.name,'%'), 0) + OR IFNULL(i.longName LIKE CONCAT('%',r.longName,'%'),0)) + OR i.typeFk <=> r.typeFk + JOIN cache.available a ON a.item_id = i.id AND a.calc_id = vCalc + LEFT JOIN (SELECT recipe_ItemFk, element as log_element, selected_ItemFk, count(*) as previousSelected + FROM vn.recipe_log + GROUP BY recipe_ItemFk, element, selected_ItemFk) rl ON rl.recipe_ItemFk = r.itemFk + AND rl.log_element = r.element + AND rl.selected_ItemFk = i.id + WHERE r.itemFk = vItemFk + AND a.available > vBunchesQuantity * r.quantity + UNION ALL + SELECT 100 itemFk, + CONCAT('? ',r.element,' ',IFNULL(r.size,''),' ',IFNULL(r.inkFk,'')) as longName, + NULL, + NULL, + 0, + r.element, + vBunchesQuantity * r.quantity as quantity, + r.itemFk as bunchItemFk, + -1 as matches, + r.typeFk, + NULL + FROM vn.recipe r + WHERE r.itemFk = vItemFk + GROUP BY r.element + ) sub + + ORDER BY element, matches DESC, previousSelected DESC; + + SELECT * + FROM tmp.recipeCook + WHERE counter < 6 + OR itemFk = 100 + ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/recipe_Plaster.sql b/db/routines/vn/procedures/recipe_Plaster.sql new file mode 100644 index 000000000..65e2ab473 --- /dev/null +++ b/db/routines/vn/procedures/recipe_Plaster.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`recipe_Plaster`(vItemFk INT, vTicketFk INT, vQuantity INT) +BEGIN + + DECLARE vLastCost DECIMAL(10,2); + DECLARE vWarehouseFk INT; + DECLARE vShipped DATE; + DECLARE vEntryFk INT; + DECLARE vTravelFk INT; + + CALL cache.last_buy_refresh(FALSE); + + SELECT warehouseFk, shipped + INTO vWarehouseFk, vShipped + FROM vn.ticket + WHERE id = vTicketFk; + + UPDATE vn.ticket t + JOIN vn.item i ON i.id = vItemFk + SET t.nickname = CONCAT(vQuantity,' ',i.longName) + WHERE t.id = vTicketFk; + + SELECT b.buyingValue INTO vLastCost + FROM vn.buy b + JOIN cache.last_buy lb ON lb.buy_id = b.id + WHERE lb.item_id = vItemFk + ORDER BY (lb.warehouse_id = vWarehouseFk) DESC + LIMIT 1; + + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) + SELECT vTicketFk, 98, - vQuantity, i.longName, vLastCost + FROM vn.item i + WHERE i.id = vItemFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/reportLabelCollection_get.sql b/db/routines/vn/procedures/reportLabelCollection_get.sql new file mode 100644 index 000000000..6ad5ae964 --- /dev/null +++ b/db/routines/vn/procedures/reportLabelCollection_get.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`reportLabelCollection_get`( + vParam INT, + vLabelCount INT +) +BEGIN +/** + * Obtains tag data from a ticket or collection. + * + * @param vParam Ticket/Collection from which data is to be taken. + * @param vLabelCount number of times the collection has been printed. + */ + DECLARE vIsCollection BOOL; + + SELECT IF(id, TRUE, FALSE) INTO vIsCollection + FROM vn.collection c + WHERE id = vParam; + + SELECT c.itemPackingTypeFk, + CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color, + CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.level) levelV, + tc.ticketFk, + LEFT(COALESCE(et.description, zo.name, am.name),12) agencyDescription, + am.name, + t.clientFk, + CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 , + CAST(IF(ic.code = 'plant', CONCAT(MAX(i.size), ' cm'), COUNT(*)) AS CHAR) size, + w.code workerCode, + IF(vLabelCount IS NULL, tt.labelCount, vLabelCount) labelCount, + IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.hour)) agencyHour, + t.shipped, + COUNT(*) lineCount, + t.nickName + FROM ticket t + JOIN ticketCollection tc ON tc.ticketFk = t.id + JOIN collection c ON c.id = tc.collectionFk + LEFT JOIN collectionColors cc ON cc.shelve = tc.level + AND cc.wagon = tc.wagon + AND cc.trainFk = c.trainFk + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleVolume sv ON sv.saleFk = s.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN worker w ON w.id = c.workerFk + JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN ticketTrolley tt ON tt.ticket = t.id + LEFT JOIN zone zo ON t.zoneFk = zo.id + LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN expeditionTruck et ON et.id = rm.expeditionTruckFk + WHERE IF(vIsCollection, tc.collectionFk = vParam, tc.ticketFk = vParam) + GROUP BY t.id + ORDER BY cc.code; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/report_print.sql b/db/routines/vn/procedures/report_print.sql new file mode 100644 index 000000000..5d399dedf --- /dev/null +++ b/db/routines/vn/procedures/report_print.sql @@ -0,0 +1,83 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`report_print`( + vReportName VARCHAR(100), + vPrinterFk INT, + vUserFk INT, + vParams JSON, + vPriorityName VARCHAR(100) + ) +BEGIN +/** + * Inserts in the print queue the report to be printed and the necessary parameters for this + * one taking into account the paper size of both the printer and the report. + * + * @param vReportName the report to be printed. + * @param vPrinterFk the printer selected. + * @param vUserFk user id. + * @param vParams JSON with report parameters. + * @param vPriorityName the printing priority. + */ + DECLARE vI INT DEFAULT 0; + DECLARE vKeys TEXT DEFAULT JSON_KEYS(vParams); + DECLARE vLength INT DEFAULT JSON_LENGTH(vKeys); + DECLARE vKey VARCHAR(255); + DECLARE vVal VARCHAR(255); + DECLARE vPrintQueueFk INT; + DECLARE vReportSize VARCHAR(255); + DECLARE vIsThePrinterReal INT; + DECLARE vPrinteSize VARCHAR(255); + DECLARE vPriorityFk INT; + DECLARE vReportFk INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT id, paperSizeFk INTO vReportFk, vReportSize + FROM report + WHERE name = vReportName; + + SELECT id, paperSizeFk INTO vIsThePrinterReal, vPrinteSize + FROM printer + WHERE id = vPrinterFk; + + SELECT id INTO vPriorityFk + FROM queuePriority + WHERE code = vPriorityName; + + IF vIsThePrinterReal IS NULL THEN + CALL util.throw('printerNotExists'); + END IF; + + IF vReportFk IS NULL THEN + CALL util.throw('reportNotExists'); + END IF; + + IF vReportSize <> vPrinteSize THEN + CALL util.throw('incorrectSize'); + END IF; + + START TRANSACTION; + INSERT INTO printQueue + SET printerFk = vPrinterFk, + priorityFk = vPriorityFk, + reportFk = vReportFk, + workerFk = vUserFk; + + SET vPrintQueueFk = LAST_INSERT_ID(); + + WHILE vI < vLength DO + SET vKey = JSON_VALUE(vKeys, CONCAT('$[', vI ,']')); + SET vVal = JSON_VALUE(vParams, CONCAT('$.', vKey)); + + INSERT INTO printQueueArgs + SET printQueueFk = vPrintQueueFk, + name = vKey, + value = vVal; + + SET vI = vI + 1; + END WHILE; + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/riskAllClients.sql b/db/routines/vn/procedures/riskAllClients.sql new file mode 100644 index 000000000..66c0a0dd5 --- /dev/null +++ b/db/routines/vn/procedures/riskAllClients.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`riskAllClients`(maxRiskDate DATE) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT id Id_Cliente, null grade FROM vn.client; + + CALL vn2008.risk_vs_client_list(maxRiskDate); + + SELECT + c.RazonSocial, + c.Id_Cliente, + c.Credito, + CAST(r.risk as DECIMAL (10,2)) risk, + CAST(c.Credito - r.risk as DECIMAL (10,2)) Diferencia, + c.Id_Pais + FROM + vn2008.Clientes c + JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente + JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente + GROUP BY c.Id_cliente; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/routeGuessPriority.sql b/db/routines/vn/procedures/routeGuessPriority.sql new file mode 100644 index 000000000..7208fcbcf --- /dev/null +++ b/db/routines/vn/procedures/routeGuessPriority.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`routeGuessPriority`(IN vRuta INT) +BEGIN +/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta + * vRuta id ruta +*/ + +UPDATE ticket mt + JOIN ( + SELECT tt.addressFk, ROUND(IFNULL(AVG(t.priority),0),0) AS priority + FROM ticket t + JOIN ticket tt ON tt.addressFk = t.addressFk + WHERE t.shipped > TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) + AND tt.routeFk = vRuta + GROUP BY addressFk + ) sub ON sub.addressFk = mt.addressFk + SET mt.priority = sub.priority + WHERE mt.routeFk = vRuta; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/routeInfo.sql b/db/routines/vn/procedures/routeInfo.sql new file mode 100644 index 000000000..1f25b1429 --- /dev/null +++ b/db/routines/vn/procedures/routeInfo.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`routeInfo`(vRouteFk INT) +BEGIN + + DECLARE vPackages INT; + DECLARE vM3 INT; + DECLARE vKg INT; + DECLARE vMatricula varchar(50); + + SELECT sum(packages) as bultos + INTO vPackages + FROM vn.ticket t + WHERE routeFk = vRouteFk; + + SELECT SUM(sv.physicalVolume), SUM(sv.physicalWeight) + INTO vM3, vKg + FROM vn.saleVolume sv + WHERE sv.routeFk = vRouteFk; + + SELECT v.numberPlate as matricula + INTO vMatricula + FROM vn.route r + JOIN vn.vehicle v ON r.vehicleFk = v.id + WHERE r.id = vRouteFk; + + SELECT vRouteFk as Ruta, + vPackages as Bultos, + vM3 as m3, + vKg as Kg, + vMatricula as Matricula; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/routeMonitor_calculate.sql b/db/routines/vn/procedures/routeMonitor_calculate.sql new file mode 100644 index 000000000..af7f5297e --- /dev/null +++ b/db/routines/vn/procedures/routeMonitor_calculate.sql @@ -0,0 +1,114 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`routeMonitor_calculate`( + vDate DATE, + vDaysAgo INT +) +BEGIN + DECLARE vDateEnd DATETIME; + SET vDate = vDate - INTERVAL vDaysAgo DAY; + SET vDateEnd = util.dayend(vDate); + + CREATE OR REPLACE TEMPORARY TABLE tmp.routesMonitor + (INDEX (routeFk)) + ENGINE = MEMORY + SELECT DISTINCT(t.routeFk) routeFk + FROM vn.ticket t + WHERE t.shipped BETWEEN vDate AND vDateEnd + AND t.routeFk IS NOT NULL; + + INSERT IGNORE INTO routesMonitor(routeFk) + SELECT routeFk + FROM tmp.routesMonitor; + + UPDATE routesMonitor rm + JOIN route r ON r.id = rm.routeFk + JOIN agencyMode a ON a.id = r.agencyModeFk + SET rm.`name` = a.name, + rm.ticketFree = 0, + rm.ticketProduction = 0, + rm.ticketPacked = 0, + rm.dated = r.created; + + UPDATE routesMonitor rm + JOIN ( + SELECT t.routeFk, COUNT(*) AS ticketFree + FROM vn.ticket t + JOIN tmp.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN ticketLastState ts ON t.id = ts.ticketFk + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state s ON s.id = tt.stateFk + JOIN vn.alertLevel al ON al.id = s.alertLevel + AND al.code = "FREE" + GROUP BY t.routeFk + ) sub ON sub.routeFk = rm.routeFk + SET rm.ticketFree = sub.ticketFree; + + UPDATE routesMonitor rm + JOIN( + SELECT t.routeFk, COUNT(*) AS ticketPacked + FROM vn.ticket t + JOIN tmp.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN ticketLastState ts ON t.id = ts.ticketFk + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state s ON s.id = tt.stateFk + JOIN vn.alertLevel al ON al.id = s.alertLevel + AND al.code = "PACKED" + GROUP BY t.routeFk + ) sub ON sub.routeFk = rm.routeFk + SET rm.ticketPacked = sub.ticketPacked; + + UPDATE routesMonitor rm + JOIN( + SELECT t.routeFk, COUNT(*) AS ticketProduction + FROM vn.ticket t + JOIN tmp.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN ticketLastState ts ON t.id = ts.ticketFk + JOIN ticketTracking tt ON tt.id = ts.ticketTrackingFk + JOIN state s ON s.id = tt.stateFk + JOIN vn.alertLevel al ON al.id = s.alertLevel + AND al.code = "DELIVERED" + GROUP BY t.routeFk + ) sub ON sub.routeFk = rm.routeFk + SET rm.ticketProduction = sub.ticketProduction; + + UPDATE routesMonitor rm + JOIN ( + SELECT t.routeFk, COUNT(*) packages + FROM vn.ticket t + JOIN tmp.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN expedition e ON e.ticketFk = t.id + GROUP BY t.routeFk + ) sub ON sub.routeFk = rm.routeFk + SET rm.packages = sub.packages; + + UPDATE routesMonitor rm + JOIN( SELECT t.routeFk, SUM(sv.volume) m3 + FROM vn.ticket t + JOIN tmp.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + GROUP BY t.routeFk + ) sub ON sub.routeFk = rm.routeFk + SET rm.m3 = sub.m3; + + UPDATE routesMonitor rm + JOIN ( + SELECT t.routeFk, + SUM(IFNULL(pk.volume, + pk.width * pk.height * pk.`depth` + ) + ) / 1000000 m3boxes + FROM vn.ticket t + JOIN tmp.routesMonitor rm ON rm.routeFk = t.routeFk + JOIN vn.expedition e ON e.ticketFk = t.id + JOIN vn.packaging pk ON pk.id = e.packagingFk + GROUP BY t.routeFk + ) sub ON sub.routeFk = rm.routeFk + SET rm.m3boxes = sub.m3boxes; + + UPDATE routesMonitor rm + JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + SET rm.etd = et.eta; + + DROP TEMPORARY TABLE tmp.routesMonitor; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/routeSetOk.sql b/db/routines/vn/procedures/routeSetOk.sql new file mode 100644 index 000000000..86b32fe7b --- /dev/null +++ b/db/routines/vn/procedures/routeSetOk.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`routeSetOk`( + vRouteFk INT) +BEGIN + + UPDATE vn.route r + SET r.isOk = 1 + WHERE r.id = vRouteFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/routeUpdateM3.sql b/db/routines/vn/procedures/routeUpdateM3.sql new file mode 100644 index 000000000..7dbf5a194 --- /dev/null +++ b/db/routines/vn/procedures/routeUpdateM3.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`routeUpdateM3`(vRoute INT) +BEGIN +/** + * @deprecated Use vn.route_updateM3() + */ + call route_updateM3(vRoute); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/route_calcCommission.sql b/db/routines/vn/procedures/route_calcCommission.sql new file mode 100644 index 000000000..63f702bee --- /dev/null +++ b/db/routines/vn/procedures/route_calcCommission.sql @@ -0,0 +1,94 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_calcCommission`( + vSelf INT +) +BEGIN +/** + * Calcula las comisión para una ruta y guarda los valores + * en la tabla vn.routeCommission. + * + * @param vSelf Id de ruta + */ + DECLARE vIsUpdatable, vIsFreelance BOOL DEFAULT 0; + DECLARE vAgencyModePricePercentage DOUBLE; + + SELECT r.created >= rc.cutoffDated INTO vIsUpdatable + FROM route r + JOIN routeConfig rc + WHERE r.id = vSelf; + + IF vIsUpdatable THEN + DELETE FROM routeCommission + WHERE routeFk = vSelf; + + SELECT w.isFreelance INTO vIsFreelance + FROM route r + JOIN worker w ON w.id = r.workerFk + WHERE r.id = vSelf; + + SELECT ampp.percentage INTO vAgencyModePricePercentage + FROM route r + JOIN agencyMode am ON am.id = r.agencyModeFk + JOIN agencyModePricePercentage ampp ON ampp.agencyModeFk = am.id + WHERE r.id = vSelf; + + -- Falta calcular el precio, a la espera de saber el/los campo/s exacto/s al que aplicarlo/s + IF vIsFreelance THEN + INSERT INTO routeCommission ( + routeFk, + workCenterFk, + freelanceYearlyM3, + cat4m3, + cat5m3 + ) + SELECT vSelf, + r.commissionWorkCenterFk, + IF(vAgencyModePricePercentage IS NOT NULL, + vAgencyModePricePercentage / 100, + rc.freelanceM3 + ) * + IF(IFNULL(r.m3, 0) >= rc.freelanceMinM3, + IFNULL(r.m3, 0), + 0 + ), + rc.distributionCat4M3 * IFNULL(r.m3, 0), + rc.distributionCat5M3 * IFNULL(r.m3, 0) + FROM route r + JOIN vehicle v ON v.id = r.vehicleFk + JOIN routeConfig rc + WHERE r.id = vSelf + AND r.workerFk + AND r.commissionWorkCenterFk; + ELSE + INSERT INTO routeCommission ( + routeFk, + workCenterFk, + km, + m3, + yearlyKm, + yearlyM3, + cat4m3, + cat5m3 + ) + SELECT vSelf, + r.commissionWorkCenterFk, + (r.kmEnd - r.kmStart) * + IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), + IFNULL(r.m3, 0) * + IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), + (r.kmEnd - r.kmStart) * rc.kmYearly, + IFNULL(r.m3, 0) * rc.m3Yearly, + rc.distributionCat4M3 * IFNULL(r.m3, 0), + rc.distributionCat5M3 * IFNULL(r.m3, 0) + FROM route r + JOIN vehicle v ON v.id = r.vehicleFk + JOIN routeConfig rc + WHERE r.id = vSelf + AND r.kmStart + AND r.kmEnd + AND r.workerFk + AND r.commissionWorkCenterFk; + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/route_doRecalc.sql b/db/routines/vn/procedures/route_doRecalc.sql new file mode 100644 index 000000000..365796f7e --- /dev/null +++ b/db/routines/vn/procedures/route_doRecalc.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_doRecalc`() +proc: BEGIN +/** + * Recalculates modified route. + */ + + DECLARE vDone BOOL; + DECLARE vRouteFk INT; + + DECLARE cCur CURSOR FOR + SELECT routeFk FROM routeRecalc; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.route_doRecalc'); + ROLLBACK; + RESIGNAL; + END; + + IF !GET_LOCK('vn.route_doRecalc', 0) THEN + LEAVE proc; + END IF; + + OPEN cCur; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cCur INTO vRouteFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + START TRANSACTION; + CALL route_updateM3(vRouteFk); + COMMIT; + + DELETE FROM routeRecalc WHERE routeFk = vRouteFk; + END LOOP; + + CLOSE cCur; + DO RELEASE_LOCK('vn.route_doRecalc'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/route_getTickets.sql b/db/routines/vn/procedures/route_getTickets.sql new file mode 100644 index 000000000..55b08208f --- /dev/null +++ b/db/routines/vn/procedures/route_getTickets.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_getTickets`(vRouteFk INT) +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * @select Información de los tickets + */ +SELECT t.id Id, + t.clientFk Client, + a.id Address, + a.nickname ClientName, + t.packages Packages, + a.street AddressName, + a.postalCode PostalCode, + a.city City, + sub3.itemPackingTypeFk PackingType, + c.phone ClientPhone, + c.mobile ClientMobile, + a.phone AddressPhone, + a.mobile AddressMobile, + d.longitude Longitude, + d.latitude Latitude, + wm.mediaValue SalePersonPhone, + tob.description Note, + t.isSigned Signed, + t.priority, + t.cmrFk + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN ( + SELECT t.addressFk, MAX(d.ticketFk) lastTicketFk + FROM ticket t + JOIN delivery d ON t.id = d.ticketFk + JOIN ticket ti ON ti.routeFk = vRouteFk + AND ti.id = t.id + AND ti.clientFk = t.clientFk + GROUP BY addressFk + )sub ON sub.addressFk = a.id + LEFT JOIN delivery d ON d.ticketFk = sub.lastTicketFk + LEFT JOIN( + SELECT t.id ticketFk, tob.description + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.ticketFk = t.id + LEFT JOIN( + SELECT sub2.ticketFk, + CONCAT('(', + GROUP_CONCAT(DISTINCT sub2.itemPackingTypeFk + ORDER BY sub2.items DESC SEPARATOR ','), + ') ') itemPackingTypeFk + FROM ( + SELECT s.ticketFk, i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id, i.itemPackingTypeFk + )sub2 + GROUP BY sub2.ticketFk + )sub3 ON sub3.ticketFk = t.id + WHERE t.routeFk = vRouteFk + ORDER BY priority, Id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/route_updateM3.sql b/db/routines/vn/procedures/route_updateM3.sql new file mode 100644 index 000000000..92d26b753 --- /dev/null +++ b/db/routines/vn/procedures/route_updateM3.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_updateM3`(vRoute INT) +BEGIN + + UPDATE vn.route r + LEFT JOIN ( + SELECT routeFk, SUM(volume) AS m3 + FROM saleVolume + WHERE routeFk = vRoute + ) v ON v.routeFk = r.id + SET r.m3 = IFNULL(v.m3,0) + WHERE r.id =vRoute; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleBuy_Add.sql b/db/routines/vn/procedures/saleBuy_Add.sql new file mode 100644 index 000000000..2f689ad2a --- /dev/null +++ b/db/routines/vn/procedures/saleBuy_Add.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleBuy_Add`(vSaleFk INT, vBuyFk INT) +BEGIN + + /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad + * + * @param vSaleFk clave primaria de vn.sale + * @param vBuyFk clave primaria de vn.buy + */ + /*IF (SELECT COUNT(*) + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE s.id = vSaleFk + AND ic.code = 'fruit') THEN */ + + IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN + + INSERT INTO vn.saleBuy (saleFk, buyFk) + VALUES(vSaleFk, vBuyFk); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleGroup_add.sql b/db/routines/vn/procedures/saleGroup_add.sql new file mode 100644 index 000000000..679b84025 --- /dev/null +++ b/db/routines/vn/procedures/saleGroup_add.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_add`(vSectorFk INT) +BEGIN +/** + * Añade un nuevo registro a la tabla y devuelve su id. + * + * @param vSectorFk Identificador de vn.sector + */ + INSERT INTO vn.saleGroup(userFk, sectorFk) + VALUES (account.myUser_getId(), vSectorFk); + + SELECT LAST_INSERT_ID(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleGroup_setParking.sql b/db/routines/vn/procedures/saleGroup_setParking.sql new file mode 100644 index 000000000..4872f74c6 --- /dev/null +++ b/db/routines/vn/procedures/saleGroup_setParking.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN +/** + * Aparca una preparación previa en un parking + * + * @param vSaleGroupFk id de la preparación previa + * @param vParkingFk id del parking + */ + UPDATE vn.saleGroup sg + SET sg.parkingFk = vParkingFk + WHERE sg.id = vSaleGroupFk + AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + + CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk)); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleMistake_Add.sql b/db/routines/vn/procedures/saleMistake_Add.sql new file mode 100644 index 000000000..cc174993e --- /dev/null +++ b/db/routines/vn/procedures/saleMistake_Add.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleMistake_Add`(vSaleFk INT, vUserFk INT, vTypeFk INT) +BEGIN + + INSERT INTO vn.saleMistake(saleFk, userFk, typeFk) + VALUES(vSaleFk, vUserFk, vTypeFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/salePreparingList.sql b/db/routines/vn/procedures/salePreparingList.sql new file mode 100644 index 000000000..ae3a267f3 --- /dev/null +++ b/db/routines/vn/procedures/salePreparingList.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`salePreparingList`(IN vTicketFk BIGINT) +BEGIN +/** + * Devuelve un listado con las lineas de vn.sale y los distintos estados de prepacion + * + * @param vTicketFk Identificador de vn.ticket + */ + CALL cache.last_buy_refresh(FALSE); + + SELECT t.clientFk, + t.shipped, + a.nickname, + s.ticketFk, + s.itemFk, + s.quantity, + s.concept, + s.reserved, + s.id saleFk, + i.size, + i.inkFk, + i.stems, + i.image, + i.subName, + b.`grouping`, + IF(stPrevious.saleFk,TRUE,FALSE) as isPreviousSelected, + stPrevious.isChecked as isPrevious, + stPrepared.isChecked as isPrepared, + stControled.isChecked as isControled, + ib.code as barcode, + (MAX(sgd.id) IS NOT NULL) AS hasSaleGroupDetail + FROM vn.ticket t + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = t.warehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.saleTracking stPrevious ON stPrevious.saleFk = s.id AND stPrevious.stateFk = 26 + LEFT JOIN vn.saleTracking stPrepared ON stPrepared.saleFk = s.id AND stPrepared.stateFk = 14 + LEFT JOIN vn.saleTracking stControled ON stControled.saleFk = s.id AND stControled.stateFk = 8 + LEFT JOIN vn.itemBarcode ib ON ib.itemFk = i.id + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + WHERE t.id = vTicketFk + GROUP BY s.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleSplit.sql b/db/routines/vn/procedures/saleSplit.sql new file mode 100644 index 000000000..dab78d811 --- /dev/null +++ b/db/routines/vn/procedures/saleSplit.sql @@ -0,0 +1,43 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleSplit`(vSaleFk INT, vQuantity INT) +BEGIN + + + DECLARE vNewSaleFk INT; + + INSERT INTO vn.sale(itemFk, + concept, + price, + discount, + quantity, + ticketFk, + isPriceFixed) + SELECT s.itemFk, + i.longName, + s.price, + s.discount, + vQuantity, + s.ticketFk, + s.isPriceFixed + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + WHERE s.id = vSaleFk; + + UPDATE vn.sale s + JOIN vn.item i ON i.id = s.itemFk + SET s.quantity = s.quantity - vQuantity, s.concept = i.longName + WHERE s.id = vSaleFk; + + SELECT LAST_INSERT_ID() INTO vNewSaleFk; + + INSERT INTO vn.saleComponent( saleFk, + componentFk, + value) + SELECT vNewSaleFk, + componentFk, + value + FROM vn.saleComponent + WHERE saleFk = vSaleFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_add.sql b/db/routines/vn/procedures/saleTracking_add.sql new file mode 100644 index 000000000..dc347b0e3 --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_add.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_add`(vSaleGroupFk INT) +BEGIN +/** Inserta en vn.saleTracking las lineas de una previa + * + * @param vSaleGroupFk Identificador de vn.saleGroup + */ + REPLACE vn.saleTracking( + saleFk, + isChecked, + workerFk, + stateFk + ) + SELECT sgd.saleFk , + TRUE, + account.myUser_getId(), + s.id + FROM vn.saleGroupDetail sgd + JOIN vn.state s ON s.code = 'ON_PREPARATION' + WHERE sgd.saleGroupFk = vSaleGroupFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_addPreparedSaleGroup.sql b/db/routines/vn/procedures/saleTracking_addPreparedSaleGroup.sql new file mode 100644 index 000000000..b9475433c --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_addPreparedSaleGroup.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_addPreparedSaleGroup`(vSaleGroupFk INT) +BEGIN +/** + * Inserta lineas de vn.saleTracking para un saleGroup (previa) que escanea un sacador + * + * @param vSaleGroupFk Identificador de vn.saleGroup + */ + REPLACE vn.saleTracking(saleFk, isChecked, workerFk, stateFk) + SELECT sgd.saleFk, TRUE, account.myUser_getId(), s.id + FROM vn.saleGroupDetail sgd + JOIN vn.state s ON s.code = 'PREPARED' + WHERE sgd.saleGroupFk = vSaleGroupFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_addPrevOK.sql b/db/routines/vn/procedures/saleTracking_addPrevOK.sql new file mode 100644 index 000000000..84cea965f --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_addPrevOK.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_addPrevOK`(vSectorCollectionFk INT) +BEGIN +/** + * Inserta los registros de la colección de sector con el estado PREVIA OK + * + * @param vSectorCollectionFk Identificador de vn.sectorCollection + */ + REPLACE vn.saleTracking( + saleFk, + isChecked, + workerFk, + stateFk + ) + SELECT sgd.saleFk, + TRUE, + sc.userFk, + s.id + FROM vn.sectorCollection sc + JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + JOIN vn.state s ON s.code = 'OK PREVIOUS' + WHERE sc.id = vSectorCollectionFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_del.sql b/db/routines/vn/procedures/saleTracking_del.sql new file mode 100644 index 000000000..263bd68a1 --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_del.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_del`(vSaleFk INT, vState VARCHAR(50)) +BEGIN + + DELETE FROM itemShelvingSale + WHERE saleFk = vSaleFk; + + DELETE st.* + FROM vn.saleTracking st + JOIN vn.state s ON s.id = st.stateFk + WHERE st.saleFk = vSaleFk + AND s.code = vState COLLATE utf8_unicode_ci; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_new.sql b/db/routines/vn/procedures/saleTracking_new.sql new file mode 100644 index 000000000..5982f8df0 --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_new.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_new`( + vSaleFK INT, + vIsChecked BOOLEAN, + vOriginalQuantity INT, + vWorkerFk INT, + vAction VARCHAR(50), + vState VARCHAR(50), + vIsScanned BOOLEAN) +BEGIN +/** + * Modifica registro de saleTracking + * + * @param vSaleFK Identificador del registro a modificar + * @param vIsChecked Indica si la línea ha sido pulsada + * @param vOriginalQuantity Cantidad original + * @param vWorkerFk Identificador del trabajador + * @param vAction Identificador de la acción realizada + * @param vState Identificador del estado a modificar + * @param vIsScanned Identificador si se ha escaneado automáticamente o manual + */ + + REPLACE vn.saleTracking(saleFk, + isChecked, + originalQuantity, + workerFk, + stateFk, + isScanned) + SELECT vSaleFK, + vIsChecked, + vOriginalQuantity, + IFNULL(vWorkerFk, vn.getUser()), + s.id, + vIsScanned + FROM vn.state s + WHERE s.code = vState COLLATE utf8_unicode_ci; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/saleTracking_updateIsChecked.sql b/db/routines/vn/procedures/saleTracking_updateIsChecked.sql new file mode 100644 index 000000000..57d8df701 --- /dev/null +++ b/db/routines/vn/procedures/saleTracking_updateIsChecked.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_updateIsChecked`(vSaleFK INT, vIsChecked BOOL, vIsScanned BOOL) +BEGIN + + /** + * Actualiza el estado del campo vn.saleTracking.isChecked y elimina las lineas de vn.itemShelving + * si procede, en el caso de las preparaciones previas, por usuario + * + * @param vSaleFk Identificador de vn.sale + * @param vIsChecked Estado del registro + */ + + UPDATE vn.saleTracking st + JOIN vn.state s ON s.id = st.stateFk AND s.code = 'PREVIOUS_PREPARATION' + SET st.isChecked = vIsChecked, + st.isScanned = vIsScanned + WHERE st.saleFk = vSaleFK + AND st.workerFk = account.myUser_getId(); + + IF vIsChecked = FALSE THEN + + DELETE FROM vn.itemShelvingSale + WHERE saleFk = vSaleFK; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_PriceFix.sql b/db/routines/vn/procedures/sale_PriceFix.sql new file mode 100644 index 000000000..8ffa77070 --- /dev/null +++ b/db/routines/vn/procedures/sale_PriceFix.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_PriceFix`(vTicketFk INT) +BEGIN + + DELETE sc.* + FROM vn.saleComponent sc + JOIN vn.sale s ON s.id = sc.saleFk + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE s.ticketFk = vTicketFk + AND ct.`type` = 'otros'; + + UPDATE vn.sale s + JOIN ( + SELECT sc.saleFk, sum(sc.value ) price + FROM vn.saleComponent sc + JOIN vn.sale s ON s.id = sc.saleFk + WHERE s.ticketFk = vTicketFk + GROUP BY sc.saleFk) sub ON sub.saleFk = s.id + SET s.price = sub.price; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_calculateComponent.sql b/db/routines/vn/procedures/sale_calculateComponent.sql new file mode 100644 index 000000000..d720c5b06 --- /dev/null +++ b/db/routines/vn/procedures/sale_calculateComponent.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption INT) +proc: BEGIN +/** + * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id de la venta + * @param vOption indica en que componente pone el descuadre, NULL en casos habituales + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.id = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_checkNoComponents.sql b/db/routines/vn/procedures/sale_checkNoComponents.sql new file mode 100644 index 000000000..136c13409 --- /dev/null +++ b/db/routines/vn/procedures/sale_checkNoComponents.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) +BEGIN +/** + * Comprueba que las ventas creadas entre un rango de fechas tienen componentes + * + * @param vCreatedFrom inicio del rango + * @param vCreatedTo fin del rango + */ + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vSaleFk INTEGER; + DECLARE vTicketFk INTEGER; + DECLARE vConcept VARCHAR(50); + DECLARE vCur CURSOR FOR + SELECT s.id + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo + AND c.id IS NULL + AND t.agencyModeFk IS NOT NULL + AND t.isDeleted IS FALSE + AND t.warehouseFk = 60 + AND ic.merchandise != FALSE + GROUP BY s.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + CREATE TEMPORARY TABLE tmp.coste + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT s.id + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6 + WHERE s.created >= vCreatedFrom + AND ic.merchandise != FALSE; + + OPEN vCur; + + l: LOOP + SET v_done = FALSE; + FETCH vCur INTO vSaleFk; + + IF v_done THEN + LEAVE l; + END IF; + + SELECT ticketFk, concept + INTO vTicketFk, vConcept + FROM sale + WHERE id = vSaleFk; + + CALL sale_calculateComponent(vSaleFk, 1); + END LOOP; + + CLOSE vCur; + DROP TEMPORARY TABLE tmp.coste; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql new file mode 100644 index 000000000..407c15854 --- /dev/null +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getBoxPickingList`(vSectorFk INT, vDated DATE) +BEGIN +/** +* Returns a suitable boxPicking sales list +* +* @param vSectorFk Identifier for vn.sector table +* @param vDated Date for vn.tickets.shipping +* +* @return tmp.sale +*/ + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM sector + WHERE id = vSectorFk; + + CALL productionControl(vWarehouseFk, 0); + + SELECT + s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + s.quantity / i.packingOut stickers, + i.packingOut + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemShelving ish ON ish.itemFk = s.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk + JOIN agencyMode am ON am.id = pb.agencyModeFk + LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = p.sectorFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk + WHERE s.quantity MOD i.packingOut = 0 + AND pb.problem = "" + AND s.quantity > 0 + AND sgd.saleFk IS NULL + AND p.sectorFk = vSectorFk + AND ts.isPreviousPreparable + AND iss.visible >= s.quantity + AND ((rm.bufferFk AND rm.isPickingAllowed) + OR am.name = 'REC_ALGEMESI') + AND pb.shipped = vDated + GROUP BY s.id + ORDER BY etd; + + DROP TEMPORARY TABLE tmp.productionBuffer; + END$$ +DELIMITER ; + + diff --git a/db/routines/vn/procedures/sale_getFromTicketOrCollection.sql b/db/routines/vn/procedures/sale_getFromTicketOrCollection.sql new file mode 100644 index 000000000..f177abf59 --- /dev/null +++ b/db/routines/vn/procedures/sale_getFromTicketOrCollection.sql @@ -0,0 +1,115 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getFromTicketOrCollection`(vParam INT) +BEGIN +/** + * Visualizar lineas de la tabla sale a través del parámetro vParam que puede + * ser ticket o collection. + * + * @param vParam Identificador de ticket o collection + */ +DECLARE vIsCollection BOOL; + + SELECT COUNT(*) INTO vIsCollection + FROM collection c + WHERE c.id = vParam; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + DROP TEMPORARY TABLE IF EXISTS tmp.ticket2; + + IF vIsCollection THEN + CREATE TEMPORARY TABLE tmp.ticket + (INDEX (id)) + ENGINE = MEMORY + SELECT tc.ticketFk id + FROM ticketCollection tc + JOIN ticket t ON t.id = tc.ticketFk + WHERE tc.collectionFk = vParam; + + CREATE TEMPORARY TABLE tmp.ticket2 + (INDEX (id)) + ENGINE = MEMORY + SELECT tc.ticketFk id + FROM ticketCollection tc + JOIN ticket t ON t.id = tc.ticketFk + WHERE tc.collectionFk = vParam; + ELSE + CREATE TEMPORARY TABLE tmp.ticket + (INDEX (id)) + ENGINE = MEMORY + SELECT vParam id; + + CREATE TEMPORARY TABLE tmp.ticket2 + (INDEX (id)) + ENGINE = MEMORY + SELECT vParam id; + END IF; + + SELECT s.ticketFk, + sgd.saleGroupFk, + s.id saleFk, + s.itemFk, + s.quantity, + i.longName, + i.size, + s.reserved, + MAX(IF(st.semaphore <=> 1, TRUE, FALSE)) isPreviousPrepared, + MAX(IF(st.semaphore <=> 2, TRUE, FALSE)) isPrepared, + MAX(IF(st.semaphore <=> 3, TRUE, FALSE)) isControlled, + MAX(IF(st.semaphore <=> 4, TRUE, FALSE)) isPreControlled, + ic.color, + ip.productor, + s.discount, + s.price, + i.stems, + i.category, + o.code origin, + tt.clientFk, + s.originalQuantity, + TRIM(CONCAT(LPAD(s.concept,30,' '), ' ', + RPAD(IFNULL(i.size,''),5,' '))) line1, + '' cel1, + TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, + IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1), + CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)), + CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2, + TRIM(CONCAT(ic.color)) line3, + p.code cel3, + s.isAdded, + IF(c.workerFk IS NULL, getUser(), c.workerFk) workerFk, + IF(SUM(iss.quantity) IS NULL, 0, SUM(iss.quantity)) pickedQuantity, + i.packingShelve, + MIN(iss.created) picked, + IF(sm.id, TRUE, FALSE) hasMistake, + sg.sectorFk + FROM tmp.ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN ticket tt ON tt.id = t.id + LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk + LEFT JOIN buy b ON b.id = lb.buy_id + JOIN item i ON i.id = s.itemFk + LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id + LEFT JOIN collection c ON c.id = tc.collectionFk + LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity + FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity + FROM tmp.ticket2 t + JOIN sale s ON s.ticketFk = t.id + JOIN saleTracking st ON st.saleFk = s.id + ORDER BY st.id DESC + LIMIT 10000000000000000000) sub + GROUP BY sub.saleFk, sub.stateFK) sub2 ON sub2.saleFk = s.id AND sub2.isChecked = 1 + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN state st ON st.id = sub2.stateFk + LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk + LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk + LEFT JOIN parking p ON p.id = sg.parkingFk + LEFT JOIN saleMistake sm ON sm.saleFk = s.id + GROUP BY s.id; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticket2; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_getProblems.sql b/db/routines/vn/procedures/sale_getProblems.sql new file mode 100644 index 000000000..bf02e2401 --- /dev/null +++ b/db/routines/vn/procedures/sale_getProblems.sql @@ -0,0 +1,299 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getProblems`(IN vIsTodayRelative tinyint(1)) +BEGIN +/** + * Calcula los problemas de cada venta para un conjunto de tickets. + * + * @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy + * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular + * @return tmp.sale_problems + */ + DECLARE vWarehouseFk INT; + DECLARE vDate DATE; + DECLARE vAvailableCache INT; + DECLARE vVisibleCache INT; + DECLARE vDone BOOL; + DECLARE vComponentCount INT; + + DECLARE vCursor CURSOR FOR + SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(tt.shipped)) + FROM tmp.sale_getProblems tt + WHERE DATE(tt.shipped) BETWEEN util.VN_CURDATE() + AND util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE tt.* + FROM tmp.sale_getProblems tt + JOIN ticketObservation tto ON tto.ticketFk = tt.ticketFk + JOIN observationType ot ON ot.id = tto.observationTypeFk + WHERE ot.code = 'administrative' + AND tto.description = 'Miriam'; + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale_problems ( + ticketFk INT(11), + saleFk INT(11), + isFreezed INTEGER(1) DEFAULT 0, + risk DECIMAL(10,2) DEFAULT 0, + hasHighRisk TINYINT(1) DEFAULT 0, + hasTicketRequest INTEGER(1) DEFAULT 0, + itemShortage VARCHAR(255), + isTaxDataChecked INTEGER(1) DEFAULT 1, + itemDelay VARCHAR(255), + itemLost VARCHAR(255), + hasComponentLack INTEGER(1), + hasRounding VARCHAR(255), + isTooLittle BOOL DEFAULT FALSE, + PRIMARY KEY (ticketFk, saleFk) + ) ENGINE = MEMORY; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, clientFk + FROM tmp.sale_getProblems; + + SELECT COUNT(*) INTO vComponentCount + FROM component + WHERE isRequired; + + -- Too Little + INSERT INTO tmp.sale_problems(ticketFk, isTooLittle) + SELECT tp.ticketFk, TRUE + FROM tmp.sale_getProblems tp + JOIN ticket t ON t.id = tp.ticketFk + JOIN ( + SELECT t.addressFk, SUM(sv.litros) litros, t.totalWithoutVat + FROM tmp.ticket_list tl + JOIN saleVolume sv ON sv.ticketFk = tl.ticketFk + JOIN ticket t ON t.id = tl.ticketFk + JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + AND zc.dated = util.VN_CURDATE() + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE + AND dm.code IN ('AGENCY','DELIVERY','PICKUP') + AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() + GROUP BY t.addressFk + ) sub ON sub.addressFk = t.addressFk + JOIN volumeConfig vc + WHERE sub.litros < vc.minTicketVolume + AND sub.totalWithoutVat < vc.minTicketValue; + + -- Faltan componentes + INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk) + SELECT ticketFk, (vComponentCount > nComp) hasComponentLack, saleFk + FROM ( + SELECT COUNT(s.id) nComp, tl.ticketFk, s.id saleFk + FROM tmp.ticket_list tl + JOIN vn.sale s ON s.ticketFk = tl.ticketFk + LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id + LEFT JOIN vn.component c ON c.id = sc.componentFk AND c.isRequired + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP') + AND s.quantity > 0 + GROUP BY s.id + ) sub + HAVING hasComponentLack; + + -- Cliente congelado + INSERT INTO tmp.sale_problems(ticketFk, isFreezed) + SELECT DISTINCT tl.ticketFk, TRUE + FROM tmp.ticket_list tl + JOIN client c ON c.id = tl.clientFk + WHERE c.isFreezed + ON DUPLICATE KEY UPDATE isFreezed = c.isFreezed; + + -- Credit exceeded + CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt + (PRIMARY KEY (clientFk)) + ENGINE = MEMORY + SELECT DISTINCT clientFk + FROM tmp.ticket_list; + + CALL client_getDebt(util.VN_CURDATE()); + + INSERT INTO tmp.sale_problems(ticketFk, risk, hasHighRisk) + SELECT DISTINCT tl.ticketFk, r.risk, ((r.risk - cc.riskTolerance) > c.credit + 10) + FROM tmp.ticket_list tl + JOIN ticket t ON t.id = tl.ticketFk + JOIN agencyMode a ON t.agencyModeFk = a.id + JOIN tmp.risk r ON r.clientFk = t.clientFk + JOIN client c ON c.id = t.clientFk + JOIN clientConfig cc + WHERE r.risk > c.credit + 10 + AND NOT a.isRiskFree + ON DUPLICATE KEY UPDATE + risk = r.risk, hasHighRisk = ((r.risk - cc.riskTolerance) > c.credit + 10); + + -- Antiguo COD 100, son peticiones de compra sin terminar + INSERT INTO tmp.sale_problems(ticketFk, hasTicketRequest) + SELECT DISTINCT tl.ticketFk, TRUE + FROM tmp.ticket_list tl + JOIN ticketRequest tr ON tr.ticketFk = tl.ticketFk + WHERE tr.isOK IS NULL + ON DUPLICATE KEY UPDATE hasTicketRequest = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk; + + -- Disponible, Faltas, Inventario y Retrasos + OPEN vCursor; + l: LOOP + SET vDone = FALSE; + FETCH vCursor INTO vWarehouseFk, vDate; + + IF vDone THEN + LEAVE l; + END IF; + + -- Disponible: no va a haber suficiente producto para preparar todos los pedidos + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); + + -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida + CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); + + INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk) + SELECT ticketFk, problem, saleFk + FROM ( + SELECT tl.ticketFk, + LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem, + s.id AS saleFk + FROM tmp.ticket_list tl + JOIN ticket t ON t.id = tl.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible,0) < s.quantity + AND IFNULL(av.available ,0) < s.quantity + AND IFNULL(issw.visible, 0) < s.quantity + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY tl.ticketFk) sub + ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk; + + -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida + INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk) + SELECT ticketFk, problem, saleFk + FROM ( + SELECT tl.ticketFk, + LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem, + s.id saleFk + FROM tmp.ticket_list tl + JOIN ticket t ON t.id = tl.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible,0) >= s.quantity + AND IFNULL(issw.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY tl.ticketFk + ) sub + ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; + + -- Retraso: Disponible suficiente, pero no visible ni ubicado + INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk) + SELECT ticketFk, problem, saleFk + FROM ( + SELECT tl.ticketFk, + LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem, + s.id saleFk + FROM tmp.ticket_list tl + JOIN ticket t ON t.id = tl.ticketFk + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible, 0) < s.quantity + AND IFNULL(av.available, 0) >= s.quantity + AND IFNULL(issw.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate) + AND NOT i.generic + AND util.VN_CURDATE() = vDate + AND t.warehouseFk = vWarehouseFk + GROUP BY tl.ticketFk + ) sub + ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; + + -- Redondeo: Cantidad pedida incorrecta en al grouping de la última compra + CALL buyUltimate(vWarehouseFk, vDate); + INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk) + SELECT ticketFk, problem, saleFk + FROM ( + SELECT tl.ticketFk, + s.id saleFk , + LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,''), ' '), 250) problem, + MOD(s.quantity, b.`grouping`) hasRounding + FROM tmp.ticket_list tl + JOIN ticket t ON t.id = tl.ticketFk + AND t.warehouseFk = vWarehouseFk + JOIN sale s ON s.ticketFk = tl.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + JOIN buy b ON b.id = bu.buyFk + GROUP BY tl.ticketFk + HAVING hasRounding + ) sub + ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk; + END LOOP; + CLOSE vCursor; + + INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked) + SELECT DISTINCT tl.ticketFk, FALSE + FROM tmp.ticket_list tl + JOIN client c ON c.id = tl.clientFk + WHERE NOT c.isTaxDataChecked + ON DUPLICATE KEY UPDATE isTaxDataChecked = FALSE; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.ticket_list, + tItemShelvingStock_byWarehouse; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_getProblemsByTicket.sql b/db/routines/vn/procedures/sale_getProblemsByTicket.sql new file mode 100644 index 000000000..b4aaad7de --- /dev/null +++ b/db/routines/vn/procedures/sale_getProblemsByTicket.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTicket`(IN vTicketFk INT, IN vIsTodayRelative TINYINT(1)) +BEGIN +/** + * Calcula los problemas de cada venta + * para un conjunto de tickets. + * + * @return Problems result + */ + DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems; + CREATE TEMPORARY TABLE tmp.sale_getProblems + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped + FROM ticket t + WHERE t.id = vTicketFk; + + CALL sale_getProblems(vIsTodayRelative); + + SELECT * FROM tmp.sale_problems; + + DROP TEMPORARY TABLE + tmp.sale_getProblems, + tmp.sale_problems; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sale_recalcComponent.sql b/db/routines/vn/procedures/sale_recalcComponent.sql new file mode 100644 index 000000000..4e407ca6b --- /dev/null +++ b/db/routines/vn/procedures/sale_recalcComponent.sql @@ -0,0 +1,115 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption INT) +proc: BEGIN +/** + * Este procedimiento recalcula los componentes de un conjunto de sales, + * eliminando los componentes existentes e insertandolos de nuevo + * + * @param vOption si no se quiere forzar llamar con NULL + * @table tmp.recalculateSales (id) + */ + DECLARE vShipped DATE; + DECLARE vWarehouseFk SMALLINT; + DECLARE vAgencyModeFk INT; + DECLARE vAddressFk INT; + DECLARE vTicketFk INT; + DECLARE vLanded DATE; + DECLARE vIsEditable BOOLEAN; + DECLARE vZoneFk INTEGER; + DECLARE vDone BOOL DEFAULT FALSE; + + DECLARE vCur CURSOR FOR + SELECT DISTINCT s.ticketFk + FROM tmp.recalculateSales rs + JOIN vn.sale s ON s.id = rs.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCur; + + l: LOOP + SET vDone = FALSE; + FETCH vCur INTO vTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, + t.zoneFk, + t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, + t.landed + INTO vIsEditable, + vZoneFk, + vWarehouseFk, + vShipped, + vAddressFk, + vAgencyModeFk, + vLanded + FROM ticket t + LEFT JOIN ticketState ts ON t.id = ts.ticketFk + LEFT JOIN alertLevel al ON al.id = ts.alertLevel + WHERE t.id = vTicketFk; + + CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); + + IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN + CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); + END IF; + + IF vLanded IS NULL OR vZoneFk IS NULL THEN + + UPDATE ticket t + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + WHERE t.id = vTicketFk AND t.landed IS NULL; + + IF vZoneFk IS NULL THEN + SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; + UPDATE ticket t + SET t.zoneFk = vZoneFk + WHERE t.id = vTicketFk AND t.zoneFk IS NULL; + END IF; + + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetLanded; + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) ENGINE = MEMORY + SELECT s.id saleFk, vWarehouseFk warehouseFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + WHERE s.ticketFk = vTicketFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY s.itemFk; + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + IF vOption IS NULL THEN + SET vOption = IF(vIsEditable, 1, 6); + END IF; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + + DROP TEMPORARY TABLE tmp.buyUltimate; + DROP TEMPORARY TABLE tmp.sale; + + END LOOP; + CLOSE vCur; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sales_merge.sql b/db/routines/vn/procedures/sales_merge.sql new file mode 100644 index 000000000..a91268c2f --- /dev/null +++ b/db/routines/vn/procedures/sales_merge.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sales_merge`(vTicketFk INT) +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve + SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE s.ticketFk = vTicketFk + AND it.isMergeable + GROUP BY s.itemFk, s.price, s.discount; + + START TRANSACTION; + + UPDATE sale s + JOIN tSalesToPreserve stp ON stp.id = s.id + SET quantity = newQuantity + WHERE s.ticketFk = vTicketFk; + + DELETE s.* + FROM sale s + LEFT JOIN tSalesToPreserve stp ON stp.id = s.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE s.ticketFk = vTicketFk + AND stp.id IS NULL + AND it.isMergeable; + + COMMIT; + + DROP TEMPORARY TABLE tSalesToPreserve; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sales_mergeByCollection.sql b/db/routines/vn/procedures/sales_mergeByCollection.sql new file mode 100644 index 000000000..4c0693753 --- /dev/null +++ b/db/routines/vn/procedures/sales_mergeByCollection.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sales_mergeByCollection`(vCollectionFk INT) +BEGIN + + DECLARE vDone BOOL; + -- Fetch variables + DECLARE vTicketFk INT; + + DECLARE cCur CURSOR FOR + SELECT ticketFk + FROM vn.ticketCollection + WHERE collectionFk = vCollectionFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + OPEN cCur; + + myLoop: LOOP + + SET vDone = FALSE; + + FETCH cCur INTO vTicketFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL vn.sales_merge(vTicketFk); + + END LOOP; + + CLOSE cCur; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql new file mode 100644 index 000000000..9e21defc5 --- /dev/null +++ b/db/routines/vn/procedures/sectorCollectionSaleGroup_add.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollectionSaleGroup_add`(vSaleGroupFk INT, vSectorCollectionFk INT) +BEGIN +/** + * Inserta un nuevo registro en vn.sectorCollectionSaleGroup + * Actualiza el usuario en vn.saleGroup y reemplaza los registros de vn.saleTracking + * + * @param vSaleGroupFk Identificador de vn.saleGroup + * @param vSectorCollectionFk Identificador de vn.sectorCollection + */ + REPLACE sectorCollectionSaleGroup + SET sectorCollectionFk = vSectorCollectionFk, + saleGroupFk = vSaleGroupFk; + + UPDATE saleGroup sg + JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id + JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk + SET sg.userFk = sc.userFk + WHERE sg.id = vSaleGroupFk; + + INSERT IGNORE saleTracking( + saleFk, + isChecked, + workerFk, + stateFk + ) + SELECT sgd.saleFk , + FALSE, + sc.userFk, + s.id + FROM saleGroupDetail sgd + JOIN sectorCollectionSaleGroup scsg + ON scsg.saleGroupFk = sgd.saleGroupFk + JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk + JOIN state s ON s.code = 'PREVIOUS_PREPARATION' + WHERE sgd.saleGroupFk = vSaleGroupFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sectorCollection_get.sql b/db/routines/vn/procedures/sectorCollection_get.sql new file mode 100644 index 000000000..e518e05f8 --- /dev/null +++ b/db/routines/vn/procedures/sectorCollection_get.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_get`() +BEGIN +/** + * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas + * + */ + SELECT DISTINCT sc.id collectionFk, sc.created + FROM vn.sectorCollection sc + JOIN vn.state s ON s.code = 'PREVIOUS_PREPARATION' + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + LEFT JOIN vn.saleTracking st ON st.saleFk = sgd.saleFk AND st.stateFk = s.id AND st.workerFk = sc.userFk + LEFT JOIN vn.sale sl ON sl.id = st.saleFk + WHERE sc.userFk = account.myUser_getId() + AND ( + ISNULL(scsg.sectorCollectionFk) + OR (NOT st.isChecked AND sl.quantity > 0) + ) + AND sc.created > util.VN_CURDATE(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sectorCollection_getSale.sql b/db/routines/vn/procedures/sectorCollection_getSale.sql new file mode 100644 index 000000000..e1636895b --- /dev/null +++ b/db/routines/vn/procedures/sectorCollection_getSale.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_getSale`(vSelf INT) +BEGIN +/** + * Devuelve las lineas de venta correspondientes a esa coleccion de sector + * + * @param vSelf Identificador de vn.sectorCollection + */ + SELECT s.ticketFk, + s.itemFk, + i.longName, + itemPackingTypeFk, + subName, + s.quantity, + w.code workerCode, + sgd.saleFk, + iss.quantity pickedQuantity, + c.salesPersonFk + FROM vn.sale s + JOIN item i ON i.id = s.itemFk + JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk + JOIN saleTracking st ON st.saleFk = s.id + JOIN `state` stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION' + JOIN worker w ON w.id = st.workerFk + JOIN ticket t ON t.id= s.ticketFk + JOIN client c ON c.id=t.clientFk + LEFT JOIN itemShelvingSaleSum iss ON iss.saleFk = s.id + WHERE scsg.sectorCollectionFk = vSelf + AND st.workerFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sectorCollection_new.sql b/db/routines/vn/procedures/sectorCollection_new.sql new file mode 100644 index 000000000..fae8eba31 --- /dev/null +++ b/db/routines/vn/procedures/sectorCollection_new.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorCollection_new`(vSectorFk INT) +BEGIN +/** + * Inserta una nueva colección, si el usuario no tiene ninguna vacia. + * Esto se hace para evitar que por error se generen colecciones sin sentido. + * + * @param vSectorFk Identificador de #vn.sector + */ + DECLARE hasEmptyCollections BOOL; + DECLARE vUserFk INT; + + SET vUserFk = account.myUser_getId(); + + SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections + FROM vn.sectorCollection sc + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + WHERE ISNULL(scsg.id) + AND sc.userFk = vUserFk + AND sc.sectorFk = vSectorFk + AND sc.created >= util.VN_CURDATE(); + + IF NOT hasEmptyCollections THEN + INSERT INTO vn.sectorCollection(userFk, sectorFk) + VALUES(vUserFk, vSectorFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sectorProductivity_add.sql b/db/routines/vn/procedures/sectorProductivity_add.sql new file mode 100644 index 000000000..be75c842d --- /dev/null +++ b/db/routines/vn/procedures/sectorProductivity_add.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sectorProductivity_add`() +BEGIN + DECLARE vDatedFrom DATETIME; + DECLARE vDatedTo DATETIME; + + SELECT DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY),' 23:59:59') INTO vDatedFrom, vDatedTo; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; + DROP TEMPORARY TABLE IF EXISTS tmp.errorsByChecker; + DROP TEMPORARY TABLE IF EXISTS tmp.previousErrors; + + CALL timeControl_calculateAll(vDatedFrom, vDatedTo); + + CREATE TEMPORARY TABLE tmp.errorsByChecker + ENGINE = MEMORY + SELECT sc.userFk workerFk, COUNT(DISTINCT s.ticketFk) errorsByChecker + FROM saleMistake sm + JOIN vn.saleGroupDetail sgd on sgd.saleFk = sm.saleFk + JOIN vn.sectorCollectionSaleGroup scsg on scsg.saleGroupFk = sgd.saleGroupFk + JOIN vn.sectorCollection sc on sc.id = scsg.sectorCollectionFk + JOIN sale s ON s.id = sm.saleFk + JOIN ticket t on t.id = s.ticketFk + WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) + GROUP BY sc.userFk ; + + CREATE TEMPORARY TABLE tmp.previousErrors -- Errores de previa, derivadores de los revisadores (por reclamación) + ENGINE = MEMORY + SELECT tt.userFk, COUNT(c.ticketFk) errorsByClaim + FROM claimDevelopment cd + JOIN claim c ON cd.claimFk = c.id + JOIN ticket t ON c.ticketFk = t.id + JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id + JOIN ticketTracking tt ON tt.ticketFk = t.id + JOIN `state` s ON s.id = tt.stateFk + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.description = 'Revisadores' AND s.code = 'OK PREVIOUS' + GROUP BY tt.userFk; + + DELETE FROM sectorProductivity + WHERE dated = vDatedFrom + AND sector IN ('Algemesi Artificial','Algemesi Complementos'); + + INSERT INTO sectorProductivity(workerFk, firstName, lastName, sector, ticketCount, saleCount, error, volume, hourWorked, dated) + SELECT w.id workerFk, + w.firstName, + w.lastName, + se.description sector, + COUNT(DISTINCT s.ticketFk) ticketCount, + COUNT(sgd.id) saleCount, + IFNULL(ec2.errorsByChecker,0) + IFNULL(pe.errorsByClaim, 0) errors, + wp.volume, + IFNULL(CAST(tc.timeWorkDecimal AS DECIMAL (10,2)) , 0) AS hourWorked, + DATE(vDatedFrom) dated + FROM vn.saleGroupDetail sgd + JOIN vn.saleGroup sg on sg.id = sgd.saleGroupFk + JOIN vn.sectorCollectionSaleGroup scsg on scsg.saleGroupFk = sgd.saleGroupFk + JOIN vn.sectorCollection sc on sc.id = scsg.sectorCollectionFk + join vn.sector se on se.id = sc.sectorFk + JOIN vn.worker w ON w.id = sc.userFk + LEFT JOIN vn.sale s ON s.id = sgd.saleFk + LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = w.id + LEFT JOIN bs.workerProductivity wp ON wp.workerFk = w.id + LEFT JOIN `state` s2 ON s2.id = wp.stateFk AND s2.code = 'OK PREVIOUS' + LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = w.id + LEFT JOIN tmp.previousErrors pe ON pe.userFk = w.id + WHERE DATE(sc.created) = vDatedFrom + AND wp.dated = vDatedFrom + GROUP BY w.id; + + DROP TEMPORARY TABLE tmp.timeControlCalculate; + DROP TEMPORARY TABLE tmp.errorsByChecker; + DROP TEMPORARY TABLE tmp.previousErrors; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sector_get.sql b/db/routines/vn/procedures/sector_get.sql new file mode 100644 index 000000000..fe978203a --- /dev/null +++ b/db/routines/vn/procedures/sector_get.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sector_get`() +BEGIN + +/** + * Obtiene los sectores +*/ + + SELECT s.id,s.description,s.warehouseFk + FROM vn.sector s; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sector_getWarehouse.sql b/db/routines/vn/procedures/sector_getWarehouse.sql new file mode 100644 index 000000000..fe363f39f --- /dev/null +++ b/db/routines/vn/procedures/sector_getWarehouse.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sector_getWarehouse`(vSectorFk INT) +BEGIN + + SELECT s.warehouseFk + FROM vn.sector s + WHERE s.id = vSectorFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql new file mode 100644 index 000000000..97a40bbe0 --- /dev/null +++ b/db/routines/vn/procedures/setParking.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) +proc: BEGIN +/** + * Aparca una colección, un ticket, un saleGroup o un shelving en un parking + * + * @param vParam id del ticket, colección, saleGroup o shelving + * @param vParkingCode código del parking + */ + DECLARE vParkingFk INT; + DECLARE vIsSaleGroup BOOL; + DECLARE vIsTicket BOOL; + DECLARE vIsCollection BOOL; + + SET vParkingCode = replace(vParkingCode,' ',''); + + SELECT id INTO vParkingFk + FROM vn.parking + WHERE code = vParkingCode COLLATE utf8_unicode_ci; + + IF vParkingFk IS NULL THEN + CALL util.throw('parkingNotExist'); + LEAVE proc; + END IF; + + -- Se comprueba si es una preparación previa + SELECT COUNT(*) INTO vIsSaleGroup + FROM vn.saleGroup sg + WHERE sg.id = vParam; + + IF vIsSaleGroup THEN + CALL vn.saleGroup_setParking(vParam, vParkingFk); + LEAVE proc; + END IF; + + -- Se comprueba si es un ticket + SELECT COUNT(*) INTO vIsTicket + FROM vn.ticket t + WHERE t.id = vParam + AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + + IF vIsTicket THEN + CALL vn.ticket_setParking(vParam, vParkingFk); + LEAVE proc; + END IF; + + -- Se comprueba si es una coleccion de tickets + SELECT COUNT(*) INTO vIsCollection + FROM vn.collection c + WHERE c.id = vParam + AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + + IF vIsCollection THEN + CALL vn.collection_setParking(vParam, vParkingFk); + LEAVE proc; + END IF; + + -- Por descarte, se considera una matrícula + CALL vn.shelving_setParking(vParam, vParkingFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelvingChange.sql b/db/routines/vn/procedures/shelvingChange.sql new file mode 100644 index 000000000..fde38212c --- /dev/null +++ b/db/routines/vn/procedures/shelvingChange.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelvingChange`(IN `vShelvingO` VARCHAR(8), IN `vShelvingD` VARCHAR(8)) +BEGIN + + UPDATE vn.itemShelving + SET shelvingFk = vShelvingD COLLATE utf8_unicode_ci + WHERE shelvingFk = vShelvingO COLLATE utf8_unicode_ci; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelvingLog_get.sql b/db/routines/vn/procedures/shelvingLog_get.sql new file mode 100644 index 000000000..d48e38d03 --- /dev/null +++ b/db/routines/vn/procedures/shelvingLog_get.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelvingLog_get`(shelvingFk VARCHAR(10)) +BEGIN + + /* Lista el log de un carro + * + * @param shelvingFk matrícula del carro + * + */ + + SELECT originFk, name, creationDate, description + FROM shelvingLog sl + JOIN account.user u ON u.id = sl.userFk + WHERE sl.originFk = shelvingFk COLLATE utf8_general_ci + ORDER BY creationDate DESC; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelvingParking_get.sql b/db/routines/vn/procedures/shelvingParking_get.sql new file mode 100644 index 000000000..0131db7d2 --- /dev/null +++ b/db/routines/vn/procedures/shelvingParking_get.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelvingParking_get`(vShelvingFk VARCHAR(10), vWarehouseFk INT, vDayRange INT) +BEGIN + + +SELECT s.itemFk, + s.concept, + CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir, + CAST(IFNULL(ist.visible,0) AS DECIMAL(10,0)) as aparcado + FROM vn.sale s + LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk AND ist.warehouseFk = vWarehouseFk + JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk AND ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) + AND iss.saleFk IS NULL + AND t.warehouseFk = vWarehouseFk + GROUP BY s.itemFk + HAVING sinServir > aparcado; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelvingPriority_update.sql b/db/routines/vn/procedures/shelvingPriority_update.sql new file mode 100644 index 000000000..317f17333 --- /dev/null +++ b/db/routines/vn/procedures/shelvingPriority_update.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelvingPriority_update`(priority INT,vShelvingFk VARCHAR(10)) +BEGIN + + UPDATE vn.shelving SET priority = priority WHERE code=vShelvingFk COLLATE utf8_unicode_ci; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelving_clean.sql b/db/routines/vn/procedures/shelving_clean.sql new file mode 100644 index 000000000..f9248a0d7 --- /dev/null +++ b/db/routines/vn/procedures/shelving_clean.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelving_clean`() +BEGIN + + DELETE FROM shelving + WHERE length(code) > 3 + AND parked < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + + DELETE FROM itemShelving + WHERE visible <= 0 + AND created < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + + DELETE ish.* + FROM itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + WHERE sh.parkingFk IS NULL + AND ish.created < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + +UPDATE shelving sh + LEFT JOIN itemShelving its ON its.shelvingFk = sh.`code` + SET isPrinted = 0, + parkingFk = NULL + WHERE its.id IS NULL + AND sh.isRecyclable + AND ( + sh.parked IS NULL + OR + sh.parked < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) + ) + AND IF(code REGEXP '^[A-Za-z]{2}[0-9]', LEFT (code, 2) NOT IN ( + SELECT DISTINCT LEFT(its.shelvingFk, 2) + FROM itemShelving its + WHERE its.shelvingFk REGEXP '^[A-Za-z]{2}[0-9]' + ), TRUE); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelving_getSpam.sql b/db/routines/vn/procedures/shelving_getSpam.sql new file mode 100644 index 000000000..eccbfb9a4 --- /dev/null +++ b/db/routines/vn/procedures/shelving_getSpam.sql @@ -0,0 +1,84 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelving_getSpam`(vDated DATE, vWarehouseFk INT) +BEGIN +/** + * Devuelve las matrículas con productos que no son necesarios para la venta + * hasta la fecha señalada. + * + * @param vDated Fecha hasta la que se puede pasar sin esos productos + * @param vWarehouse Identificador único de vn.warehouse + */ + DROP TEMPORARY TABLE IF EXISTS tmp.stock; + + CALL cache.stock_refresh(FALSE); + + CREATE TEMPORARY TABLE tmp.stock + SELECT i.id itemFk, + v.amount - IFNULL(fue.reserva,0) as visible, + fue.reserva, + sale.venta, + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, + IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.reserva,0) as saldo + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN ( + SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva + 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 s.code = 'FUENTES_PICASSE' + OR sh.isSpam + GROUP BY ish.itemFk + ) fue ON fue.itemFk = i.id + LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta + FROM vn2008.item_out + WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated) + AND warehouse_id = vWarehouseFk + GROUP BY item_id + ) sale ON sale.item_id = i.id + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra + FROM vn2008.item_entry_in + WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated) + AND warehouse_id = vWarehouseFk + AND isVirtualStock = FALSE + GROUP BY item_id + ) buy ON buy.item_id = i.id + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado + FROM vn2008.item_entry_out + WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated) + AND warehouse_id = vWarehouseFk + GROUP BY item_id + ) mov ON mov.item_id = i.id + WHERE v.amount; + + SELECT ish.shelvingFk matricula, + i.longName articulo, + ish.visible, + count(*) lineas, + sum(ish.visible <= s.saldo) spam, + p.code parking, + s.description sector , + w.name AS almacen, + sh.isSpam + FROM vn.itemShelving ish + JOIN vn.item i ON i.id = ish.itemFk + 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 + JOIN vn.warehouse w ON w.id = s.warehouseFk + LEFT JOIN tmp.stock s ON s.itemFk = ish.itemFk + WHERE (w.name = 'Algemesi' + OR (w.name = 'NuncaJamas' AND ish.created < util.VN_CURDATE())) + AND ish.visible + GROUP BY ish.shelvingFk + HAVING lineas = spam OR isSpam; + + DROP TEMPORARY TABLE tmp.stock; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/shelving_setParking.sql b/db/routines/vn/procedures/shelving_setParking.sql new file mode 100644 index 000000000..0ff07ef5d --- /dev/null +++ b/db/routines/vn/procedures/shelving_setParking.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`shelving_setParking`(IN `vShelvingCode` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN +/** + * Aparca una matrícula en un parking + * + * @param vShelvingCode code de la matrícula + * @param vParkingFk id del parking + */ + INSERT INTO vn.shelvingLog (originFk, userFk, action , description,changedModel,changedModelId) + SELECT s.id, account.myUser_getId(), 'update', CONCAT("Cambio parking ",vShelvingCode," de ", p.code," a ", pNew.code),'Shelving',s.id + FROM parking p + JOIN shelving s ON s.parkingFk = p.id + JOIN parking pNew ON pNew.id = vParkingFk + WHERE s.code = vShelvingCode COLLATE utf8_unicode_ci; + + UPDATE vn.shelving + SET parkingFk = vParkingFk, + parked = util.VN_NOW(), + isPrinted = TRUE + WHERE code = vShelvingCode COLLATE utf8_unicode_ci; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/sleep_X_min.sql b/db/routines/vn/procedures/sleep_X_min.sql new file mode 100644 index 000000000..39102b57d --- /dev/null +++ b/db/routines/vn/procedures/sleep_X_min.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sleep_X_min`() +BEGIN + # Ernesto. 4.8.2020 + # Para su uso en las tareas ejecutadas a las 2AM (visibles con: SELECT * FROM bs.nightTask order by started asc;) + # Simplemente esperar unos minutos para que en las graficas de rendimiento de Percona PMM y escritura a disco de vCenter se puedan ver los efectos de cada tarea. + do SLEEP(300); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/solunionRiskRequest.sql b/db/routines/vn/procedures/solunionRiskRequest.sql new file mode 100644 index 000000000..b735bea33 --- /dev/null +++ b/db/routines/vn/procedures/solunionRiskRequest.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`solunionRiskRequest`() +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc + JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification + WHERE dateEnd IS NULL + ORDER BY ci.creationDate DESC + LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; + + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); + + SELECT + c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, + cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, + f.Consumo consumo_anual, c.Vencimiento, ci.grade + FROM + vn2008.Clientes c + JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente + JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente + JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente + GROUP BY Id_cliente; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/stockBuyedByWorker.sql b/db/routines/vn/procedures/stockBuyedByWorker.sql new file mode 100644 index 000000000..730612db8 --- /dev/null +++ b/db/routines/vn/procedures/stockBuyedByWorker.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBuyedByWorker`( + vDated DATE, + vWorker INT +) +BEGIN +/** + * Inserta el volumen de compra de un comprador + * en stockBuyed de acuerdo con la fecha. + * + * @param vDated Fecha de compra + * @param vWorker Id de trabajador + */ + CREATE OR REPLACE TEMPORARY TABLE tStockBuyed + (INDEX (userFk)) + ENGINE = MEMORY + SELECT requested, reserved, userFk + FROM stockBuyed + WHERE dated = vDated + AND userFk = vWorker; + + DELETE FROM stockBuyed + WHERE dated = vDated + AND userFk = vWorker; + + CALL stockTraslation(vDated); + + INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description) + SELECT it.workerFk, + SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000, + vDated, + sb.reserved, + sb.requested, + u.name + FROM itemType it + JOIN item i ON i.typeFk = it.id + LEFT JOIN tmp.item ti ON ti.itemFk = i.id + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN warehouse wh ON wh.code = 'VNH' + JOIN tmp.buyUltimate bu ON bu.itemFk = i.id + AND bu.warehouseFk = wh.id + JOIN buy b ON b.id = bu.buyFk + JOIN volumeConfig vc + JOIN account.`user` u ON u.id = it.workerFk + LEFT JOIN tStockBuyed sb ON sb.userFk = it.workerFk + WHERE ic.display + AND it.workerFk = vWorker; + + SELECT b.entryFk Id_Entrada, + i.id Id_Article, + i.name Article, + ti.quantity Cantidad, + (ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id)) + / (vc.trolleyM3 * 1000000) buyed, + b.packagingFk id_cubo, + b.packing + FROM tmp.item ti + JOIN item i ON i.id = ti.itemFk + JOIN itemType it ON i.typeFk = it.id + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN worker w ON w.id = it.workerFk + JOIN auctionConfig ac + JOIN tmp.buyUltimate bu ON bu.itemFk = i.id + AND bu.warehouseFk = ac.warehouseFk + JOIN buy b ON b.id = bu.buyFk + JOIN volumeConfig vc + WHERE ic.display + AND w.id = vWorker; + + DROP TEMPORARY TABLE tmp.buyUltimate, + tmp.item, + tStockBuyed; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/stockBuyed_add.sql b/db/routines/vn/procedures/stockBuyed_add.sql new file mode 100644 index 000000000..bddb720a5 --- /dev/null +++ b/db/routines/vn/procedures/stockBuyed_add.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBuyed_add`( + vDated DATE +) +BEGIN +/** + * Inserta el volumen de compra por comprador + * en stockBuyed de acuerdo con la fecha. + * + * @param vDated Fecha de compra + */ + CREATE OR REPLACE TEMPORARY TABLE tStockBuyed + (INDEX (userFk)) + ENGINE = MEMORY + SELECT requested, reserved, userFk + FROM stockBuyed + WHERE dated = vDated; + + DELETE FROM stockBuyed WHERE dated = vDated; + + CALL stockTraslation(vDated); + + INSERT INTO stockBuyed(userFk, buyed, `dated`, description) + SELECT it.workerFk, + SUM((ti.quantity / b.packing) * buy_getVolume(b.id)) / vc.palletM3 / 1000000, + vDated, + u.name + FROM itemType it + JOIN item i ON i.typeFk = it.id + LEFT JOIN tmp.item ti ON ti.itemFk = i.id + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN warehouse wh ON wh.code = 'VNH' + JOIN tmp.buyUltimate bu ON bu.itemFk = i.id AND bu.warehouseFk = wh.id + JOIN buy b ON b.id = bu.buyFk + JOIN volumeConfig vc + JOIN account.`user` u ON u.id = it.workerFk + JOIN workerDepartment wd ON wd.workerFk = u.id + JOIN department d ON d.id = wd.departmentFk + WHERE ic.display + AND d.code IN ('shopping', 'logistic', 'franceTeam') + GROUP BY it.workerFk; + + INSERT INTO stockBuyed(buyed, dated, description) + SELECT SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000), + vDated, + IF(c.code = 'ES', p.name, c.country) destiny + FROM itemTicketOut ito + JOIN ticket t ON t.id = ito.ticketFk + JOIN `address` a ON a.id = t.addressFk + JOIN province p ON p.id = a.provinceFk + JOIN country c ON c.id = p.countryFk + JOIN warehouse wh ON wh.id = t.warehouseFk + JOIN itemCost ic ON ic.itemFk = ito.itemFk + AND ic.warehouseFk = t.warehouseFk + JOIN volumeConfig vc + WHERE ito.shipped BETWEEN vDated AND util.dayend(vDated) + AND wh.code = 'VNH' + GROUP BY destiny; + + UPDATE stockBuyed s + JOIN tStockBuyed ts ON ts.userFk = s.userFk + SET s.requested = ts.requested, + s.reserved = ts.reserved + WHERE s.dated = vDated; + + DROP TEMPORARY TABLE tmp.buyUltimate, + tmp.item, + tStockBuyed; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/stockTraslation.sql b/db/routines/vn/procedures/stockTraslation.sql new file mode 100644 index 000000000..c681112f1 --- /dev/null +++ b/db/routines/vn/procedures/stockTraslation.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockTraslation`( + vDated DATE +) +BEGIN +/** + * Calcula el stock del almacén de subasta desde FechaInventario hasta vDated + * sin tener en cuenta las salidas del mismo dia vDated + * para ver el transporte a reservar + * + * @param vDated Fecha hasta la cual calcula el stock + * @return tmp.item + */ + DECLARE vAuctionWarehouseFk INT; + + SELECT warehouseFk INTO vAuctionWarehouseFk + FROM auctionConfig; + + CREATE OR REPLACE TEMPORARY TABLE tmp.item + (UNIQUE INDEX i USING HASH (itemFk)) + ENGINE = MEMORY + SELECT itemFk, SUM(quantity) quantity + FROM itemEntryIn + WHERE landed = vDated + AND vDated >= util.VN_CURDATE() + AND warehouseInFk = vAuctionWarehouseFk + AND NOT isVirtualStock + GROUP BY itemFk + HAVING quantity; + + CALL `cache`.stock_refresh(FALSE); + + INSERT INTO tmp.item (itemFk, quantity) + SELECT item_id, amount + FROM `cache`.stock + WHERE warehouse_id = vAuctionWarehouseFk + ON DUPLICATE KEY UPDATE quantity = tmp.item.quantity + VALUES(quantity); + + CALL buyUltimate(vAuctionWarehouseFk, vDated); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/subordinateGetList.sql b/db/routines/vn/procedures/subordinateGetList.sql new file mode 100644 index 000000000..0431afaa4 --- /dev/null +++ b/db/routines/vn/procedures/subordinateGetList.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`subordinateGetList`(vBossFk INT) +BEGIN + + -- deprecated usar vn.worker_GetHierarch + DECLARE vBossId INT; + DECLARE vDone BOOL; + DECLARE workerCur CURSOR FOR + SELECT workerFk + FROM tmp.subordinate + WHERE NOT isChecked; + + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR 1062 BEGIN + CALL util.throw('INFINITE_LOOP'); + END; + + DROP TEMPORARY TABLE IF EXISTS tmp.subordinate; + + CREATE TEMPORARY TABLE tmp.subordinate + (PRIMARY KEY (workerFk)) + ENGINE = MEMORY + SELECT vBossFk AS workerFk, 0 AS isChecked; + + WHILE (SELECT COUNT(*) FROM tmp.subordinate WHERE NOT isChecked) > 0 DO + OPEN workerCur; + workerLoop: LOOP + SET vDone = FALSE; + + FETCH workerCur INTO vBossId; + + IF vDone THEN + LEAVE workerLoop; + END IF; + + INSERT INTO tmp.subordinate + SELECT id, 0 + FROM worker + WHERE bossFk = vBossId; + + UPDATE tmp.subordinate + SET isChecked = 1 + WHERE workerFk = vBossId; + END LOOP; + + CLOSE workerCur; + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplierExpenses.sql b/db/routines/vn/procedures/supplierExpenses.sql new file mode 100644 index 000000000..11ebbd603 --- /dev/null +++ b/db/routines/vn/procedures/supplierExpenses.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierExpenses`(vEnded DATE) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS openingBalance; + + CREATE TEMPORARY TABLE openingBalance( + dueDated DATE + , supplierFk INT NOT NULL + , companyFk INT NOT NULL + , eurAmount DOUBLE NOT NULL + , foreignAmount DOUBLE NOT NULL + , PRIMARY KEY(supplierFk, companyFk)) + ENGINE = MEMORY; + + -- Calcula el balance inicial y final de cada proveedor + INSERT INTO openingBalance + SELECT MAX(dueDated), + supplierFk, + companyFk, + sum(amount) eurAmount, + sum(divisa) foreignAmount + FROM ( + SELECT p.dueDated, + p.supplierFk, + p.companyFk, + p.amount, + p.divisa + FROM payment p + JOIN currency c ON c.id = p.currencyFk + JOIN company co ON co.id = p.companyFk + WHERE p.dueDated > '2014-12-31' + AND p.dueDated <= vEnded + AND co.`code` = 'VNL' + AND c.`code` <> 'EUR' + UNION ALL + + SELECT iidd.dueDated, + ii.supplierFk, + ii.companyFk, + - iidd.amount, + - iidd.foreignValue + FROM invoiceIn ii + JOIN invoiceInDueDay iidd ON ii.id = iidd.invoiceInFk + JOIN currency c ON c.id = ii.currencyFk + JOIN company co ON co.id = ii.companyFk + WHERE iidd.dueDated > '2014-12-31' + AND iidd.dueDated <= vEnded + AND ii.isBooked AND co.`code` = 'VNL' + AND c.`code` <> 'EUR' + UNION ALL + + SELECT se.dueDated, + se.supplierFk, + se.companyFk, + - se.amount, + 0 + FROM supplierExpense se + JOIN currency c ON c.id = se.currencyFk + JOIN company co ON co.id = se.companyFk + WHERE se.dueDated > '2014-12-31' + AND se.dueDated <= vEnded + AND co.`code` = 'VNL' AND c.`code` <> 'EUR' + ) sub + GROUP BY companyFk, supplierFk; + + SELECT ob.dueDated + , ob.supplierFk + , ob.companyFk + , ob.eurAmount + , s.`name` + FROM openingBalance ob + LEFT JOIN supplier s ON s.id = ob.supplierFk + WHERE ob.eurAmount <> 0 AND ob.foreignAmount = 0; + + DROP TEMPORARY TABLE openingBalance; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplierPackaging_ReportSource.sql b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql new file mode 100644 index 000000000..f9d43f925 --- /dev/null +++ b/db/routines/vn/procedures/supplierPackaging_ReportSource.sql @@ -0,0 +1,82 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplierPackaging_ReportSource`( + vFromDated DATE, + vSupplierFk INT +) +BEGIN +/** +* Selecciona los embalajes de un proveedor a partir de una fecha +* +* @param vFromDated Fecha de la que partir +* @param vSupplierFk Id del proveedor +*/ + SET @vBalance = 0; + SET @vItemFk = NULL; + + CREATE OR REPLACE TEMPORARY TABLE tSupplierPackaging + SELECT supplierFk, + itemFk, + longName, + supplier, + entryFk, + landed, + `in`, + `out`, + warehouse, + buyingValue, + IF ( + NOT (@vItemFk <=> sub.itemFk), + @vBalance := (`in` - `out`), + @vBalance := (`in` - `out` + @vBalance) + ) balance, + @vItemFk := sub.itemFk previousItemFk + FROM ( + SELECT supplierFk, + itemFk, + longName, + supplier, + entryFk, + landed, + `in`, + `out`, + warehouse, + buyingValue + FROM supplierPackaging + WHERE supplierFk = vSupplierFk + AND landed >= vFromDated + UNION ALL + SELECT vSupplierFk, + itemFk, + longName, + supplier, + 'previous', + vFromDated, + SUM(`in`), + SUM(`out`), + NULL, + buyingValue + FROM supplierPackaging + WHERE supplierFk = vSupplierFk + AND landed < vFromDated + GROUP BY itemFk + ORDER BY itemFk, landed, entryFk + ) sub + WHERE `out` OR `in`; + + SELECT supplierFk, + itemFk, + longName, + supplier, + entryFk, + landed, + `in`, + `out`, + warehouse, + buyingValue, + balance + FROM tSupplierPackaging + WHERE NOT (NOT balance AND landed < CURDATE() - INTERVAL 1 YEAR); + + DROP TEMPORARY TABLE tSupplierPackaging; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplier_checkBalance.sql b/db/routines/vn/procedures/supplier_checkBalance.sql new file mode 100644 index 000000000..5248b4cec --- /dev/null +++ b/db/routines/vn/procedures/supplier_checkBalance.sql @@ -0,0 +1,74 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_checkBalance`(IN vDateTo DATETIME, IN vIsConciliated BOOL) +BEGIN +/** + * Compara los datos de nuestros proveedores con + * los que hay en la base de datos de sage + * + * @param vDateTo + * @param vIsConciliated + * @table tmp.ledgerComparative (id, date, account, debit, credit, companyFk) + */ + DECLARE vDateFrom DATE; + DECLARE vMaxTolerance DECIMAL(10,2); + SET vDateTo = TIMESTAMP(vDateTo,'23:59:59'); + SELECT util.firstDayOfYear(vDateTo) INTO vDateFrom; + SELECT maxTolerance INTO vMaxTolerance + FROM vn.ledgerConfig; + + SELECT c.code, + s.id supplierFk, + s.account, + sub1.mysql, + sub1.sage, + sub1.mysql - sub1.sage difference, + sub1.companyFk, + s.name + FROM supplier s + JOIN (SELECT companyFk, + supplierFk, + CAST(ROUND(SUM(mysql),2) AS DECIMAL(10,2)) mysql, + CAST(ROUND(SUM(sage),2) AS DECIMAL(10,2)) sage + FROM (SELECT companyFk, + supplierFk, + - SUM(iid.amount) mysql, + 0 sage + FROM invoiceInDueDay iid + JOIN invoiceIn ii ON ii.id = iid.invoiceInFk + WHERE IFNULL(ii.bookEntried, ii.issued) BETWEEN vDateFrom AND vDateTo + AND ii.isBooked + GROUP BY ii.id + UNION ALL + SELECT p.companyFk, + p.supplierFk, + p.amount, + 0 + FROM payment p + JOIN payMethod pm ON pm.id = p.payMethodFk + WHERE p.received BETWEEN vDateFrom AND vDateTo + AND IF(vIsConciliated, p.isConciliated, TRUE) = TRUE + AND NOT pm.code <=>'previousBalance' + UNION ALL + SELECT se.companyFk, + se.supplierFk, + - se.amount, + 0 + FROM supplierExpense se + WHERE se.dated BETWEEN vDateFrom AND vDateTo + AND IF(vIsConciliated, se.isConciliated, TRUE) = TRUE + UNION ALL + SELECT lc.companyFk, + s.id, + 0, + - (NZ(lc.debit) - NZ(lc.credit)) + FROM tmp.ledgerComparative lc + JOIN supplier s ON s.account = lc.account + WHERE lc.`date` BETWEEN vDateFrom AND vDateTo + ) sub + GROUP BY companyFk, supplierFk + ) sub1 ON sub1.supplierFk = s.id + JOIN company c ON c.id = sub1.companyFk + HAVING ABS(difference) > vMaxTolerance + ORDER BY s.name; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplier_checkIsActive.sql b/db/routines/vn/procedures/supplier_checkIsActive.sql new file mode 100644 index 000000000..9dcb6452a --- /dev/null +++ b/db/routines/vn/procedures/supplier_checkIsActive.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_checkIsActive`(vSelf INT) +BEGIN +/** + * Comprueba si un proveedor esta activo. + */ + DECLARE vIsActive BOOL; + + SELECT isActive INTO vIsActive + FROM vn.supplier + WHERE id = vSelf; + + IF NOT vIsActive THEN + CALL util.throw('INACTIVE_PROVIDER'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplier_disablePayMethodChecked.sql b/db/routines/vn/procedures/supplier_disablePayMethodChecked.sql new file mode 100644 index 000000000..d486f6e86 --- /dev/null +++ b/db/routines/vn/procedures/supplier_disablePayMethodChecked.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_disablePayMethodChecked`() +BEGIN + +/* + * Deshabilita la comprobación de los datos bancarios de todos aquellos proveedores que tengan + * un número que no sea 0 en el campo graceMonthsDisableChecked de la tabla vn.payMethod + * y que no hayan recibido un pago desde el mes indicado + */ + + UPDATE vn.supplier s + JOIN ( SELECT p.supplierFk + FROM supplier s + JOIN payMethod pm ON pm.id = s.payMethodFk + JOIN (SELECT supplierFk,MAX(created) created + FROM payment + GROUP BY supplierFk) p ON p.supplierFk = s.id + WHERE p.created < (util.VN_CURDATE() - INTERVAL pm.graceMonthsDisableChecked MONTH) + AND pm.graceMonthsDisableChecked + AND s.isPayMethodChecked + GROUP BY p.supplierFk) sdpmc ON sdpmc.supplierFk = s.id + SET s.isPayMethodChecked = FALSE; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/test.sql b/db/routines/vn/procedures/test.sql new file mode 100644 index 000000000..69340291d --- /dev/null +++ b/db/routines/vn/procedures/test.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`test`() +BEGIN +select 'procedimiento ejecutado con éxito'; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketBoxesView.sql b/db/routines/vn/procedures/ticketBoxesView.sql new file mode 100644 index 000000000..d5fcef226 --- /dev/null +++ b/db/routines/vn/procedures/ticketBoxesView.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketBoxesView`(IN vTicketFk INT) +BEGIN + + SELECT s.id, + s.itemFk, + s.concept, + floor(s.quantity / b.packing) as Cajas, + b.packing, + s.isPicked, + i.size + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN cache.last_buy lb on lb.warehouse_id = t.warehouseFk AND lb.item_id = s.itemFk + JOIN buy b on b.id = lb.buy_id + JOIN packaging p on p.id = b.packagingFk + WHERE s.quantity >= b.packing + AND t.id = vTicketFk + AND p.isBox + GROUP BY s.itemFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketBuiltTime.sql b/db/routines/vn/procedures/ticketBuiltTime.sql new file mode 100644 index 000000000..936e872ab --- /dev/null +++ b/db/routines/vn/procedures/ticketBuiltTime.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketBuiltTime`(vDate DATE) +BEGIN + + DECLARE vDateStart DATETIME DEFAULT DATE(vDate); + DECLARE vDateEnd DATETIME DEFAULT util.dayEnd(vDate); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketBuiltTime; + + CREATE TEMPORARY TABLE tmp.ticketBuiltTime + ENGINE = MEMORY + SELECT t.id as ticketFk ,t.shipped, IFNULL(builtTime, vDateEnd) as builtTime + FROM + vn.ticket t + LEFT JOIN + ( + SELECT ticketFk, builtTime + FROM + ( + SELECT + ticketFk, + created as builtTime + FROM + ticketTracking + WHERE created BETWEEN vDateStart AND vDateEnd + ORDER BY ticketFk, created DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY ticketFk + ) sub2 ON sub2.ticketFk = t.id + WHERE t.shipped BETWEEN vDate AND util.dayEnd(vDate) + AND t.clientFk NOT IN (50,400,200) + AND t.companyFk = 442 + + ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketCalculateClon.sql b/db/routines/vn/procedures/ticketCalculateClon.sql new file mode 100644 index 000000000..0be51c2ce --- /dev/null +++ b/db/routines/vn/procedures/ticketCalculateClon.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) +BEGIN +/* + * Recalcula los componentes un ticket clonado, + * las lineas a precio cero fuerza para que tengan precio, el resto lo respeta + * @param vTicketNew nuevo ticket clonado + * @param vTicketOld icket original, a partir del qual se clonara el nuevo +*/ + + REPLACE INTO orderTicket(orderFk,ticketFk) + SELECT orderFk, vTicketNew + FROM orderTicket + WHERE ticketFk = vTicketOld; + + -- Bionizamos lineas con Preu = 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price = 0; + + CALL sale_recalcComponent(1); + + -- Bionizamos lineas con Preu > 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price > 0; + + CALL sale_recalcComponent(6); + + DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketCalculateFromType.sql b/db/routines/vn/procedures/ticketCalculateFromType.sql new file mode 100644 index 000000000..106e0aecc --- /dev/null +++ b/db/routines/vn/procedures/ticketCalculateFromType.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateFromType`( vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT, + vTypeFk INT) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT id itemFk FROM vn.item + WHERE typeFk = vTypeFk; + + CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); + DROP TEMPORARY TABLE tmp.item; + DROP TEMPORARY TABLE tmp.ticketLot; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketCalculatePurge.sql b/db/routines/vn/procedures/ticketCalculatePurge.sql new file mode 100644 index 000000000..86e3b0d1b --- /dev/null +++ b/db/routines/vn/procedures/ticketCalculatePurge.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculatePurge`() +BEGIN + DROP TEMPORARY TABLE + tmp.ticketCalculateItem, + tmp.ticketComponentPrice, + tmp.ticketComponent, + tmp.ticketLot, + tmp.zoneGetShipped; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketClon.sql b/db/routines/vn/procedures/ticketClon.sql new file mode 100644 index 000000000..81328bc11 --- /dev/null +++ b/db/routines/vn/procedures/ticketClon.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketClon`(vTicketFk INT, vNewShipped DATE) +BEGIN + + DECLARE done INT DEFAULT FALSE; + DECLARE vNewTicketFk INT; + DECLARE vOldSaleFk INT; + DECLARE vNewSaleFk INT; + + DECLARE cur1 CURSOR FOR + SELECT id + FROM vn.sale + WHERE ticketFk = vTicketFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); + + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); + + UPDATE vn.ticket + SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed), + shipped = vNewShipped + WHERE id = vNewTicketFk; + + OPEN cur1; + + read_loop: LOOP + + FETCH cur1 INTO vOldSaleFk; + + IF done THEN + LEAVE read_loop; + END IF; + + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed) + SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed + FROM vn.sale + WHERE id = vOldSaleFk; + + SELECT max(id) INTO vNewSaleFk + FROM vn.sale + WHERE ticketFk = vNewTicketFk; + + INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge) + SELECT vNewSaleFk, componentFk, value, isGreuge + FROM vn.saleComponent + WHERE saleFk = vOldSaleFk; + + END LOOP; + + CLOSE cur1; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketClon_OneYear.sql b/db/routines/vn/procedures/ticketClon_OneYear.sql new file mode 100644 index 000000000..b0c08dec8 --- /dev/null +++ b/db/routines/vn/procedures/ticketClon_OneYear.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketClon_OneYear`(vTicketFk INT) +BEGIN + + DECLARE vShipped DATE; + DECLARE vMaxDated DATE; + + SELECT shipped, TIMESTAMPADD(YEAR,1,shipped) + INTO vShipped, vMaxDated + FROM vn.ticket + WHERE id = vTicketFk; + + WHILE vShipped <= vMaxDated DO + + SET vShipped = TIMESTAMPADD(WEEK, 1, vShipped); + + CALL vn.ticketClon(vTicketFk, vShipped); + + END WHILE; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketCollection_get.sql b/db/routines/vn/procedures/ticketCollection_get.sql new file mode 100644 index 000000000..357471fee --- /dev/null +++ b/db/routines/vn/procedures/ticketCollection_get.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCollection_get`(vTicketFk INT) +BEGIN + + SELECT tc.collectionFk + FROM vn.ticketCollection tc + WHERE ticketFk = vTicketFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketCollection_setUsedShelves.sql b/db/routines/vn/procedures/ticketCollection_setUsedShelves.sql new file mode 100644 index 000000000..c69575ba7 --- /dev/null +++ b/db/routines/vn/procedures/ticketCollection_setUsedShelves.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCollection_setUsedShelves`(vTicketFk INT, vUsedShelves INT) +BEGIN + + /* + * Inserta número de baldas que ocupa un ticket + * + * @param vTicketFk Identificador de ticket + * @param vUsedShelves Número de baldas + */ + + UPDATE ticketCollection tc + SET tc.usedShelves = vUsedShelves + WHERE tc.ticketFk = vTicketFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketComponentUpdate.sql b/db/routines/vn/procedures/ticketComponentUpdate.sql new file mode 100644 index 000000000..28af8b87f --- /dev/null +++ b/db/routines/vn/procedures/ticketComponentUpdate.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption INT) +BEGIN + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + IF vOption <> 8 THEN + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + END IF; + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketComponentUpdateSale.sql b/db/routines/vn/procedures/ticketComponentUpdateSale.sql new file mode 100644 index 000000000..fe11d1e83 --- /dev/null +++ b/db/routines/vn/procedures/ticketComponentUpdateSale.sql @@ -0,0 +1,184 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vOption INT) +BEGIN +/** + * A partir de la tabla tmp.sale, crea los Movimientos_componentes + * y modifica el campo Preu de la tabla Movimientos + * + * @param i_option integer tipo de actualizacion + * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk + **/ + DECLARE vComponentFk INT; + DECLARE vRenewComponents BOOLEAN; + DECLARE vKeepPrices BOOLEAN; + + CASE vOption + WHEN 1 THEN + SET vRenewComponents = TRUE; + SET vKeepPrices = FALSE; + WHEN 2 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'debtCollection'; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 3 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'mana'; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 4 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'buyerDiscount'; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + /* WHEN 5 THEN + SET vComponentFk = 35; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE;*/ + WHEN 6 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'imbalance'; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 7 THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk NOT IN (28, 29) + GROUP BY s.id; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk NOT IN (28, 29) + GROUP BY s.id; + + SET vRenewComponents = FALSE; + SET vKeepPrices = FALSE; + WHEN 8 THEN + DELETE sc.* + FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id; + + SET vRenewComponents = FALSE; + SET vKeepPrices = FALSE; + WHEN 9 THEN + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + END CASE; + + IF vRenewComponents THEN + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN `component` c ON c.id = sc.componentFk + WHERE c.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, tc.cost + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); + + -- Añadir componente venta por paquete + DROP TEMPORARY TABLE IF EXISTS tmp.sale2; + CREATE TEMPORARY TABLE tmp.sale2 + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT * FROM tmp.sale; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent2; + CREATE TEMPORARY TABLE tmp.ticketComponent2 + SELECT * FROM tmp.ticketComponent; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT t.id, t.componentFk, t.cost + FROM ( + SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN vn.buy b ON b.id = buy_id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + LEFT JOIN ( + SELECT s.id + FROM vn.sale s + JOIN tmp.sale2 tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent2 tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk + JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' + ) tp ON tp.id = s.id + WHERE tp.id IS NULL + HAVING resto <> 0) t; + + DROP TEMPORARY TABLE IF EXISTS + tmp.sale2, + tmp.ticketComponent2; + END IF; + + IF vKeepPrices THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE + UPDATE sale s + JOIN item i on i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.price = sumValue / ((100 - s.discount) / 100) + WHERE it.code != 'PRT' ; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.componentFk != 21 + GROUP BY s.id + HAVING ROUND(saleValue, 4) <> 0; + END IF; + + UPDATE sale s + JOIN ( + SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN `component` c ON c.id = sc.componentFk + JOIN componentType ct on ct.id = c.typeFk AND ct.isBase + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.priceFixed = sumValue, s.isPriceFixed = 1; + + DELETE sc.* + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN sale s on s.id = sc.saleFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT'; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 15, s.price + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN item i ON i.id = s.itemFK + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT' AND s.price > 0; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketDown_PrintableSelection.sql b/db/routines/vn/procedures/ticketDown_PrintableSelection.sql new file mode 100644 index 000000000..45002dd1f --- /dev/null +++ b/db/routines/vn/procedures/ticketDown_PrintableSelection.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketDown_PrintableSelection`(vSectorFk INT) +BEGIN + + UPDATE vn.ticketDown td + JOIN + (SELECT DISTINCT t.id + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + JOIN vn.itemShelving ish ON ish.id = iss.itemShelvingFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + WHERE p.sectorFk = vSectorFk + ) sub ON sub.id = td.ticketFk + JOIN vn.ticketDown_SelectionType tdst ON tdst.description = 'FREE' + JOIN vn.ticketDown_SelectionType tdst2 ON tdst2.description = 'SELECTED' + SET td.selected = tdst2.id + WHERE td.selected = tdst.id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketGetTaxAdd.sql b/db/routines/vn/procedures/ticketGetTaxAdd.sql new file mode 100644 index 000000000..55f587d9d --- /dev/null +++ b/db/routines/vn/procedures/ticketGetTaxAdd.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketGetTaxAdd`(vTicketFk INT) +BEGIN +/** + * Añade un ticket a la tabla tmp.ticket para calcular + * el IVA y el recargo de equivalencia y devuelve el resultado. + */ + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + SELECT vTicketFk ticketFk; + + CALL vn.ticket_getTax(NULL); + + SELECT + tt.ticketFk, + CAST(tt.taxableBase AS DECIMAL(10, 2)) AS taxableBase, + CAST(tt.rate * tt.taxableBase / 100 AS DECIMAL(10, 2)) AS tax, + pgc.*, + CAST(IF(pe.equFk IS NULL, taxableBase, 0) AS DECIMAL(10, 2)) AS Base, + pgc.rate / 100 as vatPercent + FROM tmp.ticketTax tt + JOIN vn.pgc ON pgc.code = tt.pgcFk + LEFT JOIN vn.pgcEqu pe ON pe.equFk = pgc.code; + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketTax; + DROP TEMPORARY TABLE tmp.ticketAmount; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketGetTax_new.sql b/db/routines/vn/procedures/ticketGetTax_new.sql new file mode 100644 index 000000000..f7c5891cc --- /dev/null +++ b/db/routines/vn/procedures/ticketGetTax_new.sql @@ -0,0 +1,66 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketGetTax_new`() + READS SQL DATA +BEGIN +/** + * Calcula la base imponible, el IVA y el recargo de equivalencia para + * un conjunto de tickets. + * + * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular + * @return tmp.ticketTax Impuesto desglosado para cada ticket + * @return tmp.ticketAmount + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany + (INDEX (addressFk, companyFk)) + ENGINE = MEMORY + SELECT DISTINCT t.addressFk, t.companyFk + FROM tmp.ticket tmpTicket + JOIN ticket t ON t.id = tmpTicket.ticketFk; + + CALL addressTaxArea (); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; + CREATE TEMPORARY TABLE tmp.ticketTax + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT tmpTicket.ticketFk, + bp.pgcFk, + SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) + ) AS taxableBase, + SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) + ) * pgc.rate / 100 AS tax, + tc.code + + FROM tmp.ticket tmpTicket + JOIN sale s ON s.ticketFk = tmpTicket.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = tmpTicket.ticketFk + JOIN supplier su ON su.id = t.companyFk + JOIN tmp.addressTaxArea ata + ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk + JOIN itemTaxCountry itc + ON itc.itemFk = i.id AND itc.countryFk = su.countryFk + JOIN bookingPlanner bp + ON bp.countryFk = su.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = itc.taxClassFk + JOIN pgc ON pgc.code = bp.pgcFk + JOIN taxClass tc ON tc.id = bp.taxClassFk + GROUP BY tmpTicket.ticketFk, pgc.code + HAVING taxableBase != 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; + CREATE TEMPORARY TABLE tmp.ticketAmount + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, taxableBase, SUM(tax) tax + FROM tmp.ticketTax + GROUP BY ticketFk, code; + + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketGetTotal.sql b/db/routines/vn/procedures/ticketGetTotal.sql new file mode 100644 index 000000000..b77f261b0 --- /dev/null +++ b/db/routines/vn/procedures/ticketGetTotal.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketGetTotal`(vTaxArea VARCHAR(25)) +BEGIN +/** + * Calcula el total con IVA para un conjunto de tickets. + * + * @param vTaxArea + * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular + * @return tmp.ticketTotal Total para cada ticket + */ + CALL ticket_getTax(vTaxArea); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTotal; + CREATE TEMPORARY TABLE tmp.ticketTotal + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT t.ticketFk, + IFNULL(SUM(ta.taxableBase + ta.tax), 0.0) AS total, + SUM(ta.taxableBase) totalWithoutVat + FROM tmp.ticket t + LEFT JOIN tmp.ticketAmount ta ON t.ticketFk = ta.ticketFk + GROUP BY ticketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketGetVisibleAvailable.sql b/db/routines/vn/procedures/ticketGetVisibleAvailable.sql new file mode 100644 index 000000000..07dfa69e5 --- /dev/null +++ b/db/routines/vn/procedures/ticketGetVisibleAvailable.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketGetVisibleAvailable`( + vTicket INT) +BEGIN + DECLARE vVisibleCalc INT; + DECLARE vAvailableCalc INT; + DECLARE vShipped DATE; + DECLARE vWarehouse TINYINT; + DECLARE vAlertLevel INT; + + SELECT t.warehouseFk, t.shipped, ts.alertLevel INTO vWarehouse, vShipped, vAlertLevel + FROM ticket t + LEFT JOIN ticketState ts ON ts.ticketFk = vTicket + WHERE t.id = vTicket; + + IF vAlertLevel IS NULL OR vAlertLevel = 0 THEN + IF vShipped >= util.VN_CURDATE() THEN + CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped); + END IF; + IF vShipped = util.VN_CURDATE() THEN + CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse); + END IF; + END IF; + + SELECT s.id, s.itemFk, s.quantity, s.concept, s.price, s.reserved, s.discount, v.visible, av.available, it.image, it.subName + FROM sale s + LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCalc + LEFT JOIN cache.available av ON av.item_id = s.itemFk AND av.calc_id = vAvailableCalc + LEFT JOIN item it ON it.id = s.itemFk + WHERE s.ticketFk = vTicket + ORDER BY s.concept; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketMissed_List.sql b/db/routines/vn/procedures/ticketMissed_List.sql new file mode 100644 index 000000000..c35852b15 --- /dev/null +++ b/db/routines/vn/procedures/ticketMissed_List.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketMissed_List`(vTicketFk INT) +BEGIN + + DECLARE vParkingFk INT; + DECLARE vParked DATETIME; + DECLARE vLevel INT; + DECLARE vCollectionFk INT; + + SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) + INTO vLevel, vCollectionFk + FROM vn.ticketCollection + WHERE ticketFk = vTicketFk + LIMIT 1; + + SELECT created, parkingFk + INTO vParked, vParkingFk + FROM vn.ticketParking + WHERE ticketFk = vTicketFk; + + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia + FROM vn.ticketParking tp + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.zone z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + JOIN vn.state s ON s.id = tst.state + WHERE (s.alertLevel < 2 + AND tp.parkingFk = vParkingFk + AND sc.isPackagingArea + AND ( + ( + ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) + OR + ( tc.collectionFk = vCollectionFk AND LEFT(tc.level,1) < LEFT(vLevel,1) ) + ) + )) -- Etiquetas que no se han escaneado y ya estamos con una posterior + OR + (s.alertLevel > 1 + AND tp.parkingFk = vParkingFk + AND sc.isPackagingArea + AND tp.created < vParked + AND t.packages <=> 0); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketNotInvoicedByClient.sql b/db/routines/vn/procedures/ticketNotInvoicedByClient.sql new file mode 100644 index 000000000..cb177b6d0 --- /dev/null +++ b/db/routines/vn/procedures/ticketNotInvoicedByClient.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketNotInvoicedByClient`(vClientFk INT) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + + CREATE TEMPORARY TABLE tmp.ticket + SELECT id ticketFk + FROM ticket + WHERE refFk IS NULL + AND clientFk = vClientFk + AND shipped > '2001-01-01'; + + CALL vn.ticketGetTotal(NULL); + + SELECT c.id, + c.name as Cliente, + t.shipped as Fecha, + t.id as Id_Ticket, + CAST(tt.total AS DECIMAL(10,2)) as Importe + FROM tmp.ticketTotal tt + JOIN ticket t ON t.id = tt.ticketFk + JOIN client c ON c.id = t.ClientFk; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticketTotal; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketObservation_addNewBorn.sql b/db/routines/vn/procedures/ticketObservation_addNewBorn.sql new file mode 100644 index 000000000..f70a11a48 --- /dev/null +++ b/db/routines/vn/procedures/ticketObservation_addNewBorn.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketObservation_addNewBorn`(vTicketFk INT) +BEGIN + + /** + * Inserta observaciones para los tickets con clientes nuevos o recuperados + * + * @param vTicketFk Identificador de vn.ticket + */ + + DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! '; + + INSERT INTO vn.ticketObservation(ticketFk, observationTypeFk, description) + SELECT vTicketFk, ot.id, vDescription + FROM vn.observationType ot + WHERE ot.hasNewBornMessage + ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description); + +END$$ +DELIMITER ; diff --git a/db/.archive/231001/03-ticketPackaging_add.sql b/db/routines/vn/procedures/ticketPackaging_add.sql similarity index 98% rename from db/.archive/231001/03-ticketPackaging_add.sql rename to db/routines/vn/procedures/ticketPackaging_add.sql index a7cf1d1d3..d669b95f5 100644 --- a/db/.archive/231001/03-ticketPackaging_add.sql +++ b/db/routines/vn/procedures/ticketPackaging_add.sql @@ -1,7 +1,4 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticketPackaging_add`; - DELIMITER $$ -$$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketPackaging_add`( vClientFk INT, vDated DATE, @@ -138,4 +135,4 @@ BEGIN DROP TEMPORARY TABLE tmp.packagingToInvoice; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketParking_findSkipped.sql b/db/routines/vn/procedures/ticketParking_findSkipped.sql new file mode 100644 index 000000000..1da3e2a7f --- /dev/null +++ b/db/routines/vn/procedures/ticketParking_findSkipped.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1)) +BEGIN + +/** + * Averigua los tickets que se han saltado por un error en el proceso encajado + * @param vTicketFk Ticket + * @param vItemPackingTypeFk Modo de encajado + * @return un select con los tickets afectados + */ + + DECLARE vParkingFk INT; + DECLARE vParked DATETIME; + DECLARE vLevel INT; + DECLARE vWagon INT; + DECLARE vCollectionFk INT; + + SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) + INTO vLevel, vWagon, vCollectionFk + FROM vn.ticketCollection tc + JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk + WHERE ticketFk = vTicketFk + ORDER BY c.id DESC + LIMIT 1; + + SELECT created, parkingFk + INTO vParked, vParkingFk + FROM vn.ticketParking tp + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE ticketFk = vTicketFk + AND s.itemPackingTypeFk = vItemPackingTypeFk + AND s.isPackagingArea ; + + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia + FROM vn.ticketParking tp + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.zone z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + JOIN vn.state s ON s.id = tst.state + WHERE (s.alertLevel < 2 + AND tp.parkingFk = vParkingFk + AND sc.isPackagingArea + AND ( + ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) + OR + ( tc.collectionFk = vCollectionFk + AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) + OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) + ) + ) + ) -- Etiquetas que no se han escaneado y ya estamos con una posterior + OR + (s.alertLevel > 1 + AND tp.parkingFk = vParkingFk + AND sc.isPackagingArea + AND tp.created < vParked + AND t.packages <=> 0); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketRefund_beforeUpsert.sql b/db/routines/vn/procedures/ticketRefund_beforeUpsert.sql new file mode 100644 index 000000000..5a0e99318 --- /dev/null +++ b/db/routines/vn/procedures/ticketRefund_beforeUpsert.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRefund_beforeUpsert`(vRefundTicketFk INT, vOriginalTicketFk INT) +BEGIN + DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + + IF vRefundTicketFk = vOriginalTicketFk THEN + CALL util.throw('Original ticket and refund ticket has same id'); + END IF; + + SELECT COUNT(*) INTO vAlreadyExists + FROM ticketRefund + WHERE refundTicketFk = vOriginalTicketFk; + + IF vAlreadyExists > 0 THEN + CALL util.throw('This ticket is already a refund'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketRequest_Add.sql b/db/routines/vn/procedures/ticketRequest_Add.sql new file mode 100644 index 000000000..5ba347fef --- /dev/null +++ b/db/routines/vn/procedures/ticketRequest_Add.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRequest_Add`(vDescription VARCHAR(255), vQuantity INT, vPrice DOUBLE, vTicketFk INT, vBuyerCode VARCHAR(3)) +BEGIN + + INSERT INTO vn.ticketRequest(description, + quantity, + price, + ticketFk, + buyerCode, + requesterFk) + VALUES(vDescription, + vQuantity, + vPrice, + vTicketFk, + vBuyerCode, + vn.getUser()); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketStateToday_setState.sql b/db/routines/vn/procedures/ticketStateToday_setState.sql new file mode 100644 index 000000000..98e5ee480 --- /dev/null +++ b/db/routines/vn/procedures/ticketStateToday_setState.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45)) +BEGIN + + /* Modifica el estado de un ticket de hoy + * + * @param vTicketFk el id del ticket + * @param vStateCode estado a modificar del ticket + * + */ + + DECLARE vAlertLevel INT; + + SELECT s.alertLevel INTO vAlertLevel + FROM state s + JOIN ticketStateToday tst ON tst.state = s.id + WHERE tst.ticket = vTicketFk + LIMIT 1; + + IF vAlertLevel < 2 THEN + + CALL vn.ticket_setState(vTicketFk, vStateCode); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketStateUpdate.sql b/db/routines/vn/procedures/ticketStateUpdate.sql new file mode 100644 index 000000000..4e19b7eb4 --- /dev/null +++ b/db/routines/vn/procedures/ticketStateUpdate.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) +BEGIN + + /* + * @deprecated:utilizar ticket_setState + */ + + DECLARE vAlertLevel INT; + + SELECT s.alertLevel INTO vAlertLevel + FROM vn.state s + JOIN vn.ticketState ts ON ts.stateFk = s.id + WHERE ts.ticketFk = vTicketFk; + + IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN + + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) + SELECT id, vTicketFk, account.myUser_getId() + FROM vn.state + WHERE `code` = vStateCode collate utf8_unicode_ci; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketToInvoiceByAddress.sql b/db/routines/vn/procedures/ticketToInvoiceByAddress.sql new file mode 100644 index 000000000..ad51c761a --- /dev/null +++ b/db/routines/vn/procedures/ticketToInvoiceByAddress.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketToInvoiceByAddress`( + vStarted DATE, + vEnded DATETIME, + vAddress INT, + vCompany INT + ) +BEGIN + + SET vEnded = util.dayEnd(vEnded); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice; + + CREATE TEMPORARY TABLE tmp.ticketToInvoice + SELECT id + FROM vn.ticket + WHERE addressFk = vAddress + AND companyFk = vCompany + AND shipped BETWEEN vStarted AND vEnded + AND refFk IS NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketToInvoiceByDate.sql b/db/routines/vn/procedures/ticketToInvoiceByDate.sql new file mode 100644 index 000000000..8937ab7ae --- /dev/null +++ b/db/routines/vn/procedures/ticketToInvoiceByDate.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketToInvoiceByDate`( + vStarted DATE, + vEnded DATETIME, + vClient INT, + vCompany INT + ) +BEGIN + + SET vEnded = util.dayEnd(vEnded); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice; + + CREATE TEMPORARY TABLE tmp.ticketToInvoice + SELECT id + FROM vn.ticket + WHERE clientFk = vClient + AND companyFk = vCompany + AND shipped BETWEEN vStarted AND vEnded + AND refFk IS NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketToInvoiceByRef.sql b/db/routines/vn/procedures/ticketToInvoiceByRef.sql new file mode 100644 index 000000000..4f5c23ba2 --- /dev/null +++ b/db/routines/vn/procedures/ticketToInvoiceByRef.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketToInvoiceByRef`(IN vInvoiceRef VARCHAR(15)) +BEGIN + +/* Para tickets ya facturados, vuelve a repetir el proceso de facturación. +* +* @param vInvoiceRef Factura +*/ + + DECLARE vInvoice INT; + DECLARE vCountry INT; + DECLARE vTaxArea VARCHAR(15); + DECLARE vSpainCountryCode INT DEFAULT 1; + + SELECT id + INTO vInvoice + FROM vn.invoiceOut + WHERE ref = vInvoiceRef; + + SELECT s.countryFk + INTO vCountry + FROM vn.supplier s + JOIN vn.invoiceOut io ON io.companyFk = s.id + WHERE io.id = vInvoice; + + SELECT IF( + c.isEqualizated + AND c.countryFk = vSpainCountryCode + AND i.taxAreaFk = 'NATIONAL', + 'EQU', + i.taxAreaFk + ) + INTO vTaxArea + FROM vn.invoiceOutSerial i + JOIN vn.invoiceOut io ON io.serial = i.code + JOIN vn.client c ON c.id = io.clientFk + WHERE io.id = vInvoice; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToInvoice; + + CREATE TEMPORARY TABLE tmp.ticketToInvoice + SELECT id + FROM vn.ticket + WHERE refFk = vInvoiceRef; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_Clone.sql b/db/routines/vn/procedures/ticket_Clone.sql new file mode 100644 index 000000000..7670e832e --- /dev/null +++ b/db/routines/vn/procedures/ticket_Clone.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) +BEGIN +/** + * Clona el contenido de un ticket en otro + * + * @param vOriginalTicket ticket Original + * @param vNewTicket ticket creado + */ + DECLARE vStateFk INT; + + INSERT INTO ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk, + priority, + hasPriority, + clonedFrom + ) + SELECT + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus, + routeFk, + priority, + hasPriority, + vOriginalTicket + FROM ticket + WHERE id = vOriginalTicket; + + SET vNewTicket = LAST_INSERT_ID(); + + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT vNewTicket, observationTypeFk, description + FROM ticketObservation + WHERE ticketFk = vOriginalTicket; + + INSERT INTO ticketTracking(ticketFk, stateFk, userFk, created) + SELECT vNewTicket, stateFk, userFk, created + FROM ticketTracking + WHERE ticketFk = vOriginalTicket + ORDER BY created; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruck.sql b/db/routines/vn/procedures/ticket_DelayTruck.sql new file mode 100644 index 000000000..7a3170d68 --- /dev/null +++ b/db/routines/vn/procedures/ticket_DelayTruck.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_DelayTruck`(vWarehouserFk INT, vHour INT, vMinute INT) +BEGIN + DECLARE done INT DEFAULT FALSE; + DECLARE vTicketFk INT; + DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + CALL vn.productionControl(vWarehouserFk,0) ; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT ticketFk + FROM tmp.productionBuffer + WHERE shipped = util.VN_CURDATE() + AND problem LIKE '%I:%' + AND (HH <= vHour OR HH = vHour AND mm < vMinute) + AND alertLevel = 0; + + OPEN cur1; + + read_loop: LOOP + FETCH cur1 INTO vTicketFk; + IF done THEN + LEAVE read_loop; + END IF; + + CALL vn.ticket_DelayTruckSplit(vTicketFk); + END LOOP; + + CLOSE cur1; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruckSplit.sql b/db/routines/vn/procedures/ticket_DelayTruckSplit.sql new file mode 100644 index 000000000..c7de6a984 --- /dev/null +++ b/db/routines/vn/procedures/ticket_DelayTruckSplit.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_DelayTruckSplit`(vTicketFk INT) +BEGIN +/** + * Splita las lineas de ticket que no estan ubicadas + * + * @param vTicketFk Id ticket + */ + DECLARE vNewTicketFk INT; + DECLARE vTotalLines INT; + DECLARE vLinesToSplit INT; + + DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit; + + SELECT COUNT(*) INTO vTotalLines + FROM sale + WHERE ticketFk = vTicketFk; + + CREATE TEMPORARY TABLE tmp.SalesToSplit + SELECT s.id saleFk + FROM ticket t + JOIN sale s ON t.id = s.ticketFk + LEFT JOIN ( + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk + ) issw ON issw.itemFk = s.itemFk + AND issw.warehouseFk = t.warehouseFk + WHERE s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND t.id = vTicketFk; + + SELECT COUNT(*) INTO vLinesToSplit + FROM tmp.SalesToSplit; + + IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN + SET vNewTicketFk = vTicketFk; + ELSE + CALL ticket_Clone(vTicketFk, vNewTicketFk); + UPDATE sale s + JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id + SET s.ticketFk = vNewTicketFk; + END IF; + + CALL ticketStateUpdate(vNewTicketFk, 'FIXING'); + + DROP TEMPORARY TABLE tmp.SalesToSplit; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_WeightDeclaration.sql b/db/routines/vn/procedures/ticket_WeightDeclaration.sql new file mode 100644 index 000000000..e50290dd8 --- /dev/null +++ b/db/routines/vn/procedures/ticket_WeightDeclaration.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_WeightDeclaration`(vClientFk INT, vDated DATE) +BEGIN + + DECLARE vTheorycalWeight DECIMAL(10,2); + DECLARE vRealWeight DECIMAL(10,2); + DECLARE vRatio DOUBLE; + + SELECT IFNULL(sum(tob.description),0) INTO vRealWeight + FROM vn.ticketObservation tob + JOIN vn.observationType ot ON ot.id = tob.observationTypeFk + JOIN vn.ticket t ON t.id = tob.ticketFk + WHERE ot.description = 'Peso Aduana' + AND t.clientFk = vClientFk + AND t.shipped BETWEEN vDated AND util.dayend(vDated); + + SELECT sum(IF(sv.physicalWeight = 0, sv.weight, sv.physicalWeight)) INTO vTheorycalWeight + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.saleVolume sv ON sv.saleFk = s.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk + WHERE t.clientFk = vClientFk + AND t.shipped BETWEEN vDated AND util.dayend(vDated); + + SET vRatio = vRealWeight / vTheorycalWeight; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketWeight; + + CREATE TEMPORARY TABLE tmp.ticketWeight + ENGINE = MEMORY + SELECT i.intrastatFk, + ib.ediBotanic, + FLOOR(sum(s.quantity)) as quantity, + CAST(vRatio * SUM(IF(sv.physicalWeight = 0, sv.weight, sv.physicalWeight) ) AS DECIMAL(10,2)) physicalWeight, + o.code as countryCode, + vDated as Dated + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.saleVolume sv ON sv.saleFk = s.id + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN vn.itemBotanicalWithGenus ib ON ib.itemFk = i.id + LEFT JOIN vn.origin o ON o.id = i.originFk + WHERE t.clientFk = vClientFk + AND t.shipped BETWEEN vDated AND util.dayend(vDated) + GROUP BY ib.ediBotanic, o.code; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_add.sql b/db/routines/vn/procedures/ticket_add.sql new file mode 100644 index 000000000..5c3c28081 --- /dev/null +++ b/db/routines/vn/procedures/ticket_add.sql @@ -0,0 +1,123 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_add`( + vClientId INT + ,vShipped DATE + ,vWarehouseFk INT + ,vCompanyFk INT + ,vAddressFk INT + ,vAgencyModeFk INT + ,vRouteFk INT + ,vlanded DATE + ,vUserId INT + ,vIsRequiredZone INT + ,OUT vNewTicket INT) +BEGIN +/** +* Crea un ticket, +* ¡¡NO se debe llamar directamente, llamar a salix que hace comprobaciones previas!! +* +* @param vClientId id del cliente +* @param vShipped dia preparacion +* @param vWarehouseFk id del warehouse +* @param vCompanyFk id la empresa +* @param vAddressFk id del consignatario +* @param vAgencyModeFk id de la agencia +* @param vRouteFk id de la ruta | NULL +* @param vlanded dia llegada +* @param vUserId que crea el ticket +* @param vIsRequiredZone Indica si tiene que tener zona valida para ser creado +* @return vNewTicket id del ticket creado +*/ + DECLARE vZoneFk INT; + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + DECLARE vIsActive BOOL; + + IF vClientId IS NULL THEN + CALL util.throw ('CLIENT_NOT_ESPECIFIED'); + END IF; + + SELECT isActive INTO vIsActive + FROM vn.client + WHERE id = vClientId; + + IF NOT vIsActive THEN + CALL util.throw ('CLIENT_NOT_ACTIVE'); + END IF; + + IF NOT vAddressFk OR vAddressFk IS NULL THEN + SELECT id INTO vAddressFk + FROM address + WHERE clientFk = vClientId + AND isDefaultAddress; + END IF; + + IF vAgencyModeFk IS NOT NULL THEN + CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); + + SELECT zoneFk, price, bonus + INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped = vShipped + AND warehouseFk = vWarehouseFk + LIMIT 1; + + IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN + CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); + END IF; + END IF; + + INSERT INTO ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + routeFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus + ) + SELECT vClientId, + vShipped, + a.id, + vAgencyModeFk, + a.nickname, + vWarehouseFk, + IF(vRouteFk,vRouteFk,NULL), + vCompanyFk, + vlanded, + vZoneFk, + vPrice, + vBonus + 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; + + IF (SELECT COUNT(*) + FROM bs.clientNewBorn cnb + WHERE cnb.clientFk = vClientId + AND NOT cnb.isRookie) = 0 THEN + + CALL vn.ticketObservation_addNewBorn(vNewTicket); + END IF; + + 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 ticketTracking(stateFk, ticketFk, userFk) + SELECT id, vNewTicket, account.myUser_getId() + FROM state + WHERE `code` = 'DELIVERED'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_administrativeCopy.sql b/db/routines/vn/procedures/ticket_administrativeCopy.sql new file mode 100644 index 000000000..f240a5fe0 --- /dev/null +++ b/db/routines/vn/procedures/ticket_administrativeCopy.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT) +BEGIN + + INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) + SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed + FROM vn.ticket t + JOIN vn.warehouse w ON w.name = 'INVENTARIO' + WHERE t.id = vOriginalTicket; + + SELECT LAST_INSERT_ID() INTO vNewTicket; + + INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) + SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount + FROM vn.sale s + WHERE s.ticketFk = vOriginalTicket; + +END$$ +DELIMITER ; diff --git a/db/changes/234801/00-ticket_canAdvance_update.sql b/db/routines/vn/procedures/ticket_canAdvance.sql similarity index 99% rename from db/changes/234801/00-ticket_canAdvance_update.sql rename to db/routines/vn/procedures/ticket_canAdvance.sql index afe0a4dc6..8852a3010 100644 --- a/db/changes/234801/00-ticket_canAdvance_update.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -1,5 +1,4 @@ DELIMITER $$ -$$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) BEGIN /** diff --git a/db/.archive/232201/00-procedurecanbePostponed.sql b/db/routines/vn/procedures/ticket_canMerge.sql similarity index 55% rename from db/.archive/232201/00-procedurecanbePostponed.sql rename to db/routines/vn/procedures/ticket_canMerge.sql index 39aa35cd5..c3f211027 100644 --- a/db/.archive/232201/00-procedurecanbePostponed.sql +++ b/db/routines/vn/procedures/ticket_canMerge.sql @@ -1,34 +1,24 @@ DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vWarehouseFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canMerge`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) BEGIN /** * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * - * @param vOriginDated Fecha en cuestión - * @param vFutureDated Fecha en el futuro a sondear + * + * @param vDated Fecha en cuestión + * @param vScopeDays Dias en el futuro a sondear + * @param vLitersMax Volumen máximo de los tickets a catapultar + * @param vLinesMax Número máximo de lineas de los tickets a catapultar * @param vWarehouseFk Identificador de vn.warehouse */ - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT sv.ticketFk id, - sub2.id futureId, + SELECT sv.ticketFk, GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, + CAST(SUM(litros) AS DECIMAL(10,0)) liters, + CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, st.name state, - sub2.iptd futureIpt, - sub2.state futureState, - t.clientFk, - t.warehouseFk, - ts.alertLevel, - t.shipped, - sub2.shipped futureShipped, - t.workerFk, - st.code stateCode, - sub2.code futureStateCode, - st.classColor + sub2.id ticketFuture, + sub2.shipped, + sub2.iptd tfIpt, + sub2.state tfState FROM vn.saleVolume sv JOIN vn.sale s ON s.id = sv.saleFk JOIN vn.item i ON i.id = s.itemFk @@ -43,30 +33,33 @@ BEGIN LEFT JOIN ( SELECT * FROM ( - SELECT - t.addressFk, - t.id, - t.shipped, - st.name state, - st.code code, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd + SELECT t.addressFk, + t.id, + t.shipped, + st.name state, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk + ORDER BY i.itemPackingTypeFk) iptd FROM vn.ticket t JOIN vn.ticketState ts ON ts.ticketFk = t.id JOIN vn.state st ON st.id = ts.stateFk JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.alertLevel al ON al.id = st.alertLevel JOIN vn.item i ON i.id = s.itemFk - WHERE t.shipped BETWEEN vFutureDated - AND util.dayend(vFutureDated) + WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated) + AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated)) AND t.warehouseFk = vWarehouseFk + AND al.code = 'FREE' GROUP BY t.id ) sub GROUP BY sub.addressFk ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id - WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated) + WHERE t.shipped BETWEEN vDated AND util.dayend(vDated) AND t.warehouseFk = vWarehouseFk AND al.code = 'FREE' AND tp.ticketFk IS NULL GROUP BY sv.ticketFk - HAVING futureId; + HAVING liters <= vLitersMax + AND `lines` <= vLinesMax + AND ticketFuture; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/.archive/232202/00-procedurecanbePostponed.sql b/db/routines/vn/procedures/ticket_canbePostponed.sql similarity index 94% rename from db/.archive/232202/00-procedurecanbePostponed.sql rename to db/routines/vn/procedures/ticket_canbePostponed.sql index 9d42dcc4b..a88099fed 100644 --- a/db/.archive/232202/00-procedurecanbePostponed.sql +++ b/db/routines/vn/procedures/ticket_canbePostponed.sql @@ -1,5 +1,4 @@ DELIMITER $$ -$$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vWarehouseFk INT) BEGIN /** @@ -9,10 +8,9 @@ BEGIN * @param vFutureDated Fecha en el futuro a sondear * @param vWarehouseFk Identificador de vn.warehouse */ - DROP TEMPORARY TABLE IF EXISTS tmp.filter; - CREATE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT sv.ticketFk id, + CREATE OR REPLACE TEMPORARY TABLE tmp.filter + (INDEX (id)) + SELECT sv.ticketFk id, sub2.id futureId, GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, CAST(sum(litros) AS DECIMAL(10,0)) liters, diff --git a/db/routines/vn/procedures/ticket_checkNoComponents.sql b/db/routines/vn/procedures/ticket_checkNoComponents.sql new file mode 100644 index 000000000..6b3e75e85 --- /dev/null +++ b/db/routines/vn/procedures/ticket_checkNoComponents.sql @@ -0,0 +1,45 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) +BEGIN + +/** + * Comprueba que los tickets entre un rango de fechas tienen componentes + * y recalcula sus componentes + * + * @param vShippedFrom rango inicial de fecha + * @param vShippedTo rango final de fecha + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.coste + (primary key (id)) ENGINE = MEMORY + SELECT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 + WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo + AND ic.merchandise; + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (primary key (id)) ENGINE = MEMORY + SELECT DISTINCT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo + AND c.id IS NULL + AND ic.merchandise; + + CALL vn.sale_recalcComponent(1); + + DROP TEMPORARY TABLE tmp.recalculateSales; + DROP TEMPORARY TABLE tmp.coste; + END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_cloneWeekly.sql b/db/routines/vn/procedures/ticket_cloneWeekly.sql new file mode 100644 index 000000000..6bceb2fdf --- /dev/null +++ b/db/routines/vn/procedures/ticket_cloneWeekly.sql @@ -0,0 +1,202 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_cloneWeekly`(vDateFrom DATE, vDateTo DATE) +BEGIN + DECLARE vIsDone BOOL; + DECLARE vLanding DATE; + DECLARE vShipment DATE; + DECLARE vWarehouseFk INT; + DECLARE vTicketFk INT; + DECLARE vClientFk INT; + DECLARE vCompanyFk INT; + DECLARE vAddressFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vNewTicket INT; + DECLARE vYear INT; + DECLARE vSalesPersonFK INT; + DECLARE vItemPicker INT; + + DECLARE rsTicket CURSOR FOR + SELECT tt.ticketFk, + t.clientFk, + t.warehouseFk, + t.companyFk, + t.addressFk, + tt.agencyModeFk, + ti.dated + FROM ticketWeekly tt + JOIN ticket t ON tt.ticketFk = t.id + JOIN tmp.time ti + WHERE WEEKDAY(ti.dated) = tt.weekDay; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; + + CALL `util`.`time_generate`(vDateFrom,vDateTo); + + OPEN rsTicket; + myLoop: LOOP + BEGIN + DECLARE vSalesPersonEmail VARCHAR(150); + DECLARE vIsDuplicateMail BOOL; + DECLARE vSubject VARCHAR(150); + DECLARE vMessage TEXT; + + SET vIsDone = FALSE; + FETCH rsTicket INTO vTicketFk,vClientFk, vWarehouseFk, vCompanyFk, vAddressFk, vAgencyModeFk,vShipment; + + IF vIsDone THEN + LEAVE myLoop; + END IF; + + -- busca si el ticket ya ha sido clonado + IF EXISTS (SELECT TRUE FROM ticket tOrig + JOIN sale saleOrig ON tOrig.id = saleOrig.ticketFk + JOIN saleCloned sc ON sc.saleOriginalFk = saleOrig.id + JOIN sale saleClon ON saleClon.id = sc.saleClonedFk + JOIN ticket tClon ON tClon.id = saleClon.ticketFk + WHERE tOrig.id = vTicketFk + AND tClon.isDeleted = FALSE + AND DATE(tClon.shipped) = vShipment) + THEN + ITERATE myLoop; + END IF; + + IF vAgencyModeFk IS NULL THEN + SELECT agencyModeFk INTO vAgencyModeFk + FROM address + WHERE clientFk = vClientFk + AND isDefaultAddress; + END IF; + + CALL zone_getLanded(vShipment, vAddressFk, vAgencyModeFk, vWarehouseFk,FALSE); + SET vLanding = NULL; + SELECT landed INTO vLanding FROM tmp.zoneGetLanded LIMIT 1; + + CALL ticket_add( + vClientFk, + vShipment, + vWarehouseFk, + vCompanyFk, + vAddressFk, + vAgencyModeFk, + NULL, + vLanding, + account.myUser_getId(), + FALSE, + vNewTicket); + + UPDATE ticket + SET clonedFrom = vTicketFk + WHERE id = vNewTicket; + + INSERT INTO sale (ticketFk, itemFk, concept, quantity, price, + discount, priceFixed, isPriceFixed) + SELECT vNewTicket, + saleOrig.itemFk, + saleOrig.concept, + saleOrig.quantity, + saleOrig.price, + saleOrig.discount, + saleOrig.priceFixed, + saleOrig.isPriceFixed + FROM sale saleOrig + WHERE saleOrig.ticketFk = vTicketFk; + + INSERT IGNORE INTO saleCloned(saleOriginalFk, saleClonedFk) + SELECT saleOriginal.id, saleClon.id + FROM sale saleOriginal + JOIN sale saleClon ON saleOriginal.itemFk = saleClon.itemFk + AND saleOriginal.quantity = saleClon.quantity + WHERE saleOriginal.ticketFk = vTicketFk + AND saleClon.ticketFk = vNewTicket; + + INSERT INTO ticketRequest (description, + ordered, + shipped, + quantity, + price, + itemFk, + clientFk, + response, + total, + buyed, + requesterFk + ,attenderFk, + ticketFk) + SELECT description, + ordered, + shipped, + quantity, + price, + itemFk, + clientFk, + response, + total, + buyed, + requesterFk, + attenderFk, + vNewTicket + FROM ticketRequest + WHERE ticketFk =vTicketFk; + + SELECT id INTO vSalesPersonFK + FROM observationType + WHERE code = 'salesPerson'; + + SELECT id INTO vItemPicker + FROM observationType + WHERE code = 'itemPicker'; + + INSERT INTO ticketObservation( + ticketFk, + observationTypeFk, + description) + VALUES( + vNewTicket, + vSalesPersonFK, + CONCAT('turno desde ticket: ',vTicketFk)) + ON DUPLICATE KEY UPDATE description = + CONCAT(ticketObservation.description,VALUES(description),' '); + + INSERT INTO ticketObservation(ticketFk, + observationTypeFk, + description) + VALUES( + vNewTicket, + vItemPicker, + 'ATENCION: Contiene lineas de TURNO') + ON DUPLICATE KEY UPDATE description = + CONCAT(ticketObservation.description,VALUES(description),' '); + + IF (vLanding IS NULL) THEN + + SELECT e.email INTO vSalesPersonEmail + FROM client c + JOIN account.emailUser e ON e.userFk = c.salesPersonFk + WHERE c.id = vClientFk; + + SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', + vTicketFk,' para el dia: ', vShipment); + SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicketFk, + ' para el dia: ', vShipment, + ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', + vNewTicket, ' pero ha que revisar las fechas y la agencia'); + + SELECT COUNT(*) INTO vIsDuplicateMail + FROM mail + WHERE receiver = vSalesPersonEmail + AND subject = vSubject; + + IF NOT vIsDuplicateMail THEN + CALL mail_insert(vSalesPersonEmail, NULL, vSubject, vMessage); + END IF; + CALL ticketStateUpdate (vNewTicket, 'FIXING'); + ELSE + CALL ticketCalculateClon(vNewTicket, vTicketFk); + END IF; + + END; + END LOOP; + CLOSE rsTicket; + DROP TEMPORARY TABLE IF EXISTS tmp.time; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql new file mode 100644 index 000000000..91e0979cd --- /dev/null +++ b/db/routines/vn/procedures/ticket_close.sql @@ -0,0 +1,103 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_close`() +BEGIN +/** + * Realiza el cierre de todos los + * tickets de la tabla tmp.ticket_close. + * + * @table tmp.ticket_close(ticketFk) Identificadores de los tickets a cerrar + */ + DECLARE vDone BOOL; + DECLARE vClientFk INT; + DECLARE vCurTicketFk INT; + DECLARE vIsTaxDataChecked BOOL; + DECLARE vCompanyFk INT; + DECLARE vShipped DATE; + DECLARE vNewInvoiceId INT; + DECLARE vHasDailyInvoice BOOL; + DECLARE vWithPackage BOOL; + DECLARE vHasToInvoice BOOL; + + DECLARE cur CURSOR FOR + SELECT ticketFk FROM tmp.ticket_close; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + RESIGNAL; + END; + + OPEN cur; + + proc: LOOP + SET vDone = FALSE; + + FETCH cur INTO vCurTicketFk; + + IF vDone THEN + LEAVE proc; + END IF; + + SELECT + c.id, + c.isTaxDataChecked, + t.companyFk, + t.shipped, + IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), + w.isManaged, + c.hasToInvoice + INTO vClientFk, + vIsTaxDataChecked, + vCompanyFk, + vShipped, + vHasDailyInvoice, + vWithPackage, + vHasToInvoice + FROM ticket t + JOIN `client` c ON c.id = t.clientFk + JOIN province p ON p.id = c.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + JOIN country co ON co.id = p.countryFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.id = vCurTicketFk; + + INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) + (SELECT vCurTicketFk, p.id, COUNT(*) + FROM expedition e + JOIN packaging p ON p.itemFk = e.freightItemFk + WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable + AND vWithPackage + GROUP BY p.itemFk); + + -- No retornables o no catalogados + INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) + (SELECT e.freightItemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.freightItemFk, vClientFk), 1 + FROM expedition e + JOIN item i ON i.id = e.freightItemFk + LEFT JOIN packaging p ON p.itemFk = i.id + WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 + AND getSpecialPrice(e.freightItemFk, vClientFk) > 0 + GROUP BY e.freightItemFk); + + IF(vHasDailyInvoice) AND vHasToInvoice THEN + + -- Facturacion rapida + CALL ticket_setState(vCurTicketFk, 'DELIVERED'); + -- Facturar si está contabilizado + IF vIsTaxDataChecked THEN + CALL invoiceOut_newFromClient( + vClientFk, + (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), + vShipped, + vCompanyFk, + NULL, + NULL, + vNewInvoiceId); + END IF; + ELSE + CALL ticket_setState(vCurTicketFk, (SELECT vn.getAlert3State(vCurTicketFk))); + END IF; + END LOOP; + + CLOSE cur; +END$$ +DELIMITER ; diff --git a/db/.archive/224702/00-ticket_closeByTicket.sql b/db/routines/vn/procedures/ticket_closeByTicket.sql similarity index 58% rename from db/.archive/224702/00-ticket_closeByTicket.sql rename to db/routines/vn/procedures/ticket_closeByTicket.sql index f378b1146..93772225b 100644 --- a/db/.archive/224702/00-ticket_closeByTicket.sql +++ b/db/routines/vn/procedures/ticket_closeByTicket.sql @@ -1,35 +1,27 @@ -drop procedure `vn`.`ticket_closeByTicket`; - DELIMITER $$ -$$ -create - definer = `root`@`localhost` procedure `vn`.`ticket_closeByTicket`(IN vTicketFk int) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_closeByTicket`(IN vTicketFk int) BEGIN - /** * Inserta el ticket en la tabla temporal * para ser cerrado. * * @param vTicketFk Id del ticket */ - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_close; CREATE TEMPORARY TABLE tmp.ticket_close ENGINE = MEMORY ( - SELECT + SELECT t.id AS ticketFk FROM ticket t - JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN agencyMode am ON am.id = t.agencyModeFk LEFT JOIN ticketState ts ON ts.ticketFk = t.id - JOIN alertLevel al ON al.id = ts.alertLevel + JOIN alertLevel al ON al.id = ts.alertLevel WHERE al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered') - AND t.id = vTicketFk + AND t.id = vTicketFk AND t.refFk IS NULL GROUP BY t.id); - + CALL ticket_close(); - DROP TEMPORARY TABLE tmp.ticket_close; + DROP TEMPORARY TABLE tmp.ticket_close; END$$ DELIMITER ; - - diff --git a/db/routines/vn/procedures/ticket_componentMakeUpdate.sql b/db/routines/vn/procedures/ticket_componentMakeUpdate.sql new file mode 100644 index 000000000..001e7ebaa --- /dev/null +++ b/db/routines/vn/procedures/ticket_componentMakeUpdate.sql @@ -0,0 +1,99 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( + vTicketFk INT, + vClientFk INT, + vNickname VARCHAR(50), + vAgencyModeFk INT, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk INT, + vCompanyFk INT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption INT) +BEGIN + + /** + * Modifica en el ticket los campos que se le pasan por parámetro + * y cambia sus componentes + * + * @param vTicketFk Id del ticket a modificar + * @param vClientFk nuevo cliente + * @param vNickname nuevo alias + * @param vAgencyModeFk nueva agencia + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo almacen + * @param vCompanyFk nueva empresa + * @param vShipped nueva fecha del envio de mercancia + * @param vLanded nueva fecha de recepcion de mercancia + * @param vIsDeleted si se borra el ticket + * @param vHasToBeUnrouted si se le elimina la ruta al ticket + * @param vOption opcion para el case del proc ticketComponentUpdateSale + */ + + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + + CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.nickname = vNickname, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.zoneFk = vZoneFk, + t.zonePrice = vPrice, + t.zoneBonus = vBonus, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + IF vOption <> 8 THEN + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent + SELECT * FROM tmp.ticketComponentPreview; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_componentPreview.sql b/db/routines/vn/procedures/ticket_componentPreview.sql new file mode 100644 index 000000000..729e3a743 --- /dev/null +++ b/db/routines/vn/procedures/ticket_componentPreview.sql @@ -0,0 +1,101 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentPreview`( + vTicketFk INT, + vLanded DATE, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk SMALLINT) +BEGIN +/** + * Calcula los componentes de los articulos de un ticket + * + * @param vTicketFk id del ticket + * @param vLanded nueva fecha de entrega + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo warehouse + * + * @return tmp.ticketComponentPreview (warehouseFk, itemFk, componentFk, cost) + */ + DECLARE vHasDataChanged BOOL DEFAULT FALSE; + DECLARE vHasAddressChanged BOOL; + DECLARE vHasZoneChanged BOOL DEFAULT FALSE; + DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; + + DECLARE vShipped DATE; + DECLARE vAddressTypeRateFk INT DEFAULT NULL; + DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; + + DECLARE vHasChangeAll BOOL DEFAULT FALSE; + + SELECT DATE(landed) <> vLanded, + addressFk <> vAddressFk, + zoneFk <> vZoneFk, + warehouseFk <> vWarehouseFk + INTO + vHasDataChanged, + vHasAddressChanged, + vHasZoneChanged, + vHasWarehouseChanged + FROM vn.ticket t + WHERE t.id = vTicketFk; + + IF vHasDataChanged OR vHasWarehouseChanged THEN + SET vHasChangeAll = TRUE; + END IF; + + IF vHasAddressChanged THEN + SET vAddressTypeRateFk = 5; + END IF; + + IF vHasZoneChanged THEN + SET vAgencyModeTypeRateFk = 6; + END IF; + + SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped + FROM zone + WHERE id = vZoneFk; + + CALL buyUltimate(vWarehouseFk, vShipped); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; + CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( + SELECT + vWarehouseFk AS warehouseFk, + NULL AS available, + s.itemFk, + bu.buyFk, + vZoneFk zoneFk + FROM sale s + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY bu.warehouseFk, bu.itemFk); + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value + FROM saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN `component` c ON c.id = sc.componentFk + WHERE s.ticketFk = vTicketFk + AND (c.isRenewable = FALSE + OR + (NOT vHasChangeAll + AND (NOT (c.typeFk <=> vAddressTypeRateFk + OR c.typeFk <=> vAgencyModeTypeRateFk)))); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPreview; + CREATE TEMPORARY TABLE tmp.ticketComponentPreview + SELECT * FROM tmp.ticketComponent; + + CALL catalog_componentPurge(); + DROP TEMPORARY TABLE tmp.buyUltimate; + + IF vShipped IS NULL THEN + CALL util.throw('NO_ZONE_AVAILABLE'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_doCmr.sql b/db/routines/vn/procedures/ticket_doCmr.sql new file mode 100644 index 000000000..5789d09de --- /dev/null +++ b/db/routines/vn/procedures/ticket_doCmr.sql @@ -0,0 +1,89 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doCmr`(vSelf INT) +BEGIN +/** +* Crea u actualiza la información del CMR asociado con +* un ticket específico en caso de que sea necesario. +* +* @param vSelf El id del ticket +*/ + DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT; + SELECT cmrFk INTO vCmrFk + FROM ticket + WHERE id = vSelf; + + CREATE OR REPLACE TEMPORARY TABLE tTicket + SELECT wo.firstName, + v.numberPlate, + com.id companyFk, + a.id addressFk, + c2.defaultAddressFk, + su.id supplierFk, + t.landed + FROM ticket t + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN `state` s ON s.id = ts.stateFk + JOIN alertLevel al ON al.id = s.alertLevel + JOIN client c ON c.id = t.clientFk + JOIN `address` a ON a.id = t.addressFk + JOIN province p ON p.id = a.provinceFk + JOIN country co ON co.id = p.countryFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN company com ON com.id = t.companyFk + JOIN client c2 ON c2.id = com.clientFk + JOIN supplierAccount sa ON sa.id = com.supplierAccountFk + JOIN supplier su ON su.id = sa.supplierFk + LEFT JOIN route r ON r.id = t.routeFk + LEFT JOIN worker wo ON wo.id = r.workerFk + LEFT JOIN vehicle v ON v.id = r.vehicleFk + WHERE t.shipped BETWEEN util.yesterday() AND util.dayEnd(util.VN_CURDATE()) + AND al.code IN ('PACKED', 'DELIVERED') + AND co.code <> 'ES' + AND am.name <> 'ABONO' + AND w.code = 'ALG' + AND dm.code = 'DELIVERY' + AND t.id = vSelf + GROUP BY t.id; + + START TRANSACTION; + + IF vCmrFk THEN + UPDATE cmr c + JOIN tTicket t + SET c.senderInstruccions = t.firstName, + c.truckPlate = t.numberPlate, + c.companyFk = t.companyFk, + c.addressToFk = t.addressFk, + c.addressFromFk = t.defaultAddressFk, + c.supplierFk = t.supplierFk, + c.ead = t.landed + WHERE id = vCmrFk; + ELSE + SELECT MAX(id) INTO vPreviousCmrFk FROM cmr; + + INSERT INTO cmr ( + senderInstruccions, + truckPlate, + companyFk, + addressToFk, + addressFromFk, + supplierFk, + ead + ) + SELECT * FROM tTicket; + + SELECT MAX(id) INTO vCurrentCmrFk FROM cmr; + + IF vPreviousCmrFk <> vCurrentCmrFk THEN + UPDATE ticket + SET cmrFk = vCurrentCmrFk + WHERE id = vSelf; + END IF; + END IF; + + COMMIT; + DROP TEMPORARY TABLE tTicket; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_doRecalc.sql b/db/routines/vn/procedures/ticket_doRecalc.sql new file mode 100644 index 000000000..1dd2a05cb --- /dev/null +++ b/db/routines/vn/procedures/ticket_doRecalc.sql @@ -0,0 +1,53 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_doRecalc`() +proc: BEGIN +/** + * Recalculates modified ticket. + */ + DECLARE vDone BOOL; + DECLARE vTicketFk INT; + + DECLARE cCur CURSOR FOR + SELECT DISTINCT ticketFk FROM tTicket; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.ticket_doRecalc'); + ROLLBACK; + RESIGNAL; + END; + + IF !GET_LOCK('vn.ticket_doRecalc', 0) THEN + LEAVE proc; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tTicket; + CREATE TEMPORARY TABLE tTicket + ENGINE = MEMORY + SELECT id, ticketFk FROM ticketRecalc; + + OPEN cCur; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cCur INTO vTicketFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL ticket_recalc(vTicketFk, NULL); + END LOOP; + + CLOSE cCur; + + DELETE tr FROM ticketRecalc tr JOIN tTicket t ON tr.id = t.id; + + DROP TEMPORARY TABLE tTicket; + + DO RELEASE_LOCK('vn.ticket_doRecalc'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getFromFloramondo.sql b/db/routines/vn/procedures/ticket_getFromFloramondo.sql new file mode 100644 index 000000000..4d83d6dda --- /dev/null +++ b/db/routines/vn/procedures/ticket_getFromFloramondo.sql @@ -0,0 +1,127 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFromFloramondo`(vDateFrom DATE, vDateTo DATE) +BEGIN +/** + * Genera una tabla con la lista de tickets de Floramondo + * para una fecha determinada. + * + * @param vDated Fecha de preparación de los pedidos + * @table tmp.ticketFloramondo(ticketFk, clientName, agencyName, + * agencyModeFk, supplierName, supplierFk, freight, expeditionCount, + * margin, trolleys, pallets, shipped, created) + */ + DROP TEMPORARY TABLE IF EXISTS tmp.ticketFloramondo; + CREATE TEMPORARY TABLE tmp.ticketFloramondo + (ticketFk INT PRIMARY KEY, + clientName VARCHAR(50), + agencyName VARCHAR(50), + agencyModeFk INT, + supplierName VARCHAR(50), + supplierFk INT, + freight DECIMAL(10,2) DEFAULT 0, + expeditionCount INT, + margin DECIMAL(10,3) DEFAULT 0, + trolleys INT DEFAULT 0, + pallets INT DEFAULT 0, + shipped DATE, + created DATE) + ENGINE = MEMORY; + + INSERT INTO tmp.ticketFloramondo(ticketFk, + clientName, + agencyName, + agencyModeFk, + shipped, + supplierName, + supplierFk, + created) + SELECT t.id ticketFk, + t.nickname, + am.name, + am.id, + t.shipped, + s.name, + sat.supplierFk, + t.created + FROM vn.ticket t + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + AND w.code IN ('VNH','FLM') + AND t.shipped BETWEEN vDateFrom AND util.dayend(vDateTo) + JOIN vn.agency a ON a.id = am.agencyFk + LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id + LEFT JOIN vn.supplier s ON s.id = sat.supplierFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (ticketFk INT(11) PRIMARY KEY) + SELECT ticketFk + FROM tmp.ticketFloramondo; + + -- Freight + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(sc.value * s.quantity) freight, t.ticketFk + FROM vn.saleComponent sc + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.sale s ON s.id = sc.saleFk + JOIN tmp.ticket t ON t.ticketFk = s.ticketFk + WHERE ct.code = 'FREIGHT' + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.freight = sb.freight; + + -- Freight service + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(ts.price * ts.quantity) service, t.ticketFk + FROM vn.ticketService ts + JOIN tmp.ticket t ON t.ticketFk = ts.ticketFk + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.freight = tf.freight + sb.service; + + -- Expedition Count + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT COUNT(e.id) expeditionCount, t.ticketFk + FROM vn.expedition e + RIGHT JOIN tmp.ticket t ON t.ticketFk = e.ticketFk + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.expeditionCount = sb.expeditionCount; + + -- Margin + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost, + SUM(IF(ct.isMargin, sc.value, 0)) margin, + t.ticketFk + FROM vn.saleComponent sc + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.sale s ON s.id = sc.saleFk + JOIN tmp.ticket t ON t.ticketFk = s.ticketFk + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.margin = sb.margin / sb.cost; + + -- Trolleys + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(tp.quantity) trolleys, t.ticketFk + FROM vn.ticketPackaging tp + JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk + JOIN vn.packaging p ON p.id = tp.packagingFk + WHERE p.isTrolley + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.trolleys = sb.trolleys; + + -- Pallets + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(tp.quantity) pallets, t.ticketFk + FROM vn.ticketPackaging tp + JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk + JOIN vn.packaging p ON p.id = tp.packagingFk + WHERE p.isPallet + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.pallets = sb.pallets; + + SELECT * FROM tmp.ticketFloramondo; + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketFloramondo; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getMovable.sql b/db/routines/vn/procedures/ticket_getMovable.sql new file mode 100644 index 000000000..b69fa220a --- /dev/null +++ b/db/routines/vn/procedures/ticket_getMovable.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getMovable`(vTicketFk INT, vDatedNew DATETIME, vWarehouseFk INT) +BEGIN +/** + * Cálcula el stock movible para los artículos de un ticket + * vDatedNew debe ser menor que vDatedOld, en los otros casos se + * asume que siempre es posible + * + * @param vTicketFk -> Ticket + * @param vDatedNew -> Nueva fecha + * @return Sales con Movible +*/ + DECLARE vDatedOld DATETIME; + SET vDatedNew = DATE_ADD(vDatedNew, INTERVAL 1 DAY); + + SELECT t.shipped INTO vDatedOld + FROM ticket t + WHERE t.id = vTicketFk; + + CALL item_getStock(vWarehouseFk, vDatedNew, NULL); + CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(DATE_SUB(vDatedOld, INTERVAL 1 DAY), vDatedNew), NULL); + + SELECT s.id, + s.itemFk, + s.quantity, + s.concept, + s.price, + s.reserved, + s.discount, + i.image, + i.subName, + il.stock + IFNULL(im.amount, 0) AS movable + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + LEFT JOIN tmp.itemMinacum im ON im.itemFk = s.itemFk AND im.warehouseFk = vWarehouseFk + LEFT JOIN tmp.itemList il ON il.itemFk = s.itemFk + WHERE t.id = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemList; + DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getProblems.sql b/db/routines/vn/procedures/ticket_getProblems.sql new file mode 100644 index 000000000..7c57492b4 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getProblems.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getProblems`(IN vIsTodayRelative tinyint(1)) +BEGIN +/** + * Calcula los problemas para un conjunto de tickets. + * Agrupados por ticket + * + * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular + * @return tmp.ticket_problems + */ + CALL sale_getProblems(vIsTodayRelative); + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, + MAX(isFreezed) isFreezed, + MAX(risk) risk, + MAX(hasHighRisk) hasHighRisk, + MAX(hasTicketRequest) hasTicketRequest, + MAX(itemShortage) itemShortage, + MIN(isTaxDataChecked) isTaxDataChecked, + MAX(hasComponentLack) hasComponentLack, + MAX(isTooLittle) isTooLittle, + MAX(itemDelay) itemDelay, + MAX(hasRounding) hasRounding, + MAX(itemLost) itemLost, + 0 totalProblems + FROM tmp.sale_problems + GROUP BY ticketFk; + + UPDATE tmp.ticket_problems tp + SET tp.totalProblems = ( + (tp.isFreezed) + + IF(tp.risk,TRUE, FALSE) + + (tp.hasTicketRequest) + + (tp.isTaxDataChecked = 0) + + (tp.hasComponentLack) + + (tp.itemDelay) + + (tp.isTooLittle) + + (tp.itemLost) + + (tp.hasRounding) + + (tp.itemShortage) + ); + + DROP TEMPORARY TABLE tmp.sale_problems; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getSplitList.sql b/db/routines/vn/procedures/ticket_getSplitList.sql new file mode 100644 index 000000000..10488d596 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getSplitList.sql @@ -0,0 +1,160 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getSplitList`(vDated DATE, vHour TIME, vWarehouseFk INT) +BEGIN +/** + * Devuelve un listado con los tickets posibles para splitar HOY. + * + * @param vDated Fecha a estudiar + * @param vHour Hora a partir de la cual todavía se puede enviar, si la fecha es la de hoy + * @param vWarehouseFk Almacén + */ + DECLARE vAvailableCache INT; + DECLARE vVisibleCache INT; + + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, util.VN_CURDATE()); + CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); + CALL `vn`.`zoneClosure_recalc`(); + + CREATE OR REPLACE TEMPORARY TABLE tmp.salesToSplit + (saleFk INT PRIMARY KEY, + ticketFk INT, + problem VARCHAR(1), + INDEX(ticketFk)) ENGINE = MEMORY; + + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk; + + INSERT INTO tmp.salesToSplit(saleFk, ticketFk, problem) + SELECT s.id, s.ticketFk, 'F' + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible,0) < s.quantity + AND IFNULL(av.available ,0) < s.quantity + AND IFNULL(issw.visible, 0) < s.quantity + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND ic.merchandise = TRUE + AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND NOT i.generic + AND t.warehouseFk = vWarehouseFk; + + INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem) + SELECT s.id, s.ticketFk, 'I' + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible,0) >= s.quantity + AND IFNULL(issw.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND NOT i.generic + AND t.warehouseFk = vWarehouseFk; + + INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem) + SELECT s.id, s.ticketFk, 'R' + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk + WHERE IFNULL(v.visible,0) < s.quantity + AND IFNULL(av.available ,0) >= s.quantity + AND IFNULL(issw.visible, 0) < s.quantity + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise + AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND NOT i.generic + AND t.warehouseFk = vWarehouseFk; + + CREATE OR REPLACE TEMPORARY TABLE tTicketsToSplit( + ticketFk INT PRIMARY KEY, + problems VARCHAR(100), + addressFk INT, + ipt VARCHAR(10), + etd TIME, + INDEX(addressFk) + ) ENGINE = MEMORY; + + INSERT INTO tTicketsToSplit + SELECT ss.ticketFk, + GROUP_CONCAT(DISTINCT ss.problem ORDER BY ss.problem) problems, + t.addressFk, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, + DATE_FORMAT(IF(HOUR(t.shipped), + t.shipped, + IFNULL(zc.hour, z.HOUR)),'%H:%i') etd + FROM tmp.salesToSplit ss + JOIN ticket t ON t.id = ss.ticketFk + JOIN sale s ON s.id = ss.saleFk + JOIN item i ON i.id = s.itemFk + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + LEFT JOIN zone z ON z.id = t.zoneFk + GROUP BY ss.ticketFk; + + SELECT ts.*, + t.id ticketFuture, + st.name state, + zc.`hour` tfEtd, + GROUP_CONCAT( + DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk + ) tfIpt, + st2.name tfState + FROM tTicketsToSplit ts + LEFT JOIN ticketState ts2 ON ts2.ticketFk = ts.ticketFk + LEFT JOIN `state` st ON st.id = ts2.stateFk + LEFT JOIN ticket t ON t.id != ts.ticketFk + AND t.addressFk = ts.addressFk + AND t.shipped BETWEEN vDated AND util.dayend(vDated) + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = vDated + LEFT JOIN sale s ON s.ticketFk = t.id + LEFT JOIN item i ON i.id = s.itemFk + LEFT JOIN ticketState tst ON tst.ticketFk = t.id + LEFT JOIN state st2 ON st2.id = tst.stateFk + WHERE (t.id IS NULL + OR (vDated > util.VN_CURDATE()) + OR (vDated = util.VN_CURDATE() AND vHour >= zc.`hour`)) + AND ts.etd <= vHour + GROUP BY ts.ticketFk, t.id + ORDER BY ts.etd, ts.ticketFk; + + DROP TEMPORARY TABLE + tTicketsToSplit, + tItemShelvingStock_byWarehouse; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getTax.sql b/db/routines/vn/procedures/ticket_getTax.sql new file mode 100644 index 000000000..7269a1caf --- /dev/null +++ b/db/routines/vn/procedures/ticket_getTax.sql @@ -0,0 +1,103 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTax`(IN vTaxArea VARCHAR(25)) +BEGIN +/** + * Calcula la base imponible, el IVA y el recargo de equivalencia para + * un conjunto de tickets. + * + * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular + * @return tmp.ticketAmount (ticketFk, taxableBase, tax, code) + * @return tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) Impuesto desglosado para cada ticket. + */ + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany + (INDEX (addressFk, companyFk)) + ENGINE = MEMORY + SELECT DISTINCT t.addressFk, t.companyFk + FROM tmp.ticket tmpTicket + JOIN ticket t ON t.id = tmpTicket.ticketFk; + + CALL addressTaxArea (); + + IF vTaxArea IS NOT NULL THEN + UPDATE tmp.addressTaxArea + SET areaFk = vTaxArea; + END IF; + + /* Solo se calcula la base imponible (taxableBase) y el impuesto se calculará posteriormente + * No se debería cambiar el sistema por problemas con los decimales + */ + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; + CREATE TEMPORARY TABLE tmp.ticketTax + (PRIMARY KEY (ticketFk, code, rate)) + ENGINE = MEMORY + SELECT * FROM ( + SELECT tmpTicket.ticketFk, + bp.pgcFk, + SUM(s.quantity * s.price * (100 - s.discount)/100 ) taxableBase, + pgc.rate, + tc.code, + bp.priority + FROM tmp.ticket tmpTicket + JOIN sale s ON s.ticketFk = tmpTicket.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = tmpTicket.ticketFk + JOIN supplier su ON su.id = t.companyFk + JOIN tmp.addressTaxArea ata + ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk + JOIN itemTaxCountry itc + ON itc.itemFk = i.id AND itc.countryFk = su.countryFk + JOIN bookingPlanner bp + ON bp.countryFk = su.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = itc.taxClassFk + JOIN pgc ON pgc.code = bp.pgcFk + JOIN taxClass tc ON tc.id = bp.taxClassFk + GROUP BY tmpTicket.ticketFk, pgc.code, pgc.rate + HAVING taxableBase <> 0) t3 + ORDER BY priority; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax; + CREATE TEMPORARY TABLE tmp.ticketServiceTax + (PRIMARY KEY (ticketFk, code, rate)) + ENGINE = MEMORY + SELECT tt.ticketFk, + pgc.code pgcFk, + SUM(ts.quantity * ts.price) taxableBase, + pgc.rate, + tc.code + FROM tmp.ticket tt + JOIN ticketService ts ON ts.ticketFk = tt.ticketFk + JOIN ticket t ON t.id = tt.ticketFk + JOIN supplier su ON su.id = t.companyFk + JOIN tmp.addressTaxArea ata + ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk + JOIN bookingPlanner bp + ON bp.countryFk = su.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = ts.taxClassFk + JOIN pgc ON pgc.code = bp.pgcFk + JOIN taxClass tc ON tc.id = bp.taxClassFk + GROUP BY tt.ticketFk, pgc.code + HAVING taxableBase <> 0; + + INSERT INTO tmp.ticketTax (ticketFk, pgcFk, taxableBase, rate, code) + SELECT ts.ticketFk, ts.pgcFk, ts.taxableBase, ts.rate, ts.code + FROM tmp.ticketServiceTax ts + ON DUPLICATE KEY UPDATE ticketTax.taxableBase = VALUES (taxableBase) + ticketTax.taxableBase ; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; + CREATE TEMPORARY TABLE tmp.ticketAmount + (INDEX (ticketFk)) + ENGINE = MEMORY + SELECT ticketFk, + taxableBase, + SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax, + code + FROM tmp.ticketTax + GROUP BY ticketFk, code; + + DROP TEMPORARY TABLE tmp.addressCompany; + DROP TEMPORARY TABLE tmp.addressTaxArea; +END$$ +DELIMITER ; diff --git a/db/.archive/231201/00-ticket_getWarnings.sql b/db/routines/vn/procedures/ticket_getWarnings.sql similarity index 58% rename from db/.archive/231201/00-ticket_getWarnings.sql rename to db/routines/vn/procedures/ticket_getWarnings.sql index 5253b58ab..0bda30446 100644 --- a/db/.archive/231201/00-ticket_getWarnings.sql +++ b/db/routines/vn/procedures/ticket_getWarnings.sql @@ -1,8 +1,5 @@ -DROP PROCEDURE IF EXISTS `vn`.`ticket_getWarnings`; - DELIMITER $$ -$$ -CREATE PROCEDURE `vn`.`ticket_getWarnings`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getWarnings`() BEGIN /** * Calcula las adventencias para un conjunto de tickets. @@ -11,16 +8,15 @@ BEGIN * @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular * @return tmp.ticket_warnings */ - DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings; - CREATE TEMPORARY TABLE tmp.sale_warnings ( + CREATE OR REPLACE TEMPORARY TABLE tSaleWarnings ( ticketFk INT(11), saleFk INT(11), isFragile INTEGER(1) DEFAULT 0, PRIMARY KEY (ticketFk, saleFk) ) ENGINE = MEMORY; - -- Frágil - INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile) + -- Fragile + INSERT INTO tSaleWarnings(ticketFk, saleFk, isFragile) SELECT tt.ticketFk, s.id, TRUE FROM tmp.sale_getWarnings tt LEFT JOIN sale s ON s.ticketFk = tt.ticketFk @@ -31,17 +27,16 @@ BEGIN WHERE dm.code IN ('AGENCY') AND it.isFragile; - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_warnings; - CREATE TEMPORARY TABLE tmp.ticket_warnings - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT - sw.ticketFk, - MAX(sw.isFragile) AS isFragile - FROM tmp.sale_warnings sw - GROUP BY sw.ticketFk; + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_warnings + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT + sw.ticketFk, + MAX(sw.isFragile) AS isFragile + FROM tSaleWarnings sw + GROUP BY sw.ticketFk; DROP TEMPORARY TABLE - tmp.sale_warnings; + tSaleWarnings; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getWithParameters.sql b/db/routines/vn/procedures/ticket_getWithParameters.sql new file mode 100644 index 000000000..2d3d09311 --- /dev/null +++ b/db/routines/vn/procedures/ticket_getWithParameters.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getWithParameters`( + vClientFk INT, + vWarehouseFk INT, + vShipped DATE, + vAddressFk INT, + vCompanyFk INT, + vAgencyModeFk INT, + OUT vTicketFk INT + ) +BEGIN +/** + * Devuelve un ticket con los parametros, en caso de no existir lo crea + * + * @param vClientFk Cliente + * @param vWarehouseFk almacen + * @param vShipped Fecha de preparacion + * @param vAddressFk Consignatario + * @param vCompanyFk Empresa + * @param vAgencyModeFk agencia + */ + + SELECT t.id INTO vTicketFk + FROM vn.ticket t + WHERE t.clientFk <=> vClientFk + AND t.warehouseFk <=> vWarehouseFk + AND (t.shipped <=> vShipped OR vShipped IS NULL) + AND (t.addressFk <=> vAddressFk OR vAddressFk IS NULL) + AND (t.companyFk <=> vCompanyFk OR vCompanyFk IS NULL) + AND (t.agencyModeFk <=> vAgencyModeFk OR vAgencyModeFk IS NULL) + LIMIT 1; + + IF vTicketFk IS NULL THEN + CALL vn.ticket_add( + vClientFk, + IFNULL(vShipped, util.VN_CURDATE()), + vWarehouseFk, + vCompanyFk, + vAddressFk, + vAgencyModeFk, + NULL, + vShipped, + `account`.`myUser_getId`(), + TRUE, + vTicketFk + ); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_insertZone.sql b/db/routines/vn/procedures/ticket_insertZone.sql new file mode 100644 index 000000000..ee6eabdec --- /dev/null +++ b/db/routines/vn/procedures/ticket_insertZone.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_insertZone`() +BEGIN + DECLARE vDone INT DEFAULT 0; + DECLARE vFechedTicket INT; + DECLARE vLanded DATE; + DECLARE vAddressFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vWarehouseFk INT; + DECLARE vCursor CURSOR FOR + SELECT id, landed, addressFk, agencyModeFk, warehouseFk + FROM vn.ticket WHERE shipped > '2020-01-01' AND zoneFk is null; + DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET vDone = 1; + + OPEN vCursor; + REPEAT + FETCH vCursor INTO vFechedTicket, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk; + CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); + + UPDATE vn.ticket t + JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = vWarehouseFk + SET t.zoneFk = zgs.zoneFk + WHERE t.id = vFechedTicket; + + UNTIL vDone END REPEAT; + DROP TEMPORARY TABLE tmp.zoneGetShipped; + + CLOSE vCursor; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_priceDifference.sql b/db/routines/vn/procedures/ticket_priceDifference.sql new file mode 100644 index 000000000..4ef168840 --- /dev/null +++ b/db/routines/vn/procedures/ticket_priceDifference.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_priceDifference`( + vTicketFk INT, + vLanded DATE, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk INT) +BEGIN +/** + * Devuelve las diferencias de precio de los movimientos de un ticket. + * + * @param vTicketFk Id del ticket + * @param vLanded Fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vZoneFk Id de la zona + * @param vWarehouseFk Id del almacén + */ + CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); + + SELECT s.itemFk, + i.name, + i.size, + i.category, + IFNULL(s.quantity, 0) AS quantity, + IFNULL(s.price, 0) AS price, + ROUND(SUM(tc.cost), 2) AS newPrice, + s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference, + s.id AS saleFk + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk + AND tc.warehouseFk = vWarehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE t.id = vTicketFk + AND IF(sc.componentFk IS NULL + AND c.classRate IS NOT NULL, FALSE, TRUE) + GROUP BY s.id ORDER BY s.id; + + DROP TEMPORARY TABLE tmp.ticketComponentPreview; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_printLabelPrevious.sql b/db/routines/vn/procedures/ticket_printLabelPrevious.sql new file mode 100644 index 000000000..cba42ff3e --- /dev/null +++ b/db/routines/vn/procedures/ticket_printLabelPrevious.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_printLabelPrevious`(vTicketFk INT) +BEGIN +/** + * Calls the report_print procedure and passes it + * the necessary parameters for printing. + * + * @param vTicketFk id ticket to print. + */ + DECLARE vPrinterFk INT; + DECLARE vSaleGroup INT; + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SELECT sg.id, o.labelerFk INTO vSaleGroup, vPrinterFk + FROM saleGroup sg + JOIN sector sc ON sc.id = sg.sectorFk + JOIN saleGroupDetail sgd ON sg.id = sgd.saleGroupFk + JOIN sale s ON sgd.saleFk = s.id + JOIN ticket t ON s.ticketFk = t.id + JOIN operator o ON o.workerFk = vUserFk + WHERE sc.id = o.sectorFk + AND t.id = vTicketFk + LIMIT 1; + + CALL report_print( + 'LabelPrevia', + vPrinterFk, + vUserFk, + JSON_OBJECT('id', vSaleGroup, 'userFk', vUserFk), + 'high' + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_recalc.sql b/db/routines/vn/procedures/ticket_recalc.sql new file mode 100644 index 000000000..50065d03a --- /dev/null +++ b/db/routines/vn/procedures/ticket_recalc.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalc`(vSelf INT, vTaxArea VARCHAR(25)) +proc:BEGIN +/** + * Calcula y guarda el total con/sin IVA en un ticket. + * + * @param vSelf Identificador del ticket + * @param vTaxArea + */ + DECLARE hasInvoice BOOL; + + SELECT COUNT(*) INTO hasInvoice + FROM ticket + WHERE id = vSelf + AND refFk IS NOT NULL; + + IF hasInvoice THEN + LEAVE proc; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + SELECT vSelf ticketFk; + + CALL ticketGetTotal(vTaxArea); + + UPDATE ticket t + JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id + SET t.totalWithVat = tt.total, + t.totalWithoutVat = tt.totalWithoutVat; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticketTotal; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_recalcComponents.sql b/db/routines/vn/procedures/ticket_recalcComponents.sql new file mode 100644 index 000000000..f48d70ee2 --- /dev/null +++ b/db/routines/vn/procedures/ticket_recalcComponents.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption INT) +proc: BEGIN + +/** + * Crea tabla temporal para sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id del ticket + * @param vOption si no se quiere forzar llamar con NULL + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.ticketFk = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_requestRecalc.sql b/db/routines/vn/procedures/ticket_requestRecalc.sql new file mode 100644 index 000000000..6636e4c0f --- /dev/null +++ b/db/routines/vn/procedures/ticket_requestRecalc.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_requestRecalc`(vSelf INT) +proc: BEGIN +/** + * Adds a request to recalculate the ticket total. + * + * @param vSelf The ticket identifier + */ + IF vSelf IS NULL THEN + LEAVE proc; + END IF; + + INSERT INTO ticketRecalc SET ticketFk = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_setNextState.sql b/db/routines/vn/procedures/ticket_setNextState.sql new file mode 100644 index 000000000..d13cd53f0 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setNextState.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT) +BEGIN +/** + * Cambia el estado del ticket al siguiente estado según la tabla state + * + * @param vSelf id dle ticket + */ + DECLARE vStateFk INT; + DECLARE vNewStateFk INT; + + SELECT stateFk INTO vStateFk + FROM ticketState + WHERE ticketFk = vSelf; + + SELECT nextStateFk INTO vNewStateFk + FROM state + WHERE id = vStateFk; + + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) + VALUES (vNewStateFk, vSelf, account.myUser_getId()); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_setParking.sql b/db/routines/vn/procedures/ticket_setParking.sql new file mode 100644 index 000000000..54c64daea --- /dev/null +++ b/db/routines/vn/procedures/ticket_setParking.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN +/** + * Aparca un ticket en un parking + * + * @param vTicketFk id del ticket + * @param vParkingFk id del parking + */ + DECLARE vDone INT DEFAULT FALSE; + DECLARE vCollectionTicketFk INT; + DECLARE vCursor CURSOR FOR + SELECT IFNULL(tc2.ticketFk, t.id) + FROM ticket t + LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id + LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk + WHERE t.id = vTicketFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + INSERT INTO vn.ticketParking(ticketFk, parkingFk) + SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk + FROM ticket t + LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id + LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk + WHERE t.id = vTicketFk + ON DUPLICATE KEY UPDATE parkingFk = vParkingFk; + + OPEN vCursor; + l: LOOP + FETCH vCursor INTO vCollectionTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL vn.ticket_setNextState(vCollectionTicketFk); + END LOOP; + + CLOSE vCursor; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_setPreviousState.sql b/db/routines/vn/procedures/ticket_setPreviousState.sql new file mode 100644 index 000000000..c03d41b09 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setPreviousState.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setPreviousState`(vTicketFk INT) +BEGIN + DECLARE vControlFk INT; + + SELECT MAX(id) INTO vControlFk + FROM ticketTracking + WHERE ticketFk = vTicketFk; + + IF (SELECT s.code + FROM vn.state s + JOIN ticketTracking tt ON tt.stateFk = s.id + WHERE tt.id = vControlFk) + = 'PREVIOUS_PREPARATION' THEN + SELECT id + INTO vControlFk + FROM ticketTracking tt + JOIN vn.state s ON tt.stateFk = s.id + WHERE ticketFk = vTicketFk + AND id < vControlFk + AND s.code != 'PREVIOUS_PREPARATION' + ORDER BY id DESC + LIMIT 1; + + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) + SELECT s.nextStateFk, tt.ticketFk, account.myUser_getId() + FROM ticketTracking tt + JOIN vn.state s ON tt.stateFk = s.id + WHERE id = vControlFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/changes/234601/00-ticketSetStateRefactor.sql b/db/routines/vn/procedures/ticket_setState.sql similarity index 96% rename from db/changes/234601/00-ticketSetStateRefactor.sql rename to db/routines/vn/procedures/ticket_setState.sql index 9078ffb0e..13a93380d 100644 --- a/db/changes/234601/00-ticketSetStateRefactor.sql +++ b/db/routines/vn/procedures/ticket_setState.sql @@ -40,7 +40,7 @@ BEGIN ); IF vCanChangeState THEN - INSERT INTO ticketTracking (stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking (stateFk, ticketFk, userFk) SELECT id, vSelf, account.myUser_getId() FROM state WHERE `code` = vStateCode COLLATE utf8_unicode_ci; diff --git a/db/routines/vn/procedures/ticket_split.sql b/db/routines/vn/procedures/ticket_split.sql new file mode 100644 index 000000000..e8a94c610 --- /dev/null +++ b/db/routines/vn/procedures/ticket_split.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_split`(vTicketFk INT, vTicketFutureFk INT, vDated DATE) +proc:BEGIN +/** + * Mueve las lineas con problemas a otro ticket existente o a uno nuevo. + * + * @param vTicketFk Identificador del ticket a splittar + * @param vTicketFutureFk Identificador del ticket al que se quieren mover las lineas + * @param vDate Fecha a la que se va a mover + * @table tmp.salesToSplit(saleFk, ticketFk, problem) + */ + DECLARE vHasFullProblem BOOL; + DECLARE vProblemLines INT; + DECLARE vTotalLines INT; + + SELECT COUNT(*) INTO vProblemLines + FROM tmp.salesToSplit + WHERE ticketFk = vTicketFk; + + SELECT count(*) INTO vTotalLines + FROM vn.sale s + WHERE s.ticketFk = vTicketFk; + + SET vHasFullProblem = (vTotalLines = vProblemLines); + + -- Ticket completo + IF vHasFullProblem THEN + + UPDATE vn.ticket + SET landed = vDated + INTERVAL 1 DAY, + shipped = vDated, + nickname = CONCAT('(',DAY(util.VN_CURDATE()),') ', nickname ) + WHERE id = vTicketFk; + + SELECT CONCAT("Se ha cambiado el ticket ", vTicketFk, " al dia ", vDated); + LEAVE proc; + + END IF; + + -- Ticket a futuro existe + IF vTicketFutureFk THEN + + UPDATE vn.sale s + JOIN tmp.salesToSplit ss ON s.id = ss.saleFk + SET s.ticketFk = vTicketFutureFk, + s.concept = CONCAT('(s) ', s.concept) + WHERE ss.ticketFk = vTicketFk; + + SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, + " al ticket existente ", vTicketFutureFk,"(", vDated,")"); + LEAVE proc; + + END IF; + + -- Ticket nuevo + CALL vn.ticket_Clone(vTicketFk, vTicketFutureFk); + + UPDATE vn.ticket t + JOIN vn.productionConfig pc + SET t.routeFk = IF(t.shipped = vDated , t.routeFk, NULL), + t.landed = vDated + INTERVAL 1 DAY, + t.shipped = vDated, + t.agencyModeFk = pc.defautlAgencyMode, + t.zoneFk = pc.defaultZone + WHERE t.id = vTicketFutureFk; + + UPDATE vn.sale s + JOIN tmp.salesToSplit sts ON sts.saleFk = s.id + SET s.ticketFk = vTicketFutureFk, + s.concept = CONCAT('(s) ', s.concept) + WHERE sts.ticketFk = vTicketFk; + + CALL vn.ticketStateUpdate(vTicketFutureFk, 'FIXING'); + + SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, + " al nuevo ticket ", vTicketFutureFk,"(", vDated,")"); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql new file mode 100644 index 000000000..d6424efad --- /dev/null +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -0,0 +1,106 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_splitItemPackingType`(vTicketFk INT, vOriginalItemPackingTypeFk VARCHAR(1)) +proc:BEGIN +/** + * Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado. + * Respeta el id inicial para el tipo propuesto. + * + * @param vTicketFk Identificador de vn.ticket + * @param vOriginalItemPackingTypeFk Tipo para el que se reserva el número de ticket original + * @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk) + */ + DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H'; + DECLARE vNewTicketFk INT; + DECLARE vPackingTypesToSplit INT; + DECLARE vDone INT DEFAULT FALSE; + + DECLARE cur1 CURSOR FOR + SELECT itemPackingTypeFk + FROM tmp.saleGroup + WHERE itemPackingTypeFk IS NOT NULL + ORDER BY (itemPackingTypeFk = vOriginalItemPackingTypeFk) DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE FROM vn.sale + WHERE quantity = 0 + AND ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (id)) + SELECT s.id, i.itemPackingTypeFk , IFNULL(sv.litros, 0) litros + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id + WHERE s.ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.saleGroup; + CREATE TEMPORARY TABLE tmp.saleGroup + SELECT itemPackingTypeFk , sum(litros) AS totalLitros + FROM tmp.sale + GROUP BY itemPackingTypeFk; + + SELECT COUNT(*) INTO vPackingTypesToSplit + FROM tmp.saleGroup + WHERE itemPackingTypeFk IS NOT NULL; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketIPT; + CREATE TEMPORARY TABLE tmp.ticketIPT + (ticketFk INT, + itemPackingTypeFk VARCHAR(1)); + + CASE vPackingTypesToSplit + WHEN 0 THEN + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + VALUES(vTicketFk, vItemPackingTypeFk); + WHEN 1 THEN + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + SELECT vTicketFk, itemPackingTypeFk + FROM tmp.saleGroup + WHERE itemPackingTypeFk IS NOT NULL; + ELSE + OPEN cur1; + + FETCH cur1 INTO vItemPackingTypeFk; + + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + VALUES(vTicketFk, vItemPackingTypeFk); + + read_loop: LOOP + FETCH cur1 INTO vItemPackingTypeFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); + + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + VALUES(vNewTicketFk, vItemPackingTypeFk); + END LOOP; + + CLOSE cur1; + + UPDATE vn.sale s + JOIN tmp.sale ts ON ts.id = s.id + JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk + SET s.ticketFk = t.ticketFk; + + SELECT itemPackingTypeFk INTO vItemPackingTypeFk + FROM tmp.saleGroup sg + WHERE NOT ISNULL(sg.itemPackingTypeFk) + ORDER BY sg.itemPackingTypeFk + LIMIT 1; + + UPDATE vn.sale s + JOIN tmp.sale ts ON ts.id = s.id + JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk + SET s.ticketFk = t.ticketFk + WHERE ts.itemPackingTypeFk IS NULL; + END CASE; + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE tmp.saleGroup; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_splitPackingComplete.sql b/db/routines/vn/procedures/ticket_splitPackingComplete.sql new file mode 100644 index 000000000..528e8fbed --- /dev/null +++ b/db/routines/vn/procedures/ticket_splitPackingComplete.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_splitPackingComplete`(vTicketFk INT, vSectorFk INT) +BEGIN + + DECLARE vNeedToSplit BOOLEAN; + DECLARE vNewTicketFk INT; + + DROP TEMPORARY TABLE IF EXISTS tmpSale; + + CREATE TEMPORARY TABLE tmpSale + SELECT DISTINCT s.id + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = vSectorFk + JOIN vn.packagingConfig pc + WHERE t.id = vTicketFk + AND ( s.quantity MOD IFNULL(iss.packing,1) != 0 + OR + IFNULL(iss.packing,1) = 1 + OR + i.`size` <= pc.previousPreparationMinimumSize + ); + + SELECT COUNT(*) + INTO vNeedToSplit + FROM tmpSale; + + IF vNeedToSplit THEN + + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); + + UPDATE vn.sale s + JOIN vn.tmpSale ts ON ts.id = s.id + SET s.ticketFk = vNewTicketFk; + + END IF; + + DROP TEMPORARY TABLE tmpSale; + +END$$ +DELIMITER ; diff --git a/db/changes/234001/00-timeBusiness_calculate.sql b/db/routines/vn/procedures/timeBusiness_calculate.sql similarity index 99% rename from db/changes/234001/00-timeBusiness_calculate.sql rename to db/routines/vn/procedures/timeBusiness_calculate.sql index 599dba74a..3cb734069 100644 --- a/db/changes/234001/00-timeBusiness_calculate.sql +++ b/db/routines/vn/procedures/timeBusiness_calculate.sql @@ -1,5 +1,4 @@ DELIMITER $$ -$$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /** @@ -14,7 +13,7 @@ BEGIN (INDEX (departmentFk)) SELECT dated, businessFk, - sub.id userFk, + sub.id userFk, departmentFk, hourStart, hourEnd, diff --git a/db/routines/vn/procedures/timeBusiness_calculateAll.sql b/db/routines/vn/procedures/timeBusiness_calculateAll.sql new file mode 100644 index 000000000..4e0ac7da5 --- /dev/null +++ b/db/routines/vn/procedures/timeBusiness_calculateAll.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculateAll`(vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + +/** + * @param vDatedFrom Fecha desde + * @param vDatedTo Fecha hasta + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + SELECT w.id userFk + FROM vn.worker w; + + CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeBusiness_calculateByDepartment.sql b/db/routines/vn/procedures/timeBusiness_calculateByDepartment.sql new file mode 100644 index 000000000..54c587342 --- /dev/null +++ b/db/routines/vn/procedures/timeBusiness_calculateByDepartment.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN +/** + * @param vDepartmentFk + * @param vDatedFrom workerTimeControl + * @param vDatedTo workerTimeControl + */ + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; + + CREATE TEMPORARY TABLE tmp.`user` + SELECT DISTINCT b.workerFk userFk + FROM business AS b + WHERE (b.started BETWEEN vDatedFrom AND vDatedTo + OR IFNULL(b.ended, vDatedTo) BETWEEN vDatedFrom AND vDatedTo + OR (b.started <= vDatedFrom AND b.ended >= vDatedTo) + ) AND b.departmentFk = vDepartmentFk + ORDER BY b.ended DESC; + + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeBusiness_calculateByUser.sql b/db/routines/vn/procedures/timeBusiness_calculateByUser.sql new file mode 100644 index 000000000..a54dfcc2e --- /dev/null +++ b/db/routines/vn/procedures/timeBusiness_calculateByUser.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculateByUser`(vUserFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + +/** + * @param vUserFk + * @param vDatedFrom workerTimeControl + * @param vDatedTo workerTimeControl + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; + + CREATE TEMPORARY TABLE tmp.`user` + SELECT id userFk + FROM account.user + WHERE id = vUserFk; + CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeBusiness_calculateByWorker.sql b/db/routines/vn/procedures/timeBusiness_calculateByWorker.sql new file mode 100644 index 000000000..89a4c0ab0 --- /dev/null +++ b/db/routines/vn/procedures/timeBusiness_calculateByWorker.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculateByWorker`(vWorkerFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + +/** + * @param vWorkerFk + * @param vDatedFrom Fecha desde + * @param vDatedTo Fecha hasta + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + SELECT w.id userFk + FROM worker w + WHERE w.id = vWorkerFk; + + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/changes/234004/01-timeControl_calculate.sql b/db/routines/vn/procedures/timeControl_calculate.sql similarity index 82% rename from db/changes/234004/01-timeControl_calculate.sql rename to db/routines/vn/procedures/timeControl_calculate.sql index 93d88c047..258960265 100644 --- a/db/changes/234004/01-timeControl_calculate.sql +++ b/db/routines/vn/procedures/timeControl_calculate.sql @@ -20,17 +20,17 @@ BEGIN */ DECLARE vHourSeconds INTEGER; DECLARE vDatedFromYesterday DATETIME; - DECLARE vDatedToTomorrow DATETIME; + DECLARE vDatedToTomorrow DATETIME; DECLARE vTimeToBreakTime INT; DECLARE vBreakTime INT; DECLARE vMaxTimeToBreak INT; - + SELECT DATE_SUB(vDatedFrom, INTERVAL 1 DAY), DATE_ADD(vDatedTo, INTERVAL 1 DAY) INTO vDatedFromYesterday, vDatedToTomorrow; - + SELECT timeToBreakTime, breakTime, maxTimeToBreak, TIME_TO_SEC('01:00:00') INTO vTimeToBreakTime, vBreakTime, vMaxTimeToBreak, vHourSeconds - FROM workerTimeControlConfig + FROM workerTimeControlConfig LIMIT 1; CALL timeControl_getError(vDatedFromYesterday, vDatedToTomorrow); @@ -38,13 +38,13 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.workerTimeControl (INDEX(userFk, timed), INDEX(timed), INDEX(direction)) ENGINE = MEMORY - SELECT wtc.userFk, - wtc.timed, + SELECT wtc.userFk, + wtc.timed, DATE(wtc.timed) dated, wtc.direction, TRUE isReal FROM workerTimeControl wtc - JOIN tmp.`user` u ON u.userFk = wtc.userFk + JOIN tmp.`user` u ON u.userFk = wtc.userFk LEFT JOIN ( SELECT wtc.userFk, MIN(wtc.timed) firstIn FROM workerTimeControl wtc @@ -69,67 +69,67 @@ BEGIN WHERE wtc.timed BETWEEN fi.firstIn AND lo.lastOut AND tce.id IS NULL ORDER BY wtc.userFk, wtc.timed; - + CREATE OR REPLACE TEMPORARY TABLE tmp.wtcToinsert - (INDEX(timed)) + (INDEX(timed)) ENGINE = MEMORY WITH wtc AS( SELECT timed, userFk, dated, direction, - LEAD(dated) OVER + LEAD(dated) OVER (PARTITION BY userFk, dated ORDER BY timed) nextDay, - LEAD(userFk) OVER + LEAD(userFk) OVER (PARTITION BY userFk ORDER BY timed) nextUserFk, ROW_NUMBER() OVER (ORDER BY userFk, timed) MOD 2 isOdd FROM tmp.workerTimeControl WHERE timed BETWEEN vDatedFromYesterday AND vDatedToTomorrow ORDER BY userFk, timed - ), wtcToinsert AS( - SELECT userFk, + ), wtcToinsert AS( + SELECT userFk, dated, - IF(userFk = nextUserFk - AND nextDay IS NULL - AND isOdd + IF(userFk = nextUserFk + AND nextDay IS NULL + AND isOdd AND direction <> 'out', TRUE, FALSE) outNextDay, - IF(userFk = nextUserFk - AND nextDay IS NULL - AND NOT isOdd - AND direction <> 'out', TRUE, FALSE) outNextDayWhitBreak + IF(userFk = nextUserFk + AND nextDay IS NULL + AND NOT isOdd + AND direction <> 'out', TRUE, FALSE) outNextDayWhitBreak FROM wtc HAVING outNextDay OR outNextDayWhitBreak - )SELECT userFk, util.dayEnd(dated) timed, 'out' direction + )SELECT userFk, util.dayEnd(dated) timed, 'out' direction FROM wtcToinsert WHERE outNextDay - UNION ALL + UNION ALL SELECT userFk, dated + INTERVAL 1 DAY, 'in' FROM wtcToinsert WHERE outNextDay - UNION ALL - SELECT userFk, util.dayEnd(dated) - INTERVAL 1 SECOND, 'middle' + UNION ALL + SELECT userFk, util.dayEnd(dated) - INTERVAL 1 SECOND, 'middle' FROM wtcToinsert WHERE outNextDayWhitBreak UNION ALL SELECT userFk, util.dayEnd(dated), 'out' FROM wtcToinsert - WHERE outNextDayWhitBreak - UNION ALL + WHERE outNextDayWhitBreak + UNION ALL SELECT userFk, dated + INTERVAL 1 DAY, 'in' FROM wtcToinsert WHERE outNextDayWhitBreak - UNION ALL + UNION ALL SELECT userFk, dated + INTERVAL 1 DAY + INTERVAL 1 SECOND, 'middle' FROM wtcToinsert WHERE outNextDayWhitBreak; - + INSERT INTO tmp.workerTimeControl (userFk, timed, dated, direction, isReal) SELECT userFk, timed, DATE(timed), direction, FALSE FROM tmp.wtcToinsert; SET @accumulatedForBreakTime = 0; - SET @oldrealDay = NULL; - CREATE OR REPLACE TEMPORARY TABLE tmp.timeControlCalculate + SET @oldrealDay = NULL; + CREATE OR REPLACE TEMPORARY TABLE tmp.timeControlCalculate WITH workerTimed AS ( SELECT userFk, @@ -138,32 +138,32 @@ BEGIN (direction ='in' AND isReal) breakPoint, SUM(CASE WHEN (direction ='in' AND isReal) THEN TRUE ELSE FALSE END) OVER (ORDER BY userFk, timed) AS realDay, - TIMESTAMPDIFF(SECOND, LAG(timed) + TIMESTAMPDIFF(SECOND, LAG(timed) OVER (PARTITION BY userFk, dated ORDER BY timed), timed) gapTime, - ROW_NUMBER() + ROW_NUMBER() OVER (PARTITION BY userFk, dated ORDER BY timed) MOD 2 isOdd FROM tmp.workerTimeControl WHERE timed BETWEEN vDatedFromYesterday AND vDatedToTomorrow ), accumulated AS ( - SELECT SUM(IF(isOdd, 0, gapTime)) + SELECT SUM(IF(isOdd, 0, gapTime)) OVER (PARTITION BY userFk,dated ORDER BY userFk,timed) accumulatedWorkTime, - SUM(IF(NOT isOdd OR breakPoint, 0, IFNULL(gapTime, 0))) - OVER (PARTITION BY realDay ORDER BY realDay,timed) accumulatedBreakTime, - IF(realDay <> @oldrealDay OR (isOdd AND gapTime >= vMaxTimeToBreak), + SUM(IF(NOT isOdd OR breakPoint OR gapTime >= vMaxTimeToBreak OR gapTime IS NULL, 0, gapTime)) + OVER (PARTITION BY realDay ORDER BY realDay,timed) accumulatedBreakTime, + IF(realDay <> @oldrealDay OR (isOdd AND gapTime >= vMaxTimeToBreak), @accumulatedForBreakTime := 0, - @accumulatedForBreakTime := @accumulatedForBreakTime + + @accumulatedForBreakTime := @accumulatedForBreakTime + IF(isOdd, 0, gapTime )) accumulatedForBreakTime, @oldrealDay := realDay, userFk, dated, realDay FROM workerTimed - ), totalWorked AS ( + ), totalWorked AS ( SELECT userFk, dated, - MAX(accumulatedWorkTime) + - IF(MAX(accumulatedForBreakTime) >= vTimeToBreakTime, - LEAST(vBreakTime, MAX(accumulatedBreakTime)), + MAX(accumulatedWorkTime) + + IF(MAX(accumulatedForBreakTime) + LEAST(vBreakTime, MAX(accumulatedBreakTime)) >= vTimeToBreakTime, + LEAST(vBreakTime, MAX(accumulatedBreakTime)), 0) timeWorkSeconds FROM accumulated GROUP BY userFk, dated @@ -177,7 +177,7 @@ BEGIN JOIN ( SELECT userFk, dated, - GROUP_CONCAT(DATE_FORMAT(timed, "%H:%i") ORDER BY timed ASC + GROUP_CONCAT(DATE_FORMAT(timed, "%H:%i") ORDER BY timed ASC SEPARATOR ' - ')tableTimed FROM tmp.workerTimeControl WHERE timed BETWEEN vDatedFromYesterday AND vDatedToTomorrow @@ -186,9 +186,9 @@ BEGIN )sub ON sub.dated = tw.dated AND sub.userFk = tw.userFk WHERE tw.dated BETWEEN vDatedFrom AND vDatedTo; - + DROP TEMPORARY TABLE tmp.timeControlError; DROP TEMPORARY TABLE tmp.wtcToinsert; DROP TEMPORARY TABLE tmp.workerTimeControl; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/procedures/timeControl_calculateAll.sql b/db/routines/vn/procedures/timeControl_calculateAll.sql new file mode 100644 index 000000000..c6354ad78 --- /dev/null +++ b/db/routines/vn/procedures/timeControl_calculateAll.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeControl_calculateAll`(vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + +/** + * @param vDatedFrom Fecha desde + * @param vDatedTo Fecha hasta + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + SELECT w.id userFk + FROM vn.worker w; + + CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeControl_calculateByDepartment.sql b/db/routines/vn/procedures/timeControl_calculateByDepartment.sql new file mode 100644 index 000000000..bb9ccec60 --- /dev/null +++ b/db/routines/vn/procedures/timeControl_calculateByDepartment.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeControl_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN +/** + * @param vDepartmentFk + * @param vDatedFrom workerTimeControl + * @param vDatedTo workerTimeControl + */ + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; + + CREATE TEMPORARY TABLE tmp.`user` + SELECT DISTINCT b.workerFk userFk + FROM business AS b + WHERE (b.started BETWEEN vDatedFrom AND vDatedTo + OR IFNULL(b.ended, vDatedTo) BETWEEN vDatedFrom AND vDatedTo + OR (b.started <= vDatedFrom AND b.ended >= vDatedTo) + ) AND b.departmentFk = vDepartmentFk + ORDER BY b.ended DESC; + + CALL timeControl_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeControl_calculateByUser.sql b/db/routines/vn/procedures/timeControl_calculateByUser.sql new file mode 100644 index 000000000..8e831cb4c --- /dev/null +++ b/db/routines/vn/procedures/timeControl_calculateByUser.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeControl_calculateByUser`(vUserFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + +/** + * @param vUserFk + * @param vDatedFrom workerTimeControl + * @param vDatedTo workerTimeControl + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; + + CREATE TEMPORARY TABLE tmp.`user` + SELECT id userFk + FROM account.user + WHERE id = vUserFk; + CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeControl_calculateByWorker.sql b/db/routines/vn/procedures/timeControl_calculateByWorker.sql new file mode 100644 index 000000000..98c3dedd2 --- /dev/null +++ b/db/routines/vn/procedures/timeControl_calculateByWorker.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeControl_calculateByWorker`(vWorkerFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + +/** + * @param vWorkerFk + * @param vDatedFrom workerTimeControl + * @param vDatedTo workerTimeControl + */ + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; + + CREATE TEMPORARY TABLE tmp.`user` + SELECT u.id userFk + FROM account.user u + JOIN vn.worker w ON w.id = u.id + WHERE w.id = vWorkerFk; + + CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); + + DROP TEMPORARY TABLE tmp.`user`; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeControl_getError.sql b/db/routines/vn/procedures/timeControl_getError.sql new file mode 100644 index 000000000..6e5ca02ab --- /dev/null +++ b/db/routines/vn/procedures/timeControl_getError.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeControl_getError`(vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN +/* + * @param vDatedFrom + * @param vDatedTo + * @table tmp.`user`(userFk) + * Fichadas incorrectas de las cuales no se puede calcular horas trabajadas + * @return tmp.timeControlError (id) + */ + DECLARE vDayMaxTime INTEGER; + + SET @journeyCounter := 0; + SET @lastUserFk := NULL; + + SELECT dayMaxTime INTO vDayMaxTime + FROM workerTimeControlConfig LIMIT 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; + CREATE TEMPORARY TABLE tmp.timeControl + (INDEX(id), INDEX(journeyCounter)) + ENGINE = MEMORY + SELECT sub.id, + sub.direction, + sub.timed, + IF(sub.direction = 'in' OR @hasOut OR sub.userFk <> @lastUserFk, @journeyCounter := @journeyCounter + 1, @journeyCounter) journeyCounter, + @lastUserFk := sub.userFk workerFk, + IF(sub.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE) + FROM ( + SELECT DISTINCT wtc.id, + wtc.direction, + wtc.timed, + wtc.userFk + FROM workerTimeControl wtc + JOIN tmp.`user` w ON w.userFk = wtc.userFk + WHERE wtc.timed BETWEEN DATE_SUB(vDatedFrom, INTERVAL 1 DAY) AND DATE_ADD(vDatedTo, INTERVAL 1 DAY) + ORDER BY wtc.userFk, wtc.timed + ) sub; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; + CREATE TEMPORARY TABLE tmp.timeControlAux + (INDEX(id), INDEX(journeyCounter)) + ENGINE = MEMORY + SELECT * FROM tmp.timeControl; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlError; + CREATE TEMPORARY TABLE tmp.timeControlError + (INDEX(id)) + ENGINE = MEMORY + SELECT id + FROM tmp.timeControlAux tca + JOIN ( + SELECT journeyCounter, + UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork, + SUM(direction = 'in') totalIn, + SUM(direction = 'out') totalOut, + timed + FROM tmp.timeControl + GROUP BY journeyCounter + HAVING COUNT(*) MOD 2 = 1 + OR totalIn <> 1 + OR totalOut <> 1 + OR timeWork >= vDayMaxTime + )sub ON sub.journeyCounter = tca.journeyCounter + WHERE sub.timed BETWEEN vDatedFrom AND vDatedTo; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/timeWorkerControl_check.sql b/db/routines/vn/procedures/timeWorkerControl_check.sql new file mode 100644 index 000000000..877bc9b69 --- /dev/null +++ b/db/routines/vn/procedures/timeWorkerControl_check.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeWorkerControl_check`(vUserFk INT, vDated DATE,vTabletFk VARCHAR(100)) +proc: BEGIN +/** + * deprecated call workerTimeControl_check + */ +CALL vn.workerTimeControl_check(vUserFk,vDated,vTabletFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/tpvTransaction_checkStatus.sql b/db/routines/vn/procedures/tpvTransaction_checkStatus.sql new file mode 100644 index 000000000..e16c20161 --- /dev/null +++ b/db/routines/vn/procedures/tpvTransaction_checkStatus.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`tpvTransaction_checkStatus`() +BEGIN +/** + * + * Envia mail con los cobros web no + * trasladados a la ficha del cliente. + * + */ + INSERT INTO mail (receiver, replyTo, subject, body) + SELECT 'administracion@verdnatura.es, finanzas@verdnatura.es', + 'noreply@verdnatura.es', + CONCAT('Cobro web no trasladado a la ficha del cliente ', clientFk), + CONCAT('Hay un importe de ', amount / 100, '€ del cliente ', clientFk, ' con fecha ', created, + ', que no se ha trasladado a recibos. Si nos ha llegado el importe al banco confirme el pago en + + https://salix.verdnatura.es/#!/client/', clientFk, '/web-payment') + FROM hedera.tpvTransaction + WHERE receiptFk IS NULL + AND status = 'ok' + AND created < (util.VN_NOW() - INTERVAL 2 DAY) + GROUP BY clientFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travelVolume.sql b/db/routines/vn/procedures/travelVolume.sql new file mode 100644 index 000000000..21eae36ac --- /dev/null +++ b/db/routines/vn/procedures/travelVolume.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travelVolume`(vTravelFk INT) +BEGIN + + SELECT w1.name AS ORI, + w2.name AS DES, + tr.shipped shipment, + tr.landed landing, + a.name Agencia, + s.name Proveedor, + e.id Id_Entrada, + e.invoiceNumber Referencia, + CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * + vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) AS CC, + CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * + vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) AS espais + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode a ON a.id = tr.agencyModeFk + JOIN vn.warehouse w1 ON w1.id = tr.warehouseInFk + JOIN vn.warehouse w2 ON w2.id = tr.warehouseOutFk + JOIN vn.volumeConfig vc + JOIN vn.item i ON i.id = b.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + WHERE tr.id = vTravelFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travelVolume_get.sql b/db/routines/vn/procedures/travelVolume_get.sql new file mode 100644 index 000000000..f9d00aeb4 --- /dev/null +++ b/db/routines/vn/procedures/travelVolume_get.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travelVolume_get`(vFromDated DATE, vToDated DATE, vWarehouseFk INT) +BEGIN + SELECT tr.landed Fecha, + a.name Agencia, + count(DISTINCT e.id) numEntradas, + FLOOR(sum(item_getVolume(b.itemFk, b.packagingFk) * b.stickers / 1000000 )) AS m3 + FROM vn.travel tr + JOIN vn.agencyMode a ON a.id = tr.agencyModeFk + JOIN vn.entry e ON e.travelFk = tr.id + JOIN vn.buy b ON b.entryFk = e.id + WHERE tr.landed BETWEEN vFromDated AND vToDated + AND e.isRaid = FALSE + AND tr.warehouseInFk = vWarehouseFk + GROUP BY tr.landed , a.name ; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_checkDates.sql b/db/routines/vn/procedures/travel_checkDates.sql new file mode 100644 index 000000000..45690fcb4 --- /dev/null +++ b/db/routines/vn/procedures/travel_checkDates.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`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 ; diff --git a/db/routines/vn/procedures/travel_checkPackaging.sql b/db/routines/vn/procedures/travel_checkPackaging.sql new file mode 100644 index 000000000..59df1b894 --- /dev/null +++ b/db/routines/vn/procedures/travel_checkPackaging.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_checkPackaging`(vSelf INT) +BEGIN + DECLARE vDone BOOL; + DECLARE vEntryFk INT; + + DECLARE cTravelEntries CURSOR FOR + SELECT id + FROM entry + WHERE entry.travelFk = vSelf; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + OPEN cTravelEntries; + + l: LOOP + SET vDone = FALSE; + FETCH cTravelEntries INTO vEntryFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL entry_checkPackaging(vEntryFk); + END LOOP; + + CLOSE cTravelEntries; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_checkWarehouseIsFeedStock.sql b/db/routines/vn/procedures/travel_checkWarehouseIsFeedStock.sql new file mode 100644 index 000000000..ef69d772b --- /dev/null +++ b/db/routines/vn/procedures/travel_checkWarehouseIsFeedStock.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_checkWarehouseIsFeedStock`(vWarehouseFk INT) +proc: BEGIN +/* + * Check that the warehouse is not Feed Stock + * + * @vWarehouseFk param warehouse id + */ + IF vWarehouseFk IS NULL THEN + LEAVE proc; + END IF; + + IF (SELECT isFeedStock FROM warehouse WHERE id = vWarehouseFk) THEN + CALL util.throw('Cannot create a travel with a source warehouse marked isFeedStock'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_clone.sql b/db/routines/vn/procedures/travel_clone.sql new file mode 100644 index 000000000..96500baa1 --- /dev/null +++ b/db/routines/vn/procedures/travel_clone.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_clone`(vSelf INT, vDays INT, OUT vNewTravelFk INT) +BEGIN +/** + * Clona un travel el número de dias indicado y devuelve su id. + * + * @param vSelf Identificador de vn.travel + * @param vDays Número de dias a futuro + * @return vNewTravelFk Nuevo número de travel + */ + SELECT tr.id INTO vNewTravelFk + FROM vn.travel tr + JOIN vn.travel tr2 USING(shipped, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`) + WHERE tr2.id = vSelf + AND tr.landed = TIMESTAMPADD(DAY, vDays, tr2.landed); + + IF ISNULL(vNewTravelFk) THEN + START TRANSACTION; + + INSERT INTO vn.travel( shipped, + shipmentHour, + landed, + landingHour, + warehouseInFk, + warehouseOutFk, + agencyModeFk, + `ref`, + cargoSupplierFk, + clonedFrom) + SELECT shipped, + shipmentHour, + TIMESTAMPADD(DAY, vDays, landed), + landingHour, + warehouseInFk, + warehouseOutFk, + agencyModeFk, + `ref`, + cargoSupplierFk, + vSelf + FROM vn.travel + WHERE id = vSelf; + + SELECT LAST_INSERT_ID() INTO vNewTravelFk; + + COMMIT; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_cloneWithEntries.sql b/db/routines/vn/procedures/travel_cloneWithEntries.sql new file mode 100644 index 000000000..840152c44 --- /dev/null +++ b/db/routines/vn/procedures/travel_cloneWithEntries.sql @@ -0,0 +1,81 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`( + IN vTravelFk INT, + IN vDateStart DATE, + IN vDateEnd DATE, + IN vWarehouseOutFk INT, + IN vWarehouseInFk INT, + IN vRef VARCHAR(255), + IN vAgencyModeFk INT, + OUT vNewTravelFk INT) +BEGIN +/** + * Clona un travel junto con sus entradas y compras + * + * @param vTravelFk travel plantilla a clonar + * @param vDateStart fecha del shipment del nuevo travel + * @param vDateEnd fecha del landing del nuevo travel + * @param vWarehouseOutFk fecha del salida del nuevo travel + * @param vWarehouseInFk warehouse de landing del nuevo travel + * @param vRef referencia del nuevo travel + * @param vAgencyModeFk del nuevo travel + * @param vNewTravelFk id del nuevo travel + */ + DECLARE vNewEntryFk INT; + DECLARE vEvaNotes VARCHAR(255); + DECLARE vDone BOOL; + DECLARE vAuxEntryFk INT; + DECLARE vRsEntry CURSOR FOR + SELECT e.id + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.travelFk = vTravelFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) + SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk + FROM travel + WHERE id = vTravelFk; + + SET vNewTravelFk = LAST_INSERT_ID(); + + SET vDone = FALSE; + SET @isModeInventory = TRUE; + + OPEN vRsEntry; + + l: LOOP + SET vDone = FALSE; + FETCH vRsEntry INTO vAuxEntryFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); + CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); + + SELECT evaNotes INTO vEvaNotes + FROM entry + WHERE id = vAuxEntryFk; + + UPDATE entry + SET evaNotes = vEvaNotes + WHERE id = vNewEntryFk; + END LOOP; + + SET @isModeInventory = FALSE; + CLOSE vRsEntry; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_doRecalc.sql b/db/routines/vn/procedures/travel_doRecalc.sql new file mode 100644 index 000000000..5d877174c --- /dev/null +++ b/db/routines/vn/procedures/travel_doRecalc.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_doRecalc`() +proc: BEGIN +/** +* Recounts the number of entries of changed travels. +*/ + DECLARE vTravelFk INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.ticket_doRecalc'); + END; + + IF !GET_LOCK('vn.travel_doRecalc', 0) THEN + LEAVE proc; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tTravel + ENGINE = MEMORY + SELECT travelFk FROM travelRecalc; + + UPDATE travel t + JOIN tTravel tt ON tt.travelFk = t.id + SET t.totalEntries = ( + SELECT COUNT(e.id) + FROM entry e + WHERE e.travelFk = t.id + ); + + DELETE tr FROM travelRecalc tr JOIN tTravel t ON tr.travelFk = t.travelFk; + DROP TEMPORARY TABLE tTravel; + DO RELEASE_LOCK('vn.travel_doRecalc'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_getEntriesMissingPackage.sql b/db/routines/vn/procedures/travel_getEntriesMissingPackage.sql new file mode 100644 index 000000000..35d30e0c4 --- /dev/null +++ b/db/routines/vn/procedures/travel_getEntriesMissingPackage.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_getEntriesMissingPackage`(vSelf INT) +BEGIN + DECLARE vpackageOrPackingNull INT; + DECLARE vTravelFk INT; + + SELECT travelfk INTO vTravelFk + FROM entry + WHERE id = vSelf; + + SELECT e.id entryFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + JOIN buy b ON b.entryFk = e.id + WHERE t.id = vTravelFk + AND (b.packing IS NULL OR b.packagingFk IS NULL); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_moveRaids.sql b/db/routines/vn/procedures/travel_moveRaids.sql new file mode 100644 index 000000000..c7696e829 --- /dev/null +++ b/db/routines/vn/procedures/travel_moveRaids.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_moveRaids`() +BEGIN + +/* + * Desplaza al dia siguiente los travels que contengan redadas y avisa a los compradores + * + */ + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vWorkerName VARCHAR(50); + DECLARE vRaid TEXT; + DECLARE vWorker VARCHAR(50) DEFAULT ''; + DECLARE vMailBody TEXT DEFAULT ''; + + DECLARE vCur CURSOR FOR + SELECT GROUP_CONCAT( DISTINCT CONCAT('https://salix.verdnatura.es/#!/travel/', ttr.id, '/summary ') ORDER BY ttr.id SEPARATOR '\n\r'), + u.name + FROM tmp.travel ttr + JOIN entry e ON e.travelFk = ttr.id + JOIN buy b ON b.entryFk = e.id + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN account.user u ON u.id = it.workerFk + GROUP BY u.name; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + DROP TEMPORARY TABLE IF EXISTS tmp.travel; + CREATE TEMPORARY TABLE tmp.travel + SELECT tr.id,tr.landed + FROM travel tr + JOIN entry e ON e.travelFk = tr.id + WHERE tr.landed = util.tomorrow() + AND e.isRaid + GROUP BY tr.id; + + START TRANSACTION; + + UPDATE travel tr + JOIN tmp.travel ttr ON ttr.id = tr.id + SET tr.landed = TIMESTAMPADD(DAY, 1, tr.landed); + + OPEN vCur; + + l: LOOP + SET vDone = FALSE; + FETCH vCur INTO vRaid, vWorkerName; + + IF vDone THEN + LEAVE l; + END IF; + + CALL `vn`.`mail_insert`(CONCAT(vWorkerName, '@verdnatura.es'), + 'noreply@verdnatura.es', + 'Cambio de fecha en Redadas', + CONCAT('Se ha movido las siguientes redadas: \n\r ', vRaid) + ); + + END LOOP; + CLOSE vCur; + COMMIT; + DROP TEMPORARY TABLE tmp.travel; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_requestRecalc.sql b/db/routines/vn/procedures/travel_requestRecalc.sql new file mode 100644 index 000000000..5797f2397 --- /dev/null +++ b/db/routines/vn/procedures/travel_requestRecalc.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`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 ; diff --git a/db/routines/vn/procedures/travel_upcomingArrivals.sql b/db/routines/vn/procedures/travel_upcomingArrivals.sql new file mode 100644 index 000000000..a2cd3733c --- /dev/null +++ b/db/routines/vn/procedures/travel_upcomingArrivals.sql @@ -0,0 +1,81 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_upcomingArrivals`( + vWarehouseFk INT, + vDate DATETIME +) +BEGIN +/** + * Procedure to track and organize the movement of items between warehouses, + * where 'warehouseINFk' is @vWarehouseFk. + * Uses temporary tables to process and store the travel data of the items. + * + * @params vWarehouseFk warehouse id + * @params vDate selected landed date + * @return tmp.itemTravel + */ + DECLARE vTravelFk INT; + DECLARE vWarehouseOutFk INT; + DECLARE vShipment DATETIME; + DECLARE vDateStart DATETIME; + + CREATE OR REPLACE TEMPORARY TABLE tTravelTop + (PRIMARY KEY (wh_in,wh_out,landing,shipment)) + ENGINE = MEMORY + SELECT 0 id, + vWarehouseFk wh_in, + vWarehouseFk wh_out, + FALSE ok, + vDate landing, + vDate shipment; + + REPEAT + SET vTravelFk = NULL; + + SELECT id, + wh_out, + shipment, + landing + INTO vTravelFk, + vWarehouseOutFk, + vShipment, + vDateStart + FROM tTravelTop + WHERE ok = FALSE LIMIT 1; + + UPDATE tTravelTop + SET ok = TRUE + WHERE id = vTravelFk; + + INSERT IGNORE INTO tTravelTop + SELECT id, + vWarehouseFk, + warehouseOutFk, + FALSE, + IF(vTravelFk, vDateStart, landed), + shipped shipment + FROM travel + WHERE warehouseOutFk = vWarehouseOutFk + AND IF(vTravelFk, landed <= vShipment, landed >= vShipment) + AND shipped >= util.VN_CURDATE() + AND NOT isDelivered; + UNTIL vTravelFk IS NULL END REPEAT; + + DELETE FROM tTravelTop WHERE id = 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemTravel + (KEY (wh)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT wh_out wh, + landing + FROM tTravelTop + WHERE wh_out <> vWarehouseFk + ORDER BY landing + LIMIT 10000000000000000000 + ) t + GROUP BY wh; + + DROP TEMPORARY TABLE tTravelTop; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_updatePacking.sql b/db/routines/vn/procedures/travel_updatePacking.sql new file mode 100644 index 000000000..0f63bbf62 --- /dev/null +++ b/db/routines/vn/procedures/travel_updatePacking.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_updatePacking`(vItemFk INT, vPacking INT) +BEGIN +/** + * Actualiza packing para los movimientos de almacén de la subasta al almacén central + * + * @param vItemFk id del item + * @param vPacking nuevo packing + */ + + DECLARE vAuctionWarehouseFk INT; + DECLARE vMainWarehouseFk INT; + + SELECT warehouseFk INTO vAuctionWarehouseFk + FROM auctionConfig; + + SELECT mainWarehouseFk INTO vMainWarehouseFk + FROM config; + + UPDATE entry e + JOIN travel t ON t.id = e.travelFk + JOIN buy b on b.entryFk = e.id + SET b.packing = vPacking + WHERE t.shipped >= util.dayEnd(CURDATE()) + AND t.warehouseInFk = vMainWarehouseFk + AND t.warehouseOutFk = vAuctionWarehouseFk + AND b.itemFk = vItemFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_weeklyClone.sql b/db/routines/vn/procedures/travel_weeklyClone.sql new file mode 100644 index 000000000..a92916c10 --- /dev/null +++ b/db/routines/vn/procedures/travel_weeklyClone.sql @@ -0,0 +1,73 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_weeklyClone`(vSinceWeek INT, vToWeek INT) +BEGIN +/** + * Clona los traslados plantilla para las semanas pasadas por parámetros. + * + * @param vSinceWeek Número de semanas en el futuro para empezar a clonar + * @param vToWeek Número de semenas en el futuro hasta donde clonar + */ + DECLARE vCounter INT; + DECLARE vCurrentTravelFk INT; + DECLARE vShipped DATE; + DECLARE vLanded DATE; + DECLARE vWarehouseInFk INT; + DECLARE vWarehouseOutFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vRef VARCHAR(255); + DECLARE vNewTravelFk INT; + DECLARE vDone BOOL; + DECLARE vRsTravel CURSOR FOR + SELECT travelFk, + @a := TIMESTAMPADD(DAY,vCounter * 7 - WEEKDAY(util.VN_CURDATE()) - 1 + weekDay, util.VN_CURDATE()), + @a := TIMESTAMPADD(DAY,duration,@a), + warehouseOutFk, + warehouseInFk, + `ref`, + agencyModeFk + FROM travelClonedWeekly + WHERE travelFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SET vCounter = vSinceWeek; + + vWeekLoop :LOOP + INSERT IGNORE INTO travel (shipped, landed, warehouseOutFk, warehouseInFk, agencyModeFk, ref, cargoSupplierFk, kg) + SELECT @a := TIMESTAMPADD(DAY, vCounter * 7 - WEEKDAY(util.VN_CURDATE()) - 1 + weekDay, util.VN_CURDATE()), + @a := TIMESTAMPADD(DAY, duration, @a), + warehouseOutFk, + warehouseInFk, + agencyModeFk, + ref, + supplierFk, + kg + FROM travelClonedWeekly + WHERE travelFk IS NULL; + + OPEN vRsTravel; + + l: LOOP + SET vDone = FALSE; + FETCH vRsTravel INTO vCurrentTravelFk, vShipped, vLanded, vWarehouseOutFk, vWarehouseInFk, vRef, vAgencyModeFk; + + IF vDone THEN + LEAVE l; + END IF; + + BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RESIGNAL SQLSTATE '01000'; + CALL travel_cloneWithEntries(vCurrentTravelFk, vShipped, vLanded, vWarehouseOutFk, vWarehouseInFk, vRef, vAgencyModeFk, vNewTravelFk); + END; + END LOOP; + + CLOSE vRsTravel; + + IF vCounter = vToWeek THEN + LEAVE vWeekLoop; + END IF; + + SET vCounter = vCounter + 1; + END LOOP vWeekLoop; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/typeTagMake.sql b/db/routines/vn/procedures/typeTagMake.sql new file mode 100644 index 000000000..ddfc7fdb9 --- /dev/null +++ b/db/routines/vn/procedures/typeTagMake.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`typeTagMake`(vTypeFk INT) +BEGIN +/* + * Plantilla para modificar reemplazar todos los tags + * por los valores que tienen los articulos + * + * @param vTypeFk tipo a modificar + * + */ + DELETE it.* + FROM itemTag it + JOIN item i ON i.id = it.itemFk + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, CONCAT(i.size,' cm'), 1 + FROM item i + JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, i.category, 5 + FROM item i + JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, ink.name, 2 + FROM item i + JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci + JOIN ink ON ink.id = i.inkFk + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, p.name, 3 + FROM item i + JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci + JOIN producer p ON p.id = i.producerFk + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, o.name, 4 + FROM item i + JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci + JOIN origin o ON o.id = i.originFk + WHERE i.typeFk = vTypeFk; + /* + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, i.stems, 6 + FROM item i + JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci + WHERE i.typeFk = vTypeFk; + */ +-- CALL itemTagArrangedUpdate(NULL); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/updatePedidosInternos.sql b/db/routines/vn/procedures/updatePedidosInternos.sql new file mode 100644 index 000000000..97b01bf8b --- /dev/null +++ b/db/routines/vn/procedures/updatePedidosInternos.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`updatePedidosInternos`(vItemFk INT) +BEGIN + + UPDATE vn.item SET upToDown = 0 WHERE item.id = vItemFk; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/vehicle_checkNumberPlate.sql b/db/routines/vn/procedures/vehicle_checkNumberPlate.sql new file mode 100644 index 000000000..8e3f24d76 --- /dev/null +++ b/db/routines/vn/procedures/vehicle_checkNumberPlate.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`vehicle_checkNumberPlate`(vNumberPlate VARCHAR(10), vCountryCodeFk VARCHAR(2)) +BEGIN +/** + * Comprueba si la matricula pasada tiene el formato correcto dependiendo del pais del vehiculo + */ + DECLARE vRegex VARCHAR(45); + + SELECT vp.regex INTO vRegex + FROM vehiclePlateRegex vp + WHERE vp.countryCodeFk = vCountryCodeFk; + + IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN + CALL util.throw(CONCAT('Error: la matricula ', vNumberPlate, ' no es valida para ',vCountryCodeFk)); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/vehicle_notifyEvents.sql b/db/routines/vn/procedures/vehicle_notifyEvents.sql new file mode 100644 index 000000000..1a07a96e2 --- /dev/null +++ b/db/routines/vn/procedures/vehicle_notifyEvents.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`vehicle_notifyEvents`() +proc:BEGIN +/** + * Query the vehicleEvent table to see if there are any events that need to be notified. + * + */ + DECLARE vEventEarlyDays INT; + DECLARE vHasEvents INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT eventEarlyDays INTO vEventEarlyDays + FROM vehicleConfig; + + DROP TEMPORARY TABLE IF EXISTS tEvents; + CREATE TEMPORARY TABLE tEvents + SELECT e.id + FROM vehicleEvent e + JOIN vehicleState s ON e.vehicleStateFk = s.id + WHERE e.finished BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY, vEventEarlyDays, util.VN_CURDATE()) + AND e.notified IS NULL + AND s.hasToNotify; + + SELECT COUNT(id) INTO vHasEvents FROM tEvents; + + IF NOT vHasEvents THEN + LEAVE proc; + END IF; + + START TRANSACTION; + + SELECT util.notification_send('vehicle-event-expired', + JSON_OBJECT('eventIds', JSON_ARRAYAGG(id)), + account.myUser_getId() + ) + FROM tEvents; + + UPDATE vehicleEvent e + JOIN tEvents s ON e.id = s.id + SET e.notified = util.VN_NOW() + WHERE e.id = s.id; + COMMIT; + + DROP TEMPORARY TABLE IF EXISTS tEvents; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/visible_getMisfit.sql b/db/routines/vn/procedures/visible_getMisfit.sql new file mode 100644 index 000000000..631f0236e --- /dev/null +++ b/db/routines/vn/procedures/visible_getMisfit.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`visible_getMisfit`(vSectorFk INT) +BEGIN + + /* Devuelve una tabla temporal con los descuadres entre el visible teórico y lo ubicado en la práctica + * + * @param vSectorFk Identificador de vn.sector + * + * @return tmp.stockMisfit(itemFk, visible, parked) + */ + + DECLARE vCalcVisibleFk INT; + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM vn.sector s + WHERE s.id = vSectorFk; + + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, vWarehouseFk); + + DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; + + CREATE TEMPORARY TABLE tmp.stockMisfit( + itemFk INT PRIMARY KEY, + visible INT NOT NULL DEFAULT 0, + parked INT NOT NULL DEFAULT 0) + ENGINE = MEMORY; + + INSERT INTO tmp.stockMisfit(itemFk, parked) + SELECT iss.itemFk , sum(iss.visible ) + FROM vn.itemShelvingStock iss + JOIN vn.sector s ON s.id = iss.sectorFk + WHERE vSectorFk IN (s.id, s.sonFk) + GROUP BY iss.itemFk; + + INSERT INTO tmp.stockMisfit(itemFk, visible) + SELECT v.item_id , v.visible + FROM cache.visible v + WHERE v.calc_id = vCalcVisibleFk + ON DUPLICATE KEY UPDATE visible = v.visible; + + DELETE FROM tmp.stockMisfit + WHERE visible = parked; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/warehouseFitting.sql b/db/routines/vn/procedures/warehouseFitting.sql new file mode 100644 index 000000000..4be35a3ee --- /dev/null +++ b/db/routines/vn/procedures/warehouseFitting.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`warehouseFitting`(IN vWhOrigin INT , IN vWhDestiny INT) +BEGIN + DECLARE vCacheVisibleOriginFk INT; + DECLARE vCacheVisibleDestinyFk INT; + + CALL cache.visible_refresh(vCacheVisibleOriginFk, FALSE, vWhOrigin); + CALL cache.visible_refresh(vCacheVisibleDestinyFk, FALSE, vWhDestiny); + + SELECT i.id itemFk, + i.longName, + i.size, + i.subName, + vOrigin.visible AS Origen, + vDestiny.visible Destino + + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN cache.visible vOrigin ON vOrigin.calc_id = vCacheVisibleOriginFk AND vOrigin.item_id = i.id + LEFT JOIN cache.visible vDestiny ON vDestiny.calc_id = vCacheVisibleDestinyFk AND vDestiny.item_id = i.id + WHERE (vOrigin.visible OR vDestiny.visible) + AND it.categoryFk < 6 + ORDER BY IF(vOrigin.visible,0,1), longName, size, subName; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/warehouseFitting_byTravel.sql b/db/routines/vn/procedures/warehouseFitting_byTravel.sql new file mode 100644 index 000000000..db67c1599 --- /dev/null +++ b/db/routines/vn/procedures/warehouseFitting_byTravel.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`warehouseFitting_byTravel`(IN vTravelFk INT) +BEGIN + + DECLARE vWhOrigin INT; + DECLARE vWhDestiny INT; + + SELECT warehouseInFk, warehouseOutFk INTO vWhDestiny, vWhOrigin + FROM vn.travel + WHERE id = vTravelFk; + + CALL vn.warehouseFitting(vWhOrigin, vWhDestiny); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerCalculateBoss.sql b/db/routines/vn/procedures/workerCalculateBoss.sql new file mode 100644 index 000000000..0fc08ed40 --- /dev/null +++ b/db/routines/vn/procedures/workerCalculateBoss.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerCalculateBoss`(vWorker INT) +BEGIN +/** +* Actualiza la tabla workerBosses +* vWorker: id del trabajador +* +*/ + DECLARE vBoss INT; + DECLARE vWorkerCompare INT DEFAULT vWorker; + + l: LOOP + SELECT bossFk INTO vBoss + FROM vn.worker + WHERE id=vWorkerCompare; + + IF vBoss=0 OR vWorkerCompare=vBoss THEN + LEAVE l; + END IF; + + REPLACE INTO vn.workerBosses(workerFk,bossFk) + VALUES(vWorker,vBoss); + + SET vWorkerCompare = vBoss; + + END LOOP; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerCalendar_calculateBusiness.sql b/db/routines/vn/procedures/workerCalendar_calculateBusiness.sql new file mode 100644 index 000000000..72b461154 --- /dev/null +++ b/db/routines/vn/procedures/workerCalendar_calculateBusiness.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerCalendar_calculateBusiness`(vYear INT, vBusinessFk INT) +BEGIN +/** + * Calcula los días y horas de vacaciones en función de un contrato y año + * + * @param vYear + * @param vBusinessFk + * @return tmp.workerCalendarCalculateBusiness (days, hours, daysEnjoyed, hoursEnjoyed) + */ + DECLARE vStarted DATE; + DECLARE vEnded DATE; + DECLARE vDaysHoliday DECIMAL(5,2); + DECLARE vHoursWeek DECIMAL(5,2); + DECLARE vDaysToSubtract DECIMAL(5,2); + DECLARE vDaysHolidayEnjoyed DECIMAL(5,2); + DECLARE vPayedHolidays DECIMAL(5,2); + DECLARE vDifDays INT; + + SELECT IF(b.started < CONCAT(vYear,"-01-01"), CONCAT(vYear,"-01-01"),b.started), + IF(b.ended IS NULL OR YEAR(b.ended)>vYear , CONCAT(vYear,"-12-31"), b.ended), + IF(wbt.hasHolidayEntitlement, w.days, 0), + c.hoursWeek, + IF(YEAR(b.ended) = vYear, b.payedHolidays, 0) payedHolidays + INTO vStarted, + vEnded, + vDaysHoliday, + vHoursWeek, + vPayedHolidays + FROM business b + JOIN workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk + JOIN workCenterHoliday w ON w.workcenterFk = b.workcenterFk + LEFT JOIN calendarType c ON c.id = b.calendarTypeFk + WHERE b.id = vBusinessFk + AND w.year = vYear; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateBusiness; + + IF vStarted < vEnded THEN + SET vDifDays = DAYOFYEAR(vEnded) - DAYOFYEAR(vStarted) + 1; + + SELECT IFNULL(SUM(a.holidayEntitlementRate), 0), + SUM(-(a.discountRate - 1)) + vPayedHolidays + INTO vDaysToSubtract, + vDaysHolidayEnjoyed + FROM calendar c + JOIN absenceType a ON a.id = c.dayOffTypeFk + JOIN business b ON b.id = c.businessFk + WHERE b.id = vBusinessFk + AND YEAR(c.dated) = vYear; + + END IF; + + CREATE TEMPORARY TABLE tmp.workerCalendarCalculateBusiness + ENGINE = MEMORY + SELECT @days := IFNULL(ROUND((vDaysHoliday * (vDifDays - vDaysToSubtract) / IF(util.isLeapYear(vYear) , 366, 365)), 1), 0) days, + @days * (vHoursWeek / 5) hours, + @daysEnjoyed := IFNULL(ROUND(vDaysHolidayEnjoyed, 1), 0) daysEnjoyed, + @daysEnjoyed * (vHoursWeek / 5) hoursEnjoyed; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerCalendar_calculateYear.sql b/db/routines/vn/procedures/workerCalendar_calculateYear.sql new file mode 100644 index 000000000..9e3baf641 --- /dev/null +++ b/db/routines/vn/procedures/workerCalendar_calculateYear.sql @@ -0,0 +1,59 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerCalendar_calculateYear`(vYear INT, vWorkerFk INT) +BEGIN + +/** + * Calcula los días y horas de vacaciones en función de un trabajador y año + * + * @param vYear + * @param vWorkerFk + * @return tmp.workerCalendarCalculateYear (days, hours, daysEnjoyed, hoursEnjoyed) + */ + DECLARE vDone BOOL; + DECLARE vBusinessFk INT; + + DECLARE cur CURSOR FOR + SELECT b.id + FROM business b + WHERE vYear BETWEEN YEAR(b.started) AND IFNULL(YEAR(b.ended), vYear) + AND b.workerFk = vWorkerFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateYear; + + CREATE TEMPORARY TABLE tmp.workerCalendarCalculateYear + (days DEC(5,2), + hours DEC(5,2), + daysEnjoyed DEC(5,2), + hoursEnjoyed DEC(5,2)) + ENGINE = MEMORY; + INSERT INTO tmp.workerCalendarCalculateYear VALUES(0, 0, 0, 0); + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vBusinessFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL workerCalendar_calculateBusiness(vYear, vBusinessFk); + UPDATE tmp.workerCalendarCalculateYear w + JOIN tmp.workerCalendarCalculateBusiness wc + SET w.days = w.days + wc.days, + w.hours = w.hours + wc.hours, + w.daysEnjoyed = w.daysEnjoyed + wc.daysEnjoyed, + w.hoursEnjoyed = w.hoursEnjoyed + wc.hoursEnjoyed; + + DROP TEMPORARY TABLE tmp.workerCalendarCalculateBusiness; + + END LOOP; + + CLOSE cur; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerCreateExternal.sql b/db/routines/vn/procedures/workerCreateExternal.sql new file mode 100644 index 000000000..f8cea70b1 --- /dev/null +++ b/db/routines/vn/procedures/workerCreateExternal.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerCreateExternal`( + vFirstName VARCHAR(50), + vSurname1 VARCHAR(50), + vSurname2 VARCHAR(50), + vUser VARCHAR(20), + vPassword VARCHAR(50), + vWorkerCode VARCHAR(3), + vRole INT(2) + ) +BEGIN + DECLARE vUserId INT; + DECLARE vSurnames VARCHAR(100); + + INSERT INTO account.`user`(name, nickname, password, `role`, hasGrant) + SELECT vUser, vUser, MD5(vPassword), vRole, false; + + SET vUserId = LAST_INSERT_ID(); + + IF vSurname2 IS NULL THEN + SET vSurnames = vSurname1; + ELSE + SET vSurnames = CONCAT(vSurname1, ' ', vSurname2); + END IF; + + INSERT INTO worker(id, firstName, lastName, code, isFreelance) + SELECT vUserId, vFirstName, vSurnames, vWorkerCode, true; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerDepartmentByDate.sql b/db/routines/vn/procedures/workerDepartmentByDate.sql new file mode 100644 index 000000000..40a099d64 --- /dev/null +++ b/db/routines/vn/procedures/workerDepartmentByDate.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerDepartmentByDate`(vDate DATE) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.workerDepartmentByDate; + CREATE TEMPORARY TABLE tmp.workerDepartmentByDate + ENGINE = MEMORY + SELECT w.id userFk, + w.lastName name, + w.firstName firstname, + d.name department, + d.id departmentFk, + b.started, + d.isProduction, + CAST(12 * b.amount / ct.hoursWeek / 52 AS DECIMAL(10,2)) costeHora, + w.fi nif + FROM business b + JOIN calendarType ct ON ct.id = b.calendarTypeFk + JOIN department d ON d.id = b.departmentFk + JOIN worker w ON w.id = b.workerFk + WHERE b.started <= vDate + AND (b.ended > vDate OR b.ended IS NULL); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerDisable.sql b/db/routines/vn/procedures/workerDisable.sql new file mode 100644 index 000000000..4b10cb7fa --- /dev/null +++ b/db/routines/vn/procedures/workerDisable.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerDisable`(vUserId int) +mainLabel:BEGIN + + IF (SELECT COUNT(*) FROM workerDisableExcluded WHERE workerFk = vUserId AND (dated > util.VN_CURDATE() OR dated IS NULL)) > 0 THEN + LEAVE mainLabel; + END IF; + + DELETE cp FROM clientProtected cp + JOIN client c ON c.id = cp.clientFk + WHERE c.salesPersonFk = vUserId; + + DELETE FROM account.account + WHERE id = vUserId; + + UPDATE account.user + SET role = 2 + WHERE id = vUserId; + + DELETE FROM pbx.sip + WHERE user_id = vUserId; + + UPDATE `client` c + JOIN payMethod p ON p.name = 'CONTADO' + SET c.credit = 0, c.payMethodFk = p.id, hasCoreVnl = FALSE + WHERE c.id = vUserId; + + UPDATE `client` c + SET c.salesPersonFk = null + WHERE c.salesPersonFk = vUserId; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerDisableAll.sql b/db/routines/vn/procedures/workerDisableAll.sql new file mode 100644 index 000000000..e2f7740b2 --- /dev/null +++ b/db/routines/vn/procedures/workerDisableAll.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerDisableAll`() +BEGIN + DECLARE done BOOL DEFAULT FALSE; + DECLARE vUserFk INT; + + DECLARE rs CURSOR FOR + SELECT b.workerFk + FROM business b + JOIN vn.worker w ON w.id = b.workerFk + JOIN account.account a ON a.id = b.workerFk + LEFT JOIN (SELECT b.workerFk + FROM business b + WHERE (ended IS NULL OR ended >=util.VN_CURDATE()) + )sub ON sub.workerFk = a.id + LEFT JOIN vn.workerDisableExcluded wd ON wd.workerFk = b.workerFk + WHERE sub.workerFk IS NULL + AND wd.workerFk IS NULL + GROUP BY w.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + OPEN rs; + + FETCH rs INTO vUserFk; + + WHILE NOT done DO + CALL workerDisable(vUserFk); + FETCH rs INTO vUserFk; + + END WHILE; + + CLOSE rs; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerForAllCalculateBoss.sql b/db/routines/vn/procedures/workerForAllCalculateBoss.sql new file mode 100644 index 000000000..f3574116e --- /dev/null +++ b/db/routines/vn/procedures/workerForAllCalculateBoss.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerForAllCalculateBoss`() +BEGIN +/** +* Actualiza la tabla workerBosses utilizando el procedimiento +* vn.workerCalculateBoss(), actualiza todos los trabajadores en esa tabla +* +*/ + DECLARE vWorker INT; + DECLARE vDone BOOL; + + DECLARE cur CURSOR FOR + SELECT id FROM worker; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vWorker; + + IF vDone THEN + LEAVE l; + END IF; + + CALL workerCalculateBoss(vWorker); + END LOOP; + + CLOSE cur; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerJourney_replace.sql b/db/routines/vn/procedures/workerJourney_replace.sql new file mode 100644 index 000000000..1fcb8c590 --- /dev/null +++ b/db/routines/vn/procedures/workerJourney_replace.sql @@ -0,0 +1,308 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerJourney_replace`( + vDatedFrom DATE, + vDatedTo DATE, + vWorkerFk INT) +BEGIN +/** + * Actualiza la tabla workerJourney para que actue como caché permanente revisable + * de las jornadas laborales. + * @param vDatedFrom workerTimeControl + * @param vDatedTo workerTimeControl + * @param vWorkerFk, en caso de pasar 0 ó NULL se aplica a todos + */ + DECLARE vDatedTimeTo DATETIME; + DECLARE vMaxTimePerDay INT; + DECLARE vMinHoursToBreak DECIMAL(10,2); + DECLARE vBreakHours DECIMAL(10,2); + DECLARE vMonthByYear INT; + DECLARE vWeeksByYear INT DEFAULT 52; + DECLARE vMonthsByYear INT DEFAULT 12; + DECLARE vDaysByWeek INT DEFAULT 5; + DECLARE vDatedFromYesterday DATETIME; + DECLARE vDatedToTomorrow DATETIME; + + SELECT DATE_SUB(vDatedFrom, INTERVAL 1 DAY), DATE_ADD(vDatedTo, INTERVAL 1 DAY) + INTO vDatedFromYesterday, vDatedToTomorrow; + + SET vDatedTimeTo = util.dayEnd(vDatedTo); + + SELECT minHoursToBreak, breakHours, maxTimePerDay + INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay + FROM workerTimeControlConfig; + + DELETE FROM workerJourney + WHERE dated BETWEEN vDatedFrom AND vDatedTo + AND NOT isPaid + AND NOT isUpdated + AND (vWorkerFk IS NULL OR userFK = vWorkerFk); + + -- Se inserta todos los días del periodo por worker y business en el rango de fechas. + INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) + SELECT b.workerFk, t.dated, b.id + FROM business b + JOIN time t ON t.dated BETWEEN b.started AND IFNULL(b.ended,util.VN_CURDATE()) + WHERE t.dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR b.workerFk = vWorkerFk) + ORDER BY b.workerFk, t.dated, b.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; + + IF vWorkerFk THEN + CALL timeControl_calculateByUser(vWorkerFk, vDatedFrom , vDatedTimeTo); + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` + SELECT vWorkerFk userFk; + ELSE + CALL timeControl_calculateAll(vDatedFrom, vDatedTimeTo); + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` + SELECT id userFk + FROM worker w; + END IF; + + UPDATE workerJourney wj + JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk + SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, + t.timeWorkDecimal - vBreakHours, + t.timeWorkDecimal) AS DECIMAL (10,2)), + wj.lunch = IF(t.timeWorkDecimal >= vMinHoursToBreak , vBreakHours , 0) + WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo + AND NOT wj.isPaid + AND NOT wj.isUpdated + AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk); + + -- NOCTURNIDAD + CALL timeControl_getError(vDatedFrom, vDatedTimeTo); + + SET @vIsOdd := TRUE; + SET @vDated := NULL; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControl; + CREATE TEMPORARY TABLE tmp.workerTimeControl + (INDEX (userFk), INDEX (timed)) + ENGINE = MEMORY + SELECT DISTINCT(wtc.id), + wtc.userFk, + wtc.timed, + wtc.direction + FROM workerTimeControl wtc + JOIN tmp.`user` w ON w.userFk = wtc.userFk + LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id + WHERE wtc.timed BETWEEN vDatedFrom AND vDatedToTomorrow + AND tce.id IS NULL + AND (vWorkerFk IS NULL OR wtc.userFk = vWorkerFk) + ORDER BY wtc.userFk, wtc.timed ASC; + + SELECT MAX(id) INTO @vCont + FROM tmp.workerTimeControl; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlAux; + CREATE TEMPORARY TABLE tmp.workerTimeControlAux ( + `id` int(11) , + `userFk` int(10) unsigned , + `timed` datetime, + `direction` enum('in', 'out','middle') + ) ENGINE=MEMORY; + + SET @vIsOdd := TRUE; + SET @lastUserFk := NULL; + SET @lastDirection := NULL; + + -- Cambio de dia en medio de un descanso + INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) + SELECT @vCont:= @vCont + 1, + lastUserFk, + util.dayEnd(dated), + 'middle' + FROM (SELECT IF(@lastUserFk <> userFk, @vIsOdd := TRUE, NULL), + DATE(@lastTimed) dated, + @lastUserFk lastUserFk, + IF(direction ='middle', @vIsOdd := NOT @vIsOdd, FALSE) isOdd, + IF(@vIsOdd + AND @lastDirection = 'middle' + AND (DATE(@lastTimed) <> date(timed) + OR @lastUserFk <> userFk), TRUE, FALSE) hasBreak, + @lastTimed := wtc.timed, + @lastUserFk := userFk, + @lastDirection := direction + FROM tmp.workerTimeControl wtc + ORDER BY wtc.userFk, wtc.timed)sub + WHERE hasBreak; + + SET @vIsOdd := TRUE; + SET @lastUserFk := NULL; + SET @lastDirection := NULL; + + INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) + SELECT @vCont:= @vCont + 1, + lastUserFk, + DATE_ADD(sub.dated, INTERVAL 1 DAY), + 'middle' + FROM (SELECT IF(@lastUserFk <> userFk, @vIsOdd := TRUE, NULL), + DATE(@lastTimed) dated, + @lastUserFk lastUserFk, + IF(direction ='middle', @vIsOdd := NOT @vIsOdd, FALSE) isOdd, + IF(@vIsOdd + AND @lastDirection = 'middle' + AND (DATE(@lastTimed)<>date(timed) + OR @lastUserFk<>userFk), TRUE, FALSE) hasBreak, + @lastTimed := wtc.timed, + @lastUserFk := userFk, + @lastDirection := direction + FROM tmp.workerTimeControl wtc + ORDER BY wtc.userFk, wtc.timed)sub + WHERE hasBreak; + + -- Cambio de dia + INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) + SELECT @vCont:= @vCont + 1, + wtc.userFk, + util.dayEnd(date(wtc.timed)), + 'out' + FROM workerTimeControl wtc + JOIN tmp.`user` w ON w.userFk = wtc.userFk + LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id + WHERE wtc.timed BETWEEN vDatedFromYesterday AND vDatedToTomorrow + AND wtc.direction <> 'out' + GROUP BY wtc.userFk, DATE(wtc.timed); + + INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) + SELECT @vCont:= @vCont + 1, + wtc.userFk, + DATE_ADD(date(wtc.timed), INTERVAL 1 DAY), + 'in' + FROM workerTimeControl wtc + JOIN tmp.`user` w ON w.userFk = wtc.userFk + LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id + WHERE wtc.timed BETWEEN vDatedFromYesterday AND vDatedToTomorrow + AND wtc.direction <> 'out' + GROUP BY wtc.userFk, DATE(wtc.timed); + + INSERT INTO tmp.workerTimeControl (id, userFk, timed, direction) + SELECT id, userFk, timed, direction + FROM tmp.workerTimeControlAux; + + SET @lastUserFk := NULL; + SET @vIsOdd := TRUE; + SET @vDated := NULL; + SET @vLastTimed := NULL; + + UPDATE workerJourney wj + JOIN (SELECT sub.dated, userFk, SUM(NigthlyHours) NigthlyHours + FROM(SELECT (@vIsOdd := NOT @vIsOdd) isOdd, + IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd), + IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed), + IF(direction='in', @vDated := DATE(wtc.timed), @vDated ) dated, + wtc.userFk, + IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay, + workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed), + 0) NigthlyHours, + @lastUserFk := userFk + FROM (SELECT DISTINCT(wtc.id), wtc.userFk, wtc.timed, wtc.direction + FROM tmp.workerTimeControl wtc + LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id + WHERE wtc.timed BETWEEN vDatedFrom AND util.dayEnd(vDatedToTomorrow) + AND tce.id IS NULL + ORDER BY userFk, timed ASC + LIMIT 10000000000000000000 + ) wtc + ORDER BY wtc.userFk, wtc.timed + )sub + WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo + GROUP BY userFk, sub.dated + )night ON night.userFk = wj.userFk AND night.dated = wj.dated + SET wj.nocturn = night.NigthlyHours + WHERE NOT wj.isPaid + AND NOT isUpdated + AND night.NigthlyHours <> 0; + + -- Horas téoricas y precio de la hora ordinaria + UPDATE workerJourney wj + JOIN business b ON b.id = wj.businessFk + JOIN calendarType ct ON ct.id = b.calendarTypeFk + SET wj.priceOrdinaryHour = + (vMonthsByYear * b.amount) / + (vWeeksByYear * ct.hoursWeek), + wj.contractJourney = ct.hoursWeek / vDaysByWeek + WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) + AND NOT wj.isPaid + AND NOT isUpdated; + + -- Precio Extras, Vacaciones y Nocturnas + UPDATE workerJourney wj + JOIN(SELECT MAX(w.dated), t.dated, w.holidayInc, w.nightInc, w.extraInc + FROM time t + JOIN workerHourPrice w ON w.dated <= t.dated + WHERE t.dated BETWEEN vDatedFrom AND vDatedTo + GROUP BY t.dated + ) sub ON sub.dated = wj.dated + SET wj.priceHolidayHour = wj.priceOrdinaryHour * sub.holidayInc, + wj.priceNocturnHour = wj.priceOrdinaryHour * sub.nightInc, + wj.priceExtraHour = wj.priceOrdinaryHour * sub.extraInc + WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) + AND NOT wj.isPaid + AND NOT wj.isUpdated; + + -- Elimina el precio de las horas extras para los contratos parciales. + UPDATE workerJourney wj + JOIN business b ON b.id = wj.businessFk + JOIN calendarType ct ON ct.id = b.calendarTypeFk + SET wj.priceExtraHour = 0 + WHERE ct.isPartial + AND wj.dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) + AND NOT wj.isPaid + AND NOT wj.isUpdated; + + -- Ausencias + UPDATE workerJourney wj + JOIN businessCalendar bc ON bc.businessFk = wj.businessFk + AND bc.dated = wj.dated + JOIN absenceType ab ON ab.id = bc.absenceTypeFk + SET wj.permission = ab.permissionRate * wj.contractJourney, + wj.contractJourney = IF(ab.permissionRate = 1, 0, ab.permissionRate) * wj.contractJourney + WHERE ab.permissionRate > 0 + AND wj.dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) + AND NOT wj.isPaid + AND NOT wj.isUpdated; + + -- Sábados / Domingos + UPDATE workerJourney + SET holiday = IF(DAYNAME(dated)='sábado', 0, total), + contractJourney = 0 + WHERE DAYNAME(dated) IN ('sábado', 'domingo') + AND dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR userFk = vWorkerFk) + AND NOT isPaid + AND NOT isUpdated; + + -- Festivos por centro de trabajo + UPDATE workerJourney wj + JOIN calendarHolidays ch ON ch.dated = wj.dated + JOIN business b ON b.id = wj.businessFk + AND b.workcenterFk = ch.workcenterFk + SET wj.holiday = wj.total, + wj.permission = wj.contractJourney, + wj.contractJourney = 0 + WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) + AND NOT wj.isPaid + AND NOT wj.isUpdated; + + -- Horas extras + UPDATE workerJourney + SET extra = lunch + total - contractJourney + WHERE dated BETWEEN vDatedFrom AND vDatedTo + AND (vWorkerFk IS NULL OR userFk = vWorkerFk) + AND NOT isPaid + AND NOT isUpdated; + + DROP TEMPORARY TABLE tmp.timeControlCalculate; + DROP TEMPORARY TABLE tmp.`user`; + DROP TEMPORARY TABLE tmp.timeControlError; + DROP TEMPORARY TABLE tmp.workerTimeControlAux; + DROP TEMPORARY TABLE tmp.workerTimeControl; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerMistakeType_get.sql b/db/routines/vn/procedures/workerMistakeType_get.sql new file mode 100644 index 000000000..ae81640a1 --- /dev/null +++ b/db/routines/vn/procedures/workerMistakeType_get.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerMistakeType_get`() +BEGIN + +/** + * Obtiene los tipos de error para los trabajadores + */ + + SELECT code, description + FROM workerMistakeType + ORDER BY description; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerMistake_add.sql b/db/routines/vn/procedures/workerMistake_add.sql new file mode 100644 index 000000000..c4786090b --- /dev/null +++ b/db/routines/vn/procedures/workerMistake_add.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerMistake_add`(vWorkerFk INT, vWorkerMistakeTypeFk VARCHAR(10)) +BEGIN +/** + * Añade error al trabajador + * + * @param vWorkerFk id del trabajador al cual se le va a añadir error + * @param vWorkerMistakeTypeFk code del tipo de error + * + */ + INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk) + VALUES(vWorkerFk, vWorkerMistakeTypeFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlAdd.sql b/db/routines/vn/procedures/workerTimeControlAdd.sql new file mode 100644 index 000000000..1f5f0db2d --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControlAdd.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlAdd`(IN vUserFk INT, IN vWarehouseFk INT, IN vDated DATETIME) +BEGIN + + /*INSERT INTO workerTimeControl(userFk, timed, manual, warehouseFk) + VALUES(vUserFk, vDated, FALSE, vWarehouseFk); + + CALL vn.workerTimeControlSOWP(vUserFk , vDated);*/ + + CALL vn.workerTimeControl_add(vUserFk,vWarehouseFk,util.VN_NOW(),FALSE); + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlPinGenerate.sql b/db/routines/vn/procedures/workerTimeControlPinGenerate.sql new file mode 100644 index 000000000..afbb47c31 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControlPinGenerate.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlPinGenerate`( + vWorkerFk INT) +BEGIN +/** + * Create new pin for workerFk or new pin for all workers if vWorkerFk is null + * + */ + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlSOWP.sql b/db/routines/vn/procedures/workerTimeControlSOWP.sql new file mode 100644 index 000000000..14959b942 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControlSOWP.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlSOWP`(IN vUserFk INT, IN vDated DATE) +BEGIN + SET @order := 0; + + UPDATE workerTimeControl + SET `order` = @order := @order + 1 + WHERE vUserFk =userFk + AND vDated = DATE(timed) + ORDER BY timed; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlSetOrder.sql b/db/routines/vn/procedures/workerTimeControlSetOrder.sql new file mode 100644 index 000000000..953fa25f5 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControlSetOrder.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlSetOrder`() +BEGIN + + SET @order := 1; + SET @userFk := 0; + SET @day := 0; + + UPDATE tmp.workerTimeControl + SET `order` = IF(userFk = @userFk AND day(timed) = @day, @order := @order + 1, @order := 1), + userFk = @userFk := userFk, + manual = manual + (0 * @day := day(timed)) + ORDER BY userFk, timed; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_add.sql b/db/routines/vn/procedures/workerTimeControl_add.sql new file mode 100644 index 000000000..7769d71aa --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_add.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) +BEGIN + + + SELECT workerTimeControl_add(vUserFk,vWarehouseFk,vTimed,vIsManual); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_calculateOddDays.sql b/db/routines/vn/procedures/workerTimeControl_calculateOddDays.sql new file mode 100644 index 000000000..9c1e58608 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_calculateOddDays.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_calculateOddDays`() +BEGIN +/** + * Calculo de las fichadas impares por empleado y dia. + * + * @return tmp.workerTimeControlOddDays (userFk, dated) + */ + SET @cont := FALSE; + SET @lastUserFk:= NULL; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlOddDays; + CREATE TEMPORARY TABLE tmp.workerTimeControlOddDays + SELECT sub2.userFk workerFk, sub2.dated + FROM ( + SELECT userFk, + dated, + COUNT(*) cont2 + FROM ( + SELECT DATE(wtc.timed) dated, + userFk, + IFNULL(@cont, @cont := TRUE ), + IF(direction = 'in' OR userFk <> @lastUserFk, @cont := @cont+1, TRUE), + @cont cont, + @lastUserFk := userFk + FROM workerTimeControl wtc + WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND util.dayEnd(util.VN_CURDATE()) + ORDER BY userFk, timed + LIMIT 10000000000000000000)sub + GROUP BY cont + HAVING cont2 MOD 2 = 1 + )sub2; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_check.sql b/db/routines/vn/procedures/workerTimeControl_check.sql new file mode 100644 index 000000000..ce0e51490 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_check.sql @@ -0,0 +1,168 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_check`(vUserFk INT, vDated DATE,vTabletFk VARCHAR(100)) +proc: BEGIN +/** + * Verifica si el empleado puede fichar en el momento actual, si puede fichar llama a workerTimeControlAdd + * + * @param vUserFk Identificador del trabajador + * @return Retorna si encuentra un problema 'odd','maxTimeWork','breakDay','breakWeek' ; + * En caso de tener algun problema retorna el primero que encuentra + */ + DECLARE vLastIn DATETIME ; + DECLARE vLastOut DATETIME ; + DECLARE vDayWorkMax INT; + DECLARE vDayBreak INT; + DECLARE vWeekBreak INT ; + DECLARE vWeekScope INT; + DECLARE vDayStayMax INT; + DECLARE vProblem VARCHAR(20) DEFAULT NULL; + DECLARE vTimedWorked INT; + DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; + DECLARE vDepartmentFk INT; + DECLARE vTo VARCHAR(50) DEFAULT NULL; + DECLARE vUserName VARCHAR(50) DEFAULT NULL; + DECLARE vBody VARCHAR(255) DEFAULT NULL; + + SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax + INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax + FROM workerTimeControlParams; + + SELECT MAX(timed) INTO vLastIn + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'in'; + + SELECT MAX(timed) INTO vLastOut + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'out'; + + SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo + FROM account.user u + WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); + + SELECT CONCAT(firstName,' ',lastName) INTO vUserName + FROM worker w + WHERE w.id = vUserFk; + + + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA + + -- VERIFICAR DESCANSO DIARIO + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN + SELECT "Descansos 12 h" AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 12 h") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + END IF; + + -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ + IF (SELECT MOD(COUNT(*),2) -- <>0 + FROM workerTimeControl + WHERE userFk = vUserFk + AND timed >= vLastIn + ) THEN + SELECT "Dias con fichadas impares" AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + END IF; + + -- VERIFICAR VACACIONES + SELECT at2.name INTO vCalendarStateType + FROM calendar c + JOIN business b ON b.id = c.businessFk + JOIN absenceType at2 ON at2.id = c.dayOffTypeFk + WHERE c.dated = util.VN_CURDATE() + AND at2.isAllowedToWork = FALSE + AND b.workerFk = vUserFk + LIMIT 1; + + IF(LENGTH(vCalendarStateType)) THEN + SELECT vCalendarStateType AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + + END IF; + + -- VERIFICAR CONTRATO EN VIGOR + IF (SELECT COUNT(*) + FROM business b + WHERE b.workerFk = vUserFk + AND b.started <= vDated + AND IFNULL(b.ended, vDated) >= vDated + ) = 0 THEN + SELECT "No hay un contrato en vigor" AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + + END IF; + + -- VERIFICAR DESCANSO SEMANAL + SET @vHasBreakWeek:= FALSE; + SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); + + DROP TEMPORARY TABLE IF EXISTS tmp.trash; + CREATE TEMPORARY TABLE tmp.trash + SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, + @vLastTimed:= UNIX_TIMESTAMP(timed) + FROM workerTimeControl + WHERE timed>= (util.VN_NOW() - INTERVAL vWeekScope SECOND) + AND userFk= vUserFk + AND direction IN ('in','out') + ORDER BY timed ASC; + + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA + SELECT "Descansos 36 h" AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 36 h") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + END IF; + + DROP TEMPORARY TABLE tmp.trash; + + ELSE -- DIA ACTUAL + + -- VERIFICA QUE EL TIEMPO EFECTIVO NO SUPERE EL MÁXIMO + SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked + FROM workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= vLastIn + ORDER BY timed; + + IF vTimedWorked > vDayWorkMax THEN + SELECT "Jornadas" AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Jornadas") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + END IF; + + END IF; + + -- VERIFICAR DEPARTAMENTO + /* IF vTabletFk IS NOT NULL THEN + SELECT wtcu.departmentFk INTO vDepartmentFk + FROM workerTimeControlUserInfo wtcu + WHERE wtcu.userFk = vUserFk; + IF (SELECT COUNT(td.tabletFk) + FROM tabletDepartment td + WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk + ) = 0 THEN + SELECT "No perteneces a este departamento." AS problem; + -- ENVIAMOS CORREO AL BOSSFK + SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; + CALL mail_insert(vTo,vTo,'error al fichar',vBody); + LEAVE proc; + END IF; + END IF;*/ + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_checkBreak.sql b/db/routines/vn/procedures/workerTimeControl_checkBreak.sql new file mode 100644 index 000000000..15dd12373 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_checkBreak.sql @@ -0,0 +1,154 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_checkBreak`(vStarted DATE) +BEGIN +/** + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * El sistema verificará el descanso corto en la siguiente semana + * o el largo en las 2 siguientes semanas a partir de la fecha dada + * @param vStarted día inicio de la semana en el que se quiere verificar + * @return tmp.workerWithoutWeekBreak (workerFk) + */ + DECLARE vShortEnded DATETIME; + DECLARE vLongEnded DATETIME; + DECLARE vShortWeekBreak INT; + DECLARE vLongWeekBreak INT; + + SELECT util.dayEnd(DATE_ADD(vStarted, INTERVAL shortWeekDays DAY)), + util.dayEnd(DATE_ADD(vStarted, INTERVAL longWeekDays DAY)), + shortWeekBreak, + longWeekBreak + INTO vShortEnded, vLongEnded, vShortWeekBreak, vLongWeekBreak + FROM workerTimeControlConfig; + + SET @previousTimed:= UNIX_TIMESTAMP(vStarted); + SET @lastUserFk := NULL; + + -- Descanso corto en la semana + + DROP TEMPORARY TABLE IF EXISTS tmp.worker; + CREATE TEMPORARY TABLE tmp.worker + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT DISTINCT userFk workerFk + FROM workerTimeControl + WHERE timed BETWEEN vStarted AND vShortEnded + AND direction IN ('in', 'out'); + + DROP TEMPORARY TABLE IF EXISTS tmp.worker2; + CREATE TEMPORARY TABLE tmp.worker2 + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT workerFk + FROM tmp.worker; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutShortWeekBreak; + CREATE TEMPORARY TABLE tmp.workerWithoutShortWeekBreak + SELECT sub2.userFk workerFk + FROM(SELECT sub.userFk, + IF(sub.userFk <> @lastUserFk, + @previousTimed:= sub.timed, + FALSE), + IF(sub.timed - @previousTimed >= vShortWeekBreak, + TRUE, + FALSE) hasShortWeekBreak, + @previousTimed:= sub.timed, + @lastUserFk:= sub.userFk + FROM ( + SELECT userFk, UNIX_TIMESTAMP(timed) timed + FROM workerTimeControl + WHERE timed BETWEEN vStarted AND vShortEnded + AND direction IN ('in', 'out') + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL( + MIN(wtc.timed), + DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND))) + FROM tmp.worker w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN vShortEnded + AND DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND) + GROUP BY w.workerFk + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL( + MAX(wtc.timed), + DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND))) + FROM tmp.worker2 w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN + DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND) + AND vStarted + GROUP BY w.workerFk + ORDER BY userFk, timed + LIMIT 10000000000000000000 + )sub + )sub2 + GROUP BY sub2.userFk + HAVING NOT SUM(hasShortWeekBreak); + + -- Descanso largo en las 2 siguientes semanas + DROP TEMPORARY TABLE tmp.worker; + CREATE TEMPORARY TABLE tmp.worker + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT workerFk + FROM tmp.workerWithoutShortWeekBreak; + + DROP TEMPORARY TABLE tmp.worker2; + CREATE TEMPORARY TABLE tmp.worker2 + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT workerFk + FROM tmp.workerWithoutShortWeekBreak; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreak; + CREATE TEMPORARY TABLE tmp.workerWithoutWeekBreak + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT sub2.userFk workerFk + FROM(SELECT userFk, + IF(userFk <> @lastUserFk, + @previousTimed:= timed, + TRUE), + IF(timed - @previousTimed >= vLongWeekBreak, + TRUE, + FALSE) hasLongWeekBreak, + @previousTimed:= timed, + @lastUserFk:= userFk + FROM (SELECT userFk, UNIX_TIMESTAMP(timed) timed + FROM workerTimeControl wtc + JOIN tmp.workerWithoutShortWeekBreak wws ON wws.workerFk = wtc.userFk + WHERE timed BETWEEN vStarted AND vLongEnded + AND direction IN ('in', 'out') + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL(MIN(wtc.timed), + DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND))) + FROM tmp.worker w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN vLongEnded + AND DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND) + GROUP BY w.workerFk + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL(MAX(wtc.timed), + DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND))) + FROM tmp.worker2 w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND) + AND vStarted + GROUP BY w.workerFk + ORDER BY userFk, timed + LIMIT 10000000000000000000 + )sub + )sub2 + GROUP BY userFk + HAVING NOT SUM(hasLongWeekBreak); + + DROP TEMPORARY TABLE tmp.workerWithoutShortWeekBreak, tmp.worker, tmp.worker2; +END$$ +DELIMITER ; diff --git a/db/changes/234004/02-workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql similarity index 99% rename from db/changes/234004/02-workerTimeControl_clockIn.sql rename to db/routines/vn/procedures/workerTimeControl_clockIn.sql index 69091e51c..2d790c301 100644 --- a/db/changes/234004/02-workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -283,4 +283,4 @@ BEGIN SELECT LAST_INSERT_ID() id; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_direction.sql b/db/routines/vn/procedures/workerTimeControl_direction.sql new file mode 100644 index 000000000..ce44b9703 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_direction.sql @@ -0,0 +1,61 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_direction`(vWorkerFk VARCHAR(10), vTimed DATETIME) +BEGIN +/** + * Devuelve que direcciones de fichadas son lógicas a partir de la anterior fichada + * @param vWorkerFk Identificador del trabajador + * @return (option1, option2) + * Los valores posibles de retorno son ('in', 'inMiddle', 'outMiddle', 'out') + */ + DECLARE vLastIn DATETIME ; + DECLARE vIsMiddleOdd BOOLEAN ; + + IF (vTimed IS NULL) THEN + SET vTimed = util.VN_NOW(); + END IF; + + SELECT timed INTO vLastIn + FROM workerTimeControl + WHERE userFk = vWorkerFk + AND direction = 'in' + AND timed < vTimed + ORDER BY timed DESC + LIMIT 1; + + SELECT (COUNT(*)mod 2 = 1) INTO vIsMiddleOdd + FROM workerTimeControl + WHERE userFk = vWorkerFk + AND direction = 'middle' + AND timed BETWEEN vLastIn AND util.VN_NOW(); + + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlDirection; + CREATE TEMPORARY TABLE tmp.workerTimeControlDirection + SELECT IF(isCorrect, option1, NULL) option1, + IF(isCorrect, option2, NULL) option2 + FROM( SELECT IF(w.direction <> 'out' AND (UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(w.timed) > wc.dayBreak), FALSE, TRUE) isCorrect, + CASE WHEN w.direction ='in' THEN 'inMiddle' + WHEN w.direction = 'out' THEN 'in' + WHEN w.direction = 'middle' AND vIsMiddleOdd THEN 'outMiddle' + WHEN w.direction IS NULL THEN 'in' + ELSE 'inMiddle' + END option1, + CASE WHEN w.direction ='in' THEN 'out' + WHEN w.direction = 'out' THEN NULL + WHEN w.direction = 'middle' AND vIsMiddleOdd THEN NULL + WHEN w.direction IS NULL THEN NULL + ELSE 'out' + END option2 + FROM workerTimeControl w + JOIN workerTimeControlConfig wc ON TRUE + WHERE w.timed <= vTimed + AND w.userFk = vWorkerFk + ORDER BY w.timed DESC + LIMIT 1)sub; + + IF (SELECT IF(COUNT(*)=0, TRUE, FALSE) FROM tmp.workerTimeControlDirection ) THEN + INSERT INTO tmp.workerTimeControlDirection (option1, option2) + VALUES('in', NULL); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_getClockIn.sql b/db/routines/vn/procedures/workerTimeControl_getClockIn.sql new file mode 100644 index 000000000..11cd23fa5 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_getClockIn.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_getClockIn`( + vUserFk INT, + vDated DATE) +BEGIN +/** + * Muestra una tabla con los 7 días inmediatamente anteriores a la fecha proporcionada + * y las fichadas de cada día, en columnas por día + * @param vUserFk Identificador del trabajador + * @param vDated Fecha proporcionada + */ + CALL timeControl_calculateByWorker( + vUserFk, + DATE_SUB(vDated, INTERVAL 6 DAY), util.dayEnd(vDated)); + + SET @position := 0; + SET @lastDated := NULL; + + SELECT * + FROM( SELECT MAX(6daysAgo) 6daysAgo, + MAX(6daysAgoDirection) 6daysAgoDirection, + MAX(5daysAgo) 5daysAgo, + MAX(5daysAgoDirection) 5daysAgoDirection, + MAX(4daysAgo) 4daysAgo, + MAX(4daysAgoDirection) 4daysAgoDirection, + MAX(3daysAgo) 3daysAgo, + MAX(3daysAgoDirection) 3daysAgoDirection, + MAX(2daysAgo) 2daysAgo, + MAX(2daysAgoDirection) 2daysAgoDirection, + MAX(1daysAgo) 1daysAgo, + MAX(1daysAgoDirection) 1daysAgoDirection, + MAX(0daysAgo) 0daysAgo, + MAX(0daysAgoDirection) 0daysAgoDirection + FROM(SELECT IF(daysAgo = 6, timed, '') 6daysAgo, + IF(daysAgo = 5, timed, '') 5daysAgo, + IF(daysAgo = 4, timed, '') 4daysAgo, + IF(daysAgo = 3, timed, '') 3daysAgo, + IF(daysAgo = 2, timed, '') 2daysAgo, + IF(daysAgo = 1, timed, '') 1daysAgo, + IF(daysAgo = 0, timed, '') 0daysAgo, + IF(daysAgo = 6, direction, '') 6daysAgoDirection, + IF(daysAgo = 5, direction, '') 5daysAgoDirection, + IF(daysAgo = 4, direction, '') 4daysAgoDirection, + IF(daysAgo = 3, direction, '') 3daysAgoDirection, + IF(daysAgo = 2, direction, '') 2daysAgoDirection, + IF(daysAgo = 1, direction, '') 1daysAgoDirection, + IF(daysAgo = 0, direction, '') 0daysAgoDirection, + + direction, + position + FROM(SELECT DATEDIFF(vDated, timed) daysAgo, + TIME_FORMAT(timed,'%H:%i') timed, + IF(DATE(timed) <> @lastDated, @position := 0, NULL), + @position := @position+1 position, + @lastDated := DATE(timed), + direction + FROM workerTimeControl wtc + WHERE wtc.userFk = vUserFk + AND wtc.timed >= TIMESTAMPADD(DAY, -6,vDated) + ORDER BY wtc.timed + LIMIT 10000000000000000000 + )sub + )sub2 + GROUP BY position) sub3 + JOIN (SELECT MAX(IF(daysAgo = 6, timeWorkSeconds, 0)) 6daysAgoTotal, + MAX(IF(daysAgo = 5, timeWorkSeconds, 0)) 5daysAgoTotal, + MAX(IF(daysAgo = 4, timeWorkSeconds, 0)) 4daysAgoTotal, + MAX(IF(daysAgo = 3, timeWorkSeconds, 0)) 3daysAgoTotal, + MAX(IF(daysAgo = 2, timeWorkSeconds, 0)) 2daysAgoTotal, + MAX(IF(daysAgo = 1, timeWorkSeconds, 0)) 1daysAgoTotal, + MAX(IF(daysAgo = 0, timeWorkSeconds, 0)) 0daysAgoTotal + FROM (SELECT DATEDIFF(vDated, dated) daysAgo, + timeWorkSeconds + FROM tmp.timeControlCalculate) sub4)sub5 ON TRUE; + + DROP TEMPORARY TABLE tmp.timeControlCalculate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_login.sql b/db/routines/vn/procedures/workerTimeControl_login.sql new file mode 100644 index 000000000..c46663e1f --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_login.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_login`(vWorkerFk VARCHAR(10)) +BEGIN +/** + * Consulta la información del usuario y los botones que tiene que activar en la tablet tras hacer login + * Solo retornará 1 ó 2 opciones de las 4 posibles + * @param vWorkerFk Identificador del trabajador + * @return (name, surname, userFk, departmentFk, button1, button2) + * Los valores posibles para button son ('in', 'inMiddle', 'outMiddle', 'out') + */ + CALL vn.workerTimeControl_direction(vWorkerFk, util.VN_NOW()); + + SELECT wi.name, + wi.surname, + wi.userFk, + wi.departmentFk, + w.option1 button1, + w.option2 button2 + FROM workerTimeControlUserInfo wi + JOIN tmp.workerTimeControlDirection w + WHERE wi.userFk = vWorkerFk + LIMIT 1; + + DROP TEMPORARY TABLE tmp.workerTimeControlDirection; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_remove.sql b/db/routines/vn/procedures/workerTimeControl_remove.sql new file mode 100644 index 000000000..7b34cbbeb --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_remove.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_remove`(IN vUserFk INT, IN vTimed DATETIME) +BEGIN + + DECLARE vDirectionRemove VARCHAR(6); + DECLARE vDirectionPrevious VARCHAR(6); + DECLARE vTimedPrevious DATETIME; + + SELECT direction INTO vDirectionRemove + FROM vn.workerTimeControl + WHERE userFk = vUserFk + AND timed = vTimed ; + + IF vDirectionRemove = 'out' THEN + + SELECT timed, direction INTO vTimedPrevious, vDirectionPrevious + FROM vn.workerTimeControl + WHERE userFk = vUserFk + AND timed < vTimed + ORDER BY timed DESC + LIMIT 1; + + IF vDirectionPrevious = "middle" THEN + UPDATE vn.workerTimeControl + SET direction = "out" + WHERE userFk = vUserFk + AND timed = vTimedPrevious; + END IF; + + ELSE IF vDirectionRemove = 'in' THEN + + UPDATE vn.workerTimeControl + SET direction = "in" + WHERE userFk = vUserFk + AND timed > vTimed + ORDER BY timed ASC + LIMIT 1; + END IF; + + END IF; + + DELETE FROM vn.workerTimeControl + WHERE userFk = vUserFk + AND timed = vTimed; + + CALL vn.workerTimeControlSOWP(vUserFk, vTimed); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_repair.sql b/db/routines/vn/procedures/workerTimeControl_repair.sql new file mode 100644 index 000000000..f4f0fd0a5 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_repair.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_repair`() +proc: BEGIN +/** + * Corrige las fichadas + * + */ + +/*1- poner todos a middle*/ +UPDATE vn.workerTimeControl SET direction = 'middle'; + +/*2- poner los out*/ +UPDATE vn.workerTimeControl wtc + JOIN + (SELECT userFk,MAX(timed) maxTimed FROM + (SELECT id, userFk, timed, date(timed) dated + FROM vn.workerTimeControl + ) sub + GROUP BY userFk,dated + )sub + SET direction = "out" + WHERE wtc.userFk = sub.userFk + AND wtc.timed = sub.maxTimed; + + /*3- poner los in*/ +UPDATE vn.workerTimeControl wtc + JOIN + (SELECT userFk,MIN(timed) maxTimed FROM + (SELECT id, userFk, timed, date(timed) dated + FROM vn.workerTimeControl + ) sub + GROUP BY userFk,dated + )sub + SET direction = "in" + WHERE wtc.userFk = sub.userFk + AND wtc.timed = sub.maxTimed ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_sendMailByDepartment.sql b/db/routines/vn/procedures/workerTimeControl_sendMailByDepartment.sql new file mode 100644 index 000000000..5b276084a --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_sendMailByDepartment.sql @@ -0,0 +1,129 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_sendMailByDepartment`(IN vDatedFrom DATETIME, IN vDatedTo DATETIME, IN vWorkerFk INT) +BEGIN +/** + * Inserta el registro de horario semanalmente de PRODUCCION, CAMARA, REPARTO, TALLER NATURAL y TALLER ARTIFICIAL en vn.mail. + * + * @param vDatedFrom + * @param vDatedTo + * @param vWorkerFk -> En el caso de querer generarlo para todos los empleados deberá de pasarse = NULL + */ + SET session group_concat_max_len = 15000; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; + DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate; + DROP TEMPORARY TABLE IF EXISTS tmp.reportHours; + + IF vWorkerFk IS NULL THEN + CALL timeControl_calculateAll(vDatedFrom,vDatedTo); + CALL timeBusiness_calculateAll(vDatedFrom,vDatedTo); + ELSE + CALL timeControl_calculateByUser(vWorkerFk,vDatedFrom,vDatedTo); + CALL timeBusiness_calculateByUser(vWorkerFk,vDatedFrom,vDatedTo); + END IF; + + CREATE TEMPORARY TABLE tmp.reportHours + SELECT t.dated, + IF (tm.hoursWeek IS NULL,'', GROUP_CONCAT(DATE_FORMAT(wtc.timed,'%H:%i') ORDER BY wtc.timed ASC SEPARATOR ' ') ) timeWorkDay, + SEC_TO_TIME(IFNULL(tm.timeWorkSeconds, 0)) tm, + SEC_TO_TIME(IFNULL(tc.timeWorkSeconds, 0)) tc, + SEC_TO_TIME(IFNULL(tc.timeWorkSeconds, 0) - IFNULL(tm.timeWorkSeconds, 0)) balance, + w.lastName, + w.firstname, + c.fi, + w.id userFk, + MONTHNAME(t.dated) mes, + YEAR(t.dated) año, + w.id, + tm.hoursWeek, + tm.type, + b.started, + b.ended, + d.name, + tm.businessFk + FROM time t + LEFT JOIN tmp.timeBusinessCalculate tm ON tm.dated = t.dated + LEFT JOIN tmp.timeControlCalculate tc ON tc.dated = tm.dated AND tc.userFk = tm.userFk + LEFT JOIN vn.workerTimeControl wtc ON wtc.userFk = tm.userFk AND DATE(wtc.timed) = t.dated + LEFT JOIN business b ON b.workerFk = tm.userFk AND b.id = tm.businessFk + LEFT JOIN workCenter wc ON wc.id = b.workcenterFk + LEFT JOIN department d ON d.id = b.departmentFk + LEFT JOIN worker w ON w.id = tm.userFk + LEFT JOIN client c ON c.id = w.id + WHERE wc.name NOT IN ('VNH') + AND d.hasToSendMail + AND w.businessFk + GROUP BY tm.userFk,t.dated + ORDER BY tm.userFk,t.dated; + + INSERT INTO vn.mail (receiver, replyTo, subject, body) + SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', WEEK(vDatedFrom), ' año ', YEAR(vDatedFrom)) , + CONCAT(' + + + + + + +
+

REGISTRO DE LA JORNADA DE LOS TRABAJADORES

+ + + + + + + + + + + + + + + + +
+ Según la información recogida en el sistema, adjuntamos la tabla con los registros. Cualquier incidencia rogamos la comunique a laboral@verdnatura.es. +
De no recibir incidencia por su parte, se entenderá que el registro es correcto.
+
Empresa: Verdnatura Levante SL
Trabajador: ',rh.firstname,' ',rh.lastName, ' NIF: ',rh.fi, '
AÑO: ',rh.año, ' MES: ',UPPER(rh.mes), ' Calendario Laboral: ',rh.hoursWeek,' horas semanales
+
+ + + + + + + + + ', + GROUP_CONCAT(DISTINCT '' ORDER BY rh.dated SEPARATOR ''), + ' + + + + + + +
Fecha:Día:Fichadas:Horas a trabajar:Horas trabajadas:Balance:
', DATE_FORMAT( rh.dated, '%d-%m-%y'), + ' ', CONCAT(UCASE(LEFT(DAYNAME(rh.dated), 1)), SUBSTRING(DAYNAME(rh.dated), 2)), + ' ', IFNULL(rh.timeWorkDay,' '),' ', IFNULL(rh.type,' '), + ' ', rh.tm, + ' ', SUBSTRING_INDEX(rh.tc, '.', 1), + ' ', SUBSTRING_INDEX(rh.balance, '.', 1), '
Total horas trabajadas: ', SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(rh.tc))), '.', 1),'', SUBSTRING_INDEX(SEC_TO_TIME(SUM(TIME_TO_SEC(rh.balance))), '.', 1),'
+ ') + FROM tmp.reportHours rh + JOIN account.emailUser eu ON rh.id = eu.userFk + GROUP BY rh.id; + + DROP TEMPORARY TABLE tmp.timeControlCalculate; + DROP TEMPORARY TABLE tmp.timeBusinessCalculate; + DROP TEMPORARY TABLE tmp.reportHours; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_sendMailByDepartmentLauncher.sql b/db/routines/vn/procedures/workerTimeControl_sendMailByDepartmentLauncher.sql new file mode 100644 index 000000000..406bb8d8d --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_sendMailByDepartmentLauncher.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_sendMailByDepartmentLauncher`() +BEGIN + DECLARE vDatedFrom, vDatedTo DATETIME; + + IF (DAYNAME(util.VN_CURDATE()) = 'miércoles') THEN + SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL 9 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(), INTERVAL 3 DAY), ' 23:59:59') INTO vDatedFrom, vDatedTo; + + CALL vn.workerTimeControl_sendMailByDepartment(vDatedFrom, vDatedTo, NULL); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_setOrder.sql b/db/routines/vn/procedures/workerTimeControl_setOrder.sql new file mode 100644 index 000000000..c3d3753ae --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_setOrder.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_setOrder`(vUserFk INT, vStarted DATE, vFinished DATE) +BEGIN + + SET @order := 0; + SET @day := '2000-01-01'; + + UPDATE vn.workerTimeControl w + SET w.`order` = @order := IF(@day = @day := date(timed), @order, 0) + 1 + WHERE w.userFk = vUserFk + AND w.timed BETWEEN vStarted AND util.dayend(vFinished) + ORDER BY w.timed; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_weekCheckBreak.sql b/db/routines/vn/procedures/workerTimeControl_weekCheckBreak.sql new file mode 100644 index 000000000..70ef3da07 --- /dev/null +++ b/db/routines/vn/procedures/workerTimeControl_weekCheckBreak.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_weekCheckBreak`(vStarted DATE, vEnded DATE) +BEGIN +/** + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * El sistema verificará el descanso corto en la siguiente semana + * o el largo en las 2 siguientes semanas a partir de las fechas dadas + * @param vStarted día inicio para verificar + * @param vEnded día final para verificar + * @return tmp.workerWithoutWeekBreak (workerFk) + */ + DECLARE vDone INT DEFAULT FALSE; + + IF(vStarted > vEnded) then + CALL util.throw ('Date end can not be greater then start'); + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreakInWeek; + CREATE TEMPORARY TABLE tmp.workerWithoutWeekBreakInWeek + (workerFk INT, + PRIMARY KEY(workerFk)) + ENGINE = MEMORY; + + + WHILE vStarted <= vEnded DO + + CALL workerTimeControl_checkBreak(vStarted); + INSERT IGNORE INTO tmp.workerWithoutWeekBreakInWeek + SELECT workerFk + FROM tmp.workerWithoutWeekBreak; + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreak; + SET vStarted = DATE_ADD(vStarted, INTERVAL 1 DAY); + + END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workerWeekControl.sql b/db/routines/vn/procedures/workerWeekControl.sql new file mode 100644 index 000000000..8001d8d3a --- /dev/null +++ b/db/routines/vn/procedures/workerWeekControl.sql @@ -0,0 +1,133 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerWeekControl`(vUserFk INT, vDated DATE, vTabletFk VARCHAR(100)) +BEGIN +/* +* Devuelve la cantidad de descansos de 12h y de 36 horas que ha disfrutado el trabajador +* en la semana inmediatamente anterior a la fecha que pasa como parámetro. +* UPDATED PAK 2019/09/02 +* PENDING REVIEW +*/ + DECLARE vDescansos12h INT; + DECLARE vDescansos36h INT; + DECLARE vJornadas INT; + DECLARE vImpares INT; + DECLARE vHasSignedToday BOOLEAN; + DECLARE v12hoursInMinutes INT DEFAULT 719; + DECLARE v36hoursInMinutes INT DEFAULT 2159; + DECLARE vCantWork VARCHAR(50) DEFAULT ''; + DECLARE vDepartmentFk INT; + DECLARE isEnabled BOOLEAN DEFAULT TRUE; + + SELECT COUNT(*) INTO vHasSignedToday + FROM workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; + + SET @day := 0; + SET @lastTimed := util.VN_NOW(); + + SELECT SUM(IF(interval_in_minutes >= v12hoursInMinutes,1,0)), SUM(FLOOR(interval_in_minutes/ v36hoursInMinutes)) , SUM(jornadas) + INTO vDescansos12h, vDescansos36h, vJornadas + FROM + ( + SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas + FROM + ( + SELECT @lastTimed fichada_anterior, + timed, + CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, + IF(day(timed) != @day, 1, 0) as jornadas, + @day := day(timed) dia_del_mes, + @lastTimed := timed fichada_actual + FROM + ( + SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed + FROM + (SELECT TIMESTAMPADD(DAY, -11, util.VN_NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior + UNION ALL + SELECT timed, userFk + FROM vn.workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= TIMESTAMPADD(DAY, -10,vDated) + UNION ALL + SELECT IF(vHasSignedToday, '2000-01-01 00:00', util.VN_NOW()) as timed, vUserFk + ) sub4 + ORDER BY timed + ) sub + + ) sub2 + WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) + ) sub3 ; + + SELECT IFNULL(SUM(impar),0) into vImpares + FROM ( + SELECT day(timed) as dayNumber, + count(*) mod 2 as impar + FROM vn.workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= TIMESTAMPADD(WEEK, -1,vDated) AND timed < vDated + GROUP BY dayNumber + ) sub; + + -- Vacaciones + SELECT at2.name INTO vCantWork + FROM calendar c + JOIN business b ON b.id = c.businessFk + JOIN absenceType at2 ON at2.id = c.dayOffTypeFk + WHERE c.dated = util.VN_CURDATE() + AND at2.isAllowedToWork = FALSE + AND b.workerFk = vUserFk + LIMIT 1; + + -- Contrato en vigor + SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork + FROM business b + WHERE b.workerFk = vUserFk + AND b.started <= vDated + AND IFNULL(b.ended, vDated) >= vDated; + + -- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) + IF vTabletFk <> '0' THEN + -- 1 Obtener el departamento del usuario + SELECT wtcu.departmentFk INTO vDepartmentFk + FROM workerTimeControlUserInfo wtcu + WHERE wtcu.userFk = vUserFk; + -- 2 Comprobar si la tablet pertenece al departamento + SELECT COUNT(td.tabletFk) INTO isEnabled + FROM tabletDepartment td + WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; + + END IF; + + IF vJornadas IS NOT NULL THEN + + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis + UNION ALL + SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis + UNION ALL + SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, IF(vDescansos36h / 2 >= FLOOR(vJornadas/10), 'Correcto','Error: mínimo 2 cada 14 dias') as Análisis + UNION ALL + SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis + UNION ALL + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, + IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + UNION ALL + SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; + + ELSE + + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis + UNION ALL + SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + UNION ALL + SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/worker_getFromHasMistake.sql b/db/routines/vn/procedures/worker_getFromHasMistake.sql new file mode 100644 index 000000000..052097e79 --- /dev/null +++ b/db/routines/vn/procedures/worker_getFromHasMistake.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_getFromHasMistake`(vDepartmentFk INT) +BEGIN + +/** + * Obtiene los trabajadores de los departamentos que se les puede poner error + * @param vDepartmentFk id del departamento + * + */ + + SELECT w.id,w.firstName, w.lastName,d.name + FROM worker w + JOIN workerDepartment wd ON wd.workerFk = w.id + JOIN department d ON d.id = wd.departmentFk + WHERE d.id = vDepartmentFk + ORDER BY firstName; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/worker_getHierarchy.sql b/db/routines/vn/procedures/worker_getHierarchy.sql new file mode 100644 index 000000000..de6956898 --- /dev/null +++ b/db/routines/vn/procedures/worker_getHierarchy.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_getHierarchy`(vUserFk INT) +BEGIN +/** + * Retorna una tabla temporal con los trabajadores que tiene + * el usuario por debajo en la jerarquía de la empresa. + * + * @param vUserFk Id de usuario. + * @return tmp.workerHierarchyList + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.workerHierarchyList + (PRIMARY KEY (workerFk)) + ENGINE = MEMORY + WITH RECURSIVE workerHierarchy AS ( + SELECT id workerFk, bossFk, 0 depth + FROM vn.worker + WHERE id = vUserFk + UNION ALL + SELECT w.id, w.bossFk, wh.depth + 1 + FROM vn.worker w + JOIN workerHierarchy wh ON w.bossFk = wh.workerFk + ) + SELECT * + FROM workerHierarchy + ORDER BY depth, workerFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/worker_getSector.sql b/db/routines/vn/procedures/worker_getSector.sql new file mode 100644 index 000000000..759bb839b --- /dev/null +++ b/db/routines/vn/procedures/worker_getSector.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_getSector`() +BEGIN + +/** + * Obtiene el sector del usuario conectado +*/ + + SELECT s.id,s.description,s.warehouseFk + FROM sector s + JOIN operator o ON o.sectorFk = s.id + WHERE o.workerFk = account.myUser_getId(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/worker_updateBalance.sql b/db/routines/vn/procedures/worker_updateBalance.sql new file mode 100644 index 000000000..c1fd0adf7 --- /dev/null +++ b/db/routines/vn/procedures/worker_updateBalance.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelfFk INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2)) +BEGIN +/** + * Actualiza la columna balance de worker. + * + * @param selfFk, credit, debit + */ + UPDATE worker + SET balance = IFNULL(balance, 0) + IFNULL(vCredit, 0) - IFNULL(vDebit, 0) + WHERE id = vSelfFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/worker_updateBusiness.sql b/db/routines/vn/procedures/worker_updateBusiness.sql new file mode 100644 index 000000000..274bc3ec0 --- /dev/null +++ b/db/routines/vn/procedures/worker_updateBusiness.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBusiness`(vSelf INT) +BEGIN +/** + * Activates an account and configures its email settings. + * + * @param vSelf account id. + */ + DECLARE vOldBusinessFk INT; + DECLARE vNewBusinessFk INT; + + SELECT businessFk INTO vOldBusinessFk FROM worker WHERE id = vSelf; + + SELECT id INTO vNewBusinessFk + FROM business + WHERE workerFk = vSelf + AND util.VN_CURDATE() BETWEEN started AND IFNULL(ended, util.VN_CURDATE()) + LIMIT 1; + + UPDATE worker + SET businessFk = vNewBusinessFk + WHERE id = vSelf; + + IF vOldBusinessFk IS NULL THEN + CALL account.account_enable(vSelf); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/worker_updateChangedBusiness.sql b/db/routines/vn/procedures/worker_updateChangedBusiness.sql new file mode 100644 index 000000000..05e68b099 --- /dev/null +++ b/db/routines/vn/procedures/worker_updateChangedBusiness.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateChangedBusiness`() +BEGIN +/** + * Actualiza el contrato actual de todos los trabajadores cuyo contracto ha + * empezado/vencido. + */ + DECLARE vBusinessUpdated DATE; + DECLARE vCurdate DATE DEFAULT util.VN_CURDATE(); + DECLARE vWorkerFk INT; + DECLARE vDone BOOL; + + DECLARE vCursor CURSOR FOR + SELECT DISTINCT b.workerFk + FROM business b + WHERE b.started > vBusinessUpdated AND b.started <= vCurdate + OR b.ended >= vBusinessUpdated AND b.ended < vCurdate; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SELECT businessUpdated INTO vBusinessUpdated + FROM workerConfig; + + OPEN vCursor; + + l: LOOP + SET vDone = FALSE; + + FETCH vCursor INTO vWorkerFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL worker_updateBusiness(vWorkerFk); + END LOOP; + + UPDATE workerConfig SET businessUpdated = vCurdate; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workingHours.sql b/db/routines/vn/procedures/workingHours.sql new file mode 100644 index 000000000..c08226db7 --- /dev/null +++ b/db/routines/vn/procedures/workingHours.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workingHours`(username varchar(255), logon boolean) +BEGIN + DECLARE userid int(11); + + SELECT vn.getUserId(username) INTO userid; + SELECT username, userid; + IF userid IS NOT NULL THEN + IF (logon) THEN + CALL vn.workingHoursTimeIn(userid); + ELSE + CALL vn.workingHoursTimeOut(userid); + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workingHoursTimeIn.sql b/db/routines/vn/procedures/workingHoursTimeIn.sql new file mode 100644 index 000000000..8a4268c54 --- /dev/null +++ b/db/routines/vn/procedures/workingHoursTimeIn.sql @@ -0,0 +1,7 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workingHoursTimeIn`(vUserId INT(11)) +BEGIN + INSERT INTO vn.workingHours (timeIn, userId) + VALUES (util.VN_NOW(),vUserId); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/workingHoursTimeOut.sql b/db/routines/vn/procedures/workingHoursTimeOut.sql new file mode 100644 index 000000000..f6ce2886c --- /dev/null +++ b/db/routines/vn/procedures/workingHoursTimeOut.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workingHoursTimeOut`(vUserId INT(11)) +BEGIN + UPDATE vn.workingHours + SET timeOut = util.VN_NOW() + WHERE userId = vUserId + AND DATE(timeIn) = util.VN_CURDATE(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/wrongEqualizatedClient.sql b/db/routines/vn/procedures/wrongEqualizatedClient.sql new file mode 100644 index 000000000..47a6a608d --- /dev/null +++ b/db/routines/vn/procedures/wrongEqualizatedClient.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`wrongEqualizatedClient`() +BEGIN + SELECT clientFk, c.name, c.isActive, c.isTaxDataChecked, count(ie) as num + FROM vn.client c + JOIN + ( + SELECT DISTINCT + `a`.`clientFk` , + a.isEqualizated = 0 as ie + + FROM + `vn`.`address` `a` + ) sub ON sub.clientFk = c.id + WHERE c.hasToInvoiceByAddress = FALSE + + GROUP BY clientFk + HAVING num > 1 + UNION ALL + SELECT DISTINCT c.id, c.name, c.isActive, c.isTaxDataChecked,1 + FROM + `vn`.`address` `a` + JOIN `vn`.`client` `c` ON `c`.`id` = `a`.`clientFk` + WHERE ABS(a.isEqualizated) <> ABS(c.isEqualizated) + AND c.hasToInvoiceByAddress = FALSE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneClosure_recalc.sql b/db/routines/vn/procedures/zoneClosure_recalc.sql new file mode 100644 index 000000000..9e51c007d --- /dev/null +++ b/db/routines/vn/procedures/zoneClosure_recalc.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneClosure_recalc`() +proc: BEGIN +/** + * Recalculates the delivery time (hour) for every zone in days + scope in future + */ + DECLARE vScope INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vShipped DATE DEFAULT util.VN_CURDATE(); + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.zoneClosure_recalc'); + RESIGNAL; + END; + + IF NOT GET_LOCK('vn.zoneClosure_recalc', 0) THEN + LEAVE proc; + END IF; + + SELECT scope INTO vScope + FROM zoneConfig; + + DROP TEMPORARY TABLE IF EXISTS tmp.zone; + CREATE TEMPORARY TABLE tmp.zone + (INDEX (id)) + ENGINE = MEMORY + SELECT id FROM zone; + + TRUNCATE TABLE zoneClosure; + + WHILE vCounter <= vScope DO + + CALL zone_getOptionsForShipment(vShipped, TRUE); + + REPLACE zoneClosure(zoneFk, dated, `hour`) + SELECT zoneFk, vShipped, `hour` + FROM tmp.zoneOption; + + SET vCounter = vCounter + 1; + SET vShipped = TIMESTAMPADD(DAY, 1, vShipped); + END WHILE; + + -- DROP TEMPORARY TABLE tmp.zone; + DO RELEASE_LOCK('vn.zoneClosure_recalc'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_calcTree.sql b/db/routines/vn/procedures/zoneGeo_calcTree.sql new file mode 100644 index 000000000..34e1d8241 --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_calcTree.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_calcTree`() +BEGIN +/** + * Calculates the #path, #lft, #rgt, #sons and #depth columns of + * the #zoneGeo table. To build the tree, it uses the #parentFk + * column. + */ + DECLARE vIndex INT DEFAULT 0; + DECLARE vSons INT; + + DROP TEMPORARY TABLE IF EXISTS tNestedTree; + CREATE TEMPORARY TABLE tNestedTree + SELECT id, path, lft, rgt, depth, sons + FROM zoneGeo LIMIT 0; + + SET max_sp_recursion_depth = 5; + CALL zoneGeo_calcTreeRec(NULL, '/', 0, vIndex, vSons); + SET max_sp_recursion_depth = 0; + + UPDATE zoneGeo z + JOIN tNestedTree t ON t.id = z.id + SET z.path = t.path, + z.lft = t.lft, + z.rgt = t.rgt, + z.depth = t.depth, + z.sons = t.sons; + + DROP TEMPORARY TABLE tNestedTree; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_calcTreeRec.sql b/db/routines/vn/procedures/zoneGeo_calcTreeRec.sql new file mode 100644 index 000000000..da499ede3 --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_calcTreeRec.sql @@ -0,0 +1,69 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_calcTreeRec`( + vSelf INT, + vPath VARCHAR(255), + vDepth INT, + INOUT vIndex INT, + OUT vSons INT +) +BEGIN +/** + * Calculates and sets the #path, #lft, #rgt, #sons and #depth + * columns for all children of the passed node. Once calculated + * the last node rgt index and the number of sons are returned. + * To update it's children, this procedure calls itself recursively + * for each one. + * + * @vSelf The node identifier + * @vPath The initial path + * @vDepth The initial depth + * @vIndex The initial lft index + * @vSons The number of direct sons + */ + DECLARE vChildFk INT; + DECLARE vLft INT; + DECLARE vMySons INT; + DECLARE vDone BOOL; + DECLARE vChildren CURSOR FOR + SELECT id FROM zoneGeo + WHERE (vSelf IS NULL AND parentFk IS NULL) + OR (vSelf IS NOT NULL AND parentFk = vSelf); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SET vSons = 0; + + OPEN vChildren; + myLoop: LOOP + SET vDone = FALSE; + FETCH vChildren INTO vChildFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vIndex = vIndex + 1; + SET vLft = vIndex; + SET vSons = vSons + 1; + + CALL zoneGeo_calcTreeRec( + vChildFk, + CONCAT(vPath, vChildFk, '/'), + vDepth + 1, + vIndex, + vMySons + ); + + SET vIndex = vIndex + 1; + + INSERT INTO tNestedTree + SET id = vChildFk, + path = vPath, + lft = vLft, + rgt = vIndex, + depth = vDepth, + sons = vMySons; + END LOOP; + CLOSE vChildren; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_checkName.sql b/db/routines/vn/procedures/zoneGeo_checkName.sql new file mode 100644 index 000000000..5933f4be2 --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_checkName.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_checkName`(vName VARCHAR(255)) +BEGIN + IF vName = '' THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Column `name` cannot be empty'; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_delete.sql b/db/routines/vn/procedures/zoneGeo_delete.sql new file mode 100644 index 000000000..5bf0c5120 --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_delete.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_delete`(vSelf INT) +BEGIN +/** + * Deletes a node from the #zoneGeo table. Also sets a mark + * to force the tree recalculation. + * + * @vSelf The node identifier + */ + DELETE FROM zoneGeo WHERE id = vSelf; + UPDATE zoneGeoRecalc SET isChanged = TRUE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_doCalc.sql b/db/routines/vn/procedures/zoneGeo_doCalc.sql new file mode 100644 index 000000000..ce32357ec --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_doCalc.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_doCalc`() +proc: BEGIN +/** + * Recalculates the zones tree. + */ + DECLARE vIsChanged BOOL; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.zoneGeo_doCalc'); + RESIGNAL; + END; + + IF !GET_LOCK('vn.zoneGeo_doCalc', 0) THEN + LEAVE proc; + END IF; + + SELECT isChanged INTO vIsChanged + FROM zoneGeoRecalc; + + IF vIsChanged THEN + UPDATE zoneGeoRecalc SET isChanged = FALSE; + CALL vn.zoneGeo_calcTree; + END IF; + + DO RELEASE_LOCK('vn.zoneGeo_doCalc'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_setParent.sql b/db/routines/vn/procedures/zoneGeo_setParent.sql new file mode 100644 index 000000000..3f8f051a2 --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_setParent.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_setParent`(vSelf INT, vParentFk INT) +BEGIN +/** + * Updates the parent of a node. Also sets a mark + * to force the tree recalculation. + * + * @vSelf The node identifier + * @vParentFk The new parent identifier + */ + UPDATE zoneGeo SET parentFk = vParentFk + WHERE id = vSelf; + + UPDATE zoneGeoRecalc SET isChanged = TRUE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zoneGeo_throwNotEditable.sql b/db/routines/vn/procedures/zoneGeo_throwNotEditable.sql new file mode 100644 index 000000000..0b5c8aecf --- /dev/null +++ b/db/routines/vn/procedures/zoneGeo_throwNotEditable.sql @@ -0,0 +1,7 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneGeo_throwNotEditable`() +BEGIN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Column `geoFk` cannot be modified'; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_excludeFromGeo.sql b/db/routines/vn/procedures/zone_excludeFromGeo.sql new file mode 100644 index 000000000..6f0556bd7 --- /dev/null +++ b/db/routines/vn/procedures/zone_excludeFromGeo.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_excludeFromGeo`(vZoneGeo INT) +BEGIN +/** + * Excluye zonas a partir un geoFk. + * + * @table tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, landed, shipped) The computed options + * @param vZoneGeo The zone geo + * @return tmp.zoneOption The computed options + */ + DELETE t + FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vZoneGeo + WHERE zg2.`path` LIKE CONCAT(zg1.`path`, zg1.id,'/%') + OR zg2.id = zg1.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getAddresses.sql b/db/routines/vn/procedures/zone_getAddresses.sql new file mode 100644 index 000000000..1412c7ab3 --- /dev/null +++ b/db/routines/vn/procedures/zone_getAddresses.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( + vSelf INT, + vLanded DATE +) +BEGIN +/** + * Devuelve un listado de todos los clientes activos + * con consignatarios a los que se les puede + * vender producto para esa zona y no tiene un ticket + * para ese día. + * + * @param vSelf Id de zona + * @param vDated Fecha de entrega + * @return Un select + */ + CALL zone_getPostalCode(vSelf); + + WITH notHasTicket AS ( + SELECT id + FROM vn.client + WHERE id NOT IN ( + SELECT clientFk + FROM vn.ticket + WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded) + ) + ) + SELECT c.id clientFk, + c.name, + c.phone, + c.mobile, + c.salesPersonFk, + u.name username, + aai.invoiced, + cnb.lastShipped + FROM vn.client c + JOIN notHasTicket ON notHasTicket.id = c.id + LEFT JOIN account.`user` u ON u.id = c.salesPersonFk + JOIN vn.`address` a ON a.clientFk = c.id + JOIN vn.postCode pc ON pc.code = a.postalCode + JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk + JOIN vn.zoneGeo zg ON zg.name = a.postalCode + JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk + LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id + LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id + JOIN vn.clientType ct ON ct.code = c.typeFk + WHERE a.isActive + AND c.isActive + AND ct.code = 'normal' + AND c.businessTypeFk <> 'worker' + GROUP BY c.id; + + DROP TEMPORARY TABLE tmp.zoneNodes; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getAgency.sql b/db/routines/vn/procedures/zone_getAgency.sql new file mode 100644 index 000000000..8b66b110b --- /dev/null +++ b/db/routines/vn/procedures/zone_getAgency.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAgency`(vAddress INT, vLanded DATE) +BEGIN +/** + * Devuelve el listado de agencias disponibles para la fecha + * y dirección pasadas. + * + * @param vAddress Id de dirección de envío, %NULL si es recogida + * @param vLanded Fecha de recogida + * @return tmp.zoneGetAgency Listado de agencias disponibles + */ + CALL zone_getFromGeo(address_getGeo(vAddress)); + CALL zone_getOptionsForLanding(vLanded, FALSE); + CALL vn.zone_excludeFromGeo(address_getGeo(vAddress)); + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetAgency; + CREATE TEMPORARY TABLE tmp.zoneGetAgency + (INDEX (agencyModeFk)) ENGINE = MEMORY + SELECT am.name agencyMode, + am.description, + z.agencyModeFk, + am.deliveryMethodFk, + TIMESTAMPADD(DAY,-zo.travelingDays, vLanded) shipped, + TRUE isIncluded, + zo.zoneFk, + am.web AS isVisible + FROM tmp.zoneOption zo + JOIN zone z ON z.id = zo.zoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + GROUP BY agencyModeFk; + + DROP TEMPORARY TABLE + tmp.zone, + tmp.zoneOption; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getAvailable.sql b/db/routines/vn/procedures/zone_getAvailable.sql new file mode 100644 index 000000000..4fd3d1b34 --- /dev/null +++ b/db/routines/vn/procedures/zone_getAvailable.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAvailable`(vAddress INT, vLanded DATE) +BEGIN + CALL zone_getFromGeo(address_getGeo(vAddress)); + CALL zone_getOptionsForLanding(vLanded, FALSE); + + SELECT * FROM tmp.zoneOption; + + DROP TEMPORARY TABLE + tmp.zone, + tmp.zoneOption; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getClosed.sql b/db/routines/vn/procedures/zone_getClosed.sql new file mode 100644 index 000000000..f48e6ff44 --- /dev/null +++ b/db/routines/vn/procedures/zone_getClosed.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getClosed`() +proc:BEGIN +/** + * Devuelve una tabla con las zonas cerradas para hoy + * + * @table tmp.closedZones(zoneFk, warehouseFk); + */ + DROP TEMPORARY TABLE IF EXISTS tmp.closedZones; + + CREATE TEMPORARY TABLE tmp.closedZones ( + `zoneFk` int(11) NOT NULL, + `warehouseFk` smallint(6) unsigned NOT NULL, + PRIMARY KEY `zoneFk` (`zoneFk`,`warehouseFk`), + KEY `warehouseFk` (`warehouseFk`)) + ENGINE=MEMORY DEFAULT CHARSET=utf8; + + INSERT INTO tmp.closedZones(zoneFk, warehouseFk) + SELECT zoneFk, warehouseFk + FROM ( + SELECT t.zoneFk, t.warehouseFk, count(DISTINCT t.id) numTickets, pc.minTicketsToCloseZone + FROM vn.ticket t + JOIN vn.expedition e ON e.ticketFk = t.id + JOIN vn.`zone`z on z.id = t.zoneFk + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.productionConfig pc + WHERE a.isOwn + AND pc.isZoneClosedByExpeditionActivated + AND e.created >= util.VN_CURDATE() + GROUP BY t.zoneFk, t.warehouseFk + HAVING numTickets >= minTicketsToCloseZone) sub; + END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getCollisions.sql b/db/routines/vn/procedures/zone_getCollisions.sql new file mode 100644 index 000000000..f6779e1b7 --- /dev/null +++ b/db/routines/vn/procedures/zone_getCollisions.sql @@ -0,0 +1,125 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getCollisions`() +BEGIN +/** + * Calcula si para un mismo codigo postal y dia + * hay mas de una zona configurada y manda correo + * + */ + DECLARE vGeoFk INT DEFAULT NULL; + DECLARE vZoneFk INT; + DECLARE vIsDone INT DEFAULT FALSE; + DECLARE vTableCollisions TEXT; + DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.zone; + CREATE TEMPORARY TABLE tmp.zone + SELECT z.id + FROM zone z + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.code IN ('AGENCY','DELIVERY'); + + CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes; + CREATE TEMPORARY TABLE tmp.zoneNodes ( + geoFk INT, + name VARCHAR(100), + parentFk INT, + sons INT, + isChecked BOOL DEFAULT 0, + zoneFk INT, + PRIMARY KEY zoneFkk (zoneFk, geoFk), + INDEX(geoFk)) + ENGINE = MyISAM; + + OPEN cur1; + cur1Loop: LOOP + SET vIsDone = FALSE; + FETCH cur1 INTO vZoneFk; + IF vIsDone THEN + LEAVE cur1Loop; + END IF; + + CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE); + + myLoop: LOOP + SET vGeoFk = NULL; + SELECT geoFk INTO vGeoFk + FROM tmp.zoneNodes zn + WHERE NOT isChecked + LIMIT 1; + + IF vGeoFk IS NULL THEN + LEAVE myLoop; + END IF; + + CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE); + UPDATE tmp.zoneNodes + SET isChecked = TRUE + WHERE geoFk = vGeoFk; + END LOOP; + + END LOOP; + CLOSE cur1; + DELETE FROM tmp.zoneNodes + WHERE sons > 0; + + DROP TEMPORARY TABLE IF EXISTS geoCollision; + CREATE TEMPORARY TABLE geoCollision + SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk + FROM tmp.zoneNodes zn + JOIN zone z ON z.id = zn.zoneFk + JOIN zoneWarehouse zw ON z.id = zw.zoneFk + GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk + HAVING count(*) > 1; + + SELECT ' + + + + + + + + ' INTO vTableCollisions; + + INSERT INTO mail (receiver,replyTo,subject,body) + SELECT 'pepe@verdnatura.es' receiver, + 'noreply@verdnatura.es' replyTo, + CONCAT('Colisiones en zonas ', util.VN_CURDATE()) subject, + CONCAT(vTableCollisions, + GROUP_CONCAT(sub.td SEPARATOR ''), + '
C.PostalNúmero de zonaPrecioZonaAlmacénSalix
') body + FROM(SELECT + CONCAT(' + ', zn.name, ' + ', zoneFk,' + ', z.price,' + ', z.name,' + ', w.name, ' + ', CONCAT('' + 'https://salix.verdnatura.es/#!/zone/', + zoneFk, + '/location?q=%7B%22search%22:%22', + zn.name, + '%22%7D'),' + ') td + FROM tmp.zoneNodes zn + JOIN zone z ON z.id = zn.zoneFk + JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk + JOIN warehouse w ON w.id = gc.warehouseFk) sub; + + DROP TEMPORARY TABLE + geoCollision, + tmp.zone, + tmp.zoneNodes; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getEvents.sql b/db/routines/vn/procedures/zone_getEvents.sql new file mode 100644 index 000000000..53e065083 --- /dev/null +++ b/db/routines/vn/procedures/zone_getEvents.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getEvents`( + vGeoFk INT, + vAgencyModeFk INT) +BEGIN +/** + * Returns available events for the passed province/postcode and agency. + * + * @param vGeoFk The geo id + * @param vAgencyModeFk The agency mode id + */ + DECLARE vDeliveryMethodFk VARCHAR(255); + + DROP TEMPORARY TABLE IF EXISTS tZone; + CREATE TEMPORARY TABLE tZone + (id INT PRIMARY KEY) + ENGINE = MEMORY; + + SELECT dm.`code` INTO vDeliveryMethodFk + FROM agencyMode am + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE am.id = vAgencyModeFk; + + IF vDeliveryMethodFk = 'PICKUP' THEN + INSERT INTO tZone + SELECT id + FROM zone + WHERE agencyModeFk = vAgencyModeFk; + ELSE + CALL zone_getFromGeo(vGeoFk); + + IF vAgencyModeFk IS NOT NULL THEN + INSERT INTO tZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + WHERE z.agencyModeFk = vAgencyModeFk; + ELSE + INSERT INTO tZone + SELECT t.id + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.`code` IN ('AGENCY', 'DELIVERY'); + END IF; + DROP TEMPORARY TABLE tmp.zone; + END IF; + + SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays + FROM tZone t + JOIN zoneEvent e ON e.zoneFk = t.id; + + SELECT e.zoneFk, e.dated + FROM tZone t + JOIN zoneExclusion e ON e.zoneFk = t.id + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + LEFT JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vGeoFk + WHERE eg.zoneExclusionFk IS NULL OR zg2.`path` LIKE CONCAT(zg1.`path`,'%'); + + DROP TEMPORARY TABLE tZone; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getFromGeo.sql b/db/routines/vn/procedures/zone_getFromGeo.sql new file mode 100644 index 000000000..fe6be86a7 --- /dev/null +++ b/db/routines/vn/procedures/zone_getFromGeo.sql @@ -0,0 +1,56 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getFromGeo`(vGeoFk INT) +BEGIN +/** + * Returns all zones which have the passed geo included. + * + * @param vGeoFk The geo id + * @return tmp.zone(id) The list of zones + */ + DECLARE vChildFk INT DEFAULT vGeoFk; + DECLARE vParentFk INT; + DECLARE vLevel INT DEFAULT 1; + + DROP TEMPORARY TABLE IF EXISTS tNodes; + CREATE TEMPORARY TABLE tNodes + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT vGeoFk id, vLevel `level`; + + myLoop: LOOP + SELECT parentFk INTO vParentFk + FROM zoneGeo + WHERE id = vChildFk; + + SET vChildFk = vParentFk; + SET vLevel = vLevel + 1; + + INSERT IGNORE INTO tNodes + SELECT vChildFk, vLevel + FROM DUAL + WHERE vChildFk IS NOT NULL; + + IF ROW_COUNT() = 0 THEN + LEAVE myLoop; + END IF; + END LOOP; + + DROP TEMPORARY TABLE IF EXISTS tmp.zone; + CREATE TEMPORARY TABLE tmp.zone + (INDEX (id)) + ENGINE = MEMORY + SELECT id FROM ( + SELECT zoneFk id, isIncluded + FROM ( + SELECT i.zoneFk, i.isIncluded + FROM tNodes n + JOIN zoneIncluded i ON i.geoFk = n.id + ORDER BY zoneFk, n.`level` + LIMIT 10000000000000000000 + ) t + GROUP BY id HAVING isIncluded + ) t; + + DROP TEMPORARY TABLE tNodes; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getLanded.sql b/db/routines/vn/procedures/zone_getLanded.sql new file mode 100644 index 000000000..b75f409b9 --- /dev/null +++ b/db/routines/vn/procedures/zone_getLanded.sql @@ -0,0 +1,47 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Devuelve una tabla temporal con el dia de recepcion para vShipped. + * Excluye las que tengan cajas preparadas + * + * @param vShipped Fecha de preparacion de mercancia + * @param vAddressFk Id de consignatario, %NULL para recogida + * @param vAgencyModeFk Id agencia + * @param vWarehouseFk vWarehouseFk + * @table tmp.zoneGetLanded Datos de recepción + */ + DECLARE vZoneGeo INT; + + SELECT address_getGeo(vAddressFk) INTO vZoneGeo; + + CALL vn.zone_getFromGeo(vZoneGeo); + CALL vn.zone_getOptionsForShipment(vShipped, vShowExpiredZones); + CALL vn.zone_excludeFromGeo(vZoneGeo); + CALL vn.zone_getClosed(); + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; + CREATE TEMPORARY TABLE tmp.zoneGetLanded + ENGINE = MEMORY + SELECT vWarehouseFk warehouseFk, + TIMESTAMPADD(DAY,zo.travelingDays, vShipped) landed, + zo.zoneFk + FROM tmp.zoneOption zo + JOIN vn.`zone` z ON z.id = zo.zoneFk + JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk + AND cz.zoneFk = zw.zoneFk + AND zo.shipped = util.VN_CURDATE() + WHERE z.agencyModeFk = vAgencyModeFk + AND zw.warehouseFk = vWarehouseFk + AND (ISNULL(cz.zoneFk) OR vShowExpiredZones) + ORDER BY z.price DESC, zo.zoneFk + LIMIT 1; + + DROP TEMPORARY TABLE + tmp.`zone`, + tmp.zoneOption, + tmp.closedZones; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getLeaves.sql b/db/routines/vn/procedures/zone_getLeaves.sql new file mode 100644 index 000000000..d1e66267e --- /dev/null +++ b/db/routines/vn/procedures/zone_getLeaves.sql @@ -0,0 +1,123 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getLeaves`( + vSelf INT, + vParentFk INT, + vSearch VARCHAR(255), + vHasInsert BOOL +) +BEGIN +/** + * Devuelve las ubicaciones incluidas en la ruta y que sean hijos de parentFk. + * @param vSelf Id de la zona + * @param vParentFk Id del geo a calcular + * @param vSearch Cadena a buscar + * @param vHasInsert Indica si inserta en tmp.zoneNodes + * Optional @table tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + */ + DECLARE vIsNumber BOOL; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; + + CREATE OR REPLACE TEMPORARY TABLE tNodes + (UNIQUE (id)) + ENGINE = MEMORY + SELECT id + FROM zoneGeo + LIMIT 0; + + IF vIsSearch THEN + SET vIsNumber = vSearch REGEXP '^[0-9]+$'; + + INSERT INTO tNodes + SELECT id + FROM zoneGeo + WHERE (vIsNumber AND `name` = vSearch) + OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) + LIMIT 1000; + + ELSEIF vParentFk IS NULL THEN + INSERT INTO tNodes + SELECT geoFk + FROM zoneIncluded + WHERE zoneFk = vSelf; + END IF; + + IF vParentFk IS NULL THEN + CREATE OR REPLACE TEMPORARY TABLE tChilds + (INDEX(id)) + ENGINE = MEMORY + SELECT id FROM tNodes; + + CREATE OR REPLACE TEMPORARY TABLE tParents + (INDEX(id)) + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + myLoop: LOOP + DELETE FROM tParents; + INSERT INTO tParents + SELECT parentFk id + FROM zoneGeo g + JOIN tChilds c ON c.id = g.id + WHERE g.parentFk IS NOT NULL; + + INSERT IGNORE INTO tNodes + SELECT id FROM tParents; + + IF NOT ROW_COUNT() THEN + LEAVE myLoop; + END IF; + + DELETE FROM tChilds; + INSERT INTO tChilds + SELECT id FROM tParents; + END LOOP; + + DROP TEMPORARY TABLE tChilds, tParents; + END IF; + + IF NOT vIsSearch THEN + INSERT IGNORE INTO tNodes + SELECT id + FROM zoneGeo + WHERE parentFk <=> vParentFk; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tZones + SELECT g.id, + g.name, + g.parentFk, + g.sons, + NOT g.sons OR `type` = 'country' isChecked, + i.isIncluded selected, + g.`depth`, + vSelf + FROM zoneGeo g + JOIN tNodes n ON n.id = g.id + LEFT JOIN zoneIncluded i ON i.geoFk = g.id + AND i.zoneFk = vSelf + ORDER BY g.`depth`, selected DESC, g.name; + + IF vHasInsert THEN + INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + SELECT id, + name, + parentFk, + sons, + isChecked, + vSelf + FROM tZones + WHERE selected + OR (selected IS NULL AND vParentFk IS NOT NULL); + ELSE + SELECT id, + name, + parentFk, + sons, + selected + FROM tZones + ORDER BY `depth`, selected DESC, name; + END IF; + + DROP TEMPORARY TABLE tNodes, tZones; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getOptionsForLanding.sql b/db/routines/vn/procedures/zone_getOptionsForLanding.sql new file mode 100644 index 000000000..1c12e8c88 --- /dev/null +++ b/db/routines/vn/procedures/zone_getOptionsForLanding.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getOptionsForLanding`(vLanded DATE, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Gets computed options for the passed zones and delivery date. + * + * @table tmp.zone(id) The zones ids + * @param vLanded The delivery date + * @return tmp.zoneOption The computed options + */ + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + CREATE TEMPORARY TABLE tmp.zoneOption + ENGINE = MEMORY + SELECT + zoneFk, + `hour`, + travelingDays, + price, + bonus, + vLanded landed, + TIMESTAMPADD(DAY, -travelingDays, vLanded) shipped + FROM ( + SELECT t.id zoneFk, + TIME(IFNULL(e.`hour`, z.`hour`)) `hour`, + IFNULL(e.travelingDays, z.travelingDays) travelingDays, + IFNULL(e.price, z.price) price, + IFNULL(e.bonus, z.bonus) bonus + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN zoneEvent e ON e.zoneFk = t.id + WHERE ( + e.`type` = 'day' + AND e.dated = vLanded + ) OR ( + e.`type` != 'day' + AND e.weekDays & (1 << WEEKDAY(vLanded)) + AND (e.`started` IS NULL OR vLanded >= e.`started`) + AND (e.`ended` IS NULL OR vLanded <= e.`ended`) + ) + ORDER BY + zoneFk, + CASE + WHEN e.`type` = 'day' + THEN 1 + WHEN e.`type` = 'range' + THEN 2 + ELSE 3 + END + LIMIT 10000000000000000000 + ) t + GROUP BY zoneFk; + + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + + IF NOT vShowExpiredZones THEN + DELETE FROM tmp.zoneOption + WHERE shipped < util.VN_CURDATE() + OR (shipped = util.VN_CURDATE() AND util.VN_CURTIME() > `hour`); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getOptionsForShipment.sql b/db/routines/vn/procedures/zone_getOptionsForShipment.sql new file mode 100644 index 000000000..ec7824303 --- /dev/null +++ b/db/routines/vn/procedures/zone_getOptionsForShipment.sql @@ -0,0 +1,75 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getOptionsForShipment`(vShipped DATE, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Gets computed options for the passed zones and shipping date. + * + * @table tmp.zones(id) The zones ids + * @param vShipped The shipping date + * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options + */ + DECLARE vHour TIME DEFAULT TIME(util.VN_NOW()); + + DROP TEMPORARY TABLE IF EXISTS tLandings; + CREATE TEMPORARY TABLE tLandings + (INDEX (eventFk)) + ENGINE = MEMORY + SELECT e.id eventFk, + @travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays, + TIMESTAMPADD(DAY, @travelingDays, vShipped) landed + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN zoneEvent e ON e.zoneFk = t.id; + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + CREATE TEMPORARY TABLE tmp.zoneOption + ENGINE = MEMORY + SELECT * + FROM ( + SELECT t.id zoneFk, + TIME(IFNULL(e.`hour`, z.`hour`)) `hour`, + l.travelingDays, + IFNULL(e.price, z.price) price, + IFNULL(e.bonus, z.bonus) bonus, + l.landed, + vShipped shipped + FROM tmp.zone t + JOIN zone z ON z.id = t.id + JOIN zoneEvent e ON e.zoneFk = t.id + JOIN tLandings l ON l.eventFk = e.id + WHERE ( + e.`type` = 'day' + AND e.`dated` = l.landed + ) OR ( + e.`type` != 'day' + AND e.weekDays & (1 << WEEKDAY(l.landed)) + AND (e.`started` IS NULL OR l.landed >= e.`started`) + AND (e.`ended` IS NULL OR l.landed <= e.`ended`) + ) + ORDER BY + zoneFk, + CASE + WHEN e.`type` = 'day' + THEN 1 + WHEN e.`type` = 'range' + THEN 2 + ELSE 3 + END + LIMIT 10000000000000000000 + ) t + GROUP BY zoneFk; + + DROP TEMPORARY TABLE tLandings; + + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + + IF NOT vShowExpiredZones THEN + DELETE FROM tmp.zoneOption + WHERE vShipped < util.VN_CURDATE() + OR (vShipped = util.VN_CURDATE() AND util.VN_CURTIME() > `hour`); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getPostalCode.sql b/db/routines/vn/procedures/zone_getPostalCode.sql new file mode 100644 index 000000000..920ad3171 --- /dev/null +++ b/db/routines/vn/procedures/zone_getPostalCode.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getPostalCode`(vSelf INT) +BEGIN +/** + * Devuelve los códigos postales incluidos en una zona + */ + DECLARE vGeoFk INT DEFAULT NULL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.zoneNodes ( + geoFk INT, + name VARCHAR(100), + parentFk INT, + sons INT, + isChecked BOOL DEFAULT 0, + zoneFk INT, + PRIMARY KEY zoneNodesPk (zoneFk, geoFk), + INDEX(geoFk)) + ENGINE = MEMORY; + + CALL zone_getLeaves(vSelf, NULL , NULL, TRUE); + + UPDATE tmp.zoneNodes + SET isChecked = 0 + WHERE parentFk IS NULL; + + myLoop: LOOP + SET vGeoFk = NULL; + SELECT geoFk INTO vGeoFk + FROM tmp.zoneNodes + WHERE NOT isChecked + LIMIT 1; + + CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE); + UPDATE tmp.zoneNodes + SET isChecked = TRUE + WHERE geoFk = vGeoFk; + + IF vGeoFk IS NULL THEN + LEAVE myLoop; + END IF; + END LOOP; + + DELETE FROM tmp.zoneNodes + WHERE sons > 0; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getShipped.sql b/db/routines/vn/procedures/zone_getShipped.sql new file mode 100644 index 000000000..8d28c9062 --- /dev/null +++ b/db/routines/vn/procedures/zone_getShipped.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getShipped`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vShowExpiredZones BOOLEAN) +BEGIN +/** + * Devuelve la mínima fecha de envío para cada warehouse + * Excluye aquellas zonas que ya tienen cajas preparadas en ese almacén + * + * @param vLanded La fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id de la agencia + * @return tmp.zoneGetShipped + */ + DECLARE vZoneGeo INT; + + SELECT address_getGeo(vAddressFk) INTO vZoneGeo; + + CALL vn.zone_getFromGeo(vZoneGeo); + CALL vn.zone_getOptionsForLanding(vLanded, vShowExpiredZones); + CALL vn.zone_excludeFromGeo(vZoneGeo); + CALL vn.zone_getClosed(); + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; + CREATE TEMPORARY TABLE tmp.zoneGetShipped + ENGINE = MEMORY + SELECT * FROM ( + SELECT zo.zoneFk, + zo.shipped, + zo.`hour`, + zw.warehouseFk, + z.agencyModeFk, + zo.price, + zo.bonus + FROM tmp.zoneOption zo + JOIN vn.zoneWarehouse zw ON zw.zoneFk = zo.zoneFk + JOIN vn.`zone` z ON z.id = zo.zoneFk + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk + AND cz.zoneFk = zw.zoneFk + AND zo.shipped = util.VN_CURDATE() + WHERE z.agencyModeFk = vAgencyModeFk + AND (ISNULL(cz.zoneFk) OR vShowExpiredZones) + ORDER BY shipped + LIMIT 10000000000000000000) t + GROUP BY warehouseFk; + + DROP TEMPORARY TABLE + tmp.`zone`, + tmp.zoneOption, + tmp.closedZones; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getState.sql b/db/routines/vn/procedures/zone_getState.sql new file mode 100644 index 000000000..aa61d08a2 --- /dev/null +++ b/db/routines/vn/procedures/zone_getState.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getState`(vDated DATE) +BEGIN +/** + * Devuelve las zonas y el estado para la fecha solicitada + * + * @param vDated Fecha en cuestión + */ + DROP TEMPORARY TABLE IF EXISTS tmp.zone; + + CREATE TEMPORARY TABLE tmp.zone ( + id INT PRIMARY KEY) + ENGINE=MEMORY; + + INSERT INTO tmp.zone(id) + SELECT id + FROM vn.zone; + + CALL vn.zone_getOptionsForShipment(vDated, TRUE); + + CALL vn.zone_getClosed(); + + SELECT zo.zoneFk, + zo.`hour`etd, + (zo.`hour` <= TIME(util.VN_NOW())) isLate, + !ISNULL(cz.zoneFk) isFull, + zw.warehouseFk, + zo.landed + FROM tmp.zoneOption zo + JOIN vn.zone z ON z.id = zo.zoneFk + JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk + AND cz.zoneFk = zo.zoneFk; + + DROP TEMPORARY TABLE + tmp.closedZones, + tmp.zoneOption, + tmp.zone; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getWarehouse.sql b/db/routines/vn/procedures/zone_getWarehouse.sql new file mode 100644 index 000000000..b6915a302 --- /dev/null +++ b/db/routines/vn/procedures/zone_getWarehouse.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) +BEGIN +/** + * Devuelve el listado de agencias disponibles para la fecha, + * dirección y almacén pasados. + * + * @param vAddress + * @param vWarehouse warehouse + * @param vLanded Fecha de recogida + * @select Listado de agencias disponibles + */ + + CALL zone_getFromGeo(address_getGeo(vAddress)); + CALL zone_getOptionsForLanding(vLanded, FALSE); + + SELECT am.id agencyModeFk, + am.name agencyMode, + am.description, + am.deliveryMethodFk, + TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, + zw.warehouseFk, + z.id zoneFk + FROM tmp.zoneOption zo + JOIN zone z ON z.id = zo.zoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk + WHERE zw.warehouseFk = vWarehouse + GROUP BY z.agencyModeFk + ORDER BY agencyMode; + + DROP TEMPORARY TABLE + tmp.zone, + tmp.zoneOption; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/zone_upcomingDeliveries.sql b/db/routines/vn/procedures/zone_upcomingDeliveries.sql new file mode 100644 index 000000000..3d83b51cf --- /dev/null +++ b/db/routines/vn/procedures/zone_upcomingDeliveries.sql @@ -0,0 +1,77 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_upcomingDeliveries`() +BEGIN + + DECLARE vForwardDays INT; + + SELECT forwardDays INTO vForwardDays FROM zoneConfig; + CALL util.time_createTable(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); + + DROP TEMPORARY TABLE IF EXISTS tLandings; + CREATE TEMPORARY TABLE tLandings + (INDEX (eventFk)) + ENGINE = MEMORY + SELECT e.id eventFk, + @travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays, + TIMESTAMPADD(DAY, @travelingDays, ti.dated) landed, + ti.dated shipped + FROM zone z + JOIN zoneEvent e ON e.zoneFk = z.id + JOIN tmp.time ti ON ti.dated BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY, vForwardDays, util.VN_CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + CREATE TEMPORARY TABLE tmp.zoneOption + ENGINE = MEMORY + SELECT * + FROM ( + SELECT z.id zoneFk, + TIME(IFNULL(e.`hour`, z.`hour`)) `hour`, + l.travelingDays, + IFNULL(e.price, z.price) price, + IFNULL(e.bonus, z.bonus) bonus, + l.landed, + l.shipped + FROM zone z + JOIN zoneEvent e ON e.zoneFk = z.id + JOIN tLandings l ON l.eventFk = e.id + WHERE ( + e.`type` = 'day' + AND e.`dated` = l.landed + ) OR ( + e.`type` != 'day' + AND e.weekDays & (1 << WEEKDAY(l.landed)) + AND (e.`started` IS NULL OR l.landed >= e.`started`) + AND (e.`ended` IS NULL OR l.landed <= e.`ended`) + ) + ORDER BY + zoneFk, + CASE + WHEN e.`type` = 'day' + THEN 1 + WHEN e.`type` = 'range' + THEN 2 + ELSE 3 + END + LIMIT 10000000000000000000 + ) t + GROUP BY zoneFk, landed; + + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + + SELECT MAX(zo.`hour`) `hour`, zg.`name`, zo.shipped, zo.zoneFk + FROM tmp.zoneOption zo + JOIN `zone` z ON z.id = zo.zoneFk + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN zoneIncluded zi ON zi.zoneFk = z.id + JOIN zoneGeo zg ON zg.id = zi.geoFk AND zg.type = 'province' + WHERE dm.code = 'DELIVERY' + GROUP BY shipped, zg.`name` + ORDER BY shipped, zg.`name`; + + DROP TEMPORARY TABLE tmp.time, tLandings; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/BEFORE_INSERT.sql b/db/routines/vn/triggers/BEFORE_INSERT.sql new file mode 100644 index 000000000..c0fcf4e3e --- /dev/null +++ b/db/routines/vn/triggers/BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`BEFORE_INSERT` + BEFORE INSERT ON `saleBuy` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + + END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/XDiario_beforeInsert.sql b/db/routines/vn/triggers/XDiario_beforeInsert.sql new file mode 100644 index 000000000..bc89e221f --- /dev/null +++ b/db/routines/vn/triggers/XDiario_beforeInsert.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`XDiario_beforeInsert` + BEFORE INSERT ON `XDiario` + FOR EACH ROW +BEGIN + IF NEW.SUBCTA <=> '' THEN + SET NEW.SUBCTA = NULL; + END IF; + IF NEW.SUBCTA IS NOT NULL AND NOT LENGTH(NEW.SUBCTA) <=> 10 THEN + CALL util.throw('INVALID_STRING_LENGTH'); + END IF; + IF NEW.CONTRA <=> '' THEN + SET NEW.CONTRA = NULL; + END IF; + IF NEW.CONTRA IS NOT NULL AND NOT LENGTH(NEW.CONTRA) <=> 10 THEN + CALL util.throw('INVALID_STRING_LENGTH'); + END IF; + CALL XDiario_checkDate(NEW.FECHA); + CALL XDiario_checkDate(NEW.FECHA_EX); + CALL XDiario_checkDate(NEW.FECHA_OP); + CALL XDiario_checkDate(NEW.FECHA_RT); + CALL XDiario_checkDate(NEW.FECREGCON); +END$$ +DELIMITER ; diff --git a/db/.archive/230201/00-triggersXDiario.sql b/db/routines/vn/triggers/XDiario_beforeUpdate.sql similarity index 54% rename from db/.archive/230201/00-triggersXDiario.sql rename to db/routines/vn/triggers/XDiario_beforeUpdate.sql index 5cf0b6253..33787c8f1 100644 --- a/db/.archive/230201/00-triggersXDiario.sql +++ b/db/routines/vn/triggers/XDiario_beforeUpdate.sql @@ -1,9 +1,5 @@ -DROP TRIGGER IF EXISTS vn.XDiario_beforeUpdate; -USE vn; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`XDiario_beforeUpdate` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`XDiario_beforeUpdate` BEFORE UPDATE ON `XDiario` FOR EACH ROW BEGIN @@ -40,34 +36,3 @@ BEGIN END IF; END$$ DELIMITER ; - - -DROP TRIGGER IF EXISTS vn.XDiario_beforeInsert; -USE vn; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`XDiario_beforeInsert` - BEFORE INSERT ON `XDiario` - FOR EACH ROW -BEGIN - IF NEW.SUBCTA <=> '' THEN - SET NEW.SUBCTA = NULL; - END IF; - IF NEW.SUBCTA IS NOT NULL AND NOT LENGTH(NEW.SUBCTA) <=> 10 THEN - CALL util.throw('INVALID_STRING_LENGTH'); - END IF; - IF NEW.CONTRA <=> '' THEN - SET NEW.CONTRA = NULL; - END IF; - IF NEW.CONTRA IS NOT NULL AND NOT LENGTH(NEW.CONTRA) <=> 10 THEN - CALL util.throw('INVALID_STRING_LENGTH'); - END IF; - CALL XDiario_checkDate(NEW.FECHA); - CALL XDiario_checkDate(NEW.FECHA_EX); - CALL XDiario_checkDate(NEW.FECHA_OP); - CALL XDiario_checkDate(NEW.FECHA_RT); - CALL XDiario_checkDate(NEW.FECREGCON); -END$$ -DELIMITER ; - diff --git a/db/routines/vn/triggers/address_afterDelete.sql b/db/routines/vn/triggers/address_afterDelete.sql new file mode 100644 index 000000000..d4195d48d --- /dev/null +++ b/db/routines/vn/triggers/address_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`address_afterDelete` + AFTER DELETE ON `address` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Address', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/address_afterInsert.sql b/db/routines/vn/triggers/address_afterInsert.sql new file mode 100644 index 000000000..318fd3958 --- /dev/null +++ b/db/routines/vn/triggers/address_afterInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`address_afterInsert` + BEFORE INSERT ON `address` + FOR EACH ROW +BEGIN + IF (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/address_afterUpdate.sql b/db/routines/vn/triggers/address_afterUpdate.sql new file mode 100644 index 000000000..6160aa2a5 --- /dev/null +++ b/db/routines/vn/triggers/address_afterUpdate.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`address_afterUpdate` + AFTER UPDATE ON `address` + FOR EACH ROW +BEGIN + -- Recargos de equivalencia distintos implican facturacion por consignatario + IF NEW.isEqualizated != OLD.isEqualizated THEN + IF + (SELECT COUNT(*) FROM + ( + SELECT DISTINCT (isEqualizated = FALSE) as Equ + FROM address + WHERE clientFk = NEW.clientFk + ) t1 + ) > 1 + THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + END IF; + END IF; + IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN + CALL util.throw ('Cannot desactivate the default address'); + END IF; + + IF NOT (NEW.isEqualizated <=> OLD.isEqualizated) THEN + INSERT IGNORE INTO ticketRecalc (ticketFk) + SELECT id FROM ticket t + WHERE t.addressFk = NEW.id + AND t.refFk IS NULL; + END IF; + + IF (NEW.clientFk <> OLD.clientFk OR NEW.isActive <> OLD.isActive OR NOT (NEW.provinceFk <=> OLD.provinceFk)) + AND (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/address_beforeInsert.sql b/db/routines/vn/triggers/address_beforeInsert.sql new file mode 100644 index 000000000..2ef582499 --- /dev/null +++ b/db/routines/vn/triggers/address_beforeInsert.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`address_beforeInsert` + BEFORE INSERT ON `address` + FOR EACH ROW +BEGIN + DECLARE vIsEqualizated BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF (NEW.mobile <> '') THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + + IF NEW.isEqualizated IS NULL THEN + SELECT isEqualizated + INTO vIsEqualizated + FROM client + WHERE id = NEW.clientFk; + + SET NEW.isEqualizated = vIsEqualizated; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/address_beforeUpdate.sql b/db/routines/vn/triggers/address_beforeUpdate.sql new file mode 100644 index 000000000..8922105e7 --- /dev/null +++ b/db/routines/vn/triggers/address_beforeUpdate.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`address_beforeUpdate` + BEFORE UPDATE ON `address` + FOR EACH ROW +BEGIN + + SET NEW.editorFk = account.myUser_getId(); + + IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/agency_afterInsert.sql b/db/routines/vn/triggers/agency_afterInsert.sql new file mode 100644 index 000000000..35670538b --- /dev/null +++ b/db/routines/vn/triggers/agency_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`agency_afterInsert` + AFTER INSERT ON `agency` + FOR EACH ROW +BEGIN + INSERT INTO agencyMode(name,agencyFk) VALUES(NEW.name,NEW.id); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/autonomy_AD.sql b/db/routines/vn/triggers/autonomy_AD.sql new file mode 100644 index 000000000..f9e1ccf36 --- /dev/null +++ b/db/routines/vn/triggers/autonomy_AD.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_AD` + AFTER DELETE ON `autonomy` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/autonomy_BI.sql b/db/routines/vn/triggers/autonomy_BI.sql new file mode 100644 index 000000000..e5f9ca9ca --- /dev/null +++ b/db/routines/vn/triggers/autonomy_BI.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_BI` + BEFORE INSERT ON `autonomy` + FOR EACH ROW +BEGIN + + SET NEW.geoFk = zoneGeo_new('autonomy', NEW.`name`, (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/autonomy_BU.sql b/db/routines/vn/triggers/autonomy_BU.sql new file mode 100644 index 000000000..fd68cef58 --- /dev/null +++ b/db/routines/vn/triggers/autonomy_BU.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_BU` + BEFORE UPDATE ON `autonomy` + FOR EACH ROW +BEGIN + IF !(OLD.countryFk <=> NEW.countryFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/awb_bi.sql b/db/routines/vn/triggers/awb_bi.sql new file mode 100644 index 000000000..1cc0fc2f7 --- /dev/null +++ b/db/routines/vn/triggers/awb_bi.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`awb_bi` + BEFORE INSERT ON `awb` + FOR EACH ROW +BEGIN + + SET NEW.year= year(util.VN_CURDATE()); + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/bankEntity_beforeInsert.sql b/db/routines/vn/triggers/bankEntity_beforeInsert.sql new file mode 100644 index 000000000..6c1ce78a7 --- /dev/null +++ b/db/routines/vn/triggers/bankEntity_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`bankEntity_beforeInsert` + BEFORE INSERT ON `bankEntity` + FOR EACH ROW +BEGIN + CALL bankEntity_checkBic(NEW.bic); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/bankEntity_beforeUpdate.sql b/db/routines/vn/triggers/bankEntity_beforeUpdate.sql new file mode 100644 index 000000000..5bea154a2 --- /dev/null +++ b/db/routines/vn/triggers/bankEntity_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`bankEntity_beforeUpdate` + BEFORE UPDATE ON `bankEntity` + FOR EACH ROW +BEGIN + IF NOT (NEW.bic <=> OLD.bic) THEN + CALL bankEntity_checkBic(NEW.bic); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/budgetNotes_BeforeInsert.sql b/db/routines/vn/triggers/budgetNotes_BeforeInsert.sql new file mode 100644 index 000000000..f75b7a01e --- /dev/null +++ b/db/routines/vn/triggers/budgetNotes_BeforeInsert.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`budgetNotes_BeforeInsert` + BEFORE INSERT ON `budgetNotes` + FOR EACH ROW +BEGIN + + IF ISNULL(NEW.userFk) THEN + + SET NEW.userFk = account.myUser_getId(); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/business_afterDelete.sql b/db/routines/vn/triggers/business_afterDelete.sql new file mode 100644 index 000000000..9b897b4e9 --- /dev/null +++ b/db/routines/vn/triggers/business_afterDelete.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterDelete` + AFTER DELETE ON `business` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'Business', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL worker_updateBusiness(OLD.workerFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/business_afterInsert.sql b/db/routines/vn/triggers/business_afterInsert.sql new file mode 100644 index 000000000..2949eede8 --- /dev/null +++ b/db/routines/vn/triggers/business_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterInsert` + AFTER INSERT ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/business_afterUpdate.sql b/db/routines/vn/triggers/business_afterUpdate.sql new file mode 100644 index 000000000..95746a30d --- /dev/null +++ b/db/routines/vn/triggers/business_afterUpdate.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterUpdate` + AFTER UPDATE ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); + + IF NOT (OLD.workerFk <=> NEW.workerFk) THEN + CALL worker_updateBusiness(OLD.workerFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/business_beforeInsert.sql b/db/routines/vn/triggers/business_beforeInsert.sql new file mode 100644 index 000000000..1f136c1e8 --- /dev/null +++ b/db/routines/vn/triggers/business_beforeInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_beforeInsert` + BEFORE INSERT ON `business` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.ended IS NULL THEN + SET NEW.payedHolidays = 0; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/business_beforeUpdate.sql b/db/routines/vn/triggers/business_beforeUpdate.sql new file mode 100644 index 000000000..4b7a10041 --- /dev/null +++ b/db/routines/vn/triggers/business_beforeUpdate.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_beforeUpdate` + BEFORE UPDATE ON `business` + FOR EACH ROW +BEGIN + DECLARE isOverlapping BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.ended IS NULL THEN + SET NEW.payedHolidays = 0; + END IF; + + IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN + + SELECT COUNT(*) > 0 INTO isOverlapping + FROM business b + WHERE (util.hasDateOverlapped( + NEW.started, + IFNULL(NEW.ended, b.started), + b.started, + IFNULL(b.ended, NEW.started)) + OR (NEW.ended <=> NULL AND b.ended <=> NULL)) + AND b.id <> OLD.id + AND workerFk = OLD.workerFk; + + IF isOverlapping THEN + CALL util.throw ('IS_OVERLAPPING'); + END IF; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_afterDelete.sql b/db/routines/vn/triggers/buy_afterDelete.sql new file mode 100644 index 000000000..2fcb0852d --- /dev/null +++ b/db/routines/vn/triggers/buy_afterDelete.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_afterDelete` + AFTER DELETE ON `buy` + FOR EACH ROW +trig: BEGIN + DECLARE vValues VARCHAR(255); + + IF @isModeInventory OR @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL stock.log_add('buy', NULL, OLD.id); + + INSERT INTO entryLog + SET `action` = 'delete', + `changedModel` = 'Buy', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_afterInsert.sql b/db/routines/vn/triggers/buy_afterInsert.sql new file mode 100644 index 000000000..25682f1bb --- /dev/null +++ b/db/routines/vn/triggers/buy_afterInsert.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_afterInsert` + AFTER INSERT ON `buy` + FOR EACH ROW +trig: BEGIN + IF @isModeInventory OR @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL stock.log_add('buy', NEW.id, NULL); + + CALL buy_afterUpsert(NEW.id); +END$$ +DELIMITER ; diff --git a/db/changes/234201/02-packagingFktrigger.sql b/db/routines/vn/triggers/buy_afterUpdate.sql similarity index 99% rename from db/changes/234201/02-packagingFktrigger.sql rename to db/routines/vn/triggers/buy_afterUpdate.sql index 4edcd3f3e..9866f5bb8 100644 --- a/db/changes/234201/02-packagingFktrigger.sql +++ b/db/routines/vn/triggers/buy_afterUpdate.sql @@ -54,4 +54,4 @@ trig: BEGIN END IF; END IF; END$$ -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_beforeDelete.sql b/db/routines/vn/triggers/buy_beforeDelete.sql new file mode 100644 index 000000000..eb7c0ef70 --- /dev/null +++ b/db/routines/vn/triggers/buy_beforeDelete.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeDelete` + BEFORE DELETE ON `buy` + FOR EACH ROW +BEGIN + IF OLD.printedStickers <> 0 THEN + CALL util.throw("it is not possible to delete buys with printed labels "); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_beforeInsert.sql b/db/routines/vn/triggers/buy_beforeInsert.sql new file mode 100644 index 000000000..c88bef05a --- /dev/null +++ b/db/routines/vn/triggers/buy_beforeInsert.sql @@ -0,0 +1,84 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeInsert` + BEFORE INSERT ON `buy` + FOR EACH ROW +trig: BEGIN + DECLARE vWarehouse INT; + DECLARE vLanding DATE; + DECLARE vGrouping INT; + DECLARE vGroupingMode TINYINT; + DECLARE vGenericFk INT; + DECLARE vGenericInDate BOOL; + + IF @isModeInventory THEN + LEAVE trig; + END IF; + + IF NEW.printedStickers <> 0 THEN + CALL util.throw('it is not possible to create buy lines with printedstickers other than 0'); + END IF; + + SET NEW.editorFk = account.myUser_getId(); + + CALL buy_checkGrouping(NEW.`grouping`); + + SELECT t.warehouseInFk, t.landed + INTO vWarehouse, vLanding + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.id = NEW.entryFk; + + SELECT b.`grouping`, b.groupingMode + INTO vGrouping, vGroupingMode + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed <= vLanding + AND b.itemFk = NEW.itemFk + 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` = vGrouping; + END IF; + + IF NEW.groupingMode IS NULL THEN + SET NEW.groupingMode = vGroupingMode; + END IF; + + -- Generics + SELECT i.genericFk INTO vGenericFk + FROM item i + WHERE i.id = NEW.itemFk; + + IF vGenericFk THEN + SELECT COUNT(*) INTO vGenericInDate + FROM genericAllocation ga + JOIN entry e ON e.id = NEW.entryFk + JOIN travel tr on tr.id = e.travelFk + WHERE ga.itemFk = vGenericFk + AND tr.landed BETWEEN ga.startDated AND ga.endDated; + + IF vGenericInDate THEN + SET NEW.itemOriginalFk = NEW.itemFk; + SET NEW.itemFk = vGenericFk; + END IF; + END IF; + + IF NEW.quantity < 0 THEN + SET NEW.isIgnored = TRUE; + END IF; + + IF NEW.weight AND NEW.packing + AND (SELECT weightByPiece FROM item WHERE id = NEW.itemFk) IS NULL THEN + + UPDATE item + SET weightByPiece = (NEW.weight * 1000) / NEW.packing + WHERE id = NEW.itemFk; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/buy_beforeUpdate.sql b/db/routines/vn/triggers/buy_beforeUpdate.sql new file mode 100644 index 000000000..4468d3f3a --- /dev/null +++ b/db/routines/vn/triggers/buy_beforeUpdate.sql @@ -0,0 +1,68 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeUpdate` + BEFORE UPDATE ON `buy` + FOR EACH ROW +trig:BEGIN + DECLARE vGenericFk INT; + DECLARE vGenericInDate BOOL; + DECLARE vIsInventory BOOL; + DECLARE vDefaultEntry INT; + + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT defaultEntry INTO vDefaultEntry + FROM entryConfig; + + IF (NOT OLD.entryFk <=> NEW.entryFk OR NOT OLD.printedStickers <=> NEW.printedStickers) + AND NEW.printedStickers <> 0 THEN + SELECT defaultEntry INTO vDefaultEntry + FROM entryConfig; + + IF NEW.entryFk = vDefaultEntry THEN + CALL util.throw('There can be no lines with printed labels on the default entry'); + END IF; + END IF; + + IF NOT NEW.`grouping` <=> OLD.`grouping` THEN + CALL buy_checkGrouping(NEW.`grouping`); + END IF; + + -- Generics + SELECT i.genericFk INTO vGenericFk + FROM item i + WHERE i.id = NEW.itemFk; + + IF vGenericFk THEN + SELECT COUNT(*) INTO vGenericInDate + FROM genericAllocation ga + JOIN entry e ON e.id = NEW.entryFk + JOIN travel tr on tr.id = e.travelFk + WHERE ga.itemFk = vGenericFk + AND tr.landed BETWEEN ga.startDated AND ga.endDated; + IF vGenericInDate THEN + SET NEW.itemOriginalFk = NEW.itemFk; + SET NEW.itemFk = vGenericFk; + END IF; + END IF; + + SELECT COUNT(*) INTO vIsInventory + FROM entry e + JOIN supplier s ON s.id = e.supplierFk + JOIN entryConfig ec ON ec.inventorySupplierFk = e.supplierFk + WHERE e.id = NEW.entryFk; + + IF vIsInventory THEN + IF NOT NEW.printedStickers <=> OLD.printedStickers THEN + CALL util.throw("Stickers cannot be modified if they are inventory"); + END IF; + END IF; + + IF NEW.quantity < 0 THEN + SET NEW.isIgnored = TRUE; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimBeginning_afterDelete.sql b/db/routines/vn/triggers/claimBeginning_afterDelete.sql new file mode 100644 index 000000000..5e12d9feb --- /dev/null +++ b/db/routines/vn/triggers/claimBeginning_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimBeginning_afterDelete` + AFTER DELETE ON `claimBeginning` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimBeginning', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimBeginning_beforeInsert.sql b/db/routines/vn/triggers/claimBeginning_beforeInsert.sql new file mode 100644 index 000000000..f6ad1672b --- /dev/null +++ b/db/routines/vn/triggers/claimBeginning_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimBeginning_beforeInsert` + BEFORE INSERT ON `claimBeginning` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimBeginning_beforeUpdate.sql b/db/routines/vn/triggers/claimBeginning_beforeUpdate.sql new file mode 100644 index 000000000..500d08cb6 --- /dev/null +++ b/db/routines/vn/triggers/claimBeginning_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimBeginning_beforeUpdate` + BEFORE UPDATE ON `claimBeginning` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimDevelopment_afterDelete.sql b/db/routines/vn/triggers/claimDevelopment_afterDelete.sql new file mode 100644 index 000000000..90b1e89eb --- /dev/null +++ b/db/routines/vn/triggers/claimDevelopment_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimDevelopment_afterDelete` + AFTER DELETE ON `claimDevelopment` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimDevelopment', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimDevelopment_beforeInsert.sql b/db/routines/vn/triggers/claimDevelopment_beforeInsert.sql new file mode 100644 index 000000000..15ec36138 --- /dev/null +++ b/db/routines/vn/triggers/claimDevelopment_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimDevelopment_beforeInsert` + BEFORE INSERT ON `claimDevelopment` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimDevelopment_beforeUpdate.sql b/db/routines/vn/triggers/claimDevelopment_beforeUpdate.sql new file mode 100644 index 000000000..b0727adb3 --- /dev/null +++ b/db/routines/vn/triggers/claimDevelopment_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimDevelopment_beforeUpdate` + BEFORE UPDATE ON `claimDevelopment` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimDms_afterDelete.sql b/db/routines/vn/triggers/claimDms_afterDelete.sql new file mode 100644 index 000000000..53bf819e2 --- /dev/null +++ b/db/routines/vn/triggers/claimDms_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimDms_afterDelete` + AFTER DELETE ON `claimDms` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimDms', + `changedModelId` = OLD.claimFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimDms_beforeInsert.sql b/db/routines/vn/triggers/claimDms_beforeInsert.sql new file mode 100644 index 000000000..bb84e7a81 --- /dev/null +++ b/db/routines/vn/triggers/claimDms_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimDms_beforeInsert` + BEFORE INSERT ON `claimDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimDms_beforeUpdate.sql b/db/routines/vn/triggers/claimDms_beforeUpdate.sql new file mode 100644 index 000000000..8ffab268e --- /dev/null +++ b/db/routines/vn/triggers/claimDms_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimDms_beforeUpdate` + BEFORE UPDATE ON `claimDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimEnd_afterDelete.sql b/db/routines/vn/triggers/claimEnd_afterDelete.sql new file mode 100644 index 000000000..dee80fc77 --- /dev/null +++ b/db/routines/vn/triggers/claimEnd_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimEnd_afterDelete` + AFTER DELETE ON `claimEnd` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimEnd', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimEnd_beforeInsert.sql b/db/routines/vn/triggers/claimEnd_beforeInsert.sql new file mode 100644 index 000000000..beb66c297 --- /dev/null +++ b/db/routines/vn/triggers/claimEnd_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimEnd_beforeInsert` + BEFORE INSERT ON `claimEnd` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimEnd_beforeUpdate.sql b/db/routines/vn/triggers/claimEnd_beforeUpdate.sql new file mode 100644 index 000000000..7e91996dd --- /dev/null +++ b/db/routines/vn/triggers/claimEnd_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimEnd_beforeUpdate` + BEFORE UPDATE ON `claimEnd` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimObservation_afterDelete.sql b/db/routines/vn/triggers/claimObservation_afterDelete.sql new file mode 100644 index 000000000..b61368310 --- /dev/null +++ b/db/routines/vn/triggers/claimObservation_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimObservation_afterDelete` + AFTER DELETE ON `claimObservation` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimObservation_beforeInsert.sql b/db/routines/vn/triggers/claimObservation_beforeInsert.sql new file mode 100644 index 000000000..e6cf4a42a --- /dev/null +++ b/db/routines/vn/triggers/claimObservation_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimObservation_beforeInsert` + BEFORE INSERT ON `claimObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimObservation_beforeUpdate.sql b/db/routines/vn/triggers/claimObservation_beforeUpdate.sql new file mode 100644 index 000000000..79008eb1b --- /dev/null +++ b/db/routines/vn/triggers/claimObservation_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimObservation_beforeUpdate` + BEFORE UPDATE ON `claimObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimState_afterDelete.sql b/db/routines/vn/triggers/claimState_afterDelete.sql new file mode 100644 index 000000000..00c0a203d --- /dev/null +++ b/db/routines/vn/triggers/claimState_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimState_afterDelete` + AFTER DELETE ON `claimState` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimState', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimState_beforeInsert.sql b/db/routines/vn/triggers/claimState_beforeInsert.sql new file mode 100644 index 000000000..e289e8067 --- /dev/null +++ b/db/routines/vn/triggers/claimState_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimState_beforeInsert` + BEFORE INSERT ON `claimState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claimState_beforeUpdate.sql b/db/routines/vn/triggers/claimState_beforeUpdate.sql new file mode 100644 index 000000000..53c8c254b --- /dev/null +++ b/db/routines/vn/triggers/claimState_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimState_beforeUpdate` + BEFORE UPDATE ON `claimState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claim_afterDelete.sql b/db/routines/vn/triggers/claim_afterDelete.sql new file mode 100644 index 000000000..bd01ad80f --- /dev/null +++ b/db/routines/vn/triggers/claim_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claim_afterDelete` + AFTER DELETE ON `claim` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'Claim', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claim_beforeInsert.sql b/db/routines/vn/triggers/claim_beforeInsert.sql new file mode 100644 index 000000000..36f73902b --- /dev/null +++ b/db/routines/vn/triggers/claim_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claim_beforeInsert` + BEFORE INSERT ON `claim` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/claim_beforeUpdate.sql b/db/routines/vn/triggers/claim_beforeUpdate.sql new file mode 100644 index 000000000..9dec746ad --- /dev/null +++ b/db/routines/vn/triggers/claim_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claim_beforeUpdate` + BEFORE UPDATE ON `claim` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientContact_afterDelete.sql b/db/routines/vn/triggers/clientContact_afterDelete.sql new file mode 100644 index 000000000..b138a0957 --- /dev/null +++ b/db/routines/vn/triggers/clientContact_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientContact_afterDelete` + AFTER DELETE ON `clientContact` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientContact', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientContact_beforeInsert.sql b/db/routines/vn/triggers/clientContact_beforeInsert.sql new file mode 100644 index 000000000..7ddf4d7dd --- /dev/null +++ b/db/routines/vn/triggers/clientContact_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientContact_beforeInsert` + BEFORE INSERT ON `clientContact` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientCredit_AfterInsert.sql b/db/routines/vn/triggers/clientCredit_AfterInsert.sql new file mode 100644 index 000000000..a0f1c65ce --- /dev/null +++ b/db/routines/vn/triggers/clientCredit_AfterInsert.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientCredit_AfterInsert` + AFTER INSERT ON `clientCredit` + FOR EACH ROW +BEGIN + + DECLARE vSender VARCHAR(50); + + SELECT u.name INTO vSender + FROM account.`user` u + WHERE u.id = NEW.workerFk; + + IF vSender IN ('juanvi','pepe') THEN + + CALL `vn`.`mail_insert`('pako@verdnatura.es', + NULL, + CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €'), + CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €')); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientDms_afterDelete.sql b/db/routines/vn/triggers/clientDms_afterDelete.sql new file mode 100644 index 000000000..9b6fb4876 --- /dev/null +++ b/db/routines/vn/triggers/clientDms_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientDms_afterDelete` + AFTER DELETE ON `clientDms` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientDms', + `changedModelId` = OLD.dmsFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientDms_beforeInsert.sql b/db/routines/vn/triggers/clientDms_beforeInsert.sql new file mode 100644 index 000000000..011cc6e96 --- /dev/null +++ b/db/routines/vn/triggers/clientDms_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientDms_beforeInsert` + BEFORE INSERT ON `clientDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientDms_beforeUpdate.sql b/db/routines/vn/triggers/clientDms_beforeUpdate.sql new file mode 100644 index 000000000..56eaec7eb --- /dev/null +++ b/db/routines/vn/triggers/clientDms_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientDms_beforeUpdate` + BEFORE UPDATE ON `clientDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientObservation_afterDelete.sql b/db/routines/vn/triggers/clientObservation_afterDelete.sql new file mode 100644 index 000000000..c93564aa5 --- /dev/null +++ b/db/routines/vn/triggers/clientObservation_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientObservation_afterDelete` + AFTER DELETE ON `clientObservation` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientObservation_beforeInsert.sql b/db/routines/vn/triggers/clientObservation_beforeInsert.sql new file mode 100644 index 000000000..684873031 --- /dev/null +++ b/db/routines/vn/triggers/clientObservation_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientObservation_beforeInsert` + BEFORE INSERT ON `clientObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientObservation_beforeUpdate.sql b/db/routines/vn/triggers/clientObservation_beforeUpdate.sql new file mode 100644 index 000000000..6e0b63794 --- /dev/null +++ b/db/routines/vn/triggers/clientObservation_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientObservation_beforeUpdate` + BEFORE UPDATE ON `clientObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientSample_afterDelete.sql b/db/routines/vn/triggers/clientSample_afterDelete.sql new file mode 100644 index 000000000..1ac9e77be --- /dev/null +++ b/db/routines/vn/triggers/clientSample_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientSample_afterDelete` + AFTER DELETE ON `clientSample` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientSample', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientSample_beforeInsert.sql b/db/routines/vn/triggers/clientSample_beforeInsert.sql new file mode 100644 index 000000000..c7fe43c9b --- /dev/null +++ b/db/routines/vn/triggers/clientSample_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientSample_beforeInsert` + BEFORE INSERT ON `clientSample` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/clientSample_beforeUpdate.sql b/db/routines/vn/triggers/clientSample_beforeUpdate.sql new file mode 100644 index 000000000..5c16950b5 --- /dev/null +++ b/db/routines/vn/triggers/clientSample_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientSample_beforeUpdate` + BEFORE UPDATE ON `clientSample` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/client_AfterInsert.sql b/db/routines/vn/triggers/client_AfterInsert.sql new file mode 100644 index 000000000..401d8951f --- /dev/null +++ b/db/routines/vn/triggers/client_AfterInsert.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_AfterInsert` + AFTER INSERT ON `client` + FOR EACH ROW +BEGIN + IF NEW.credit IS NOT NULL AND NEW.credit THEN + INSERT INTO clientCredit + SET clientFk = NEW.id, + workerFk = NEW.editorFk, + amount = NEW.credit; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/client_afterDelete.sql b/db/routines/vn/triggers/client_afterDelete.sql new file mode 100644 index 000000000..e6849ef49 --- /dev/null +++ b/db/routines/vn/triggers/client_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterDelete` + AFTER DELETE ON `client` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Client', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/client_afterUpdate.sql b/db/routines/vn/triggers/client_afterUpdate.sql new file mode 100644 index 000000000..481b00007 --- /dev/null +++ b/db/routines/vn/triggers/client_afterUpdate.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterUpdate` + AFTER UPDATE ON `client` + FOR EACH ROW +BEGIN + IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN + UPDATE `address` SET isDefaultAddress = 0 + WHERE clientFk = NEW.id; + + UPDATE `address` SET isDefaultAddress = 1 + WHERE id = NEW.defaultAddressFk; + END IF; + + IF NOT (NEW.provinceFk <=> OLD.provinceFk) OR NOT (NEW.isVies <=> OLD.isVies) THEN + INSERT IGNORE INTO ticketRecalc (ticketFk) + SELECT id FROM ticket t + WHERE t.clientFk = NEW.id + AND t.refFk IS NULL; + END IF; + + IF NOT NEW.isActive THEN + UPDATE account.`user` + SET active = FALSE + WHERE id = NEW.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/client_beforeInsert.sql b/db/routines/vn/triggers/client_beforeInsert.sql new file mode 100644 index 000000000..75b69c7dd --- /dev/null +++ b/db/routines/vn/triggers/client_beforeInsert.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeInsert` + BEFORE INSERT ON `client` + FOR EACH ROW +BEGIN + + SET NEW.editorFk = account.myUser_getId(); + + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF (NEW.mobile <> '') THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + + SET NEW.accountingAccount = 4300000000 + NEW.id; + + SET NEW.lastSalesPersonFk = NEW.salesPersonFk; +END$$ +DELIMITER ; diff --git a/db/.archive/231401/00-clientBeforeUpdate.sql b/db/routines/vn/triggers/client_beforeUpdate.sql similarity index 73% rename from db/.archive/231401/00-clientBeforeUpdate.sql rename to db/routines/vn/triggers/client_beforeUpdate.sql index 6bae98f61..2f384c535 100644 --- a/db/.archive/231401/00-clientBeforeUpdate.sql +++ b/db/routines/vn/triggers/client_beforeUpdate.sql @@ -1,21 +1,26 @@ -DROP TRIGGER IF EXISTS `vn`.`client_beforeUpdate`; -USE `vn`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate` BEFORE UPDATE ON `client` FOR EACH ROW BEGIN DECLARE vText VARCHAR(255) DEFAULT NULL; - DECLARE vPayMethodFk INT; + DECLARE vPayMethodFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF NOT(NEW.credit <=> OLD.credit) THEN + INSERT INTO clientCredit + SET clientFk = NEW.id, + amount = NEW.credit, + workerFk = NEW.editorFk; + END IF; -- Comprueba que el formato de los teléfonos es válido IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN CALL pbx.phone_isValid(NEW.phone); END IF; - IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN CALL pbx.phone_isValid(NEW.mobile); END IF; @@ -25,7 +30,7 @@ BEGIN IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN SET NEW.dueDay = 5; - END IF; + END IF; -- Avisar al comercial si ha llegado la documentación sepa/core @@ -38,12 +43,12 @@ BEGIN END IF; IF vText IS NOT NULL - THEN + THEN INSERT INTO mail(receiver, replyTo, `subject`, body) SELECT CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'), - 'administracion@verdnatura.es', - CONCAT('Cliente ', NEW.id), + 'administracion@verdnatura.es', + CONCAT('Cliente ', NEW.id), CONCAT('Recibida la documentación: ', vText) FROM worker w LEFT JOIN account.user u ON w.id = u.id AND u.active @@ -51,10 +56,10 @@ BEGIN WHERE w.id = NEW.salesPersonFk; END IF; - IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN + IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN IF (SELECT COUNT(clientFk) FROM clientProtected - WHERE clientFk = NEW.id + WHERE clientFk = NEW.id ) > 0 THEN CALL util.throw("HAS_CLIENT_PROTECTED"); END IF; @@ -67,6 +72,5 @@ BEGIN IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN SET NEW.isTaxDataChecked = 0; END IF; - END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/cmr_beforeDelete.sql b/db/routines/vn/triggers/cmr_beforeDelete.sql new file mode 100644 index 000000000..2cb789244 --- /dev/null +++ b/db/routines/vn/triggers/cmr_beforeDelete.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`cmr_beforeDelete` + BEFORE DELETE ON `cmr` + FOR EACH ROW +BEGIN + IF NOT (OLD.companyFk <=> NULL AND OLD.addressFromFk <=> NULL AND OLD.packagesList <=> NULL) THEN + CALL util.throw("Can not delete cmr, fields required not empty"); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/collectionColors_beforeInsert.sql b/db/routines/vn/triggers/collectionColors_beforeInsert.sql new file mode 100644 index 000000000..254529932 --- /dev/null +++ b/db/routines/vn/triggers/collectionColors_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collectionColors_beforeInsert` + BEFORE INSERT ON `collectionColors` + FOR EACH ROW +BEGIN + CALL util.checkHex(NEW.rgb); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/collectionColors_beforeUpdate.sql b/db/routines/vn/triggers/collectionColors_beforeUpdate.sql new file mode 100644 index 000000000..1ee83ab74 --- /dev/null +++ b/db/routines/vn/triggers/collectionColors_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collectionColors_beforeUpdate` + BEFORE UPDATE ON `collectionColors` + FOR EACH ROW +BEGIN + CALL util.checkHex(NEW.rgb); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/collectionVolumetry_afterDelete.sql b/db/routines/vn/triggers/collectionVolumetry_afterDelete.sql new file mode 100644 index 000000000..53c6340ee --- /dev/null +++ b/db/routines/vn/triggers/collectionVolumetry_afterDelete.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collectionVolumetry_afterDelete` + AFTER DELETE ON `collectionVolumetry` + FOR EACH ROW +BEGIN + DECLARE vJSON JSON DEFAULT JSON_OBJECT(); + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SET vJSON = JSON_MERGE(JSON_OBJECT('id', OLD.id), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('level', OLD.level), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('lines', OLD.lines), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('liters', OLD.liters), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('height', OLD.height), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', OLD.itemPackingTypeFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', OLD.trainFk), vJSON); + + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'delete'), vJSON); + + SET vJSON = util.notification_send( + 'modified-collection-volumetry', + JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), + vUserFk + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/collectionVolumetry_afterInsert.sql b/db/routines/vn/triggers/collectionVolumetry_afterInsert.sql new file mode 100644 index 000000000..9f061742c --- /dev/null +++ b/db/routines/vn/triggers/collectionVolumetry_afterInsert.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collectionVolumetry_afterInsert` + AFTER INSERT ON `collectionVolumetry` + FOR EACH ROW +BEGIN + DECLARE vJSON JSON DEFAULT JSON_OBJECT(); + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.level), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('lines', NEW.lines), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('liters', NEW.liters), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('height', NEW.height), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); + + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'insert'), vJSON); + + SET vJSON = util.notification_send( + 'modified-collection-volumetry', + JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), + vUserFk + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/collectionVolumetry_afterUpdate.sql b/db/routines/vn/triggers/collectionVolumetry_afterUpdate.sql new file mode 100644 index 000000000..6dc4311c5 --- /dev/null +++ b/db/routines/vn/triggers/collectionVolumetry_afterUpdate.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collectionVolumetry_afterUpdate` + AFTER UPDATE ON `collectionVolumetry` + FOR EACH ROW +BEGIN + DECLARE vJSON JSON DEFAULT JSON_OBJECT(); + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + IF NOT (NEW.id <=> OLD.id) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); + END IF; + + IF NOT (NEW.`level` <=> OLD.`level`) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.`level`), vJSON); + END IF; + + IF NOT (NEW.`lines` <=> OLD.`lines`) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('lines', NEW.`lines`), vJSON); + END IF; + + IF NOT (NEW.liters <=> OLD.liters) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('liters', NEW.liters), vJSON); + END IF; + + IF NOT (NEW.height <=> OLD.height) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('height', NEW.height), vJSON); + END IF; + + IF NOT (NEW.itemPackingTypeFk <=> OLD.itemPackingTypeFk) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); + END IF; + + IF NOT (NEW.trainFk <=> OLD.trainFk) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); + END IF; + + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'update'), vJSON); + + SET vJSON = util.notification_send( + 'modified-collection-volumetry', + JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), + vUserFk + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/collection_BEFORE_UPDATE.sql b/db/routines/vn/triggers/collection_BEFORE_UPDATE.sql new file mode 100644 index 000000000..a4a5ff91c --- /dev/null +++ b/db/routines/vn/triggers/collection_BEFORE_UPDATE.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collection_BEFORE_UPDATE` + BEFORE UPDATE ON `collection` + FOR EACH ROW +BEGIN + + DECLARE vStateFk INT; + DECLARE vTotalLines INT; + DECLARE vPickedLines INT; + + IF NEW.saleTotalCount <= NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount + OR NEW.salePickedCount != OLD.salePickedCount) + THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'PREPARED'; + + SET NEW.stateFk = vStateFk; + + END IF; + + IF NEW.saleTotalCount > NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'ON_PREPARATION'; + + SET NEW.stateFk = vStateFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/country_AFTER_INSERT.sql b/db/routines/vn/triggers/country_AFTER_INSERT.sql new file mode 100644 index 000000000..baf17b18b --- /dev/null +++ b/db/routines/vn/triggers/country_AFTER_INSERT.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_AFTER_INSERT` + AFTER INSERT ON `country` + FOR EACH ROW +BEGIN + UPDATE sage.Naciones + SET countryFk = NEW.id + WHERE Nacion = NEW.country; + + IF ROW_COUNT() = 0 THEN + CALL mail_insert( + 'cau@verdnatura.es', + NULL, + 'Actualizar tabla sage.Naciones', + CONCAT('Se ha insertado un nuevo país en la tabla vn.conuntry. Para el correcto funcionamiento del sistema \n\t\t\t\tde contabilidad es necesario actualizar la columna sage.Naciones.countryFk con el valor del nuevo país. \n\t\t\t Hay que buscar el nuevo país: ', NEW.country, ' en la tabla sage.Naciones y actualizar el campo sage.Naciones.countryFk con el valor ', NEW.id) + ); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/country_afterDelete.sql b/db/routines/vn/triggers/country_afterDelete.sql new file mode 100644 index 000000000..30fbfc817 --- /dev/null +++ b/db/routines/vn/triggers/country_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_afterDelete` + AFTER DELETE ON `country` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/country_afterUpdate.sql b/db/routines/vn/triggers/country_afterUpdate.sql new file mode 100644 index 000000000..6afa2fd48 --- /dev/null +++ b/db/routines/vn/triggers/country_afterUpdate.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_afterUpdate` + AFTER UPDATE ON `country` + FOR EACH ROW +BEGIN + IF !(OLD.country <=> NEW.country) THEN + UPDATE zoneGeo SET `name` = NEW.country + WHERE id = NEW.geoFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/country_beforeInsert.sql b/db/routines/vn/triggers/country_beforeInsert.sql new file mode 100644 index 000000000..26e0235ce --- /dev/null +++ b/db/routines/vn/triggers/country_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_beforeInsert` + BEFORE INSERT ON `country` + FOR EACH ROW +BEGIN + SET NEW.geoFk = zoneGeo_new('country', NEW.country, NULL); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/country_beforeUpdate.sql b/db/routines/vn/triggers/country_beforeUpdate.sql new file mode 100644 index 000000000..31de99f34 --- /dev/null +++ b/db/routines/vn/triggers/country_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_beforeUpdate` + BEFORE UPDATE ON `country` + FOR EACH ROW +BEGIN + -- IF !(OLD.geoFk <=> NEW.geoFk) THEN + -- CALL zoneGeo_throwNotEditable; + -- END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/creditClassification_beforeUpdate.sql b/db/routines/vn/triggers/creditClassification_beforeUpdate.sql new file mode 100644 index 000000000..410ce2bc4 --- /dev/null +++ b/db/routines/vn/triggers/creditClassification_beforeUpdate.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`creditClassification_beforeUpdate` + BEFORE UPDATE ON `creditClassification` + FOR EACH ROW +BEGIN + IF NEW.client <> OLD.client THEN + CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT'); + END IF; + IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN + UPDATE `client` c + SET creditInsurance = NULL WHERE c.id = NEW.client; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/creditInsurance_afterInsert.sql b/db/routines/vn/triggers/creditInsurance_afterInsert.sql new file mode 100644 index 000000000..22f94854b --- /dev/null +++ b/db/routines/vn/triggers/creditInsurance_afterInsert.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`creditInsurance_afterInsert` + AFTER INSERT ON `creditInsurance` + FOR EACH ROW +BEGIN + UPDATE `client` c + JOIN vn.creditClassification cc ON cc.client = c.id + SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/creditInsurance_beforeInsert.sql b/db/routines/vn/triggers/creditInsurance_beforeInsert.sql new file mode 100644 index 000000000..51ab223b1 --- /dev/null +++ b/db/routines/vn/triggers/creditInsurance_beforeInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`creditInsurance_beforeInsert` + BEFORE INSERT ON `creditInsurance` + FOR EACH ROW +BEGIN + IF NEW.creditClassificationFk THEN + SET NEW.creditClassification = NEW.creditClassificationFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/department_afterDelete.sql b/db/routines/vn/triggers/department_afterDelete.sql new file mode 100644 index 000000000..311847556 --- /dev/null +++ b/db/routines/vn/triggers/department_afterDelete.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`department_afterDelete` + AFTER DELETE ON `department` + FOR EACH ROW +BEGIN + + UPDATE vn.department_recalc SET isChanged = TRUE; + + UPDATE vn.business b + JOIN vn.department d ON d.id = b.departmentFk + SET b.departmentFk = d.parentFk + WHERE b.departmentFk = OLD.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/department_afterUpdate.sql b/db/routines/vn/triggers/department_afterUpdate.sql new file mode 100644 index 000000000..a425e1809 --- /dev/null +++ b/db/routines/vn/triggers/department_afterUpdate.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`department_afterUpdate` + AFTER UPDATE ON `department` + FOR EACH ROW +BEGIN + IF !(OLD.parentFk <=> NEW.parentFk) THEN + UPDATE vn.department_recalc SET isChanged = TRUE; + END IF; + + IF !(OLD.twoFactor <=> NEW.twoFactor) THEN + UPDATE account.user u + JOIN vn.workerDepartment wd ON wd.workerFk = u.id + SET u.twoFactor = NEW.twoFactor + WHERE wd.departmentFk = NEW.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/department_beforeDelete.sql b/db/routines/vn/triggers/department_beforeDelete.sql new file mode 100644 index 000000000..6eaa5b42e --- /dev/null +++ b/db/routines/vn/triggers/department_beforeDelete.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`department_beforeDelete` + BEFORE DELETE ON `department` + FOR EACH ROW +BEGIN + + UPDATE vn.business b + JOIN vn.department d ON d.id = b.departmentFk + SET b.departmentFk = d.parentFk + WHERE b.departmentFk = OLD.id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/department_beforeInsert.sql b/db/routines/vn/triggers/department_beforeInsert.sql new file mode 100644 index 000000000..6bd6617ae --- /dev/null +++ b/db/routines/vn/triggers/department_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`department_beforeInsert` + BEFORE INSERT ON `department` + FOR EACH ROW +BEGIN + UPDATE vn.department_recalc SET isChanged = TRUE; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionConfig_afterUpdate.sql b/db/routines/vn/triggers/deviceProductionConfig_afterUpdate.sql new file mode 100644 index 000000000..98e4f844f --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionConfig_afterUpdate.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionConfig_afterUpdate` + AFTER UPDATE ON `deviceProductionConfig` + FOR EACH ROW +BEGIN + IF NEW.isAllUsersAllowed = 1 OR NEW.isAllUsersAllowed = -1 THEN + SET @username := (SELECT account.myUser_getName()); + INSERT INTO vn.mail (receiver, subject, body) + VALUES ('cau@verdnatura.es', 'Se ha activado la autenticación sin restricciones en la app', + CONCAT('El usuario ', @username,' ha habilitado la opción para que todos los usuarios puedan acceder a la app sin restricciones')); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionModels_beforeInsert.sql b/db/routines/vn/triggers/deviceProductionModels_beforeInsert.sql new file mode 100644 index 000000000..3994520b7 --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionModels_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionModels_beforeInsert` + BEFORE INSERT ON `deviceProductionModels` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionModels_beforeUpdate.sql b/db/routines/vn/triggers/deviceProductionModels_beforeUpdate.sql new file mode 100644 index 000000000..01c8d347e --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionModels_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionModels_beforeUpdate` + BEFORE UPDATE ON `deviceProductionModels` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionState_beforeInsert.sql b/db/routines/vn/triggers/deviceProductionState_beforeInsert.sql new file mode 100644 index 000000000..1a2a66e10 --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionState_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionState_beforeInsert` + BEFORE INSERT ON `deviceProductionState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionState_beforeUpdate.sql b/db/routines/vn/triggers/deviceProductionState_beforeUpdate.sql new file mode 100644 index 000000000..e8172fb42 --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionState_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionState_beforeUpdate` + BEFORE UPDATE ON `deviceProductionState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionUser_afterDelete.sql b/db/routines/vn/triggers/deviceProductionUser_afterDelete.sql new file mode 100644 index 000000000..a95170e9a --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionUser_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_afterDelete` + AFTER DELETE ON `deviceProductionUser` + FOR EACH ROW +BEGIN + INSERT INTO deviceProductionLog + SET `action` = 'delete', + `changedModel` = 'DeviceProductionUser', + `changedModelId` = OLD.deviceProductionFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionUser_beforeInsert.sql b/db/routines/vn/triggers/deviceProductionUser_beforeInsert.sql new file mode 100644 index 000000000..b392cf5a1 --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionUser_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_beforeInsert` + BEFORE INSERT ON `deviceProductionUser` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProductionUser_beforeUpdate.sql b/db/routines/vn/triggers/deviceProductionUser_beforeUpdate.sql new file mode 100644 index 000000000..055f81790 --- /dev/null +++ b/db/routines/vn/triggers/deviceProductionUser_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_beforeUpdate` + BEFORE UPDATE ON `deviceProductionUser` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProduction_afterDelete.sql b/db/routines/vn/triggers/deviceProduction_afterDelete.sql new file mode 100644 index 000000000..af2b640e5 --- /dev/null +++ b/db/routines/vn/triggers/deviceProduction_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProduction_afterDelete` + AFTER DELETE ON `deviceProduction` + FOR EACH ROW +BEGIN + INSERT INTO deviceProductionLog + SET `action` = 'delete', + `changedModel` = 'DeviceProduction', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProduction_beforeInsert.sql b/db/routines/vn/triggers/deviceProduction_beforeInsert.sql new file mode 100644 index 000000000..66b5c2aef --- /dev/null +++ b/db/routines/vn/triggers/deviceProduction_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProduction_beforeInsert` + BEFORE INSERT ON `deviceProduction` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/deviceProduction_beforeUpdate.sql b/db/routines/vn/triggers/deviceProduction_beforeUpdate.sql new file mode 100644 index 000000000..9206195fe --- /dev/null +++ b/db/routines/vn/triggers/deviceProduction_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProduction_beforeUpdate` + BEFORE UPDATE ON `deviceProduction` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/dms_beforeDelete.sql b/db/routines/vn/triggers/dms_beforeDelete.sql new file mode 100644 index 000000000..3bbc05ba3 --- /dev/null +++ b/db/routines/vn/triggers/dms_beforeDelete.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`dms_beforeDelete` + BEFORE DELETE ON `dms` + FOR EACH ROW +BEGIN + DECLARE vCanNotBeDeleted INT; + SELECT COUNT(*) INTO vCanNotBeDeleted + FROM dmsType dt + WHERE NOT (code <=> 'trash') + AND dt.id = OLD.dmsTypeFk; + + IF vCanNotBeDeleted THEN + CALL util.throw('A dms can not be deleted'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/dms_beforeInsert.sql b/db/routines/vn/triggers/dms_beforeInsert.sql new file mode 100644 index 000000000..f7877ecb8 --- /dev/null +++ b/db/routines/vn/triggers/dms_beforeInsert.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`dms_beforeInsert` + BEFORE INSERT ON `dms` + FOR EACH ROW +BEGIN + DECLARE vHardCopyNumber INT; + DECLARE vDmsTypeCode INT; + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + CALL util.throw('this warehouse has not dms'); + END IF; + + IF NEW.hasFile THEN + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms + WHERE warehouseFk = NEW.warehouseFk; + + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); + END IF; + + SELECT code INTO vDmsTypeCode + FROM dmsType WHERE NEW.dmsTypeFk = id; + IF (vDmsTypeCode ='ticket') THEN + UPDATE ticket SET isSigned = 1 WHERE id = NEW.reference; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/dms_beforeUpdate.sql b/db/routines/vn/triggers/dms_beforeUpdate.sql new file mode 100644 index 000000000..c93659d45 --- /dev/null +++ b/db/routines/vn/triggers/dms_beforeUpdate.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`dms_beforeUpdate` + BEFORE UPDATE ON `dms` + FOR EACH ROW +BEGIN + DECLARE vHardCopyNumber INT; + + IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) + OR + (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); + END IF; + + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms + WHERE warehouseFk = NEW.warehouseFk; + + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); + END IF; + + IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN + + SET NEW.hasFile = 0; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql b/db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql new file mode 100644 index 000000000..5a937cc79 --- /dev/null +++ b/db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`duaTax_BEFORE_INSERT` + BEFORE INSERT ON `duaTax` + FOR EACH ROW +BEGIN + SET NEW.rate = duaTax_getRate(NEW.duaFk, NEW.taxClassFk); + SET NEW.tax = NEW.base * NEW.rate / 100; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql b/db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql new file mode 100644 index 000000000..13c7f91c7 --- /dev/null +++ b/db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`duaTax_BEFORE_UPDATE` + BEFORE UPDATE ON `duaTax` + FOR EACH ROW +BEGIN + SET NEW.rate = duaTax_getRate(NEW.duaFk, NEW.taxClassFk); + SET NEW.tax = NEW.base * NEW.rate / 100; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ektEntryAssign_afterInsert.sql b/db/routines/vn/triggers/ektEntryAssign_afterInsert.sql new file mode 100644 index 000000000..e42b43ca1 --- /dev/null +++ b/db/routines/vn/triggers/ektEntryAssign_afterInsert.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ektEntryAssign_afterInsert` + AFTER INSERT ON `ektEntryAssign` + FOR EACH ROW +UPDATE entry SET reference = NEW.`ref` WHERE id = NEW.entryFk$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ektEntryAssign_afterUpdate.sql b/db/routines/vn/triggers/ektEntryAssign_afterUpdate.sql new file mode 100644 index 000000000..8d2791d0f --- /dev/null +++ b/db/routines/vn/triggers/ektEntryAssign_afterUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ektEntryAssign_afterUpdate` + AFTER UPDATE ON `ektEntryAssign` + FOR EACH ROW +BEGIN + IF NOT(NEW.`ref` <=> OLD.`ref`) OR NOT(NEW.`entryFk` <=> OLD.`entryFk`) THEN + UPDATE entry SET reference = NEW.`ref` WHERE id = NEW.entryFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entryObservation_afterDelete.sql b/db/routines/vn/triggers/entryObservation_afterDelete.sql new file mode 100644 index 000000000..d143e105a --- /dev/null +++ b/db/routines/vn/triggers/entryObservation_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entryObservation_afterDelete` + AFTER DELETE ON `entryObservation` + FOR EACH ROW +BEGIN + INSERT INTO entryLog + SET `action` = 'delete', + `changedModel` = 'EntryObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entryObservation_beforeInsert.sql b/db/routines/vn/triggers/entryObservation_beforeInsert.sql new file mode 100644 index 000000000..b842aeee7 --- /dev/null +++ b/db/routines/vn/triggers/entryObservation_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entryObservation_beforeInsert` + BEFORE INSERT ON `entryObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entryObservation_beforeUpdate.sql b/db/routines/vn/triggers/entryObservation_beforeUpdate.sql new file mode 100644 index 000000000..501631c69 --- /dev/null +++ b/db/routines/vn/triggers/entryObservation_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entryObservation_beforeUpdate` + BEFORE UPDATE ON `entryObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entry_afterDelete.sql b/db/routines/vn/triggers/entry_afterDelete.sql new file mode 100644 index 000000000..5c246651d --- /dev/null +++ b/db/routines/vn/triggers/entry_afterDelete.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_afterDelete` + AFTER DELETE ON `entry` + FOR EACH ROW +BEGIN + INSERT INTO entryLog + SET `action` = 'delete', + `changedModel` = 'Entry', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL travel_requestRecalc(OLD.travelFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entry_afterInsert.sql b/db/routines/vn/triggers/entry_afterInsert.sql new file mode 100644 index 000000000..79563c17f --- /dev/null +++ b/db/routines/vn/triggers/entry_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_afterInsert` + AFTER INSERT ON `entry` + FOR EACH ROW +BEGIN + CALL travel_requestRecalc(NEW.travelFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entry_afterUpdate.sql b/db/routines/vn/triggers/entry_afterUpdate.sql new file mode 100644 index 000000000..6d1ad0720 --- /dev/null +++ b/db/routines/vn/triggers/entry_afterUpdate.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_afterUpdate` + AFTER UPDATE ON `entry` + FOR EACH ROW +BEGIN + IF NOT(NEW.id <=> OLD.id) + OR NOT(NEW.travelFk <=> OLD.travelFk) + OR NOT(NEW.isRaid <=> OLD.isRaid) THEN + CALL stock.log_add('entry', NEW.id, OLD.id); + END IF; + + IF NOT (NEW.travelFk <=> OLD.travelFk) THEN + CALL travel_requestRecalc(OLD.travelFk); + CALL travel_requestRecalc(NEW.travelFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeDelete.sql b/db/routines/vn/triggers/entry_beforeDelete.sql new file mode 100644 index 000000000..82a3dabd5 --- /dev/null +++ b/db/routines/vn/triggers/entry_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeDelete` + BEFORE DELETE ON `entry` + FOR EACH ROW +BEGIN + DELETE FROM buy WHERE entryFk = OLD.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeInsert.sql b/db/routines/vn/triggers/entry_beforeInsert.sql new file mode 100644 index 000000000..f475630db --- /dev/null +++ b/db/routines/vn/triggers/entry_beforeInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeInsert` + BEFORE INSERT ON `entry` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL supplier_checkIsActive(NEW.supplierFk); + SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); + SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql new file mode 100644 index 000000000..91d490b21 --- /dev/null +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeUpdate` + BEFORE UPDATE ON `entry` + FOR EACH ROW +BEGIN + DECLARE vIsVirtual BOOL; + DECLARE vPrintedCount INT; + DECLARE vHasDistinctWarehouses BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF !(NEW.travelFk <=> OLD.travelFk) THEN + SELECT COUNT(*) > 0 INTO vIsVirtual + FROM entryVirtual WHERE entryFk = NEW.id; + + SELECT !(o.warehouseInFk <=> n.warehouseInFk) + OR !(o.warehouseOutFk <=> n.warehouseOutFk) + INTO vHasDistinctWarehouses + FROM travel o, travel n + WHERE o.id = OLD.travelFk + AND n.id = NEW.travelFk; + + IF vIsVirtual AND vHasDistinctWarehouses THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'A cloned entry cannot be moved to a travel with different warehouses'; + END IF; + + IF NEW.travelFk IS NULL THEN + SELECT COUNT(*) INTO vPrintedCount + FROM buy + WHERE entryFk = OLD.id + AND printedStickers > 0; + + IF vPrintedCount > 0 THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'An entry that contains lines with printed labels cannot be deleted'; + END IF; + END IF; + END IF; + + IF NOT (NEW.supplierFk <=> OLD.supplierFk) THEN + CALL supplier_checkIsActive(NEW.supplierFk); + SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); + END IF; + + IF NOT (NEW.travelFk <=> OLD.travelFk) + OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN + SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql b/db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql new file mode 100644 index 000000000..2ed69502b --- /dev/null +++ b/db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionPallet_BEFORE_INSERT` + BEFORE INSERT ON `expeditionPallet` + FOR EACH ROW +BEGIN + + DECLARE vNewPosition INT; + + SELECT MAX(position) + 1 INTO vNewPosition + FROM vn.expeditionPallet + WHERE truckFk = NEW.truckFk; + + SET NEW.position = IFNULL(vNewPosition,1); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql b/db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql new file mode 100644 index 000000000..dfc25f8bc --- /dev/null +++ b/db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionScan_BEFORE_INSERT` + BEFORE INSERT ON `expeditionScan` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expeditionState_AfterInsert.sql b/db/routines/vn/triggers/expeditionState_AfterInsert.sql new file mode 100644 index 000000000..618c2cfee --- /dev/null +++ b/db/routines/vn/triggers/expeditionState_AfterInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_AfterInsert` + AFTER INSERT ON `expeditionState` + FOR EACH ROW +BEGIN + + UPDATE vn.expedition e + SET e.stateTypeFk = NEW.typeFk + WHERE e.id = NEW.expeditionFk; + +END$$ +DELIMITER ; diff --git a/db/changes/234601/00-expeditionStateBeforeInsert.sql b/db/routines/vn/triggers/expeditionState_BeforeInsert.sql similarity index 97% rename from db/changes/234601/00-expeditionStateBeforeInsert.sql rename to db/routines/vn/triggers/expeditionState_BeforeInsert.sql index 565b3ded3..b210889ec 100644 --- a/db/changes/234601/00-expeditionStateBeforeInsert.sql +++ b/db/routines/vn/triggers/expeditionState_BeforeInsert.sql @@ -3,11 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_Befor BEFORE INSERT ON `expeditionState` FOR EACH ROW BEGIN - SET NEW.userFk = IFNULL(NEW.userFk, account.myUser_getId()); - END$$ DELIMITER ; - - - diff --git a/db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql b/db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql new file mode 100644 index 000000000..d7bf827f0 --- /dev/null +++ b/db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionTruck_BEFORE_INSERT` + BEFORE INSERT ON `expeditionTruck` + FOR EACH ROW +BEGIN + + SET NEW.description = UCASE(NEW.description); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql b/db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql new file mode 100644 index 000000000..f08e02ddf --- /dev/null +++ b/db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionTruck_BEFORE_UPDATE` + BEFORE UPDATE ON `expeditionTruck` + FOR EACH ROW +BEGIN + + SET NEW.description = UCASE(NEW.description); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expedition_afterDelete.sql b/db/routines/vn/triggers/expedition_afterDelete.sql new file mode 100644 index 000000000..e05cbf279 --- /dev/null +++ b/db/routines/vn/triggers/expedition_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_afterDelete` + AFTER DELETE ON `expedition` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'Expedition', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expedition_beforeDelete.sql b/db/routines/vn/triggers/expedition_beforeDelete.sql new file mode 100644 index 000000000..cbcc5a3bb --- /dev/null +++ b/db/routines/vn/triggers/expedition_beforeDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeDelete` + BEFORE DELETE ON `expedition` + FOR EACH ROW +BEGIN + UPDATE ticket t + SET packages = (SELECT COUNT(counter)-1 + FROM expedition e WHERE e.ticketFk = OLD.ticketFk and e.freightItemFk) + WHERE t.id = OLD.ticketFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expedition_beforeInsert.sql b/db/routines/vn/triggers/expedition_beforeInsert.sql new file mode 100644 index 000000000..a7fa029b4 --- /dev/null +++ b/db/routines/vn/triggers/expedition_beforeInsert.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeInsert` + BEFORE INSERT ON `expedition` + FOR EACH ROW +BEGIN + DECLARE intcounter INT; + DECLARE vShipFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.freightItemFk IS NOT NULL THEN + + UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk; + + SELECT IFNULL(MAX(counter),0) +1 INTO intcounter + FROM expedition e + INNER JOIN ticket t1 ON e.ticketFk = t1.id + LEFT JOIN ticketState ts ON ts.ticketFk = t1.id + INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + AND t1.warehouseFk = t2.warehouseFk + WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk + AND t1.agencyModeFk = t2.agencyModeFk; + + SET NEW.`counter` = intcounter; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/expedition_beforeUpdate.sql b/db/routines/vn/triggers/expedition_beforeUpdate.sql new file mode 100644 index 000000000..870c1a285 --- /dev/null +++ b/db/routines/vn/triggers/expedition_beforeUpdate.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeUpdate` + BEFORE UPDATE ON `expedition` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.counter <> OLD.counter THEN + IF (SELECT COUNT(*) FROM expedition e + INNER JOIN ticket t1 ON e.ticketFk = t1.id + INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + WHERE t1.id = NEW.ticketFk AND counter = NEW.counter) > 0 THEN + SET NEW.id = NULL; + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql b/db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql new file mode 100644 index 000000000..f4d9a5317 --- /dev/null +++ b/db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`floramondoConfig_AFTER_INSERT` + AFTER INSERT ON `floramondoConfig` + FOR EACH ROW +BEGIN + CALL util.throw ("Tabla config no permite añadir más registros"); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/gregue_beforeInsert.sql b/db/routines/vn/triggers/gregue_beforeInsert.sql new file mode 100644 index 000000000..76e178356 --- /dev/null +++ b/db/routines/vn/triggers/gregue_beforeInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`gregue_beforeInsert` + BEFORE INSERT ON `greuge` + FOR EACH ROW +BEGIN + IF NEW.userFk IS NULL THEN + SET NEW.userFk = account.myUser_getId(); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/greuge_afterDelete.sql b/db/routines/vn/triggers/greuge_afterDelete.sql new file mode 100644 index 000000000..947359b4c --- /dev/null +++ b/db/routines/vn/triggers/greuge_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`greuge_afterDelete` + AFTER DELETE ON `greuge` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Greuge', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/greuge_beforeInsert.sql b/db/routines/vn/triggers/greuge_beforeInsert.sql new file mode 100644 index 000000000..100f2f244 --- /dev/null +++ b/db/routines/vn/triggers/greuge_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`greuge_beforeInsert` + BEFORE INSERT ON `greuge` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/greuge_beforeUpdate.sql b/db/routines/vn/triggers/greuge_beforeUpdate.sql new file mode 100644 index 000000000..265861db5 --- /dev/null +++ b/db/routines/vn/triggers/greuge_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`greuge_beforeUpdate` + BEFORE UPDATE ON `greuge` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/host_beforeUpdate.sql b/db/routines/vn/triggers/host_beforeUpdate.sql new file mode 100644 index 000000000..0b0962e86 --- /dev/null +++ b/db/routines/vn/triggers/host_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`host_beforeUpdate` + BEFORE UPDATE ON `host` + FOR EACH ROW +BEGIN + SET new.updated = util.VN_NOW(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_afterDelete.sql b/db/routines/vn/triggers/invoiceInDueDay_afterDelete.sql new file mode 100644 index 000000000..1e5b75bb2 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInDueDay_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_afterDelete` + AFTER DELETE ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + INSERT INTO invoiceInLog + SET `action` = 'delete', + `changedModel` = 'InvoiceInDueDay', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql b/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql new file mode 100644 index 000000000..f7e4265a7 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInDueDay_beforeInsert.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_beforeInsert` + BEFORE INSERT ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + DECLARE vIsNotified BOOLEAN; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT isNotified INTO vIsNotified + FROM vn.invoiceIn ii + JOIN vn.supplier s ON s.id = ii.supplierFk + JOIN vn.payMethod pm ON pm.id = s.payMethodFk + WHERE ii.id = NEW.invoiceInFk; + + IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) + THEN + CALL mail_insert( + 'begonya@verdnatura.es', + 'begonya@verdnatura.es', + 'Añadido vencimiento en el pasado', + CONCAT( + account.myUser_getName(), ' ha añadido un vencimiento de ', + NEW.amount, '€ en una fecha pasada en la recibida ', NEW.invoiceInFk + ) + ); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInDueDay_beforeUpdate.sql b/db/routines/vn/triggers/invoiceInDueDay_beforeUpdate.sql new file mode 100644 index 000000000..2452ff0d1 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInDueDay_beforeUpdate.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInDueDay_beforeUpdate` + BEFORE UPDATE ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + DECLARE vIsNotified BOOLEAN; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT isNotified INTO vIsNotified + FROM vn.invoiceIn ii + JOIN vn.supplier s ON s.id = ii.supplierFk + JOIN vn.payMethod pm ON pm.id = s.payMethodFk + WHERE ii.id = NEW.invoiceInFk; + + IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) + THEN + CALL mail_insert( + 'begonya@verdnatura.es', + 'begonya@verdnatura.es', + 'Añadido vencimiento en el pasado', + CONCAT( + account.myUser_getName(), ' ha añadido un vencimiento de ', + NEW.amount,'€ en una fecha pasada en la recibida ',NEW.invoiceInFk + ) + ); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInTax_afterDelete.sql b/db/routines/vn/triggers/invoiceInTax_afterDelete.sql new file mode 100644 index 000000000..f541503ff --- /dev/null +++ b/db/routines/vn/triggers/invoiceInTax_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_afterDelete` + AFTER DELETE ON `invoiceInTax` + FOR EACH ROW +BEGIN + INSERT INTO invoiceInLog + SET `action` = 'delete', + `changedModel` = 'InvoiceInTax', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInTax_beforeInsert.sql b/db/routines/vn/triggers/invoiceInTax_beforeInsert.sql new file mode 100644 index 000000000..b1138fc3a --- /dev/null +++ b/db/routines/vn/triggers/invoiceInTax_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeInsert` + BEFORE INSERT ON `invoiceInTax` + FOR EACH ROW +BEGIN + CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql b/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql new file mode 100644 index 000000000..30918b7c5 --- /dev/null +++ b/db/routines/vn/triggers/invoiceInTax_beforeUpdate.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceInTax_beforeUpdate` + BEFORE UPDATE ON `invoiceInTax` + FOR EACH ROW +BEGIN + IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN + CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); + END IF; + + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceIn_afterDelete.sql b/db/routines/vn/triggers/invoiceIn_afterDelete.sql new file mode 100644 index 000000000..c088f6492 --- /dev/null +++ b/db/routines/vn/triggers/invoiceIn_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_afterDelete` + AFTER DELETE ON `invoiceIn` + FOR EACH ROW +BEGIN + INSERT INTO invoiceInLog + SET `action` = 'delete', + `changedModel` = 'InvoiceIn', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceIn_au.sql b/db/routines/vn/triggers/invoiceIn_au.sql new file mode 100644 index 000000000..b8e385c4b --- /dev/null +++ b/db/routines/vn/triggers/invoiceIn_au.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_au` + AFTER UPDATE ON `invoiceIn` + FOR EACH ROW +BEGIN + + IF NEW.issued != OLD.issued + OR NEW.currencyFk != OLD.currencyFk THEN + + UPDATE invoiceInTax iit + JOIN invoiceIn ii ON ii.id = iit.invoiceInFk + LEFT JOIN referenceRate rr ON rr.dated = ii.issued + AND rr.currencyFk = ii.currencyFk + SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value) + WHERE ii.id = NEW.id; + + UPDATE invoiceInDueDay iidd + JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk + LEFT JOIN referenceRate rr ON rr.dated = ii.issued + AND rr.currencyFk = ii.currencyFk + SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value) + WHERE ii.id = NEW.id; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceIn_bi.sql b/db/routines/vn/triggers/invoiceIn_bi.sql new file mode 100644 index 000000000..5baf75897 --- /dev/null +++ b/db/routines/vn/triggers/invoiceIn_bi.sql @@ -0,0 +1,52 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_bi` + BEFORE INSERT ON `invoiceIn` + FOR EACH ROW +BEGIN + DECLARE vSerie CHAR(1) DEFAULT 'R'; + DECLARE vNumReceived INT; + DECLARE vIssuingCountry, vhostCountry INT; + DECLARE vActive TINYINT; + DECLARE vWithholdingSageFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier + WHERE id = NEW.supplierFk; + + SET NEW.withholdingSageFk = vWithholdingSageFk; + + SELECT countryFk, isActive INTO vIssuingCountry, vActive + FROM vn.supplier + WHERE id = NEW.supplierFk; + + SELECT countryFk INTO vhostCountry + FROM vn.supplier + WHERE id = NEW.companyFk; + + IF vActive = 0 THEN + CALL util.throw('INACTIVE_PROVIDER'); + END IF; + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + ) THEN + CALL util.throw('reference duplicated'); + END IF; + + SELECT CASE WHEN (SELECT account FROM vn.supplier where id = NEW.supplierFk) LIKE '___3______' THEN 'C' + WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' + WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' + WHEN (SELECT vIssuingCountry<>vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' + END INTO vSerie; + + SET NEW.serial = IFNULL(vSerie,'R'); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceIn_bu.sql b/db/routines/vn/triggers/invoiceIn_bu.sql new file mode 100644 index 000000000..5fe54a518 --- /dev/null +++ b/db/routines/vn/triggers/invoiceIn_bu.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_bu` + BEFORE UPDATE ON `invoiceIn` + FOR EACH ROW +BEGIN + + DECLARE vWithholdingSageFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + AND id <> NEW.id + ) THEN + CALL util.throw('reference duplicated'); + END IF; + + IF NEW.supplierFk != OLD.supplierFk THEN + CALL supplier_checkIsActive(NEW.supplierFk); + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier + WHERE id = NEW.supplierFk; + SET NEW.withholdingSageFk = vWithholdingSageFk; + END IF; + +END$$ +DELIMITER ; diff --git a/db/.archive/231401/00-invoiceOutAfterInsert.sql b/db/routines/vn/triggers/invoiceOut_afterInsert.sql similarity index 51% rename from db/.archive/231401/00-invoiceOutAfterInsert.sql rename to db/routines/vn/triggers/invoiceOut_afterInsert.sql index adeaf9834..389c01111 100644 --- a/db/.archive/231401/00-invoiceOutAfterInsert.sql +++ b/db/routines/vn/triggers/invoiceOut_afterInsert.sql @@ -1,13 +1,8 @@ -DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`; -USE vn; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_afterInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_afterInsert` AFTER INSERT ON `invoiceOut` FOR EACH ROW BEGIN CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount); END$$ DELIMITER ; - diff --git a/db/routines/vn/triggers/invoiceOut_beforeDelete.sql b/db/routines/vn/triggers/invoiceOut_beforeDelete.sql new file mode 100644 index 000000000..8c8d7464c --- /dev/null +++ b/db/routines/vn/triggers/invoiceOut_beforeDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeDelete` + BEFORE DELETE ON `invoiceOut` + FOR EACH ROW +BEGIN + CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceOut_beforeInsert.sql b/db/routines/vn/triggers/invoiceOut_beforeInsert.sql new file mode 100644 index 000000000..159c98370 --- /dev/null +++ b/db/routines/vn/triggers/invoiceOut_beforeInsert.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeInsert` + BEFORE INSERT ON `invoiceOut` + FOR EACH ROW +BEGIN + DECLARE vRef CHAR(10) ; + + IF YEAR(NEW.issued) <= 2021 THEN + + SELECT CONCAT(NEW.serial, + IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , + RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 7,'0')) + 1) INTO vRef + FROM invoiceOut i + LEFT JOIN company c ON c.id = i.companyFk + WHERE i.serial = NEW.serial + AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) + AND c.id = NEW.companyFk; + ELSE + + SELECT CONCAT(NEW.serial, + IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , + RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 8,'0')) + 1) INTO vRef + FROM invoiceOut i + LEFT JOIN company c ON c.id = i.companyFk + WHERE i.serial = NEW.serial + AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) + AND c.id = NEW.companyFk; + END IF; + + SET NEW.ref = vRef; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/invoiceOut_beforeUpdate.sql b/db/routines/vn/triggers/invoiceOut_beforeUpdate.sql new file mode 100644 index 000000000..72be9cef0 --- /dev/null +++ b/db/routines/vn/triggers/invoiceOut_beforeUpdate.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeUpdate` + BEFORE UPDATE ON `invoiceOut` + FOR EACH ROW +BEGIN +CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount); +CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemBarcode_afterDelete.sql b/db/routines/vn/triggers/itemBarcode_afterDelete.sql new file mode 100644 index 000000000..4453d4a2f --- /dev/null +++ b/db/routines/vn/triggers/itemBarcode_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemBarcode_afterDelete` + AFTER DELETE ON `itemBarcode` + FOR EACH ROW +BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemBarcode', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemBarcode_beforeInsert.sql b/db/routines/vn/triggers/itemBarcode_beforeInsert.sql new file mode 100644 index 000000000..503f1eb8a --- /dev/null +++ b/db/routines/vn/triggers/itemBarcode_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemBarcode_beforeInsert` + BEFORE INSERT ON `itemBarcode` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemBarcode_beforeUpdate.sql b/db/routines/vn/triggers/itemBarcode_beforeUpdate.sql new file mode 100644 index 000000000..2131427b2 --- /dev/null +++ b/db/routines/vn/triggers/itemBarcode_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemBarcode_beforeUpdate` + BEFORE UPDATE ON `itemBarcode` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemBotanical_afterDelete.sql b/db/routines/vn/triggers/itemBotanical_afterDelete.sql new file mode 100644 index 000000000..1b3c50ad1 --- /dev/null +++ b/db/routines/vn/triggers/itemBotanical_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemBotanical_afterDelete` + AFTER DELETE ON `itemBotanical` + FOR EACH ROW +BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemBotanical', + `changedModelId` = OLD.itemFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemBotanical_beforeInsert.sql b/db/routines/vn/triggers/itemBotanical_beforeInsert.sql new file mode 100644 index 000000000..8a1b9346d --- /dev/null +++ b/db/routines/vn/triggers/itemBotanical_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemBotanical_beforeInsert` + BEFORE INSERT ON `itemBotanical` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemBotanical_beforeUpdate.sql b/db/routines/vn/triggers/itemBotanical_beforeUpdate.sql new file mode 100644 index 000000000..55939c403 --- /dev/null +++ b/db/routines/vn/triggers/itemBotanical_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemBotanical_beforeUpdate` + BEFORE UPDATE ON `itemBotanical` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql b/db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql new file mode 100644 index 000000000..82272126d --- /dev/null +++ b/db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemCategory_AFTER_INSERT` + AFTER INSERT ON `itemCategory` + FOR EACH ROW +BEGIN + CALL mail_insert('cau@verdnatura.es', + NULL, + CONCAT('Se ha añadido la familia: ', NEW.name), + 'Hay que añadir la familia en el formulario gastos'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemCost_beforeInsert.sql b/db/routines/vn/triggers/itemCost_beforeInsert.sql new file mode 100644 index 000000000..ba80193a6 --- /dev/null +++ b/db/routines/vn/triggers/itemCost_beforeInsert.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemCost_beforeInsert` + BEFORE INSERT ON `itemCost` + FOR EACH ROW +BEGIN + IF NEW.itemFk IN (95, 98) THEN + SET NEW.cm3 = 0; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemCost_beforeUpdate.sql b/db/routines/vn/triggers/itemCost_beforeUpdate.sql new file mode 100644 index 000000000..242c768f5 --- /dev/null +++ b/db/routines/vn/triggers/itemCost_beforeUpdate.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemCost_beforeUpdate` + BEFORE UPDATE ON `itemCost` + FOR EACH ROW +BEGIN + IF NEW.itemFk IN (95, 98) THEN + SET NEW.cm3 = 0; + END IF; + + IF !(NEW.cm3delivery <=> OLD.cm3delivery) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.itemCost ic + JOIN vn.sale s ON s.itemFk = ic.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk AND t.warehouseFk = ic.warehouseFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND ic.itemFk = NEW.itemFk + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + IF NEW.cm3Delivery = 0 AND NEW.warehouseFk = 60 THEN + CALL mail_insert( + 'jgallego@verdnatura.es', + NULL, + 'update cm3Delivery', + CONCAT('articulo: ', NEW.itemFk)); + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql b/db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql new file mode 100644 index 000000000..aca98dbef --- /dev/null +++ b/db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_AFTER_INSERT` + AFTER INSERT ON `itemShelvingSale` + FOR EACH ROW +BEGIN + + UPDATE vn.sale + SET isPicked = TRUE + WHERE id = NEW.saleFk; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql b/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql new file mode 100644 index 000000000..e9b4397ca --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT` + AFTER INSERT ON `itemShelving` + FOR EACH ROW +INSERT INTO vn.itemShelvingLog( itemShelvingFk, + workerFk, + accion, + itemFk, + shelvingFk, + visible, + `grouping`, + packing) + VALUES( NEW.id, + NEW.userFk, + 'CREA REGISTRO', + NEW.itemFk, + NEW.shelvingFk, + NEW.visible, + NEW.`grouping`, + NEW.packing + )$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql b/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql new file mode 100644 index 000000000..50a9c7d01 --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE` + AFTER UPDATE ON `itemShelving` + FOR EACH ROW +INSERT INTO itemShelvingLog + SET itemShelvingFk = NEW.id, + workerFk = account.myUser_getId(), + accion = 'CAMBIO', + itemFk = NEW.itemFk, + shelvingFk = NEW.shelvingFk, + visible = NEW.visible, + `grouping` = NEW.`grouping`, + packing = NEW.packing$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql b/db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql new file mode 100644 index 000000000..2018066c4 --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_DELETE` + BEFORE DELETE ON `itemShelving` + FOR EACH ROW +INSERT INTO vn.itemShelvingLog(itemShelvingFk, + workerFk, + accion, + shelvingFk, + itemFk) + VALUES( OLD.id, + account.myUser_getId(), + 'ELIMINADO', + OLD.shelvingFk, + OLD.itemFk)$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql b/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql new file mode 100644 index 000000000..3a3f5c41a --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_INSERT` + BEFORE INSERT ON `itemShelving` + FOR EACH ROW +BEGIN + + SET NEW.userFk = account.myUser_getId(); + + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql b/db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql new file mode 100644 index 000000000..6937eb1fd --- /dev/null +++ b/db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_UPDATE` + BEFORE UPDATE ON `itemShelving` + FOR EACH ROW +BEGIN + IF NEW.userFk IS NULL THEN + SET NEW.userFk = account.myUser_getId(); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTag_afterDelete.sql b/db/routines/vn/triggers/itemTag_afterDelete.sql new file mode 100644 index 000000000..4014c88b5 --- /dev/null +++ b/db/routines/vn/triggers/itemTag_afterDelete.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTag_afterDelete` + AFTER DELETE ON `itemTag` + FOR EACH ROW +trig: BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemTag', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL item_refreshFromTags(OLD.itemFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTag_afterInsert.sql b/db/routines/vn/triggers/itemTag_afterInsert.sql new file mode 100644 index 000000000..3dfb25ad3 --- /dev/null +++ b/db/routines/vn/triggers/itemTag_afterInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTag_afterInsert` + AFTER INSERT ON `itemTag` + FOR EACH ROW +trig: BEGIN + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL item_refreshFromTags(NEW.itemFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTag_afterUpdate.sql b/db/routines/vn/triggers/itemTag_afterUpdate.sql new file mode 100644 index 000000000..61b45a161 --- /dev/null +++ b/db/routines/vn/triggers/itemTag_afterUpdate.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTag_afterUpdate` + AFTER UPDATE ON `itemTag` + FOR EACH ROW +trig: BEGIN + DECLARE vItemFk INT; + DECLARE visTriggerDisabled BOOL; + + SELECT isItemTagTriggerDisabled INTO visTriggerDisabled + FROM vn.itemConfig; + + IF @isTriggerDisabled OR visTriggerDisabled THEN + LEAVE trig; + END IF; + + SET vItemFk = NEW.itemFk; + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + SELECT vItemFk id; + + CALL item_refreshTags(); + DROP TEMPORARY TABLE tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTag_beforeInsert.sql b/db/routines/vn/triggers/itemTag_beforeInsert.sql new file mode 100644 index 000000000..cec4fd02f --- /dev/null +++ b/db/routines/vn/triggers/itemTag_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTag_beforeInsert` + BEFORE INSERT ON `itemTag` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.intValue = itemTag_getIntValue(NEW.`value`); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTag_beforeUpdate.sql b/db/routines/vn/triggers/itemTag_beforeUpdate.sql new file mode 100644 index 000000000..41de249ef --- /dev/null +++ b/db/routines/vn/triggers/itemTag_beforeUpdate.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTag_beforeUpdate` + BEFORE UPDATE ON `itemTag` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF !(OLD.`value` <=> NEW.`value`) + OR !(OLD.intValue <=> NEW.intValue) THEN + SET NEW.intValue = itemTag_getIntValue(NEW.`value`); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTaxCountry_afterDelete.sql b/db/routines/vn/triggers/itemTaxCountry_afterDelete.sql new file mode 100644 index 000000000..8f91b26e1 --- /dev/null +++ b/db/routines/vn/triggers/itemTaxCountry_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTaxCountry_afterDelete` + AFTER DELETE ON `itemTaxCountry` + FOR EACH ROW +BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemTaxCountry', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTaxCountry_beforeInsert.sql b/db/routines/vn/triggers/itemTaxCountry_beforeInsert.sql new file mode 100644 index 000000000..348dac023 --- /dev/null +++ b/db/routines/vn/triggers/itemTaxCountry_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTaxCountry_beforeInsert` + BEFORE INSERT ON `itemTaxCountry` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemTaxCountry_beforeUpdate.sql b/db/routines/vn/triggers/itemTaxCountry_beforeUpdate.sql new file mode 100644 index 000000000..7470cd81e --- /dev/null +++ b/db/routines/vn/triggers/itemTaxCountry_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemTaxCountry_beforeUpdate` + BEFORE UPDATE ON `itemTaxCountry` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemType_beforeUpdate.sql b/db/routines/vn/triggers/itemType_beforeUpdate.sql new file mode 100644 index 000000000..0e0aa0098 --- /dev/null +++ b/db/routines/vn/triggers/itemType_beforeUpdate.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemType_beforeUpdate` + BEFORE UPDATE ON `itemType` + FOR EACH ROW +BEGIN + IF NEW.itemPackingTypeFk = '' THEN + + SET NEW.itemPackingTypeFk = NULL; + + END IF; + + IF NEW.itemPackingTypeFk != OLD.itemPackingTypeFk THEN + UPDATE vn.item + SET itemPackingTypeFk = NEW.itemPackingTypeFk + WHERE typeFk = NEW.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/item_afterDelete.sql b/db/routines/vn/triggers/item_afterDelete.sql new file mode 100644 index 000000000..34f702cdd --- /dev/null +++ b/db/routines/vn/triggers/item_afterDelete.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`item_afterDelete` + AFTER DELETE ON `item` + FOR EACH ROW +BEGIN + CALL hedera.image_unref('catalog', OLD.image); + + IF OLD.isFloramondo THEN + INSERT IGNORE edi.item_free + SET id = OLD.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/item_afterInsert.sql b/db/routines/vn/triggers/item_afterInsert.sql new file mode 100644 index 000000000..a4f9c5f5a --- /dev/null +++ b/db/routines/vn/triggers/item_afterInsert.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`item_afterInsert` + AFTER INSERT ON `item` + FOR EACH ROW +BEGIN + CALL hedera.image_ref('catalog', NEW.image); + + INSERT INTO vn.itemTaxCountry(itemFk, countryFk) VALUES + (NEW.id, 1), + (NEW.id, 5); + + DELETE ifr.* + FROM edi.item_free ifr + WHERE ifr.id = NEW.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/item_afterUpdate.sql b/db/routines/vn/triggers/item_afterUpdate.sql new file mode 100644 index 000000000..3b433c302 --- /dev/null +++ b/db/routines/vn/triggers/item_afterUpdate.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`item_afterUpdate` + AFTER UPDATE ON `item` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL hedera.image_unref('catalog', OLD.image); + CALL hedera.image_ref('catalog', NEW.image); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/item_beforeInsert.sql b/db/routines/vn/triggers/item_beforeInsert.sql new file mode 100644 index 000000000..d7ee4db34 --- /dev/null +++ b/db/routines/vn/triggers/item_beforeInsert.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`item_beforeInsert` + BEFORE INSERT ON `item` + FOR EACH ROW +BEGIN + DECLARE vItemPackingType VARCHAR(1); + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.itemPackingTypeFk IS NULL THEN + SELECT itemPackingTypeFk INTO vItemPackingType + FROM vn.itemType it + WHERE id = NEW.typeFk; + + SET NEW.itemPackingTypeFk = vItemPackingType; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/item_beforeUpdate.sql b/db/routines/vn/triggers/item_beforeUpdate.sql new file mode 100644 index 000000000..c7c8676de --- /dev/null +++ b/db/routines/vn/triggers/item_beforeUpdate.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`item_beforeUpdate` + BEFORE UPDATE ON `item` + FOR EACH ROW +BEGIN + DECLARE vNewPackingShelve INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF ISNULL(NEW.packingShelve) AND NOT ISNULL(NEW.packingOut) THEN + SELECT NEW.packingOut * vc.shelveVolume / vc.standardFlowerBox + INTO vNewPackingShelve + FROM vn.volumeConfig vc; + + SET NEW.packingShelve = vNewPackingShelve; + END IF; + + IF NEW.itemPackingTypeFk = '' THEN + SET NEW.itemPackingTypeFk = NULL; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/machine_BI.sql b/db/routines/vn/triggers/machine_BI.sql new file mode 100644 index 000000000..4b9210e65 --- /dev/null +++ b/db/routines/vn/triggers/machine_BI.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`machine_BI` + BEFORE INSERT ON `machine` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/mail_beforeInsert.sql b/db/routines/vn/triggers/mail_beforeInsert.sql new file mode 100644 index 000000000..fc598f829 --- /dev/null +++ b/db/routines/vn/triggers/mail_beforeInsert.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`mail_beforeInsert` + BEFORE INSERT ON `mail` + FOR EACH ROW +BEGIN + + IF NEW.sender IS NOT NULL THEN + + SET NEW.receiver = NEW.sender; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/mandate_beforeInsert.sql b/db/routines/vn/triggers/mandate_beforeInsert.sql new file mode 100644 index 000000000..7d1e9a59e --- /dev/null +++ b/db/routines/vn/triggers/mandate_beforeInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`mandate_beforeInsert` + BEFORE INSERT ON `mandate` + FOR EACH ROW +BEGIN + IF (NEW.code IS NULL) THEN + SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT + FROM information_schema.TABLES + WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/operator_beforeInsert.sql b/db/routines/vn/triggers/operator_beforeInsert.sql new file mode 100644 index 000000000..c1805d0fc --- /dev/null +++ b/db/routines/vn/triggers/operator_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`operator_beforeInsert` + BEFORE INSERT ON `operator` + FOR EACH ROW +BEGIN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/operator_beforeUpdate.sql b/db/routines/vn/triggers/operator_beforeUpdate.sql new file mode 100644 index 000000000..84fb8ca04 --- /dev/null +++ b/db/routines/vn/triggers/operator_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`operator_beforeUpdate` + BEFORE UPDATE ON `operator` + FOR EACH ROW +BEGIN + IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/packaging_beforeInsert.sql b/db/routines/vn/triggers/packaging_beforeInsert.sql new file mode 100644 index 000000000..02ba3cf4f --- /dev/null +++ b/db/routines/vn/triggers/packaging_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`packaging_beforeInsert` + BEFORE INSERT ON `packaging` + FOR EACH ROW +BEGIN + SET NEW.value = packaging_calculate(NEW.isPackageReturnable, NEW.packagingReturnFk, NEW.base, NEW.price, NEW.upload); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/packaging_beforeUpdate.sql b/db/routines/vn/triggers/packaging_beforeUpdate.sql new file mode 100644 index 000000000..515c94bb5 --- /dev/null +++ b/db/routines/vn/triggers/packaging_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`packaging_beforeUpdate` + BEFORE UPDATE ON `packaging` + FOR EACH ROW +BEGIN + SET NEW.value = packaging_calculate(NEW.isPackageReturnable, NEW.packagingReturnFk, NEW.base, NEW.price, NEW.upload); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/packingSite_afterDelete.sql b/db/routines/vn/triggers/packingSite_afterDelete.sql new file mode 100644 index 000000000..7c76ae7ec --- /dev/null +++ b/db/routines/vn/triggers/packingSite_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`packingSite_afterDelete` + AFTER DELETE ON `packingSite` + FOR EACH ROW +BEGIN + INSERT INTO packingSiteDeviceLog + SET `action` = 'delete', + `changedModel` = 'PackingSite', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/packingSite_beforeInsert.sql b/db/routines/vn/triggers/packingSite_beforeInsert.sql new file mode 100644 index 000000000..966dfdd53 --- /dev/null +++ b/db/routines/vn/triggers/packingSite_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`packingSite_beforeInsert` + BEFORE INSERT ON `packingSite` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/packingSite_beforeUpdate.sql b/db/routines/vn/triggers/packingSite_beforeUpdate.sql new file mode 100644 index 000000000..4d56ac1b5 --- /dev/null +++ b/db/routines/vn/triggers/packingSite_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`packingSite_beforeUpdate` + BEFORE UPDATE ON `packingSite` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/parking_BEFORE_INSERT.sql b/db/routines/vn/triggers/parking_BEFORE_INSERT.sql new file mode 100644 index 000000000..9ae2464cb --- /dev/null +++ b/db/routines/vn/triggers/parking_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`parking_BEFORE_INSERT` + BEFORE INSERT ON `parking` + FOR EACH ROW +BEGIN + + -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/parking_BEFORE_UPDATE.sql b/db/routines/vn/triggers/parking_BEFORE_UPDATE.sql new file mode 100644 index 000000000..bc2187c64 --- /dev/null +++ b/db/routines/vn/triggers/parking_BEFORE_UPDATE.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`parking_BEFORE_UPDATE` + BEFORE UPDATE ON `parking` + FOR EACH ROW +BEGIN + + -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/payment_afterInsert.sql b/db/routines/vn/triggers/payment_afterInsert.sql new file mode 100644 index 000000000..5585d6682 --- /dev/null +++ b/db/routines/vn/triggers/payment_afterInsert.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`payment_afterInsert` + AFTER INSERT ON `payment` + FOR EACH ROW +BEGIN + DECLARE vIsPayMethodChecked BOOLEAN; + DECLARE vEmail VARCHAR(150); + + SELECT isPayMethodChecked INTO vIsPayMethodChecked + FROM supplier + WHERE id = NEW.supplierFk; + + + IF vIsPayMethodChecked = FALSE THEN + + SELECT notificationEmail INTO vEmail + FROM department + WHERE name = 'FINANZAS'; + + CALL mail_insert( + vEmail, + NULL, + 'Pago con método sin verificar', + CONCAT( + 'Se ha realizado el pago ', + NEW.id, + ' al proveedor ', + NEW.supplierFk, + ' con el método de pago sin verificar.' + ) + ); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/payment_beforeInsert.sql b/db/routines/vn/triggers/payment_beforeInsert.sql new file mode 100644 index 000000000..6a28a1382 --- /dev/null +++ b/db/routines/vn/triggers/payment_beforeInsert.sql @@ -0,0 +1,94 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`payment_beforeInsert` + BEFORE INSERT ON `payment` + FOR EACH ROW +BEGIN + DECLARE cuenta_banco,cuenta_proveedor DOUBLE; + DECLARE vNewBookEntry INT; + DECLARE bolCASH BOOLEAN; + DECLARE isSupplierActive BOOLEAN; + + -- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH + SELECT (at2.code = 'cash') INTO bolCASH + FROM vn.bank b + JOIN vn.accountingType at2 ON at2.id = b.cash + WHERE b.id = NEW.bankFk; + + IF bolCASH THEN + + SELECT account INTO cuenta_banco + FROM bank + WHERE id = NEW.bankFk; + + SELECT account INTO cuenta_proveedor + FROM supplier + WHERE id = NEW.supplierFk; + + CALL vn.ledger_next(vNewBookEntry); + + INSERT INTO XDiario ( ASIEN, + FECHA, + SUBCTA, + CONTRA, + CONCEPTO, + EURODEBE, + EUROHABER, + empresa_id) + SELECT vNewBookEntry, + NEW.received, + SUBCTA, + CONTRA, + NEW.concept, + EURODEBE, + EUROHABER, + NEW.companyFk + FROM ( SELECT cuenta_banco SUBCTA, + cuenta_proveedor CONTRA, + 0 EURODEBE, + NEW.amount + NEW.bankingFees EUROHABER + UNION ALL + SELECT cuenta_proveedor SUBCTA, + cuenta_banco CONTRA, + NEW.amount EURODEBE, + 0 EUROHABER) gf; + + IF NEW.bankingFees <> 0 THEN + INSERT INTO XDiario ( ASIEN, + FECHA, + SUBCTA, + CONTRA, + CONCEPTO, + EURODEBE, + EUROHABER, + empresa_id) + SELECT vNewBookEntry, + NEW.received, + IF(c.id = 1,6260000002, + IF(CEE = 1,6260000003,6260000004)), + cuenta_banco, + NEW.concept, + NEW.bankingFees, + 0, + NEW.companyFk + FROM supplier s + JOIN country c ON s.countryFk = c.id + WHERE s.id = NEW.supplierFk; + END IF; + END IF; + + SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received); + + SELECT isActive INTO isSupplierActive + FROM supplier + WHERE id = NEW.supplierFk; + + IF isSupplierActive = FALSE THEN + CALL util.throw('SUPPLIER_INACTIVE'); + END IF; + + IF ISNULL(NEW.workerFk) THEN + SET NEW.workerFk = account.myUser_getId(); + END IF; + + END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/payment_beforeUpdate.sql b/db/routines/vn/triggers/payment_beforeUpdate.sql new file mode 100644 index 000000000..b3ef1342b --- /dev/null +++ b/db/routines/vn/triggers/payment_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`payment_beforeUpdate` + BEFORE UPDATE ON `payment` + FOR EACH ROW +BEGIN + IF ISNULL(NEW.workerFk) THEN + SET NEW.workerFk = account.myUser_getId(); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/postCode_afterDelete.sql b/db/routines/vn/triggers/postCode_afterDelete.sql new file mode 100644 index 000000000..736d5f5f3 --- /dev/null +++ b/db/routines/vn/triggers/postCode_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`postCode_afterDelete` + AFTER DELETE ON `postCode` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/postCode_afterUpdate.sql b/db/routines/vn/triggers/postCode_afterUpdate.sql new file mode 100644 index 000000000..c1e56044a --- /dev/null +++ b/db/routines/vn/triggers/postCode_afterUpdate.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`postCode_afterUpdate` + AFTER UPDATE ON `postCode` + FOR EACH ROW +BEGIN + IF !(OLD.townFk <=> NEW.townFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM town WHERE id = NEW.townFk)); + END IF; + + IF !(OLD.`code` <=> NEW.`code`) THEN + UPDATE zoneGeo SET `name` = NEW.`code` + WHERE id = NEW.geoFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/postCode_beforeInsert.sql b/db/routines/vn/triggers/postCode_beforeInsert.sql new file mode 100644 index 000000000..9e6d7e592 --- /dev/null +++ b/db/routines/vn/triggers/postCode_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`postCode_beforeInsert` + BEFORE INSERT ON `postCode` + FOR EACH ROW +BEGIN + SET NEW.geoFk = zoneGeo_new('postCode', NEW.`code`, + (SELECT geoFk FROM town WHERE id = NEW.townFk)); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/postCode_beforeUpdate.sql b/db/routines/vn/triggers/postCode_beforeUpdate.sql new file mode 100644 index 000000000..1b3c228a3 --- /dev/null +++ b/db/routines/vn/triggers/postCode_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`postCode_beforeUpdate` + BEFORE UPDATE ON `postCode` + FOR EACH ROW +BEGIN + -- IF !(OLD.geoFk <=> NEW.geoFk) THEN + -- CALL zoneGeo_throwNotEditable; + -- END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/priceFixed_beforeInsert.sql b/db/routines/vn/triggers/priceFixed_beforeInsert.sql new file mode 100644 index 000000000..ecf6f3e30 --- /dev/null +++ b/db/routines/vn/triggers/priceFixed_beforeInsert.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`priceFixed_beforeInsert` + BEFORE INSERT ON `priceFixed` + FOR EACH ROW +BEGIN + DECLARE vDated DATE; + IF NEW.started > NEW.ended THEN + SET vDated = NEW.started; + SET NEW.started = NEW.ended; + SET NEW.ended = vDated; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/priceFixed_beforeUpdate.sql b/db/routines/vn/triggers/priceFixed_beforeUpdate.sql new file mode 100644 index 000000000..f675322b9 --- /dev/null +++ b/db/routines/vn/triggers/priceFixed_beforeUpdate.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`priceFixed_beforeUpdate` + BEFORE UPDATE ON `priceFixed` + FOR EACH ROW +BEGIN + DECLARE vDated DATE; + IF NEW.started > NEW.ended THEN + SET vDated = NEW.started; + SET NEW.started = NEW.ended; + SET NEW.ended = vDated; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/projectNotes_BeforeInsert.sql b/db/routines/vn/triggers/projectNotes_BeforeInsert.sql new file mode 100644 index 000000000..8b6424ef0 --- /dev/null +++ b/db/routines/vn/triggers/projectNotes_BeforeInsert.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`projectNotes_BeforeInsert` + BEFORE INSERT ON `projectNotes` + FOR EACH ROW +BEGIN + + IF ISNULL(NEW.userFk) THEN + + SET NEW.userFk = account.myUser_getId(); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/province_afterDelete.sql b/db/routines/vn/triggers/province_afterDelete.sql new file mode 100644 index 000000000..d0cee78e7 --- /dev/null +++ b/db/routines/vn/triggers/province_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`province_afterDelete` + AFTER DELETE ON `province` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/province_afterUpdate.sql b/db/routines/vn/triggers/province_afterUpdate.sql new file mode 100644 index 000000000..e8f3958b2 --- /dev/null +++ b/db/routines/vn/triggers/province_afterUpdate.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`province_afterUpdate` + AFTER UPDATE ON `province` + FOR EACH ROW +BEGIN + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/province_beforeInsert.sql b/db/routines/vn/triggers/province_beforeInsert.sql new file mode 100644 index 000000000..f3f039fc3 --- /dev/null +++ b/db/routines/vn/triggers/province_beforeInsert.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`province_beforeInsert` + BEFORE INSERT ON `province` + FOR EACH ROW +BEGIN + + SET NEW.geoFk = zoneGeo_new('province', NEW.`name`, + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/province_beforeUpdate.sql b/db/routines/vn/triggers/province_beforeUpdate.sql new file mode 100644 index 000000000..23ca49d4a --- /dev/null +++ b/db/routines/vn/triggers/province_beforeUpdate.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`province_beforeUpdate` + BEFORE UPDATE ON `province` + FOR EACH ROW +BEGIN + + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/rate_afterDelete.sql b/db/routines/vn/triggers/rate_afterDelete.sql new file mode 100644 index 000000000..dae240c15 --- /dev/null +++ b/db/routines/vn/triggers/rate_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`rate_afterDelete` + AFTER DELETE ON `rate` + FOR EACH ROW +BEGIN + INSERT INTO rateLog + SET `action` = 'delete', + `changedModel` = 'Rate', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/rate_beforeInsert.sql b/db/routines/vn/triggers/rate_beforeInsert.sql new file mode 100644 index 000000000..0d77a95d7 --- /dev/null +++ b/db/routines/vn/triggers/rate_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`rate_beforeInsert` + BEFORE INSERT ON `rate` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/rate_beforeUpdate.sql b/db/routines/vn/triggers/rate_beforeUpdate.sql new file mode 100644 index 000000000..2055d14fd --- /dev/null +++ b/db/routines/vn/triggers/rate_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`rate_beforeUpdate` + BEFORE UPDATE ON `rate` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/receipt_afterInsert.sql b/db/routines/vn/triggers/receipt_afterInsert.sql new file mode 100644 index 000000000..3881cb4d2 --- /dev/null +++ b/db/routines/vn/triggers/receipt_afterInsert.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`receipt_afterInsert` + AFTER INSERT ON `receipt` + FOR EACH ROW +CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid)$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/receipt_afterUpdate.sql b/db/routines/vn/triggers/receipt_afterUpdate.sql new file mode 100644 index 000000000..3d739e8f1 --- /dev/null +++ b/db/routines/vn/triggers/receipt_afterUpdate.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`receipt_afterUpdate` + AFTER UPDATE ON `receipt` + FOR EACH ROW +BEGIN + IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN + CALL mail_insert( + 'finanzas@verdnatura.es', + NULL, + CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), + CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) + ); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/receipt_beforeDelete.sql b/db/routines/vn/triggers/receipt_beforeDelete.sql new file mode 100644 index 000000000..fc75a4c35 --- /dev/null +++ b/db/routines/vn/triggers/receipt_beforeDelete.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`receipt_beforeDelete` + BEFORE DELETE ON `receipt` + FOR EACH ROW +CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid)$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/receipt_beforeInsert.sql b/db/routines/vn/triggers/receipt_beforeInsert.sql new file mode 100644 index 000000000..696cad241 --- /dev/null +++ b/db/routines/vn/triggers/receipt_beforeInsert.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`receipt_beforeInsert` + BEFORE INSERT ON `receipt` + FOR EACH ROW +BEGIN + DECLARE vIsAutoConciliated BOOLEAN; + + IF NEW.isConciliate = FALSE THEN + SELECT isAutoConciliated INTO vIsAutoConciliated + FROM accounting a + JOIN accountingType at2 ON at2.id = a.accountingTypeFk + WHERE a.id = NEW.bankFk; + + SET NEW.isConciliate = vIsAutoConciliated; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/receipt_beforeUpdate.sql b/db/routines/vn/triggers/receipt_beforeUpdate.sql new file mode 100644 index 000000000..8ea14c17c --- /dev/null +++ b/db/routines/vn/triggers/receipt_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`receipt_beforeUpdate` + BEFORE UPDATE ON `receipt` + FOR EACH ROW +BEGIN + CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid); + CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid); + SET NEW.workerFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/recovery_afterDelete.sql b/db/routines/vn/triggers/recovery_afterDelete.sql new file mode 100644 index 000000000..429f562ac --- /dev/null +++ b/db/routines/vn/triggers/recovery_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`recovery_afterDelete` + AFTER DELETE ON `recovery` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Recovery', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/recovery_beforeInsert.sql b/db/routines/vn/triggers/recovery_beforeInsert.sql new file mode 100644 index 000000000..2318e0b7b --- /dev/null +++ b/db/routines/vn/triggers/recovery_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`recovery_beforeInsert` + BEFORE INSERT ON `recovery` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/recovery_beforeUpdate.sql b/db/routines/vn/triggers/recovery_beforeUpdate.sql new file mode 100644 index 000000000..4d485c075 --- /dev/null +++ b/db/routines/vn/triggers/recovery_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`recovery_beforeUpdate` + BEFORE UPDATE ON `recovery` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/route_afterDelete.sql b/db/routines/vn/triggers/route_afterDelete.sql new file mode 100644 index 000000000..e929bd519 --- /dev/null +++ b/db/routines/vn/triggers/route_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`route_afterDelete` + AFTER DELETE ON `route` + FOR EACH ROW +BEGIN + INSERT INTO routeLog + SET `action` = 'delete', + `changedModel` = 'Route', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/route_afterInsert.sql b/db/routines/vn/triggers/route_afterInsert.sql new file mode 100644 index 000000000..f030f09fa --- /dev/null +++ b/db/routines/vn/triggers/route_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`route_afterInsert` + AFTER INSERT ON `route` + FOR EACH ROW +BEGIN + CALL route_calcCommission(NEW.id); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/route_afterUpdate.sql b/db/routines/vn/triggers/route_afterUpdate.sql new file mode 100644 index 000000000..14b53c2a5 --- /dev/null +++ b/db/routines/vn/triggers/route_afterUpdate.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`route_afterUpdate` + AFTER UPDATE ON `route` + FOR EACH ROW +BEGIN + IF IFNULL(NEW.gestdocFk,0) <> IFNULL(OLD.gestdocFk,0) AND NEW.gestdocFk > 0 THEN + -- JGF 09/09/14 cuando se añade un gestdoc a una ruta, se le asigna automagicamente a todos sus Tickets + + -- Inserta el gestdoc en todos los tickets de la ruta + INSERT INTO ticketDms(ticketFk,dmsFk) + SELECT id, NEW.gestdocFk FROM ticket WHERE routeFk = NEW.id + ON DUPLICATE KEY UPDATE dmsFk = NEW.gestdocFk; + + -- Update del firmado + UPDATE ticket t + JOIN ticketDms tg ON t.id = tg.ticketFk + SET isSigned = 1 WHERE t.routeFk = NEW.id; + END IF; + + IF !(NEW.kmStart <=> OLD.kmStart) + OR !(NEW.kmEnd <=> OLD.kmEnd) + OR !(NEW.workerFk <=> OLD.workerFk) + OR !(NEW.m3 <=> OLD.m3) + OR !(NEW.agencyModeFk <=> OLD.agencyModeFk)THEN + CALL route_calcCommission(NEW.id); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/route_beforeInsert.sql b/db/routines/vn/triggers/route_beforeInsert.sql new file mode 100644 index 000000000..442b0620e --- /dev/null +++ b/db/routines/vn/triggers/route_beforeInsert.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`route_beforeInsert` + BEFORE INSERT ON `route` + FOR EACH ROW +BEGIN + DECLARE vDefaultAgencyModeFk INT; + DECLARE vUserFk INT ; + + SET vUserFk = account.myUser_getId(); + SET NEW.editorFk = vUserFk; + SET NEW.firstEditorFk = vUserFk; + + SET NEW.commissionWorkCenterFk = ( + SELECT IFNULL(b.workCenterFK, r.defaultWorkCenterFk) + FROM vn.routeConfig r + LEFT JOIN vn.business b ON b.workerFk = vUserFk + AND NEW.created BETWEEN b.started AND IFNULL(b.ended, NEW.created)); + + IF ISNULL(NEW.agencyModeFk) THEN + SELECT r.agencyModeFk INTO vDefaultAgencyModeFk + FROM routeDefaultAgencyMode r + JOIN business b ON b.workCenterFk = r.workCenterFK + JOIN worker w ON w.businessFk = b.id + WHERE b.workerFk = vUserFk; + + SET NEW.agencyModeFk = vDefaultAgencyModeFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/route_beforeUpdate.sql b/db/routines/vn/triggers/route_beforeUpdate.sql new file mode 100644 index 000000000..43ee802f5 --- /dev/null +++ b/db/routines/vn/triggers/route_beforeUpdate.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`route_beforeUpdate` + BEFORE UPDATE ON `route` + FOR EACH ROW +BEGIN + DECLARE vKmMax INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.isOk <> FALSE AND OLD.isOk = FALSE THEN + SET NEW.m3 = ( SELECT SUM(litros)/1000 + FROM vn.saleVolume s + JOIN vn.ticket t ON s.ticketFk = t.id + WHERE t.routeFk = NEW.id); + END IF; + + IF NEW.kmEnd < NEW.kmStart AND NEW.kmEnd <> 0 THEN + CALL util.throw ('KmEnd menor que kmStart'); + END IF; + + SELECT kmMax INTO vKmMax + FROM routeConfig rc; + + IF ((NEW.kmEnd - NEW.kmStart) > vKmMax) AND NEW.kmEnd <> 0 THEN + CALL util.throw (CONCAT('The km can not exceed ', vKmMax)); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/routesMonitor_afterDelete.sql b/db/routines/vn/triggers/routesMonitor_afterDelete.sql new file mode 100644 index 000000000..000425dad --- /dev/null +++ b/db/routines/vn/triggers/routesMonitor_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`routesMonitor_afterDelete` + AFTER DELETE ON `routesMonitor` + FOR EACH ROW +BEGIN + INSERT INTO routeLog + SET `action` = 'delete', + `changedModel` = 'RoutesMonitor', + `changedModelId` = OLD.routeFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/routesMonitor_beforeInsert.sql b/db/routines/vn/triggers/routesMonitor_beforeInsert.sql new file mode 100644 index 000000000..70b723d54 --- /dev/null +++ b/db/routines/vn/triggers/routesMonitor_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`routesMonitor_beforeInsert` + BEFORE INSERT ON `routesMonitor` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/routesMonitor_beforeUpdate.sql b/db/routines/vn/triggers/routesMonitor_beforeUpdate.sql new file mode 100644 index 000000000..0ca867b7a --- /dev/null +++ b/db/routines/vn/triggers/routesMonitor_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`routesMonitor_beforeUpdate` + BEFORE UPDATE ON `routesMonitor` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleBuy_AI.sql b/db/routines/vn/triggers/saleBuy_AI.sql new file mode 100644 index 000000000..3186a0ec7 --- /dev/null +++ b/db/routines/vn/triggers/saleBuy_AI.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleBuy_AI` + AFTER INSERT ON `saleBuy` + FOR EACH ROW +BEGIN +/* Activar de nuevo cuando volvamos a vender fruta y verdura + * + UPDATE vn.sale s + SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk) + WHERE s.id = NEW.saleFk; +*/ +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleTracking_After_Insert.sql b/db/routines/vn/triggers/saleTracking_After_Insert.sql new file mode 100644 index 000000000..861428f19 --- /dev/null +++ b/db/routines/vn/triggers/saleTracking_After_Insert.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleTracking_After_Insert` + AFTER INSERT ON `saleTracking` + FOR EACH ROW +BEGIN + + IF NEW.isChecked THEN + + UPDATE vn.sale s + SET s.isPicked = TRUE + WHERE s.id = NEW.saleFk + AND s.isPicked = 0; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sale_BEFORE_DELETE.sql b/db/routines/vn/triggers/sale_BEFORE_DELETE.sql new file mode 100644 index 000000000..724f65262 --- /dev/null +++ b/db/routines/vn/triggers/sale_BEFORE_DELETE.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_BEFORE_DELETE` + BEFORE DELETE ON `sale` + FOR EACH ROW +BEGIN + IF OLD.quantity > 0 THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = OLD.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sale_afterDelete.sql b/db/routines/vn/triggers/sale_afterDelete.sql new file mode 100644 index 000000000..fab1c52cd --- /dev/null +++ b/db/routines/vn/triggers/sale_afterDelete.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_afterDelete` + AFTER DELETE ON `sale` + FOR EACH ROW +BEGIN + DECLARE vIsToSendMail BOOL; + DECLARE vUserRole VARCHAR(255); + + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'Sale', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL stock.log_add('sale', NULL, OLD.id); + CALL ticket_requestRecalc(OLD.ticketFk); + + SELECT account.myUser_getName() INTO vUserRole; + SELECT account.user_getMysqlRole(vUserRole) INTO vUserRole; + + SELECT COUNT(*) INTO vIsToSendMail + FROM ticketTracking tt + JOIN vn.state s ON s.id = tt.stateFk + WHERE s.code='PACKED' + AND tt.ticketFk = OLD.ticketFk + AND vUserRole IN ('salesPerson', 'salesBoss') + LIMIT 1; + + IF vIsToSendMail THEN + CALL vn.mail_insert('jefesventas@verdnatura.es', + 'noreply@verdnatura.es', + CONCAT('Ticket ', OLD.ticketFk ,' eliminado artículo tras encajado' ), + CONCAT('Ticket ', OLD.ticketFk ,'.
', + 'Eliminado artículo ', OLD.itemFk, ' tras estado encajado del ticket.
Este email se ha generado automáticamente' ) + ); + END IF; + + IF OLD.quantity > 0 THEN + UPDATE vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = OLD.ticketFk + JOIN vn.item i ON i.id = OLD.itemFk + AND (c.itemPackingTypeFk = i.itemPackingTypeFk + OR ISNULL(c.itemPackingTypeFk)) + SET c.saleTotalCount = c.saleTotalCount - 1, + c.salePickedCount = c.salePickedCount - ABS(OLD.isPicked); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sale_afterInsert.sql b/db/routines/vn/triggers/sale_afterInsert.sql new file mode 100644 index 000000000..d4c2d60f5 --- /dev/null +++ b/db/routines/vn/triggers/sale_afterInsert.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_afterInsert` + AFTER INSERT ON `sale` + FOR EACH ROW +BEGIN + IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN + CALL util.throw('Cannot insert a service item into a ticket'); + END IF; + + CALL stock.log_add('sale', NEW.id, NULL); + CALL ticket_requestRecalc(NEW.ticketFk); + + IF NEW.quantity > 0 THEN + + UPDATE vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id + AND tc.ticketFk = NEW.ticketFk + JOIN vn.item i ON i.id = NEW.itemFk + AND (c.itemPackingTypeFk = i.itemPackingTypeFk + OR c.itemPackingTypeFk IS NULL) + SET c.saleTotalCount = c.saleTotalCount + 1; + + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = NEW.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/.archive/224701/00-sale_afterUpdate.sql b/db/routines/vn/triggers/sale_afterUpdate.sql similarity index 83% rename from db/.archive/224701/00-sale_afterUpdate.sql rename to db/routines/vn/triggers/sale_afterUpdate.sql index 407fb52c9..0d21f08d7 100644 --- a/db/.archive/224701/00-sale_afterUpdate.sql +++ b/db/routines/vn/triggers/sale_afterUpdate.sql @@ -1,17 +1,11 @@ -DROP TRIGGER IF EXISTS vn.sale_afterUpdate; -USE vn; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_afterUpdate` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_afterUpdate` AFTER UPDATE ON `sale` FOR EACH ROW BEGIN DECLARE vIsToSendMail BOOL; - DECLARE vPickedLines INT; - DECLARE vCollectionFk INT; DECLARE vUserRole VARCHAR(255); - + IF !(NEW.id <=> OLD.id) OR !(NEW.ticketFk <=> OLD.ticketFk) OR !(NEW.itemFk <=> OLD.itemFk) @@ -34,64 +28,61 @@ BEGIN UPDATE ticketRequest SET ticketFk = NEW.ticketFk WHERE saleFk = NEW.id; END IF; - + SELECT account.myUser_getName() INTO vUserRole; SELECT account.user_getMysqlRole(vUserRole) INTO vUserRole; IF !(OLD.quantity <=> NEW.quantity) THEN - SELECT COUNT(*) INTO vIsToSendMail - FROM vncontrol.inter i - JOIN vn.state s ON s.id = i.state_id - WHERE s.code='PACKED' - AND i.Id_Ticket = OLD.ticketFk + SELECT COUNT(*) INTO vIsToSendMail + FROM ticketTracking tt + JOIN vn.state s ON s.id = tt.stateFk + WHERE s.code='PACKED' + AND tt.ticketFk = OLD.ticketFk AND vUserRole IN ('salesPerson', 'salesTeamBoss') LIMIT 1; - - IF vIsToSendMail THEN + + IF vIsToSendMail THEN CALL vn.mail_insert('jefesventas@verdnatura.es', 'noreply@verdnatura.es', CONCAT('Ticket ', OLD.ticketFk ,' modificada cantidad tras encajado'), CONCAT('Ticket ', OLD.ticketFk ,'.
', - 'Modificada la catidad de ', OLD.quantity, ' a ' , NEW.quantity, + 'Modificada la catidad de ', OLD.quantity, ' a ' , NEW.quantity, ' del artículo ', OLD.itemFk, ' tras estado encajado del ticket.
', 'Este email se ha generado automáticamente' ) ); - END IF; + END IF; IF (OLD.quantity > NEW.quantity) THEN INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT NEW.id, cm.id, sc.value + SELECT NEW.id, cm.id, sc.value FROM saleComponent sc JOIN component cd ON cd.id = sc.componentFk JOIN component cm ON cm.code = 'mana' WHERE saleFk = NEW.id AND cd.code = 'lastUnitsDiscount' ON DUPLICATE KEY UPDATE value = sc.value + VALUES(value); - - DELETE sc.* + + DELETE sc.* FROM vn.saleComponent sc JOIN component c ON c.id = sc.componentFk WHERE saleFk = NEW.id AND c.code = 'lastUnitsDiscount'; - END IF; + END IF; INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id + SELECT r.id FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE + WHERE r.isOk = FALSE AND s.id = NEW.id - AND r.created >= CURDATE() + AND r.created >= util.VN_CURDATE() GROUP BY r.id; END IF; IF !(ABS(NEW.isPicked) <=> ABS(OLD.isPicked)) AND NEW.quantity > 0 THEN - UPDATE vn.collection c JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk SET c.salePickedCount = c.salePickedCount + IF(NEW.isPicked != 0, 1, -1); - END IF; IF !(NEW.quantity <=> OLD.quantity) AND (NEW.quantity = 0 OR OLD.quantity = 0) THEN - UPDATE vn.collection c JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk SET c.saleTotalCount = c.saleTotalCount + IF(OLD.quantity = 0, 1, -1); diff --git a/db/routines/vn/triggers/sale_beforeInsert.sql b/db/routines/vn/triggers/sale_beforeInsert.sql new file mode 100644 index 000000000..0ef368513 --- /dev/null +++ b/db/routines/vn/triggers/sale_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_beforeInsert` + BEFORE INSERT ON `sale` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.originalQuantity = NEW.quantity; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sale_beforeUpdate.sql b/db/routines/vn/triggers/sale_beforeUpdate.sql new file mode 100644 index 000000000..c5a748503 --- /dev/null +++ b/db/routines/vn/triggers/sale_beforeUpdate.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_beforeUpdate` + BEFORE UPDATE ON `sale` + FOR EACH ROW +BEGIN +/* + IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN + CALL util.throw('Cannot insert a service item into a ticket'); + END IF; +*/ + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.discount > 100 THEN + SET NEW.discount = 0; + END IF; + + IF old.discount > 0 AND NEW.discount = 0 THEN + INSERT INTO ticketLog + SET originFk = NEW.ticketFk, userFk = account.myUser_getId(), `action` = 'insert', + description = CONCAT('Cambio de descuento del item :', ' ', new.itemFk, ' de ', old.discount ,' a 0 '); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sharingCart_beforeDelete.sql b/db/routines/vn/triggers/sharingCart_beforeDelete.sql new file mode 100644 index 000000000..6996b3138 --- /dev/null +++ b/db/routines/vn/triggers/sharingCart_beforeDelete.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sharingCart_beforeDelete` + BEFORE DELETE ON `sharingCart` + FOR EACH ROW +BEGIN + DELETE sc FROM sharingCartDaily sc + WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND + sc.ownerFk = OLD.workerFk AND + sc.substituteFk = OLD.workerSubstitute; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sharingCart_beforeInsert.sql b/db/routines/vn/triggers/sharingCart_beforeInsert.sql new file mode 100644 index 000000000..116337b62 --- /dev/null +++ b/db/routines/vn/triggers/sharingCart_beforeInsert.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sharingCart_beforeInsert` + BEFORE INSERT ON `sharingCart` + FOR EACH ROW +BEGIN + IF NEW.workerFk = NEW.workerSubstitute THEN + CALL util.throw ('worker and workerSubstitute must be different'); + ELSE + INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) + SELECT NEW.workerFk, NEW.workerSubstitute, dated + FROM time + WHERE dated BETWEEN NEW.started AND NEW.ended; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sharingCart_beforeUpdate.sql b/db/routines/vn/triggers/sharingCart_beforeUpdate.sql new file mode 100644 index 000000000..91cbfb3d0 --- /dev/null +++ b/db/routines/vn/triggers/sharingCart_beforeUpdate.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sharingCart_beforeUpdate` + BEFORE UPDATE ON `sharingCart` + FOR EACH ROW +BEGIN + IF NEW.workerFk = NEW.workerSubstitute THEN + CALL util.throw ('worker and workerSubstitute must be different'); + ELSE + DELETE sc FROM sharingCartDaily sc + WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND + sc.ownerFk = OLD.workerFk AND + sc.substituteFk = OLD.workerSubstitute; + + INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) + SELECT NEW.workerFk, NEW.workerSubstitute, dated + FROM time + WHERE dated BETWEEN NEW.started AND NEW.ended; + + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sharingClient_beforeInsert.sql b/db/routines/vn/triggers/sharingClient_beforeInsert.sql new file mode 100644 index 000000000..eea65e74c --- /dev/null +++ b/db/routines/vn/triggers/sharingClient_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sharingClient_beforeInsert` + BEFORE INSERT ON `sharingClient` + FOR EACH ROW +BEGIN + SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); + SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/sharingClient_beforeUpdate.sql b/db/routines/vn/triggers/sharingClient_beforeUpdate.sql new file mode 100644 index 000000000..fceab691c --- /dev/null +++ b/db/routines/vn/triggers/sharingClient_beforeUpdate.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sharingClient_beforeUpdate` + BEFORE UPDATE ON `sharingClient` + FOR EACH ROW +BEGIN + SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); + SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql b/db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql new file mode 100644 index 000000000..770e2a495 --- /dev/null +++ b/db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`shelving_BEFORE_UPDATE` + BEFORE UPDATE ON `shelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.code = "" THEN + CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); + END IF; + + IF NOT(OLD.parkingFk <=> NEW.parkingFK) THEN + SET NEW.isMoving = FALSE; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/shelving_afterDelete.sql b/db/routines/vn/triggers/shelving_afterDelete.sql new file mode 100644 index 000000000..964a866e7 --- /dev/null +++ b/db/routines/vn/triggers/shelving_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`shelving_afterDelete` + AFTER DELETE ON `shelving` + FOR EACH ROW +BEGIN + INSERT INTO shelvingLog + SET `action` = 'delete', + `changedModel` = 'Shelving', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/shelving_beforeInsert.sql b/db/routines/vn/triggers/shelving_beforeInsert.sql new file mode 100644 index 000000000..ef3c7030c --- /dev/null +++ b/db/routines/vn/triggers/shelving_beforeInsert.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`shelving_beforeInsert` + BEFORE INSERT ON `shelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.code = "" THEN + CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql b/db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql new file mode 100644 index 000000000..a35635e43 --- /dev/null +++ b/db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_AFTER_INSERT` + AFTER INSERT ON `solunionCAP` + FOR EACH ROW +BEGIN + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql b/db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql new file mode 100644 index 000000000..91ea1b4ba --- /dev/null +++ b/db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_AFTER_UPDATE` + AFTER UPDATE ON `solunionCAP` + FOR EACH ROW +BEGIN + IF NEW.dateLeaving IS NOT NULL THEN + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; + ELSE + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql b/db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql new file mode 100644 index 000000000..590a38734 --- /dev/null +++ b/db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_BEFORE_DELETE` + BEFORE DELETE ON `solunionCAP` + FOR EACH ROW +BEGIN + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/specie_BEFORE_INSERT.sql b/db/routines/vn/triggers/specie_BEFORE_INSERT.sql new file mode 100644 index 000000000..2b5fd85d6 --- /dev/null +++ b/db/routines/vn/triggers/specie_BEFORE_INSERT.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`specie_BEFORE_INSERT` + BEFORE INSERT ON `specie` + FOR EACH ROW +BEGIN + SET NEW.name = LCASE(NEW.name); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/specie_BEFORE_UPDATE.sql b/db/routines/vn/triggers/specie_BEFORE_UPDATE.sql new file mode 100644 index 000000000..d451c5a8f --- /dev/null +++ b/db/routines/vn/triggers/specie_BEFORE_UPDATE.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`specie_BEFORE_UPDATE` + BEFORE UPDATE ON `specie` + FOR EACH ROW +BEGIN + SET NEW.name = LCASE(NEW.name); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierAccount_afterDelete.sql b/db/routines/vn/triggers/supplierAccount_afterDelete.sql new file mode 100644 index 000000000..23c2cd4a4 --- /dev/null +++ b/db/routines/vn/triggers/supplierAccount_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierAccount_afterDelete` + AFTER DELETE ON `supplierAccount` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'SupplierAccount', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierAccount_beforeInsert.sql b/db/routines/vn/triggers/supplierAccount_beforeInsert.sql new file mode 100644 index 000000000..512f172e1 --- /dev/null +++ b/db/routines/vn/triggers/supplierAccount_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierAccount_beforeInsert` + BEFORE INSERT ON `supplierAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierAccount_beforeUpdate.sql b/db/routines/vn/triggers/supplierAccount_beforeUpdate.sql new file mode 100644 index 000000000..0fac19deb --- /dev/null +++ b/db/routines/vn/triggers/supplierAccount_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierAccount_beforeUpdate` + BEFORE UPDATE ON `supplierAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierAddress_afterDelete.sql b/db/routines/vn/triggers/supplierAddress_afterDelete.sql new file mode 100644 index 000000000..69dd94dfe --- /dev/null +++ b/db/routines/vn/triggers/supplierAddress_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierAddress_afterDelete` + AFTER DELETE ON `supplierAddress` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'SupplierAddress', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierAddress_beforeInsert.sql b/db/routines/vn/triggers/supplierAddress_beforeInsert.sql new file mode 100644 index 000000000..db8d0ea94 --- /dev/null +++ b/db/routines/vn/triggers/supplierAddress_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierAddress_beforeInsert` + BEFORE INSERT ON `supplierAddress` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierAddress_beforeUpdate.sql b/db/routines/vn/triggers/supplierAddress_beforeUpdate.sql new file mode 100644 index 000000000..8e484e4de --- /dev/null +++ b/db/routines/vn/triggers/supplierAddress_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierAddress_beforeUpdate` + BEFORE UPDATE ON `supplierAddress` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierContact_afterDelete.sql b/db/routines/vn/triggers/supplierContact_afterDelete.sql new file mode 100644 index 000000000..401ec9e9e --- /dev/null +++ b/db/routines/vn/triggers/supplierContact_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierContact_afterDelete` + AFTER DELETE ON `supplierContact` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'SupplierContact', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierContact_beforeInsert.sql b/db/routines/vn/triggers/supplierContact_beforeInsert.sql new file mode 100644 index 000000000..76e78ba5a --- /dev/null +++ b/db/routines/vn/triggers/supplierContact_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierContact_beforeInsert` + BEFORE INSERT ON `supplierContact` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplierContact_beforeUpdate.sql b/db/routines/vn/triggers/supplierContact_beforeUpdate.sql new file mode 100644 index 000000000..24723656a --- /dev/null +++ b/db/routines/vn/triggers/supplierContact_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplierContact_beforeUpdate` + BEFORE UPDATE ON `supplierContact` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplier_afterDelete.sql b/db/routines/vn/triggers/supplier_afterDelete.sql new file mode 100644 index 000000000..d4b8e0d21 --- /dev/null +++ b/db/routines/vn/triggers/supplier_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_afterDelete` + AFTER DELETE ON `supplier` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'Supplier', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/supplier_beforeInsert.sql b/db/routines/vn/triggers/supplier_beforeInsert.sql new file mode 100644 index 000000000..aef8d02ab --- /dev/null +++ b/db/routines/vn/triggers/supplier_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_beforeInsert` + BEFORE INSERT ON `supplier` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/.archive/225201/00-supplier_beforeUpdate.sql b/db/routines/vn/triggers/supplier_beforeUpdate.sql similarity index 88% rename from db/.archive/225201/00-supplier_beforeUpdate.sql rename to db/routines/vn/triggers/supplier_beforeUpdate.sql index 08af8666b..f462d6f57 100644 --- a/db/.archive/225201/00-supplier_beforeUpdate.sql +++ b/db/routines/vn/triggers/supplier_beforeUpdate.sql @@ -1,9 +1,5 @@ -DROP TRIGGER IF EXISTS `vn`.`supplier_beforeUpdate`; -USE `vn`; - DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`supplier_beforeUpdate` BEFORE UPDATE ON `supplier` FOR EACH ROW BEGIN @@ -14,6 +10,8 @@ BEGIN DECLARE vOldPayMethodName VARCHAR(20); DECLARE vNewPayMethodName VARCHAR(20); + SET NEW.editorFk = account.myUser_getId(); + SELECT hasVerified INTO vPayMethodHasVerified FROM payMethod WHERE id = NEW.payMethodFk; diff --git a/db/routines/vn/triggers/tag_BEFORE_INSERT.sql b/db/routines/vn/triggers/tag_BEFORE_INSERT.sql new file mode 100644 index 000000000..69536a711 --- /dev/null +++ b/db/routines/vn/triggers/tag_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`tag_BEFORE_INSERT` + BEFORE INSERT ON `tag` + FOR EACH ROW +BEGIN + IF NEW.ediTypeFk IS NULL AND (SELECT COUNT(*) FROM tag WHERE `name` = NEW.`name`) THEN + CALL util.throw('name duplicated'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketCollection_afterDelete.sql b/db/routines/vn/triggers/ticketCollection_afterDelete.sql new file mode 100644 index 000000000..e0917452a --- /dev/null +++ b/db/routines/vn/triggers/ticketCollection_afterDelete.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketCollection_afterDelete` + AFTER DELETE ON `ticketCollection` + FOR EACH ROW +BEGIN + + DECLARE vSalesRemaining INT; + + SELECT count(*) INTO vSalesRemaining + FROM vn.ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE collectionFk = OLD.collectionFk + AND tc.id != OLD.id; + + IF NOT vSalesRemaining THEN + + DELETE FROM vn.collection WHERE id = OLD.collectionFk; + + ELSE + + UPDATE vn.collection + SET saleTotalCount = vSalesRemaining + WHERE id = OLD.collectionFk; + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketDms_afterDelete.sql b/db/routines/vn/triggers/ticketDms_afterDelete.sql new file mode 100644 index 000000000..834079520 --- /dev/null +++ b/db/routines/vn/triggers/ticketDms_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketDms_afterDelete` + AFTER DELETE ON `ticketDms` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'ticketDms', + `changedModelId` = OLD.ticketFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketDms_beforeDelete.sql b/db/routines/vn/triggers/ticketDms_beforeDelete.sql new file mode 100644 index 000000000..9c251fba1 --- /dev/null +++ b/db/routines/vn/triggers/ticketDms_beforeDelete.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketDms_beforeDelete` + BEFORE DELETE ON `ticketDms` + FOR EACH ROW +BEGIN + UPDATE dms + SET dmsTypeFk = (SELECT id + FROM dmsType + WHERE `code` = 'trash' + ) + WHERE id = OLD.dmsFk AND ( SELECT IF(COUNT(*) > 0, FALSE, TRUE) + FROM ticketDms + WHERE dmsFk = OLD.dmsFk + ) ; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketDms_beforeInsert.sql b/db/routines/vn/triggers/ticketDms_beforeInsert.sql new file mode 100644 index 000000000..0c00dba28 --- /dev/null +++ b/db/routines/vn/triggers/ticketDms_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketDms_beforeInsert` + BEFORE INSERT ON `ticketDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketDms_beforeUpdate.sql b/db/routines/vn/triggers/ticketDms_beforeUpdate.sql new file mode 100644 index 000000000..aab22dd99 --- /dev/null +++ b/db/routines/vn/triggers/ticketDms_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketDms_beforeUpdate` + BEFORE UPDATE ON `ticketDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketObservation_afterDelete.sql b/db/routines/vn/triggers/ticketObservation_afterDelete.sql new file mode 100644 index 000000000..f8d88add6 --- /dev/null +++ b/db/routines/vn/triggers/ticketObservation_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketObservation_afterDelete` + AFTER DELETE ON `ticketObservation` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketObservation_beforeInsert.sql b/db/routines/vn/triggers/ticketObservation_beforeInsert.sql new file mode 100644 index 000000000..ce141d56a --- /dev/null +++ b/db/routines/vn/triggers/ticketObservation_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketObservation_beforeInsert` + BEFORE INSERT ON `ticketObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketObservation_beforeUpdate.sql b/db/routines/vn/triggers/ticketObservation_beforeUpdate.sql new file mode 100644 index 000000000..466e17e85 --- /dev/null +++ b/db/routines/vn/triggers/ticketObservation_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketObservation_beforeUpdate` + BEFORE UPDATE ON `ticketObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql b/db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql new file mode 100644 index 000000000..36d64ca3e --- /dev/null +++ b/db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketPackaging_BEFORE_INSERT` + BEFORE INSERT ON `ticketPackaging` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.workerFk = account.myUser_getId(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketPackaging_afterDelete.sql b/db/routines/vn/triggers/ticketPackaging_afterDelete.sql new file mode 100644 index 000000000..320f7e01e --- /dev/null +++ b/db/routines/vn/triggers/ticketPackaging_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketPackaging_afterDelete` + AFTER DELETE ON `ticketPackaging` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketPackaging', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketPackaging_beforeUpdate.sql b/db/routines/vn/triggers/ticketPackaging_beforeUpdate.sql new file mode 100644 index 000000000..5d15249c4 --- /dev/null +++ b/db/routines/vn/triggers/ticketPackaging_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketPackaging_beforeUpdate` + BEFORE UPDATE ON `ticketPackaging` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql b/db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql new file mode 100644 index 000000000..ec403b307 --- /dev/null +++ b/db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketParking_BEFORE_INSERT` + BEFORE INSERT ON `ticketParking` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRefund_afterDelete.sql b/db/routines/vn/triggers/ticketRefund_afterDelete.sql new file mode 100644 index 000000000..167030d4a --- /dev/null +++ b/db/routines/vn/triggers/ticketRefund_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_afterDelete` + AFTER DELETE ON `ticketRefund` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketRefund', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRefund_beforeInsert.sql b/db/routines/vn/triggers/ticketRefund_beforeInsert.sql new file mode 100644 index 000000000..7893f6c51 --- /dev/null +++ b/db/routines/vn/triggers/ticketRefund_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_beforeInsert` + BEFORE INSERT ON `ticketRefund` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql b/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql new file mode 100644 index 000000000..51c7db8f2 --- /dev/null +++ b/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_beforeUpdate` + BEFORE UPDATE ON `ticketRefund` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRequest_afterDelete.sql b/db/routines/vn/triggers/ticketRequest_afterDelete.sql new file mode 100644 index 000000000..a8932a744 --- /dev/null +++ b/db/routines/vn/triggers/ticketRequest_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRequest_afterDelete` + AFTER DELETE ON `ticketRequest` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketRequest', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRequest_beforeInsert.sql b/db/routines/vn/triggers/ticketRequest_beforeInsert.sql new file mode 100644 index 000000000..d17459912 --- /dev/null +++ b/db/routines/vn/triggers/ticketRequest_beforeInsert.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRequest_beforeInsert` + BEFORE INSERT ON `ticketRequest` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.ticketFk IS NULL THEN + SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk); + END IF; + + IF NEW.requesterFk IS NULL THEN + SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode); + END IF; + + IF NEW.attenderFk IS NULL THEN + SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql b/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql new file mode 100644 index 000000000..e5e9c307e --- /dev/null +++ b/db/routines/vn/triggers/ticketRequest_beforeUpdate.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRequest_beforeUpdate` + BEFORE UPDATE ON `ticketRequest` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.saleFk <> OLD.saleFk THEN + SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk); + END IF; + + IF NEW.salesPersonCode <> OLD.salesPersonCode THEN + SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode); + END IF; + + IF NEW.buyerCode <> OLD.buyerCode THEN + SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketService_ad.sql b/db/routines/vn/triggers/ticketService_ad.sql new file mode 100644 index 000000000..94c771c65 --- /dev/null +++ b/db/routines/vn/triggers/ticketService_ad.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_ad` + AFTER DELETE ON `ticketService` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketService', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL ticket_requestRecalc(OLD.ticketFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketService_ai.sql b/db/routines/vn/triggers/ticketService_ai.sql new file mode 100644 index 000000000..c98ebccd5 --- /dev/null +++ b/db/routines/vn/triggers/ticketService_ai.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_ai` + AFTER INSERT ON `ticketService` + FOR EACH ROW +BEGIN + + CALL ticket_requestRecalc(NEW.ticketFk); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketService_au.sql b/db/routines/vn/triggers/ticketService_au.sql new file mode 100644 index 000000000..989cb3b08 --- /dev/null +++ b/db/routines/vn/triggers/ticketService_au.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_au` + AFTER UPDATE ON `ticketService` + FOR EACH ROW +BEGIN + IF !(NEW.price <=> OLD.price) + OR !(NEW.ticketFk <=> OLD.ticketFk) + OR !(NEW.quantity <=> OLD.quantity) THEN + CALL ticket_requestRecalc(NEW.ticketFk); + CALL ticket_requestRecalc(OLD.ticketFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketService_beforeInsert.sql b/db/routines/vn/triggers/ticketService_beforeInsert.sql new file mode 100644 index 000000000..81b7e5e91 --- /dev/null +++ b/db/routines/vn/triggers/ticketService_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_beforeInsert` + BEFORE INSERT ON `ticketService` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketService_beforeUpdate.sql b/db/routines/vn/triggers/ticketService_beforeUpdate.sql new file mode 100644 index 000000000..a24af8269 --- /dev/null +++ b/db/routines/vn/triggers/ticketService_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_beforeUpdate` + BEFORE UPDATE ON `ticketService` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketTracking_afterDelete.sql b/db/routines/vn/triggers/ticketTracking_afterDelete.sql new file mode 100644 index 000000000..2f1bbbcee --- /dev/null +++ b/db/routines/vn/triggers/ticketTracking_afterDelete.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketTracking_afterDelete` + AFTER DELETE ON `ticketTracking` + FOR EACH ROW +BEGIN + DECLARE vTicketFk INT; + DECLARE vTicketTrackingFk INT; + DECLARE vStateName VARCHAR(15); + + DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' + BEGIN + DELETE FROM vn.ticketLastState + WHERE ticketFk = OLD.ticketFk; + END; + + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketTracking', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL util.debugAdd('deletedState', + CONCAT('interFk: ', OLD.id, + ' ticketFk: ', OLD.ticketFk, + ' stateFk: ', OLD.stateFk)); + + SELECT i.ticketFk, i.id, s.`name` + INTO vTicketFk, vTicketTrackingFk, vStateName + FROM ticketTracking i + JOIN state s ON i.stateFk = s.id + WHERE ticketFk = OLD.ticketFk + ORDER BY created DESC + LIMIT 1; + + IF vTicketFk > 0 THEN + REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name) + VALUES(vTicketFk, vTicketTrackingFk, vStateName); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketTracking_afterInsert.sql b/db/routines/vn/triggers/ticketTracking_afterInsert.sql new file mode 100644 index 000000000..b246cd44f --- /dev/null +++ b/db/routines/vn/triggers/ticketTracking_afterInsert.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketTracking_afterInsert` + AFTER INSERT ON `ticketTracking` + FOR EACH ROW +BEGIN + DECLARE vNumTicketsPrepared INT; + + REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) + SELECT NEW.ticketFk, NEW.id, `name` + FROM state + WHERE id = NEW.stateFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketTracking_afterUpdate.sql b/db/routines/vn/triggers/ticketTracking_afterUpdate.sql new file mode 100644 index 000000000..ce5586569 --- /dev/null +++ b/db/routines/vn/triggers/ticketTracking_afterUpdate.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketTracking_afterUpdate` + AFTER UPDATE ON `ticketTracking` + FOR EACH ROW +BEGIN + DECLARE vTicketFk INT; + DECLARE vTicketTrackingFk INT; + DECLARE vStateName VARCHAR(15); + + IF NEW.stateFk <> OLD.stateFk THEN + REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) + SELECT NEW.ticketFk, NEW.id, `name` + FROM state + WHERE id = NEW.stateFk; + END IF; + + IF NEW.ticketFk <> OLD.ticketFk THEN + SELECT i.ticketFk, i.id, s.`name` + INTO vTicketFk, vTicketTrackingFk, vStateName + FROM ticketTracking i + JOIN state s ON i.stateFk = s.id + WHERE ticketFk = NEW.ticketFk + ORDER BY created DESC + LIMIT 1; + + IF vTicketFk > 0 THEN + REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name) + VALUES(vTicketFk, vTicketTrackingFk, vStateName); + END IF; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketTracking_beforeInsert.sql b/db/routines/vn/triggers/ticketTracking_beforeInsert.sql new file mode 100644 index 000000000..685713aea --- /dev/null +++ b/db/routines/vn/triggers/ticketTracking_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketTracking_beforeInsert` + BEFORE INSERT ON `ticketTracking` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketTracking_beforeUpdate.sql b/db/routines/vn/triggers/ticketTracking_beforeUpdate.sql new file mode 100644 index 000000000..ec875387e --- /dev/null +++ b/db/routines/vn/triggers/ticketTracking_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketTracking_beforeUpdate` + BEFORE UPDATE ON `ticketTracking` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketWeekly_afterDelete.sql b/db/routines/vn/triggers/ticketWeekly_afterDelete.sql new file mode 100644 index 000000000..d0ef0b8df --- /dev/null +++ b/db/routines/vn/triggers/ticketWeekly_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketWeekly_afterDelete` + AFTER DELETE ON `ticketWeekly` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketWeekly', + `changedModelId` = OLD.ticketFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketWeekly_beforeInsert.sql b/db/routines/vn/triggers/ticketWeekly_beforeInsert.sql new file mode 100644 index 000000000..e4a61d203 --- /dev/null +++ b/db/routines/vn/triggers/ticketWeekly_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketWeekly_beforeInsert` + BEFORE INSERT ON `ticketWeekly` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketWeekly_beforeUpdate.sql b/db/routines/vn/triggers/ticketWeekly_beforeUpdate.sql new file mode 100644 index 000000000..1a631bec1 --- /dev/null +++ b/db/routines/vn/triggers/ticketWeekly_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketWeekly_beforeUpdate` + BEFORE UPDATE ON `ticketWeekly` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_afterDelete.sql b/db/routines/vn/triggers/ticket_afterDelete.sql new file mode 100644 index 000000000..c80f3dbe1 --- /dev/null +++ b/db/routines/vn/triggers/ticket_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterDelete` + AFTER DELETE ON `ticket` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'Ticket', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_afterInsert.sql b/db/routines/vn/triggers/ticket_afterInsert.sql new file mode 100644 index 000000000..0fad0aaee --- /dev/null +++ b/db/routines/vn/triggers/ticket_afterInsert.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterInsert` + AFTER INSERT ON `ticket` + FOR EACH ROW +BEGIN + + DECLARE vClientType VARCHAR(255); + DECLARE vStateCode VARCHAR(255); + DECLARE vTransferorFirstShipped DATE; + + -- Borrar cuando se cambie el insert ticket en la APP móvil + + SELECT typeFk INTO vClientType + FROM vn.`client` WHERE id = NEW.clientFk; + + IF vClientType = 'loses' THEN + SET vStateCode = 'DELIVERED'; + ELSE + SET vStateCode = 'FREE'; + END IF; + + CALL ticket_setState(NEW.id, vStateCode); + + IF YEAR(NEW.shipped) > 2000 THEN + + SELECT cnb.firstShipped INTO vTransferorFirstShipped + FROM bs.clientNewBorn cnb + JOIN `client` c ON c.transferorFk = cnb.clientFk + WHERE c.id = NEW.clientFk; + + INSERT INTO bs.clientNewBorn(clientFk, firstShipped, lastShipped) + VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, util.VN_CURDATE()), util.VN_CURDATE()) + ON DUPLICATE KEY UPDATE lastShipped = util.VN_CURDATE(); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_afterUpdate.sql b/db/routines/vn/triggers/ticket_afterUpdate.sql new file mode 100644 index 000000000..df939c9d1 --- /dev/null +++ b/db/routines/vn/triggers/ticket_afterUpdate.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_afterUpdate` + AFTER UPDATE ON `ticket` + FOR EACH ROW +BEGIN + + IF !(NEW.id <=> OLD.id) + OR !(NEW.warehouseFk <=> OLD.warehouseFk) + OR !(NEW.shipped <=> OLD.shipped) THEN + CALL stock.log_add('ticket', NEW.id, OLD.id); + END IF; + + IF !(NEW.clientFk <=> OLD.clientFk) + OR !(NEW.addressFk <=> OLD.addressFk) + OR !(NEW.companyFk <=> OLD.companyFk) THEN + CALL ticket_requestRecalc(NEW.id); + END IF; + + IF NEW.routeFk <> OLD.routeFk THEN + UPDATE expedition + SET hasNewRoute = TRUE + WHERE ticketFk = NEW.id; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_beforeDelete.sql b/db/routines/vn/triggers/ticket_beforeDelete.sql new file mode 100644 index 000000000..02c5352e6 --- /dev/null +++ b/db/routines/vn/triggers/ticket_beforeDelete.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_beforeDelete` + BEFORE DELETE ON `ticket` + FOR EACH ROW +BEGIN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.route r + WHERE r.isOk = FALSE + AND r.id = OLD.routeFk + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + + DELETE FROM sale WHERE ticketFk = OLD.id; + + DELETE FROM ticketDms WHERE ticketFk = OLD.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_beforeInsert.sql b/db/routines/vn/triggers/ticket_beforeInsert.sql new file mode 100644 index 000000000..7e0fc57b8 --- /dev/null +++ b/db/routines/vn/triggers/ticket_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_beforeInsert` + BEFORE INSERT ON `ticket` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticket_beforeUpdate.sql b/db/routines/vn/triggers/ticket_beforeUpdate.sql new file mode 100644 index 000000000..0836b2486 --- /dev/null +++ b/db/routines/vn/triggers/ticket_beforeUpdate.sql @@ -0,0 +1,77 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticket_beforeUpdate` + BEFORE UPDATE ON `ticket` + FOR EACH ROW +BEGIN + DECLARE vNewTime TIME; + DECLARE vHasTicketRefund BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF NOT (NEW.routeFk <=> OLD.routeFk) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.route r + WHERE r.isOk = FALSE + AND r.id IN (OLD.routeFk,NEW.routeFk) + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + END IF; + + IF NOT (DATE(NEW.shipped) <=> DATE(OLD.shipped)) THEN + IF YEAR(NEW.shipped) < 2000 THEN + SIGNAL SQLSTATE '46000' + SET MESSAGE_TEXT = 'Year cannot be lesser than 2000'; + END IF; + + IF YEAR(NEW.shipped) = 2000 THEN + SET NEW.isDeleted = TRUE; + END IF; + + END IF; + + IF NOT (NEW.isDeleted <=> OLD.isDeleted) AND NEW.isDeleted THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND t.id = NEW.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + SET NEW.shipped = DATE_FORMAT(NEW.shipped, '2000-%m-%d %T'); + SET NEW.landed = DATE_FORMAT(NEW.landed, '2000-%m-%d %T'); + SET NEW.routeFk = NULL; + SET NEW.zoneFk = NULL; + END IF; + + IF NEW.routeFk AND NEW.isDeleted THEN + CALL util.throw ('This ticket is deleted'); + END IF; + + IF NOT (NEW.routeFk <=> OLD.routeFk) AND NEW.routeFk IS NOT NULL THEN + SELECT MAX(TIME(shipped)) INTO vNewTime + FROM vn.ticket + WHERE routeFk = NEW.routeFk + HAVING MAX(TIME(shipped)) > TIME(NEW.shipped); + + IF vNewTime THEN + SET NEW.shipped = TIMESTAMP(DATE(NEW.shipped), vNewTime); + END IF; + INSERT IGNORE INTO zoneAgencyMode (agencyModeFk,zoneFk) + SELECT r.agencyModeFk, NEW.zoneFk FROM route r + WHERE r.id = NEW.routeFk; + + CALL vn.routeUpdateM3(NEW.routeFk); + END IF; + + SELECT COUNT(*) INTO vHasTicketRefund + FROM ticketRefund + WHERE originalTicketFk = NEW.id + OR refundTicketFk = NEW.id; + + IF vHasTicketRefund AND NEW.clientFk <> OLD.clientFk THEN + CALL util.throw('The ticket has a refund associated'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/time_AFTER_UPDATE.sql b/db/routines/vn/triggers/time_AFTER_UPDATE.sql new file mode 100644 index 000000000..14fdf96dc --- /dev/null +++ b/db/routines/vn/triggers/time_AFTER_UPDATE.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`time_AFTER_UPDATE` + AFTER UPDATE ON `time` + FOR EACH ROW +BEGIN + /*INSERT INTO vn.mail SET + `sender` = 'jgallego@verdnatura.es', + `replyTo` = 'jgallego@verdnatura.es', + `subject` = 'tabla time modificada', + `body` = CONCAT(account.myUser_getName(), ' ha modificado la tabla time ', + NEW.`dated`);*/ +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/town_afterDelete.sql b/db/routines/vn/triggers/town_afterDelete.sql new file mode 100644 index 000000000..e6ca82d80 --- /dev/null +++ b/db/routines/vn/triggers/town_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`town_afterDelete` + AFTER DELETE ON `town` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/town_afterUpdate.sql b/db/routines/vn/triggers/town_afterUpdate.sql new file mode 100644 index 000000000..830428061 --- /dev/null +++ b/db/routines/vn/triggers/town_afterUpdate.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`town_afterUpdate` + AFTER UPDATE ON `town` + FOR EACH ROW +BEGIN + IF !(OLD.provinceFk <=> NEW.provinceFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM province WHERE id = NEW.provinceFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/town_beforeInsert.sql b/db/routines/vn/triggers/town_beforeInsert.sql new file mode 100644 index 000000000..f3a060b2d --- /dev/null +++ b/db/routines/vn/triggers/town_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`town_beforeInsert` + BEFORE INSERT ON `town` + FOR EACH ROW +BEGIN + SET NEW.geoFk = zoneGeo_new('town', NEW.`name`, + (SELECT geoFk FROM province WHERE id = NEW.provinceFk)); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/town_beforeUpdate.sql b/db/routines/vn/triggers/town_beforeUpdate.sql new file mode 100644 index 000000000..e607b3f41 --- /dev/null +++ b/db/routines/vn/triggers/town_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`town_beforeUpdate` + BEFORE UPDATE ON `town` + FOR EACH ROW +BEGIN + -- IF !(OLD.geoFk <=> NEW.geoFk) THEN + -- CALL zoneGeo_throwNotEditable; + -- END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travelThermograph_afterDelete.sql b/db/routines/vn/triggers/travelThermograph_afterDelete.sql new file mode 100644 index 000000000..14a875799 --- /dev/null +++ b/db/routines/vn/triggers/travelThermograph_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travelThermograph_afterDelete` + AFTER DELETE ON `travelThermograph` + FOR EACH ROW +BEGIN + INSERT INTO travelLog + SET `action` = 'delete', + `changedModel` = 'TravelThermograph', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travelThermograph_beforeInsert.sql b/db/routines/vn/triggers/travelThermograph_beforeInsert.sql new file mode 100644 index 000000000..4ebe14e75 --- /dev/null +++ b/db/routines/vn/triggers/travelThermograph_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travelThermograph_beforeInsert` + BEFORE INSERT ON `travelThermograph` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travelThermograph_beforeUpdate.sql b/db/routines/vn/triggers/travelThermograph_beforeUpdate.sql new file mode 100644 index 000000000..381e655f3 --- /dev/null +++ b/db/routines/vn/triggers/travelThermograph_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travelThermograph_beforeUpdate` + BEFORE UPDATE ON `travelThermograph` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travel_afterDelete.sql b/db/routines/vn/triggers/travel_afterDelete.sql new file mode 100644 index 000000000..a528793e9 --- /dev/null +++ b/db/routines/vn/triggers/travel_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_afterDelete` + AFTER DELETE ON `travel` + FOR EACH ROW +BEGIN + INSERT INTO travelLog + SET `action` = 'delete', + `changedModel` = 'Travel', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travel_afterUpdate.sql b/db/routines/vn/triggers/travel_afterUpdate.sql new file mode 100644 index 000000000..8c639cca7 --- /dev/null +++ b/db/routines/vn/triggers/travel_afterUpdate.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_afterUpdate` + AFTER UPDATE ON `travel` + FOR EACH ROW +BEGIN + CALL stock.log_add('travel', NEW.id, OLD.id); + + IF !(NEW.shipped <=> OLD.shipped) THEN + UPDATE entry + SET commission = entry_getCommission(travelFk, currencyFk,supplierFk) + WHERE travelFk = NEW.id; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travel_beforeInsert.sql b/db/routines/vn/triggers/travel_beforeInsert.sql new file mode 100644 index 000000000..38e28b7e9 --- /dev/null +++ b/db/routines/vn/triggers/travel_beforeInsert.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_beforeInsert` + BEFORE INSERT ON `travel` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + CALL travel_checkDates(NEW.shipped, NEW.landed); + + -- Actualizar agencyFk y agencyModeFk + IF NEW.agencyFk THEN + SET NEW.agencyModeFk = NEW.agencyFk; + END IF; + + IF NEW.agencyModeFk THEN + SET NEW.agencyFk = NEW.agencyModeFk; + END IF; + + CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/travel_beforeUpdate.sql b/db/routines/vn/triggers/travel_beforeUpdate.sql new file mode 100644 index 000000000..46fa2edb8 --- /dev/null +++ b/db/routines/vn/triggers/travel_beforeUpdate.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`travel_beforeUpdate` + BEFORE UPDATE ON `travel` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +/* + IF ((NOT NEW.shipped <=> OLD.shipped ) + OR (NOT NEW.landed <=> OLD.landed ) + OR (NOT NEW.warehouseInFk <=> OLD.warehouseInFk ) + OR (NOT NEW.warehouseOutFk <=> OLD.warehouseOutFk )) + AND (OLD.totalEntries AND OLD.landed < CURDATE()) THEN + CALL util.throw("Cannot past travels with entries"); + END IF; +*/ + IF NOT (NEW.landed <=> OLD.landed) + OR NOT (NEW.shipped <=> OLD.shipped) THEN + CALL travel_checkDates(NEW.shipped, NEW.landed); + END IF; + + -- Actualizar agencyFk y agencyModeFk + IF NOT (NEW.agencyFk <=> OLD.agencyFk)THEN + SET NEW.agencyModeFk = NEW.agencyFk; + END IF; + + IF NOT (NEW.agencyModeFk <=> OLD.agencyModeFk) THEN + SET NEW.agencyFk = NEW.agencyModeFk; + END IF; + + IF NOT (NEW.isReceived <=> OLD.isReceived) THEN + CALL travel_checkPackaging(NEW.id); + END IF; + + IF NOT (NEW.warehouseInFk <=> OLD.warehouseInFk) THEN + CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/vehicle_beforeInsert.sql b/db/routines/vn/triggers/vehicle_beforeInsert.sql new file mode 100644 index 000000000..046e11703 --- /dev/null +++ b/db/routines/vn/triggers/vehicle_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`vehicle_beforeInsert` + BEFORE INSERT ON `vehicle` + FOR EACH ROW +BEGIN + CALL vehicle_checkNumberPlate(NEW.numberPlate, NEW.countryCodeFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/vehicle_beforeUpdate.sql b/db/routines/vn/triggers/vehicle_beforeUpdate.sql new file mode 100644 index 000000000..d61005468 --- /dev/null +++ b/db/routines/vn/triggers/vehicle_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`vehicle_beforeUpdate` + BEFORE UPDATE ON `vehicle` + FOR EACH ROW +BEGIN + CALL vehicle_checkNumberPlate(NEW.numberPlate, NEW.countryCodeFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/warehouse_afterInsert.sql b/db/routines/vn/triggers/warehouse_afterInsert.sql new file mode 100644 index 000000000..97a8c4152 --- /dev/null +++ b/db/routines/vn/triggers/warehouse_afterInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`warehouse_afterInsert` + BEFORE UPDATE ON `warehouse` + FOR EACH ROW +BEGIN + IF NEW.isFeedStock AND NEW.isInventory THEN + CALL util.throw("isFeedStock and isInventory cannot both be true"); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/warehouse_afterUpdate.sql b/db/routines/vn/triggers/warehouse_afterUpdate.sql new file mode 100644 index 000000000..93f424429 --- /dev/null +++ b/db/routines/vn/triggers/warehouse_afterUpdate.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`warehouse_afterUpdate` + AFTER UPDATE ON `warehouse` + FOR EACH ROW +BEGIN + IF NEW.isFeedStock IS TRUE AND OLD.isFeedStock IS FALSE THEN + INSERT IGNORE INTO warehouseAlias(`name`) VALUES(NEW.`name`); + INSERT IGNORE INTO warehouseJoined(warehouseFk, warehouseAliasFk) + VALUES(NEW.id,LAST_INSERT_ID()); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerDocument_afterDelete.sql b/db/routines/vn/triggers/workerDocument_afterDelete.sql new file mode 100644 index 000000000..b266d3bf6 --- /dev/null +++ b/db/routines/vn/triggers/workerDocument_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerDocument_afterDelete` + AFTER DELETE ON `workerDocument` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'WorkerDocument', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerDocument_beforeInsert.sql b/db/routines/vn/triggers/workerDocument_beforeInsert.sql new file mode 100644 index 000000000..2a795ba38 --- /dev/null +++ b/db/routines/vn/triggers/workerDocument_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerDocument_beforeInsert` + BEFORE INSERT ON `workerDocument` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerDocument_beforeUpdate.sql b/db/routines/vn/triggers/workerDocument_beforeUpdate.sql new file mode 100644 index 000000000..ffa137b3a --- /dev/null +++ b/db/routines/vn/triggers/workerDocument_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerDocument_beforeUpdate` + BEFORE UPDATE ON `workerDocument` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerIncome_afterDelete.sql b/db/routines/vn/triggers/workerIncome_afterDelete.sql new file mode 100644 index 000000000..e19df59a8 --- /dev/null +++ b/db/routines/vn/triggers/workerIncome_afterDelete.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerIncome_afterDelete` + AFTER DELETE ON `workerIncome` + FOR EACH ROW +BEGIN + CALL worker_updateBalance(OLD.workerFk,-OLD.credit,-OLD.debit); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerIncome_afterInsert.sql b/db/routines/vn/triggers/workerIncome_afterInsert.sql new file mode 100644 index 000000000..8837f9c07 --- /dev/null +++ b/db/routines/vn/triggers/workerIncome_afterInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerIncome_afterInsert` + AFTER INSERT ON `workerIncome` + FOR EACH ROW +BEGIN + CALL worker_updateBalance(NEW.workerFk,NEW.credit,NEW.debit); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerIncome_afterUpdate.sql b/db/routines/vn/triggers/workerIncome_afterUpdate.sql new file mode 100644 index 000000000..a2584df22 --- /dev/null +++ b/db/routines/vn/triggers/workerIncome_afterUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerIncome_afterUpdate` + AFTER UPDATE ON `workerIncome` + FOR EACH ROW +BEGIN + CALL worker_updateBalance(NEW.workerFk,-OLD.credit,-OLD.debit); + + CALL worker_updateBalance(NEW.workerFk,NEW.credit,NEW.debit); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerTimeControl_AI.sql b/db/routines/vn/triggers/workerTimeControl_AI.sql new file mode 100644 index 000000000..8e55004eb --- /dev/null +++ b/db/routines/vn/triggers/workerTimeControl_AI.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerTimeControl_AI` + AFTER INSERT ON `workerTimeControl` + FOR EACH ROW +BEGIN + IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN + CALL util.throw('date in the future'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/worker_afterDelete.sql b/db/routines/vn/triggers/worker_afterDelete.sql new file mode 100644 index 000000000..0104248ff --- /dev/null +++ b/db/routines/vn/triggers/worker_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`worker_afterDelete` + AFTER DELETE ON `worker` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'Worker', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/worker_beforeInsert.sql b/db/routines/vn/triggers/worker_beforeInsert.sql new file mode 100644 index 000000000..8830bd77e --- /dev/null +++ b/db/routines/vn/triggers/worker_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`worker_beforeInsert` + BEFORE INSERT ON `worker` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/worker_beforeUpdate.sql b/db/routines/vn/triggers/worker_beforeUpdate.sql new file mode 100644 index 000000000..05705d273 --- /dev/null +++ b/db/routines/vn/triggers/worker_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`worker_beforeUpdate` + BEFORE UPDATE ON `worker` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workingHoursBeforeInsert.sql b/db/routines/vn/triggers/workingHoursBeforeInsert.sql new file mode 100644 index 000000000..763061be8 --- /dev/null +++ b/db/routines/vn/triggers/workingHoursBeforeInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workingHoursBeforeInsert` + BEFORE INSERT ON `workingHours` + FOR EACH ROW +BEGIN + IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = util.VN_CURDATE()) > 0 THEN + CALL util.throw ('ALREADY_LOGGED'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneEvent_afterDelete.sql b/db/routines/vn/triggers/zoneEvent_afterDelete.sql new file mode 100644 index 000000000..1eecc21dc --- /dev/null +++ b/db/routines/vn/triggers/zoneEvent_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneEvent_afterDelete` + AFTER DELETE ON `zoneEvent` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'zoneEvent', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneEvent_beforeInsert.sql b/db/routines/vn/triggers/zoneEvent_beforeInsert.sql new file mode 100644 index 000000000..ae1542851 --- /dev/null +++ b/db/routines/vn/triggers/zoneEvent_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneEvent_beforeInsert` + BEFORE INSERT ON `zoneEvent` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneEvent_beforeUpdate.sql b/db/routines/vn/triggers/zoneEvent_beforeUpdate.sql new file mode 100644 index 000000000..09698a2c9 --- /dev/null +++ b/db/routines/vn/triggers/zoneEvent_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneEvent_beforeUpdate` + BEFORE UPDATE ON `zoneEvent` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneExclusion_BI.sql b/db/routines/vn/triggers/zoneExclusion_BI.sql new file mode 100644 index 000000000..117a482ab --- /dev/null +++ b/db/routines/vn/triggers/zoneExclusion_BI.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_BI` + BEFORE INSERT ON `zoneExclusion` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.userFk = account.myUser_getId(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneExclusion_BU.sql b/db/routines/vn/triggers/zoneExclusion_BU.sql new file mode 100644 index 000000000..cab6ae3c4 --- /dev/null +++ b/db/routines/vn/triggers/zoneExclusion_BU.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_BU` + BEFORE UPDATE ON `zoneExclusion` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.userFk = account.myUser_getId(); + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneExclusion_afterDelete.sql b/db/routines/vn/triggers/zoneExclusion_afterDelete.sql new file mode 100644 index 000000000..6c8a441aa --- /dev/null +++ b/db/routines/vn/triggers/zoneExclusion_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_afterDelete` + AFTER DELETE ON `zoneExclusion` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'zoneExclusion', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneGeo_beforeInsert.sql b/db/routines/vn/triggers/zoneGeo_beforeInsert.sql new file mode 100644 index 000000000..1dbefbed9 --- /dev/null +++ b/db/routines/vn/triggers/zoneGeo_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneGeo_beforeInsert` + BEFORE INSERT ON `zoneGeo` + FOR EACH ROW +BEGIN + CALL zoneGeo_checkName(NEW.`name`); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneGeo_beforeUpdate.sql b/db/routines/vn/triggers/zoneGeo_beforeUpdate.sql new file mode 100644 index 000000000..0fdd7a682 --- /dev/null +++ b/db/routines/vn/triggers/zoneGeo_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneGeo_beforeUpdate` + BEFORE UPDATE ON `zoneGeo` + FOR EACH ROW +BEGIN + IF !(OLD.`name` <=> NEW.`name`) THEN + CALL zoneGeo_checkName(NEW.`name`); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneIncluded_afterDelete.sql b/db/routines/vn/triggers/zoneIncluded_afterDelete.sql new file mode 100644 index 000000000..6d184bb12 --- /dev/null +++ b/db/routines/vn/triggers/zoneIncluded_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete` + AFTER DELETE ON `zoneIncluded` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'zoneIncluded', + `changedModelId` = OLD.zoneFk, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql b/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql new file mode 100644 index 000000000..5eff33efa --- /dev/null +++ b/db/routines/vn/triggers/zoneIncluded_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeInsert` + BEFORE INSERT ON `zoneIncluded` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql b/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql new file mode 100644 index 000000000..445f37699 --- /dev/null +++ b/db/routines/vn/triggers/zoneIncluded_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_beforeUpdate` + BEFORE UPDATE ON `zoneIncluded` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneWarehouse_afterDelete.sql b/db/routines/vn/triggers/zoneWarehouse_afterDelete.sql new file mode 100644 index 000000000..3befff38a --- /dev/null +++ b/db/routines/vn/triggers/zoneWarehouse_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneWarehouse_afterDelete` + AFTER DELETE ON `zoneWarehouse` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'ZoneWarehouse', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneWarehouse_beforeInsert.sql b/db/routines/vn/triggers/zoneWarehouse_beforeInsert.sql new file mode 100644 index 000000000..099e66587 --- /dev/null +++ b/db/routines/vn/triggers/zoneWarehouse_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneWarehouse_beforeInsert` + BEFORE INSERT ON `zoneWarehouse` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zoneWarehouse_beforeUpdate.sql b/db/routines/vn/triggers/zoneWarehouse_beforeUpdate.sql new file mode 100644 index 000000000..2a6563dc5 --- /dev/null +++ b/db/routines/vn/triggers/zoneWarehouse_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneWarehouse_beforeUpdate` + BEFORE UPDATE ON `zoneWarehouse` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zone_afterDelete.sql b/db/routines/vn/triggers/zone_afterDelete.sql new file mode 100644 index 000000000..463fa89e8 --- /dev/null +++ b/db/routines/vn/triggers/zone_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zone_afterDelete` + AFTER DELETE ON `zone` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'Zone', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zone_beforeInsert.sql b/db/routines/vn/triggers/zone_beforeInsert.sql new file mode 100644 index 000000000..e0449a989 --- /dev/null +++ b/db/routines/vn/triggers/zone_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zone_beforeInsert` + BEFORE INSERT ON `zone` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/zone_beforeUpdate.sql b/db/routines/vn/triggers/zone_beforeUpdate.sql new file mode 100644 index 000000000..f945ad32c --- /dev/null +++ b/db/routines/vn/triggers/zone_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zone_beforeUpdate` + BEFORE UPDATE ON `zone` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/views/NewView.sql b/db/routines/vn/views/NewView.sql new file mode 100644 index 000000000..389564966 --- /dev/null +++ b/db/routines/vn/views/NewView.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`NewView` +AS SELECT `c`.`id` AS `clientFk`, + max(`t`.`shipped`) AS `lastShipped`, + `pc`.`notBuyingMonths` AS `notBuyingMonths` +FROM ( + ( + `vn`.`client` `c` + JOIN `vn`.`productionConfig` `pc` + ) + LEFT JOIN `vn`.`ticket` `t` ON( + `c`.`id` = `t`.`clientFk` + AND `t`.`shipped` < `util`.`VN_CURDATE`() + INTERVAL - `pc`.`rookieDays` DAY + ) + ) +GROUP BY `c`.`id` +HAVING `lastShipped` IS NULL + OR `lastShipped` < `util`.`VN_CURDATE`() + INTERVAL - `notBuyingMonths` MONTH diff --git a/db/routines/vn/views/__coolerPathDetail.sql b/db/routines/vn/views/__coolerPathDetail.sql new file mode 100644 index 000000000..375d9e2d0 --- /dev/null +++ b/db/routines/vn/views/__coolerPathDetail.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`__coolerPathDetail` +AS SELECT `c`.`cooler_path_detail_id` AS `id`, + `c`.`cooler_path_id` AS `coolerPathFk`, + `c`.`pasillo` AS `hallway` +FROM `vn2008`.`cooler_path_detail` `c` diff --git a/db/routines/vn/views/agencyTerm.sql b/db/routines/vn/views/agencyTerm.sql new file mode 100644 index 000000000..5f54cf39f --- /dev/null +++ b/db/routines/vn/views/agencyTerm.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`agencyTerm` +AS SELECT `sat`.`agencyFk` AS `agencyFk`, + `sat`.`minimumPackages` AS `minimumPackages`, + `sat`.`kmPrice` AS `kmPrice`, + `sat`.`packagePrice` AS `packagePrice`, + `sat`.`routePrice` AS `routePrice`, + `sat`.`minimumKm` AS `minimumKm`, + `sat`.`minimumM3` AS `minimumM3`, + `sat`.`m3Price` AS `m3Price` +FROM `vn`.`supplierAgencyTerm` `sat` diff --git a/db/routines/vn/views/agencyWarehouse.sql b/db/routines/vn/views/agencyWarehouse.sql new file mode 100644 index 000000000..6cb174544 --- /dev/null +++ b/db/routines/vn/views/agencyWarehouse.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`agencyWarehouse` +AS SELECT `a`.`agency_id` AS `agencyFk`, + `a`.`warehouse_id` AS `warehouseFk`, + `a`.`Vista` AS `agencyType` +FROM `vn2008`.`agency_warehouse` `a` diff --git a/db/routines/vn/views/annualAverageInvoiced.sql b/db/routines/vn/views/annualAverageInvoiced.sql new file mode 100644 index 000000000..30e81e1ec --- /dev/null +++ b/db/routines/vn/views/annualAverageInvoiced.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`annualAverageInvoiced` +AS SELECT `cec`.`clientFk` AS `clientFk`, + `cec`.`invoiced` AS `invoiced` +FROM `bs`.`clientAnnualConsumption` `cec` diff --git a/db/routines/vn/views/awbVolume.sql b/db/routines/vn/views/awbVolume.sql new file mode 100644 index 000000000..0f4778864 --- /dev/null +++ b/db/routines/vn/views/awbVolume.sql @@ -0,0 +1,36 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`awbVolume` +AS SELECT `d`.`awbFk` AS `awbFk`, + `b`.`stickers` * `i`.`density` * IF( + `p`.`volume` > 0, + `p`.`volume`, + `p`.`width` * `p`.`depth` * IF(`p`.`height` = 0, `i`.`size` + 10, `p`.`height`) + ) / (`vc`.`aerealVolumetricDensity` * 1000) AS `volume`, + `b`.`id` AS `buyFk` +FROM ( + ( + ( + ( + ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) + ) + JOIN `vn`.`itemType` `it` ON(`i`.`typeFk` = `it`.`id`) + ) + JOIN `vn`.`packaging` `p` ON(`p`.`id` = `b`.`packagingFk`) + ) + JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) + ) + JOIN `vn`.`travel` `t` ON(`t`.`id` = `e`.`travelFk`) + ) + JOIN `vn`.`duaEntry` `de` ON(`de`.`entryFk` = `e`.`id`) + ) + JOIN `vn`.`dua` `d` ON(`d`.`id` = `de`.`duaFk`) + ) + JOIN `vn`.`volumeConfig` `vc` + ) +WHERE `t`.`shipped` > makedate(year(`util`.`VN_CURDATE`()) - 1, 1) diff --git a/db/routines/vn/views/bank.sql b/db/routines/vn/views/bank.sql new file mode 100644 index 000000000..fa0d9a4f0 --- /dev/null +++ b/db/routines/vn/views/bank.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`bank` +AS SELECT `a`.`id` AS `id`, + `a`.`bank` AS `bank`, + `a`.`account` AS `account`, + `a`.`accountingTypeFk` AS `cash`, + `a`.`entityFk` AS `entityFk`, + `a`.`isActive` AS `isActive`, + `a`.`currencyFk` AS `currencyFk`, + `a`.`code` AS `code` +FROM `vn`.`accounting` `a` diff --git a/db/routines/vn/views/bankPolicy.sql b/db/routines/vn/views/bankPolicy.sql new file mode 100644 index 000000000..e329d2b2c --- /dev/null +++ b/db/routines/vn/views/bankPolicy.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`bankPolicy` +AS SELECT `bp`.`poliza_id` AS `id`, + `bp`.`referencia` AS `ref`, + `bp`.`importe` AS `amount`, + `bp`.`com_dispuesto` AS `balanceInterestDrawn`, + `bp`.`com_no_dispuesto` AS `commissionAvailableBalances`, + `bp`.`com_anual` AS `openingCommission`, + `bp`.`apertura` AS `started`, + `bp`.`cierre` AS `ended`, + `bp`.`Id_Banco` AS `bankFk`, + `bp`.`empresa_id` AS `companyFk`, + `bp`.`supplierFk` AS `supplierFk`, + `bp`.`description` AS `description`, + `bp`.`hasGuarantee` AS `hasGuarantee`, + `bp`.`dmsFk` AS `dmsFk`, + `bp`.`notaryFk` AS `notaryFk`, + `bp`.`currencyFk` AS `currencyFk`, + `bp`.`amortizationTypeFk` AS `amortizationTypeFk`, + `bp`.`periodicityTypeFk` AS `periodicityTypeFk`, + `bp`.`insuranceExpired` AS `insuranceExpired` +FROM `vn2008`.`Bancos_poliza` `bp` +ORDER BY `bp`.`poliza_id` DESC diff --git a/db/routines/vn/views/businessCalendar.sql b/db/routines/vn/views/businessCalendar.sql new file mode 100644 index 000000000..feda22793 --- /dev/null +++ b/db/routines/vn/views/businessCalendar.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`businessCalendar` +AS SELECT `c`.`id` AS `id`, + `c`.`businessFk` AS `businessFk`, + `c`.`dayOffTypeFk` AS `absenceTypeFk`, + `c`.`dated` AS `dated` +FROM `vn`.`calendar` `c` diff --git a/db/routines/vn/views/buyer.sql b/db/routines/vn/views/buyer.sql new file mode 100644 index 000000000..7114c50bc --- /dev/null +++ b/db/routines/vn/views/buyer.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`buyer` +AS SELECT DISTINCT `u`.`id` AS `userFk`, + `u`.`nickname` AS `nickname` +FROM ( + `account`.`user` `u` + JOIN `vn`.`itemType` `it` ON(`it`.`workerFk` = `u`.`id`) + ) +WHERE `u`.`active` <> 0 +ORDER BY `u`.`nickname` diff --git a/db/routines/vn/views/buyerSales.sql b/db/routines/vn/views/buyerSales.sql new file mode 100644 index 000000000..b67e17569 --- /dev/null +++ b/db/routines/vn/views/buyerSales.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`buyerSales` +AS SELECT `v`.`importe` AS `importe`, + `w`.`code` AS `comprador`, + `t`.`year` AS `año`, + `t`.`week` AS `semana` +FROM ( + ( + ( + `bs`.`ventas` `v` + JOIN `vn`.`time` `t` ON(`t`.`dated` = `v`.`fecha`) + ) + JOIN `vn`.`itemType` `it` ON(`it`.`id` = `v`.`tipo_id`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `it`.`workerFk`) + ) diff --git a/db/routines/vn/views/clientDefaultCompany.sql b/db/routines/vn/views/clientDefaultCompany.sql new file mode 100644 index 000000000..6af418a1a --- /dev/null +++ b/db/routines/vn/views/clientDefaultCompany.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`clientDefaultCompany` +AS SELECT `t`.`Id_Clientes_empresa` AS `id`, + `t`.`Id_Cliente` AS `clientFk`, + `t`.`empresa_id` AS `companyFk`, + `t`.`fecha_ini` AS `started`, + `t`.`fecha_fin` AS `finished` +FROM `vn2008`.`Clientes_empresa` `t` diff --git a/db/routines/vn/views/clientLost.sql b/db/routines/vn/views/clientLost.sql new file mode 100644 index 000000000..764782d08 --- /dev/null +++ b/db/routines/vn/views/clientLost.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`clientLost` +AS SELECT `c`.`id` AS `clientFk`, + max(`t`.`shipped`) AS `lastShipped`, + `pc`.`notBuyingMonths` AS `notBuyingMonths` +FROM ( + ( + `vn`.`client` `c` + JOIN `vn`.`productionConfig` `pc` + ) + LEFT JOIN `vn`.`ticket` `t` ON( + `c`.`id` = `t`.`clientFk` + AND `t`.`shipped` < `util`.`VN_CURDATE`() + INTERVAL - `pc`.`rookieDays` DAY + ) + ) +GROUP BY `c`.`id` +HAVING `lastShipped` IS NULL + OR `lastShipped` < `util`.`VN_CURDATE`() + INTERVAL - `notBuyingMonths` MONTH diff --git a/db/routines/vn/views/clientPhoneBook.sql b/db/routines/vn/views/clientPhoneBook.sql new file mode 100644 index 000000000..7ab2a99db --- /dev/null +++ b/db/routines/vn/views/clientPhoneBook.sql @@ -0,0 +1,41 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`clientPhoneBook` +AS SELECT `c`.`id` AS `clientFk`, + trim(`c`.`phone`) AS `phone` +FROM `vn`.`client` `c` +WHERE `c`.`phone` <> 0 + AND `c`.`isActive` <> 0 +UNION +SELECT `c`.`id` AS `clientFk`, + trim(`c`.`mobile`) AS `phone` +FROM `vn`.`client` `c` +WHERE `c`.`mobile` <> 0 + AND `c`.`isActive` <> 0 +UNION +SELECT `a`.`clientFk` AS `clientFk`, + trim(`a`.`phone`) AS `phone` +FROM ( + `vn`.`address` `a` + JOIN `vn`.`client` `c` ON(`c`.`id` = `a`.`clientFk`) + ) +WHERE `a`.`phone` <> 0 + AND `c`.`isActive` <> 0 +UNION +SELECT `a`.`clientFk` AS `clientFk`, + trim(`a`.`mobile`) AS `phone` +FROM ( + `vn`.`address` `a` + JOIN `vn`.`client` `c` ON(`c`.`id` = `a`.`clientFk`) + ) +WHERE `a`.`mobile` <> 0 + AND `c`.`isActive` <> 0 +UNION +SELECT `cc`.`clientFk` AS `clientFk`, + trim(`cc`.`phone`) AS `phone` +FROM ( + `vn`.`clientContact` `cc` + LEFT JOIN `vn`.`client` `c` ON(`c`.`id` = `cc`.`clientFk`) + ) +WHERE `c`.`phone` <> 0 + AND `c`.`isActive` <> 0 diff --git a/db/routines/vn/views/companyL10n.sql b/db/routines/vn/views/companyL10n.sql new file mode 100644 index 000000000..fa5c4c5d8 --- /dev/null +++ b/db/routines/vn/views/companyL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`companyL10n` +AS SELECT `c`.`id` AS `id`, + IFNULL(`ci`.`footnotes`, `c`.`footnotes`) AS `footnotes` +FROM ( + `vn`.`company` `c` + LEFT JOIN `vn`.`companyI18n` `ci` ON( + `ci`.`companyFk` = `c`.`id` + AND `ci`.`lang` = `util`.`LANG`() + ) + ) diff --git a/db/routines/vn/views/coolerPath.sql b/db/routines/vn/views/coolerPath.sql new file mode 100644 index 000000000..6be11e557 --- /dev/null +++ b/db/routines/vn/views/coolerPath.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`coolerPath` +AS SELECT `c`.`cooler_path_id` AS `id`, + `c`.`description` AS `description` +FROM `vn2008`.`cooler_path` `c` diff --git a/db/routines/vn/views/defaulter.sql b/db/routines/vn/views/defaulter.sql new file mode 100644 index 000000000..9d48978b2 --- /dev/null +++ b/db/routines/vn/views/defaulter.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`defaulter` +AS SELECT `d`.`clientFk` AS `clientFk`, + `d`.`created` AS `created`, + `d`.`amount` AS `amount`, + `d`.`defaulterSinced` AS `defaulterSinced`, + `d`.`hasChanged` AS `hasChanged`, + `c`.`countryFk` AS `country`, + `c`.`payMethodFk` AS `payMethod` +FROM ( + ( + ( + `bs`.`defaulter` `d` + JOIN `vn`.`client` `c` ON(`c`.`id` = `d`.`clientFk`) + ) + JOIN `vn`.`country` `co` ON(`co`.`id` = `c`.`countryFk`) + ) + JOIN `vn`.`payMethod` `pm` ON(`pm`.`id` = `c`.`payMethodFk`) + ) diff --git a/db/routines/vn/views/departmentTree.sql b/db/routines/vn/views/departmentTree.sql new file mode 100644 index 000000000..6f5a1205a --- /dev/null +++ b/db/routines/vn/views/departmentTree.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`departmentTree` +AS SELECT `node`.`id` AS `id`, + concat( + CONVERT( + repeat(repeat(' ', 5), COUNT(`parent`.`id`) - 1) USING utf8mb3 + ), + `node`.`name` + ) AS `dep` +FROM ( + `vn`.`department` `node` + JOIN `vn`.`department` `parent` + ) +WHERE `node`.`lft` BETWEEN `parent`.`lft` AND `parent`.`rgt` +GROUP BY `node`.`id` +ORDER BY `node`.`lft` diff --git a/db/routines/vn/views/doc.sql b/db/routines/vn/views/doc.sql new file mode 100644 index 000000000..31ac20640 --- /dev/null +++ b/db/routines/vn/views/doc.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`doc` +AS SELECT `g`.`id` AS `id`, + `g`.`sref` AS `sref`, + `g`.`brief` AS `brief`, + `g`.`emp_id` AS `companyFk`, + `g`.`orden` AS `order`, + `g`.`file` AS `file`, + `g`.`original` AS `original`, + `g`.`trabajador_id` AS `workerFk`, + `g`.`odbc_date` AS `created`, + `g`.`warehouse_id` AS `warehouseFk` +FROM `vn2008`.`gestdoc` `g` diff --git a/db/routines/vn/views/ediGenus.sql b/db/routines/vn/views/ediGenus.sql new file mode 100644 index 000000000..4546afa33 --- /dev/null +++ b/db/routines/vn/views/ediGenus.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ediGenus` +AS SELECT `g`.`genus_id` AS `id`, + `g`.`latin_genus_name` AS `latinGenusName`, + `g`.`entry_date` AS `entried`, + `g`.`expiry_date` AS `dued`, + `g`.`change_date_time` AS `modified` +FROM `edi`.`genus` `g` diff --git a/db/routines/vn/views/ediSpecie.sql b/db/routines/vn/views/ediSpecie.sql new file mode 100644 index 000000000..9587cb530 --- /dev/null +++ b/db/routines/vn/views/ediSpecie.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ediSpecie` +AS SELECT `s`.`specie_id` AS `id`, + `s`.`genus_id` AS `genusFk`, + `s`.`latin_species_name` AS `latinSpeciesName`, + `s`.`entry_date` AS `entried`, + `s`.`expiry_date` AS `dued`, + `s`.`change_date_time` AS `modified` +FROM `edi`.`specie` `s` diff --git a/db/routines/vn/views/ektSubAddress.sql b/db/routines/vn/views/ektSubAddress.sql new file mode 100644 index 000000000..11f6e2e70 --- /dev/null +++ b/db/routines/vn/views/ektSubAddress.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ektSubAddress` +AS SELECT `eea`.`sub` AS `sub`, + `a`.`clientFk` AS `clientFk`, + `a`.`nickname` AS `nickname`, + `eea`.`addressFk` AS `addressFk` +FROM ( + `vn`.`ektEntryAssign` `eea` + JOIN `vn`.`address` `a` ON(`a`.`id` = `eea`.`addressFk`) + ) +GROUP BY `eea`.`sub` diff --git a/db/routines/vn/views/especialPrice.sql b/db/routines/vn/views/especialPrice.sql new file mode 100644 index 000000000..08b9b434a --- /dev/null +++ b/db/routines/vn/views/especialPrice.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`especialPrice` +AS SELECT `p`.`Id_PrecioEspecial` AS `id`, + `p`.`Id_Cliente` AS `clientFk`, + `p`.`Id_Article` AS `itemFk`, + `p`.`PrecioEspecial` AS `value` +FROM `vn2008`.`PreciosEspeciales` `p` diff --git a/db/routines/vn/views/exchangeInsurance.sql b/db/routines/vn/views/exchangeInsurance.sql new file mode 100644 index 000000000..5df3c2f1d --- /dev/null +++ b/db/routines/vn/views/exchangeInsurance.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeInsurance` +AS SELECT `vn2008`.`pago_sdc`.`pago_sdc_id` AS `id`, + `vn2008`.`pago_sdc`.`importe` AS `amount`, + `vn2008`.`pago_sdc`.`fecha` AS `dated`, + `vn2008`.`pago_sdc`.`vencimiento` AS `finished`, + `vn2008`.`pago_sdc`.`entity_id` AS `entityFk`, + `vn2008`.`pago_sdc`.`ref` AS `ref`, + `vn2008`.`pago_sdc`.`rate` AS `rate`, + `vn2008`.`pago_sdc`.`empresa_id` AS `companyFk`, + `vn2008`.`pago_sdc`.`financialProductTypefk` AS `financialProductTypefk`, + `vn2008`.`pago_sdc`.`upperBarrier` AS `upperBarrier`, + `vn2008`.`pago_sdc`.`lowerBarrier` AS `lowerBarrier`, + `vn2008`.`pago_sdc`.`strike` AS `strike` +FROM `vn2008`.`pago_sdc` diff --git a/db/routines/vn/views/exchangeInsuranceEntry.sql b/db/routines/vn/views/exchangeInsuranceEntry.sql new file mode 100644 index 000000000..e9c7a7bbe --- /dev/null +++ b/db/routines/vn/views/exchangeInsuranceEntry.sql @@ -0,0 +1,28 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeInsuranceEntry` +AS SELECT max(`tr`.`landed`) AS `dated`, + cast( + sum( + (`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity` + ) AS decimal(10, 2) + ) AS `Dolares`, + cast( + sum( + (`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity` + ) / sum( + (100 + `e`.`commission`) / 100 * (`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity` + ) AS decimal(10, 4) + ) AS `rate` +FROM ( + ( + `vn`.`entry` `e` + JOIN `vn`.`buy` `b` ON(`e`.`id` = `b`.`entryFk`) + ) + JOIN `vn`.`travel` `tr` ON(`tr`.`id` = `e`.`travelFk`) + ) +WHERE `tr`.`landed` BETWEEN '2016-01-31' AND `util`.`VN_CURDATE`() + AND `e`.`commission` < 0 + AND `e`.`currencyFk` = 2 +GROUP BY MONTH(`tr`.`landed`), + year(`tr`.`landed`) diff --git a/db/routines/vn/views/exchangeInsuranceIn.sql b/db/routines/vn/views/exchangeInsuranceIn.sql new file mode 100644 index 000000000..aa27cfb4c --- /dev/null +++ b/db/routines/vn/views/exchangeInsuranceIn.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeInsuranceIn` +AS SELECT `exchangeInsuranceInPrevious`.`dated` AS `dated`, + sum(`exchangeInsuranceInPrevious`.`amount`) AS `amount`, + cast( + sum( + `exchangeInsuranceInPrevious`.`amount` * `exchangeInsuranceInPrevious`.`rate` + ) / sum(`exchangeInsuranceInPrevious`.`amount`) AS decimal(10, 4) + ) AS `rate` +FROM `vn`.`exchangeInsuranceInPrevious` +GROUP BY `exchangeInsuranceInPrevious`.`dated` diff --git a/db/routines/vn/views/exchangeInsuranceInPrevious.sql b/db/routines/vn/views/exchangeInsuranceInPrevious.sql new file mode 100644 index 000000000..097728bc7 --- /dev/null +++ b/db/routines/vn/views/exchangeInsuranceInPrevious.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeInsuranceInPrevious` +AS SELECT `ei`.`finished` AS `dated`, + `ei`.`amount` AS `amount`, + `ei`.`rate` AS `rate` +FROM `vn`.`exchangeInsurance` `ei` +WHERE `ei`.`amount` <> 0 + AND `ei`.`financialProductTypefk` = 'SC' diff --git a/db/routines/vn/views/exchangeInsuranceOut.sql b/db/routines/vn/views/exchangeInsuranceOut.sql new file mode 100644 index 000000000..f93b65331 --- /dev/null +++ b/db/routines/vn/views/exchangeInsuranceOut.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeInsuranceOut` +AS SELECT `p`.`received` AS `received`, + sum(`p`.`divisa`) AS `divisa`, + sum(`p`.`divisa`) / sum(`p`.`amount`) AS `rate` +FROM ( + ( + `vn`.`payment` `p` + JOIN `vn`.`bank` `b` ON(`b`.`id` = `p`.`bankFk`) + ) + JOIN `vn`.`accountingType` `at2` ON(`at2`.`id` = `b`.`cash`) + ) +WHERE `p`.`currencyFk` = 2 + AND `at2`.`code` = 'wireTransfer' + AND `p`.`supplierFk` <> 2213 +GROUP BY `p`.`received` diff --git a/db/routines/vn/views/exchangeReportSource.sql b/db/routines/vn/views/exchangeReportSource.sql new file mode 100644 index 000000000..6a2b9bb7e --- /dev/null +++ b/db/routines/vn/views/exchangeReportSource.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeReportSource` +AS SELECT `e`.`dated` AS `dated`, + cast(sum(`e`.`amountIn`) AS decimal(10, 2)) AS `amountIn`, + cast(sum(`e`.`rateIn`) AS decimal(10, 4)) AS `rateIn`, + cast(sum(`e`.`amountOut`) AS decimal(10, 2)) AS `amountOut`, + cast(sum(`e`.`rateOut`) AS decimal(10, 4)) AS `rateOut`, + cast(sum(`e`.`amountEntry`) AS decimal(10, 2)) AS `amountEntry`, + cast(sum(`e`.`rateEntry`) AS decimal(10, 4)) AS `rateEntry`, + cast( + IFNULL(`rr`.`value`, `rrc`.`simulatedValue`) AS decimal(10, 4) + ) AS `rateECB` +FROM ( + ( + `vn`.`exchangeReportSourcePrevious` `e` + LEFT JOIN `vn`.`referenceRate` `rr` ON(`rr`.`dated` = `e`.`dated`) + ) + JOIN `vn`.`referenceRateConfig` `rrc` ON(1) + ) +GROUP BY `e`.`dated` +ORDER BY `e`.`dated` diff --git a/db/routines/vn/views/exchangeReportSourcePrevious.sql b/db/routines/vn/views/exchangeReportSourcePrevious.sql new file mode 100644 index 000000000..b9e8ba8c1 --- /dev/null +++ b/db/routines/vn/views/exchangeReportSourcePrevious.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`exchangeReportSourcePrevious` +AS SELECT `exchangeInsuranceIn`.`dated` AS `dated`, + `exchangeInsuranceIn`.`amount` AS `amountIn`, + `exchangeInsuranceIn`.`rate` AS `rateIn`, + 0.00 AS `amountOut`, + 0.00 AS `rateOut`, + 0.00 AS `amountEntry`, + 0.00 AS `rateEntry` +FROM `vn`.`exchangeInsuranceIn` +UNION ALL +SELECT `exchangeInsuranceOut`.`received` AS `received`, + 0.00 AS `amountIn`, + 0.00 AS `ratedIn`, + `exchangeInsuranceOut`.`divisa` AS `amountOut`, + `exchangeInsuranceOut`.`rate` AS `ratedOut`, + 0.00 AS `amountEntry`, + 0.00 AS `rateEntry` +FROM `vn`.`exchangeInsuranceOut` +UNION ALL +SELECT `exchangeInsuranceEntry`.`dated` AS `dated`, + 0.00 AS `amountIn`, + 0.00 AS `ratedIn`, + 0.00 AS `amountOut`, + 0.00 AS `ratedOut`, + `exchangeInsuranceEntry`.`Dolares` AS `amountEntry`, + `exchangeInsuranceEntry`.`rate` AS `rateEntry` +FROM `vn`.`exchangeInsuranceEntry` diff --git a/db/routines/vn/views/expeditionCommon.sql b/db/routines/vn/views/expeditionCommon.sql new file mode 100644 index 000000000..f03966c05 --- /dev/null +++ b/db/routines/vn/views/expeditionCommon.sql @@ -0,0 +1,31 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionCommon` +AS SELECT `et`.`id` AS `truckFk`, + `et`.`eta` AS `eta`, + IFNULL(ucase(`et`.`description`), 'SIN ESCANEAR') AS `description`, + `es`.`palletFk` AS `palletFk`, + `t`.`routeFk` AS `routeFk`, + `es`.`id` AS `scanFk`, + `e`.`id` AS `expeditionFk`, + `r`.`expeditionTruckFk` AS `expeditionTruckFk`, + `t`.`warehouseFk` AS `warehouseFk`, + `e`.`created` AS `lastPacked`, + `t`.`id` AS `ticketFk` +FROM ( + ( + ( + ( + ( + `vn`.`expeditionTruck` `et` + LEFT JOIN `vn`.`routesMonitor` `r` ON(`et`.`id` = `r`.`expeditionTruckFk`) + ) + LEFT JOIN `vn`.`ticket` `t` ON(`r`.`routeFk` = `t`.`routeFk`) + ) + LEFT JOIN `vn`.`expedition` `e` ON(`t`.`id` = `e`.`ticketFk`) + ) + LEFT JOIN `vn`.`expeditionScan` `es` ON(`e`.`id` = `es`.`expeditionFk`) + ) + LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`es`.`palletFk` = `ep`.`id`) + ) +WHERE `et`.`eta` >= `util`.`VN_CURDATE`() diff --git a/db/routines/vn/views/expeditionPallet_Print.sql b/db/routines/vn/views/expeditionPallet_Print.sql new file mode 100644 index 000000000..0a41c95da --- /dev/null +++ b/db/routines/vn/views/expeditionPallet_Print.sql @@ -0,0 +1,39 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionPallet_Print` +AS SELECT `et2`.`description` AS `truck`, + `t`.`routeFk` AS `routeFk`, + `r`.`description` AS `zone`, + COUNT(`es`.`id`) AS `eti`, + `ep`.`id` AS `palletFk`, + `et`.`id` <=> `rm`.`expeditionTruckFk` AS `isMatch`, + `t`.`warehouseFk` AS `warehouseFk`, + IF( + `r`.`created` > util.VN_CURDATE() + INTERVAL 1 DAY, + ucase(dayname(`r`.`created`)), + NULL + ) AS `nombreDia` +FROM ( + ( + ( + ( + ( + ( + ( + `vn`.`expeditionTruck` `et` + JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`truckFk` = `et`.`id`) + ) + JOIN `vn`.`expeditionScan` `es` ON(`es`.`palletFk` = `ep`.`id`) + ) + JOIN `vn`.`expedition` `e` ON(`e`.`id` = `es`.`expeditionFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `e`.`ticketFk`) + ) + JOIN `vn`.`route` `r` ON(`r`.`id` = `t`.`routeFk`) + ) + LEFT JOIN `vn2008`.`Rutas_monitor` `rm` ON(`rm`.`Id_Ruta` = `r`.`id`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et2` ON(`et2`.`id` = `rm`.`expeditionTruckFk`) + ) +GROUP BY `ep`.`id`, + `t`.`routeFk` diff --git a/db/routines/vn/views/expeditionRoute_Monitor.sql b/db/routines/vn/views/expeditionRoute_Monitor.sql new file mode 100644 index 000000000..774f21433 --- /dev/null +++ b/db/routines/vn/views/expeditionRoute_Monitor.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionRoute_Monitor` +AS SELECT `r`.`id` AS `routeFk`, + COUNT(DISTINCT IF(`e`.`id` IS NULL, `t`.`id`, NULL)) AS `tickets`, + COUNT(DISTINCT `e`.`id`) AS `expeditions`, + COUNT(DISTINCT `es`.`id`) AS `scanned`, + max(`e`.`created`) AS `lastPacked`, + `r`.`created` AS `created` +FROM ( + ( + ( + ( + ( + `vn`.`route` `r` + LEFT JOIN `vn`.`routesMonitor` `rm` ON(`r`.`id` = `rm`.`routeFk`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `rm`.`expeditionTruckFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`routeFk` = `r`.`id`) + ) + LEFT JOIN `vn`.`expedition` `e` ON(`e`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `vn`.`expeditionScan` `es` ON(`es`.`expeditionFk` = `e`.`id`) + ) +WHERE `r`.`created` >= `util`.`yesterday`() +GROUP BY `r`.`id` diff --git a/db/routines/vn/views/expeditionRoute_freeTickets.sql b/db/routines/vn/views/expeditionRoute_freeTickets.sql new file mode 100644 index 000000000..2c25ac94f --- /dev/null +++ b/db/routines/vn/views/expeditionRoute_freeTickets.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionRoute_freeTickets` AS +SELECT + `t`.`routeFk` AS `routeFk`, + `tss`.`ticketFk` AS `ticket`, + `s`.`name` AS `code`, + `w`.`name` AS `almacen`, + `tss`.`updated` AS `updated`, + `p`.`code` AS `parkingCode` + FROM `vn`.`ticketState` `tss` + JOIN `vn`.`ticket` `t` ON `t`.`id` = `tss`.`ticketFk` + JOIN `vn`.`warehouse` `w` ON `w`.`id` = `t`.`warehouseFk` + JOIN `vn`.`state` `s` ON `s`.`id` = `tss`.`state` + LEFT JOIN `vn`.`ticketParking` `tp` ON `tp`.`ticketFk` = `t`.`id` + LEFT JOIN `vn`.`parking` `p` ON `p`.`id` = `tp`.`parkingFk` + WHERE IFNULL(`t`.`packages`, 0) = 0; \ No newline at end of file diff --git a/db/routines/vn/views/expeditionScan_Monitor.sql b/db/routines/vn/views/expeditionScan_Monitor.sql new file mode 100644 index 000000000..7566a0bfd --- /dev/null +++ b/db/routines/vn/views/expeditionScan_Monitor.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionScan_Monitor` +AS SELECT `et`.`id` AS `truckFk`, + `et`.`eta` AS `ETD`, + `et`.`description` AS `description`, + `ep`.`id` AS `palletFk`, + `ep`.`position` AS `position`, + `ep`.`built` AS `built`, + `es`.`id` AS `scanFk`, + `es`.`expeditionFk` AS `expeditionFk`, + `es`.`scanned` AS `scanned` +FROM ( + ( + `vn`.`expeditionTruck` `et` + LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`truckFk` = `et`.`id`) + ) + LEFT JOIN `vn`.`expeditionScan` `es` ON(`es`.`palletFk` = `ep`.`id`) + ) diff --git a/db/routines/vn/views/expeditionSticker.sql b/db/routines/vn/views/expeditionSticker.sql new file mode 100644 index 000000000..2b6bf18d2 --- /dev/null +++ b/db/routines/vn/views/expeditionSticker.sql @@ -0,0 +1,61 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionSticker` +AS SELECT `e`.`id` AS `expeditionFk`, + `e`.`ticketFk` AS `ticketFk`, + `t`.`addressFk` AS `addressFk`, + `t`.`clientFk` AS `clientFk`, + `a`.`street` AS `street`, + `a`.`postalCode` AS `postalCode`, + `a`.`city` AS `city`, + `a`.`nickname` AS `nickname`, + concat('R(', right(`t`.`routeFk`, 3), ')') AS `routeFk`, + `rm`.`beachFk` AS `beachFk`, + IF( + `t`.`routeFk`, + IFNULL( + `et`.`description`, + REPLACE(`am`.`name`, 'ZONA ', 'Z') + ), + `z`.`name` + ) AS `zona`, + `p`.`name` AS `province`, + IFNULL( + `c`.`mobile`, + IFNULL(`a`.`mobile`, IFNULL(`c`.`phone`, `a`.`phone`)) + ) AS `phone`, + `w`.`code` AS `workerCode` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + ( + ( + `vn`.`expedition` `e` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `e`.`ticketFk`) + ) + JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`) + ) + JOIN `vn`.`province` `p` ON(`p`.`id` = `a`.`provinceFk`) + ) + LEFT JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `rm`.`expeditionTruckFk`) + ) + LEFT JOIN `vn`.`beach` `b` ON(`b`.`code` = `rm`.`beachFk`) + ) + LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) + LEFT JOIN `vn`.`route` `r` ON(`r`.`id` = `t`.`routeFk`) + ) + LEFT JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `r`.`agencyModeFk`) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `a`.`clientFk`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `e`.`workerFk`) + ) diff --git a/db/routines/vn/views/expeditionTicket_NoBoxes.sql b/db/routines/vn/views/expeditionTicket_NoBoxes.sql new file mode 100644 index 000000000..080edd3ac --- /dev/null +++ b/db/routines/vn/views/expeditionTicket_NoBoxes.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionTicket_NoBoxes` +AS SELECT `t`.`id` AS `ticketFk`, + `t`.`warehouseFk` AS `warehouseFk`, + `t`.`routeFk` AS `routeFk`, + `et`.`description` AS `description` +FROM ( + ( + ( + `vn`.`ticket` `t` + LEFT JOIN `vn`.`expedition` `e` ON(`e`.`ticketFk` = `t`.`id`) + ) + JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`) + ) + JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `rm`.`expeditionTruckFk`) + ) +WHERE `e`.`id` IS NULL + AND `et`.`eta` > `util`.`VN_CURDATE`() diff --git a/db/routines/vn/views/expeditionTimeExpended.sql b/db/routines/vn/views/expeditionTimeExpended.sql new file mode 100644 index 000000000..65aeb72b2 --- /dev/null +++ b/db/routines/vn/views/expeditionTimeExpended.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionTimeExpended` +AS SELECT `e`.`ticketFk` AS `ticketFk`, + min(`e`.`created`) AS `started`, + max(`e`.`created`) AS `finished`, + max(`e`.`counter`) AS `cajas`, + `w`.`code` AS `code`, + `t`.`warehouseFk` AS `warehouseFk` +FROM ( + ( + `vn`.`expedition` `e` + JOIN `vn`.`worker` `w` ON(`w`.`id` = `e`.`workerFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `e`.`ticketFk`) + ) +WHERE `e`.`created` > `util`.`VN_CURDATE`() +GROUP BY `e`.`ticketFk` diff --git a/db/routines/vn/views/expeditionTruck_Control.sql b/db/routines/vn/views/expeditionTruck_Control.sql new file mode 100644 index 000000000..838e1f89e --- /dev/null +++ b/db/routines/vn/views/expeditionTruck_Control.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionTruck_Control` +AS SELECT `e`.`truckFk` AS `id`, + `e`.`eta` AS `ETD`, + `e`.`description` AS `description`, + COUNT( + DISTINCT IF(`e`.`expeditionFk` IS NULL, `e`.`ticketFk`, NULL) + ) AS `ticketsSinBultos`, + COUNT(DISTINCT `e`.`palletFk`) AS `pallets`, + COUNT(DISTINCT `e`.`routeFk`) AS `routes`, + COUNT(DISTINCT `e`.`scanFk`) AS `scans`, + COUNT(DISTINCT `e`.`expeditionFk`) AS `expeditions`, + sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + max(`e`.`lastPacked`) AS `lastPacked` +FROM `vn`.`expeditionCommon` `e` +GROUP BY `e`.`truckFk` +ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, + `e`.`eta` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail.sql b/db/routines/vn/views/expeditionTruck_Control_Detail.sql new file mode 100644 index 000000000..96a5b78e6 --- /dev/null +++ b/db/routines/vn/views/expeditionTruck_Control_Detail.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionTruck_Control_Detail` +AS SELECT `e`.`truckFk` AS `id`, + `e`.`eta` AS `eta`, + `e`.`description` AS `destino`, + `e`.`palletFk` AS `pallet`, + COUNT(DISTINCT `e`.`routeFk`) AS `routes`, + COUNT(DISTINCT `e`.`scanFk`) AS `scans`, + COUNT(DISTINCT `e`.`expeditionTruckFk`) AS `destinos`, + sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + max(`e`.`lastPacked`) AS `lastPacked` +FROM `vn`.`expeditionCommon` `e` +GROUP BY `e`.`truckFk`, + `e`.`palletFk` +ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, + `e`.`eta`, + `e`.`truckFk` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql new file mode 100644 index 000000000..01bdbf795 --- /dev/null +++ b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`expeditionTruck_Control_Detail_Pallet` +AS SELECT `e`.`truckFk` AS `id`, + `e`.`eta` AS `eta`, + `e`.`description` AS `destino`, + `e`.`palletFk` AS `pallet`, + `e`.`routeFk` AS `route`, + COUNT(DISTINCT `e`.`scanFk`) AS `scans`, + `et`.`description` AS `destinos`, + sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + `e`.`expeditionTruckFk` AS `expeditionTruckFk`, + max(`e`.`lastPacked`) AS `lastPacked` +FROM ( + `vn`.`expeditionCommon` `e` + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `e`.`expeditionTruckFk`) + ) +GROUP BY `e`.`truckFk`, + `e`.`palletFk`, + `e`.`routeFk` +ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, + `e`.`palletFk` diff --git a/db/routines/vn/views/firstTicketShipped.sql b/db/routines/vn/views/firstTicketShipped.sql new file mode 100644 index 000000000..c01a17976 --- /dev/null +++ b/db/routines/vn/views/firstTicketShipped.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`firstTicketShipped` +AS SELECT min(`vn`.`ticket`.`shipped`) AS `shipped`, + `vn`.`ticket`.`clientFk` AS `clientFk` +FROM `vn`.`ticket` +WHERE `vn`.`ticket`.`shipped` > '2001-01-01' +GROUP BY `vn`.`ticket`.`clientFk` diff --git a/db/routines/vn/views/floraHollandBuyedItems.sql b/db/routines/vn/views/floraHollandBuyedItems.sql new file mode 100644 index 000000000..b695c49fd --- /dev/null +++ b/db/routines/vn/views/floraHollandBuyedItems.sql @@ -0,0 +1,31 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`floraHollandBuyedItems` +AS SELECT `b`.`itemFk` AS `itemFk`, + `i`.`longName` AS `longName`, + `b`.`quantity` AS `quantity`, + `b`.`buyingValue` AS `buyingValue`, + `tr`.`landed` AS `landed`, + `e`.`companyFk` AS `companyFk` +FROM ( + ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) + ) + JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`) + ) + JOIN `vn`.`itemCategory` `ic` ON(`ic`.`id` = `it`.`categoryFk`) + ) + JOIN `vn`.`entry` `e` ON(`e`.`id` = `b`.`entryFk`) + ) + JOIN `vn`.`travel` `tr` ON( + `tr`.`id` = `e`.`travelFk` + AND `ic`.`id` NOT IN (8, 6) + AND `b`.`buyingValue` <> 0 + AND `b`.`quantity` <> 0 + AND `e`.`supplierFk` IN (1664, 1665, 1666, 1465, 1433) + ) + ) diff --git a/db/routines/vn/views/grantGroup.sql b/db/routines/vn/views/grantGroup.sql new file mode 100644 index 000000000..267c3154e --- /dev/null +++ b/db/routines/vn/views/grantGroup.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`grantGroup` +AS SELECT `vn2008`.`Grupos`.`id` AS `id`, + `vn2008`.`Grupos`.`Grupo` AS `description`, + `vn2008`.`Grupos`.`observation_type_id` AS `observationTypeFk` +FROM `vn2008`.`Grupos` diff --git a/db/routines/vn/views/inkL10n.sql b/db/routines/vn/views/inkL10n.sql new file mode 100644 index 000000000..14958ff0a --- /dev/null +++ b/db/routines/vn/views/inkL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`inkL10n` +AS SELECT `k`.`id` AS `id`, + IFNULL(`i`.`name`, `k`.`name`) AS `name` +FROM ( + `vn`.`ink` `k` + LEFT JOIN `vn`.`inkI18n` `i` ON( + `i`.`inkFk` = `k`.`id` + AND `i`.`lang` = `util`.`lang`() + ) + ) diff --git a/db/routines/vn/views/invoiceCorrectionDataSource.sql b/db/routines/vn/views/invoiceCorrectionDataSource.sql new file mode 100644 index 000000000..d401c20f1 --- /dev/null +++ b/db/routines/vn/views/invoiceCorrectionDataSource.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`invoiceCorrectionDataSource` +AS SELECT `s`.`itemFk` AS `itemFk`, + `s`.`quantity` AS `quantity`, + `s`.`concept` AS `concept`, + `s`.`price` AS `price`, + `s`.`discount` AS `discount`, + `t`.`refFk` AS `refFk`, + `s`.`id` AS `saleFk`, + `t`.`shipped` AS `shipped` +FROM ( + `vn`.`sale` `s` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) +WHERE `t`.`shipped` > `util`.`VN_CURDATE`() + INTERVAL -3 year diff --git a/db/routines/vn/views/itemBotanicalWithGenus.sql b/db/routines/vn/views/itemBotanicalWithGenus.sql new file mode 100644 index 000000000..3bc0b943d --- /dev/null +++ b/db/routines/vn/views/itemBotanicalWithGenus.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemBotanicalWithGenus` +AS SELECT `ib`.`itemFk` AS `itemFk`, + concat(`g`.`name`, ' ', IFNULL(`s`.`name`, '')) AS `ediBotanic` +FROM ( + ( + `vn`.`itemBotanical` `ib` + LEFT JOIN `vn`.`specie` `s` ON(`s`.`id` = `ib`.`specieFk`) + ) + LEFT JOIN `vn`.`genus` `g` ON(`g`.`id` = `ib`.`genusFk`) + ) diff --git a/db/routines/vn/views/itemCategoryL10n.sql b/db/routines/vn/views/itemCategoryL10n.sql new file mode 100644 index 000000000..08a7c7321 --- /dev/null +++ b/db/routines/vn/views/itemCategoryL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemCategoryL10n` +AS SELECT `c`.`id` AS `id`, + IFNULL(`i`.`name`, `c`.`name`) AS `name` +FROM ( + `vn`.`itemCategory` `c` + LEFT JOIN `vn`.`itemCategoryI18n` `i` ON( + `i`.`categoryFk` = `c`.`id` + AND `i`.`lang` = `util`.`lang`() + ) + ) diff --git a/db/routines/vn/views/itemColor.sql b/db/routines/vn/views/itemColor.sql new file mode 100644 index 000000000..5ab8a4c4f --- /dev/null +++ b/db/routines/vn/views/itemColor.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemColor` +AS SELECT `it`.`itemFk` AS `itemFk`, + `it`.`value` AS `color` +FROM ( + `vn`.`itemTag` `it` + JOIN `vn`.`tag` `t` ON(`t`.`id` = `it`.`tagFk`) + ) +WHERE `t`.`code` = 'COLOR' diff --git a/db/routines/vn/views/itemEntryIn.sql b/db/routines/vn/views/itemEntryIn.sql new file mode 100644 index 000000000..184ccbf59 --- /dev/null +++ b/db/routines/vn/views/itemEntryIn.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemEntryIn` +AS SELECT `t`.`warehouseInFk` AS `warehouseInFk`, + `t`.`landed` AS `landed`, + `b`.`itemFk` AS `itemFk`, + `b`.`quantity` AS `quantity`, + `t`.`isReceived` AS `isReceived`, + `e`.`isRaid` AS `isVirtualStock`, + `e`.`id` AS `entryFk` +FROM ( + ( + `vn`.`buy` `b` + JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) + ) + JOIN `vn`.`travel` `t` ON(`e`.`travelFk` = `t`.`id`) + ) +WHERE `e`.`isExcludedFromAvailable` = 0 + AND `b`.`quantity` <> 0 diff --git a/db/routines/vn/views/itemEntryOut.sql b/db/routines/vn/views/itemEntryOut.sql new file mode 100644 index 000000000..82b065985 --- /dev/null +++ b/db/routines/vn/views/itemEntryOut.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemEntryOut` +AS SELECT `t`.`warehouseOutFk` AS `warehouseOutFk`, + `t`.`shipped` AS `shipped`, + `b`.`itemFk` AS `itemFk`, + - `b`.`quantity` AS `quantity`, + `t`.`isDelivered` AS `isDelivered`, + `e`.`id` AS `entryFk` +FROM ( + ( + `vn`.`buy` `b` + JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) + ) + JOIN `vn`.`travel` `t` ON(`e`.`travelFk` = `t`.`id`) + ) +WHERE `e`.`isExcludedFromAvailable` = 0 + AND `e`.`isRaid` = 0 + AND `b`.`quantity` <> 0 diff --git a/db/routines/vn/views/itemInk.sql b/db/routines/vn/views/itemInk.sql new file mode 100644 index 000000000..d13a862e7 --- /dev/null +++ b/db/routines/vn/views/itemInk.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemInk` +AS SELECT `i`.`longName` AS `longName`, + `i`.`inkFk` AS `inkFk`, + `vn`.`ink`.`name` AS `color` +FROM ( + `vn`.`item` `i` + JOIN `vn`.`ink` ON(`vn`.`ink`.`id` = `i`.`inkFk`) + ) +WHERE `vn`.`ink`.`isRealColor` <> 0 +GROUP BY `i`.`longName` diff --git a/db/routines/vn/views/itemPlacementSupplyList.sql b/db/routines/vn/views/itemPlacementSupplyList.sql new file mode 100644 index 000000000..10e7ae3ef --- /dev/null +++ b/db/routines/vn/views/itemPlacementSupplyList.sql @@ -0,0 +1,34 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemPlacementSupplyList` +AS SELECT `ips`.`id` AS `id`, + `ips`.`itemFk` AS `itemFk`, + `ips`.`quantity` AS `quantity`, + `ips`.`priority` AS `priority`, + IFNULL(`isps`.`created`, `ips`.`created`) AS `created`, + `ips`.`userFk` AS `userFk`, + `ips`.`repoUserFk` AS `repoUserFk`, + `ips`.`quantity` - sum(IFNULL(`isps`.`quantity`, 0)) AS `saldo`, + concat(`i`.`longName`, ' ', `i`.`size`) AS `longName`, + `i`.`subName` AS `subName`, + `i`.`size` AS `size`, + `w`.`code` AS `workerCode`, + `rw`.`code` AS `repoCode`, + `ips`.`sectorFk` AS `sectorFk` +FROM ( + ( + ( + ( + `vn`.`itemPlacementSupply` `ips` + JOIN `vn`.`item` `i` ON(`i`.`id` = `ips`.`itemFk`) + ) + LEFT JOIN `vn`.`worker` `w` ON(`w`.`id` = `ips`.`userFk`) + ) + LEFT JOIN `vn`.`worker` `rw` ON(`rw`.`id` = `ips`.`repoUserFk`) + ) + LEFT JOIN `vn`.`itemShelvingPlacementSupply` `isps` ON(`isps`.`itemPlacementSupplyFk` = `ips`.`id`) + ) +WHERE `ips`.`created` >= `util`.`VN_CURDATE`() +GROUP BY `ips`.`priority`, + `ips`.`id`, + `ips`.`sectorFk` diff --git a/db/routines/vn/views/itemProductor.sql b/db/routines/vn/views/itemProductor.sql new file mode 100644 index 000000000..f6cb0eb19 --- /dev/null +++ b/db/routines/vn/views/itemProductor.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemProductor` +AS SELECT `it`.`itemFk` AS `itemFk`, + `it`.`value` AS `productor` +FROM ( + `vn`.`itemTag` `it` + JOIN `vn`.`tag` `t` ON(`t`.`id` = `it`.`tagFk`) + ) +WHERE `t`.`code` = 'PRODUCER' diff --git a/db/routines/vn/views/itemSearch.sql b/db/routines/vn/views/itemSearch.sql new file mode 100644 index 000000000..6a21b9e92 --- /dev/null +++ b/db/routines/vn/views/itemSearch.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemSearch` +AS SELECT `s`.`itemFk` AS `itemFk`, + `s`.`concept` AS `concept`, + `s`.`quantity` AS `quantity`, + `t`.`nickname` AS `nickname`, + `t`.`shipped` AS `shipped` +FROM ( + ( + `vn`.`sale` `s` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`) + ) +WHERE `t`.`shipped` BETWEEN `util`.`yesterday`() AND `util`.`tomorrow`() + AND `w`.`name` IN ('VNH', 'Floramondo') diff --git a/db/routines/vn/views/itemShelvingAvailable.sql b/db/routines/vn/views/itemShelvingAvailable.sql new file mode 100644 index 000000000..e9599a1db --- /dev/null +++ b/db/routines/vn/views/itemShelvingAvailable.sql @@ -0,0 +1,59 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingAvailable` +AS SELECT `s`.`id` AS `saleFk`, + `tst`.`updated` AS `Modificado`, + `s`.`ticketFk` AS `ticketFk`, + 0 AS `isPicked`, + `s`.`itemFk` AS `itemFk`, + `s`.`quantity` AS `quantity`, + `s`.`concept` AS `concept`, + `i`.`size` AS `size`, + `st`.`name` AS `Estado`, + `st`.`sectorProdPriority` AS `sectorProdPriority`, + `stock`.`visible` AS `available`, + `stock`.`sectorFk` AS `sectorFk`, + `stock`.`shelvingFk` AS `matricula`, + `stock`.`parkingFk` AS `parking`, + `stock`.`itemShelvingFk` AS `itemShelving`, + `am`.`name` AS `Agency`, + `t`.`shipped` AS `shipped`, + `stock`.`grouping` AS `grouping`, + `stock`.`packing` AS `packing`, + `z`.`hour` AS `hour`, + `st`.`isPreviousPreparable` AS `isPreviousPreparable`, + `sv`.`physicalVolume` AS `physicalVolume`, + `t`.`warehouseFk` AS `warehouseFk` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + `vn`.`sale` `s` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`) + ) + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `t`.`id`) + ) + JOIN `vn`.`state` `st` ON(`st`.`id` = `tst`.`state`) + ) + JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`) + ) + JOIN `vn`.`itemShelvingStock` `stock` ON(`stock`.`itemFk` = `i`.`id`) + ) + LEFT JOIN `vn`.`saleTracking` `stk` ON(`stk`.`saleFk` = `s`.`id`) + ) + LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) + LEFT JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`) + ) +WHERE `t`.`shipped` BETWEEN `util`.`yesterday`() AND `util`.`dayend`(`util`.`VN_CURDATE`()) + AND `stk`.`id` IS NULL + AND `stock`.`visible` > 0 + AND `stk`.`saleFk` IS NULL + AND `st`.`isPreviousPreparable` <> 0 diff --git a/db/routines/vn/views/itemShelvingList.sql b/db/routines/vn/views/itemShelvingList.sql new file mode 100644 index 000000000..570bf0be6 --- /dev/null +++ b/db/routines/vn/views/itemShelvingList.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingList` +AS SELECT `ish`.`shelvingFk` AS `shelvingFk`, + `ish`.`visible` AS `visible`, + `ish`.`created` AS `created`, + `pk`.`code` AS `parking`, + `ish`.`itemFk` AS `itemFk`, + `i`.`longName` AS `longName`, + `i`.`size` AS `size`, + `i`.`subName` AS `subName`, + `sh`.`parked` AS `parked`, + `pk`.`sectorFk` AS `sectorFk` +FROM ( + ( + ( + `vn`.`itemShelving` `ish` + JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) + ) + JOIN `vn`.`item` `i` ON(`i`.`id` = `ish`.`itemFk`) + ) + LEFT JOIN `vn`.`parking` `pk` ON(`pk`.`id` = `sh`.`parkingFk`) + ) +ORDER BY `ish`.`created` diff --git a/db/routines/vn/views/itemShelvingPlacementSupplyStock.sql b/db/routines/vn/views/itemShelvingPlacementSupplyStock.sql new file mode 100644 index 000000000..217aaf6ac --- /dev/null +++ b/db/routines/vn/views/itemShelvingPlacementSupplyStock.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingPlacementSupplyStock` +AS SELECT `ish`.`id` AS `itemShelvingFk`, + `ish`.`itemFk` AS `itemFk`, + `ish`.`packing` AS `packing`, + `ish`.`visible` AS `stock`, + `i`.`longName` AS `longName`, + `i`.`size` AS `size`, + `i`.`subName` AS `subName`, + `sh`.`code` AS `shelving`, + `p`.`code` AS `parking`, + `ish`.`created` AS `created`, + IFNULL(`sh`.`priority`, 1) AS `priority`, + `p`.`id` AS `parkingFk`, + `p`.`sectorFk` AS `sectorFk` +FROM ( + ( + ( + `vn`.`itemShelving` `ish` + JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) + ) + LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) + ) + JOIN `vn`.`item` `i` ON(`i`.`id` = `ish`.`itemFk`) + ) +GROUP BY `ish`.`id` diff --git a/db/routines/vn/views/itemShelvingSaleSum.sql b/db/routines/vn/views/itemShelvingSaleSum.sql new file mode 100644 index 000000000..566e20a69 --- /dev/null +++ b/db/routines/vn/views/itemShelvingSaleSum.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingSaleSum` +AS SELECT `iss`.`id` AS `id`, + `iss`.`itemShelvingFk` AS `itemShelvingFk`, + `iss`.`saleFk` AS `saleFk`, + sum(`iss`.`quantity`) AS `quantity`, + `iss`.`created` AS `created`, + `p`.`sectorFk` AS `sectorFk` +FROM ( + ( + ( + `vn`.`itemShelvingSale` `iss` + JOIN `vn`.`itemShelving` `ish` ON(`ish`.`id` = `iss`.`itemShelvingFk`) + ) + JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) + ) + JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) + ) +GROUP BY `iss`.`saleFk` diff --git a/db/routines/vn/views/itemShelvingStock.sql b/db/routines/vn/views/itemShelvingStock.sql new file mode 100644 index 000000000..c4057d7f0 --- /dev/null +++ b/db/routines/vn/views/itemShelvingStock.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingStock` AS +SELECT ish.itemFk, + SUM(ish.visible) visible, + MIN(ish.packing) packing, + MIN(ish.`grouping`) `grouping`, + s.description sector, + SUM(ish.visible) visibleOriginal, + 0 removed, + p.sectorFk, + s.warehouseFk, + ish.shelvingFk, + p.code, + sh.parkingFk, + ish.id itemShelvingFk, + ish.created, + st.description = 'previousPrepared' isPreviousPrepared + FROM itemShelving ish + LEFT JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = sh.parkingFk + LEFT JOIN sector s ON s.id = p.sectorFk + LEFT JOIN sectorType st ON st.id = s.typeFk + WHERE ish.visible <> 0 + AND p.sectorFk <> 0 + GROUP BY ish.itemFk, + p.sectorFk diff --git a/db/routines/vn/views/itemShelvingStockFull.sql b/db/routines/vn/views/itemShelvingStockFull.sql new file mode 100644 index 000000000..71ce5ed79 --- /dev/null +++ b/db/routines/vn/views/itemShelvingStockFull.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingStockFull` +AS SELECT `ish`.`itemFk` AS `itemFk`, + `ish`.`visible` AS `quantity`, + `ish`.`packing` AS `packing`, + `ish`.`grouping` AS `grouping`, + `s`.`description` AS `sector`, + `issr`.`removed` AS `removed`, + `p`.`sectorFk` AS `sectorFk`, + `s`.`warehouseFk` AS `warehouseFk`, + `ish`.`shelvingFk` AS `shelvingFk`, + `p`.`code` AS `parkingCode`, + `sh`.`parkingFk` AS `parkingFk`, + `ish`.`id` AS `itemShelvingFk`, + `ish`.`created` AS `created` +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`) + ) + LEFT JOIN `vn`.`itemShelvingStockRemoved` `issr` ON(`issr`.`itemShelvingFk` = `ish`.`id`) + ) diff --git a/db/routines/vn/views/itemShelvingStockRemoved.sql b/db/routines/vn/views/itemShelvingStockRemoved.sql new file mode 100644 index 000000000..fb201e0f1 --- /dev/null +++ b/db/routines/vn/views/itemShelvingStockRemoved.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingStockRemoved` +AS SELECT `ish`.`id` AS `itemShelvingFk`, + `ish`.`itemFk` AS `itemFk`, + 0 AS `removed` +FROM ( + ( + `vn`.`itemShelving` `ish` + LEFT JOIN `vn`.`itemShelvingSale` `iss` ON(`iss`.`itemShelvingFk` = `ish`.`id`) + ) + LEFT JOIN `vn`.`itemShelvingPlacementSupply` `isps` ON(`isps`.`itemShelvingFk` = `ish`.`id`) + ) +GROUP BY `ish`.`id` diff --git a/db/routines/vn/views/itemTagged.sql b/db/routines/vn/views/itemTagged.sql new file mode 100644 index 000000000..c22354bda --- /dev/null +++ b/db/routines/vn/views/itemTagged.sql @@ -0,0 +1,5 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemTagged` +AS SELECT DISTINCT `vn`.`itemTag`.`itemFk` AS `itemFk` +FROM `vn`.`itemTag` diff --git a/db/routines/vn/views/itemTaxCountrySpain.sql b/db/routines/vn/views/itemTaxCountrySpain.sql new file mode 100644 index 000000000..9dfaf0b41 --- /dev/null +++ b/db/routines/vn/views/itemTaxCountrySpain.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemTaxCountrySpain` +AS SELECT `i`.`id` AS `id`, + `i`.`name` AS `name`, + `i`.`typeFk` AS `typeFk`, + `i`.`stems` AS `stems`, + `i`.`description` AS `description`, + `i`.`intrastatFk` AS `intrastatFk`, + `i`.`expenseFk` AS `expenseFk`, + `i`.`comment` AS `comment`, + `i`.`relevancy` AS `relevancy`, + `i`.`image` AS `image`, + `i`.`generic` AS `generic`, + `itc`.`taxClassFk` AS `taxClassFk` +FROM ( + `vn`.`item` `i` + JOIN `vn`.`itemTaxCountry` `itc` ON(`itc`.`itemFk` = `i`.`id`) + ) +WHERE `itc`.`countryFk` = 1 diff --git a/db/routines/vn/views/itemTicketOut.sql b/db/routines/vn/views/itemTicketOut.sql new file mode 100644 index 000000000..d9bbd54bd --- /dev/null +++ b/db/routines/vn/views/itemTicketOut.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemTicketOut` +AS SELECT `t`.`warehouseFk` AS `warehouseFk`, + `t`.`shipped` AS `shipped`, + `s`.`itemFk` AS `itemFk`, + - `s`.`quantity` AS `quantity`, + `s`.`isPicked` AS `isPicked`, + `s`.`reserved` AS `reserved`, + `t`.`refFk` AS `refFk`, + `s`.`id` AS `saleFk`, + `s`.`ticketFk` AS `ticketFk` +FROM ( + `vn`.`sale` `s` + JOIN `vn`.`ticket` `t` ON(`s`.`ticketFk` = `t`.`id`) + ) +WHERE `s`.`quantity` <> 0 diff --git a/db/routines/vn/views/itemTypeL10n.sql b/db/routines/vn/views/itemTypeL10n.sql new file mode 100644 index 000000000..03d72f0d4 --- /dev/null +++ b/db/routines/vn/views/itemTypeL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemTypeL10n` +AS SELECT `t`.`id` AS `id`, + IFNULL(`i`.`name`, `t`.`name`) AS `name` +FROM ( + `vn`.`itemType` `t` + LEFT JOIN `vn`.`itemTypeI18n` `i` ON( + `i`.`typeFk` = `t`.`id` + AND `i`.`lang` = `util`.`LANG`() + ) + ) diff --git a/db/routines/vn/views/item_Free_Id.sql b/db/routines/vn/views/item_Free_Id.sql new file mode 100644 index 000000000..36464004c --- /dev/null +++ b/db/routines/vn/views/item_Free_Id.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`item_Free_Id` +AS SELECT `i1`.`id` + 1 AS `newId` +FROM ( + `vn`.`item` `i1` + LEFT JOIN `vn`.`item` `i2` ON(`i1`.`id` + 1 = `i2`.`id`) + ) +WHERE `i2`.`id` IS NULL + AND `i1`.`isFloramondo` <> 0 diff --git a/db/routines/vn/views/labelInfo.sql b/db/routines/vn/views/labelInfo.sql new file mode 100644 index 000000000..ccc6fc6ac --- /dev/null +++ b/db/routines/vn/views/labelInfo.sql @@ -0,0 +1,35 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`labelInfo` +AS SELECT `i`.`id` AS `itemId`, + `i`.`name` AS `itemName`, + `b`.`stickers` AS `stickers`, + `b`.`printedStickers` AS `life`, + `i`.`inkFk` AS `colorCode`, + `i`.`stems` AS `stems`, + `i`.`category` AS `category`, + `i`.`subName` AS `productor`, + `b`.`packing` AS `packing`, + `clb`.`warehouse_id` AS `warehouse_id`, + `i`.`size` AS `size`, + `b`.`isPickedOff` AS `isPickedOff`, + `e`.`evaNotes` AS `notes`, + `w`.`name` AS `wh_in`, + `e`.`id` AS `entryId`, + `b`.`id` AS `buyId` +FROM ( + ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`item` `i` ON(`i`.`id` = `b`.`itemFk`) + ) + JOIN `cache`.`last_buy` `clb` ON(`clb`.`item_id` = `i`.`id`) + ) + JOIN `vn`.`entry` `e` ON(`e`.`id` = `b`.`entryFk`) + ) + LEFT JOIN `vn`.`travel` `tr` ON(`tr`.`id` = `e`.`travelFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `tr`.`warehouseInFk`) + ) diff --git a/db/routines/vn/views/lastHourProduction.sql b/db/routines/vn/views/lastHourProduction.sql new file mode 100644 index 000000000..90bc0cd76 --- /dev/null +++ b/db/routines/vn/views/lastHourProduction.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`lastHourProduction` +AS SELECT `t`.`warehouseFk` AS `warehouseFk`, + cast( + sum( + IFNULL( + `p`.`volume`, + `p`.`width` * `p`.`height` * `p`.`depth` + ) / 1000000 + ) AS decimal(5, 1) + ) AS `m3` +FROM ( + ( + ( + `vn`.`warehouse` `w` + JOIN `vn`.`ticket` `t` ON(`t`.`warehouseFk` = `w`.`id`) + ) + LEFT JOIN `vn`.`expedition` `e` ON(`t`.`id` = `e`.`ticketFk`) + ) + LEFT JOIN `vn`.`packaging` `p` ON(`p`.`id` = `e`.`packagingFk`) + ) +WHERE `e`.`created` BETWEEN `util`.`VN_NOW`() - INTERVAL 1 HOUR + AND `util`.`VN_NOW`() +GROUP BY `t`.`warehouseFk` diff --git a/db/routines/vn/views/lastPurchases.sql b/db/routines/vn/views/lastPurchases.sql new file mode 100644 index 000000000..04a9f8c05 --- /dev/null +++ b/db/routines/vn/views/lastPurchases.sql @@ -0,0 +1,35 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`lastPurchases` +AS SELECT `tr`.`landed` AS `landed`, + `w`.`id` AS `warehouseFk`, + `w`.`name` AS `warehouse`, + `i`.`longName` AS `longName`, + `i`.`subName` AS `subName`, + `e`.`id` AS `entryFk`, + `b`.`stickers` AS `stickers`, + `b`.`packing` AS `packing`, + `e`.`invoiceNumber` AS `ref`, + `b`.`itemFk` AS `itemFk`, + `ek`.`pro` AS `pro`, + `ek`.`ref` AS `ektRef`, + `ek`.`agj` AS `agj` +FROM ( + ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`entry` `e` ON(`e`.`id` = `b`.`entryFk`) + ) + JOIN `vn`.`item` `i` ON(`i`.`id` = `b`.`itemFk`) + ) + JOIN `vn`.`travel` `tr` ON(`tr`.`id` = `e`.`travelFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `tr`.`warehouseInFk`) + ) + LEFT JOIN `edi`.`ekt` `ek` ON(`ek`.`id` = `b`.`ektFk`) + ) +WHERE `tr`.`landed` BETWEEN `util`.`yesterday`() AND `util`.`tomorrow`() + AND `e`.`isRaid` = 0 + AND `b`.`stickers` > 0 diff --git a/db/routines/vn/views/lastTopClaims.sql b/db/routines/vn/views/lastTopClaims.sql new file mode 100644 index 000000000..0bc36e3c2 --- /dev/null +++ b/db/routines/vn/views/lastTopClaims.sql @@ -0,0 +1,38 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`lastTopClaims` +AS SELECT `s`.`itemFk` AS `itemFk`, + `i`.`longName` AS `itemName`, + `it`.`name` AS `itemTypeName`, + COUNT(0) AS `claimsNumber`, + round( + sum( + `cb`.`quantity` * `s`.`price` * (1 - (`c`.`responsibility` - 1) / 4) * (100 - `s`.`discount`) / 100 + ), + 2 + ) AS `claimedAmount`, + round( + sum( + `cb`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100 + ), + 2 + ) AS `totalAmount` +FROM ( + ( + ( + ( + `vn`.`claim` `c` + JOIN `vn`.`claimBeginning` `cb` ON(`cb`.`claimFk` = `c`.`id`) + ) + JOIN `vn`.`sale` `s` ON(`s`.`id` = `cb`.`saleFk`) + ) + JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`) + ) + JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`) + ) +WHERE `c`.`created` >= `util`.`VN_CURDATE`() + INTERVAL -1 week +GROUP BY `s`.`itemFk` +HAVING `claimedAmount` > 100 + AND `claimsNumber` > 2 + OR `claimsNumber` > 4 +ORDER BY COUNT(0) DESC diff --git a/db/routines/vn/views/mistake.sql b/db/routines/vn/views/mistake.sql new file mode 100644 index 000000000..0ed4dccf2 --- /dev/null +++ b/db/routines/vn/views/mistake.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`mistake` +AS SELECT `wr`.`code` AS `revisador`, + `s`.`concept` AS `concept`, + `w`.`code` AS `sacador`, + `w`.`firstName` AS `firstName`, + `w`.`lastName` AS `lastName`, + `mt`.`description` AS `description`, + cast(`iss`.`created` AS date) AS `created`, + `w`.`id` AS `workerFk` +FROM ( + ( + ( + ( + ( + `vn`.`saleMistake` `sm` + JOIN `vn`.`mistakeType` `mt` ON(`mt`.`id` = `sm`.`typeFk`) + ) + JOIN `vn`.`worker` `wr` ON(`wr`.`id` = `sm`.`userFk`) + ) + JOIN `vn`.`sale` `s` ON(`s`.`id` = `sm`.`saleFk`) + ) + JOIN `vn`.`itemShelvingSale` `iss` ON(`iss`.`saleFk` = `sm`.`saleFk`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `iss`.`userFk`) + ) diff --git a/db/routines/vn/views/mistakeRatio.sql b/db/routines/vn/views/mistakeRatio.sql new file mode 100644 index 000000000..4b7fd5a1f --- /dev/null +++ b/db/routines/vn/views/mistakeRatio.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`mistakeRatio` +AS SELECT `wr`.`code` AS `revisador`, + `w`.`code` AS `sacador`, + `w`.`firstName` AS `firstName`, + `w`.`lastName` AS `lastName`, + `mt`.`description` AS `description`, + cast(`iss`.`created` AS date) AS `created`, + `w`.`id` AS `workerFk`, + `sm`.`saleFk` AS `saleFk` +FROM ( + ( + ( + ( + `vn`.`itemShelvingSale` `iss` + JOIN `vn`.`worker` `w` ON(`w`.`id` = `iss`.`userFk`) + ) + LEFT JOIN `vn`.`saleMistake` `sm` ON(`iss`.`saleFk` = `sm`.`saleFk`) + ) + LEFT JOIN `vn`.`mistakeType` `mt` ON(`mt`.`id` = `sm`.`typeFk`) + ) + LEFT JOIN `vn`.`worker` `wr` ON(`wr`.`id` = `sm`.`userFk`) + ) diff --git a/db/routines/vn/views/newBornSales.sql b/db/routines/vn/views/newBornSales.sql new file mode 100644 index 000000000..d34eff4ef --- /dev/null +++ b/db/routines/vn/views/newBornSales.sql @@ -0,0 +1,26 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`newBornSales` +AS SELECT `v`.`importe` AS `amount`, + `v`.`Id_Cliente` AS `clientFk`, + `c`.`salesPersonFk` AS `userFk`, + `v`.`fecha` AS `dated`, + `cn`.`firstShipped` AS `firstShipped` +FROM ( + ( + ( + ( + `bs`.`clientNewBorn` `cn` + JOIN `bs`.`ventas` `v` ON( + `cn`.`firstShipped` + INTERVAL 1 year > `v`.`fecha` + AND `v`.`Id_Cliente` = `cn`.`clientFk` + ) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `v`.`Id_Cliente`) + ) + JOIN `account`.`user` `u` ON(`u`.`id` = `c`.`salesPersonFk`) + ) + JOIN `account`.`role` `r` ON(`r`.`id` = `u`.`role`) + ) +WHERE `r`.`name` = 'salesPerson' + AND `u`.`name` NOT IN ('ismaelalcolea', 'ruben') diff --git a/db/routines/vn/views/operatorWorkerCode.sql b/db/routines/vn/views/operatorWorkerCode.sql new file mode 100644 index 000000000..340d833a7 --- /dev/null +++ b/db/routines/vn/views/operatorWorkerCode.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`operatorWorkerCode` +AS SELECT `o`.`workerFk` AS `workerFk`, + concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `fullName`, + `w`.`code` AS `code`, + `o`.`numberOfWagons` AS `numberOfWagons` +FROM ( + ( + `vn`.`worker` `w` + JOIN `vn`.`operator` `o` ON(`o`.`workerFk` = `w`.`id`) + ) + JOIN `vn`.`sector` `s` ON(`o`.`sectorFk` = `s`.`id`) + ) +WHERE `o`.`sectorFk` IS NOT NULL + AND `s`.`code` IN ( + 'H2', + 'H2', + 'PEQUES_H', + 'ALTILLO COMP', + 'ALTILLO ARTI' + ) diff --git a/db/routines/vn/views/originL10n.sql b/db/routines/vn/views/originL10n.sql new file mode 100644 index 000000000..2ff368e14 --- /dev/null +++ b/db/routines/vn/views/originL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`originL10n` +AS SELECT `o`.`id` AS `id`, + IFNULL(`i`.`name`, `o`.`name`) AS `name` +FROM ( + `vn`.`origin` `o` + LEFT JOIN `vn`.`originI18n` `i` ON( + `i`.`originFk` = `o`.`id` + AND `i`.`lang` = `util`.`lang`() + ) + ) diff --git a/db/routines/vn/views/packageEquivalentItem.sql b/db/routines/vn/views/packageEquivalentItem.sql new file mode 100644 index 000000000..ba2897c14 --- /dev/null +++ b/db/routines/vn/views/packageEquivalentItem.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`packageEquivalentItem` +AS SELECT `p`.`itemFk` AS `itemFk`, + `p2`.`itemFk` AS `equivalentFk` +FROM ( + ( + `vn`.`packageEquivalent` `pe` + JOIN `vn`.`packaging` `p` ON(`p`.`id` = `pe`.`packagingFk`) + ) + JOIN `vn`.`packaging` `p2` ON(`p2`.`id` = `pe`.`equivalentFk`) + ) diff --git a/db/routines/vn/views/paymentExchangeInsurance.sql b/db/routines/vn/views/paymentExchangeInsurance.sql new file mode 100644 index 000000000..7128144ea --- /dev/null +++ b/db/routines/vn/views/paymentExchangeInsurance.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`paymentExchangeInsurance` +AS SELECT `p`.`pago_sdc_id` AS `id`, + `p`.`importe` AS `amount`, + `p`.`fecha` AS `created`, + `p`.`vencimiento` AS `dueDay`, + `p`.`entity_id` AS `entityFk`, + `p`.`ref` AS `ref`, + `p`.`rate` AS `rate`, + `p`.`empresa_id` AS `companyFk`, + `p`.`financialProductTypefk` AS `financialProductTypefk`, + `p`.`upperBarrier` AS `upperBarrier`, + `p`.`lowerBarrier` AS `lowerBarrier`, + `p`.`strike` AS `strike` +FROM `vn2008`.`pago_sdc` `p` diff --git a/db/routines/vn/views/payrollCenter.sql b/db/routines/vn/views/payrollCenter.sql new file mode 100644 index 000000000..fc6635483 --- /dev/null +++ b/db/routines/vn/views/payrollCenter.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`payrollCenter` +AS SELECT `b`.`cod_centro` AS `codCenter`, + `b`.`Centro` AS `name`, + `b`.`nss_cotizacion` AS `nss`, + `b`.`domicilio` AS `street`, + `b`.`poblacion` AS `city`, + `b`.`cp` AS `postcode`, + `b`.`empresa_id` AS `companyFk`, + `b`.`codempresa` AS `companyCode` +FROM `vn2008`.`payroll_centros` `b` diff --git a/db/routines/vn/views/personMedia.sql b/db/routines/vn/views/personMedia.sql new file mode 100644 index 000000000..d17410ef1 --- /dev/null +++ b/db/routines/vn/views/personMedia.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`personMedia` +AS SELECT `c`.`id` AS `workerFk`, + IFNULL(`c`.`mobile`, `c`.`phone`) AS `mediaValue` +FROM ( + `vn`.`client` `c` + JOIN `vn`.`worker` `w` ON(`w`.`id` = `c`.`id`) + ) +HAVING `mediaValue` IS NOT NULL diff --git a/db/routines/vn/views/phoneBook.sql b/db/routines/vn/views/phoneBook.sql new file mode 100644 index 000000000..5fcafe99c --- /dev/null +++ b/db/routines/vn/views/phoneBook.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`phoneBook` +AS SELECT 'C' AS `Tipo`, + `vn`.`client`.`id` AS `Id`, + `vn`.`client`.`name` AS `Cliente`, + `vn`.`client`.`phone` AS `Telefono` +FROM `vn`.`client` +WHERE `vn`.`client`.`phone` IS NOT NULL +UNION +SELECT 'C' AS `Tipo`, + `vn`.`client`.`id` AS `Id`, + `vn`.`client`.`name` AS `Cliente`, + `vn`.`client`.`mobile` AS `Movil` +FROM `vn`.`client` +WHERE `vn`.`client`.`mobile` IS NOT NULL +UNION +SELECT 'C' AS `Tipo`, + `vn`.`clientContact`.`clientFk` AS `clientFk`, + `vn`.`clientContact`.`name` AS `name`, + `vn`.`clientContact`.`phone` AS `phone` +FROM `vn`.`clientContact` diff --git a/db/routines/vn/views/preparationException.sql b/db/routines/vn/views/preparationException.sql new file mode 100644 index 000000000..ba624ad27 --- /dev/null +++ b/db/routines/vn/views/preparationException.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`preparationException` +AS SELECT `p`.`exception_day` AS `exceptionDay`, + `p`.`warehouse_id` AS `warehouseFk`, + `p`.`percentage` AS `percentage` +FROM `vn2008`.`preparation_exception` `p` diff --git a/db/routines/vn/views/productionVolume.sql b/db/routines/vn/views/productionVolume.sql new file mode 100644 index 000000000..fd83b96bc --- /dev/null +++ b/db/routines/vn/views/productionVolume.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`productionVolume` +AS SELECT HOUR(`e`.`created`) AS `hora`, + MINUTE(`e`.`created`) AS `minuto`, + IFNULL( + `p`.`volume`, + IFNULL(`p`.`width` * `p`.`height` * `p`.`depth`, 94500) + ) AS `cm3`, + `t`.`warehouseFk` AS `warehouseFk`, + `e`.`created` AS `created` +FROM ( + ( + ( + `vn`.`expedition` `e` + LEFT JOIN `vn`.`packaging` `p` ON(`p`.`id` = `e`.`packagingFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `e`.`ticketFk`) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`) + ) +WHERE `e`.`created` BETWEEN `util`.`VN_CURDATE`() AND `util`.`dayend`(`util`.`VN_CURDATE`()) + AND `c`.`isRelevant` <> 0 diff --git a/db/routines/vn/views/productionVolume_LastHour.sql b/db/routines/vn/views/productionVolume_LastHour.sql new file mode 100644 index 000000000..561a23f9b --- /dev/null +++ b/db/routines/vn/views/productionVolume_LastHour.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`productionVolume_LastHour` +AS SELECT cast( + sum(`productionVolume`.`cm3` / 1000000) AS decimal(10, 0) + ) AS `m3`, + `productionVolume`.`warehouseFk` AS `warehouseFk` +FROM `vn`.`productionVolume` +WHERE `productionVolume`.`created` > `util`.`VN_NOW`() + INTERVAL -1 HOUR + AND `productionVolume`.`warehouseFk` IN (1, 44, 60) +GROUP BY `productionVolume`.`warehouseFk` diff --git a/db/routines/vn/views/promissoryNote.sql b/db/routines/vn/views/promissoryNote.sql new file mode 100644 index 000000000..a9f047285 --- /dev/null +++ b/db/routines/vn/views/promissoryNote.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`promissoryNote` +AS SELECT `p`.`Id_Pagare` AS `id`, + `p`.`Concepto` AS `Concept`, + `p`.`pago_id` AS `paymentFk` +FROM `vn2008`.`Pagares` `p` diff --git a/db/routines/vn/views/role.sql b/db/routines/vn/views/role.sql new file mode 100644 index 000000000..310951570 --- /dev/null +++ b/db/routines/vn/views/role.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`role` +AS SELECT `account`.`role`.`id` AS `id`, + `account`.`role`.`name` AS `name`, + `account`.`role`.`description` AS `description`, + `account`.`role`.`hasLogin` AS `hasLogin` +FROM `account`.`role` diff --git a/db/routines/vn/views/routesControl.sql b/db/routines/vn/views/routesControl.sql new file mode 100644 index 000000000..380d9d9ce --- /dev/null +++ b/db/routines/vn/views/routesControl.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`routesControl` +AS SELECT `t`.`routeFk` AS `routeFk`, + COUNT(`e`.`id`) AS `expeditions`, + COUNT(`es`.`id`) AS `scanned`, + COUNT(DISTINCT `es`.`palletFk`) AS `pallets`, + max(`es`.`scanned`) AS `lastScanned`, + max(`et`.`description`) AS `description`, + max(`et`.`eta`) AS `eta` +FROM ( + ( + ( + ( + `vn`.`ticket` `t` + JOIN `vn`.`expedition` `e` ON(`t`.`id` = `e`.`ticketFk`) + ) + LEFT JOIN `vn`.`expeditionScan` `es` ON(`es`.`expeditionFk` = `e`.`id`) + ) + LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`id` = `es`.`palletFk`) + ) + LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `ep`.`truckFk`) + ) +WHERE `t`.`shipped` >= `util`.`VN_CURDATE`() + AND `t`.`routeFk` <> 0 +GROUP BY `t`.`routeFk` +ORDER BY max(`et`.`eta`) diff --git a/db/routines/vn/views/saleCost.sql b/db/routines/vn/views/saleCost.sql new file mode 100644 index 000000000..27265aa93 --- /dev/null +++ b/db/routines/vn/views/saleCost.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleCost` +AS SELECT `s`.`itemFk` AS `itemFk`, + `s`.`ticketFk` AS `ticketFk`, + `s`.`concept` AS `concept`, + `s`.`quantity` AS `quantity`, + `s`.`discount` AS `discount`, + `s`.`price` AS `price`, + `c`.`name` AS `component`, + `sc`.`value` AS `coste` +FROM ( + ( + ( + `vn`.`sale` `s` + JOIN `vn`.`saleComponent` `sc` ON(`sc`.`saleFk` = `s`.`id`) + ) + JOIN `vn`.`component` `c` ON(`c`.`id` = `sc`.`componentFk`) + ) + JOIN `vn`.`componentType` `ct` ON(`ct`.`id` = `c`.`typeFk`) + ) +WHERE `ct`.`type` = 'coste' diff --git a/db/routines/vn/views/saleLabel.sql b/db/routines/vn/views/saleLabel.sql new file mode 100644 index 000000000..4feae9294 --- /dev/null +++ b/db/routines/vn/views/saleLabel.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleLabel` +AS SELECT `ml`.`Id_movimiento` AS `saleFk`, + `ml`.`label` AS `label`, + `ml`.`stem` AS `stem`, + `ml`.`created` AS `created` +FROM `vn2008`.`movement_label` `ml` diff --git a/db/routines/vn/views/saleMistakeList.sql b/db/routines/vn/views/saleMistakeList.sql new file mode 100644 index 000000000..d362e0d97 --- /dev/null +++ b/db/routines/vn/views/saleMistakeList.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleMistakeList` +AS SELECT `st`.`saleFk` AS `saleFk`, + `st`.`workerFk` AS `workerFk`, + concat(`w2`.`firstName`, ' ', `w2`.`lastName`) AS `sacador`, + `st`.`created` AS `created`, + concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `revisador`, + `mt`.`description` AS `description`, + `sm`.`created` AS `controlled` +FROM ( + ( + ( + ( + ( + `vn`.`saleTracking` `st` + JOIN `vn`.`worker` `w2` ON(`w2`.`id` = `st`.`workerFk`) + ) + JOIN `vn`.`state` `s` ON( + `s`.`id` = `st`.`stateFk` + AND `s`.`code` IN ('PREVIOUS_PREPARATION', 'PREPARED', 'OK') + ) + ) + LEFT JOIN `vn`.`saleMistake` `sm` ON(`st`.`saleFk` = `sm`.`saleFk`) + ) + LEFT JOIN `vn`.`mistakeType` `mt` ON(`mt`.`id` = `sm`.`typeFk`) + ) + LEFT JOIN `vn`.`worker` `w` ON(`w`.`id` = `sm`.`userFk`) + ) diff --git a/db/routines/vn/views/saleMistake_list__2.sql b/db/routines/vn/views/saleMistake_list__2.sql new file mode 100644 index 000000000..1f40a89d9 --- /dev/null +++ b/db/routines/vn/views/saleMistake_list__2.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleMistake_list__2` +AS SELECT `st`.`saleFk` AS `saleFk`, + `st`.`workerFk` AS `workerFk`, + concat(`w2`.`firstName`, ' ', `w2`.`lastName`) AS `sacador`, + `st`.`created` AS `created`, + concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `revisador`, + `mt`.`description` AS `description`, + `sm`.`created` AS `controlled` +FROM ( + ( + ( + ( + ( + `vn`.`saleTracking` `st` + JOIN `vn`.`worker` `w2` ON(`w2`.`id` = `st`.`workerFk`) + ) + JOIN `vn`.`state` `s` ON( + `s`.`id` = `st`.`stateFk` + AND `s`.`code` IN ('PREVIOUS_PREPARATION', 'PREPARED', 'OK') + ) + ) + LEFT JOIN `vn`.`saleMistake` `sm` ON(`st`.`saleFk` = `sm`.`saleFk`) + ) + LEFT JOIN `vn`.`mistakeType` `mt` ON(`mt`.`id` = `sm`.`typeFk`) + ) + LEFT JOIN `vn`.`worker` `w` ON(`w`.`id` = `sm`.`userFk`) + ) diff --git a/db/routines/vn/views/saleSaleTracking.sql b/db/routines/vn/views/saleSaleTracking.sql new file mode 100644 index 000000000..9ada798cf --- /dev/null +++ b/db/routines/vn/views/saleSaleTracking.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleSaleTracking` +AS SELECT DISTINCT `st`.`saleFk` AS `saleFk` +FROM `vn`.`saleTracking` `st` +WHERE `st`.`created` >= `util`.`VN_CURDATE`() + INTERVAL -1 DAY diff --git a/db/routines/vn/views/saleValue.sql b/db/routines/vn/views/saleValue.sql new file mode 100644 index 000000000..4394769d1 --- /dev/null +++ b/db/routines/vn/views/saleValue.sql @@ -0,0 +1,50 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleValue` +AS SELECT `wh`.`name` AS `warehouse`, + `c`.`name` AS `client`, + `c`.`typeFk` AS `clientTypeFk`, + `u`.`name` AS `buyer`, + `it`.`id` AS `itemTypeFk`, + `it`.`name` AS `family`, + `s`.`itemFk` AS `itemFk`, + `s`.`concept` AS `concept`, + `s`.`quantity` AS `quantity`, + `b`.`buyingValue` + `b`.`freightValue` + `b`.`comissionValue` + `b`.`packageValue` AS `cost`, +( + `b`.`buyingValue` + `b`.`freightValue` + `b`.`comissionValue` + `b`.`packageValue` + ) * `s`.`quantity` AS `value`, + `tm`.`year` AS `year`, + `tm`.`week` AS `week` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + `vn`.`sale` `s` + JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`) + ) + JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`) + ) + JOIN `account`.`user` `u` ON(`u`.`id` = `it`.`workerFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`) + ) + JOIN `vn`.`warehouse` `wh` ON(`wh`.`id` = `t`.`warehouseFk`) + ) + JOIN `vn`.`time` `tm` ON(`tm`.`dated` = cast(`t`.`shipped` AS date)) + ) + JOIN `cache`.`last_buy` `lb` ON( + `lb`.`item_id` = `i`.`id` + AND `lb`.`warehouse_id` = `wh`.`id` + ) + ) + JOIN `vn`.`buy` `b` ON(`b`.`id` = `lb`.`buy_id`) + ) +WHERE `wh`.`isManaged` <> 0 diff --git a/db/routines/vn/views/saleVolume.sql b/db/routines/vn/views/saleVolume.sql new file mode 100644 index 000000000..aec739678 --- /dev/null +++ b/db/routines/vn/views/saleVolume.sql @@ -0,0 +1,45 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleVolume` +AS SELECT `s`.`ticketFk` AS `ticketFk`, + `s`.`id` AS `saleFk`, + round(`ic`.`cm3delivery` * `s`.`quantity` / 1000, 0) AS `litros`, + `t`.`routeFk` AS `routeFk`, + `t`.`shipped` AS `shipped`, + `t`.`landed` AS `landed`, + `s`.`quantity` * `ic`.`cm3delivery` / 1000000 AS `volume`, + `s`.`quantity` * `ic`.`grams` / 1000 AS `physicalWeight`, + `s`.`quantity` * `ic`.`cm3delivery` * greatest( + `ic`.`grams` / `ic`.`cm3delivery`, + `vc`.`aerealVolumetricDensity` + ) / 1000000 AS `weight`, + `s`.`quantity` * `ic`.`cm3delivery` / 1000000 AS `physicalVolume`, + `s`.`quantity` * `ic`.`cm3delivery` * IFNULL( + `t`.`zonePrice` - IFNULL(`t`.`zoneBonus`, 0), + `z`.`price` - `z`.`bonus` + ) / (`vc`.`standardFlowerBox` * 1000) * `z`.`inflation` AS `freight`, + `t`.`zoneFk` AS `zoneFk`, + `t`.`clientFk` AS `clientFk`, + `s`.`isPicked` AS `isPicked`, + `s`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100 AS `eurosValue`, + `i`.`itemPackingTypeFk` AS `itemPackingTypeFk` +FROM ( + ( + ( + ( + ( + `vn`.`sale` `s` + JOIN `vn`.`item` `i` ON(`i`.`id` = `s`.`itemFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) + JOIN `vn`.`volumeConfig` `vc` + ) + JOIN `vn`.`itemCost` `ic` ON( + `ic`.`itemFk` = `s`.`itemFk` + AND `ic`.`warehouseFk` = `t`.`warehouseFk` + ) + ) +WHERE `s`.`quantity` > 0 diff --git a/db/routines/vn/views/saleVolume_Today_VNH.sql b/db/routines/vn/views/saleVolume_Today_VNH.sql new file mode 100644 index 000000000..29b921bcb --- /dev/null +++ b/db/routines/vn/views/saleVolume_Today_VNH.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`saleVolume_Today_VNH` +AS SELECT `t`.`nickname` AS `Cliente`, + `p`.`name` AS `Provincia`, + `c`.`country` AS `Pais`, + cast(sum(`sv`.`volume`) AS decimal(5, 1)) AS `volume` +FROM ( + ( + ( + ( + ( + `vn`.`saleVolume` `sv` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `sv`.`ticketFk`) + ) + JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`) + ) + JOIN `vn`.`province` `p` ON(`p`.`id` = `a`.`provinceFk`) + ) + JOIN `vn`.`country` `c` ON(`c`.`id` = `p`.`countryFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`) + ) +WHERE `w`.`name` = 'VNH' + AND `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`dayend`(`util`.`VN_CURDATE`()) +GROUP BY `t`.`nickname`, + `p`.`name` diff --git a/db/routines/vn/views/sale_freightComponent.sql b/db/routines/vn/views/sale_freightComponent.sql new file mode 100644 index 000000000..7a329e0ee --- /dev/null +++ b/db/routines/vn/views/sale_freightComponent.sql @@ -0,0 +1,21 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`sale_freightComponent` +AS SELECT `t`.`id` AS `ticketFk`, + `sc`.`value` * `s`.`quantity` AS `amount`, + `t`.`shipped` AS `shipped` +FROM ( + ( + ( + ( + `vn`.`ticket` `t` STRAIGHT_JOIN `vn`.`sale` `s` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`saleComponent` `sc` ON(`sc`.`saleFk` = `s`.`id`) + ) + JOIN `vn`.`component` `c` ON(`c`.`id` = `sc`.`componentFk`) + ) + JOIN `vn`.`componentType` `ct` ON( + `ct`.`id` = `c`.`typeFk` + AND `ct`.`type` = 'agencia' + ) + ) diff --git a/db/routines/vn/views/salesPersonSince.sql b/db/routines/vn/views/salesPersonSince.sql new file mode 100644 index 000000000..43c45adc0 --- /dev/null +++ b/db/routines/vn/views/salesPersonSince.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`salesPersonSince` +AS SELECT `b`.`workerFk` AS `workerFk`, + min(`b`.`started`) AS `started` +FROM ( + ( + `vn`.`business` `b` + JOIN `vn`.`worker` `w` ON(`w`.`id` = `b`.`workerFk`) + ) + LEFT JOIN `vn`.`professionalCategory` `pc` ON( + `pc`.`id` = `b`.`workerBusinessProfessionalCategoryFk` + ) + ) +WHERE `pc`.`name` = 'Aux ventas' +GROUP BY `b`.`workerFk` diff --git a/db/routines/vn/views/salesPreparedLastHour.sql b/db/routines/vn/views/salesPreparedLastHour.sql new file mode 100644 index 000000000..caa7866cb --- /dev/null +++ b/db/routines/vn/views/salesPreparedLastHour.sql @@ -0,0 +1,46 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`salesPreparedLastHour` +AS SELECT `t`.`warehouseFk` AS `warehouseFk`, + `st`.`saleFk` AS `saleFk`, + `st`.`isChecked` AS `isChecked`, + `st`.`originalQuantity` AS `originalQuantity`, + `st`.`created` AS `created`, + `e`.`code` AS `code`, + `w`.`firstName` AS `firstname`, + `w`.`lastName` AS `lastName`, + `w`.`code` AS `workerCode`, + `ic`.`cm3delivery` * `s`.`quantity` / 1000 AS `litros`, + `s`.`concept` AS `concept`, + `d`.`name` AS `departmentName` +FROM ( + ( + ( + ( + ( + ( + ( + ( + `vn`.`saleTracking` `st` + LEFT JOIN `vn`.`salesPreviousPreparated` `prevPrepSales` ON(`prevPrepSales`.`saleFk` = `st`.`saleFk`) + ) + JOIN `vn`.`sale` `s` ON(`s`.`id` = `st`.`saleFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`itemCost` `ic` ON( + `ic`.`warehouseFk` = `t`.`warehouseFk` + AND `ic`.`itemFk` = `s`.`itemFk` + ) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `st`.`workerFk`) + ) + JOIN `vn`.`state` `e` ON(`e`.`id` = `st`.`stateFk`) + ) + JOIN `vn`.`workerDepartment` `wd` ON(`wd`.`workerFk` = `st`.`workerFk`) + ) + JOIN `vn`.`department` `d` ON(`d`.`id` = `wd`.`departmentFk`) + ) +WHERE `st`.`created` > `util`.`VN_NOW`() + INTERVAL -1 HOUR + AND `prevPrepSales`.`saleFk` IS NULL + AND `d`.`name` NOT LIKE 'EQUIPO%' diff --git a/db/routines/vn/views/salesPreviousPreparated.sql b/db/routines/vn/views/salesPreviousPreparated.sql new file mode 100644 index 000000000..40ae29eda --- /dev/null +++ b/db/routines/vn/views/salesPreviousPreparated.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`salesPreviousPreparated` +AS SELECT `st`.`saleFk` AS `saleFk` +FROM ( + `vn`.`saleTracking` `st` + JOIN `vn`.`state` `e` ON(`e`.`id` = `st`.`stateFk`) + ) +WHERE `st`.`created` > `util`.`VN_CURDATE`() + AND `e`.`code` LIKE 'PREVIOUS_PREPARATION' diff --git a/db/routines/vn/views/supplierPackaging.sql b/db/routines/vn/views/supplierPackaging.sql new file mode 100644 index 000000000..45a9d46d3 --- /dev/null +++ b/db/routines/vn/views/supplierPackaging.sql @@ -0,0 +1,33 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`supplierPackaging` +AS SELECT `e`.`supplierFk` AS `supplierFk`, + `b`.`itemFk` AS `itemFk`, + `i`.`longName` AS `longName`, + `s`.`name` AS `supplier`, + `b`.`entryFk` AS `entryFk`, + `tr`.`landed` AS `landed`, + - least(`b`.`quantity`, 0) AS `out`, + greatest(`b`.`quantity`, 0) AS `in`, + `w`.`name` AS `warehouse`, + `b`.`buyingValue` AS `buyingValue` +FROM ( + ( + ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`item` `i` ON(`i`.`id` = `b`.`itemFk`) + ) + JOIN `vn`.`packaging` `p` ON(`p`.`itemFk` = `i`.`id`) + ) + JOIN `vn`.`entry` `e` ON(`e`.`id` = `b`.`entryFk`) + ) + JOIN `vn`.`supplier` `s` ON(`s`.`id` = `e`.`supplierFk`) + ) + JOIN `vn`.`travel` `tr` ON(`tr`.`id` = `e`.`travelFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `tr`.`warehouseInFk`) + ) +WHERE `p`.`isPackageReturnable` <> 0 diff --git a/db/routines/vn/views/tagL10n.sql b/db/routines/vn/views/tagL10n.sql new file mode 100644 index 000000000..982122b13 --- /dev/null +++ b/db/routines/vn/views/tagL10n.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`tagL10n` +AS SELECT `t`.`id` AS `id`, + IFNULL(`i`.`name`, `t`.`name`) AS `name` +FROM ( + `vn`.`tag` `t` + LEFT JOIN `vn`.`tagI18n` `i` ON( + `i`.`tagFk` = `t`.`id` + AND `i`.`lang` = `util`.`LANG`() + ) + ) diff --git a/db/routines/vn/views/ticketDownBuffer.sql b/db/routines/vn/views/ticketDownBuffer.sql new file mode 100644 index 000000000..84e053fd4 --- /dev/null +++ b/db/routines/vn/views/ticketDownBuffer.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketDownBuffer` +AS SELECT `td`.`ticketFk` AS `ticketFk`, + `td`.`created` AS `created`, + `td`.`selected` AS `selected`, + concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `sacador`, + `pk`.`code` AS `parking` +FROM ( + ( + ( + ( + `vn`.`ticketDown` `td` + JOIN `vn`.`ticketParking` `tp` ON(`tp`.`ticketFk` = `td`.`ticketFk`) + ) + JOIN `vn`.`parking` `pk` ON(`pk`.`id` = `tp`.`parkingFk`) + ) + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `td`.`ticketFk`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `tst`.`worker`) + ) +WHERE `td`.`selected` = 2 diff --git a/db/routines/vn/views/ticketLastUpdated.sql b/db/routines/vn/views/ticketLastUpdated.sql new file mode 100644 index 000000000..96b6eaa17 --- /dev/null +++ b/db/routines/vn/views/ticketLastUpdated.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketLastUpdated` +AS SELECT `ticketLastUpdatedList`.`ticketFk` AS `ticketFk`, + max(`ticketLastUpdatedList`.`created`) AS `lastUpdated` +FROM `vn`.`ticketLastUpdatedList` +GROUP BY `ticketLastUpdatedList`.`ticketFk` diff --git a/db/routines/vn/views/ticketLastUpdatedList.sql b/db/routines/vn/views/ticketLastUpdatedList.sql new file mode 100644 index 000000000..bfc769e47 --- /dev/null +++ b/db/routines/vn/views/ticketLastUpdatedList.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketLastUpdatedList` +AS SELECT `s`.`ticketFk` AS `ticketFk`, + `st`.`created` AS `created` +FROM ( + `vn`.`saleTracking` `st` + JOIN `vn`.`sale` `s` ON(`s`.`id` = `st`.`saleFk`) + ) +WHERE `st`.`created` > `util`.`VN_CURDATE`() +UNION ALL +SELECT `tt`.`ticketFk` AS `Id_Ticket`, + `tt`.`created` AS `odbc_date` +FROM `vn`.`ticketTracking` `tt` +WHERE `tt`.`created` > `util`.`VN_CURDATE`() +UNION ALL +SELECT `s`.`ticketFk` AS `ticketFk`, + `iss`.`created` AS `created` +FROM ( + `vn`.`itemShelvingSale` `iss` + JOIN `vn`.`sale` `s` ON(`s`.`id` = `iss`.`saleFk`) + ) +WHERE `iss`.`created` > `util`.`VN_CURDATE`() diff --git a/db/routines/vn/views/ticketMRW.sql b/db/routines/vn/views/ticketMRW.sql new file mode 100644 index 000000000..d612c8742 --- /dev/null +++ b/db/routines/vn/views/ticketMRW.sql @@ -0,0 +1,47 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketMRW` +AS SELECT `Tickets`.`Id_Agencia` AS `id_Agencia`, + `Tickets`.`empresa_id` AS `empresa_id`, + `Consignatarios`.`consignatario` AS `Consignatario`, + `Consignatarios`.`domicilio` AS `DOMICILIO`, + `Consignatarios`.`poblacion` AS `POBLACION`, + `Consignatarios`.`codPostal` AS `CODPOSTAL`, + `Consignatarios`.`telefono` AS `telefono`, + IFNULL( + IFNULL( + IFNULL( + IFNULL(`Consignatarios`.`movil`, `Clientes`.`movil`), + `Consignatarios`.`telefono` + ), + `Clientes`.`telefono` + ), + 0 + ) AS `movil`, + `Clientes`.`if` AS `IF`, + `Tickets`.`Id_Ticket` AS `Id_Ticket`, + `Tickets`.`warehouse_id` AS `warehouse_id`, + `Consignatarios`.`id_consigna` AS `Id_Consigna`, + `Paises`.`Codigo` AS `CodigoPais`, + `Tickets`.`Fecha` AS `Fecha`, + `province`.`province_id` AS `province_id`, + `Tickets`.`landing` AS `landing` +FROM ( + ( + ( + ( + `vn2008`.`Clientes` + JOIN `vn2008`.`Consignatarios` ON( + `Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente` + ) + ) + JOIN `vn2008`.`Tickets` ON( + `Consignatarios`.`id_consigna` = `Tickets`.`Id_Consigna` + ) + ) + JOIN `vn2008`.`province` ON( + `Consignatarios`.`province_id` = `province`.`province_id` + ) + ) + JOIN `vn2008`.`Paises` ON(`province`.`Paises_Id` = `Paises`.`Id`) + ) diff --git a/db/routines/vn/views/ticketNotInvoiced.sql b/db/routines/vn/views/ticketNotInvoiced.sql new file mode 100644 index 000000000..c35b414ce --- /dev/null +++ b/db/routines/vn/views/ticketNotInvoiced.sql @@ -0,0 +1,26 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketNotInvoiced` +AS SELECT `t`.`companyFk` AS `companyFk`, + `cm`.`code` AS `companyCode`, + `t`.`clientFk` AS `clientFk`, + `c`.`name` AS `clientName`, + `t`.`shipped` AS `shipped`, + cast( + sum( + `s`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100 + ) AS decimal(10, 2) + ) AS `value` +FROM ( + ( + ( + `vn`.`ticket` `t` + JOIN `vn`.`sale` `s` ON(`s`.`ticketFk` = `t`.`id`) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `t`.`clientFk`) + ) + JOIN `vn`.`company` `cm` ON(`cm`.`id` = `t`.`companyFk`) + ) +WHERE `t`.`refFk` IS NULL + AND `t`.`shipped` > '2017-01-01' +GROUP BY `t`.`id` diff --git a/db/routines/vn/views/ticketPackingList.sql b/db/routines/vn/views/ticketPackingList.sql new file mode 100644 index 000000000..bafe3c00c --- /dev/null +++ b/db/routines/vn/views/ticketPackingList.sql @@ -0,0 +1,38 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketPackingList` +AS SELECT `t`.`nickname` AS `nickname`, + `t`.`id` AS `ticketFk`, + `am`.`name` AS `agencyMode`, + `am`.`flag` AS `flag`, + `p`.`name` AS `province`, + `s`.`itemFk` AS `itemFk`, + `s`.`concept` AS `concept`, + `s`.`quantity` AS `quantity`, + `sv`.`litros` AS `litros`, + `to`.`description` AS `observaciones` +FROM ( + ( + ( + ( + ( + ( + ( + `vn`.`ticket` `t` + JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`) + ) + JOIN `vn`.`province` `p` ON(`p`.`id` = `a`.`provinceFk`) + ) + JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`) + ) + LEFT JOIN `vn`.`sale` `s` ON(`s`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `vn`.`saleVolume` `sv` ON(`sv`.`saleFk` = `s`.`id`) + ) + JOIN `vn`.`observationType` `ot` ON(`ot`.`code` = 'packager') + ) + LEFT JOIN `vn`.`ticketObservation` `to` ON( + `to`.`ticketFk` = `t`.`id` + AND `ot`.`id` = `to`.`observationTypeFk` + ) + ) diff --git a/db/routines/vn/views/ticketPreviousPreparingList.sql b/db/routines/vn/views/ticketPreviousPreparingList.sql new file mode 100644 index 000000000..9c84b8af3 --- /dev/null +++ b/db/routines/vn/views/ticketPreviousPreparingList.sql @@ -0,0 +1,36 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketPreviousPreparingList` +AS SELECT `s`.`ticketFk` AS `ticketFk`, + `w`.`code` AS `code`, + COUNT(`s`.`id`) AS `saleLines`, + sum(`s`.`isPicked` <> 0) AS `alreadyMadeSaleLines`, + sum(`s`.`isPicked` <> 0) / COUNT(`s`.`id`) AS `madeRate`, + `sg`.`created` AS `created`, + `p`.`code` AS `parking`, + `iss`.`sectorFk` AS `sectorFk`, + `al`.`code` AS `alertCode` +FROM ( + ( + ( + ( + ( + ( + ( + `vn`.`saleGroup` `sg` + JOIN `vn`.`saleGroupDetail` `sgd` ON(`sgd`.`saleGroupFk` = `sg`.`id`) + ) + JOIN `vn`.`sale` `s` ON(`s`.`id` = `sgd`.`saleFk`) + ) + JOIN `vn`.`ticketState` `tls` ON(`tls`.`ticketFk` = `s`.`ticketFk`) + ) + JOIN `vn`.`alertLevel` `al` ON(`al`.`id` = `tls`.`alertLevel`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `sg`.`userFk`) + ) + LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sg`.`parkingFk`) + ) + JOIN `vn`.`itemShelvingStock` `iss` ON(`iss`.`itemFk` = `s`.`itemFk`) + ) +WHERE `sg`.`created` >= `util`.`VN_CURDATE`() + INTERVAL 0.1 DAY +GROUP BY `sg`.`id` diff --git a/db/routines/vn/views/ticketState.sql b/db/routines/vn/views/ticketState.sql new file mode 100644 index 000000000..f8273d7a9 --- /dev/null +++ b/db/routines/vn/views/ticketState.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketState` +AS SELECT `tt`.`created` AS `updated`, + `tt`.`stateFk` AS `stateFk`, + `tt`.`userFk` AS `workerFk`, + `tls`.`ticketFk` AS `ticketFk`, + `s`.`id` AS `state`, + `s`.`order` AS `productionOrder`, + `s`.`alertLevel` AS `alertLevel`, + `s`.`code` AS `code`, + `tls`.`ticketFk` AS `ticket`, + `tt`.`userFk` AS `worker`, + `s`.`isPreviousPreparable` AS `isPreviousPreparable`, + `s`.`isPicked` AS `isPicked` +FROM ( + ( + `vn`.`ticketLastState` `tls` + JOIN `vn`.`ticketTracking` `tt` ON(`tt`.`id` = `tls`.`ticketTrackingFk`) + ) + JOIN `vn`.`state` `s` ON(`s`.`id` = `tt`.`stateFk`) + ) diff --git a/db/routines/vn/views/ticketStateToday.sql b/db/routines/vn/views/ticketStateToday.sql new file mode 100644 index 000000000..f4a0ebc02 --- /dev/null +++ b/db/routines/vn/views/ticketStateToday.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketStateToday` +AS SELECT `ts`.`ticketFk` AS `ticket`, + `ts`.`state` AS `state`, + `ts`.`productionOrder` AS `productionOrder`, + `ts`.`alertLevel` AS `alertLevel`, + `ts`.`worker` AS `worker`, + `ts`.`code` AS `code`, + `ts`.`updated` AS `updated`, + `ts`.`isPicked` AS `isPicked` +FROM ( + `vn`.`ticketState` `ts` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ts`.`ticketFk`) + ) +WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`()) diff --git a/db/routines/vn/views/ticketToPrepare.sql b/db/routines/vn/views/ticketToPrepare.sql new file mode 100644 index 000000000..98302b60d --- /dev/null +++ b/db/routines/vn/views/ticketToPrepare.sql @@ -0,0 +1,58 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketToPrepare` +AS SELECT `m`.`Id_Ticket` AS `Id_Ticket`, + `mk`.`Id_Movimiento` AS `Id_Movimiento`, + `mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`, + `mk`.`Id_Trabajador` AS `Id_Trabjador`, + `m`.`Id_Article` AS `Id_Article`, + `m`.`Concepte` AS `Concepte`, + `art`.`subName` AS `subName`, + `mk`.`original_quantity` - IFNULL(`is`.`quantity`, 0) AS `Cantidad`, + `mk`.`original_quantity` AS `original_quantity`, + IF( + HOUR(`t`.`shipped`), + HOUR(`t`.`shipped`), + HOUR(`z`.`hour`) + ) AS `Hora`, + HOUR(`t`.`shipped`) AS `Departure`, + MINUTE(`t`.`shipped`) AS `Minuto`, + `am`.`agencyFk` AS `agency_id`, + `t`.`warehouseFk` AS `warehouse_id`, + `a`.`provinceFk` AS `province_id`, + `is`.`quantity` AS `picked`, + `t`.`zoneFk` AS `zoneFk`, + `p`.`sectorFk` AS `sectorFk` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + ( + `vn2008`.`Movimientos_mark` `mk` + JOIN `vn2008`.`Movimientos` `m` ON(`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`) + ) + JOIN `vn`.`ticket` `t` ON(`m`.`Id_Ticket` = `t`.`id`) + ) + JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`) + ) + JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`) + ) + LEFT JOIN `vn`.`itemShelvingSale` `is` ON(`is`.`saleFk` = `mk`.`Id_Movimiento`) + ) + LEFT JOIN `vn`.`itemShelving` `ish` ON(`ish`.`id` = `is`.`itemShelvingFk`) + ) + LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) + ) + LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) + ) + LEFT JOIN `vn2008`.`Articles` `art` ON(`art`.`Id_Article` = `m`.`Id_Article`) + ) + LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) +WHERE `mk`.`stateFk` = 26 + AND `mk`.`valor` <> 1 diff --git a/db/routines/vn/views/ticketeToPreparePrepared.sql b/db/routines/vn/views/ticketeToPreparePrepared.sql new file mode 100644 index 000000000..76e840816 --- /dev/null +++ b/db/routines/vn/views/ticketeToPreparePrepared.sql @@ -0,0 +1,47 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketeToPreparePrepared` +AS SELECT `m`.`Id_Ticket` AS `Id_Ticket`, + `mk`.`Id_Movimiento` AS `Id_Movimiento`, + `mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`, + `mk`.`Id_Trabajador` AS `Id_Trabjador`, + `m`.`Id_Article` AS `Id_Article`, + `m`.`Concepte` AS `Concepte`, + `art`.`subName` AS `subName`, + `mk`.`original_quantity` - IFNULL(`is`.`quantity`, 0) AS `Cantidad`, + `mk`.`original_quantity` AS `original_quantity`, + HOUR(`t`.`shipped`) AS `Hora`, + HOUR(`t`.`shipped`) AS `Departure`, + MINUTE(`t`.`shipped`) AS `Minuto`, + `am`.`agencyFk` AS `agency_id`, + `t`.`warehouseFk` AS `warehouse_id`, + `a`.`provinceFk` AS `province_id`, + `is`.`quantity` AS `picked`, + `t`.`CodigoTrabajador` AS `trabajador`, + `is`.`sectorFk` AS `sectorFk` +FROM ( + ( + ( + ( + ( + ( + ( + ( + `vn2008`.`Movimientos_mark` `mk` + JOIN `vn`.`state` `st` ON(`st`.`id` = `mk`.`stateFk`) + ) + JOIN `vn2008`.`Movimientos` `m` ON(`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`) + ) + JOIN `vn`.`ticket` `t` ON(`m`.`Id_Ticket` = `t`.`id`) + ) + JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`) + ) + JOIN `vn`.`address` `a` ON(`a`.`id` = `t`.`addressFk`) + ) + LEFT JOIN `vn`.`itemShelvingSaleSum` `is` ON(`is`.`saleFk` = `mk`.`Id_Movimiento`) + ) + JOIN `vn2008`.`Articles` `art` ON(`art`.`Id_Article` = `m`.`Id_Article`) + ) + LEFT JOIN `vn2008`.`Trabajadores` `t` ON(`t`.`Id_Trabajador` = `mk`.`Id_Trabajador`) + ) +WHERE `st`.`code` LIKE 'PREVIOUS_PREPARATION' diff --git a/db/routines/vn/views/tr2.sql b/db/routines/vn/views/tr2.sql new file mode 100644 index 000000000..5abc2bfa8 --- /dev/null +++ b/db/routines/vn/views/tr2.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`tr2` +AS SELECT `vn`.`travel`.`id` AS `id`, + `vn`.`travel`.`shipped` AS `shipped`, + `vn`.`travel`.`shipmentHour` AS `shipmentHour`, + `vn`.`travel`.`landed` AS `landed`, + `vn`.`travel`.`landingHour` AS `landingHour`, + `vn`.`travel`.`warehouseInFk` AS `warehouseInFk`, + `vn`.`travel`.`warehouseOutFk` AS `warehouseOutFk`, + `vn`.`travel`.`agencyModeFk` AS `agencyFk`, + `vn`.`travel`.`ref` AS `ref`, + `vn`.`travel`.`isDelivered` AS `isDelivered`, + `vn`.`travel`.`isReceived` AS `isReceived`, + `vn`.`travel`.`m3` AS `m3`, + `vn`.`travel`.`kg` AS `kg`, + `vn`.`travel`.`cargoSupplierFk` AS `cargoSupplierFk`, + `vn`.`travel`.`totalEntries` AS `totalEntries` +FROM `vn`.`travel` diff --git a/db/routines/vn/views/traceabilityBuy.sql b/db/routines/vn/views/traceabilityBuy.sql new file mode 100644 index 000000000..0257c2f5d --- /dev/null +++ b/db/routines/vn/views/traceabilityBuy.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`traceabilityBuy` +AS SELECT `b`.`id` AS `buyFk`, + `b`.`quantity` AS `quantity`, + `tr`.`landed` AS `landed`, + `w`.`name` AS `warehouseName`, + `b`.`entryFk` AS `entryFk`, + `s`.`name` AS `supplierName`, + IFNULL(`b`.`itemOriginalFk`, `b`.`itemFk`) AS `itemFk` +FROM ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`entry` `e` ON(`e`.`id` = `b`.`entryFk`) + ) + JOIN `vn`.`travel` `tr` ON(`tr`.`id` = `e`.`travelFk`) + ) + JOIN `vn`.`supplier` `s` ON(`s`.`id` = `e`.`supplierFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `tr`.`warehouseInFk`) + ) diff --git a/db/routines/vn/views/traceabilitySale.sql b/db/routines/vn/views/traceabilitySale.sql new file mode 100644 index 000000000..9caf11d5e --- /dev/null +++ b/db/routines/vn/views/traceabilitySale.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`traceabilitySale` +AS SELECT `s`.`ticketFk` AS `ticketFk`, + `sb`.`buyFk` AS `buyFk`, + `t`.`shipped` AS `shipped`, + `t`.`nickname` AS `nickname`, + `s`.`quantity` AS `quantity`, + concat(`w`.`firstName`, ' ', `w`.`lastName`) AS `worker` +FROM ( + ( + ( + `vn`.`saleBuy` `sb` + JOIN `vn`.`sale` `s` ON(`s`.`id` = `sb`.`saleFk`) + ) + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `s`.`ticketFk`) + ) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `sb`.`workerFk`) + ) diff --git a/db/routines/vn/views/unary.sql b/db/routines/vn/views/unary.sql new file mode 100644 index 000000000..7f4c0d8c5 --- /dev/null +++ b/db/routines/vn/views/unary.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`unary` +AS SELECT `a`.`id` AS `id`, + `a`.`parent` AS `parent` +FROM `vn2008`.`unary` `a` diff --git a/db/routines/vn/views/unaryScan.sql b/db/routines/vn/views/unaryScan.sql new file mode 100644 index 000000000..18428dd62 --- /dev/null +++ b/db/routines/vn/views/unaryScan.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`unaryScan` +AS SELECT `u`.`unary_id` AS `unaryFk`, + `u`.`name` AS `name`, + `u`.`odbc_date` AS `created`, + `u`.`type` AS `type` +FROM `vn2008`.`unary_scan` `u` diff --git a/db/routines/vn/views/unaryScanLine.sql b/db/routines/vn/views/unaryScanLine.sql new file mode 100644 index 000000000..75aec7fed --- /dev/null +++ b/db/routines/vn/views/unaryScanLine.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`unaryScanLine` +AS SELECT `u`.`id` AS `id`, + `u`.`code` AS `code`, + `u`.`odbc_date` AS `created`, + `u`.`unary_id` AS `unaryScanFk` +FROM `vn2008`.`unary_scan_line` `u` diff --git a/db/routines/vn/views/unaryScanLineBuy.sql b/db/routines/vn/views/unaryScanLineBuy.sql new file mode 100644 index 000000000..26f178a45 --- /dev/null +++ b/db/routines/vn/views/unaryScanLineBuy.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`unaryScanLineBuy` +AS SELECT `u`.`scan_line_id` AS `unaryScanLineFk`, + `u`.`Id_Article` AS `itemFk` +FROM `vn2008`.`unary_scan_line_buy` `u` diff --git a/db/routines/vn/views/unaryScanLineExpedition.sql b/db/routines/vn/views/unaryScanLineExpedition.sql new file mode 100644 index 000000000..e71c2423e --- /dev/null +++ b/db/routines/vn/views/unaryScanLineExpedition.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`unaryScanLineExpedition` +AS SELECT `u`.`scan_line_id` AS `unaryScanLineFk`, + `u`.`expedition_id` AS `expeditionFk` +FROM `vn2008`.`unary_scan_line_expedition` `u` diff --git a/db/routines/vn/views/warehouseJoined.sql b/db/routines/vn/views/warehouseJoined.sql new file mode 100644 index 000000000..dbbb40b1a --- /dev/null +++ b/db/routines/vn/views/warehouseJoined.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`warehouseJoined` +AS SELECT `wj`.`warehouse_id` AS `warehouseFk`, + `wj`.`warehouse_alias_id` AS `warehouseAliasFk` +FROM `vn2008`.`warehouse_joined` `wj` diff --git a/db/routines/vn/views/workerBusinessDated.sql b/db/routines/vn/views/workerBusinessDated.sql new file mode 100644 index 000000000..83d6eb48c --- /dev/null +++ b/db/routines/vn/views/workerBusinessDated.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerBusinessDated` +AS SELECT `t`.`dated` AS `dated`, + `b`.`id` AS `businessFk`, + `b`.`workerFk` AS `workerFk` +FROM ( + `vn`.`time` `t` + LEFT JOIN `vn`.`business` `b` ON( + `t`.`dated` BETWEEN `b`.`started` AND IFNULL(`b`.`ended`, `util`.`VN_CURDATE`()) + ) + ) +WHERE `t`.`dated` > `util`.`VN_CURDATE`() + INTERVAL -2 year diff --git a/db/routines/vn/views/workerDepartment.sql b/db/routines/vn/views/workerDepartment.sql new file mode 100644 index 000000000..4be3122da --- /dev/null +++ b/db/routines/vn/views/workerDepartment.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerDepartment` +AS SELECT `b`.`workerFk` AS `workerFk`, + `b`.`departmentFk` AS `departmentFk` +FROM ( + `vn`.`business` `b` + JOIN `vn`.`worker` `w` ON(`w`.`businessFk` = `b`.`id`) + ) diff --git a/db/routines/vn/views/workerLabour.sql b/db/routines/vn/views/workerLabour.sql new file mode 100644 index 000000000..2f4067c2d --- /dev/null +++ b/db/routines/vn/views/workerLabour.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerLabour` +AS SELECT `b`.`id` AS `businessFk`, + `b`.`workerFk` AS `workerFk`, + `b`.`workcenterFk` AS `workCenterFk`, + `b`.`started` AS `started`, + `b`.`ended` AS `ended`, + `b`.`departmentFk` AS `departmentFk`, + `b`.`payedHolidays` AS `payedHolidays` +FROM `vn`.`business` `b` +ORDER BY `b`.`started` DESC diff --git a/db/routines/vn/views/workerMedia.sql b/db/routines/vn/views/workerMedia.sql new file mode 100644 index 000000000..72ee04299 --- /dev/null +++ b/db/routines/vn/views/workerMedia.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerMedia` +AS SELECT `w`.`id` AS `workerFk`, + `w`.`phone` AS `mediaValue` +FROM `vn`.`worker` `w` +WHERE `w`.`phone` IS NOT NULL diff --git a/db/routines/vn/views/workerSpeedExpedition.sql b/db/routines/vn/views/workerSpeedExpedition.sql new file mode 100644 index 000000000..db13cf16a --- /dev/null +++ b/db/routines/vn/views/workerSpeedExpedition.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerSpeedExpedition` +AS SELECT `sv`.`ticketFk` AS `ticketFk`, + sum(`sv`.`litros`) AS `litros`, + sum( + IF( + `sub`.`started` > `util`.`VN_NOW`() + INTERVAL -1 HOUR, + `sv`.`litros`, + 0 + ) + ) AS `literLastHour`, + cast( + 60 * sum(`sv`.`litros`) / time_to_sec( + timediff(max(`sub`.`finished`), min(`sub`.`started`)) + ) AS decimal(10, 1) + ) AS `litersByMinute`, + `sub`.`code` AS `workerCode`, + `sub`.`cajas` AS `cajas`, + `sub`.`warehouseFk` AS `warehouseFk` +FROM ( + `vn`.`saleVolume` `sv` + JOIN `vn`.`expeditionTimeExpended` `sub` ON(`sub`.`ticketFk` = `sv`.`ticketFk`) + ) +GROUP BY `sub`.`code` diff --git a/db/routines/vn/views/workerSpeedSaleTracking.sql b/db/routines/vn/views/workerSpeedSaleTracking.sql new file mode 100644 index 000000000..21f07ea8a --- /dev/null +++ b/db/routines/vn/views/workerSpeedSaleTracking.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerSpeedSaleTracking` +AS SELECT `salesPreparedLastHour`.`warehouseFk` AS `warehouseFk`, + `salesPreparedLastHour`.`code` AS `state`, + `salesPreparedLastHour`.`workerCode` AS `workerCode`, + sum(`salesPreparedLastHour`.`litros`) AS `sumaLitros`, + min(`salesPreparedLastHour`.`created`) AS `started`, + max(`salesPreparedLastHour`.`created`) AS `finished`, + sum( + IF( + `salesPreparedLastHour`.`created` >= `util`.`VN_NOW`() + INTERVAL -1 HOUR, + `salesPreparedLastHour`.`litros`, + 0 + ) + ) AS `sumaLitrosLastHour`, + cast( + 60 * sum(`salesPreparedLastHour`.`litros`) / time_to_sec( + timediff( + max(`salesPreparedLastHour`.`created`), + min(`salesPreparedLastHour`.`created`) + ) + ) AS decimal(10, 1) + ) AS `litersByMinute`, + `salesPreparedLastHour`.`departmentName` AS `departmentName` +FROM `vn`.`salesPreparedLastHour` +GROUP BY `salesPreparedLastHour`.`warehouseFk`, + `salesPreparedLastHour`.`code`, + `salesPreparedLastHour`.`workerCode` diff --git a/db/routines/vn/views/workerTeamCollegues.sql b/db/routines/vn/views/workerTeamCollegues.sql new file mode 100644 index 000000000..dbe245a16 --- /dev/null +++ b/db/routines/vn/views/workerTeamCollegues.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerTeamCollegues` +AS SELECT DISTINCT `w`.`workerFk` AS `workerFk`, + `t`.`workerFk` AS `collegueFk` +FROM ( + `vn`.`workerTeam` `w` + JOIN `vn`.`workerTeam` `t` ON(`w`.`team` = `t`.`team`) + ) diff --git a/db/routines/vn/views/workerTimeControlUserInfo.sql b/db/routines/vn/views/workerTimeControlUserInfo.sql new file mode 100644 index 000000000..eea8ffd7c --- /dev/null +++ b/db/routines/vn/views/workerTimeControlUserInfo.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerTimeControlUserInfo` +AS SELECT `u`.`id` AS `userFk`, + `w`.`firstName` AS `name`, + `w`.`lastName` AS `surname`, + `u`.`name` AS `user`, + `u`.`password` AS `password`, + `wd`.`departmentFk` AS `departmentFk`, + left(`c`.`fi`, 8) AS `dni` +FROM ( + ( + ( + `account`.`user` `u` + JOIN `vn`.`worker` `w` ON(`w`.`id` = `u`.`id`) + ) + JOIN `vn`.`client` `c` ON(`c`.`id` = `u`.`id`) + ) + LEFT JOIN `vn`.`workerDepartment` `wd` ON(`wd`.`workerFk` = `w`.`id`) + ) diff --git a/db/routines/vn/views/workerTimeJourneyNG.sql b/db/routines/vn/views/workerTimeJourneyNG.sql new file mode 100644 index 000000000..b45b855b7 --- /dev/null +++ b/db/routines/vn/views/workerTimeJourneyNG.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerTimeJourneyNG` +AS SELECT `wtc`.`userFk` AS `userFk`, + cast(`wtc`.`timed` AS date) AS `dated`, + IF(`wtc`.`order` MOD 2, -1, 1) * (HOUR(`wtc`.`timed`) + MINUTE(`wtc`.`timed`) / 60) AS `Journey`, + dayname(`wtc`.`timed`) AS `dayName`, + `w`.`lastName` AS `name`, + `w`.`firstName` AS `firstname` +FROM ( + `vn`.`workerTimeControl` `wtc` + JOIN `vn`.`worker` `w` ON(`w`.`id` = `wtc`.`userFk`) + ) diff --git a/db/routines/vn/views/workerWithoutTractor.sql b/db/routines/vn/views/workerWithoutTractor.sql new file mode 100644 index 000000000..e0c0978a5 --- /dev/null +++ b/db/routines/vn/views/workerWithoutTractor.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`workerWithoutTractor` +AS SELECT `c`.`workerFk` AS `workerFk`, + `cl`.`name` AS `Trabajador`, + COUNT(DISTINCT `c`.`id`) AS `Colecciones`, + max(`c`.`created`) AS `created` +FROM ( + ( + `vn`.`collection` `c` + JOIN `vn`.`client` `cl` ON(`cl`.`id` = `c`.`workerFk`) + ) + LEFT JOIN `vn`.`machineWorker` `mw` ON( + `mw`.`workerFk` = `c`.`workerFk` + AND `mw`.`inTimed` > `util`.`VN_CURDATE`() + ) + ) +WHERE `c`.`created` > `util`.`VN_CURDATE`() + AND `mw`.`workerFk` IS NULL +GROUP BY `c`.`workerFk` diff --git a/db/routines/vn/views/zoneEstimatedDelivery.sql b/db/routines/vn/views/zoneEstimatedDelivery.sql new file mode 100644 index 000000000..cfd837add --- /dev/null +++ b/db/routines/vn/views/zoneEstimatedDelivery.sql @@ -0,0 +1,48 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`zoneEstimatedDelivery` +AS SELECT `t`.`zoneFk` AS `zoneFk`, + `zc`.`hour` AS `zoneClosureHour`, + `z`.`hour` AS `zoneHour`, + `sv`.`volume` AS `volume`, + `al`.`hasToRecalcPrice` AS `hasToRecalcPrice`, + `lhp`.`m3` AS `m3`, + `dl`.`minSpeed` AS `minSpeed` +FROM ( + ( + ( + ( + ( + ( + ( + ( + ( + ( + `vn`.`ticket` `t` + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `t`.`id`) + ) + JOIN `vn`.`state` `s` ON(`s`.`id` = `tst`.`state`) + ) + JOIN `vn`.`saleVolume` `sv` ON(`sv`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `vn`.`lastHourProduction` `lhp` ON(`lhp`.`warehouseFk` = `t`.`warehouseFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`) + ) + JOIN `vn`.`warehouseAlias` `wa` ON(`wa`.`id` = `w`.`aliasFk`) + ) STRAIGHT_JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) + ) + LEFT JOIN `vn`.`zoneClosure` `zc` ON( + `zc`.`zoneFk` = `t`.`zoneFk` + AND `zc`.`dated` = `util`.`VN_CURDATE`() + ) + ) + LEFT JOIN `cache`.`departure_limit` `dl` ON( + `dl`.`warehouse_id` = `t`.`warehouseFk` + AND `dl`.`fecha` = `util`.`VN_CURDATE`() + ) + ) + JOIN `vn`.`alertLevel` `al` ON(`al`.`id` = `s`.`alertLevel`) + ) +WHERE `w`.`hasProduction` <> 0 + AND cast(`t`.`shipped` AS date) = `util`.`VN_CURDATE`() diff --git a/db/routines/vn2008/events/raidUpdate.sql b/db/routines/vn2008/events/raidUpdate.sql new file mode 100644 index 000000000..aacfd6dcd --- /dev/null +++ b/db/routines/vn2008/events/raidUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn2008`.`raidUpdate` + ON SCHEDULE EVERY 1 DAY + STARTS '2017-12-29 00:05:00.000' + ON COMPLETION PRESERVE + ENABLE +DO CALL raidUpdate$$ +DELIMITER ; diff --git a/db/routines/vn2008/functions/cc_to_iban.sql b/db/routines/vn2008/functions/cc_to_iban.sql new file mode 100644 index 000000000..c4515a9cc --- /dev/null +++ b/db/routines/vn2008/functions/cc_to_iban.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`cc_to_iban`(cc VARCHAR(20)) + RETURNS varchar(4) CHARSET utf8mb3 COLLATE utf8mb3_general_ci + DETERMINISTIC +BEGIN + DECLARE iban VARCHAR(4); + select + CONCAT('ES', + RIGHT( + concat(0, + 98- + mod( + concat( + mod( + concat( + mod( + concat( + mod( + substring(cc,1,8), + 97), + substring(cc,9,8) + ), + 97), + substring( + concat( + cc, + 142800 + ), + 17, + 8 + ) + ), + 97), + substring( + concat( + cc, + 142800 + ), + 25, + 2 + ) + ), + 97) + ) + ,2) + )into iban; +RETURN iban; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/functions/intrastat_neto.sql b/db/routines/vn2008/functions/intrastat_neto.sql new file mode 100644 index 000000000..34e01de8c --- /dev/null +++ b/db/routines/vn2008/functions/intrastat_neto.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`intrastat_neto`(intINSTRASTAT INTEGER,intUNIDADES INTEGER) + RETURNS double + DETERMINISTIC +BEGIN + + DECLARE n DOUBLE; + + SELECT ROUND(intUNIDADES / (SUM(MEDIA) / COUNT(media)), 2) INTO n FROM + (SELECT *, unidades / neto MEDIA + FROM intrastat_data + WHERE intrastat_id = intINSTRASTAT AND neto + AND unidades > 0 + ORDER BY odbc_date DESC + LIMIT 20) t; + -- JGF 01/06 per a evitar Kg en negatiu + RETURN n/2; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/functions/nz.sql b/db/routines/vn2008/functions/nz.sql new file mode 100644 index 000000000..3ca911052 --- /dev/null +++ b/db/routines/vn2008/functions/nz.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`nz`(dblCANTIDAD DOUBLE) + RETURNS double + DETERMINISTIC +BEGIN + + DECLARE dblRESULT DOUBLE; + + SET dblRESULT = IFNULL(dblCANTIDAD,0); + + RETURN dblRESULT; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/functions/red.sql b/db/routines/vn2008/functions/red.sql new file mode 100644 index 000000000..b94e3d716 --- /dev/null +++ b/db/routines/vn2008/functions/red.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`red`(intCANTIDAD DOUBLE) + RETURNS double + DETERMINISTIC +BEGIN + + DECLARE n DOUBLE; + + SET n = SIGN(intCANTIDAD) * TRUNCATE( (ABS(intCANTIDAD) * 100) + 0.5001 ,0) /100 ; + + RETURN n; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql b/db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql new file mode 100644 index 000000000..3dd9e9dc4 --- /dev/null +++ b/db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Cajas_Saldo_Detalle`() +BEGIN + + Select Proveedores.Id_Proveedor, Proveedor, Fecha, round(Importe) as Importe + from Proveedores + join + ( + select Fecha, sub.Id_Proveedor, sum(Importe) as Importe + from + + ( + + select round(sum(Importe),2) as Importe, TIMESTAMPADD(DAY,-1,util.VN_CURDATE()) as Fecha, Id_Proveedor + from pago + join Proveedores using(Id_Proveedor) + where Fecha >= '2011-01-01' + and Id_Proveedor NOT IN (select id from empresa) + group by Id_Proveedor + + union all + + select IFNULL(-1 * round(sum(rv.Cantidad / if(Id_Moneda = 2,rate,1)),2),0) AS Vto, TIMESTAMPADD(DAY,-1,util.VN_CURDATE()), proveedor_id + from recibida_vencimiento rv + join recibida r on r.id = rv.recibida_id + join reference_rate rr on rr.`date` = rv.fecha + join Proveedores P on P.Id_Proveedor = r.proveedor_id + join Paises PS on PS.Id = P.pais_id + where rv.fecha between '2011-01-01' and util.VN_CURDATE()-1 + and Id_Proveedor NOT IN (select id from empresa) + group by proveedor_id + + union all + + select -1 * round(rv.Cantidad / if(Id_Moneda = 2,(SELECT value FROM vn.referenceRate ORDER BY dated DESC LIMIT 1),1),2) AS Vto, rv.fecha, proveedor_id + from recibida_vencimiento rv + join recibida r on r.id = rv.recibida_id + join Proveedores P on P.Id_Proveedor = r.proveedor_id + join Paises PS on PS.Id = P.pais_id + where rv.fecha >= util.VN_CURDATE() + and Id_Proveedor NOT IN (select id from empresa) + + union all + + select @remesas:= @pago:= @saldo:= 0.0000, util.VN_CURDATE(), @prov:= 0) sub + group by Fecha,Id_Proveedor + ) sub2 using(Id_Proveedor) + having Importe < -100 + ; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/CalculoRemesas.sql b/db/routines/vn2008/procedures/CalculoRemesas.sql new file mode 100644 index 000000000..17a2e7fdd --- /dev/null +++ b/db/routines/vn2008/procedures/CalculoRemesas.sql @@ -0,0 +1,66 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`CalculoRemesas`(IN vFechaRemesa DATE) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS; + CREATE TEMPORARY TABLE TMP_REMESAS + SELECT + CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1, + cli.Id_Cliente, + cli.Cliente, + cli.`IF` as NIF, + c.PaymentDate as Vencimiento, + 0 ImporteFac, + cast(c.Recibo as decimal(10,2)) as ImporteRec, + 0 as ImporteActual, + c.companyFk empresa_id, + cli.RazonSocial, + cast(c.Recibo as decimal(10,2)) as ImporteTotal, + cast(c.Recibo as decimal(10,2)) as Saldo, + p.Proveedor as Empresa, + e.abbreviation as EMP, + cli.cuenta, + iban AS Iban, + CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe, + sepavnl as SEPA, + corevnl as RecibidoCORE, + hasLcr, + be.bic, + be.`name` entityName + FROM Clientes cli + JOIN + (SELECT risk.companyFk, + c.Id_Cliente, + sum(risk.amount) as Recibo, + IF((c.Vencimiento + graceDays) mod 30.001 <= day(vFechaRemesa) + ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-1,vFechaRemesa))) + ,TIMESTAMPADD(DAY, (c.Vencimiento + graceDays) MOD 30.001, LAST_DAY(TIMESTAMPADD(MONTH,-2,vFechaRemesa))) + ) as PaymentDate + FROM Clientes c + JOIN pay_met pm on pm.id = pay_met_id + JOIN + ( + SELECT companyFk, clientFk, amount + FROM Clientes c + JOIN vn.clientRisk cr ON cr.clientFk = c.Id_Cliente + WHERE pay_met_id = 4 + + UNION ALL + + SELECT empresa_id, Id_Cliente, - Importe + FROM Facturas f + JOIN Clientes c using(Id_Cliente) + JOIN pay_met pm on pm.id = pay_met_id + WHERE f.Vencimiento > vFechaRemesa + AND pay_met_id = 4 AND pm.deudaviva + AND Importe > 0 + + ) risk ON c.Id_Cliente = risk.clientFk + GROUP BY risk.companyFk, Id_Cliente + HAVING Recibo > 10 + ) c on c.Id_Cliente = cli.Id_Cliente + JOIN Proveedores p on p.Id_Proveedor = c.companyFk + JOIN empresa e on e.id = c.companyFk + LEFT JOIN vn.bankEntity be ON be.id = cli.bankEntityFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql b/db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql new file mode 100644 index 000000000..3c8e40702 --- /dev/null +++ b/db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`CompresTriggerBeforeDelete`(oldId INT, oldEntrada INT) +BEGIN + + DECLARE hasToRecalculate BOOLEAN; + DECLARE newWarehouse INT; + + SELECT Id_Compra INTO hasToRecalculate FROM vn.lastBuy lb + WHERE lb.id = oldId LIMIT 1; + + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel t + JOIN Entradas e ON t.id = e.travel_id + WHERE e.Id_Entrada = oldEntrada; + + CALL vn.lastBuyRefresh(newWarehouse); + END IF; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql b/db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql new file mode 100644 index 000000000..e48359f55 --- /dev/null +++ b/db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`EntradasTriggerBeforeDelete`(oldTravel INT, oldId INT) +BEGIN + + DECLARE hasToRecalculate BOOLEAN; + DECLARE newWarehouse INT; + + SELECT Id_Compra INTO hasToRecalculate FROM Compres c + JOIN vn.lastBuy lb ON lb.id = c.Id_Compra + WHERE c.Id_Entrada = newId LIMIT 1; + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel WHERE id = oldTravel; + CALL vn.lastBuyRefresh(newWarehouse); + END IF; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql b/db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql new file mode 100644 index 000000000..8e387ce1f --- /dev/null +++ b/db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`EntradasTriggerBeforeUpdate`(oldTravel INT, newTravel INT, oldRedada BOOLEAN, + newRedada BOOLEAN, newId INT) +BEGIN + DECLARE newWarehouse INTEGER; + DECLARE hasToRecalculate BOOLEAN; + + IF oldRedada <> newRedada OR newTravel IS NULL THEN + + SELECT Id_Compra INTO hasToRecalculate FROM Compres c + JOIN vn.lastBuy lb ON lb.id = c.Id_Compra + WHERE c.Id_Entrada = newId LIMIT 1; + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel WHERE id = newtravel; + CALL vn.lastBuyRefresh(newWarehouse); + END IF; + END IF; + + IF newTravel <> oldTravel AND newTravel IS NOT NULL THEN + UPDATE travel t + JOIN Compres c ON c.Id_Entrada = newId + JOIN vn.lastBuy lb ON c.Id_Article = lb.item AND t.warehouse_id = lb.warehouse + SET lb.id = c.Id_Compra + WHERE t.id = newTravel AND t.landing BETWEEN vn.getInventoryDate() AND util.yesterday() + AND t.landing > lb.landing; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/Facturas_Saltos.sql b/db/routines/vn2008/procedures/Facturas_Saltos.sql new file mode 100644 index 000000000..22c7ab516 --- /dev/null +++ b/db/routines/vn2008/procedures/Facturas_Saltos.sql @@ -0,0 +1,65 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Facturas_Saltos`(IN datSTART DATE , IN datEND DATE) +BEGIN + + +DECLARE strSER1 VARCHAR(2); +DECLARE strSER2 VARCHAR(2); +DECLARE intEMP1 INT; +DECLARE intEMP2 INT; +DECLARE v_done BOOLEAN DEFAULT FALSE; +DECLARE strFAC1 VARCHAR(11); +DECLARE strFAC2 VARCHAR(11); + + +DECLARE rs CURSOR FOR + SELECT Id_Factura, empresa_id, Serie + FROM Facturas + WHERE Fecha BETWEEN datSTART AND datEND + ORDER BY empresa_id, Serie, Id_Factura; + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; + +OPEN rs; + +DROP TEMPORARY TABLE IF EXISTS Facturas_Saltarinas; + +CREATE TEMPORARY TABLE Facturas_Saltarinas +(Factura_Inicial VARCHAR(11), + Factura_Final VARCHAR(11), + Empresa VARCHAR(3), + Serie VARCHAR(1)); + +FETCH rs INTO strFAC1, intEMP1, strSER1; + +IF NOT v_done THEN + + FETCH rs INTO strFAC2, intEMP2, strSER2; + +END IF; + +WHILE NOT v_done DO + + IF strSER1 = strSER2 AND intEMP1 = intEMP2 AND right(strFAC2,5) - right(strFAC1,5) > 1 then + + INSERT INTO Facturas_Saltarinas(Factura_Inicial, Factura_Final, Empresa, Serie) + SELECT strFAC1, strFAC2, abbreviation, strSER1 + FROM empresa + WHERE id = intEMP1; + + END IF; + + SET strFAC1 = strFAC2; + SET intEMP1 = intEMP2; + SET STRSER1 = strSER2; + + FETCH rs INTO strFAC2, intEMP2, strSER2; + +END WHILE; + +SELECT * FROM Facturas_Saltarinas; + +CLOSE rs; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/InsertarEspionaje.sql b/db/routines/vn2008/procedures/InsertarEspionaje.sql new file mode 100644 index 000000000..5ddc1c820 --- /dev/null +++ b/db/routines/vn2008/procedures/InsertarEspionaje.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`InsertarEspionaje`(intIdTrabajador INT(11),intIdEquipo int) +BEGIN + +DECLARE intNReg TINYINT DEFAULT 0; + +SELECT Count(*) AS NReg +INTO intNReg +FROM Espionajes +WHERE Fecha=Current_date +AND Id_Trabajador=intIdTrabajador; + +IF (intNReg=0) THEN + INSERT INTO Espionajes (Id_Trabajador,Fecha,HoraEntrada,Id_Equipo) + VALUES (intIdTrabajador,CURRENT_DATE,CURRENT_TIME,intIdEquipo); +ELSE + UPDATE Espionajes + SET HoraSalida=CURRENT_TIME + WHERE Id_Trabajador=intIdTrabajador + AND Fecha=util.VN_CURDATE(); +END IF; + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/ListaTicketsEncajados.sql b/db/routines/vn2008/procedures/ListaTicketsEncajados.sql new file mode 100644 index 000000000..3d3318c63 --- /dev/null +++ b/db/routines/vn2008/procedures/ListaTicketsEncajados.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`ListaTicketsEncajados`(IN intId_Trabajador int) +BEGIN + +SELECT Agencia, + Consignatario, + ti.Id_Ticket, + ts.userFk Id_Trabajador, + IFNULL(ncajas,0) AS ncajas, + IFNULL(nbultos,0) AS nbultos, + IFNULL(notros,0) AS notros, + ts.code AS Estado + FROM Tickets ti + INNER JOIN Consignatarios ON ti.Id_Consigna = Consignatarios.Id_consigna + INNER JOIN Agencias ON ti.Id_Agencia = Agencias.Id_Agencia + LEFT JOIN (SELECT Ticket_Id,count(*) AS ncajas FROM expeditions WHERE Id_Article=94 GROUP BY ticket_id) sub1 ON ti.Id_Ticket=sub1.Ticket_Id + LEFT JOIN (SELECT Ticket_Id,count(*) AS nbultos FROM expeditions WHERE Id_Article IS NULL GROUP BY ticket_id) sub2 ON ti.Id_Ticket=sub2.Ticket_Id + LEFT JOIN (SELECT Ticket_Id,count(*) AS notros FROM expeditions WHERE Id_Article >0 GROUP BY ticket_id) sub3 ON ti.Id_Ticket=sub3.Ticket_Id + INNER JOIN vn.ticketState ts ON ti.Id_ticket = ts.ticketFk + WHERE ti.Fecha=util.VN_CURDATE() AND + ts.userFk=intId_Trabajador + GROUP BY ti.Id_Ticket; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/Rutas_Graph.sql b/db/routines/vn2008/procedures/Rutas_Graph.sql new file mode 100644 index 000000000..b1a7471d0 --- /dev/null +++ b/db/routines/vn2008/procedures/Rutas_Graph.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Rutas_Graph`() +BEGIN + + DECLARE datSTART DATE DEFAULT TIMESTAMPADD(DAY,-3,util.VN_CURDATE()); + DECLARE datEND DATE; + + SET datEND = util.dayEnd(timestampadd(DAY,3,util.VN_CURDATE())); + + CALL vn.buyUltimate(NULL, datSTART); + + SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(buy_id)) / 1000000 AS DECIMAL(5,1)) AS m3, Agencia, w.name AS Almacen, DATE(R.Fecha) AS Fecha_Ruta + FROM vn2008.Rutas R + JOIN vn2008.Agencias a ON a.Id_Agencia = R.Id_Agencia + JOIN vn2008.Tickets t USING(Id_Ruta) + JOIN vn2008.warehouse w ON w.id = t.warehouse_id + JOIN vn2008.Movimientos m USING(Id_Ticket) + JOIN cache.last_buy b ON m.Id_Article = b.item_id AND t.warehouse_id = b.warehouse_id + WHERE R.Fecha BETWEEN datSTART AND datEND + GROUP BY Agencia, Almacen, Fecha_Ruta + UNION ALL + SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(buy_id)) / 1000000 AS decimal(5,1)) AS m3 ,Agencia, w.name AS Almacen, timestampadd(DAY,1,t.Fecha) AS Fecha + FROM vn2008.Tickets t + JOIN warehouse w ON w.id = warehouse_id + JOIN Agencias a USING(Id_Agencia) + JOIN vn2008.Movimientos m USING(Id_Ticket) + JOIN cache.last_buy b ON m.Id_Article = b.item_id AND t.warehouse_id = b.warehouse_id + LEFT JOIN warehouse_pickup wp ON wp.agency_id = t.Id_Agencia and wp.warehouse_id = t.warehouse_id + JOIN warehouse_pickup is_rec ON is_rec.agency_id = t.Id_Agencia + WHERE t.Fecha BETWEEN TIMESTAMPADD(DAY,-1,datSTART) AND TIMESTAMPADD(DAY,-1,datEND) + AND wp.agency_id IS NULL + GROUP BY Agencia, Almacen, timestampadd(DAY,1,t.Fecha) + -- JGF 2016-05-05 + UNION ALL + SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(Id_Compra)) / 1000000 AS decimal(5,1)) AS m3 ,a.Agencia, w.name AS Almacen, timestampadd(DAY,1,t.shipment) AS Fecha + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + JOIN Agencias a ON a.Id_Agencia = t.agency_id + JOIN warehouse w ON w.id = t.warehouse_id_out + JOIN warehouse_pickup wp ON wp.warehouse_id = t.warehouse_id_out + WHERE t.shipment BETWEEN TIMESTAMPADD(DAY,-1,datSTART) AND TIMESTAMPADD(DAY,-1,datEND) + GROUP BY a.Agencia, Almacen, Fecha; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/Trabuque.sql b/db/routines/vn2008/procedures/Trabuque.sql new file mode 100644 index 000000000..9efbc86c9 --- /dev/null +++ b/db/routines/vn2008/procedures/Trabuque.sql @@ -0,0 +1,72 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Trabuque`(IN intIDTICKET BIGINT, IN dblINCREMENTO DOUBLE ) +BEGIN + + + +#Vamos a calcular el porcentaje a incrementar las cantidades de las lineas de movimiento para inflar / desinflar la base final + +DECLARE dblBASE_INICIAL DOUBLE DEFAULT 0; +DECLARE dblBASE_FINAL DOUBLE DEFAULT 0; +DECLARE dblAUMENTO DOUBLE DEFAULT 1; + + +SELECT SUM(Cantidad * Preu * (100 - Descuento) / 100) +INTO dblBASE_INICIAL +FROM Movimientos +WHERE Id_Ticket = intIDTICKET; + +SET dblBASE_FINAL = dblBASE_INICIAL; + + +#Eliminamos lineas a 0 + +DELETE FROM Movimientos WHERE Cantidad = 0 AND Id_Ticket = intIDTICKET; + +# Vamos a ir probando incrementos paulatinos hasta que encontremos el que supera lo pedido, teniendo en cuenta el sentido del incremento + +IF dblINCREMENTO < 0 THEN + + + + WHILE (dblBASE_FINAL > dblBASE_INICIAL + dblINCREMENTO) or (dblAUMENTO < 0 ) DO + + SET dblAUMENTO = dblAUMENTO - 0.01; + + SELECT SUM(IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) * Preu * (100 - Descuento) / 100) + INTO dblBASE_FINAL + FROM Movimientos + WHERE Id_Ticket = intIDTICKET; + + END WHILE; + +ELSE + + WHILE dblBASE_FINAL < dblBASE_INICIAL + dblINCREMENTO DO + + SET dblAUMENTO = dblAUMENTO + 0.01; + + SELECT SUM(IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) * Preu * (100 - Descuento) / 100) + INTO dblBASE_FINAL + FROM Movimientos + WHERE Id_Ticket = intIDTICKET; + + END WHILE; + +END IF; + +UPDATE Movimientos +SET Cantidad = IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) +WHERE Id_Ticket = intIDTICKET; + +SELECT tipoiva + , ROUND(SUM(Cantidad * Preu * (100 - Descuento) / 100),2) as Base + , ROUND(ROUND(SUM(Cantidad * Preu * (100 - Descuento) / 100),2) * iva / 100,2) as Cuota +FROM Movimientos M +INNER JOIN Articles A USING(Id_Article) +INNER JOIN tblIVA USING(tipoiva) +WHERE Id_Ticket = intIDTICKET +GROUP BY tipoiva; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql b/db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql new file mode 100644 index 000000000..5c8f174be --- /dev/null +++ b/db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Vehiculos_consumo_calculateLiters100km`() +BEGIN + DECLARE vConsumptionVehicleId INT; + DECLARE vDone BOOL; + DECLARE vOldKm INT; + DECLARE vOldLiters INT; + DECLARE vNewKm INT; + DECLARE vVehicleId INT; + + DECLARE cur CURSOR FOR + SELECT Vehiculos_consumo_id, Id_Vehiculo, km FROM vn2008.Vehiculos_consumo; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vConsumptionVehicleId, vVehicleId, vNewKm; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT km, litros INTO vOldKm, vOldLiters + FROM Vehiculos_consumo + WHERE Id_Vehiculo = vVehicleId + AND Vehiculos_consumo_id < vConsumptionVehicleId + ORDER BY Vehiculos_consumo_id DESC + LIMIT 1; + + UPDATE Vehiculos_consumo + SET liters100km = vOldLiters/((vNewKm-vOldKm)*0.01) + WHERE Vehiculos_consumo_id = vConsumptionVehicleId; + + END LOOP; + + CLOSE cur; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/XDiario_Quadrator.sql b/db/routines/vn2008/procedures/XDiario_Quadrator.sql new file mode 100644 index 000000000..c95a3a892 --- /dev/null +++ b/db/routines/vn2008/procedures/XDiario_Quadrator.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`XDiario_Quadrator`() +BEGIN + INSERT INTO vn.mail (receiver, subject, body) + SELECT 'cau@verdnatura.es', + 'asientos descuadrados', + group_concat(CONCAT(' Asiento: ', ASIEN, '- importe:', quadre) SEPARATOR ' \r\n ') + FROM ( + SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) quadre + FROM XDiario + WHERE enlazado = FALSE + GROUP BY ASIEN + HAVING ABS(SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0))) > 0.01 + ) t + HAVING count(*) > 0; + + UPDATE XDiario XD + INNER JOIN( + SELECT XD.id, SUBCTA, Quadre FROM XDiario XD + INNER JOIN ( + SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) as Quadre + FROM XDiario + WHERE enlazado = FALSE + GROUP BY ASIEN + HAVING Quadre != 0 + ) sub USING(ASIEN) + WHERE SUBCTA > '5999999999' + GROUP BY ASIEN + ) sub2 USING(id) + SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre), + Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre); + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/account_conciliacion_add.sql b/db/routines/vn2008/procedures/account_conciliacion_add.sql new file mode 100644 index 000000000..94ef0b14b --- /dev/null +++ b/db/routines/vn2008/procedures/account_conciliacion_add.sql @@ -0,0 +1,33 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`account_conciliacion_add`() +BEGIN + UPDATE account_conciliacion ac + JOIN + ( + SELECT idaccount_conciliacion, @c:= if(@id = id_calculated, @c + 1, 1) contador, + @id:= id_calculated as id_calculated, concat(id_calculated,'(',@c,')') as new_id + FROM account_conciliacion + JOIN + ( + select id_calculated, count(*) rep, @c:= 0, @id:= concat('-',id_calculated) + from account_conciliacion + group by id_calculated + having rep > 1 + ) sub using(id_calculated) + ) sub2 using(idaccount_conciliacion) + SET ac.id_calculated = sub2.new_id; + + INSERT INTO Cajas(Cajafecha, Partida, Serie, Concepto, Entrada, + Salida, Id_Banco,empresa_id, warehouse_id, + Proveedores_account_id, id_calculated, InForeignValue, OutForeignValue, Id_Trabajador) + SELECT Fechaoperacion, TRUE, 'MB', ac.Concepto, IF(DebeHaber = 2 AND currencyFk = 1, importe,null), + IF(DebeHaber = 1 AND currencyFk = 1, importe, null), a.id, sa.supplierFk, 1, + ac.Id_Proveedores_account, ac.id_calculated, IF(DebeHaber = 2 AND NOT currencyFk = 1, importe, null), + IF(DebeHaber = 1 AND NOT currencyFk = 1, importe, null), account.myUser_getId() + FROM account_conciliacion ac + JOIN vn.supplierAccount sa on sa.id = ac.Id_Proveedores_account + JOIN vn.accounting a ON a.id = sa.accountingFk + LEFT JOIN Cajas c on c.id_calculated = ac.id_calculated + WHERE c.Id_Caja IS NULL; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/add_awb_component.sql b/db/routines/vn2008/procedures/add_awb_component.sql new file mode 100644 index 000000000..a563bd0df --- /dev/null +++ b/db/routines/vn2008/procedures/add_awb_component.sql @@ -0,0 +1,64 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`add_awb_component`(IN vAwbFk SMALLINT) +BEGIN + + DECLARE vShipped DATE; + DECLARE vHasStems BOOLEAN; + + SELECT tr.shipped, IF(a.stems, TRUE, FALSE) + INTO vShipped, vHasStems + FROM vn.travel tr + JOIN vn.entry e ON e.travelFk = tr.id + JOIN vn.duaEntry de ON de.entryFk = e.id + JOIN vn.dua d ON d.id = de.duaFk + JOIN vn.awb a ON a.id = d.awbFk + WHERE awbFk = vAwbFk + LIMIT 1; + + INSERT IGNORE INTO awb_component (awb_id,Id_Proveedor,awb_component_type_id,awb_role_id,awb_unit_id,value,Id_Moneda) + SELECT id, Id_Proveedor, awb_component_type_id, awb_role_id,awb_unit_id, LEAST(GREATEST(value1, IFNULL(min_value, value1)), IFNULL(max_value, value1)), Id_Moneda + FROM ( + SELECT a.id, + IFNULL(act.carguera_id, + CASE awb_role_id + WHEN 1 THEN a.carguera_id + WHEN 2 THEN a.transitario_id + WHEN 3 THEN f.airline_id + END + ) Id_Proveedor, + act.awb_component_type_id, + act.awb_role_id, + act.awb_unit_id, + value * + CASE awb_unit_id + WHEN '1000Tj-20' THEN ((CAST(stems AS SIGNED) - 20000)/1000) + (min_value / value) + WHEN '1000Tj-10' THEN ((CAST(stems AS SIGNED) - 10000)/1000) + (min_value / value) + WHEN '100GW' THEN peso/100 + WHEN 'AWB' THEN 1 -- No action + WHEN 'FB' THEN hb/2 + WHEN 'GW' THEN peso + WHEN 'TW' THEN GREATEST(peso,volume_weight) + WHEN 'PN' THEN LEAST(90, value + a.propertyNumber * 10) + END value1, + value, + act.Id_Moneda, + act.min_value, + act.max_value + FROM awb a + JOIN flight f ON f.flight_id = a.flight_id + LEFT JOIN awb_component_template act ON + ((IFNULL(act.carguera_id, a.carguera_id) = a.carguera_id AND awb_role_id = 1) + OR (IFNULL(act.carguera_id, a.transitario_id) = a.transitario_id AND awb_role_id = 2) + OR (IFNULL(act.airline_id, f.airline_id) = f.airline_id AND awb_role_id = 3) + OR (awb_role_id = 4)) + AND IFNULL(act.airport_out, f.airport_out) = f.airport_out + AND IFNULL(act.airport_in, f.airport_in) = f.airport_in + AND IFNULL(act.airline_id, f.airline_id) = f.airline_id + AND INSTR(IFNULL(act.days, WEEKDAY(vShipped) + 1),WEEKDAY(vShipped) + 1) + JOIN awb_component_type acty ON acty.awb_component_type_id = act.awb_component_type_id + WHERE a.id = vAwbFk AND Fecha <= vShipped + AND (vHasStems = TRUE OR acty.hasStems) + ORDER BY Fecha DESC, act.days DESC LIMIT 10000000000000000000 + ) t; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/agencia_descuadre.sql b/db/routines/vn2008/procedures/agencia_descuadre.sql new file mode 100644 index 000000000..59bf2476d --- /dev/null +++ b/db/routines/vn2008/procedures/agencia_descuadre.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`agencia_descuadre`(vFrom DATE, vTo DATE, vAgencyModeFk INT, vWarehouseAlias INT) +BEGIN + DECLARE vToDayEnd DATETIME; + + SET vToDayEnd = util.dayEnd(vTo); + + SELECT t.id ticketFk,t.addressFk, + v.amount AS VN, v.amount - shipping_charge AS Difer, + e.shipping_charge AS teorico, t.packages, t.clientFk, t.zoneFk, a.provinceFk + + FROM vn.ticket t + LEFT JOIN + (SELECT ticketFk, SUM(amount) amount,shipped + FROM vn.sale_freightComponent + WHERE shipped BETWEEN vFrom AND vToDayEnd + GROUP BY ticketFk) v ON t.id = v.ticketFk + LEFT JOIN (SELECT t.id, SUM(t.zonePrice * ebv.ratio) shipping_charge + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk + WHERE t.shipped BETWEEN vFrom AND vToDayEnd + GROUP BY t.id + ) e ON t.id = e.id + JOIN vn.address a ON a.id = t.addressFk + JOIN warehouse_group wg ON wg.warehouse_id = t.warehouseFk + WHERE DATE(t.shipped) BETWEEN vFrom AND vToDayEnd + AND t.agencyModeFk = vAgencyModeFk + AND wg.warehouse_alias_id = vWarehouseAlias; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/agencia_volume.sql b/db/routines/vn2008/procedures/agencia_volume.sql new file mode 100644 index 000000000..ea631793d --- /dev/null +++ b/db/routines/vn2008/procedures/agencia_volume.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`agencia_volume`() +BEGIN + DECLARE vStarted DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE()); + DECLARE vEnded DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE(), '23:59:59'); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_PackagingEstimated; + CREATE TEMPORARY TABLE tmp.ticket_PackagingEstimated + ( + ticketFk INT PRIMARY KEY + ,boxes INT DEFAULT 0 + ); + + INSERT INTO tmp.ticket_PackagingEstimated(ticketFk, boxes) + SELECT sv.ticketFk, CEIL(1000 * sum(sv.volume) / vc.standardFlowerBox) + FROM vn.ticket t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.volumeConfig vc + WHERE t.shipped BETWEEN vStarted AND vEnded + AND IFNULL(t.packages,0) = 0 + GROUP BY t.id; + SELECT * FROM + ( + SELECT ag.id agency_id, + CONCAT(RPAD(c.country, 16,' _') ,' ',ag.name) Agencia, + count(*) expediciones, + sum(t.packages) Bultos, + sum(tpe.boxes) Faltan + FROM vn.ticket t + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.country c ON w.countryFk = c.id + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.agency ag ON ag.id = am.agencyFk + JOIN tmp.ticket_PackagingEstimated tpe ON tpe.ticketFk = t.id + WHERE t.shipped BETWEEN vStarted AND vEnded + AND ag.isOwn = FALSE + GROUP BY ag.id + ) sub + ORDER BY Agencia; + + DROP TEMPORARY TABLE tmp.ticket_PackagingEstimated; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/agencyModeImbalance.sql b/db/routines/vn2008/procedures/agencyModeImbalance.sql new file mode 100644 index 000000000..89706f0d2 --- /dev/null +++ b/db/routines/vn2008/procedures/agencyModeImbalance.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`agencyModeImbalance`(vStarted DATE, vEnded DATE) +BEGIN +/** + * Devuelve el valor de los precios teorico, practico de las agencias + * y si ademas es de mrw lo compara con su fichero previamente procesado + * + * @param vEktFk Identificador de edi.ekt + */ + DECLARE vEndedDayEnd DATETIME; + + SET vEndedDayEnd = util.dayEnd(vEnded); + + SELECT t.id ticketFk,t.addressFk, + CAST(v.amount AS DECIMAL (10,2)) AS VN, + CAST(v.amount - e.shipping_charge AS DECIMAL (10,2)) AS Difer, + CAST(mrwPrice AS DECIMAL (10,2)) mrwPrice, + CAST(e.shipping_charge - mrwPrice AS DECIMAL (10,2)) mrwDifference, + CAST(e.shipping_charge AS DECIMAL (10,2)) AS teorico, + CAST(e.extraCharge AS DECIMAL (10,2)) AS extraCharge, + t.packages, t.clientFk, + t.zoneFk, a.provinceFk, mrwCount + FROM vn.ticket t + LEFT JOIN + (SELECT ticketFk, SUM(amount) amount, fc.shipped + FROM vn.sale_freightComponent fc + JOIN vn.ticket t ON t.id = fc.ticketFk + JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk + WHERE fc.shipped BETWEEN vStarted AND vEndedDayEnd + GROUP BY ticketFk) v ON t.id = v.ticketFk + LEFT JOIN (SELECT t.id, + SUM(t.zonePrice) shipping_charge, + SUM(IFNULL(aex.price,0)) extraCharge + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + LEFT JOIN vn.packaging p ON p.id = e.packagingFk + JOIN tmp.agencyMode amc ON amc.agencyModeFk = t.agencyModeFk + JOIN vn.agencyMode am ON am.id = amc.agencyModeFk + LEFT JOIN vn.agencyExtraCharge aex ON p.width+p.depth+p.height BETWEEN aex.sizeMin AND aex.sizeMax AND aex.agencyFk = am.agencyFk + WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd + GROUP BY t.id + ) e ON t.id = e.id + LEFT JOIN (SELECT ticketFk, SUM(price) mrwPrice, COUNT(*) mrwCount + FROM vn.mrw + GROUP BY ticketFk) mrw ON mrw.ticketFk = t.id + JOIN vn.address a ON a.id = t.addressFk + JOIN tmp.agencyMode am ON am.agencyModeFk = t.agencyModeFk + WHERE t.shipped BETWEEN vStarted AND vEndedDayEnd; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/article.sql b/db/routines/vn2008/procedures/article.sql new file mode 100644 index 000000000..3c2664c0f --- /dev/null +++ b/db/routines/vn2008/procedures/article.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`article`() +BEGIN +/** + * Crea la tabla temporal: article_inventory + */ + DROP TEMPORARY TABLE IF EXISTS article_inventory; + CREATE TEMPORARY TABLE article_inventory + ( + `article_id` INT(11) NOT NULL PRIMARY KEY, + `future` DATETIME + ) + ENGINE = MEMORY; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/article_available_single.sql b/db/routines/vn2008/procedures/article_available_single.sql new file mode 100644 index 000000000..efc0df3b7 --- /dev/null +++ b/db/routines/vn2008/procedures/article_available_single.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`article_available_single`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT) +BEGIN + +/* CALL bionic_available_single (v_wh, v_date,id_single,0);*/ + + + SELECT available AS minimo FROM tmp.item + WHERE item_id = id_single; +-- ixen totes les linies en lloc d'una sola + DROP TEMPORARY TABLE IF EXISTS tmp.item; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/article_multiple_buy.sql b/db/routines/vn2008/procedures/article_multiple_buy.sql new file mode 100644 index 000000000..5b0d402c5 --- /dev/null +++ b/db/routines/vn2008/procedures/article_multiple_buy.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`article_multiple_buy`(v_date DATETIME, wh INT) +BEGIN + CALL vn.item_multipleBuy(v_date, wh); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/article_multiple_buy_date.sql b/db/routines/vn2008/procedures/article_multiple_buy_date.sql new file mode 100644 index 000000000..7b197cb01 --- /dev/null +++ b/db/routines/vn2008/procedures/article_multiple_buy_date.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`article_multiple_buy_date`( + IN vDated DATETIME, + IN vWarehouseFk TINYINT(3) +) +BEGIN + CALL vn.item_multipleBuyByDate(vDated, vWarehouseFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/availableTraslate.sql b/db/routines/vn2008/procedures/availableTraslate.sql new file mode 100644 index 000000000..6328560c8 --- /dev/null +++ b/db/routines/vn2008/procedures/availableTraslate.sql @@ -0,0 +1,126 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`availableTraslate`( + vWarehouseLanding INT, + vDated DATE, + vWarehouseShipment INT) +proc: BEGIN + DECLARE vDatedFrom DATE; + DECLARE vDatedTo DATETIME; + DECLARE vDatedReserve DATETIME; + DECLARE vDatedInventory DATE; + + IF vDated < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + CALL vn.item_getStock (vWarehouseLanding, vDated, NULL); + + -- Calcula algunos parámetros necesarios + SET vDatedFrom = TIMESTAMP(vDated, '00:00:00'); + SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59'); + SELECT FechaInventario INTO vDatedInventory FROM tblContadores; + SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vDatedReserve + FROM hedera.orderConfig; + + -- Calcula el ultimo dia de vida para cada producto + DROP TEMPORARY TABLE IF EXISTS itemRange; + CREATE TEMPORARY TABLE itemRange + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT c.itemFk, MAX(t.landed) dated + FROM vn.buy c + JOIN vn.entry e ON c.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDatedInventory AND vDatedFrom + AND t.warehouseInFk = vWarehouseLanding + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + GROUP BY c.itemFk; + + -- Tabla con el ultimo dia de last_buy para cada producto que hace un replace de la anterior + CALL vn.buyUltimate(vWarehouseShipment, util.VN_CURDATE()); + + INSERT INTO itemRange + SELECT t.itemFk, tr.landed + FROM tmp.buyUltimate t + JOIN vn.buy b ON b.id = t.buyFk + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + LEFT JOIN itemRange i ON t.itemFk = i.itemFk + WHERE t.warehouseFk = vWarehouseShipment + AND NOT e.isRaid + ON DUPLICATE KEY UPDATE itemRange.dated = GREATEST(itemRange.dated, tr.landed); + + DROP TEMPORARY TABLE IF EXISTS itemRangeLive; + CREATE TEMPORARY TABLE itemRangeLive + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT ir.itemFk, TIMESTAMP(TIMESTAMPADD(DAY, it.life, ir.dated), '23:59:59') dated + FROM itemRange ir + JOIN vn.item i ON i.id = ir.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + HAVING dated >= vDatedFrom OR dated IS NULL; + + -- Calcula el ATP + DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc; + CREATE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk,warehouseFk)) + ENGINE = MEMORY + SELECT i.item_id itemFk, vWarehouseLanding warehouseFk, i.dat dated, i.amount quantity + FROM item_out i + JOIN itemRangeLive ir ON ir.itemFK = i.item_id + WHERE i.dat >= vDatedFrom + AND (ir.dated IS NULL OR i.dat <= ir.dated) + AND i.warehouse_id = vWarehouseLanding + UNION ALL + SELECT b.itemFk, vWarehouseLanding, t.landed, b.quantity + FROM vn.buy b + JOIN vn.entry e ON b.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN itemRangeLive ir ON ir.itemFk = b.itemFk + WHERE NOT e.isExcludedFromAvailable + AND b.quantity <> 0 + AND NOT e.isRaid + AND t.warehouseInFk = vWarehouseLanding + AND t.landed >= vDatedFrom + AND (ir.dated IS NULL OR t.landed <= ir.dated) + UNION ALL + SELECT i.item_id, vWarehouseLanding, i.dat, i.amount + FROM item_entry_out i + JOIN itemRangeLive ir ON ir.itemFk = i.item_id + WHERE i.dat >= vDatedFrom + AND (ir.dated IS NULL OR i.dat <= ir.dated) + AND i.warehouse_id = vWarehouseLanding + UNION ALL + SELECT r.item_id, vWarehouseLanding, r.shipment, -r.amount + FROM hedera.order_row r + JOIN hedera.`order` o ON o.id = r.order_id + JOIN itemRangeLive ir ON ir.itemFk = r.item_id + WHERE r.shipment >= vDatedFrom + AND (ir.dated IS NULL OR r.shipment <= ir.dated) + AND r.warehouse_id = vWarehouseLanding + AND r.created >= vDatedReserve + AND NOT o.confirmed; + + CALL vn.item_getAtp(vDated); + + DROP TEMPORARY TABLE IF EXISTS availableTraslate; + CREATE TEMPORARY TABLE availableTraslate + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT t.item_id, SUM(stock) available + FROM ( + SELECT ti.itemFk item_id, stock + FROM tmp.itemList ti + JOIN itemRange ir ON ir.itemFk = ti.itemFk + UNION ALL + SELECT itemFk, quantity + FROM tmp.itemAtp + ) t + GROUP BY t.item_id + HAVING available <> 0; + + DROP TEMPORARY TABLE tmp.itemList, itemRange, itemRangeLive; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/balance_create.sql b/db/routines/vn2008/procedures/balance_create.sql new file mode 100644 index 000000000..978dae720 --- /dev/null +++ b/db/routines/vn2008/procedures/balance_create.sql @@ -0,0 +1,207 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`balance_create`( + IN vStartingMonth INT, + IN vEndingMonth INT, + IN vCompany INT, + IN vIsConsolidated BOOLEAN, + IN vInterGroupSalesIncluded BOOLEAN) +BEGIN + DECLARE intGAP INT DEFAULT 7; + DECLARE vYears INT DEFAULT 2; + DECLARE vYear TEXT; + DECLARE vOneYearAgo TEXT; + DECLARE vTwoYearsAgo TEXT; + DECLARE vQuery TEXT; + DECLARE vConsolidatedGroup INT; + DECLARE vStartingDate DATE DEFAULT '2020-01-01'; + DECLARE vCurYear INT DEFAULT YEAR(util.VN_CURDATE()); + DECLARE vStartingYear INT DEFAULT vCurYear - 2; + DECLARE vTable TEXT; + + SET vTable = util.quoteIdentifier('balance_nest_tree'); + SET vYear = util.quoteIdentifier(vCurYear); + SET vOneYearAgo = util.quoteIdentifier(vCurYear-1); + SET vTwoYearsAgo = util.quoteIdentifier(vCurYear-2); + + -- Solicitamos la tabla tmp.nest, como base para el balance + DROP TEMPORARY TABLE IF EXISTS tmp.nest; + + EXECUTE IMMEDIATE CONCAT( + 'CREATE TEMPORARY TABLE tmp.nest + SELECT node.id + ,CONCAT( REPEAT(REPEAT(" ",?), COUNT(parent.id) - 1), node.name) AS name + ,node.lft + ,node.rgt + ,COUNT(parent.id) - 1 as depth + ,cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons + FROM ', vTable, ' AS node, + ', vTable, ' AS parent + WHERE node.lft BETWEEN parent.lft AND parent.rgt + GROUP BY node.id + ORDER BY node.lft') + USING intGAP; + + DROP TEMPORARY TABLE IF EXISTS tmp.balance; + CREATE TEMPORARY TABLE tmp.balance + SELECT * FROM tmp.nest; + + DROP TEMPORARY TABLE IF EXISTS tmp.empresas_receptoras; + DROP TEMPORARY TABLE IF EXISTS tmp.empresas_emisoras; + + SELECT empresa_grupo INTO vConsolidatedGroup + FROM empresa + WHERE id = vCompany; + + CREATE TEMPORARY TABLE tmp.empresas_receptoras + SELECT id as empresa_id + FROM vn2008.empresa + WHERE id = vCompany + OR empresa_grupo = IF(vIsConsolidated, vConsolidatedGroup, NULL); + + CREATE TEMPORARY TABLE tmp.empresas_emisoras + SELECT Id_Proveedor as empresa_id FROM vn2008.Proveedores p; + + IF vInterGroupSalesIncluded = FALSE THEN + + DELETE ee.* + FROM tmp.empresas_emisoras ee + JOIN vn2008.empresa e on e.id = ee.empresa_id + WHERE e.empresa_grupo = vConsolidatedGroup; + + END IF; + + -- Se calculan las facturas que intervienen, para luego poder servir el desglose desde aqui + DROP TEMPORARY TABLE IF EXISTS tmp.balance_desglose; + CREATE TEMPORARY TABLE tmp.balance_desglose + SELECT er.empresa_id receptora_id, + ee.empresa_id emisora_id, + year(IFNULL(r.bookEntried,IFNULL(r.dateBooking, r.Fecha))) `year`, + month(IFNULL(r.bookEntried,IFNULL(r.dateBooking, r.Fecha))) `month`, + gastos_id Id_Gasto, + SUM(bi) importe + FROM recibida r + JOIN recibida_iva ri on ri.recibida_id = r.id + JOIN tmp.empresas_receptoras er on er.empresa_id = r.empresa_id + JOIN tmp.empresas_emisoras ee ON ee.empresa_id = r.proveedor_id + WHERE IFNULL(r.bookEntried,IFNULL(r.dateBooking, r.Fecha)) >= vStartingDate + AND r.contabilizada + GROUP BY Id_Gasto, year, month, emisora_id, receptora_id; + + INSERT INTO tmp.balance_desglose( + receptora_id, + emisora_id, + year, + month, + Id_Gasto, + importe) + SELECT gr.empresa_id, + gr.empresa_id, + year, + month, + Id_Gasto, + SUM(importe) + FROM gastos_resumen gr + JOIN tmp.empresas_receptoras er on gr.empresa_id = er.empresa_id + WHERE year >= vStartingYear + AND month BETWEEN vStartingMonth AND vEndingMonth + GROUP BY Id_Gasto, year, month, gr.empresa_id; + + DELETE FROM tmp.balance_desglose + WHERE month < vStartingMonth + OR month > vEndingMonth; + + -- Ahora el balance + EXECUTE IMMEDIATE CONCAT( + 'ALTER TABLE tmp.balance + ADD COLUMN ', vTwoYearsAgo ,' INT(10) NULL , + ADD COLUMN ', vOneYearAgo ,' INT(10) NULL , + ADD COLUMN ', vYear,' INT(10) NULL , + ADD COLUMN Id_Gasto VARCHAR(10) NULL, + ADD COLUMN Gasto VARCHAR(45) NULL'); + + -- Añadimos los gastos, para facilitar el formulario + UPDATE tmp.balance b + JOIN vn2008.balance_nest_tree bnt on bnt.id = b.id + JOIN (SELECT Id_Gasto, Gasto + FROM vn2008.Gastos + GROUP BY Id_Gasto) g ON g.Id_Gasto = bnt.Id_Gasto COLLATE utf8_general_ci + SET b.Id_Gasto = g.Id_Gasto COLLATE utf8_general_ci + , b.Gasto = g.Gasto COLLATE utf8_general_ci ; + + -- Rellenamos los valores de primer nivel, los que corresponden a los gastos simples + WHILE vYears >= 0 DO + SET vQuery = CONCAT( + 'UPDATE tmp.balance b + JOIN + (SELECT Id_Gasto, SUM(Importe) as Importe + FROM tmp.balance_desglose + WHERE year = ? + GROUP BY Id_Gasto + ) sub on sub.Id_Gasto = b.Id_Gasto COLLATE utf8_general_ci + SET ', util.quoteIdentifier(vCurYear - vYears), ' = - Importe'); + + EXECUTE IMMEDIATE vQuery + USING vCurYear - vYears; + + SET vYears = vYears - 1; + END WHILE; + + -- Añadimos las ventas + EXECUTE IMMEDIATE CONCAT( + 'UPDATE tmp.balance b + JOIN ( + SELECT SUM(IF(year = ?, venta, 0)) y2, + SUM(IF(year = ?, venta, 0)) y1, + SUM(IF(year = ?, venta, 0)) y0, + c.Gasto + FROM bs.ventas_contables c + JOIN tmp.empresas_receptoras er on er.empresa_id = c.empresa_id + WHERE month BETWEEN ? AND ? + GROUP BY c.Gasto + ) sub ON sub.Gasto = b.Id_Gasto COLLATE utf8_general_ci + SET b.', vTwoYearsAgo, '= IFNULL(b.', vTwoYearsAgo, ', 0) + sub.y2, + b.', vOneYearAgo, '= IFNULL(b.', vOneYearAgo, ', 0) + sub.y1, + b.', vYear, '= IFNULL(b.', vYear, ', 0) + sub.y0') + USING vCurYear-2, + vCurYear-1, + vCurYear, + vStartingMonth, + vEndingMonth; + + -- Ventas intra grupo + IF NOT vInterGroupSalesIncluded THEN + + SELECT lft, rgt INTO @grupoLft, @grupoRgt + FROM tmp.balance b + WHERE TRIM(b.`name`) = 'Grupo'; + + DELETE + FROM tmp.balance + WHERE lft BETWEEN @grupoLft AND @grupoRgt; + + END IF; + + -- Rellenamos el valor de los padres con la suma de los hijos + DROP TEMPORARY TABLE IF EXISTS tmp.balance_aux; + CREATE TEMPORARY TABLE tmp.balance_aux + SELECT * FROM tmp.balance; + + EXECUTE IMMEDIATE + CONCAT('UPDATE tmp.balance b + JOIN ( + SELECT b1.id, + b1.name, + SUM(b2.', vYear,') thisYear, + SUM(b2.', vOneYearAgo,') oneYearAgo, + SUM(b2.', vTwoYearsAgo,') twoYearsAgo + FROM tmp.nest b1 + JOIN tmp.balance_aux b2 on b2.lft BETWEEN b1.lft and b1.rgt + GROUP BY b1.id)sub ON sub.id = b.id + SET b.', vYear, ' = thisYear, + b.', vOneYearAgo, ' = oneYearAgo, + b.', vTwoYearsAgo, ' = twoYearsAgo'); + + SELECT *, CONCAT('',ifnull(Id_Gasto,'')) newgasto + FROM tmp.balance; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/base_ticket.sql b/db/routines/vn2008/procedures/base_ticket.sql new file mode 100644 index 000000000..2352eabaf --- /dev/null +++ b/db/routines/vn2008/procedures/base_ticket.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`base_ticket`(IN Id_Ticket INT) +BEGIN + SELECT + red(SUM(Cantidad * Preu * (100 - Descuento) / 100)) AS base + FROm + Movimientos m + INNER JOIN Tickets t USING (Id_Ticket) + WHERE t.Id_Ticket = Id_Ticket; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/bionic_available_types_filter.sql b/db/routines/vn2008/procedures/bionic_available_types_filter.sql new file mode 100644 index 000000000..308c6396e --- /dev/null +++ b/db/routines/vn2008/procedures/bionic_available_types_filter.sql @@ -0,0 +1,38 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`bionic_available_types_filter`( + v_date DATE, + v_consigna INT, + v_agencia INT) +BEGIN +/** + * Este procedimiento devuelve una tabla t_bionic_available_types + * que debe de ser borrar por quien la llame, y se conecta con la tabla articlelist + * que tambien hay que eliminar. + * + * @param vDatefecha de recepcion de mercancia + * @table t_bionic_available_types + */ + + CALL vn.catalog_Calculate(v_date, v_consigna, v_agencia); + + -- Introducimos los valores en una tabla temporal + DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types; + + CALL check_table_existence('articlelist'); + + IF @table_exists THEN + call util.throw('No usar articlelist'); + END IF; + + CREATE TEMPORARY TABLE t_bionic_available_types + SELECT a.tipo_id, t.Tipo, r.reino, count(*) as item_count + FROM tmp.ticketCalculateItem tci + JOIN vn2008.Articles a ON tci.itemFk = a.Id_Article + JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id + JOIN vn2008.reinos r ON r.id = t.reino_id + WHERE tci.available > 0 + GROUP BY a.tipo_id; + + DROP TEMPORARY TABLE tmp.ticketCalculateItem; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_label.sql b/db/routines/vn2008/procedures/buy_label.sql new file mode 100644 index 000000000..0ee1be5a4 --- /dev/null +++ b/db/routines/vn2008/procedures/buy_label.sql @@ -0,0 +1,40 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_label`(IN entry_id_ INT, IN groupby TINYINT(1)) +BEGIN + + DECLARE done INT DEFAULT 0; + DECLARE label INT; + DECLARE id INT; + DECLARE recordset CURSOR FOR SELECT Compres.Etiquetas, Compres.Id_Compra FROM Compres INNER JOIN + (SELECT e.Id_entrada FROM Entradas e INNER JOIN ( + SELECT Id_Entrada,Inventario,Id_proveedor,travel_id,Id_Agencia FROM Entradas e1 INNER JOIN travel t ON e1.travel_id = t.id WHERE Id_Entrada = entry_id_) y + ON y.Inventario = e.Inventario AND e.travel_id = y.travel_id AND e.Id_proveedor = y.Id_proveedor AND y.Id_Agencia = e.Id_Agencia + WHERE (0 OR e.Id_Entrada = entry_id_)) entry_label + ON Compres.Id_Entrada = entry_label.Id_entrada + INNER JOIN Articles ON Compres.Id_Article = Articles.Id_Article WHERE Articles.Imprimir <> FALSE; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + DROP TEMPORARY TABLE IF EXISTS `buy_label_source`; + + CREATE TEMPORARY TABLE `buy_label_source` + ( + `buy_id` INT(11) NOT NULL + ) + + ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + OPEN recordset; + + REPEAT + + FETCH recordset INTO label, id; + WHILE label > 0 DO + + SET label = label - 1; + INSERT INTO buy_label_source (buy_id) VALUES (id); + + END WHILE; + + UNTIL done END REPEAT; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_split.sql b/db/routines/vn2008/procedures/buy_split.sql new file mode 100644 index 000000000..188bd89ec --- /dev/null +++ b/db/routines/vn2008/procedures/buy_split.sql @@ -0,0 +1,150 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_split`(IN `v_buy` INT, IN `v_entry` INT) +BEGIN + + -- DEPRECATED use vn.buySplit + + DECLARE v_item INT; + DECLARE v_packing INT; + DECLARE v_remaining INT; + DECLARE v_labels INT; + DECLARE v_remainder INT; + DECLARE v_is_buy INT; + DECLARE v_id INT; + DECLARE v_amount INT; + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vNameCharMax INT DEFAULT 16; + + DECLARE cur CURSOR FOR + SELECT TRUE, c.Id_Compra, c.Cantidad - IFNULL((c.Vida * c.Packing), 0) + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE c.Id_Article = v_item + AND DATE(t.shipment) = util.VN_CURDATE() AND t.warehouse_id_out IN (7, 40) + AND t.warehouse_id NOT IN (60) + AND NOT e.redada AND NOT e.Inventario + AND IFNULL(c.Vida, 0) < c.Etiquetas + UNION ALL + SELECT FALSE, m.Id_Movimiento, m.Cantidad - IFNULL(l.stem, 0) + FROM Movimientos m + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + LEFT JOIN movement_label l ON l.Id_Movimiento = m.Id_Movimiento + WHERE m.Id_Article = v_item + AND t.Fecha >= util.VN_CURDATE() AND t.warehouse_id IN (7, 40) + AND NOT t.Etiquetasemitidas + AND IFNULL(l.stem, 0) < m.Cantidad + LOCK IN SHARE MODE; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + -- Obtiene los datos de la compra + + SELECT Id_Article, Packing, Cantidad + INTO v_item, v_packing, v_remaining + FROM Compres WHERE Id_Compra = v_buy; + + -- Crea splits de los tickets + + DROP TEMPORARY TABLE IF EXISTS tmp.split; + CREATE TEMPORARY TABLE tmp.split + ( + is_buy BOOL, + id INT, + labels INT, + remainder INT + ) + ENGINE = MEMORY; + + OPEN cur; + + l: LOOP + SET v_done = FALSE; + FETCH cur INTO v_is_buy, v_id, v_amount; + + IF v_done OR v_remaining = 0 THEN + LEAVE l; + END IF; + + SET v_amount = LEAST(v_amount, v_remaining); + SET v_remaining = v_remaining - v_amount; + SET v_labels = v_amount DIV v_packing; + + INSERT INTO tmp.split + VALUES (v_is_buy, v_id, v_labels, v_amount % v_packing); + + IF v_is_buy + THEN + UPDATE Compres + SET Vida = Vida + v_labels + WHERE Id_Compra = v_id; + ELSE + INSERT INTO movement_label + SET + Id_Movimiento = v_id, + stem = v_amount, + label = v_labels + ON DUPLICATE KEY UPDATE + stem = stem + VALUES(stem), + label = label + VALUES(label); + END IF; + END LOOP; + + CLOSE cur; + + -- Crea los movimientos de almacén a silla + + CALL buy_transfer (v_buy, v_entry); + + UPDATE Compres SET dispatched = Vida * Packing + WHERE Id_Compra = v_buy; + + -- Devuelve los splits creados + + DROP TEMPORARY TABLE IF EXISTS tmp.aux; + CREATE TEMPORARY TABLE tmp.aux + ENGINE = MEMORY + SELECT s.labels, s.remainder, w.`name` destination, + a.Id_Article, a.Article, a.Medida, ' ' counter, ' ' destination2 + FROM tmp.split s + JOIN Compres c ON c.Id_Compra = s.id + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + JOIN warehouse w ON t.warehouse_id = w.id + WHERE s.is_buy; + + INSERT INTO tmp.aux + SELECT s.labels, s.remainder, IF(p.`name` IN ('BARCELONA','TARRAGONA','GIRONA','LLEIDA','LÉRIDA') AND t.Id_Cliente != 93, '<< VILASSAR >>',o.Consignatario), + a.Id_Article, a.Article, a.Medida, + vn.ticketSplitCounter(t.Id_Ticket), IF(p.`name` IN ('BARCELONA','TARRAGONA','GIRONA','LLEIDA','LÉRIDA') AND t.Id_Cliente != 93, o.Consignatario,CONCAT(o.id_consigna, ' ', p.`name`,' (', c.`code`,')')) + /*UCASE(CONCAT(p.`name`,' (', c.`code`, ')'))*/ + FROM tmp.split s + JOIN Movimientos m ON m.Id_Movimiento = s.id + JOIN Articles a ON a.Id_Article = m.Id_Article + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN Consignatarios o ON o.Id_Consigna = t.Id_Consigna + JOIN vn.province p ON p.id = o.province_id + JOIN vn.country c ON c.id = p.countryFk + WHERE NOT s.is_buy; + + SELECT * FROM tmp.aux; + + -- Limpia y confirma cambios + + DROP TEMPORARY TABLE + tmp.split, + tmp.aux; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_tarifas.sql b/db/routines/vn2008/procedures/buy_tarifas.sql new file mode 100644 index 000000000..c6e8dff90 --- /dev/null +++ b/db/routines/vn2008/procedures/buy_tarifas.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_tarifas`(vBuyFk INT) +BEGIN + CALL vn.buy_recalcPricesByBuy(vBuyFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_tarifas_entry.sql b/db/routines/vn2008/procedures/buy_tarifas_entry.sql new file mode 100644 index 000000000..3fc0739e0 --- /dev/null +++ b/db/routines/vn2008/procedures/buy_tarifas_entry.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_tarifas_entry`(IN vEntryFk INT(11)) +BEGIN +/** + * Recalcula los precios de una entrada + * + * @param vEntryFk + */ + CALL vn.buy_recalcPricesByEntry(vEntryFk); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql b/db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql new file mode 100644 index 000000000..d2248505d --- /dev/null +++ b/db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_tarifas_recalcular_almacen`(IN wh_id INT, IN datFEC DATE) +BEGIN + +DECLARE done INT DEFAULT 0; +DECLARE idE INT; + +DECLARE cur1 CURSOR FOR +SELECT Id_Entrada +FROM Entradas +JOIN travel ON travel.id = travel_id +WHERE landing >= datFEC AND wh_id IN (0,warehouse_id); + +DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; + +OPEN cur1; + +REPEAT + + FETCH cur1 INTO idE; + + IF NOT done THEN + + Call buy_tarifas_entry(idE); + + + + END IF; + + +UNTIL done END REPEAT; + + CLOSE cur1; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_transfer.sql b/db/routines/vn2008/procedures/buy_transfer.sql new file mode 100644 index 000000000..935a570bd --- /dev/null +++ b/db/routines/vn2008/procedures/buy_transfer.sql @@ -0,0 +1,104 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_transfer`(IN `v_buy` INT, IN `entryFk` INT) +proc: BEGIN +/** + * Traslada la cantidad restante de una compra de Holanda + * al almacén de Silla. + */ + DECLARE v_wh INT; + DECLARE v_fv INT; + DECLARE v_amount INT; + DECLARE v_item INT; + DECLARE v_holland_wh INT DEFAULT 7; + DECLARE vIsIgnored BOOL DEFAULT FALSE; + DECLARE vDestinationWarehouse INT; + + -- Comprueba que es mercancía que llega al almacén de Holanda + + SELECT t.warehouse_id, IF(tp.warehouseFk=1,1,0), tp.warehouseFk, c.Id_Article, c.Novincular + INTO v_wh, v_fv, vDestinationWarehouse, v_item, vIsIgnored + FROM Compres c + JOIN Entradas e ON c.Id_Entrada = e.Id_Entrada + JOIN travel t ON t.id = e.travel_id + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + WHERE c.Id_Compra = v_buy; + + IF v_wh != v_holland_wh THEN + LEAVE proc; + END IF; + + IF entryFk IS NULL THEN + LEAVE proc; + END IF; + + -- Calcula la cantidad a trasladar + + SELECT IFNULL(SUM(amount), 0) INTO v_amount + FROM ( + SELECT SUM(c.Cantidad) amount + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE c.Id_Article = v_item + AND t.landing = util.VN_CURDATE() + AND t.warehouse_id = v_holland_wh + UNION ALL + SELECT -SUM(c.Cantidad) + FROM Compres c + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE c.Id_Article = v_item + AND t.shipment = util.VN_CURDATE() + AND t.warehouse_id_out = v_holland_wh + UNION ALL + SELECT -SUM(Cantidad) + FROM Movimientos m + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE m.Id_Article = v_item + AND t.Fecha = util.VN_CURDATE() + AND t.warehouse_id = v_holland_wh + ) t; + + IF v_amount <= 0 THEN + LEAVE proc; + END IF; + + -- Si la linea tiene no vincular hay que buscar la anterior válida + IF vIsIgnored THEN + CALL buyUltimate(vDestinationWarehouse, util.VN_CURDATE()); + SELECT buyFk INTO v_buy + FROM tmp.buyUltimate + LIMIT 1; + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; + END IF; + + -- Crea la nueva línea de compra con el translado + + INSERT INTO Compres ( + Id_Article, Etiquetas, Cantidad, Id_Entrada, + Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, + Embalajefijo, Comisionfija, buy_edi_id) + SELECT c.Id_Article, + v_amount DIV c.Packing, + v_amount, + entryFk, + c.Id_Cubo, + c.Packing, + c.`grouping`, + c.caja, + @cost := IFNULL(c.Costefijo, 0) + IFNULL(c.Comisionfija, 0) + IFNULL(c.Portefijo, 0), + @porte := ROUND((@cm3:= vn.item_getVolume(c.Id_Article, c.Id_Cubo)) * a.m3 / 1000000 / c.Packing, 3), + c.EmbalajeFijo, + @comision := ROUND(c.Costefijo * e.comision / 100, 3), + c.buy_edi_id + FROM Compres c + JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo + JOIN Entradas e ON e.Id_Entrada = entryFk + JOIN travel t ON t.id = e.travel_id + JOIN Agencias a ON t.agency_id = a.Id_Agencia + WHERE c.Id_Compra = v_buy; + + CALL buy_tarifas (LAST_INSERT_ID()); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/cacheReset.sql b/db/routines/vn2008/procedures/cacheReset.sql new file mode 100644 index 000000000..f36169fda --- /dev/null +++ b/db/routines/vn2008/procedures/cacheReset.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`cacheReset`(vCacheName VARCHAR(10), vParams VARCHAR(15)) +BEGIN + + UPDATE cache.cache_calc + SET expires = util.VN_NOW() + WHERE cacheName = vCacheName collate utf8_unicode_ci + AND params = vParams collate utf8_unicode_ci; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/camiones.sql b/db/routines/vn2008/procedures/camiones.sql new file mode 100644 index 000000000..4c37cf9da --- /dev/null +++ b/db/routines/vn2008/procedures/camiones.sql @@ -0,0 +1,23 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`camiones`(vWarehouse INT, vDate DATE) +BEGIN + SELECT Temperatura + ,ROUND(SUM(Etiquetas * volume)) AS cm3 + ,ROUND(SUM(IF(scanned, Etiquetas, 0) * volume)) AS cm3s + ,ROUND(SUM(Vida * volume)) AS cm3e + FROM ( + SELECT t.Temperatura, c.Etiquetas, b.scanned, c.Vida, + IF(cu.Volumen > 0, cu.Volumen, cu.x * cu.y * IF(cu.z > 0, cu.z, a.Medida + 10)) volume + FROM Compres c + LEFT JOIN buy_edi b ON b.id = c.buy_edi_id + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos t ON t.tipo_id = a.tipo_id + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel tr ON tr.id = e.travel_id + JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo + WHERE tr.warehouse_id = vWarehouse + AND tr.landing = vDate + ) sub + GROUP BY Temperatura; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/check_table_existence.sql b/db/routines/vn2008/procedures/check_table_existence.sql new file mode 100644 index 000000000..081912d3b --- /dev/null +++ b/db/routines/vn2008/procedures/check_table_existence.sql @@ -0,0 +1,16 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`check_table_existence`(IN table_name CHAR(64)) +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' SET @err = 1; + SET @err = 0; + SET @table_name = table_name; + SET @sqlString = CONCAT('SELECT NULL FROM ',@table_name); + PREPARE stmt1 FROM @sqlString; + IF (@err = 1) THEN + SET @table_exists = 0; + ELSE + SET @table_exists = 1; + DEALLOCATE PREPARE stmt1; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/clean.sql b/db/routines/vn2008/procedures/clean.sql new file mode 100644 index 000000000..e2f3c9544 --- /dev/null +++ b/db/routines/vn2008/procedures/clean.sql @@ -0,0 +1,95 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`clean`(IN `v_full` TINYINT(1)) +proc: BEGIN + DECLARE vDate DATETIME; + DECLARE vDate18 DATETIME; + DECLARE vDate26 DATETIME; + DECLARE vDate8 DATE; + DECLARE vDate6 DATE; + DECLARE vDate3 DATE; + DECLARE vDate2000 DATE; + DECLARE vRangeDeleteTicket INT; + DECLARE vStrtable VARCHAR(15) DEFAULT NULL; + + SET vDate = util.VN_CURDATE() - INTERVAL 2 MONTH; + SET vDate18 = util.VN_CURDATE() - INTERVAL 18 MONTH; + SET vDate26 = util.VN_CURDATE() - INTERVAL 26 MONTH; + SET vDate3 = util.VN_CURDATE() - INTERVAL 3 MONTH; + SET vDate8 = util.VN_CURDATE() - INTERVAL 8 DAY; + SET vDate6 = util.VN_CURDATE() - INTERVAL 6 DAY; + SET vDate2000 = util.VN_CURDATE() + INTERVAL (2000 - YEAR(util.VN_CURDATE())) YEAR; + SET vRangeDeleteTicket = 60; + + DELETE FROM Rutas_monitor WHERE fecha < vDate; + DELETE FROM cdr WHERE calldate < vDate18; + DELETE FROM Monitoring WHERE ODBC_TIME < vDate; + DELETE FROM Conteo WHERE Fecha < vDate; + DELETE FROM XDiario WHERE FECHA < vDate3 OR FECHA IS NULL; + DELETE FROM mail WHERE DATE_ODBC < vDate; + DELETE FROM expeditions_deleted WHERE odbc_date < vDate26; + DELETE FROM sms WHERE DATE_ODBC < vDate18; + DELETE FROM Movimientos_mark WHERE odbc_date < vDate; + DELETE FROM Splits WHERE Fecha < vDate18; + + DELETE ts + FROM Tickets_stack ts + JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket + WHERE t.Fecha < vDate; + + DELETE tobs + FROM ticket_observation tobs + JOIN Tickets t ON tobs.Id_Ticket = t.Id_Ticket + WHERE t.Fecha < vDate; + + DELETE tobs + FROM movement_label tobs + JOIN Movimientos m ON tobs.Id_Movimiento = m.Id_Movimiento + JOIN Tickets t ON m.Id_Ticket = t.Id_Ticket WHERE t.Fecha < vDate; + + DELETE FROM Remesas WHERE `Fecha Remesa` < vDate18; + DELETE FROM sharingcart where datEND < vDate; + DELETE FROM sharingclient where datEND < vDate; + + DELETE tt.* + FROM Tickets_turno tt + LEFT JOIN Movimientos m USING(Id_Ticket) + WHERE m.Id_Article IS NULL; + + DELETE FROM cl_main WHERE Fecha < vDate18; + DELETE FROM hedera.`order` WHERE date_send < vDate18; + DELETE FROM vn.message WHERE sendDate < vDate; + DELETE FROM travel_reserve WHERE odbc_date < vDate; + + DELETE FROM cache.departure_limit WHERE Fecha < util.VN_CURDATE() - INTERVAL 1 MONTH; + + DELETE cm + FROM Compres_mark cm + JOIN Compres c ON c.Id_Compra = cm.Id_Compra + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE t.landing <= vDate; + + DELETE co + FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra + JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE t.landing <= vDate; + DELETE FROM scan WHERE odbc_date < vDate6 AND id <> 1; + + IF v_full THEN + DELETE t + FROM Tickets t + LEFT JOIN Tickets_turno tt ON tt.Id_Ticket = t.Id_Ticket + WHERE Fecha NOT IN ('2000-01-01','2000-01-02') + AND YEAR(Fecha) = 2000 + AND ABS(DATEDIFF(Fecha,vDate2000)) > vRangeDeleteTicket + AND tt.Id_Ticket IS NULL; + END IF; + + -- Tickets Nulos PAK 11/10/2016 + UPDATE Tickets + SET empresa_id = 965 + WHERE Id_Cliente = 31 + AND empresa_id != 965; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/clean_launcher.sql b/db/routines/vn2008/procedures/clean_launcher.sql new file mode 100644 index 000000000..63c23e8cf --- /dev/null +++ b/db/routines/vn2008/procedures/clean_launcher.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`clean_launcher`() +BEGIN + CALL clean(TRUE); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/cobro.sql b/db/routines/vn2008/procedures/cobro.sql new file mode 100644 index 000000000..fb6010f38 --- /dev/null +++ b/db/routines/vn2008/procedures/cobro.sql @@ -0,0 +1,79 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`cobro`(IN datFEC DATE + , IN idCLI INT + , IN dblIMPORTE DOUBLE + , IN idCAJA INT + , IN idPAYMET INT + , IN strCONCEPTO VARCHAR(40) + , IN idEMP INT + , IN idWH INT + , IN idTRABAJADOR INT) +BEGIN + + DECLARE bolCASH BOOLEAN; + DECLARE cuenta_banco BIGINT; + DECLARE cuenta_cliente BIGINT; + DECLARE max_asien INT; + -- XDIARIO + -- No se asientan los cobros directamente, salvo en el caso de las cajas de CASH + SELECT (at2.code = 'cash') INTO bolCASH FROM Bancos b JOIN vn.accountingType at2 ON at2.id = b.cash WHERE b.Id_Banco = idCAJA; + IF bolCASH THEN + SELECT Cuenta INTO cuenta_banco + FROM Bancos + WHERE Id_Banco = idCAJA; + SELECT Cuenta INTO cuenta_cliente + FROM Clientes + WHERE Id_Cliente = idCLI; + CALL vn.ledger_next(max_asien); + INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id) + SELECT max_asien,datFEC,SUBCTA,CONTRA,strCONCEPTO,EURODEBE,EUROHABER,idEMP + FROM(SELECT cuenta_banco SUBCTA, cuenta_cliente CONTRA, 0 EURODEBE, dblIMPORTE EUROHABER + UNION ALL + SELECT cuenta_cliente SUBCTA, cuenta_banco CONTRA, dblIMPORTE EURODEBE, 0 EUROHABER + ) gf; + END IF; + + -- CAJERA + INSERT INTO Cajas(Id_Trabajador, + Id_Banco, + Entrada, + Concepto, + Cajafecha, + Serie, + Partida, + Numero, + empresa_id, + warehouse_id + ) + VALUES (idTRABAJADOR, + idCAJA, + dblIMPORTE, + strCONCEPTO, + datFEC, + 'A', + TRUE, + idCLI, + idEMP, + idWH + ); + + -- RECIBO + INSERT INTO Recibos(Entregado, + Fechacobro, + Id_Trabajador, + Id_Banco, + Id_Cliente, + Id_Factura, + empresa_id + ) + VALUES ( dblIMPORTE, + datFEC, + idTRABAJADOR, + idCAJA, + idCLI, + strCONCEPTO, + idEMP + ); + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/comercial_caducado.sql b/db/routines/vn2008/procedures/comercial_caducado.sql new file mode 100644 index 000000000..47b0d6249 --- /dev/null +++ b/db/routines/vn2008/procedures/comercial_caducado.sql @@ -0,0 +1,57 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`comercial_caducado`() +BEGIN + +-- Este procedimiento le pasa los clientes al jefe de ventas cuando llevan dos meses inactivos + +IF day(util.VN_CURDATE()) = 5 then -- solo se ejecuta los dias 5 de cada mes + + Update Clientes + join + ( + Select c.Id_Cliente + from Clientes c + join jerarquia j on j.worker_id = c.Id_Trabajador -- este filtro es para que solo toque los de los comerciales + + join + ( + select Id_Cliente, sum(Importe) as Saldo + from + ( + select Id_Cliente, Importe from Facturas + union all + select Id_Cliente, - Entregado from Recibos + ) sub + group by Id_Cliente + ) sindeuda on sindeuda.Id_Cliente = c.Id_Cliente + + left join + ( + select distinct Id_Cliente + from Facturas + where Fecha BETWEEN util.VN_CURDATE() - INTERVAL 12 MONTH AND util.VN_CURDATE() + ) f on f.Id_Cliente = c.Id_Cliente + + left join + ( + select distinct Id_Cliente + from Tickets + where Fecha between util.VN_CURDATE() - INTERVAL 2 DAY AND util.VN_CURDATE() + INTERVAL 200 DAY + + ) tic_vivos on tic_vivos.Id_Cliente = c.Id_Cliente + + where c.Created < util.VN_CURDATE() - INTERVAL 2 MONTH -- este filtro respeta a los recien nacidos.... + and j.boss_id = 87 -- sólo afecta a los comerciales de Alfredo + and f.Id_Cliente is null -- comprueba que no tenga facturas en los dos ultimos meses + and sindeuda.Saldo < 10 -- sólo cambia a los clientes con deuda escasa o nula + and tic_vivos.Id_Cliente is null -- si tiene tickets vivos, lo respeta + + + ) sub using(Id_Cliente) + + set Id_Trabajador = 87 ;-- Alfredo Giner; + +end if; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql b/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql new file mode 100644 index 000000000..107bb59af --- /dev/null +++ b/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`compresTriggerBeforeInsert`(newNoVincular INT, newEntrada INT, newCompra INT, newItem INT) +BEGIN + DECLARE newWarehouse INTEGER; + + IF newNoVincular = FALSE THEN + + UPDATE travel t + JOIN vn.lastBuy lb ON newItem = lb.item AND t.warehouse_id = lb.warehouse + JOIN Entradas e ON e.travel_id = t.id + SET lb.id = newCompra + WHERE e.Id_Entrada = newEntrada AND t.landing > lb.landing AND t.landing <= util.VN_CURDATE(); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql b/db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql new file mode 100644 index 000000000..e420dc0ab --- /dev/null +++ b/db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql @@ -0,0 +1,36 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`compresTriggerBeforeUpdate`(vOldEntrada INT, vNewEntrada INT, oldItem INT, + newItem INT, newNoVincular BOOLEAN, newCompra INT) +BEGIN + DECLARE newWarehouse INTEGER; + DECLARE hasToRecalculate BOOLEAN; + + IF newNoVincular = FALSE THEN + IF oldItem <> newItem OR vOldEntrada <> vNewEntrada THEN + SELECT Id_Compra INTO hasToRecalculate FROM travel t + JOIN Entradas e ON e.travel_id = t.id + JOIN vn.lastBuy lb ON lb.id = newCompra + WHERE e.Id_Entrada = vOldEntrada LIMIT 1; + + IF hasToRecalculate THEN + SELECT warehouse_id INTO newWarehouse FROM travel t + JOIN Entradas e ON t.id = e.travel_id + WHERE e.Id_Entrada = vOldEntrada; + CALL vn.lastBuyRefresh(newWarehouse); + END IF; + END IF; + IF vOldEntrada <> vNewEntrada THEN + + UPDATE Entradas oldEntrada + JOIN travel oldTravel ON oldEntrada.travel_id = oldtravel.id + JOIN Entradas newEntrada ON newEntrada.Id_Entrada = vNewEntrada + JOIN travel newTravel ON newTravel.id = newEntrada.travel_id + JOIN vn.lastBuy lb ON newItem = lb.item AND newTravel.warehouse_id = lb.warehouse + SET lb.id = newCompra + WHERE oldEntrada.Id_Entrada = vOldEntrada AND oldTravel.warehouse_id <> newTravel.warehouse_id + AND newTravel.landing > lb.landing AND newTravel.landing <= util.VN_CURDATE(); + END IF; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/confection_control_source.sql b/db/routines/vn2008/procedures/confection_control_source.sql new file mode 100644 index 000000000..f439e80f7 --- /dev/null +++ b/db/routines/vn2008/procedures/confection_control_source.sql @@ -0,0 +1,105 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`confection_control_source`(vDated DATE, vScopeDays TINYINT) +BEGIN + + DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(vDated,'23:59:59'); + DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight); + DECLARE maxAlertLevel INT DEFAULT 2; + + DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer; + + CREATE TEMPORARY TABLE tmp.production_buffer + ENGINE = MEMORY + SELECT + date(t.Fecha) as Fecha, + hour(t.Fecha) as Hora, + hour(t.Fecha) as Departure, + t.Id_Ticket, + m.Id_Movimiento, + m.Cantidad, + m.Concepte, + ABS(m.Reservado) Reservado, + i.Categoria, + tp.Tipo, + t.Alias as Cliente, + wh.name as Almacen, + t.warehouse_id, + cs.province_id, + a.agency_id, + ct.description as Taller, + stock.visible, + stock.available + FROM vn2008.Tickets t + JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia + JOIN vn2008.warehouse wh ON wh.id = t.warehouse_id + JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket + JOIN vn2008.Articles i ON i.Id_Article = m.Id_Article + JOIN vn2008.Tipos tp ON tp.tipo_id = i.tipo_id + JOIN vn.confectionType ct ON ct.id = tp.confeccion + JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna + LEFT JOIN vn.ticketState tls on tls.ticketFk = t.Id_Ticket + LEFT JOIN + ( + SELECT item_id, sum(visible) visible, sum(available) available + FROM + ( + SELECT a.item_id, 0 as visible, a.available + FROM cache.cache_calc cc + LEFT JOIN cache.available a ON a.calc_id = cc.id + WHERE cc.cache_id IN (2,8) + AND cc.params IN (concat("1/", util.VN_CURDATE()),concat("44/", util.VN_CURDATE())) + + UNION ALL + + SELECT v.item_id, v.visible, 0 as available + FROM cache.cache_calc cc + LEFT JOIN cache.visible v ON v.calc_id = cc.id + where cc.cache_id IN (2,8) and cc.params IN ("1","44") + ) sub + GROUP BY item_id + ) stock ON stock.item_id = m.Id_Article + WHERE tp.confeccion + AND tls.alertLevel < maxAlertLevel + AND wh.hasConfectionTeam + AND t.Fecha BETWEEN vDated AND vEndingDate + AND m.Cantidad > 0; + + -- Entradas + + INSERT INTO tmp.production_buffer( + Fecha, + Id_Ticket, + Cantidad, + Concepte, + Categoria, + Cliente, + Almacen, + Taller + ) + SELECT + tr.shipment AS Fecha, + e.Id_Entrada AS Id_Ticket, + c.Cantidad, + a.Article, + a.Categoria, + whi.name as Cliente, + who.name as Almacen, + ct.description as Taller + FROM vn2008.Compres c + JOIN vn2008.Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN vn2008.travel tr ON tr.id = e.travel_id + JOIN vn2008.warehouse whi ON whi.id = tr.warehouse_id + JOIN vn2008.warehouse who ON who.id = tr.warehouse_id_out + JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article + JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id + JOIN vn.confectionType ct ON ct.id = tp.confeccion + WHERE who.hasConfectionTeam + AND tp.confeccion + AND tr.shipment BETWEEN vDated AND vEndingDate; + + + SELECT * FROM tmp.production_buffer; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/createBouquet.sql b/db/routines/vn2008/procedures/createBouquet.sql new file mode 100644 index 000000000..2796ce9aa --- /dev/null +++ b/db/routines/vn2008/procedures/createBouquet.sql @@ -0,0 +1,50 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`createBouquet`( + vName VARCHAR(50), + vType int, + vSize int, + vColour VARCHAR(5), + OUT vItem INT(11) +) +BEGIN + + DECLARE vTaxClass VARCHAR(1); + DECLARE vIntrastatFk INT(11); + + -- COMPROBAMOS SI EXISTE UN ARTÍCULO IGUAL. + SELECT Id_Article INTO vItem + FROM Articles + WHERE (Id_Article BETWEEN 161000 AND 169000) + AND Article LIKE CONCAT('%', vName) + AND tipo_id = vType + AND Medida = vSize + AND Color = vColour + LIMIT 1; + + -- SI NO EXISTE CREAMOS UNO NUEVO + IF vItem IS NULL THEN + + -- OBTENER EL ID ENTRE 161000 Y 169000 DEL SIGUIENTE ARTÍCULO + SELECT (IF(MAX(Id_Article) IS NULL, 161000, (MAX(Id_Article) + 1))) INTO vItem FROM Articles WHERE Id_Article BETWEEN 161000 AND 169000; + + -- INSERTAR EL ARTÍCULO + INSERT INTO vn.item (id, `name`, typeFk, size, inkFk, originFk, intrastatFk) + VALUES ( + vItem, + vName, + vType, + vSize, + vColour, + 1, + 06031970 + ); + + SELECT id INTO vTaxClass FROM vn.taxClass WHERE `code` = 'G'; + SELECT id INTO vIntrastatFk FROM vn.intrastat + WHERE description LIKE 'Flores,follaje y frutos artificiales: otras%'; + + UPDATE vn.itemTaxCountry SET taxClassFk = vTaxClass WHERE itemFk = LAST_INSERT_ID(); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/credit_update.sql b/db/routines/vn2008/procedures/credit_update.sql new file mode 100644 index 000000000..e29fa5ada --- /dev/null +++ b/db/routines/vn2008/procedures/credit_update.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`credit_update`() +BEGIN + +DECLARE dblDiferencia DOUBLE DEFAULT 10.0; +DECLARE dblImporteRec,auxdblImporteRec DOUBLE DEFAULT 0.0; +DECLARE dblImporteFac,auxdblImporteFac DOUBLE DEFAULT 0.0; +DECLARE intIdRecibo,auxintIdRecibo INT (11) DEFAULT 0; +DECLARE intId_Cliente,auxintId_Cliente,intId_ClienteRec,auxintId_ClienteRec INT DEFAULT 0; +DECLARE bitFin,bitFinRecord,bitFinRecord1 BIT DEFAULT 0; +DECLARE datFechaVencimiento DATE DEFAULT util.VN_CURDATE(); +DECLARE intEmpresa_id INT DEFAULT 0; + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/customerDebtEvolution.sql b/db/routines/vn2008/procedures/customerDebtEvolution.sql new file mode 100644 index 000000000..e5d23f0ef --- /dev/null +++ b/db/routines/vn2008/procedures/customerDebtEvolution.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`customerDebtEvolution`(IN vCustomer INT) +BEGIN + +SELECT * FROM +( + SELECT day, date, @s:= round(IFNULL(Euros,0) + @s,2) as Saldo, Euros, Credito, 0 as Cero + FROM + ( + SELECT day, date, IFNULL(Euros,0) as Euros, Credito + FROM time + JOIN (SELECT @s:= 0, - Credito as Credito FROM Clientes WHERE Id_Cliente = vCustomer) c + LEFT JOIN + (SELECT Euros, date(Fecha) as Fecha FROM + ( + SELECT Fechacobro as Fecha, Entregado as Euros + FROM Recibos + WHERE Id_Cliente = vCustomer + AND Fechacobro >= '2017-01-01' + UNION ALL + SELECT vn.getDueDate(f.Fecha,c.Vencimiento), - Importe + FROM Facturas f + JOIN Clientes c ON f.Id_Cliente = c.Id_Cliente + WHERE f.Id_Cliente = vCustomer + AND Fecha >= '2017-01-01' + UNION ALL + SELECT '2016-12-31', Debt + FROM bi.customerDebtInventory + WHERE Id_Cliente = vCustomer + UNION ALL + SELECT Fecha, - SUM(Cantidad * Preu * (100 - Descuento ) * 1.10 / 100) + FROM Tickets t + JOIN Movimientos m on m.Id_Ticket = t.Id_Ticket + WHERE Id_Cliente = vCustomer + AND Factura IS NULL + AND Fecha >= '2017-01-01' + GROUP BY Fecha + ) sub2 + ORDER BY Fecha + )sub ON time.date = sub.Fecha + WHERE time.date BETWEEN '2016-12-31' AND util.VN_CURDATE() + ORDER BY date + ) sub3 +)sub4 +; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/desglose_volume.sql b/db/routines/vn2008/procedures/desglose_volume.sql new file mode 100644 index 000000000..3fcad4b71 --- /dev/null +++ b/db/routines/vn2008/procedures/desglose_volume.sql @@ -0,0 +1,82 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`desglose_volume`(IN vAgencyFk INT) +BEGIN + + DECLARE vStarted DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE()); + DECLARE vEnded DATETIME DEFAULT TIMESTAMP(util.VN_CURDATE(), '23:59:59'); + DECLARE vIsHolland BOOL; + + SELECT (wa.name = 'Holanda') INTO vIsHolland + FROM vn.agency a + JOIN vn.warehouseAlias wa ON wa.id = a.warehouseAliasFk + WHERE a.id = vAgencyFk; + + IF vIsHolland THEN + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_PackagingEstimated; + CREATE TEMPORARY TABLE tmp.ticket_PackagingEstimated + ( + ticketFk INT PRIMARY KEY + ,carros DECIMAL(5,1) DEFAULT 0 + ); + + INSERT INTO tmp.ticket_PackagingEstimated(ticketFk, carros) + SELECT sv.ticketFk, ROUND(vc.dutchCompressionRate * sum(sv.volume) / vc.trolleyM3,0) + FROM vn.ticket t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.volumeConfig vc + WHERE t.shipped BETWEEN vStarted AND vEnded + AND am.agencyFk = vAgencyFk + GROUP BY t.id; + + SELECT a.nickname Provincia, + count(*) expediciones, + 0 Bultos, + sum(tpe.carros) Prevision + FROM vn.ticket t + JOIN vn.address a ON a.id = t.addressFk + JOIN tmp.ticket_PackagingEstimated tpe ON tpe.ticketFk = t.id + GROUP BY a.nickname; + + ELSE + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_PackagingEstimated; + CREATE TEMPORARY TABLE tmp.ticket_PackagingEstimated + ( + ticketFk INT PRIMARY KEY + ,boxes INT DEFAULT 0 + ); + + INSERT INTO tmp.ticket_PackagingEstimated(ticketFk, boxes) + SELECT sv.ticketFk, CEIL(1000 * sum(sv.volume) / vc.standardFlowerBox) + FROM vn.ticket t + JOIN vn.saleVolume sv ON sv.ticketFk = t.id + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.volumeConfig vc + WHERE t.shipped BETWEEN vStarted AND vEnded + AND IFNULL(t.packages,0) = 0 + AND am.agencyFk = vAgencyFk + GROUP BY t.id; + + + SELECT p.name Provincia, + count(*) expediciones, + sum(t.packages) Bultos, + sum(tpe.boxes) Prevision + FROM vn.ticket t + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON a.provinceFk = p.id + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN tmp.ticket_PackagingEstimated tpe ON tpe.ticketFk = t.id + WHERE t.warehouseFk = 60 + AND t.shipped BETWEEN vStarted AND vEnded + AND am.agencyFk = vAgencyFk + GROUP BY p.name; + + END IF; + SELECT * FROM tmp.ticket_PackagingEstimated; + DROP TEMPORARY TABLE tmp.ticket_PackagingEstimated; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/emailYesterdayPurchasesByConsigna.sql b/db/routines/vn2008/procedures/emailYesterdayPurchasesByConsigna.sql new file mode 100644 index 000000000..bde90cf7b --- /dev/null +++ b/db/routines/vn2008/procedures/emailYesterdayPurchasesByConsigna.sql @@ -0,0 +1,87 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`emailYesterdayPurchasesByConsigna`(IN v_Date DATE, IN v_Client_Id INT) +BEGIN + + DECLARE MyIdTicket BIGINT; + DECLARE MyAlias VARCHAR(50); + DECLARE MyDomicilio VARCHAR(255); + DECLARE MyPoblacion VARCHAR(25); + DECLARE MyImporte DOUBLE; + DECLARE MyMailTo VARCHAR(250); + DECLARE MyMailReplyTo VARCHAR(250); + DECLARE done INT DEFAULT FALSE; + DECLARE emptyList INT DEFAULT 0; + DECLARE txt TEXT; + + DECLARE rs CURSOR FOR + SELECT t.Id_Ticket, Alias, cast(amount as decimal(10,2)) Importe, Domicilio, POBLACION + FROM Tickets t + JOIN Consignatarios cs ON t.Id_Consigna = cs.Id_Consigna + JOIN v_ticket_amount v ON v.Id_Ticket = t.Id_Ticket + WHERE t.Fecha BETWEEN v_Date AND util.dayEnd(v_Date) + AND t.Id_Cliente = v_Client_Id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + SET v_Date = IFNULL(v_Date, util.yesterday()); + + OPEN rs; + + FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion; + + SET emptyList = done; + + SET txt = CONCAT('

', + '

Relación de envíos.

', + '

Dia: ', v_Date, '

'); + + WHILE NOT done DO + + SET txt = CONCAT(txt, '

', + ' + + + + + + +
+ Ticket ', MyIdTicket,' ', MyImporte, ' €
' + , ' ', MyAlias, '
' + , ' ', MyDomicilio, '(', MyPoblacion, ')'); + + FETCH rs INTO MyIdTicket, MyAlias, MyImporte, MyDomicilio, MyPoblacion; + + END WHILE; + + SET txt = CONCAT( + txt, + '', + '', + '
', + '

Puede acceder al detalle de los albaranes haciendo click sobre el número de Ticket', + '

Muchas gracias por su confianza

', + '

'); + + -- Envío del email + IF emptyList = 0 THEN + + SELECT CONCAT(`e-mail`,',pako@verdnatura.es') INTO MyMailTo + FROM Clientes + WHERE Id_Cliente = v_Client_Id AND `e-mail`>''; + + IF v_Client_Id = 7818 THEN -- LOEWE + SET MyMailTo = 'isabel@elisabethblumen.com,emunozca@loewe.es,pako@verdnatura.es'; + END IF; + + CALL vn.mail_insert( + IFNULL(MyMailTo,'pako.natek@gmail.com'), + 'pako@verdnatura.es', + 'Resumen de pedidos preparados', + txt + ); + + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/emailYesterdayPurchasesLauncher.sql b/db/routines/vn2008/procedures/emailYesterdayPurchasesLauncher.sql new file mode 100644 index 000000000..c414cf1c4 --- /dev/null +++ b/db/routines/vn2008/procedures/emailYesterdayPurchasesLauncher.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`emailYesterdayPurchasesLauncher`() +BEGIN + +DECLARE done INT DEFAULT 0; +DECLARE vMyClientId INT; + +DECLARE rs CURSOR FOR +SELECT Id_Cliente +FROM Clientes +WHERE EYPBC != 0; + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + +OPEN rs; + +FETCH rs INTO vMyClientId; + +WHILE NOT done DO + + CALL emailYesterdayPurchasesByConsigna(util.yesterday(), vMyClientId); + + FETCH rs INTO vMyClientId; + +END WHILE; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/embalajes_stocks.sql b/db/routines/vn2008/procedures/embalajes_stocks.sql new file mode 100644 index 000000000..b20e44c79 --- /dev/null +++ b/db/routines/vn2008/procedures/embalajes_stocks.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`embalajes_stocks`(IN idPEOPLE INT, IN bolCLIENT BOOLEAN) +BEGIN + +if bolCLIENT then + + select m.Id_Article, Article, - cast(sum(m.Cantidad) as decimal) as Saldo + from Movimientos m + join Articles a on m.Id_Article = a.Id_Article + join Tipos tp on tp.tipo_id = a.tipo_id + join Tickets t using(Id_Ticket) + join Consignatarios cs using(Id_Consigna) + where cs.Id_Cliente = idPEOPLE + and Tipo = 'Contenedores' + and t.Fecha > '2010-01-01' + group by m.Id_Article; + +else + +select Id_Article, Article, sum(Cantidad) as Saldo +from +(select Id_Article, Cantidad +from Compres c +join Articles a using(Id_Article) +join Tipos tp using(tipo_id) +join Entradas e using(Id_Entrada) +join travel tr on tr.id = travel_id +where Id_Proveedor = idPEOPLE +and landing >= '2010-01-01' +and reino_id = 6 + +union all + +select Id_Article, - Cantidad +from Movimientos m +join Articles a using(Id_Article) +join Tipos tp using(tipo_id) +join Tickets t using(Id_Ticket) +join Consignatarios cs using(Id_Consigna) +join proveedores_clientes pc on pc.Id_Cliente = cs.Id_Cliente +where Id_Proveedor = idPEOPLE +and reino_id = 6 +and t.Fecha > '2010-01-01') mov + +join Articles a using(Id_Article) +group by Id_Article; + +end if; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/embalajes_stocks_detalle.sql b/db/routines/vn2008/procedures/embalajes_stocks_detalle.sql new file mode 100644 index 000000000..c49d1b88a --- /dev/null +++ b/db/routines/vn2008/procedures/embalajes_stocks_detalle.sql @@ -0,0 +1,78 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`embalajes_stocks_detalle`(IN idPEOPLE INT, IN idARTICLE INT, IN bolCLIENT BOOLEAN) +BEGIN + + +if bolCLIENT then + + select m.Id_Article + , Article + , IF(Cantidad < 0, - Cantidad, NULL) as Entrada + , IF(Cantidad < 0, NULL, Cantidad) as Salida + , 'T' as Tabla + , t.Id_Ticket as Registro + , t.Fecha + , w.name as Almacen + , cast(Preu as Decimal(5,2)) Precio + , c.Cliente as Proveedor + , abbreviation as Empresa + from Movimientos m + join Articles a using(Id_Article) + join Tickets t using(Id_Ticket) + join empresa e on e.id = t.empresa_id + join warehouse w on w.id = t.warehouse_id + join Consignatarios cs using(Id_Consigna) + join Clientes c on c.Id_Cliente = cs.Id_Cliente + where cs.Id_Cliente = idPEOPLE + and m.Id_Article = idARTICLE + and t.Fecha > '2010-01-01'; + +else + +select Id_Article, Tabla, Registro, Fecha, Article +, w.name as Almacen, Entrada, Salida, Proveedor, cast(Precio as Decimal(5,2)) Precio + +from + +(select Id_Article + , IF(Cantidad > 0, Cantidad, NULL) as Entrada + , IF(Cantidad > 0, NULL,- Cantidad) as Salida + , 'E' as Tabla + , Id_Entrada as Registro + , landing as Fecha + , tr.warehouse_id + , Costefijo as Precio +from Compres c +join Entradas e using(Id_Entrada) +join travel tr on tr.id = travel_id +where Id_Proveedor = idPEOPLE +and Id_Article = idARTICLE +and landing >= '2010-01-01' + +union all + +select Id_Article + , IF(Cantidad < 0, - Cantidad, NULL) as Entrada + , IF(Cantidad < 0, NULL, Cantidad) as Salida + , 'T' + , Id_Ticket + , Fecha + , t.warehouse_id + , Preu +from Movimientos m +join Tickets t using(Id_Ticket) +join Consignatarios cs using(Id_Consigna) +join proveedores_clientes pc on pc.Id_Cliente = cs.Id_Cliente +where Id_Proveedor = idPEOPLE +and Id_Article = idARTICLE +and t.Fecha > '2010-01-01') mov + +join Articles a using(Id_Article) +join Proveedores p on Id_Proveedor = idPEOPLE +join warehouse w on w.id = mov.warehouse_id +; + +end if; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/entryFromOrder.sql b/db/routines/vn2008/procedures/entryFromOrder.sql new file mode 100644 index 000000000..e340177af --- /dev/null +++ b/db/routines/vn2008/procedures/entryFromOrder.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`entryFromOrder`(IN vShipmentWarehouse INTEGER, IN vLandingWarehouse INTEGER, IN vItem INTEGER, + IN vAmount INTEGER,IN vVolume INTEGER,vCost DECIMAL(10,2), IN vRetailedPrice DECIMAL(10,2), vInOutDate DATE) +BEGIN + + DECLARE vTravel INT; + DECLARE vEntry INT; + DECLARE vBucket VARCHAR(10); + + -- seleccionamos travel + SELECT id, Id_Entrada INTO vTravel, vEntry + FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id + WHERE t.landing = vInOutDate AND t.shipment = vInOutDate AND t.warehouse_id_out = vShipmentWarehouse + AND t.warehouse_id = vLandingWarehouse AND agency_id = 15 + LIMIT 1; + + -- creamos el travel si es necesario + IF NOT IFNULL(vTravel,0) THEN + INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) + VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse, 15); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + -- creamos la Entrada si es necesario + IF NOT IFNULL(vEntry,0) THEN + INSERT INTO Entradas (Id_Proveedor, travel_id) + VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' + SELECT LAST_INSERT_ID() INTO vEntry; + END IF; + + -- creamos el cubo si es necesario + SELECT Id_Cubo INTO vBucket FROM Cubos WHERE Volumen = vVolume LIMIT 1; + + IF NOT IFNULL(vBucket,'') > '' THEN + INSERT INTO Cubos (Id_Cubo, Volumen) + VALUES (CONCAT('dm',vVolume/1000), vVolume); + SELECT LAST_INSERT_ID() INTO vBucket; + END IF; + + INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, Embalajefijo, + Comisionfija, Tarifa2, Tarifa3) + VALUES(vItem, + vAmount, + vEntry, + vBucket, + 1, + 1, + 0, + vCost, + 0, + 0, + 0, + vRetailedPrice, + vRetailedPrice); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/entryFromTicket.sql b/db/routines/vn2008/procedures/entryFromTicket.sql new file mode 100644 index 000000000..f580959d7 --- /dev/null +++ b/db/routines/vn2008/procedures/entryFromTicket.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`entryFromTicket`(IN vTicket INTEGER, IN vLandingWarehouse INTEGER) +BEGIN + + DECLARE vShipmentWarehouse INT; + DECLARE vLandingDate DATE; + DECLARE vShipmentDate DATE; + DECLARE vTravel INT; + DECLARE vEntry INT; + + SELECT warehouse_id, Fecha, Fecha INTO vShipmentWarehouse, vShipmentDate, vLandingDate + FROM Tickets + WHERE Id_Ticket = vTicket; + + -- seleccionamos travel + SELECT id, Id_Entrada INTO vTravel, vEntry + FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id + WHERE t.landing = vLandingDate + AND t.shipment = vShipmentDate + AND t.warehouse_id_out = vShipmentWarehouse + AND t.warehouse_id = vLandingWarehouse + AND agency_id = 15 + LIMIT 1; + + -- creamos el travel si es necesario + IF vTravel IS NULL THEN + SELECT vLandingDate; + INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) + VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, 15); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + + -- creamos la Entrada si es necesario + IF vEntry IS NULL THEN + INSERT INTO Entradas (Id_Proveedor, travel_id) + VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' + SELECT LAST_INSERT_ID() INTO vEntry; + END IF; + + CALL vn.buyUltimate(vShipmentWarehouse,vShipmentDate); + + INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, Embalajefijo, Comisionfija, Tarifa2, Tarifa3) + SELECT m.Id_Article, + m.Cantidad, + vEntry, + c.Id_Cubo, + c.Packing, + IF(c.`grouping`,c.`grouping`,1), + c.caja, + Costefijo, + c.Portefijo, + c.Embalajefijo, + c.Comisionfija, + m.Preu Tarifa2, + m.Preu Tarifa3 + FROM Movimientos m + JOIN Articles a ON m.Id_Article = a.Id_Article + LEFT JOIN tmp.buyUltimate b ON m.Id_Article = b.itemFk AND b.warehouseFk = vShipmentWarehouse + LEFT JOIN Compres c ON c.Id_Compra = b.buyFk + WHERE m.Id_Ticket = vTicket; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/eti_to_print.sql b/db/routines/vn2008/procedures/eti_to_print.sql new file mode 100644 index 000000000..4185d6a0a --- /dev/null +++ b/db/routines/vn2008/procedures/eti_to_print.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`eti_to_print`(IN idENTRADA INT, IN idPRODUCER INT) +BEGIN + +select Vida as Impresas + ,Etiquetas as bultos + ,Packing + ,Id_Article + ,CONCAT(Article,' ',Medida,' ', Categoria) as Articat + ,p.name as marca + ,Proveedor + ,Id_Entrada + ,Id_Compra +from Compres c +join Entradas e using(Id_Entrada) +join Proveedores using(Id_Proveedor) +join travel tr on tr.id = e.travel_id +join Articles a using(Id_Article) +left join producer p using(producer_id) +where Id_Entrada = idENTRADA + and idPRODUCER in (0,a.producer_id) ; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/f10_no_vincular.sql b/db/routines/vn2008/procedures/f10_no_vincular.sql new file mode 100644 index 000000000..4ec93f68e --- /dev/null +++ b/db/routines/vn2008/procedures/f10_no_vincular.sql @@ -0,0 +1,60 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`f10_no_vincular`(lngEntrada INTEGER) +BEGIN + DECLARE datFecha DATE DEFAULT util.VN_CURDATE(); + +-- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo + DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_; + CREATE TEMPORARY TABLE IF NOT EXISTS f10_no_vincular_ + SELECT c.Id_Entrada,c.Id_Compra,c.Id_Article, c.Novincular, c.Packing, be.pri + FROM Compres c + JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha + LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = c.Id_Entrada + WHERE + ((ek.Id_Entrada IS NOT NULL AND ek.sub IS NULL) + OR (c.Id_Entrada = 9200 AND be.ok <> FALSE) + OR c.Id_Entrada = lngEntrada) AND Id_Article <> 90; + + -- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing; + CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Packing + SELECT * FROM ( + SELECT * FROM f10_no_vincular_ + ORDER BY pri DESC + LIMIT 10000000000000000000) t + GROUP BY Id_Article,Packing + HAVING count(Id_Compra) > 1 AND BIT_OR(Id_Entrada = 9200); + + UPDATE Compres c + JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha + JOIN f10_mismo_Packing f ON f.Id_Article = c.Id_Article AND c.Packing = f.Packing + LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = f.Id_Entrada + SET c.Novincular = IF(c.Id_Compra = f.Id_Compra,0,1) + WHERE + ((ek.Id_Entrada IS NOT NULL AND ek.sub IS NULL) + OR (c.Id_Entrada = 9200 AND be.ok <> FALSE) + OR c.Id_Entrada = lngEntrada); + +-- Modifica el Id_Articulo si hay dos entradas con packing y el mismo Id_Articulo + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo; + CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Articulo + SELECT Id_Article FROM ( + SELECT * FROM ( + SELECT * FROM f10_no_vincular_ + ORDER BY Id_Entrada = 9200 DESC + LIMIT 10000000000000000000) t + GROUP BY Id_Article,Packing ) t + GROUP BY Id_Article HAVING COUNT(*) > 1 AND BIT_OR(Id_Entrada = 9200); + SELECT 4; + UPDATE Compres c + JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha + JOIN f10_mismo_Articulo f ON f.Id_Article = c.Id_Article + LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = c.Id_Entrada + SET c.Id_Article = 90 + WHERE c.Id_Entrada = 9200 AND be.ok <> FALSE; + + DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_; + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing; + DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/historico_absoluto.sql b/db/routines/vn2008/procedures/historico_absoluto.sql new file mode 100644 index 000000000..1a7e1dbfa --- /dev/null +++ b/db/routines/vn2008/procedures/historico_absoluto.sql @@ -0,0 +1,91 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_absoluto`(IN idART INT, IN wh INT, IN datfecha DATETIME) +BEGIN + + DECLARE inv_calculado INT; + DECLARE inv INT; + DECLARE today DATETIME; + DECLARE fecha_inv DATETIME; + + SET today = util.VN_CURDATE(); + + CREATE OR REPLACE TEMPORARY TABLE historico_pasado + SELECT * + FROM ( + SELECT TR.landing Fecha, + C.Cantidad Entrada, + NULL Salida, + (TR.received != FALSE) OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5 + FROM Compres C -- mirar perque no entra en received + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + INNER JOIN Proveedores P USING (Id_Proveedor) + WHERE TR.landing >= '2001-01-01' + AND Id_proveedor <> 4 + AND wh IN (TR.warehouse_id , 0) + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT TR.shipment Fecha, + NULL Entrada, + C.Cantidad Salida, + TR.delivered OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5 + FROM Compres C + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + INNER JOIN Proveedores P USING (Id_Proveedor) + WHERE TR.shipment >= '2001-01-01' + AND wh = TR.warehouse_id_out + AND Id_Proveedor <> 4 + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT T.Fecha Fecha, + NULL Entrada, + M.Cantidad Salida, + (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK, + T.Alias Alias, + T.Factura Referencia, + T.Id_Ticket, + T.PedidoImpreso + FROM Movimientos M + INNER JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente + WHERE T.Fecha >= '2001-01-01' + AND M.Id_Article = idART + AND wh IN (T.warehouse_id , 0) + ) t1 + ORDER BY Fecha, Entrada DESC, OK DESC; + + SELECT sum(Entrada) - sum(Salida) INTO inv_calculado + FROM historico_pasado + WHERE Fecha < datfecha; + + SELECT p1.*, NULL v_virtual + FROM( + SELECT datfecha Fecha, + inv_calculado Entrada, + NULL Salida, + 1 OK, + 'Inventario calculado' Alias, + '' Referencia, 0 id, + 1 F5 + UNION ALL + SELECT * + FROM historico_pasado + WHERE Fecha >= datfecha + ) p1; + + DROP TEMPORARY TABLE historico_pasado; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/historico_joined.sql b/db/routines/vn2008/procedures/historico_joined.sql new file mode 100644 index 000000000..730562de1 --- /dev/null +++ b/db/routines/vn2008/procedures/historico_joined.sql @@ -0,0 +1,88 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_joined`(IN idART INT, IN wh_joined INT, IN v_virtual INT) +BEGIN + DECLARE datFEC DATETIME; + + SELECT Fechainventario INTO datFEC FROM tblContadores; + SET @a = 0; + SELECT DATE(Fecha) Fecha, + Entrada, + Salida, + OK, + Alias, + Referencia, + id, + @a := @a + IFNULL(Entrada,0) - IFNULL(Salida,0) acumulado, + F5, + v_virtual, + CodigoTrabajador + FROM + ( SELECT TR.landing Fecha, + C.Cantidad Entrada, + NULL Salida, + (TR.received != FALSE) OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5, + tra.CodigoTrabajador + FROM Compres C + JOIN Entradas E USING (Id_Entrada) + JOIN travel TR ON TR.id = E.travel_id + JOIN Proveedores P USING (Id_Proveedor) + LEFT JOIN Articles a ON a.Id_Article = C.Id_Article + LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id + LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador + LEFT JOIN warehouse_joined wj ON wj.warehouse_id = TR.warehouse_id + WHERE TR.landing >= datFEC + AND wh_joined IN (wj.warehouse_alias_id , 0) + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT TR.shipment Fecha, + NULL Entrada, + C.Cantidad Salida, + TR.delivered OK, + P.Proveedor Alias, + E.Referencia Referencia, + E.Id_Entrada id, + TR.delivered F5, + tra.CodigoTrabajador + FROM Compres C + JOIN Entradas E USING (Id_Entrada) + JOIN travel TR ON TR.id = E.travel_id + JOIN Proveedores P USING (Id_Proveedor) + LEFT JOIN Articles a ON a.Id_Article = C.Id_Article + LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id + LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador + LEFT JOIN warehouse_joined wj ON wj.warehouse_id = TR.warehouse_id_out + WHERE TR.shipment >= datFEC + AND wh_joined IN (wj.warehouse_alias_id,0) + AND Id_Proveedor <> 4 + AND C.Id_Article = idART + AND E.Inventario = 0 + AND E.Redada = 0 + UNION ALL + SELECT T.Fecha Fecha, + NULL Entrada, + M.Cantidad Salida, + (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK, + T.Alias Alias, + T.Localizacion Referencia, + T.Id_Ticket id, + T.PedidoImpreso EtiquetasEmitidas, + tr.CodigoTrabajador + FROM Movimientos M + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente + LEFT JOIN Trabajadores tr ON tr.Id_Trabajador = C.Id_Trabajador + LEFT JOIN warehouse_joined wj ON wj.warehouse_id = T.warehouse_id + WHERE T.Fecha >= datFEC + AND M.Id_Article = idART + AND wh_joined IN (wj.warehouse_alias_id , 0) + ) AS Historico + ORDER BY Fecha, Entrada DESC, OK DESC; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/historico_multiple.sql b/db/routines/vn2008/procedures/historico_multiple.sql new file mode 100644 index 000000000..ae4045a34 --- /dev/null +++ b/db/routines/vn2008/procedures/historico_multiple.sql @@ -0,0 +1,206 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_multiple`(IN vItemFk INT) +BEGIN + + DECLARE vDateInventory DATETIME; + + SELECT Fechainventario INTO vDateInventory FROM tblContadores; + + SET @a = 0; + + DROP TEMPORARY TABLE IF EXISTS hm1; + + CREATE TEMPORARY TABLE hm1 + SELECT DATE(Fecha) as Fecha, + Entrada, + Salida, + OK, + Referencia, + Historia.id, + + wh, + + `name` as wh_name + + FROM + + ( SELECT TR.landing as Fecha, + C.Cantidad as Entrada, + NULL as Salida, + + IF(warehouse_id = 44, 1, warehouse_id) as wh, + (TR.received != FALSE) as OK, + E.Referencia as Referencia, + E.Id_Entrada as id + + + + FROM Compres C + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + WHERE TR.landing >= vDateInventory + AND C.Id_Article = vItemFk + AND E.Redada = 0 + + AND C.Cantidad <> 0 + + UNION ALL + + SELECT TR.shipment as Fecha, + NULL as Entrada, + C.Cantidad as Salida, + warehouse_id_out as wh, + TR.delivered as OK, + E.Referencia as Referencia, + E.Id_Entrada as id + + FROM Compres C + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + WHERE TR.shipment >= vDateInventory + AND C.Id_Article = vItemFk + + AND E.Redada = 0 + + AND C.Cantidad <> 0 + + UNION ALL + + SELECT T.Fecha as Fecha, + NULL as Entrada, + M.Cantidad as Salida, + warehouse_id as wh, + (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) as OK, + T.Factura as Referencia, + T.Id_Ticket as id + + FROM Movimientos M + INNER JOIN Tickets T USING (Id_Ticket) + WHERE T.Fecha >= vDateInventory + AND M.Id_Article = vItemFk + + ) AS Historia + + INNER JOIN warehouse ON warehouse.id = Historia.wh + ORDER BY Fecha, Entrada DESC, OK DESC; + + + DROP TEMPORARY TABLE IF EXISTS hm2; + DROP TEMPORARY TABLE IF EXISTS hm3; + DROP TEMPORARY TABLE IF EXISTS hm4; + DROP TEMPORARY TABLE IF EXISTS hm5; + DROP TEMPORARY TABLE IF EXISTS hm6; + DROP TEMPORARY TABLE IF EXISTS hm7; + DROP TEMPORARY TABLE IF EXISTS hm8; + CREATE TEMPORARY TABLE hm2 SELECT * FROM hm1 WHERE wh = 19; + CREATE TEMPORARY TABLE hm3 SELECT * FROM hm1 WHERE wh = 7; + CREATE TEMPORARY TABLE hm4 SELECT * FROM hm1 WHERE wh = 60; + CREATE TEMPORARY TABLE hm5 SELECT * FROM hm1 WHERE wh = 5; + CREATE TEMPORARY TABLE hm6 SELECT * FROM hm1 WHERE wh = 17; + CREATE TEMPORARY TABLE hm7 SELECT * FROM hm1 WHERE wh = 37; + CREATE TEMPORARY TABLE hm8 SELECT * FROM hm1 WHERE wh = 55; + + SELECT * FROM + + ( + + SELECT Fecha, Entrada as BOGEntrada, Salida as BOGSalida, OK as BOGOK, Referencia as BOGReferencia, id as BOGid, + + NULL AS VNHEntrada, NULL AS VNHSalida, NULL AS VNHOK, NULL AS VNHReferencia, NULL AS VNHid, + + NULL AS ALGEntrada, NULL AS ALGSalida, NULL AS ALGOK, NULL AS ALGReferencia, NULL AS ALGid, + + NULL AS MADEntrada, NULL AS MADSalida, NULL AS MADOK, NULL AS MADReferencia, NULL AS MADid, + + NULL AS MCFEntrada, NULL AS MCFSalida, NULL AS MCFOK, NULL AS MCFReferencia, NULL AS MCFid, + + NULL AS VILEntrada, NULL AS VILSalida, NULL AS VILOK, NULL AS VILReferencia, NULL AS VILid, + + NULL AS BAREntrada, NULL AS BARSalida, NULL AS BAROK, NULL AS BARReferencia, NULL AS BARid + + FROM hm2 + + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + ,Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm3 + + + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm4 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm5 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + FROM hm6 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + , NULL, NULL, NULL, NULL, NULL + + + FROM hm7 + + UNION ALL + + SELECT Fecha + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , NULL, NULL, NULL, NULL, NULL + , Entrada, Salida, OK, Referencia, id + + FROM hm8 + + ) sub + + ORDER BY Fecha, BOGEntrada IS NULL, VNHEntrada IS NULL, ALGEntrada IS NULL, MADEntrada IS NULL, MCFEntrada IS NULL, VILEntrada IS NULL, BAREntrada IS NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/inventario_valorado.sql b/db/routines/vn2008/procedures/inventario_valorado.sql new file mode 100644 index 000000000..e8e5eeed0 --- /dev/null +++ b/db/routines/vn2008/procedures/inventario_valorado.sql @@ -0,0 +1,185 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`inventario_valorado`(IN vDated DATE, IN vIsDetailed BOOLEAN) +BEGIN + +/** + * DEPRECATED usar item_ValuateInventory + */ + DECLARE vInventoried DATE; + DECLARE vHasNotInventory BOOLEAN DEFAULT 0; + DECLARE vInventoried2 DATE; + DECLARE vDateDayEnd DATETIME; + + SET vDateDayEnd = util.dayEnd(vDated); + SELECT landing INTO vInventoried + FROM travel tr + JOIN Entradas E ON E.travel_id = tr.id + WHERE landing <= vDateDayEnd + AND E.Id_Proveedor = 4 + ORDER BY landing DESC + LIMIT 1; + + SET vHasNotInventory = IF (vInventoried is null, TRUE, FALSE); + + IF vHasNotInventory THEN + + SELECT landing INTO vInventoried2 + FROM travel tr + JOIN Entradas E ON E.travel_id = tr.id + WHERE landing >= vDated + AND E.Id_Proveedor = 4 + ORDER BY landing ASC + LIMIT 1; + + SET vInventoried = TIMESTAMPADD(DAY,1,vDated); + SET vDateDayEnd = vInventoried2; + + END IF; + + DROP TEMPORARY TABLE IF EXISTS inv; + + CREATE TEMPORARY TABLE inv + (warehouseFk SMALLINT, + Id_Article BIGINT, + cantidad INT, + coste DOUBLE DEFAULT 0, + total DOUBLE DEFAULT 0, + Almacen VARCHAR(20), + PRIMARY KEY (Almacen, Id_Article) USING HASH) + ENGINE = MEMORY; + + IF vHasNotInventory = TRUE THEN + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id, C.Id_Article, SUM(C.Cantidad), w.`name` + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id + WHERE landing = vDateDayEnd + AND E.Id_Proveedor = 4 + AND w.valuatedInventory + AND t.inventory + GROUP BY tr.warehouse_id, C.Id_Article; + + END IF; + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id, C.Id_Article, C.Cantidad * IF(vHasNotInventory,-1,1), w.`name` + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = tr.warehouse_id + WHERE landing BETWEEN vInventoried AND vDateDayEnd + AND IF(landing = util.VN_CURDATE(), tr.received, trUE) + AND NOT redada + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(vHasNotInventory,-1,1)); + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id_out, C.Id_Article, C.Cantidad * IF(vHasNotInventory,1,-1), w.`name` + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id_out + WHERE shipment BETWEEN vInventoried AND vDateDayEnd + AND NOT redada + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(vHasNotInventory,1,-1)); + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT w.id, M.Id_Article, M.Cantidad * IF(vHasNotInventory,1,-1), w.`name` + FROM Movimientos M + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C USING(Id_Cliente) + JOIN Articles A USING(Id_Article) + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id + WHERE T.Fecha BETWEEN vInventoried AND vDateDayEnd + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(vHasNotInventory,1,-1); + + IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias + + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT w.id, M.Id_Article, M.Cantidad * IF(vHasNotInventory,0,1), w.`name` + FROM Movimientos M + JOIN Tickets T USING (Id_Ticket) + JOIN Clientes C USING(Id_Cliente) + JOIN Articles A USING(Id_Article) + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = warehouse_id + WHERE T.Fecha BETWEEN vDated AND vDateDayEnd + AND (M.OK <> 0 or T.Etiquetasemitidas <> 0 ) + AND w.valuatedInventory + AND t.inventory + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(vHasNotInventory,0,1); + + END IF; + + -- Mercancia en transito + INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) + SELECT tr.warehouse_id, C.Id_Article, C.Cantidad, CONCAT(wOut.`name`,' - ', wIn.`name`) + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel tr ON tr.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse wIn ON wIn.id = tr.warehouse_id + JOIN warehouse wOut ON wOut.id = tr.warehouse_id_out + WHERE vDated >= shipment AND vDated < landing + AND NOT redada + AND wIn.valuatedInventory + AND t.inventory + AND E.Confirmada + ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad); + + CALL vn.buyUltimate(NULL,vDateDayEnd); + + UPDATE inv i + JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.Id_Article = bu.itemFk + JOIN Compres C ON C.Id_Compra = bu.buyFk + SET total = i.cantidad * (ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0)), + coste = ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0) + WHERE i.cantidad <> 0; + + DELETE FROM inv WHERE Cantidad IS NULL or Cantidad = 0; + + IF vIsDetailed THEN + + SELECT inv.warehouseFk, a.Id_Article, a.Article, a.Medida, inv.Cantidad, tp.Id_Tipo, + tp.reino_id, inv.coste, cast(inv.total as decimal(10,2)) total, Almacen + FROM inv + JOIN warehouse w on w.id = warehouseFk + JOIN Articles a ON a.Id_Article = inv.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + WHERE w.valuatedInventory + and inv.total > 0 + order by inv.total desc; + + ELSE + + SELECT i.Almacen, r.reino as Reino, cast(i.total as decimal(10,2)) as Euros, tr.Codigotrabajador as Comprador,A.Id_Article + FROM inv i + JOIN warehouse w on w.id = warehouseFk + JOIN Articles A USING(Id_Article) + JOIN Tipos t USING(tipo_id) + LEFT JOIN Trabajadores tr ON tr.Id_trabajador = t.Id_trabajador + JOIN reinos r ON r.id = t.reino_id + WHERE w.valuatedInventory + AND i.total > 0; + + END IF; + DROP TEMPORARY TABLE tmp.buyUltimate; + DROP TEMPORARY TABLE inv; +end$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/item_buy.sql b/db/routines/vn2008/procedures/item_buy.sql new file mode 100644 index 000000000..244334c80 --- /dev/null +++ b/db/routines/vn2008/procedures/item_buy.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`item_buy`(IN v_wh TINYINT, IN v_date DATETIME) +BEGIN + DECLARE date_inv DATE; + ALTER TABLE item + ADD buy_id INT UNSIGNED; + + IF v_date < (SELECT vn.getInventoryDate()) THEN + SELECT MIN(landing) INTO date_inv FROM travel t INNER JOIN Entradas e ON e.travel_id = t.id + WHERE warehouse_id_out = 13 AND landing <= v_date; + ELSE + SET date_inv = vn.getInventoryDate(); + END IF; + UPDATE item i INNER JOIN ( + SELECT * FROM ( + SELECT c.Id_Article item_id, c.Id_Compra id + FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) + INNER JOIN travel t ON t.id = e.travel_id + WHERE t.landing BETWEEN date_inv AND v_date + AND c.Novincular = FALSE + AND c.Tarifa2 >= 0 + ORDER BY v_wh = t.warehouse_id DESC, t.landing DESC + LIMIT 10000000000000000000 + ) t + GROUP BY item_id + ) t + ON i.id = t.item_id + SET i.buy_id = t.id; + + CREATE INDEX buy USING HASH ON item (buy_id); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/item_express.sql b/db/routines/vn2008/procedures/item_express.sql new file mode 100644 index 000000000..46275014d --- /dev/null +++ b/db/routines/vn2008/procedures/item_express.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`item_express`(IN intWH INT, IN datFEC DATE) +BEGIN + +DECLARE datINV DATE; + + + +SELECT FechaInventario INTO datINV FROM tblContadores LIMIT 1; + + +SELECT sub1.Id_Article, Visible, Tarifa2 +FROM +(SELECT Id_Article, SUM(Cantidad) as Visible +FROM Compres C +JOIN Entradas E USING(Id_Entrada) +JOIN travel T ON T.id = E.travel_id +WHERE shipment >= datINV +AND landing <= datFEC +AND Redada = 0 +AND warehouse_id = intWH +GROUP BY Id_Article) sub1 +JOIN +( +SELECT * FROM +( +SELECT Id_Article, Tarifa2 +FROM Compres C +JOIN Entradas E USING(Id_Entrada) +JOIN travel T ON T.id = E.travel_id +WHERE shipment >= datINV +AND landing <= datFEC +AND Redada = 0 +AND Novincular = 0 +AND warehouse_id = intWH +ORDER BY landing DESC LIMIT 10000000000000000000) sub +GROUP BY Id_Article) sub2 USING(Id_Article); + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/item_new.sql b/db/routines/vn2008/procedures/item_new.sql new file mode 100644 index 000000000..701e4986a --- /dev/null +++ b/db/routines/vn2008/procedures/item_new.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`item_new`() +BEGIN + CREATE TEMPORARY TABLE item + ( + item_id INT UNSIGNED NOT NULL, + UNIQUE KEY USING HASH (item_id) + ) + ENGINE = MEMORY; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/malpagantes.sql b/db/routines/vn2008/procedures/malpagantes.sql new file mode 100644 index 000000000..196de92d2 --- /dev/null +++ b/db/routines/vn2008/procedures/malpagantes.sql @@ -0,0 +1,44 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`malpagantes`() +BEGIN + +set @cliente := 0; +set @saldo := 0; + +Select Id_Cliente, Cliente from +Clientes +join +(select distinct Id_Cliente +from Facturas +where Fecha > '2015-01-01') cli using(Id_Cliente) +left join +( +select distinct Id_Cliente +from +( +select Fecha + , @saldo := IF(@cliente = Id_Cliente, @saldo + Importe, Importe) Saldo + , @cliente := Id_Cliente as Id_Cliente +from +( +select Id_Cliente, Fecha, Importe from + +( +select Id_Cliente, -1 * Importe Importe, Fecha +from Facturas +union all +select Id_Cliente, Entregado, Fechacobro +from Recibos +) sub +order by Id_Cliente, Fecha +) sub2 +) sub3 +where Saldo > -1 +and Fecha > '2015-01-01' + +) sub4 using(Id_Cliente) +where sub4.Id_Cliente is null; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/mensaje.sql b/db/routines/vn2008/procedures/mensaje.sql new file mode 100644 index 000000000..89f9bf4f0 --- /dev/null +++ b/db/routines/vn2008/procedures/mensaje.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`mensaje`(IN idREM INT, IN idDES INT, IN strMSG LONGTEXT) +BEGIN + +/*DECLARE lngLASTID BIGINT;*/ + +-- Caso sencillo + +INSERT INTO Mensajes(Mensaje, Fecha, Remitente, Destinatario) +VALUES(strMSG, util.VN_NOW(), idREM, idDES); + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/msg.sql b/db/routines/vn2008/procedures/msg.sql new file mode 100644 index 000000000..e402efe39 --- /dev/null +++ b/db/routines/vn2008/procedures/msg.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`msg`(IN memTXT VARCHAR(255), IN idREM INTEGER, idDES INTEGER) +BEGIN + DECLARE last_ID INTEGER; + DECLARE codDES CHAR(3); + + SELECT CodigoTrabajador INTO codDES FROM Trabajadores WHERE Id_Trabajador = idDES; + + INSERT INTO Mensajes(Mensaje,Fecha,Remitente,Destinatario) + VALUES(memTXT, util.VN_NOW(),idREM, idDES); + + SELECT LAST_INSERT_ID() INTO last_ID; + + + INSERT INTO Incidencias(Incidencia,Id_Trabajador,Destino,Fecha,Fecha_Mod) + VALUES (CONCAT('@@ ',last_ID),idREM,codDES,util.VN_NOW(),util.VN_NOW()); + + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/nest_child_add.sql b/db/routines/vn2008/procedures/nest_child_add.sql new file mode 100644 index 000000000..5b45a9d07 --- /dev/null +++ b/db/routines/vn2008/procedures/nest_child_add.sql @@ -0,0 +1,48 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`nest_child_add`( + vTable VARCHAR(45) + ,vChild VARCHAR(45) + ,vFatherId INT +) +BEGIN + DECLARE vMyLeft INT; + + SET vTable = util.quoteIdentifier(vTable); + + DROP TEMPORARY TABLE IF EXISTS aux; + CREATE TEMPORARY TABLE aux + SELECT 0 as lft; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux + SET lft = (SELECT lft + FROM ', vTable, + ' WHERE id = ?)') + USING vFatherId; + + SELECT lft INTO vMyLeft FROM aux; + DROP TEMPORARY TABLE aux; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, ' + SET rgt = rgt + 2 + WHERE rgt > ? + ORDER BY rgt DESC') + USING vMyLeft; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, ' + SET lft = lft + 2 + WHERE lft > ? + ORDER BY lft DESC') + USING vMyLeft; + + EXECUTE IMMEDIATE CONCAT( + 'INSERT INTO ', vTable, ' (name, lft, rgt) + VALUES(?, ? + 1, ? + 2)') + USING vChild, + vMyLeft, + vMyLeft; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/nest_delete.sql b/db/routines/vn2008/procedures/nest_delete.sql new file mode 100644 index 000000000..84f75294b --- /dev/null +++ b/db/routines/vn2008/procedures/nest_delete.sql @@ -0,0 +1,51 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`nest_delete`( + vTable VARCHAR(45) + ,vNodeId INT +) +BEGIN + DECLARE vMyRight INT; + DECLARE vMyLeft INT; + DECLARE vMyWidth INT; + + DROP TEMPORARY TABLE IF EXISTS aux; + CREATE TEMPORARY TABLE aux + SELECT 0 rgt, 0 lft, 0 wdt; + + SET vTable = util.quoteIdentifier(vTable); + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.rgt = t.rgt, + a.lft = t.lft, + a.wdt = t.rgt - t.lft + 1 + WHERE t.id = ?') + USING vNodeId; + + SELECT rgt, lft, wdt + INTO vMyRight, vMyLeft, vMyWidth + FROM aux; + + DROP TEMPORARY TABLE aux; + + EXECUTE IMMEDIATE CONCAT( + 'DELETE FROM ', vTable, + ' WHERE lft BETWEEN ? AND ?') + USING vMyLeft, vMyRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + ' SET rgt = rgt - ? + WHERE rgt > ? + ORDER BY rgt') + USING vMyWidth,vMyRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + ' SET lft = lft - ? + WHERE lft > ? + ORDER BY lft') + USING vMyWidth, vMyRight; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/nest_move.sql b/db/routines/vn2008/procedures/nest_move.sql new file mode 100644 index 000000000..950d46e68 --- /dev/null +++ b/db/routines/vn2008/procedures/nest_move.sql @@ -0,0 +1,108 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`nest_move`( + vTable VARCHAR(45) + ,idNODE INT + ,idFATHER INT +) +BEGIN + DECLARE myRight INT; + DECLARE myLeft INT; + DECLARE myWidth INT; + DECLARE fatherRight INT; + DECLARE fatherLeft INT; + DECLARE gap INT; + + SET vTable = util.quoteIdentifier(vTable); + + DROP TEMPORARY TABLE IF EXISTS aux; + CREATE TEMPORARY TABLE aux + SELECT 0 as rgt, 0 as lft, 0 as wdt, 0 as frg, 0 as flf; + + -- Averiguamos el ancho de la rama + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.wdt = t.rgt - t.lft + 1 + WHERE t.id = ?') + USING idNODE; + + -- Averiguamos la posicion del nuevo padre + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.frg = t.rgt, + a.flf = t.lft + WHERE t.id = ?') + USING idFATHER; + + SELECT wdt, frg, flf INTO myWidth, fatherRight, fatherLeft + FROM aux; + + -- 1º Incrementamos los valores de todos los nodos a la derecha del punto de inserción (fatherRight) , para hacer sitio + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET rgt = rgt + ? + WHERE rgt >= ? + ORDER BY rgt DESC') + USING myWidth, + fatherRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET lft = lft + ? + WHERE lft >= ? + ORDER BY lft DESC') + USING myWidth, + fatherRight; + + -- Es preciso recalcular los valores del nodo en el caso de que estuviera a la derecha del nuevo padre + EXECUTE IMMEDIATE CONCAT( + 'UPDATE aux a + JOIN ', vTable, ' t + SET a.rgt = t.rgt, + a.lft = t.lft + WHERE t.id = ?') + USING idNODE; + + SELECT lft, rgt, frg - lft INTO myLeft, myRight, gap + FROM aux; + + -- 2º Incrementamos el valor de todos los nodos a trasladar hasta alcanzar su nueva posicion + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET lft = lft + ? + WHERE lft BETWEEN ? AND ? + ORDER BY lft DESC') + USING gap, + myLeft, + myRight; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET rgt = rgt + ? + WHERE rgt BETWEEN ? AND ? + ORDER BY rgt DESC') + USING gap, + myLeft, + myRight; + + -- 3º Restaremos a todos los nodos resultantes, a la derecha de la posicion arrancada el ancho de la rama escindida + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET lft = lft - ? + WHERE lft > ? + ORDER BY lft') + USING myWidth, + myLeft; + + EXECUTE IMMEDIATE CONCAT( + 'UPDATE ', vTable, + 'SET rgt = rgt - ? + WHERE rgt > ? + ORDER BY rgt') + USING myWidth, + myRight; + + DROP TEMPORARY TABLE aux; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/newItem.sql b/db/routines/vn2008/procedures/newItem.sql new file mode 100644 index 000000000..8982b6adc --- /dev/null +++ b/db/routines/vn2008/procedures/newItem.sql @@ -0,0 +1,34 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`newItem`(IN vTicket INTEGER, IN vVolume INTEGER, IN vQuantity INTEGER) +BEGIN + + DECLARE vLandingWarehouse INT; + DECLARE vLandingDate DATE; + DECLARE vShipmentDate DATE; + DECLARE vTravel INT; + DECLARE vEntry INT; + + SELECT warehouse_id, Fecha, landing INTO vLandingWarehouse, vShipmentDate, vLandingDate FROM Tickets WHERE Id_Ticket = vTicket; + + -- seleccionamos travel + SELECT id, Id_Entrada INTO vTravel, vEntry + FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id + WHERE t.landing = vLandingDate AND t.shipment = vShipmentDate AND t.warehouse_id_out = vLandingWarehouse AND t.warehouse_id = vWarehouse + AND t.delivered = FALSE ; -- agency ?? + + -- creamos el travel si es necesario + IF NOT vTravel THEN + INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) + VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, a); + SELECT LAST_INSERT_ID() INTO vTravel; + END IF; + + -- creamos la Entrada si es necesario + IF NOT vEntry THEN + INSERT INTO Entradas (Id_Proveedor, travel_id) + VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' + SELECT LAST_INSERT_ID() INTO vEntry; + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/niching.sql b/db/routines/vn2008/procedures/niching.sql new file mode 100644 index 000000000..eff501ed5 --- /dev/null +++ b/db/routines/vn2008/procedures/niching.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`niching`(IN i_ini INT, IN i_end INT +, IN i_bal INT, IN i_col INT ) +BEGIN + +DECLARE i INT(5); +DECLARE j INT(5); + +DROP TEMPORARY TABLE IF EXISTS labels; + +CREATE TEMPORARY TABLE `labels` + (`label` VARCHAR(15) NULL) +ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +WHILE i_ini <= i_end DO + + SET i = i_bal; + + WHILE i > 0 DO + + + + SET j = i_col; + IF j = 0 THEN + INSERT INTO labels(label) + VALUES (CONCAT(i_ini,IF(i=0,' ',char(64 + i)))); + ELSE + + WHILE j > 0 DO + + INSERT INTO labels(label) + VALUES (CONCAT(i_ini,char(64 + i), j)); + + SET j = j - 1; + + END WHILE; + END IF; + SET i = i - 1; + + END WHILE; + +SET i_ini = i_ini + 1; + +END WHILE; + +SELECT CONCAT('*',label,'*') as label, label as id FROM labels; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/notify_passport.sql b/db/routines/vn2008/procedures/notify_passport.sql new file mode 100644 index 000000000..5b611f063 --- /dev/null +++ b/db/routines/vn2008/procedures/notify_passport.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`notify_passport`( + IN vItemFk INT, + IN vStickers SMALLINT, + IN vPacking SMALLINT, + IN vBuyFk INT +) +BEGIN + -- DPRECATED use vn.buy_notifyPassport + CALL vn.buy_notifyPassport(vBuyFk, vItemFk, vStickers, vPacking); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/pay.sql b/db/routines/vn2008/procedures/pay.sql new file mode 100644 index 000000000..ec73ee696 --- /dev/null +++ b/db/routines/vn2008/procedures/pay.sql @@ -0,0 +1,67 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`pay`(IN datFEC DATE + , IN idPROV INT + , IN dblIMPORTE DOUBLE + , IN idMONEDA INT + , IN dblDIVISA DOUBLE + , IN idCAJA INT + , IN idPAYMET INT + , IN dblGASTOS DOUBLE + , IN strCONCEPTO VARCHAR(40) + , IN idEMP INT) +BEGIN + + -- Registro en la tabla Cajas + INSERT INTO Cajas ( Concepto + , Serie + , Numero + , Salida + , Cajafecha + , Partida + , Id_Banco + , Id_Trabajador + ,empresa_id + ,conciliado) + + SELECT CONCAT('n/pago a ', Proveedor) + , 'R' + , idPROV + , dblIMPORTE + , datFEC + , 1 + , idCAJA + , account.myUser_getId() + , idEMP + , 1 + FROM Proveedores + WHERE Id_Proveedor = idPROV; + + -- Registro en la tabla pago + INSERT INTO pago(fecha + , dueDated + , id_proveedor + , importe + , id_moneda + , divisa + , id_banco + , pay_met_id + , g_bancarios + , concepte + , empresa_id) + + VALUES(datFEC + , datFEC + , idPROV + , dblIMPORTE + , idMONEDA + , IF(dblDIVISA = 0, NULL, dblDIVISA) + , idCAJA + , idPAYMET + , dblGASTOS + , strCONCEPTO + , idEMP); + + SELECT LAST_INSERT_ID() as pago_id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/percentil.sql b/db/routines/vn2008/procedures/percentil.sql new file mode 100644 index 000000000..650be0138 --- /dev/null +++ b/db/routines/vn2008/procedures/percentil.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`percentil`() +BEGIN + +DECLARE max_range INT; + +DROP TEMPORARY TABLE IF EXISTS previa; + +CREATE TEMPORARY TABLE previa +SELECT @posicion:= @posicion +1 as Posicion, Id_Cliente, Total FROM ( +SELECT Id_Cliente, Total FROM ( +SELECT Id_Cliente, SUM(Importe) as Total +FROM Facturas +INNER JOIN Clientes USING(Id_Cliente) +INNER JOIN (SELECT @posicion := 0) sub_pos +WHERE invoice +AND YEAR(Fecha) = YEAR(util.VN_CURDATE()) +GROUP BY Id_Cliente) sub +ORDER BY Total +) sub2; + +SELECT COUNT(*) INTO max_range FROM previa; + +UPDATE Clientes SET percentil = 0; + +UPDATE Clientes INNER JOIN previa USING(Id_Cliente) +SET Clientes.percentil = ROUND(Posicion *100 / max_range,0); + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/preOrdenarRuta.sql b/db/routines/vn2008/procedures/preOrdenarRuta.sql new file mode 100644 index 000000000..b5fd2b24b --- /dev/null +++ b/db/routines/vn2008/procedures/preOrdenarRuta.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`preOrdenarRuta`(IN vRutaId INT) +BEGIN +/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta + * vRutaId id ruta + * DEPRECATED use vn.routeGressPriority +*/ + +UPDATE Tickets mt +JOIN ( + SELECT tt.Id_Consigna, round(ifnull(avg(t.Prioridad),0),0) as Prioridad + from Tickets t + JOIN Tickets tt on tt.Id_Consigna = t.Id_Consigna + where t.Fecha > TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) + AND tt.Id_Ruta = vRutaId + GROUP BY Id_Consigna + ) sub ON sub.Id_Consigna = mt.Id_Consigna + SET mt.Prioridad = sub.Prioridad + WHERE mt.Id_Ruta = vRutaId; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/prepare_client_list.sql b/db/routines/vn2008/procedures/prepare_client_list.sql new file mode 100644 index 000000000..740bbff4a --- /dev/null +++ b/db/routines/vn2008/procedures/prepare_client_list.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`prepare_client_list`() +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente + FROM tmp.ticket_list; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/prepare_ticket_list.sql b/db/routines/vn2008/procedures/prepare_ticket_list.sql new file mode 100644 index 000000000..e407a91b7 --- /dev/null +++ b/db/routines/vn2008/procedures/prepare_ticket_list.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`prepare_ticket_list`(vStartingDate DATETIME, vEndingDate DATETIME) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + ENGINE = MEMORY + SELECT t.Id_Ticket, c.Id_Cliente + FROM Tickets t + LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.Id_Ticket + JOIN Clientes c ON c.Id_Cliente = t.Id_Cliente + WHERE c.typeFk IN ('normal','handMaking','internalUse') + AND ( + Fecha BETWEEN util.today() AND vEndingDate + OR ( + ts.alertLevel < 3 + AND t.Fecha >= vStartingDate + AND t.Fecha < util.today() + ) + ); +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/proc_end.sql b/db/routines/vn2008/procedures/proc_end.sql new file mode 100644 index 000000000..982ef708f --- /dev/null +++ b/db/routines/vn2008/procedures/proc_end.sql @@ -0,0 +1,11 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`proc_end`() +BEGIN + +UPDATE stat SET `end` = util.VN_NOW() +WHERE id = (SELECT id FROM lastid); + +DROP TEMPORARY TABLE IF EXISTS lastid; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/proc_start.sql b/db/routines/vn2008/procedures/proc_start.sql new file mode 100644 index 000000000..57d919c12 --- /dev/null +++ b/db/routines/vn2008/procedures/proc_start.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`proc_start`(IN v_proc_id INT) +BEGIN + +INSERT INTO stat(proc_id) VALUES(v_proc_id); + + +DROP TEMPORARY TABLE IF EXISTS lastid; +CREATE TEMPORARY TABLE lastid +SELECT last_insert_id() id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/prueba_miguel.sql b/db/routines/vn2008/procedures/prueba_miguel.sql new file mode 100644 index 000000000..829f4a8cf --- /dev/null +++ b/db/routines/vn2008/procedures/prueba_miguel.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`prueba_miguel`() +BEGIN +select 1; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/quadre_clientes.sql b/db/routines/vn2008/procedures/quadre_clientes.sql new file mode 100644 index 000000000..3db4c073a --- /dev/null +++ b/db/routines/vn2008/procedures/quadre_clientes.sql @@ -0,0 +1,67 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`quadre_clientes`(IN datFEC DATETIME) +BEGIN + + + DECLARE datSTART DATE; + SET datFEC = TIMESTAMP(datFEC,'23:59:59'); + SELECT util.firstDayOfYear(datFEC) INTO datSTART; + + SELECT P2.Alias, C.Id_Cliente, C.Cuenta, Gestion, Contaplus, Gestion - Contaplus as Diferencia, empresa_id, Cliente + + FROM Clientes C + + JOIN pay_met pm ON pm.id = C.pay_met_id + + JOIN + + ( + + SELECT empresa_id, Id_Cliente, round(sum(Gestion),2) as Gestion, round(sum(Contaplus),2) as Contaplus + + FROM + + ( + SELECT empresa_id, Id_Cliente, Gestion, 0 as Contaplus + + FROM + + ( + SELECT empresa_id, Id_Cliente, -1 * Importe as Gestion + FROM Facturas + WHERE Fecha BETWEEN datSTART AND datFEC + UNION ALL + SELECT empresa_id, Id_Cliente, Entregado + FROM Recibos + WHERE Fechacobro BETWEEN datSTART AND datFEC + ) G + + WHERE empresa_id <> 965 + + UNION ALL + + SELECT empresa_id, Id_Cliente, 0, round(nz(Eurohaber) - nz(Eurodebe),2) as Contaplus + + FROM bi.XDiario_ALL XD + + JOIN Clientes C ON C.Cuenta = XD.SUBCTA + + WHERE Fecha BETWEEN datSTART AND datFEC + + ) sub1 + + GROUP BY empresa_id, Id_Cliente + + ) sub2 USING(Id_Cliente) + + JOIN Proveedores P2 ON P2.Id_Proveedor = sub2.empresa_id + + WHERE pm.deudaviva -- Cliente de perdidas no vale la pena revisarlo + + HAVING ABS(Diferencia) > 0.05 + + ORDER BY Cliente; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/quadre_clientes_detalle.sql b/db/routines/vn2008/procedures/quadre_clientes_detalle.sql new file mode 100644 index 000000000..4ed261d4b --- /dev/null +++ b/db/routines/vn2008/procedures/quadre_clientes_detalle.sql @@ -0,0 +1,70 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`quadre_clientes_detalle`(IN idC INT, IN idE INT, IN datFEC DATETIME) +BEGIN + +DECLARE datSTART DATE; + +SET datSTART = util.firstDayOfYear(datFEC); +SET datFEC = TIMESTAMP(datFEC,'23:59:59'); + +-- Creamos una tabla para almacenar las facturas del cliente, junto con el numero de veces que se repite. +DROP TEMPORARY TABLE IF EXISTS qFACTURAS; + +CREATE TEMPORARY TABLE qFACTURAS +(Fecha DATETIME, + TPVcount INT, + Factura DECIMAL(10,2) SIGNED, + Recibo DECIMAL(10,2) SIGNED, + CPcount INT, + Debe DECIMAL(10,2) SIGNED, + Haber DECIMAL(10,2) SIGNED, + Control INT DEFAULT 0, + PRIMARY KEY(Fecha, TPVcount, Factura, Recibo, CPcount, Debe, Haber)) + ENGINE = InnoDB +; + +-- Insertamos las facturas y los recibos de gestion. +INSERT INTO qFACTURAS + + SELECT Fecha, COUNT(*) as TPVcount, round(Importe,2) as Factura, 0 as Recibo, COUNT(*)as CPcount,round(Importe,2) as Debe, 0 as Haber, 1 as Control + FROM Facturas + WHERE Id_Cliente = idC AND empresa_id = idE AND Fecha BETWEEN datSTART AND datFEC + GROUP BY Fecha, round(Importe,2) + UNION ALL + SELECT Fechacobro as Fecha, COUNT(*) as TPVcount, 0 as Factura, round(Entregado,2) as Recibo,COUNT(*) as CPCount, 0 as Debe, round(Entregado,2) as Haber, 3 as Control + FROM Recibos + WHERE Id_Cliente = idC AND empresa_id = idE AND Fechacobro BETWEEN datSTART AND datFEC + GROUP BY Fechacobro, round(Entregado,2); + +-- Insertamos los asientos de contabilidad, marcando con control = -1 las repetidas. +INSERT INTO qFACTURAS + SELECT * + FROM ( + SELECT Fecha, COUNT(*) as TPVcount, round(Eurodebe,2) as Factura, round(Eurohaber,2) as Recibo, COUNT(*) as CPcount, round(Eurodebe,2) as Debe, round(Eurohaber,2) as Haber, 2 as Control + FROM bi.XDiario_ALL XD + JOIN Clientes C ON C.Cuenta = XD.SUBCTA + WHERE Id_Cliente = idC AND empresa_id = idE AND Fecha BETWEEN datSTART AND datFEC + AND (Eurodebe <> 0 OR Eurohaber <>0) + GROUP BY Fecha, round(Eurodebe,2), round(Eurohaber,2) + ) sub + + ON DUPLICATE KEY UPDATE Control = -1; + + + +-- Eliminamos las repetidas +-- DELETE FROM qFACTURAS WHERE Control = -1; + +-- Arreglamos las buenas +UPDATE qFACTURAS SET TPVcount = 0, Factura = 0, Recibo = 0 WHERE Control = 2; +UPDATE qFACTURAS SET CPcount = 0, Debe = 0, Haber = 0 WHERE Control IN (1,3); + +-- Mostramos el resultado +SELECT *, @saldo := @saldo + TPVcount * (Factura + Recibo) - CPCount * ( Debe + Haber ) as Saldo +FROM qFACTURAS +JOIN (SELECT @saldo := 0) truqui ; +DROP TEMPORARY TABLE IF EXISTS qFACTURAS; + + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/raidUpdate.sql b/db/routines/vn2008/procedures/raidUpdate.sql new file mode 100644 index 000000000..9746f3cf9 --- /dev/null +++ b/db/routines/vn2008/procedures/raidUpdate.sql @@ -0,0 +1,28 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`raidUpdate`() +BEGIN + + UPDATE Entradas e + JOIN Entradas_Auto ea USING (Id_Entrada) + JOIN travel t ON t.id = e.travel_id + JOIN ( + SELECT * + FROM ( + SELECT id, landing, warehouse_id, warehouse_id_out + FROM travel + JOIN ( + SELECT warehouse_id, warehouse_id_out + FROM Entradas_Auto ea + JOIN Entradas e USING(Id_Entrada) + JOIN travel t ON t.id = e.travel_id + GROUP BY warehouse_id, warehouse_id_out + ) t USING (warehouse_id, warehouse_id_out) + WHERE shipment > util.VN_CURDATE() AND delivered = FALSE + ORDER BY landing + LIMIT 10000000000000000000 + ) t + GROUP BY warehouse_id, warehouse_id_out + ) t USING (warehouse_id, warehouse_id_out) + SET e.travel_id = t.id; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/rateView.sql b/db/routines/vn2008/procedures/rateView.sql new file mode 100644 index 000000000..91e317be6 --- /dev/null +++ b/db/routines/vn2008/procedures/rateView.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`rateView`() +BEGIN + + SELECT + t.year as año, + t.month as mes, + pagos.dolares, + pagos.cambioPractico, + CAST(sum(divisa) / sum(bi) as DECIMAL(5,4)) as cambioTeorico, + pagos.cambioOficial + FROM recibida r + JOIN time t ON t.date = r.fecha + JOIN recibida_iva ri ON r.id = ri.recibida_id + JOIN + ( + SELECT + t.year as Año, + t.month as Mes, + cast(sum(divisa) as DECIMAL(10,2)) as dolares, + cast(sum(divisa) / sum(importe) as DECIMAL(5,4)) as cambioPractico, + cast(rr.rate * 0.998 as DECIMAL(5,4)) as cambioOficial + FROM pago p + JOIN time t ON t.date = p.fecha + JOIN reference_rate rr ON rr.date = p.fecha AND moneda_id = 2 + WHERE divisa + AND fecha >= '2015-01-11' + GROUP BY t.year, t.month + ) pagos ON t.year = pagos.Año AND t.month = pagos.Mes + WHERE moneda_id = 2 + AND fecha >= '2015-01-01' + AND divisa + AND bi + GROUP BY t.year, t.month; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/recibidaIvaInsert.sql b/db/routines/vn2008/procedures/recibidaIvaInsert.sql new file mode 100644 index 000000000..e2aba0a35 --- /dev/null +++ b/db/routines/vn2008/procedures/recibidaIvaInsert.sql @@ -0,0 +1,39 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`recibidaIvaInsert`(IN vId INT) +BEGIN + + DECLARE vRate DOUBLE DEFAULT 1; + DECLARE vDated DATE; + + SELECT MAX(rr.date) INTO vDated + FROM reference_rate rr + JOIN recibida r ON r.id = vId + WHERE rr.date <= r.fecha + AND rr.moneda_id = r.moneda_id ; + + IF vDated THEN + + SELECT rate INTO vRate + FROM reference_rate + WHERE `date` = vDated; + END IF; + + DELETE FROM recibida_iva WHERE recibida_id = vId; + + INSERT INTO recibida_iva(recibida_id, bi, gastos_id, divisa, taxTypeSageFk, transactionTypeSageFk) + SELECT r.id, + SUM(Costefijo * Cantidad) / IFNULL(vRate,1) bi, + 6003000000, + IF(r.moneda_id = 1,NULL,SUM(Costefijo * Cantidad )) divisa, + taxTypeSageFk, + transactionTypeSageFk + FROM recibida r + JOIN Entradas e ON e.recibida_id = r.id + JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor + JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + LEFT JOIN reference_rate rr ON rr.moneda_id = r.moneda_id AND rr.date = r.fecha + WHERE r.id = vId + HAVING bi IS NOT NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/recobro_credito.sql b/db/routines/vn2008/procedures/recobro_credito.sql new file mode 100644 index 000000000..8c4ca5f94 --- /dev/null +++ b/db/routines/vn2008/procedures/recobro_credito.sql @@ -0,0 +1,55 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`recobro_credito`() +BEGIN + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + INSERT INTO vn.clientCredit(clientFk, amount) + SELECT c.id, 0 + FROM vn.`client` c + JOIN vn.payMethod pm ON pm.id = c.payMethodFk + WHERE c.credit <> 0 AND pm.`code` = 'card'; + + UPDATE vn.`client` c + JOIN vn.payMethod pm ON pm.id = c.payMethodFk + SET credit = 0 + WHERE pm.`code` = 'card'; + + DROP TEMPORARY TABLE IF EXISTS clientes_credit; + CREATE TEMPORARY TABLE clientes_credit + SELECT Id_Cliente, if (Credito > Recobro ,Credito - Recobro,0) AS newCredit + FROM ( + SELECT r.Id_Cliente, r.amount AS Recobro, + timestampadd(DAY, period, UltimaFecha) AS Deadline, sub2.amount AS Credito + FROM vn2008.recovery r + JOIN ( + SELECT Id_Cliente, amount , odbc_date AS UltimaFecha + FROM ( + SELECT * FROM credit + ORDER BY odbc_date DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY Id_Cliente + ) sub2 USING(Id_Cliente) + WHERE dend IS NULL or dend >= util.VN_CURDATE() + GROUP BY Id_Cliente + HAVING Deadline <= util.VN_CURDATE() + ) sub3 + WHERE Credito > 0; + + UPDATE Clientes + JOIN clientes_credit USING(Id_Cliente) + SET Clientes.Credito = newCredit; + + INSERT INTO credit(Id_Cliente, amount, Id_Trabajador) + SELECT Id_Cliente, newCredit, NULL + FROM clientes_credit; + + DROP TEMPORARY TABLE clientes_credit; + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/risk_vs_client_list.sql b/db/routines/vn2008/procedures/risk_vs_client_list.sql new file mode 100644 index 000000000..92f94eb9f --- /dev/null +++ b/db/routines/vn2008/procedures/risk_vs_client_list.sql @@ -0,0 +1,84 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`risk_vs_client_list`(maxRiskDate DATE) +BEGIN +/** + * Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list + * + * @deprecated usar vn.client_getDebt + * @param maxRiskDate Fecha maxima de los registros + * @return table tmp.risk + */ + DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(util.VN_CURDATE()) - 60, util.VN_CURDATE()); + DECLARE endingDate DATETIME; + DECLARE MAX_RISK_ALLOWED INT DEFAULT 200; + + SET maxRiskDate = IFNULL(maxRiskDate, util.VN_CURDATE()); + SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59'); + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2; + CREATE TEMPORARY TABLE tmp.client_list_2 + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * + FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3; + CREATE TEMPORARY TABLE tmp.client_list_3 + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT * + FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar; + CREATE TEMPORARY TABLE tmp.tickets_sin_facturar + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT t.Id_Cliente, floor(IF(cl.isVies, 1, 1.1) * sum(Cantidad * Preu * (100 - Descuento) / 100)) as total + FROM Movimientos m + JOIN Tickets t on m.Id_Ticket = t.Id_Ticket + JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente + JOIN vn.client cl ON cl.id = t.Id_Cliente + WHERE Factura IS NULL + AND Fecha BETWEEN startingDate AND endingDate + GROUP BY t.Id_Cliente; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + CREATE TEMPORARY TABLE tmp.risk + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo + FROM Clientes c + JOIN ( + SELECT clientFk, SUM(amount) amount,SUM(amount) saldo + FROM vn.clientRisk + JOIN tmp.client_list on Id_Cliente = clientFk + GROUP BY clientFk + UNION ALL + SELECT Id_Cliente, SUM(Entregado),SUM(Entregado) + FROM Recibos + JOIN tmp.client_list_2 using(Id_Cliente) + WHERE Fechacobro > endingDate + GROUP BY Id_Cliente + UNION ALL + SELECT Id_Cliente, total,0 + FROM tmp.tickets_sin_facturar + UNION ALL + SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)) + FROM hedera.tpvTransaction t + JOIN tmp.client_list_3 on Id_Cliente = t.clientFk + WHERE t.receiptFk IS NULL + AND t.status = 'ok' + GROUP BY t.clientFk + ) t ON c.Id_Cliente = t.clientFk + WHERE c.activo != FALSE + GROUP BY c.Id_Cliente; + + DELETE r.* + FROM tmp.risk r + JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente + JOIN vn2008.pay_met pm on pm.id = c.pay_met_id + WHERE IFNULL(r.saldo,0) < 10 + AND r.risk <= MAX_RISK_ALLOWED + AND pm.`name` = 'TARJETA'; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/scan_rutas_view.sql b/db/routines/vn2008/procedures/scan_rutas_view.sql new file mode 100644 index 000000000..e61d94d71 --- /dev/null +++ b/db/routines/vn2008/procedures/scan_rutas_view.sql @@ -0,0 +1,31 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`scan_rutas_view`() +BEGIN + + +/* muestra las rutas agrupadas de los ultimos tres dias, así como una lista de los tickets sin enrutar, agrpados por agencia y fecha*/ + +select Fecha, Id_Ruta, Matricula, sub.m3, CodigoTrabajador, Agencia, Bultos, w.name as Almacen +from +( +select r.Fecha, Id_Ruta, r.Id_Trabajador, r.Id_Agencia, Id_Vehiculo, sum(m3) m3, sum(Bultos) Bultos, warehouse_id +from Rutas r +join Tickets t using(Id_Ruta) +where r.Fecha >= timestampadd(day,-3,util.VN_CURDATE()) +group by Id_Ruta, warehouse_id + +union all + +select ifnull(landing,Fecha), dayofmonth(Fecha) * 100000 + Id_Agencia ruta , count(*) as m3, Id_Agencia, null, null, sum(Bultos), warehouse_id +from Tickets +where Id_Ruta is null +and Fecha between timestampadd(day,-3,util.VN_CURDATE()) and util.dayEnd(util.VN_CURDATE()) +group by ruta, warehouse_id +) sub +left join Vehiculos using(Id_Vehiculo) +left join Agencias using(Id_Agencia) +left join Trabajadores using(Id_Trabajador) +left join warehouse w on w.id = sub.warehouse_id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql b/db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql new file mode 100644 index 000000000..5c824ac9b --- /dev/null +++ b/db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql @@ -0,0 +1,85 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`sort_merge_passes_ernesto`() +BEGIN +declare i INT; +declare SMP INT; +DECLARE SMP_RATE INT; +DECLARE SMP_OLD INT; +DECLARE SMP_NEW INT; + +SET i = 0; +loop1: REPEAT + SET i = i + 1; + SET @SleepTime = 300; + + SELECT variable_value INTO @SMP_OLD FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes'; + + SELECT SLEEP(@SleepTime) INTO @NiCasoAEsteSLEEP_EsNormal; + + SELECT variable_value INTO @SMP_NEW FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes'; + SET @SMP = @SMP_NEW - @SMP_OLD; + SET @SMP_RATE = @SMP * 3600 / @SleepTime; + + Select VARIABLE_value into @connections from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'connections'; + Select VARIABLE_value into @Threads_created from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_created'; + Select VARIABLE_value into @Threads_cached from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_cached'; + Select VARIABLE_value into @Innodb_os_log_written from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Innodb_os_log_written'; + + Select VARIABLE_value into @Created_tmp_disk_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Created_tmp_disk_tables'; + Select VARIABLE_value into @created_tmp_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'created_tmp_tables'; + Select VARIABLE_value into @Created_tmp_files from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Created_tmp_files'; + Select VARIABLE_value into @opened_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'opened_tables'; + Select VARIABLE_value into @open_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'open_tables'; + Select VARIABLE_value into @TABLE_OPEN_CACHE_OVERFLOWS from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_OVERFLOWS'; + Select VARIABLE_value into @TABLE_OPEN_CACHE_MISSES from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_MISSES'; + Select VARIABLE_value into @TABLE_OPEN_CACHE_HITS from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_HITS'; + Select VARIABLE_value into @Uptime_since_flush_status from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Uptime_since_flush_status'; + Select VARIABLE_value into @Uptime from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Uptime'; + Select VARIABLE_value into @Qcache_hits from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_hits'; + Select VARIABLE_value into @Qcache_inserts from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_inserts'; + Select VARIABLE_value into @Qcache_not_cached from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_not_cached'; + Select VARIABLE_value into @Innodb_num_open_files from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Innodb_num_open_files'; + Select VARIABLE_value into @Open_table_definitions from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Open_table_definitions'; + select count into @trx_rseg_history_len from information_schema.innodb_metrics where name = 'trx_rseg_history_len'; + + Select @@global.table_definition_cache into @table_definition_cache; + Select @@global.table_open_cache into @table_open_cache; + Select @@global.table_open_cache_instances into @table_open_cache_instances; + Select @@global.thread_cache_size into @Thread_cache_size; + Select @@global.sort_buffer_size into @sort_buffer_size; + select @@global.join_buffer_size into @join_buffer_size; + select @@global.read_rnd_buffer_size into @read_rnd_buffer_size; + select @@global.tmp_table_size into @tmp_table_size; + select @@global.max_heap_table_size into @max_heap_table_size; + Select @@global.open_files_limit into @open_files_limit; + Select @@global.innodb_open_files into @innodb_open_files; + Select @@global.query_cache_size into @query_cache_size; + Select @@global.query_cache_type into @query_cache_type; + select @@global.log_output into @log_output; + + SELECT (Open_tables * Uptime / Opened_Tables) AS OpenTablesxUptimeDivOpened INTO @OpenTablesxUptimeDivOpened FROM + (SELECT variable_value Uptime FROM information_schema.global_status + WHERE variable_name = 'Uptime_since_flush_status') up, + (SELECT variable_value Open_tables FROM information_schema.global_status + WHERE variable_name = 'Open_tables') opn, + (SELECT IF(variable_value=0,1,variable_value) Opened_tables + FROM information_schema.global_status + WHERE variable_name = 'Opened_tables') opnd; + + INSERT INTO sort_merge_results_ernesto (hora, uptime, uptime_since_flush, smp_old, smp_new, smp, smp_hour,connections, Threads_created, Threads_cached, Thread_cache_size, sort_buffer_size, opened_tables, + Created_tmp_disk_tables, created_tmp_tables, Innodb_os_log_written, table_definition_cache, table_open_cache, table_open_cache_instances, open_tables, TABLE_OPEN_CACHE_OVERFLOWS, TABLE_OPEN_CACHE_MISSES, + TABLE_OPEN_CACHE_HITS, tmp_table_size, max_heap_table_size, OpenTablesxUptimeDivOpened, join_buffer_size, open_files_limit, innodb_open_files, Created_tmp_files, query_cache_size, query_cache_type, Qcache_hits, + Qcache_inserts, Qcache_not_cached, Innodb_num_open_files, Open_table_definitions, read_rnd_buffer_size, log_output, trx_rseg_history_len) + VALUES (util.VN_NOW(), @uptime, @uptime_since_flush, @SMP_OLD, @SMP_NEW, @SMP, @SMP_RATE, @connections, @Threads_created, @Threads_cached, @Thread_cache_size, @sort_buffer_size, @opened_tables, + @Created_tmp_disk_tables, @created_tmp_tables, @Innodb_os_log_written, @table_definition_cache, @table_open_cache, @table_open_cache_instances, @open_tables, @TABLE_OPEN_CACHE_OVERFLOWS, @TABLE_OPEN_CACHE_MISSES, + @TABLE_OPEN_CACHE_HITS, @tmp_table_size, @max_heap_table_size, @OpenTablesxUptimeDivOpened, @join_buffer_size, @open_files_limit, @innodb_open_files, @Created_tmp_files, @query_cache_size, @query_cache_type, @Qcache_hits, + @Qcache_inserts, @Qcache_not_cached, @Innodb_num_open_files, @Open_table_definitions, @read_rnd_buffer_size, @log_output, @trx_rseg_history_len); + + if (i mod 3 = 0) then + SELECT * FROM sort_merge_results_ernesto order by hora desc limit 20; + End if; + + UNTIL i >= 12 * 24 +END REPEAT; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/splitAnthuriums2016.sql b/db/routines/vn2008/procedures/splitAnthuriums2016.sql new file mode 100644 index 000000000..fa7b7caf9 --- /dev/null +++ b/db/routines/vn2008/procedures/splitAnthuriums2016.sql @@ -0,0 +1,86 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`splitAnthuriums2016`() +BEGIN + +DECLARE vStartingDate DATETIME DEFAULT '2016-10-18'; +DECLARE vEndingDate DATETIME DEFAULT '2016-10-31 23:59:00'; +DECLARE vMyTicket INT; +DECLARE vNewTicket INT; +-- DECLARE SILLA_PCA INT DEFAULT 44; +DECLARE done INT DEFAULT 0; + +DECLARE rs CURSOR FOR +SELECT DISTINCT Id_Ticket +FROM Movimientos m +JOIN Tickets t using(Id_Ticket) +JOIN Articles a using(Id_Article) +JOIN Tipos tp using(tipo_id) +WHERE t.Fecha between vStartingDate and vEndingDate +AND warehouse_id = 1 +AND + ( + Id_Tipo = 'ANT' + OR + ( Id_Article = 100 + AND + Concepte LIKE 'ANT%') + ); + +DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + +OPEN rs; + +FETCH rs INTO vMyTicket; + + + +WHILE NOT done DO + + + INSERT INTO Tickets(Id_Cliente + , warehouse_id + , Fecha + , Alias + , Id_Consigna + , Id_Trabajador + , Id_Ruta + , empresa_id + , Id_Agencia + , landing) + SELECT Id_Cliente + , SILLA_PCA as warehouse_id + , Fecha + , Alias + , Id_Consigna + , Id_Trabajador + , Id_Ruta + , empresa_id + , Id_Agencia + , landing + FROM Tickets + WHERE Id_Ticket = vMyTicket; + + SELECT LAST_INSERT_ID() INTO vNewTicket; + + -- SELECT vMyTicket, vNewTicket; SET done = 1; + UPDATE Movimientos m + JOIN Articles a using(Id_Article) + JOIN Tipos tp using(tipo_id) + SET Id_Ticket = vNewTicket + WHERE Id_Ticket = vMyTicket + AND ( + Id_Tipo = 'ANT' + OR + ( m.Id_Article = 100 + AND + Concepte LIKE 'ANT%') + ); + + FETCH rs INTO vMyTicket; + +END WHILE; + +CLOSE rs; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/subordinate.sql b/db/routines/vn2008/procedures/subordinate.sql new file mode 100644 index 000000000..a30396951 --- /dev/null +++ b/db/routines/vn2008/procedures/subordinate.sql @@ -0,0 +1,46 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`subordinate`(IN `vWorker` INT, IN `vBaseCase` BOOLEAN) + NO SQL +BEGIN + -- deprecated usar vn.worker_GetHierarch + DECLARE vAuxWorker INT; + + IF vBaseCase THEN + SET @@max_sp_recursion_depth = 5 ; + DROP TEMPORARY TABLE IF EXISTS subordinate; + CREATE TEMPORARY TABLE subordinate + (INDEX (Id_Trabajador)) + ENGINE = MEMORY + SELECT vWorker Id_Trabajador, TRUE visited, 0 boss; + END IF; + + INSERT INTO subordinate + SELECT Id_Trabajador, FALSE, vWorker + FROM Trabajadores WHERE boss = vWorker; + + IF (SELECT COUNT(*) FROM subordinate WHERE NOT visited AND vWorker = boss LIMIT 1) > 0 THEN + SELECT Id_Trabajador INTO vAuxWorker + FROM subordinate + WHERE NOT visited AND vWorker = boss LIMIT 1; + + REPEAT + CALL subordinate(vAuxWorker, FALSE); + UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = vAuxWorker; + SET vAuxWorker = 0; + + SELECT Id_Trabajador INTO vAuxWorker + FROM subordinate + WHERE NOT visited + AND vWorker = boss + LIMIT 1; + + UNTIL vAuxWorker = 0 + END REPEAT; + END IF; + + IF vWorker = 2 THEN + INSERT INTO subordinate + SET Id_Trabajador = vWorker, visited = TRUE, boss = vWorker; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/supplierStatement.sql b/db/routines/vn2008/procedures/supplierStatement.sql new file mode 100644 index 000000000..4701e3e21 --- /dev/null +++ b/db/routines/vn2008/procedures/supplierStatement.sql @@ -0,0 +1,117 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`supplierStatement`(vSupplierFk INT, vCurrencyFk INT, vCompanyFk INT, vOrderBy VARCHAR(15), vOnlyConciliated BIT) +BEGIN + SET @saldo_eur:= 0; + SET @saldo_div:= 0; +select vOnlyConciliated; + DROP TEMPORARY TABLE IF EXISTS tmp.supplierStatement; + + CREATE TEMPORARY TABLE tmp.supplierStatement ENGINE = MEMORY + SELECT + *, + @saldo_eur:= round(@saldo_eur + IFNULL(Pago_Euros, 0) - IFNULL(Fac_Euros, 0) ,2 ) AS saldo_eur, + @saldo_div:= round(@saldo_div + IFNULL(Pago_Divisas, 0) - IFNULL(Fac_Divisas, 0) ,2 ) AS saldo_div + FROM + (SELECT * FROM + (SELECT + NULL as banco_id, + r.empresa_id, + r.serie, + r.id, + CASE + WHEN vOrderBy = 'issued' THEN r.fecha + WHEN vOrderBy = 'bookEntried' THEN r.bookEntried + WHEN vOrderBy = 'booked' THEN r.dateBooking + WHEN vOrderBy = 'dueDate' THEN rv.fecha + END AS fecha, + CONCAT('S/Fra ', r.sref) sref, + if(r.moneda_id > 1,round(sum(divisa) / sum(cantidad),3),NULL) val_cambio, + CAST(sum(cantidad) as DECIMAL(10,2)) as Fac_Euros, + CAST(sum(divisa) as DECIMAL(10,2)) as Fac_Divisas, + NULL AS Pago_Euros, + NULL AS Pago_Divisas, + r.moneda_id, + r.contabilizada, + Moneda, + NULL as pago_sdc_id, + 'invoiceIn' statementType + FROM + recibida r + JOIN recibida_vencimiento rv on rv.recibida_id = r.id + JOIN Monedas m on m.Id_Moneda = r.moneda_id + WHERE + r.fecha > '2014-12-31' + AND r.proveedor_id = vSupplierFk + AND vCurrencyFk IN (r.moneda_id, 0) + AND vCompanyFk IN (r.empresa_id,0) + AND (vOnlyConciliated = r.contabilizada OR NOT vOnlyConciliated) + GROUP BY rv.id + + UNION ALL + SELECT + p.id_banco, + p.empresa_id, + NULL, + p.id, + CASE + WHEN vOrderBy = 'issued' THEN p.Fecha + WHEN vOrderBy = 'bookEntried' THEN p.Fecha + WHEN vOrderBy = 'booked' THEN p.Fecha + WHEN vOrderBy = 'dueDate' THEN p.dueDated + END AS fecha, + CONCAT(IFNULL(name, ''), IF(pre.concepto <> '', CONCAT(' : ', pre.concepto), '')), + if(p.id_moneda > 1, p.divisa / importe, NULL) tip_cambio, + NULL, + NULL, + p.importe, + p.divisa, + p.id_moneda, + p.conciliado, + Moneda, + NULL as pago_sdc_id, + 'payment' statementType + FROM + pago p + LEFT JOIN Monedas ON Monedas.Id_Moneda = p.id_moneda + LEFT JOIN Bancos ON p.id_banco = Bancos.Id_banco + LEFT JOIN pay_met pm ON p.pay_met_id = pm.id + LEFT JOIN Pagares pre ON pre.pago_id = p.id + WHERE + Fecha > '2014-12-31' + AND p.Id_Proveedor = vSupplierFk + AND vCurrencyFk IN (p.id_moneda,0) + AND vCompanyFk IN (p.empresa_id,0) + AND (vOnlyConciliated = p.conciliado OR NOT vOnlyConciliated) + UNION ALL + SELECT + NULL, + companyFk, + NULL, + se.id, + CASE + WHEN vOrderBy = 'issued' THEN se.dated + WHEN vOrderBy = 'bookEntried' THEN se.dated + WHEN vOrderBy = 'booked' THEN se.dated + WHEN vOrderBy = 'dueDate' THEN se.dueDated + END AS fecha, + se.description, + 1 tip_cambio, + amount, + NULL, + NULL, + NULL, + currencyFk, + isConciliated, + c.`code`, + NULL, + 'expense' statementType + FROM vn.supplierExpense se + JOIN vn.currency c on c.id= se.currencyFk + WHERE se.supplierFk = vSupplierFk + AND vCurrencyFk IN (se.currencyFk,0) + AND vCompanyFk IN (se.companyFk,0) + AND (vOnlyConciliated = se.isConciliated OR NOT vOnlyConciliated) + ) AS SUB + ORDER BY (fecha is null and NOT contabilizada),fecha, IF(vOrderBy = 'dueDate', id, NULL) LIMIT 10000000000000000000) t; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/suppliersDebt.sql b/db/routines/vn2008/procedures/suppliersDebt.sql new file mode 100644 index 000000000..9670badc5 --- /dev/null +++ b/db/routines/vn2008/procedures/suppliersDebt.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`suppliersDebt`() +BEGIN + SELECT abbreviation as Empresa, Proveedor, Euros, divisa, empresa_id, proveedor_id + FROM + ( + SELECT empresa_id, + proveedor_id, + cast(sum(Euros) AS DECIMAL(10,2)) as Euros, + cast(sum(divisa) AS DECIMAL(10,2)) as divisa + FROM + ( + SELECT empresa_id, + proveedor_id, + -1 * cantidad as Euros, + -1 * divisa as divisa + FROM recibida_vencimiento rv + INNER JOIN recibida r ON r.id = rv.recibida_id + WHERE r.fecha > '2014-12-31' + + UNION ALL + + SELECT empresa_id, + id_proveedor, + importe, + divisa + FROM pago + WHERE fecha > '2014-12-31' + ) sub + GROUP BY empresa_id, proveedor_id + ) sub2 + JOIN Proveedores p ON p.Id_Proveedor = sub2.proveedor_id + JOIN empresa e ON e.id = sub2.empresa_id; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/top_seller.sql b/db/routines/vn2008/procedures/top_seller.sql new file mode 100644 index 000000000..cb51d1425 --- /dev/null +++ b/db/routines/vn2008/procedures/top_seller.sql @@ -0,0 +1,113 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`top_seller`() +BEGIN + + drop table if exists top_sellers_min; + create temporary table top_sellers_min ENGINE = MEMORY + select a.Id_Article , tip.reino_id as Reino, count(m.Id_Article) as contados + from Movimientos m + inner join Tickets t + on m.Id_Ticket = t.Id_Ticket + inner join Articles a + on a.Id_Article = m.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tip.reino_id + where t.Fecha between timestampadd(day,-7,util.VN_CURDATE()) and util.VN_CURDATE() + group by m.Id_Article; + + drop table if exists top_seller; + create temporary table top_seller ENGINE = MEMORY + select a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 1 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 2 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 3 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 4 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 5 + order by contados desc + limit 5; + + insert into top_seller + select + a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, + tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados + from top_sellers_min tmp + inner join Articles a + on a.Id_Article = tmp.Id_Article + inner join Tipos tip + on a.tipo_id = tip.tipo_id + inner join reinos r + on r.id = tmp.Reino + where tmp.Reino = 7 + order by contados desc + limit 5; + + drop table if exists top_sellers_min; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/traslado.sql b/db/routines/vn2008/procedures/traslado.sql new file mode 100644 index 000000000..9c1e5efe7 --- /dev/null +++ b/db/routines/vn2008/procedures/traslado.sql @@ -0,0 +1,182 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`traslado`(IN i_entrada INTEGER) +BEGIN + DECLARE dateShipment DATE; + DECLARE dateLanding DATE; + DECLARE warehouseShipment INTEGER; + DECLARE warehouseLanding INTEGER; + DECLARE v_calc_visible INTEGER; + DECLARE vInventoryDate DATE; + + SET vInventoryDate := vn.getInventoryDate(); + SELECT shipment, landing, warehouse_id_out, warehouse_id + INTO dateShipment, dateLanding, warehouseShipment, warehouseLanding + FROM travel t JOIN Entradas e ON t.id = e.travel_id + WHERE Id_Entrada = i_entrada; + + CALL vn.rate_getPrices(dateShipment, warehouseLanding); + + -- Traslado en almacen origen + + DROP TEMPORARY TABLE IF EXISTS buy_edi_temp; + CREATE TEMPORARY TABLE buy_edi_temp + (KEY (Id_Article), INDEX(Id_Compra)) ENGINE = MEMORY + SELECT * + FROM (SELECT c.Id_Article, c.Id_Compra + FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) + INNER JOIN travel t ON t.id = e.travel_id + WHERE t.landing BETWEEN vInventoryDate AND dateShipment + AND c.Novincular = FALSE + AND c.Tarifa2 >= 0 + ORDER BY (warehouseShipment = t.warehouse_id) DESC, t.landing DESC + LIMIT 10000000000000000000) t + GROUP BY Id_Article; + + IF dateShipment >= util.VN_CURDATE() THEN + CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseShipment); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + + CREATE TEMPORARY TABLE tmp.item ( + `itemFk` int(10) unsigned NOT NULL, + `visible` int(11) NOT NULL DEFAULT 0, + `available` int(11) NOT NULL DEFAULT 0, + `visibleLanding` int(11) NOT NULL DEFAULT 0, + `availableLanding` int(11) NOT NULL DEFAULT 0, + UNIQUE INDEX i USING HASH (itemFk) + ) ENGINE = MEMORY; + + INSERT INTO tmp.item(itemFk, visible) + SELECT item_id itemFk, visible + FROM `cache`.visible + WHERE calc_id = v_calc_visible + AND visible; + + CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseLanding); + + INSERT INTO tmp.item(itemFk, visibleLanding) + SELECT item_id, `visible` + FROM `cache`.`visible` v + WHERE v.calc_id = v_calc_visible + AND v.`visible` + ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`; + + CALL availableTraslate(warehouseShipment, dateShipment, NULL); + + INSERT INTO tmp.item(itemFk, available) + SELECT a.item_id, a.available + FROM availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE available = a.available; + + CALL availableTraslate(warehouseLanding, dateLanding, warehouseShipment); + + INSERT INTO tmp.item(itemFk, availableLanding) + SELECT a.item_id, a.available + FROM availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE availableLanding = a.available; + ELSE + CALL vn.item_getStock(warehouseShipment, dateShipment, NULL); + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item (UNIQUE INDEX i USING HASH (itemFk)) ENGINE = MEMORY + SELECT itemFk, `visible`, available , 0 visibleLanding, 0 availableLanding + FROM tmp.itemList; + + DROP TEMPORARY TABLE tmp.itemList; + END IF; + + CALL vn.buyUltimateFromInterval(warehouseLanding,vInventoryDate, dateLanding); + + DROP TEMPORARY TABLE IF EXISTS Traslados; + CREATE TEMPORARY TABLE Traslados ENGINE = MEMORY + SELECT tp.Id_Tipo AS Tipo, + tp.reino_id, + ar.tipo_id, + ar.Id_Article AS article_id, + ar.Article, + ar.Medida, + ar.Categoria, + ar.Color, + Origen.abreviatura as Origen, + CE.Cantidad, + ar.Tallos, + CAST(AIM.visible AS DECIMAL(10,0)) as vis1, + CAST(AIM.available AS DECIMAL(10,0)) as dis1, + CAST(AIM.visibleLanding AS DECIMAL(10,0)) as vis2, + CAST(AIM.availableLanding AS DECIMAL(10,0)) as dis2, + COALESCE(CE.`grouping`, C.`grouping`) as `grouping`, + COALESCE(CE.Packing, C.Packing) as Packing, + COALESCE(cl.caja, CE.caja, C.caja) as caja, + IFNULL(p.name, P2.Alias) AS Productor, + C.Id_Cubo, + 1 Tinta, + CE.Id_Compra, + CE.Etiquetas, + C.buy_edi_id, + tp.Id_Trabajador, + CB.Volumen, + IFNULL(CB.x,0) x, + IFNULL(CB.y,0) y, + IFNULL(CB.z,0) z, + IFNULL(C.Costefijo,0) Costefijo, + IFNULL(C.Comisionfija,0) Comisionfija, + IFNULL(C.Portefijo,0) Portefijo, + A.m3, + E.comision, + CB.Retornable, + IFNULL(CEB.Valor,CB.Valor) Valor, + r.rate3 t3, r.rate2 t2, tp.promo, + C.`grouping` groupingOrigin, + C.Packing PackingOrigin, + C.Id_Compra CompraOrigin, + CB.costeRetorno, + C.weight + FROM Articles ar + JOIN tmp.item AIM ON AIM.itemFk = ar.Id_Article + LEFT JOIN producer p ON p.producer_id = ar.producer_id + LEFT JOIN Tipos tp ON tp.tipo_id = ar.tipo_id + JOIN vn.itemCategory ic ON ic.id = tp.reino_id + LEFT JOIN Origen ON Origen.id = ar.id_origen + LEFT JOIN buy_edi_temp lb ON lb.Id_Article = ar.Id_Article + LEFT JOIN Compres C ON C.Id_Compra = lb.Id_Compra + LEFT JOIN Cubos CB ON CB.Id_Cubo = C.Id_Cubo + LEFT JOIN Entradas E2 ON E2.Id_Entrada = C.Id_Entrada + LEFT JOIN Proveedores P2 ON P2.Id_Proveedor = E2.Id_Proveedor + LEFT JOIN Entradas E ON E.Id_Entrada = i_entrada + LEFT JOIN travel TR ON TR.id = E.travel_id + LEFT JOIN Agencias A ON A.Id_Agencia = TR.agency_id + LEFT JOIN Compres CE ON CE.Id_Article = ar.Id_Article AND CE.Id_Entrada = i_entrada + LEFT JOIN Cubos CEB ON CEB.Id_Cubo = CE.Id_Cubo + LEFT JOIN tmp.rate r ON TRUE + LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = ar.Id_Article + LEFT JOIN Compres cl ON cl.Id_Compra = bufi.buyFk + WHERE ic.display + AND E.Redada = FALSE + AND (AIM.visible != 0 OR AIM.available != 0) + ORDER BY tipo_id, Article, article_id, Medida, Categoria, Origen; + + CREATE INDEX tindex USING HASH ON Traslados (article_id); + + SELECT t.*, + Cantidad - MOD(Cantidad , `grouping`) as Subcantidad, + MOD(Cantidad , `grouping`) as Soll, + ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) / Packing,0) as cm3, + Costefijo + Comisionfija + Portefijo AS Cost, + @porte := ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) * m3 / 1000000 / Packing ,3) AS Porte, + @comision := ROUND((Costefijo + Comisionfija + Portefijo) * comision / 100 ,3) AS Comision, + ROUND(@embalaje := (costeRetorno + IF(Retornable != 0, 0, Valor)) / packing ,3) AS Embalaje, + @coste := IFNULL((Costefijo + Comisionfija + Portefijo),0) + IFNULL(@embalaje,0) + IFNULL(@porte,0) + IFNULL(@comision,0) AS Coste, + @t3 := ROUND(@coste / ( (100 - t3 - t.promo)/100),2) AS Tarifa3, + ROUND(@t3 * (1 + ((t2 - t3)/100)),2) AS Tarifa2, + 0 selected + FROM Traslados t; + + DROP TEMPORARY TABLE Traslados; + DROP TEMPORARY TABLE tmp.item; + DROP TEMPORARY TABLE buy_edi_temp; + DROP TEMPORARY TABLE tmp.buyUltimateFromInterval; + DROP TEMPORARY TABLE tmp.rate; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/travelDetail.sql b/db/routines/vn2008/procedures/travelDetail.sql new file mode 100644 index 000000000..39ed4f7b8 --- /dev/null +++ b/db/routines/vn2008/procedures/travelDetail.sql @@ -0,0 +1,119 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`travelDetail`() +BEGIN +/** + * Returns the details of the travels that have a departure warehouse in Ecuador or Colombia. + */ + DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; + SELECT IFNULL(CONCAT(" ",Entrada),travel) travelAndEntry, + travel, + Entrada, + IsTravel, + Agencia, + ref, + shipment, + OrigenCajas, + landing, + Destino, + Etiquetas, + Notas_Eva, + kg, + loadedKg, + volumeKg, + loadPriority, + invoiceAmount, + Carguera, + reference + FROM + (SELECT TRUE IsTravel, + tr.id travel, + NULL Entrada, + ag.Agencia, + tr.ref, + tr.shipment, + wo.name OrigenCajas, + tr.landing, + w.name Destino, + SUM(c.Etiquetas) Etiquetas, + NULL Notas_Eva, + tr.kg, + CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg, + CAST( + SUM(vc.aerealVolumetricDensity * + c.Etiquetas * + IF(cb.Volumen, + cb.Volumen, + cb.X * cb.Y * cb.Z + ) / 1000000 + ) AS INT + ) volumeKg, + NULL loadPriority, + NULL invoiceAmount, + pc.Alias Carguera, + NULL reference + FROM travel tr + LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk + LEFT JOIN Entradas e ON e.travel_id = tr.id + LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo + LEFT JOIN Articles a ON a.Id_Article = c.Id_Article + LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id + JOIN warehouse w ON w.id = tr.warehouse_id + JOIN warehouse wo ON wo.id = tr.warehouse_id_out + JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id + JOIN vn.volumeConfig vc + WHERE tr.landing >= vDateFrom + AND (wo.name="Colombia" OR wo.name="Ecuador") + GROUP BY tr.id + UNION ALL + SELECT 0 IsTravel, + e.travel_id travel, + e.Id_Entrada, + p.Proveedor, + e.Referencia, + tr.shipment, + wo.name OrigenCajas, + tr.landing, + w.name Destino, + SUM(Etiquetas) Etiquetas, + e.Notas_Eva, + NULL kg, + CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg, + CAST( + SUM(vc.aerealVolumetricDensity * + c.Etiquetas * + IF(cb.Volumen, + cb.Volumen, + cb.X * cb.Y * cb.Z + ) / 1000000 + ) AS INT + ) volumeKg, + loadPriority, + e.invoiceAmount, + pc.Alias carguera, + e.reference + FROM Entradas e + JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor + JOIN travel tr ON tr.id = e.travel_id + LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk + JOIN warehouse w ON w.id = tr.warehouse_id + JOIN warehouse wo ON wo.id = tr.warehouse_id_out + JOIN vn.volumeConfig vc + WHERE tr.landing >= vDateFrom + AND (wo.name="Colombia" OR wo.name="Ecuador") + GROUP BY e.Id_Entrada + ) sub + ORDER BY landing ASC, + shipment ASC, + travel, + IsTravel DESC, + (loadPriority > 0) DESC, + loadPriority, + Agencia, + Notas_Eva; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/travel_tree_shipment.sql b/db/routines/vn2008/procedures/travel_tree_shipment.sql new file mode 100644 index 000000000..acbca6752 --- /dev/null +++ b/db/routines/vn2008/procedures/travel_tree_shipment.sql @@ -0,0 +1,37 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`travel_tree_shipment`(v_date DATE, v_consigna INT, v_agency INT, v_warehouse INT) +BEGIN +/** +* DEPRECATED usar vn.agencyHourGetLanded +* + * Devuelve una tabla temporal con el dia de recepcion para v_date. + * + * @param v_date Fecha de preparacion de mercancia + * @param v_consigna Id de consignatario, %NULL para recogida + * @param v_agency Id agencia + * @table travel_tree_shipment Datos de recepción + */ + DROP TEMPORARY TABLE IF EXISTS travel_tree_shipment; + CREATE TEMPORARY TABLE travel_tree_shipment + ENGINE = MEMORY + SELECT v_warehouse warehouse_id, v_envio landing FROM ( + SELECT * FROM ( + SELECT v_warehouse, TIMESTAMPADD(DAY, subtract_day, v_date) v_envio, subtract_day, ah.max_hour + FROM agency_hour ah + LEFT JOIN Consignatarios c ON c.Id_Consigna = v_consigna + WHERE (week_day = weekday(TIMESTAMPADD(DAY, subtract_day, v_date)) OR week_day IS NULL) + AND (ah.agency_id = v_agency OR ah.agency_id IS NULL) + AND ah.warehouse_id = v_warehouse + AND (ah.province_id = c.province_id OR ah.province_id IS NULL OR v_consigna IS NULL) + ORDER BY ( + (ah.week_day IS NOT NULL) + + (ah.agency_id IS NOT NULL) + + (- ah.subtract_day) + + ((ah.province_id IS NOT NULL)*3) + ) DESC + ) t + LIMIT 1 + ) t + WHERE IF(v_date = util.VN_CURDATE(), max_hour > HOUR(util.VN_NOW()), TRUE) AND subtract_day < 225; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_delete.sql b/db/routines/vn2008/procedures/unary_delete.sql new file mode 100644 index 000000000..7f60569ca --- /dev/null +++ b/db/routines/vn2008/procedures/unary_delete.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_delete`(v_node INT, v_delete bool) +BEGIN +/** + * Borra un nodo. Se puede indicar si se quieren mantener los hijos. + * En este caso los hijos pasan al padre del nodo. + * Si no tiene padre, los hijos pasaran a ser padres. + * + * @v_node: Nodo que se quiere borrar. + * @v_delete: Se indica si se borran los nodos. + **/ + + DECLARE v_parent INT; + + SELECT parent + INTO v_parent + FROM unary + WHERE id = v_node; + + IF(v_delete = FALSE) THEN + UPDATE unary + SET parent = v_parent + WHERE parent = v_node; + END IF; + + DELETE FROM unary + WHERE id = v_node; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_insert.sql b/db/routines/vn2008/procedures/unary_insert.sql new file mode 100644 index 000000000..743944f86 --- /dev/null +++ b/db/routines/vn2008/procedures/unary_insert.sql @@ -0,0 +1,17 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_insert`(OUT v_unary INT, v_parent INT) +BEGIN + + /** + * Inserta un nuevo nodo. Se puede indicar el padre. + * + * @v_parent: Nodo padre. + * @v_unary: Id del nuevo nodo. + **/ + + INSERT INTO unary(parent) VALUES(v_parent); + + SELECT last_insert_id() INTO v_unary; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_leaves.sql b/db/routines/vn2008/procedures/unary_leaves.sql new file mode 100644 index 000000000..28b5baa76 --- /dev/null +++ b/db/routines/vn2008/procedures/unary_leaves.sql @@ -0,0 +1,58 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_leaves`(v_top INT) +BEGIN +/** + * A partir de un nodo devuelve todos sus descendientes. + * + * @table tmp.tree Tabla con los ids de los nodos descendientes; + **/ + DECLARE v_count INT; + DECLARE v_parent INT; + DECLARE v_depth INT DEFAULT 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.tree; + CREATE TEMPORARY TABLE tmp.tree + (INDEX (id)) + ENGINE = MEMORY + SELECT v_top id, v_parent parent, v_depth depth; + + DROP TEMPORARY TABLE IF EXISTS tmp.parent; + CREATE TEMPORARY TABLE tmp.parent + ENGINE = MEMORY + SELECT v_top id; + + l: LOOP + + SET v_depth = v_depth + 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.child; + CREATE TEMPORARY TABLE tmp.child + ENGINE = MEMORY + SELECT c.`id`, c.parent + FROM `unary` c + JOIN tmp.parent p ON c.`parent` = p.id; + + DROP TEMPORARY TABLE tmp.parent; + CREATE TEMPORARY TABLE tmp.parent + ENGINE = MEMORY + SELECT c.id, c.parent + FROM tmp.child c + LEFT JOIN tmp.tree t ON t.id = c.id + WHERE t.id IS NULL; + + INSERT INTO tmp.tree + SELECT id, parent, v_depth FROM tmp.parent; + + SELECT COUNT(*) INTO v_count + FROM tmp.parent; + + IF v_count = 0 THEN + LEAVE l; + END IF; + END LOOP; + + DROP TEMPORARY TABLE + tmp.parent, + tmp.child; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_scan_ident.sql b/db/routines/vn2008/procedures/unary_scan_ident.sql new file mode 100644 index 000000000..5c62e93e7 --- /dev/null +++ b/db/routines/vn2008/procedures/unary_scan_ident.sql @@ -0,0 +1,25 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_scan_ident`(v_top INT, v_space INT) +BEGIN +/** + * A partir de un nodo devuelve el id y el nombre del nodod y sus hijos. + * El nombre viene identado segun el numero de espacios multiplicado por la profundiad del nodo. + * + * v_top: Id del nodo padre. + * v_space: Spacios a dejar al identar, + * @table tmp.tree_ident Tabla con los ids de los nodos descendientes y su nombre identado; + **/ + + DROP TEMPORARY TABLE IF EXISTS tmp.tree_ident; + CALL tree_leaves(v_top); + + CREATE TEMPORARY TABLE tmp.tree_ident + ENGINE = MEMORY + SELECT t.id, + CONCAT( REPEAT(REPEAT(" ",v_space), t.depth), sp.name) AS name + FROM tmp.tree t + INNER JOIN unary_scan sp + ON t.id = sp.id; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_scan_insert.sql b/db/routines/vn2008/procedures/unary_scan_insert.sql new file mode 100644 index 000000000..0ac2c7b1e --- /dev/null +++ b/db/routines/vn2008/procedures/unary_scan_insert.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_scan_insert`(v_name VARCHAR(45), v_parent INT, v_type VARCHAR(45)) +BEGIN + + /** + * Inserta un nuevo nodo de tipo unary_scan. Se puede indicar el padre. + * + * @v_name: Nombre del nodo. + * @v_parent: Nodo padre. + * @v_type: Tipo del nodo a crear. + **/ + + DECLARE v_unary INT; + + CALL unary_insert(v_unary, v_parent); + + INSERT INTO unary_scan(name, unary_id, type) VALUES(v_name, v_unary, v_type); + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_tops.sql b/db/routines/vn2008/procedures/unary_tops.sql new file mode 100644 index 000000000..b3a7cf11d --- /dev/null +++ b/db/routines/vn2008/procedures/unary_tops.sql @@ -0,0 +1,19 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_tops`() +BEGIN +/** + * Devuelve todos los nodos que no tienen padre. + * + * @table tmp.tree Tabla con los ids de los nodos que no tienen padre; + **/ + + DROP TEMPORARY TABLE IF EXISTS tmp.tree; + CREATE TEMPORARY TABLE tmp.tree + ENGINE = MEMORY + SELECT s.`unary_id` AS id, s.name, s.odbc_date, s.type + FROM `unary_scan` s + INNER JOIN `unary` u ON s.unary_id = u.id + WHERE u.parent IS NULL; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_update.sql b/db/routines/vn2008/procedures/unary_update.sql new file mode 100644 index 000000000..8bb366810 --- /dev/null +++ b/db/routines/vn2008/procedures/unary_update.sql @@ -0,0 +1,32 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_update`(v_node INT, v_new_parent INT, v_move bool) +BEGIN +/** + * Cambia el padre de un nodo. Se puede indicar si se quieren mover los hijos. + * En este caso los hijos pasan al padre del nodo. + * Si no tiene padre, los hijos pasaran a ser padres. + * + * @v_node: Nodo que se quiere mover. + * @v_new_parent: Padre al que se quiere mover el nodo. + * @v_move: Se indica si se mueven los nodos. + **/ + + DECLARE v_parent INT; + + SELECT parent + INTO v_parent + FROM unary + WHERE id = v_node; + + IF(v_move = TRUE) THEN + UPDATE unary + SET parent = v_parent + WHERE parent = v_node; + END IF; + + UPDATE unary + SET parent = v_new_parent + WHERE id = v_node; + +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/triggers/Conteo_ai.sql b/db/routines/vn2008/triggers/Conteo_ai.sql new file mode 100644 index 000000000..5d8a0ef25 --- /dev/null +++ b/db/routines/vn2008/triggers/Conteo_ai.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`Conteo_ai` + AFTER INSERT ON `Conteo` + FOR EACH ROW +BEGIN + DECLARE intTravel INTEGER; + SELECT t.id INTO intTravel FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE landing = util.VN_CURDATE() AND c.Id_Article = NEW.Id_Article AND warehouse_id = NEW.warehouse_id AND received <> TRUE LIMIT 1; + IF (intTravel) then + UPDATE travel SET received = TRUE WHERE id = intTravel; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql b/db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql new file mode 100644 index 000000000..01c8af36e --- /dev/null +++ b/db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql @@ -0,0 +1,14 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`account_conciliacion_BEFORE_INSERT` + BEFORE INSERT ON `account_conciliacion` + FOR EACH ROW +set new.id_calculated = replace( + replace( + replace( + replace( + concat(new.Id_Proveedores_account,new.Fechaoperacion,new.importe,new.Concepto,new.DebeHaber) + ,' ','') + ,":",'') + ,'-','') + ,'.','')$$ +DELIMITER ; diff --git a/db/routines/vn2008/triggers/agency_hourBeforeInsert.sql b/db/routines/vn2008/triggers/agency_hourBeforeInsert.sql new file mode 100644 index 000000000..f4ea375c5 --- /dev/null +++ b/db/routines/vn2008/triggers/agency_hourBeforeInsert.sql @@ -0,0 +1,21 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hourBeforeInsert` + BEFORE INSERT ON `agency_hour` + FOR EACH ROW +BEGIN + DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + IF NEW.week_day IS NULL AND NEW.province_id IS NULL AND NEW.subtract_day = 0 AND NEW.max_hour = 0 THEN + CALL util.throw ('FILL_MORE_FIELDS'); + END IF; + + SELECT COUNT(*) INTO vAlreadyExists + FROM vn2008.agency_hour + WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id + AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour + AND NEW.agency_id <=> agency_id; + + IF vAlreadyExists > 1 THEN + CALL util.throw('ALREADY_EXISTS'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql b/db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql new file mode 100644 index 000000000..fb958c165 --- /dev/null +++ b/db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql @@ -0,0 +1,18 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hour_AFTER_UPDATE` + AFTER UPDATE ON `agency_hour` + FOR EACH ROW +BEGIN +DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + + SELECT COUNT(*) INTO vAlreadyExists + FROM vn2008.agency_hour + WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id + AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour + AND NEW.agency_id <=> agency_id; + + IF vAlreadyExists > 1 THEN + CALL util.throw('ALREADY_EXISTS'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn2008/triggers/awb_recibida_ad.sql b/db/routines/vn2008/triggers/awb_recibida_ad.sql new file mode 100644 index 000000000..e33d7fd3c --- /dev/null +++ b/db/routines/vn2008/triggers/awb_recibida_ad.sql @@ -0,0 +1,13 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`awb_recibida_ad` + AFTER DELETE ON `awb_recibida` + FOR EACH ROW +IF (SELECT COUNT(*) FROM recibida_iva where recibida_id = OLD.recibida_id) = 0 + AND + (SELECT COUNT(*) FROM recibida_vencimiento where recibida_id = OLD.recibida_id) = 0 + AND + (SELECT contabilizada FROM recibida WHERE id = OLD.recibida_id) = 0 +THEN + DELETE FROM recibida WHERE id = OLD.recibida_id; +END IF$$ +DELIMITER ; diff --git a/db/routines/vn2008/triggers/movement_label_au.sql b/db/routines/vn2008/triggers/movement_label_au.sql new file mode 100644 index 000000000..5f9561e15 --- /dev/null +++ b/db/routines/vn2008/triggers/movement_label_au.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`movement_label_au` + AFTER UPDATE ON `movement_label` + FOR EACH ROW +IF NEW.stem >= (SELECT Cantidad FROM Movimientos WHERE Id_Movimiento = NEW.Id_Movimiento) THEN + UPDATE Movimientos SET OK = 1 WHERE Id_Movimiento = NEW.Id_Movimiento; +END IF$$ +DELIMITER ; diff --git a/db/routines/vn2008/views/Agencias.sql b/db/routines/vn2008/views/Agencias.sql new file mode 100644 index 000000000..d70ec73f4 --- /dev/null +++ b/db/routines/vn2008/views/Agencias.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Agencias` +AS SELECT `am`.`id` AS `Id_Agencia`, + `am`.`name` AS `Agencia`, + `am`.`description` AS `description`, + `am`.`deliveryMethodFk` AS `Vista`, + `am`.`m3` AS `m3`, + `am`.`web` AS `web`, + `am`.`agencyFk` AS `agency_id`, + `am`.`inflation` AS `inflacion`, + `am`.`isVolumetric` AS `is_volumetric`, + `am`.`reportMail` AS `send_mail`, + `am`.`isActive` AS `tpv`, + `am`.`code` AS `code`, + `am`.`showAgencyName` AS `show_AgencyName`, + `am`.`isRiskFree` AS `isRiskFree` +FROM `vn`.`agencyMode` `am` diff --git a/db/routines/vn2008/views/Articles.sql b/db/routines/vn2008/views/Articles.sql new file mode 100644 index 000000000..385bf310b --- /dev/null +++ b/db/routines/vn2008/views/Articles.sql @@ -0,0 +1,52 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Articles` +AS SELECT `i`.`id` AS `Id_Article`, + `i`.`name` AS `Article`, + `i`.`typeFk` AS `tipo_id`, + `i`.`size` AS `Medida`, + `i`.`inkFk` AS `Color`, + `i`.`category` AS `Categoria`, + `i`.`stems` AS `Tallos`, + `i`.`originFk` AS `id_origen`, + `i`.`description` AS `description`, + `i`.`producerFk` AS `producer_id`, + `i`.`intrastatFk` AS `Codintrastat`, + `i`.`box` AS `caja`, + `i`.`expenseFk` AS `expenseFk`, + `i`.`comment` AS `comments`, + `i`.`relevancy` AS `relevancy`, + `i`.`image` AS `Foto`, + `i`.`generic` AS `generic`, + `i`.`density` AS `density`, + `i`.`minPrice` AS `PVP`, + `i`.`hasMinPrice` AS `Min`, + `i`.`isActive` AS `isActive`, + `i`.`longName` AS `longName`, + `i`.`subName` AS `subName`, + `i`.`tag5` AS `tag5`, + `i`.`value5` AS `value5`, + `i`.`tag6` AS `tag6`, + `i`.`value6` AS `value6`, + `i`.`tag7` AS `tag7`, + `i`.`value7` AS `value7`, + `i`.`tag8` AS `tag8`, + `i`.`value8` AS `value8`, + `i`.`tag9` AS `tag9`, + `i`.`value9` AS `value9`, + `i`.`tag10` AS `tag10`, + `i`.`value10` AS `value10`, + `i`.`minimum` AS `minimum`, + `i`.`upToDown` AS `upToDown`, + `i`.`hasKgPrice` AS `hasKgPrice`, + `i`.`equivalent` AS `Equivalente`, + `i`.`isToPrint` AS `Imprimir`, + `i`.`family` AS `Familia__`, + `i`.`doPhoto` AS `do_photo`, + `i`.`created` AS `odbc_date`, + `i`.`isFloramondo` AS `isFloramondo`, + `i`.`supplyResponseFk` AS `supplyResponseFk`, + `i`.`stemMultiplier` AS `stemMultiplier`, + `i`.`itemPackingTypeFk` AS `itemPackingTypeFk`, + `i`.`packingOut` AS `packingOut` +FROM `vn`.`item` `i` diff --git a/db/routines/vn2008/views/Articles_botanical.sql b/db/routines/vn2008/views/Articles_botanical.sql new file mode 100644 index 000000000..44edda655 --- /dev/null +++ b/db/routines/vn2008/views/Articles_botanical.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Articles_botanical` +AS SELECT `ab`.`itemFk` AS `Id_Article`, + `ab`.`genusFk` AS `genus_id`, + `ab`.`specieFk` AS `specie_id` +FROM `vn`.`itemBotanical` `ab` diff --git a/db/routines/vn2008/views/Bancos.sql b/db/routines/vn2008/views/Bancos.sql new file mode 100644 index 000000000..0c6f8d1bd --- /dev/null +++ b/db/routines/vn2008/views/Bancos.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Bancos` +AS SELECT `b`.`id` AS `Id_Banco`, + `b`.`bank` AS `Banco`, + `b`.`account` AS `Cuenta`, + `b`.`cash` AS `cash`, + `b`.`entityFk` AS `entity_id`, + `b`.`isActive` AS `activo`, + `b`.`currencyFk` AS `currencyFk` +FROM `vn`.`bank` `b` diff --git a/db/routines/vn2008/views/Cajas.sql b/db/routines/vn2008/views/Cajas.sql new file mode 100644 index 000000000..54b9ee189 --- /dev/null +++ b/db/routines/vn2008/views/Cajas.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Cajas` +AS SELECT `t`.`id` AS `Id_Caja`, + `t`.`dated` AS `Cajafecha`, + `t`.`serie` AS `Serie`, + `t`.`concept` AS `Concepto`, + `t`.`in` AS `Entrada`, + `t`.`out` AS `Salida`, + `t`.`bankFk` AS `Id_Banco`, + `t`.`companyFk` AS `empresa_id`, + `t`.`isAccountable` AS `Partida`, + `t`.`InForeignValue` AS `InForeignValue`, + `t`.`OutForeignValue` AS `OutForeignValue`, + `t`.`workerFk` AS `Id_Trabajador`, + `t`.`calculatedCode` AS `id_calculated`, + `t`.`number` AS `Numero`, + `t`.`isLinked` AS `linked`, + `t`.`created` AS `odbc_date`, + `t`.`isOk` AS `ok`, + `t`.`warehouseFk` AS `warehouse_id`, + `t`.`isConciliate` AS `conciliado`, + `t`.`supplierAccountFk` AS `Proveedores_account_Id` +FROM `vn`.`till` `t` diff --git a/db/routines/vn2008/views/Clientes.sql b/db/routines/vn2008/views/Clientes.sql new file mode 100644 index 000000000..12583915a --- /dev/null +++ b/db/routines/vn2008/views/Clientes.sql @@ -0,0 +1,49 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Clientes` +AS SELECT `c`.`id` AS `id_cliente`, + `c`.`name` AS `cliente`, + `c`.`fi` AS `if`, + `c`.`socialName` AS `razonSocial`, + `c`.`contact` AS `contacto`, + `c`.`street` AS `domicilio`, + `c`.`city` AS `poblacion`, + `c`.`postcode` AS `codPostal`, + `c`.`phone` AS `telefono`, + `c`.`mobile` AS `movil`, + `c`.`isRelevant` AS `real`, + `c`.`email` AS `e-mail`, + `c`.`iban` AS `iban`, + `c`.`dueDay` AS `vencimiento`, + `c`.`accountingAccount` AS `Cuenta`, + `c`.`isEqualizated` AS `RE`, + `c`.`provinceFk` AS `province_id`, + `c`.`hasToInvoice` AS `invoice`, + `c`.`credit` AS `credito`, + `c`.`countryFk` AS `Id_Pais`, + `c`.`isActive` AS `activo`, + `c`.`gestdocFk` AS `gestdoc_id`, + `c`.`quality` AS `calidad`, + `c`.`payMethodFk` AS `pay_met_id`, + `c`.`created` AS `created`, + `c`.`isToBeMailed` AS `mail`, + `c`.`contactChannelFk` AS `chanel_id`, + `c`.`hasSepaVnl` AS `sepaVnl`, + `c`.`hasCoreVnl` AS `coreVnl`, + `c`.`hasCoreVnh` AS `coreVnh`, + `c`.`hasLcr` AS `hasLcr`, + `c`.`defaultAddressFk` AS `default_address`, + `c`.`riskCalculated` AS `risk_calculated`, + `c`.`clientTypeFk` AS `clientes_tipo_id`, + `c`.`hasToInvoiceByAddress` AS `invoiceByAddress`, + `c`.`isTaxDataChecked` AS `contabilizado`, + `c`.`isFreezed` AS `congelado`, + `c`.`creditInsurance` AS `creditInsurance`, + `c`.`isCreatedAsServed` AS `isCreatedAsServed`, + `c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified`, + `c`.`salesPersonFk` AS `Id_Trabajador`, + `c`.`isVies` AS `vies`, + `c`.`eypbc` AS `EYPBC`, + `c`.`bankEntityFk` AS `bankEntityFk`, + `c`.`typeFk` AS `typeFk` +FROM `vn`.`client` `c` diff --git a/db/routines/vn2008/views/Comparativa.sql b/db/routines/vn2008/views/Comparativa.sql new file mode 100644 index 000000000..875a5c370 --- /dev/null +++ b/db/routines/vn2008/views/Comparativa.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Comparativa` +AS SELECT `c`.`timePeriod` AS `Periodo`, + `c`.`itemFk` AS `Id_Article`, + `c`.`warehouseFk` AS `warehouse_id`, + `c`.`quantity` AS `Cantidad`, + `c`.`price` AS `price`, + `c`.`countryFk` AS `countryFk` +FROM `vn`.`comparative` `c` diff --git a/db/routines/vn2008/views/Compres.sql b/db/routines/vn2008/views/Compres.sql new file mode 100644 index 000000000..557136192 --- /dev/null +++ b/db/routines/vn2008/views/Compres.sql @@ -0,0 +1,33 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Compres` +AS SELECT `c`.`id` AS `Id_Compra`, + `c`.`entryFk` AS `Id_Entrada`, + `c`.`itemFk` AS `Id_Article`, + `c`.`buyingValue` AS `Costefijo`, + `c`.`quantity` AS `Cantidad`, + `c`.`packagingFk` AS `Id_Cubo`, + `c`.`stickers` AS `Etiquetas`, + `c`.`freightValue` AS `Portefijo`, + `c`.`packageValue` AS `Embalajefijo`, + `c`.`comissionValue` AS `Comisionfija`, + `c`.`packing` AS `Packing`, + `c`.`grouping` AS `grouping`, + `c`.`groupingMode` AS `caja`, + `c`.`location` AS `Nicho`, + `c`.`price1` AS `Tarifa1`, + `c`.`price2` AS `Tarifa2`, + `c`.`price3` AS `Tarifa3`, + `c`.`minPrice` AS `PVP`, + `c`.`printedStickers` AS `Vida`, + `c`.`isChecked` AS `punteo`, + `c`.`ektFk` AS `buy_edi_id`, + `c`.`created` AS `odbc_date`, + `c`.`isIgnored` AS `Novincular`, + `c`.`isPickedOff` AS `isPickedOff`, + `c`.`workerFk` AS `Id_Trabajador`, + `c`.`weight` AS `weight`, + `c`.`dispatched` AS `dispatched`, + `c`.`containerFk` AS `container_id`, + `c`.`itemOriginalFk` AS `itemOriginalFk` +FROM `vn`.`buy` `c` diff --git a/db/routines/vn2008/views/Compres_mark.sql b/db/routines/vn2008/views/Compres_mark.sql new file mode 100644 index 000000000..7138c4e4c --- /dev/null +++ b/db/routines/vn2008/views/Compres_mark.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Compres_mark` +AS SELECT `bm`.`id` AS `Id_Compra`, + `bm`.`comment` AS `comment`, + `bm`.`mark` AS `mark`, + `bm`.`odbcDate` AS `odbc_date` +FROM `vn`.`buyMark` `bm` diff --git a/db/routines/vn2008/views/Consignatarios.sql b/db/routines/vn2008/views/Consignatarios.sql new file mode 100644 index 000000000..13a426f4d --- /dev/null +++ b/db/routines/vn2008/views/Consignatarios.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Consignatarios` +AS SELECT `a`.`id` AS `id_consigna`, + `a`.`clientFk` AS `Id_cliente`, + `a`.`street` AS `domicilio`, + `a`.`city` AS `poblacion`, + `a`.`postalCode` AS `codPostal`, + `a`.`provinceFk` AS `province_id`, + `a`.`phone` AS `telefono`, + `a`.`mobile` AS `movil`, + `a`.`nickname` AS `consignatario`, + `a`.`isDefaultAddress` AS `predeterminada`, + `a`.`longitude` AS `longitude`, + `a`.`latitude` AS `latitude`, + `a`.`agencyModeFk` AS `Id_Agencia`, + `a`.`isEqualizated` AS `isEqualizated`, + `a`.`isActive` AS `active` +FROM `vn`.`address` `a` diff --git a/db/routines/vn2008/views/Cubos.sql b/db/routines/vn2008/views/Cubos.sql new file mode 100644 index 000000000..4ece9c435 --- /dev/null +++ b/db/routines/vn2008/views/Cubos.sql @@ -0,0 +1,21 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Cubos` +AS SELECT `p`.`id` AS `Id_Cubo`, + `p`.`volume` AS `Volumen`, + `p`.`width` AS `X`, + `p`.`depth` AS `Y`, + `p`.`height` AS `Z`, + `p`.`isPackageReturnable` AS `Retornable`, + `p`.`created` AS `odbc_date`, + `p`.`itemFk` AS `item_id`, + `p`.`price` AS `pvp`, + `p`.`cubicPackage` AS `bultoCubico`, + `p`.`value` AS `Valor`, + `p`.`packagingReturnFk` AS `idCubos_Retorno`, + `p`.`lower` AS `Bajan`, + `p`.`upload` AS `Suben`, + `p`.`base` AS `Base`, + `p`.`isBox` AS `box`, + `p`.`returnCost` AS `costeRetorno` +FROM `vn`.`packaging` `p` diff --git a/db/routines/vn2008/views/Cubos_Retorno.sql b/db/routines/vn2008/views/Cubos_Retorno.sql new file mode 100644 index 000000000..bc56f275b --- /dev/null +++ b/db/routines/vn2008/views/Cubos_Retorno.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Cubos_Retorno` +AS SELECT `rb`.`id` AS `idCubos_Retorno`, + `rb`.`freightContainerType` AS `Soporte`, + `rb`.`freightPackagingEmpty` AS `Vacio`, + `rb`.`freightPackagingFull` AS `Lleno` +FROM `vn`.`returnBuckets` `rb` diff --git a/db/routines/vn2008/views/Entradas.sql b/db/routines/vn2008/views/Entradas.sql new file mode 100644 index 000000000..63fbaa728 --- /dev/null +++ b/db/routines/vn2008/views/Entradas.sql @@ -0,0 +1,29 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Entradas` +AS SELECT `e`.`id` AS `Id_Entrada`, + `e`.`supplierFk` AS `Id_Proveedor`, + `e`.`invoiceNumber` AS `Referencia`, + `e`.`reference` AS `reference`, + `e`.`isExcludedFromAvailable` AS `Inventario`, + `e`.`isConfirmed` AS `Confirmada`, + `e`.`isOrdered` AS `Pedida`, + `e`.`isRaid` AS `Redada`, + `e`.`commission` AS `comision`, + `e`.`created` AS `odbc_date`, + `e`.`evaNotes` AS `Notas_Eva`, + `e`.`travelFk` AS `travel_id`, + `e`.`currencyFk` AS `Id_Moneda`, + `e`.`companyFk` AS `empresa_id`, + `e`.`gestDocFk` AS `gestdoc_id`, + `e`.`invoiceInFk` AS `recibida_id`, + `e`.`dated` AS `Fecha`, + `e`.`isBooked` AS `Anotadoencaja`, + `e`.`loadPriority` AS `loadPriority`, + `e`.`sub` AS `sub`, + `e`.`kop` AS `kop`, + `e`.`pro` AS `pro`, + `e`.`invoiceAmount` AS `invoiceAmount`, + `e`.`buyerFk` AS `buyerFk`, + `e`.`typeFk` AS `typeFk` +FROM `vn`.`entry` `e` diff --git a/db/routines/vn2008/views/Entradas_Auto.sql b/db/routines/vn2008/views/Entradas_Auto.sql new file mode 100644 index 000000000..5d1266965 --- /dev/null +++ b/db/routines/vn2008/views/Entradas_Auto.sql @@ -0,0 +1,5 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Entradas_Auto` +AS SELECT `ev`.`entryFk` AS `Id_Entrada` +FROM `vn`.`entryVirtual` `ev` diff --git a/db/routines/vn2008/views/Equipos.sql b/db/routines/vn2008/views/Equipos.sql new file mode 100644 index 000000000..fd1210237 --- /dev/null +++ b/db/routines/vn2008/views/Equipos.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Equipos` +AS SELECT `h`.`code` AS `alias`, + `h`.`description` AS `descripcion`, + `h`.`workerFk` AS `trabajador_id`, + `h`.`windowsSerial` AS `windowsSerial` +FROM `vn`.`host` `h` diff --git a/db/routines/vn2008/views/Facturas.sql b/db/routines/vn2008/views/Facturas.sql new file mode 100644 index 000000000..bc99c02d8 --- /dev/null +++ b/db/routines/vn2008/views/Facturas.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Facturas` +AS SELECT `io`.`id` AS `factura_id`, + `io`.`ref` AS `Id_Factura`, + `io`.`serial` AS `Serie`, + `io`.`issued` AS `Fecha`, + `io`.`amount` AS `Importe`, + `io`.`clientFk` AS `Id_Cliente`, + `io`.`created` AS `odbc_date`, + `io`.`companyFk` AS `empresa_id`, + `io`.`dued` AS `Vencimiento`, + `io`.`booked` AS `booked`, + `io`.`bankFk` AS `Id_Banco`, + `io`.`siiTypeInvoiceOutFk` AS `siiTypeInvoiceOutFk`, + `io`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`, + `io`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`, + `io`.`siiTrascendencyInvoiceOutFk` AS `siiTrascendencyInvoiceOutFk`, + `io`.`hasPdf` AS `pdf` +FROM `vn`.`invoiceOut` `io` diff --git a/db/routines/vn2008/views/Gastos.sql b/db/routines/vn2008/views/Gastos.sql new file mode 100644 index 000000000..2eee445d8 --- /dev/null +++ b/db/routines/vn2008/views/Gastos.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Gastos` +AS SELECT `e`.`id` AS `Id_Gasto`, + `e`.`name` AS `Gasto`, + `e`.`isWithheld` AS `isWithheld` +FROM `vn`.`expense` `e` diff --git a/db/routines/vn2008/views/Greuges.sql b/db/routines/vn2008/views/Greuges.sql new file mode 100644 index 000000000..8958ec455 --- /dev/null +++ b/db/routines/vn2008/views/Greuges.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Greuges` +AS SELECT `g`.`Id` AS `Id`, + `g`.`clientFk` AS `Id_Cliente`, + `g`.`description` AS `Comentario`, + `g`.`amount` AS `Importe`, + `g`.`shipped` AS `Fecha`, + `g`.`created` AS `odbc_date`, + `g`.`greugeTypeFk` AS `Greuges_type_id`, + `g`.`ticketFk` AS `Id_Ticket` +FROM `vn`.`greuge` `g` diff --git a/db/routines/vn2008/views/Greuges_type.sql b/db/routines/vn2008/views/Greuges_type.sql new file mode 100644 index 000000000..500a1cc03 --- /dev/null +++ b/db/routines/vn2008/views/Greuges_type.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Greuges_type` +AS SELECT `gt`.`id` AS `Greuges_type_id`, + `gt`.`name` AS `name` +FROM `vn`.`greugeType` `gt` diff --git a/db/routines/vn2008/views/Impresoras.sql b/db/routines/vn2008/views/Impresoras.sql new file mode 100644 index 000000000..c4782ab72 --- /dev/null +++ b/db/routines/vn2008/views/Impresoras.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Impresoras` +AS SELECT `vn`.`printer`.`id` AS `Id_impresora`, + `vn`.`printer`.`path` AS `Ruta`, + `vn`.`printer`.`name` AS `Impresora`, + `vn`.`printer`.`reference` AS `referencia`, + `vn`.`printer`.`isLabeler` AS `isLabeler` +FROM `vn`.`printer` diff --git a/db/routines/vn2008/views/Intrastat.sql b/db/routines/vn2008/views/Intrastat.sql new file mode 100644 index 000000000..9ed3ef283 --- /dev/null +++ b/db/routines/vn2008/views/Intrastat.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Intrastat` +AS SELECT `i`.`id` AS `Codintrastat`, + `i`.`description` AS `Definicion`, + `i`.`taxClassFk` AS `iva_group_id`, + `i`.`taxCodeFk` AS `iva_codigo_id` +FROM `vn`.`intrastat` `i` diff --git a/db/routines/vn2008/views/Monedas.sql b/db/routines/vn2008/views/Monedas.sql new file mode 100644 index 000000000..3693885be --- /dev/null +++ b/db/routines/vn2008/views/Monedas.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Monedas` +AS SELECT `c`.`id` AS `Id_Moneda`, + `c`.`code` AS `Moneda`, + `c`.`name` AS `Descripcion`, + `c`.`ratio` AS `Cambio` +FROM `vn`.`currency` `c` diff --git a/db/routines/vn2008/views/Movimientos.sql b/db/routines/vn2008/views/Movimientos.sql new file mode 100644 index 000000000..da41c51bb --- /dev/null +++ b/db/routines/vn2008/views/Movimientos.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Movimientos` +AS SELECT `m`.`id` AS `Id_Movimiento`, + `m`.`itemFk` AS `Id_Article`, + `m`.`ticketFk` AS `Id_Ticket`, + `m`.`concept` AS `Concepte`, + `m`.`quantity` AS `Cantidad`, + `m`.`price` AS `Preu`, + `m`.`discount` AS `Descuento`, + `m`.`reserved` AS `Reservado`, + `m`.`isPicked` AS `OK`, + `m`.`created` AS `odbc_date`, + `m`.`priceFixed` AS `CostFixat`, + `m`.`isPriceFixed` AS `PrecioFijado`, + `m`.`originalQuantity` AS `quantity`, + `m`.`isAdded` AS `isAdded` +FROM `vn`.`sale` `m` diff --git a/db/routines/vn2008/views/Movimientos_componentes.sql b/db/routines/vn2008/views/Movimientos_componentes.sql new file mode 100644 index 000000000..440fbfb6a --- /dev/null +++ b/db/routines/vn2008/views/Movimientos_componentes.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Movimientos_componentes` +AS SELECT `sc`.`saleFk` AS `Id_Movimiento`, + `sc`.`componentFk` AS `Id_Componente`, + `sc`.`value` AS `Valor`, + `sc`.`created` AS `created`, + `sc`.`isGreuge` AS `greuge` +FROM `vn`.`saleComponent` `sc` diff --git a/db/routines/vn2008/views/Movimientos_mark.sql b/db/routines/vn2008/views/Movimientos_mark.sql new file mode 100644 index 000000000..10ef2fc08 --- /dev/null +++ b/db/routines/vn2008/views/Movimientos_mark.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Movimientos_mark` +AS SELECT `mm`.`saleFk` AS `Id_Movimiento`, + `mm`.`isChecked` AS `valor`, + `mm`.`created` AS `odbc_date`, + `mm`.`originalQuantity` AS `original_quantity`, + `mm`.`workerFk` AS `Id_Trabajador`, + `mm`.`id` AS `Id_Movimiento_mark`, + `mm`.`stateFk` AS `stateFk` +FROM `vn`.`saleTracking` `mm` diff --git a/db/routines/vn2008/views/Ordenes.sql b/db/routines/vn2008/views/Ordenes.sql new file mode 100644 index 000000000..46d9fd89b --- /dev/null +++ b/db/routines/vn2008/views/Ordenes.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Ordenes` +AS SELECT `tr`.`id` AS `Id_ORDEN`, + `tr`.`description` AS `ORDEN`, + `tr`.`requesterFk` AS `requesterFk`, + `tr`.`attenderFk` AS `attenderFk`, + `tr`.`quantity` AS `CANTIDAD`, + `tr`.`itemFk` AS `Id_ARTICLE`, + `tr`.`price` AS `PRECIOMAX`, + `tr`.`isOk` AS `isOk`, + `tr`.`saleFk` AS `Id_Movimiento`, + `tr`.`ticketFk` AS `ticketFk`, + `tr`.`response` AS `COMENTARIO`, + `tr`.`created` AS `odbc_date`, + `tr`.`ordered` AS `datORDEN`, + `tr`.`shipped` AS `datTICKET`, + `tr`.`salesPersonCode` AS `CodVENDEDOR`, + `tr`.`buyerCode` AS `CodCOMPRADOR`, + `tr`.`clientFk` AS `Id_CLIENTE`, + `tr`.`total` AS `TOTAL`, + `tr`.`buyed` AS `datCOMPRA` +FROM `vn`.`ticketRequest` `tr` diff --git a/db/routines/vn2008/views/Origen.sql b/db/routines/vn2008/views/Origen.sql new file mode 100644 index 000000000..5bb1d9b7f --- /dev/null +++ b/db/routines/vn2008/views/Origen.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Origen` +AS SELECT `o`.`id` AS `id`, + `o`.`code` AS `Abreviatura`, + `o`.`name` AS `Origen`, + `o`.`countryFk` AS `Id_Paises`, + `o`.`warehouseFk` AS `warehouse_id` +FROM `vn`.`origin` `o` diff --git a/db/routines/vn2008/views/Paises.sql b/db/routines/vn2008/views/Paises.sql new file mode 100644 index 000000000..ea7172dff --- /dev/null +++ b/db/routines/vn2008/views/Paises.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Paises` +AS SELECT `c`.`id` AS `Id`, + `c`.`country` AS `Pais`, + `c`.`CEE` AS `CEE`, + `c`.`isUeeMember` AS `isUeeMember`, + `c`.`code` AS `Codigo`, + `c`.`currencyFk` AS `Id_Moneda`, + `c`.`geoFk` AS `geoFk`, + `c`.`ibanLength` AS `ibanLength`, + `c`.`hasDailyInvoice` AS `hasDailyInvoice` +FROM `vn`.`country` `c` diff --git a/db/routines/vn2008/views/PreciosEspeciales.sql b/db/routines/vn2008/views/PreciosEspeciales.sql new file mode 100644 index 000000000..cea9f87fd --- /dev/null +++ b/db/routines/vn2008/views/PreciosEspeciales.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`PreciosEspeciales` +AS SELECT `sp`.`id` AS `Id_PrecioEspecial`, + `sp`.`clientFk` AS `Id_Cliente`, + `sp`.`itemFk` AS `Id_Article`, + `sp`.`value` AS `PrecioEspecial` +FROM `vn`.`specialPrice` `sp` diff --git a/db/routines/vn2008/views/Prioridades.sql b/db/routines/vn2008/views/Prioridades.sql new file mode 100644 index 000000000..7e89a538f --- /dev/null +++ b/db/routines/vn2008/views/Prioridades.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Prioridades` +AS SELECT `qp`.`id` AS `Id_Prioridad`, + `qp`.`priority` AS `Prioridad` +FROM `vn`.`queuePriority` `qp` diff --git a/db/routines/vn2008/views/Proveedores.sql b/db/routines/vn2008/views/Proveedores.sql new file mode 100644 index 000000000..0b7ee89f8 --- /dev/null +++ b/db/routines/vn2008/views/Proveedores.sql @@ -0,0 +1,35 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Proveedores` +AS SELECT `s`.`id` AS `Id_Proveedor`, + `s`.`name` AS `Proveedor`, + `s`.`account` AS `cuenta`, + `s`.`countryFk` AS `pais_id`, + `s`.`nif` AS `NIF`, + `s`.`isFarmer` AS `Agricola`, + `s`.`phone` AS `Telefono`, + `s`.`retAccount` AS `cuentaret`, + `s`.`commission` AS `ComisionProveedor`, + `s`.`created` AS `odbc_time`, + `s`.`postcodeFk` AS `postcode_id`, + `s`.`isActive` AS `active`, + `s`.`street` AS `Domicilio`, + `s`.`city` AS `Localidad`, + `s`.`provinceFk` AS `province_id`, + `s`.`postCode` AS `codpos`, + `s`.`payMethodFk` AS `pay_met_id`, + `s`.`payDemFk` AS `pay_dem_id`, + `s`.`nickname` AS `Alias`, + `s`.`isOfficial` AS `oficial`, + `s`.`workerFk` AS `workerFk`, + `s`.`payDay` AS `pay_day`, + `s`.`isSerious` AS `serious`, + `s`.`note` AS `notas`, + `s`.`taxTypeSageFk` AS `taxTypeSageFk`, + `s`.`withholdingSageFk` AS `withholdingSageFk`, + `s`.`isTrucker` AS `isTrucker`, + `s`.`transactionTypeSageFk` AS `transactionTypeSageFk`, + `s`.`supplierActivityFk` AS `supplierActivityFk`, + `s`.`healthRegister` AS `healthRegister`, + `s`.`isPayMethodChecked` AS `isPayMethodChecked` +FROM `vn`.`supplier` `s` diff --git a/db/routines/vn2008/views/Recibos.sql b/db/routines/vn2008/views/Recibos.sql new file mode 100644 index 000000000..93ec7bc6f --- /dev/null +++ b/db/routines/vn2008/views/Recibos.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Recibos` +AS SELECT `r`.`Id` AS `Id`, + `r`.`invoiceFk` AS `Id_Factura`, + `r`.`amountPaid` AS `Entregado`, + `r`.`payed` AS `Fechacobro`, + `r`.`workerFk` AS `Id_Trabajador`, + `r`.`bankFk` AS `Id_Banco`, + `r`.`clientFk` AS `Id_Cliente`, + `r`.`created` AS `odbc_date`, + `r`.`companyFk` AS `empresa_id`, + `r`.`isConciliate` AS `conciliado` +FROM `vn`.`receipt` `r` diff --git a/db/routines/vn2008/views/Rutas.sql b/db/routines/vn2008/views/Rutas.sql new file mode 100644 index 000000000..78b3bb471 --- /dev/null +++ b/db/routines/vn2008/views/Rutas.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Rutas` +AS SELECT `r`.`id` AS `Id_Ruta`, + `r`.`workerFk` AS `Id_Trabajador`, + `r`.`created` AS `Fecha`, + `r`.`vehicleFk` AS `Id_Vehiculo`, + `r`.`agencyModeFk` AS `Id_Agencia`, + `r`.`time` AS `Hora`, + `r`.`isOk` AS `ok`, + `r`.`kmStart` AS `km_start`, + `r`.`kmEnd` AS `km_end`, + `r`.`started` AS `date_start`, + `r`.`finished` AS `date_end`, + `r`.`gestdocFk` AS `gestdoc_id`, + `r`.`cost` AS `cost`, + `r`.`m3` AS `m3`, + `r`.`description` AS `description` +FROM `vn`.`route` `r` diff --git a/db/routines/vn2008/views/Rutas_Master b/db/routines/vn2008/views/Rutas_Master new file mode 100644 index 000000000..03b9cfc21 --- /dev/null +++ b/db/routines/vn2008/views/Rutas_Master @@ -0,0 +1,24 @@ + +CREATE OR REPLACE DEFINER = `root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Rutas_Master` +AS SELECT + `rm`.`id` AS `id`, + `rm`.`warehoseFk` AS `warehouse_id`, + `rm`.`km` AS `km`, + `rm`.`packages` AS `bultos`, + `rm`.`vehicleCost` AS `vehiculos_coste`, + `rm`.`staffCost` AS `personal_coste`, + `rm`.`vehicle` AS `vehiculos_numero`, + `rm`.`staff` AS `personal_numero`, + `rm`.`fuel` AS `gasoil`, + `rm`.`freelancers` AS `autonomos`, + `rm`.`year` AS `año`, + `rm`.`mounth` AS `mes`, + `rm`.`expense` AS `gastos`, + `rm`.`freelancersPackages` AS `bultos_autonomos`, + `rm`.`kmCost` AS `coste_km`, + `rm`.`packageCost` AS `coste_bulto`, + `rm`.`freelancerPackageCost` AS `coste_bulto_autonomo` , + `rm`.`created` AS `odbc_date` + FROM `vn`.`routeMaster` `rm` \ No newline at end of file diff --git a/db/routines/vn2008/views/Rutas_Master.sql b/db/routines/vn2008/views/Rutas_Master.sql new file mode 100644 index 000000000..cdc2bedef --- /dev/null +++ b/db/routines/vn2008/views/Rutas_Master.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Rutas_Master` +AS SELECT `rm`.`id` AS `id`, + `rm`.`warehouseFk` AS `warehouse_id`, + `rm`.`km` AS `km`, + `rm`.`packages` AS `bultos`, + `rm`.`vehicleCost` AS `vehiculos_coste`, + `rm`.`staffCost` AS `personal_coste`, + `rm`.`vehicle` AS `vehiculos_numero`, + `rm`.`staff` AS `personal_numero`, + `rm`.`fuel` AS `gasoil`, + `rm`.`freelancers` AS `autonomos`, + `rm`.`year` AS `año`, + `rm`.`month` AS `mes`, + `rm`.`expense` AS `gastos`, + `rm`.`freelancersPackages` AS `bultos_autonomos`, + `rm`.`kmCost` AS `coste_km`, + `rm`.`packageCost` AS `coste_bulto`, + `rm`.`freelancerPackageCost` AS `coste_bulto_autonomo`, + `rm`.`created` AS `odbc_date` +FROM `vn`.`routeMaster` `rm` diff --git a/db/routines/vn2008/views/Rutas_monitor.sql b/db/routines/vn2008/views/Rutas_monitor.sql new file mode 100644 index 000000000..bd6daab4c --- /dev/null +++ b/db/routines/vn2008/views/Rutas_monitor.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Rutas_monitor` +AS SELECT `vn`.`routesMonitor`.`routeFk` AS `Id_Ruta`, + `vn`.`routesMonitor`.`name` AS `name`, + `vn`.`routesMonitor`.`beachFk` AS `Ubicacion`, + `vn`.`routesMonitor`.`ticketPacked` AS `pedidosEncajados`, + `vn`.`routesMonitor`.`ticketFree` AS `pedidosLibres`, + `vn`.`routesMonitor`.`ticketProduction` AS `pedidosProduccion`, + `vn`.`routesMonitor`.`packages` AS `bultos`, + `vn`.`routesMonitor`.`note` AS `notas`, + `vn`.`routesMonitor`.`dated` AS `fecha`, + `vn`.`routesMonitor`.`dockFk` AS `dockFk`, + `vn`.`routesMonitor`.`m3` AS `m3`, + `vn`.`routesMonitor`.`priority` AS `priority`, + `vn`.`routesMonitor`.`etd` AS `etd`, + `vn`.`routesMonitor`.`expeditionTruckFk` AS `expeditionTruckFk` +FROM `vn`.`routesMonitor` diff --git a/db/routines/vn2008/views/Tickets.sql b/db/routines/vn2008/views/Tickets.sql new file mode 100644 index 000000000..c24b87b72 --- /dev/null +++ b/db/routines/vn2008/views/Tickets.sql @@ -0,0 +1,33 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Tickets` +AS SELECT `t`.`id` AS `Id_Ticket`, + `t`.`clientFk` AS `Id_Cliente`, + `t`.`warehouseFk` AS `warehouse_id`, + `t`.`shipped` AS `Fecha`, + `t`.`landed` AS `landing`, + `t`.`nickname` AS `Alias`, + `t`.`refFk` AS `Factura`, + `t`.`addressFk` AS `Id_Consigna`, + `t`.`location` AS `Localizacion`, + `t`.`solution` AS `Solucion`, + `t`.`routeFk` AS `Id_Ruta`, + `t`.`companyFk` AS `empresa_id`, + `t`.`agencyModeFk` AS `Id_Agencia`, + `t`.`priority` AS `Prioridad`, + `t`.`packages` AS `Bultos`, + `t`.`isDeleted` AS `isDeleted`, + `t`.`created` AS `odbc_date`, + `t`.`workerFk` AS `Id_Trabajador`, + `t`.`observations` AS `Observaciones`, + `t`.`isSigned` AS `Firmado`, + `t`.`isLabeled` AS `Etiquetasemitidas`, + `t`.`isPrinted` AS `PedidoImpreso`, + `t`.`hour` AS `Hora`, + `t`.`isBlocked` AS `blocked`, + `t`.`hasPriority` AS `priority`, + `t`.`isBoxed` AS `boxed`, + `t`.`zoneFk` AS `zoneFk`, + `t`.`totalWithVat` AS `totalWithVat`, + `t`.`totalWithoutVat` AS `totalWithoutVat` +FROM `vn`.`ticket` `t` diff --git a/db/routines/vn2008/views/Tickets_state.sql b/db/routines/vn2008/views/Tickets_state.sql new file mode 100644 index 000000000..be59a750f --- /dev/null +++ b/db/routines/vn2008/views/Tickets_state.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Tickets_state` +AS SELECT `t`.`ticketFk` AS `Id_Ticket`, + `t`.`ticketTrackingFk` AS `inter_id`, + `t`.`name` AS `state_name` +FROM `vn`.`ticketLastState` `t` diff --git a/db/routines/vn2008/views/Tickets_turno.sql b/db/routines/vn2008/views/Tickets_turno.sql new file mode 100644 index 000000000..28bc2d55f --- /dev/null +++ b/db/routines/vn2008/views/Tickets_turno.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Tickets_turno` +AS SELECT `tw`.`ticketFk` AS `Id_Ticket`, + `tw`.`weekDay` AS `weekDay` +FROM `vn`.`ticketWeekly` `tw` diff --git a/db/routines/vn2008/views/Tintas.sql b/db/routines/vn2008/views/Tintas.sql new file mode 100644 index 000000000..2299aa759 --- /dev/null +++ b/db/routines/vn2008/views/Tintas.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Tintas` +AS SELECT `i`.`id` AS `Id_Tinta`, + `i`.`name` AS `name`, + `i`.`picture` AS `Tinta`, + `i`.`showOrder` AS `Orden`, + `i`.`ball` AS `ball`, + `i`.`isCargex` AS `cargex`, + `i`.`hex` AS `colorHex` +FROM `vn`.`ink` `i` diff --git a/db/routines/vn2008/views/Tipos.sql b/db/routines/vn2008/views/Tipos.sql new file mode 100644 index 000000000..4cde954f1 --- /dev/null +++ b/db/routines/vn2008/views/Tipos.sql @@ -0,0 +1,22 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Tipos` +AS SELECT `it`.`id` AS `tipo_id`, + `it`.`code` AS `Id_Tipo`, + `it`.`name` AS `Tipo`, + `it`.`order` AS `Orden`, + `it`.`categoryFk` AS `reino_id`, + `it`.`workerFk` AS `Id_Trabajador`, + `it`.`life` AS `life`, + `it`.`isPackaging` AS `isPackaging`, + `it`.`density` AS `density`, + `it`.`isInventory` AS `inventory`, + `it`.`created` AS `odbc_date`, + `it`.`making` AS `confeccion`, + `it`.`temperatureFk` AS `Temperatura`, + `it`.`promo` AS `promo`, + `it`.`maneuver` AS `maneuver`, + `it`.`target` AS `target`, + `it`.`topMargin` AS `top_margin`, + `it`.`profit` AS `profit` +FROM `vn`.`itemType` `it` diff --git a/db/routines/vn2008/views/Trabajadores.sql b/db/routines/vn2008/views/Trabajadores.sql new file mode 100644 index 000000000..72b53e54e --- /dev/null +++ b/db/routines/vn2008/views/Trabajadores.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Trabajadores` +AS SELECT `w`.`id` AS `Id_Trabajador`, + `w`.`firstName` AS `Nombre`, + `w`.`id` AS `user_id`, + `w`.`phone` AS `phone`, + `w`.`bossFk` AS `boss`, + NULL AS `Foto`, + `w`.`fiDueDate` AS `DniExpiration`, + `w`.`code` AS `CodigoTrabajador`, + `w`.`lastName` AS `Apellidos`, + `w`.`hasMachineryAuthorized` AS `hasMachineryAuthorized`, + `w`.`sub` AS `sub`, + `w`.`maritalStatus` AS `marital_status` +FROM `vn`.`worker` `w` diff --git a/db/routines/vn2008/views/V_edi_item_track.sql b/db/routines/vn2008/views/V_edi_item_track.sql new file mode 100644 index 000000000..64cfdc1c5 --- /dev/null +++ b/db/routines/vn2008/views/V_edi_item_track.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`V_edi_item_track` +AS SELECT `edi`.`item_track`.`item_id` AS `item_id`, + `edi`.`item_track`.`s1` AS `s1`, + `edi`.`item_track`.`s2` AS `s2`, + `edi`.`item_track`.`s3` AS `s3`, + `edi`.`item_track`.`s4` AS `s4`, + `edi`.`item_track`.`s5` AS `s5`, + `edi`.`item_track`.`s6` AS `s6`, + `edi`.`item_track`.`kop` AS `kop`, + `edi`.`item_track`.`pac` AS `pac`, + `edi`.`item_track`.`cat` AS `cat`, + `edi`.`item_track`.`ori` AS `ori`, + `edi`.`item_track`.`pro` AS `pro`, + `edi`.`item_track`.`sub` AS `sub`, + `edi`.`item_track`.`package` AS `package`, + `edi`.`item_track`.`item` AS `item` +FROM `edi`.`item_track` diff --git a/db/routines/vn2008/views/Vehiculos.sql b/db/routines/vn2008/views/Vehiculos.sql new file mode 100644 index 000000000..477ff657c --- /dev/null +++ b/db/routines/vn2008/views/Vehiculos.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Vehiculos` +AS SELECT `v`.`id` AS `Id_Vehiculo`, + `v`.`numberPlate` AS `Matricula`, + `v`.`tradeMark` AS `Marca`, + `v`.`model` AS `Modelo`, + `v`.`companyFk` AS `empresa_id`, + `v`.`warehouseFk` AS `warehouseFk`, + `v`.`description` AS `description`, + `v`.`m3` AS `m3`, + `v`.`isActive` AS `active`, + `v`.`deliveryPointFk` AS `deliveryPointFk` +FROM `vn`.`vehicle` `v` diff --git a/db/routines/vn2008/views/VerEspionaje.sql b/db/routines/vn2008/views/VerEspionaje.sql new file mode 100644 index 000000000..d32687b23 --- /dev/null +++ b/db/routines/vn2008/views/VerEspionaje.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`VerEspionaje` +AS SELECT `Trabajadores`.`CodigoTrabajador` AS `CodigoTrabajador`, + `vn2008`.`Espionajes`.`Fecha` AS `Fecha`, + `vn2008`.`Espionajes`.`HoraEntrada` AS `HoraEntrada`, + `vn2008`.`Espionajes`.`HoraSalida` AS `HoraSalida`, + `vn2008`.`Espionajes`.`Id_Equipo` AS `Id_Equipo`, + `Trabajadores`.`Id_Trabajador` AS `Id_Trabajador` +FROM ( + `vn2008`.`Espionajes` + JOIN `vn2008`.`Trabajadores` ON( + `vn2008`.`Espionajes`.`Id_Trabajador` = `Trabajadores`.`Id_Trabajador` + ) + ) +ORDER BY `Trabajadores`.`CodigoTrabajador`, + `vn2008`.`Espionajes`.`Fecha` diff --git a/db/routines/vn2008/views/Vistas.sql b/db/routines/vn2008/views/Vistas.sql new file mode 100644 index 000000000..4bff8fd11 --- /dev/null +++ b/db/routines/vn2008/views/Vistas.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Vistas` +AS SELECT `dm`.`id` AS `vista_id`, + `dm`.`code` AS `code`, + `dm`.`description` AS `vista` +FROM `vn`.`deliveryMethod` `dm` diff --git a/db/routines/vn2008/views/XDiario.sql b/db/routines/vn2008/views/XDiario.sql new file mode 100644 index 000000000..0a9672d2e --- /dev/null +++ b/db/routines/vn2008/views/XDiario.sql @@ -0,0 +1,56 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`XDiario` +AS SELECT `d`.`id` AS `id`, + `d`.`ASIEN` AS `ASIEN`, + `d`.`FECHA` AS `FECHA`, + `d`.`SUBCTA` AS `SUBCTA`, + `d`.`CONTRA` AS `CONTRA`, + `d`.`CONCEPTO` AS `CONCEPTO`, + `d`.`EURODEBE` AS `EURODEBE`, + `d`.`EUROHABER` AS `EUROHABER`, + `d`.`BASEEURO` AS `BASEEURO`, + `d`.`SERIE` AS `SERIE`, + `d`.`FACTURA` AS `FACTURA`, + `d`.`IVA` AS `IVA`, + `d`.`RECEQUIV` AS `RECEQUIV`, + `d`.`CLAVE` AS `CLAVE`, + `d`.`CAMBIO` AS `CAMBIO`, + `d`.`DEBEME` AS `DEBEME`, + `d`.`HABERME` AS `HABERME`, + `d`.`AUXILIAR` AS `AUXILIAR`, + `d`.`MONEDAUSO` AS `MONEDAUSO`, + `d`.`TIPOOPE` AS `TIPOOPE`, + `d`.`NFACTICK` AS `NFACTICK`, + `d`.`TERIDNIF` AS `TERIDNIF`, + `d`.`TERNIF` AS `TERNIF`, + `d`.`TERNOM` AS `TERNOM`, + `d`.`OPBIENES` AS `OPBIENES`, + `d`.`L340` AS `L340`, + `d`.`enlazado` AS `enlazado`, + `d`.`FECHA_EX` AS `FECHA_EX`, + `d`.`LRECT349` AS `LRECT349`, + `d`.`empresa_id` AS `empresa_id`, + `d`.`LDIFADUAN` AS `LDIFADUAN`, + `d`.`METAL` AS `METAL`, + `d`.`METALIMP` AS `METALIMP`, + `d`.`CLIENTE` AS `CLIENTE`, + `d`.`METALEJE` AS `METALEJE`, + `d`.`FECHA_OP` AS `FECHA_OP`, + `d`.`FACTURAEX` AS `FACTURAEX`, + `d`.`TIPOCLAVE` AS `TIPOCLAVE`, + `d`.`TIPOEXENCI` AS `TIPOEXENCI`, + `d`.`TIPONOSUJE` AS `TIPONOSUJE`, + `d`.`TIPOFACT` AS `TIPOFACT`, + `d`.`TIPORECTIF` AS `TIPORECTIF`, + `d`.`SERIE_RT` AS `SERIE_RT`, + `d`.`FACTU_RT` AS `FACTU_RT`, + `d`.`BASEIMP_RT` AS `BASEIMP_RT`, + `d`.`BASEIMP_RF` AS `BASEIMP_RF`, + `d`.`RECTIFICA` AS `RECTIFICA`, + `d`.`FECHA_RT` AS `FECHA_RT`, + `d`.`created` AS `created`, + `d`.`updated` AS `updated`, + `d`.`FECREGCON` AS `FECREGCON`, + `d`.`enlazadoSage` AS `enlazadoSage` +FROM `vn`.`XDiario` `d` diff --git a/db/routines/vn2008/views/agency.sql b/db/routines/vn2008/views/agency.sql new file mode 100644 index 000000000..819fbd009 --- /dev/null +++ b/db/routines/vn2008/views/agency.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`agency` +AS SELECT `a`.`id` AS `agency_id`, + `a`.`name` AS `name`, + `a`.`warehouseFk` AS `warehouse_id`, + `a`.`warehouseAliasFk` AS `warehouse_alias_id`, + `a`.`isOwn` AS `propios`, + `a`.`workCenterFk` AS `workCenterFk` +FROM `vn`.`agency` `a` diff --git a/db/routines/vn2008/views/awb.sql b/db/routines/vn2008/views/awb.sql new file mode 100644 index 000000000..010596288 --- /dev/null +++ b/db/routines/vn2008/views/awb.sql @@ -0,0 +1,33 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`awb` +AS SELECT `a`.`id` AS `id`, + `a`.`code` AS `codigo`, + `a`.`package` AS `bultos`, + `a`.`weight` AS `peso`, + `a`.`created` AS `MYSQL_TIME`, + `a`.`transitoryFk` AS `transitario_id`, + `a`.`taxFk` AS `iva_id`, + `a`.`duakk` AS `duakk`, + `a`.`docFk` AS `gestdoc_id`, + `a`.`amount` AS `importe`, + `a`.`freightFk` AS `carguera_id`, + `a`.`m3` AS `m3`, + `a`.`stems` AS `stems`, + `a`.`flightFk` AS `flight_id`, + `a`.`volumeWeight` AS `volume_weight`, + `a`.`hb` AS `hb`, + `a`.`rate` AS `rate`, + `a`.`booked` AS `booked`, + `a`.`issued` AS `issued`, + `a`.`operated` AS `operated`, + `a`.`bookEntried` AS `bookEntried`, + `a`.`invoiceInFk` AS `invoiceInFk`, + `a`.`isChecked` AS `isChecked`, + `a`.`isTransitoryChecked` AS `isTransitoryChecked`, + `a`.`year` AS `year`, + `a`.`invoiceInPaletizedFk` AS `invoiceInPaletizedFk`, + `a`.`observation` AS `observation`, + `a`.`hasFreightPrepaid` AS `hasFreightPrepaid`, + `a`.`propertyNumber` AS `propertyNumber` +FROM `vn`.`awb` `a` diff --git a/db/routines/vn2008/views/barcodes.sql b/db/routines/vn2008/views/barcodes.sql new file mode 100644 index 000000000..f366e15fa --- /dev/null +++ b/db/routines/vn2008/views/barcodes.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`barcodes` +AS SELECT `b`.`id` AS `id`, + `b`.`itemFk` AS `Id_Article`, + `b`.`code` AS `code` +FROM `vn`.`itemBarcode` `b` diff --git a/db/routines/vn2008/views/bionic_updating_options.sql b/db/routines/vn2008/views/bionic_updating_options.sql new file mode 100644 index 000000000..7ee531238 --- /dev/null +++ b/db/routines/vn2008/views/bionic_updating_options.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`bionic_updating_options` +AS SELECT `t`.`id` AS `buo_id`, + `t`.`description` AS `description` +FROM `vn`.`ticketUpdateAction` `t` diff --git a/db/routines/vn2008/views/businessReasonEnd.sql b/db/routines/vn2008/views/businessReasonEnd.sql new file mode 100644 index 000000000..459a33a8b --- /dev/null +++ b/db/routines/vn2008/views/businessReasonEnd.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`businessReasonEnd` +AS SELECT `b`.`id` AS `id`, + `b`.`reason` AS `reason` +FROM `vn`.`businessReasonEnd` `b` diff --git a/db/routines/vn2008/views/buySource.sql b/db/routines/vn2008/views/buySource.sql new file mode 100644 index 000000000..33226a1dc --- /dev/null +++ b/db/routines/vn2008/views/buySource.sql @@ -0,0 +1,77 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`buySource` +AS SELECT `b`.`entryFk` AS `Id_Entrada`, + `b`.`isPickedOff` AS `isPickedOff`, + NULL AS `tarifa0`, + `e`.`kop` AS `kop`, + `b`.`id` AS `Id_Compra`, + `i`.`typeFk` AS `tipo_id`, + `b`.`itemFk` AS `Id_Article`, + `i`.`size` AS `Medida`, + `i`.`stems` AS `Tallos`, + `b`.`stickers` AS `Etiquetas`, + `b`.`packagingFk` AS `Id_Cubo`, + `b`.`buyingValue` AS `Costefijo`, + `b`.`packing` AS `Packing`, + `b`.`grouping` AS `Grouping`, + `b`.`quantity` AS `Cantidad`, + `b`.`price2` AS `Tarifa2`, + `b`.`price3` AS `Tarifa3`, + `b`.`isChecked` AS `Punteo`, + `b`.`groupingMode` AS `Caja`, + `i`.`isToPrint` AS `Imprimir`, + `i`.`name` AS `Article`, + `vn`.`ink`.`picture` AS `Tinta`, + `i`.`originFk` AS `id_origen`, + `i`.`minPrice` AS `PVP`, + NULL AS `Id_Accion`, + `s`.`company_name` AS `pro`, + `i`.`hasMinPrice` AS `Min`, + `b`.`isIgnored` AS `Novincular`, + `b`.`freightValue` AS `Portefijo`, + round(`b`.`buyingValue` * `b`.`quantity`, 2) AS `Importe`, + `b`.`printedStickers` AS `Vida`, + `i`.`comment` AS `reference`, + `b`.`workerFk` AS `Id_Trabajador`, + `e`.`s1` AS `S1`, + `e`.`s2` AS `S2`, + `e`.`s3` AS `S3`, + `e`.`s4` AS `S4`, + `e`.`s5` AS `S5`, + `e`.`s6` AS `S6`, + 0 AS `price_fixed`, + `i`.`producerFk` AS `producer_id`, + `i`.`subName` AS `tag1`, + `i`.`value5` AS `tag2`, + `i`.`value6` AS `tag3`, + `i`.`value7` AS `tag4`, + `i`.`value8` AS `tag5`, + `i`.`value9` AS `tag6`, + `i`.`value10` AS `tag7`, + `s`.`company_name` AS `company_name`, + `b`.`weight` AS `weightPacking`, + `i`.`packingOut` AS `packingOut`, + `b`.`itemOriginalFk` AS `itemOriginalFk`, + `io`.`longName` AS `itemOriginalName`, + `it`.`gramsMax` AS `gramsMax`, + `i`.`minQuantity` AS `minQuantity` +FROM ( + ( + ( + ( + ( + ( + `vn`.`item` `i` + JOIN `vn`.`itemType` `it` ON(`it`.`id` = `i`.`typeFk`) + ) + LEFT JOIN `vn`.`ink` ON(`vn`.`ink`.`id` = `i`.`inkFk`) + ) + LEFT JOIN `vn`.`buy` `b` ON(`b`.`itemFk` = `i`.`id`) + ) + LEFT JOIN `vn`.`item` `io` ON(`io`.`id` = `b`.`itemOriginalFk`) + ) + LEFT JOIN `edi`.`ekt` `e` ON(`e`.`id` = `b`.`ektFk`) + ) + LEFT JOIN `edi`.`supplier` `s` ON(`e`.`pro` = `s`.`supplier_id`) + ) diff --git a/db/routines/vn2008/views/buy_edi.sql b/db/routines/vn2008/views/buy_edi.sql new file mode 100644 index 000000000..0d194c89e --- /dev/null +++ b/db/routines/vn2008/views/buy_edi.sql @@ -0,0 +1,41 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`buy_edi` +AS SELECT `t`.`id` AS `id`, + `t`.`barcode` AS `barcode`, + `t`.`entryYear` AS `entry_year`, + `t`.`deliveryNumber` AS `delivery_number`, + `t`.`fec` AS `fec`, + `t`.`hor` AS `hor`, + `t`.`now` AS `now`, + `t`.`ptj` AS `ptj`, + `t`.`ref` AS `ref`, + `t`.`item` AS `item`, + `t`.`pac` AS `pac`, + `t`.`qty` AS `qty`, + `t`.`ori` AS `ori`, + `t`.`cat` AS `cat`, + `t`.`agj` AS `agj`, + `t`.`kop` AS `kop`, + `t`.`ptd` AS `ptd`, + `t`.`sub` AS `sub`, + `t`.`pro` AS `pro`, + `t`.`pri` AS `pri`, + `t`.`package` AS `package`, + `t`.`auction` AS `auction`, + `t`.`klo` AS `klo`, + `t`.`k1` AS `k01`, + `t`.`k2` AS `k02`, + `t`.`k3` AS `k03`, + `t`.`k4` AS `k04`, + `t`.`s1` AS `s1`, + `t`.`s2` AS `s2`, + `t`.`s3` AS `s3`, + `t`.`s4` AS `s4`, + `t`.`s5` AS `s5`, + `t`.`s6` AS `s6`, + `t`.`ok` AS `ok`, + `t`.`trolleyFk` AS `trolley_id`, + `t`.`putOrderFk` AS `putOrderFk`, + `t`.`scanned` AS `scanned` +FROM `edi`.`ekt` `t` diff --git a/db/routines/vn2008/views/cdr.sql b/db/routines/vn2008/views/cdr.sql new file mode 100644 index 000000000..9d0d2f172 --- /dev/null +++ b/db/routines/vn2008/views/cdr.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cdr` +AS SELECT `c`.`call_date` AS `calldate`, + `c`.`clid` AS `clid`, + `c`.`src` AS `src`, + `c`.`dst` AS `dst`, + `c`.`dcontext` AS `dcontext`, + `c`.`channel` AS `channel`, + `c`.`dst_channel` AS `dstchannel`, + `c`.`last_app` AS `lastapp`, + `c`.`last_data` AS `lastdata`, + `c`.`duration` AS `duration`, + `c`.`billsec` AS `billsec`, + `c`.`disposition` AS `disposition`, + `c`.`ama_flags` AS `amaflags`, + `c`.`account_code` AS `accountcode`, + `c`.`unique_id` AS `uniqueid`, + `c`.`user_field` AS `userfield` +FROM `pbx`.`cdr` `c` diff --git a/db/routines/vn2008/views/chanel.sql b/db/routines/vn2008/views/chanel.sql new file mode 100644 index 000000000..9d2ed0d9c --- /dev/null +++ b/db/routines/vn2008/views/chanel.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`chanel` +AS SELECT `c`.`id` AS `chanel_id`, + `c`.`name` AS `name` +FROM `vn`.`contactChannel` `c` diff --git a/db/routines/vn2008/views/cl_act.sql b/db/routines/vn2008/views/cl_act.sql new file mode 100644 index 000000000..a62ac3efe --- /dev/null +++ b/db/routines/vn2008/views/cl_act.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_act` +AS SELECT `c`.`id` AS `id`, + `c`.`saleFk` AS `Id_Movimiento`, + `c`.`claimFk` AS `cl_main_id`, + `c`.`workerFk` AS `Id_Trabajador`, + `c`.`claimDestinationFk` AS `cl_sol_id`, + `c`.`isGreuge` AS `greuge` +FROM `vn`.`claimEnd` `c` diff --git a/db/routines/vn2008/views/cl_cau.sql b/db/routines/vn2008/views/cl_cau.sql new file mode 100644 index 000000000..a835a94c9 --- /dev/null +++ b/db/routines/vn2008/views/cl_cau.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_cau` +AS SELECT `c`.`id` AS `id`, + `c`.`claimFk` AS `cl_main_id`, + `c`.`claimResponsibleFk` AS `cl_res_id`, + `c`.`workerFk` AS `Id_Trabajador`, + `c`.`claimReasonFk` AS `cl_mot_id`, + `c`.`claimResultFk` AS `cl_con_id`, + `c`.`claimRedeliveryFk` AS `cl_dev`, + `c`.`claimDestinationFk` AS `cl_sol` +FROM `vn`.`claimDevelopment` `c` diff --git a/db/routines/vn2008/views/cl_con.sql b/db/routines/vn2008/views/cl_con.sql new file mode 100644 index 000000000..b4f596d56 --- /dev/null +++ b/db/routines/vn2008/views/cl_con.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_con` +AS SELECT `c`.`id` AS `id`, + `c`.`description` AS `consecuencia` +FROM `vn`.`claimResult` `c` diff --git a/db/routines/vn2008/views/cl_det.sql b/db/routines/vn2008/views/cl_det.sql new file mode 100644 index 000000000..cef5c821d --- /dev/null +++ b/db/routines/vn2008/views/cl_det.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_det` +AS SELECT `c`.`id` AS `id`, + `c`.`claimFk` AS `cl_main_id`, + `c`.`saleFk` AS `Id_Movimiento`, + `c`.`quantity` AS `numero` +FROM `vn`.`claimBeginning` `c` diff --git a/db/routines/vn2008/views/cl_dev.sql b/db/routines/vn2008/views/cl_dev.sql new file mode 100644 index 000000000..7364fe833 --- /dev/null +++ b/db/routines/vn2008/views/cl_dev.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_dev` +AS SELECT `c`.`id` AS `id`, + `c`.`description` AS `devolucion` +FROM `vn`.`claimRedelivery` `c` diff --git a/db/routines/vn2008/views/cl_est.sql b/db/routines/vn2008/views/cl_est.sql new file mode 100644 index 000000000..8aa6ecb2e --- /dev/null +++ b/db/routines/vn2008/views/cl_est.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_est` +AS SELECT `c`.`id` AS `id`, + `c`.`description` AS `estado`, + `c`.`roleFk` AS `roleFk` +FROM `vn`.`claimState` `c` diff --git a/db/routines/vn2008/views/cl_main.sql b/db/routines/vn2008/views/cl_main.sql new file mode 100644 index 000000000..ef0c2cb8a --- /dev/null +++ b/db/routines/vn2008/views/cl_main.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_main` +AS SELECT `c`.`id` AS `id`, + `c`.`ticketCreated` AS `Fecha`, + `c`.`claimStateFk` AS `cl_est_id`, + `c`.`observation` AS `notas`, + `c`.`clientFk` AS `Id_Cliente`, + `c`.`workerFk` AS `Id_Trabajador`, + `c`.`responsibility` AS `sensib`, + `c`.`isChargedToMana` AS `mana`, + `c`.`ticketFk` AS `ticketFk`, + `c`.`created` AS `odbc_date` +FROM `vn`.`claim` `c` diff --git a/db/routines/vn2008/views/cl_mot.sql b/db/routines/vn2008/views/cl_mot.sql new file mode 100644 index 000000000..60fb27041 --- /dev/null +++ b/db/routines/vn2008/views/cl_mot.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_mot` +AS SELECT `c`.`id` AS `id`, + `c`.`description` AS `motivo` +FROM `vn`.`claimReason` `c` diff --git a/db/routines/vn2008/views/cl_res.sql b/db/routines/vn2008/views/cl_res.sql new file mode 100644 index 000000000..e82ee73b0 --- /dev/null +++ b/db/routines/vn2008/views/cl_res.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_res` +AS SELECT `c`.`id` AS `id`, + `c`.`description` AS `responsable`, + `c`.`responsability` AS `sensibility` +FROM `vn`.`claimResponsible` `c` diff --git a/db/routines/vn2008/views/cl_sol.sql b/db/routines/vn2008/views/cl_sol.sql new file mode 100644 index 000000000..23f2b8594 --- /dev/null +++ b/db/routines/vn2008/views/cl_sol.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cl_sol` +AS SELECT `c`.`id` AS `id`, + `c`.`description` AS `solucion`, + `c`.`addressFk` AS `addressFk` +FROM `vn`.`claimDestination` `c` diff --git a/db/routines/vn2008/views/client_observation.sql b/db/routines/vn2008/views/client_observation.sql new file mode 100644 index 000000000..7cd357b4e --- /dev/null +++ b/db/routines/vn2008/views/client_observation.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`client_observation` +AS SELECT `co`.`id` AS `client_observation_id`, + `co`.`clientFk` AS `Id_Cliente`, + `co`.`workerFk` AS `Id_Trabajador`, + `co`.`text` AS `text`, + `co`.`created` AS `odbc_date` +FROM `vn`.`clientObservation` `co` diff --git a/db/routines/vn2008/views/clientes_gestdoc.sql b/db/routines/vn2008/views/clientes_gestdoc.sql new file mode 100644 index 000000000..e711fded4 --- /dev/null +++ b/db/routines/vn2008/views/clientes_gestdoc.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`clientes_gestdoc` +AS SELECT `cd`.`clientFk` AS `Id_Cliente`, + `cd`.`dmsFk` AS `gest_doc_id` +FROM `vn`.`clientDms` `cd` diff --git a/db/routines/vn2008/views/clientes_regalos_enc.sql b/db/routines/vn2008/views/clientes_regalos_enc.sql new file mode 100644 index 000000000..b8ed6fec2 --- /dev/null +++ b/db/routines/vn2008/views/clientes_regalos_enc.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`clientes_regalos_enc` +AS SELECT `cpg`.`clientFk` AS `Id_Cliente`, + `cpg`.`giftFk` AS `Id_Regalo`, + `cpg`.`added` AS `odbc_date` +FROM `vn`.`clientPackagingGifts` `cpg` diff --git a/db/routines/vn2008/views/clientes_regalos_lista_enc.sql b/db/routines/vn2008/views/clientes_regalos_lista_enc.sql new file mode 100644 index 000000000..e129776b5 --- /dev/null +++ b/db/routines/vn2008/views/clientes_regalos_lista_enc.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`clientes_regalos_lista_enc` +AS SELECT `pg`.`id` AS `Id_Regalo`, + `pg`.`description` AS `Descripcion`, + `pg`.`photo` AS `foto`, + IF( + `util`.`VN_CURDATE`() BETWEEN `pg`.`started` AND `pg`.`ended`, + 1, + 0 + ) AS `activo`, + `pg`.`started` AS `datstart`, + `pg`.`ended` AS `datend`, + IFNULL(`pg`.`warehouseFk`, 0) AS `warehouse_id`, + IFNULL(`pg`.`provinceFk`, 0) AS `province_id`, + IFNULL(`pg`.`countryFk`, 0) AS `countryFk` +FROM `vn`.`packagingGifts` `pg` diff --git a/db/routines/vn2008/views/clientes_tipo.sql b/db/routines/vn2008/views/clientes_tipo.sql new file mode 100644 index 000000000..130dceb65 --- /dev/null +++ b/db/routines/vn2008/views/clientes_tipo.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`clientes_tipo` +AS SELECT `ct`.`id` AS `clientes_tipo_id`, + `ct`.`code` AS `code`, + `ct`.`type` AS `tipo`, + `ct`.`isCreatedAsServed` AS `isCreatedAsServed` +FROM `vn`.`clientType` `ct` diff --git a/db/routines/vn2008/views/config_host.sql b/db/routines/vn2008/views/config_host.sql new file mode 100644 index 000000000..2d4d6fa4c --- /dev/null +++ b/db/routines/vn2008/views/config_host.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`config_host` +AS SELECT `vn`.`host`.`code` AS `config_host_id`, + `vn`.`host`.`warehouseFk` AS `warehouse`, + `vn`.`host`.`companyFk` AS `empresaId`, + `vn`.`host`.`bankFk` AS `caja`, + `vn`.`host`.`printerFk` AS `Id_Impresora`, + `vn`.`host`.`routeDaysBefore` AS `route_days_before`, + `vn`.`host`.`routeDaysAfter` AS `route_days_after` +FROM `vn`.`host` diff --git a/db/routines/vn2008/views/consignatarios_observation.sql b/db/routines/vn2008/views/consignatarios_observation.sql new file mode 100644 index 000000000..1f4c2eeb2 --- /dev/null +++ b/db/routines/vn2008/views/consignatarios_observation.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`consignatarios_observation` +AS SELECT `co`.`id` AS `consignatarios_observation_id`, + `co`.`addressFk` AS `Id_Consigna`, + `co`.`observationTypeFk` AS `observation_type_id`, + `co`.`description` AS `text` +FROM `vn`.`addressObservation` `co` diff --git a/db/routines/vn2008/views/cooler_path_detail.sql b/db/routines/vn2008/views/cooler_path_detail.sql new file mode 100644 index 000000000..97b234186 --- /dev/null +++ b/db/routines/vn2008/views/cooler_path_detail.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`cooler_path_detail` +AS SELECT `cpd`.`id` AS `cooler_path_detail_id`, + `cpd`.`coolerPathFk` AS `cooler_path_id`, + `cpd`.`hallway` AS `pasillo` +FROM `vn`.`coolerPathDetail` `cpd` diff --git a/db/routines/vn2008/views/credit.sql b/db/routines/vn2008/views/credit.sql new file mode 100644 index 000000000..233e9dc1a --- /dev/null +++ b/db/routines/vn2008/views/credit.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`credit` +AS SELECT `c`.`id` AS `id`, + `c`.`clientFk` AS `Id_Cliente`, + `c`.`workerFk` AS `Id_Trabajador`, + `c`.`amount` AS `amount`, + `c`.`created` AS `odbc_date` +FROM `vn`.`clientCredit` `c` diff --git a/db/routines/vn2008/views/deliveryPoint.sql b/db/routines/vn2008/views/deliveryPoint.sql new file mode 100644 index 000000000..7763bc9fa --- /dev/null +++ b/db/routines/vn2008/views/deliveryPoint.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`deliveryPoint` +AS SELECT `dp`.`id` AS `id`, + `dp`.`name` AS `name`, + `dp`.`ubication` AS `ubication` +FROM `vn`.`deliveryPoint` `dp` diff --git a/db/routines/vn2008/views/device_user.sql b/db/routines/vn2008/views/device_user.sql new file mode 100644 index 000000000..52a2faafa --- /dev/null +++ b/db/routines/vn2008/views/device_user.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`device_user` +AS SELECT `dpu`.`deviceProductionFk` AS `device_id`, + `dpu`.`userFk` AS `user_id` +FROM `vn`.`deviceProductionUser` `dpu` diff --git a/db/routines/vn2008/views/edi_article.sql b/db/routines/vn2008/views/edi_article.sql new file mode 100644 index 000000000..34bb64149 --- /dev/null +++ b/db/routines/vn2008/views/edi_article.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_article` +AS SELECT `edi`.`item`.`id` AS `id`, + `edi`.`item`.`product_name` AS `product_name`, + `edi`.`item`.`name` AS `name`, + `edi`.`item`.`plant_id` AS `plant_id`, + `edi`.`item`.`group_id` AS `group_id`, + `edi`.`item`.`entry_date` AS `entry_date`, + `edi`.`item`.`expiry_date` AS `expiry_date`, + `edi`.`item`.`change_date_time` AS `change_date_time` +FROM `edi`.`item` diff --git a/db/routines/vn2008/views/edi_bucket.sql b/db/routines/vn2008/views/edi_bucket.sql new file mode 100644 index 000000000..1af487a6c --- /dev/null +++ b/db/routines/vn2008/views/edi_bucket.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_bucket` +AS SELECT cast( + `edi`.`bucket`.`bucket_id` AS char CHARSET utf8mb3 + ) COLLATE utf8mb3_general_ci AS `bucket_id`, + `edi`.`bucket`.`bucket_type_id` AS `bucket_type_id`, + `edi`.`bucket`.`description` AS `description`, + `edi`.`bucket`.`x_size` AS `x_size`, + `edi`.`bucket`.`y_size` AS `y_size`, + `edi`.`bucket`.`z_size` AS `z_size`, + `edi`.`bucket`.`entry_date` AS `entry_date`, + `edi`.`bucket`.`expiry_date` AS `expiry_date`, + `edi`.`bucket`.`change_date_time` AS `change_date_time` +FROM `edi`.`bucket` diff --git a/db/routines/vn2008/views/edi_bucket_type.sql b/db/routines/vn2008/views/edi_bucket_type.sql new file mode 100644 index 000000000..8e3af2080 --- /dev/null +++ b/db/routines/vn2008/views/edi_bucket_type.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_bucket_type` +AS SELECT `edi`.`bucket_type`.`bucket_type_id` AS `bucket_type_id`, + `edi`.`bucket_type`.`description` AS `description`, + `edi`.`bucket_type`.`entry_date` AS `entry_date`, + `edi`.`bucket_type`.`expiry_date` AS `expiry_date`, + `edi`.`bucket_type`.`change_date_time` AS `change_date_time` +FROM `edi`.`bucket_type` diff --git a/db/routines/vn2008/views/edi_feature.sql b/db/routines/vn2008/views/edi_feature.sql new file mode 100644 index 000000000..7789eac06 --- /dev/null +++ b/db/routines/vn2008/views/edi_feature.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_feature` +AS SELECT `edi`.`feature`.`item_id` AS `item_id`, + `edi`.`feature`.`feature_type_id` AS `feature_type_id`, + `edi`.`feature`.`feature_value` AS `feature_value`, + `edi`.`feature`.`entry_date` AS `entry_date`, + `edi`.`feature`.`expiry_date` AS `expiry_date`, + `edi`.`feature`.`change_date_time` AS `change_date_time` +FROM `edi`.`feature` diff --git a/db/routines/vn2008/views/edi_genus.sql b/db/routines/vn2008/views/edi_genus.sql new file mode 100644 index 000000000..c87ef2243 --- /dev/null +++ b/db/routines/vn2008/views/edi_genus.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_genus` +AS SELECT `edi`.`genus`.`genus_id` AS `genus_id`, + `edi`.`genus`.`latin_genus_name` AS `latin_genus_name`, + `edi`.`genus`.`entry_date` AS `entry_date`, + `edi`.`genus`.`expiry_date` AS `expiry_date`, + `edi`.`genus`.`change_date_time` AS `change_date_time` +FROM `edi`.`genus` diff --git a/db/routines/vn2008/views/edi_item_feature.sql b/db/routines/vn2008/views/edi_item_feature.sql new file mode 100644 index 000000000..216bd7cf6 --- /dev/null +++ b/db/routines/vn2008/views/edi_item_feature.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_item_feature` +AS SELECT `edi`.`item_feature`.`item_id` AS `item_id`, + `edi`.`item_feature`.`presentation_order` AS `presentation_order`, + `edi`.`item_feature`.`feature` AS `feature`, + `edi`.`item_feature`.`regulation_type` AS `regulation_type`, + `edi`.`item_feature`.`entry_date` AS `entry_date`, + `edi`.`item_feature`.`expiry_date` AS `expiry_date`, + `edi`.`item_feature`.`change_date_time` AS `change_date_time` +FROM `edi`.`item_feature` diff --git a/db/routines/vn2008/views/edi_plant.sql b/db/routines/vn2008/views/edi_plant.sql new file mode 100644 index 000000000..3537998db --- /dev/null +++ b/db/routines/vn2008/views/edi_plant.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_plant` +AS SELECT `edi`.`plant`.`plant_id` AS `plant_id`, + `edi`.`plant`.`genus_id` AS `genus_id`, + `edi`.`plant`.`specie_id` AS `specie_id`, + `edi`.`plant`.`entry_date` AS `entry_date`, + `edi`.`plant`.`expiry_date` AS `expiry_date`, + `edi`.`plant`.`change_date_time` AS `change_date_time` +FROM `edi`.`plant` diff --git a/db/routines/vn2008/views/edi_specie.sql b/db/routines/vn2008/views/edi_specie.sql new file mode 100644 index 000000000..33e38482e --- /dev/null +++ b/db/routines/vn2008/views/edi_specie.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_specie` +AS SELECT `edi`.`specie`.`specie_id` AS `specie_id`, + `edi`.`specie`.`genus_id` AS `genus_id`, + `edi`.`specie`.`latin_species_name` AS `latin_species_name`, + `edi`.`specie`.`entry_date` AS `entry_date`, + `edi`.`specie`.`expiry_date` AS `expiry_date`, + `edi`.`specie`.`change_date_time` AS `change_date_time` +FROM `edi`.`specie` diff --git a/db/routines/vn2008/views/edi_supplier.sql b/db/routines/vn2008/views/edi_supplier.sql new file mode 100644 index 000000000..51f96b83d --- /dev/null +++ b/db/routines/vn2008/views/edi_supplier.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_supplier` +AS SELECT `edi`.`supplier`.`supplier_id` AS `supplier_id`, + `edi`.`supplier`.`company_name` AS `company_name` +FROM `edi`.`supplier` diff --git a/db/routines/vn2008/views/edi_type.sql b/db/routines/vn2008/views/edi_type.sql new file mode 100644 index 000000000..95d73a1ff --- /dev/null +++ b/db/routines/vn2008/views/edi_type.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_type` +AS SELECT `edi`.`type`.`type_id` AS `type_id`, + `edi`.`type`.`type_group_id` AS `type_group_id`, + `edi`.`type`.`description` AS `description`, + `edi`.`type`.`entry_date` AS `entry_date`, + `edi`.`type`.`expiry_date` AS `expiry_date`, + `edi`.`type`.`change_date_time` AS `change_date_time` +FROM `edi`.`type` diff --git a/db/routines/vn2008/views/edi_value.sql b/db/routines/vn2008/views/edi_value.sql new file mode 100644 index 000000000..27829aa9e --- /dev/null +++ b/db/routines/vn2008/views/edi_value.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`edi_value` +AS SELECT `edi`.`value`.`type_id` AS `type_id`, + `edi`.`value`.`type_value` AS `type_value`, + `edi`.`value`.`type_description` AS `type_description`, + `edi`.`value`.`entry_date` AS `entry_date`, + `edi`.`value`.`expiry_date` AS `expiry_date`, + `edi`.`value`.`change_date_time` AS `change_date_time` +FROM `edi`.`value` diff --git a/db/routines/vn2008/views/empresa.sql b/db/routines/vn2008/views/empresa.sql new file mode 100644 index 000000000..3b43ee574 --- /dev/null +++ b/db/routines/vn2008/views/empresa.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`empresa` +AS SELECT `c`.`id` AS `id`, + `c`.`code` AS `abbreviation`, + `c`.`supplierAccountFk` AS `Id_Proveedores_account`, + `c`.`workerManagerFk` AS `gerente_id`, + `c`.`sage200Company` AS `digito_factura`, + `c`.`phytosanitary` AS `phytosanitary`, + `c`.`companyCode` AS `CodigoEmpresa`, + `c`.`companyGroupFk` AS `empresa_grupo`, + `c`.`isDefaulter` AS `morosidad`, + `c`.`expired` AS `baja`, + `c`.`register` AS `registro`, + `c`.`registered` AS `alta`, + `c`.`logo` AS `logo`, + `c`.`isOfficial` AS `oficial`, + `c`.`hasCyc` AS `cyc`, + `c`.`rgb` AS `rgb`, + `c`.`email` AS `mail`, + `c`.`stamp` AS `cuno`, + `c`.`created` AS `ODBC_DATE`, + `c`.`clientFk` AS `Id_Cliente` +FROM `vn`.`company` `c` diff --git a/db/routines/vn2008/views/empresa_grupo.sql b/db/routines/vn2008/views/empresa_grupo.sql new file mode 100644 index 000000000..35ba27279 --- /dev/null +++ b/db/routines/vn2008/views/empresa_grupo.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`empresa_grupo` +AS SELECT `vn`.`companyGroup`.`id` AS `empresa_grupo_id`, + `vn`.`companyGroup`.`code` AS `grupo` +FROM `vn`.`companyGroup` diff --git a/db/routines/vn2008/views/entrySource.sql b/db/routines/vn2008/views/entrySource.sql new file mode 100644 index 000000000..3a8df41bf --- /dev/null +++ b/db/routines/vn2008/views/entrySource.sql @@ -0,0 +1,55 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`entrySource` +AS SELECT `e`.`gestDocFk` AS `gestdoc_id`, + `e`.`id` AS `Id_Entrada`, + `e`.`invoiceNumber` AS `invoiceNumber`, + `e`.`reference` AS `reference`, + `e`.`isExcludedFromAvailable` AS `Inventario`, + `e`.`isConfirmed` AS `Confirmada`, + `e`.`isOrdered` AS `Pedida`, + `e`.`isRaid` AS `Redada`, + `e`.`evaNotes` AS `notas`, + `e`.`supplierFk` AS `Id_Proveedor`, + `tr`.`shipped` AS `shipment`, + `tr`.`landed` AS `landing`, + `w2`.`name` AS `wh_in`, + `w1`.`name` AS `wh_out`, + `am`.`name` AS `Agencia`, + `e`.`commission` AS `comision`, + `tr`.`warehouseInFk` AS `warehouse_id`, + `w1`.`id` AS `warehouse_id_out`, + `e`.`isBooked` AS `anotadoencaja`, + `e`.`invoiceInFk` AS `invoiceInFk`, + `e`.`companyFk` AS `empresa_id`, + `e`.`currencyFk` AS `Id_Moneda`, + `tr`.`id` AS `TravelFk`, + `e`.`sub` AS `sub`, + `e`.`kop` AS `kop`, + `e`.`pro` AS `pro`, + `e`.`invoiceAmount` AS `invoiceAmount`, + `w`.`code` AS `buyerCode`, + `e`.`typeFk` AS `typeFk`, + `w3`.`code` AS `observationWorkerCode` +FROM ( + ( + ( + ( + ( + ( + ( + `vn`.`entry` `e` + LEFT JOIN `vn`.`travel` `tr` ON(`e`.`travelFk` = `tr`.`id`) + ) + LEFT JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `tr`.`agencyModeFk`) + ) + LEFT JOIN `vn`.`warehouse` `w1` ON(`tr`.`warehouseOutFk` = `w1`.`id`) + ) + LEFT JOIN `vn`.`warehouse` `w2` ON(`tr`.`warehouseInFk` = `w2`.`id`) + ) + LEFT JOIN `vn`.`supplier` `s` ON(`e`.`supplierFk` = `s`.`id`) + ) + LEFT JOIN `vn`.`worker` `w` ON(`w`.`id` = `e`.`buyerFk`) + ) + LEFT JOIN `vn`.`worker` `w3` ON(`w3`.`id` = `e`.`observationEditorFk`) + ) diff --git a/db/routines/vn2008/views/escritos.sql b/db/routines/vn2008/views/escritos.sql new file mode 100644 index 000000000..b99bc13d7 --- /dev/null +++ b/db/routines/vn2008/views/escritos.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`escritos` +AS SELECT `s`.`id` AS `id`, + `s`.`code` AS `abrev`, + `s`.`description` AS `descripcion`, + `s`.`isVisible` AS `visible`, + `s`.`hasCompany` AS `hasCompany` +FROM `vn`.`sample` `s` diff --git a/db/routines/vn2008/views/escritos_det.sql b/db/routines/vn2008/views/escritos_det.sql new file mode 100644 index 000000000..46b6db506 --- /dev/null +++ b/db/routines/vn2008/views/escritos_det.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`escritos_det` +AS SELECT `cs`.`id` AS `id`, + `cs`.`clientFk` AS `Id_Cliente`, + `cs`.`typeFk` AS `escritos_id`, + `cs`.`created` AS `fecha`, + `cs`.`workerFk` AS `Id_Trabajador`, + `cs`.`userFk` AS `userFk`, + `cs`.`companyFk` AS `empresa_id`, + `cs`.`balance` AS `saldo` +FROM `vn`.`clientSample` `cs` diff --git a/db/routines/vn2008/views/expeditions.sql b/db/routines/vn2008/views/expeditions.sql new file mode 100644 index 000000000..d93e2a1c6 --- /dev/null +++ b/db/routines/vn2008/views/expeditions.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`expeditions` +AS SELECT `e`.`id` AS `expeditions_id`, + `e`.`agencyModeFk` AS `agency_id`, + `e`.`ticketFk` AS `ticket_id`, + `e`.`freightItemFk` AS `EsBulto`, + `e`.`created` AS `odbc_date`, + `e`.`counter` AS `counter`, + `e`.`workerFk` AS `workerFk`, + `e`.`externalId` AS `externalId`, + `p`.`itemFk` AS `Id_article` +FROM ( + `vn`.`expedition` `e` + LEFT JOIN `vn`.`packaging` `p` ON(`p`.`id` = `e`.`packagingFk`) + ) diff --git a/db/routines/vn2008/views/gestdoc.sql b/db/routines/vn2008/views/gestdoc.sql new file mode 100644 index 000000000..f9fef2895 --- /dev/null +++ b/db/routines/vn2008/views/gestdoc.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`gestdoc` +AS SELECT `d`.`id` AS `id`, + `d`.`dmsTypeFk` AS `gesttip_id`, + `d`.`file` AS `file`, + `d`.`contentType` AS `contentType`, + `d`.`workerFk` AS `trabajador_id`, + `d`.`warehouseFk` AS `warehouse_id`, + `d`.`companyFk` AS `emp_id`, + `d`.`hardCopyNumber` AS `orden`, + `d`.`hasFile` AS `original`, + `d`.`reference` AS `sref`, + `d`.`description` AS `brief`, + `d`.`created` AS `odbc_date` +FROM `vn`.`dms` `d` diff --git a/db/routines/vn2008/views/gesttip.sql b/db/routines/vn2008/views/gesttip.sql new file mode 100644 index 000000000..0c3befe1a --- /dev/null +++ b/db/routines/vn2008/views/gesttip.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`gesttip` +AS SELECT `g`.`id` AS `id`, + `g`.`name` AS `tipo`, + `g`.`path` AS `path`, + `g`.`readRoleFk` AS `readRoleFk`, + `g`.`writeRoleFk` AS `writeRoleFk`, + `g`.`code` AS `code` +FROM `vn`.`dmsType` `g` diff --git a/db/routines/vn2008/views/intrastat_data.sql b/db/routines/vn2008/views/intrastat_data.sql new file mode 100644 index 000000000..54853b69c --- /dev/null +++ b/db/routines/vn2008/views/intrastat_data.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`intrastat_data` +AS SELECT `ii`.`id` AS `id`, + `ii`.`invoiceInFk` AS `recibida_id`, + `ii`.`net` AS `neto`, + `ii`.`intrastatFk` AS `intrastat_id`, + `ii`.`amount` AS `importe`, + `ii`.`stems` AS `unidades`, + `ii`.`countryFk` AS `Paises_Id`, + `ii`.`dated` AS `odbc_date`, + `ii`.`statisticalValue` AS `valorestadistico` +FROM `vn`.`invoiceInIntrastat` `ii` diff --git a/db/routines/vn2008/views/invoiceCorrection.sql b/db/routines/vn2008/views/invoiceCorrection.sql new file mode 100644 index 000000000..5ed1d5844 --- /dev/null +++ b/db/routines/vn2008/views/invoiceCorrection.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`invoiceCorrection` +AS SELECT `ic`.`correctingFk` AS `correctingFk`, + `ic`.`correctedFk` AS `correctedFk`, + `ic`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`, + `ic`.`siiTypeInvoiceOutFk` AS `siiTypeInvoiceOutFk`, + `ic`.`invoiceCorrectionTypeFk` AS `invoiceCorrectionTypeFk` +FROM `vn`.`invoiceCorrection` `ic` diff --git a/db/routines/vn2008/views/itemTag.sql b/db/routines/vn2008/views/itemTag.sql new file mode 100644 index 000000000..ff247089f --- /dev/null +++ b/db/routines/vn2008/views/itemTag.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`itemTag` +AS SELECT `i`.`id` AS `id`, + `i`.`itemFk` AS `itemFk`, + `i`.`tagFk` AS `tagFk`, + `i`.`value` AS `value`, + `i`.`priority` AS `priority` +FROM `vn`.`itemTag` `i` diff --git a/db/routines/vn2008/views/item_entry_in.sql b/db/routines/vn2008/views/item_entry_in.sql new file mode 100644 index 000000000..1cc7d21b1 --- /dev/null +++ b/db/routines/vn2008/views/item_entry_in.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`item_entry_in` +AS SELECT `t`.`warehouse_id` AS `warehouse_id`, + `t`.`warehouse_id_out` AS `warehouse_id_out`, + `t`.`landing` AS `dat`, + `m`.`Id_Article` AS `item_id`, + `m`.`Cantidad` AS `amount`, + `t`.`received` AS `received`, + `e`.`Redada` AS `isVirtualStock`, + `e`.`Id_Entrada` AS `entryFk` +FROM ( + ( + `vn2008`.`Compres` `m` + JOIN `vn2008`.`Entradas` `e` ON(`m`.`Id_Entrada` = `e`.`Id_Entrada`) + ) + JOIN `vn2008`.`travel` `t` ON(`e`.`travel_id` = `t`.`id`) + ) +WHERE `e`.`Inventario` = 0 + AND `m`.`Cantidad` <> 0 diff --git a/db/routines/vn2008/views/item_entry_out.sql b/db/routines/vn2008/views/item_entry_out.sql new file mode 100644 index 000000000..d99672df8 --- /dev/null +++ b/db/routines/vn2008/views/item_entry_out.sql @@ -0,0 +1,27 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`item_entry_out` +AS SELECT `t`.`warehouse_id_out` AS `warehouse_id`, + `t`.`shipment` AS `dat`, + `m`.`Id_Article` AS `item_id`, + - `m`.`Cantidad` AS `amount`, + `t`.`delivered` <> 0 + OR IFNULL(`co`.`valor`, 0) AS `delivered`, + `e`.`Id_Entrada` AS `entryFk` +FROM ( + ( + ( + `vn2008`.`Compres` `m` + JOIN `vn2008`.`Entradas` `e` ON(`m`.`Id_Entrada` = `e`.`Id_Entrada`) + ) + JOIN `vn2008`.`travel` `t` ON(`e`.`travel_id` = `t`.`id`) + ) + LEFT JOIN `vn2008`.`Compres_ok` `co` ON( + `co`.`Id_Compra` = `m`.`Id_Compra` + AND `co`.`Id_Accion` = 3 + AND `co`.`valor` <> 0 + ) + ) +WHERE `e`.`Inventario` = 0 + AND `e`.`Redada` = 0 + AND `m`.`Cantidad` <> 0 diff --git a/db/routines/vn2008/views/item_out.sql b/db/routines/vn2008/views/item_out.sql new file mode 100644 index 000000000..57353a6d6 --- /dev/null +++ b/db/routines/vn2008/views/item_out.sql @@ -0,0 +1,17 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`item_out` +AS SELECT `t`.`warehouse_id` AS `warehouse_id`, + `t`.`Fecha` AS `dat`, + `m`.`Id_Article` AS `item_id`, + - `m`.`Cantidad` AS `amount`, + `m`.`OK` AS `ok`, + `m`.`Reservado` AS `Reservado`, + `t`.`Factura` AS `invoice`, + `m`.`Id_Movimiento` AS `saleFk`, + `m`.`Id_Ticket` AS `ticketFk` +FROM ( + `vn2008`.`Movimientos` `m` + JOIN `vn2008`.`Tickets` `t` ON(`m`.`Id_Ticket` = `t`.`Id_Ticket`) + ) +WHERE `m`.`Cantidad` <> 0 diff --git a/db/routines/vn2008/views/iva_codigo.sql b/db/routines/vn2008/views/iva_codigo.sql new file mode 100644 index 000000000..6bd811abe --- /dev/null +++ b/db/routines/vn2008/views/iva_codigo.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`iva_codigo` +AS SELECT `tc`.`id` AS `id`, + `tc`.`dated` AS `fecha`, + `tc`.`code` AS `codigo`, + `tc`.`taxTypeFk` AS `iva_tipo_id`, + `tc`.`rate` AS `iva`, + `tc`.`equalizationTax` AS `recargo`, + `tc`.`type` AS `tipo`, + `tc`.`link` AS `link`, + `tc`.`isActive` AS `isActive`, + `tc`.`updated` AS `updated`, + `tc`.`transactionCode` AS `transactionCode` +FROM `vn`.`taxCode` `tc` diff --git a/db/routines/vn2008/views/iva_group.sql b/db/routines/vn2008/views/iva_group.sql new file mode 100644 index 000000000..f4fc1e92e --- /dev/null +++ b/db/routines/vn2008/views/iva_group.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`iva_group` +AS SELECT `tc`.`id` AS `iva_group_id`, + `tc`.`description` AS `description`, + `tc`.`code` AS `code` +FROM `vn`.`taxClass` `tc` diff --git a/db/routines/vn2008/views/iva_group_codigo.sql b/db/routines/vn2008/views/iva_group_codigo.sql new file mode 100644 index 000000000..86e72ebe9 --- /dev/null +++ b/db/routines/vn2008/views/iva_group_codigo.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`iva_group_codigo` +AS SELECT `tcc`.`taxClassFk` AS `iva_group_id`, + `tcc`.`effectived` AS `date`, + `tcc`.`taxCodeFk` AS `iva_codigo_id` +FROM `vn`.`taxClassCode` `tcc` diff --git a/db/routines/vn2008/views/iva_tipo.sql b/db/routines/vn2008/views/iva_tipo.sql new file mode 100644 index 000000000..0c62243e2 --- /dev/null +++ b/db/routines/vn2008/views/iva_tipo.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`iva_tipo` +AS SELECT `tt`.`id` AS `id`, + `tt`.`nickname` AS `alias`, + `tt`.`isAccrued` AS `isAccrued`, + `tt`.`serial` AS `serie_id`, + `tt`.`TIPOOPE` AS `TIPOOPE`, + `tt`.`description` AS `descripcion`, + `tt`.`countryFk` AS `Id_Pais` +FROM `vn`.`taxType` `tt` diff --git a/db/routines/vn2008/views/mail.sql b/db/routines/vn2008/views/mail.sql new file mode 100644 index 000000000..3074dfa95 --- /dev/null +++ b/db/routines/vn2008/views/mail.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`mail` +AS SELECT `m`.`id` AS `id`, + `m`.`senderFk` AS `senderFk`, + `m`.`recipientFk` AS `recipientFk`, + `m`.`receiver` AS `to`, + `m`.`replyTo` AS `reply_to`, + `m`.`subject` AS `subject`, + `m`.`body` AS `text`, + `m`.`plainTextBody` AS `plainTextBody`, + `m`.`attachment` AS `path`, + `m`.`creationDate` AS `DATE_ODBC`, + `m`.`sent` AS `sent`, + `m`.`status` AS `error` +FROM `vn`.`mail` `m` diff --git a/db/routines/vn2008/views/mandato.sql b/db/routines/vn2008/views/mandato.sql new file mode 100644 index 000000000..dde43b48d --- /dev/null +++ b/db/routines/vn2008/views/mandato.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`mandato` +AS SELECT `m`.`id` AS `id`, + `m`.`clientFk` AS `Id_Cliente`, + `m`.`companyFk` AS `empresa_id`, + `m`.`code` AS `Id_mandato`, + `m`.`created` AS `FAlta`, + `m`.`finished` AS `Fbaja`, + `m`.`mandateTypeFk` AS `idmandato_tipo` +FROM `vn`.`mandate` `m` diff --git a/db/routines/vn2008/views/mandato_tipo.sql b/db/routines/vn2008/views/mandato_tipo.sql new file mode 100644 index 000000000..a1b5b0a9f --- /dev/null +++ b/db/routines/vn2008/views/mandato_tipo.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`mandato_tipo` +AS SELECT `m`.`id` AS `idmandato_tipo`, + `m`.`name` AS `Nombre` +FROM `vn`.`mandateType` `m` diff --git a/db/routines/vn2008/views/observation_type.sql b/db/routines/vn2008/views/observation_type.sql new file mode 100644 index 000000000..2fea17c5f --- /dev/null +++ b/db/routines/vn2008/views/observation_type.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`observation_type` +AS SELECT `co`.`id` AS `observation_type_id`, + `co`.`description` AS `description` +FROM `vn`.`observationType` `co` diff --git a/db/routines/vn2008/views/order.sql b/db/routines/vn2008/views/order.sql new file mode 100644 index 000000000..e0c8c5f85 --- /dev/null +++ b/db/routines/vn2008/views/order.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`order` +AS SELECT `hedera`.`order`.`id` AS `id`, + `hedera`.`order`.`date_make` AS `date_make`, + `hedera`.`order`.`date_send` AS `date_send`, + `hedera`.`order`.`customer_id` AS `customer_id`, + `hedera`.`order`.`delivery_method_id` AS `delivery_method_id`, + `hedera`.`order`.`agency_id` AS `agency_id`, + `hedera`.`order`.`address_id` AS `address_id`, + `hedera`.`order`.`note` AS `note`, + `hedera`.`order`.`confirmed` AS `confirmed`, + `hedera`.`order`.`is_bionic` AS `is_bionic`, + `hedera`.`order`.`source_app` AS `source_app` +FROM `hedera`.`order` diff --git a/db/routines/vn2008/views/order_Tickets.sql b/db/routines/vn2008/views/order_Tickets.sql new file mode 100644 index 000000000..46fdf8e55 --- /dev/null +++ b/db/routines/vn2008/views/order_Tickets.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`order_Tickets` +AS SELECT `ot`.`orderFk` AS `order_id`, + `ot`.`ticketFk` AS `Id_Ticket` +FROM `vn`.`orderTicket` `ot` diff --git a/db/routines/vn2008/views/order_component.sql b/db/routines/vn2008/views/order_component.sql new file mode 100644 index 000000000..c4468f084 --- /dev/null +++ b/db/routines/vn2008/views/order_component.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`order_component` +AS SELECT `c`.`order_row_id` AS `order_row_id`, + `c`.`component_id` AS `component_id`, + `c`.`price` AS `price` +FROM `hedera`.`order_component` `c` diff --git a/db/routines/vn2008/views/order_row.sql b/db/routines/vn2008/views/order_row.sql new file mode 100644 index 000000000..7f151e32b --- /dev/null +++ b/db/routines/vn2008/views/order_row.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`order_row` +AS SELECT `order_row`.`id` AS `id`, + `order_row`.`order_id` AS `order_id`, + `order_row`.`item_id` AS `item_id`, + `order_row`.`warehouse_id` AS `warehouse_id`, + `order_row`.`shipment` AS `shipment`, + `order_row`.`amount` AS `amount`, + `order_row`.`price` AS `price`, + `order_row`.`rate` AS `rate`, + `order_row`.`created` AS `created`, + `order_row`.`Id_Movimiento` AS `Id_Movimiento` +FROM `hedera`.`order_row` diff --git a/db/routines/vn2008/views/pago.sql b/db/routines/vn2008/views/pago.sql new file mode 100644 index 000000000..546496070 --- /dev/null +++ b/db/routines/vn2008/views/pago.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`pago` +AS SELECT `p`.`id` AS `id`, + `p`.`received` AS `fecha`, + `p`.`dueDated` AS `dueDated`, + `p`.`supplierFk` AS `id_proveedor`, + `p`.`amount` AS `importe`, + `p`.`currencyFk` AS `id_moneda`, + `p`.`divisa` AS `divisa`, + `p`.`bankFk` AS `id_banco`, + `p`.`payMethodFk` AS `pay_met_id`, + `p`.`companyFk` AS `empresa_id`, + `p`.`isConciliated` AS `conciliado`, + `p`.`bankingFees` AS `g_bancarios`, + `p`.`concept` AS `concepte`, + `p`.`created` AS `odbc_date` +FROM `vn`.`payment` `p` diff --git a/db/routines/vn2008/views/pay_dem.sql b/db/routines/vn2008/views/pay_dem.sql new file mode 100644 index 000000000..1ef00d645 --- /dev/null +++ b/db/routines/vn2008/views/pay_dem.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`pay_dem` +AS SELECT `pd`.`id` AS `id`, + `pd`.`payDem` AS `pay_dem` +FROM `vn`.`payDem` `pd` diff --git a/db/routines/vn2008/views/pay_dem_det.sql b/db/routines/vn2008/views/pay_dem_det.sql new file mode 100644 index 000000000..822897ed8 --- /dev/null +++ b/db/routines/vn2008/views/pay_dem_det.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`pay_dem_det` +AS SELECT `pdd`.`id` AS `id`, + `pdd`.`detail` AS `detalle` +FROM `vn`.`payDemDetail` `pdd` diff --git a/db/routines/vn2008/views/pay_met.sql b/db/routines/vn2008/views/pay_met.sql new file mode 100644 index 000000000..63e2b30e0 --- /dev/null +++ b/db/routines/vn2008/views/pay_met.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`pay_met` +AS SELECT `pm`.`id` AS `id`, + `pm`.`name` AS `name`, + `pm`.`graceDays` AS `graceDays`, + `pm`.`outstandingDebt` AS `deudaviva`, + `pm`.`solution` AS `solucion`, + `pm`.`isNotified` AS `isNotified` +FROM `vn`.`payMethod` `pm` diff --git a/db/routines/vn2008/views/payroll_categorias.sql b/db/routines/vn2008/views/payroll_categorias.sql new file mode 100644 index 000000000..b71e69019 --- /dev/null +++ b/db/routines/vn2008/views/payroll_categorias.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`payroll_categorias` +AS SELECT `pc`.`id` AS `codcategoria`, + `pc`.`rate` AS `Tarifa`, + `pc`.`description` AS `descripcion` +FROM `vn`.`payrollCategories` `pc` diff --git a/db/routines/vn2008/views/person_user.sql b/db/routines/vn2008/views/person_user.sql new file mode 100644 index 000000000..1fb470c88 --- /dev/null +++ b/db/routines/vn2008/views/person_user.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`person_user` +AS SELECT `u`.`id` AS `id`, + `u`.`role` AS `mysql_user_id`, + `u`.`name` AS `name`, + `u`.`password` AS `password`, + `u`.`active` AS `active`, + `u`.`lastPassChange` AS `last_pass_change` +FROM `account`.`user` `u` diff --git a/db/routines/vn2008/views/person_user_idtrabajador.sql b/db/routines/vn2008/views/person_user_idtrabajador.sql new file mode 100644 index 000000000..1eb45f464 --- /dev/null +++ b/db/routines/vn2008/views/person_user_idtrabajador.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`person_user_idtrabajador` +AS SELECT `t`.`Id_Trabajador` AS `Id_Trabajador` +FROM ( + `vn2008`.`person_user` `p` + JOIN `vn2008`.`Trabajadores` `t` ON(`p`.`id` = `t`.`user_id`) + ) +WHERE `t`.`user_id` = `account`.`myUser_getId`() diff --git a/db/routines/vn2008/views/plantpassport.sql b/db/routines/vn2008/views/plantpassport.sql new file mode 100644 index 000000000..b1be6a80b --- /dev/null +++ b/db/routines/vn2008/views/plantpassport.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`plantpassport` +AS SELECT `pp`.`producerFk` AS `producer_id`, + `pp`.`plantpassportAuthorityFk` AS `plantpassport_authority_id`, + `pp`.`number` AS `number`, + `pp`.`isRequested` AS `isRequested` +FROM `vn`.`plantpassport` `pp` diff --git a/db/routines/vn2008/views/plantpassport_authority.sql b/db/routines/vn2008/views/plantpassport_authority.sql new file mode 100644 index 000000000..4548bbede --- /dev/null +++ b/db/routines/vn2008/views/plantpassport_authority.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`plantpassport_authority` +AS SELECT `ppa`.`id` AS `plantpassport_authority_id`, + `ppa`.`denomination` AS `denomination`, + `ppa`.`countryFk` AS `Paises_Id` +FROM `vn`.`plantpassportAuthority` `ppa` diff --git a/db/routines/vn2008/views/price_fixed.sql b/db/routines/vn2008/views/price_fixed.sql new file mode 100644 index 000000000..ce8170e7c --- /dev/null +++ b/db/routines/vn2008/views/price_fixed.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`price_fixed` +AS SELECT `pf`.`itemFk` AS `item_id`, + `pf`.`rate0` AS `rate_0`, + `pf`.`rate1` AS `rate_1`, + `pf`.`rate2` AS `rate_2`, + `pf`.`rate3` AS `rate_3`, + `pf`.`started` AS `date_start`, + `pf`.`ended` AS `date_end`, + `pf`.`bonus` AS `bonus`, + `pf`.`warehouseFk` AS `warehouse_id`, + `pf`.`created` AS `odbc_date`, + `pf`.`id` AS `price_fixed_id`, + `pf`.`grouping` AS `grouping`, + `pf`.`packing` AS `Packing`, + `pf`.`box` AS `caja` +FROM `vn`.`priceFixed` `pf` diff --git a/db/routines/vn2008/views/producer.sql b/db/routines/vn2008/views/producer.sql new file mode 100644 index 000000000..babfb887e --- /dev/null +++ b/db/routines/vn2008/views/producer.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`producer` +AS SELECT `p`.`id` AS `producer_id`, + `p`.`name` AS `name`, + `p`.`isVisible` AS `visible` +FROM `vn`.`producer` `p` diff --git a/db/routines/vn2008/views/proveedores_clientes.sql b/db/routines/vn2008/views/proveedores_clientes.sql new file mode 100644 index 000000000..e08f4a3a7 --- /dev/null +++ b/db/routines/vn2008/views/proveedores_clientes.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`proveedores_clientes` +AS SELECT `Proveedores`.`Id_Proveedor` AS `Id_Proveedor`, + `Proveedores`.`Proveedor` AS `Proveedor`, + `Clientes`.`id_cliente` AS `Id_Cliente`, + `Clientes`.`cliente` AS `Cliente` +FROM ( + `vn2008`.`Proveedores` + JOIN `vn2008`.`Clientes` ON(`Proveedores`.`NIF` = `Clientes`.`if`) + ) diff --git a/db/routines/vn2008/views/province.sql b/db/routines/vn2008/views/province.sql new file mode 100644 index 000000000..1477ec803 --- /dev/null +++ b/db/routines/vn2008/views/province.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`province` +AS SELECT `p`.`id` AS `province_id`, + `p`.`name` AS `name`, + `p`.`countryFk` AS `Paises_Id`, + `p`.`warehouseFk` AS `warehouse_id`, + `p`.`zoneFk` AS `zone`, + `p`.`geoFk` AS `geoFk` +FROM `vn`.`province` `p` diff --git a/db/routines/vn2008/views/recibida.sql b/db/routines/vn2008/views/recibida.sql new file mode 100644 index 000000000..76b86505e --- /dev/null +++ b/db/routines/vn2008/views/recibida.sql @@ -0,0 +1,26 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`recibida` +AS SELECT `r`.`id` AS `id`, + `r`.`serialNumber` AS `num_recibida`, + `r`.`serial` AS `serie`, + `r`.`supplierFk` AS `proveedor_id`, + `r`.`issued` AS `fecha`, + `r`.`supplierRef` AS `sref`, + `r`.`isBooked` AS `contabilizada`, + `r`.`currencyFk` AS `moneda_id`, + `r`.`created` AS `MYSQL_TIME`, + `r`.`companyFk` AS `empresa_id`, + `r`.`docFk` AS `gestdoc_id`, + `r`.`booked` AS `dateBooking`, + `r`.`operated` AS `dateOperation`, + `r`.`siiTypeInvoiceInFk` AS `siiTypeInvoiceInFk`, + `r`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`, + `r`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`, + `r`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`, + `r`.`siiTrascendencyInvoiceInFk` AS `siiTrascendencyInvoiceInFk`, + `r`.`bookEntried` AS `bookEntried`, + `r`.`isVatDeductible` AS `isVatDeductible`, + `r`.`withholdingSageFk` AS `withholdingSageFk`, + `r`.`expenseFkDeductible` AS `expenseFkDeductible` +FROM `vn`.`invoiceIn` `r` diff --git a/db/routines/vn2008/views/recibida_intrastat.sql b/db/routines/vn2008/views/recibida_intrastat.sql new file mode 100644 index 000000000..402781931 --- /dev/null +++ b/db/routines/vn2008/views/recibida_intrastat.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`recibida_intrastat` +AS SELECT `i`.`invoiceInFk` AS `recibida_id`, + `i`.`intrastatFk` AS `Codintrastat`, + `i`.`amount` AS `importe` +FROM `vn`.`invoiceInIntrastat` `i` diff --git a/db/routines/vn2008/views/recibida_iva.sql b/db/routines/vn2008/views/recibida_iva.sql new file mode 100644 index 000000000..7d948a6ff --- /dev/null +++ b/db/routines/vn2008/views/recibida_iva.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`recibida_iva` +AS SELECT `i`.`id` AS `id`, + `i`.`invoiceInFk` AS `recibida_id`, + `i`.`taxCodeFk` AS `iva_id`, + `i`.`taxableBase` AS `bi`, + `i`.`expenseFk` AS `gastos_id`, + `i`.`foreignValue` AS `divisa`, + `i`.`taxTypeSageFk` AS `taxTypeSageFk`, + `i`.`transactionTypeSageFk` AS `transactionTypeSageFk`, + `i`.`created` AS `MYSQL_TIME` +FROM `vn`.`invoiceInTax` `i` diff --git a/db/routines/vn2008/views/recibida_vencimiento.sql b/db/routines/vn2008/views/recibida_vencimiento.sql new file mode 100644 index 000000000..813ae40d7 --- /dev/null +++ b/db/routines/vn2008/views/recibida_vencimiento.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`recibida_vencimiento` +AS SELECT `r`.`id` AS `id`, + `r`.`invoiceInFk` AS `recibida_id`, + `r`.`dueDated` AS `fecha`, + `r`.`bankFk` AS `banco_id`, + `r`.`amount` AS `cantidad`, + `r`.`foreignValue` AS `divisa`, + `r`.`created` AS `stamp` +FROM `vn`.`invoiceInDueDay` `r` diff --git a/db/routines/vn2008/views/recovery.sql b/db/routines/vn2008/views/recovery.sql new file mode 100644 index 000000000..5bbff3124 --- /dev/null +++ b/db/routines/vn2008/views/recovery.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`recovery` +AS SELECT `r`.`id` AS `recovery_id`, + `r`.`clientFk` AS `Id_Cliente`, + `r`.`started` AS `dstart`, + `r`.`finished` AS `dend`, + `r`.`amount` AS `amount`, + `r`.`period` AS `period` +FROM `vn`.`recovery` `r` diff --git a/db/routines/vn2008/views/reference_min.sql b/db/routines/vn2008/views/reference_min.sql new file mode 100644 index 000000000..d40ae12a3 --- /dev/null +++ b/db/routines/vn2008/views/reference_min.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`reference_min` +AS SELECT `rc`.`dated` AS `date`, + `rc`.`value` AS `rate`, + `rc`.`currencyFk` AS `moneda_id` +FROM `vn`.`referenceCurrent` `rc` diff --git a/db/routines/vn2008/views/reference_rate.sql b/db/routines/vn2008/views/reference_rate.sql new file mode 100644 index 000000000..eb0f1c25e --- /dev/null +++ b/db/routines/vn2008/views/reference_rate.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`reference_rate` +AS SELECT `rr`.`currencyFk` AS `moneda_id`, + `rr`.`dated` AS `date`, + `rr`.`value` AS `rate` +FROM `vn`.`referenceRate` `rr` diff --git a/db/routines/vn2008/views/reinos.sql b/db/routines/vn2008/views/reinos.sql new file mode 100644 index 000000000..4d98d1f09 --- /dev/null +++ b/db/routines/vn2008/views/reinos.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`reinos` +AS SELECT `r`.`id` AS `id`, + `r`.`name` AS `reino`, + `r`.`display` AS `display`, + `r`.`color` AS `color`, + `r`.`icon` AS `icon`, + `r`.`merchandise` AS `mercancia`, + `r`.`order` AS `orden`, + `r`.`shortLife` AS `efimero` +FROM `vn`.`itemCategory` `r` diff --git a/db/routines/vn2008/views/sharingcart.sql b/db/routines/vn2008/views/sharingcart.sql new file mode 100644 index 000000000..b59977b8f --- /dev/null +++ b/db/routines/vn2008/views/sharingcart.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`sharingcart` +AS SELECT `sc`.`id` AS `id`, + `sc`.`workerFk` AS `Id_Trabajador`, + `sc`.`started` AS `datSTART`, + `sc`.`ended` AS `datEND`, + `sc`.`workerSubstitute` AS `Id_Suplente`, + `sc`.`created` AS `odbc_date` +FROM `vn`.`sharingCart` `sc` diff --git a/db/routines/vn2008/views/sharingclient.sql b/db/routines/vn2008/views/sharingclient.sql new file mode 100644 index 000000000..970132c80 --- /dev/null +++ b/db/routines/vn2008/views/sharingclient.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`sharingclient` +AS SELECT `sc`.`id` AS `id`, + `sc`.`workerFk` AS `Id_Trabajador`, + `sc`.`started` AS `datSTART`, + `sc`.`ended` AS `datEND`, + `sc`.`clientFk` AS `Id_Cliente` +FROM `vn`.`sharingClient` `sc` diff --git a/db/routines/vn2008/views/sms.sql b/db/routines/vn2008/views/sms.sql new file mode 100644 index 000000000..abaea40a2 --- /dev/null +++ b/db/routines/vn2008/views/sms.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`sms` +AS SELECT `t`.`id` AS `id`, + `t`.`senderFk` AS `Id_trabajador`, + `t`.`sender` AS `from`, + `t`.`destination` AS `to`, + `t`.`message` AS `text`, + `t`.`statusCode` AS `sent`, + `t`.`status` AS `response`, + `t`.`created` AS `DATE_ODBC` +FROM `vn`.`sms` `t` diff --git a/db/routines/vn2008/views/state.sql b/db/routines/vn2008/views/state.sql new file mode 100644 index 000000000..63f6589af --- /dev/null +++ b/db/routines/vn2008/views/state.sql @@ -0,0 +1,13 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`state` +AS SELECT `s`.`id` AS `id`, + `s`.`name` AS `name`, + `s`.`order` AS `order`, + `s`.`alertLevel` AS `alert_level`, + `s`.`code` AS `code`, + `s`.`sectorProdPriority` AS `sectorProdPriority`, + `s`.`nextStateFk` AS `nextStateFk`, + `s`.`isPreviousPreparable` AS `isPreviousPreparable`, + `s`.`isPicked` AS `isPicked` +FROM `vn`.`state` `s` diff --git a/db/routines/vn2008/views/tag.sql b/db/routines/vn2008/views/tag.sql new file mode 100644 index 000000000..25b3ab82e --- /dev/null +++ b/db/routines/vn2008/views/tag.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tag` +AS SELECT `t`.`id` AS `id`, + `t`.`name` AS `name`, + `t`.`isFree` AS `isFree`, + `t`.`isQuantitatif` AS `isQuantitatif`, + `t`.`sourceTable` AS `sourceTable`, + `t`.`unit` AS `unit` +FROM `vn`.`tag` `t` diff --git a/db/routines/vn2008/views/tarifa_componentes.sql b/db/routines/vn2008/views/tarifa_componentes.sql new file mode 100644 index 000000000..bec53abd9 --- /dev/null +++ b/db/routines/vn2008/views/tarifa_componentes.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tarifa_componentes` +AS SELECT `tarifa_componentes`.`Id_Componente` AS `Id_Componente`, + `tarifa_componentes`.`Componente` AS `Componente`, + `tarifa_componentes`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`, + `tarifa_componentes`.`tarifa_class` AS `tarifa_class`, + `tarifa_componentes`.`tax` AS `tax`, + `tarifa_componentes`.`is_renewable` AS `is_renewable` +FROM `bi`.`tarifa_componentes` diff --git a/db/routines/vn2008/views/tarifa_componentes_series.sql b/db/routines/vn2008/views/tarifa_componentes_series.sql new file mode 100644 index 000000000..a1d188709 --- /dev/null +++ b/db/routines/vn2008/views/tarifa_componentes_series.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tarifa_componentes_series` +AS SELECT `tarifa_componentes_series`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`, + `tarifa_componentes_series`.`Serie` AS `Serie`, + `tarifa_componentes_series`.`base` AS `base` +FROM `bi`.`tarifa_componentes_series` diff --git a/db/routines/vn2008/views/tarifas.sql b/db/routines/vn2008/views/tarifas.sql new file mode 100644 index 000000000..8b836d60a --- /dev/null +++ b/db/routines/vn2008/views/tarifas.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tarifas` +AS SELECT `r`.`id` AS `tarifa_id`, + `r`.`dated` AS `fecha`, + `r`.`warehouseFk` AS `warehouse_id`, + `r`.`rate0` AS `t0`, + `r`.`rate1` AS `t1`, + `r`.`rate2` AS `t2`, + `r`.`rate3` AS `t3` +FROM `vn`.`rate` `r` diff --git a/db/routines/vn2008/views/tblContadores.sql b/db/routines/vn2008/views/tblContadores.sql new file mode 100644 index 000000000..129d3ce8b --- /dev/null +++ b/db/routines/vn2008/views/tblContadores.sql @@ -0,0 +1,39 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tblContadores` +AS SELECT `c`.`id` AS `id`, + `c`.`ochoa` AS `ochoa`, + `c`.`invoiceOutFk` AS `nfactura`, + `c`.`inventoried` AS `FechaInventario`, + `c`.`itemLog` AS `HistoricoArticulo`, + `c`.`weekGoal` AS `week_goal`, + `c`.`photosPath` AS `Rutafotos`, + `c`.`cashBoxNumber` AS `numCaja`, + `c`.`redCode` AS `CodigoRojo`, + `c`.`TabletTime` AS `Tablet_Hora`, + `c`.`t0` AS `t0`, + `c`.`t1` AS `t1`, + `c`.`t2` AS `t2`, + `c`.`t3` AS `t3`, + `c`.`cc` AS `cc`, + `c`.`palet` AS `palet`, + `c`.`campaign` AS `campaign`, + `c`.`campaignLife` AS `campaign_life`, + `c`.`truckDays` AS `truck_days`, + `c`.`transportCharges` AS `tasa_transporte`, + `c`.`escanerPath` AS `escaner_path`, + `c`.`printedTurn` AS `turnoimpreso`, + `c`.`truckLength` AS `truck_length`, + `c`.`fuelConsumption` AS `fuel_consumption`, + `c`.`petrol` AS `petrol`, + `c`.`maintenance` AS `maintenance`, + `c`.`hourPrice` AS `hour_price`, + `c`.`meterPrice` AS `meter_price`, + `c`.`kmPrice` AS `km_price`, + `c`.`routeOption` AS `route_option`, + `c`.`dbproduccion` AS `dbproduccion`, + `c`.`mdbServer` AS `mdbServer`, + `c`.`fakeEmail` AS `fakeEmail`, + `c`.`defaultersMaxAmount` AS `defaultersMaxAmount`, + `c`.`ASIEN` AS `ASIEN` +FROM `vn`.`config` `c` diff --git a/db/routines/vn2008/views/thermograph.sql b/db/routines/vn2008/views/thermograph.sql new file mode 100644 index 000000000..f51b83d24 --- /dev/null +++ b/db/routines/vn2008/views/thermograph.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`thermograph` +AS SELECT `t`.`id` AS `thermograph_id`, + `t`.`model` AS `model` +FROM `vn`.`thermograph` `t` diff --git a/db/routines/vn2008/views/ticketCreationData.sql b/db/routines/vn2008/views/ticketCreationData.sql new file mode 100644 index 000000000..5de86375d --- /dev/null +++ b/db/routines/vn2008/views/ticketCreationData.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`ticketCreationData` +AS SELECT dayname(`h`.`confirm_date`) AS `DiadelaSemana`, + HOUR(`h`.`confirm_date`) AS `Hora`, + cast(`h`.`confirm_date` AS date) AS `Fecha`, + `h`.`source_app` AS `Dispositivo` +FROM `hedera`.`order` `h` +WHERE `h`.`confirm_date` <> 0 diff --git a/db/routines/vn2008/views/ticketMRW.sql b/db/routines/vn2008/views/ticketMRW.sql new file mode 100644 index 000000000..1173c5180 --- /dev/null +++ b/db/routines/vn2008/views/ticketMRW.sql @@ -0,0 +1,38 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`ticketMRW` +AS SELECT `Tickets`.`Id_Agencia` AS `id_Agencia`, + `Tickets`.`empresa_id` AS `empresa_id`, + `Consignatarios`.`consignatario` AS `Consignatario`, + `Consignatarios`.`domicilio` AS `DOMICILIO`, + `Consignatarios`.`poblacion` AS `POBLACION`, + `Consignatarios`.`codPostal` AS `CODPOSTAL`, + `Consignatarios`.`telefono` AS `telefono`, + `Consignatarios`.`movil` AS `movil`, + `Clientes`.`if` AS `IF`, + `Tickets`.`Id_Ticket` AS `Id_Ticket`, + `Tickets`.`warehouse_id` AS `warehouse_id`, + `Consignatarios`.`id_consigna` AS `Id_Consigna`, + `Paises`.`Codigo` AS `CodigoPais`, + `Tickets`.`Fecha` AS `Fecha`, + `province`.`province_id` AS `province_id`, + `Tickets`.`landing` AS `landing` +FROM ( + ( + ( + ( + `vn2008`.`Clientes` + JOIN `vn2008`.`Consignatarios` ON( + `Clientes`.`id_cliente` = `Consignatarios`.`Id_cliente` + ) + ) + JOIN `vn2008`.`Tickets` ON( + `Consignatarios`.`id_consigna` = `Tickets`.`Id_Consigna` + ) + ) + JOIN `vn2008`.`province` ON( + `Consignatarios`.`province_id` = `province`.`province_id` + ) + ) + JOIN `vn2008`.`Paises` ON(`province`.`Paises_Id` = `Paises`.`Id`) + ) diff --git a/db/routines/vn2008/views/ticket_observation.sql b/db/routines/vn2008/views/ticket_observation.sql new file mode 100644 index 000000000..deb85e4b6 --- /dev/null +++ b/db/routines/vn2008/views/ticket_observation.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`ticket_observation` +AS SELECT `to`.`id` AS `ticket_observation_id`, + `to`.`ticketFk` AS `Id_Ticket`, + `to`.`observationTypeFk` AS `observation_type_id`, + `to`.`description` AS `text` +FROM `vn`.`ticketObservation` `to` diff --git a/db/routines/vn2008/views/tickets_gestdoc.sql b/db/routines/vn2008/views/tickets_gestdoc.sql new file mode 100644 index 000000000..a8682db57 --- /dev/null +++ b/db/routines/vn2008/views/tickets_gestdoc.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tickets_gestdoc` +AS SELECT `td`.`ticketFk` AS `Id_Ticket`, + `td`.`dmsFk` AS `gestdoc_id` +FROM `vn`.`ticketDms` `td` diff --git a/db/routines/vn2008/views/time.sql b/db/routines/vn2008/views/time.sql new file mode 100644 index 000000000..f3bbc8607 --- /dev/null +++ b/db/routines/vn2008/views/time.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`time` +AS SELECT `t`.`dated` AS `date`, + `t`.`period` AS `period`, + `t`.`month` AS `month`, + `t`.`year` AS `year`, + `t`.`day` AS `day`, + `t`.`week` AS `week`, + `t`.`yearMonth` AS `yearMonth` +FROM `vn`.`time` `t` diff --git a/db/routines/vn2008/views/tr2.sql b/db/routines/vn2008/views/tr2.sql new file mode 100644 index 000000000..e3b42c59a --- /dev/null +++ b/db/routines/vn2008/views/tr2.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`tr2` +AS SELECT `vn`.`travel`.`id` AS `id`, + `vn`.`travel`.`shipped` AS `shipped`, + `vn`.`travel`.`shipmentHour` AS `shipmentHour`, + `vn`.`travel`.`landed` AS `landed`, + `vn`.`travel`.`landingHour` AS `landingHour`, + `vn`.`travel`.`warehouseInFk` AS `warehouseInFk`, + `vn`.`travel`.`warehouseOutFk` AS `warehouseOutFk`, + `vn`.`travel`.`agencyModeFk` AS `agencyFk`, + `vn`.`travel`.`ref` AS `ref`, + `vn`.`travel`.`isDelivered` AS `isDelivered`, + `vn`.`travel`.`isReceived` AS `isReceived`, + `vn`.`travel`.`m3` AS `m3`, + `vn`.`travel`.`kg` AS `kg`, + `vn`.`travel`.`cargoSupplierFk` AS `cargoSupplierFk`, + `vn`.`travel`.`totalEntries` AS `totalEntries` +FROM `vn`.`travel` diff --git a/db/routines/vn2008/views/travel.sql b/db/routines/vn2008/views/travel.sql new file mode 100644 index 000000000..9c98120ef --- /dev/null +++ b/db/routines/vn2008/views/travel.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`travel` +AS SELECT `t`.`id` AS `id`, + `t`.`shipped` AS `shipment`, + `t`.`shipmentHour` AS `shipment_hour`, + `t`.`landed` AS `landing`, + `t`.`landingHour` AS `landing_hour`, + `t`.`warehouseInFk` AS `warehouse_id`, + `t`.`warehouseOutFk` AS `warehouse_id_out`, + `t`.`agencyModeFk` AS `agency_id`, + `t`.`ref` AS `ref`, + `t`.`isDelivered` AS `delivered`, + `t`.`isReceived` AS `received`, + `t`.`m3` AS `m3`, + `t`.`kg` AS `kg`, + `t`.`cargoSupplierFk` AS `cargoSupplierFk`, + `t`.`totalEntries` AS `totalEntries`, + `t`.`appointment` AS `appointment` +FROM `vn`.`travel` `t` diff --git a/db/routines/vn2008/views/travel_thermograph.sql b/db/routines/vn2008/views/travel_thermograph.sql new file mode 100644 index 000000000..e6f5ce954 --- /dev/null +++ b/db/routines/vn2008/views/travel_thermograph.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`travel_thermograph` +AS SELECT `tt`.`thermographFk` AS `thermograph_id`, + `tt`.`created` AS `odbc_date`, + `tt`.`warehouseFk` AS `warehouse_id`, + `tt`.`travelFk` AS `travel_id`, + `tt`.`temperatureFk` AS `temperature`, + `tt`.`result` AS `result`, + `tt`.`dmsFk` AS `gestdoc_id` +FROM `vn`.`travelThermograph` `tt` diff --git a/db/routines/vn2008/views/v_Articles_botanical.sql b/db/routines/vn2008/views/v_Articles_botanical.sql new file mode 100644 index 000000000..8640bb638 --- /dev/null +++ b/db/routines/vn2008/views/v_Articles_botanical.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_Articles_botanical` +AS SELECT `ib`.`itemFk` AS `itemFk`, + concat(`g`.`name`, ' ', IFNULL(`s`.`name`, '')) AS `ediBotanic` +FROM ( + ( + ( + `vn`.`itemBotanical` `ib` + LEFT JOIN `vn`.`genus` `g` ON(`g`.`id` = `ib`.`genusFk`) + ) + LEFT JOIN `vn`.`specie` `s` ON(`s`.`id` = `ib`.`specieFk`) + ) + LEFT JOIN `vn`.`ediSpecie` `es` ON(`es`.`id` = `ib`.`specieFk`) + ) diff --git a/db/routines/vn2008/views/v_account.sql b/db/routines/vn2008/views/v_account.sql new file mode 100644 index 000000000..51333f639 --- /dev/null +++ b/db/routines/vn2008/views/v_account.sql @@ -0,0 +1,5 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_account` +AS SELECT `a`.`id` AS `user_id` +FROM `account`.`account` `a` diff --git a/db/routines/vn2008/views/v_analisis_ventas.sql b/db/routines/vn2008/views/v_analisis_ventas.sql new file mode 100644 index 000000000..d95e5d274 --- /dev/null +++ b/db/routines/vn2008/views/v_analisis_ventas.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_analisis_ventas` +AS SELECT `bi`.`analisis_ventas`.`Familia` AS `Familia`, + `bi`.`analisis_ventas`.`Reino` AS `Reino`, + `bi`.`analisis_ventas`.`Comercial` AS `Comercial`, + `bi`.`analisis_ventas`.`Comprador` AS `Comprador`, + `bi`.`analisis_ventas`.`Provincia` AS `Provincia`, + `bi`.`analisis_ventas`.`almacen` AS `almacen`, + `bi`.`analisis_ventas`.`Año` AS `Año`, + `bi`.`analisis_ventas`.`Mes` AS `Mes`, + `bi`.`analisis_ventas`.`Semana` AS `Semana`, + `bi`.`analisis_ventas`.`Vista` AS `Vista`, + `bi`.`analisis_ventas`.`Importe` AS `Importe` +FROM `bi`.`analisis_ventas` diff --git a/db/routines/vn2008/views/v_barcodes.sql b/db/routines/vn2008/views/v_barcodes.sql new file mode 100644 index 000000000..b86af8c6b --- /dev/null +++ b/db/routines/vn2008/views/v_barcodes.sql @@ -0,0 +1,21 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_barcodes` +AS SELECT `Articles`.`Id_Article` AS `code`, + `Articles`.`Id_Article` AS `Id_Article` +FROM `vn2008`.`Articles` +UNION ALL +SELECT `barcodes`.`code` AS `code`, + `barcodes`.`Id_Article` AS `Id_Article` +FROM `vn2008`.`barcodes` +UNION ALL +SELECT `c`.`Id_Compra` AS `Id_Compra`, + `c`.`Id_Article` AS `Id_Article` +FROM ( + ( + `vn2008`.`Compres` `c` + JOIN `vn2008`.`Entradas` `e` ON(`c`.`Id_Entrada` = `e`.`Id_Entrada`) + ) + JOIN `vn2008`.`travel` `tr` ON(`tr`.`id` = `e`.`travel_id`) + ) +WHERE `tr`.`landing` >= `util`.`VN_CURDATE`() + INTERVAL -15 DAY diff --git a/db/routines/vn2008/views/v_compres.sql b/db/routines/vn2008/views/v_compres.sql new file mode 100644 index 000000000..8c52e2a72 --- /dev/null +++ b/db/routines/vn2008/views/v_compres.sql @@ -0,0 +1,90 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_compres` +AS SELECT `TP`.`Id_Tipo` AS `Familia`, + `RN`.`id` AS `reino_id`, + `C`.`Id_Compra` AS `Id_Compra`, + `C`.`Id_Entrada` AS `Id_Entrada`, + `C`.`Id_Article` AS `Id_Article`, + `C`.`Cantidad` AS `Cantidad`, + `C`.`Costefijo` AS `Costefijo`, + `C`.`Portefijo` AS `Portefijo`, + `C`.`Novincular` AS `Novincular`, + `C`.`Etiquetas` AS `Etiquetas`, + `C`.`Packing` AS `Packing`, + `C`.`grouping` AS `grouping`, + `C`.`Comisionfija` AS `Comisionfija`, + `C`.`Embalajefijo` AS `Embalajefijo`, + `C`.`Id_Cubo` AS `Id_Cubo`, + `C`.`Tarifa1` AS `Tarifa1`, + `C`.`Tarifa2` AS `Tarifa2`, + `C`.`Tarifa3` AS `Tarifa3`, + `C`.`PVP` AS `PVP`, + `C`.`Vida` AS `Vida`, + `C`.`Id_Trabajador` AS `Id_Trabajador`, + `C`.`punteo` AS `punteo`, + `C`.`odbc_date` AS `odbc_date`, + `E`.`Inventario` AS `Inventario`, + `E`.`Id_Proveedor` AS `Id_Proveedor`, + `E`.`Fecha` AS `Fecha`, + `E`.`Confirmada` AS `Confirmada`, + `E`.`Redada` AS `Redada`, + `E`.`empresa_id` AS `empresa_id`, + `E`.`travel_id` AS `travel_id`, + `E`.`Pedida` AS `Pedida`, + `E`.`recibida_id` AS `recibida_id`, + `TR`.`id` AS `id`, + `TR`.`shipment` AS `shipment`, + `TR`.`landing` AS `landing`, + `TR`.`warehouse_id` AS `warehouse_id`, + `TR`.`warehouse_id_out` AS `warehouse_id_out`, + `TR`.`agency_id` AS `agency_id`, + `TR`.`ref` AS `ref`, + `TR`.`delivered` AS `delivered`, + `TR`.`received` AS `received`, + `A`.`Article` AS `Article`, + `A`.`Medida` AS `Medida`, + `A`.`Tallos` AS `Tallos`, + `C`.`caja` AS `caja`, + `A`.`Categoria` AS `Categoria`, + `A`.`id_origen` AS `id_origen`, + `TP`.`Id_Tipo` AS `Tipo`, + `A`.`tipo_id` AS `tipo_id`, + `A`.`Color` AS `Color`, + `A`.`Min` AS `Min`, + `C`.`Costefijo` + `C`.`Embalajefijo` + `C`.`Comisionfija` + `C`.`Portefijo` AS `Coste`, + `W_OUT`.`fuente` AS `fuente`, + IF( + `cb`.`Volumen` > 0, + `cb`.`Volumen`, + `cb`.`X` * `cb`.`Y` * IF(`cb`.`Z` = 0, `A`.`Medida` + 10, `cb`.`Z`) + ) * `C`.`Etiquetas` AS `cm3`, + `A`.`producer_id` AS `producer_id` +FROM ( + ( + ( + ( + ( + ( + ( + ( + `vn2008`.`Compres` `C` + JOIN `vn2008`.`Entradas` `E` ON(`C`.`Id_Entrada` = `E`.`Id_Entrada`) + ) + JOIN `vn2008`.`travel` `TR` ON(`TR`.`id` = `E`.`travel_id`) + ) + JOIN `vn2008`.`warehouse` `W_IN` ON(`W_IN`.`id` = `TR`.`warehouse_id`) + ) + JOIN `vn2008`.`warehouse` `W_OUT` ON(`W_OUT`.`id` = `TR`.`warehouse_id_out`) + ) + JOIN `vn2008`.`Articles` `A` ON(`C`.`Id_Article` = `A`.`Id_Article`) + ) + JOIN `vn2008`.`Tipos` `TP` ON(`A`.`tipo_id` = `TP`.`tipo_id`) + ) + JOIN `vn2008`.`reinos` `RN` ON(`RN`.`id` = `TP`.`reino_id`) + ) + JOIN `vn2008`.`Cubos` `cb` ON(`cb`.`Id_Cubo` = `C`.`Id_Cubo`) + ) +WHERE `W_IN`.`fuente` = 0 + AND `E`.`Inventario` = 0 + AND `E`.`Redada` = 0 diff --git a/db/routines/vn2008/views/v_departure_limit.sql b/db/routines/vn2008/views/v_departure_limit.sql new file mode 100644 index 000000000..39478a54a --- /dev/null +++ b/db/routines/vn2008/views/v_departure_limit.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_departure_limit` +AS SELECT `cache`.`departure_limit`.`warehouse_id` AS `warehouse_id`, + `cache`.`departure_limit`.`fecha` AS `fecha`, + `cache`.`departure_limit`.`hora` AS `hora`, + `cache`.`departure_limit`.`minSpeed` AS `minSpeed` +FROM `cache`.`departure_limit` diff --git a/db/routines/vn2008/views/v_descuadre_bionic.sql b/db/routines/vn2008/views/v_descuadre_bionic.sql new file mode 100644 index 000000000..446c10694 --- /dev/null +++ b/db/routines/vn2008/views/v_descuadre_bionic.sql @@ -0,0 +1,41 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_descuadre_bionic` +AS SELECT `t`.`Id_Ticket` AS `Id_Ticket`, + `t`.`Alias` AS `Alias`, + `m`.`Concepte` AS `Concepte`, + sum(`mc`.`Valor`) AS `suma_componente`, + `m`.`Preu` AS `Preu`, + `m`.`Descuento` AS `Descuento`, + `m`.`Preu` * (100 - `m`.`Descuento`) / 100 - sum(`mc`.`Valor`) AS `diferencia`, + `t`.`Fecha` AS `Fecha`, + `m`.`Preu` > 0 + AND `tp`.`reino_id` <> 6 + AND `a`.`tipo_id` NOT IN (7, 115) AS `benvenut` +FROM ( + ( + ( + ( + ( + ( + `vn2008`.`Movimientos` `m` + JOIN `vn2008`.`Tickets` `t` ON(`m`.`Id_Ticket` = `t`.`Id_Ticket`) + ) + JOIN `vn2008`.`Clientes` `c` ON(`t`.`Id_Cliente` = `c`.`id_cliente`) + ) + JOIN `vn2008`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouse_id`) + ) + JOIN `vn2008`.`Articles` `a` ON(`m`.`Id_Article` = `a`.`Id_Article`) + ) + JOIN `vn2008`.`Tipos` `tp` ON(`a`.`tipo_id` = `tp`.`tipo_id`) + ) + LEFT JOIN `vn2008`.`Movimientos_componentes` `mc` ON(`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`) + ) +WHERE `t`.`Fecha` >= '2015-09-01' + AND `t`.`empresa_id` IN (442, 791, 567) + AND `w`.`reserve` <> 0 + AND `c`.`real` <> 0 + AND `tp`.`reino_id` <> 6 +GROUP BY `m`.`Id_Movimiento` +HAVING abs(`diferencia`) > 0.01 + OR `diferencia` IS NULL diff --git a/db/routines/vn2008/views/v_empresa.sql b/db/routines/vn2008/views/v_empresa.sql new file mode 100644 index 000000000..5a6d6e0f5 --- /dev/null +++ b/db/routines/vn2008/views/v_empresa.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_empresa` +AS SELECT `e`.`logo` AS `logo`, + `e`.`id` AS `id`, + `e`.`registro` AS `registro`, + `e`.`gerente_id` AS `gerente_id`, + `e`.`alta` AS `alta`, + `t`.`Nombre` AS `Nombre`, + `t`.`Apellidos` AS `Apellidos`, + `p`.`Proveedor` AS `Proveedor`, + `p`.`Domicilio` AS `Domicilio`, + `p`.`codpos` AS `CP`, + `p`.`Localidad` AS `Localidad`, + `p`.`NIF` AS `NIF`, + `p`.`Telefono` AS `Telefono`, + `p`.`Alias` AS `Alias`, + `e`.`abbreviation` AS `abbreviation` +FROM ( + ( + `vn2008`.`empresa` `e` + JOIN `vn2008`.`Trabajadores` `t` ON(`t`.`Id_Trabajador` = `e`.`gerente_id`) + ) + JOIN `vn2008`.`Proveedores` `p` ON(`p`.`Id_Proveedor` = `e`.`id`) + ) diff --git a/db/routines/vn2008/views/v_inter.sql b/db/routines/vn2008/views/v_inter.sql new file mode 100644 index 000000000..7701c8471 --- /dev/null +++ b/db/routines/vn2008/views/v_inter.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_inter` +AS SELECT `tt`.`id` AS `inter_id`, + `tt`.`stateFk` AS `state_id`, + `tt`.`notes` AS `nota`, + `tt`.`created` AS `odbc_date`, + `tt`.`ticketFk` AS `Id_Ticket`, + `tt`.`userFk` AS `Id_Trabajador`, + `tt`.`supervisorFk` AS `Id_supervisor` +FROM `vn`.`ticketTracking` `tt` diff --git a/db/routines/vn2008/views/v_jerarquia.sql b/db/routines/vn2008/views/v_jerarquia.sql new file mode 100644 index 000000000..6938a1fdf --- /dev/null +++ b/db/routines/vn2008/views/v_jerarquia.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_jerarquia` +AS SELECT `vn2008`.`jerarquia`.`worker_id` AS `Id_Trabajador`, + `vn2008`.`jerarquia`.`boss_id` AS `boss_id` +FROM `vn2008`.`jerarquia` +UNION ALL +SELECT DISTINCT `vn2008`.`jerarquia`.`boss_id` AS `Id_Trabajador`, + `vn2008`.`jerarquia`.`boss_id` AS `boss_id` +FROM `vn2008`.`jerarquia` diff --git a/db/routines/vn2008/views/v_miriam.sql b/db/routines/vn2008/views/v_miriam.sql new file mode 100644 index 000000000..70af88943 --- /dev/null +++ b/db/routines/vn2008/views/v_miriam.sql @@ -0,0 +1,23 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_miriam` +AS SELECT `M`.`Id_Article` AS `Id_Article`, + `M`.`Concepte` AS `Concepte`, + `M`.`Cantidad` AS `Cantidad`, + `M`.`Preu` AS `Preu`, + `M`.`Descuento` AS `Descuento`, + `T`.`Fecha` AS `Fecha`, + `T`.`Id_Cliente` AS `Id_Cliente`, + `M`.`Cantidad` * `M`.`Preu` * (100 - `M`.`Descuento`) / 100 AS `Importe` +FROM ( + ( + ( + `vn2008`.`Tickets` `T` + JOIN `vn2008`.`Movimientos` `M` ON(`T`.`Id_Ticket` = `M`.`Id_Ticket`) + ) + JOIN `vn2008`.`Articles` `A` ON(`M`.`Id_Article` = `A`.`Id_Article`) + ) + JOIN `vn2008`.`Tipos` `TP` ON(`A`.`tipo_id` = `TP`.`tipo_id`) + ) +WHERE `T`.`Fecha` >= '2011-01-01' + AND `A`.`tipo_id` = 7 diff --git a/db/routines/vn2008/views/v_price_fixed.sql b/db/routines/vn2008/views/v_price_fixed.sql new file mode 100644 index 000000000..db48e5a46 --- /dev/null +++ b/db/routines/vn2008/views/v_price_fixed.sql @@ -0,0 +1,35 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_price_fixed` +AS SELECT `pf`.`warehouse_id` AS `warehouse_id`, + `pf`.`item_id` AS `item_id`, + `pf`.`rate_0` AS `rate_0`, + `pf`.`rate_1` AS `rate_1`, + `pf`.`rate_2` AS `rate_2`, + `pf`.`rate_3` AS `rate_3`, + `pf`.`date_start` AS `date_start`, + `pf`.`date_end` AS `date_end`, + `pf`.`bonus` AS `bonus`, + `pf`.`grouping` AS `grouping`, + `pf`.`Packing` AS `Packing`, + `pf`.`caja` AS `caja` +FROM `vn2008`.`price_fixed` `pf` +WHERE `pf`.`warehouse_id` < 1000 +UNION ALL +SELECT `wg`.`warehouse_id` AS `warehouse_id`, + `pf`.`item_id` AS `item_id`, + `pf`.`rate_0` AS `rate_0`, + `pf`.`rate_1` AS `rate_1`, + `pf`.`rate_2` AS `rate_2`, + `pf`.`rate_3` AS `rate_3`, + `pf`.`date_start` AS `date_start`, + `pf`.`date_end` AS `date_end`, + `pf`.`bonus` AS `bonus`, + `pf`.`grouping` AS `grouping`, + `pf`.`Packing` AS `Packing`, + `pf`.`caja` AS `caja` +FROM ( + `vn2008`.`price_fixed` `pf` + JOIN `vn2008`.`warehouse_group` `wg` + ) +WHERE `wg`.`warehouse_alias_id` + 1000 = `pf`.`warehouse_id` diff --git a/db/routines/vn2008/views/v_price_fixed_group.sql b/db/routines/vn2008/views/v_price_fixed_group.sql new file mode 100644 index 000000000..d9add16ae --- /dev/null +++ b/db/routines/vn2008/views/v_price_fixed_group.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_price_fixed_group` +AS SELECT `pf`.`warehouse_id` AS `warehouse_id`, + `pf`.`item_id` AS `item_id`, + `pf`.`rate_0` AS `rate_0`, + `pf`.`rate_1` AS `rate_1`, + `pf`.`rate_2` AS `rate_2`, + `pf`.`rate_3` AS `rate_3`, + `pf`.`date_start` AS `date_start`, + `pf`.`date_end` AS `date_end`, + `pf`.`bonus` AS `bonus`, + `pf`.`grouping` AS `grouping`, + `pf`.`Packing` AS `Packing`, + `pf`.`caja` AS `caja` +FROM `vn2008`.`v_price_fixed` `pf` +GROUP BY `pf`.`warehouse_id`, + `pf`.`item_id`, + `pf`.`date_start`, + `pf`.`date_end` diff --git a/db/routines/vn2008/views/v_ticket_amount.sql b/db/routines/vn2008/views/v_ticket_amount.sql new file mode 100644 index 000000000..142bec74d --- /dev/null +++ b/db/routines/vn2008/views/v_ticket_amount.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_ticket_amount` +AS SELECT `Movimientos`.`Id_Ticket` AS `Id_Ticket`, + sum( + `Movimientos`.`Cantidad` * `Movimientos`.`Preu` * (100 - `Movimientos`.`Descuento`) / 100 + ) AS `amount` +FROM ( + `vn2008`.`Movimientos` + JOIN `vn2008`.`Tickets` ON( + `Movimientos`.`Id_Ticket` = `Tickets`.`Id_Ticket` + ) + ) +WHERE `Tickets`.`Fecha` >= `util`.`VN_CURDATE`() + INTERVAL -6 MONTH +GROUP BY `Movimientos`.`Id_Ticket` diff --git a/db/routines/vn2008/views/v_ventes.sql b/db/routines/vn2008/views/v_ventes.sql new file mode 100644 index 000000000..9fd87a002 --- /dev/null +++ b/db/routines/vn2008/views/v_ventes.sql @@ -0,0 +1,68 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_ventes` +AS SELECT `Agencias`.`Agencia` AS `Agencia`, + `A`.`Categoria` AS `Categoria`, + `A`.`tipo_id` AS `tipo_id`, + `A`.`Medida` AS `Medida`, + `A`.`Article` AS `Article`, + `A`.`Color` AS `Color`, + `CS`.`Id_cliente` AS `Id_Cliente`, + `TP`.`Id_Tipo` AS `Tipo`, + `T`.`Factura` AS `Factura`, + `T`.`warehouse_id` AS `warehouse_id`, + `M`.`Id_Movimiento` AS `Id_Movimiento`, + `M`.`Id_Article` AS `Id_Article`, + `TP`.`Id_Tipo` AS `Familia`, + `M`.`Id_Ticket` AS `Id_Ticket`, + `M`.`Concepte` AS `Concepte`, + `M`.`Cantidad` AS `Cantidad`, + `M`.`quantity` AS `quantity`, + `M`.`Preu` AS `Preu`, + `M`.`Descuento` AS `Descuento`, + IF( + `T`.`Fecha` >= '2015-10-01', + `M`.`CostFixat`, + `M`.`Preu` * (100 - `M`.`Descuento`) / 100 + ) AS `CostFixat`, + `M`.`Reservado` AS `Reservado`, + `M`.`OK` AS `OK`, + `M`.`PrecioFijado` AS `PrecioFijado`, + `M`.`odbc_date` AS `odbc_date`, + cast(`T`.`Fecha` AS date) AS `Fecha`, + `T`.`Fecha` AS `FechaCompleta`, + `CS`.`consignatario` AS `Alias`, + `T`.`Id_Consigna` AS `Id_Consigna`, + `M`.`Cantidad` * `M`.`Preu` * (100 - `M`.`Descuento`) / 100 AS `Importe`, + `O`.`Origen` AS `Origen`, + `TP`.`reino_id` AS `reino_id`, + `C`.`invoice` AS `invoice`, + `A`.`producer_id` AS `producer_id` +FROM ( + ( + ( + ( + ( + ( + ( + ( + `vn2008`.`Movimientos` `M` + JOIN `vn2008`.`Tickets` `T` ON(`M`.`Id_Ticket` = `T`.`Id_Ticket`) + ) + JOIN `vn2008`.`Consignatarios` `CS` ON(`CS`.`id_consigna` = `T`.`Id_Consigna`) + ) + JOIN `vn2008`.`Clientes` `C` ON(`CS`.`Id_cliente` = `C`.`id_cliente`) + ) + JOIN `vn2008`.`Articles` `A` ON(`M`.`Id_Article` = `A`.`Id_Article`) + ) + JOIN `vn2008`.`Origen` `O` ON(`O`.`id` = `A`.`id_origen`) + ) + JOIN `vn2008`.`Tipos` `TP` ON(`A`.`tipo_id` = `TP`.`tipo_id`) + ) + JOIN `vn2008`.`reinos` `r` ON(`TP`.`reino_id` = `r`.`id`) + ) + JOIN `vn2008`.`Agencias` ON(`Agencias`.`Id_Agencia` = `T`.`Id_Agencia`) + ) +WHERE `T`.`Fecha` >= '2013-01-01' + AND `C`.`real` > 0 + AND `r`.`id` <> 6 diff --git a/db/routines/vn2008/views/v_warehouse.sql b/db/routines/vn2008/views/v_warehouse.sql new file mode 100644 index 000000000..fd17b6a06 --- /dev/null +++ b/db/routines/vn2008/views/v_warehouse.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_warehouse` +AS SELECT `warehouse`.`id` AS `id`, + `warehouse`.`name` AS `almacen` +FROM `vn2008`.`warehouse` +UNION ALL +SELECT 1000 + `warehouse_alias`.`warehouse_alias_id` AS `warehouse_alias_id`, + concat(`warehouse_alias`.`alias`, '(G)') AS `concat(alias, '(G)')` +FROM `vn2008`.`warehouse_alias` diff --git a/db/routines/vn2008/views/v_xsubclien.sql b/db/routines/vn2008/views/v_xsubclien.sql new file mode 100644 index 000000000..bbe5803e0 --- /dev/null +++ b/db/routines/vn2008/views/v_xsubclien.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_xsubclien` +AS SELECT DISTINCT `Facturas`.`Id_Cliente` AS `Id_Cliente`, + `Facturas`.`empresa_id` AS `empresa_id` +FROM `vn2008`.`Facturas` +WHERE `Facturas`.`Fecha` > `util`.`VN_CURDATE`() + INTERVAL -2 MONTH +UNION +SELECT `Recibos`.`Id_Cliente` AS `Id_Cliente`, + `Recibos`.`empresa_id` AS `empresa_id` +FROM `vn2008`.`Recibos` +WHERE `Recibos`.`Fechacobro` > `util`.`VN_CURDATE`() + INTERVAL -2 MONTH diff --git a/db/routines/vn2008/views/v_xsubcuentas.sql b/db/routines/vn2008/views/v_xsubcuentas.sql new file mode 100644 index 000000000..79f26216c --- /dev/null +++ b/db/routines/vn2008/views/v_xsubcuentas.sql @@ -0,0 +1,169 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_xsubcuentas` +AS SELECT `Clientes`.`Cuenta` AS `COD`, + `Clientes`.`razonSocial` AS `TITULO`, + concat( + IF( + `p`.`CEE` = 1 + AND ascii(left(`Clientes`.`if`, 1)) < 58, + `p`.`Codigo`, + '' + ), + `Clientes`.`if` + ) AS `NIF`, + `Clientes`.`domicilio` AS `DOMICILIO`, + `Clientes`.`poblacion` AS `POBLACION`, + `province`.`name` AS `PROVINCIA`, + `Clientes`.`codPostal` AS `CODPOSTAL`, + `p`.`Codigo` AS `country_code`, + `v_xsubclien`.`empresa_id` AS `empresa_id`, + substr( + `Clientes`.`e-mail`, + 1, + coalesce(nullif(locate(',', `Clientes`.`e-mail`), 0), 99) - 1 + ) AS `EMAIL`, + IF( + `p`.`CEE` = 0 + OR `p`.`CEE` = 1 + AND `Clientes`.`vies` = 0, + 1, + IF( + `p`.`CEE` = 1 + AND `Clientes`.`vies` <> 0, + 2, + 4 + ) + ) AS `IDNIF` +FROM ( + ( + ( + `vn2008`.`Clientes` + JOIN `vn2008`.`v_xsubclien` ON( + `Clientes`.`id_cliente` = `v_xsubclien`.`Id_Cliente` + ) + ) + LEFT JOIN `vn2008`.`Paises` `p` ON(`p`.`Id` = `Clientes`.`Id_Pais`) + ) + JOIN `vn2008`.`province` ON( + `Clientes`.`province_id` = `province`.`province_id` + ) + ) +GROUP BY `Clientes`.`id_cliente`, + `v_xsubclien`.`empresa_id` +UNION ALL +SELECT `Proveedores`.`cuenta` AS `Cuenta`, + `Proveedores`.`Proveedor` AS `Proveedor`, + concat( + IF( + `p`.`CEE` = 1 + AND ascii(left(`Proveedores`.`NIF`, 1)) < 58, + `p`.`Codigo`, + '' + ), + `Proveedores`.`NIF` + ) AS `NIF`, + `Proveedores`.`Domicilio` AS `Domicilio`, + `Proveedores`.`Localidad` AS `Localidad`, + `prov`.`name` AS `Provincia`, + `Proveedores`.`codpos` AS `CP`, + `p`.`Codigo` AS `country_code`, + `v_xsubprov`.`empresa_id` AS `empresa_id`, + substr( + `c`.`email`, + 1, + coalesce(nullif(locate(',', `c`.`email`), 0), 99) - 1 + ) AS `EMAIL`, + IF(`p`.`CEE` = 0, 1, IF(`p`.`CEE` = 1, 2, 4)) AS `IDNIF` +FROM ( + ( + ( + ( + `vn2008`.`Proveedores` + JOIN `vn2008`.`v_xsubprov` ON( + `Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id` + ) + ) + LEFT JOIN `vn2008`.`Paises` `p` ON(`p`.`Id` = `Proveedores`.`pais_id`) + ) + LEFT JOIN `vn2008`.`province` `prov` ON( + `prov`.`province_id` = `Proveedores`.`province_id` + ) + ) + LEFT JOIN `vn`.`supplierContact` `c` ON(`c`.`supplierFk` = `Proveedores`.`Id_Proveedor`) + ) +WHERE `Proveedores`.`oficial` <> 0 +GROUP BY `v_xsubprov`.`proveedor_id`, + `v_xsubprov`.`empresa_id` +UNION ALL +SELECT `Gastos`.`Id_Gasto` COLLATE utf8mb3_unicode_ci AS `Id_Gasto`, + `Gastos`.`Gasto` COLLATE utf8mb3_unicode_ci AS `Gasto`, + NULL AS `NULL`, + NULL AS `My_exp_NULL`, + NULL AS `My_exp_1_NULL`, + NULL AS `My_exp_2_NULL`, + NULL AS `My_exp_3_NULL`, + NULL AS `country_code`, + `e`.`id` AS `id`, + NULL AS `EMAIL`, + 1 AS `IDNIF` +FROM ( + `vn2008`.`Gastos` + JOIN `vn2008`.`empresa` `e` ON(`e`.`id` = 442) + ) +UNION ALL +SELECT `Bancos`.`Cuenta` AS `Cuenta`, + `Bancos`.`Banco` AS `Banco`, + NULL AS `NULL`, + NULL AS `My_exp_NULL`, + NULL AS `My_exp_1_NULL`, + NULL AS `My_exp_2_NULL`, + NULL AS `My_exp_3_NULL`, + NULL AS `country_code`, + `e`.`id` AS `id`, + NULL AS `EMAIL`, + 1 AS `IDNIF` +FROM ( + `vn2008`.`Bancos` + JOIN `vn2008`.`empresa` `e` ON(`e`.`id` = 442) + ) +UNION ALL +SELECT lpad(right(`Proveedores`.`cuenta`, 5), 10, '47510000') AS `Cuenta`, + `Proveedores`.`Proveedor` AS `Proveedor`, + `Proveedores`.`NIF` AS `NIF`, + `Proveedores`.`Domicilio` AS `Domicilio`, + `Proveedores`.`Localidad` AS `Localidad`, + `prov`.`name` AS `Provincia`, + `Proveedores`.`codpos` AS `CP`, + `p`.`Codigo` AS `country_code`, + `v_xsubprov`.`empresa_id` AS `empresa_id`, + substr( + `c`.`email`, + 1, + coalesce(nullif(locate(',', `c`.`email`), 0), 99) - 1 + ) AS `EMAIL`, + IF(`p`.`CEE` = 0, 1, IF(`p`.`CEE` = 1, 2, 4)) AS `IDNIF` +FROM ( + ( + ( + ( + `vn2008`.`Proveedores` + JOIN `vn2008`.`v_xsubprov` ON( + `Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id` + ) + ) + LEFT JOIN `vn2008`.`Paises` `p` ON(`p`.`Id` = `Proveedores`.`pais_id`) + ) + LEFT JOIN `vn2008`.`province` `prov` ON( + `prov`.`province_id` = `Proveedores`.`province_id` + ) + ) + LEFT JOIN `vn`.`supplierContact` `c` ON(`c`.`supplierFk` = `Proveedores`.`Id_Proveedor`) + ) +WHERE ( + `Proveedores`.`cuenta` LIKE '_____3____' + OR `Proveedores`.`cuenta` LIKE '_____2____' + ) + AND `Proveedores`.`oficial` = 1 +GROUP BY `v_xsubprov`.`proveedor_id`, + `v_xsubprov`.`empresa_id` diff --git a/db/routines/vn2008/views/v_xsubprov.sql b/db/routines/vn2008/views/v_xsubprov.sql new file mode 100644 index 000000000..abbedbe5e --- /dev/null +++ b/db/routines/vn2008/views/v_xsubprov.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`v_xsubprov` +AS SELECT `recibida`.`proveedor_id` AS `proveedor_id`, + `recibida`.`empresa_id` AS `empresa_id` +FROM `vn2008`.`recibida` +WHERE `recibida`.`fecha` > `util`.`VN_CURDATE`() + INTERVAL -3 MONTH +GROUP BY `recibida`.`proveedor_id`, + `recibida`.`empresa_id` +UNION ALL +SELECT `pago`.`id_proveedor` AS `id_proveedor`, + `pago`.`empresa_id` AS `empresa_id` +FROM `vn2008`.`pago` +WHERE `pago`.`fecha` > `util`.`VN_CURDATE`() + INTERVAL -3 MONTH +GROUP BY `pago`.`id_proveedor`, + `pago`.`empresa_id` diff --git a/db/routines/vn2008/views/versiones.sql b/db/routines/vn2008/views/versiones.sql new file mode 100644 index 000000000..04e63dbb4 --- /dev/null +++ b/db/routines/vn2008/views/versiones.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`versiones` +AS SELECT `m`.`app` AS `programa`, + `m`.`version` AS `version`, + 0 AS `critical` +FROM `vn`.`mdbVersion` `m` +WHERE `m`.`branchFk` = 'master' diff --git a/db/routines/vn2008/views/vnCreditClassification.sql b/db/routines/vn2008/views/vnCreditClassification.sql new file mode 100644 index 000000000..4dcc590e4 --- /dev/null +++ b/db/routines/vn2008/views/vnCreditClassification.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`vnCreditClassification` +AS SELECT `vn`.`creditClassification`.`id` AS `id`, + `vn`.`creditClassification`.`client` AS `client`, + `vn`.`creditClassification`.`dateStart` AS `dateStart`, + `vn`.`creditClassification`.`dateEnd` AS `dateEnd` +FROM `vn`.`creditClassification` diff --git a/db/routines/vn2008/views/vnCreditInsurance.sql b/db/routines/vn2008/views/vnCreditInsurance.sql new file mode 100644 index 000000000..305ff2f4b --- /dev/null +++ b/db/routines/vn2008/views/vnCreditInsurance.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`vnCreditInsurance` +AS SELECT `vn`.`creditInsurance`.`id` AS `id`, + `vn`.`creditInsurance`.`creditClassification` AS `creditClassification`, + `vn`.`creditInsurance`.`credit` AS `credit`, + `vn`.`creditInsurance`.`creationDate` AS `creationDate`, + `vn`.`creditInsurance`.`grade` AS `grade` +FROM `vn`.`creditInsurance` diff --git a/db/routines/vn2008/views/vnSolunionCAP.sql b/db/routines/vn2008/views/vnSolunionCAP.sql new file mode 100644 index 000000000..65bd2470d --- /dev/null +++ b/db/routines/vn2008/views/vnSolunionCAP.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`vnSolunionCAP` +AS SELECT `vn`.`solunionCAP`.`creditInsurance` AS `creditInsurance`, + `vn`.`solunionCAP`.`dateStart` AS `dateStart`, + `vn`.`solunionCAP`.`dateEnd` AS `dateEnd`, + `vn`.`solunionCAP`.`dateLeaving` AS `dateLeaving` +FROM `vn`.`solunionCAP` diff --git a/db/routines/vn2008/views/warehouse.sql b/db/routines/vn2008/views/warehouse.sql new file mode 100644 index 000000000..5199d5c8e --- /dev/null +++ b/db/routines/vn2008/views/warehouse.sql @@ -0,0 +1,21 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`warehouse` +AS SELECT `w`.`id` AS `id`, + `w`.`name` AS `name`, + `w`.`isInventory` AS `inventario`, + `w`.`isFeedStock` AS `fuente`, + `w`.`isComparative` AS `is_comparative`, + `w`.`hasComission` AS `comisionantes`, + `w`.`hasAvailable` AS `reserve`, + `w`.`isManaged` AS `isManaged`, + `w`.`isForTicket` AS `tpv`, + `w`.`hasStowaway` AS `hasStowaway`, + `w`.`hasDms` AS `hasDms`, + `w`.`addressName` AS `address_name`, + `w`.`delay` AS `delay`, + `w`.`countryFk` AS `Id_Paises`, + `w`.`labelZone` AS `zone_label`, + `w`.`valuatedInventory` AS `valuatedInventory`, + `w`.`hasConfectionTeam` AS `hasConfectionTeam` +FROM `vn`.`warehouse` `w` diff --git a/db/routines/vn2008/views/warehouse_alias.sql b/db/routines/vn2008/views/warehouse_alias.sql new file mode 100644 index 000000000..9a151c9d5 --- /dev/null +++ b/db/routines/vn2008/views/warehouse_alias.sql @@ -0,0 +1,6 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`warehouse_alias` +AS SELECT `wa`.`id` AS `warehouse_alias_id`, + `wa`.`name` AS `alias` +FROM `vn`.`warehouseAlias` `wa` diff --git a/db/routines/vn2008/views/workcenter_holiday.sql b/db/routines/vn2008/views/workcenter_holiday.sql new file mode 100644 index 000000000..55ce6618c --- /dev/null +++ b/db/routines/vn2008/views/workcenter_holiday.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`workcenter_holiday` +AS SELECT `wh`.`workCenterFk` AS `workcenter_id`, + `wh`.`days` AS `day`, + `wh`.`year` AS `year` +FROM `vn`.`workCenterHoliday` `wh` diff --git a/db/routines/vn2008/views/workerDocument.sql b/db/routines/vn2008/views/workerDocument.sql new file mode 100644 index 000000000..7aca7497f --- /dev/null +++ b/db/routines/vn2008/views/workerDocument.sql @@ -0,0 +1,8 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`workerDocument` +AS SELECT `vn`.`workerDocument`.`id` AS `id`, + `vn`.`workerDocument`.`worker` AS `worker`, + `vn`.`workerDocument`.`document` AS `document`, + `vn`.`workerDocument`.`isReadableByWorker` AS `isReadableByWorker` +FROM `vn`.`workerDocument` diff --git a/db/routines/vn2008/views/workerTeam.sql b/db/routines/vn2008/views/workerTeam.sql new file mode 100644 index 000000000..6db6c094a --- /dev/null +++ b/db/routines/vn2008/views/workerTeam.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`workerTeam` +AS SELECT `wt`.`team` AS `team`, + `wt`.`id` AS `id`, + `wt`.`workerFk` AS `user` +FROM `vn`.`workerTeam` `wt` diff --git a/db/routines/vn2008/views/zoneNickname.sql b/db/routines/vn2008/views/zoneNickname.sql new file mode 100644 index 000000000..67a126851 --- /dev/null +++ b/db/routines/vn2008/views/zoneNickname.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`zoneNickname` +AS SELECT `ap`.`warehouse_id` AS `warehouse_id`, + `ap`.`agency_id` AS `agency_id`, + `ap`.`zona` AS `zona`, + concat( + 'ZONA ', + `ap`.`zona`, + ' ', + IF(`ap`.`zona` = 20, 'Madrid', `p`.`name`) + ) AS `alias` +FROM ( + `vn2008`.`Agencias_province` `ap` + JOIN `vn2008`.`province` `p` ON(`p`.`province_id` = `ap`.`province_id`) + ) +GROUP BY `ap`.`zona`, + `ap`.`warehouse_id`, + `ap`.`agency_id` diff --git a/db/tests.js b/db/tests.js deleted file mode 100644 index 74ea9a80b..000000000 --- a/db/tests.js +++ /dev/null @@ -1,39 +0,0 @@ -process.on('warning', warning => { - console.log(warning.name); - console.log(warning.message); - console.log(warning.stack); -}); - -let verbose = false; - -if (process.argv[2] === '--v') - verbose = true; - -let app = require(`vn-loopback/server/server`); -app.boot(); -loopbackApp = 'vn-loopback/server/server'; - -let Jasmine = require('jasmine'); -let jasmine = new Jasmine(); -let SpecReporter = require('jasmine-spec-reporter').SpecReporter; - -let serviceSpecs = [ - './tests/**/*[sS]pec.js' -]; - -jasmine.loadConfig({ - spec_dir: 'db', - spec_files: serviceSpecs, - helpers: [] -}); - -jasmine.addReporter(new SpecReporter({ - spec: { - // displayStacktrace: 'summary', - displaySuccessful: verbose, - displayFailedSpec: true, - displaySpecDuration: true - } -})); - -jasmine.execute(); diff --git a/db/tests/cache/last_buy_refresh.spec.js b/db/tests/cache/last_buy_refresh.spec.js deleted file mode 100644 index 71a9c3872..000000000 --- a/db/tests/cache/last_buy_refresh.spec.js +++ /dev/null @@ -1,42 +0,0 @@ -const app = require(`${loopbackApp}`); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('last_buy_refresh()', () => { - it(`should store some data on cache.last_buy`, async() => { - const stmts = []; - - stmts.push('START TRANSACTION'); - - const lastBuyTableIndex = stmts.push(`SELECT * FROM cache.last_buy ORDER BY item_id ASC`) - 1; - - stmts.push('ROLLBACK'); - - const sql = ParameterizedSQL.join(stmts, ';'); - const result = await app.models.Ticket.rawStmt(sql); - - const lastBuyTable = result[lastBuyTableIndex]; - - expect(lastBuyTable.length).toEqual(12); - - expect(lastBuyTable[0].item_id).toEqual(1); - expect(lastBuyTable[1].item_id).toEqual(1); - expect(lastBuyTable[2].item_id).toEqual(1); - expect(lastBuyTable[3].item_id).toEqual(2); - expect(lastBuyTable[4].item_id).toEqual(2); - expect(lastBuyTable[5].item_id).toEqual(3); - - expect(lastBuyTable[0].warehouse_id).toEqual(1); - expect(lastBuyTable[1].warehouse_id).toEqual(3); - expect(lastBuyTable[2].warehouse_id).toEqual(5); - expect(lastBuyTable[3].warehouse_id).toEqual(1); - expect(lastBuyTable[4].warehouse_id).toEqual(5); - expect(lastBuyTable[5].warehouse_id).toEqual(1); - - expect(lastBuyTable[1].buy_id).toEqual(10); - expect(lastBuyTable[0].buy_id).toEqual(3); - expect(lastBuyTable[2].buy_id).toEqual(13); - expect(lastBuyTable[3].buy_id).toEqual(4); - expect(lastBuyTable[4].buy_id).toEqual(14); - expect(lastBuyTable[5].buy_id).toEqual(5); - }); -}); diff --git a/db/tests/vn/buyUltimate.spec.js b/db/tests/vn/buyUltimate.spec.js deleted file mode 100644 index 4c98945c1..000000000 --- a/db/tests/vn/buyUltimate.spec.js +++ /dev/null @@ -1,55 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('buyUltimate()', () => { - const today = Date.vnNew(); - it(`should create buyUltimate temporal table and update it's values`, async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - warehouseFk: 1, - date: today - }; - - stmt = new ParameterizedSQL('CALL vn.buyUltimate(?, ?)', [ - params.warehouseFk, - params.date - ]); - stmts.push(stmt); - - let buyUltimateTableIndex = stmts.push(`SELECT * FROM tmp.buyUltimate ORDER BY itemFk ASC`) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let buyUltimateTable = result[buyUltimateTableIndex]; - - expect(buyUltimateTable.length).toEqual(6); - - expect(buyUltimateTable[0].itemFk).toEqual(1); - expect(buyUltimateTable[1].itemFk).toEqual(2); - expect(buyUltimateTable[2].itemFk).toEqual(3); - expect(buyUltimateTable[3].itemFk).toEqual(4); - expect(buyUltimateTable[4].itemFk).toEqual(8); - expect(buyUltimateTable[5].itemFk).toEqual(9); - - expect(buyUltimateTable[0].warehouseFk).toEqual(1); - expect(buyUltimateTable[1].warehouseFk).toEqual(1); - expect(buyUltimateTable[2].warehouseFk).toEqual(1); - expect(buyUltimateTable[3].warehouseFk).toEqual(1); - expect(buyUltimateTable[4].warehouseFk).toEqual(1); - expect(buyUltimateTable[5].warehouseFk).toEqual(1); - - expect(buyUltimateTable[1].buyFk).toEqual(4); - expect(buyUltimateTable[0].buyFk).toEqual(3); - expect(buyUltimateTable[2].buyFk).toEqual(5); - expect(buyUltimateTable[3].buyFk).toEqual(9); - expect(buyUltimateTable[4].buyFk).toEqual(6); - expect(buyUltimateTable[5].buyFk).toEqual(7); - }); -}); diff --git a/db/tests/vn/buyUltimateFromInterval.spec.js b/db/tests/vn/buyUltimateFromInterval.spec.js deleted file mode 100644 index 7a4a79d47..000000000 --- a/db/tests/vn/buyUltimateFromInterval.spec.js +++ /dev/null @@ -1,132 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('buyUltimateFromInterval()', () => { - let today; - let future; - beforeAll(() => { - let now = Date.vnNew(); - now.setHours(0, 0, 0, 0); - today = now; - - let futureDate = new Date(now); - let futureMonth = now.getMonth() + 1; - futureDate.setMonth(futureMonth); - future = futureDate; - }); - - it(`should create a temporal table with it's data`, async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - warehouseFk: 1, - started: today, - ended: today - }; - - stmt = new ParameterizedSQL('CALL vn.buyUltimateFromInterval(?, ?, ?)', [ - params.warehouseFk, - params.started, - params.ended - ]); - stmts.push(stmt); - - let buyUltimateFromIntervalTableIndex = stmts.push(`SELECT * FROM tmp.buyUltimateFromInterval`) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let buyUltimateFromIntervalTable = result[buyUltimateFromIntervalTableIndex]; - - expect(buyUltimateFromIntervalTable.length).toEqual(2); - - expect(buyUltimateFromIntervalTable[0].itemFk).toEqual(1); - expect(buyUltimateFromIntervalTable[1].itemFk).toEqual(3); - - expect(buyUltimateFromIntervalTable[0].warehouseFk).toEqual(1); - expect(buyUltimateFromIntervalTable[1].warehouseFk).toEqual(1); - - expect(buyUltimateFromIntervalTable[0].buyFk).toEqual(3); - expect(buyUltimateFromIntervalTable[1].buyFk).toEqual(5); - - expect(buyUltimateFromIntervalTable[0].landed).toEqual(today); - expect(buyUltimateFromIntervalTable[1].landed).toEqual(today); - }); - - it(`should create a temporal table with it's data in which started value is assigned to ended`, async() => { - let params = { - warehouseFk: 1, - started: today, - ended: null - }; - - let query = ` - START TRANSACTION; - CALL vn.buyUltimateFromInterval(?, ?, ?); - SELECT * FROM tmp.buyUltimateFromInterval; - ROLLBACK;`; - - let result = await app.models.Ticket.rawSql(query, [ - params.warehouseFk, - params.started, - params.ended - ]); - - let buyUltimateFromIntervalTable = result[2]; - - expect(buyUltimateFromIntervalTable.length).toEqual(2); - - expect(buyUltimateFromIntervalTable[0].itemFk).toEqual(1); - expect(buyUltimateFromIntervalTable[1].itemFk).toEqual(3); - - expect(buyUltimateFromIntervalTable[0].warehouseFk).toEqual(1); - expect(buyUltimateFromIntervalTable[1].warehouseFk).toEqual(1); - - expect(buyUltimateFromIntervalTable[0].buyFk).toEqual(3); - expect(buyUltimateFromIntervalTable[1].buyFk).toEqual(5); - - expect(buyUltimateFromIntervalTable[0].landed).toEqual(today); - expect(buyUltimateFromIntervalTable[1].landed).toEqual(today); - }); - - it(`should create a temporal table with it's data in which ended value is a date in the future`, async() => { - let params = { - warehouseFk: 1, - started: today, - ended: future - }; - - let query = ` - START TRANSACTION; - CALL vn.buyUltimateFromInterval(?, ?, ?); - SELECT * FROM tmp.buyUltimateFromInterval; - ROLLBACK;`; - - let result = await app.models.Ticket.rawSql(query, [ - params.warehouseFk, - params.started, - params.ended - ]); - - let buyUltimateFromIntervalTable = result[2]; - - expect(buyUltimateFromIntervalTable.length).toEqual(2); - - expect(buyUltimateFromIntervalTable[0].itemFk).toEqual(1); - expect(buyUltimateFromIntervalTable[1].itemFk).toEqual(3); - - expect(buyUltimateFromIntervalTable[0].warehouseFk).toEqual(1); - expect(buyUltimateFromIntervalTable[1].warehouseFk).toEqual(1); - - expect(buyUltimateFromIntervalTable[0].buyFk).toEqual(3); - expect(buyUltimateFromIntervalTable[1].buyFk).toEqual(5); - - expect(buyUltimateFromIntervalTable[0].landed).toEqual(today); - expect(buyUltimateFromIntervalTable[1].landed).toEqual(today); - }); -}); diff --git a/db/tests/vn/item_getBalance.spec.js b/db/tests/vn/item_getBalance.spec.js deleted file mode 100644 index 74e1e6659..000000000 --- a/db/tests/vn/item_getBalance.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('item_getBalance()', () => { - it(`should return the item balance ordered by alert level`, async() => { - let stmts = []; - - let params = { - itemFk: 1, - warehouseFk: 1 - }; - - const conn = await app.models.Item.dataSource.connector; - - stmts.push(new ParameterizedSQL('CALL vn.item_getBalance(?, ?, NULL)', [ - params.warehouseFk, - params.itemFk - ])); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await conn.executeStmt(sql); - let itemBalance = result[0]; - - expect(itemBalance[0].alertLevel).toBeGreaterThanOrEqual(itemBalance[1].alertLevel); - expect(itemBalance[1].alertLevel).toBeGreaterThanOrEqual(itemBalance[2].alertLevel); - expect(itemBalance[2].alertLevel).toBeGreaterThanOrEqual(itemBalance[3].alertLevel); - expect(itemBalance[3].alertLevel).toBeGreaterThanOrEqual(itemBalance[4].alertLevel); - expect(itemBalance[4].alertLevel).toBeGreaterThanOrEqual(itemBalance[5].alertLevel); - expect(itemBalance[5].alertLevel).toBeGreaterThanOrEqual(itemBalance[6].alertLevel); - }); -}); diff --git a/db/tests/vn/ticketCalculateClon.spec.js b/db/tests/vn/ticketCalculateClon.spec.js deleted file mode 100644 index 665d52ed0..000000000 --- a/db/tests/vn/ticketCalculateClon.spec.js +++ /dev/null @@ -1,108 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('ticket ticketCalculateClon()', () => { - const today = Date.vnNew(); - it('should add the ticket to the order containing the original ticket', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - clientFk: 1101, - shipped: today, - warehouseFk: 1, - companyFk: 442, - addressFk: 121, - agencyType: 23, - routeFk: 1, - landed: today, - userId: 21, - originalTicketId: 11 - }; - - stmt = new ParameterizedSQL('CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @result)', [ - params.clientFk, - params.shipped, - params.warehouseFk, - params.companyFk, - params.addressFk, - params.agencyType, - params.routeFk, - params.landed, - params.userId, - true - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('CALL vn.ticketCalculateClon(@result, ?)', [params.originalTicketId]); - stmts.push(stmt); - - let orderIndex = stmts.push(`SELECT * FROM vn.orderTicket WHERE ticketFk = @result`) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let expectedOrder = 11; - let newestTicketIdInFixtures = 21; - - expect(result[orderIndex][0].orderFk).toEqual(expectedOrder); - expect(result[orderIndex][0].ticketFk).toBeGreaterThan(newestTicketIdInFixtures); - }); - - it('should add the ticket to the order containing the original ' + - 'ticket and generate landed value if it was null', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - clientFk: 1101, - shipped: today, - warehouseFk: 1, - companyFk: 442, - addressFk: 121, - agencyType: 23, - routeFk: 1, - landed: null, - userId: 21, - originalTicketId: 11 - }; - - stmt = new ParameterizedSQL('CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @result)', [ - params.clientFk, - params.shipped, - params.warehouseFk, - params.companyFk, - params.addressFk, - params.agencyType, - params.routeFk, - params.landed, - params.userId, - true - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('CALL vn.ticketCalculateClon(@result, ?)', [params.originalTicketId]); - stmts.push(stmt); - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - - let error; - - try { - await app.models.Ticket.rawStmt(sql); - } catch (e) { - error = e; - } - - expect(error).toBeDefined(); - expect(error.statusCode).toBe(500); - expect(error.code).toBe('ER_SIGNAL_EXCEPTION'); - }); -}); diff --git a/db/tests/vn/ticketComponentUpdateSale.spec.js b/db/tests/vn/ticketComponentUpdateSale.spec.js deleted file mode 100644 index 9e252200b..000000000 --- a/db/tests/vn/ticketComponentUpdateSale.spec.js +++ /dev/null @@ -1,294 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('ticketComponentUpdateSale()', () => { - it(`should update the sale price when option ONE using the base components and reclaculate only the ones with isRenewable TRUE`, async() => { - let stmts = []; - let stmt; - - let params = { - warehouseFk: 1, - ticketFk: 13 - }; - - stmts.push('START TRANSACTION'); - - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale'); - - // createSaleTempTable code comes from vn.ticketComponentUpdate procedure - let createSaleTempTable = ` - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, ? warehouseFk - FROM sale s WHERE s.ticketFk = ? - `; - - stmt = new ParameterizedSQL(createSaleTempTable, [ - params.warehouseFk, - params.ticketFk - ]); - stmts.push(stmt); - - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent'); - - // createTicketComponentTable code comes partially from vn.ticketComponenetCalculate procedure - let createTicketComponentTable = ` - CREATE TEMPORARY TABLE tmp.ticketComponent ( - warehouseFk INT UNSIGNED NOT NULL, - itemFk INT NOT NULL, - componentFk INT UNSIGNED NOT NULL, - cost DECIMAL(10,4) NOT NULL, - INDEX itemWarehouse USING BTREE (itemFk ASC, warehouseFk ASC), - UNIQUE INDEX itemWarehouseComponent (itemFk ASC, warehouseFk ASC, componentFk ASC)) - `; - - stmts.push(createTicketComponentTable); - - let insertTicketComponentTable = ` - INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - VALUES - (1 , 4 , 15 , 999.00), - (1 , 4 , 17 , 2.00), - (1 , 4 , 22 , 999.00), - (1 , 4 , 28 , 1.00), - (1 , 4 , 29 , 2.00), - (1 , 4 , 32 , 999.00), - (1 , 4 , 39 , 1.00) - `; - - stmts.push(insertTicketComponentTable); - - let updateComponentTwentyNine = ` - UPDATE vn.saleComponent - SET value = '5' - WHERE saleFk = 26 AND componentFk = 29 - `; - - stmts.push(updateComponentTwentyNine); - - let updateComponentTwentyEight = ` - UPDATE vn.saleComponent - SET value = '5' - WHERE saleFk = 26 AND componentFk = 28 - `; - - stmts.push(updateComponentTwentyEight); - - let priceFixtedToZero = ` - UPDATE vn.sale - SET priceFixed = 0 - WHERE id = 26 - `; - - stmts.push(priceFixtedToZero); - - let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; - - stmts.push('CALL vn.ticketComponentUpdateSale(1)'); - - let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - expect(result[firstSalePriceIndexBefore][0].price).toEqual(1.72); - expect(result[firstSalePriceIndexAfter][0].price).toEqual(1005); - }); - - it(`should keep the sale price when option TWO using the base components and save the difference in a new component`, async() => { - let stmts = []; - let stmt; - - let params = { - warehouseFk: 1, - ticketFk: 13 - }; - - stmts.push('START TRANSACTION'); - - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale'); - - // createSaleTempTable code comes from vn.ticketComponentUpdate procedure - let createSaleTempTable = ` - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, ? warehouseFk - FROM sale s WHERE s.ticketFk = ? - `; - - stmt = new ParameterizedSQL(createSaleTempTable, [ - params.warehouseFk, - params.ticketFk - ]); - stmts.push(stmt); - - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent'); - - // createTicketComponentTable code comes partially from vn.ticketComponenetCalculate procedure - let createTicketComponentTable = ` - CREATE TEMPORARY TABLE tmp.ticketComponent ( - warehouseFk INT UNSIGNED NOT NULL, - itemFk INT NOT NULL, - componentFk INT UNSIGNED NOT NULL, - cost DECIMAL(10,4) NOT NULL, - INDEX itemWarehouse USING BTREE (itemFk ASC, warehouseFk ASC), - UNIQUE INDEX itemWarehouseComponent (itemFk ASC, warehouseFk ASC, componentFk ASC)) - `; - - stmts.push(createTicketComponentTable); - - let insertTicketComponentTable = ` - INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - VALUES - (1 , 4 , 15 , 999.00), - (1 , 4 , 17 , 2.00), - (1 , 4 , 22 , 999.00), - (1 , 4 , 28 , 1.00), - (1 , 4 , 29 , 2.00), - (1 , 4 , 32 , 999.00), - (1 , 4 , 39 , 1.00) - `; - - stmts.push(insertTicketComponentTable); - - let updateComponentTwentyNine = ` - UPDATE vn.saleComponent - SET value = '5' - WHERE saleFk = 26 AND componentFk = 29 - `; - - stmts.push(updateComponentTwentyNine); - - let updateComponentTwentyEight = ` - UPDATE vn.saleComponent - SET value = '5' - WHERE saleFk = 26 AND componentFk = 28 - `; - - stmts.push(updateComponentTwentyEight); - - let priceFixtedToZero = ` - UPDATE vn.sale - SET priceFixed = 0 - WHERE id = 26 - `; - - stmts.push(priceFixtedToZero); - - let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; - - stmts.push('CALL vn.ticketComponentUpdateSale(2)'); - - let addedComponentIndex = stmts.push('SELECT * FROM vn.saleComponent WHERE saleFk = 26 AND componentFk = 17') - 1; - let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 26') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - expect(result[addedComponentIndex][0].value).toEqual(-1003.28); - expect(result[firstSalePriceIndexBefore][0].price).toEqual(result[firstSalePriceIndexAfter][0].price); - }); - - it(`should not change the sale price when option SEVEN, instead it stores 80% and 20% of the price in two components and any price difference in a third one`, async() => { - let stmts = []; - let stmt; - - let params = { - warehouseFk: 1, - ticketFk: 1 - }; - - stmts.push('START TRANSACTION'); - - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale'); - - // createSaleTempTable code comes from vn.ticketComponentUpdate procedure - let createSaleTempTable = ` - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, ? warehouseFk - FROM sale s WHERE s.ticketFk = ? - `; - - stmt = new ParameterizedSQL(createSaleTempTable, [ - params.warehouseFk, - params.ticketFk - ]); - stmts.push(stmt); - - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent'); - - // createTicketComponentTable code comes partially from vn.ticketComponenetCalculate procedure - let createTicketComponentTable = ` - CREATE TEMPORARY TABLE tmp.ticketComponent ( - warehouseFk INT UNSIGNED NOT NULL, - itemFk INT NOT NULL, - componentFk INT UNSIGNED NOT NULL, - cost DECIMAL(10,4) NOT NULL, - INDEX itemWarehouse USING BTREE (itemFk ASC, warehouseFk ASC), - UNIQUE INDEX itemWarehouseComponent (itemFk ASC, warehouseFk ASC, componentFk ASC)) - `; - - stmts.push(createTicketComponentTable); - - let insertTicketComponentTable = ` - INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - VALUES - (1 , 2 , 29 , 999.00), - (1 , 2 , 28 , 2.00), - (1 , 4 , 29 , 999.00), - (1 , 4 , 28 , 1.00) - `; - - stmts.push(insertTicketComponentTable); - - let updateComponentTwentyEight = ` - UPDATE vn.saleComponent - SET value = '5' - WHERE saleFk = 1 AND componentFk = 28 - `; - - stmts.push(updateComponentTwentyEight); - - let updateComponentTwentyNine = ` - UPDATE vn.saleComponent - SET value = '5' - WHERE saleFk = 1 AND componentFk = 29 - `; - - stmts.push(updateComponentTwentyNine); - - let priceFixtedToZero = ` - UPDATE vn.sale - SET priceFixed = 0 - WHERE id = 1 - `; - - stmts.push(priceFixtedToZero); - - let firstSalePriceIndexBefore = stmts.push('SELECT price FROM vn.sale WHERE id = 1') - 1; - - stmts.push('CALL vn.ticketComponentUpdateSale(7)'); - - let componentTwentyEightIndex = stmts.push('SELECT * FROM vn.saleComponent WHERE saleFk = 1 AND componentFk = 28') - 1; - let componentTwentyNineIndex = stmts.push('SELECT * FROM vn.saleComponent WHERE saleFk = 1 AND componentFk = 29') - 1; - let firstSalePriceIndexAfter = stmts.push('SELECT price FROM vn.sale WHERE id = 1') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - expect(result[componentTwentyEightIndex][0].value).toEqual(79.517); - expect(result[componentTwentyNineIndex][0].value).toEqual(19.879); - expect(result[firstSalePriceIndexBefore][0].price).toEqual(result[firstSalePriceIndexAfter][0].price); - }); -}); - diff --git a/db/tests/vn/ticketCreateWithUser.spec.js b/db/tests/vn/ticketCreateWithUser.spec.js deleted file mode 100644 index 5dd84d397..000000000 --- a/db/tests/vn/ticketCreateWithUser.spec.js +++ /dev/null @@ -1,203 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('ticket ticket_add()', () => { - const today = Date.vnNew(); - it('should confirm the procedure creates the expected ticket', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - clientFk: 1101, - shipped: today, - warehouseFk: 1, - companyFk: 442, - addressFk: 121, - agencyModeFk: 1, - routeFk: null, - landed: today, - userId: 18 - }; - - stmt = new ParameterizedSQL(`CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [ - params.clientFk, - params.shipped, - params.warehouseFk, - params.companyFk, - params.addressFk, - params.agencyModeFk, - params.routeFk, - params.landed, - params.userId, - true - ]); - stmts.push(stmt); - - let ticketResultIndex = stmts.push(`SELECT * FROM vn.ticket WHERE id = @newTicketId`) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let ticketResult = result[ticketResultIndex][0]; - - expect(ticketResult.id).toBeGreaterThan(21); - expect(ticketResult.clientFk).toEqual(params.clientFk); - expect(ticketResult.warehouseFk).toEqual(params.warehouseFk); - expect(ticketResult.companyFk).toEqual(params.companyFk); - expect(ticketResult.addressFk).toEqual(params.addressFk); - expect(ticketResult.agencyModeFk).toEqual(params.agencyModeFk); - expect(ticketResult.routeFk).toEqual(params.routeFk); - }); - - it('should confirm the procedure creates the expected observations in the ticket', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - clientFk: 1101, - shipped: today, - warehouseFk: 1, - companyFk: 442, - addressFk: 121, - agencyModeFk: 1, - routeFk: null, - landed: today, - userId: 18 - }; - - stmt = new ParameterizedSQL('CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)', [ - params.clientFk, - params.shipped, - params.warehouseFk, - params.companyFk, - params.addressFk, - params.agencyModeFk, - params.routeFk, - params.landed, - params.userId, - true - ]); - stmts.push(stmt); - - let ticketObsevationsIndex = stmts.push(`SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId`) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let firstTicketObservation = result[ticketObsevationsIndex][0]; - let secondTicketObservation = result[ticketObsevationsIndex][1]; - let thirdTicketObservation = result[ticketObsevationsIndex][2]; - - expect(firstTicketObservation.observationTypeFk).toEqual(1); - expect(firstTicketObservation.description).toEqual('under the floor'); - expect(secondTicketObservation.observationTypeFk).toEqual(2); - expect(secondTicketObservation.description).toEqual('wears leather and goes out at night'); - expect(thirdTicketObservation.observationTypeFk).toEqual(3); - expect(thirdTicketObservation.description).toEqual('care with the dog'); - }); - - it('should confirm the procedure sets address if it received it null', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - clientFk: 1101, - shipped: today, - warehouseFk: 1, - companyFk: 442, - addressFk: 0, - agencyModeFk: 1, - routeFk: null, - landed: today, - userId: 18 - }; - - stmt = new ParameterizedSQL(`CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [ - params.clientFk, - params.shipped, - params.warehouseFk, - params.companyFk, - params.addressFk, - params.agencyModeFk, - params.routeFk, - params.landed, - params.userId, - true - ]); - - stmts.push(stmt); - - let ticketAddressIndex = stmts.push(`SELECT addressFk FROM vn.ticket WHERE id = @newTicketId`) - 1; - - stmt = new ParameterizedSQL(`SELECT id FROM vn.address WHERE clientFk = ? AND isDefaultAddress = 1`, [ - params.clientFk, - ]); - let clientDefaultAddressIndex = stmts.push(stmt) - 1; - stmts.push('ROLLBACK'); - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - let ticketAddress = result[ticketAddressIndex][0]; - let clientDefaultAddress = result[clientDefaultAddressIndex][0]; - - expect(ticketAddress.addressFk).toEqual(clientDefaultAddress.id); - }); - - it('should confirm the procedure creates the state as delivered if the client has isCreatedAsServed TRUE', async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - clientFk: 1101, - shipped: today, - warehouseFk: 1, - companyFk: 442, - addressFk: 121, - agencyModeFk: 1, - routeFk: null, - landed: today, - userId: 18 - }; - - stmt = new ParameterizedSQL(`UPDATE vn.client SET isCreatedAsServed = 1 WHERE id = ?`, [ - params.clientFk, - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL(`CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [ - params.clientFk, - params.shipped, - params.warehouseFk, - params.companyFk, - params.addressFk, - params.agencyModeFk, - params.routeFk, - params.landed, - params.userId, - true - ]); - stmts.push(stmt); - stmts.push(`select @newTicketId`); - let ticketStateCodeIndex = stmts.push(`SELECT code FROM vn.ticketState WHERE ticketFk = @newTicketId`) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let ticketStateCode = result[ticketStateCodeIndex][0].code; - - expect(ticketStateCode).toEqual('FREE'); - }); -}); diff --git a/db/tests/vn/ticket_recalcComponents.spec.js b/db/tests/vn/ticket_recalcComponents.spec.js deleted file mode 100644 index 1256528e6..000000000 --- a/db/tests/vn/ticket_recalcComponents.spec.js +++ /dev/null @@ -1,62 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('ticket_recalcComponents()', () => { - it('should recalculate the components in a ticket and check it', async() => { - let stmts = []; - let stmt; - const ticketId = 11; - - stmts.push('START TRANSACTION'); - - let sales = await app.models.Sale.find({where: {ticketFk: ticketId}}); - - stmt = new ParameterizedSQL('UPDATE vn.sale SET price=100 WHERE id IN(?,?)', [ - sales[0].id, - sales[1].id - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('SELECT * FROM vn.sale WHERE ticketFk = ?', [ - ticketId - ]); - stmts.push(stmt); - - let modifiedSales = stmts.push(stmt) - 1; - - stmt = new ParameterizedSQL('CALL vn.ticket_recalcComponents(?, NULL)', [ - ticketId, - ]); - stmts.push(stmt); - - stmt = new ParameterizedSQL('SELECT * FROM vn.sale WHERE ticketFk = ?', [ - ticketId - ]); - stmts.push(stmt); - - let expectedSales = stmts.push(stmt) - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - // original data - const firstPrice = sales[0].price; - const secondPrice = sales[1].price; - - // alteratons for test purposes - const modifiedFirstPrice = result[modifiedSales][0].price; - const modifiedSecondPrice = result[modifiedSales][1].price; - - // expected data after recalc - const expectedSalesFirstPrice = result[expectedSales][0].price; - const expectedSalesSecondPrice = result[expectedSales][1].price; - - expect(firstPrice).not.toEqual(modifiedFirstPrice); - expect(secondPrice).not.toEqual(modifiedSecondPrice); - - expect(firstPrice).toEqual(expectedSalesFirstPrice); - expect(secondPrice).toEqual(expectedSalesSecondPrice); - }); -}); diff --git a/db/tests/vn/timeBusiness_calculateByUser.spec.js b/db/tests/vn/timeBusiness_calculateByUser.spec.js deleted file mode 100644 index 5fe51d8f8..000000000 --- a/db/tests/vn/timeBusiness_calculateByUser.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('timeBusiness_calculateByUser()', () => { - it('should return the expected hours for today', async() => { - let start = Date.vnNew(); - start.setHours(0, 0, 0, 0); - let end = Date.vnNew(); - end.setHours(0, 0, 0, 0); - - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - workerID: 1106, - start: start, - end: end - }; - - stmt = new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [ - params.workerID, - params.start, - params.end - ]); - stmts.push(stmt); - - let tableIndex = stmts.push('SELECT * FROM tmp.timeBusinessCalculate') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let [timeBusinessCalculateTable] = result[tableIndex]; - - expect(timeBusinessCalculateTable.timeBusinessSeconds).toEqual(28800); - }); -}); diff --git a/db/tests/vn/zone_getEvents.spec.js b/db/tests/vn/zone_getEvents.spec.js deleted file mode 100644 index fe49b60be..000000000 --- a/db/tests/vn/zone_getEvents.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('zone zone_getEvents()', () => { - it(`should return data for a agencyMode with deliveryMethod pickup`, async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - - let params = { - zoneGeoFk: 1, - agencyModeFk: 1}; - - stmt = new ParameterizedSQL('CALL zone_getEvents(?, ?)', [ - params.zoneGeoFk, - params.agencyModeFk, - - ]); - stmts.push(stmt); - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let zonesEvents = result[1]; - - expect(zonesEvents.length).toBeGreaterThan(0); - }); -}); diff --git a/db/tests/vn/zone_getFromGeo.spec.js b/db/tests/vn/zone_getFromGeo.spec.js deleted file mode 100644 index 74b6e00cc..000000000 --- a/db/tests/vn/zone_getFromGeo.spec.js +++ /dev/null @@ -1,28 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('zone zone_getFromGeo()', () => { - it(`should check that there are some results in table zone`, async() => { - let stmts = []; - let stmt; - - stmts.push('START TRANSACTION'); - let geoFk = 16; - - stmt = new ParameterizedSQL('CALL zone_getFromGeo(?)', [ - geoFk, - ]); - stmts.push(stmt); - - let tableIndex = stmts.push('SELECT count(*) countZone FROM tmp.zone WHERE id IN (1, 2, 3, 4, 5, 6, 7, 8)') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let [zoneTable] = result[tableIndex]; - - expect(zoneTable.countZone).toBe(8); - }); -}); diff --git a/db/tests/vn/zone_getLanded.spec.js b/db/tests/vn/zone_getLanded.spec.js deleted file mode 100644 index 888d7c132..000000000 --- a/db/tests/vn/zone_getLanded.spec.js +++ /dev/null @@ -1,75 +0,0 @@ -const app = require('vn-loopback/server/server'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; - -describe('zone zone_getLanded()', () => { - it(`should return data for a shipped in the past`, async() => { - let stmts = []; - let stmt; - stmts.push('START TRANSACTION'); - const date = Date.vnNew(); - date.setHours(0, 0, 0, 0); - - let params = { - addressFk: 121, - agencyModeFk: 7, - warehouseFk: 1, - showExpiredZones: true}; - - stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL -1 DAY), ?, ?, ?, ?)', [ - date, - params.addressFk, - params.agencyModeFk, - params.warehouseFk, - params.showExpiredZones - - ]); - stmts.push(stmt); - - let tableIndex = stmts.push('SELECT count(*) countZone FROM tmp.zoneGetLanded') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let [zoneTable] = result[tableIndex]; - - expect(zoneTable.countZone).toBe(1); - }); - - it(`should return data for a shipped tomorrow`, async() => { - let stmts = []; - let stmt; - const date = Date.vnNew(); - date.setHours(0, 0, 0, 0); - - stmts.push('START TRANSACTION'); - - let params = { - addressFk: 121, - agencyModeFk: 7, - warehouseFk: 1, - showExpiredZones: false}; - - stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL +2 DAY), ?, ?, ?, ?)', [ - date, - params.addressFk, - params.agencyModeFk, - params.warehouseFk, - params.showExpiredZones - - ]); - stmts.push(stmt); - - let tableIndex = stmts.push('SELECT count(*) countZone FROM tmp.zoneGetLanded') - 1; - - stmts.push('ROLLBACK'); - - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await app.models.Ticket.rawStmt(sql); - - let [zoneTable] = result[tableIndex]; - - expect(zoneTable.countZone).toBe(1); - }); -}); diff --git a/db/versions/.archive/10107-pinkPaniculata/00-firstScript.sql b/db/versions/.archive/10107-pinkPaniculata/00-firstScript.sql new file mode 100644 index 000000000..a5e4dd843 --- /dev/null +++ b/db/versions/.archive/10107-pinkPaniculata/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig ADD defaultZone INT DEFAULT 697 NOT NULL; +ALTER TABLE vn.productionConfig ADD defautlAgencyMode INT DEFAULT 1328 NOT NULL COMMENT 'SENDING'; diff --git a/db/versions/.archive/10112-wheatAnthurium/00-firstScript.sql b/db/versions/.archive/10112-wheatAnthurium/00-firstScript.sql new file mode 100644 index 000000000..bc4b383b9 --- /dev/null +++ b/db/versions/.archive/10112-wheatAnthurium/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE `vn2008`.`Tickets_dits` RENAME TO `vn2008`.`Tickets_dits__` ; diff --git a/db/versions/.archive/10113-blueMonstera/00-firstScript.sql b/db/versions/.archive/10113-blueMonstera/00-firstScript.sql new file mode 100644 index 000000000..c437d076b --- /dev/null +++ b/db/versions/.archive/10113-blueMonstera/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.specialPrice DROP FOREIGN KEY `{01A99AF1-3D3F-4B15-AC0C-C7A834F319A3}`; +ALTER TABLE vn.specialPrice DROP FOREIGN KEY `{EE4ADEF6-0AC6-401F-B7C4-D797972FC065}`; + \ No newline at end of file diff --git a/db/versions/.archive/10114-maroonOrchid/00-updateConfig.sql b/db/versions/.archive/10114-maroonOrchid/00-updateConfig.sql new file mode 100644 index 000000000..919c6269a --- /dev/null +++ b/db/versions/.archive/10114-maroonOrchid/00-updateConfig.sql @@ -0,0 +1 @@ +ALTER TABLE srt.config ADD isBalanced BOOL DEFAULT 1 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10116-pinkOak/00-firstScript.sql b/db/versions/.archive/10116-pinkOak/00-firstScript.sql new file mode 100644 index 000000000..682f9772b --- /dev/null +++ b/db/versions/.archive/10116-pinkOak/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.propertyNotes DROP FOREIGN KEY propertyNotes_FK; +ALTER TABLE vn.propertyNotes MODIFY COLUMN propertyFk int(11) NOT NULL; +ALTER TABLE vn.propertyNotes ADD CONSTRAINT propertyNotes_FK FOREIGN KEY (propertyFk) REFERENCES vn.property(id); diff --git a/db/versions/.archive/10118-blueFern/00-firstScript.sql b/db/versions/.archive/10118-blueFern/00-firstScript.sql new file mode 100644 index 000000000..12de63f4b --- /dev/null +++ b/db/versions/.archive/10118-blueFern/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.cmrConfig ADD landingDays TINYINT DEFAULT 1 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10119-navyGerbera/00-AfegirFKPart1.sql b/db/versions/.archive/10119-navyGerbera/00-AfegirFKPart1.sql new file mode 100644 index 000000000..bfff1133b --- /dev/null +++ b/db/versions/.archive/10119-navyGerbera/00-AfegirFKPart1.sql @@ -0,0 +1,18 @@ +/*ALTER TABLE bi.rutasBoard ADD CONSTRAINT rutasBoard_FK FOREIGN KEY (warehouse_id) REFERENCES vn.warehouse(id); +ALTER TABLE bi.tarifa_warehouse MODIFY COLUMN warehouse_id smallint(6) UNSIGNED NOT NULL; +ALTER TABLE bi.tarifa_warehouse ADD CONSTRAINT tarifa_warehouse_FK FOREIGN KEY (warehouse_id) REFERENCES vn.warehouse(id); +ALTER TABLE bi.XDiario_ALL MODIFY COLUMN empresa_id SMALLINT (5) UNSIGNED NOT NULL; +ALTER TABLE bi.XDiario_ALL ADD CONSTRAINT XDiario_ALL_FK FOREIGN KEY (empresa_id) REFERENCES vn.company(id); +ALTER TABLE bs.defaulter ADD CONSTRAINT defaulter_FK FOREIGN KEY (clientFk) REFERENCES vn.client(id); +ALTER TABLE bs.inspeccionSS_2021 ADD CONSTRAINT inspeccionSS_2021_FK FOREIGN KEY (business_id) REFERENCES postgresql.business(business_id); +DELETE FROM bs.m3 WHERE id=589880; +DELETE FROM bs.m3 WHERE id=639521; +DELETE FROM bs.m3 WHERE id=639984; +ALTER TABLE bs.m3 ADD CONSTRAINT m3_FK FOREIGN KEY (provinceFk) REFERENCES vn.province(id); +ALTER TABLE bs.m3 ADD CONSTRAINT m3Warehouse_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON UPDATE CASCADE; +ALTER TABLE bs.ventas_contables MODIFY COLUMN empresa_id smallint(5) unsigned NOT NULL; +ALTER TABLE bs.ventas_contables ADD CONSTRAINT ventas_contables_FK FOREIGN KEY (empresa_id) REFERENCES vn.company(id); +DELETE FROM bs.ventas_contables WHERE tipo_id = 97; -- BORRE PER QUE ESTE TIPO JA NO EXISTEIX +ALTER TABLE cache.cache_calc ADD CONSTRAINT cache_calc_FK FOREIGN KEY (cache_id) REFERENCES cache.cache(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE cache.last_buy MODIFY COLUMN item_id int(11) NOT NULL; +comente per que ja s'ha executat esta part*/ \ No newline at end of file diff --git a/db/versions/.archive/10119-navyGerbera/01-AfegirFkPart2.sql b/db/versions/.archive/10119-navyGerbera/01-AfegirFkPart2.sql new file mode 100644 index 000000000..c129b2c76 --- /dev/null +++ b/db/versions/.archive/10119-navyGerbera/01-AfegirFkPart2.sql @@ -0,0 +1,17 @@ +/* +ALTER TABLE cache.last_buy ADD CONSTRAINT last_buy_FK_1 FOREIGN KEY (warehouse_id) REFERENCES vn.warehouse(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE cache.last_buy MODIFY COLUMN buy_id int(11) NULL; +-- Aplicado hasta aquí +ALTER TABLE cache.last_buy ADD CONSTRAINT last_buy_FK_2 FOREIGN KEY (buy_id) REFERENCES vn.buy(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE cache.prod_graphic_source MODIFY COLUMN warehouse_id smallint(6) unsigned NOT NULL; +ALTER TABLE cache.prod_graphic_source ADD CONSTRAINT prod_graphic_source_FK FOREIGN KEY (warehouse_id) REFERENCES vn.warehouse(id) ON DELETE CASCADE ON UPDATE CASCADE; +DELETE FROM dipole.expedition_PrintOut WHERE expeditionFk NOT IN (SELECT id FROM vn.expedition); +ALTER TABLE dipole.expedition_PrintOut ADD CONSTRAINT expedition_PrintOut_FK_1 FOREIGN KEY (expeditionFk) REFERENCES vn.expedition(id); +ALTER TABLE dipole.expedition_PrintOut ADD CONSTRAINT expedition_PrintOut_FK_2 FOREIGN KEY (addressFk) REFERENCES vn.address(id); +ALTER TABLE dipole.expedition_PrintOut ADD CONSTRAINT expedition_PrintOut_FK_3 FOREIGN KEY (clientFk) REFERENCES vn.client(id); +ALTER TABLE dipole.expedition_PrintOut MODIFY COLUMN routeFk int(11) DEFAULT 0 NOT NULL COMMENT '3 ultimos caracteres de la ruta'; +ALTER TABLE dipole.expedition_PrintOut ADD CONSTRAINT expedition_PrintOut_FK_4 FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id); +ALTER TABLE dipole.expedition_Read ADD CONSTRAINT expedition_Read_FK_1 FOREIGN KEY (expeditionFk) REFERENCES vn.expedition(id); +ALTER TABLE edi.bucket ADD CONSTRAINT bucket_FK FOREIGN KEY (bucket_type_id) REFERENCES edi.bucket_type(bucket_type_id) ON UPDATE CASCADE; +ALTER TABLE edi.clientFHAdminNumber ADD CONSTRAINT clientFHAdminNumber_FK_1 FOREIGN KEY (clientFk) REFERENCES vn.client(id) ON UPDATE CASCADE; +*/ \ No newline at end of file diff --git a/db/versions/.archive/10125-grayRose/00-firstScript.sql b/db/versions/.archive/10125-grayRose/00-firstScript.sql new file mode 100644 index 000000000..e37209b83 --- /dev/null +++ b/db/versions/.archive/10125-grayRose/00-firstScript.sql @@ -0,0 +1,45 @@ +ALTER TABLE hedera.restPriv MODIFY COLUMN `role` int(10) unsigned NULL; + +UPDATE hedera.restPriv + SET `role`=104 + WHERE id=5; +UPDATE hedera.restPriv + SET `role`=5 + WHERE id=7; +DELETE FROM hedera.restPriv + WHERE id=2; +DELETE FROM hedera.restPriv + WHERE id=6; +DELETE FROM hedera.restPriv + WHERE id=8; +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/captcha'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/log'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/login'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/logout'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/query'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/recover-password'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('core/restore-password'); +INSERT INTO hedera.restPriv (methodPath,`role`) + VALUES ('dms/invoice',2); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('image/thumb'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('misc/concact'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('misc/production'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('tpv/confirm-post'); +INSERT INTO hedera.restPriv (methodPath) + VALUES ('tpv/confirm-soap'); +INSERT INTO hedera.restPriv (methodPath,`role`) + VALUES ('client/supplant',18); + +UPDATE vn.`itemCategory` SET `display` = '0' WHERE `itemCategory`.`id` = 9; +DELETE FROM hedera.`menu` WHERE `menu`.`id` = 16 diff --git a/db/versions/.archive/10127-purpleMedeola/00-firstScript.sql b/db/versions/.archive/10127-purpleMedeola/00-firstScript.sql new file mode 100644 index 000000000..e64ccf9cb --- /dev/null +++ b/db/versions/.archive/10127-purpleMedeola/00-firstScript.sql @@ -0,0 +1,28 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn2008`.`Trabajadores` +AS SELECT `w`.`id` AS `Id_Trabajador`, + `w`.`firstName` AS `Nombre`, + `w`.`userFk` AS `user_id`, + `w`.`phone` AS `phone`, + `w`.`bossFk` AS `boss`, + NULL AS `Foto`, + `w`.`fiDueDate` AS `DniExpiration`, + `w`.`code` AS `CodigoTrabajador`, + `w`.`lastName` AS `Apellidos`, + `w`.`hasMachineryAuthorized` AS `hasMachineryAuthorized`, + `w`.`password__` AS `Password__`, + `w`.`email__` AS `email__`, + `w`.`extension__` AS `extension__`, + `w`.`sub` AS `sub`, + `w`.`user__` AS `user__`, + `w`.`typeBussines__` AS `Contrato_Tipo__`, + `w`.`laborCategory__` AS `Categoria_Laboral__`, + `w`.`started__` AS `Fecha_Inicio__`, + `w`.`ended__` AS `Fecha_Fin__`, + `w`.`notes__` AS `Notas__`, + `w`.`address__` AS `address__`, + `w`.`birthed__` AS `date_birth__`, + `w`.`maritalStatus` AS `marital_status`, + `w`.`clientFk__` AS `Id_Cliente_Interno__` +FROM `vn`.`worker` `w` diff --git a/db/versions/.archive/10128-tealGerbera/00-firstScript.sql b/db/versions/.archive/10128-tealGerbera/00-firstScript.sql new file mode 100644 index 000000000..3904fcdcf --- /dev/null +++ b/db/versions/.archive/10128-tealGerbera/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE srt.config ADD testMode BOOL DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10129-maroonChrysanthemum/00-firstScript.sql b/db/versions/.archive/10129-maroonChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..d10ca22fa --- /dev/null +++ b/db/versions/.archive/10129-maroonChrysanthemum/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.itemShelving CHANGE deep deep__ int(11) unsigned DEFAULT 1 NOT NULL; +ALTER TABLE vn.itemShelving CHANGE quantity quantity__ int(11) DEFAULT 0 NOT NULL; +ALTER TABLE vn.itemShelving CHANGE `level` level__ varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT '1' NOT NULL; +ALTER TABLE vn.itemShelving CHANGE available available__ int(11) DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10132-blackChrysanthemum/00-firstScript.sql b/db/versions/.archive/10132-blackChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..3d9ce2922 --- /dev/null +++ b/db/versions/.archive/10132-blackChrysanthemum/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.item CHANGE compression compression__ decimal(5,2) +DEFAULT 1.00 NOT NULL +COMMENT 'Relacion de compresividad entre el volumen de las entradas en Silla y el empaquetado en los envios a clientes.'; diff --git a/db/versions/.archive/10133-crimsonLaurel/00-firstScript.sql b/db/versions/.archive/10133-crimsonLaurel/00-firstScript.sql new file mode 100644 index 000000000..caaad1e40 --- /dev/null +++ b/db/versions/.archive/10133-crimsonLaurel/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`item` CHANGE compression__ compression decimal(5,2) DEFAULT 1.00 NOT NULL COMMENT 'Relacion de compresividad entre el volumen de las entradas en Silla y el empaquetado en los envios a clientes.'; diff --git a/db/versions/.archive/10134-limeAnthurium/00-firstScript.sql b/db/versions/.archive/10134-limeAnthurium/00-firstScript.sql new file mode 100644 index 000000000..f32521d8f --- /dev/null +++ b/db/versions/.archive/10134-limeAnthurium/00-firstScript.sql @@ -0,0 +1,35 @@ +ALTER TABLE `vn`.`commissionConfig` ADD executionDay SMALLINT NULL; +ALTER TABLE `vn`.`commissionConfig` ADD salesPersonWithPlusNewClient INT NULL; +ALTER TABLE `vn`.`commissionConfig` ADD maxPlusNewClient INT NULL; +ALTER TABLE `vn`.`commissionConfig` ADD plusDifference INT NULL; +ALTER TABLE `vn`.`commissionConfig` ADD maxScoreNewClient INT NULL; +ALTER TABLE `vn`.`commissionConfig` ADD scoreDifference INT NULL; + +UPDATE `vn`.`commissionConfig` +SET plusDifference=5,executionDay=5,scoreDifference=1,maxScoreNewClient=100,maxPlusNewClient=100,salesPersonWithPlusNewClient=20 +WHERE rate=0.0080; + +UPDATE `vn`.`department` +SET workerFk=4661 +WHERE id=96; +UPDATE `vn`.`department` +SET workerFk=4667 +WHERE id=95; +UPDATE `vn`.`department` +SET workerFk=3810 +WHERE id=115; +UPDATE `vn`.`department` +SET workerFk=7102 +WHERE id=123; +UPDATE `vn`.`department` +SET workerFk=3797 +WHERE id=94; +UPDATE `vn`.`department` +SET workerFk=4250 +WHERE id=80; +UPDATE `vn`.`department` +SET workerFk=1118 +WHERE id=125; +UPDATE `vn`.`department` +SET workerFk=1203 +WHERE id=92; \ No newline at end of file diff --git a/db/versions/.archive/10135-brownMonstera/00-firstScript.sql b/db/versions/.archive/10135-brownMonstera/00-firstScript.sql new file mode 100644 index 000000000..cce5f0521 --- /dev/null +++ b/db/versions/.archive/10135-brownMonstera/00-firstScript.sql @@ -0,0 +1,12 @@ +Use `vn`; + +CREATE TABLE `vn`.`zoneExclusionGeo` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `zoneExclusionFk` int(11) NOT NULL, + `geoFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `zoneExclusionGeo_UN` (`zoneExclusionFk`,`geoFk`), + KEY `zoneExclusionGeo2_FK_1` (`geoFk`), + CONSTRAINT `zoneExclusionGeo_FK` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE, + CONSTRAINT `zoneExclusionGeo_FK_1` FOREIGN KEY (`zoneExclusionFk`) REFERENCES `zoneExclusion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; diff --git a/db/versions/.archive/10136-turquoiseGerbera/00-workerTimeControl.sql b/db/versions/.archive/10136-turquoiseGerbera/00-workerTimeControl.sql new file mode 100644 index 000000000..f5b6e046a --- /dev/null +++ b/db/versions/.archive/10136-turquoiseGerbera/00-workerTimeControl.sql @@ -0,0 +1,9 @@ +USE vn; +ALTER TABLE `vn`.`workerTimeControl` +ADD INDEX `timed_idx` (`timed` ASC); + +ALTER TABLE `vn`.`workerTimeControlConfig` +ADD COLUMN `shortWeekDays` INT(11) NULL COMMENT 'Días a tener en cuenta para calcular el descanso corto' AFTER `dayMaxTime`, +ADD COLUMN `longWeekDays` INT(11) NULL COMMENT 'Días a tener en cuenta para calcular el descanso largo' AFTER `shortWeekDays`; + +UPDATE `vn`.`workerTimeControlConfig` SET `shortWeekDays` = '6', `longWeekDays` = '13' WHERE (`id` = '1'); diff --git a/db/versions/.archive/10138-limeBirch/00-firstScript.sql b/db/versions/.archive/10138-limeBirch/00-firstScript.sql new file mode 100644 index 000000000..40dee2261 --- /dev/null +++ b/db/versions/.archive/10138-limeBirch/00-firstScript.sql @@ -0,0 +1,14 @@ +TRUNCATE vn.beach; +ALTER TABLE vn.beach CHANGE name name varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL AFTER id; +ALTER TABLE vn.beach DROP COLUMN x; +ALTER TABLE vn.beach DROP COLUMN y; +ALTER TABLE vn.beach DROP COLUMN isShowed; +ALTER TABLE vn.beach DROP COLUMN name; +ALTER TABLE vn.beach CHANGE id code varchar(45) NOT NULL; +ALTER TABLE vn.beach MODIFY COLUMN code varchar(45) NOT NULL; +ALTER TABLE vn.beach MODIFY COLUMN warehouseFk smallint(6) DEFAULT 60 NOT NULL; +ALTER TABLE vn.routesMonitor ADD CONSTRAINT routesMonitor_FK_2 FOREIGN KEY (beachFk) REFERENCES vn.beach(code) ON DELETE RESTRICT ON UPDATE CASCADE; +INSERT INTO vn.beach (code) VALUES ('p1'); +INSERT INTO vn.beach (code) VALUES ('p2'); +INSERT INTO vn.beach (code) VALUES ('p3'); +INSERT INTO vn.beach (code) VALUES ('p4'); diff --git a/db/versions/.archive/10139-grayAspidistra/00-firstScript.sql b/db/versions/.archive/10139-grayAspidistra/00-firstScript.sql new file mode 100644 index 000000000..1a0584851 --- /dev/null +++ b/db/versions/.archive/10139-grayAspidistra/00-firstScript.sql @@ -0,0 +1,63 @@ +USE vn; +ALTER TABLE `vn`.`labelReport` + RENAME TO `vn`.`report` ; + +UPDATE `vn`.`report` SET `name` = 'invoice' WHERE (`id` = '3'); +UPDATE `vn`.`report` SET `name` = 'cleanDMS' WHERE (`id` = '11'); +UPDATE `vn`.`report` SET `name` = 'invoicePdf' WHERE (`id` = '40'); + + +CREATE TABLE `printQueue` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `printerFk` tinyint(3) unsigned DEFAULT NULL, + `priorityFk` tinyint(3) unsigned DEFAULT NULL, + `reportFk` tinyint(3) unsigned DEFAULT NULL, + `statusCode` enum('queued','error','printing') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'queued', + `started` datetime DEFAULT NULL, + `finished` datetime DEFAULT NULL, + `workerFk` int(11) DEFAULT NULL, + `error` text COLLATE utf8_unicode_ci, + `errorNumber` int(11) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `statusCode` (`statusCode`), + KEY `printerFk` (`printerFk`), + KEY `priorityFk` (`priorityFk`), + KEY `workerFk` (`workerFk`), + KEY `printQueue_report` (`reportFk`), + CONSTRAINT `printQueue_priorityFk` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE, + CONSTRAINT `printQueue_printerFk` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE, + CONSTRAINT `printQueue_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci; + + + + +CREATE TABLE `printQueueArgs` ( + `printQueueFk` int(10) unsigned NOT NULL, + `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `value` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + KEY `printQueueArgs_printQueueFk_idx` (`printQueueFk`), + CONSTRAINT `printQueueArgs_printQueueFk` FOREIGN KEY (`printQueueFk`) REFERENCES `printQueue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Argumentos que se pasarán al informe para generarlos'; + + + +ALTER TABLE `vn`.`sector` + DROP FOREIGN KEY `sector_labelReport`; + +ALTER TABLE `vn`.`sector` + CHANGE COLUMN `labelReportFk` `reportFk` TINYINT(3) UNSIGNED NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`sector` + ADD CONSTRAINT `sector_report` + FOREIGN KEY (`reportFk`) + REFERENCES `vn`.`report` (`id`); + +ALTER TABLE `vn`.`queuePriority` +ADD COLUMN `code` VARCHAR(6) NULL AFTER `priority`; + +UPDATE `vn`.`queuePriority` SET `code` = 'normal' WHERE (`id` = '2'); +UPDATE `vn`.`queuePriority` SET `code` = 'low' WHERE (`id` = '3'); +UPDATE `vn`.`queuePriority` SET `code` = 'high' WHERE (`id` = '1'); + diff --git a/db/versions/.archive/10139-grayAspidistra/01-secondScript.sql b/db/versions/.archive/10139-grayAspidistra/01-secondScript.sql new file mode 100644 index 000000000..57d90337a --- /dev/null +++ b/db/versions/.archive/10139-grayAspidistra/01-secondScript.sql @@ -0,0 +1,18 @@ +USE vn; + +CREATE TABLE `vn`.`printQueueConfig` ( + `networkDrive` VARCHAR(10) NOT NULL DEFAULT 'X:\\', + `dmsPath` VARCHAR(45) NOT NULL DEFAULT ' \\\\server\\dms'); + + +ALTER TABLE `vn`.`printQueue` + DROP FOREIGN KEY `printQueue_priorityFk`; + +ALTER TABLE `vn`.`printQueue` + CHANGE COLUMN `priorityFk` `priorityFk` TINYINT(3) UNSIGNED NOT NULL DEFAULT 3 COMMENT '1 - high, 2 - normal, 3 - low' ; + +ALTER TABLE `vn`.`printQueue` + ADD CONSTRAINT `printQueue_priorityFk` + FOREIGN KEY (`priorityFk`) + REFERENCES `vn`.`queuePriority` (`id`) + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10141-turquoiseCordyline/00-firstScript.sql b/db/versions/.archive/10141-turquoiseCordyline/00-firstScript.sql new file mode 100644 index 000000000..7c7d05b56 --- /dev/null +++ b/db/versions/.archive/10141-turquoiseCordyline/00-firstScript.sql @@ -0,0 +1 @@ +RENAME TABLE vn.itemPlacement TO vn.itemPlacement__; \ No newline at end of file diff --git a/db/versions/.archive/10142-silverMedeola/00-firstScript.sql b/db/versions/.archive/10142-silverMedeola/00-firstScript.sql new file mode 100644 index 000000000..0f960efe8 --- /dev/null +++ b/db/versions/.archive/10142-silverMedeola/00-firstScript.sql @@ -0,0 +1,11 @@ +UPDATE hedera.orderRow or2 + LEFT JOIN vn.sale s ON s.id = or2.saleFk + SET or2.saleFk = NULL + WHERE s.id IS NULL AND or2.saleFk IS NOT NULL; + +ALTER TABLE `hedera`.`orderRow` +ADD CONSTRAINT `orderRow_ibfk_4` + FOREIGN KEY (`saleFk`) + REFERENCES `vn`.`sale` (`id`) + ON DELETE SET NULL + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10143-whiteFern/00-firstScript.sql b/db/versions/.archive/10143-whiteFern/00-firstScript.sql new file mode 100644 index 000000000..18f7762c1 --- /dev/null +++ b/db/versions/.archive/10143-whiteFern/00-firstScript.sql @@ -0,0 +1 @@ +RENAME TABLE postgresql.periodos TO postgresql.periodos__; \ No newline at end of file diff --git a/db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.sql b/db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.sql new file mode 100644 index 000000000..c71c66699 --- /dev/null +++ b/db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.sql @@ -0,0 +1,62 @@ + +-- vn mail recipientFk +ALTER TABLE vn.mail MODIFY COLUMN recipientFk int(10) unsigned NULL; +ALTER TABLE vn.mail ADD CONSTRAINT mail_FK_1 FOREIGN KEY (recipientFk) REFERENCES account.user(id) ON UPDATE CASCADE; + +-- vn mail senderFk +ALTER TABLE vn.mail MODIFY COLUMN senderFk int(10) unsigned NULL; +ALTER TABLE vn.mail ADD CONSTRAINT mail_FK FOREIGN KEY (senderFk) REFERENCES account.user(id) ON UPDATE CASCADE; + +-- vn packaging packagingReturnFk +ALTER TABLE vn.packaging ADD CONSTRAINT packaging_FK_1 FOREIGN KEY (packagingReturnFk) REFERENCES vn2008.Cubos_Retorno(idCubos_Retorno) ON UPDATE CASCADE; + +-- vn printServerQueue2 +ALTER TABLE vn.printServerQueue2 ADD CONSTRAINT printServerQueue2_FK_1 FOREIGN KEY (printerFk) REFERENCES vn.printer(id); +ALTER TABLE vn.printServerQueue2 ADD CONSTRAINT printServerQueue2_FK_2 FOREIGN KEY (priorityFk) REFERENCES vn.queuePriority(id); + +-- vn recipe inkFk +ALTER TABLE vn.recipe ADD CONSTRAINT recipe_FK FOREIGN KEY (inkFk) REFERENCES vn.ink(id) ON UPDATE CASCADE; + +-- vn recipe_log recipe_ItemFk +ALTER TABLE vn.recipe_log ADD CONSTRAINT recipe_log_FK FOREIGN KEY (recipe_ItemFk) REFERENCES vn.item(id) ON UPDATE CASCADE; +-- vn recipe_log selected_ItemFk +ALTER TABLE vn.recipe_log ADD CONSTRAINT recipe_log_FK_1 FOREIGN KEY (selected_ItemFk) REFERENCES vn.item(id) ON UPDATE CASCADE; + +-- vn routesMonitor dockFk +ALTER TABLE vn.routesMonitor MODIFY COLUMN dockFk varchar(10) NULL; +ALTER TABLE vn.routesMonitor ADD CONSTRAINT routesMonitor_FK_1 FOREIGN KEY (dockFk) REFERENCES vn.dock(code) ON UPDATE CASCADE; + +-- vn saleTracking actionFk +ALTER TABLE vn.saleTracking MODIFY COLUMN actionFk int(11) NULL; +UPDATE vn.saleTracking SET actionFk = NULL WHERE actionFk = 0; +ALTER TABLE vn.saleTracking ADD CONSTRAINT saleTracking_FK_1 FOREIGN KEY (actionFk) REFERENCES vncontrol.accion(accion_id) ON UPDATE CASCADE; + +-- vn sector sonFk +ALTER TABLE vn.sector ADD CONSTRAINT sector_FK FOREIGN KEY (sonFk,warehouseFk) REFERENCES vn.sector(id,warehouseFk) ON UPDATE CASCADE; + +-- vn sms senderFk +ALTER TABLE vn.sms MODIFY COLUMN senderFk int(10) unsigned NOT NULL; +ALTER TABLE vn.sms ADD CONSTRAINT sms_FK FOREIGN KEY (senderFk) REFERENCES account.`user`(id) ON UPDATE CASCADE; + +-- vn state nextStateFk +ALTER TABLE vn.state MODIFY COLUMN nextStateFk tinyint(3) unsigned NOT NULL COMMENT 'Estado al que tiene que cambiar el ticket despues de preparacion previa'; +ALTER TABLE vn.state ADD CONSTRAINT state_FK FOREIGN KEY (nextStateFk) REFERENCES vn.state(id) ON UPDATE CASCADE; + +-- vn supplierAccount bankEntityFk +ALTER TABLE vn.supplierAccount MODIFY COLUMN bankEntityFk int(10) unsigned NULL; +ALTER TABLE vn.supplierAccount ADD CONSTRAINT supplierAccount_FK_1 FOREIGN KEY (bankEntityFk) REFERENCES vn.bankEntity(id) ON UPDATE CASCADE; + +-- suplier +ALTER TABLE vn.supplierAccount MODIFY COLUMN supplierFk int(11) NULL; +UPDATE vn.supplierAccount SET supplierFk = null WHERE supplierFk NOT IN (SELECT id FROM vn.supplier s); +ALTER TABLE vn.supplierAccount ADD CONSTRAINT supplierAccount_FK FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON UPDATE CASCADE; + +-- vn ticketCollection smartTagFk +ALTER TABLE vn.ticketCollection MODIFY COLUMN smartTagFk varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL; +ALTER TABLE vn.ticketCollection ADD CONSTRAINT ticketCollection_FK FOREIGN KEY (smartTagFk) REFERENCES vn.smartTag(code) ON UPDATE CASCADE; + +-- vn workCenter payrollCenterFk +ALTER TABLE vn.workCenter MODIFY COLUMN payrollCenterFk int(11) NULL COMMENT 'Campo workcenter en A3'; + +-- vn warehouse pickUpAgencyModeFk +ALTER TABLE vn.warehouse ADD CONSTRAINT warehouse_FK_1 FOREIGN KEY (pickUpAgencyModeFk) REFERENCES vn.agencyMode(id) ON UPDATE CASCADE; diff --git a/db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.undo.sql b/db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.undo.sql new file mode 100644 index 000000000..cb6fb8d5d --- /dev/null +++ b/db/versions/.archive/10144-silverAralia/00-AfegirFKPArt1.undo.sql @@ -0,0 +1,34 @@ +ALTER TABLE vn.mail + DROP CONSTRAINT mail_FK_1; +ALTER TABLE vn.mail + DROP CONSTRAINT mail_FK; +ALTER TABLE vn.packaging + DROP CONSTRAINT packaging_FK_1; +ALTER TABLE vn.printServerQueue2 + DROP CONSTRAINT printServerQueue2_FK_1; +ALTER TABLE vn.printServerQueue2 + DROP CONSTRAINT printServerQueue2_FK_2; +ALTER TABLE vn.recipe + DROP CONSTRAINT recipe_FK; +ALTER TABLE vn.recipe_log + DROP CONSTRAINT recipe_log_FK; +ALTER TABLE vn.recipe_log + DROP CONSTRAINT recipe_log_FK_1; +ALTER TABLE vn.routesMonitor + DROP CONSTRAINT routesMonitor_FK_1; +ALTER TABLE vn.saleTracking + DROP CONSTRAINT saleTracking_FK_1; +ALTER TABLE vn.sector + DROP CONSTRAINT sector_FK; +ALTER TABLE vn.sms + DROP CONSTRAINT sms_FK; +ALTER TABLE vn.state + DROP CONSTRAINT state_FK; +ALTER TABLE vn.supplierAccount + DROP CONSTRAINT supplierAccount_FK_1; +ALTER TABLE vn.supplierAccount + DROP CONSTRAINT supplierAccount_FK; +ALTER TABLE vn.ticketCollection + DROP CONSTRAINT ticketCollection_FK; +ALTER TABLE vn.warehouse + DROP CONSTRAINT warehouse_FK_1; diff --git a/db/versions/.archive/10147-tealRuscus/00-firstScript.sql b/db/versions/.archive/10147-tealRuscus/00-firstScript.sql new file mode 100644 index 000000000..74a9047ee --- /dev/null +++ b/db/versions/.archive/10147-tealRuscus/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.person CHANGE readerId readerId__ int(11) DEFAULT NULL NULL; diff --git a/db/versions/.archive/10149-whiteMonstera/00-firstScript.sql b/db/versions/.archive/10149-whiteMonstera/00-firstScript.sql new file mode 100644 index 000000000..29108403a --- /dev/null +++ b/db/versions/.archive/10149-whiteMonstera/00-firstScript.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.config CHANGE bookFk bookFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialAFk serialAFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialEFk serialEFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialRFk serialRFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialCFk serialCFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialHFk serialHFk__ int(11) NOT NULL; +ALTER TABLE vn.config CHANGE serialPFk serialPFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialTFk serialTFk__ int(11) DEFAULT 0 NULL; +ALTER TABLE vn.config CHANGE serialMFk serialMFk__ int(11) DEFAULT 0 NULL; diff --git a/db/versions/.archive/10150-4062isLaid/00-firstScript.sql b/db/versions/.archive/10150-4062isLaid/00-firstScript.sql new file mode 100644 index 000000000..30f5a1e1f --- /dev/null +++ b/db/versions/.archive/10150-4062isLaid/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn.item ADD isLaid BOOL DEFAULT FALSE NOT NULL COMMENT 'Indica si el producto se puede tumbar a efectos del transporte desde Holanda'; + +ALTER TABLE vn.itemType ADD isLaid BOOL DEFAULT FALSE NOT NULL COMMENT 'Indica si el producto se puede tumbar a efectos del transporte desde Holanda'; diff --git a/db/versions/.archive/10152-bluePalmetto/00-firstScript.sql b/db/versions/.archive/10152-bluePalmetto/00-firstScript.sql new file mode 100644 index 000000000..d3175a4cb --- /dev/null +++ b/db/versions/.archive/10152-bluePalmetto/00-firstScript.sql @@ -0,0 +1,19 @@ +-- Place your SQL code here +USE vn; + +DROP TABLE IF EXISTS workerAppTester; + +CREATE TABLE `workerAppTester` ( + `workerFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`workerFk`), + KEY `workerAppTester_FK` (`workerFk`), + CONSTRAINT `workerAppTester_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='La tabla incluye usuarios testers que actualizarán a una versión diferente que el resto para testear los cambios nuevos en las app'; + +-- vn.mobileAppVersionControl definition + +ALTER TABLE vn.mobileAppVersionControl ADD urlProduction varchar(100) NULL; +ALTER TABLE vn.mobileAppVersionControl ADD urlBeta varchar(100) NULL; +ALTER TABLE vn.mobileAppVersionControl ADD versionBeta varchar(45) NULL; +ALTER TABLE vn.mobileAppVersionControl ADD isVersionBetaCritical tinyint(1) DEFAULT 0 NULL; +ALTER TABLE vn.mobileAppVersionControl CHANGE IsVersionCritical isVersionCritical tinyint(1) DEFAULT 0 NULL; \ No newline at end of file diff --git a/db/versions/.archive/10153-maroonAralia/00-firstScript.sql b/db/versions/.archive/10153-maroonAralia/00-firstScript.sql new file mode 100644 index 000000000..2a160b841 --- /dev/null +++ b/db/versions/.archive/10153-maroonAralia/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`sms` CHANGE destinationFk destinationFk__ int(11) DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/.archive/10154-blackSalal/00-compressionKk.sql b/db/versions/.archive/10154-blackSalal/00-compressionKk.sql new file mode 100644 index 000000000..5d9358515 --- /dev/null +++ b/db/versions/.archive/10154-blackSalal/00-compressionKk.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.item CHANGE compression compression__ decimal(5,2) DEFAULT 1.00 NOT NULL + COMMENT 'Relacion de compresividad entre el volumen de las entradas en Silla y el empaquetado en los envios a clientes.'; diff --git a/db/versions/.archive/10157-goldenCyca/00-firstScript.sql b/db/versions/.archive/10157-goldenCyca/00-firstScript.sql new file mode 100644 index 000000000..d8fa592bd --- /dev/null +++ b/db/versions/.archive/10157-goldenCyca/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE postgresql.business_labour DROP FOREIGN KEY workcenter_labour; +ALTER TABLE postgresql.business_labour ADD CONSTRAINT business_labour_FK FOREIGN KEY (workcenter_id) REFERENCES vn.workCenter(id) ON DELETE RESTRICT ON UPDATE CASCADE; +RENAME TABLE postgresql.workcenter TO postgresql.workcenter__; \ No newline at end of file diff --git a/db/versions/.archive/10158-grayCordyline/00-firstScript.sql b/db/versions/.archive/10158-grayCordyline/00-firstScript.sql new file mode 100644 index 000000000..33e83a81f --- /dev/null +++ b/db/versions/.archive/10158-grayCordyline/00-firstScript.sql @@ -0,0 +1,31 @@ +CREATE TABLE bs.`salesByItemTypeDay` ( + `itemTypeFk` smallint(5) unsigned NOT NULL, + `itemCategoryFk` int(10) unsigned NOT NULL, + `dated` date NOT NULL, + `netSale` int(11) NOT NULL DEFAULT 0, + `stems` int(11) NOT NULL DEFAULT 0, + `references` int(11) NOT NULL DEFAULT 0, + `trash` int(11) NOT NULL DEFAULT 0, + `faults` int(11) NOT NULL DEFAULT 0, + `claimed` decimal(10,2) NOT NULL DEFAULT 0.00, + `accepted` decimal(10,2) NOT NULL DEFAULT 0.00, + `sale` decimal(10,2) NOT NULL DEFAULT 0.00, + `buy` decimal(10,2) NOT NULL DEFAULT 0.00, + `saleComponent` decimal(10,2) NOT NULL DEFAULT 0.00, + `costComponent` decimal(10,2) NOT NULL DEFAULT 0.00, + `marginComponent` decimal(10,2) NOT NULL DEFAULT 0.00, + PRIMARY KEY (`itemTypeFk`,`dated`), + KEY `itemTypeSalesByweek_itemCategoryFk_idx` (`itemCategoryFk`), + KEY `itemTypeSalesByweek_period_idx` (`dated`), + CONSTRAINT `itemTypeSalesByweek_itemCategoryFk` FOREIGN KEY (`itemCategoryFk`) REFERENCES `vn`.`itemCategory` (`id`) ON UPDATE CASCADE, + CONSTRAINT `itemTypeSalesByweek_itemTypeFk` FOREIGN KEY (`itemTypeFk`) REFERENCES `vn`.`itemType` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Ventas diarias agrupadas por reino y familia'; + +ALTER TABLE `vn`.`claimConfig` ADD maxResponsibility INT NULL; + +UPDATE `vn`.`claimConfig` + SET maxResponsibility=5 + WHERE id=1; + +INSERT INTO `bs`.`nightTask` (`order`,`schema`,`procedure`) + VALUES (1005,'bs','salesByItemTypeDay_addLauncher'); diff --git a/db/versions/.archive/10160-limePalmetto/00-firstScript.sql b/db/versions/.archive/10160-limePalmetto/00-firstScript.sql new file mode 100644 index 000000000..26ceaf40f --- /dev/null +++ b/db/versions/.archive/10160-limePalmetto/00-firstScript.sql @@ -0,0 +1,7 @@ +CREATE INDEX greuge_shipped_IDX USING BTREE ON `vn`.`greuge` (shipped); + +INSERT INTO `bs`.`nightTask` (`order`,`schema`,`procedure`) + VALUES (1006,'vn','greuge_add'); + +ALTER TABLE `vn`.`greugeConfig` ADD yearsToDelete INT NULL; +UPDATE `vn`.`greugeConfig` SET yearsToDelete=5 WHERE id=1; diff --git a/db/versions/.archive/10163-tealErica/00-firstScript.sql b/db/versions/.archive/10163-tealErica/00-firstScript.sql new file mode 100644 index 000000000..2a9042144 --- /dev/null +++ b/db/versions/.archive/10163-tealErica/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.expedition ADD hasNewRoute BIT DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10164-pinkMastic/00-borrarSectorsDesus.sql b/db/versions/.archive/10164-pinkMastic/00-borrarSectorsDesus.sql new file mode 100644 index 000000000..7c64fc588 --- /dev/null +++ b/db/versions/.archive/10164-pinkMastic/00-borrarSectorsDesus.sql @@ -0,0 +1,2 @@ +DELETE FROM vn.parking WHERE sectorFk IN (2,42,43,46,47,54); +DELETE FROM vn.sector WHERE id IN (2,42,43,46,47,54); \ No newline at end of file diff --git a/db/versions/.archive/10165-yellowMastic/00-firstScript.sql b/db/versions/.archive/10165-yellowMastic/00-firstScript.sql new file mode 100644 index 000000000..54d1e9ae3 --- /dev/null +++ b/db/versions/.archive/10165-yellowMastic/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE `vn2008`.`Contactos` +RENAME TO `vn2008`.`Contactos__` ; + +ALTER TABLE `vn2008`.`Relaciones` +RENAME TO `vn2008`.`Relaciones__` ; \ No newline at end of file diff --git a/db/versions/.archive/10166-grayArborvitae/00-firstScript.sql b/db/versions/.archive/10166-grayArborvitae/00-firstScript.sql new file mode 100644 index 000000000..88544a1cd --- /dev/null +++ b/db/versions/.archive/10166-grayArborvitae/00-firstScript.sql @@ -0,0 +1,5 @@ + +USE vn; + +ALTER TABLE `vn`.`printQueueConfig` +ADD COLUMN `printQueueLimit` INT NOT NULL DEFAULT 30 COMMENT 'Número máximo de filas de la cola de impresión a mostrar al enviar correo a través del evento vn.printQueue_check' AFTER `dmsPath`; diff --git a/db/versions/.archive/10167-limeRoebelini/00-renameVnActiveContrat.sql b/db/versions/.archive/10167-limeRoebelini/00-renameVnActiveContrat.sql new file mode 100644 index 000000000..c74247c06 --- /dev/null +++ b/db/versions/.archive/10167-limeRoebelini/00-renameVnActiveContrat.sql @@ -0,0 +1 @@ +RENAME TABLE vn.activeContrat TO vn.activeContrat__; \ No newline at end of file diff --git a/db/versions/.archive/10167-limeRoebelini/01-renameVnActiveContrat.undo.sql b/db/versions/.archive/10167-limeRoebelini/01-renameVnActiveContrat.undo.sql new file mode 100644 index 000000000..9289cbc2f --- /dev/null +++ b/db/versions/.archive/10167-limeRoebelini/01-renameVnActiveContrat.undo.sql @@ -0,0 +1 @@ +RENAME TABLE vn.activeContrat__ TO vn.activeContrat; \ No newline at end of file diff --git a/db/versions/.archive/10168-orangeAnthurium/00-firstScript.sql b/db/versions/.archive/10168-orangeAnthurium/00-firstScript.sql new file mode 100644 index 000000000..bc461bfc0 --- /dev/null +++ b/db/versions/.archive/10168-orangeAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`routeGate` +RENAME TO `vn`.`routeGate__` ; diff --git a/db/versions/.archive/10169-greenMonstera/00-createTableBankEntityConfig.sql b/db/versions/.archive/10169-greenMonstera/00-createTableBankEntityConfig.sql new file mode 100644 index 000000000..6d56edc36 --- /dev/null +++ b/db/versions/.archive/10169-greenMonstera/00-createTableBankEntityConfig.sql @@ -0,0 +1,10 @@ +CREATE TABLE vn.bankEntityConfig ( + id INT auto_increment NULL, + bicLength TINYINT DEFAULT 11 NULL COMMENT 'Tamaño del campo bic', + CONSTRAINT bankEntityConfig_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT INTO vn.bankEntityConfig (id, bicLength) VALUES(1, 11); \ No newline at end of file diff --git a/db/versions/.archive/10169-greenMonstera/01-createTableBankEntityConfig.undo.sql b/db/versions/.archive/10169-greenMonstera/01-createTableBankEntityConfig.undo.sql new file mode 100644 index 000000000..76dacb203 --- /dev/null +++ b/db/versions/.archive/10169-greenMonstera/01-createTableBankEntityConfig.undo.sql @@ -0,0 +1 @@ +DROP TABLE vn.bankEntityConfig; \ No newline at end of file diff --git a/db/versions/.archive/10169-greenMonstera/02-addNotNullToBankEntityBic.sql b/db/versions/.archive/10169-greenMonstera/02-addNotNullToBankEntityBic.sql new file mode 100644 index 000000000..1f12efd8d --- /dev/null +++ b/db/versions/.archive/10169-greenMonstera/02-addNotNullToBankEntityBic.sql @@ -0,0 +1 @@ +ALTER TABLE vn.bankEntity MODIFY COLUMN bic varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10171-crimsonCarnation/00-volumeConfig.sql b/db/versions/.archive/10171-crimsonCarnation/00-volumeConfig.sql new file mode 100644 index 000000000..df189acbc --- /dev/null +++ b/db/versions/.archive/10171-crimsonCarnation/00-volumeConfig.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.volumeConfig ADD aerealVolumetricDensity DECIMAL(10,1) DEFAULT 167 NULL +COMMENT 'factor de conversión para calcular el peso tasable aereo'; diff --git a/db/versions/.archive/10171-crimsonCarnation/01-itemWeight.sql b/db/versions/.archive/10171-crimsonCarnation/01-itemWeight.sql new file mode 100644 index 000000000..052c5259c --- /dev/null +++ b/db/versions/.archive/10171-crimsonCarnation/01-itemWeight.sql @@ -0,0 +1,27 @@ +ALTER TABLE vn.item ADD weightByPiece int unsigned NULL +COMMENT 'peso por defecto para un articulo por tallo/unidad'; +/* +-- actualizamos con los valores del itemCost, o de la ultima compra, o de la densidad * volumen +UPDATE vn.itemCost ic + JOIN cache.last_buy lb ON lb.item_id = ic.itemFk and lb.warehouse_id = ic.warehouseFk + JOIN vn.buy b ON b.id = lb.buy_id + JOIN vn.item i ON i.id = ic.itemFk + SET ic.grams = COALESCE( + (b.weight * 1000) / b.packing, + i.density * (cm3delivery / 1000000) * 1000); + +UPDATE vn.item i + JOIN vn.itemCost ic ON ic.itemFk = i.id and ic.warehouseFk = 60 + SET i.weightByPiece = ic.grams + WHERE i.weightByPiece IS NULL; + +UPDATE vn.item i + JOIN vn.itemCost ic ON ic.itemFk = i.id and ic.warehouseFk = 7 + SET i.weightByPiece = ic.grams + WHERE weightByPiece IS NULL; + +UPDATE vn.item i + JOIN vn.itemCost ic ON ic.itemFk = i.id + SET i.weightByPiece = ic.grams + WHERE i.weightByPiece IS NULL + AND ic.warehouseFk NOT IN (60,7);*/ \ No newline at end of file diff --git a/db/versions/.archive/10171-crimsonCarnation/02-agencymode.sql b/db/versions/.archive/10171-crimsonCarnation/02-agencymode.sql new file mode 100644 index 000000000..28413f789 --- /dev/null +++ b/db/versions/.archive/10171-crimsonCarnation/02-agencymode.sql @@ -0,0 +1 @@ +ALTER TABLE vn.agencyMode ADD hasWeightVolumetric INT DEFAULT 0 NOT NULL COMMENT 'Tiene en cuenta el peso volumetrico para los calculos'; diff --git a/db/versions/.archive/10172-brownMedeola/00-firstScript.sql b/db/versions/.archive/10172-brownMedeola/00-firstScript.sql new file mode 100644 index 000000000..b5ed114a2 --- /dev/null +++ b/db/versions/.archive/10172-brownMedeola/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE `vn`.`ticket` +CHANGE COLUMN `notes` `notes__` LONGTEXT COLLATE 'utf8mb3_unicode_ci' NULL DEFAULT NULL , +CHANGE COLUMN `invoiceOutFk` `invoiceOutFk__` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT 'eliminar' , +CHANGE COLUMN `isBooked` `isBooked__` TINYINT(1) NOT NULL DEFAULT 0 ; diff --git a/db/versions/.archive/10174-silverOrchid/00-firstScript.sql b/db/versions/.archive/10174-silverOrchid/00-firstScript.sql new file mode 100644 index 000000000..23aa7bfca --- /dev/null +++ b/db/versions/.archive/10174-silverOrchid/00-firstScript.sql @@ -0,0 +1,25 @@ +USE vn; + +ALTER TABLE `vn`.`printer` +ADD COLUMN `sectorFk` INT(11) NULL DEFAULT NULL AFTER `isLabeler`, +ADD INDEX `printer_sectorFk_idx` (`id` ASC, `sectorFk` ASC) ; + +ALTER TABLE `vn`.`printer` +ADD CONSTRAINT `printer_sectorFk` + FOREIGN KEY (`sectorFk`) + REFERENCES `vn`.`sector` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + +DELETE FROM `vn`.`sector` WHERE (`id` = '61') and (`warehouseFk` = '60'); +UPDATE `vn`.`sector` SET `description` = 'Zona Palletizado', `code` = 'pallet1' WHERE (`id` = '60') and (`warehouseFk` = '60'); + +UPDATE `vn`.`printer` SET `sectorFk` = '60' WHERE (`id` = '68'); +UPDATE `vn`.`printer` SET `sectorFk` = '60' WHERE (`id` = '54'); +UPDATE `vn`.`printer` SET `sectorFk` = '60' WHERE (`id` = '58'); +UPDATE `vn`.`printer` SET `sectorFk` = '60' WHERE (`id` = '60'); +UPDATE `vn`.`printer` SET `sectorFk` = '40' WHERE (`id` = '89'); +UPDATE `vn`.`printer` SET `sectorFk` = '40' WHERE (`id` = '66'); +UPDATE `vn`.`printer` SET `sectorFk` = '41' WHERE (`id` = '88'); +UPDATE `vn`.`printer` SET `sectorFk` = '41' WHERE (`id` = '36'); diff --git a/db/versions/.archive/10175-bluePaniculata/00-firstScript.sql b/db/versions/.archive/10175-bluePaniculata/00-firstScript.sql new file mode 100644 index 000000000..c492182a1 --- /dev/null +++ b/db/versions/.archive/10175-bluePaniculata/00-firstScript.sql @@ -0,0 +1,40 @@ +CREATE TABLE `vn`.`mdbBranch` ( + `name` VARCHAR(255), + PRIMARY KEY(`name`) +); + +CREATE TABLE `vn`.`mdbVersion` ( + `app` VARCHAR(255) NOT NULL, + `branchFk` VARCHAR(255) NOT NULL, + `version` INT, + CONSTRAINT `mdbVersion_branchFk` FOREIGN KEY (`branchFk`) REFERENCES `vn`.`mdbBranch` (`name`) ON DELETE CASCADE ON UPDATE CASCADE +); + +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('MdbVersion', '*', '*', 'ALLOW', 'ROLE', 'developer'); + +INSERT INTO `vn`.`mdbBranch` (`name`) + VALUES + ('test'), + ('master'); + +INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`) + SELECT programa, 'master', version + FROM vn2008.versiones; + +INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`) + SELECT programa, 'test', version + FROM vn2008.versiones; + +RENAME TABLE vn2008.versiones TO vn2008.versiones__; + +CREATE OR REPLACE +ALGORITHM = UNDEFINED VIEW `vn2008`.`versiones` AS +SELECT + `m`.`app` AS `programa`, + `m`.`version` AS `version`, + 0 AS `critical` +FROM + `vn`.`mdbVersion` `m` +WHERE + (`m`.`branchFk` = 'master'); diff --git a/db/versions/.archive/10177-pinkArborvitae/00-crearTablaSpecialLabels.sql b/db/versions/.archive/10177-pinkArborvitae/00-crearTablaSpecialLabels.sql new file mode 100644 index 000000000..ad0d326da --- /dev/null +++ b/db/versions/.archive/10177-pinkArborvitae/00-crearTablaSpecialLabels.sql @@ -0,0 +1,11 @@ +CREATE TABLE vn.specialLabels ( + id INT auto_increment NOT NULL, + description varchar(100) NOT NULL, + reportName varchar(100) NOT NULL, + isVisible BOOL DEFAULT 0 NOT NULL, + image BLOB NULL, + CONSTRAINT specialLabels_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/.archive/10178-tealMoss/00-firstScript.sql b/db/versions/.archive/10178-tealMoss/00-firstScript.sql new file mode 100644 index 000000000..f96dc41be --- /dev/null +++ b/db/versions/.archive/10178-tealMoss/00-firstScript.sql @@ -0,0 +1,6 @@ +DROP VIEW vn.absenceType; +ALTER TABLE vn.calendar DROP FOREIGN KEY calendar_employee_state_id; +RENAME TABLE postgresql.calendar_state TO vn.absenceType; +ALTER TABLE vn.absenceType CHANGE calendar_state_id id int(11) auto_increment NOT NULL; +ALTER TABLE vn.absenceType CHANGE `type` name varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL; +ALTER TABLE vn.calendar ADD CONSTRAINT calendar_FK FOREIGN KEY (dayOffTypeFk) REFERENCES vn.absenceType(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10179-goldenMonstera/00-firstScript.sql b/db/versions/.archive/10179-goldenMonstera/00-firstScript.sql new file mode 100644 index 000000000..76089284c --- /dev/null +++ b/db/versions/.archive/10179-goldenMonstera/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`payment` +CHANGE COLUMN `exchangeInsuranceFk` `exchangeInsuranceFk__` INT(11) NULL DEFAULT NULL ; diff --git a/db/versions/.archive/10183-navyBamboo/00-firstScript.sql b/db/versions/.archive/10183-navyBamboo/00-firstScript.sql new file mode 100644 index 000000000..37c5d05e3 --- /dev/null +++ b/db/versions/.archive/10183-navyBamboo/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.expedition CHANGE checked checked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Deprecado 01/06/2022'; +ALTER TABLE vn.expedition MODIFY COLUMN checked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Deprecado 01/06/2022'; +ALTER TABLE vn.expedition CHANGE isRefund isRefund__ bit(1) DEFAULT b'0' NULL COMMENT 'Deprecado 01/06/2022'; +ALTER TABLE vn.expedition MODIFY COLUMN isRefund__ bit(1) DEFAULT b'0' NULL COMMENT 'Deprecado 01/06/2022'; +ALTER TABLE vn.expedition CHANGE isPickUp isPickUp__ bit(1) DEFAULT b'0' NULL COMMENT 'Deprecado 01/06/2022'; +ALTER TABLE vn.expedition MODIFY COLUMN isPickUp__ bit(1) DEFAULT b'0' NULL COMMENT 'Deprecado 01/06/2022'; \ No newline at end of file diff --git a/db/versions/.archive/10184-azureLaurel/00-firstScript.sql b/db/versions/.archive/10184-azureLaurel/00-firstScript.sql new file mode 100644 index 000000000..94900d44d --- /dev/null +++ b/db/versions/.archive/10184-azureLaurel/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.itemType ADD maxRefs INT UNSIGNED NULL COMMENT 'Indica el número máximo de referencias'; \ No newline at end of file diff --git a/db/versions/.archive/10185-greenGalax/00-firstScript.sql b/db/versions/.archive/10185-greenGalax/00-firstScript.sql new file mode 100644 index 000000000..03a46e785 --- /dev/null +++ b/db/versions/.archive/10185-greenGalax/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here + +ALTER TABLE vn.clientConfig ADD maxPriceIncreasingRatio DECIMAL(2,2) DEFAULT 0.25 NOT NULL COMMENT 'máximo recobro permitido'; diff --git a/db/versions/.archive/10186-silverGerbera/00-desactivar_trigger.sql b/db/versions/.archive/10186-silverGerbera/00-desactivar_trigger.sql new file mode 100644 index 000000000..d32e8299d --- /dev/null +++ b/db/versions/.archive/10186-silverGerbera/00-desactivar_trigger.sql @@ -0,0 +1,2 @@ +-- desactivem trigger per a canviar el camp +DROP TRIGGER IF EXISTS `vn`.`buy_afterUpdate`; \ No newline at end of file diff --git a/db/versions/.archive/10186-silverGerbera/01-alter_Table_buy.sql b/db/versions/.archive/10186-silverGerbera/01-alter_Table_buy.sql new file mode 100644 index 000000000..090fd4a4f --- /dev/null +++ b/db/versions/.archive/10186-silverGerbera/01-alter_Table_buy.sql @@ -0,0 +1,3 @@ +-- buy.sticker not null, por defecto valor cero +ALTER TABLE vn.buy MODIFY COLUMN stickers int(11) DEFAULT 0 NOT NULL; +ALTER TABLE vn.buy MODIFY COLUMN printedStickers int(11) DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10186-silverGerbera/02-alter_table_entryConfig.sql b/db/versions/.archive/10186-silverGerbera/02-alter_table_entryConfig.sql new file mode 100644 index 000000000..8a350d656 --- /dev/null +++ b/db/versions/.archive/10186-silverGerbera/02-alter_table_entryConfig.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`entryConfig` ADD COLUMN `inventorySupplierFk` INT(11) NULL DEFAULT 4 AFTER `mailToNotify`; \ No newline at end of file diff --git a/db/versions/.archive/10186-silverGerbera/04-regularizar_Sticker_Inventario.sql b/db/versions/.archive/10186-silverGerbera/04-regularizar_Sticker_Inventario.sql new file mode 100644 index 000000000..3cfd57d3c --- /dev/null +++ b/db/versions/.archive/10186-silverGerbera/04-regularizar_Sticker_Inventario.sql @@ -0,0 +1,6 @@ +-- recorrer los inventarios y verificar que no tengan el campo sticker > 0 en caso contrario regularizar a zero +UPDATE vn.buy b +JOIN vn.entry e ON e.id = b.entryFk +JOIN vn.entryConfig ec ON ec.inventorySupplierFk = e.supplierFk +SET printedStickers = 0 +WHERE printedStickers <> 0; \ No newline at end of file diff --git a/db/versions/.archive/10186-silverGerbera/09-reactivar_trigger.sql b/db/versions/.archive/10186-silverGerbera/09-reactivar_trigger.sql new file mode 100644 index 000000000..9f37fa5af --- /dev/null +++ b/db/versions/.archive/10186-silverGerbera/09-reactivar_trigger.sql @@ -0,0 +1,94 @@ +-- reactivem trigger +DROP TRIGGER IF EXISTS `vn`.`buy_afterUpdate`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_afterUpdate` + AFTER UPDATE ON `buy` + FOR EACH ROW +trig: BEGIN + DECLARE vLanded DATE; + DECLARE vBuyerFk INT; + DECLARE vIsBuyerToBeEmailed BOOL; + DECLARE vItemName VARCHAR(50); + DECLARE vIsInventory BOOL; + DECLARE vEmail VARCHAR(255); + + IF !(NEW.id <=> OLD.id) + OR !(NEW.entryFk <=> OLD.entryFk) + OR !(NEW.itemFk <=> OLD.itemFk) + OR !(NEW.quantity <=> OLD.quantity) + OR !(NEW.created <=> OLD.created) THEN + CALL stock.log_add('buy', NEW.id, OLD.id); + END IF; + + IF @isModeInventory THEN + LEAVE trig; + END IF; + + CALL buy_afterUpsert(NEW.id); + + IF !(NEW.weight <=> OLD.weight) AND NEW.weight THEN + UPDATE item + SET density = NEW.weight / (item_getVolume(NEW.itemFk, NEW.packageFk) / 1000000) + WHERE id = NEW.itemFk; + END IF; + + SELECT w.isBuyerToBeEmailed, t.landed + INTO vIsBuyerToBeEmailed, vLanded + FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE e.id = NEW.entryFk; + + SELECT it.workerFk, i.longName + INTO vBuyerFk, vItemName + FROM itemCategory k + JOIN itemType it ON it.categoryFk = k.id + JOIN item i ON i.typeFk = it.id + WHERE i.id = OLD.itemFk; + + IF vIsBuyerToBeEmailed AND + vBuyerFk != account.myUser_getId() AND + vLanded = util.CURDATE() THEN + IF !(NEW.itemFk <=> OLD.itemFk) OR + !(NEW.quantity <=> OLD.quantity) OR + !(NEW.packing <=> OLD.packing) OR + !(NEW.grouping <=> OLD.grouping) OR + !(NEW.packageFk <=> OLD.packageFk) OR + !(NEW.weight <=> OLD.weight) THEN + CALL vn.mail_insert( + CONCAT(account.user_getNameFromId(vBuyerFk),'@verdnatura.es'), + CONCAT(account.myUser_getName(),'@verdnatura.es'), + CONCAT('E ', NEW.entryFk ,' Se ha modificado item ', NEW.itemFk, ' ', vItemName), + 'Este email se ha generado automáticamente' + ); + END IF; + END IF; + + SELECT e.isInventory INTO vIsInventory + FROM entry e + WHERE e.id = NEW.entryFk; + + SELECT e.mailToNotify INTO vEmail + FROM entryConfig e + LIMIT 1; + + IF vIsInventory AND + (!(NEW.quantity <=> OLD.quantity) + OR !(NEW.price1<=>OLD.price1) + OR !(NEW.price2<=>OLD.price2) + OR !(NEW.price3<=>OLD.price3)) THEN + + CALL mail_insert( + vEmail, + NULL, + CONCAT('Se ha modificado la entrada ', NEW.entryFk ,' del Artículo ', NEW.itemFk, ' siendo inventario'), + CONCAT( + 'Antes: Cantidad: ', OLD.quantity, ' Precio1: ', OLD.price1, ' Precio2: ', OLD.price2, ' Precio3: ', OLD.price3, + '
', + 'Despues: Cantidad: ', NEW.quantity, ' Precio1: ', NEW.price1, ' Precio2: ', NEW.price2, ' Precio3: ', NEW.price3 + ) + ); + END IF; + +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/.archive/10187-pinkAspidistra/00-firstScript.sql b/db/versions/.archive/10187-pinkAspidistra/00-firstScript.sql new file mode 100644 index 000000000..1fa97095e --- /dev/null +++ b/db/versions/.archive/10187-pinkAspidistra/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn.agency CHANGE isVolumetric isVolumetric__ tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Si el calculo del porte se hacer por volumen'; +ALTER TABLE vn.agency CHANGE bankFk bankFk__ int(11) DEFAULT 8 NOT NULL COMMENT 'para realizar los reembolsos'; +ALTER TABLE vn.agency CHANGE labelZone labelZone__ tinyint(4) DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10188-limeMedeola/00-firstScript.sql b/db/versions/.archive/10188-limeMedeola/00-firstScript.sql new file mode 100644 index 000000000..f3a153748 --- /dev/null +++ b/db/versions/.archive/10188-limeMedeola/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +ALTER TABLE vn.client CHANGE cc cc__ varchar(23) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT 'obsoleta (comprobar)'; +ALTER TABLE vn.client CHANGE cyc cyc__ double NULL COMMENT 'obsoleta (comprobar)'; +ALTER TABLE vn.client CHANGE discount discount__ tinyint(3) unsigned DEFAULT 0 NOT NULL COMMENT 'obsoleta (comprobar)'; +ALTER TABLE vn.client CHANGE notes notes__ text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT 'obsoleta (comprobar)'; diff --git a/db/versions/.archive/10189-aquaDendro/00-firstScript.sql b/db/versions/.archive/10189-aquaDendro/00-firstScript.sql new file mode 100644 index 000000000..222cd9986 --- /dev/null +++ b/db/versions/.archive/10189-aquaDendro/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`itemType` CHANGE gramsMin gramsMin__ int(11) DEFAULT NULL NULL; +ALTER TABLE `vn`.`itemType` CHANGE f11 f11__ tinyint(4) DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10191-orangeRoebelini/00-firstScript.sql b/db/versions/.archive/10191-orangeRoebelini/00-firstScript.sql new file mode 100644 index 000000000..58674b9e5 --- /dev/null +++ b/db/versions/.archive/10191-orangeRoebelini/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.item DROP FOREIGN KEY item_ibfk_6; +ALTER TABLE vn.item CHANGE sectorFk sectorFk__ int(11) DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/.archive/10194-redRose/00-firstScript.sql b/db/versions/.archive/10194-redRose/00-firstScript.sql new file mode 100644 index 000000000..213423dbb --- /dev/null +++ b/db/versions/.archive/10194-redRose/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.sector CHANGE `path` path__ int(11) DEFAULT NULL NULL; +ALTER TABLE vn.sector CHANGE pickingPlacement pickingPlacement__ varchar(15) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; diff --git a/db/versions/.archive/10195-redPhormium/00-firstScript.sql b/db/versions/.archive/10195-redPhormium/00-firstScript.sql new file mode 100644 index 000000000..532f8a4f8 --- /dev/null +++ b/db/versions/.archive/10195-redPhormium/00-firstScript.sql @@ -0,0 +1,24 @@ +CREATE TABLE `vn`.`itemCleanConfig` ( + `id` int(11) NOT NULL, + `step` int(11) NOT NULL COMMENT 'Indica los items que procesa en cada ciclo', + `quantity` int(11) NOT NULL COMMENT 'Indica el número de items que va a procesar', + `isStop` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +INSERT INTO vn.itemCleanConfig (id,step,quantity,isStop) + VALUES (1,500,100000,0); + +CREATE TABLE vn.itemCleanCount ( + id int(11) auto_increment NOT NULL, + itemFrom int(11) NULL COMMENT 'Indica el item por donde ha empezado', + itemDeleted int(11) NULL COMMENT 'Indica la cantidad de items que ha eliminado', + created TIMESTAMP DEFAULT current_timestamp() NULL, + PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8 +COLLATE=utf8_unicode_ci; + +INSERT INTO bs.nightTask (`order`,`schema`,`procedure`) + VALUES (1008,'vn','item_cleanLauncher'); \ No newline at end of file diff --git a/db/versions/.archive/10200-bronzeCyca/00-firstScript.sql b/db/versions/.archive/10200-bronzeCyca/00-firstScript.sql new file mode 100644 index 000000000..d18c9f57a --- /dev/null +++ b/db/versions/.archive/10200-bronzeCyca/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE vn.itemConfig ADD monthToDeactivate int(3) DEFAULT 24 NOT NULL; +ALTER TABLE vn.item ADD lastUsed datetime DEFAULT CURRENT_TIMESTAMP; +CREATE INDEX item_lastUsed_IDX USING BTREE ON vn.item (lastUsed); +INSERT INTO bs.nightTask (`order`,`schema`,`procedure`) + VALUES (1007,'vn','item_deactivateUnused'); \ No newline at end of file diff --git a/db/versions/.archive/10201-whiteRaphis/00-firstScript.sql b/db/versions/.archive/10201-whiteRaphis/00-firstScript.sql new file mode 100644 index 000000000..ff254a6d1 --- /dev/null +++ b/db/versions/.archive/10201-whiteRaphis/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`origin` +CHANGE COLUMN `flag` `flag__` BLOB NULL DEFAULT NULL , +CHANGE COLUMN `nl` `nl__` TINYINT(4) NOT NULL DEFAULT '0' ; \ No newline at end of file diff --git a/db/versions/.archive/10202-redCamellia/00-Remove_FK_to_ediGenus.sql b/db/versions/.archive/10202-redCamellia/00-Remove_FK_to_ediGenus.sql new file mode 100644 index 000000000..c92cd9de5 --- /dev/null +++ b/db/versions/.archive/10202-redCamellia/00-Remove_FK_to_ediGenus.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.botanicExport DROP FOREIGN KEY botanicExport_FK4; +ALTER TABLE vn.botanicExport DROP FOREIGN KEY botanicExport_FK; \ No newline at end of file diff --git a/db/versions/.archive/10203-redMedeola/00-firstScript.sql b/db/versions/.archive/10203-redMedeola/00-firstScript.sql new file mode 100644 index 000000000..1e6bfa49e --- /dev/null +++ b/db/versions/.archive/10203-redMedeola/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplier MODIFY COLUMN postCode char(8) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/.archive/10204-bronzeCarnation/00-firstScript.sql b/db/versions/.archive/10204-bronzeCarnation/00-firstScript.sql new file mode 100644 index 000000000..6c4885bc0 --- /dev/null +++ b/db/versions/.archive/10204-bronzeCarnation/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.state MODIFY COLUMN name varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; -- codi de Sergio \ No newline at end of file diff --git a/db/versions/.archive/10205-bronzeAnthurium/00-firstScript.sql b/db/versions/.archive/10205-bronzeAnthurium/00-firstScript.sql new file mode 100644 index 000000000..d281dbd42 --- /dev/null +++ b/db/versions/.archive/10205-bronzeAnthurium/00-firstScript.sql @@ -0,0 +1,32 @@ +DROP TEMPORARY TABLE IF EXISTS tmp.priority; +CREATE TEMPORARY TABLE tmp.priority + ENGINE = MEMORY + SELECT itemTagId, MaxPriority + FROM (SELECT it.id itemTagId, priorityChange.MaxPriority, i.id + FROM vn.itemTag it + JOIN vn.item i ON i.id = it.itemFk + JOIN vn.itemType ity ON ity.id = i.typeFk + JOIN (SELECT it.itemFk, max(it.priority) + 1 as MaxPriority + FROM vn.itemTag it + GROUP BY it.`itemFk` + ) priorityChange ON priorityChange.itemFk = i.id + JOIN(SELECT it.itemFk,it.priority, min(it.id) as minId + FROM vn.itemTag it + GROUP BY it.`itemFk`,it.`priority` + ) minId ON minId.itemFk = i.id + AND minId.priority = it.priority + WHERE i.isActive + GROUP BY it.itemFk, it.priority + HAVING COUNT(it.priority) > 1)sub + GROUP BY sub.id; + +SET @isTriggerDisabled := TRUE; + UPDATE vn.itemTag it + JOIN tmp.priority tmp ON tmp.itemTagId = it.id + SET it.priority = tmp.MaxPriority; +SET @isTriggerDisabled := FALSE; + +DROP TEMPORARY TABLE IF EXISTS tmp.priority; + +ALTER TABLE `vn`.`itemTag` +ADD UNIQUE INDEX `itemTagItemPriority` (`itemFk` ASC, `priority` ASC); diff --git a/db/versions/.archive/10207-greenRose/00-Alter_table_entry.sql b/db/versions/.archive/10207-greenRose/00-Alter_table_entry.sql new file mode 100644 index 000000000..d562e3f3b --- /dev/null +++ b/db/versions/.archive/10207-greenRose/00-Alter_table_entry.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.entry ADD invoiceAmount DECIMAL(10,2) DEFAULT NULL; +ALTER TABLE vn.entry ADD buyerFk INT(10) unsigned NULL; +ALTER TABLE vn.entry ADD CONSTRAINT entry_FK FOREIGN KEY (buyerFk) REFERENCES vn.worker(id) ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10207-greenRose/00-Alter_table_entry.undo.sql b/db/versions/.archive/10207-greenRose/00-Alter_table_entry.undo.sql new file mode 100644 index 000000000..c39a01c9b --- /dev/null +++ b/db/versions/.archive/10207-greenRose/00-Alter_table_entry.undo.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.entry DROP invoiceAmount; +ALTER TABLE vn.entry DROP CONSTRAINT entry_FK; +ALTER TABLE vn.entry DROP buyerFk; \ No newline at end of file diff --git a/db/versions/.archive/10207-greenRose/01-Update_invoiceAmount.sql b/db/versions/.archive/10207-greenRose/01-Update_invoiceAmount.sql new file mode 100644 index 000000000..1dc2c8836 --- /dev/null +++ b/db/versions/.archive/10207-greenRose/01-Update_invoiceAmount.sql @@ -0,0 +1,4 @@ + UPDATE IGNORE vn.entry e + JOIN vn.worker w ON w.code = TRIM(Right(REPLACE(e.notes, Char(10), ""), 4)) + SET invoiceAmount = CAST(REPLACE(notes, ',', '.') as DECIMAL (10,2)), + buyerFk = w.id; \ No newline at end of file diff --git a/db/versions/.archive/10208-goldenRuscus/00-firstScript.sql b/db/versions/.archive/10208-goldenRuscus/00-firstScript.sql new file mode 100644 index 000000000..05aaa9b48 --- /dev/null +++ b/db/versions/.archive/10208-goldenRuscus/00-firstScript.sql @@ -0,0 +1,131 @@ +-- Crear tabla en caso de necesitar recuperar + +CREATE TABLE vn.expence__ LIKE vn.expence; +INSERT INTO vn.expence__ SELECT * FROM vn.expence; + +-- Eliminar las Fk en expence + +ALTER TABLE `vn`.`invoiceOutExpence` +DROP FOREIGN KEY `invoiceOutExpence_expenceFk`; +ALTER TABLE `vn`.`invoiceOutExpence` +DROP INDEX `invoiceOutExpence_FK_2_idx` ; + +ALTER TABLE `vn`.`item` +DROP FOREIGN KEY `item_expenceFk`; +ALTER TABLE `vn`.`item` +DROP INDEX `item_expenceFk` ; + +ALTER TABLE `vn`.`invoiceInTax` +DROP FOREIGN KEY `recibida_iva_gastos_id`; +ALTER TABLE `vn`.`invoiceInTax` +DROP INDEX `recibida_iva_gastos_id` ; + +ALTER TABLE `vn`.`invoiceInSage` +DROP FOREIGN KEY `invoiceInSage_expenceFk`; +ALTER TABLE `vn`.`invoiceInSage` +DROP INDEX `invoiceInSage_expenceFk` ; + +ALTER TABLE `vn`.`invoiceIn` +DROP FOREIGN KEY `invoiceIn_expenceFkDeductible`; +ALTER TABLE `vn`.`invoiceIn` +DROP INDEX `invoiceIn_expenceFkDeductible` ; + +ALTER TABLE `vn`.`ticketServiceType` +DROP FOREIGN KEY `ticketServiceType_expenceFk`; +ALTER TABLE `vn`.`ticketServiceType` +DROP INDEX `ticketServiceType_expenceFk` ; + +-- Actualizar tabla expence + +ALTER TABLE `vn`.`expence` +DROP INDEX `iva_tipo_id`; + +ALTER TABLE `vn`.`expence` +DROP COLUMN `isForSale`, +DROP COLUMN `isConbase`; + +CREATE TEMPORARY TABLE tmp.expence +SELECT * + FROM vn.expence + GROUP BY id; + +TRUNCATE vn.expence; + +ALTER TABLE `vn`.`expence` + CHANGE COLUMN `taxTypeFk` `taxTypeFk` TINYINT(4) NULL , + DROP PRIMARY KEY, + ADD PRIMARY KEY (`id`); + +ALTER TABLE `vn`.`expence` + DROP COLUMN `taxTypeFk`; + + +INSERT INTO vn.expence (id, name ,isWithheld) + SELECT id, name ,isWithheld + FROM tmp.expence; + + +-- Volver a poner las Fk en expence + +ALTER TABLE `vn`.`invoiceOutExpence` + ADD INDEX `invoiceOutExpence_expenceFk_idx` (`expenceFk` ASC) ; + +ALTER TABLE `vn`.`invoiceOutExpence` + ADD CONSTRAINT `invoiceOutExpence_expenceFk` + FOREIGN KEY (`expenceFk`) + REFERENCES `vn`.`expence` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`item` + ADD INDEX `item_expenceFk_idx` (`expenceFk` ASC) ; + +ALTER TABLE `vn`.`item` + ADD CONSTRAINT `item_expenceFk` + FOREIGN KEY (`expenceFk`) + REFERENCES `vn`.`expence` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + +ALTER TABLE `vn`.`invoiceInTax` + ADD INDEX `invoiceInTax_idx` (`expenceFk` ASC) ; + +ALTER TABLE `vn`.`invoiceInTax` + ADD CONSTRAINT `invoiceInTax_expenceFk` + FOREIGN KEY (`expenceFk`) + REFERENCES `vn`.`expence` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + +ALTER TABLE `vn`.`invoiceInSage` + ADD INDEX `invoiceInSage_idx` (`expenceFk` ASC) ; + +ALTER TABLE `vn`.`invoiceInSage` + ADD CONSTRAINT `invoiceInSage_expenceFk` + FOREIGN KEY (`expenceFk`) + REFERENCES `vn`.`expence` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`invoiceIn` + ADD INDEX `invoiceIn_expenceFkDeductible_idx` (`expenceFkDeductible` ASC) ; + +ALTER TABLE `vn`.`invoiceIn` + ADD CONSTRAINT `invoiceIn_expenceFkDeductible` + FOREIGN KEY (`expenceFkDeductible`) + REFERENCES `vn`.`expence` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`ticketServiceType` + ADD INDEX `ticketServiceType_expenceFk_idx` (`expenceFk` ASC) ; + +ALTER TABLE `vn`.`ticketServiceType` + ADD CONSTRAINT `ticketServiceType_expenceFk` + FOREIGN KEY (`expenceFk`) + REFERENCES `vn`.`expence` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + \ No newline at end of file diff --git a/db/versions/.archive/10209-bronzeBirch/00-firstScript.sql b/db/versions/.archive/10209-bronzeBirch/00-firstScript.sql new file mode 100644 index 000000000..681faa1b1 --- /dev/null +++ b/db/versions/.archive/10209-bronzeBirch/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE account.`user` ADD CONSTRAINT mail UNIQUE KEY (email); \ No newline at end of file diff --git a/db/versions/.archive/10211-greenDendro/01-firstScript.sql b/db/versions/.archive/10211-greenDendro/01-firstScript.sql new file mode 100644 index 000000000..ebea1865e --- /dev/null +++ b/db/versions/.archive/10211-greenDendro/01-firstScript.sql @@ -0,0 +1,24 @@ +USE `vn`; + +DROP TABLE IF EXISTS vn.splitFilter; +CREATE TABLE `vn`.`splitFilter` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `autonomyFk` int(11) DEFAULT NULL, + `clientFk` int(11) DEFAULT NULL, + `nickname` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `splitFilter_UN` (`autonomyFk`), + UNIQUE KEY `splitFilter_UN1` (`clientFk`), + KEY `splitFilter_FK` (`autonomyFk`), + KEY `splitFilter_FK_1` (`clientFk`), + CONSTRAINT `splitFilter_FK` FOREIGN KEY (`autonomyFk`) REFERENCES `autonomy` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `splitFilter_FK_1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='define los clientes que tienen split y el nombre a mostrar en la etiqueta'; + +INSERT INTO vn.splitFilter +(id, autonomyFk, clientFk, nickname) +VALUES(1, 7, NULL, '<>'); + +INSERT INTO vn.splitFilter +(id, autonomyFk, clientFk, nickname) +VALUES(2, NULL, 93, 'DIONI'); diff --git a/db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.sql b/db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.sql new file mode 100644 index 000000000..aeb072de5 --- /dev/null +++ b/db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entry CHANGE isInventory isExcludedFromAvailable tinyint(1) DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.undo.sql b/db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.undo.sql new file mode 100644 index 000000000..786d31887 --- /dev/null +++ b/db/versions/.archive/10215-yellowAnthurium/00-renameIsInventory.undo.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entry CHANGE isExcludedFromAvailable isInventory tinyint(1) DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10216-pinkMedeola/00-firstScript.sql b/db/versions/.archive/10216-pinkMedeola/00-firstScript.sql new file mode 100644 index 000000000..91e500f20 --- /dev/null +++ b/db/versions/.archive/10216-pinkMedeola/00-firstScript.sql @@ -0,0 +1,36 @@ +ALTER TABLE edi.ekt + ADD batchNumber BIGINT(20) UNSIGNED NULL COMMENT 'RFF+BT' AFTER entryYear; + +ALTER TABLE edi.`param` ADD UNIQUE(`code`); + +INSERT IGNORE INTO edi.`param` (`id`, `code`, `name`, `subname`, `position`, `type`, `required`) + VALUES ('0', 'batchNumber', 'RFF', 'BT', '2', 'INTEGER', '0'); + +ALTER TABLE edi.ekt + MODIFY COLUMN id int(11) auto_increment NOT NULL COMMENT 'Id', + MODIFY COLUMN barcode char(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL COMMENT 'Generated auction barcode', + MODIFY COLUMN entryYear smallint(5) unsigned NOT NULL COMMENT 'Transaction year', + MODIFY COLUMN deliveryNumber bigint(20) unsigned DEFAULT NULL NULL COMMENT 'RFF+AAJ', + MODIFY COLUMN fec date DEFAULT NULL NULL COMMENT 'DTM+97', + MODIFY COLUMN hor time DEFAULT NULL NULL COMMENT 'UNB', + MODIFY COLUMN now timestamp DEFAULT current_timestamp() NULL COMMENT 'Creation time', + MODIFY COLUMN ptj mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'NAD+BY', + MODIFY COLUMN `ref` int(11) NOT NULL COMMENT 'LIN', + MODIFY COLUMN item varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL COMMENT 'IMD+S99', + MODIFY COLUMN pac int(11) DEFAULT 0 NULL COMMENT 'QTY+52', + MODIFY COLUMN qty int(10) NOT NULL COMMENT 'QTY+66', + MODIFY COLUMN ori varchar(3) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT 'NL' NULL COMMENT 'IMD+S62', + MODIFY COLUMN cat varchar(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL COMMENT 'IMD+S98', + MODIFY COLUMN agj int(11) DEFAULT NULL NULL COMMENT 'RFF+AGJ', + MODIFY COLUMN kop int(11) DEFAULT NULL NULL COMMENT 'RFF+ADZ', + MODIFY COLUMN ptd varchar(6) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL COMMENT 'RFF+ACE', + MODIFY COLUMN sub mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'RFF+CTS', + MODIFY COLUMN pro mediumint(8) unsigned NOT NULL COMMENT 'NAD+MF', + MODIFY COLUMN pri double NOT NULL COMMENT 'PRI+INV', + MODIFY COLUMN package int(10) unsigned DEFAULT NULL NULL COMMENT 'PAC', + MODIFY COLUMN auction smallint(5) unsigned DEFAULT NULL NULL COMMENT 'NAD+FLA', + MODIFY COLUMN klo smallint(5) unsigned DEFAULT NULL NULL COMMENT 'RFF+FAC', + MODIFY COLUMN k1 smallint(5) unsigned DEFAULT NULL NULL COMMENT 'IMD+K01', + MODIFY COLUMN k2 smallint(5) unsigned DEFAULT NULL NULL COMMENT 'IMD+K02', + MODIFY COLUMN putOrderFk bigint(20) unsigned DEFAULT NULL NULL COMMENT 'RFF+ON', + MODIFY COLUMN scanned tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Whether it''s been scanned'; diff --git a/db/versions/.archive/10216-pinkMedeola/00-firstScript.undo.sql b/db/versions/.archive/10216-pinkMedeola/00-firstScript.undo.sql new file mode 100644 index 000000000..5424e10fa --- /dev/null +++ b/db/versions/.archive/10216-pinkMedeola/00-firstScript.undo.sql @@ -0,0 +1,35 @@ +ALTER TABLE edi.ekt + DROP COLUMN batchNumber; + +ALTER TABLE `param` DROP INDEX `code`; + +DELETE FROM edi.`param` WHERE code = 'batchNumber' + +ALTER TABLE edi.ekt + MODIFY COLUMN id int(11) auto_increment NOT NULL, + MODIFY COLUMN barcode char(15) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL, + MODIFY COLUMN entryYear smallint(5) unsigned NOT NULL, + MODIFY COLUMN deliveryNumber bigint(20) unsigned DEFAULT NULL NULL, + MODIFY COLUMN fec date DEFAULT NULL NULL, + MODIFY COLUMN hor time DEFAULT NULL NULL, + MODIFY COLUMN now timestamp DEFAULT current_timestamp() NULL, + MODIFY COLUMN ptj mediumint(8) unsigned DEFAULT NULL NULL, + MODIFY COLUMN `ref` int(11) NOT NULL, + MODIFY COLUMN item varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL, + MODIFY COLUMN pac int(11) DEFAULT 0 NULL, + MODIFY COLUMN qty int(10) NOT NULL, + MODIFY COLUMN ori varchar(3) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT 'NL' NULL, + MODIFY COLUMN cat varchar(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL, + MODIFY COLUMN agj int(11) DEFAULT NULL NULL, + MODIFY COLUMN kop int(11) DEFAULT NULL NULL, + MODIFY COLUMN ptd varchar(6) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL NULL, + MODIFY COLUMN sub mediumint(8) unsigned DEFAULT NULL NULL, + MODIFY COLUMN pro mediumint(8) unsigned NOT NULL, + MODIFY COLUMN pri double NOT NULL, + MODIFY COLUMN package int(10) unsigned DEFAULT NULL NULL, + MODIFY COLUMN auction smallint(5) unsigned DEFAULT NULL NULL, + MODIFY COLUMN klo smallint(5) unsigned DEFAULT NULL NULL, + MODIFY COLUMN k1 smallint(5) unsigned DEFAULT NULL NULL, + MODIFY COLUMN k2 smallint(5) unsigned DEFAULT NULL NULL, + MODIFY COLUMN putOrderFk bigint(20) unsigned DEFAULT NULL NULL, + MODIFY COLUMN scanned tinyint(1) DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10216-pinkMedeola/01-batchIndex.sql b/db/versions/.archive/10216-pinkMedeola/01-batchIndex.sql new file mode 100644 index 000000000..536526c22 --- /dev/null +++ b/db/versions/.archive/10216-pinkMedeola/01-batchIndex.sql @@ -0,0 +1,15 @@ +CREATE INDEX ekt_batchNumber USING BTREE ON edi.ekt (batchNumber); + +ALTER TABLE edi.ekt + MODIFY COLUMN k3 tinyint(3) unsigned DEFAULT NULL NULL COMMENT 'IMD+P01', + MODIFY COLUMN k4 tinyint(3) unsigned DEFAULT NULL NULL COMMENT 'IMD+P02'; + +ALTER TABLE edi.mail ADD source TEXT DEFAULT NULL NULL; + +ALTER TABLE edi.ekt + ADD vendorOrderNumber BIGINT(20) unsigned DEFAULT NULL NULL COMMENT 'RFF+VN' AFTER deliveryNumber; + +CREATE INDEX ekt_vendorOrderNumber USING BTREE ON edi.ekt (vendorOrderNumber); + +INSERT INTO edi.param (code,name,subname,`position`,`type`,required) VALUES + ('vendorOrderNumber','RFF','VN',2,'INTEGER',0); diff --git a/db/versions/.archive/10216-pinkMedeola/01-batchIndex.undo.sql b/db/versions/.archive/10216-pinkMedeola/01-batchIndex.undo.sql new file mode 100644 index 000000000..a62ced45d --- /dev/null +++ b/db/versions/.archive/10216-pinkMedeola/01-batchIndex.undo.sql @@ -0,0 +1,11 @@ +ALTER TABLE edi.ekt DROP INDEX ekt_batchNumber; + +ALTER TABLE edi.ekt + MODIFY COLUMN k3 tinyint(3) unsigned DEFAULT NULL NULL, + MODIFY COLUMN k4 tinyint(3) unsigned DEFAULT NULL NULL; + +ALTER TABLE edi.mail DROP COLUMN source; + +ALTER TABLE edi.ekt DROP COLUMN vendorOrderNumber; + +DELETE FROM edi.param WHERE code = 'vendorOrderNumber'; diff --git a/db/versions/.archive/10219-orangeRuscus/00-AddCollectionFkOnPackingSite.sql b/db/versions/.archive/10219-orangeRuscus/00-AddCollectionFkOnPackingSite.sql new file mode 100644 index 000000000..1e5b4b9b8 --- /dev/null +++ b/db/versions/.archive/10219-orangeRuscus/00-AddCollectionFkOnPackingSite.sql @@ -0,0 +1 @@ +ALTER TABLE vn.packingSite ADD collectionFk INT(11) NULL COMMENT 'Last collection packed on this site'; \ No newline at end of file diff --git a/db/versions/.archive/10219-orangeRuscus/01-AddFkToCollectionFk.sql b/db/versions/.archive/10219-orangeRuscus/01-AddFkToCollectionFk.sql new file mode 100644 index 000000000..249b21d87 --- /dev/null +++ b/db/versions/.archive/10219-orangeRuscus/01-AddFkToCollectionFk.sql @@ -0,0 +1 @@ +ALTER TABLE vn.packingSite ADD CONSTRAINT packingSite_FK_2 FOREIGN KEY (collectionFk) REFERENCES vn.collection(id) ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/db/versions/.archive/10220-chocolateCymbidium/00-createPersonalProtectionEquipment.sql b/db/versions/.archive/10220-chocolateCymbidium/00-createPersonalProtectionEquipment.sql new file mode 100644 index 000000000..e4eceb924 --- /dev/null +++ b/db/versions/.archive/10220-chocolateCymbidium/00-createPersonalProtectionEquipment.sql @@ -0,0 +1,8 @@ +DROP TABLE IF EXISTS `vn`.`personalProtectionEquipment`; +CREATE TABLE `vn`.`personalProtectionEquipment` ( + `id` INT(11) Primary Key auto_increment NOT NULL, + `name` varchar(255) NOT NULL +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8 +COLLATE=utf8_unicode_ci; diff --git a/db/versions/.archive/10222-redEucalyptus/00-firstScript.sql b/db/versions/.archive/10222-redEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..f78b18ec7 --- /dev/null +++ b/db/versions/.archive/10222-redEucalyptus/00-firstScript.sql @@ -0,0 +1,226 @@ +USE vn; + +ALTER TABLE `vn`.`route` +CHANGE COLUMN `kmStart` `kmStart` MEDIUMINT(9) NULL DEFAULT NULL , +CHANGE COLUMN `kmEnd` `kmEnd` MEDIUMINT(9) NULL DEFAULT NULL ; + +DROP TABLE IF EXISTS `vn`.`routeCommission`; +CREATE TABLE `vn`.`routeCommission` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `routeFk` int(10) unsigned NOT NULL, + `workCenterFk` int(11) DEFAULT NULL, + `km` decimal(5,2) DEFAULT NULL, + `m3` decimal(5,2) DEFAULT NULL, + `yearlyKm` decimal(5,2) DEFAULT NULL, + `yearlyM3` decimal(5,2) DEFAULT NULL, + `cat4m3` decimal(5,2) DEFAULT NULL, + `cat5m3` decimal(5,2) DEFAULT NULL, + `freelanceYearlyM3` decimal(5,2) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `routeCommission_routeFk_idx` (`routeFk`), + KEY `routeCommission_workCenterFk_idx` (`workCenterFk`), + CONSTRAINT `routeCommission_routeFk` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON UPDATE CASCADE, + CONSTRAINT `routeCommission_workCenterFk` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +ALTER TABLE `vn`.`routeConfig` +ADD COLUMN `kmHeavy` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por kilometro vehículo pesado', +ADD COLUMN `kmLight` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por kilometro vehículo ligero', +ADD COLUMN `kmYearly` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por kilometro objetivo anual', +ADD COLUMN `m3Yearly` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por m3 objetivo anual', +ADD COLUMN `deliveryM3Cat4` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por m3 repartido Cat.IV', +ADD COLUMN `deliveryM3Cat5` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por m3 repartido Cat. V', +ADD COLUMN `plusCat2Fixed` decimal(5,2) DEFAULT NULL COMMENT 'Plus fijo Cat.II vehículo ligero', +ADD COLUMN `plusCat2Variable` decimal(5,2) DEFAULT NULL COMMENT 'Plus variable Cat.II vehículo ligero', +ADD COLUMN `plusCat3Fixed` decimal(5,2) DEFAULT NULL COMMENT 'Plus fijo Cat.III vehículo pesado', +ADD COLUMN `plusCat3Variable` decimal(5,2) DEFAULT NULL COMMENT 'Plus variable Cat.III vehículo pesado', +ADD COLUMN `distributionCat4M3` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por gestión de la distribución Cat IV', +ADD COLUMN `distributionCat5M3` decimal(5,2) DEFAULT NULL COMMENT 'Comisión por gestión de la distribución Cat V', +ADD COLUMN `rateCat4` decimal(5,2) DEFAULT NULL COMMENT 'Ratio aplicado a la media de venta de los repartidores para el cálculo de las comisiones de enrutadores Cat IV', +ADD COLUMN `rateCat5` decimal(5,2) DEFAULT NULL COMMENT 'Ratio aplicado a la media de venta de los repartidores para el cálculo de las comisiones de enrutadores Cat V', +ADD COLUMN `freelanceM3` decimal(5,2) DEFAULT NULL COMMENT 'Comisión para enrutadores sobre rutas de autónomos', +ADD COLUMN `freelanceMinM3` decimal(5,2) DEFAULT NULL COMMENT 'Metros mínimos para considerar las rutas de autónomos', +ADD COLUMN `mainlineDelivered` decimal(5,2) DEFAULT NULL COMMENT 'Comisión para entregas troncales', +ADD COLUMN `cutoffDated` DATE DEFAULT NULL COMMENT 'Fecha a partir de la cual se autoriza calcular la comisión', +ADD COLUMN `defaultWorkCenterFk` INT DEFAULT 9 COMMENT 'Para el cálculo de las comisiones, en caso de el creador de la ruta no tenga workCenter', +ADD COLUMN `kmMax` INT NULL DEFAULT 4000 COMMENT 'Máximo número de km validos para una ruta'; + + +ALTER TABLE `vn`.`route` +ADD COLUMN `commissionWorkCenterFk` INT(11) NULL COMMENT 'WorkerCenter que gestiona la ruta' AFTER `beachFk`, +ADD INDEX `route_WorkCenterFk_idx` (`commissionWorkCenterFk` ASC); + +ALTER TABLE `vn`.`route` +ADD CONSTRAINT `route_WorkCenterFk` + FOREIGN KEY (`commissionWorkCenterFk`) + REFERENCES `vn`.`workCenter` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +UPDATE `vn`.`routeConfig` + SET `kmHeavy` = '0.12', + `kmLight` = '0.11', + `kmYearly` = '0.01', + `m3Yearly` = '0.25', + `deliveryM3Cat4` = '6.54', + `deliveryM3Cat5` = '6.54', + `plusCat2Fixed` = '75', + `plusCat2Variable` = '75', + `plusCat3Fixed` = '150', + `plusCat3Variable` = '150', + `distributionCat4M3` = '1.53', + `distributionCat5M3` = '1.7', + `rateCat4` = '3', + `rateCat5` = '4.66', + `freelanceM3` = '0.10', + `freelanceMinM3` = '1.5', + `mainlineDelivered` = '1', + `cutoffDated` = '2021-12-01' + WHERE (`id` = '1'); + + + UPDATE vn.route r + JOIN(SELECT r.id, wl.workcenterFk + FROM vn.route r + JOIN vn.routeLog rl ON rl.originFk = r.id + JOIN vn.workerLabour wl ON wl.workerFk = rl.userFk + AND r.created BETWEEN wl.started AND IFNULL(wl.ended, r.created) + WHERE r.created BETWEEN '2021-12-01' AND util.CURDATE() + AND rl.action = 'insert' + )sub ON sub.id = r.id + SET r.commissionWorkCenterFk = sub.workcenterFk; + + UPDATE vn.route + SET commissionWorkCenterFk = 9 + WHERE id = 125360; -- la ruta no tiene valor de insert en la tabla vn.routeLog + +ALTER TABLE `vn`.`absenceType` + ADD COLUMN `isNaturalDay` TINYINT(1) NULL DEFAULT 0 COMMENT 'Para el cálculo de los salarios de los repartidores' AFTER `holidayEntitlementRate`, + ADD COLUMN `isCalculate` TINYINT(1) NULL DEFAULT 0 COMMENT 'Para el cálculo de los salarios de los repartidores' AFTER `isNaturalDay`; + +UPDATE `vn`.`absenceType` SET `isNaturalDay` = '1' WHERE (`id` = '1'); +UPDATE `vn`.`absenceType` SET `isNaturalDay` = '1' WHERE (`id` = '6'); + +UPDATE `vn`.`absenceType` SET `isCalculate` = '1' WHERE (`id` = '1'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '1' WHERE (`id` = '2'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '1' WHERE (`id` = '6'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '7'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '1' WHERE (`id` = '10'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '1' WHERE (`id` = '11'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '12'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '14'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '1' WHERE (`id` = '15'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '16'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '17'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '13'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '22'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '21'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '20'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '19'); +UPDATE `vn`.`absenceType` SET `isCalculate` = '0' WHERE (`id` = '18'); + +DROP PROCEDURE IF EXISTS `vn`.`route_calcCommission`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`route_calcCommission`(vSelf INT) +proc: BEGIN +/** + * Calcula las comisión para una ruta y guarda los valores en la tabla routeCommission + * + * @param vSelf id de ruta + */ + DECLARE vIsUpdatable BOOL; + DECLARE vIsFreelance BOOL; + + SELECT r.created >= rc.cutoffDated INTO vIsUpdatable + FROM route r + JOIN routeConfig rc + WHERE r.id = vSelf; + + IF vIsUpdatable THEN + + DELETE FROM routeCommission + WHERE routeFk = vSelf; + + SELECT wl.workerFk IS NULL INTO vIsFreelance + FROM route r + LEFT JOIN workerLabour wl ON wl.workerFk = r.workerFk + WHERE r.id = vSelf + LIMIT 1; + + IF vIsFreelance THEN + INSERT INTO routeCommission (routeFk, workCenterFk, freelanceYearlyM3) + SELECT vSelf, + r.commissionWorkCenterFk, + rc.freelanceM3 * IF(IFNULL(r.m3, 0) >= rc.freelanceMinM3, IFNULL(r.m3, 0), 0) + FROM route r + JOIN vehicle v ON v.id = r.vehicleFk + JOIN routeConfig rc + WHERE r.id = vSelf + AND r.workerFk + AND r.commissionWorkCenterFk + AND r.m3; + ELSE + INSERT INTO routeCommission (routeFk, workCenterFk, km, m3, yearlyKm, yearlyM3, cat4m3, cat5m3) + SELECT vSelf, + r.commissionWorkCenterFk, + FORMAT((r.kmEnd - r.kmStart) * IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), 2), + FORMAT(IFNULL(r.m3, 0) * IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), 2), + FORMAT((r.kmEnd - r.kmStart) * rc.kmYearly, 2), + FORMAT(IFNULL(r.m3, 0) * rc.m3Yearly, 2), + FORMAT(distributionCat4M3 * IFNULL(r.m3, 0), 2), + FORMAT(rc.distributionCat5M3 * IFNULL(r.m3, 0), 2) + FROM route r + JOIN vehicle v ON v.id = r.vehicleFk + JOIN routeConfig rc + WHERE r.id = vSelf + AND r.kmStart + AND r.kmEnd + AND r.workerFk + AND r.commissionWorkCenterFk + AND r.m3; + END IF; + END IF; +END$$ +DELIMITER ; + +DROP PROCEDURE IF EXISTS `vn`.`routeCommission_loadData`; + +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`routeCommission_loadData`() +BEGIN +/** + * Procedimiento temporal para realizar primera carga de datos de la comisiones de las rutas + */ + DECLARE vDone INT DEFAULT FALSE; + DECLARE vRouteFk INT; + DECLARE vCursor CURSOR FOR + SELECT r.id + FROM route r + JOIN routeConfig rc + WHERE r.created BETWEEN rc.cutoffDated AND util.CURDATE() + AND r.kmEnd - r.kmStart <= rc.kmMax; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCursor; + + read_loop: LOOP + + FETCH vCursor INTO vRouteFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + CALL route_calcCommission(vRouteFk); + + END LOOP; + + CLOSE vCursor; + +END$$ +DELIMITER ; + +CALL vn.routeCommission_loadData(); + +DROP PROCEDURE `vn`.`routeCommission_loadData`; diff --git a/db/versions/.archive/10223-azureRuscus/00-firstScript.sql b/db/versions/.archive/10223-azureRuscus/00-firstScript.sql new file mode 100644 index 000000000..56aef8cc7 --- /dev/null +++ b/db/versions/.archive/10223-azureRuscus/00-firstScript.sql @@ -0,0 +1,17 @@ +USE `vn`; + +-- Añadir campo en la tabla ticket + +ALTER TABLE `vn`.`ticket` +ADD COLUMN `weight` DECIMAL(10,2) NULL DEFAULT NULL COMMENT 'En caso de informar, se utilizará su valor para calcular el peso de la factura' AFTER `totalWithoutVat`; + +-- Actualizar campo con los valores de ticketObservation + +UPDATE + vn.ticket t + JOIN (SELECT t.ticketFk, CAST(t.description AS DECIMAL(10,2)) weight + FROM vn.ticketObservation t + LEFT JOIN vn.observationType ot ON ot.id = t.observationTypeFk + WHERE ot.code ='weight' + having weight > 0)sub ON sub.ticketFk = t.id + SET t.weight = sub.weight; \ No newline at end of file diff --git a/db/versions/.archive/10224-orangeEucalyptus/00-cosetes.sql b/db/versions/.archive/10224-orangeEucalyptus/00-cosetes.sql new file mode 100644 index 000000000..a67f0133a --- /dev/null +++ b/db/versions/.archive/10224-orangeEucalyptus/00-cosetes.sql @@ -0,0 +1,20 @@ +use vn; + +CREATE TABLE `vn`.`mrwService` ( + `agencyModeCodeFk` varchar(45) COLLATE utf8mb3_unicode_ci NOT NULL, + `clientType` int(11) unsigned NOT NULL, + `serviceType` int(11) unsigned DEFAULT NULL, + PRIMARY KEY (`agencyModeCodeFk`), + CONSTRAINT `mrwService_agencyModeCodeFk` FOREIGN KEY (`agencyModeCodeFk`) REFERENCES `agencyMode` (`code`)ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de los servicios de MRW'; + +CREATE TABLE `vn`.`mrwServiceWeekday` ( + `agencyModeCodeFk` VARCHAR(45) NOT NULL, + `weekdays` SET('mon','tue','wed','thu','fri','sat','sun') NOT NULL, + `serviceType` INT(11) UNSIGNED NOT NULL, + `params` VARCHAR(255) NULL DEFAULT NULL, + PRIMARY KEY (`agencyModeCodeFk`), + CONSTRAINT `mrwServiceWeekday_agencyModeCodeFk` FOREIGN KEY (agencyModeCodeFk) + REFERENCES `vn`.`agencyMode` (`code`) ON DELETE CASCADE + ON UPDATE CASCADE) +COMMENT = 'Configuración de los servicios en relación con el día de la semana para MRW'; diff --git a/db/versions/.archive/10229-salmonDendro/00-firstScript.sql b/db/versions/.archive/10229-salmonDendro/00-firstScript.sql new file mode 100644 index 000000000..6bc6a59fc --- /dev/null +++ b/db/versions/.archive/10229-salmonDendro/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +ALTER TABLE vn.deviceProductionUser DROP FOREIGN KEY deviceProductionUser_FK; +ALTER TABLE vn.deviceProductionUser DROP FOREIGN KEY deviceProductionUser_PK; +ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_FK FOREIGN KEY (deviceProductionFk) REFERENCES vn.deviceProduction(id)ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_PK FOREIGN KEY (userFk) REFERENCES account.`user`(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_CK PRIMARY KEY (deviceProductionFk); +ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_UN UNIQUE KEY (userFk); +ALTER TABLE vn.deviceProductionUser ADD created TIMESTAMP NULL; +ALTER TABLE vn.deviceProductionUser MODIFY COLUMN created timestamp DEFAULT current_timestamp() NULL; \ No newline at end of file diff --git a/db/versions/.archive/10231-buyScanPAK/01-tablaEktConfig.sql b/db/versions/.archive/10231-buyScanPAK/01-tablaEktConfig.sql new file mode 100644 index 000000000..90390f3f7 --- /dev/null +++ b/db/versions/.archive/10231-buyScanPAK/01-tablaEktConfig.sql @@ -0,0 +1,16 @@ +USE edi; + +-- edi.ektConfig definition +CREATE TABLE `ektConfig` ( + `usefulAuctionLeftSegmentLength` int(11) NOT NULL DEFAULT 13 COMMENT 'Segmento aprovechable del codigo de barras de Floricode', + `standardBarcodeLength` int(11) NOT NULL DEFAULT 20 COMMENT 'Longitud del código de barras standard de Floricode', + `floridayBarcodeLength` int(11) NOT NULL DEFAULT 6, + `floramondoBarcodeLength` int(11) NOT NULL DEFAULT 13 COMMENT 'Longitud del código de los albaranes múltiples de Floramondo', + `defaultKlo` int(11) NOT NULL DEFAULT 99 COMMENT 'Reloj por defecto' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT INTO ektConfig (usefulAuctionLeftSegmentLength) + VALUES (DEFAULT); + +DROP TABLE IF EXISTS testData; + diff --git a/db/versions/.archive/10233-aquaCymbidium/00-firstScript.sql b/db/versions/.archive/10233-aquaCymbidium/00-firstScript.sql new file mode 100644 index 000000000..79088b273 --- /dev/null +++ b/db/versions/.archive/10233-aquaCymbidium/00-firstScript.sql @@ -0,0 +1,5 @@ +USE `vn`; + +ALTER TABLE `vn`.`awb` ADD invoiceInPaletizedFk INT NULL; +ALTER TABLE `vn`.`awb` MODIFY COLUMN invoiceInPaletizedFk mediumint(8) unsigned NULL; +ALTER TABLE `vn`.`awb` ADD CONSTRAINT awb_FK_3 FOREIGN KEY (invoiceInPaletizedFk) REFERENCES vn.invoiceIn(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10235-limeDracena/00-firstScript.sql b/db/versions/.archive/10235-limeDracena/00-firstScript.sql new file mode 100644 index 000000000..d755117ec --- /dev/null +++ b/db/versions/.archive/10235-limeDracena/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE `bs`.`produccion` +RENAME TO `bs`.`produccion__` ; + +DELETE FROM `bs`.`nightTask` WHERE (`id` = '45'); diff --git a/db/versions/.archive/10236-limeArborvitae/00-firstScript.sql b/db/versions/.archive/10236-limeArborvitae/00-firstScript.sql new file mode 100644 index 000000000..545f0b813 --- /dev/null +++ b/db/versions/.archive/10236-limeArborvitae/00-firstScript.sql @@ -0,0 +1,93 @@ +CREATE TABLE vn.ppeLocation ( + code varchar(10) NULL, + description varchar(100) NULL, + CONSTRAINT ppeLocation_PK PRIMARY KEY (code) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8 +COLLATE=utf8_unicode_ci; + +INSERT INTO vn.ppeLocation (code, description) VALUES('B01', 'VILASSAR'); +INSERT INTO vn.ppeLocation (code, description) VALUES('H01', 'MERCA HOL'); +INSERT INTO vn.ppeLocation (code, description) VALUES('M01', 'TORREJON DE ARDOZ'); +INSERT INTO vn.ppeLocation (code, description) VALUES('M02', 'MADRID SAN FERNANDO DE HENA'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V01', 'VALENCIA'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V02', 'ALGEMESI P.I. PEPE MIQUEL'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V03', 'Terme d''Alginet'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V04', 'VALENCIA-ALGEMESI (ZONA PULPIS)'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V05', 'MARJAL'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V06', 'Finca Rustica Alzira'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V07', 'NAVE EN SILLA'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V08', 'PICASSENT'); +INSERT INTO vn.ppeLocation (code, description) VALUES('V09', 'Mercavalencia'); + +UPDATE vn.ppe p + JOIN (SELECT p.id, + p.location, + pl.code + FROM vn.ppe p + JOIN vn.ppeLocation pl ON pl.description = p.location) sub ON sub.id = p.id + SET p.location = sub.code; + +UPDATE vn.ppe + SET location='V05' + WHERE id=530; +UPDATE vn.ppe + SET location='V05' + WHERE id=631; +UPDATE vn.ppe + SET location='V03' + WHERE id=643; + +UPDATE vn.ppeLocation + SET description='BARCELONA-VILASSAR' + WHERE code='B01'; +UPDATE vn.ppeLocation + SET description='HOLANDA-MERCA HOL' + WHERE code='H01'; +UPDATE vn.ppeLocation + SET description='MADRID-TORREJON DE ARDOZ' + WHERE code='M01'; +UPDATE vn.ppeLocation + SET description='MADRID-SAN FERNANDO DE HENA' + WHERE code='M02'; +UPDATE vn.ppeLocation + SET description='VALENCIA-ALGEMESI CL FENOLLAR' + WHERE code='V02'; +UPDATE vn.ppeLocation + SET description='VALENCIA-CARLET (ZONA ARENAL)' + WHERE code='V03'; +UPDATE vn.ppeLocation + SET description='VALENCIA-ALGEMESI (ZONA MARJA)' + WHERE code='V05'; +UPDATE vn.ppeLocation + SET description='VALENCIA-ALZIRA (CUADRA)' + WHERE code='V06'; +UPDATE vn.ppeLocation + SET description='VALENCIA-NAVE EN SILLA' + WHERE code='V07'; +UPDATE vn.ppeLocation + SET description='VALENCIA-PICASSENT' + WHERE code='V08'; +UPDATE vn.ppeLocation + SET description='VALENCIA-MERCAVALENCIA' + WHERE code='V09'; + +UPDATE vn.ppeLocation + SET description='HOLANDA-MERCA HOL [BAJA/VENTA]' + WHERE code='H01'; +UPDATE vn.ppeLocation + SET description='MADRID-SAN FERNANDO DE HENA [BAJA/VENTA]' + WHERE code='M02'; +UPDATE vn.ppeLocation + SET description='VALENCIA-NAVE EN SILLA [BAJA/VENTA]' + WHERE code='V07'; +UPDATE vn.ppeLocation + SET description='VALENCIA-PICASSENT [BAJA/VENTA]' + WHERE code='V08'; +UPDATE vn.ppeLocation + SET description='VALENCIA-MERCAVALENCIA [BAJA/VENTA]' + WHERE code='V09'; + +ALTER TABLE vn.ppe MODIFY COLUMN location varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL; +ALTER TABLE vn.ppe ADD CONSTRAINT ppe_FK FOREIGN KEY (location) REFERENCES vn.ppeLocation(code) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10237-greenRoebelini/00-firstScript.sql b/db/versions/.archive/10237-greenRoebelini/00-firstScript.sql new file mode 100644 index 000000000..e35bdee4d --- /dev/null +++ b/db/versions/.archive/10237-greenRoebelini/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +ALTER TABLE vn.tagAbbreviation ADD tagFk int(11) DEFAULT NULL; +ALTER TABLE vn.tagAbbreviation ADD CONSTRAINT tagAbbreviation_FK FOREIGN KEY (tagFk) REFERENCES vn.tag(id); +UPDATE vn.tagAbbreviation + SET tagFk=56 + WHERE value='Rosa'; diff --git a/db/versions/.archive/10238-azureMastic/00-worker_mobileExtension.sql b/db/versions/.archive/10238-azureMastic/00-worker_mobileExtension.sql new file mode 100644 index 000000000..54f94e4ae --- /dev/null +++ b/db/versions/.archive/10238-azureMastic/00-worker_mobileExtension.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.worker ADD mobileExtension INT(4) NULL; +ALTER TABLE vn.worker CHANGE mobileExtension mobileExtension int(4) DEFAULT NULL NULL AFTER phone; +ALTER TABLE vn.worker MODIFY COLUMN phone varchar(9) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL; + +UPDATE vn.worker + SET phone = NULL; diff --git a/db/versions/.archive/10239-redAsparagus/00-firstScript.sql b/db/versions/.archive/10239-redAsparagus/00-firstScript.sql new file mode 100644 index 000000000..45a7d1f9c --- /dev/null +++ b/db/versions/.archive/10239-redAsparagus/00-firstScript.sql @@ -0,0 +1,23 @@ + +ALTER TABLE edi.imapConfig + ADD environment varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER id, + ADD CONSTRAINT imapConfig_environment UNIQUE KEY (environment); + +UPDATE edi.imapConfig + SET environment='production' + WHERE id=1; + +UPDATE edi.param SET code='item' + WHERE id=2; +UPDATE edi.param SET code='k3' + WHERE id=21; +UPDATE edi.param SET code='k4' + WHERE id=22; +UPDATE edi.param SET code='deliveryNumber' + WHERE id=25; + +INSERT INTO edi.param (code,name,`position`,`type`,`required`) + VALUES ('cps','CPS',1,'STRING', FALSE); + +ALTER TABLE edi.ekt + ADD cps varchar(7) NULL COMMENT 'Código alfanumérico de Floriday'; diff --git a/db/versions/.archive/10239-redAsparagus/00-firstScript.undo.sql b/db/versions/.archive/10239-redAsparagus/00-firstScript.undo.sql new file mode 100644 index 000000000..0a6f89960 --- /dev/null +++ b/db/versions/.archive/10239-redAsparagus/00-firstScript.undo.sql @@ -0,0 +1,16 @@ + +DELETE FROM edi.imapConfig WHERE environment = 'test'; +ALTER TABLE edi.imapConfig DROP COLUMN environment; + +UPDATE edi.param SET code='art' + WHERE id=2; +UPDATE edi.param SET code='p1' + WHERE id=21; +UPDATE edi.param SET code='p2' + WHERE id=22; +UPDATE edi.param SET code='aaj' + WHERE id=25; + +DELETE FROM edi.param WHERE code = 'cps'; + +ALTER TABLE edi.ekt DROP COLUMN cps; diff --git a/db/versions/.archive/10241-whiteTulip/00-firstScript.sql b/db/versions/.archive/10241-whiteTulip/00-firstScript.sql new file mode 100644 index 000000000..19082f65c --- /dev/null +++ b/db/versions/.archive/10241-whiteTulip/00-firstScript.sql @@ -0,0 +1,161 @@ +USE vn; + +ALTER TABLE vn.worker + ADD COLUMN `fi` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, + ADD COLUMN `birth` date DEFAULT NULL, + ADD COLUMN `isDisable` tinyint(1) NOT NULL DEFAULT '0', + ADD COLUMN `isFreelance` tinyint(1) NOT NULL DEFAULT '0', + ADD COLUMN `isSsDiscounted` tinyint(1) NOT NULL DEFAULT '0', + ADD COLUMN `sex` enum('M','F') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'F' COMMENT 'M Masculino F Femenino'; + +UPDATE vn.worker w + JOIN vn.person p ON p.workerFk = w.id + SET w.fi = p.fi, + w.birth = p.birth, + w.isDisable = p.isDisable, + w.isFreelance = p.isFreelance, + w.isSsDiscounted = p.isSsDiscounted, + w.sex = p.sex; + +ALTER TABLE `vn`.`person` + RENAME TO `vn`.`person__` ; + +ALTER TABLE `vn`.`worker` + DROP FOREIGN KEY `Clientes`; + +ALTER TABLE `vn`.`worker` + DROP COLUMN `clientFk__`, + DROP COLUMN `birthed__`, + DROP COLUMN `address__`, + DROP COLUMN `fi__`, + DROP COLUMN `notes__`, + DROP COLUMN `ended__`, + DROP COLUMN `started__`, + DROP COLUMN `laborCategory__`, + DROP COLUMN `typeBussines__`, + DROP COLUMN `user__`, + DROP COLUMN `extension__`, + DROP COLUMN `email__`, + DROP COLUMN `password__`, + DROP INDEX `Id_Cliente_Interno` , + DROP INDEX `user` ; + + +ALTER TABLE `postgresql`.`bank_account` + DROP FOREIGN KEY `bank_account_client_id`; + +ALTER TABLE `postgresql`.`profile` + DROP FOREIGN KEY `profile_FK`; + +ALTER TABLE `postgresql`.`bank_account` + CHANGE COLUMN `client_id` `client_id__` INT(11) NULL DEFAULT NULL , + DROP INDEX `fki_bank_profile`; + +ALTER TABLE `postgresql`.`profile` + ADD COLUMN `workerFk` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `profile_type_id`; + +UPDATE postgresql.profile pr + JOIN vn.person__ p ON p.id = pr.person_id + SET pr.workerFk = p.workerFk; + +ALTER TABLE `postgresql`.`profile` + ADD INDEX `profile_workerFk_idx` (`workerFk` ASC); + +ALTER TABLE `postgresql`.`profile` + CHANGE COLUMN `person_id` `person_id__` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `postgresql`.`profile` + ADD CONSTRAINT `profile_workerFk` + FOREIGN KEY (`workerFk`) + REFERENCES `vn`.`worker` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +-- Hay que revisar 2 contratos con provider null +ALTER TABLE `postgresql`.`business` + ADD COLUMN `companyCodeFk` CHAR(3) COLLATE utf8mb3_unicode_ci DEFAULT NULL AFTER `provider_id`; + +UPDATE postgresql.business b + SET b.companyCodeFk ='VNH' + WHERE b.provider_id = 187; + +UPDATE postgresql.business b + SET b.companyCodeFk ='FTH' + WHERE b.provider_id = 194; + +UPDATE postgresql.business b + SET b.companyCodeFk ='EFL' + WHERE b.provider_id = 201; + +UPDATE postgresql.business b + SET b.companyCodeFk ='ORN' + WHERE b.provider_id = 305; + +UPDATE postgresql.business b + SET b.companyCodeFk ='ORN' + WHERE b.provider_id = 305; + +ALTER TABLE `postgresql`.`business` + DROP FOREIGN KEY `bussiness_provider`; + +ALTER TABLE `postgresql`.`business` + CHANGE COLUMN `provider_id` `provider_id__` INT(11) NULL DEFAULT NULL , + DROP INDEX `bussiness_provider` ; + + +ALTER TABLE `vn2008`.`payroll_employee` + ADD COLUMN `workerFk` INT(11) UNSIGNED NULL AFTER `ContratoTemporal`; + +ALTER TABLE `vn2008`.`payroll_employee` + ADD INDEX `payroll_employee_workerFk_idx` (`workerFk` ASC); + +UPDATE vn2008.payroll_employee pe + JOIN vn.person__ p ON p.id = pe.person_id + SET pe.workerFk = p.workerFk; + +ALTER TABLE `vn2008`.`payroll_employee` + ADD CONSTRAINT `payroll_employee_workerFk` + FOREIGN KEY (`workerFk`) + REFERENCES `vn`.`worker` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn2008`.`payroll_employee` + CHANGE COLUMN `Person_id` `Person_id__` INT(11) NOT NULL ; + +ALTER TABLE `postgresql`.`income_employee` + ADD COLUMN `workerFk` INT(11) UNSIGNED NULL AFTER `odbc_date`, + ADD INDEX `income_employee_workerFk_idx` (`workerFk` ASC) ; + +UPDATE postgresql.income_employee ie + JOIN vn.person__ p ON p.id = ie.person_id + SET ie.workerFk = p.workerFk; + +DELETE FROM postgresql.income_employee + WHERE workerFk IS NULL; -- 1 registro de 2005 a 0 + +ALTER TABLE `postgresql`.`income_employee` + CHANGE COLUMN `workerFk` `workerFk` INT(11) UNSIGNED NOT NULL ; + +ALTER TABLE `postgresql`.`income_employee` + ADD CONSTRAINT `income_employee_workerFk` + FOREIGN KEY (`workerFk`) + REFERENCES `vn`.`worker` (`id`) + ON UPDATE CASCADE; + +ALTER TABLE `postgresql`.`income_employee` + DROP FOREIGN KEY `income_employee_FK`; + +ALTER TABLE `postgresql`.`income_employee` + CHANGE COLUMN `person_id` `person_id__` INT(11) NULL DEFAULT NULL , + DROP INDEX `fperson_id` ; + +ALTER TABLE `vn`.`company` + ADD UNIQUE INDEX `companyCode_UNIQUE` (`code` ASC); + +ALTER TABLE `postgresql`.`business` + ADD CONSTRAINT `business_companyCodeFk` + FOREIGN KEY (companyCodeFk) + REFERENCES `vn`.`company` (`code`) + ON DELETE RESTRICT + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10242-grayChico/00-firstScript.sql b/db/versions/.archive/10242-grayChico/00-firstScript.sql new file mode 100644 index 000000000..ff9d31787 --- /dev/null +++ b/db/versions/.archive/10242-grayChico/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE edi.ekt ADD dp INT NULL COMMENT 'NAD+DP'; diff --git a/db/versions/.archive/10243-wheatErica/00-firstScript.sql b/db/versions/.archive/10243-wheatErica/00-firstScript.sql new file mode 100644 index 000000000..a1d5442d9 --- /dev/null +++ b/db/versions/.archive/10243-wheatErica/00-firstScript.sql @@ -0,0 +1,7 @@ +-- Cambios que me ha pedido Sergio que añada +INSERT INTO vn.silexACL +(id, module, `method`, `role`) +VALUES(139, 'delivery', 'get_expeditionsSummary', 'employee'); +INSERT INTO vn.silexACL +(id, module, `method`, `role`) +VALUES(140, 'almacennew', 'cmrExpeditionPallet_add', 'employee'); \ No newline at end of file diff --git a/db/versions/.archive/10245-yellowRaphis/00-firstScript.sql b/db/versions/.archive/10245-yellowRaphis/00-firstScript.sql new file mode 100644 index 000000000..8358d8f86 --- /dev/null +++ b/db/versions/.archive/10245-yellowRaphis/00-firstScript.sql @@ -0,0 +1,7 @@ +ALTER TABLE `vn`.`travel` ADD agencyModeFk INT DEFAULT NULL NULL; +ALTER TABLE `vn`.`travel` ADD CONSTRAINT travel_FK FOREIGN KEY (agencyModeFk) REFERENCES `vn`.`agencyMode`(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE `vn`.`travel` ADD CONSTRAINT shipment_1 UNIQUE KEY (shipped,landed,warehouseInFk,warehouseOutFk,agencyFk,agencyModeFk,`ref`); +ALTER TABLE `vn`.`travel` DROP KEY shipment_2; + +UPDATE `vn`.`travel` + SET agencyModeFk = agencyFk; \ No newline at end of file diff --git a/db/versions/.archive/10247-whiteAsparagus/00-firstScript.sql b/db/versions/.archive/10247-whiteAsparagus/00-firstScript.sql new file mode 100644 index 000000000..d8153074b --- /dev/null +++ b/db/versions/.archive/10247-whiteAsparagus/00-firstScript.sql @@ -0,0 +1,13 @@ +-- Place your SQL code here +USE vn; +DROP TABLE IF EXISTS vn.accountingConfig; +CREATE TABLE vn.accountingConfig ( + id INT primary key, + minDate DATE NOT NULL, + maxDate DATE NOT NULL +); + +ALTER TABLE `vn`.`accountingConfig` +CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT ; + +INSERT INTO `vn`.`accountingConfig` (`minDate`, `maxDate`) VALUES ('2021-12-01', '2023-01-01'); diff --git a/db/versions/.archive/10248-azureCordyline/00-firstScript.sql b/db/versions/.archive/10248-azureCordyline/00-firstScript.sql new file mode 100644 index 000000000..f7e15c089 --- /dev/null +++ b/db/versions/.archive/10248-azureCordyline/00-firstScript.sql @@ -0,0 +1,30 @@ +USE `vn`; +DROP VIEW IF EXISTS vn.comparativeFilter; + +CREATE TABLE IF NOT EXISTS vn.`comparativeFilter` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `userFk` int(10) unsigned NOT NULL, + `name` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, + `buyer` int(11) DEFAULT NULL, + `itemFilter` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `isFloramondo` tinyint(4) DEFAULT NULL, + `warehouseFk` smallint(6) unsigned DEFAULT NULL, + `tintaFk` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `hasType` tinyint(1) DEFAULT 0, + `producerFilter` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `supplierFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `comparativeFilter_FK` (`userFk`), + KEY `comparativeFilter_FK_1` (`warehouseFk`), + KEY `comparativeFilter_FK_2` (`supplierFk`), + CONSTRAINT `comparativeFilter_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`), + CONSTRAINT `comparativeFilter_FK_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`), + CONSTRAINT `comparativeFilter_FK_2` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +CREATE TABLE IF NOT EXISTS vn.`comparativeFilterType` ( + `comparativeFilterFk` int(11) NOT NULL, + `itemTypeFk` int(11) NOT NULL, + PRIMARY KEY (`comparativeFilterFk`,`itemTypeFk`), + CONSTRAINT `comparativeFilterType_FK` FOREIGN KEY (`comparativeFilterFk`) REFERENCES `comparativeFilter` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/.archive/10250-wheatBamboo/00-firstScript.sql b/db/versions/.archive/10250-wheatBamboo/00-firstScript.sql new file mode 100644 index 000000000..6a83cb5d1 --- /dev/null +++ b/db/versions/.archive/10250-wheatBamboo/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +/* +INSERT INTO vn.silexACL +(id, module, `method`, `role`) +VALUES(141, 'almacennew', 'item_saveStems', 'employee'); +*/ diff --git a/db/versions/.archive/10253-whiteAnthurium/00-firstScript.sql b/db/versions/.archive/10253-whiteAnthurium/00-firstScript.sql new file mode 100644 index 000000000..5a49ad4e0 --- /dev/null +++ b/db/versions/.archive/10253-whiteAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE edi.ekt ADD sender INT NULL COMMENT 'NAD+SE'; diff --git a/db/versions/.archive/10254-whiteOak/00-firstScript.sql b/db/versions/.archive/10254-whiteOak/00-firstScript.sql new file mode 100644 index 000000000..9d277778d --- /dev/null +++ b/db/versions/.archive/10254-whiteOak/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn.ektEntryAssign ADD COLUMN auction INT NULL AFTER pro; + +ALTER TABLE vn.entry ADD COLUMN auction INT NULL AFTER pro; diff --git a/db/versions/.archive/10256-orangeFern/00-firstScript.sql b/db/versions/.archive/10256-orangeFern/00-firstScript.sql new file mode 100644 index 000000000..84b2ae4b3 --- /dev/null +++ b/db/versions/.archive/10256-orangeFern/00-firstScript.sql @@ -0,0 +1,16 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`ticketRecalc` +DROP FOREIGN KEY `ticketRecalc_ibfk_1`; + +ALTER TABLE `vn`.`ticketRecalc` +ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, +DROP PRIMARY KEY, +ADD PRIMARY KEY (`id`); + + +ALTER TABLE `vn`.`ticketRecalc` +ADD CONSTRAINT `ticketRecalc_ibfk_1` + FOREIGN KEY (`ticketFk`) + REFERENCES `vn`.`ticket` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10258-azureOak/00-firstScript.sql b/db/versions/.archive/10258-azureOak/00-firstScript.sql new file mode 100644 index 000000000..cc54269fb --- /dev/null +++ b/db/versions/.archive/10258-azureOak/00-firstScript.sql @@ -0,0 +1,21 @@ +-- Place your SQL code here +USE vn; + +ALTER TABLE vn.vehicleEvent DROP FOREIGN KEY vehicleEvent_FK; +ALTER TABLE vn.vehicleState MODIFY COLUMN id int(11) NOT NULL; +ALTER TABLE vn.vehicleState DROP PRIMARY KEY; +ALTER TABLE vn.vehicleState ADD CONSTRAINT vehicleState_PK PRIMARY KEY (id); +ALTER TABLE vn.vehicleState MODIFY COLUMN id int(11) auto_increment NOT NULL; +ALTER TABLE vn.vehicleState ADD hasToNotify INT DEFAULT NULL NULL; +ALTER TABLE vn.vehicleEvent ADD CONSTRAINT vehicleEvent_FK FOREIGN KEY (vehicleStateFk) REFERENCES vn.vehicleState(id); + +ALTER TABLE vn.vehicleEvent ADD notified DATETIME NULL; + +CREATE OR REPLACE TABLE vn.vehicleConfig ( + eventEarlyDays int NULL +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.vehicleConfig MODIFY COLUMN eventEarlyDays int(11) DEFAULT 15 COMMENT 'Previous days on which the expiration of an event must be notified'; diff --git a/db/versions/.archive/10259-limeMonstera/00-firstScript.sql b/db/versions/.archive/10259-limeMonstera/00-firstScript.sql new file mode 100644 index 000000000..420b382d6 --- /dev/null +++ b/db/versions/.archive/10259-limeMonstera/00-firstScript.sql @@ -0,0 +1,15 @@ +-- Place your SQL code here +ALTER TABLE `hedera`.`orderRecalc` +DROP FOREIGN KEY `orderRecalc_ibfk_1`; + +ALTER TABLE `hedera`.`orderRecalc` +ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, +DROP PRIMARY KEY, +ADD PRIMARY KEY (`id`); + +ALTER TABLE `hedera`.`orderRecalc` +ADD CONSTRAINT `orderRecalc_ibfk_1` + FOREIGN KEY (`orderFk`) + REFERENCES `hedera`.`order` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10261-maroonArborvitae/00-firstScript.sql b/db/versions/.archive/10261-maroonArborvitae/00-firstScript.sql new file mode 100644 index 000000000..8313415b9 --- /dev/null +++ b/db/versions/.archive/10261-maroonArborvitae/00-firstScript.sql @@ -0,0 +1,10 @@ +CREATE TABLE srt.photocell ( + bufferFk INT NOT NULL, + `position` INT NOT NULL COMMENT 'Posición relativa al celluveyor de dentro a fuera, siendo 1 la más cercana a este', + isActive BOOL NULL, + CONSTRAINT photocell_PK PRIMARY KEY (bufferFk,`position`), + CONSTRAINT photocell_FK FOREIGN KEY (bufferFk) REFERENCES srt.buffer(id) ON DELETE CASCADE ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/.archive/10262-salmonTulip/00-createTablepackagingWithFreight.sql b/db/versions/.archive/10262-salmonTulip/00-createTablepackagingWithFreight.sql new file mode 100644 index 000000000..48d620be6 --- /dev/null +++ b/db/versions/.archive/10262-salmonTulip/00-createTablepackagingWithFreight.sql @@ -0,0 +1,9 @@ +DROP TABLE IF EXISTS vn.packagingWithFreight; + +CREATE TABLE vn.`packagingWithFreight` ( + `packagingFk` varchar(10) COLLATE utf8mb3_unicode_ci NOT NULL, + `priority` int(11) NOT NULL, + PRIMARY KEY (`packagingFk`), + UNIQUE KEY `packagingWithFreight_UN` (`priority`), + CONSTRAINT `packagingWithFreight_FK` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Embalajes con porte para encajado'; \ No newline at end of file diff --git a/db/versions/.archive/10262-salmonTulip/01-alterTablePackagingConfig.sql b/db/versions/.archive/10262-salmonTulip/01-alterTablePackagingConfig.sql new file mode 100644 index 000000000..2a427bac0 --- /dev/null +++ b/db/versions/.archive/10262-salmonTulip/01-alterTablePackagingConfig.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.packagingConfig ADD palletPackaging varchar(10) default 'pallet USA' NULL; +ALTER TABLE vn.packagingConfig ADD carryPackaging varchar(10) DEFAULT 'cc' NULL; +ALTER TABLE vn.packagingConfig ADD freightItemPackaging INT(11) DEFAULT 71 NULL; diff --git a/db/versions/.archive/10262-salmonTulip/02-insertsInicials.sql b/db/versions/.archive/10262-salmonTulip/02-insertsInicials.sql new file mode 100644 index 000000000..dcb6449fe --- /dev/null +++ b/db/versions/.archive/10262-salmonTulip/02-insertsInicials.sql @@ -0,0 +1,21 @@ +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('94', 1); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('94m', 2); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('94p', 3); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('cc', 4); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('pallet usa', 5); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('cactus200', 6); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('kalan400', 7); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('crisantemo', 8); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('madre430', 9); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('guzma650', 10); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('madre700', 11); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('madre800', 12); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('madre900', 13); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('guzma1200', 14); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('guzma1400', 15); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('dm120', 16); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('HC', 17); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('dm040', 18); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('qb033', 19); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('hb076', 20); +INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('hb104', 21); diff --git a/db/versions/.archive/10262-salmonTulip/03-createTablepackingWithoutFreight.sql b/db/versions/.archive/10262-salmonTulip/03-createTablepackingWithoutFreight.sql new file mode 100644 index 000000000..b029ba652 --- /dev/null +++ b/db/versions/.archive/10262-salmonTulip/03-createTablepackingWithoutFreight.sql @@ -0,0 +1,9 @@ +DROP TABLE IF EXISTS vn.packagingWithoutFreight; + +CREATE TABLE vn.`packagingWithoutFreight` ( + `packagingFk` varchar(10) COLLATE utf8mb3_unicode_ci NOT NULL, + `priority` int(11) NOT NULL, + PRIMARY KEY (`packagingFk`), + UNIQUE KEY `packagingWithoutFreight_UN` (`priority`), + CONSTRAINT `packagingWithoutFreight_FK` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Embalajes sin porte para encajar'; diff --git a/db/versions/.archive/10263-tealPaniculata/00-firstScript.sql b/db/versions/.archive/10263-tealPaniculata/00-firstScript.sql new file mode 100644 index 000000000..371c2c358 --- /dev/null +++ b/db/versions/.archive/10263-tealPaniculata/00-firstScript.sql @@ -0,0 +1 @@ +-- Place your SQL code here diff --git a/db/versions/.archive/10265-greenAspidistra/00-firstScript.sql b/db/versions/.archive/10265-greenAspidistra/00-firstScript.sql new file mode 100644 index 000000000..aa0c97049 --- /dev/null +++ b/db/versions/.archive/10265-greenAspidistra/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`printServerQueue` +RENAME TO `vn`.`printServerQueue__` ; + +ALTER TABLE `vn`.`printServerQueue2` +RENAME TO `vn`.`printServerQueue2__` ; + +ALTER TABLE `vn2008`.`printServerQueue2` +RENAME TO `vn2008`.`printServerQueue2__` ; diff --git a/db/versions/.archive/10267-blueDracena/00-firstScript.sql b/db/versions/.archive/10267-blueDracena/00-firstScript.sql new file mode 100644 index 000000000..3d95af886 --- /dev/null +++ b/db/versions/.archive/10267-blueDracena/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn.worker ADD businessFk int(11) DEFAULT NULL NULL; +ALTER TABLE vn.worker ADD CONSTRAINT worker_business FOREIGN KEY (businessFk) REFERENCES postgresql.business(business_id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.worker ADD CONSTRAINT worker_business UNIQUE KEY (businessFk); \ No newline at end of file diff --git a/db/versions/.archive/10267-blueDracena/01-fixMerge.sql b/db/versions/.archive/10267-blueDracena/01-fixMerge.sql new file mode 100644 index 000000000..88d7c68ed --- /dev/null +++ b/db/versions/.archive/10267-blueDracena/01-fixMerge.sql @@ -0,0 +1,12 @@ +use vn; +DROP TEMPORARY TABLE IF EXISTS tWorkerLabour ; +CREATE TEMPORARY TABLE tWorkerLabour +SELECT l.workerFk, l.businessFk +FROM vn.workerLabour l +WHERE util.CURDATE() BETWEEN l.started AND IFNULL(l.ended, util.CURDATE()); + +UPDATE vn.worker w + JOIN tWorkerLabour l ON l.workerFk = w.id + SET w.businessFk = l.businessFk; + +DROP TEMPORARY TABLE tWorkerLabour; \ No newline at end of file diff --git a/db/versions/.archive/10275-maroonCataractarum/00-improvedGeneralLog.sql b/db/versions/.archive/10275-maroonCataractarum/00-improvedGeneralLog.sql new file mode 100644 index 000000000..4f64f9d59 --- /dev/null +++ b/db/versions/.archive/10275-maroonCataractarum/00-improvedGeneralLog.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS `vn`.`improvedGeneralLog` ( + user char(128) DEFAULT NULL, + db char(64) DEFAULT NULL, + tables char(64) DEFAULT NULL, + type set('Select','Insert','Update','Delete'), + PRIMARY KEY(user, db, tables) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS `vn`.`improvedGeneralLogProcedures` ( + user char(128) DEFAULT NULL, + db varchar(250) DEFAULT NULL, + routine char(64) DEFAULT NULL, + type enum('FUNCTION','PROCEDURE') NOT NULL, + PRIMARY KEY(user, db, routine, type) +) ENGINE=InnoDB; diff --git a/db/versions/.archive/10277-azurePalmetto/00-firstScript.sql b/db/versions/.archive/10277-azurePalmetto/00-firstScript.sql new file mode 100644 index 000000000..5823e2388 --- /dev/null +++ b/db/versions/.archive/10277-azurePalmetto/00-firstScript.sql @@ -0,0 +1,12 @@ +-- Place your SQL code here +USE vn; +CREATE OR REPLACE TABLE `operator` ( + `workerFk` int(10) unsigned NOT NULL, + `numberOfWagons` int(11) DEFAULT 1, + PRIMARY KEY (`workerFk`), + KEY `operator_FK` (`workerFk`), + CONSTRAINT `operator_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT INTO vn.operator (workerFk, numberOfWagons) +SELECT id, 2 FROM vn.worker WHERE sectorFk is not null; diff --git a/db/versions/.archive/10278-silverRose/00-firstScript.sql b/db/versions/.archive/10278-silverRose/00-firstScript.sql new file mode 100644 index 000000000..ba2ab4509 --- /dev/null +++ b/db/versions/.archive/10278-silverRose/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.mdbVersion ADD CONSTRAINT mdbVersion_PK PRIMARY KEY (app,branchFk); \ No newline at end of file diff --git a/db/versions/.archive/10279-purpleAsparagus/00-firstScript.sql b/db/versions/.archive/10279-purpleAsparagus/00-firstScript.sql new file mode 100644 index 000000000..4dae32ddd --- /dev/null +++ b/db/versions/.archive/10279-purpleAsparagus/00-firstScript.sql @@ -0,0 +1,7 @@ +INSERT INTO `vn`.`businessType` (`code`,`description`) + VALUES + ('individual','Particular'), + ('otherSector', 'Profesional de otro sector'); + +INSERT INTO `vn`.`component` (`name`,`typeFk`,`classRate`,`isRenewable`,`code`,`isRequired`, `tax`) + VALUES ('recargo a particular',2,NULL,0,'individual',0, 0.25); \ No newline at end of file diff --git a/db/versions/.archive/10281-navyPalmetto/00-firstScript.sql b/db/versions/.archive/10281-navyPalmetto/00-firstScript.sql new file mode 100644 index 000000000..6438c46ab --- /dev/null +++ b/db/versions/.archive/10281-navyPalmetto/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.supplier MODIFY COLUMN isActive tinyint(4) DEFAULT 1 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10282-brownAsparagus/00-firstScript.sql b/db/versions/.archive/10282-brownAsparagus/00-firstScript.sql new file mode 100644 index 000000000..54b82cd89 --- /dev/null +++ b/db/versions/.archive/10282-brownAsparagus/00-firstScript.sql @@ -0,0 +1,10 @@ +TRUNCATE vn.itemCleanCount; +ALTER TABLE vn.itemCleanConfig DROP COLUMN step; +RENAME TABLE vn.itemCleanCount TO vn.itemCleanLog; +ALTER TABLE vn.itemCleanConfig MODIFY COLUMN isStop tinyint(1) DEFAULT NULL NULL COMMENT 'Si está a TRUE para el proceso a tiempo real'; +INSERT INTO bs.nightTask (`order`,`schema`,`procedure`) + VALUES (1009,'vn','item_clean'); +UPDATE vn.itemCleanConfig + SET quantity=50000 + WHERE id=1; + \ No newline at end of file diff --git a/db/versions/.archive/10283-rm4375pak/00-alterTable.sql b/db/versions/.archive/10283-rm4375pak/00-alterTable.sql new file mode 100644 index 000000000..7db2bacea --- /dev/null +++ b/db/versions/.archive/10283-rm4375pak/00-alterTable.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE srt.config ADD IF NOT EXISTS isAllowedUnloading bool DEFAULT 1 NOT NULL +COMMENT 'Permite que se pueda cambiar el mode de los buffers a UNLOADING'; diff --git a/db/versions/.archive/10284-aquaErica/00-firstScript.sql b/db/versions/.archive/10284-aquaErica/00-firstScript.sql new file mode 100644 index 000000000..8a287eead --- /dev/null +++ b/db/versions/.archive/10284-aquaErica/00-firstScript.sql @@ -0,0 +1,11 @@ +-- Dejo el update para que quede relacionado con el cambio +USE vn; + +UPDATE vn.XDiario x + JOIN (SELECT DISTINCT Asiento + FROM sage.movConta + WHERE enlazadoSage + AND CodigoEmpresa = 2) sub ON sub.Asiento = x.ASIEN + SET x.enlazadoSage = FALSE + WHERE x.enlazadoSage = TRUE + AND x.updated >= util.CURDATE(); diff --git a/db/versions/.archive/10285-aquaHydrangea/00-firstScript.sql b/db/versions/.archive/10285-aquaHydrangea/00-firstScript.sql new file mode 100644 index 000000000..4c4a3454a --- /dev/null +++ b/db/versions/.archive/10285-aquaHydrangea/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +DROP FUNCTION IF EXISTS `vn`.`company_getCode`; \ No newline at end of file diff --git a/db/versions/.archive/10287-turquoiseRose/00-firstScript.sql b/db/versions/.archive/10287-turquoiseRose/00-firstScript.sql new file mode 100644 index 000000000..ea0142836 --- /dev/null +++ b/db/versions/.archive/10287-turquoiseRose/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE edi.ekt MODIFY COLUMN ptj BIGINT UNSIGNED DEFAULT NULL NULL COMMENT 'NAD+BY'; +ALTER TABLE edi.ekt MODIFY COLUMN dp BIGINT UNSIGNED DEFAULT NULL NULL COMMENT 'NAD+DP'; +ALTER TABLE edi.ekt MODIFY COLUMN sender BIGINT UNSIGNED DEFAULT NULL NULL COMMENT 'NAD+SE'; diff --git a/db/versions/.archive/10288-chocolateSalal/00-firstScript.sql b/db/versions/.archive/10288-chocolateSalal/00-firstScript.sql new file mode 100644 index 000000000..ff2e2fb11 --- /dev/null +++ b/db/versions/.archive/10288-chocolateSalal/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE edi.ektConfig ADD ektRecentScopeDays INT DEFAULT 7 NOT NULL; diff --git a/db/versions/.archive/10289-turquoiseCarnation/00-firstScript.sql b/db/versions/.archive/10289-turquoiseCarnation/00-firstScript.sql new file mode 100644 index 000000000..96812f96c --- /dev/null +++ b/db/versions/.archive/10289-turquoiseCarnation/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`packaging` +CHANGE COLUMN `base` `base` DECIMAL(10,2) NOT NULL DEFAULT 0 , +CHANGE COLUMN `price` `price` DECIMAL(10,2) NOT NULL DEFAULT 0 ; diff --git a/db/versions/.archive/10291-azureGalax/00-firstScript.sql b/db/versions/.archive/10291-azureGalax/00-firstScript.sql new file mode 100644 index 000000000..8d0dfd5c3 --- /dev/null +++ b/db/versions/.archive/10291-azureGalax/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`item` MODIFY COLUMN description varchar(1000) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; diff --git a/db/versions/.archive/10293-salmonCamellia/00-firstScript.sql b/db/versions/.archive/10293-salmonCamellia/00-firstScript.sql new file mode 100644 index 000000000..8ef4fa5ea --- /dev/null +++ b/db/versions/.archive/10293-salmonCamellia/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here + +INSERT INTO vn.silexACL +( module, `method`, `role`) +VALUES('almacennew', 'operator_getNumberOfWagons', 'employee'); + +INSERT INTO vn.silexACL +( module, `method`, `role`) +VALUES('almacennew', 'operator_add', 'employee'); \ No newline at end of file diff --git a/db/versions/.archive/10297-redErica/00-firstScript.sql b/db/versions/.archive/10297-redErica/00-firstScript.sql new file mode 100644 index 000000000..c8021ec8b --- /dev/null +++ b/db/versions/.archive/10297-redErica/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE edi.ekt MODIFY COLUMN barcode char(25) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Generated auction barcode'; +ALTER TABLE edi.ekt DROP KEY barcode_year; \ No newline at end of file diff --git a/db/versions/.archive/10298-grayBamboo/00-firstScript.sql b/db/versions/.archive/10298-grayBamboo/00-firstScript.sql new file mode 100644 index 000000000..6d4b5c215 --- /dev/null +++ b/db/versions/.archive/10298-grayBamboo/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.printQueueArgs ADD CONSTRAINT printQueueArgs_PK PRIMARY KEY (printQueueFk,name); diff --git a/db/versions/.archive/10299-blueTulip/00-firstScript.sql b/db/versions/.archive/10299-blueTulip/00-firstScript.sql new file mode 100644 index 000000000..0c52e4b45 --- /dev/null +++ b/db/versions/.archive/10299-blueTulip/00-firstScript.sql @@ -0,0 +1,10 @@ + +ALTER TABLE hedera.orderRecalc DROP FOREIGN KEY orderRecalc_ibfk_1; +ALTER TABLE vn.ticketRecalc DROP FOREIGN KEY ticketRecalc_ibfk_1; + +CREATE TABLE `util`.`binlogQueue`( + `code` VARCHAR(255) NOT NULL, + `logName` VARCHAR(255) NOT NULL, + `position` BIGINT UNSIGNED NOT NULL, + PRIMARY KEY (`code`) +) ENGINE = InnoDB COMMENT='Binary log position of asynchronous queues'; diff --git a/db/versions/.archive/10299-blueTulip/00-firstScript.undo.sql b/db/versions/.archive/10299-blueTulip/00-firstScript.undo.sql new file mode 100644 index 000000000..f0dbb8ba6 --- /dev/null +++ b/db/versions/.archive/10299-blueTulip/00-firstScript.undo.sql @@ -0,0 +1,7 @@ + +ALTER TABLE hedera.orderRecalc + ADD CONSTRAINT orderRecalc_ibfk_1 FOREIGN KEY (orderFk) REFERENCES hedera.`order`(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.ticketRecalc + ADD CONSTRAINT ticketRecalc_ibfk_1 FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id) ON DELETE CASCADE ON UPDATE CASCADE; + +DROP TABLE IF EXISTS `util`.`binlogQueue`; diff --git a/db/versions/.archive/10301-4415collectionNewPAK/00-productionConfig.sql b/db/versions/.archive/10301-4415collectionNewPAK/00-productionConfig.sql new file mode 100644 index 000000000..ec8bb84a0 --- /dev/null +++ b/db/versions/.archive/10301-4415collectionNewPAK/00-productionConfig.sql @@ -0,0 +1,7 @@ +-- Place your SQL code here +ALTER TABLE vn.productionConfig + ADD IF NOT EXISTS hasUniqueCollectionTime bool DEFAULT FALSE NOT NULL + COMMENT 'Determina si los tickets de una colección deben de tener la misma hora y minuto'; + +ALTER TABLE vn.productionConfig ADD maxCollectionWithoutUser INT DEFAULT 1 NOT NULL +COMMENT 'Número máximo de colecciones que pueden estar sin usuario, haciendo de caché....'; diff --git a/db/versions/.archive/10301-4415collectionNewPAK/01-drop.sql b/db/versions/.archive/10301-4415collectionNewPAK/01-drop.sql new file mode 100644 index 000000000..c949f8dd0 --- /dev/null +++ b/db/versions/.archive/10301-4415collectionNewPAK/01-drop.sql @@ -0,0 +1,2 @@ +DROP PROCEDURE IF EXISTS vn.collection_get_; +DROP PROCEDURE IF EXISTS vn.collection_newWithWagon_beta; \ No newline at end of file diff --git a/db/versions/.archive/10301-4415collectionNewPAK/02-collection.sql b/db/versions/.archive/10301-4415collectionNewPAK/02-collection.sql new file mode 100644 index 000000000..eb3f598bb --- /dev/null +++ b/db/versions/.archive/10301-4415collectionNewPAK/02-collection.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.collection ADD IF NOT EXISTS sectorFk INT NULL; +ALTER TABLE vn.collection ADD IF NOT EXISTS wagons INT NULL; + +ALTER TABLE vn.collection + ADD CONSTRAINT collectionSector_FK + FOREIGN KEY (sectorFk) + REFERENCES vn.sector(id) + ON DELETE SET NULL + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10302-chocolateRoebelini/00-CreateTableEntryType.sql b/db/versions/.archive/10302-chocolateRoebelini/00-CreateTableEntryType.sql new file mode 100644 index 000000000..a3c5f7ca8 --- /dev/null +++ b/db/versions/.archive/10302-chocolateRoebelini/00-CreateTableEntryType.sql @@ -0,0 +1,6 @@ +CREATE TABLE vn.entryType ( + `code` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, + `description` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + diff --git a/db/versions/.archive/10302-chocolateRoebelini/01-insertDataEntryType.sql b/db/versions/.archive/10302-chocolateRoebelini/01-insertDataEntryType.sql new file mode 100644 index 000000000..abe1fc66b --- /dev/null +++ b/db/versions/.archive/10302-chocolateRoebelini/01-insertDataEntryType.sql @@ -0,0 +1,4 @@ +INSERT INTO vn.entryType (code, `description`) VALUES('product', 'Producto'); +INSERT INTO vn.entryType (code, `description`) VALUES('packaging', 'Embalaje'); +INSERT INTO vn.entryType (code, `description`) VALUES('payment', 'Abono'); +INSERT INTO vn.entryType (code, `description`) VALUES('regularization', 'Regularización'); diff --git a/db/versions/.archive/10302-chocolateRoebelini/02-alterTableEntry.sql b/db/versions/.archive/10302-chocolateRoebelini/02-alterTableEntry.sql new file mode 100644 index 000000000..b51123775 --- /dev/null +++ b/db/versions/.archive/10302-chocolateRoebelini/02-alterTableEntry.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.entry ADD typeFk varchar(100) DEFAULT 'product' NULL COMMENT 'Tipo de entrada, por defecto PRODUCTO'; +ALTER TABLE vn.entry ADD CONSTRAINT entry_FK_1 FOREIGN KEY (typeFk) REFERENCES vn.entryType(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/.archive/10303-tealRoebelini/00-firstScript.sql b/db/versions/.archive/10303-tealRoebelini/00-firstScript.sql new file mode 100644 index 000000000..3ff1b4b75 --- /dev/null +++ b/db/versions/.archive/10303-tealRoebelini/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn2008.Reservas ADD buyFk INT(11) NOT NULL; +ALTER TABLE vn2008.Reservas ADD `grouping` INT(11) NULL; +ALTER TABLE vn2008.Reservas ADD packing INT(11) NULL; diff --git a/db/versions/.archive/10304-limeAsparagus/00-firstScript.sql b/db/versions/.archive/10304-limeAsparagus/00-firstScript.sql new file mode 100644 index 000000000..42a41402e --- /dev/null +++ b/db/versions/.archive/10304-limeAsparagus/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticket CHANGE isLabeled isLabeled__ tinyint(1) DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10304-limeAsparagus/01-altertableticket.sql b/db/versions/.archive/10304-limeAsparagus/01-altertableticket.sql new file mode 100644 index 000000000..8a8f9aea8 --- /dev/null +++ b/db/versions/.archive/10304-limeAsparagus/01-altertableticket.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticket CHANGE isLabeled__ isLabeled tinyint(1) DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10305-brownFern/00-ektAssign.sql b/db/versions/.archive/10305-brownFern/00-ektAssign.sql new file mode 100644 index 000000000..82bc795d8 --- /dev/null +++ b/db/versions/.archive/10305-brownFern/00-ektAssign.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ektEntryAssign ADD companyFk SMALLINT unsigned DEFAULT 442 NOT NULL; diff --git a/db/versions/.archive/10306-turquoiseCyca/00-deliveryInformation.sql b/db/versions/.archive/10306-turquoiseCyca/00-deliveryInformation.sql new file mode 100644 index 000000000..aa88dc103 --- /dev/null +++ b/db/versions/.archive/10306-turquoiseCyca/00-deliveryInformation.sql @@ -0,0 +1,3 @@ +ALTER TABLE edi.deliveryInformation DROP KEY deliveryInformation_UN; +ALTER TABLE edi.deliveryInformation ADD CONSTRAINT deliveryInformation_UN + UNIQUE KEY (Location, LatestDeliveryDateTime, FirstOrderDateTime, LatestOrderDateTime, supplyResponseID, DeliveryType); diff --git a/db/versions/.archive/10307-tealFern/00-firstScript.sql b/db/versions/.archive/10307-tealFern/00-firstScript.sql new file mode 100644 index 000000000..8f31d43f8 --- /dev/null +++ b/db/versions/.archive/10307-tealFern/00-firstScript.sql @@ -0,0 +1,10 @@ +ALTER TABLE vn.awb ADD propertyNumber INT(11) NULL; + +ALTER TABLE vn2008.awb_component_template ADD CONSTRAINT awb_component_template_FK FOREIGN KEY (awb_component_type_id) +REFERENCES vn2008.awb_component_type(awb_component_type_id) ON DELETE RESTRICT ON UPDATE CASCADE; + +ALTER TABLE vn2008.awb_component_template ADD CONSTRAINT awb_component_template_FK_1 FOREIGN KEY (airline_id) +REFERENCES vn2008.airline(airline_id) ON DELETE RESTRICT ON UPDATE CASCADE; + +INSERT INTO vn2008.awb_unit (awb_unit_id,operation) + VALUES ('PN','LEAST(90, value + propertyNumber *10)'); \ No newline at end of file diff --git a/db/versions/.archive/10308-grayAsparagus/00-firstScript.sql b/db/versions/.archive/10308-grayAsparagus/00-firstScript.sql new file mode 100644 index 000000000..c7a2eeee9 --- /dev/null +++ b/db/versions/.archive/10308-grayAsparagus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.greuge ADD userFK int(10) unsigned DEFAULT NULL NULL; +ALTER TABLE vn.greuge ADD CONSTRAINT greuge_FK FOREIGN KEY (userFK) REFERENCES account.`user`(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/.archive/10309-navyCordyline/00-firstScript.sql b/db/versions/.archive/10309-navyCordyline/00-firstScript.sql new file mode 100644 index 000000000..81ba5d4ba --- /dev/null +++ b/db/versions/.archive/10309-navyCordyline/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +USE vn; +ALTER TABLE vn.worker DROP FOREIGN KEY worker_business; +ALTER TABLE vn.worker ADD CONSTRAINT worker_business FOREIGN KEY (businessFk) +REFERENCES postgresql.business(business_id) ON DELETE SET NULL ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10310-azureCymbidium/00-firstScript.sql b/db/versions/.archive/10310-azureCymbidium/00-firstScript.sql new file mode 100644 index 000000000..60489518c --- /dev/null +++ b/db/versions/.archive/10310-azureCymbidium/00-firstScript.sql @@ -0,0 +1,10 @@ +-- UPDATE asociado a la tarea +USE vn; +UPDATE vn.worker w + JOIN(SELECT r.workerFk + FROM route r + LEFT JOIN workerLabour wl ON wl.workerFk = r.workerFk + WHERE wl.workerFk IS NULL + AND r.workerFk IS NOT NULL + GROUP BY r.workerFk) sub ON sub.workerFk = w.id + SET w.isFreelance = TRUE; \ No newline at end of file diff --git a/db/versions/.archive/10311-navyChico/00-firstScript.sql b/db/versions/.archive/10311-navyChico/00-firstScript.sql new file mode 100644 index 000000000..bdfb80334 --- /dev/null +++ b/db/versions/.archive/10311-navyChico/00-firstScript.sql @@ -0,0 +1,3 @@ +USE postgresql; +ALTER TABLE `postgresql`.`business` + CHANGE COLUMN `payedHolidays` `payedHolidays` DECIMAL(5,2) NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/db/versions/.archive/10312-pinkCymbidium/00-firstScript.sql b/db/versions/.archive/10312-pinkCymbidium/00-firstScript.sql new file mode 100644 index 000000000..3776dd971 --- /dev/null +++ b/db/versions/.archive/10312-pinkCymbidium/00-firstScript.sql @@ -0,0 +1 @@ +DROP TABLE bs.zone_ETD_byTime; diff --git a/db/versions/.archive/10313-chocolateMastic/00-firstScript.sql b/db/versions/.archive/10313-chocolateMastic/00-firstScript.sql new file mode 100644 index 000000000..39a7d0a0c --- /dev/null +++ b/db/versions/.archive/10313-chocolateMastic/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.expedition CHANGE itemFk__ itemFk int(11) NULL COMMENT 'Si es necesario el itemFk del cubo, se obtiene mediante packagingFk, join packing.itemFk'; \ No newline at end of file diff --git a/db/versions/.archive/10314-goldenGerbera/00-firstScript.sql b/db/versions/.archive/10314-goldenGerbera/00-firstScript.sql new file mode 100644 index 000000000..933d2e7cd --- /dev/null +++ b/db/versions/.archive/10314-goldenGerbera/00-firstScript.sql @@ -0,0 +1 @@ +USE vn; diff --git a/db/versions/.archive/10315-purpleDracena/00-firstScript.sql b/db/versions/.archive/10315-purpleDracena/00-firstScript.sql new file mode 100644 index 000000000..f63790aa5 --- /dev/null +++ b/db/versions/.archive/10315-purpleDracena/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +ALTER TABLE `postgresql`.`bank_account` +RENAME TO `postgresql`.`bank_account__` ; + +ALTER TABLE `vn`.`client` +DROP COLUMN `cc__`; diff --git a/db/versions/.archive/10317-crimsonRuscus/00-firstScript.sql b/db/versions/.archive/10317-crimsonRuscus/00-firstScript.sql new file mode 100644 index 000000000..94a5811e3 --- /dev/null +++ b/db/versions/.archive/10317-crimsonRuscus/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here + +USE vn; +ALTER TABLE vn.productionConfig ADD pendingCollectionsOrder tinyint(3) unsigned DEFAULT 8 NULL; +ALTER TABLE vn.productionConfig ADD pendingCollectionsAge TINYINT unsigned DEFAULT 6 NULL; + + + diff --git a/db/versions/.archive/10318-greenPaniculata/00-firstScript.sql b/db/versions/.archive/10318-greenPaniculata/00-firstScript.sql new file mode 100644 index 000000000..c61bb9851 --- /dev/null +++ b/db/versions/.archive/10318-greenPaniculata/00-firstScript.sql @@ -0,0 +1,25 @@ +-- Place your SQL code here +RENAME TABLE `vn`.`returnBuckets` TO `vn`.`returnBuckets__`; + +ALTER TABLE `vn2008`.`Cubos_Retorno` RENAME `vn`.`returnBuckets`; + + +ALTER TABLE `vn`.`returnBuckets` +CHANGE COLUMN `idCubos_Retorno` `id` int(11) NOT NULL AUTO_INCREMENT, +CHANGE COLUMN `Soporte` `freightContainerType` varchar(15) COLLATE utf8mb3_unicode_ci NOT NULL, +CHANGE COLUMN `Vacio` `freightPackagingEmpty` DOUBLE NOT NULL DEFAULT 0, +CHANGE COLUMN `Lleno` `freightPackagingFull` DOUBLE NOT NULL DEFAULT 0; + + +CREATE + ALGORITHM = UNDEFINED + DEFINER = `root`@`localhost` + SQL SECURITY DEFINER +VIEW `vn2008`.`Cubos_Retorno` AS + SELECT + `rb`.`id` AS `idCubos_Retorno`, + `rb`.`freightContainerType` AS `Soporte`, + `rb`.`freightPackagingEmpty` AS `Vacio`, + `rb`.`freightPackagingFull` AS `Lleno` + FROM + `vn`.`returnBuckets` `rb`; diff --git a/db/versions/.archive/10319-orangeLaurel/00-firstScript.sql b/db/versions/.archive/10319-orangeLaurel/00-firstScript.sql new file mode 100644 index 000000000..1e77497a6 --- /dev/null +++ b/db/versions/.archive/10319-orangeLaurel/00-firstScript.sql @@ -0,0 +1,244 @@ +USE vn; + +ALTER TABLE `postgresql`.`business` +ADD COLUMN `workerFk` INT(10) UNSIGNED NOT NULL AFTER `occupationCodeFk`; + +UPDATE postgresql.business b + JOIN postgresql.profile p ON p.profile_id = b.client_id + SET b.workerFk = p.workerFk + WHERE p.workerFk IS NOT NULL; + +-- 5 líneas afectadas contratos 2014 (info en A3) +DELETE FROM postgresql.business + WHERE NOT workerFk; + +ALTER TABLE `postgresql`.`business` + ADD INDEX `business_workerFk_idx` (`workerFk` ASC) ; + +ALTER TABLE `postgresql`.`business` + ADD CONSTRAINT `business_workerFk` + FOREIGN KEY (`workerFk`) + REFERENCES `vn`.`worker` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +CREATE TABLE `business` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `companyCodeFk` char(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `started` date DEFAULT NULL, + `ended` date DEFAULT NULL, + `workerBusiness` longtext DEFAULT NULL, + `reasonEndFk` int(11) DEFAULT NULL, + `payedHolidays` decimal(5,2) NOT NULL DEFAULT 0.00, + `occupationCodeFk` varchar(1) DEFAULT NULL, + `workerFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `business_occupationCodeFk` (`occupationCodeFk`), + KEY `business_companyCodeFk` (`companyCodeFk`), + KEY `business_workerFk_idx` (`workerFk`), + CONSTRAINT `business_companyCodeFk` FOREIGN KEY (`companyCodeFk`) REFERENCES `vn`.`company` (`code`) ON UPDATE CASCADE, + CONSTRAINT `business_occupationCodeFk` FOREIGN KEY (`occupationCodeFk`) REFERENCES `vn`.`occupationCode` (`code`) ON UPDATE CASCADE, + CONSTRAINT `business_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +INSERT INTO vn.business (id, + companyCodeFk, + started, + ended, + workerBusiness, + reasonEndFk, + payedHolidays, + occupationCodeFk, + workerFk ) + SELECT business_id, + companyCodeFk, + date_start, + date_end, + workerBusiness, + reasonEndFk, + IFNULL(payedHolidays, 0), + occupationCodeFk, + workerFk + FROM postgresql.business; + +ALTER TABLE `vn`.`worker` + DROP FOREIGN KEY `worker_business`; + +ALTER TABLE `vn`.`worker` +ADD CONSTRAINT `worker_businessFk` + FOREIGN KEY (`businessFk`) + REFERENCES `vn`.`business` (`id`) + ON DELETE SET NULL + ON UPDATE CASCADE; + +ALTER TABLE `postgresql`.`business_labour_payroll` + DROP FOREIGN KEY `business_labour_payroll_fk1`; + +ALTER TABLE `postgresql`.`business_labour_payroll` +ADD CONSTRAINT `business_labour_payroll_business_id` + FOREIGN KEY (`business_id`) + REFERENCES `vn`.`business` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; + +ALTER TABLE `postgresql`.`business_labour` +DROP FOREIGN KEY `bus_restriction`; + +ALTER TABLE `postgresql`.`business_labour` +ADD CONSTRAINT `business_labour_business_id` + FOREIGN KEY (`business_id`) + REFERENCES `vn`.`business` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; + +-- Es necesario hacerlo aquí porque falla en otras vistas donde se utiliza esta +CREATE + OR REPLACE ALGORITHM = UNDEFINED + DEFINER = `root`@`localhost` + SQL SECURITY DEFINER +VIEW `postgresql`.`calendar_employee` AS + SELECT + `ce`.`id` AS `id`, + `ce`.`businessFk` AS `businessFk`, + `ce`.`dayOffTypeFk` AS `calendar_state_id`, + `ce`.`dated` AS `date` + FROM + `vn`.`calendar` `ce`; + +DROP TABLE `vn`.`profile`; + +ALTER TABLE `vn`.`business` +ADD COLUMN `notes` LONGTEXT NULL DEFAULT NULL AFTER `workerFk`, +ADD COLUMN `departmentFk` INT(11) NULL DEFAULT NULL AFTER `notes`, +ADD COLUMN `workerBusinessProfessionalCategoryFk` INT(11) NULL DEFAULT NULL AFTER `departmentFk`, +ADD COLUMN `calendarTypeFk` INT(11) NULL DEFAULT 1 AFTER `workerBusinessProfessionalCategoryFk`, +ADD COLUMN `isHourlyLabor` tinyint(1) NOT NULL DEFAULT FALSE COMMENT 'Contrato por horas' AFTER `calendarTypeFk`, +ADD COLUMN `workcenterFk` INT(11) NOT NULL AFTER `isHourlyLabor`, +ADD COLUMN `rate` INT(11) NULL DEFAULT NULL AFTER `workcenterFk`, +ADD COLUMN `workerBusinessCategoryFk` INT(11) NULL DEFAULT NULL AFTER `rate`, +ADD COLUMN `workerBusinessTypeFk` INT(11) NULL DEFAULT NULL AFTER `workerBusinessCategoryFk`, +ADD COLUMN `amount` DECIMAL(10,2) NOT NULL DEFAULT 0 COMMENT 'Importe pactado' AFTER `workerBusinessTypeFk`, +ADD COLUMN `workerBusinessAgreementFk` INT(11) NULL DEFAULT NULL AFTER `amount`; + +UPDATE vn.business b + LEFT JOIN postgresql.business_labour bl ON bl.business_id = b.id + LEFT JOIN postgresql.business_labour_payroll blp ON blp.business_id = b.id + SET b.notes = bl.notes, + b.departmentFk = bl.department_id, + b.workerBusinessProfessionalCategoryFk = bl.professional_category_id, + b.calendarTypeFk = bl.calendar_labour_type_id, + b.isHourlyLabor = bl.porhoras, + b.workcenterFk = bl.workcenter_id, + b.rate = blp.cod_tarifa, + b.workerBusinessCategoryFk = blp.cod_categoria, + b.workerBusinessTypeFk = blp.cod_contrato, + b.amount = blp.importepactado, + b.workerBusinessAgreementFk = bl.labour_agreement_id; + + ALTER TABLE `vn`.`business` + ADD INDEX `business_departmentFk_idx` (`departmentFk` ASC); + + ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_departmentFk` + FOREIGN KEY (`departmentFk`) + REFERENCES `vn`.`department` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + ALTER TABLE `vn`.`business` + ADD INDEX `business_workerBusinessProfessionalCategoryFk_idx` (`workerBusinessProfessionalCategoryFk` ASC) ; + + ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_workerBusinessProfessionalCategoryFk` + FOREIGN KEY (`workerBusinessProfessionalCategoryFk`) + REFERENCES `postgresql`.`professional_category` (`professional_category_id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + ALTER TABLE `vn`.`business` + ADD INDEX `business_calendarTypeFk_idx` (`calendarTypeFk` ASC); + + ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_calendarTypeFk` + FOREIGN KEY (`calendarTypeFk`) + REFERENCES `postgresql`.`calendar_labour_type` (`calendar_labour_type_id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_workerBusinessCategoryFk` + FOREIGN KEY (`workerBusinessCategoryFk`) + REFERENCES `vn2008`.`payroll_categorias` (`codcategoria`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + ALTER TABLE `vn`.`business` + ADD INDEX `business_workerBusinessTypeFk_idx` (`workerBusinessTypeFk` ASC); + + ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_workerBusinessTypeFk` + FOREIGN KEY (`workerBusinessTypeFk`) + REFERENCES `vn`.`workerBusinessType` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + + ALTER TABLE `vn`.`business` + ADD INDEX `business_workerBusinessAgreementFk_idx` (`workerBusinessAgreementFk` ASC); + + ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_workerBusinessAgreementFk` + FOREIGN KEY (`workerBusinessAgreementFk`) + REFERENCES `postgresql`.`labour_agreement` (`labour_agreement_id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `postgresql`.`profile` + RENAME TO `postgresql`.`profile__` ; + +ALTER TABLE `postgresql`.`business` + RENAME TO `postgresql`.`business__` ; + +ALTER TABLE `postgresql`.`business_labour` + RENAME TO `postgresql`.`business_labour__` ; + +ALTER TABLE `postgresql`.`business_labour_payroll` + RENAME TO `postgresql`.`business_labour_payroll__` ; + +ALTER TABLE `postgresql`.`journey` + DROP FOREIGN KEY `business_journey`; +ALTER TABLE `postgresql`.`journey` + ADD INDEX `journey_business_id_idx` (`business_id` ASC) , + DROP INDEX `fki_business_journey` ; + +ALTER TABLE `postgresql`.`journey` + ADD CONSTRAINT `journey_business_id` + FOREIGN KEY (`business_id`) + REFERENCES `vn`.`business` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`calendar` + DROP FOREIGN KEY `calendar_businessFk`; + +ALTER TABLE `vn`.`calendar` +DROP INDEX `business_id_date` ; + +ALTER TABLE `vn`.`calendar` + ADD CONSTRAINT `calendar_businessFk` + FOREIGN KEY (`businessFk`) + REFERENCES `vn`.`business` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; + +ALTER TABLE `vn`.`workerJourney` + DROP FOREIGN KEY `workerJourney_businessFk`; + +ALTER TABLE `vn`.`workerJourney` + DROP INDEX `workerJourney_businessFk_idx` ; + +ALTER TABLE `vn`.`workerJourney` + ADD CONSTRAINT `workerJourney_businessFk` + FOREIGN KEY (`businessFk`) + REFERENCES `vn`.`business` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10320-4130collectionnewPAK/00-operator.sql b/db/versions/.archive/10320-4130collectionnewPAK/00-operator.sql new file mode 100644 index 000000000..7c3f07f83 --- /dev/null +++ b/db/versions/.archive/10320-4130collectionnewPAK/00-operator.sql @@ -0,0 +1,7 @@ +-- Place your SQL code here +ALTER TABLE vn.operator ADD IF NOT EXISTS trainFk INT DEFAULT 1 NOT NULL; +ALTER TABLE vn.operator ADD IF NOT EXISTS itemPackingTypeFk VARCHAR(1) NULL; +ALTER TABLE vn.operator ADD IF NOT EXISTS warehouseFk SMALLINT(6) UNSIGNED DEFAULT 60 NOT NULL; +ALTER TABLE vn.operator ADD CONSTRAINT operator_FK_1 FOREIGN KEY (trainFk) REFERENCES vn.train(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.operator ADD CONSTRAINT operator_FK_2 FOREIGN KEY (itemPackingTypeFk) REFERENCES vn.itemPackingType(code) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.operator ADD CONSTRAINT operator_FK_3 FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/.archive/10320-4130collectionnewPAK/01-collection.sql b/db/versions/.archive/10320-4130collectionnewPAK/01-collection.sql new file mode 100644 index 000000000..f1b70cac6 --- /dev/null +++ b/db/versions/.archive/10320-4130collectionnewPAK/01-collection.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.collection ADD warehouseFk smallint(6) unsigned DEFAULT 60 NOT NULL; + +ALTER TABLE vn.collection ADD CONSTRAINT collection_FK2 FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/.archive/10320-4130collectionnewPAK/02-productionConfig.sql b/db/versions/.archive/10320-4130collectionnewPAK/02-productionConfig.sql new file mode 100644 index 000000000..59080f4f6 --- /dev/null +++ b/db/versions/.archive/10320-4130collectionnewPAK/02-productionConfig.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.productionConfig + ADD maxNotAssignedCollectionLifeTime TIME DEFAULT '00:10:00' NOT NULL + COMMENT 'Tiempo de vida de las colecciones sin asignar. Cuando se supera son eliminadas'; diff --git a/db/versions/.archive/10321-yellowDendro/00-firstScript.sql b/db/versions/.archive/10321-yellowDendro/00-firstScript.sql new file mode 100644 index 000000000..80fc2a6c6 --- /dev/null +++ b/db/versions/.archive/10321-yellowDendro/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.expedition CHANGE itemFk__ itemFk int(11) NULL COMMENT 'Si es necesario el itemFk del cubo, se obtiene mediante packagingFk, join packing.itemFk'; diff --git a/db/versions/.archive/10322-maroonFern/00-firstScript.sql b/db/versions/.archive/10322-maroonFern/00-firstScript.sql new file mode 100644 index 000000000..fbb1dd569 --- /dev/null +++ b/db/versions/.archive/10322-maroonFern/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entry MODIFY COLUMN typeFk varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'Tipo de entrada'; \ No newline at end of file diff --git a/db/versions/.archive/10326-crimsonCyca/00-firstScript.sql b/db/versions/.archive/10326-crimsonCyca/00-firstScript.sql new file mode 100644 index 000000000..718a32f9b --- /dev/null +++ b/db/versions/.archive/10326-crimsonCyca/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.buy CHANGE producer producer__ varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/.archive/10328-whiteMedeola/00-firstScript.sql b/db/versions/.archive/10328-whiteMedeola/00-firstScript.sql new file mode 100644 index 000000000..5fb22fdf2 --- /dev/null +++ b/db/versions/.archive/10328-whiteMedeola/00-firstScript.sql @@ -0,0 +1,10 @@ +CREATE TABLE sage.config ( + id INT auto_increment NULL, + pendingTaxAccount varchar(100) NULL COMMENT 'Cuenta contable IVA pendiente', + CONSTRAINT config_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_general_ci; + +INSERT INTO sage.config SET id = 1,pendingTaxAccount = '4700000999'; \ No newline at end of file diff --git a/db/versions/.archive/10329-aquaRose/00-firstScript.sql b/db/versions/.archive/10329-aquaRose/00-firstScript.sql new file mode 100644 index 000000000..43e17a951 --- /dev/null +++ b/db/versions/.archive/10329-aquaRose/00-firstScript.sql @@ -0,0 +1,10 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`routeCommission` + DROP FOREIGN KEY `routeCommission_routeFk`; + +ALTER TABLE `vn`.`routeCommission` + ADD CONSTRAINT `routeCommission_routeFk` + FOREIGN KEY (`routeFk`) + REFERENCES `vn`.`route` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; diff --git a/db/versions/.archive/10330-pinkCataractarum/00-firstScript.sql b/db/versions/.archive/10330-pinkCataractarum/00-firstScript.sql new file mode 100644 index 000000000..eb665c5c3 --- /dev/null +++ b/db/versions/.archive/10330-pinkCataractarum/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`worker` +ADD COLUMN `balance` DECIMAL(10,2) NULL AFTER `businessFk`; + +UPDATE `vn`.`worker` w +JOIN(SELECT workerFk, SUM(i.debe) - SUM(i.haber) balance +FROM postgresql.income_employee i +GROUP BY i.workerFk) sub ON sub.workerFk = w.id +SET w.balance = sub.balance; \ No newline at end of file diff --git a/db/versions/.archive/10332-greenMedeola/00-firstScript.sql b/db/versions/.archive/10332-greenMedeola/00-firstScript.sql new file mode 100644 index 000000000..bdeb9240d --- /dev/null +++ b/db/versions/.archive/10332-greenMedeola/00-firstScript.sql @@ -0,0 +1,10 @@ +ALTER TABLE vn.itemShelving DROP COLUMN deep__; +ALTER TABLE vn.itemShelving DROP COLUMN quantity__; +ALTER TABLE vn.itemShelving DROP COLUMN available__; +ALTER TABLE vn.itemShelving DROP COLUMN level__; + + -- deprecar shelve, priority, stars +ALTER TABLE vn.itemShelving RENAME COLUMN shelve TO shelve__; +ALTER TABLE vn.itemShelving RENAME COLUMN `priority` TO priority__; +ALTER TABLE vn.itemShelving RENAME COLUMN stars TO stars__; + diff --git a/db/versions/.archive/10334-4310collectionAssignPAK/00-collectionHotbed.sql b/db/versions/.archive/10334-4310collectionAssignPAK/00-collectionHotbed.sql new file mode 100644 index 000000000..43b85a106 --- /dev/null +++ b/db/versions/.archive/10334-4310collectionAssignPAK/00-collectionHotbed.sql @@ -0,0 +1,7 @@ +-- Place your SQL code here +CREATE OR REPLACE TABLE vn.collectionHotbed ( + `userFk` int(10) unsigned NOT NULL, + `created` timestamp NULL DEFAULT current_timestamp(), + PRIMARY KEY (`userFk`), + CONSTRAINT `collectionHotbed_FK` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/.archive/10334-4310collectionAssignPAK/01-saleGroupDetail.sql b/db/versions/.archive/10334-4310collectionAssignPAK/01-saleGroupDetail.sql new file mode 100644 index 000000000..9f4c2deac --- /dev/null +++ b/db/versions/.archive/10334-4310collectionAssignPAK/01-saleGroupDetail.sql @@ -0,0 +1 @@ +ALTER TABLE vn.saleGroupDetail ADD CONSTRAINT saleGroupDetail_UN UNIQUE KEY (saleFk,saleGroupFk); diff --git a/db/versions/.archive/10335-silverCyca/00-firstScript.sql b/db/versions/.archive/10335-silverCyca/00-firstScript.sql new file mode 100644 index 000000000..85385f8fb --- /dev/null +++ b/db/versions/.archive/10335-silverCyca/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`supplierAccount` +CHANGE COLUMN `bicSufix` `bicSufix__` VARCHAR(3) NOT NULL DEFAULT '' ; diff --git a/db/versions/.archive/10336-grayMoss/00-firstScript.sql b/db/versions/.archive/10336-grayMoss/00-firstScript.sql new file mode 100644 index 000000000..c2a69e09c --- /dev/null +++ b/db/versions/.archive/10336-grayMoss/00-firstScript.sql @@ -0,0 +1,9 @@ +USE vn; + +ALTER TABLE vn.ticketRefund + DROP FOREIGN KEY ticketRefund_FK; + +ALTER TABLE vn.ticketRefund + ADD CONSTRAINT ticketRefund_FK + FOREIGN KEY (refundTicketFk) + REFERENCES vn.ticket(id) ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/.archive/10337-orangePalmetto/00-firstScript.sql b/db/versions/.archive/10337-orangePalmetto/00-firstScript.sql new file mode 100644 index 000000000..a772caaa8 --- /dev/null +++ b/db/versions/.archive/10337-orangePalmetto/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.ledgerConfig ADD maxTolerance decimal(10,2) NOT NULL; +UPDATE vn.ledgerConfig + SET maxTolerance=0.05; \ No newline at end of file diff --git a/db/versions/.archive/10339-goldenCarnation/00-firstScript.sql b/db/versions/.archive/10339-goldenCarnation/00-firstScript.sql new file mode 100644 index 000000000..7ee0d95cb --- /dev/null +++ b/db/versions/.archive/10339-goldenCarnation/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +use vn; +CREATE TABLE vn.workerConfig ( + id INT PRIMARY KEY AUTO_INCREMENT NOT NULL, + businessUpdated DATE NULL +); \ No newline at end of file diff --git a/db/versions/.archive/10340-maroonCordyline/00-firstScript.sql b/db/versions/.archive/10340-maroonCordyline/00-firstScript.sql new file mode 100644 index 000000000..1d7e64e8c --- /dev/null +++ b/db/versions/.archive/10340-maroonCordyline/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here + +USE vn; + +RENAME TABLE vn.cmr_expeditionPallet TO vn.cmrPallet; diff --git a/db/versions/.archive/10341-redDendro/00-firstScript.sql b/db/versions/.archive/10341-redDendro/00-firstScript.sql new file mode 100644 index 000000000..b2c4fd35c --- /dev/null +++ b/db/versions/.archive/10341-redDendro/00-firstScript.sql @@ -0,0 +1,20 @@ +ALTER TABLE vn.project ADD stateFk varchar(25) DEFAULT 'open'; + +CREATE TABLE vn.projectState ( + code varchar(25) NOT NULL, + description varchar(100) NOT NULL, + CONSTRAINT projectState_PK PRIMARY KEY (code) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT INTO vn.projectState (code,description) + VALUES ('open','Abierto'); +INSERT INTO vn.projectState (code,description) + VALUES ('inProgress','En progreso'); +INSERT INTO vn.projectState (code,description) + VALUES ('closed','Cerrado'); + +ALTER TABLE vn.project ADD CONSTRAINT project_FK_3 FOREIGN KEY (stateFk) REFERENCES vn.projectState(code); + diff --git a/db/versions/.archive/10342-limeChico/00-firstScript.sql b/db/versions/.archive/10342-limeChico/00-firstScript.sql new file mode 100644 index 000000000..5055a5011 --- /dev/null +++ b/db/versions/.archive/10342-limeChico/00-firstScript.sql @@ -0,0 +1,33 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.collectionColors ADD rgb char(7) DEFAULT NULL NULL; + +ALTER TABLE vn.collectionColors ADD CONSTRAINT collectionColors_UN UNIQUE KEY (shelve,wagon,trainFk); + +UPDATE vn.collectionColors +SET rgb='#ff0000' +WHERE id=1; + +UPDATE vn.collectionColors +SET rgb='#ffce30' + WHERE id=2; + +UPDATE vn.collectionColors +SET rgb='#008000' + WHERE id=3; + +UPDATE vn.collectionColors +SET rgb='#0000ff' + WHERE id=4; + +UPDATE vn.collectionColors +SET rgb='#ffffff' + WHERE id=5; + +UPDATE vn.collectionColors +SET rgb='#000000' + WHERE id=6; + + diff --git a/db/versions/.archive/10343-azureOak/00-firstScript.sql b/db/versions/.archive/10343-azureOak/00-firstScript.sql new file mode 100644 index 000000000..aa01e1533 --- /dev/null +++ b/db/versions/.archive/10343-azureOak/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`buy` +CHANGE COLUMN `buyingValue` `buyingValue` DECIMAL(10,3) NOT NULL DEFAULT 0.000 , +CHANGE COLUMN `freightValue` `freightValue` DECIMAL(10,3) NOT NULL DEFAULT 0.000 , +CHANGE COLUMN `comissionValue` `comissionValue` DECIMAL(10,3) NOT NULL DEFAULT 0.000 , +CHANGE COLUMN `packageValue` `packageValue` DECIMAL(10,3) NOT NULL DEFAULT 0.000 ; \ No newline at end of file diff --git a/db/versions/.archive/10345-wheatRaphis/00-firstScript.sql b/db/versions/.archive/10345-wheatRaphis/00-firstScript.sql new file mode 100644 index 000000000..13cec2f16 --- /dev/null +++ b/db/versions/.archive/10345-wheatRaphis/00-firstScript.sql @@ -0,0 +1,15 @@ +use vn; +CREATE OR REPLACE TABLE `paperSize` ( + `code` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, + `color` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, + `alias` varchar(100) COLLATE utf8mb3_unicode_ci NOT NULL, + PRIMARY KEY (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.report ADD paperSizeFk varchar(100) DEFAULT NULL NULL; +ALTER TABLE vn.report ADD CONSTRAINT report_FK FOREIGN KEY (paperSizeFk) REFERENCES vn.paperSize(code); + +ALTER TABLE vn.printer ADD paperSizeFk varchar(100) DEFAULT NULL NULL; +ALTER TABLE vn.printer ADD CONSTRAINT printer_FK_1 FOREIGN KEY (paperSizeFk) REFERENCES vn.paperSize(code); + + diff --git a/db/versions/.archive/10347-wheatDracena/00-firstScript.sql b/db/versions/.archive/10347-wheatDracena/00-firstScript.sql new file mode 100644 index 000000000..31446ee37 --- /dev/null +++ b/db/versions/.archive/10347-wheatDracena/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.expedition CHANGE isBox freightItemFk int(11) DEFAULT 1 NULL COMMENT 'itemFk del artículo que nos va a facturar el proveedor de transporte.'; + +UPDATE vn.expedition SET freightItemFk = NULL WHERE freightItemFk = 0; \ No newline at end of file diff --git a/db/versions/.archive/10347-wheatDracena/01-addVirtualField.sql b/db/versions/.archive/10347-wheatDracena/01-addVirtualField.sql new file mode 100644 index 000000000..7085c0ecd --- /dev/null +++ b/db/versions/.archive/10347-wheatDracena/01-addVirtualField.sql @@ -0,0 +1 @@ +ALTER TABLE vn.expedition ADD isBox INT(11) GENERATED ALWAYS AS (freightItemFk) VIRTUAL COMMENT 'Columna virtual provisional para Salix'; \ No newline at end of file diff --git a/db/versions/.archive/10349-greenOak/00-firstScript.sql b/db/versions/.archive/10349-greenOak/00-firstScript.sql new file mode 100644 index 000000000..36d9079aa --- /dev/null +++ b/db/versions/.archive/10349-greenOak/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`itemType` +ADD COLUMN `isMergeable` TINYINT(1) NOT NULL DEFAULT 1 AFTER `maxRefs`; + +ALTER TABLE `vn`.`itemType` +CHANGE COLUMN `isMergeable` `isMergeable` TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'Articulos que al mergear los tickets se fusionara la linea' ; + +UPDATE `vn`.`itemType` SET `isMergeable` = '0' WHERE (`code` = 'GEN'); + diff --git a/db/versions/.archive/10350-azureAnthurium/00-firstScript.sql b/db/versions/.archive/10350-azureAnthurium/00-firstScript.sql new file mode 100644 index 000000000..dbe80c35a --- /dev/null +++ b/db/versions/.archive/10350-azureAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.tag DROP FOREIGN KEY fgnTag; diff --git a/db/versions/.archive/10352-maroonHydrangea/00-firstScript.sql b/db/versions/.archive/10352-maroonHydrangea/00-firstScript.sql new file mode 100644 index 000000000..ab1540fd6 --- /dev/null +++ b/db/versions/.archive/10352-maroonHydrangea/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.entry CHANGE `ref` invoiceNumber varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; +ALTER TABLE vn.entry ADD reference varchar(50) NULL COMMENT 'Referencia para eti'; +ALTER TABLE vn.entry ADD ref VARCHAR(50) GENERATED ALWAYS AS (invoiceNumber) VIRTUAL COMMENT 'Columna virtual provisional para Salix'; \ No newline at end of file diff --git a/db/versions/.archive/10353-silverRoebelini/00-firstScript.sql b/db/versions/.archive/10353-silverRoebelini/00-firstScript.sql new file mode 100644 index 000000000..e4cfbe5c0 --- /dev/null +++ b/db/versions/.archive/10353-silverRoebelini/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here + +USE vn; + +INSERT INTO vn.silexACL +( module, `method`, `role`) +VALUES('almacennew', 'shelvingLog_add', 'employee'); + +ALTER TABLE vn.shelvingLog MODIFY COLUMN `action` set('insert','update','delete','select') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; diff --git a/db/versions/.archive/10354-wheatMedeola/00-firstScript.sql b/db/versions/.archive/10354-wheatMedeola/00-firstScript.sql new file mode 100644 index 000000000..143183830 --- /dev/null +++ b/db/versions/.archive/10354-wheatMedeola/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.ticket CHANGE isLabeled isLabeled__ tinyint(1) DEFAULT 0 NOT NULL; + diff --git a/db/versions/.archive/10356-turquoiseAnthurium/00-firstScript.sql b/db/versions/.archive/10356-turquoiseAnthurium/00-firstScript.sql new file mode 100644 index 000000000..9c2d7280a --- /dev/null +++ b/db/versions/.archive/10356-turquoiseAnthurium/00-firstScript.sql @@ -0,0 +1,20 @@ + +-- Menú options + +DELETE FROM hedera.menu + WHERE id=27; + +-- Rest privileges + +UPDATE hedera.restPriv + SET methodPath='user/supplant' + WHERE id=5; +UPDATE hedera.restPriv + SET methodPath='misc/captcha' + WHERE id=10; +UPDATE hedera.restPriv + SET methodPath='user/recover-password' + WHERE id=15; +UPDATE hedera.restPriv + SET methodPath='user/restore-password' + WHERE id=16; diff --git a/db/versions/.archive/10356-turquoiseAnthurium/01-orderConfigFk.sql b/db/versions/.archive/10356-turquoiseAnthurium/01-orderConfigFk.sql new file mode 100644 index 000000000..d29f56ce9 --- /dev/null +++ b/db/versions/.archive/10356-turquoiseAnthurium/01-orderConfigFk.sql @@ -0,0 +1 @@ +ALTER TABLE hedera.orderConfig DROP FOREIGN KEY orderConfig_ibfk_5; diff --git a/db/versions/.archive/10356-turquoiseAnthurium/02-orderConfigDrop.sql b/db/versions/.archive/10356-turquoiseAnthurium/02-orderConfigDrop.sql new file mode 100644 index 000000000..e3ce6afe9 --- /dev/null +++ b/db/versions/.archive/10356-turquoiseAnthurium/02-orderConfigDrop.sql @@ -0,0 +1 @@ +ALTER TABLE `hedera`.`orderConfig` DROP `guestAddressFk`; diff --git a/db/versions/.archive/10357-blackAnthurium/00-firstScript.sql b/db/versions/.archive/10357-blackAnthurium/00-firstScript.sql new file mode 100644 index 000000000..8a2bd8b41 --- /dev/null +++ b/db/versions/.archive/10357-blackAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.ticket CHANGE isLabeled__ isLabeled tinyint(1) DEFAULT 0 NOT NULL; + diff --git a/db/versions/.archive/10359-turquoiseAnthurium/00-improvedGeneralLog_collate.sql b/db/versions/.archive/10359-turquoiseAnthurium/00-improvedGeneralLog_collate.sql new file mode 100644 index 000000000..5f354ba6f --- /dev/null +++ b/db/versions/.archive/10359-turquoiseAnthurium/00-improvedGeneralLog_collate.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.improvedGeneralLog CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci; +ALTER TABLE vn.improvedGeneralLogProcedures CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci; diff --git a/db/versions/.archive/10360-tealLaurel/00-firstScript.sql b/db/versions/.archive/10360-tealLaurel/00-firstScript.sql new file mode 100644 index 000000000..8d0506b74 --- /dev/null +++ b/db/versions/.archive/10360-tealLaurel/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +USE vn; + +INSERT INTO vn.silexACL +(module, `method`, `role`) +VALUES('almacennew', 'collection_get', 'employee'); diff --git a/db/versions/.archive/10361-redTulip/00-firstScript.sql b/db/versions/.archive/10361-redTulip/00-firstScript.sql new file mode 100644 index 000000000..1a46ef57a --- /dev/null +++ b/db/versions/.archive/10361-redTulip/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`printQueue` +CHANGE COLUMN `statusCode` `statusCode` + ENUM('queued', 'error', 'printing', 'printed') NOT NULL DEFAULT 'queued' ; diff --git a/db/versions/.archive/10362-azureMoss/00-dropUdfs.sql b/db/versions/.archive/10362-azureMoss/00-dropUdfs.sql new file mode 100644 index 000000000..e64e75586 --- /dev/null +++ b/db/versions/.archive/10362-azureMoss/00-dropUdfs.sql @@ -0,0 +1,3 @@ +DROP FUNCTION IF EXISTS minacum; +DROP FUNCTION IF EXISTS multimax; +DROP FUNCTION IF EXISTS sql_printf; diff --git a/db/versions/.archive/10362-azureMoss/00-dropUdfs.undo.sql b/db/versions/.archive/10362-azureMoss/00-dropUdfs.undo.sql new file mode 100644 index 000000000..4d469ed79 --- /dev/null +++ b/db/versions/.archive/10362-azureMoss/00-dropUdfs.undo.sql @@ -0,0 +1,3 @@ +CREATE AGGREGATE FUNCTION minacum RETURNS INT SONAME 'minacum.so'; +CREATE AGGREGATE FUNCTION multimax RETURNS INT SONAME 'multimax.so'; +CREATE FUNCTION sql_printf RETURNS STRING SONAME 'sql_printf.so'; diff --git a/db/versions/.archive/10363-azureLilium/00-firstScript.sql b/db/versions/.archive/10363-azureLilium/00-firstScript.sql new file mode 100644 index 000000000..6c2edbb2d --- /dev/null +++ b/db/versions/.archive/10363-azureLilium/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE bi.rutasBoard ADD m3 decimal(10,1) unsigned NULL; diff --git a/db/versions/.archive/10365-hfCollectionPAK/00-firstScript.sql b/db/versions/.archive/10365-hfCollectionPAK/00-firstScript.sql new file mode 100644 index 000000000..86a045524 --- /dev/null +++ b/db/versions/.archive/10365-hfCollectionPAK/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.operator MODIFY COLUMN itemPackingTypeFk varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'H' NOT NULL; diff --git a/db/versions/.archive/10368-maroonErica/00-firstScript.sql b/db/versions/.archive/10368-maroonErica/00-firstScript.sql new file mode 100644 index 000000000..46c3a1cc1 --- /dev/null +++ b/db/versions/.archive/10368-maroonErica/00-firstScript.sql @@ -0,0 +1,2 @@ +USE vn; +ALTER TABLE vn.business ADD basicSalary decimal(10,2) DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/.archive/10369-hfProductionControlPAK/00-firstScript.sql b/db/versions/.archive/10369-hfProductionControlPAK/00-firstScript.sql new file mode 100644 index 000000000..78a388f07 --- /dev/null +++ b/db/versions/.archive/10369-hfProductionControlPAK/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER IGNORE TABLE vn.productionConfig ADD maxProductionScopeDays INT DEFAULT 1 NOT NULL COMMENT 'maximo numero de dias en F11'; diff --git a/db/versions/.archive/10370-pinkBirch/00-deleteForeignKey.sql b/db/versions/.archive/10370-pinkBirch/00-deleteForeignKey.sql new file mode 100644 index 000000000..ecebeaf90 --- /dev/null +++ b/db/versions/.archive/10370-pinkBirch/00-deleteForeignKey.sql @@ -0,0 +1,45 @@ +ALTER TABLE `vn`.`item` +DROP FOREIGN KEY IF EXISTS `item_ibfk_4`; + +ALTER TABLE `vn`.`address` +DROP FOREIGN KEY IF EXISTS `address_ibfk_1`; + +ALTER TABLE `vn`.`agency` +DROP FOREIGN KEY IF EXISTS `agency_ibfk_2`; + +ALTER TABLE `vn`.`claim` +DROP FOREIGN KEY IF EXISTS `claim_ibfk_4`; + +ALTER TABLE `vn`.`host` +DROP FOREIGN KEY IF EXISTS `configHost_FK_1`; + +ALTER TABLE `vn`.`ticket` +DROP FOREIGN KEY IF EXISTS `tickets_fk11`; + +ALTER TABLE `vn`.`zone` +DROP FOREIGN KEY IF EXISTS `fk_zone_1`; + +ALTER TABLE `vn`.`floramondoConfig` +DROP FOREIGN KEY IF EXISTS `floramondoConfigWarehouseOutFk`, +DROP FOREIGN KEY IF EXISTS `floramondoConfigAgencyModeFk`; + +ALTER TABLE `postgresql`.`province` +DROP FOREIGN KEY IF EXISTS `fk_province_nation1`; + +ALTER TABLE `vn`.`person__` +DROP FOREIGN KEY `Person_ibfk_1`; + +ALTER TABLE `postgresql`.`profile__` +DROP FOREIGN KEY IF EXISTS `profile_workerFk`; + +ALTER TABLE `postgresql`.`profile_media` +DROP FOREIGN KEY IF EXISTS `media_ibfk_20`; + +ALTER TABLE `postgresql`.`erte_COVID19` +DROP FOREIGN KEY IF EXISTS `erte_COVID19_FK`; + +ALTER TABLE `vn`.`contratos_subvencion_270619` +DROP FOREIGN KEY IF EXISTS `contratos_subvencion_270619_fk3`; + + + diff --git a/db/versions/.archive/10370-pinkBirch/01-firstScript.sql b/db/versions/.archive/10370-pinkBirch/01-firstScript.sql new file mode 100644 index 000000000..eaa1190ec --- /dev/null +++ b/db/versions/.archive/10370-pinkBirch/01-firstScript.sql @@ -0,0 +1,193 @@ +-- Place your SQL code here +DROP DATABASE IF EXISTS `roundcube__`; +DROP DATABASE IF EXISTS `mediawiki__`; +DROP DATABASE IF EXISTS `wordpress__`; +DROP DATABASE IF EXISTS `ps_helper__`; + +ALTER TABLE `vn`.`invoiceOut` +DROP COLUMN IF EXISTS `workerFk__`, +DROP COLUMN IF EXISTS `vat16__`, +DROP COLUMN IF EXISTS `vat7__`, +DROP COLUMN IF EXISTS `equ4__`, +DROP COLUMN IF EXISTS `equ1__`, +DROP COLUMN IF EXISTS `taxableBase16__`, +DROP COLUMN IF EXISTS `taxableBase7__`, +DROP INDEX IF EXISTS `Id_Trabajador` ; + +ALTER TABLE `vn`.`item` +DROP COLUMN IF EXISTS `sectorFk__`, +DROP COLUMN IF EXISTS `compression__`, +DROP COLUMN IF EXISTS `isBargain__`, +DROP COLUMN IF EXISTS `isOnOffer__`, +DROP COLUMN IF EXISTS `niche__`, +DROP COLUMN IF EXISTS `taxClassFk__`, +DROP COLUMN IF EXISTS `isDeliveryNote__`, +DROP INDEX IF EXISTS `item_ibfk_6_idx` , +DROP INDEX IF EXISTS `iva_group_id`; + +ALTER TABLE `vn`.`address` +DROP COLUMN IF EXISTS `isVilassarBuyer__`, +DROP COLUMN IF EXISTS `codPosOld__`, +DROP COLUMN IF EXISTS `postcodeOLD__`, +DROP COLUMN IF EXISTS `porte__`, +DROP COLUMN IF EXISTS `hasInsurance__`, +DROP COLUMN IF EXISTS `notes__`, +DROP COLUMN IF EXISTS `warehouseFk__`, +DROP INDEX IF EXISTS `warehouse_id` ; + +ALTER TABLE `vn`.`config` +DROP COLUMN IF EXISTS `serialMFk__`, +DROP COLUMN IF EXISTS `serialTFk__`, +DROP COLUMN IF EXISTS `serialPFk__`, +DROP COLUMN IF EXISTS `serialHFk__`, +DROP COLUMN IF EXISTS `serialCFk__`, +DROP COLUMN IF EXISTS `serialRFk__`, +DROP COLUMN IF EXISTS `serialEFk__`, +DROP COLUMN IF EXISTS `serialAFk__`, +DROP COLUMN IF EXISTS `bookFk__`; + +ALTER TABLE `vn`.`client` +DROP COLUMN IF EXISTS `cplusTerIdNifFk__`, +DROP COLUMN IF EXISTS `codposOLD__`, +DROP COLUMN IF EXISTS `postcodeOld__`, +DROP COLUMN IF EXISTS `coreFth__`, +DROP COLUMN IF EXISTS `sepaFth__`, +DROP COLUMN IF EXISTS `splitHolland__`, +DROP COLUMN IF EXISTS `cyc__`, +DROP COLUMN IF EXISTS `hold__`, +DROP COLUMN IF EXISTS `invoiceCopy__`, +DROP COLUMN IF EXISTS `administrativeNotes__`, +DROP COLUMN IF EXISTS `notes__`, +DROP COLUMN IF EXISTS `isReExpedition__`, +DROP COLUMN IF EXISTS `wholesaler__`, +DROP COLUMN IF EXISTS `isOfficial__`, +DROP COLUMN IF EXISTS `receipt__`, +DROP COLUMN IF EXISTS `fax__`, +DROP COLUMN IF EXISTS `discount__`, +DROP INDEX IF EXISTS `codpos` , +ADD INDEX `codpos` (`postcode` ASC) VISIBLE; + +ALTER TABLE `vn`.`claimBeginning` +DROP COLUMN IF EXISTS `claimRequestFk__`, +DROP COLUMN IF EXISTS `claimComplaintFk__`; + +ALTER TABLE `vn`.`department` +DROP COLUMN IF EXISTS `y__`, +DROP COLUMN IF EXISTS `x__`, +DROP COLUMN IF EXISTS `bossFk__`; + +ALTER TABLE `vn`.`claim` +DROP COLUMN IF EXISTS `claimDepartmentFk__`, +DROP INDEX IF EXISTS `cl_dep_id` ; + +ALTER TABLE `vn`.`supplierAccount` +DROP COLUMN IF EXISTS `bicSufix__`; + +ALTER TABLE `vn`.`travelThermograph` +DROP COLUMN IF EXISTS `temperature__`; + +ALTER TABLE `vn`.`origin` +DROP COLUMN IF EXISTS `nl__`, +DROP COLUMN IF EXISTS `flag__`; + +ALTER TABLE `vn`.`itemShelving` +DROP COLUMN IF EXISTS `stars__`, +DROP COLUMN IF EXISTS `priority__`, +DROP COLUMN IF EXISTS `shelve__`; + +ALTER TABLE `vn`.`receipt` +DROP COLUMN IF EXISTS `amountUnpaid__`; + +ALTER TABLE `vn`.`agency` +DROP COLUMN IF EXISTS `supplierFk__`, +DROP COLUMN IF EXISTS `labelZone__`, +DROP COLUMN IF EXISTS `bankFk__`, +DROP COLUMN IF EXISTS `isVolumetric__`, +DROP INDEX IF EXISTS `agency_ibfk_4_idx` , +DROP INDEX IF EXISTS `Id_Banco` ; + +ALTER TABLE `vn`.`sector` +DROP COLUMN IF EXISTS `labelReport__`, +DROP COLUMN IF EXISTS `path__`, +DROP COLUMN IF EXISTS `pickingPlacement__`; + +ALTER TABLE `vn`.`ticket` +DROP COLUMN IF EXISTS `collectionFk__`, +DROP COLUMN IF EXISTS `isBooked__`, +DROP COLUMN IF EXISTS `invoiceOutFk__`, +DROP COLUMN IF EXISTS `notes__`, +DROP INDEX IF EXISTS `tickets_fk11_idx` ; + +ALTER TABLE `vn`.`agencyMode` +DROP COLUMN IF EXISTS `cod71__`; + +ALTER TABLE `vn`.`itemType` +DROP COLUMN IF EXISTS `f11__`, +DROP COLUMN IF EXISTS `gramsMin__`; + +ALTER TABLE `vn`.`ticketRequest` +DROP COLUMN IF EXISTS `ko__`, +DROP COLUMN IF EXISTS `ok__`, +DROP COLUMN IF EXISTS `price__`; + +ALTER TABLE `vn`.`supplier` +DROP COLUMN IF EXISTS `Fax__`; + +ALTER TABLE `vn`.`clientProtected` +DROP COLUMN IF EXISTS `isValidated__`; + +ALTER TABLE `vn`.`payment` +DROP COLUMN IF EXISTS `exchangeInsuranceFk__`, +DROP INDEX IF EXISTS `fk_pago_pago_sdc1_idx` ; + +ALTER TABLE `vn`.`buy` +DROP COLUMN IF EXISTS `producer__`; + +ALTER TABLE `vn`.`host` +DROP COLUMN IF EXISTS `packingSite__`, +DROP COLUMN IF EXISTS `itemPackingTypeFk__`, +DROP INDEX IF EXISTS `configHost_FK_1` ; + +ALTER TABLE `vn`.`zone` +DROP COLUMN IF EXISTS `warehouseFk__`, +DROP INDEX IF EXISTS `fk_zone_1_idx`; + +ALTER TABLE `vn`.`floramondoConfig` +DROP COLUMN IF EXISTS `agencyModeFk__`, +DROP COLUMN IF EXISTS `warehouseOutFk__`, +DROP INDEX IF EXISTS `floramondoConfigAgencyModeFk_idx` , +DROP INDEX IF EXISTS `floramondoConfigWarehouseOut_idx` ; + +ALTER TABLE `vn`.`sms` +DROP COLUMN IF EXISTS `destinationFk__`; + +ALTER TABLE `vn`.`itemBotanical` +DROP COLUMN IF EXISTS `botanical__`; + +ALTER TABLE `vn`.`smsConfig` +DROP COLUMN IF EXISTS `password__`, +DROP COLUMN IF EXISTS `user__`; + +ALTER TABLE `vn`.`expedition` +DROP COLUMN IF EXISTS `checked__`, +DROP COLUMN IF EXISTS `isPickUp__`, +DROP COLUMN IF EXISTS `isRefund__`; + +ALTER TABLE `vn`.`intrastat` +DROP COLUMN IF EXISTS `import__`; + +ALTER TABLE `bs`.`indicators` +DROP COLUMN IF EXISTS `salesWorkersCostRate__`, +DROP COLUMN IF EXISTS `workerCostM3__`, +DROP COLUMN IF EXISTS `hoursM3__`, +DROP COLUMN IF EXISTS `valueM3__`, +DROP COLUMN IF EXISTS `salesValue__`, +DROP COLUMN IF EXISTS `volumeM3__`, +DROP COLUMN IF EXISTS `dailyWorkersCost__`, +DROP COLUMN IF EXISTS `productionHours__`; + +ALTER TABLE `vn2008`.`payroll_employee` +DROP COLUMN IF EXISTS `Person_id__`; + +ALTER TABLE `postgresql`.`income_employee` +DROP COLUMN IF EXISTS `person_id__`; \ No newline at end of file diff --git a/db/versions/.archive/10370-pinkBirch/02-deleteTable.sql b/db/versions/.archive/10370-pinkBirch/02-deleteTable.sql new file mode 100644 index 000000000..850c93789 --- /dev/null +++ b/db/versions/.archive/10370-pinkBirch/02-deleteTable.sql @@ -0,0 +1,116 @@ +DROP TABLE IF EXISTS `bi`.`Last_buy_id__`; +DROP TABLE IF EXISTS `bi`.`lastaction__`; + +DROP TABLE IF EXISTS `bs`.`clientNewBorn__`; +DROP TABLE IF EXISTS `bs`.`mermasCache__`; +DROP TABLE IF EXISTS `bs`.`produccion__`; +DROP TABLE IF EXISTS `bs`.`salePersonEvolution__`; +DROP TABLE IF EXISTS `bs`.`salesMonthlySnapshot__`; +DROP TABLE IF EXISTS `bs`.`salesPersonClient__`; +DROP TABLE IF EXISTS `bs`.`workerSpeed__`; +DROP TABLE IF EXISTS `bs`.`zone_ETD__`; + +DROP TABLE IF EXISTS `edi`.`ektEntryAssign__`; + +DROP TABLE IF EXISTS `postgresql`.`bank_account__`; +DROP TABLE IF EXISTS `postgresql`.`bank_bic__`; +DROP TABLE IF EXISTS `postgresql`.`business__`; +DROP TABLE IF EXISTS `postgresql`.`business_labour__`; +DROP TABLE IF EXISTS `postgresql`.`business_labour_payroll__`; +DROP TABLE IF EXISTS `postgresql`.`calendar_labour__`; +DROP TABLE IF EXISTS `postgresql`.`calendar_free__`; +DROP TABLE IF EXISTS `postgresql`.`calendar_labour_legend__`; + +ALTER TABLE IF EXISTS `postgresql`.`province` + DROP INDEX IF EXISTS `province_nation_id_idx` ; + +DROP TABLE IF EXISTS `postgresql`.`nation__`; +DROP TABLE IF EXISTS `postgresql`.`currency__`; +DROP TABLE IF EXISTS `postgresql`.`periodos__`; +DROP TABLE IF EXISTS `postgresql`.`person__`; + +ALTER TABLE IF EXISTS `postgresql`.`profile__` + DROP INDEX IF EXISTS `profile_workerFk_idx` ; + +ALTER TABLE IF EXISTS `postgresql`.`profile_media` + DROP INDEX IF EXISTS `profile_media_profile_id_idx` ; + +DROP TABLE IF EXISTS `postgresql`.`profile__`; +DROP TABLE IF EXISTS `postgresql`.`workcenter__`; +DROP TABLE IF EXISTS `postgresql`.`workerTimeControlConfig__`; + +DROP TABLE IF EXISTS `vn`.`activeContrat__`; +DROP TABLE IF EXISTS `vn`.`autonomousRegion__`; +DROP TABLE IF EXISTS `vn`.`config__`; +DROP TABLE IF EXISTS `vn`.`entrySplit__`; +DROP TABLE IF EXISTS `vn`.`errorProduction__`; +DROP TABLE IF EXISTS `vn`.`expence__`; +DROP TABLE IF EXISTS `vn`.`floramondoNotOfferDay__`; +DROP TABLE IF EXISTS `vn`.`glsExpedition__`; +DROP TABLE IF EXISTS `vn`.`invoiceInIntrastat__`; +DROP TABLE IF EXISTS `vn`.`itemConversor__`; +DROP TABLE IF EXISTS `vn`.`itemPlacement__`; +DROP TABLE IF EXISTS `vn`.`itemRepo__`; +DROP TABLE IF EXISTS `vn`.`itemVerdecora__`; + +ALTER TABLE IF EXISTS `vn`.`person__` +DROP INDEX IF EXISTS `workerFk_idx` ; + +DROP TABLE IF EXISTS `vn`.`person__`; + +DROP TABLE IF EXISTS `vn`.`printServerQueue2__`; +DROP TABLE IF EXISTS `vn`.`printServerQueue__`; +DROP TABLE IF EXISTS `vn`.`routeGate__`; +DROP TABLE IF EXISTS `vn`.`saleItemShelving__`; +DROP TABLE IF EXISTS `vn`.`saleParking__`; +DROP TABLE IF EXISTS `vn`.`workerConfig__`; +DROP TABLE IF EXISTS `vn`.`zonePromo__`; +DROP VIEW IF EXISTS `vn`.`returnBuckets__`; + +DROP TABLE IF EXISTS `vn2008`.`accumulatorsReadingDate__`; +DROP TABLE IF EXISTS `vn2008`.`Agencias_dits__`; +DROP TABLE IF EXISTS `vn2008`.`Articles_dits__`; +DROP TABLE IF EXISTS `vn2008`.`awb_cargo__`; +DROP TABLE IF EXISTS `vn2008`.`awb_coordinacion__`; +DROP TABLE IF EXISTS `vn2008`.`business_labour_payrroll__`; +DROP TABLE IF EXISTS `vn2008`.`Clientes_cedidos__`; +DROP TABLE IF EXISTS `vn2008`.`clientes_regalos_enc__`; +DROP TABLE IF EXISTS `vn2008`.`clientes_regalos_lista_enc__`; +DROP TABLE IF EXISTS `vn2008`.`Compres_mark__`; +DROP TABLE IF EXISTS `vn2008`.`config_host__`; +DROP TABLE IF EXISTS `vn2008`.`Contactos__`; +DROP TABLE IF EXISTS `vn2008`.`equipos__`; +DROP TABLE IF EXISTS `vn2008`.`Extractos__`; +DROP TABLE IF EXISTS `vn2008`.`Impresoras__`; +DROP TABLE IF EXISTS `vn2008`.`log_articles__`; + + +ALTER TABLE IF EXISTS `vn`.`contratos_subvencion_270619` + DROP INDEX IF EXISTS `contratos_subvencion_270619_fk3_idx` ; + +DROP TABLE IF EXISTS `vn2008`.`payroll_contratos__`; + +DROP TABLE IF EXISTS `vn2008`.`payroll_pagarini__`; +DROP TABLE IF EXISTS `vn2008`.`payroll_pais__`; +DROP TABLE IF EXISTS `vn2008`.`printServerQueue2__`; +DROP TABLE IF EXISTS `vn2008`.`profile_labour_payroll__`; +DROP TABLE IF EXISTS `vn2008`.`Relaciones__`; +DROP TABLE IF EXISTS `vn2008`.`ruta_location__`; +DROP TABLE IF EXISTS `vn2008`.`Rutas_dits__`; +DROP TABLE IF EXISTS `vn2008`.`Rutas_monitor__`; +DROP TABLE IF EXISTS `vn2008`.`Stockcontrol__`; +DROP TABLE IF EXISTS `vn2008`.`Tickets_dits__`; +DROP TABLE IF EXISTS `vn2008`.`travel_dits__`; +DROP TABLE IF EXISTS `vn2008`.`versiones__`; + +DROP TABLE IF EXISTS `geo`.`autonomias`; +DROP TABLE IF EXISTS `geo`.`postalcodes`; +DROP TABLE IF EXISTS `geo`.`vn_rutas`; +DROP VIEW IF EXISTS `geo`.`table_list`; +DROP DATABASE IF EXISTS `geo`; + +DROP TABLE IF EXISTS `nst`.`balance`; +DROP TABLE IF EXISTS `nst`.`geo`; +DROP TABLE IF EXISTS `nst`.`labourTree`; +DROP TABLE IF EXISTS `nst`.`nst`; +DROP DATABASE IF EXISTS `nst`; \ No newline at end of file diff --git a/db/versions/.archive/10370-pinkBirch/03-accion.sql b/db/versions/.archive/10370-pinkBirch/03-accion.sql new file mode 100644 index 000000000..51df27fcc --- /dev/null +++ b/db/versions/.archive/10370-pinkBirch/03-accion.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vncontrol`.`accion` RENAME `vn`.`ticketTrackingState`; + +-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Rename columns + +ALTER TABLE `vn`.`ticketTrackingState` +CHANGE COLUMN `accion_id` `id` int(11) NOT NULL AUTO_INCREMENT, +CHANGE COLUMN `accion` `action` varchar(15) COLLATE utf8mb3_unicode_ci NOT NULL; + diff --git a/db/versions/.archive/10370-pinkBirch/04-inter.sql b/db/versions/.archive/10370-pinkBirch/04-inter.sql new file mode 100644 index 000000000..124acc4cf --- /dev/null +++ b/db/versions/.archive/10370-pinkBirch/04-inter.sql @@ -0,0 +1,35 @@ +RENAME TABLE `vn`.`ticketTracking` TO `vn`.`ticketTracking__`; + +DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_beforeInsert`; +DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_afterInsert`; +DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_afterUpdate`; +DROP TRIGGER IF EXISTS `vncontrol`.`ticketTracking_afterDelete`; + + +ALTER TABLE `vncontrol`.`inter` RENAME `vn`.`ticketTracking`; + +ALTER TABLE vn.ticketTracking CHANGE nota notes varchar(255) DEFAULT NULL NULL; +ALTER TABLE vn.ticketTracking CHANGE inter_id id int(11) auto_increment NOT NULL; +ALTER TABLE vn.ticketTracking CHANGE state_id stateFk tinyint(3) unsigned NOT NULL; +ALTER TABLE vn.ticketTracking CHANGE fallo_id failFk int(10) unsigned DEFAULT 21 NOT NULL; +ALTER TABLE vn.ticketTracking CHANGE odbc_date created timestamp DEFAULT current_timestamp() NULL; +ALTER TABLE vn.ticketTracking CHANGE Id_Ticket ticketFk int(11) DEFAULT NULL NULL; +ALTER TABLE vn.ticketTracking CHANGE Id_Trabajador workerFk int(11) DEFAULT NULL NULL; +ALTER TABLE vn.ticketTracking CHANGE Id_Supervisor supervisorFk int(10) unsigned DEFAULT NULL NULL; + +CREATE + ALGORITHM = UNDEFINED + DEFINER = `root`@`localhost` + SQL SECURITY DEFINER +VIEW `vncontrol`.`inter` AS + SELECT + `tt`.`id` AS `inter_id`, + `tt`.`stateFk` AS `state_id`, + `tt`.`failFk` AS `fallo_id`, + `tt`.`notes` AS `nota`, + `tt`.`created` AS `odbc_date`, + `tt`.`ticketFk` AS `Id_Ticket`, + `tt`.`workerFk` AS `Id_Trabajador`, + `tt`.`supervisorFk` AS `Id_Supervisor` + FROM + `vn`.`ticketTracking` `tt`; \ No newline at end of file diff --git a/db/versions/.archive/10371-crimsonChico/00-firstScript.sql b/db/versions/.archive/10371-crimsonChico/00-firstScript.sql new file mode 100644 index 000000000..608576c2c --- /dev/null +++ b/db/versions/.archive/10371-crimsonChico/00-firstScript.sql @@ -0,0 +1,47 @@ +use vn; +-- Crear columna en deviceProduction +ALTER TABLE vn.deviceProduction ADD stateFk varchar(50) DEFAULT 'idle'; +-- Crear columna en deviceLog +ALTER TABLE vn.deviceLog ADD deviceProductionFk INT(10) NULL; +-- vn.deviceProductionLog definition +CREATE TABLE `deviceProductionLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `deviceProduction` int(10) unsigned NOT NULL, + `action` set('insert','update','delete','retired') COLLATE utf8mb3_unicode_ci NOT NULL, + `created` timestamp NULL DEFAULT current_timestamp(), + `oldInstance` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `newInstance` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `changedModel` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, + `changedModelId` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +-- Preguntar sobre elimnar estos campos +ALTER TABLE vn.deviceProduction DROP FOREIGN KEY departmentFgn; +ALTER TABLE vn.deviceProduction DROP COLUMN departmentFk; +ALTER TABLE vn.deviceProduction DROP COLUMN isOutOfService; +-- Crear tabla +CREATE TABLE vn.deviceProductionState ( + code varchar(50) NOT NULL, + description varchar(50) NOT NULL, + CONSTRAINT deviceProductionState_PK PRIMARY KEY (code) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; +-- Rellenar tabla +INSERT INTO vn.deviceProductionState +(code, description) +VALUES('idle', 'inactivo'); +INSERT INTO vn.deviceProductionState +(code, description) +VALUES('active', 'activo'); +INSERT INTO vn.deviceProductionState +(code, description) +VALUES('maintenance', 'mantenimiento'); +INSERT INTO vn.deviceProductionState +(code, description) +VALUES('retired', 'retirada'); +-- FK deviceProductionStateFk +ALTER TABLE vn.deviceProduction ADD CONSTRAINT deviceProduction_FK FOREIGN KEY (stateFk) REFERENCES vn.deviceProductionState(code); \ No newline at end of file diff --git a/db/versions/.archive/10372-grayIvy/00-firstScript.sql b/db/versions/.archive/10372-grayIvy/00-firstScript.sql new file mode 100644 index 000000000..0a4b962f2 --- /dev/null +++ b/db/versions/.archive/10372-grayIvy/00-firstScript.sql @@ -0,0 +1,15 @@ +USE bs; + +ALTER TABLE bs.salesMonthlySnapshot + COMMENT = '@deprecated 2022-11' , + RENAME TO bs.salesMonthlySnapshot___ ; + +ALTER TABLE bs.salesPerson + COMMENT = '@deprecated 2022-11' , + RENAME TO bs.salesPerson__ ; + +ALTER TABLE bs.vendedores_evolution + COMMENT = '@deprecated 2022-11' , + RENAME TO bs.vendedores_evolution__ ; + +TRUNCATE bs.salesPersonEvolution; \ No newline at end of file diff --git a/db/versions/.archive/10373-salmonHydrangea/00-firstScript.sql b/db/versions/.archive/10373-salmonHydrangea/00-firstScript.sql new file mode 100644 index 000000000..4c78fb783 --- /dev/null +++ b/db/versions/.archive/10373-salmonHydrangea/00-firstScript.sql @@ -0,0 +1,30 @@ +CREATE TABLE vn.expeditionMistakeType ( + code VARCHAR(15) NOT NULL, + description varchar(45) NOT NULL, + CONSTRAINT packagingTypeMistake_PK PRIMARY KEY (code) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + + +CREATE TABLE vn.expeditionMistake ( + expeditionFk INT NOT NULL, + workerFk INT(10) unsigned NOT NULL COMMENT 'Quien marca el error', + typeFk VARCHAR(15) NOT NULL, + created TIMESTAMP DEFAULT current_timestamp() NOT NULL, + CONSTRAINT expeditionMistake_PK PRIMARY KEY (expeditionFk ), + CONSTRAINT expeditionMistake_FK FOREIGN KEY (expeditionFk) REFERENCES vn.expedition(id) ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT expeditionMistake_FK_1 FOREIGN KEY (workerfk) REFERENCES vn.worker(id) ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT expeditionMistake_FK_2 FOREIGN KEY (typeFk) REFERENCES vn.expeditionMistakeType(code) ON DELETE RESTRICT ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci +COMMENT='Errores de encajadores'; + +INSERT INTO vn.expeditionMistakeType (code, description) VALUES('bpc', 'Mal encajado'); +INSERT INTO vn.expeditionMistakeType (code, description) VALUES('mex', 'Mezcla de pedidos'); + +INSERT INTO vn.silexACL ( module, `method`, `role`) VALUES( 'almacennew', 'expeditionMistakeType_get', 'employee'); +INSERT INTO vn.silexACL ( module, `method`, `role`) VALUES( 'almacennew', 'expeditionMistake_add', 'employee'); \ No newline at end of file diff --git a/db/versions/.archive/10378-blueCarnation/00-rename_routeUserPercentage.sql b/db/versions/.archive/10378-blueCarnation/00-rename_routeUserPercentage.sql new file mode 100644 index 000000000..327b35625 --- /dev/null +++ b/db/versions/.archive/10378-blueCarnation/00-rename_routeUserPercentage.sql @@ -0,0 +1 @@ +RENAME TABLE vn.routeUserPercentage TO vn.routeUserPercentage__; \ No newline at end of file diff --git a/db/versions/.archive/10382-4777itemShelvingPAK/00-firstScript.sql b/db/versions/.archive/10382-4777itemShelvingPAK/00-firstScript.sql new file mode 100644 index 000000000..9d2d25be6 --- /dev/null +++ b/db/versions/.archive/10382-4777itemShelvingPAK/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.itemShelving ADD IF NOT EXISTS isChecked bool NULL COMMENT 'Este valor cambia al escanear un carro. True: Existe. False: Nuevo. Null: No escaneado'; diff --git a/db/versions/.archive/10383-navyBirch/00-firstScript.sql b/db/versions/.archive/10383-navyBirch/00-firstScript.sql new file mode 100644 index 000000000..9e128aa5b --- /dev/null +++ b/db/versions/.archive/10383-navyBirch/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.clientConfig ADD riskScope INT DEFAULT 2 NOT NULL COMMENT 'Time range in months to calculating a customer''s risk'; diff --git a/db/versions/.archive/10385-chocolateMonstera/00-firstScript.sql b/db/versions/.archive/10385-chocolateMonstera/00-firstScript.sql new file mode 100644 index 000000000..60adcb429 --- /dev/null +++ b/db/versions/.archive/10385-chocolateMonstera/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.report ADD `method` varchar(255) DEFAULT NULL NULL COMMENT 'Salix method'; +UPDATE vn.report SET `method` = 'Tickets/{id}/collection-label' WHERE `name` = 'LabelCollection'; diff --git a/db/versions/.archive/10386-tealTulip/00-firstScript.sql b/db/versions/.archive/10386-tealTulip/00-firstScript.sql new file mode 100644 index 000000000..be41a4a2d --- /dev/null +++ b/db/versions/.archive/10386-tealTulip/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +USE vn; +INSERT INTO vn.silexACL +( module, `method`, `role`) +VALUES( 'almacennew', 'itemShelving_addList', 'employee'); diff --git a/db/versions/.archive/10387-wheatRuscus/00-firstScript.sql b/db/versions/.archive/10387-wheatRuscus/00-firstScript.sql new file mode 100644 index 000000000..3686138b0 --- /dev/null +++ b/db/versions/.archive/10387-wheatRuscus/00-firstScript.sql @@ -0,0 +1,18 @@ +USE vn; + +ALTER TABLE `vn`.`routeAction` + ADD COLUMN `isMainlineDelivered` TINYINT NOT NULL DEFAULT 0 AFTER `price`; + +ALTER TABLE `vn`.`routeConfig` + ADD COLUMN `truckerBusinessProfessionalCategoryFk` INT NOT NULL DEFAULT 42 AFTER `kmMax`; + +UPDATE vn.routeCommission rc + JOIN (SELECT rc.routeFk, r.m3 + FROM routeCommission rc + JOIN vn.route r ON r.id = rc.routeFk + WHERE (cat4m3 IS NULL OR cat5m3 IS NULL) + AND r.m3 IS NOT NULL)sub ON sub.routeFk = rc.routeFk + JOIN routeConfig rcon + SET rc.m3 = sub.m3, + rc.cat4m3 = sub.m3 * rcon.distributionCat4M3, + rc.cat5m3 = sub.m3 * rcon.distributionCat5M3; \ No newline at end of file diff --git a/db/versions/.archive/10388-bronzePaniculata/00-resizeUtilVerionLogCode.sql b/db/versions/.archive/10388-bronzePaniculata/00-resizeUtilVerionLogCode.sql new file mode 100644 index 000000000..4b9b5faa1 --- /dev/null +++ b/db/versions/.archive/10388-bronzePaniculata/00-resizeUtilVerionLogCode.sql @@ -0,0 +1 @@ +ALTER TABLE util.versionLog MODIFY COLUMN code varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10388-bronzePaniculata/01-resizeUtilVersionCode.sql b/db/versions/.archive/10388-bronzePaniculata/01-resizeUtilVersionCode.sql new file mode 100644 index 000000000..208e5aa7b --- /dev/null +++ b/db/versions/.archive/10388-bronzePaniculata/01-resizeUtilVersionCode.sql @@ -0,0 +1 @@ +ALTER TABLE util.version MODIFY COLUMN code varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/.archive/10390-chocolateAnthurium/00-firstScript.sql b/db/versions/.archive/10390-chocolateAnthurium/00-firstScript.sql new file mode 100644 index 000000000..0a00fdd0e --- /dev/null +++ b/db/versions/.archive/10390-chocolateAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +UPDATE vn.sale SET price = 0 WHERE price IS NULL; +ALTER TABLE vn.sale MODIFY COLUMN price decimal(10,2) DEFAULT 0 NOT NULL; diff --git a/db/versions/.archive/10391-orangeCyca/00-firstScript.sql b/db/versions/.archive/10391-orangeCyca/00-firstScript.sql new file mode 100644 index 000000000..c761cd08d --- /dev/null +++ b/db/versions/.archive/10391-orangeCyca/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +use vn; + +CREATE OR REPLACE TABLE `auctionConfig` ( + `conversionCoefficient` double NOT NULL DEFAULT 1 COMMENT 'value used to calculate the used space of an item in a container', + `warehosueFk` smallint(6) unsigned NOT NULL DEFAULT 7 COMMENT 'default warehouse used for the calculation', + KEY `auctionConfig_FK` (`warehosueFk`), + CONSTRAINT `auctionConfig_FK` FOREIGN KEY (`warehosueFk`) REFERENCES `warehouse` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/.archive/10394-brownHydrangea/00-firstScript.sql b/db/versions/.archive/10394-brownHydrangea/00-firstScript.sql new file mode 100644 index 000000000..0e888db5f --- /dev/null +++ b/db/versions/.archive/10394-brownHydrangea/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.workerJourney DROP FOREIGN KEY workerJourney_businessFk; +ALTER TABLE vn.workerJourney ADD CONSTRAINT workerJourney_businessFk FOREIGN KEY (businessFk) REFERENCES vn.business(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10193-navyHydrangea/00-delete.sql b/db/versions/10193-navyHydrangea/00-delete.sql new file mode 100644 index 000000000..23d8ee4e7 --- /dev/null +++ b/db/versions/10193-navyHydrangea/00-delete.sql @@ -0,0 +1,46 @@ +use vn; +-- Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values. +DELETE FROM vn.taxClassCode + WHERE taxClassFk=1 AND effectived='2014-01-01' AND taxCodeFk=108; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=2 AND effectived='2014-01-01' AND taxCodeFk=108; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=3 AND effectived='2014-01-01' AND taxCodeFk=108; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=5 AND effectived='2014-01-01' AND taxCodeFk=108; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=3 AND effectived='2016-01-01' AND taxCodeFk=109; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=5 AND effectived='2016-01-01' AND taxCodeFk=109; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=1 AND effectived='2019-01-01' AND taxCodeFk=122; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=2 AND effectived='2019-01-01' AND taxCodeFk=122; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=3 AND effectived='2019-01-01' AND taxCodeFk=122; +DELETE FROM vn.taxClassCode + WHERE taxClassFk=5 AND effectived='2019-01-01' AND taxCodeFk=122; +-- Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values. +DELETE FROM vn.taxCode + WHERE id=108; +DELETE FROM vn.taxCode + WHERE id=109; +DELETE FROM vn.taxCode + WHERE id=110; +DELETE FROM vn.taxCode + WHERE id=122; +-- Auto-generated SQL script. Actual values for binary/complex data types may differ - what you see is the default string representation of values. +DELETE FROM vn.bookingPlanner + WHERE countryFk = 30; + +DELETE FROM vn.botanicExport where restriction = 'Importacion Prohibida'; + +DELETE FROM vn.itemTaxCountry WHERE countryFk = 30; +DELETE FROM vn.botanicExport WHERE countryFk = 30; +UPDATE vn.client SET countryFk = 1 WHERE countryFk = 30; +UPDATE vn.supplier SET countryFk = 1 WHERE countryFk = 30; +UPDATE province SET countryFk = 1 WHERE countryFk = 30; +UPDATE autonomy SET countryFk = 1 WHERE countryFk = 30; +DELETE FROM vn.taxCode WHERE taxTypeFk = 24; +DELETE FROM vn.taxClassCode WHERE taxCodeFk IN (108, 109,110,122); +DELETE FROM vn.country WHERE code = 'EX'; \ No newline at end of file diff --git a/db/versions/10193-navyHydrangea/01-botanicExport.sql b/db/versions/10193-navyHydrangea/01-botanicExport.sql new file mode 100644 index 000000000..f36f7fa9b --- /dev/null +++ b/db/versions/10193-navyHydrangea/01-botanicExport.sql @@ -0,0 +1 @@ +ALTER TABLE vn.botanicExport CHANGE countryFk countryFk__ mediumint(8) unsigned DEFAULT NULL NULL; diff --git a/db/versions/10193-navyHydrangea/02-item.sql b/db/versions/10193-navyHydrangea/02-item.sql new file mode 100644 index 000000000..8694e6d15 --- /dev/null +++ b/db/versions/10193-navyHydrangea/02-item.sql @@ -0,0 +1 @@ +ALTER TABLE vn.item MODIFY COLUMN comment varchar(150) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'referencia del proveedor'; diff --git a/db/versions/10193-navyHydrangea/03-autonomy.sql b/db/versions/10193-navyHydrangea/03-autonomy.sql new file mode 100644 index 000000000..32771ef05 --- /dev/null +++ b/db/versions/10193-navyHydrangea/03-autonomy.sql @@ -0,0 +1,17 @@ +ALTER TABLE vn.autonomy ADD isUeeMember BOOL DEFAULT NULL NULL; +ALTER TABLE vn.autonomy ADD hasDailyInvoice tinyint(4) DEFAULT NULL; + +UPDATE vn.autonomy + SET isUeeMember = FALSE, + hasDailyInvoice = TRUE + WHERE name = 'Canarias'; + +UPDATE vn.autonomy + SET isUeeMember = FALSE, + hasDailyInvoice = TRUE + WHERE name = 'Ciudad de Ceuta'; + +UPDATE vn.autonomy + SET isUeeMember = FALSE, + hasDailyInvoice = TRUE + WHERE name = 'Ciudad de Melilla'; diff --git a/db/versions/10193-navyHydrangea/03-turn.sql b/db/versions/10193-navyHydrangea/03-turn.sql new file mode 100644 index 000000000..eb48cbdea --- /dev/null +++ b/db/versions/10193-navyHydrangea/03-turn.sql @@ -0,0 +1 @@ +RENAME TABLE vn2008.turn TO vn2008.turn__; diff --git a/db/versions/10193-navyHydrangea/04-country.sql b/db/versions/10193-navyHydrangea/04-country.sql new file mode 100644 index 000000000..fe57cf1b0 --- /dev/null +++ b/db/versions/10193-navyHydrangea/04-country.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.country CHANGE politicalCountryFk politicalCountryFk__ mediumint(8) unsigned NULL + COMMENT 'Pais Real(apaño por culpa del España Exento)'; \ No newline at end of file diff --git a/db/versions/10379-turquoiseOrchid/00-firstScript.sql b/db/versions/10379-turquoiseOrchid/00-firstScript.sql new file mode 100644 index 000000000..f77733ba5 --- /dev/null +++ b/db/versions/10379-turquoiseOrchid/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here +USE vn; + +ALTER TABLE vn.ticketConfig ADD packingDelay int(11) DEFAULT 1 NULL COMMENT 'Horas que marcará el retraso respecto hora de cierre web del ticket'; + +INSERT INTO vn.silexACL +(module, `method`, `role`) +VALUES( 'almacennew', 'ticket_isOutClosureZone', 'employee'); \ No newline at end of file diff --git a/db/versions/10384-limeLaurel/00-business_workcenterFk.sql b/db/versions/10384-limeLaurel/00-business_workcenterFk.sql new file mode 100644 index 000000000..036092b46 --- /dev/null +++ b/db/versions/10384-limeLaurel/00-business_workcenterFk.sql @@ -0,0 +1,15 @@ +ALTER TABLE `vn`.`business` MODIFY COLUMN workcenterFk int(11) NULL; + +UPDATE `vn`.`business` b + SET b.workcenterFk = NULL + WHERE b.workcenterFk = 0; + +ALTER TABLE `vn`.`business` + ADD INDEX IF NOT EXISTS `business_workcenterFk_idx` (`workcenterFk` ASC); + +ALTER TABLE `vn`.`business` + ADD CONSTRAINT `business_workcenterFk` + FOREIGN KEY IF NOT EXISTS (`workcenterFk`) + REFERENCES `vn`.`workCenter` (`id`) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/db/versions/10395-blueGalax/00-firstScript.sql b/db/versions/10395-blueGalax/00-firstScript.sql new file mode 100644 index 000000000..c6c666144 --- /dev/null +++ b/db/versions/10395-blueGalax/00-firstScript.sql @@ -0,0 +1,2 @@ +UPDATE vn.client SET businessTypeFk = 'florist' WHERE businessTypeFk IS NULL; +ALTER TABLE vn.client MODIFY COLUMN businessTypeFk varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'florist' NOT NULL; diff --git a/db/versions/10396-grayRoebelini/00-firstScript.sql b/db/versions/10396-grayRoebelini/00-firstScript.sql new file mode 100644 index 000000000..43eb6d38d --- /dev/null +++ b/db/versions/10396-grayRoebelini/00-firstScript.sql @@ -0,0 +1,5 @@ +USE vn; + +ALTER TABLE `vn`.`workCenter` + ADD COLUMN `deliveryManAdjustment` DECIMAL(4,2) NULL DEFAULT NULL + COMMENT 'Número de trabajadores para equilibrar los repartidores de diferentes centros. Utilizado en repartidores de grafana' AFTER `geoFk`; diff --git a/db/versions/10397-4848TicketsFloramondo/00-firstScript.sql b/db/versions/10397-4848TicketsFloramondo/00-firstScript.sql new file mode 100644 index 000000000..098330da8 --- /dev/null +++ b/db/versions/10397-4848TicketsFloramondo/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +ALTER TABLE vn.ektEntryAssign MODIFY COLUMN warehouseInFk int(11) NOT NULL; +ALTER TABLE vn.ektEntryAssign MODIFY COLUMN agencyModeFk int(11) NOT NULL; +ALTER TABLE vn.ektEntryAssign MODIFY COLUMN warehouseOutFk int(11) NOT NULL; +ALTER TABLE vn.ektEntryAssign MODIFY COLUMN supplierFk int(11) NOT NULL; diff --git a/db/versions/10399-blueErica/00-firstScript.sql b/db/versions/10399-blueErica/00-firstScript.sql new file mode 100644 index 000000000..d9992443f --- /dev/null +++ b/db/versions/10399-blueErica/00-firstScript.sql @@ -0,0 +1,5 @@ +USE vn; + +UPDATE vn.buy b + JOIN vn.entryConfig e ON e.defaultEntry = b.entryFk + SET b.printedStickers = 0; \ No newline at end of file diff --git a/db/versions/10400-brownEucalyptus/00-firstScript.sql b/db/versions/10400-brownEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..ed315d9f4 --- /dev/null +++ b/db/versions/10400-brownEucalyptus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.itemCleanLog DROP COLUMN itemFrom; +DROP TABLE vn.itemCleanConfig; diff --git a/db/versions/10402-orangeTulip/00-firstScript.sql b/db/versions/10402-orangeTulip/00-firstScript.sql new file mode 100644 index 000000000..90f61183d --- /dev/null +++ b/db/versions/10402-orangeTulip/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE vn.workerJourney DROP FOREIGN KEY workerJourney_businessFk; +ALTER TABLE vn.workerJourney ADD CONSTRAINT workerJourney_businessFk FOREIGN KEY (businessFk) REFERENCES vn.business(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.calendar DROP FOREIGN KEY calendar_businessFk; +ALTER TABLE vn.calendar ADD CONSTRAINT calendar_businessFk FOREIGN KEY (businessFk) REFERENCES vn.business(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10404-grayMedeola/00-firstScript.sql b/db/versions/10404-grayMedeola/00-firstScript.sql new file mode 100644 index 000000000..c1f5461b0 --- /dev/null +++ b/db/versions/10404-grayMedeola/00-firstScript.sql @@ -0,0 +1,2 @@ +USE vn; +ALTER TABLE vn.calendar ADD CONSTRAINT calendar_UN UNIQUE KEY (businessFk,dated); diff --git a/db/versions/10405-orangeGalax/00-firstScript.sql b/db/versions/10405-orangeGalax/00-firstScript.sql new file mode 100644 index 000000000..b4eb7425c --- /dev/null +++ b/db/versions/10405-orangeGalax/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.property ADD purchased DATE DEFAULT util.CURDATE() NOT NULL COMMENT 'date of purchase of the property'; +ALTER TABLE vn.property ADD booked DATE NULL COMMENT 'date of completion of property registration'; diff --git a/db/versions/10407-blueOak/00-firstScript.sql b/db/versions/10407-blueOak/00-firstScript.sql new file mode 100644 index 000000000..478258d8a --- /dev/null +++ b/db/versions/10407-blueOak/00-firstScript.sql @@ -0,0 +1,5 @@ +use vn; +CREATE TABLE `supplierDebtConfig` ( + `dated` DATE NOT NULL DEFAULT '2014-12-31' COMMENT 'date from which we start counting', + `invalidBalances` DOUBLE NOT NULL DEFAULT 0.5 COMMENT 'balances not to be paid' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10408-purpleIvy/00-firstScript.sql b/db/versions/10408-purpleIvy/00-firstScript.sql new file mode 100644 index 000000000..a564b70aa --- /dev/null +++ b/db/versions/10408-purpleIvy/00-firstScript.sql @@ -0,0 +1,31 @@ +CREATE TABLE IF NOT EXISTS vn.roadmap ( + id int(10) unsigned auto_increment NOT NULL, + tractorPlate varchar(10) DEFAULT NULL NULL, + trailerPlate varchar(12) DEFAULT NULL NULL, + phone varchar(15) DEFAULT NULL NULL, + supplierFk int(11) DEFAULT NULL NULL, + etd datetime DEFAULT NULL NULL, + observations varchar(255) DEFAULT NULL NULL, + created timestamp DEFAULT current_timestamp() NULL, + userFk int(10) unsigned DEFAULT NULL NULL, + CONSTRAINT PRIMARY KEY (id), + + FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE, + FOREIGN KEY (userFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.expeditionTruck ADD IF NOT EXISTS roadmapFk int(10) unsigned NULL, + ADD IF NOT EXISTS warehouseFk smallint(6) unsigned NULL, + ADD IF NOT EXISTS created timestamp DEFAULT current_timestamp() NULL, + ADD IF NOT EXISTS userFk int(10) unsigned NULL, + CHANGE roadmapFk roadmapFk int(10) unsigned NULL AFTER id, + CHANGE warehouseFk warehouseFk smallint(6) unsigned NULL AFTER roadmapFk; + +ALTER TABLE vn.expeditionTruck ADD CONSTRAINT expeditionTruck_FK_1 FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE, + ADD CONSTRAINT expeditionTruck_FK_2 FOREIGN KEY (roadmapFk) REFERENCES vn.roadmap(id) ON DELETE RESTRICT ON UPDATE CASCADE, + ADD CONSTRAINT expeditionTruck_FK_3 FOREIGN KEY (userFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +ALTER TABLE vn.warehouse ADD IF NOT EXISTS isHalt tinyint(1) DEFAULT 0 NOT NULL COMMENT 'Almacén en el que descargan nuestros troncales'; diff --git a/db/versions/10409-brownSalal/00-firstScript.sql b/db/versions/10409-brownSalal/00-firstScript.sql new file mode 100644 index 000000000..8373aa3d1 --- /dev/null +++ b/db/versions/10409-brownSalal/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE `vn`.`itemType` CHANGE `transaction` transaction__ tinyint(4) DEFAULT 0 NOT NULL; +ALTER TABLE `vn`.`itemType` CHANGE location location__ varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; +ALTER TABLE `vn`.`itemType` CHANGE hasComponents hasComponents__ tinyint(1) DEFAULT 1 NOT NULL; +ALTER TABLE `vn`.`itemType` CHANGE warehouseFk warehouseFk__ smallint(6) unsigned DEFAULT 60 NOT NULL; +ALTER TABLE `vn`.`itemType` CHANGE compression compression__ decimal(5,2) DEFAULT 1.00 NULL; diff --git a/db/.archive/224702/00-zipConfig.sql b/db/versions/10412-yellowCarnation/00-firstScript.sql similarity index 53% rename from db/.archive/224702/00-zipConfig.sql rename to db/versions/10412-yellowCarnation/00-firstScript.sql index 134ce7770..a3c41b527 100644 --- a/db/.archive/224702/00-zipConfig.sql +++ b/db/versions/10412-yellowCarnation/00-firstScript.sql @@ -3,7 +3,3 @@ CREATE TABLE `vn`.`zipConfig` ( `maxSize` int(11) DEFAULT NULL COMMENT 'in MegaBytes', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ZipConfig', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/versions/10413-whiteCymbidium/00-firstScript.sql b/db/versions/10413-whiteCymbidium/00-firstScript.sql new file mode 100644 index 000000000..bd382fdf7 --- /dev/null +++ b/db/versions/10413-whiteCymbidium/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`referenceCurrent` +CHANGE COLUMN `dated` `dated` DATE NOT NULL DEFAULT CURRENT_TIMESTAMP(); \ No newline at end of file diff --git a/db/versions/10416-blueAsparagus/00-firstScript.sql b/db/versions/10416-blueAsparagus/00-firstScript.sql new file mode 100644 index 000000000..f96145156 --- /dev/null +++ b/db/versions/10416-blueAsparagus/00-firstScript.sql @@ -0,0 +1,25 @@ +-- Place your SQL code here +ALTER TABLE vn2008.Rutas_Master DROP FOREIGN KEY fk_rutas_warehouse_id; + +ALTER TABLE `vn2008`.`Rutas_Master` RENAME `vn`.`routeMaster`; + +ALTER TABLE `vn`.`routeMaster` +CHANGE COLUMN `warehouse_id` `warehoseFk` SMALLINT(6) unsigned DEFAULT NULL, +CHANGE COLUMN `km` `km` INT(11) NOT NULL DEFAULT 0, +CHANGE COLUMN `bultos` `packages` INT(11) NOT NULL DEFAULT 0, +CHANGE COLUMN `vehiculos_coste` `vehicleCost` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `personal_coste` `staffCost` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `vehiculos_numero` `vehicle` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `personal_numero` `staff` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `gasoil` `fuel` INT(11) NOT NULL DEFAULT 0, +CHANGE COLUMN `autonomos` `freelancers` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `año` `year` INT(11) NOT NULL DEFAULT 0, +CHANGE COLUMN `mes` `mounth` INT(11) NOT NULL DEFAULT 0, +CHANGE COLUMN `gastos` `expense` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `bultos_autonomos` `freelancersPackages` INT(11) NOT NULL DEFAULT 0, +CHANGE COLUMN `coste_km` `kmCost` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `coste_bulto` `packageCost` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `coste_bulto_autonomo` `freelancerPackageCost` DECIMAL(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `odbc_date` `created` TIMESTAMP NULL DEFAULT current_timestamp(); + +ALTER TABLE vn.routeMaster ADD CONSTRAINT routeMaster_FK FOREIGN KEY (warehoseFk) REFERENCES vn.warehouse(id); diff --git a/db/versions/10420-goldenCataractarum/00-firstScript.sql b/db/versions/10420-goldenCataractarum/00-firstScript.sql new file mode 100644 index 000000000..3d36c2737 --- /dev/null +++ b/db/versions/10420-goldenCataractarum/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.printQueue ADD serverId int(10) UNSIGNED NULL COMMENT 'Indica el id del servidor de impresión'; diff --git a/db/versions/10421-navyMonstera/00-firstScript.sql b/db/versions/10421-navyMonstera/00-firstScript.sql new file mode 100644 index 000000000..d097e9b49 --- /dev/null +++ b/db/versions/10421-navyMonstera/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +UPDATE vn.client + SET provinceFk = 1 + WHERE provinceFk IS NULL; + +ALTER TABLE vn.client MODIFY COLUMN provinceFk smallint(5) unsigned NOT NULL; diff --git a/db/versions/10426-silverAsparagus/00-firstScript.sql b/db/versions/10426-silverAsparagus/00-firstScript.sql new file mode 100644 index 000000000..ae7f8c189 --- /dev/null +++ b/db/versions/10426-silverAsparagus/00-firstScript.sql @@ -0,0 +1,7 @@ +USE vn; +ALTER TABLE vn.config + ADD IF NOT EXISTS mainWarehouseFk SMALLINT(6) UNSIGNED DEFAULT 60 NOT NULL; + +ALTER TABLE `vn`.`auctionConfig` + ADD COLUMN `id` INT NOT NULL FIRST, + ADD PRIMARY KEY (`id`); diff --git a/db/versions/10428-wheatRose/00-firstScript.sql b/db/versions/10428-wheatRose/00-firstScript.sql new file mode 100644 index 000000000..bdc3ef085 --- /dev/null +++ b/db/versions/10428-wheatRose/00-firstScript.sql @@ -0,0 +1,14 @@ +USE vn; +CREATE TABLE `mdbVersionTree` ( + `app` varchar(255) COLLATE utf8mb3_unicode_ci NOT NULL, + `version` int(10) unsigned NOT NULL, + `branchFk` varchar(255) COLLATE utf8mb3_unicode_ci NOT NULL, + `fromVersion` int(10) unsigned NOT NULL, + `userFk` int(10) unsigned NOT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`app`,`version`), + KEY `mdbVersionTree_FK` (`userFk`), + KEY `mdbVersionTree_FK_2` (`branchFk`), + CONSTRAINT `mdbVersionTree_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, + CONSTRAINT `mdbVersionTree_FK_2` FOREIGN KEY (`branchFk`) REFERENCES `mdbBranch` (`name`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10431-redCordyline/00-firstScript.sql b/db/versions/10431-redCordyline/00-firstScript.sql new file mode 100644 index 000000000..0847c4ad8 --- /dev/null +++ b/db/versions/10431-redCordyline/00-firstScript.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.workerMana DROP COLUMN minRate; +ALTER TABLE vn.workerMana DROP COLUMN maxRate; + +CREATE TABLE `vn`.`salespersonConfig` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `manaMaxRate` decimal(3,2) DEFAULT 0.05 COMMENT 'Valor máximo a recficar en una línea por el maná de un comercial', + `manaMinRate` decimal(3,2) DEFAULT -0.05 COMMENT 'Valor mínimo a recficar en una línea por el maná de un comercial', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10433-salmonAnthurium/00-firstScript.sql b/db/versions/10433-salmonAnthurium/00-firstScript.sql new file mode 100644 index 000000000..2dd142d68 --- /dev/null +++ b/db/versions/10433-salmonAnthurium/00-firstScript.sql @@ -0,0 +1,3 @@ +UPDATE IGNORE vn.report + SET `method`='Tickets/{collectionOrTicketFk}/collection-label' + WHERE id=28; diff --git a/db/versions/10434-grayTulip/00-firstScript.sql b/db/versions/10434-grayTulip/00-firstScript.sql new file mode 100644 index 000000000..f2f3200a3 --- /dev/null +++ b/db/versions/10434-grayTulip/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.deviceProduction ADD isInScalefusion BOOL DEFAULT 0 NULL COMMENT 'Para saber si esta en Scalefusion'; diff --git a/db/versions/10435-aquaGalax/00-firstScript.sql b/db/versions/10435-aquaGalax/00-firstScript.sql new file mode 100644 index 000000000..3228d1fcb --- /dev/null +++ b/db/versions/10435-aquaGalax/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.mdbApp DROP PRIMARY KEY; +ALTER TABLE vn.mdbApp ADD CONSTRAINT mdbApp_PK PRIMARY KEY (app); diff --git a/db/versions/10436-tealPalmetto/00-createFkWorker.sql b/db/versions/10436-tealPalmetto/00-createFkWorker.sql new file mode 100644 index 000000000..356bb8a90 --- /dev/null +++ b/db/versions/10436-tealPalmetto/00-createFkWorker.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.saleTracking MODIFY COLUMN workerFk int(10) unsigned NOT NULL; +DELETE FROM vn.saleTracking WHERE workerFk = 0; +ALTER TABLE vn.saleTracking ADD CONSTRAINT saleTracking_FK_2 FOREIGN KEY (workerFk) REFERENCES vn.worker(id) ON UPDATE CASCADE; diff --git a/db/versions/10436-tealPalmetto/01-addStateToWorkerProductivity.sql b/db/versions/10436-tealPalmetto/01-addStateToWorkerProductivity.sql new file mode 100644 index 000000000..560de4e73 --- /dev/null +++ b/db/versions/10436-tealPalmetto/01-addStateToWorkerProductivity.sql @@ -0,0 +1,2 @@ +ALTER TABLE bs.workerProductivity ADD stateFk TINYINT UNSIGNED NULL; +ALTER TABLE bs.workerProductivity ADD CONSTRAINT workerProductivity_FK_1 FOREIGN KEY (stateFk) REFERENCES vn.state(id) ON UPDATE CASCADE; diff --git a/db/versions/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql b/db/versions/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql new file mode 100644 index 000000000..d4942ba20 --- /dev/null +++ b/db/versions/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql @@ -0,0 +1 @@ +RENAME TABLE vn.ticketTrackingState TO vn.ticketTrackingState__; \ No newline at end of file diff --git a/db/versions/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql b/db/versions/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql new file mode 100644 index 000000000..c27b48e70 --- /dev/null +++ b/db/versions/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql @@ -0,0 +1 @@ +ALTER TABLE vn.saleTracking CHANGE actionFk actionFk__ int(11) DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10436-tealPalmetto/04-DropSchemaVnControl.sql b/db/versions/10436-tealPalmetto/04-DropSchemaVnControl.sql new file mode 100644 index 000000000..01f9a9853 --- /dev/null +++ b/db/versions/10436-tealPalmetto/04-DropSchemaVnControl.sql @@ -0,0 +1 @@ +DROP SCHEMA IF EXISTS vncontrol; \ No newline at end of file diff --git a/db/versions/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql b/db/versions/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql new file mode 100644 index 000000000..099f02f19 --- /dev/null +++ b/db/versions/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql @@ -0,0 +1,2 @@ +ALTER TABLE bs.workerProductivity DROP FOREIGN KEY workerProductivity_FK; +ALTER TABLE bs.workerProductivity MODIFY COLUMN actionFk int(11) NULL; \ No newline at end of file diff --git a/db/versions/10439-greenTulip/00-fixRole.sql b/db/versions/10439-greenTulip/00-fixRole.sql new file mode 100644 index 000000000..67f802c6f --- /dev/null +++ b/db/versions/10439-greenTulip/00-fixRole.sql @@ -0,0 +1,2 @@ +ALTER TABLE `account`.`role` MODIFY COLUMN name varchar(79) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT 'MariaDB doesn''t support more than 79 chars for proxied user names'; + diff --git a/db/versions/10440-grayDendro/00-firstScript.sql b/db/versions/10440-grayDendro/00-firstScript.sql new file mode 100644 index 000000000..f7069e9a6 --- /dev/null +++ b/db/versions/10440-grayDendro/00-firstScript.sql @@ -0,0 +1,3 @@ + +INSERT INTO hedera.menu (id, description, `path`, roleFk, parentFk, displayOrder) + VALUES (31,'Pending orders','ecomerce/pending',11,2,1); diff --git a/db/versions/10444-crimsonBamboo/00-firstScript.sql b/db/versions/10444-crimsonBamboo/00-firstScript.sql new file mode 100644 index 000000000..aac896046 --- /dev/null +++ b/db/versions/10444-crimsonBamboo/00-firstScript.sql @@ -0,0 +1,7 @@ +-- Place your SQL code here +CREATE TABLE `vn`.`timeControlDevice` ( + `id` INT(10) PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(255) NULL, + `key` VARCHAR(255) NULL, + UNIQUE INDEX `name_UNIQUE` (`name` ASC) VISIBLE); + \ No newline at end of file diff --git a/db/versions/10445-orangeMoss/00-firstScript.sql b/db/versions/10445-orangeMoss/00-firstScript.sql new file mode 100644 index 000000000..d46154aa4 --- /dev/null +++ b/db/versions/10445-orangeMoss/00-firstScript.sql @@ -0,0 +1,27 @@ +USE vn; + +ALTER TABLE vn.itemType MODIFY COLUMN id smallint(5) unsigned NOT NULL; + +-- id drop references +ALTER TABLE vn.item DROP FOREIGN KEY item_ibfk_5; +ALTER TABLE vn.itemTypeRestriction DROP FOREIGN KEY itemTypeRestriction_itemType_id_fk; +ALTER TABLE vn.itemTypeTag DROP FOREIGN KEY itemTypeTagTipos; +ALTER TABLE vn.zoneFilter DROP FOREIGN KEY zoneFilter_FK_1; + +-- code drop references +ALTER TABLE vn.clientItemType DROP FOREIGN KEY clientItemType_FK_1; + +-- drop and add constraint +ALTER TABLE vn.itemType DROP PRIMARY KEY; +ALTER TABLE vn.itemType ADD CONSTRAINT itemType_PK PRIMARY KEY (id); +ALTER TABLE vn.itemType DROP KEY tipo_id_UNIQUE; +ALTER TABLE vn.itemType ADD CONSTRAINT itemType_UN UNIQUE KEY (code); + +-- code add references +ALTER TABLE vn.clientItemType ADD CONSTRAINT clientItemType_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(code); + +-- id add references +ALTER TABLE vn.item ADD CONSTRAINT item_FK_1 FOREIGN KEY (typeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn.itemTypeRestriction ADD CONSTRAINT itemTypeRestriction_FK FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn.itemTypeTag ADD CONSTRAINT itemTypeTag_FK FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn.zoneFilter ADD CONSTRAINT zoneFilter_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id); diff --git a/db/versions/10448-wheatChrysanthemum/00-firstScript.sql b/db/versions/10448-wheatChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..15fb6d339 --- /dev/null +++ b/db/versions/10448-wheatChrysanthemum/00-firstScript.sql @@ -0,0 +1,10 @@ +USE vn; + +ALTER TABLE `vn`.`ticketConfig` + ADD COLUMN `packagingInvoicingDated` DATE NOT NULL DEFAULT '2017-11-21' + COMMENT 'Fecha desde la cual se gestiona el registro de embalajes de tickets (tabla vn.ticketPackaging)' + AFTER `pickingDelay`; + +UPDATE `vn`.`warehouse` + SET `code` = 'inv' + WHERE (`id` = '13'); diff --git a/db/versions/10450-blackIvy/00-firstScript.sql b/db/versions/10450-blackIvy/00-firstScript.sql new file mode 100644 index 000000000..0a6d76580 --- /dev/null +++ b/db/versions/10450-blackIvy/00-firstScript.sql @@ -0,0 +1,7 @@ +USE vn; +CREATE TABLE vn.`arcRead` ( + `id` smallint(2) unsigned NOT NULL AUTO_INCREMENT, + `printerFk` tinyint(3) unsigned, + PRIMARY KEY (`id`), + CONSTRAINT `worker_printer_FK` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10451-salmonOak/00-firstScript.sql b/db/versions/10451-salmonOak/00-firstScript.sql new file mode 100644 index 000000000..1dd38d8c3 --- /dev/null +++ b/db/versions/10451-salmonOak/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.arcRead ADD ip varchar(50) NOT NULL; +ALTER TABLE vn.arcRead ADD counter smallint(2) unsigned DEFAULT NULL NULL COMMENT 'Número de etiquetas leídas del pallet actual por el arco'; +ALTER TABLE vn.arcRead ADD error varchar(50) NULL; +ALTER TABLE vn.arcRead ADD CONSTRAINT arcRead_ip_UN UNIQUE KEY (ip); diff --git a/db/versions/10452-redEucalyptus/00-firstScript.sql b/db/versions/10452-redEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..c7ac09499 --- /dev/null +++ b/db/versions/10452-redEucalyptus/00-firstScript.sql @@ -0,0 +1,13 @@ +CREATE TABLE vn.mdbConfig ( + id int(10) unsigned auto_increment NOT NULL, + issueTrackerUrl varchar(255) NOT NULL, + issueNumberRegex varchar(255) NOT NULL, + CONSTRAINT mdbConfig_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci +COMMENT='Global configuration parameters for Access'; + +INSERT INTO vn.mdbConfig (issueTrackerUrl, issueNumberRegex) + VALUES ('https://cau.verdnatura.es/scp/tickets.php?number={index}','#(\\d+)'); diff --git a/db/versions/10453-aquaMedeola/00-firstScript.sql b/db/versions/10453-aquaMedeola/00-firstScript.sql new file mode 100644 index 000000000..035da0448 --- /dev/null +++ b/db/versions/10453-aquaMedeola/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.mdbVersionTree ADD description text DEFAULT NULL NULL; +ALTER TABLE vn.mdbVersionTree CHANGE description description text DEFAULT NULL NULL AFTER userFk; diff --git a/db/versions/10454-bronzeMoss/00-firstScript.sql b/db/versions/10454-bronzeMoss/00-firstScript.sql new file mode 100644 index 000000000..2b90cb0e0 --- /dev/null +++ b/db/versions/10454-bronzeMoss/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.mdbConfig ADD chatDestionation varchar(255) NOT NULL COMMENT 'User (@) or channel (#) to send the message'; +UPDATE vn.mdbConfig SET chatDestionation='#versiones-access' WHERE id=1; diff --git a/db/versions/10455-blackGerbera/00-firstScript.sql b/db/versions/10455-blackGerbera/00-firstScript.sql new file mode 100644 index 000000000..e7c069bff --- /dev/null +++ b/db/versions/10455-blackGerbera/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.mdbConfig CHANGE chatDestionation chatDestination varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT 'User (@) or channel (#) to send the message'; diff --git a/db/versions/10456-greenArborvitae/00-firstScript.sql b/db/versions/10456-greenArborvitae/00-firstScript.sql new file mode 100644 index 000000000..ffa275f71 --- /dev/null +++ b/db/versions/10456-greenArborvitae/00-firstScript.sql @@ -0,0 +1,2 @@ +USE vn; +ALTER TABLE saleTracking DROP KEY IF EXISTS saleTracking_UN; diff --git a/db/versions/10457-crimsonTulip/00-firstScript.sql b/db/versions/10457-crimsonTulip/00-firstScript.sql new file mode 100644 index 000000000..880bee9d8 --- /dev/null +++ b/db/versions/10457-crimsonTulip/00-firstScript.sql @@ -0,0 +1,17 @@ +USE vn; + +CREATE TEMPORARY TABLE tmp.tt + SELECT MIN(id) id, saleFk, workerFk, stateFk + FROM saleTracking + GROUP BY saleFk, workerFk, stateFk + HAVING COUNT(*) > 1; + +DELETE st FROM saleTracking st + JOIN tmp.tt USING(saleFk, workerFk, stateFk) + WHERE tt.id <> st.id; + +ALTER TABLE saleTracking + ADD CONSTRAINT saleTracking_UN + UNIQUE KEY (saleFk, workerFk, stateFk); + +DROP TEMPORARY TABLE tmp.tt; diff --git a/db/versions/10458-orangePalmetto/00-firstScript.sql b/db/versions/10458-orangePalmetto/00-firstScript.sql new file mode 100644 index 000000000..79f937b10 --- /dev/null +++ b/db/versions/10458-orangePalmetto/00-firstScript.sql @@ -0,0 +1,18 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`XDiario` +DROP COLUMN `BASEIMPO`, +DROP COLUMN `DOCUMENTO`, +DROP COLUMN `DEPARTA`, +DROP COLUMN `ESTADO`, +DROP COLUMN `NCASADO`, +DROP COLUMN `TCASADO`, +DROP COLUMN `TRANS`, +DROP COLUMN `PTAHABER`, +DROP COLUMN `SUCURSAL`, +DROP COLUMN `PTADEBE`, +DROP COLUMN `CODDIVISA`, +DROP COLUMN `IMPAUXME`, +DROP COLUMN `NOCONV`, +DROP COLUMN `NUMEROINV`, +DROP COLUMN `TIPOFAC`, +DROP COLUMN `TIPOIVA`; \ No newline at end of file diff --git a/db/versions/10459-chocolateMedeola/00-alterTableUtilConfig.sql b/db/versions/10459-chocolateMedeola/00-alterTableUtilConfig.sql new file mode 100644 index 000000000..ede4f3315 --- /dev/null +++ b/db/versions/10459-chocolateMedeola/00-alterTableUtilConfig.sql @@ -0,0 +1,10 @@ +ALTER TABLE util.config + ADD mockUtcTime DATETIME NULL, + ADD mockEnabled TINYINT UNSIGNED NOT NULL DEFAULT FALSE, + ADD mockTz varchar(255) NULL; + +UPDATE util.config SET + mockUtcTime = '2001-01-01 11:00:00.000', + mockEnabled = TRUE, + mockTz = '+01:00'; + \ No newline at end of file diff --git a/db/versions/10459-chocolateMedeola/01-createFunctionCurdate.sql b/db/versions/10459-chocolateMedeola/01-createFunctionCurdate.sql new file mode 100644 index 000000000..986067ce3 --- /dev/null +++ b/db/versions/10459-chocolateMedeola/01-createFunctionCurdate.sql @@ -0,0 +1,13 @@ +DROP FUNCTION IF EXISTS `util`.`VN_CURDATE`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`CURDATE`() + RETURNS DATE + DETERMINISTIC +BEGIN + /** + * @return The mock date + **/ + + RETURN DATE(mockTime()); +END$$ +DELIMITER ; diff --git a/db/versions/10459-chocolateMedeola/02-createFunctionMockTime.sql b/db/versions/10459-chocolateMedeola/02-createFunctionMockTime.sql new file mode 100644 index 000000000..01abda758 --- /dev/null +++ b/db/versions/10459-chocolateMedeola/02-createFunctionMockTime.sql @@ -0,0 +1,23 @@ +DROP FUNCTION IF EXISTS `util`.`mockTime`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTime`() + RETURNS datetime + DETERMINISTIC +BEGIN +/** + * Returns the mockTime with predefined timezone or current dateTime + * depending of config.mockEnabled + * + * @return formatted datetime + */ + DECLARE vMockEnabled BOOL; + + SELECT mockEnabled INTO vMockEnabled FROM config LIMIT 1; + + IF vMockEnabled THEN + RETURN mockTimeBase(FALSE); + ELSE + RETURN util.NOW(); + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql b/db/versions/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql new file mode 100644 index 000000000..f17706639 --- /dev/null +++ b/db/versions/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql @@ -0,0 +1,27 @@ +DROP FUNCTION IF EXISTS `util`.`mockTimeBase`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTimeBase`(vIsUtc BOOL) + RETURNS datetime + DETERMINISTIC +BEGIN +/** + * Returns the date formatted to utc if vIsUtc or config.mocTz if not + * + * @param vIsUtc If date must be returned as UTC format + * @return The formatted mock time + */ +DECLARE vMockUtcTime DATETIME; + DECLARE vMockTz VARCHAR(255); + + SELECT mockUtcTime, mockTz + INTO vMockUtcTime, vMockTz + FROM config + LIMIT 1; + + IF vIsUtc OR vMockTz IS NULL THEN + RETURN vMockUtcTime; + ELSE + RETURN CONVERT_TZ(vMockUtcTime, '+00:00', vMockTz); + END IF; +END$$ +DELIMITER ; diff --git a/db/versions/10459-chocolateMedeola/04-createFunctionNow.sql b/db/versions/10459-chocolateMedeola/04-createFunctionNow.sql new file mode 100644 index 000000000..6c84d1d80 --- /dev/null +++ b/db/versions/10459-chocolateMedeola/04-createFunctionNow.sql @@ -0,0 +1,12 @@ +DROP FUNCTION IF EXISTS `util`.`NOW`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`NOW`() + RETURNS DATETIME + DETERMINISTIC +BEGIN + /** + * @return The mock datetime + */ + RETURN mockTime(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/10460-crimsonDendro/00-firstScript.sql b/db/versions/10460-crimsonDendro/00-firstScript.sql new file mode 100644 index 000000000..52f13e0f8 --- /dev/null +++ b/db/versions/10460-crimsonDendro/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE `vn2008`.`ticket_location` RENAME TO `vn2008`.`ticket_location__` ; \ No newline at end of file diff --git a/db/versions/10461-filtroPorTipos/00-firstScript.sql b/db/versions/10461-filtroPorTipos/00-firstScript.sql new file mode 100644 index 000000000..9c6c1abcf --- /dev/null +++ b/db/versions/10461-filtroPorTipos/00-firstScript.sql @@ -0,0 +1,39 @@ +ALTER TABLE vn.clientItemType + DROP COLUMN IF EXISTS isAllowed; + +ALTER TABLE vn.clientItemType + DROP FOREIGN KEY IF EXISTS clientItemType_FK_1; + +ALTER TABLE vn.clientItemType + MODIFY COLUMN IF EXISTS itemTypeFk SMALLINT UNSIGNED DEFAULT 1 NOT NULL; + +TRUNCATE TABLE vn.clientItemType; + +ALTER TABLE vn.clientItemType + ADD CONSTRAINT clientItemType_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id); + +DROP TABLE IF EXISTS vn.clientItemCategory; + +CREATE TABLE IF NOT EXISTS vn.zoneItemType ( + id int PRIMARY KEY NOT NULL AUTO_INCREMENT, + zoneFk int NOT NULL, + itemTypeFk smallint UNSIGNED NOT NULL, + CONSTRAINT zoneItemType_FK FOREIGN KEY (zoneFk) REFERENCES vn.`zone`(id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT zoneItemType_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id) ON DELETE CASCADE ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci +COMMENT='Combinaciones prohibidas entre zone e itemType al calcular el catálogo de items'; + +CREATE TABLE IF NOT EXISTS vn.agencyModeItemType ( + id int PRIMARY KEY NOT NULL AUTO_INCREMENT, + agencyModeFk int NOT NULL, + itemTypeFk smallint UNSIGNED NOT NULL, + CONSTRAINT agencyModeItemType_FK FOREIGN KEY (agencyModeFk) REFERENCES vn.agencyMode(id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT agencyModeItemType_FK_1 FOREIGN KEY (itemTypeFk) REFERENCES vn.itemType(id) ON DELETE CASCADE ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci +COMMENT='Combinaciones prohibidas entre agencyMode e itemType al calcular el catálogo de items'; diff --git a/db/versions/10463-wheatMonstera/00-firstScript.sql b/db/versions/10463-wheatMonstera/00-firstScript.sql new file mode 100644 index 000000000..28b2da36d --- /dev/null +++ b/db/versions/10463-wheatMonstera/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.mdbBranch ADD dsName varchar(255) DEFAULT NULL NULL; diff --git a/db/versions/10468-goldenGerbera/00-firstScript.sql b/db/versions/10468-goldenGerbera/00-firstScript.sql new file mode 100644 index 000000000..0440add97 --- /dev/null +++ b/db/versions/10468-goldenGerbera/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.expeditionMistake DROP FOREIGN KEY expeditionMistake_FK; +ALTER TABLE vn.expeditionMistake ADD CONSTRAINT expeditionMistake_FK FOREIGN KEY (expeditionFk) REFERENCES vn.expedition(id) ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10469-bronzeEucalyptus/00-firstScript.sql b/db/versions/10469-bronzeEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..5f844ff31 --- /dev/null +++ b/db/versions/10469-bronzeEucalyptus/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.deviceProduction ADD description varchar(100) DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10470-notaUltimoUsuario/00-firstScript.sql b/db/versions/10470-notaUltimoUsuario/00-firstScript.sql new file mode 100644 index 000000000..86fd847fe --- /dev/null +++ b/db/versions/10470-notaUltimoUsuario/00-firstScript.sql @@ -0,0 +1,15 @@ +ALTER TABLE `vn`.`entry` ADD observationEditorFk INT(10) unsigned NULL COMMENT 'Último usuario que ha modificado el campo evaNotes'; +ALTER TABLE `vn`.`entry` ADD CONSTRAINT entry_observationEditorFk FOREIGN KEY (observationEditorFk) REFERENCES account.user(id) ON UPDATE CASCADE; + +UPDATE + `vn`.`entry` e +SET + observationEditorFk = ( + SELECT w.userFk + FROM + `vn`.`worker` w + JOIN `account`.`user` u ON + u.id = w.userFk + WHERE + w.code = RIGHT(e.evaNotes,3)), + evaNotes = LEFT(evaNotes,LENGTH(evaNotes)-5) \ No newline at end of file diff --git a/db/versions/10471-orangeMastic/00-firstScript.sql b/db/versions/10471-orangeMastic/00-firstScript.sql new file mode 100644 index 000000000..742db67f4 --- /dev/null +++ b/db/versions/10471-orangeMastic/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here + +ALTER TABLE vn.saleTracking ADD isScanned tinyint(1) DEFAULT NULL NULL COMMENT 'TRUE: se ha escaneado. FALSE: escrito a mano. NULL:demás casos'; diff --git a/db/versions/10472-bronzeOak/00-firstScript.sql b/db/versions/10472-bronzeOak/00-firstScript.sql new file mode 100644 index 000000000..4f8bf198e --- /dev/null +++ b/db/versions/10472-bronzeOak/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +RENAME TABLE vn2008.payroll_categorias TO vn.payrollCategories; +ALTER TABLE vn.payrollCategories CHANGE codcategoria id int(11) NOT NULL; +ALTER TABLE vn.payrollCategories CHANGE Tarifa rate tinyint(4) NOT NULL; +ALTER TABLE vn.payrollCategories CHANGE descripcion description varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/10477-goldenDendro/00-firstScript.sql b/db/versions/10477-goldenDendro/00-firstScript.sql new file mode 100644 index 000000000..a81554bf2 --- /dev/null +++ b/db/versions/10477-goldenDendro/00-firstScript.sql @@ -0,0 +1,12 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`ticket` +CHANGE COLUMN `created` `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ; + +ALTER TABLE `vn`.`ticket` +ADD COLUMN `clonedFrom` INT(11) NULL DEFAULT NULL; + +ALTER TABLE `vn`.`entry` +ADD COLUMN `clonedFrom` INT(11) NULL DEFAULT NULL; + +ALTER TABLE `vn`.`travel` +ADD COLUMN `clonedFrom` INT(11) NULL DEFAULT NULL; diff --git a/db/versions/10478-tealGalax/00-dropBasket.sql b/db/versions/10478-tealGalax/00-dropBasket.sql new file mode 100644 index 000000000..f455b0f79 --- /dev/null +++ b/db/versions/10478-tealGalax/00-dropBasket.sql @@ -0,0 +1 @@ +DROP TABLE hedera.basketOrder; diff --git a/db/versions/10478-tealGalax/00-firstScript.sql b/db/versions/10478-tealGalax/00-firstScript.sql new file mode 100644 index 000000000..b100cf4a4 --- /dev/null +++ b/db/versions/10478-tealGalax/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT INTO hedera.message (code,description) + VALUES ('orderOutdated','La configuración del pedido es incorrecta, por favor vuelve a configurarlo para continuar comprando'); diff --git a/db/versions/10478-tealGalax/01-orderConfigured.sql b/db/versions/10478-tealGalax/01-orderConfigured.sql new file mode 100644 index 000000000..6c38123e1 --- /dev/null +++ b/db/versions/10478-tealGalax/01-orderConfigured.sql @@ -0,0 +1 @@ +ALTER TABLE hedera.`order` ADD configured DATETIME NULL; diff --git a/db/versions/10478-tealGalax/02-configuredUpdate.sql b/db/versions/10478-tealGalax/02-configuredUpdate.sql new file mode 100644 index 000000000..9b99a87cc --- /dev/null +++ b/db/versions/10478-tealGalax/02-configuredUpdate.sql @@ -0,0 +1 @@ +UPDATE hedera.order SET configured = date_make WHERE configured IS NULL; diff --git a/db/versions/10478-tealGalax/99-privileges.sql b/db/versions/10478-tealGalax/99-privileges.sql new file mode 100644 index 000000000..d5177738b --- /dev/null +++ b/db/versions/10478-tealGalax/99-privileges.sql @@ -0,0 +1,12 @@ +/* +GRANT EXECUTE ON PROCEDURE hedera.myOrder_configureForGuest TO guest; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_calcCatalogFull TO guest; +GRANT SELECT ON hedera.myOrder TO guest; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_create TO account; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_checkConfig TO account; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_configure TO account; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_calcCatalogFromItem TO account; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_getTax TO account; +GRANT EXECUTE ON PROCEDURE hedera.myOrder_confirm TO account; +CALL account.role_syncPrivileges; +*/ diff --git a/db/versions/10480-blueTulip/00-firstScript.sql b/db/versions/10480-blueTulip/00-firstScript.sql new file mode 100644 index 000000000..013405b75 --- /dev/null +++ b/db/versions/10480-blueTulip/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE edi.ekt MODIFY COLUMN putOrderFk int(11) DEFAULT NULL NULL COMMENT 'RFF+ON'; \ No newline at end of file diff --git a/db/versions/10481-brownAspidistra/00-firstScript.sql b/db/versions/10481-brownAspidistra/00-firstScript.sql new file mode 100644 index 000000000..8c912eb19 --- /dev/null +++ b/db/versions/10481-brownAspidistra/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE srt.movingLast ADD CONSTRAINT movingLast_PK PRIMARY KEY (id); diff --git a/db/versions/10482-blueMastic/00-firstScript.sql b/db/versions/10482-blueMastic/00-firstScript.sql new file mode 100644 index 000000000..2c08e2e63 --- /dev/null +++ b/db/versions/10482-blueMastic/00-firstScript.sql @@ -0,0 +1,4 @@ +CREATE INDEX ekt_sub_IDX USING BTREE ON edi.ekt (sub); +CREATE INDEX buy_itemFk_IDX USING BTREE ON vn.buy (itemFk); +ALTER TABLE edi.ekt MODIFY COLUMN putOrderFk bigint(20) DEFAULT NULL NULL COMMENT 'RFF+ON'; +ALTER TABLE edi.putOrder MODIFY COLUMN id bigint(20) auto_increment NOT NULL; diff --git a/db/versions/10485-aquaCamellia/00-firstScript.sql b/db/versions/10485-aquaCamellia/00-firstScript.sql new file mode 100644 index 000000000..c6ee5eff3 --- /dev/null +++ b/db/versions/10485-aquaCamellia/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +DROP TABLE IF EXISTS vn.workers20190711; +DROP TABLE IF EXISTS vn.workers20190711_FichadasAbril; +DROP TABLE IF EXISTS vn.workers20190711_FichadasJulio11; +DROP TABLE IF EXISTS vn.workers20190711_FichadasJunio; +DROP TABLE IF EXISTS vn.workers20190711_FichadasMayo; +DROP TABLE IF EXISTS vn.workers20190711_FichadasOctubre; +DROP TABLE IF EXISTS vn.workers20190711_Garrote; +DROP TABLE IF EXISTS postgresql.workers20190711_FichadasAbril; diff --git a/db/versions/10488-grayCarnation/00-firstScript.sql b/db/versions/10488-grayCarnation/00-firstScript.sql new file mode 100644 index 000000000..9375d52dc --- /dev/null +++ b/db/versions/10488-grayCarnation/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +DROP TABLE IF EXISTS postgresql.address, +postgresql.address_type, +postgresql.bank_account_type, +postgresql.erte_COVID19, +postgresql.professional_levels, +postgresql.profile_media, +postgresql.profile_type, +postgresql.townKk; \ No newline at end of file diff --git a/db/versions/10491-orangeDracena/00-firstScript.sql b/db/versions/10491-orangeDracena/00-firstScript.sql new file mode 100644 index 000000000..9957478c7 --- /dev/null +++ b/db/versions/10491-orangeDracena/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.printQueue MODIFY COLUMN serverId varchar(255) DEFAULT NULL NULL COMMENT 'Indica el identificador de los servidores de impresión'; diff --git a/db/versions/10492-wheatIvy/00-firstScript.sql b/db/versions/10492-wheatIvy/00-firstScript.sql new file mode 100644 index 000000000..1a39b43d9 --- /dev/null +++ b/db/versions/10492-wheatIvy/00-firstScript.sql @@ -0,0 +1,38 @@ +RENAME TABLE vn2008.Reservas TO vn2008.Reservas__; +ALTER TABLE vn2008.Reservas__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Recibos_recorded TO vn2008.Recibos_recorded__; +ALTER TABLE vn2008.Recibos_recorded__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Objetivos TO vn2008.Objetivos__; +ALTER TABLE vn2008.Objetivos__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.mail_templates TO vn2008.mail_templates__; +ALTER TABLE vn2008.mail_templates__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Jefes TO vn2008.Jefes__; +ALTER TABLE vn2008.Jefes__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.intervalos TO vn2008.intervalos__; +ALTER TABLE vn2008.intervalos__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Estanterias TO vn2008.Estanterias__; +ALTER TABLE vn2008.Estanterias__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Estanterias_distri TO vn2008.Estanterias_distri__; +ALTER TABLE vn2008.Estanterias_distri__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Estanterias_distri_name TO vn2008.Estanterias_distri_name__; +ALTER TABLE vn2008.Estanterias_distri_name__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.EnvioMasivo TO vn2008.EnvioMasivo__; +ALTER TABLE vn2008.EnvioMasivo__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Entradas_turno TO vn2008.Entradas_turno__; +ALTER TABLE vn2008.Entradas_turno__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.Entradas_stack TO vn2008.Entradas_stack__; +ALTER TABLE vn2008.Entradas_stack__ COMMENT='Deprecated 27-02-2023'; + +RENAME TABLE vn2008.`Enlaces Facturas` TO vn2008.`Enlaces Facturas__`; +ALTER TABLE vn2008.`Enlaces Facturas__` COMMENT='Deprecated 27-02-2023'; diff --git a/db/versions/10493-purpleAnthurium/00-firstScript.sql b/db/versions/10493-purpleAnthurium/00-firstScript.sql new file mode 100644 index 000000000..ada713d3d --- /dev/null +++ b/db/versions/10493-purpleAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.greugeConfig ADD maxPercentToWrong decimal(10,2) DEFAULT NULL COMMENT 'Porcentaje del precio del ticket que es considerado error'; +ALTER TABLE vn.greugeConfig ADD lastNotifyCheck timestamp DEFAULT NULL NULL COMMENT 'Última ejecución del procedimiento que revisa los greuges anormales'; diff --git a/db/versions/10495-whiteFern/00-firstScript.sql b/db/versions/10495-whiteFern/00-firstScript.sql new file mode 100644 index 000000000..93bff192f --- /dev/null +++ b/db/versions/10495-whiteFern/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.client DROP COLUMN mailAddress; diff --git a/db/versions/10498-redAspidistra/00-firstScript.sql b/db/versions/10498-redAspidistra/00-firstScript.sql new file mode 100644 index 000000000..860b57c5e --- /dev/null +++ b/db/versions/10498-redAspidistra/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`supplierAccount` +CHANGE COLUMN `bankFk` `accountingFk` INT(11) NULL DEFAULT NULL ; diff --git a/db/versions/10500-limeChrysanthemum/00-firstScript.sql b/db/versions/10500-limeChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..3792608d4 --- /dev/null +++ b/db/versions/10500-limeChrysanthemum/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.bankEntity DROP KEY bic_UNIQUE; diff --git a/db/versions/10500-limeRaphis/00-firstScript.sql b/db/versions/10500-limeRaphis/00-firstScript.sql new file mode 100644 index 000000000..7db02c439 --- /dev/null +++ b/db/versions/10500-limeRaphis/00-firstScript.sql @@ -0,0 +1,10 @@ +USE vn; +CREATE TABLE `vn`.`glsExpedition` ( + `expeditionFk` int(11) NOT NULL, + `barcode` varchar(20) DEFAULT NULL, + `uid` varchar(45) DEFAULT NULL COMMENT 'Valor retornado por GLS al hacer pertición al webservice', + `codexp` int(11) DEFAULT NULL COMMENT 'Valor retornado por GLS al hacer pertición al webservice', + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`expeditionFk`), + CONSTRAINT `glsExpedition_FK` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10501-orangeAnthurium/00-firstScript.sql b/db/versions/10501-orangeAnthurium/00-firstScript.sql new file mode 100644 index 000000000..14a42f832 --- /dev/null +++ b/db/versions/10501-orangeAnthurium/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE hedera.tpvTransaction + ADD merchantParameters TEXT DEFAULT NULL NULL, + ADD signature VARCHAR(255) DEFAULT NULL NULL, + ADD signatureVersion varchar(50) DEFAULT NULL NULL, + ADD responseError varchar(255) DEFAULT NULL NULL; diff --git a/db/versions/10502-azureCarnation/00-firstScript.sql b/db/versions/10502-azureCarnation/00-firstScript.sql new file mode 100644 index 000000000..8e3812e6d --- /dev/null +++ b/db/versions/10502-azureCarnation/00-firstScript.sql @@ -0,0 +1,8 @@ +USE vn; + +DROP TABLE IF EXISTS vn.workerTimeControlConfig_; +ALTER TABLE vn.workerTimeControlConfig + ADD breakTimeSplitDay int(11) unsigned DEFAULT 3600 NULL + COMMENT 'Tiempo de descanso a partir del cual se determina que la jornada es partida', + ADD dateSplitDay date DEFAULT '2023-03-01' NULL + COMMENT 'Fecha a partir de la cual se tiene en cuenta el valor de configuración de breakTimeSplitDay'; diff --git a/db/versions/10502-yellowCordyline/00-firstScript.sql b/db/versions/10502-yellowCordyline/00-firstScript.sql new file mode 100644 index 000000000..d1e5a76da --- /dev/null +++ b/db/versions/10502-yellowCordyline/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here +ALTER TABLE vn.sale + ADD COLUMN total DECIMAL(10,2) + AS (price * quantity * (100 - discount) / 100) VIRTUAL; + +ALTER TABLE vn.claim + ADD COLUMN responsabilityRate DECIMAL(3,2) + AS ((5 - responsibility) / 4) VIRTUAL; diff --git a/db/versions/10504-maroonPalmetto/00-firstScript.sql b/db/versions/10504-maroonPalmetto/00-firstScript.sql new file mode 100644 index 000000000..f57f96c18 --- /dev/null +++ b/db/versions/10504-maroonPalmetto/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.vehicle MODIFY COLUMN numberPlate varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; diff --git a/db/versions/10506-aquaPaniculata/01-firstScript.sql b/db/versions/10506-aquaPaniculata/01-firstScript.sql new file mode 100644 index 000000000..9cfd1d7ae --- /dev/null +++ b/db/versions/10506-aquaPaniculata/01-firstScript.sql @@ -0,0 +1,12 @@ +ALTER TABLE vn.expense + ADD COLUMN IF NOT EXISTS code VARCHAR(25) DEFAULT NULL NULL, + ADD CONSTRAINT expense_UN UNIQUE KEY IF NOT EXISTS (code); + +CREATE TABLE IF NOT EXISTS sage.`taxType` ( + `id` int(11) NOT NULL, + `code` varchar(25) DEFAULT NULL, + `isIntracommunity` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `taxType_UN` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci + COMMENT='Coincidencia del id con Sage.TiposIVA.CodigoIva(propia de Sage), en ningún caso vincular mediate FK'; diff --git a/db/versions/10506-aquaPaniculata/02-secondScript.sql b/db/versions/10506-aquaPaniculata/02-secondScript.sql new file mode 100644 index 000000000..089d47e5e --- /dev/null +++ b/db/versions/10506-aquaPaniculata/02-secondScript.sql @@ -0,0 +1,3 @@ +INSERT IGNORE INTO sage.taxType (id, isIntracommunity) + SELECT CodigoIva, isIntracommunity + FROM sage.TiposIva; \ No newline at end of file diff --git a/db/versions/10506-aquaPaniculata/03-thirdScript.sql b/db/versions/10506-aquaPaniculata/03-thirdScript.sql new file mode 100644 index 000000000..b891a5858 --- /dev/null +++ b/db/versions/10506-aquaPaniculata/03-thirdScript.sql @@ -0,0 +1,48 @@ +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='import10' + WHERE ti.IVA = 'IVA 10% importaciones'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='import21' + WHERE ti.IVA = 'IVA 21% importaciones'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='ISP21' + WHERE ti.IVA = 'HP DEVENGADO 21 ISP'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='import4' + WHERE ti.IVA = 'H.P. IVA Soportado Impor 4%'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='national10' + WHERE ti.IVA = 'I.V.A. 10% Nacional'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='national21' + WHERE ti.IVA = 'I.V.A. 21%'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='national4' + WHERE ti.IVA = 'I.V.A. 4%'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='national0' + WHERE ti.IVA = 'I.V.A 0% Nacional'; + +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code='CEEServices21' + WHERE ti.IVA = 'I.V.A. Adqui. servicios CEE'; + +ALTER TABLE sage.TiposIva + DROP COLUMN IF EXISTS isIntracommunity; + diff --git a/db/versions/10506-crimsonRoebelini/00-firstScript.sql b/db/versions/10506-crimsonRoebelini/00-firstScript.sql new file mode 100644 index 000000000..ded96ce50 --- /dev/null +++ b/db/versions/10506-crimsonRoebelini/00-firstScript.sql @@ -0,0 +1,12 @@ +-- Place your SQL code here +ALTER TABLE `postgresql`.`calendar_labour_type` RENAME `vn`.`calendarType`; + +ALTER TABLE `vn`.`calendarType` +DROP COLUMN `pausa_remunerada`, +CHANGE COLUMN `calendar_labour_type_id` `id` int(11) NOT NULL AUTO_INCREMENT, +CHANGE COLUMN `descripcion` `description` varchar(50) DEFAULT NULL, +CHANGE COLUMN `hours_week` `hoursWeek` smallint(6) DEFAULT NULL , +CHANGE COLUMN `isPartial` `isPartial` tinyint(1) NOT NULL DEFAULT 0 ; + +ALTER TABLE `vn`.`calendarType` +CHANGE COLUMN `hoursWeek` `hoursWeek` SMALLINT(6) UNSIGNED NULL DEFAULT NULL ; \ No newline at end of file diff --git a/db/versions/10507-greenAspidistra/00-firstScript.sql b/db/versions/10507-greenAspidistra/00-firstScript.sql new file mode 100644 index 000000000..52d743f8e --- /dev/null +++ b/db/versions/10507-greenAspidistra/00-firstScript.sql @@ -0,0 +1,40 @@ +USE vn; + +ALTER TABLE vn.sectorCollectionSaleGroup DROP FOREIGN KEY IF EXISTS sectorCollectionSaleGroup_FK_1; +ALTER TABLE vn.sectorCollectionSaleGroup DROP FOREIGN KEY IF EXISTS sectorCollectionSaleGroup_FK; + +ALTER TABLE vn.sectorCollectionSaleGroup DROP KEY IF EXISTS sectorCollectionSaleGroup_UN; +DELETE + FROM sectorCollectionSaleGroup + WHERE id NOT IN ( + SELECT * + FROM ( + SELECT MIN(id) + FROM sectorCollectionSaleGroup + GROUP BY saleGroupFk + ) as temp_table + ); +ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT UNIQUE KEY (saleGroupFk); + +ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT FOREIGN KEY (sectorCollectionFk) REFERENCES vn.sectorCollection(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT FOREIGN KEY (saleGroupFk) REFERENCES vn.saleGroup(id) ON DELETE CASCADE ON UPDATE CASCADE; + +CREATE OR REPLACE TEMPORARY TABLE tSGD +SELECT saleFk, sgd.id, count(*) n + FROM vn.saleGroupDetail sgd + GROUP BY saleFk + HAVING n > 1; + +DELETE sgd.* + FROM vn.saleGroupDetail sgd + JOIN tSGD ON tSGD.saleFk = sgd.saleFk AND tSGD.id <> sgd.id; + +DROP TEMPORARY TABLE tSGD; + +ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT FOREIGN KEY (saleGroupFk) REFERENCES vn.saleGroup(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.saleGroupDetail DROP FOREIGN KEY IF EXISTS saleGroupDetail_FK; +ALTER TABLE vn.saleGroupDetail DROP FOREIGN KEY IF EXISTS saleGroupDetail_FK_1; +ALTER TABLE vn.saleGroupDetail DROP KEY IF EXISTS saleGroupDetail_UN; +ALTER TABLE vn.saleGroupDetail ADD CONSTRAINT FOREIGN KEY (saleFk) REFERENCES vn.sale(id) ON DELETE CASCADE ON UPDATE CASCADE; + \ No newline at end of file diff --git a/db/versions/10508-maroonMonstera/00-firstScript.sql b/db/versions/10508-maroonMonstera/00-firstScript.sql new file mode 100644 index 000000000..e7e62cebe --- /dev/null +++ b/db/versions/10508-maroonMonstera/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.buy MODIFY COLUMN printedStickers int(11) DEFAULT 0 NOT NULL; diff --git a/db/versions/10510-salmonMoss/00-dropBusinessFk.sql b/db/versions/10510-salmonMoss/00-dropBusinessFk.sql new file mode 100644 index 000000000..5ef0ecf22 --- /dev/null +++ b/db/versions/10510-salmonMoss/00-dropBusinessFk.sql @@ -0,0 +1 @@ +ALTER TABLE vn.business DROP FOREIGN KEY IF EXISTS business_workerBusinessProfessionalCategoryFk; \ No newline at end of file diff --git a/db/versions/10510-salmonMoss/01-createTableProfessionalCategory.sql b/db/versions/10510-salmonMoss/01-createTableProfessionalCategory.sql new file mode 100644 index 000000000..1a8b2d733 --- /dev/null +++ b/db/versions/10510-salmonMoss/01-createTableProfessionalCategory.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE TABLE vn.professionalCategory ( + id int(11) auto_increment NOT NULL, + name varchar(50) NOT NULL, + `level` INT(11) UNSIGNED DEFAULT NULL NULL, + dayBreak int(11) UNSIGNED DEFAULT NULL NULL, + CONSTRAINT prefessionalCategory_PK PRIMARY KEY (id), + CONSTRAINT prefessionalCategory_UN UNIQUE KEY (name) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10510-salmonMoss/02-exportToNewTable.sql b/db/versions/10510-salmonMoss/02-exportToNewTable.sql new file mode 100644 index 000000000..8f26f5ac5 --- /dev/null +++ b/db/versions/10510-salmonMoss/02-exportToNewTable.sql @@ -0,0 +1,3 @@ +INSERT INTO vn.professionalCategory (id, name, `level`, dayBreak) +SELECT pc.professional_category_id, pc.category_name, pc.professional_levels_id, pc.dayBreak +FROM postgresql.professional_category pc; \ No newline at end of file diff --git a/db/versions/10510-salmonMoss/03-RecreateFK.sql b/db/versions/10510-salmonMoss/03-RecreateFK.sql new file mode 100644 index 000000000..28f08fc9d --- /dev/null +++ b/db/versions/10510-salmonMoss/03-RecreateFK.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.business ADD CONSTRAINT business_FK FOREIGN KEY (workerBusinessProfessionalCategoryFk) + REFERENCES vn.professionalCategory(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10510-salmonMoss/04-kkPostgresqlTable.sql b/db/versions/10510-salmonMoss/04-kkPostgresqlTable.sql new file mode 100644 index 000000000..938671c42 --- /dev/null +++ b/db/versions/10510-salmonMoss/04-kkPostgresqlTable.sql @@ -0,0 +1,2 @@ +ALTER TABLE postgresql.professional_category RENAME TO postgresql.professional_category__; +ALTER TABLE postgresql.professional_category__ COMMENT='@deprecated 2023-03-24'; \ No newline at end of file diff --git a/db/versions/10511-chocolateChrysanthemum/00-firstScript.sql b/db/versions/10511-chocolateChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..bc94ecd22 --- /dev/null +++ b/db/versions/10511-chocolateChrysanthemum/00-firstScript.sql @@ -0,0 +1,33 @@ +USE `postgresql`; + +DELIMITER $$ + +USE `postgresql`$$ +DROP TRIGGER IF EXISTS `postgresql`.`income_employee_afterInsert` $$ +DELIMITER ; +USE `postgresql`; + +DELIMITER $$ + +USE `postgresql`$$ +DROP TRIGGER IF EXISTS `postgresql`.`income_employee_afterUpdate` $$ +DELIMITER ; +USE `postgresql`; + +DELIMITER $$ + +USE `postgresql`$$ +DROP TRIGGER IF EXISTS `postgresql`.`income_employee_afterDelete` $$ +DELIMITER ; + +ALTER TABLE `postgresql`.`income_employee` RENAME `vn`.`workerIncome`; + +ALTER TABLE `vn`.`workerIncome` +CHANGE COLUMN `debe` `debit` decimal(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `haber` `credit` decimal(10,2) NOT NULL DEFAULT 0.00, +CHANGE COLUMN `id_incomeType` `incomeTypeFk` int(11) DEFAULT NULL, +CHANGE COLUMN `odbc_date` `paymentDate` date DEFAULT NULL, +CHANGE COLUMN `concepto` `concept` longtext DEFAULT NULL; + +GRANT SELECT ON TABLE `vn`.`workerIncome` TO `hr`; +GRANT INSERT, UPDATE, DELETE ON TABLE `vn`.`workerIncome` TO `hrBoss`; \ No newline at end of file diff --git a/db/versions/10512-purpleRoebelini/00-firstScript.sql b/db/versions/10512-purpleRoebelini/00-firstScript.sql new file mode 100644 index 000000000..de8387e2d --- /dev/null +++ b/db/versions/10512-purpleRoebelini/00-firstScript.sql @@ -0,0 +1,2 @@ +RENAME TABLE postgresql.incometype_employee TO postgresql.incometype_employee__; +ALTER TABLE postgresql.incometype_employee__ COMMENT='@deprecated 2023-03-15'; \ No newline at end of file diff --git a/db/versions/10513-aquaCataractarum/00-firstScript.sql b/db/versions/10513-aquaCataractarum/00-firstScript.sql new file mode 100644 index 000000000..a15d4ea27 --- /dev/null +++ b/db/versions/10513-aquaCataractarum/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE `salix`.`AccessToken` +ADD COLUMN `outdated` DATETIME AS (TIMESTAMPADD(SECOND, ttl, created)) PERSISTENT, +ADD INDEX `outdated_Index` (`outdated` ASC) VISIBLE; diff --git a/db/versions/10514-silverAspidistra/00-firstScript.sql b/db/versions/10514-silverAspidistra/00-firstScript.sql new file mode 100644 index 000000000..9a5022336 --- /dev/null +++ b/db/versions/10514-silverAspidistra/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +USE vn; +INSERT INTO vn.silexACL +(module, `method`, `role`) +VALUES('almacennew', 'ticket_printLabelPrevious', 'employee'); diff --git a/db/versions/10516-crimsonSalal/00-firstScript.sql b/db/versions/10516-crimsonSalal/00-firstScript.sql new file mode 100644 index 000000000..7db02c439 --- /dev/null +++ b/db/versions/10516-crimsonSalal/00-firstScript.sql @@ -0,0 +1,10 @@ +USE vn; +CREATE TABLE `vn`.`glsExpedition` ( + `expeditionFk` int(11) NOT NULL, + `barcode` varchar(20) DEFAULT NULL, + `uid` varchar(45) DEFAULT NULL COMMENT 'Valor retornado por GLS al hacer pertición al webservice', + `codexp` int(11) DEFAULT NULL COMMENT 'Valor retornado por GLS al hacer pertición al webservice', + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`expeditionFk`), + CONSTRAINT `glsExpedition_FK` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10521-salmonLilium/00-firstScript.sql b/db/versions/10521-salmonLilium/00-firstScript.sql new file mode 100644 index 000000000..bbd4c8c88 --- /dev/null +++ b/db/versions/10521-salmonLilium/00-firstScript.sql @@ -0,0 +1,4 @@ +CREATE TABLE vn.franceExpressConfig ( + id INT auto_increment NOT NULL PRIMARY KEY, + `path` varchar(100) DEFAULT "\\\\server\\agencies\\franceexpress\\expeditions" NULL +); \ No newline at end of file diff --git a/db/versions/10522-yellowMedeola/00-firstScript.sql b/db/versions/10522-yellowMedeola/00-firstScript.sql new file mode 100644 index 000000000..50e1848a8 --- /dev/null +++ b/db/versions/10522-yellowMedeola/00-firstScript.sql @@ -0,0 +1,4 @@ +RENAME TABLE postgresql.media TO postgresql.media__; +ALTER TABLE postgresql.media__ +COMMENT='@deprecated 2023-03-31'; + diff --git a/db/versions/10523-tealCataractarum/00-firstScript.sql b/db/versions/10523-tealCataractarum/00-firstScript.sql new file mode 100644 index 000000000..cd7172bd6 --- /dev/null +++ b/db/versions/10523-tealCataractarum/00-firstScript.sql @@ -0,0 +1,54 @@ +CREATE TABLE vn.farming ( + id int(10) unsigned auto_increment NOT NULL, + name varchar(100) NOT NULL, + location varchar(255) NOT NULL, + warehouseFk smallint(6) unsigned NOT NULL, + description text DEFAULT NULL NULL, + photo blob DEFAULT NULL NULL, + isActive tinyint(1) DEFAULT 1 NOT NULL, + created timestamp DEFAULT current_timestamp() NOT NULL, + CONSTRAINT farming_PK PRIMARY KEY (id), + CONSTRAINT farming_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +CREATE TABLE vn.farmingDms ( + id int(10) unsigned auto_increment NOT NULL, + farmingFk int(10) unsigned NOT NULL, + dmsFk int(11) NOT NULL, + CONSTRAINT farmingDms_PK PRIMARY KEY (id), + CONSTRAINT farmingDms_FK FOREIGN KEY (farmingFk) REFERENCES vn.farming(id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT farmingDms_FK_1 FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +CREATE TABLE vn.farmingInvoiceIn ( + id int(10) unsigned auto_increment NOT NULL, + farmingFk int(10) unsigned NOT NULL, + invoiceInFk mediumint(8) unsigned NOT NULL, + amount decimal(10,2) DEFAULT NULL NULL, + CONSTRAINT farmingInvoiceIn_PK PRIMARY KEY (id), + CONSTRAINT farmingInvoiceIn_FK FOREIGN KEY (invoiceInFk) REFERENCES vn.invoiceIn(id) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT farmingInvoiceIn_FK_1 FOREIGN KEY (farmingFk) REFERENCES vn.farming(id) ON DELETE RESTRICT ON UPDATE RESTRICT +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +CREATE TABLE vn.farmingNotes ( + id int(10) unsigned auto_increment NOT NULL, + farmingFk int(10) unsigned NOT NULL, + note text NOT NULL, + userFk int(10) unsigned NOT NULL, + created timestamp DEFAULT current_timestamp() NOT NULL, + CONSTRAINT farmingNotes_PK PRIMARY KEY (id), + CONSTRAINT farmingNotes_FK FOREIGN KEY (id) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE RESTRICT, + CONSTRAINT farmingNotes_FK_1 FOREIGN KEY (farmingFk) REFERENCES vn.farming(id) ON DELETE RESTRICT ON UPDATE RESTRICT +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10524-limeCordyline/00-firstScript.sql b/db/versions/10524-limeCordyline/00-firstScript.sql new file mode 100644 index 000000000..1c7843073 --- /dev/null +++ b/db/versions/10524-limeCordyline/00-firstScript.sql @@ -0,0 +1,21 @@ +-- Place your SQL code here +USE vn; +CREATE OR REPLACE TABLE `rateLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('Rate') NOT NULL DEFAULT 'Rate', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `logRateuserFk` (`userFk`), + KEY `rateLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `rateLog_originFk` (`originFk`,`creationDate`), + CONSTRAINT `rateOriginFk` FOREIGN KEY (`originFk`) REFERENCES `rate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `rateUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10524-limeCordyline/01-rateEditorFk.sql b/db/versions/10524-limeCordyline/01-rateEditorFk.sql new file mode 100644 index 000000000..e2b6d27fd --- /dev/null +++ b/db/versions/10524-limeCordyline/01-rateEditorFk.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`rate` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT rate_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); \ No newline at end of file diff --git a/db/versions/10525-yellowRuscus/00-firstScript.sql b/db/versions/10525-yellowRuscus/00-firstScript.sql new file mode 100644 index 000000000..0a9cb6bbe --- /dev/null +++ b/db/versions/10525-yellowRuscus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.ticketSms DROP FOREIGN KEY ticketSms_FK_1; +ALTER TABLE vn.ticketSms ADD CONSTRAINT ticketSms_FK_1 FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id) ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10526-goldenOak/00-firstScript.sql b/db/versions/10526-goldenOak/00-firstScript.sql new file mode 100644 index 000000000..e50c1ce07 --- /dev/null +++ b/db/versions/10526-goldenOak/00-firstScript.sql @@ -0,0 +1,3 @@ +RENAME TABLE postgresql.province TO postgresql.province__; +ALTER TABLE postgresql.province__ +COMMENT='@deprecated 2023-03-21'; diff --git a/db/versions/10528-orangeRoebelini/00-firstScript.sql b/db/versions/10528-orangeRoebelini/00-firstScript.sql new file mode 100644 index 000000000..c26a9edbb --- /dev/null +++ b/db/versions/10528-orangeRoebelini/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`supplierAccount` +CHANGE COLUMN `description` `description__` VARCHAR(45) NULL DEFAULT NULL COMMENT '@deprecated 2023-03-23' ; diff --git a/db/versions/10530-orangeCyca/00-firstScript.sql b/db/versions/10530-orangeCyca/00-firstScript.sql new file mode 100644 index 000000000..4fbd5f4d4 --- /dev/null +++ b/db/versions/10530-orangeCyca/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entryLog MODIFY COLUMN userFk int(10) unsigned DEFAULT NULL NULL; diff --git a/db/versions/10531-chocolateFern/00-firstScript.sql b/db/versions/10531-chocolateFern/00-firstScript.sql new file mode 100644 index 000000000..7ab9c0be8 --- /dev/null +++ b/db/versions/10531-chocolateFern/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.config ADD comparativeLastBuyScope int(11) NULL COMMENT 'Rango en el que se busca la última entrada de un artículo'; \ No newline at end of file diff --git a/db/versions/10532-tealTulip/00-firstScript.sql b/db/versions/10532-tealTulip/00-firstScript.sql new file mode 100644 index 000000000..79e07d591 --- /dev/null +++ b/db/versions/10532-tealTulip/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.glsConfig ADD density INT DEFAULT 42 NOT NULL; \ No newline at end of file diff --git a/db/versions/10533-crimsonLaurel/00-firstScript.sql b/db/versions/10533-crimsonLaurel/00-firstScript.sql new file mode 100644 index 000000000..4a24baf95 --- /dev/null +++ b/db/versions/10533-crimsonLaurel/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.ppe ADD isDone BOOL NULL; diff --git a/db/versions/10537-grayCordyline/00-firstScript.sql b/db/versions/10537-grayCordyline/00-firstScript.sql new file mode 100644 index 000000000..ede9a6942 --- /dev/null +++ b/db/versions/10537-grayCordyline/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.printQueue MODIFY COLUMN printerFk tinyint(3) unsigned NULL; diff --git a/db/versions/10538-silverAspidistra/00-createChronopostConfig.sql b/db/versions/10538-silverAspidistra/00-createChronopostConfig.sql new file mode 100644 index 000000000..0cebe2c0c --- /dev/null +++ b/db/versions/10538-silverAspidistra/00-createChronopostConfig.sql @@ -0,0 +1,24 @@ +CREATE TABLE vn.chronopostConfig ( + id INT(11) auto_increment NOT NULL, + accountNumber INT(11) NOT NULL, + password INT(11) NOT NULL, + idEmit varchar(20) DEFAULT "CHRFR" NOT NULL COMMENT "Valor fijo de chronopost", + urlShipping varchar(100) DEFAULT "https://ws.chronopost.fr/shipping-cxf/ShippingServiceWS/" NOT NULL, + urlTracking varchar(100) DEFAULT "https://ws.chronopost.fr/tracking-cxf/TrackingServiceWS/" NOT NULL, + cxfShipping varchar(100) DEFAULT "http://cxf.shipping.soap.chronopost.fr/" NOT NULL, + cxfTracking varchar(100) DEFAULT "http://cxf.tracking.soap.chronopost.fr/" NOT NULL, + evtCode varchar(2) DEFAULT "DC" NOT NULL COMMENT "Valor fijo de chronopost", + objectType VARCHAR(3) DEFAULT "MAR" NOT NULL COMMENT "MAR: mercancia, DOC: documentación", + productCode VARCHAR(2) DEFAULT "1S" NOT NULL, + weightUnit VARCHAR(3) DEFAULT "KGM" NOT NULL, + stickerMode VARCHAR(6) DEFAULT "THE" NOT NULL COMMENT "THE: vertical, THEPSG: horizontal, PDF, ...", + defaultWeight INT(11) DEFAULT 10 NOT NULL, + defaultSevice INT(11) DEFAULT 0 NOT NULL, + numberOfParcel INT(11) DEFAULT 1 NOT NULL, + civility varchar(1) DEFAULT 'M' NOT NULL, + modeRetour VARCHAR(1) DEFAULT '2' NOT NULL, + CONSTRAINT chronopostConfig_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10538-silverAspidistra/01-createChronopostService.sql b/db/versions/10538-silverAspidistra/01-createChronopostService.sql new file mode 100644 index 000000000..1b083201c --- /dev/null +++ b/db/versions/10538-silverAspidistra/01-createChronopostService.sql @@ -0,0 +1,9 @@ +CREATE TABLE vn.chronopostServiceWeekday ( + id int(11) auto_increment NOT NULL, + weekdays set('mon','tue','wed','thu','fri','sat','sun') NOT NULL, + serviceType int(11) unsigned NOT NULL, + CONSTRAINT chronopostServiceWeekday_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10538-silverAspidistra/02-createChronopostExpedition.sql b/db/versions/10538-silverAspidistra/02-createChronopostExpedition.sql new file mode 100644 index 000000000..b655f8068 --- /dev/null +++ b/db/versions/10538-silverAspidistra/02-createChronopostExpedition.sql @@ -0,0 +1,9 @@ +CREATE TABLE vn.chronopostExpedition ( + expeditionFk int(11) NOT NULL, + skybillNumber varchar(20) NOT NULL COMMENT 'Código devuelto por chronopost', + PRIMARY KEY (`expeditionFk`), + CONSTRAINT chronopostExpedition_FK FOREIGN KEY (expeditionFk) REFERENCES vn.expedition(id) ON DELETE RESTRICT ON UPDATE RESTRICT +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10538-silverAspidistra/03-createChronopostSenderAddress.sql b/db/versions/10538-silverAspidistra/03-createChronopostSenderAddress.sql new file mode 100644 index 000000000..700d13615 --- /dev/null +++ b/db/versions/10538-silverAspidistra/03-createChronopostSenderAddress.sql @@ -0,0 +1,8 @@ +CREATE TABLE vn.`chronopostSenderAddress` ( + `warehouseFk` smallint(6) unsigned NOT NULL, + `addressFk` int(11) NOT NULL, + PRIMARY KEY (`warehouseFk`), + KEY `chronopostSenderAddress_FK_1` (`addressFk`), + CONSTRAINT `chronopostSenderAddress_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `chronopostSenderAddress_FK_1` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10538-silverAspidistra/04-addgrantPrivilegies.sql b/db/versions/10538-silverAspidistra/04-addgrantPrivilegies.sql new file mode 100644 index 000000000..59c32d202 --- /dev/null +++ b/db/versions/10538-silverAspidistra/04-addgrantPrivilegies.sql @@ -0,0 +1,5 @@ +GRANT SELECT ON vn.chronopostConfig TO packager; +GRANT SELECT ON vn.chronopostSenderAddress TO packager; +GRANT SELECT ON vn.chronopostServiceWeekday TO packager; +GRANT INSERT ON vn.chronopostExpedition TO packager; +GRANT DELETE ON vn.chronopostExpedition TO packager; \ No newline at end of file diff --git a/db/versions/10538-silverAspidistra/05-updateChronopostConfig.sql b/db/versions/10538-silverAspidistra/05-updateChronopostConfig.sql new file mode 100644 index 000000000..6475cf5c4 --- /dev/null +++ b/db/versions/10538-silverAspidistra/05-updateChronopostConfig.sql @@ -0,0 +1 @@ +ALTER TABLE vn.chronopostConfig MODIFY COLUMN password VARCHAR(20) NOT NULL; \ No newline at end of file diff --git a/db/versions/10539-pinkPalmetto/00-firstScript.sql b/db/versions/10539-pinkPalmetto/00-firstScript.sql new file mode 100644 index 000000000..584d6f6f2 --- /dev/null +++ b/db/versions/10539-pinkPalmetto/00-firstScript.sql @@ -0,0 +1,8 @@ +USE vn; +DROP TABLE IF EXISTS vn.workerTimeControlConfig_; +ALTER TABLE vn.workerTimeControlConfig + ADD breakTimeSplitDay int(11) unsigned DEFAULT 3600 NULL + COMMENT 'Tiempo de descanso a partir del cual se determina que la jornada es partida', + ADD dateSplitDay date DEFAULT '2023-03-01' NULL + COMMENT 'Fecha a partir de la cual se tiene en cuenta el valor de configuración de breakTimeSplitDay'; + \ No newline at end of file diff --git a/db/versions/10540-bronzeOrchid/00-firstScript.sql b/db/versions/10540-bronzeOrchid/00-firstScript.sql new file mode 100644 index 000000000..25f37a457 --- /dev/null +++ b/db/versions/10540-bronzeOrchid/00-firstScript.sql @@ -0,0 +1,39 @@ +-- Place your SQL code here +USE account; +CREATE TABLE `userLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(10) unsigned NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` varchar(45) DEFAULT NULL, + `oldInstance` text DEFAULT NULL, + `newInstance` text DEFAULT NULL, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `userLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `userLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +CREATE TABLE `roleLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(10) unsigned NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` varchar(45) DEFAULT NULL, + `oldInstance` text DEFAULT NULL, + `newInstance` text DEFAULT NULL, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `roleLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `roleLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10545-maroonDracena/00-firstScript.sql b/db/versions/10545-maroonDracena/00-firstScript.sql new file mode 100644 index 000000000..7ee9d7f29 --- /dev/null +++ b/db/versions/10545-maroonDracena/00-firstScript.sql @@ -0,0 +1,5 @@ + UPDATE vn.supplier s + JOIN vn.country c ON c.id = s.countryFk + SET s.nif = MID(REPLACE(s.nif, ' ', ''), 3, LENGTH(REPLACE(s.nif, ' ', '')) - 1) + WHERE s.isVies = TRUE + AND c.code = LEFT(REPLACE(s.nif, ' ', ''), 2); \ No newline at end of file diff --git a/db/versions/10546-redOak/00-firstScript.sql b/db/versions/10546-redOak/00-firstScript.sql new file mode 100644 index 000000000..3d7f0415f --- /dev/null +++ b/db/versions/10546-redOak/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.item + ADD editorFk INT UNSIGNED NULL, + ADD CONSTRAINT item_fk_editor FOREIGN KEY (editorFk) REFERENCES account.`user`(id); + +CREATE INDEX itemLog_changedModel_idx USING BTREE + ON vn.itemLog (changedModel,changedModelId); diff --git a/db/versions/10547-aquaDendro/00-firstScript.sql b/db/versions/10547-aquaDendro/00-firstScript.sql new file mode 100644 index 000000000..3fb94ef41 --- /dev/null +++ b/db/versions/10547-aquaDendro/00-firstScript.sql @@ -0,0 +1,17 @@ +-- Place your SQL code here +USE vn; +CREATE INDEX IF NOT EXISTS ticketLog_creationDate_IDX + USING BTREE ON vn.ticketLog (creationDate); -- 10m + +DELETE tl + FROM vn.ticketLog tl + JOIN vn.ticket t ON t.id = tl.originFk + WHERE tl.creationDate <= util.VN_CURDATE() + INTERVAL -5 YEAR + AND t.shipped IS NOT NULL; -- 400000 rows + +DELETE tl + FROM vn.ticketLog tl + JOIN vn.ticket t ON t.id = tl.originFk + WHERE t.isDeleted; -- 113574 rows + +OPTIMIZE TABLE vn.ticketLog; -- 17m 35s \ No newline at end of file diff --git a/db/versions/10549-goldenHydrangea/00-updateUpdateLog.sql b/db/versions/10549-goldenHydrangea/00-updateUpdateLog.sql new file mode 100644 index 000000000..a7619b174 --- /dev/null +++ b/db/versions/10549-goldenHydrangea/00-updateUpdateLog.sql @@ -0,0 +1,37 @@ +-- Place your SQL code here +UPDATE vn.claimLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.itemLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.entryLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.supplierLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.zoneLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.travelLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.routeLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.clientLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.shelvingLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.ticketLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.deviceProductionLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; +UPDATE vn.workerLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'update'; \ No newline at end of file diff --git a/db/versions/10549-goldenHydrangea/01-updateInsertLog.sql b/db/versions/10549-goldenHydrangea/01-updateInsertLog.sql new file mode 100644 index 000000000..3c4397c89 --- /dev/null +++ b/db/versions/10549-goldenHydrangea/01-updateInsertLog.sql @@ -0,0 +1,37 @@ +-- Place your SQL code here +UPDATE vn.claimLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.itemLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.entryLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.supplierLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.zoneLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.travelLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.routeLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.clientLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.shelvingLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.ticketLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.deviceProductionLog + SET oldInstance = NULL + WHERE `action` = 'insert'; +UPDATE vn.workerLog + SET oldInstance = NULL + WHERE `action` = 'insert'; \ No newline at end of file diff --git a/db/versions/10549-goldenHydrangea/02-updateDeleteLog.sql b/db/versions/10549-goldenHydrangea/02-updateDeleteLog.sql new file mode 100644 index 000000000..60890741b --- /dev/null +++ b/db/versions/10549-goldenHydrangea/02-updateDeleteLog.sql @@ -0,0 +1,37 @@ +-- Place your SQL code here +UPDATE vn.claimLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.itemLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.entryLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.supplierLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.zoneLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.travelLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.routeLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.clientLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.shelvingLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.ticketLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.deviceProductionLog + SET newInstance = NULL + WHERE `action` = 'delete'; +UPDATE vn.workerLog + SET newInstance = NULL + WHERE `action` = 'delete'; \ No newline at end of file diff --git a/db/versions/10549-goldenHydrangea/03-deleteEmptyLog.sql b/db/versions/10549-goldenHydrangea/03-deleteEmptyLog.sql new file mode 100644 index 000000000..616c3a1d2 --- /dev/null +++ b/db/versions/10549-goldenHydrangea/03-deleteEmptyLog.sql @@ -0,0 +1,45 @@ +-- Place your SQL code here +DELETE FROM vn.claimLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.itemLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.entryLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.supplierLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.zoneLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.travelLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.routeLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.clientLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.shelvingLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.ticketLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; +DELETE FROM vn.workerLog + WHERE oldInstance IS NULL + AND newInstance IS NULL + AND `description` IS NULL; \ No newline at end of file diff --git a/db/versions/10549-goldenHydrangea/04-optimizeLogTables.sql b/db/versions/10549-goldenHydrangea/04-optimizeLogTables.sql new file mode 100644 index 000000000..ef9cb5863 --- /dev/null +++ b/db/versions/10549-goldenHydrangea/04-optimizeLogTables.sql @@ -0,0 +1,13 @@ +-- Place your SQL code here +OPTIMIZE TABLE vn.claimLog; +OPTIMIZE TABLE vn.itemLog; +OPTIMIZE TABLE vn.entryLog; +OPTIMIZE TABLE vn.supplierLog; +OPTIMIZE TABLE vn.zoneLog; +OPTIMIZE TABLE vn.travelLog; +OPTIMIZE TABLE vn.routeLog; +OPTIMIZE TABLE vn.clientLog; +OPTIMIZE TABLE vn.shelvingLog; +OPTIMIZE TABLE vn.ticketLog; +OPTIMIZE TABLE vn.deviceProductionLog; +OPTIMIZE TABLE vn.workerLog; \ No newline at end of file diff --git a/db/versions/10550-grayMonstera/00-editorFk.sql b/db/versions/10550-grayMonstera/00-editorFk.sql new file mode 100644 index 000000000..7e2ce329c --- /dev/null +++ b/db/versions/10550-grayMonstera/00-editorFk.sql @@ -0,0 +1,227 @@ +ALTER TABLE `vn`.`ticket` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticket_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`sale` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT sale_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`entry` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT entry_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`buy` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT buy_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`route` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT route_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`travel` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT travel_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`business` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT business_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claimBeginning` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claimBeginning_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claimDevelopment` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claimDevelopment_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claimDms` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claimDms_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claimEnd` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claimEnd_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claimObservation` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claimObservation_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claimState` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claimState_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`claim` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT claim_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`address` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT address_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`clientContact` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT clientContact_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`clientDms` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT clientDms_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`clientObservation` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT clientObservation_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`clientSample` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT clientSample_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`client` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT client_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`greuge` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT greuge_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`recovery` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT recovery_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`entryObservation` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT entryObservation_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`invoiceInTax` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT invoiceInTax_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`invoiceIn` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT invoiceIn_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`itemBarcode` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT itemBarcode_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`itemBotanical` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT itemBotanical_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`itemTag` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT itemTag_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`itemTaxCountry` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT itemTaxCountry_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`shelving` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT shelving_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`supplierAccount` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT supplierAccount_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`supplierAddress` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT supplierAddress_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`supplierContact` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT supplierContact_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`supplier` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT supplier_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`expedition` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT expedition_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketDms` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketDms_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketObservation` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketObservation_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketPackaging` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketPackaging_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketRefund` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketRefund_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketRequest` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketRequest_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketService` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketService_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketTracking` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketTracking_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`ticketWeekly` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT ticketWeekly_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`travelThermograph` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT travelThermograph_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`workerDocument` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT workerDocument_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`worker` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT worker_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`zone` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT zone_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`zoneEvent` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT zoneEvent_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`zoneExclusion` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT zoneExclusion_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`zoneIncluded` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT zoneIncluded_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `vn`.`zoneWarehouse` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT zoneWarehouse_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `account`.`user` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT user_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `account`.`account` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT account_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `account`.`mailAlias` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT mailAlias_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `account`.`mailForward` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT mailForward_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `account`.`role` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT role_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); + +ALTER TABLE `account`.`roleInherit` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT roleInherit_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); diff --git a/db/versions/10550-grayMonstera/01-originFk.sql b/db/versions/10550-grayMonstera/01-originFk.sql new file mode 100644 index 000000000..df8c19678 --- /dev/null +++ b/db/versions/10550-grayMonstera/01-originFk.sql @@ -0,0 +1,48 @@ +ALTER TABLE `vn`.`ticketLog` + CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`ticketLog` + CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`entryLog` + CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`shelvingLog` + CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`clientLog` + CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`zoneLog` + CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`routeLog` + CHANGE COLUMN `originFk` `originFk` INT(10) UNSIGNED NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`travelLog` + CHANGE COLUMN `originFk` `originFk` INT(10) UNSIGNED NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`claimLog` + CHANGE COLUMN `originFk` `originFk` INT(10) UNSIGNED NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`invoiceInLog` + CHANGE COLUMN `originFk` `originFk` MEDIUMINT(8) UNSIGNED NULL DEFAULT NULL ; + +ALTER TABLE `vn`.`workerLog` + CHANGE COLUMN `originFk` `originFk` INT(10) UNSIGNED NULL DEFAULT NULL ; + + + + + + + + + + + + + + + + diff --git a/db/versions/10552-blackAnthurium/00-firstScript.sql b/db/versions/10552-blackAnthurium/00-firstScript.sql new file mode 100644 index 000000000..15d6950c4 --- /dev/null +++ b/db/versions/10552-blackAnthurium/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.mrwService ADD kg INT; diff --git a/db/versions/10554-maroonFern/00-firstScript.sql b/db/versions/10554-maroonFern/00-firstScript.sql new file mode 100644 index 000000000..828de3ae9 --- /dev/null +++ b/db/versions/10554-maroonFern/00-firstScript.sql @@ -0,0 +1,3 @@ +DROP PROCEDURE vn.workerWeekTiming; +DROP PROCEDURE vn.workerTimeControlSetOrder_by_User_and_dateRange; + diff --git a/db/versions/10557-whiteCordyline/00-firstScript.sql b/db/versions/10557-whiteCordyline/00-firstScript.sql new file mode 100644 index 000000000..c382c279d --- /dev/null +++ b/db/versions/10557-whiteCordyline/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.itemCost ADD created TIMESTAMP DEFAULT current_timestamp() NULL; diff --git a/db/versions/10559-brownDracena/00-firstScript.sql b/db/versions/10559-brownDracena/00-firstScript.sql new file mode 100644 index 000000000..94162d308 --- /dev/null +++ b/db/versions/10559-brownDracena/00-firstScript.sql @@ -0,0 +1,15 @@ +-- Place your SQL code here +CREATE TABLE edi.offerRefreshConfig ( + id int unsigned auto_increment NOT NULL, + dayRange int unsigned NULL COMMENT 'range of days to update the photos of an article in seconds', + CONSTRAINT NewTable_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE hedera.image MODIFY COLUMN updated bigint unsigned DEFAULT NULL NULL; + +UPDATE hedera.image + SET updated = UNIX_TIMESTAMP(util.VN_NOW()) + WHERE updated > UNIX_TIMESTAMP(util.VN_NOW()); \ No newline at end of file diff --git a/db/versions/10560-crimsonCataractarum/00-firstScript.sql b/db/versions/10560-crimsonCataractarum/00-firstScript.sql new file mode 100644 index 000000000..ae01f6288 --- /dev/null +++ b/db/versions/10560-crimsonCataractarum/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.config MODIFY COLUMN dbproduccion tinyint(1) DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/db/versions/10562-whiteDendro/00-firstScript.sql b/db/versions/10562-whiteDendro/00-firstScript.sql new file mode 100644 index 000000000..c099033cd --- /dev/null +++ b/db/versions/10562-whiteDendro/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +ALTER TABLE `account`.`userLog` + CHANGE COLUMN `originFk` `originFk` INT(10) UNSIGNED NULL DEFAULT NULL ; + +ALTER TABLE `account`.`roleLog` + CHANGE COLUMN `originFk` `originFk` INT(10) UNSIGNED NULL DEFAULT NULL ; \ No newline at end of file diff --git a/db/versions/10563-azureMonstera/00-delivery_ticketFk.sql b/db/versions/10563-azureMonstera/00-delivery_ticketFk.sql new file mode 100644 index 000000000..e8ed5d20b --- /dev/null +++ b/db/versions/10563-azureMonstera/00-delivery_ticketFk.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`delivery` DROP COLUMN ticketFk; +ALTER TABLE `vn`.`delivery` ADD ticketFk INT DEFAULT NULL; +ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); diff --git a/db/.archive/231401/00-hotfixDelivery.sql b/db/versions/10566-azureArborvitae/00-firstScript.sql similarity index 85% rename from db/.archive/231401/00-hotfixDelivery.sql rename to db/versions/10566-azureArborvitae/00-firstScript.sql index c119bebad..6c69c6172 100644 --- a/db/.archive/231401/00-hotfixDelivery.sql +++ b/db/versions/10566-azureArborvitae/00-firstScript.sql @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS `vn`.`dmsRecover`; + DROP PROCEDURE IF EXISTS `vn`.`route_getTickets`; DELIMITER $$ @@ -71,7 +71,4 @@ SELECT * END$$ DELIMITER ; -ALTER TABLE `vn`.`delivery` DROP FOREIGN KEY delivery_ticketFk_FK; -ALTER TABLE `vn`.`delivery` DROP COLUMN ticketFk; -ALTER TABLE `vn`.`delivery` ADD ticketFk INT DEFAULT NULL; -ALTER TABLE `vn`.`delivery` ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`); +ALTER TABLE `vn`.`delivery` DROP COLUMN addressFk; diff --git a/db/versions/10567-salmonAspidistra/00-firstScript.sql b/db/versions/10567-salmonAspidistra/00-firstScript.sql new file mode 100644 index 000000000..a3b9c4e92 --- /dev/null +++ b/db/versions/10567-salmonAspidistra/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.auctionConfig CHANGE warehosueFk warehouseFk smallint(6) unsigned DEFAULT 7 NOT NULL COMMENT 'Default warehouse used for the calculation'; diff --git a/db/versions/10568-grayAnthurium/00-firstScript.sql b/db/versions/10568-grayAnthurium/00-firstScript.sql new file mode 100644 index 000000000..5e35ba9f7 --- /dev/null +++ b/db/versions/10568-grayAnthurium/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE util.config DROP COLUMN mockTz; +ALTER TABLE util.config ADD mockTime datetime DEFAULT NULL NULL; +ALTER TABLE util.config CHANGE mockTime mockTime datetime DEFAULT NULL NULL AFTER mockUtcTime; diff --git a/db/versions/10569-salmonLaurel/00-firstScript.sql b/db/versions/10569-salmonLaurel/00-firstScript.sql new file mode 100644 index 000000000..acba96844 --- /dev/null +++ b/db/versions/10569-salmonLaurel/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`itemLog` +CHANGE COLUMN `originFk` `originFk` INT(11) NULL DEFAULT NULL ; \ No newline at end of file diff --git a/db/versions/10570-goldenTulip/00-createSendingConfig.sql b/db/versions/10570-goldenTulip/00-createSendingConfig.sql new file mode 100644 index 000000000..471abc39c --- /dev/null +++ b/db/versions/10570-goldenTulip/00-createSendingConfig.sql @@ -0,0 +1,9 @@ +CREATE TABLE vn.sendingConfig ( + id INT auto_increment NOT NULL, + defaultWeight INT DEFAULT 13 NOT NULL, + defaultPackages INT DEFAULT 1 NOT NULL, + CONSTRAINT sendingConfig_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file diff --git a/db/versions/10570-goldenTulip/01-createSendingServiceWeekday.sql b/db/versions/10570-goldenTulip/01-createSendingServiceWeekday.sql new file mode 100644 index 000000000..2926ffd23 --- /dev/null +++ b/db/versions/10570-goldenTulip/01-createSendingServiceWeekday.sql @@ -0,0 +1,6 @@ +CREATE TABLE vn.sendingServiceWeekday ( + id INT(11) auto_increment NOT NULL, + weekdays set('mon','tue','wed','thu','fri','sat','sun') NOT NULL, + params VARCHAR(20) NOT NULL, + CONSTRAINT chronopostServiceWeekday_PK PRIMARY KEY (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de parámetros por dia de SENDING'; \ No newline at end of file diff --git a/db/versions/10570-goldenTulip/02-createSendingService.sql b/db/versions/10570-goldenTulip/02-createSendingService.sql new file mode 100644 index 000000000..6c9824333 --- /dev/null +++ b/db/versions/10570-goldenTulip/02-createSendingService.sql @@ -0,0 +1,7 @@ +CREATE TABLE vn.`sendingService` ( + `agencyModeCodeFk` varchar(45) NOT NULL, + `serviceType` varchar(45) NOT NULL DEFAULT '01', + `accountNumber` varchar(100) NOT NULL, + PRIMARY KEY (`agencyModeCodeFk`), + CONSTRAINT `sendingService_agencyModeCodeFk` FOREIGN KEY (`agencyModeCodeFk`) REFERENCES `agencyMode` (`code`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de los servicios de Sending'; \ No newline at end of file diff --git a/db/versions/10570-goldenTulip/03-permisos.sql b/db/versions/10570-goldenTulip/03-permisos.sql new file mode 100644 index 000000000..34ff35d3d --- /dev/null +++ b/db/versions/10570-goldenTulip/03-permisos.sql @@ -0,0 +1,3 @@ +GRANT SELECT ON vn.sendingConfig TO packager; +GRANT SELECT ON vn.sendingServiceWeekday TO packager; +GRANT SELECT ON vn.sendingService TO packager; \ No newline at end of file diff --git a/db/versions/10571-navyCyca/00-firstScript.sql b/db/versions/10571-navyCyca/00-firstScript.sql new file mode 100644 index 000000000..efa7750d2 --- /dev/null +++ b/db/versions/10571-navyCyca/00-firstScript.sql @@ -0,0 +1,9 @@ +-- Place your SQL code here +ALTER TABLE `postgresql`.`journey` RENAME `vn`.`businessSchedule`; + +ALTER TABLE `vn`.`businessSchedule` +CHANGE COLUMN `journey_id` `id` int(11) NOT NULL AUTO_INCREMENT, +CHANGE COLUMN `day_id` `weekday` smallint(6) NOT NULL DEFAULT 1 COMMENT 'Lunes = 1 \nDomingo = 7', +CHANGE COLUMN `start` `started` time DEFAULT NULL, +CHANGE COLUMN `end` `ended` time DEFAULT NULL, +CHANGE COLUMN `business_id` `businessFk` int(11) NOT NULL; \ No newline at end of file diff --git a/db/versions/10573-tealChico/00-firstScript.sql b/db/versions/10573-tealChico/00-firstScript.sql new file mode 100644 index 000000000..1710cd263 --- /dev/null +++ b/db/versions/10573-tealChico/00-firstScript.sql @@ -0,0 +1,11 @@ +-- Place your SQL code here +ALTER TABLE vn.entry ADD IF NOT EXISTS lockerUserFk int(10) unsigned NULL; +ALTER TABLE vn.entry ADD IF NOT EXISTS locked DATETIME DEFAULT NOW() NULL; +ALTER TABLE vn.entry ADD CONSTRAINT entryAccountFk FOREIGN KEY IF NOT EXISTS (lockerUserFk) REFERENCES account.`user`(id); + +ALTER TABLE vn.entry CHANGE isBlocked isBlocked__ tinyint(4) DEFAULT 0 NOT NULL COMMENT 'Deprecado 04/07/2023'; + +ALTER TABLE vn.entryConfig ADD IF NOT EXISTS maxLockTime int(10) unsigned NULL COMMENT 'Tiempo máximo que puede estar una entrada bloqueada en segundos'; + +UPDATE vn.entryConfig + SET maxLockTime = 300; \ No newline at end of file diff --git a/db/versions/10575-crimsonAnthurium/00-firstScript.sql b/db/versions/10575-crimsonAnthurium/00-firstScript.sql new file mode 100644 index 000000000..8c4aa1b94 --- /dev/null +++ b/db/versions/10575-crimsonAnthurium/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`alertLevel` +ADD COLUMN `hasToRecalcPrice` TINYINT(1) NOT NULL DEFAULT 0 AFTER `id`; diff --git a/db/versions/10577-salmonMonstera/00-firstScript.sql b/db/versions/10577-salmonMonstera/00-firstScript.sql new file mode 100644 index 000000000..5e9ac76fb --- /dev/null +++ b/db/versions/10577-salmonMonstera/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.itemImageQueue MODIFY COLUMN url varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; diff --git a/db/versions/10578-brownCarnation/00-firstScript.sql b/db/versions/10578-brownCarnation/00-firstScript.sql new file mode 100644 index 000000000..807fcf24e --- /dev/null +++ b/db/versions/10578-brownCarnation/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +ALTER TABLE vn.routeLoadWorker DROP FOREIGN KEY IF EXISTS frmRutas; +ALTER TABLE vn.routeLoadWorker DROP FOREIGN KEY IF EXISTS frmWorker; + +RENAME TABLE vn.routeLoadWorker TO vn.routeLoadWorker__; +ALTER TABLE vn.routeLoadWorker__ COMMENT= 'Table deprecated on 26/04/23'; \ No newline at end of file diff --git a/db/versions/10579-aquaRoebelini/00-firstScript.sql b/db/versions/10579-aquaRoebelini/00-firstScript.sql new file mode 100644 index 000000000..41c59d61b --- /dev/null +++ b/db/versions/10579-aquaRoebelini/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.farming ADD companyFk smallint(5) unsigned NULL; +ALTER TABLE vn.farming ADD CONSTRAINT farming_FK_1 FOREIGN KEY (companyFk) REFERENCES vn.company(id); diff --git a/db/versions/10580-purpleCataractarum/00-itemTypeDropConstraint.sql b/db/versions/10580-purpleCataractarum/00-itemTypeDropConstraint.sql new file mode 100644 index 000000000..2a47637f3 --- /dev/null +++ b/db/versions/10580-purpleCataractarum/00-itemTypeDropConstraint.sql @@ -0,0 +1 @@ +ALTER TABLE vn.item DROP FOREIGN KEY item_FK_1; diff --git a/db/versions/10580-purpleCataractarum/01-itemTypeAddConstraint.sql b/db/versions/10580-purpleCataractarum/01-itemTypeAddConstraint.sql new file mode 100644 index 000000000..f872b43fa --- /dev/null +++ b/db/versions/10580-purpleCataractarum/01-itemTypeAddConstraint.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.item + ADD CONSTRAINT item_FK_1 FOREIGN KEY (typeFk) REFERENCES vn.itemType(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10581-grayPaniculata/00-itemTypeAutoIncrement.sql b/db/versions/10581-grayPaniculata/00-itemTypeAutoIncrement.sql new file mode 100644 index 000000000..854d1accf --- /dev/null +++ b/db/versions/10581-grayPaniculata/00-itemTypeAutoIncrement.sql @@ -0,0 +1,29 @@ +ALTER TABLE edi .item_groupToOffer DROP CONSTRAINT IF EXISTS item_groupToOffer_fk2 ; +ALTER TABLE bs .waste DROP CONSTRAINT IF EXISTS waste_itemType_id ; +ALTER TABLE vn .itemTypeTag DROP CONSTRAINT IF EXISTS itemTypeTag_FK ; +ALTER TABLE vn .itemTypeRestriction DROP CONSTRAINT IF EXISTS itemTypeRestriction_FK ; +ALTER TABLE vn .clientItemType DROP CONSTRAINT IF EXISTS clientItemType_FK_1 ; +ALTER TABLE vn .agencyModeItemType DROP CONSTRAINT IF EXISTS agencyModeItemType_FK_1 ; +ALTER TABLE vn .item DROP CONSTRAINT IF EXISTS item_FK_1 ; +ALTER TABLE vn .zoneItemType DROP CONSTRAINT IF EXISTS zoneItemType_FK_1 ; +ALTER TABLE vn .zoneFilter DROP CONSTRAINT IF EXISTS zoneFilter_FK_1 ; +ALTER TABLE hedera.shelfConfig DROP CONSTRAINT IF EXISTS shelfConfig_ibfk_1 ; +ALTER TABLE bi .analisis_ventas_familia_evolution DROP CONSTRAINT IF EXISTS analisis_ventas_familia_evolution_FK; +ALTER TABLE bs .salesByItemTypeDay DROP CONSTRAINT IF EXISTS itemTypeSalesByweek_itemTypeFk ; +ALTER TABLE bs .sale DROP CONSTRAINT IF EXISTS sale_FK_3 ; + +ALTER TABLE vn.itemType MODIFY COLUMN id smallint(5) unsigned auto_increment NOT NULL; + +ALTER TABLE edi .item_groupToOffer ADD CONSTRAINT item_groupToOffer_fk2 FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE bs .waste ADD CONSTRAINT waste_itemType_id FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn .itemTypeTag ADD CONSTRAINT itemTypeTag_FK FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn .itemTypeRestriction ADD CONSTRAINT itemTypeRestriction_FK FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn .clientItemType ADD CONSTRAINT clientItemType_FK_1 FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn .agencyModeItemType ADD CONSTRAINT agencyModeItemType_FK_1 FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn .item ADD CONSTRAINT item_FK_1 FOREIGN KEY IF NOT EXISTS (typeFk ) REFERENCES vn.itemType(id); +ALTER TABLE vn .zoneItemType ADD CONSTRAINT zoneItemType_FK_1 FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE vn .zoneFilter ADD CONSTRAINT zoneFilter_FK_1 FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE hedera.shelfConfig ADD CONSTRAINT shelfConfig_ibfk_1 FOREIGN KEY IF NOT EXISTS (family ) REFERENCES vn.itemType(id); +ALTER TABLE bi .analisis_ventas_familia_evolution ADD CONSTRAINT analisis_ventas_familia_evolution_FK FOREIGN KEY IF NOT EXISTS (typeFk ) REFERENCES vn.itemType(id); +ALTER TABLE bs .salesByItemTypeDay ADD CONSTRAINT itemTypeSalesByweek_itemTypeFk FOREIGN KEY IF NOT EXISTS (itemTypeFk) REFERENCES vn.itemType(id); +ALTER TABLE bs .sale ADD CONSTRAINT sale_FK_3 FOREIGN KEY IF NOT EXISTS (typeFk ) REFERENCES vn.itemType(id); diff --git a/db/versions/10582-purpleOrchid/00-firstScript.sql b/db/versions/10582-purpleOrchid/00-firstScript.sql new file mode 100644 index 000000000..3ff779c9d --- /dev/null +++ b/db/versions/10582-purpleOrchid/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.packingSite MODIFY COLUMN hostFk int(11) NULL; + diff --git a/db/versions/10583-turquoiseGerbera/00-firstScript.sql b/db/versions/10583-turquoiseGerbera/00-firstScript.sql new file mode 100644 index 000000000..cdbcfa04e --- /dev/null +++ b/db/versions/10583-turquoiseGerbera/00-firstScript.sql @@ -0,0 +1 @@ +DROP SCHEMA `ext`; diff --git a/db/versions/10584-azureGerbera/00-firstScript.sql b/db/versions/10584-azureGerbera/00-firstScript.sql new file mode 100644 index 000000000..09ee9381b --- /dev/null +++ b/db/versions/10584-azureGerbera/00-firstScript.sql @@ -0,0 +1,10 @@ +ALTER TABLE `vn`.`agencyModeItemType` +ADD UNIQUE INDEX `agencyModeFk_ItemType_UNIQUE` (`agencyModeFk` ASC, `itemTypeFk` ASC) VISIBLE; + +ALTER TABLE `vn`.`clientItemType` +ADD UNIQUE INDEX `clientFk_itemTypeFk_UNIQUE` (`clientFk` ASC, `itemTypeFk` ASC) VISIBLE; + +ALTER TABLE `vn`.`zoneItemType` +ADD UNIQUE INDEX `zoneType_itemTypeFk_UNIQUE` (`zoneFk` ASC, `itemTypeFk` ASC) VISIBLE; + + diff --git a/db/versions/10585-pinkMedeola/00-ticketLog.sql b/db/versions/10585-pinkMedeola/00-ticketLog.sql new file mode 100644 index 000000000..2a2d2cf68 --- /dev/null +++ b/db/versions/10585-pinkMedeola/00-ticketLog.sql @@ -0,0 +1,10 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`ticketLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Ticket', 'Sale', 'TicketWeekly', 'TicketTracking', 'TicketService', 'TicketRequest', 'TicketRefund', 'TicketPackaging', 'TicketObservation', 'TicketDms', 'Expedition', 'Sms') NOT NULL DEFAULT 'Ticket', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `ticketLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `ticketLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `ticketLog_creationDate_IDX` , +DROP INDEX IF EXISTS `logTicketoriginFk` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/01-entryLog.sql b/db/versions/10585-pinkMedeola/01-entryLog.sql new file mode 100644 index 000000000..ce4940533 --- /dev/null +++ b/db/versions/10585-pinkMedeola/01-entryLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`entryLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Entry', 'Buy', 'EntryObservation') NOT NULL DEFAULT 'Entry' , +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `entryLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `entryLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `logEntry_ibfk_1` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/02-claimLog.sql b/db/versions/10585-pinkMedeola/02-claimLog.sql new file mode 100644 index 000000000..41684c190 --- /dev/null +++ b/db/versions/10585-pinkMedeola/02-claimLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`claimLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Claim', 'ClaimBeginning','ClaimState', 'ClaimDevelopment', 'ClaimDms', 'ClaimEnd', 'ClaimObservation') NOT NULL DEFAULT 'Claim', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `claimLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `claimLog_claimLog` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/03-clientLog.sql b/db/versions/10585-pinkMedeola/03-clientLog.sql new file mode 100644 index 000000000..b7c21aa8f --- /dev/null +++ b/db/versions/10585-pinkMedeola/03-clientLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`clientLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Client', 'Address', 'ClientContact', 'ClientDms', 'ClientObservation', 'ClientSample', 'Greuge', 'Recovery', 'TpvTransaction', 'WorkerDms', 'Sms') NOT NULL DEFAULT 'Client', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `clientLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `clientLog_clientLog` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/04-invoiceInLog.sql b/db/versions/10585-pinkMedeola/04-invoiceInLog.sql new file mode 100644 index 000000000..b9b8ff95b --- /dev/null +++ b/db/versions/10585-pinkMedeola/04-invoiceInLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`invoiceInLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('InvoiceIn', 'invoiceInTax') NOT NULL DEFAULT 'InvoiceIn', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `invoiceInLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `invoiceInLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/05-itemLog.sql b/db/versions/10585-pinkMedeola/05-itemLog.sql new file mode 100644 index 000000000..cd82e943b --- /dev/null +++ b/db/versions/10585-pinkMedeola/05-itemLog.sql @@ -0,0 +1,9 @@ +ALTER TABLE `vn`.`itemLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Item', 'ItemBarcode', 'ItemBotanical', 'ItemNiche', 'ItemTag', 'ItemTaxCountry') NOT NULL DEFAULT 'Item', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +DROP INDEX IF EXISTS `itemLog_changedModel_idx` , +ADD INDEX IF NOT EXISTS `itemLog_changedModel_idx` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `itemLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `itemLogItemFk_idx` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/06-routeLog.sql b/db/versions/10585-pinkMedeola/06-routeLog.sql new file mode 100644 index 000000000..d35a6a503 --- /dev/null +++ b/db/versions/10585-pinkMedeola/06-routeLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`routeLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Route') NOT NULL DEFAULT 'Route', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `routeLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `routeLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/07-shelvingLog.sql b/db/versions/10585-pinkMedeola/07-shelvingLog.sql new file mode 100644 index 000000000..34c190a99 --- /dev/null +++ b/db/versions/10585-pinkMedeola/07-shelvingLog.sql @@ -0,0 +1,15 @@ +ALTER TABLE `vn`.`shelvingLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Shelving') NOT NULL DEFAULT 'Shelving', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `shelvingLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `shelvingLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; +; +ALTER TABLE `vn`.`shelvingLog` +ADD CONSTRAINT `shelvingLog_ibfk_1` + FOREIGN KEY IF NOT EXISTS (`originFk`) + REFERENCES `vn`.`shelving` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/08-supplierLog.sql b/db/versions/10585-pinkMedeola/08-supplierLog.sql new file mode 100644 index 000000000..b82d3f060 --- /dev/null +++ b/db/versions/10585-pinkMedeola/08-supplierLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`supplierLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Supplier', 'SupplierAddress', 'SupplierAccount', 'SupplierContact') NOT NULL DEFAULT 'Supplier', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `supplierLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `supplierLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `logSupplier_ibfk_1` ; diff --git a/db/versions/10585-pinkMedeola/09-travelLog.sql b/db/versions/10585-pinkMedeola/09-travelLog.sql new file mode 100644 index 000000000..058f2ca32 --- /dev/null +++ b/db/versions/10585-pinkMedeola/09-travelLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`travelLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Travel', 'TravelThermograph') NOT NULL DEFAULT 'Travel', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `travelLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `originFk` ASC), +ADD INDEX IF NOT EXISTS `travelLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/10-workerLog.sql b/db/versions/10585-pinkMedeola/10-workerLog.sql new file mode 100644 index 000000000..01528c6f9 --- /dev/null +++ b/db/versions/10585-pinkMedeola/10-workerLog.sql @@ -0,0 +1,8 @@ +ALTER TABLE `vn`.`workerLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Worker', 'workerDocument', 'Calendar', 'WorkerTimeControlMail') NOT NULL DEFAULT 'Worker', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `workerLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `workerLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `workerFk_idx` ; diff --git a/db/versions/10585-pinkMedeola/11-zoneLog.sql b/db/versions/10585-pinkMedeola/11-zoneLog.sql new file mode 100644 index 000000000..cb27a535c --- /dev/null +++ b/db/versions/10585-pinkMedeola/11-zoneLog.sql @@ -0,0 +1,9 @@ +ALTER TABLE `vn`.`zoneLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Zone', 'ZoneEvent', 'ZoneExclusion', 'ZoneIncluded', 'ZoneWarehouse') NOT NULL DEFAULT 'Zone', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `zoneLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `zoneLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; +; \ No newline at end of file diff --git a/db/versions/10585-pinkMedeola/12-userLog.sql b/db/versions/10585-pinkMedeola/12-userLog.sql new file mode 100644 index 000000000..6cface450 --- /dev/null +++ b/db/versions/10585-pinkMedeola/12-userLog.sql @@ -0,0 +1,9 @@ +ALTER TABLE `account`.`userLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('User') NOT NULL DEFAULT 'User', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `userLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `userLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; +; diff --git a/db/versions/10585-pinkMedeola/13-roleLog.sql b/db/versions/10585-pinkMedeola/13-roleLog.sql new file mode 100644 index 000000000..75c037eb4 --- /dev/null +++ b/db/versions/10585-pinkMedeola/13-roleLog.sql @@ -0,0 +1,9 @@ +ALTER TABLE `account`.`roleLog` +CHANGE COLUMN `changedModel` `changedModel` ENUM('Role') NOT NULL DEFAULT 'Role', +MODIFY COLUMN changedModelId INT(11) NOT NULL, +MODIFY COLUMN oldInstance JSON NULL, +MODIFY COLUMN newInstance JSON NULL, +ADD INDEX IF NOT EXISTS `roleLog_changedModel` (`changedModel` ASC, `changedModelId` ASC, `creationDate` ASC), +ADD INDEX IF NOT EXISTS `roleLog_originFk` (`originFk` ASC, `creationDate` ASC), +DROP INDEX IF EXISTS `originFk` ; +; diff --git a/db/versions/10587-navyOak/00-arcRead_addMinimum.sql b/db/versions/10587-navyOak/00-arcRead_addMinimum.sql new file mode 100644 index 000000000..97af35911 --- /dev/null +++ b/db/versions/10587-navyOak/00-arcRead_addMinimum.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`arcRead` ADD minimum TINYINT NULL; diff --git a/db/versions/10593-greenLilium/00-firstScript.sql b/db/versions/10593-greenLilium/00-firstScript.sql new file mode 100644 index 000000000..f6e04b0a1 --- /dev/null +++ b/db/versions/10593-greenLilium/00-firstScript.sql @@ -0,0 +1,7 @@ +CREATE TABLE `vn`.`vehiclePlateRegex` ( + `countryCodeFk` VARCHAR(2) NOT NULL, + `regex` VARCHAR(45) NOT NULL, + PRIMARY KEY (`countryCodeFk`)); + +ALTER TABLE `vn`.`vehicle` +ADD COLUMN `countryCodeFk` VARCHAR(2) NULL DEFAULT 'ES' AFTER `ppeFk`; \ No newline at end of file diff --git a/db/versions/10596-purpleCamellia/00-firstScript.sql b/db/versions/10596-purpleCamellia/00-firstScript.sql new file mode 100644 index 000000000..2fba524d0 --- /dev/null +++ b/db/versions/10596-purpleCamellia/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.company CHANGE footnotes footnotes__ longtext CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'pie de paginas en las facturas'; diff --git a/db/versions/10597-navyAralia/00-firstScript.sql b/db/versions/10597-navyAralia/00-firstScript.sql new file mode 100644 index 000000000..bad3c3939 --- /dev/null +++ b/db/versions/10597-navyAralia/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.vehicle ADD leasing varchar(50) NULL COMMENT 'Id de arrendamiento'; diff --git a/db/versions/10598-purpleGalax/00-workerLog.sql b/db/versions/10598-purpleGalax/00-workerLog.sql new file mode 100644 index 000000000..7a5081c5e --- /dev/null +++ b/db/versions/10598-purpleGalax/00-workerLog.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.workerLog +MODIFY COLUMN userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10598-purpleGalax/01-supplierLog.sql b/db/versions/10598-purpleGalax/01-supplierLog.sql new file mode 100644 index 000000000..ca0eea44b --- /dev/null +++ b/db/versions/10598-purpleGalax/01-supplierLog.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.supplierLog +MODIFY COLUMN userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10598-purpleGalax/02-workerTimeControlLog.sql b/db/versions/10598-purpleGalax/02-workerTimeControlLog.sql new file mode 100644 index 000000000..83dc5bb1e --- /dev/null +++ b/db/versions/10598-purpleGalax/02-workerTimeControlLog.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.workerTimeControlLog +MODIFY COLUMN userFk int(10) DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10598-purpleGalax/03-workerClockLog.sql b/db/versions/10598-purpleGalax/03-workerClockLog.sql new file mode 100644 index 000000000..2cbcb2b9b --- /dev/null +++ b/db/versions/10598-purpleGalax/03-workerClockLog.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.workerClockLog +MODIFY COLUMN userFk int(10) unsigned DEFAULT NULL NULL; diff --git a/db/versions/10599-orangeHydrangea/00-firstScript.sql b/db/versions/10599-orangeHydrangea/00-firstScript.sql new file mode 100644 index 000000000..92aa037af --- /dev/null +++ b/db/versions/10599-orangeHydrangea/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.expeditionTruck CHANGE ETD eta datetime DEFAULT NULL NULL COMMENT 'Estimated time of arrival'; +ALTER TABLE vn.expeditionTruck ADD COLUMN ETD DATETIME AS (eta) VIRTUAL; \ No newline at end of file diff --git a/db/versions/10601-orangeErica/00-firstScript.sql b/db/versions/10601-orangeErica/00-firstScript.sql new file mode 100644 index 000000000..017309dfb --- /dev/null +++ b/db/versions/10601-orangeErica/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.expedition + MODIFY COLUMN hasNewRoute BOOL DEFAULT FALSE NOT NULL; diff --git a/db/versions/10602-whiteArborvitae/00-firstScript.sql b/db/versions/10602-whiteArborvitae/00-firstScript.sql new file mode 100644 index 000000000..62e01601b --- /dev/null +++ b/db/versions/10602-whiteArborvitae/00-firstScript.sql @@ -0,0 +1,3 @@ + +ALTER TABLE vn.workerTimeControlConfig DROP COLUMN dateSplitDay; +ALTER TABLE vn.workerTimeControlConfig DROP COLUMN breakTimeSplitDay; diff --git a/db/versions/10606-pinkChico/00-firstScript.sql b/db/versions/10606-pinkChico/00-firstScript.sql new file mode 100644 index 000000000..4c1bde562 --- /dev/null +++ b/db/versions/10606-pinkChico/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.farming MODIFY COLUMN location varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; diff --git a/db/versions/10608-pinkAsparagus/00-firstScript.sql b/db/versions/10608-pinkAsparagus/00-firstScript.sql new file mode 100644 index 000000000..a8795aa9b --- /dev/null +++ b/db/versions/10608-pinkAsparagus/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.farming MODIFY COLUMN warehouseFk smallint(6) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10609-grayRaphis/00-firstScript.sql b/db/versions/10609-grayRaphis/00-firstScript.sql new file mode 100644 index 000000000..df72131ba --- /dev/null +++ b/db/versions/10609-grayRaphis/00-firstScript.sql @@ -0,0 +1,19 @@ +USE account; +ALTER TABLE userLog PAGE_COMPRESSED=1; +ALTER TABLE roleLog PAGE_COMPRESSED=1; + +USE vn; +ALTER TABLE supplierLog PAGE_COMPRESSED=1; +ALTER TABLE deviceProductionLog PAGE_COMPRESSED=1; +ALTER TABLE routeLog PAGE_COMPRESSED=1; +ALTER TABLE itemLog PAGE_COMPRESSED=1; +ALTER TABLE userLog PAGE_COMPRESSED=1; +ALTER TABLE invoiceInLog PAGE_COMPRESSED=1; +ALTER TABLE zoneLog PAGE_COMPRESSED=1; +ALTER TABLE clientLog PAGE_COMPRESSED=1; +ALTER TABLE workerLog PAGE_COMPRESSED=1; +ALTER TABLE ticketLog PAGE_COMPRESSED=1; +ALTER TABLE claimLog PAGE_COMPRESSED=1; +ALTER TABLE travelLog PAGE_COMPRESSED=1; +ALTER TABLE shelvingLog PAGE_COMPRESSED=1; +ALTER TABLE entryLog PAGE_COMPRESSED=1; diff --git a/db/versions/10610-goldenArborvitae/00-updateCompanyId.sql b/db/versions/10610-goldenArborvitae/00-updateCompanyId.sql new file mode 100644 index 000000000..5e323b6c8 --- /dev/null +++ b/db/versions/10610-goldenArborvitae/00-updateCompanyId.sql @@ -0,0 +1,104 @@ +-- Place your SQL code here +ALTER TABLE hedera.`orderConfig` DROP FOREIGN KEY IF EXISTS `orderConfig_ibfk_2`; +ALTER TABLE vn.`project` DROP FOREIGN KEY IF EXISTS `project_FK_2`; +ALTER TABLE vn.`vehicle` DROP FOREIGN KEY IF EXISTS `vehicle_ibfk_1`; +ALTER TABLE vn.`routeConfig` DROP FOREIGN KEY IF EXISTS `routeConfig_FK`; +ALTER TABLE vn.`entry` DROP FOREIGN KEY IF EXISTS `entry_ibfk_7`; +ALTER TABLE vn.`payment` DROP FOREIGN KEY IF EXISTS `payment_ibfk_1`; +ALTER TABLE vn.`receipt` DROP FOREIGN KEY IF EXISTS `receipt_ibfk_1`; +ALTER TABLE vn.`invoiceIn` DROP FOREIGN KEY IF EXISTS `invoiceIn_ibfk_2`; +ALTER TABLE vn.`sinister` DROP FOREIGN KEY IF EXISTS `sinister_fk4`; +ALTER TABLE vn.`supplierExpense` DROP FOREIGN KEY IF EXISTS `pago_ibfk_1`; +ALTER TABLE vn.`ticket` DROP FOREIGN KEY IF EXISTS `ticket_ibfk_5`; +ALTER TABLE vn.`mandate` DROP FOREIGN KEY IF EXISTS `mandato_fgkey2`; +ALTER TABLE vn.`XDiario` DROP FOREIGN KEY IF EXISTS `XDiario_ibfk_1`; +ALTER TABLE vn.`dms` DROP FOREIGN KEY IF EXISTS `dms_companyFk`; +ALTER TABLE vn.`property` DROP FOREIGN KEY IF EXISTS `property_company`; +ALTER TABLE vn.`cmr` DROP FOREIGN KEY IF EXISTS `cmr_fk2`; +ALTER TABLE vn.`host` DROP FOREIGN KEY IF EXISTS `configHost_FK_3`; +ALTER TABLE vn.`clientRisk` DROP FOREIGN KEY IF EXISTS `clientRisk_ibfk_2`; +ALTER TABLE vn.`ppe` DROP FOREIGN KEY IF EXISTS `ppe_fk4`; +ALTER TABLE vn.`invoiceOut` DROP FOREIGN KEY IF EXISTS `invoiceOut_ibfk_1`; +ALTER TABLE vn.`dua` DROP FOREIGN KEY IF EXISTS `dua_fk4`; +ALTER TABLE vn.`clientSample` DROP FOREIGN KEY IF EXISTS `clientSample_ibfk_1`; +ALTER TABLE vn2008.`Saldos_Prevision` DROP FOREIGN KEY IF EXISTS `empresa_prevision`; +ALTER TABLE vn2008.`pago_sdc` DROP FOREIGN KEY IF EXISTS `empresa_sdc`; +ALTER TABLE vn2008.`Clientes_empresa` DROP FOREIGN KEY IF EXISTS `empresa_id`; +ALTER TABLE vn2008.`Bancos_poliza` DROP FOREIGN KEY IF EXISTS `Id_Poliza_Empresa`; +ALTER TABLE vn2008.`Permisos` DROP FOREIGN KEY IF EXISTS `Permisos_ibfk_1`; +ALTER TABLE vn2008.`albaran` DROP FOREIGN KEY IF EXISTS `fk_albaran_empresa1`; +ALTER TABLE vn2008.`Remesas` DROP FOREIGN KEY IF EXISTS `Remesas_ibfk_1`; +ALTER TABLE vn2008.`Enlaces Facturas__` DROP FOREIGN KEY IF EXISTS `Enlaces@0020Facturas_ibfk_1`; +ALTER TABLE bs.`sale` DROP FOREIGN KEY IF EXISTS `sale_FK_2`; +ALTER TABLE vn.`farming` DROP FOREIGN KEY IF EXISTS `farming_Fk_1`; +ALTER TABLE vn.companyI18n DROP FOREIGN KEY IF EXISTS companyI18n_FK; + + +ALTER TABLE vn.company MODIFY COLUMN id INT UNSIGNED NOT NULL; +ALTER TABLE hedera.`orderConfig` MODIFY COLUMN defaultCompanyFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`project` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`vehicle` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`routeConfig` MODIFY COLUMN defaultCompanyFk INT UNSIGNED DEFAULT 442; +ALTER TABLE vn.`entry` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`payment` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`receipt` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`invoiceIn` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`sinister` MODIFY COLUMN companyFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`supplierExpense` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`ticket` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`mandate` MODIFY COLUMN companyFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`XDiario` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`dms` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`property` MODIFY COLUMN companyFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`cmr` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`host` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442; +ALTER TABLE vn.`clientRisk` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 0 NOT NULL ; +ALTER TABLE vn.`ppe` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +-- ALTER TABLE vn.`invoiceOut` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`dua` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`clientSample` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn2008.`Saldos_Prevision` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn2008.`pago_sdc` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn2008.`Clientes_empresa` MODIFY COLUMN empresa_id INT UNSIGNED NOT NULL ; +ALTER TABLE vn2008.`Bancos_poliza` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn2008.`Permisos` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn2008.`albaran` MODIFY COLUMN empresa_id INT UNSIGNED NOT NULL ; +ALTER TABLE vn2008.`Remesas` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn2008.`Enlaces Facturas__` MODIFY COLUMN empresa_id INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE bs.`sale` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.`farming` MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL ; +ALTER TABLE vn.companyI18n MODIFY COLUMN companyFk INT UNSIGNED NOT NULL; + +ALTER TABLE hedera.`orderConfig` ADD CONSTRAINT `orderConfigCompany_Fk` FOREIGN KEY IF NOT EXISTS (defaultCompanyFk) REFERENCES vn.company(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`project` ADD CONSTRAINT `projectCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`vehicle` ADD CONSTRAINT `vehicleCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`routeConfig` ADD CONSTRAINT `routeConfigCompany_Fk` FOREIGN KEY IF NOT EXISTS (defaultCompanyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.`entry` ADD CONSTRAINT `entryCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`payment` ADD CONSTRAINT `paymentCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`receipt` ADD CONSTRAINT `receiptCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`invoiceIn` ADD CONSTRAINT `invoiceInCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`sinister` ADD CONSTRAINT `sinisterCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`supplierExpense` ADD CONSTRAINT `supplierExpenseCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`ticket` ADD CONSTRAINT `ticketCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`mandate` ADD CONSTRAINT `mandateCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE NO ACTION ON UPDATE CASCADE; +ALTER TABLE vn.`XDiario` ADD CONSTRAINT `XDiarioCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`dms` ADD CONSTRAINT `dmsCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`property` ADD CONSTRAINT `propertyCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`cmr` ADD CONSTRAINT `cmrCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn.`host` ADD CONSTRAINT `hostCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`clientRisk` ADD CONSTRAINT `clientRiskCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`ppe` ADD CONSTRAINT `ppeCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +-- ALTER TABLE vn.`invoiceOut` ADD CONSTRAINT `invoiceOutCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`dua` ADD CONSTRAINT `duaCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`clientSample` ADD CONSTRAINT `clientSampleCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Saldos_Prevision` ADD CONSTRAINT `Saldos_PrevisionCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`pago_sdc` ADD CONSTRAINT `pago_sdcCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Clientes_empresa` ADD CONSTRAINT `Clientes_empresaCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE NO ACTION ON UPDATE RESTRICT; +ALTER TABLE vn2008.`Bancos_poliza` ADD CONSTRAINT `Bancos_polizaCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Permisos` ADD CONSTRAINT `PermisosCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn2008.`albaran` ADD CONSTRAINT `albaranCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Remesas` ADD CONSTRAINT `RemesasCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Enlaces Facturas__` ADD CONSTRAINT `EnlacesFacturas__Company_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE bs.`sale` ADD CONSTRAINT `saleCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`farming` ADD CONSTRAINT `farmingCompany_Fk` FOREIGN KEY IF NOT EXISTS(companyFk) REFERENCES vn.company(id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.`companyI18n` ADD CONSTRAINT `companyI18nCompany_Fk` FOREIGN KEY IF NOT EXISTS(companyFk) REFERENCES vn.company(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10610-goldenArborvitae/01-updateSupplierId.sql b/db/versions/10610-goldenArborvitae/01-updateSupplierId.sql new file mode 100644 index 000000000..89eee7ac2 --- /dev/null +++ b/db/versions/10610-goldenArborvitae/01-updateSupplierId.sql @@ -0,0 +1,80 @@ +ALTER TABLE vn.`budget` DROP FOREIGN KEY IF EXISTS `budget_FK_3`; +ALTER TABLE vn.`supplierContact` DROP FOREIGN KEY IF EXISTS `supplier_id`; +ALTER TABLE vn.`entry` DROP FOREIGN KEY IF EXISTS `entry_ibfk_1`; +ALTER TABLE vn.`payment` DROP FOREIGN KEY IF EXISTS `pago_ibfk_3`; +ALTER TABLE vn.`travelClonedWeekly` DROP FOREIGN KEY IF EXISTS `travelClonedWeekly_FK_3`; +ALTER TABLE vn.`invoiceIn` DROP FOREIGN KEY IF EXISTS `invoiceIn_ibfk_1`; +ALTER TABLE vn.`sinister` DROP FOREIGN KEY IF EXISTS `sinister_fk1`; +ALTER TABLE vn.`comparativeFilter` DROP FOREIGN KEY IF EXISTS `comparativeFilter_FK_2`; +ALTER TABLE vn.`supplierExpense` DROP FOREIGN KEY IF EXISTS `proveedor_pago`; +ALTER TABLE vn.`supplierAccount` DROP FOREIGN KEY IF EXISTS `supplierAccount_FK`; +ALTER TABLE vn.`roadmap` DROP FOREIGN KEY IF EXISTS `roadmap_ibfk_1`; +ALTER TABLE vn.`awb` DROP FOREIGN KEY IF EXISTS `awbTransitoryFk`; +ALTER TABLE vn.`awb` DROP FOREIGN KEY IF EXISTS `awb_FK_2`; +ALTER TABLE vn.`supplierLog` DROP FOREIGN KEY IF EXISTS `supplierLog_ibfk_1`; +ALTER TABLE vn.`cmr` DROP FOREIGN KEY IF EXISTS `cm_fk4`; +ALTER TABLE vn.`duaTax` DROP FOREIGN KEY IF EXISTS `duaTax_fk2`; +ALTER TABLE vn.`supplierAgencyTerm` DROP FOREIGN KEY IF EXISTS `agencyTerm_FK_1`; +ALTER TABLE vn.`machine` DROP FOREIGN KEY IF EXISTS `machine_FK_2`; +ALTER TABLE vn2008.`travel_pattern` DROP FOREIGN KEY IF EXISTS `travel_pattern_ibfk_6`; +ALTER TABLE vn2008.`Bancos_poliza` DROP FOREIGN KEY IF EXISTS `bankNotaryIdx3`; +ALTER TABLE vn2008.`Bancos_poliza` DROP FOREIGN KEY IF EXISTS `bankSupplierIdx1`; +ALTER TABLE vn2008.`Vehiculos_consumo` DROP FOREIGN KEY IF EXISTS `proveedoresFk`; +ALTER TABLE vn2008.`albaran` DROP FOREIGN KEY IF EXISTS `fk_albaran_Proveedores`; +ALTER TABLE vn2008.`Proveedores_cargueras` DROP FOREIGN KEY IF EXISTS `proveedores_cargueras_fk1`; +ALTER TABLE vn2008.`Proveedores_comunicados` DROP FOREIGN KEY IF EXISTS `Proveedores_comunicados_ibfk_3`; + +ALTER TABLE vn.supplier MODIFY COLUMN id INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`budget` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`supplierContact` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`entry` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT 644 NOT NULL ; +ALTER TABLE vn.`payment` MODIFY COLUMN supplierFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`travelClonedWeekly` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`invoiceIn` MODIFY COLUMN supplierFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`sinister` MODIFY COLUMN supplierFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`comparativeFilter` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`supplierExpense` MODIFY COLUMN supplierFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`supplierAccount` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`roadmap` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`awb` MODIFY COLUMN transitoryFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`awb` MODIFY COLUMN freightFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`supplierLog` MODIFY COLUMN originFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`cmr` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`duaTax` MODIFY COLUMN supplierFk INT UNSIGNED NOT NULL ; +ALTER TABLE vn.`supplierAgencyTerm` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn.`machine` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn2008.`travel_pattern` MODIFY COLUMN cargoSupplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn2008.`Bancos_poliza` MODIFY COLUMN notaryFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn2008.`Bancos_poliza` MODIFY COLUMN supplierFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn2008.`Vehiculos_consumo` MODIFY COLUMN proveedoresFk INT UNSIGNED DEFAULT NULL; +ALTER TABLE vn2008.`albaran` MODIFY COLUMN Id_Proveedor INT UNSIGNED NOT NULL ; +ALTER TABLE vn2008.`Proveedores_cargueras` MODIFY COLUMN Id_Proveedor INT UNSIGNED NOT NULL ; +ALTER TABLE vn2008.`Proveedores_comunicados` MODIFY COLUMN Id_Proveedor INT UNSIGNED NOT NULL ; + +ALTER TABLE vn.`budget` ADD CONSTRAINT `budgetSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`supplierContact` ADD CONSTRAINT `supplierContactSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`entry` ADD CONSTRAINT `entrySupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`payment` ADD CONSTRAINT `paymentSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`travelClonedWeekly` ADD CONSTRAINT `travelClonedWeeklySupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn.`invoiceIn` ADD CONSTRAINT `invoiceInSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`sinister` ADD CONSTRAINT `sinisterSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`comparativeFilter` ADD CONSTRAINT `comparativeFilterSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.`supplierExpense` ADD CONSTRAINT `supplierExpenseSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`supplierAccount` ADD CONSTRAINT `supplierAccountSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`roadmap` ADD CONSTRAINT `roadmapSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`awb` ADD CONSTRAINT `awbSupplier_Fk` FOREIGN KEY IF NOT EXISTS (transitoryFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`awb` ADD CONSTRAINT `awbSupplier_Fk` FOREIGN KEY IF NOT EXISTS (freightFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`supplierLog` ADD CONSTRAINT `supplierLogSupplier_Fk` FOREIGN KEY IF NOT EXISTS (originFk) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`cmr` ADD CONSTRAINT `cmrSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`duaTax` ADD CONSTRAINT `duaTaxSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`supplierAgencyTerm` ADD CONSTRAINT `supplierAgencyTermSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`machine` ADD CONSTRAINT `machineSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn2008.`travel_pattern` ADD CONSTRAINT `travel_patternSupplier_Fk` FOREIGN KEY IF NOT EXISTS (cargoSupplierFk) REFERENCES vn.supplier (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn2008.`Bancos_poliza` ADD CONSTRAINT `Bancos_polizaSupplier_Fk` FOREIGN KEY IF NOT EXISTS (notaryFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Bancos_poliza` ADD CONSTRAINT `Bancos_polizaSupplier_Fk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Vehiculos_consumo` ADD CONSTRAINT `Vehiculos_consumoSupplier_Fk` FOREIGN KEY IF NOT EXISTS (proveedoresFk) REFERENCES vn.supplier (id) ON DELETE NO ACTION ON UPDATE NO ACTION; +ALTER TABLE vn2008.`albaran` ADD CONSTRAINT `albaranSupplier_Fk` FOREIGN KEY IF NOT EXISTS (Id_Proveedor) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Proveedores_cargueras` ADD CONSTRAINT `Proveedores_carguerasSupplier_Fk` FOREIGN KEY IF NOT EXISTS (Id_Proveedor) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn2008.`Proveedores_comunicados` ADD CONSTRAINT `Proveedores_comunicadosSupplier_Fk` FOREIGN KEY IF NOT EXISTS (Id_Proveedor) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; + +ALTER TABLE vn.company ADD CONSTRAINT company_FK FOREIGN KEY IF NOT EXISTS (id) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10610-goldenArborvitae/02-invoiceOutCompany.sql b/db/versions/10610-goldenArborvitae/02-invoiceOutCompany.sql new file mode 100644 index 000000000..7a347369c --- /dev/null +++ b/db/versions/10610-goldenArborvitae/02-invoiceOutCompany.sql @@ -0,0 +1,8 @@ +-- SET SESSION idle_transaction_timeout = 0; + +ALTER TABLE vn.`invoiceOut` + MODIFY COLUMN companyFk INT UNSIGNED DEFAULT 442 NOT NULL; + +ALTER TABLE vn.`invoiceOut` + ADD CONSTRAINT `invoiceOutCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) + REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10611-blueGerbera/00-firstScript.sql b/db/versions/10611-blueGerbera/00-firstScript.sql new file mode 100644 index 000000000..457d1d3d4 --- /dev/null +++ b/db/versions/10611-blueGerbera/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticketRefund ADD CONSTRAINT ticketRefund_UN UNIQUE KEY (refundTicketFk); diff --git a/db/versions/10613-purpleAspidistra/00-firstScript.sql b/db/versions/10613-purpleAspidistra/00-firstScript.sql new file mode 100644 index 000000000..e50a8cc9c --- /dev/null +++ b/db/versions/10613-purpleAspidistra/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.bankEntityConfig ADD defaultBankId int DEFAULT 3117 NOT NULL COMMENT 'Id del banco por defecto'; \ No newline at end of file diff --git a/db/versions/10614-chocolateGalax/00-firstScript.sql b/db/versions/10614-chocolateGalax/00-firstScript.sql new file mode 100644 index 000000000..ab9d4539c --- /dev/null +++ b/db/versions/10614-chocolateGalax/00-firstScript.sql @@ -0,0 +1 @@ +DROP TABLE vn.contratos_subvencion_270619; diff --git a/db/versions/10615-azureCataractarum/00-firstScript.sql b/db/versions/10615-azureCataractarum/00-firstScript.sql new file mode 100644 index 000000000..c8c7119c8 --- /dev/null +++ b/db/versions/10615-azureCataractarum/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`warehouse` +ADD COLUMN IF NOT EXISTS `isOrigin` TINYINT(1) NULL AFTER `isHalt`, +ADD COLUMN IF NOT EXISTS `isDestiny` TINYINT(1) NULL AFTER `isOrigin`; \ No newline at end of file diff --git a/db/versions/10616-yellowIvy/00-firstScript.sql b/db/versions/10616-yellowIvy/00-firstScript.sql new file mode 100644 index 000000000..281d43133 --- /dev/null +++ b/db/versions/10616-yellowIvy/00-firstScript.sql @@ -0,0 +1,13 @@ + +CREATE TABLE IF NOT EXISTS vn.`budgetState` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `code` varchar(45) NOT NULL, + `description` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `budgetState_UN` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +ALTER TABLE vn.budget ADD IF NOT EXISTS budgetStateFk varchar(45) NULL; + +ALTER TABLE vn.budget ADD CONSTRAINT budgetStateFk FOREIGN KEY IF NOT EXISTS +(budgetStateFk) REFERENCES vn.budgetState(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10616-yellowIvy/01-firstScript.sql b/db/versions/10616-yellowIvy/01-firstScript.sql new file mode 100644 index 000000000..50ea15f8b --- /dev/null +++ b/db/versions/10616-yellowIvy/01-firstScript.sql @@ -0,0 +1,8 @@ + +ALTER TABLE vn.property ADD IF NOT EXISTS supplierFk int(10) unsigned NULL; +ALTER TABLE vn.property + ADD CONSTRAINT propertySupplierFk + FOREIGN KEY IF NOT EXISTS (supplierFk) + REFERENCES vn.supplier(id) + ON DELETE RESTRICT + ON UPDATE CASCADE; diff --git a/db/versions/10617-aquaAralia/00-firstScript.sql b/db/versions/10617-aquaAralia/00-firstScript.sql new file mode 100644 index 000000000..a2ddd50a5 --- /dev/null +++ b/db/versions/10617-aquaAralia/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX ticketTracking_created_IDX USING BTREE ON vn.ticketTracking (created); diff --git a/db/versions/10618-whiteArborvitae/00-firstScript.sql b/db/versions/10618-whiteArborvitae/00-firstScript.sql new file mode 100644 index 000000000..161525ab7 --- /dev/null +++ b/db/versions/10618-whiteArborvitae/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.company CHANGE footnotes__ footnotes longtext CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL COMMENT 'pie de paginas en las facturas'; + diff --git a/db/versions/10619-chocolateErica/00-firstScript.sql b/db/versions/10619-chocolateErica/00-firstScript.sql new file mode 100644 index 000000000..66c626c83 --- /dev/null +++ b/db/versions/10619-chocolateErica/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.expeditionTruck DROP COLUMN ETD; \ No newline at end of file diff --git a/db/versions/10620-azurePalmetto/00-firstScript.sql b/db/versions/10620-azurePalmetto/00-firstScript.sql new file mode 100644 index 000000000..34b02f24e --- /dev/null +++ b/db/versions/10620-azurePalmetto/00-firstScript.sql @@ -0,0 +1,11 @@ +-- Place your SQL code here +SET @isTriggerDisabled = TRUE; + +UPDATE vn.buy + SET printedStickers = 0 + WHERE printedStickers < 0; + +ALTER TABLE vn.buy MODIFY COLUMN IF EXISTS + printedStickers int(10) unsigned DEFAULT 0 NOT NULL; + +SET @isTriggerDisabled = FALSE; \ No newline at end of file diff --git a/db/versions/10624-blueAnthurium/00-firstScript.sql b/db/versions/10624-blueAnthurium/00-firstScript.sql new file mode 100644 index 000000000..def992317 --- /dev/null +++ b/db/versions/10624-blueAnthurium/00-firstScript.sql @@ -0,0 +1,142 @@ +ALTER TABLE vn.workerLog + MODIFY COLUMN changedModel enum('Worker','workerDocument','Calendar','WorkerTimeControlMail','Business') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Worker' NOT NULL, + MODIFY COLUMN description text CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; + +-- Fix description, model and id + +UPDATE vn.workerLog SET description = NULL WHERE description = ''; + +UPDATE vn.workerLog + SET changedModel = 'Business' + WHERE description LIKE '%del contrato con id%' + AND changedModel = ''; + +UPDATE vn.workerLog + SET changedModelId = REGEXP_REPLACE(description, '.*del contrato con id ([0-9]*)$', '\\1') + WHERE description LIKE '%del contrato con id%' + AND changedModel = 'Business' + AND changedModelId = 0; + +-- Various fixes + +DELETE FROM vn.workerLog + WHERE `action` = 'update' AND oldInstance = newInstance; + +-- Set instance from description + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('departmentFk', + IF((@val := REGEXP_REPLACE(description, 'Cambiado el departamento a (.*) del contrato con id ?[0-9]*', '\\1')) = '', + NULL, CAST(@val AS SIGNED) + ) + ), + description = NULL + WHERE description LIKE 'Cambiado el departamento a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('ended', + IF((@val := REGEXP_REPLACE(description, 'Cambiado el Fecha finalización a (.*) del contrato con id ?[0-9]*', '\\1')) = '', + NULL, CAST(@val AS SIGNED) + ) + ), + description = NULL + WHERE description LIKE 'Cambiado el Fecha finalización a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('workcenterFk', + IF((@val := REGEXP_REPLACE(description, 'Cambiado el Centro de trabajo a (.*) del contrato con id ?[0-9]*', '\\1')) = '', + NULL, CAST(@val AS SIGNED) + ) + ), + description = NULL + WHERE description LIKE 'Cambiado el Centro de trabajo a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('calendarTypeFk', + IF((@val := REGEXP_REPLACE(description, 'Cambiado el Calendario a (.*) del contrato con id ?[0-9]*', '\\1')) = '', + NULL, CAST(@val AS SIGNED) + ) + ), + description = NULL + WHERE description LIKE 'Cambiado el Calendario a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('amount', + IF((@val := REGEXP_REPLACE(description, 'Cambiado el importe Pactado a (.*) del contrato con id ?[0-9]*', '\\1')) <> '', + CAST(REPLACE(@val, ',', '.') AS DECIMAL(12,2)), + NULL + ) + ), + description = NULL + WHERE description LIKE 'Cambiado el importe Pactado a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('rate', + IF((@val := REGEXP_REPLACE(description, 'Cambiado el tarifa a (.*) del contrato con id ?[0-9]*', '\\1')) <> '', + CAST(@val AS SIGNED), + NULL + ) + ), + description = NULL + WHERE description LIKE 'Cambiado el tarifa a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('departmentFk', + IF((@val := REGEXP_REPLACE(description, 'Ha cambiado el departamento a (.*) del contrato con id ?[0-9]*', '\\1')) <> '', + @val, + NULL + ) + ), + description = NULL + WHERE description LIKE 'Ha cambiado el departamento a %del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('departmentFk', + IF((@val := REGEXP_REPLACE(description, 'Ha cambiado el departamento .* a (.*) del contrato con id ?[0-9]*', '\\1')) <> '', + @val, + NULL + ) + ), + oldInstance = JSON_OBJECT('departmentFk', + IF((@val := REGEXP_REPLACE(description, 'Ha cambiado el departamento (.*) a .* del contrato con id ?[0-9]*', '\\1')) <> '', + @val, + NULL + ) + ), + description = NULL + WHERE description LIKE 'Ha cambiado el departamento % a % del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; + +UPDATE vn.workerLog + SET newInstance = JSON_OBJECT('amount', + IF((@val := REGEXP_REPLACE(description, 'Ha cambiado el salario de [0-9,]* a ([0-9,]*) del contrato con id ?[0-9]*', '\\1')) <> '', + CAST(REPLACE(@val, ',', '.') AS DECIMAL(12,2)), + NULL + ) + ), + oldInstance = JSON_OBJECT('amount', + IF((@val := REGEXP_REPLACE(description, 'Ha cambiado el salario de ([0-9,]*) a [0-9,]* del contrato con id ?[0-9]*', '\\1')) <> '', + CAST(REPLACE(@val, ',', '.') AS DECIMAL(12,2)), + NULL + ) + ), + description = NULL + WHERE description LIKE 'Ha cambiado el salario de % a % del contrato con id%' + AND newInstance IS NULL + AND changedModel = 'Business'; diff --git a/db/versions/10625-whiteOak/00-firstScript.sql b/db/versions/10625-whiteOak/00-firstScript.sql new file mode 100644 index 000000000..5ac2e5978 --- /dev/null +++ b/db/versions/10625-whiteOak/00-firstScript.sql @@ -0,0 +1,3 @@ +RENAME TABLE bs.compradores TO bs.compradores__; +DROP TABLE bi.analisis_ventas_comprador_evolution; + diff --git a/db/versions/10626-silverRaphis/00-firstScript.sql b/db/versions/10626-silverRaphis/00-firstScript.sql new file mode 100644 index 000000000..8fa4af266 --- /dev/null +++ b/db/versions/10626-silverRaphis/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here +UPDATE vn.buy b + JOIN vn.entryConfig e ON e.defaultEntry = b.entryFk + SET b.printedStickers = 0 + WHERE printedStickers <> 0; \ No newline at end of file diff --git a/db/versions/10628-grayOrchid/00-firstScript.sql b/db/versions/10628-grayOrchid/00-firstScript.sql new file mode 100644 index 000000000..020c47177 --- /dev/null +++ b/db/versions/10628-grayOrchid/00-firstScript.sql @@ -0,0 +1 @@ +RENAME TABLE vn2008.Permisos TO vn2008.Permisos__; \ No newline at end of file diff --git a/db/versions/10630-brownMastic/00-firstScript.sql b/db/versions/10630-brownMastic/00-firstScript.sql new file mode 100644 index 000000000..caa0b45bc --- /dev/null +++ b/db/versions/10630-brownMastic/00-firstScript.sql @@ -0,0 +1,38 @@ + +-- Fix vn.workerLog.changedModel + +ALTER TABLE vn.workerLog + MODIFY COLUMN changedModel ENUM('Worker','workerDocument','Calendar','WorkerTimeControlMail','Business', 'WorkerDms') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Worker' NOT NULL; + +UPDATE vn.workerLog SET changedModel = 'WorkerDms' WHERE changedModel = 'workerDocument'; + +ALTER TABLE vn.workerLog + MODIFY COLUMN changedModel ENUM('Worker','Calendar','WorkerTimeControlMail','Business', 'WorkerDms') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Worker' NOT NULL; + +-- Fix account.userLog.changedModel + +ALTER TABLE account.userLog + MODIFY COLUMN changedModel enum('User', 'VnUser', 'Account', 'MailAliasAccount', 'MailForward') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'User' NOT NULL; + +UPDATE account.userLog SET changedModel = 'VnUser' WHERE changedModel = 'User'; + +UPDATE account.userLog u + SET changedModel = 'MailForward' + WHERE + changedModel = '' + AND (JSON_VALUE(newInstance, '$.forwardTo') IS NOT NULL + OR JSON_VALUE(oldInstance, '$.forwardTo') IS NOT NULL); + +UPDATE account.userLog u + SET changedModel = 'MailAliasAccount' + WHERE + changedModel = '' + AND (JSON_VALUE(newInstance, '$.mailAlias') IS NOT NULL + OR JSON_VALUE(oldInstance, '$.mailAlias') IS NOT NULL); + +ALTER TABLE account.userLog + MODIFY COLUMN changedModel enum('VnUser', 'Account', 'MailAliasAccount', 'MailForward') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'VnUser' NOT NULL; diff --git a/db/versions/10631-yellowBamboo/00-firstScript.sql b/db/versions/10631-yellowBamboo/00-firstScript.sql new file mode 100644 index 000000000..391d54860 --- /dev/null +++ b/db/versions/10631-yellowBamboo/00-firstScript.sql @@ -0,0 +1,18 @@ +ALTER TABLE account.roleLog + MODIFY COLUMN changedModel enum('Role', 'RoleInherit') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Role' NOT NULL; + +UPDATE account.roleLog SET changedModel = 'RoleInherit' + WHERE changedModel = ''; + +UPDATE account.roleLog + SET oldInstance = JSON_REMOVE(oldInstance, '$.modified'), + newInstance = JSON_REMOVE(newInstance, '$.modified') + WHERE changedModel = 'Role' + AND (JSON_VALUE(oldInstance, '$.modified') IS NOT NULL + OR JSON_VALUE(newInstance, '$.modified') IS NOT NULL); + +DELETE FROM account.roleLog + WHERE oldInstance = '{}' + AND newInstance = '{}' + AND description IS NULL; diff --git a/db/versions/10632-wheatPaniculata/00-firstScript.sql b/db/versions/10632-wheatPaniculata/00-firstScript.sql new file mode 100644 index 000000000..ec3e42c30 --- /dev/null +++ b/db/versions/10632-wheatPaniculata/00-firstScript.sql @@ -0,0 +1,4 @@ +RENAME TABLE bi.analisis_ventas_familia_evolution TO bi.analisis_ventas_familia_evolution__; +ALTER TABLE bi.analisis_ventas_familia_evolution__ +COMMENT='refs #5196 Deprecated 2023-06-05'; + diff --git a/db/versions/10633-orangeArborvitae/00-firstScript.sql b/db/versions/10633-orangeArborvitae/00-firstScript.sql new file mode 100644 index 000000000..f1406f2bc --- /dev/null +++ b/db/versions/10633-orangeArborvitae/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.vehicle MODIFY COLUMN companyFk int(10) unsigned DEFAULT 442 NULL; diff --git a/db/versions/10634-pinkCymbidium/00-firstScript.sql b/db/versions/10634-pinkCymbidium/00-firstScript.sql new file mode 100644 index 000000000..7ee397ba3 --- /dev/null +++ b/db/versions/10634-pinkCymbidium/00-firstScript.sql @@ -0,0 +1,70 @@ +USE hedera; +CREATE OR REPLACE TABLE `messageI18n` ( + `code` CHAR(35) NOT NULL, + `lang` char(2) NOT NULL, + `description` varchar(255) NOT NULL, + PRIMARY KEY (`code`,`lang`), + CONSTRAINT `messageI18nFk` FOREIGN KEY (`code`) REFERENCES `hedera`.`message` (`code`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO hedera.message (code, description) + VALUES ('clientNotVerified', 'Datos fiscales incompletos, por favor contacte con su comercial'); + +INSERT IGNORE INTO hedera.messageI18n (code, lang, description) + VALUES ('ORDER_DATE_HOLIDAY', 'es', 'No es posible realizar pedidos para días festivos'), +('ORDER_DATE_HOLIDAY', 'fr', 'Il n''est pas possible de passer des commandes pour les jours fériés'), +('ORDER_DATE_HOLIDAY', 'pt', 'Não é possível efectuar encomendas para feriados'), +('ORDER_EMPTY', 'es', 'El pedido esta vacío'), +('ORDER_EMPTY', 'fr', 'La commande est vide'), +('ORDER_EMPTY', 'pt', 'A encomenda está vazia'), +('ORDER_UNAVAILABLE', 'es', 'Algunos artículos ya no están disponibles, verifica las cantidades resaltadas en rojo'), +('ORDER_UNAVAILABLE', 'fr', 'Certains articles ne sont plus disponibles, veuillez vérifier les quantités surlignées en rouge'), +('ORDER_UNAVAILABLE', 'pt', 'Alguns artigos já não estão disponíveis, verifique as quantidades assinaladas a vermelho'), +('SURVEY_MAX_ONE_VOTE', 'es', 'Solo es posible realizar un voto por encuesta'), +('SURVEY_MAX_ONE_VOTE', 'fr', 'Un seul vote est possible par sondage'), +('SURVEY_MAX_ONE_VOTE', 'pt', 'Só é possível um voto por sondagem'), +('ORDER_MAX_EXCEEDED', 'es', 'Has excedido el número máximo de pedidos por confirmar, por favor elimina o confirma los pedidos iniciados'), +('ORDER_MAX_EXCEEDED', 'fr', 'Vous avez dépassé le nombre maximum de commandes à confirmer, veuillez supprimer ou confirmer les commandes entamées'), +('ORDER_MAX_EXCEEDED', 'pt', 'Excedeu o número máximo de encomendas a serem confirmadas, por favor apague ou confirme as encomendas iniciadas'), +('LOGIN_INCORRECT', 'es', 'Usuario o contraseña incorrectos. Recuerda que se hace distinción entre mayúsculas y minúsculas.'), +('LOGIN_INCORRECT', 'fr', 'Nom d''utilisateur ou mot de passe incorrect. N''oubliez pas que nous respectons les majuscules et les minuscules'), +('LOGIN_INCORRECT', 'pt', 'Nome de utilizador ou palavra-passe incorrectos. Lembre-se que somos sensíveis às maiúsculas e minúsculas'), +('ORDER_DATE_PAST', 'es', 'La fecha de su pedido debe ser mayor o igual al día de hoy'), +('ORDER_DATE_PAST', 'fr', 'La date de votre commande doit être supérieure ou égale à la date d''aujourd''hui'), +('ORDER_DATE_PAST', 'pt', 'A data da sua encomenda deve ser maior ou igual à data de hoje'), +('ORDER_DATE_LAST', 'es', 'No es posible realizar más para hoy, por favor atrasa la fecha de tu pedido a mañana o días posteriores'), +('ORDER_DATE_LAST', 'fr', 'Il n''est plus possible de passer des commandes pour aujourd''hui, veuillez reporter la date de votre commande à demain ou plus tard'), +('ORDER_DATE_LAST', 'pt', 'Não é possível efectuar mais encomendas para hoje, por favor adie a data da sua encomenda para amanhã ou mais tarde'), +('ORDER_DATE_SUNDAY', 'es', 'No es posible confirmar pedidos para Domingo'), +('ORDER_DATE_SUNDAY', 'fr', 'Il n''est pas possible de confirmer les commandes pour le dimanche'), +('ORDER_DATE_SUNDAY', 'pt', 'Não é possível confirmar encomendas para domingo'), +('ORDER_DATE_SATURATED', 'es', 'Estamos saturados de pedidos, por favor selecciona otra fecha de envío o recogida '), +('ORDER_DATE_SATURATED', 'fr', 'Nous sommes surchargés de commandes, veuillez choisir une autre date de livraison ou d''enlèvement'), +('ORDER_DATE_SATURATED', 'pt', 'Estamos sobrecarregados com encomendas, por favor seleccione outra data de entrega ou recolha'), +('USER_DISCONNECTED', 'es', 'Has sido desconectado del servidor, por favor vuelve a iniciar sesión'), +('USER_DISCONNECTED', 'fr', 'Vous avez été déconnecté du serveur, veuillez vous connecter à nouveau'), +('USER_DISCONNECTED', 'pt', 'Foi desligado do servidor, por favor inicie novamente a sessão'), +('UNAUTH_ACTION', 'es', 'Acción no permitida'), +('UNAUTH_ACTION', 'fr', 'Action non autorisée'), +('UNAUTH_ACTION', 'pt', 'Acção não permitida'), +('ORDER_INVALID_AGENCY', 'es', 'La agencia de envío no es válida'), +('ORDER_INVALID_AGENCY', 'fr', 'L''agence de livraison n''est pas valide'), +('ORDER_INVALID_AGENCY', 'pt', 'A agência de expedição é inválida'), +('ORDER_EMPTY_ADDRESS', 'es', 'Selecciona una dirección de envío'), +('ORDER_EMPTY_ADDRESS', 'fr', 'Veuillez sélectionner une adresse de livraison'), +('ORDER_EMPTY_ADDRESS', 'pt', 'Por favor, seleccione um endereço de entrega'), +('ORDER_AMOUNT_ROUNDED', 'es', 'Este artículo se vende agrupado y la cantidad ha sido redondeada'), +('ORDER_AMOUNT_ROUNDED', 'fr', 'Cet article est vendu groupé et la quantité a été arrondie'), +('ORDER_AMOUNT_ROUNDED', 'pt', 'Este artigo é vendido em pacote e a quantidade foi arredondada'), +('orderOutdated', 'es', 'La configuración del pedido es incorrecta, por favor vuelve a configurarlo para continuar comprando'), +('orderOutdated', 'fr', 'La configuration de la commande est incorrecte, veuillez la reconfigurer pour poursuivre vos achats'), +('orderOutdated', 'pt', 'A configuração da encomenda está incorrecta, por favor reconfigure-a para continuar a comprar'), +('orderNotOwnedByUser', 'es', 'El pedido pertenece a otro usuario'), +('orderNotOwnedByUser', 'fr', 'La commande appartient à un autre utilisateur'), +('orderNotOwnedByUser', 'pt', 'A encomenda pertence a outro utilizador'), +('orderConfirmed', 'es', 'El pedido ya ha sido confirmado y no puede modificarse'), +('orderConfirmed', 'fr', 'La commande a déjà été confirmée et ne peut être modifiée'), +('orderConfirmed', 'pt', 'A encomenda já foi confirmada e não pode ser modificada'), +('clientNotVerified', 'es', 'Datos fiscales incompletos, por favor contacte con su comercial'), +('clientNotVerified', 'fr', 'Données fiscales incomplètes, veuillez contacter votre représentant commercial'), +('clientNotVerified', 'pt', 'Dados fiscais incompletos, por favor contacte o seu representante de vendas'); diff --git a/db/versions/10637-yellowAspidistra/00-firstScript.sql b/db/versions/10637-yellowAspidistra/00-firstScript.sql new file mode 100644 index 000000000..ec633f4a2 --- /dev/null +++ b/db/versions/10637-yellowAspidistra/00-firstScript.sql @@ -0,0 +1,17 @@ +RENAME TABLE bi.live_counter TO bi.live_counter__; +ALTER TABLE bi.live_counter__ +COMMENT='refs #5744 Deprecated 2023-06-06'; +RENAME TABLE bi.partitioning_information TO bi.partitioning_information__; +ALTER TABLE bi.partitioning_information__ +COMMENT='refs #5744 Deprecated 2023-06-06'; +RENAME TABLE bi.primer_pedido TO bi.primer_pedido__; +ALTER TABLE bi.primer_pedido__ +COMMENT='refs #5744 Deprecated 2023-06-06'; +RENAME TABLE bi.tarifa_premisas TO bi.tarifa_premisas__; +ALTER TABLE bi.tarifa_premisas__ +COMMENT='refs #5744 Deprecated 2023-06-06'; +RENAME TABLE bi.tarifa_warehouse TO bi.tarifa_warehouse__; +ALTER TABLE bi.tarifa_warehouse__ +COMMENT='refs #5744 Deprecated 2023-06-06 +Almacena los valores de gasto por almacen'; + diff --git a/db/versions/10640-redPalmetto/00-companyFkDrop.sql b/db/versions/10640-redPalmetto/00-companyFkDrop.sql new file mode 100644 index 000000000..b6345086e --- /dev/null +++ b/db/versions/10640-redPalmetto/00-companyFkDrop.sql @@ -0,0 +1,36 @@ +ALTER TABLE bs.sale DROP FOREIGN KEY IF EXISTS saleCompany_Fk; +ALTER TABLE edi.clientFHAdminNumber DROP FOREIGN KEY IF EXISTS clientFHAdminNumber_fk; +ALTER TABLE hedera.orderConfig DROP FOREIGN KEY IF EXISTS orderConfigCompany_Fk; +ALTER TABLE vn.business DROP FOREIGN KEY IF EXISTS business_companyCodeFk; +ALTER TABLE vn.clientRisk DROP FOREIGN KEY IF EXISTS clientRiskCompany_Fk; +ALTER TABLE vn.clientSample DROP FOREIGN KEY IF EXISTS clientSampleCompany_Fk; +ALTER TABLE vn.cmr DROP FOREIGN KEY IF EXISTS cmrCompany_Fk; +ALTER TABLE vn.companyI18n DROP FOREIGN KEY IF EXISTS companyI18nCompany_Fk; +ALTER TABLE vn.dms DROP FOREIGN KEY IF EXISTS dmsCompany_Fk; +ALTER TABLE vn.dua DROP FOREIGN KEY IF EXISTS duaCompany_Fk; +ALTER TABLE vn.entry DROP FOREIGN KEY IF EXISTS entryCompany_Fk; +ALTER TABLE vn.farming DROP FOREIGN KEY IF EXISTS farmingCompany_Fk; +ALTER TABLE vn.host DROP FOREIGN KEY IF EXISTS hostCompany_Fk; +ALTER TABLE vn.invoiceIn DROP FOREIGN KEY IF EXISTS invoiceInCompany_Fk; +ALTER TABLE vn.invoiceOut DROP FOREIGN KEY IF EXISTS invoiceOutCompany_Fk; +ALTER TABLE vn.mandate DROP FOREIGN KEY IF EXISTS mandateCompany_Fk; +ALTER TABLE vn.payment DROP FOREIGN KEY IF EXISTS paymentCompany_Fk; +ALTER TABLE vn.ppe DROP FOREIGN KEY IF EXISTS ppeCompany_Fk; +ALTER TABLE vn.project DROP FOREIGN KEY IF EXISTS projectCompany_Fk; +ALTER TABLE vn.property DROP FOREIGN KEY IF EXISTS propertyCompany_Fk; +ALTER TABLE vn.receipt DROP FOREIGN KEY IF EXISTS receiptCompany_Fk; +ALTER TABLE vn.routeConfig DROP FOREIGN KEY IF EXISTS routeConfigCompany_Fk; +ALTER TABLE vn.sinister DROP FOREIGN KEY IF EXISTS sinisterCompany_Fk; +ALTER TABLE vn.supplierExpense DROP FOREIGN KEY IF EXISTS supplierExpenseCompany_Fk; +ALTER TABLE vn.ticket DROP FOREIGN KEY IF EXISTS ticketCompany_Fk; +ALTER TABLE vn.vehicle DROP FOREIGN KEY IF EXISTS vehicleCompany_Fk; +ALTER TABLE vn.XDiario DROP FOREIGN KEY IF EXISTS XDiarioCompany_Fk; +ALTER TABLE vn2008.albaran DROP FOREIGN KEY IF EXISTS albaranCompany_Fk; +ALTER TABLE vn2008.Bancos_poliza DROP FOREIGN KEY IF EXISTS Bancos_polizaCompany_Fk; +ALTER TABLE vn2008.Clientes_empresa DROP FOREIGN KEY IF EXISTS Clientes_empresaCompany_Fk; +ALTER TABLE vn2008.`Enlaces Facturas__` DROP FOREIGN KEY IF EXISTS EnlacesFacturas__Company_Fk; +ALTER TABLE vn2008.pago_sdc DROP FOREIGN KEY IF EXISTS pago_sdcCompany_Fk; +ALTER TABLE vn2008.Permisos__ DROP FOREIGN KEY IF EXISTS PermisosCompany_Fk; +ALTER TABLE vn2008.Remesas DROP FOREIGN KEY IF EXISTS RemesasCompany_Fk; +ALTER TABLE vn2008.Saldos_Prevision DROP FOREIGN KEY IF EXISTS Saldos_PrevisionCompany_Fk; +ALTER TABLE vn.company DROP FOREIGN KEY IF EXISTS company_Fk; diff --git a/db/versions/10640-redPalmetto/01-companyFkAi.sql b/db/versions/10640-redPalmetto/01-companyFkAi.sql new file mode 100644 index 000000000..e04206667 --- /dev/null +++ b/db/versions/10640-redPalmetto/01-companyFkAi.sql @@ -0,0 +1 @@ +ALTER TABLE vn.company MODIFY COLUMN id INT UNSIGNED auto_increment NOT NULL; diff --git a/db/versions/10640-redPalmetto/02-companyFkCreate.sql b/db/versions/10640-redPalmetto/02-companyFkCreate.sql new file mode 100644 index 000000000..086dcb18c --- /dev/null +++ b/db/versions/10640-redPalmetto/02-companyFkCreate.sql @@ -0,0 +1,32 @@ +ALTER TABLE hedera.`orderConfig` ADD CONSTRAINT `orderConfigCompany_Fk` FOREIGN KEY IF NOT EXISTS (defaultCompanyFk) REFERENCES vn.company(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`project` ADD CONSTRAINT `projectCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`vehicle` ADD CONSTRAINT `vehicleCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`routeConfig` ADD CONSTRAINT `routeConfigCompany_Fk` FOREIGN KEY IF NOT EXISTS (defaultCompanyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.`entry` ADD CONSTRAINT `entryCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`payment` ADD CONSTRAINT `paymentCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`receipt` ADD CONSTRAINT `receiptCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`invoiceIn` ADD CONSTRAINT `invoiceInCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`sinister` ADD CONSTRAINT `sinisterCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`supplierExpense` ADD CONSTRAINT `supplierExpenseCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`ticket` ADD CONSTRAINT `ticketCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`mandate` ADD CONSTRAINT `mandateCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE NO ACTION ON UPDATE CASCADE; +ALTER TABLE vn.`XDiario` ADD CONSTRAINT `XDiarioCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`dms` ADD CONSTRAINT `dmsCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`property` ADD CONSTRAINT `propertyCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`cmr` ADD CONSTRAINT `cmrCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn.`host` ADD CONSTRAINT `hostCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`clientRisk` ADD CONSTRAINT `clientRiskCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`ppe` ADD CONSTRAINT `ppeCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +-- ALTER TABLE vn.`invoiceOut` ADD CONSTRAINT `invoiceOutCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`dua` ADD CONSTRAINT `duaCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`clientSample` ADD CONSTRAINT `clientSampleCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Saldos_Prevision` ADD CONSTRAINT `Saldos_PrevisionCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`pago_sdc` ADD CONSTRAINT `pago_sdcCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Clientes_empresa` ADD CONSTRAINT `Clientes_empresaCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE NO ACTION ON UPDATE RESTRICT; +ALTER TABLE vn2008.`Bancos_poliza` ADD CONSTRAINT `Bancos_polizaCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`albaran` ADD CONSTRAINT `albaranCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Remesas` ADD CONSTRAINT `RemesasCompany_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Enlaces Facturas__` ADD CONSTRAINT `EnlacesFacturas__Company_Fk` FOREIGN KEY IF NOT EXISTS (empresa_id) REFERENCES vn.company (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE bs.`sale` ADD CONSTRAINT `saleCompany_Fk` FOREIGN KEY IF NOT EXISTS (companyFk) REFERENCES vn.company (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`farming` ADD CONSTRAINT `farmingCompany_Fk` FOREIGN KEY IF NOT EXISTS(companyFk) REFERENCES vn.company(id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.`companyI18n` ADD CONSTRAINT `companyI18nCompany_Fk` FOREIGN KEY IF NOT EXISTS(companyFk) REFERENCES vn.company(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10640-redPalmetto/04-supplierFkDrop.sql b/db/versions/10640-redPalmetto/04-supplierFkDrop.sql new file mode 100644 index 000000000..377198fd5 --- /dev/null +++ b/db/versions/10640-redPalmetto/04-supplierFkDrop.sql @@ -0,0 +1,26 @@ +ALTER TABLE vn.`budget` DROP FOREIGN KEY IF EXISTS `budgetSupplier_Fk`; +ALTER TABLE vn.`supplierContact` DROP FOREIGN KEY IF EXISTS `supplierContactSupplier_Fk`; +ALTER TABLE vn.`entry` DROP FOREIGN KEY IF EXISTS `entrySupplier_Fk`; +ALTER TABLE vn.`payment` DROP FOREIGN KEY IF EXISTS `paymentSupplier_Fk`; +ALTER TABLE vn.`travelClonedWeekly` DROP FOREIGN KEY IF EXISTS `travelClonedWeeklySupplier_Fk`; +ALTER TABLE vn.`invoiceIn` DROP FOREIGN KEY IF EXISTS `invoiceInSupplier_Fk`; +ALTER TABLE vn.`sinister` DROP FOREIGN KEY IF EXISTS `sinisterSupplier_Fk`; +ALTER TABLE vn.`company` DROP FOREIGN KEY IF EXISTS `company_FK`; +ALTER TABLE vn.`comparativeFilter` DROP FOREIGN KEY IF EXISTS `comparativeFilterSupplier_Fk`; +ALTER TABLE vn.`supplierExpense` DROP FOREIGN KEY IF EXISTS `supplierExpenseSupplier_Fk`; +ALTER TABLE vn.`supplierAccount` DROP FOREIGN KEY IF EXISTS `supplierAccountSupplier_Fk`; +ALTER TABLE vn.`roadmap` DROP FOREIGN KEY IF EXISTS `roadmapSupplier_Fk`; +ALTER TABLE vn.`awb` DROP FOREIGN KEY IF EXISTS `awbSupplier_Fk`; +ALTER TABLE vn.`awb` DROP FOREIGN KEY IF EXISTS `awbSupplier_Fk`; +ALTER TABLE vn.`supplierLog` DROP FOREIGN KEY IF EXISTS `supplierLogSupplier_Fk`; +ALTER TABLE vn.`cmr` DROP FOREIGN KEY IF EXISTS `cmrSupplier_Fk`; +ALTER TABLE vn.`duaTax` DROP FOREIGN KEY IF EXISTS `duaTaxSupplier_Fk`; +ALTER TABLE vn.`supplierAgencyTerm` DROP FOREIGN KEY IF EXISTS `supplierAgencyTermSupplier_Fk`; +ALTER TABLE vn.`machine` DROP FOREIGN KEY IF EXISTS `machineSupplier_Fk`; +ALTER TABLE vn2008.`travel_pattern` DROP FOREIGN KEY IF EXISTS `travel_patternSupplier_Fk`; +ALTER TABLE vn2008.`Bancos_poliza` DROP FOREIGN KEY IF EXISTS `Bancos_polizaSupplier_Fk`; +ALTER TABLE vn2008.`Bancos_poliza` DROP FOREIGN KEY IF EXISTS `Bancos_polizaSupplier_Fk1`; +ALTER TABLE vn2008.`Vehiculos_consumo` DROP FOREIGN KEY IF EXISTS `Vehiculos_consumoSupplier_Fk`; +ALTER TABLE vn2008.`albaran` DROP FOREIGN KEY IF EXISTS `albaranSupplier_Fk`; +ALTER TABLE vn2008.`Proveedores_cargueras` DROP FOREIGN KEY IF EXISTS `Proveedores_carguerasSupplier_Fk`; +ALTER TABLE vn2008.`Proveedores_comunicados` DROP FOREIGN KEY IF EXISTS `Proveedores_comunicadosSupplier_Fk`; diff --git a/db/versions/10640-redPalmetto/05-supplierFkAi.sql b/db/versions/10640-redPalmetto/05-supplierFkAi.sql new file mode 100644 index 000000000..94cf0d815 --- /dev/null +++ b/db/versions/10640-redPalmetto/05-supplierFkAi.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplier MODIFY COLUMN id INT UNSIGNED auto_increment NOT NULL ; diff --git a/db/versions/10640-redPalmetto/06-supplierFkCreate.sql b/db/versions/10640-redPalmetto/06-supplierFkCreate.sql new file mode 100644 index 000000000..a5ad7a629 --- /dev/null +++ b/db/versions/10640-redPalmetto/06-supplierFkCreate.sql @@ -0,0 +1,26 @@ +ALTER TABLE vn.`budget` ADD CONSTRAINT `budget_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`supplierContact` ADD CONSTRAINT `supplierContact_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`entry` ADD CONSTRAINT `entry_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`payment` ADD CONSTRAINT `payment_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`travelClonedWeekly` ADD CONSTRAINT `travelClonedWeekly_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn.`invoiceIn` ADD CONSTRAINT `invoiceIn_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`sinister` ADD CONSTRAINT `sinister_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`company` ADD CONSTRAINT company_supplierFk FOREIGN KEY IF NOT EXISTS (id) REFERENCES vn.supplier(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`comparativeFilter` ADD CONSTRAINT `comparativeFilter_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.`supplierExpense` ADD CONSTRAINT `supplierExpense_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`supplierAccount` ADD CONSTRAINT `supplierAccount_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`roadmap` ADD CONSTRAINT `roadmap_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`awb` ADD CONSTRAINT `awb_supplierFk` FOREIGN KEY IF NOT EXISTS (transitoryFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`awb` ADD CONSTRAINT `awb_supplierFk` FOREIGN KEY IF NOT EXISTS (freightFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`supplierLog` ADD CONSTRAINT `supplierLog_supplierFk` FOREIGN KEY IF NOT EXISTS (originFk) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.`cmr` ADD CONSTRAINT `cmr_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`duaTax` ADD CONSTRAINT `duaTax_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`supplierAgencyTerm` ADD CONSTRAINT `supplierAgencyTerm_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.`machine` ADD CONSTRAINT `machine_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn2008.`travel_pattern` ADD CONSTRAINT `travel_pattern_supplierFk` FOREIGN KEY IF NOT EXISTS (cargoSupplierFk) REFERENCES vn.supplier (id) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE vn2008.`Bancos_poliza` ADD CONSTRAINT `Bancos_poliza_notaryFk` FOREIGN KEY IF NOT EXISTS (notaryFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Bancos_poliza` ADD CONSTRAINT `Bancos_poliza_supplierFk` FOREIGN KEY IF NOT EXISTS (supplierFk) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Vehiculos_consumo` ADD CONSTRAINT `Vehiculos_consumo_supplierFk` FOREIGN KEY IF NOT EXISTS (proveedoresFk) REFERENCES vn.supplier (id) ON DELETE NO ACTION ON UPDATE NO ACTION; +ALTER TABLE vn2008.`albaran` ADD CONSTRAINT `albaran_supplierFk` FOREIGN KEY IF NOT EXISTS (Id_Proveedor) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn2008.`Proveedores_cargueras` ADD CONSTRAINT `Proveedores_cargueras_supplierFk` FOREIGN KEY IF NOT EXISTS (Id_Proveedor) REFERENCES vn.supplier (id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn2008.`Proveedores_comunicados` ADD CONSTRAINT `Proveedores_comunicados_supplierFk` FOREIGN KEY IF NOT EXISTS (Id_Proveedor) REFERENCES vn.supplier (id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10642-crimsonAspidistra/00-firstScript.sql b/db/versions/10642-crimsonAspidistra/00-firstScript.sql new file mode 100644 index 000000000..a1a0e1721 --- /dev/null +++ b/db/versions/10642-crimsonAspidistra/00-firstScript.sql @@ -0,0 +1,303 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`json_cleanEquals`(vA JSON, vB JSON) + RETURNS JSON + DETERMINISTIC +BEGIN +/** +* Cleans @vA instance removing nulls and keys whose values are the same. +* +* @param vA JSON containing the old values +* @param vB JSON containing the new values +*/ + DECLARE vKeys JSON; + DECLARE vPath VARCHAR(255); + DECLARE vValueA JSON; + DECLARE vValueB JSON; + DECLARE i INT DEFAULT 0; + DECLARE vCount INT; + + IF vA IS NULL OR vB IS NULL THEN + RETURN vA; + END IF; + + SET vKeys = JSON_KEYS(vB); + SET vCount = JSON_LENGTH(vKeys); + + WHILE i < vCount DO + SET vPath = CONCAT('$.', JSON_VALUE(vKeys, CONCAT('$[',i,']'))); + SET vValueA = JSON_EXTRACT(vA, vPath); + SET vValueB = JSON_EXTRACT(vB, vPath); + IF vValueA <=> vValueB THEN + SET vA = JSON_REMOVE(vA, vPath); + END IF; + SET i := i + 1; + END WHILE; + + RETURN vA; +END$$ +DELIMITER ; + + +-- Aplicar a todas las tablas log + +-- ticketLog +UPDATE vn.ticketLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.ticketLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.ticketLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.ticketLog; + +-- entryLog +UPDATE vn.entryLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.entryLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.entryLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.entryLog; + +-- itemLog +UPDATE vn.itemLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.itemLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.itemLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.itemLog; + +-- routeLog +UPDATE vn.routeLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.routeLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.routeLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.routeLog; + +-- travelLog +UPDATE vn.travelLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.travelLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.travelLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.travelLog; + +-- zoneLog +UPDATE vn.zoneLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.zoneLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.zoneLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.zoneLog; + +-- clientLog +UPDATE vn.clientLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.clientLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.clientLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.clientLog; + +-- workerLog +UPDATE vn.workerLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.workerLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.workerLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.workerLog; + +-- claimLog +UPDATE vn.claimLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.claimLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.claimLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.claimLog; + +-- shelvingLog +UPDATE vn.shelvingLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.shelvingLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.shelvingLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.shelvingLog; + +-- invoiceInLog +UPDATE vn.invoiceInLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.invoiceInLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.invoiceInLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.invoiceInLog; + +-- userLog +UPDATE vn.userLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.userLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.userLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.userLog; + +-- supplierLog +UPDATE vn.supplierLog + SET oldInstance = util.json_cleanEquals(@oldI := oldInstance, newInstance), + newInstance = util.json_cleanEquals(newInstance, @oldI) + WHERE `action` = 'update'; + +UPDATE vn.supplierLog + SET oldInstance = util.json_removeNulls(oldInstance) + WHERE `action` = 'delete' + AND oldInstance IS NOT NULL + AND NOT (oldInstance <=> util.json_removeNulls(oldInstance)); + +UPDATE vn.supplierLog + SET newInstance = util.json_removeNulls(newInstance) + WHERE `action` = 'insert' + AND newInstance IS NOT NULL + AND NOT (newInstance <=> util.json_removeNulls(newInstance)); + +OPTIMIZE TABLE vn.supplierLog; + +DROP FUNCTION util.json_cleanEquals; diff --git a/db/versions/10643-blueCataractarum/00-firstScript.sql b/db/versions/10643-blueCataractarum/00-firstScript.sql new file mode 100644 index 000000000..184a5ea3b --- /dev/null +++ b/db/versions/10643-blueCataractarum/00-firstScript.sql @@ -0,0 +1,43 @@ +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clientRemoveWorker1`() +BEGIN + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vClientFk INT; + DECLARE rs CURSOR FOR + SELECT c.clientFk + FROM tmp.clientGetDebt c + LEFT JOIN clientRisk r ON r.clientFk = c.clientFk + GROUP BY c.clientFk + HAVING SUM(IFNULL(r.amount,0)) = 0; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt + SELECT cd.id as clientFk + FROM bs.clientDied cd + LEFT JOIN clientProtected cp ON cp.clientFk = cd.id + JOIN client c ON c.id = cd.id + JOIN province p ON p.id = c.provinceFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk + JOIN country co ON co.id = p.countryFk + WHERE cd.Aviso = 'TERCER AVISO' + AND cp.clientFk IS NULL + AND co.code NOT IN ('PT') + AND a.name <> 'Canarias' + AND c.salesPersonFk IS NOT NULL; + + OPEN rs; + FETCH rs INTO vClientFk; + WHILE NOT vDone DO + CALL vn.clientGreugeSpray(vClientFk, TRUE, '',TRUE); + UPDATE vn.client SET salesPersonFk = NULL WHERE id = vClientFk; + FETCH rs INTO vClientFk; + END WHILE; + CLOSE rs; + DROP TEMPORARY TABLE tmp.clientGetDebt; +END$$ +DELIMITER ; + +CALL vn.clientRemoveWorker1(); +DROP PROCEDURE vn.clientRemoveWorker1; diff --git a/db/versions/10644-aquaLaurel/00-firstScript.sql b/db/versions/10644-aquaLaurel/00-firstScript.sql new file mode 100644 index 000000000..cf09bc029 --- /dev/null +++ b/db/versions/10644-aquaLaurel/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE vn.expeditionBoxVol ADD code varchar(45) DEFAULT NULL NULL; +ALTER TABLE vn.routeMaster CHANGE mounth `month` int(11) DEFAULT 0 NOT NULL; +ALTER TABLE vn.routeMaster CHANGE warehoseFk warehouseFk smallint(6) unsigned DEFAULT NULL NULL; + + diff --git a/db/versions/10645-purplePalmetto/00-addNewFields.sql b/db/versions/10645-purplePalmetto/00-addNewFields.sql new file mode 100644 index 000000000..524cbe6d8 --- /dev/null +++ b/db/versions/10645-purplePalmetto/00-addNewFields.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.collectionWagonTicket ADD rgb varchar(30) NULL COMMENT 'Color de la balda'; +ALTER TABLE vn.collectionWagonTicket ADD height int(11) NULL COMMENT 'altura de la balda'; \ No newline at end of file diff --git a/db/versions/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql b/db/versions/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql new file mode 100644 index 000000000..8bd540252 --- /dev/null +++ b/db/versions/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.collectionWagonTicket DROP FOREIGN KEY collectionWagonTicket_ticket; +ALTER TABLE vn.collectionWagonTicket DROP PRIMARY KEY; +ALTER TABLE vn.collectionWagonTicket ADD CONSTRAINT collectionWagonTicket_PK PRIMARY KEY (ticketFk,trayFk); +ALTER TABLE vn.collectionWagonTicket ADD CONSTRAINT collectionWagonTicket_FK FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10645-purplePalmetto/02-updateWagonPrimaryKey.sql b/db/versions/10645-purplePalmetto/02-updateWagonPrimaryKey.sql new file mode 100644 index 000000000..80078c510 --- /dev/null +++ b/db/versions/10645-purplePalmetto/02-updateWagonPrimaryKey.sql @@ -0,0 +1,20 @@ +ALTER TABLE vn.wagonVolumetry DROP FOREIGN KEY wagonVolumetry_FK; +ALTER TABLE vn.wagonVolumetry MODIFY COLUMN wagonFk VARCHAR(6) NOT NULL; + +ALTER TABLE vn.collectionWagon DROP FOREIGN KEY collectionWagon_wagon; +ALTER TABLE vn.collectionWagon MODIFY COLUMN wagonFk VARCHAR(6) NOT NULL; + +ALTER TABLE vn.collectionWagonTicket DROP FOREIGN KEY collectionWagonTicket_wagon; +ALTER TABLE vn.collectionWagonTicket MODIFY COLUMN wagonFk VARCHAR(6) NOT NULL; + +ALTER TABLE vn.wagon MODIFY COLUMN id varchar(6) NOT NULL COMMENT '26 letras de alfabeto inglés'; + +ALTER TABLE vn.wagonVolumetry ADD CONSTRAINT wagonVolumetry_FK_1 FOREIGN KEY (wagonFk) REFERENCES vn.wagon(id) ON UPDATE CASCADE; + +ALTER TABLE vn.collectionWagon COLLATE=utf8mb3_unicode_ci; +ALTER TABLE vn.collectionWagon MODIFY COLUMN wagonFk varchar(6) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; +ALTER TABLE vn.collectionWagon ADD CONSTRAINT collectionWagon_FK_1 FOREIGN KEY (wagonFk) REFERENCES vn.wagon(id) ON UPDATE CASCADE; + +ALTER TABLE vn.collectionWagonTicket COLLATE=utf8mb3_unicode_ci; +ALTER TABLE vn.collectionWagonTicket MODIFY COLUMN wagonFk varchar(6) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; +ALTER TABLE vn.collectionWagonTicket ADD CONSTRAINT collectionWagonTicket_FK_1 FOREIGN KEY (wagonFk) REFERENCES vn.wagon(id) ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10645-purplePalmetto/03-addFieldToPackingSite.sql b/db/versions/10645-purplePalmetto/03-addFieldToPackingSite.sql new file mode 100644 index 000000000..1047a4681 --- /dev/null +++ b/db/versions/10645-purplePalmetto/03-addFieldToPackingSite.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.packingSite ADD parkingFk int(11) NULL; +ALTER TABLE vn.packingSite ADD CONSTRAINT packingSite_FK_3 FOREIGN KEY (parkingFk) REFERENCES vn.parking(id) ON DELETE CASCADE ON UPDATE SET NULL; \ No newline at end of file diff --git a/db/versions/10647-goldenBamboo/00-renombrarTabla.sql b/db/versions/10647-goldenBamboo/00-renombrarTabla.sql new file mode 100644 index 000000000..562472d28 --- /dev/null +++ b/db/versions/10647-goldenBamboo/00-renombrarTabla.sql @@ -0,0 +1,2 @@ +RENAME TABLE postgresql.media_type TO postgresql.media_type__; +ALTER TABLE postgresql.media_type__ COMMENT='#5374 @deprecated 2023-06-19'; diff --git a/db/versions/10648-blackBirch/00-firstScript.sql b/db/versions/10648-blackBirch/00-firstScript.sql new file mode 100644 index 000000000..8f5c37a87 --- /dev/null +++ b/db/versions/10648-blackBirch/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.workerDocument DROP FOREIGN KEY workerDocument_ibfk_1; +ALTER TABLE vn.workerDocument ADD CONSTRAINT workerDocument_FK FOREIGN KEY (worker) REFERENCES vn.worker(id) ON DELETE RESTRICT ON UPDATE CASCADE; + diff --git a/db/versions/10649-yellowAsparagus/00-firstScript.sql b/db/versions/10649-yellowAsparagus/00-firstScript.sql new file mode 100644 index 000000000..6ab678808 --- /dev/null +++ b/db/versions/10649-yellowAsparagus/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplierLog MODIFY COLUMN originFk int(10) unsigned NULL; diff --git a/db/versions/10651-chocolatePalmetto/00-comparativeCountryFk.sql b/db/versions/10651-chocolatePalmetto/00-comparativeCountryFk.sql new file mode 100644 index 000000000..d8c41cfe2 --- /dev/null +++ b/db/versions/10651-chocolatePalmetto/00-comparativeCountryFk.sql @@ -0,0 +1,40 @@ + +DROP VIEW IF EXISTS vn.comparative; + +CREATE TABLE IF NOT EXISTS vn.comparative ( + id int unsigned auto_increment NULL, + timePeriod int NULL, + itemFk int(11) NULL, + warehouseFk smallint(6) unsigned NULL, + quantity int NULL, + price int NULL, + countryFk mediumint(8) unsigned NULL, + CONSTRAINT comparative_PK PRIMARY KEY (id), + CONSTRAINT comparative_UN UNIQUE KEY (timePeriod,itemFk,warehouseFk), + CONSTRAINT comparativeItem_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id), + CONSTRAINT comparativeWarehouse_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id), + CONSTRAINT comparativeCountry_FK FOREIGN KEY (countryFk) REFERENCES vn.country(id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT INTO vn.comparative( + timePeriod, + itemFk, + warehouseFk, + quantity, + price +) + SELECT c.Periodo, + c.Id_Article, + c.warehouse_id, + c.Cantidad, + c.price + FROM vn2008.Comparativa c + JOIN vn.item i ON i.id = c.Id_Article + JOIN vn.warehouse w ON w.id = c.warehouse_id; + +RENAME TABLE vn2008.Comparativa TO vn2008.Comparativa__; + +ALTER TABLE vn2008.Comparativa__ COMMENT= '20/11/2023'; \ No newline at end of file diff --git a/db/versions/10651-chocolatePalmetto/01-comparativeAddConfig.sql b/db/versions/10651-chocolatePalmetto/01-comparativeAddConfig.sql new file mode 100644 index 000000000..a718fd1ae --- /dev/null +++ b/db/versions/10651-chocolatePalmetto/01-comparativeAddConfig.sql @@ -0,0 +1,11 @@ +-- Place your SQL code here +CREATE TABLE IF NOT EXISTS vn.`comparativeAddConfig` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `period` INT(10) UNSIGNED DEFAULT NULL COMMENT 'The number of periods to be regressed for insertion in vn.comparative', + `week` INT(10) UNSIGNED DEFAULT NULL COMMENT 'The number of weeks to exceed for recalculating the last period', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO vn.comparativeAddConfig (period, week) + VALUES (3, 3); + diff --git a/db/versions/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql b/db/versions/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql new file mode 100644 index 000000000..fec4f9a46 --- /dev/null +++ b/db/versions/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +DELETE FROM bs.nightTask + WHERE `procedure` = 'comparativa_add'; + +INSERT IGNORE INTO bs.nightTask (`order`,`schema`,`procedure`) + VALUES (260,'vn','comparative_add'); diff --git a/db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql b/db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql new file mode 100644 index 000000000..151d1a24b --- /dev/null +++ b/db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql @@ -0,0 +1,2 @@ +GRANT EXECUTE ON PROCEDURE vn.item_comparative TO claimManager, buyer; +FLUSH PRIVILEGES; diff --git a/db/versions/10652-maroonPhormium/00-firstScript.sql b/db/versions/10652-maroonPhormium/00-firstScript.sql new file mode 100644 index 000000000..3cad31e56 --- /dev/null +++ b/db/versions/10652-maroonPhormium/00-firstScript.sql @@ -0,0 +1,4 @@ +RENAME TABLE postgresql.labour_agreement TO postgresql.labour_agreement__; +ALTER TABLE postgresql.labour_agreement__ +COMMENT='deprecated 2023-06-21'; + diff --git a/db/versions/10653-redHydrangea/00-firstScript.sql b/db/versions/10653-redHydrangea/00-firstScript.sql new file mode 100644 index 000000000..3e20614d0 --- /dev/null +++ b/db/versions/10653-redHydrangea/00-firstScript.sql @@ -0,0 +1,3 @@ +RENAME TABLE postgresql.profile_address TO postgresql.profile_address__; +ALTER TABLE postgresql.profile_address__ COMMENT='deprecated 2023-07-03'; + diff --git a/db/versions/10655-navyRuscus/00-firstScript.sql b/db/versions/10655-navyRuscus/00-firstScript.sql new file mode 100644 index 000000000..4c99697ef --- /dev/null +++ b/db/versions/10655-navyRuscus/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here +USE vn; + +ALTER TABLE vn.worker CHANGE labelerFk labelerFk__ tinyint(3) unsigned DEFAULT NULL NULL COMMENT '@deprecated 2023-06-26'; +ALTER TABLE vn.worker CHANGE sectorFk sectorFk__ int(11) DEFAULT NULL NULL COMMENT '@deprecated 2023-06-26'; + diff --git a/db/versions/10656-navyMastic/00-firstScript.sql b/db/versions/10656-navyMastic/00-firstScript.sql new file mode 100644 index 000000000..077829579 --- /dev/null +++ b/db/versions/10656-navyMastic/00-firstScript.sql @@ -0,0 +1,34 @@ +UPDATE sage.taxType tt + JOIN sage.TiposIva ti ON ti.CodigoIva = tt.id + SET tt.code = 'nonTaxable' + WHERE ti.Iva = 'Operaciones no sujetas'; + +ALTER TABLE sage.config ADD nontaxableTransactionTypeFk TINYINT(4) NULL + COMMENT 'Transacción Operaciones exentas'; +ALTER TABLE sage.config ADD pendingServiceTransactionTypeFk TINYINT(4) NULL + COMMENT 'Transacción Import. bienes y serv. corrientes pdte. liquidar'; +ALTER TABLE sage.config ADD definitiveExportTransactionTypeFk TINYINT(4) NULL + COMMENT 'Transacción Exportaciones definitivas'; +ALTER TABLE sage.config ADD shipmentTransactionTypeFk TINYINT(4) NULL + COMMENT 'Transacción Envíos definitivos a Canarias, Ceuta y Melilla'; + +UPDATE sage.config c + JOIN sage.TiposTransacciones tt + ON tt.Transaccion = 'Operaciones exentas' + SET c.nontaxableTransactionTypeFk = tt.CodigoTransaccion; + +UPDATE sage.config c + JOIN sage.TiposTransacciones tt + ON tt.Transaccion = 'Import. bienes y serv. corrientes pdte. liquidar' + SET c.pendingServiceTransactionTypeFk = tt.CodigoTransaccion; + +UPDATE sage.config c + JOIN sage.TiposTransacciones tt + ON tt.Transaccion = 'Exportaciones definitivas' + SET c.definitiveExportTransactionTypeFk = tt.CodigoTransaccion; + + +UPDATE sage.config c + JOIN sage.TiposTransacciones tt + ON tt.Transaccion = 'Envíos definitivos a Canarias, Ceuta y Melilla' + SET c.shipmentTransactionTypeFk = tt.CodigoTransaccion; diff --git a/db/versions/10657-redDracena/00-renameErrorProduction.sql b/db/versions/10657-redDracena/00-renameErrorProduction.sql new file mode 100644 index 000000000..1b39039a7 --- /dev/null +++ b/db/versions/10657-redDracena/00-renameErrorProduction.sql @@ -0,0 +1 @@ +RENAME TABLE vn.errorProduction TO vn.productionError; \ No newline at end of file diff --git a/db/versions/10657-redDracena/01-changeNightTask.sql b/db/versions/10657-redDracena/01-changeNightTask.sql new file mode 100644 index 000000000..9b55d1583 --- /dev/null +++ b/db/versions/10657-redDracena/01-changeNightTask.sql @@ -0,0 +1 @@ +UPDATE bs.nightTask SET `procedure` = "productionError_add" WHERE `procedure` = "errorProduction_addLauncher" \ No newline at end of file diff --git a/db/versions/10657-redDracena/02-addCodeToClaimResponsible.sql b/db/versions/10657-redDracena/02-addCodeToClaimResponsible.sql new file mode 100644 index 000000000..07b602f88 --- /dev/null +++ b/db/versions/10657-redDracena/02-addCodeToClaimResponsible.sql @@ -0,0 +1,27 @@ +ALTER TABLE vn.claimResponsible ADD code varchar(3) NOT NULL; + +UPDATE vn.claimResponsible SET code='buy' WHERE `description` = "Compradores"; +UPDATE vn.claimResponsible SET code='sup' WHERE `description` = "Proveedor"; +UPDATE vn.claimResponsible SET code='ent' WHERE `description` = "Entradores"; +UPDATE vn.claimResponsible SET code='bar' WHERE `description` = "Camareros"; +UPDATE vn.claimResponsible SET code='pic' WHERE `description` = "Sacadores"; +UPDATE vn.claimResponsible SET code='chk' WHERE `description` = "Revisadores"; +UPDATE vn.claimResponsible SET code='qas' WHERE `description` = "Calidad general"; +UPDATE vn.claimResponsible SET code='pck' WHERE `description` = "Encajadores"; +UPDATE vn.claimResponsible SET code='wea' WHERE `description` = "Clima"; +UPDATE vn.claimResponsible SET code='com' WHERE `description` = "Comerciales"; +UPDATE vn.claimResponsible SET code='cli' WHERE `description` = "Clientes"; +UPDATE vn.claimResponsible SET code='adm' WHERE `description` = "Administración"; +UPDATE vn.claimResponsible SET code='age' WHERE `description` = "Agencia"; +UPDATE vn.claimResponsible SET code='del' WHERE `description` = "Repartidores"; +UPDATE vn.claimResponsible SET code='ite' WHERE `description` = "Informatica"; +UPDATE vn.claimResponsible SET code='tra' WHERE `description` = "Transp.origen"; +UPDATE vn.claimResponsible SET code='con' WHERE `description` = "Confeccion"; +UPDATE vn.claimResponsible SET code='oth' WHERE `description` = "OTROS"; +UPDATE vn.claimResponsible SET code='man' WHERE `description` = "Gerencia"; +UPDATE vn.claimResponsible SET code='pal' WHERE `description` = "Paletizadores"; +UPDATE vn.claimResponsible SET code='pre' WHERE `description` = "Preparación Previa"; +UPDATE vn.claimResponsible SET code='war' WHERE `description` = "Almacén PCA"; +UPDATE vn.claimResponsible SET code='str' WHERE `description` = "Huelga"; + +ALTER TABLE vn.claimResponsible ADD CONSTRAINT claimResponsible_UN UNIQUE KEY (code); \ No newline at end of file diff --git a/db/versions/10657-redDracena/03-grantSelectGrafana.sql b/db/versions/10657-redDracena/03-grantSelectGrafana.sql new file mode 100644 index 000000000..f910f4df4 --- /dev/null +++ b/db/versions/10657-redDracena/03-grantSelectGrafana.sql @@ -0,0 +1 @@ +GRANT SELECT ON TABLE vn.productionError TO `grafana`@`10.0.%.%`; \ No newline at end of file diff --git a/db/versions/10658-whiteDracena/00-firstScript.sql b/db/versions/10658-whiteDracena/00-firstScript.sql new file mode 100644 index 000000000..4af955f8a --- /dev/null +++ b/db/versions/10658-whiteDracena/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn2008.account_detail DROP FOREIGN KEY fk_account_detail_account_id_proveedores_account; +ALTER TABLE vn2008.account_detail ADD CONSTRAINT fk_account_detail_account_id_proveedores_account +FOREIGN KEY (Id_Proveedores_account) REFERENCES vn.supplierAccount(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10659-azureDracena/00-firstScript.sql b/db/versions/10659-azureDracena/00-firstScript.sql new file mode 100644 index 000000000..3299481c6 --- /dev/null +++ b/db/versions/10659-azureDracena/00-firstScript.sql @@ -0,0 +1,11 @@ +USE vn; +DELETE tc FROM vn.ticketCollection tc + JOIN ( + SELECT id, COUNT(ticketFk) counter + FROM vn.ticketCollection + GROUP BY ticketFk + HAVING counter > 1 + ) sub ON sub.id = tc.id; + +ALTER TABLE vn.ticketCollection DROP KEY ticketCollection_UN; +ALTER TABLE vn.ticketCollection ADD CONSTRAINT ticketCollection_UN UNIQUE KEY (ticketFk); diff --git a/db/versions/10661-crimsonIvy/00-firstScript.sql b/db/versions/10661-crimsonIvy/00-firstScript.sql new file mode 100644 index 000000000..d0ac38b87 --- /dev/null +++ b/db/versions/10661-crimsonIvy/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn.itemShelving ADD buyFk int(11) NULL; +ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelvingBuy_FK FOREIGN KEY (buyFk) REFERENCES vn.buy(id); +ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_UN UNIQUE KEY (buyFk,shelvingFk); \ No newline at end of file diff --git a/db/versions/10662-wheatErica/00-firstScript.sql b/db/versions/10662-wheatErica/00-firstScript.sql new file mode 100644 index 000000000..7cb5b1d45 --- /dev/null +++ b/db/versions/10662-wheatErica/00-firstScript.sql @@ -0,0 +1,2 @@ +UPDATE IGNORE vn.invoiceIn SET currencyFk = 1 WHERE NOT currencyFk; +ALTER TABLE vn.invoiceIn ADD CONSTRAINT invoiceIn_FK FOREIGN KEY (currencyFk) REFERENCES vn.currency(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10663-tealCymbidium/00-firstScript.sql b/db/versions/10663-tealCymbidium/00-firstScript.sql new file mode 100644 index 000000000..ffc60d47d --- /dev/null +++ b/db/versions/10663-tealCymbidium/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.vehicle ADD CONSTRAINT vehicle_UN UNIQUE KEY (numberPlate); \ No newline at end of file diff --git a/db/versions/10665-maroonSalal/00-firstScript.sql b/db/versions/10665-maroonSalal/00-firstScript.sql new file mode 100644 index 000000000..7283a2b36 --- /dev/null +++ b/db/versions/10665-maroonSalal/00-firstScript.sql @@ -0,0 +1,19 @@ +ALTER TABLE vn.business DROP FOREIGN KEY business_workerBusinessAgreementFk; + +CREATE TABLE `vn`.`workerBusinessAgreement` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + `monthHolidays` double DEFAULT NULL, + `yearHours` int(11) DEFAULT NULL, + `started` date DEFAULT NULL, + `ended` date DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; + +INSERT INTO vn.workerBusinessAgreement + SELECT labour_agreement_id, name, month_hollidays, year_hours, date_START, date_END + FROM postgresql.labour_agreement__; + +ALTER TABLE vn.business ADD CONSTRAINT business_workerBusinessAgreementFk FOREIGN KEY (workerBusinessAgreementFk) REFERENCES vn.workerBusinessAgreement(id) ON DELETE RESTRICT ON UPDATE CASCADE; + +DROP TABLE postgresql.labour_agreement__; diff --git a/db/versions/10666-limeGerbera/00-firstScript.sql b/db/versions/10666-limeGerbera/00-firstScript.sql new file mode 100644 index 000000000..866a8de18 --- /dev/null +++ b/db/versions/10666-limeGerbera/00-firstScript.sql @@ -0,0 +1,3 @@ +RENAME TABLE vn2008.Colores TO vn2008.Colores__; +ALTER TABLE vn2008.Colores__ COMMENT='refs #5903 deprecated 2023-06-30'; + diff --git a/db/versions/10667-blackChrysanthemum/00-firstScript.sql b/db/versions/10667-blackChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..b05518b35 --- /dev/null +++ b/db/versions/10667-blackChrysanthemum/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entryConfig ADD defaultSupplierFk int(11) DEFAULT 13 NULL; \ No newline at end of file diff --git a/db/versions/10668-tealBirch/00-firstScript.sql b/db/versions/10668-tealBirch/00-firstScript.sql new file mode 100644 index 000000000..2cbad363f --- /dev/null +++ b/db/versions/10668-tealBirch/00-firstScript.sql @@ -0,0 +1,29 @@ +ALTER TABLE vn.deviceProduction ADD editorFk int(10) unsigned NULL; +ALTER TABLE vn.deviceProductionModels ADD editorFk int(10) unsigned NULL; +ALTER TABLE vn.deviceProductionState ADD editorFk int(10) unsigned NULL; +ALTER TABLE vn.deviceProductionUser ADD editorFk int(10) unsigned NULL; +ALTER TABLE vn.deviceProduction ADD CONSTRAINT deviceProduction_fk_editor FOREIGN KEY (editorFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.deviceProductionModels ADD CONSTRAINT deviceProductionModels_fk_editor FOREIGN KEY (editorFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.deviceProductionState ADD CONSTRAINT deviceProductionState_fk_editor FOREIGN KEY (editorFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE RESTRICT; +ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_fk_editor FOREIGN KEY (editorFk) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE RESTRICT; + +DROP TABLE vn.deviceProductionLog; +CREATE TABLE `vn`.`deviceProductionLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('DeviceProduction','DeviceProductionModels','DeviceProductionState','DeviceProductionUser') NOT NULL DEFAULT 'DeviceProduction', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `userFk` (`userFk`), + KEY `deviceProductionLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `deviceProductionLog_deviceProductionLog` (`originFk`,`creationDate`), + CONSTRAINT `deviceProductionOriginFk` FOREIGN KEY (`originFk`) REFERENCES `deviceProduction` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `deviceProductionUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; \ No newline at end of file diff --git a/db/versions/10671-maroonIvy/00-firstScript.sql b/db/versions/10671-maroonIvy/00-firstScript.sql new file mode 100644 index 000000000..f67ee98bc --- /dev/null +++ b/db/versions/10671-maroonIvy/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.floramondoConfig ADD daysToKeepItem int(4) NULL COMMENT 'Número de dias para mantener artículos'; +UPDATE IGNORE vn.floramondoConfig SET daysToKeepItem=7 WHERE id=1; diff --git a/db/versions/10675-grayRuscus/00-firstScript.sql b/db/versions/10675-grayRuscus/00-firstScript.sql new file mode 100644 index 000000000..39bed640e --- /dev/null +++ b/db/versions/10675-grayRuscus/00-firstScript.sql @@ -0,0 +1 @@ +DROP EVENT vn.ticketClosure; diff --git a/db/versions/10676-aquaTulip/00-firstScript.sql b/db/versions/10676-aquaTulip/00-firstScript.sql new file mode 100644 index 000000000..c956c60f4 --- /dev/null +++ b/db/versions/10676-aquaTulip/00-firstScript.sql @@ -0,0 +1,4 @@ +DROP TABLE IF EXISTS vn.chronopostConfig; +DROP TABLE IF EXISTS vn.chronopostExpedition; +DROP TABLE IF EXISTS vn.chronopostSenderAddress; +DROP TABLE IF EXISTS vn.chronopostServiceWeekday; \ No newline at end of file diff --git a/db/versions/10677-yellowMoss/00-firstScript.sql b/db/versions/10677-yellowMoss/00-firstScript.sql new file mode 100644 index 000000000..400f1d9d5 --- /dev/null +++ b/db/versions/10677-yellowMoss/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.packagingConfig ADD defaultSmallPackageFk VARCHAR(10) DEFAULT '94p' NOT NULL COMMENT 'bulto pequeño'; +ALTER TABLE vn.packagingConfig ADD defaultBigPackageFk VARCHAR(10) DEFAULT '94m' NOT NULL COMMENT 'bulto grande'; +ALTER TABLE vn.packagingConfig ADD CONSTRAINT packagingConfig_FK FOREIGN KEY (defaultSmallPackageFk) REFERENCES vn.packaging(id) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.packagingConfig ADD CONSTRAINT packagingConfig_FK_1 FOREIGN KEY (defaultBigPackageFk) REFERENCES vn.packaging(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10678-orangeMedeola/00-firstScript.sql b/db/versions/10678-orangeMedeola/00-firstScript.sql new file mode 100644 index 000000000..e0c09a14c --- /dev/null +++ b/db/versions/10678-orangeMedeola/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.itemConfig ADD downloadMaxAttempts tinyint(3) DEFAULT NULL NULL COMMENT 'Intentos máximos para que se borre'; +INSERT IGNORE INTO vn.itemConfig (downloadMaxAttempts) VALUES (3); diff --git a/db/versions/10679-inventoryDiscrepancy/00-tables.sql b/db/versions/10679-inventoryDiscrepancy/00-tables.sql new file mode 100644 index 000000000..ab4f1b475 --- /dev/null +++ b/db/versions/10679-inventoryDiscrepancy/00-tables.sql @@ -0,0 +1,28 @@ + +-- bs.inventoryDiscrepancy definition +USE bs; + +CREATE TABLE `inventoryDiscrepancy` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `warehouseFk` int(11) NOT NULL, + `timed` timestamp NOT NULL DEFAULT current_timestamp(), + `alert` int(11) NOT NULL DEFAULT 0, + `quantity` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB +COMMENT='This table collects the discrepancies between theorical inventory and located items'; + +-- bs.inventoryDiscrepancyDetail definition + +CREATE TABLE `inventoryDiscrepancyDetail` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `warehouseFk` int(11) NOT NULL, + `itemFk` int(11) NOT NULL, + `theorical` int(11) DEFAULT NULL COMMENT 'theorical stock: purchases vs. sales', + `visible` int(11) DEFAULT NULL COMMENT 'located stock', + `notPicked` int(11) DEFAULT NULL COMMENT 'sales not picked yet', + `alert` int(11) DEFAULT NULL COMMENT 'alert level for this discrepancy', + PRIMARY KEY (`id`), + UNIQUE KEY `inventoryDiscrepancyDetail_UN` (`warehouseFk`,`itemFk`) + ) ENGINE=InnoDB + COMMENT='Last discrepancies'; \ No newline at end of file diff --git a/db/versions/10680-turquoiseLilium/00-firstScript.sql b/db/versions/10680-turquoiseLilium/00-firstScript.sql new file mode 100644 index 000000000..1b15d79c1 --- /dev/null +++ b/db/versions/10680-turquoiseLilium/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.stockBuyed CHANGE `date` dated date DEFAULT NULL NULL; +ALTER TABLE vn.stockBuyed CHANGE `user` userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/10682-crimsonEucalyptus/00-firstScript.sql b/db/versions/10682-crimsonEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..c63d644a9 --- /dev/null +++ b/db/versions/10682-crimsonEucalyptus/00-firstScript.sql @@ -0,0 +1,15 @@ +CREATE TABLE bs.clientDiedPeriod ( + id int(10) unsigned auto_increment NOT NULL, + countryFk mediumint(8) unsigned NOT NULL, + days int(11) NOT NULL, + CONSTRAINT clientDiedPeriod_PK PRIMARY KEY (id), + CONSTRAINT clientDiedPeriod_UN UNIQUE KEY (countryFk), + CONSTRAINT clientDiedPeriod_FK FOREIGN KEY (countryFk) REFERENCES vn.country(id) ON DELETE RESTRICT ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci +COMMENT='Define lo que es un periodo para los clientes de los diferentes países'; + +DELETE IGNORE FROM bs.nightTask + WHERE `procedure` = 'clientDied_recalc'; diff --git a/db/versions/10683-bronzeMastic/00-firstScript.sql b/db/versions/10683-bronzeMastic/00-firstScript.sql new file mode 100644 index 000000000..8ca6ff831 --- /dev/null +++ b/db/versions/10683-bronzeMastic/00-firstScript.sql @@ -0,0 +1,20 @@ +-- Place your SQL code here +DROP TABLE IF EXISTS vn.comparativeConfig; + +CREATE TABLE IF NOT EXISTS vn.comparativeConfig ( + id int unsigned NOT NULL AUTO_INCREMENT, + defaultDayRange int unsigned NULL COMMENT 'Rango de días predeterminado si no se especifica', + weekRange int unsigned NULL COMMENT 'La cantidad de semanas que se restarán y sumarán', + maxDayRange int unsigned NULL COMMENT 'El rango máximo de días antes de utilizar el rango de días predeterminado', + minDayRange int unsigned NULL COMMENT 'El rango mínimo de días antes de utilizar el rango de días predeterminado', + PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO vn.comparativeConfig + SET defaultDayRange = 21, + weekRange = 3, + maxDayRange = 60, + minDayRange = 0; \ No newline at end of file diff --git a/db/versions/10684-tealEucalyptus/00-firstScript.sql b/db/versions/10684-tealEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..152f13f53 --- /dev/null +++ b/db/versions/10684-tealEucalyptus/00-firstScript.sql @@ -0,0 +1,2 @@ +RENAME TABLE vn.botanicExport TO vn.botanicExport__; +ALTER TABLE vn.botanicExport__ COMMENT='refs #4419 Deprecated 2023-07-20'; \ No newline at end of file diff --git a/db/versions/10685-blueMedeola/00-firstScript.sql b/db/versions/10685-blueMedeola/00-firstScript.sql new file mode 100644 index 000000000..d60801291 --- /dev/null +++ b/db/versions/10685-blueMedeola/00-firstScript.sql @@ -0,0 +1,23 @@ +-- Place your SQL code here +ALTER TABLE vn.clientContact + ADD CONSTRAINT clientContact_FK FOREIGN KEY (clientFk) REFERENCES vn.client(id) + ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.clientSample MODIFY COLUMN clientFk int(11) NOT NULL; + +ALTER TABLE vn.clientSample + ADD CONSTRAINT clientSample_FK FOREIGN KEY (clientFk) REFERENCES vn.client(id) + ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.greuge MODIFY COLUMN clientFk int(11) NOT NULL; + +ALTER TABLE vn.greuge + ADD CONSTRAINT greuge_FK_1 FOREIGN KEY (clientFk) REFERENCES vn.client(id) + ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.supplierAddress MODIFY COLUMN supplierFk int(10) UNSIGNED DEFAULT NULL NULL; +-- poner unsigned + +ALTER TABLE vn.supplierAddress + ADD CONSTRAINT supplierAddress_FK FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) + ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10690-azureGalax/00-firstScript.sql b/db/versions/10690-azureGalax/00-firstScript.sql new file mode 100644 index 000000000..7c05d905b --- /dev/null +++ b/db/versions/10690-azureGalax/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.entry CHANGE isBlocked__ isBlocked tinyint(4) DEFAULT 0 NOT NULL; diff --git a/db/versions/10691-bronzeCamellia/00-firstScript.sql b/db/versions/10691-bronzeCamellia/00-firstScript.sql new file mode 100644 index 000000000..0d409a389 --- /dev/null +++ b/db/versions/10691-bronzeCamellia/00-firstScript.sql @@ -0,0 +1,7 @@ + +ALTER TABLE vn.invoiceInLog MODIFY COLUMN changedModel enum('InvoiceIn','InvoiceInTax','InvoiceInDueDay') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'InvoiceIn' NOT NULL; + +ALTER TABLE `vn`.`invoiceInDueDay` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT invoiceInDueDay_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); \ No newline at end of file diff --git a/db/versions/10692-silverLilium/00-firstScript.sql b/db/versions/10692-silverLilium/00-firstScript.sql new file mode 100644 index 000000000..faf91c393 --- /dev/null +++ b/db/versions/10692-silverLilium/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE bs.salesByItemTypeDay DROP FOREIGN KEY itemTypeSalesByweek_itemCategoryFk; +ALTER TABLE bs.salesByItemTypeDay DROP COLUMN itemCategoryFk; +ALTER TABLE bs.salesByItemTypeDay DROP COLUMN saleComponent; diff --git a/db/versions/10693-chocolateCordyline/00-firstScript.sql b/db/versions/10693-chocolateCordyline/00-firstScript.sql new file mode 100644 index 000000000..bc19d0af5 --- /dev/null +++ b/db/versions/10693-chocolateCordyline/00-firstScript.sql @@ -0,0 +1,2 @@ +RENAME TABLE bi.rutasBoard TO bi.rutasBoard__; +ALTER TABLE bi.rutasBoard__ COMMENT='refs #5801 @deprecated 2023-07-27'; diff --git a/db/versions/10694-bluePaniculata/00-firstScript.sql b/db/versions/10694-bluePaniculata/00-firstScript.sql new file mode 100644 index 000000000..db0ef6e17 --- /dev/null +++ b/db/versions/10694-bluePaniculata/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.company MODIFY COLUMN stamp longblob DEFAULT NULL NULL; +ALTER TABLE vn.supplier ADD stamp longblob DEFAULT NULL NULL; +ALTER TABLE vn.supplier CHANGE stamp stamp longblob DEFAULT NULL NULL AFTER isVies; diff --git a/db/versions/10695-pinkMastic/00-firstScript.sql b/db/versions/10695-pinkMastic/00-firstScript.sql new file mode 100644 index 000000000..212cedb6e --- /dev/null +++ b/db/versions/10695-pinkMastic/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.ticket ADD cmrFk int(11) DEFAULT NULL NULL; +ALTER TABLE vn.ticket ADD CONSTRAINT ticket_cmrFk FOREIGN KEY (cmrFk) REFERENCES vn.cmr(id) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE vn.ticket CHANGE cmrFk cmrFk int(11) DEFAULT NULL NULL AFTER clonedFrom; +ALTER TABLE vn.cmr MODIFY COLUMN ticketFk int(11) DEFAULT NULL NULL COMMENT 'refs #6092 @toDeprecate 2023-08-02'; \ No newline at end of file diff --git a/db/versions/10696-blackCataractarum/00-firstScript.sql b/db/versions/10696-blackCataractarum/00-firstScript.sql new file mode 100644 index 000000000..7a91697ff --- /dev/null +++ b/db/versions/10696-blackCataractarum/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.itemTag MODIFY COLUMN value varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; diff --git a/db/versions/10698-yellowGalax/00-firstScript.sql b/db/versions/10698-yellowGalax/00-firstScript.sql new file mode 100644 index 000000000..b3b4141fc --- /dev/null +++ b/db/versions/10698-yellowGalax/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.cmr DROP FOREIGN KEY cmr_fk1; +ALTER TABLE vn.cmr ADD CONSTRAINT cmr_fk1 FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id); diff --git a/db/versions/10699-aquaOak/00-firstScript.sql b/db/versions/10699-aquaOak/00-firstScript.sql new file mode 100644 index 000000000..b64ceaadf --- /dev/null +++ b/db/versions/10699-aquaOak/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.cmr MODIFY COLUMN senderInstruccions varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; +ALTER TABLE vn.cmr MODIFY COLUMN paymentInstruccions varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; diff --git a/db/versions/10700-salmonTulip/00-firstScript.sql b/db/versions/10700-salmonTulip/00-firstScript.sql new file mode 100644 index 000000000..fef078e1f --- /dev/null +++ b/db/versions/10700-salmonTulip/00-firstScript.sql @@ -0,0 +1,3 @@ +RENAME TABLE vn2008.Entradas_dits TO vn2008.Entradas_dits__; +ALTER TABLE vn2008.Entradas_dits__ COMMENT='refs #6039 @deprecated 2023-08-04'; + diff --git a/db/versions/10701-turquoisePaniculata/00-firstScript.sql b/db/versions/10701-turquoisePaniculata/00-firstScript.sql new file mode 100644 index 000000000..16504797f --- /dev/null +++ b/db/versions/10701-turquoisePaniculata/00-firstScript.sql @@ -0,0 +1,21 @@ +USE vn; +ALTER TABLE vn.duaTax DROP FOREIGN KEY duaTax_supplierFk; +ALTER TABLE vn.duaTax DROP INDEX duaTax_fk2_idx; +ALTER TABLE vn.duaTax DROP COLUMN supplierFk; + +UPDATE vn.duaTax d + JOIN ( + SELECT duaFk, taxClassFk , SUM(base) totalBase, rate, SUM(tax)totalTax + FROM vn.duaTax + GROUP BY duaFk, taxClassFk + )sub ON sub.duaFk = d.id + SET d.base = totalBase, + d.tax = totalTax; + +DELETE d FROM vn.duaTax d + LEFT JOIN ( + SELECT id + FROM vn.duaTax + GROUP BY duaFk, taxClassFk + )sub ON sub.id = d.id + WHERE sub.id IS NULL; \ No newline at end of file diff --git a/db/versions/10702-crimsonCymbidium/00-firstScript.sql b/db/versions/10702-crimsonCymbidium/00-firstScript.sql new file mode 100644 index 000000000..1429017da --- /dev/null +++ b/db/versions/10702-crimsonCymbidium/00-firstScript.sql @@ -0,0 +1,11 @@ +-- Place your SQL code here +USE vn; +CREATE TABLE vn.`routeDefaultAgencyMode` ( + `id` int(11) NOT NULL DEFAULT 0, + `workcenterFk` int(11) UNIQUE DEFAULT NULL, + `agencyModeFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; + +ALTER TABLE vn.routeDefaultAgencyMode ADD CONSTRAINT routeDefaultAgencyMode_FK FOREIGN KEY (agencyModeFk) REFERENCES vn.`agencyMode`(id); +ALTER TABLE vn.routeDefaultAgencyMode ADD CONSTRAINT routeDefaultAgencyMode_FK_1 FOREIGN KEY (workcenterFk) REFERENCES vn.workCenter(id); diff --git a/db/versions/10704-wheatMastic/00-firstScript.sql b/db/versions/10704-wheatMastic/00-firstScript.sql new file mode 100644 index 000000000..047a50477 --- /dev/null +++ b/db/versions/10704-wheatMastic/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.delivery DROP FOREIGN KEY delivery_ticketFk_FK; +ALTER TABLE vn.delivery ADD CONSTRAINT delivery_ticketFk_FK FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10705-yellowBirch/00-firstScript.sql b/db/versions/10705-yellowBirch/00-firstScript.sql new file mode 100644 index 000000000..ff4b4ff85 --- /dev/null +++ b/db/versions/10705-yellowBirch/00-firstScript.sql @@ -0,0 +1,2 @@ +RENAME TABLE bi.rutasBoard__ TO bi.rutasBoard; +ALTER TABLE bi.rutasBoard ; diff --git a/db/versions/10707-azureFern/00-firstScript.sql b/db/versions/10707-azureFern/00-firstScript.sql new file mode 100644 index 000000000..7b28ed764 --- /dev/null +++ b/db/versions/10707-azureFern/00-firstScript.sql @@ -0,0 +1,5 @@ +CREATE TABLE `vn`.`salesPersonProtected` ( + `salesPersonFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`salesPersonFk`), + CONSTRAINT `salesPersonProtected_FK` FOREIGN KEY (`salesPersonFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de comerciales que no se desasignarán automáticamente los clientes'; \ No newline at end of file diff --git a/db/versions/10708-greenChrysanthemum/00-firstScript.sql b/db/versions/10708-greenChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..e4067f23d --- /dev/null +++ b/db/versions/10708-greenChrysanthemum/00-firstScript.sql @@ -0,0 +1,12 @@ +ALTER TABLE bs.salesByItemTypeDay CHANGE netSale netSale__ int(11) DEFAULT 0 NOT NULL COMMENT '@deprecated 2023-08-31, Mismo valor que campo sale'; + +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN stems int(11) DEFAULT 0 NOT NULL COMMENT 'Número de tallos vendidos'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN `references` int(11) DEFAULT 0 NOT NULL COMMENT 'Número de artículos distintos por tipo vendidos'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN trash int(11) DEFAULT 0 NOT NULL COMMENT 'Tallos basura'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN faults int(11) DEFAULT 0 NOT NULL COMMENT 'Tallos faltas'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN claimed decimal(10, 2) DEFAULT 0 NOT NULL COMMENT 'Valor total de reclamaciones'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN accepted decimal(10, 2) DEFAULT 0 NOT NULL COMMENT 'Valor total de reclamaciones aceptadas'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN sale decimal(10, 2) DEFAULT 0 NOT NULL COMMENT 'Ventas totales'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN buy decimal(10, 2) DEFAULT 0 NOT NULL COMMENT 'Valor de compras totales'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN costComponent decimal(10, 2) DEFAULT 0 NOT NULL COMMENT 'Suma de componentes que son valor de compra'; +ALTER TABLE bs.salesByItemTypeDay MODIFY COLUMN marginComponent decimal(10, 2) DEFAULT 0 NOT NULL COMMENT 'Suma de componentes que son márgen'; \ No newline at end of file diff --git a/db/versions/10712-crimsonCordyline/00-firstScript.sql b/db/versions/10712-crimsonCordyline/00-firstScript.sql new file mode 100644 index 000000000..47cb741fc --- /dev/null +++ b/db/versions/10712-crimsonCordyline/00-firstScript.sql @@ -0,0 +1 @@ +DROP SCHEMA IF EXISTS postgresql; diff --git a/db/versions/10714-azureOak/00-firstScript.sql b/db/versions/10714-azureOak/00-firstScript.sql new file mode 100644 index 000000000..a42ab17d3 --- /dev/null +++ b/db/versions/10714-azureOak/00-firstScript.sql @@ -0,0 +1,25 @@ +USE vn; +UPDATE vn.deviceProduction dp + JOIN ( + SELECT id + FROM deviceProduction dp + WHERE LENGTH(android_id) < 16 + ) sub ON sub.id = dp.id + SET dp.android_id = NULL; +UPDATE vn.deviceProduction dp + JOIN ( + SELECT id + FROM ( + SELECT id, COUNT(*) total, android_id + FROM deviceProduction dp + WHERE android_id IS NOT NULL + GROUP BY android_id + ) sub + WHERE total > 1 + ) sub ON sub.id = dp.id + SET dp.android_id = NULL; +ALTER TABLE vn.deviceLog DROP COLUMN deviceProductionFk; +ALTER TABLE vn.deviceLog MODIFY COLUMN android_id varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; +ALTER TABLE vn.deviceProduction MODIFY COLUMN android_id varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; +ALTER TABLE vn.deviceProduction ADD CONSTRAINT deviceProduction_UN UNIQUE KEY (android_id); +ALTER TABLE vn.deviceProduction ADD CONSTRAINT deviceProduction_CHECK CHECK (android_id REGEXP '[A-Za-z0-9]{16,}' OR android_id IS NULL); diff --git a/db/versions/10716-chocolateCamellia/00-firstScript.sql b/db/versions/10716-chocolateCamellia/00-firstScript.sql new file mode 100644 index 000000000..2b75d7be1 --- /dev/null +++ b/db/versions/10716-chocolateCamellia/00-firstScript.sql @@ -0,0 +1,17 @@ + +CREATE TABLE vn.transitoryDuaUnified ( + id INT auto_increment NOT NULL, + supplierFk INT(10) UNSIGNED NULL, + CONSTRAINT transitoryDuaUnified_PK PRIMARY KEY (id), + CONSTRAINT transitoryDuaUnified_FK FOREIGN KEY (supplierFk) REFERENCES vn.supplier(id) ON DELETE CASCADE ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci +COMMENT='Transitarios que al contabilizar sus entradas sólo generan un único DUA para todos los proveedores'; + + +INSERT INTO vn.transitoryDuaUnified (supplierFk) + SELECT id + FROM vn.supplier + WHERE name = 'VALLINOTO CARGO SA'; diff --git a/db/versions/10717-silverRose/00-firstScript.sql b/db/versions/10717-silverRose/00-firstScript.sql new file mode 100644 index 000000000..73ae80c25 --- /dev/null +++ b/db/versions/10717-silverRose/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.expedition ADD packingSiteFk INT NULL; +ALTER TABLE vn.expedition ADD monitorId varchar(255) NULL; +ALTER TABLE vn.expedition ADD started TIMESTAMP NOT NULL; +ALTER TABLE vn.expedition ADD ended TIMESTAMP NOT NULL; + +ALTER TABLE vn.expedition ADD CONSTRAINT expedition_FK_1 FOREIGN KEY (packingSiteFk) REFERENCES vn.packingSite(id) ON DELETE SET NULL ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10718-orangeRaphis/00-firstScript.sql b/db/versions/10718-orangeRaphis/00-firstScript.sql new file mode 100644 index 000000000..d083fca48 --- /dev/null +++ b/db/versions/10718-orangeRaphis/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.invoiceInConfig ADD taxRowLimit INT DEFAULT 4 NULL + COMMENT 'Número máximo de líneas de IVA que puede tener una factura'; \ No newline at end of file diff --git a/db/versions/10719-orangeMonstera/00-firstScript.sql b/db/versions/10719-orangeMonstera/00-firstScript.sql new file mode 100644 index 000000000..18a859114 --- /dev/null +++ b/db/versions/10719-orangeMonstera/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE pbx.sipConfig + DROP COLUMN avpf, + DROP COLUMN icesupport, + CHANGE careInvite directMedia enum('yes','no') DEFAULT NULL, + ADD `disallow` varchar(100) DEFAULT 'all', + ADD `allow` varchar(100) DEFAULT 'g729;ilbc;gsm;ulaw;alaw'; diff --git a/db/versions/10720-wheatCymbidium/00-firstScript.sql b/db/versions/10720-wheatCymbidium/00-firstScript.sql new file mode 100644 index 000000000..045a2b697 --- /dev/null +++ b/db/versions/10720-wheatCymbidium/00-firstScript.sql @@ -0,0 +1,5 @@ +RENAME TABLE account.mailClientAccess TO account.mailClientAccess__; +RENAME TABLE account.mailSenderAccess TO account.mailSenderAccess__; + +ALTER TABLE account.mailClientAccess__ COMMENT='@deprecated 2023-09-03'; +ALTER TABLE account.mailSenderAccess__ COMMENT='@deprecated 2023-09-03'; diff --git a/db/versions/10721-blueEucalyptus/00-firstScript.sql b/db/versions/10721-blueEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..c14220085 --- /dev/null +++ b/db/versions/10721-blueEucalyptus/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.till MODIFY COLUMN concept varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; +ALTER TABLE vn2008.account_conciliacion MODIFY COLUMN Concepto varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NULL; diff --git a/db/versions/10725-wheatAnthurium/00-firstScript.sql b/db/versions/10725-wheatAnthurium/00-firstScript.sql new file mode 100644 index 000000000..e26ad5197 --- /dev/null +++ b/db/versions/10725-wheatAnthurium/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.worker MODIFY COLUMN bossFk int(10) unsigned DEFAULT 103 NOT NULL; +ALTER TABLE vn.worker ADD CONSTRAINT workerWorker_FK FOREIGN KEY (bossFk) REFERENCES vn.worker(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10726-blackMastic/00-firstScript.sql b/db/versions/10726-blackMastic/00-firstScript.sql new file mode 100644 index 000000000..bb357cf4b --- /dev/null +++ b/db/versions/10726-blackMastic/00-firstScript.sql @@ -0,0 +1,3 @@ + +ALTER TABLE vn.workerTimeControlConfig + ADD maxTimeToBreak INT DEFAULT 3600 NULL; diff --git a/db/versions/10727-limeErica/00-addPrinterField.sql b/db/versions/10727-limeErica/00-addPrinterField.sql new file mode 100644 index 000000000..1502fa418 --- /dev/null +++ b/db/versions/10727-limeErica/00-addPrinterField.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`printer` ADD isRfid TINYINT DEFAULT 0 NOT NULL; diff --git a/db/versions/10727-limeErica/01-createTableScreenModel.sql b/db/versions/10727-limeErica/01-createTableScreenModel.sql new file mode 100644 index 000000000..dd11b6dfa --- /dev/null +++ b/db/versions/10727-limeErica/01-createTableScreenModel.sql @@ -0,0 +1,13 @@ +/** + * Hemos utilizado CREATE OR REPLACE y IF || OR EXISTS + * porque se han subido los cambios a medias a dev y a + * test (en el proceso ha fallado), simplemente para que + * no falle. + */ +CREATE OR REPLACE TABLE `vn`.`screenModel` ( + code VARCHAR(50) NOT NULL, + CONSTRAINT screenModel_UN PRIMARY KEY (code) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10727-limeErica/02-createTableScreen.sql b/db/versions/10727-limeErica/02-createTableScreen.sql new file mode 100644 index 000000000..3358229b4 --- /dev/null +++ b/db/versions/10727-limeErica/02-createTableScreen.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE TABLE `vn`.`screen` ( + id INT(11) AUTO_INCREMENT NOT NULL, + `name` VARCHAR(100) NOT NULL, + modelFk VARCHAR(50) NOT NULL, + CONSTRAINT screen_PK PRIMARY KEY (id), + CONSTRAINT screen_FK FOREIGN KEY (modelFk) REFERENCES vn.screenModel(code) ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10727-limeErica/03-createTableScreenModel.sql b/db/versions/10727-limeErica/03-createTableScreenModel.sql new file mode 100644 index 000000000..3f208a24e --- /dev/null +++ b/db/versions/10727-limeErica/03-createTableScreenModel.sql @@ -0,0 +1,7 @@ +CREATE OR REPLACE TABLE `vn`.`scannerModel` ( + code VARCHAR(50) NOT NULL, + CONSTRAINT scannerModel_UN PRIMARY KEY (code) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10727-limeErica/04-createTableScanner.sql b/db/versions/10727-limeErica/04-createTableScanner.sql new file mode 100644 index 000000000..dee978190 --- /dev/null +++ b/db/versions/10727-limeErica/04-createTableScanner.sql @@ -0,0 +1,10 @@ +CREATE OR REPLACE TABLE `vn`.`scanner` ( + id INT(11) auto_increment NOT NULL, + name varchar(100) NOT NULL, + modelFk VARCHAR(50) NOT NULL, + CONSTRAINT scanner_PK PRIMARY KEY (id), + CONSTRAINT scanner_FK FOREIGN KEY (modelFk) REFERENCES vn.scannerModel(code) ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10727-limeErica/05-createTablePackingSiteDeviceLog.sql b/db/versions/10727-limeErica/05-createTablePackingSiteDeviceLog.sql new file mode 100644 index 000000000..8d7d9456e --- /dev/null +++ b/db/versions/10727-limeErica/05-createTablePackingSiteDeviceLog.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE TABLE `vn`.`packingSiteDeviceLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('PackingSite') NOT NULL DEFAULT 'PackingSite', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `userFk` (`userFk`), + KEY `packingSiteDeviceLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `packingSiteDeviceLog_packingSiteDeviceLog` (`originFk`,`creationDate`), + CONSTRAINT `packingSiteDeviceLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `packingSiteDeviceLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci `PAGE_COMPRESSED`=1; diff --git a/db/versions/10727-limeErica/06-alterTablePrinterModel.sql b/db/versions/10727-limeErica/06-alterTablePrinterModel.sql new file mode 100644 index 000000000..9b28456ef --- /dev/null +++ b/db/versions/10727-limeErica/06-alterTablePrinterModel.sql @@ -0,0 +1,8 @@ +ALTER TABLE vn.printer DROP FOREIGN KEY IF EXISTS printer_FK; +ALTER TABLE vn.packingSiteLog DROP FOREIGN KEY IF EXISTS packingSiteLog_FK_1; + +ALTER TABLE vn.printerModel ADD CONSTRAINT printerModel_PK PRIMARY KEY IF NOT EXISTS (code); +ALTER TABLE vn.printerModel DROP KEY IF EXISTS printerModel_UN; + +ALTER TABLE vn.printer ADD CONSTRAINT printer_FK FOREIGN KEY IF NOT EXISTS (modelFk) REFERENCES vn.printerModel(code) ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE vn.packingSiteLog ADD CONSTRAINT packingSiteLog_FK_1 FOREIGN KEY IF NOT EXISTS (printerModelFk) REFERENCES vn.printerModel(code) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10727-limeErica/07-AddFieldsToPackingSite.sql b/db/versions/10727-limeErica/07-AddFieldsToPackingSite.sql new file mode 100644 index 000000000..958abfd8c --- /dev/null +++ b/db/versions/10727-limeErica/07-AddFieldsToPackingSite.sql @@ -0,0 +1,14 @@ +ALTER TABLE vn.packingSite ADD printerRfidFk TINYINT(3) UNSIGNED DEFAULT NULL NULL UNIQUE AFTER hostFk; +ALTER TABLE vn.packingSite ADD scannerFk INT(11) NULL UNIQUE; +ALTER TABLE vn.packingSite ADD screenFk INT(11) NULL UNIQUE; +ALTER TABLE vn.packingSite ADD editorFk INT(10) UNSIGNED NULL; + +ALTER TABLE vn.packingSite ADD CONSTRAINT packingSite_FK_4 FOREIGN KEY (printerRfidFk) REFERENCES vn.printer(id) ON UPDATE CASCADE; +ALTER TABLE vn.packingSite ADD CONSTRAINT packingSite_FK_5 FOREIGN KEY (scannerFk) REFERENCES vn.scanner(id) ON UPDATE CASCADE; +ALTER TABLE vn.packingSite ADD CONSTRAINT packingSite_FK_6 FOREIGN KEY (screenFk) REFERENCES vn.screen(id) ON UPDATE CASCADE; + +ALTER TABLE vn.packingSite CHANGE collectionFk collectionFk int(11) DEFAULT NULL NULL COMMENT 'Last collection packed on this site'; +ALTER TABLE vn.packingSite ADD CONSTRAINT packingSite_UNI UNIQUE KEY (hostFk); + +UPDATE vn.packingSite SET printerRfidFk = printerFk; +UPDATE vn.packingSite SET printerFk = NULL; diff --git a/db/versions/10730-whiteChrysanthemum/00-firstScript.sql b/db/versions/10730-whiteChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..f537d1871 --- /dev/null +++ b/db/versions/10730-whiteChrysanthemum/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE pbx.sipConfig ADD qualify ENUM('yes','no') NULL DEFAULT NULL; diff --git a/db/versions/10733-azureErica/00-firstScript.sql b/db/versions/10733-azureErica/00-firstScript.sql new file mode 100644 index 000000000..8fdd37d38 --- /dev/null +++ b/db/versions/10733-azureErica/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.productionConfig ADD stockScopeDays INT DEFAULT 1 NULL COMMENT 'Días a futuro al revisar el stock'; diff --git a/db/versions/10736-maroonChico/00-workerBossNull.sql b/db/versions/10736-maroonChico/00-workerBossNull.sql new file mode 100644 index 000000000..3747acf98 --- /dev/null +++ b/db/versions/10736-maroonChico/00-workerBossNull.sql @@ -0,0 +1 @@ +ALTER TABLE vn.worker MODIFY COLUMN bossFk int(10) unsigned NULL DEFAULT 103; diff --git a/db/versions/10739-turquoiseCordyline/00-firstScript.sql b/db/versions/10739-turquoiseCordyline/00-firstScript.sql new file mode 100644 index 000000000..c6ef13e2d --- /dev/null +++ b/db/versions/10739-turquoiseCordyline/00-firstScript.sql @@ -0,0 +1,88 @@ +ALTER TABLE vn.item DROP COLUMN IF EXISTS minQuantity; + +ALTER TABLE vn.item ADD minQuantity INT UNSIGNED DEFAULT NULL NULL + COMMENT 'Cantidad mínima para una línea de venta'; + +INSERT IGNORE INTO hedera.message (code, description) + VALUES ('quantityLessThanMin','The quantity cannot be less than the minimum'); + +INSERT IGNORE INTO hedera.messageI18n (code, lang, description) VALUES + ('quantityLessThanMin','fr','Le montant ne peut être inférieur au montant minimum'), + ('quantityLessThanMin','pt','O montante não pode ser inferior ao montante mínimo'), + ('quantityLessThanMin','es','La cantidad no puedes ser menor a la mínima'); + +UPDATE hedera.message + SET description='Orders for holidays are not possible' + WHERE code='ORDER_DATE_HOLIDAY'; + +UPDATE hedera.message + SET description='The order is empty' + WHERE code='ORDER_EMPTY'; + +UPDATE hedera.message + SET description='Some items are no longer available, please check the quantities highlighted in red' + WHERE code='ORDER_UNAVAILABLE'; + +UPDATE hedera.message + SET description='Only one vote per survey is possible' + WHERE code='SURVEY_MAX_ONE_VOTE'; + +UPDATE hedera.message + SET description='You have exceeded the maximum number of unconfirmed orders, please delete or confirm started orders' + WHERE code='ORDER_MAX_EXCEEDED'; + +UPDATE hedera.message + SET description='Incorrect username or password. Case-sensitive.' + WHERE code='LOGIN_INCORRECT'; + +UPDATE hedera.message + SET description='The order date must be today or later' + WHERE code='ORDER_DATE_PAST'; + +UPDATE hedera.message + SET description='No more orders can be made for today, please postpone your order for tomorrow or later' + WHERE code='ORDER_DATE_LAST'; + +UPDATE hedera.message + SET description='Orders for Sunday cannot be confirmed' + WHERE code='ORDER_DATE_SUNDAY'; + +UPDATE hedera.message + SET description='We are overwhelmed with orders, please select another delivery or pick-up date' + WHERE code='ORDER_DATE_SATURATED'; + +UPDATE hedera.message + SET description='You have been disconnected from the server, please log in again' + WHERE code='USER_DISCONNECTED'; + +UPDATE hedera.message + SET description='Action not allowed' + WHERE code='UNAUTH_ACTION'; + +UPDATE hedera.message + SET description='The shipping agency is not valid' + WHERE code='ORDER_INVALID_AGENCY'; + +UPDATE hedera.message + SET description='Please select a shipping address' + WHERE code='ORDER_EMPTY_ADDRESS'; + +UPDATE hedera.message + SET description='This item is sold in bundles, the quantity has been rounded' + WHERE code='ORDER_AMOUNT_ROUNDED'; + +UPDATE hedera.message + SET description='The order configuration is incorrect, please reconfigure it to continue shopping' + WHERE code='orderOutdated'; + +UPDATE hedera.message + SET description='The order belongs to another user' + WHERE code='orderNotOwnedByUser'; + +UPDATE hedera.message + SET description='The order has already been confirmed and cannot be modified' + WHERE code='orderConfirmed'; + +UPDATE hedera.message + SET description='Incomplete tax data, please contact your sales representative' + WHERE code='clientNotVerified'; \ No newline at end of file diff --git a/db/versions/10740-pinkCataractarum/00-firstScript.sql b/db/versions/10740-pinkCataractarum/00-firstScript.sql new file mode 100644 index 000000000..d46373355 --- /dev/null +++ b/db/versions/10740-pinkCataractarum/00-firstScript.sql @@ -0,0 +1,9 @@ +UPDATE bs.clientDied SET Aviso='first' WHERE Aviso like 'Primer Aviso'; +UPDATE bs.clientDied SET Aviso='second' WHERE Aviso like 'Segundo Aviso'; +UPDATE bs.clientDied SET Aviso='third' WHERE Aviso like 'Tercer Aviso'; + +ALTER TABLE bs.clientDied CHANGE id clientFk int(11) DEFAULT 0 NOT NULL; +ALTER TABLE bs.clientDied CHANGE Aviso warning ENUM('first', 'second','third') CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; +ALTER TABLE bs.clientDied CHANGE workerCode workerCode__ varchar(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT '@deprecated 2023-10-15'; +ALTER TABLE bs.clientDied CHANGE clientName clientName__ varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT '@deprecated 2023-10-15'; +ALTER TABLE bs.clientDied CHANGE Boss Boss__ varchar(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT '@deprecated 2023-10-15'; \ No newline at end of file diff --git a/db/versions/10741-maroonMastic/01-refactorCplusTrascendency472.sql b/db/versions/10741-maroonMastic/01-refactorCplusTrascendency472.sql new file mode 100644 index 000000000..37d0b2c0d --- /dev/null +++ b/db/versions/10741-maroonMastic/01-refactorCplusTrascendency472.sql @@ -0,0 +1,54 @@ +UPDATE vn.cplusTrascendency472 + SET id=13 + WHERE id=11; + +UPDATE vn.cplusTrascendency472 + SET id=14 + WHERE id=12; + +UPDATE vn.cplusTrascendency472 + SET id=12 + WHERE id=10; + +UPDATE vn.cplusTrascendency472 + SET description='Operación de régimen general' + WHERE id=1; +UPDATE vn.cplusTrascendency472 + SET description='Operaciones por las que los empresarios satisfacen compensaciones REAGYP' + WHERE id=2; +UPDATE vn.cplusTrascendency472 + SET description='Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (135 - 139 de LIVA)' + WHERE id=3; +UPDATE vn.cplusTrascendency472 + SET description='Régimen especial oro de inversión' + WHERE id=4; +UPDATE vn.cplusTrascendency472 + SET description='Régimen especial agencias de viajes' + WHERE id=5; +UPDATE vn.cplusTrascendency472 + SET description='Régimen especial grupo de entidades en IVA (Nivel Avanzado)' + WHERE id=6; +UPDATE vn.cplusTrascendency472 + SET description='Régimen especial criterio de caja' + WHERE id=7; +UPDATE vn.cplusTrascendency472 + SET description='Operaciones sujetas al IPSI / IGIC' + WHERE id=8; +UPDATE vn.cplusTrascendency472 + SET description='Adquisiciones intracomunitarias de bienes y prestaciones de servicios' + WHERE id=9; +UPDATE vn.cplusTrascendency472 + SET description='Operaciones de arrendamiento de local de negocio' + WHERE id=12; +UPDATE vn.cplusTrascendency472 + SET description='Factura correspondiente a una importación (informada sin asociar a un DUA)' + WHERE id=13; +UPDATE vn.cplusTrascendency472 + SET description='Primer semestre 2017' + WHERE id=14; + +RENAME TABLE vn.cplusTrascendency472 TO vn.siiTrascendencyInvoiceIn; + ALTER TABLE vn.siiTrascendencyInvoiceIn + COMMENT='Clave de régimen especial o trascendencia en facturas recibidas en el suministro de inmediato'; + +ALTER TABLE vn.invoiceIn CHANGE cplusTrascendency472Fk siiTrascendencyInvoiceInFk int(10) unsigned DEFAULT 1 NULL; diff --git a/db/versions/10741-maroonMastic/02-refactorCplusTrascendency477.sql b/db/versions/10741-maroonMastic/02-refactorCplusTrascendency477.sql new file mode 100644 index 000000000..7a6066677 --- /dev/null +++ b/db/versions/10741-maroonMastic/02-refactorCplusTrascendency477.sql @@ -0,0 +1,55 @@ +RENAME TABLE vn.cplusTrascendency477 TO vn.siiTrascendencyInvoiceOut; + ALTER TABLE vn.siiTrascendencyInvoiceOut + COMMENT='Clave de régimen especial o trascendencia en facturas expedidas del suministro de inmediato'; + +ALTER TABLE vn.pgc CHANGE cplusTrascendency477Fk siiTrascendencyInvoiceOutFk int(10) unsigned DEFAULT 1 NULL; +ALTER TABLE vn.invoiceOut CHANGE cplusTrascendency477Fk siiTrascendencyInvoiceOutFk int(10) unsigned DEFAULT 1 NOT NULL; + +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Operación de régimen general' + WHERE id=1; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Exportación' + WHERE id=2; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (135 - 139 de LIVA)' + WHERE id=3; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Régimen especial oro de inversión' + WHERE id=4; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Régimen especial agencias de viajes' + WHERE id=5; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Régimen especial grupo de entidades en IVA (Nivel Avanzado)' + WHERE id=6; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Régimen especial criterio de caja' + WHERE id=7; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Operaciones sujetas al IPSI / IGIC' + WHERE id=8; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Facturación de las prestaciones de servicios de agencias de viaje que actúan como mediadoras en nombre y por cuenta ajena (D.A.4ª RD 1619/2012)' + WHERE id=9; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Cobros por cuenta de terceros de honorarios profesionales o de Dº derivados de la propiedad industrial, de autor u otros por cuenta de sus socios, asociados,colegiados efectuados por sociedades, asociaciones, colegios profesionales u otras entidades ' + WHERE id=10; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Operaciones de arrendamiento de local de negocio sujetas a retención' + WHERE id=11; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Operaciones de arrendamiento de local de negocio no sujetos a retención' + WHERE id=12; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Operaciones de arrendamiento de local de negocio sujetas y no sujetas a retención' + WHERE id=13; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Factura con IVA pendiente de devengo (certificaciones de obra cuyo destinatario sea una Administración Pública)' + WHERE id=14; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Factura con IVA pendiente de devengo - operaciones de tracto sucesivo' + WHERE id=15; +UPDATE vn.siiTrascendencyInvoiceOut + SET description='Primer semestre 2017' + WHERE id=16; \ No newline at end of file diff --git a/db/versions/10741-maroonMastic/03-refactorCplusInvoiceType477.sql b/db/versions/10741-maroonMastic/03-refactorCplusInvoiceType477.sql new file mode 100644 index 000000000..cc1b958ab --- /dev/null +++ b/db/versions/10741-maroonMastic/03-refactorCplusInvoiceType477.sql @@ -0,0 +1,49 @@ +RENAME TABLE vn.cplusInvoiceType477 TO vn.siiTypeInvoiceOut; + ALTER TABLE vn.siiTypeInvoiceOut + COMMENT='Tipo de Factura Emitidas en el suministro de inmediato'; + +ALTER TABLE vn.invoiceOut CHANGE cplusInvoiceType477Fk siiTypeInvoiceOut int(10) unsigned DEFAULT 1 NOT NULL; + +ALTER TABLE vn.invoiceCorrection CHANGE cplusInvoiceType477Fk siiTypeInvoiceOutFk int(10) unsigned NOT NULL; + +ALTER TABLE vn.siiTypeInvoiceOut ADD code varchar(2) NOT NULL AFTER `id`; + +UPDATE vn.siiTypeInvoiceOut + SET code='F1', + description = 'Factura' + WHERE id=1; +UPDATE vn.siiTypeInvoiceOut + SET code='F2', + description = 'Factura simplificada (ticket)' + WHERE id=2; +UPDATE vn.siiTypeInvoiceOut + SET code='F3', + description = 'Factura emitida en sustitución de facturas simplificadas facturadas y declaradas' + WHERE id=3; +UPDATE vn.siiTypeInvoiceOut + SET code='F4', + description = 'Asiento resumen de facturas' + WHERE id=4; +UPDATE vn.siiTypeInvoiceOut + SET code='R1', + description = 'Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)' + WHERE id=5; +UPDATE vn.siiTypeInvoiceOut + SET code='R2', + description = 'Factura rectificativa (Art. 80.3)' + WHERE id=6; +UPDATE vn.siiTypeInvoiceOut + SET code='R3', + description = 'Factura rectificativa (Art. 80.4)' + WHERE id=7; +UPDATE vn.siiTypeInvoiceOut + SET code='R4', + description = 'Factura rectificativa (Resto)' + WHERE id=8; +UPDATE vn.siiTypeInvoiceOut + SET code='R5', + description = 'Factura rectificativa en facturas simplificadas' + WHERE id=9; + +ALTER TABLE `vn`.`siiTypeInvoiceOut` + ADD UNIQUE INDEX `code_UNIQUE` (`code` ASC) ; \ No newline at end of file diff --git a/db/versions/10741-maroonMastic/04-refactorCplusInvoiceType472.sql b/db/versions/10741-maroonMastic/04-refactorCplusInvoiceType472.sql new file mode 100644 index 000000000..419e58568 --- /dev/null +++ b/db/versions/10741-maroonMastic/04-refactorCplusInvoiceType472.sql @@ -0,0 +1,44 @@ +RENAME TABLE vn.cplusInvoiceType472 TO vn.siiTypeInvoiceIn; +ALTER TABLE vn.siiTypeInvoiceIn +COMMENT='Tipo de Factura Recibidas en el suministro de inmediato'; + +ALTER TABLE vn.invoiceIn CHANGE cplusInvoiceType472Fk siiTypeInvoiceInFk int(10) unsigned DEFAULT 1 NULL; + +ALTER TABLE vn.siiTypeInvoiceIn ADD code varchar(2) NOT NULL AFTER `id`; + +UPDATE vn.siiTypeInvoiceIn + SET code='F1',description='Factura' + WHERE id=1; +UPDATE vn.siiTypeInvoiceIn + SET code='F2',description='Factura simplificada (ticket)' + WHERE id=2; +UPDATE vn.siiTypeInvoiceIn + SET code='F3',description='Factura emitida en sustitución de facturas simplificadas facturadas y declaradas' + WHERE id=3; +UPDATE vn.siiTypeInvoiceIn + SET code='F4',description='Asiento resumen de facturas' + WHERE id=4; +UPDATE vn.siiTypeInvoiceIn + SET code='F5',description='Importaciones (DUA)' + WHERE id=5; +UPDATE vn.siiTypeInvoiceIn + SET code='F6',description='Otros justificantes contables' + WHERE id=6; +UPDATE vn.siiTypeInvoiceIn + SET code='R1',description='Factura rectificativa (Art. 80.1, 80.2 y error fundado en derecho)' + WHERE id=7; +UPDATE vn.siiTypeInvoiceIn + SET code='R2',description='Factura rectificativa (Art. 80.3)' + WHERE id=8; +UPDATE vn.siiTypeInvoiceIn + SET code='R3',description='Factura rectificativa (Art. 80.4)' + WHERE id=9; +UPDATE vn.siiTypeInvoiceIn + SET code='R4',description='Factura rectificativa (Resto)' + WHERE id=10; +UPDATE vn.siiTypeInvoiceIn + SET code='R5',description='Factura rectificativa en facturas simplificadas' + WHERE id=11; + +ALTER TABLE `vn`.`siiTypeInvoiceIn` + ADD UNIQUE INDEX `code_UNIQUE` (`code` ASC) ; \ No newline at end of file diff --git a/db/versions/10741-maroonMastic/05-fixes.sql b/db/versions/10741-maroonMastic/05-fixes.sql new file mode 100644 index 000000000..8a42e3365 --- /dev/null +++ b/db/versions/10741-maroonMastic/05-fixes.sql @@ -0,0 +1 @@ +ALTER TABLE vn.invoiceOut CHANGE siiTypeInvoiceOut siiTypeInvoiceOutFk int(10) unsigned DEFAULT 1 NOT NULL; \ No newline at end of file diff --git a/db/versions/10744-aquaBirch/00-firstScript.sql b/db/versions/10744-aquaBirch/00-firstScript.sql new file mode 100644 index 000000000..a4f6c32ad --- /dev/null +++ b/db/versions/10744-aquaBirch/00-firstScript.sql @@ -0,0 +1,9 @@ +UPDATE vn.shelving +SET isPrinted = TRUE + WHERE LEFT (code, 2) IN ( + SELECT DISTINCT LEFT(code,2) + FROM vn.shelving + WHERE isPrinted + AND code REGEXP '^[A-Za-z]{2}[0-9]' + ORDER BY code) + AND code REGEXP '^[A-Za-z]{2}[0-9]' \ No newline at end of file diff --git a/db/versions/10746-aquaMastic/00-firstScript.sql b/db/versions/10746-aquaMastic/00-firstScript.sql new file mode 100644 index 000000000..87fdd140d --- /dev/null +++ b/db/versions/10746-aquaMastic/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn.salespersonConfig ADD manaDateFrom DATE DEFAULT '2023-01-01' NOT NULL COMMENT 'first date to count mana'; +ALTER TABLE vn.salespersonConfig ADD manaFromDays INT DEFAULT 90 NOT NULL COMMENT 'Range of days from mana calculation'; +ALTER TABLE vn.salespersonConfig ADD manaToDays INT DEFAULT 30 NOT NULL COMMENT 'Range of days to mana calculation'; diff --git a/db/versions/10747-brownRaphis/00-firstScript.sql b/db/versions/10747-brownRaphis/00-firstScript.sql new file mode 100644 index 000000000..517cbddd8 --- /dev/null +++ b/db/versions/10747-brownRaphis/00-firstScript.sql @@ -0,0 +1,13 @@ +ALTER TABLE bi.rutasBoard CHANGE km km__ varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE Dia Dia__ varchar(9) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE Terceros Terceros__ int(11) DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE Matricula Matricula__ varchar(10) DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE Tipo Tipo__ varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE `year` year__ int(4) DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE `month` month__ int(2) DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE warehouse_id warehouse_id__ smallint(5) unsigned DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE coste_bulto coste_bulto__ decimal(10,2) unsigned DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; +ALTER TABLE bi.rutasBoard CHANGE m3 m3__ decimal(10,1) unsigned DEFAULT NULL NULL COMMENT '@deprecated 2023-11-01, refs #6087'; + +ALTER TABLE bi.rutasBoard +COMMENT='Se usa en https://grafana.verdnatura.es/d/c089276b-5ab5-430f-aa76-e5d8e0e7fe2e/analisis-de-volumen-y-rendimiento-por-agencia?orgId=1'; diff --git a/db/versions/10748-navyRose/00-firstScript.sql b/db/versions/10748-navyRose/00-firstScript.sql new file mode 100644 index 000000000..6f6e081d4 --- /dev/null +++ b/db/versions/10748-navyRose/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.cmr CHANGE ticketFk `ticketFk__` int(11) DEFAULT NULL NULL COMMENT '@deprecated 2023-10-20 refs #6092'; +ALTER TABLE vn.cmr MODIFY COLUMN `ticketFk__` int(11) DEFAULT NULL NULL COMMENT '@deprecated 2023-10-20 refs #6092'; diff --git a/db/versions/10748-navyRose/01-SecondScript.sql b/db/versions/10748-navyRose/01-SecondScript.sql new file mode 100644 index 000000000..d3ae6fee3 --- /dev/null +++ b/db/versions/10748-navyRose/01-SecondScript.sql @@ -0,0 +1,7 @@ +UPDATE vn.ticket t + JOIN ( + SELECT id, ticketFk__ + FROM vn.cmr + WHERE ticketFk__ + ) sub ON sub.ticketFk__ = t.id + SET cmrFk = sub.id; diff --git a/db/versions/10749-chocolateEucalyptus/00-firstScript.sql b/db/versions/10749-chocolateEucalyptus/00-firstScript.sql new file mode 100644 index 000000000..17f518a52 --- /dev/null +++ b/db/versions/10749-chocolateEucalyptus/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.shelving ADD isMoving BOOL NULL; diff --git a/db/versions/10750-limeAsparagus/00-firstScript.sql b/db/versions/10750-limeAsparagus/00-firstScript.sql new file mode 100644 index 000000000..21410f5f8 --- /dev/null +++ b/db/versions/10750-limeAsparagus/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX ticket_created_IDX USING BTREE ON vn.ticket (created); diff --git a/db/versions/10750-wheatGalax/00-ticket_addGrants.sql b/db/versions/10750-wheatGalax/00-ticket_addGrants.sql new file mode 100644 index 000000000..c318b7df6 --- /dev/null +++ b/db/versions/10750-wheatGalax/00-ticket_addGrants.sql @@ -0,0 +1,3 @@ +REVOKE EXECUTE ON PROCEDURE `vn`.`ticket_add` FROM `employee`; +REVOKE EXECUTE ON PROCEDURE `vn`.`ticket_add` FROM `administrative`; +GRANT EXECUTE ON PROCEDURE `vn`.`ticket_add` TO `developer`; diff --git a/db/versions/10751-silverArborvitae/00-firstScript.sql b/db/versions/10751-silverArborvitae/00-firstScript.sql new file mode 100644 index 000000000..49a680964 --- /dev/null +++ b/db/versions/10751-silverArborvitae/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.routeConfig DROP COLUMN kmRate; +ALTER TABLE vn.routeConfig DROP COLUMN kmTruckRate; + diff --git a/db/versions/10752-crimsonChrysanthemum/00-firstScript.sql b/db/versions/10752-crimsonChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..751daa20e --- /dev/null +++ b/db/versions/10752-crimsonChrysanthemum/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX client_isTaxDataChecked_IDX USING BTREE ON vn.client (isTaxDataChecked); diff --git a/db/versions/10753-blueDracena/00-firstScript.sql b/db/versions/10753-blueDracena/00-firstScript.sql new file mode 100644 index 000000000..375dfbee9 --- /dev/null +++ b/db/versions/10753-blueDracena/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticket DROP INDEX ticket_created_IDX; diff --git a/db/versions/10754-purpleMonstera/00-firstScript.sql b/db/versions/10754-purpleMonstera/00-firstScript.sql new file mode 100644 index 000000000..01d466ad3 --- /dev/null +++ b/db/versions/10754-purpleMonstera/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.sector DROP FOREIGN KEY sector_FK; +ALTER TABLE vn.sector DROP PRIMARY KEY, ADD PRIMARY KEY (id); diff --git a/db/versions/10755-redGalax/00-firstScript.sql b/db/versions/10755-redGalax/00-firstScript.sql new file mode 100644 index 000000000..11633e845 --- /dev/null +++ b/db/versions/10755-redGalax/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX tpvTransaction_status_IDX USING BTREE ON hedera.tpvTransaction (status,receiptFk); diff --git a/db/versions/10756-wheatRoebelini/00-firstScript.sql b/db/versions/10756-wheatRoebelini/00-firstScript.sql new file mode 100644 index 000000000..5886863e2 --- /dev/null +++ b/db/versions/10756-wheatRoebelini/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX sale_created_IDX USING BTREE ON vn.sale (created); diff --git a/db/versions/10757-silverChrysanthemum/00-firstScript.sql b/db/versions/10757-silverChrysanthemum/00-firstScript.sql new file mode 100644 index 000000000..ee64b83e1 --- /dev/null +++ b/db/versions/10757-silverChrysanthemum/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.ticketTracking MODIFY COLUMN workerFk int(10) unsigned DEFAULT NULL NULL; +ALTER TABLE vn.ticketTracking ADD CONSTRAINT ticketTracking_FK3 FOREIGN KEY (workerFk) +REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10758-boxPicking/00-sectorType.sql b/db/versions/10758-boxPicking/00-sectorType.sql new file mode 100644 index 000000000..464752a62 --- /dev/null +++ b/db/versions/10758-boxPicking/00-sectorType.sql @@ -0,0 +1,33 @@ +USE vn; + +ALTER TABLE vn.sector DROP FOREIGN KEY IF EXISTS sectorType_FK; + +CREATE OR REPLACE TABLE vn.sectorType ( + id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT, + description VARCHAR(100) NOT NULL +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO sectorType (id, `description`) + VALUES (1, 'normalPicking'); +INSERT IGNORE INTO sectorType (id, `description`) + VALUES (2, 'previousByPacking'); +INSERT IGNORE INTO sectorType (id, `description`) + VALUES (3, 'boxPicking'); +INSERT IGNORE INTO sectorType (id, `description`) + VALUES (4, 'previousPrepared'); + +ALTER TABLE sector ADD IF NOT EXISTS typeFk INT(10) UNSIGNED DEFAULT 1 NOT NULL; + +UPDATE sector s + SET typeFk = (SELECT id FROM sectorType WHERE `description` = 'previousByPacking') + WHERE s.isPreviousPreparedByPacking; + +UPDATE sector s + SET typeFk = (SELECT id FROM sectorType WHERE `description` = 'previousPrepared') + WHERE s.isPreviousPrepared; + +ALTER TABLE vn.sector ADD CONSTRAINT sectorType_FK FOREIGN KEY IF NOT EXISTS (typeFk) + REFERENCES vn.sectorType(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/db/versions/10758-boxPicking/01-dipole.sql b/db/versions/10758-boxPicking/01-dipole.sql new file mode 100644 index 000000000..05c4542bb --- /dev/null +++ b/db/versions/10758-boxPicking/01-dipole.sql @@ -0,0 +1,5 @@ +ALTER TABLE dipole.expedition_PrintOut ADD itemFk INT NULL; +ALTER TABLE dipole.expedition_PrintOut ADD quantity int NULL; +ALTER TABLE dipole.expedition_PrintOut ADD longName varchar(30) NULL; +ALTER TABLE dipole.expedition_PrintOut ADD shelvingFk varchar(5) NULL; +ALTER TABLE dipole.expedition_PrintOut ADD comments varchar(100) NULL; diff --git a/db/versions/10761-greenGalax/00-firstScript.sql b/db/versions/10761-greenGalax/00-firstScript.sql new file mode 100644 index 000000000..5540a9b71 --- /dev/null +++ b/db/versions/10761-greenGalax/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +ALTER TABLE vn2008.albaran ADD IF NOT EXISTS farmingFk int(10) unsigned NULL; +ALTER TABLE vn2008.albaran DROP FOREIGN KEY IF EXISTS albaran_FK; +ALTER TABLE vn2008.albaran ADD CONSTRAINT albaran_FK FOREIGN KEY (farmingFk) REFERENCES vn.farming(id); diff --git a/db/versions/10768-blueRose/00-firstScript.sql b/db/versions/10768-blueRose/00-firstScript.sql new file mode 100644 index 000000000..6746b4448 --- /dev/null +++ b/db/versions/10768-blueRose/00-firstScript.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`time_generate`() +BEGIN + +END$$ +DELIMITER ; + +GRANT EXECUTE ON PROCEDURE util.time_generate TO guest; diff --git a/db/versions/10771-bronzeLaurel/00-firstScript.sql b/db/versions/10771-bronzeLaurel/00-firstScript.sql new file mode 100644 index 000000000..877407de5 --- /dev/null +++ b/db/versions/10771-bronzeLaurel/00-firstScript.sql @@ -0,0 +1,14 @@ + +UPDATE vn.client c + JOIN ( + SELECT c.id, COUNT(DISTINCT co.id) > 1 hasDifferentCountries + FROM vn.client c + JOIN vn.`address` a ON a.clientFk = c.id + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.country co ON co.id = p.countryFk + WHERE NOT c.hasToInvoiceByAddress + AND a.isActive + GROUP BY a.clientFk + HAVING hasDifferentCountries + )sub ON sub.id = c.id + SET c.hasToInvoiceByAddress = TRUE; \ No newline at end of file diff --git a/db/versions/10773-maroonBamboo/00-firstScript.sql b/db/versions/10773-maroonBamboo/00-firstScript.sql new file mode 100644 index 000000000..026f89ad1 --- /dev/null +++ b/db/versions/10773-maroonBamboo/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE dipole.expedition_PrintOut MODIFY COLUMN province varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/10775-chocolateOrchid/00-firstScript.sql b/db/versions/10775-chocolateOrchid/00-firstScript.sql new file mode 100644 index 000000000..61d92d400 --- /dev/null +++ b/db/versions/10775-chocolateOrchid/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.clientProtected DROP FOREIGN KEY clientProtected_fk2; +ALTER TABLE vn.clientProtected DROP COLUMN workerFk; \ No newline at end of file diff --git a/db/versions/10778-goldenSalal/00-firstScript.sql b/db/versions/10778-goldenSalal/00-firstScript.sql new file mode 100644 index 000000000..7ce9e2ea5 --- /dev/null +++ b/db/versions/10778-goldenSalal/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.routesMonitor ADD CONSTRAINT routesMonitor_FK_3 FOREIGN KEY (expeditionTruckFk) REFERENCES vn.expeditionTruck(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10782-salmonErica/00-firstScript.sql b/db/versions/10782-salmonErica/00-firstScript.sql new file mode 100644 index 000000000..b2ee19780 --- /dev/null +++ b/db/versions/10782-salmonErica/00-firstScript.sql @@ -0,0 +1,10 @@ +CREATE TABLE vn.`agencyModePricePercentage` ( + `agencyModeFk` int(11) NOT NULL, + `percentage` double NOT NULL, + PRIMARY KEY (`agencyModeFk`), + CONSTRAINT `agencyModePricePercentage_FK` + FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10783-silverGalax/00-firstScript.sql b/db/versions/10783-silverGalax/00-firstScript.sql new file mode 100644 index 000000000..fb7e26224 --- /dev/null +++ b/db/versions/10783-silverGalax/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.`zone` MODIFY COLUMN price double DEFAULT 0 NOT NULL CHECK(price>0); diff --git a/db/versions/10785-grayCyca/00-firstScript.sql b/db/versions/10785-grayCyca/00-firstScript.sql new file mode 100644 index 000000000..3f0ec701f --- /dev/null +++ b/db/versions/10785-grayCyca/00-firstScript.sql @@ -0,0 +1,9 @@ +/* +RENAME TABLE vn.expence TO vn.expense; +RENAME TABLE vn.invoiceOutExpence TO vn.invoiceOutExpense; +ALTER TABLE vn.invoiceOutExpense CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; +ALTER TABLE vn.ticketServiceType CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '7050000000' NOT NULL; +ALTER TABLE vn.invoiceOutTaxConfig CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; +ALTER TABLE vn.invoiceInSage CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; +ALTER TABLE vn.agencyTermConfig CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; +*/ diff --git a/db/versions/10785-grayCyca/02-invoiceIn.sql b/db/versions/10785-grayCyca/02-invoiceIn.sql new file mode 100644 index 000000000..f9b4fe9eb --- /dev/null +++ b/db/versions/10785-grayCyca/02-invoiceIn.sql @@ -0,0 +1 @@ +ALTER TABLE vn.invoiceIn CHANGE expenceFkDeductible expenseFkDeductible varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL NULL; diff --git a/db/versions/10785-grayCyca/02-invoiceInTax.sql b/db/versions/10785-grayCyca/02-invoiceInTax.sql new file mode 100644 index 000000000..a284ba282 --- /dev/null +++ b/db/versions/10785-grayCyca/02-invoiceInTax.sql @@ -0,0 +1 @@ +ALTER TABLE vn.invoiceInTax CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL; diff --git a/db/versions/10785-grayCyca/02-item.sql b/db/versions/10785-grayCyca/02-item.sql new file mode 100644 index 000000000..407b75fc5 --- /dev/null +++ b/db/versions/10785-grayCyca/02-item.sql @@ -0,0 +1 @@ +ALTER TABLE vn.item CHANGE expenceFk expenseFk varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '7001000000' NOT NULL; diff --git a/db/versions/10789-whiteSalal/00-firstScript.sql b/db/versions/10789-whiteSalal/00-firstScript.sql new file mode 100644 index 000000000..0a2bafaa1 --- /dev/null +++ b/db/versions/10789-whiteSalal/00-firstScript.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here + +ALTER TABLE vn.productionConfig ADD clientSelfConsumptionFk int(11) NULL COMMENT 'Cliente para crear el ticket de autoconsumo'; +ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_FK_1 FOREIGN KEY (clientSelfConsumptionFk) REFERENCES vn.client(id) ON DELETE CASCADE ON UPDATE CASCADE; + diff --git a/db/versions/10789-whiteSalal/00-firstScript.vn.sql b/db/versions/10789-whiteSalal/00-firstScript.vn.sql new file mode 100644 index 000000000..61324de57 --- /dev/null +++ b/db/versions/10789-whiteSalal/00-firstScript.vn.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here + +UPDATE vn.productionConfig + SET clientSelfConsumptionFk=450 + WHERE id=1; diff --git a/db/versions/10792-crimsonMoss/00-buy.sql b/db/versions/10792-crimsonMoss/00-buy.sql new file mode 100644 index 000000000..9c8bfb44a --- /dev/null +++ b/db/versions/10792-crimsonMoss/00-buy.sql @@ -0,0 +1 @@ +ALTER TABLE vn.buy MODIFY COLUMN buyingValue decimal(10,4) DEFAULT 0.0000 NOT NULL; diff --git a/db/versions/10798-grayLaurel/00-firstScript.sql b/db/versions/10798-grayLaurel/00-firstScript.sql new file mode 100644 index 000000000..afdcc74d4 --- /dev/null +++ b/db/versions/10798-grayLaurel/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE `vn`.`routesMonitor` + ADD IF NOT EXISTS editorFk INT UNSIGNED NULL, + ADD CONSTRAINT routesMonitor_fk_editor FOREIGN KEY IF NOT EXISTS (editorFk) REFERENCES account.`user`(id); +ALTER TABLE vn.routeLog + MODIFY COLUMN changedModel enum('Route', 'RoutesMonitor') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Route' NOT NULL; diff --git a/db/versions/10799-limePalmetto/00-firstScript.sql b/db/versions/10799-limePalmetto/00-firstScript.sql new file mode 100644 index 000000000..690c0fc4f --- /dev/null +++ b/db/versions/10799-limePalmetto/00-firstScript.sql @@ -0,0 +1,27 @@ +ALTER TABLE vn.routeCommission DROP FOREIGN KEY IF EXISTS routeCommission_firstEditorFk; +ALTER TABLE vn.routeCommission DROP COLUMN IF EXISTS firstEditorFk; + +ALTER TABLE vn.route DROP FOREIGN KEY IF EXISTS route_firstEditorFk; +ALTER TABLE vn.route DROP COLUMN IF EXISTS firstEditorFk; + +ALTER TABLE vn.route + ADD firstEditorFk INTEGER UNSIGNED NOT NULL + COMMENT 'Usuario creador de la ruta' AFTER workerFk; + +ALTER TABLE vn.routeCommission + ADD firstEditorFk INTEGER UNSIGNED NOT NULL + COMMENT 'Usuario creador de la ruta' AFTER workCenterFk; + + +UPDATE vn.routeCommission rc + JOIN vn.routeLog rl ON rl.originFk = rc.routeFk + SET rc.firstEditorFk = rl.userFk + WHERE rl.`action` = 'insert'; + +UPDATE vn.routeCommission rc + SET firstEditorFk = 4365 + WHERE routeFk = 125360; + +ALTER TABLE vn.routeCommission + ADD CONSTRAINT routeCommission_firstEditorFk FOREIGN KEY (firstEditorFk) + REFERENCES account.user(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10800-yellowSalal/00-firstScript.sql b/db/versions/10800-yellowSalal/00-firstScript.sql new file mode 100644 index 000000000..07b6084b2 --- /dev/null +++ b/db/versions/10800-yellowSalal/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.operator ADD CONSTRAINT operator_FK_4 + FOREIGN KEY (sectorFk) REFERENCES vn.sector(id) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/db/versions/10801-redRoebelini/00-firstScript.sql b/db/versions/10801-redRoebelini/00-firstScript.sql new file mode 100644 index 000000000..ad828b3d3 --- /dev/null +++ b/db/versions/10801-redRoebelini/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.sector + DROP COLUMN isPreviousPrepared, + DROP COLUMN isPreviousPreparedByPacking; diff --git a/db/versions/10806-limeRose/00-firstScript.sql b/db/versions/10806-limeRose/00-firstScript.sql new file mode 100644 index 000000000..0e2085fe8 --- /dev/null +++ b/db/versions/10806-limeRose/00-firstScript.sql @@ -0,0 +1,3 @@ + +ALTER TABLE vn.routeCommission + DROP FOREIGN KEY routeCommission_firstEditorFk; diff --git a/myt.config.yml b/myt.config.yml new file mode 100755 index 000000000..56ab7818a --- /dev/null +++ b/myt.config.yml @@ -0,0 +1,401 @@ +code: vn-database +versionSchema: util +replace: true +sumViews: false +mockDate: '2001-01-01 12:00:00' +subdir: db +schemas: + - account + - bi + - bs + - cache + - dipole + - edi + - hedera + - pbx + - psico + - rfid + - sage + - salix + - srt + - stock + - tmp + - util + - vn + - vn2008 +privileges: + where: >- + `Host` = '' + AND `User` NOT LIKE '$%' + AND `User` <> 'any' +fixtures: + util: + - version + - versionLog + account: + - role + - roleInherit + - userPassword + - accountConfig + - mailConfig + salix: + - ACL + - fieldAcl + - module + - defaultViewConfig + vn: + - agencyTermConfig + - alertLevel + - bookingPlanner + - businessType + - companyI18n + - cplusRectificationType + - cplusSubjectOp + - cplusTaxBreak + - claimResponsible + - claimReason + - claimRedelivery + - claimResult + - component + - componentType + - continent + - department + - docuware + - itemPackingType + - pgc + - sample + - siiTrascendencyInvoiceIn + - siiTypeInvoiceIn + - siiTypeInvoiceOut + - silexACL + - state + - ticketUpdateAction + - volumeConfig + - workCenter + - workerBusinessAgreement + cache: + - cache + hedera: + - browser + - imageCollection + - imageCollectionSize + - language + - link + - location + - menu + - message + - metatag + - newsTag + - restPriv + - social + - tpvError + - tpvResponse + sage: + - TiposIva + - TiposTransacciones + - TiposRetencion + - taxType +localFixtures: + account: + - account + - mailAlias + - mailAliasAccount + - mailForward + - roleConfig + - user + - userConfig + bs: + - clientAnnualConsumption + - clientNewBorn + - defaulter + - sale + - waste + cache: + - cache_calc + hedera: + - config + - image + - imageConfig + - news + - order + - orderConfig + - orderRow + - orderRowComponent + - tpvConfig + - tpvMerchant + - tpvMerchantEnable + - tpvTransaction + - userSession + - visit + - visitAccess + - visitAgent + - visitUser + pbx: + - sip + salix: + - AccessToken + - accessTokenConfig + - printConfig + - url + util: + - config + - notification + - notificationAcl + - notificationConfig + - notificationQueue + - notificationSubscription + vn: + - absenceType + - accounting + - accountingConfig + - accountingType + - address + - addressObservation + - agency + - agencyMode + - autonomy + - awb + - bankEntity + - beach + - bionicConfig + - business + - businessReasonEnd + - buy + - buyConfig + - calendar + - calendarHolidays + - calendarHolidaysName + - calendarHolidaysType + - calendarType + - campaign + - chat + - chatConfig + - claim + - claimBeginning + - claimConfig + - claimDestination + - claimDevelopment + - claimDms + - claimEnd + - claimLog + - claimObservation + - claimRatio + - claimRma + - claimState + - client + - clientConfig + - clientContact + - clientCredit + - roleCreditLimit + - clientDms + - clientManaCache + - clientObservation + - clientRisk + - clientSample + - clientType + - cmr + - cmrConfig + - collection + - collectionColors + - company + - companyGroup + - config + - contactChannel + - country + - cplusTerIdNif + - creditClassification + - creditInsurance + - currency + - customsAgent + - deliveryMethod + - deliveryPoint + - device + - deviceProduction + - deviceProductionModels + - deviceProductionState + - deviceProductionUser + - disabilityGrade + - dms + - dmsType + - docuwareConfig + - dua + - duaInvoiceIn + - educationLevel + - entry + - entryConfig + - expedition + - expeditionBoxVol + - expeditionPallet + - expeditionScan + - expeditionState + - expeditionStateType + - expeditionTruck + - expense + - genus + - greuge + - greugeConfig + - greugeType + - host + - incoterms + - ink + - intrastat + - invoiceIn + - invoiceInConfig + - invoiceInDueDay + - invoiceInIntrastat + - invoiceInSerial + - invoiceInTax + - invoiceOut + - invoiceOutConfig + - invoiceOutExpense + - invoiceOutSerial + - invoiceOutTax + - item + - itemBarcode + - itemBotanical + - itemCategory + - itemConfig + - itemCost + - itemFamily + - itemLog + - itemShelving + - itemShelvingLog + - itemShelvingSale + - itemTag + - itemTaxCountry + - itemType + - itemTypeTag + - machine + - machineWorker + - mail + - mandate + - mandateType + - mdbApp + - mdbBranch + - mdbVersion + - medicalCenter + - mobileAppVersionControl + - observationType + - occupationCode + - operator + - orderTicket + - origin + - osTicketConfig + - packaging + - packagingConfig + - packingSite + - packingSiteConfig + - parking + - payDem + - payDemDetail + - payMethod + - payrollCategories + - postCode + - priceFixed + - printer + - producer + - productionConfig + - professionalCategory + - profileType + - province + - queuePriority + - rate + - rateConfig + - receipt + - recovery + - report + - roadmap + - route + - routeConfig + - routeRecalc + - routesMonitor + - sale + - saleCloned + - saleComponent + - saleGroup + - saleGroupDetail + - saleTracking + - sector + - sectorCollection + - sectorCollectionSaleGroup + - sharingCart + - sharingCartDaily + - sharingClient + - shelving + - smsConfig + - specie + - supplier + - supplierAccount + - supplierActivity + - supplierAddress + - supplierAgencyTerm + - supplierContact + - tablet + - tabletDepartment + - tag + - taxArea + - taxClass + - taxClassCode + - taxCode + - taxType + - temperature + - thermograph + - ticket + - ticketCollection + - ticketConfig + - ticketDms + - ticketLastState + - ticketLog + - ticketObservation + - ticketPackaging + - ticketRecalc + - ticketRefund + - ticketRequest + - ticketService + - ticketServiceType + - ticketTracking + - ticketWeekly + - town + - train + - trainingCenter + - trainingCourseType + - travel + - travelConfig + - travelRecalc + - travelThermograph + - userConfig + - vehicle + - wagonConfig + - wagonType + - wagonTypeColor + - wagonTypeTray + - warehouse + - warehouseAlias + - workCenterHoliday + - worker + - workerBosses + - workerBusinessType + - workerConfig + - workerDocument + - workerLog + - workerMana + - workerManaExcluded + - workerTeam + - workerTimeControl + - workerTimeControlConfig + - workerTimeControlMail + - workerTimeControlParams + - zone + - zoneAgencyMode + - zoneClosure + - zoneConfig + - zoneEvent + - zoneExclusion + - zoneExclusionGeo + - zoneGeo + - zoneIncluded + - zoneWarehouse + vn2008: + - payroll_employee + - Splits + - zones diff --git a/package-lock.json b/package-lock.json index 36e11dc8f..1316a2cc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", + "@verdnatura/myt": "^1.5.23", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3076,6 +3077,12 @@ "url": "https://github.com/sindresorhus/is?sponsor=1" } }, + "node_modules/@sqltools/formatter": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.5.tgz", + "integrity": "sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw==", + "dev": true + }, "node_modules/@szmarczak/http-timer": { "version": "4.0.6", "integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==", @@ -3367,6 +3374,150 @@ "@types/node": "*" } }, + "node_modules/@verdnatura/myt": { + "version": "1.5.23", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.23.tgz", + "integrity": "sha512-gqMLcnFgAW0pqekEkWa069ySBWI+j5Q3Mtll7IIaBCl8OSUWqC6/EMuGg/2X2i9RjhMuCHzOnz+yMKrBE4vX/w==", + "dev": true, + "dependencies": { + "@sqltools/formatter": "^1.2.5", + "colors": "^1.4.0", + "ejs": "^3.1.9", + "fs-extra": "^11.1.1", + "getopts": "^2.3.0", + "ini": "^4.1.1", + "mysql2": "^3.3.4", + "nodegit": "^0.27.0", + "require-yaml": "^0.0.1", + "sha.js": "^2.4.11" + }, + "bin": { + "myt": "cli.js" + } + }, + "node_modules/@verdnatura/myt/node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "dev": true, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/@verdnatura/myt/node_modules/ejs": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", + "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "dev": true, + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@verdnatura/myt/node_modules/fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, + "node_modules/@verdnatura/myt/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@verdnatura/myt/node_modules/ini": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.1.tgz", + "integrity": "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/@verdnatura/myt/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/@verdnatura/myt/node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "dev": true + }, + "node_modules/@verdnatura/myt/node_modules/lru-cache": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", + "dev": true, + "engines": { + "node": ">=16.14" + } + }, + "node_modules/@verdnatura/myt/node_modules/mysql2": { + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.5.tgz", + "integrity": "sha512-pS/KqIb0xlXmtmqEuTvBXTmLoQ5LmAz5NW/r8UyQ1ldvnprNEj3P9GbmuQQ2J0A4LO+ynotGi6TbscPa8OUb+w==", + "dev": true, + "dependencies": { + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru-cache": "^8.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/@verdnatura/myt/node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/@verdnatura/myt/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", @@ -4960,6 +5111,22 @@ "isarray": "^1.0.0" } }, + "node_modules/buffer-alloc": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", + "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", + "dev": true, + "dependencies": { + "buffer-alloc-unsafe": "^1.1.0", + "buffer-fill": "^1.0.0" + } + }, + "node_modules/buffer-alloc-unsafe": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", + "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==", + "dev": true + }, "node_modules/buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -4980,6 +5147,12 @@ "version": "1.0.1", "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" }, + "node_modules/buffer-fill": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", + "integrity": "sha512-T7zexNBwiiaCOGDg9xNX9PBmjrubblRkENuptryuI64URkXDFum9il/JGL8Lm8wYfAXpredVXXZz7eMHilimiQ==", + "dev": true + }, "node_modules/buffer-from": { "version": "1.1.2", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" @@ -8511,10 +8684,30 @@ } }, "node_modules/filelist": { - "version": "1.0.2", - "integrity": "sha512-z7O0IS8Plc39rTCq6i6iHxk43duYOn8uFJiWSewIq0Bww1RNybVHSCjahmcC87ZqAm4OTvFzlzeGu3XAzG1ctQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", "dependencies": { - "minimatch": "^3.0.4" + "minimatch": "^5.0.1" + } + }, + "node_modules/filelist/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/filelist/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" } }, "node_modules/fill-range": { @@ -9329,6 +9522,12 @@ "node": ">=0.10.0" } }, + "node_modules/getopts": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/getopts/-/getopts-2.3.0.tgz", + "integrity": "sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==", + "dev": true + }, "node_modules/getpass": { "version": "0.1.7", "integrity": "sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==", @@ -11786,6 +11985,15 @@ "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", "dev": true }, + "node_modules/ignore-walk": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.4.tgz", + "integrity": "sha512-PY6Ii8o1jMRA1z4F2hRkH/xN59ox43DavKvD3oDpfurRlOJyAHpifIwpbdv1n4jt4ov0jSpw3kQ4GhJnpBL6WQ==", + "dev": true, + "dependencies": { + "minimatch": "^3.0.4" + } + }, "node_modules/image-type": { "version": "4.1.0", "integrity": "sha512-CFJMJ8QK8lJvRlTCEgarL4ro6hfDQKif2HjSvYCdQZESaIPV4v9imrf7BQHK+sQeTeNeMpWciR9hyC/g8ybXEg==", @@ -12594,13 +12802,14 @@ } }, "node_modules/jake": { - "version": "10.8.4", - "integrity": "sha512-MtWeTkl1qGsWUtbl/Jsca/8xSoK3x0UmS82sNbjqxxG/de/M/3b1DntdjHgPMC50enlTNwXOCRqPXLLt5cCfZA==", + "version": "10.8.7", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.7.tgz", + "integrity": "sha512-ZDi3aP+fG/LchyBzUM804VjddnwfSfsdeYkwt8NcbKRvo4rFkjhs456iLFn3k2ZUWvNe4i48WACDbza8fhq2+w==", "dependencies": { - "async": "0.9.x", + "async": "^3.2.3", "chalk": "^4.0.2", - "filelist": "^1.0.1", - "minimatch": "^3.0.4" + "filelist": "^1.0.4", + "minimatch": "^3.1.2" }, "bin": { "jake": "bin/cli.js" @@ -12610,8 +12819,9 @@ } }, "node_modules/jake/node_modules/async": { - "version": "0.9.2", - "integrity": "sha512-l6ToIJIotphWahxxHyzK9bnLR6kM4jJIIgLShZeqLY7iboHoGkdgFl7W2/Ivi4SkMJYGKqW8vSuk0uKUj6qsSw==" + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" }, "node_modules/jasmine": { "version": "5.0.0", @@ -17382,30 +17592,24 @@ } }, "node_modules/named-placeholders": { - "version": "1.1.2", - "integrity": "sha512-wiFWqxoLL3PGVReSZpjLVxyJ1bRqe+KKJVbr4hGs1KWfTZTQyezHFBbuKj9hsizHyGV2ne7EMjHdxEGAybD5SA==", - "dev": true, + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", "dependencies": { - "lru-cache": "^4.1.3" + "lru-cache": "^7.14.1" }, "engines": { - "node": ">=6.0.0" + "node": ">=12.0.0" } }, "node_modules/named-placeholders/node_modules/lru-cache": { - "version": "4.1.5", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "dev": true, - "dependencies": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "engines": { + "node": ">=12" } }, - "node_modules/named-placeholders/node_modules/yallist": { - "version": "2.1.2", - "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", - "dev": true - }, "node_modules/nan": { "version": "2.17.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz", @@ -17442,6 +17646,38 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "node_modules/needle": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/needle/-/needle-2.9.1.tgz", + "integrity": "sha512-6R9fqJ5Zcmf+uYaFgdIHmLwNldn5HbK8L5ybn7Uz+ylX/rnOsSp1AHcvQSrCaFN+qNM1wpymHqD7mVasEOlHGQ==", + "dev": true, + "dependencies": { + "debug": "^3.2.6", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" + }, + "bin": { + "needle": "bin/needle" + }, + "engines": { + "node": ">= 4.4.x" + } + }, + "node_modules/needle/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/needle/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, "node_modules/negotiator": { "version": "0.6.3", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", @@ -17796,6 +18032,199 @@ "dev": true, "optional": true }, + "node_modules/node-pre-gyp": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.13.0.tgz", + "integrity": "sha512-Md1D3xnEne8b/HGVQkZZwV27WUi1ZRuZBij24TNaZwUPU3ZAFtvT6xxJGaUVillfmMKnn5oD1HoGsp2Ftik7SQ==", + "deprecated": "Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future", + "dev": true, + "dependencies": { + "detect-libc": "^1.0.2", + "mkdirp": "^0.5.1", + "needle": "^2.2.1", + "nopt": "^4.0.1", + "npm-packlist": "^1.1.6", + "npmlog": "^4.0.2", + "rc": "^1.2.7", + "rimraf": "^2.6.1", + "semver": "^5.3.0", + "tar": "^4" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, + "node_modules/node-pre-gyp/node_modules/are-we-there-yet": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", + "integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==", + "dev": true, + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "node_modules/node-pre-gyp/node_modules/detect-libc": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", + "integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==", + "dev": true, + "bin": { + "detect-libc": "bin/detect-libc.js" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/node-pre-gyp/node_modules/fs-minipass": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", + "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", + "dev": true, + "dependencies": { + "minipass": "^2.6.0" + } + }, + "node_modules/node-pre-gyp/node_modules/gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==", + "dev": true, + "dependencies": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "node_modules/node-pre-gyp/node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true + }, + "node_modules/node-pre-gyp/node_modules/minipass": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", + "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "node_modules/node-pre-gyp/node_modules/minizlib": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", + "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", + "dev": true, + "dependencies": { + "minipass": "^2.9.0" + } + }, + "node_modules/node-pre-gyp/node_modules/nopt": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz", + "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==", + "dev": true, + "dependencies": { + "abbrev": "1", + "osenv": "^0.1.4" + }, + "bin": { + "nopt": "bin/nopt.js" + } + }, + "node_modules/node-pre-gyp/node_modules/npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "dev": true, + "dependencies": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "node_modules/node-pre-gyp/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/node-pre-gyp/node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, + "node_modules/node-pre-gyp/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, + "node_modules/node-pre-gyp/node_modules/tar": { + "version": "4.4.19", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz", + "integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==", + "dev": true, + "dependencies": { + "chownr": "^1.1.4", + "fs-minipass": "^1.2.7", + "minipass": "^2.9.0", + "minizlib": "^1.3.3", + "mkdirp": "^0.5.5", + "safe-buffer": "^5.2.1", + "yallist": "^3.1.1" + }, + "engines": { + "node": ">=4.5" + } + }, + "node_modules/node-pre-gyp/node_modules/tar/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/node-releases": { "version": "2.0.2", "integrity": "sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg==" @@ -18013,6 +18442,295 @@ "node": ">=0.4.0" } }, + "node_modules/nodegit": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/nodegit/-/nodegit-0.27.0.tgz", + "integrity": "sha512-E9K4gPjWiA0b3Tx5lfWCzG7Cvodi2idl3V5UD2fZrOrHikIfrN7Fc2kWLtMUqqomyoToYJLeIC8IV7xb1CYRLA==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "fs-extra": "^7.0.0", + "got": "^10.7.0", + "json5": "^2.1.0", + "lodash": "^4.17.14", + "nan": "^2.14.0", + "node-gyp": "^4.0.0", + "node-pre-gyp": "^0.13.0", + "ramda": "^0.25.0", + "tar-fs": "^1.16.3" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/nodegit/node_modules/are-we-there-yet": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", + "integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==", + "dev": true, + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "node_modules/nodegit/node_modules/bl": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.3.tgz", + "integrity": "sha512-pvcNpa0UU69UT341rO6AYy4FVAIkUHuZXRIWbq+zHnsVcRzDDjIAhGuuYoi0d//cwIwtt4pkpKycWEfjdV+vww==", + "dev": true, + "dependencies": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "node_modules/nodegit/node_modules/fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, + "node_modules/nodegit/node_modules/fs-minipass": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", + "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", + "dev": true, + "dependencies": { + "minipass": "^2.6.0" + } + }, + "node_modules/nodegit/node_modules/gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==", + "dev": true, + "dependencies": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "node_modules/nodegit/node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true + }, + "node_modules/nodegit/node_modules/minipass": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", + "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "node_modules/nodegit/node_modules/minizlib": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", + "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", + "dev": true, + "dependencies": { + "minipass": "^2.9.0" + } + }, + "node_modules/nodegit/node_modules/node-gyp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-4.0.0.tgz", + "integrity": "sha512-2XiryJ8sICNo6ej8d0idXDEMKfVfFK7kekGCtJAuelGsYHQxhj13KTf95swTCN2dZ/4lTfZ84Fu31jqJEEgjWA==", + "dev": true, + "dependencies": { + "glob": "^7.0.3", + "graceful-fs": "^4.1.2", + "mkdirp": "^0.5.0", + "nopt": "2 || 3", + "npmlog": "0 || 1 || 2 || 3 || 4", + "osenv": "0", + "request": "^2.87.0", + "rimraf": "2", + "semver": "~5.3.0", + "tar": "^4.4.8", + "which": "1" + }, + "bin": { + "node-gyp": "bin/node-gyp.js" + }, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/nodegit/node_modules/nopt": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", + "integrity": "sha512-4GUt3kSEYmk4ITxzB/b9vaIDfUVWN/Ml1Fwl11IlnIG2iaJ9O6WXZ9SrYM9NLI8OCBieN2Y8SWC2oJV0RQ7qYg==", + "dev": true, + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + } + }, + "node_modules/nodegit/node_modules/npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "dev": true, + "dependencies": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "node_modules/nodegit/node_modules/pump": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.3.tgz", + "integrity": "sha512-8k0JupWme55+9tCVE+FS5ULT3K6AbgqrGa58lTT49RpyfwwcGedHqaC5LlQNdEAumn/wFsu6aPwkuPMioy8kqw==", + "dev": true, + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/nodegit/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/nodegit/node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, + "node_modules/nodegit/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, + "node_modules/nodegit/node_modules/tar": { + "version": "4.4.19", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz", + "integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==", + "dev": true, + "dependencies": { + "chownr": "^1.1.4", + "fs-minipass": "^1.2.7", + "minipass": "^2.9.0", + "minizlib": "^1.3.3", + "mkdirp": "^0.5.5", + "safe-buffer": "^5.2.1", + "yallist": "^3.1.1" + }, + "engines": { + "node": ">=4.5" + } + }, + "node_modules/nodegit/node_modules/tar-fs": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.16.3.tgz", + "integrity": "sha512-NvCeXpYx7OsmOh8zIOP/ebG55zZmxLE0etfWRbWok+q2Qo8x/vOR/IJT1taADXPe+jsiu9axDb3X4B+iIgNlKw==", + "dev": true, + "dependencies": { + "chownr": "^1.0.1", + "mkdirp": "^0.5.1", + "pump": "^1.0.0", + "tar-stream": "^1.1.2" + } + }, + "node_modules/nodegit/node_modules/tar-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz", + "integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==", + "dev": true, + "dependencies": { + "bl": "^1.0.0", + "buffer-alloc": "^1.2.0", + "end-of-stream": "^1.0.0", + "fs-constants": "^1.0.0", + "readable-stream": "^2.3.0", + "to-buffer": "^1.1.1", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/nodegit/node_modules/tar/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/nodegit/node_modules/which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, + "node_modules/nodegit/node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "dev": true, + "engines": { + "node": ">=0.4" + } + }, "node_modules/nodemailer": { "version": "6.7.3", "integrity": "sha512-KUdDsspqx89sD4UUyUKzdlUOper3hRkDVkrKh/89G+d9WKsU5ox51NWS4tB1XR5dPUdR4SP0E3molyEfOvSa3g==", @@ -18221,6 +18939,32 @@ "node": ">= 0.10" } }, + "node_modules/npm-bundled": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.1.2.tgz", + "integrity": "sha512-x5DHup0SuyQcmL3s7Rx/YQ8sbw/Hzg0rj48eN0dV7hf5cmQq5PXIeioroH3raV1QC1yh3uTYuMThvEQF3iKgGQ==", + "dev": true, + "dependencies": { + "npm-normalize-package-bin": "^1.0.1" + } + }, + "node_modules/npm-normalize-package-bin": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz", + "integrity": "sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==", + "dev": true + }, + "node_modules/npm-packlist": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz", + "integrity": "sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==", + "dev": true, + "dependencies": { + "ignore-walk": "^3.0.1", + "npm-bundled": "^1.0.1", + "npm-normalize-package-bin": "^1.0.1" + } + }, "node_modules/npm-run-path": { "version": "4.0.1", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", @@ -18558,6 +19302,15 @@ "url-parse": "^1.4.3" } }, + "node_modules/os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/os-locale": { "version": "5.0.0", "integrity": "sha512-tqZcNEDAIZKBEPnHPlVDvKrp7NzgLi7jRmhKiUoa2NUmhl13FtkAGLUVR+ZsYvApBQdBfYm43A4tXXQ4IrYLBA==", @@ -18573,6 +19326,25 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "dev": true, + "dependencies": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, "node_modules/p-cancelable": { "version": "2.1.1", "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==", @@ -19682,6 +20454,12 @@ "node": ">=8" } }, + "node_modules/ramda": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.25.0.tgz", + "integrity": "sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ==", + "dev": true + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -21335,6 +22113,19 @@ "version": "1.2.0", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "node_modules/sha.js": { + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "dev": true, + "dependencies": { + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" + }, + "bin": { + "sha.js": "bin.js" + } + }, "node_modules/shallow-clone": { "version": "3.0.1", "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", @@ -23557,6 +24348,12 @@ "node": ">=0.10.0" } }, + "node_modules/to-buffer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", + "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==", + "dev": true + }, "node_modules/to-fast-properties": { "version": "2.0.0", "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", @@ -26671,28 +27468,6 @@ "node": ">= 8.0" } }, - "print/node_modules/named-placeholders": { - "version": "1.1.2", - "license": "MIT", - "dependencies": { - "lru-cache": "^4.1.3" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "print/node_modules/named-placeholders/node_modules/lru-cache": { - "version": "4.1.5", - "license": "ISC", - "dependencies": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "print/node_modules/named-placeholders/node_modules/yallist": { - "version": "2.1.2", - "license": "ISC" - }, "print/node_modules/nice-try": { "version": "1.0.5", "license": "MIT" @@ -26777,10 +27552,6 @@ "node": ">=10.13.0" } }, - "print/node_modules/pseudomap": { - "version": "1.0.2", - "license": "ISC" - }, "print/node_modules/psl": { "version": "1.9.0", "license": "MIT" @@ -29542,6 +30313,12 @@ "version": "2.1.1", "integrity": "sha512-/aPsuoj/1Dw/kzhkgz+ES6TxG0zfTMGLwuK2ZG00k/iJzYHTLCE8mVU8EPqEOp/lmxPoq1C1C9RYToRKb2KEfg==" }, + "@sqltools/formatter": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.5.tgz", + "integrity": "sha512-Uy0+khmZqUrUGm5dmMqVlnvufZRSK0FbYzVgp0UMstm+F5+W2/jnEEQyc9vo1ZR/E5ZI/B1WjjoTqBqwJL6Krw==", + "dev": true + }, "@szmarczak/http-timer": { "version": "4.0.6", "integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==", @@ -29826,6 +30603,117 @@ "@types/node": "*" } }, + "@verdnatura/myt": { + "version": "1.5.23", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.23.tgz", + "integrity": "sha512-gqMLcnFgAW0pqekEkWa069ySBWI+j5Q3Mtll7IIaBCl8OSUWqC6/EMuGg/2X2i9RjhMuCHzOnz+yMKrBE4vX/w==", + "dev": true, + "requires": { + "@sqltools/formatter": "^1.2.5", + "colors": "^1.4.0", + "ejs": "^3.1.9", + "fs-extra": "^11.1.1", + "getopts": "^2.3.0", + "ini": "^4.1.1", + "mysql2": "^3.3.4", + "nodegit": "^0.27.0", + "require-yaml": "^0.0.1", + "sha.js": "^2.4.11" + }, + "dependencies": { + "denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "dev": true + }, + "ejs": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.9.tgz", + "integrity": "sha512-rC+QVNMJWv+MtPgkt0y+0rVEIdbtxVADApW9JXrUVlzHetgcyczP/E7DJmWJ4fJCZF2cPcBk0laWO9ZHMG3DmQ==", + "dev": true, + "requires": { + "jake": "^10.8.5" + } + }, + "fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + }, + "ini": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.1.tgz", + "integrity": "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==", + "dev": true + }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "dev": true + }, + "lru-cache": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", + "dev": true + }, + "mysql2": { + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.6.5.tgz", + "integrity": "sha512-pS/KqIb0xlXmtmqEuTvBXTmLoQ5LmAz5NW/r8UyQ1ldvnprNEj3P9GbmuQQ2J0A4LO+ynotGi6TbscPa8OUb+w==", + "dev": true, + "requires": { + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru-cache": "^8.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + } + }, + "sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "dev": true + }, + "universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true + } + } + }, "@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", @@ -31050,6 +31938,22 @@ } } }, + "buffer-alloc": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", + "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", + "dev": true, + "requires": { + "buffer-alloc-unsafe": "^1.1.0", + "buffer-fill": "^1.0.0" + } + }, + "buffer-alloc-unsafe": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", + "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==", + "dev": true + }, "buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -31064,6 +31968,12 @@ "version": "1.0.1", "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" }, + "buffer-fill": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", + "integrity": "sha512-T7zexNBwiiaCOGDg9xNX9PBmjrubblRkENuptryuI64URkXDFum9il/JGL8Lm8wYfAXpredVXXZz7eMHilimiQ==", + "dev": true + }, "buffer-from": { "version": "1.1.2", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" @@ -33776,10 +34686,29 @@ } }, "filelist": { - "version": "1.0.2", - "integrity": "sha512-z7O0IS8Plc39rTCq6i6iHxk43duYOn8uFJiWSewIq0Bww1RNybVHSCjahmcC87ZqAm4OTvFzlzeGu3XAzG1ctQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", "requires": { - "minimatch": "^3.0.4" + "minimatch": "^5.0.1" + }, + "dependencies": { + "brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "requires": { + "balanced-match": "^1.0.0" + } + }, + "minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "requires": { + "brace-expansion": "^2.0.1" + } + } } }, "fill-range": { @@ -34410,6 +35339,12 @@ "integrity": "sha512-Ln0UQDlxH1BapMu3GPtf7CuYNwRZf2gwCuPqbyG6pB8WfmFpzqcy4xtAaAMUhnNqjMKTiCPZG2oMT3YSx8U2NA==", "dev": true }, + "getopts": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/getopts/-/getopts-2.3.0.tgz", + "integrity": "sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==", + "dev": true + }, "getpass": { "version": "0.1.7", "integrity": "sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==", @@ -36427,6 +37362,15 @@ "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", "dev": true }, + "ignore-walk": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.4.tgz", + "integrity": "sha512-PY6Ii8o1jMRA1z4F2hRkH/xN59ox43DavKvD3oDpfurRlOJyAHpifIwpbdv1n4jt4ov0jSpw3kQ4GhJnpBL6WQ==", + "dev": true, + "requires": { + "minimatch": "^3.0.4" + } + }, "image-type": { "version": "4.1.0", "integrity": "sha512-CFJMJ8QK8lJvRlTCEgarL4ro6hfDQKif2HjSvYCdQZESaIPV4v9imrf7BQHK+sQeTeNeMpWciR9hyC/g8ybXEg==", @@ -36998,18 +37942,20 @@ } }, "jake": { - "version": "10.8.4", - "integrity": "sha512-MtWeTkl1qGsWUtbl/Jsca/8xSoK3x0UmS82sNbjqxxG/de/M/3b1DntdjHgPMC50enlTNwXOCRqPXLLt5cCfZA==", + "version": "10.8.7", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.7.tgz", + "integrity": "sha512-ZDi3aP+fG/LchyBzUM804VjddnwfSfsdeYkwt8NcbKRvo4rFkjhs456iLFn3k2ZUWvNe4i48WACDbza8fhq2+w==", "requires": { - "async": "0.9.x", + "async": "^3.2.3", "chalk": "^4.0.2", - "filelist": "^1.0.1", - "minimatch": "^3.0.4" + "filelist": "^1.0.4", + "minimatch": "^3.1.2" }, "dependencies": { "async": { - "version": "0.9.2", - "integrity": "sha512-l6ToIJIotphWahxxHyzK9bnLR6kM4jJIIgLShZeqLY7iboHoGkdgFl7W2/Ivi4SkMJYGKqW8vSuk0uKUj6qsSw==" + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" } } }, @@ -40882,26 +41828,17 @@ } }, "named-placeholders": { - "version": "1.1.2", - "integrity": "sha512-wiFWqxoLL3PGVReSZpjLVxyJ1bRqe+KKJVbr4hGs1KWfTZTQyezHFBbuKj9hsizHyGV2ne7EMjHdxEGAybD5SA==", - "dev": true, + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", "requires": { - "lru-cache": "^4.1.3" + "lru-cache": "^7.14.1" }, "dependencies": { "lru-cache": { - "version": "4.1.5", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "dev": true, - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "yallist": { - "version": "2.1.2", - "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", - "dev": true + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==" } } }, @@ -40938,6 +41875,34 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "needle": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/needle/-/needle-2.9.1.tgz", + "integrity": "sha512-6R9fqJ5Zcmf+uYaFgdIHmLwNldn5HbK8L5ybn7Uz+ylX/rnOsSp1AHcvQSrCaFN+qNM1wpymHqD7mVasEOlHGQ==", + "dev": true, + "requires": { + "debug": "^3.2.6", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + } + } + }, "negotiator": { "version": "0.6.3", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" @@ -41192,6 +42157,170 @@ } } }, + "node-pre-gyp": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.13.0.tgz", + "integrity": "sha512-Md1D3xnEne8b/HGVQkZZwV27WUi1ZRuZBij24TNaZwUPU3ZAFtvT6xxJGaUVillfmMKnn5oD1HoGsp2Ftik7SQ==", + "dev": true, + "requires": { + "detect-libc": "^1.0.2", + "mkdirp": "^0.5.1", + "needle": "^2.2.1", + "nopt": "^4.0.1", + "npm-packlist": "^1.1.6", + "npmlog": "^4.0.2", + "rc": "^1.2.7", + "rimraf": "^2.6.1", + "semver": "^5.3.0", + "tar": "^4" + }, + "dependencies": { + "are-we-there-yet": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", + "integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==", + "dev": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "detect-libc": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", + "integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==", + "dev": true + }, + "fs-minipass": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", + "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", + "dev": true, + "requires": { + "minipass": "^2.6.0" + } + }, + "gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==", + "dev": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true + }, + "minipass": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", + "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "minizlib": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", + "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", + "dev": true, + "requires": { + "minipass": "^2.9.0" + } + }, + "nopt": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz", + "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==", + "dev": true, + "requires": { + "abbrev": "1", + "osenv": "^0.1.4" + } + }, + "npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "dev": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "tar": { + "version": "4.4.19", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz", + "integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==", + "dev": true, + "requires": { + "chownr": "^1.1.4", + "fs-minipass": "^1.2.7", + "minipass": "^2.9.0", + "minizlib": "^1.3.3", + "mkdirp": "^0.5.5", + "safe-buffer": "^5.2.1", + "yallist": "^3.1.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + } + } + } + } + }, "node-releases": { "version": "2.0.2", "integrity": "sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg==" @@ -41357,6 +42486,254 @@ "is": "^3.2.1" } }, + "nodegit": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/nodegit/-/nodegit-0.27.0.tgz", + "integrity": "sha512-E9K4gPjWiA0b3Tx5lfWCzG7Cvodi2idl3V5UD2fZrOrHikIfrN7Fc2kWLtMUqqomyoToYJLeIC8IV7xb1CYRLA==", + "dev": true, + "requires": { + "fs-extra": "^7.0.0", + "got": "^10.7.0", + "json5": "^2.1.0", + "lodash": "^4.17.14", + "nan": "^2.14.0", + "node-gyp": "^4.0.0", + "node-pre-gyp": "^0.13.0", + "ramda": "^0.25.0", + "tar-fs": "^1.16.3" + }, + "dependencies": { + "are-we-there-yet": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.7.tgz", + "integrity": "sha512-nxwy40TuMiUGqMyRHgCSWZ9FM4VAoRP4xUYSTv5ImRog+h9yISPbVH7H8fASCIzYn9wlEv4zvFL7uKDMCFQm3g==", + "dev": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "bl": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.3.tgz", + "integrity": "sha512-pvcNpa0UU69UT341rO6AYy4FVAIkUHuZXRIWbq+zHnsVcRzDDjIAhGuuYoi0d//cwIwtt4pkpKycWEfjdV+vww==", + "dev": true, + "requires": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "fs-minipass": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", + "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", + "dev": true, + "requires": { + "minipass": "^2.6.0" + } + }, + "gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha512-14x4kjc6lkD3ltw589k0NrPD6cCNTD6CWoVUNpB85+DrtONoZn+Rug6xZU5RvSC4+TZPxA5AnBibQYAvZn41Hg==", + "dev": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true + }, + "minipass": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", + "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "minizlib": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", + "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", + "dev": true, + "requires": { + "minipass": "^2.9.0" + } + }, + "node-gyp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-4.0.0.tgz", + "integrity": "sha512-2XiryJ8sICNo6ej8d0idXDEMKfVfFK7kekGCtJAuelGsYHQxhj13KTf95swTCN2dZ/4lTfZ84Fu31jqJEEgjWA==", + "dev": true, + "requires": { + "glob": "^7.0.3", + "graceful-fs": "^4.1.2", + "mkdirp": "^0.5.0", + "nopt": "2 || 3", + "npmlog": "0 || 1 || 2 || 3 || 4", + "osenv": "0", + "request": "^2.87.0", + "rimraf": "2", + "semver": "~5.3.0", + "tar": "^4.4.8", + "which": "1" + } + }, + "nopt": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz", + "integrity": "sha512-4GUt3kSEYmk4ITxzB/b9vaIDfUVWN/Ml1Fwl11IlnIG2iaJ9O6WXZ9SrYM9NLI8OCBieN2Y8SWC2oJV0RQ7qYg==", + "dev": true, + "requires": { + "abbrev": "1" + } + }, + "npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "dev": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "pump": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.3.tgz", + "integrity": "sha512-8k0JupWme55+9tCVE+FS5ULT3K6AbgqrGa58lTT49RpyfwwcGedHqaC5LlQNdEAumn/wFsu6aPwkuPMioy8kqw==", + "dev": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "tar": { + "version": "4.4.19", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz", + "integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==", + "dev": true, + "requires": { + "chownr": "^1.1.4", + "fs-minipass": "^1.2.7", + "minipass": "^2.9.0", + "minizlib": "^1.3.3", + "mkdirp": "^0.5.5", + "safe-buffer": "^5.2.1", + "yallist": "^3.1.1" + }, + "dependencies": { + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + } + } + }, + "tar-fs": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.16.3.tgz", + "integrity": "sha512-NvCeXpYx7OsmOh8zIOP/ebG55zZmxLE0etfWRbWok+q2Qo8x/vOR/IJT1taADXPe+jsiu9axDb3X4B+iIgNlKw==", + "dev": true, + "requires": { + "chownr": "^1.0.1", + "mkdirp": "^0.5.1", + "pump": "^1.0.0", + "tar-stream": "^1.1.2" + } + }, + "tar-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz", + "integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==", + "dev": true, + "requires": { + "bl": "^1.0.0", + "buffer-alloc": "^1.2.0", + "end-of-stream": "^1.0.0", + "fs-constants": "^1.0.0", + "readable-stream": "^2.3.0", + "to-buffer": "^1.1.1", + "xtend": "^4.0.0" + } + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "dev": true + } + } + }, "nodemailer": { "version": "6.7.3", "integrity": "sha512-KUdDsspqx89sD4UUyUKzdlUOper3hRkDVkrKh/89G+d9WKsU5ox51NWS4tB1XR5dPUdR4SP0E3molyEfOvSa3g==" @@ -41506,6 +42883,32 @@ "once": "^1.3.2" } }, + "npm-bundled": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.1.2.tgz", + "integrity": "sha512-x5DHup0SuyQcmL3s7Rx/YQ8sbw/Hzg0rj48eN0dV7hf5cmQq5PXIeioroH3raV1QC1yh3uTYuMThvEQF3iKgGQ==", + "dev": true, + "requires": { + "npm-normalize-package-bin": "^1.0.1" + } + }, + "npm-normalize-package-bin": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz", + "integrity": "sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==", + "dev": true + }, + "npm-packlist": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz", + "integrity": "sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==", + "dev": true, + "requires": { + "ignore-walk": "^3.0.1", + "npm-bundled": "^1.0.1", + "npm-normalize-package-bin": "^1.0.1" + } + }, "npm-run-path": { "version": "4.0.1", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", @@ -41768,6 +43171,12 @@ "url-parse": "^1.4.3" } }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==", + "dev": true + }, "os-locale": { "version": "5.0.0", "integrity": "sha512-tqZcNEDAIZKBEPnHPlVDvKrp7NzgLi7jRmhKiUoa2NUmhl13FtkAGLUVR+ZsYvApBQdBfYm43A4tXXQ4IrYLBA==", @@ -41777,6 +43186,22 @@ "mem": "^5.0.0" } }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", + "dev": true + }, + "osenv": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "dev": true, + "requires": { + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" + } + }, "p-cancelable": { "version": "2.1.1", "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==" @@ -42583,6 +44008,12 @@ "integrity": "sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g==", "dev": true }, + "ramda": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.25.0.tgz", + "integrity": "sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ==", + "dev": true + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -43860,6 +45291,16 @@ "version": "1.2.0", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, + "sha.js": { + "version": "2.4.11", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "dev": true, + "requires": { + "inherits": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, "shallow-clone": { "version": "3.0.1", "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", @@ -45557,6 +46998,12 @@ "is-negated-glob": "^1.0.0" } }, + "to-buffer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", + "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==", + "dev": true + }, "to-fast-properties": { "version": "2.0.0", "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", @@ -46950,24 +48397,6 @@ "sqlstring": "^2.3.1" } }, - "named-placeholders": { - "version": "1.1.2", - "requires": { - "lru-cache": "^4.1.3" - }, - "dependencies": { - "lru-cache": { - "version": "4.1.5", - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "yallist": { - "version": "2.1.2" - } - } - }, "nice-try": { "version": "1.0.5" }, @@ -47013,9 +48442,6 @@ "pngjs": { "version": "5.0.0" }, - "pseudomap": { - "version": "1.0.2" - }, "psl": { "version": "1.9.0" }, diff --git a/package.json b/package.json index f13c44162..0c9d518e6 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", + "@verdnatura/myt": "^1.5.23", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 51a46083901cc43689414cc514989fa666a71d7f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 15 Jan 2024 12:35:23 +0100 Subject: [PATCH 045/116] feat: refs #5483 Gulp and back tests adjustments --- back/tests.js | 32 ++++++++++++++++++-------------- gulpfile.js | 17 ++++++++++++----- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/back/tests.js b/back/tests.js index 2678f6744..b56b32d94 100644 --- a/back/tests.js +++ b/back/tests.js @@ -1,6 +1,10 @@ -const Docker = require('../db/docker.js'); +const path = require('path'); +const Myt = require('../../myt/myt'); +const Run = require('../../myt/myt-run'); let dataSources = require('../loopback/server/datasources.json'); +let myt; + process.on('warning', warning => { console.log(warning.name); console.log(warning.message); @@ -8,28 +12,28 @@ process.on('warning', warning => { }); process.on('SIGUSR2', async() => { - if (container) await container.rm(); + if (myt) await myt.deinit(); }); process.on('exit', async function() { - if (container) await container.rm(); + if (myt) await myt.deinit(); }); -let container; async function test() { - let isCI = false; + const isCI = process.argv[2] === 'ci'; - if (process.argv[2] === 'ci') - isCI = true; + myt = new Myt(); + await myt.init({ + workspace: path.join(__dirname, '..'), + random: true, + ci: isCI + }); + const {dbConfig} = await myt.run(Run); - container = new Docker(); - - await container.run(isCI); dataSources = JSON.parse(JSON.stringify(dataSources)); - Object.assign(dataSources.vn, { - host: container.dbConf.host, - port: container.dbConf.port + host: dbConfig.host, + port: dbConfig.port }); const bootOptions = {dataSources}; @@ -77,7 +81,7 @@ async function test() { await jasmine.execute(); if (app) await app.disconnect(); - if (container) await container.rm(); + if (myt) await myt.deinit(); console.log('App disconnected & container removed'); } diff --git a/gulpfile.js b/gulpfile.js index d7e7d8e86..04510afa7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,7 +3,9 @@ const gulp = require('gulp'); const PluginError = require('plugin-error'); const argv = require('minimist')(process.argv.slice(2)); const log = require('fancy-log'); -const Docker = require('./db/docker.js'); +const Myt = require('../myt/myt'); +const Run = require('../myt/myt-run'); +const Start = require('../myt/myt-start'); // Configuration @@ -231,14 +233,18 @@ watch.description = `Watches for changes in routes and locale files`; // Docker async function dockerStart() { - const container = new Docker('salix-db'); - await container.start(); + const myt = new Myt(); + await myt.init({workspace: __dirname}); + await myt.run(Start); + await myt.deinit(); } dockerStart.description = `Starts the salix-db container`; async function docker() { - const container = new Docker('salix-db'); - await container.run(); + const myt = new Myt(); + await myt.init({workspace: __dirname}); + await myt.run(Run); + await myt.deinit(); } docker.description = `Runs the salix-db container`; @@ -258,5 +264,6 @@ module.exports = { locales, localesRoutes, watch, + dockerStart, docker }; From 3ba5bc8fa1806712791305af9ba15418f0bcb581 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 15 Jan 2024 12:59:19 +0100 Subject: [PATCH 046/116] refs #3979 fix e2e --- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 9095eee0a..d7e9f3e84 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -1,7 +1,7 @@ import selectors from '../../../helpers/selectors.js'; import getBrowser from '../../../helpers/puppeteer'; -describe('Ticket Edit sale path', () => { +fdescribe('Ticket Edit sale path', () => { let browser; let page; @@ -225,7 +225,7 @@ describe('Ticket Edit sale path', () => { }); it('should show error trying to delete a ticket with a refund', async() => { - await page.accessToSearchResult('6'); + await page.accessToSearchResult('7'); await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); await page.waitToClick(selectors.globalItems.acceptButton); From 7d7c6d707124fc4d3abc53fd09728658651064e0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 15 Jan 2024 12:59:55 +0100 Subject: [PATCH 047/116] remove fdescribre --- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index d7e9f3e84..8be307269 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -1,7 +1,7 @@ import selectors from '../../../helpers/selectors.js'; import getBrowser from '../../../helpers/puppeteer'; -fdescribe('Ticket Edit sale path', () => { +describe('Ticket Edit sale path', () => { let browser; let page; From 74a4e486aac4ce3216b1f8401b0478bb9f7e3593 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 15 Jan 2024 13:12:15 +0100 Subject: [PATCH 048/116] refs #6661 Propagate changes from vn-database --- .../240401/02-invoiceOutConfig_refLen.sql | 2 + ...t.sql => 03-fixInvoiceOutBeforeInsert.sql} | 51 ++++++++++--------- db/dump/fixtures.sql | 6 +-- 3 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 db/changes/240401/02-invoiceOutConfig_refLen.sql rename db/changes/240401/{00-fixInvoiceOutBeforeInsert.sql => 03-fixInvoiceOutBeforeInsert.sql} (51%) diff --git a/db/changes/240401/02-invoiceOutConfig_refLen.sql b/db/changes/240401/02-invoiceOutConfig_refLen.sql new file mode 100644 index 000000000..8b91889f2 --- /dev/null +++ b/db/changes/240401/02-invoiceOutConfig_refLen.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.invoiceOutConfig + ADD IF NOT EXISTS refLen TINYINT UNSIGNED DEFAULT 5 NOT NULL COMMENT 'Invoice reference identifier length'; diff --git a/db/changes/240401/00-fixInvoiceOutBeforeInsert.sql b/db/changes/240401/03-fixInvoiceOutBeforeInsert.sql similarity index 51% rename from db/changes/240401/00-fixInvoiceOutBeforeInsert.sql rename to db/changes/240401/03-fixInvoiceOutBeforeInsert.sql index 10e8d6356..0081c8803 100644 --- a/db/changes/240401/00-fixInvoiceOutBeforeInsert.sql +++ b/db/changes/240401/03-fixInvoiceOutBeforeInsert.sql @@ -4,17 +4,20 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeInse FOR EACH ROW BEGIN /** + * Generates the next reference for the invoice serial. There cannot be gaps + * between identifiers of the same serial! + * * Reference format: - * - 0: Serial [A-Z] - * - 1: Sage company id - * - 2-3: Last two digits of issued year - * - 4-8: Autoincrement identifier - **/ - DECLARE vNewRef INT DEFAULT 0; - DECLARE vCompanyCode INT; + * {0} Invoice serial + * {1} The company code + * {2-3} Last two digits of issue year + * {4-$} Autoincrement identifier + */ + DECLARE vRef INT DEFAULT 0; + DECLARE vRefLen INT; + DECLARE vRefPrefix VARCHAR(255); DECLARE vLastRef VARCHAR(255); - DECLARE vRefStr VARCHAR(255); - DECLARE vRefLen INT DEFAULT 5; + DECLARE vCompanyCode INT; DECLARE vYearLen INT DEFAULT 2; DECLARE vPrefixLen INT; @@ -23,36 +26,34 @@ BEGIN WHERE id = NEW.companyFk; IF vCompanyCode IS NULL THEN - CALL util.throw('sageCompanyNotDefined'); + CALL util.throw('companyCodeNotDefined'); END IF; SELECT MAX(i.ref) INTO vLastRef FROM invoiceOut i WHERE i.serial = NEW.serial - AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) + AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.lastDayOfYear(NEW.issued) AND i.companyFk = NEW.companyFk; IF vLastRef IS NOT NULL THEN SET vPrefixLen = LENGTH(NEW.serial) + LENGTH(vCompanyCode) + vYearLen; SET vRefLen = LENGTH(vLastRef) - vPrefixLen; - SET vRefStr = SUBSTRING(vLastRef, vPrefixLen + 1); - SET vNewRef = vRefStr + 1; - - IF LENGTH(vNewRef) > vRefLen THEN - CALL util.throw('refLenExceeded'); - END IF; - - SET NEW.ref = CONCAT( - SUBSTRING(vLastRef, 1, vPrefixLen), - LPAD(vNewRef, LENGTH(vRefStr), '0') - ); + SET vRefPrefix = LEFT(vLastRef, vPrefixLen); + SET vRef = RIGHT(vLastRef, vRefLen); ELSE - SET NEW.ref = CONCAT( + SELECT refLen INTO vRefLen FROM invoiceOutConfig; + SET vRefPrefix = CONCAT( NEW.serial, vCompanyCode, - RIGHT(YEAR(NEW.issued), vYearLen), - LPAD(1, vRefLen, '0') + RIGHT(YEAR(NEW.issued), vYearLen) ); END IF; + + SET vRef = vRef + 1; + IF LENGTH(vRef) > vRefLen THEN + CALL util.throw('refIdLenExceeded'); + END IF; + + SET NEW.ref = CONCAT(vRefPrefix, LPAD(vRef, vRefLen, '0')); END$$ DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 923872f8c..b243692bb 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -600,6 +600,9 @@ INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion` ('NATIONAL', 0, 1), ('WORLD', 2, 15); +INSERT INTO vn.invoiceOutConfig + SET parallelism = 8; + INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) VALUES ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), @@ -623,9 +626,6 @@ UPDATE `vn`.`invoiceOut` SET ref = 'T3333333' WHERE id = 3; UPDATE `vn`.`invoiceOut` SET ref = 'T4444444' WHERE id = 4; UPDATE `vn`.`invoiceOut` SET ref = 'A1111111' WHERE id = 5; -INSERT INTO vn.invoiceOutConfig - SET parallelism = 8; - INSERT INTO `vn`.`invoiceOutTax` (`invoiceOutFk`, `taxableBase`, `vat`, `pgcFk`) VALUES (1, 895.76, 89.58, 4722000010), From b3e1c58918dd63769515b08dd6a022dd6ad78cbf Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 15 Jan 2024 14:50:08 +0100 Subject: [PATCH 049/116] refs #6313 remove restriction --- modules/ticket/back/models/sale.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 3589eac4b..dd092573d 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -28,7 +28,6 @@ module.exports = Self => { const loopBackContext = LoopBackContext.getCurrentContext(); ctx.req = loopBackContext.active; - if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'canForceQuantity', 'WRITE')) return; const ticketId = changes?.ticketFk || instance?.ticketFk; const itemId = changes?.itemFk || instance?.itemFk; From 3ebeebc15913babada444ec73ec095dd7545d032 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 16 Jan 2024 11:47:45 +0100 Subject: [PATCH 050/116] refs #6230 remove basic-data columns --- db/changes/240401/00-revokeItem.sql | 4 + modules/item/front/basic-data/index.html | 115 ++++++++--------------- 2 files changed, 41 insertions(+), 78 deletions(-) create mode 100644 db/changes/240401/00-revokeItem.sql diff --git a/db/changes/240401/00-revokeItem.sql b/db/changes/240401/00-revokeItem.sql new file mode 100644 index 000000000..2b75d67cf --- /dev/null +++ b/db/changes/240401/00-revokeItem.sql @@ -0,0 +1,4 @@ +REVOKE UPDATE ON TABLE `vn`.`item` FROM `employee`; + + +GRANT UPDATE(id, equivalent, stems, minPrice, isToPrint, family, box, category, doPhoto, image, inkFk, intrastatFk, hasMinPrice, created, comment, typeFk, generic, producerFk, description, density, relevancy, expenseFk, isActive, subName, tag5, value5, tag6, value6, tag7, value7, tag8, value8, tag9, value9, tag10, value10, minimum, upToDown, supplyResponseFk, hasKgPrice, isFloramondo, isFragile, numberOfItemsPerCask, embalageCode, quality, stemMultiplier, itemPackingTypeFk, packingOut, genericFk, packingShelve, isLaid, lastUsed, weightByPiece, weightByPiece, editorFk, recycledPlastic, nonRecycledPlastic, minQuantity) ON TABLE vn.item TO employee; diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index 3e47faa5f..bcb78c48e 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -18,22 +18,6 @@
- - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + Date: Tue, 16 Jan 2024 12:14:47 +0100 Subject: [PATCH 051/116] refs #6230 fix test back --- e2e/paths/04-item/02_basic_data.spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/e2e/paths/04-item/02_basic_data.spec.js b/e2e/paths/04-item/02_basic_data.spec.js index f177a98df..3bad18303 100644 --- a/e2e/paths/04-item/02_basic_data.spec.js +++ b/e2e/paths/04-item/02_basic_data.spec.js @@ -27,11 +27,8 @@ describe('Item Edit basic data path', () => { it(`should edit the item basic data and confirm the item data was edited`, async() => { const values = { - name: 'Rose of Purity', - longName: 'RS Rose of Purity', type: 'Anthurium', intrastat: 'Coral y materiales similares', - origin: 'Spain', relevancy: 1, generic: 'Pallet', isActive: false, From ce2bfc7cf18464a6d16d6110d4e649e2749a1548 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 16 Jan 2024 12:46:53 +0100 Subject: [PATCH 052/116] refs #5525 insert --- db/changes/235001/01-supplierAccount.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/changes/235001/01-supplierAccount.sql diff --git a/db/changes/235001/01-supplierAccount.sql b/db/changes/235001/01-supplierAccount.sql new file mode 100644 index 000000000..1c0f1ef43 --- /dev/null +++ b/db/changes/235001/01-supplierAccount.sql @@ -0,0 +1,9 @@ +UPDATE vn.supplierAccount sa + JOIN vn.country c ON sa.countryFk = c.id AND c.code = 'FR' + SET countryFk = c.id + WHERE iban = 'FR7630003012690002801121597'; + +UPDATE vn.supplierAccount sa + JOIN vn.country c ON sa.countryFk = c.id AND c.code = 'PT' + SET countryFk = c.id + WHERE iban = 'PT50001000005813059150168'; From 84134d671f38a2f58074060e6c033efeccdbe5c9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 16 Jan 2024 12:47:58 +0100 Subject: [PATCH 053/116] refs #5525 remove as --- print/templates/reports/sepa-core/sql/supplier.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index ade4b048e..80635ecf5 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -1,15 +1,15 @@ SELECT - m.code AS mandateCode, + m.code mandateCode, s.name, s.street, sc.country, s.postCode, s.city, - sp.name AS province, + sp.name province, s.nif, sa.iban, sa.supplierFk, - be.name AS bankName + be.name bankName FROM client c LEFT JOIN mandate m ON m.clientFk = c.id AND m.companyFk = ? AND m.finished IS NULL From 8095b02835d9ae7e275144b77b73de71edf6b956 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 16 Jan 2024 12:48:40 +0100 Subject: [PATCH 054/116] refs #5525 move version --- db/changes/{235001 => 240401}/00-supplier.sql | 0 db/changes/{235001 => 240401}/01-supplierAccount.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{235001 => 240401}/00-supplier.sql (100%) rename db/changes/{235001 => 240401}/01-supplierAccount.sql (100%) diff --git a/db/changes/235001/00-supplier.sql b/db/changes/240401/00-supplier.sql similarity index 100% rename from db/changes/235001/00-supplier.sql rename to db/changes/240401/00-supplier.sql diff --git a/db/changes/235001/01-supplierAccount.sql b/db/changes/240401/01-supplierAccount.sql similarity index 100% rename from db/changes/235001/01-supplierAccount.sql rename to db/changes/240401/01-supplierAccount.sql From 5bbeda40149fbe44352a1807aa241c0a53809ecc Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 16 Jan 2024 13:05:16 +0100 Subject: [PATCH 055/116] feat: refs #4734 Added viaexpress interdia --- .../viaexpress-config/internationalExpedition.js | 2 +- back/methods/viaexpress-config/renderer.js | 11 ++++++----- back/methods/viaexpress-config/template.ejs | 2 +- back/models/viaexpress-config.json | 3 +++ db/changes/240202/01-viaExpressConfig.sql | 2 ++ .../back/methods/worker-time-control/getClockIn.js | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 db/changes/240202/01-viaExpressConfig.sql diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 698bb1dac..df50b21e5 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -20,7 +20,7 @@ module.exports = Self => { } }); - Self.internationalExpedition = async expeditionFk => { + Self.internationalExpedition = async (expeditionFk) => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index e9abce5ca..c8533ea6b 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -20,11 +20,11 @@ module.exports = Self => { } }); - Self.renderer = async expeditionFk => { + Self.renderer = async (expeditionFk) => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ - fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType'] + fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType', 'agencyModeFk'] }); const expedition = await models.Expedition.findOne({ @@ -34,7 +34,7 @@ module.exports = Self => { { relation: 'ticket', scope: { - fields: ['shipped', 'addressFk', 'clientFk', 'companyFk'], + fields: ['shipped', 'addressFk', 'clientFk', 'companyFk', 'agencyModeFk'], include: [ { relation: 'client', @@ -102,7 +102,6 @@ module.exports = Self => { } ] } - } ] }); @@ -110,13 +109,15 @@ module.exports = Self => { const ticket = expedition.ticket(); const sender = ticket.company().client(); const shipped = ticket.shipped.toISOString(); + const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk) const data = { viaexpressConfig, sender, senderAddress: sender.defaultAddress(), client: ticket.client(), address: ticket.address(), - shipped + shipped, + isInterdia }; const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8'); diff --git a/back/methods/viaexpress-config/template.ejs b/back/methods/viaexpress-config/template.ejs index 0b6eb468c..f9acfe316 100644 --- a/back/methods/viaexpress-config/template.ejs +++ b/back/methods/viaexpress-config/template.ejs @@ -13,7 +13,7 @@ 0 0 0 - 0 + <%= isInterdia %> 0 diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index 8df24201b..acab1f7e6 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -29,6 +29,9 @@ }, "deliveryType": { "type": "string" + }, + "agencyModeFk": { + "type": "number" } } } diff --git a/db/changes/240202/01-viaExpressConfig.sql b/db/changes/240202/01-viaExpressConfig.sql new file mode 100644 index 000000000..8b7f42c9c --- /dev/null +++ b/db/changes/240202/01-viaExpressConfig.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.viaexpressConfig ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; +ALTER TABLE vn.viaexpressConfig ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT; diff --git a/modules/worker/back/methods/worker-time-control/getClockIn.js b/modules/worker/back/methods/worker-time-control/getClockIn.js index 470700643..458cadafb 100644 --- a/modules/worker/back/methods/worker-time-control/getClockIn.js +++ b/modules/worker/back/methods/worker-time-control/getClockIn.js @@ -5,7 +5,7 @@ module.exports = Self => { accepts: [ { arg: 'workerFk', - type: 'int', + type: 'number', required: true, }, From ed8210d5da163492255dd2608b1c8535ce3e94f4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 16 Jan 2024 14:16:11 +0100 Subject: [PATCH 056/116] feat: refs #4734 Requested changes --- db/changes/240202/01-viaExpressConfig.sql | 2 -- db/changes/240203/.gitkeep | 0 db/changes/240203/00-viaExpressConfig.sql | 2 ++ 3 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 db/changes/240202/01-viaExpressConfig.sql create mode 100644 db/changes/240203/.gitkeep create mode 100644 db/changes/240203/00-viaExpressConfig.sql diff --git a/db/changes/240202/01-viaExpressConfig.sql b/db/changes/240202/01-viaExpressConfig.sql deleted file mode 100644 index 8b7f42c9c..000000000 --- a/db/changes/240202/01-viaExpressConfig.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE vn.viaexpressConfig ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; -ALTER TABLE vn.viaexpressConfig ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT; diff --git a/db/changes/240203/.gitkeep b/db/changes/240203/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/db/changes/240203/00-viaExpressConfig.sql b/db/changes/240203/00-viaExpressConfig.sql new file mode 100644 index 000000000..57832e7cd --- /dev/null +++ b/db/changes/240203/00-viaExpressConfig.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`viaexpressConfig` ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; +ALTER TABLE `vn`.`viaexpressConfig` ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT; From 928317389848ec54b1c3e68eadba0dacec39dbfd Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 16 Jan 2024 14:40:50 +0100 Subject: [PATCH 057/116] refs #6222 fix: correct sql folder --- db/changes/240202/00-saleComponent.sql | 589 +++++++++++++++++++++++++ 1 file changed, 589 insertions(+) create mode 100644 db/changes/240202/00-saleComponent.sql diff --git a/db/changes/240202/00-saleComponent.sql b/db/changes/240202/00-saleComponent.sql new file mode 100644 index 000000000..44f9d172c --- /dev/null +++ b/db/changes/240202/00-saleComponent.sql @@ -0,0 +1,589 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption VARCHAR(25)) +proc: BEGIN +/** + * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id de la venta + * @param vOption indica en que componente pone el descuadre, NULL en casos habituales + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.id = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) +BEGIN +/** + * Comprueba que las ventas creadas entre un rango de fechas tienen componentes + * + * @param vCreatedFrom inicio del rango + * @param vCreatedTo fin del rango + */ + DECLARE v_done BOOL DEFAULT FALSE; + DECLARE vSaleFk INTEGER; + DECLARE vTicketFk INTEGER; + DECLARE vConcept VARCHAR(50); + DECLARE vCur CURSOR FOR + SELECT s.id + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo + AND c.id IS NULL + AND t.agencyModeFk IS NOT NULL + AND t.isDeleted IS FALSE + AND t.warehouseFk = 60 + AND ic.merchandise != FALSE + GROUP BY s.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET v_done = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + + DROP TEMPORARY TABLE IF EXISTS tmp.coste; + CREATE TEMPORARY TABLE tmp.coste + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT s.id + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6 + WHERE s.created >= vCreatedFrom + AND ic.merchandise != FALSE; + + OPEN vCur; + + l: LOOP + SET v_done = FALSE; + FETCH vCur INTO vSaleFk; + + IF v_done THEN + LEAVE l; + END IF; + + SELECT ticketFk, concept + INTO vTicketFk, vConcept + FROM sale + WHERE id = vSaleFk; + + CALL sale_calculateComponent(vSaleFk, 'renewPrices'); + END LOOP; + + CLOSE vCur; + DROP TEMPORARY TABLE tmp.coste; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25)) +proc: BEGIN +/** + * Este procedimiento recalcula los componentes de un conjunto de sales, + * eliminando los componentes existentes e insertandolos de nuevo + * + * @param vOption si no se quiere forzar llamar con NULL + * @table tmp.recalculateSales (id) + */ + DECLARE vShipped DATE; + DECLARE vWarehouseFk SMALLINT; + DECLARE vAgencyModeFk INT; + DECLARE vAddressFk INT; + DECLARE vTicketFk INT; + DECLARE vLanded DATE; + DECLARE vIsEditable BOOLEAN; + DECLARE vZoneFk INTEGER; + DECLARE vDone BOOL DEFAULT FALSE; + + DECLARE vCur CURSOR FOR + SELECT DISTINCT s.ticketFk + FROM tmp.recalculateSales rs + JOIN vn.sale s ON s.id = rs.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN vCur; + + l: LOOP + SET vDone = FALSE; + FETCH vCur INTO vTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, + t.zoneFk, + t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, + t.landed + INTO vIsEditable, + vZoneFk, + vWarehouseFk, + vShipped, + vAddressFk, + vAgencyModeFk, + vLanded + FROM ticket t + LEFT JOIN ticketState ts ON t.id = ts.ticket + LEFT JOIN alertLevel al ON al.id = ts.alertLevel + WHERE t.id = vTicketFk; + + CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); + + IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN + CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); + END IF; + + IF vLanded IS NULL OR vZoneFk IS NULL THEN + + UPDATE ticket t + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + WHERE t.id = vTicketFk AND t.landed IS NULL; + + IF vZoneFk IS NULL THEN + SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; + UPDATE ticket t + SET t.zoneFk = vZoneFk + WHERE t.id = vTicketFk AND t.zoneFk IS NULL; + END IF; + + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetLanded; + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) ENGINE = MEMORY + SELECT s.id saleFk, vWarehouseFk warehouseFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + WHERE s.ticketFk = vTicketFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk + FROM sale s + JOIN tmp.recalculateSales rs ON s.id = rs.id + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY s.itemFk; + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + IF vOption IS NULL THEN + SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); + END IF; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + + DROP TEMPORARY TABLE tmp.buyUltimate; + DROP TEMPORARY TABLE tmp.sale; + + END LOOP; + CLOSE vCur; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) +BEGIN +/* + * Recalcula los componentes un ticket clonado, + * las lineas a precio cero fuerza para que tengan precio, el resto lo respeta + * @param vTicketNew nuevo ticket clonado + * @param vTicketOld icket original, a partir del qual se clonara el nuevo +*/ + + REPLACE INTO orderTicket(orderFk,ticketFk) + SELECT orderFk, vTicketNew + FROM orderTicket + WHERE ticketFk = vTicketOld; + + -- Bionizamos lineas con Preu = 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price = 0; + + CALL sale_recalcComponent('renewPrices'); + + -- Bionizamos lineas con Preu > 0 + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (PRIMARY KEY (id)) ENGINE = MEMORY + SELECT id + FROM sale + WHERE ticketFk = vTicketNew AND price > 0; + + CALL sale_recalcComponent('imbalance'); + + DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; + +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) +BEGIN + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + END IF; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + COMMIT; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) +BEGIN +/** + * A partir de la tabla tmp.sale, crea los Movimientos_componentes + * y modifica el campo Preu de la tabla Movimientos + * + * @param i_option integer tipo de actualizacion + * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk + **/ + DECLARE vComponentFk INT; + + IF vCode <> 'renewPrices' THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; + END IF; + + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN `component` c ON c.id = sc.componentFk + WHERE c.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, tc.cost + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); + + -- Añadir componente venta por paquete + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT t.id, t.componentFk, t.cost + FROM ( + SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN vn.buy b ON b.id = buy_id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + LEFT JOIN ( + SELECT s.id + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk + JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' + ) tp ON tp.id = s.id + WHERE tp.id IS NULL + HAVING resto <> 0) t; + + IF vCode <> 'renewPrices' THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE + UPDATE sale s + JOIN item i on i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.price = sumValue / ((100 - s.discount) / 100) + WHERE it.code != 'PRT' ; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.componentFk != 21 + GROUP BY s.id + HAVING ROUND(saleValue, 4) <> 0; + END IF; + + UPDATE sale s + JOIN ( + SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN `component` c ON c.id = sc.componentFk + JOIN componentType ct on ct.id = c.typeFk AND ct.isBase + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.priceFixed = sumValue, s.isPriceFixed = 1; + + DELETE sc.* + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN sale s on s.id = sc.saleFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT'; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 15, s.price + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN item i ON i.id = s.itemFK + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT' AND s.price > 0; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) +BEGIN + +/** + * Comprueba que los tickets entre un rango de fechas tienen componentes + * y recalcula sus componentes + * + * @param vShippedFrom rango inicial de fecha + * @param vShippedTo rango final de fecha + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.coste + (primary key (id)) ENGINE = MEMORY + SELECT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN saleComponent sc ON sc.saleFk = s.id + JOIN component c ON c.id = sc.componentFk + JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 + WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo + AND ic.merchandise; + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + (primary key (id)) ENGINE = MEMORY + SELECT DISTINCT s.id + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + LEFT JOIN tmp.coste c ON c.id = s.id + WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo + AND c.id IS NULL + AND ic.merchandise; + + CALL sale_recalcComponent('renewPrices'); + + DROP TEMPORARY TABLE tmp.recalculateSales; + DROP TEMPORARY TABLE tmp.coste; + END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( + vTicketFk INT, + vClientFk INT, + vNickname VARCHAR(50), + vAgencyModeFk INT, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk INT, + vCompanyFk INT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) +BEGIN + + /** + * Modifica en el ticket los campos que se le pasan por parámetro + * y cambia sus componentes + * + * @param vTicketFk Id del ticket a modificar + * @param vClientFk nuevo cliente + * @param vNickname nuevo alias + * @param vAgencyModeFk nueva agencia + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo almacen + * @param vCompanyFk nueva empresa + * @param vShipped nueva fecha del envio de mercancia + * @param vLanded nueva fecha de recepcion de mercancia + * @param vIsDeleted si se borra el ticket + * @param vHasToBeUnrouted si se le elimina la ruta al ticket + * @param vOption opcion para el case del proc ticketComponentUpdateSale + */ + + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + + CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.nickname = vNickname, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.zoneFk = vZoneFk, + t.zonePrice = vPrice, + t.zoneBonus = vBonus, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent + SELECT * FROM tmp.ticketComponentPreview; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + + DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; +END$$ +DELIMITER ; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption VARCHAR(25)) +proc: BEGIN + +/** + * Crea tabla temporal para sale_recalcComponent() para recalcular los componentes + * + * @param vSelf Id del ticket + * @param vOption si no se quiere forzar llamar con NULL + */ + + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.ticketFk = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; + +TRUNCATE TABLE `vn`.`ticketUpdateAction`; +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrice'); +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(2, 'Convertir en maná', 'mana'); \ No newline at end of file From 858912021b94f17ce6d40a40574775c6bf90901e Mon Sep 17 00:00:00 2001 From: Alex Moreno Date: Tue, 16 Jan 2024 13:46:24 +0000 Subject: [PATCH 058/116] Delete db/changes/240201/00-saleComponent.sql --- db/changes/240201/00-saleComponent.sql | 589 ------------------------- 1 file changed, 589 deletions(-) delete mode 100644 db/changes/240201/00-saleComponent.sql diff --git a/db/changes/240201/00-saleComponent.sql b/db/changes/240201/00-saleComponent.sql deleted file mode 100644 index 44f9d172c..000000000 --- a/db/changes/240201/00-saleComponent.sql +++ /dev/null @@ -1,589 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption VARCHAR(25)) -proc: BEGIN -/** - * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes - * - * @param vSelf Id de la venta - * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - SELECT s.id - FROM sale s - WHERE s.id = vSelf; - - CALL sale_recalcComponent(vOption); - - DROP TEMPORARY TABLE tmp.recalculateSales; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) -BEGIN -/** - * Comprueba que las ventas creadas entre un rango de fechas tienen componentes - * - * @param vCreatedFrom inicio del rango - * @param vCreatedTo fin del rango - */ - DECLARE v_done BOOL DEFAULT FALSE; - DECLARE vSaleFk INTEGER; - DECLARE vTicketFk INTEGER; - DECLARE vConcept VARCHAR(50); - DECLARE vCur CURSOR FOR - SELECT s.id - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - LEFT JOIN tmp.coste c ON c.id = s.id - WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo - AND c.id IS NULL - AND t.agencyModeFk IS NOT NULL - AND t.isDeleted IS FALSE - AND t.warehouseFk = 60 - AND ic.merchandise != FALSE - GROUP BY s.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; - - DROP TEMPORARY TABLE IF EXISTS tmp.coste; - - DROP TEMPORARY TABLE IF EXISTS tmp.coste; - CREATE TEMPORARY TABLE tmp.coste - (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT s.id - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6 - WHERE s.created >= vCreatedFrom - AND ic.merchandise != FALSE; - - OPEN vCur; - - l: LOOP - SET v_done = FALSE; - FETCH vCur INTO vSaleFk; - - IF v_done THEN - LEAVE l; - END IF; - - SELECT ticketFk, concept - INTO vTicketFk, vConcept - FROM sale - WHERE id = vSaleFk; - - CALL sale_calculateComponent(vSaleFk, 'renewPrices'); - END LOOP; - - CLOSE vCur; - DROP TEMPORARY TABLE tmp.coste; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25)) -proc: BEGIN -/** - * Este procedimiento recalcula los componentes de un conjunto de sales, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vOption si no se quiere forzar llamar con NULL - * @table tmp.recalculateSales (id) - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicketFk INT; - DECLARE vLanded DATE; - DECLARE vIsEditable BOOLEAN; - DECLARE vZoneFk INTEGER; - DECLARE vDone BOOL DEFAULT FALSE; - - DECLARE vCur CURSOR FOR - SELECT DISTINCT s.ticketFk - FROM tmp.recalculateSales rs - JOIN vn.sale s ON s.id = rs.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN vCur; - - l: LOOP - SET vDone = FALSE; - FETCH vCur INTO vTicketFk; - - IF vDone THEN - LEAVE l; - END IF; - - SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, - t.zoneFk, - t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, - t.landed - INTO vIsEditable, - vZoneFk, - vWarehouseFk, - vShipped, - vAddressFk, - vAgencyModeFk, - vLanded - FROM ticket t - LEFT JOIN ticketState ts ON t.id = ts.ticket - LEFT JOIN alertLevel al ON al.id = ts.alertLevel - WHERE t.id = vTicketFk; - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - - IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN - CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); - END IF; - - IF vLanded IS NULL OR vZoneFk IS NULL THEN - - UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) - WHERE t.id = vTicketFk AND t.landed IS NULL; - - IF vZoneFk IS NULL THEN - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - UPDATE ticket t - SET t.zoneFk = vZoneFk - WHERE t.id = vTicketFk AND t.zoneFk IS NULL; - END IF; - - END IF; - - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouseFk warehouseFk - FROM sale s - JOIN tmp.recalculateSales rs ON s.id = rs.id - WHERE s.ticketFk = vTicketFk; - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk - FROM sale s - JOIN tmp.recalculateSales rs ON s.id = rs.id - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - IF vOption IS NULL THEN - SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); - END IF; - - CALL ticketComponentUpdateSale(vOption); - CALL catalog_componentPurge(); - - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.sale; - - END LOOP; - CLOSE vCur; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) -BEGIN -/* - * Recalcula los componentes un ticket clonado, - * las lineas a precio cero fuerza para que tengan precio, el resto lo respeta - * @param vTicketNew nuevo ticket clonado - * @param vTicketOld icket original, a partir del qual se clonara el nuevo -*/ - - REPLACE INTO orderTicket(orderFk,ticketFk) - SELECT orderFk, vTicketNew - FROM orderTicket - WHERE ticketFk = vTicketOld; - - -- Bionizamos lineas con Preu = 0 - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id - FROM sale - WHERE ticketFk = vTicketNew AND price = 0; - - CALL sale_recalcComponent('renewPrices'); - - -- Bionizamos lineas con Preu > 0 - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id - FROM sale - WHERE ticketFk = vTicketNew AND price > 0; - - CALL sale_recalcComponent('imbalance'); - - DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( - vTicketFk INT, - vClientFk INT, - vAgencyModeFk INT, - vAddressFk INT, - vWarehouseFk TINYINT, - vCompanyFk SMALLINT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption VARCHAR(25)) -BEGIN - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t - JOIN address a ON a.id = vAddressFk - SET t.nickname = a.nickname - WHERE t.id = vTicketFk; - END IF; - - UPDATE ticket t - SET - t.clientFk = vClientFk, - t.agencyModeFk = vAgencyModeFk, - t.addressFk = vAddressFk, - t.warehouseFk = vWarehouseFk, - t.companyFk = vCompanyFk, - t.landed = vLanded, - t.shipped = vShipped, - t.isDeleted = vIsDeleted - WHERE - t.id = vTicketFk; - - IF vHasToBeUnrouted THEN - UPDATE ticket t SET t.routeFk = NULL - WHERE t.id = vTicketFk; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - - CALL ticketComponentUpdateSale (vOption); - - DROP TEMPORARY TABLE tmp.sale; - COMMIT; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) -BEGIN -/** - * A partir de la tabla tmp.sale, crea los Movimientos_componentes - * y modifica el campo Preu de la tabla Movimientos - * - * @param i_option integer tipo de actualizacion - * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk - **/ - DECLARE vComponentFk INT; - - IF vCode <> 'renewPrices' THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; - END IF; - - DELETE sc.* - FROM tmp.sale tmps - JOIN saleComponent sc ON sc.saleFk = tmps.saleFk - JOIN `component` c ON c.id = sc.componentFk - WHERE c.isRenewable; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, tc.componentFk, tc.cost - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk - WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); - - -- Añadir componente venta por paquete - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT t.id, t.componentFk, t.cost - FROM ( - SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto - FROM vn.sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id - JOIN vn.buy b ON b.id = buy_id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' - LEFT JOIN ( - SELECT s.id - FROM vn.sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk - JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' - ) tp ON tp.id = s.id - WHERE tp.id IS NULL - HAVING resto <> 0) t; - - IF vCode <> 'renewPrices' THEN - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.saleFk <> vComponentFk - GROUP BY s.id - HAVING dif <> 0; - ELSE - UPDATE sale s - JOIN item i on i.id = s.itemFk - JOIN itemType it on it.id = i.typeFk - JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - GROUP BY sc.saleFk) sc ON sc.saleFk = s.id - SET s.price = sumValue / ((100 - s.discount) / 100) - WHERE it.code != 'PRT' ; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.componentFk != 21 - GROUP BY s.id - HAVING ROUND(saleValue, 4) <> 0; - END IF; - - UPDATE sale s - JOIN ( - SELECT SUM(sc.value) sumValue, sc.saleFk - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - JOIN `component` c ON c.id = sc.componentFk - JOIN componentType ct on ct.id = c.typeFk AND ct.isBase - GROUP BY sc.saleFk) sc ON sc.saleFk = s.id - SET s.priceFixed = sumValue, s.isPriceFixed = 1; - - DELETE sc.* - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - JOIN sale s on s.id = sc.saleFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT'; - - INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 15, s.price - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN item i ON i.id = s.itemFK - JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT' AND s.price > 0; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) -BEGIN - -/** - * Comprueba que los tickets entre un rango de fechas tienen componentes - * y recalcula sus componentes - * - * @param vShippedFrom rango inicial de fecha - * @param vShippedTo rango final de fecha - */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.coste - (primary key (id)) ENGINE = MEMORY - SELECT s.id - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 - WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo - AND ic.merchandise; - - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - (primary key (id)) ENGINE = MEMORY - SELECT DISTINCT s.id - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - LEFT JOIN tmp.coste c ON c.id = s.id - WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo - AND c.id IS NULL - AND ic.merchandise; - - CALL sale_recalcComponent('renewPrices'); - - DROP TEMPORARY TABLE tmp.recalculateSales; - DROP TEMPORARY TABLE tmp.coste; - END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( - vTicketFk INT, - vClientFk INT, - vNickname VARCHAR(50), - vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, - vWarehouseFk INT, - vCompanyFk INT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption VARCHAR(25)) -BEGIN - - /** - * Modifica en el ticket los campos que se le pasan por parámetro - * y cambia sus componentes - * - * @param vTicketFk Id del ticket a modificar - * @param vClientFk nuevo cliente - * @param vNickname nuevo alias - * @param vAgencyModeFk nueva agencia - * @param vAddressFk nuevo consignatario - * @param vZoneFk nueva zona - * @param vWarehouseFk nuevo almacen - * @param vCompanyFk nueva empresa - * @param vShipped nueva fecha del envio de mercancia - * @param vLanded nueva fecha de recepcion de mercancia - * @param vIsDeleted si se borra el ticket - * @param vHasToBeUnrouted si se le elimina la ruta al ticket - * @param vOption opcion para el case del proc ticketComponentUpdateSale - */ - - DECLARE vPrice DECIMAL(10,2); - DECLARE vBonus DECIMAL(10,2); - - CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); - - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t - JOIN address a ON a.id = vAddressFk - SET t.nickname = a.nickname - WHERE t.id = vTicketFk; - - END IF; - - CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); - - SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus - FROM tmp.zoneGetShipped - WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; - - UPDATE ticket t - SET - t.clientFk = vClientFk, - t.nickname = vNickname, - t.agencyModeFk = vAgencyModeFk, - t.addressFk = vAddressFk, - t.zoneFk = vZoneFk, - t.zonePrice = vPrice, - t.zoneBonus = vBonus, - t.warehouseFk = vWarehouseFk, - t.companyFk = vCompanyFk, - t.landed = vLanded, - t.shipped = vShipped, - t.isDeleted = vIsDeleted - WHERE - t.id = vTicketFk; - - IF vHasToBeUnrouted THEN - UPDATE ticket t SET t.routeFk = NULL - WHERE t.id = vTicketFk; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - CREATE TEMPORARY TABLE tmp.ticketComponent - SELECT * FROM tmp.ticketComponentPreview; - - CALL ticketComponentUpdateSale (vOption); - - DROP TEMPORARY TABLE tmp.sale; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - - DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption VARCHAR(25)) -proc: BEGIN - -/** - * Crea tabla temporal para sale_recalcComponent() para recalcular los componentes - * - * @param vSelf Id del ticket - * @param vOption si no se quiere forzar llamar con NULL - */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - SELECT s.id - FROM sale s - WHERE s.ticketFk = vSelf; - - CALL sale_recalcComponent(vOption); - - DROP TEMPORARY TABLE tmp.recalculateSales; -END$$ -DELIMITER ; - -TRUNCATE TABLE `vn`.`ticketUpdateAction`; -INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrice'); -INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(2, 'Convertir en maná', 'mana'); \ No newline at end of file From 30b505aa8fa4f8b0640f3a233acb0d51fe5d4c32 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Jan 2024 08:34:15 +0100 Subject: [PATCH 059/116] refs #6694 feat: add filter for postcodes --- back/models/postcode.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/back/models/postcode.js b/back/models/postcode.js index b08fdaa40..4c1bf7fd7 100644 --- a/back/models/postcode.js +++ b/back/models/postcode.js @@ -1,6 +1,38 @@ let UserError = require('vn-loopback/util/user-error'); module.exports = Self => { + Self.remoteMethod('filter', { + description: + 'Find all postcodes of the model matched by postcode, town, province or country.', + accessType: 'READ', + returns: { + type: ['object'], + root: true, + }, + http: { + path: `/filter`, + verb: 'GET', + }, + }); + Self.filter = async(ctx, filter, options) => { + const {Postcode} = Self.app.models; + let {value} = ctx.where; + let limit = ctx.where?.limit ?? 30; + return await Postcode.rawSql(` + SELECT pc.code, t.name as town, p.name as province , c.country + FROM postCode pc + JOIN town t on t.id = pc.townFk + JOIN province p on p.id = t.provinceFk + JOIN country c on c.id = p.countryFk + WHERE + pc.code like '%${value}%' + or t.name like '%${value}%' + or p.name like '%${value}%' + or c.country like '%${value}%' + LIMIT ${limit} + `); + }; + Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') return new UserError(`This postcode already exists`); From d47429b4a7db95f8d549ac858652288f218dca71 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 10:01:38 +0100 Subject: [PATCH 060/116] refs #6667 sql --- modules/worker/back/methods/worker/search.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 7fe9e0666..2cef3543b 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -41,13 +41,15 @@ module.exports = Self => { } const stmt = new ParameterizedSQL(` - SELECT * - FROM( - SELECT DISTINCT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk - FROM worker w - JOIN account.user u ON u.id = w.id - LEFT JOIN business b ON b.workerFk = w.id - ) w`); + SELECT * + FROM( + SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk + FROM worker w + JOIN account.user u ON u.id = w.id + LEFT JOIN business b ON b.workerFk = w.id + ORDER BY b.id DESC + ) w + GROUP BY w.id`); stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); From 21ce57d21701d99a2446be7de0c1d791f9e061ea Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Jan 2024 10:31:07 +0100 Subject: [PATCH 061/116] refs #6174 feat: update back to separate invoice and pdf --- .../back/methods/invoiceOut/makePdfList.js | 30 +++++++++++++ .../methods/invoiceOut/transferInvoice.js | 14 +++--- modules/invoiceOut/back/models/invoice-out.js | 1 + .../back/methods/ticket/invoiceTickets.js | 8 +--- .../methods/ticket/invoiceTicketsAndPdf.js | 44 +++++++++++++++++++ .../ticket/specs/invoiceTickets.spec.js | 2 +- modules/ticket/back/models/ticket-methods.js | 1 + 7 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 modules/invoiceOut/back/methods/invoiceOut/makePdfList.js create mode 100644 modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js diff --git a/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js b/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js new file mode 100644 index 000000000..cf041ee17 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js @@ -0,0 +1,30 @@ + +module.exports = Self => { + Self.remoteMethodCtx('makePdfList', { + description: 'Handle a list of invoices to generate PDF and send it to client', + accessType: 'WRITE', + accepts: [ + { + arg: 'ids', + type: ['number'], + description: 'The invoice id', + required: true, + http: {source: 'path'} + }, { + arg: 'printerFk', + type: 'number', + description: 'The printer to print' + } + ], + http: { + path: '/:id/makePdfList', + verb: 'POST' + } + }); + + Self.makePdfList = async function(ctx, ids, printerFk, options) { + ids.forEach(async id => { + await Self.makePdfAndNotify(ctx, id, printerFk, options); + }); + }; +}; diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index 3372c84dd..8e234d7cc 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -50,7 +50,6 @@ module.exports = Self => { Self.transferInvoice = async(ctx, options) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; - let makePdf = false; const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args; let tx; if (typeof options == 'object') @@ -64,7 +63,6 @@ module.exports = Self => { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; - makePdf = true; } try { const filterRef = {where: {refFk: refFk}}; @@ -88,16 +86,18 @@ module.exports = Self => { clonedTicketIds.push(clonedTicket.id); } - const invoiceCorrection = - {correctedFk: id, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk}; + const invoiceCorrection = { + correctedFk: id, + cplusRectificationTypeFk, + siiTypeInvoiceOutFk, + invoiceCorrectionTypeFk + }; const refundTicketIds = refundTickets.map(ticket => ticket.id); await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); - const [invoiceId] = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions); - tx && await tx.commit(); + const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions); - makePdf && await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); return invoiceId; } catch (e) { if (tx) await tx.rollback(); diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index ca77c856f..91f4883ad 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -13,6 +13,7 @@ module.exports = Self => { require('../methods/invoiceOut/createManualInvoice')(Self); require('../methods/invoiceOut/clientsToInvoice')(Self); require('../methods/invoiceOut/invoiceClient')(Self); + require('../methods/invoiceOut/makePdfList')(Self); require('../methods/invoiceOut/makePdfAndNotify')(Self); require('../methods/invoiceOut/refund')(Self); require('../methods/invoiceOut/invoiceEmail')(Self); diff --git a/modules/ticket/back/methods/ticket/invoiceTickets.js b/modules/ticket/back/methods/ticket/invoiceTickets.js index 162ddda03..53400e724 100644 --- a/modules/ticket/back/methods/ticket/invoiceTickets.js +++ b/modules/ticket/back/methods/ticket/invoiceTickets.js @@ -32,7 +32,6 @@ module.exports = function(Self) { const models = Self.app.models; const date = Date.vnNew(); date.setHours(0, 0, 0, 0); - let makePdf = false; const myOptions = {userId: ctx.req.accessToken.userId}; let tx; @@ -43,7 +42,6 @@ module.exports = function(Self) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; - makePdf = true; } let invoicesIds = []; @@ -78,15 +76,11 @@ module.exports = function(Self) { for (const ticketIds of ticketsByAddress) invoicesIds.push(await createInvoice(ctx, companyId, ticketIds, invoiceCorrection, myOptions)); - if (tx) await tx.commit(); + tx && await tx.commit(); } catch (e) { if (tx) await tx.rollback(); throw e; } - if (makePdf) { - for (const invoiceId of invoicesIds) - await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); - } return invoicesIds; }; diff --git a/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js b/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js new file mode 100644 index 000000000..3831854a7 --- /dev/null +++ b/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js @@ -0,0 +1,44 @@ + +module.exports = function(Self) { + Self.remoteMethodCtx('invoiceTicketsAndPdf', { + description: 'Make out an invoice from one or more tickets', + accessType: 'WRITE', + accepts: [ + { + arg: 'ticketsIds', + description: 'The tickets id', + type: ['number'], + required: true + }, + { + arg: 'invoiceCorrection', + description: 'The invoice correction', + type: 'object', + } + + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/invoiceTicketsAndPdf`, + verb: 'POST' + } + }); + + Self.invoiceTicketsAndPdf = async(ctx, ticketsIds, invoiceCorrection, options) => { + let invoiceIds = null; + + try { + invoiceIds = await Self.invoiceTickets(ctx, ticketsIds, invoiceCorrection, options); + if (!invoiceIds) return []; + if (!options.transaction) + await Self.app.models.InvoiceOut.makePdfList(ctx, invoiceIds, null, options); + return invoiceIds; + } catch (error) { + return []; + } + }; +}; + diff --git a/modules/ticket/back/methods/ticket/specs/invoiceTickets.spec.js b/modules/ticket/back/methods/ticket/specs/invoiceTickets.spec.js index 162dc066a..7d511cfd2 100644 --- a/modules/ticket/back/methods/ticket/specs/invoiceTickets.spec.js +++ b/modules/ticket/back/methods/ticket/specs/invoiceTickets.spec.js @@ -102,7 +102,7 @@ describe('ticket invoiceTickets()', () => { const options = {transaction: tx}; const ticketsIds = [11]; - const invoicesIds = await models.Ticket.invoiceTickets(ctx, ticketsIds, null, options); + const invoicesIds = await models.Ticket.invoiceTicketsAndPdf(ctx, ticketsIds, null, options); expect(invoicesIds.length).toBeGreaterThan(0); diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 14cb104be..ce54959e7 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -42,5 +42,6 @@ module.exports = function(Self) { require('../methods/ticket/expeditionPalletLabel')(Self); require('../methods/ticket/saveSign')(Self); require('../methods/ticket/invoiceTickets')(Self); + require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/docuwareDownload')(Self); }; From d1a3c67d2ea296971c4f7390be827cfe554ff2f9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 14:07:04 +0100 Subject: [PATCH 062/116] refs #6667 fix limit --- modules/worker/back/methods/worker/search.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 2cef3543b..e423f660d 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -42,14 +42,15 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT * - FROM( - SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk - FROM worker w - JOIN account.user u ON u.id = w.id - LEFT JOIN business b ON b.workerFk = w.id - ORDER BY b.id DESC - ) w - GROUP BY w.id`); + FROM( + SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk + FROM worker w + JOIN account.user u ON u.id = w.id + LEFT JOIN business b ON b.workerFk = w.id + ORDER BY b.id DESC + LIMIT 10000000000000000000 + ) w + GROUP BY w.id`); stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); From 75259984771994568b67a906ef36a2ad320e6656 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 14:13:09 +0100 Subject: [PATCH 063/116] refs #6296 postal code --- modules/client/front/address/index/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/client/front/address/index/index.html b/modules/client/front/address/index/index.html index 989ce13a9..ef3da4051 100644 --- a/modules/client/front/address/index/index.html +++ b/modules/client/front/address/index/index.html @@ -47,6 +47,7 @@
{{::address.nickname}} - #{{::address.id}}
{{::address.street}}
+ {{::address.postalCode}} - {{::address.city}}, {{::address.province.name}}, {{::address.province.country.country}} From 71f387f626add3952755e0c83b6ead88bd435941 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Jan 2024 14:15:21 +0100 Subject: [PATCH 064/116] refs #6694 feat: move filter remote method to own file --- back/methods/postcode/filter.js | 34 +++++++++++++++++++++++++++++++++ back/models/postcode.js | 33 +------------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) create mode 100644 back/methods/postcode/filter.js diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js new file mode 100644 index 000000000..53f25b7d4 --- /dev/null +++ b/back/methods/postcode/filter.js @@ -0,0 +1,34 @@ + +module.exports = Self => { + Self.remoteMethod('filter', { + description: + 'Find all postcodes of the model matched by postcode, town, province or country.', + accessType: 'READ', + returns: { + type: ['object'], + root: true, + }, + http: { + path: `/filter`, + verb: 'GET', + }, + }); + Self.filter = async(ctx, filter, options) => { + const {Postcode} = Self.app.models; + let {value} = ctx.where; + let limit = ctx.where?.limit ?? 30; + return await Postcode.rawSql(` + SELECT pc.code, t.name as town, p.name as province , c.country + FROM postCode pc + JOIN town t on t.id = pc.townFk + JOIN province p on p.id = t.provinceFk + JOIN country c on c.id = p.countryFk + WHERE + pc.code like '%${value}%' + or t.name like '%${value}%' + or p.name like '%${value}%' + or c.country like '%${value}%' + LIMIT ${limit} + `); + }; +}; diff --git a/back/models/postcode.js b/back/models/postcode.js index 4c1bf7fd7..63fd0657f 100644 --- a/back/models/postcode.js +++ b/back/models/postcode.js @@ -1,38 +1,7 @@ let UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethod('filter', { - description: - 'Find all postcodes of the model matched by postcode, town, province or country.', - accessType: 'READ', - returns: { - type: ['object'], - root: true, - }, - http: { - path: `/filter`, - verb: 'GET', - }, - }); - Self.filter = async(ctx, filter, options) => { - const {Postcode} = Self.app.models; - let {value} = ctx.where; - let limit = ctx.where?.limit ?? 30; - return await Postcode.rawSql(` - SELECT pc.code, t.name as town, p.name as province , c.country - FROM postCode pc - JOIN town t on t.id = pc.townFk - JOIN province p on p.id = t.provinceFk - JOIN country c on c.id = p.countryFk - WHERE - pc.code like '%${value}%' - or t.name like '%${value}%' - or p.name like '%${value}%' - or c.country like '%${value}%' - LIMIT ${limit} - `); - }; - + require('../methods/postcode/filter.js')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_DUP_ENTRY') return new UserError(`This postcode already exists`); From 92a3e841ed3fe6ec34ea6ff44339808bd6a71e30 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Jan 2024 14:16:09 +0100 Subject: [PATCH 065/116] refs #6694 perf: change let to const --- back/methods/postcode/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 53f25b7d4..0c97c61c5 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -15,8 +15,8 @@ module.exports = Self => { }); Self.filter = async(ctx, filter, options) => { const {Postcode} = Self.app.models; - let {value} = ctx.where; - let limit = ctx.where?.limit ?? 30; + const {value} = ctx.where; + const limit = ctx.where?.limit ?? 30; return await Postcode.rawSql(` SELECT pc.code, t.name as town, p.name as province , c.country FROM postCode pc From 41aa5ff2f72f7a78750f422add47902028dbcf4b Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 17 Jan 2024 14:24:07 +0100 Subject: [PATCH 066/116] refs #6222 --- db/changes/240201/00-saleComponent.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/240201/00-saleComponent.sql b/db/changes/240201/00-saleComponent.sql index 44f9d172c..2e1021000 100644 --- a/db/changes/240201/00-saleComponent.sql +++ b/db/changes/240201/00-saleComponent.sql @@ -141,7 +141,7 @@ proc: BEGIN vAgencyModeFk, vLanded FROM ticket t - LEFT JOIN ticketState ts ON t.id = ts.ticket + LEFT JOIN ticketState ts ON t.id = ts.ticketFk LEFT JOIN alertLevel al ON al.id = ts.alertLevel WHERE t.id = vTicketFk; From ccdef0458a566849a5381e6357a39843cfe508e3 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 17 Jan 2024 14:39:11 +0100 Subject: [PATCH 067/116] refs #6667 fix groupBy --- modules/worker/back/methods/worker/search.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index e423f660d..59348a9ce 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -49,10 +49,14 @@ module.exports = Self => { LEFT JOIN business b ON b.workerFk = w.id ORDER BY b.id DESC LIMIT 10000000000000000000 - ) w - GROUP BY w.id`); + ) w`); + + stmt.merge(conn.makeSuffix(filter.fields)); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(conn.makeGroupBy('w.id')); + stmt.merge(conn.makeOrderBy(filter.order)); + stmt.merge(conn.makeLimit(filter.limit)); - stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); }; From 38c93e8c769ad79387b6a0e30bb92e036a7ffb7a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Jan 2024 14:49:35 +0100 Subject: [PATCH 068/116] refs #6694 test: add test --- back/methods/postcode/filter.js | 67 +++++++++++--- back/methods/postcode/specs/filter.spec.js | 103 +++++++++++++++++++++ 2 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 back/methods/postcode/specs/filter.spec.js diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 0c97c61c5..dcf11f80b 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -1,3 +1,6 @@ +const {ParameterizedSQL} = require('loopback-connector'); +const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); +// const {models} = require('vn-loopback/server/server'); module.exports = Self => { Self.remoteMethod('filter', { @@ -8,27 +11,67 @@ module.exports = Self => { type: ['object'], root: true, }, + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, + { + arg: 'search', + type: 'string', + description: 'Value to filter', + http: {source: 'query'} + }, + ], http: { path: `/filter`, verb: 'GET', }, }); Self.filter = async(ctx, filter, options) => { - const {Postcode} = Self.app.models; - const {value} = ctx.where; - const limit = ctx.where?.limit ?? 30; - return await Postcode.rawSql(` - SELECT pc.code, t.name as town, p.name as province , c.country - FROM postCode pc + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const conn = Self.dataSource.connector; + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'search': + return {or: [ + {'pc.code': {like: `%${value}%`}}, + {'t.name': {like: `%${value}%`}}, + {'p.name': {like: `%${value}%`}}, + {'c.country': {like: `%${value}%`}} + ] + }; + } + }) ?? {}; + + filter = mergeFilters(ctx.args.filter, {where}); + + const stmts = []; + let stmt; + stmt = new ParameterizedSQL(` + SELECT + pc.code, + t.name as town, + p.name as province, + c.country + FROM + postCode pc JOIN town t on t.id = pc.townFk JOIN province p on p.id = t.provinceFk JOIN country c on c.id = p.countryFk - WHERE - pc.code like '%${value}%' - or t.name like '%${value}%' - or p.name like '%${value}%' - or c.country like '%${value}%' - LIMIT ${limit} `); + + stmt.merge(conn.makeSuffix(filter)); + const itemsIndex = stmts.push(stmt) - 1; + + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql, myOptions); + return itemsIndex === 0 ? result : result[itemsIndex]; }; }; diff --git a/back/methods/postcode/specs/filter.spec.js b/back/methods/postcode/specs/filter.spec.js new file mode 100644 index 000000000..c393b629a --- /dev/null +++ b/back/methods/postcode/specs/filter.spec.js @@ -0,0 +1,103 @@ +const {models} = require('vn-loopback/server/server'); + +describe('Postcode filter()', () => { + it('should retrieve with no filter', async() => { + const tx = await models.Postcode.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + + }, + }; + const results = await models.Postcode.filter(ctx, options); + + expect(results.length).toBeGreaterThan(0); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should retrieve with filter as postcode', async() => { + const tx = await models.Postcode.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: 46, + }, + }; + const results = await models.Postcode.filter(ctx, options); + + expect(results.length).toEqual(4); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should retrieve with filter as city', async() => { + const tx = await models.Postcode.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: 'Alz', + }, + }; + const results = await models.Postcode.filter(ctx, options); + + expect(results.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should retrieve with filter as province', async() => { + const tx = await models.Postcode.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: 'one', + }, + }; + const results = await models.Postcode.filter(ctx, options); + + expect(results.length).toEqual(4); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should retrieve with filter as country', async() => { + const tx = await models.Postcode.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: 'Ec', + }, + }; + const results = await models.Postcode.filter(ctx, options); + + expect(results.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); From 145e72022a76e4686f711c3f7b4915218e849707 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Jan 2024 14:58:55 +0100 Subject: [PATCH 069/116] refs #6694 perf: handle minor errors --- back/methods/postcode/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index dcf11f80b..9986a16c9 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -50,7 +50,7 @@ module.exports = Self => { } }) ?? {}; - filter = mergeFilters(ctx.args.filter, {where}); + filter = mergeFilters(ctx.args?.filter ?? {}, {where}); const stmts = []; let stmt; From dfee2b0ce450e34440f9c42d181a2faa33762dc7 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 Jan 2024 10:39:12 +0100 Subject: [PATCH 070/116] refs #6718 fix: loggable and sql --- db/changes/240401/00-revokeItem.sql | 2 +- db/changes/{240201 => 240401}/00-ticketSmsToClientSms.sql | 0 .../{235001 => 240401}/00-updateACL_Role_VnRole.sql | 2 +- db/changes/240401/01-saleGroupDetailDefaultSize.sql | 4 ++-- db/changes/240401/01-supplierAccount.sql | 8 ++++---- db/changes/240401/02-invoiceOutConfig_refLen.sql | 2 +- loopback/server/connectors/vn-mysql.js | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) rename db/changes/{240201 => 240401}/00-ticketSmsToClientSms.sql (100%) rename db/changes/{235001 => 240401}/00-updateACL_Role_VnRole.sql (59%) diff --git a/db/changes/240401/00-revokeItem.sql b/db/changes/240401/00-revokeItem.sql index 2b75d67cf..5f6a30620 100644 --- a/db/changes/240401/00-revokeItem.sql +++ b/db/changes/240401/00-revokeItem.sql @@ -1,4 +1,4 @@ REVOKE UPDATE ON TABLE `vn`.`item` FROM `employee`; -GRANT UPDATE(id, equivalent, stems, minPrice, isToPrint, family, box, category, doPhoto, image, inkFk, intrastatFk, hasMinPrice, created, comment, typeFk, generic, producerFk, description, density, relevancy, expenseFk, isActive, subName, tag5, value5, tag6, value6, tag7, value7, tag8, value8, tag9, value9, tag10, value10, minimum, upToDown, supplyResponseFk, hasKgPrice, isFloramondo, isFragile, numberOfItemsPerCask, embalageCode, quality, stemMultiplier, itemPackingTypeFk, packingOut, genericFk, packingShelve, isLaid, lastUsed, weightByPiece, weightByPiece, editorFk, recycledPlastic, nonRecycledPlastic, minQuantity) ON TABLE vn.item TO employee; +GRANT UPDATE(id, equivalent, stems, minPrice, isToPrint, family, box, category, doPhoto, image, inkFk, intrastatFk, hasMinPrice, created, comment, typeFk, generic, producerFk, description, density, relevancy, expenseFk, isActive, subName, tag5, value5, tag6, value6, tag7, value7, tag8, value8, tag9, value9, tag10, value10, minimum, upToDown, supplyResponseFk, hasKgPrice, isFloramondo, isFragile, numberOfItemsPerCask, embalageCode, quality, stemMultiplier, itemPackingTypeFk, packingOut, genericFk, packingShelve, isLaid, lastUsed, weightByPiece, weightByPiece, editorFk, recycledPlastic, nonRecycledPlastic, minQuantity) ON TABLE `vn`.`item` TO `employee`; diff --git a/db/changes/240201/00-ticketSmsToClientSms.sql b/db/changes/240401/00-ticketSmsToClientSms.sql similarity index 100% rename from db/changes/240201/00-ticketSmsToClientSms.sql rename to db/changes/240401/00-ticketSmsToClientSms.sql diff --git a/db/changes/235001/00-updateACL_Role_VnRole.sql b/db/changes/240401/00-updateACL_Role_VnRole.sql similarity index 59% rename from db/changes/235001/00-updateACL_Role_VnRole.sql rename to db/changes/240401/00-updateACL_Role_VnRole.sql index b08a44138..5d108ac44 100644 --- a/db/changes/235001/00-updateACL_Role_VnRole.sql +++ b/db/changes/240401/00-updateACL_Role_VnRole.sql @@ -1,4 +1,4 @@ -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) VALUES +INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) VALUES ('VnRole','*','READ','ALLOW','ROLE','employee'), ('VnRole','*','WRITE','ALLOW','ROLE','it'); diff --git a/db/changes/240401/01-saleGroupDetailDefaultSize.sql b/db/changes/240401/01-saleGroupDetailDefaultSize.sql index 12f17c5e7..34529ba78 100644 --- a/db/changes/240401/01-saleGroupDetailDefaultSize.sql +++ b/db/changes/240401/01-saleGroupDetailDefaultSize.sql @@ -1,2 +1,2 @@ -ALTER TABLE vn.productionConfig ADD itemPreviousDefaultSize int NULL COMMENT 'Altura por defecto para los artículos de previa'; -UPDATE IGNORE vn.productionConfig SET itemPreviousDefaultSize = 40 WHERE id = 1; +ALTER TABLE `vn`.`productionConfig` ADD itemPreviousDefaultSize int NULL COMMENT 'Altura por defecto para los artículos de previa'; +UPDATE IGNORE `vn`.`productionConfig` SET itemPreviousDefaultSize = 40 WHERE id = 1; diff --git a/db/changes/240401/01-supplierAccount.sql b/db/changes/240401/01-supplierAccount.sql index 1c0f1ef43..21ce7c71e 100644 --- a/db/changes/240401/01-supplierAccount.sql +++ b/db/changes/240401/01-supplierAccount.sql @@ -1,9 +1,9 @@ -UPDATE vn.supplierAccount sa - JOIN vn.country c ON sa.countryFk = c.id AND c.code = 'FR' +UPDATE `vn`.`supplierAccount` sa + JOIN `vn`.`country` c ON sa.countryFk = c.id AND c.code = 'FR' SET countryFk = c.id WHERE iban = 'FR7630003012690002801121597'; -UPDATE vn.supplierAccount sa - JOIN vn.country c ON sa.countryFk = c.id AND c.code = 'PT' +UPDATE `vn`.`supplierAccount` sa + JOIN `vn`.`country` c ON sa.countryFk = c.id AND c.code = 'PT' SET countryFk = c.id WHERE iban = 'PT50001000005813059150168'; diff --git a/db/changes/240401/02-invoiceOutConfig_refLen.sql b/db/changes/240401/02-invoiceOutConfig_refLen.sql index 8b91889f2..a5f5c2088 100644 --- a/db/changes/240401/02-invoiceOutConfig_refLen.sql +++ b/db/changes/240401/02-invoiceOutConfig_refLen.sql @@ -1,2 +1,2 @@ -ALTER TABLE vn.invoiceOutConfig +ALTER TABLE `vn`.`invoiceOutConfig` ADD IF NOT EXISTS refLen TINYINT UNSIGNED DEFAULT 5 NOT NULL COMMENT 'Invoice reference identifier length'; diff --git a/loopback/server/connectors/vn-mysql.js b/loopback/server/connectors/vn-mysql.js index 40ad78bde..1f7169501 100644 --- a/loopback/server/connectors/vn-mysql.js +++ b/loopback/server/connectors/vn-mysql.js @@ -270,8 +270,8 @@ class VnMySQL extends MySQL { isLoggable(model) { const Model = this.getModelDefinition(model).model; - const settings = Model.definition.settings; - return settings.base && settings.base === 'Loggable'; + const {settings} = Model.definition; + return settings?.mixins?.Loggable; } invokeMethod(method, args, model, ctx, opts, cb) { @@ -291,7 +291,7 @@ class VnMySQL extends MySQL { } try { - const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId; + const userId = opts.httpCtx && opts.httpCtx.active?.accessToken?.userId; if (userId) { const user = await Model.app.models.VnUser.findById(userId, {fields: ['name']}, opts); await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts); From 0a98cd7b23d9fd3f6e3dcd577f440d16e6d91443 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 Jan 2024 10:43:58 +0100 Subject: [PATCH 071/116] refs #6718 deploy: init version 24.06 --- CHANGELOG.md | 7 +++++++ db/changes/240601/.gitkeep | 0 package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 db/changes/240601/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index 69e93a309..29df75827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2406.01] - 2024-02-08 + +### Added +### Changed +### Fixed + + ## [2404.01] - 2024-01-25 ### Added diff --git a/db/changes/240601/.gitkeep b/db/changes/240601/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package-lock.json b/package-lock.json index 36e11dc8f..4a8aa4fb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "salix-back", - "version": "24.04.01", + "version": "24.06.01", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "salix-back", - "version": "24.04.01", + "version": "24.06.01", "license": "GPL-3.0", "dependencies": { "axios": "^1.2.2", diff --git a/package.json b/package.json index f13c44162..ba8006e8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.04.01", + "version": "24.06.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 2415e22258484508b1c303885e1562b41c3af7bc Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 18 Jan 2024 14:25:48 +0100 Subject: [PATCH 072/116] refs #6222 fix: apply sql --- db/changes/{240202 => 240402}/00-saleComponent.sql | 0 loopback/server/connectors/vn-mysql.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename db/changes/{240202 => 240402}/00-saleComponent.sql (100%) diff --git a/db/changes/240202/00-saleComponent.sql b/db/changes/240402/00-saleComponent.sql similarity index 100% rename from db/changes/240202/00-saleComponent.sql rename to db/changes/240402/00-saleComponent.sql diff --git a/loopback/server/connectors/vn-mysql.js b/loopback/server/connectors/vn-mysql.js index 1f7169501..737fd94d5 100644 --- a/loopback/server/connectors/vn-mysql.js +++ b/loopback/server/connectors/vn-mysql.js @@ -271,7 +271,7 @@ class VnMySQL extends MySQL { isLoggable(model) { const Model = this.getModelDefinition(model).model; const {settings} = Model.definition; - return settings?.mixins?.Loggable; + return settings.mixins?.Loggable; } invokeMethod(method, args, model, ctx, opts, cb) { From 3be194356fee6497194aca25714d122bf2a59dad Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 19 Jan 2024 09:31:25 +0100 Subject: [PATCH 073/116] fix expense --- modules/item/front/basic-data/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index bcb78c48e..af76d5966 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -117,7 +117,7 @@ url="Expenses" label="Expense" ng-model="$ctrl.item.expenseFk" - vn-name="expence" + vn-name="expense" initial-data="$ctrl.item.expense"> From 0f104e54103580f8b879bbfef21227496533c397 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 19 Jan 2024 10:11:33 +0100 Subject: [PATCH 074/116] refs #6667 view workerDepartment --- modules/worker/back/methods/worker/search.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/worker/back/methods/worker/search.js b/modules/worker/back/methods/worker/search.js index 59348a9ce..07bdfe240 100644 --- a/modules/worker/back/methods/worker/search.js +++ b/modules/worker/back/methods/worker/search.js @@ -43,19 +43,13 @@ module.exports = Self => { const stmt = new ParameterizedSQL(` SELECT * FROM( - SELECT w.id, w.code, u.name, u.nickname, u.active, b.departmentFk + SELECT w.id, w.code, u.name, u.nickname, u.active, wd.departmentFk FROM worker w JOIN account.user u ON u.id = w.id - LEFT JOIN business b ON b.workerFk = w.id - ORDER BY b.id DESC - LIMIT 10000000000000000000 + LEFT JOIN workerDepartment wd ON wd.workerFk = w.id ) w`); - stmt.merge(conn.makeSuffix(filter.fields)); - stmt.merge(conn.makeWhere(filter.where)); - stmt.merge(conn.makeGroupBy('w.id')); - stmt.merge(conn.makeOrderBy(filter.order)); - stmt.merge(conn.makeLimit(filter.limit)); + stmt.merge(conn.makeSuffix(filter)); return conn.executeStmt(stmt); }; From d1692c51d73cf018ddfa5dc4cf9b1a578e9f9da6 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 22 Jan 2024 10:21:06 +0100 Subject: [PATCH 075/116] refs #5483 myt updated --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1316a2cc3..f27802ac1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.23", + "@verdnatura/myt": "^1.5.28", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.23", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.23.tgz", - "integrity": "sha512-gqMLcnFgAW0pqekEkWa069ySBWI+j5Q3Mtll7IIaBCl8OSUWqC6/EMuGg/2X2i9RjhMuCHzOnz+yMKrBE4vX/w==", + "version": "1.5.28", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.28.tgz", + "integrity": "sha512-weIUwj1zR1ZzreidHeIvCNfOUnpJfuag3+J71U4Y7/HasTxY42iBDqU4zJEestHB1kp3dTYqyOSJZ2mVU/rdVQ==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.23", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.23.tgz", - "integrity": "sha512-gqMLcnFgAW0pqekEkWa069ySBWI+j5Q3Mtll7IIaBCl8OSUWqC6/EMuGg/2X2i9RjhMuCHzOnz+yMKrBE4vX/w==", + "version": "1.5.28", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.28.tgz", + "integrity": "sha512-weIUwj1zR1ZzreidHeIvCNfOUnpJfuag3+J71U4Y7/HasTxY42iBDqU4zJEestHB1kp3dTYqyOSJZ2mVU/rdVQ==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 0c9d518e6..40015a305 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.23", + "@verdnatura/myt": "^1.5.28", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 39453492a0a55a3f880adeb1bbf2503dd0e94489 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 22 Jan 2024 10:22:21 +0100 Subject: [PATCH 076/116] refs #2687 feat update db/change version --- .../00-update_procedure_TravelCloneWithEntries.sql | 0 db/changes/{240201 => 240601}/00-util_tx_commit.sql | 0 db/changes/{240201 => 240601}/00-util_tx_rollback.sql | 0 db/changes/{240201 => 240601}/00-util_tx_start.sql | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename db/changes/{240201 => 240601}/00-update_procedure_TravelCloneWithEntries.sql (100%) rename db/changes/{240201 => 240601}/00-util_tx_commit.sql (100%) rename db/changes/{240201 => 240601}/00-util_tx_rollback.sql (100%) rename db/changes/{240201 => 240601}/00-util_tx_start.sql (100%) diff --git a/db/changes/240201/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql similarity index 100% rename from db/changes/240201/00-update_procedure_TravelCloneWithEntries.sql rename to db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql diff --git a/db/changes/240201/00-util_tx_commit.sql b/db/changes/240601/00-util_tx_commit.sql similarity index 100% rename from db/changes/240201/00-util_tx_commit.sql rename to db/changes/240601/00-util_tx_commit.sql diff --git a/db/changes/240201/00-util_tx_rollback.sql b/db/changes/240601/00-util_tx_rollback.sql similarity index 100% rename from db/changes/240201/00-util_tx_rollback.sql rename to db/changes/240601/00-util_tx_rollback.sql diff --git a/db/changes/240201/00-util_tx_start.sql b/db/changes/240601/00-util_tx_start.sql similarity index 100% rename from db/changes/240201/00-util_tx_start.sql rename to db/changes/240601/00-util_tx_start.sql From e86e8045197fdb4c3b5e3c54db8ae6493c2625fd Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 22 Jan 2024 17:32:07 +0100 Subject: [PATCH 077/116] fix: refs #5483 myt updated --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f27802ac1..f2ffd77bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.28", + "@verdnatura/myt": "^1.5.29", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.28", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.28.tgz", - "integrity": "sha512-weIUwj1zR1ZzreidHeIvCNfOUnpJfuag3+J71U4Y7/HasTxY42iBDqU4zJEestHB1kp3dTYqyOSJZ2mVU/rdVQ==", + "version": "1.5.29", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.29.tgz", + "integrity": "sha512-d8PiGjjEQpEu4MyddRXGgay9gLOsD8V2SBxLws748g1WpECETJUZF8I8YKf/jH4Y91f1bFmW9kJn/PR+gA44ww==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.28", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.28.tgz", - "integrity": "sha512-weIUwj1zR1ZzreidHeIvCNfOUnpJfuag3+J71U4Y7/HasTxY42iBDqU4zJEestHB1kp3dTYqyOSJZ2mVU/rdVQ==", + "version": "1.5.29", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.29.tgz", + "integrity": "sha512-d8PiGjjEQpEu4MyddRXGgay9gLOsD8V2SBxLws748g1WpECETJUZF8I8YKf/jH4Y91f1bFmW9kJn/PR+gA44ww==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 40015a305..343b321c6 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.28", + "@verdnatura/myt": "^1.5.29", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From c1bc2c94a6ae782aa969e8bb00e5b8e26e1afdd9 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 23 Jan 2024 08:33:15 +0100 Subject: [PATCH 078/116] refs #2687 perf: generate comments --- db/changes/240601/00-util_tx_commit.sql | 5 +++++ db/changes/240601/00-util_tx_rollback.sql | 5 +++++ db/changes/240601/00-util_tx_start.sql | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/db/changes/240601/00-util_tx_commit.sql b/db/changes/240601/00-util_tx_commit.sql index 036909ed5..ebf3ffdb4 100644 --- a/db/changes/240601/00-util_tx_commit.sql +++ b/db/changes/240601/00-util_tx_commit.sql @@ -2,6 +2,11 @@ DROP PROCEDURE IF EXISTS util.tx_commit; DELIMITER $$ $$ +/* +Procedimiento para confirmar los cambios asociados a una transacción + * @param tx BOOL es true si existe transacción asociada +*/ + CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) BEGIN IF tx THEN diff --git a/db/changes/240601/00-util_tx_rollback.sql b/db/changes/240601/00-util_tx_rollback.sql index ff27601b8..7be817ebc 100644 --- a/db/changes/240601/00-util_tx_rollback.sql +++ b/db/changes/240601/00-util_tx_rollback.sql @@ -2,6 +2,11 @@ DROP PROCEDURE IF EXISTS util.tx_rollback; DELIMITER $$ $$ +/* +Procedimiento para deshacer los cambios asociados a una transacción + * @param tx BOOL es true si existe transacción asociada +*/ + CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) BEGIN IF tx THEN diff --git a/db/changes/240601/00-util_tx_start.sql b/db/changes/240601/00-util_tx_start.sql index ac7c94f27..7d2c8a2b5 100644 --- a/db/changes/240601/00-util_tx_start.sql +++ b/db/changes/240601/00-util_tx_start.sql @@ -2,6 +2,11 @@ DROP PROCEDURE IF EXISTS util.tx_start; DELIMITER $$ $$ +/* +Procedimiento para iniciar una transacción + * @param tx BOOL es true si existe transacción asociada +*/ + CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) BEGIN IF tx THEN From fe714aef220bff5b10a06631cf131a1e7e5119ac Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 23 Jan 2024 11:20:27 +0100 Subject: [PATCH 079/116] refs #2687 perf: change variable description --- .../240601/00-update_procedure_TravelCloneWithEntries.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql b/db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql index 7d04096e3..b0c177b9a 100644 --- a/db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql +++ b/db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql @@ -17,7 +17,7 @@ BEGIN * @param vTravelFk travel plantilla a clonar * @param vDateStart fecha del shipment del nuevo travel * @param vDateEnd fecha del landing del nuevo travel - * @param vWarehouseOutFk fecha del salida del nuevo travel + * @param vWarehouseOutFk warehouse del salida del nuevo travel * @param vWarehouseInFk warehouse de landing del nuevo travel * @param vRef referencia del nuevo travel * @param vAgencyModeFk del nuevo travel From 056dddd21229f2c8911c0917555e24bea5a254ad Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 23 Jan 2024 11:22:59 +0100 Subject: [PATCH 080/116] refs #2687 perf: generate comments --- db/changes/240601/00-util_tx_commit.sql | 5 +++-- db/changes/240601/00-util_tx_rollback.sql | 5 +++-- db/changes/240601/00-util_tx_start.sql | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/db/changes/240601/00-util_tx_commit.sql b/db/changes/240601/00-util_tx_commit.sql index ebf3ffdb4..47e782987 100644 --- a/db/changes/240601/00-util_tx_commit.sql +++ b/db/changes/240601/00-util_tx_commit.sql @@ -2,8 +2,9 @@ DROP PROCEDURE IF EXISTS util.tx_commit; DELIMITER $$ $$ -/* -Procedimiento para confirmar los cambios asociados a una transacción +/** + * Procedimiento para confirmar los cambios asociados a una transacción + * * @param tx BOOL es true si existe transacción asociada */ diff --git a/db/changes/240601/00-util_tx_rollback.sql b/db/changes/240601/00-util_tx_rollback.sql index 7be817ebc..1a79479be 100644 --- a/db/changes/240601/00-util_tx_rollback.sql +++ b/db/changes/240601/00-util_tx_rollback.sql @@ -2,8 +2,9 @@ DROP PROCEDURE IF EXISTS util.tx_rollback; DELIMITER $$ $$ -/* -Procedimiento para deshacer los cambios asociados a una transacción +/** + * Procedimiento para deshacer los cambios asociados a una transacción + * * @param tx BOOL es true si existe transacción asociada */ diff --git a/db/changes/240601/00-util_tx_start.sql b/db/changes/240601/00-util_tx_start.sql index 7d2c8a2b5..22d156642 100644 --- a/db/changes/240601/00-util_tx_start.sql +++ b/db/changes/240601/00-util_tx_start.sql @@ -2,8 +2,9 @@ DROP PROCEDURE IF EXISTS util.tx_start; DELIMITER $$ $$ -/* -Procedimiento para iniciar una transacción +/** + * Procedimiento para iniciar una transacción + * * @param tx BOOL es true si existe transacción asociada */ From b5d883cdbeb742187a923ca70ca12f1923cb4714 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 23 Jan 2024 11:53:12 +0100 Subject: [PATCH 081/116] refs #2687 feat: add grant privileges for guest --- db/changes/240601/00-grant_privileges_util_tx.sql | 3 +++ db/changes/240601/00-util_tx_commit.sql | 4 +--- db/changes/240601/00-util_tx_rollback.sql | 4 +--- db/changes/240601/00-util_tx_start.sql | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 db/changes/240601/00-grant_privileges_util_tx.sql diff --git a/db/changes/240601/00-grant_privileges_util_tx.sql b/db/changes/240601/00-grant_privileges_util_tx.sql new file mode 100644 index 000000000..bd49f6cb2 --- /dev/null +++ b/db/changes/240601/00-grant_privileges_util_tx.sql @@ -0,0 +1,3 @@ +GRANT EXECUTE ON PROCEDURE util.tx_commit TO guest; +GRANT EXECUTE ON PROCEDURE util.tx_rollback TO guest; +GRANT EXECUTE ON PROCEDURE util.tx_start TO guest; diff --git a/db/changes/240601/00-util_tx_commit.sql b/db/changes/240601/00-util_tx_commit.sql index 47e782987..f288e5fe3 100644 --- a/db/changes/240601/00-util_tx_commit.sql +++ b/db/changes/240601/00-util_tx_commit.sql @@ -1,5 +1,3 @@ -DROP PROCEDURE IF EXISTS util.tx_commit; - DELIMITER $$ $$ /** @@ -8,7 +6,7 @@ $$ * @param tx BOOL es true si existe transacción asociada */ -CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) BEGIN IF tx THEN COMMIT; diff --git a/db/changes/240601/00-util_tx_rollback.sql b/db/changes/240601/00-util_tx_rollback.sql index 1a79479be..3ec738fa7 100644 --- a/db/changes/240601/00-util_tx_rollback.sql +++ b/db/changes/240601/00-util_tx_rollback.sql @@ -1,5 +1,3 @@ -DROP PROCEDURE IF EXISTS util.tx_rollback; - DELIMITER $$ $$ /** @@ -8,7 +6,7 @@ $$ * @param tx BOOL es true si existe transacción asociada */ -CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) BEGIN IF tx THEN ROLLBACK; diff --git a/db/changes/240601/00-util_tx_start.sql b/db/changes/240601/00-util_tx_start.sql index 22d156642..f4a970c4f 100644 --- a/db/changes/240601/00-util_tx_start.sql +++ b/db/changes/240601/00-util_tx_start.sql @@ -1,4 +1,4 @@ -DROP PROCEDURE IF EXISTS util.tx_start; + DELIMITER $$ $$ @@ -8,7 +8,7 @@ $$ * @param tx BOOL es true si existe transacción asociada */ -CREATE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) BEGIN IF tx THEN START TRANSACTION; From 5d53d69754aa5a1c36570ae1302428d65acdabee Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 23 Jan 2024 12:52:35 +0100 Subject: [PATCH 082/116] refs #6694 perf: update postCode/filter method --- back/methods/postcode/filter.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 9986a16c9..8dbe2965f 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -7,10 +7,6 @@ module.exports = Self => { description: 'Find all postcodes of the model matched by postcode, town, province or country.', accessType: 'READ', - returns: { - type: ['object'], - root: true, - }, accepts: [ { arg: 'filter', @@ -25,6 +21,10 @@ module.exports = Self => { http: {source: 'query'} }, ], + returns: { + type: ['object'], + root: true, + }, http: { path: `/filter`, verb: 'GET', @@ -32,12 +32,11 @@ module.exports = Self => { }); Self.filter = async(ctx, filter, options) => { const myOptions = {}; - if (typeof options == 'object') Object.assign(myOptions, options); const conn = Self.dataSource.connector; - const where = buildFilter(ctx.args, (param, value) => { + const where = buildFilter(ctx.where, (param, value) => { switch (param) { case 'search': return {or: [ @@ -50,7 +49,7 @@ module.exports = Self => { } }) ?? {}; - filter = mergeFilters(ctx.args?.filter ?? {}, {where}); + filter = mergeFilters(ctx?.where ?? {}, where); const stmts = []; let stmt; @@ -67,7 +66,7 @@ module.exports = Self => { JOIN country c on c.id = p.countryFk `); - stmt.merge(conn.makeSuffix(filter)); + stmt.merge(conn.makeSuffix({where: filter, limit: ctx?.limit ?? 30})); const itemsIndex = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); From cddd8f7d94713f985c624ae9dfa1d839310dacf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Tue, 23 Jan 2024 16:36:53 +0100 Subject: [PATCH 083/116] refs #2687 perf: improve comments --- db/changes/240601/00-util_tx_commit.sql | 9 ++++----- db/changes/240601/00-util_tx_rollback.sql | 9 ++++----- db/changes/240601/00-util_tx_start.sql | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/db/changes/240601/00-util_tx_commit.sql b/db/changes/240601/00-util_tx_commit.sql index f288e5fe3..11be92c2e 100644 --- a/db/changes/240601/00-util_tx_commit.sql +++ b/db/changes/240601/00-util_tx_commit.sql @@ -1,16 +1,15 @@ DELIMITER $$ $$ + +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) +BEGIN /** * Procedimiento para confirmar los cambios asociados a una transacción * * @param tx BOOL es true si existe transacción asociada */ - -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) -BEGIN IF tx THEN COMMIT; END IF; -END -$$ +END$$ DELIMITER ; diff --git a/db/changes/240601/00-util_tx_rollback.sql b/db/changes/240601/00-util_tx_rollback.sql index 3ec738fa7..b6ac2cd12 100644 --- a/db/changes/240601/00-util_tx_rollback.sql +++ b/db/changes/240601/00-util_tx_rollback.sql @@ -1,16 +1,15 @@ DELIMITER $$ $$ + +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) +BEGIN /** * Procedimiento para deshacer los cambios asociados a una transacción * * @param tx BOOL es true si existe transacción asociada */ - -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) -BEGIN IF tx THEN ROLLBACK; END IF; -END -$$ +END$$ DELIMITER ; diff --git a/db/changes/240601/00-util_tx_start.sql b/db/changes/240601/00-util_tx_start.sql index f4a970c4f..6e513790b 100644 --- a/db/changes/240601/00-util_tx_start.sql +++ b/db/changes/240601/00-util_tx_start.sql @@ -2,17 +2,16 @@ DELIMITER $$ $$ + +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) +BEGIN /** * Procedimiento para iniciar una transacción * * @param tx BOOL es true si existe transacción asociada */ - -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) -BEGIN IF tx THEN START TRANSACTION; END IF; -END -$$ +END$$ DELIMITER ; From bc6f9bc0744d13d90f2a93746a40f53838aa0602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Tue, 23 Jan 2024 23:52:45 +0100 Subject: [PATCH 084/116] refs #6174 test: new test for new method --- .../back/methods/invoiceOut/makePdfList.js | 7 +- .../methods/ticket/invoiceTicketsAndPdf.js | 14 +-- .../ticket/specs/invoiceTicketsAndPdf.spec.js | 115 ++++++++++++++++++ 3 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/specs/invoiceTicketsAndPdf.spec.js diff --git a/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js b/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js index cf041ee17..a0449aeda 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js +++ b/modules/invoiceOut/back/methods/invoiceOut/makePdfList.js @@ -23,8 +23,9 @@ module.exports = Self => { }); Self.makePdfList = async function(ctx, ids, printerFk, options) { - ids.forEach(async id => { - await Self.makePdfAndNotify(ctx, id, printerFk, options); - }); + const pdfs = ids.map(id => + Self.makePdfAndNotify(ctx, id, printerFk, options) + ); + await Promise.all(pdfs); }; }; diff --git a/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js b/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js index 3831854a7..5529a3ae3 100644 --- a/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js +++ b/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js @@ -30,15 +30,11 @@ module.exports = function(Self) { Self.invoiceTicketsAndPdf = async(ctx, ticketsIds, invoiceCorrection, options) => { let invoiceIds = null; - try { - invoiceIds = await Self.invoiceTickets(ctx, ticketsIds, invoiceCorrection, options); - if (!invoiceIds) return []; - if (!options.transaction) - await Self.app.models.InvoiceOut.makePdfList(ctx, invoiceIds, null, options); - return invoiceIds; - } catch (error) { - return []; - } + invoiceIds = await Self.invoiceTickets(ctx, ticketsIds, invoiceCorrection, options); + if (!invoiceIds) return []; + if (!options.transaction) + await Self.app.models.InvoiceOut.makePdfList(ctx, invoiceIds, null, options); + return invoiceIds; }; }; diff --git a/modules/ticket/back/methods/ticket/specs/invoiceTicketsAndPdf.spec.js b/modules/ticket/back/methods/ticket/specs/invoiceTicketsAndPdf.spec.js new file mode 100644 index 000000000..086d1117f --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/invoiceTicketsAndPdf.spec.js @@ -0,0 +1,115 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +describe('ticket invoiceTicketsAndPdf()', () => { + const userId = 19; + const clientId = 1102; + const activeCtx = { + getLocale: () => { + return 'en'; + }, + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + }; + const ctx = {req: activeCtx}; + + beforeAll(async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should throw an error when invoicing tickets from multiple clients', async() => { + const invoiceOutModel = models.InvoiceOut; + spyOn(invoiceOutModel, 'makePdfAndNotify'); + + const tx = await models.Ticket.beginTransaction({}); + + let error; + + try { + const options = {transaction: tx}; + + const ticketsIds = [11, 16]; + await models.Ticket.invoiceTicketsAndPdf(ctx, ticketsIds, null, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`You can't invoice tickets from multiple clients`); + }); + + it(`should throw an error when invoicing a client without tax data checked`, async() => { + const invoiceOutModel = models.InvoiceOut; + spyOn(invoiceOutModel, 'makePdfAndNotify'); + + const tx = await models.Ticket.beginTransaction({}); + + let error; + + try { + const options = {transaction: tx}; + + const client = await models.Client.findById(clientId, null, options); + await client.updateAttribute('isTaxDataChecked', false, options); + + const ticketsIds = [11]; + await models.Ticket.invoiceTicketsAndPdf(ctx, ticketsIds, null, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`This client can't be invoiced`); + }); + + it('should invoice a ticket, then try again to fail', async() => { + const invoiceOutModel = models.InvoiceOut; + spyOn(invoiceOutModel, 'makePdfAndNotify'); + + const tx = await models.Ticket.beginTransaction({}); + + let error; + + try { + const options = {transaction: tx}; + + const ticketsIds = [11]; + await models.Ticket.invoiceTicketsAndPdf(ctx, ticketsIds, null, options); + await models.Ticket.invoiceTicketsAndPdf(ctx, ticketsIds, null, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`This ticket is already invoiced`); + }); + + it('should success to invoice a ticket', async() => { + const invoiceOutModel = models.InvoiceOut; + spyOn(invoiceOutModel, 'makePdfAndNotify'); + + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ticketsIds = [11]; + const invoicesIds = await models.Ticket.invoiceTicketsAndPdf(ctx, ticketsIds, null, options); + + expect(invoicesIds.length).toBeGreaterThan(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); From 701b039e9789bf6804fbc4df9b2cbdcdad71fcc2 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 Jan 2024 08:23:17 +0100 Subject: [PATCH 085/116] refs #6743 feat: import db --- db/dump/dumpedFixtures.sql | 46 +- db/dump/structure.sql | 13936 +++++++++++++++++++---------------- 2 files changed, 7626 insertions(+), 6356 deletions(-) diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 3e46c8e04..0b9ac605b 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -4,7 +4,7 @@ USE `util`; -- -- Host: db2.static.verdnatura.es Database: util -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -22,7 +22,7 @@ USE `util`; LOCK TABLES `config` WRITE; /*!40000 ALTER TABLE `config` DISABLE KEYS */; -INSERT INTO `config` VALUES (1,'234604',0,'production',NULL,'2001-01-01 11:00:00',NULL,0); +INSERT INTO `config` VALUES (1,'240203',0,'production',NULL,'2001-01-01 11:00:00',NULL,0); /*!40000 ALTER TABLE `config` ENABLE KEYS */; UNLOCK TABLES; @@ -32,7 +32,7 @@ UNLOCK TABLES; LOCK TABLES `version` WRITE; /*!40000 ALTER TABLE `version` DISABLE KEYS */; -INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL),('vn-database','10761','6c1146271aa71f7c3332e11d50d6812752391ea4','2023-11-20 11:55:47','10778'); +INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL),('vn-database','10827','7dcc0ea3642cfa81a4cf7192bb38f89af02c220a','2024-01-23 12:32:14','10829'); /*!40000 ALTER TABLE `version` ENABLE KEYS */; UNLOCK TABLES; @@ -42,7 +42,7 @@ UNLOCK TABLES; LOCK TABLES `versionLog` WRITE; /*!40000 ALTER TABLE `versionLog` DISABLE KEYS */; -INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL),('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL),('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL),('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL),('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL),('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL),('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL),('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL),('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL),('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL),('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL),('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL),('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL),('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL),('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL),('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL),('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL),('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL),('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL),('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL),('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL),('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL),('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL),('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL),('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL),('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL),('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL),('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL),('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL),('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL),('vn-database','10097','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL),('vn-database','10103','00-awbVolume.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10104','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10105','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL),('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL),('vn-database','10113','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL),('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL),('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL),('vn-database','10119','00-AfegirFKPart1.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10119','01-AfegirFkPart2.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10125','00-firstScript.sql','jenkins@10.0.2.68','2022-05-18 18:44:30',NULL,NULL),('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL),('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL),('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL),('vn-database','10132','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10133','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 14:32:30',NULL,NULL),('vn-database','10134','00-firstScript.sql','jenkins@10.0.2.69','2022-05-06 07:45:25',NULL,NULL),('vn-database','10135','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10136','00-workerTimeControl.sql','jenkins@10.0.2.69','2022-05-09 13:51:12',NULL,NULL),('vn-database','10138','00-firstScript.sql','jenkins@10.0.2.69','2022-05-10 13:58:05',NULL,NULL),('vn-database','10139','00-firstScript.sql','jenkins@10.0.2.68','2022-05-16 14:32:37',NULL,NULL),('vn-database','10139','01-secondScript.sql','jenkins@10.0.2.68','2022-05-17 12:16:13',NULL,NULL),('vn-database','10141','00-firstScript.sql','jenkins@10.0.2.70','2022-05-12 08:27:31',NULL,NULL),('vn-database','10142','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10143','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10144','00-AfegirFKPArt1.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10144','00-firstScript.sql','jenkins@10.0.2.68','2022-05-13 09:44:25',NULL,NULL),('vn-database','10147','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10149','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10150','00-firstScript.sql','jenkins@10.0.2.68','2022-05-17 09:57:16',NULL,NULL),('vn-database','10152','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10153','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10154','00-compressionKk.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10157','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:35',NULL,NULL),('vn-database','10158','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10160','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:30:50',NULL,NULL),('vn-database','10163','00-firstScript.sql','jenkins@10.0.2.68','2022-05-23 08:17:14',NULL,NULL),('vn-database','10164','00-borrarSectorsDesus.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10165','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10166','00-firstScript.sql','jenkins@10.0.2.68','2022-05-24 16:11:21',NULL,NULL),('vn-database','10167','00-renameVnActiveContrat.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10168','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','00-createTableBankEntityConfig.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','02-addNotNullToBankEntityBic.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10171','00-volumeConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 14:11:11',NULL,NULL),('vn-database','10171','01-itemWeight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL),('vn-database','10171','02-agencymode.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL),('vn-database','10172','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10174','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10175','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10177','00-crearTablaSpecialLabels.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10178','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10179','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10183','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10184','00-firstScript.sql','jenkins@10.0.2.68','2022-06-03 08:05:34',NULL,NULL),('vn-database','10185','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 09:07:45',NULL,NULL),('vn-database','10186','00-desactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:31:23',NULL,NULL),('vn-database','10186','01-alter_Table_buy.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','02-alter_table_entryConfig.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','04-regularizar_Sticker_Inventario.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10186','09-reactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10187','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 12:37:31',NULL,NULL),('vn-database','10188','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 14:03:36',NULL,NULL),('vn-database','10189','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10191','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10193','00-delete.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:35',NULL,NULL),('vn-database','10193','01-botanicExport.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:43',NULL,NULL),('vn-database','10193','02-item.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','03-autonomy.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','03-turn.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','04-country.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10194','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10195','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10200','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10201','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10202','00-Remove_FK_to_ediGenus.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10203','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10204','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10205','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:21',NULL,NULL),('vn-database','10207','00-Alter_table_entry.sql','jenkins@10.0.2.69','2022-06-16 07:22:50',NULL,NULL),('vn-database','10207','01-Update_invoiceAmount.sql','jenkins@10.0.2.69','2022-06-16 07:23:00',NULL,NULL),('vn-database','10208','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10209','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 08:47:40',NULL,NULL),('vn-database','10210','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 17:39:17',1046,'Base de datos no seleccionada'),('vn-database','10211','01-firstScript.sql','jenkins@10.0.2.69','2022-06-17 07:11:27',NULL,NULL),('vn-database','10215','00-renameIsInventory.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10216','00-firstScript.sql','jenkins@10.0.2.69','2022-06-23 11:15:28',NULL,NULL),('vn-database','10216','01-batchIndex.sql','jenkins@10.0.2.70','2022-06-27 18:10:55',NULL,NULL),('vn-database','10219','00-AddCollectionFkOnPackingSite.sql','jenkins@10.0.2.70','2022-06-29 09:23:42',NULL,NULL),('vn-database','10219','01-AddFkToCollectionFk.sql','jenkins@10.0.2.70','2022-06-29 09:23:43',NULL,NULL),('vn-database','10220','00-createPersonalProtectionEquipment.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10222','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:12:40',NULL,NULL),('vn-database','10223','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:52',NULL,NULL),('vn-database','10224','00-cosetes.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-21 12:03:45',NULL,NULL),('vn-database','10229','00-firstScript.sql','jenkins@10.0.2.69','2022-07-01 11:59:34',NULL,NULL),('vn-database','10231','01-tablaEktConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:25:39',NULL,NULL),('vn-database','10233','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10235','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10236','00-firstScript.sql','jenkins@10.0.2.69','2022-07-05 12:11:40',NULL,NULL),('vn-database','10237','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10238','00-worker_mobileExtension.sql','jenkins@10.0.2.69','2022-07-14 09:14:09',NULL,NULL),('vn-database','10239','00-firstScript.sql','jenkins@10.0.2.69','2022-07-07 21:51:58',NULL,NULL),('vn-database','10241','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-29 08:14:01',NULL,NULL),('vn-database','10242','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL),('vn-database','10243','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL),('vn-database','10245','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL),('vn-database','10247','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL),('vn-database','10248','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-20 17:27:51',NULL,NULL),('vn-database','10250','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:40',NULL,NULL),('vn-database','10253','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:57',NULL,NULL),('vn-database','10254','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10256','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10258','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL),('vn-database','10259','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-02 08:54:56',NULL,NULL),('vn-database','10261','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-22 08:42:20',NULL,NULL),('vn-database','10262','00-createTablepackagingWithFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','01-alterTablePackagingConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','02-insertsInicials.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','03-createTablepackingWithoutFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10263','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10265','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10267','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10267','01-fixMerge.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10275','00-improvedGeneralLog.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 09:55:56',NULL,NULL),('vn-database','10277','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL),('vn-database','10278','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 17:51:41',NULL,NULL),('vn-database','10279','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10281','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10282','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10283','00-alterTable.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10284','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-04 16:59:08',NULL,NULL),('vn-database','10285','00-firstScript.sql','jenkins@swarm-worker3.static.verdnatura.es','2022-08-05 09:19:33',NULL,NULL),('vn-database','10287','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL),('vn-database','10288','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL),('vn-database','10289','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:36',NULL,NULL),('vn-database','10291','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-10 14:19:34',NULL,NULL),('vn-database','10293','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL),('vn-database','10297','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-16 12:43:36',NULL,NULL),('vn-database','10298','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-13 21:04:13',NULL,NULL),('vn-database','10299','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','00-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','01-drop.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','02-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','00-CreateTableEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','01-insertDataEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','02-alterTableEntry.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:22',NULL,NULL),('vn-database','10303','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:23',NULL,NULL),('vn-database','10304','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:48',NULL,NULL),('vn-database','10304','01-altertableticket.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:51',NULL,NULL),('vn-database','10305','00-ektAssign.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:24:52',NULL,NULL),('vn-database','10306','00-deliveryInformation.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:25',NULL,NULL),('vn-database','10307','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:26',NULL,NULL),('vn-database','10308','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:26:43',NULL,NULL),('vn-database','10309','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:54',NULL,NULL),('vn-database','10310','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL),('vn-database','10311','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:55',NULL,NULL),('vn-database','10312','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL),('vn-database','10313','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:27:21',NULL,NULL),('vn-database','10314','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:19',NULL,NULL),('vn-database','10315','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10317','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10318','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10319','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:41',NULL,NULL),('vn-database','10320','00-operator.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL),('vn-database','10320','01-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL),('vn-database','10320','02-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10321','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 11:11:12',NULL,NULL),('vn-database','10322','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-09 09:19:05',NULL,NULL),('vn-database','10326','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10328','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10329','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10330','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10332','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10334','00-collectionHotbed.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10334','01-saleGroupDetail.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10335','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10336','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10337','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10339','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-19 09:41:19',NULL,NULL),('vn-database','10340','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10341','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10342','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10343','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:35:30',NULL,NULL),('vn-database','10345','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL),('vn-database','10347','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10347','01-addVirtualField.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10349','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10350','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-30 10:11:56',NULL,NULL),('vn-database','10352','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL),('vn-database','10353','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10354','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10356','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10356','01-orderConfigFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10356','02-orderConfigDrop.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10357','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10359','00-improvedGeneralLog_collate.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL),('vn-database','10360','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL),('vn-database','10361','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 11:16:07',NULL,NULL),('vn-database','10362','00-dropUdfs.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-10 11:01:15',NULL,NULL),('vn-database','10363','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10365','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-13 19:30:46',NULL,NULL),('vn-database','10368','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10369','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-14 13:38:06',NULL,NULL),('vn-database','10370','00-deleteForeignKey.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:41',NULL,NULL),('vn-database','10370','01-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:47',NULL,NULL),('vn-database','10370','02-deleteTable.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL),('vn-database','10370','03-accion.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL),('vn-database','10370','04-inter.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL),('vn-database','10371','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10372','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL),('vn-database','10373','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-19 08:31:58',NULL,NULL),('vn-database','10378','00-rename_routeUserPercentage.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10379','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:16',NULL,NULL),('vn-database','10382','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10383','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL),('vn-database','10384','00-business_workcenterFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10385','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL),('vn-database','10386','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL),('vn-database','10387','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-16 14:05:33',NULL,NULL),('vn-database','10388','00-resizeUtilVerionLogCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10388','01-resizeUtilVersionCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10390','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:16',NULL,NULL),('vn-database','10391','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10394','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:24',NULL,NULL),('vn-database','10395','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10396','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 15:36:38',NULL,NULL),('vn-database','10397','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10399','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10400','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10402','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-21 14:11:31',NULL,NULL),('vn-database','10404','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10405','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:22',NULL,NULL),('vn-database','10407','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL),('vn-database','10408','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10409','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL),('vn-database','10412','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-30 12:45:44',NULL,NULL),('vn-database','10413','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL),('vn-database','10416','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL),('vn-database','10420','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:25',NULL,NULL),('vn-database','10421','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:26',NULL,NULL),('vn-database','10426','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:40',NULL,NULL),('vn-database','10428','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10431','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:22',NULL,NULL),('vn-database','10433','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10434','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10435','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-13 07:30:10',NULL,NULL),('vn-database','10436','00-createFkWorker.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:59',NULL,NULL),('vn-database','10436','01-addStateToWorkerProductivity.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL),('vn-database','10436','02-DeprecateVnSaleTrackingState.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL),('vn-database','10436','03-DeprecateColumnVnSaleTrackingActionFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10436','04-DropSchemaVnControl.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10436','05-RemoveFkWorkerProductivity.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-17 14:51:19',NULL,NULL),('vn-database','10439','00-fixRole.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:26',NULL,NULL),('vn-database','10440','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10444','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10445','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10448','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10450','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-27 08:28:04',NULL,NULL),('vn-database','10451','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-06 08:08:32',NULL,NULL),('vn-database','10452','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10453','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 14:04:37',NULL,NULL),('vn-database','10454','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10455','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10456','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:30',NULL,NULL),('vn-database','10457','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:33',NULL,NULL),('vn-database','10458','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10459','00-alterTableUtilConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','01-createFunctionCurdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','02-createFunctionMockTime.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','03-createFunctionMockTimeBase.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','04-createFunctionNow.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10460','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10461','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10463','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-03 12:59:26',NULL,NULL),('vn-database','10468','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10469','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10470','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10471','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10472','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10477','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:31',NULL,NULL),('vn-database','10478','00-dropBasket.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10478','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10478','01-orderConfigured.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:16',NULL,NULL),('vn-database','10478','02-configuredUpdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL),('vn-database','10478','99-privileges.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL),('vn-database','10480','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 15:09:26',NULL,NULL),('vn-database','10481','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 16:37:22',NULL,NULL),('vn-database','10482','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-21 10:00:28',NULL,NULL),('vn-database','10485','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10488','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10491','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL),('vn-database','10492','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL),('vn-database','10493','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10495','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:19',NULL,NULL),('vn-database','10498','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:38',NULL,NULL),('vn-database','10500','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 07:06:03',NULL,NULL),('vn-database','10501','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 10:52:24',NULL,NULL),('vn-database','10502','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10504','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL),('vn-database','10506','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10506','01-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10506','02-secondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10506','03-thirdScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10507','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:35:23',NULL,NULL),('vn-database','10508','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:43',NULL,NULL),('vn-database','10510','00-dropBusinessFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','01-createTableProfessionalCategory.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','02-exportToNewTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','03-RecreateFK.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL),('vn-database','10510','04-kkPostgresqlTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL),('vn-database','10511','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10512','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:52',NULL,NULL),('vn-database','10513','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:56',NULL,NULL),('vn-database','10514','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10516','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10521','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 06:58:13',NULL,NULL),('vn-database','10522','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10523','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10524','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL),('vn-database','10524','01-rateEditorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL),('vn-database','10525','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 12:42:50',NULL,NULL),('vn-database','10526','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:57',NULL,NULL),('vn-database','10528','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:00',NULL,NULL),('vn-database','10530','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-23 14:49:30',NULL,NULL),('vn-database','10531','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:47:10',NULL,NULL),('vn-database','10532','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:17:38',NULL,NULL),('vn-database','10533','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:04',NULL,NULL),('vn-database','10537','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-29 15:18:36',NULL,NULL),('vn-database','10538','00-createChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','01-createChronopostService.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','02-createChronopostExpedition.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','03-createChronopostSenderAddress.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','04-addgrantPrivilegies.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','05-updateChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 11:54:57',NULL,NULL),('vn-database','10539','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:07',NULL,NULL),('vn-database','10540','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10545','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-11 08:31:03',NULL,NULL),('vn-database','10546','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL),('vn-database','10547','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:21:58',NULL,NULL),('vn-database','10549','00-updateUpdateLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:29:22',NULL,NULL),('vn-database','10549','01-updateInsertLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:11',NULL,NULL),('vn-database','10549','02-updateDeleteLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:51',NULL,NULL),('vn-database','10549','03-deleteEmptyLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:31:34',NULL,NULL),('vn-database','10549','04-optimizeLogTables.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:33:58',NULL,NULL),('vn-database','10550','00-editorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:42:33',NULL,NULL),('vn-database','10550','01-originFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10552','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-13 08:25:10',NULL,NULL),('vn-database','10554','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL),('vn-database','10557','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-17 07:45:56',NULL,NULL),('vn-database','10559','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-18 10:53:50',NULL,NULL),('vn-database','10560','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-17 09:19:31',NULL,NULL),('vn-database','10562','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10563','00-delivery_ticketFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 09:30:53',NULL,NULL),('vn-database','10566','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:08:41',NULL,NULL),('vn-database','10567','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:18:06',NULL,NULL),('vn-database','10568','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10569','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-24 09:14:35',NULL,NULL),('vn-database','10570','00-createSendingConfig.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','01-createSendingServiceWeekday.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','02-createSendingService.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','03-permisos.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10571','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL),('vn-database','10573','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:23',NULL,NULL),('vn-database','10575','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-26 11:27:32',NULL,NULL),('vn-database','10577','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-27 14:00:12',NULL,NULL),('vn-database','10578','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10579','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-28 11:27:36',NULL,NULL),('vn-database','10580','00-itemTypeDropConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:18:52',NULL,NULL),('vn-database','10580','01-itemTypeAddConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:19:10',NULL,NULL),('vn-database','10581','00-itemTypeAutoIncrement.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 19:06:46',NULL,NULL),('vn-database','10582','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10583','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10584','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10585','00-ticketLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:20:10',NULL,NULL),('vn-database','10585','01-entryLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:21:12',NULL,NULL),('vn-database','10585','02-claimLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:36',NULL,NULL),('vn-database','10585','03-clientLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:54',NULL,NULL),('vn-database','10585','04-invoiceInLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:55',NULL,NULL),('vn-database','10585','05-itemLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:29:46',NULL,NULL),('vn-database','10585','06-routeLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:18',NULL,NULL),('vn-database','10585','07-shelvingLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL),('vn-database','10585','08-supplierLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL),('vn-database','10585','09-travelLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:41',NULL,NULL),('vn-database','10585','10-workerLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:42',NULL,NULL),('vn-database','10585','11-zoneLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:43',NULL,NULL),('vn-database','10585','12-userLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10585','13-roleLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10587','00-arcRead_addMinimum.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-16 13:13:15',NULL,NULL),('vn-database','10593','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10596','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10597','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10598','00-workerLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','01-supplierLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','02-workerTimeControlLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','03-workerClockLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10599','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10601','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-17 09:26:26',NULL,NULL),('vn-database','10602','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 08:52:15',NULL,NULL),('vn-database','10606','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 09:26:00',NULL,NULL),('vn-database','10608','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 12:36:31',NULL,NULL),('vn-database','10609','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 08:28:07',NULL,NULL),('vn-database','10610','00-updateCompanyId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:07',NULL,NULL),('vn-database','10610','01-updateSupplierId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:39',NULL,NULL),('vn-database','10610','02-invoiceOutCompany.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 09:49:55',NULL,NULL),('vn-database','10611','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-19 14:39:41',NULL,NULL),('vn-database','10613','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10614','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL),('vn-database','10615','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL),('vn-database','10616','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL),('vn-database','10616','01-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL),('vn-database','10617','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:41',NULL,NULL),('vn-database','10618','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 12:55:56',NULL,NULL),('vn-database','10619','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10620','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:20:53',NULL,NULL),('vn-database','10624','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-30 19:01:10',NULL,NULL),('vn-database','10625','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10626','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 13:32:32',NULL,NULL),('vn-database','10628','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10630','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-02 13:30:58',NULL,NULL),('vn-database','10631','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-05 08:37:25',NULL,NULL),('vn-database','10632','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10633','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10634','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-06 12:15:55',NULL,NULL),('vn-database','10637','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:19',NULL,NULL),('vn-database','10640','00-companyFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL),('vn-database','10640','00-updateCompany.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-07 14:22:13',1205,'Tiempo de espera de bloqueo excedido; intente rearrancar la transacción'),('vn-database','10640','01-companyFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL),('vn-database','10640','02-companyFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:47:04',NULL,NULL),('vn-database','10640','04-supplierFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:48:30',NULL,NULL),('vn-database','10640','05-supplierFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:53:17',NULL,NULL),('vn-database','10640','06-supplierFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 15:06:00',NULL,NULL),('vn-database','10642','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10643','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-09 15:04:35',NULL,NULL),('vn-database','10644','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:18',NULL,NULL),('vn-database','10645','00-addNewFields.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL),('vn-database','10645','01-updateCollectionWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL),('vn-database','10645','02-updateWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10645','03-addFieldToPackingSite.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10647','00-renombrarTabla.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10648','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10649','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-16 10:59:06',NULL,NULL),('vn-database','10652','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10653','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:20',NULL,NULL),('vn-database','10655','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:24',NULL,NULL),('vn-database','10656','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10657','00-renameErrorProduction.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','01-changeNightTask.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','02-addCodeToClaimResponsible.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','03-grantSelectGrafana.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10658','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:27',NULL,NULL),('vn-database','10659','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10661','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL),('vn-database','10662','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:33',NULL,NULL),('vn-database','10663','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL),('vn-database','10665','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-30 08:52:51',NULL,NULL),('vn-database','10666','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL),('vn-database','10667','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10668','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10671','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-25 14:56:50',NULL,NULL),('vn-database','10675','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10676','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10677','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL),('vn-database','10678','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10679','00-tables.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10680','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-18 14:58:36',NULL,NULL),('vn-database','10682','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10683','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10684','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10685','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:53:55',NULL,NULL),('vn-database','10690','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-27 10:52:26',NULL,NULL),('vn-database','10691','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-31 13:37:21',NULL,NULL),('vn-database','10692','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10693','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10694','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 09:50:53',NULL,NULL),('vn-database','10695','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 13:40:16',NULL,NULL),('vn-database','10696','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 16:54:57',NULL,NULL),('vn-database','10698','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-03 08:53:12',NULL,NULL),('vn-database','10699','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 15:24:30',NULL,NULL),('vn-database','10700','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:11',NULL,NULL),('vn-database','10701','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10702','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 12:50:46',NULL,NULL),('vn-database','10704','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:14',NULL,NULL),('vn-database','10705','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-16 14:16:05',NULL,NULL),('vn-database','10707','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-21 12:31:18',NULL,NULL),('vn-database','10708','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL),('vn-database','10712','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL),('vn-database','10714','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-28 13:01:45',NULL,NULL),('vn-database','10716','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL),('vn-database','10717','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:28:54',NULL,NULL),('vn-database','10718','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10719','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-01 12:53:30',NULL,NULL),('vn-database','10720','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL),('vn-database','10721','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10722','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-09 13:00:29',NULL,NULL),('vn-database','10725','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-12 14:15:14',NULL,NULL),('vn-database','10726','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 15:32:20',NULL,NULL),('vn-database','10727','00-addPrinterField.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','01-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','02-createTableScreen.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','03-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','04-createTableScanner.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','05-createTablePackingSiteDeviceLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','06-alterTablePrinterModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','07-AddFieldsToPackingSite.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:30',NULL,NULL),('vn-database','10730','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-15 11:42:48',NULL,NULL),('vn-database','10733','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:54:00',NULL,NULL),('vn-database','10736','00-workerBossNull.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-22 00:02:05',NULL,NULL),('vn-database','10739','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-10 10:19:07',NULL,NULL),('vn-database','10740','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10741','01-refactorCplusTrascendency472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','02-refactorCplusTrascendency477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','03-refactorCplusInvoiceType477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','04-refactorCplusInvoiceType472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','05-fixes.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10744','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-13 09:23:19',NULL,NULL),('vn-database','10746','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-16 18:22:46',NULL,NULL),('vn-database','10747','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL),('vn-database','10748','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL),('vn-database','10748','01-SecondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10749','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-22 16:08:17',NULL,NULL),('vn-database','10750','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-23 13:04:17',NULL,NULL),('vn-database','10750','00-ticket_addGrants.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10751','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10752','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-24 14:07:54',NULL,NULL),('vn-database','10753','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-24 14:37:21',NULL,NULL),('vn-database','10754','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10755','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:35',NULL,NULL),('vn-database','10756','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-03 07:14:38',NULL,NULL),('vn-database','10757','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:57',NULL,NULL),('vn-database','10761','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL),('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL),('vn-database','10113','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL),('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL),('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL),('vn-database','10119','00-AfegirFKPart1.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10119','01-AfegirFkPart2.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10125','00-firstScript.sql','jenkins@10.0.2.68','2022-05-18 18:44:30',NULL,NULL),('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL),('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL),('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL),('vn-database','10132','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10133','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 14:32:30',NULL,NULL),('vn-database','10134','00-firstScript.sql','jenkins@10.0.2.69','2022-05-06 07:45:25',NULL,NULL),('vn-database','10135','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10136','00-workerTimeControl.sql','jenkins@10.0.2.69','2022-05-09 13:51:12',NULL,NULL),('vn-database','10138','00-firstScript.sql','jenkins@10.0.2.69','2022-05-10 13:58:05',NULL,NULL),('vn-database','10139','00-firstScript.sql','jenkins@10.0.2.68','2022-05-16 14:32:37',NULL,NULL),('vn-database','10139','01-secondScript.sql','jenkins@10.0.2.68','2022-05-17 12:16:13',NULL,NULL),('vn-database','10141','00-firstScript.sql','jenkins@10.0.2.70','2022-05-12 08:27:31',NULL,NULL),('vn-database','10142','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10143','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10144','00-AfegirFKPArt1.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10147','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10149','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10150','00-firstScript.sql','jenkins@10.0.2.68','2022-05-17 09:57:16',NULL,NULL),('vn-database','10152','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10153','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10154','00-compressionKk.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10157','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:35',NULL,NULL),('vn-database','10158','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10160','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:30:50',NULL,NULL),('vn-database','10163','00-firstScript.sql','jenkins@10.0.2.68','2022-05-23 08:17:14',NULL,NULL),('vn-database','10164','00-borrarSectorsDesus.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10165','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10166','00-firstScript.sql','jenkins@10.0.2.68','2022-05-24 16:11:21',NULL,NULL),('vn-database','10167','00-renameVnActiveContrat.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10168','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','00-createTableBankEntityConfig.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','02-addNotNullToBankEntityBic.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10171','00-volumeConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 14:11:11',NULL,NULL),('vn-database','10171','01-itemWeight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL),('vn-database','10171','02-agencymode.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-18 16:01:34',NULL,NULL),('vn-database','10172','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10174','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10175','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10177','00-crearTablaSpecialLabels.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10178','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10179','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10183','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10184','00-firstScript.sql','jenkins@10.0.2.68','2022-06-03 08:05:34',NULL,NULL),('vn-database','10185','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 09:07:45',NULL,NULL),('vn-database','10186','00-desactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:31:23',NULL,NULL),('vn-database','10186','01-alter_Table_buy.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','02-alter_table_entryConfig.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','04-regularizar_Sticker_Inventario.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10186','09-reactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10187','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 12:37:31',NULL,NULL),('vn-database','10188','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 14:03:36',NULL,NULL),('vn-database','10189','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10191','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10193','00-delete.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:35',NULL,NULL),('vn-database','10193','01-botanicExport.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:43',NULL,NULL),('vn-database','10193','02-item.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','03-autonomy.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','03-turn.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10193','04-country.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-15 12:14:44',NULL,NULL),('vn-database','10194','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10195','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10200','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10201','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10202','00-Remove_FK_to_ediGenus.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10203','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10204','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10205','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:21',NULL,NULL),('vn-database','10207','00-Alter_table_entry.sql','jenkins@10.0.2.69','2022-06-16 07:22:50',NULL,NULL),('vn-database','10207','01-Update_invoiceAmount.sql','jenkins@10.0.2.69','2022-06-16 07:23:00',NULL,NULL),('vn-database','10208','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10209','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 08:47:40',NULL,NULL),('vn-database','10211','01-firstScript.sql','jenkins@10.0.2.69','2022-06-17 07:11:27',NULL,NULL),('vn-database','10215','00-renameIsInventory.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10216','00-firstScript.sql','jenkins@10.0.2.69','2022-06-23 11:15:28',NULL,NULL),('vn-database','10216','01-batchIndex.sql','jenkins@10.0.2.70','2022-06-27 18:10:55',NULL,NULL),('vn-database','10219','00-AddCollectionFkOnPackingSite.sql','jenkins@10.0.2.70','2022-06-29 09:23:42',NULL,NULL),('vn-database','10219','01-AddFkToCollectionFk.sql','jenkins@10.0.2.70','2022-06-29 09:23:43',NULL,NULL),('vn-database','10220','00-createPersonalProtectionEquipment.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL),('vn-database','10222','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:12:40',NULL,NULL),('vn-database','10223','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:52',NULL,NULL),('vn-database','10224','00-cosetes.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-21 12:03:45',NULL,NULL),('vn-database','10229','00-firstScript.sql','jenkins@10.0.2.69','2022-07-01 11:59:34',NULL,NULL),('vn-database','10231','01-tablaEktConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:25:39',NULL,NULL),('vn-database','10233','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10235','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10236','00-firstScript.sql','jenkins@10.0.2.69','2022-07-05 12:11:40',NULL,NULL),('vn-database','10237','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:13:53',NULL,NULL),('vn-database','10238','00-worker_mobileExtension.sql','jenkins@10.0.2.69','2022-07-14 09:14:09',NULL,NULL),('vn-database','10239','00-firstScript.sql','jenkins@10.0.2.69','2022-07-07 21:51:58',NULL,NULL),('vn-database','10241','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-29 08:14:01',NULL,NULL),('vn-database','10242','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL),('vn-database','10243','00-firstScript.sql','jenkins@10.0.2.69','2022-07-14 09:14:32',NULL,NULL),('vn-database','10245','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL),('vn-database','10247','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:34:51',NULL,NULL),('vn-database','10248','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-20 17:27:51',NULL,NULL),('vn-database','10250','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:40',NULL,NULL),('vn-database','10253','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:36:57',NULL,NULL),('vn-database','10254','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10256','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10258','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL),('vn-database','10259','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-02 08:54:56',NULL,NULL),('vn-database','10261','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-22 08:42:20',NULL,NULL),('vn-database','10262','00-createTablepackagingWithFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','01-alterTablePackagingConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','02-insertsInicials.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:13',NULL,NULL),('vn-database','10262','03-createTablepackingWithoutFreight.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10263','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10265','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-07-28 08:38:48',NULL,NULL),('vn-database','10267','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10267','01-fixMerge.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10275','00-improvedGeneralLog.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 09:55:56',NULL,NULL),('vn-database','10277','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL),('vn-database','10278','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-01 17:51:41',NULL,NULL),('vn-database','10279','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:17',NULL,NULL),('vn-database','10281','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10282','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10283','00-alterTable.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:34:18',NULL,NULL),('vn-database','10284','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-04 16:59:08',NULL,NULL),('vn-database','10285','00-firstScript.sql','jenkins@swarm-worker3.static.verdnatura.es','2022-08-05 09:19:33',NULL,NULL),('vn-database','10287','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL),('vn-database','10288','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-11 09:35:24',NULL,NULL),('vn-database','10289','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:36',NULL,NULL),('vn-database','10291','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-10 14:19:34',NULL,NULL),('vn-database','10293','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:32',NULL,NULL),('vn-database','10297','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-16 12:43:36',NULL,NULL),('vn-database','10298','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-08-13 21:04:13',NULL,NULL),('vn-database','10299','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','00-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','01-drop.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:14',NULL,NULL),('vn-database','10301','02-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','00-CreateTableEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','01-insertDataEntryType.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:15',NULL,NULL),('vn-database','10302','02-alterTableEntry.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:22',NULL,NULL),('vn-database','10303','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:22:23',NULL,NULL),('vn-database','10304','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:48',NULL,NULL),('vn-database','10304','01-altertableticket.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:23:51',NULL,NULL),('vn-database','10305','00-ektAssign.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:24:52',NULL,NULL),('vn-database','10306','00-deliveryInformation.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:25',NULL,NULL),('vn-database','10307','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:25:26',NULL,NULL),('vn-database','10308','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-02 17:26:43',NULL,NULL),('vn-database','10309','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:54',NULL,NULL),('vn-database','10310','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL),('vn-database','10311','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-06 11:37:55',NULL,NULL),('vn-database','10312','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:26:33',NULL,NULL),('vn-database','10313','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:27:21',NULL,NULL),('vn-database','10314','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:19',NULL,NULL),('vn-database','10315','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10317','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10318','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 10:31:43',NULL,NULL),('vn-database','10319','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-20 12:37:41',NULL,NULL),('vn-database','10320','00-operator.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL),('vn-database','10320','01-collection.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:37',NULL,NULL),('vn-database','10320','02-productionConfig.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10321','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-08 11:11:12',NULL,NULL),('vn-database','10322','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-09 09:19:05',NULL,NULL),('vn-database','10326','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10328','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10329','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:29:38',NULL,NULL),('vn-database','10330','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10332','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10334','00-collectionHotbed.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:30',NULL,NULL),('vn-database','10334','01-saleGroupDetail.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10335','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10336','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10337','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10339','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-19 09:41:19',NULL,NULL),('vn-database','10340','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10341','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:34:32',NULL,NULL),('vn-database','10342','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10343','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-22 08:35:30',NULL,NULL),('vn-database','10345','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL),('vn-database','10347','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10347','01-addVirtualField.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-29 11:08:03',NULL,NULL),('vn-database','10349','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10350','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-09-30 10:11:56',NULL,NULL),('vn-database','10352','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:16',NULL,NULL),('vn-database','10353','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10354','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10356','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10356','01-orderConfigFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10356','02-orderConfigDrop.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-10 22:35:00',NULL,NULL),('vn-database','10357','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:38',NULL,NULL),('vn-database','10359','00-improvedGeneralLog_collate.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL),('vn-database','10360','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 09:52:39',NULL,NULL),('vn-database','10361','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-06 11:16:07',NULL,NULL),('vn-database','10362','00-dropUdfs.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-10 11:01:15',NULL,NULL),('vn-database','10363','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10365','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-13 19:30:46',NULL,NULL),('vn-database','10368','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10369','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-14 13:38:06',NULL,NULL),('vn-database','10370','00-deleteForeignKey.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:41',NULL,NULL),('vn-database','10370','01-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:47',NULL,NULL),('vn-database','10370','02-deleteTable.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL),('vn-database','10370','03-accion.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:49',NULL,NULL),('vn-database','10370','04-inter.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL),('vn-database','10371','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10372','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:48',NULL,NULL),('vn-database','10373','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-10-19 08:31:58',NULL,NULL),('vn-database','10378','00-rename_routeUserPercentage.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-11-04 08:25:17',NULL,NULL),('vn-database','10379','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:16',NULL,NULL),('vn-database','10382','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10383','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:53',NULL,NULL),('vn-database','10384','00-business_workcenterFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10385','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL),('vn-database','10386','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 14:32:54',NULL,NULL),('vn-database','10387','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-16 14:05:33',NULL,NULL),('vn-database','10388','00-resizeUtilVerionLogCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10388','01-resizeUtilVersionCode.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:47:20',NULL,NULL),('vn-database','10390','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:16',NULL,NULL),('vn-database','10391','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10394','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:24',NULL,NULL),('vn-database','10395','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10396','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-17 15:36:38',NULL,NULL),('vn-database','10397','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10399','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10400','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10402','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-21 14:11:31',NULL,NULL),('vn-database','10404','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-12-01 08:50:29',NULL,NULL),('vn-database','10405','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:22',NULL,NULL),('vn-database','10407','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL),('vn-database','10408','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:23',NULL,NULL),('vn-database','10409','00-firstScript.sql','jenkins@swarm-worker2.static.verdnatura.es','2022-12-16 09:14:49',NULL,NULL),('vn-database','10412','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2022-11-30 12:45:44',NULL,NULL),('vn-database','10413','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL),('vn-database','10416','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:24',NULL,NULL),('vn-database','10420','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:25',NULL,NULL),('vn-database','10421','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-12 10:56:26',NULL,NULL),('vn-database','10426','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:40',NULL,NULL),('vn-database','10428','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10431','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:22',NULL,NULL),('vn-database','10433','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10434','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-26 13:27:05',NULL,NULL),('vn-database','10435','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-13 07:30:10',NULL,NULL),('vn-database','10436','00-createFkWorker.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:58:59',NULL,NULL),('vn-database','10436','01-addStateToWorkerProductivity.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL),('vn-database','10436','02-DeprecateVnSaleTrackingState.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:00',NULL,NULL),('vn-database','10436','03-DeprecateColumnVnSaleTrackingActionFk.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10436','04-DropSchemaVnControl.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10436','05-RemoveFkWorkerProductivity.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-17 14:51:19',NULL,NULL),('vn-database','10439','00-fixRole.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:26',NULL,NULL),('vn-database','10440','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10444','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:01',NULL,NULL),('vn-database','10445','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10448','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10450','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-27 08:28:04',NULL,NULL),('vn-database','10451','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-06 08:08:32',NULL,NULL),('vn-database','10452','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10453','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 14:04:37',NULL,NULL),('vn-database','10454','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10455','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:30:04',NULL,NULL),('vn-database','10456','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:30',NULL,NULL),('vn-database','10457','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-01-31 12:00:33',NULL,NULL),('vn-database','10458','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10459','00-alterTableUtilConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','01-createFunctionCurdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','02-createFunctionMockTime.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','03-createFunctionMockTimeBase.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10459','04-createFunctionNow.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:41',NULL,NULL),('vn-database','10460','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10461','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10463','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-03 12:59:26',NULL,NULL),('vn-database','10468','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10469','00-firstScript.sql','jenkins@swarm-worker1.static.verdnatura.es','2023-02-16 09:59:31',NULL,NULL),('vn-database','10470','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10471','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10472','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10477','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:31',NULL,NULL),('vn-database','10478','00-dropBasket.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10478','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:28:54',NULL,NULL),('vn-database','10478','01-orderConfigured.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:16',NULL,NULL),('vn-database','10478','02-configuredUpdate.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL),('vn-database','10478','99-privileges.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-23 10:29:53',NULL,NULL),('vn-database','10480','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 15:09:26',NULL,NULL),('vn-database','10481','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-02-17 16:37:22',NULL,NULL),('vn-database','10482','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-02-21 10:00:28',NULL,NULL),('vn-database','10485','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10488','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:17',NULL,NULL),('vn-database','10491','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL),('vn-database','10492','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:18',NULL,NULL),('vn-database','10493','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10495','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-09 08:40:19',NULL,NULL),('vn-database','10498','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:38',NULL,NULL),('vn-database','10500','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 07:06:03',NULL,NULL),('vn-database','10501','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-03 10:52:24',NULL,NULL),('vn-database','10502','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10504','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL),('vn-database','10506','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10506','01-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10506','02-secondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10506','03-thirdScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10507','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:35:23',NULL,NULL),('vn-database','10508','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:43',NULL,NULL),('vn-database','10510','00-dropBusinessFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','01-createTableProfessionalCategory.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','02-exportToNewTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:47',NULL,NULL),('vn-database','10510','03-RecreateFK.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL),('vn-database','10510','04-kkPostgresqlTable.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:51',NULL,NULL),('vn-database','10511','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10512','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:52',NULL,NULL),('vn-database','10513','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:56',NULL,NULL),('vn-database','10514','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10516','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-23 09:09:48',NULL,NULL),('vn-database','10521','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 06:58:13',NULL,NULL),('vn-database','10522','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10523','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10524','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL),('vn-database','10524','01-rateEditorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:12',NULL,NULL),('vn-database','10525','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-21 12:42:50',NULL,NULL),('vn-database','10526','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:36:57',NULL,NULL),('vn-database','10528','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:00',NULL,NULL),('vn-database','10530','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-03-23 14:49:30',NULL,NULL),('vn-database','10531','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:47:10',NULL,NULL),('vn-database','10532','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-24 11:17:38',NULL,NULL),('vn-database','10533','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:04',NULL,NULL),('vn-database','10537','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-03-29 15:18:36',NULL,NULL),('vn-database','10538','00-createChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','01-createChronopostService.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','02-createChronopostExpedition.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','03-createChronopostSenderAddress.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','04-addgrantPrivilegies.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:07:41',NULL,NULL),('vn-database','10538','05-updateChronopostConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 11:54:57',NULL,NULL),('vn-database','10539','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-05 10:37:07',NULL,NULL),('vn-database','10540','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:18:01',NULL,NULL),('vn-database','10545','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-11 08:31:03',NULL,NULL),('vn-database','10546','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL),('vn-database','10547','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:21:58',NULL,NULL),('vn-database','10549','00-updateUpdateLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:29:22',NULL,NULL),('vn-database','10549','01-updateInsertLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:11',NULL,NULL),('vn-database','10549','02-updateDeleteLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:30:51',NULL,NULL),('vn-database','10549','03-deleteEmptyLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:31:34',NULL,NULL),('vn-database','10549','04-optimizeLogTables.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-21 07:33:58',NULL,NULL),('vn-database','10550','00-editorFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:42:33',NULL,NULL),('vn-database','10550','01-originFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10552','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-13 08:25:10',NULL,NULL),('vn-database','10554','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-20 09:08:10',NULL,NULL),('vn-database','10557','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-17 07:45:56',NULL,NULL),('vn-database','10559','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-18 10:53:50',NULL,NULL),('vn-database','10560','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-17 09:19:31',NULL,NULL),('vn-database','10562','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10563','00-delivery_ticketFk.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 09:30:53',NULL,NULL),('vn-database','10566','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:08:41',NULL,NULL),('vn-database','10567','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-20 10:18:06',NULL,NULL),('vn-database','10568','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10569','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-24 09:14:35',NULL,NULL),('vn-database','10570','00-createSendingConfig.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','01-createSendingServiceWeekday.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','02-createSendingService.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10570','03-permisos.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10571','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:13:27',NULL,NULL),('vn-database','10573','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:23',NULL,NULL),('vn-database','10575','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-26 11:27:32',NULL,NULL),('vn-database','10577','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-27 14:00:12',NULL,NULL),('vn-database','10578','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10579','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-04-28 11:27:36',NULL,NULL),('vn-database','10580','00-itemTypeDropConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:18:52',NULL,NULL),('vn-database','10580','01-itemTypeAddConstraint.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 18:19:10',NULL,NULL),('vn-database','10581','00-itemTypeAutoIncrement.sql','jenkins@db-proxy2.static.verdnatura.es','2023-04-28 19:06:46',NULL,NULL),('vn-database','10582','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10583','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10584','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:28',NULL,NULL),('vn-database','10585','00-ticketLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:20:10',NULL,NULL),('vn-database','10585','01-entryLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-25 09:21:12',NULL,NULL),('vn-database','10585','02-claimLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:36',NULL,NULL),('vn-database','10585','03-clientLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:54',NULL,NULL),('vn-database','10585','04-invoiceInLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:28:55',NULL,NULL),('vn-database','10585','05-itemLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:29:46',NULL,NULL),('vn-database','10585','06-routeLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:18',NULL,NULL),('vn-database','10585','07-shelvingLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL),('vn-database','10585','08-supplierLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:32',NULL,NULL),('vn-database','10585','09-travelLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:41',NULL,NULL),('vn-database','10585','10-workerLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:42',NULL,NULL),('vn-database','10585','11-zoneLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:43',NULL,NULL),('vn-database','10585','12-userLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10585','13-roleLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10587','00-arcRead_addMinimum.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-16 13:13:15',NULL,NULL),('vn-database','10593','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10596','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10597','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10598','00-workerLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','01-supplierLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','02-workerTimeControlLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10598','03-workerClockLog.sql','jenkins@db-proxy2.static.verdnatura.es','2023-05-12 09:45:29',NULL,NULL),('vn-database','10599','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 09:30:44',NULL,NULL),('vn-database','10601','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-17 09:26:26',NULL,NULL),('vn-database','10602','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 08:52:15',NULL,NULL),('vn-database','10606','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 09:26:00',NULL,NULL),('vn-database','10608','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-18 12:36:31',NULL,NULL),('vn-database','10609','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 08:28:07',NULL,NULL),('vn-database','10610','00-updateCompanyId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:07',NULL,NULL),('vn-database','10610','01-updateSupplierId.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:39',NULL,NULL),('vn-database','10610','02-invoiceOutCompany.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-01 09:49:55',NULL,NULL),('vn-database','10611','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-19 14:39:41',NULL,NULL),('vn-database','10613','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10614','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL),('vn-database','10615','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:40',NULL,NULL),('vn-database','10616','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL),('vn-database','10616','01-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:18:55',NULL,NULL),('vn-database','10617','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-01 09:11:41',NULL,NULL),('vn-database','10618','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-25 12:55:56',NULL,NULL),('vn-database','10619','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10620','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:20:53',NULL,NULL),('vn-database','10624','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-05-30 19:01:10',NULL,NULL),('vn-database','10625','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10626','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 13:32:32',NULL,NULL),('vn-database','10628','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10630','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-02 13:30:58',NULL,NULL),('vn-database','10631','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-05 08:37:25',NULL,NULL),('vn-database','10632','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10633','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:18',NULL,NULL),('vn-database','10634','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-06 12:15:55',NULL,NULL),('vn-database','10637','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:19',NULL,NULL),('vn-database','10640','00-companyFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL),('vn-database','10640','01-companyFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL),('vn-database','10640','02-companyFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:47:04',NULL,NULL),('vn-database','10640','04-supplierFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:48:30',NULL,NULL),('vn-database','10640','05-supplierFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:53:17',NULL,NULL),('vn-database','10640','06-supplierFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 15:06:00',NULL,NULL),('vn-database','10642','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10643','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-09 15:04:35',NULL,NULL),('vn-database','10644','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:18',NULL,NULL),('vn-database','10645','00-addNewFields.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL),('vn-database','10645','01-updateCollectionWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:11',NULL,NULL),('vn-database','10645','02-updateWagonPrimaryKey.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10645','03-addFieldToPackingSite.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10647','00-renombrarTabla.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10648','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10649','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-16 10:59:06',NULL,NULL),('vn-database','10651','00-comparativeCountryFk.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:16',NULL,NULL),('vn-database','10651','01-comparativeAddConfig.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:16',NULL,NULL),('vn-database','10651','02-nightTaskAddNewTask.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:16',NULL,NULL),('vn-database','10652','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-29 14:04:13',NULL,NULL),('vn-database','10653','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:20',NULL,NULL),('vn-database','10655','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:24',NULL,NULL),('vn-database','10656','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10657','00-renameErrorProduction.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','01-changeNightTask.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','02-addCodeToClaimResponsible.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10657','03-grantSelectGrafana.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10658','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:27',NULL,NULL),('vn-database','10659','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10661','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL),('vn-database','10662','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:33',NULL,NULL),('vn-database','10663','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL),('vn-database','10665','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-30 08:52:51',NULL,NULL),('vn-database','10666','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-13 11:22:34',NULL,NULL),('vn-database','10667','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10668','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10671','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-25 14:56:50',NULL,NULL),('vn-database','10675','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10676','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10677','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL),('vn-database','10678','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10679','00-tables.sql','jenkins@db-proxy2.static.verdnatura.es','2023-07-27 09:17:24',NULL,NULL),('vn-database','10680','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-18 14:58:36',NULL,NULL),('vn-database','10682','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10683','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10684','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10685','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:53:55',NULL,NULL),('vn-database','10690','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-27 10:52:26',NULL,NULL),('vn-database','10691','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-07-31 13:37:21',NULL,NULL),('vn-database','10692','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10693','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 11:50:13',NULL,NULL),('vn-database','10694','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 09:50:53',NULL,NULL),('vn-database','10695','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-02 13:40:16',NULL,NULL),('vn-database','10696','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 16:54:57',NULL,NULL),('vn-database','10698','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-03 08:53:12',NULL,NULL),('vn-database','10699','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-03 15:24:30',NULL,NULL),('vn-database','10700','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:11',NULL,NULL),('vn-database','10701','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:12',NULL,NULL),('vn-database','10702','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-10 12:50:46',NULL,NULL),('vn-database','10704','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-29 09:42:14',NULL,NULL),('vn-database','10705','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-16 14:16:05',NULL,NULL),('vn-database','10707','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-08-21 12:31:18',NULL,NULL),('vn-database','10708','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL),('vn-database','10712','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-07 10:43:13',NULL,NULL),('vn-database','10714','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-08-28 13:01:45',NULL,NULL),('vn-database','10716','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:27:50',NULL,NULL),('vn-database','10717','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:28:54',NULL,NULL),('vn-database','10718','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10719','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-01 12:53:30',NULL,NULL),('vn-database','10720','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL),('vn-database','10721','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10725','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-12 14:15:14',NULL,NULL),('vn-database','10726','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 15:32:20',NULL,NULL),('vn-database','10727','00-addPrinterField.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','01-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','02-createTableScreen.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','03-createTableScreenModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','04-createTableScanner.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','05-createTablePackingSiteDeviceLog.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','06-alterTablePrinterModel.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL),('vn-database','10727','07-AddFieldsToPackingSite.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:30',NULL,NULL),('vn-database','10730','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-15 11:42:48',NULL,NULL),('vn-database','10733','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:54:00',NULL,NULL),('vn-database','10736','00-workerBossNull.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-22 00:02:05',NULL,NULL),('vn-database','10739','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-10 10:19:07',NULL,NULL),('vn-database','10740','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL),('vn-database','10741','01-refactorCplusTrascendency472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','02-refactorCplusTrascendency477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','03-refactorCplusInvoiceType477.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','04-refactorCplusInvoiceType472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10741','05-fixes.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL),('vn-database','10744','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-13 09:23:19',NULL,NULL),('vn-database','10746','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-16 18:22:46',NULL,NULL),('vn-database','10747','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL),('vn-database','10748','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:32',NULL,NULL),('vn-database','10748','01-SecondScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10749','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-22 16:08:17',NULL,NULL),('vn-database','10750','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-23 13:04:17',NULL,NULL),('vn-database','10750','00-ticket_addGrants.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10751','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10752','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-24 14:07:54',NULL,NULL),('vn-database','10753','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-10-24 14:37:21',NULL,NULL),('vn-database','10754','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:34',NULL,NULL),('vn-database','10755','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:35',NULL,NULL),('vn-database','10756','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-03 07:14:38',NULL,NULL),('vn-database','10757','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:57',NULL,NULL),('vn-database','10758','00-sectorType.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:18',NULL,NULL),('vn-database','10758','01-dipole.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:18',NULL,NULL),('vn-database','10761','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:58',NULL,NULL),('vn-database','10764','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-04 12:07:59',NULL,NULL),('vn-database','10768','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:37',NULL,NULL),('vn-database','10771','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:37',NULL,NULL),('vn-database','10773','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:38',NULL,NULL),('vn-database','10775','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:18:16',NULL,NULL),('vn-database','10778','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:38',NULL,NULL),('vn-database','10782','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:18:16',NULL,NULL),('vn-database','10783','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-24 14:49:17',NULL,NULL),('vn-database','10785','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:38',NULL,NULL),('vn-database','10785','02-invoiceIn.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:38',NULL,NULL),('vn-database','10785','02-invoiceInTax.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL),('vn-database','10785','02-item.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL),('vn-database','10789','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL),('vn-database','10792','00-buy.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:20:15',NULL,NULL),('vn-database','10798','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:21:14',NULL,NULL),('vn-database','10799','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-26 12:00:59',NULL,NULL),('vn-database','10800','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:21:16',NULL,NULL),('vn-database','10801','00-firstScript.sql','jenkins@test-db-proxy1.servers.dc.verdnatura.es','2024-01-11 05:53:13',NULL,NULL),('vn-database','10806','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-03 11:56:05',NULL,NULL),('vn-database','10810','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-04 14:29:30',NULL,NULL),('vn-database','10815','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-09 18:11:57',NULL,NULL),('vn-database','10827','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-23 12:32:13',NULL,NULL); /*!40000 ALTER TABLE `versionLog` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -54,13 +54,13 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:25 USE `account`; -- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db2.static.verdnatura.es Database: account -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -78,7 +78,7 @@ USE `account`; LOCK TABLES `role` WRITE; /*!40000 ALTER TABLE `role` DISABLE KEYS */; -INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 07:04:58','2023-06-08 16:47:57',NULL),(2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 07:04:58','2023-06-02 20:33:28',NULL),(3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(9,'developer','Desarrolladores del sistema',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(11,'account','Privilegios relacionados con el login',0,'2017-05-19 07:04:58','2017-09-20 17:06:35',NULL),(13,'teamBoss','Jefe de equipo/departamento',1,'2017-05-19 07:04:58','2021-06-30 13:29:30',NULL),(15,'logistic','Departamento de compras, responsables de la logistica',1,'2017-05-19 07:04:58','2018-02-12 10:50:10',NULL),(16,'logisticBoss','Jefe del departamento de logística',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(17,'adminBoss','Jefe del departamento de administración',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(18,'salesPerson','Departamento de ventas',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(19,'salesBoss','Jefe del departamento de ventas',1,'2017-05-19 07:04:58','2017-08-16 12:38:27',NULL),(20,'manager','Gerencia',1,'2017-06-01 14:57:02','2022-07-29 07:36:15',NULL),(21,'salesAssistant','Jefe auxiliar de ventas',1,'2017-08-16 12:40:52','2017-08-16 12:40:52',NULL),(22,'teamManager','Jefe de departamento con privilegios de auxiliar de venta.',1,'2017-09-07 09:08:12','2017-09-07 09:08:12',NULL),(30,'financialBoss','Director finaciero',1,'2017-09-21 11:05:36','2017-09-21 11:05:36',NULL),(31,'freelancer','Trabajadores por cuenta ajena',1,'2017-10-10 12:57:26','2017-10-10 12:59:27',NULL),(32,'ett','Trabajadores de empresa temporal',1,'2017-10-10 12:58:58','2017-10-10 12:59:20',NULL),(33,'invoicing','Personal con acceso a facturación',0,'2018-01-29 16:43:34','2018-01-29 16:43:34',NULL),(34,'agencyBoss','Jefe/a del departamento de agencias',1,'2018-01-29 16:44:39','2018-02-23 07:58:53',NULL),(35,'buyer','Departamento de compras',1,'2018-02-12 10:35:42','2018-02-12 10:35:42',NULL),(36,'replenisher','Trabajadores de camara',1,'2018-02-16 14:07:10','2019-04-12 05:38:08',NULL),(37,'hr','Gestor/a de recursos humanos',1,'2018-02-22 17:34:53','2018-02-22 17:34:53',NULL),(38,'hrBoss','Jefe/a de recursos humanos',1,'2018-02-22 17:35:09','2018-02-22 17:35:09',NULL),(39,'adminAssistant','Jefe auxiliar administrativo',1,'2018-02-23 10:37:36','2018-02-23 10:38:41',NULL),(40,'handmade','Departamento de confección',1,'2018-02-23 11:14:53','2018-02-23 11:39:12',NULL),(41,'handmadeBoss','Jefe de departamento de confección',1,'2018-02-23 11:15:09','2018-02-23 11:39:26',NULL),(42,'artificial','Departamento de artificial',1,'2018-02-23 11:39:59','2018-02-23 11:39:59',NULL),(43,'artificialBoss','Jefe del departamento de artificial',1,'2018-02-23 11:40:16','2018-02-23 11:40:16',NULL),(44,'accessory','Departamento de complementos',1,'2018-02-23 11:41:12','2018-02-23 11:41:12',NULL),(45,'accessoryBoss','Jefe del departamento de complementos',1,'2018-02-23 11:41:23','2018-02-23 11:41:23',NULL),(47,'cooler','Empleados de cámara',1,'2018-02-23 13:08:18','2018-02-23 13:08:18',NULL),(48,'coolerBoss','Jefe de cámara',1,'2018-02-23 13:12:01','2023-03-13 08:49:43',NULL),(49,'production','Empleado de producción',1,'2018-02-26 15:28:23','2021-02-12 09:42:35',NULL),(50,'productionBoss','Jefe de producción',1,'2018-02-26 15:34:12','2018-02-26 15:34:12',NULL),(51,'marketing','Departamento de marketing',1,'2018-03-01 07:28:39','2018-03-01 07:28:39',NULL),(52,'marketingBoss','Jefe del departamento de marketing',1,'2018-03-01 07:28:57','2018-03-01 07:28:57',NULL),(53,'insurance','Gestor de seguros de cambio',0,'2018-03-05 07:44:35','2019-02-01 13:47:57',NULL),(54,'itemPicker','Sacador en cámara',1,'2018-03-05 12:08:17','2018-03-05 12:08:17',NULL),(55,'itemPickerBoss','Jefe de sacadores',1,'2018-03-05 12:08:31','2018-03-05 12:08:31',NULL),(56,'delivery','Personal de reparto',1,'2018-05-30 06:07:02','2018-05-30 06:07:02',NULL),(57,'deliveryBoss','Jefe de personal de reparto',1,'2018-05-30 06:07:19','2018-05-30 06:07:19',NULL),(58,'packager','Departamento encajadores',1,'2019-01-21 12:43:45','2019-01-21 12:43:45',NULL),(59,'packagerBoss','Jefe departamento encajadores',1,'2019-01-21 12:44:10','2019-01-21 12:44:10',NULL),(60,'productionAssi','Tareas relacionadas con producción y administración',1,'2019-01-29 13:29:01','2019-01-29 13:29:01',NULL),(61,'replenisherBos','Jefe de Complementos/Camara',1,'2019-07-01 06:44:07','2019-07-01 06:44:07',NULL),(62,'noLogin','Role without login access to MySQL',0,'2019-07-01 06:50:19','2019-07-02 13:42:05',NULL),(64,'balanceSheet','Consulta de Balance',0,'2019-07-16 12:12:08','2019-07-16 12:12:08',NULL),(65,'officeBoss','Jefe de filial',1,'2019-08-02 06:54:26','2019-08-02 06:54:26',NULL),(66,'sysadmin','Administrador de sistema',1,'2019-08-08 06:58:56','2019-08-08 06:58:56',NULL),(67,'adminOfficer','categoria profesional oficial de administración',1,'2020-01-03 08:09:23','2020-01-03 08:09:23',NULL),(69,'coolerAssist','Asistente de cámara con permiso compras',1,'2020-02-05 12:36:09','2023-03-13 08:50:07',NULL),(70,'trainee','Alumno de prácticas',1,'2020-03-04 11:00:25','2020-03-04 11:00:25',NULL),(71,'checker','Rol de revisor con privilegios de itemPicker',1,'2020-10-02 10:50:07','2020-10-02 10:50:07',NULL),(72,'claimManager','Personal de reclamaciones',1,'2020-10-13 10:01:32','2020-10-26 07:29:46',NULL),(73,'financial','Departamento de finanzas',1,'2020-11-16 09:30:27','2020-11-16 09:30:27',NULL),(74,'userPhotos','Privilegios para subir fotos de usuario',1,'2021-02-03 10:24:27','2021-02-03 10:24:27',NULL),(75,'catalogPhotos','Privilegios para subir fotos del catálogo',1,'2021-02-03 10:24:27','2021-02-03 10:24:27',NULL),(76,'chat','Rol para utilizar el rocket chat',1,'2020-11-27 13:06:50','2020-12-17 07:49:41',NULL),(100,'root','Rol con todos los privilegios',0,'2018-04-23 14:33:36','2020-11-12 06:50:07',NULL),(101,'buyerBoss','Jefe del departamento de compras',1,'2021-06-16 09:53:17','2021-06-16 09:53:17',NULL),(102,'preservedBoss','Responsable preservado',1,'2021-09-14 13:45:37','2021-09-14 13:45:37',NULL),(103,'it','Departamento de informática',1,'2021-11-11 09:48:22','2021-11-11 09:48:22',NULL),(104,'itBoss','Jefe de departamento de informática',1,'2021-11-11 09:48:49','2021-11-11 09:48:49',NULL),(105,'grant','Adjudicar roles a usuarios',1,'2021-11-11 12:41:09','2021-11-11 12:41:09',NULL),(106,'ext','Usuarios externos de la Base de datos',1,'2021-11-23 14:51:16','2021-11-23 14:51:16',NULL),(107,'productionPlus','Creado para pepe por orden de Juanvi',1,'2022-02-08 06:47:10','2022-02-08 06:47:10',NULL),(108,'system','System user',1,'2022-05-16 08:09:51','2022-05-16 08:09:51',NULL),(109,'salesTeamBoss','Jefe de equipo de comerciales',1,'2022-06-14 13:45:56','2022-06-14 13:45:56',NULL),(110,'palletizer','Paletizadores',1,'2022-12-02 12:56:22','2022-12-02 12:56:30',NULL),(111,'entryEditor','Entry editor',1,'2023-01-13 11:21:55','2023-01-13 11:21:55',NULL),(112,'maintenance','Personal de mantenimiento',1,'2023-01-19 06:23:35','2023-01-19 06:23:35',NULL),(114,'maintenanceBos','Jefe de mantenimiento',1,'2023-01-19 06:31:16','2023-05-17 11:07:21',NULL),(115,'itManagement','TI management',1,'2023-03-29 07:27:55','2023-03-29 07:28:04',NULL),(119,'palletizerBoss','Jefe de paletizadores',1,'2023-06-07 11:51:54','2023-06-07 11:51:54',NULL),(120,'developerBoss','Jefe de proyecto de desarrollo',1,'2023-06-19 07:07:21','2023-06-19 07:07:21',21709),(121,'buyerSalesAssistant','Rol para compradores que también son responsables de ventas',1,'2023-06-23 14:48:19','2023-06-23 14:48:19',NULL),(122,'logisticAssistant','Jefe auxiliar de logística',1,'2023-06-26 07:21:15','2023-06-26 07:21:15',NULL),(123,'deliveryAssistant','Jefe auxiliar repartos',1,'2023-10-05 06:47:48','2023-10-05 06:47:48',10578),(124,'hrBuyer','Recursos Humanos con Buyer',1,'2023-10-23 11:50:43','2023-10-23 11:50:43',NULL),(125,'claimViewer','Trabajadores que consulta las reclamaciones ',1,'2023-11-16 08:14:46','2023-11-16 08:14:46',10578),(126,'greenhouseBoss','Jefe de invernadero',1,'2023-11-16 13:32:13','2023-11-16 13:32:13',NULL); +INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 07:04:58','2023-06-08 16:47:57',NULL),(2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 07:04:58','2023-06-02 20:33:28',NULL),(3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(9,'developer','Desarrolladores del sistema',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(11,'account','Privilegios relacionados con el login',0,'2017-05-19 07:04:58','2017-09-20 17:06:35',NULL),(13,'teamBoss','Jefe de equipo/departamento',1,'2017-05-19 07:04:58','2021-06-30 13:29:30',NULL),(15,'logistic','Departamento de compras, responsables de la logistica',1,'2017-05-19 07:04:58','2018-02-12 10:50:10',NULL),(16,'logisticBoss','Jefe del departamento de logística',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(17,'adminBoss','Jefe del departamento de administración',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(18,'salesPerson','Departamento de ventas',1,'2017-05-19 07:04:58','2017-05-19 07:04:58',NULL),(19,'salesBoss','Jefe del departamento de ventas',1,'2017-05-19 07:04:58','2017-08-16 12:38:27',NULL),(20,'manager','Gerencia',1,'2017-06-01 14:57:02','2022-07-29 07:36:15',NULL),(21,'salesAssistant','Jefe auxiliar de ventas',1,'2017-08-16 12:40:52','2017-08-16 12:40:52',NULL),(22,'teamManager','Jefe de departamento con privilegios de auxiliar de venta.',1,'2017-09-07 09:08:12','2017-09-07 09:08:12',NULL),(30,'financialBoss','Director finaciero',1,'2017-09-21 11:05:36','2017-09-21 11:05:36',NULL),(31,'freelancer','Trabajadores por cuenta ajena',1,'2017-10-10 12:57:26','2017-10-10 12:59:27',NULL),(32,'ett','Trabajadores de empresa temporal',1,'2017-10-10 12:58:58','2017-10-10 12:59:20',NULL),(33,'invoicing','Personal con acceso a facturación',0,'2018-01-29 16:43:34','2018-01-29 16:43:34',NULL),(34,'agencyBoss','Jefe/a del departamento de agencias',1,'2018-01-29 16:44:39','2018-02-23 07:58:53',NULL),(35,'buyer','Departamento de compras',1,'2018-02-12 10:35:42','2018-02-12 10:35:42',NULL),(36,'replenisher','Trabajadores de camara',1,'2018-02-16 14:07:10','2019-04-12 05:38:08',NULL),(37,'hr','Gestor/a de recursos humanos',1,'2018-02-22 17:34:53','2018-02-22 17:34:53',NULL),(38,'hrBoss','Jefe/a de recursos humanos',1,'2018-02-22 17:35:09','2018-02-22 17:35:09',NULL),(39,'adminAssistant','Jefe auxiliar administrativo',1,'2018-02-23 10:37:36','2018-02-23 10:38:41',NULL),(40,'handmade','Departamento de confección',1,'2018-02-23 11:14:53','2018-02-23 11:39:12',NULL),(41,'handmadeBoss','Jefe de departamento de confección',1,'2018-02-23 11:15:09','2018-02-23 11:39:26',NULL),(42,'artificial','Departamento de artificial',1,'2018-02-23 11:39:59','2018-02-23 11:39:59',NULL),(43,'artificialBoss','Jefe del departamento de artificial',1,'2018-02-23 11:40:16','2018-02-23 11:40:16',NULL),(44,'accessory','Departamento de complementos',1,'2018-02-23 11:41:12','2018-02-23 11:41:12',NULL),(45,'accessoryBoss','Jefe del departamento de complementos',1,'2018-02-23 11:41:23','2018-02-23 11:41:23',NULL),(47,'cooler','Empleados de cámara',1,'2018-02-23 13:08:18','2018-02-23 13:08:18',NULL),(48,'coolerBoss','Jefe de cámara',1,'2018-02-23 13:12:01','2023-03-13 08:49:43',NULL),(49,'production','Empleado de producción',1,'2018-02-26 15:28:23','2021-02-12 09:42:35',NULL),(50,'productionBoss','Jefe de producción',1,'2018-02-26 15:34:12','2018-02-26 15:34:12',NULL),(51,'marketing','Departamento de marketing',1,'2018-03-01 07:28:39','2018-03-01 07:28:39',NULL),(52,'marketingBoss','Jefe del departamento de marketing',1,'2018-03-01 07:28:57','2018-03-01 07:28:57',NULL),(53,'insurance','Gestor de seguros de cambio',0,'2018-03-05 07:44:35','2019-02-01 13:47:57',NULL),(54,'itemPicker','Sacador en cámara',1,'2018-03-05 12:08:17','2018-03-05 12:08:17',NULL),(55,'itemPickerBoss','Jefe de sacadores',1,'2018-03-05 12:08:31','2018-03-05 12:08:31',NULL),(56,'delivery','Personal de reparto',1,'2018-05-30 06:07:02','2018-05-30 06:07:02',NULL),(57,'deliveryBoss','Jefe de personal de reparto',1,'2018-05-30 06:07:19','2018-05-30 06:07:19',NULL),(58,'packager','Departamento encajadores',1,'2019-01-21 12:43:45','2019-01-21 12:43:45',NULL),(59,'packagerBoss','Jefe departamento encajadores',1,'2019-01-21 12:44:10','2019-01-21 12:44:10',NULL),(60,'productionAssi','Tareas relacionadas con producción y administración',1,'2019-01-29 13:29:01','2019-01-29 13:29:01',NULL),(61,'replenisherBos','Jefe de Complementos/Camara',1,'2019-07-01 06:44:07','2019-07-01 06:44:07',NULL),(62,'noLogin','Role without login access to MySQL',0,'2019-07-01 06:50:19','2019-07-02 13:42:05',NULL),(64,'balanceSheet','Consulta de Balance',0,'2019-07-16 12:12:08','2019-07-16 12:12:08',NULL),(65,'officeBoss','Jefe de filial',1,'2019-08-02 06:54:26','2019-08-02 06:54:26',NULL),(66,'sysadmin','Administrador de sistema',1,'2019-08-08 06:58:56','2019-08-08 06:58:56',NULL),(67,'adminOfficer','categoria profesional oficial de administración',1,'2020-01-03 08:09:23','2020-01-03 08:09:23',NULL),(69,'coolerAssist','Asistente de cámara con permiso compras',1,'2020-02-05 12:36:09','2023-03-13 08:50:07',NULL),(70,'trainee','Alumno de prácticas',1,'2020-03-04 11:00:25','2020-03-04 11:00:25',NULL),(71,'checker','Rol de revisor con privilegios de itemPicker',1,'2020-10-02 10:50:07','2020-10-02 10:50:07',NULL),(72,'claimManager','Personal de reclamaciones',1,'2020-10-13 10:01:32','2020-10-26 07:29:46',NULL),(73,'financial','Departamento de finanzas',1,'2020-11-16 09:30:27','2020-11-16 09:30:27',NULL),(74,'userPhotos','Privilegios para subir fotos de usuario',1,'2021-02-03 10:24:27','2021-02-03 10:24:27',NULL),(75,'catalogPhotos','Privilegios para subir fotos del catálogo',1,'2021-02-03 10:24:27','2021-02-03 10:24:27',NULL),(76,'chat','Rol para utilizar el rocket chat',1,'2020-11-27 13:06:50','2020-12-17 07:49:41',NULL),(100,'root','Rol con todos los privilegios',0,'2018-04-23 14:33:36','2020-11-12 06:50:07',NULL),(101,'buyerBoss','Jefe del departamento de compras',1,'2021-06-16 09:53:17','2021-06-16 09:53:17',NULL),(102,'preservedBoss','Responsable preservado',1,'2021-09-14 13:45:37','2021-09-14 13:45:37',NULL),(103,'it','Departamento de informática',1,'2021-11-11 09:48:22','2021-11-11 09:48:22',NULL),(104,'itBoss','Jefe de departamento de informática',1,'2021-11-11 09:48:49','2021-11-11 09:48:49',NULL),(105,'grant','Adjudicar roles a usuarios',1,'2021-11-11 12:41:09','2021-11-11 12:41:09',NULL),(106,'ext','Usuarios externos de la Base de datos',1,'2021-11-23 14:51:16','2021-11-23 14:51:16',NULL),(107,'productionPlus','Creado para pepe por orden de Juanvi',1,'2022-02-08 06:47:10','2022-02-08 06:47:10',NULL),(108,'system','System user',1,'2022-05-16 08:09:51','2022-05-16 08:09:51',NULL),(109,'salesTeamBoss','Jefe de equipo de comerciales',1,'2022-06-14 13:45:56','2022-06-14 13:45:56',NULL),(110,'palletizer','Paletizadores',1,'2022-12-02 12:56:22','2022-12-02 12:56:30',NULL),(111,'entryEditor','Entry editor',1,'2023-01-13 11:21:55','2023-01-13 11:21:55',NULL),(112,'maintenance','Personal de mantenimiento',1,'2023-01-19 06:23:35','2023-01-19 06:23:35',NULL),(114,'maintenanceBos','Jefe de mantenimiento',1,'2023-01-19 06:31:16','2023-05-17 11:07:21',NULL),(115,'itManagement','TI management',1,'2023-03-29 07:27:55','2023-03-29 07:28:04',NULL),(119,'palletizerBoss','Jefe de paletizadores',1,'2023-06-07 11:51:54','2023-06-07 11:51:54',NULL),(120,'developerBoss','Jefe de proyecto de desarrollo',1,'2023-06-19 07:07:21','2023-06-19 07:07:21',21709),(121,'buyerSalesAssistant','Rol para compradores que también son responsables de ventas',1,'2023-06-23 14:48:19','2023-06-23 14:48:19',NULL),(122,'logisticAssistant','Jefe auxiliar de logística',1,'2023-06-26 07:21:15','2023-06-26 07:21:15',NULL),(123,'deliveryAssistant','Jefe auxiliar repartos',1,'2023-10-05 06:47:48','2023-10-05 06:47:48',10578),(124,'hrBuyer','Recursos Humanos con Buyer',1,'2023-10-23 11:50:43','2023-10-23 11:50:43',NULL),(125,'claimViewer','Trabajadores que consulta las reclamaciones ',1,'2023-11-16 08:14:46','2023-11-16 08:14:46',10578),(126,'greenhouseBoss','Jefe de invernadero',1,'2023-11-16 13:32:13','2023-11-16 13:32:13',NULL),(127,'timeControl','Tablet para fichar',1,'2024-01-09 15:36:56','2024-01-09 15:36:56',NULL); /*!40000 ALTER TABLE `role` ENABLE KEYS */; UNLOCK TABLES; @@ -88,7 +88,7 @@ UNLOCK TABLES; LOCK TABLES `roleInherit` WRITE; /*!40000 ALTER TABLE `roleInherit` DISABLE KEYS */; -INSERT INTO `roleInherit` VALUES (1,1,2,NULL),(2,1,3,NULL),(3,1,70,NULL),(4,2,11,NULL),(5,3,11,NULL),(6,5,1,NULL),(8,5,33,NULL),(10,11,6,NULL),(11,13,1,NULL),(12,15,35,NULL),(16,17,20,NULL),(17,17,37,NULL),(18,17,39,NULL),(19,17,64,NULL),(20,18,1,NULL),(21,19,21,NULL),(22,20,13,NULL),(23,20,16,NULL),(24,20,65,NULL),(25,21,13,NULL),(26,21,18,NULL),(27,21,53,NULL),(28,22,13,NULL),(29,22,21,NULL),(30,30,5,NULL),(31,30,20,NULL),(32,30,22,NULL),(33,30,53,NULL),(34,30,64,NULL),(35,31,1,NULL),(36,32,1,NULL),(37,34,1,NULL),(38,34,13,NULL),(39,34,33,NULL),(40,35,1,NULL),(41,36,44,NULL),(42,36,47,NULL),(43,37,1,NULL),(44,38,37,NULL),(45,38,64,NULL),(46,39,5,NULL),(47,39,21,NULL),(48,39,57,NULL),(49,40,1,NULL),(50,40,49,NULL),(51,41,13,NULL),(52,41,35,NULL),(53,41,40,NULL),(54,42,35,NULL),(55,42,49,NULL),(56,43,13,NULL),(57,43,42,NULL),(58,44,1,NULL),(59,45,13,NULL),(60,45,44,NULL),(61,47,1,NULL),(62,48,13,NULL),(63,48,47,NULL),(64,49,36,NULL),(65,49,58,NULL),(66,50,13,NULL),(67,50,21,NULL),(70,50,57,NULL),(72,51,1,NULL),(73,52,13,NULL),(74,52,19,NULL),(76,52,51,NULL),(77,53,1,NULL),(78,54,1,NULL),(79,55,13,NULL),(80,55,54,NULL),(81,56,1,NULL),(84,58,1,NULL),(85,59,13,NULL),(87,60,5,NULL),(91,61,13,NULL),(92,61,36,NULL),(94,65,35,NULL),(97,67,5,NULL),(98,67,37,NULL),(99,69,35,NULL),(101,70,11,NULL),(102,71,1,NULL),(103,71,58,NULL),(105,72,18,NULL),(106,73,5,NULL),(107,73,64,NULL),(108,73,19,NULL),(109,59,50,NULL),(115,39,76,NULL),(117,65,76,NULL),(118,30,76,NULL),(124,5,76,NULL),(125,37,76,NULL),(126,38,76,NULL),(128,42,76,NULL),(129,35,76,NULL),(130,60,76,NULL),(131,21,76,NULL),(132,18,76,NULL),(133,50,76,NULL),(134,20,76,NULL),(135,41,76,NULL),(136,17,76,NULL),(137,52,76,NULL),(139,37,74,NULL),(140,51,74,NULL),(141,51,75,NULL),(142,35,75,NULL),(143,15,49,NULL),(145,17,67,NULL),(146,38,13,NULL),(147,101,35,NULL),(148,101,13,NULL),(150,15,56,NULL),(152,69,47,NULL),(153,48,35,NULL),(154,102,1,NULL),(167,9,103,NULL),(168,66,9,NULL),(169,104,100,NULL),(172,103,76,NULL),(173,103,1,NULL),(174,103,44,NULL),(175,103,45,NULL),(176,103,11,NULL),(177,103,39,NULL),(178,103,17,NULL),(179,103,5,NULL),(180,103,67,NULL),(181,103,3,NULL),(182,103,34,NULL),(183,103,42,NULL),(184,103,43,NULL),(185,103,64,NULL),(186,103,35,NULL),(187,103,101,NULL),(188,103,75,NULL),(189,103,71,NULL),(190,103,72,NULL),(191,103,47,NULL),(192,103,69,NULL),(193,103,48,NULL),(194,103,2,NULL),(195,103,56,NULL),(196,103,57,NULL),(197,103,32,NULL),(198,103,73,NULL),(199,103,30,NULL),(200,103,31,NULL),(201,103,6,NULL),(202,103,40,NULL),(203,103,41,NULL),(204,103,37,NULL),(205,103,38,NULL),(206,103,53,NULL),(207,103,33,NULL),(210,103,54,NULL),(211,103,55,NULL),(212,103,15,NULL),(213,103,16,NULL),(215,103,51,NULL),(216,103,52,NULL),(218,103,65,NULL),(219,103,58,NULL),(220,103,59,NULL),(221,103,102,NULL),(222,103,49,NULL),(223,103,60,NULL),(224,103,50,NULL),(225,103,36,NULL),(226,103,61,NULL),(228,103,21,NULL),(229,103,19,NULL),(230,103,18,NULL),(231,103,13,NULL),(232,103,22,NULL),(233,103,70,NULL),(234,103,74,NULL),(237,66,103,NULL),(238,103,20,NULL),(239,106,11,NULL),(240,107,60,NULL),(241,21,72,NULL),(242,20,9,NULL),(246,102,35,NULL),(247,108,1,NULL),(248,102,13,NULL),(249,109,18,NULL),(250,109,13,NULL),(251,51,21,NULL),(253,48,49,NULL),(254,110,1,NULL),(255,110,76,NULL),(256,48,69,NULL),(257,47,111,NULL),(258,43,111,NULL),(259,72,111,NULL),(260,35,111,NULL),(261,5,111,NULL),(262,112,1,NULL),(263,114,112,NULL),(264,51,35,NULL),(265,72,49,NULL),(266,101,18,NULL),(268,65,57,NULL),(269,65,59,NULL),(270,65,49,NULL),(271,65,18,NULL),(272,65,13,NULL),(273,60,35,NULL),(275,50,59,NULL),(276,60,49,NULL),(280,5,53,NULL),(281,5,18,NULL),(282,50,60,NULL),(283,5,21,NULL),(285,58,76,NULL),(287,69,58,NULL),(288,115,66,NULL),(290,104,115,NULL),(291,115,103,NULL),(297,21,33,NULL),(298,49,54,NULL),(299,112,49,NULL),(300,114,13,NULL),(302,5,35,NULL),(303,69,49,NULL),(306,119,110,NULL),(307,1,76,NULL),(309,120,9,NULL),(310,120,66,NULL),(311,120,13,25508),(312,115,120,NULL),(314,43,18,NULL),(315,121,35,NULL),(316,121,21,NULL),(317,122,15,NULL),(318,16,122,NULL),(319,37,49,NULL),(320,37,18,NULL),(328,57,123,10578),(329,123,33,NULL),(330,123,56,NULL),(332,103,112,NULL),(333,57,13,NULL),(334,60,123,NULL),(335,124,37,NULL),(336,124,35,NULL),(337,103,124,NULL),(338,35,125,10578),(339,57,125,10578),(340,41,125,10578),(341,18,125,10578),(346,126,15,NULL),(347,102,49,NULL); +INSERT INTO `roleInherit` VALUES (1,1,2,NULL),(2,1,3,NULL),(3,1,70,NULL),(4,2,11,NULL),(5,3,11,NULL),(6,5,1,NULL),(8,5,33,NULL),(10,11,6,NULL),(11,13,1,NULL),(12,15,35,NULL),(16,17,20,NULL),(17,17,37,NULL),(18,17,39,NULL),(19,17,64,NULL),(20,18,1,NULL),(21,19,21,NULL),(22,20,13,NULL),(23,20,16,NULL),(24,20,65,NULL),(25,21,13,NULL),(26,21,18,NULL),(27,21,53,NULL),(28,22,13,NULL),(29,22,21,NULL),(30,30,5,NULL),(31,30,20,NULL),(32,30,22,NULL),(33,30,53,NULL),(34,30,64,NULL),(35,31,1,NULL),(36,32,1,NULL),(37,34,1,NULL),(38,34,13,NULL),(39,34,33,NULL),(40,35,1,NULL),(42,36,47,NULL),(43,37,1,NULL),(44,38,37,NULL),(45,38,64,NULL),(46,39,5,NULL),(47,39,21,NULL),(48,39,57,NULL),(49,40,1,NULL),(50,40,49,NULL),(51,41,13,NULL),(52,41,35,NULL),(53,41,40,NULL),(54,42,35,NULL),(55,42,49,NULL),(56,43,13,NULL),(57,43,42,NULL),(58,44,1,NULL),(59,45,13,NULL),(60,45,44,NULL),(61,47,1,NULL),(62,48,13,NULL),(63,48,47,NULL),(64,49,36,NULL),(65,49,58,NULL),(66,50,13,NULL),(67,50,21,NULL),(70,50,57,NULL),(72,51,1,NULL),(73,52,13,NULL),(74,52,19,NULL),(76,52,51,NULL),(77,53,1,NULL),(78,54,1,NULL),(79,55,13,NULL),(80,55,54,NULL),(81,56,1,NULL),(84,58,1,NULL),(85,59,13,NULL),(87,60,5,NULL),(91,61,13,NULL),(92,61,36,NULL),(94,65,35,NULL),(97,67,5,NULL),(98,67,37,NULL),(99,69,35,NULL),(101,70,11,NULL),(102,71,1,NULL),(103,71,58,NULL),(105,72,18,NULL),(106,73,5,NULL),(107,73,64,NULL),(108,73,19,NULL),(109,59,50,NULL),(115,39,76,NULL),(117,65,76,NULL),(118,30,76,NULL),(124,5,76,NULL),(125,37,76,NULL),(126,38,76,NULL),(128,42,76,NULL),(129,35,76,NULL),(130,60,76,NULL),(131,21,76,NULL),(132,18,76,NULL),(133,50,76,NULL),(134,20,76,NULL),(135,41,76,NULL),(136,17,76,NULL),(137,52,76,NULL),(139,37,74,NULL),(140,51,74,NULL),(141,51,75,NULL),(142,35,75,NULL),(143,15,49,NULL),(145,17,67,NULL),(146,38,13,NULL),(147,101,35,NULL),(148,101,13,NULL),(150,15,56,NULL),(152,69,47,NULL),(153,48,35,NULL),(154,102,1,NULL),(167,9,103,NULL),(168,66,9,NULL),(169,104,100,NULL),(172,103,76,NULL),(173,103,1,NULL),(174,103,44,NULL),(175,103,45,NULL),(176,103,11,NULL),(177,103,39,NULL),(178,103,17,NULL),(179,103,5,NULL),(180,103,67,NULL),(181,103,3,NULL),(182,103,34,NULL),(183,103,42,NULL),(184,103,43,NULL),(185,103,64,NULL),(186,103,35,NULL),(187,103,101,NULL),(188,103,75,NULL),(189,103,71,NULL),(190,103,72,NULL),(191,103,47,NULL),(192,103,69,NULL),(193,103,48,NULL),(194,103,2,NULL),(195,103,56,NULL),(196,103,57,NULL),(197,103,32,NULL),(198,103,73,NULL),(199,103,30,NULL),(200,103,31,NULL),(201,103,6,NULL),(202,103,40,NULL),(203,103,41,NULL),(204,103,37,NULL),(205,103,38,NULL),(206,103,53,NULL),(207,103,33,NULL),(210,103,54,NULL),(211,103,55,NULL),(212,103,15,NULL),(213,103,16,NULL),(215,103,51,NULL),(216,103,52,NULL),(218,103,65,NULL),(219,103,58,NULL),(220,103,59,NULL),(221,103,102,NULL),(222,103,49,NULL),(223,103,60,NULL),(224,103,50,NULL),(225,103,36,NULL),(226,103,61,NULL),(228,103,21,NULL),(229,103,19,NULL),(230,103,18,NULL),(231,103,13,NULL),(232,103,22,NULL),(233,103,70,NULL),(234,103,74,NULL),(237,66,103,NULL),(238,103,20,NULL),(239,106,11,NULL),(240,107,60,NULL),(241,21,72,NULL),(242,20,9,NULL),(246,102,35,NULL),(247,108,1,NULL),(248,102,13,NULL),(249,109,18,NULL),(250,109,13,NULL),(251,51,21,NULL),(253,48,49,NULL),(254,110,1,NULL),(255,110,76,NULL),(256,48,69,NULL),(257,47,111,NULL),(258,43,111,NULL),(259,72,111,NULL),(260,35,111,NULL),(261,5,111,NULL),(262,112,1,NULL),(263,114,112,NULL),(264,51,35,NULL),(265,72,49,NULL),(266,101,18,NULL),(268,65,57,NULL),(269,65,59,NULL),(270,65,49,NULL),(271,65,18,NULL),(272,65,13,NULL),(273,60,35,NULL),(275,50,59,NULL),(276,60,49,NULL),(280,5,53,NULL),(281,5,18,NULL),(282,50,60,NULL),(283,5,21,NULL),(285,58,76,NULL),(288,115,66,NULL),(290,104,115,NULL),(291,115,103,NULL),(297,21,33,NULL),(298,49,54,NULL),(299,112,49,NULL),(300,114,13,NULL),(302,5,35,NULL),(303,69,49,NULL),(306,119,110,NULL),(307,1,76,NULL),(309,120,9,NULL),(310,120,66,NULL),(311,120,13,25508),(312,115,120,NULL),(314,43,18,NULL),(315,121,35,NULL),(316,121,21,NULL),(317,122,15,NULL),(318,16,122,NULL),(319,37,49,NULL),(320,37,18,NULL),(328,57,123,10578),(329,123,33,NULL),(330,123,56,NULL),(332,103,112,NULL),(333,57,13,NULL),(334,60,123,NULL),(335,124,37,NULL),(336,124,35,NULL),(337,103,124,NULL),(338,35,125,10578),(339,57,125,10578),(340,41,125,10578),(341,18,125,10578),(346,126,15,NULL),(347,102,49,NULL),(350,49,75,NULL),(351,72,35,NULL),(353,110,49,NULL),(354,103,119,NULL),(355,127,11,NULL),(356,123,125,NULL),(357,36,35,NULL),(358,36,49,NULL); /*!40000 ALTER TABLE `roleInherit` ENABLE KEYS */; UNLOCK TABLES; @@ -98,7 +98,7 @@ UNLOCK TABLES; LOCK TABLES `roleRole` WRITE; /*!40000 ALTER TABLE `roleRole` DISABLE KEYS */; -INSERT INTO `roleRole` VALUES (326595,1,1),(326596,1,2),(326597,1,3),(326601,1,6),(326600,1,11),(326598,1,70),(326599,1,76),(326602,2,2),(326604,2,6),(326603,2,11),(326605,3,3),(326607,3,6),(326606,3,11),(326609,5,1),(326623,5,2),(326622,5,3),(326608,5,5),(326629,5,6),(326625,5,11),(326619,5,13),(326610,5,18),(326611,5,21),(326612,5,33),(326613,5,35),(326628,5,36),(326631,5,44),(326630,5,47),(326624,5,49),(326614,5,53),(326627,5,54),(326626,5,58),(326621,5,70),(326618,5,72),(326617,5,75),(326615,5,76),(326616,5,111),(326620,5,125),(326632,6,6),(326635,9,1),(326636,9,2),(326637,9,3),(326638,9,5),(326639,9,6),(326633,9,9),(326640,9,11),(326641,9,13),(326642,9,15),(326643,9,16),(326644,9,17),(326645,9,18),(326646,9,19),(326647,9,20),(326648,9,21),(326649,9,22),(326650,9,30),(326651,9,31),(326652,9,32),(326653,9,33),(326654,9,34),(326655,9,35),(326656,9,36),(326657,9,37),(326658,9,38),(326659,9,39),(326660,9,40),(326661,9,41),(326662,9,42),(326663,9,43),(326664,9,44),(326665,9,45),(326666,9,47),(326667,9,48),(326668,9,49),(326669,9,50),(326670,9,51),(326671,9,52),(326672,9,53),(326673,9,54),(326674,9,55),(326675,9,56),(326676,9,57),(326677,9,58),(326678,9,59),(326679,9,60),(326680,9,61),(326681,9,64),(326682,9,65),(326683,9,67),(326684,9,69),(326685,9,70),(326686,9,71),(326687,9,72),(326688,9,73),(326689,9,74),(326690,9,75),(326691,9,76),(326692,9,101),(326693,9,102),(326634,9,103),(326699,9,111),(326694,9,112),(326698,9,122),(326696,9,123),(326695,9,124),(326697,9,125),(326701,11,6),(326700,11,11),(326703,13,1),(326704,13,2),(326705,13,3),(326709,13,6),(326708,13,11),(326702,13,13),(326706,13,70),(326707,13,76),(326716,15,1),(326726,15,2),(326725,15,3),(326728,15,6),(326727,15,11),(326710,15,15),(326711,15,35),(326719,15,36),(326723,15,44),(326722,15,47),(326712,15,49),(326720,15,54),(326713,15,56),(326721,15,58),(326724,15,70),(326715,15,75),(326714,15,76),(326717,15,111),(326718,15,125),(326737,16,1),(326747,16,2),(326746,16,3),(326749,16,6),(326748,16,11),(326731,16,15),(326729,16,16),(326732,16,35),(326740,16,36),(326744,16,44),(326743,16,47),(326733,16,49),(326741,16,54),(326734,16,56),(326742,16,58),(326745,16,70),(326736,16,75),(326735,16,76),(326738,16,111),(326730,16,122),(326739,16,125),(326758,17,1),(326774,17,2),(326773,17,3),(326765,17,5),(326799,17,6),(326762,17,9),(326798,17,11),(326761,17,13),(326797,17,15),(326760,17,16),(326750,17,17),(326757,17,18),(326796,17,19),(326751,17,20),(326766,17,21),(326795,17,22),(326794,17,30),(326793,17,31),(326792,17,32),(326779,17,33),(326791,17,34),(326776,17,35),(326770,17,36),(326752,17,37),(326790,17,38),(326753,17,39),(326789,17,40),(326788,17,41),(326787,17,42),(326786,17,43),(326785,17,44),(326784,17,45),(326800,17,47),(326801,17,48),(326763,17,49),(326802,17,50),(326803,17,51),(326804,17,52),(326780,17,53),(326769,17,54),(326805,17,55),(326806,17,56),(326767,17,57),(326768,17,58),(326775,17,59),(326807,17,60),(326808,17,61),(326754,17,64),(326759,17,65),(326755,17,67),(326809,17,69),(326772,17,70),(326810,17,71),(326782,17,72),(326811,17,73),(326764,17,74),(326812,17,75),(326756,17,76),(326813,17,101),(326814,17,102),(326778,17,103),(326781,17,111),(326815,17,112),(326777,17,122),(326783,17,123),(326816,17,124),(326771,17,125),(326818,18,1),(326823,18,2),(326822,18,3),(326825,18,6),(326824,18,11),(326817,18,18),(326821,18,70),(326819,18,76),(326820,18,125),(326837,19,1),(326843,19,2),(326842,19,3),(326847,19,6),(326846,19,11),(326828,19,13),(326829,19,18),(326826,19,19),(326827,19,21),(326830,19,33),(326840,19,36),(326845,19,44),(326844,19,47),(326835,19,49),(326831,19,53),(326839,19,54),(326838,19,58),(326841,19,70),(326832,19,72),(326833,19,76),(326834,19,111),(326836,19,125),(326857,20,1),(326869,20,2),(326868,20,3),(326867,20,5),(326866,20,6),(326849,20,9),(326865,20,11),(326850,20,13),(326864,20,15),(326851,20,16),(326863,20,17),(326855,20,18),(326862,20,19),(326848,20,20),(326870,20,21),(326871,20,22),(326872,20,30),(326873,20,31),(326874,20,32),(326875,20,33),(326876,20,34),(326854,20,35),(326877,20,36),(326878,20,37),(326879,20,38),(326880,20,39),(326881,20,40),(326882,20,41),(326883,20,42),(326884,20,43),(326885,20,44),(326886,20,45),(326887,20,47),(326888,20,48),(326859,20,49),(326889,20,50),(326890,20,51),(326891,20,52),(326892,20,53),(326893,20,54),(326894,20,55),(326895,20,56),(326860,20,57),(326896,20,58),(326861,20,59),(326897,20,60),(326898,20,61),(326899,20,64),(326852,20,65),(326900,20,67),(326901,20,69),(326902,20,70),(326903,20,71),(326904,20,72),(326905,20,73),(326906,20,74),(326907,20,75),(326853,20,76),(326908,20,101),(326909,20,102),(326858,20,103),(326913,20,111),(326910,20,112),(326856,20,122),(326914,20,123),(326911,20,124),(326912,20,125),(326925,21,1),(326931,21,2),(326930,21,3),(326935,21,6),(326934,21,11),(326916,21,13),(326917,21,18),(326915,21,21),(326918,21,33),(326928,21,36),(326933,21,44),(326932,21,47),(326923,21,49),(326919,21,53),(326927,21,54),(326926,21,58),(326929,21,70),(326920,21,72),(326921,21,76),(326922,21,111),(326924,21,125),(326940,22,1),(326950,22,2),(326949,22,3),(326957,22,6),(326954,22,11),(326937,22,13),(326939,22,18),(326938,22,21),(326936,22,22),(326941,22,33),(326953,22,36),(326956,22,44),(326955,22,47),(326946,22,49),(326942,22,53),(326952,22,54),(326951,22,58),(326948,22,70),(326943,22,72),(326944,22,76),(326945,22,111),(326947,22,125),(326970,30,1),(326984,30,2),(326983,30,3),(326959,30,5),(326995,30,6),(326971,30,9),(326996,30,11),(326972,30,13),(326994,30,15),(326973,30,16),(326993,30,17),(326969,30,18),(326992,30,19),(326960,30,20),(326968,30,21),(326961,30,22),(326958,30,30),(326991,30,31),(326990,30,32),(326967,30,33),(326989,30,34),(326966,30,35),(326988,30,36),(326987,30,37),(326986,30,38),(326997,30,39),(326998,30,40),(326999,30,41),(327000,30,42),(327001,30,43),(327002,30,44),(327003,30,45),(327004,30,47),(327005,30,48),(326976,30,49),(327006,30,50),(327007,30,51),(327008,30,52),(326962,30,53),(327009,30,54),(327010,30,55),(327011,30,56),(326975,30,57),(327012,30,58),(326985,30,59),(327013,30,60),(327014,30,61),(326963,30,64),(326974,30,65),(327015,30,67),(327016,30,69),(326982,30,70),(327017,30,71),(326980,30,72),(327018,30,73),(327019,30,74),(326979,30,75),(326964,30,76),(327020,30,101),(327021,30,102),(326978,30,103),(326965,30,111),(327022,30,112),(326977,30,122),(327024,30,123),(327023,30,124),(326981,30,125),(327026,31,1),(327027,31,2),(327028,31,3),(327032,31,6),(327031,31,11),(327025,31,31),(327029,31,70),(327030,31,76),(327034,32,1),(327035,32,2),(327036,32,3),(327040,32,6),(327039,32,11),(327033,32,32),(327037,32,70),(327038,32,76),(327041,33,33),(327043,34,1),(327048,34,2),(327047,34,3),(327051,34,6),(327050,34,11),(327044,34,13),(327045,34,33),(327042,34,34),(327046,34,70),(327049,34,76),(327053,35,1),(327060,35,2),(327059,35,3),(327062,35,6),(327061,35,11),(327052,35,35),(327058,35,70),(327054,35,75),(327055,35,76),(327056,35,111),(327057,35,125),(327067,36,1),(327069,36,2),(327068,36,3),(327073,36,6),(327072,36,11),(327063,36,36),(327064,36,44),(327065,36,47),(327070,36,70),(327071,36,76),(327066,36,111),(327075,37,1),(327084,37,2),(327083,37,3),(327091,37,6),(327089,37,11),(327076,37,18),(327080,37,36),(327074,37,37),(327088,37,44),(327087,37,47),(327077,37,49),(327085,37,54),(327086,37,58),(327082,37,70),(327078,37,74),(327079,37,76),(327090,37,111),(327081,37,125),(327100,38,1),(327104,38,2),(327103,38,3),(327112,38,6),(327110,38,11),(327093,38,13),(327099,38,18),(327105,38,36),(327094,38,37),(327092,38,38),(327109,38,44),(327108,38,47),(327098,38,49),(327106,38,54),(327107,38,58),(327095,38,64),(327102,38,70),(327097,38,74),(327096,38,76),(327111,38,111),(327101,38,125),(327121,39,1),(327133,39,2),(327132,39,3),(327114,39,5),(327140,39,6),(327137,39,11),(327124,39,13),(327120,39,18),(327115,39,21),(327119,39,33),(327118,39,35),(327136,39,36),(327113,39,39),(327139,39,44),(327138,39,47),(327129,39,49),(327122,39,53),(327135,39,54),(327128,39,56),(327116,39,57),(327134,39,58),(327131,39,70),(327125,39,72),(327130,39,75),(327117,39,76),(327123,39,111),(327126,39,123),(327127,39,125),(327142,40,1),(327145,40,2),(327144,40,3),(327155,40,6),(327153,40,11),(327148,40,36),(327141,40,40),(327152,40,44),(327151,40,47),(327143,40,49),(327149,40,54),(327150,40,58),(327146,40,70),(327147,40,76),(327154,40,111),(327165,41,1),(327170,41,2),(327169,41,3),(327175,41,6),(327174,41,11),(327157,41,13),(327158,41,35),(327167,41,36),(327159,41,40),(327156,41,41),(327173,41,44),(327172,41,47),(327162,41,49),(327166,41,54),(327171,41,58),(327168,41,70),(327164,41,75),(327160,41,76),(327163,41,111),(327161,41,125),(327182,42,1),(327191,42,2),(327190,42,3),(327193,42,6),(327192,42,11),(327177,42,35),(327184,42,36),(327176,42,42),(327188,42,44),(327187,42,47),(327178,42,49),(327185,42,54),(327186,42,58),(327189,42,70),(327181,42,75),(327179,42,76),(327180,42,111),(327183,42,125),(327202,43,1),(327208,43,2),(327207,43,3),(327214,43,6),(327213,43,11),(327195,43,13),(327196,43,18),(327199,43,35),(327204,43,36),(327197,43,42),(327194,43,43),(327212,43,44),(327211,43,47),(327203,43,49),(327209,43,54),(327210,43,58),(327206,43,70),(327205,43,75),(327201,43,76),(327198,43,111),(327200,43,125),(327216,44,1),(327217,44,2),(327218,44,3),(327222,44,6),(327221,44,11),(327215,44,44),(327219,44,70),(327220,44,76),(327226,45,1),(327228,45,2),(327227,45,3),(327232,45,6),(327231,45,11),(327224,45,13),(327225,45,44),(327223,45,45),(327229,45,70),(327230,45,76),(327234,47,1),(327237,47,2),(327236,47,3),(327241,47,6),(327240,47,11),(327233,47,47),(327238,47,70),(327239,47,76),(327235,47,111),(327252,48,1),(327259,48,2),(327258,48,3),(327261,48,6),(327260,48,11),(327243,48,13),(327244,48,35),(327253,48,36),(327256,48,44),(327245,48,47),(327242,48,48),(327246,48,49),(327254,48,54),(327255,48,58),(327247,48,69),(327257,48,70),(327251,48,75),(327250,48,76),(327249,48,111),(327248,48,125),(327266,49,1),(327272,49,2),(327271,49,3),(327275,49,6),(327274,49,11),(327263,49,36),(327268,49,44),(327267,49,47),(327262,49,49),(327264,49,54),(327265,49,58),(327270,49,70),(327269,49,76),(327273,49,111),(327288,50,1),(327301,50,2),(327300,50,3),(327290,50,5),(327305,50,6),(327304,50,11),(327277,50,13),(327287,50,18),(327278,50,21),(327286,50,33),(327291,50,35),(327295,50,36),(327303,50,44),(327302,50,47),(327292,50,49),(327276,50,50),(327285,50,53),(327294,50,54),(327297,50,56),(327279,50,57),(327293,50,58),(327280,50,59),(327281,50,60),(327299,50,70),(327284,50,72),(327296,50,75),(327282,50,76),(327298,50,111),(327283,50,123),(327289,50,125),(327307,51,1),(327316,51,2),(327315,51,3),(327328,51,6),(327324,51,11),(327312,51,13),(327317,51,18),(327308,51,21),(327318,51,33),(327309,51,35),(327327,51,36),(327330,51,44),(327329,51,47),(327323,51,49),(327306,51,51),(327319,51,53),(327326,51,54),(327325,51,58),(327314,51,70),(327320,51,72),(327310,51,74),(327311,51,75),(327313,51,76),(327321,51,111),(327322,51,125),(327339,52,1),(327345,52,2),(327344,52,3),(327355,52,6),(327351,52,11),(327332,52,13),(327342,52,18),(327333,52,19),(327338,52,21),(327341,52,33),(327337,52,35),(327354,52,36),(327357,52,44),(327356,52,47),(327350,52,49),(327334,52,51),(327331,52,52),(327346,52,53),(327353,52,54),(327352,52,58),(327343,52,70),(327347,52,72),(327336,52,74),(327340,52,75),(327335,52,76),(327348,52,111),(327349,52,125),(327359,53,1),(327360,53,2),(327361,53,3),(327365,53,6),(327364,53,11),(327358,53,53),(327362,53,70),(327363,53,76),(327367,54,1),(327368,54,2),(327369,54,3),(327373,54,6),(327372,54,11),(327366,54,54),(327370,54,70),(327371,54,76),(327377,55,1),(327379,55,2),(327378,55,3),(327383,55,6),(327382,55,11),(327375,55,13),(327376,55,54),(327374,55,55),(327380,55,70),(327381,55,76),(327385,56,1),(327386,56,2),(327387,56,3),(327391,56,6),(327390,56,11),(327384,56,56),(327388,56,70),(327389,56,76),(327398,57,1),(327401,57,2),(327400,57,3),(327404,57,6),(327403,57,11),(327393,57,13),(327397,57,33),(327396,57,56),(327392,57,57),(327399,57,70),(327402,57,76),(327394,57,123),(327395,57,125),(327406,58,1),(327409,58,2),(327408,58,3),(327412,58,6),(327411,58,11),(327405,58,58),(327410,58,70),(327407,58,76),(327417,59,1),(327425,59,2),(327424,59,3),(327430,59,5),(327442,59,6),(327439,59,11),(327414,59,13),(327422,59,18),(327416,59,21),(327421,59,33),(327431,59,35),(327435,59,36),(327441,59,44),(327440,59,47),(327432,59,49),(327415,59,50),(327426,59,53),(327434,59,54),(327437,59,56),(327418,59,57),(327433,59,58),(327413,59,59),(327419,59,60),(327423,59,70),(327427,59,72),(327436,59,75),(327420,59,76),(327438,59,111),(327428,59,123),(327429,59,125),(327453,60,1),(327467,60,2),(327466,60,3),(327444,60,5),(327469,60,6),(327468,60,11),(327464,60,13),(327452,60,18),(327451,60,21),(327450,60,33),(327445,60,35),(327457,60,36),(327462,60,44),(327461,60,47),(327446,60,49),(327449,60,53),(327458,60,54),(327460,60,56),(327459,60,58),(327443,60,60),(327465,60,70),(327463,60,72),(327455,60,75),(327447,60,76),(327454,60,111),(327448,60,123),(327456,60,125),(327474,61,1),(327478,61,2),(327477,61,3),(327482,61,6),(327481,61,11),(327471,61,13),(327472,61,36),(327473,61,44),(327475,61,47),(327470,61,61),(327476,61,70),(327479,61,76),(327480,61,111),(327483,62,62),(327484,64,64),(327499,65,1),(327510,65,2),(327509,65,3),(327511,65,5),(327515,65,6),(327514,65,11),(327486,65,13),(327487,65,18),(327503,65,21),(327505,65,33),(327488,65,35),(327495,65,36),(327507,65,44),(327506,65,47),(327489,65,49),(327501,65,50),(327513,65,53),(327494,65,54),(327504,65,56),(327490,65,57),(327493,65,58),(327491,65,59),(327502,65,60),(327485,65,65),(327508,65,70),(327512,65,72),(327497,65,75),(327492,65,76),(327496,65,111),(327500,65,123),(327498,65,125),(327520,66,1),(327519,66,2),(327521,66,3),(327522,66,5),(327523,66,6),(327517,66,9),(327524,66,11),(327525,66,13),(327526,66,15),(327527,66,16),(327528,66,17),(327529,66,18),(327530,66,19),(327531,66,20),(327532,66,21),(327533,66,22),(327534,66,30),(327535,66,31),(327536,66,32),(327537,66,33),(327538,66,34),(327539,66,35),(327540,66,36),(327541,66,37),(327542,66,38),(327543,66,39),(327544,66,40),(327545,66,41),(327546,66,42),(327547,66,43),(327548,66,44),(327549,66,45),(327550,66,47),(327551,66,48),(327552,66,49),(327553,66,50),(327554,66,51),(327555,66,52),(327556,66,53),(327557,66,54),(327558,66,55),(327559,66,56),(327560,66,57),(327561,66,58),(327562,66,59),(327563,66,60),(327564,66,61),(327565,66,64),(327566,66,65),(327516,66,66),(327567,66,67),(327568,66,69),(327569,66,70),(327570,66,71),(327571,66,72),(327572,66,73),(327573,66,74),(327574,66,75),(327575,66,76),(327576,66,101),(327577,66,102),(327518,66,103),(327583,66,111),(327578,66,112),(327582,66,122),(327580,66,123),(327579,66,124),(327581,66,125),(327588,67,1),(327606,67,2),(327605,67,3),(327585,67,5),(327610,67,6),(327609,67,11),(327602,67,13),(327587,67,18),(327589,67,21),(327590,67,33),(327591,67,35),(327599,67,36),(327586,67,37),(327608,67,44),(327607,67,47),(327595,67,49),(327592,67,53),(327598,67,54),(327597,67,58),(327584,67,67),(327604,67,70),(327601,67,72),(327596,67,74),(327600,67,75),(327593,67,76),(327594,67,111),(327603,67,125),(327619,69,1),(327626,69,2),(327625,69,3),(327628,69,6),(327627,69,11),(327612,69,35),(327621,69,36),(327623,69,44),(327613,69,47),(327614,69,49),(327622,69,54),(327615,69,58),(327611,69,69),(327624,69,70),(327618,69,75),(327617,69,76),(327616,69,111),(327620,69,125),(327631,70,6),(327630,70,11),(327629,70,70),(327633,71,1),(327636,71,2),(327635,71,3),(327640,71,6),(327639,71,11),(327634,71,58),(327637,71,70),(327632,71,71),(327638,71,76),(327647,72,1),(327655,72,2),(327654,72,3),(327657,72,6),(327656,72,11),(327642,72,18),(327648,72,36),(327652,72,44),(327651,72,47),(327643,72,49),(327649,72,54),(327650,72,58),(327653,72,70),(327641,72,72),(327646,72,76),(327644,72,111),(327645,72,125),(327664,73,1),(327676,73,2),(327675,73,3),(327659,73,5),(327682,73,6),(327678,73,11),(327672,73,13),(327663,73,18),(327660,73,19),(327662,73,21),(327665,73,33),(327666,73,35),(327681,73,36),(327684,73,44),(327683,73,47),(327677,73,49),(327667,73,53),(327680,73,54),(327679,73,58),(327661,73,64),(327674,73,70),(327671,73,72),(327658,73,73),(327670,73,75),(327668,73,76),(327669,73,111),(327673,73,125),(327685,74,74),(327686,75,75),(327687,76,76),(327689,100,1),(327690,100,2),(327691,100,3),(327692,100,5),(327693,100,6),(327694,100,9),(327695,100,11),(327696,100,13),(327697,100,15),(327698,100,16),(327699,100,17),(327700,100,18),(327701,100,19),(327702,100,20),(327703,100,21),(327704,100,22),(327705,100,30),(327706,100,31),(327707,100,32),(327708,100,33),(327709,100,34),(327710,100,35),(327711,100,36),(327712,100,37),(327713,100,38),(327714,100,39),(327715,100,40),(327716,100,41),(327717,100,42),(327718,100,43),(327719,100,44),(327720,100,45),(327721,100,47),(327722,100,48),(327723,100,49),(327724,100,50),(327725,100,51),(327726,100,52),(327727,100,53),(327728,100,54),(327729,100,55),(327730,100,56),(327731,100,57),(327732,100,58),(327733,100,59),(327734,100,60),(327735,100,61),(327736,100,62),(327737,100,64),(327738,100,65),(327739,100,66),(327740,100,67),(327741,100,69),(327742,100,70),(327743,100,71),(327744,100,72),(327745,100,73),(327746,100,74),(327747,100,75),(327748,100,76),(327688,100,100),(327749,100,101),(327750,100,102),(327751,100,103),(327752,100,104),(327753,100,105),(327754,100,106),(327755,100,107),(327756,100,108),(327757,100,109),(327758,100,110),(327759,100,111),(327760,100,112),(327761,100,114),(327762,100,115),(327763,100,119),(327770,100,120),(327764,100,121),(327765,100,122),(327768,100,123),(327766,100,124),(327769,100,125),(327767,100,126),(327777,101,1),(327782,101,2),(327781,101,3),(327784,101,6),(327783,101,11),(327772,101,13),(327773,101,18),(327774,101,35),(327780,101,70),(327778,101,75),(327776,101,76),(327771,101,101),(327779,101,111),(327775,101,125),(327786,102,1),(327793,102,2),(327792,102,3),(327803,102,6),(327802,102,11),(327787,102,13),(327788,102,35),(327797,102,36),(327801,102,44),(327800,102,47),(327789,102,49),(327798,102,54),(327799,102,58),(327791,102,70),(327794,102,75),(327790,102,76),(327785,102,102),(327795,102,111),(327796,102,125),(327805,103,1),(327806,103,2),(327807,103,3),(327808,103,5),(327809,103,6),(327867,103,9),(327810,103,11),(327811,103,13),(327812,103,15),(327813,103,16),(327814,103,17),(327815,103,18),(327816,103,19),(327817,103,20),(327818,103,21),(327819,103,22),(327820,103,30),(327821,103,31),(327822,103,32),(327823,103,33),(327824,103,34),(327825,103,35),(327826,103,36),(327827,103,37),(327828,103,38),(327829,103,39),(327830,103,40),(327831,103,41),(327832,103,42),(327833,103,43),(327834,103,44),(327835,103,45),(327836,103,47),(327837,103,48),(327838,103,49),(327839,103,50),(327840,103,51),(327841,103,52),(327842,103,53),(327843,103,54),(327844,103,55),(327845,103,56),(327846,103,57),(327847,103,58),(327848,103,59),(327849,103,60),(327850,103,61),(327851,103,64),(327852,103,65),(327853,103,67),(327854,103,69),(327855,103,70),(327856,103,71),(327857,103,72),(327858,103,73),(327859,103,74),(327860,103,75),(327861,103,76),(327862,103,101),(327863,103,102),(327804,103,103),(327870,103,111),(327864,103,112),(327869,103,122),(327866,103,123),(327865,103,124),(327868,103,125),(327878,104,1),(327877,104,2),(327880,104,3),(327881,104,5),(327882,104,6),(327879,104,9),(327883,104,11),(327884,104,13),(327885,104,15),(327886,104,16),(327887,104,17),(327888,104,18),(327889,104,19),(327890,104,20),(327891,104,21),(327892,104,22),(327893,104,30),(327894,104,31),(327895,104,32),(327896,104,33),(327897,104,34),(327898,104,35),(327899,104,36),(327900,104,37),(327901,104,38),(327902,104,39),(327903,104,40),(327904,104,41),(327905,104,42),(327906,104,43),(327907,104,44),(327908,104,45),(327909,104,47),(327910,104,48),(327911,104,49),(327912,104,50),(327913,104,51),(327914,104,52),(327915,104,53),(327916,104,54),(327917,104,55),(327918,104,56),(327919,104,57),(327920,104,58),(327921,104,59),(327922,104,60),(327923,104,61),(327948,104,62),(327924,104,64),(327925,104,65),(327875,104,66),(327926,104,67),(327927,104,69),(327928,104,70),(327929,104,71),(327930,104,72),(327931,104,73),(327932,104,74),(327933,104,75),(327934,104,76),(327872,104,100),(327935,104,101),(327936,104,102),(327874,104,103),(327871,104,104),(327945,104,105),(327944,104,106),(327951,104,107),(327953,104,108),(327952,104,109),(327949,104,110),(327942,104,111),(327937,104,112),(327947,104,114),(327873,104,115),(327950,104,119),(327876,104,120),(327943,104,121),(327941,104,122),(327939,104,123),(327938,104,124),(327940,104,125),(327946,104,126),(327954,105,105),(327957,106,6),(327956,106,11),(327955,106,106),(327969,107,1),(327983,107,2),(327982,107,3),(327960,107,5),(327985,107,6),(327984,107,11),(327980,107,13),(327968,107,18),(327967,107,21),(327966,107,33),(327961,107,35),(327973,107,36),(327978,107,44),(327977,107,47),(327962,107,49),(327965,107,53),(327974,107,54),(327976,107,56),(327975,107,58),(327959,107,60),(327981,107,70),(327979,107,72),(327971,107,75),(327963,107,76),(327958,107,107),(327970,107,111),(327964,107,123),(327972,107,125),(327987,108,1),(327988,108,2),(327989,108,3),(327993,108,6),(327992,108,11),(327990,108,70),(327991,108,76),(327986,108,108),(327998,109,1),(328002,109,2),(328001,109,3),(328004,109,6),(328003,109,11),(327995,109,13),(327996,109,18),(328000,109,70),(327997,109,76),(327994,109,109),(327999,109,125),(328006,110,1),(328009,110,2),(328008,110,3),(328012,110,6),(328011,110,11),(328010,110,70),(328007,110,76),(328005,110,110),(328013,111,111),(328015,112,1),(328018,112,2),(328017,112,3),(328028,112,6),(328026,112,11),(328021,112,36),(328025,112,44),(328024,112,47),(328016,112,49),(328022,112,54),(328023,112,58),(328019,112,70),(328020,112,76),(328027,112,111),(328014,112,112),(328033,114,1),(328035,114,2),(328034,114,3),(328045,114,6),(328043,114,11),(328030,114,13),(328038,114,36),(328042,114,44),(328041,114,47),(328032,114,49),(328039,114,54),(328040,114,58),(328036,114,70),(328037,114,76),(328044,114,111),(328031,114,112),(328029,114,114),(328051,115,1),(328050,115,2),(328053,115,3),(328054,115,5),(328055,115,6),(328052,115,9),(328056,115,11),(328057,115,13),(328058,115,15),(328059,115,16),(328060,115,17),(328061,115,18),(328062,115,19),(328063,115,20),(328064,115,21),(328065,115,22),(328066,115,30),(328067,115,31),(328068,115,32),(328069,115,33),(328070,115,34),(328071,115,35),(328072,115,36),(328073,115,37),(328074,115,38),(328075,115,39),(328076,115,40),(328077,115,41),(328078,115,42),(328079,115,43),(328080,115,44),(328081,115,45),(328082,115,47),(328083,115,48),(328084,115,49),(328085,115,50),(328086,115,51),(328087,115,52),(328088,115,53),(328089,115,54),(328090,115,55),(328091,115,56),(328092,115,57),(328093,115,58),(328094,115,59),(328095,115,60),(328096,115,61),(328097,115,64),(328098,115,65),(328047,115,66),(328099,115,67),(328100,115,69),(328101,115,70),(328102,115,71),(328103,115,72),(328104,115,73),(328105,115,74),(328106,115,75),(328107,115,76),(328108,115,101),(328109,115,102),(328048,115,103),(328115,115,111),(328110,115,112),(328046,115,115),(328049,115,120),(328114,115,122),(328112,115,123),(328111,115,124),(328113,115,125),(328118,119,1),(328121,119,2),(328120,119,3),(328124,119,6),(328123,119,11),(328122,119,70),(328119,119,76),(328117,119,110),(328116,119,119),(328225,120,1),(328229,120,2),(328228,120,3),(328227,120,5),(328230,120,6),(328222,120,9),(328231,120,11),(328223,120,13),(328232,120,15),(328233,120,16),(328234,120,17),(328235,120,18),(328236,120,19),(328237,120,20),(328238,120,21),(328239,120,22),(328240,120,30),(328241,120,31),(328242,120,32),(328243,120,33),(328244,120,34),(328245,120,35),(328246,120,36),(328247,120,37),(328248,120,38),(328249,120,39),(328250,120,40),(328251,120,41),(328252,120,42),(328253,120,43),(328254,120,44),(328255,120,45),(328256,120,47),(328257,120,48),(328258,120,49),(328259,120,50),(328260,120,51),(328261,120,52),(328262,120,53),(328263,120,54),(328264,120,55),(328265,120,56),(328266,120,57),(328267,120,58),(328268,120,59),(328269,120,60),(328270,120,61),(328271,120,64),(328272,120,65),(328224,120,66),(328273,120,67),(328274,120,69),(328275,120,70),(328276,120,71),(328277,120,72),(328278,120,73),(328279,120,74),(328280,120,75),(328281,120,76),(328282,120,101),(328283,120,102),(328226,120,103),(328289,120,111),(328284,120,112),(328221,120,120),(328288,120,122),(328286,120,123),(328285,120,124),(328287,120,125),(328134,121,1),(328140,121,2),(328139,121,3),(328146,121,6),(328142,121,11),(328129,121,13),(328128,121,18),(328126,121,21),(328130,121,33),(328127,121,35),(328145,121,36),(328148,121,44),(328147,121,47),(328141,121,49),(328131,121,53),(328144,121,54),(328143,121,58),(328138,121,70),(328132,121,72),(328135,121,75),(328133,121,76),(328136,121,111),(328125,121,121),(328137,121,125),(328156,122,1),(328166,122,2),(328165,122,3),(328168,122,6),(328167,122,11),(328150,122,15),(328151,122,35),(328159,122,36),(328163,122,44),(328162,122,47),(328152,122,49),(328160,122,54),(328153,122,56),(328161,122,58),(328164,122,70),(328155,122,75),(328154,122,76),(328157,122,111),(328149,122,122),(328158,122,125),(328213,123,1),(328215,123,2),(328214,123,3),(328219,123,6),(328218,123,11),(328211,123,33),(328212,123,56),(328216,123,70),(328217,123,76),(328210,123,123),(328173,124,1),(328185,124,2),(328184,124,3),(328189,124,6),(328188,124,11),(328177,124,18),(328170,124,35),(328182,124,36),(328171,124,37),(328187,124,44),(328186,124,47),(328178,124,49),(328181,124,54),(328180,124,58),(328183,124,70),(328179,124,74),(328172,124,75),(328174,124,76),(328175,124,111),(328169,124,124),(328176,124,125),(328220,125,125),(328197,126,1),(328207,126,2),(328206,126,3),(328209,126,6),(328208,126,11),(328191,126,15),(328192,126,35),(328200,126,36),(328204,126,44),(328203,126,47),(328193,126,49),(328201,126,54),(328194,126,56),(328202,126,58),(328205,126,70),(328196,126,75),(328195,126,76),(328198,126,111),(328199,126,125),(328190,126,126); +INSERT INTO `roleRole` VALUES (370990,1,1),(370991,1,2),(370992,1,3),(370996,1,6),(370995,1,11),(370993,1,70),(370994,1,76),(370997,2,2),(370999,2,6),(370998,2,11),(371000,3,3),(371002,3,6),(371001,3,11),(371004,5,1),(371018,5,2),(371017,5,3),(371003,5,5),(371024,5,6),(371020,5,11),(371014,5,13),(371005,5,18),(371006,5,21),(371007,5,33),(371008,5,35),(371023,5,36),(371025,5,47),(371019,5,49),(371009,5,53),(371022,5,54),(371021,5,58),(371016,5,70),(371013,5,72),(371012,5,75),(371010,5,76),(371011,5,111),(371015,5,125),(371026,6,6),(371029,9,1),(371030,9,2),(371031,9,3),(371032,9,5),(371033,9,6),(371027,9,9),(371034,9,11),(371035,9,13),(371036,9,15),(371037,9,16),(371038,9,17),(371039,9,18),(371040,9,19),(371041,9,20),(371042,9,21),(371043,9,22),(371044,9,30),(371045,9,31),(371046,9,32),(371047,9,33),(371048,9,34),(371049,9,35),(371050,9,36),(371051,9,37),(371052,9,38),(371053,9,39),(371054,9,40),(371055,9,41),(371056,9,42),(371057,9,43),(371058,9,44),(371059,9,45),(371060,9,47),(371061,9,48),(371062,9,49),(371063,9,50),(371064,9,51),(371065,9,52),(371066,9,53),(371067,9,54),(371068,9,55),(371069,9,56),(371070,9,57),(371071,9,58),(371072,9,59),(371073,9,60),(371074,9,61),(371075,9,64),(371076,9,65),(371077,9,67),(371078,9,69),(371079,9,70),(371080,9,71),(371081,9,72),(371082,9,73),(371083,9,74),(371084,9,75),(371085,9,76),(371086,9,101),(371087,9,102),(371028,9,103),(371091,9,110),(371095,9,111),(371088,9,112),(371089,9,119),(371094,9,122),(371092,9,123),(371090,9,124),(371093,9,125),(371097,11,6),(371096,11,11),(371099,13,1),(371100,13,2),(371101,13,3),(371105,13,6),(371104,13,11),(371098,13,13),(371102,13,70),(371103,13,76),(371112,15,1),(371121,15,2),(371120,15,3),(371123,15,6),(371122,15,11),(371106,15,15),(371107,15,35),(371115,15,36),(371118,15,47),(371108,15,49),(371116,15,54),(371109,15,56),(371117,15,58),(371119,15,70),(371111,15,75),(371110,15,76),(371113,15,111),(371114,15,125),(371132,16,1),(371141,16,2),(371140,16,3),(371143,16,6),(371142,16,11),(371126,16,15),(371124,16,16),(371127,16,35),(371135,16,36),(371138,16,47),(371128,16,49),(371136,16,54),(371129,16,56),(371137,16,58),(371139,16,70),(371131,16,75),(371130,16,76),(371133,16,111),(371125,16,122),(371134,16,125),(371152,17,1),(371168,17,2),(371167,17,3),(371159,17,5),(371195,17,6),(371156,17,9),(371194,17,11),(371155,17,13),(371193,17,15),(371154,17,16),(371144,17,17),(371151,17,18),(371192,17,19),(371145,17,20),(371160,17,21),(371191,17,22),(371190,17,30),(371189,17,31),(371188,17,32),(371174,17,33),(371187,17,34),(371170,17,35),(371164,17,36),(371146,17,37),(371186,17,38),(371147,17,39),(371185,17,40),(371184,17,41),(371183,17,42),(371182,17,43),(371181,17,44),(371180,17,45),(371179,17,47),(371196,17,48),(371157,17,49),(371197,17,50),(371198,17,51),(371199,17,52),(371175,17,53),(371163,17,54),(371200,17,55),(371201,17,56),(371161,17,57),(371162,17,58),(371169,17,59),(371202,17,60),(371203,17,61),(371148,17,64),(371153,17,65),(371149,17,67),(371204,17,69),(371166,17,70),(371205,17,71),(371177,17,72),(371206,17,73),(371158,17,74),(371173,17,75),(371150,17,76),(371207,17,101),(371208,17,102),(371172,17,103),(371212,17,110),(371176,17,111),(371209,17,112),(371210,17,119),(371171,17,122),(371178,17,123),(371211,17,124),(371165,17,125),(371214,18,1),(371219,18,2),(371218,18,3),(371221,18,6),(371220,18,11),(371213,18,18),(371217,18,70),(371215,18,76),(371216,18,125),(371234,19,1),(371240,19,2),(371239,19,3),(371244,19,6),(371243,19,11),(371224,19,13),(371225,19,18),(371222,19,19),(371223,19,21),(371226,19,33),(371232,19,35),(371236,19,36),(371242,19,47),(371231,19,49),(371227,19,53),(371235,19,54),(371241,19,58),(371238,19,70),(371228,19,72),(371237,19,75),(371229,19,76),(371230,19,111),(371233,19,125),(371254,20,1),(371266,20,2),(371265,20,3),(371264,20,5),(371263,20,6),(371246,20,9),(371262,20,11),(371247,20,13),(371261,20,15),(371248,20,16),(371260,20,17),(371252,20,18),(371259,20,19),(371245,20,20),(371267,20,21),(371268,20,22),(371269,20,30),(371270,20,31),(371271,20,32),(371272,20,33),(371273,20,34),(371251,20,35),(371274,20,36),(371275,20,37),(371276,20,38),(371277,20,39),(371278,20,40),(371279,20,41),(371280,20,42),(371281,20,43),(371282,20,44),(371283,20,45),(371284,20,47),(371285,20,48),(371256,20,49),(371286,20,50),(371287,20,51),(371288,20,52),(371289,20,53),(371290,20,54),(371291,20,55),(371292,20,56),(371257,20,57),(371293,20,58),(371258,20,59),(371294,20,60),(371295,20,61),(371296,20,64),(371249,20,65),(371297,20,67),(371298,20,69),(371299,20,70),(371300,20,71),(371301,20,72),(371302,20,73),(371303,20,74),(371304,20,75),(371250,20,76),(371305,20,101),(371306,20,102),(371255,20,103),(371313,20,110),(371311,20,111),(371307,20,112),(371308,20,119),(371253,20,122),(371312,20,123),(371309,20,124),(371310,20,125),(371325,21,1),(371331,21,2),(371330,21,3),(371335,21,6),(371334,21,11),(371315,21,13),(371316,21,18),(371314,21,21),(371317,21,33),(371323,21,35),(371327,21,36),(371333,21,47),(371322,21,49),(371318,21,53),(371326,21,54),(371332,21,58),(371329,21,70),(371319,21,72),(371328,21,75),(371320,21,76),(371321,21,111),(371324,21,125),(371340,22,1),(371350,22,2),(371349,22,3),(371358,22,6),(371356,22,11),(371337,22,13),(371339,22,18),(371338,22,21),(371336,22,22),(371341,22,33),(371346,22,35),(371354,22,36),(371357,22,47),(371345,22,49),(371342,22,53),(371353,22,54),(371352,22,58),(371348,22,70),(371343,22,72),(371355,22,75),(371344,22,76),(371351,22,111),(371347,22,125),(371371,30,1),(371385,30,2),(371384,30,3),(371360,30,5),(371396,30,6),(371372,30,9),(371397,30,11),(371373,30,13),(371395,30,15),(371374,30,16),(371394,30,17),(371370,30,18),(371393,30,19),(371361,30,20),(371369,30,21),(371362,30,22),(371359,30,30),(371392,30,31),(371391,30,32),(371368,30,33),(371390,30,34),(371367,30,35),(371389,30,36),(371388,30,37),(371387,30,38),(371398,30,39),(371399,30,40),(371400,30,41),(371401,30,42),(371402,30,43),(371403,30,44),(371404,30,45),(371405,30,47),(371406,30,48),(371377,30,49),(371407,30,50),(371408,30,51),(371409,30,52),(371363,30,53),(371410,30,54),(371411,30,55),(371412,30,56),(371376,30,57),(371413,30,58),(371386,30,59),(371414,30,60),(371415,30,61),(371364,30,64),(371375,30,65),(371416,30,67),(371417,30,69),(371383,30,70),(371418,30,71),(371381,30,72),(371419,30,73),(371420,30,74),(371380,30,75),(371365,30,76),(371421,30,101),(371422,30,102),(371379,30,103),(371427,30,110),(371366,30,111),(371423,30,112),(371424,30,119),(371378,30,122),(371426,30,123),(371425,30,124),(371382,30,125),(371429,31,1),(371430,31,2),(371431,31,3),(371435,31,6),(371434,31,11),(371428,31,31),(371432,31,70),(371433,31,76),(371437,32,1),(371438,32,2),(371439,32,3),(371443,32,6),(371442,32,11),(371436,32,32),(371440,32,70),(371441,32,76),(371444,33,33),(371446,34,1),(371451,34,2),(371450,34,3),(371454,34,6),(371453,34,11),(371447,34,13),(371448,34,33),(371445,34,34),(371449,34,70),(371452,34,76),(371456,35,1),(371463,35,2),(371462,35,3),(371465,35,6),(371464,35,11),(371455,35,35),(371461,35,70),(371457,35,75),(371458,35,76),(371459,35,111),(371460,35,125),(371472,36,1),(371479,36,2),(371478,36,3),(371481,36,6),(371480,36,11),(371467,36,35),(371466,36,36),(371468,36,47),(371469,36,49),(371475,36,54),(371476,36,58),(371477,36,70),(371471,36,75),(371470,36,76),(371473,36,111),(371474,36,125),(371483,37,1),(371492,37,2),(371491,37,3),(371500,37,6),(371498,37,11),(371484,37,18),(371497,37,35),(371488,37,36),(371482,37,37),(371496,37,47),(371485,37,49),(371493,37,54),(371494,37,58),(371490,37,70),(371486,37,74),(371495,37,75),(371487,37,76),(371499,37,111),(371489,37,125),(371509,38,1),(371513,38,2),(371512,38,3),(371522,38,6),(371520,38,11),(371502,38,13),(371508,38,18),(371519,38,35),(371514,38,36),(371503,38,37),(371501,38,38),(371518,38,47),(371507,38,49),(371515,38,54),(371516,38,58),(371504,38,64),(371511,38,70),(371506,38,74),(371517,38,75),(371505,38,76),(371521,38,111),(371510,38,125),(371531,39,1),(371543,39,2),(371542,39,3),(371524,39,5),(371549,39,6),(371547,39,11),(371534,39,13),(371530,39,18),(371525,39,21),(371529,39,33),(371528,39,35),(371546,39,36),(371523,39,39),(371548,39,47),(371539,39,49),(371532,39,53),(371545,39,54),(371538,39,56),(371526,39,57),(371544,39,58),(371541,39,70),(371535,39,72),(371540,39,75),(371527,39,76),(371533,39,111),(371536,39,123),(371537,39,125),(371551,40,1),(371554,40,2),(371553,40,3),(371566,40,6),(371563,40,11),(371562,40,35),(371557,40,36),(371550,40,40),(371561,40,47),(371552,40,49),(371558,40,54),(371559,40,58),(371555,40,70),(371560,40,75),(371556,40,76),(371565,40,111),(371564,40,125),(371576,41,1),(371581,41,2),(371580,41,3),(371585,41,6),(371584,41,11),(371568,41,13),(371569,41,35),(371578,41,36),(371570,41,40),(371567,41,41),(371583,41,47),(371573,41,49),(371577,41,54),(371582,41,58),(371579,41,70),(371575,41,75),(371571,41,76),(371574,41,111),(371572,41,125),(371592,42,1),(371600,42,2),(371599,42,3),(371602,42,6),(371601,42,11),(371587,42,35),(371594,42,36),(371586,42,42),(371597,42,47),(371588,42,49),(371595,42,54),(371596,42,58),(371598,42,70),(371591,42,75),(371589,42,76),(371590,42,111),(371593,42,125),(371611,43,1),(371617,43,2),(371616,43,3),(371622,43,6),(371621,43,11),(371604,43,13),(371605,43,18),(371608,43,35),(371613,43,36),(371606,43,42),(371603,43,43),(371620,43,47),(371612,43,49),(371618,43,54),(371619,43,58),(371615,43,70),(371614,43,75),(371610,43,76),(371607,43,111),(371609,43,125),(371624,44,1),(371625,44,2),(371626,44,3),(371630,44,6),(371629,44,11),(371623,44,44),(371627,44,70),(371628,44,76),(371634,45,1),(371636,45,2),(371635,45,3),(371640,45,6),(371639,45,11),(371632,45,13),(371633,45,44),(371631,45,45),(371637,45,70),(371638,45,76),(371642,47,1),(371645,47,2),(371644,47,3),(371649,47,6),(371648,47,11),(371641,47,47),(371646,47,70),(371647,47,76),(371643,47,111),(371660,48,1),(371666,48,2),(371665,48,3),(371668,48,6),(371667,48,11),(371651,48,13),(371652,48,35),(371661,48,36),(371653,48,47),(371650,48,48),(371654,48,49),(371662,48,54),(371663,48,58),(371655,48,69),(371664,48,70),(371659,48,75),(371658,48,76),(371657,48,111),(371656,48,125),(371675,49,1),(371679,49,2),(371678,49,3),(371684,49,6),(371683,49,11),(371677,49,35),(371670,49,36),(371676,49,47),(371669,49,49),(371671,49,54),(371672,49,58),(371682,49,70),(371673,49,75),(371674,49,76),(371681,49,111),(371680,49,125),(371697,50,1),(371710,50,2),(371709,50,3),(371699,50,5),(371713,50,6),(371712,50,11),(371686,50,13),(371696,50,18),(371687,50,21),(371695,50,33),(371700,50,35),(371704,50,36),(371711,50,47),(371701,50,49),(371685,50,50),(371694,50,53),(371703,50,54),(371706,50,56),(371688,50,57),(371702,50,58),(371689,50,59),(371690,50,60),(371708,50,70),(371693,50,72),(371705,50,75),(371691,50,76),(371707,50,111),(371692,50,123),(371698,50,125),(371715,51,1),(371724,51,2),(371723,51,3),(371736,51,6),(371732,51,11),(371720,51,13),(371725,51,18),(371716,51,21),(371726,51,33),(371717,51,35),(371735,51,36),(371737,51,47),(371731,51,49),(371714,51,51),(371727,51,53),(371734,51,54),(371733,51,58),(371722,51,70),(371728,51,72),(371718,51,74),(371719,51,75),(371721,51,76),(371729,51,111),(371730,51,125),(371746,52,1),(371752,52,2),(371751,52,3),(371762,52,6),(371758,52,11),(371739,52,13),(371749,52,18),(371740,52,19),(371745,52,21),(371748,52,33),(371744,52,35),(371761,52,36),(371763,52,47),(371757,52,49),(371741,52,51),(371738,52,52),(371753,52,53),(371760,52,54),(371759,52,58),(371750,52,70),(371754,52,72),(371743,52,74),(371747,52,75),(371742,52,76),(371755,52,111),(371756,52,125),(371765,53,1),(371766,53,2),(371767,53,3),(371771,53,6),(371770,53,11),(371764,53,53),(371768,53,70),(371769,53,76),(371773,54,1),(371774,54,2),(371775,54,3),(371779,54,6),(371778,54,11),(371772,54,54),(371776,54,70),(371777,54,76),(371783,55,1),(371785,55,2),(371784,55,3),(371789,55,6),(371788,55,11),(371781,55,13),(371782,55,54),(371780,55,55),(371786,55,70),(371787,55,76),(371791,56,1),(371792,56,2),(371793,56,3),(371797,56,6),(371796,56,11),(371790,56,56),(371794,56,70),(371795,56,76),(371804,57,1),(371807,57,2),(371806,57,3),(371810,57,6),(371809,57,11),(371799,57,13),(371803,57,33),(371802,57,56),(371798,57,57),(371805,57,70),(371808,57,76),(371800,57,123),(371801,57,125),(371812,58,1),(371815,58,2),(371814,58,3),(371818,58,6),(371817,58,11),(371811,58,58),(371816,58,70),(371813,58,76),(371823,59,1),(371831,59,2),(371830,59,3),(371836,59,5),(371847,59,6),(371845,59,11),(371820,59,13),(371828,59,18),(371822,59,21),(371827,59,33),(371837,59,35),(371841,59,36),(371846,59,47),(371838,59,49),(371821,59,50),(371832,59,53),(371840,59,54),(371843,59,56),(371824,59,57),(371839,59,58),(371819,59,59),(371825,59,60),(371829,59,70),(371833,59,72),(371842,59,75),(371826,59,76),(371844,59,111),(371834,59,123),(371835,59,125),(371858,60,1),(371871,60,2),(371870,60,3),(371849,60,5),(371873,60,6),(371872,60,11),(371868,60,13),(371857,60,18),(371856,60,21),(371855,60,33),(371850,60,35),(371862,60,36),(371866,60,47),(371851,60,49),(371854,60,53),(371863,60,54),(371865,60,56),(371864,60,58),(371848,60,60),(371869,60,70),(371867,60,72),(371860,60,75),(371852,60,76),(371859,60,111),(371853,60,123),(371861,60,125),(371878,61,1),(371884,61,2),(371883,61,3),(371891,61,6),(371890,61,11),(371875,61,13),(371877,61,35),(371876,61,36),(371879,61,47),(371880,61,49),(371888,61,54),(371889,61,58),(371874,61,61),(371882,61,70),(371885,61,75),(371881,61,76),(371886,61,111),(371887,61,125),(371892,62,62),(371893,64,64),(371908,65,1),(371918,65,2),(371917,65,3),(371919,65,5),(371923,65,6),(371922,65,11),(371895,65,13),(371896,65,18),(371912,65,21),(371914,65,33),(371897,65,35),(371904,65,36),(371915,65,47),(371898,65,49),(371910,65,50),(371921,65,53),(371903,65,54),(371913,65,56),(371899,65,57),(371902,65,58),(371900,65,59),(371911,65,60),(371894,65,65),(371916,65,70),(371920,65,72),(371906,65,75),(371901,65,76),(371905,65,111),(371909,65,123),(371907,65,125),(371928,66,1),(371927,66,2),(371929,66,3),(371930,66,5),(371931,66,6),(371925,66,9),(371932,66,11),(371933,66,13),(371934,66,15),(371935,66,16),(371936,66,17),(371937,66,18),(371938,66,19),(371939,66,20),(371940,66,21),(371941,66,22),(371942,66,30),(371943,66,31),(371944,66,32),(371945,66,33),(371946,66,34),(371947,66,35),(371948,66,36),(371949,66,37),(371950,66,38),(371951,66,39),(371952,66,40),(371953,66,41),(371954,66,42),(371955,66,43),(371956,66,44),(371957,66,45),(371958,66,47),(371959,66,48),(371960,66,49),(371961,66,50),(371962,66,51),(371963,66,52),(371964,66,53),(371965,66,54),(371966,66,55),(371967,66,56),(371968,66,57),(371969,66,58),(371970,66,59),(371971,66,60),(371972,66,61),(371973,66,64),(371974,66,65),(371924,66,66),(371975,66,67),(371976,66,69),(371977,66,70),(371978,66,71),(371979,66,72),(371980,66,73),(371981,66,74),(371982,66,75),(371983,66,76),(371984,66,101),(371985,66,102),(371926,66,103),(371989,66,110),(371993,66,111),(371986,66,112),(371987,66,119),(371992,66,122),(371990,66,123),(371988,66,124),(371991,66,125),(371998,67,1),(372016,67,2),(372015,67,3),(371995,67,5),(372019,67,6),(372018,67,11),(372012,67,13),(371997,67,18),(371999,67,21),(372000,67,33),(372001,67,35),(372009,67,36),(371996,67,37),(372017,67,47),(372005,67,49),(372002,67,53),(372008,67,54),(372007,67,58),(371994,67,67),(372014,67,70),(372011,67,72),(372006,67,74),(372010,67,75),(372003,67,76),(372004,67,111),(372013,67,125),(372026,69,1),(372034,69,2),(372033,69,3),(372036,69,6),(372035,69,11),(372021,69,35),(372029,69,36),(372022,69,47),(372023,69,49),(372030,69,54),(372031,69,58),(372020,69,69),(372032,69,70),(372025,69,75),(372024,69,76),(372027,69,111),(372028,69,125),(372039,70,6),(372038,70,11),(372037,70,70),(372041,71,1),(372044,71,2),(372043,71,3),(372048,71,6),(372047,71,11),(372042,71,58),(372045,71,70),(372040,71,71),(372046,71,76),(372057,72,1),(372064,72,2),(372063,72,3),(372066,72,6),(372065,72,11),(372050,72,18),(372051,72,35),(372058,72,36),(372061,72,47),(372052,72,49),(372059,72,54),(372060,72,58),(372062,72,70),(372049,72,72),(372054,72,75),(372056,72,76),(372053,72,111),(372055,72,125),(372073,73,1),(372085,73,2),(372084,73,3),(372068,73,5),(372091,73,6),(372087,73,11),(372081,73,13),(372072,73,18),(372069,73,19),(372071,73,21),(372074,73,33),(372075,73,35),(372090,73,36),(372092,73,47),(372086,73,49),(372076,73,53),(372089,73,54),(372088,73,58),(372070,73,64),(372083,73,70),(372080,73,72),(372067,73,73),(372079,73,75),(372077,73,76),(372078,73,111),(372082,73,125),(372093,74,74),(372094,75,75),(372095,76,76),(372097,100,1),(372098,100,2),(372099,100,3),(372100,100,5),(372101,100,6),(372102,100,9),(372103,100,11),(372104,100,13),(372105,100,15),(372106,100,16),(372107,100,17),(372108,100,18),(372109,100,19),(372110,100,20),(372111,100,21),(372112,100,22),(372113,100,30),(372114,100,31),(372115,100,32),(372116,100,33),(372117,100,34),(372118,100,35),(372119,100,36),(372120,100,37),(372121,100,38),(372122,100,39),(372123,100,40),(372124,100,41),(372125,100,42),(372126,100,43),(372127,100,44),(372128,100,45),(372129,100,47),(372130,100,48),(372131,100,49),(372132,100,50),(372133,100,51),(372134,100,52),(372135,100,53),(372136,100,54),(372137,100,55),(372138,100,56),(372139,100,57),(372140,100,58),(372141,100,59),(372142,100,60),(372143,100,61),(372144,100,62),(372145,100,64),(372146,100,65),(372147,100,66),(372148,100,67),(372149,100,69),(372150,100,70),(372151,100,71),(372152,100,72),(372153,100,73),(372154,100,74),(372155,100,75),(372156,100,76),(372096,100,100),(372157,100,101),(372158,100,102),(372159,100,103),(372160,100,104),(372161,100,105),(372162,100,106),(372163,100,107),(372164,100,108),(372165,100,109),(372166,100,110),(372167,100,111),(372168,100,112),(372169,100,114),(372170,100,115),(372171,100,119),(372179,100,120),(372172,100,121),(372173,100,122),(372177,100,123),(372174,100,124),(372178,100,125),(372175,100,126),(372176,100,127),(372186,101,1),(372191,101,2),(372190,101,3),(372193,101,6),(372192,101,11),(372181,101,13),(372182,101,18),(372183,101,35),(372189,101,70),(372187,101,75),(372185,101,76),(372180,101,101),(372188,101,111),(372184,101,125),(372195,102,1),(372202,102,2),(372201,102,3),(372211,102,6),(372210,102,11),(372196,102,13),(372197,102,35),(372206,102,36),(372209,102,47),(372198,102,49),(372207,102,54),(372208,102,58),(372200,102,70),(372203,102,75),(372199,102,76),(372194,102,102),(372204,102,111),(372205,102,125),(372213,103,1),(372214,103,2),(372215,103,3),(372216,103,5),(372217,103,6),(372277,103,9),(372218,103,11),(372219,103,13),(372220,103,15),(372221,103,16),(372222,103,17),(372223,103,18),(372224,103,19),(372225,103,20),(372226,103,21),(372227,103,22),(372228,103,30),(372229,103,31),(372230,103,32),(372231,103,33),(372232,103,34),(372233,103,35),(372234,103,36),(372235,103,37),(372236,103,38),(372237,103,39),(372238,103,40),(372239,103,41),(372240,103,42),(372241,103,43),(372242,103,44),(372243,103,45),(372244,103,47),(372245,103,48),(372246,103,49),(372247,103,50),(372248,103,51),(372249,103,52),(372250,103,53),(372251,103,54),(372252,103,55),(372253,103,56),(372254,103,57),(372255,103,58),(372256,103,59),(372257,103,60),(372258,103,61),(372259,103,64),(372260,103,65),(372261,103,67),(372262,103,69),(372263,103,70),(372264,103,71),(372265,103,72),(372266,103,73),(372267,103,74),(372268,103,75),(372269,103,76),(372270,103,101),(372271,103,102),(372212,103,103),(372275,103,110),(372280,103,111),(372272,103,112),(372273,103,119),(372279,103,122),(372276,103,123),(372274,103,124),(372278,103,125),(372288,104,1),(372287,104,2),(372290,104,3),(372291,104,5),(372292,104,6),(372289,104,9),(372293,104,11),(372294,104,13),(372295,104,15),(372296,104,16),(372297,104,17),(372298,104,18),(372299,104,19),(372300,104,20),(372301,104,21),(372302,104,22),(372303,104,30),(372304,104,31),(372305,104,32),(372306,104,33),(372307,104,34),(372308,104,35),(372309,104,36),(372310,104,37),(372311,104,38),(372312,104,39),(372313,104,40),(372314,104,41),(372315,104,42),(372316,104,43),(372317,104,44),(372318,104,45),(372319,104,47),(372320,104,48),(372321,104,49),(372322,104,50),(372323,104,51),(372324,104,52),(372325,104,53),(372326,104,54),(372327,104,55),(372328,104,56),(372329,104,57),(372330,104,58),(372331,104,59),(372332,104,60),(372333,104,61),(372360,104,62),(372334,104,64),(372335,104,65),(372285,104,66),(372336,104,67),(372337,104,69),(372338,104,70),(372339,104,71),(372340,104,72),(372341,104,73),(372342,104,74),(372343,104,75),(372344,104,76),(372282,104,100),(372345,104,101),(372346,104,102),(372284,104,103),(372281,104,104),(372357,104,105),(372356,104,106),(372361,104,107),(372363,104,108),(372362,104,109),(372350,104,110),(372354,104,111),(372347,104,112),(372359,104,114),(372283,104,115),(372348,104,119),(372286,104,120),(372355,104,121),(372353,104,122),(372351,104,123),(372349,104,124),(372352,104,125),(372358,104,126),(372364,104,127),(372365,105,105),(372368,106,6),(372367,106,11),(372366,106,106),(372380,107,1),(372393,107,2),(372392,107,3),(372371,107,5),(372395,107,6),(372394,107,11),(372390,107,13),(372379,107,18),(372378,107,21),(372377,107,33),(372372,107,35),(372384,107,36),(372388,107,47),(372373,107,49),(372376,107,53),(372385,107,54),(372387,107,56),(372386,107,58),(372370,107,60),(372391,107,70),(372389,107,72),(372382,107,75),(372374,107,76),(372369,107,107),(372381,107,111),(372375,107,123),(372383,107,125),(372397,108,1),(372398,108,2),(372399,108,3),(372403,108,6),(372402,108,11),(372400,108,70),(372401,108,76),(372396,108,108),(372408,109,1),(372412,109,2),(372411,109,3),(372414,109,6),(372413,109,11),(372405,109,13),(372406,109,18),(372410,109,70),(372407,109,76),(372404,109,109),(372409,109,125),(372416,110,1),(372421,110,2),(372420,110,3),(372431,110,6),(372428,110,11),(372427,110,35),(372422,110,36),(372426,110,47),(372417,110,49),(372423,110,54),(372424,110,58),(372419,110,70),(372425,110,75),(372418,110,76),(372415,110,110),(372430,110,111),(372429,110,125),(372432,111,111),(372434,112,1),(372437,112,2),(372436,112,3),(372449,112,6),(372446,112,11),(372445,112,35),(372440,112,36),(372444,112,47),(372435,112,49),(372441,112,54),(372442,112,58),(372438,112,70),(372443,112,75),(372439,112,76),(372448,112,111),(372433,112,112),(372447,112,125),(372454,114,1),(372456,114,2),(372455,114,3),(372468,114,6),(372465,114,11),(372451,114,13),(372464,114,35),(372459,114,36),(372463,114,47),(372453,114,49),(372460,114,54),(372461,114,58),(372457,114,70),(372462,114,75),(372458,114,76),(372467,114,111),(372452,114,112),(372450,114,114),(372466,114,125),(372474,115,1),(372473,115,2),(372476,115,3),(372477,115,5),(372478,115,6),(372475,115,9),(372479,115,11),(372480,115,13),(372481,115,15),(372482,115,16),(372483,115,17),(372484,115,18),(372485,115,19),(372486,115,20),(372487,115,21),(372488,115,22),(372489,115,30),(372490,115,31),(372491,115,32),(372492,115,33),(372493,115,34),(372494,115,35),(372495,115,36),(372496,115,37),(372497,115,38),(372498,115,39),(372499,115,40),(372500,115,41),(372501,115,42),(372502,115,43),(372503,115,44),(372504,115,45),(372505,115,47),(372506,115,48),(372507,115,49),(372508,115,50),(372509,115,51),(372510,115,52),(372511,115,53),(372512,115,54),(372513,115,55),(372514,115,56),(372515,115,57),(372516,115,58),(372517,115,59),(372518,115,60),(372519,115,61),(372520,115,64),(372521,115,65),(372470,115,66),(372522,115,67),(372523,115,69),(372524,115,70),(372525,115,71),(372526,115,72),(372527,115,73),(372528,115,74),(372529,115,75),(372530,115,76),(372531,115,101),(372532,115,102),(372471,115,103),(372536,115,110),(372540,115,111),(372533,115,112),(372469,115,115),(372534,115,119),(372472,115,120),(372539,115,122),(372537,115,123),(372535,115,124),(372538,115,125),(372543,119,1),(372548,119,2),(372547,119,3),(372558,119,6),(372555,119,11),(372554,119,35),(372549,119,36),(372553,119,47),(372544,119,49),(372550,119,54),(372551,119,58),(372546,119,70),(372552,119,75),(372545,119,76),(372542,119,110),(372557,119,111),(372541,119,119),(372556,119,125),(372659,120,1),(372663,120,2),(372662,120,3),(372661,120,5),(372664,120,6),(372656,120,9),(372665,120,11),(372657,120,13),(372666,120,15),(372667,120,16),(372668,120,17),(372669,120,18),(372670,120,19),(372671,120,20),(372672,120,21),(372673,120,22),(372674,120,30),(372675,120,31),(372676,120,32),(372677,120,33),(372678,120,34),(372679,120,35),(372680,120,36),(372681,120,37),(372682,120,38),(372683,120,39),(372684,120,40),(372685,120,41),(372686,120,42),(372687,120,43),(372688,120,44),(372689,120,45),(372690,120,47),(372691,120,48),(372692,120,49),(372693,120,50),(372694,120,51),(372695,120,52),(372696,120,53),(372697,120,54),(372698,120,55),(372699,120,56),(372700,120,57),(372701,120,58),(372702,120,59),(372703,120,60),(372704,120,61),(372705,120,64),(372706,120,65),(372658,120,66),(372707,120,67),(372708,120,69),(372709,120,70),(372710,120,71),(372711,120,72),(372712,120,73),(372713,120,74),(372714,120,75),(372715,120,76),(372716,120,101),(372717,120,102),(372660,120,103),(372721,120,110),(372725,120,111),(372718,120,112),(372719,120,119),(372655,120,120),(372724,120,122),(372722,120,123),(372720,120,124),(372723,120,125),(372568,121,1),(372574,121,2),(372573,121,3),(372580,121,6),(372576,121,11),(372563,121,13),(372562,121,18),(372560,121,21),(372564,121,33),(372561,121,35),(372579,121,36),(372581,121,47),(372575,121,49),(372565,121,53),(372578,121,54),(372577,121,58),(372572,121,70),(372566,121,72),(372569,121,75),(372567,121,76),(372570,121,111),(372559,121,121),(372571,121,125),(372589,122,1),(372598,122,2),(372597,122,3),(372600,122,6),(372599,122,11),(372583,122,15),(372584,122,35),(372592,122,36),(372595,122,47),(372585,122,49),(372593,122,54),(372586,122,56),(372594,122,58),(372596,122,70),(372588,122,75),(372587,122,76),(372590,122,111),(372582,122,122),(372591,122,125),(372647,123,1),(372650,123,2),(372649,123,3),(372653,123,6),(372652,123,11),(372644,123,33),(372645,123,56),(372648,123,70),(372651,123,76),(372643,123,123),(372646,123,125),(372605,124,1),(372617,124,2),(372616,124,3),(372620,124,6),(372619,124,11),(372609,124,18),(372602,124,35),(372614,124,36),(372603,124,37),(372618,124,47),(372610,124,49),(372613,124,54),(372612,124,58),(372615,124,70),(372611,124,74),(372604,124,75),(372606,124,76),(372607,124,111),(372601,124,124),(372608,124,125),(372654,125,125),(372628,126,1),(372637,126,2),(372636,126,3),(372639,126,6),(372638,126,11),(372622,126,15),(372623,126,35),(372631,126,36),(372634,126,47),(372624,126,49),(372632,126,54),(372625,126,56),(372633,126,58),(372635,126,70),(372627,126,75),(372626,126,76),(372629,126,111),(372630,126,125),(372621,126,126),(372642,127,6),(372641,127,11),(372640,127,127); /*!40000 ALTER TABLE `roleRole` ENABLE KEYS */; UNLOCK TABLES; @@ -140,13 +140,13 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:25 USE `salix`; -- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db2.static.verdnatura.es Database: salix -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -164,7 +164,7 @@ USE `salix`; LOCK TABLES `ACL` WRITE; /*!40000 ALTER TABLE `ACL` DISABLE KEYS */; -INSERT INTO `ACL` VALUES (3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(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','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(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'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','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'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(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,'Ticket','state','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','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','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(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','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','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','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(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','*','*','ALLOW','ROLE','logisticBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryAssistant'),(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,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','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'),(165,'TicketDms','*','*','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryAssistant'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','find','READ','ALLOW','ROLE','hr'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','READ','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','refund','WRITE','ALLOW','ROLE','invoicing'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'),(299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'),(302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'),(303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'),(304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'),(305,'EducationLevel','*','*','ALLOW','ROLE','employee'),(306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'),(308,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(309,'Zone','getZoneClosing','*','ALLOW','ROLE','employee'),(310,'ExpeditionState','*','READ','ALLOW','ROLE','employee'),(311,'Expense','*','READ','ALLOW','ROLE','employee'),(312,'Expense','*','WRITE','ALLOW','ROLE','administrative'),(314,'SupplierActivity','*','READ','ALLOW','ROLE','employee'),(315,'SupplierActivity','*','WRITE','ALLOW','ROLE','administrative'),(316,'Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee'),(317,'ClientUnpaid','*','*','ALLOW','ROLE','administrative'),(318,'MdbVersion','*','*','ALLOW','ROLE','developer'),(319,'ItemType','*','READ','ALLOW','ROLE','employee'),(320,'ItemType','*','WRITE','ALLOW','ROLE','buyer'),(321,'InvoiceOut','refund','WRITE','ALLOW','ROLE','invoicing'),(322,'InvoiceOut','refund','WRITE','ALLOW','ROLE','salesAssistant'),(323,'InvoiceOut','refund','WRITE','ALLOW','ROLE','claimManager'),(324,'Ticket','refund','WRITE','ALLOW','ROLE','invoicing'),(325,'Ticket','refund','WRITE','ALLOW','ROLE','salesAssistant'),(326,'Ticket','refund','WRITE','ALLOW','ROLE','claimManager'),(327,'Sale','refund','WRITE','ALLOW','ROLE','salesAssistant'),(328,'Sale','refund','WRITE','ALLOW','ROLE','claimManager'),(329,'TicketRefund','*','WRITE','ALLOW','ROLE','invoicing'),(330,'ClaimObservation','*','WRITE','ALLOW','ROLE','salesPerson'),(331,'ClaimObservation','*','READ','ALLOW','ROLE','salesPerson'),(332,'Client','setPassword','WRITE','ALLOW','ROLE','salesPerson'),(333,'Client','updateUser','WRITE','ALLOW','ROLE','salesPerson'),(334,'ShelvingLog','*','READ','ALLOW','ROLE','employee'),(335,'ZoneExclusionGeo','*','READ','ALLOW','ROLE','employee'),(336,'ZoneExclusionGeo','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(337,'Parking','*','*','ALLOW','ROLE','employee'),(338,'Shelving','*','*','ALLOW','ROLE','employee'),(339,'OsTicket','*','*','ALLOW','ROLE','employee'),(340,'OsTicketConfig','*','*','ALLOW','ROLE','it'),(341,'ClientConsumptionQueue','*','WRITE','ALLOW','ROLE','employee'),(342,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','employee'),(343,'Ticket','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'),(344,'Ticket','deliveryNoteCsvPdf','READ','ALLOW','ROLE','employee'),(345,'Ticket','deliveryNoteCsvEmail','READ','ALLOW','ROLE','employee'),(346,'Client','campaignMetricsPdf','READ','ALLOW','ROLE','employee'),(347,'Client','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'),(348,'Client','clientWelcomeHtml','READ','ALLOW','ROLE','employee'),(349,'Client','clientWelcomeEmail','WRITE','ALLOW','ROLE','employee'),(350,'Client','creditRequestPdf','READ','ALLOW','ROLE','employee'),(351,'Client','creditRequestHtml','READ','ALLOW','ROLE','employee'),(352,'Client','creditRequestEmail','WRITE','ALLOW','ROLE','employee'),(353,'Client','printerSetupHtml','READ','ALLOW','ROLE','employee'),(354,'Client','printerSetupEmail','WRITE','ALLOW','ROLE','employee'),(355,'Client','sepaCoreEmail','WRITE','ALLOW','ROLE','employee'),(356,'Client','letterDebtorPdf','READ','ALLOW','ROLE','employee'),(357,'Client','letterDebtorStHtml','READ','ALLOW','ROLE','employee'),(358,'Client','letterDebtorStEmail','WRITE','ALLOW','ROLE','employee'),(359,'Client','letterDebtorNdHtml','READ','ALLOW','ROLE','employee'),(360,'Client','letterDebtorNdEmail','WRITE','ALLOW','ROLE','employee'),(361,'Client','clientDebtStatementPdf','READ','ALLOW','ROLE','employee'),(362,'Client','clientDebtStatementHtml','READ','ALLOW','ROLE','employee'),(363,'Client','clientDebtStatementEmail','WRITE','ALLOW','ROLE','employee'),(364,'Client','incotermsAuthorizationPdf','READ','ALLOW','ROLE','employee'),(365,'Client','incotermsAuthorizationHtml','READ','ALLOW','ROLE','employee'),(366,'Client','incotermsAuthorizationEmail','WRITE','ALLOW','ROLE','employee'),(367,'Client','consumptionSendQueued','WRITE','ALLOW','ROLE','system'),(368,'InvoiceOut','invoiceEmail','WRITE','ALLOW','ROLE','employee'),(369,'InvoiceOut','exportationPdf','READ','ALLOW','ROLE','employee'),(370,'InvoiceOut','sendQueued','WRITE','ALLOW','ROLE','system'),(371,'Ticket','invoiceCsvPdf','READ','ALLOW','ROLE','employee'),(372,'Ticket','invoiceCsvEmail','WRITE','ALLOW','ROLE','employee'),(373,'Supplier','campaignMetricsPdf','READ','ALLOW','ROLE','employee'),(374,'Supplier','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'),(375,'Travel','extraCommunityPdf','READ','ALLOW','ROLE','employee'),(376,'Travel','extraCommunityEmail','WRITE','ALLOW','ROLE','employee'),(377,'Entry','entryOrderPdf','READ','ALLOW','ROLE','employee'),(378,'OsTicket','osTicketReportEmail','WRITE','ALLOW','ROLE','system'),(379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system'),(380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee'),(381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager'),(382,'Item','labelPdf','READ','ALLOW','ROLE','employee'),(383,'Sector','*','READ','ALLOW','ROLE','employee'),(384,'Sector','*','WRITE','ALLOW','ROLE','employee'),(385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee'),(386,'Route','driverRouteEmail','WRITE','ALLOW','ROLE','employee'),(387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','customer'),(388,'Supplier','newSupplier','WRITE','ALLOW','ROLE','administrative'),(389,'ClaimRma','*','READ','ALLOW','ROLE','claimManager'),(390,'ClaimRma','*','WRITE','ALLOW','ROLE','claimManager'),(391,'Notification','*','WRITE','ALLOW','ROLE','system'),(392,'Boxing','*','*','ALLOW','ROLE','employee'),(393,'Url','*','READ','ALLOW','ROLE','employee'),(394,'Url','*','WRITE','ALLOW','ROLE','it'),(395,'ItemShelving','*','READ','ALLOW','ROLE','employee'),(396,'ItemShelving','*','WRITE','ALLOW','ROLE','production'),(397,'ItemShelvingPlacementSupplyStock','*','READ','ALLOW','ROLE','employee'),(398,'NotificationQueue','*','*','ALLOW','ROLE','employee'),(399,'InvoiceOut','clientsToInvoice','WRITE','ALLOW','ROLE','invoicing'),(400,'InvoiceOut','invoiceClient','WRITE','ALLOW','ROLE','invoicing'),(401,'Sale','editTracked','WRITE','ALLOW','ROLE','production'),(402,'Sale','editFloramondo','WRITE','ALLOW','ROLE','salesAssistant'),(403,'Receipt','balanceCompensationEmail','WRITE','ALLOW','ROLE','employee'),(404,'Receipt','balanceCompensationPdf','READ','ALLOW','ROLE','employee'),(405,'Ticket','getTicketsFuture','READ','ALLOW','ROLE','employee'),(406,'Ticket','merge','WRITE','ALLOW','ROLE','employee'),(407,'Sale','editFloramondo','WRITE','ALLOW','ROLE','logistic'),(408,'ZipConfig','*','*','ALLOW','ROLE','employee'),(409,'Item','*','WRITE','ALLOW','ROLE','administrative'),(410,'Sale','editCloned','WRITE','ALLOW','ROLE','buyer'),(411,'Sale','editCloned','WRITE','ALLOW','ROLE','salesAssistant'),(414,'MdbVersion','*','READ','ALLOW','ROLE','$everyone'),(416,'TicketLog','getChanges','READ','ALLOW','ROLE','employee'),(417,'Ticket','getTicketsAdvance','READ','ALLOW','ROLE','employee'),(418,'EntryLog','*','READ','ALLOW','ROLE','administrative'),(419,'Sale','editTracked','WRITE','ALLOW','ROLE','buyer'),(420,'MdbBranch','*','READ','ALLOW','ROLE','$everyone'),(421,'ItemShelvingSale','*','*','ALLOW','ROLE','employee'),(422,'Docuware','checkFile','READ','ALLOW','ROLE','employee'),(423,'Docuware','download','READ','ALLOW','ROLE','salesPerson'),(424,'Docuware','upload','WRITE','ALLOW','ROLE','productionAssi'),(425,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','salesPerson'),(426,'TpvTransaction','confirm','WRITE','ALLOW','ROLE','$everyone'),(427,'TpvTransaction','start','WRITE','ALLOW','ROLE','$authenticated'),(428,'TpvTransaction','end','WRITE','ALLOW','ROLE','$authenticated'),(429,'ItemConfig','*','READ','ALLOW','ROLE','employee'),(431,'Tag','onSubmit','WRITE','ALLOW','ROLE','employee'),(432,'Worker','updateAttributes','WRITE','ALLOW','ROLE','hr'),(433,'Worker','createAbsence','*','ALLOW','ROLE','employee'),(434,'Worker','updateAbsence','WRITE','ALLOW','ROLE','employee'),(435,'Worker','deleteAbsence','*','ALLOW','ROLE','employee'),(436,'Worker','new','WRITE','ALLOW','ROLE','hr'),(438,'Client','getClientOrSupplierReference','READ','ALLOW','ROLE','employee'),(439,'NotificationSubscription','*','*','ALLOW','ROLE','employee'),(440,'NotificationAcl','*','READ','ALLOW','ROLE','employee'),(441,'MdbApp','*','READ','ALLOW','ROLE','$everyone'),(442,'MdbApp','*','*','ALLOW','ROLE','developer'),(443,'ItemConfig','*','*','ALLOW','ROLE','employee'),(444,'DeviceProduction','*','*','ALLOW','ROLE','hr'),(445,'DeviceProductionModels','*','*','ALLOW','ROLE','hr'),(446,'DeviceProductionState','*','*','ALLOW','ROLE','hr'),(447,'DeviceProductionUser','*','*','ALLOW','ROLE','hr'),(448,'DeviceProduction','*','*','ALLOW','ROLE','productionAssi'),(449,'DeviceProductionModels','*','*','ALLOW','ROLE','productionAssi'),(450,'DeviceProductionState','*','*','ALLOW','ROLE','productionAssi'),(451,'DeviceProductionUser','*','*','ALLOW','ROLE','productionAssi'),(452,'Worker','deallocatePDA','*','ALLOW','ROLE','hr'),(453,'Worker','allocatePDA','*','ALLOW','ROLE','hr'),(454,'Worker','deallocatePDA','*','ALLOW','ROLE','productionAssi'),(455,'Worker','allocatePDA','*','ALLOW','ROLE','productionAssi'),(456,'Zone','*','*','ALLOW','ROLE','deliveryAssistant'),(458,'Operator','*','READ','ALLOW','ROLE','employee'),(459,'Operator','*','WRITE','ALLOW','ROLE','employee'),(460,'InvoiceIn','getSerial','READ','ALLOW','ROLE','administrative'),(461,'Ticket','saveSign','WRITE','ALLOW','ROLE','employee'),(462,'InvoiceOut','negativeBases','READ','ALLOW','ROLE','administrative'),(463,'InvoiceOut','negativeBasesCsv','READ','ALLOW','ROLE','administrative'),(464,'WorkerObservation','*','*','ALLOW','ROLE','hr'),(465,'ClientInforma','*','READ','ALLOW','ROLE','employee'),(466,'ClientInforma','*','WRITE','ALLOW','ROLE','financial'),(467,'Receipt','receiptEmail','*','ALLOW','ROLE','salesAssistant'),(468,'Client','setRating','WRITE','ALLOW','ROLE','financial'),(470,'Client','addressesPropagateRe','*','ALLOW','ROLE','employee'),(471,'Client','canBeInvoiced','*','ALLOW','ROLE','employee'),(472,'Client','canCreateTicket','*','ALLOW','ROLE','employee'),(473,'Client','consumption','*','ALLOW','ROLE','employee'),(474,'Client','createAddress','*','ALLOW','ROLE','employee'),(475,'Client','createWithUser','*','ALLOW','ROLE','employee'),(476,'Client','extendedListFilter','*','ALLOW','ROLE','employee'),(477,'Client','getAverageInvoiced','*','ALLOW','ROLE','employee'),(478,'Client','getCard','*','ALLOW','ROLE','employee'),(479,'Client','getDebt','*','ALLOW','ROLE','employee'),(480,'Client','getMana','*','ALLOW','ROLE','employee'),(481,'Client','transactions','*','ALLOW','ROLE','employee'),(482,'Client','hasCustomerRole','*','ALLOW','ROLE','employee'),(483,'Client','isValidClient','*','ALLOW','ROLE','employee'),(484,'Client','lastActiveTickets','*','ALLOW','ROLE','employee'),(485,'Client','sendSms','*','ALLOW','ROLE','employee'),(486,'Client','setPassword','*','ALLOW','ROLE','employee'),(487,'Client','summary','*','ALLOW','ROLE','employee'),(488,'Client','updateAddress','*','ALLOW','ROLE','employee'),(489,'Client','updateFiscalData','*','ALLOW','ROLE','employee'),(491,'Client','uploadFile','*','ALLOW','ROLE','employee'),(492,'Client','campaignMetricsPdf','*','ALLOW','ROLE','employee'),(493,'Client','campaignMetricsEmail','*','ALLOW','ROLE','employee'),(494,'Client','clientWelcomeHtml','*','ALLOW','ROLE','employee'),(495,'Client','clientWelcomeEmail','*','ALLOW','ROLE','employee'),(496,'Client','printerSetupHtml','*','ALLOW','ROLE','employee'),(497,'Client','printerSetupEmail','*','ALLOW','ROLE','employee'),(498,'Client','sepaCoreEmail','*','ALLOW','ROLE','employee'),(499,'Client','letterDebtorPdf','*','ALLOW','ROLE','employee'),(500,'Client','letterDebtorStHtml','*','ALLOW','ROLE','employee'),(501,'Client','letterDebtorStEmail','*','ALLOW','ROLE','employee'),(502,'Client','letterDebtorNdHtml','*','ALLOW','ROLE','employee'),(503,'Client','letterDebtorNdEmail','*','ALLOW','ROLE','employee'),(504,'Client','clientDebtStatementPdf','*','ALLOW','ROLE','employee'),(505,'Client','clientDebtStatementHtml','*','ALLOW','ROLE','employee'),(506,'Client','clientDebtStatementEmail','*','ALLOW','ROLE','employee'),(507,'Client','creditRequestPdf','*','ALLOW','ROLE','employee'),(508,'Client','creditRequestHtml','*','ALLOW','ROLE','employee'),(509,'Client','creditRequestEmail','*','ALLOW','ROLE','employee'),(510,'Client','incotermsAuthorizationPdf','*','ALLOW','ROLE','employee'),(511,'Client','incotermsAuthorizationHtml','*','ALLOW','ROLE','employee'),(512,'Client','incotermsAuthorizationEmail','*','ALLOW','ROLE','employee'),(513,'Client','consumptionSendQueued','*','ALLOW','ROLE','employee'),(514,'Client','filter','*','ALLOW','ROLE','employee'),(515,'Client','getClientOrSupplierReference','*','ALLOW','ROLE','employee'),(516,'Client','upsert','*','ALLOW','ROLE','employee'),(518,'Client','replaceById','*','ALLOW','ROLE','employee'),(519,'Client','updateAttributes','*','ALLOW','ROLE','employee'),(520,'Client','updateAttributes','*','ALLOW','ROLE','employee'),(521,'Client','deleteById','*','ALLOW','ROLE','employee'),(522,'Client','replaceOrCreate','*','ALLOW','ROLE','employee'),(523,'Client','updateAll','*','ALLOW','ROLE','employee'),(524,'Client','upsertWithWhere','*','ALLOW','ROLE','employee'),(525,'Defaulter','observationEmail','WRITE','ALLOW','ROLE','employee'),(527,'VnUser','acl','READ','ALLOW','ROLE','account'),(528,'VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'),(530,'Account','exists','READ','ALLOW','ROLE','account'),(531,'Account','exists','READ','ALLOW','ROLE','account'),(532,'UserLog','*','READ','ALLOW','ROLE','employee'),(533,'RoleLog','*','READ','ALLOW','ROLE','employee'),(534,'WagonType','*','*','ALLOW','ROLE','productionAssi'),(535,'WagonTypeColor','*','*','ALLOW','ROLE','productionAssi'),(536,'WagonTypeTray','*','*','ALLOW','ROLE','productionAssi'),(537,'WagonConfig','*','*','ALLOW','ROLE','productionAssi'),(538,'CollectionWagon','*','*','ALLOW','ROLE','productionAssi'),(539,'CollectionWagonTicket','*','*','ALLOW','ROLE','productionAssi'),(540,'Wagon','*','*','ALLOW','ROLE','productionAssi'),(541,'WagonType','createWagonType','*','ALLOW','ROLE','productionAssi'),(542,'WagonType','deleteWagonType','*','ALLOW','ROLE','productionAssi'),(543,'WagonType','editWagonType','*','ALLOW','ROLE','productionAssi'),(544,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'),(545,'Agency','find','READ','ALLOW','ROLE','employee'),(546,'Agency','seeExpired','READ','ALLOW','ROLE','coolerAssist'),(547,'WorkerLog','models','READ','ALLOW','ROLE','hr'),(548,'Ticket','editDiscount','WRITE','ALLOW','ROLE','claimManager'),(549,'Ticket','editDiscount','WRITE','ALLOW','ROLE','salesPerson'),(550,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','salesAssistant'),(551,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','deliveryAssistant'),(552,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','buyer'),(553,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','claimManager'),(554,'Ticket','deleteTicketWithPartPrepared','WRITE','ALLOW','ROLE','salesAssistant'),(555,'Ticket','editZone','WRITE','ALLOW','ROLE','deliveryAssistant'),(556,'State','editableStates','READ','ALLOW','ROLE','employee'),(557,'State','seeEditableStates','READ','ALLOW','ROLE','administrative'),(558,'State','seeEditableStates','READ','ALLOW','ROLE','production'),(559,'State','isSomeEditable','READ','ALLOW','ROLE','salesPerson'),(560,'State','isAllEditable','READ','ALLOW','ROLE','production'),(561,'State','isAllEditable','READ','ALLOW','ROLE','administrative'),(562,'Agency','seeExpired','READ','ALLOW','ROLE','administrative'),(563,'Agency','seeExpired','READ','ALLOW','ROLE','productionBoss'),(564,'Claim','createAfterDeadline','WRITE','ALLOW','ROLE','claimManager'),(565,'Client','editAddressLogifloraAllowed','WRITE','ALLOW','ROLE','salesAssistant'),(566,'Client','editFiscalDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'),(567,'Client','editVerifiedDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'),(568,'Client','editCredit','WRITE','ALLOW','ROLE','financialBoss'),(569,'Client','zeroCreditEditor','WRITE','ALLOW','ROLE','financialBoss'),(570,'InvoiceOut','canCreatePdf','WRITE','ALLOW','ROLE','invoicing'),(571,'Supplier','editPayMethodCheck','WRITE','ALLOW','ROLE','financial'),(572,'Worker','isTeamBoss','WRITE','ALLOW','ROLE','teamBoss'),(573,'Worker','forceIsSubordinate','READ','ALLOW','ROLE','hr'),(574,'Claim','editState','WRITE','ALLOW','ROLE','claimManager'),(577,'Claim','findOne','READ','ALLOW','ROLE','salesPerson'),(579,'Claim','updateClaim','WRITE','ALLOW','ROLE','salesPerson'),(580,'Claim','regularizeClaim','WRITE','ALLOW','ROLE','claimManager'),(581,'Claim','updateClaimDestination','WRITE','ALLOW','ROLE','claimManager'),(582,'Claim','downloadFile','READ','ALLOW','ROLE','claimManager'),(583,'Claim','deleteById','WRITE','ALLOW','ROLE','claimManager'),(585,'Claim','logs','READ','ALLOW','ROLE','claimManager'),(586,'Ticket','find','READ','ALLOW','ROLE','employee'),(587,'Ticket','findById','READ','ALLOW','ROLE','employee'),(588,'Ticket','findOne','READ','ALLOW','ROLE','employee'),(589,'Ticket','getVolume','READ','ALLOW','ROLE','employee'),(590,'Ticket','getTotalVolume','READ','ALLOW','ROLE','employee'),(591,'Ticket','summary','READ','ALLOW','ROLE','employee'),(592,'Ticket','priceDifference','READ','ALLOW','ROLE','employee'),(593,'Ticket','componentUpdate','WRITE','ALLOW','ROLE','employee'),(594,'Ticket','new','WRITE','ALLOW','ROLE','employee'),(595,'Ticket','isEditable','READ','ALLOW','ROLE','employee'),(596,'Ticket','setDeleted','WRITE','ALLOW','ROLE','salesPerson'),(597,'Ticket','restore','WRITE','ALLOW','ROLE','employee'),(598,'Ticket','getSales','READ','ALLOW','ROLE','employee'),(599,'Ticket','getSalesPersonMana','READ','ALLOW','ROLE','employee'),(600,'Ticket','filter','READ','ALLOW','ROLE','employee'),(601,'Ticket','makeInvoice','WRITE','ALLOW','ROLE','employee'),(602,'Ticket','updateEditableTicket','WRITE','ALLOW','ROLE','employee'),(603,'Ticket','updateDiscount','WRITE','ALLOW','ROLE','employee'),(604,'Ticket','transferSales','WRITE','ALLOW','ROLE','employee'),(605,'Ticket','sendSms','WRITE','ALLOW','ROLE','employee'),(606,'Ticket','isLocked','READ','ALLOW','ROLE','employee'),(607,'Ticket','freightCost','READ','ALLOW','ROLE','employee'),(608,'Ticket','getComponentsSum','READ','ALLOW','ROLE','employee'),(609,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','delivery'),(610,'Ticket','deliveryNoteCsv','READ','ALLOW','ROLE','employee'),(611,'State','find','READ','ALLOW','ROLE','employee'),(612,'State','findById','READ','ALLOW','ROLE','employee'),(613,'State','findOne','READ','ALLOW','ROLE','employee'),(614,'Worker','find','READ','ALLOW','ROLE','employee'),(615,'Worker','findById','READ','ALLOW','ROLE','employee'),(616,'Worker','findOne','READ','ALLOW','ROLE','employee'),(617,'Worker','filter','READ','ALLOW','ROLE','employee'),(618,'Worker','getWorkedHours','READ','ALLOW','ROLE','employee'),(619,'Worker','active','READ','ALLOW','ROLE','employee'),(620,'Worker','activeWithRole','READ','ALLOW','ROLE','employee'),(621,'Worker','uploadFile','WRITE','ALLOW','ROLE','hr'),(622,'Worker','contracts','READ','ALLOW','ROLE','employee'),(623,'Worker','holidays','READ','ALLOW','ROLE','employee'),(624,'Worker','activeContract','READ','ALLOW','ROLE','employee'),(625,'Worker','activeWithInheritedRole','READ','ALLOW','ROLE','employee'),(626,'Ticket','collectionLabel','READ','ALLOW','ROLE','employee'),(628,'Ticket','expeditionPalletLabel','READ','ALLOW','ROLE','employee'),(629,'Ticket','editDiscount','WRITE','ALLOW','ROLE','artificialBoss'),(630,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesTeamBoss'),(635,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','administrative'),(636,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesPerson'),(637,'Claim','downloadFile','READ','ALLOW','ROLE','salesPerson'),(638,'Agency','seeExpired','READ','ALLOW','ROLE','artificialBoss'),(639,'Agency','seeExpired','READ','ALLOW','ROLE','logisticAssistant'),(654,'Ticket','editZone','WRITE','ALLOW','ROLE','logisticAssistant'),(655,'Entry','addFromPackaging','WRITE','ALLOW','ROLE','production'),(656,'Entry','addFromBuy','WRITE','ALLOW','ROLE','production'),(657,'Supplier','getItemsPackaging','READ','ALLOW','ROLE','production'),(658,'Ticket','closeAll','WRITE','ALLOW','ROLE','system'),(659,'Account','*','*','ALLOW','ROLE','developerBoss'),(664,'MailForward','*','*','ALLOW','ROLE','itManagement'),(665,'Role','*','READ','ALLOW','ROLE','employee'),(666,'Role','*','WRITE','ALLOW','ROLE','it'),(667,'VnUser','*','*','ALLOW','ROLE','itManagement'),(668,'VnUser','__get__preview','READ','ALLOW','ROLE','employee'),(669,'VnUser','preview','*','ALLOW','ROLE','employee'),(670,'VnUser','create','*','ALLOW','ROLE','itManagement'),(671,'VnUser','renewToken','WRITE','ALLOW','ROLE','employee'),(672,'PackingSiteAdvanced','*','*','ALLOW','ROLE','production'),(673,'InvoiceOut','makePdfAndNotify','WRITE','ALLOW','ROLE','invoicing'),(674,'InvoiceOutConfig','*','READ','ALLOW','ROLE','invoicing'),(676,'Ticket','invoiceTickets','WRITE','ALLOW','ROLE','employee'),(680,'MailAliasAccount','*','READ','ALLOW','ROLE','employee'),(681,'MailAliasAccount','create','WRITE','ALLOW','ROLE','employee'),(682,'MailAliasAccount','deleteById','WRITE','ALLOW','ROLE','employee'),(683,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','itManagement'),(684,'WorkerDisableExcluded','*','READ','ALLOW','ROLE','itManagement'),(685,'WorkerDisableExcluded','*','WRITE','ALLOW','ROLE','itManagement'),(686,'MailForward','*','*','ALLOW','ROLE','hr'),(687,'ClientSms','find','READ','ALLOW','ROLE','employee'),(688,'ClientSms','create','WRITE','ALLOW','ROLE','employee'),(689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'),(690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'),(691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'),(692,'ExpeditionTruck','*','*','ALLOW','ROLE','palletizerBoss'),(693,'ExpeditionTruck','*','*','ALLOW','ROLE','productionBoss'),(694,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','marketingBoss'),(695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'),(696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'),(697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'),(698,'Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer'),(699,'TicketSms','find','READ','ALLOW','ROLE','salesPerson'),(701,'Docuware','upload','WRITE','ALLOW','ROLE','deliveryAssistant'),(702,'Ticket','docuwareDownload','READ','ALLOW','ROLE','salesPerson'),(703,'Worker','search','READ','ALLOW','ROLE','employee'),(704,'ExpeditionState','addExpeditionState','WRITE','ALLOW','ROLE','delivery'),(705,'SaleGroupDetail','deleteById','WRITE','ALLOW','ROLE','employee'),(706,'Ticket','setDeleted','WRITE','ALLOW','ROLE','buyer'),(707,'DeviceLog','create','WRITE','ALLOW','ROLE','employee'),(708,'Collection','getTickets','WRITE','ALLOW','ROLE','employee'),(709,'Client','findOne','READ','ALLOW','ROLE','employee'),(710,'Client','findById','READ','ALLOW','ROLE','employee'),(711,'Client','find','READ','ALLOW','ROLE','employee'),(712,'Client','exists','READ','ALLOW','ROLE','employee'),(713,'Client','__get__addresses','READ','ALLOW','ROLE','employee'),(714,'ExpeditionMistakeType','*','READ','ALLOW','ROLE','employee'),(715,'WorkerMistakeType','*','READ','ALLOW','ROLE','employee'),(716,'ExpeditionMistake','*','WRITE','ALLOW','ROLE','employee'),(717,'WorkerMistake','*','WRITE','ALLOW','ROLE','coolerBoss'),(718,'MistakesTypes','*','WRITE','ALLOW','ROLE','coolerBoss'),(719,'MistakeType','*','READ','ALLOW','ROLE','employee'),(720,'MachineWorker','*','READ','ALLOW','ROLE','coolerAssist'),(721,'Printer','*','READ','ALLOW','ROLE','employee'),(722,'SaleMistake','*','WRITE','ALLOW','ROLE','production'),(723,'Item','setVisibleDiscard','WRITE','ALLOW','ROLE','employee'),(724,'Address','getAddress','READ','ALLOW','ROLE','employee'),(725,'Account','findOne','READ','ALLOW','ROLE','employee'),(726,'Account','findById','READ','ALLOW','ROLE','employee'),(727,'Account','find','READ','ALLOW','ROLE','employee'),(728,'Account','exists','READ','ALLOW','ROLE','employee'),(729,'Sale','refund','WRITE','ALLOW','ROLE','buyer'),(730,'Ticket','setDeleted','WRITE','ALLOW','ROLE','deliveryAssistant'),(732,'Sale','isInPreparing','*','ALLOW','ROLE','production'),(733,'Train','*','READ','ALLOW','ROLE','production'),(734,'WorkerDepartment','*','*','ALLOW','ROLE','employee'),(735,'VnUser','higherPrivileges','*','ALLOW','ROLE','itManagement'),(736,'VnUser','mediumPrivileges','*','ALLOW','ROLE','hr'),(737,'VnUser','updateUser','*','ALLOW','ROLE','employee'),(738,'TicketCollection','*','WRITE','ALLOW','ROLE','production'),(739,'Worker','setPassword','*','ALLOW','ROLE','employee'),(740,'Url','getByUser','READ','ALLOW','ROLE','$everyone'),(741,'Claim','__get__lines','READ','ALLOW','ROLE','claimViewer'),(742,'AddressShortage','*','READ','ALLOW','ROLE','production'),(743,'Claim','filter','READ','ALLOW','ROLE','claimViewer'),(744,'Claim','find','READ','ALLOW','ROLE','claimViewer'),(745,'Claim','findById','READ','ALLOW','ROLE','claimViewer'),(746,'Claim','getSummary','READ','ALLOW','ROLE','claimViewer'),(747,'CplusRectificationType','*','READ','ALLOW','ROLE','administrative'),(748,'SiiTypeInvoiceOut','*','READ','ALLOW','ROLE','administrative'),(749,'InvoiceCorrectionType','*','READ','ALLOW','ROLE','administrative'),(750,'InvoiceOut','transferInvoice','WRITE','ALLOW','ROLE','administrative'); +INSERT INTO `ACL` VALUES (3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(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','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(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'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','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'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(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,'Ticket','state','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','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','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(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','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','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','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(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','*','*','ALLOW','ROLE','logisticBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryAssistant'),(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'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','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'),(165,'TicketDms','*','*','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryAssistant'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','find','READ','ALLOW','ROLE','hr'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','READ','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','refund','WRITE','ALLOW','ROLE','invoicing'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'),(299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'),(302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'),(303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'),(304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'),(305,'EducationLevel','*','*','ALLOW','ROLE','employee'),(306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'),(308,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(309,'Zone','getZoneClosing','*','ALLOW','ROLE','employee'),(310,'ExpeditionState','*','READ','ALLOW','ROLE','employee'),(311,'Expense','*','READ','ALLOW','ROLE','employee'),(312,'Expense','*','WRITE','ALLOW','ROLE','administrative'),(314,'SupplierActivity','*','READ','ALLOW','ROLE','employee'),(315,'SupplierActivity','*','WRITE','ALLOW','ROLE','administrative'),(316,'Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee'),(317,'ClientUnpaid','*','*','ALLOW','ROLE','administrative'),(318,'MdbVersion','*','*','ALLOW','ROLE','developer'),(319,'ItemType','*','READ','ALLOW','ROLE','employee'),(320,'ItemType','*','WRITE','ALLOW','ROLE','buyer'),(321,'InvoiceOut','refund','WRITE','ALLOW','ROLE','invoicing'),(322,'InvoiceOut','refund','WRITE','ALLOW','ROLE','salesAssistant'),(323,'InvoiceOut','refund','WRITE','ALLOW','ROLE','claimManager'),(324,'Ticket','refund','WRITE','ALLOW','ROLE','invoicing'),(325,'Ticket','refund','WRITE','ALLOW','ROLE','salesAssistant'),(326,'Ticket','refund','WRITE','ALLOW','ROLE','claimManager'),(327,'Sale','refund','WRITE','ALLOW','ROLE','salesAssistant'),(328,'Sale','refund','WRITE','ALLOW','ROLE','claimManager'),(329,'TicketRefund','*','WRITE','ALLOW','ROLE','invoicing'),(330,'ClaimObservation','*','WRITE','ALLOW','ROLE','salesPerson'),(331,'ClaimObservation','*','READ','ALLOW','ROLE','salesPerson'),(332,'Client','setPassword','WRITE','ALLOW','ROLE','salesPerson'),(333,'Client','updateUser','WRITE','ALLOW','ROLE','salesPerson'),(334,'ShelvingLog','*','READ','ALLOW','ROLE','employee'),(335,'ZoneExclusionGeo','*','READ','ALLOW','ROLE','employee'),(336,'ZoneExclusionGeo','*','WRITE','ALLOW','ROLE','deliveryAssistant'),(337,'Parking','*','*','ALLOW','ROLE','employee'),(338,'Shelving','*','*','ALLOW','ROLE','employee'),(339,'OsTicket','*','*','ALLOW','ROLE','employee'),(340,'OsTicketConfig','*','*','ALLOW','ROLE','it'),(341,'ClientConsumptionQueue','*','WRITE','ALLOW','ROLE','employee'),(342,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','employee'),(343,'Ticket','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'),(344,'Ticket','deliveryNoteCsvPdf','READ','ALLOW','ROLE','employee'),(345,'Ticket','deliveryNoteCsvEmail','READ','ALLOW','ROLE','employee'),(346,'Client','campaignMetricsPdf','READ','ALLOW','ROLE','employee'),(347,'Client','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'),(348,'Client','clientWelcomeHtml','READ','ALLOW','ROLE','employee'),(349,'Client','clientWelcomeEmail','WRITE','ALLOW','ROLE','employee'),(350,'Client','creditRequestPdf','READ','ALLOW','ROLE','employee'),(351,'Client','creditRequestHtml','READ','ALLOW','ROLE','employee'),(352,'Client','creditRequestEmail','WRITE','ALLOW','ROLE','employee'),(353,'Client','printerSetupHtml','READ','ALLOW','ROLE','employee'),(354,'Client','printerSetupEmail','WRITE','ALLOW','ROLE','employee'),(355,'Client','sepaCoreEmail','WRITE','ALLOW','ROLE','employee'),(356,'Client','letterDebtorPdf','READ','ALLOW','ROLE','employee'),(357,'Client','letterDebtorStHtml','READ','ALLOW','ROLE','employee'),(358,'Client','letterDebtorStEmail','WRITE','ALLOW','ROLE','employee'),(359,'Client','letterDebtorNdHtml','READ','ALLOW','ROLE','employee'),(360,'Client','letterDebtorNdEmail','WRITE','ALLOW','ROLE','employee'),(361,'Client','clientDebtStatementPdf','READ','ALLOW','ROLE','employee'),(362,'Client','clientDebtStatementHtml','READ','ALLOW','ROLE','employee'),(363,'Client','clientDebtStatementEmail','WRITE','ALLOW','ROLE','employee'),(364,'Client','incotermsAuthorizationPdf','READ','ALLOW','ROLE','employee'),(365,'Client','incotermsAuthorizationHtml','READ','ALLOW','ROLE','employee'),(366,'Client','incotermsAuthorizationEmail','WRITE','ALLOW','ROLE','employee'),(367,'Client','consumptionSendQueued','WRITE','ALLOW','ROLE','system'),(368,'InvoiceOut','invoiceEmail','WRITE','ALLOW','ROLE','employee'),(369,'InvoiceOut','exportationPdf','READ','ALLOW','ROLE','employee'),(370,'InvoiceOut','sendQueued','WRITE','ALLOW','ROLE','system'),(371,'Ticket','invoiceCsvPdf','READ','ALLOW','ROLE','employee'),(372,'Ticket','invoiceCsvEmail','WRITE','ALLOW','ROLE','employee'),(373,'Supplier','campaignMetricsPdf','READ','ALLOW','ROLE','employee'),(374,'Supplier','campaignMetricsEmail','WRITE','ALLOW','ROLE','employee'),(375,'Travel','extraCommunityPdf','READ','ALLOW','ROLE','employee'),(376,'Travel','extraCommunityEmail','WRITE','ALLOW','ROLE','employee'),(377,'Entry','entryOrderPdf','READ','ALLOW','ROLE','employee'),(378,'OsTicket','osTicketReportEmail','WRITE','ALLOW','ROLE','system'),(379,'Item','buyerWasteEmail','WRITE','ALLOW','ROLE','system'),(380,'Claim','claimPickupPdf','READ','ALLOW','ROLE','employee'),(381,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','claimManager'),(382,'Item','labelPdf','READ','ALLOW','ROLE','employee'),(383,'Sector','*','READ','ALLOW','ROLE','employee'),(384,'Sector','*','WRITE','ALLOW','ROLE','employee'),(385,'Route','driverRoutePdf','READ','ALLOW','ROLE','employee'),(386,'Route','driverRouteEmail','WRITE','ALLOW','ROLE','employee'),(387,'Ticket','deliveryNotePdf','READ','ALLOW','ROLE','customer'),(388,'Supplier','newSupplier','WRITE','ALLOW','ROLE','administrative'),(389,'ClaimRma','*','READ','ALLOW','ROLE','claimManager'),(390,'ClaimRma','*','WRITE','ALLOW','ROLE','claimManager'),(391,'Notification','*','WRITE','ALLOW','ROLE','system'),(392,'Boxing','*','*','ALLOW','ROLE','employee'),(393,'Url','*','READ','ALLOW','ROLE','employee'),(394,'Url','*','WRITE','ALLOW','ROLE','it'),(395,'ItemShelving','*','READ','ALLOW','ROLE','employee'),(396,'ItemShelving','*','WRITE','ALLOW','ROLE','production'),(397,'ItemShelvingPlacementSupplyStock','*','READ','ALLOW','ROLE','employee'),(398,'NotificationQueue','*','*','ALLOW','ROLE','employee'),(399,'InvoiceOut','clientsToInvoice','WRITE','ALLOW','ROLE','invoicing'),(400,'InvoiceOut','invoiceClient','WRITE','ALLOW','ROLE','invoicing'),(401,'Sale','editTracked','WRITE','ALLOW','ROLE','production'),(402,'Sale','editFloramondo','WRITE','ALLOW','ROLE','salesAssistant'),(403,'Receipt','balanceCompensationEmail','WRITE','ALLOW','ROLE','employee'),(404,'Receipt','balanceCompensationPdf','READ','ALLOW','ROLE','employee'),(405,'Ticket','getTicketsFuture','READ','ALLOW','ROLE','employee'),(406,'Ticket','merge','WRITE','ALLOW','ROLE','employee'),(407,'Sale','editFloramondo','WRITE','ALLOW','ROLE','logistic'),(408,'ZipConfig','*','*','ALLOW','ROLE','employee'),(409,'Item','*','WRITE','ALLOW','ROLE','administrative'),(410,'Sale','editCloned','WRITE','ALLOW','ROLE','buyer'),(411,'Sale','editCloned','WRITE','ALLOW','ROLE','salesAssistant'),(414,'MdbVersion','*','READ','ALLOW','ROLE','$everyone'),(416,'TicketLog','getChanges','READ','ALLOW','ROLE','employee'),(417,'Ticket','getTicketsAdvance','READ','ALLOW','ROLE','employee'),(418,'EntryLog','*','READ','ALLOW','ROLE','administrative'),(419,'Sale','editTracked','WRITE','ALLOW','ROLE','buyer'),(420,'MdbBranch','*','READ','ALLOW','ROLE','$everyone'),(421,'ItemShelvingSale','*','*','ALLOW','ROLE','employee'),(422,'Docuware','checkFile','READ','ALLOW','ROLE','employee'),(423,'Docuware','download','READ','ALLOW','ROLE','salesPerson'),(424,'Docuware','upload','WRITE','ALLOW','ROLE','productionAssi'),(425,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','salesPerson'),(426,'TpvTransaction','confirm','WRITE','ALLOW','ROLE','$everyone'),(427,'TpvTransaction','start','WRITE','ALLOW','ROLE','$authenticated'),(428,'TpvTransaction','end','WRITE','ALLOW','ROLE','$authenticated'),(429,'ItemConfig','*','READ','ALLOW','ROLE','employee'),(431,'Tag','onSubmit','WRITE','ALLOW','ROLE','employee'),(432,'Worker','updateAttributes','WRITE','ALLOW','ROLE','hr'),(433,'Worker','createAbsence','*','ALLOW','ROLE','employee'),(434,'Worker','updateAbsence','WRITE','ALLOW','ROLE','employee'),(435,'Worker','deleteAbsence','*','ALLOW','ROLE','employee'),(436,'Worker','new','WRITE','ALLOW','ROLE','hr'),(438,'Client','getClientOrSupplierReference','READ','ALLOW','ROLE','employee'),(439,'NotificationSubscription','*','*','ALLOW','ROLE','employee'),(440,'NotificationAcl','*','READ','ALLOW','ROLE','employee'),(441,'MdbApp','*','READ','ALLOW','ROLE','$everyone'),(442,'MdbApp','*','*','ALLOW','ROLE','developer'),(443,'ItemConfig','*','*','ALLOW','ROLE','employee'),(444,'DeviceProduction','*','*','ALLOW','ROLE','hr'),(445,'DeviceProductionModels','*','*','ALLOW','ROLE','hr'),(446,'DeviceProductionState','*','*','ALLOW','ROLE','hr'),(447,'DeviceProductionUser','*','*','ALLOW','ROLE','hr'),(448,'DeviceProduction','*','*','ALLOW','ROLE','productionAssi'),(449,'DeviceProductionModels','*','*','ALLOW','ROLE','productionAssi'),(450,'DeviceProductionState','*','*','ALLOW','ROLE','productionAssi'),(451,'DeviceProductionUser','*','*','ALLOW','ROLE','productionAssi'),(452,'Worker','deallocatePDA','*','ALLOW','ROLE','hr'),(453,'Worker','allocatePDA','*','ALLOW','ROLE','hr'),(454,'Worker','deallocatePDA','*','ALLOW','ROLE','productionAssi'),(455,'Worker','allocatePDA','*','ALLOW','ROLE','productionAssi'),(456,'Zone','*','*','ALLOW','ROLE','deliveryAssistant'),(458,'Operator','*','READ','ALLOW','ROLE','employee'),(459,'Operator','*','WRITE','ALLOW','ROLE','employee'),(460,'InvoiceIn','getSerial','READ','ALLOW','ROLE','administrative'),(461,'Ticket','saveSign','WRITE','ALLOW','ROLE','employee'),(462,'InvoiceOut','negativeBases','READ','ALLOW','ROLE','administrative'),(463,'InvoiceOut','negativeBasesCsv','READ','ALLOW','ROLE','administrative'),(464,'WorkerObservation','*','*','ALLOW','ROLE','hr'),(465,'ClientInforma','*','READ','ALLOW','ROLE','employee'),(466,'ClientInforma','*','WRITE','ALLOW','ROLE','financial'),(467,'Receipt','receiptEmail','*','ALLOW','ROLE','salesAssistant'),(468,'Client','setRating','WRITE','ALLOW','ROLE','financial'),(470,'Client','addressesPropagateRe','*','ALLOW','ROLE','employee'),(471,'Client','canBeInvoiced','*','ALLOW','ROLE','employee'),(472,'Client','canCreateTicket','*','ALLOW','ROLE','employee'),(473,'Client','consumption','*','ALLOW','ROLE','employee'),(474,'Client','createAddress','*','ALLOW','ROLE','employee'),(475,'Client','createWithUser','*','ALLOW','ROLE','employee'),(476,'Client','extendedListFilter','*','ALLOW','ROLE','employee'),(477,'Client','getAverageInvoiced','*','ALLOW','ROLE','employee'),(478,'Client','getCard','*','ALLOW','ROLE','employee'),(479,'Client','getDebt','*','ALLOW','ROLE','employee'),(480,'Client','getMana','*','ALLOW','ROLE','employee'),(481,'Client','transactions','*','ALLOW','ROLE','employee'),(482,'Client','hasCustomerRole','*','ALLOW','ROLE','employee'),(483,'Client','isValidClient','*','ALLOW','ROLE','employee'),(484,'Client','lastActiveTickets','*','ALLOW','ROLE','employee'),(485,'Client','sendSms','*','ALLOW','ROLE','employee'),(486,'Client','setPassword','*','ALLOW','ROLE','employee'),(487,'Client','summary','*','ALLOW','ROLE','employee'),(488,'Client','updateAddress','*','ALLOW','ROLE','employee'),(489,'Client','updateFiscalData','*','ALLOW','ROLE','employee'),(491,'Client','uploadFile','*','ALLOW','ROLE','employee'),(492,'Client','campaignMetricsPdf','*','ALLOW','ROLE','employee'),(493,'Client','campaignMetricsEmail','*','ALLOW','ROLE','employee'),(494,'Client','clientWelcomeHtml','*','ALLOW','ROLE','employee'),(495,'Client','clientWelcomeEmail','*','ALLOW','ROLE','employee'),(496,'Client','printerSetupHtml','*','ALLOW','ROLE','employee'),(497,'Client','printerSetupEmail','*','ALLOW','ROLE','employee'),(498,'Client','sepaCoreEmail','*','ALLOW','ROLE','employee'),(499,'Client','letterDebtorPdf','*','ALLOW','ROLE','employee'),(500,'Client','letterDebtorStHtml','*','ALLOW','ROLE','employee'),(501,'Client','letterDebtorStEmail','*','ALLOW','ROLE','employee'),(502,'Client','letterDebtorNdHtml','*','ALLOW','ROLE','employee'),(503,'Client','letterDebtorNdEmail','*','ALLOW','ROLE','employee'),(504,'Client','clientDebtStatementPdf','*','ALLOW','ROLE','employee'),(505,'Client','clientDebtStatementHtml','*','ALLOW','ROLE','employee'),(506,'Client','clientDebtStatementEmail','*','ALLOW','ROLE','employee'),(507,'Client','creditRequestPdf','*','ALLOW','ROLE','employee'),(508,'Client','creditRequestHtml','*','ALLOW','ROLE','employee'),(509,'Client','creditRequestEmail','*','ALLOW','ROLE','employee'),(510,'Client','incotermsAuthorizationPdf','*','ALLOW','ROLE','employee'),(511,'Client','incotermsAuthorizationHtml','*','ALLOW','ROLE','employee'),(512,'Client','incotermsAuthorizationEmail','*','ALLOW','ROLE','employee'),(513,'Client','consumptionSendQueued','*','ALLOW','ROLE','employee'),(514,'Client','filter','*','ALLOW','ROLE','employee'),(515,'Client','getClientOrSupplierReference','*','ALLOW','ROLE','employee'),(516,'Client','upsert','*','ALLOW','ROLE','employee'),(518,'Client','replaceById','*','ALLOW','ROLE','employee'),(519,'Client','updateAttributes','*','ALLOW','ROLE','employee'),(520,'Client','updateAttributes','*','ALLOW','ROLE','employee'),(521,'Client','deleteById','*','ALLOW','ROLE','employee'),(522,'Client','replaceOrCreate','*','ALLOW','ROLE','employee'),(523,'Client','updateAll','*','ALLOW','ROLE','employee'),(524,'Client','upsertWithWhere','*','ALLOW','ROLE','employee'),(525,'Defaulter','observationEmail','WRITE','ALLOW','ROLE','employee'),(527,'VnUser','acl','READ','ALLOW','ROLE','account'),(528,'VnUser','getCurrentUserData','READ','ALLOW','ROLE','account'),(530,'Account','exists','READ','ALLOW','ROLE','account'),(531,'Account','exists','READ','ALLOW','ROLE','account'),(532,'UserLog','*','READ','ALLOW','ROLE','employee'),(533,'RoleLog','*','READ','ALLOW','ROLE','employee'),(534,'WagonType','*','*','ALLOW','ROLE','productionAssi'),(535,'WagonTypeColor','*','*','ALLOW','ROLE','productionAssi'),(536,'WagonTypeTray','*','*','ALLOW','ROLE','productionAssi'),(537,'WagonConfig','*','*','ALLOW','ROLE','productionAssi'),(538,'CollectionWagon','*','*','ALLOW','ROLE','productionAssi'),(539,'CollectionWagonTicket','*','*','ALLOW','ROLE','productionAssi'),(540,'Wagon','*','*','ALLOW','ROLE','productionAssi'),(541,'WagonType','createWagonType','*','ALLOW','ROLE','productionAssi'),(542,'WagonType','deleteWagonType','*','ALLOW','ROLE','productionAssi'),(543,'WagonType','editWagonType','*','ALLOW','ROLE','productionAssi'),(544,'Docuware','deliveryNoteEmail','WRITE','ALLOW','ROLE','employee'),(545,'Agency','find','READ','ALLOW','ROLE','employee'),(546,'Agency','seeExpired','READ','ALLOW','ROLE','coolerAssist'),(547,'WorkerLog','models','READ','ALLOW','ROLE','hr'),(548,'Ticket','editDiscount','WRITE','ALLOW','ROLE','claimManager'),(549,'Ticket','editDiscount','WRITE','ALLOW','ROLE','salesPerson'),(550,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','salesAssistant'),(551,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','deliveryAssistant'),(552,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','buyer'),(553,'Ticket','isRoleAdvanced','*','ALLOW','ROLE','claimManager'),(554,'Ticket','deleteTicketWithPartPrepared','WRITE','ALLOW','ROLE','salesAssistant'),(555,'Ticket','editZone','WRITE','ALLOW','ROLE','deliveryAssistant'),(556,'State','editableStates','READ','ALLOW','ROLE','employee'),(557,'State','seeEditableStates','READ','ALLOW','ROLE','administrative'),(558,'State','seeEditableStates','READ','ALLOW','ROLE','production'),(559,'State','isSomeEditable','READ','ALLOW','ROLE','salesPerson'),(560,'State','isAllEditable','READ','ALLOW','ROLE','production'),(561,'State','isAllEditable','READ','ALLOW','ROLE','administrative'),(562,'Agency','seeExpired','READ','ALLOW','ROLE','administrative'),(563,'Agency','seeExpired','READ','ALLOW','ROLE','productionBoss'),(564,'Claim','createAfterDeadline','WRITE','ALLOW','ROLE','claimManager'),(565,'Client','editAddressLogifloraAllowed','WRITE','ALLOW','ROLE','salesAssistant'),(566,'Client','editFiscalDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'),(567,'Client','editVerifiedDataWithoutTaxDataCheck','WRITE','ALLOW','ROLE','salesAssistant'),(568,'Client','editCredit','WRITE','ALLOW','ROLE','financialBoss'),(569,'Client','zeroCreditEditor','WRITE','ALLOW','ROLE','financialBoss'),(570,'InvoiceOut','canCreatePdf','WRITE','ALLOW','ROLE','invoicing'),(571,'Supplier','editPayMethodCheck','WRITE','ALLOW','ROLE','financial'),(572,'Worker','isTeamBoss','WRITE','ALLOW','ROLE','teamBoss'),(573,'Worker','forceIsSubordinate','READ','ALLOW','ROLE','hr'),(574,'Claim','editState','WRITE','ALLOW','ROLE','claimManager'),(577,'Claim','findOne','READ','ALLOW','ROLE','salesPerson'),(579,'Claim','updateClaim','WRITE','ALLOW','ROLE','salesPerson'),(580,'Claim','regularizeClaim','WRITE','ALLOW','ROLE','claimManager'),(581,'Claim','updateClaimDestination','WRITE','ALLOW','ROLE','claimManager'),(582,'Claim','downloadFile','READ','ALLOW','ROLE','claimManager'),(583,'Claim','deleteById','WRITE','ALLOW','ROLE','claimManager'),(585,'Claim','logs','READ','ALLOW','ROLE','claimManager'),(586,'Ticket','find','READ','ALLOW','ROLE','employee'),(587,'Ticket','findById','READ','ALLOW','ROLE','employee'),(588,'Ticket','findOne','READ','ALLOW','ROLE','employee'),(589,'Ticket','getVolume','READ','ALLOW','ROLE','employee'),(590,'Ticket','getTotalVolume','READ','ALLOW','ROLE','employee'),(591,'Ticket','summary','READ','ALLOW','ROLE','employee'),(592,'Ticket','priceDifference','READ','ALLOW','ROLE','employee'),(593,'Ticket','componentUpdate','WRITE','ALLOW','ROLE','employee'),(594,'Ticket','new','WRITE','ALLOW','ROLE','employee'),(595,'Ticket','isEditable','READ','ALLOW','ROLE','employee'),(596,'Ticket','setDeleted','WRITE','ALLOW','ROLE','salesPerson'),(597,'Ticket','restore','WRITE','ALLOW','ROLE','employee'),(598,'Ticket','getSales','READ','ALLOW','ROLE','employee'),(599,'Ticket','getSalesPersonMana','READ','ALLOW','ROLE','employee'),(600,'Ticket','filter','READ','ALLOW','ROLE','employee'),(601,'Ticket','makeInvoice','WRITE','ALLOW','ROLE','employee'),(602,'Ticket','updateEditableTicket','WRITE','ALLOW','ROLE','employee'),(603,'Ticket','updateDiscount','WRITE','ALLOW','ROLE','employee'),(604,'Ticket','transferSales','WRITE','ALLOW','ROLE','employee'),(605,'Ticket','sendSms','WRITE','ALLOW','ROLE','employee'),(606,'Ticket','isLocked','READ','ALLOW','ROLE','employee'),(607,'Ticket','freightCost','READ','ALLOW','ROLE','employee'),(608,'Ticket','getComponentsSum','READ','ALLOW','ROLE','employee'),(609,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','delivery'),(610,'Ticket','deliveryNoteCsv','READ','ALLOW','ROLE','employee'),(611,'State','find','READ','ALLOW','ROLE','employee'),(612,'State','findById','READ','ALLOW','ROLE','employee'),(613,'State','findOne','READ','ALLOW','ROLE','employee'),(614,'Worker','find','READ','ALLOW','ROLE','employee'),(615,'Worker','findById','READ','ALLOW','ROLE','employee'),(616,'Worker','findOne','READ','ALLOW','ROLE','employee'),(617,'Worker','filter','READ','ALLOW','ROLE','employee'),(618,'Worker','getWorkedHours','READ','ALLOW','ROLE','employee'),(619,'Worker','active','READ','ALLOW','ROLE','employee'),(620,'Worker','activeWithRole','READ','ALLOW','ROLE','employee'),(621,'Worker','uploadFile','WRITE','ALLOW','ROLE','hr'),(622,'Worker','contracts','READ','ALLOW','ROLE','employee'),(623,'Worker','holidays','READ','ALLOW','ROLE','employee'),(624,'Worker','activeContract','READ','ALLOW','ROLE','employee'),(625,'Worker','activeWithInheritedRole','READ','ALLOW','ROLE','employee'),(626,'Ticket','collectionLabel','READ','ALLOW','ROLE','employee'),(628,'Ticket','expeditionPalletLabel','READ','ALLOW','ROLE','employee'),(629,'Ticket','editDiscount','WRITE','ALLOW','ROLE','artificialBoss'),(630,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesTeamBoss'),(635,'Ticket','updateAttributes','WRITE','ALLOW','ROLE','administrative'),(636,'Claim','claimPickupEmail','WRITE','ALLOW','ROLE','salesPerson'),(637,'Claim','downloadFile','READ','ALLOW','ROLE','salesPerson'),(638,'Agency','seeExpired','READ','ALLOW','ROLE','artificialBoss'),(639,'Agency','seeExpired','READ','ALLOW','ROLE','logisticAssistant'),(654,'Ticket','editZone','WRITE','ALLOW','ROLE','logisticAssistant'),(655,'Entry','addFromPackaging','WRITE','ALLOW','ROLE','production'),(656,'Entry','addFromBuy','WRITE','ALLOW','ROLE','production'),(657,'Supplier','getItemsPackaging','READ','ALLOW','ROLE','production'),(658,'Ticket','closeAll','WRITE','ALLOW','ROLE','system'),(659,'Account','*','*','ALLOW','ROLE','developerBoss'),(664,'MailForward','*','*','ALLOW','ROLE','itManagement'),(665,'Role','*','READ','ALLOW','ROLE','employee'),(666,'Role','*','WRITE','ALLOW','ROLE','it'),(667,'VnUser','*','*','ALLOW','ROLE','itManagement'),(668,'VnUser','__get__preview','READ','ALLOW','ROLE','employee'),(669,'VnUser','preview','*','ALLOW','ROLE','employee'),(670,'VnUser','create','*','ALLOW','ROLE','itManagement'),(672,'PackingSiteAdvanced','*','*','ALLOW','ROLE','production'),(673,'InvoiceOut','makePdfAndNotify','WRITE','ALLOW','ROLE','invoicing'),(674,'InvoiceOutConfig','*','READ','ALLOW','ROLE','invoicing'),(676,'Ticket','invoiceTickets','WRITE','ALLOW','ROLE','employee'),(680,'MailAliasAccount','*','READ','ALLOW','ROLE','employee'),(681,'MailAliasAccount','create','WRITE','ALLOW','ROLE','employee'),(682,'MailAliasAccount','deleteById','WRITE','ALLOW','ROLE','employee'),(683,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','itManagement'),(684,'WorkerDisableExcluded','*','READ','ALLOW','ROLE','itManagement'),(685,'WorkerDisableExcluded','*','WRITE','ALLOW','ROLE','itManagement'),(686,'MailForward','*','*','ALLOW','ROLE','hr'),(687,'ClientSms','find','READ','ALLOW','ROLE','employee'),(688,'ClientSms','create','WRITE','ALLOW','ROLE','employee'),(689,'Vehicle','sorted','WRITE','ALLOW','ROLE','employee'),(690,'Roadmap','*','*','ALLOW','ROLE','palletizerBoss'),(691,'Roadmap','*','*','ALLOW','ROLE','productionBoss'),(692,'ExpeditionTruck','*','*','ALLOW','ROLE','production'),(693,'ExpeditionTruck','*','*','ALLOW','ROLE','productionBoss'),(694,'MailAliasAccount','canEditAlias','WRITE','ALLOW','ROLE','marketingBoss'),(695,'ViaexpressConfig','internationalExpedition','WRITE','ALLOW','ROLE','employee'),(696,'ViaexpressConfig','renderer','READ','ALLOW','ROLE','employee'),(697,'Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'),(698,'Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer'),(699,'TicketSms','find','READ','ALLOW','ROLE','salesPerson'),(701,'Docuware','upload','WRITE','ALLOW','ROLE','deliveryAssistant'),(702,'Ticket','docuwareDownload','READ','ALLOW','ROLE','salesPerson'),(703,'Worker','search','READ','ALLOW','ROLE','employee'),(704,'ExpeditionState','addExpeditionState','WRITE','ALLOW','ROLE','delivery'),(705,'SaleGroupDetail','deleteById','WRITE','ALLOW','ROLE','employee'),(706,'Ticket','setDeleted','WRITE','ALLOW','ROLE','buyer'),(707,'DeviceLog','create','WRITE','ALLOW','ROLE','employee'),(708,'Collection','getTickets','WRITE','ALLOW','ROLE','employee'),(709,'Client','findOne','READ','ALLOW','ROLE','employee'),(710,'Client','findById','READ','ALLOW','ROLE','employee'),(711,'Client','find','READ','ALLOW','ROLE','employee'),(712,'Client','exists','READ','ALLOW','ROLE','employee'),(713,'Client','__get__addresses','READ','ALLOW','ROLE','employee'),(714,'ExpeditionMistakeType','*','READ','ALLOW','ROLE','employee'),(715,'WorkerMistakeType','*','READ','ALLOW','ROLE','employee'),(716,'ExpeditionMistake','*','WRITE','ALLOW','ROLE','employee'),(717,'WorkerMistake','*','WRITE','ALLOW','ROLE','coolerAssist'),(718,'MistakesTypes','*','WRITE','ALLOW','ROLE','coolerAssist'),(719,'MistakeType','*','READ','ALLOW','ROLE','employee'),(720,'MachineWorker','*','READ','ALLOW','ROLE','coolerAssist'),(721,'Printer','*','READ','ALLOW','ROLE','employee'),(722,'SaleMistake','*','WRITE','ALLOW','ROLE','production'),(723,'Item','setVisibleDiscard','WRITE','ALLOW','ROLE','employee'),(724,'Address','getAddress','READ','ALLOW','ROLE','employee'),(725,'Account','findOne','READ','ALLOW','ROLE','employee'),(726,'Account','findById','READ','ALLOW','ROLE','employee'),(727,'Account','find','READ','ALLOW','ROLE','employee'),(728,'Account','exists','READ','ALLOW','ROLE','employee'),(729,'Sale','refund','WRITE','ALLOW','ROLE','buyer'),(730,'Ticket','setDeleted','WRITE','ALLOW','ROLE','deliveryAssistant'),(732,'Sale','isInPreparing','*','ALLOW','ROLE','production'),(733,'Train','*','READ','ALLOW','ROLE','production'),(734,'WorkerDepartment','*','*','ALLOW','ROLE','employee'),(735,'VnUser','higherPrivileges','*','ALLOW','ROLE','itManagement'),(736,'VnUser','mediumPrivileges','*','ALLOW','ROLE','hr'),(737,'VnUser','updateUser','*','ALLOW','ROLE','employee'),(738,'TicketCollection','*','WRITE','ALLOW','ROLE','production'),(739,'Worker','setPassword','*','ALLOW','ROLE','employee'),(740,'Url','getByUser','READ','ALLOW','ROLE','$everyone'),(741,'Claim','__get__lines','READ','ALLOW','ROLE','claimViewer'),(742,'AddressShortage','*','READ','ALLOW','ROLE','production'),(743,'Claim','filter','READ','ALLOW','ROLE','claimViewer'),(744,'Claim','find','READ','ALLOW','ROLE','claimViewer'),(745,'Claim','findById','READ','ALLOW','ROLE','claimViewer'),(746,'Claim','getSummary','READ','ALLOW','ROLE','claimViewer'),(747,'CplusRectificationType','*','READ','ALLOW','ROLE','administrative'),(748,'SiiTypeInvoiceOut','*','READ','ALLOW','ROLE','salesPerson'),(749,'InvoiceCorrectionType','*','READ','ALLOW','ROLE','salesPerson'),(750,'InvoiceOut','transferInvoice','WRITE','ALLOW','ROLE','administrative'),(751,'Application','executeProc','*','ALLOW','ROLE','employee'),(752,'Application','executeFunc','*','ALLOW','ROLE','employee'),(753,'NotificationSubscription','getList','READ','ALLOW','ROLE','employee'),(754,'Route','find','READ','ALLOW','ROLE','employee'),(755,'Route','findById','READ','ALLOW','ROLE','employee'),(756,'Route','findOne','READ','ALLOW','ROLE','employee'),(757,'Route','getRoutesByWorker','READ','ALLOW','ROLE','employee'),(758,'Route','canViewAllRoute','READ','ALLOW','ROLE','deliveryAssistant'),(759,'Route','cmr','READ','ALLOW','ROLE','employee'),(760,'Route','downloadCmrsZip','READ','ALLOW','ROLE','employee'),(761,'Route','downloadZip','READ','ALLOW','ROLE','employee'),(762,'Route','filter','READ','ALLOW','ROLE','employee'),(763,'Route','getByWorker','READ','ALLOW','ROLE','employee'),(764,'Route','getDeliveryPoint','READ','ALLOW','ROLE','employee'),(765,'Route','getExternalCmrs','READ','ALLOW','ROLE','employee'),(766,'Route','getSuggestedTickets','READ','ALLOW','ROLE','employee'),(767,'Route','getTickets','READ','ALLOW','ROLE','employee'),(768,'Route','guessPriority','WRITE','ALLOW','ROLE','employee'),(769,'Route','insertTicket','WRITE','ALLOW','ROLE','employee'),(770,'Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryBoss'),(771,'Route','summary','READ','ALLOW','ROLE','employee'),(772,'Route','getExpeditionSummary','READ','ALLOW','ROLE','delivery'),(773,'WorkerTimeControl','login','READ','ALLOW','ROLE','timeControl'),(774,'WorkerTimeControl','getClockIn','READ','ALLOW','ROLE','timeControl'),(775,'WorkerTimeControl','clockIn','WRITE','ALLOW','ROLE','timeControl'),(776,'WorkerTimeControl','addTimeEntry','WRITE','ALLOW','ROLE','employee'),(777,'WorkerTimeControl','deleteTimeEntry','WRITE','ALLOW','ROLE','employee'),(778,'WorkerTimeControl','updateTimeEntry','WRITE','ALLOW','ROLE','employee'),(779,'WorkerTimeControl','sendMail','WRITE','ALLOW','ROLE','employee'),(780,'WorkerTimeControl','updateWorkerTimeControlMail','WRITE','ALLOW','ROLE','employee'),(781,'WorkerTimeControl','weeklyHourRecordEmail','WRITE','ALLOW','ROLE','employee'),(782,'WorkerTimeControl','getMailStates','READ','ALLOW','ROLE','employee'),(783,'WorkerTimeControl','resendWeeklyHourEmail','WRITE','ALLOW','ROLE','employee'); /*!40000 ALTER TABLE `ACL` ENABLE KEYS */; UNLOCK TABLES; @@ -206,13 +206,13 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:25 USE `vn`; -- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db2.static.verdnatura.es Database: vn -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -400,7 +400,7 @@ UNLOCK TABLES; LOCK TABLES `department` WRITE; /*!40000 ALTER TABLE `department` DISABLE KEYS */; -INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,106,763,0,0,0,0,31,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL),(22,'shopping','COMPRAS',2,3,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(23,'CMA','CAMARA',13,14,NULL,72,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL,NULL),(31,'it','INFORMATICA',4,5,NULL,72,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL,NULL),(34,NULL,'CONTABILIDAD',6,7,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(35,NULL,'FINANZAS',8,9,NULL,0,0,0,1,0,1,'/1/',NULL,1,'begonya@verdnatura.es',1,0,0,0,NULL,NULL),(36,NULL,'LABORAL',10,11,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(37,'PROD','PRODUCCION',12,27,NULL,72,1,1,1,7,1,'/1/',NULL,0,NULL,0,1,1,1,NULL,NULL),(38,NULL,'SACADO',15,16,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(39,NULL,'ENCAJADO',17,18,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(41,NULL,'ADMINISTRACION',28,29,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(43,'VT','VENTAS',30,53,NULL,0,0,0,1,11,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL),(44,'management','GERENCIA',54,55,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(45,'logistic','LOGISTICA',56,57,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(46,'delivery','REPARTO',58,59,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL),(48,NULL,'ALMACENAJE',60,61,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(49,NULL,'PROPIEDAD',62,63,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(52,NULL,'CARGA AEREA',64,65,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',66,67,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(54,NULL,'ORNAMENTALES',68,69,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(55,NULL,'TALLER NATURAL',70,73,14548,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,1,1,0,1118,NULL),(56,NULL,'TALLER ARTIFICIAL',71,72,8470,72,0,0,2,0,55,'/1/55/',NULL,0,NULL,0,1,1,0,1927,NULL),(58,'CMP','CAMPOS',74,77,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(59,NULL,'MANTENIMIENTO',78,79,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL),(60,NULL,'RECLAMACIONES',80,81,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,1,0,0,NULL,NULL),(61,NULL,'VNH',82,85,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(66,NULL,'VERDNAMADRID',86,87,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(68,NULL,'COMPLEMENTOS',19,20,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,0,0,NULL,NULL),(69,NULL,'VERDNABARNA',88,89,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(80,NULL,'EQUIPO J VALLES',31,32,4250,72,0,0,2,0,43,'/1/43/','jvp_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(86,NULL,'LIMPIEZA',90,91,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(89,NULL,'COORDINACION',92,93,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(90,NULL,'TRAILER',83,84,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL),(91,NULL,'ARTIFICIAL',21,22,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(92,NULL,'EQUIPO SILVERIO',33,34,1203,0,0,0,2,0,43,'/1/43/','sdc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(93,NULL,'CONFECCION',94,95,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL,NULL),(94,NULL,'EQUIPO J BROCAL',35,36,3797,0,0,0,2,0,43,'/1/43/','jes_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(95,NULL,'EQUIPO C ZAMBRANO',37,38,4667,0,0,0,2,0,43,'/1/43/','czg_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(96,NULL,'EQUIPO C LOPEZ',39,40,4661,0,0,0,2,0,43,'/1/43/','cla_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(115,NULL,'EQUIPO CLAUDI',41,42,3810,0,0,0,2,0,43,'/1/43/','csr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',43,44,7102,0,0,0,2,0,43,'/1/43/','ebt_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(124,NULL,'CONTROL INTERNO',96,97,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL),(125,NULL,'EQUIPO MIRIAM MAR',45,46,1118,0,0,0,2,0,43,'/1/43/','mir_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(126,NULL,'PRESERVADO',98,99,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,NULL,NULL),(128,NULL,'PALETIZADO',23,24,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(130,NULL,'REVISION',25,26,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(131,NULL,'INVERNADERO',75,76,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL),(132,NULL,'EQUIPO DC',47,48,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(133,'franceTeam','EQUIPO FRANCIA',49,50,1731,72,0,0,2,0,43,'/1/43/','fra_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(134,NULL,'EQUIPO RODRI',51,52,6264,0,0,0,2,0,43,'/1/43/','rhr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(135,'routers','ENRUTADORES',100,101,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(136,'heavyVehicles','VEHICULOS PESADOS',102,103,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(137,'sorter','SORTER',104,105,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,106,763,0,0,0,0,28,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL),(22,'shopping','COMPRAS',2,3,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(23,'CMA','CAMARA',13,14,NULL,72,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL,NULL),(31,'it','INFORMATICA',4,5,NULL,72,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL,NULL),(34,'accounting','CONTABILIDAD',6,7,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(35,'finance','FINANZAS',8,9,NULL,0,0,0,1,0,1,'/1/',NULL,1,'begonya@verdnatura.es',1,0,0,0,NULL,NULL),(36,'labor','LABORAL',10,11,NULL,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(37,'PROD','PRODUCCION',12,33,NULL,72,1,1,1,10,1,'/1/',NULL,0,NULL,0,1,1,1,NULL,NULL),(38,'picking','SACADO',15,16,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(39,'packing','ENCAJADO',17,18,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(41,'administration','ADMINISTRACION',34,35,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(43,'VT','VENTAS',36,61,NULL,0,0,0,1,12,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL),(44,'management','GERENCIA',62,63,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(45,'logistic','LOGISTICA',64,65,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(46,'delivery','REPARTO',66,67,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL),(48,'storage','ALMACENAJE',68,69,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(49,NULL,'PROPIEDAD',70,71,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(52,NULL,'CARGA AEREA',72,73,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(53,'marketing','MARKETING Y COMUNICACIÓN',74,75,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL),(54,NULL,'ORNAMENTALES',76,77,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(55,NULL,'TALLER NATURAL',19,20,14548,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1118,NULL),(56,NULL,'TALLER ARTIFICIAL',21,22,8470,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1927,NULL),(58,'CMP','CAMPOS',78,81,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(59,'maintenance','MANTENIMIENTO',82,83,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL),(60,'claims','RECLAMACIONES',84,85,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,1,0,0,NULL,NULL),(61,NULL,'VNH',86,89,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(66,NULL,'VERDNAMADRID',90,91,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(68,NULL,'COMPLEMENTOS',23,24,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,0,0,NULL,NULL),(69,NULL,'VERDNABARNA',92,93,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(80,NULL,'EQUIPO J VALLES',37,38,4250,72,0,0,2,0,43,'/1/43/','jvp_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(86,NULL,'LIMPIEZA',94,95,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(89,NULL,'COORDINACION',96,97,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(90,NULL,'TRAILER',87,88,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL),(91,'artificial','ARTIFICIAL',25,26,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(92,NULL,'EQUIPO SILVERIO',39,40,1203,0,0,0,2,0,43,'/1/43/','sdc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(94,NULL,'EQUIPO J BROCAL',41,42,3797,0,0,0,2,0,43,'/1/43/','jes_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(95,NULL,'EQUIPO C ZAMBRANO',43,44,4667,0,0,0,2,0,43,'/1/43/','czg_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(96,NULL,'EQUIPO C LOPEZ',45,46,4661,0,0,0,2,0,43,'/1/43/','cla_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(115,NULL,'EQUIPO CLAUDI',47,48,3810,0,0,0,2,0,43,'/1/43/','csr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',49,50,7102,0,0,0,2,0,43,'/1/43/','ebt_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(124,NULL,'CONTROL INTERNO',98,99,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL),(125,NULL,'EQUIPO MIRIAM MAR',51,52,1118,0,0,0,2,0,43,'/1/43/','mir_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(126,NULL,'PRESERVADO',27,28,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,NULL,NULL),(128,NULL,'PALETIZADO',29,30,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(130,NULL,'REVISION',31,32,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL),(131,'greenhouse','INVERNADERO',79,80,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL),(132,NULL,'EQUIPO DC',53,54,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(133,'franceTeam','EQUIPO FRANCIA',55,56,1731,72,0,0,2,0,43,'/1/43/','fra_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(134,NULL,'EQUIPO RODRI',57,58,6264,0,0,0,2,0,43,'/1/43/','rhr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL),(135,'routers','ENRUTADORES',100,101,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(136,'heavyVehicles','VEHICULOS PESADOS',102,103,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(137,'sorter','SORTER',104,105,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL),(139,NULL,'EQUIPO MIRIAM MAR 2',59,60,3803,0,0,0,2,0,43,'/1/43/','mir2_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); /*!40000 ALTER TABLE `department` ENABLE KEYS */; UNLOCK TABLES; @@ -480,7 +480,7 @@ UNLOCK TABLES; LOCK TABLES `workCenter` WRITE; /*!40000 ALTER TABLE `workCenter` DISABLE KEYS */; -INSERT INTO `workCenter` VALUES (1,'Silla',20,859,1,'Av espioca 100',552703,NULL),(2,'Mercaflor',19,NULL,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL,NULL),(4,'VNH',NULL,NULL,NULL,NULL,NULL,NULL),(5,'Madrid',28,2869,5,'Av constitución 3',554145,0.50),(6,'Vilassar',88,88038,NULL,'Cami del Crist, 33',556412,NULL),(7,'Tenerife',NULL,NULL,NULL,NULL,NULL,NULL),(8,'Silla-Agrario',26,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,1354,60,'Fenollars, 2',523549,NULL),(10,'Rubi',88,NULL,84,'Av. de la Llana, 131',549722,0.50); +INSERT INTO `workCenter` VALUES (1,'Silla',20,859,1,'Av espioca 100',552703,NULL),(2,'Mercaflor',19,NULL,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL,NULL),(4,'VNH',NULL,NULL,NULL,NULL,NULL,NULL),(5,'Madrid',28,2869,5,'Av constitución 3',554145,2.00),(6,'Vilassar',88,88038,NULL,'Cami del Crist, 33',556412,NULL),(7,'Tenerife',NULL,NULL,NULL,NULL,NULL,NULL),(8,'Silla-Agrario',26,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,1354,60,'Fenollars, 2',523549,NULL),(10,'Rubi',88,NULL,84,'Av. de la Llana, 131',549722,NULL); /*!40000 ALTER TABLE `workCenter` ENABLE KEYS */; UNLOCK TABLES; @@ -522,13 +522,13 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:26 USE `cache`; -- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db2.static.verdnatura.es Database: cache -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -558,13 +558,13 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:26 USE `hedera`; -- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db2.static.verdnatura.es Database: hedera -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -724,13 +724,13 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:26 USE `sage`; -- MariaDB dump 10.19 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db2.static.verdnatura.es Database: sage -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -790,4 +790,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 12:26:42 +-- Dump completed on 2024-01-24 8:21:26 diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 694f745ef..ff18301d9 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -2,7 +2,7 @@ -- -- Host: db2.static.verdnatura.es Database: account -- ------------------------------------------------------ --- Server version 10.7.7-MariaDB-1:10.7.7+maria~deb11-log +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -314,6 +314,23 @@ CREATE TABLE `mailAliasAccount` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Mail alias that is assigned to each account'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `mailAliasAcl` +-- + +DROP TABLE IF EXISTS `mailAliasAcl`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mailAliasAcl` ( + `mailAliasFk` int(10) unsigned NOT NULL, + `roleFk` int(10) unsigned NOT NULL, + KEY `mailAliasFk` (`mailAliasFk`), + KEY `roleFk` (`roleFk`), + CONSTRAINT `mailAliasAcl_ibfk_1` FOREIGN KEY (`mailAliasFk`) REFERENCES `mailAlias` (`id`), + CONSTRAINT `mailAliasAcl_ibfk_2` FOREIGN KEY (`roleFk`) REFERENCES `role` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `mailClientAccess__` -- @@ -744,7 +761,9 @@ CREATE TABLE `signInLog` ( `token` varchar(255) NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, `creationDate` timestamp NULL DEFAULT current_timestamp(), + `userName` varchar(30) NOT NULL, `ip` varchar(100) NOT NULL, + `owner` tinyint(1) DEFAULT 1, PRIMARY KEY (`id`), KEY `userFk` (`userFk`), CONSTRAINT `signInLog_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE @@ -808,7 +827,7 @@ DELIMITER ;; FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); - + CALL user_checkName(NEW.`name`); IF NEW.nickname = '' THEN @@ -1005,27 +1024,6 @@ CREATE TABLE `userSync` ( -- -- Dumping events for database 'account' -- -/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; -/*!50106 DROP EVENT IF EXISTS `role_sync` */; -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 = utf8mb3 */ ;; -/*!50003 SET character_set_results = utf8mb3 */ ;; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ;; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; -/*!50003 SET @saved_time_zone = @@time_zone */ ;; -/*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`salix`@`10.0.%.%`*/ /*!50106 EVENT `role_sync` ON SCHEDULE AT '2023-11-16 14:32:48' ON COMPLETION NOT PRESERVE DISABLE ON SLAVE DO CALL role_sync */ ;; -/*!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 */ ; -- -- Dumping routines for database 'account' @@ -1060,7 +1058,7 @@ BEGIN SET vSignature = util.hmacSha2(256, CONCAT_WS('/', @userId, @userName), vKey); RETURN vSignature = @userSignature; END IF; - + RETURN FALSE; END ;; @@ -1089,7 +1087,7 @@ BEGIN * @return The user id */ DECLARE vUser INT DEFAULT NULL; - + IF myUser_checkLogin() THEN SET vUser = @userId; @@ -1097,7 +1095,7 @@ BEGIN SELECT id INTO vUser FROM user WHERE name = LEFT(USER(), INSTR(USER(), '@') - 1); END IF; - + RETURN vUser; END ;; DELIMITER ; @@ -1132,7 +1130,7 @@ BEGIN ELSE SET vUser = LEFT(USER(), INSTR(USER(), '@') - 1); END IF; - + RETURN vUser; END ;; DELIMITER ; @@ -1150,7 +1148,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_hasPriv`(vChain VARCHAR(100), +CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_hasPriv`(vChain VARCHAR(100), vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE') ) RETURNS tinyint(1) READS SQL DATA @@ -1285,10 +1283,10 @@ BEGIN DECLARE vDigitChars TEXT DEFAULT '1234567890'; DECLARE vPunctChars TEXT DEFAULT '!$%&()=.'; - SELECT length, nAlpha, nUpper, nDigits, nPunct + SELECT length, nAlpha, nUpper, nDigits, nPunct INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword; - WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha + WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO SET vRandIndex = FLOOR((RAND() * 4) + 1); @@ -1363,7 +1361,7 @@ BEGIN DECLARE vRole VARCHAR(255); SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole - FROM role r + FROM role r JOIN user u ON u.role = r.id JOIN roleConfig c WHERE u.name = vUserName; @@ -1390,16 +1388,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `user_getNameFromId`(vSelf INT) RETUR BEGIN /** * Gets user name from it's id. - * + * * @param vSelf The user id * @return The user name */ DECLARE vName VARCHAR(30); - - SELECT `name` INTO vName - FROM user + + SELECT `name` INTO vName + FROM user WHERE id = vSelf; - + RETURN vName; END ;; DELIMITER ; @@ -1417,8 +1415,8 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `user_hasPriv`(vChain VARCHAR(100), - vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE'), +CREATE DEFINER=`root`@`localhost` FUNCTION `user_hasPriv`(vChain VARCHAR(100), + vPrivilege ENUM('SELECT','INSERT','UPDATE','DELETE'), vUserFk INT ) RETURNS tinyint(1) READS SQL DATA @@ -1440,16 +1438,20 @@ BEGIN SET vDb = SUBSTRING_INDEX(vChain, '.', 1); SET vChain = SUBSTRING(vChain, LENGTH(vDb) + 2); - SET vTableName = SUBSTRING_INDEX(vChain, '.', 1); - SET vColumnName = SUBSTRING(vChain, LENGTH(vTableName) + 2); - + IF LOCATE('.', vChain) > 0 THEN + SET vTableName = SUBSTRING_INDEX(vChain, '.', 1); + SET vColumnName = SUBSTRING(vChain, LENGTH(vTableName) + 2); + ELSE + SET vTableName = vChain; + END IF; + SELECT COUNT(*) INTO vChainExists FROM information_schema.COLUMNS - WHERE TABLE_SCHEMA = vDb - AND TABLE_NAME = vTableName - AND COLUMN_NAME = vColumnName - LIMIT 1; - + WHERE TABLE_SCHEMA = vDb + AND TABLE_NAME = vTableName + AND (COLUMN_NAME = vColumnName OR vColumnName IS NULL) + LIMIT 1; + IF NOT vChainExists THEN RETURN FALSE; END IF; @@ -1474,22 +1476,22 @@ BEGIN SELECT hasPrivilege INTO vHasPrivilege FROM (SELECT JSON_VALUE(Priv, '$.access') & vPrivilegeFlag hasPrivilege - FROM mysql.global_priv gp + FROM mysql.global_priv gp JOIN tRole tr ON CONCAT(tr.name) = gp.User HAVING hasPrivilege LIMIT 1)sub; - + IF NOT vHasPrivilege THEN - SELECT sub.privilege = 'Y' INTO vHasPrivilege - FROM - (SELECT CASE vPrivilege - WHEN 'SELECT' THEN Select_priv - WHEN 'INSERT' THEN Insert_priv - WHEN 'UPDATE' THEN Update_priv - WHEN 'DELETE' THEN Delete_priv - END privilege - FROM mysql.db db + SELECT sub.privilege = 'Y' INTO vHasPrivilege + FROM + (SELECT CASE vPrivilege + WHEN 'SELECT' THEN Select_priv + WHEN 'INSERT' THEN Insert_priv + WHEN 'UPDATE' THEN Update_priv + WHEN 'DELETE' THEN Delete_priv + END privilege + FROM mysql.db db JOIN tRole tr ON tr.name = db.User WHERE db.Db = vDb)sub; @@ -1498,13 +1500,13 @@ BEGIN IF NOT vHasPrivilege THEN SELECT TRUE INTO vHasPrivilege - FROM tRole tr + FROM tRole tr LEFT JOIN ( SELECT User, Table_priv privilege FROM mysql.tables_priv WHERE Db = vDb AND Table_name = vTableName - UNION + UNION SELECT User, Column_priv FROM mysql.columns_priv WHERE Db = vDb @@ -1587,7 +1589,7 @@ BEGIN JOIN role r ON r.id = rr.inheritsFrom WHERE u.`name` = vUser AND r.id = vRoleId; - + RETURN vHasRole; END ;; DELIMITER ; @@ -1624,7 +1626,7 @@ BEGIN DECLARE vObject VARCHAR(50); DECLARE vChainExists BOOL; DECLARE vExecutePriv INT DEFAULT 262144; - -- 262144 = CONV(1000000000000000000, 2, 10) + -- 262144 = CONV(1000000000000000000, 2, 10) -- 1000000000000000000 execution permission expressed in binary base SET vDb = SUBSTRING_INDEX(vChain, '.', 1); @@ -1636,7 +1638,7 @@ BEGIN WHERE db = vDb AND `name` = vObject AND `type` = vType - LIMIT 1; + LIMIT 1; IF NOT vChainExists THEN RETURN FALSE; @@ -1651,18 +1653,18 @@ BEGIN JOIN roleRole rr ON rr.role = u.role JOIN `role` r ON r.id = rr.inheritsFrom WHERE u.id = vUserFk; - + SELECT TRUE INTO vHasPrivilege - FROM mysql.global_priv gp - JOIN tRole tr ON tr.name = gp.`User` + FROM mysql.global_priv gp + JOIN tRole tr ON tr.name = gp.`User` OR CONCAT('$', tr.name) = gp.`User` WHERE JSON_VALUE(gp.Priv, '$.access') >= vExecutePriv AND gp.Host = '' LIMIT 1; IF NOT vHasPrivilege THEN - SELECT TRUE INTO vHasPrivilege - FROM mysql.db db + SELECT TRUE INTO vHasPrivilege + FROM mysql.db db JOIN tRole tr ON tr.name = db.`User` WHERE db.Db = vDb AND db.Execute_priv = 'Y'; @@ -1670,7 +1672,7 @@ BEGIN IF NOT vHasPrivilege THEN SELECT TRUE INTO vHasPrivilege - FROM mysql.procs_priv pp + FROM mysql.procs_priv pp JOIN tRole tr ON tr.name = pp.`User` WHERE pp.Db = vDb AND pp.Routine_name = vObject @@ -1750,7 +1752,7 @@ BEGIN AND password = MD5(vPassword) AND active; - IF vAuthIsOk + IF vAuthIsOk THEN CALL myUser_loginWithName (vUserName); ELSE @@ -1811,7 +1813,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_loginWithName`(vUserName VAR BEGIN /** * Logs in using only the user name. This procedure is intended to be executed - * by users with a high level of privileges so that normal users should not have + * by users with a high level of privileges so that normal users should not have * execute permissions on it. * * @param vUserName The user name @@ -1847,7 +1849,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_logout`() BEGIN /** * Logouts the user. - */ + */ SET @userId = NULL; SET @userName = NULL; SET @userSignature = NULL; @@ -1945,9 +1947,9 @@ BEGIN SELECT COUNT(*) > 0 INTO vIsRoot FROM tmp.role t - JOIN role r ON r.id = t.id + JOIN role r ON r.id = t.id WHERE r.`name` = 'root'; - + IF vIsRoot THEN INSERT IGNORE INTO tmp.role (id) SELECT id FROM role; @@ -2666,7 +2668,7 @@ BEGIN IF vChr REGEXP '[[:alpha:]]' THEN SET vNAlpha = vNAlpha+1; - + IF vChr REGEXP '[A-Z]' THEN SET vNUpper = vNUpper+1; @@ -3137,7 +3139,7 @@ BEGIN IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); - + END IF; END */;; @@ -3163,7 +3165,7 @@ BEGIN IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); - + END IF; END */;; @@ -3686,11 +3688,11 @@ BEGIN DECLARE vTramo VARCHAR(20); DECLARE vHour INT; - + SET vHour = HOUR(vDateTime) ; - + SET vTramo = - CASE + CASE WHEN vHour BETWEEN 0 AND 14 THEN 'Mañana' WHEN vHour BETWEEN 15 AND 24 THEN 'Tarde' END ; @@ -3718,7 +3720,7 @@ BEGIN * Inserta en la tabla bancos_evolution los saldos acumulados de cada banco * * @param vStartingDate Fecha desde la cual se recalculan la tabla bs.bancos_evolution - */ + */ DECLARE vCurrentDate DATE; DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, util.VN_CURDATE()); IF IFNULL(vStartingDate,0) < TIMESTAMPADD(YEAR, -5, util.VN_CURDATE()) THEN @@ -3732,49 +3734,49 @@ BEGIN SELECT vCurrentDate, Id_Banco, deuda FROM bs.bancos_evolution WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate); - + WHILE vCurrentDate < vMaxDate DO -- insertar solo el dia de ayer INSERT INTO bs.bancos_evolution(Fecha ,Id_Banco, saldo) - SELECT vCurrentDate, Id_Banco, SUM(saldo) + SELECT vCurrentDate, Id_Banco, SUM(saldo) FROM ( SELECT Id_Banco ,saldo FROM bs.bancos_evolution WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate) -- los saldos acumulados del dia anterior UNION ALL - + SELECT c.Id_Banco, IFNULL(SUM(Entrada),0) - IFNULL(SUM(Salida),0) as saldo FROM vn2008.Cajas c JOIN vn2008.Bancos b using(Id_Banco) -- saldos de las cajas - JOIN vn.accountingType at2 ON at2.id = b.cash + JOIN vn.accountingType at2 ON at2.id = b.cash WHERE at2.code IN ('wireTransfer','fundingLine') AND Cajafecha = vCurrentDate AND (Serie = 'MB' OR at2.code = 'fundingLine') GROUP BY Id_Banco - )sub + )sub GROUP BY Id_Banco ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); - + SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate); END WHILE; - -- Ahora actualizamos la quilla + -- Ahora actualizamos la quilla UPDATE bs.bancos_evolution be JOIN ( SELECT bp.Id_Banco, - sum(bp.importe) as quilla, t.dated - FROM vn.time t + FROM vn.time t JOIN vn2008.Bancos_poliza bp ON t.dated between apertura AND IFNULL(cierre, t.dated) WHERE t.dated BETWEEN vStartingDate AND vMaxDate GROUP BY Id_Banco, t.dated ) sub ON be.Id_Banco = sub.Id_Banco AND sub.dated = be.Fecha - SET be.quilla = sub.quilla; + SET be.quilla = sub.quilla; -- pagos futuros no concilidados INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) SELECT t.dated, p.id_banco, - importe - FROM vn.time t + FROM vn.time t join vn2008.pago p ON p.fecha <= t.dated WHERE t.dated BETWEEN util.VN_CURDATE() AND vMaxDate AND p.fecha BETWEEN util.VN_CURDATE() AND vMaxDate @@ -3784,7 +3786,7 @@ BEGIN -- cobros futuros INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) SELECT t.dated, r.Id_Banco, SUM(Entregado) - FROM vn.time t + FROM vn.time t JOIN vn2008.Recibos r ON r.Fechacobro <= t.dated WHERE r.Fechacobro > util.VN_CURDATE() AND r.Fechacobro <= vMaxDate AND t.dated BETWEEN util.VN_CURDATE() AND vMaxDate @@ -3794,10 +3796,10 @@ BEGIN -- saldos de la tabla prevision INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) SELECT t.dated, sp.Id_Banco, SUM(Importe) - FROM vn.time t + FROM vn.time t JOIN vn2008.Saldos_Prevision sp ON sp.Fecha <= t.dated JOIN vn2008.Bancos b ON sp.Id_Banco = b.Id_Banco - JOIN vn.accountingType at2 ON at2.id = b.cash + JOIN vn.accountingType at2 ON at2.id = b.cash WHERE at2.code IN ('wireTransfer','fundingLine') AND t.dated BETWEEN vStartingDate AND vMaxDate GROUP BY t.dated, sp.Id_Banco @@ -3811,12 +3813,12 @@ BEGIN -- Deuda UPDATE bs.bancos_evolution be JOIN vn2008.Bancos b using(Id_Banco) - JOIN vn.accountingType at2 ON at2.id = b.cash + JOIN vn.accountingType at2 ON at2.id = b.cash SET be.deuda = IF(at2.code = 'fundingLine', be.saldo_aux, 0) , be.saldo = IF(at2.code = 'fundingLine', 0, be.saldo_aux) WHERE Fecha >= vStartingDate; - -- Liquidez + -- Liquidez update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate; -- Disponibilidad update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate; @@ -3839,14 +3841,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `campaignComparative`(vDateFrom DATE, vDateTo DATE) BEGIN - SELECT - workerName, - id, - name, - CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, - CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount + SELECT + workerName, + id, + name, + CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, + CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount FROM ( - (SELECT + (SELECT CONCAT(w.firstname, ' ', w.lastName) AS workerName, c.id, c.name, @@ -3855,11 +3857,11 @@ BEGIN FROM bs.ventas v INNER JOIN vn.`client` c ON v.Id_Cliente = c.id INNER JOIN vn.worker w ON c.salesPersonFk = w.id - WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) + WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR) GROUP BY w.id, v.Id_Cliente) UNION ALL - (SELECT + (SELECT CONCAT(w.firstname, ' ', w.lastName) AS workerName, c.id, c.name, @@ -3893,21 +3895,29 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `carteras_add`() -BEGIN -/** - * Inserta en @bs.carteras. - */ - DELETE FROM bs.carteras - WHERE Año >= YEAR(util.VN_CURDATE()) - 1; - - INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso) - SELECT t.year AS Año, t.month AS Mes, w.code AS CodigoTrabajador, SUM(v.importe) AS Peso - FROM vn.time t - JOIN bs.ventas v on t.dated = v.fecha - JOIN vn.client c on c.id = v.Id_Cliente - JOIN vn.worker w ON w.id = c.salesPersonFk - WHERE t.year >= YEAR(util.VN_CURDATE()) - 1 - GROUP BY w.code, t.year , t.month; +BEGIN +/** + * Inserta en la tabla @bs.carteras las ventas desde el año pasado + * agrupadas por trabajador, año y mes + */ + DECLARE vYear INT DEFAULT YEAR(util.VN_CURDATE()) - 1; + + DELETE FROM bs.carteras WHERE Año >= vYear; + + CALL util.time_generate( + MAKEDATE(vYear, 1), + (SELECT MAX(fecha) FROM ventas) + ); + + INSERT INTO carteras(Año, Mes , CodigoTrabajador, Peso) + SELECT t.`year`, t.`month`, w.code, SUM(v.importe) + FROM tmp.time t + JOIN ventas v on t.dated = v.fecha + JOIN vn.client c on c.id = v.Id_Cliente + JOIN vn.worker w ON w.id = c.salesPersonFk + GROUP BY w.code, t.`year`, t.`month`; + + DROP TEMPORARY TABLE tmp.time; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3926,18 +3936,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() BEGIN - DECLARE vFourYearsAgo DATETIME; - DECLARE vOneYearAgo DATETIME; - DECLARE vTwoYearAgo DATETIME; - DECLARE vThreeYearAgo DATETIME; + DECLARE vOneYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; + DECLARE vTwoYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; + DECLARE vThreeYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 3 YEAR; + DECLARE vFourYearsAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; + DECLARE vEighteenMonths DATE DEFAULT util.VN_CURDATE() - INTERVAL 18 MONTH; - SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,util.VN_CURDATE()); - SET vTwoYearAgo = TIMESTAMPADD(YEAR, -2,util.VN_CURDATE()); - SET vThreeYearAgo = TIMESTAMPADD(YEAR, -3,util.VN_CURDATE()); - SET vFourYearsAgo = TIMESTAMPADD(YEAR, -4,util.VN_CURDATE()); - - DELETE FROM bs.clientNewBorn + DELETE FROM clientNewBorn WHERE lastShipped < vOneYearAgo; DELETE FROM ventas @@ -3949,14 +3955,17 @@ BEGIN DELETE FROM payMethodClientEvolution WHERE dated < vFourYearsAgo; - DELETE FROM bs.salesByclientSalesPerson + DELETE FROM salesByclientSalesPerson WHERE dated < vFourYearsAgo; - DELETE FROM bs.m3 + DELETE FROM m3 WHERE fecha < vTwoYearAgo; DELETE FROM salesByItemTypeDay WHERE dated < vThreeYearAgo; + + DELETE FROM waste + WHERE MAKEDATE(`year`, 1) + INTERVAL (`week` - 1) WEEK + INTERVAL 1 DAY < vEighteenMonths; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4052,16 +4061,16 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `clientNewBorn_recalc`() BLOCK1: BEGIN DECLARE vClientFk INT; - DECLARE vShipped DATE; + DECLARE vShipped DATE; DECLARE vPreviousShipped DATE; - DECLARE vDone boolean; - DECLARE cur cursor for - - SELECT clientFk, firstShipped - FROM bs.clientNewBorn; - - DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; - SET vDone := FALSE; + DECLARE vDone boolean; + DECLARE cur cursor for + + SELECT clientFk, firstShipped + FROM bs.clientNewBorn; + + DECLARE continue HANDLER FOR NOT FOUND SET vDone = TRUE; + SET vDone := FALSE; DELETE FROM bs.clientNewBorn WHERE isModified = FALSE; @@ -4073,7 +4082,7 @@ BLOCK1: BEGIN WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null GROUP BY c.id; OPEN cur; - + LOOP1: LOOP SET vDone := FALSE; FETCH cur INTO vClientFk, vShipped; @@ -4084,37 +4093,37 @@ BLOCK1: BEGIN END IF; BLOCK2: BEGIN - DECLARE vCurrentShipped DATE; - DECLARE vDone2 boolean; + DECLARE vCurrentShipped DATE; + DECLARE vDone2 boolean; DECLARE cur2 CURSOR FOR - SELECT shipped - FROM vn.ticket + SELECT shipped + FROM vn.ticket WHERE clientFk = vClientFk AND shipped <= util.VN_CURDATE() ORDER BY shipped DESC; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE; SET vDone2 := FALSE; OPEN cur2; - + SET vPreviousShipped := vShipped; LOOP2: LOOP SET vDone2 := FALSE; FETCH cur2 INTO vCurrentShipped; - + IF DATEDIFF(vPreviousShipped,vCurrentShipped) > 365 THEN - UPDATE bs.clientNewBorn - SET firstShipped = vPreviousShipped + UPDATE bs.clientNewBorn + SET firstShipped = vPreviousShipped WHERE clientFk= vClientFk; - + CLOSE cur2; - LEAVE LOOP2; + LEAVE LOOP2; END IF; - + SET vPreviousShipped := vCurrentShipped; IF vDone2 THEN - UPDATE bs.clientNewBorn - SET firstShipped = vCurrentShipped + UPDATE bs.clientNewBorn + SET firstShipped = vCurrentShipped WHERE clientFk= vClientFk; CLOSE cur2; LEAVE LOOP2; @@ -4124,14 +4133,14 @@ BLOCK1: BEGIN END BLOCK2; END LOOP LOOP1; - UPDATE bs.clientNewBorn cnb + UPDATE bs.clientNewBorn cnb LEFT JOIN (SELECT DISTINCT t.clientFk FROM vn.ticket t JOIN vn.productionConfig pc WHERE t.shipped BETWEEN util.VN_CURDATE() + INTERVAL -(`notBuyingMonths`) MONTH AND util.VN_CURDATE() + INTERVAL -(`pc`.`rookieDays`) DAY) notRookie ON notRookie.clientFk = cnb.clientFk - SET cnb.isRookie = ISNULL(notRookie.clientFk); - + SET cnb.isRookie = ISNULL(notRookie.clientFk); + END BLOCK1 ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4152,16 +4161,16 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `comercialesCompleto`(IN vWorker INT BEGIN DECLARE vAYearAgoStarted DATE DEFAULT DATE_FORMAT(TIMESTAMPADD(YEAR, - 1, vDate), '%Y-%m-01'); DECLARE vAYearAgoEnded DATE DEFAULT TIMESTAMPADD(YEAR, - 1, LAST_DAY(vDate)); - + CALL vn.worker_GetHierarchy(vWorker); - + INSERT IGNORE INTO tmp.workerHierarchyList (workerFk) SELECT wd2.workerFk FROM vn.workerDepartment wd2 WHERE wd2.workerFk = vWorker; - + -- Falta que en algunos casos solo tenga en cuenta los tipos afectados. - SELECT + SELECT c.Id_Cliente id_cliente, c.Cliente cliente, cr.recobro * 100 tarifa, @@ -4186,7 +4195,7 @@ BEGIN FROM vn2008.Clientes c LEFT JOIN - (SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge + (SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge FROM vn2008.Greuges g JOIN vn.`client` c ON c.id = g.Id_Cliente LEFT JOIN vn.worker w ON c.salesPersonFk = w.id @@ -4208,14 +4217,14 @@ BEGIN WHERE v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, vDate) AND vDate GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente LEFT JOIN - (SELECT + (SELECT Id_Cliente, SUM(importe) consumo FROM bs.ventas v INNER JOIN vn2008.Clientes c USING (Id_Cliente) LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador WHERE - (c.Id_Trabajador = vWorker OR tr.boss = vWorker) + (c.Id_Trabajador = vWorker OR tr.boss = vWorker) AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(vDate) + 1, vDate) AND TIMESTAMPADD(DAY, - 1, vDate)) GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente LEFT JOIN @@ -4276,17 +4285,17 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_evolution_add`() BEGIN /** * Inserta en la tabla compradores_evolution las ventas acumuladas en los ultimos 365 dias - * + * */ DECLARE vDated DATE; DECLARE vCount INT DEFAULT 1; - SELECT MAX(fecha) + INTERVAL 1 DAY INTO vDated + SELECT MAX(fecha) + INTERVAL 1 DAY INTO vDated FROM compradores_evolution; IF vDated IS NULL THEN - - SELECT MIN(dated) INTO vDated + + SELECT MIN(dated) INTO vDated FROM sale; INSERT INTO compradores_evolution( @@ -4307,7 +4316,7 @@ BEGIN WHILE vDated < util.VN_CURDATE() DO SET vCount = vCount + 1; - + REPLACE compradores_evolution( Id_Trabajador, fecha, @@ -4319,18 +4328,18 @@ BEGIN SELECT Id_Trabajador, importe FROM compradores_evolution JOIN ( - SELECT DISTINCT it.workerFk - FROM vn.itemType it + SELECT DISTINCT it.workerFk + FROM vn.itemType it )sub2 ON sub2.workerFk = Id_Trabajador - WHERE fecha = vDated - INTERVAL 1 DAY + WHERE fecha = vDated - INTERVAL 1 DAY UNION ALL - SELECT it.workerFk, s.amount * IF(s.dated < vDated, -1, 1) + SELECT it.workerFk, s.amount * IF(s.dated < vDated, -1, 1) FROM sale s JOIN vn.itemType it ON it.id = s.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE s.dated IN (vDated, vDated - INTERVAL 1 YEAR) AND ic.merchandise - )sub + )sub GROUP BY Id_Trabajador; SET vDated = vDated + INTERVAL 1 DAY; @@ -4357,49 +4366,49 @@ BEGIN * Inserta en la tabla fondo_maniobra los saldos acumulados en los ultimos 365 dias */ DECLARE datFEC DATE DEFAULT '2015-01-01'; - - SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) - INTO datFEC + + SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) + INTO datFEC FROM bs.fondo_maniobra; - + WHILE datFEC < util.VN_CURDATE() DO - + IF DAY(datFEC) MOD 28 = 0 THEN -- esto solo sirve para no aburrirse mientras esperamos... SELECT datFEC; END IF; - + REPLACE bs.fondo_maniobra(Fecha, clientes_facturas, clientes_cobros,proveedores_facturas,proveedores_pagos, fondo) SELECT datFEC AS Fecha, Facturas, Cobros,Recibidas,Pagos, Facturas + Cobros + Recibidas + Pagos FROM ( SELECT SUM(io.amount) AS Facturas FROM vn.invoiceOut io - JOIN vn.client c ON io.clientFk = c.id + JOIN vn.client c ON io.clientFk = c.id WHERE c.isRelevant - AND io.companyFk <> 1381 + AND io.companyFk <> 1381 AND io.issued BETWEEN '2011-01-01' AND datFEC ) fac JOIN ( SELECT - SUM(r.amountPaid) AS Cobros - FROM vn.receipt r - JOIN vn.client c ON r.clientFk = c.id - WHERE c.isRelevant + FROM vn.receipt r + JOIN vn.client c ON r.clientFk = c.id + WHERE c.isRelevant AND r.companyFk <> 1381 AND r.payed BETWEEN '2011-01-01' AND datFEC ) cob JOIN ( SELECT - SUM(id.amount) AS Recibidas - FROM vn.invoiceIn ii - JOIN vn.invoiceInDueDay id ON ii.id = id.invoiceInFk + FROM vn.invoiceIn ii + JOIN vn.invoiceInDueDay id ON ii.id = id.invoiceInFk WHERE ii.companyFk <> 1381 AND ii.issued BETWEEN '2015-01-01' AND datFEC ) rec JOIN ( SELECT SUM(p.amount) AS Pagos - FROM vn.payment p - WHERE p.companyFk <>1381 + FROM vn.payment p + WHERE p.companyFk <>1381 AND p.received BETWEEN '2015-01-01' AND datFEC ) pag; - + UPDATE bs.fondo_maniobra JOIN ( SELECT AVG(fondo) AS media @@ -4407,7 +4416,7 @@ BEGIN WHERE fecha <= datFEC ) sub SET fondo_medio = media WHERE fecha = datFEC; - + SET datFEC = TIMESTAMPADD(DAY,1,datFEC); END WHILE; @@ -4431,7 +4440,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fruitsEvolution`() BEGIN -select Id_Cliente, +select Id_Cliente, Cliente, count(semana) as semanas, (w.code IS NOT NULL) isWorker from ( select distinct v.Id_Cliente, c.name as Cliente, week(fecha, 3) as semana @@ -4472,40 +4481,40 @@ BEGIN -- Ventas totales del ultimo año UPDATE indicators - SET lastYearSales = + SET lastYearSales = (SELECT SUM(importe + recargo) FROM ventas v JOIN vn2008.empresa e ON e.id = v.empresa_id JOIN vn2008.empresa_grupo eg ON eg.empresa_grupo_id = e.empresa_grupo WHERE fecha BETWEEN oneYearBefore AND vDated AND eg.grupo = 'Verdnatura' - ) + ) WHERE updated = vDated; - + -- Greuge total acumulado UPDATE indicators - SET totalGreuge = + SET totalGreuge = (SELECT SUM(amount) FROM vn.greuge WHERE shipped <= vDated - ) + ) WHERE updated = vDated; -- Tasa de morosidad con respecto a las ventas del último mes UPDATE indicators - SET latePaymentRate = - (SELECT SUM(amount) - FROM bi.defaulters + SET latePaymentRate = + (SELECT SUM(amount) + FROM bi.defaulters WHERE date = vDated AND amount > 0) / - (SELECT SUM(importe + recargo) - FROM ventas + (SELECT SUM(importe + recargo) + FROM ventas WHERE fecha BETWEEN oneMonthBefore AND vDated) WHERE updated = vDated; -- Número de trabajadores activos UPDATE indicators - SET countEmployee = + SET countEmployee = (SELECT CAST(SUM(ct.hoursWeek) / 40 AS DECIMAL (10, 2)) FROM vn.business b JOIN vn.calendarType ct ON ct.id = b.calendarTypeFk @@ -4524,7 +4533,7 @@ BEGIN -- Número de clientes que han comprado en los últimos 30 dias UPDATE indicators - SET lastMonthActiveClients = + SET lastMonthActiveClients = (SELECT COUNT(DISTINCT t.clientFk) FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated @@ -4533,9 +4542,9 @@ BEGIN -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores UPDATE indicators - SET lastMonthLostClients = + SET lastMonthLostClients = (SELECT COUNT(lm.clientFk) - FROM + FROM (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated @@ -4552,9 +4561,9 @@ BEGIN -- Número de clientes que han comprado en los últimos 30 dias, pero no compraron en los 30 anteriores UPDATE indicators - SET lastMonthNewClients = + SET lastMonthNewClients = (SELECT COUNT(cm.clientFk) - FROM + FROM (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated @@ -4580,7 +4589,7 @@ BEGIN -- Cálculo de las ventas agrupado por semanas SELECT week INTO vWeek - FROM vn.time + FROM vn.time WHERE dated = vDated; TRUNCATE salesByWeek; @@ -4594,12 +4603,12 @@ BEGIN -- Indicador Ventas semana actual UPDATE indicators i - JOIN salesByWeek s ON s.week= vWeek + JOIN salesByWeek s ON s.week= vWeek AND s.year = YEAR(vDated) SET i.thisWeekSales = s.sales WHERE updated = vDated; - -- Indicador ventas semana actual en el año pasado + -- Indicador ventas semana actual en el año pasado UPDATE indicators i JOIN salesByWeek s ON s.week = vWeek AND s.year = YEAR(vDated)-1 @@ -4630,15 +4639,15 @@ BEGIN SELECT IFNULL(TIMESTAMPADD(DAY,1,MAX(updated)), '2018-04-01') INTO vDated FROM bs.indicators; - + WHILE vDated < util.VN_CURDATE() DO - + CALL indicatorsUpdate(vDated); - + SELECT TIMESTAMPADD(DAY,1,MAX(updated)) INTO vDated FROM bs.indicators; - + END WHILE; END ;; @@ -4667,7 +4676,7 @@ BEGIN DECLARE vCalc INT; DECLARE vWarehouseFk INT; - DECLARE cWarehouses CURSOR FOR + DECLARE cWarehouses CURSOR FOR SELECT id FROM vn.warehouse WHERE isInventory; @@ -4680,13 +4689,13 @@ BEGIN read_loop: LOOP SET vDone = FALSE; FETCH cWarehouses INTO vWarehouseFk; - + IF vDone THEN LEAVE read_loop; END IF; - + CALL cache.visible_refresh(vCalc, FALSE, vWarehouseFk); - + CREATE OR REPLACE TEMPORARY TABLE tVisible SELECT itemFk, SUM(visible) totalVisible FROM vn.itemShelving ish @@ -4695,7 +4704,7 @@ BEGIN JOIN vn.sector sc ON sc.id = p.sectorFk WHERE sc.warehouseFk = vWarehouseFk GROUP BY itemFk; - + INSERT INTO inventoryDiscrepancyDetail( warehouseFk, itemFk, @@ -4767,15 +4776,15 @@ BEGIN DECLARE datSTART DATE; DECLARE datEND DATE; - + SELECT TIMESTAMPADD(WEEK, -1,MAX(fecha)) INTO datSTART FROM bs.m3; - + SET datEND = TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); - - DELETE FROM bs.m3 + + DELETE FROM bs.m3 WHERE fecha >= datSTART; - + INSERT INTO bs.m3 (fecha, provinceFk, warehouseFk, m3, year, month, week, day, dayName, euros) SELECT v.fecha, a.provinceFk, t.warehouseFk, sum(s.quantity * ic.cm3delivery) / 1000000 AS m3, tm.year, tm.month, tm.week, tm.day, dayname(v.fecha), sum(importe) @@ -4820,19 +4829,19 @@ BEGIN DECLARE vManaFromDays INT; DECLARE vManaToDays INT; - SELECT id INTO vManaId + SELECT id INTO vManaId FROM vn.component WHERE code = 'mana'; - - SELECT id INTO vManaAutoId + + SELECT id INTO vManaAutoId FROM vn.component WHERE code = 'autoMana'; - + SELECT id INTO vClaimManaId FROM vn.component WHERE code = 'manaClaim'; - - SELECT id INTO vManaBankId + + SELECT id INTO vManaBankId FROM vn.bank WHERE code = 'mana'; - - SELECT id INTO vManaGreugeTypeId + + SELECT id INTO vManaGreugeTypeId FROM vn.greugeType WHERE code = 'mana'; SELECT manaFromDays, manaToDays @@ -4840,17 +4849,17 @@ BEGIN FROM vn.salespersonConfig; SELECT MAX(dated) - INTO vFromDated + INTO vFromDated FROM vn.clientManaCache; DELETE FROM vn.clientManaCache WHERE dated = vFromDated; - + SELECT MAX(dated) - INTO vFromDated + INTO vFromDated FROM vn.clientManaCache; - + IF ISNULL(vFromDated) THEN SELECT manaDateFrom INTO vFromDated @@ -4860,20 +4869,20 @@ BEGIN WHILE vFromDated + INTERVAL vManaToDays DAY < util.VN_CURDATE() DO SELECT vFromDated + INTERVAL vManaToDays DAY, - vFromDated - INTERVAL vManaFromDays DAY - INTO + vFromDated - INTERVAL vManaFromDays DAY + INTO vToDated, vForDeleteDated; - + DELETE FROM vn.clientManaCache WHERE dated <= vForDeleteDated; INSERT INTO vn.clientManaCache(clientFk, mana, dated) - SELECT + SELECT Id_Cliente, SUM(mana), - vToDated - FROM + vToDated + FROM ( SELECT cs.Id_Cliente, Cantidad * Valor as mana FROM vn2008.Tickets t @@ -4881,19 +4890,19 @@ BEGIN JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento WHERE Id_Componente IN (vManaAutoId, vManaId, vClaimManaId) - AND t.Fecha > vFromDated + AND t.Fecha > vFromDated AND date(t.Fecha) <= vToDated UNION ALL SELECT r.Id_Cliente, - Entregado FROM vn2008.Recibos r WHERE Id_Banco = vManaBankId - AND Fechacobro > vFromDated + AND Fechacobro > vFromDated AND Fechacobro <= vToDated UNION ALL SELECT g.Id_Cliente, g.Importe FROM vn2008.Greuges g WHERE Greuges_type_id = vManaGreugeTypeId - AND Fecha > vFromDated + AND Fecha > vFromDated AND Fecha <= vToDated UNION ALL SELECT clientFk, mana @@ -4903,7 +4912,7 @@ BEGIN GROUP BY Id_Cliente HAVING Id_Cliente; - SET vFromDated = vToDated; + SET vFromDated = vToDated; END WHILE; END ;; DELIMITER ; @@ -4923,26 +4932,26 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `manaSpellers_actualize`() BEGIN -/** - * Recalcula el valor del campo con el modificador de precio +/** + * Recalcula el valor del campo con el modificador de precio * para el componente de maná automático. */ - UPDATE vn.workerMana wm + UPDATE vn.workerMana wm JOIN ( - SELECT c.lastSalesPersonFk, + SELECT c.lastSalesPersonFk, FLOOR(SUM(s.amount) / 12) amount FROM salesByclientSalesPerson s JOIN vn.client c ON c.id = s.clientFk WHERE s.dated BETWEEN util.VN_CURDATE() - INTERVAL 1 YEAR AND util.VN_CURDATE() GROUP BY c.lastSalesPersonFk - )avgPortfolioWeight ON avgPortfolioWeight.lastSalesPersonFk = wm.workerFk + )avgPortfolioWeight ON avgPortfolioWeight.lastSalesPersonFk = wm.workerFk JOIN vn.salespersonConfig spc - SET wm.pricesModifierRate = + SET wm.pricesModifierRate = IFNULL( GREATEST( - spc.manaMinRate, + spc.manaMinRate, LEAST( - spc.manaMaxRate, + spc.manaMaxRate, ROUND( - wm.amount / avgPortfolioWeight.amount, 3) ) ) @@ -4964,82 +4973,82 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nightTask_launchAll`() -BEGIN -/** - * Runs all nightly tasks. - */ - DECLARE vDone BOOL; - DECLARE vError VARCHAR(255); - DECLARE vErrorCode VARCHAR(255); - DECLARE vSchema VARCHAR(255); - DECLARE vProcedure VARCHAR(255); - DECLARE vLogMail VARCHAR(255); - DECLARE vNightTaskFk INT; - - DECLARE vQueue CURSOR FOR - SELECT id, `schema`, `procedure` - FROM nightTask - WHERE finished <= util.VN_CURDATE() - OR finished IS NULL - ORDER BY `order`; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SET max_sp_recursion_depth = 3; - - SELECT logMail INTO vLogMail - FROM nightTaskConfig LIMIT 1; - - OPEN vQueue; - l: LOOP - SET vDone = FALSE; - FETCH vQueue INTO vNightTaskFk, vSchema, vProcedure; - - IF vDone THEN - LEAVE l; - END IF; - - UPDATE nightTask - SET `started` = util.VN_NOW(), - `finished` = NULL, - `error` = NULL, - `errorCode` = NULL - WHERE id = vNightTaskFk; - - SET vError = NULL; - CALL nightTask_launchTask( - vSchema, - vProcedure, - vError, - vErrorCode - ); - - IF vError IS NOT NULL THEN - IF vLogMail IS NOT NULL THEN - CALL vn.mail_insert( - vLogMail, - NULL, - CONCAT('Nightly task failed (', vSchema, '.', vProcedure, ')'), - CONCAT( - '[', vErrorCode, '] ', vError, CHAR(13, 10), -- Line break - 'See ', SCHEMA(), '.nightTask table for more info.' - ) - ); - END IF; - - UPDATE nightTask - SET `error` = vError, - `errorCode` = vErrorCode - WHERE id = vNightTaskFk; - ELSE - UPDATE nightTask - SET finished = util.VN_NOW(), - lastFinished = util.VN_NOW() - WHERE id = vNightTaskFk; - END IF; - END LOOP; - CLOSE vQueue; +BEGIN +/** + * Runs all nightly tasks. + */ + DECLARE vDone BOOL; + DECLARE vError VARCHAR(255); + DECLARE vErrorCode VARCHAR(255); + DECLARE vSchema VARCHAR(255); + DECLARE vProcedure VARCHAR(255); + DECLARE vLogMail VARCHAR(255); + DECLARE vNightTaskFk INT; + + DECLARE vQueue CURSOR FOR + SELECT id, `schema`, `procedure` + FROM nightTask + WHERE finished <= util.VN_CURDATE() + OR finished IS NULL + ORDER BY `order`; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SET max_sp_recursion_depth = 3; + + SELECT logMail INTO vLogMail + FROM nightTaskConfig LIMIT 1; + + OPEN vQueue; + l: LOOP + SET vDone = FALSE; + FETCH vQueue INTO vNightTaskFk, vSchema, vProcedure; + + IF vDone THEN + LEAVE l; + END IF; + + UPDATE nightTask + SET `started` = util.VN_NOW(), + `finished` = NULL, + `error` = NULL, + `errorCode` = NULL + WHERE id = vNightTaskFk; + + SET vError = NULL; + CALL nightTask_launchTask( + vSchema, + vProcedure, + vError, + vErrorCode + ); + + IF vError IS NOT NULL THEN + IF vLogMail IS NOT NULL THEN + CALL vn.mail_insert( + vLogMail, + NULL, + CONCAT('Nightly task failed (', vSchema, '.', vProcedure, ')'), + CONCAT( + '[', vErrorCode, '] ', vError, CHAR(13, 10), -- Line break + 'See ', SCHEMA(), '.nightTask table for more info.' + ) + ); + END IF; + + UPDATE nightTask + SET `error` = vError, + `errorCode` = vErrorCode + WHERE id = vNightTaskFk; + ELSE + UPDATE nightTask + SET finished = util.VN_NOW(), + lastFinished = util.VN_NOW() + WHERE id = vNightTaskFk; + END IF; + END LOOP; + CLOSE vQueue; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5078,7 +5087,7 @@ BEGIN vError = MESSAGE_TEXT, vErrorCode = RETURNED_SQLSTATE; - CALL util.exec(CONCAT('CALL `', vSchema ,'`.`', vProcedure ,'`')); + CALL util.exec(CONCAT('CALL `', vSchema ,'`.`', vProcedure ,'`')); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5097,22 +5106,22 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `payMethodClientAdd`() BEGIN - INSERT IGNORE INTO `bs`.`payMethodClient` (dated, payMethodFk, clientFk) + INSERT IGNORE INTO `bs`.`payMethodClient` (dated, payMethodFk, clientFk) SELECT util.VN_CURDATE(), c.payMethodFk, c.id - FROM vn.client c + FROM vn.client c JOIN vn.payMethod p ON c.payMethodFk = p.id; - + TRUNCATE `bs`.`payMethodClientEvolution` ; - + INSERT INTO `bs`.`payMethodClientEvolution` (dated, payMethodName, amountClient, amount, equalizationTax) - SELECT p.dated, pm.name, COUNT(p.clientFk), SUM(sub.importe) , SUM(sub.recargo) + SELECT p.dated, pm.name, COUNT(p.clientFk), SUM(sub.importe) , SUM(sub.recargo) FROM bs.payMethodClient p - JOIN (SELECT SUM(v.importe) AS importe, SUM(v.recargo) as recargo, v.fecha, v.Id_cliente + JOIN (SELECT SUM(v.importe) AS importe, SUM(v.recargo) as recargo, v.fecha, v.Id_cliente FROM bs.ventas v WHERE v.fecha>= (SELECT MIN(dated) FROM bs. payMethodClient) GROUP BY v.Id_cliente, v.fecha) sub ON sub.fecha = p.dated AND sub.Id_cliente = p.ClientFk JOIN vn.payMethod pm ON p.payMethodFk = pm.id - GROUP BY dated,payMethodFk; + GROUP BY dated,payMethodFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5132,12 +5141,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGraphic`(IN vItemFk INT, IN vTypeFk INT, IN vCategoryFk INT, IN vFromDate DATE, IN vToDate DATE, IN vProducerFk INT) BEGIN - + DECLARE vFromDateLastYear DATE; DECLARE vToDateLastYear DATE; DECLARE vFromDateTwoYearsAgo DATE; DECLARE vToDateTwoYearsAgo DATE; - + SET vItemFk = IFNULL(vItemFk,0); SET vTypeFk = IFNULL(vTypeFk, 0); SET vCategoryFk = IFNULL(vCategoryFk,0); @@ -5152,19 +5161,19 @@ BEGIN SELECT s.quantity, CAST(v.importe AS DECIMAL(10,0)) importe, v.fecha FROM bs.ventas v - JOIN vn.sale s ON s.id = v.Id_Movimiento - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.sale s ON s.id = v.Id_Movimiento + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE vItemFk IN (i.id, 0) AND vTypeFk IN (i.typeFk, 0) AND vCategoryFk IN (it.categoryFk, 0) AND vProducerFk IN (i.producerFk, 0) AND (v.fecha BETWEEN vFromDate AND vToDate OR v.fecha BETWEEN vFromDateLastYear AND vToDateLastYear - OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo + OR v.fecha BETWEEN vFromDateTwoYearsAgo AND vToDateTwoYearsAgo ); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5183,21 +5192,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salePersonEvolutionAdd`(IN vDateStart DATETIME) BEGIN - DELETE FROM bs.salePersonEvolution + DELETE FROM bs.salePersonEvolution WHERE dated <= DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR); - - + + INSERT INTO bs.salePersonEvolution (dated, amount, equalizationTax, salesPersonFk) - SELECT fecha dated, - CAST(SUM(importe) AS DECIMAL(10,2) ) amount, + 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.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; + ORDER BY salesPersonFk,dated ASC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5219,7 +5228,7 @@ BEGIN /** * Agrupa las ventas por cliente/comercial/fecha en la tabla bs.salesByclientSalesPerson * El asociación cliente/comercial/fecha, se mantiene correcta en el tiempo - * + * * @param vDatedFrom el cálculo se realizará desde la fecha introducida hasta ayer */ @@ -5227,17 +5236,17 @@ BEGIN SET vDatedFrom = util.VN_CURDATE() - INTERVAL 1 MONTH; END IF; - UPDATE salesByclientSalesPerson + UPDATE salesByclientSalesPerson SET amount = 0, equalizationTax = 0, amountNewBorn = 0 WHERE dated BETWEEN vDatedFrom AND util.yesterday(); - - INSERT INTO salesByclientSalesPerson( - dated, - salesPersonFk, - clientFk, - amount, + + INSERT INTO salesByclientSalesPerson( + dated, + salesPersonFk, + clientFk, + amount, equalizationTax) SELECT s.dated, c.salesPersonFk, @@ -5246,7 +5255,7 @@ BEGIN SUM(s.surcharge) FROM sale s JOIN vn.client c on s.clientFk = c.id - WHERE s.dated BETWEEN vDatedFrom AND util.yesterday() + WHERE s.dated BETWEEN vDatedFrom AND util.yesterday() GROUP BY s.dated, c.salesPersonFk, s.clientFk ON DUPLICATE KEY UPDATE amount= VALUES(amount), equalizationTax= VALUES(equalizationTax); @@ -5419,8 +5428,8 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesByItemTypeDay_addLauncher`() -BEGIN - CALL bs.salesByItemTypeDay_add(util.VN_CURDATE() - INTERVAL 30 DAY, util.VN_CURDATE()); +BEGIN + CALL bs.salesByItemTypeDay_add(util.VN_CURDATE() - INTERVAL 30 DAY, util.VN_CURDATE()); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5440,35 +5449,35 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesPersonEvolution_add`() BEGIN /** - * Calcula los datos para los gráficos de evolución agrupado por salesPersonFk y día. + * Calcula los datos para los gráficos de evolución agrupado por salesPersonFk y día. * Recalcula automáticamente los 3 últimos meses para comprobar si hay algún cambio. */ DECLARE vDated DATE; DECLARE vCont INT DEFAULT 1; - SELECT MAX(dated) - INTERVAL 3 MONTH INTO vDated + SELECT MAX(dated) - INTERVAL 3 MONTH INTO vDated FROM salesPersonEvolution; - DELETE FROM salesPersonEvolution + DELETE FROM salesPersonEvolution WHERE dated >= vDated; IF ISNULL(vDated) THEN - SELECT MIN(dated) INTO vDated + SELECT MIN(dated) INTO vDated FROM salesByclientSalesPerson; - + INSERT INTO salesPersonEvolution( - salesPersonFk, - dated, - amount, - equalizationTax, + salesPersonFk, + dated, + amount, + equalizationTax, amountNewBorn ) - SELECT salesPersonFk, - dated, - amount, - equalizationTax, + SELECT salesPersonFk, + dated, + amount, + equalizationTax, amountNewBorn - FROM salesByclientSalesPerson + FROM salesByclientSalesPerson WHERE dated = vDated GROUP BY salesPersonFk; @@ -5476,21 +5485,21 @@ BEGIN END IF; WHILE vDated < util.VN_CURDATE() DO - + SET vCont = vCont + 1; REPLACE salesPersonEvolution(salesPersonFk, dated, amount) SELECT salesPersonFk, vDated, amount FROM(SELECT salesPersonFk, SUM(amount) amount FROM(SELECT salesPersonFk, amount - FROM salesPersonEvolution + FROM salesPersonEvolution WHERE dated = vDated - INTERVAL 1 DAY UNION ALL - SELECT salesPersonFk, amount - FROM salesByclientSalesPerson + SELECT salesPersonFk, amount + FROM salesByclientSalesPerson WHERE dated = vDated UNION ALL SELECT salesPersonFk, - amount - FROM salesByclientSalesPerson + FROM salesByclientSalesPerson WHERE dated = vDated - INTERVAL 1 YEAR )sub GROUP BY salesPersonFk @@ -5519,7 +5528,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vendedores_add_launcher`() BEGIN CALL bs.salesByclientSalesPerson_add(util.VN_CURDATE()- INTERVAL 45 DAY); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5543,7 +5552,7 @@ BEGIN /** * Añade las ventas que se realizaron entre * vStarted y vEnded -* +* * @param vStarted Fecha de inicio * @param vEnded Fecha de finalizacion * @@ -5551,7 +5560,7 @@ BEGIN DECLARE vStartingDate DATETIME; DECLARE vEndingDate DATETIME; - IF vStarted < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) + IF vStarted < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) OR vEnded < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) THEN CALL util.throw('fechaDemasiadoAntigua'); END IF; @@ -5560,8 +5569,8 @@ BEGIN SET vStartingDate = vStarted ; SET vEndingDate = util.dayEnd(vStartingDate); - DELETE - FROM sale + DELETE + FROM sale WHERE dated BETWEEN vStartingDate AND vEnded; WHILE vEndingDate <= vEnded DO @@ -5582,28 +5591,28 @@ BEGIN JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.itemCategory ic ON ic.id = it.categoryFk JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.address a ON a.id = t.addressFk + JOIN vn.address a ON a.id = t.addressFk JOIN vn.client cl ON cl.id = a.clientFk WHERE t.shipped BETWEEN vStartingDate AND vEndingDate AND s.quantity <> 0 AND s.discount <> 100 - AND ic.merchandise + AND ic.merchandise GROUP BY sc.saleFk HAVING IFNULL(importe,0) <> 0 OR IFNULL(recargo,0) <> 0; UPDATE sale s JOIN ( - SELECT s.id, + SELECT s.id, SUM(s.quantity * sc.value ) margen, s.quantity * s.price * (100 - s.discount ) / 100 pvp FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.saleComponent sc ON sc.saleFk = s.id - JOIN vn.component c ON c.id = sc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk WHERE t.shipped BETWEEN vStartingDate AND vEndingDate AND ct.isMargin = TRUE - GROUP BY s.id) sub ON sub.id = s.saleFk + GROUP BY s.id) sub ON sub.id = s.saleFk SET s.margin = sub.margen + s.amount + s.surcharge - sub.pvp; SET vStartingDate = TIMESTAMPADD(DAY,1, vStartingDate); @@ -5631,7 +5640,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_add_launcher`() BEGIN /** * Añade las ventas a la tabla bs.sale que se realizaron desde hace un mes hasta hoy - * + * */ DECLARE vCurDate DATE DEFAULT util.VN_CURDATE(); @@ -5655,7 +5664,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add`(IN vYear INT, IN vMonth INT) BEGIN - + /** * Reemplaza las ventas contables del último año. * Es el origen de datos para el balance de Entradas @@ -5667,8 +5676,8 @@ BEGIN DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; - DELETE FROM bs.ventas_contables - WHERE year = vYear + DELETE FROM bs.ventas_contables + WHERE year = vYear AND month = vMonth; DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; @@ -5679,7 +5688,7 @@ BEGIN FROM vn2008.Tickets t JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura WHERE year(f.Fecha) = vYear - AND month(f.Fecha) = vMonth; + AND month(f.Fecha) = vMonth; INSERT INTO bs.ventas_contables(year , month @@ -5689,7 +5698,7 @@ BEGIN , tipo_id , empresa_id , gasto) - + SELECT vYear , vMonth , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) @@ -5701,13 +5710,13 @@ BEGIN , tp.reino_id , a.tipo_id , t.empresa_id - , 7000000000 + , 7000000000 + IF(e.empresa_grupo = e2.empresa_grupo ,1 ,IF(e2.empresa_grupo,2,0) - ) * 1000000 + ) * 1000000 + tp.reino_id * 10000 as Gasto - FROM vn2008.Movimientos m + FROM vn2008.Movimientos m JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente @@ -5721,7 +5730,7 @@ BEGIN AND m.Descuento <> 100 AND a.tipo_id != TIPO_PATRIMONIAL GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto; - + INSERT INTO bs.ventas_contables(year , month , venta @@ -5740,17 +5749,17 @@ BEGIN ) as grupo , NULL , NULL - , t.companyFk + , t.companyFk , 7050000000 - FROM vn.ticketService ts + FROM vn.ticketService ts JOIN vn.ticket t ON ts.ticketFk = t.id - JOIN vn.address a on a.id = t.addressFk - JOIN vn.client cl on cl.id = a.clientFk + JOIN vn.address a on a.id = t.addressFk + JOIN vn.client cl on cl.id = a.clientFk JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id - JOIN vn.company c on c.id = t.companyFk + JOIN vn.company c on c.id = t.companyFk LEFT JOIN vn.company c2 on c2.clientFk = cl.id - GROUP BY grupo, t.companyFk ; - + GROUP BY grupo, t.companyFk ; + DROP TEMPORARY TABLE tmp.ticket_list; END ;; DELIMITER ; @@ -5770,13 +5779,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add_launcher`() BEGIN - + /** * Reemplaza las ventas contables del último año. * Es el origen de datos para el balance de Entradas * **/ - + CALL bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()))); END ;; @@ -5797,12 +5806,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT) BEGIN - + /** * Muestra las ventas (€) de cada cliente * dependiendo del año */ - + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; CREATE TEMPORARY TABLE tmp.ticket_list @@ -5811,8 +5820,8 @@ BEGIN FROM vn2008.Tickets t JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura WHERE year(f.Fecha) = vYear - AND month(f.Fecha) = vMonth; - + AND month(f.Fecha) = vMonth; + SELECT vYear Año, vMonth Mes, t.Id_Cliente, @@ -5822,7 +5831,7 @@ BEGIN IF(e2.empresa_grupo,2,0)) AS grupo, t.empresa_id empresa - FROM vn2008.Movimientos m + FROM vn2008.Movimientos m JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.Id_Consigna JOIN vn2008.Clientes c ON c.Id_Cliente = cs.Id_Cliente @@ -5836,9 +5845,9 @@ BEGIN AND m.Descuento <> 100 AND a.tipo_id != 188 GROUP BY t.Id_Cliente, grupo,t.empresa_id; - + DROP TEMPORARY TABLE tmp.ticket_list; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -5857,7 +5866,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `vivosMuertos`() BEGIN - + /** * Devuelve el número de clientes nuevos y muertos, * dependiendo de la fecha actual. @@ -5868,9 +5877,9 @@ BEGIN SET @datSTART = TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); SET @datEND = TIMESTAMPADD(DAY,-DAY(util.VN_CURDATE()),util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos; - + CREATE TEMPORARY TABLE tmp.VivosMuertos SELECT c.Id_Cliente, tm.yearMonth, f.Compra, 0 as Nuevo, 0 as Muerto FROM vn2008.Clientes c @@ -5886,10 +5895,10 @@ BEGIN WHERE Fecha BETWEEN @datSTART AND @datEND) f ON f.yearMonth = tm.yearMonth AND f.Id_Cliente = c.Id_Cliente; - + UPDATE tmp.VivosMuertos vm JOIN - (SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente + (SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente FROM vn2008.Facturas f JOIN vn2008.time tm ON tm.date = f.Fecha WHERE Fecha BETWEEN @datSTART AND @datEND @@ -5897,9 +5906,9 @@ BEGIN AND fm.Id_Cliente = vm.Id_Cliente SET Nuevo = 1; - + SELECT max(yearMonth) INTO @lastYearMonth FROM tmp.VivosMuertos; - + UPDATE tmp.VivosMuertos vm JOIN ( SELECT MAX(tm.yearMonth) firstMonth, f.Id_Cliente @@ -5940,23 +5949,23 @@ BEGIN INTO vWeek, vYear FROM vn.time WHERE dated = util.VN_CURDATE(); - + REPLACE bs.waste SELECT *, 100 * mermas / total as porcentaje FROM ( - SELECT buyer, - year, + SELECT buyer, + year, week, family, itemFk, itemTypeFk, - floor(sum(value)) as total, + floor(sum(value)) as total, floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas - FROM vn.saleValue + FROM vn.saleValue where year = vYear and week = vWeek - + GROUP BY family, itemFk - + ) sub ORDER BY mermas DESC; END ;; @@ -5988,56 +5997,56 @@ BEGIN DECLARE vDateEnded DATE; DECLARE vCursor CURSOR FOR - SELECT util.firstDayOfMonth(t.dated), LAST_DAY(t.dated) + SELECT util.firstDayOfMonth(t.dated), LAST_DAY(t.dated) FROM vn.time t WHERE t.dated BETWEEN vDateStarted AND vDateEnded - GROUP BY year,month; + GROUP BY year,month; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + IF DAY(util.VN_CURDATE()) = 21 THEN - + SELECT util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 12 MONTH)), LAST_DAY(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - INTO vDateStarted, + INTO vDateStarted, vDateEnded; - - DELETE FROM workerLabourDataByMonth + + DELETE FROM workerLabourDataByMonth WHERE CONCAT(`year`, '-',`month`, '-01') BETWEEN vDateStarted AND vDateEnded; OPEN vCursor; l: LOOP SET vDone = FALSE; - + FETCH vCursor INTO vFristDay, vLastDay; - + IF vDone THEN LEAVE l; END IF; - + -- Altas periodo - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.workCenter wc ON wc.id = b.workCenterFk JOIN vn.worker w ON w.id = b.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk LEFT JOIN (SELECT b.id, b.workerFk FROM vn.business b - LEFT JOIN (SELECT ended, workerFk FROM vn.business) wl + LEFT JOIN (SELECT ended, workerFk FROM vn.business) wl ON wl.ended = DATE_SUB(b.started, INTERVAL 1 DAY) AND wl.workerFk = b.workerFk - WHERE b.started BETWEEN vFristDay AND vLastDay AND wl.ended + WHERE b.started BETWEEN vFristDay AND vLastDay AND wl.ended )sub ON sub.workerFk = b.workerFk WHERE wc.payrollCenterFk IS NOT NULL AND b.workCenterFk IS NOT NULL AND b.started BETWEEN vFristDay AND vLastDay AND sub.workerFk IS NULL - AND NOT w.isFreelance; + AND NOT w.isFreelance; -- Bajas periodo - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.worker w ON w.id = b.workerFk JOIN vn.workCenter wc ON wc.id = b.workCenterFk @@ -6048,12 +6057,12 @@ BEGIN AND b.ended BETWEEN vFristDay AND vLastDay AND wl.started IS NULL AND NOT w.isFreelance; - + -- Anterior al periodo SET vLastDay = LAST_DAY(DATE_SUB(vFristDay, INTERVAL 1 DAY)); - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.worker w ON w.id = b.workerFk JOIN vn.workCenter wc ON wc.id = b.workCenterFk @@ -6063,8 +6072,8 @@ BEGIN AND NOT w.isFreelance; -- Discapacidad - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) + INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) + SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.business b JOIN vn.worker w ON w.id = b.workerFk JOIN vn.workCenter wc ON wc.id = b.workCenterFk @@ -6473,7 +6482,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addressFriendship_Update`() BEGIN - REPLACE cache.addressFriendship + REPLACE cache.addressFriendship SELECT addressFk1, addressFk2, count(*) friendship FROM ( @@ -6484,7 +6493,7 @@ BEGIN AND t2.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) AND t.addressFk != t2.addressFk) sub GROUP BY addressFk1, addressFk2; - + REPLACE cache.zoneAgencyFriendship SELECT r.agencyModeFk, t.zoneFk, count(*) friendship FROM vn.route r @@ -6658,12 +6667,12 @@ BEGIN FROM available a LEFT JOIN tCalc c ON c.id = a.calc_id WHERE c.id IS NULL; - + DELETE a FROM availableNoRaids a LEFT JOIN tCalc c ON c.id = a.calc_id WHERE c.id IS NULL; - + DROP TEMPORARY TABLE tCalc; END ;; DELIMITER ; @@ -6842,27 +6851,27 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_end`(IN `v_calc` INT) -BEGIN - DECLARE v_cache_name VARCHAR(255); - DECLARE v_params VARCHAR(255); - - -- Libera el bloqueo y actualiza la fecha de ultimo refresco. - - UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id - SET - cc.last_refresh = NOW(), - cc.expires = ADDTIME(NOW(), c.lifetime), - cc.connection_id = NULL - WHERE cc.id = v_calc; - - SELECT c.name, ca.params INTO v_cache_name, v_params - FROM cache c - JOIN cache_calc ca ON c.id = ca.cache_id - WHERE ca.id = v_calc; - - IF v_cache_name IS NOT NULL THEN - DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); - END IF; +BEGIN + DECLARE v_cache_name VARCHAR(255); + DECLARE v_params VARCHAR(255); + + -- Libera el bloqueo y actualiza la fecha de ultimo refresco. + + UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id + SET + cc.last_refresh = NOW(), + cc.expires = ADDTIME(NOW(), c.lifetime), + cc.connection_id = NULL + WHERE cc.id = v_calc; + + SELECT c.name, ca.params INTO v_cache_name, v_params + FROM cache c + JOIN cache_calc ca ON c.id = ca.cache_id + WHERE ca.id = v_calc; + + IF v_cache_name IS NOT NULL THEN + DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -6880,89 +6889,89 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_start`(OUT `v_calc` INT, INOUT `v_refresh` INT, IN `v_cache_name` VARCHAR(50), IN `v_params` VARCHAR(100)) -proc: BEGIN - DECLARE v_valid BOOL; - DECLARE v_lock_id VARCHAR(100); - DECLARE v_cache_id INT; - DECLARE v_expires DATETIME; - DECLARE v_clean_time DATETIME; - DECLARE vLastRefresh DATETIME; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - IF v_lock_id IS NOT NULL THEN - DO RELEASE_LOCK(v_lock_id); - END IF; - - RESIGNAL; - END; - - SET v_params = IFNULL(v_params, ''); - - -- Si el servidor se ha reiniciado invalida todos los calculos. - - SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; - - IF !v_valid - THEN - DELETE FROM cache_calc; - INSERT INTO cache_valid (valid) VALUES (TRUE); - END IF; - - -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. - - SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); - - IF !GET_LOCK(v_lock_id, 30) - THEN - SET v_calc = NULL; - SET v_refresh = FALSE; - LEAVE proc; - END IF; - - -- Comprueba si el calculo solicitado existe y esta actualizado. - - SELECT c.id, ca.id, ca.expires, ca.last_refresh - INTO v_cache_id, v_calc, v_expires, vLastRefresh - FROM cache c - LEFT JOIN cache_calc ca - ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' - WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; - - -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. - - IF !v_refresh AND NOW() < v_expires AND vLastRefresh >= CURDATE() - THEN - DO RELEASE_LOCK(v_lock_id); - SET v_refresh = FALSE; - LEAVE proc; - END IF; - - -- Si el calculo no existe le crea una entrada en la tabla de calculos. - - IF v_calc IS NULL - THEN - INSERT INTO cache_calc SET - cache_id = v_cache_id, - cacheName = v_cache_name, - params = v_params, - last_refresh = NULL, - expires = NULL, - connection_id = CONNECTION_ID(); - - SET v_calc = LAST_INSERT_ID(); - ELSE - UPDATE cache_calc - SET - last_refresh = NULL, - expires = NULL, - connection_id = CONNECTION_ID() - WHERE id = v_calc; - END IF; - - -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. - - SET v_refresh = TRUE; +proc: BEGIN + DECLARE v_valid BOOL; + DECLARE v_lock_id VARCHAR(100); + DECLARE v_cache_id INT; + DECLARE v_expires DATETIME; + DECLARE v_clean_time DATETIME; + DECLARE vLastRefresh DATETIME; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + IF v_lock_id IS NOT NULL THEN + DO RELEASE_LOCK(v_lock_id); + END IF; + + RESIGNAL; + END; + + SET v_params = IFNULL(v_params, ''); + + -- Si el servidor se ha reiniciado invalida todos los calculos. + + SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; + + IF !v_valid + THEN + DELETE FROM cache_calc; + INSERT INTO cache_valid (valid) VALUES (TRUE); + END IF; + + -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. + + SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); + + IF !GET_LOCK(v_lock_id, 30) + THEN + SET v_calc = NULL; + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Comprueba si el calculo solicitado existe y esta actualizado. + + SELECT c.id, ca.id, ca.expires, ca.last_refresh + INTO v_cache_id, v_calc, v_expires, vLastRefresh + FROM cache c + LEFT JOIN cache_calc ca + ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' + WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; + + -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. + + IF !v_refresh AND NOW() < v_expires AND vLastRefresh >= CURDATE() + THEN + DO RELEASE_LOCK(v_lock_id); + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Si el calculo no existe le crea una entrada en la tabla de calculos. + + IF v_calc IS NULL + THEN + INSERT INTO cache_calc SET + cache_id = v_cache_id, + cacheName = v_cache_name, + params = v_params, + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID(); + + SET v_calc = LAST_INSERT_ID(); + ELSE + UPDATE cache_calc + SET + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID() + WHERE id = v_calc; + END IF; + + -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. + + SET v_refresh = TRUE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -6992,7 +7001,7 @@ proc: BEGIN FROM cache c JOIN cache_calc ca ON c.id = ca.cache_id WHERE ca.id = v_calc; - + DELETE FROM cache_calc WHERE id = v_calc; IF v_cache_name IS NOT NULL THEN @@ -7088,7 +7097,7 @@ DECLARE rs CURSOR FOR DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; + SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; OPEN rs; @@ -7097,23 +7106,23 @@ DECLARE rs CURSOR FOR WHILE NOT done DO SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0); - + SET inicioProd = rsDeparture - rsHoras; - + IF inicioProd - resto < myTime THEN - + SET done = TRUE; - + ELSE - + SET departureLimit = rsDeparture; - + FETCH rs INTO rsDeparture, rsHoras , rsInicio; - + -- SELECT rsDeparture, rsHoras , rsInicio; - + END IF; - + END WHILE; SET departureLimit = IFNULL(departureLimit,24); @@ -7158,7 +7167,7 @@ proc: BEGIN DECLARE started DATE; DECLARE ended DATE; DECLARE vLastRefresh DATE; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (vCalc); @@ -7208,14 +7217,14 @@ proc: BEGIN DECLARE datEQ DATETIME; DECLARE timDIF TIME; DECLARE v_calc INT; - + CALL cache_calc_start (v_calc, v_refresh, 'prod_graphic', wh_id); - + IF !v_refresh THEN LEAVE proc; END IF; - + CALL vn2008.production_control_source(wh_id, 0); DELETE FROM prod_graphic_source; @@ -7233,8 +7242,8 @@ proc: BEGIN WHERE Fecha = util.VN_CURDATE() GROUP BY wh_id, graphCategory ; - - + + CALL cache_calc_end (v_calc); END ;; DELIMITER ; @@ -7255,11 +7264,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `stock_refresh`(v_refresh BOOL) proc: BEGIN /** - * Crea o actualiza la cache con el disponible hasta el día de + * Crea o actualiza la cache con el disponible hasta el dí­a de * ayer. Esta cache es usada como base para otros procedimientos - * como el cáculo del visible o del ATP. + * como el cálculo del visible o del ATP. * - * @param v_refresh %TRUE para forzar el recálculo de la cache + * @param v_refresh %TRUE para forzar el recálculo de la cache **/ DECLARE v_calc INT; DECLARE v_date_inv DATE; @@ -7279,23 +7288,23 @@ proc: BEGIN LEAVE proc; END IF; - SET v_date_inv = (SELECT inventoried FROM vn.config LIMIT 1); + SET v_date_inv = vn.getInventoryDate(); SET vCURDATE = util.VN_CURDATE(); - + DELETE FROM stock; - + INSERT INTO stock (item_id, warehouse_id, amount) SELECT item_id, warehouse_id, SUM(amount) amount FROM ( - SELECT itemFk AS item_id, warehouseFk AS warehouse_id, quantity AS amount + SELECT itemFk AS item_id, warehouseFk AS warehouse_id, quantity AS amount FROM vn.itemTicketOut WHERE shipped >= v_date_inv AND shipped < vCURDATE UNION ALL - SELECT itemFk ASitem_id, warehouseInFk AS warehouse_id, quantity AS amount + SELECT itemFk ASitem_id, warehouseInFk AS warehouse_id, quantity AS amount FROM vn.itemEntryIn WHERE landed >= v_date_inv AND landed < vCURDATE AND isVirtualStock is FALSE UNION ALL - SELECT itemFk AS item_id ,warehouseOutFk AS warehouse_id, quantity AS amount + SELECT itemFk AS item_id ,warehouseOutFk AS warehouse_id, quantity AS amount FROM vn.itemEntryOut WHERE shipped >= v_date_inv AND shipped < vCURDATE ) t @@ -7325,12 +7334,12 @@ BEGIN (INDEX (id)) ENGINE = MEMORY SELECT id FROM cache_calc; - + DELETE v FROM visible v LEFT JOIN tCalc c ON c.id = v.calc_id WHERE c.id IS NULL; - + DROP TEMPORARY TABLE tCalc; END ;; DELIMITER ; @@ -8254,9 +8263,9 @@ DELIMITER ;; BEGIN DECLARE nextID INT; - + SELECT 1 + MAX(id) INTO nextID FROM putOrder ; - + SET NEW.orderTradelineItemID = nextID; END */;; @@ -8278,36 +8287,36 @@ DELIMITER ;; BEFORE UPDATE ON `putOrder` FOR EACH ROW BEGIN - + DECLARE vError VARCHAR(100) DEFAULT 'Orderregel niet meer teruggevonden op basis van de orderps'; DECLARE vVmpIdError INT DEFAULT 7; DECLARE vVmpFk INT; DECLARE vSupplyResponseNumberOfUnits INT; - - SELECT sr.vmpID INTO vVmpFk - FROM edi.supplyResponse sr + + SELECT sr.vmpID INTO vVmpFk + FROM edi.supplyResponse sr WHERE sr.id = NEW.supplyResponseID; - - IF NEW.OrderStatus = 3 - AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) - AND NEW.error = vError - AND vVmpFk = vVmpIdError - - THEN - + + IF NEW.OrderStatus = 3 + AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) + AND NEW.error = vError + AND vVmpFk = vVmpIdError + + THEN + SET NEW.OrderStatus = 2; - + END IF; - + -- Error de disponible menor de lo solicitado IF NEW.error LIKE 'error2602%' THEN - + SELECT NumberOfUnits INTO vSupplyResponseNumberOfUnits - FROM edi.supplyResponse sr + FROM edi.supplyResponse sr WHERE sr.ID = NEW.supplyResponseID; - + SET NEW.error = CONCAT('(',vSupplyResponseNumberOfUnits,') ', NEW.error); - + END IF; END */;; DELIMITER ; @@ -8334,16 +8343,16 @@ BEGIN DECLARE vIsEktSender BOOLEAN; IF NEW.OrderStatus = vOrderStatusDenied AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN - + SELECT s.id INTO vSaleFk - FROM vn.sale s + FROM vn.sale s JOIN vn.ticket t ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() AND i.supplyResponseFk = NEW.supplyResponseID LIMIT 1; - + UPDATE vn.sale s JOIN vn.ticket t ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk @@ -8351,7 +8360,7 @@ BEGIN SET s.quantity = 0 WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() AND i.supplyResponseFk = NEW.supplyResponseID; - + INSERT INTO vn.mail (sender, `subject`, body) SELECT IF(u.id IS NOT NULL AND c.email IS NOT NULL, c.email, @@ -8363,26 +8372,26 @@ BEGIN IF (u.id IS NOT NULL AND c.email IS NOT NULL , CONCAT('https://shop.verdnatura.es/#!form=ecomerce%2Fticket&ticket=', t.id ), CONCAT('https://salix.verdnatura.es/#!/ticket/', t.id ,'/summary'))) - FROM vn.sale s + FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.`client` c ON c.id = t.clientFk LEFT JOIN account.user u ON u.id= c.salesPersonFk AND u.name IN ('ruben', 'ismaelalcolea') WHERE s.id = vSaleFk; - + END IF; IF NEW.OrderStatus = vOrderStatusOK AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN - SELECT v.isEktSender INTO vIsEktSender + SELECT v.isEktSender INTO vIsEktSender FROM edi.VMPSettings v - JOIN edi.supplyResponse sr ON sr.vmpID = v.VMPID + JOIN edi.supplyResponse sr ON sr.vmpID = v.VMPID WHERE sr.id = NEW.supplyResponseID; - + IF NOT vIsEktSender THEN CALL edi.ekt_add(NEW.id); - + END IF; IF NEW.barcode THEN @@ -8391,7 +8400,7 @@ BEGIN SELECT i.id, NEW.barcode FROM vn.item i WHERE i.supplyResponseFk = NEW.supplyResponseID; - + END IF; END IF; @@ -8589,8 +8598,8 @@ BEGIN UPDATE vn.buy b JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk JOIN vn.item i ON i.id = b.itemFk JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID SET b.quantity = NEW.NumberOfItemsPerCask * NEW.NumberOfUnits, @@ -8599,7 +8608,7 @@ BEGIN AND am.name = 'LOGIFLORA' AND e.isRaid AND tr.landed >= util.VN_CURDATE(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8741,7 +8750,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `imageName`(vPictureReference VARCHAR(255)) RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + SET vPictureReference = REPLACE(vPictureReference,'.',''); SET vPictureReference = REPLACE(vPictureReference,'/',''); @@ -8753,7 +8762,7 @@ BEGIN SET vPictureReference = REPLACE(vPictureReference,'?',''); SET vPictureReference = REPLACE(vPictureReference,'=',''); - + RETURN vPictureReference; END ;; @@ -8809,27 +8818,27 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deliveryInformation_Delete`() BEGIN - + DECLARE vID INT; DECLARE vGap INT DEFAULT 100; DECLARE vTope INT; - - SELECT MIN(ID), MAX(ID) + + SELECT MIN(ID), MAX(ID) INTO vID, vTope FROM edi.deliveryInformation; - WHILE vID <= vTope DO - + WHILE vID <= vTope DO + SET vID = vID + vGap; - - DELETE - FROM edi.deliveryInformation + + DELETE + FROM edi.deliveryInformation WHERE ID < vID AND EarliestDespatchDateTime IS NULL; - + END WHILE; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8848,15 +8857,15 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_add`(vPutOrderFk INT) BEGIN - + /** * Añade ekt para las ordenes de compra de proveedores que no envian el ekt por email - * + * * @param vPutOrderFk PutOrderId de donde coger los datos **/ - - INSERT INTO edi.ekt(entryYear, - deliveryNumber, + + INSERT INTO edi.ekt(entryYear, + deliveryNumber, fec, hor, item, @@ -8896,17 +8905,17 @@ BEGIN i.value10 s6, p.id putOrderFk, sr.Item_ArticleCode, - sr.vmpID + sr.vmpID FROM edi.putOrder p - JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID - JOIN edi.deliveryInformation di ON di.id = p.deliveryInformationID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN vn.origin o ON o.id = i.originFk + JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID + JOIN edi.deliveryInformation di ON di.id = p.deliveryInformationID + JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + JOIN vn.item i ON i.supplyResponseFk = sr.ID + JOIN vn.origin o ON o.id = i.originFk WHERE p.id = vPutOrderFk; - + CALL edi.ekt_load(LAST_INSERT_ID()); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8914,18 +8923,23 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ekt_load` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_load`(IN `vSelf` INT) proc:BEGIN - +/** + * Carga los datos esenciales para el sistema EKT. + * Inserta compras y ventas si es necesario. + * + * @param vSelf Id de ekt + */ DECLARE vRef INT; DECLARE vBuy INT; DECLARE vItem INT; @@ -8933,68 +8947,63 @@ proc:BEGIN DECLARE vPackage INT; DECLARE vPutOrderFk INT; DECLARE vIsLot BOOLEAN; - DECLARE vForceToPacking INT DEFAULT 2; - DECLARE vEntryFk INT; - DECLARE vHasToChangePackagingFk BOOLEAN; - DECLARE vIsFloramondoDirect BOOLEAN; - DECLARE vTicketFk INT; + DECLARE vForceToPacking INT DEFAULT 2; + DECLARE vEntryFk INT; + DECLARE vHasToChangePackagingFk BOOLEAN; + DECLARE vIsFloramondoDirect BOOLEAN; + DECLARE vTicketFk INT; DECLARE vHasItemGroup BOOL; DECLARE vDescription VARCHAR(255); DECLARE vSaleFk INT; -- Carga los datos necesarios del EKT - - SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), + SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), CONCAT(e.`ref`, ' ', e.item, ' ', e.sub, ' EktFk:', e.id) INTO vRef, vQty, vPackage, vPutOrderFk, vItem, vIsFloramondoDirect, vHasItemGroup, vDescription - FROM edi.ekt e - LEFT JOIN edi.item i ON e.ref = i.id - LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk - LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID + FROM ekt e + LEFT JOIN item i ON e.ref = i.id + LEFT JOIN putOrder po ON po.id = e.putOrderFk + LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID LEFT JOIN vn.ektEntryAssign eea ON eea.sub = e.sub - LEFT JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id + LEFT JOIN item_groupToOffer igto ON igto.group_code = i.group_id WHERE e.id = vSelf LIMIT 1; - + IF NOT vHasItemGroup THEN - CALL vn.mail_insert('logistica@verdnatura.es', 'nocontestar@verdnatura.es', 'Nuevo grupo en Floramondo', vDescription); - CALL vn.mail_insert('pako@verdnatura.es', 'nocontestar@verdnatura.es', CONCAT('Nuevo grupo en Floramondo: ', vDescription), vDescription); - LEAVE proc; - END IF; - + -- Asigna la entrada - SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; - + SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; + -- Inserta el cubo si no existe IF vPackage = 800 THEN - + SET vHasToChangePackagingFk = TRUE; - + IF vItem THEN - + SELECT vn.item_getPackage(vItem) INTO vPackage ; - + ELSE - - SET vPackage = 8000 + vQty; + + SET vPackage = 8000 + vQty; INSERT IGNORE INTO vn.packaging(id, width, `depth`) SELECT vPackage, vc.ccLength / vQty, vc.ccWidth FROM vn.volumeConfig vc; - + END IF; - + ELSE - + INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z) SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10) FROM bucket WHERE bucket_id = vPackage; - + IF ROW_COUNT() > 0 THEN INSERT INTO vn2008.mail SET @@ -9003,29 +9012,25 @@ proc:BEGIN `to` = 'ekt@verdnatura.es'; END IF; END IF; - + -- Si es una compra de Logiflora obtiene el articulo IF vPutOrderFk THEN - SELECT i.id INTO vItem - FROM edi.putOrder po + FROM putOrder po JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID WHERE po.id = vPutOrderFk LIMIT 1; - END IF; - INSERT IGNORE INTO item_track SET - item_id = vRef; - - IF IFNULL(vItem,0) = 0 THEN - + INSERT IGNORE INTO item_track + SET item_id = vRef; + + IF vItem IS NULL THEN -- Intenta obtener el artículo en base a los atributos holandeses - SELECT b.id, IFNULL(b.itemOriginalFk ,b.itemFk) INTO vBuy, vItem - FROM edi.ekt e - JOIN edi.item_track t ON t.item_id = e.ref - LEFT JOIN edi.ekt l ON l.ref = e.ref + FROM ekt e + JOIN item_track t ON t.item_id = e.ref + LEFT JOIN ekt l ON l.ref = e.ref LEFT JOIN vn.buy b ON b.ektFk = l.id LEFT JOIN vn.item i ON i.id = b.itemFk JOIN vn2008.config cfg @@ -9044,89 +9049,77 @@ proc:BEGIN AND IF(t.pro, l.pro = e.pro, TRUE) AND IF(t.package, l.package = e.package, TRUE) AND IF(t.item, l.item = e.item, TRUE) - AND i.isFloramondo = vIsFloramondoDirect - ORDER BY l.now DESC, b.id ASC + AND i.isFloramondo = vIsFloramondoDirect + ORDER BY l.now DESC, b.id ASC LIMIT 1; END IF; - + -- Si no encuentra el articulo lo crea en el caso de las compras directas en Floramondo - IF ISNULL(vItem) AND vIsFloramondoDirect THEN - - CALL edi.item_getNewByEkt(vSelf, vItem); - + IF vItem IS NULL AND vIsFloramondoDirect THEN + CALL item_getNewByEkt(vSelf, vItem); END IF; + + INSERT INTO vn.buy ( + entryFk, + ektFk, + buyingValue, + itemFk, + stickers, + packing, + `grouping`, + quantity, + groupingMode, + packagingFk, + weight) + SELECT vEntryFk, + vSelf, + (@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue, + IFNULL(vItem, cfg.generic_item) itemFk, + e.qty stickers, + @pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing, + IFNULL(b.`grouping`, e.pac), + @pac * e.qty, + vForceToPacking, + IF(vHasToChangePackagingFk OR b.packagingFk IS NULL, vPackage, b.packagingFk), + (IFNULL(i.weightByPiece, 0) * @pac) / 1000 + FROM ekt e + LEFT JOIN vn.buy b ON b.id = vBuy + LEFT JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.supplier s ON e.pro = s.id + JOIN vn2008.config cfg + WHERE e.id = vSelf + LIMIT 1; - INSERT INTO vn.buy - ( - entryFk - ,ektFk - ,buyingValue - ,itemFk - ,stickers - ,packing - ,`grouping` - ,quantity - ,groupingMode - ,packagingFk - ,weight - ) - SELECT - vEntryFk - ,vSelf - ,(@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue - ,IFNULL(vItem, cfg.generic_item) itemFk - ,e.qty stickers - ,@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing - ,IFNULL(b.`grouping`, e.pac) - ,@pac * e.qty - ,vForceToPacking - ,IF(vHasToChangePackagingFk OR ISNULL(b.packagingFk), vPackage, b.packagingFk) - ,(IFNULL(i.weightByPiece,0) * @pac)/1000 - FROM edi.ekt e - LEFT JOIN vn.buy b ON b.id = vBuy - LEFT JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.supplier s ON e.pro = s.id - JOIN vn2008.config cfg - WHERE e.id = vSelf - LIMIT 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; - - CREATE TEMPORARY TABLE tmp.buyRecalc + CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc SELECT buy.id - FROM vn.buy + FROM vn.buy WHERE ektFk = vSelf; CALL vn.buy_recalcPrices(); -- Si es una compra de Logiflora hay que informar la tabla vn.saleBuy IF vPutOrderFk THEN - REPLACE vn.saleBuy(saleFk, buyFk, workerFk) SELECT po.saleFk, b.id, account.myUser_getId() - FROM edi.putOrder po + FROM putOrder po JOIN vn.buy b ON b.ektFk = vSelf WHERE po.id = vPutOrderFk; - END IF; + -- Si es una compra directa en Floramondo hay que añadirlo al ticket - IF vIsFloramondoDirect THEN - SELECT t.id INTO vTicketFk - FROM vn.ticket t - JOIN vn.ektEntryAssign eea - ON eea.addressFk = t.addressFk + FROM vn.ticket t + JOIN vn.ektEntryAssign eea ON eea.addressFk = t.addressFk AND t.warehouseFk = eea.warehouseInFk - JOIN edi.ekt e - ON e.sub = eea.sub + JOIN ekt e ON e.sub = eea.sub AND e.id = vSelf - WHERE e.fec = t.shipped - LIMIT 1; - - IF ISNULL(vTicketFk) THEN - + WHERE e.fec = t.shipped + LIMIT 1; + + IF vTicketFk IS NULL THEN + SET @clientFk = NULL; INSERT INTO vn.ticket ( clientFk, shipped, @@ -9138,22 +9131,20 @@ proc:BEGIN landed, zoneFk, zonePrice, - zoneBonus - ) - SELECT - a.clientFk, - e.fec, - a.id, - a.agencyModeFk, - a.nickname, - eea.warehouseInFk, - c.id, - e.fec, - z.id, - z.price, - z.bonus - FROM edi.ekt e - JOIN vn.ektEntryAssign eea ON eea.sub = e.sub + zoneBonus) + SELECT @clientFk := a.clientFk, + e.fec, + a.id, + a.agencyModeFk, + a.nickname, + eea.warehouseInFk, + c.id, + e.fec, + z.id, + z.price, + z.bonus + FROM ekt e + JOIN vn.ektEntryAssign eea ON eea.sub = e.sub JOIN vn.address a ON a.id = eea.addressFk JOIN vn.company c ON c.code = 'VNL' JOIN vn.`zone` z ON z.code = 'FLORAMONDO' @@ -9162,39 +9153,36 @@ proc:BEGIN SET vTicketFk = LAST_INSERT_ID(); - INSERT INTO vn.ticketLog - SET originFk = vTicketFk, - userFk = account.myUser_getId(), - `action` = 'insert', - description = CONCAT('EktLoad ha creado el ticket:', ' ', vTicketFk); - + IF @clientFk IS NULL THEN + CALL util.throw(CONCAT("Ticket creation failed: ", vSelf)); + END IF; END IF; INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, price) SELECT vItem, vTicketFk, e.item, e.qty * e.pac, e.pri * ( 1 + fhc.floramondoMargin ) - FROM edi.ekt e - JOIN edi.floraHollandConfig fhc - WHERE e.id = vSelf; + FROM ekt e + JOIN floraHollandConfig fhc + WHERE e.id = vSelf; SELECT LAST_INSERT_ID() INTO vSaleFk; REPLACE vn.saleBuy(saleFk, buyFk, workerFk) SELECT vSaleFk, b.id, account.myUser_getId() FROM vn.buy b - WHERE b.ektFk = vSelf; + WHERE b.ektFk = vSelf; INSERT INTO vn.saleComponent(saleFk, componentFk, value) SELECT vSaleFk, c.id, e.pri - FROM edi.ekt e + FROM ekt e JOIN vn.component c ON c.code = 'purchaseValue' - WHERE e.id = vSelf; + WHERE e.id = vSelf; INSERT INTO vn.saleComponent(saleFk, componentFk, value) - SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin - FROM edi.ekt e - JOIN edi.floraHollandConfig fhc + SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin + FROM ekt e + JOIN floraHollandConfig fhc JOIN vn.component c ON c.code = 'margin' - WHERE e.id = vSelf; + WHERE e.id = vSelf; END IF; DROP TEMPORARY TABLE tmp.buyRecalc; END ;; @@ -9331,7 +9319,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_scan`(vBarcode VARCHAR(512)) BEGIN /** * Busca transaciones a partir de un código de barras, las marca como escaneadas - * y las devuelve. + * y las devuelve. * Ver https://wiki.verdnatura.es/index.php/Ekt#Algoritmos_de_lectura * * @param vBarcode Código de compra de una etiqueta de subasta @@ -9370,19 +9358,19 @@ BEGIN ENGINE = MEMORY SELECT id ektFk FROM ekt LIMIT 0; - CASE + CASE WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e WHERE e.cps = vBarcode OR e.batchNumber = vBarcode; WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN INSERT INTO tmp.ekt - SELECT e.id + SELECT e.id FROM edi.ektRecent e - WHERE e.pro = MID(vBarcode,2,6) + WHERE e.pro = MID(vBarcode,2,6) AND CAST(e.ptd AS SIGNED) = MID(vBarcode,8,5); ELSE @@ -9397,7 +9385,7 @@ BEGIN -- Clásico de subasta -- Trade standard -- Trade que construye como la subasta - -- Trade como el anterior pero sin trade code + -- Trade como el anterior pero sin trade code INSERT INTO tmp.ekt SELECT id FROM ekt @@ -9418,9 +9406,9 @@ BEGIN -- BatchNumber largo IF NOT vIsFound THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e - WHERE e.batchNumber + WHERE e.batchNumber = LEFT(vBarcode,vUsefulAuctionLeftSegmentLength) AND e.batchNumber > 0; @@ -9430,7 +9418,7 @@ BEGIN -- Order Number IF NOT vIsFound THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e WHERE e.putOrderFk = vBarcode; @@ -9440,7 +9428,7 @@ BEGIN -- deliveryNumber incrustado IF NOT vIsFound THEN INSERT INTO tmp.ekt - SELECT id + SELECT id FROM edi.ektRecent e WHERE e.deliveryNumber = MID(vBarcode, 4, 13) @@ -9451,7 +9439,7 @@ BEGIN END CASE; IF vIsFound THEN - UPDATE ekt e + UPDATE ekt e JOIN tmp.ekt t ON t.ektFk = e.id SET e.scanned = TRUE; END IF; @@ -9472,524 +9460,524 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `floramondo_offerRefresh`() -proc: BEGIN - DECLARE vLanded DATETIME; - DECLARE vDone INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 10000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - DECLARE vDayRange INT; - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); - SET @isTriggerDisabled = FALSE; - RESIGNAL; - END; - - IF 'test' = (SELECT environment FROM util.config) THEN - LEAVE proc; - END IF; - - IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN - LEAVE proc; - END IF; - - SELECT dayRange INTO vDayRange - FROM offerRefreshConfig; - - IF vDayRange IS NULL THEN - CALL util.throw("Variable vDayRange not declared"); - END IF; - - SET vStartingTime = util.VN_NOW(); - - TRUNCATE edi.offerList; - - INSERT INTO edi.offerList(supplier, total) - SELECT v.name, COUNT(DISTINCT sr.ID) total - FROM edi.supplyResponse sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - WHERE sr.NumberOfUnits > 0 - AND sr.EmbalageCode != 999 - GROUP BY sr.vmpID; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(*) total - FROM edi.supplyOffer sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.`filter` = sub.total; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - CREATE OR REPLACE TEMPORARY TABLE tmp - (INDEX (`Item_ArticleCode`)) - ENGINE = MEMORY - SELECT t.* - FROM ( - SELECT * - FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, - NumberOfUnits DESC LIMIT 10000000000000000000) t - GROUP BY t.srId; - - CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), - INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), - INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) - ENGINE = MEMORY - SELECT so.*, - ev1.type_description s1Value, - ev2.type_description s2Value, - ev3.type_description s3Value, - ev4.type_description s4Value, - ev5.type_description s5Value, - ev6.type_description s6Value, - eif1.feature ef1, - eif2.feature ef2, - eif3.feature ef3, - eif4.feature ef4, - eif5.feature ef5, - eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 - AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 - AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 - AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 - AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 - AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 - AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature - AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature - AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature - AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature - AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature - AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature - AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - DELETE o - FROM edi.offer o - LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' - LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' - LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' - LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' - LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' - LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' - JOIN vn.floramondoConfig fc ON TRUE - WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) - OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) - OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) - OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) - OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) - OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk - AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk - AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) - SET i.supplyResponseFk = o.srID - WHERE (sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() - OR di.ID IS NULL) - AND it.isInventory - AND t.id IS NULL - AND po.id IS NULL; - - CREATE OR REPLACE TEMPORARY TABLE itemToInsert - ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF vDone THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item(id, - `name`, - longName, - subName, - expenseFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT iti.itemFk, - iti.product_name, - iti.product_name, - iti.company_name, - iti.expenseFk, - iti.itemTypeFk, - iti.intrastatFk, - iti.originFk, - iti.`srId`, - iti.NumberOfItemsPerCask, - iti.EmbalageCode, - iti.Quality, - TRUE - FROM itemToInsert iti; - - -- Inserta la foto de los articulos nuevos (prioridad alta) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL - AND i.image IS NULL; - - INSERT INTO edi.`log`(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - -- Inserta los tags sólo en los articulos nuevos - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.product_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.Quality IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ii.company_name IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s1Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s2Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s3Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s4Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s5Value IS NULL; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT s6Value IS NULL; - - INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id - AND tp.`description` = 'Hoofdkleur 1' - LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value - LEFT JOIN vn.itemInk ik ON ik.longName = i.longName - WHERE ink.name IS NOT NULL - OR ik.color IS NOT NULL; - - CREATE OR REPLACE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - DROP TABLE tmp.item; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF( - fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), - util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - -- Elimina la oferta obsoleta - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() - OR i.supplyResponseFk IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); - - IF vLanded IS NOT NULL THEN - -- Actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask - OR b.buyingValue <> o.price); - - -- Inserta el resto - SET vLastInserted := util.VN_NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy ( - entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packageFk, - deliveryFk) - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask quantity, - o.Price, - o.NumberOfUnits etiquetas, - o.NumberOfItemsPerCask packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, - 2, -- Obliga al Packing - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN edi.warehouseFloramondo wf - JOIN vn.packaging p ON p.id - LIKE o.embalageCode - LEFT JOIN vn.buy b ON b.itemFk = i.id - AND b.entryFk = wf.entryFk - WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL - - INSERT INTO vn.itemCost( - itemFk, - warehouseFk, - cm3, - cm3delivery) - SELECT b.itemFk, - wf.warehouseFk, - @cm3 := vn.buy_getUnitVolume(b.id), - IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) - FROM warehouseFloramondo wf - JOIN vn.volumeConfig vc - JOIN vn.buy b ON b.entryFk = wf.entryFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk - AND ic.warehouseFk = wf.warehouseFk - WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) - ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); - - CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'VNH' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.vnh = sub.total; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'ALGEMESI' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.algemesi = sub.total; - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - SET @isTriggerDisabled = FALSE; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - -- Refresca las fotos de los items existentes que mostramos (prioridad baja) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) - SELECT i.id, sr.PictureReference, 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN edi.supplyOffer so ON so.srId = sr.ID - JOIN hedera.image i2 ON i2.name = i.image - AND i2.collectionFk = 'catalog' - WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) - AND sr.NumberOfUnits; - - INSERT INTO edi.`log` - SET tableName = 'floramondo_offerRefresh', - fieldName = 'Tiempo de proceso', - fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); - - DO RELEASE_LOCK('edi.floramondo_offerRefresh'); +proc: BEGIN + DECLARE vLanded DATETIME; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vFreeId INT; + DECLARE vSupplyResponseFk INT; + DECLARE vLastInserted DATETIME; + DECLARE vIsAuctionDay BOOLEAN; + DECLARE vMaxNewItems INT DEFAULT 10000; + DECLARE vStartingTime DATETIME; + DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; + DECLARE vDayRange INT; + + DECLARE cur1 CURSOR FOR + SELECT id + FROM edi.item_free; + + DECLARE cur2 CURSOR FOR + SELECT srId + FROM itemToInsert; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('edi.floramondo_offerRefresh'); + SET @isTriggerDisabled = FALSE; + RESIGNAL; + END; + + IF 'test' = (SELECT environment FROM util.config) THEN + LEAVE proc; + END IF; + + IF !GET_LOCK('edi.floramondo_offerRefresh', 0) THEN + LEAVE proc; + END IF; + + SELECT dayRange INTO vDayRange + FROM offerRefreshConfig; + + IF vDayRange IS NULL THEN + CALL util.throw("Variable vDayRange not declared"); + END IF; + + SET vStartingTime = util.VN_NOW(); + + TRUNCATE edi.offerList; + + INSERT INTO edi.offerList(supplier, total) + SELECT v.name, COUNT(DISTINCT sr.ID) total + FROM edi.supplyResponse sr + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + WHERE sr.NumberOfUnits > 0 + AND sr.EmbalageCode != 999 + GROUP BY sr.vmpID; + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(*) total + FROM edi.supplyOffer sr + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.`filter` = sub.total; + + -- Elimina de la lista de items libres aquellos que ya existen + DELETE itf.* + FROM edi.item_free itf + JOIN vn.item i ON i.id = itf.id; + + CREATE OR REPLACE TEMPORARY TABLE tmp + (INDEX (`Item_ArticleCode`)) + ENGINE = MEMORY + SELECT t.* + FROM ( + SELECT * + FROM edi.supplyOffer + ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, + NumberOfUnits DESC LIMIT 10000000000000000000) t + GROUP BY t.srId; + + CREATE OR REPLACE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), + INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), + INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) + ENGINE = MEMORY + SELECT so.*, + ev1.type_description s1Value, + ev2.type_description s2Value, + ev3.type_description s3Value, + ev4.type_description s4Value, + ev5.type_description s5Value, + ev6.type_description s6Value, + eif1.feature ef1, + eif2.feature ef2, + eif3.feature ef3, + eif4.feature ef4, + eif5.feature ef5, + eif6.feature ef6 + FROM tmp so + LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode + AND eif1.presentation_order = 1 + AND eif1.expiry_date IS NULL + LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode + AND eif2.presentation_order = 2 + AND eif2.expiry_date IS NULL + LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode + AND eif3.presentation_order = 3 + AND eif3.expiry_date IS NULL + LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode + AND eif4.presentation_order = 4 + AND eif4.expiry_date IS NULL + LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode + AND eif5.presentation_order = 5 + AND eif5.expiry_date IS NULL + LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode + AND eif6.presentation_order = 6 + AND eif6.expiry_date IS NULL + LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature + AND so.s1 = ev1.type_value + LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature + AND so.s2 = ev2.type_value + LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature + AND so.s3 = ev3.type_value + LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature + AND so.s4 = ev4.type_value + LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature + AND so.s5 = ev5.type_value + LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature + AND so.s6 = ev6.type_value + ORDER BY Price; + + DROP TEMPORARY TABLE tmp; + + DELETE o + FROM edi.offer o + LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' + LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' + LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' + LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' + LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' + LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' + JOIN vn.floramondoConfig fc ON TRUE + WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) + OR (t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) + OR (t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) + OR (t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) + OR (t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) + OR (t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); + + START TRANSACTION; + + -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos + UPDATE IGNORE edi.offer o + JOIN vn.item i + ON i.name = o.product_name + AND i.subname <=> o.company_name + AND i.value5 <=> o.s1Value + AND i.value6 <=> o.s2Value + AND i.value7 <=> o.s3Value + AND i.value8 <=> o.s4Value + AND i.value9 <=> o.s5Value + AND i.value10 <=> o.s6Value + AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask + AND i.EmbalageCode <=> o.EmbalageCode + AND i.quality <=> o.Quality + JOIN vn.itemType it ON it.id = i.typeFk + LEFT JOIN vn.sale s ON s.itemFk = i.id + LEFT JOIN vn.ticket t ON t.id = s.ticketFk + AND t.shipped > (util.VN_CURDATE() - INTERVAL 1 WEEK) + LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk + AND po.OrderTradeLineDateTime > (util.VN_CURDATE() - INTERVAL 1 WEEK) + SET i.supplyResponseFk = o.srID + WHERE (sr.ID IS NULL + OR sr.NumberOfUnits = 0 + OR di.LatestOrderDateTime < util.VN_NOW() + OR di.ID IS NULL) + AND it.isInventory + AND t.id IS NULL + AND po.id IS NULL; + + CREATE OR REPLACE TEMPORARY TABLE itemToInsert + ENGINE = MEMORY + SELECT o.*, CAST(NULL AS DECIMAL(6,0)) itemFk + FROM edi.offer o + LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId + WHERE i.id IS NULL + LIMIT vMaxNewItems; + + -- Reciclado de nº de item + OPEN cur1; + OPEN cur2; + + read_loop: LOOP + + FETCH cur2 INTO vSupplyResponseFk; + FETCH cur1 INTO vFreeId; + + IF vDone THEN + LEAVE read_loop; + END IF; + + UPDATE itemToInsert + SET itemFk = vFreeId + WHERE srId = vSupplyResponseFk; + + END LOOP; + + CLOSE cur1; + CLOSE cur2; + + -- Insertamos todos los items en Articles de la oferta + INSERT INTO vn.item(id, + `name`, + longName, + subName, + expenseFk, + typeFk, + intrastatFk, + originFk, + supplyResponseFk, + numberOfItemsPerCask, + embalageCode, + quality, + isFloramondo) + SELECT iti.itemFk, + iti.product_name, + iti.product_name, + iti.company_name, + iti.expenseFk, + iti.itemTypeFk, + iti.intrastatFk, + iti.originFk, + iti.`srId`, + iti.NumberOfItemsPerCask, + iti.EmbalageCode, + iti.Quality, + TRUE + FROM itemToInsert iti; + + -- Inserta la foto de los articulos nuevos (prioridad alta) + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) + SELECT i.id, PictureReference + FROM itemToInsert ii + JOIN vn.item i ON i.supplyResponseFk = ii.srId + WHERE PictureReference IS NOT NULL + AND i.image IS NULL; + + INSERT INTO edi.`log`(tableName, fieldName,fieldValue) + SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) + FROM vn.itemImageQueue + WHERE attempts = 0; + + -- Inserta si se añadiesen tags nuevos + INSERT IGNORE INTO vn.tag (name, ediTypeFk) + SELECT description, type_id FROM edi.type; + + -- Desabilita el trigger para recalcular los tags al final + SET @isTriggerDisabled = TRUE; + + -- Inserta los tags sólo en los articulos nuevos + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.product_name, 1 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Producto' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.product_name IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.Quality, 3 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Calidad' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.Quality IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , ii.company_name, 4 + FROM itemToInsert ii + JOIN vn.tag t ON t.`name` = 'Productor' + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT ii.company_name IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s1Value, 5 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef1 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s1Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s2Value, 6 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef2 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s2Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s3Value, 7 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef3 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s3Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s4Value, 8 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef4 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s4Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s5Value, 9 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef5 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s5Value IS NULL; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id , s6Value, 10 + FROM itemToInsert ii + JOIN vn.tag t ON t.ediTypeFk = ii.ef6 + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + WHERE NOT s6Value IS NULL; + + INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 + FROM itemToInsert ii + JOIN vn.item i ON i.supplyResponseFk = ii.`srId` + JOIN vn.tag t ON t.`name` = 'Color' + LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode + LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id + AND tp.`description` = 'Hoofdkleur 1' + LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value + LEFT JOIN vn.itemInk ik ON ik.longName = i.longName + WHERE ink.name IS NOT NULL + OR ik.color IS NOT NULL; + + CREATE OR REPLACE TABLE tmp.item + (PRIMARY KEY (id)) + SELECT i.id FROM vn.item i + JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; + + CALL vn.item_refreshTags(); + + DROP TABLE tmp.item; + + SELECT MIN(LatestDeliveryDateTime) INTO vLanded + FROM edi.supplyResponse sr + JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID + JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID + JOIN vn.floramondoConfig fc + WHERE mp.isLatestOrderDateTimeRelevant + AND di.LatestOrderDateTime > IF( + fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), + util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY); + + UPDATE vn.floramondoConfig + SET nextLanded = vLanded + WHERE vLanded IS NOT NULL; + + -- Elimina la oferta obsoleta + UPDATE vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID + LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk + SET b.quantity = 0 + WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() + OR i.supplyResponseFk IS NULL + OR sr.NumberOfUnits = 0) + AND am.name = 'LOGIFLORA' + AND e.isRaid; + + -- Localiza las entradas de cada almacen + UPDATE edi.warehouseFloramondo + SET entryFk = vn.entry_getForLogiflora(vLanded + INTERVAL travellingDays DAY, warehouseFk); + + IF vLanded IS NOT NULL THEN + -- Actualiza la oferta existente + UPDATE vn.buy b + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.offer o ON i.supplyResponseFk = o.`srId` + SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, + b.buyingValue = o.price + WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask + OR b.buyingValue <> o.price); + + -- Inserta el resto + SET vLastInserted := util.VN_NOW(); + + -- Inserta la oferta + INSERT INTO vn.buy ( + entryFk, + itemFk, + quantity, + buyingValue, + stickers, + packing, + `grouping`, + groupingMode, + packagingFk, + deliveryFk) + SELECT wf.entryFk, + i.id, + o.NumberOfUnits * o.NumberOfItemsPerCask quantity, + o.Price, + o.NumberOfUnits etiquetas, + o.NumberOfItemsPerCask packing, + GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask `grouping`, + 2, -- Obliga al Packing + o.embalageCode, + o.diId + FROM edi.offer o + JOIN vn.item i ON i.supplyResponseFk = o.srId + JOIN edi.warehouseFloramondo wf + JOIN vn.packaging p ON p.id + LIKE o.embalageCode + LEFT JOIN vn.buy b ON b.itemFk = i.id + AND b.entryFk = wf.entryFk + WHERE b.id IS NULL; -- Quitar esta linea y mirar de crear los packages a tiempo REAL + + INSERT INTO vn.itemCost( + itemFk, + warehouseFk, + cm3, + cm3delivery) + SELECT b.itemFk, + wf.warehouseFk, + @cm3 := vn.buy_getUnitVolume(b.id), + IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3) + FROM warehouseFloramondo wf + JOIN vn.volumeConfig vc + JOIN vn.buy b ON b.entryFk = wf.entryFk + JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.itemCost ic ON ic.itemFk = b.itemFk + AND ic.warehouseFk = wf.warehouseFk + WHERE (ic.cm3 IS NULL OR ic.cm3 = 0) + ON DUPLICATE KEY UPDATE cm3 = @cm3, cm3delivery = IFNULL((vc.standardFlowerBox * 1000) / i.packingOut, @cm3); + + CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc + SELECT b.id + FROM vn.buy b + JOIN warehouseFloramondo wf ON wf.entryFk = b.entryFk + WHERE b.created >= vLastInserted; + + CALL vn.buy_recalcPrices(); + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.warehouse w ON w.id = wf.warehouseFk + WHERE w.name = 'VNH' + AND b.quantity > 0 + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.vnh = sub.total; + + UPDATE edi.offerList o + JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk + JOIN vn.warehouse w ON w.id = wf.warehouseFk + WHERE w.name = 'ALGEMESI' + AND b.quantity > 0 + GROUP BY sr.vmpID) sub ON o.supplier = sub.name + SET o.algemesi = sub.total; + END IF; + + DROP TEMPORARY TABLE + edi.offer, + itemToInsert; + + SET @isTriggerDisabled = FALSE; + + COMMIT; + + -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias + UPDATE vn.item i + SET typeFk = 121 + WHERE i.longName LIKE 'Rosa Garden %' + AND typeFk = 17; + + UPDATE vn.item i + SET typeFk = 156 + WHERE i.longName LIKE 'Rosa ec %' + AND typeFk = 17; + + -- Refresca las fotos de los items existentes que mostramos (prioridad baja) + INSERT IGNORE INTO vn.itemImageQueue(itemFk, url, priority) + SELECT i.id, sr.PictureReference, 100 + FROM edi.supplyResponse sr + JOIN vn.item i ON i.supplyResponseFk = sr.ID + JOIN edi.supplyOffer so ON so.srId = sr.ID + JOIN hedera.image i2 ON i2.name = i.image + AND i2.collectionFk = 'catalog' + WHERE i2.updated <= (UNIX_TIMESTAMP(util.VN_NOW()) - vDayRange) + AND sr.NumberOfUnits; + + INSERT INTO edi.`log` + SET tableName = 'floramondo_offerRefresh', + fieldName = 'Tiempo de proceso', + fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); + + DO RELEASE_LOCK('edi.floramondo_offerRefresh'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -10056,7 +10044,7 @@ BEGIN /** * Devuelve un número nuevo de item a partir de un registro de la tabla edi.ekt - * + * * @param vEktFk Identificador de la tabla edi.ekt */ @@ -10065,17 +10053,17 @@ BEGIN SELECT MIN(id) id INTO vItemFk FROM edi.item_free; - DELETE FROM edi.item_free + DELETE FROM edi.item_free WHERE id = vItemFk; - + COMMIT; - + IF ISNULL(vItemFk) THEN SELECT MAX(i.id) + 1 INTO vItemFk FROM vn.item i; END IF; - + INSERT INTO vn.item(id, `name`, longName, @@ -10101,118 +10089,118 @@ BEGIN least(IF((e.package = 800),((e.package * 10) + e.pac), e.package), IFNULL(idt.bucket_id, '999')) packageFk, e.cat, TRUE - FROM edi.ekt e - JOIN edi.item i ON i.id = e.`ref` - JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id - LEFT JOIN edi.item_defaultType idt ON idt.item_id = e.`ref` + FROM edi.ekt e + JOIN edi.item i ON i.id = e.`ref` + JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id + LEFT JOIN edi.item_defaultType idt ON idt.item_id = e.`ref` WHERE e.id = vEktFk; SET @isTriggerDisabled = TRUE; - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.item , 1 - FROM edi.ekt e + SELECT vItemFk, t.id , e.item , 1 + FROM edi.ekt e JOIN vn.tag t ON t.`name` = 'Producto' WHERE e.id = vEktFk AND NOT ISNULL(e.item); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.cat , 3 - FROM edi.ekt e + SELECT vItemFk, t.id , e.cat , 3 + FROM edi.ekt e JOIN vn.tag t ON t.`name` = 'Calidad' WHERE e.id = vEktFk AND NOT ISNULL(e.cat); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , s.company_name , 4 - FROM edi.ekt e + SELECT vItemFk, t.id , s.company_name , 4 + FROM edi.ekt e JOIN edi.supplier s ON s.supplier_id = e.pro JOIN vn.tag t ON t.`name` = 'Productor' WHERE e.id = vEktFk AND NOT ISNULL(s.company_name); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s1, 5 + SELECT vItemFk, t.id , e.s1, 5 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` - AND eif.presentation_order = 1 + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 1 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s1 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s1); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s2, 6 + SELECT vItemFk, t.id , e.s2, 6 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` - AND eif.presentation_order = 2 + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 2 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s2 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s2); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s3, 7 + SELECT vItemFk, t.id , e.s3, 7 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` - AND eif.presentation_order = 3 + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + AND eif.presentation_order = 3 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s3 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s3); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s4, 8 + SELECT vItemFk, t.id , e.s4, 8 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` AND eif.presentation_order = 4 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s4 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s4); - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s5, 9 + SELECT vItemFk, t.id , e.s5, 9 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` AND eif.presentation_order = 5 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s5 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s5); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id , e.s6, 10 + SELECT vItemFk, t.id , e.s6, 10 FROM edi.ekt e - LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` + LEFT JOIN edi.item_feature eif ON eif.item_id = e.`ref` AND eif.presentation_order = 6 AND eif.expiry_date IS NULL - LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature + LEFT JOIN edi.`value` ev ON ev.type_id = eif.feature AND e.s6 = ev.type_value JOIN vn.tag t ON t.ediTypeFk = eif.feature WHERE e.id = vEktFk AND NOT ISNULL(e.s6); INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemFk, t.id, IFNULL(ink.name, ik.color), 11 - FROM edi.ekt e + SELECT vItemFk, t.id, IFNULL(ink.name, ik.color), 11 + FROM edi.ekt e JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = e.`ref` + LEFT JOIN edi.feature f ON f.item_id = e.`ref` LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id AND tp.`description` = 'Hoofdkleur 1' LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value LEFT JOIN vn.itemInk ik ON ik.longName = e.item WHERE e.id = vEktFk - AND ( ink.name IS NOT NULL + AND ( ink.name IS NOT NULL OR ik.color IS NOT NULL) LIMIT 1; @@ -10279,7 +10267,7 @@ BEGIN sender = vSender, senderFk = vSenderId, messageId = vMessageId; - + IF vIsDuplicated THEN SELECT id INTO vSelf FROM mail @@ -11101,7 +11089,7 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterInsert` AFTER INSERT ON `order` FOR EACH ROW -BEGIN +BEGIN IF NEW.address_id = 2850 THEN -- Fallo que se insertan no se sabe como tickets en este cliente CALL vn.mail_insert( @@ -11110,7 +11098,7 @@ BEGIN 'Creada order al address 2850', CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) ); - + END IF; END */;; DELIMITER ; @@ -11127,27 +11115,27 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` - AFTER UPDATE ON `order` - FOR EACH ROW -BEGIN - CALL stock.log_add('order', NEW.id, OLD.id); - - IF !(OLD.address_id <=> NEW.address_id) - OR !(OLD.company_id <=> NEW.company_id) - OR !(OLD.customer_id <=> NEW.customer_id) THEN - CALL order_requestRecalc(NEW.id); - END IF; - - IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN - -- Fallo que se actualiza no se sabe como tickets en este cliente - CALL vn.mail_insert( - 'jgallego@verdnatura.es', - 'noreply@verdnatura.es', - 'Actualizada order al address 2850', - CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) - ); - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` + AFTER UPDATE ON `order` + FOR EACH ROW +BEGIN + CALL stock.log_add('order', NEW.id, OLD.id); + + IF !(OLD.address_id <=> NEW.address_id) + OR !(OLD.company_id <=> NEW.company_id) + OR !(OLD.customer_id <=> NEW.customer_id) THEN + CALL order_requestRecalc(NEW.id); + END IF; + + IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN + -- Fallo que se actualiza no se sabe como tickets en este cliente + CALL vn.mail_insert( + 'jgallego@verdnatura.es', + 'noreply@verdnatura.es', + 'Actualizada order al address 2850', + CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) + ); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -11262,12 +11250,12 @@ DELIMITER ;; BEGIN DECLARE vIsFirst BOOL; - SELECT (first_row_stamp IS NULL) INTO vIsFirst - FROM `order` + SELECT (first_row_stamp IS NULL) INTO vIsFirst + FROM `order` WHERE id = NEW.orderFk; IF vIsFirst THEN - UPDATE `order` SET first_row_stamp = util.VN_NOW() + UPDATE `order` SET first_row_stamp = util.VN_NOW() WHERE id = NEW.orderFk; END IF; END */;; @@ -11857,7 +11845,7 @@ BEGIN IF vCount = 0 THEN RETURN FALSE; - END IF; + END IF; SELECT COUNT(*) > 0 INTO vHasRole @@ -11938,14 +11926,14 @@ BEGIN * @return tmp.ticketComponent * @return tmp.ticketLot * @return tmp.zoneGetShipped - */ + */ DECLARE vAgencyMode INT; - + SELECT a.agencyModeFk INTO vAgencyMode FROM myClient c JOIN vn.address a ON a.clientFk = c.id - WHERE a.id = vAddress; + WHERE a.id = vAddress; CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); @@ -11958,7 +11946,7 @@ BEGIN JOIN tmp.availableCalc a ON a.calcFk = c.calc_id WHERE c.available > 0 GROUP BY c.item_id; - + CALL vn.catalog_calculate(vDelivery, vAddress, vAgencyMode); DROP TEMPORARY TABLE tmp.item; @@ -12060,7 +12048,7 @@ BEGIN */ DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item - ENGINE = MEMORY + ENGINE = MEMORY SELECT vSelf itemFk; CALL vn.catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); @@ -12085,14 +12073,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getVisible` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible`( vWarehouse TINYINT, @@ -12100,7 +12088,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible`( vType INT, vPrefix VARCHAR(255)) BEGIN - + /** * Gets visible items of the specified type at specified date. * @@ -12109,22 +12097,22 @@ BEGIN * @param vType The type id * @param vPrefix The article prefix to filter or %NULL for all * @return tmp.itemVisible Visible items - */ + */ DECLARE vPrefixLen SMALLINT; DECLARE vFilter VARCHAR(255) DEFAULT NULL; - DECLARE vDateInv DATE DEFAULT vn2008.date_inv(); + DECLARE vDateInv DATE DEFAULT vn.getInventoryDate(); DECLARE EXIT HANDLER FOR 1114 BEGIN GET DIAGNOSTICS CONDITION 1 @message = MESSAGE_TEXT; CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, + 'cau@verdnatura.es', + NULL, CONCAT('hedera.item_getVisible error: ', @message), CONCAT( - 'warehouse: ', IFNULL(vWarehouse, ''), - ', Fecha:', IFNULL(vDate, ''), - ', tipo: ', IFNULL(vType,''), + 'warehouse: ', IFNULL(vWarehouse, ''), + ', Fecha:', IFNULL(vDate, ''), + ', tipo: ', IFNULL(vType,''), ', prefijo: ', IFNULL(vPrefix,''))); RESIGNAL; END; @@ -12168,7 +12156,7 @@ BEGIN SELECT m.itemFk, -m.quantity FROM vn.sale m JOIN vn.ticket t ON t.id = m.ticketFk - JOIN vn.ticketState s ON s.ticket = t.id + JOIN vn.ticketState s ON s.ticketFk = t.id WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() AND t.warehouseFk = vWarehouse AND s.alertLevel = 3 @@ -12203,7 +12191,7 @@ BEGIN IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, CEIL(s.quantity / t.packing) etiquetas FROM vn.item i - JOIN `filter` f ON f.itemFk = i.id + JOIN `filter` f ON f.itemFk = i.id JOIN currentStock s ON s.itemFk = i.id LEFT JOIN tmp t ON t.itemFk = i.id LEFT JOIN vn.packaging p ON p.id = t.packagingFk @@ -12680,15 +12668,15 @@ BEGIN START TRANSACTION; - SELECT a.agencyModeFk, a.id + SELECT a.agencyModeFk, a.id INTO vAgencyMode, vAddressFk - FROM vn.address a + FROM vn.address a WHERE a.id = vAddressFk; - + SELECT deliveryMethodFk INTO vDeliveryMethodId FROM vn.agencyMode am WHERE am.id = vAgencyMode; - + IF vCompany IS NULL THEN SELECT defaultCompanyFk INTO vCompany @@ -12706,7 +12694,7 @@ BEGIN company_id = vCompany; SET vSelf = LAST_INSERT_ID(); - + CALL order_checkConfig(vSelf); COMMIT; @@ -12752,15 +12740,15 @@ BEGIN START TRANSACTION; - SELECT a.agencyModeFk, a.id + SELECT a.agencyModeFk, a.id INTO vAgencyMode, vAddress FROM myClient c JOIN vn.address a ON a.id = c.defaultAddressFk; - + SELECT deliveryMethodFk INTO vDeliveryMethodId FROM vn.agencyMode am WHERE am.id = vAgencyMode; - + IF vCompany IS NULL THEN SELECT defaultCompanyFk INTO vCompany @@ -12778,7 +12766,7 @@ BEGIN company_id = vCompany; SET vSelf = LAST_INSERT_ID(); - + CALL order_checkConfig(vSelf); COMMIT; @@ -12961,7 +12949,7 @@ BEGIN SELECT t.id ticketFk FROM myTicket t WHERE shipped BETWEEN TIMESTAMP(vFrom) AND TIMESTAMP(vTo, '23:59:59'); - + CALL vn.ticketGetTotal(NULL); SELECT v.id, IFNULL(v.landed, v.shipped) landed, @@ -13122,7 +13110,7 @@ BEGIN ROLLBACK; RESIGNAL; END; - + CALL order_calcCatalogFromItem(vSelf, vItem); START TRANSACTION; @@ -13142,7 +13130,7 @@ BEGIN END IF; SELECT IFNULL(minQuantity, 0) INTO vMinQuantity - FROM vn.item + FROM vn.item WHERE id = vItem; IF vAmount < LEAST(vMinQuantity, vAvailable) THEN @@ -13235,10 +13223,10 @@ BEGIN CREATE TEMPORARY TABLE tmp.item (PRIMARY KEY (itemFk)) ENGINE = MEMORY - SELECT itemFk FROM orderRow + SELECT itemFk FROM orderRow WHERE orderFk = vSelf GROUP BY itemFk; - + CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); DROP TEMPORARY TABLE tmp.item; @@ -13613,7 +13601,7 @@ BEGIN END; -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, + SELECT o.date_send, o.address_id, o.note, a.clientFk, o.company_id, o.agency_id, c.isTaxDataChecked INTO vDelivery, vAddress, vNotes, vClientId, vCompanyId, vAgencyModeId, vIsTaxDataChecked @@ -13673,7 +13661,7 @@ BEGIN SELECT t.id INTO vTicket FROM vn.ticket t LEFT JOIN tPrevia tp ON tp.ticketFk = t.id - LEFT JOIN vn.ticketState tls on tls.ticket = t.id + LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id JOIN hedera.`order` o ON o.address_id = t.addressFk AND vWarehouse = t.warehouseFk @@ -13682,11 +13670,10 @@ BEGIN WHERE o.id = vSelf AND t.refFk IS NULL AND tp.ticketFk IS NULL - AND IFNULL(tls.alertLevel,0) = 0 + AND IFNULL(tls.alertLevel,0) = 0 LIMIT 1; -- Crea el ticket en el caso de no existir uno adecuado - IF vTicket IS NULL THEN @@ -13708,7 +13695,7 @@ BEGIN ELSE INSERT INTO vn.ticketTracking SET ticketFk = vTicket, - workerFk = vUserId, + userFk = vUserId, stateFk = TICKET_FREE; END IF; @@ -13722,7 +13709,7 @@ BEGIN THEN INSERT INTO vn.ticketObservation SET ticketFk = vTicket, - observationTypeFk = 4 /* salesperson */, + observationTypeFk = 4 /* salesperson */ , `description` = vNotes ON DUPLICATE KEY UPDATE `description` = CONCAT(VALUES(`description`),'. ', `description`); @@ -13942,7 +13929,7 @@ BEGIN INTO vDelivery, vAddress, vAgencyMode FROM `order` WHERE id = vSelf; - + CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable; @@ -13984,7 +13971,7 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; CREATE TEMPORARY TABLE tmp.addressCompany (INDEX (addressFk, companyFk)) - ENGINE = MEMORY + 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; @@ -14019,7 +14006,7 @@ BEGIN 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)) @@ -14028,7 +14015,7 @@ BEGIN SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax FROM tmp.orderTax GROUP BY orderFk, `code`; - + DROP TEMPORARY TABLE tmp.addressTaxArea; END ;; DELIMITER ; @@ -14098,7 +14085,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.`order` ENGINE = MEMORY SELECT vSelf orderFk; - + CALL order_getTax; SELECT IFNULL(SUM(taxableBase), 0.0), IFNULL(SUM(tax), 0.0) @@ -14189,7 +14176,7 @@ proc: BEGIN FROM orderRow r JOIN orderRowComponent c ON c.rowFk = r.id WHERE r.orderFk = vSelf; - + UPDATE orderRow r LEFT JOIN tmp.ticketComponentPrice p ON p.warehouseFk = r.warehouseFk @@ -14214,7 +14201,7 @@ proc: BEGIN ON t.id = c.componentFk AND (t.classRate IS NULL OR t.classRate = r.rate) WHERE r.orderFk = vSelf; - + CALL vn.ticketCalculatePurge; END IF; @@ -14742,13 +14729,13 @@ p: BEGIN AND DATE(FECHA) = vDate AND EURODEBE = vAmount LIMIT 1; - + -- Actualiza la transaccion UPDATE tpvTransaction SET response = NULL, status = 'started' WHERE id = vSelf; - + COMMIT; END ;; DELIMITER ; @@ -14781,7 +14768,7 @@ BEGIN UPDATE userSession SET userVisitFk = vUserVisit WHERE ssid = vSsid; - + DELETE FROM userSession WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, util.VN_NOW()); END ;; @@ -14905,7 +14892,7 @@ BEGIN UPDATE visitAgent SET firstAccessFk = vAccessId WHERE id = vAgentId; END IF; - + -- Returns the visit info SELECT vVisit visit, vAccessId access; @@ -15618,7 +15605,7 @@ BEGIN WHILE vI < vLen DO SET vChr = SUBSTR(vPhone, vI + 1, 1); - + IF vChr REGEXP '^[0-9]$' THEN SET vNewPhone = CONCAT(vNewPhone, vChr); @@ -15626,7 +15613,7 @@ BEGIN THEN SET vNewPhone = CONCAT(vNewPhone, '00'); END IF; - + SET vI = vI + 1; END WHILE; @@ -15725,18 +15712,18 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sip_getExtension`(vUserId INT(10)) BEGIN - + /* * Devuelve la extensión pbx del usuario - * - * @param vUserId Id del usuario - * + * + * @param vUserId Id del usuario + * */ SELECT extension - FROM sip s + FROM sip s WHERE s.user_id = vUserId; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -15962,6 +15949,19 @@ CREATE TABLE `TiposTransacciones` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `accountingEntryError` +-- + +DROP TABLE IF EXISTS `accountingEntryError`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `accountingEntryError` ( + `accountingEntryFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`accountingEntryFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Listado de asientos presentes en Sage para notificar su error'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `clientLastTwoMonths` -- @@ -16524,22 +16524,22 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `company_getCode`(vCompanyFk INT) RET READS SQL DATA BEGIN /** - * Devuelve la correspondencía del código de empresa de sage. + * Devuelve la correspondencía del código de empresa de sage. * Tiene en cuenta el entorno - * + * * @param vSelf Id de empresa de verdnatura * @return Código de empresa sage */ DECLARE vCompanySageFk INT(2); - - SELECT IF(c.environment = 'production', - co.companyCode, + + SELECT IF(c.environment = 'production', + co.companyCode, co.companyCodeTest ) INTO vCompanySageFk FROM util.config c JOIN vn.company co WHERE co.id = vCompanyFk; - + RETURN vCompanySageFk; END ;; DELIMITER ; @@ -16558,12 +16558,12 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `accountingMovements_add`( - vYear INT, + vYear INT, vCompanyFk INT ) BEGIN /** - * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta + * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta * para poder ejecutar posteriormente el proceso de importación de datos de SQL Server * Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE * @vYear Año contable del que se quiere trasladar la información @@ -16580,7 +16580,6 @@ BEGIN DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; DECLARE vInvoiceTypeInformativeCode VARCHAR(1); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2) ; - DECLARE vBookEntries TEXT; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -16879,8 +16878,8 @@ BEGIN mci.FechaFacturaOriginal = x.FECHA_EX, mci.SuFacturaNo = x.FACTURAEX, mci.FechaOperacion = x.FECHA_OP, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -16899,7 +16898,7 @@ BEGIN mci.CodigoIva2 = vTaxImportFk, mci.IvaDeducible2 = TRUE, mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -16917,8 +16916,8 @@ BEGIN mci.CodigoTransaccion3 = vDuaTransactionFk , mci.CodigoIva3 = vTaxImportSuperReducedFk, mci.IvaDeducible3 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + - x.BASEEURO + + mci.ImporteFactura = mci.ImporteFactura + + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) WHERE pm.description = 'HP Iva pendiente' AND mci.enlazadoSage = FALSE @@ -16952,14 +16951,14 @@ BEGIN OR CodigoTransaccion2 = vTransactionExportFk OR CodigoTransaccion3 = vTransactionExportFk OR CodigoTransaccion4 = vTransactionExportFk) - AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, + AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8mb3_unicode_ci, vCountryCeutaMelillaCode COLLATE utf8mb3_unicode_ci); UPDATE movConta mc SET CodigoDivisa = 'USD', FactorCambio = TRUE, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, - ImporteAsiento / ImporteDivisa, + ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, + ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) WHERE enlazadoSage = FALSE AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio); @@ -16970,41 +16969,6 @@ BEGIN AND importeDivisa > 0 AND ImporteAsiento < 0; - -- Comprobación que los importes e ivas sean correctos, avisa vía CAU - SELECT GROUP_CONCAT(Asiento ORDER BY Asiento ASC SEPARATOR ',') INTO vBookEntries - FROM(SELECT sub.Asiento - FROM (SELECT mc.Asiento, SUM(mc.ImporteAsiento) amount - FROM movConta mc - WHERE mc.enlazadoSage = FALSE - GROUP BY mc.Asiento)sub - JOIN (SELECT x.ASIEN, SUM(IFNULL(x.EURODEBE,0) + IFNULL(x.EUROHABER,0)) amount - FROM vn.XDiario x - WHERE x.enlazadoSage = FALSE - GROUP BY ASIEN)sub2 ON sub2.ASIEN = sub.Asiento - WHERE sub.amount <> sub2.amount - UNION ALL - SELECT sub.Asiento - FROM (SELECT Asiento, SUM(BaseIva1 + BaseIva2 + BaseIva3 + BaseIva4) amountTaxableBase - FROM movConta - WHERE TipoFactura <> 'I' - AND enlazadoSage = FALSE - GROUP BY Asiento) sub - JOIN (SELECT ASIEN, SUM(BASEEURO) amountTaxableBase - FROM (SELECT ASIEN, SUM(BASEEURO) BASEEURO - FROM vn.XDiario - WHERE FACTURA - AND auxiliar <> '*' - AND enlazadoSage = FALSE - GROUP BY FACTURA, ASIEN)sub3 - GROUP BY ASIEN) sub2 ON sub2.ASIEN = sub.Asiento - WHERE sub.amountTaxableBase<>sub2.amountTaxableBase - AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase) sub; - - IF vBookEntries IS NOT NULL THEN - SELECT util.notification_send ("book-entries-imported-incorrectly", - CONCAT('{"bookEntries":"', vBookEntries,'"}'), - null); - END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -17083,8 +17047,8 @@ BEGIN IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla := IF(pr.Provincia IN ('CEUTA', 'MELILLA'), TRUE, FALSE), vCountryCeutaMelillaFk, IF (@isCanarias, vCountryCanariasCode, n.CodigoNacion)), n.CodigoNacion), IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, IF(@isCeutaMelilla, vCountryCeutaMelillaCode, IF (@isCanarias, vCountryCanariasCode, n.SiglaNacion)), n.SiglaNacion), IF((c.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F'), - IF(cu.code = 'ES', - 1, + IF(cu.code = 'ES', + 1, IF((cu.isUeeMember AND c.isVies), 2, 4)), IFNULL(c.taxTypeSageFk,0), IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8mb3_unicode_ci, @@ -17150,6 +17114,81 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `importErrorNotification` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `importErrorNotification`() +BEGIN +/** + * Inserta notificaciones con los errores detectados durante la importación + * + */ + DECLARE vBookEntries TEXT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT GROUP_CONCAT(error SEPARATOR ' ') INTO vBookEntries + FROM( + SELECT CONCAT('- Importes: ', sub.Asiento) error + FROM (SELECT mc.Asiento, SUM(mc.ImporteAsiento) amount + FROM movConta mc + WHERE mc.enlazadoSage = FALSE + GROUP BY mc.Asiento)sub + JOIN (SELECT x.ASIEN, SUM(IFNULL(x.EURODEBE,0) + IFNULL(x.EUROHABER,0)) amount + FROM vn.XDiario x + WHERE x.enlazadoSage = FALSE + GROUP BY ASIEN)sub2 ON sub2.ASIEN = sub.Asiento + WHERE sub.amount <> sub2.amount + UNION ALL + SELECT CONCAT('- Base imponible: ', sub.Asiento) + FROM (SELECT Asiento, SUM(BaseIva1 + BaseIva2 + BaseIva3 + BaseIva4) amountTaxableBase + FROM movConta + WHERE TipoFactura <> 'I' + AND enlazadoSage = FALSE + GROUP BY Asiento) sub + JOIN (SELECT ASIEN, SUM(BASEEURO) amountTaxableBase + FROM (SELECT ASIEN, SUM(BASEEURO) BASEEURO + FROM vn.XDiario + WHERE FACTURA + AND auxiliar <> '*' + AND enlazadoSage = FALSE + GROUP BY FACTURA, ASIEN)sub3 + GROUP BY ASIEN) sub2 ON sub2.ASIEN = sub.Asiento + WHERE sub.amountTaxableBase<>sub2.amountTaxableBase + AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase + UNION ALL + SELECT CONCAT('- Factura Duplicada: ', mc.Asiento) + FROM accountingEntryError + )sub; + + IF vBookEntries IS NOT NULL THEN + START TRANSACTION; + + SELECT util.notification_send ("book-entries-imported-incorrectly", + CONCAT('{"bookEntries":"', vBookEntries,'"}'), + null); + + TRUNCATE accountingEntryError; + + COMMIT; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceIn_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17162,10 +17201,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceIn_add`(vInvoiceInFk INT, vX BEGIN /** * Traslada la info de contabilidad relacionada con las facturas recibidas - * + * * @vInvoiceInFk Factura recibida * @vXDiarioFk Id tabla XDiario - */ + */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vBase DOUBLE; DECLARE vVat DOUBLE; @@ -17182,25 +17221,25 @@ BEGIN DECLARE vInvoiceTypeInformative VARCHAR(1); DECLARE vIsInformativeExportation BOOL DEFAULT FALSE; - DECLARE vCursor CURSOR FOR + DECLARE vCursor CURSOR FOR SELECT it.taxableBase, CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)), t.PorcentajeIva, it.transactionTypeSageFk, it.taxTypeSageFk, tty.isIntracommunity, - tt.ClaveOperacionDefecto + tt.ClaveOperacionDefecto FROM vn.invoiceIn i JOIN vn.invoiceInTax it ON it.InvoiceInFk = i.id JOIN TiposIva t ON t.CodigoIva = it.taxTypeSageFk JOIN taxType tty ON tty.id = t.CodigoIva JOIN TiposTransacciones tt ON tt.CodigoTransaccion = it.transactionTypeSageFk LEFT JOIN vn.dua d ON d.id = vInvoiceInFk - WHERE i.id = vInvoiceInFk + WHERE i.id = vInvoiceInFk AND d.id IS NULL; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + DELETE FROM movContaIVA WHERE id = vXDiarioFk; @@ -17223,22 +17262,22 @@ BEGIN vTaxCode, vIsIntracommunity, vOperationCode; - - IF vDone THEN + + IF vDone THEN LEAVE l; END IF; - SET vTransactionCodeOld = vTransactionCode; - SET vTaxCodeOld = vTaxCode; + SET vTransactionCodeOld = vTransactionCode; + SET vTaxCodeOld = vTaxCode; - IF vOperationCode IS NOT NULL THEN + IF vOperationCode IS NOT NULL THEN UPDATE movContaIVA SET ClaveOperacionFactura = vOperationCode WHERE id = vXDiarioFk; END IF; - + SET vCounter = vCounter + 1; - CASE vCounter + CASE vCounter WHEN 1 THEN UPDATE movContaIVA SET BaseIva1 = vBase, @@ -17274,31 +17313,31 @@ BEGIN WHERE id = vXDiarioFk; ELSE SELECT vXDiarioFk INTO vXDiarioFk; - END CASE; + END CASE; IF vIsIntracommunity THEN UPDATE movContaIVA SET Intracomunitaria = TRUE WHERE id = vXDiarioFk; END IF; - - SET vTransactionCodeOld = vTransactionCode; - SET vTaxCodeOld = vTaxCode; - + + SET vTransactionCodeOld = vTransactionCode; + SET vTaxCodeOld = vTaxCode; + END LOOP; CLOSE vCursor; SELECT d.ASIEN AND x.ASIEN IS NULL INTO vIsInformativeExportation FROM vn.dua d - LEFT JOIN vn.XDiario x ON x.ASIEN = d.ASIEN + LEFT JOIN vn.XDiario x ON x.ASIEN = d.ASIEN AND x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci WHERE d.ASIEN = ( SELECT ASIEN - FROM vn.XDiario + FROM vn.XDiario WHERE id = vXDiarioFk) LIMIT 1; - + UPDATE movContaIVA mci JOIN tmp.invoiceIn ii ON ii.id = vInvoiceInFk JOIN vn.XDiario x ON x.id = mci.id @@ -17310,13 +17349,13 @@ BEGIN mci.Serie = ii.serial, mci.Factura = ii.id, mci.FechaFactura = ii.issued, - mci.ImporteFactura = IFNULL(mci.BaseIva1, 0) + IFNULL(mci.CuotaIva1, 0) + - IFNULL(mci.BaseIva2, 0) + IFNULL(mci.CuotaIva2, 0) + - IFNULL(mci.BaseIva3, 0) + IFNULL(mci.CuotaIva3, 0) + + mci.ImporteFactura = IFNULL(mci.BaseIva1, 0) + IFNULL(mci.CuotaIva1, 0) + + IFNULL(mci.BaseIva2, 0) + IFNULL(mci.CuotaIva2, 0) + + IFNULL(mci.BaseIva3, 0) + IFNULL(mci.CuotaIva3, 0) + IFNULL(mci.BaseIva4, 0) + IFNULL(mci.CuotaIva4, 0), - mci.TipoFactura = IF(id.id, - IF( ii.serial = vSerialDua COLLATE utf8mb3_unicode_ci, vInvoiceTypeReceived, vInvoiceTypeInformative), - IF(vIsInformativeExportation,vInvoiceTypeInformative, vInvoiceTypeReceived)), + mci.TipoFactura = IF(id.id, + IF( ii.serial = vSerialDua COLLATE utf8mb3_unicode_ci, vInvoiceTypeReceived, vInvoiceTypeInformative), + IF(vIsInformativeExportation,vInvoiceTypeInformative, vInvoiceTypeReceived)), mci.CodigoCuentaFactura = x.SUBCTA, mci.CifDni = IF(LEFT(TRIM(s.nif), 2) = n.SiglaNacion, SUBSTRING(TRIM(s.nif), 3), s.nif), mci.Nombre = s.name, @@ -17344,7 +17383,7 @@ BEGIN JOIN (SELECT SUM(x2.BASEEURO) taxableBase, SUM(x2.EURODEBE) taxBase FROM vn.XDiario x1 JOIN vn.XDiario x2 ON x1.ASIEN = x2.ASIEN - WHERE x2.BASEEURO <> 0 + WHERE x2.BASEEURO <> 0 AND x1.id = vXDiarioFk )sub JOIN ClavesOperacion co ON co.Descripcion = 'Arrendamiento de locales de negocio' @@ -17352,8 +17391,8 @@ BEGIN mci.ClaveOperacionFactura = IF( t.Retencion = 'ARRENDAMIENTO Y SUBARRENDAMIENTO', co.ClaveOperacionFactura_, mci.ClaveOperacionFactura), mci.BaseRetencion = IF (t.Retencion = 'ACTIVIDADES AGRICOLAS O GANADERAS', sub.taxableBase + sub.taxBase, sub.taxableBase), mci.PorRetencion = t.PorcentajeRetencion, - mci.ImporteRetencion = iit.taxableBase * - 1 - WHERE mci.id = vXDiarioFk + mci.ImporteRetencion = iit.taxableBase * - 1 + WHERE mci.id = vXDiarioFk AND e.name = 'Retenciones' AND id.id IS NULL; @@ -17376,10 +17415,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceIn_manager`(vYear INT, vCompanyFk INT) BEGIN /** - * Traslada la info de contabilidad relacionada con las facturas recibidas - * + * Traslada la info de contabilidad relacionada con las facturas recibidas + * * @vYear Año contable del que se quiere trasladar la información - * @vCompany Empresa de la que se quiere trasladar datos + * @vCompany Empresa de la que se quiere trasladar datos */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; @@ -17391,22 +17430,22 @@ BEGIN DECLARE vAccountTaxOutstanding VARCHAR(10); DECLARE vInvoiceTypeSended VARCHAR(1); DECLARE vCursor CURSOR FOR - SELECT IFNULL(x.CLAVE, x.FACTURA) invoiceInFk, + SELECT IFNULL(x.CLAVE, x.FACTURA) invoiceInFk, x.id XDiarioFk - FROM vn.XDiario x + FROM vn.XDiario x JOIN(SELECT DISTINCT(x.ASIEN) FROM vn.XDiario x LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id LEFT JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id - WHERE(it.taxTypeSageFk IS NOT NULL OR x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci) - AND x.enlazadoSage = FALSE + WHERE(it.taxTypeSageFk IS NOT NULL OR x.SERIE = vSerialDua COLLATE utf8mb3_unicode_ci) + AND x.enlazadoSage = FALSE AND x.FECHA BETWEEN vDatedFrom AND vDatedTo - AND x.empresa_id = vCompanyFk + AND x.empresa_id = vCompanyFk ) sub ON sub.ASIEN = x.ASIEN WHERE x.CLAVE IS NOT NULL; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) INTO vDatedFrom, vDatedTo; @@ -17420,15 +17459,15 @@ BEGIN SELECT codeSage INTO vInvoiceTypeSended FROM invoiceType WHERE `code` ='sended'; - + DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; CREATE TEMPORARY TABLE tmp.invoiceDua - SELECT x.id + SELECT x.id FROM vn.XDiario x JOIN vn.company c ON c.id = x.empresa_id JOIN (SELECT ASIEN - FROM vn.XDiario x - WHERE x.enlazadoSage = FALSE + FROM vn.XDiario x + WHERE x.enlazadoSage = FALSE AND x.SUBCTA = vAccountTaxOutstanding COLLATE utf8mb3_unicode_ci AND x.FECHA BETWEEN vDatedFrom AND vDatedTo )sub ON sub.ASIEN = x.ASIEN @@ -17446,7 +17485,7 @@ BEGIN FROM vn.invoiceIn i JOIN vn.currency c ON c.id = i.currencyFk WHERE i.bookEntried BETWEEN vDatedFrom AND vDatedTo - UNION ALL + UNION ALL SELECT d.id, d.code, vSerialDua COLLATE utf8mb3_unicode_ci, @@ -17454,8 +17493,8 @@ BEGIN d.issued, FALSE, '' -- EUROS - FROM vn.dua d - WHERE d.issued IS NOT NULL + FROM vn.dua d + WHERE d.issued IS NOT NULL AND code IS NOT NULL; OPEN vCursor; @@ -17463,7 +17502,7 @@ BEGIN l: LOOP FETCH vCursor INTO vInvoiceFk, vXDiarioFk; - IF vDone THEN + IF vDone THEN LEAVE l; END IF; CALL invoiceIn_add(vInvoiceFk, vXDiarioFk); @@ -17551,21 +17590,21 @@ BEGIN JOIN (SELECT x.ASIEN, x.id FROM vn.XDiario x JOIN(SELECT DISTINCT(x.ASIEN) ASIEN - FROM vn.XDiario x + FROM vn.XDiario x JOIN (SELECT DISTINCT(ASIEN) FROM vn.XDiario x - WHERE SUBCTA LIKE '472%' + WHERE SUBCTA LIKE '472%' AND x.enlazadoSage = FALSE AND x.empresa_id = vCompanyFk AND x.FECHA BETWEEN vDatedFrom AND vDatedTo ) sub ON sub.ASIEN = x.ASIEN WHERE x.SUBCTA LIKE '477%' )sub2 ON sub2.ASIEN = x.ASIEN - WHERE x.CONTRA IS NOT NULL + WHERE x.CONTRA IS NOT NULL AND x.SUBCTA LIKE '477%' GROUP BY x.ASIEN )sub3 ON sub3.ASIEN = x.ASIEN; - + INSERT INTO movContaIVA (`id`, `CodigoDivisa`, @@ -17636,9 +17675,9 @@ BEGIN `FechaGrabacion`, `Intracomunitaria`, `moveData`) - SELECT * + SELECT * FROM tmp.movContaIVA; - + DROP TEMPORARY TABLE tmp.movContaIVA; END ;; @@ -17660,10 +17699,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_add`(IN vInvoiceOutFk INT, IN vXDiarioFk INT) BEGIN /** - * Traslada la info de contabilidad relacionada con las facturas emitidas - * + * Traslada la info de contabilidad relacionada con las facturas emitidas + * * @vYear Año contable del que se quiere trasladar la información - * @vCompany Empresa de la que se quiere trasladar datos + * @vCompany Empresa de la que se quiere trasladar datos */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vMaxLengthName INT DEFAULT 35; @@ -17683,12 +17722,12 @@ BEGIN DECLARE vHasCustomsAccountingNote BOOL; DECLARE vCursor CURSOR FOR - SELECT oit.taxableBase, - oit.vat, - pgc.rate, - pgc.mod347, - pgcRE.rate, - oitRE.vat, + SELECT oit.taxableBase, + oit.vat, + pgc.rate, + pgc.mod347, + pgcRE.rate, + oitRE.vat, tc.transactionCode, tc.taxCode, tc.isIntracommunity, @@ -17697,7 +17736,7 @@ BEGIN JOIN vn.pgc ON pgc.code = oit.pgcFk LEFT JOIN vn.pgcEqu e ON e.vatFk = oit.pgcFk LEFT JOIN vn.pgcEqu eRE ON eRE.equFk = oit.pgcFk - LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk + LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk AND oitRE.pgcFk = e.equFk LEFT JOIN vn.pgc pgcRE ON pgcRE.code = oitRE.pgcFk LEFT JOIN vn.taxCode tc ON tc.code = pgc.code COLLATE 'utf8mb3_unicode_ci' @@ -17713,12 +17752,12 @@ BEGIN WHERE ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioFk); SELECT codeSage INTO vInvoiceTypeSended - FROM invoiceType + FROM invoiceType WHERE code = IF(vHasCustomsAccountingNote, 'informative', 'sended'); - + DELETE FROM movContaIVA WHERE id = vXDiarioFk; - + INSERT INTO movContaIVA(id) VALUES (vXDiarioFk); OPEN vCursor; @@ -17735,13 +17774,13 @@ BEGIN vIsIntracommunity, vOperationCode; - IF vDone THEN + IF vDone THEN LEAVE l; END IF; SET vCounter = vCounter + 1; - - CASE vCounter + + CASE vCounter WHEN 1 THEN UPDATE movContaIVA SET BaseIva1 = vBase, @@ -17782,7 +17821,7 @@ BEGIN CodigoTransaccion4 = vTransactionCode, CodigoIva4 = vTaxCode WHERE id = vXDiarioFk; - END CASE; + END CASE; UPDATE movContaIVA SET Exclusion347 = NOT vMod347, @@ -17793,7 +17832,7 @@ BEGIN END LOOP; CLOSE vCursor; - + UPDATE movContaIVA mci JOIN vn.invoiceOut i ON i.id = vInvoiceOutFk LEFT JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutFk @@ -17818,25 +17857,25 @@ BEGIN mci.MantenerAsiento = TRUE, mci.FechaFacturaOriginal = x.FECHA_EX WHERE mci.id = vXDiarioFk; - + SELECT correctedFk INTO vInvoiceOutCorrectedFk FROM vn.invoiceCorrection WHERE correctingFk = vInvoiceOutFk; - - IF vInvoiceOutCorrectedFk THEN + + IF vInvoiceOutCorrectedFk THEN UPDATE movContaIVA mci JOIN vn.invoiceOut i ON i.id = vInvoiceOutCorrectedFk JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk - JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, + JOIN (SELECT SUM(IF(IFNULL(e.vatFk, TRUE), iot.taxableBase, 0)) taxableBase, SUM(IF(IFNULL(e.vatFk, TRUE), iot.vat, 0)) vat, SUM(IF(IFNULL(e.vatFk, TRUE), 0, iot.vat)) equ FROM vn.invoiceOutTax iot - LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk + LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk ) tax JOIN ClavesOperacion co ON co.Descripcion = 'Factura rectificativa' SET mci.TipoRectificativa = 2, - mci.ClaseAbonoRectificativas = 1, + mci.ClaseAbonoRectificativas = 1, mci.FechaFacturaOriginal = i.issued, mci.FechaOperacion = i.issued, mci.BaseImponibleOriginal = tax.taxableBase, @@ -17867,10 +17906,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_manager`(vYear INT, vCompanyFk INT) BEGIN /** - * Traslada la info de contabilidad relacionada con las facturas emitidas - * + * Traslada la info de contabilidad relacionada con las facturas emitidas + * * @vYear Año contable del que se quiere trasladar la información - * @vCompany Empresa de la que se quiere trasladar datos + * @vCompany Empresa de la que se quiere trasladar datos */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vInvoiceFk INT; @@ -17887,7 +17926,7 @@ BEGIN JOIN (SELECT x.ASIEN, CONCAT(x.SERIE, x.FACTURA) refFk FROM vn.XDiario x WHERE x.enlazadoSage = FALSE - AND x.FACTURA + AND x.FACTURA AND x.empresa_id = vCompanyFk AND x.FECHA BETWEEN vDatedFrom AND vDatedTo GROUP BY refFk @@ -17896,19 +17935,19 @@ BEGIN )sub2 ON sub2.refFk = i.ref; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) INTO vDatedFrom, vDatedTo; - + OPEN vCursor; l: LOOP FETCH vCursor INTO vInvoiceFk, vXDiarioFk; - IF vDone THEN + IF vDone THEN LEAVE l; END IF; - + CALL invoiceOut_add(vInvoiceFk, vXDiarioFk); END LOOP; @@ -17934,7 +17973,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `pgc_add`(vCompanyFk INT) BEGIN /** - * Añade cuentas del plan general contable para exportarlos a Sage + * Añade cuentas del plan general contable para exportarlos a Sage * @vCompanyFk Empresa de la que se quiere trasladar datos */ TRUNCATE TABLE planCuentasPGC; @@ -17944,25 +17983,25 @@ BEGIN CodigoCuenta, Cuenta, ClienteOProveedor) - SELECT * + SELECT * FROM (SELECT company_getCode(vCompanyFk) companyFk, e.id accountFk, UCASE(e.name), '' FROM vn.expense e - UNION + UNION SELECT company_getCode(vCompanyFk), - b.account, + b.account, UCASE(b.bank), - '' + '' FROM vn.bank b WHERE b.isActive AND b.`account` - UNION + UNION SELECT CodigoEmpresa, CodigoCuenta, Nombre, - ClienteOProveedor + ClienteOProveedor FROM clientesProveedores)sub GROUP BY companyFk, accountFk; END ;; @@ -18311,7 +18350,7 @@ DELIMITER ;; FOR EACH ROW BEGIN SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); - + CALL visible_log( NEW.isPicked, NEW.warehouseFk, @@ -18435,7 +18474,7 @@ DELIMITER ;; BEGIN SET NEW.lack = NEW.quantity; SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); - + CALL visible_log( NEW.isPicked, NEW.warehouseFk, @@ -18646,7 +18685,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SET vSupplied = 0; OPEN vPicks; @@ -18662,7 +18701,7 @@ BEGIN SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity); SET vSupplied = vSupplied + vPickGranted; CALL inbound_removePick(vSelf, vOutboundFk, vPickGranted, vPickQuantity); - + UPDATE outbound SET isSync = FALSE, lack = lack + vPickGranted @@ -18742,7 +18781,7 @@ BEGIN END IF; SET vSupplied = LEAST(vAvailable, vLack); - + IF vSupplied > 0 THEN SET vAvailable = vAvailable - vSupplied; UPDATE outbound @@ -18755,7 +18794,7 @@ BEGIN SET vSupplied = vSupplied + vSuppliedFromRequest; SET vAvailable = vAvailable - vSuppliedFromRequest; END IF; - + IF vSupplied > 0 THEN CALL inbound_addPick(vSelf, vOutboundFk, vSupplied); END IF; @@ -18884,7 +18923,7 @@ 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; @@ -19355,7 +19394,7 @@ BEGIN SET vPickGranted = LEAST(vRequested - vSupplied, vPickQuantity); SET vSupplied = vSupplied + vPickGranted; CALL inbound_removePick(vInboundFk, vSelf, vPickGranted, vPickQuantity); - + UPDATE inbound SET isSync = FALSE, available = available + vPickGranted @@ -19809,11 +19848,11 @@ BEGIN WHILE vI < vLen DO SET vSpaceIni = vI; - + WHILE MID(vString, vI, 1) REGEXP '[[:space:]]' DO SET vI = vI + 1; END WHILE; - + SET vWordIni = vI; SET vI = vWordIni + 1; @@ -19850,11 +19889,11 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `crypt`(vText VARCHAR(255), vKey VARC BEGIN DECLARE vResult VARCHAR(255); - + CALL vn.crypt(vText, vKey, vResult); RETURN vResult; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -19876,11 +19915,11 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `cryptOff`(vText VARCHAR(255), vKey V BEGIN DECLARE vResult VARCHAR(255); - + CALL vn.cryptOff(vText, vKey, vResult); RETURN vResult; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -20048,7 +20087,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasDateOverlapped`(vSarted1 DATE, vEnded1 DATE, vSarted2 DATE, vEnded2 DATE) RETURNS tinyint(1) DETERMINISTIC -BEGIN +BEGIN RETURN GREATEST(vSarted1, vSarted2) <= LEAST(vEnded1,vEnded2); @@ -20077,7 +20116,7 @@ BEGIN */ DECLARE vHashlen INT UNSIGNED; DECLARE vOpad, vIpad TINYBLOB; - + CASE vAlg WHEN 224 THEN SET vHashlen = 64; WHEN 256 THEN SET vHashlen = 64; @@ -20085,16 +20124,16 @@ BEGIN WHEN 512 THEN SET vHashlen = 128; ELSE CALL throw ('WRONG_ALGORYTHM_IDENTIFICATOR_USED'); END CASE; - + IF LENGTH(vKey) > vHashlen THEN SET vKey = UNHEX(SHA2(vKey, vAlg)); END IF; - + SET vKey = RPAD(vKey, vHashlen, 0x00); - + SET vIpad = stringXor(vKey, 0x36); SET vOpad = stringXor(vKey, 0x5C); - + RETURN SHA2(CONCAT(vOpad, UNHEX(SHA2(CONCAT(vIpad, vMsg), vAlg))), vAlg); END ;; DELIMITER ; @@ -20117,7 +20156,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `isLeapYear`(vYear INT) RETURNS tinyi BEGIN RETURN (DAYOFYEAR(CONCAT(vYear, "-02-29")) IS NOT NULL); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -20276,7 +20315,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `midnight`() RETURNS datetime READS SQL DATA BEGIN - + RETURN TIMESTAMP(util.VN_CURDATE(), '23:59:59'); END ;; @@ -20404,7 +20443,7 @@ BEGIN * modo 3. */ DECLARE vYear INT DEFAULT FLOOR(vYearWeek / 100); - + IF vYearWeek < YEARWEEK(CONCAT(vYear, '-12-31'), 3) THEN RETURN vYearWeek + 1; ELSE @@ -20510,16 +20549,16 @@ BEGIN */ DECLARE vLen, vPos INT UNSIGNED; DECLARE vResult MEDIUMBLOB; - + SET vLen = LENGTH(vString); SET vPos = 1; SET vResult = ''; - + WHILE vPos <= vLen DO SET vResult = CONCAT(vResult, LPAD(HEX( ORD(SUBSTR(vString, vPos, 1)) ^ vConst), 2, '0')); SET vPos = vPos + 1; END WHILE; - + RETURN UNHEX(vResult); END ;; DELIMITER ; @@ -20790,11 +20829,11 @@ BEGIN IF vYear = vCurYear THEN RETURN 'curYear'; END IF; - + IF vYear = vCurYear - 1 THEN RETURN 'lastYear'; END IF; - + IF vYear = vCurYear - 2 THEN RETURN 'twoYearsAgo'; END IF; @@ -20877,7 +20916,7 @@ BEGIN * @param vValue Valor de la variable */ DECLARE vIndex INT DEFAULT INSTR(USER(), '@'); - + INSERT INTO debug SET `connectionId` = CONNECTION_ID(), `user` = LEFT(USER(), vIndex - 1), @@ -21261,7 +21300,7 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `time_createTable` */; +/*!50003 DROP PROCEDURE IF EXISTS `time_generate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -21269,18 +21308,41 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `time_createTable`(vStarted DATE, vEnded DATE) +CREATE DEFINER=`root`@`localhost` PROCEDURE `time_generate`(vStarted DATE, vEnded DATE) BEGIN +/** + * Generate a temporary table between the days passed as parameters + * + * @param vStarted Start date + * @param vEnded End date + * @table tmp.time (dated, dayed, weeked, monthed, yeared) + */ DECLARE vCurrentDate DATE; - DROP TEMPORARY TABLE IF EXISTS tmp.time; - CREATE TEMPORARY TABLE tmp.time (dated DATE PRIMARY KEY) ENGINE = MEMORY; - SET vCurrentDate = vStarted; - WHILE vCurrentDate <= vEnded DO - INSERT INTO tmp.time (dated) VALUES (vCurrentDate); - SET vCurrentDate = DATE_ADD(vCurrentDate, INTERVAL 1 DAY); - END WHILE; + CREATE OR REPLACE TEMPORARY TABLE tmp.time( + dated DATE PRIMARY KEY, + `day` INT, + `week` INT, + `month` INT, + `year` INT + ) ENGINE = MEMORY; + IF(vStarted > vEnded) THEN + CALL throw('The started cannot be later than the ended'); + END IF; + + SET vCurrentDate = vStarted; + + WHILE vCurrentDate <= vEnded DO + INSERT INTO tmp.time + SET dated = vCurrentDate, + `day` = DAY(vCurrentDate), + `week` = WEEK(vCurrentDate), + `month` = MONTH(vCurrentDate), + `year` = YEAR(vCurrentDate); + + SET vCurrentDate = vCurrentDate + INTERVAL 1 DAY; + END WHILE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -21623,8 +21685,8 @@ CREATE TABLE `address` ( `isDefaultAddress` tinyint(1) NOT NULL DEFAULT 0, `agencyModeFk` int(11) NOT NULL DEFAULT 2, `isActive` tinyint(4) NOT NULL DEFAULT 1, - `longitude` decimal(11,7) DEFAULT NULL, - `latitude` decimal(11,7) DEFAULT NULL, + `longitude` decimal(11,7) DEFAULT NULL COMMENT 'Indica la última longitud proporcionada por tabla delivery', + `latitude` decimal(11,7) DEFAULT NULL COMMENT 'Indica la última latitud proporcionada por tabla delivery', `isEqualizated` tinyint(1) DEFAULT NULL, `customsAgentFk` int(11) DEFAULT NULL, `incotermsFk` varchar(3) DEFAULT NULL, @@ -21674,11 +21736,11 @@ BEGIN END IF; IF NEW.isEqualizated IS NULL THEN - SELECT isEqualizated + SELECT isEqualizated INTO vIsEqualizated FROM client WHERE id = NEW.clientFk; - + SET NEW.isEqualizated = vIsEqualizated; END IF; END */;; @@ -21696,11 +21758,35 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_afterInsert` + BEFORE INSERT ON `address` + FOR EACH ROW +BEGIN + IF (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_beforeUpdate` BEFORE UPDATE ON `address` FOR EACH ROW BEGIN - + SET NEW.editorFk = account.myUser_getId(); IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN @@ -21732,30 +21818,37 @@ DELIMITER ;; BEGIN -- Recargos de equivalencia distintos implican facturacion por consignatario IF NEW.isEqualizated != OLD.isEqualizated THEN - IF + IF (SELECT COUNT(*) FROM ( SELECT DISTINCT (isEqualizated = FALSE) as Equ - FROM address + FROM address WHERE clientFk = NEW.clientFk ) t1 ) > 1 - THEN - UPDATE client + THEN + UPDATE client SET hasToInvoiceByAddress = TRUE WHERE id = NEW.clientFk; END IF; END IF; - IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN + IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN CALL util.throw ('Cannot desactivate the default address'); - END IF; + END IF; IF NOT (NEW.isEqualizated <=> OLD.isEqualizated) THEN - INSERT IGNORE INTO ticketRecalc (ticketFk) - SELECT id FROM ticket t - WHERE t.addressFk = NEW.id - AND t.refFk IS NULL; + INSERT IGNORE INTO ticketRecalc (ticketFk) + SELECT id FROM ticket t + WHERE t.addressFk = NEW.id + AND t.refFk IS NULL; END IF; + + IF (NEW.clientFk <> OLD.clientFk OR NEW.isActive <> OLD.isActive OR NOT (NEW.provinceFk <=> OLD.provinceFk)) + AND (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -21983,6 +22076,21 @@ CREATE TABLE `agencyModeItemType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Combinaciones prohibidas entre agencyMode e itemType al calcular el catálogo de items'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `agencyModePricePercentage` +-- + +DROP TABLE IF EXISTS `agencyModePricePercentage`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `agencyModePricePercentage` ( + `agencyModeFk` int(11) NOT NULL, + `percentage` double NOT NULL, + PRIMARY KEY (`agencyModeFk`), + CONSTRAINT `agencyModePricePercentage_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `agencyTerm` -- @@ -22183,8 +22291,8 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_BI` BEFORE INSERT ON `autonomy` FOR EACH ROW -BEGIN - +BEGIN + SET NEW.geoFk = zoneGeo_new('autonomy', NEW.`name`, (SELECT geoFk FROM country WHERE id = NEW.countryFk)); END */;; @@ -22234,7 +22342,7 @@ DELIMITER ;; AFTER DELETE ON `autonomy` FOR EACH ROW BEGIN - CALL zoneGeo_delete(OLD.geoFk); + CALL zoneGeo_delete(OLD.geoFk); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -22309,7 +22417,7 @@ DELIMITER ;; BEFORE INSERT ON `awb` FOR EACH ROW BEGIN - + SET NEW.year= year(util.VN_CURDATE()); @@ -22637,11 +22745,11 @@ DELIMITER ;; BEFORE INSERT ON `budgetNotes` FOR EACH ROW BEGIN - + IF ISNULL(NEW.userFk) THEN - + SET NEW.userFk = account.myUser_getId(); - + END IF; END */;; @@ -22735,7 +22843,7 @@ DELIMITER ;; FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); - + IF NEW.ended IS NULL THEN SET NEW.payedHolidays = 0; END IF; @@ -22781,25 +22889,25 @@ BEGIN DECLARE isOverlapping BOOL; SET NEW.editorFk = account.myUser_getId(); - + IF NEW.ended IS NULL THEN SET NEW.payedHolidays = 0; END IF; IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN - + SELECT COUNT(*) > 0 INTO isOverlapping FROM business b WHERE (util.hasDateOverlapped( - NEW.started, + NEW.started, IFNULL(NEW.ended, b.started), b.started, IFNULL(b.ended, NEW.started)) OR (NEW.ended <=> NULL AND b.ended <=> NULL)) AND b.id <> OLD.id AND workerFk = OLD.workerFk; - - IF isOverlapping THEN + + IF isOverlapping THEN CALL util.throw ('IS_OVERLAPPING'); END IF; @@ -22938,7 +23046,7 @@ CREATE TABLE `buy` ( `itemFk` int(11) NOT NULL DEFAULT 90, `quantity` int(11) DEFAULT 0, `dispatched` int(11) NOT NULL DEFAULT 0, - `buyingValue` decimal(10,3) NOT NULL DEFAULT 0.000, + `buyingValue` decimal(10,4) NOT NULL DEFAULT 0.0000, `freightValue` decimal(10,3) NOT NULL DEFAULT 0.000, `isIgnored` tinyint(1) NOT NULL DEFAULT 0, `stickers` int(11) NOT NULL DEFAULT 0, @@ -23020,19 +23128,23 @@ trig: BEGIN CALL buy_checkGrouping(NEW.`grouping`); - SELECT t.warehouseInFk, t.landed INTO vWarehouse, vLanding + SELECT t.warehouseInFk, t.landed + INTO vWarehouse, vLanding FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.id = NEW.entryFk; - SELECT b.`grouping`, b.groupingMode INTO vGrouping, vGroupingMode + SELECT b.`grouping`, b.groupingMode + INTO vGrouping, vGroupingMode FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk WHERE t.landed <= vLanding AND b.itemFk = NEW.itemFk AND !b.isIgnored - ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC, b.id DESC + ORDER BY t.warehouseInFk = vWarehouse DESC, + t.landed DESC, + b.id DESC LIMIT 1; IF NEW.`grouping` IS NULL THEN @@ -23042,6 +23154,7 @@ trig: BEGIN IF NEW.groupingMode IS NULL THEN SET NEW.groupingMode = vGroupingMode; END IF; + -- Generics SELECT i.genericFk INTO vGenericFk FROM item i @@ -23052,17 +23165,27 @@ trig: BEGIN FROM genericAllocation ga JOIN entry e ON e.id = NEW.entryFk JOIN travel tr on tr.id = e.travelFk - WHERE ga.itemFk = vGenericFk - AND tr.landed BETWEEN ga.startDated AND ga.endDated; + WHERE ga.itemFk = vGenericFk + AND tr.landed BETWEEN ga.startDated AND ga.endDated; + IF vGenericInDate THEN SET NEW.itemOriginalFk = NEW.itemFk; - SET NEW.itemFk = vGenericFk; END IF; END IF; + IF NEW.quantity < 0 THEN - SET NEW.isIgnored = TRUE; + SET NEW.isIgnored = TRUE; END IF; + + IF NEW.weight AND NEW.packing + AND (SELECT weightByPiece FROM item WHERE id = NEW.itemFk) IS NULL THEN + + UPDATE item + SET weightByPiece = (NEW.weight * 1000) / NEW.packing + WHERE id = NEW.itemFk; + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -23256,7 +23379,7 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeDelete` BEFORE DELETE ON buy FOR EACH ROW -BEGIN +BEGIN IF OLD.printedStickers <> 0 THEN CALL util.throw("it is not possible to delete buys with printed labels "); END IF; @@ -24463,7 +24586,7 @@ BEGIN END IF; SET NEW.accountingAccount = 4300000000 + NEW.id; - + SET NEW.lastSalesPersonFk = NEW.salesPersonFk; END */;; DELIMITER ; @@ -24600,18 +24723,18 @@ BEGIN IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN UPDATE `address` SET isDefaultAddress = 0 WHERE clientFk = NEW.id; - + UPDATE `address` SET isDefaultAddress = 1 - WHERE id = NEW.defaultAddressFk; + WHERE id = NEW.defaultAddressFk; END IF; IF NOT (NEW.provinceFk <=> OLD.provinceFk) OR NOT (NEW.isVies <=> OLD.isVies) THEN INSERT IGNORE INTO ticketRecalc (ticketFk) - SELECT id FROM ticket t + SELECT id FROM ticket t WHERE t.clientFk = NEW.id AND t.refFk IS NULL; END IF; - + IF NOT NEW.isActive THEN UPDATE account.`user` SET active = FALSE @@ -24809,15 +24932,15 @@ DELIMITER ;; AFTER INSERT ON clientCredit FOR EACH ROW BEGIN - + DECLARE vSender VARCHAR(50); SELECT u.name INTO vSender FROM account.`user` u WHERE u.id = NEW.workerFk; - + IF vSender IN ('juanvi','pepe') THEN - + CALL `vn`.`mail_insert`('pako@verdnatura.es', NULL, CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €'), @@ -24832,23 +24955,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; --- --- Table structure for table `clientCreditLimit` --- - -DROP TABLE IF EXISTS `clientCreditLimit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `clientCreditLimit` ( - `id` int(11) NOT NULL, - `maxAmount` int(10) unsigned NOT NULL, - `roleFk` int(10) unsigned NOT NULL, - PRIMARY KEY (`id`), - KEY `clientCreditLimit_FK_idx` (`roleFk`), - CONSTRAINT `clientCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `clientDms` -- @@ -25164,11 +25270,8 @@ DROP TABLE IF EXISTS `clientProtected`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientProtected` ( `clientFk` int(11) NOT NULL, - `workerFk` int(10) unsigned NOT NULL, PRIMARY KEY (`clientFk`), - KEY `clientProtected_fk2_idx` (`workerFk`), - CONSTRAINT `clientProtected_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `clientProtected_fk2` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `clientProtected_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Lista de clientes y comerciales que no se van a ver afectados por las desagsignaciones mensuales automaticas'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -25400,7 +25503,7 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`cmr_beforeDelete` BEFORE DELETE ON `cmr` FOR EACH ROW -BEGIN +BEGIN IF NOT (OLD.companyFk <=> NULL AND OLD.addressFromFk <=> NULL AND OLD.packagesList <=> NULL) THEN CALL util.throw("Can not delete cmr, fields required not empty"); END IF; @@ -25486,39 +25589,39 @@ CREATE TABLE `collection` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE` - BEFORE UPDATE ON `collection` - FOR EACH ROW -BEGIN - - DECLARE vStateFk INT; - DECLARE vTotalLines INT; - DECLARE vPickedLines INT; - - IF NEW.saleTotalCount <= NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount - OR NEW.salePickedCount != OLD.salePickedCount) - THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'PREPARED'; - - SET NEW.stateFk = vStateFk; - - END IF; - - IF NEW.saleTotalCount > NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'ON_PREPARATION'; - - SET NEW.stateFk = vStateFk; - - END IF; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE` + BEFORE UPDATE ON `collection` + FOR EACH ROW +BEGIN + + DECLARE vStateFk INT; + DECLARE vTotalLines INT; + DECLARE vPickedLines INT; + + IF NEW.saleTotalCount <= NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount + OR NEW.salePickedCount != OLD.salePickedCount) + THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'PREPARED'; + + SET NEW.stateFk = vStateFk; + + END IF; + + IF NEW.saleTotalCount > NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'ON_PREPARATION'; + + SET NEW.stateFk = vStateFk; + + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -25681,7 +25784,7 @@ BEGIN IF NOT (NEW.id <=> OLD.id) THEN SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); END IF; - + IF NOT (NEW.`level` <=> OLD.`level`) THEN SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.`level`), vJSON); END IF; @@ -25701,7 +25804,7 @@ BEGIN IF NOT (NEW.itemPackingTypeFk <=> OLD.itemPackingTypeFk) THEN SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); END IF; - + IF NOT (NEW.trainFk <=> OLD.trainFk) THEN SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); END IF; @@ -25743,10 +25846,10 @@ BEGIN SET vJSON = JSON_MERGE(JSON_OBJECT('height', OLD.height), vJSON); SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', OLD.itemPackingTypeFk), vJSON); SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', OLD.trainFk), vJSON); - + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'delete'), vJSON); - + SET vJSON = util.notification_send( 'modified-collection-volumetry', JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), @@ -25921,6 +26024,21 @@ SET character_set_client = utf8; 1 AS `footnotes` */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `comparativeAddConfig` +-- + +DROP TABLE IF EXISTS `comparativeAddConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `comparativeAddConfig` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `period` int(10) unsigned DEFAULT NULL COMMENT 'The number of periods to be regressed for insertion in vn.comparative', + `week` int(10) unsigned DEFAULT NULL COMMENT 'The number of weeks to exceed for recalculating the last period', + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `comparativeConfig` -- @@ -26391,7 +26509,6 @@ CREATE TABLE `cplusCorrectingType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `cplusRectificationType` -- @@ -26552,7 +26669,7 @@ BEGIN UPDATE `client` c JOIN vn.creditClassification cc ON cc.client = c.id SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -26650,6 +26767,70 @@ CREATE TABLE `delivery` ( CONSTRAINT `delivery_ticketFk_FK` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores'; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`delivery_beforeInsert` + BEFORE INSERT ON `delivery` + FOR EACH ROW +BEGIN + + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) + THEN + UPDATE address + SET longitude = NEW.longitude, + latitude = NEW.latitude + WHERE id IN ( + SELECT addressFK + FROM ticket + WHERE id = NEW.ticketFk + ); + 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`delivery_beforeUpdate` + BEFORE UPDATE ON `delivery` + FOR EACH ROW +BEGIN + +IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) + THEN + UPDATE address + SET longitude = NEW.longitude, + latitude = NEW.latitude + WHERE id IN ( + SELECT addressFK + FROM ticket + WHERE id = NEW.ticketFk + ); + 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 */ ; -- -- Table structure for table `deliveryMethod` @@ -26821,7 +27002,7 @@ BEGIN JOIN vn.department d ON d.id = b.departmentFk SET b.departmentFk = d.parentFk WHERE b.departmentFk = OLD.id; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -26841,9 +27022,9 @@ DELIMITER ;; AFTER DELETE ON `department` FOR EACH ROW BEGIN - + UPDATE vn.department_recalc SET isChanged = TRUE; - + UPDATE vn.business b JOIN vn.department d ON d.id = b.departmentFk SET b.departmentFk = d.parentFk @@ -27347,20 +27528,20 @@ DELIMITER ;; BEGIN DECLARE vHardCopyNumber INT; DECLARE vDmsTypeCode INT; - + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN CALL util.throw('this warehouse has not dms'); END IF; IF NEW.hasFile THEN - SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber - FROM dms + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms WHERE warehouseFk = NEW.warehouseFk; - + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); END IF; - - SELECT code INTO vDmsTypeCode + + SELECT code INTO vDmsTypeCode FROM dmsType WHERE NEW.dmsTypeFk = id; IF (vDmsTypeCode ='ticket') THEN UPDATE ticket SET isSigned = 1 WHERE id = NEW.reference; @@ -27380,31 +27561,31 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` - BEFORE UPDATE ON `dms` - FOR EACH ROW -BEGIN - DECLARE vHardCopyNumber INT; - - IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) - OR - (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN - - IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN - SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); - END IF; - - SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber - FROM dms - WHERE warehouseFk = NEW.warehouseFk; - - SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); - END IF; - - IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN - - SET NEW.hasFile = 0; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` + BEFORE UPDATE ON `dms` + FOR EACH ROW +BEGIN + DECLARE vHardCopyNumber INT; + + IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) + OR + (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); + END IF; + + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms + WHERE warehouseFk = NEW.warehouseFk; + + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); + END IF; + + IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN + + SET NEW.hasFile = 0; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -27423,14 +27604,14 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeDelete` BEFORE DELETE ON `dms` FOR EACH ROW -BEGIN +BEGIN DECLARE vCanNotBeDeleted INT; - SELECT COUNT(*) INTO vCanNotBeDeleted - FROM dmsType dt - WHERE NOT (code <=> 'trash') + SELECT COUNT(*) INTO vCanNotBeDeleted + FROM dmsType dt + WHERE NOT (code <=> 'trash') AND dt.id = OLD.dmsTypeFk; - - IF vCanNotBeDeleted THEN + + IF vCanNotBeDeleted THEN CALL util.throw('A dms can not be deleted'); END IF; END */;; @@ -27513,6 +27694,20 @@ CREATE TABLE `docuwareConfig` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `docuwareTablet` +-- + +DROP TABLE IF EXISTS `docuwareTablet`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `docuwareTablet` ( + `tablet` varchar(100) NOT NULL, + `description` varchar(255) DEFAULT NULL, + PRIMARY KEY (`tablet`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `dua` -- @@ -28005,7 +28200,7 @@ BEGIN END IF; IF NOT (NEW.travelFk <=> OLD.travelFk) - OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN + OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); END IF; END */;; @@ -28471,11 +28666,11 @@ CREATE TABLE `expedition` ( /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeInsert` BEFORE INSERT ON `expedition` @@ -28486,17 +28681,17 @@ BEGIN SET NEW.editorFk = account.myUser_getId(); - IF NEW.freightItemFk IS NOT NULL THEN + IF NEW.freightItemFk IS NOT NULL THEN UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk; - SELECT IFNULL(MAX(counter),0) +1 INTO intcounter - FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id - LEFT JOIN ticketState ts ON ts.ticket = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + SELECT IFNULL(MAX(counter),0) +1 INTO intcounter + FROM expedition e + INNER JOIN ticket t1 ON e.ticketFk = t1.id + LEFT JOIN ticketState ts ON ts.ticketFk = t1.id + INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) AND t1.warehouseFk = t2.warehouseFk - WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk + WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk AND t1.agencyModeFk = t2.agencyModeFk; SET NEW.`counter` = intcounter; @@ -28523,9 +28718,9 @@ BEGIN SET NEW.editorFk = account.myUser_getId(); IF NEW.counter <> OLD.counter THEN - IF (SELECT COUNT(*) FROM expedition e + IF (SELECT COUNT(*) FROM expedition e INNER JOIN ticket t1 ON e.ticketFk = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) WHERE t1.id = NEW.ticketFk AND counter = NEW.counter) > 0 THEN SET NEW.id = NULL; END IF; @@ -28549,11 +28744,11 @@ DELIMITER ;; BEFORE DELETE ON `expedition` FOR EACH ROW BEGIN - UPDATE ticket t - SET packages = (SELECT COUNT(counter)-1 + UPDATE ticket t + SET packages = (SELECT COUNT(counter)-1 FROM expedition e WHERE e.ticketFk = OLD.ticketFk and e.freightItemFk) - WHERE t.id = OLD.ticketFk; - + WHERE t.id = OLD.ticketFk; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -28692,13 +28887,13 @@ DELIMITER ;; BEGIN DECLARE vNewPosition INT; - + SELECT MAX(position) + 1 INTO vNewPosition FROM vn.expeditionPallet WHERE truckFk = NEW.truckFk; - + SET NEW.position = IFNULL(vNewPosition,1); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -28797,7 +28992,7 @@ DELIMITER ;; BEGIN SET NEW.workerFk = vn.getUser(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -28882,7 +29077,7 @@ BEGIN UPDATE vn.expedition e SET e.stateTypeFk = NEW.typeFk WHERE e.id = NEW.expeditionFk; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -29110,7 +29305,7 @@ CREATE TABLE `expense` ( `isWithheld` tinyint(4) NOT NULL DEFAULT 0, `code` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `expense_UN` (`code`) + UNIQUE KEY `expence_UN` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29794,9 +29989,9 @@ CREATE TABLE `invoiceCorrection` ( KEY `invoiceCorrectionTypeFk_idx` (`invoiceCorrectionTypeFk`), CONSTRAINT `corrected_fk` FOREIGN KEY (`correctedFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `correcting_fk` FOREIGN KEY (`correctingFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `cplusInvoiceTyoeFk` FOREIGN KEY (`siiTypeInvoiceOutFk`) REFERENCES `siiTypeInvoiceOut` (`id`) ON UPDATE CASCADE, - CONSTRAINT `invoiceCorrectionType_Fk33` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `invoiceCorrectionType` (`id`) ON UPDATE CASCADE, - CONSTRAINT `invoiceCorrection_ibfk_1` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `cplusRectificationType` (`id`) ON UPDATE CASCADE + CONSTRAINT `cplusRectificationType_FK` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `cplusRectificationType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceCorrectionType_FK` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `invoiceCorrectionType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `siiTypeInvoiceOut_FK` FOREIGN KEY (`siiTypeInvoiceOutFk`) REFERENCES `siiTypeInvoiceOut` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Relacion entre las facturas rectificativas y las rectificadas.'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29878,12 +30073,12 @@ CREATE TABLE `invoiceIn` ( KEY `recibida_ibfk_6` (`cplusRectificationTypeFk`), KEY `recibida_ibfk_7` (`siiTrascendencyInvoiceInFk`), KEY `invoiceIn_withholdingFk_idx` (`withholdingSageFk`), - KEY `invoiceIn_expenseFkDeductible_idx` (`expenseFkDeductible`), + KEY `invoiceIn_expenceFkDeductible_idx` (`expenseFkDeductible`), KEY `invoiceIn_fk_editor` (`editorFk`), KEY `invoiceIn_FK` (`currencyFk`), CONSTRAINT `invoiceInCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_FK` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON UPDATE CASCADE, - CONSTRAINT `invoiceIn_expenseFkDeductible` FOREIGN KEY (`expenseFkDeductible`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceIn_expenceFkDeductible` FOREIGN KEY (`expenseFkDeductible`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `invoiceIn_ibfk_3` FOREIGN KEY (`cplusSubjectOpFk`) REFERENCES `cplusSubjectOp` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceIn_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `cplusTaxBreak` (`id`) ON UPDATE CASCADE, @@ -29914,42 +30109,42 @@ BEGIN DECLARE vWithholdingSageFk INT; SET NEW.editorFk = account.myUser_getId(); - - SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier + + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier WHERE id = NEW.supplierFk; - SET NEW.withholdingSageFk = vWithholdingSageFk; - - SELECT countryFk, isActive INTO vIssuingCountry, vActive - FROM vn.supplier + SET NEW.withholdingSageFk = vWithholdingSageFk; + + SELECT countryFk, isActive INTO vIssuingCountry, vActive + FROM vn.supplier WHERE id = NEW.supplierFk; - - SELECT countryFk INTO vhostCountry - FROM vn.supplier + + SELECT countryFk INTO vhostCountry + FROM vn.supplier WHERE id = NEW.companyFk; IF vActive = 0 THEN CALL util.throw('INACTIVE_PROVIDER'); END IF; - - IF (SELECT COUNT(*) FROM vn.invoiceIn - WHERE supplierRef = NEW.supplierRef - AND supplierFk = NEW.supplierFk + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk AND YEAR(issued) = YEAR(NEW.issued) ) THEN CALL util.throw('reference duplicated'); END IF; - + SELECT CASE WHEN (SELECT account FROM vn.supplier where id = NEW.supplierFk) LIKE '___3______' THEN 'C' - WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' - WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' + WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' WHEN (SELECT vIssuingCountry<>vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry - where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' + where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' END INTO vSerie; - + SET NEW.serial = IFNULL(vSerie,'R'); END */;; @@ -29976,9 +30171,9 @@ BEGIN SET NEW.editorFk = account.myUser_getId(); - IF (SELECT COUNT(*) FROM vn.invoiceIn - WHERE supplierRef = NEW.supplierRef - AND supplierFk = NEW.supplierFk + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk AND YEAR(issued) = YEAR(NEW.issued) AND id <> NEW.id ) THEN @@ -29988,7 +30183,7 @@ BEGIN IF NEW.supplierFk != OLD.supplierFk THEN CALL supplier_checkIsActive(NEW.supplierFk); SELECT withholdingSageFk INTO vWithholdingSageFk - FROM vn.supplier + FROM vn.supplier WHERE id = NEW.supplierFk; SET NEW.withholdingSageFk = vWithholdingSageFk; END IF; @@ -30013,23 +30208,23 @@ DELIMITER ;; FOR EACH ROW BEGIN - IF NEW.issued != OLD.issued + IF NEW.issued != OLD.issued OR NEW.currencyFk != OLD.currencyFk THEN UPDATE invoiceInTax iit JOIN invoiceIn ii ON ii.id = iit.invoiceInFk LEFT JOIN referenceRate rr ON rr.dated = ii.issued - AND rr.currencyFk = ii.currencyFk + AND rr.currencyFk = ii.currencyFk SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value) WHERE ii.id = NEW.id; - + UPDATE invoiceInDueDay iidd JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk LEFT JOIN referenceRate rr ON rr.dated = ii.issued - AND rr.currencyFk = ii.currencyFk + AND rr.currencyFk = ii.currencyFk SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value) - WHERE ii.id = NEW.id; - + WHERE ii.id = NEW.id; + END IF; END */;; @@ -30124,13 +30319,13 @@ BEGIN DECLARE vIsNotified BOOLEAN; SET NEW.editorFk = account.myUser_getId(); - - SELECT isNotified INTO vIsNotified - FROM vn.invoiceIn ii + + SELECT isNotified INTO vIsNotified + FROM vn.invoiceIn ii JOIN vn.supplier s ON s.id = ii.supplierFk JOIN vn.payMethod pm ON pm.id = s.payMethodFk WHERE ii.id = NEW.invoiceInFk; - + IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) THEN CALL mail_insert( @@ -30138,12 +30333,12 @@ BEGIN 'begonya@verdnatura.es', 'Añadido vencimiento en el pasado', CONCAT( - account.myUser_getName(), ' ha añadido un vencimiento de ', + account.myUser_getName(), ' ha añadido un vencimiento de ', NEW.amount, '€ en una fecha pasada en la recibida ', NEW.invoiceInFk ) ); END IF; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -30166,13 +30361,13 @@ BEGIN DECLARE vIsNotified BOOLEAN; SET NEW.editorFk = account.myUser_getId(); - - SELECT isNotified INTO vIsNotified - FROM vn.invoiceIn ii + + SELECT isNotified INTO vIsNotified + FROM vn.invoiceIn ii JOIN vn.supplier s ON s.id = ii.supplierFk JOIN vn.payMethod pm ON pm.id = s.payMethodFk WHERE ii.id = NEW.invoiceInFk; - + IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) THEN CALL mail_insert( @@ -30180,12 +30375,12 @@ BEGIN 'begonya@verdnatura.es', 'Añadido vencimiento en el pasado', CONCAT( - account.myUser_getName(), ' ha añadido un vencimiento de ', + account.myUser_getName(), ' ha añadido un vencimiento de ', NEW.amount,'€ en una fecha pasada en la recibida ',NEW.invoiceInFk ) ); END IF; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -30294,7 +30489,7 @@ CREATE TABLE `invoiceInSage` ( KEY `invoiceInSage_taxTypeSageFk` (`taxTypeSageFk`), KEY `invoiceInSage_transactionTypeSageFk` (`transactionTypeSageFk`), KEY `invoiceInSage_idx` (`expenseFk`), - CONSTRAINT `invoiceInSage_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInSage_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_invoiceInSerialFk` FOREIGN KEY (`invoiceInSerialFk`) REFERENCES `invoiceInSerial` (`code`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_taxClassFk` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`code`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_taxTypeSageFk` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`) ON UPDATE CASCADE, @@ -30348,7 +30543,7 @@ CREATE TABLE `invoiceInTax` ( KEY `invoiceInTax_transactionTypeSageFk_idx` (`transactionTypeSageFk`), KEY `invoiceInTax_idx` (`expenseFk`), KEY `invoiceInTax_fk_editor` (`editorFk`), - CONSTRAINT `invoiceInTax_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `invoiceInTax_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInTax_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `invoiceInTax_ibfk_5` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInTax_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, @@ -30389,7 +30584,7 @@ DELIMITER ;; BEFORE UPDATE ON `invoiceInTax` FOR EACH ROW BEGIN - IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN + IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); END IF; @@ -30629,10 +30824,10 @@ CREATE TABLE `invoiceOutExpense` ( `expenseFk` varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, `created` timestamp NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), - KEY `invoiceOutExpense_FK_1_idx` (`invoiceOutFk`), - KEY `invoiceOutExpense_expenseFk_idx` (`expenseFk`), - CONSTRAINT `invoiceOutExpense_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `invoiceOutExpense_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE + KEY `invoiceOutExpence_FK_1_idx` (`invoiceOutFk`), + KEY `invoiceOutExpence_expenceFk_idx` (`expenseFk`), + CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `invoiceOutExpence_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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 */; @@ -30793,11 +30988,11 @@ CREATE TABLE `item` ( KEY `item_size_IDX` (`size`) USING BTREE, KEY `item_size_IDX2` (`longName`) USING BTREE, KEY `item_lastUsed_IDX` (`lastUsed`) USING BTREE, - KEY `item_expenseFk_idx` (`expenseFk`), + KEY `item_expenceFk_idx` (`expenseFk`), KEY `item_fk_editor` (`editorFk`), CONSTRAINT `item_FK` FOREIGN KEY (`genericFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `item_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `itemType` (`id`), - CONSTRAINT `item_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, + CONSTRAINT `item_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_family` FOREIGN KEY (`family`) REFERENCES `itemFamily` (`code`) ON UPDATE CASCADE, CONSTRAINT `item_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `item_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `origin` (`id`) ON UPDATE CASCADE, @@ -31328,15 +31523,15 @@ BEGIN IF NEW.itemFk IN (95, 98) THEN SET NEW.cm3 = 0; END IF; - + IF !(NEW.cm3delivery <=> OLD.cm3delivery) THEN INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id + SELECT r.id FROM vn.itemCost ic JOIN vn.sale s ON s.itemFk = ic.itemFk - JOIN vn.ticket t ON t.id = s.ticketFk AND t.warehouseFk = ic.warehouseFk + JOIN vn.ticket t ON t.id = s.ticketFk AND t.warehouseFk = ic.warehouseFk JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE + WHERE r.isOk = FALSE AND ic.itemFk = NEW.itemFk AND r.created >= util.VN_CURDATE() GROUP BY r.id; @@ -31659,10 +31854,10 @@ DELIMITER ;; BEFORE INSERT ON `itemShelving` FOR EACH ROW BEGIN - + SET NEW.userFk = account.myUser_getId(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -31764,8 +31959,8 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_DELETE` BEFORE DELETE ON `itemShelving` FOR EACH ROW -INSERT INTO vn.itemShelvingLog(itemShelvingFk, - workerFk, +INSERT INTO vn.itemShelvingLog(itemShelvingFk, + workerFk, accion, shelvingFk, itemFk) @@ -31950,7 +32145,7 @@ DELIMITER ;; BEGIN UPDATE vn.sale - SET isPicked = TRUE + SET isPicked = TRUE WHERE id = NEW.saleFk; END */;; @@ -32041,20 +32236,6 @@ SET character_set_client = utf8; 1 AS `removed` */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `itemShelvingStock_byWarehouse` --- - -DROP TABLE IF EXISTS `itemShelvingStock_byWarehouse`; -/*!50001 DROP VIEW IF EXISTS `itemShelvingStock_byWarehouse`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `itemShelvingStock_byWarehouse` AS SELECT - 1 AS `itemFk`, - 1 AS `visible`, - 1 AS `warehouseFk` */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `itemTag` -- @@ -32140,9 +32321,9 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_beforeUpdate` BEFORE UPDATE ON `itemTag` FOR EACH ROW -BEGIN +BEGIN SET NEW.editorFk = account.myUser_getId(); - + IF !(OLD.`value` <=> NEW.`value`) OR !(OLD.intValue <=> NEW.intValue) THEN SET NEW.intValue = itemTag_getIntValue(NEW.`value`); @@ -32175,7 +32356,7 @@ trig: BEGIN IF @isTriggerDisabled OR visTriggerDisabled THEN LEAVE trig; END IF; - + SET vItemFk = NEW.itemFk; DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item @@ -32682,7 +32863,7 @@ DELIMITER ;; BEFORE INSERT ON `machine` FOR EACH ROW BEGIN - + SET NEW.workerFk = vn.getUser(); END */;; @@ -32816,9 +32997,9 @@ DELIMITER ;; BEGIN IF NEW.sender IS NOT NULL THEN - + SET NEW.receiver = NEW.sender; - + END IF; END */;; @@ -32881,8 +33062,8 @@ DELIMITER ;; FOR EACH ROW BEGIN IF (NEW.code IS NULL) THEN - SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT - FROM information_schema.TABLES + SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT + FROM information_schema.TABLES WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); END IF; END */;; @@ -33218,6 +33399,24 @@ CREATE TABLE `mrwServiceWeekday` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de los servicios en relación con el día de la semana para MRW'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `negativeOrigin` +-- + +DROP TABLE IF EXISTS `negativeOrigin`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `negativeOrigin` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `itemFk` int(11) NOT NULL, + `type` enum('FALTAS','CONTENEDOR','ENTRADAS','OVERBOOKING') NOT NULL, + `dated` date DEFAULT curdate(), + `quantity` decimal(10,2) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_constraint` (`itemFk`,`type`,`dated`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `newBornSales` -- @@ -33322,10 +33521,12 @@ CREATE TABLE `operator` ( KEY `operator_FK_2` (`itemPackingTypeFk`), KEY `operator_FK_3` (`warehouseFk`), KEY `operator_FK_5` (`labelerFk`), + KEY `operator_FK_4` (`sectorFk`), CONSTRAINT `operator_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `operator_FK_1` FOREIGN KEY (`trainFk`) REFERENCES `train` (`id`) ON UPDATE CASCADE, CONSTRAINT `operator_FK_2` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `operator_FK_3` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `operator_FK_4` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON UPDATE CASCADE, CONSTRAINT `operator_FK_5` FOREIGN KEY (`labelerFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -33987,7 +34188,7 @@ DELIMITER ;; BEGIN -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -34112,13 +34313,13 @@ BEGIN SELECT account INTO cuenta_banco FROM bank WHERE id = NEW.bankFk; - + SELECT account INTO cuenta_proveedor FROM supplier WHERE id = NEW.supplierFk; - + CALL vn.ledger_next(vNewBookEntry); - + INSERT INTO XDiario ( ASIEN, FECHA, SUBCTA, @@ -34144,7 +34345,7 @@ BEGIN cuenta_banco CONTRA, NEW.amount EURODEBE, 0 EUROHABER) gf; - + IF NEW.bankingFees <> 0 THEN INSERT INTO XDiario ( ASIEN, FECHA, @@ -34166,7 +34367,7 @@ BEGIN FROM supplier s JOIN country c ON s.countryFk = c.id WHERE s.id = NEW.supplierFk; - END IF; + END IF; END IF; SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received); @@ -34174,15 +34375,15 @@ BEGIN SELECT isActive INTO isSupplierActive FROM supplier WHERE id = NEW.supplierFk; - + IF isSupplierActive = FALSE THEN CALL util.throw('SUPPLIER_INACTIVE'); END IF; - + IF ISNULL(NEW.workerFk) THEN SET NEW.workerFk = account.myUser_getId(); END IF; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -34204,12 +34405,12 @@ DELIMITER ;; BEGIN DECLARE vIsPayMethodChecked BOOLEAN; DECLARE vEmail VARCHAR(150); - + SELECT isPayMethodChecked INTO vIsPayMethodChecked FROM supplier WHERE id = NEW.supplierFk; - - + + IF vIsPayMethodChecked = FALSE THEN SELECT notificationEmail INTO vEmail @@ -34966,9 +35167,12 @@ CREATE TABLE `productionConfig` ( `orderMode` enum('Location','Age') NOT NULL DEFAULT 'Location', `stockScopeDays` int(11) DEFAULT 1 COMMENT 'Días a futuro al revisar el stock', `shortageAddressFk` int(11) DEFAULT NULL COMMENT 'Consignatario por defecto para añadir un item de alta', + `clientSelfConsumptionFk` int(11) DEFAULT NULL COMMENT 'Cliente para crear el ticket de autoconsumo', PRIMARY KEY (`id`), KEY `productionConfig_FK` (`shortageAddressFk`), - CONSTRAINT `productionConfig_FK` FOREIGN KEY (`shortageAddressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE + KEY `productionConfig_FK_1` (`clientSelfConsumptionFk`), + CONSTRAINT `productionConfig_FK` FOREIGN KEY (`shortageAddressFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, + CONSTRAINT `productionConfig_FK_1` FOREIGN KEY (`clientSelfConsumptionFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Recoge los parámetros que condicionan la producción'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -35122,11 +35326,11 @@ DELIMITER ;; BEFORE INSERT ON projectNotes FOR EACH ROW BEGIN - + IF ISNULL(NEW.userFk) THEN - + SET NEW.userFk = account.myUser_getId(); - + END IF; END */;; @@ -35288,10 +35492,10 @@ DELIMITER ;; BEFORE INSERT ON `province` FOR EACH ROW BEGIN - + SET NEW.geoFk = zoneGeo_new('province', NEW.`name`, (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); - + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); END */;; @@ -35312,14 +35516,14 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_beforeUpdate` BEFORE UPDATE ON `province` FOR EACH ROW -BEGIN - +BEGIN + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN - + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); END IF; - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35335,19 +35539,19 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate` - AFTER UPDATE ON `province` - FOR EACH ROW -BEGIN - IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN - CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); - END IF; - - IF !(OLD.`name` <=> NEW.`name`) THEN - UPDATE zoneGeo SET `name` = NEW.`name` - WHERE id = NEW.geoFk; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate` + AFTER UPDATE ON `province` + FOR EACH ROW +BEGIN + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35367,7 +35571,7 @@ DELIMITER ;; AFTER DELETE ON `province` FOR EACH ROW BEGIN - CALL zoneGeo_delete(OLD.geoFk); + CALL zoneGeo_delete(OLD.geoFk); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35591,20 +35795,20 @@ CREATE TABLE `receipt` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert` - BEFORE INSERT ON `receipt` - FOR EACH ROW -BEGIN - DECLARE vIsAutoConciliated BOOLEAN; - - IF NEW.isConciliate = FALSE THEN - SELECT isAutoConciliated INTO vIsAutoConciliated - FROM accounting a - JOIN accountingType at2 ON at2.id = a.accountingTypeFk - WHERE a.id = NEW.bankFk; - - SET NEW.isConciliate = vIsAutoConciliated; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert` + BEFORE INSERT ON `receipt` + FOR EACH ROW +BEGIN + DECLARE vIsAutoConciliated BOOLEAN; + + IF NEW.isConciliate = FALSE THEN + SELECT isAutoConciliated INTO vIsAutoConciliated + FROM accounting a + JOIN accountingType at2 ON at2.id = a.accountingTypeFk + WHERE a.id = NEW.bankFk; + + SET NEW.isConciliate = vIsAutoConciliated; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35660,18 +35864,18 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` - AFTER UPDATE ON `receipt` - FOR EACH ROW -BEGIN - IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN - CALL mail_insert( - 'finanzas@verdnatura.es', - NULL, - CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), - CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) - ); - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` + AFTER UPDATE ON `receipt` + FOR EACH ROW +BEGIN + IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN + CALL mail_insert( + 'finanzas@verdnatura.es', + NULL, + CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), + CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) + ); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35955,6 +36159,23 @@ SET character_set_client = utf8; 1 AS `hasLogin` */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `roleCreditLimit` +-- + +DROP TABLE IF EXISTS `roleCreditLimit`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `roleCreditLimit` ( + `id` int(11) NOT NULL, + `maxAmount` int(10) unsigned NOT NULL, + `roleFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `clientCreditLimit_FK_idx` (`roleFk`), + CONSTRAINT `roleCreditLimit_FK` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `route` -- @@ -35965,6 +36186,7 @@ DROP TABLE IF EXISTS `route`; CREATE TABLE `route` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `workerFk` int(10) unsigned DEFAULT NULL, + `firstEditorFk` int(10) unsigned NOT NULL COMMENT 'Usuario creador de la ruta', `created` date NOT NULL, `vehicleFk` int(10) unsigned DEFAULT NULL, `agencyModeFk` int(11) DEFAULT NULL, @@ -36017,13 +36239,16 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vDefaultAgencyModeFk INT; + DECLARE vUserFk INT ; - SET NEW.editorFk = account.myUser_getId(); - + SET vUserFk = account.myUser_getId(); + SET NEW.editorFk = vUserFk; + SET NEW.firstEditorFk = vUserFk; + SET NEW.commissionWorkCenterFk = ( SELECT IFNULL(b.workCenterFK, r.defaultWorkCenterFk) FROM vn.routeConfig r - LEFT JOIN vn.business b ON b.workerFk = account.myUser_getId() + LEFT JOIN vn.business b ON b.workerFk = vUserFk AND NEW.created BETWEEN b.started AND IFNULL(b.ended, NEW.created)); IF ISNULL(NEW.agencyModeFk) THEN @@ -36031,7 +36256,7 @@ BEGIN FROM routeDefaultAgencyMode r JOIN business b ON b.workCenterFk = r.workCenterFK JOIN worker w ON w.businessFk = b.id - WHERE b.workerFk = account.myUser_getId(); + WHERE b.workerFk = vUserFk; SET NEW.agencyModeFk = vDefaultAgencyModeFk; END IF; @@ -36053,7 +36278,7 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterInsert` AFTER INSERT ON `route` FOR EACH ROW -BEGIN +BEGIN CALL route_calcCommission(NEW.id); END */;; DELIMITER ; @@ -36075,16 +36300,16 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vKmMax INT; - + SET NEW.editorFk = account.myUser_getId(); - + IF NEW.isOk <> FALSE AND OLD.isOk = FALSE THEN - SET NEW.m3 = ( SELECT SUM(litros)/1000 - FROM vn.saleVolume s - JOIN vn.ticket t ON s.ticketFk = t.id + SET NEW.m3 = ( SELECT SUM(litros)/1000 + FROM vn.saleVolume s + JOIN vn.ticket t ON s.ticketFk = t.id WHERE t.routeFk = NEW.id); END IF; - + IF NEW.kmEnd < NEW.kmStart AND NEW.kmEnd <> 0 THEN CALL util.throw ('KmEnd menor que kmStart'); END IF; @@ -36114,18 +36339,18 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterUpdate` AFTER UPDATE ON `route` FOR EACH ROW -BEGIN +BEGIN IF IFNULL(NEW.gestdocFk,0) <> IFNULL(OLD.gestdocFk,0) AND NEW.gestdocFk > 0 THEN -- JGF 09/09/14 cuando se añade un gestdoc a una ruta, se le asigna automagicamente a todos sus Tickets - + -- Inserta el gestdoc en todos los tickets de la ruta INSERT INTO ticketDms(ticketFk,dmsFk) SELECT id, NEW.gestdocFk FROM ticket WHERE routeFk = NEW.id ON DUPLICATE KEY UPDATE dmsFk = NEW.gestdocFk; - -- Update del firmado - UPDATE ticket t - JOIN ticketDms tg ON t.id = tg.ticketFk + -- Update del firmado + UPDATE ticket t + JOIN ticketDms tg ON t.id = tg.ticketFk SET isSigned = 1 WHERE t.routeFk = NEW.id; END IF; @@ -36195,6 +36420,7 @@ CREATE TABLE `routeCommission` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `routeFk` int(10) unsigned NOT NULL, `workCenterFk` int(11) DEFAULT NULL, + `firstEditorFk` int(10) unsigned NOT NULL COMMENT 'Usuario creador de la ruta', `km` decimal(5,2) DEFAULT NULL, `m3` decimal(5,2) DEFAULT NULL, `yearlyKm` decimal(5,2) DEFAULT NULL, @@ -36205,6 +36431,7 @@ CREATE TABLE `routeCommission` ( PRIMARY KEY (`id`), KEY `routeCommission_routeFk_idx` (`routeFk`), KEY `routeCommission_workCenterFk_idx` (`workCenterFk`), + KEY `routeCommission_firstEditorFk` (`firstEditorFk`), CONSTRAINT `routeCommission_routeFk` FOREIGN KEY (`routeFk`) REFERENCES `route` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `routeCommission_workCenterFk` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; @@ -36334,7 +36561,7 @@ CREATE TABLE `routeLog` ( `action` set('insert','update','delete') NOT NULL, `creationDate` timestamp NULL DEFAULT current_timestamp(), `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, - `changedModel` enum('Route') NOT NULL DEFAULT 'Route', + `changedModel` enum('Route','RoutesMonitor') NOT NULL DEFAULT 'Route', `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), `changedModelId` int(11) NOT NULL, @@ -36436,15 +36663,84 @@ CREATE TABLE `routesMonitor` ( `m3boxes` decimal(10,1) DEFAULT NULL, `bufferFk` int(11) DEFAULT NULL COMMENT 'Buffer del sorter por el que se quiere sacar esa ruta', `isPickingAllowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Los tickets de esta ruta se pueden preparar', + `editorFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`routeFk`), KEY `routesMonitor_FK` (`bufferFk`), KEY `routesMonitor_FK_2` (`beachFk`), KEY `routesMonitor_FK_1` (`dockFk`), + KEY `routesMonitor_FK_3` (`expeditionTruckFk`), + KEY `routesMonitor_fk_editor` (`editorFk`), CONSTRAINT `routesMonitor_FK` FOREIGN KEY (`bufferFk`) REFERENCES `srt`.`buffer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `routesMonitor_FK_1` FOREIGN KEY (`dockFk`) REFERENCES `dock` (`code`) ON UPDATE CASCADE, - CONSTRAINT `routesMonitor_FK_2` FOREIGN KEY (`beachFk`) REFERENCES `beach` (`code`) ON UPDATE CASCADE + CONSTRAINT `routesMonitor_FK_2` FOREIGN KEY (`beachFk`) REFERENCES `beach` (`code`) ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_FK_3` FOREIGN KEY (`expeditionTruckFk`) REFERENCES `expeditionTruck` (`id`) ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routesMonitor_beforeInsert` + BEFORE INSERT ON `routesMonitor` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routesMonitor_beforeUpdate` + BEFORE UPDATE ON `routesMonitor` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routesMonitor_afterDelete` + AFTER DELETE ON `routesMonitor` + FOR EACH ROW +BEGIN + INSERT INTO routeLog + SET `action` = 'delete', + `changedModel` = 'RoutesMonitor', + `changedModelId` = OLD.routeFk, + `userFk` = account.myUser_getId(); +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 `sale` @@ -36541,11 +36837,6 @@ BEGIN AND r.created >= util.VN_CURDATE() GROUP BY r.id; END IF; - - IF NEW.quantity = 0 THEN - CALL util.debugAdd('saleZeroQuantity', - CONCAT('[', user(), ']', ' Inserted sale: ', NEW.id)); - END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36565,20 +36856,20 @@ DELIMITER ;; BEFORE UPDATE ON `sale` FOR EACH ROW BEGIN -/* +/* IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN CALL util.throw('Cannot insert a service item into a ticket'); END IF; */ SET NEW.editorFk = account.myUser_getId(); - + IF NEW.discount > 100 THEN SET NEW.discount = 0; END IF; IF old.discount > 0 AND NEW.discount = 0 THEN INSERT INTO ticketLog - SET originFk = NEW.ticketFk, userFk = account.myUser_getId(), `action` = 'insert', + SET originFk = NEW.ticketFk, userFk = account.myUser_getId(), `action` = 'insert', description = CONCAT('Cambio de descuento del item :', ' ', new.itemFk, ' de ', old.discount ,' a 0 '); END IF; END */;; @@ -36684,11 +36975,6 @@ BEGIN JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk SET c.saleTotalCount = c.saleTotalCount + IF(OLD.quantity = 0, 1, -1); END IF; - - IF NEW.quantity = 0 THEN - CALL util.debugAdd('saleZeroQuantity', - CONCAT('[', user(), ']', ' Updated sale: ', NEW.id)); - END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36710,11 +36996,11 @@ DELIMITER ;; BEGIN IF OLD.quantity > 0 THEN INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id + SELECT r.id FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.route r ON r.id = t.routeFk - WHERE r.isOk = FALSE + WHERE r.isOk = FALSE AND s.id = OLD.id AND r.created >= util.VN_CURDATE() GROUP BY r.id; @@ -36816,10 +37102,10 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`BEFORE_INSERT` BEFORE INSERT ON `saleBuy` FOR EACH ROW -BEGIN - +BEGIN + SET NEW.workerFk = vn.getUser(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36838,13 +37124,13 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleBuy_AI` AFTER INSERT ON `saleBuy` FOR EACH ROW -BEGIN +BEGIN /* Activar de nuevo cuando volvamos a vender fruta y verdura - * + * UPDATE vn.sale s SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk) WHERE s.id = NEW.saleFk; -*/ +*/ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -37110,14 +37396,14 @@ DELIMITER ;; AFTER INSERT ON `saleTracking` FOR EACH ROW BEGIN - - IF NEW.isChecked THEN - + + IF NEW.isChecked THEN + UPDATE vn.sale s - SET s.isPicked = TRUE + SET s.isPicked = TRUE WHERE s.id = NEW.saleFk AND s.isPicked = 0; - + END IF; END */;; @@ -37394,9 +37680,7 @@ CREATE TABLE `sector` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) NOT NULL, `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 1, - `isPreviousPreparedByPacking` tinyint(4) NOT NULL DEFAULT 1, `code` varchar(15) DEFAULT NULL, - `isPreviousPrepared` tinyint(1) NOT NULL DEFAULT 0, `isPackagingArea` tinyint(1) NOT NULL DEFAULT 0, `reportFk` tinyint(3) unsigned DEFAULT NULL, `sonFk` int(11) DEFAULT NULL, @@ -37406,12 +37690,15 @@ CREATE TABLE `sector` ( `isHideForPickers` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'sector a ocultar a los sacadores', `isReserve` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Sectores de reserva, como Albenfruit o Fuentes', `mainPrinterFk` tinyint(3) unsigned DEFAULT NULL, + `typeFk` int(10) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`), KEY `sector_fk1_idx` (`warehouseFk`), KEY `sector_report` (`reportFk`), KEY `sector_FK` (`sonFk`,`warehouseFk`), KEY `sector_FK_1` (`mainPrinterFk`), + KEY `sectorType_FK` (`typeFk`), + CONSTRAINT `sectorType_FK` FOREIGN KEY (`typeFk`) REFERENCES `sectorType` (`id`) ON UPDATE CASCADE, CONSTRAINT `sector_FK_1` FOREIGN KEY (`mainPrinterFk`) REFERENCES `printer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sector_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sector_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) @@ -37482,6 +37769,20 @@ CREATE TABLE `sectorProductivity` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `sectorType` +-- + +DROP TABLE IF EXISTS `sectorType`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sectorType` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `description` varchar(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `sendingConfig` -- @@ -37565,9 +37866,9 @@ BEGIN IF NEW.workerFk = NEW.workerSubstitute THEN CALL util.throw ('worker and workerSubstitute must be different'); ELSE - INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) - SELECT NEW.workerFk, NEW.workerSubstitute, dated - FROM time + INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) + SELECT NEW.workerFk, NEW.workerSubstitute, dated + FROM time WHERE dated BETWEEN NEW.started AND NEW.ended; END IF; END */;; @@ -37592,14 +37893,14 @@ BEGIN IF NEW.workerFk = NEW.workerSubstitute THEN CALL util.throw ('worker and workerSubstitute must be different'); ELSE - DELETE sc FROM sharingCartDaily sc - WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND - sc.ownerFk = OLD.workerFk AND + DELETE sc FROM sharingCartDaily sc + WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND + sc.ownerFk = OLD.workerFk AND sc.substituteFk = OLD.workerSubstitute; - - INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) - SELECT NEW.workerFk, NEW.workerSubstitute, dated - FROM time + + INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) + SELECT NEW.workerFk, NEW.workerSubstitute, dated + FROM time WHERE dated BETWEEN NEW.started AND NEW.ended; END IF; @@ -37622,9 +37923,9 @@ DELIMITER ;; BEFORE DELETE ON `sharingCart` FOR EACH ROW BEGIN - DELETE sc FROM sharingCartDaily sc - WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND - sc.ownerFk = OLD.workerFk AND + DELETE sc FROM sharingCartDaily sc + WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND + sc.ownerFk = OLD.workerFk AND sc.substituteFk = OLD.workerSubstitute; END */;; DELIMITER ; @@ -38070,7 +38371,7 @@ DELIMITER ;; FOR EACH ROW BEGIN UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditClassification cc ON c.Id_Cliente = cc.client JOIN creditInsurance ci ON ci.creditClassification = cc.id SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance; END */;; @@ -38094,12 +38395,12 @@ DELIMITER ;; BEGIN IF NEW.dateLeaving IS NOT NULL THEN UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditClassification cc ON c.Id_Cliente = cc.client JOIN creditInsurance ci ON ci.creditClassification = cc.id SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; ELSE UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditClassification cc ON c.Id_Cliente = cc.client JOIN creditInsurance ci ON ci.creditClassification = cc.id SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance; END IF; @@ -38123,7 +38424,7 @@ DELIMITER ;; FOR EACH ROW BEGIN UPDATE vn2008.Clientes c - JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditClassification cc ON c.Id_Cliente = cc.client JOIN creditInsurance ci ON ci.creditClassification = cc.id SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; END */;; @@ -39338,7 +39639,7 @@ DELIMITER ;; AFTER INSERT ON `ticket` FOR EACH ROW BEGIN - + DECLARE vClientType VARCHAR(255); DECLARE vStateCode VARCHAR(255); DECLARE vTransferorFirstShipped DATE; @@ -39366,7 +39667,7 @@ BEGIN INSERT INTO bs.clientNewBorn(clientFk, firstShipped, lastShipped) VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, util.VN_CURDATE()), util.VN_CURDATE()) ON DUPLICATE KEY UPDATE lastShipped = util.VN_CURDATE(); - + END IF; END */;; @@ -39389,6 +39690,7 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vNewTime TIME; + DECLARE vHasTicketRefund BOOL; SET NEW.editorFk = account.myUser_getId(); @@ -39448,6 +39750,15 @@ BEGIN CALL vn.routeUpdateM3(NEW.routeFk); END IF; + + SELECT COUNT(*) INTO vHasTicketRefund + FROM ticketRefund + WHERE originalTicketFk = NEW.id + OR refundTicketFk = NEW.id; + + IF vHasTicketRefund AND NEW.clientFk <> OLD.clientFk THEN + CALL util.throw('The ticket has a refund associated'); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -39481,7 +39792,7 @@ BEGIN END IF; IF NEW.routeFk <> OLD.routeFk THEN - UPDATE expedition + UPDATE expedition SET hasNewRoute = TRUE WHERE ticketFk = NEW.id; END IF; @@ -39504,11 +39815,11 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeDelete` BEFORE DELETE ON `ticket` FOR EACH ROW -BEGIN - INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) - SELECT r.id +BEGIN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id FROM vn.route r - WHERE r.isOk = FALSE + WHERE r.isOk = FALSE AND r.id = OLD.routeFk AND r.created >= util.VN_CURDATE() GROUP BY r.id; @@ -39585,31 +39896,31 @@ CREATE TABLE `ticketCollection` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete -AFTER DELETE -ON ticketCollection FOR EACH ROW -BEGIN - - DECLARE vSalesRemaining INT; - - SELECT count(*) INTO vSalesRemaining - FROM vn.ticketCollection tc - JOIN sale s ON s.ticketFk = tc.ticketFk - WHERE collectionFk = OLD.collectionFk - AND tc.id != OLD.id; - - IF NOT vSalesRemaining THEN - - DELETE FROM vn.collection WHERE id = OLD.collectionFk; - - ELSE - - UPDATE vn.collection - SET saleTotalCount = vSalesRemaining - WHERE id = OLD.collectionFk; - - END IF; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete +AFTER DELETE +ON ticketCollection FOR EACH ROW +BEGIN + + DECLARE vSalesRemaining INT; + + SELECT count(*) INTO vSalesRemaining + FROM vn.ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE collectionFk = OLD.collectionFk + AND tc.id != OLD.id; + + IF NOT vSalesRemaining THEN + + DELETE FROM vn.collection WHERE id = OLD.collectionFk; + + ELSE + + UPDATE vn.collection + SET saleTotalCount = vSalesRemaining + WHERE id = OLD.collectionFk; + + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -39707,13 +40018,13 @@ DELIMITER ;; BEFORE DELETE ON `ticketDms` FOR EACH ROW BEGIN - UPDATE dms - SET dmsTypeFk = (SELECT id - FROM dmsType + UPDATE dms + SET dmsTypeFk = (SELECT id + FROM dmsType WHERE `code` = 'trash' ) - WHERE id = OLD.dmsFk AND ( SELECT IF(COUNT(*) > 0, FALSE, TRUE) - FROM ticketDms + WHERE id = OLD.dmsFk AND ( SELECT IF(COUNT(*) > 0, FALSE, TRUE) + FROM ticketDms WHERE dmsFk = OLD.dmsFk ) ; END */;; @@ -40189,7 +40500,7 @@ DELIMITER ;; BEGIN SET NEW.workerFk = vn.getUser(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40517,7 +40828,7 @@ DELIMITER ;; BEGIN CALL ticket_requestRecalc(NEW.ticketFk); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40587,7 +40898,7 @@ BEGIN `changedModel` = 'TicketService', `changedModelId` = OLD.id, `userFk` = account.myUser_getId(); - + CALL ticket_requestRecalc(OLD.ticketFk); END */;; @@ -40609,8 +40920,8 @@ CREATE TABLE `ticketServiceType` ( `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL, `expenseFk` varchar(10) NOT NULL DEFAULT '7050000000', PRIMARY KEY (`id`), - KEY `ticketServiceType_expenseFk_idx` (`expenseFk`), - CONSTRAINT `ticketServiceType_expenseFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE + KEY `ticketServiceType_expenceFk_idx` (`expenseFk`), + CONSTRAINT `ticketServiceType_expenceFk` FOREIGN KEY (`expenseFk`) REFERENCES `expense` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Lista de los posibles servicios a elegir'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -40642,14 +40953,12 @@ SET character_set_client = utf8; /*!50001 CREATE VIEW `ticketState` AS SELECT 1 AS `updated`, 1 AS `stateFk`, - 1 AS `workerFk`, + 1 AS `userFk`, 1 AS `ticketFk`, 1 AS `state`, 1 AS `productionOrder`, 1 AS `alertLevel`, 1 AS `code`, - 1 AS `ticket`, - 1 AS `worker`, 1 AS `isPreviousPreparable`, 1 AS `isPicked` */; SET character_set_client = @saved_cs_client; @@ -40687,11 +40996,11 @@ CREATE TABLE `ticketTracking` ( `notes` varchar(255) DEFAULT NULL, `created` timestamp NULL DEFAULT current_timestamp(), `ticketFk` int(11) DEFAULT NULL, - `workerFk` int(10) unsigned DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, `supervisorFk` int(10) unsigned DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), - KEY `currante` (`workerFk`), + KEY `currante` (`userFk`), KEY `responsable` (`supervisorFk`), KEY `ticket` (`ticketFk`), KEY `inter_state` (`stateFk`), @@ -40700,7 +41009,7 @@ CREATE TABLE `ticketTracking` ( KEY `ticketTracking_created_IDX` (`created`) USING BTREE, CONSTRAINT `inter_state` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE, CONSTRAINT `responsable` FOREIGN KEY (`supervisorFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, - CONSTRAINT `ticketTracking_FK3` FOREIGN KEY (`workerFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, + CONSTRAINT `ticketTracking_FK3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, CONSTRAINT `ticketTracking_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `ticketTracking_ibfk_1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; @@ -40739,11 +41048,11 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vNumTicketsPrepared INT; - + REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) SELECT NEW.ticketFk, NEW.id, `name` FROM state - WHERE id = NEW.stateFk; + WHERE id = NEW.stateFk; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40786,21 +41095,21 @@ BEGIN DECLARE vTicketFk INT; DECLARE vTicketTrackingFk INT; DECLARE vStateName VARCHAR(15); - + IF NEW.stateFk <> OLD.stateFk THEN REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) SELECT NEW.ticketFk, NEW.id, `name` FROM state WHERE id = NEW.stateFk; END IF; - + IF NEW.ticketFk <> OLD.ticketFk THEN SELECT i.ticketFk, i.id, s.`name` - INTO vTicketFk, vTicketTrackingFk, vStateName - FROM ticketTracking i - JOIN state s ON i.stateFk = s.id - WHERE ticketFk = NEW.ticketFk - ORDER BY created DESC + INTO vTicketFk, vTicketTrackingFk, vStateName + FROM ticketTracking i + JOIN state s ON i.stateFk = s.id + WHERE ticketFk = NEW.ticketFk + ORDER BY created DESC LIMIT 1; IF vTicketFk > 0 THEN @@ -40842,18 +41151,18 @@ BEGIN `changedModel` = 'TicketTracking', `changedModelId` = OLD.id, `userFk` = account.myUser_getId(); - + CALL util.debugAdd('deletedState', CONCAT('interFk: ', OLD.id, ' ticketFk: ', OLD.ticketFk, ' stateFk: ', OLD.stateFk)); SELECT i.ticketFk, i.id, s.`name` - INTO vTicketFk, vTicketTrackingFk, vStateName - FROM ticketTracking i - JOIN state s ON i.stateFk = s.id - WHERE ticketFk = OLD.ticketFk - ORDER BY created DESC + INTO vTicketFk, vTicketTrackingFk, vStateName + FROM ticketTracking i + JOIN state s ON i.stateFk = s.id + WHERE ticketFk = OLD.ticketFk + ORDER BY created DESC LIMIT 1; IF vTicketFk > 0 THEN @@ -41459,16 +41768,16 @@ 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_beforeUpdate` BEFORE UPDATE ON `travel` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); - +/* IF ((NOT NEW.shipped <=> OLD.shipped ) OR (NOT NEW.landed <=> OLD.landed ) OR (NOT NEW.warehouseInFk <=> OLD.warehouseInFk ) @@ -41476,7 +41785,7 @@ BEGIN AND (OLD.totalEntries AND OLD.landed < CURDATE()) THEN CALL util.throw("Cannot past travels with entries"); END IF; - +*/ IF NOT (NEW.landed <=> OLD.landed) OR NOT (NEW.shipped <=> OLD.shipped) THEN CALL travel_checkDates(NEW.shipped, NEW.landed); @@ -41520,7 +41829,7 @@ BEGIN CALL stock.log_add('travel', NEW.id, OLD.id); IF !(NEW.shipped <=> OLD.shipped) THEN - UPDATE entry + UPDATE entry SET commission = entry_getCommission(travelFk, currencyFk,supplierFk) WHERE travelFk = NEW.id; END IF; @@ -41800,7 +42109,10 @@ CREATE TABLE `userConfig` ( `created` timestamp NULL DEFAULT current_timestamp(), `updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), `darkMode` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Salix interface dark mode', - PRIMARY KEY (`userFk`) + `tabletFk` varchar(100) DEFAULT NULL, + PRIMARY KEY (`userFk`), + KEY `tabletFk` (`tabletFk`), + CONSTRAINT `userConfig_ibfk_1` FOREIGN KEY (`tabletFk`) REFERENCES `docuwareTablet` (`tablet`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Configuración de usuario en Salix'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -42085,7 +42397,10 @@ CREATE TABLE `viaexpressConfig` ( `password` varchar(100) NOT NULL, `defaultWeight` decimal(10,2) NOT NULL, `deliveryType` varchar(5) NOT NULL, - PRIMARY KEY (`id`) + `agencyModeFk` int(11) DEFAULT NULL COMMENT 'Indica el agencyMode que es interdia', + PRIMARY KEY (`id`), + KEY `viaexpressConfig_agencyMode_Fk` (`agencyModeFk`), + CONSTRAINT `viaexpressConfig_agencyMode_Fk` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -43232,9 +43547,9 @@ DELIMITER ;; AFTER INSERT ON `workerTimeControl` FOR EACH ROW BEGIN - IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN + IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN CALL util.throw('date in the future'); - END IF; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43509,7 +43824,7 @@ CREATE TABLE `zone` ( `hour` datetime NOT NULL, `agencyModeFk` int(11) NOT NULL, `travelingDays` int(11) NOT NULL DEFAULT 1, - `price` double NOT NULL DEFAULT 0, + `price` double NOT NULL DEFAULT 0 CHECK (`price` > 0), `bonus` double NOT NULL DEFAULT 0, `isVolumetric` tinyint(1) NOT NULL DEFAULT 0, `inflation` decimal(5,2) NOT NULL DEFAULT 1.00, @@ -43649,13 +43964,12 @@ SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `zoneEstimatedDelivery` AS SELECT 1 AS `zoneFk`, - 1 AS `hourTheoretical`, - 1 AS `totalVolume`, - 1 AS `remainingVolume`, - 1 AS `speed`, - 1 AS `hourEffective`, - 1 AS `minutesLess`, - 1 AS `etc` */; + 1 AS `zoneClosureHour`, + 1 AS `zoneHour`, + 1 AS `volume`, + 1 AS `hasToRecalcPrice`, + 1 AS `m3`, + 1 AS `minSpeed` */; SET character_set_client = @saved_cs_client; -- @@ -43785,10 +44099,10 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_BI` BEFORE INSERT ON `zoneExclusion` FOR EACH ROW -BEGIN +BEGIN SET NEW.editorFk = account.myUser_getId(); SET NEW.userFk = account.myUser_getId(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43807,10 +44121,10 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_BU` BEFORE UPDATE ON `zoneExclusion` FOR EACH ROW -BEGIN +BEGIN SET NEW.editorFk = account.myUser_getId(); SET NEW.userFk = account.myUser_getId(); - + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -44209,8 +44523,8 @@ DELIMITER ;; FROM client c LEFT JOIN ticket t ON t.clientFk = c.id WHERE c.salesPersonFk IS NOT NULL - OR t.created > util.VN_CURDATE() - INTERVAL 2 MONTH - OR shipped > util.VN_CURDATE() - INTERVAL 2 MONTH + OR t.created > util.VN_CURDATE() - INTERVAL 2 MONTH + OR shipped > util.VN_CURDATE() - INTERVAL 2 MONTH ); END */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; @@ -44223,14 +44537,14 @@ 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 = utf8mb3 */ ;; -/*!50003 SET character_set_results = utf8mb3 */ ;; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ;; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`jgallego`@`%`*/ /*!50106 EVENT `client_unassignSalesPerson` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:30:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL client_unassignSalesPerson */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `client_unassignSalesPerson` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:30:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO CALL client_unassignSalesPerson */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44348,9 +44662,9 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `itemImageQueue_check` ON SCHEDULE EVERY 1 HOUR STARTS '2023-07-28 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN - DELETE FROM itemImageQueue - WHERE attempts >= (SELECT downloadMaxAttempts FROM itemConfig); +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `itemImageQueue_check` ON SCHEDULE EVERY 1 HOUR STARTS '2023-07-28 00:00:00' ON COMPLETION PRESERVE DISABLE ON SLAVE DO BEGIN + DELETE FROM itemImageQueue + WHERE attempts >= (SELECT downloadMaxAttempts FROM itemConfig); END */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; @@ -44715,7 +45029,7 @@ BEGIN DECLARE vGeoFk INT; SELECT p.geoFk INTO vGeoFk - FROM address a + FROM address a JOIN town t ON t.provinceFk = a.provinceFk JOIN postCode p ON p.townFk = t.id AND p.`code` = a.postalCode WHERE a.id = vSelf @@ -44742,12 +45056,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `barcodeToItem`(vBarcode VARCHAR(22)) RETURNS int(11) DETERMINISTIC BEGIN - + /** * Obtiene el id del artículo * * @param vBarcode código de barras - * + * * return id del item */ @@ -44757,35 +45071,35 @@ BEGIN FROM vn.item WHERE id = vBarcode OR comment = vBarcode LIMIT 1; - - IF vItemFk THEN + + IF vItemFk THEN RETURN vItemFk; END IF; - SELECT itemFk INTO vItemFk - FROM buy + SELECT itemFk INTO vItemFk + FROM buy WHERE id = vBarcode; - - IF vItemFk THEN + + IF vItemFk THEN RETURN vItemFk; END IF; - - SELECT itemFk INTO vItemFk - FROM itemBarcode + + SELECT itemFk INTO vItemFk + FROM itemBarcode WHERE code = vBarcode; - - IF vItemFk THEN + + IF vItemFk THEN RETURN vItemFk; END IF; - SELECT i.id INTO vItemFk + SELECT i.id INTO vItemFk FROM vn.item i WHERE i.name LIKE CONCAT('%',vBarcode,'%') ORDER BY i.id ASC LIMIT 1; - + RETURN vItemFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -44849,7 +45163,7 @@ BEGIN DECLARE vItem INT; DECLARE vPackaging VARCHAR(10); - SELECT itemFk, packageFk INTO vItem, vPackaging + SELECT itemFk, packagingFk INTO vItem, vPackaging FROM buy WHERE id = vSelf; @@ -44878,16 +45192,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `catalog_componentReverse`(vWarehouse DETERMINISTIC BEGIN /* Calcula los componentes para un cliente a partir de un coste y volumen - * @param vWarehouse + * @param vWarehouse * @param vCost Valor de coste del articulo * @param vM3 m3 del articulo - * @param vAddressFk + * @param vAddressFk * @param vZoneFk - * @return vRetailedPrice precio de venta sin iva + * @return vRetailedPrice precio de venta sin iva * @return tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) */ - - DECLARE vBoxVolume BIGINT; + + DECLARE vBoxVolume BIGINT; DECLARE vCustomer INT; DECLARE vComponentRecovery INT DEFAULT 17; DECLARE vComponentMana INT DEFAULT 39; @@ -44896,11 +45210,11 @@ BEGIN DECLARE vComponentCost INT DEFAULT 28; DECLARE vRetailedPrice DECIMAL(10,2); DECLARE vItem INT DEFAULT 98; - + SELECT volume INTO vBoxVolume FROM vn.packaging WHERE id = '94'; - + SELECT clientFk INTO vCustomer FROM address WHERE id = vAddressFk; DROP TEMPORARY TABLE IF EXISTS tmp.catalog_component; @@ -44924,7 +45238,7 @@ BEGIN -- Margen -- No se aplica margen, cau 12589 /* INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) - SELECT vWarehouse, vItem, vComponentMargin, (vCost / ((100 - rate2) / 100)) - vCost + SELECT vWarehouse, vItem, vComponentMargin, (vCost / ((100 - rate2) / 100)) - vCost FROM vn.rate WHERE dated <= util.VN_CURDATE() AND warehouseFk = vWarehouse @@ -44933,7 +45247,7 @@ BEGIN */ -- Recobro INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) - SELECT vWarehouse, vItem, vComponentRecovery, ROUND(LEAST(recobro,0.25), 3) + SELECT vWarehouse, vItem, vComponentRecovery, ROUND(LEAST(recobro,0.25), 3) FROM bi.claims_ratio WHERE Id_Cliente = vCustomer AND recobro > 0.009; @@ -44950,7 +45264,7 @@ BEGIN ROUND( vM3 * (z.price - z.bonus) - * z.inflation + * z.inflation / vBoxVolume, 4 ) FROM zone z @@ -45044,7 +45358,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `clientTaxArea`(vClientId INT, vCompa READS SQL DATA BEGIN /** -* Devuelve el area de un cliente, +* Devuelve el area de un cliente, * intracomunitario, extracomunitario o nacional. * * @param vClient Id del cliente @@ -45077,37 +45391,37 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getDebt`(`vClient` INT, `vDate` DATE) RETURNS decimal(10,2) READS SQL DATA -BEGIN -/** - * Returns the risk of a customer. - * - * @param vClient client id - * @param vDate date to check the risk - * @return Client risk - */ - DECLARE vDebt DECIMAL(10,2); - DECLARE vHasDebt BOOLEAN; - - SELECT COUNT(*) INTO vHasDebt - FROM `client` c - WHERE c.id = vClient AND c.typeFk = 'normal'; - - IF NOT vHasDebt THEN - RETURN 0; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt (clientFk INT); - INSERT INTO tmp.clientGetDebt SET clientFk = vClient; - - CALL vn.client_getDebt(vDate); - - SELECT risk INTO vDebt FROM tmp.risk; - - DROP TEMPORARY TABLE - tmp.clientGetDebt, - tmp.risk; - - RETURN vDebt; +BEGIN +/** + * Returns the risk of a customer. + * + * @param vClient client id + * @param vDate date to check the risk + * @return Client risk + */ + DECLARE vDebt DECIMAL(10,2); + DECLARE vHasDebt BOOLEAN; + + SELECT COUNT(*) INTO vHasDebt + FROM `client` c + WHERE c.id = vClient AND c.typeFk = 'normal'; + + IF NOT vHasDebt THEN + RETURN 0; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt (clientFk INT); + INSERT INTO tmp.clientGetDebt SET clientFk = vClient; + + CALL vn.client_getDebt(vDate); + + SELECT risk INTO vDebt FROM tmp.risk; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.risk; + + RETURN vDebt; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45183,8 +45497,8 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `client_getSalesPerson`(vClientFk INT 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 + * 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 @@ -45222,29 +45536,29 @@ BEGIN l: LOOP SELECT workerSubstitute INTO vWorkerSubstituteFk - FROM sharingCart + FROM sharingCart WHERE util.VN_CURDATE() BETWEEN started AND ended AND workerFk = vSalesPersonFk ORDER BY id LIMIT 1; - + IF vWorkerSubstituteFk IS NULL THEN LEAVE l; END IF; - + SELECT COUNT(*) > 0 INTO vLoop FROM tmp.stack WHERE substitute = vWorkerSubstituteFk; IF vLoop THEN LEAVE l; END IF; - + INSERT INTO tmp.stack SET substitute = vWorkerSubstituteFk; - + SET vSalesPersonFk = vWorkerSubstituteFk; END LOOP; - + DROP TEMPORARY TABLE tmp.stack; END IF; @@ -45278,11 +45592,11 @@ BEGIN **/ DECLARE vClientFk INT; DECLARE vDated DATE; - + SELECT clientFk, shipped INTO vClientFk, vDated FROM ticket WHERE id = vTicketFk; - + RETURN client_getSalesPerson(vClientFk, vDated); END ;; DELIMITER ; @@ -45313,12 +45627,12 @@ BEGIN **/ DECLARE vWorkerCode CHAR(3); DECLARE vSalesPersonFk INT; - + SET vSalesPersonFk = client_getSalesPerson(vClientFk, vDated); SELECT code INTO vWorkerCode - FROM worker + FROM worker WHERE id = vSalesPersonFk; RETURN vWorkerCode; @@ -45351,11 +45665,11 @@ BEGIN **/ DECLARE vClientFk INT; DECLARE vDated DATE; - + SELECT clientFk, shipped INTO vClientFk, vDated FROM ticket WHERE id = vTicketFk; - + RETURN client_getSalesPersonCode(vClientFk, vDated); END ;; DELIMITER ; @@ -45365,6 +45679,38 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `client_hasDifferentCountries` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `client_hasDifferentCountries`(vClientFk INT) RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Return if client have address in different countries. + * + * @param vClientFk The id client + * @return BOOL + **/ + RETURN (SELECT COUNT(DISTINCT c.id) > 1 + FROM `address` a + JOIN province p ON p.id = a.provinceFk + JOIN country c ON c.id = p.countryFk + WHERE a.clientFk = vClientFk + AND a.isActive); + +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `collection_isPacked` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45447,7 +45793,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `currentRate`(vCurrencyFk INT, vDated BEGIN DECLARE curRate DECIMAL(10,4); - + SELECT value INTO curRate FROM referenceRate WHERE dated <= vDated @@ -45478,23 +45824,23 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `deviceProductionUser_accessGranted`( BEGIN /* * Comprueba si el usuario puede entrar en la aplicacion de almacen con ese movil - * + * * */ - + /*DECLARE vIsGranted BOOLEAN; DECLARE vDeviceProductionFk INT(11) DEFAULT NULL; - SELECT dp.id INTO vDeviceProductionFk - FROM vn.deviceProduction dp + SELECT dp.id INTO vDeviceProductionFk + FROM vn.deviceProduction dp WHERE dp.android_id = android_id; IF vDeviceProductionFk THEN - - SELECT COUNT(*) INTO vIsGranted - FROM vn.deviceProductionUser dpu - WHERE dpu.userFk = vUserFK + + SELECT COUNT(*) INTO vIsGranted + FROM vn.deviceProductionUser dpu + WHERE dpu.userFk = vUserFK AND dpu.deviceProductionFk = vDeviceProductionFk; - + RETURN vIsGranted; END IF;*/ RETURN TRUE; @@ -45519,7 +45865,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `duaTax_getRate`(vDuaFk INT, vTaxClas BEGIN /** * Devuelve el rate para un Dua teniendo en cuenta la fecha de opreción del DUA - * + * * @param vDuaFk Identificador de la tabla dua * @param vTaxClassFk Identificador del IVA de la tabla invoiceInTaxBookingAccount */ @@ -45553,24 +45899,24 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getEntry`(vEktFk INT) RETURNS in READS SQL DATA BEGIN /** - * Devuelve el numero de entrada para el ekt - * + * Devuelve el numero de entrada para el ekt + * * @param vEktFk Identificador de edi.ekt - */ + */ DECLARE vTravelFk INT; DECLARE vEntryFk INT DEFAULT 0; DECLARE vEntryAssignFk INT; - SELECT ea.id + SELECT ea.id INTO vEntryAssignFk FROM edi.ekt e - JOIN vn.ektEntryAssign ea ON + JOIN vn.ektEntryAssign ea ON IFNULL(ea.sub, e.sub) <=> e.sub AND IFNULL(ea.kop, e.kop) <=> e.kop AND IFNULL(ea.pro, e.pro) <=> e.pro AND IFNULL(ea.auction, e.auction) <=> e.auction WHERE e.id = vEktFk - ORDER BY + ORDER BY IF(ea.sub,1,0) * 1000 + IF(ea.kop,1,0) * 100 + IF(ea.pro,1,0) * 10 + @@ -45581,7 +45927,7 @@ BEGIN IF vTravelFk THEN - SELECT MAX(e.id) + SELECT MAX(e.id) INTO vEntryFk FROM vn.entry e JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk @@ -45596,13 +45942,13 @@ BEGIN INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, reference, pro, auction) SELECT vTravelFk, ea.supplierFk, ea.companyFk, cu.id, ea.kop, ea.sub, ea.ref, ea.pro, ea.auction FROM vn.ektEntryAssign ea - JOIN vn.currency cu ON cu.code = 'EUR' + JOIN vn.currency cu ON cu.code = 'EUR' WHERE ea.id = vEntryAssignFk; SET vEntryFk = LAST_INSERT_ID(); END IF; - UPDATE vn.ektEntryAssign + UPDATE vn.ektEntryAssign SET entryFk = vEntryFk WHERE id = vEntryAssignFk; @@ -45636,7 +45982,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getTravel`(vEntryAssignFk INT, v BEGIN /** * Devuelve un vn.travel.id - * + * * @param vEntryAssignFk Identificador de vn.entryAssign */ DECLARE vTravelFk INT; @@ -45697,36 +46043,36 @@ BEGIN DECLARE vCurrentCommission INT; DECLARE vIsCurrencyUsd INT; DECLARE vLastEntryFk INT; - + SELECT count(*) INTO vIsCurrencyUsd FROM currency c WHERE c.code = 'USD' AND id = vCurrencyFk; - + IF NOT vIsCurrencyUsd THEN - + SELECT e.id INTO vLastEntryFk FROM vn.entry e JOIN vn.travel tr ON tr.id = e.travelFk WHERE e.supplierFk = vSupplierFk ORDER BY tr.landed DESC LIMIT 1; - + IF vLastEntryFk THEN - + SELECT commission INTO vCurrentCommission FROM vn.entry WHERE id = vLastEntryFk; - + ELSE - + SELECT commission INTO vCurrentCommission FROM supplier s WHERE s.id = vSupplierFk; - + END IF; - + RETURN vCurrentCommission; - + ELSE SELECT ROUND(-100 * (1 - (1 / r.value))) INTO vCommission @@ -45735,11 +46081,11 @@ BEGIN WHERE t.id = vTravelFk ORDER BY r.`dated` DESC LIMIT 1; - + RETURN IFNULL(vCommission, 0); - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45790,10 +46136,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getForLogiflora`(vLanded DATE, vWarehouseFk INT) RETURNS int(11) READS SQL DATA BEGIN - + /** * Devuelve una entrada para Logiflora. Si no existe la crea. - * + * * @param vLanded Fecha de llegada al almacén * @param vWarehouseFk Identificador de vn.warehouse */ @@ -45801,51 +46147,51 @@ BEGIN DECLARE vTravelFk INT; DECLARE vEntryFk INT; DECLARE previousEntryFk INT; - + SET vTravelFk = vn.travel_getForLogiflora(vLanded, vWarehouseFk); - + IF vLanded THEN - - SELECT IFNULL(MAX(id),0) INTO vEntryFk + + SELECT IFNULL(MAX(id),0) INTO vEntryFk FROM vn.entry - WHERE travelFk = vTravelFk + WHERE travelFk = vTravelFk AND isRaid; IF NOT vEntryFk THEN - + INSERT INTO vn.entry(travelFk, supplierFk, commission, companyFk, currencyFk, isRaid) SELECT vTravelFk, s.id, 4, c.id, cu.id, TRUE FROM vn.supplier s JOIN vn.company c ON c.code = 'VNL' JOIN vn.currency cu ON cu.code = 'EUR' WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; - - SELECT MAX(id) INTO vEntryFk + + SELECT MAX(id) INTO vEntryFk FROM vn.entry WHERE travelFk = vTravelFk; - + END IF; + + END IF; - END IF; - - SELECT entryFk INTO previousEntryFk + SELECT entryFk INTO previousEntryFk FROM edi.warehouseFloramondo wf WHERE wf.warehouseFk = vWarehouseFk; - + IF IFNULL(previousEntryFk,0) != vEntryFk THEN - - UPDATE buy b - SET b.printedStickers = 0 + + UPDATE buy b + SET b.printedStickers = 0 WHERE entryFk = previousEntryFk; DELETE FROM buy WHERE entryFk = previousEntryFk; - + DELETE FROM entry WHERE id = previousEntryFk; - + END IF; - + RETURN vEntryFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45878,21 +46224,21 @@ BEGIN SELECT IFNULL(a.isUeeMember, c.isUeeMember), c.id INTO vIsUeeSupplier, vSupplierCountry - FROM entry e - JOIN supplier s ON s.id = e.supplierFk - JOIN country c ON c.id = s.countryFk + FROM entry e + JOIN supplier s ON s.id = e.supplierFk + JOIN country c ON c.id = s.countryFk LEFT JOIN province p ON p.id = s.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk WHERE e.id = vSelf; - + SELECT IFNULL(a.isUeeMember, c.isUeeMember), c.id INTO vIsUeeCompany, vCompanyCountry - FROM entry e - JOIN supplier s ON s.id = e.companyFk - JOIN country c ON c.id = s.countryFk + FROM entry e + JOIN supplier s ON s.id = e.companyFk + JOIN country c ON c.id = s.countryFk LEFT JOIN province p ON p.id = s.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk - WHERE e.id = vSelf; + WHERE e.id = vSelf; RETURN vIsUeeCompany AND vIsUeeSupplier AND (vSupplierCountry <> vCompanyCountry); @@ -45957,17 +46303,17 @@ BEGIN DECLARE vHasDistinctRoutes BOOL; SELECT t.routeFk INTO vRouteFk - FROM vn.expedition e + FROM vn.expedition e JOIN vn.ticket t ON e.ticketFk = t.id WHERE e.id = vExpeditionFk; - + SELECT COUNT(*) > 0 INTO vHasDistinctRoutes FROM vn.expeditionScan es JOIN vn.expedition e ON es.expeditionFk = e.id JOIN vn.ticket t ON e.ticketFk = t.id WHERE es.palletFk = vPalletFk AND t.routeFk <> vRouteFk; - + RETURN vHasDistinctRoutes; END ;; @@ -46028,27 +46374,27 @@ BEGIN DECLARE vDeliveryType INTEGER DEFAULT 0; DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; DECLARE vCode VARCHAR(45); - + SELECT am.deliveryMethodFk - INTO vDeliveryType + INTO vDeliveryType FROM ticket t JOIN agencyMode am ON am.id = t.agencyModeFk WHERE t.id = vTicket; - + CASE vDeliveryType WHEN 1 THEN -- AGENCIAS SET vCode = 'DELIVERED'; - + WHEN 2 THEN -- REPARTO SET vCode = 'ON_DELIVERY'; - + ELSE -- MERCADO, OTROS SELECT MIN(t.warehouseFk <> w.id) INTO isWaitingForPickUp - FROM ticket t + FROM ticket t LEFT JOIN warehouse w ON w.pickUpagencyModeFk = t.agencyModeFk WHERE t.id = vTicket; - + IF isWaitingForPickUp THEN SET vCode = 'WAITING_FOR_PICKUP'; ELSE @@ -46078,28 +46424,28 @@ BEGIN DECLARE vDeliveryType INTEGER DEFAULT 0; DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; DECLARE vCode VARCHAR(45); - - SELECT + + SELECT a.Vista - INTO vDeliveryType + INTO vDeliveryType FROM vn2008.Tickets t JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia WHERE Id_Ticket = vTicket; - + CASE vDeliveryType WHEN 1 THEN -- AGENCIAS SET vCode = 'DELIVERED'; - + WHEN 2 THEN -- REPARTO SET vCode = 'ON_DELIVERY'; - + ELSE -- MERCADO, OTROS SELECT t.warehouse_id <> w.warehouse_id INTO isWaitingForPickUp - FROM vn2008.Tickets t - LEFT JOIN vn2008.warehouse_pickup w + FROM vn2008.Tickets t + LEFT JOIN vn2008.warehouse_pickup w ON w.agency_id = t.Id_Agencia AND w.warehouse_id = t.warehouse_id WHERE t.Id_Ticket = vTicket; - + IF isWaitingForPickUp THEN SET vCode = 'WAITING_FOR_PICKUP'; ELSE @@ -46153,8 +46499,8 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getInventoryDate`() RETURNS date DETERMINISTIC -BEGIN - RETURN vn2008.date_inv(); +BEGIN + RETURN (SELECT inventoried FROM config LIMIT 1); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46207,16 +46553,16 @@ BEGIN DECLARE vReturn DATE; DECLARE vDuaDate DATE; DECLARE vDuaDateDay INT; - + SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate; IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN - SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); + SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN - SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); + SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); END IF; - IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN + IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN IF util.isLeapYear(YEAR(vDuaDate)) THEN SET vPayDay = 29; ELSE @@ -46224,7 +46570,7 @@ BEGIN END IF; END IF; - SELECT DAY(vDuaDate) INTO vDuaDateDay; + SELECT DAY(vDuaDate) INTO vDuaDateDay; RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay))); END ;; DELIMITER ; @@ -46246,11 +46592,11 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `getShipmentHour`(vTicket INT) RETURN READS SQL DATA BEGIN DECLARE vShipmentHour INT; - + SELECT HOUR(shipped) INTO vShipmentHour FROM ticket WHERE id = vTicket; - + IF vShipmentHour = 0 THEN DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer; @@ -46265,11 +46611,11 @@ BEGIN JOIN agencyMode am on am.id = t.agencyModeFk JOIN address a on a.id = t.addressFk WHERE t.id = vTicket; - - SELECT Hora INTO vShipmentHour + + SELECT Hora INTO vShipmentHour FROM tmp.production_buffer; END IF; - + RETURN vShipmentHour; END ;; DELIMITER ; @@ -46294,12 +46640,12 @@ BEGIN SELECT rate3 INTO price FROM vn.priceFixed - WHERE itemFk = vItemFk + WHERE itemFk = vItemFk AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; - SELECT `value` INTO price + SELECT `value` INTO price FROM vn.specialPrice - WHERE itemFk = vItemFk + WHERE itemFk = vItemFk AND clientFk = vClientFk ; RETURN price; END ;; @@ -46323,7 +46669,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `getTicketTrolleyLabelCount`(vTicket BEGIN DECLARE vLabelCount INT DEFAULT 0; - SELECT labelCount INTO vLabelCount + SELECT labelCount INTO vLabelCount FROM ticketTrolley WHERE ticket = vTicket; @@ -46390,48 +46736,83 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `hasAnyNegativeBase` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasAnyNegativeBase`() RETURNS tinyint(1) DETERMINISTIC BEGIN -/* Calcula si existe alguna base imponible negativa -* Requiere la tabla temporal tmp.ticketToInvoice(id) +/** +* Calcula si existe alguna base imponible negativa +* Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases() * * returns BOOLEAN */ + DECLARE hasAnyNegativeBase BOOLEAN; - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; + CALL getTaxBases(); - CALL ticket_getTax(NULL); + SELECT negative INTO hasAnyNegativeBase + FROM tmp.taxBases + LIMIT 1; - SELECT COUNT(*) INTO hasAnyNegativeBase - FROM( - SELECT SUM(taxableBase) as taxableBase - FROM tmp.ticketTax - GROUP BY pgcFk - HAVING taxableBase < 0 - ) t; - - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE + tmp.ticketTax, + tmp.ticket, + tmp.taxBases; RETURN hasAnyNegativeBase; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `hasAnyPositiveBase` */; +/*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `hasAnyPositiveBase`() RETURNS tinyint(1) + DETERMINISTIC +BEGIN + +/** +* Calcula si existe alguna base imponible positiva +* Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases() +* +* returns BOOLEAN +*/ + + DECLARE hasAnyPositiveBase BOOLEAN; + + CALL getTaxBases(); + + SELECT positive INTO hasAnyPositiveBase + FROM tmp.taxBases + LIMIT 1; + + DROP TEMPORARY TABLE + tmp.ticketTax, + tmp.ticket, + tmp.taxBases; + + RETURN hasAnyPositiveBase; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46453,17 +46834,17 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `hasItemsInSector`(vTicketFk INT, vSe BEGIN DECLARE vItemCount INT; - + SELECT count(*) INTO vItemCount - FROM vn.sale s + FROM vn.sale s JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk WHERE s.ticketFk = vTicketFk AND p.sectorFk = vSectorFk; - + RETURN vItemCount; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46486,7 +46867,7 @@ BEGIN DECLARE vCountry INT; DECLARE hasSomeNegativeBase BOOLEAN; - SELECT s.countryFk + SELECT s.countryFk INTO vCountry FROM supplier s JOIN ticket t ON t.companyFk = s.id @@ -46495,9 +46876,9 @@ BEGIN SELECT COUNT(*) INTO hasSomeNegativeBase FROM ( SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase - FROM sale s + FROM sale s JOIN item i ON i.id = s.itemFk - JOIN itemTaxCountry itc + JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = vCountry WHERE s.ticketFk = vTicket GROUP BY itc.taxClassFk @@ -46527,12 +46908,12 @@ BEGIN DECLARE totalAmount DECIMAL(10,2); SELECT SUM(vat) INTO totalAmount - FROM ( + FROM ( SELECT iot.vat FROM invoiceOutTax iot JOIN invoiceOut io ON io.id = iot.invoiceOutFk WHERE io.ref = vInvoiceRef - UNION ALL + UNION ALL SELECT ioe.amount FROM invoiceOutExpense ioe JOIN invoiceOut io ON io.id = ioe.invoiceOutFk @@ -46563,23 +46944,23 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceOut_getMaxIssued`(vSerial VAR READS SQL DATA BEGIN /** - * Retorna la fecha a partir de la cual es válido emitir una factura + * Retorna la fecha a partir de la cual es válido emitir una factura * - * @param vSerial Serie de facturación + * @param vSerial Serie de facturación * @param vCompanyFk Empresa factura emitida * @param vYear Año contable * @return vInvoiceOutIssued fecha factura válida */ DECLARE vInvoiceOutIssued DATE; DECLARE vFirstDayOfYear DATE; - + SET vFirstDayOfYear := MAKEDATE(vYear, 1); - SELECT IFNULL(MAX(io.issued), vFirstDayOfYear) INTO vInvoiceOutIssued + SELECT IFNULL(MAX(io.issued), vFirstDayOfYear) INTO vInvoiceOutIssued FROM invoiceOut io WHERE io.serial = vSerial AND io.companyFk = vCompanyFk - AND io.issued BETWEEN vFirstDayOfYear + AND io.issued BETWEEN vFirstDayOfYear AND util.lastDayOfYear(vFirstDayOfYear); RETURN vInvoiceOutIssued; @@ -46605,7 +46986,7 @@ BEGIN DECLARE vIssued DATE; DECLARE vSerial VARCHAR(15); - SELECT issued, ref + SELECT issued, ref INTO vIssued, vSerial FROM invoiceOut WHERE id = vSelf; @@ -46677,9 +47058,9 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceSerial`(vClientFk INT, vCompa DETERMINISTIC BEGIN /** - * Obtiene la serie de de una factura + * Obtiene la serie de de una factura * dependiendo del area del cliente. - * + * * @param vClientFk Id del cliente * @param vCompanyFk Id de la empresa * @param vType Tipo de factura ["R", "M", "G"] @@ -46760,18 +47141,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `isLogifloraDay`(vShipped DATE, vWarehouse INT) RETURNS tinyint(1) DETERMINISTIC BEGIN - + DECLARE vIsLogifloraDay BOOLEAN; SELECT COUNT(*) INTO vIsLogifloraDay FROM edi.warehouseFloramondo wf - JOIN vn.floramondoConfig fc + JOIN vn.floramondoConfig fc WHERE wf.warehouseFk = vWarehouse AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded)) AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded)); - + RETURN vIsLogifloraDay; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46808,7 +47189,7 @@ BEGIN WHERE sl.scan_id = vScanId AND t.Id_Ruta ) t1; - + RETURN vDistinctRoutesInThePallet = 1; END ;; DELIMITER ; @@ -46832,20 +47213,20 @@ BEGIN DECLARE vPacking INTEGER DEFAULT 0; DECLARE vItemFk INTEGER; - + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - - SELECT IFNULL(packing,0) INTO vPacking - FROM vn.buy + + SELECT IFNULL(packing,0) INTO vPacking + FROM vn.buy WHERE id = CAST(vBarcode AS DECIMAL(18,0)); - - - - + + + + IF NOT vPacking THEN CALL cache.last_buy_refresh(FALSE); SELECT IFNULL(packing,1) INTO vPacking - FROM + FROM (SELECT packing , created FROM vn.itemShelving WHERE itemFk = vItemFk @@ -46858,11 +47239,11 @@ BEGIN ) packings ORDER BY created desc LIMIT 1; - + END IF; - + RETURN vPacking; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46887,11 +47268,11 @@ BEGIN DECLARE vColumn INT; DECLARE vClosestParkingFk INT; DECLARE vSectorFk INT; - + SELECT p.column, sectorFk INTO vColumn, vSectorFk FROM vn.parking p WHERE p.id = vParkingFk; - + SELECT itemShelvingFk INTO vClosestParkingFk FROM ( @@ -46901,12 +47282,12 @@ BEGIN JOIN vn.itemPlacementSupplyList ipsl ON ipsl.sectorFk = ispss.sectorFk AND ipsl.itemFk = ispss.itemFk WHERE p.sectorFk = vSectorFk AND ipsl.saldo > 0 - ) sub + ) sub ORDER BY distance LIMIT 1; - + RETURN vClosestParkingFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -46928,17 +47309,17 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `itemsInSector_get`(vTicketFk INT, vS BEGIN DECLARE vItemCount INT; - + SELECT count(*) INTO vItemCount - FROM vn.sale s + FROM vn.sale s JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk JOIN vn.shelving sh ON sh.code = ish.shelvingFk JOIN vn.parking p ON p.id = sh.parkingFk WHERE s.ticketFk = vTicketFk AND p.sectorFk = vSectorFk; - + RETURN vItemCount; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47011,29 +47392,29 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `item_getPackage`(vItemFk INT) RETURNS varchar(50) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + DECLARE vDiameter INT; DECLARE vPackageFk VARCHAR(50); DECLARE vCoeficient DOUBLE DEFAULT 1.08; - + SELECT MAX(LEFT(value,3)) INTO vDiameter - FROM vn.itemTag it + FROM vn.itemTag it JOIN vn.tag t ON t.id = it.tagFk WHERE it.itemFk = vItemFk AND t.overwrite = 'diameter'; - + SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2))) INTO vPackageFk FROM vn.volumeConfig vc; - + INSERT IGNORE INTO vn.packaging(id, width, `depth`) - SELECT vPackageFk, - FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), + SELECT vPackageFk, + FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter)) FROM vn.volumeConfig vc; - + RETURN vPackageFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47070,7 +47451,7 @@ BEGIN FROM packaging p JOIN item i ON i.id = vSelf WHERE p.id = vPackaging; - + RETURN vVolume; END ;; @@ -47091,7 +47472,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `lastDayOfWeek`(vYear INT, vWeek INT) RETURNS date DETERMINISTIC -BEGIN +BEGIN /** * Returns the date of the last day of the week * @@ -47130,16 +47511,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `machine_checkPlate`(vPlate VARCHAR(1 BEGIN /** * Comprueba si existe matrícula - * + * * @param vPlate matrícula del vehículo * @return Devuelve TRUE en caso de que exista - * + * */ - + IF (SELECT COUNT(*) - FROM machine m + FROM machine m WHERE m.plate = vPlate - ) THEN + ) THEN RETURN TRUE; ELSE RETURN FALSE; @@ -47166,9 +47547,9 @@ BEGIN DECLARE result INT; DECLARE vSenderFk INT; - SELECT id INTO vSenderFk + SELECT id INTO vSenderFk FROM account.user WHERE `name` = account.myUser_getName(); - + RETURN (SELECT messageSendWithUser(vSenderFk, vRecipient, vMessage)); END ;; DELIMITER ; @@ -47195,9 +47576,9 @@ BEGIN DECLARE vSendDate DATETIME DEFAULT util.VN_NOW(); DECLARE vSender VARCHAR(255) CHARSET utf8; - SELECT `name` INTO vSender + SELECT `name` INTO vSender FROM account.user WHERE id = vSenderFK; - + SET vRecipient = LOWER(vRecipient); DROP TEMPORARY TABLE IF EXISTS tRecipients; @@ -47218,7 +47599,7 @@ BEGIN IF vCount = 0 THEN RETURN vCount; - END IF; + END IF; SET vUuid = UUID(); @@ -47229,7 +47610,7 @@ BEGIN message = vMessage, sendDate = vSendDate; - INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate) + INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate) SELECT vUuid, vSender, vRecipient, finalRecipient, vMessage, vSendDate FROM tRecipients; @@ -47303,7 +47684,7 @@ BEGIN -- Devuelte el volumen total de la orden sumada DECLARE vWarehouseId INTEGER; DECLARE vVolume DECIMAL(10,3); - + SELECT IFNULL(SUM(o.amount * ic.cm3delivery)/1000000,0) INTO vVolume FROM hedera.orderRow o JOIN item i ON i.id = o.itemFk @@ -47380,7 +47761,7 @@ BEGIN WHERE cb.id = packagingReturnFk; SET vValue = IF (vAmount IS NULL, - IFNULL(base,0), + IFNULL(base,0), vAmount / IFNULL(upload, 0) + IFNULL(base, 0)); ELSE SET vValue = IFNULL(price, 0) + IFNULL(base, 0); @@ -47441,20 +47822,20 @@ BEGIN DECLARE vRouteFk INT; DECLARE vAddressFk INT; - + DECLARE vLanded DATE; DECLARE vZoneFk INT; DECLARE vSignificativeFriendship INT DEFAULT 6; DECLARE vVolumeMax DECIMAL(5,1) DEFAULT 10; - + SELECT addressFk, zoneFk, landed INTO vAddressFk, vZoneFk, vLanded - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; - + -- Se inicia la selección de rutas posibles con aquellas cuyas agencias alguna vez han estado asociadas con nuestra zona DROP TEMPORARY TABLE IF EXISTS tmp.route; CREATE TEMPORARY TABLE tmp.route - SELECT r.id routeFk, + SELECT r.id routeFk, zf.friendship zoneFriendship FROM vn.route r JOIN cache.zoneAgencyFriendship zf ON zf.agencyModeFk = r.agencyModeFk @@ -47462,16 +47843,16 @@ BEGIN AND zf.zoneFk = vZoneFk AND r.created = vLanded ORDER BY friendship; - + -- Se eliminan aquellas que superan el volumen máximo DELETE r.* - FROM tmp.route r + FROM tmp.route r JOIN (SELECT routeFk, sum(volume) volume FROM vn.saleVolume WHERE landed = vLanded GROUP BY routeFk) sub ON sub.routeFk = r.routeFk WHERE sub.volume > vVolumeMax; - + -- Se ordenan las que quedan en función con la afinidad del resto de consignatarios de cada ruta SELECT routeFk INTO vRouteFk FROM @@ -47483,7 +47864,7 @@ BEGIN ORDER BY zoneFriendship DESC, friendshipSum DESC ) sub LIMIT 1; - + RETURN vRouteFk; END ;; DELIMITER ; @@ -47508,9 +47889,9 @@ BEGIN DECLARE vRouteFk INT; DECLARE vAddressFk INT; DECLARE vShipped DATETIME; - + SELECT addressFk, date(shipped) INTO vAddressFk, vShipped - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; SELECT routeFk INTO vRouteFk @@ -47524,7 +47905,7 @@ BEGIN ORDER BY friendshipSum DESC ) sub LIMIT 1; - + RETURN vRouteFk; END ;; DELIMITER ; @@ -47548,20 +47929,20 @@ BEGIN DECLARE vRouteFk INT; DECLARE vAddressFk INT; - + DECLARE vLanded DATE; DECLARE vZoneFk INT; DECLARE vSignificativeFriendship INT DEFAULT 6; DECLARE vVolumeMax DECIMAL(5,1) DEFAULT 10; - + SELECT addressFk, zoneFk, landed INTO vAddressFk, vZoneFk, vLanded - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; - + -- Se inicia la selección de rutas posibles con aquellas cuyas agencias alguna vez han estado asociadas con nuestra zona DROP TEMPORARY TABLE IF EXISTS tmp.route; CREATE TEMPORARY TABLE tmp.route - SELECT r.id routeFk, + SELECT r.id routeFk, zf.friendship zoneFriendship FROM vn.route r JOIN cache.zoneAgencyFriendship zf ON zf.agencyModeFk = r.agencyModeFk @@ -47569,16 +47950,16 @@ BEGIN AND zf.zoneFk = vZoneFk AND r.created = vLanded ORDER BY friendship; - + -- Se eliminan aquellas que superan el volumen máximo DELETE r.* - FROM tmp.route r + FROM tmp.route r JOIN (SELECT routeFk, sum(volume) volume FROM vn.saleVolume WHERE landed = vLanded GROUP BY routeFk) sub ON sub.routeFk = r.routeFk WHERE sub.volume > vVolumeMax; - + -- Se ordenan las que quedan en función con la afinidad del resto de consignatarios de cada ruta SELECT routeFk INTO vRouteFk FROM @@ -47590,7 +47971,7 @@ BEGIN ORDER BY zoneFriendship DESC, friendshipSum DESC ) sub LIMIT 1; - + RETURN vRouteFk; END ;; DELIMITER ; @@ -47611,26 +47992,26 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `specie_IsForbidden`(vItemFk INT, vAddressFk INT) RETURNS tinyint(1) READS SQL DATA BEGIN - + DECLARE vIsForbbiden BOOL; DECLARE vLeft INT; SELECT zg.lft INTO vLeft - FROM vn.address a - JOIN vn.zoneGeo zg ON zg.name = a.postalCode + FROM vn.address a + JOIN vn.zoneGeo zg ON zg.name = a.postalCode WHERE a.id = vAddressFk; - + SELECT sgi.isForbidden INTO vIsForbbiden - FROM vn.specieGeoInvasive sgi - JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk + FROM vn.specieGeoInvasive sgi + JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk JOIN vn.itemBotanical ib ON ib.genusFk = sgi.genusFk AND sgi.specieFk IN ('sp.',ib.specieFk) WHERE vLeft BETWEEN zg.lft AND zg.rgt AND ib.itemFk = vItemFk - ORDER BY zg.`depth` DESC + ORDER BY zg.`depth` DESC LIMIT 1; RETURN IFNULL(vIsForbbiden, FALSE); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47650,7 +48031,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `testCIF`(vCIF VARCHAR(9)) RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + DECLARE vLetraInicial VARCHAR(1); DECLARE vLetraFinal VARCHAR(1); DECLARE vParteNumerica VARCHAR(7); @@ -47662,60 +48043,60 @@ BEGIN SET vLetraInicial = SUBSTR(vCIF, 1, 1); SET vLetraFinal = SUBSTR(vCIF, 9, 1); SET vParteNumerica = SUBSTR(vCIF, 2, 7); - - WHILE i < 7 DO - + + WHILE i < 7 DO + SET i = i + 1; - + SET vNumero = CAST(SUBSTR(vParteNumerica, i, 1) AS DECIMAL(1,0)); - + IF i MOD 2 THEN - + SET vNumero = vNumero * 2; SET vNumero = vNumero MOD 10 + FLOOR(vNumero/10); - + END IF; - + SET vSuma = vSuma + vNumero; - + END WHILE; - + SET vSuma = vSuma MOD 10; - + IF vSuma > 0 THEN - + SET vSuma = 10 - vSuma; - + END IF; - + -- Comprobación de dígito de control IF CAST(vLetraFinal AS DECIMAL(1,0)) = vSuma THEN - + SET vResult = TRUE; - + END IF; - + IF vSuma = 0 THEN - + SET vSuma = 10; - + END IF; - + IF CHAR(64 + vSuma) = vLetraFinal THEN - + SET vResult = TRUE; - + END IF; - + -- Sólo se aceptan letras como caracter inicial IF ASCII(vLetraInicial) < 65 OR ASCII(vLetraInicial) > 87 THEN -- Ha de ser entre la A y la W - + SET vResult = FALSE; - + END IF; - + RETURN vResult; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47735,7 +48116,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `testNIE`(vNIE VARCHAR(9)) RETURNS tinyint(1) DETERMINISTIC BEGIN - + DECLARE vIndice INT; DECLARE vNumero VARCHAR(7); DECLARE vOperador VARCHAR(9); @@ -47744,45 +48125,45 @@ BEGIN DECLARE vLetraFinal VARCHAR(1); DECLARE vLetrasFinalesPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; DECLARE vLetraInicialEsIncorrecta BOOL DEFAULT FALSE; - + SET vLetraInicial = SUBSTR(vNIE, 1, 1); SET vLetraFinal = SUBSTR(vNIE, 9, 1); SET vNumero = SUBSTR(vNIE, 2, 7); CASE vLetraInicial - + WHEN 'X' THEN - + SET vOperador = "0"; - + WHEN 'Y' THEN - + SET vOperador = "1"; - + WHEN 'Z' THEN - + SET vOperador = "2"; - + ELSE - + SET vLetraInicialEsIncorrecta = TRUE; - + END CASE; - + SET vOperador = CONCAT(vOperador, vNumero); SET vParteNumerica = CAST(vOperador AS DECIMAL(8,0)); SET vIndice = Round(vParteNumerica Mod 23, 0) + 1; IF SUBSTR(vLetrasFinalesPosibles, vIndice, 1) = vLetraFinal AND vLetraInicialEsIncorrecta = FALSE THEN - + RETURN TRUE; - + ELSE - + RETURN FALSE; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47807,23 +48188,23 @@ BEGIN DECLARE vParteNumerica DECIMAL(8,0); DECLARE vLetra VARCHAR(1); DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; - + SET vLetra = SUBSTRING(vNIF, 9, 1); - + SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0)); - + SET vIndice = Round(vParteNumerica MOD 23, 0) + 1; - + If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then - + RETURN TRUE; - + ELSE - + RETURN FALSE; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47843,21 +48224,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketCollection_getNoPacked`(vCollectionFk INT) RETURNS varchar(100) CHARSET utf8mb3 COLLATE utf8mb3_unicode_ci DETERMINISTIC BEGIN - + /* * return message with tickets and collection if there is tickets of a collection without expeditions - * + * * @param vCollectionFk the collection to check * @return an array with collection and tickets without expeditions - * + * */ - + DECLARE vAnswer VARCHAR(100) DEFAULT ''; IF collection_isPacked(vCollectionFk) = FALSE THEN SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer FROM vn.ticketCollection tc - LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk WHERE tc.collectionFk = vCollectionFk AND ISNULL(e.id); END IF; @@ -47903,9 +48284,9 @@ BEGIN DROP TEMPORARY TABLE tmp.ticket, tmp.ticketTotal; - + RETURN vTotal; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -47925,7 +48306,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_general_ci DETERMINISTIC BEGIN - + DECLARE vRestTicketsMaxOrder INT; DECLARE vRestTicketsMinOrder INT; DECLARE vRestTicketsPacking INT; @@ -47937,7 +48318,7 @@ BEGIN DECLARE vExpeditionsCount INT; DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE; -SELECT `order` +SELECT `order` INTO PACKING_ORDER FROM state WHERE code = 'PACKING'; @@ -47945,10 +48326,10 @@ SELECT `order` SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0) INTO vMyPath, vMyWarehouse, vMyProductionOrder FROM ticket t - LEFT JOIN ticketState ts on ts.ticket = t.id + LEFT JOIN ticketState ts on ts.ticketFk = t.id WHERE t.id = vTicketId; -SELECT (ag.`name` = 'VN_VALENCIA') +SELECT (ag.`name` = 'VN_VALENCIA') INTO vIsValenciaPath FROM vn2008.Rutas r JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia @@ -47962,19 +48343,19 @@ IF vIsValenciaPath THEN -- Rutas Valencia FROM expedition e JOIN ticket t ON t.id = e.ticketFk WHERE t.routeFk = vMyPath; - + SELECT MAX(ts.productionOrder), MIN(ts.productionOrder) INTO vRestTicketsMaxOrder, vRestTicketsMinOrder FROM ticket t - LEFT JOIN ticketState ts on t.id = ts.ticket + LEFT JOIN ticketState ts on t.id = ts.ticketFk WHERE t.routeFk = vMyPath AND t.warehouseFk = vMyWarehouse AND t.id != vTicketid; - SELECT COUNT(*) + SELECT COUNT(*) INTO vRestTicketsPacking FROM ticket t - LEFT JOIN ticketState ts on t.id = ts.ticket + LEFT JOIN ticketState ts on t.id = ts.ticketFk WHERE ts.productionOrder = PACKING_ORDER AND t.routeFk = vMyPath AND t.warehouseFk = vMyWarehouse @@ -48026,9 +48407,9 @@ BEGIN LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id WHERE ticketFk = vTicketFk ) sub; - + RETURN IFNULL(vSplitCounter,'--'); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48077,21 +48458,21 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ticketTotalVolumeBoxes`(vTicketId IN DETERMINISTIC BEGIN -/* +/* * Devuelve el volumen estimado del ticket sumado, en cajas * * vTicketId Numero de ticket - * + * */ DECLARE vVolumeBoxM3 DOUBLE; DECLARE vTicketTotalVolumeBoxes DECIMAL(10,1); DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; - + SELECT volume / 1000000 INTO vVolumeBoxM3 FROM packaging WHERE id = vVnBoxId; - + SET vTicketTotalVolumeBoxes = ticketTotalVolume(vTicketId) / vVolumeBoxM3; - + RETURN vTicketTotalVolumeBoxes; END ;; @@ -48116,7 +48497,7 @@ BEGIN DECLARE vWarehouseFk INT; SELECT warehouseFk INTO vWarehouseFk - FROM ticket + FROM ticket WHERE id = vTicketFk; RETURN vWarehouseFk; @@ -48139,18 +48520,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_CC_volume`(vTicketFk INT) RETURNS decimal(10,1) READS SQL DATA BEGIN - + DECLARE vCC DECIMAL(10,1); SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000) INTO vCC - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk JOIN vn.packaging p ON p.id = 'CC' - JOIN vn.volumeConfig vc + JOIN vn.volumeConfig vc WHERE sv.ticketFk = vTicketFk; - + RETURN vCC; END ;; @@ -48172,44 +48553,44 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_get`(vParamFk INT) RETURNS int(11) READS SQL DATA proc:BEGIN - + /* Devuelve el número de ticket o collection consultando en varias tablas posibles - * + * * @param vParamFk Número a validar * @return vValidFk Identificador validado */ - + DECLARE vValidFk INT; -- Tabla vn.saleGroup SELECT s.ticketFk INTO vValidFk FROM vn.sale s JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk + JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk WHERE sg.id = vParamFk AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()) LIMIT 1; - + IF vValidFk THEN - + RETURN vValidFk; - + LEAVE proc; - + END IF; -- Tabla vn.collection SELECT c.id INTO vValidFk - FROM vn.collection c + FROM vn.collection c WHERE c.id = vParamFk AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); - + IF vValidFk THEN - + RETURN vValidFk; - + LEAVE proc; - + END IF; -- Tabla vn.ticket @@ -48217,17 +48598,17 @@ proc:BEGIN FROM vn.ticket t WHERE t.id = vParamFk AND t.shipped > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); - + IF vValidFk THEN - + RETURN vValidFk; - + LEAVE proc; - + END IF; RETURN NULL; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48253,8 +48634,8 @@ BEGIN * @vTicketFk Id del ticket a calcular */ DECLARE deliveryPrice DECIMAL (10,2); - - IF (SELECT isVolumetric FROM ticket t JOIN zone z ON t.zoneFk = z.id + + IF (SELECT isVolumetric FROM ticket t JOIN zone z ON t.zoneFk = z.id WHERE t.id = vTicketFk) THEN SELECT SUM(sv.freight) INTO deliveryPrice FROM vn.saleVolume sv @@ -48265,7 +48646,7 @@ BEGIN LEFT JOIN expedition e ON e.ticketFk = t.id JOIN expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk WHERE t.id = vTicketFk; - + END IF; RETURN deliveryPrice; END ;; @@ -48289,16 +48670,16 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_getWeight`(vTicketFk INT) RET BEGIN /** * Devuelve el peso total del ticket - * + * * @return Total peso */ - + DECLARE vWeight DECIMAL(10,3); SELECT sum(weight) INTO vWeight FROM saleVolume WHERE ticketFk = vTicketFk; - + RETURN vWeight; END ;; @@ -48320,15 +48701,15 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_HasUbication`(vTicketFk INT) RETURNS tinyint(1) READS SQL DATA BEGIN - + DECLARE hasUbication BOOL; SELECT COUNT(*) INTO hasUbication FROM vn.ticket t JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - WHERE rm.beachFk + WHERE rm.beachFk AND t.id = vTicketFk; - + RETURN hasUbication; END ;; @@ -48477,7 +48858,7 @@ CREATE DEFINER=`root`@`localhost` FUNCTION `timeWorkerControl_getDirection`(vUse READS SQL DATA BEGIN /** - * Verifica la dirección de la fichada + * Verifica la dirección de la fichada * @param vUserFk Identificador del trabajador * @param vTimed Hora de la fichada * @return Retorna sentido de la fichada 'in, out, middle' @@ -48490,40 +48871,40 @@ BEGIN DECLARE vDayStayMax INT; DECLARE vTimedSeconds INT; DECLARE vLastTimeIn INT; - + SELECT UNIX_TIMESTAMP(vTimed) INTO vTimedSeconds; - + SELECT dayStayMax INTO vDayStayMax FROM vn.workerTimeControlParams; SELECT timed, direction INTO vNext,vNextDirection - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND direction IN ('in','out') AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + SELECT timed, direction INTO vPrevious, vPreviousDirection - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND direction IN ('in','out') AND timed < vTimed ORDER BY timed DESC - LIMIT 1; - - IF (vTimedSeconds - UNIX_TIMESTAMP(vPrevious) + UNIX_TIMESTAMP(vNext) - vTimedSeconds)<= vDayStayMax AND vPreviousDirection = 'in' AND vNextDirection = 'out' THEN + LIMIT 1; + + IF (vTimedSeconds - UNIX_TIMESTAMP(vPrevious) + UNIX_TIMESTAMP(vNext) - vTimedSeconds)<= vDayStayMax AND vPreviousDirection = 'in' AND vNextDirection = 'out' THEN RETURN 'middle'; END IF; - - + + IF (vTimedSeconds> UNIX_TIMESTAMP(vPrevious)) THEN - IF vPreviousDirection = 'in' THEN + IF vPreviousDirection = 'in' THEN RETURN 'out'; ELSE SELECT UNIX_TIMESTAMP(MAX(timed)) INTO vLastTimeIn - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND direction ='in' AND timed < vPrevious; IF vTimedSeconds - vLastTimeIn <= vDayStayMax THEN @@ -48577,11 +48958,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `travel_getForLogiflora`(vLanded DATE, vWarehouseFk INT) RETURNS int(11) READS SQL DATA BEGIN - + /** * Devuelve un número de travel para compras de Logiflora a partir de la fecha de llegada y del almacén. * Si no existe lo genera. - * + * * @param vLanded Fecha de llegada al almacén * @param vWarehouseFk Identificador de vn.warehouse */ @@ -48589,8 +48970,8 @@ BEGIN DECLARE vTravelFk INT; IF vLanded THEN - - SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk + + SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk FROM vn.travel tr JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk @@ -48601,14 +48982,14 @@ BEGIN AND landed = vLanded; IF NOT vTravelFk THEN - + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) - SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id - FROM vn.warehouse wOut + SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id + FROM vn.warehouse wOut JOIN vn.agencyMode am ON am.name = 'LOGIFLORA' WHERE wOut.name = 'Holanda'; - - SELECT MAX(tr.id) INTO vTravelFk + + SELECT MAX(tr.id) INTO vTravelFk FROM vn.travel tr JOIN vn.warehouse wIn ON wIn.id = tr.warehouseInFk JOIN vn.warehouse wOut ON wOut.id = tr.warehouseOutFk @@ -48616,11 +48997,11 @@ BEGIN AND wOut.name = 'Holanda' AND landed = vLanded; END IF; - + END IF; - + RETURN vTravelFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48647,21 +49028,21 @@ BEGIN DECLARE vChar INT; SET vLength = length(vString); - + WHILE vLength > 0 DO - + SET vChar = MID(vString,vLength,1); - + SET vSeed = vSeed + ASCII(vChar); - + SET vLength = vLength - 1; - + END WHILE; SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; RETURN vCode; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48688,21 +49069,21 @@ BEGIN DECLARE vChar INT; SET vLength = length(vString); - + WHILE vLength > 0 DO - + SET vChar = MID(vString,vLength,1); - + SET vSeed = vSeed + ASCII(vChar); - + SET vLength = vLength - 1; - + END WHILE; SET vCode = FLOOR(SQRT(vSeed)*1000000) mod 1000; RETURN vCode; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -48763,15 +49144,15 @@ BEGIN * @param vTimeOut * @return vNigthlyHours */ - DECLARE vNigthlyHours DECIMAL(5,2); + DECLARE vNigthlyHours DECIMAL(5,2); DECLARE vSecondsPerHour INT(4) DEFAULT 3600; - + SELECT GREATEST(0, TIMESTAMPDIFF(SECOND, - IF(TIME(vTimeIn) BETWEEN endNightlyHours AND startNightlyHours, - CONCAT(DATE(vTimeIn), ' ', startNightlyHours), + IF(TIME(vTimeIn) BETWEEN endNightlyHours AND startNightlyHours, + CONCAT(DATE(vTimeIn), ' ', startNightlyHours), vTimeIn), - IF(TIME(vTimeOut) BETWEEN endNightlyHours AND startNightlyHours, - CONCAT(DATE(vTimeOut), ' ', endNightlyHours), + IF(TIME(vTimeOut) BETWEEN endNightlyHours AND startNightlyHours, + CONCAT(DATE(vTimeOut), ' ', endNightlyHours), vTimeOut))) / vSecondsPerHour INTO vNigthlyHours FROM vn.workerTimeControlConfig; @@ -48803,47 +49184,47 @@ BEGIN SELECT dayStayMax INTO vDayStayMax FROM workerTimeControlParams; - + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; IF vDirection = 'out' THEN - + SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk + FROM workerTimeControl + WHERE userFk = vUserFk AND direction = 'in' AND timed < vTimed; - + UPDATE workerTimeControl wtc SET wtc.direction = 'middle' WHERE userFk = vUserFk AND direction = 'out' AND timed BETWEEN vLastIn AND vTimed; - + ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut + + SELECT COUNT(*) INTO vHasDirectionOut FROM workerTimeControl wtc - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); UPDATE workerTimeControl wtc SET wtc.direction = IF (vHasDirectionOut,'middle','out') WHERE userFk = vUserFk AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); END IF; END IF; - + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - + SET vLastInsertedId = LAST_INSERT_ID(); - + CALL workerTimeControlSOWP(vUserFk, vTimed); - + RETURN vLastInsertedId; END ;; DELIMITER ; @@ -48872,47 +49253,47 @@ BEGIN SELECT dayStayMax INTO vDayStayMax FROM workerTimeControlParams; - + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; IF vDirection = 'out' THEN - + SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk + FROM workerTimeControl + WHERE userFk = vUserFk AND direction = 'in' AND timed < vTimed; - + UPDATE workerTimeControl wtc SET wtc.direction = 'middle' WHERE userFk = vUserFk AND direction = 'out' AND timed BETWEEN vLastIn AND vTimed; - + ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut + + SELECT COUNT(*) INTO vHasDirectionOut FROM workerTimeControl wtc - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); UPDATE workerTimeControl wtc SET wtc.direction = IF (vHasDirectionOut,'middle','out') WHERE userFk = vUserFk AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); END IF; END IF; - + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - + SET vLastInsertedId = LAST_INSERT_ID(); - + CALL workerTimeControlSOWP(vUserFk, vTimed); - + RETURN vLastInsertedId; END ;; DELIMITER ; @@ -49006,6 +49387,45 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `worker_isInDepartment` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `worker_isInDepartment`(vDepartmentCode VARCHAR(255)) RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Devuelve booleano si el trabajador conectado pertenece + * al departamento vDepartmentCode o a sus departamentos subordinados + * + * @param vDepartmentCode code del departamento que se desea comprobar. + * @return Devuelve verdadero si es jefe del empleado por escala jerárquica. + */ + DECLARE vIsInDepartment BOOLEAN; + WITH RECURSIVE department AS ( + SELECT d.id FROM vn.department d WHERE code = vDepartmentCode + UNION + SELECT d.id + FROM department ds + JOIN vn.department d ON ds.id = d.parentFk + ) + SELECT COUNT(*) INTO vIsInDepartment FROM department ds + JOIN vn.workerDepartment wd ON wd.departmentFk = ds.id + WHERE wd.workerFk = account.myUser_getId(); + + RETURN vIsInDepartment; +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_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `worker_isWorking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -49023,17 +49443,17 @@ BEGIN * @return Devuelve TRUE en caso de que este trabajando. Si se encuentra en un descanso devolverá FALSE */ DECLARE vLastIn DATETIME ; - + SELECT MAX(timed) INTO vLastIn - FROM vn.workerTimeControl + FROM vn.workerTimeControl WHERE userFk = vWorkerFk AND direction = 'in'; - IF (SELECT MOD(COUNT(*),2) - FROM vn.workerTimeControl - WHERE userFk = vWorkerFk AND + IF (SELECT MOD(COUNT(*),2) + FROM vn.workerTimeControl + WHERE userFk = vWorkerFk AND timed >= vLastIn - ) THEN + ) THEN RETURN TRUE; ELSE RETURN FALSE; @@ -49127,7 +49547,7 @@ BEGIN SET `type` = vType, `name` = vName, parentFk = vParentFk; - + SET vSelf = LAST_INSERT_ID(); UPDATE zoneGeoRecalc SET isChanged = TRUE; @@ -49151,7 +49571,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addNoteFromDelivery`(idTicket INT,nota TEXT) BEGIN - + DECLARE observationTypeFk INT DEFAULT 3; /*3 = REPARTIDOR*/ INSERT INTO ticketObservation(ticketFk,observationTypeFk,description) @@ -49179,23 +49599,23 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `addressTaxArea`() READS SQL DATA BEGIN /** - * Devuelve el taxArea para un conjunto de Consignatarios y empresas, + * Devuelve el taxArea para un conjunto de Consignatarios y empresas, * * @table tmp.addressCompany(addressFk, companyFk) valores a calcular * @return tmp.addressTaxArea(addressFk,companyFk) */ - + DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; CREATE TEMPORARY TABLE tmp.addressTaxArea (PRIMARY KEY (addressFk, companyFk)) ENGINE = MEMORY - SELECT CASE - WHEN (NOT IFNULL(auClient.isUeeMember, cClient.isUeeMember) OR NOT cSupplier.isUeeMember) - AND NOT (auSupplier.id <=> auClient.id) THEN + SELECT CASE + WHEN (NOT IFNULL(auClient.isUeeMember, cClient.isUeeMember) OR NOT cSupplier.isUeeMember) + AND NOT (auSupplier.id <=> auClient.id) THEN 'WORLD' - WHEN cClient.isUeeMember AND cSupplier.isUeeMember AND c.countryFk != s.countryFk AND c.isVies THEN + WHEN cClient.isUeeMember AND cSupplier.isUeeMember AND c.countryFk != s.countryFk AND c.isVies THEN 'CEE' - WHEN a.isEqualizated AND cClient.code = 'ES' THEN + WHEN a.isEqualizated AND cClient.code = 'ES' THEN 'EQU' ELSE 'NATIONAL' @@ -49236,27 +49656,27 @@ BEGIN * @param vAddress id de la direccion * @param vWarehouse id del warehouse * @return vShipped la primera fecha disponible y vLanded la fecha de llegada/recojida -*/ +*/ DECLARE vAgency INT; DECLARE vShipped DATE; DECLARE vLanded DATE DEFAULT util.VN_CURDATE(); SELECT agencyFk INTO vAgency FROM agencyMode WHERE id= vAgencyMode; l: LOOP - + CALL agencyHourGetShipped(vLanded,vAddress,vAgency); - SELECT shipped INTO vShipped + SELECT shipped INTO vShipped FROM tmp.agencyHourGetShipped WHERE warehouseFk = vWarehouse LIMIT 1; - + IF vShipped THEN LEAVE l; END IF; - + SET vLanded = DATE_ADD(vLanded, INTERVAL +1 DAY); - + END LOOP; - + SELECT vShipped,vLanded; END ;; DELIMITER ; @@ -49307,7 +49727,7 @@ BEGIN LIMIT 1 ) t WHERE IF(vDated = util.VN_CURDATE(), t.maxHour > HOUR(util.VN_NOW()), TRUE) AND t.substractDay < 225; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -49330,14 +49750,14 @@ BEGIN * DEPRECATED usar zoneGetWarehouse * Devuelve el listado de agencias disponibles para la fecha, * dirección y warehouuse pasadas - * + * * @param vAddress no puede ser NULL * @param vWarehouse warehouse donde comprobaremos las agencias y fecha * @param vDate Fecha de recogida * @table agencyModeWarehouseList Listado de agencias disponibles */ DECLARE vAgency INT; - DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vDone BOOL DEFAULT FALSE; DECLARE vCur CURSOR FOR SELECT DISTINCT a.id FROM agency a @@ -49361,13 +49781,13 @@ BEGIN PRIMARY KEY(id) ) ENGINE = MEMORY; - + OPEN vCur; FETCH vCur INTO vAgency; WHILE NOT vDone DO - + INSERT INTO tmp.agencyModeWarehouseList SELECT am.id, am.name, am.description,am.deliveryMethodFk, TIMESTAMPADD(DAY, -ah.substractDay, vDate), w.name FROM agencyHour ah @@ -49396,7 +49816,7 @@ BEGIN END WHILE; CLOSE vCur; - + SELECT * FROM tmp.agencyModeWarehouseList; DROP TEMPORARY TABLE tmp.agencyModeWarehouseList; END ;; @@ -49422,9 +49842,9 @@ BEGIN CALL vn.agencyHourGetShipped(vDate, vAddress, vAgency); SELECT * FROM tmp.agencyHourGetShipped; - + DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -49462,7 +49882,7 @@ BEGIN DECLARE cWarehouses CURSOR FOR SELECT warehouseFk, shipped FROM tmp.zoneGetShipped; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -49471,7 +49891,7 @@ BEGIN CALL vn.zone_getShipped (vDate, vAddress, vAgencyMode, FALSE); DROP TEMPORARY TABLE IF EXISTS tmp.availableCalc; - CREATE TEMPORARY TABLE tmp.availableCalc( + CREATE TEMPORARY TABLE tmp.availableCalc( calcFk INT UNSIGNED, PRIMARY KEY (calcFk) ) @@ -49482,7 +49902,7 @@ BEGIN l: LOOP SET vDone = FALSE; FETCH cWarehouses INTO vWarehouse, vShipment; - + IF vDone THEN LEAVE l; END IF; @@ -49515,7 +49935,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `bankEntity_checkBic`(vBic VARCHAR(2 BEGIN /** * If the bic length is Incorrect throw exception - * + * * @param vBic bic code */ @@ -49523,7 +49943,7 @@ BEGIN SELECT bicLength INTO vConfigBicLenght FROM vn.bankEntityConfig bec; - + IF LENGTH(vBic) <> vConfigBicLenght THEN CALL util.throw(CONCAT('bic must be of length ', vConfigBicLenght )); END IF; @@ -49550,14 +49970,14 @@ BEGIN * Manda correo cuando caduca un seguro * de los leasing * -*/ +*/ INSERT INTO mail (receiver,replyTo,subject,body) SELECT 'administracion@verdnatura.es' receiver, 'noreply@verdnatura.es' replyTo, CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') subject, CONCAT('El seguro de la poliza ',b.id,' ',b.bank,' ha finalizado.') body - FROM vn.bankPolicy bp - LEFT JOIN vn.supplier s + FROM vn.bankPolicy bp + LEFT JOIN vn.supplier s ON s.id = bp.supplierFk LEFT JOIN vn.bank b ON b.id = bp.bankFk @@ -49786,19 +50206,19 @@ BEGIN DECLARE vIsFeedStock BOOL; DECLARE vWeight DECIMAL(10,2); DECLARE vPacking INT; - - SELECT b.entryFk, - b.itemFk, - i.packingOut, - ic.merchandise, + + SELECT b.entryFk, + b.itemFk, + i.packingOut, + ic.merchandise, vc.standardFlowerBox, b.weight, - b.packing - INTO - vEntryFk, - vItemFk, - vPackingOut, - vIsMerchandise, + b.packing + INTO + vEntryFk, + vItemFk, + vPackingOut, + vIsMerchandise, vStandardFlowerBox, vWeight, vPacking @@ -49806,7 +50226,7 @@ BEGIN LEFT JOIN item i ON i.id = b.itemFk LEFT JOIN itemType it ON it.id = i.typeFk LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN packaging p ON p.id = b.packagingFk AND NOT p.isBox + LEFT JOIN packaging p ON p.id = b.packagingFk AND NOT p.isBox JOIN volumeConfig vc ON TRUE WHERE b.id = vSelf; @@ -49823,7 +50243,7 @@ BEGIN warehouseFk = vWarehouse, cm3 = buy_getUnitVolume(vSelf), cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf)); - + IF vWeight AND vPacking THEN UPDATE itemCost SET grams = vWeight * 1000 / vPacking @@ -49844,7 +50264,7 @@ BEGIN WHERE b.id = vSelf; END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -49891,10 +50311,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getSplit`(vSelf INT, vDated DATE) BEGIN /** - * Devuelve tantos registros como etiquetas se necesitan para cada uno de los cubos o cajas de - * las ventas correspondientes a la compra que se pasa como parámetro, en los almacenes que tienen + * Devuelve tantos registros como etiquetas se necesitan para cada uno de los cubos o cajas de + * las ventas correspondientes a la compra que se pasa como parámetro, en los almacenes que tienen * habilitada la venta de productos con stock virtual, aunque los productos pueden ser de cualquier tipo. - * + * * @param vSelf Identificador de vn.buy * @param vDated Fecha de preparación de las ventas que queremos etiquetar */ @@ -49969,7 +50389,7 @@ BEGIN WHILE vLabels >= vCounter DO INSERT INTO tmp.split SET - id = vSaleFk, + id = vSaleFk, labels = vLabels, counter = vCounter; @@ -49991,11 +50411,11 @@ BEGIN -- Devuelve los splits creados SELECT CONCAT(sp.counter,'/',sp.labels) labels, COALESCE(sfc.nickname, sfa.nickname, a.nickname) destination, - s.itemFk, - i.longName, - i.`size`, - vn.ticketSplitCounter(t.id) counter, - IF(sfa.id OR sfc.id, + s.itemFk, + i.longName, + i.`size`, + vn.ticketSplitCounter(t.id) counter, + IF(sfa.id OR sfc.id, a.nickname, CONCAT(a.id, ' ', p.`name`,' (', c.`code`,')')) destination2 FROM tmp.split sp @@ -50040,12 +50460,12 @@ BEGIN item_getVolume(b.itemFk, b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) carros , CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * item_getVolume(b.itemFk, b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) espais - FROM buy b + FROM buy b JOIN tmp.buy tb ON tb.buyFk = b.id JOIN volumeConfig vc JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk - LEFT JOIN temperature t ON t.code = it.temperatureFk + LEFT JOIN temperature t ON t.code = it.temperatureFk GROUP BY Temp; END ;; DELIMITER ; @@ -50065,21 +50485,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolumeByAgency`(vDated DATE, vAgencyFk INT) BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.buy; CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; - INSERT INTO tmp.buy + INSERT INTO tmp.buy SELECT b.id - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk WHERE t.landed = vDated AND t.agencyModeFk IN (0, vAgencyFk); CALL buy_getVolume(); DROP TEMPORARY TABLE tmp.buy; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -50098,19 +50518,19 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolumeByEntry`(vEntryFk INT) BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.buy; CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; - - INSERT INTO tmp.buy + + INSERT INTO tmp.buy SELECT b.id - FROM buy b - JOIN entry e ON e.id = b.entryFk + FROM buy b + JOIN entry e ON e.id = b.entryFk WHERE e.id = vEntryFk; CALL buy_getVolume(); DROP TEMPORARY TABLE tmp.buy; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -50118,14 +50538,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_recalcPrices` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_recalcPrices`() BEGIN @@ -50137,7 +50557,7 @@ BEGIN DECLARE vLanded DATE; DECLARE vWarehouseFk INT; DECLARE vHasNotPrice BOOL; - DECLARE vBuyingValue DECIMAL(10,3); + DECLARE vBuyingValue DECIMAL(10,4); DECLARE vPackagingFk VARCHAR(10); DECLARE vIsWarehouseFloramondo BOOL; @@ -50198,12 +50618,12 @@ BEGIN * inserta en tmp.buyRecalc las compras de un awb * * @param awbFk - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; CREATE TEMPORARY TABLE tmp.buyRecalc SELECT b.id - FROM buy b + FROM buy b JOIN entry e ON e.id = b.entryFk JOIN duaEntry de ON de.entryFk = e.id JOIN dua d ON d.id = de.duaFk @@ -50235,7 +50655,7 @@ BEGIN * Recalcula los precios de una compra * * @param vBuyFk - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; CREATE TEMPORARY TABLE tmp.buyRecalc @@ -50266,12 +50686,12 @@ BEGIN * Recalcula los precios de una entrada * * @param vEntryFk - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; CREATE TEMPORARY TABLE tmp.buyRecalc SELECT b.id - FROM buy b + FROM buy b WHERE b.entryFk = vEntryFk; CALL buy_recalcPrices(); @@ -50311,12 +50731,12 @@ BEGIN LIMIT 0; INSERT INTO tBuy(buyFk) - SELECT b.id + SELECT b.id FROM buy b JOIN tmp.ekt t ON t.ektFk = b.ektFk JOIN vn.entry en ON en.id = b.entryFk JOIN vn.travel tr ON tr.id = en.travelFk - JOIN vn.warehouse w ON w.id = tr.warehouseInFk + JOIN vn.warehouse w ON w.id = tr.warehouseInFk JOIN vn.country c ON c.id = w.countryFk AND c.code = 'NL'; SELECT b.id buy, i.doPhoto do_photo, b.stickers - CAST(b.printedStickers AS INT) stickersToPrint @@ -50382,7 +50802,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_updatePacking`(vWarehouseFk INT, vItemFk INT, vPacking INT) BEGIN /** - * Actualiza packing + * Actualiza packing * * @param vWarehouseFk warehouse del item * @param vItemFk id del item @@ -50392,8 +50812,8 @@ BEGIN UPDATE buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk - SET b.packing = vPacking - WHERE bu.warehouseFk = vWarehouseFk + SET b.packing = vPacking + WHERE bu.warehouseFk = vWarehouseFk AND bu.itemFk = vItemFk; DROP TEMPORARY TABLE tmp.buyUltimate; @@ -50432,7 +50852,7 @@ BEGIN */ DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item - ENGINE = MEMORY + ENGINE = MEMORY SELECT vItemFk itemFk; CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); @@ -50454,7 +50874,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calculate`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) -BEGIN +BEGIN /** * Calcula los articulos disponibles y sus precios * @@ -50462,7 +50882,7 @@ BEGIN * @param vLanded Fecha de recepcion de mercancia * @param vAddressFk Id del consignatario * @param vAgencyModeFk Id de la agencia - * @return tmp.ticketCalculateItem(itemFk, available, producer, + * @return tmp.ticketCalculateItem(itemFk, available, producer, * item, size, stems, category, inkFk, image, origin, price) * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk) * @return tmp.ticketComponent @@ -50497,22 +50917,22 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem; CREATE TEMPORARY TABLE tmp.ticketCalculateItem( - itemFk INT(11) NOT NULL, + itemFk INT(11) NOT NULL, available INT(11), - producer VARCHAR(50), - item VARCHAR(50), - size INT(10) UNSIGNED, - stems INT(11), - category VARCHAR(3), - inkFk VARCHAR(3), + producer VARCHAR(50), + item VARCHAR(50), + size INT(10) UNSIGNED, + stems INT(11), + category VARCHAR(3), + inkFk VARCHAR(3), image VARCHAR(50), - origin VARCHAR(3), + origin VARCHAR(3), price DECIMAL(10,2), priceKg DECIMAL(10,2), `grouping` INT(10) UNSIGNED, PRIMARY KEY `itemFk` (`itemFk`) ) ENGINE = MEMORY DEFAULT CHARSET=utf8; - + OPEN cTravelTree; l: LOOP @@ -50534,20 +50954,20 @@ BEGIN bu.buyFk, vZoneFk FROM `cache`.available a - LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id + LEFT JOIN cache.availableNoRaids anr ON anr.item_id = a.item_id AND anr.calc_id = vAvailableNoRaidsCalc JOIN tmp.item i ON i.itemFk = a.item_id JOIN vn.item it ON it.id = i.itemFk JOIN vn.`zone` z ON z.id = vZoneFk - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id - LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk - LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = a.item_id + LEFT JOIN edi.supplyResponse sr ON sr.ID = it.supplyResponseFk + LEFT JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID LEFT JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID LEFT JOIN (SELECT isVNHSupplier, isEarlyBird, TRUE AS itemAllowed FROM vn.addressFilter af - JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed - FROM vn.address ad - JOIN vn.province p ON p.id = ad.provinceFk + JOIN (SELECT ad.provinceFk, p.countryFk, ad.isLogifloraAllowed + FROM vn.address ad + JOIN vn.province p ON p.id = ad.provinceFk WHERE ad.id = vAddressFk ) sub2 ON sub2.provinceFk <=> IFNULL(af.provinceFk, sub2.provinceFk) AND sub2.countryFk <=> IFNULL(af.countryFk, sub2.countryFk) @@ -50564,13 +50984,13 @@ BEGIN JOIN vn.itemType itt ON itt.id = it.typeFk JOIN vn.itemCategory itc on itc.id = itt.categoryFk JOIN vn.address ad ON ad.id = vAddressFk - LEFT JOIN vn.clientItemType cit + LEFT JOIN vn.clientItemType cit ON cit.clientFk = ad.clientFk AND cit.itemTypeFk = itt.id - LEFT JOIN vn.zoneItemType zit + LEFT JOIN vn.zoneItemType zit ON zit.zoneFk = vZoneFk AND zit.itemTypeFk = itt.id - LEFT JOIN vn.agencyModeItemType ait + LEFT JOIN vn.agencyModeItemType ait ON ait.agencyModeFk = vAgencyModeFk AND ait.itemTypeFk = itt.id WHERE a.calc_id = vAvailableCalc @@ -50663,7 +51083,7 @@ BEGIN * Calcula los componentes de los articulos de tmp.ticketLot * * @param vZoneFk para calcular el transporte - * @param vAddressFk Consignatario + * @param vAddressFk Consignatario * @param vShipped dia de salida del pedido * @param vWarehouseFk warehouse de salida del pedido * @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk) @@ -50677,7 +51097,7 @@ BEGIN SELECT clientFk INTO vClientFK FROM address WHERE id = vAddressFk; - + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate (PRIMARY KEY (itemFk, warehouseFk)) ENGINE = MEMORY @@ -50689,7 +51109,7 @@ BEGIN IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing, IFNULL(pf.`grouping`, b.`grouping`) `grouping`, ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, - tl.buyFk, + tl.buyFk, i.typeFk, IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping FROM tmp.ticketLot tl @@ -50697,7 +51117,7 @@ BEGIN JOIN item i ON i.id = tl.itemFk JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN specialPrice sp ON sp.itemFk = i.id + LEFT JOIN specialPrice sp ON sp.itemFk = i.id AND sp.clientFk = vClientFk LEFT JOIN ( SELECT * FROM ( @@ -50716,7 +51136,7 @@ BEGIN LIMIT 10000000000000000000 ) tpf GROUP BY tpf.itemFk, tpf.warehouseFk - ) pf ON pf.itemFk = tl.itemFk + ) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.merchandise @@ -50748,10 +51168,10 @@ BEGIN FROM tmp.ticketComponent tc JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk GROUP BY tc.itemFk, warehouseFk; - + -- RECOBRO INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcb.warehouseFk, tcb.itemFk, c2.id, + SELECT tcb.warehouseFk, tcb.itemFk, c2.id, ROUND(tcb.base * LEAST( MAX(GREATEST(IFNULL(cr.priceIncreasing,0), @@ -50782,29 +51202,29 @@ BEGIN ROUND(base * wm.pricesModifierRate, 3) manaAuto FROM tmp.ticketComponentBase tcb JOIN `client` c on c.id = vClientFk - JOIN workerMana wm ON c.salesPersonFk = wm.workerFk + JOIN workerMana wm ON c.salesPersonFk = wm.workerFk JOIN vn.component c2 ON c2.code = 'autoMana' WHERE wm.isPricesModifierActivated HAVING manaAuto <> 0; - + -- Precios especiales INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, c2.id, GREATEST( - IFNULL(ROUND(tcb.base * c2.tax, 4), 0), + IFNULL(ROUND(tcb.base * c2.tax, 4), 0), IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3 ) cost FROM tmp.ticketComponentBase tcb JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount' - JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk + JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk JOIN vn.item i ON i.id = tcb.itemFk WHERE sp.value IS NULL AND i.supplyResponseFk IS NULL; - -- Individual + -- Individual INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) SELECT tcb.warehouseFk, tcb.itemFk, @@ -50815,10 +51235,10 @@ BEGIN JOIN vn.client c ON c.id = vClientFk JOIN vn.businessType bt ON bt.code = c.businessTypeFk WHERE bt.code = 'individual'; - + -- Venta por paquetes INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 + SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3 FROM tmp.ticketComponentCalculate tcc JOIN vn.component c2 ON c2.code = 'salePerPackage' JOIN buy b ON b.id = tcc.buyFk @@ -50830,7 +51250,7 @@ BEGIN SELECT vZoneFk id; CALL zone_getOptionsForShipment(vShipped, TRUE); - + -- Reparto INSERT INTO tmp.ticketComponent SELECT tcc.warehouseFK, @@ -50844,7 +51264,7 @@ BEGIN JOIN agencyMode am ON am.id = z.agencyModeFk JOIN vn.volumeConfig vc JOIN vn.component c2 ON c2.code = 'delivery' - LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk + LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk AND ic.itemFk = tcc.itemFk HAVING cost <> 0; @@ -50897,9 +51317,9 @@ BEGIN CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price, CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg FROM tmp.ticketComponentCalculate tcc - JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk AND tcs.warehouseFk = tcc.warehouseFk - WHERE IFNULL(tcs.classRate, 1) = 1 + WHERE IFNULL(tcs.classRate, 1) = 1 AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0) GROUP BY tcs.warehouseFk, tcs.itemFk; @@ -50936,7 +51356,7 @@ BEGIN SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 ) t GROUP BY itemFk, warehouseFk, `grouping`; - + DROP TEMPORARY TABLE tmp.ticketComponentCalculate, tmp.ticketComponentSum, @@ -50961,7 +51381,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentPrepare`() BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; CREATE TEMPORARY TABLE tmp.ticketComponent ( `warehouseFk` INT UNSIGNED NOT NULL, @@ -50971,9 +51391,9 @@ BEGIN INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), UNIQUE `fkItemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC) )ENGINE=MEMORY DEFAULT CHARSET=utf8; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice; - CREATE TEMPORARY TABLE tmp.ticketComponentPrice ( + CREATE TEMPORARY TABLE tmp.ticketComponentPrice ( `warehouseFk` INT UNSIGNED NOT NULL, `itemFk` INT NOT NULL, `rate` INT NOT NULL, @@ -50982,7 +51402,7 @@ BEGIN `priceKg` DECIMAL(10,4), INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), UNIQUE `fkItemWarehouseRate` (`itemFk` ASC, `warehouseFk` ASC, `rate` ASC) - )ENGINE=MEMORY DEFAULT CHARSET=utf8; + )ENGINE=MEMORY DEFAULT CHARSET=utf8; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51001,7 +51421,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentPurge`() BEGIN - DROP TEMPORARY TABLE + DROP TEMPORARY TABLE tmp.ticketComponentPrice, tmp.ticketComponent, tmp.ticketLot; @@ -51056,7 +51476,7 @@ BEGIN DELETE FROM sms WHERE created < v18Month; DELETE FROM saleTracking WHERE created < vOneYearAgo; DELETE FROM ticketTracking WHERE created < v18Month; - DELETE tobs FROM ticketObservation tobs + DELETE tobs FROM ticketObservation tobs JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo; DELETE FROM sharingCart where ended < vDateShort; @@ -51135,12 +51555,12 @@ BEGIN FROM vn.travel t LEFT JOIN vn.entry e ON e.travelFk = t.id WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; - + UPDATE dms d - JOIN dmsType dt ON dt.id = d.dmsTypeFk - SET d.dmsTypeFk = vTrashId + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, util.VN_CURDATE()); - + -- borrar entradas sin compras DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; CREATE TEMPORARY TABLE tmp.entryToDelete @@ -51159,7 +51579,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.routeToDelete SELECT * FROM vn.route r - WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); + WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); UPDATE tmp.routeToDelete tmp JOIN vn.dms d ON d.id = tmp.gestdocFk @@ -51342,21 +51762,21 @@ BEGIN */ DECLARE vClientDebt DOUBLE; - + SELECT vn.client_getDebt(vClientFk, util.VN_CURDATE()) INTO vClientDebt; - + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) VALUES (vClientFk, 'Saldo pendiente', vClientDebt, util.VN_CURDATE(), 5); - + CALL vn.clientGreugeSpray(vClientFk, TRUE, '', TRUE); - + INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) SELECT vClientFk, 'Liquidación cliente', sum(amount), util.VN_CURDATE(), 5 FROM vn.greuge WHERE clientFk = vClientFk; - - UPDATE vn.client - SET salesPersonFk = NULL + + UPDATE vn.client + SET salesPersonFk = NULL WHERE id = vClientFk; END ;; @@ -51447,33 +51867,33 @@ BEGIN DECLARE vIssued DATETIME; DECLARE vBalance DOUBLE DEFAULT 0.00; DECLARE cur CURSOR FOR - SELECT - created, - issued, + SELECT + created, + issued, ROUND(amount, 2) AS balance FROM invoiceOut - WHERE clientFk = vClientFk AND companyFk = vCompanyFk - UNION ALL - SELECT - created, - payed, + WHERE clientFk = vClientFk AND companyFk = vCompanyFk + UNION ALL + SELECT + created, + payed, ROUND(-1 * amountPaid, 2) AS balance - FROM receipt + FROM receipt WHERE clientFk = vClientFk AND companyFk = vCompanyFk ORDER BY issued, created; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + OPEN cur; - + proc: LOOP SET vDone = FALSE; - + FETCH cur INTO vCreated, vIssued, vBalance; IF vDate IS NULL THEN SET vDate=vIssued; END IF; - + IF vDone THEN LEAVE proc; END IF; @@ -51485,66 +51905,66 @@ BEGIN SET vDone = TRUE; END IF; END LOOP; - + CLOSE cur; - - SELECT - issued, - CAST(debtOut AS DECIMAL(10,2)) debtOut, + + SELECT + issued, + CAST(debtOut AS DECIMAL(10,2)) debtOut, CAST(debtIn AS DECIMAL(10,2)) debtIn, - ref, - companyFk, + ref, + companyFk, priority FROM - (SELECT - NULL AS issued, - SUM(amountUnpaid) AS debtOut, - NULL AS debtIn, - 'Saldo Anterior' AS ref, + (SELECT + NULL AS issued, + SUM(amountUnpaid) AS debtOut, + NULL AS debtIn, + 'Saldo Anterior' AS ref, companyFk, - 0 as priority - FROM - (SELECT SUM(amount) AS amountUnpaid, companyFk, 0 + 0 as priority + FROM + (SELECT SUM(amount) AS amountUnpaid, companyFk, 0 FROM invoiceOut - WHERE clientFk = vClientFK - AND issued < vDate - GROUP BY companyFk - - UNION ALL - - SELECT SUM(-1 * amountPaid), companyFk, 0 - FROM receipt - WHERE clientFk = vClientFK - AND payed < vDate - GROUP BY companyFk) AS transactions - GROUP BY companyFk - - UNION ALL - - SELECT - issued, - amount as debtOut, - NULL AS debtIn, + WHERE clientFk = vClientFK + AND issued < vDate + GROUP BY companyFk + + UNION ALL + + SELECT SUM(-1 * amountPaid), companyFk, 0 + FROM receipt + WHERE clientFk = vClientFK + AND payed < vDate + GROUP BY companyFk) AS transactions + GROUP BY companyFk + + UNION ALL + + SELECT + issued, + amount as debtOut, + NULL AS debtIn, ref, companyFk, - 1 - FROM invoiceOut - WHERE clientFk = vClientFK + 1 + FROM invoiceOut + WHERE clientFk = vClientFK AND issued >= vDate - UNION ALL - - SELECT - r.payed, - NULL as debtOut, - r.amountPaid, - r.invoiceFk, + UNION ALL + + SELECT + r.payed, + NULL as debtOut, + r.amountPaid, + r.invoiceFk, r.companyFk, - 0 + 0 FROM receipt r - WHERE r.clientFk = vClientFK - AND r.payed >= vDate) t - INNER JOIN `client` c ON c.id = vClientFK - HAVING debtOut <> 0 OR debtIn <> 0 + WHERE r.clientFk = vClientFK + AND r.payed >= vDate) t + INNER JOIN `client` c ON c.id = vClientFK + HAVING debtOut <> 0 OR debtIn <> 0 ORDER BY issued, priority DESC, debtIn; END ;; DELIMITER ; @@ -51602,13 +52022,13 @@ BEGIN WHERE id = vClientFk; ELSE - + SELECT id INTO vOwner FROM vn.worker WHERE code = vWorkerCode COLLATE utf8_general_ci; END IF; - + DROP TEMPORARY TABLE IF EXISTS tmp.clientList; CREATE TEMPORARY TABLE tmp.clientList SELECT DISTINCT t.clientFk, floor(cr.yearSale / 12) monthSale @@ -51620,7 +52040,7 @@ BEGIN AND t.shipped >= TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) AND c.id != vClientFk HAVING monthSale > 100; - + SELECT SUM(monthSale) INTO vTotalSale FROM tmp.clientList; @@ -51631,7 +52051,7 @@ BEGIN SELECT vClientFk, 'Reparto greuge', -vGreuge, util.VN_CURDATE(), vGreugeTypeFk; END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51826,11 +52246,11 @@ BEGIN LEFT JOIN clientProtected cp ON cp.clientFk = cd.clientFk JOIN client c ON c.id = cd.clientFk JOIN province p ON p.id = c.provinceFk - LEFT JOIN autonomy a ON a.id = p.autonomyFk + LEFT JOIN autonomy a ON a.id = p.autonomyFk JOIN country co ON co.id = p.countryFk WHERE cd.warning = 'third' AND cp.clientFk IS NULL - AND co.code NOT IN ('PT') + AND co.code NOT IN ('PT') AND a.name <> 'Canarias' AND c.salesPersonFk IS NOT NULL; @@ -51941,7 +52361,7 @@ BEGIN JOIN client c ON c.accountingAccount = lc.account WHERE lc.`date` BETWEEN vDateFrom AND vDateTo )sub - GROUP BY companyFk, clientFk + GROUP BY companyFk, clientFk ) sub1 ON sub1.clientFk = c.id JOIN supplier s ON s.id = sub1.companyFk JOIN company co ON co.id = sub1.companyFk @@ -52218,9 +52638,9 @@ BEGIN DECLARE i INT DEFAULT 0; DECLARE c INT DEFAULT 0; DECLARE maxClientFk INT; - + DROP TEMPORARY TABLE IF EXISTS tmp.client; - + CREATE TEMPORARY TABLE tmp.`client` (id INT AUTO_INCREMENT, clientFk INT, @@ -52228,40 +52648,40 @@ BEGIN PRIMARY KEY(id), UNIQUE KEY clientFk (clientFk)) ENGINE = MEMORY; - + INSERT INTO tmp.client(clientFk) SELECT DISTINCT clientFk FROM vn.invoiceOut WHERE issued > TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); - + SELECT max(id) INTO maxClientFk FROM tmp.client; - - + + WHILE i < vNumber DO - + SET i = i + 1; - + WHILE c = 0 DO - + SELECT id INTO c FROM tmp.client WHERE id = floor(RAND() * maxClientFk) + 1 AND isSelected = FALSE LIMIT 1; - + END WHILE; - + -- SELECT i, maxClientFk, c; - - UPDATE tmp.client - SET isSelected = TRUE + + UPDATE tmp.client + SET isSelected = TRUE WHERE id = c; - + SET c = 0; - + END WHILE; - + SELECT c.id, c.name FROM tmp.client tc JOIN vn.client c ON c.id = tc.clientFk WHERE isSelected @@ -52303,9 +52723,9 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; CREATE OR REPLACE TEMPORARY TABLE tClientList - SELECT c.clientFk + SELECT c.id clientFk FROM bs.clientDied cd - JOIN client c ON c.id = cd.id + JOIN client c ON c.id = cd.clientFk LEFT JOIN clientProtected cp ON cp.clientFk = c.id LEFT JOIN salesPersonProtected sp ON sp.salesPersonFk = c.salesPersonFk JOIN province p ON p.id = c.provinceFk @@ -52413,9 +52833,7 @@ BEGIN DECLARE vWarehouseFk INT; DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); - DROP TEMPORARY TABLE IF EXISTS tSale; - - CREATE TEMPORARY TABLE tSale + CREATE OR REPLACE TEMPORARY TABLE tSale (INDEX(ticketFk), INDEX(saleFk), INDEX(itemFk)) ENGINE = MEMORY SELECT s.ticketFk, s.id saleFk, s.itemFk, s.quantity @@ -52436,8 +52854,7 @@ BEGIN CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - DROP TEMPORARY TABLE IF EXISTS tGrouping; - CREATE TEMPORARY TABLE tGrouping + CREATE OR REPLACE TEMPORARY TABLE tGrouping (INDEX(itemFk)) ENGINE = MEMORY SELECT b.itemFk, @@ -52451,8 +52868,7 @@ BEGIN WHERE lb.warehouse_id = vWarehouseFk GROUP BY b.itemFk; - DROP TEMPORARY TABLE IF EXISTS tSalePlacementList; - CREATE TEMPORARY TABLE tSalePlacementList + CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList (INDEX(saleFk), INDEX(`order`)) ENGINE = MEMORY SELECT ts.saleFk, @@ -52473,9 +52889,9 @@ BEGIN ish.created, ish.visible, IFNULL( - IF(sc.isPreviousPreparedByPacking, ish.packing, g.`grouping`), + IF(st.description = 'previousByPacking', ish.packing, g.`grouping`), 1) `grouping`, - sc.isPreviousPrepared, + st.description = 'previousPrepared' isPreviousPrepared, iss.id itemShelvingSaleFk, ts.ticketFk, iss.id, @@ -52492,6 +52908,7 @@ BEGIN JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON p.id = sh.parkingFk JOIN sector sc ON sc.id = p.sectorFk + JOIN sectorType st ON st.id = sc.typeFk JOIN warehouse w ON w.id = sc.warehouseFk LEFT JOIN tGrouping g ON g.itemFk = ts.itemFk LEFT JOIN itemShelvingSale iss ON iss.saleFk = ts.saleFk @@ -52504,8 +52921,7 @@ BEGIN AND NOT sc.isHideForPickers HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL; - DROP TEMPORARY TABLE IF EXISTS tSalePlacementList2; - CREATE TEMPORARY TABLE tSalePlacementList2 + CREATE OR REPLACE TEMPORARY TABLE tSalePlacementList2 (INDEX(saleFk), INDEX(olderPriority)) ENGINE = MEMORY SELECT saleFk, priority olderPriority @@ -52591,15 +53007,15 @@ BEGIN DATE_FORMAT(util.VN_NOW(), '%H:%i' ), ' ', i.name - ) INTO vConcept + ) INTO vConcept FROM item i WHERE i.id = vItemFk; SELECT name INTO vItemName FROM item WHERE id = vBarccodeFk; - SELECT CONCAT('Añadido articulo ', + SELECT CONCAT('Añadido articulo ', vItemName, - ' cantidad:', + ' cantidad:', vQuantity ) INTO vDescription; @@ -52636,7 +53052,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_assign`(vUserFk INT, OUT vCollectionFk INT) -proc:BEGIN +proc:BEGIN /* Comprueba si existen colecciones libres que se ajustan al perfil del usuario * y le asigna la más antigua. * Añade un registro al semillero de colecciones @@ -52669,14 +53085,14 @@ proc:BEGIN FROM vn.collection c JOIN vn.ticketCollection tc ON tc.collectionFk = c.id JOIN vn.state s ON s.code = 'PRINTED_AUTO' - JOIN vn.productionConfig pc - WHERE c.workerFk IS NULL + JOIN vn.productionConfig pc + WHERE c.workerFk IS NULL AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; DELETE c.* FROM vn.collection c - JOIN vn.productionConfig pc - WHERE c.workerFk IS NULL + JOIN vn.productionConfig pc + WHERE c.workerFk IS NULL AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; -- Se a�ade registro al semillero @@ -52686,8 +53102,8 @@ proc:BEGIN -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion SELECT MIN(c.id) INTO vCollectionFk - FROM vn.collection c - JOIN vn.operator o + FROM vn.collection c + JOIN vn.operator o ON (o.itemPackingTypeFk = c.itemPackingTypeFk OR c.itemPackingTypeFk IS NULL) AND o.numberOfWagons = c.wagons AND o.trainFk = c.trainFk @@ -52734,18 +53150,18 @@ BEGIN SELECT c.id collectionFk, date(c.created) created, COUNT(DISTINCT tc.ticketFk) ticketTotalCount - FROM collection c - JOIN ticketCollection tc ON tc.collectionFk = c.id - JOIN sale s ON s.ticketFk = tc.ticketFk + FROM collection c + JOIN ticketCollection tc ON tc.collectionFk = c.id + JOIN sale s ON s.ticketFk = tc.ticketFk JOIN ticketState ts ON ts.ticketFk = tc.ticketFk JOIN state s2 ON s2.id = ts.stateFk JOIN productionConfig pc JOIN vn.state ss on ss.code = 'PREPARED' LEFT JOIN vn.saleTracking st on st.saleFk = s.id AND st.stateFk = ss.id - WHERE c.workerFk = vWorkerFk + WHERE c.workerFk = vWorkerFk AND TIMESTAMPDIFF(HOUR, c.created , util.VN_NOW()) < pc.pendingCollectionsAge AND s.quantity != 0 - AND s2.order < pc.pendingCollectionsOrder + AND s2.order < pc.pendingCollectionsOrder GROUP BY c.id HAVING COUNT(*) > COUNT(DISTINCT st.id); @@ -52772,15 +53188,15 @@ BEGIN * Selecciona los tickets de una colección/ticket * @param vParamFk ticketFk/collectionFk * @return Retorna ticketFk, level, agencyName, warehouseFk, salesPersonFk, observaciones - */ + */ DECLARE vItemPackingTypeFk VARCHAR(1); -- Si los sacadores son los de pruebas, pinta los colores SELECT itemPackingTypeFk INTO vItemPackingTypeFk - FROM vn.collection + FROM vn.collection WHERE id = vParamFk; - SELECT t.id ticketFk, + SELECT t.id ticketFk, IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`, am.name agencyName, t.warehouseFk, @@ -52790,20 +53206,20 @@ BEGIN FROM vn.ticket t LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 - LEFT JOIN vn.collectionColors cc - ON cc.wagon = tc.wagon - AND cc.shelve = tc.`level` + LEFT JOIN vn.collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk -- PAK 23/12/21 - LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN vn.client c ON c.id = t.clientFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 1 - WHERE t.id = vParamFk + WHERE t.id = vParamFk AND t.shipped >= util.yesterday() UNION ALL - SELECT t.id ticketFk, + SELECT t.id ticketFk, IF(!(vItemPackingTypeFk <=> 'V'), cc.code, CONCAT(SUBSTRING('ABCDEFGH', tc.wagon, 1), '-', tc.`level`)) `level`, am.name agencyName, t.warehouseFk, @@ -52813,15 +53229,15 @@ BEGIN FROM vn.ticket t JOIN vn.ticketCollection tc ON t.id = tc.ticketFk LEFT JOIN vn.collection c2 ON c2.id = tc.collectionFk -- PAK 23/12/21 - LEFT JOIN vn.collectionColors cc - ON cc.wagon = tc.wagon - AND cc.shelve = tc.`level` + LEFT JOIN vn.collectionColors cc + ON cc.wagon = tc.wagon + AND cc.shelve = tc.`level` AND cc.trainFk = c2.trainFk -- PAK 23/12/21 - LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN vn.client c ON c.id = t.clientFk LEFT JOIN vn.worker w ON w.id = c.salesPersonFk - LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 1 WHERE tc.collectionFk = vParamFk; @@ -53184,8 +53600,8 @@ proc:BEGIN -- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo DELETE tt.* FROM tTrain tt - LEFT JOIN (SELECT DISTINCT wagon - FROM tTrain + LEFT JOIN (SELECT DISTINCT wagon + FROM tTrain WHERE ticketFk IS NOT NULL ) nn ON nn.wagon = tt.wagon WHERE nn.wagon IS NULL; @@ -53353,7 +53769,7 @@ BEGIN DECLARE vDone INT DEFAULT FALSE; DECLARE vCursor CURSOR FOR SELECT DISTINCT ticketFk - FROM ticketCollection tc + FROM ticketCollection tc WHERE tc.collectionFk = vSelf; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -53400,25 +53816,25 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `company_getFiscaldata`(workerFk INT) BEGIN - + DECLARE vCompanyFk INT; - - SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) + + SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) INTO vCompanyFk FROM vn.routeConfig rc LEFT JOIN userConfig uc ON uc.userFk = workerFk; - - + + SELECT s.name AS name , s.NIF AS nif , s.street AS street , s.city AS city , - s.postCode AS postCode - - FROM vn.company c + s.postCode AS postCode + + FROM vn.company c JOIN vn.worker w ON w.id = c.workerManagerFk - JOIN vn.supplier s ON s.id = c.id + JOIN vn.supplier s ON s.id = c.id WHERE c.id = vCompanyFk; END ;; DELIMITER ; @@ -53475,7 +53891,7 @@ BEGIN IF (p.currencyFk = vCurrencyEuroFk, p.amount, p.divisa) AS amount, p.dueDated < vStartingDate isBeforeStarting, p.currencyFk - FROM payment p + FROM payment p WHERE p.received > vStartDate AND p.companyFk = vSelf UNION ALL @@ -53483,9 +53899,9 @@ BEGIN r.companyFk, - IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue) AS Total, rv.dueDated < vStartingDate isBeforeStarting, - r.currencyFk - FROM invoiceIn r - INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk + r.currencyFk + FROM invoiceIn r + INNER JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk WHERE r.issued > vStartDate AND r.isBooked AND r.companyFk = vSelf @@ -53537,11 +53953,11 @@ BEGIN -IF (r.currencyFk = vCurrencyEuroFk, rv.amount, rv.foreignValue), r.currencyFk, FALSE isPayment, - TRUE - FROM invoiceIn r + TRUE + FROM invoiceIn r LEFT JOIN tOpeningBalances si ON r.companyFk = si.companyFk AND r.supplierFk = si.supplierFk - AND r.currencyFk = si.currencyFk + AND r.currencyFk = si.currencyFk JOIN invoiceInDueDay rv ON r.id = rv.invoiceInFk WHERE rv.dueDated >= vStartingDate AND (si.closingBalances IS NULL OR si.closingBalances <> 0) @@ -53596,7 +54012,7 @@ BEGIN FROM tPendingDuedates WHERE balance < vInvalidBalances AND balance > - vInvalidBalances; - + DELETE vp.* FROM tPendingDuedates vp JOIN tRowsToDelete rd ON ( @@ -53624,9 +54040,9 @@ BEGIN FROM tPendingDuedates vp LEFT JOIN supplier s ON s.id = vp.supplierFk LEFT JOIN client c ON c.fi = s.nif - LEFT JOIN clientRisk cr ON cr.clientFk = c.id + LEFT JOIN clientRisk cr ON cr.clientFk = c.id AND cr.companyFk = vp.companyFk; - + DROP TEMPORARY TABLE tOpeningBalances; DROP TEMPORARY TABLE tPendingDuedates; DROP TEMPORARY TABLE tRowsToDelete; @@ -53638,6 +54054,79 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `comparative_add` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `comparative_add`() +BEGIN +/** + * Inserts sales records less than one month old in comparative. + */ + DECLARE vMaxPeriod INT; + DECLARE vPeriod INT; + DECLARE vWeek INT; + DECLARE vConfigPeriod INT; + DECLARE vConfigWeek INT; + + SELECT period, week INTO vConfigPeriod, vConfigWeek + FROM comparativeAddConfig; + + SELECT IFNULL(MAX(timePeriod), 0) INTO vMaxPeriod + FROM comparative; + + SELECT period - vConfigPeriod, + week + INTO vPeriod, + vWeek + FROM `time` + WHERE dated = util.VN_CURDATE(); + + IF vMaxPeriod < vPeriod AND vWeek > vConfigWeek THEN + DELETE FROM comparative WHERE timePeriod BETWEEN vMaxPeriod AND vPeriod; + + INSERT INTO comparative( + timePeriod, + itemFk, + warehouseFk, + quantity, + price, + countryFk + ) + SELECT tm.period, + s.itemFk, + t.warehouseFk, + sum(s.quantity), + sum(v.importe), + p.countryFk + FROM bs.ventas v + JOIN time tm ON tm.dated = v.fecha + JOIN sale s ON s.id = v.Id_Movimiento + JOIN itemType tp ON tp.id = v.tipo_id + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN ticket t ON t.id = s.ticketFk + JOIN client c ON c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN address ad ON ad.id = t.addressFk + LEFT JOIN province p ON p.id = ad.provinceFk + WHERE tm.period BETWEEN vMaxPeriod AND vPeriod + AND ct.code <> 'loses' + AND NOT w.code = 'inv' + GROUP BY p.countryFk, s.itemFk, tm.period, t.warehouseFk; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `conveyorExpedition_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53649,7 +54138,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `conveyorExpedition_Add`(vStarted DATETIME, vEnded DATETIME) BEGIN - + DECLARE startingMinute INT; TRUNCATE vn.conveyorExpedition; @@ -53666,23 +54155,23 @@ BEGIN conveyorBuildingClassFk) SELECT e.id, e.created, - 10 * p.depth as depth, + 10 * p.depth as depth, 10 * p.width as width, 10 * p.height as height, IFNULL(t.routeFk,am.agencyFk) routeFk, hour(e.created) * 60 + minute(e.created), IFNULL(et.description , a.name), IFNULL(t.routeFk,am.agencyFk) criterion, - IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass) + IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass) FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.packaging p ON p.id = e.packagingFk LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN vn.agency a ON a.id = am.agencyFk - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk - JOIN vn.packagingConfig pc + LEFT JOIN vn.agency a ON a.id = am.agencyFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + JOIN vn.packagingConfig pc WHERE t.warehouseFk IN (60,1,44) AND e.created BETWEEN vStarted AND vEnded AND p.height < 140 @@ -53691,8 +54180,8 @@ BEGIN SELECT MIN(productionMinute) INTO startingMinute FROM vn.conveyorExpedition ce ; - - UPDATE vn.conveyorExpedition + + UPDATE vn.conveyorExpedition SET productionMinute = productionMinute - startingMinute; END ;; @@ -53761,7 +54250,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `createPedidoInterno`(vItemFk INT,vQuantity INT) BEGIN - + UPDATE vn.item SET upToDown = vQuantity WHERE id = vItemFk; END ;; @@ -53784,52 +54273,52 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `crypt`(vText VARCHAR(255), vKey VAR BEGIN DECLARE vEncryptedText VARCHAR(255) DEFAULT ''; - + DECLARE vKeyLength INT; DECLARE vKeyPosition INT DEFAULT 1; DECLARE vKeyChar VARCHAR(1); - + DECLARE vTextLength INT; DECLARE vTextPosition INT DEFAULT 1; DECLARE vTextChar VARCHAR(1); - + DECLARE vEncryptedChar VARCHAR(1); DECLARE vEncryptedCharPosition INT; - + DECLARE vChain VARCHAR(255) DEFAULT '#$.-_0123456789abcdefghijklmnopqrstuvwxyz'; DECLARE vChainTextPosition INT; DECLARE vChainKeyPosition INT; DECLARE vChainLength INT; - + DECLARE vInvalidadChars VARCHAR(255) DEFAULT ''; - - SET vTextLength = LENGTH(vText); + + SET vTextLength = LENGTH(vText); SET vKeyLength = LENGTH(vKey); SET vChainLength = LENGTH(vChain); - + WHILE vTextPosition <= vTextLength DO - + SET vTextChar = MID(vText,vTextPosition,1); SET vKeyChar = MID(vKey,vKeyPosition,1); - + SET vChainTextPosition = LOCATE(vTextChar, vChain); SET vInvalidadChars = IF(vChainTextPosition, vInvalidadChars, CONCAT(vInvalidadChars,vTextChar)); SET vChainKeyPosition = LOCATE(vKeyChar, vChain); SET vEncryptedCharPosition = vChainTextPosition + vChainKeyPosition; - + IF vEncryptedCharPosition > vChainLength THEN - + SET vEncryptedCharPosition = vEncryptedCharPosition - vChainLength; - + END IF; - + SET vEncryptedChar = MID(vChain, vEncryptedCharPosition,1); - + SET vEncryptedText = CONCAT(vEncryptedText, vEncryptedChar); - + SET vKeyPosition = IF(vKeyPosition = vKeyLength, 1,vKeyPosition + 1); SET vTextPosition = vTextPosition + 1; - + END WHILE; SET vResult = IF(LENGTH(vInvalidadChars), CONCAT('Caracteres no válidos: ',vInvalidadChars),vEncryptedText); @@ -53854,49 +54343,49 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `cryptOff`(vText VARCHAR(255), vKey BEGIN DECLARE vUncryptedText VARCHAR(255) DEFAULT ''; - + DECLARE vKeyLength INT; DECLARE vKeyPosition INT DEFAULT 1; DECLARE vKeyChar VARCHAR(1); - + DECLARE vTextLength INT; DECLARE vTextPosition INT DEFAULT 1; DECLARE vTextChar VARCHAR(1); - + DECLARE vUncryptedChar VARCHAR(1); DECLARE vUncryptedCharPosition INT; - + DECLARE vChain VARCHAR(255) DEFAULT '#$.-_0123456789abcdefghijklmnopqrstuvwxyz'; DECLARE vChainTextPosition INT; DECLARE vChainKeyPosition INT; DECLARE vChainLength INT; - - SET vTextLength = LENGTH(vText); + + SET vTextLength = LENGTH(vText); SET vKeyLength = LENGTH(vKey); SET vChainLength = LENGTH(vChain); - + WHILE vTextPosition <= vTextLength DO - + SET vTextChar = MID(vText,vTextPosition,1); SET vKeyChar = MID(vKey,vKeyPosition,1); - + SET vChainTextPosition = LOCATE(vTextChar, vChain); SET vChainKeyPosition = LOCATE(vKeyChar, vChain); SET vUncryptedCharPosition = vChainTextPosition - vChainKeyPosition; - + IF vUncryptedCharPosition < 1 THEN - + SET vUncryptedCharPosition = vUncryptedCharPosition + vChainLength; - + END IF; - + SET vUncryptedChar = MID(vChain, vUncryptedCharPosition,1); - + SET vUncryptedText = CONCAT(vUncryptedText, vUncryptedChar); - + SET vKeyPosition = IF(vKeyPosition = vKeyLength, 1,vKeyPosition + 1); SET vTextPosition = vTextPosition + 1; - + END WHILE; SET vResult = vUncryptedText; @@ -53992,7 +54481,7 @@ BEGIN OR (vSelf IS NOT NULL AND parentFk = vSelf); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SET vSons = 0; OPEN vChildren; @@ -54003,11 +54492,11 @@ BEGIN IF vDone THEN LEAVE myLoop; END IF; - + SET vIndex = vIndex + 1; SET vLft = vIndex; SET vSons = vSons + 1; - + CALL department_calcTreeRec( vChildFk, CONCAT(vPath, vChildFk, '/'), @@ -54062,7 +54551,7 @@ proc: BEGIN SELECT isChanged INTO vIsChanged FROM department_recalc; - + IF vIsChanged THEN UPDATE department_recalc SET isChanged = FALSE; CALL vn.department_calcTree; @@ -54087,17 +54576,17 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_getHasMistake`() BEGIN - + /** * Obtiene los sectores a los cuales les ponemos errores * */ - + SELECT id, name FROM department WHERE hasToMistake <> FALSE; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54156,19 +54645,19 @@ BEGIN FROM department g JOIN tChilds c ON c.id = g.id WHERE g.parentFk IS NOT NULL; - + INSERT IGNORE INTO tNodes SELECT id FROM tParents; - + IF ROW_COUNT() = 0 THEN LEAVE myLoop; END IF; - + DELETE FROM tChilds; INSERT INTO tChilds SELECT id FROM tParents; END LOOP; - + DROP TEMPORARY TABLE tChilds, tParents; @@ -54235,12 +54724,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceProductionUser_exists`(vUserFk INT) BEGIN - + /* SELECT COUNT(*) AS UserExists - FROM vn.deviceProductionUser dpu + FROM vn.deviceProductionUser dpu WHERE dpu.userFk = vUserFk;*/ SELECT TRUE; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54312,10 +54801,10 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `device_checkLogin`(vUserFk INT, vAndroidID VARCHAR(50)) BEGIN - + /* * Comprueba si está registrado el dispositivo mediante su androidId - * + * * @param vUSerFk el id del user * @param vAndroidID es el identificador android_id del dispositivo */ @@ -54327,20 +54816,20 @@ BEGIN SELECT dpc.isAllUsersallowed INTO vIsAllUsersAllowed FROM vn.deviceProductionConfig dpc; - IF NOT vIsAllUsersAllowed THEN - + IF NOT vIsAllUsersAllowed THEN + SELECT COUNT(*) INTO vIsDepartment - FROM vn.workerDepartment dp + FROM vn.workerDepartment dp JOIN department d ON d.id = dp.departmentFk WHERE dp.workerFk = vUserFk AND d.hasToCheckLogin; - + IF vIsDepartment THEN SELECT COUNT(*) INTO vIsAuthorized - FROM vn.deviceProductionUser dpu + FROM vn.deviceProductionUser dpu JOIN vn.deviceProduction dp ON dp.id = dpu.deviceProductionFk WHERE dpu.userFk = vUserFk AND dp.android_id = vAndroidID; - + IF NOT vIsAuthorized THEN SET vMessage = 'Usuario no autorizado'; END IF; @@ -54370,15 +54859,15 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `duaEntryValueUpdate`(vDuaFk INT) BEGIN UPDATE duaEntry de - JOIN + JOIN ( SELECT b.entryFk, sum(b.quantity * b.buyingValue) as total FROM buy b JOIN duaEntry de ON de.entryFk = b.entryFk WHERE duaFk = vDuaFk GROUP BY b.entryFk ) sub ON sub.entryFk = de.entryFk - - LEFT JOIN + + LEFT JOIN (SELECT e.id, sum(iit.taxableBase) as euros FROM entry e JOIN invoiceInTax iit ON iit.invoiceInFk = e.invoiceInFk @@ -54386,11 +54875,11 @@ BEGIN WHERE de.duaFk = vDuaFk GROUP BY e.id ) sub2 ON sub2.id = de.entryFk - + SET de.value = sub.total, de.euroValue = sub2.euros WHERE duaFk = vDuaFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54414,7 +54903,7 @@ BEGIN DECLARE vInvoiceFk INT; DECLARE vASIEN BIGINT DEFAULT 0; DECLARE vCounter INT DEFAULT 0; - + DECLARE rs CURSOR FOR SELECT e.invoiceInFk FROM entry e @@ -54427,7 +54916,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN rs; - + UPDATE invoiceIn ii JOIN entry e ON e.invoiceInFk = ii.id JOIN duaEntry de ON de.entryFk = e.id @@ -54439,41 +54928,41 @@ BEGIN ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried), e.isConfirmed = TRUE WHERE d.id = vDuaFk; - + SELECT IFNULL(ASIEN,0) INTO vASIEN FROM dua WHERE id = vDuaFk; - + FETCH rs INTO vInvoiceFk; - + WHILE NOT done DO CALL invoiceIn_booking(vInvoiceFk); - + IF vCounter > 0 OR vASIEN > 0 THEN - + UPDATE vn2008.XDiario x JOIN vn.ledgerConfig lc ON lc.lastBookEntry = x.ASIEN SET x.ASIEN = vASIEN; - + ELSE - + SELECT lastBookEntry INTO vASIEN FROM vn.ledgerConfig; - + END IF; - + SET vCounter = vCounter + 1; - + FETCH rs INTO vInvoiceFk; END WHILE; - + CLOSE rs; - - UPDATE dua + + UPDATE dua SET ASIEN = vASIEN WHERE id = vDuaFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54499,9 +54988,9 @@ BEGIN SELECT awbFk,companyFk FROM dua WHERE id = vDuaFk; - + SELECT LAST_INSERT_ID() INTO vNewDuaFk; - + INSERT INTO duaEntry(duaFk, entryFk, value, customsValue) SELECT vNewDuaFk, entryFk, value, value - customsValue FROM duaEntry @@ -54530,11 +55019,11 @@ BEGIN DECLARE vBookDated DATE; DECLARE vDiff DECIMAL(10,2); DECLARE vApunte BIGINT; - + SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated - FROM dua + FROM dua WHERE id = vDuaFk; - + IF vBookNumber IS NULL OR NOT vBookNumber THEN CALL ledger_next(vBookNumber); END IF; @@ -54545,14 +55034,14 @@ BEGIN ASIEN, FECHA, SUBCTA, - CONCEPTO, + CONCEPTO, EUROHABER, SERIE, empresa_id, CLAVE, FACTURA) - SELECT + SELECT vBookNumber, d.bookEntried, '4700000999', @@ -54565,20 +55054,20 @@ BEGIN FROM duaTax dt JOIN dua d ON d.id = dt.duaFk WHERE dt.duaFk = vDuaFk; - + -- Apuntes por tipo de IVA y proveedor - + INSERT INTO XDiario( ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EURODEBE, BASEEURO, - CONCEPTO, - FACTURA, + CONCEPTO, + FACTURA, IVA, - AUXILIAR, + AUXILIAR, SERIE, FECHA_EX, FECHA_OP, @@ -54598,17 +55087,17 @@ BEGIN FECREGCON ) - SELECT + SELECT vBookNumber ASIEN, vBookDated FECHA, tr.account SUBCTA, '4330002067' CONTRA, sum(dt.tax) EURODEBE, - sum(dt.base) BASEEURO, + sum(dt.base) BASEEURO, CONCAT('DUA nº',d.code) CONCEPTO, d.id FACTURA, dt.rate IVA, - '*' AUXILIAR, + '*' AUXILIAR, 'D' SERIE, d.issued FECHA_EX, d.operated FECHA_OP, @@ -54635,10 +55124,10 @@ BEGIN WHERE ta.effectived <= vBookDated AND taxAreaFk = 'WORLD' ORDER BY ta.effectived DESC - LIMIT 10000000000000000000 + LIMIT 10000000000000000000 ) tba GROUP BY rate - ) tr ON tr.rate = dt.rate + ) tr ON tr.rate = dt.rate JOIN supplier s ON s.id = d.companyFk JOIN country c ON c.id = s.countryFk WHERE d.id = vDuaFk @@ -54647,16 +55136,16 @@ BEGIN SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte FROM XDiario WHERE ASIEN = vBookNumber; - + UPDATE XDiario SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA, - EURODEBE = EURODEBE - vDiff + EURODEBE = EURODEBE - vDiff WHERE id = vApunte; UPDATE dua SET ASIEN = vBookNumber WHERE id = vDuaFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54677,36 +55166,36 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `duaTax_doRecalc`(vDuaFk INT) BEGIN /** * Borra los valores de duaTax y los vuelve a crear en base a la tabla duaEntry - * + * * @param vDuaFk Id del dua a recalcular */ DELETE FROM duaTax WHERE duaFk = vDuaFk; - - INSERT INTO duaTax(duaFk, taxClassFk, base) + + INSERT INTO duaTax(duaFk, taxClassFk, base) SELECT vDuaFk, taxClassFk, SUM(sub.totalBase) FROM intrastat ist JOIN (SELECT i.intrastatFk, - CAST(SUM(b.quantity * - b.buyingValue * - de.customsValue / - de.value) - * di.totalAmount / + CAST(SUM(b.quantity * + b.buyingValue * + de.customsValue / + de.value) + * di.totalAmount / bi.totalAmount AS DECIMAL(10,2) ) totalBase - FROM buy b + FROM buy b JOIN item i ON i.id = b.itemFk JOIN entry e ON e.id = b.entryFk JOIN duaEntry de ON de.entryFk = e.id JOIN( SELECT i.intrastatFk, - CAST(SUM(b.quantity * - b.buyingValue * - de.customsValue / + CAST(SUM(b.quantity * + b.buyingValue * + de.customsValue / de.value) AS DECIMAL(10,2) ) totalAmount - FROM buy b + FROM buy b JOIN item i ON i.id = b.itemFk JOIN entry e ON e.id = b.entryFk JOIN duaEntry de ON de.entryFk = e.id @@ -54721,7 +55210,7 @@ BEGIN ) di ON di.intrastatFk = i.intrastatFk WHERE de.duaFk = vDuaFk GROUP BY i.intrastatFk - HAVING totalBase + HAVING totalBase )sub ON ist.id = sub.intrastatFk GROUP BY ist.taxClassFk; END ;; @@ -54742,13 +55231,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ediTables_Update`() BEGIN - - INSERT IGNORE INTO vn.genus(name) + + INSERT IGNORE INTO vn.genus(name) SELECT latin_genus_name FROM edi.genus ; - INSERT IGNORE INTO vn.specie(name) - SELECT LCASE(latin_species_name) + INSERT IGNORE INTO vn.specie(name) + SELECT LCASE(latin_species_name) FROM edi.specie ; END ;; DELIMITER ; @@ -54788,71 +55277,71 @@ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur1; read_loop: LOOP - + SET done = FALSE; SET vEntryFk = 0; - + FETCH cur1 INTO vId; - + IF done THEN LEAVE read_loop; END IF; - + SELECT IFNULL(e.id,0) INTO vEntryFk FROM vn.entry e JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyModeFk AND ea.supplierFk = e.supplierFk WHERE ea.id = vId AND tr.landed = vLanded LIMIT 1; - + IF NOT vEntryFk THEN - + SELECT IFNULL(e.id,0) INTO vEntryFk FROM vn.entry e JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyModeFk WHERE ea.id = vId AND tr.landed = vLanded AND ea.supplierFk IS NULL LIMIT 1; - + END IF; - + IF NOT vEntryFk THEN - + SET vTravelFk = 0; - - SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk + + SELECT IFNULL(MAX(tr.id),0) INTO vTravelFk FROM vn.travel tr - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyModeFk WHERE ea.id = vId AND tr.landed = vLanded; - + IF NOT vTravelFk THEN - + INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyModeFk) SELECT vLanded, vLanded, warehouseInFk, warehouseOutFk, agencyModeFk - FROM vn.ektEntryAssign + FROM vn.ektEntryAssign WHERE id = vId; - - SELECT MAX(tr.id) INTO vTravelFk + + SELECT MAX(tr.id) INTO vTravelFk FROM vn.travel tr - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk AND ea.agencyModeFk = tr.agencyFk WHERE ea.id = vId AND tr.landed = vLanded; - + END IF; - + INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk) SELECT vTravelFk, IFNULL(ea.supplierFk,s.id), c.id, cu.id FROM vn.supplier s @@ -54860,13 +55349,13 @@ OPEN cur1; JOIN vn.currency cu ON cu.code = 'EUR' JOIN vn.ektEntryAssign ea ON ea.id = vId WHERE s.name = 'KONINKLIJE COOPERATIEVE BLOEMENVEILING FLORAHOLLAN'; - - SELECT MAX(id) INTO vEntryFk + + SELECT MAX(id) INTO vEntryFk FROM vn.entry WHERE travelFk = vTravelFk; - + END IF; - + UPDATE vn.ektEntryAssign SET entryFk = vEntryFk WHERE id = vId; @@ -54874,7 +55363,7 @@ OPEN cur1; END LOOP; CLOSE cur1; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54894,18 +55383,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `energyMeter_record`(vInput INT, vActiveTime INT) BEGIN DECLARE vConsumption INT; - + SELECT consumption INTO vConsumption FROM energyInput WHERE input = vInput; - INSERT INTO vn.energyMeter - SET - `input` = vInput, - `period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'), + INSERT INTO vn.energyMeter + SET + `input` = vInput, + `period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'), `activeTime` = vActiveTime, `consumption` = CAST(IFNULL((vConsumption / 3600) * vActiveTime, 0) AS DECIMAL(10,2)) - ON DUPLICATE KEY UPDATE + ON DUPLICATE KEY UPDATE `activeTime` = `activeTime` + vActiveTime, `consumption` = `consumption` + CAST(VALUES(`consumption`) AS DECIMAL(10,2)); END ;; @@ -54928,28 +55417,28 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `entryDelivered`(vDated DATE, vEntry BEGIN DECLARE vTravelFk INT; - + SELECT travelFk INTO vTravelFk - FROM vn.entry + FROM vn.entry WHERE id = vEntryFk; - + IF (SELECT COUNT(*) FROM vn.entry WHERE travelFk = vTravelFk) = 1 THEN - + UPDATE vn.travel SET shipped = LEAST(shipped, vDated), landed = vDated WHERE id = vTravelFk; - + ELSE - + INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, ref, isDelivered, isReceived) SELECT LEAST(shipped, vDated), vDated, warehouseInFk, warehouseOutFk, agencyModeFk, CONCAT(account.myUser_getName(),' ', vEntryFk), TRUE, TRUE FROM vn.travel WHERE id = vTravelFk; - + SELECT LAST_INSERT_ID() INTO vTravelFk; - - UPDATE vn.entry - SET travelFk = vTravelFk + + UPDATE vn.entry + SET travelFk = vTravelFk WHERE id = vEntryFk; - + END IF; END ;; @@ -54975,29 +55464,29 @@ BEGIN DECLARE vEntry INT; DECLARE vBucket VARCHAR(10); DECLARE vSupplierFk INT; - + SET vSupplierFk = IF (vLandingWarehouse = 1, 850, 963); -- seleccionamos travel SELECT t.id, e.id INTO vTravel, vEntry FROM travel t LEFT JOIN entry e ON t.id = e.travelFk - WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse + WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse AND t.warehouseInFk = vLandingWarehouse AND t.agencyModeFk IS NULL AND e.supplierFk = vSupplierFk - LIMIT 1; - + LIMIT 1; + -- creamos el travel si es necesario IF IFNULL(vTravel, FALSE) = FALSE THEN INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk) VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse); SELECT LAST_INSERT_ID() INTO vTravel; END IF; - + -- creamos la Entrada si es necesario IF IFNULL(vEntry, FALSE) = FALSE THEN INSERT INTO entry (supplierFk, travelFk) VALUES (vSupplierFk, vTravel); -- proveedor 'CONFECCION ARTIFICIAL' SELECT LAST_INSERT_ID() INTO vEntry; END IF; - + -- creamos el cubo si es necesario SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; IF vBucket IS NULL THEN @@ -55007,7 +55496,7 @@ BEGIN SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; END IF; - INSERT INTO buy(itemFk,quantity, entryFk, packageFk, packing, stickers, buyingValue, price2, price3) + INSERT INTO buy(itemFk,quantity, entryFk, packagingFk, packing, stickers, buyingValue, price2, price3) SELECT itemFk, quantity, vEntry, @@ -55039,7 +55528,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_checkPackaging`(vEntryFk INT) BEGIN /** * Comprueba que los campos package y packaging no sean nulos - * + * * @param vEntryFk Id de entrada */ DECLARE vpackageOrPackingNull INT; @@ -55293,7 +55782,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55313,7 +55802,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55343,7 +55832,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_getRate`(vSelf INT) BEGIN /** - * Prepara una tabla con las tarifas aplicables en funcion de la fecha + * Prepara una tabla con las tarifas aplicables en funcion de la fecha * y el almacén * * @param vSelf Id de la tabla entry @@ -55353,7 +55842,7 @@ BEGIN DECLARE vWarehouseFk INT; SELECT t.landed, t.warehouseInFk INTO vDated, vWarehouseFk - FROM entry e + FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.id = vSelf; @@ -55460,7 +55949,7 @@ BEGIN containerFk, comissionValue, packageValue, - packageFk, + packagingFk, price1, price2, price3, @@ -55481,7 +55970,7 @@ BEGIN containerFk, comissionValue, packageValue, - packageFk, + packagingFk, price1, price2, price3, @@ -55492,7 +55981,7 @@ BEGIN FROM buy b WHERE b.entryFk = vSelf AND b.printedStickers != b.stickers; - + IF vChangeEntry THEN UPDATE buy SET stickers = printedStickers, @@ -55504,7 +55993,7 @@ BEGIN FROM item i WHERE i.description = 'MISFIT' LIMIT 1; - + INSERT INTO buy(entryFk, itemFk, quantity, @@ -55519,7 +56008,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55538,7 +56027,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55571,7 +56060,7 @@ BEGIN UPDATE entry SET gestDocFk = (SELECT gestDocFk FROM entry WHERE id = vSelf LIMIT 1) WHERE id = vNewEntryFk; - + INSERT INTO duaEntry (duaFk, entryFk) SELECT duaFk, vNewEntryFk FROM duaEntry WHERE entryFk = vSelf LIMIT 1; END ;; @@ -55645,12 +56134,12 @@ BEGIN */ DECLARE v_done BOOL DEFAULT FALSE; DECLARE vEntryFk INTEGER; - + DECLARE vCur CURSOR FOR SELECT id FROM tmp.recalcEntryCommision; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; + SET v_done = TRUE; OPEN vCur; @@ -55661,7 +56150,7 @@ BEGIN IF v_done THEN LEAVE l; END IF; - + CALL vn2008.buy_tarifas_entry(vEntryFk); END LOOP; @@ -55686,7 +56175,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitByShelving`(vShelvingFk BEGIN /** * Divide las compras entre dos entradas de acuerdo con lo ubicado en una matr�cula - * + * * @param vShelvingFk Identificador de vn.shelving * @param vFromEntryFk Entrada origen * @param vToEntryFk Entrada destino @@ -55696,49 +56185,49 @@ BEGIN DECLARE vBuyStickers INT; DECLARE vDone BOOLEAN DEFAULT FALSE; - DECLARE cur CURSOR FOR + DECLARE cur CURSOR FOR SELECT bb.id buyFk, FLOOR(ish.visible / ish.packing) ishStickers, bb.stickers buyStickers FROM vn.itemShelving ish - JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM vn.buy b WHERE b.entryFk = vFromEntryFk ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk AND bb.stickers >= FLOOR(ish.visible / ish.packing) WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci GROUP BY ish.id; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Cantidades de la matrícula que exceden la de las entradas - SELECT ish.itemFk, - i.longName, + + -- Cantidades de la matrícula que exceden la de las entradas + SELECT ish.itemFk, + i.longName, FLOOR(ish.visible / ish.packing) AS etiEnMatricula, bb.stickers etiEnEntrada FROM vn.itemShelving ish - JOIN vn.item i ON i.id = ish.itemFk - LEFT JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b + JOIN vn.item i ON i.id = ish.itemFk + LEFT JOIN (SELECT b.id, b.itemFk, b.stickers + FROM vn.buy b WHERE b.entryFk = vFromEntryFk ORDER BY b.stickers DESC LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing) GROUP BY ish.id; - + OPEN cur; read_loop: LOOP SET vDone = FALSE; - + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; - + IF vDone THEN LEAVE read_loop; END IF; - + IF vIshStickers = vBuyStickers THEN UPDATE vn.buy SET entryFk = vToEntryFk @@ -55746,9 +56235,9 @@ BEGIN ELSE UPDATE vn.buy SET stickers = stickers - vIshStickers, - quantity = stickers * packing + quantity = stickers * packing WHERE id = vBuyFk; - + INSERT INTO vn.buy(entryFk, itemFk, quantity, @@ -55763,7 +56252,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55790,7 +56279,7 @@ BEGIN comissionValue, packageValue, location, - packageFk, + packagingFk, price1, price2, price3, @@ -55828,16 +56317,16 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitMisfit`(vSelf INT) BEGIN - + /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original * a la nueva */ - + DECLARE vNewEntryFk INT; DECLARE vBuyFk INT; SELECT MAX(b.id) INTO vBuyFk - FROM vn.buy b + FROM vn.buy b JOIN vn.item i ON i.id = b.itemFk WHERE b.entryFk = vSelf AND i.description = 'MISFIT'; @@ -55846,17 +56335,17 @@ BEGIN SELECT supplierFk, dated, travelFk, currencyFk, companyFk FROM vn.entry e WHERE e.id = vSelf; + + SET vNewEntryFk = LAST_INSERT_ID(); - SET vNewEntryFk = LAST_INSERT_ID(); - - UPDATE vn.buy b + UPDATE vn.buy b SET b.entryFk = vNewEntryFk WHERE b.entryFk = vSelf AND b.id > vBuyFk; - + SELECT vNewEntryFk; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55879,7 +56368,7 @@ BEGIN * Unlock the indicated entry * @vSelf params entry id */ - UPDATE `entry` + UPDATE `entry` SET lockerUserFk = NULL, locked = NULL WHERE id = vSelf; @@ -55910,21 +56399,21 @@ BEGIN DECLARE vComission INT; CREATE OR REPLACE TEMPORARY TABLE tmp.recalcEntryCommision - SELECT e.id + SELECT e.id FROM vn.entry e JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseInFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk WHERE t.shipped >= util.VN_CURDATE() AND e.currencyFk = vCurrency; SET vComission = currency_getCommission(vCurrency); - UPDATE vn.entry e + UPDATE vn.entry e JOIN tmp.recalcEntryCommision tmp ON tmp.id = e.id SET e.commission = vComission; - SELECT `name` INTO vCurrencyName - FROM currency + SELECT `name` INTO vCurrencyName + FROM currency WHERE id = vCurrency; CALL entry_recalc(); @@ -55960,7 +56449,7 @@ BEGIN DECLARE vRouteFk INT DEFAULT 0; SELECT t.routeFk INTO vRouteFk - FROM vn.expedition exp + FROM vn.expedition exp INNER JOIN ticket t on t.id = exp.ticketFk WHERE exp.id = vExpeditionFk; @@ -56163,14 +56652,14 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_printLabel`(vSelf INT) BEGIN /** - * Calls the report_print procedure and passes it + * Calls the report_print procedure and passes it * the necessary parameters for printing. * * @param vSelf expeditioPallet id. */ DECLARE vPrinterFk INT; DECLARE vUserFk INT DEFAULT account.myUser_getId(); - + SELECT o.labelerFk INTO vPrinterFk FROM operator o WHERE o.workerFk = vUserFk; @@ -56237,22 +56726,22 @@ BEGIN DECLARE vTotal INT DEFAULT 0; IF vPalletFk = 0 THEN -- Nuevo pallet - - INSERT INTO vn.expeditionPallet(truckFk) + + INSERT INTO vn.expeditionPallet(truckFk) VALUES(vTruckFk); - + SELECT LAST_INSERT_ID() INTO vPalletFk; - + END IF; - + SELECT COUNT(expeditionFk) INTO vTotal FROM vn.expeditionScan WHERE palletFk = vPalletFk; - + IF vTotal <> 0 THEN - SELECT expeditionFk, + SELECT expeditionFk, palletFk - FROM vn.expeditionScan + FROM vn.expeditionScan WHERE palletFk = vPalletFk; - ELSE + ELSE SELECT 0 expeditionFk,vPalletFk palletFk; END IF; END ;; @@ -56325,12 +56814,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionScan_Put`(vPalletFk INT, vExpeditionFk INT) BEGIN - - REPLACE vn.expeditionScan(expeditionFk, palletFk) + + REPLACE vn.expeditionScan(expeditionFk, palletFk) VALUES(vExpeditionFk, vPalletFk); - + SELECT LAST_INSERT_ID() INTO vPalletFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56349,32 +56838,32 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_add`(vParam INT, vStateCode VARCHAR(100)) BEGIN - + /** * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro - * + * * @param vParam Identificador de vn.expedition o de vn.route * @param vStateCode Corresponde a vn.expeditionStateType.code */ - + IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT e.id, est.id FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.expeditionStateType est ON est.code = vStateCode WHERE t.routeFk = vParam; - + ELSE - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT vParam, est.id FROM vn.expeditionStateType est WHERE est.code = vStateCode; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56406,7 +56895,7 @@ BEGIN SELECT e.id, est.id FROM vn.expedition e JOIN vn.expeditionStateType est ON est.code = vStateCode - JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk; END ;; @@ -56427,14 +56916,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByExpedition`(vExpeditionFk INT, vStateCode VARCHAR(100)) BEGIN - + /** * Inserta nuevos registros en la tabla vn.expeditionState - * + * * @param vExpeditionFk Identificador de vn.expedition * @param vStateCode Corresponde a vn.expeditionStateType.code */ - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT vExpeditionFk, est.id FROM vn.expeditionStateType est @@ -56460,7 +56949,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByPallet`(vPalle BEGIN /** * Inserta nuevos registros en la tabla vn.expeditionState - * + * * @param vPalletFk Identificador de vn.expedition * @param vStateCode Corresponde a vn.expeditionStateType.code */ @@ -56477,7 +56966,7 @@ BEGIN IF NOT hasExpeditions THEN DROP TEMPORARY TABLE tExpeditionScan; - CALL util.throw('palletDoesNotExist'); + CALL util.throw('palletDoesNotExist'); END IF; INSERT INTO vn.expeditionState(expeditionFk, typeFk) @@ -56502,21 +56991,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByRoute`(vRouteFk INT, vStateCode VARCHAR(100)) BEGIN - + /** * Inserta nuevos registros en la tabla vn.expeditionState, por rutas - * + * * @param vRouteFk Identificador de vn.route * @param vStateCode Corresponde a vn.expeditionStateType.code */ - + INSERT INTO vn.expeditionState(expeditionFk, typeFk) SELECT e.id, est.id FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.expeditionStateType est ON est.code = vStateCode WHERE t.routeFk = vRouteFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56558,8 +57047,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionTruck_List`() BEGIN - SELECT id truckFk, - eta, + SELECT id truckFk, + eta, description Destino FROM expeditionTruck WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) @@ -56603,7 +57092,7 @@ BEGIN JOIN address a ON t.addressFk = a.id JOIN route r ON r.id = t.routeFk LEFT JOIN warehouse w ON t.warehouseFk = w.id - LEFT JOIN (SELECT sub.ticketFk, + LEFT JOIN (SELECT sub.ticketFk, CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeConcat FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items FROM ticket t @@ -56634,7 +57123,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_getState`(vExpeditionFk INT) BEGIN - + DECLARE vTicketsPendientes INT; DECLARE vEtiquetasTotales INT; DECLARE vEtiquetasEscaneadas INT; @@ -56644,24 +57133,24 @@ BEGIN FROM vn.ticket t JOIN vn.expedition e ON e.ticketFk = t.id WHERE e.id = vExpeditionFk; - + SELECT COUNT(*) INTO vTicketsPendientes FROM vn.ticket t LEFT JOIN vn.expedition e ON e.ticketFk = t.id WHERE t.routeFk = vRouteFk AND ISNULL(e.id); - + SELECT COUNT(*) INTO vEtiquetasTotales - FROM vn.expedition e + FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT COUNT(*) INTO vEtiquetasEscaneadas - FROM vn.expeditionScan es + FROM vn.expeditionScan es JOIN vn.expedition e ON e.id = es.expeditionFk - JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT e.ticketFk ticket, t.nickname cliente, a.city ciudad, @@ -56675,17 +57164,17 @@ BEGIN vTicketsPendientes AS ticketsPendientes, vEtiquetasTotales AS etiquetasTotales, vEtiquetasEscaneadas AS etiquetasEscaneadas - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.`zone`z ON z.id = t.zoneFk - LEFT JOIN vn.route r ON r.id = t.routeFk - LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk WHERE e.id = vExpeditionFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56704,12 +57193,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_StateGet`(vExpeditionFk INT) BEGIN - + /* Devuelve una "ficha" con todos los datos relativos a la expedición - * - * param vExpeditionFk + * + * param vExpeditionFk */ - + DECLARE vTicketsPendientes INT; DECLARE vEtiquetasTotales INT; DECLARE vEtiquetasEscaneadas INT; @@ -56720,34 +57209,34 @@ BEGIN FROM vn.ticket t JOIN vn.expedition e ON e.ticketFk = t.id WHERE e.id = vExpeditionFk; - + SELECT COUNT(*) INTO vTicketsPendientes FROM vn.ticket t LEFT JOIN vn.expedition e ON e.ticketFk = t.id WHERE t.routeFk = vRouteFk AND ISNULL(e.id); - + SELECT COUNT(*) INTO vEtiquetasTotales - FROM vn.expedition e + FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT COUNT(*) INTO vEtiquetasEscaneadas - FROM vn.expeditionScan es + FROM vn.expeditionScan es JOIN vn.expedition e ON e.id = es.expeditionFk - JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.ticket t ON t.id = e.ticketFk WHERE t.routeFk = vRouteFk; - + SELECT COUNT(*) INTO vEtiquetasLeidasSorter - FROM srt.expedition e + FROM srt.expedition e JOIN vn.expedition ve ON ve.id = e.id LEFT JOIN vn.expeditionScan es ON es.expeditionFk = e.id - JOIN vn.ticket t ON t.id = ve.ticketFk + JOIN vn.ticket t ON t.id = ve.ticketFk WHERE t.routeFk = vRouteFk AND e.created != e.updated - AND ISNULL(es.expeditionFk); - - + AND ISNULL(es.expeditionFk); + + SELECT e.ticketFk ticket, t.nickname cliente, a.city ciudad, @@ -56762,17 +57251,17 @@ BEGIN vEtiquetasTotales AS etiquetasTotales, vEtiquetasEscaneadas AS etiquetasEscaneadas, vEtiquetasLeidasSorter AS etiquetasSorter - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.`zone`z ON z.id = t.zoneFk - LEFT JOIN vn.route r ON r.id = t.routeFk - LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk WHERE e.id = vExpeditionFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56818,7 +57307,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControl`(vFromDated DATE, vToDated DATE) BEGIN - + DECLARE vSijsnerClientFk INT DEFAULT 19752; DECLARE vDateStart DATETIME; @@ -56827,68 +57316,68 @@ BEGIN SET vDateStart = vFromDated; SET vDateEnd = util.Dayend(vToDated); - SELECT p.id FustCode, - CAST(sent.stucks AS DECIMAL(10,0)) FH, - CAST(tp.stucks AS DECIMAL(10,0)) Tickets, - CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, + SELECT p.id FustCode, + CAST(sent.stucks AS DECIMAL(10,0)) FH, + CAST(tp.stucks AS DECIMAL(10,0)) Tickets, + CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo FROM vn.packaging p LEFT JOIN ( SELECT FustCode, sum(fustQuantity) stucks FROM ( SELECT IFNULL(pe.equivalentFk ,b.packagingFk) FustCode, s.quantity / b.packing AS fustQuantity - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk - JOIN vn.buy b ON b.id = lb.buy_id - JOIN vn.packaging p ON p.id = b.packagingFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk + JOIN vn.buy b ON b.id = lb.buy_id + JOIN vn.packaging p ON p.id = b.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk WHERE t.shipped BETWEEN vDateStart AND vDateEnd AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA') sub + AND p.isPackageReturnable + AND c.country = 'FRANCIA') sub GROUP BY FustCode) sent ON sent.FustCode = p.id LEFT JOIN ( SELECT FustCode, sum(quantity) stucks FROM ( SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk WHERE t.shipped BETWEEN vDateStart AND vDateEnd AND wa.name = 'VNH' - AND p.isPackageReturnable + AND p.isPackageReturnable AND c.country = 'FRANCIA' AND t.clientFk != vSijsnerClientFk - AND tp.quantity > 0) sub + AND tp.quantity > 0) sub GROUP BY FustCode) tp ON tp.FustCode = p.id LEFT JOIN ( SELECT FustCode, sum(quantity) stucks FROM ( SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) AND wa.name = 'VNH' - AND p.isPackageReturnable - AND t.clientFk = vSijsnerClientFk) sub + AND p.isPackageReturnable + AND t.clientFk = vSijsnerClientFk) sub GROUP BY FustCode) sj ON sj.FustCode = p.id - WHERE sent.stucks + WHERE sent.stucks OR tp.stucks OR sj.stucks; @@ -56910,7 +57399,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControlDetail`(vFromDated DATE, vToDated DATE) BEGIN - + DECLARE vSijsnerClientFk INT DEFAULT 19752; DECLARE vDateStart DATETIME; @@ -56918,29 +57407,29 @@ BEGIN SET vDateStart = vFromDated; SET vDateEnd = util.Dayend(vToDated); - + SELECT a.nickname shopName, - a.city , - IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, + a.city , + IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity, tp.ticketFk, CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - JOIN vn.packaging p ON p.id = tp.packagingFk + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + JOIN vn.packaging p ON p.id = tp.packagingFk LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p2 ON p2.id = a.provinceFk - JOIN vn.country c ON c.id = p2.countryFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p2 ON p2.id = a.provinceFk + JOIN vn.country c ON c.id = p2.countryFk WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated) AND wa.name = 'VNH' - AND p.isPackageReturnable + AND p.isPackageReturnable AND c.country = 'FRANCIA' AND t.clientFk != vSijsnerClientFk AND tp.quantity > 0; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56966,8 +57455,8 @@ DECLARE vTicketFk INT; DECLARE vSaleFk INT; DECLARE vClonTicket INT DEFAULT 0; -DECLARE cur1 CURSOR FOR -SELECT s.ticketFk, s.id +DECLARE cur1 CURSOR FOR +SELECT s.ticketFk, s.id FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.item i ON i.id = s.itemFk @@ -56983,17 +57472,17 @@ OPEN cur1; FETCH cur1 INTO vTicketFk, vSaleFk; WHILE done = 0 DO - + SELECT t.id INTO vClonTicket FROM vn.ticket t JOIN (SELECT addressFk, shipped FROM vn.ticket WHERE id = vTicketFk) sub USING(addressFk, shipped) WHERE t.warehouseFk = 44 LIMIT 1; - + SELECT vTicketFk, vClonTicket; - + IF vClonTicket = 0 THEN - + INSERT INTO ticket ( clientFk, shipped, @@ -57021,12 +57510,12 @@ FETCH cur1 INTO vTicketFk, vSaleFk; zonePrice, zoneBonus, routeFk - + FROM ticket WHERE id = vTicketFk; SET vClonTicket = LAST_INSERT_ID(); - + SELECT 'lstID', vClonTicket; /* INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) @@ -57036,20 +57525,20 @@ FETCH cur1 INTO vTicketFk, vSaleFk; WHERE t.id = vClonTicket; */ INSERT INTO ticketLog - SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert', + SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vClonTicket, ' clonando el ', vTicketFk); - + END IF; - + UPDATE vn.sale SET ticketFk = vClonTicket WHERE id = vSaleFk; SET vClonTicket = 0; - + SET done = 0; FETCH cur1 INTO vTicketFk, vSaleFk; - + END WHILE; CLOSE cur1; @@ -57074,8 +57563,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `getDayExpeditions`() BEGIN - SELECT - e.expeditions_id as expeditionFk, + SELECT + e.expeditions_id as expeditionFk, date_format(e.odbc_date,'%Y-%m-%d') as expeditionDate, e.ticket_id as ticketFk, t.routeFk as routeFk @@ -57127,6 +57616,51 @@ BEGIN SELECT id,name as description,upToDown as quantity FROM vn.item WHERE upToDown; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `getTaxBases` */; +/*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `getTaxBases`() +BEGIN +/** +* Calcula y devuelve en número de bases imponibles postivas y negativas +* Requiere la tabla temporal tmp.ticketToInvoice(id) +* +* returns tmp.taxBases +*/ + + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM tmp.ticketToInvoice; + + CALL ticket_getTax(NULL); + + DROP TEMPORARY TABLE IF EXISTS tmp.taxBases; + CREATE TEMPORARY TABLE tmp.taxBases + ENGINE = MEMORY + SELECT + SUM(taxableBase > 0) as positive, + SUM(taxableBase < 0) as negative + FROM( + SELECT SUM(taxableBase) taxableBase + FROM tmp.ticketTax + GROUP BY pgcFk + ) t; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -57152,7 +57686,7 @@ BEGIN SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL yearsToDelete YEAR) INTO vDated FROM vn.greugeConfig; - + INSERT INTO vn.greuge(clientFk, description, amount, shipped, created, greugeTypeFk) SELECT clientFk, 'Suma agrupada', SUM(amount), MAX(shipped), MAX(created), greugeTypeFk FROM vn.greuge @@ -57270,8 +57804,8 @@ DECLARE done BOOL DEFAULT FALSE; DECLARE vTicketFk INT; DECLARE rs CURSOR FOR - SELECT id FROM vn.ticket - WHERE shipped = util.yesterday() + SELECT id FROM vn.ticket + WHERE shipped = util.yesterday() AND clientFk = 400 AND warehouseFk IN (1,44); @@ -57282,13 +57816,13 @@ OPEN rs; FETCH rs INTO vTicketFk; WHILE NOT done DO - + INSERT INTO vn.inventoryFailure(dated, itemFk, quantity, value, warehouseFk, throwerFk) - SELECT t.shipped, - s.itemFk, - s.quantity, + SELECT t.shipped, + s.itemFk, + s.quantity, b.buyingValue + b.freightValue + b.packageValue + b.comissionValue, - t.warehouseFk, + t.warehouseFk, w.id FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id @@ -57299,7 +57833,7 @@ WHILE NOT done DO AND s.quantity > 0; FETCH rs INTO vTicketFk; - + END WHILE; @@ -57442,7 +57976,7 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.inventory ( itemFk INT(11) NOT NULL PRIMARY KEY, quantity int(11) DEFAULT '0', - buyingValue decimal(10,3) DEFAULT '0.000', + buyingValue decimal(10,4) DEFAULT '0.0000', freightValue decimal(10,3) DEFAULT '0.000', packing int(11) DEFAULT '0', `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', @@ -57640,7 +58174,7 @@ BEGIN b.id AS buyFk, b.entryFk, b.isIgnored, - b.price2, + b.price2, b.price3, b.stickers, b.packing, @@ -57654,20 +58188,20 @@ BEGIN s.id AS supplierFk, s.name AS supplier FROM itemType it - RIGHT JOIN (entry e + RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk RIGHT JOIN buy b ON b.entryFk = e.id LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk + LEFT JOIN ink ON ink.id = i.inkFk LEFT JOIN travel tr ON tr.id = e.travelFk LEFT JOIN warehouse w ON w.id = tr.warehouseInFk LEFT JOIN origin o ON o.id = i.originFk ) ON it.id = i.typeFk LEFT JOIN edi.ekt ek ON b.ektFk = ek.id WHERE (b.packagingFk = "--" OR b.price2 = 0 OR b.packing = 0 OR b.buyingValue = 0) AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())) AND s.name = 'INVENTARIO'; - + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOk; - CREATE TEMPORARY TABLE tmp.lastEntryOk + CREATE TEMPORARY TABLE tmp.lastEntryOk (PRIMARY KEY (buyFk)) SELECT i.id AS itemFk, @@ -57677,7 +58211,7 @@ BEGIN b.id AS buyFk, b.entryFk, b.isIgnored, - b.price2, + b.price2, b.price3, b.stickers, b.packing, @@ -57691,11 +58225,11 @@ BEGIN s.id AS supplierFk, s.name AS supplier FROM itemType it - RIGHT JOIN (entry e + RIGHT JOIN (entry e LEFT JOIN supplier s ON s.id = e.supplierFk RIGHT JOIN buy b ON b.entryFk = e.id LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk + LEFT JOIN ink ON ink.id = i.inkFk LEFT JOIN travel tr ON tr.id = e.travelFk LEFT JOIN warehouse w ON w.id = tr.warehouseInFk LEFT JOIN origin o ON o.id = i.originFk @@ -57703,34 +58237,34 @@ BEGIN LEFT JOIN edi.ekt ek ON b.ektFk = ek.id WHERE b.packagingFk != "--" AND b.price2 != 0 AND b.packing != 0 AND b.buyingValue > 0 AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-2,util.VN_CURDATE())) ORDER BY tr.landed DESC; - + DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOkGroup; - CREATE TEMPORARY TABLE tmp.lastEntryOkGroup + CREATE TEMPORARY TABLE tmp.lastEntryOkGroup (INDEX (warehouseFk,itemFk)) SELECT * FROM tmp.lastEntryOk tmp GROUP BY tmp.itemFk,tmp.warehouseFk; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.packagingFk = eo.packagingFk WHERE b.packagingFk = "--"; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.price2 = eo.price2 WHERE b.price2 = 0 ; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.packing = eo.packing WHERE b.packing = 0; - + UPDATE buy b JOIN tmp.lastEntry lt ON lt.buyFk = b.id JOIN tmp.lastEntryOkGroup eo ON eo.itemFk = lt.itemFk AND eo.warehouseFk = lt.warehouseFk SET b.buyingValue = eo.buyingValue WHERE b.buyingValue = 0; - + DROP TEMPORARY TABLE tmp.lastEntry; DROP TEMPORARY TABLE tmp.lastEntryOk; DROP TEMPORARY TABLE tmp.lastEntryOkGroup; @@ -57798,7 +58332,7 @@ BEGIN DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()); - SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate); + SET vMaxTicketDate = util.dayEnd(vMaxTicketDate); DROP TEMPORARY TABLE IF EXISTS `tmp`.`ticketToInvoice`; @@ -57890,7 +58424,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInDueDay_calculate`(vInvoiceInFk INT) BEGIN /** - * Calcula los vctos. de una factura recibida + * Calcula los vctos. de una factura recibida * En caso de haberlos informado previamente o que el proveedor sea español, no los recalculará * * @param vInvoiceInFk Factura recibida @@ -57911,46 +58445,46 @@ BEGIN WHERE ii.id = vInvoiceInFk; SELECT COUNT(*) INTO vHasDueDay - FROM invoiceInDueDay iid + FROM invoiceInDueDay iid WHERE iid.invoiceInFk = vInvoiceInFk; IF NOT vHasDueDay AND vCompanyCountryCode = 'ES' THEN SET @cont := 0; INSERT INTO invoiceInDueDay ( - invoiceInFk, - dueDated, - amount, + invoiceInFk, + dueDated, + amount, foreignValue ) SELECT vInvoiceInFk, - IF(payDay, + IF(payDay, IF(getNextDueDate(issued, pdd.detail, payDay) < created, created, - getNextDueDate(issued, pdd.detail, payDay)), + getNextDueDate(issued, pdd.detail, payDay)), GREATEST(created, issued + INTERVAL pdd.detail DAY)), - IF((@cont := @cont + 1) < cont, - TRUNCATE(venc / cont, 2), - venc - (TRUNCATE(venc / cont, 2) * (cont - 1))), - IF(@cont < cont, - TRUNCATE(foreignValue / cont, 2), - foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) - FROM ( - SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100) * vHasDueDayTax) - * iit.taxableBase) / COUNT(DISTINCT(pdd.detail)) venc, + IF((@cont := @cont + 1) < cont, + TRUNCATE(venc / cont, 2), + venc - (TRUNCATE(venc / cont, 2) * (cont - 1))), + IF(@cont < cont, + TRUNCATE(foreignValue / cont, 2), + foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) + FROM ( + SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100) * vHasDueDayTax) + * iit.taxableBase) / COUNT(DISTINCT(pdd.detail)) venc, SUM(iit.foreignValue) / COUNT(DISTINCT(pdd.detail)) foreignValue, - s.payDemFk, + s.payDemFk, ii.companyFk, COUNT(DISTINCT(pdd.detail)) cont, s.payDay, ii.issued, DATE(ii.created) + INTERVAL 2 DAY created - FROM invoiceIn ii - JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id - LEFT JOIN sage.TiposIva ti ON ti.CodigoIva= iit.taxTypeSageFk - JOIN supplier s ON s.id = ii.supplierFk - JOIN payDemDetail pdd ON pdd.id = s.payDemFk - WHERE ii.id = vInvoiceInFk + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + LEFT JOIN sage.TiposIva ti ON ti.CodigoIva= iit.taxTypeSageFk + JOIN supplier s ON s.id = ii.supplierFk + JOIN payDemDetail pdd ON pdd.id = s.payDemFk + WHERE ii.id = vInvoiceInFk GROUP BY ii.id )sub JOIN payDemDetail pdd ON pdd.id = sub.payDemFk @@ -57978,9 +58512,9 @@ BEGIN DELETE FROM invoiceInDueDay WHERE invoiceInFk = vInvoiceInFk; - + CALL invoiceInDueDay_calculate(vInvoiceInFk); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -58053,14 +58587,15 @@ BEGIN DECLARE vLines INT; SELECT taxRowLimit INTO vTaxRowLimit FROM invoiceInConfig; - + SELECT COUNT(*) INTO vLines FROM invoiceInTax - WHERE invoiceInFk = vInvoiceInFk; - - IF vLines >= vTaxRowLimit THEN + WHERE invoiceInFk = vInvoiceInFk + AND (taxTypeSageFk OR transactionTypeSageFk); + + IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); - END IF; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -58099,7 +58634,7 @@ BEGIN CALL invoiceInTax_getFromEntries(vInvoiceInFk); CALL invoiceInDueDay_calculate(vInvoiceInFk); - + FETCH rs INTO vInvoiceInFk; END WHILE; @@ -58131,7 +58666,7 @@ BEGIN SELECT MAX(rr.dated) INTO vDated FROM referenceRate rr JOIN invoiceIn ii ON ii.id = vId - WHERE rr.dated <= ii.issued + WHERE rr.dated <= ii.issued AND rr.currencyFk = ii.currencyFk ; IF vDated THEN @@ -58140,13 +58675,13 @@ BEGIN WHERE dated = vDated; END IF; - SELECT id INTO vExpenseFk - FROM vn.expense - WHERE `name` = 'Adquisición mercancia Extracomunitaria' - GROUP BY id + SELECT id INTO vExpenseFk + FROM vn.expense + WHERE `name` = 'Adquisición mercancia Extracomunitaria' + GROUP BY id LIMIT 1; - - DELETE FROM invoiceInTax + + DELETE FROM invoiceInTax WHERE invoiceInFk = vId; INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, foreignValue, taxTypeSageFk, transactionTypeSageFk) @@ -58160,9 +58695,9 @@ BEGIN JOIN entry e ON e.invoiceInFk = ii.id JOIN supplier s ON s.id = e.supplierFk JOIN buy b ON b.entryFk = e.id - LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk + LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk AND rr.dated = ii.issued - WHERE ii.id = vId + WHERE ii.id = vId HAVING taxableBase IS NOT NULL; END ;; DELIMITER ; @@ -58189,7 +58724,7 @@ BEGIN SELECT ii.bookEntried, iit.foreignValue, ii.companyFk, - ii.expenseFkDeductible, + ii.expenseFkDeductible, iit.taxableBase, iit.transactionTypeSageFk, ii.serial, @@ -58228,7 +58763,7 @@ BEGIN JOIN country c ON c.id = s.countryFk JOIN supplier sc ON sc.id = ii.companyFk JOIN country cc ON cc.id = sc.countryFk - JOIN invoiceInSerial iis ON iis.code = ii.serial + JOIN invoiceInSerial iis ON iis.code = ii.serial JOIN siiTypeInvoiceIn cit ON cit.id = ii.siiTypeInvoiceInFk LEFT JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id LEFT JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = iit.transactionTypeSageFk @@ -58251,18 +58786,18 @@ BEGIN NFACTICK, CLAVE, empresa_id) - SELECT + SELECT vBookNumber ASIEN, tii.bookEntried FECHA, tii.supplierAccount SUBCTA, - SUM(tii.taxableBase * - IF(tii.serial= 'R' AND ((tii.taxCode IS NULL OR tii.taxCode <> 'ISP21') - AND tii.taxTypeSageFk IS NOT NULL), - 1 + (tii.PorcentajeIva / 100), - 1)) EUROHABER, - CONCAT('s/fra', - RIGHT(tii.supplierRef, 8), - ':', + SUM(tii.taxableBase * + IF(tii.serial= 'R' AND ((tii.taxCode IS NULL OR tii.taxCode <> 'ISP21') + AND tii.taxTypeSageFk IS NOT NULL), + 1 + (tii.PorcentajeIva / 100), + 1)) EUROHABER, + CONCAT('s/fra', + RIGHT(tii.supplierRef, 8), + ':', LEFT(tii.supplierName, 10)) CONCEPTO, CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10,4)) CAMBIO, SUM(tii.foreignValue * IF(tii.serial = 'R', 1 + (tii.PorcentajeIva / 100), 1)) HABERME, @@ -58279,7 +58814,7 @@ BEGIN CONTRA, EURODEBE, EUROHABER, - CONCEPTO, + CONCEPTO, CAMBIO, DEBEME, HABERME, @@ -58291,9 +58826,9 @@ BEGIN tii.supplierAccount CONTRA, IF(tii.isWithheld AND tii.taxableBase < 0, NULL, ROUND(SUM(tii.taxableBase),2)) EURODEBE, IF(tii.isWithheld AND tii.taxableBase < 0, ROUND(SUM(-tii.taxableBase), 2), NULL) EUROHABER, - CONCAT('s/fra', - RIGHT(tii.supplierRef, 8), - ':', + CONCAT('s/fra', + RIGHT(tii.supplierRef, 8), + ':', LEFT(tii.supplierName, 10)) CONCEPTO, CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10, 4)) CAMBIO, IF(tii.isWithheld, NULL,ABS(ROUND(SUM(tii.foreignValue), 2))) DEBEME, @@ -58305,17 +58840,17 @@ BEGIN GROUP BY tii.expenseFk; -- Líneas de IVA - INSERT INTO XDiario( + INSERT INTO XDiario( ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EURODEBE, BASEEURO, CONCEPTO, - FACTURA, + FACTURA, IVA, - AUXILIAR, + AUXILIAR, SERIE, TIPOOPE, FECHA_EX, @@ -58364,28 +58899,28 @@ BEGIN tii.companyFk FROM tInvoiceIn tii LEFT JOIN ( - SELECT e.id + SELECT e.id FROM tInvoiceIn tii - JOIN expense e ON e.id = tii.expenseFk + JOIN expense e ON e.id = tii.expenseFk WHERE e.isWithheld LIMIT 1 - ) eWithheld ON TRUE - WHERE tii.taxTypeSageFk IS NOT NULL - AND (tii.taxCode IS NULL OR tii.taxCode NOT IN ('import10', 'import21')) + ) eWithheld ON TRUE + WHERE tii.taxTypeSageFk IS NOT NULL + AND (tii.taxCode IS NULL OR tii.taxCode NOT IN ('import10', 'import21')) GROUP BY tii.PorcentajeIva, tii.expenseFk; -- Línea iva inversor sujeto pasivo - INSERT INTO XDiario( + INSERT INTO XDiario( ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EUROHABER, BASEEURO, CONCEPTO, - FACTURA, + FACTURA, IVA, - AUXILIAR, + AUXILIAR, SERIE, TIPOOPE, FECHA_EX, @@ -58434,31 +58969,31 @@ BEGIN JOIN sage.config c WHERE tii.taxCode = 'ISP21' OR MID(tii.supplierAccount, 4, 1) = '1' AND tii.taxTypeSageFk IS NOT NULL - AND NOT(tii.isVies - AND c.nontaxableTransactionTypeFk = tii.transactionTypeSageFk + AND NOT(tii.isVies + AND c.nontaxableTransactionTypeFk = tii.transactionTypeSageFk AND tii.taxCode = 'nonTaxable') GROUP BY tii.PorcentajeIva, tii.expenseFk; - - -- Actualización del registro original + + -- Actualización del registro original UPDATE invoiceIn ii SET ii.isBooked = TRUE WHERE ii.id = vSelf; - + -- Problemas derivados de la precisión en los decimales al calcular los impuestos - UPDATE XDiario - SET EURODEBE = EURODEBE - + UPDATE XDiario + SET EURODEBE = EURODEBE - (SELECT IF(ABS(sub.difference) = 0.01, sub.difference, 0) FROM( - SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference + SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference FROM XDiario WHERE ASIEN = vBookNumber )sub ) - WHERE ASIEN = vBookNumber + WHERE ASIEN = vBookNumber AND EURODEBE <> 0 ORDER BY id DESC LIMIT 1; - + DROP TEMPORARY TABLE tInvoiceIn; END ;; DELIMITER ; @@ -58573,7 +59108,7 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS rs; CREATE TEMPORARY TABLE rs - SELECT + SELECT c.accountingAccount AS clientBookingAccount, io.amount as totalAmount, CONCAT('n/fra ', io.ref) as simpleConcept, @@ -58607,19 +59142,19 @@ BEGIN WHERE io.id = vInvoice; CALL vn.ledger_next(vBookNumber); - + -- Linea del cliente INSERT INTO XDiario( ASIEN, FECHA, - SUBCTA, + SUBCTA, EURODEBE, - CONCEPTO, + CONCEPTO, FECHA_EX, FECHA_OP, empresa_id ) - SELECT + SELECT vBookNumber AS ASIEN, rs.FECHA, rs.clientBookingAccount AS SUBCTA, @@ -58635,14 +59170,14 @@ BEGIN ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EUROHABER, - CONCEPTO, + CONCEPTO, FECHA_EX, FECHA_OP, empresa_id ) - SELECT + SELECT vBookNumber AS ASIEN, rs.FECHA, ioe.expenseFk AS SUBCTA, @@ -58656,8 +59191,8 @@ BEGIN JOIN invoiceOutExpense ioe WHERE ioe.invoiceOutFk = vInvoice; - SELECT GROUP_CONCAT(`name` SEPARATOR ',') - INTO vExpenseConcept + SELECT GROUP_CONCAT(`name` SEPARATOR ',') + INTO vExpenseConcept FROM expense e JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id WHERE ioe.invoiceOutFk = vInvoice; @@ -58667,7 +59202,7 @@ BEGIN ASIEN, FECHA, SUBCTA, - CONTRA, + CONTRA, EUROHABER, BASEEURO, CONCEPTO, @@ -58695,7 +59230,7 @@ BEGIN TIPORECTIF, empresa_id ) - SELECT + SELECT vBookNumber AS ASIEN, rs.FECHA, iot.pgcFk AS SUBCTA, @@ -58715,11 +59250,11 @@ BEGIN rs.FECHA_OP, rs.FECHA_EX, rs.TIPOOPE, - rs.NFACTICK, + rs.NFACTICK, rs.TERIDNIF, rs.TERNIF, rs.TERNOM, - pgc.mod340 AS L340, + pgc.mod340 AS L340, pgc.siiTrascendencyInvoiceOutFk AS TIPOCLAVE, pgc.cplusTaxBreakFk as TIPOEXENCI, rs.TIPONOSUJE, @@ -58727,13 +59262,13 @@ BEGIN rs.TIPORECTIF, rs.companyFk AS empresa_id FROM rs - JOIN invoiceOutTax iot + JOIN invoiceOutTax iot JOIN pgc ON pgc.code = iot.pgcFk LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado - LEFT JOIN pgc pgce ON pgce.code = pe.equFk + LEFT JOIN pgc pgce ON pgce.code = pe.equFk LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv. WHERE iot.invoiceOutFk = vInvoice; - + UPDATE invoiceOut SET booked = util.VN_CURDATE() WHERE id = vInvoice; @@ -58765,7 +59300,7 @@ BEGIN DECLARE done BOOL DEFAULT FALSE; - DECLARE rs CURSOR FOR + DECLARE rs CURSOR FOR SELECT io.id FROM invoiceOut io WHERE RIGHT(ref,7) BETWEEN 1724215 AND 1724224 @@ -58780,15 +59315,15 @@ BEGIN WHILE NOT done DO CALL invoiceOutBooking(vInvoice); - + FETCH rs INTO vInvoice ; - + SET vContador = vContador + 1; - + IF vContador MOD 50 = 0 THEN - + SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS; - + END IF; END WHILE; @@ -58816,7 +59351,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE) BEGIN -SELECT +SELECT c.socialName as RazonSocial, c.fi as NIF, io.ref as Factura, @@ -58828,7 +59363,7 @@ SELECT pgc.rate as Tipo, iot.vat as Cuota, pgc.name as Concepto - + FROM vn.invoiceOut io JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id JOIN vn.client c ON c.id = io.clientFk @@ -59132,17 +59667,17 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador + SELECT s.id, ti.id ticket_id, vWorker Id_Trabajador FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticket + LEFT JOIN ticketState ts ON ti.id = ts.ticketFk JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); + WHERE IFNULL(ts.alertLevel, 0) < 3 and s.`code` = getAlert3State(ti.id); - INSERT INTO ticketTracking(stateFk,ticketFk,workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT * FROM tmp.updateInter; CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); + CALL invoiceTaxMake(vNewInvoiceId, vTaxArea); UPDATE invoiceOut io JOIN ( @@ -59273,17 +59808,17 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_newFromClient`( - IN vClientFk INT, - IN vSerial CHAR(2), + IN vClientFk INT, + IN vSerial CHAR(2), IN vMaxShipped DATE, - IN vCompanyFk INT, + IN vCompanyFk INT, IN vTaxArea VARCHAR(25), - IN vRef VARCHAR(25), + IN vRef VARCHAR(25), OUT vInvoiceId INT) BEGIN /** * Factura los tickets de un cliente hasta una fecha dada - * @param vClientFk Id del cliente a facturar + * @param vClientFk Id del cliente a facturar * @param vSerial Serie de factura * @param vMaxShipped Fecha hasta la cual cogera tickets para facturar * @param vCompanyFk Id de la empresa desde la que se factura @@ -59302,11 +59837,11 @@ BEGIN IF NOT vIsRefEditable THEN CALL util.throw('serial non editable'); END IF; - END IF; + END IF; SELECT COUNT(*) INTO vIsExportation FROM vn.invoiceOutSerial - WHERE taxAreaFk = 'WORLD' + WHERE taxAreaFk = 'WORLD' AND `code` = vSerial; IF vIsExportation THEN @@ -59319,7 +59854,7 @@ BEGIN UPDATE invoiceOut SET `ref` = vRef - WHERE id = vInvoiceId + WHERE id = vInvoiceId AND vRef IS NOT NULL; IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN @@ -59348,7 +59883,7 @@ BEGIN * Factura un ticket * @param vTicketFk Id del ticket * @param vSerial Serie de factura - * @param vTaxArea Area de la factura en caso de querer forzarlo, + * @param vTaxArea Area de la factura en caso de querer forzarlo, * en la mayoria de los casos poner NULL * @return vInvoiceId */ @@ -59363,11 +59898,11 @@ BEGIN IF NOT vIsRefEditable THEN CALL util.throw('serial non editable'); END IF; - - UPDATE invoiceOut + + UPDATE invoiceOut SET `ref` = vRef WHERE id = vInvoiceId; - END IF; + END IF; IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN CALL invoiceOutBooking(vInvoiceId); @@ -59449,7 +59984,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemBarcode_update`(vItemFk INT,vCo BEGIN IF vDelete THEN DELETE FROM vn.itemBarcode WHERE itemFk = vItemFk AND code = vCode; -ELSE +ELSE INSERT INTO vn.itemBarcode(itemFk,code) VALUES (vItemFk,vCode); END IF; @@ -59473,33 +60008,33 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemFuentesBalance`(vDaysInFuture I BEGIN /* Se utiliza para calcular la necesidad de mover mercancia entre el almacén de fuentes y el nuestro - * + * * @param vDaysInFuture Rango de dias para calcular entradas y salidas - * + * */ - + DECLARE vWarehouseFk INT; SELECT s.warehouseFk INTO vWarehouseFk - FROM vn.sector s + FROM vn.sector s WHERE s.code = 'FUENTES_PICASSE'; - + CALL cache.stock_refresh(FALSE); - SELECT i.id itemFk, + SELECT i.id itemFk, i.longName, i.size, i.subName, - v.amount - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as visible, - fue.Fuentes, + v.amount - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as visible, + fue.Fuentes, alb.Albenfruit, - sale.venta, - IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, - IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) + sale.venta, + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, + IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.Fuentes,0) - IFNULL(alb.albenfruit,0) as saldo - FROM vn.item i - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk LEFT JOIN ( SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Fuentes FROM vn.itemShelving ish @@ -59507,7 +60042,7 @@ BEGIN JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.code = 'FUENTES_PICASSE' - GROUP BY ish.itemFk + GROUP BY ish.itemFk ) fue ON fue.itemFk = i.id LEFT JOIN ( SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS Albenfruit @@ -59516,7 +60051,7 @@ BEGIN JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.sector s ON s.id = p.sectorFk WHERE s.code = 'ALBENFRUIT' - GROUP BY ish.itemFk + GROUP BY ish.itemFk ) alb ON alb.itemFk = i.id LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk LEFT JOIN ( @@ -59541,9 +60076,9 @@ BEGIN AND warehouse_id = vWarehouseFk GROUP BY item_id ) mov ON mov.item_id = i.id - WHERE (v.amount OR fue.Fuentes OR alb.Albenfruit) + WHERE (v.amount OR fue.Fuentes OR alb.Albenfruit) AND i.itemPackingTypeFk = 'H' - AND ic.shortLife + AND ic.shortLife ; END ;; @@ -59565,7 +60100,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementFromTicket`(vTicket INT) BEGIN /** - * Llama a itemPlacementUpdateVisible + * Llama a itemPlacementUpdateVisible * de los articulos de la tabla temporal tmp.itemPlacement(itemFk) * @treturn tmp.itemPlacement * @param vTicket Id del Ticket @@ -59579,9 +60114,9 @@ BEGIN FROM ticket t JOIN sale s ON s.ticketFk = t.id WHERE t.id = vTicket; - + CALL itemPlacementUpdateVisible(); - + DROP TEMPORARY TABLE tmp.itemPlacement; END ;; DELIMITER ; @@ -59614,7 +60149,7 @@ BEGIN CAST(FLOOR(LEAST(ish.stock,quantity) / ish.packing) AS DECIMAL(10,0)), ' x ', ish.packing, - IF ( + IF ( LEAST(ish.stock,quantity) MOD ish.packing, CONCAT(' + ',CAST(LEAST(ish.stock,quantity) MOD ish.packing AS DECIMAL(10,0))), '' @@ -59645,7 +60180,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSupplyCloseOrder`(vId INT, vQuantity INT) BEGIN - UPDATE vn.itemPlacementSupply + UPDATE vn.itemPlacementSupply SET priority = 10 WHERE id = vId; @@ -59671,7 +60206,7 @@ BEGIN DECLARE vId INT; DECLARE vLastParkingFk INT; DECLARE vNextParkingFk INT; - + SELECT sh.parkingFk INTO vLastParkingFk FROM vn.itemShelvingPlacementSupply isps JOIN vn.itemShelving ish ON ish.id = isps.itemShelvingFk @@ -59679,9 +60214,9 @@ BEGIN WHERE isps.userFk = getUser() ORDER BY isps.created DESC LIMIT 1; - + SET vNextParkingFk = vn.itemShelvingPlacementSupply_ClosestGet(vLastParkingFk); - + SELECT ipsl.id INTO vId FROM vn.itemPlacementSupplyList ipsl JOIN vn.itemShelvingPlacementSupplyStock ispss ON ispss.itemFk = ipsl.itemFk @@ -59690,13 +60225,13 @@ BEGIN AND ipsl.sectorFk = vSector ORDER BY ipsl.repoUserFk DESC, ipsl.priority DESC, (ispss.parkingFk = vNextParkingFk) DESC, ispss.parking DESC, ipsl.created LIMIT 1; - + UPDATE vn.itemPlacementSupply SET repoUserFk = getUser() WHERE id = vId; - - SELECT * FROM vn.itemPlacementSupplyList - WHERE id = vId + + SELECT * FROM vn.itemPlacementSupplyList + WHERE id = vId AND sectorFk = vSector; END ;; @@ -59870,7 +60405,7 @@ BEGIN * @param vSaleFk id de la tabla sale * @param vMateFk articulo sustituto * @ param vQuantity cantidad que se va a sustituir - */ + */ DECLARE vTicketFk INT; DECLARE vItemFk INT; DECLARE vWarehouseFk SMALLINT; @@ -59879,41 +60414,41 @@ BEGIN DECLARE vBox INT; DECLARE vPacking INT; DECLARE vRoundQuantity INT DEFAULT 1; - + SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk WHERE s.id = vSaleFk; - + UPDATE vn.sale SET quantity = quantity - vQuantity WHERE id = vSaleFk; - + CALL vn.buyUltimate(vWarehouseFk, vDate); - + SELECT `grouping`, groupingMode, packing INTO vGrouping,vBox,vPacking FROM buy b JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; - + IF vBox = 2 AND vPacking > 0 THEN SET vRoundQuantity = vPacking; END IF; IF vBox = 1 AND vGrouping > 0 THEN SET vRoundQuantity = vGrouping; END IF; - + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept) SELECT vTicketFk, vMateFk, CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ',i.longName) FROM vn.item i WHERE id = vMateFk; - + SELECT LAST_INSERT_ID() INTO vSaleFk; - + CALL vn.sale_calculateComponent(vSaleFk, NULL); - + INSERT INTO vn.itemProposal(itemFk, mateFk, counter) VALUES(vItemFk, vMateFk, 1) ON DUPLICATE KEY UPDATE counter = counter + 1; @@ -59942,13 +60477,13 @@ BEGIN DECLARE vCalcFk INT; DECLARE vTypeFk INT; DECLARE vResultsMax INT DEFAULT 10; - + DECLARE vTag1 VARCHAR(25); DECLARE vTag5 VARCHAR(25); DECLARE vTag6 VARCHAR(25); DECLARE vTag7 VARCHAR(25); DECLARE vTag8 VARCHAR(25); - + DECLARE vValue1 VARCHAR(50); DECLARE vValue5 VARCHAR(50); DECLARE vValue6 VARCHAR(50); @@ -59958,16 +60493,16 @@ BEGIN SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped FROM vn.ticket WHERE id = vTicketFk; - + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 - FROM vn.item i + FROM vn.item i LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk WHERE i.id = vItemFk; - + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); - + SELECT i.id itemFk, i.longName, i.subName, @@ -59985,7 +60520,7 @@ BEGIN (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, a.available, IFNULL(ip.counter,0) counter - FROM vn.item i + FROM vn.item i JOIN cache.available a ON a.item_id = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 @@ -59999,7 +60534,7 @@ BEGIN (it1.value = vValue1 COLLATE utf8_general_ci) DESC, (i.tag5 = vTag5 COLLATE utf8_general_ci) DESC, (i.value5 = vValue5 COLLATE utf8_general_ci) DESC, - (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, + (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, (i.value6 = vValue6 COLLATE utf8_general_ci) DESC, (i.tag7 = vTag7 COLLATE utf8_general_ci) DESC, (i.value7 = vValue7 COLLATE utf8_general_ci) DESC, @@ -60035,7 +60570,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.item SELECT vItem id; - + CALL item_refreshTags(); DROP TEMPORARY TABLE tmp.item; @@ -60058,23 +60593,23 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSale_byWeek`(vWeek INT, IN vYear INT, vItemFk INT, vWarehouseFk INT) BEGIN - + DECLARE vStarted DATE; DECLARE vEnded DATETIME; SELECT MIN(dated), util.dayEnd(MAX(dated)) INTO vStarted, vEnded - FROM `time` t + FROM `time` t WHERE CONCAT(vYear, LPAD(vWeek, 2, 0)) = t.period; SELECT t.shipped, w.name warehouse, - s.ticketFk, + s.ticketFk, t.nickname client, - am.name agencyName, + am.name agencyName, wk.code salesPerson, s.itemFk, - IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept, - s.quantity, + IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept, + s.quantity, s.price, s.priceFixed, s.discount, @@ -60084,15 +60619,15 @@ BEGIN wk.id salesPersonFk FROM sale s JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk + JOIN warehouse w ON w.id = t.warehouseFk JOIN address a ON a.id = t.addressFk LEFT JOIN agencyMode am ON am.id = t.agencyModeFk JOIN `client` c ON c.id = a.clientFk - LEFT JOIN worker wk ON wk.id = c.salesPersonFk + LEFT JOIN worker wk ON wk.id = c.salesPersonFk LEFT JOIN ticketLastState tls ON tls.ticketFk = t.id - LEFT JOIN saleBuy sb ON sb.saleFk = s.id - LEFT JOIN buy b ON b.id = sb.buyFk - LEFT JOIN item ig ON ig.id = b.itemOriginalFk + LEFT JOIN saleBuy sb ON sb.saleFk = s.id + LEFT JOIN buy b ON b.id = sb.buyFk + LEFT JOIN item ig ON ig.id = b.itemOriginalFk WHERE s.itemFk = vItemFk AND t.shipped BETWEEN vStarted AND vEnded AND IF(vWarehouseFk = 0, w.hasComission , t.warehouseFk = vWarehouseFk) @@ -60119,9 +60654,9 @@ BEGIN DECLARE vItemFk INT; SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - + UPDATE vn.item SET minimum = min WHERE id = vItemFk; - + END ;; @@ -60143,8 +60678,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSearchShelving`(`vShelvingFk` VARCHAR(3)) BEGIN SELECT p.`column` AS col , p.`row` - FROM vn.shelving s - JOIN parking p ON s.parkingFk = p.id + FROM vn.shelving s + JOIN parking p ON s.parkingFk = p.id WHERE s.`code` = vShelvingFk COLLATE utf8_general_ci; END ;; DELIMITER ; @@ -60185,36 +60720,36 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingLog_get`(vShelvingFk VARCHAR(10) ) BEGIN - + /** * Devuelve el log de los item en cada carro * - * @param vShelvingFk Matrícula del carro - * + * @param vShelvingFk Matrícula del carro + * */ - - SELECT isl.itemShelvingFk, - isl.created, - isl.accion, - isl.itemFk, - isl.shelvingFk, - isl.quantity, + + SELECT isl.itemShelvingFk, + isl.created, + isl.accion, + isl.itemFk, + isl.shelvingFk, + isl.quantity, isl.visible, - isl.available, - isl.grouping, - isl.packing, - isl.stars, - item.longName, - item.size, - item.subName, - worker.code, + isl.available, + isl.grouping, + isl.packing, + isl.stars, + item.longName, + item.size, + item.subName, + worker.code, isl.accion - FROM item - JOIN itemShelvingLog isl ON item.id = isl.itemFk + FROM item + JOIN itemShelvingLog isl ON item.id = isl.itemFk JOIN worker ON isl.workerFk = worker.id WHERE shelvingFk = vShelvingFk OR isl.itemFk = vShelvingFk ORDER BY isl.created DESC; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60233,7 +60768,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22)) BEGIN - + DECLARE vItemFk INT; SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; @@ -60252,9 +60787,9 @@ BEGIN END IF; - IF (SELECT COUNT(*) FROM vn.itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk + IF (SELECT COUNT(*) FROM vn.itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk AND packing = vPacking) = 1 THEN UPDATE vn.itemShelving @@ -60284,8 +60819,8 @@ BEGIN LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk LEFT JOIN vn.buy b ON b.id = lb.buy_id WHERE i.id = vItemFk; - END IF; - + END IF; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60306,9 +60841,9 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMatch`(vEntryFk INT, vA BEGIN DECLARE vTravelFk INT; - - SELECT travelFk INTO vTravelFk - FROM entry + + SELECT travelFk INTO vTravelFk + FROM entry WHERE id = vEntryFk; SELECT i.id, i.longName, i.size, i.subName, b.stickers, ish.etiquetas, b.printed @@ -60321,7 +60856,7 @@ BEGIN GROUP BY itemFk ) b ON b.itemFk = i.id LEFT JOIN ( - SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas + SELECT itemFk, sum(cast(visible / packing AS DECIMAL(10,0))) AS etiquetas FROM itemShelving ish JOIN shelving sh ON sh.code = ish.shelvingFk LEFT JOIN parking pk ON pk.id = sh.parkingFk @@ -60361,7 +60896,7 @@ BEGIN UPDATE vn.itemShelving SET visible = visible - vQuantity WHERE id = vItemShelvingFk; - + END ;; DELIMITER ; @@ -60384,47 +60919,47 @@ BEGIN DECLARE vVisibleCache INT; DECLARE vWarehouseFk INT; - + SELECT warehouseFk INTO vWarehouseFk FROM vn.sector WHERE id = vSectorFk; CALL cache.visible_refresh (vVisibleCache, FALSE, vWarehouseFk); - - SELECT t.id as ticketFk, - CAST(s.quantity AS DECIMAL(10,0)) as Cantidad, - s.itemFk, - s.concept, - v.visible - GREATEST(0,iss.visible) + IFNULL(sub3.transit,0) as Nicho, + + SELECT t.id as ticketFk, + CAST(s.quantity AS DECIMAL(10,0)) as Cantidad, + s.itemFk, + s.concept, + v.visible - GREATEST(0,iss.visible) + IFNULL(sub3.transit,0) as Nicho, i.subName, - GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo, + GREATEST(0,iss.visible - IFNULL(sub3.transit,0)) as Altillo, s.id as saleFk, IFNULL(sub3.transit,0) transit, v.visible, s.isPicked, s.reserved, t.shipped, tst.productionOrder, mm.Id_Movimiento - FROM vn.ticket t + FROM vn.ticket t JOIN vn.ticketState tst ON tst.ticketFk = t.id JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN cache.visible v ON s.itemFk = v.item_id AND v.calc_id = vVisibleCache LEFT JOIN vn2008.Movimientos_mark mm ON mm.Id_Movimiento = s.id AND mm.stateFk = 26 - JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id + JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id LEFT JOIN - (SELECT itemFk, sum(saldo) as transit - FROM vn.itemPlacementSupplyList - WHERE saldo > 0 + (SELECT itemFk, sum(saldo) as transit + FROM vn.itemPlacementSupplyList + WHERE saldo > 0 AND sectorFk = vSectorFk GROUP BY itemFk) sub3 ON sub3.itemFk = i.id - WHERE v.visible + IFNULL(sub3.transit,0) - GREATEST(0,iss.visible) < s.quantity + WHERE v.visible + IFNULL(sub3.transit,0) - GREATEST(0,iss.visible) < s.quantity AND IFNULL(sub3.transit,0) < s.quantity - AND s.isPicked = FALSE + AND s.isPicked = FALSE AND s.reserved = FALSE - AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) + AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) AND tst.isPreviousPreparable = TRUE AND t.warehouseFk = vWarehouseFk AND iss.sectorFk = vSectorFk AND mm.Id_Movimiento IS NULL ORDER BY itemFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60443,7 +60978,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar`(vSectorFk INT) proc:BEGIN - + DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; DECLARE hasFatherSector BOOLEAN; @@ -60451,17 +60986,17 @@ proc:BEGIN DECLARE vWarehouseFk INT DEFAULT 0; DECLARE vSonSectorFk INT; DECLARE vWorkerFk INT; - - SELECT s.workerFk - INTO vWorkerFk + + SELECT s.workerFk + INTO vWorkerFk FROM vn.sector s WHERE s.id = vSectorFk; SELECT w.id, s.warehouseFk INTO vBuyerFk, vWarehouseFk - FROM vn.worker w + FROM vn.worker w JOIN vn.sector s ON s.code = w.code WHERE s.id = vSectorFk; - + SELECT s.id INTO vSectorFk FROM vn.sector s WHERE s.warehouseFk = vWarehouseFk @@ -60470,21 +61005,21 @@ proc:BEGIN SELECT COUNT(*) INTO hasFatherSector FROM vn.sector WHERE sonFk = vSectorFk; - + SELECT warehouseFk, sonFk INTO vWarehouseFk, vSonSectorFk FROM vn.sector WHERE id = vSectorFk; - + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar; - + IF hasFatherSector THEN CREATE TEMPORARY TABLE tmp.itemShelvingRadar (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT * + ENGINE = MEMORY + SELECT * FROM ( SELECT iss.itemFk, i.longName, @@ -60503,9 +61038,9 @@ proc:BEGIN LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk WHERE vSectorFk IN (iss.sectorFk, s.sonFk) GROUP BY iss.itemFk - + UNION ALL - + SELECT v.item_id, i.longName, i.size, @@ -60515,7 +61050,7 @@ proc:BEGIN 0 downstairs, IF(it.isPackaging, NULL, v.visible) visible, vSectorFk as sectorFk - FROM cache.visible v + FROM cache.visible v JOIN vn.item i on i.id = v.item_id JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk) LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk @@ -60524,8 +61059,8 @@ proc:BEGIN AND iss.itemFk IS NULL AND it.isInventory ) sub GROUP BY itemFk; - - SELECT ishr.*, + + SELECT ishr.*, CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho, CAST(downstairs - IFNULL(notPickedYed,0) AS DECIMAL(10,0)) as pendiente FROM tmp.itemShelvingRadar ishr @@ -60542,7 +61077,7 @@ proc:BEGIN ELSE CREATE TEMPORARY TABLE tmp.itemShelvingRadar (PRIMARY KEY (itemFk)) - ENGINE = MEMORY + ENGINE = MEMORY SELECT iss.itemFk, 0 `hour`, 0 `minute`, @@ -60554,7 +61089,7 @@ proc:BEGIN IFNULL(a.available,0) available, IFNULL(v.visible - iss.visible,0) dayEndVisible, IFNULL(v.visible - iss.visible,0) firstNegative, - IFNULL(v.visible - iss.visible,0) itemPlacementVisible, + IFNULL(v.visible - iss.visible,0) itemPlacementVisible, IFNULL(i.minimum * b.packing,0) itemPlacementSize, ips.onTheWay, iss.visible itemShelvingStock, @@ -60568,20 +61103,20 @@ proc:BEGIN LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk LEFT JOIN (SELECT itemFk, sum(saldo) as onTheWay - FROM vn.itemPlacementSupplyList - WHERE saldo > 0 + FROM vn.itemPlacementSupplyList + WHERE saldo > 0 GROUP BY itemFk ) ips ON ips.itemFk = i.id - WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk) - OR iss.sectorFk = vSectorFk; + WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk) + OR iss.sectorFk = vSectorFk; DROP TEMPORARY TABLE IF EXISTS tmp.itemOutTime; CREATE TEMPORARY TABLE tmp.itemOutTime SELECT *,SUM(amount) quantity - FROM + FROM (SELECT item_id itemFk, - amount, - IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours, + amount, + IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours, IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes FROM vn2008.item_out io JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.item_id @@ -60589,23 +61124,23 @@ proc:BEGIN JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk JOIN vn.state s ON s.id = ts.stateFk LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN (SELECT DISTINCT saleFk - FROM vn.saleTracking st - WHERE st.created > util.VN_CURDATE() + LEFT JOIN (SELECT DISTINCT saleFk + FROM vn.saleTracking st + WHERE st.created > util.VN_CURDATE() AND st.isChecked ) stPrevious ON `stPrevious`.`saleFk` = io.saleFk WHERE t.warehouseFk = vWarehouseFk - AND s.isPicked = 0 - AND NOT io.Reservado + AND s.isPicked = 0 + AND NOT io.Reservado AND stPrevious.saleFk IS NULL - AND io.dat >= util.VN_CURDATE() + AND io.dat >= util.VN_CURDATE() AND io.dat < util.VN_CURDATE() + INTERVAL 1 DAY ) sub GROUP BY itemFk, hours, minutes; - + INSERT INTO tmp.itemShelvingRadar (itemFk) SELECT itemFk FROM tmp.itemOutTime - ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity, + ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity, firstNegative = if (firstNegative < 0, firstNegative, firstNegative + quantity), `hour` = ifnull(if (firstNegative > 0 , `hour`, hours),0), `minute` = ifnull(if (firstNegative > 0, `minute`, minutes),0); @@ -60625,7 +61160,7 @@ proc:BEGIN END IF; DROP TEMPORARY TABLE tmp.itemShelvingRadar; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60649,24 +61184,24 @@ BEGIN DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); - + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item ENGINE = MEMORY SELECT DISTINCT itemFk - FROM vn.buy + FROM vn.buy WHERE entryFk = vEntryFk; - + DROP TEMPORARY TABLE IF EXISTS tmp.item2; CREATE TEMPORARY TABLE tmp.item2 ENGINE = MEMORY SELECT * FROM tmp.item; - - SELECT i.id as itemFk, + + SELECT i.id as itemFk, i.minimum, CAST(IFNULL(v.visible,0) - IFNULL(iss.visible,0) AS DECIMAL(10,0)) as enNicho, CAST(IFNULL(a.available,0) AS DECIMAL(10,0)) as disponible, @@ -60686,11 +61221,11 @@ BEGIN AND IFNULL(tst.productionOrder,0) < 5 GROUP BY s.itemFK ) ts ON ts.itemFk = i.id; - - + + DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.item2; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60714,34 +61249,34 @@ BEGIN DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); - + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - + DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item ENGINE = MEMORY SELECT DISTINCT itemFk - FROM vn.buy + FROM vn.buy WHERE entryFk = vEntryFk; - + DROP TEMPORARY TABLE IF EXISTS tmp.item2; CREATE TEMPORARY TABLE tmp.item2 ENGINE = MEMORY SELECT * FROM tmp.item; - - SELECT i.id as itemFk, + + SELECT i.id as itemFk, CAST(IFNULL(iss.visible,0) - IFNULL(v.visible,0) AS DECIMAL(10,0)) as outShelving FROM vn.item i JOIN tmp.item ti ON ti.itemFk = i.id LEFT JOIN cache.visible v ON v.calc_id = vCalcVisibleFk AND v.item_id = i.id LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = i.id; - - + + DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.item2; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -60762,10 +61297,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_Add`(vItemShelving BEGIN /** * Añade línea a itemShelvingSale y regulariza el carro - * + * * @param vItemShelvingFk Id itemShelving * @param vSaleFk Id de sale - * @param vQuantity cantidad a regularizar + * @param vQuantity cantidad a regularizar */ INSERT INTO itemShelvingSale(itemShelvingFk, saleFk, @@ -60948,7 +61483,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_reserveBySale`( - vSelf INT , + vSelf INT , vQuantity INT, vUserFk INT ) @@ -60963,7 +61498,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale ENGINE = MEMORY SELECT vSelf saleFk, vUserFk userFk; - + CALL itemShelvingSale_reserve(); END ;; DELIMITER ; @@ -60989,12 +61524,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_setQuantity`( BEGIN /** * Gestiona la reserva de un itemShelvingFk, actualizando isPicked y quantity - * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. - * Si la reserva de la ubicación es fallida, se regulariza la situación - * - * @param vItemShelvingSaleFk Id itemShelvingSaleFK + * en vn.itemShelvingSale y vn.sale.isPicked en caso necesario. + * Si la reserva de la ubicación es fallida, se regulariza la situación + * + * @param vItemShelvingSaleFk Id itemShelvingSaleFK * @param vQuantity Cantidad real que se ha cogido de la ubicación - * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha + * @param vIsItemShelvingSaleEmpty determina si ka ubicación itemShelvingSale se ha * quedado vacio tras el movimiento */ DECLARE vSaleFk INT; @@ -61005,7 +61540,7 @@ BEGIN DECLARE vItemFk INT; DECLARE vUserFk INT; DECLARE vDone BOOLEAN DEFAULT FALSE; - DECLARE vSales CURSOR FOR + DECLARE vSales CURSOR FOR SELECT iss.saleFk, iss.userFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk @@ -61019,14 +61554,14 @@ BEGIN CALL util.throw('Booking completed'); END IF; - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk + SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk INTO vItemFk, vSaleFk, vItemShelvingFk FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk WHERE iss.id = vItemShelvingSaleFk AND NOT iss.isPicked; - - UPDATE itemShelvingSale + + UPDATE itemShelvingSale SET isPicked = TRUE, quantity = vQuantity WHERE id = vItemShelvingSaleFk; @@ -61051,10 +61586,10 @@ l: LOOP CALL itemShelvingSale_reserveWhitUser(); DROP TEMPORARY TABLE tmp.sale; - + END LOOP; CLOSE vSales; - + DELETE iss FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk @@ -61068,32 +61603,32 @@ l: LOOP WHERE saleFk = vSaleFk AND NOT isPicked; - IF vRemainingQuantity THEN + IF vRemainingQuantity THEN CALL itemShelvingSale_reserveBySale (vSaleFk, vRemainingQuantity, NULL); - + SELECT SUM(quantity) INTO vRemainingQuantity FROM itemShelvingSale WHERE saleFk = vSaleFk AND NOT isPicked; IF NOT vRemainingQuantity <=> 0 THEN - SELECT SUM(iss.quantity) + SELECT SUM(iss.quantity) INTO vReservedQuantity - FROM itemShelvingSale iss + FROM itemShelvingSale iss WHERE iss.saleFk = vSaleFk; - + CALL saleTracking_new( vSaleFk, - TRUE, - vReservedQuantity, - `account`.`myUser_getId`(), + TRUE, + vReservedQuantity, + `account`.`myUser_getId`(), NULL, 'PREPARED', TRUE); - + UPDATE sale s SET s.quantity = vReservedQuantity - WHERE s.id = vSaleFk ; + WHERE s.id = vSaleFk ; END IF; END IF; END ;; @@ -61172,7 +61707,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN - + /** * Añade registro o lo actualiza si ya existe. @@ -61184,7 +61719,7 @@ BEGIN * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra * @param vPacking el packing del producto, NULL para coger el de la ultima compra * @param vWarehouseFk indica el sector - * + * **/ DECLARE vItemFk INT; @@ -61194,21 +61729,21 @@ BEGIN IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); - INSERT INTO shelving(code, parkingFk) + INSERT INTO shelving(code, parkingFk) SELECT vShelvingFk, id - FROM parking + FROM parking WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; END IF; - IF (SELECT COUNT(*) FROM itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk + IF (SELECT COUNT(*) FROM itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk AND packing = vPacking) = 1 THEN UPDATE itemShelving SET visible = visible+vQuantity - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; ELSE CALL cache.last_buy_refresh(FALSE); @@ -61359,10 +61894,10 @@ proc:BEGIN * @return Lista de articulos */ DECLARE vCalcVisibleFk INT; - + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); - SELECT * FROM + SELECT * FROM (SELECT sub.itemFk, sub.longName, CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, @@ -61379,28 +61914,28 @@ proc:BEGIN 0 upstairs, SUM(IFNULL(iss.visible,0)) downstairs, IF(it.isPackaging, null, IFNULL(v.visible, 0)) visible, - ik.name + ik.name FROM itemShelvingStock iss JOIN sector s ON s.id = iss.sectorFk JOIN item i on i.id = iss.itemFk - LEFT JOIN ink ik ON ik.id = i.inkFk + LEFT JOIN ink ik ON ik.id = i.inkFk JOIN itemType it ON it.id = i.typeFk LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk WHERE s.warehouseFk = vWarehouseFk AND it.workerFk = vBuyerFk - GROUP BY itemFk + GROUP BY itemFk ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente FROM sale s LEFT JOIN saleTracking st ON st.saleFk = s.id - JOIN ticket t ON t.id = s.ticketFk + JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND st.saleFk IS NULL AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk - ) sub2 ON sub2.itemFk = sub.itemFk - UNION ALL + ) sub2 ON sub2.itemFk = sub.itemFk + UNION ALL SELECT v.item_id , i.longName, CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, @@ -61418,7 +61953,7 @@ proc:BEGIN LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente FROM sale s LEFT JOIN saleTracking st ON st.saleFk = s.id - JOIN ticket t ON t.id = s.ticketFk + JOIN ticket t ON t.id = s.ticketFk JOIN client c on c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) @@ -61451,12 +61986,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_get`(IN vSelf VARCHAR(8)) BEGIN /** -* Lista artículos de itemshelving +* Lista artículos de itemshelving * * @param vSelf matrícula del carro **/ - SELECT ish.itemFk item, - IFNULL(i.longName, CONCAT(i.name, ' ', i.size)) description, + SELECT ish.itemFk item, + IFNULL(i.longName, CONCAT(i.name, ' ', i.size)) description, ish.visible, CEIL(ish.visible/ish.packing) stickers, ish.packing, @@ -61494,7 +62029,7 @@ BEGIN * * @param vShelvingFk matricula del carro */ - SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder + SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , is2.visible, p.pickingOrder FROM itemShelving is2 JOIN shelving sh ON sh.code = is2.shelvingFk JOIN parking p ON p.id = sh.parkingFk @@ -61559,167 +62094,167 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_getSaleDate`(vShelvingFk VARCHAR(3)) -BEGIN - - /* Devuelve la mínima fecha en que se necesita cada producto en esa matrícula. - * - * @param vShelvingFk Matrícula del carro o pallet - */ - - DECLARE vWarehouseFk INT; - DECLARE vStockScopeDays INT; - - SELECT s.warehouseFk, stockScopeDays - INTO vWarehouseFk, vStockScopeDays - FROM sector s - JOIN operator o ON s.id = o.sectorFk - JOIN productionConfig pc - WHERE o.workerFk = account.myUser_getId(); - - IF vWarehouseFk IS NULL - THEN CALL util.throw('WarehouseFk not setted'); - END IF; - - IF vStockScopeDays IS NULL - THEN CALL util.throw('StockScopeDays not setted'); - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tmp.tItems - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT itemFk, SUM(visible) visible - FROM itemShelving - WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci - GROUP BY itemFk; - - CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay - (INDEX (itemFk, dated)) - ENGINE = MEMORY - SELECT dated, - SUM(t3.amount) OVER (PARTITION BY t3.itemFk ORDER BY dated) stock, - t3.itemFk - FROM ( - SELECT t.itemFk, dated, SUM(amount) amount - FROM ( - SELECT t2.itemFk, t2.amount, t2.dated - FROM ( - SELECT item_id itemFk, amount, util.VN_CURDATE() dated - FROM cache.stock s - JOIN tmp.tItems i ON i.itemFk = s.item_id - WHERE s.warehouse_id = vWarehouseFk - UNION ALL - SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE() - FROM itemShelving ish - JOIN tmp.tItems i ON i.itemFk = ish.itemFk - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON sh.parkingFk = p.id - JOIN sector s ON s.id = p.sectorFk - WHERE s.isReserve - GROUP BY ish.itemFk - UNION ALL - SELECT iei.itemFk, SUM(quantity), landed - FROM itemEntryIn iei - JOIN tmp.tItems i ON i.itemFk = iei.itemFk - WHERE iei.landed BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY - AND iei.warehouseInFk = vWarehouseFk - AND NOT isVirtualStock - GROUP BY iei.itemFk, iei.landed - UNION ALL - SELECT ieo.itemFk, SUM(quantity), shipped - FROM itemEntryOut ieo - JOIN tmp.tItems i ON i.itemFk = ieo.itemFk - WHERE ieo.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY - AND ieo.warehouseOutFk = vWarehouseFk - GROUP BY ieo.itemFk, ieo.shipped - UNION ALL - SELECT i.itemFk, SUM(ito.quantity), DATE(ito.shipped) - FROM itemTicketOut ito - JOIN tmp.tItems i ON i.itemFk = ito.itemFk - WHERE ito.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY - AND ito.warehouseFk = vWarehouseFk - GROUP BY ito.itemFk, ito.shipped - ) t2 - JOIN tmp.tItems i ON i.itemFk = t2.itemFk)t - GROUP BY t.itemFk, dated - ) t3; - - -- Se restan las entradas de hoy - UPDATE tmp.tStockByDay sbd - JOIN (SELECT iei.itemFk, SUM(quantity) todayEntry - FROM itemEntryIn iei - JOIN tmp.tItems i ON i.itemFk = iei.itemFk - WHERE iei.landed = util.VN_CURDATE() - AND iei.warehouseInFk = vWarehouseFk - AND NOT iei.isVirtualStock) sub ON sub.itemFk = sbd.itemFk - SET sbd.stock = sbd.stock - sub.todayEntry - WHERE sbd.dated = util.VN_CURDATE(); - - -- Se añaden las lineas de venta servidas - UPDATE tmp.tStockByDay sbd - JOIN (SELECT s.itemFK, SUM(quantity) amount - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - WHERE t.warehouseFk = vWarehouseFk - AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() - AND s.isPicked - GROUP BY s.itemFk) sub ON sub.itemFk = sbd.itemFk - SET sbd.stock = sbd.stock + sub.amount; - - -- Se añaden los items ubicados hoy - UPDATE tmp.tStockByDay sbd - JOIN (SELECT ish.itemFK, SUM(ish.visible) amount - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND NOT s.isReserve - AND ish.created BETWEEN util.VN_CURDATE() AND util.midnight() - GROUP BY ish.itemFk) sub ON sub.itemFk = sbd.itemFk - SET sbd.stock = sbd.stock + sub.amount; - - SELECT ts.itemFk, - i.longName, - IF(ts.stock<=0, ts.dated, NULL) dated, - ts.stock, - sub4.visible, - sub4.shelvingFk - FROM( - SELECT IFNULL(sub2.minDated, sub.minDated) dated, - IFNULL(sub2.itemFk, sub.itemFk) itemFk - FROM(SELECT sbd.itemFk, - MIN(dated) minDated, - sbd.stock - FROM tmp.tItems ti - LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk - GROUP BY itemFk)sub - LEFT JOIN ( - SELECT sbd.itemFk, - MIN(dated) minDated, - sbd.stock - FROM tmp.tItems ti - LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk - WHERE sbd.stock <= 0 - GROUP BY itemFk)sub2 ON sub2.itemFk =sub.itemFk - WHERE sub2.itemFk IS NOT NULL - OR (sub2.itemFk IS NULL AND sub.itemFk IS NOT NULL)) sub3 - LEFT JOIN tmp.tStockByDay ts ON ts.itemFk = sub3.itemFk AND ts.dated = sub3.dated - JOIN (SELECT ish.itemFk, - ish.visible, - p.sectorFk, - ish.shelvingFk - FROM itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = parkingFk - LEFT JOIN vn.sector s ON s.id = p.sectorFk - WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci - ) sub4 ON sub4.itemFk = ts.itemFk - LEFT JOIN sector s ON s.id = sub4.sectorFk - LEFT JOIN item i ON i.id = ts.itemFk - WHERE NOT s.isReserve; - - DROP TEMPORARY TABLE tmp.tStockByDay, tmp.tItems; - +BEGIN + + /* Devuelve la mínima fecha en que se necesita cada producto en esa matrícula. + * + * @param vShelvingFk Matrícula del carro o pallet + */ + + DECLARE vWarehouseFk INT; + DECLARE vStockScopeDays INT; + + SELECT s.warehouseFk, stockScopeDays + INTO vWarehouseFk, vStockScopeDays + FROM sector s + JOIN operator o ON s.id = o.sectorFk + JOIN productionConfig pc + WHERE o.workerFk = account.myUser_getId(); + + IF vWarehouseFk IS NULL + THEN CALL util.throw('WarehouseFk not setted'); + END IF; + + IF vStockScopeDays IS NULL + THEN CALL util.throw('StockScopeDays not setted'); + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tmp.tItems + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT itemFk, SUM(visible) visible + FROM itemShelving + WHERE shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + GROUP BY itemFk; + + CREATE OR REPLACE TEMPORARY TABLE tmp.tStockByDay + (INDEX (itemFk, dated)) + ENGINE = MEMORY + SELECT dated, + SUM(t3.amount) OVER (PARTITION BY t3.itemFk ORDER BY dated) stock, + t3.itemFk + FROM ( + SELECT t.itemFk, dated, SUM(amount) amount + FROM ( + SELECT t2.itemFk, t2.amount, t2.dated + FROM ( + SELECT item_id itemFk, amount, util.VN_CURDATE() dated + FROM cache.stock s + JOIN tmp.tItems i ON i.itemFk = s.item_id + WHERE s.warehouse_id = vWarehouseFk + UNION ALL + SELECT ish.itemFk, - SUM(ish.visible), util.VN_CURDATE() + FROM itemShelving ish + JOIN tmp.tItems i ON i.itemFk = ish.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON sh.parkingFk = p.id + JOIN sector s ON s.id = p.sectorFk + WHERE s.isReserve + GROUP BY ish.itemFk + UNION ALL + SELECT iei.itemFk, SUM(quantity), landed + FROM itemEntryIn iei + JOIN tmp.tItems i ON i.itemFk = iei.itemFk + WHERE iei.landed BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND iei.warehouseInFk = vWarehouseFk + AND NOT isVirtualStock + GROUP BY iei.itemFk, iei.landed + UNION ALL + SELECT ieo.itemFk, SUM(quantity), shipped + FROM itemEntryOut ieo + JOIN tmp.tItems i ON i.itemFk = ieo.itemFk + WHERE ieo.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND ieo.warehouseOutFk = vWarehouseFk + GROUP BY ieo.itemFk, ieo.shipped + UNION ALL + SELECT i.itemFk, SUM(ito.quantity), DATE(ito.shipped) + FROM itemTicketOut ito + JOIN tmp.tItems i ON i.itemFk = ito.itemFk + WHERE ito.shipped BETWEEN util.VN_CURDATE() AND util.VN_CURDATE() + INTERVAL vStockScopeDays DAY + AND ito.warehouseFk = vWarehouseFk + GROUP BY ito.itemFk, ito.shipped + ) t2 + JOIN tmp.tItems i ON i.itemFk = t2.itemFk)t + GROUP BY t.itemFk, dated + ) t3; + + -- Se restan las entradas de hoy + UPDATE tmp.tStockByDay sbd + JOIN (SELECT iei.itemFk, SUM(quantity) todayEntry + FROM itemEntryIn iei + JOIN tmp.tItems i ON i.itemFk = iei.itemFk + WHERE iei.landed = util.VN_CURDATE() + AND iei.warehouseInFk = vWarehouseFk + AND NOT iei.isVirtualStock) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock - sub.todayEntry + WHERE sbd.dated = util.VN_CURDATE(); + + -- Se añaden las lineas de venta servidas + UPDATE tmp.tStockByDay sbd + JOIN (SELECT s.itemFK, SUM(quantity) amount + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE t.warehouseFk = vWarehouseFk + AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() + AND s.isPicked + GROUP BY s.itemFk) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock + sub.amount; + + -- Se añaden los items ubicados hoy + UPDATE tmp.tStockByDay sbd + JOIN (SELECT ish.itemFK, SUM(ish.visible) amount + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND NOT s.isReserve + AND ish.created BETWEEN util.VN_CURDATE() AND util.midnight() + GROUP BY ish.itemFk) sub ON sub.itemFk = sbd.itemFk + SET sbd.stock = sbd.stock + sub.amount; + + SELECT ts.itemFk, + i.longName, + IF(ts.stock<=0, ts.dated, NULL) dated, + ts.stock, + sub4.visible, + sub4.shelvingFk + FROM( + SELECT IFNULL(sub2.minDated, sub.minDated) dated, + IFNULL(sub2.itemFk, sub.itemFk) itemFk + FROM(SELECT sbd.itemFk, + MIN(dated) minDated, + sbd.stock + FROM tmp.tItems ti + LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk + GROUP BY itemFk)sub + LEFT JOIN ( + SELECT sbd.itemFk, + MIN(dated) minDated, + sbd.stock + FROM tmp.tItems ti + LEFT JOIN tmp.tStockByDay sbd ON sbd.itemFk = ti.itemFk + WHERE sbd.stock <= 0 + GROUP BY itemFk)sub2 ON sub2.itemFk =sub.itemFk + WHERE sub2.itemFk IS NOT NULL + OR (sub2.itemFk IS NULL AND sub.itemFk IS NOT NULL)) sub3 + LEFT JOIN tmp.tStockByDay ts ON ts.itemFk = sub3.itemFk AND ts.dated = sub3.dated + JOIN (SELECT ish.itemFk, + ish.visible, + p.sectorFk, + ish.shelvingFk + FROM itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = parkingFk + LEFT JOIN vn.sector s ON s.id = p.sectorFk + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci + ) sub4 ON sub4.itemFk = ts.itemFk + LEFT JOIN sector s ON s.id = sub4.sectorFk + LEFT JOIN item i ON i.id = ts.itemFk + WHERE NOT s.isReserve; + + DROP TEMPORARY TABLE tmp.tStockByDay, tmp.tItems; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -61812,15 +62347,15 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_selfConsumption`( - vShelvingFk VARCHAR(10) COLLATE utf8_general_ci, - vItemFk INT, + vShelvingFk VARCHAR(10) COLLATE utf8_general_ci, + vItemFk INT, vQuantity INT ) -BEGIN +BEGIN /** - * Leave the indicated amount on the shelf + * Leave the indicated amount on the shelf * and create a ticket with the difference. - * + * * @param vShelvingFk id of the shelf where the item is located. * @param vItemFk article of which the self-consumption ticket is to be created. * @param vQuantity amount that will stay on the shelf @@ -61834,7 +62369,7 @@ BEGIN DECLARE vItemShelvingFk INT; SELECT c.id, - c.clientFk, + pc.clientSelfConsumptionFk, s.warehouseFk INTO vCompanyFk, vClientFk, @@ -61845,6 +62380,7 @@ BEGIN JOIN sector s ON s.warehouseFk = w.id JOIN parking p ON p.sectorFk = s.id JOIN shelving s2 ON s2.parkingFk = p.id + JOIN productionConfig pc ON TRUE WHERE s2.code = vShelvingFk; IF vClientFk IS NULL THEN @@ -61864,10 +62400,10 @@ BEGIN END IF; SELECT SUM(visible), id INTO vVisible, vItemShelvingFk - FROM itemShelving + FROM itemShelving WHERE shelvingFk = vShelvingFk AND itemFk = vItemFk; - + IF vVisible IS NULL THEN CALL util.throw('The item is not on the shelf.'); END IF; @@ -61920,9 +62456,9 @@ BEGIN * @param vGrouping el grouping del producto en itemShelving */ UPDATE itemShelving - SET visible = vVisible, - packing = vPacking, - grouping = vGrouping + SET visible = vVisible, + packing = vPacking, + grouping = vGrouping WHERE id = vShelf; END ;; @@ -61944,7 +62480,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagMake`(vItemFk INT) BEGIN -/* * Crea los tags usando la tabla plantilla itemTag +/* * Crea los tags usando la tabla plantilla itemTag * y si no existe a partir de la ficha del artículo. * @param vItemFk El item al que se le añaden los tags */ @@ -61954,33 +62490,33 @@ BEGIN DECLARE vProducer VARCHAR(50); DECLARE vOrigin VARCHAR(20); DECLARE vTypeFk INTEGER; - - DELETE FROM itemTag + + DELETE FROM itemTag WHERE itemFk = vItemFk; - - SELECT typeFk INTO vTypeFk + + SELECT typeFk INTO vTypeFk FROM item WHERE id = vItemFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT vItemFk, itt.tagFk, NULL, itt.priority FROM itemTag it LEFT JOIN itemTypeTag itt ON itt.itemTypeFk = vTypeFk WHERE it.itemFk = vItemFk; - + IF (SELECT COUNT(*) FROM itemTag WHERE itemFk = vItemFk LIMIT 1) = 0 THEN - SELECT ik.name, i.size, i.category, p.name, o.name + SELECT ik.name, i.size, i.category, p.name, o.name INTO vInk, vSize, vCategory, vProducer, vOrigin FROM item i LEFT JOIN ink ik ON ik.id = i.inkFk LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible LEFT JOIN origin o ON o.id = i.originFk WHERE i.id = vItemFk; - + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES(vItemFk, 1, vInk, 1); - + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES (vItemFk, 8, vSize, 2); @@ -61989,11 +62525,11 @@ BEGIN INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES(vItemFk, 37, vProducer, 4); - + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) VALUES(vItemFk, 35, vOrigin, 5); END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62014,12 +62550,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorder`(itemTypeFk INT) BEGIN SET @isTriggerDisabled = TRUE; - + -- No se puede usar temporary porque da error Error Code: 1137. No puedo reabrir tabla: 'i DROP TABLE IF EXISTS tmp.item; CREATE TABLE tmp.item SELECT DISTINCT i.id - FROM vn.item i + FROM vn.item i WHERE i.typeFk = itemTypeFk; UPDATE itemTag it @@ -62028,8 +62564,8 @@ BEGIN JOIN itemTypeTag itt ON itt.itemTypeFk = item.typeFk AND itt.tagFk = it.tagFk SET it.priority = itt.priority WHERE itt.itemTypeFk = itemTypeFk; - - CALL item_refreshTags(); + + CALL item_refreshTags(); SET @isTriggerDisabled = FALSE; @@ -62054,12 +62590,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorderByName`(vName VARCHAR BEGIN SET @isTriggerDisabled = TRUE; - + -- No se puede usar temporary porque da error Error Code: 1137. No puedo reabrir tabla: 'i DROP TABLE IF EXISTS tmp.item; CREATE TABLE tmp.item SELECT DISTINCT i.id - FROM vn.item i + FROM vn.item i WHERE i.`name` LIKE CONCAT(vName,'%'); UPDATE itemTag it @@ -62068,8 +62604,8 @@ BEGIN JOIN itemTypeTag itt ON itt.itemTypeFk = item.typeFk AND itt.tagFk = it.tagFk SET it.priority = itt.priority WHERE itt.itemTypeFk = itemTypeFk; - - CALL item_refreshTags(); + + CALL item_refreshTags(); SET @isTriggerDisabled = FALSE; @@ -62092,36 +62628,36 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTag_replace`(vItemFromFk INT, vItemToFk INT, vPicture VARCHAR(100)) BEGIN - + /* Reemplaza los tags de un artículo por los de otro, así como su imagen - * + * * @param vItemFromFk id de vn.item con el artículo del que se toman los tags * @param vItemToFk id de vn.item con el artículo del que se toman los tags * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk */ - DELETE FROM vn.itemTag + DELETE FROM vn.itemTag WHERE itemFk = vItemToFk; - + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) SELECT vItemToFk, tagFk, value, priority - FROM vn.itemTag + FROM vn.itemTag WHERE itemFk = vItemFromFk; - + IF ISNULL(vPicture) THEN - - SELECT image INTO vPicture - FROM vn.item + + SELECT image INTO vPicture + FROM vn.item WHERE id = vItemFromFk; - + END IF; - UPDATE vn.item i + UPDATE vn.item i SET i.image = vPicture WHERE i.id = vItemToFk; - + CALL vn.itemRefreshTags(vItemToFk); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62146,9 +62682,9 @@ BEGIN SELECT DISTINCT id FROM vn.itemCategory WHERE merchandise <> FALSE; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN RESIGNAL; END; @@ -62159,45 +62695,45 @@ BEGIN INNER JOIN bs.ventas v ON v.Id_Movimiento = s.id WHERE v.fecha BETWEEN TIMESTAMPADD(DAY, - 7, util.VN_CURDATE()) AND util.VN_CURDATE() GROUP BY s.itemFk; - + DROP TABLE IF EXISTS tmp.topSeller; - CREATE TEMPORARY TABLE 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; + 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 */ ; @@ -62307,7 +62843,7 @@ SET tag6 = t.name, value6 = it.value WHERE it.priority = 2 AND (vItem IS NULL OR vItem = it.itemFk); -UPDATE item i +UPDATE item i JOIN itemTag it ON it.itemFk = i.id JOIN tag t ON t.id = it.tagFk SET tag7 = t.name, value7 = it.value @@ -62340,7 +62876,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_cleanFloramondo`() BEGIN /** -* Elimina todos los items repetidos de floramondo +* Elimina todos los items repetidos de floramondo * y los sustituye por el que tiene menor id */ DECLARE vItemFrom INT; @@ -62406,7 +62942,7 @@ BEGIN AND i2.EmbalageCode <=> i.EmbalageCode AND i2.quality <=> i.quality JOIN ( - SELECT DISTINCT b.itemFk + SELECT DISTINCT b.itemFk FROM buy b JOIN item i ON i.id = b.itemFk WHERE i.isFloramondo @@ -62414,7 +62950,7 @@ BEGIN )sub2 ON sub2.itemFk = GREATEST(i.id, i2.id) WHERE i.isFloramondo AND i.id <> i2.id; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION SET vDone = TRUE; BEGIN SET vDone = TRUE; @@ -62545,6 +63081,316 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_comparative` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_comparative`( + vDate DATETIME, + vDayRange TINYINT, + vWarehouseFk TINYINT, + vAvailableSince DATE, + vBuyerFk INT, + vIsFloramondo BOOL, + vCountryFk INT +) +proc: BEGIN +/** + * Genera una tabla de comparativa de artículos por itemType/comprador/fecha. + * Los datos se calculan en función de los parámetros proporcionados. + * + * @param vDate La fecha para la cual se generará la comparativa. + * @param vDayRange El rango de días a considerar para la comparativa. + * @param vWarehouseFk El identificador del almacén para filtrar los artículos. + * @param vAvailableSince La fecha de disponibilidad desde la cual se consideran los artículos disponibles. + * @param vBuyerFk El identificador del comprador para filtrar los artículos. + * @param vIsFloramondo Indica si se deben incluir solo los artículos de Floramondo (opcional). + * @param vCountryFk El identificador del país. + * @param tmp.comparativeFilterType(filterFk INT ,itemTypeFk INT) + * @return tmp.comparative + */ + + DECLARE vDayRangeStart DATE; + DECLARE vDayRangeEnd DATE; + DECLARE w1, w2, w3, w4, w5, w6, w7 INT; + DECLARE y1, y2, y3, y4, y5, y6, y7 INT; + DECLARE z1, z2, z3, z4, z5, z6, z7 INT; + DECLARE vPeriod INT; + DECLARE i INT DEFAULT 0; + DECLARE vHasTypeFilter BOOL; + DECLARE vWeekRange INT; + DECLARE vWeekCount TINYINT; + DECLARE vMaxDayRange INT; + DECLARE vMinDayRange INT; + DECLARE vDefaultDayRange INT; + + IF NOT(SELECT COUNT(*) FROM comparativeConfig)THEN + LEAVE proc; + END IF; + + SELECT weekRange, + weekRange * 2 + 1, + maxDayRange, + minDayRange, + defaultDayRange + INTO vWeekRange, + vWeekCount, + vMaxDayRange, + vMinDayRange, + vDefaultDayRange + FROM comparativeConfig; + + IF vDayRange < vMinDayRange OR vDayRange > vMaxDayRange THEN + SET vDayRange = vDefaultDayRange; + END IF; + + SELECT MIN(dated) INTO vDayRangeStart + FROM vn.time + WHERE dated <= vDate + GROUP BY period + ORDER BY dated desc + LIMIT 1 OFFSET vWeekRange; + + SELECT MAX(dated) INTO vDayRangeEnd + FROM vn.time + WHERE dated >= vDate + GROUP BY period + ORDER BY dated ASC + LIMIT 1 OFFSET vWeekRange; + + SELECT COUNT(itemTypeFk) > 0 INTO vHasTypeFilter + FROM tmp.comparativeFilterType; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemInventory + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT i.id + FROM item i + JOIN itemType t ON t.id = i.typeFk + JOIN itemCategory c ON c.id = t.categoryFk + LEFT JOIN worker w ON w.id = t.workerFk + WHERE (NOT vHasTypeFilter + OR t.id IN (SELECT itemTypeFk FROM tmp.comparativeFilterType)) + AND (vBuyerFk IS NULL + OR t.workerFk = vBuyerFk) + AND (vIsFloramondo IS NULL + OR i.isFloramondo = vIsFloramondo); + + IF vDate < util.VN_CURDATE() THEN + ALTER TABLE tmp.itemInventory + ADD `buy_id` INT NOT NULL DEFAULT 0, + ADD `buy_date` DATE DEFAULT '2000-01-01', + ADD `life` INT DEFAULT 0, + ADD `sd` INT DEFAULT 0, + ADD `avalaible` INT DEFAULT 0, + ADD `visible` INT DEFAULT 0; + ELSE + CALL multipleInventory(vAvailableSince, vWarehouseFk, vDayRange); + CALL item_multipleBuy(vDate, vWarehouseFk); + CALL item_multipleBuyByDate(vDate, vWarehouseFk); + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tTable ( + cy INT(6) PRIMARY KEY, + ly INT(6), + zy INT(6), + INDEX (ly) + ); + + REPEAT + SET i = i + 1; + + SELECT t.period INTO vPeriod + FROM vn.`time` t + WHERE t.dated = vDayRangeStart + INTERVAL (vWeekCount * (i - 1)) DAY; + + INSERT IGNORE INTO tTable(cy, ly, zy) VALUES(vPeriod, vPeriod - 100, vPeriod - 200); + UNTIL i = vWeekCount END REPEAT; + + SELECT cy, ly, zy INTO w1, y1, z1 FROM tTable LIMIT 1; + SELECT cy, ly, zy INTO w2, y2, z2 FROM tTable WHERE cy > w1 LIMIT 1; + SELECT cy, ly, zy INTO w3, y3, z3 FROM tTable WHERE cy > w2 LIMIT 1; + SELECT cy, ly, zy INTO w4, y4, z4 FROM tTable WHERE cy > w3 LIMIT 1; + SELECT cy, ly, zy INTO w5, y5, z5 FROM tTable WHERE cy > w4 LIMIT 1; + SELECT cy, ly, zy INTO w6, y6, z6 FROM tTable WHERE cy > w5 LIMIT 1; + SELECT cy, ly, zy INTO w7, y7, z7 FROM tTable WHERE cy > w6 LIMIT 1; + + -- Genera una tabla con los datos del año pasado. + + CREATE OR REPLACE TEMPORARY TABLE tLastYear + (KEY (lItemFk)) + ENGINE = MEMORY + SELECT c.itemFk lItemFk, + SUM(IF(c.timePeriod = y1, c.quantity, 0)) lweek1, + SUM(IF(c.timePeriod = y2, c.quantity, 0)) lweek2, + SUM(IF(c.timePeriod = y3, c.quantity, 0)) lweek3, + SUM(IF(c.timePeriod = y4, c.quantity, 0)) lweek4, + SUM(IF(c.timePeriod = y5, c.quantity, 0)) lweek5, + SUM(IF(c.timePeriod = y6, c.quantity, 0)) lweek6, + SUM(IF(c.timePeriod = y7, c.quantity, 0)) lweek7, + SUM(IF(c.timePeriod = y1, c.price, 0)) lprice1, + SUM(IF(c.timePeriod = y2, c.price, 0)) lprice2, + SUM(IF(c.timePeriod = y3, c.price, 0)) lprice3, + SUM(IF(c.timePeriod = y4, c.price, 0)) lprice4, + SUM(IF(c.timePeriod = y5, c.price, 0)) lprice5, + SUM(IF(c.timePeriod = y6, c.price, 0)) lprice6, + SUM(IF(c.timePeriod = y7, c.price, 0)) lprice7 + FROM tmp.itemInventory ai + JOIN comparative c ON c.itemFk = ai.id + JOIN warehouse w on w.id = c.warehouseFk + JOIN tTable wt ON c.timePeriod = wt.ly + WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk + AND w.isComparative + AND (vCountryFk IS NULL OR c.countryFk = vCountryFk) + GROUP BY ai.id; + + -- Genera una tabla con los datos de hace DOS años. + + CREATE OR REPLACE TEMPORARY TABLE tTwoYearsAgo + (KEY (tItemFk)) + ENGINE = MEMORY + SELECT c.itemFk tItemFk, + SUM(IF(c.timePeriod = z1, c.quantity, 0)) vlweek1, + SUM(IF(c.timePeriod = z2, c.quantity, 0)) vlweek2, + SUM(IF(c.timePeriod = z3, c.quantity, 0)) vlweek3, + SUM(IF(c.timePeriod = z4, c.quantity, 0)) vlweek4, + SUM(IF(c.timePeriod = z5, c.quantity, 0)) vlweek5, + SUM(IF(c.timePeriod = z6, c.quantity, 0)) vlweek6, + SUM(IF(c.timePeriod = z7, c.quantity, 0)) vlweek7, + SUM(IF(c.timePeriod = z1, c.price, 0)) vlprice1, + SUM(IF(c.timePeriod = z2, c.price, 0)) vlprice2, + SUM(IF(c.timePeriod = z3, c.price, 0)) vlprice3, + SUM(IF(c.timePeriod = z4, c.price, 0)) vlprice4, + SUM(IF(c.timePeriod = z5, c.price, 0)) vlprice5, + SUM(IF(c.timePeriod = z6, c.price, 0)) vlprice6, + SUM(IF(c.timePeriod = z7, c.price, 0)) vlprice7 + FROM tmp.itemInventory ai + JOIN comparative c ON c.itemFk = ai.id + JOIN warehouse w on w.id = c.warehouseFk + JOIN tTable wt ON c.timePeriod = wt.zy + WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk + AND w.isComparative + AND (vCountryFk IS NULL OR c.countryFk = vCountryFk) + GROUP BY ai.id; + + -- Genera una tabla con los datos de este año.ss + + CREATE OR REPLACE TEMPORARY TABLE tCurrentYear + (KEY (cItemFk)) + ENGINE = MEMORY + SELECT t.itemFk cItemFk, + SUM(IF(week = w1, total, 0)) cweek1, + SUM(IF(week = w2, total, 0)) cweek2, + SUM(IF(week = w3, total, 0)) cweek3, + SUM(IF(week = w4, total, 0)) cweek4, + SUM(IF(week = w5, total, 0)) cweek5, + SUM(IF(week = w6, total, 0)) cweek6, + SUM(IF(week = w7, total, 0)) cweek7, + SUM(IF(week = w1, price, 0)) cprice1, + SUM(IF(week = w2, price, 0)) cprice2, + SUM(IF(week = w3, price, 0)) cprice3, + SUM(IF(week = w4, price, 0)) cprice4, + SUM(IF(week = w5, price, 0)) cprice5, + SUM(IF(week = w6, price, 0)) cprice6, + SUM(IF(week = w7, price, 0)) cprice7 + FROM ( + SELECT s.itemFk, + ti.period `week`, + SUM(s.quantity) total, + TRUNCATE(SUM(s.quantity * s.priceFixed),0) price + FROM ticket t + JOIN sale s ON t.id = s.ticketFk + JOIN tmp.itemInventory it ON it.id = s.itemFk + JOIN time ti ON ti.dated = DATE(t.shipped) + JOIN item i ON i.id = s.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + JOIN warehouse w ON w.id = t.warehouseFk + STRAIGHT_JOIN address ad ON ad.id = t.addressFk + JOIN province p ON p.id = ad.provinceFk + JOIN `client` c ON c.id = ad.clientFk + WHERE t.shipped BETWEEN vDayRangeStart AND util.dayEnd(vDayRangeEnd) + AND c.typeFk IN ('Normal','handMaking') + AND w.id = COALESCE(vWarehouseFk, w.id) + AND w.isComparative + AND (vCountryFk IS NULL OR p.countryFk = vCountryFk) + GROUP BY i.id, week + ) t + GROUP BY t.itemFk; + + -- Genera la tabla con la comparativa. + CREATE OR REPLACE TEMPORARY TABLE tmp.comparative + ENGINE = MEMORY + SELECT it.subName productor, + b.packing, + b.buyingValue costefijo, + b.groupingMode caja, + it.image ArticleImage, + IFNULL(it.inkFk,"?") color, + tp.code tipo, + it.typeFk tipo_id, + o.code origen, + it.category categoria, + it.stems tallos, + it.size medida, + it.name article, + w.code codigoTrabajador, + tp.categoryFk reino_id, + ly.*, + cy.*, + zy.*, + it.*, + it.id Id_Article, + i.buy_id, + tp.life, + IFNULL(i.sd,0) sd, + i.avalaible, + i.visible, + i.buy_date, + e.id provider_id, + it.comment comments, + it.description itemDescription, + IF(cy.cItemFk IS NULL AND i.visible = 0 AND i.avalaible = 0 + AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) filtret, + IF(it.hasMinPrice, FORMAT(it.minPrice, 2), "") pvp, + s.company_name + FROM tmp.itemInventory i + JOIN item it ON it.id = i.id + LEFT JOIN itemType tp ON tp.id = it.typeFk + LEFT JOIN worker w ON w.id = tp.workerFk + LEFT JOIN buy b ON b.id = i.buy_id + LEFT JOIN entry e ON e.id = b.entryFk + LEFT JOIN origin o ON o.id = it.originFk + LEFT JOIN tLastYear ly ON ly.lItemFk = it.id + LEFT JOIN tCurrentYear cy ON cy.cItemFk = it.id + LEFT JOIN tTwoYearsAgo zy ON zy.tItemFk = it.id + LEFT JOIN edi.ekt e2 ON e2.id = b.ektFk + LEFT JOIN edi.supplier s ON s.supplier_id = e2.pro + WHERE i.avalaible + OR i.visible + OR i.sd + OR cy.cweek1 OR cy.cweek2 OR cy.cweek3 OR cy.cweek4 OR cy.cweek5 OR cy.cweek6 OR cy.cweek7 + OR ly.lweek1 OR ly.lweek2 OR ly.lweek3 OR ly.lweek4 OR ly.lweek5 OR ly.lweek6 OR ly.lweek7 + OR zy.vlweek1 OR zy.vlweek2 OR zy.vlweek3 OR zy.vlweek4 OR zy.vlweek5 OR zy.vlweek6 OR zy.vlweek7; + + -- Elimina las tablas temporales creadas... + DROP TEMPORARY TABLE IF EXISTS tmp.itemInventory, + tTwoYearsAgo, + tLastYear, + tCurrentYear, + tTable; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_deactivateUnused` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62598,50 +63444,50 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getAtp`(vDated DATE) -BEGIN -/** - * Calcula el valor mínimo acumulado para cada artículo ordenado por fecha y - * almacén. - * - * @param vDated Si no hay movimientos en la fecha indicada, debe devolver 0 - * @table tmp.itemCalc(itemFk, wareHouseFk, dated, quantity) - * @return tmp.itemAtp(itemFk, warehouseFk, quantity) - */ - CREATE OR REPLACE TEMPORARY TABLE tItemOrdered - (UNIQUE(itemFk, warehouseFk, dated)) - ENGINE = MEMORY - SELECT itemFk, warehouseFk, dated, SUM(quantity) quantity - FROM ( - SELECT itemFk, warehouseFk, dated, quantity - FROM tmp.itemCalc - UNION ALL - SELECT itemFk, warehouseFk, vDated, 0 - FROM (SELECT DISTINCT itemFk, warehouseFk FROM tmp.itemCalc) t2 - ) t1 - GROUP BY itemFk, warehouseFk, dated - ORDER BY itemFk, warehouseFk, dated; - - SET @lastItemFk := 0; - SET @lastWareHouseFk := 0; - SET @lastQuantity := 0; - - CREATE OR REPLACE TEMPORARY TABLE tmp.itemAtp - (INDEX (itemFk, wareHouseFk)) - SELECT itemFk, wareHouseFk, MIN(quantityAccumulated) quantity - FROM ( - SELECT - itemFk, - IF(itemFk <> @lastItemFk OR wareHouseFk <> @lastWareHouseFk, - @lastQuantity := quantity, - @lastQuantity := @lastQuantity + quantity) quantityAccumulated, - wareHouseFk, - @lastItemFk := itemFk, - @lastWareHouseFk := wareHouseFk - FROM tItemOrdered - )sub - GROUP BY itemFk, wareHouseFk; - - DROP TEMPORARY TABLE tItemOrdered; +BEGIN +/** + * Calcula el valor mínimo acumulado para cada artículo ordenado por fecha y + * almacén. + * + * @param vDated Si no hay movimientos en la fecha indicada, debe devolver 0 + * @table tmp.itemCalc(itemFk, wareHouseFk, dated, quantity) + * @return tmp.itemAtp(itemFk, warehouseFk, quantity) + */ + CREATE OR REPLACE TEMPORARY TABLE tItemOrdered + (UNIQUE(itemFk, warehouseFk, dated)) + ENGINE = MEMORY + SELECT itemFk, warehouseFk, dated, SUM(quantity) quantity + FROM ( + SELECT itemFk, warehouseFk, dated, quantity + FROM tmp.itemCalc + UNION ALL + SELECT itemFk, warehouseFk, vDated, 0 + FROM (SELECT DISTINCT itemFk, warehouseFk FROM tmp.itemCalc) t2 + ) t1 + GROUP BY itemFk, warehouseFk, dated + ORDER BY itemFk, warehouseFk, dated; + + SET @lastItemFk := 0; + SET @lastWareHouseFk := 0; + SET @lastQuantity := 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemAtp + (INDEX (itemFk, wareHouseFk)) + SELECT itemFk, wareHouseFk, MIN(quantityAccumulated) quantity + FROM ( + SELECT + itemFk, + IF(itemFk <> @lastItemFk OR wareHouseFk <> @lastWareHouseFk, + @lastQuantity := quantity, + @lastQuantity := @lastQuantity + quantity) quantityAccumulated, + wareHouseFk, + @lastItemFk := itemFk, + @lastWareHouseFk := wareHouseFk + FROM tItemOrdered + )sub + GROUP BY itemFk, wareHouseFk; + + DROP TEMPORARY TABLE tItemOrdered; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62667,13 +63513,13 @@ BEGIN /** * @vItemFk item a buscar * @vWarehouseFk almacen donde buscar - * @vDate Si la fecha es null, muestra el histórico desde el inventario. + * @vDate Si la fecha es null, muestra el histórico desde el inventario. * Si la fecha no es null, muestra histórico desde la fecha pasada. */ DECLARE vDateInventory DATETIME; IF vDate IS NULL THEN - SELECT inventoried INTO vDateInventory + SELECT inventoried INTO vDateInventory FROM config; ELSE SELECT mockUtcTime INTO vDateInventory @@ -62699,7 +63545,7 @@ BEGIN inventorySupplierFk INT(10) ); - INSERT INTO tItemDiary + INSERT INTO tItemDiary SELECT tr.landed shipped, b.quantity `in`, NULL `out`, @@ -62720,14 +63566,14 @@ BEGIN JOIN entry e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk JOIN supplier s ON s.id = e.supplierFk - JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() + JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() OR (util.VN_CURDATE() AND tr.isReceived), - 'DELIVERED', + 'DELIVERED', 'FREE') JOIN entryConfig ec WHERE tr.landed >= vDateInventory AND vWarehouseFk = tr.warehouseInFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) AND b.itemFk = vItemFk AND e.isExcludedFromAvailable = FALSE AND e.isRaid = FALSE @@ -62753,14 +63599,14 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk JOIN warehouse w ON w.id = tr.warehouseOutFk JOIN supplier s ON s.id = e.supplierFk - JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() + JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), - 'DELIVERED', + 'DELIVERED', 'FREE') JOIN entryConfig ec WHERE tr.shipped >= vDateInventory AND vWarehouseFk = tr.warehouseOutFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) AND b.itemFk = vItemFk AND e.isExcludedFromAvailable = FALSE AND w.isFeedStock = FALSE @@ -62784,17 +63630,17 @@ BEGIN NULL FROM sale s JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN ticketState ts ON ts.ticket = t.id + LEFT JOIN ticketState ts ON ts.ticketFk = t.id LEFT JOIN state st ON st.`code` = ts.`code` JOIN client c ON c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), - 'DELIVERED', + 'DELIVERED', IF (t.shipped > util.dayEnd(util.VN_CURDATE()), 'FREE', IFNULL(ts.code, 'FREE'))) LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' - LEFT JOIN saleTracking stk ON stk.saleFk = s.id + LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id LEFT JOIN claimBeginning cb ON s.id = cb.saleFk WHERE t.shipped >= vDateInventory @@ -62810,7 +63656,7 @@ BEGIN `out` DESC; IF vDate IS NULL THEN - + SET @a := 0; SET @currentLineFk := 0; SET @shipped := ''; @@ -62825,9 +63671,9 @@ BEGIN `in` invalue, `out`, @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0) balance, - @currentLineFk := IF (@shipped < util.VN_CURDATE() + @currentLineFk := IF (@shipped < util.VN_CURDATE() OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')), - lineFk, + lineFk, @currentLineFk) lastPreparedLineFk, isTicket, lineFk, @@ -62859,25 +63705,25 @@ BEGIN 0 clientType, 0 claimFk UNION ALL - SELECT shipped, - alertlevel, - stateName, - origin, - reference, - clientFk, - name, `in`, - `out`, - @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), - 0, - isTicket, - lineFk, - isPicked, - clientType, + SELECT shipped, + alertlevel, + stateName, + origin, + reference, + clientFk, + name, `in`, + `out`, + @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), + 0, + isTicket, + lineFk, + isPicked, + clientType, claimFk FROM tItemDiary WHERE shipped >= vDate; END IF; - + DROP TEMPORARY TABLE tItemDiary; END ;; DELIMITER ; @@ -62984,7 +63830,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getLack`(IN vForce BOOLEAN, IN BEGIN /** * Calcula una tabla con el máximo negativo visible para cada producto y almacen - * + * * @param vForce Fuerza el recalculo del stock * @param vDays Numero de dias a considerar **/ @@ -62994,32 +63840,32 @@ BEGIN CALL item_getMinETD(); CALL item_zoneClosure(); - SELECT i.id itemFk, + SELECT i.id itemFk, i.longName, w.id warehouseFk, - p.`name` producer, + p.`name` producer, i.`size`, i.category, - w.name warehouse, + w.name warehouse, SUM(IFNULL(sub.amount,0)) lack, i.inkFk, IFNULL(im.timed, util.midnight()) timed, IFNULL(izc.timed, util.midnight()) minTimed - FROM (SELECT item_id, - warehouse_id, + FROM (SELECT item_id, + warehouse_id, amount FROM cache.stock WHERE amount > 0 UNION ALL - SELECT itemFk, - warehouseFk, + SELECT itemFk, + warehouseFk, amount FROM tmp.itemMinacum ) sub JOIN warehouse w ON w.id = sub.warehouse_id JOIN item i ON i.id = sub.item_id - LEFT JOIN producer p ON p.id = i.producerFk - JOIN itemType it ON it.id = i.typeFk + LEFT JOIN producer p ON p.id = i.producerFk + JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id @@ -63142,12 +63988,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getMinETD`() BEGIN - + /* Devuelve una tabla temporal con la primera ETD, para todos los artículos con salida hoy. - * + * * @return tmp.itemMinETD(itemFk, timed) */ - + DECLARE vMidnight DATETIME DEFAULT util.midnight(); DROP TEMPORARY TABLE IF EXISTS tmp.itemMinETD; @@ -63158,7 +64004,7 @@ BEGIN SELECT s.itemFk, MIN(TIME(IFNULL(z.`hour`,vMidnight))) timed FROM ticket t JOIN sale s ON s.ticketFk = t.id - LEFT JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN `zone` z ON z.id = t.zoneFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND vMidnight GROUP BY s.itemFk; END ;; @@ -63188,33 +64034,33 @@ BEGIN * @param vWarehouseFk warehouse id * @param vDate fecha para revisar disponible * @param vIsShowedByType para mostrar solo artículos de ese tipo - */ + */ DECLARE vCalcFk INT; DECLARE vTypeFk INT; - + DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag6 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag7 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vTag8 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - + DECLARE vValue1 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue5 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue6 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'; - + SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 FROM vn.item i LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk WHERE i.id = vItemFk; - + CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDate); - + SELECT i.id itemFk, i.longName, i.subName, @@ -63247,7 +64093,7 @@ BEGIN ORDER BY counter DESC, (t1.name = vTag1) DESC, (it1.value = vValue1) DESC, - (i.tag6 = vTag6) DESC, + (i.tag6 = vTag6) DESC, (i.value6 = vValue6) DESC, (i.tag5 = vTag5) DESC, (i.value5 = vValue5) DESC, @@ -63256,7 +64102,7 @@ BEGIN (i.tag8 = vTag8) DESC, (i.value8 = vValue8) DESC LIMIT 30; - + END ;; DELIMITER ; @@ -63407,6 +64253,108 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_multipleBuy` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_multipleBuy`( + vDate DATETIME, + vWarehouseFk INT +) +BEGIN +/** + * Updates the tmp.itemInventory table, adding the buy id. + * + * @param tmp.itemInventory(buy_id) + * @param vDate -> Date of the purchase operation. + * @param vWarehouseFk -> Identifier of the warehouse (warehouseId). + */ + ALTER TABLE tmp.itemInventory ADD IF NOT EXISTS buy_id INT; + + CALL buyUltimate(vWarehouseFk, vDate); + + CREATE OR REPLACE TEMPORARY TABLE tmp + (KEY (itemFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT itemFk, buyFk + FROM tmp.buyUltimate + ORDER BY (vWarehouseFk = warehouseFk) DESC, landing DESC + LIMIT 10000000000000000000 + ) t + GROUP BY itemFk; + + UPDATE tmp.itemInventory ai + JOIN tmp t ON ai.id = t.itemFk + SET ai.buy_id = t.buyFk; + + DROP TEMPORARY TABLE tmp, tmp.buyUltimate; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_multipleBuyByDate` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_multipleBuyByDate`( + vDated DATETIME, + vWarehouseFk TINYINT(3) +) +BEGIN +/** + * Updates the tmp.itemInventory table, adding the purchase date. + * + * @param tmp.itemInventory(buy_date) + * @param vDated -> end date + * @param vWarehouseFk -> warehouse id + */ + DECLARE vLastBuyScope INT; + SELECT comparativeLastBuyScope INTO vLastBuyScope + FROM config; + + ALTER TABLE tmp.itemInventory + ADD `buy_date` datetime NOT NULL; + + CREATE OR REPLACE TEMPORARY TABLE lastBuyScope + SELECT i.id, MAX(t.landed) lastLanded + FROM item i + JOIN buy b ON b.itemFk = i.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN supplier s ON s.id = e.supplierFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN (vDated + INTERVAL - vLastBuyScope DAY) AND vDated + AND NOT s.name = 'INVENTARIO' + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND w.isComparative + AND NOT e.isRaid + GROUP BY i.id; + + UPDATE tmp.itemInventory y + JOIN lastBuyScope lbs ON lbs.id = y.id + SET y.buy_date = lbs.lastLanded; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_refreshFromTags` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63541,11 +64489,11 @@ BEGIN * @param vBarcode del item * @param vReference referencia a actualizar */ - + DECLARE vItemFk INT; SELECT barcodeToItem(vBarcode) INTO vItemFk; - + UPDATE item SET comment = vReference WHERE id = vItemFk; END ;; @@ -63568,7 +64516,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `item_setGeneric`(vSelf INT) BEGIN /** * Asigna el código genérico a un item, salvo que sea un código de item genérico. - * + * * @param vSelf identificador de vn.item */ DECLARE vGenericFk INT; @@ -63578,7 +64526,7 @@ BEGIN SELECT itemFk, SUM(matches) = maxMatches `match` FROM ( SELECT ga.id gaid, ga.itemFk, - CASE + CASE WHEN t.code = 'nflowers' THEN it.value <=> ga.numFlores WHEN t.code = 'origin' THEN @@ -63609,13 +64557,13 @@ BEGIN AND (i.`size` = ga.`size` OR ga.`size` IS NULL) AND i.id != ga.itemFk WHERE i.id = vSelf - AND NOT i.isFloramondo) sub + AND NOT i.isFloramondo) sub GROUP BY gaid HAVING `match`) sub2 LIMIT 1; - UPDATE vn.item - SET genericFk = vGenericFk + UPDATE vn.item + SET genericFk = vGenericFk WHERE id = vSelf; END ;; DELIMITER ; @@ -63657,11 +64605,11 @@ BEGIN SELECT DEFAULT(companyFk) INTO vDefaultCompanyFk FROM vn.ticket LIMIT 1; - - IF vAddressFk IS NULL THEN + + IF vAddressFk IS NULL THEN SELECT pc.shortageAddressFk INTO vAddressShortage FROM productionConfig pc ; - ELSE + ELSE SET vAddressShortage = vAddressFk; END IF; @@ -63726,18 +64674,18 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_updatePackingShelve`(vSelf INT, vPacking INT) BEGIN - + /** * Actualiza el valor de item.packingShelve - * + * * @param vSelf Identificador de vn.item * @param vPacking Cantidad de unidades de venta que caben en una bandeja */ - - UPDATE vn.item i + + UPDATE vn.item i SET i.packingShelve = vPacking WHERE i.id = vSelf; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -63780,204 +64728,240 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_ValuateInventory`(IN vDated DATE, IN vIsDetailed BOOLEAN) +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_ValuateInventory`(vDated DATE, vIsDetailed BOOLEAN) BEGIN + DECLARE vInventoried DATE; + DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE; + DECLARE vInventoryClone DATE; + DECLARE vDateDayEnd DATETIME; + DECLARE vInventorySupplierFk INT; - DECLARE vInventoried DATE; - DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE; - DECLARE vInventoried2 DATE; - DECLARE vDateDayEnd DATETIME; - DECLARE vInventorySupplierFk INT; + SELECT inventorySupplierFk INTO vInventorySupplierFk + FROM entryConfig; - SELECT inventorySupplierFk INTO vInventorySupplierFk - FROM entryConfig; + SET vDateDayEnd = util.dayEnd(vDated); - SET vDateDayEnd = util.dayEnd(vDated); + SELECT tr.landed INTO vInventoried + FROM travel tr + JOIN `entry` e ON e.travelFk = tr.id + JOIN entryConfig ec + WHERE landed <= vDateDayEnd + AND e.supplierFk = vInventorySupplierFk + ORDER BY tr.landed DESC + LIMIT 1; - SELECT landed INTO vInventoried - FROM travel tr - JOIN entry E ON E.travelFk = tr.id - WHERE landed <= vDateDayEnd - AND E.supplierFk = vInventorySupplierFk - ORDER BY landed DESC - LIMIT 1; + SET vHasNotInventory = (vInventoried IS NULL); + + IF vHasNotInventory THEN + SELECT landed INTO vInventoryClone + FROM travel tr + JOIN `entry` e ON e.travelFk = tr.id + JOIN entryConfig ec + WHERE landed >= vDated + AND e.supplierFk = vInventorySupplierFk + ORDER BY landed ASC + LIMIT 1; - SET vHasNotInventory = IF (vInventoried is null, TRUE, FALSE); + SET vInventoried = vDated + INTERVAL 1 DAY; + SET vDateDayEnd = vInventoryClone; + END IF; - IF vHasNotInventory THEN + CREATE OR REPLACE TEMPORARY TABLE tInventory( + warehouseFk SMALLINT, + itemFk BIGINT, + quantity INT, + cost DOUBLE DEFAULT 0, + total DOUBLE DEFAULT 0, + warehouseInventory VARCHAR(20), + PRIMARY KEY (warehouseInventory, itemFk) USING HASH + ) + ENGINE = MEMORY; + + -- Inventario inicial + IF vHasNotInventory THEN + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + SUM(b.quantity), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = warehouseInFk + JOIN entryConfig ec + WHERE landed = vDateDayEnd + AND e.supplierFk = vInventorySupplierFk + AND w.valuatedInventory + AND t.isInventory + GROUP BY tr.warehouseInFk, b.itemFk; + ELSE + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + SUM(b.quantity), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = warehouseInFk + JOIN entryConfig ec + WHERE landed = vInventoried + AND e.supplierFk = vInventorySupplierFk + AND w.valuatedInventory + AND t.isInventory + GROUP BY tr.warehouseInFk, b.itemFk; + END IF; - SELECT landed INTO vInventoried2 - FROM travel tr - JOIN entry E ON E.travelFk = tr.id - WHERE landed >= vDated - AND E.supplierFk = vInventorySupplierFk - ORDER BY landed ASC - LIMIT 1; + -- Añadimos las entradas + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + b.quantity * IF(vHasNotInventory, -1, 1), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = tr.warehouseInFk + JOIN entryConfig ec + WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd + AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE) + AND NOT e.isRaid + AND w.valuatedInventory + AND t.isInventory + AND e.supplierFk <> vInventorySupplierFk + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory, -1, 1)); - SET vInventoried = TIMESTAMPADD(DAY,1,vDated); - SET vDateDayEnd = vInventoried2; + -- Descontamos las salidas + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseOutFk, + b.itemFk, + b.quantity * IF(vHasNotInventory, 1, -1), + w.name + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse w ON w.id = tr.warehouseOutFk + WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd + AND NOT e.isRaid + AND w.valuatedInventory + AND t.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity * IF(vHasNotInventory,1,-1)); - END IF; + -- Descontamos las lineas de venta + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT w.id, + s.itemFk, + s.quantity * IF(vHasNotInventory, 1, -1), + w.name + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN `client` c ON c.id = t.clientFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd + AND w.valuatedInventory + AND it.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 1, -1); - DROP TEMPORARY TABLE IF EXISTS inv; + -- Volver a poner lo que esta aun en las estanterias + IF vDated = util.VN_CURDATE() THEN + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT w.id, + s.itemFk, + s.quantity * IF(vHasNotInventory, 0, 1), + w.name + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN `client` c ON c.id = t.clientFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDated AND vDateDayEnd + AND NOT (s.isPicked OR t.isLabeled) + AND w.valuatedInventory + AND it.isInventory + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + s.quantity * IF(vHasNotInventory, 0, 1); + END IF; - CREATE TEMPORARY TABLE inv - (warehouseFk SMALLINT, - Id_Article BIGINT, - cantidad INT, - coste DOUBLE DEFAULT 0, - total DOUBLE DEFAULT 0, - Almacen VARCHAR(20), - PRIMARY KEY (Almacen, Id_Article) USING HASH) - ENGINE = MEMORY; + -- Mercancia en transito + INSERT INTO tInventory(warehouseFk, itemFk, quantity, warehouseInventory) + SELECT tr.warehouseInFk, + b.itemFk, + b.quantity, + CONCAT(wOut.`name`, ' - ', wIn.`name`) + FROM buy b + JOIN item i ON i.id = b.itemFk + JOIN `entry` e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + JOIN itemType t ON t.id = i.typeFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + WHERE vDated >= tr.shipped AND vDated < tr.landed + AND NOT isRaid + AND wIn.valuatedInventory + AND t.isInventory + AND e.isConfirmed + ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity); + + CALL vn.buyUltimate(NULL, vDateDayEnd); - IF vHasNotInventory = TRUE THEN + UPDATE tInventory i + JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk + JOIN buy b ON b.id = bu.buyFk + SET total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)), + cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0) + WHERE i.quantity; - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, SUM(b.quantity), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = warehouseInFk - WHERE landed = vDateDayEnd - AND e.supplierFk = vInventorySupplierFk - AND w.valuatedInventory - AND t.isInventory - GROUP BY tr.warehouseInFk, b.itemFk; + DELETE FROM tInventory + WHERE quantity IS NULL OR NOT quantity; - END IF; - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, - b.itemFk, - b.quantity * IF(vHasNotInventory,-1,1), - w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = tr.warehouseInFk - WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd - AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, trUE) - AND NOT e.isRaid - AND w.valuatedInventory - AND t.isInventory - AND e.supplierFk <> vInventorySupplierFk - ON DUPLICATE KEY UPDATE inv.cantidad = - inv.cantidad + (b.quantity * IF(vHasNotInventory,-1,1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseOutFk, b.itemFk, b.quantity * IF(vHasNotInventory,1,-1), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = tr.warehouseOutFk - WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd - AND NOT e.isRaid - AND w.valuatedInventory - AND t.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity * IF(vHasNotInventory,1,-1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,1,-1), w.`name` - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN `client` c ON c.id = t.clientFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd - AND w.valuatedInventory - AND it.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,1,-1); - - IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,0,1), w.`name` - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN `client` c ON c.id = t.clientFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDated AND vDateDayEnd - AND (s.isPicked <> 0 or t.isLabeled <> 0 ) - AND w.valuatedInventory - AND it.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,0,1); - - END IF; - - -- Mercancia en transito - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, b.quantity, CONCAT(wOut.`name`,' - ', wIn.`name`) - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk - WHERE vDated >= tr.shipped AND vDated < tr.landed - AND NOT isRaid - AND wIn.valuatedInventory - AND t.isInventory - AND e.isConfirmed - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity); - - CALL vn.buyUltimate(NULL,vDateDayEnd); - - UPDATE inv i - JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.Id_Article = bu.itemFk - JOIN buy b ON b.id = bu.buyFk - SET total = i.cantidad * (ifnull(b.buyingValue,0) + IFNULL(b.packageValue,0) + IFNULL(b.freightValue,0) + IFNULL(b.comissionValue,0)), - coste = ifnull(b.buyingValue,0) + IFNULL(b.packageValue,0) + IFNULL(b.freightValue,0) + IFNULL(b.comissionValue,0) - WHERE i.cantidad <> 0; - - DELETE FROM inv WHERE Cantidad IS NULL or Cantidad = 0; - - IF vIsDetailed THEN - - SELECT inv.warehouseFk, - i.id itemFk, - i.longName , - i.size, - inv.Cantidad, - tp.name Tipo, - ic.name Reino, - inv.coste, - cast(inv.total as decimal(10,2)) total, - almacen - FROM inv - JOIN warehouse w on w.id = warehouseFk - JOIN item i ON i.id = inv.Id_Article - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - WHERE w.valuatedInventory - and inv.total > 0 - order by inv.total desc; - - ELSE - - SELECT i.Almacen, ic.name as Reino, cast(i.total as decimal(10,2)) as Euros, w.code as Comprador,it.id - FROM inv i - JOIN warehouse wh on wh.id = warehouseFk - JOIN item it ON it.id = i.Id_Article - JOIN itemType itp ON itp.id = it.typeFk - LEFT JOIN worker w ON w.id = itp.workerFk - JOIN itemCategory ic ON ic.id = itp.categoryFk + IF vIsDetailed THEN + SELECT ti.warehouseFk, + i.id itemFk, + i.longName, + i.size, + ti.quantity, + tp.name Tipo, + ic.name Reino, + ti.cost, + CAST(ti.total AS DECIMAL(10, 2)) total, + ti.warehouseInventory almacen + FROM tInventory ti + JOIN warehouse w ON w.id = warehouseFk + JOIN item i ON i.id = ti.itemFk + JOIN itemType tp ON tp.id = i.typeFk + JOIN itemCategory ic ON ic.id = tp.categoryFk + WHERE w.valuatedInventory + AND ti.total > 0 + ORDER BY ti.total DESC; + ELSE + SELECT i.warehouseInventory Almacen, + ic.name Reino, + CAST(i.total AS DECIMAL(10, 2)) Euros, + w.code Comprador, + it.id + FROM tInventory i + JOIN warehouse wh ON wh.id = warehouseFk + JOIN item it ON it.id = i.itemFk + JOIN itemType itp ON itp.id = it.typeFk + LEFT JOIN worker w ON w.id = itp.workerFk + JOIN itemCategory ic ON ic.id = itp.categoryFk WHERE wh.valuatedInventory - AND i.total > 0; + AND i.total > 0; + END IF; - END IF; - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE inv; + DROP TEMPORARY TABLE + tmp.buyUltimate, + tInventory; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -63996,10 +64980,10 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_zoneClosure`() BEGIN - -/* Devuelve una tabla temporal con la hora minima de un ticket sino tiene el de la zoneClosure y + +/* Devuelve una tabla temporal con la hora minima de un ticket sino tiene el de la zoneClosure y * si tampoco hay el de la zona , para todos los artículos con salida hoy. - * + * * @return tmp.itemZoneClosure(itemFk, timed) */ @@ -64010,7 +64994,7 @@ BEGIN MIN(DATE_FORMAT(IF(HOUR(t.shipped),t.shipped, IFNULL(zc.hour, z.HOUR)), '%H:%i') )timed - FROM ticket t + FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN `zone` z ON z.id = t.zoneFk LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk @@ -64043,37 +65027,37 @@ BEGIN * @param vConcept descripcion * @param vAmount cantidad que se compensa * @param vCompany empresa - * @param vOriginalAccount cuenta contable desde la cual se compensa - * - */ + * @param vOriginalAccount cuenta contable desde la cual se compensa + * + */ DECLARE vNewBookEntry INT; DECLARE vIsClientCompensation INT; DECLARE vClientFk INT; DECLARE vSupplierFk INT; DECLARE vIsOriginalAClient BOOL; DECLARE vPayMethodCompensation INT; - + CALL ledger_next(vNewBookEntry); SELECT COUNT(id) INTO vIsOriginalAClient FROM client WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci; - SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation - FROM client + SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation + FROM client WHERE accountingAccount LIKE vCompensationAccount COLLATE utf8_general_ci; - + SET @vAmount1:= 0.0; SET @vAmount2:= 0.0; - INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id) - VALUES ( vNewBookEntry, - vDated, - vOriginalAccount, - vCompensationAccount, - vConcept, + INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id) + VALUES ( vNewBookEntry, + vDated, + vOriginalAccount, + vCompensationAccount, + vConcept, @vAmount1:= IF( - (vIsOriginalAClient AND vAmount > 0) OR - (NOT vIsOriginalAClient AND vAmount < 0), - 0, + (vIsOriginalAClient AND vAmount > 0) OR + (NOT vIsOriginalAClient AND vAmount < 0), + 0, ABS(vAmount) ), @vAmount2:= IF(@vAmount1, @@ -64082,20 +65066,20 @@ BEGIN ), vCompanyFk ), - ( vNewBookEntry, - vDated, - vCompensationAccount, - vOriginalAccount, - vConcept, + ( vNewBookEntry, + vDated, + vCompensationAccount, + vOriginalAccount, + vConcept, @vAmount2, @vAmount1, vCompanyFk); - + IF vIsClientCompensation THEN IF vIsOriginalAClient THEN SET vAmount = -vAmount; END IF; - INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate) + INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate) VALUES (vConcept, vAmount, vDated, vBankFk, vCompanyFk, vClientFk, TRUE); ELSE IF NOT vIsOriginalAClient THEN @@ -64103,7 +65087,7 @@ BEGIN END IF; SELECT id INTO vSupplierFk FROM supplier WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci; SELECT id INTO vPayMethodCompensation FROM payMethod WHERE `code` = 'compensation'; - + INSERT INTO payment (received, dueDated, supplierFk, amount, bankFk, payMethodFk, concept, companyFk, isConciliated) VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE); END IF; @@ -64125,10 +65109,10 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ledger_next`(OUT vNewBookEntry INT) BEGIN - + UPDATE vn.ledgerConfig SET lastBookEntry = LAST_INSERT_ID(lastBookEntry + 1); SET vNewBookEntry = LAST_INSERT_ID(); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64154,15 +65138,15 @@ BEGIN * @param vEntity Nombre que hace referencia a la tabla. */ DECLARE vTableName VARCHAR(45); - + SET vTableName = CONCAT(vEntity, 'Log'); - + SET @qryLog := CONCAT( 'SELECT ot.id, ot.originFk, ot.userFk, u.name, ot.action, ot.creationDate, ot.description FROM ', vTableName, ' AS ot', ' INNER JOIN account.user u ON u.id = ot.userFk', ' WHERE ot.originFk = ', vOriginFk, ' ORDER BY ot.creationDate DESC' ); - + PREPARE stmt FROM @qryLog; EXECUTE stmt; END ;; @@ -64187,9 +65171,9 @@ BEGIN SET @buildingOrder := 0; SET @route := 0; set @cajas := 0; - + UPDATE tmp.sorter - SET buildingOrder = @buildingOrder := IF(@route = @route := routeFk, @buildingOrder, 0) + 1 + SET buildingOrder = @buildingOrder := IF(@route = @route := routeFk, @buildingOrder, 0) + 1 where date(created) = vDate order by routeFk, created, weight DESC; @@ -64207,23 +65191,23 @@ set @cajas := 0; UPDATE tmp.sorter SET lungGrow = IF(palletOrder = 0, -13, lungGrow); - + DELETE FROM tmp.lungSize WHERE dia = vDate; - + INSERT INTO tmp.lungSize(dia, hora,size) select vDate,hora, @cajas := @cajas + cajas as size from ( select IF(lungGrow BETWEEN -12 AND -1, ETD,time_format(created,"%H:%i")) as hora, sum(if(lungGrow <= 0, lungGrow, 1)) as cajas, @cajas := 0 - from tmp.sorter + from tmp.sorter where date(created) = vDate group by hora ) sub; - + SELECT * FROM tmp.lungSize WHERE dia = vDate; - - + + END ;; @@ -64244,23 +65228,23 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT) BEGIN - + /** * Inserta registro si el vWorkerFk no ha registrado nada en las últimas 12 horas * @param vPlate número de matrícula - * @param vWorkerFk id del worker - * -*/ - UPDATE vn.machineWorker mw - JOIN vn.machine m ON m.id = mw.machineFk + * @param vWorkerFk id del worker + * +*/ + UPDATE vn.machineWorker mw + JOIN vn.machine m ON m.id = mw.machineFk SET mw.outTimed = util.VN_NOW() WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate) AND ISNULL(mw.outTimed); - + INSERT INTO machineWorker (machineFk, workerFk) SELECT m.id, vWorkerFk FROM machine m - WHERE m.plate= vPlate; + WHERE m.plate= vPlate; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64280,21 +65264,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT) BEGIN /** - * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, + * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, * si es jefe de producción muestra el historial completo. - * + * * @param vPlate número de matrícula - * @param vWorkerFk id del trabajador - * + * @param vWorkerFk id del trabajador + * */ DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vWorkerFk); - SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed + SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed FROM machineWorker mw JOIN machine m ON m.plate = vPlate WHERE mw.machineFk = m.id AND mw.workerFk = IF(account.user_hasRole(vWorkerName, 'coolerAssist'), mw.workerFk, vWorkerFk) - ORDER BY mw.inTimed DESC; + ORDER BY mw.inTimed DESC; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64313,13 +65297,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT) BEGIN - + /** - * Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate, - * + * Actualiza el registro correspondiente si el vWorkerFk se ha registrado en las últimas horas (campo maxHours de machineWorkerConfig) con vPlate, + * * @param vPlate número de matrícula - * @param vWorkerFk id del trabajador - * + * @param vWorkerFk id del trabajador + * */ DECLARE vMachineFk INT(10); @@ -64328,24 +65312,24 @@ BEGIN SELECT m.id INTO vMachineFk FROM machine m WHERE m.plate = vPlate; - + SELECT maxHours INTO vMaxHours FROM machineWorkerConfig; - IF (SELECT COUNT(*) + IF (SELECT COUNT(*) FROM machineWorker m WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN - + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN + UPDATE machineWorker m SET m.outTimed = CURRENT_TIMESTAMP() - WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed) AND m.machineFk = vMachineFk; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64400,12 +65384,12 @@ BEGIN /** * Inserta en la tabla vn.mail * - * @param vReceiver Receptor del correo + * @param vReceiver Receptor del correo * @param vReplyTo A quién contestar el correo * @param vSubject Título del correo * @param vBody Cuerpo del correo */ - + DECLARE vIsRepeated BOOLEAN; SELECT COUNT(*) INTO vIsRepeated @@ -64446,12 +65430,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `makeNewItem`() BEGIN DECLARE newItemFk INT; - + SELECT getNewItemId() INTO newItemFk; - + INSERT INTO item(id,name,typeFk,originFk) SELECT newItemFk, 'Nuevo artículo', 78,39; - + SELECT newItemFk; @@ -64479,34 +65463,34 @@ BEGIN DECLARE vMinute INT DEFAULT 0; DECLARE vBoxes INT; - + DROP TEMPORARY TABLE IF EXISTS vn.pcsDay; CREATE TEMPORARY TABLE vn.pcsDay SELECT 0 as hh, 0 as mm, 0 as boxes; - + -- Creamos una tabla soporte para acumular las cajas a lo largo del dia WHILE vHour < 24 DO - + WHILE vMinute < 59 DO - + SET vMinute = vMinute + 1; - + INSERT INTO vn.pcsDay(hh,mm) VALUES(vHour, vMinute); - + END WHILE; - + SET vMinute = -1; SET vHour = vHour + 1; - + END WHILE; - + -- Acumulamos UPDATE vn.pcsDay pd LEFT JOIN (SELECT * FROM vn.pcs_graf WHERE dia = vDated) pg USING(hh,mm) SET pd.boxes = pd.boxes + pg.box; - + SELECT * FROM vn.pcsDay; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64543,7 +65527,7 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.client SELECT id - FROM client + FROM client WHERE salesPersonFk = vWorkerFk; CALL client_getMana(); @@ -64553,7 +65537,7 @@ BEGIN FROM tmp.clientMana ON DUPLICATE KEY UPDATE amount = VALUES(amount); - DROP TEMPORARY TABLE + DROP TEMPORARY TABLE tmp.client, tmp.clientMana; END ;; @@ -64572,196 +65556,197 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `multipleInventory`( - vDate DATE, - vWarehouseFk TINYINT, - vMaxDays TINYINT +CREATE DEFINER=`root`@`localhost` PROCEDURE `multipleInventory`( + vDate DATE, + vWarehouseFk TINYINT, + vMaxDays TINYINT ) -proc: BEGIN - DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; - DECLARE vDateFrom DATE DEFAULT vDate; - DECLARE vDateTo DATETIME; - DECLARE vDateToTomorrow DATETIME; - DECLARE vDefaultDayRange INT; - - IF vDate < util.VN_CURDATE() THEN - LEAVE proc; - END IF; - - IF vDate = util.VN_CURDATE() THEN - SELECT inventoried INTO vDateFrom - FROM config; - END IF; - - SELECT defaultDayRange INTO vDefaultDayRange - FROM comparativeConfig; - - SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; - SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; - - ALTER TABLE vn2008.article_inventory - ADD `avalaible` INT NOT NULL, - ADD `sd` INT NOT NULL, - ADD `rest` INT NOT NULL, - ADD `expected` INT NOT NULL, - ADD `inventory` INT NOT NULL, - ADD `visible` INT NOT NULL, - ADD `life` TINYINT NOT NULL DEFAULT '0'; - - -- Calculo del inventario - UPDATE vn2008.article_inventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, - s.quantity quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - ) sub2 - GROUP BY itemFk - ) sub ON ai.article_id = sub.Id_Article - SET ai.inventory = sub.Subtotal, - ai.visible = sub.Subtotal, - ai.avalaible = sub.Subtotal, - ai.sd = sub.Subtotal; - - -- Cálculo del visible - UPDATE vn2008.article_inventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, s.quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped >= vDate - AND t.shipped < vDateTomorrow - AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - ) sub2 - GROUP BY itemFk - ) sub ON ai.article_id = sub.Id_Article - SET ai.visible = ai.visible + sub.Subtotal; - - -- Calculo del disponible - CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc - (INDEX (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT sub.itemFk, - vWarehouseFk warehouseFk, - sub.dated, - SUM(sub.quantity) quantity - FROM ( - SELECT s.itemFk, - DATE(t.shipped) dated, - - s.quantity quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, t.landed, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, t.shipped, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - ) sub - GROUP BY sub.itemFk, sub.dated; - - CALL item_getAtp(vDate); - CALL vn2008.item_travel(vWarehouseFk, vDate); - UPDATE vn2008.article_inventory ai - JOIN ( - SELECT it.itemFk, - SUM(it.quantity) quantity, - im.quantity minQuantity - FROM tmp.itemCalc it - JOIN tmp.itemAtp im ON im.itemFk = it.itemFk - JOIN item i ON i.id = it.itemFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN vn2008.item_travel t ON t.wh = o.warehouseFk - WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, - t.landing, - vDateToTomorrow) - GROUP BY it.itemFk - ) sub ON sub.itemFk = ai.article_id - SET ai.avalaible = IF(sub.minQuantity > 0, - ai.avalaible, - ai.avalaible + sub.minQuantity), - ai.sd = ai.inventory + sub.quantity; - - DROP TEMPORARY TABLE - vn2008.item_travel, - tmp.itemCalc, - tmp.itemAtp; +proc: BEGIN + DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; + DECLARE vDateFrom DATE DEFAULT vDate; + DECLARE vDateTo DATETIME; + DECLARE vDateToTomorrow DATETIME; + DECLARE vDefaultDayRange INT; + + IF vDate < util.VN_CURDATE() THEN + LEAVE proc; + END IF; + + IF vDate = util.VN_CURDATE() THEN + SELECT inventoried INTO vDateFrom + FROM config; + END IF; + + SELECT defaultDayRange INTO vDefaultDayRange + FROM comparativeConfig; + + SET vDateTo = vDate + INTERVAL IFNULL(vMaxDays, vDefaultDayRange) DAY; + SET vDateToTomorrow = vDateTo + INTERVAL 1 DAY; + + ALTER TABLE tmp.itemInventory + ADD `avalaible` INT NOT NULL, + ADD `sd` INT NOT NULL, + ADD `rest` INT NOT NULL, + ADD `expected` INT NOT NULL, + ADD `inventory` INT NOT NULL, + ADD `visible` INT NOT NULL, + ADD `life` TINYINT NOT NULL DEFAULT '0'; + + -- Calculo del inventario + UPDATE tmp.itemInventory ai + JOIN ( + SELECT itemFk Id_Article, SUM(quantity) Subtotal + FROM ( + SELECT s.itemFk, - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped BETWEEN vDateFrom AND util.dayEnd(vDate) + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + ) sub2 + GROUP BY itemFk + ) sub ON ai.id = sub.Id_Article + SET ai.inventory = sub.Subtotal, + ai.visible = sub.Subtotal, + ai.avalaible = sub.Subtotal, + ai.sd = sub.Subtotal; + + -- Cálculo del visible + UPDATE tmp.itemInventory ai + JOIN ( + SELECT itemFk Id_Article, SUM(quantity) Subtotal + FROM ( + SELECT s.itemFk, s.quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped >= vDate + AND t.shipped < vDateTomorrow + AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed = vDate + AND NOT t.isReceived + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped = vDate + AND NOT t.isReceived + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + ) sub2 + GROUP BY itemFk + ) sub ON ai.id = sub.Id_Article + SET ai.visible = ai.visible + sub.Subtotal; + + -- Calculo del disponible + CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT sub.itemFk, + vWarehouseFk warehouseFk, + sub.dated, + SUM(sub.quantity) quantity + FROM ( + SELECT s.itemFk, + DATE(t.shipped) dated, + - s.quantity quantity + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN warehouse w ON w.id = t.warehouseFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk + AND w.isComparative + UNION ALL + SELECT b.itemFk, t.landed, b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE t.landed BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, t.shipped, - b.quantity + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseOutFk + WHERE t.shipped BETWEEN vDateTomorrow AND vDateTo + AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk + AND w.isComparative + AND NOT e.isExcludedFromAvailable + AND NOT e.isRaid + ) sub + GROUP BY sub.itemFk, sub.dated; + + CALL item_getAtp(vDate); + CALL travel_upcomingArrivals(vWarehouseFk, vDate); + + UPDATE tmp.itemInventory ai + JOIN ( + SELECT it.itemFk, + SUM(it.quantity) quantity, + im.quantity minQuantity + FROM tmp.itemCalc it + JOIN tmp.itemAtp im ON im.itemFk = it.itemFk + JOIN item i ON i.id = it.itemFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN tmp.itemTravel t ON t.wh = o.warehouseFk + WHERE it.dated < IF(vMaxDays < 0 AND t.landing IS NOT NULL, + t.landing, + vDateToTomorrow) + GROUP BY it.itemFk + ) sub ON sub.itemFk = ai.id + SET ai.avalaible = IF(sub.minQuantity > 0, + ai.avalaible, + ai.avalaible + sub.minQuantity), + ai.sd = ai.inventory + sub.quantity; + + DROP TEMPORARY TABLE + tmp.itemTravel, + tmp.itemCalc, + tmp.itemAtp; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64782,20 +65767,20 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqlConnectionsSorter_kill`() BEGIN /** - * Elimina conexiones del usuario sorter con tiempo >= 30seg. Asociado al evento con el mismo nombre - */ - + * Elimina conexiones del usuario sorter con tiempo >= 30seg. Asociado al evento con el mismo nombre + */ + DECLARE vDone INT DEFAULT 0; DECLARE vProcesId INT; DECLARE vCursor CURSOR FOR - SELECT p.id + SELECT p.id FROM information_schema.processlist p - WHERE USER = 'sorter' + WHERE USER = 'sorter' AND TIME >= 30; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + OPEN vCursor; l: LOOP @@ -64832,7 +65817,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqlPreparedCount_check`() BEGIN DECLARE vPreparedCount INTEGER; - SELECT VARIABLE_VALUE INTO vPreparedCount + SELECT VARIABLE_VALUE INTO vPreparedCount FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME LIKE '%prepared_stmt_count%'; @@ -64840,7 +65825,7 @@ BEGIN CALL `vn`.`mail_insert`('cau@verdnatura.es', NULL, 'Problemas BBDD prepared_stmt_count', - CONCAT('Existen problemas con el servicio de Logiflora, prepared_stmt_count con valor: ', + CONCAT('Existen problemas con el servicio de Logiflora, prepared_stmt_count con valor: ', vPreparedCount, ', está próximo a exceder su límite. \r\n Hay que reiniciar el servicio LF.VMP.Service del servidor a3.') ); @@ -64867,37 +65852,37 @@ BEGIN DECLARE newShelving VARCHAR(3); DECLARE vCode VARCHAR(3); - + SELECT MAX(code) INTO vCode FROM vn.shelving WHERE isPrinted = FALSE; - + SET @a1 := ASCII(MID(vCode,1,1)); SET @a2 := ASCII(MID(vCode,2,1)); SET @a3 := ASCII(MID(vCode,3,1)) + 1; - + IF @a3 > 90 THEN - + SET @a3 = 65; SET @a2 = @a2 + 1; - + IF @a2 > 90 THEN - + SET @a2 = 65; SET @a1 = @a1 + 1; - + IF @a1 > 90 THEN - + SET @a1 = 65; - + END IF; - + END IF; - + END IF; SET newShelving = CHAR(@a1,@a2,@a3 USING utf8); - + INSERT INTO vn.shelving(code) VALUES(newShelving); END ;; @@ -64926,18 +65911,18 @@ BEGIN * @param descripcion Texto de la observacion */ DECLARE vTableName VARCHAR(45); - + SET vTableName = CONCAT(vTableCode,'Observation'); - + IF ISNULL(vTableName) THEN CALL util.throw('CODE_NOT_FOUND'); END IF; - + SET @qryLog := CONCAT( 'INSERT INTO ', vTableName, ' (originFk, userFk, description)', ' VALUES (', vOriginFk, ', ', account.myUser_getId(), ', "', vDescription, '")' ); - + PREPARE stmt FROM @qryLog; EXECUTE stmt; DEALLOCATE PREPARE stmt; @@ -64967,15 +65952,15 @@ BEGIN DECLARE vDeliveryMethod INT; DECLARE vClient INT; - + SELECT deliveryMethodFk INTO vDeliveryMethod - FROM vn.agencyMode + FROM vn.agencyMode WHERE id = vAgencyMode; - + SELECT clientFk INTO vClient FROM vn.address WHERE id = vAddress; - + INSERT INTO hedera.order(date_send,customer_id,delivery_method_id,agency_id,address_id,source_app) VALUES( vLanded,vClient ,vDeliveryMethod,vAgencyMode ,vAddress ,vSourceApp); @@ -65001,7 +65986,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `orderDelete`(IN vId INT) BEGIN DELETE FROM hedera.`order` where id = vId; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65028,7 +66013,7 @@ BEGIN DECLARE vOrderId INT; CALL vn.orderCreate(vLanded,vAgencyMode,vAddress,vSourceApp,vOrderId); SELECT vOrderId; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65048,7 +66033,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `orderListVolume`(IN vOrderId INT) BEGIN - SELECT + SELECT o.id, o.itemFk, i.description, @@ -65074,7 +66059,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `packageInvoicing`( +CREATE DEFINER=`root`@`localhost` PROCEDURE `packageInvoicing`( IN vClient INT, IN vDate DATE, IN vCompany INT, @@ -65093,20 +66078,20 @@ BEGIN SET vGraceDays = IF(vIsAllInvoiceable ,0, 30); SET vGraceDate = TIMESTAMPADD(DAY, - vGraceDays, vDate); - - /* Clientes especiales: + + /* Clientes especiales: 3240 MADEFLOR 992 JAVIER FELIU 4 TONI VENDRELL */ - + IF vClient IN (992, 3240, 4) THEN - + SET vGraceDays = 365; - + END IF; /* Fin clientes especiales */ - + SET vDateEnd = DATE_ADD(vDate, INTERVAL 1 DAY); DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoice; @@ -65130,22 +66115,22 @@ BEGIN FROM tmp.packageToInvoice GROUP BY itemFk HAVING totalQuantity > 0; - + SELECT COUNT(*) INTO vIsInvoiceable FROM tmp.packageToInvoicePositives; IF vIsInvoiceable THEN - CALL ticket_add(vClient, + CALL ticket_add(vClient, vDateEnd, - vWarehouse, - vCompany, - NULL, - NULL, - NULL, - vDateEnd, - account.myUser_getId(), + vWarehouse, + vCompany, + NULL, + NULL, + NULL, + vDateEnd, + account.myUser_getId(), TRUE, vNewTicket); @@ -65154,44 +66139,44 @@ BEGIN packagingFk, quantity, pvp) - SELECT vNewTicket, - pti.packagingFk, - - SUM(pti.quantity) AS totalQuantity, + SELECT vNewTicket, + pti.packagingFk, + - SUM(pti.quantity) AS totalQuantity, pti.price FROM tmp.packageToInvoice pti - LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk - WHERE ptip.itemFK IS NOT NULL + LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk + WHERE ptip.itemFK IS NOT NULL OR vIsAllInvoiceable GROUP BY packagingFk HAVING totalQuantity; INSERT INTO sale( ticketFk, - itemFk, - concept, - quantity, + itemFk, + concept, + quantity, price ) - SELECT vNewTicket, - pti.itemFk, - i.name as concept, - sum(pti.quantity) as totalQuantity, + SELECT vNewTicket, + pti.itemFk, + i.name as concept, + sum(pti.quantity) as totalQuantity, pti.price FROM tmp.packageToInvoice pti JOIN item i ON i.id = pti.itemFk LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk - WHERE ptip.itemFK IS NOT NULL + WHERE ptip.itemFK IS NOT NULL OR vIsAllInvoiceable GROUP BY pti.itemFk HAVING totalQuantity; - + INSERT INTO saleComponent(saleFk, componentFk, value) SELECT id, vComponentCost, price FROM sale WHERE ticketFk = vNewTicket; - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65217,7 +66202,7 @@ BEGIN WHERE mm.valor = 1 -- Listo para imprimir AND mm.stateFk = 9 -- Encajando AND m.Id_Ticket = ticketFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65239,15 +66224,15 @@ BEGIN DECLARE valueFk INT; DECLARE encajando INT DEFAULT 9; - - SELECT valor INTO valueFk - FROM vn2008.Movimientos_mark - WHERE Id_Movimiento = saleFk + + SELECT valor INTO valueFk + FROM vn2008.Movimientos_mark + WHERE Id_Movimiento = saleFk AND stateFk = encajando; - + SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3; - - REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk) + + REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, stateFk) VALUES(saleFk,valueFk,account.myUser_getId(),encajando); @@ -65339,34 +66324,34 @@ BEGIN DECLARE vLetters VARCHAR(26) DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; DECLARE vMaxId INT; DECLARE vCode VARCHAR(8); - + SET vColumn = vFromColumn; SET vRow = vFromRow; SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - + SELECT MAX(id) INTO vMaxId FROM vn.parking; WHILE vColumn <= vToColumn DO - + WHILE vRow <= vToRow DO - + INSERT IGNORE INTO vn.parking(`column`, `row`, sectorFk, `code`, pickingOrder) VALUES (vColumn, vRow, vSectorFk, vCode, vColumn * 100 + vRow ) ON DUPLICATE KEY UPDATE `code` = vCode; - + SET vRow = vRow + 1; SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - + END WHILE; - + SET vRow = vFromRow; SET vColumn = vColumn + 1; - + SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - + END WHILE; - + SELECT * FROM vn.parking WHERE `column` BETWEEN vFromColumn AND vToColumn; END ;; @@ -65391,59 +66376,59 @@ BEGIN DECLARE vRow INT; DECLARE vCode VARCHAR(8); DECLARE i INT; - + IF vToRow < vFromRow THEN - + SET vRow = vFromRow; - + WHILE vRow >= vToRow DO - + SET i = 1; - + WHILE i <= vTrolleysByLine DO - + SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); - + INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) VALUES (vSectorFk, vCode, vPickingOrder + (i * 10)) ON DUPLICATE KEY UPDATE `code` = vCode; - + SET i = i + 1; - + END WHILE; - + SET vRow = vRow - 1; - + END WHILE; ELSE - + SET vRow = vFromRow; - + WHILE vRow <= vToRow DO - + SET i = 1; - + WHILE i <= vTrolleysByLine DO - + SET vCode = CONCAT(vLetter,'-', LPAD(vRow,2,'0'),'-', i); - + INSERT IGNORE INTO vn.parking( sectorFk, `code`, pickingOrder) VALUES (vSectorFk, vCode, vPickingOrder + (i * 10) ) ON DUPLICATE KEY UPDATE `code` = vCode; - + SET i = i + 1; - + END WHILE; - + SET vRow = vRow + 1; - + END WHILE; - - + + END IF; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65467,28 +66452,28 @@ BEGIN DECLARE vColumn INT; DECLARE vLetters VARCHAR(200); DECLARE vLettersLength INT; - + SET vColumn = vStart; SET vRow = 1; SET vLetters = 'ABCDEF'; SET vLettersLength = LENGTH(vLetters); - + WHILE vColumn <= vEnd DO - + REPLACE vn.parking(`column`, `row`, `code`, sectorFk) VALUES(vColumn, vRow, CONCAT(vColumn,MID(vLetters,vRow,1)), vSectorFk); - + SET vRow = vRow + 1; - + IF vRow > vLettersLength THEN - + SET vRow = 1; SET vColumn = vColumn + 1; - + END IF; - + END WHILE; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65507,11 +66492,11 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_setOrder`(vWarehouseFk INT) BEGIN - + /* * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor */ - + UPDATE vn.parking p JOIN ( SELECT code, @@ -65520,15 +66505,15 @@ BEGIN SELECT c.prepOrder, p.code, @orden := 0, - IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , - CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication + IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , + CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication FROM vn.parking p - JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.sector s ON s.id = p.sectorFk JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci - WHERE s.warehouseFk = vWarehouseFk) sub - ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code + WHERE s.warehouseFk = vWarehouseFk) sub + ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code SET p.pickingOrder = sub2.po; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65547,17 +66532,17 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `prepareClientList`() BEGIN - + /* * Require la tabla tmp.ticket(id,clientFk) */ - + DROP TEMPORARY TABLE IF EXISTS tmp.client; CREATE TEMPORARY TABLE tmp.client (PRIMARY KEY (id)) ENGINE = MEMORY SELECT DISTINCT clientFk id - FROM tmp.ticket; + FROM tmp.ticket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65582,7 +66567,7 @@ BEGIN ENGINE = MEMORY SELECT t.id ticketFk, t.clientFk FROM vn.ticket t - LEFT JOIN vn.ticketState ts ON ts.ticket = t.id + LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id JOIN vn.client c ON c.id = t.clientFk WHERE c.typeFk IN ('normal','handMaking','internalUse') AND ( @@ -65685,14 +66670,14 @@ BEGIN /** * Comprueba si la impresora pertenece al sector * - * @param vLabelerFk id de la impresora + * @param vLabelerFk id de la impresora * @param vSector sector a comprobar */ DECLARE isPrinterInNewSector BOOL; IF vLabelerFk IS NOT NULL THEN SELECT COUNT(sectorFK) INTO isPrinterInNewSector - FROM vn.printer p + FROM vn.printer p WHERE id = vLabelerFk AND sectorFk = vSector; IF !isPrinterInNewSector THEN @@ -65716,7 +66701,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `productionControl`( - vWarehouseFk INT, + vWarehouseFk INT, vScopeDays INT ) proc: BEGIN @@ -65806,9 +66791,9 @@ proc: BEGIN JOIN agencyMode am ON am.id = t.agencyModeFk JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk JOIN agency ag ON ag.id = am.agencyFk - LEFT JOIN ticketState tls ON tls.ticket = tt.ticketFk + LEFT JOIN ticketState tls ON tls.ticketFk = tt.ticketFk LEFT JOIN ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk - LEFT JOIN worker w ON w.id = tls.worker + LEFT JOIN worker w ON w.id = tls.userFk LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk LEFT JOIN `zone` z ON z.id = t.zoneFk LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk @@ -65817,7 +66802,7 @@ proc: BEGIN LEFT JOIN parking pk ON pk.id = tp.parkingFk WHERE t.warehouseFk = vWarehouseFk AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); - + UPDATE tmp.productionBuffer pb JOIN ( SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking @@ -65825,12 +66810,12 @@ proc: BEGIN JOIN sale s ON s.ticketFk = pb.ticketFk JOIN saleGroupDetail sgd ON sgd.saleFk = s.id JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - JOIN parking p ON p.id = sg.parkingFk + JOIN parking p ON p.id = sg.parkingFk GROUP BY pb.ticketFk ) t ON t.ticketFk = pb.ticketFk SET pb.previaParking = t.previaParking; - -- Problemas por ticket + -- Problemas por ticket ALTER TABLE tmp.productionBuffer CHANGE COLUMN `problem` `problem` VARCHAR(255), ADD COLUMN `collectionH` INT, @@ -65923,12 +66908,13 @@ proc: BEGIN ENGINE = MEMORY SELECT ish.itemFk, p.sectorFk, - sc.isPreviousPrepared, + st.description = 'previousPrepared' isPreviousPrepared, sc.itemPackingTypeFk FROM itemShelving ish JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON p.id = sh.parkingFk JOIN sector sc ON sc.id = p.sectorFk + JOIN sectorType st ON st.id = sc.typeFk WHERE p.sectorFk AND ish.visible GROUP BY ish.itemFk, p.sectorFk; @@ -66102,8 +67088,8 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE itemPickerErrors -- Errores de los sacadores, derivadores de los revisadores ENGINE = MEMORY - SELECT COUNT(c.ticketFk) errors, - tt.workerFk + SELECT COUNT(c.ticketFk) errors, + tt.userFk FROM claimDevelopment cd JOIN claim c ON cd.claimFk = c.id JOIN ticket t ON c.ticketFk = t.id @@ -66113,10 +67099,10 @@ BEGIN WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.code = 'chk' AND s.code = 'ON_PREPARATION' - GROUP BY workerFk; + GROUP BY tt.userFk; UPDATE productionError ep - JOIN itemPickerErrors ipe ON ipe.workerFk = ep.userFk + JOIN itemPickerErrors ipe ON ipe.userFk = ep.userFk SET ep.error = ep.error + ipe.errors WHERE vDatedFrom = ep.dated AND ep.rol = 'Sacadores'; @@ -66224,23 +67210,23 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `productionSectorList`(vSectorFk INT) BEGIN /** - * Devuelve el listado de vn.sale que se puede preparar en previa para ese sector + * Devuelve el listado de sale que se puede preparar en previa para ese sector * - * @param vSectorFk Identificador de vn.sector + * @param vSectorFk Identificador de sector */ DECLARE vWarehouseFk INT; SELECT warehouseFk INTO vWarehouseFk - FROM vn.sector + FROM sector WHERE id = vSectorFk; DROP TEMPORARY TABLE IF EXISTS tmp.whiteTicket; CREATE TEMPORARY TABLE tmp.whiteTicket (ticketFk INT PRIMARY KEY) SELECT s.ticketFk , count(*) AS saleNum, sum(ISNULL(i.itemPackingTypeFk)) iptNull - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticket t ON t.id = s.ticketFk + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, util.VN_CURDATE()) GROUP BY s.ticketFk HAVING saleNum = iptNull; @@ -66249,15 +67235,15 @@ BEGIN CREATE TEMPORARY TABLE tmp.sectorTypeTicket (ticketFk INT PRIMARY KEY) SELECT s.ticketFk , sum(i.itemPackingTypeFk <=> sc.itemPackingTypeFk) iptSector - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.sector sc ON sc.id = vSectorFk + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + JOIN sector sc ON sc.id = vSectorFk WHERE t.shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, util.VN_CURDATE()) GROUP BY s.ticketFk HAVING iptSector; - CALL vn.productionControl(vWarehouseFk, 0); + CALL productionControl(vWarehouseFk, 0); SELECT 0,999999,0 INTO @sameTicket, @ticket, @litrosTicket; @@ -66296,19 +67282,19 @@ BEGIN IF (MINUTE(isa.shipped),MINUTE(isa.shipped), MINUTE(isa.`hour`)) Minuto, i.subName, CAST(isa.physicalVolume * 1000 AS DECIMAL(10,0)) as Litros - FROM vn.itemShelvingAvailable isa - JOIN vn.item i ON i.id = isa.itemFk - JOIN vn.sector s ON s.id = isa.sectorFk AND s.warehouseFk = isa.warehouseFk - JOIN vn.ticket t ON t.id = isa.ticketFk + FROM itemShelvingAvailable isa + JOIN item i ON i.id = isa.itemFk + JOIN sector s ON s.id = isa.sectorFk AND s.warehouseFk = isa.warehouseFk + JOIN sectorType st ON st.id = s.typeFk + JOIN ticket t ON t.id = isa.ticketFk LEFT JOIN tmp.whiteTicket wt ON wt.ticketFk = isa.ticketFk LEFT JOIN tmp.sectorTypeTicket stt ON stt.ticketFk = isa.ticketFk - LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = isa.saleFk - JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = isa.saleFk + JOIN client c ON c.id = t.clientFk JOIN tmp.productionBuffer pb ON pb.ticketFk = t.id - JOIN vn.packagingConfig pc - WHERE IF(s.isPreviousPreparedByPacking, + JOIN packagingConfig pc + WHERE IF(st.description = 'previousByPacking', i.`size` > pc.previousPreparationMinimumSize - AND isa.packing > 1 AND (MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 ), TRUE) AND sgd.saleFk IS NULL @@ -66363,7 +67349,7 @@ BEGIN `yearMonth` INT ) ENGINE = MEMORY; - + WHILE vDated <= vEnded DO INSERT INTO tmp.rangeDate SET `dated` = vDated, @@ -66373,7 +67359,7 @@ BEGIN `day` = DAY(vDated), `week` = WEEK(vDated, 1), `yearMonth` = YEAR(vDated) * 100 + MONTH(vDated); - + SET vDated = DATE_ADD(vDated, INTERVAL 1 DAY); END WHILE; END ;; @@ -66462,7 +67448,7 @@ BEGIN CALL cache.available_refresh(vCalc, FALSE, vWarehouseFk, vDate); DROP TEMPORARY TABLE IF EXISTS tmp.recipeCook; - + CREATE TEMPORARY TABLE tmp.recipeCook SELECT *, @counter := IF(@element = element COLLATE utf8_general_ci , @counter + 1, 1) as counter, @@ -66480,22 +67466,22 @@ BEGIN IFNULL((i.inkFk = r.inkFk ) ,0) + IFNULL((i.size = r.size) ,0) + IFNULL((i.name LIKE CONCAT('%',r.name,'%')) ,0) - + IFNULL((i.longName LIKE CONCAT('%',r.longName,'%')),0) + + IFNULL((i.longName LIKE CONCAT('%',r.longName,'%')),0) + IFNULL((i.typeFk = r.typeFk),0) as matches, i.typeFk, rl.previousSelected - FROM vn.recipe r + FROM vn.recipe r JOIN vn.item i ON (IFNULL(i.name LIKE CONCAT('%',r.name,'%'), 0) OR IFNULL(i.longName LIKE CONCAT('%',r.longName,'%'),0)) OR i.typeFk <=> r.typeFk JOIN cache.available a ON a.item_id = i.id AND a.calc_id = vCalc LEFT JOIN (SELECT recipe_ItemFk, element as log_element, selected_ItemFk, count(*) as previousSelected FROM vn.recipe_log - GROUP BY recipe_ItemFk, element, selected_ItemFk) rl ON rl.recipe_ItemFk = r.itemFk + GROUP BY recipe_ItemFk, element, selected_ItemFk) rl ON rl.recipe_ItemFk = r.itemFk AND rl.log_element = r.element AND rl.selected_ItemFk = i.id WHERE r.itemFk = vItemFk - AND a.available > vBunchesQuantity * r.quantity + AND a.available > vBunchesQuantity * r.quantity UNION ALL SELECT 100 itemFk, CONCAT('? ',r.element,' ',IFNULL(r.size,''),' ',IFNULL(r.inkFk,'')) as longName, @@ -66512,15 +67498,15 @@ BEGIN WHERE r.itemFk = vItemFk GROUP BY r.element ) sub - + ORDER BY element, matches DESC, previousSelected DESC; - - SELECT * + + SELECT * FROM tmp.recipeCook WHERE counter < 6 - OR itemFk = 100 + OR itemFk = 100 ; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -66545,79 +67531,30 @@ BEGIN DECLARE vShipped DATE; DECLARE vEntryFk INT; DECLARE vTravelFk INT; - + CALL cache.last_buy_refresh(FALSE); - - SELECT warehouseFk, shipped + + SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped - FROM vn.ticket + FROM vn.ticket WHERE id = vTicketFk; UPDATE vn.ticket t JOIN vn.item i ON i.id = vItemFk SET t.nickname = CONCAT(vQuantity,' ',i.longName) WHERE t.id = vTicketFk; - + SELECT b.buyingValue INTO vLastCost FROM vn.buy b JOIN cache.last_buy lb ON lb.buy_id = b.id WHERE lb.item_id = vItemFk ORDER BY (lb.warehouse_id = vWarehouseFk) DESC LIMIT 1; - + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) SELECT vTicketFk, 98, - vQuantity, i.longName, vLastCost FROM vn.item i WHERE i.id = vItemFk; - /* - SELECT tr.id INTO vTravelFk - FROM vn.travel tr - JOIN vn.warehouse w ON w.id = tr.warehouseOutFk - WHERE tr.warehouseInFk = vWarehouseFk - AND tr.landed = vShipped - AND w.name = 'Confeccion'; - - IF IFNULL(vTravelFk,0) = 0 THEN - - INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyFk) - SELECT vShipped, vShipped, vWarehouseFk, w.id, am.id - FROM vn.warehouse w - JOIN vn.agencyMode am - WHERE w.name = 'Confeccion' - AND am.name = 'DIRECTO PROVEEDOR'; - - SET vTravelFk = LAST_INSERT_ID(); - - END IF; - - SELECT e.id INTO vEntryFk - FROM vn.entry e - JOIN vn.supplier s ON s.id = supplierFk - WHERE e.travelFk = vTravelFk - AND s.name = 'Confeccion Natural' - AND e.isRaid = FALSE; - - IF IFNULL(vEntryFk,0) = 0 THEN - - INSERT INTO vn.entry(supplierFk, evaNotes, travelFk, companyFk) - SELECT s.id, t.nickname, vTravelFk, c.id - FROM vn.supplier s - JOIN vn.ticket t ON t.id = vTicketFk - JOIN vn.company c ON c.code = 'VNL' - WHERE s.name = 'Confeccion Natural'; - - SET vEntryFk = LAST_INSERT_ID(); - - END IF; - - INSERT INTO vn.buy(entryFk, itemFk, quantity, buyingValue, packageFk, packing, grouping) - SELECT vEntryFk, b.itemFk, vQuantity, b.buyingValue, b.packageFk, b.packing, b.grouping - FROM cache.last_buy lb - JOIN vn.buy b ON b.id = lb.buy_id - WHERE lb.item_id = vItemFk - ORDER BY (lb.warehouse_id = vWarehouseFk) DESC - LIMIT 1; -*/ END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -66711,7 +67648,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `report_print`( ) BEGIN /** - * Inserts in the print queue the report to be printed and the necessary parameters for this + * Inserts in the print queue the report to be printed and the necessary parameters for this * one taking into account the paper size of both the printer and the report. * * @param vReportName the report to be printed. @@ -66754,11 +67691,11 @@ BEGIN END IF; IF vReportFk IS NULL THEN - CALL util.throw('reportNotExists'); + CALL util.throw('reportNotExists'); END IF; IF vReportSize <> vPrinteSize THEN - CALL util.throw('incorrectSize'); + CALL util.throw('incorrectSize'); END IF; START TRANSACTION; @@ -66767,7 +67704,7 @@ BEGIN priorityFk = vPriorityFk, reportFk = vReportFk, workerFk = vUserFk; - + SET vPrintQueueFk = LAST_INSERT_ID(); WHILE vI < vLength DO @@ -66800,16 +67737,16 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `riskAllClients`(maxRiskDate DATE) BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; CREATE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY SELECT id Id_Cliente, null grade FROM vn.client; - + CALL vn2008.risk_vs_client_list(maxRiskDate); - - SELECT + + SELECT c.RazonSocial, c.Id_Cliente, c.Credito, @@ -66821,7 +67758,7 @@ BEGIN JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente GROUP BY c.Id_cliente; - + DROP TEMPORARY TABLE IF EXISTS tmp.risk; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END ;; @@ -66880,25 +67817,25 @@ BEGIN DECLARE vM3 INT; DECLARE vKg INT; DECLARE vMatricula varchar(50); - + SELECT sum(packages) as bultos INTO vPackages - FROM vn.ticket t + FROM vn.ticket t WHERE routeFk = vRouteFk; - + SELECT SUM(sv.physicalVolume), SUM(sv.physicalWeight) INTO vM3, vKg FROM vn.saleVolume sv WHERE sv.routeFk = vRouteFk; - + SELECT v.numberPlate as matricula INTO vMatricula - FROM vn.route r + FROM vn.route r JOIN vn.vehicle v ON r.vehicleFk = v.id WHERE r.id = vRouteFk; - + SELECT vRouteFk as Ruta, - vPackages as Bultos, + vPackages as Bultos, vM3 as m3, vKg as Kg, vMatricula as Matricula; @@ -66963,7 +67900,7 @@ BEGIN ) sub ON sub.routeFk = rm.routeFk SET rm.ticketFree = sub.ticketFree; - UPDATE routesMonitor rm + UPDATE routesMonitor rm JOIN( SELECT t.routeFk, COUNT(*) AS ticketPacked FROM vn.ticket t @@ -67049,11 +67986,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeSetOk`( vRouteFk INT) BEGIN - + UPDATE vn.route r SET r.isOk = 1 WHERE r.id = vRouteFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67092,15 +68029,18 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `route_calcCommission`(vSelf INT) -proc: BEGIN +CREATE DEFINER=`root`@`localhost` PROCEDURE `route_calcCommission`( + vSelf INT +) +BEGIN /** - * Calcula las comisión para una ruta y guarda los valores en la tabla routeCommission + * Calcula las comisión para una ruta y guarda los valores + * en la tabla vn.routeCommission. * - * @param vSelf id de ruta + * @param vSelf Id de ruta */ - DECLARE vIsUpdatable BOOL; - DECLARE vIsFreelance BOOL; + DECLARE vIsUpdatable, vIsFreelance BOOL DEFAULT 0; + DECLARE vAgencyModePricePercentage DOUBLE; SELECT r.created >= rc.cutoffDated INTO vIsUpdatable FROM route r @@ -67116,6 +68056,13 @@ proc: BEGIN JOIN worker w ON w.id = r.workerFk WHERE r.id = vSelf; + SELECT ampp.percentage INTO vAgencyModePricePercentage + FROM route r + JOIN agencyMode am ON am.id = r.agencyModeFk + JOIN agencyModePricePercentage ampp ON ampp.agencyModeFk = am.id + WHERE r.id = vSelf; + + -- Falta calcular el precio, a la espera de saber el/los campo/s exacto/s al que aplicarlo/s IF vIsFreelance THEN INSERT INTO routeCommission ( routeFk, @@ -67125,13 +68072,17 @@ proc: BEGIN cat5m3 ) SELECT vSelf, - r.commissionWorkCenterFk, - rc.freelanceM3 * IF( - IFNULL(r.m3, 0) >= rc.freelanceMinM3, + r.commissionWorkCenterFk, + IF(vAgencyModePricePercentage IS NOT NULL, + vAgencyModePricePercentage / 100, + rc.freelanceM3 + ) * + IF(IFNULL(r.m3, 0) >= rc.freelanceMinM3, IFNULL(r.m3, 0), - 0), - rc.distributionCat4M3 * IFNULL(r.m3, 0), - rc.distributionCat5M3 * IFNULL(r.m3, 0) + 0 + ), + rc.distributionCat4M3 * IFNULL(r.m3, 0), + rc.distributionCat5M3 * IFNULL(r.m3, 0) FROM route r JOIN vehicle v ON v.id = r.vehicleFk JOIN routeConfig rc @@ -67150,15 +68101,15 @@ proc: BEGIN cat5m3 ) SELECT vSelf, - r.commissionWorkCenterFk, - (r.kmEnd - r.kmStart) * - IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), - IFNULL(r.m3, 0) * - IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), - (r.kmEnd - r.kmStart) * rc.kmYearly, - IFNULL(r.m3, 0) * rc.m3Yearly, - rc.distributionCat4M3 * IFNULL(r.m3, 0), - rc.distributionCat5M3 * IFNULL(r.m3, 0) + r.commissionWorkCenterFk, + (r.kmEnd - r.kmStart) * + IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), + IFNULL(r.m3, 0) * + IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), + (r.kmEnd - r.kmStart) * rc.kmYearly, + IFNULL(r.m3, 0) * rc.m3Yearly, + rc.distributionCat4M3 * IFNULL(r.m3, 0), + rc.distributionCat5M3 * IFNULL(r.m3, 0) FROM route r JOIN vehicle v ON v.id = r.vehicleFk JOIN routeConfig rc @@ -67177,40 +68128,6 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -/*!50003 DROP PROCEDURE IF EXISTS `route_checkDeliveryMethod` */; -/*!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 */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `route_checkDeliveryMethod`(vSelf INT) -BEGIN -/** -* Comprueba si el deliveryMethod del agencyMode de la ruta es reparto -* -* @param vSelf Id de ruta -*/ - DECLARE vDeliveryMethod VARCHAR(45); - - SELECT dm.code INTO vDeliveryMethod - FROM route r - JOIN agencyMode am ON am.id = r.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE r.id = vSelf; - - IF vDeliveryMethod <> 'DELIVERY' THEN - CALL util.throw('Route tickets via delivery only'); - 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_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `route_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67224,7 +68141,7 @@ proc: BEGIN /** * Recalculates modified route. */ - + DECLARE vDone BOOL; DECLARE vRouteFk INT; @@ -67233,7 +68150,7 @@ proc: BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN DO RELEASE_LOCK('vn.route_doRecalc'); @@ -67311,13 +68228,13 @@ SELECT t.id Id, t.cmrFk FROM ticket t JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id + JOIN address a ON t.addressFk = a.id LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk LEFT JOIN ( SELECT t.addressFk, MAX(d.ticketFk) lastTicketFk FROM ticket t JOIN delivery d ON t.id = d.ticketFk - JOIN ticket ti ON ti.routeFk = vRouteFk + JOIN ticket ti ON ti.routeFk = vRouteFk AND ti.id = t.id AND ti.clientFk = t.clientFk GROUP BY addressFk @@ -67394,27 +68311,27 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleBuy_Add`(vSaleFk INT, vBuyFk INT) BEGIN - + /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad - * + * * @param vSaleFk clave primaria de vn.sale * @param vBuyFk clave primaria de vn.buy */ - /*IF (SELECT COUNT(*) + /*IF (SELECT COUNT(*) FROM vn.sale s JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk WHERE s.id = vSaleFk AND ic.code = 'fruit') THEN */ - - IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN - + + IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN + INSERT INTO vn.saleBuy (saleFk, buyFk) VALUES(vSaleFk, vBuyFk); - + END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67438,7 +68355,7 @@ BEGIN * * @param vSectorFk Identificador de vn.sector */ - INSERT INTO vn.saleGroup(userFk, sectorFk) + INSERT INTO vn.saleGroup(userFk, sectorFk) VALUES (account.myUser_getId(), vSectorFk); SELECT LAST_INSERT_ID(); @@ -67572,41 +68489,41 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleSplit`(vSaleFk INT, vQuantity INT) BEGIN - + DECLARE vNewSaleFk INT; - - INSERT INTO vn.sale(itemFk, - concept, - price, - discount, - quantity, - ticketFk, + + INSERT INTO vn.sale(itemFk, + concept, + price, + discount, + quantity, + ticketFk, isPriceFixed) - SELECT s.itemFk, - i.longName, - s.price, - s.discount, + SELECT s.itemFk, + i.longName, + s.price, + s.discount, vQuantity, - s.ticketFk, - s.isPriceFixed + s.ticketFk, + s.isPriceFixed FROM vn.sale s JOIN vn.item i ON i.id = s.itemFk WHERE s.id = vSaleFk; - + UPDATE vn.sale s JOIN vn.item i ON i.id = s.itemFk SET s.quantity = s.quantity - vQuantity, s.concept = i.longName WHERE s.id = vSaleFk; - + SELECT LAST_INSERT_ID() INTO vNewSaleFk; - - INSERT INTO vn.saleComponent( saleFk, - componentFk, + + INSERT INTO vn.saleComponent( saleFk, + componentFk, value) - SELECT vNewSaleFk, - componentFk, + SELECT vNewSaleFk, + componentFk, value - FROM vn.saleComponent + FROM vn.saleComponent WHERE saleFk = vSaleFk; END ;; @@ -67626,41 +68543,41 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sales_merge`(vTicketFk INT) -BEGIN - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve - SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE s.ticketFk = vTicketFk - AND it.isMergeable - GROUP BY s.itemFk, s.price, s.discount; - - START TRANSACTION; - - UPDATE sale s - JOIN tSalesToPreserve stp ON stp.id = s.id - SET quantity = newQuantity - WHERE s.ticketFk = vTicketFk; - - DELETE s.* - FROM sale s - LEFT JOIN tSalesToPreserve stp ON stp.id = s.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE s.ticketFk = vTicketFk - AND stp.id IS NULL - AND it.isMergeable; - - COMMIT; - - DROP TEMPORARY TABLE tSalesToPreserve; +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve + SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE s.ticketFk = vTicketFk + AND it.isMergeable + GROUP BY s.itemFk, s.price, s.discount; + + START TRANSACTION; + + UPDATE sale s + JOIN tSalesToPreserve stp ON stp.id = s.id + SET quantity = newQuantity + WHERE s.ticketFk = vTicketFk; + + DELETE s.* + FROM sale s + LEFT JOIN tSalesToPreserve stp ON stp.id = s.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE s.ticketFk = vTicketFk + AND stp.id IS NULL + AND it.isMergeable; + + COMMIT; + + DROP TEMPORARY TABLE tSalesToPreserve; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67695,17 +68612,17 @@ BEGIN OPEN cCur; myLoop: LOOP - + SET vDone = FALSE; - + FETCH cCur INTO vTicketFk; IF vDone THEN LEAVE myLoop; END IF; - + CALL vn.sales_merge(vTicketFk); - + END LOOP; CLOSE cCur; @@ -67836,9 +68753,9 @@ BEGIN DELETE st.* FROM vn.saleTracking st JOIN vn.state s ON s.id = st.stateFk - WHERE st.saleFk = vSaleFk + WHERE st.saleFk = vSaleFk AND s.code = vState COLLATE utf8_unicode_ci; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67855,12 +68772,12 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_new`( - vSaleFK INT, - vIsChecked BOOLEAN, - vOriginalQuantity INT, - vWorkerFk INT, - vAction VARCHAR(50), +CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_new`( + vSaleFK INT, + vIsChecked BOOLEAN, + vOriginalQuantity INT, + vWorkerFk INT, + vAction VARCHAR(50), vState VARCHAR(50), vIsScanned BOOLEAN) BEGIN @@ -67876,12 +68793,12 @@ BEGIN * @param vIsScanned Identificador si se ha escaneado automáticamente o manual */ - REPLACE vn.saleTracking(saleFk, - isChecked, - originalQuantity, - workerFk, + REPLACE vn.saleTracking(saleFk, + isChecked, + originalQuantity, + workerFk, stateFk, - isScanned) + isScanned) SELECT vSaleFK, vIsChecked, vOriginalQuantity, @@ -67908,27 +68825,27 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_updateIsChecked`(vSaleFK INT, vIsChecked BOOL, vIsScanned BOOL) BEGIN - + /** * Actualiza el estado del campo vn.saleTracking.isChecked y elimina las lineas de vn.itemShelving * si procede, en el caso de las preparaciones previas, por usuario - * + * * @param vSaleFk Identificador de vn.sale * @param vIsChecked Estado del registro */ - + UPDATE vn.saleTracking st JOIN vn.state s ON s.id = st.stateFk AND s.code = 'PREVIOUS_PREPARATION' SET st.isChecked = vIsChecked, st.isScanned = vIsScanned WHERE st.saleFk = vSaleFK AND st.workerFk = account.myUser_getId(); - + IF vIsChecked = FALSE THEN - - DELETE FROM vn.itemShelvingSale + + DELETE FROM vn.itemShelvingSale WHERE saleFk = vSaleFK; - + END IF; END ;; @@ -67954,14 +68871,14 @@ proc: BEGIN * * @param vSelf Id de la venta * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - */ + */ CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales SELECT s.id FROM sale s WHERE s.id = vSelf; - + CALL sale_recalcComponent(vOption); - + DROP TEMPORARY TABLE tmp.recalculateSales; END ;; DELIMITER ; @@ -68008,7 +68925,7 @@ BEGIN GROUP BY s.id; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; + SET v_done = TRUE; DROP TEMPORARY TABLE IF EXISTS tmp.coste; @@ -68016,7 +68933,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.coste (PRIMARY KEY (id)) ENGINE = MEMORY SELECT s.id - FROM sale s + FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemType tp ON tp.id = i.typeFk JOIN itemCategory ic ON ic.id = tp.categoryFk @@ -68035,17 +68952,17 @@ BEGIN IF v_done THEN LEAVE l; END IF; - + SELECT ticketFk, concept INTO vTicketFk, vConcept FROM sale WHERE id = vSaleFk; - + CALL sale_calculateComponent(vSaleFk, 1); END LOOP; CLOSE vCur; - DROP TEMPORARY TABLE tmp.coste; + DROP TEMPORARY TABLE tmp.coste; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68054,6 +68971,75 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `sale_getBoxPickingList` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getBoxPickingList`(vSectorFk INT, vDated DATE) +BEGIN +/** +* Returns a suitable boxPicking sales list +* +* @param vSectorFk Identifier for vn.sector table +* @param vDated Date for vn.tickets.shipping +* +* @return tmp.sale +*/ + DECLARE vWarehouseFk INT; + + SELECT warehouseFk INTO vWarehouseFk + FROM sector + WHERE id = vSectorFk; + + CALL productionControl(vWarehouseFk, 0); + + SELECT + s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + s.quantity / i.packingOut stickers, + i.packingOut + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemShelving ish ON ish.itemFk = s.itemFk + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk + JOIN agencyMode am ON am.id = pb.agencyModeFk + LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = p.sectorFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk + WHERE s.quantity MOD i.packingOut = 0 + AND pb.problem = "" + AND s.quantity > 0 + AND sgd.saleFk IS NULL + AND p.sectorFk = vSectorFk + AND ts.isPreviousPreparable + AND iss.visible >= s.quantity + AND ((rm.bufferFk AND rm.isPickingAllowed) + OR am.name = 'REC_ALGEMESI') + AND pb.shipped = vDated + GROUP BY s.id + ORDER BY etd; + + DROP TEMPORARY TABLE tmp.productionBuffer; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_getFromTicketOrCollection` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68131,7 +69117,7 @@ DECLARE vIsCollection BOOL; TRIM(CONCAT(LPAD(s.concept,30,' '), ' ', RPAD(IFNULL(i.size,''),5,' '))) line1, '' cel1, - TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, + TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1), CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)), CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2, @@ -68148,12 +69134,12 @@ DECLARE vIsCollection BOOL; JOIN sale s ON s.ticketFk = t.id JOIN ticket tt ON tt.id = t.id LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN buy b ON b.id = lb.buy_id JOIN item i ON i.id = s.itemFk LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id LEFT JOIN collection c ON c.id = tc.collectionFk - LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity - FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity + LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity + FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity FROM tmp.ticket2 t JOIN sale s ON s.ticketFk = t.id JOIN saleTracking st ON st.saleFk = s.id @@ -68165,7 +69151,7 @@ DECLARE vIsCollection BOOL; LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN parking p ON p.id = sg.parkingFk LEFT JOIN saleMistake sm ON sm.saleFk = s.id @@ -68217,8 +69203,8 @@ BEGIN DELETE tt.* FROM tmp.sale_getProblems tt JOIN ticketObservation tto ON tto.ticketFk = tt.ticketFk - JOIN observationType ot ON ot.id = tto.observationTypeFk - WHERE ot.code = 'administrative' + JOIN observationType ot ON ot.id = tto.observationTypeFk + WHERE ot.code = 'administrative' AND tto.description = 'Miriam'; CREATE OR REPLACE TEMPORARY TABLE tmp.sale_problems ( @@ -68250,7 +69236,7 @@ BEGIN -- Too Little INSERT INTO tmp.sale_problems(ticketFk, isTooLittle) - SELECT tp.ticketFk, TRUE + SELECT tp.ticketFk, TRUE FROM tmp.sale_getProblems tp JOIN ticket t ON t.id = tp.ticketFk JOIN ( @@ -68327,6 +69313,19 @@ BEGIN WHERE tr.isOK IS NULL ON DUPLICATE KEY UPDATE hasTicketRequest = TRUE; + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk; + -- Disponible, Faltas, Inventario y Retrasos OPEN vCursor; l: LOOP @@ -68339,25 +69338,28 @@ BEGIN -- Disponible: no va a haber suficiente producto para preparar todos los pedidos CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate); - - -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida + + -- Faltas: visible, disponible y ubicado son menores que la cantidad vendida CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, - LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem, + SELECT tl.ticketFk, + LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem, s.id AS saleFk FROM tmp.ticket_list tl JOIN ticket t ON t.id = tl.ticketFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) < s.quantity AND IFNULL(av.available ,0) < s.quantity AND IFNULL(issw.visible, 0) < s.quantity @@ -68370,20 +69372,24 @@ BEGIN AND t.warehouseFk = vWarehouseFk GROUP BY tl.ticketFk) sub ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk; - + -- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, LEFT(GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' '),250) problem, s.id AS saleFk + SELECT tl.ticketFk, + LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem, + s.id saleFk FROM tmp.ticket_list tl JOIN ticket t ON t.id = tl.ticketFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity AND s.quantity > 0 @@ -68397,21 +69403,26 @@ BEGIN GROUP BY tl.ticketFk ) sub ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; - + -- Retraso: Disponible suficiente, pero no visible ni ubicado INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, LEFT(GROUP_CONCAT('R: ',i.id, ' ', i.longName, ' '),250) problem, s.id AS saleFk + SELECT tl.ticketFk, + LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem, + s.id saleFk FROM tmp.ticket_list tl JOIN ticket t ON t.id = tl.ticketFk JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible, 0) < s.quantity AND IFNULL(av.available, 0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity @@ -68432,12 +69443,12 @@ BEGIN INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk) SELECT ticketFk, problem, saleFk FROM ( - SELECT tl.ticketFk, + SELECT tl.ticketFk, s.id saleFk , - LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,''), ' '), 250) problem, + LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,''), ' '), 250) problem, MOD(s.quantity, b.`grouping`) hasRounding FROM tmp.ticket_list tl - JOIN ticket t ON t.id = tl.ticketFk + JOIN ticket t ON t.id = tl.ticketFk AND t.warehouseFk = vWarehouseFk JOIN sale s ON s.ticketFk = tl.ticketFk JOIN item i ON i.id = s.itemFk @@ -68445,11 +69456,11 @@ BEGIN JOIN buy b ON b.id = bu.buyFk GROUP BY tl.ticketFk HAVING hasRounding - ) sub + ) sub ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk; END LOOP; CLOSE vCursor; - + INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked) SELECT DISTINCT tl.ticketFk, FALSE FROM tmp.ticket_list tl @@ -68459,7 +69470,8 @@ BEGIN DROP TEMPORARY TABLE tmp.clientGetDebt, - tmp.ticket_list; + tmp.ticket_list, + tItemShelvingStock_byWarehouse; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68479,16 +69491,16 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getProblemsByTicket`(IN vTicketFk INT, IN vIsTodayRelative TINYINT(1)) BEGIN /** - * Calcula los problemas de cada venta + * Calcula los problemas de cada venta * para un conjunto de tickets. * * @return Problems result */ DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems; - CREATE TEMPORARY TABLE tmp.sale_getProblems + CREATE TEMPORARY TABLE tmp.sale_getProblems (INDEX (ticketFk)) ENGINE = MEMORY - SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped + SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped FROM ticket t WHERE t.id = vTicketFk; @@ -68517,7 +69529,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_PriceFix`(vTicketFk INT) BEGIN - + DELETE sc.* FROM vn.saleComponent sc JOIN vn.sale s ON s.id = sc.saleFk @@ -68553,84 +69565,84 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_recalcComponent`(vOption INT) proc: BEGIN /** - * Este procedimiento recalcula los componentes de un conjunto de sales, + * Este procedimiento recalcula los componentes de un conjunto de sales, * eliminando los componentes existentes e insertandolos de nuevo * * @param vOption si no se quiere forzar llamar con NULL * @table tmp.recalculateSales (id) - */ - DECLARE vShipped DATE; + */ + DECLARE vShipped DATE; DECLARE vWarehouseFk SMALLINT; DECLARE vAgencyModeFk INT; DECLARE vAddressFk INT; DECLARE vTicketFk INT; - DECLARE vLanded DATE; + DECLARE vLanded DATE; DECLARE vIsEditable BOOLEAN; DECLARE vZoneFk INTEGER; DECLARE vDone BOOL DEFAULT FALSE; - + DECLARE vCur CURSOR FOR SELECT DISTINCT s.ticketFk FROM tmp.recalculateSales rs JOIN vn.sale s ON s.id = rs.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + OPEN vCur; l: LOOP SET vDone = FALSE; - FETCH vCur INTO vTicketFk; - + FETCH vCur INTO vTicketFk; + IF vDone THEN LEAVE l; END IF; - SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, - t.zoneFk, - t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, + SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, + t.zoneFk, + t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, t.landed - INTO vIsEditable, - vZoneFk, - vWarehouseFk, - vShipped, - vAddressFk, - vAgencyModeFk, + INTO vIsEditable, + vZoneFk, + vWarehouseFk, + vShipped, + vAddressFk, + vAgencyModeFk, vLanded FROM ticket t - LEFT JOIN ticketState ts ON t.id = ts.ticket + LEFT JOIN ticketState ts ON t.id = ts.ticketFk LEFT JOIN alertLevel al ON al.id = ts.alertLevel WHERE t.id = vTicketFk; CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - + IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); END IF; - + IF vLanded IS NULL OR vZoneFk IS NULL THEN - + UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) WHERE t.id = vTicketFk AND t.landed IS NULL; - + IF vZoneFk IS NULL THEN SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; UPDATE ticket t SET t.zoneFk = vZoneFk WHERE t.id = vTicketFk AND t.zoneFk IS NULL; END IF; - + END IF; - + DROP TEMPORARY TABLE tmp.zoneGetLanded; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + CREATE OR REPLACE TEMPORARY TABLE tmp.sale (PRIMARY KEY (saleFk)) ENGINE = MEMORY SELECT s.id saleFk, vWarehouseFk warehouseFk @@ -68638,7 +69650,7 @@ proc: BEGIN JOIN tmp.recalculateSales rs ON s.id = rs.id WHERE s.ticketFk = vTicketFk; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk FROM sale s JOIN tmp.recalculateSales rs ON s.id = rs.id @@ -68652,15 +69664,15 @@ proc: BEGIN IF vOption IS NULL THEN SET vOption = IF(vIsEditable, 1, 6); END IF; - - CALL ticketComponentUpdateSale(vOption); + + CALL ticketComponentUpdateSale(vOption); CALL catalog_componentPurge(); - + DROP TEMPORARY TABLE tmp.buyUltimate; DROP TEMPORARY TABLE tmp.sale; - + END LOOP; - CLOSE vCur; + CLOSE vCur; END ;; DELIMITER ; @@ -68669,6 +69681,155 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `sale_replaceItem` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_replaceItem`(vSaleFk INT, vNewItemFk INT, vQuantity INT) +BEGIN +/** + * Añade un nuevo articulo para sustituir a otro, y actualiza la memoria de sustituciones. + * + * @param vSaleFk id de la tabla sale + * @param vNewItemFk articulo sustituto + * @param vQuantity cantidad que se va a sustituir + */ + DECLARE vTicketFk INT; + DECLARE vItemFk INT; + DECLARE vWarehouseFk SMALLINT; + DECLARE vDate DATE; + DECLARE vGrouping INT; + DECLARE vGroupingModeFk INT; + DECLARE vPacking INT; + DECLARE vRoundQuantity INT DEFAULT 1; + DECLARE vLanded DATE; + DECLARE vAddressFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vNewPrice DECIMAL(10,2); + DECLARE vOldPrice DECIMAL(10,2); + DECLARE vOption INT DEFAULT NULL; + DECLARE vNewSaleFk INT; + DECLARE vChangePrice INT DEFAULT 1; + DECLARE vBuyerDiscount INT DEFAULT 4; + DECLARE vManaDiscount INT DEFAULT 3; + DECLARE vForceToGrouping INT DEFAULT 1; + DECLARE vForceToPacking INT DEFAULT 2; + DECLARE vFinalPrice DECIMAL(10,2); + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT s.ticketFk, + LEAST(s.quantity, vQuantity), + s.itemFk, + t.shipped, + t.warehouseFk, + t.landed, + t.addressFk, + t.agencyModeFk, + s.price + INTO vTicketFk, + vQuantity, + vItemFk, + vDate, + vWarehouseFk, + vLanded, + vAddressFk, + vAgencyModeFk, + vOldPrice + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE s.id = vSaleFk; + + CALL buyUltimate(vWarehouseFk, vDate); + + SELECT `grouping`, groupingMode, packing + INTO vGrouping,vGroupingModeFk,vPacking + FROM buy b + JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk + WHERE tmp.itemFk = vNewItemFk AND tmp.WarehouseFk = vWarehouseFk; + + IF vGroupingModeFk = vForceToPacking AND vPacking > 0 THEN + SET vRoundQuantity = vPacking; + END IF; + IF vGroupingModeFk = vForceToGrouping AND vGrouping > 0 THEN + SET vRoundQuantity = vGrouping; + END IF; + + CALL catalog_calcFromItem( + vLanded, + vAddressFk, + vAgencyModeFk, + vNewItemFk); + + SELECT price INTO vNewPrice + FROM tmp.ticketCalculateItem; + + IF vNewPrice IS NULL THEN + CALL util.throw('price retrieval failed'); + END IF; + IF vNewPrice > vOldPrice THEN + SET vFinalPrice = vOldPrice; + IF worker_isInDepartment('vt') THEN + SET vOption = vManaDiscount; + ELSE + SET vOption = vBuyerDiscount; + END IF; + ELSE + SET vFinalPrice = vNewPrice; + SET vOption = vChangePrice; + END IF; + + START TRANSACTION; + + UPDATE sale + SET quantity = quantity - vQuantity + WHERE id = vSaleFk; + + INSERT INTO vn.sale(ticketFk, + itemFk, + quantity, + concept, + price) + SELECT vTicketFk, + vNewItemFk, + CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ',i.longName), + vFinalPrice + FROM vn.item i + WHERE id = vNewItemFk; + + SELECT LAST_INSERT_ID() INTO vNewSaleFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE id = vNewSaleFk; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + + INSERT INTO itemProposal(itemFk, mateFk, counter) + VALUES(vItemFk, vNewItemFk, 1) + ON DUPLICATE KEY UPDATE counter = counter + 1; + + 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 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sectorCollectionSaleGroup_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -68681,22 +69842,22 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollectionSaleGroup_add`(vSaleGroupFk INT, vSectorCollectionFk INT) BEGIN /** - * Inserta un nuevo registro en vn.sectorCollectionSaleGroup + * Inserta un nuevo registro en vn.sectorCollectionSaleGroup * Actualiza el usuario en vn.saleGroup y reemplaza los registros de vn.saleTracking - * + * * @param vSaleGroupFk Identificador de vn.saleGroup * @param vSectorCollectionFk Identificador de vn.sectorCollection */ REPLACE sectorCollectionSaleGroup - SET sectorCollectionFk = vSectorCollectionFk, + SET sectorCollectionFk = vSectorCollectionFk, saleGroupFk = vSaleGroupFk; - + UPDATE saleGroup sg JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk - SET sg.userFk = sc.userFk + SET sg.userFk = sc.userFk WHERE sg.id = vSaleGroupFk; - + INSERT IGNORE saleTracking( saleFk, isChecked, @@ -68708,8 +69869,8 @@ BEGIN sc.userFk, s.id FROM saleGroupDetail sgd - JOIN sectorCollectionSaleGroup scsg - ON scsg.saleGroupFk = sgd.saleGroupFk + JOIN sectorCollectionSaleGroup scsg + ON scsg.saleGroupFk = sgd.saleGroupFk JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk JOIN state s ON s.code = 'PREVIOUS_PREPARATION' WHERE sgd.saleGroupFk = vSaleGroupFk; @@ -68810,30 +69971,30 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_new`(vSectorFk INT) -BEGIN -/** - * Inserta una nueva colección, si el usuario no tiene ninguna vacia. - * Esto se hace para evitar que por error se generen colecciones sin sentido. - * - * @param vSectorFk Identificador de #vn.sector - */ - DECLARE hasEmptyCollections BOOL; - DECLARE vUserFk INT; - - SET vUserFk = account.myUser_getId(); - - SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections - FROM vn.sectorCollection sc - LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - WHERE ISNULL(scsg.id) - AND sc.userFk = vUserFk - AND sc.sectorFk = vSectorFk - AND sc.created >= util.VN_CURDATE(); - - IF NOT hasEmptyCollections THEN - INSERT INTO vn.sectorCollection(userFk, sectorFk) - VALUES(vUserFk, vSectorFk); - END IF; +BEGIN +/** + * Inserta una nueva colección, si el usuario no tiene ninguna vacia. + * Esto se hace para evitar que por error se generen colecciones sin sentido. + * + * @param vSectorFk Identificador de #vn.sector + */ + DECLARE hasEmptyCollections BOOL; + DECLARE vUserFk INT; + + SET vUserFk = account.myUser_getId(); + + SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections + FROM vn.sectorCollection sc + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + WHERE ISNULL(scsg.id) + AND sc.userFk = vUserFk + AND sc.sectorFk = vSectorFk + AND sc.created >= util.VN_CURDATE(); + + IF NOT hasEmptyCollections THEN + INSERT INTO vn.sectorCollection(userFk, sectorFk) + VALUES(vUserFk, vSectorFk); + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68877,7 +70038,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.previousErrors -- Errores de previa, derivadores de los revisadores (por reclamación) ENGINE = MEMORY - SELECT tt.workerFk, COUNT(c.ticketFk) errorsByClaim + SELECT tt.userFk, COUNT(c.ticketFk) errorsByClaim FROM claimDevelopment cd JOIN claim c ON cd.claimFk = c.id JOIN ticket t ON c.ticketFk = t.id @@ -68885,7 +70046,7 @@ BEGIN JOIN ticketTracking tt ON tt.ticketFk = t.id JOIN `state` s ON s.id = tt.stateFk WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.description = 'Revisadores' AND s.code = 'OK PREVIOUS' - GROUP BY workerFk; + GROUP BY tt.userFk; DELETE FROM sectorProductivity WHERE dated = vDatedFrom @@ -68913,7 +70074,7 @@ BEGIN LEFT JOIN bs.workerProductivity wp ON wp.workerFk = w.id LEFT JOIN `state` s2 ON s2.id = wp.stateFk AND s2.code = 'OK PREVIOUS' LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = w.id - LEFT JOIN tmp.previousErrors pe ON pe.workerFk = w.id + LEFT JOIN tmp.previousErrors pe ON pe.userFk = w.id WHERE DATE(sc.created) = vDatedFrom AND wp.dated = vDatedFrom GROUP BY w.id; @@ -68969,7 +70130,7 @@ BEGIN SELECT s.warehouseFk FROM vn.sector s WHERE s.id = vSectorFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69064,10 +70225,10 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingChange`(IN `vShelvingO` VAR BEGIN UPDATE vn.itemShelving - SET shelvingFk = vShelvingD COLLATE utf8_unicode_ci - WHERE shelvingFk = vShelvingO COLLATE utf8_unicode_ci; - - + SET shelvingFk = vShelvingD COLLATE utf8_unicode_ci + WHERE shelvingFk = vShelvingO COLLATE utf8_unicode_ci; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69086,16 +70247,16 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingLog_get`(shelvingFk VARCHAR(10)) BEGIN - + /* Lista el log de un carro - * + * * @param shelvingFk matrícula del carro - * + * */ - + SELECT originFk, name, creationDate, description FROM shelvingLog sl - JOIN account.user u ON u.id = sl.userFk + JOIN account.user u ON u.id = sl.userFk WHERE sl.originFk = shelvingFk COLLATE utf8_general_ci ORDER BY creationDate DESC; @@ -69118,22 +70279,22 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingParking_get`(vShelvingFk VARCHAR(10), vWarehouseFk INT, vDayRange INT) BEGIN - -SELECT s.itemFk, + +SELECT s.itemFk, s.concept, - CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir, - CAST(IFNULL(ist.visible,0) AS DECIMAL(10,0)) as aparcado + CAST(SUM(s.quantity) AS DECIMAL(10,0)) as sinServir, + CAST(IFNULL(ist.visible,0) AS DECIMAL(10,0)) as aparcado FROM vn.sale s LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk AND ist.warehouseFk = vWarehouseFk JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk AND ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) AND iss.saleFk IS NULL AND t.warehouseFk = vWarehouseFk GROUP BY s.itemFk HAVING sinServir > aparcado; - + END ;; DELIMITER ; @@ -69178,12 +70339,12 @@ BEGIN DELETE FROM shelving WHERE length(code) > 3 AND parked < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - + DELETE FROM itemShelving WHERE visible <= 0 AND created < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); - DELETE ish.* + DELETE ish.* FROM itemShelving ish JOIN vn.shelving sh ON sh.code = ish.shelvingFk WHERE sh.parkingFk IS NULL @@ -69379,20 +70540,20 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `solunionRiskRequest`() BEGIN - + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; CREATE TEMPORARY TABLE tmp.client_list (PRIMARY KEY (Id_Cliente)) ENGINE = MEMORY - SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc + SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification WHERE dateEnd IS NULL ORDER BY ci.creationDate DESC LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; - + CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); - - SELECT + + SELECT c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo, f.Consumo consumo_anual, c.Vencimiento, ci.grade @@ -69402,7 +70563,7 @@ BEGIN JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente GROUP BY Id_cliente; - + DROP TEMPORARY TABLE IF EXISTS tmp.risk; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; END ;; @@ -69652,10 +70813,10 @@ BEGIN DECLARE vBossId INT; DECLARE vDone BOOL; DECLARE workerCur CURSOR FOR - SELECT workerFk - FROM tmp.subordinate + SELECT workerFk + FROM tmp.subordinate WHERE NOT isChecked; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR 1062 BEGIN @@ -69663,29 +70824,29 @@ BEGIN END; DROP TEMPORARY TABLE IF EXISTS tmp.subordinate; - + CREATE TEMPORARY TABLE tmp.subordinate (PRIMARY KEY (workerFk)) ENGINE = MEMORY SELECT vBossFk AS workerFk, 0 AS isChecked; - + WHILE (SELECT COUNT(*) FROM tmp.subordinate WHERE NOT isChecked) > 0 DO OPEN workerCur; workerLoop: LOOP SET vDone = FALSE; FETCH workerCur INTO vBossId; - + IF vDone THEN LEAVE workerLoop; END IF; - - INSERT INTO tmp.subordinate - SELECT id, 0 - FROM worker + + INSERT INTO tmp.subordinate + SELECT id, 0 + FROM worker WHERE bossFk = vBossId; - - UPDATE tmp.subordinate + + UPDATE tmp.subordinate SET isChecked = 1 WHERE workerFk = vBossId; END LOOP; @@ -69725,13 +70886,13 @@ BEGIN -- Calcula el balance inicial y final de cada proveedor INSERT INTO openingBalance SELECT MAX(dueDated), - supplierFk, - companyFk, + supplierFk, + companyFk, sum(amount) eurAmount, sum(divisa) foreignAmount FROM ( SELECT p.dueDated, - p.supplierFk, + p.supplierFk, p.companyFk, p.amount, p.divisa @@ -69747,7 +70908,7 @@ BEGIN SELECT iidd.dueDated, ii.supplierFk, ii.companyFk, - - iidd.amount, + - iidd.amount, - iidd.foreignValue FROM invoiceIn ii JOIN invoiceInDueDay iidd ON ii.id = iidd.invoiceInFk @@ -69755,14 +70916,14 @@ BEGIN JOIN company co ON co.id = ii.companyFk WHERE iidd.dueDated > '2014-12-31' AND iidd.dueDated <= vEnded - AND ii.isBooked AND co.`code` = 'VNL' + AND ii.isBooked AND co.`code` = 'VNL' AND c.`code` <> 'EUR' UNION ALL SELECT se.dueDated, se.supplierFk, se.companyFk, - - se.amount, + - se.amount, 0 FROM supplierExpense se JOIN currency c ON c.id = se.currencyFk @@ -69772,7 +70933,7 @@ BEGIN AND co.`code` = 'VNL' AND c.`code` <> 'EUR' ) sub GROUP BY companyFk, supplierFk; - + SELECT ob.dueDated , ob.supplierFk , ob.companyFk @@ -69930,7 +71091,7 @@ BEGIN - SUM(iid.amount) mysql, 0 sage FROM invoiceInDueDay iid - JOIN invoiceIn ii ON ii.id = iid.invoiceInFk + JOIN invoiceIn ii ON ii.id = iid.invoiceInFk WHERE IFNULL(ii.bookEntried, ii.issued) BETWEEN vDateFrom AND vDateTo AND ii.isBooked GROUP BY ii.id @@ -70025,8 +71186,8 @@ BEGIN JOIN ( SELECT p.supplierFk FROM supplier s JOIN payMethod pm ON pm.id = s.payMethodFk - JOIN (SELECT supplierFk,MAX(created) created - FROM payment + JOIN (SELECT supplierFk,MAX(created) created + FROM payment GROUP BY supplierFk) p ON p.supplierFk = s.id WHERE p.created < (util.VN_CURDATE() - INTERVAL pm.graceMonthsDisableChecked MONTH) AND pm.graceMonthsDisableChecked @@ -70071,15 +71232,15 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketBoxesView`(IN vTicketFk INT) BEGIN - - SELECT s.id, - s.itemFk, - s.concept, - floor(s.quantity / b.packing) as Cajas, - b.packing, - s.isPicked, + + SELECT s.id, + s.itemFk, + s.concept, + floor(s.quantity / b.packing) as Cajas, + b.packing, + s.isPicked, i.size - FROM ticket t + FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN cache.last_buy lb on lb.warehouse_id = t.warehouseFk AND lb.item_id = s.itemFk @@ -70090,7 +71251,7 @@ BEGIN AND p.isBox GROUP BY s.itemFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70112,7 +71273,7 @@ BEGIN DECLARE vDateStart DATETIME DEFAULT DATE(vDate); DECLARE vDateEnd DATETIME DEFAULT util.dayEnd(vDate); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketBuiltTime; CREATE TEMPORARY TABLE tmp.ticketBuiltTime @@ -70125,7 +71286,7 @@ BEGIN SELECT ticketFk, builtTime FROM ( - SELECT + SELECT ticketFk, created as builtTime FROM @@ -70133,13 +71294,13 @@ BEGIN WHERE created BETWEEN vDateStart AND vDateEnd ORDER BY ticketFk, created DESC LIMIT 10000000000000000000 - ) sub + ) sub GROUP BY ticketFk ) sub2 ON sub2.ticketFk = t.id WHERE t.shipped BETWEEN vDate AND util.dayEnd(vDate) AND t.clientFk NOT IN (50,400,200) AND t.companyFk = 442 - + ; END ;; @@ -70168,30 +71329,30 @@ BEGIN */ REPLACE INTO orderTicket(orderFk,ticketFk) - SELECT orderFk, vTicketNew - FROM orderTicket + SELECT orderFk, vTicketNew + FROM orderTicket WHERE ticketFk = vTicketOld; - + -- Bionizamos lineas con Preu = 0 CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id + SELECT id FROM sale WHERE ticketFk = vTicketNew AND price = 0; - + CALL sale_recalcComponent(1); -- Bionizamos lineas con Preu > 0 CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id + SELECT id FROM sale WHERE ticketFk = vTicketNew AND price > 0; - + CALL sale_recalcComponent(6); DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70214,12 +71375,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateFromType`( vLanded D vTypeFk INT) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (INDEX (itemFk)) - ENGINE = MEMORY + CREATE TEMPORARY TABLE tmp.item + (INDEX (itemFk)) + ENGINE = MEMORY SELECT id itemFk FROM vn.item WHERE typeFk = vTypeFk; - + CALL catalog_calculate(vLanded, vAddressFk, vAgencyModeFk); DROP TEMPORARY TABLE tmp.item; DROP TEMPORARY TABLE tmp.ticketLot; @@ -70241,7 +71402,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculatePurge`() BEGIN - DROP TEMPORARY TABLE + DROP TEMPORARY TABLE tmp.ticketCalculateItem, tmp.ticketComponentPrice, tmp.ticketComponent, @@ -70265,56 +71426,56 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClon`(vTicketFk INT, vNewShipped DATE) BEGIN - + DECLARE done INT DEFAULT FALSE; - DECLARE vNewTicketFk INT; + DECLARE vNewTicketFk INT; DECLARE vOldSaleFk INT; DECLARE vNewSaleFk INT; - + DECLARE cur1 CURSOR FOR SELECT id FROM vn.sale WHERE ticketFk = vTicketFk; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - + SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); - + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); - - UPDATE vn.ticket + + UPDATE vn.ticket SET landed = TIMESTAMPADD(DAY, DATEDIFF(vNewShipped, shipped), landed), shipped = vNewShipped WHERE id = vNewTicketFk; - + OPEN cur1; - + read_loop: LOOP - + FETCH cur1 INTO vOldSaleFk; - + IF done THEN LEAVE read_loop; END IF; - + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed) SELECT vNewTicketFk, itemFk, quantity, concept, price, discount, priceFixed, isPriceFixed FROM vn.sale WHERE id = vOldSaleFk; - + SELECT max(id) INTO vNewSaleFk FROM vn.sale WHERE ticketFk = vNewTicketFk; - + INSERT INTO vn.saleComponent(saleFk, componentFk, value, isGreuge) SELECT vNewSaleFk, componentFk, value, isGreuge FROM vn.saleComponent WHERE saleFk = vOldSaleFk; - + END LOOP; CLOSE cur1; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70336,18 +71497,18 @@ BEGIN DECLARE vShipped DATE; DECLARE vMaxDated DATE; - - SELECT shipped, TIMESTAMPADD(YEAR,1,shipped) + + SELECT shipped, TIMESTAMPADD(YEAR,1,shipped) INTO vShipped, vMaxDated FROM vn.ticket WHERE id = vTicketFk; - + WHILE vShipped <= vMaxDated DO - + SET vShipped = TIMESTAMPADD(WEEK, 1, vShipped); - + CALL vn.ticketClon(vTicketFk, vShipped); - + END WHILE; END ;; @@ -70369,10 +71530,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_get`(vTicketFk INT) BEGIN - SELECT tc.collectionFk + SELECT tc.collectionFk FROM vn.ticketCollection tc WHERE ticketFk = vTicketFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70391,18 +71552,18 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_setUsedShelves`(vTicketFk INT, vUsedShelves INT) BEGIN - + /* * Inserta número de baldas que ocupa un ticket - * + * * @param vTicketFk Identificador de ticket * @param vUsedShelves Número de baldas */ - + UPDATE ticketCollection tc SET tc.usedShelves = vUsedShelves WHERE tc.ticketFk = vTicketFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70440,18 +71601,18 @@ BEGIN END; START TRANSACTION; - + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t + + UPDATE ticket t JOIN address a ON a.id = vAddressFk SET t.nickname = a.nickname WHERE t.id = vTicketFk; - + END IF; - + UPDATE ticket t - SET + SET t.clientFk = vClientFk, t.agencyModeFk = vAgencyModeFk, t.addressFk = vAddressFk, @@ -70462,12 +71623,12 @@ BEGIN t.isDeleted = vIsDeleted WHERE t.id = vTicketFk; - + IF vHasToBeUnrouted THEN UPDATE ticket t SET t.routeFk = NULL WHERE t.id = vTicketFk; END IF; - + IF vOption <> 8 THEN DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale @@ -70509,104 +71670,104 @@ BEGIN DECLARE vComponentFk INT; DECLARE vRenewComponents BOOLEAN; DECLARE vKeepPrices BOOLEAN; - + CASE vOption - WHEN 1 THEN + WHEN 1 THEN SET vRenewComponents = TRUE; SET vKeepPrices = FALSE; WHEN 2 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'debtCollection'; + SELECT id INTO vComponentFk FROM component WHERE `code` = 'debtCollection'; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; - WHEN 3 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'mana'; + WHEN 3 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'mana'; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 4 THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = 'buyerDiscount'; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; - WHEN 4 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'buyerDiscount'; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - /* WHEN 5 THEN + /* WHEN 5 THEN SET vComponentFk = 35; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE;*/ - WHEN 6 THEN + WHEN 6 THEN SELECT id INTO vComponentFk FROM component WHERE `code` = 'imbalance'; SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; WHEN 7 THEN REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk NOT IN (28, 29) GROUP BY s.id; - + REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) + SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk NOT IN (28, 29) GROUP BY s.id; - + SET vRenewComponents = FALSE; SET vKeepPrices = FALSE; WHEN 8 THEN - DELETE sc.* + DELETE sc.* FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; - + REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id; - + SET vRenewComponents = FALSE; SET vKeepPrices = FALSE; - WHEN 9 THEN + WHEN 9 THEN SET vRenewComponents = TRUE; SET vKeepPrices = TRUE; END CASE; IF vRenewComponents THEN - DELETE sc.* - FROM tmp.sale tmps + DELETE sc.* + FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk JOIN `component` c ON c.id = sc.componentFk WHERE c.isRenewable; - + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT s.id, tc.componentFk, tc.cost - FROM sale s + FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); - - -- Añadir componente venta por paquete + + -- Añadir componente venta por paquete DROP TEMPORARY TABLE IF EXISTS tmp.sale2; CREATE TEMPORARY TABLE tmp.sale2 (PRIMARY KEY (saleFk)) - ENGINE = MEMORY + ENGINE = MEMORY SELECT * FROM tmp.sale; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent2; CREATE TEMPORARY TABLE tmp.ticketComponent2 - SELECT * FROM tmp.ticketComponent; - - REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT * FROM tmp.ticketComponent; + + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT t.id, t.componentFk, t.cost FROM ( SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto FROM vn.sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id JOIN vn.buy b ON b.id = buy_id JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' LEFT JOIN ( SELECT s.id FROM vn.sale s @@ -70617,8 +71778,8 @@ BEGIN ) tp ON tp.id = s.id WHERE tp.id IS NULL HAVING resto <> 0) t; - - DROP TEMPORARY TABLE IF EXISTS + + DROP TEMPORARY TABLE IF EXISTS tmp.sale2, tmp.ticketComponent2; END IF; @@ -70636,26 +71797,26 @@ BEGIN UPDATE sale s JOIN item i on i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk GROUP BY sc.saleFk) sc ON sc.saleFk = s.id SET s.price = sumValue / ((100 - s.discount) / 100) - WHERE it.code != 'PRT' ; - + WHERE it.code != 'PRT' ; + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id WHERE sc.componentFk != 21 - GROUP BY s.id + GROUP BY s.id HAVING ROUND(saleValue, 4) <> 0; END IF; - + UPDATE sale s JOIN ( - SELECT SUM(sc.value) sumValue, sc.saleFk + SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk JOIN `component` c ON c.id = sc.componentFk @@ -70669,10 +71830,10 @@ BEGIN JOIN sale s on s.id = sc.saleFk JOIN item i ON i.id = s.itemFk JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT'; - + WHERE it.code = 'PRT'; + INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 15, s.price + SELECT s.id, 15, s.price FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id JOIN item i ON i.id = s.itemFK @@ -70739,24 +71900,24 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticket ENGINE = MEMORY SELECT vTicketFk ticketFk; - + CALL vn.ticket_getTax(NULL); - SELECT + SELECT tt.ticketFk, CAST(tt.taxableBase AS DECIMAL(10, 2)) AS taxableBase, CAST(tt.rate * tt.taxableBase / 100 AS DECIMAL(10, 2)) AS tax, - pgc.*, + pgc.*, CAST(IF(pe.equFk IS NULL, taxableBase, 0) AS DECIMAL(10, 2)) AS Base, pgc.rate / 100 as vatPercent FROM tmp.ticketTax tt JOIN vn.pgc ON pgc.code = tt.pgcFk LEFT JOIN vn.pgcEqu pe ON pe.equFk = pgc.code; - + DROP TEMPORARY TABLE tmp.ticket; DROP TEMPORARY TABLE tmp.ticketTax; DROP TEMPORARY TABLE tmp.ticketAmount; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70794,29 +71955,29 @@ BEGIN JOIN ticket t ON t.id = tmpTicket.ticketFk; CALL addressTaxArea (); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; CREATE TEMPORARY TABLE tmp.ticketTax (INDEX (ticketFk)) ENGINE = MEMORY SELECT tmpTicket.ticketFk, bp.pgcFk, - SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) + SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) ) AS taxableBase, SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2) ) * pgc.rate / 100 AS tax, tc.code - + FROM tmp.ticket tmpTicket JOIN sale s ON s.ticketFk = tmpTicket.ticketFk JOIN item i ON i.id = s.itemFk JOIN ticket t ON t.id = tmpTicket.ticketFk JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata + JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN itemTaxCountry itc + JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - JOIN bookingPlanner bp + JOIN bookingPlanner bp ON bp.countryFk = su.countryFk AND bp.taxAreaFk = ata.areaFk AND bp.taxClassFk = itc.taxClassFk @@ -70824,7 +71985,7 @@ BEGIN JOIN taxClass tc ON tc.id = bp.taxClassFk GROUP BY tmpTicket.ticketFk, pgc.code HAVING taxableBase != 0; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; CREATE TEMPORARY TABLE tmp.ticketAmount (INDEX (ticketFk)) @@ -70835,7 +71996,7 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70856,7 +72017,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTotal`(vTaxArea VARCHAR(25 BEGIN /** * Calcula el total con IVA para un conjunto de tickets. - * + * * @param vTaxArea * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular * @return tmp.ticketTotal Total para cada ticket @@ -70873,7 +72034,7 @@ BEGIN FROM tmp.ticket t LEFT JOIN tmp.ticketAmount ta ON t.ticketFk = ta.ticketFk GROUP BY ticketFk; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; END ;; @@ -70945,18 +72106,18 @@ BEGIN DECLARE vParked DATETIME; DECLARE vLevel INT; DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) + + SELECT IFNULL(`level`,0), IFNULL(collectionFk,0) INTO vLevel, vCollectionFk FROM vn.ticketCollection WHERE ticketFk = vTicketFk LIMIT 1; - - SELECT created, parkingFk + + SELECT created, parkingFk INTO vParked, vParkingFk FROM vn.ticketParking WHERE ticketFk = vTicketFk; - + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp JOIN vn.parking p ON p.id = tp.parkingFk @@ -70983,7 +72144,7 @@ BEGIN AND sc.isPackagingArea AND tp.created < vParked AND t.packages <=> 0); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71004,7 +72165,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketNotInvoicedByClient`(vClientF BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - + CREATE TEMPORARY TABLE tmp.ticket SELECT id ticketFk FROM ticket @@ -71014,7 +72175,7 @@ BEGIN CALL vn.ticketGetTotal(NULL); - SELECT c.id, + SELECT c.id, c.name as Cliente, t.shipped as Fecha, t.id as Id_Ticket, @@ -71025,7 +72186,7 @@ BEGIN DROP TEMPORARY TABLE tmp.ticket, - tmp.ticketTotal; + tmp.ticketTotal; END ;; DELIMITER ; @@ -71045,21 +72206,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketObservation_addNewBorn`(vTicketFk INT) BEGIN - + /** * Inserta observaciones para los tickets con clientes nuevos o recuperados - * + * * @param vTicketFk Identificador de vn.ticket */ - + DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! '; INSERT INTO vn.ticketObservation(ticketFk, observationTypeFk, description) SELECT vTicketFk, ot.id, vDescription FROM vn.observationType ot WHERE ot.hasNewBornMessage - ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description); - + ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71099,7 +72260,7 @@ BEGIN DECLARE vComponentCost INT; DECLARE vDone INT DEFAULT FALSE; DECLARE vClientId INT; - + DECLARE vCursor CURSOR FOR SELECT DISTINCT clientFk FROM ( @@ -71116,31 +72277,31 @@ BEGIN RESIGNAL; END; - SELECT id INTO vWarehouseInventory - FROM warehouse + SELECT id INTO vWarehouseInventory + FROM warehouse WHERE `code`= 'inv'; - - SELECT id INTO vComponentCost - FROM component + + SELECT id INTO vComponentCost + FROM component WHERE `code`= 'purchaseValue'; - - SELECT packagingInvoicingDated INTO vDateStart - FROM ticketConfig; - + + SELECT packagingInvoicingDated INTO vDateStart + FROM ticketConfig; + IF vWarehouseInventory IS NULL THEN CALL util.throw('Warehouse inventory not set'); END IF; IF vComponentCost IS NULL THEN CALL util.throw('Component cost not set'); - END IF; + END IF; SET vDateEnd = vDated + INTERVAL 1 DAY; - + IF NOT vWithoutPeriodGrace THEN SET vGraceDate = vGraceDate -INTERVAL 1 MONTH; END IF; - + DROP TEMPORARY TABLE IF EXISTS tmp.packagingToInvoice; CREATE TEMPORARY TABLE tmp.packagingToInvoice (INDEX (clientFk)) @@ -71153,7 +72314,7 @@ BEGIN t.clientFk FROM ticketPackaging tp JOIN packaging p ON p.id = tp.packagingFk - JOIN ticket t ON t.id = tp.ticketFk + JOIN ticket t ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk WHERE c.isActive AND (vClientFk IS NULL OR t.clientFk = vClientFk) @@ -71161,7 +72322,7 @@ BEGIN AND (tp.quantity < 0 OR (tp.quantity > 0 AND t.shipped < vGraceDate)) AND tp.quantity AND p.itemFk; - + OPEN vCursor; l: LOOP @@ -71174,25 +72335,25 @@ BEGIN START TRANSACTION; CALL ticket_add( - vClientId, + vClientId, vDateEnd, - vWarehouseInventory, - vCompanyFk, - NULL, - NULL, - NULL, - vDateEnd, - account.myUser_getId(), + vWarehouseInventory, + vCompanyFk, + NULL, + NULL, + NULL, + vDateEnd, + account.myUser_getId(), TRUE, vNewTicket); - + INSERT INTO ticketPackaging(ticketFk, packagingFk, quantity, pvp) SELECT vNewTicket, packagingFk, - SUM(quantity) totalQuantity, price - FROM tmp.packagingToInvoice + FROM tmp.packagingToInvoice WHERE clientFk = vClientId GROUP BY packagingFk HAVING IF(vWithoutPeriodGrace, totalQuantity <> 0, totalQuantity < 0); - + INSERT INTO sale(ticketFk, itemFk, concept, quantity, price) SELECT vNewTicket, pti.itemFk, i.name, SUM(pti.quantity) totalQuantity, pti.price FROM tmp.packagingToInvoice pti @@ -71200,12 +72361,12 @@ BEGIN WHERE pti.clientFk = vClientId GROUP BY pti.itemFk HAVING IF(vWithoutPeriodGrace, totalQuantity <> 0, totalQuantity > 0); - + INSERT INTO saleComponent(saleFk, componentFk, value) SELECT id, vComponentCost, price FROM sale WHERE ticketFk = vNewTicket; - + COMMIT; END LOOP; CLOSE vCursor; @@ -71229,37 +72390,37 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1)) BEGIN - + /** * Averigua los tickets que se han saltado por un error en el proceso encajado * @param vTicketFk Ticket * @param vItemPackingTypeFk Modo de encajado * @return un select con los tickets afectados - */ + */ DECLARE vParkingFk INT; DECLARE vParked DATETIME; DECLARE vLevel INT; DECLARE vWagon INT; DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) + + SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) INTO vLevel, vWagon, vCollectionFk FROM vn.ticketCollection tc JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk WHERE ticketFk = vTicketFk ORDER BY c.id DESC LIMIT 1; - - SELECT created, parkingFk + + SELECT created, parkingFk INTO vParked, vParkingFk FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk WHERE ticketFk = vTicketFk AND s.itemPackingTypeFk = vItemPackingTypeFk AND s.isPackagingArea ; - + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia FROM vn.ticketParking tp JOIN vn.parking p ON p.id = tp.parkingFk @@ -71276,9 +72437,9 @@ BEGIN AND ( ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) OR - ( tc.collectionFk = vCollectionFk + ( tc.collectionFk = vCollectionFk AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) - OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) + OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) ) ) ) -- Etiquetas que no se han escaneado y ya estamos con una posterior @@ -71286,7 +72447,7 @@ BEGIN (s.alertLevel > 1 AND tp.parkingFk = vParkingFk AND sc.isPackagingArea - AND tp.created < vParked + AND tp.created < vParked AND t.packages <=> 0); END ;; DELIMITER ; @@ -71338,11 +72499,11 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketRequest_Add`(vDescription VARCHAR(255), vQuantity INT, vPrice DOUBLE, vTicketFk INT, vBuyerCode VARCHAR(3)) BEGIN - INSERT INTO vn.ticketRequest(description, - quantity, - price, - ticketFk, - buyerCode, + INSERT INTO vn.ticketRequest(description, + quantity, + price, + ticketFk, + buyerCode, requesterFk) VALUES(vDescription, vQuantity, @@ -71350,7 +72511,7 @@ BEGIN vTicketFk, vBuyerCode, vn.getUser()); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71369,26 +72530,26 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN - + /* Modifica el estado de un ticket de hoy - * + * * @param vTicketFk el id del ticket * @param vStateCode estado a modificar del ticket - * + * */ - + DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM state s - JOIN ticketStateToday tst ON tst.state = s.id + + SELECT s.alertLevel INTO vAlertLevel + FROM state s + JOIN ticketStateToday tst ON tst.state = s.id WHERE tst.ticket = vTicketFk LIMIT 1; - + IF vAlertLevel < 2 THEN - + CALL vn.ticket_setState(vTicketFk, vStateCode); - + END IF; END ;; @@ -71398,34 +72559,34 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketStateUpdate` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN - + /* * @deprecated:utilizar ticket_setState */ - + DECLARE vAlertLevel INT; - SELECT s.alertLevel INTO vAlertLevel + SELECT s.alertLevel INTO vAlertLevel FROM vn.state s JOIN vn.ticketState ts ON ts.stateFk = s.id WHERE ts.ticketFk = vTicketFk; - - IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN - - INSERT INTO ticketTracking(stateFk, ticketFk, workerFk) + + IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN + + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT id, vTicketFk, account.myUser_getId() - FROM vn.state + FROM vn.state WHERE `code` = vStateCode collate utf8_unicode_ci; END IF; @@ -71569,14 +72730,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_add` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_add`( vClientId INT @@ -71693,7 +72854,7 @@ BEGIN END IF; 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 ticketTracking(stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT id, vNewTicket, account.myUser_getId() FROM state WHERE `code` = 'DELIVERED'; @@ -71716,20 +72877,20 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN - + INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) - SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed + SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed FROM vn.ticket t JOIN vn.warehouse w ON w.name = 'INVENTARIO' WHERE t.id = vOriginalTicket; - + SELECT LAST_INSERT_ID() INTO vNewTicket; INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) - SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount + SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount FROM vn.sale s WHERE s.ticketFk = vOriginalTicket; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71759,8 +72920,7 @@ BEGIN SELECT inventoried INTO vDateInventory FROM config; - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - CREATE TEMPORARY TABLE tmp.stock + CREATE OR REPLACE TEMPORARY TABLE tmp.stock (itemFk INT PRIMARY KEY, amount INT) ENGINE = MEMORY; @@ -71777,7 +72937,7 @@ BEGIN SELECT itemFk, quantity FROM itemEntryIn WHERE landed >= vDateInventory - AND landed < vDateFuture + AND landed <= vDateToAdvance AND isVirtualStock = FALSE AND warehouseInFk = vWarehouseFk UNION ALL @@ -71806,15 +72966,24 @@ BEGIN dest.totalWithVat, origin.totalWithVat futureTotalWithVat, dest.agency, + dest.agencyModeFk, origin.futureAgency, + origin.agencyModeFk futureAgencyModeFk, dest.lines, dest.liters, origin.futureLines - origin.hasStock AS notMovableLines, (origin.futureLines = origin.hasStock) AS isFullMovable, + dest.zoneFk, origin.futureZoneFk, origin.futureZoneName, origin.classColor futureClassColor, - dest.classColor + dest.classColor, + origin.clientFk futureClientFk, + origin.addressFk futureAddressFk, + origin.warehouseFk futureWarehouseFk, + origin.companyFk futureCompanyFk, + IFNULL(dest.nickname, origin.nickname) nickname, + dest.landed FROM ( SELECT s.ticketFk, @@ -71822,7 +72991,6 @@ BEGIN t.shipped, t.totalWithVat, st.name futureState, - t.addressFk, am.name futureAgency, count(s.id) futureLines, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, @@ -71830,7 +72998,13 @@ BEGIN SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, z.id futureZoneFk, z.name futureZoneName, - st.classColor + st.classColor, + t.clientFk, + t.nickname, + t.addressFk, + t.warehouseFk, + t.companyFk, + t.agencyModeFk FROM ticket t JOIN client c ON c.id = t.clientFk JOIN sale s ON s.ticketFk = t.id @@ -71846,10 +73020,9 @@ BEGIN AND t.warehouseFk = vWarehouseFk GROUP BY t.id ) origin - JOIN ( + LEFT JOIN ( SELECT t.id ticketFk, - t.addressFk, st.name state, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, t.shipped, @@ -71857,7 +73030,15 @@ BEGIN am.name agency, CAST(SUM(litros) AS DECIMAL(10,0)) liters, CAST(COUNT(*) AS DECIMAL(10,0)) `lines`, - st.classColor + st.classColor, + t.clientFk, + t.nickname, + t.addressFk, + t.zoneFk, + t.warehouseFk, + t.companyFk, + t.landed, + t.agencyModeFk FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id @@ -71871,7 +73052,7 @@ BEGIN AND st.order <= 5 GROUP BY t.id ) dest ON dest.addressFk = origin.addressFk - WHERE origin.hasStock != 0; + WHERE origin.hasStock; DROP TEMPORARY TABLE tmp.stock; END ;; @@ -71979,7 +73160,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canMerge`(vDated DATE, vScop BEGIN /** * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * + * * @param vDated Fecha en cuestión * @param vScopeDays Dias en el futuro a sondear * @param vLitersMax Volumen máximo de los tickets a catapultar @@ -72060,10 +73241,10 @@ BEGIN * Comprueba que los tickets entre un rango de fechas tienen componentes * y recalcula sus componentes * - * @param vShippedFrom rango inicial de fecha + * @param vShippedFrom rango inicial de fecha * @param vShippedTo rango final de fecha */ - + CREATE OR REPLACE TEMPORARY TABLE tmp.coste (primary key (id)) ENGINE = MEMORY SELECT s.id @@ -72092,9 +73273,9 @@ BEGIN AND ic.merchandise; CALL vn.sale_recalcComponent(1); - + DROP TEMPORARY TABLE tmp.recalculateSales; - DROP TEMPORARY TABLE tmp.coste; + DROP TEMPORARY TABLE tmp.coste; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72102,14 +73283,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_Clone` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN @@ -72164,8 +73345,8 @@ BEGIN FROM ticketObservation WHERE ticketFk = vOriginalTicket; - INSERT INTO ticketTracking(ticketFk, stateFk, workerFk, created) - SELECT vNewTicket, stateFk, workerFk, created + INSERT INTO ticketTracking(ticketFk, stateFk, userFk, created) + SELECT vNewTicket, stateFk, userFk, created FROM ticketTracking WHERE ticketFk = vOriginalTicket ORDER BY created; @@ -72185,14 +73366,13 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_cloneWeekly`(vWeek INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_cloneWeekly`(vDateFrom DATE, vDateTo DATE) BEGIN DECLARE vIsDone BOOL; DECLARE vLanding DATE; DECLARE vShipment DATE; DECLARE vWarehouseFk INT; DECLARE vTicketFk INT; - DECLARE vWeekDay INT; DECLARE vClientFk INT; DECLARE vCompanyFk INT; DECLARE vAddressFk INT; @@ -72204,19 +73384,21 @@ BEGIN DECLARE rsTicket CURSOR FOR SELECT tt.ticketFk, - tt.weekDay, - t.clientFk, - t.warehouseFk, - t.companyFk, - t.addressFk, - tt.agencyModeFk - FROM ticketWeekly tt - JOIN ticket t ON tt.ticketFk = t.id; + t.clientFk, + t.warehouseFk, + t.companyFk, + t.addressFk, + tt.agencyModeFk, + ti.dated + FROM ticketWeekly tt + JOIN ticket t ON tt.ticketFk = t.id + JOIN tmp.time ti + WHERE WEEKDAY(ti.dated) = tt.weekDay; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; - - SET vYear = YEAR(util.VN_CURDATE()) + IF(vWeek < WEEK(util.VN_CURDATE()),1, 0); - + + CALL `util`.`time_generate`(vDateFrom,vDateTo); + OPEN rsTicket; myLoop: LOOP BEGIN @@ -72224,36 +73406,31 @@ BEGIN DECLARE vIsDuplicateMail BOOL; DECLARE vSubject VARCHAR(150); DECLARE vMessage TEXT; - + SET vIsDone = FALSE; - FETCH rsTicket INTO vTicketFk, vWeekDay, vClientFk, vWarehouseFk, vCompanyFk, vAddressFk, vAgencyModeFk; + FETCH rsTicket INTO vTicketFk,vClientFk, vWarehouseFk, vCompanyFk, vAddressFk, vAgencyModeFk,vShipment; IF vIsDone THEN LEAVE myLoop; END IF; - SELECT dated INTO vShipment - FROM `time` - WHERE `year` = vYear AND `week` = vWeek - AND WEEKDAY(dated) = vWeekDay; - -- busca si el ticket ya ha sido clonado IF EXISTS (SELECT TRUE FROM ticket tOrig JOIN sale saleOrig ON tOrig.id = saleOrig.ticketFk JOIN saleCloned sc ON sc.saleOriginalFk = saleOrig.id JOIN sale saleClon ON saleClon.id = sc.saleClonedFk JOIN ticket tClon ON tClon.id = saleClon.ticketFk - WHERE tOrig.id = vTicketFk - AND tClon.isDeleted = FALSE + WHERE tOrig.id = vTicketFk + AND tClon.isDeleted = FALSE AND DATE(tClon.shipped) = vShipment) THEN ITERATE myLoop; END IF; IF vAgencyModeFk IS NULL THEN - SELECT agencyModeFk INTO vAgencyModeFk + SELECT agencyModeFk INTO vAgencyModeFk FROM address - WHERE clientFk = vClientFk + WHERE clientFk = vClientFk AND isDefaultAddress; END IF; @@ -72274,8 +73451,8 @@ BEGIN FALSE, vNewTicket); - UPDATE ticket - SET clonedFrom = vTicketFk + UPDATE ticket + SET clonedFrom = vTicketFk WHERE id = vNewTicket; INSERT INTO sale (ticketFk, itemFk, concept, quantity, price, @@ -72294,7 +73471,7 @@ BEGIN INSERT IGNORE INTO saleCloned(saleOriginalFk, saleClonedFk) SELECT saleOriginal.id, saleClon.id FROM sale saleOriginal - JOIN sale saleClon ON saleOriginal.itemFk = saleClon.itemFk + JOIN sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity WHERE saleOriginal.ticketFk = vTicketFk AND saleClon.ticketFk = vNewTicket; @@ -72324,7 +73501,7 @@ BEGIN buyed, requesterFk, attenderFk, - vNewTicket + vNewTicket FROM ticketRequest WHERE ticketFk =vTicketFk; @@ -72339,26 +73516,26 @@ BEGIN INSERT INTO ticketObservation( ticketFk, observationTypeFk, - description) + description) VALUES( vNewTicket, vSalesPersonFK, CONCAT('turno desde ticket: ',vTicketFk)) - ON DUPLICATE KEY UPDATE description = + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); INSERT INTO ticketObservation(ticketFk, observationTypeFk, - description) + description) VALUES( vNewTicket, vItemPicker, 'ATENCION: Contiene lineas de TURNO') - ON DUPLICATE KEY UPDATE description = + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); IF (vLanding IS NULL) THEN - + SELECT e.email INTO vSalesPersonEmail FROM client c JOIN account.emailUser e ON e.userFk = c.salesPersonFk @@ -72366,8 +73543,8 @@ BEGIN SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicketFk,' para el dia: ', vShipment); - SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicketFk, - ' para el dia: ', vShipment, + SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicketFk, + ' para el dia: ', vShipment, ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket, ' pero ha que revisar las fechas y la agencia'); @@ -72387,6 +73564,7 @@ BEGIN END; END LOOP; CLOSE rsTicket; + DROP TEMPORARY TABLE IF EXISTS tmp.time; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72406,7 +73584,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_close`() BEGIN /** - * Realiza el cierre de todos los + * Realiza el cierre de todos los * tickets de la tabla tmp.ticket_close. * * @table tmp.ticket_close(ticketFk) Identificadores de los tickets a cerrar @@ -72424,7 +73602,7 @@ BEGIN DECLARE cur CURSOR FOR SELECT ticketFk FROM tmp.ticket_close; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN RESIGNAL; @@ -72434,7 +73612,7 @@ BEGIN proc: LOOP SET vDone = FALSE; - + FETCH cur INTO vCurTicketFk; IF vDone THEN @@ -72451,12 +73629,12 @@ BEGIN c.hasToInvoice INTO vClientFk, vIsTaxDataChecked, - vCompanyFk, + vCompanyFk, vShipped, vHasDailyInvoice, vWithPackage, vHasToInvoice - FROM ticket t + FROM ticket t JOIN `client` c ON c.id = t.clientFk JOIN province p ON p.id = c.provinceFk LEFT JOIN autonomy a ON a.id = p.autonomyFk @@ -72466,22 +73644,22 @@ BEGIN INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) (SELECT vCurTicketFk, p.id, COUNT(*) - FROM expedition e + FROM expedition e JOIN packaging p ON p.itemFk = e.freightItemFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage GROUP BY p.itemFk); -- No retornables o no catalogados - INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) + INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) (SELECT e.freightItemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.freightItemFk, vClientFk), 1 - FROM expedition e + FROM expedition e JOIN item i ON i.id = e.freightItemFk LEFT JOIN packaging p ON p.itemFk = i.id WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 AND getSpecialPrice(e.freightItemFk, vClientFk) > 0 GROUP BY e.freightItemFk); - + IF(vHasDailyInvoice) AND vHasToInvoice THEN -- Facturacion rapida @@ -72489,10 +73667,10 @@ BEGIN -- Facturar si está contabilizado IF vIsTaxDataChecked THEN CALL invoiceOut_newFromClient( - vClientFk, - (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), - vShipped, - vCompanyFk, + vClientFk, + (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), + vShipped, + vCompanyFk, NULL, NULL, vNewInvoiceId); @@ -72560,25 +73738,25 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentMakeUpdate`( - vTicketFk INT, + vTicketFk INT, vClientFk INT, - vNickname VARCHAR(50), + vNickname VARCHAR(50), vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, + vAddressFk INT, + vZoneFk INT, vWarehouseFk INT, - vCompanyFk INT, + vCompanyFk INT, vShipped DATETIME, - vLanded DATE, + vLanded DATE, vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, + vHasToBeUnrouted BOOLEAN, vOption INT) BEGIN - + /** * Modifica en el ticket los campos que se le pasan por parámetro * y cambia sus componentes - * + * * @param vTicketFk Id del ticket a modificar * @param vClientFk nuevo cliente * @param vNickname nuevo alias @@ -72593,29 +73771,29 @@ BEGIN * @param vHasToBeUnrouted si se le elimina la ruta al ticket * @param vOption opcion para el case del proc ticketComponentUpdateSale */ - + DECLARE vPrice DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2); CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t + + UPDATE ticket t JOIN address a ON a.id = vAddressFk SET t.nickname = a.nickname WHERE t.id = vTicketFk; - + END IF; CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); - SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus FROM tmp.zoneGetShipped WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; - + UPDATE ticket t - SET + SET t.clientFk = vClientFk, t.nickname = vNickname, t.agencyModeFk = vAgencyModeFk, @@ -72630,12 +73808,12 @@ BEGIN t.isDeleted = vIsDeleted WHERE t.id = vTicketFk; - + IF vHasToBeUnrouted THEN UPDATE ticket t SET t.routeFk = NULL WHERE t.id = vTicketFk; END IF; - + IF vOption <> 8 THEN DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale @@ -72673,7 +73851,7 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentPreview`( vTicketFk INT, - vLanded DATE, + vLanded DATE, vAddressFk INT, vZoneFk INT, vWarehouseFk SMALLINT) @@ -72689,7 +73867,7 @@ BEGIN * * @return tmp.ticketComponentPreview (warehouseFk, itemFk, componentFk, cost) */ - DECLARE vHasDataChanged BOOL DEFAULT FALSE; + DECLARE vHasDataChanged BOOL DEFAULT FALSE; DECLARE vHasAddressChanged BOOL; DECLARE vHasZoneChanged BOOL DEFAULT FALSE; DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; @@ -72700,8 +73878,8 @@ BEGIN DECLARE vHasChangeAll BOOL DEFAULT FALSE; - SELECT DATE(landed) <> vLanded, - addressFk <> vAddressFk, + SELECT DATE(landed) <> vLanded, + addressFk <> vAddressFk, zoneFk <> vZoneFk, warehouseFk <> vWarehouseFk INTO @@ -72724,15 +73902,15 @@ BEGIN SET vAgencyModeTypeRateFk = 6; END IF; - SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped + SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped FROM zone WHERE id = vZoneFk; - + CALL buyUltimate(vWarehouseFk, vShipped); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( - SELECT + CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( + SELECT vWarehouseFk AS warehouseFk, NULL AS available, s.itemFk, @@ -72752,9 +73930,9 @@ BEGIN JOIN sale s ON s.id = sc.saleFk JOIN ticket t ON t.id = s.ticketFk JOIN `component` c ON c.id = sc.componentFk - WHERE s.ticketFk = vTicketFk - AND (c.isRenewable = FALSE - OR + WHERE s.ticketFk = vTicketFk + AND (c.isRenewable = FALSE + OR (NOT vHasChangeAll AND (NOT (c.typeFk <=> vAddressTypeRateFk OR c.typeFk <=> vAgencyModeTypeRateFk)))); @@ -72833,55 +74011,59 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_DelayTruckSplit`(vTicketFk INT) -BEGIN - - /* - * Splita las lineas de ticket que no estan ubicadas - * - */ - - DECLARE vNewTicketFk INT; - DECLARE vTotalLines INT; - DECLARE vLinesToSplit INT; - - DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit; - - SELECT COUNT(*) INTO vTotalLines - FROM vn.sale - WHERE ticketFk = vTicketFk; - - CREATE TEMPORARY TABLE tmp.SalesToSplit - SELECT s.id saleFk - FROM vn.ticket t - JOIN vn.sale s ON t.id = s.ticketFk - LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = s.itemFk AND issw.warehouseFk = t.warehouseFk - WHERE s.quantity > IFNULL(issw.visible, 0) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND t.id = vTicketFk; - - SELECT COUNT(*) INTO vLinesToSplit - FROM tmp.SalesToSplit; - - IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN - - SET vNewTicketFk = vTicketFk; - - ELSE - - CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); - - UPDATE vn.sale s - JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id - SET s.ticketFk = vNewTicketFk; - - END IF; - - CALL vn.ticketStateUpdate(vNewTicketFk, 'FIXING'); - - DROP TEMPORARY TABLE tmp.SalesToSplit; - +BEGIN +/** + * Splita las lineas de ticket que no estan ubicadas + * + * @param vTicketFk Id ticket + */ + DECLARE vNewTicketFk INT; + DECLARE vTotalLines INT; + DECLARE vLinesToSplit INT; + + DROP TEMPORARY TABLE IF EXISTS tmp.SalesToSplit; + + SELECT COUNT(*) INTO vTotalLines + FROM sale + WHERE ticketFk = vTicketFk; + + CREATE TEMPORARY TABLE tmp.SalesToSplit + SELECT s.id saleFk + FROM ticket t + JOIN sale s ON t.id = s.ticketFk + LEFT JOIN ( + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk + ) issw ON issw.itemFk = s.itemFk + AND issw.warehouseFk = t.warehouseFk + WHERE s.quantity > IFNULL(issw.visible, 0) + AND s.quantity > 0 + AND NOT s.isPicked + AND NOT s.reserved + AND t.id = vTicketFk; + + SELECT COUNT(*) INTO vLinesToSplit + FROM tmp.SalesToSplit; + + IF vLinesToSplit = vTotalLines AND vLinesToSplit > 0 THEN + SET vNewTicketFk = vTicketFk; + ELSE + CALL ticket_Clone(vTicketFk, vNewTicketFk); + UPDATE sale s + JOIN tmp.SalesToSplit sts ON sts.saleFk = s.id + SET s.ticketFk = vNewTicketFk; + END IF; + + CALL ticketStateUpdate(vNewTicketFk, 'FIXING'); + + DROP TEMPORARY TABLE tmp.SalesToSplit; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72899,91 +74081,91 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_doCmr`(vSelf INT) -BEGIN -/** -* Crea u actualiza la información del CMR asociado con -* un ticket específico en caso de que sea necesario. -* -* @param vSelf El id del ticket -*/ - DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT; - SELECT cmrFk INTO vCmrFk - FROM ticket - WHERE id = vSelf; - - CREATE OR REPLACE TEMPORARY TABLE tTicket - SELECT wo.firstName, - v.numberPlate, - com.id companyFk, - a.id addressFk, - c2.defaultAddressFk, - su.id supplierFk, - t.landed - FROM ticket t - JOIN ticketState ts ON ts.ticketFk = t.id - JOIN `state` s ON s.id = ts.stateFk - JOIN alertLevel al ON al.id = s.alertLevel - JOIN client c ON c.id = t.clientFk - JOIN `address` a ON a.id = t.addressFk - JOIN province p ON p.id = a.provinceFk - JOIN country co ON co.id = p.countryFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - JOIN warehouse w ON w.id = t.warehouseFk - JOIN company com ON com.id = t.companyFk - JOIN client c2 ON c2.id = com.clientFk - JOIN supplierAccount sa ON sa.id = com.supplierAccountFk - JOIN supplier su ON su.id = sa.supplierFk - LEFT JOIN route r ON r.id = t.routeFk - LEFT JOIN worker wo ON wo.id = r.workerFk - LEFT JOIN vehicle v ON v.id = r.vehicleFk - WHERE t.shipped BETWEEN util.yesterday() AND util.dayEnd(util.VN_CURDATE()) - AND al.code IN ('PACKED', 'DELIVERED') - AND co.code <> 'ES' - AND am.name <> 'ABONO' - AND w.code = 'ALG' - AND dm.code = 'DELIVERY' - AND t.id = vSelf - GROUP BY t.id; - - START TRANSACTION; - - IF vCmrFk THEN - UPDATE cmr c - JOIN tTicket t - SET c.senderInstruccions = t.firstName, - c.truckPlate = t.numberPlate, - c.companyFk = t.companyFk, - c.addressToFk = t.addressFk, - c.addressFromFk = t.defaultAddressFk, - c.supplierFk = t.supplierFk, - c.ead = t.landed - WHERE id = vCmrFk; - ELSE - SELECT MAX(id) INTO vPreviousCmrFk FROM cmr; - - INSERT INTO cmr ( - senderInstruccions, - truckPlate, - companyFk, - addressToFk, - addressFromFk, - supplierFk, - ead - ) - SELECT * FROM tTicket; - - SELECT MAX(id) INTO vCurrentCmrFk FROM cmr; - - IF vPreviousCmrFk <> vCurrentCmrFk THEN - UPDATE ticket - SET cmrFk = vCurrentCmrFk - WHERE id = vSelf; - END IF; - END IF; - - COMMIT; - DROP TEMPORARY TABLE tTicket; +BEGIN +/** +* Crea u actualiza la información del CMR asociado con +* un ticket específico en caso de que sea necesario. +* +* @param vSelf El id del ticket +*/ + DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT; + SELECT cmrFk INTO vCmrFk + FROM ticket + WHERE id = vSelf; + + CREATE OR REPLACE TEMPORARY TABLE tTicket + SELECT wo.firstName, + v.numberPlate, + com.id companyFk, + a.id addressFk, + c2.defaultAddressFk, + su.id supplierFk, + t.landed + FROM ticket t + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN `state` s ON s.id = ts.stateFk + JOIN alertLevel al ON al.id = s.alertLevel + JOIN client c ON c.id = t.clientFk + JOIN `address` a ON a.id = t.addressFk + JOIN province p ON p.id = a.provinceFk + JOIN country co ON co.id = p.countryFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN company com ON com.id = t.companyFk + JOIN client c2 ON c2.id = com.clientFk + JOIN supplierAccount sa ON sa.id = com.supplierAccountFk + JOIN supplier su ON su.id = sa.supplierFk + LEFT JOIN route r ON r.id = t.routeFk + LEFT JOIN worker wo ON wo.id = r.workerFk + LEFT JOIN vehicle v ON v.id = r.vehicleFk + WHERE t.shipped BETWEEN util.yesterday() AND util.dayEnd(util.VN_CURDATE()) + AND al.code IN ('PACKED', 'DELIVERED') + AND co.code <> 'ES' + AND am.name <> 'ABONO' + AND w.code = 'ALG' + AND dm.code = 'DELIVERY' + AND t.id = vSelf + GROUP BY t.id; + + START TRANSACTION; + + IF vCmrFk THEN + UPDATE cmr c + JOIN tTicket t + SET c.senderInstruccions = t.firstName, + c.truckPlate = t.numberPlate, + c.companyFk = t.companyFk, + c.addressToFk = t.addressFk, + c.addressFromFk = t.defaultAddressFk, + c.supplierFk = t.supplierFk, + c.ead = t.landed + WHERE id = vCmrFk; + ELSE + SELECT MAX(id) INTO vPreviousCmrFk FROM cmr; + + INSERT INTO cmr ( + senderInstruccions, + truckPlate, + companyFk, + addressToFk, + addressFromFk, + supplierFk, + ead + ) + SELECT * FROM tTicket; + + SELECT MAX(id) INTO vCurrentCmrFk FROM cmr; + + IF vPreviousCmrFk <> vCurrentCmrFk THEN + UPDATE ticket + SET cmrFk = vCurrentCmrFk + WHERE id = vSelf; + END IF; + END IF; + + COMMIT; + DROP TEMPORARY TABLE tTicket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73216,37 +74398,37 @@ BEGIN * @param vTicketFk -> Ticket * @param vDatedNew -> Nueva fecha * @return Sales con Movible -*/ +*/ DECLARE vDatedOld DATETIME; SET vDatedNew = DATE_ADD(vDatedNew, INTERVAL 1 DAY); SELECT t.shipped INTO vDatedOld - FROM ticket t + FROM ticket t WHERE t.id = vTicketFk; - CALL item_getStock(vWarehouseFk, vDatedNew, NULL); + CALL item_getStock(vWarehouseFk, vDatedNew, NULL); CALL item_getMinacum(vWarehouseFk, vDatedNew, DATEDIFF(DATE_SUB(vDatedOld, INTERVAL 1 DAY), vDatedNew), NULL); - - SELECT s.id, - s.itemFk, - s.quantity, - s.concept, - s.price, + + SELECT s.id, + s.itemFk, + s.quantity, + s.concept, + s.price, s.reserved, - s.discount, - i.image, - i.subName, + s.discount, + i.image, + i.subName, il.stock + IFNULL(im.amount, 0) AS movable FROM ticket t JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk + JOIN item i ON i.id = s.itemFk LEFT JOIN tmp.itemMinacum im ON im.itemFk = s.itemFk AND im.warehouseFk = vWarehouseFk LEFT JOIN tmp.itemList il ON il.itemFk = s.itemFk WHERE t.id = vTicketFk; DROP TEMPORARY TABLE IF EXISTS tmp.itemList; - DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; - + DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73274,7 +74456,7 @@ BEGIN */ CALL sale_getProblems(vIsTodayRelative); - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems (PRIMARY KEY (ticketFk)) ENGINE = MEMORY SELECT ticketFk, @@ -73346,16 +74528,32 @@ BEGIN problem VARCHAR(1), INDEX(ticketFk)) ENGINE = MEMORY; + CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT ish.itemFk itemFk, + SUM(ish.visible) visible, + s.warehouseFk warehouseFk + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + GROUP BY ish.itemFk, + s.warehouseFk; + INSERT INTO tmp.salesToSplit(saleFk, ticketFk, problem) SELECT s.id, s.ticketFk, 'F' FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN cache.visible v ON v.item_id = i.id + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) < s.quantity AND IFNULL(av.available ,0) < s.quantity AND IFNULL(issw.visible, 0) < s.quantity @@ -73365,26 +74563,28 @@ BEGIN AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; - + INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem) SELECT s.id, s.ticketFk, 'I' - FROM ticket t + FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND ic.merchandise = TRUE + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; - + INSERT IGNORE INTO tmp.salesToSplit(saleFk, ticketFk, problem) SELECT s.id, s.ticketFk, 'R' FROM ticket t @@ -73392,20 +74592,23 @@ BEGIN JOIN item i ON i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - LEFT JOIN itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN cache.visible v ON v.item_id = s.itemFk + AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id + AND issw.warehouseFk = t.warehouseFk WHERE IFNULL(v.visible,0) < s.quantity AND IFNULL(av.available ,0) >= s.quantity AND IFNULL(issw.visible, 0) < s.quantity AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND ic.merchandise = TRUE + AND NOT s.isPicked + AND NOT s.reserved + AND ic.merchandise AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; - + CREATE OR REPLACE TEMPORARY TABLE tTicketsToSplit( ticketFk INT PRIMARY KEY, problems VARCHAR(100), @@ -73420,18 +74623,18 @@ BEGIN GROUP_CONCAT(DISTINCT ss.problem ORDER BY ss.problem) problems, t.addressFk, GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - DATE_FORMAT(IF(HOUR(t.shipped), - t.shipped, + DATE_FORMAT(IF(HOUR(t.shipped), + t.shipped, IFNULL(zc.hour, z.HOUR)),'%H:%i') etd FROM tmp.salesToSplit ss JOIN ticket t ON t.id = ss.ticketFk JOIN sale s ON s.id = ss.saleFk JOIN item i ON i.id = s.itemFk LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk - LEFT JOIN zone z ON z.id = t.zoneFk + LEFT JOIN zone z ON z.id = t.zoneFk GROUP BY ss.ticketFk; - SELECT ts.*, + SELECT ts.*, t.id ticketFuture, st.name state, zc.`hour` tfEtd, @@ -73442,22 +74645,24 @@ BEGIN FROM tTicketsToSplit ts LEFT JOIN ticketState ts2 ON ts2.ticketFk = ts.ticketFk LEFT JOIN `state` st ON st.id = ts2.stateFk - LEFT JOIN ticket t ON t.id != ts.ticketFk + LEFT JOIN ticket t ON t.id != ts.ticketFk AND t.addressFk = ts.addressFk AND t.shipped BETWEEN vDated AND util.dayend(vDated) LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = vDated LEFT JOIN sale s ON s.ticketFk = t.id LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN ticketState tst ON tst.ticketFk = t.id + LEFT JOIN ticketState tst ON tst.ticketFk = t.id LEFT JOIN state st2 ON st2.id = tst.stateFk - WHERE (t.id IS NULL + WHERE (t.id IS NULL OR (vDated > util.VN_CURDATE()) OR (vDated = util.VN_CURDATE() AND vHour >= zc.`hour`)) AND ts.etd <= vHour GROUP BY ts.ticketFk, t.id ORDER BY ts.etd, ts.ticketFk; - - DROP TEMPORARY TABLE tTicketsToSplit; + + DROP TEMPORARY TABLE + tTicketsToSplit, + tItemShelvingStock_byWarehouse; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -73493,7 +74698,7 @@ BEGIN JOIN ticket t ON t.id = tmpTicket.ticketFk; CALL addressTaxArea (); - + IF vTaxArea IS NOT NULL THEN UPDATE tmp.addressTaxArea SET areaFk = vTaxArea; @@ -73565,8 +74770,8 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticketAmount (INDEX (ticketFk)) ENGINE = MEMORY - SELECT ticketFk, - taxableBase, + SELECT ticketFk, + taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax, code FROM tmp.ticketTax @@ -73646,11 +74851,11 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getWithParameters`( - vClientFk INT, + vClientFk INT, vWarehouseFk INT, - vShipped DATE, - vAddressFk INT, - vCompanyFk INT, + vShipped DATE, + vAddressFk INT, + vCompanyFk INT, vAgencyModeFk INT, OUT vTicketFk INT ) @@ -73664,8 +74869,8 @@ BEGIN * @param vAddressFk Consignatario * @param vCompanyFk Empresa * @param vAgencyModeFk agencia - */ - + */ + SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.clientFk <=> vClientFk @@ -73675,7 +74880,7 @@ BEGIN AND (t.companyFk <=> vCompanyFk OR vCompanyFk IS NULL) AND (t.agencyModeFk <=> vAgencyModeFk OR vAgencyModeFk IS NULL) LIMIT 1; - + IF vTicketFk IS NULL THEN CALL vn.ticket_add( vClientFk, @@ -73715,24 +74920,24 @@ BEGIN DECLARE vAddressFk INT; DECLARE vAgencyModeFk INT; DECLARE vWarehouseFk INT; - DECLARE vCursor CURSOR FOR + DECLARE vCursor CURSOR FOR SELECT id, landed, addressFk, agencyModeFk, warehouseFk FROM vn.ticket WHERE shipped > '2020-01-01' AND zoneFk is null; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET vDone = 1; - + OPEN vCursor; REPEAT FETCH vCursor INTO vFechedTicket, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk; CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); - + UPDATE vn.ticket t JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = vWarehouseFk SET t.zoneFk = zgs.zoneFk WHERE t.id = vFechedTicket; - + UNTIL vDone END REPEAT; DROP TEMPORARY TABLE tmp.zoneGetShipped; - + CLOSE vCursor; END ;; DELIMITER ; @@ -73752,14 +74957,14 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_priceDifference`( vTicketFk INT, - vLanded DATE, + vLanded DATE, vAddressFk INT, vZoneFk INT, vWarehouseFk INT) BEGIN /** * Devuelve las diferencias de precio de los movimientos de un ticket. - * + * * @param vTicketFk Id del ticket * @param vLanded Fecha de recepcion * @param vAddressFk Id del consignatario @@ -73768,26 +74973,26 @@ BEGIN */ CALL vn.ticket_componentPreview(vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); - SELECT s.itemFk, - i.name, - i.size, - i.category, - IFNULL(s.quantity, 0) AS quantity, - IFNULL(s.price, 0) AS price, + SELECT s.itemFk, + i.name, + i.size, + i.category, + IFNULL(s.quantity, 0) AS quantity, + IFNULL(s.price, 0) AS price, ROUND(SUM(tc.cost), 2) AS newPrice, s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference, s.id AS saleFk FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN tmp.ticketComponentPreview tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = vWarehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk - WHERE t.id = vTicketFk - AND IF(sc.componentFk IS NULL - AND c.classRate IS NOT NULL, FALSE, TRUE) + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE t.id = vTicketFk + AND IF(sc.componentFk IS NULL + AND c.classRate IS NOT NULL, FALSE, TRUE) GROUP BY s.id ORDER BY s.id; DROP TEMPORARY TABLE tmp.ticketComponentPreview; @@ -73810,7 +75015,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_printLabelPrevious`(vTicketFk INT) BEGIN /** - * Calls the report_print procedure and passes it + * Calls the report_print procedure and passes it * the necessary parameters for printing. * * @param vTicketFk id ticket to print. @@ -73818,18 +75023,18 @@ BEGIN DECLARE vPrinterFk INT; DECLARE vSaleGroup INT; DECLARE vUserFk INT DEFAULT account.myUser_getId(); - + SELECT sg.id, o.labelerFk INTO vSaleGroup, vPrinterFk FROM saleGroup sg JOIN sector sc ON sc.id = sg.sectorFk - JOIN saleGroupDetail sgd ON sg.id = sgd.saleGroupFk + JOIN saleGroupDetail sgd ON sg.id = sgd.saleGroupFk JOIN sale s ON sgd.saleFk = s.id JOIN ticket t ON s.ticketFk = t.id JOIN operator o ON o.workerFk = vUserFk - WHERE sc.id = o.sectorFk + WHERE sc.id = o.sectorFk AND t.id = vTicketFk LIMIT 1; - + CALL report_print( 'LabelPrevia', vPrinterFk, @@ -73863,12 +75068,12 @@ proc:BEGIN */ DECLARE hasInvoice BOOL; - SELECT COUNT(*) INTO hasInvoice - FROM ticket + SELECT COUNT(*) INTO hasInvoice + FROM ticket WHERE id = vSelf AND refFk IS NOT NULL; - - IF hasInvoice THEN + + IF hasInvoice THEN LEAVE proc; END IF; @@ -73956,14 +75161,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setNextState` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setNextState`(vSelf INT) BEGIN @@ -73983,7 +75188,7 @@ BEGIN FROM state WHERE id = vStateFk; - INSERT INTO ticketTracking(stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) VALUES (vNewStateFk, vSelf, account.myUser_getId()); END ;; DELIMITER ; @@ -74047,14 +75252,14 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setPreviousState` */; /*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setPreviousState`(vTicketFk INT) BEGIN @@ -74079,7 +75284,7 @@ BEGIN ORDER BY id DESC LIMIT 1; - INSERT INTO ticketTracking(stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) SELECT s.nextStateFk, tt.ticketFk, account.myUser_getId() FROM ticketTracking tt JOIN vn.state s ON tt.stateFk = s.id @@ -74127,14 +75332,14 @@ BEGIN ORDER BY tt.created DESC LIMIT 1; - SELECT id INTO vPackedAlertLevel FROM alertLevel WHERE code = 'PACKED'; + SELECT id INTO vPackedAlertLevel FROM alertLevel WHERE code = 'PACKED'; IF vStateCode = 'OK' AND vZoneFk IS NULL THEN CALL util.throw('ASSIGN_ZONE_FIRST'); END IF; SET vCanChangeState = ( - vStateCode <> 'ON_CHECKING' OR + vStateCode <> 'ON_CHECKING' OR vticketAlertLevel < vPackedAlertLevel )AND NOT ( vTicketStateCode IN ('CHECKED', 'CHECKING') @@ -74142,11 +75347,11 @@ BEGIN ); IF vCanChangeState THEN - INSERT INTO ticketTracking (stateFk, ticketFk, workerFk) + INSERT INTO ticketTracking (stateFk, ticketFk, userFk) SELECT id, vSelf, account.myUser_getId() FROM state WHERE `code` = vStateCode COLLATE utf8_unicode_ci; - + IF vStateCode = 'PACKED' THEN CALL ticket_doCmr(vSelf); END IF; @@ -74186,40 +75391,40 @@ proc:BEGIN SELECT COUNT(*) INTO vProblemLines FROM tmp.salesToSplit WHERE ticketFk = vTicketFk; - + SELECT count(*) INTO vTotalLines - FROM vn.sale s + FROM vn.sale s WHERE s.ticketFk = vTicketFk; - + SET vHasFullProblem = (vTotalLines = vProblemLines); -- Ticket completo IF vHasFullProblem THEN - + UPDATE vn.ticket SET landed = vDated + INTERVAL 1 DAY, shipped = vDated, nickname = CONCAT('(',DAY(util.VN_CURDATE()),') ', nickname ) WHERE id = vTicketFk; - + SELECT CONCAT("Se ha cambiado el ticket ", vTicketFk, " al dia ", vDated); LEAVE proc; - + END IF; -- Ticket a futuro existe IF vTicketFutureFk THEN - - UPDATE vn.sale s + + UPDATE vn.sale s JOIN tmp.salesToSplit ss ON s.id = ss.saleFk SET s.ticketFk = vTicketFutureFk, s.concept = CONCAT('(s) ', s.concept) WHERE ss.ticketFk = vTicketFk; - - SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, + + SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, " al ticket existente ", vTicketFutureFk,"(", vDated,")"); LEAVE proc; - + END IF; -- Ticket nuevo @@ -74231,18 +75436,18 @@ proc:BEGIN t.landed = vDated + INTERVAL 1 DAY, t.shipped = vDated, t.agencyModeFk = pc.defautlAgencyMode, - t.zoneFk = pc.defaultZone + t.zoneFk = pc.defaultZone WHERE t.id = vTicketFutureFk; - - UPDATE vn.sale s - JOIN tmp.salesToSplit sts ON sts.saleFk = s.id + + UPDATE vn.sale s + JOIN tmp.salesToSplit sts ON sts.saleFk = s.id SET s.ticketFk = vTicketFutureFk, s.concept = CONCAT('(s) ', s.concept) WHERE sts.ticketFk = vTicketFk; CALL vn.ticketStateUpdate(vTicketFutureFk, 'FIXING'); - SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, + SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, " al nuevo ticket ", vTicketFutureFk,"(", vDated,")"); END ;; DELIMITER ; @@ -74351,7 +75556,7 @@ proc:BEGIN SELECT itemPackingTypeFk INTO vItemPackingTypeFk FROM tmp.saleGroup sg WHERE NOT ISNULL(sg.itemPackingTypeFk) - ORDER BY sg.totalLitros + ORDER BY sg.itemPackingTypeFk LIMIT 1; UPDATE vn.sale s @@ -74381,43 +75586,43 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_splitPackingComplete`(vTicketFk INT, vSectorFk INT) BEGIN - + DECLARE vNeedToSplit BOOLEAN; DECLARE vNewTicketFk INT; - + DROP TEMPORARY TABLE IF EXISTS tmpSale; - + CREATE TEMPORARY TABLE tmpSale SELECT DISTINCT s.id - FROM vn.ticket t + FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk + JOIN vn.item i ON i.id = s.itemFk LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = vSectorFk - JOIN vn.packagingConfig pc + JOIN vn.packagingConfig pc WHERE t.id = vTicketFk AND ( s.quantity MOD IFNULL(iss.packing,1) != 0 - OR + OR IFNULL(iss.packing,1) = 1 - OR + OR i.`size` <= pc.previousPreparationMinimumSize ); - - SELECT COUNT(*) + + SELECT COUNT(*) INTO vNeedToSplit - FROM tmpSale; - + FROM tmpSale; + IF vNeedToSplit THEN - + CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); - + UPDATE vn.sale s - JOIN vn.tmpSale ts ON ts.id = s.id + JOIN vn.tmpSale ts ON ts.id = s.id SET s.ticketFk = vNewTicketFk; - + END IF; - + DROP TEMPORARY TABLE tmpSale; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74448,7 +75653,7 @@ BEGIN WHERE ot.description = 'Peso Aduana' AND t.clientFk = vClientFk AND t.shipped BETWEEN vDated AND util.dayend(vDated); - + SELECT sum(IF(sv.physicalWeight = 0, sv.weight, sv.physicalWeight)) INTO vTheorycalWeight FROM vn.ticket t JOIN vn.sale s ON s.ticketFk = t.id @@ -74457,9 +75662,9 @@ BEGIN JOIN vn.itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk WHERE t.clientFk = vClientFk AND t.shipped BETWEEN vDated AND util.dayend(vDated); - + SET vRatio = vRealWeight / vTheorycalWeight; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketWeight; CREATE TEMPORARY TABLE tmp.ticketWeight @@ -74480,7 +75685,7 @@ BEGIN AND t.shipped BETWEEN vDated AND util.dayend(vDated) GROUP BY ib.ediBotanic, o.code; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74599,18 +75804,18 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateAll`(vDatedFr BEGIN /** - * @param vDatedFrom Fecha desde + * @param vDatedFrom Fecha desde * @param vDatedTo Fecha hasta */ - CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` SELECT w.id userFk FROM vn.worker w; - + CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74630,21 +75835,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /** - * @param vDepartmentFk + * @param vDepartmentFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT DISTINCT b.workerFk userFk - FROM business AS b - WHERE (b.started BETWEEN vDatedFrom AND vDatedTo + FROM business AS b + WHERE (b.started BETWEEN vDatedFrom AND vDatedTo OR IFNULL(b.ended, vDatedTo) BETWEEN vDatedFrom AND vDatedTo OR (b.started <= vDatedFrom AND b.ended >= vDatedTo) ) AND b.departmentFk = vDepartmentFk ORDER BY b.ended DESC; - + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; @@ -74669,19 +75874,19 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByUser`(vUser BEGIN /** - * @param vUserFk + * @param vUserFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ - + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk - FROM account.user - WHERE id = vUserFk; + FROM account.user + WHERE id = vUserFk; CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); - + DROP TEMPORARY TABLE tmp.`user`; END ;; @@ -74708,14 +75913,14 @@ BEGIN * @param vDatedFrom Fecha desde * @param vDatedTo Fecha hasta */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` SELECT w.id userFk FROM worker w WHERE w.id = vWorkerFk; - + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); - + DROP TEMPORARY TABLE tmp.`user`; END ;; @@ -74725,32 +75930,32 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_calculate` */; /*!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 = utf8mb3 */ ; -/*!50003 SET character_set_results = utf8mb3 */ ; -/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculate`( - vDatedFrom DATETIME, + vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /* * Agrupa por trabajador y día, el tiempo de trabajo y descanso retribuido(si tiene). * Los registros horarios incorrectos (tmp.timeControlError) no se considerarán. - * Si un trabajador ha trabajado más de un cierto umbral de tiempo (vTimeToBreakTime) - * y no ha tenido descansos que superen un parámetro determinado(vMaxTimeToBreak), + * Si un trabajador ha trabajado más de un cierto umbral de tiempo (vTimeToBreakTime) + * y no ha tenido descansos que superen un parámetro determinado(vMaxTimeToBreak), * se le añadirá un tiempo de descanso (vBreakTime) a sus horas trabajadas. * El tiempo de descanso solo se añade si el trabajador realmente disfrutó del descanso. * Si disfrutó de menos tiempo de descanso, solo se añade el tiempo que disfrutó. - * + * * @param vDatedFrom - * @param vDatedTo + * @param vDatedTo * - * @return tmp.timeControlCalculate + * @return tmp.timeControlCalculate * (workerFk, dated, timeWorkSeconds, timeWorkSexagesimal, timeWorkDecimal, timed) */ DECLARE vHourSeconds INTEGER; @@ -74882,7 +76087,7 @@ BEGIN ), accumulated AS ( SELECT SUM(IF(isOdd, 0, gapTime)) OVER (PARTITION BY userFk,dated ORDER BY userFk,timed) accumulatedWorkTime, - SUM(IF(NOT isOdd OR breakPoint, 0, IFNULL(gapTime, 0))) + SUM(IF(NOT isOdd OR breakPoint OR gapTime >= vMaxTimeToBreak OR gapTime IS NULL, 0, gapTime)) OVER (PARTITION BY realDay ORDER BY realDay,timed) accumulatedBreakTime, IF(realDay <> @oldrealDay OR (isOdd AND gapTime >= vMaxTimeToBreak), @accumulatedForBreakTime := 0, @@ -74897,7 +76102,7 @@ BEGIN SELECT userFk, dated, MAX(accumulatedWorkTime) + - IF(MAX(accumulatedForBreakTime) >= vTimeToBreakTime, + IF(MAX(accumulatedForBreakTime) + LEAST(vBreakTime, MAX(accumulatedBreakTime)) >= vTimeToBreakTime, LEAST(vBreakTime, MAX(accumulatedBreakTime)), 0) timeWorkSeconds FROM accumulated @@ -74949,14 +76154,14 @@ BEGIN * @param vDatedTo Fecha hasta */ - CREATE OR REPLACE TEMPORARY TABLE tmp.`user` + CREATE OR REPLACE TEMPORARY TABLE tmp.`user` SELECT w.id userFk FROM vn.worker w; - + CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74976,21 +76181,21 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN /** - * @param vDepartmentFk + * @param vDepartmentFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT DISTINCT b.workerFk userFk - FROM business AS b - WHERE (b.started BETWEEN vDatedFrom AND vDatedTo + FROM business AS b + WHERE (b.started BETWEEN vDatedFrom AND vDatedTo OR IFNULL(b.ended, vDatedTo) BETWEEN vDatedFrom AND vDatedTo OR (b.started <= vDatedFrom AND b.ended >= vDatedTo) ) AND b.departmentFk = vDepartmentFk ORDER BY b.ended DESC; - + CALL timeControl_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; @@ -75015,19 +76220,19 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByUser`(vUserF BEGIN /** - * @param vUserFk + * @param vUserFk * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl */ - + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; - + CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk - FROM account.user - WHERE id = vUserFk; + FROM account.user + WHERE id = vUserFk; CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); - + DROP TEMPORARY TABLE tmp.`user`; END ;; @@ -75085,12 +76290,12 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_getError`(vDatedFrom DA BEGIN /* * @param vDatedFrom - * @param vDatedTo + * @param vDatedTo * @table tmp.`user`(userFk) * Fichadas incorrectas de las cuales no se puede calcular horas trabajadas * @return tmp.timeControlError (id) */ - DECLARE vDayMaxTime INTEGER; + DECLARE vDayMaxTime INTEGER; SET @journeyCounter := 0; SET @lastUserFk := NULL; @@ -75098,16 +76303,16 @@ BEGIN SELECT dayMaxTime INTO vDayMaxTime FROM workerTimeControlConfig LIMIT 1; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; - CREATE TEMPORARY TABLE tmp.timeControl + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; + CREATE TEMPORARY TABLE tmp.timeControl (INDEX(id), INDEX(journeyCounter)) ENGINE = MEMORY SELECT sub.id, - sub.direction, + sub.direction, sub.timed, IF(sub.direction = 'in' OR @hasOut OR sub.userFk <> @lastUserFk, @journeyCounter := @journeyCounter + 1, @journeyCounter) journeyCounter, - @lastUserFk := sub.userFk workerFk, - IF(sub.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE) + @lastUserFk := sub.userFk workerFk, + IF(sub.direction = 'out', @hasOut:= TRUE, @hasOut:= FALSE) FROM ( SELECT DISTINCT wtc.id, wtc.direction, @@ -75118,36 +76323,36 @@ BEGIN WHERE wtc.timed BETWEEN DATE_SUB(vDatedFrom, INTERVAL 1 DAY) AND DATE_ADD(vDatedTo, INTERVAL 1 DAY) ORDER BY wtc.userFk, wtc.timed ) sub; - - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; CREATE TEMPORARY TABLE tmp.timeControlAux (INDEX(id), INDEX(journeyCounter)) ENGINE = MEMORY SELECT * FROM tmp.timeControl; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlError; - CREATE TEMPORARY TABLE tmp.timeControlError + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlError; + CREATE TEMPORARY TABLE tmp.timeControlError (INDEX(id)) ENGINE = MEMORY - SELECT id + SELECT id FROM tmp.timeControlAux tca JOIN ( - SELECT journeyCounter, + SELECT journeyCounter, UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork, - SUM(direction = 'in') totalIn, + SUM(direction = 'in') totalIn, SUM(direction = 'out') totalOut, timed FROM tmp.timeControl GROUP BY journeyCounter - HAVING COUNT(*) MOD 2 = 1 - OR totalIn <> 1 - OR totalOut <> 1 + HAVING COUNT(*) MOD 2 = 1 + OR totalIn <> 1 + OR totalOut <> 1 OR timeWork >= vDayMaxTime )sub ON sub.journeyCounter = tca.journeyCounter WHERE sub.timed BETWEEN vDatedFrom AND vDatedTo; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75170,7 +76375,7 @@ proc: BEGIN * deprecated call workerTimeControl_check */ CALL vn.workerTimeControl_check(vUserFk,vDated,vTabletFk); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75226,12 +76431,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travelVolume`(vTravelFk INT) BEGIN - - SELECT w1.name AS ORI, - w2.name AS DES, + + SELECT w1.name AS ORI, + w2.name AS DES, tr.shipped shipment, tr.landed landing, - a.name Agencia, + a.name Agencia, s.name Proveedor, e.id Id_Entrada, e.invoiceNumber Referencia, @@ -75239,18 +76444,18 @@ BEGIN vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) AS CC, CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * vn.item_getVolume(b.itemFk ,b.packagingFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) AS espais - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.travel tr ON tr.id = e.travelFk + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.travel tr ON tr.id = e.travelFk JOIN vn.agencyMode a ON a.id = tr.agencyModeFk - JOIN vn.warehouse w1 ON w1.id = tr.warehouseInFk - JOIN vn.warehouse w2 ON w2.id = tr.warehouseOutFk - JOIN vn.volumeConfig vc - JOIN vn.item i ON i.id = b.itemFk + JOIN vn.warehouse w1 ON w1.id = tr.warehouseInFk + JOIN vn.warehouse w2 ON w2.id = tr.warehouseOutFk + JOIN vn.volumeConfig vc + JOIN vn.item i ON i.id = b.itemFk JOIN vn.itemType it ON it.id = i.typeFk WHERE tr.id = vTravelFk; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75306,11 +76511,11 @@ BEGIN * @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 IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75374,7 +76579,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_checkWarehouseIsFeedStock`(v proc: BEGIN /* * Check that the warehouse is not Feed Stock - * + * * @vWarehouseFk param warehouse id */ IF vWarehouseFk IS NULL THEN @@ -75462,13 +76667,13 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_cloneWithEntries`( - IN vTravelFk INT, - IN vDateStart DATE, + IN vTravelFk INT, + IN vDateStart DATE, IN vDateEnd DATE, IN vWarehouseOutFk INT, - IN vWarehouseInFk INT, - IN vRef VARCHAR(255), - IN vAgencyModeFk INT, + IN vWarehouseInFk INT, + IN vRef VARCHAR(255), + IN vAgencyModeFk INT, OUT vNewTravelFk INT) BEGIN /** @@ -75492,29 +76697,29 @@ BEGIN FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.travelFk = vTravelFk; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN + BEGIN ROLLBACK; RESIGNAL; END; - + START TRANSACTION; INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk FROM travel WHERE id = vTravelFk; - + SET vNewTravelFk = LAST_INSERT_ID(); SET vDone = FALSE; SET @isModeInventory = TRUE; OPEN vRsEntry; - + l: LOOP SET vDone = FALSE; FETCH vRsEntry INTO vAuxEntryFk; @@ -75556,36 +76761,36 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_doRecalc`() -proc: BEGIN -/** -* Recounts the number of entries of changed travels. -*/ - DECLARE vTravelFk INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('vn.ticket_doRecalc'); - END; - - IF !GET_LOCK('vn.travel_doRecalc', 0) THEN - LEAVE proc; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tTravel - ENGINE = MEMORY - SELECT travelFk FROM travelRecalc; - - UPDATE travel t - JOIN tTravel tt ON tt.travelFk = t.id - SET t.totalEntries = ( - SELECT COUNT(e.id) - FROM entry e - WHERE e.travelFk = t.id - ); - - DELETE tr FROM travelRecalc tr JOIN tTravel t ON tr.travelFk = t.travelFk; - DROP TEMPORARY TABLE tTravel; - DO RELEASE_LOCK('vn.travel_doRecalc'); +proc: BEGIN +/** +* Recounts the number of entries of changed travels. +*/ + DECLARE vTravelFk INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.ticket_doRecalc'); + END; + + IF !GET_LOCK('vn.travel_doRecalc', 0) THEN + LEAVE proc; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tTravel + ENGINE = MEMORY + SELECT travelFk FROM travelRecalc; + + UPDATE travel t + JOIN tTravel tt ON tt.travelFk = t.id + SET t.totalEntries = ( + SELECT COUNT(e.id) + FROM entry e + WHERE e.travelFk = t.id + ); + + DELETE tr FROM travelRecalc tr JOIN tTravel t ON tr.travelFk = t.travelFk; + DROP TEMPORARY TABLE tTravel; + DO RELEASE_LOCK('vn.travel_doRecalc'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75612,10 +76817,10 @@ BEGIN WHERE id = vSelf; SELECT e.id entryFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - JOIN buy b ON b.entryFk = e.id - WHERE t.id = vTravelFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + JOIN buy b ON b.entryFk = e.id + WHERE t.id = vTravelFk AND (b.packing IS NULL OR b.packagingFk IS NULL); END ;; DELIMITER ; @@ -75638,7 +76843,7 @@ BEGIN /* * Desplaza al dia siguiente los travels que contengan redadas y avisa a los compradores - * + * */ DECLARE vDone BOOL DEFAULT FALSE; DECLARE vWorkerName VARCHAR(50); @@ -75650,7 +76855,7 @@ BEGIN SELECT GROUP_CONCAT( DISTINCT CONCAT('https://salix.verdnatura.es/#!/travel/', ttr.id, '/summary ') ORDER BY ttr.id SEPARATOR '\n\r'), u.name FROM tmp.travel ttr - JOIN entry e ON e.travelFk = ttr.id + JOIN entry e ON e.travelFk = ttr.id JOIN buy b ON b.entryFk = e.id JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk @@ -75658,19 +76863,19 @@ BEGIN GROUP BY u.name; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; RESIGNAL; END; - + DROP TEMPORARY TABLE IF EXISTS tmp.travel; CREATE TEMPORARY TABLE tmp.travel SELECT tr.id,tr.landed FROM travel tr - JOIN entry e ON e.travelFk = tr.id + JOIN entry e ON e.travelFk = tr.id WHERE tr.landed = util.tomorrow() AND e.isRaid GROUP BY tr.id; @@ -75728,7 +76933,7 @@ proc: BEGIN IF vSelf IS NULL THEN LEAVE proc; END IF; - + INSERT IGNORE INTO travelRecalc SET travelFk = vSelf; END ;; DELIMITER ; @@ -75738,6 +76943,100 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `travel_upcomingArrivals` */; +/*!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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_upcomingArrivals`( + vWarehouseFk INT, + vDate DATETIME +) +BEGIN +/** + * Procedure to track and organize the movement of items between warehouses, + * where 'warehouseINFk' is @vWarehouseFk. + * Uses temporary tables to process and store the travel data of the items. + * + * @params vWarehouseFk warehouse id + * @params vDate selected landed date + * @return tmp.itemTravel + */ + DECLARE vTravelFk INT; + DECLARE vWarehouseOutFk INT; + DECLARE vShipment DATETIME; + DECLARE vDateStart DATETIME; + + CREATE OR REPLACE TEMPORARY TABLE tTravelTop + (PRIMARY KEY (wh_in,wh_out,landing,shipment)) + ENGINE = MEMORY + SELECT 0 id, + vWarehouseFk wh_in, + vWarehouseFk wh_out, + FALSE ok, + vDate landing, + vDate shipment; + + REPEAT + SET vTravelFk = NULL; + + SELECT id, + wh_out, + shipment, + landing + INTO vTravelFk, + vWarehouseOutFk, + vShipment, + vDateStart + FROM tTravelTop + WHERE ok = FALSE LIMIT 1; + + UPDATE tTravelTop + SET ok = TRUE + WHERE id = vTravelFk; + + INSERT IGNORE INTO tTravelTop + SELECT id, + vWarehouseFk, + warehouseOutFk, + FALSE, + IF(vTravelFk, vDateStart, landed), + shipped shipment + FROM travel + WHERE warehouseOutFk = vWarehouseOutFk + AND IF(vTravelFk, landed <= vShipment, landed >= vShipment) + AND shipped >= util.VN_CURDATE() + AND NOT isDelivered; + UNTIL vTravelFk IS NULL END REPEAT; + + DELETE FROM tTravelTop WHERE id = 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemTravel + (KEY (wh)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT wh_out wh, + landing + FROM tTravelTop + WHERE wh_out <> vWarehouseFk + ORDER BY landing + LIMIT 10000000000000000000 + ) t + GROUP BY wh; + + DROP TEMPORARY TABLE tTravelTop; +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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_updatePacking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75754,10 +77053,10 @@ BEGIN * @param vItemFk id del item * @param vPacking nuevo packing */ - + DECLARE vAuctionWarehouseFk INT; DECLARE vMainWarehouseFk INT; - + SELECT warehouseFk INTO vAuctionWarehouseFk FROM auctionConfig; @@ -75817,7 +77116,7 @@ BEGIN FROM travelClonedWeekly WHERE travelFk; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; SET vCounter = vSinceWeek; @@ -75879,12 +77178,12 @@ BEGIN /* * Plantilla para modificar reemplazar todos los tags * por los valores que tienen los articulos - * + * * @param vTypeFk tipo a modificar - * + * */ - DELETE it.* - FROM itemTag it + DELETE it.* + FROM itemTag it JOIN item i ON i.id = it.itemFk WHERE i.typeFk = vTypeFk; @@ -75893,40 +77192,40 @@ BEGIN FROM item i JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci WHERE i.typeFk = vTypeFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, i.category, 5 FROM item i JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci WHERE i.typeFk = vTypeFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, ink.name, 2 FROM item i JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci JOIN ink ON ink.id = i.inkFk WHERE i.typeFk = vTypeFk; - + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, p.name, 3 FROM item i JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci JOIN producer p ON p.id = i.producerFk - WHERE i.typeFk = vTypeFk; - + WHERE i.typeFk = vTypeFk; + INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, o.name, 4 FROM item i JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci JOIN origin o ON o.id = i.originFk WHERE i.typeFk = vTypeFk; - /* + /* INSERT INTO itemTag(itemFk, tagFk, value, priority) SELECT i.id, t.id, i.stems, 6 FROM item i JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci - WHERE i.typeFk = vTypeFk; - */ + WHERE i.typeFk = vTypeFk; + */ -- CALL itemTagArrangedUpdate(NULL); END ;; @@ -75949,7 +77248,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `updatePedidosInternos`(vItemFk INT) BEGIN UPDATE vn.item SET upToDown = 0 WHERE item.id = vItemFk; - + END ;; DELIMITER ; @@ -75977,7 +77276,7 @@ BEGIN SELECT vp.regex INTO vRegex FROM vehiclePlateRegex vp WHERE vp.countryCodeFk = vCountryCodeFk; - + IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN CALL util.throw(CONCAT('Error: la matricula ', vNumberPlate, ' no es valida para ',vCountryCodeFk)); END IF; @@ -76010,7 +77309,7 @@ proc:BEGIN ROLLBACK; RESIGNAL; END; - + SELECT eventEarlyDays INTO vEventEarlyDays FROM vehicleConfig; @@ -76028,7 +77327,7 @@ proc:BEGIN IF NOT vHasEvents THEN LEAVE proc; END IF; - + START TRANSACTION; SELECT util.notification_send('vehicle-event-expired', @@ -76063,21 +77362,21 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_getMisfit`(vSectorFk INT) BEGIN - + /* Devuelve una tabla temporal con los descuadres entre el visible teórico y lo ubicado en la práctica - * + * * @param vSectorFk Identificador de vn.sector - * + * * @return tmp.stockMisfit(itemFk, visible, parked) */ - + DECLARE vCalcVisibleFk INT; DECLARE vWarehouseFk INT; SELECT warehouseFk INTO vWarehouseFk - FROM vn.sector s + FROM vn.sector s WHERE s.id = vSectorFk; - + CALL cache.visible_refresh(vCalcVisibleFk, FALSE, vWarehouseFk); DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; @@ -76090,17 +77389,17 @@ BEGIN INSERT INTO tmp.stockMisfit(itemFk, parked) SELECT iss.itemFk , sum(iss.visible ) - FROM vn.itemShelvingStock iss - JOIN vn.sector s ON s.id = iss.sectorFk + FROM vn.itemShelvingStock iss + JOIN vn.sector s ON s.id = iss.sectorFk WHERE vSectorFk IN (s.id, s.sonFk) GROUP BY iss.itemFk; - + INSERT INTO tmp.stockMisfit(itemFk, visible) - SELECT v.item_id , v.visible - FROM cache.visible v - WHERE v.calc_id = vCalcVisibleFk + SELECT v.item_id , v.visible + FROM cache.visible v + WHERE v.calc_id = vCalcVisibleFk ON DUPLICATE KEY UPDATE visible = v.visible; - + DELETE FROM tmp.stockMisfit WHERE visible = parked; @@ -76124,17 +77423,17 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `warehouseFitting`(IN vWhOrigin INT BEGIN DECLARE vCacheVisibleOriginFk INT; DECLARE vCacheVisibleDestinyFk INT; - + CALL cache.visible_refresh(vCacheVisibleOriginFk, FALSE, vWhOrigin); CALL cache.visible_refresh(vCacheVisibleDestinyFk, FALSE, vWhDestiny); - + SELECT i.id itemFk, i.longName, i.size, i.subName, vOrigin.visible AS Origen, vDestiny.visible Destino - + FROM vn.item i JOIN vn.itemType it ON it.id = i.typeFk LEFT JOIN cache.visible vOrigin ON vOrigin.calc_id = vCacheVisibleOriginFk AND vOrigin.item_id = i.id @@ -76163,13 +77462,13 @@ BEGIN DECLARE vWhOrigin INT; DECLARE vWhDestiny INT; - + SELECT warehouseInFk, warehouseOutFk INTO vWhDestiny, vWhOrigin FROM vn.travel WHERE id = vTravelFk; - + CALL vn.warehouseFitting(vWhOrigin, vWhDestiny); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76233,7 +77532,7 @@ BEGIN * Calcula los días y horas de vacaciones en función de un contrato y año * * @param vYear - * @param vBusinessFk + * @param vBusinessFk * @return tmp.workerCalendarCalculateBusiness (days, hours, daysEnjoyed, hoursEnjoyed) */ DECLARE vStarted DATE; @@ -76245,17 +77544,17 @@ BEGIN DECLARE vPayedHolidays DECIMAL(5,2); DECLARE vDifDays INT; - SELECT IF(b.started < CONCAT(vYear,"-01-01"), CONCAT(vYear,"-01-01"),b.started), - IF(b.ended IS NULL OR YEAR(b.ended)>vYear , CONCAT(vYear,"-12-31"), b.ended), + SELECT IF(b.started < CONCAT(vYear,"-01-01"), CONCAT(vYear,"-01-01"),b.started), + IF(b.ended IS NULL OR YEAR(b.ended)>vYear , CONCAT(vYear,"-12-31"), b.ended), IF(wbt.hasHolidayEntitlement, w.days, 0), c.hoursWeek, IF(YEAR(b.ended) = vYear, b.payedHolidays, 0) payedHolidays - INTO vStarted, - vEnded, - vDaysHoliday, + INTO vStarted, + vEnded, + vDaysHoliday, vHoursWeek, vPayedHolidays - FROM business b + FROM business b JOIN workerBusinessType wbt ON wbt.id = b.workerBusinessTypeFk JOIN workCenterHoliday w ON w.workcenterFk = b.workcenterFk LEFT JOIN calendarType c ON c.id = b.calendarTypeFk @@ -76263,23 +77562,23 @@ BEGIN AND w.year = vYear; DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateBusiness; - + IF vStarted < vEnded THEN SET vDifDays = DAYOFYEAR(vEnded) - DAYOFYEAR(vStarted) + 1; - SELECT IFNULL(SUM(a.holidayEntitlementRate), 0), + SELECT IFNULL(SUM(a.holidayEntitlementRate), 0), SUM(-(a.discountRate - 1)) + vPayedHolidays - INTO vDaysToSubtract, - vDaysHolidayEnjoyed + INTO vDaysToSubtract, + vDaysHolidayEnjoyed FROM calendar c JOIN absenceType a ON a.id = c.dayOffTypeFk JOIN business b ON b.id = c.businessFk - WHERE b.id = vBusinessFk + WHERE b.id = vBusinessFk AND YEAR(c.dated) = vYear; END IF; - CREATE TEMPORARY TABLE tmp.workerCalendarCalculateBusiness + CREATE TEMPORARY TABLE tmp.workerCalendarCalculateBusiness ENGINE = MEMORY SELECT @days := IFNULL(ROUND((vDaysHoliday * (vDifDays - vDaysToSubtract) / IF(util.isLeapYear(vYear) , 366, 365)), 1), 0) days, @days * (vHoursWeek / 5) hours, @@ -76307,32 +77606,32 @@ BEGIN /** * Calcula los días y horas de vacaciones en función de un trabajador y año * - * @param vYear - * @param vWorkerFk + * @param vYear + * @param vWorkerFk * @return tmp.workerCalendarCalculateYear (days, hours, daysEnjoyed, hoursEnjoyed) - */ + */ DECLARE vDone BOOL; DECLARE vBusinessFk INT; DECLARE cur CURSOR FOR - SELECT b.id + SELECT b.id FROM business b - WHERE vYear BETWEEN YEAR(b.started) AND IFNULL(YEAR(b.ended), vYear) + WHERE vYear BETWEEN YEAR(b.started) AND IFNULL(YEAR(b.ended), vYear) AND b.workerFk = vWorkerFk; DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - + SET vDone = TRUE; + DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateYear; CREATE TEMPORARY TABLE tmp.workerCalendarCalculateYear - (days DEC(5,2), + (days DEC(5,2), hours DEC(5,2), - daysEnjoyed DEC(5,2), - hoursEnjoyed DEC(5,2)) + daysEnjoyed DEC(5,2), + hoursEnjoyed DEC(5,2)) ENGINE = MEMORY; INSERT INTO tmp.workerCalendarCalculateYear VALUES(0, 0, 0, 0); - + OPEN cur; l: LOOP @@ -76345,12 +77644,12 @@ BEGIN CALL workerCalendar_calculateBusiness(vYear, vBusinessFk); UPDATE tmp.workerCalendarCalculateYear w - JOIN tmp.workerCalendarCalculateBusiness wc + JOIN tmp.workerCalendarCalculateBusiness wc SET w.days = w.days + wc.days, w.hours = w.hours + wc.hours, w.daysEnjoyed = w.daysEnjoyed + wc.daysEnjoyed, w.hoursEnjoyed = w.hoursEnjoyed + wc.hoursEnjoyed; - + DROP TEMPORARY TABLE tmp.workerCalendarCalculateBusiness; END LOOP; @@ -76421,20 +77720,20 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.workerDepartmentByDate; CREATE TEMPORARY TABLE tmp.workerDepartmentByDate ENGINE = MEMORY - SELECT w.id userFk, - w.lastName name, - w.firstName firstname, - d.name department, + SELECT w.id userFk, + w.lastName name, + w.firstName firstname, + d.name department, d.id departmentFk, - b.started, - d.isProduction, + b.started, + d.isProduction, CAST(12 * b.amount / ct.hoursWeek / 52 AS DECIMAL(10,2)) costeHora, w.fi nif FROM business b JOIN calendarType ct ON ct.id = b.calendarTypeFk JOIN department d ON d.id = b.departmentFk JOIN worker w ON w.id = b.workerFk - WHERE b.started <= vDate + WHERE b.started <= vDate AND (b.ended > vDate OR b.ended IS NULL); END ;; DELIMITER ; @@ -76458,21 +77757,26 @@ mainLabel:BEGIN IF (SELECT COUNT(*) FROM workerDisableExcluded WHERE workerFk = vUserId AND (dated > util.VN_CURDATE() OR dated IS NULL)) > 0 THEN LEAVE mainLabel; END IF; + + DELETE cp FROM clientProtected cp + JOIN client c ON c.id = cp.clientFk + WHERE c.salesPersonFk = vUserId; + DELETE FROM account.account WHERE id = vUserId; - UPDATE account.user + UPDATE account.user SET role = 2 - WHERE id = vUserId; + WHERE id = vUserId; - DELETE FROM pbx.sip - WHERE user_id = vUserId; + DELETE FROM pbx.sip + WHERE user_id = vUserId; UPDATE `client` c JOIN payMethod p ON p.name = 'CONTADO' SET c.credit = 0, c.payMethodFk = p.id, hasCoreVnl = FALSE WHERE c.id = vUserId; - + UPDATE `client` c SET c.salesPersonFk = null WHERE c.salesPersonFk = vUserId; @@ -76501,12 +77805,12 @@ BEGIN SELECT b.workerFk FROM business b JOIN vn.worker w ON w.id = b.workerFk - JOIN account.account a ON a.id = b.workerFk - LEFT JOIN (SELECT b.workerFk + JOIN account.account a ON a.id = b.workerFk + LEFT JOIN (SELECT b.workerFk FROM business b WHERE (ended IS NULL OR ended >=util.VN_CURDATE()) )sub ON sub.workerFk = a.id - LEFT JOIN vn.workerDisableExcluded wd ON wd.workerFk = b.workerFk + LEFT JOIN vn.workerDisableExcluded wd ON wd.workerFk = b.workerFk WHERE sub.workerFk IS NULL AND wd.workerFk IS NULL GROUP BY w.id; @@ -76524,7 +77828,7 @@ BEGIN END WHILE; CLOSE rs; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76588,19 +77892,19 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace`( - vDatedFrom DATE, - vDatedTo DATE, + vDatedFrom DATE, + vDatedTo DATE, vWorkerFk INT) BEGIN /** - * Actualiza la tabla workerJourney para que actue como caché permanente revisable + * Actualiza la tabla workerJourney para que actue como caché permanente revisable * de las jornadas laborales. * @param vDatedFrom workerTimeControl * @param vDatedTo workerTimeControl * @param vWorkerFk, en caso de pasar 0 ó NULL se aplica a todos - */ + */ DECLARE vDatedTimeTo DATETIME; - DECLARE vMaxTimePerDay INT; + DECLARE vMaxTimePerDay INT; DECLARE vMinHoursToBreak DECIMAL(10,2); DECLARE vBreakHours DECIMAL(10,2); DECLARE vMonthByYear INT; @@ -76608,57 +77912,57 @@ BEGIN DECLARE vMonthsByYear INT DEFAULT 12; DECLARE vDaysByWeek INT DEFAULT 5; DECLARE vDatedFromYesterday DATETIME; - DECLARE vDatedToTomorrow DATETIME; - - SELECT DATE_SUB(vDatedFrom, INTERVAL 1 DAY), DATE_ADD(vDatedTo, INTERVAL 1 DAY) + DECLARE vDatedToTomorrow DATETIME; + + SELECT DATE_SUB(vDatedFrom, INTERVAL 1 DAY), DATE_ADD(vDatedTo, INTERVAL 1 DAY) INTO vDatedFromYesterday, vDatedToTomorrow; SET vDatedTimeTo = util.dayEnd(vDatedTo); - - SELECT minHoursToBreak, breakHours, maxTimePerDay + + SELECT minHoursToBreak, breakHours, maxTimePerDay INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay FROM workerTimeControlConfig; DELETE FROM workerJourney - WHERE dated BETWEEN vDatedFrom AND vDatedTo + WHERE dated BETWEEN vDatedFrom AND vDatedTo AND NOT isPaid AND NOT isUpdated - AND (vWorkerFk IS NULL OR userFK = vWorkerFk); + AND (vWorkerFk IS NULL OR userFK = vWorkerFk); - -- Se inserta todos los días del periodo por worker y business en el rango de fechas. + -- Se inserta todos los días del periodo por worker y business en el rango de fechas. INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) SELECT b.workerFk, t.dated, b.id - FROM business b + FROM business b JOIN time t ON t.dated BETWEEN b.started AND IFNULL(b.ended,util.VN_CURDATE()) WHERE t.dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR b.workerFk = vWorkerFk) ORDER BY b.workerFk, t.dated, b.id; - + DROP TEMPORARY TABLE IF EXISTS tmp.`user`; IF vWorkerFk THEN CALL timeControl_calculateByUser(vWorkerFk, vDatedFrom , vDatedTimeTo); - CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` - SELECT vWorkerFk userFk; + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` + SELECT vWorkerFk userFk; ELSE CALL timeControl_calculateAll(vDatedFrom, vDatedTimeTo); - CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` + CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT id userFk FROM worker w; - END IF; + END IF; UPDATE workerJourney wj JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk - SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, - t.timeWorkDecimal - vBreakHours, + SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, + t.timeWorkDecimal - vBreakHours, t.timeWorkDecimal) AS DECIMAL (10,2)), wj.lunch = IF(t.timeWorkDecimal >= vMinHoursToBreak , vBreakHours , 0) WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo AND NOT wj.isPaid AND NOT wj.isUpdated AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk); - - -- NOCTURNIDAD + + -- NOCTURNIDAD CALL timeControl_getError(vDatedFrom, vDatedTimeTo); SET @vIsOdd := TRUE; @@ -76668,9 +77972,9 @@ BEGIN CREATE TEMPORARY TABLE tmp.workerTimeControl (INDEX (userFk), INDEX (timed)) ENGINE = MEMORY - SELECT DISTINCT(wtc.id), - wtc.userFk, - wtc.timed, + SELECT DISTINCT(wtc.id), + wtc.userFk, + wtc.timed, wtc.direction FROM workerTimeControl wtc JOIN tmp.`user` w ON w.userFk = wtc.userFk @@ -76680,10 +77984,10 @@ BEGIN AND (vWorkerFk IS NULL OR wtc.userFk = vWorkerFk) ORDER BY wtc.userFk, wtc.timed ASC; - SELECT MAX(id) INTO @vCont + SELECT MAX(id) INTO @vCont FROM tmp.workerTimeControl; - DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlAux; + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlAux; CREATE TEMPORARY TABLE tmp.workerTimeControlAux ( `id` int(11) , `userFk` int(10) unsigned , @@ -76705,9 +78009,9 @@ BEGIN DATE(@lastTimed) dated, @lastUserFk lastUserFk, IF(direction ='middle', @vIsOdd := NOT @vIsOdd, FALSE) isOdd, - IF(@vIsOdd - AND @lastDirection = 'middle' - AND (DATE(@lastTimed) <> date(timed) + IF(@vIsOdd + AND @lastDirection = 'middle' + AND (DATE(@lastTimed) <> date(timed) OR @lastUserFk <> userFk), TRUE, FALSE) hasBreak, @lastTimed := wtc.timed, @lastUserFk := userFk, @@ -76721,16 +78025,16 @@ BEGIN SET @lastDirection := NULL; INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) - SELECT @vCont:= @vCont + 1, - lastUserFk, - DATE_ADD(sub.dated, INTERVAL 1 DAY), + SELECT @vCont:= @vCont + 1, + lastUserFk, + DATE_ADD(sub.dated, INTERVAL 1 DAY), 'middle' FROM (SELECT IF(@lastUserFk <> userFk, @vIsOdd := TRUE, NULL), DATE(@lastTimed) dated, @lastUserFk lastUserFk, IF(direction ='middle', @vIsOdd := NOT @vIsOdd, FALSE) isOdd, - IF(@vIsOdd - AND @lastDirection = 'middle' + IF(@vIsOdd + AND @lastDirection = 'middle' AND (DATE(@lastTimed)<>date(timed) OR @lastUserFk<>userFk), TRUE, FALSE) hasBreak, @lastTimed := wtc.timed, @@ -76743,7 +78047,7 @@ BEGIN -- Cambio de dia INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) SELECT @vCont:= @vCont + 1, - wtc.userFk, + wtc.userFk, util.dayEnd(date(wtc.timed)), 'out' FROM workerTimeControl wtc @@ -76754,8 +78058,8 @@ BEGIN GROUP BY wtc.userFk, DATE(wtc.timed); INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) - SELECT @vCont:= @vCont + 1, - wtc.userFk, + SELECT @vCont:= @vCont + 1, + wtc.userFk, DATE_ADD(date(wtc.timed), INTERVAL 1 DAY), 'in' FROM workerTimeControl wtc @@ -76781,8 +78085,8 @@ BEGIN IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed), IF(direction='in', @vDated := DATE(wtc.timed), @vDated ) dated, wtc.userFk, - IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay, - workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed), + IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay, + workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed), 0) NigthlyHours, @lastUserFk := userFk FROM (SELECT DISTINCT(wtc.id), wtc.userFk, wtc.timed, wtc.direction @@ -76795,7 +78099,7 @@ BEGIN ) wtc ORDER BY wtc.userFk, wtc.timed )sub - WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo + WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo GROUP BY userFk, sub.dated )night ON night.userFk = wj.userFk AND night.dated = wj.dated SET wj.nocturn = night.NigthlyHours @@ -76807,8 +78111,8 @@ BEGIN UPDATE workerJourney wj JOIN business b ON b.id = wj.businessFk JOIN calendarType ct ON ct.id = b.calendarTypeFk - SET wj.priceOrdinaryHour = - (vMonthsByYear * b.amount) / + SET wj.priceOrdinaryHour = + (vMonthsByYear * b.amount) / (vWeeksByYear * ct.hoursWeek), wj.contractJourney = ct.hoursWeek / vDaysByWeek WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo @@ -76816,7 +78120,7 @@ BEGIN AND NOT wj.isPaid AND NOT isUpdated; - -- Precio Extras, Vacaciones y Nocturnas + -- Precio Extras, Vacaciones y Nocturnas UPDATE workerJourney wj JOIN(SELECT MAX(w.dated), t.dated, w.holidayInc, w.nightInc, w.extraInc FROM time t @@ -76840,12 +78144,12 @@ BEGIN WHERE ct.isPartial AND wj.dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid + AND NOT wj.isPaid AND NOT wj.isUpdated; -- Ausencias UPDATE workerJourney wj - JOIN businessCalendar bc ON bc.businessFk = wj.businessFk + JOIN businessCalendar bc ON bc.businessFk = wj.businessFk AND bc.dated = wj.dated JOIN absenceType ab ON ab.id = bc.absenceTypeFk SET wj.permission = ab.permissionRate * wj.contractJourney, @@ -76860,7 +78164,7 @@ BEGIN UPDATE workerJourney SET holiday = IF(DAYNAME(dated)='sábado', 0, total), contractJourney = 0 - WHERE DAYNAME(dated) IN ('sábado', 'domingo') + WHERE DAYNAME(dated) IN ('sábado', 'domingo') AND dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR userFk = vWorkerFk) AND NOT isPaid @@ -76869,8 +78173,8 @@ BEGIN -- Festivos por centro de trabajo UPDATE workerJourney wj JOIN calendarHolidays ch ON ch.dated = wj.dated - JOIN business b ON b.id = wj.businessFk - AND b.workcenterFk = ch.workcenterFk + JOIN business b ON b.id = wj.businessFk + AND b.workcenterFk = ch.workcenterFk SET wj.holiday = wj.total, wj.permission = wj.contractJourney, wj.contractJourney = 0 @@ -76880,7 +78184,7 @@ BEGIN AND NOT wj.isUpdated; -- Horas extras - UPDATE workerJourney + UPDATE workerJourney SET extra = lunch + total - contractJourney WHERE dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR userFk = vWorkerFk) @@ -76910,15 +78214,15 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerMistakeType_get`() BEGIN - + /** * Obtiene los tipos de error para los trabajadores */ - - SELECT code, description - FROM workerMistakeType + + SELECT code, description + FROM workerMistakeType ORDER BY description; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76945,7 +78249,7 @@ BEGIN * */ INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk) - VALUES(vWorkerFk, vWorkerMistakeTypeFk); + VALUES(vWorkerFk, vWorkerMistakeTypeFk); END ;; DELIMITER ; @@ -76968,11 +78272,11 @@ BEGIN /*INSERT INTO workerTimeControl(userFk, timed, manual, warehouseFk) VALUES(vUserFk, vDated, FALSE, vWarehouseFk); - + CALL vn.workerTimeControlSOWP(vUserFk , vDated);*/ - + CALL vn.workerTimeControl_add(vUserFk,vWarehouseFk,util.VN_NOW(),FALSE); - + END ;; DELIMITER ; @@ -76998,8 +78302,8 @@ BEGIN * */ - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -77048,13 +78352,13 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlSOWP`(IN vUserFk INT, IN vDated DATE) BEGIN SET @order := 0; - - UPDATE workerTimeControl - SET `order` = @order := @order + 1 - WHERE vUserFk =userFk + + UPDATE workerTimeControl + SET `order` = @order := @order + 1 + WHERE vUserFk =userFk AND vDated = DATE(timed) ORDER BY timed; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -77073,8 +78377,8 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) BEGIN - - + + SELECT workerTimeControl_add(vUserFk,vWarehouseFk,vTimed,vIsManual); END ;; DELIMITER ; @@ -77162,73 +78466,73 @@ proc: BEGIN DECLARE vTo VARCHAR(50) DEFAULT NULL; DECLARE vUserName VARCHAR(50) DEFAULT NULL; DECLARE vBody VARCHAR(255) DEFAULT NULL; - - SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax + + SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax FROM workerTimeControlParams; SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk + FROM workerTimeControl + WHERE userFk = vUserFk AND direction = 'in'; - + SELECT MAX(timed) INTO vLastOut - FROM workerTimeControl - WHERE userFk = vUserFk - AND direction = 'out'; + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'out'; SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo FROM account.user u - WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); - + WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); + SELECT CONCAT(firstName,' ',lastName) INTO vUserName FROM worker w WHERE w.id = vUserFk; IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA - - -- VERIFICAR DESCANSO DIARIO - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN + + -- VERIFICAR DESCANSO DIARIO + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN SELECT "Descansos 12 h" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 12 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; - END IF; - + END IF; + -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ - IF (SELECT MOD(COUNT(*),2) -- <>0 - FROM workerTimeControl + IF (SELECT MOD(COUNT(*),2) -- <>0 + FROM workerTimeControl WHERE userFk = vUserFk AND timed >= vLastIn - ) THEN + ) THEN SELECT "Dias con fichadas impares" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; - + -- VERIFICAR VACACIONES SELECT at2.name INTO vCalendarStateType - FROM calendar c + FROM calendar c JOIN business b ON b.id = c.businessFk JOIN absenceType at2 ON at2.id = c.dayOffTypeFk WHERE c.dated = util.VN_CURDATE() AND at2.isAllowedToWork = FALSE AND b.workerFk = vUserFk LIMIT 1; - + IF(LENGTH(vCalendarStateType)) THEN SELECT vCalendarStateType AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - + LEAVE proc; + END IF; - + -- VERIFICAR CONTRATO EN VIGOR IF (SELECT COUNT(*) FROM business b @@ -77240,44 +78544,44 @@ proc: BEGIN -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - + LEAVE proc; + END IF; -- VERIFICAR DESCANSO SEMANAL SET @vHasBreakWeek:= FALSE; - SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); - + SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); + DROP TEMPORARY TABLE IF EXISTS tmp.trash; CREATE TEMPORARY TABLE tmp.trash SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, @vLastTimed:= UNIX_TIMESTAMP(timed) - FROM workerTimeControl + FROM workerTimeControl WHERE timed>= (util.VN_NOW() - INTERVAL vWeekScope SECOND) AND userFk= vUserFk AND direction IN ('in','out') - ORDER BY timed ASC; - - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA + ORDER BY timed ASC; + + IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA SELECT "Descansos 36 h" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 36 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; END IF; + + DROP TEMPORARY TABLE tmp.trash; - DROP TEMPORARY TABLE tmp.trash; - - ELSE -- DIA ACTUAL - + ELSE -- DIA ACTUAL + -- VERIFICA QUE EL TIEMPO EFECTIVO NO SUPERE EL MÁXIMO - SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked + SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked FROM workerTimeControl wtc - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND timed >= vLastIn ORDER BY timed; - IF vTimedWorked > vDayWorkMax THEN + IF vTimedWorked > vDayWorkMax THEN SELECT "Jornadas" AS problem; -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Jornadas") INTO vBody; @@ -77300,10 +78604,10 @@ proc: BEGIN -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; END IF;*/ - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -77323,7 +78627,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_checkBreak`(vStarted DATE) BEGIN /** - * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas * El sistema verificará el descanso corto en la siguiente semana * o el largo en las 2 siguientes semanas a partir de la fecha dada * @param vStarted día inicio de la semana en el que se quiere verificar @@ -77334,27 +78638,27 @@ BEGIN DECLARE vShortWeekBreak INT; DECLARE vLongWeekBreak INT; - SELECT util.dayEnd(DATE_ADD(vStarted, INTERVAL shortWeekDays DAY)), + SELECT util.dayEnd(DATE_ADD(vStarted, INTERVAL shortWeekDays DAY)), util.dayEnd(DATE_ADD(vStarted, INTERVAL longWeekDays DAY)), - shortWeekBreak, + shortWeekBreak, longWeekBreak INTO vShortEnded, vLongEnded, vShortWeekBreak, vLongWeekBreak FROM workerTimeControlConfig; - + SET @previousTimed:= UNIX_TIMESTAMP(vStarted); SET @lastUserFk := NULL; - + -- Descanso corto en la semana - + DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY(workerFk)) ENGINE = MEMORY SELECT DISTINCT userFk workerFk - FROM workerTimeControl + FROM workerTimeControl WHERE timed BETWEEN vStarted AND vShortEnded AND direction IN ('in', 'out'); - + DROP TEMPORARY TABLE IF EXISTS tmp.worker2; CREATE TEMPORARY TABLE tmp.worker2 (PRIMARY KEY(workerFk)) @@ -77367,28 +78671,28 @@ BEGIN SELECT sub2.userFk workerFk FROM(SELECT sub.userFk, IF(sub.userFk <> @lastUserFk, - @previousTimed:= sub.timed, + @previousTimed:= sub.timed, FALSE), - IF(sub.timed - @previousTimed >= vShortWeekBreak, - TRUE, + IF(sub.timed - @previousTimed >= vShortWeekBreak, + TRUE, FALSE) hasShortWeekBreak, @previousTimed:= sub.timed, @lastUserFk:= sub.userFk FROM ( SELECT userFk, UNIX_TIMESTAMP(timed) timed - FROM workerTimeControl + FROM workerTimeControl WHERE timed BETWEEN vStarted AND vShortEnded AND direction IN ('in', 'out') - UNION + UNION SELECT w.workerFk, UNIX_TIMESTAMP(IFNULL( - MIN(wtc.timed), + MIN(wtc.timed), DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND))) FROM tmp.worker w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND wtc.timed BETWEEN vShortEnded - AND DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN vShortEnded + AND DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND) GROUP BY w.workerFk UNION SELECT w.workerFk, @@ -77396,10 +78700,10 @@ BEGIN MAX(wtc.timed), DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND))) FROM tmp.worker2 w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND wtc.timed BETWEEN - DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN + DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND) AND vStarted GROUP BY w.workerFk ORDER BY userFk, timed @@ -77409,7 +78713,7 @@ BEGIN GROUP BY sub2.userFk HAVING NOT SUM(hasShortWeekBreak); - -- Descanso largo en las 2 siguientes semanas + -- Descanso largo en las 2 siguientes semanas DROP TEMPORARY TABLE tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY(workerFk)) @@ -77429,12 +78733,12 @@ BEGIN (PRIMARY KEY(workerFk)) ENGINE = MEMORY SELECT sub2.userFk workerFk - FROM(SELECT userFk, + FROM(SELECT userFk, IF(userFk <> @lastUserFk, - @previousTimed:= timed, + @previousTimed:= timed, TRUE), - IF(timed - @previousTimed >= vLongWeekBreak, - TRUE, + IF(timed - @previousTimed >= vLongWeekBreak, + TRUE, FALSE) hasLongWeekBreak, @previousTimed:= timed, @lastUserFk:= userFk @@ -77443,24 +78747,24 @@ BEGIN JOIN tmp.workerWithoutShortWeekBreak wws ON wws.workerFk = wtc.userFk WHERE timed BETWEEN vStarted AND vLongEnded AND direction IN ('in', 'out') - UNION + UNION SELECT w.workerFk, - UNIX_TIMESTAMP(IFNULL(MIN(wtc.timed), + UNIX_TIMESTAMP(IFNULL(MIN(wtc.timed), DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND))) FROM tmp.worker w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND timed BETWEEN vLongEnded - AND DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN vLongEnded + AND DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND) GROUP BY w.workerFk UNION - SELECT w.workerFk, - UNIX_TIMESTAMP(IFNULL(MAX(wtc.timed), + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL(MAX(wtc.timed), DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND))) FROM tmp.worker2 w - LEFT JOIN workerTimeControl wtc - ON wtc.userFk = w.workerFk - AND timed BETWEEN DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND) + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND) AND vStarted GROUP BY w.workerFk ORDER BY userFk, timed @@ -77504,14 +78808,14 @@ BEGIN * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá * fichada a la tabla vn.workerTimeControl */ - + DECLARE vLastIn DATETIME; DECLARE vLastOut DATETIME; DECLARE vNextIn DATETIME; DECLARE vNextOut DATETIME; DECLARE vNextDirection ENUM('in', 'out'); DECLARE vLastDirection ENUM('in', 'out'); - DECLARE vDayMaxTime INTEGER; + DECLARE vDayMaxTime INTEGER; DECLARE vDayBreak INT; DECLARE vShortWeekBreak INT; DECLARE vLongWeekBreak INT; @@ -77538,7 +78842,7 @@ BEGIN WHERE w.id = vWorkerFk; SELECT `description` INTO vErrorMessage - FROM workerTimeControlError + FROM workerTimeControlError WHERE `code` = vErrorCode; IF vErrorMessage IS NULL THEN @@ -77550,7 +78854,7 @@ BEGIN ' no ha podido fichar por el siguiente problema: ', vErrorMessage) INTO vErrorMessage; - + CALL mail_insert( vMailTo, vMailTo, 'Error al fichar', vErrorMessage); END; @@ -77583,19 +78887,19 @@ BEGIN JOIN workerTimeControlConfig wc WHERE b.workerFk = vWorkerFk AND vDated BETWEEN b.started AND IFNULL(b.ended, vDated); - + -- CONTRATO EN VIGOR IF vDayBreak IS NULL THEN SET vErrorCode = 'INACTIVE_BUSINESS'; CALL util.throw(vErrorCode); END IF; - + -- FICHADAS A FUTURO IF vTimed > util.VN_NOW() + INTERVAL 1 MINUTE THEN SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE'; CALL util.throw(vErrorCode); END IF; - + -- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR CALL timeBusiness_calculateByWorker(vWorkerFk, vDated, vDated); SELECT isAllowedToWork INTO vIsAllowedToWork @@ -77622,7 +78926,7 @@ BEGIN ) THEN SET vIsError = TRUE; END IF; - + DROP TEMPORARY TABLE tmp.workerTimeControlDirection; IF vIsError THEN SET vErrorCode = 'WRONG_DIRECTION'; @@ -77637,7 +78941,7 @@ BEGIN AND timed < vTimed ORDER BY timed DESC LIMIT 1; - + IF (SELECT IF(vDirection = 'in', MOD(COUNT(*), 2) , IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE)) @@ -77648,7 +78952,7 @@ BEGIN SET vErrorCode = 'ODD_WORKERTIMECONTROL'; CALL util.throw(vErrorCode); END IF; - + -- DESCANSO DIARIO SELECT timed INTO vLastOut FROM workerTimeControl @@ -77657,7 +78961,7 @@ BEGIN AND timed < vTimed ORDER BY timed DESC LIMIT 1; - + SELECT timed INTO vNextIn FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77665,7 +78969,7 @@ BEGIN AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + CASE vDirection WHEN 'in' THEN IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN @@ -77687,7 +78991,7 @@ BEGIN IF (vDirection IN('in', 'out')) THEN -- VERIFICA MAXIMO TIEMPO DESDE ENTRADA HASTA LA SALIDA - + SELECT timed INTO vNextOut FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77695,7 +78999,7 @@ BEGIN AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + SELECT direction INTO vNextDirection FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77703,7 +79007,7 @@ BEGIN AND timed > vTimed ORDER BY timed ASC LIMIT 1; - + SELECT direction INTO vLastDirection FROM workerTimeControl WHERE userFk = vWorkerFk @@ -77711,34 +79015,34 @@ BEGIN AND timed < vTimed ORDER BY timed ASC LIMIT 1; - - IF (vDirection ='in' - AND vNextDirection = 'out' + + IF (vDirection ='in' + AND vNextDirection = 'out' AND UNIX_TIMESTAMP(vNextOut) - UNIX_TIMESTAMP(vTimed) > vDayMaxTime) OR - (vDirection ='out' + (vDirection ='out' AND vLastDirection = 'in' AND UNIX_TIMESTAMP(vTimed) -UNIX_TIMESTAMP(vLastIn) > vDayMaxTime) THEN SET vErrorCode = 'DAY_MAX_TIME'; CALL util.throw(vErrorCode); END IF; - + -- VERIFICA DESCANSO SEMANAL - + WITH wtc AS( - (SELECT timed - FROM vn.workerTimeControl + (SELECT timed + FROM vn.workerTimeControl WHERE userFk = vWorkerFk AND direction IN ('in', 'out') - AND timed BETWEEN vTimed - INTERVAL (vWeekScope * 2) SECOND + AND timed BETWEEN vTimed - INTERVAL (vWeekScope * 2) SECOND AND vTimed + INTERVAL (vWeekScope * 2) SECOND ) - UNION + UNION (SELECT vTimed) ), wtcGap AS( SELECT timed, - TIMESTAMPDIFF(SECOND, LAG(timed) OVER (ORDER BY timed), timed) gap + TIMESTAMPDIFF(SECOND, LAG(timed) OVER (ORDER BY timed), timed) gap FROM wtc ORDER BY timed - ), wtcBreak AS( + ), wtcBreak AS( SELECT timed, IF(IFNULL(gap, 0) > vShortWeekBreak, TRUE, FALSE) hasShortBreak, IF(IFNULL(gap, 0) > vLongWeekBreak, TRUE, FALSE) hasLongBreak @@ -77749,21 +79053,21 @@ BEGIN SUM(hasShortBreak) OVER (ORDER BY timed) breakCounter , LEAD(hasLongBreak) OVER (ORDER BY timed) nextHasLongBreak FROM wtcBreak - )SELECT TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed)) > vMaxWorkLongCycle OR - (TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed))> vMaxWorkShortCycle + )SELECT TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed)) > vMaxWorkLongCycle OR + (TIMESTAMPDIFF(SECOND, MIN(timed), MAX(timed))> vMaxWorkShortCycle AND NOT SUM(IFNULL(nextHasLongBreak, 1))) hasError INTO vIsError FROM wtcBreakCounter GROUP BY breakCounter HAVING hasError LIMIT 1; - + IF vIsError THEN SET vErrorCode = 'BREAK_WEEK'; CALL util.throw(vErrorCode); END IF; END IF; - + -- SE PERMITE FICHAR INSERT INTO workerTimeControl(userFk, timed, direction, `manual`) VALUES(vWorkerFk, vTimed, vDirection, vIsManual); @@ -77792,27 +79096,27 @@ BEGIN * Devuelve que direcciones de fichadas son lógicas a partir de la anterior fichada * @param vWorkerFk Identificador del trabajador * @return (option1, option2) - * Los valores posibles de retorno son ('in', 'inMiddle', 'outMiddle', 'out') + * Los valores posibles de retorno son ('in', 'inMiddle', 'outMiddle', 'out') */ DECLARE vLastIn DATETIME ; DECLARE vIsMiddleOdd BOOLEAN ; - IF (vTimed IS NULL) THEN + IF (vTimed IS NULL) THEN SET vTimed = util.VN_NOW(); END IF; - + SELECT timed INTO vLastIn - FROM workerTimeControl + FROM workerTimeControl WHERE userFk = vWorkerFk - AND direction = 'in' + AND direction = 'in' AND timed < vTimed ORDER BY timed DESC LIMIT 1; - + SELECT (COUNT(*)mod 2 = 1) INTO vIsMiddleOdd - FROM workerTimeControl + FROM workerTimeControl WHERE userFk = vWorkerFk - AND direction = 'middle' + AND direction = 'middle' AND timed BETWEEN vLastIn AND util.VN_NOW(); DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlDirection; @@ -77861,7 +79165,7 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_getClockIn`( - vUserFk INT, + vUserFk INT, vDated DATE) BEGIN /** @@ -77871,9 +79175,9 @@ BEGIN * @param vDated Fecha proporcionada */ CALL timeControl_calculateByWorker( - vUserFk, + vUserFk, DATE_SUB(vDated, INTERVAL 6 DAY), util.dayEnd(vDated)); - + SET @position := 0; SET @lastDated := NULL; @@ -77890,7 +79194,7 @@ BEGIN MAX(2daysAgoDirection) 2daysAgoDirection, MAX(1daysAgo) 1daysAgo, MAX(1daysAgoDirection) 1daysAgoDirection, - MAX(0daysAgo) 0daysAgo, + MAX(0daysAgo) 0daysAgo, MAX(0daysAgoDirection) 0daysAgoDirection FROM(SELECT IF(daysAgo = 6, timed, '') 6daysAgo, IF(daysAgo = 5, timed, '') 5daysAgo, @@ -77910,7 +79214,7 @@ BEGIN direction, position FROM(SELECT DATEDIFF(vDated, timed) daysAgo, - TIME_FORMAT(timed,'%H:%i') timed, + TIME_FORMAT(timed,'%H:%i') timed, IF(DATE(timed) <> @lastDated, @position := 0, NULL), @position := @position+1 position, @lastDated := DATE(timed), @@ -77922,18 +79226,18 @@ BEGIN LIMIT 10000000000000000000 )sub )sub2 - GROUP BY position) sub3 + GROUP BY position) sub3 JOIN (SELECT MAX(IF(daysAgo = 6, timeWorkSeconds, 0)) 6daysAgoTotal, MAX(IF(daysAgo = 5, timeWorkSeconds, 0)) 5daysAgoTotal, MAX(IF(daysAgo = 4, timeWorkSeconds, 0)) 4daysAgoTotal, MAX(IF(daysAgo = 3, timeWorkSeconds, 0)) 3daysAgoTotal, MAX(IF(daysAgo = 2, timeWorkSeconds, 0)) 2daysAgoTotal, MAX(IF(daysAgo = 1, timeWorkSeconds, 0)) 1daysAgoTotal, - MAX(IF(daysAgo = 0, timeWorkSeconds, 0)) 0daysAgoTotal + MAX(IF(daysAgo = 0, timeWorkSeconds, 0)) 0daysAgoTotal FROM (SELECT DATEDIFF(vDated, dated) daysAgo, timeWorkSeconds FROM tmp.timeControlCalculate) sub4)sub5 ON TRUE; - + DROP TEMPORARY TABLE tmp.timeControlCalculate; END ;; DELIMITER ; @@ -77997,45 +79301,45 @@ BEGIN DECLARE vDirectionPrevious VARCHAR(6); DECLARE vTimedPrevious DATETIME; - SELECT direction INTO vDirectionRemove - FROM vn.workerTimeControl - WHERE userFk = vUserFk + SELECT direction INTO vDirectionRemove + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND timed = vTimed ; IF vDirectionRemove = 'out' THEN - + SELECT timed, direction INTO vTimedPrevious, vDirectionPrevious - FROM vn.workerTimeControl - WHERE userFk = vUserFk + FROM vn.workerTimeControl + WHERE userFk = vUserFk AND timed < vTimed ORDER BY timed DESC - LIMIT 1; - + LIMIT 1; + IF vDirectionPrevious = "middle" THEN - UPDATE vn.workerTimeControl + UPDATE vn.workerTimeControl SET direction = "out" WHERE userFk = vUserFk AND timed = vTimedPrevious; END IF; - + ELSE IF vDirectionRemove = 'in' THEN - UPDATE vn.workerTimeControl + UPDATE vn.workerTimeControl SET direction = "in" WHERE userFk = vUserFk AND timed > vTimed ORDER BY timed ASC - LIMIT 1; + LIMIT 1; END IF; - + END IF; - + DELETE FROM vn.workerTimeControl - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND timed = vTimed; - + CALL vn.workerTimeControlSOWP(vUserFk, vTimed); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78063,31 +79367,31 @@ proc: BEGIN UPDATE vn.workerTimeControl SET direction = 'middle'; /*2- poner los out*/ -UPDATE vn.workerTimeControl wtc - JOIN +UPDATE vn.workerTimeControl wtc + JOIN (SELECT userFk,MAX(timed) maxTimed FROM (SELECT id, userFk, timed, date(timed) dated - FROM vn.workerTimeControl - ) sub + FROM vn.workerTimeControl + ) sub GROUP BY userFk,dated )sub SET direction = "out" - WHERE wtc.userFk = sub.userFk + WHERE wtc.userFk = sub.userFk AND wtc.timed = sub.maxTimed; - - /*3- poner los in*/ -UPDATE vn.workerTimeControl wtc - JOIN + + /*3- poner los in*/ +UPDATE vn.workerTimeControl wtc + JOIN (SELECT userFk,MIN(timed) maxTimed FROM (SELECT id, userFk, timed, date(timed) dated - FROM vn.workerTimeControl - ) sub + FROM vn.workerTimeControl + ) sub GROUP BY userFk,dated )sub SET direction = "in" - WHERE wtc.userFk = sub.userFk - AND wtc.timed = sub.maxTimed ; - + WHERE wtc.userFk = sub.userFk + AND wtc.timed = sub.maxTimed ; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78160,7 +79464,7 @@ BEGIN AND w.businessFk GROUP BY tm.userFk,t.dated ORDER BY tm.userFk,t.dated; - + INSERT INTO vn.mail (receiver, replyTo, subject, body) SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', WEEK(vDatedFrom), ' año ', YEAR(vDatedFrom)) , CONCAT(' @@ -78252,7 +79556,7 @@ BEGIN IF (DAYNAME(util.VN_CURDATE()) = 'miércoles') THEN SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL 9 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(), INTERVAL 3 DAY), ' 23:59:59') INTO vDatedFrom, vDatedTo; - + CALL vn.workerTimeControl_sendMailByDepartment(vDatedFrom, vDatedTo, NULL); END IF; END ;; @@ -78302,9 +79606,9 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_weekCheckBreak`(vStarted DATE, vEnded DATE) BEGIN /** - * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas - * El sistema verificará el descanso corto en la siguiente semana - * o el largo en las 2 siguientes semanas a partir de las fechas dadas + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * El sistema verificará el descanso corto en la siguiente semana + * o el largo en las 2 siguientes semanas a partir de las fechas dadas * @param vStarted día inicio para verificar * @param vEnded día final para verificar * @return tmp.workerWithoutWeekBreak (workerFk) @@ -78326,10 +79630,10 @@ BEGIN CALL workerTimeControl_checkBreak(vStarted); INSERT IGNORE INTO tmp.workerWithoutWeekBreakInWeek - SELECT workerFk + SELECT workerFk FROM tmp.workerWithoutWeekBreak; DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreak; - SET vStarted = DATE_ADD(vStarted, INTERVAL 1 DAY); + SET vStarted = DATE_ADD(vStarted, INTERVAL 1 DAY); END WHILE; END ;; @@ -78367,7 +79671,7 @@ BEGIN DECLARE vDepartmentFk INT; DECLARE isEnabled BOOLEAN DEFAULT TRUE; - SELECT COUNT(*) INTO vHasSignedToday + SELECT COUNT(*) INTO vHasSignedToday FROM workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; SET @day := 0; @@ -78380,16 +79684,16 @@ BEGIN SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas FROM ( - SELECT @lastTimed fichada_anterior, + SELECT @lastTimed fichada_anterior, timed, CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, IF(day(timed) != @day, 1, 0) as jornadas, @day := day(timed) dia_del_mes, - @lastTimed := timed fichada_actual + @lastTimed := timed fichada_actual FROM ( SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed - FROM + FROM (SELECT TIMESTAMPADD(DAY, -11, util.VN_NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior UNION ALL SELECT timed, userFk @@ -78397,18 +79701,18 @@ BEGIN WHERE userFk = vUserFk AND timed >= TIMESTAMPADD(DAY, -10,vDated) UNION ALL - SELECT IF(vHasSignedToday, '2000-01-01 00:00', util.VN_NOW()) as timed, vUserFk + SELECT IF(vHasSignedToday, '2000-01-01 00:00', util.VN_NOW()) as timed, vUserFk ) sub4 ORDER BY timed ) sub - + ) sub2 WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) ) sub3 ; SELECT IFNULL(SUM(impar),0) into vImpares FROM ( - SELECT day(timed) as dayNumber, + SELECT day(timed) as dayNumber, count(*) mod 2 as impar FROM vn.workerTimeControl wtc WHERE userFk = vUserFk @@ -78425,29 +79729,29 @@ BEGIN AND at2.isAllowedToWork = FALSE AND b.workerFk = vUserFk LIMIT 1; - + -- Contrato en vigor SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork FROM business b WHERE b.workerFk = vUserFk AND b.started <= vDated AND IFNULL(b.ended, vDated) >= vDated; - + -- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) IF vTabletFk <> '0' THEN -- 1 Obtener el departamento del usuario SELECT wtcu.departmentFk INTO vDepartmentFk FROM workerTimeControlUserInfo wtcu WHERE wtcu.userFk = vUserFk; - -- 2 Comprobar si la tablet pertenece al departamento + -- 2 Comprobar si la tablet pertenece al departamento SELECT COUNT(td.tabletFk) INTO isEnabled FROM tabletDepartment td WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; - + END IF; - + IF vJornadas IS NOT NULL THEN - + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis UNION ALL SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis @@ -78456,9 +79760,9 @@ BEGIN UNION ALL SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis UNION ALL - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, - '' as Cantidad, - IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, + IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis UNION ALL SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; @@ -78472,7 +79776,7 @@ BEGIN UNION ALL SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis UNION ALL - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis UNION ALL SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; @@ -78502,11 +79806,11 @@ BEGIN * @param vDepartmentFk id del departamento * */ - - SELECT w.id,w.firstName, w.lastName,d.name - FROM worker w - JOIN workerDepartment wd ON wd.workerFk = w.id - JOIN department d ON d.id = wd.departmentFk + + SELECT w.id,w.firstName, w.lastName,d.name + FROM worker w + JOIN workerDepartment wd ON wd.workerFk = w.id + JOIN department d ON d.id = wd.departmentFk WHERE d.id = vDepartmentFk ORDER BY firstName; @@ -78526,46 +79830,30 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getHierarchy`(vBoss INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getHierarchy`(vUserFk INT) BEGIN - DECLARE EXIT HANDLER FOR 1062 BEGIN - CALL util.throw('INFINITE_LOOP'); - END; - - DROP TEMPORARY TABLE IF EXISTS workerHierarchy; - CREATE TEMPORARY TABLE workerHierarchy +/** + * Retorna una tabla temporal con los trabajadores que tiene + * el usuario por debajo en la jerarquía de la empresa. + * + * @param vUserFk Id de usuario. + * @return tmp.workerHierarchyList + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.workerHierarchyList (PRIMARY KEY (workerFk)) ENGINE = MEMORY - SELECT vBoss AS workerFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.workerHierarchyList; - CREATE TEMPORARY TABLE tmp.workerHierarchyList - (PRIMARY KEY (workerFk)) - ENGINE = MEMORY - SELECT vBoss AS workerFk, 0 AS isChecked; - - - WHILE (SELECT COUNT(*) FROM tmp.workerHierarchyList WHERE NOT isChecked) > 0 DO - - INSERT INTO tmp.workerHierarchyList - SELECT w.id, 0 - FROM worker w - JOIN workerHierarchy wh ON wh.workerFk = w.bossFk; - - UPDATE tmp.workerHierarchyList whl - JOIN workerHierarchy wh ON wh.workerFk = whl.workerFk - SET whl.isChecked = 1; - - TRUNCATE workerHierarchy; - - INSERT INTO workerHierarchy - SELECT workerFk - FROM tmp.workerHierarchyList - WHERE NOT isChecked; - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS workerHierarchy; + WITH RECURSIVE workerHierarchy AS ( + SELECT id workerFk, bossFk, 0 depth + FROM vn.worker + WHERE id = vUserFk + UNION ALL + SELECT w.id, w.bossFk, wh.depth + 1 + FROM vn.worker w + JOIN workerHierarchy wh ON w.bossFk = wh.workerFk + ) + SELECT * + FROM workerHierarchy + ORDER BY depth, workerFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78591,7 +79879,7 @@ BEGIN SELECT s.id,s.description,s.warehouseFk FROM sector s - JOIN operator o ON o.sectorFk = s.id + JOIN operator o ON o.sectorFk = s.id WHERE o.workerFk = account.myUser_getId(); END ;; @@ -78689,8 +79977,8 @@ BEGIN DECLARE vDone BOOL; DECLARE vCursor CURSOR FOR - SELECT DISTINCT b.workerFk - FROM business b + SELECT DISTINCT b.workerFk + FROM business b WHERE b.started > vBusinessUpdated AND b.started <= vCurdate OR b.ended >= vBusinessUpdated AND b.ended < vCurdate; @@ -78733,10 +80021,10 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workingHours`(username varchar(255), logon boolean) BEGIN DECLARE userid int(11); - + SELECT vn.getUserId(username) INTO userid; SELECT username, userid; - IF userid IS NOT NULL THEN + IF userid IS NOT NULL THEN IF (logon) THEN CALL vn.workingHoursTimeIn(userid); ELSE @@ -78805,17 +80093,17 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `wrongEqualizatedClient`() BEGIN SELECT clientFk, c.name, c.isActive, c.isTaxDataChecked, count(ie) as num FROM vn.client c - JOIN + JOIN ( - SELECT DISTINCT + SELECT DISTINCT `a`.`clientFk` , a.isEqualizated = 0 as ie - + FROM `vn`.`address` `a` ) sub ON sub.clientFk = c.id WHERE c.hasToInvoiceByAddress = FALSE - + GROUP BY clientFk HAVING num > 1 UNION ALL @@ -78899,27 +80187,27 @@ proc: BEGIN SELECT scope INTO vScope FROM zoneConfig; - + DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE tmp.zone (INDEX (id)) ENGINE = MEMORY SELECT id FROM zone; - + TRUNCATE TABLE zoneClosure; - + WHILE vCounter <= vScope DO - + CALL zone_getOptionsForShipment(vShipped, TRUE); - + REPLACE zoneClosure(zoneFk, dated, `hour`) - SELECT zoneFk, vShipped, `hour` + SELECT zoneFk, vShipped, `hour` FROM tmp.zoneOption; - + SET vCounter = vCounter + 1; SET vShipped = TIMESTAMPADD(DAY, 1, vShipped); END WHILE; - + -- DROP TEMPORARY TABLE tmp.zone; DO RELEASE_LOCK('vn.zoneClosure_recalc'); END ;; @@ -79013,7 +80301,7 @@ BEGIN OR (vSelf IS NOT NULL AND parentFk = vSelf); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + SET vSons = 0; OPEN vChildren; @@ -79024,11 +80312,11 @@ BEGIN IF vDone THEN LEAVE myLoop; END IF; - + SET vIndex = vIndex + 1; SET vLft = vIndex; SET vSons = vSons + 1; - + CALL zoneGeo_calcTreeRec( vChildFk, CONCAT(vPath, vChildFk, '/'), @@ -79131,7 +80419,7 @@ proc: BEGIN SELECT isChanged INTO vIsChanged FROM zoneGeoRecalc; - + IF vIsChanged THEN UPDATE zoneGeoRecalc SET isChanged = FALSE; CALL vn.zoneGeo_calcTree; @@ -79387,7 +80675,7 @@ proc:BEGIN * @table tmp.closedZones(zoneFk, warehouseFk); */ DROP TEMPORARY TABLE IF EXISTS tmp.closedZones; - + CREATE TEMPORARY TABLE tmp.closedZones ( `zoneFk` int(11) NOT NULL, `warehouseFk` smallint(6) unsigned NOT NULL, @@ -79429,7 +80717,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getCollisions`() BEGIN /** - * Calcula si para un mismo codigo postal y dia + * Calcula si para un mismo codigo postal y dia * hay mas de una zona configurada y manda correo * */ @@ -79438,16 +80726,16 @@ BEGIN DECLARE vIsDone INT DEFAULT FALSE; DECLARE vTableCollisions TEXT; DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE tmp.zone - SELECT z.id + SELECT z.id FROM zone z JOIN agencyMode am ON am.id = z.agencyModeFk JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE dm.code IN ('AGENCY','DELIVERY'); + WHERE dm.code IN ('AGENCY','DELIVERY'); CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE); @@ -79462,7 +80750,7 @@ BEGIN PRIMARY KEY zoneFkk (zoneFk, geoFk), INDEX(geoFk)) ENGINE = MyISAM; - + OPEN cur1; cur1Loop: LOOP SET vIsDone = FALSE; @@ -79470,40 +80758,40 @@ BEGIN IF vIsDone THEN LEAVE cur1Loop; END IF; - + CALL zone_getLeaves(vZoneFk, NULL, NULL, TRUE); - myLoop: LOOP + myLoop: LOOP SET vGeoFk = NULL; - SELECT geoFk INTO vGeoFk + SELECT geoFk INTO vGeoFk FROM tmp.zoneNodes zn WHERE NOT isChecked LIMIT 1; - + IF vGeoFk IS NULL THEN LEAVE myLoop; END IF; - + CALL zone_getLeaves(vZoneFk, vGeoFk, NULL, TRUE); UPDATE tmp.zoneNodes - SET isChecked = TRUE + SET isChecked = TRUE WHERE geoFk = vGeoFk; END LOOP; END LOOP; CLOSE cur1; - DELETE FROM tmp.zoneNodes + DELETE FROM tmp.zoneNodes WHERE sons > 0; - + DROP TEMPORARY TABLE IF EXISTS geoCollision; CREATE TEMPORARY TABLE geoCollision SELECT z.agencyModeFk, zn.geoFk, zw.warehouseFk FROM tmp.zoneNodes zn JOIN zone z ON z.id = zn.zoneFk - JOIN zoneWarehouse zw ON z.id = zw.zoneFk + JOIN zoneWarehouse zw ON z.id = zw.zoneFk GROUP BY z.agencyModeFk, zn.geoFk, zw.warehouseFk HAVING count(*) > 1; - + SELECT ' @@ -79513,39 +80801,39 @@ BEGIN ' INTO vTableCollisions; - - INSERT INTO mail (receiver,replyTo,subject,body) + + INSERT INTO mail (receiver,replyTo,subject,body) SELECT 'pepe@verdnatura.es' receiver, 'noreply@verdnatura.es' replyTo, CONCAT('Colisiones en zonas ', util.VN_CURDATE()) subject, CONCAT(vTableCollisions, GROUP_CONCAT(sub.td SEPARATOR ''), '
C.PostalAlmacén Salix
') body - FROM(SELECT + FROM(SELECT CONCAT(' ', zn.name, ' ', zoneFk,' ', z.price,' ', z.name,' ', w.name, ' - ', CONCAT('' - 'https://salix.verdnatura.es/#!/zone/', + 'https://salix.verdnatura.es/#!/zone/', zoneFk, '/location?q=%7B%22search%22:%22', - zn.name, + zn.name, '%22%7D'),' ') td FROM tmp.zoneNodes zn JOIN zone z ON z.id = zn.zoneFk JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk JOIN warehouse w ON w.id = gc.warehouseFk) sub; - - DROP TEMPORARY TABLE - geoCollision, + + DROP TEMPORARY TABLE + geoCollision, tmp.zone, tmp.zoneNodes; END ;; @@ -79652,18 +80940,18 @@ BEGIN DECLARE vChildFk INT DEFAULT vGeoFk; DECLARE vParentFk INT; DECLARE vLevel INT DEFAULT 1; - + DROP TEMPORARY TABLE IF EXISTS tNodes; CREATE TEMPORARY TABLE tNodes (PRIMARY KEY (id)) ENGINE = MEMORY SELECT vGeoFk id, vLevel `level`; - + myLoop: LOOP SELECT parentFk INTO vParentFk FROM zoneGeo WHERE id = vChildFk; - + SET vChildFk = vParentFk; SET vLevel = vLevel + 1; @@ -79671,7 +80959,7 @@ BEGIN SELECT vChildFk, vLevel FROM DUAL WHERE vChildFk IS NOT NULL; - + IF ROW_COUNT() = 0 THEN LEAVE myLoop; END IF; @@ -79770,126 +81058,126 @@ DELIMITER ; /*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves`( - vSelf INT, - vParentFk INT, - vSearch VARCHAR(255), - vHasInsert BOOL +CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves`( + vSelf INT, + vParentFk INT, + vSearch VARCHAR(255), + vHasInsert BOOL ) -BEGIN -/** - * Devuelve las ubicaciones incluidas en la ruta y que sean hijos de parentFk. - * @param vSelf Id de la zona - * @param vParentFk Id del geo a calcular - * @param vSearch Cadena a buscar - * @param vHasInsert Indica si inserta en tmp.zoneNodes - * Optional @table tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) - */ - DECLARE vIsNumber BOOL; - DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; - - CREATE OR REPLACE TEMPORARY TABLE tNodes - (UNIQUE (id)) - ENGINE = MEMORY - SELECT id - FROM zoneGeo - LIMIT 0; - - IF vIsSearch THEN - SET vIsNumber = vSearch REGEXP '^[0-9]+$'; - - INSERT INTO tNodes - SELECT id - FROM zoneGeo - WHERE (vIsNumber AND `name` = vSearch) - OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) - LIMIT 1000; - - ELSEIF vParentFk IS NULL THEN - INSERT INTO tNodes - SELECT geoFk - FROM zoneIncluded - WHERE zoneFk = vSelf; - END IF; - - IF vParentFk IS NULL THEN - CREATE OR REPLACE TEMPORARY TABLE tChilds - (INDEX(id)) - ENGINE = MEMORY - SELECT id FROM tNodes; - - CREATE OR REPLACE TEMPORARY TABLE tParents - (INDEX(id)) - ENGINE = MEMORY - SELECT id FROM zoneGeo LIMIT 0; - - myLoop: LOOP - DELETE FROM tParents; - INSERT INTO tParents - SELECT parentFk id - FROM zoneGeo g - JOIN tChilds c ON c.id = g.id - WHERE g.parentFk IS NOT NULL; - - INSERT IGNORE INTO tNodes - SELECT id FROM tParents; - - IF NOT ROW_COUNT() THEN - LEAVE myLoop; - END IF; - - DELETE FROM tChilds; - INSERT INTO tChilds - SELECT id FROM tParents; - END LOOP; - - DROP TEMPORARY TABLE tChilds, tParents; - END IF; - - IF NOT vIsSearch THEN - INSERT IGNORE INTO tNodes - SELECT id - FROM zoneGeo - WHERE parentFk <=> vParentFk; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tZones - SELECT g.id, - g.name, - g.parentFk, - g.sons, - NOT g.sons OR `type` = 'country' isChecked, - i.isIncluded selected, - g.`depth`, - vSelf - FROM zoneGeo g - JOIN tNodes n ON n.id = g.id - LEFT JOIN zoneIncluded i ON i.geoFk = g.id - AND i.zoneFk = vSelf - ORDER BY g.`depth`, selected DESC, g.name; - - IF vHasInsert THEN - INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) - SELECT id, - name, - parentFk, - sons, - isChecked, - vSelf - FROM tZones - WHERE selected - OR (selected IS NULL AND vParentFk IS NOT NULL); - ELSE - SELECT id, - name, - parentFk, - sons, - selected - FROM tZones - ORDER BY `depth`, selected DESC, name; - END IF; - - DROP TEMPORARY TABLE tNodes, tZones; +BEGIN +/** + * Devuelve las ubicaciones incluidas en la ruta y que sean hijos de parentFk. + * @param vSelf Id de la zona + * @param vParentFk Id del geo a calcular + * @param vSearch Cadena a buscar + * @param vHasInsert Indica si inserta en tmp.zoneNodes + * Optional @table tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + */ + DECLARE vIsNumber BOOL; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch <> ''; + + CREATE OR REPLACE TEMPORARY TABLE tNodes + (UNIQUE (id)) + ENGINE = MEMORY + SELECT id + FROM zoneGeo + LIMIT 0; + + IF vIsSearch THEN + SET vIsNumber = vSearch REGEXP '^[0-9]+$'; + + INSERT INTO tNodes + SELECT id + FROM zoneGeo + WHERE (vIsNumber AND `name` = vSearch) + OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) + LIMIT 1000; + + ELSEIF vParentFk IS NULL THEN + INSERT INTO tNodes + SELECT geoFk + FROM zoneIncluded + WHERE zoneFk = vSelf; + END IF; + + IF vParentFk IS NULL THEN + CREATE OR REPLACE TEMPORARY TABLE tChilds + (INDEX(id)) + ENGINE = MEMORY + SELECT id FROM tNodes; + + CREATE OR REPLACE TEMPORARY TABLE tParents + (INDEX(id)) + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + myLoop: LOOP + DELETE FROM tParents; + INSERT INTO tParents + SELECT parentFk id + FROM zoneGeo g + JOIN tChilds c ON c.id = g.id + WHERE g.parentFk IS NOT NULL; + + INSERT IGNORE INTO tNodes + SELECT id FROM tParents; + + IF NOT ROW_COUNT() THEN + LEAVE myLoop; + END IF; + + DELETE FROM tChilds; + INSERT INTO tChilds + SELECT id FROM tParents; + END LOOP; + + DROP TEMPORARY TABLE tChilds, tParents; + END IF; + + IF NOT vIsSearch THEN + INSERT IGNORE INTO tNodes + SELECT id + FROM zoneGeo + WHERE parentFk <=> vParentFk; + END IF; + + CREATE OR REPLACE TEMPORARY TABLE tZones + SELECT g.id, + g.name, + g.parentFk, + g.sons, + NOT g.sons OR `type` = 'country' isChecked, + i.isIncluded selected, + g.`depth`, + vSelf + FROM zoneGeo g + JOIN tNodes n ON n.id = g.id + LEFT JOIN zoneIncluded i ON i.geoFk = g.id + AND i.zoneFk = vSelf + ORDER BY g.`depth`, selected DESC, g.name; + + IF vHasInsert THEN + INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + SELECT id, + name, + parentFk, + sons, + isChecked, + vSelf + FROM tZones + WHERE selected + OR (selected IS NULL AND vParentFk IS NOT NULL); + ELSE + SELECT id, + name, + parentFk, + sons, + selected + FROM tZones + ORDER BY `depth`, selected DESC, name; + END IF; + + DROP TEMPORARY TABLE tNodes, tZones; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -79914,7 +81202,7 @@ BEGIN * @table tmp.zone(id) The zones ids * @param vLanded The delivery date * @return tmp.zoneOption The computed options - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; CREATE TEMPORARY TABLE tmp.zoneOption ENGINE = MEMORY @@ -79955,13 +81243,13 @@ BEGIN END LIMIT 10000000000000000000 ) t - GROUP BY zoneFk; - + GROUP BY zoneFk; + DELETE t FROM tmp.zoneOption t JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id WHERE eg.zoneExclusionFk IS NULL; - + IF NOT vShowExpiredZones THEN DELETE FROM tmp.zoneOption WHERE shipped < util.VN_CURDATE() @@ -79993,7 +81281,7 @@ BEGIN * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options */ DECLARE vHour TIME DEFAULT TIME(util.VN_NOW()); - + DROP TEMPORARY TABLE IF EXISTS tLandings; CREATE TEMPORARY TABLE tLandings (INDEX (eventFk)) @@ -80072,48 +81360,48 @@ DELIMITER ; /*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getPostalCode`(vSelf INT) -BEGIN -/** - * Devuelve los códigos postales incluidos en una zona - */ - DECLARE vGeoFk INT DEFAULT NULL; - - CREATE OR REPLACE TEMPORARY TABLE tmp.zoneNodes ( - geoFk INT, - name VARCHAR(100), - parentFk INT, - sons INT, - isChecked BOOL DEFAULT 0, - zoneFk INT, - PRIMARY KEY zoneNodesPk (zoneFk, geoFk), - INDEX(geoFk)) - ENGINE = MEMORY; - - CALL zone_getLeaves(vSelf, NULL , NULL, TRUE); - - UPDATE tmp.zoneNodes - SET isChecked = 0 - WHERE parentFk IS NULL; - - myLoop: LOOP - SET vGeoFk = NULL; - SELECT geoFk INTO vGeoFk - FROM tmp.zoneNodes - WHERE NOT isChecked - LIMIT 1; - - CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE); - UPDATE tmp.zoneNodes - SET isChecked = TRUE - WHERE geoFk = vGeoFk; - - IF vGeoFk IS NULL THEN - LEAVE myLoop; - END IF; - END LOOP; - - DELETE FROM tmp.zoneNodes - WHERE sons > 0; +BEGIN +/** + * Devuelve los códigos postales incluidos en una zona + */ + DECLARE vGeoFk INT DEFAULT NULL; + + CREATE OR REPLACE TEMPORARY TABLE tmp.zoneNodes ( + geoFk INT, + name VARCHAR(100), + parentFk INT, + sons INT, + isChecked BOOL DEFAULT 0, + zoneFk INT, + PRIMARY KEY zoneNodesPk (zoneFk, geoFk), + INDEX(geoFk)) + ENGINE = MEMORY; + + CALL zone_getLeaves(vSelf, NULL , NULL, TRUE); + + UPDATE tmp.zoneNodes + SET isChecked = 0 + WHERE parentFk IS NULL; + + myLoop: LOOP + SET vGeoFk = NULL; + SELECT geoFk INTO vGeoFk + FROM tmp.zoneNodes + WHERE NOT isChecked + LIMIT 1; + + CALL zone_getLeaves(vSelf, vGeoFk, NULL, TRUE); + UPDATE tmp.zoneNodes + SET isChecked = TRUE + WHERE geoFk = vGeoFk; + + IF vGeoFk IS NULL THEN + LEAVE myLoop; + END IF; + END LOOP; + + DELETE FROM tmp.zoneNodes + WHERE sons > 0; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -80144,7 +81432,7 @@ BEGIN DECLARE vZoneGeo INT; SELECT address_getGeo(vAddressFk) INTO vZoneGeo; - + CALL vn.zone_getFromGeo(vZoneGeo); CALL vn.zone_getOptionsForLanding(vLanded, vShowExpiredZones); CALL vn.zone_excludeFromGeo(vZoneGeo); @@ -80164,7 +81452,7 @@ BEGIN FROM tmp.zoneOption zo JOIN vn.zoneWarehouse zw ON zw.zoneFk = zo.zoneFk JOIN vn.`zone` z ON z.id = zo.zoneFk - LEFT JOIN tmp.closedZones cz + LEFT JOIN tmp.closedZones cz ON cz.warehouseFk = zw.warehouseFk AND cz.zoneFk = zw.zoneFk AND zo.shipped = util.VN_CURDATE() @@ -80198,9 +81486,9 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getState`(vDated DATE) BEGIN /** * Devuelve las zonas y el estado para la fecha solicitada - * + * * @param vDated Fecha en cuestión - */ + */ DROP TEMPORARY TABLE IF EXISTS tmp.zone; CREATE TEMPORARY TABLE tmp.zone ( @@ -80214,7 +81502,7 @@ BEGIN CALL vn.zone_getOptionsForShipment(vDated, TRUE); CALL vn.zone_getClosed(); - + SELECT zo.zoneFk, zo.`hour`etd, (zo.`hour` <= TIME(util.VN_NOW())) isLate, @@ -80224,11 +81512,11 @@ BEGIN FROM tmp.zoneOption zo JOIN vn.zone z ON z.id = zo.zoneFk JOIN vn.zoneWarehouse zw ON zw.zoneFk = z.id - LEFT JOIN tmp.closedZones cz - ON cz.warehouseFk = zw.warehouseFk + LEFT JOIN tmp.closedZones cz + ON cz.warehouseFk = zw.warehouseFk AND cz.zoneFk = zo.zoneFk; - - DROP TEMPORARY TABLE + + DROP TEMPORARY TABLE tmp.closedZones, tmp.zoneOption, tmp.zone; @@ -80254,21 +81542,21 @@ BEGIN /** * Devuelve el listado de agencias disponibles para la fecha, * dirección y almacén pasados. - * + * * @param vAddress * @param vWarehouse warehouse * @param vLanded Fecha de recogida * @select Listado de agencias disponibles */ - + CALL zone_getFromGeo(address_getGeo(vAddress)); CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, + + SELECT am.id agencyModeFk, + am.name agencyMode, + am.description, am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, + TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, zw.warehouseFk, z.id zoneFk FROM tmp.zoneOption zo @@ -80278,11 +81566,11 @@ BEGIN WHERE zw.warehouseFk = vWarehouse GROUP BY z.agencyModeFk ORDER BY agencyMode; - + DROP TEMPORARY TABLE tmp.zone, tmp.zoneOption; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -80303,9 +81591,9 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_upcomingDeliveries`() BEGIN DECLARE vForwardDays INT; - + SELECT forwardDays INTO vForwardDays FROM zoneConfig; - CALL util.time_createTable(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); + CALL util.time_generate(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); DROP TEMPORARY TABLE IF EXISTS tLandings; CREATE TEMPORARY TABLE tLandings @@ -80319,7 +81607,7 @@ BEGIN JOIN zoneEvent e ON e.zoneFk = z.id JOIN tmp.time ti ON ti.dated BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY, vForwardDays, util.VN_CURDATE()); - DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; + DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; CREATE TEMPORARY TABLE tmp.zoneOption ENGINE = MEMORY SELECT * @@ -80360,7 +81648,7 @@ BEGIN JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id WHERE eg.zoneExclusionFk IS NULL; - + SELECT MAX(zo.`hour`) `hour`, zg.`name`, zo.shipped, zo.zoneFk FROM tmp.zoneOption zo JOIN `zone` z ON z.id = zo.zoneFk @@ -80371,7 +81659,7 @@ BEGIN WHERE dm.code = 'DELIVERY' GROUP BY shipped, zg.`name` ORDER BY shipped, zg.`name`; - + DROP TEMPORARY TABLE tmp.time, tLandings; END ;; DELIMITER ; @@ -81708,7 +82996,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionRoute_freeTickets` AS select `t`.`routeFk` AS `routeFk`,`tss`.`ticket` AS `ticket`,`s`.`name` AS `code`,`w`.`name` AS `almacen`,`tss`.`updated` AS `updated`,`p`.`code` AS `parkingCode` from (((((`ticketState` `tss` join `ticket` `t` on(`t`.`id` = `tss`.`ticket`)) join `warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `state` `s` on(`s`.`id` = `tss`.`state`)) left join `ticketParking` `tp` on(`tp`.`ticketFk` = `t`.`id`)) left join `parking` `p` on(`p`.`id` = `tp`.`parkingFk`)) where ifnull(`t`.`packages`,0) = 0 */; +/*!50001 VIEW `expeditionRoute_freeTickets` AS select `t`.`routeFk` AS `routeFk`,`tss`.`ticketFk` AS `ticket`,`s`.`name` AS `code`,`w`.`name` AS `almacen`,`tss`.`updated` AS `updated`,`p`.`code` AS `parkingCode` from (((((`ticketState` `tss` join `ticket` `t` on(`t`.`id` = `tss`.`ticketFk`)) join `warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `state` `s` on(`s`.`id` = `tss`.`state`)) left join `ticketParking` `tp` on(`tp`.`ticketFk` = `t`.`id`)) left join `parking` `p` on(`p`.`id` = `tp`.`parkingFk`)) where ifnull(`t`.`packages`,0) = 0 */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82158,7 +83446,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStock` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,min(`ish`.`packing`) AS `packing`,min(`ish`.`grouping`) AS `grouping`,`s`.`description` AS `sector`,sum(`ish`.`visible`) AS `visibleOriginal`,0 AS `removed`,`p`.`sectorFk` AS `sectorFk`,`s`.`warehouseFk` AS `warehouseFk`,`ish`.`shelvingFk` AS `shelvingFk`,`p`.`code` AS `parkingCode`,`sh`.`parkingFk` AS `parkingFk`,`ish`.`id` AS `itemShelvingFk`,`ish`.`created` AS `created`,`s`.`isPreviousPrepared` AS `isPreviousPrepared` from (((`itemShelving` `ish` left join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) left join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) left join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) where `ish`.`visible` <> 0 and `p`.`sectorFk` <> 0 group by `ish`.`itemFk`,`p`.`sectorFk` */; +/*!50001 VIEW `itemShelvingStock` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,min(`ish`.`packing`) AS `packing`,min(`ish`.`grouping`) AS `grouping`,`s`.`description` AS `sector`,sum(`ish`.`visible`) AS `visibleOriginal`,0 AS `removed`,`p`.`sectorFk` AS `sectorFk`,`s`.`warehouseFk` AS `warehouseFk`,`ish`.`shelvingFk` AS `shelvingFk`,`p`.`code` AS `parkingCode`,`sh`.`parkingFk` AS `parkingFk`,`ish`.`id` AS `itemShelvingFk`,`ish`.`created` AS `created`,`st`.`description` = 'previousPrepared' AS `isPreviousPrepared` from ((((`itemShelving` `ish` left join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) left join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) left join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) left join `sectorType` `st` on(`st`.`id` = `s`.`typeFk`)) where `ish`.`visible` <> 0 and `p`.`sectorFk` <> 0 group by `ish`.`itemFk`,`p`.`sectorFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82199,24 +83487,6 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `itemShelvingStock_byWarehouse` --- - -/*!50001 DROP VIEW IF EXISTS `itemShelvingStock_byWarehouse`*/; -/*!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 = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStock_byWarehouse` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,`s`.`warehouseFk` AS `warehouseFk` from (((`itemShelving` `ish` join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) group by `ish`.`itemFk`,`s`.`warehouseFk` */; -/*!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 `itemTagged` -- @@ -82932,7 +84202,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketState` AS select `tt`.`created` AS `updated`,`tt`.`stateFk` AS `stateFk`,`tt`.`workerFk` AS `workerFk`,`tls`.`ticketFk` AS `ticketFk`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alertLevel` AS `alertLevel`,`s`.`code` AS `code`,`tls`.`ticketFk` AS `ticket`,`tt`.`workerFk` AS `worker`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from ((`ticketLastState` `tls` join `ticketTracking` `tt` on(`tt`.`id` = `tls`.`ticketTrackingFk`)) join `state` `s` on(`s`.`id` = `tt`.`stateFk`)) */; +/*!50001 VIEW `ticketState` AS select `tt`.`created` AS `updated`,`tt`.`stateFk` AS `stateFk`,`tt`.`userFk` AS `userFk`,`tls`.`ticketFk` AS `ticketFk`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alertLevel` AS `alertLevel`,`s`.`code` AS `code`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from ((`ticketLastState` `tls` join `ticketTracking` `tt` on(`tt`.`id` = `tls`.`ticketTrackingFk`)) join `state` `s` on(`s`.`id` = `tt`.`stateFk`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82950,7 +84220,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code`,`ts`.`updated` AS `updated`,`ts`.`isPicked` AS `isPicked` from (`ticketState` `ts` join `ticket` `t` on(`t`.`id` = `ts`.`ticket`)) where `t`.`shipped` between `util`.`VN_CURDATE`() and `MIDNIGHT`(`util`.`VN_CURDATE`()) */; +/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticketFk` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`userFk` AS `worker`,`ts`.`code` AS `code`,`ts`.`updated` AS `updated`,`ts`.`isPicked` AS `isPicked` from (`ticketState` `ts` join `ticket` `t` on(`t`.`id` = `ts`.`ticketFk`)) where `t`.`shipped` between `util`.`VN_CURDATE`() and `MIDNIGHT`(`util`.`VN_CURDATE`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83202,7 +84472,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `zoneEstimatedDelivery` AS SELECT `t`.`zoneFk` AS `zoneFk`, `zc`.`hour` AS `zoneClosureHour`, `z`.`hour` AS `zoneHour`, `sv`.`volume` AS `volume`, `al`.`hasToRecalcPrice` AS `hasToRecalcPrice`, `lhp`.`m3` AS `m3`, `dl`.`minSpeed` AS `minSpeed` FROM ((((((((((`vn`.`ticket` `t` JOIN `vn`.`ticketStateToday` `tst` ON (`tst`.`ticket` = `t`.`id`)) JOIN `vn`.`state` `s` ON (`s`.`id` = `tst`.`state`)) JOIN `vn`.`saleVolume` `sv` ON (`sv`.`ticketFk` = `t`.`id`)) LEFT JOIN `vn`.`lastHourProduction` `lhp` ON (`lhp`.`warehouseFk` = `t`.`warehouseFk`)) JOIN `vn`.`warehouse` `w` ON (`w`.`id` = `t`.`warehouseFk`)) JOIN `vn`.`warehouseAlias` `wa` ON (`wa`.`id` = `w`.`aliasFk`)) STRAIGHT_JOIN `vn`.`zone` `z` ON (`z`.`id` = `t`.`zoneFk`)) LEFT JOIN `vn`.`zoneClosure` `zc` ON (`zc`.`zoneFk` = `t`.`zoneFk` AND `zc`.`dated` = `util`.`VN_CURDATE`())) LEFT JOIN `cache`.`departure_limit` `dl` ON (`dl`.`warehouse_id` = `t`.`warehouseFk` AND `dl`.`fecha` = `util`.`VN_CURDATE`())) JOIN `vn`.`alertLevel` `al` ON (`al`.`id` = `s`.`alertLevel`)) WHERE `w`.`hasProduction` <> 0 AND CAST(`t`.`shipped` AS date) = `util`.`VN_CURDATE`() */; +/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,`zc`.`hour` AS `zoneClosureHour`,`z`.`hour` AS `zoneHour`,`sv`.`volume` AS `volume`,`al`.`hasToRecalcPrice` AS `hasToRecalcPrice`,`lhp`.`m3` AS `m3`,`dl`.`minSpeed` AS `minSpeed` from ((((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on(`tst`.`ticket` = `t`.`id`)) join `vn`.`state` `s` on(`s`.`id` = `tst`.`state`)) join `vn`.`saleVolume` `sv` on(`sv`.`ticketFk` = `t`.`id`)) left join `vn`.`lastHourProduction` `lhp` on(`lhp`.`warehouseFk` = `t`.`warehouseFk`)) join `vn`.`warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `vn`.`warehouseAlias` `wa` on(`wa`.`id` = `w`.`aliasFk`)) straight_join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`zoneClosure` `zc` on(`zc`.`zoneFk` = `t`.`zoneFk` and `zc`.`dated` = `util`.`VN_CURDATE`())) left join `cache`.`departure_limit` `dl` on(`dl`.`warehouse_id` = `t`.`warehouseFk` and `dl`.`fecha` = `util`.`VN_CURDATE`())) join `vn`.`alertLevel` `al` on(`al`.`id` = `s`.`alertLevel`)) where `w`.`hasProduction` <> 0 and cast(`t`.`shipped` as date) = `util`.`VN_CURDATE`() */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83216,4 +84486,4 @@ USE `vn`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2023-11-20 10:10:52 +-- Dump completed on 2024-01-24 8:21:19 From 5b2b6a15ad704a67f357b7dcc8577bc2151e7cd5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 24 Jan 2024 08:36:08 +0100 Subject: [PATCH 086/116] refs #6694 perf: improve filter --- back/methods/postcode/filter.js | 12 ++++++--- back/methods/postcode/specs/filter.spec.js | 30 ++++++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 8dbe2965f..2ea70e15a 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -35,8 +35,10 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); + filter = ctx?.filter ?? {}; + const conn = Self.dataSource.connector; - const where = buildFilter(ctx.where, (param, value) => { + const where = buildFilter(filter?.where, (param, value) => { switch (param) { case 'search': return {or: [ @@ -48,13 +50,15 @@ module.exports = Self => { }; } }) ?? {}; - - filter = mergeFilters(ctx?.where ?? {}, where); + delete ctx.filter.where; const stmts = []; let stmt; stmt = new ParameterizedSQL(` SELECT + pc.townFk, + t.provinceFk, + p.countryFk, pc.code, t.name as town, p.name as province, @@ -66,7 +70,7 @@ module.exports = Self => { JOIN country c on c.id = p.countryFk `); - stmt.merge(conn.makeSuffix({where: filter, limit: ctx?.limit ?? 30})); + stmt.merge(conn.makeSuffix({where, ...ctx})); const itemsIndex = stmts.push(stmt) - 1; const sql = ParameterizedSQL.join(stmts, ';'); diff --git a/back/methods/postcode/specs/filter.spec.js b/back/methods/postcode/specs/filter.spec.js index c393b629a..60ac24809 100644 --- a/back/methods/postcode/specs/filter.spec.js +++ b/back/methods/postcode/specs/filter.spec.js @@ -7,13 +7,13 @@ describe('Postcode filter()', () => { try { const ctx = { - args: { - + filter: { }, + limit: 1 }; const results = await models.Postcode.filter(ctx, options); - expect(results.length).toBeGreaterThan(0); + expect(results.length).toEqual(1); await tx.rollback(); } catch (e) { await tx.rollback(); @@ -27,8 +27,10 @@ describe('Postcode filter()', () => { try { const ctx = { - args: { - search: 46, + filter: { + where: { + search: 46, + } }, }; const results = await models.Postcode.filter(ctx, options); @@ -47,8 +49,10 @@ describe('Postcode filter()', () => { try { const ctx = { - args: { - search: 'Alz', + filter: { + where: { + search: 'Alz', + } }, }; const results = await models.Postcode.filter(ctx, options); @@ -67,8 +71,10 @@ describe('Postcode filter()', () => { try { const ctx = { - args: { - search: 'one', + filter: { + where: { + search: 'one', + } }, }; const results = await models.Postcode.filter(ctx, options); @@ -87,8 +93,10 @@ describe('Postcode filter()', () => { try { const ctx = { - args: { - search: 'Ec', + filter: { + where: { + search: 'Ec', + } }, }; const results = await models.Postcode.filter(ctx, options); From 40d5e8662b501eae200f913545a61e70005885d8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 24 Jan 2024 08:38:34 +0100 Subject: [PATCH 087/116] refs #6694 perf: remove unused imports --- back/methods/postcode/filter.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/back/methods/postcode/filter.js b/back/methods/postcode/filter.js index 2ea70e15a..4c3fc0cd3 100644 --- a/back/methods/postcode/filter.js +++ b/back/methods/postcode/filter.js @@ -1,6 +1,5 @@ const {ParameterizedSQL} = require('loopback-connector'); -const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); -// const {models} = require('vn-loopback/server/server'); +const {buildFilter} = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethod('filter', { @@ -41,12 +40,13 @@ module.exports = Self => { const where = buildFilter(filter?.where, (param, value) => { switch (param) { case 'search': - return {or: [ - {'pc.code': {like: `%${value}%`}}, - {'t.name': {like: `%${value}%`}}, - {'p.name': {like: `%${value}%`}}, - {'c.country': {like: `%${value}%`}} - ] + return { + or: [ + {'pc.code': {like: `%${value}%`}}, + {'t.name': {like: `%${value}%`}}, + {'p.name': {like: `%${value}%`}}, + {'c.country': {like: `%${value}%`}} + ] }; } }) ?? {}; From 2ee48a53e2deb73c8b0b270d4201d153b158e609 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 24 Jan 2024 09:59:27 +0100 Subject: [PATCH 088/116] refs #6222 fix(ticket): step-two --- db/changes/{240402 => 240403}/00-saleComponent.sql | 2 +- modules/ticket/front/basic-data/step-two/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename db/changes/{240402 => 240403}/00-saleComponent.sql (99%) diff --git a/db/changes/240402/00-saleComponent.sql b/db/changes/240403/00-saleComponent.sql similarity index 99% rename from db/changes/240402/00-saleComponent.sql rename to db/changes/240403/00-saleComponent.sql index 2e1021000..ea2b9c399 100644 --- a/db/changes/240402/00-saleComponent.sql +++ b/db/changes/240403/00-saleComponent.sql @@ -585,5 +585,5 @@ END$$ DELIMITER ; TRUNCATE TABLE `vn`.`ticketUpdateAction`; -INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrice'); +INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrices'); INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(2, 'Convertir en maná', 'mana'); \ No newline at end of file diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index 9717d1ea4..4818137fa 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -25,7 +25,7 @@ class Controller extends Component { loadDefaultTicketAction() { const isSalesAssistant = this.aclService.hasAny(['salesAssistant']); - this.ticket.option = isSalesAssistant ? 'mana' : 'buyerDiscount'; + this.ticket.option = isSalesAssistant ? 'mana' : 'renewPrices'; } onStepChange() { From fc53e98bb58af1cdf758b5ae49c691ae4369ba4a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 24 Jan 2024 10:48:01 +0100 Subject: [PATCH 089/116] refs #6028 hotFix : getByWorker days to show --- modules/route/back/methods/route/getByWorker.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/route/back/methods/route/getByWorker.js b/modules/route/back/methods/route/getByWorker.js index 7e70cb1f1..77be47957 100644 --- a/modules/route/back/methods/route/getByWorker.js +++ b/modules/route/back/methods/route/getByWorker.js @@ -1,3 +1,5 @@ +const {ConsoleMessage} = require('puppeteer'); + const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { @@ -40,7 +42,7 @@ module.exports = Self => { currentDate.setHours(0, 0, 0, 0); const nextDay = Date.vnNew(); nextDay.setDate(currentDate.getDate() + 1); - + nextDay.setHours(0, 0, 0, 0); const filter = { where: { and: [ From 48e4e21aa899d35588d299263bbdf385ffb32c94 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 24 Jan 2024 12:55:51 +0100 Subject: [PATCH 090/116] refs #6028 hotFix : getByWorker days to show --- modules/route/back/methods/route/getByWorker.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/route/back/methods/route/getByWorker.js b/modules/route/back/methods/route/getByWorker.js index 77be47957..9243cfbfb 100644 --- a/modules/route/back/methods/route/getByWorker.js +++ b/modules/route/back/methods/route/getByWorker.js @@ -1,5 +1,3 @@ -const {ConsoleMessage} = require('puppeteer'); - const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { From 1c0f8acb87e44a1f7dadb2dc855a429bca8cd801 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 Jan 2024 13:37:29 +0100 Subject: [PATCH 091/116] refs #5871 fix: awb --- db/dump/fixtures.sql | 44 ++++++++++++++----- db/dump/structure.sql | 39 +++++++++++++--- .../back/methods/invoice-in/filter.js | 19 +++++--- .../methods/invoice-in/specs/filter.spec.js | 7 +-- 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b243692bb..3e12659af 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1426,16 +1426,29 @@ INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) (5, 6), (15, 6); -INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`) +INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) VALUES - (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1), - (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2), - (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1), - (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2), - (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1), - (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2); + (1, '07546501420', 67, 671, util.VN_CURDATE(), 1761, 1, 1), + (2, '07546491421', 252, 2769, util.VN_CURDATE(), 5231, 1, 1), + (3, '07546500823', 102, 1495, util.VN_CURDATE(), 3221, 1, 1), + (4, '99610288821', 252, 2777, util.VN_CURDATE(), 3641, 1, 1), + (5, '07546500834', 229, 3292, util.VN_CURDATE(), 6601, 2, 1), + (6, '22101929561', 37, 458, util.VN_CURDATE(), 441, 2, 1), + (7, '07546491432', 258, 3034, util.VN_CURDATE(), 6441, 2, 1), + (8, '99610288644', 476, 4461, util.VN_CURDATE(), 5751, 442, 1), + (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), + (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); + +INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`) + VALUES + (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), + (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2, 2), + (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), + (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), + (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), + (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) VALUES @@ -2512,7 +2525,7 @@ INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); -INSERT INTO `vn`.`dua` (id, code, awbFk, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) +INSERT INTO `vn`.`dua` (id, code, awbFk__, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) VALUES (1, '19ES0028013A481523', 1, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), (2, '21ES00280136115760', 2, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1376.20, 442), @@ -2525,6 +2538,17 @@ INSERT INTO `vn`.`dua` (id, code, awbFk, issued, operated, booked, bookEntried, (9, '19ES00280132025491', 9, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 7126.23, 442), (10, '19ES00280132025492', 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 4631.45, 442); +INSERT INTO `vn`.`duaEntry` (`duaFk`, `entryFk`, `value`, `customsValue`, `euroValue`) + VALUES + (1, 1, 1.00, 1.00, 1.00), + (2, 2, 1.00, 1.00, 1.00), + (3, 3, 1.00, 1.00, 1.00), + (4, 4, 1.00, 1.00, 1.00), + (5, 5, 1.00, 1.00, 1.00), + (6, 6, 1.00, 1.00, 1.00), + (7, 7, 1.00, 1.00, 1.00), + (8, 8, 1.00, 1.00, 1.00); + REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`) VALUES (1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1), diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 694f745ef..66e9fd2f8 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -27523,7 +27523,7 @@ DROP TABLE IF EXISTS `dua`; CREATE TABLE `dua` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(45) DEFAULT NULL, - `awbFk` smallint(11) unsigned NOT NULL, + `awbFk__` smallint(11) unsigned NOT NULL, `issued` date DEFAULT NULL, `operated` date DEFAULT NULL, `booked` date DEFAULT NULL, @@ -27534,12 +27534,10 @@ CREATE TABLE `dua` ( `ASIEN` double DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`), - KEY `fk_awb_dua_awb_idx` (`awbFk`), KEY `fk_dua_gestdoc1_idx` (`gestdocFk`), KEY `dua_fk4_idx` (`companyFk`), CONSTRAINT `duaCompany_Fk` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, - CONSTRAINT `dua_fk1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `dua_fk2` FOREIGN KEY (`awbFk`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `dua_fk1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -41404,6 +41402,7 @@ CREATE TABLE `travel` ( `agencyModeFk` int(11) DEFAULT NULL, `clonedFrom` int(11) DEFAULT NULL, `editorFk` int(10) unsigned DEFAULT NULL, + `awbFk` SMALLINT(11) UNSIGNED, PRIMARY KEY (`id`), UNIQUE KEY `shipment_1` (`shipped`,`landed`,`warehouseInFk`,`warehouseOutFk`,`agencyFk`,`agencyModeFk`,`ref`), KEY `agency_id` (`agencyFk`), @@ -41418,7 +41417,8 @@ CREATE TABLE `travel` ( CONSTRAINT `travel_fk_editor` FOREIGN KEY (`editorFk`) REFERENCES `account`.`user` (`id`), CONSTRAINT `travel_ibfk_1` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouseOutFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, - CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agencyFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE + CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agencyFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, + CONSTRAINT `travel_FK_1` FOREIGN KEY (`awbFk`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -81330,7 +81330,34 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb3_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `awbVolume` AS select `d`.`awbFk` AS `awbFk`,`b`.`stickers` * `i`.`density` * if(`p`.`volume` > 0,`p`.`volume`,`p`.`width` * `p`.`depth` * if(`p`.`height` = 0,`i`.`size` + 10,`p`.`height`)) / (`vc`.`aerealVolumetricDensity` * 1000) AS `volume`,`b`.`id` AS `buyFk` from ((((((((`buy` `b` join `item` `i` on(`b`.`itemFk` = `i`.`id`)) join `itemType` `it` on(`i`.`typeFk` = `it`.`id`)) join `packaging` `p` on(`p`.`id` = `b`.`packagingFk`)) join `entry` `e` on(`b`.`entryFk` = `e`.`id`)) join `travel` `t` on(`t`.`id` = `e`.`travelFk`)) join `duaEntry` `de` on(`de`.`entryFk` = `e`.`id`)) join `dua` `d` on(`d`.`id` = `de`.`duaFk`)) join `volumeConfig` `vc`) where `t`.`shipped` > makedate(year(`util`.`VN_CURDATE`()) - 1,1) */; +/*!50001 VIEW `awbVolume` AS SELECT `t`.`awbFk` AS `awbFk`, + `b`.`stickers` * `i`.`density` * IF( + `p`.`volume` > 0, + `p`.`volume`, + `p`.`width` * `p`.`depth` * IF(`p`.`height` = 0, `i`.`size` + 10, `p`.`height`) + ) / (`vc`.`aerealVolumetricDensity` * 1000) AS `volume`, + `b`.`id` AS `buyFk` +FROM ( + ( + ( + ( + ( + ( + `vn`.`buy` `b` + JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) + ) + JOIN `vn`.`itemType` `it` ON(`i`.`typeFk` = `it`.`id`) + ) + JOIN `vn`.`packaging` `p` ON(`p`.`id` = `b`.`packagingFk`) + ) + JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) + ) + JOIN `vn`.`travel` `t` ON(`t`.`id` = `e`.`travelFk`) + ) + JOIN `vn`.`volumeConfig` `vc` + ) +WHERE `t`.`shipped` > makedate(year(`util`.`VN_CURDATE`()) - 1, 1) + AND t.awbFk*/; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; diff --git a/modules/invoiceIn/back/methods/invoice-in/filter.js b/modules/invoiceIn/back/methods/invoice-in/filter.js index dd193af85..e9d3da43c 100644 --- a/modules/invoiceIn/back/methods/invoice-in/filter.js +++ b/modules/invoiceIn/back/methods/invoice-in/filter.js @@ -127,7 +127,7 @@ module.exports = Self => { case 'isBooked': return {[`ii.${param}`]: value}; case 'awbCode': - return {'awb.code': value}; + return {'sub.code': value}; } }); @@ -143,20 +143,27 @@ module.exports = Self => { ii.issued, ii.isBooked, ii.supplierRef, - ii.docFk AS dmsFk, + ii.docFk dmsFk, dm.file, ii.supplierFk, ii.expenseFkDeductible deductibleExpenseFk, - s.name AS supplierName, + s.name supplierName, s.account, - SUM(iid.amount) AS amount, - awb.code AS awbCode + SUM(iid.amount) amount, + sub.code awbCode FROM invoiceIn ii JOIN supplier s ON s.id = ii.supplierFk LEFT JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id LEFT JOIN duaInvoiceIn dii ON dii.invoiceInFk = ii.id LEFT JOIN dua d ON d.id = dii.duaFk - LEFT JOIN awb ON awb.id = d.awbFk + LEFT JOIN ( + SELECT awb.code, de.duaFk + FROM duaEntry de + JOIN entry e ON e.id = de.entryFk + JOIN travel t ON t.id = e.travelFk + JOIN awb ON awb.id = t.awbFk + GROUP BY de.duaFk + ) sub ON sub.duaFk = d.id LEFT JOIN company co ON co.id = ii.companyFk LEFT JOIN dms dm ON dm.id = ii.docFk` ); diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js index adab3cbeb..76f17720f 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/filter.spec.js @@ -98,9 +98,10 @@ describe('InvoiceIn filter()', () => { const options = {transaction: tx}; try { + const awbExpected = '07546501420'; const ctx = { args: { - awbCode: '07546500856', + awbCode: awbExpected, } }; @@ -108,8 +109,8 @@ describe('InvoiceIn filter()', () => { const firstRow = result[0]; expect(result.length).toEqual(1); - expect(firstRow.id).toEqual(10); - expect(firstRow.awbCode).toEqual('07546500856'); + expect(firstRow.id).toEqual(1); + expect(firstRow.awbCode).toEqual(awbExpected); await tx.rollback(); } catch (e) { From ece0c926ddc2ad63d93179ee5b8093944d7d456b Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 Jan 2024 14:52:49 +0100 Subject: [PATCH 092/116] refs #6745 fix: duplicate fixtures --- db/dump/fixtures.sql | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 3e12659af..0a45cc216 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2512,19 +2512,6 @@ INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate (DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), (util.VN_CURDATE(), 1, 12, 17, 22, 27); -INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) - VALUES - (1, '07546501420', 67, 671, util.VN_CURDATE(), 1761, 1, 1), - (2, '07546491421', 252, 2769, util.VN_CURDATE(), 5231, 1, 1), - (3, '07546500823', 102, 1495, util.VN_CURDATE(), 3221, 1, 1), - (4, '99610288821', 252, 2777, util.VN_CURDATE(), 3641, 1, 1), - (5, '07546500834', 229, 3292, util.VN_CURDATE(), 6601, 2, 1), - (6, '22101929561', 37, 458, util.VN_CURDATE(), 441, 2, 1), - (7, '07546491432', 258, 3034, util.VN_CURDATE(), 6441, 2, 1), - (8, '99610288644', 476, 4461, util.VN_CURDATE(), 5751, 442, 1), - (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), - (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); - INSERT INTO `vn`.`dua` (id, code, awbFk__, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) VALUES (1, '19ES0028013A481523', 1, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), From 3848503853620d5931c1a58ae262eba27d613a4d Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 25 Jan 2024 14:58:48 +0100 Subject: [PATCH 093/116] fix(test): refs #6743 exportDb --- back/methods/image/specs/upload.spec.js | 7 ++--- back/models/vn-user.js | 10 +++---- db/dump/fixtures.sql | 30 +++++++++++-------- e2e/helpers/tests.js | 14 +++++++++ .../05-ticket/01-sale/02_edit_sale.spec.js | 5 ++-- .../10-travel/02_basic_data_and_log.spec.js | 11 ------- .../ticket/specs/componentUpdate.spec.js | 6 ++++ .../methods/ticket/specs/setDeleted.spec.js | 2 +- .../specs/timeEntry.spec.js | 3 +- 9 files changed, 50 insertions(+), 38 deletions(-) diff --git a/back/methods/image/specs/upload.spec.js b/back/methods/image/specs/upload.spec.js index 144770bcf..63c5cfb65 100644 --- a/back/methods/image/specs/upload.spec.js +++ b/back/methods/image/specs/upload.spec.js @@ -95,10 +95,7 @@ describe('image upload()', () => { spyOn(containerModel, 'upload'); const ctx = {req: {accessToken: {userId: hhrrId}}, - args: { - id: itemId, - collection: 'user' - } + args: {id: itemId, collection: 'user'} }; try { @@ -109,7 +106,7 @@ describe('image upload()', () => { }); it('should try to upload a file for the collection "catalog" and throw a privilege error', async() => { - const ctx = {req: {accessToken: {userId: hhrrId}}, + const ctx = {req: {accessToken: {userId: 1}}, args: { id: workerId, collection: 'catalog' diff --git a/back/models/vn-user.js b/back/models/vn-user.js index 39e7008ca..3a416d7e3 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -79,10 +79,10 @@ module.exports = function(Self) { Self.getRoles = async(userId, options) => { const result = await Self.rawSql( `SELECT r.name - FROM account.user u - JOIN account.roleRole rr ON rr.role = u.role - JOIN account.role r ON r.id = rr.inheritsFrom - WHERE u.id = ?`, [userId], options); + FROM account.user u + JOIN account.roleRole rr ON rr.role = u.role + JOIN account.role r ON r.id = rr.inheritsFrom + WHERE u.id = ?`, [userId], options); const roles = []; for (const role of result) @@ -142,7 +142,7 @@ module.exports = function(Self) { ip: ctx.req.ip, owner: isOwner }); - throw new UserError('Try again'); + throw new UserError('Try again'); } }; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 3e12659af..33f047854 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -180,11 +180,13 @@ INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 2, 1, 0), (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0); +INSERT INTO `vn`.`sectorType` (id,description) + VALUES (1,'First type'); -INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `isPreviousPreparedByPacking`, `code`) +INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`) VALUES - (1, 'First sector', 1, 1, 'FIRST'), - (2, 'Second sector', 2, 0, 'SECOND'); + (1, 'First sector', 1, 'FIRST', 1), + (2, 'Second sector', 2, 'SECOND',1); INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAddress`) VALUES @@ -194,6 +196,7 @@ INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAd UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1; + INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`,`bossFk`, `phone`) VALUES (1106, 'LGN', 'David Charles', 'Haller', 19, 432978106), @@ -659,19 +662,20 @@ INSERT INTO `vn`.`invoiceOutExpense`(`id`, `invoiceOutFk`, `amount`, `expenseFk` INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `itemMaxSize`) VALUES - (1, 'Zone pickup A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), - (2, 'Zone pickup B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), + (1, 'Zone pickup A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), + (2, 'Zone pickup B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), (3, 'Zone 247 A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), (4, 'Zone 247 B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), (5, 'Zone expensive A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), (6, 'Zone expensive B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), - (7, 'Zone refund', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 100), - (8, 'Zone others', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 100), - (9, 'Zone superMan', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 0, 0, 100), - (10, 'Zone teleportation', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 0, 0, 100), - (11, 'Zone pickup C', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), - (12, 'Zone entanglement', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 0, 0, 100), - (13, 'Zone quantum break', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 0, 0, 100); + (7, 'Zone refund', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 1, 0, 100), + (8, 'Zone others', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 1, 0, 100), + (9, 'Zone superMan', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 1, 0, 100), + (10, 'Zone teleportation', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 1, 0, 100), + (11, 'Zone pickup C', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), + (12, 'Zone entanglement', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 1, 0, 100), + (13, 'Zone quantum break', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 1, 0, 100); + INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) VALUES @@ -2935,7 +2939,7 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES - (24, 7); + (24, 8); INSERT INTO `vn`.`deviceProductionModels` (`code`) VALUES diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js index 992ec051f..adb2f8f72 100644 --- a/e2e/helpers/tests.js +++ b/e2e/helpers/tests.js @@ -49,6 +49,20 @@ async function test() { random: false, }); + const SpecReporter = require('jasmine-spec-reporter').SpecReporter; + jasmine.addReporter(new SpecReporter({ + spec: { + displaySuccessful: false, + displayPending: false, + displayDuration: false, + displayFailed: true, + displayErrorMessages: true, + }, + summary: { + displayPending: false, + } + })); + await backendStatus(); jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 8be307269..21dbc01da 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -8,7 +8,7 @@ describe('Ticket Edit sale path', () => { beforeAll(async() => { browser = await getBrowser(); page = browser.page; - await page.loginAndModule('salesPerson', 'ticket'); + await page.loginAndModule('developer', 'ticket'); await page.accessToSearchResult('16'); await page.accessToSection('ticket.card.sale'); }); @@ -225,7 +225,8 @@ describe('Ticket Edit sale path', () => { }); it('should show error trying to delete a ticket with a refund', async() => { - await page.accessToSearchResult('7'); + await page.loginAndModule('production', 'ticket'); + await page.accessToSearchResult('8'); await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); await page.waitToClick(selectors.globalItems.acceptButton); diff --git a/e2e/paths/10-travel/02_basic_data_and_log.spec.js b/e2e/paths/10-travel/02_basic_data_and_log.spec.js index e6c601d7d..701e6b1b4 100644 --- a/e2e/paths/10-travel/02_basic_data_and_log.spec.js +++ b/e2e/paths/10-travel/02_basic_data_and_log.spec.js @@ -22,17 +22,6 @@ describe('Travel basic data path', () => { await page.waitForState('travel.card.basicData'); }); - it('should throw error if try move a travel with entries', async() => { - const lastMonth = Date.vnNew(); - lastMonth.setMonth(lastMonth.getMonth() - 1); - - await page.pickDate(selectors.travelBasicData.deliveryDate, lastMonth); - await page.waitToClick(selectors.travelBasicData.save); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Cannot past travels with entries'); - }); - it('should set a wrong delivery date then receive an error on submit', async() => { await page.loginAndModule('buyer', 'travel'); await page.write(selectors.travelIndex.generalSearchFilter, '4'); diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index c9a13b4cc..f176efd8e 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -75,6 +75,12 @@ describe('ticket componentUpdate()', () => { } }; + console.log('entra'); + const state = await models.TicketState.findOne({ + where: {ticketFk: 11} + }); + console.log('state: ', state); + console.log('ctx: ', ctx.args); await models.Ticket.componentUpdate(ctx, options); [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven, null, options); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 43bc2c2d9..7931935b7 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -117,7 +117,7 @@ describe('ticket setDeleted()', () => { return value; }; - const ticketId = 7; + const ticketId = 8; await models.Ticket.setDeleted(ctx, ticketId, options); await tx.rollback(); diff --git a/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js b/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js index 92c01792f..97f100501 100644 --- a/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js @@ -247,6 +247,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { const start = new Date(dated - 1); start.setHours(0, 0, 0); + await models.WorkerTimeControl.rawSql('CALL vn.timeControl_calculateByUser(?, ?, ?)', [ hankPymId, start, @@ -255,7 +256,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { let [timeControlCalculateTable] = await models.WorkerTimeControl.rawSql('SELECT * FROM tmp.timeControlCalculate', null, options); - expect(timeControlCalculateTable.timeWorkSeconds).toEqual(26400); + expect(timeControlCalculateTable.timeWorkSeconds).toEqual(25200); await tx.rollback(); } catch (e) { await tx.rollback(); From a7faac3ef65cea2ff9a1237b7d265934cdfe871a Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 25 Jan 2024 15:07:19 +0100 Subject: [PATCH 094/116] fix. refs #6743 remove consoleLog --- .../back/methods/ticket/specs/componentUpdate.spec.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index f176efd8e..8abb1a4a1 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -74,13 +74,6 @@ describe('ticket componentUpdate()', () => { } } }; - - console.log('entra'); - const state = await models.TicketState.findOne({ - where: {ticketFk: 11} - }); - console.log('state: ', state); - console.log('ctx: ', ctx.args); await models.Ticket.componentUpdate(ctx, options); [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven, null, options); From 9981c0bef936db61bddda2fef6ab0153ebb7e311 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 25 Jan 2024 15:09:48 +0100 Subject: [PATCH 095/116] fix(test): refs #6743 fix test --- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 21dbc01da..4f54ad860 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -8,7 +8,7 @@ describe('Ticket Edit sale path', () => { beforeAll(async() => { browser = await getBrowser(); page = browser.page; - await page.loginAndModule('developer', 'ticket'); + await page.loginAndModule('salesPerson', 'ticket'); await page.accessToSearchResult('16'); await page.accessToSection('ticket.card.sale'); }); From 1ad1e53970707775446e53fe8825858e6ea1c439 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 25 Jan 2024 17:33:54 +0100 Subject: [PATCH 096/116] feat: refs #5483 update db files --- db/.gitignore | 2 + db/changes/240201/.gitkeep | 0 db/changes/240201/00-aclsMails.sql | 8 - ...00-fixInvoiceCorrectionConstraintsName.sql | 7 - db/changes/240201/00-getTaxBases.sql | 33 - db/changes/240201/00-tabletDocuware.sql | 10 - db/changes/240201/00-timecontrol.sql | 17 - .../240201/00-truncateWhereSignInLog.sql | 2 - db/changes/240201/01-functions.sql | 81 - .../240201/01-newHasAnyPositiveBase.sql | 30 - db/changes/240201/01-procedures.sql | 1788 --- .../240201/01-refactorHasAnyNegativeBase.sql | 32 - db/changes/240201/01-triggers.sql | 27 - db/changes/240201/01-views.sql | 58 - db/changes/240202/.gitkeep | 0 db/changes/240202/00-aclWorkerTimeControl.sql | 14 - db/changes/240203/.gitkeep | 0 db/changes/240203/00-viaExpressConfig.sql | 2 - db/changes/240401/.gitkeep | 0 db/changes/240401/00-removeStars.sql | 1 - db/changes/240401/00-revokeItem.sql | 4 - db/changes/240401/00-supplier.sql | 12 - db/changes/240401/00-ticketSmsToClientSms.sql | 9 - .../240401/00-ticket_canbePostponed.sql | 74 - .../240401/00-updateACL_Role_VnRole.sql | 6 - .../240401/01-saleGroupDetailDefaultSize.sql | 2 - db/changes/240401/01-supplierAccount.sql | 9 - .../240401/03-fixInvoiceOutBeforeInsert.sql | 59 - db/changes/240403/00-saleComponent.sql | 589 - db/changes/240601/.gitkeep | 0 db/dump/.dump/data.sql | 169 +- db/dump/.dump/privileges.sql | 89 +- db/dump/.dump/triggers.sql | 10780 ++++++++++++++++ db/dump/Dockerfile | 2 +- db/dump/fixtures.after.sql | 10 +- db/dump/fixtures.before.sql | 652 +- db/dump/fixtures.sql | 3060 ----- db/routines/bs/procedures/clean.sql | 9 +- ...ATE.sql => clientNewBorn_beforeUpdate.sql} | 2 +- ...eInsert.sql => nightTask_beforeInsert.sql} | 2 +- ...eUpdate.sql => nightTask_beforeUpdate.sql} | 2 +- db/routines/edi/procedures/ekt_load.sql | 219 +- ...e_bi.sql => item_feature_beforeInsert.sql} | 2 +- ...ER_UPDATE.sql => putOrder_afterUpdate.sql} | 2 +- ...E_INSERT.sql => putOrder_beforeInsert.sql} | 2 +- ...E UPDATE.sql => putOrder_beforeUpdate.sql} | 2 +- ...ATE.sql => supplyResponse_afterUpdate.sql} | 2 +- .../procedures/accountingMovements_add.sql | 36 - db/routines/sage/procedures/clean.sql | 12 + .../procedures/importErrorNotification.sql | 62 + ...E_UPDATE.sql => movConta_beforeUpdate.sql} | 2 +- ...ion_BU.sql => expedition_beforeUpdate.sql} | 2 +- .../{moving_AI.sql => moving_afterInsert.sql} | 2 +- .../vn/events/client_unassignSalesPerson.sql | 4 +- .../vn/events/sale_checkWithoutComponents.sql | 2 +- .../vn/functions/workerTimeControl_add.sql | 57 - .../workerTimeControl_addDirection.sql | 57 - .../vn/functions/worker_isInDepartment.sql | 27 + db/routines/vn/procedures/buyUltimate.sql | 7 +- .../vn/procedures/buyUltimateFromInterval.sql | 36 +- .../vn/procedures/buy_recalcPricesByAwb.sql | 5 +- .../procedures/client_unassignSalesPerson.sql | 4 +- .../vn/procedures/collection_assign.sql | 160 +- db/routines/vn/procedures/collection_new.sql | 247 +- db/routines/vn/procedures/comparative_add.sql | 7 +- db/routines/vn/procedures/duaParcialMake.sql | 6 +- .../vn/procedures/ektEntryAssign_setEntry.sql | 2 +- .../procedures/invoiceInTax_afterUpsert.sql | 3 +- .../vn/procedures/itemProposal_Add.sql | 101 +- .../procedures/itemShelving_filterBuyer.sql | 12 +- .../vn/procedures/productionControl.sql | 4 +- db/routines/vn/procedures/recipe_Plaster.sql | 30 +- db/routines/vn/procedures/saleGroup_add.sql | 8 +- .../vn/procedures/sale_calculateComponent.sql | 20 +- .../vn/procedures/sale_checkNoComponents.sql | 2 +- .../vn/procedures/sale_getBoxPickingList.sql | 68 +- .../vn/procedures/sale_recalcComponent.sql | 50 +- .../vn/procedures/sale_replaceItem.sql | 136 + .../vn/procedures/ticketCalculateClon.sql | 16 +- .../vn/procedures/ticketComponentUpdate.sql | 67 +- .../procedures/ticketComponentUpdateSale.sql | 195 +- .../vn/procedures/ticketMissed_List.sql | 2 +- .../procedures/ticketParking_findSkipped.sql | 2 +- .../procedures/ticketStateToday_setState.sql | 2 +- .../vn/procedures/ticket_canbePostponed.sql | 1 + .../procedures/ticket_checkNoComponents.sql | 10 +- .../procedures/ticket_componentMakeUpdate.sql | 48 +- .../vn/procedures/ticket_recalcComponents.sql | 2 +- db/routines/vn/procedures/ticket_split.sql | 8 +- .../vn/procedures/timeWorkerControl_check.sql | 10 - .../vn/procedures/workerTimeControlAdd.sql | 14 - .../workerTimeControlPinGenerate.sql | 13 - .../procedures/workerTimeControlSetOrder.sql | 16 - .../vn/procedures/workerTimeControl_add.sql | 8 - .../procedures/workerTimeControl_repair.sql | 39 - .../procedures/workerTimeControl_setOrder.sql | 15 - .../vn/procedures/zone_upcomingDeliveries.sql | 2 +- ...tonomy_AD.sql => autonomy_afterDelete.sql} | 2 +- ...onomy_BI.sql => autonomy_beforeInsert.sql} | 2 +- ...onomy_BU.sql => autonomy_beforeUpdate.sql} | 2 +- .../{awb_bi.sql => awb_beforeInsert.sql} | 2 +- .../vn/triggers/calendar_afterDelete.sql | 12 + .../vn/triggers/calendar_beforeInsert.sql | 8 + .../vn/triggers/calendar_beforeUpdate.sql | 8 + .../vn/triggers/clientCredit_AfterInsert.sql | 2 +- .../vn/triggers/client_AfterInsert.sql | 2 +- ...UPDATE.sql => collection_beforeUpdate.sql} | 62 +- ...TER_INSERT.sql => country_afterInsert.sql} | 2 +- .../vn/triggers/delivery_beforeInsert.sql | 20 + .../vn/triggers/delivery_beforeUpdate.sql | 20 + ...ORE_INSERT.sql => duaTax_beforeInsert.sql} | 2 +- ...ORE_UPDATE.sql => duaTax_beforeUpdate.sql} | 2 +- ....sql => expeditionPallet_beforeInsert.sql} | 2 +- ...RT.sql => expeditionScan_beforeInsert.sql} | 2 +- .../triggers/expeditionState_AfterInsert.sql | 2 +- .../triggers/expeditionState_BeforeInsert.sql | 2 +- ...T.sql => expeditionTruck_beforeInsert.sql} | 2 +- ...E.sql => expeditionTruck_beforeUpdate.sql} | 2 +- ...T.sql => floramondoConfig_afterInsert.sql} | 2 +- ...iceIn_au.sql => invoiceIn_afterUpdate.sql} | 2 +- ...ceIn_bi.sql => invoiceIn_beforeInsert.sql} | 2 +- ...ceIn_bu.sql => invoiceIn_beforeUpdate.sql} | 2 +- .../vn/triggers/invoiceOut_beforeInsert.sql | 69 +- ...NSERT.sql => itemCategory_afterInsert.sql} | 2 +- .../vn/triggers/itemShelving _afterDelete.sql | 12 + ...T.sql => itemShelvingSale_afterInsert.sql} | 2 +- ...NSERT.sql => itemShelving_afterInsert.sql} | 2 +- ...PDATE.sql => itemShelving_afterUpdate.sql} | 2 +- ...LETE.sql => itemShelving_beforeDelete.sql} | 2 +- ...SERT.sql => itemShelving_beforeInsert.sql} | 5 +- ...DATE.sql => itemShelving_beforeUpdate.sql} | 3 +- ...achine_BI.sql => machine_beforeInsert.sql} | 2 +- ...RE_INSERT.sql => parking_beforeInsert.sql} | 2 +- ...RE_UPDATE.sql => parking_beforeUpdate.sql} | 2 +- .../vn/triggers/projectNotes_BeforeInsert.sql | 2 +- db/routines/vn/triggers/saleBuy_AI.sql | 13 - ...RE_INSERT.sql => saleBuy_beforeInsert.sql} | 2 +- .../vn/triggers/saleGroup_afterDelete.sql | 12 + .../vn/triggers/saleGroup_beforeInser.sql | 8 + .../vn/triggers/saleGroup_beforeUpdate.sql | 8 + ...nsert.sql => saleTracking_afterInsert.sql} | 2 +- ...EFORE_DELETE.sql => sale_beforeDelete.sql} | 2 +- ...E_UPDATE.sql => shelving_beforeUpdate.sql} | 2 +- ...INSERT.sql => solunionCAP_afterInsert.sql} | 2 +- ...UPDATE.sql => solunionCAP_afterUpdate.sql} | 2 +- ...ELETE.sql => solunionCAP_beforeDelete.sql} | 2 +- ...ORE_INSERT.sql => specie_beforeInsert.sql} | 2 +- ...ORE_UPDATE.sql => specie_beforeUpdate.sql} | 2 +- ...BEFORE_INSERT.sql => tag_beforeInsert.sql} | 2 +- ...T.sql => ticketPackaging_beforeInsert.sql} | 2 +- ...ERT.sql => ticketParking_beforeInsert.sql} | 2 +- ...e_ad.sql => ticketService_afterDelete.sql} | 2 +- ...e_ai.sql => ticketService_afterInsert.sql} | 2 +- ...e_au.sql => ticketService_afterUpdate.sql} | 2 +- ..._AFTER_UPDATE.sql => time_afterUpdate.sql} | 2 +- .../vn/triggers/travel_beforeInsert.sql | 11 +- .../vn/triggers/travel_beforeUpdate.sql | 9 - .../workerTimeControl_afterDelete.sql | 12 + ....sql => workerTimeControl_afterInsert.sql} | 6 +- .../workerTimeControl_beforeInsert.sql | 8 + .../workerTimeControl_beforeUpdate.sql | 8 + ...sert.sql => workingHours_beforeInsert.sql} | 2 +- ..._BI.sql => zoneExclusion_beforeInsert.sql} | 2 +- ..._BU.sql => zoneExclusion_beforeUpdate.sql} | 2 +- db/routines/vn/views/awbVolume.sql | 21 +- .../vn/views/expeditionRoute_freeTickets.sql | 39 +- .../vn/views/itemShelvingAvailable.sql | 2 +- db/routines/vn/views/itemShelvingStock.sql | 62 +- db/routines/vn/views/ticketDownBuffer.sql | 4 +- db/routines/vn/views/ticketState.sql | 4 +- db/routines/vn/views/ticketStateToday.sql | 2 +- .../vn/views/zoneEstimatedDelivery.sql | 2 +- .../vn2008/procedures/Cajas_Saldo_Detalle.sql | 51 - .../procedures/CompresTriggerBeforeDelete.sql | 21 - .../EntradasTriggerBeforeDelete.sql | 18 - .../EntradasTriggerBeforeUpdate.sql | 28 - .../vn2008/procedures/Facturas_Saltos.sql | 65 - .../vn2008/procedures/InsertarEspionaje.sql | 26 - db/routines/vn2008/procedures/Rutas_Graph.sql | 46 - db/routines/vn2008/procedures/Trabuque.sql | 72 - ...Vehiculos_consumo_calculateLiters100km.sql | 42 - .../vn2008/procedures/add_awb_component.sql | 9 +- .../vn2008/procedures/agencia_descuadre.sql | 32 - .../procedures/article_available_single.sql | 13 - db/routines/vn2008/procedures/base_ticket.sql | 12 - .../bionic_available_types_filter.sql | 38 - db/routines/vn2008/procedures/buy_label.sql | 40 - db/routines/vn2008/procedures/buy_split.sql | 150 - .../buy_tarifas_recalcular_almacen.sql | 36 - .../vn2008/procedures/buy_transfer.sql | 104 - .../procedures/check_table_existence.sql | 16 - db/routines/vn2008/procedures/clean.sql | 22 +- .../vn2008/procedures/comercial_caducado.sql | 57 - .../procedures/compresTriggerBeforeInsert.sql | 17 - .../procedures/compresTriggerBeforeUpdate.sql | 36 - .../vn2008/procedures/createBouquet.sql | 50 - .../vn2008/procedures/credit_update.sql | 17 - .../vn2008/procedures/entryFromOrder.sql | 55 - .../vn2008/procedures/entryFromTicket.sql | 62 - .../vn2008/procedures/eti_to_print.sql | 24 - .../vn2008/procedures/f10_no_vincular.sql | 60 - .../vn2008/procedures/historico_joined.sql | 88 - .../vn2008/procedures/inventario_valorado.sql | 185 - db/routines/vn2008/procedures/item_buy.sql | 32 - .../vn2008/procedures/item_express.sql | 41 - db/routines/vn2008/procedures/item_new.sql | 11 - db/routines/vn2008/procedures/malpagantes.sql | 44 - db/routines/vn2008/procedures/mensaje.sql | 13 - db/routines/vn2008/procedures/msg.sql | 21 - db/routines/vn2008/procedures/newItem.sql | 34 - db/routines/vn2008/procedures/niching.sql | 49 - .../vn2008/procedures/notify_passport.sql | 12 - db/routines/vn2008/procedures/percentil.sql | 30 - .../vn2008/procedures/prepare_client_list.sql | 11 - db/routines/vn2008/procedures/proc_end.sql | 11 - db/routines/vn2008/procedures/proc_start.sql | 13 - .../vn2008/procedures/prueba_miguel.sql | 6 - .../vn2008/procedures/quadre_clientes.sql | 67 - .../procedures/quadre_clientes_detalle.sql | 70 - .../vn2008/procedures/recobro_credito.sql | 8 +- .../vn2008/procedures/scan_rutas_view.sql | 31 - .../procedures/sort_merge_passes_ernesto.sql | 85 - .../vn2008/procedures/splitAnthuriums2016.sql | 86 - db/routines/vn2008/procedures/subordinate.sql | 46 - .../vn2008/procedures/suppliersDebt.sql | 35 - db/routines/vn2008/procedures/top_seller.sql | 113 - .../procedures/travel_tree_shipment.sql | 37 - .../vn2008/procedures/unary_delete.sql | 30 - .../vn2008/procedures/unary_insert.sql | 17 - .../vn2008/procedures/unary_scan_ident.sql | 25 - .../vn2008/procedures/unary_scan_insert.sql | 20 - .../vn2008/procedures/unary_update.sql | 32 - .../{Conteo_ai.sql => Conteo_afterInsert.sql} | 2 +- ... => account_conciliacion_beforeInsert.sql} | 2 +- ...UPDATE.sql => agency_hour_afterUpdate.sql} | 2 +- ...nsert.sql => agency_hour_beforeInsert.sql} | 2 +- ...da_ad.sql => awb_recibida_afterDelete.sql} | 2 +- ..._au.sql => movement_label_afterUpdate.sql} | 2 +- .../vn2008/views/client_observation.sql | 9 - db/routines/vn2008/views/clientes_gestdoc.sql | 6 - .../vn2008/views/clientes_regalos_enc.sql | 7 - .../views/clientes_regalos_lista_enc.sql | 17 - db/routines/vn2008/views/clientes_tipo.sql | 8 - .../vn2008/views/cooler_path_detail.sql | 7 - db/routines/vn2008/views/credit.sql | 9 - db/routines/vn2008/views/escritos_det.sql | 12 - db/routines/vn2008/views/gesttip.sql | 1 - db/routines/vn2008/views/iva_codigo.sql | 15 - db/routines/vn2008/views/iva_group.sql | 7 - db/routines/vn2008/views/iva_group_codigo.sql | 7 - db/routines/vn2008/views/iva_tipo.sql | 11 - db/routines/vn2008/views/travel.sql | 3 +- .../10193-navyHydrangea/00-delete.sql | 0 .../10193-navyHydrangea/01-botanicExport.sql | 0 .../10193-navyHydrangea/02-item.sql | 0 .../10193-navyHydrangea/03-autonomy.sql | 0 .../10193-navyHydrangea/03-turn.sql | 0 .../10193-navyHydrangea/04-country.sql | 0 .../10379-turquoiseOrchid/00-firstScript.sql | 0 .../00-business_workcenterFk.sql | 0 .../10395-blueGalax/00-firstScript.sql | 0 .../10396-grayRoebelini/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10399-blueErica/00-firstScript.sql | 0 .../10400-brownEucalyptus/00-firstScript.sql | 0 .../10402-orangeTulip/00-firstScript.sql | 0 .../10404-grayMedeola/00-firstScript.sql | 0 .../10405-orangeGalax/00-firstScript.sql | 0 .../10407-blueOak/00-firstScript.sql | 0 .../10408-purpleIvy/00-firstScript.sql | 0 .../10409-brownSalal/00-firstScript.sql | 0 .../10412-yellowCarnation/00-firstScript.sql | 0 .../10413-whiteCymbidium/00-firstScript.sql | 0 .../10416-blueAsparagus/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10421-navyMonstera/00-firstScript.sql | 0 .../10426-silverAsparagus/00-firstScript.sql | 0 .../10428-wheatRose/00-firstScript.sql | 0 .../10431-redCordyline/00-firstScript.sql | 0 .../10433-salmonAnthurium/00-firstScript.sql | 0 .../10434-grayTulip/00-firstScript.sql | 0 .../10435-aquaGalax/00-firstScript.sql | 0 .../10436-tealPalmetto/00-createFkWorker.sql | 0 .../01-addStateToWorkerProductivity.sql | 0 .../02-DeprecateVnSaleTrackingState.sql | 0 ...-DeprecateColumnVnSaleTrackingActionFk.sql | 0 .../04-DropSchemaVnControl.sql | 0 .../05-RemoveFkWorkerProductivity.sql | 0 .../10439-greenTulip/00-fixRole.sql | 0 .../10440-grayDendro/00-firstScript.sql | 0 .../10444-crimsonBamboo/00-firstScript.sql | 0 .../10445-orangeMoss/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10450-blackIvy/00-firstScript.sql | 0 .../10451-salmonOak/00-firstScript.sql | 0 .../10452-redEucalyptus/00-firstScript.sql | 0 .../10453-aquaMedeola/00-firstScript.sql | 0 .../10454-bronzeMoss/00-firstScript.sql | 0 .../10455-blackGerbera/00-firstScript.sql | 0 .../10456-greenArborvitae/00-firstScript.sql | 0 .../10457-crimsonTulip/00-firstScript.sql | 0 .../10458-orangePalmetto/00-firstScript.sql | 0 .../00-alterTableUtilConfig.sql | 0 .../01-createFunctionCurdate.sql | 0 .../02-createFunctionMockTime.sql | 0 .../03-createFunctionMockTimeBase.sql | 0 .../04-createFunctionNow.sql | 0 .../10460-crimsonDendro/00-firstScript.sql | 0 .../10461-filtroPorTipos/00-firstScript.sql | 0 .../10463-wheatMonstera/00-firstScript.sql | 0 .../10468-goldenGerbera/00-firstScript.sql | 0 .../10469-bronzeEucalyptus/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10471-orangeMastic/00-firstScript.sql | 0 .../10472-bronzeOak/00-firstScript.sql | 0 .../10477-goldenDendro/00-firstScript.sql | 0 .../10478-tealGalax/00-dropBasket.sql | 0 .../10478-tealGalax/00-firstScript.sql | 0 .../10478-tealGalax/01-orderConfigured.sql | 0 .../10478-tealGalax/02-configuredUpdate.sql | 0 .../10478-tealGalax/99-privileges.sql | 0 .../10480-blueTulip/00-firstScript.sql | 0 .../10481-brownAspidistra/00-firstScript.sql | 0 .../10482-blueMastic/00-firstScript.sql | 0 .../10485-aquaCamellia/00-firstScript.sql | 0 .../10488-grayCarnation/00-firstScript.sql | 0 .../10491-orangeDracena/00-firstScript.sql | 0 .../10492-wheatIvy/00-firstScript.sql | 0 .../10493-purpleAnthurium/00-firstScript.sql | 0 .../10495-whiteFern/00-firstScript.sql | 0 .../10498-redAspidistra/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10500-limeRaphis/00-firstScript.sql | 0 .../10501-orangeAnthurium/00-firstScript.sql | 0 .../10502-azureCarnation/00-firstScript.sql | 0 .../10502-yellowCordyline/00-firstScript.sql | 0 .../10504-maroonPalmetto/00-firstScript.sql | 0 .../10506-aquaPaniculata/01-firstScript.sql | 0 .../10506-aquaPaniculata/02-secondScript.sql | 0 .../10506-aquaPaniculata/03-thirdScript.sql | 0 .../10506-crimsonRoebelini/00-firstScript.sql | 0 .../10507-greenAspidistra/00-firstScript.sql | 0 .../10508-maroonMonstera/00-firstScript.sql | 0 .../10510-salmonMoss/00-dropBusinessFk.sql | 0 .../01-createTableProfessionalCategory.sql | 0 .../10510-salmonMoss/02-exportToNewTable.sql | 0 .../10510-salmonMoss/03-RecreateFK.sql | 0 .../10510-salmonMoss/04-kkPostgresqlTable.sql | 0 .../00-firstScript.sql | 0 .../10512-purpleRoebelini/00-firstScript.sql | 0 .../10513-aquaCataractarum/00-firstScript.sql | 0 .../10514-silverAspidistra/00-firstScript.sql | 0 .../10516-crimsonSalal/00-firstScript.sql | 0 .../10521-salmonLilium/00-firstScript.sql | 0 .../10522-yellowMedeola/00-firstScript.sql | 0 .../10523-tealCataractarum/00-firstScript.sql | 0 .../10524-limeCordyline/00-firstScript.sql | 0 .../10524-limeCordyline/01-rateEditorFk.sql | 0 .../10525-yellowRuscus/00-firstScript.sql | 0 .../10526-goldenOak/00-firstScript.sql | 0 .../10528-orangeRoebelini/00-firstScript.sql | 0 .../10530-orangeCyca/00-firstScript.sql | 0 .../10531-chocolateFern/00-firstScript.sql | 0 .../10532-tealTulip/00-firstScript.sql | 0 .../10533-crimsonLaurel/00-firstScript.sql | 0 .../10537-grayCordyline/00-firstScript.sql | 0 .../00-createChronopostConfig.sql | 0 .../01-createChronopostService.sql | 0 .../02-createChronopostExpedition.sql | 0 .../03-createChronopostSenderAddress.sql | 0 .../04-addgrantPrivilegies.sql | 0 .../05-updateChronopostConfig.sql | 0 .../10539-pinkPalmetto/00-firstScript.sql | 0 .../10540-bronzeOrchid/00-firstScript.sql | 0 .../10545-maroonDracena/00-firstScript.sql | 0 .../10546-redOak/00-firstScript.sql | 0 .../10547-aquaDendro/00-firstScript.sql | 0 .../00-updateUpdateLog.sql | 0 .../01-updateInsertLog.sql | 0 .../02-updateDeleteLog.sql | 0 .../03-deleteEmptyLog.sql | 0 .../04-optimizeLogTables.sql | 0 .../10550-grayMonstera/00-editorFk.sql | 0 .../10550-grayMonstera/01-originFk.sql | 0 .../10552-blackAnthurium/00-firstScript.sql | 0 .../10554-maroonFern/00-firstScript.sql | 0 .../10557-whiteCordyline/00-firstScript.sql | 0 .../10559-brownDracena/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10562-whiteDendro/00-firstScript.sql | 0 .../00-delivery_ticketFk.sql | 0 .../10566-azureArborvitae/00-firstScript.sql | 0 .../10567-salmonAspidistra/00-firstScript.sql | 0 .../10568-grayAnthurium/00-firstScript.sql | 0 .../10569-salmonLaurel/00-firstScript.sql | 0 .../00-createSendingConfig.sql | 0 .../01-createSendingServiceWeekday.sql | 0 .../02-createSendingService.sql | 0 .../10570-goldenTulip/03-permisos.sql | 0 .../10571-navyCyca/00-firstScript.sql | 0 .../10573-tealChico/00-firstScript.sql | 0 .../10575-crimsonAnthurium/00-firstScript.sql | 0 .../10577-salmonMonstera/00-firstScript.sql | 0 .../10578-brownCarnation/00-firstScript.sql | 0 .../10579-aquaRoebelini/00-firstScript.sql | 0 .../00-itemTypeDropConstraint.sql | 0 .../01-itemTypeAddConstraint.sql | 0 .../00-itemTypeAutoIncrement.sql | 0 .../10582-purpleOrchid/00-firstScript.sql | 0 .../10583-turquoiseGerbera/00-firstScript.sql | 0 .../10584-azureGerbera/00-firstScript.sql | 0 .../10585-pinkMedeola/00-ticketLog.sql | 0 .../10585-pinkMedeola/01-entryLog.sql | 0 .../10585-pinkMedeola/02-claimLog.sql | 0 .../10585-pinkMedeola/03-clientLog.sql | 0 .../10585-pinkMedeola/04-invoiceInLog.sql | 0 .../10585-pinkMedeola/05-itemLog.sql | 0 .../10585-pinkMedeola/06-routeLog.sql | 0 .../10585-pinkMedeola/07-shelvingLog.sql | 0 .../10585-pinkMedeola/08-supplierLog.sql | 0 .../10585-pinkMedeola/09-travelLog.sql | 0 .../10585-pinkMedeola/10-workerLog.sql | 0 .../10585-pinkMedeola/11-zoneLog.sql | 0 .../10585-pinkMedeola/12-userLog.sql | 0 .../10585-pinkMedeola/13-roleLog.sql | 0 .../10587-navyOak/00-arcRead_addMinimum.sql | 0 .../10593-greenLilium/00-firstScript.sql | 0 .../10596-purpleCamellia/00-firstScript.sql | 0 .../10597-navyAralia/00-firstScript.sql | 0 .../10598-purpleGalax/00-workerLog.sql | 0 .../10598-purpleGalax/01-supplierLog.sql | 0 .../02-workerTimeControlLog.sql | 0 .../10598-purpleGalax/03-workerClockLog.sql | 0 .../10599-orangeHydrangea/00-firstScript.sql | 0 .../10601-orangeErica/00-firstScript.sql | 0 .../10602-whiteArborvitae/00-firstScript.sql | 0 .../10606-pinkChico/00-firstScript.sql | 0 .../10608-pinkAsparagus/00-firstScript.sql | 0 .../10609-grayRaphis/00-firstScript.sql | 0 .../00-updateCompanyId.sql | 0 .../01-updateSupplierId.sql | 0 .../02-invoiceOutCompany.sql | 0 .../10611-blueGerbera/00-firstScript.sql | 0 .../10613-purpleAspidistra/00-firstScript.sql | 0 .../10614-chocolateGalax/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10616-yellowIvy/00-firstScript.sql | 0 .../10616-yellowIvy/01-firstScript.sql | 0 .../10617-aquaAralia/00-firstScript.sql | 0 .../10618-whiteArborvitae/00-firstScript.sql | 0 .../10619-chocolateErica/00-firstScript.sql | 0 .../10620-azurePalmetto/00-firstScript.sql | 0 .../10624-blueAnthurium/00-firstScript.sql | 0 .../10625-whiteOak/00-firstScript.sql | 0 .../10626-silverRaphis/00-firstScript.sql | 0 .../10628-grayOrchid/00-firstScript.sql | 0 .../10630-brownMastic/00-firstScript.sql | 0 .../10631-yellowBamboo/00-firstScript.sql | 0 .../10632-wheatPaniculata/00-firstScript.sql | 0 .../10633-orangeArborvitae/00-firstScript.sql | 0 .../10634-pinkCymbidium/00-firstScript.sql | 0 .../10637-yellowAspidistra/00-firstScript.sql | 0 .../10640-redPalmetto/00-companyFkDrop.sql | 0 .../10640-redPalmetto/01-companyFkAi.sql | 0 .../10640-redPalmetto/02-companyFkCreate.sql | 0 .../10640-redPalmetto/04-supplierFkDrop.sql | 0 .../10640-redPalmetto/05-supplierFkAi.sql | 0 .../10640-redPalmetto/06-supplierFkCreate.sql | 0 .../00-firstScript.sql | 0 .../10643-blueCataractarum/00-firstScript.sql | 0 .../10644-aquaLaurel/00-firstScript.sql | 0 .../10645-purplePalmetto/00-addNewFields.sql | 0 .../01-updateCollectionWagonPrimaryKey.sql | 0 .../02-updateWagonPrimaryKey.sql | 0 .../03-addFieldToPackingSite.sql | 0 .../10647-goldenBamboo/00-renombrarTabla.sql | 0 .../10648-blackBirch/00-firstScript.sql | 0 .../10649-yellowAsparagus/00-firstScript.sql | 0 .../00-comparativeCountryFk.sql | 0 .../01-comparativeAddConfig.sql | 0 .../02-nightTaskAddNewTask.sql | 0 .../03-grantProc.vn.sql | 2 +- .../10652-maroonPhormium/00-firstScript.sql | 0 .../10653-redHydrangea/00-firstScript.sql | 0 .../10655-navyRuscus/00-firstScript.sql | 0 .../10656-navyMastic/00-firstScript.sql | 0 .../00-renameErrorProduction.sql | 0 .../10657-redDracena/01-changeNightTask.sql | 0 .../02-addCodeToClaimResponsible.sql | 0 .../03-grantSelectGrafana.sql | 0 .../10658-whiteDracena/00-firstScript.sql | 0 .../10659-azureDracena/00-firstScript.sql | 0 .../10661-crimsonIvy/00-firstScript.sql | 0 .../10662-wheatErica/00-firstScript.sql | 0 .../10663-tealCymbidium/00-firstScript.sql | 0 .../10665-maroonSalal/00-firstScript.sql | 0 .../10666-limeGerbera/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10668-tealBirch/00-firstScript.sql | 0 .../10671-maroonIvy/00-firstScript.sql | 0 .../10675-grayRuscus/00-firstScript.sql | 0 .../10676-aquaTulip/00-firstScript.sql | 0 .../10677-yellowMoss/00-firstScript.sql | 0 .../10678-orangeMedeola/00-firstScript.sql | 0 .../10679-inventoryDiscrepancy/00-tables.sql | 0 .../10680-turquoiseLilium/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10683-bronzeMastic/00-firstScript.sql | 0 .../10684-tealEucalyptus/00-firstScript.sql | 0 .../10685-blueMedeola/00-firstScript.sql | 0 .../10690-azureGalax/00-firstScript.sql | 0 .../10691-bronzeCamellia/00-firstScript.sql | 0 .../10692-silverLilium/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10694-bluePaniculata/00-firstScript.sql | 0 .../10695-pinkMastic/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10698-yellowGalax/00-firstScript.sql | 0 .../10699-aquaOak/00-firstScript.sql | 0 .../10700-salmonTulip/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10702-crimsonCymbidium/00-firstScript.sql | 0 .../10704-wheatMastic/00-firstScript.sql | 0 .../10705-yellowBirch/00-firstScript.sql | 0 .../10707-azureFern/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10712-crimsonCordyline/00-firstScript.sql | 0 .../10714-azureOak/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10717-silverRose/00-firstScript.sql | 0 .../10718-orangeRaphis/00-firstScript.sql | 0 .../10719-orangeMonstera/00-firstScript.sql | 0 .../10720-wheatCymbidium/00-firstScript.sql | 0 .../10721-blueEucalyptus/00-firstScript.sql | 0 .../10722-azureAralia/00-firstScript.vn.sql | 289 + .../10725-wheatAnthurium/00-firstScript.sql | 0 .../10726-blackMastic/00-firstScript.sql | 0 .../10727-limeErica/00-addPrinterField.sql | 0 .../01-createTableScreenModel.sql | 0 .../10727-limeErica/02-createTableScreen.sql | 0 .../03-createTableScreenModel.sql | 0 .../10727-limeErica/04-createTableScanner.sql | 0 .../05-createTablePackingSiteDeviceLog.sql | 0 .../06-alterTablePrinterModel.sql | 0 .../07-AddFieldsToPackingSite.sql | 0 .../00-firstScript.sql | 0 .../10733-azureErica/00-firstScript.sql | 0 .../10736-maroonChico/00-workerBossNull.sql | 0 .../00-firstScript.sql | 0 .../10740-pinkCataractarum/00-firstScript.sql | 0 .../01-refactorCplusTrascendency472.sql | 0 .../02-refactorCplusTrascendency477.sql | 0 .../03-refactorCplusInvoiceType477.sql | 0 .../04-refactorCplusInvoiceType472.sql | 0 .../10741-maroonMastic/05-fixes.sql | 0 .../10744-aquaBirch/00-firstScript.sql | 0 .../10746-aquaMastic/00-firstScript.sql | 0 .../10747-brownRaphis/00-firstScript.sql | 0 .../10748-navyRose/00-firstScript.sql | 0 .../10748-navyRose/01-SecondScript.sql | 0 .../00-firstScript.sql | 0 .../10750-limeAsparagus/00-firstScript.sql | 0 .../10750-wheatGalax/00-ticket_addGrants.sql | 0 .../10751-silverArborvitae/00-firstScript.sql | 0 .../00-firstScript.sql | 0 .../10753-blueDracena/00-firstScript.sql | 0 .../10754-purpleMonstera/00-firstScript.sql | 0 .../10755-redGalax/00-firstScript.sql | 0 .../10724-maroonOrchid/00-firstScript.sql | 33 + .../00-addFieldToTravel.sql | 9 + .../01-copyDataToTravel.sql | 9 + .../03-deprecateDuaAwbFk.sql | 2 + .../10758-boxPicking/02-agencyMode.sql | 3 + db/versions/10758-boxPicking/03-item.sql | 3 + .../10764-navyTulip/00-firstScript.sql | 7 + .../10781-crimsonMonstera/00-firstScript.sql | 9 + .../10784-tealCamellia/00-firstScript.sql | 3 + .../10808-maroonRoebelini/00-firstScript.sql | 2 + .../10809-purpleDendro/00-firstScript.sql | 2 + .../00-firstScript.sql | 7 + .../10811-pinkBirch/00-firstScript.sql | 7 + .../10812-goldenPaniculata/00-update.sql | 8 + .../10812-goldenPaniculata/01-delete.sql | 1 + .../10812-goldenPaniculata/02-rename.sql | 2 + .../03-changePosition.sql | 1 + .../10812-goldenPaniculata/04-unique.sql | 1 + .../10813-salmonChico/00-firstScript.sql | 2 + .../10815-brownGalax/00-firstScript.sql | 3 + .../10816-yellowMonstera/00-firstScript.sql | 1 + .../00-invoiceOutConfig_refLen.sql} | 2 +- .../10818-crimsonCamellia/00-firstScript.sql | 1 + db/versions/10819-blueIvy/00-firstScript.sql | 18 + .../10820-limeAspidistra/00-grants.sql | 14 + .../10827-purpleRaphis/00-firstScript.sql | 10 + .../10828-purpleRuscus/00-firstScript.sql | 1 + .../01-RevokeClientes_regalos_lista.sql | 1 + .../10832-purpleAralia}/00-util_tx_commit.sql | 0 .../00-util_tx_rollback.sql | 0 .../10832-purpleAralia}/00-util_tx_start.sql | 0 ...date_procedure_TravelCloneWithEntries.sql} | 0 .../02-grant_privileges_util_tx.sql} | 0 myt.config.yml | 3 +- 602 files changed, 13072 insertions(+), 10104 deletions(-) delete mode 100644 db/changes/240201/.gitkeep delete mode 100644 db/changes/240201/00-aclsMails.sql delete mode 100644 db/changes/240201/00-fixInvoiceCorrectionConstraintsName.sql delete mode 100644 db/changes/240201/00-getTaxBases.sql delete mode 100644 db/changes/240201/00-tabletDocuware.sql delete mode 100644 db/changes/240201/00-timecontrol.sql delete mode 100644 db/changes/240201/00-truncateWhereSignInLog.sql delete mode 100644 db/changes/240201/01-functions.sql delete mode 100644 db/changes/240201/01-newHasAnyPositiveBase.sql delete mode 100644 db/changes/240201/01-procedures.sql delete mode 100644 db/changes/240201/01-refactorHasAnyNegativeBase.sql delete mode 100644 db/changes/240201/01-triggers.sql delete mode 100644 db/changes/240201/01-views.sql delete mode 100644 db/changes/240202/.gitkeep delete mode 100644 db/changes/240202/00-aclWorkerTimeControl.sql delete mode 100644 db/changes/240203/.gitkeep delete mode 100644 db/changes/240203/00-viaExpressConfig.sql delete mode 100644 db/changes/240401/.gitkeep delete mode 100644 db/changes/240401/00-removeStars.sql delete mode 100644 db/changes/240401/00-revokeItem.sql delete mode 100644 db/changes/240401/00-supplier.sql delete mode 100644 db/changes/240401/00-ticketSmsToClientSms.sql delete mode 100644 db/changes/240401/00-ticket_canbePostponed.sql delete mode 100644 db/changes/240401/00-updateACL_Role_VnRole.sql delete mode 100644 db/changes/240401/01-saleGroupDetailDefaultSize.sql delete mode 100644 db/changes/240401/01-supplierAccount.sql delete mode 100644 db/changes/240401/03-fixInvoiceOutBeforeInsert.sql delete mode 100644 db/changes/240403/00-saleComponent.sql delete mode 100644 db/changes/240601/.gitkeep create mode 100644 db/dump/.dump/triggers.sql delete mode 100644 db/dump/fixtures.sql rename db/routines/bs/triggers/{clientNewBorn_BEFORE_UPDATE.sql => clientNewBorn_beforeUpdate.sql} (92%) rename db/routines/bs/triggers/{nightTaskBeforeInsert.sql => nightTask_beforeInsert.sql} (94%) rename db/routines/bs/triggers/{nightTaskBeforeUpdate.sql => nightTask_beforeUpdate.sql} (94%) rename db/routines/edi/triggers/{item_feature_bi.sql => item_feature_beforeInsert.sql} (90%) rename db/routines/edi/triggers/{putOrder_AFTER_UPDATE.sql => putOrder_afterUpdate.sql} (99%) rename db/routines/edi/triggers/{putOrder_BEFORE_INSERT.sql => putOrder_beforeInsert.sql} (93%) rename db/routines/edi/triggers/{BEFORE UPDATE.sql => putOrder_beforeUpdate.sql} (91%) rename db/routines/edi/triggers/{supplyResponse_AFTER_UPDATE.sql => supplyResponse_afterUpdate.sql} (96%) create mode 100644 db/routines/sage/procedures/clean.sql create mode 100644 db/routines/sage/procedures/importErrorNotification.sql rename db/routines/sage/triggers/{movConta_BEFORE_UPDATE.sql => movConta_beforeUpdate.sql} (92%) rename db/routines/srt/triggers/{expedition_BU.sql => expedition_beforeUpdate.sql} (89%) rename db/routines/srt/triggers/{moving_AI.sql => moving_afterInsert.sql} (97%) delete mode 100644 db/routines/vn/functions/workerTimeControl_add.sql delete mode 100644 db/routines/vn/functions/workerTimeControl_addDirection.sql create mode 100644 db/routines/vn/functions/worker_isInDepartment.sql create mode 100644 db/routines/vn/procedures/sale_replaceItem.sql delete mode 100644 db/routines/vn/procedures/timeWorkerControl_check.sql delete mode 100644 db/routines/vn/procedures/workerTimeControlAdd.sql delete mode 100644 db/routines/vn/procedures/workerTimeControlPinGenerate.sql delete mode 100644 db/routines/vn/procedures/workerTimeControlSetOrder.sql delete mode 100644 db/routines/vn/procedures/workerTimeControl_add.sql delete mode 100644 db/routines/vn/procedures/workerTimeControl_repair.sql delete mode 100644 db/routines/vn/procedures/workerTimeControl_setOrder.sql rename db/routines/vn/triggers/{autonomy_AD.sql => autonomy_afterDelete.sql} (91%) rename db/routines/vn/triggers/{autonomy_BI.sql => autonomy_beforeInsert.sql} (93%) rename db/routines/vn/triggers/{autonomy_BU.sql => autonomy_beforeUpdate.sql} (95%) rename db/routines/vn/triggers/{awb_bi.sql => awb_beforeInsert.sql} (93%) create mode 100644 db/routines/vn/triggers/calendar_afterDelete.sql create mode 100644 db/routines/vn/triggers/calendar_beforeInsert.sql create mode 100644 db/routines/vn/triggers/calendar_beforeUpdate.sql rename db/routines/vn/triggers/{collection_BEFORE_UPDATE.sql => collection_beforeUpdate.sql} (93%) rename db/routines/vn/triggers/{country_AFTER_INSERT.sql => country_afterInsert.sql} (97%) create mode 100644 db/routines/vn/triggers/delivery_beforeInsert.sql create mode 100644 db/routines/vn/triggers/delivery_beforeUpdate.sql rename db/routines/vn/triggers/{duaTax_BEFORE_INSERT.sql => duaTax_beforeInsert.sql} (93%) rename db/routines/vn/triggers/{duaTax_BEFORE_UPDATE.sql => duaTax_beforeUpdate.sql} (93%) rename db/routines/vn/triggers/{expeditionPallet_BEFORE_INSERT.sql => expeditionPallet_beforeInsert.sql} (92%) rename db/routines/vn/triggers/{expeditionScan_BEFORE_INSERT.sql => expeditionScan_beforeInsert.sql} (88%) rename db/routines/vn/triggers/{expeditionTruck_BEFORE_INSERT.sql => expeditionTruck_beforeInsert.sql} (88%) rename db/routines/vn/triggers/{expeditionTruck_BEFORE_UPDATE.sql => expeditionTruck_beforeUpdate.sql} (88%) rename db/routines/vn/triggers/{floramondoConfig_AFTER_INSERT.sql => floramondoConfig_afterInsert.sql} (89%) rename db/routines/vn/triggers/{invoiceIn_au.sql => invoiceIn_afterUpdate.sql} (97%) rename db/routines/vn/triggers/{invoiceIn_bi.sql => invoiceIn_beforeInsert.sql} (98%) rename db/routines/vn/triggers/{invoiceIn_bu.sql => invoiceIn_beforeUpdate.sql} (97%) rename db/routines/vn/triggers/{itemCategory_AFTER_INSERT.sql => itemCategory_afterInsert.sql} (93%) create mode 100644 db/routines/vn/triggers/itemShelving _afterDelete.sql rename db/routines/vn/triggers/{itemShelvingSale_AFTER_INSERT.sql => itemShelvingSale_afterInsert.sql} (89%) rename db/routines/vn/triggers/{itemShelving_AFTER_INSERT.sql => itemShelving_afterInsert.sql} (95%) rename db/routines/vn/triggers/{itemShelving_AFTER_UPDATE.sql => itemShelving_afterUpdate.sql} (94%) rename db/routines/vn/triggers/{itemShelving_BEFORE_DELETE.sql => itemShelving_beforeDelete.sql} (94%) rename db/routines/vn/triggers/{itemShelving_BEFORE_INSERT.sql => itemShelving_beforeInsert.sql} (74%) rename db/routines/vn/triggers/{itemShelving_BEFORE_UPDATE.sql => itemShelving_beforeUpdate.sql} (77%) rename db/routines/vn/triggers/{machine_BI.sql => machine_beforeInsert.sql} (91%) rename db/routines/vn/triggers/{parking_BEFORE_INSERT.sql => parking_beforeInsert.sql} (91%) rename db/routines/vn/triggers/{parking_BEFORE_UPDATE.sql => parking_beforeUpdate.sql} (92%) delete mode 100644 db/routines/vn/triggers/saleBuy_AI.sql rename db/routines/vn/triggers/{BEFORE_INSERT.sql => saleBuy_beforeInsert.sql} (59%) create mode 100644 db/routines/vn/triggers/saleGroup_afterDelete.sql create mode 100644 db/routines/vn/triggers/saleGroup_beforeInser.sql create mode 100644 db/routines/vn/triggers/saleGroup_beforeUpdate.sql rename db/routines/vn/triggers/{saleTracking_After_Insert.sql => saleTracking_afterInsert.sql} (92%) rename db/routines/vn/triggers/{sale_BEFORE_DELETE.sql => sale_beforeDelete.sql} (96%) rename db/routines/vn/triggers/{shelving_BEFORE_UPDATE.sql => shelving_beforeUpdate.sql} (94%) rename db/routines/vn/triggers/{solunionCAP_AFTER_INSERT.sql => solunionCAP_afterInsert.sql} (94%) rename db/routines/vn/triggers/{solunionCAP_AFTER_UPDATE.sql => solunionCAP_afterUpdate.sql} (96%) rename db/routines/vn/triggers/{solunionCAP_BEFORE_DELETE.sql => solunionCAP_beforeDelete.sql} (94%) rename db/routines/vn/triggers/{specie_BEFORE_INSERT.sql => specie_beforeInsert.sql} (91%) rename db/routines/vn/triggers/{specie_BEFORE_UPDATE.sql => specie_beforeUpdate.sql} (91%) rename db/routines/vn/triggers/{tag_BEFORE_INSERT.sql => tag_beforeInsert.sql} (73%) rename db/routines/vn/triggers/{ticketPackaging_BEFORE_INSERT.sql => ticketPackaging_beforeInsert.sql} (90%) rename db/routines/vn/triggers/{ticketParking_BEFORE_INSERT.sql => ticketParking_beforeInsert.sql} (88%) rename db/routines/vn/triggers/{ticketService_ad.sql => ticketService_afterDelete.sql} (94%) rename db/routines/vn/triggers/{ticketService_ai.sql => ticketService_afterInsert.sql} (89%) rename db/routines/vn/triggers/{ticketService_au.sql => ticketService_afterUpdate.sql} (94%) rename db/routines/vn/triggers/{time_AFTER_UPDATE.sql => time_afterUpdate.sql} (96%) create mode 100644 db/routines/vn/triggers/workerTimeControl_afterDelete.sql rename db/routines/vn/triggers/{workerTimeControl_AI.sql => workerTimeControl_afterInsert.sql} (65%) create mode 100644 db/routines/vn/triggers/workerTimeControl_beforeInsert.sql create mode 100644 db/routines/vn/triggers/workerTimeControl_beforeUpdate.sql rename db/routines/vn/triggers/{workingHoursBeforeInsert.sql => workingHours_beforeInsert.sql} (93%) rename db/routines/vn/triggers/{zoneExclusion_BI.sql => zoneExclusion_beforeInsert.sql} (91%) rename db/routines/vn/triggers/{zoneExclusion_BU.sql => zoneExclusion_beforeUpdate.sql} (91%) delete mode 100644 db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql delete mode 100644 db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql delete mode 100644 db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql delete mode 100644 db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql delete mode 100644 db/routines/vn2008/procedures/Facturas_Saltos.sql delete mode 100644 db/routines/vn2008/procedures/InsertarEspionaje.sql delete mode 100644 db/routines/vn2008/procedures/Rutas_Graph.sql delete mode 100644 db/routines/vn2008/procedures/Trabuque.sql delete mode 100644 db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql delete mode 100644 db/routines/vn2008/procedures/agencia_descuadre.sql delete mode 100644 db/routines/vn2008/procedures/article_available_single.sql delete mode 100644 db/routines/vn2008/procedures/base_ticket.sql delete mode 100644 db/routines/vn2008/procedures/bionic_available_types_filter.sql delete mode 100644 db/routines/vn2008/procedures/buy_label.sql delete mode 100644 db/routines/vn2008/procedures/buy_split.sql delete mode 100644 db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql delete mode 100644 db/routines/vn2008/procedures/buy_transfer.sql delete mode 100644 db/routines/vn2008/procedures/check_table_existence.sql delete mode 100644 db/routines/vn2008/procedures/comercial_caducado.sql delete mode 100644 db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql delete mode 100644 db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql delete mode 100644 db/routines/vn2008/procedures/createBouquet.sql delete mode 100644 db/routines/vn2008/procedures/credit_update.sql delete mode 100644 db/routines/vn2008/procedures/entryFromOrder.sql delete mode 100644 db/routines/vn2008/procedures/entryFromTicket.sql delete mode 100644 db/routines/vn2008/procedures/eti_to_print.sql delete mode 100644 db/routines/vn2008/procedures/f10_no_vincular.sql delete mode 100644 db/routines/vn2008/procedures/historico_joined.sql delete mode 100644 db/routines/vn2008/procedures/inventario_valorado.sql delete mode 100644 db/routines/vn2008/procedures/item_buy.sql delete mode 100644 db/routines/vn2008/procedures/item_express.sql delete mode 100644 db/routines/vn2008/procedures/item_new.sql delete mode 100644 db/routines/vn2008/procedures/malpagantes.sql delete mode 100644 db/routines/vn2008/procedures/mensaje.sql delete mode 100644 db/routines/vn2008/procedures/msg.sql delete mode 100644 db/routines/vn2008/procedures/newItem.sql delete mode 100644 db/routines/vn2008/procedures/niching.sql delete mode 100644 db/routines/vn2008/procedures/notify_passport.sql delete mode 100644 db/routines/vn2008/procedures/percentil.sql delete mode 100644 db/routines/vn2008/procedures/prepare_client_list.sql delete mode 100644 db/routines/vn2008/procedures/proc_end.sql delete mode 100644 db/routines/vn2008/procedures/proc_start.sql delete mode 100644 db/routines/vn2008/procedures/prueba_miguel.sql delete mode 100644 db/routines/vn2008/procedures/quadre_clientes.sql delete mode 100644 db/routines/vn2008/procedures/quadre_clientes_detalle.sql delete mode 100644 db/routines/vn2008/procedures/scan_rutas_view.sql delete mode 100644 db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql delete mode 100644 db/routines/vn2008/procedures/splitAnthuriums2016.sql delete mode 100644 db/routines/vn2008/procedures/subordinate.sql delete mode 100644 db/routines/vn2008/procedures/suppliersDebt.sql delete mode 100644 db/routines/vn2008/procedures/top_seller.sql delete mode 100644 db/routines/vn2008/procedures/travel_tree_shipment.sql delete mode 100644 db/routines/vn2008/procedures/unary_delete.sql delete mode 100644 db/routines/vn2008/procedures/unary_insert.sql delete mode 100644 db/routines/vn2008/procedures/unary_scan_ident.sql delete mode 100644 db/routines/vn2008/procedures/unary_scan_insert.sql delete mode 100644 db/routines/vn2008/procedures/unary_update.sql rename db/routines/vn2008/triggers/{Conteo_ai.sql => Conteo_afterInsert.sql} (96%) rename db/routines/vn2008/triggers/{account_conciliacion_BEFORE_INSERT.sql => account_conciliacion_beforeInsert.sql} (92%) rename db/routines/vn2008/triggers/{agency_hour_AFTER_UPDATE.sql => agency_hour_afterUpdate.sql} (95%) rename db/routines/vn2008/triggers/{agency_hourBeforeInsert.sql => agency_hour_beforeInsert.sql} (96%) rename db/routines/vn2008/triggers/{awb_recibida_ad.sql => awb_recibida_afterDelete.sql} (94%) rename db/routines/vn2008/triggers/{movement_label_au.sql => movement_label_afterUpdate.sql} (92%) delete mode 100644 db/routines/vn2008/views/client_observation.sql delete mode 100644 db/routines/vn2008/views/clientes_gestdoc.sql delete mode 100644 db/routines/vn2008/views/clientes_regalos_enc.sql delete mode 100644 db/routines/vn2008/views/clientes_regalos_lista_enc.sql delete mode 100644 db/routines/vn2008/views/clientes_tipo.sql delete mode 100644 db/routines/vn2008/views/cooler_path_detail.sql delete mode 100644 db/routines/vn2008/views/credit.sql delete mode 100644 db/routines/vn2008/views/escritos_det.sql delete mode 100644 db/routines/vn2008/views/iva_codigo.sql delete mode 100644 db/routines/vn2008/views/iva_group.sql delete mode 100644 db/routines/vn2008/views/iva_group_codigo.sql delete mode 100644 db/routines/vn2008/views/iva_tipo.sql rename db/versions/{ => .archive}/10193-navyHydrangea/00-delete.sql (100%) rename db/versions/{ => .archive}/10193-navyHydrangea/01-botanicExport.sql (100%) rename db/versions/{ => .archive}/10193-navyHydrangea/02-item.sql (100%) rename db/versions/{ => .archive}/10193-navyHydrangea/03-autonomy.sql (100%) rename db/versions/{ => .archive}/10193-navyHydrangea/03-turn.sql (100%) rename db/versions/{ => .archive}/10193-navyHydrangea/04-country.sql (100%) rename db/versions/{ => .archive}/10379-turquoiseOrchid/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10384-limeLaurel/00-business_workcenterFk.sql (100%) rename db/versions/{ => .archive}/10395-blueGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10396-grayRoebelini/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10397-4848TicketsFloramondo/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10399-blueErica/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10400-brownEucalyptus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10402-orangeTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10404-grayMedeola/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10405-orangeGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10407-blueOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10408-purpleIvy/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10409-brownSalal/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10412-yellowCarnation/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10413-whiteCymbidium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10416-blueAsparagus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10420-goldenCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10421-navyMonstera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10426-silverAsparagus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10428-wheatRose/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10431-redCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10433-salmonAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10434-grayTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10435-aquaGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10436-tealPalmetto/00-createFkWorker.sql (100%) rename db/versions/{ => .archive}/10436-tealPalmetto/01-addStateToWorkerProductivity.sql (100%) rename db/versions/{ => .archive}/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql (100%) rename db/versions/{ => .archive}/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql (100%) rename db/versions/{ => .archive}/10436-tealPalmetto/04-DropSchemaVnControl.sql (100%) rename db/versions/{ => .archive}/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql (100%) rename db/versions/{ => .archive}/10439-greenTulip/00-fixRole.sql (100%) rename db/versions/{ => .archive}/10440-grayDendro/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10444-crimsonBamboo/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10445-orangeMoss/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10448-wheatChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10450-blackIvy/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10451-salmonOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10452-redEucalyptus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10453-aquaMedeola/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10454-bronzeMoss/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10455-blackGerbera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10456-greenArborvitae/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10457-crimsonTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10458-orangePalmetto/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10459-chocolateMedeola/00-alterTableUtilConfig.sql (100%) rename db/versions/{ => .archive}/10459-chocolateMedeola/01-createFunctionCurdate.sql (100%) rename db/versions/{ => .archive}/10459-chocolateMedeola/02-createFunctionMockTime.sql (100%) rename db/versions/{ => .archive}/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql (100%) rename db/versions/{ => .archive}/10459-chocolateMedeola/04-createFunctionNow.sql (100%) rename db/versions/{ => .archive}/10460-crimsonDendro/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10461-filtroPorTipos/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10463-wheatMonstera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10468-goldenGerbera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10469-bronzeEucalyptus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10470-notaUltimoUsuario/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10471-orangeMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10472-bronzeOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10477-goldenDendro/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10478-tealGalax/00-dropBasket.sql (100%) rename db/versions/{ => .archive}/10478-tealGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10478-tealGalax/01-orderConfigured.sql (100%) rename db/versions/{ => .archive}/10478-tealGalax/02-configuredUpdate.sql (100%) rename db/versions/{ => .archive}/10478-tealGalax/99-privileges.sql (100%) rename db/versions/{ => .archive}/10480-blueTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10481-brownAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10482-blueMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10485-aquaCamellia/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10488-grayCarnation/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10491-orangeDracena/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10492-wheatIvy/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10493-purpleAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10495-whiteFern/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10498-redAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10500-limeChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10500-limeRaphis/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10501-orangeAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10502-azureCarnation/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10502-yellowCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10504-maroonPalmetto/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10506-aquaPaniculata/01-firstScript.sql (100%) rename db/versions/{ => .archive}/10506-aquaPaniculata/02-secondScript.sql (100%) rename db/versions/{ => .archive}/10506-aquaPaniculata/03-thirdScript.sql (100%) rename db/versions/{ => .archive}/10506-crimsonRoebelini/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10507-greenAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10508-maroonMonstera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10510-salmonMoss/00-dropBusinessFk.sql (100%) rename db/versions/{ => .archive}/10510-salmonMoss/01-createTableProfessionalCategory.sql (100%) rename db/versions/{ => .archive}/10510-salmonMoss/02-exportToNewTable.sql (100%) rename db/versions/{ => .archive}/10510-salmonMoss/03-RecreateFK.sql (100%) rename db/versions/{ => .archive}/10510-salmonMoss/04-kkPostgresqlTable.sql (100%) rename db/versions/{ => .archive}/10511-chocolateChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10512-purpleRoebelini/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10513-aquaCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10514-silverAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10516-crimsonSalal/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10521-salmonLilium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10522-yellowMedeola/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10523-tealCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10524-limeCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10524-limeCordyline/01-rateEditorFk.sql (100%) rename db/versions/{ => .archive}/10525-yellowRuscus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10526-goldenOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10528-orangeRoebelini/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10530-orangeCyca/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10531-chocolateFern/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10532-tealTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10533-crimsonLaurel/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10537-grayCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10538-silverAspidistra/00-createChronopostConfig.sql (100%) rename db/versions/{ => .archive}/10538-silverAspidistra/01-createChronopostService.sql (100%) rename db/versions/{ => .archive}/10538-silverAspidistra/02-createChronopostExpedition.sql (100%) rename db/versions/{ => .archive}/10538-silverAspidistra/03-createChronopostSenderAddress.sql (100%) rename db/versions/{ => .archive}/10538-silverAspidistra/04-addgrantPrivilegies.sql (100%) rename db/versions/{ => .archive}/10538-silverAspidistra/05-updateChronopostConfig.sql (100%) rename db/versions/{ => .archive}/10539-pinkPalmetto/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10540-bronzeOrchid/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10545-maroonDracena/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10546-redOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10547-aquaDendro/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10549-goldenHydrangea/00-updateUpdateLog.sql (100%) rename db/versions/{ => .archive}/10549-goldenHydrangea/01-updateInsertLog.sql (100%) rename db/versions/{ => .archive}/10549-goldenHydrangea/02-updateDeleteLog.sql (100%) rename db/versions/{ => .archive}/10549-goldenHydrangea/03-deleteEmptyLog.sql (100%) rename db/versions/{ => .archive}/10549-goldenHydrangea/04-optimizeLogTables.sql (100%) rename db/versions/{ => .archive}/10550-grayMonstera/00-editorFk.sql (100%) rename db/versions/{ => .archive}/10550-grayMonstera/01-originFk.sql (100%) rename db/versions/{ => .archive}/10552-blackAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10554-maroonFern/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10557-whiteCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10559-brownDracena/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10560-crimsonCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10562-whiteDendro/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10563-azureMonstera/00-delivery_ticketFk.sql (100%) rename db/versions/{ => .archive}/10566-azureArborvitae/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10567-salmonAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10568-grayAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10569-salmonLaurel/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10570-goldenTulip/00-createSendingConfig.sql (100%) rename db/versions/{ => .archive}/10570-goldenTulip/01-createSendingServiceWeekday.sql (100%) rename db/versions/{ => .archive}/10570-goldenTulip/02-createSendingService.sql (100%) rename db/versions/{ => .archive}/10570-goldenTulip/03-permisos.sql (100%) rename db/versions/{ => .archive}/10571-navyCyca/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10573-tealChico/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10575-crimsonAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10577-salmonMonstera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10578-brownCarnation/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10579-aquaRoebelini/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10580-purpleCataractarum/00-itemTypeDropConstraint.sql (100%) rename db/versions/{ => .archive}/10580-purpleCataractarum/01-itemTypeAddConstraint.sql (100%) rename db/versions/{ => .archive}/10581-grayPaniculata/00-itemTypeAutoIncrement.sql (100%) rename db/versions/{ => .archive}/10582-purpleOrchid/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10583-turquoiseGerbera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10584-azureGerbera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/00-ticketLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/01-entryLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/02-claimLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/03-clientLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/04-invoiceInLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/05-itemLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/06-routeLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/07-shelvingLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/08-supplierLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/09-travelLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/10-workerLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/11-zoneLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/12-userLog.sql (100%) rename db/versions/{ => .archive}/10585-pinkMedeola/13-roleLog.sql (100%) rename db/versions/{ => .archive}/10587-navyOak/00-arcRead_addMinimum.sql (100%) rename db/versions/{ => .archive}/10593-greenLilium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10596-purpleCamellia/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10597-navyAralia/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10598-purpleGalax/00-workerLog.sql (100%) rename db/versions/{ => .archive}/10598-purpleGalax/01-supplierLog.sql (100%) rename db/versions/{ => .archive}/10598-purpleGalax/02-workerTimeControlLog.sql (100%) rename db/versions/{ => .archive}/10598-purpleGalax/03-workerClockLog.sql (100%) rename db/versions/{ => .archive}/10599-orangeHydrangea/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10601-orangeErica/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10602-whiteArborvitae/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10606-pinkChico/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10608-pinkAsparagus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10609-grayRaphis/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10610-goldenArborvitae/00-updateCompanyId.sql (100%) rename db/versions/{ => .archive}/10610-goldenArborvitae/01-updateSupplierId.sql (100%) rename db/versions/{ => .archive}/10610-goldenArborvitae/02-invoiceOutCompany.sql (100%) rename db/versions/{ => .archive}/10611-blueGerbera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10613-purpleAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10614-chocolateGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10615-azureCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10616-yellowIvy/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10616-yellowIvy/01-firstScript.sql (100%) rename db/versions/{ => .archive}/10617-aquaAralia/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10618-whiteArborvitae/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10619-chocolateErica/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10620-azurePalmetto/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10624-blueAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10625-whiteOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10626-silverRaphis/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10628-grayOrchid/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10630-brownMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10631-yellowBamboo/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10632-wheatPaniculata/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10633-orangeArborvitae/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10634-pinkCymbidium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10637-yellowAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10640-redPalmetto/00-companyFkDrop.sql (100%) rename db/versions/{ => .archive}/10640-redPalmetto/01-companyFkAi.sql (100%) rename db/versions/{ => .archive}/10640-redPalmetto/02-companyFkCreate.sql (100%) rename db/versions/{ => .archive}/10640-redPalmetto/04-supplierFkDrop.sql (100%) rename db/versions/{ => .archive}/10640-redPalmetto/05-supplierFkAi.sql (100%) rename db/versions/{ => .archive}/10640-redPalmetto/06-supplierFkCreate.sql (100%) rename db/versions/{ => .archive}/10642-crimsonAspidistra/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10643-blueCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10644-aquaLaurel/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10645-purplePalmetto/00-addNewFields.sql (100%) rename db/versions/{ => .archive}/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql (100%) rename db/versions/{ => .archive}/10645-purplePalmetto/02-updateWagonPrimaryKey.sql (100%) rename db/versions/{ => .archive}/10645-purplePalmetto/03-addFieldToPackingSite.sql (100%) rename db/versions/{ => .archive}/10647-goldenBamboo/00-renombrarTabla.sql (100%) rename db/versions/{ => .archive}/10648-blackBirch/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10649-yellowAsparagus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10651-chocolatePalmetto/00-comparativeCountryFk.sql (100%) rename db/versions/{ => .archive}/10651-chocolatePalmetto/01-comparativeAddConfig.sql (100%) rename db/versions/{ => .archive}/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql (100%) rename db/versions/{ => .archive}/10651-chocolatePalmetto/03-grantProc.vn.sql (79%) rename db/versions/{ => .archive}/10652-maroonPhormium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10653-redHydrangea/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10655-navyRuscus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10656-navyMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10657-redDracena/00-renameErrorProduction.sql (100%) rename db/versions/{ => .archive}/10657-redDracena/01-changeNightTask.sql (100%) rename db/versions/{ => .archive}/10657-redDracena/02-addCodeToClaimResponsible.sql (100%) rename db/versions/{ => .archive}/10657-redDracena/03-grantSelectGrafana.sql (100%) rename db/versions/{ => .archive}/10658-whiteDracena/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10659-azureDracena/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10661-crimsonIvy/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10662-wheatErica/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10663-tealCymbidium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10665-maroonSalal/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10666-limeGerbera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10667-blackChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10668-tealBirch/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10671-maroonIvy/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10675-grayRuscus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10676-aquaTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10677-yellowMoss/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10678-orangeMedeola/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10679-inventoryDiscrepancy/00-tables.sql (100%) rename db/versions/{ => .archive}/10680-turquoiseLilium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10682-crimsonEucalyptus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10683-bronzeMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10684-tealEucalyptus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10685-blueMedeola/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10690-azureGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10691-bronzeCamellia/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10692-silverLilium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10693-chocolateCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10694-bluePaniculata/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10695-pinkMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10696-blackCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10698-yellowGalax/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10699-aquaOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10700-salmonTulip/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10701-turquoisePaniculata/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10702-crimsonCymbidium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10704-wheatMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10705-yellowBirch/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10707-azureFern/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10708-greenChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10712-crimsonCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10714-azureOak/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10716-chocolateCamellia/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10717-silverRose/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10718-orangeRaphis/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10719-orangeMonstera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10720-wheatCymbidium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10721-blueEucalyptus/00-firstScript.sql (100%) create mode 100644 db/versions/.archive/10722-azureAralia/00-firstScript.vn.sql rename db/versions/{ => .archive}/10725-wheatAnthurium/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10726-blackMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/00-addPrinterField.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/01-createTableScreenModel.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/02-createTableScreen.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/03-createTableScreenModel.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/04-createTableScanner.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/05-createTablePackingSiteDeviceLog.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/06-alterTablePrinterModel.sql (100%) rename db/versions/{ => .archive}/10727-limeErica/07-AddFieldsToPackingSite.sql (100%) rename db/versions/{ => .archive}/10730-whiteChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10733-azureErica/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10736-maroonChico/00-workerBossNull.sql (100%) rename db/versions/{ => .archive}/10739-turquoiseCordyline/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10740-pinkCataractarum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10741-maroonMastic/01-refactorCplusTrascendency472.sql (100%) rename db/versions/{ => .archive}/10741-maroonMastic/02-refactorCplusTrascendency477.sql (100%) rename db/versions/{ => .archive}/10741-maroonMastic/03-refactorCplusInvoiceType477.sql (100%) rename db/versions/{ => .archive}/10741-maroonMastic/04-refactorCplusInvoiceType472.sql (100%) rename db/versions/{ => .archive}/10741-maroonMastic/05-fixes.sql (100%) rename db/versions/{ => .archive}/10744-aquaBirch/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10746-aquaMastic/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10747-brownRaphis/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10748-navyRose/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10748-navyRose/01-SecondScript.sql (100%) rename db/versions/{ => .archive}/10749-chocolateEucalyptus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10750-limeAsparagus/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10750-wheatGalax/00-ticket_addGrants.sql (100%) rename db/versions/{ => .archive}/10751-silverArborvitae/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10752-crimsonChrysanthemum/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10753-blueDracena/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10754-purpleMonstera/00-firstScript.sql (100%) rename db/versions/{ => .archive}/10755-redGalax/00-firstScript.sql (100%) create mode 100644 db/versions/10724-maroonOrchid/00-firstScript.sql create mode 100644 db/versions/10738-greenCordyline/00-addFieldToTravel.sql create mode 100644 db/versions/10738-greenCordyline/01-copyDataToTravel.sql create mode 100644 db/versions/10738-greenCordyline/03-deprecateDuaAwbFk.sql create mode 100644 db/versions/10758-boxPicking/02-agencyMode.sql create mode 100644 db/versions/10758-boxPicking/03-item.sql create mode 100644 db/versions/10764-navyTulip/00-firstScript.sql create mode 100644 db/versions/10781-crimsonMonstera/00-firstScript.sql create mode 100644 db/versions/10784-tealCamellia/00-firstScript.sql create mode 100644 db/versions/10808-maroonRoebelini/00-firstScript.sql create mode 100644 db/versions/10809-purpleDendro/00-firstScript.sql create mode 100644 db/versions/10810-turquoiseCataractarum/00-firstScript.sql create mode 100644 db/versions/10811-pinkBirch/00-firstScript.sql create mode 100644 db/versions/10812-goldenPaniculata/00-update.sql create mode 100644 db/versions/10812-goldenPaniculata/01-delete.sql create mode 100644 db/versions/10812-goldenPaniculata/02-rename.sql create mode 100644 db/versions/10812-goldenPaniculata/03-changePosition.sql create mode 100644 db/versions/10812-goldenPaniculata/04-unique.sql create mode 100644 db/versions/10813-salmonChico/00-firstScript.sql create mode 100644 db/versions/10815-brownGalax/00-firstScript.sql create mode 100644 db/versions/10816-yellowMonstera/00-firstScript.sql rename db/{changes/240401/02-invoiceOutConfig_refLen.sql => versions/10817-navyChico/00-invoiceOutConfig_refLen.sql} (75%) create mode 100644 db/versions/10818-crimsonCamellia/00-firstScript.sql create mode 100644 db/versions/10819-blueIvy/00-firstScript.sql create mode 100644 db/versions/10820-limeAspidistra/00-grants.sql create mode 100644 db/versions/10827-purpleRaphis/00-firstScript.sql create mode 100644 db/versions/10828-purpleRuscus/00-firstScript.sql create mode 100644 db/versions/10828-purpleRuscus/01-RevokeClientes_regalos_lista.sql rename db/{changes/240601 => versions/10832-purpleAralia}/00-util_tx_commit.sql (100%) rename db/{changes/240601 => versions/10832-purpleAralia}/00-util_tx_rollback.sql (100%) rename db/{changes/240601 => versions/10832-purpleAralia}/00-util_tx_start.sql (100%) rename db/{changes/240601/00-update_procedure_TravelCloneWithEntries.sql => versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql} (100%) rename db/{changes/240601/00-grant_privileges_util_tx.sql => versions/10832-purpleAralia/02-grant_privileges_util_tx.sql} (100%) diff --git a/db/.gitignore b/db/.gitignore index b81ed39cc..54ed9df77 100644 --- a/db/.gitignore +++ b/db/.gitignore @@ -7,3 +7,5 @@ dump/.changes dump/fixtures.local.sql .dBeaver .idea +.project +.dbeaver/ diff --git a/db/changes/240201/.gitkeep b/db/changes/240201/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/240201/00-aclsMails.sql b/db/changes/240201/00-aclsMails.sql deleted file mode 100644 index 5cfea4030..000000000 --- a/db/changes/240201/00-aclsMails.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Definición de la tabla mailAliasACL - -CREATE OR REPLACE TABLE `account`.`mailAliasAcl` ( - `mailAliasFk` int(10) unsigned NOT NULL, - `roleFk` int(10) unsigned NOT NULL, - FOREIGN KEY (`mailAliasFk`) REFERENCES `account`.`mailAlias` (`id`), - FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; diff --git a/db/changes/240201/00-fixInvoiceCorrectionConstraintsName.sql b/db/changes/240201/00-fixInvoiceCorrectionConstraintsName.sql deleted file mode 100644 index 426afea90..000000000 --- a/db/changes/240201/00-fixInvoiceCorrectionConstraintsName.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `cplusInvoiceTyoeFk`; -ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `invoiceCorrectionType_Fk33`; -ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `invoiceCorrection_ibfk_1`; - -ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `siiTypeInvoiceOut_FK` FOREIGN KEY (`siiTypeInvoiceOutFk`) REFERENCES `vn`.`siiTypeInvoiceOut`(id) ON UPDATE CASCADE; -ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `invoiceCorrectionType_FK` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `vn`.`invoiceCorrectionType`(id) ON UPDATE CASCADE; -ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `cplusRectificationType_FK` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType`(id) ON UPDATE CASCADE; diff --git a/db/changes/240201/00-getTaxBases.sql b/db/changes/240201/00-getTaxBases.sql deleted file mode 100644 index 8bd1b745a..000000000 --- a/db/changes/240201/00-getTaxBases.sql +++ /dev/null @@ -1,33 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getTaxBases`() -BEGIN -/** -* Calcula y devuelve en número de bases imponibles postivas y negativas -* Requiere la tabla temporal tmp.ticketToInvoice(id) -* -* returns tmp.taxBases -*/ - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; - - CALL ticket_getTax(NULL); - - DROP TEMPORARY TABLE IF EXISTS tmp.taxBases; - CREATE TEMPORARY TABLE tmp.taxBases - ENGINE = MEMORY - SELECT - SUM(taxableBase > 0) as positive, - SUM(taxableBase < 0) as negative - FROM( - SELECT SUM(taxableBase) taxableBase - FROM tmp.ticketTax - GROUP BY pgcFk - ) t; - -END$$ -DELIMITER ; diff --git a/db/changes/240201/00-tabletDocuware.sql b/db/changes/240201/00-tabletDocuware.sql deleted file mode 100644 index ffa0226b3..000000000 --- a/db/changes/240201/00-tabletDocuware.sql +++ /dev/null @@ -1,10 +0,0 @@ --- vn.docuwareTablet definition - -CREATE TABLE `vn`.`docuwareTablet` ( - `tablet` varchar(100) NOT NULL PRIMARY KEY, - `description` varchar(255) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; - -ALTER TABLE `vn`.`userConfig` -ADD COLUMN tabletFk varchar(100) DEFAULT NULL, -ADD FOREIGN KEY (tabletFk) REFERENCES `vn`.`docuwareTablet`(tablet); diff --git a/db/changes/240201/00-timecontrol.sql b/db/changes/240201/00-timecontrol.sql deleted file mode 100644 index c3ddf5d96..000000000 --- a/db/changes/240201/00-timecontrol.sql +++ /dev/null @@ -1,17 +0,0 @@ -DELETE FROM `salix`.`ACL` - WHERE model = 'VnUser' - AND property = 'renewToken'; - -INSERT INTO `account`.`role` (name, description) - VALUES ('timeControl','Tablet para fichar'); - -INSERT INTO `account`.`roleInherit` (role, inheritsFrom) - VALUES (127, 11); - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('WorkerTimeControl', 'login', 'READ', 'ALLOW', 'ROLE', 'timeControl'), - ('WorkerTimeControl', 'getClockIn', 'READ', 'ALLOW', 'ROLE', 'timeControl'), - ('WorkerTimeControl', 'clockIn', 'WRITE', 'ALLOW', 'ROLE', 'timeControl'); - -CALL `account`.`role_sync`(); diff --git a/db/changes/240201/00-truncateWhereSignInLog.sql b/db/changes/240201/00-truncateWhereSignInLog.sql deleted file mode 100644 index db5d8e25d..000000000 --- a/db/changes/240201/00-truncateWhereSignInLog.sql +++ /dev/null @@ -1,2 +0,0 @@ -DELETE FROM `account`.`signInLog` where owner <> FALSE; - diff --git a/db/changes/240201/01-functions.sql b/db/changes/240201/01-functions.sql deleted file mode 100644 index 7bbe1f442..000000000 --- a/db/changes/240201/01-functions.sql +++ /dev/null @@ -1,81 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketPositionInPath`(vTicketId INT) - RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_general_ci - DETERMINISTIC -BEGIN - - DECLARE vRestTicketsMaxOrder INT; - DECLARE vRestTicketsMinOrder INT; - DECLARE vRestTicketsPacking INT; - DECLARE vMyProductionOrder INT; - DECLARE vPosition VARCHAR(10) DEFAULT 'MID'; - DECLARE vMyPath INT; - DECLARE vMyWarehouse INT; - DECLARE PACKING_ORDER INT; - DECLARE vExpeditionsCount INT; - DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE; - - - -SELECT `order` - INTO PACKING_ORDER - FROM state - WHERE code = 'PACKING'; - -SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0) - INTO vMyPath, vMyWarehouse, vMyProductionOrder - FROM ticket t - LEFT JOIN ticketState ts on ts.ticketFk = t.id - WHERE t.id = vTicketId; - -SELECT (ag.`name` = 'VN_VALENCIA') - INTO vIsValenciaPath - FROM vn2008.Rutas r - JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia - JOIN vn2008.agency ag on ag.agency_id = a.agency_id - WHERE r.Id_Ruta = vMyPath; - -IF vIsValenciaPath THEN -- Rutas Valencia - - SELECT COUNT(*) - INTO vExpeditionsCount - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - WHERE t.routeFk = vMyPath; - - SELECT MAX(ts.productionOrder), MIN(ts.productionOrder) - INTO vRestTicketsMaxOrder, vRestTicketsMinOrder - FROM ticket t - LEFT JOIN ticketState ts on t.id = ts.ticketFk - WHERE t.routeFk = vMyPath - AND t.warehouseFk = vMyWarehouse - AND t.id != vTicketid; - - SELECT COUNT(*) - INTO vRestTicketsPacking - FROM ticket t - LEFT JOIN ticketState ts on t.id = ts.ticketFk - WHERE ts.productionOrder = PACKING_ORDER - AND t.routeFk = vMyPath - AND t.warehouseFk = vMyWarehouse - AND t.id != vTicketid; - - IF vExpeditionsCount = 1 THEN - SET vPosition = 'FIRST'; - ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN - SET vPosition = 'LAST'; - ELSEIF vRestTicketsPacking THEN - SET vPosition = 'SHARED'; - ELSE - SET vPosition = 'MID'; - END IF; - -ELSE - SET vPosition = 'MID'; - -END IF; - -RETURN vPosition; - -END$$ -DELIMITER ; diff --git a/db/changes/240201/01-newHasAnyPositiveBase.sql b/db/changes/240201/01-newHasAnyPositiveBase.sql deleted file mode 100644 index c4edfaed0..000000000 --- a/db/changes/240201/01-newHasAnyPositiveBase.sql +++ /dev/null @@ -1,30 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyPositiveBase`() RETURNS tinyint(1) - DETERMINISTIC -BEGIN - -/** -* Calcula si existe alguna base imponible positiva -* Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases() -* -* returns BOOLEAN -*/ - - DECLARE hasAnyPositiveBase BOOLEAN; - - CALL getTaxBases(); - - SELECT positive INTO hasAnyPositiveBase - FROM tmp.taxBases - LIMIT 1; - - DROP TEMPORARY TABLE - tmp.ticketTax, - tmp.ticket, - tmp.taxBases; - - RETURN hasAnyPositiveBase; - -END$$ -DELIMITER ; diff --git a/db/changes/240201/01-procedures.sql b/db/changes/240201/01-procedures.sql deleted file mode 100644 index ab52dbd1b..000000000 --- a/db/changes/240201/01-procedures.sql +++ /dev/null @@ -1,1788 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`item_getVisible`( - vWarehouse TINYINT, - vDate DATE, - vType INT, - vPrefix VARCHAR(255)) -BEGIN - -/** - * Gets visible items of the specified type at specified date. - * - * @param vWarehouse The warehouse id - * @param vDate The visible date - * @param vType The type id - * @param vPrefix The article prefix to filter or %NULL for all - * @return tmp.itemVisible Visible items - */ - DECLARE vPrefixLen SMALLINT; - DECLARE vFilter VARCHAR(255) DEFAULT NULL; - DECLARE vDateInv DATE DEFAULT vn.getInventoryDate(); - DECLARE EXIT HANDLER FOR 1114 - BEGIN - GET DIAGNOSTICS CONDITION 1 - @message = MESSAGE_TEXT; - CALL vn.mail_insert( - 'cau@verdnatura.es', - NULL, - CONCAT('hedera.item_getVisible error: ', @message), - CONCAT( - 'warehouse: ', IFNULL(vWarehouse, ''), - ', Fecha:', IFNULL(vDate, ''), - ', tipo: ', IFNULL(vType,''), - ', prefijo: ', IFNULL(vPrefix,''))); - RESIGNAL; - END; - SET vPrefixLen = IFNULL(LENGTH(vPrefix), 0) + 1; - - IF vPrefixLen > 1 THEN - SET vFilter = CONCAT(vPrefix, '%'); - END IF; - - DROP TEMPORARY TABLE IF EXISTS `filter`; - CREATE TEMPORARY TABLE `filter` - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT id itemFk FROM vn.item - WHERE typeFk = vType - AND (vFilter IS NULL OR `name` LIKE vFilter); - - DROP TEMPORARY TABLE IF EXISTS currentStock; - CREATE TEMPORARY TABLE currentStock - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT itemFk, SUM(quantity) quantity - FROM ( - SELECT b.itemFk, b.quantity - 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 BETWEEN vDateInv AND vDate - AND t.warehouseInFk = vWarehouse - AND NOT e.isRaid - UNION ALL - SELECT b.itemFk, -b.quantity - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel t ON t.id = e.travelFk - WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() - AND t.warehouseOutFk = vWarehouse - AND NOT e.isRaid - AND t.isDelivered - UNION ALL - SELECT m.itemFk, -m.quantity - FROM vn.sale m - JOIN vn.ticket t ON t.id = m.ticketFk - JOIN vn.ticketState s ON s.ticketFk = t.id - WHERE t.shipped BETWEEN vDateInv AND util.VN_CURDATE() - AND t.warehouseFk = vWarehouse - AND s.alertLevel = 3 - ) t - GROUP BY itemFk - HAVING quantity > 0; - - DROP TEMPORARY TABLE IF EXISTS tmp; - CREATE TEMPORARY TABLE tmp - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT * - FROM ( - SELECT b.itemFk, b.packagingFk, b.packing - 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 BETWEEN vDateInv AND vDate - AND NOT b.isIgnored - AND b.price2 >= 0 - AND b.packagingFk IS NOT NULL - ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC - LIMIT 10000000000000000000 - ) t GROUP BY itemFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.itemVisible; - CREATE TEMPORARY TABLE tmp.itemVisible - ENGINE = MEMORY - SELECT i.id Id_Article, - SUBSTRING(i.`name`, vPrefixLen) Article, - t.packing, p.id Id_Cubo, - IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, - CEIL(s.quantity / t.packing) etiquetas - FROM vn.item i - JOIN `filter` f ON f.itemFk = i.id - JOIN currentStock s ON s.itemFk = i.id - LEFT JOIN tmp t ON t.itemFk = i.id - LEFT JOIN vn.packaging p ON p.id = t.packagingFk - WHERE CEIL(s.quantity / t.packing) > 0 - -- FIXME: Column Cubos.box not included in view vn.packaging - /* AND p.box */ ; - - DROP TEMPORARY TABLE - `filter`, - currentStock, - tmp; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_confirmWithUser`(vSelf INT, vUserId INT) -BEGIN -/** - * Confirms an order, creating each of its tickets on the corresponding - * date, store and user. - * - * @param vSelf The order identifier - * @param vUser The user identifier - */ - DECLARE vOk BOOL; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vWarehouse INT; - DECLARE vShipment DATE; - 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 vPriceFixed DECIMAL(10,2); - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vIsConfirmed BOOL; - DECLARE vClientId INT; - DECLARE vCompanyId INT; - DECLARE vAgencyModeId INT; - DECLARE TICKET_FREE INT DEFAULT 2; - DECLARE vCalc INT; - DECLARE vIsLogifloraItem BOOL; - DECLARE vOldQuantity INT; - DECLARE vNewQuantity INT; - DECLARE vIsTaxDataChecked BOOL; - - DECLARE cDates CURSOR FOR - SELECT zgs.shipped, r.warehouse_id - FROM `order` o - JOIN order_row r ON r.order_id = o.id - LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id - WHERE o.id = vSelf AND r.amount != 0 - GROUP BY r.warehouse_id; - - DECLARE cRows CURSOR FOR - SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo - FROM order_row r - JOIN vn.item i ON i.id = r.item_id - WHERE r.amount != 0 - AND r.warehouse_id = vWarehouse - AND r.order_id = vSelf - ORDER BY r.rate DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Carga los datos del pedido - SELECT o.date_send, o.address_id, o.note, a.clientFk, - o.company_id, o.agency_id, c.isTaxDataChecked - INTO vDelivery, vAddress, vNotes, vClientId, - vCompanyId, vAgencyModeId, vIsTaxDataChecked - FROM hedera.`order` o - JOIN vn.address a ON a.id = o.address_id - JOIN vn.client c ON c.id = a.clientFk - WHERE o.id = vSelf; - - -- Verifica si el cliente tiene los datos comprobados - IF NOT vIsTaxDataChecked THEN - CALL util.throw ('clientNotVerified'); - END IF; - - -- Carga las fechas de salida de cada almacen - CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE); - - -- Trabajador que realiza la accion - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; - END IF; - - START TRANSACTION; - - CALL order_checkEditable(vSelf); - - -- Check order is not empty - - SELECT COUNT(*) > 0 INTO vOk - FROM order_row WHERE order_id = vSelf AND amount > 0; - - IF NOT vOk THEN - CALL util.throw ('ORDER_EMPTY'); - END IF; - - -- Crea los tickets del pedido - - OPEN cDates; - - lDates: - LOOP - SET vTicket = NULL; - SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouse; - - IF vDone THEN - LEAVE lDates; - END IF; - - -- Busca un ticket existente que coincida con los parametros - WITH tPrevia AS - (SELECT DISTINCT s.ticketFk - FROM vn.sale s - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN vShipment AND util.dayend(vShipment) - ) - SELECT t.id INTO vTicket - FROM vn.ticket t - LEFT JOIN tPrevia tp ON tp.ticketFk = t.id - LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id - JOIN hedera.`order` o - ON o.address_id = t.addressFk - AND vWarehouse = t.warehouseFk - AND o.date_send = t.landed - AND DATE(t.shipped) = vShipment - WHERE o.id = vSelf - AND t.refFk IS NULL - AND tp.ticketFk IS NULL - AND IFNULL(tls.alertLevel,0) = 0 - LIMIT 1; - - -- Crea el ticket en el caso de no existir uno adecuado - IF vTicket IS NULL - THEN - - SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); - - CALL vn.ticket_add( - vClientId, - vShipment, - vWarehouse, - vCompanyId, - vAddress, - vAgencyModeId, - NULL, - vDelivery, - vUserId, - TRUE, - vTicket - ); - ELSE - INSERT INTO vn.ticketTracking - SET ticketFk = vTicket, - workerFk = vUserId, - stateFk = TICKET_FREE; - END IF; - - INSERT IGNORE INTO vn.orderTicket - SET orderFk = vSelf, - ticketFk = vTicket; - - -- Añade las notas - - IF vNotes IS NOT NULL AND vNotes != '' - THEN - INSERT INTO vn.ticketObservation SET - ticketFk = vTicket, - observationTypeFk = 4 /* salesperson */, - `description` = vNotes - ON DUPLICATE KEY UPDATE - `description` = CONCAT(VALUES(`description`),'. ', `description`); - END IF; - - -- Añade los movimientos y sus componentes - - OPEN cRows; - - lRows: LOOP - SET vDone = FALSE; - FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; - - IF vDone THEN - LEAVE lRows; - END IF; - - SET vSale = NULL; - - SELECT s.id, s.quantity INTO vSale, vOldQuantity - FROM vn.sale s - WHERE ticketFk = vTicket - AND price = vPrice - AND itemFk = vItem - AND discount = 0 - LIMIT 1; - - IF vSale THEN - UPDATE vn.sale - SET quantity = quantity + vAmount, - originalQuantity = quantity - WHERE id = vSale; - - SELECT s.quantity INTO vNewQuantity - FROM vn.sale s - WHERE id = vSale; - ELSE - -- Obtiene el coste - SELECT SUM(rc.`price`) valueSum INTO vPriceFixed - FROM orderRowComponent rc - JOIN vn.component c ON c.id = rc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk AND ct.isBase - WHERE rc.rowFk = vRowId; - - INSERT INTO vn.sale - SET itemFk = vItem, - ticketFk = vTicket, - concept = vConcept, - quantity = vAmount, - price = vPrice, - priceFixed = vPriceFixed, - isPriceFixed = TRUE; - - SET vSale = LAST_INSERT_ID(); - - INSERT INTO vn.saleComponent - (saleFk, componentFk, `value`) - SELECT vSale, rc.componentFk, rc.price - FROM orderRowComponent rc - JOIN vn.component c ON c.id = rc.componentFk - WHERE rc.rowFk = vRowId - GROUP BY vSale, rc.componentFk; - END IF; - - UPDATE order_row SET Id_Movimiento = vSale - WHERE id = vRowId; - - -- Inserta en putOrder si la compra es de Floramondo - IF vIsLogifloraItem THEN - CALL cache.availableNoRaids_refresh(vCalc,FALSE,vWarehouse,vShipment); - - SET @available := 0; - - SELECT GREATEST(0,available) INTO @available - FROM cache.availableNoRaids - WHERE calc_id = vCalc - AND item_id = vItem; - - UPDATE cache.availableNoRaids - SET available = GREATEST(0,available - vAmount) - WHERE item_id = vItem - AND calc_id = vCalc; - - INSERT INTO edi.putOrder ( - deliveryInformationID, - supplyResponseId, - quantity , - EndUserPartyId, - EndUserPartyGLN, - FHAdminNumber, - saleFk - ) - SELECT di.ID, - i.supplyResponseFk, - CEIL((vAmount - @available)/ sr.NumberOfItemsPerCask), - o.address_id , - vClientId, - IFNULL(ca.fhAdminNumber, fhc.defaultAdminNumber), - vSale - FROM edi.deliveryInformation di - JOIN vn.item i ON i.supplyResponseFk = di.supplyResponseID - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientId - JOIN edi.floraHollandConfig fhc - JOIN hedera.`order` o ON o.id = vSelf - WHERE i.id = vItem - AND di.LatestOrderDateTime > util.VN_NOW() - AND vAmount > @available - LIMIT 1; - END IF; - END LOOP; - - CLOSE cRows; - END LOOP; - - CLOSE cDates; - - UPDATE `order` SET confirmed = TRUE, confirm_date = util.VN_NOW() - WHERE id = vSelf; - - COMMIT; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATE, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN -/** - * Creación de facturas emitidas. - * requiere previamente tabla tmp.ticketToInvoice(id). - * - * @param vSerial serie a la cual se hace la factura - * @param vInvoiceDate fecha de la factura - * @param vTaxArea tipo de iva en relacion a la empresa y al cliente - * @param vNewInvoiceId id de la factura que se acaba de generar - * @return vNewInvoiceId - */ - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompanyFk INT; - DECLARE vInterCompanyFk INT; - DECLARE vClientFk INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInFk INT; - DECLARE vIsInterCompany BOOL DEFAULT FALSE; - DECLARE vIsCEESerial BOOL DEFAULT FALSE; - DECLARE vIsCorrectInvoiceDate BOOL; - DECLARE vMaxShipped DATE; - DECLARE vDone BOOL; - DECLARE vTicketFk INT; - DECLARE vCursor CURSOR FOR - SELECT id - FROM tmp.ticketToInvoice; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); - - SELECT t.clientFk, - t.companyFk, - MAX(DATE(t.shipped)), - DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( - vSerial, - t.companyFk, - YEAR(vInvoiceDate)) - INTO vClientFk, - vCompanyFk, - vMaxShipped, - vIsCorrectInvoiceDate - FROM tmp.ticketToInvoice tt - JOIN ticket t ON t.id = tt.id; - - IF(vMaxShipped > vInvoiceDate) THEN - CALL util.throw("Invoice date can't be less than max date"); - END IF; - - IF NOT vIsCorrectInvoiceDate THEN - CALL util.throw('Exists an invoice with a previous date'); - END IF; - - -- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM tmp.ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN supplier su ON su.id = t.companyFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE - OR itc.id IS NULL; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 - INTO vIsAnySaleToInvoice - FROM tmp.ticketToInvoice t - JOIN sale s ON s.ticketFk = t.id; - - SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice - FROM tmp.ticketToInvoice t - JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - siiTypeInvoiceOutFk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClientFk, - getDueDate(vInvoiceDate, dueDay), - vCompanyFk, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClientFk; - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - OPEN vCursor; - l: LOOP - SET vDone = FALSE; - FETCH vCursor INTO vTicketFk; - - IF vDone THEN - LEAVE l; - END IF; - - CALL ticket_recalc(vTicketFk, vTaxArea); - - END LOOP; - CLOSE vCursor; - - UPDATE ticket t - JOIN tmp.ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticketFk - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); - - INSERT INTO ticketTracking(stateFk,ticketFk,userFk) - SELECT * FROM tmp.updateInter; - - CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) total - FROM invoiceOutExpense - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT COUNT(*), id - INTO vIsInterCompany, vInterCompanyFk - FROM company - WHERE clientFk = vClientFk; - - IF (vIsInterCompany) THEN - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; - - SET vNewInvoiceInFk = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - @vTaxableBaseServices, - sub.expenseFk, - sub.taxTypeSageFk, - sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, - i.expenseFk, - i.taxTypeSageFk, - i.transactionTypeSageFk, - @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, - @vTaxableBaseServices, 0) taxableBase, - i.expenseFk, - i.taxTypeSageFk , - i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL invoiceInDueDay_calculate(vNewInvoiceInFk); - - SELECT COUNT(*) INTO vIsCEESerial - FROM invoiceOutSerial - WHERE code = vSerial; - - IF vIsCEESerial THEN - - INSERT INTO invoiceInIntrastat ( - invoiceInFk, - intrastatFk, - amount, - stems, - countryFk, - net) - SELECT - vNewInvoiceInFk, - i.intrastatFk, - SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), - SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), - su.countryFk, - CAST(SUM(IFNULL(i.stems, 1) - * s.quantity - * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) - FROM sale s - JOIN ticket t ON s.ticketFk = t.id - JOIN supplier su ON su.id = t.companyFk - JOIN item i ON i.id = s.itemFk - LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - WHERE t.refFk = vNewRef - GROUP BY i.intrastatFk; - - END IF; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - END IF; - END IF; - DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingRadar`(vSectorFk INT) -proc:BEGIN - - DECLARE vCalcVisibleFk INT; - DECLARE vCalcAvailableFk INT; - DECLARE hasFatherSector BOOLEAN; - DECLARE vBuyerFk INT DEFAULT 0; - DECLARE vWarehouseFk INT DEFAULT 0; - DECLARE vSonSectorFk INT; - DECLARE vWorkerFk INT; - - SELECT s.workerFk - INTO vWorkerFk - FROM vn.sector s - WHERE s.id = vSectorFk; - - SELECT w.id, s.warehouseFk INTO vBuyerFk, vWarehouseFk - FROM vn.worker w - JOIN vn.sector s ON s.code = w.code - WHERE s.id = vSectorFk; - - SELECT s.id INTO vSectorFk - FROM vn.sector s - WHERE s.warehouseFk = vWarehouseFk - AND s.isMain; - - SELECT COUNT(*) INTO hasFatherSector - FROM vn.sector - WHERE sonFk = vSectorFk; - - SELECT warehouseFk, sonFk INTO vWarehouseFk, vSonSectorFk - FROM vn.sector - WHERE id = vSectorFk; - - CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); - CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); - - DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar; - - IF hasFatherSector THEN - CREATE TEMPORARY TABLE tmp.itemShelvingRadar - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT * - FROM ( - SELECT iss.itemFk, - i.longName, - i.size, - i.subName producer, - IFNULL(a.available,0) available, - SUM(IF(s.sonFk = vSectorFk, IFNULL(iss.visible,0), 0)) upstairs, - SUM(IF(iss.sectorFk = vSectorFk, IFNULL(iss.visible,0), 0)) downstairs, - IF(it.isPackaging, NULL, IFNULL(v.visible,0)) as visible, - vSectorFk sectorFk - FROM vn.itemShelvingStock iss - JOIN vn.sector s ON s.id = iss.sectorFk - JOIN vn.item i on i.id = iss.itemFk - JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk) - LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk - LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk - WHERE vSectorFk IN (iss.sectorFk, s.sonFk) - GROUP BY iss.itemFk - - UNION ALL - - SELECT v.item_id, - i.longName, - i.size, - i.subName producer, - IFNULL(a.available,0) as available, - 0 upstairs, - 0 downstairs, - IF(it.isPackaging, NULL, v.visible) visible, - vSectorFk as sectorFk - FROM cache.visible v - JOIN vn.item i on i.id = v.item_id - JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk) - LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk - LEFT JOIN cache.available a ON a.item_id = v.item_id AND a.calc_id = vCalcAvailableFk - WHERE v.calc_id = vCalcVisibleFk - AND iss.itemFk IS NULL - AND it.isInventory - ) sub GROUP BY itemFk; - - SELECT ishr.*, - CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho, - CAST(downstairs - IFNULL(notPickedYed,0) AS DECIMAL(10,0)) as pendiente - FROM tmp.itemShelvingRadar ishr - JOIN vn.item i ON i.id = ishr.itemFk - LEFT JOIN (SELECT s.itemFk, sum(s.quantity) as notPickedYed - FROM vn.ticket t - JOIN vn.ticketStateToday tst ON tst.ticketFk = t.id - JOIN vn.sale s ON s.ticketFk = t.id - WHERE t.warehouseFk = vWarehouseFk - AND tst.alertLevel = 0 - GROUP BY s.itemFk - ) sub ON sub.itemFk = ishr.itemFk - ORDER BY i.typeFk, i.longName; - ELSE - CREATE TEMPORARY TABLE tmp.itemShelvingRadar - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT iss.itemFk, - 0 `hour`, - 0 `minute`, - '--' itemPlacementCode, - i.longName, - i.size, - i.subName producer, - i.upToDown, - IFNULL(a.available,0) available, - IFNULL(v.visible - iss.visible,0) dayEndVisible, - IFNULL(v.visible - iss.visible,0) firstNegative, - IFNULL(v.visible - iss.visible,0) itemPlacementVisible, - IFNULL(i.minimum * b.packing,0) itemPlacementSize, - ips.onTheWay, - iss.visible itemShelvingStock, - IFNULL(v.visible,0) visible, - b.isPickedOff, - iss.sectorFk - FROM vn.itemShelvingStock iss - JOIN vn.item i on i.id = iss.itemFk - LEFT JOIN cache.last_buy lb ON lb.item_id = iss.itemFk AND lb.warehouse_id = vWarehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk - LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk - LEFT JOIN (SELECT itemFk, sum(saldo) as onTheWay - FROM vn.itemPlacementSupplyList - WHERE saldo > 0 - GROUP BY itemFk - ) ips ON ips.itemFk = i.id - WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk) - OR iss.sectorFk = vSectorFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.itemOutTime; - CREATE TEMPORARY TABLE tmp.itemOutTime - SELECT *,SUM(amount) quantity - FROM - (SELECT item_id itemFk, - amount, - IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours, - IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes - FROM vn2008.item_out io - JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.item_id - JOIN vn.ticket t on t.id= io.ticketFk - JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk - JOIN vn.state s ON s.id = ts.stateFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN (SELECT DISTINCT saleFk - FROM vn.saleTracking st - WHERE st.created > util.VN_CURDATE() - AND st.isChecked - ) stPrevious ON `stPrevious`.`saleFk` = io.saleFk - WHERE t.warehouseFk = vWarehouseFk - AND s.isPicked = 0 - AND NOT io.Reservado - AND stPrevious.saleFk IS NULL - AND io.dat >= util.VN_CURDATE() - AND io.dat < util.VN_CURDATE() + INTERVAL 1 DAY - ) sub - GROUP BY itemFk, hours, minutes; - - INSERT INTO tmp.itemShelvingRadar (itemFk) - SELECT itemFk FROM tmp.itemOutTime - ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity, - firstNegative = if (firstNegative < 0, firstNegative, firstNegative + quantity), - `hour` = ifnull(if (firstNegative > 0 , `hour`, hours),0), - `minute` = ifnull(if (firstNegative > 0, `minute`, minutes),0); - - UPDATE tmp.itemShelvingRadar isr - JOIN (SELECT s.itemFk, sum(s.quantity) amount - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN ticketLastState tls ON tls.ticketFk = t.id - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND tls.name = 'Prep Camara' - GROUP BY s.itemFk) sub ON sub.itemFk = isr.itemFk - SET isr.dayEndVisible = dayEndVisible + sub.amount, - firstNegative = firstNegative + sub.amount; - - SELECT * FROM tmp.itemShelvingRadar; - END IF; - - DROP TEMPORARY TABLE tmp.itemShelvingRadar; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`( - vItemFk INT, - vWarehouseFk INT, - vDate DATETIME -) -BEGIN -/** - * @vItemFk item a buscar - * @vWarehouseFk almacen donde buscar - * @vDate Si la fecha es null, muestra el histórico desde el inventario. - * Si la fecha no es null, muestra histórico desde la fecha pasada. - */ - DECLARE vDateInventory DATETIME; - - IF vDate IS NULL THEN - SELECT inventoried INTO vDateInventory - FROM config; - ELSE - SELECT mockUtcTime INTO vDateInventory - FROM util.config; - END IF; - - CREATE OR REPLACE TEMPORARY TABLE tItemDiary( - shipped DATE, - `in` INT(11), - `out` INT(11), - alertLevel INT(11), - stateName VARCHAR(20), - `name` VARCHAR(50), - reference VARCHAR(50), - origin INT(11), - clientFk INT(11), - isPicked INT(11), - isTicket TINYINT(1), - lineFk INT(11), - `order` TINYINT(3) UNSIGNED, - clientType VARCHAR(20), - claimFk INT(10) UNSIGNED, - inventorySupplierFk INT(10) - ); - - INSERT INTO tItemDiary - SELECT tr.landed shipped, - b.quantity `in`, - NULL `out`, - st.alertLevel , - st.name stateName, - s.name `name`, - e.invoiceNumber reference, - e.id origin, - s.id clientFk, - IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, - FALSE isTicket, - b.id lineFk, - NULL `order`, - NULL clientType, - NULL claimFk, - ec.inventorySupplierFk - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN supplier s ON s.id = e.supplierFk - JOIN state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() - OR (util.VN_CURDATE() AND tr.isReceived), - 'DELIVERED', - 'FREE') - JOIN entryConfig ec - WHERE tr.landed >= vDateInventory - AND vWarehouseFk = tr.warehouseInFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) - AND b.itemFk = vItemFk - AND e.isExcludedFromAvailable = FALSE - AND e.isRaid = FALSE - UNION ALL - SELECT tr.shipped, - NULL, - b.quantity, - st.alertLevel, - st.name, - s.name, - e.invoiceNumber, - e.id, - s.id, - IF(st.`code` = 'DELIVERED' , TRUE, FALSE), - FALSE, - b.id, - NULL, - NULL, - NULL, - ec.inventorySupplierFk - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN warehouse w ON w.id = tr.warehouseOutFk - JOIN supplier s ON s.id = e.supplierFk - JOIN state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE() - OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), - 'DELIVERED', - 'FREE') - JOIN entryConfig ec - WHERE tr.shipped >= vDateInventory - AND vWarehouseFk = tr.warehouseOutFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) - AND b.itemFk = vItemFk - AND e.isExcludedFromAvailable = FALSE - AND w.isFeedStock = FALSE - AND e.isRaid = FALSE - UNION ALL - SELECT DATE(t.shipped), - NULL, - s.quantity, - st2.alertLevel, - st2.name, - t.nickname, - t.refFk, - t.id, - t.clientFk, - stk.id, - TRUE, - s.id, - st.`order`, - ct.`code`, - cb.claimFk, - NULL - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - LEFT JOIN state st ON st.`code` = ts.`code` - JOIN client c ON c.id = t.clientFk - JOIN clientType ct ON ct.id = c.clientTypeFk - JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), - 'DELIVERED', - IF (t.shipped > util.dayEnd(util.VN_CURDATE()), - 'FREE', - IFNULL(ts.code, 'FREE'))) - LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' - LEFT JOIN saleTracking stk ON stk.saleFk = s.id - AND stk.stateFk = stPrep.id - LEFT JOIN claimBeginning cb ON s.id = cb.saleFk - WHERE t.shipped >= vDateInventory - AND s.itemFk = vItemFk - AND vWarehouseFk =t.warehouseFk - ORDER BY shipped, - (inventorySupplierFk = clientFk) DESC, - alertLevel DESC, - isTicket, - `order` DESC, - isPicked DESC, - `in` DESC, - `out` DESC; - - IF vDate IS NULL THEN - - SET @a := 0; - SET @currentLineFk := 0; - SET @shipped := ''; - - SELECT DATE(@shipped:= shipped) shipped, - alertLevel, - stateName, - origin, - reference, - clientFk, - name, - `in` invalue, - `out`, - @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0) balance, - @currentLineFk := IF (@shipped < util.VN_CURDATE() - OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')), - lineFk, - @currentLineFk) lastPreparedLineFk, - isTicket, - lineFk, - isPicked, - clientType, - claimFk - FROM tItemDiary - LEFT JOIN alertLevel a ON a.id = tItemDiary.alertLevel; - - ELSE - SELECT SUM(`in`) - SUM(`out`) INTO @a - FROM tItemDiary - WHERE shipped < vDate; - - SELECT vDate shipped, - 0 alertLevel, - 0 stateName, - 0 origin, - '' reference, - 0 clientFk, - 'Inventario calculado', - @a invalue, - NULL `out`, - @a balance, - 0 lastPreparedLineFk, - 0 isTicket, - 0 lineFk, - 0 isPicked, - 0 clientType, - 0 claimFk - UNION ALL - SELECT shipped, - alertlevel, - stateName, - origin, - reference, - clientFk, - name, `in`, - `out`, - @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), - 0, - isTicket, - lineFk, - isPicked, - clientType, - claimFk - FROM tItemDiary - WHERE shipped >= vDate; - END IF; - - DROP TEMPORARY TABLE tItemDiary; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`productionControl`( - vWarehouseFk INT, - vScopeDays INT -) -proc: BEGIN -/** - * Devuelve un listado de tickets con parámetros relativos a la producción de los días en rango. - * - * @param vWarehouseFk Identificador de warehouse - * @param vScopeDays Número de días desde hoy en adelante que entran en el cálculo. - * - * @return Table tmp.productionBuffer - */ - DECLARE vEndingDate DATETIME; - DECLARE vIsTodayRelative BOOLEAN; - - SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY - INTO vEndingDate - FROM productionConfig; - - SELECT isTodayRelative INTO vIsTodayRelative - FROM worker - WHERE id = getUser(); -- Cambiar por account.myUser_getId(), falta dar permisos - - CALL prepareTicketList(util.yesterday(), vEndingDate); - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT * FROM tmp.productionTicket; - - CALL prepareClientList(); - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems - (INDEX (ticketFk)) ENGINE = MEMORY - SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped - FROM tmp.productionTicket tt - JOIN ticket t ON t.id = tt.ticketFk; - - CALL ticket_getProblems(vIsTodayRelative); - - CREATE OR REPLACE TEMPORARY TABLE tmp.productionBuffer - (PRIMARY KEY(ticketFk), previaParking VARCHAR(255)) - ENGINE = MEMORY - SELECT tt.ticketFk, - tt.clientFk, - t.warehouseFk, - t.nickname, - t.packages, - IF(HOUR(t.shipped), HOUR(t.shipped), COALESCE(HOUR(zc.hour),HOUR(z.hour))) HH, - COALESCE(HOUR(zc.hour), HOUR(z.hour)) Departure, - COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) mm, - t.routeFk, - IF(dm.code = 'DELIVERY', z.`id`, 0) zona, - t.nickname addressNickname, - a.postalCode, - a.city, - p.name province, - CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency, - am.id agencyModeFk, - 0 `lines`, - CAST( 0 AS DECIMAL(5,2)) m3, - CAST( 0 AS DECIMAL(5,2)) preparationRate, - "" problem, - IFNULL(tls.state,2) state, - w.code workerCode, - DATE(t.shipped) shipped, - wk.code salesPersonCode, - p.id provinceFk, - tls.productionOrder, - IFNULL(tls.alertLevel, 0) alertLevel, - t.isBoxed palletized, - IF(rm.isPickingAllowed, rm.bufferFk, NULL) ubicacion, - tlu.lastUpdated, - IFNULL(st.graphCategory, 0) graphCategory, - pk.code parking, - 0 H, - 0 V, - 0 N, - st.isOk, - ag.isOwn, - rm.bufferFk - FROM tmp.productionTicket tt - JOIN ticket t ON tt.ticketFk = t.id - LEFT JOIN ticketStateToday tst ON tst.ticket = t.id - LEFT JOIN state st ON st.id = tst.state - LEFT JOIN client c ON c.id = t.clientFk - LEFT JOIN worker wk ON wk.id = c.salesPersonFk - JOIN address a ON a.id = t.addressFk - LEFT JOIN province p ON p.id = a.provinceFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - JOIN agency ag ON ag.id = am.agencyFk - LEFT JOIN ticketState tls ON tls.ticketFk = tt.ticketFk - LEFT JOIN ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk - LEFT JOIN worker w ON w.id = tls.userFk - LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN `zone` z ON z.id = t.zoneFk - LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk - AND DATE(t.shipped) = zc.dated - LEFT JOIN ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN parking pk ON pk.id = tp.parkingFk - WHERE t.warehouseFk = vWarehouseFk - AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); - - UPDATE tmp.productionBuffer pb - JOIN ( - SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking - FROM tmp.productionBuffer pb - JOIN sale s ON s.ticketFk = pb.ticketFk - JOIN saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - JOIN parking p ON p.id = sg.parkingFk - GROUP BY pb.ticketFk - ) t ON t.ticketFk = pb.ticketFk - SET pb.previaParking = t.previaParking; - - -- Problemas por ticket - ALTER TABLE tmp.productionBuffer - CHANGE COLUMN `problem` `problem` VARCHAR(255), - ADD COLUMN `collectionH` INT, - ADD COLUMN `collectionV` INT, - ADD COLUMN `collectionN` INT; - - UPDATE tmp.productionBuffer pb - JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk - SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage, ''), - IFNULL(tp.itemDelay, ''), - IFNULL(tp.itemLost, ''), - IF(tp.isFreezed, ' CONGELADO',''), - IF(tp.hasHighRisk, ' RIESGO',''), - IF(tp.hasTicketRequest, ' COD 100',''), - IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), - IF(tp.hasComponentLack, ' COMPONENTES', ''), - IF(HOUR(util.VN_NOW()) < pb.HH AND tp.isTooLittle, ' PEQUEÑO', '') - ) AS char(255))); - - -- Clientes Nuevos o Recuperados - UPDATE tmp.productionBuffer pb - LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk - JOIN productionConfig pc - SET pb.problem = TRIM(CAST(CONCAT('NUEVO ', pb.problem) AS CHAR(255))) - WHERE (cnb.clientFk IS NULL OR cnb.isRookie) - AND pc.rookieDays; - - -- Líneas y volumen por ticket - UPDATE tmp.productionBuffer pb - JOIN ( - SELECT tt.ticketFk, - COUNT(*) `lines`, - SUM(sv.volume) m3, - IFNULL(SUM(IF(sv.isPicked, sv.volume, 0)) / SUM(sv.volume), 0) rate - FROM tmp.productionTicket tt - JOIN saleVolume sv ON sv.ticketFk = tt.ticketFk - GROUP BY tt.ticketFk - ) m ON m.ticketFk = pb.ticketFk - SET pb.`lines` = m.`lines`, - pb.m3 = m.m3, - pb.preparationRate = m.rate; - - DELETE FROM tmp.productionBuffer - WHERE NOT `lines`; - - -- Lineas por linea de encajado - UPDATE tmp.productionBuffer pb - JOIN ( - SELECT ticketFk, - SUM(sub.H) H, - SUM(sub.V) V, - SUM(sub.N) N - FROM ( - SELECT t.ticketFk, - SUM(i.itemPackingTypeFk = 'H') H, - SUM(i.itemPackingTypeFk = 'V') V, - SUM(i.itemPackingTypeFk IS NULL) N - FROM tmp.productionTicket t - JOIN sale s ON s.ticketFk = t.ticketFk - JOIN item i ON i.id = s.itemFk - GROUP BY t.ticketFk, i.itemPackingTypeFk - ) sub - GROUP BY ticketFk - ) sub2 ON sub2.ticketFk = pb.ticketFk - SET pb.H = sub2.H, - pb.V = sub2.V, - pb.N = sub2.N; - - -- Colecciones segun tipo de encajado - UPDATE tmp.productionBuffer pb - JOIN ticketCollection tc ON pb.ticketFk = tc.ticketFk - SET pb.collectionH = IF(pb.H, tc.collectionFk, NULL), - pb.collectionV = IF(pb.V, tc.collectionFk, NULL), - pb.collectionN = IF(pb.N, tc.collectionFk, NULL); - - -- Previa pendiente - ALTER TABLE tmp.productionBuffer - ADD previousWithoutParking BOOL DEFAULT FALSE; - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketWithPrevia - (ticketFk INT PRIMARY KEY, - salesCount INT DEFAULT 0, - salesInParkingCount INT DEFAULT 0) - ENGINE = MEMORY; - - -- Insertamos todos los tickets que tienen productos parkineados - -- en sectores de previa, segun el sector - CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock - (PRIMARY KEY(itemFk, sectorFk)) - ENGINE = MEMORY - SELECT ish.itemFk, - p.sectorFk, - sc.isPreviousPrepared, - sc.itemPackingTypeFk - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector sc ON sc.id = p.sectorFk - WHERE p.sectorFk - AND ish.visible - GROUP BY ish.itemFk, p.sectorFk; - - INSERT INTO tmp.ticketWithPrevia(ticketFk, salesCount) - SELECT pb.ticketFk, COUNT(DISTINCT s.id) - FROM tmp.productionBuffer pb - JOIN sale s ON s.ticketFk = pb.ticketFk - JOIN tItemShelvingStock iss ON iss.itemFk = s.itemFk - JOIN sector sc ON sc.id = iss.sectorFk - JOIN item i ON i.id = iss.itemFk - WHERE iss.isPreviousPrepared - AND (sc.itemPackingTypeFk IS NULL - OR (i.itemPackingTypeFk IS NULL AND NOT pb.V) - OR sc.itemPackingTypeFk = i.itemPackingTypeFk) - AND s.quantity > 0 - GROUP BY pb.ticketFk; - - -- Se calcula la cantidad de productos que estan ya preparados porque su saleGroup está aparcado - UPDATE tmp.ticketWithPrevia twp - JOIN ( - SELECT pb.ticketFk, COUNT(DISTINCT s.id) salesInParkingCount - FROM tmp.productionBuffer pb - JOIN sale s ON s.ticketFk = pb.ticketFk - JOIN saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - WHERE sg.parkingFk IS NOT NULL - AND s.quantity > 0 - GROUP BY pb.ticketFk - ) sub ON twp.ticketFk = sub.ticketFk - SET twp.salesInParkingCount = sub.salesInParkingCount; - - -- Marcamos como pendientes aquellos que no coinciden las cantidades - UPDATE tmp.productionBuffer pb - JOIN tmp.ticketWithPrevia twp ON twp.ticketFk = pb.ticketFk - SET pb.previousWithoutParking = TRUE - WHERE twp.salesCount > twp.salesInParkingCount; - - DROP TEMPORARY TABLE - tmp.productionTicket, - tmp.ticket, - tmp.risk, - tmp.ticket_problems, - tmp.ticketWithPrevia, - tItemShelvingStock; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeInsert` - BEFORE INSERT ON `expedition` - FOR EACH ROW -BEGIN - DECLARE intcounter INT; - DECLARE vShipFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.freightItemFk IS NOT NULL THEN - - UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk; - - SELECT IFNULL(MAX(counter),0) +1 INTO intcounter - FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id - LEFT JOIN ticketState ts ON ts.ticketFk = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) - AND t1.warehouseFk = t2.warehouseFk - WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk - AND t1.agencyModeFk = t2.agencyModeFk; - - SET NEW.`counter` = intcounter; - END IF; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption INT) -proc: BEGIN -/** - * Este procedimiento recalcula los componentes de un conjunto de sales, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vOption si no se quiere forzar llamar con NULL - * @table tmp.recalculateSales (id) - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicketFk INT; - DECLARE vLanded DATE; - DECLARE vIsEditable BOOLEAN; - DECLARE vZoneFk INTEGER; - DECLARE vDone BOOL DEFAULT FALSE; - - DECLARE vCur CURSOR FOR - SELECT DISTINCT s.ticketFk - FROM tmp.recalculateSales rs - JOIN vn.sale s ON s.id = rs.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN vCur; - - l: LOOP - SET vDone = FALSE; - FETCH vCur INTO vTicketFk; - - IF vDone THEN - LEAVE l; - END IF; - - SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, - t.zoneFk, - t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, - t.landed - INTO vIsEditable, - vZoneFk, - vWarehouseFk, - vShipped, - vAddressFk, - vAgencyModeFk, - vLanded - FROM ticket t - LEFT JOIN ticketState ts ON t.id = ts.ticketFk - LEFT JOIN alertLevel al ON al.id = ts.alertLevel - WHERE t.id = vTicketFk; - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - - IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN - CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); - END IF; - - IF vLanded IS NULL OR vZoneFk IS NULL THEN - - UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) - WHERE t.id = vTicketFk AND t.landed IS NULL; - - IF vZoneFk IS NULL THEN - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - UPDATE ticket t - SET t.zoneFk = vZoneFk - WHERE t.id = vTicketFk AND t.zoneFk IS NULL; - END IF; - - END IF; - - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouseFk warehouseFk - FROM sale s - JOIN tmp.recalculateSales rs ON s.id = rs.id - WHERE s.ticketFk = vTicketFk; - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk - FROM sale s - JOIN tmp.recalculateSales rs ON s.id = rs.id - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - IF vOption IS NULL THEN - SET vOption = IF(vIsEditable, 1, 6); - END IF; - - CALL ticketComponentUpdateSale(vOption); - CALL catalog_componentPurge(); - - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.sale; - - END LOOP; - CLOSE vCur; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATE, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN -/** - * Creación de facturas emitidas. - * requiere previamente tabla tmp.ticketToInvoice(id). - * - * @param vSerial serie a la cual se hace la factura - * @param vInvoiceDate fecha de la factura - * @param vTaxArea tipo de iva en relacion a la empresa y al cliente - * @param vNewInvoiceId id de la factura que se acaba de generar - * @return vNewInvoiceId - */ - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompanyFk INT; - DECLARE vInterCompanyFk INT; - DECLARE vClientFk INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInFk INT; - DECLARE vIsInterCompany BOOL DEFAULT FALSE; - DECLARE vIsCEESerial BOOL DEFAULT FALSE; - DECLARE vIsCorrectInvoiceDate BOOL; - DECLARE vMaxShipped DATE; - DECLARE vDone BOOL; - DECLARE vTicketFk INT; - DECLARE vCursor CURSOR FOR - SELECT id - FROM tmp.ticketToInvoice; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - SET vInvoiceDate = IFNULL(vInvoiceDate, util.VN_CURDATE()); - - SELECT t.clientFk, - t.companyFk, - MAX(DATE(t.shipped)), - DATE(vInvoiceDate) >= invoiceOut_getMaxIssued( - vSerial, - t.companyFk, - YEAR(vInvoiceDate)) - INTO vClientFk, - vCompanyFk, - vMaxShipped, - vIsCorrectInvoiceDate - FROM tmp.ticketToInvoice tt - JOIN ticket t ON t.id = tt.id; - - IF(vMaxShipped > vInvoiceDate) THEN - CALL util.throw("Invoice date can't be less than max date"); - END IF; - - IF NOT vIsCorrectInvoiceDate THEN - CALL util.throw('Exists an invoice with a previous date'); - END IF; - - -- Eliminem de tmp.ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM tmp.ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN supplier su ON su.id = t.companyFk - JOIN client c ON c.id = t.clientFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - WHERE (YEAR(t.shipped) < 2001 AND t.isDeleted) - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE - OR itc.id IS NULL; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100) <> 0 - INTO vIsAnySaleToInvoice - FROM tmp.ticketToInvoice t - JOIN sale s ON s.ticketFk = t.id; - - SELECT COUNT(*) > 0 INTO vIsAnyServiceToInvoice - FROM tmp.ticketToInvoice t - JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - siiTypeInvoiceOutFk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClientFk, - getDueDate(vInvoiceDate, dueDay), - vCompanyFk, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClientFk; - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - OPEN vCursor; - l: LOOP - SET vDone = FALSE; - FETCH vCursor INTO vTicketFk; - - IF vDone THEN - LEAVE l; - END IF; - - CALL ticket_recalc(vTicketFk, vTaxArea); - - END LOOP; - CLOSE vCursor; - - UPDATE ticket t - JOIN tmp.ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM tmp.ticketToInvoice ti - LEFT JOIN ticketState ts ON ti.id = ts.ticketFk - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = getAlert3State(ti.id); - - INSERT INTO ticketTracking(stateFk,ticketFk,userFk) - SELECT * FROM tmp.updateInter; - - CALL invoiceExpenseMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) total - FROM invoiceOutExpense - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT COUNT(*), id - INTO vIsInterCompany, vInterCompanyFk - FROM company - WHERE clientFk = vClientFk; - - IF (vIsInterCompany) THEN - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vCompanyFk, vNewRef, vInvoiceDate, vInterCompanyFk; - - SET vNewInvoiceInFk = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM tmp.ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - @vTaxableBaseServices, - sub.expenseFk, - sub.taxTypeSageFk, - sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, - i.expenseFk, - i.taxTypeSageFk, - i.transactionTypeSageFk, - @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInFk, - SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, - @vTaxableBaseServices, 0) taxableBase, - i.expenseFk, - i.taxTypeSageFk , - i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL invoiceInDueDay_calculate(vNewInvoiceInFk); - - SELECT COUNT(*) INTO vIsCEESerial - FROM invoiceOutSerial - WHERE code = vSerial; - - IF vIsCEESerial THEN - - INSERT INTO invoiceInIntrastat ( - invoiceInFk, - intrastatFk, - amount, - stems, - countryFk, - net) - SELECT - vNewInvoiceInFk, - i.intrastatFk, - SUM(CAST((s.quantity * s.price * (100 - s.discount) / 100 ) AS DECIMAL(10, 2))), - SUM(CAST(IFNULL(i.stems, 1) * s.quantity AS DECIMAL(10, 2))), - su.countryFk, - CAST(SUM(IFNULL(i.stems, 1) - * s.quantity - * IF(ic.grams, ic.grams, IFNULL(i.weightByPiece, 0)) / 1000) AS DECIMAL(10, 2)) - FROM sale s - JOIN ticket t ON s.ticketFk = t.id - JOIN supplier su ON su.id = t.companyFk - JOIN item i ON i.id = s.itemFk - LEFT JOIN itemCost ic ON ic.itemFk = i.id AND ic.warehouseFk = t.warehouseFk - WHERE t.refFk = vNewRef - GROUP BY i.intrastatFk; - - END IF; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - END IF; - END IF; - DROP TEMPORARY TABLE `tmp`.`ticketToInvoice`; -END$$ -DELIMITER ; diff --git a/db/changes/240201/01-refactorHasAnyNegativeBase.sql b/db/changes/240201/01-refactorHasAnyNegativeBase.sql deleted file mode 100644 index a3eb2d9c7..000000000 --- a/db/changes/240201/01-refactorHasAnyNegativeBase.sql +++ /dev/null @@ -1,32 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyNegativeBase`() RETURNS tinyint(1) - DETERMINISTIC -BEGIN - -/** -* Calcula si existe alguna base imponible negativa -* Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases() -* -* returns BOOLEAN -*/ - - DECLARE hasAnyNegativeBase BOOLEAN; - - CALL getTaxBases(); - - SELECT negative INTO hasAnyNegativeBase - FROM tmp.taxBases - LIMIT 1; - - DROP TEMPORARY TABLE - tmp.ticketTax, - tmp.ticket, - tmp.taxBases; - - RETURN hasAnyNegativeBase; - -END$$ -DELIMITER ; - - diff --git a/db/changes/240201/01-triggers.sql b/db/changes/240201/01-triggers.sql deleted file mode 100644 index a7fa029b4..000000000 --- a/db/changes/240201/01-triggers.sql +++ /dev/null @@ -1,27 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeInsert` - BEFORE INSERT ON `expedition` - FOR EACH ROW -BEGIN - DECLARE intcounter INT; - DECLARE vShipFk INT; - - SET NEW.editorFk = account.myUser_getId(); - - IF NEW.freightItemFk IS NOT NULL THEN - - UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk; - - SELECT IFNULL(MAX(counter),0) +1 INTO intcounter - FROM expedition e - INNER JOIN ticket t1 ON e.ticketFk = t1.id - LEFT JOIN ticketState ts ON ts.ticketFk = t1.id - INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) - AND t1.warehouseFk = t2.warehouseFk - WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk - AND t1.agencyModeFk = t2.agencyModeFk; - - SET NEW.`counter` = intcounter; - END IF; -END$$ -DELIMITER ; diff --git a/db/changes/240201/01-views.sql b/db/changes/240201/01-views.sql deleted file mode 100644 index 30b08b776..000000000 --- a/db/changes/240201/01-views.sql +++ /dev/null @@ -1,58 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`expeditionRoute_freeTickets` AS -SELECT - `t`.`routeFk` AS `routeFk`, - `tss`.`ticketFk` AS `ticket`, - `s`.`name` AS `code`, - `w`.`name` AS `almacen`, - `tss`.`updated` AS `updated`, - `p`.`code` AS `parkingCode` - FROM `vn`.`ticketState` `tss` - JOIN `vn`.`ticket` `t` ON `t`.`id` = `tss`.`ticketFk` - JOIN `vn`.`warehouse` `w` ON `w`.`id` = `t`.`warehouseFk` - JOIN `vn`.`state` `s` ON `s`.`id` = `tss`.`state` - LEFT JOIN `vn`.`ticketParking` `tp` ON `tp`.`ticketFk` = `t`.`id` - LEFT JOIN `vn`.`parking` `p` ON `p`.`id` = `tp`.`parkingFk` - WHERE IFNULL(`t`.`packages`, 0) = 0; - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`ticketState` -AS SELECT `tt`.`created` AS `updated`, - `tt`.`stateFk` AS `stateFk`, - `tt`.`userFk` AS `userFk`, - `tls`.`ticketFk` AS `ticketFk`, - `s`.`id` AS `state`, - `s`.`order` AS `productionOrder`, - `s`.`alertLevel` AS `alertLevel`, - `s`.`code` AS `code`, - `s`.`isPreviousPreparable` AS `isPreviousPreparable`, - `s`.`isPicked` AS `isPicked` -FROM ( - ( - `vn`.`ticketLastState` `tls` - JOIN `vn`.`ticketTracking` `tt` ON(`tt`.`id` = `tls`.`ticketTrackingFk`) - ) - JOIN `vn`.`state` `s` ON(`s`.`id` = `tt`.`stateFk`) - ); - -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`ticketStateToday` -AS -SELECT - `ts`.`ticketFk` AS `ticket`, - `ts`.`state` AS `state`, - `ts`.`productionOrder` AS `productionOrder`, - `ts`.`alertLevel` AS `alertLevel`, - `ts`.`userFk` AS `worker`, - `ts`.`code` AS `code`, - `ts`.`updated` AS `updated`, - `ts`.`isPicked` AS `isPicked` -FROM - `vn`.`ticketState` `ts` - JOIN `vn`.`ticket` `t` ON `t`.`id` = `ts`.`ticketFk` -WHERE - `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`VN_CURDATE`() + INTERVAL 1 DAY; - diff --git a/db/changes/240202/.gitkeep b/db/changes/240202/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/240202/00-aclWorkerTimeControl.sql b/db/changes/240202/00-aclWorkerTimeControl.sql deleted file mode 100644 index 5ccb3131d..000000000 --- a/db/changes/240202/00-aclWorkerTimeControl.sql +++ /dev/null @@ -1,14 +0,0 @@ -DELETE FROM salix.ACL - WHERE model = 'WorkerTimeControl' - AND property IN ('*','addTime'); - -INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) - VALUES - ('WorkerTimeControl', 'addTimeEntry', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'deleteTimeEntry', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'updateTimeEntry', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'sendMail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'updateWorkerTimeControlMail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'weeklyHourRecordEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'getMailStates', 'READ', 'ALLOW', 'ROLE', 'employee'), - ('WorkerTimeControl', 'resendWeeklyHourEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/240203/.gitkeep b/db/changes/240203/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/240203/00-viaExpressConfig.sql b/db/changes/240203/00-viaExpressConfig.sql deleted file mode 100644 index 57832e7cd..000000000 --- a/db/changes/240203/00-viaExpressConfig.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `vn`.`viaexpressConfig` ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; -ALTER TABLE `vn`.`viaexpressConfig` ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT; diff --git a/db/changes/240401/.gitkeep b/db/changes/240401/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/240401/00-removeStars.sql b/db/changes/240401/00-removeStars.sql deleted file mode 100644 index ecc1664c8..000000000 --- a/db/changes/240401/00-removeStars.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn`.`item` DROP COLUMN stars; diff --git a/db/changes/240401/00-revokeItem.sql b/db/changes/240401/00-revokeItem.sql deleted file mode 100644 index 5f6a30620..000000000 --- a/db/changes/240401/00-revokeItem.sql +++ /dev/null @@ -1,4 +0,0 @@ -REVOKE UPDATE ON TABLE `vn`.`item` FROM `employee`; - - -GRANT UPDATE(id, equivalent, stems, minPrice, isToPrint, family, box, category, doPhoto, image, inkFk, intrastatFk, hasMinPrice, created, comment, typeFk, generic, producerFk, description, density, relevancy, expenseFk, isActive, subName, tag5, value5, tag6, value6, tag7, value7, tag8, value8, tag9, value9, tag10, value10, minimum, upToDown, supplyResponseFk, hasKgPrice, isFloramondo, isFragile, numberOfItemsPerCask, embalageCode, quality, stemMultiplier, itemPackingTypeFk, packingOut, genericFk, packingShelve, isLaid, lastUsed, weightByPiece, weightByPiece, editorFk, recycledPlastic, nonRecycledPlastic, minQuantity) ON TABLE `vn`.`item` TO `employee`; diff --git a/db/changes/240401/00-supplier.sql b/db/changes/240401/00-supplier.sql deleted file mode 100644 index e60707eca..000000000 --- a/db/changes/240401/00-supplier.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais'; - - -ALTER TABLE `vn`.`supplierAccount` -ADD COLUMN `countryFk` mediumint(8) unsigned DEFAULT NULL, -ADD CONSTRAINT `fk_supplierAccount_country` - FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE; - -ALTER TABLE `vn`.`supplierAccount` -ADD UNIQUE KEY `uk_supplier_country` (`supplierFk`, `countryFk`); - - diff --git a/db/changes/240401/00-ticketSmsToClientSms.sql b/db/changes/240401/00-ticketSmsToClientSms.sql deleted file mode 100644 index cd3cf7dd3..000000000 --- a/db/changes/240401/00-ticketSmsToClientSms.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE `vn`.`clientSms` ADD `ticketFk` int(11) NULL; -ALTER TABLE `vn`.`clientSms` ADD CONSTRAINT `clientSms_FK_2` FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - -INSERT INTO`vn`.`clientSms` (`clientFk`, `smsFk`, `ticketFk`) - SELECT `t`.`clientFk`, `s`.`smsFk`, `s`.`ticketFk` - FROM `vn`.`clientSms` `s` - JOIN `vn`.`ticket` `t` ON `t`.`id` = `s`.`ticketFk`; - -RENAME TABLE `vn`.`ticketSms` TO `vn`.`ticketSms__`; diff --git a/db/changes/240401/00-ticket_canbePostponed.sql b/db/changes/240401/00-ticket_canbePostponed.sql deleted file mode 100644 index e0fbb99cf..000000000 --- a/db/changes/240401/00-ticket_canbePostponed.sql +++ /dev/null @@ -1,74 +0,0 @@ -DELIMITER $$ -$$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vWarehouseFk INT) -BEGIN -/** - * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * - * @param vOriginDated Fecha en cuestión - * @param vFutureDated Fecha en el futuro a sondear - * @param vWarehouseFk Identificador de vn.warehouse - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.filter - (INDEX (id)) - SELECT sv.ticketFk id, - sub2.id futureId, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, - st.name state, - sub2.iptd futureIpt, - sub2.state futureState, - t.clientFk, - t.warehouseFk, - ts.alertLevel, - t.shipped, - t.totalWithVat, - sub2.shipped futureShipped, - t.workerFk, - st.code stateCode, - sub2.code futureStateCode, - st.classColor, - sub2.classColor futureClassColor - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticket t ON t.id = sv.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.country c ON c.id = p.countryFk - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.alertLevel al ON al.id = ts.alertLevel - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN ( - SELECT * - FROM ( - SELECT - t.addressFk, - t.id, - t.shipped, - st.name state, - st.code, - st.classColor, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd - FROM vn.ticket t - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - WHERE t.shipped BETWEEN vFutureDated - AND util.dayend(vFutureDated) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) sub - GROUP BY sub.addressFk - ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id - WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated) - AND t.warehouseFk = vWarehouseFk - AND al.code = 'FREE' - AND tp.ticketFk IS NULL - GROUP BY sv.ticketFk - HAVING futureId; -END$$ -DELIMITER ; diff --git a/db/changes/240401/00-updateACL_Role_VnRole.sql b/db/changes/240401/00-updateACL_Role_VnRole.sql deleted file mode 100644 index 5d108ac44..000000000 --- a/db/changes/240401/00-updateACL_Role_VnRole.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId) VALUES - ('VnRole','*','READ','ALLOW','ROLE','employee'), - ('VnRole','*','WRITE','ALLOW','ROLE','it'); - -DELETE FROM`salix`.`ACL` WHERE model='Role'; - diff --git a/db/changes/240401/01-saleGroupDetailDefaultSize.sql b/db/changes/240401/01-saleGroupDetailDefaultSize.sql deleted file mode 100644 index 34529ba78..000000000 --- a/db/changes/240401/01-saleGroupDetailDefaultSize.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `vn`.`productionConfig` ADD itemPreviousDefaultSize int NULL COMMENT 'Altura por defecto para los artículos de previa'; -UPDATE IGNORE `vn`.`productionConfig` SET itemPreviousDefaultSize = 40 WHERE id = 1; diff --git a/db/changes/240401/01-supplierAccount.sql b/db/changes/240401/01-supplierAccount.sql deleted file mode 100644 index 21ce7c71e..000000000 --- a/db/changes/240401/01-supplierAccount.sql +++ /dev/null @@ -1,9 +0,0 @@ -UPDATE `vn`.`supplierAccount` sa - JOIN `vn`.`country` c ON sa.countryFk = c.id AND c.code = 'FR' - SET countryFk = c.id - WHERE iban = 'FR7630003012690002801121597'; - -UPDATE `vn`.`supplierAccount` sa - JOIN `vn`.`country` c ON sa.countryFk = c.id AND c.code = 'PT' - SET countryFk = c.id - WHERE iban = 'PT50001000005813059150168'; diff --git a/db/changes/240401/03-fixInvoiceOutBeforeInsert.sql b/db/changes/240401/03-fixInvoiceOutBeforeInsert.sql deleted file mode 100644 index 0081c8803..000000000 --- a/db/changes/240401/03-fixInvoiceOutBeforeInsert.sql +++ /dev/null @@ -1,59 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeInsert` - BEFORE INSERT ON `invoiceOut` - FOR EACH ROW -BEGIN -/** - * Generates the next reference for the invoice serial. There cannot be gaps - * between identifiers of the same serial! - * - * Reference format: - * {0} Invoice serial - * {1} The company code - * {2-3} Last two digits of issue year - * {4-$} Autoincrement identifier - */ - DECLARE vRef INT DEFAULT 0; - DECLARE vRefLen INT; - DECLARE vRefPrefix VARCHAR(255); - DECLARE vLastRef VARCHAR(255); - DECLARE vCompanyCode INT; - DECLARE vYearLen INT DEFAULT 2; - DECLARE vPrefixLen INT; - - SELECT companyCode INTO vCompanyCode - FROM company - WHERE id = NEW.companyFk; - - IF vCompanyCode IS NULL THEN - CALL util.throw('companyCodeNotDefined'); - END IF; - - SELECT MAX(i.ref) INTO vLastRef - FROM invoiceOut i - WHERE i.serial = NEW.serial - AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.lastDayOfYear(NEW.issued) - AND i.companyFk = NEW.companyFk; - - IF vLastRef IS NOT NULL THEN - SET vPrefixLen = LENGTH(NEW.serial) + LENGTH(vCompanyCode) + vYearLen; - SET vRefLen = LENGTH(vLastRef) - vPrefixLen; - SET vRefPrefix = LEFT(vLastRef, vPrefixLen); - SET vRef = RIGHT(vLastRef, vRefLen); - ELSE - SELECT refLen INTO vRefLen FROM invoiceOutConfig; - SET vRefPrefix = CONCAT( - NEW.serial, - vCompanyCode, - RIGHT(YEAR(NEW.issued), vYearLen) - ); - END IF; - - SET vRef = vRef + 1; - IF LENGTH(vRef) > vRefLen THEN - CALL util.throw('refIdLenExceeded'); - END IF; - - SET NEW.ref = CONCAT(vRefPrefix, LPAD(vRef, vRefLen, '0')); -END$$ -DELIMITER ; diff --git a/db/changes/240403/00-saleComponent.sql b/db/changes/240403/00-saleComponent.sql deleted file mode 100644 index ea2b9c399..000000000 --- a/db/changes/240403/00-saleComponent.sql +++ /dev/null @@ -1,589 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption VARCHAR(25)) -proc: BEGIN -/** - * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes - * - * @param vSelf Id de la venta - * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - SELECT s.id - FROM sale s - WHERE s.id = vSelf; - - CALL sale_recalcComponent(vOption); - - DROP TEMPORARY TABLE tmp.recalculateSales; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) -BEGIN -/** - * Comprueba que las ventas creadas entre un rango de fechas tienen componentes - * - * @param vCreatedFrom inicio del rango - * @param vCreatedTo fin del rango - */ - DECLARE v_done BOOL DEFAULT FALSE; - DECLARE vSaleFk INTEGER; - DECLARE vTicketFk INTEGER; - DECLARE vConcept VARCHAR(50); - DECLARE vCur CURSOR FOR - SELECT s.id - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - LEFT JOIN tmp.coste c ON c.id = s.id - WHERE s.created >= vCreatedFrom AND s.created <= vCreatedTo - AND c.id IS NULL - AND t.agencyModeFk IS NOT NULL - AND t.isDeleted IS FALSE - AND t.warehouseFk = 60 - AND ic.merchandise != FALSE - GROUP BY s.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; - - DROP TEMPORARY TABLE IF EXISTS tmp.coste; - - DROP TEMPORARY TABLE IF EXISTS tmp.coste; - CREATE TEMPORARY TABLE tmp.coste - (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT s.id - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 6 - WHERE s.created >= vCreatedFrom - AND ic.merchandise != FALSE; - - OPEN vCur; - - l: LOOP - SET v_done = FALSE; - FETCH vCur INTO vSaleFk; - - IF v_done THEN - LEAVE l; - END IF; - - SELECT ticketFk, concept - INTO vTicketFk, vConcept - FROM sale - WHERE id = vSaleFk; - - CALL sale_calculateComponent(vSaleFk, 'renewPrices'); - END LOOP; - - CLOSE vCur; - DROP TEMPORARY TABLE tmp.coste; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25)) -proc: BEGIN -/** - * Este procedimiento recalcula los componentes de un conjunto de sales, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vOption si no se quiere forzar llamar con NULL - * @table tmp.recalculateSales (id) - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicketFk INT; - DECLARE vLanded DATE; - DECLARE vIsEditable BOOLEAN; - DECLARE vZoneFk INTEGER; - DECLARE vDone BOOL DEFAULT FALSE; - - DECLARE vCur CURSOR FOR - SELECT DISTINCT s.ticketFk - FROM tmp.recalculateSales rs - JOIN vn.sale s ON s.id = rs.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN vCur; - - l: LOOP - SET vDone = FALSE; - FETCH vCur INTO vTicketFk; - - IF vDone THEN - LEAVE l; - END IF; - - SELECT (hasToRecalcPrice OR ts.alertLevel IS NULL) AND t.refFk IS NULL, - t.zoneFk, - t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, - t.landed - INTO vIsEditable, - vZoneFk, - vWarehouseFk, - vShipped, - vAddressFk, - vAgencyModeFk, - vLanded - FROM ticket t - LEFT JOIN ticketState ts ON t.id = ts.ticketFk - LEFT JOIN alertLevel al ON al.id = ts.alertLevel - WHERE t.id = vTicketFk; - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - - IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN - CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); - END IF; - - IF vLanded IS NULL OR vZoneFk IS NULL THEN - - UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) - WHERE t.id = vTicketFk AND t.landed IS NULL; - - IF vZoneFk IS NULL THEN - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - UPDATE ticket t - SET t.zoneFk = vZoneFk - WHERE t.id = vTicketFk AND t.zoneFk IS NULL; - END IF; - - END IF; - - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouseFk warehouseFk - FROM sale s - JOIN tmp.recalculateSales rs ON s.id = rs.id - WHERE s.ticketFk = vTicketFk; - - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk - FROM sale s - JOIN tmp.recalculateSales rs ON s.id = rs.id - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - IF vOption IS NULL THEN - SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); - END IF; - - CALL ticketComponentUpdateSale(vOption); - CALL catalog_componentPurge(); - - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.sale; - - END LOOP; - CLOSE vCur; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) -BEGIN -/* - * Recalcula los componentes un ticket clonado, - * las lineas a precio cero fuerza para que tengan precio, el resto lo respeta - * @param vTicketNew nuevo ticket clonado - * @param vTicketOld icket original, a partir del qual se clonara el nuevo -*/ - - REPLACE INTO orderTicket(orderFk,ticketFk) - SELECT orderFk, vTicketNew - FROM orderTicket - WHERE ticketFk = vTicketOld; - - -- Bionizamos lineas con Preu = 0 - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id - FROM sale - WHERE ticketFk = vTicketNew AND price = 0; - - CALL sale_recalcComponent('renewPrices'); - - -- Bionizamos lineas con Preu > 0 - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id - FROM sale - WHERE ticketFk = vTicketNew AND price > 0; - - CALL sale_recalcComponent('imbalance'); - - DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; - -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( - vTicketFk INT, - vClientFk INT, - vAgencyModeFk INT, - vAddressFk INT, - vWarehouseFk TINYINT, - vCompanyFk SMALLINT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption VARCHAR(25)) -BEGIN - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t - JOIN address a ON a.id = vAddressFk - SET t.nickname = a.nickname - WHERE t.id = vTicketFk; - END IF; - - UPDATE ticket t - SET - t.clientFk = vClientFk, - t.agencyModeFk = vAgencyModeFk, - t.addressFk = vAddressFk, - t.warehouseFk = vWarehouseFk, - t.companyFk = vCompanyFk, - t.landed = vLanded, - t.shipped = vShipped, - t.isDeleted = vIsDeleted - WHERE - t.id = vTicketFk; - - IF vHasToBeUnrouted THEN - UPDATE ticket t SET t.routeFk = NULL - WHERE t.id = vTicketFk; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - - CALL ticketComponentUpdateSale (vOption); - - DROP TEMPORARY TABLE tmp.sale; - COMMIT; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) -BEGIN -/** - * A partir de la tabla tmp.sale, crea los Movimientos_componentes - * y modifica el campo Preu de la tabla Movimientos - * - * @param i_option integer tipo de actualizacion - * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk - **/ - DECLARE vComponentFk INT; - - IF vCode <> 'renewPrices' THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; - END IF; - - DELETE sc.* - FROM tmp.sale tmps - JOIN saleComponent sc ON sc.saleFk = tmps.saleFk - JOIN `component` c ON c.id = sc.componentFk - WHERE c.isRenewable; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, tc.componentFk, tc.cost - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk - WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); - - -- Añadir componente venta por paquete - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT t.id, t.componentFk, t.cost - FROM ( - SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto - FROM vn.sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id - JOIN vn.buy b ON b.id = buy_id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' - LEFT JOIN ( - SELECT s.id - FROM vn.sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk - JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' - ) tp ON tp.id = s.id - WHERE tp.id IS NULL - HAVING resto <> 0) t; - - IF vCode <> 'renewPrices' THEN - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.saleFk <> vComponentFk - GROUP BY s.id - HAVING dif <> 0; - ELSE - UPDATE sale s - JOIN item i on i.id = s.itemFk - JOIN itemType it on it.id = i.typeFk - JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - GROUP BY sc.saleFk) sc ON sc.saleFk = s.id - SET s.price = sumValue / ((100 - s.discount) / 100) - WHERE it.code != 'PRT' ; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.componentFk != 21 - GROUP BY s.id - HAVING ROUND(saleValue, 4) <> 0; - END IF; - - UPDATE sale s - JOIN ( - SELECT SUM(sc.value) sumValue, sc.saleFk - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - JOIN `component` c ON c.id = sc.componentFk - JOIN componentType ct on ct.id = c.typeFk AND ct.isBase - GROUP BY sc.saleFk) sc ON sc.saleFk = s.id - SET s.priceFixed = sumValue, s.isPriceFixed = 1; - - DELETE sc.* - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - JOIN sale s on s.id = sc.saleFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT'; - - INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 15, s.price - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN item i ON i.id = s.itemFK - JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT' AND s.price > 0; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) -BEGIN - -/** - * Comprueba que los tickets entre un rango de fechas tienen componentes - * y recalcula sus componentes - * - * @param vShippedFrom rango inicial de fecha - * @param vShippedTo rango final de fecha - */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.coste - (primary key (id)) ENGINE = MEMORY - SELECT s.id - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - JOIN saleComponent sc ON sc.saleFk = s.id - JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 - WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo - AND ic.merchandise; - - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - (primary key (id)) ENGINE = MEMORY - SELECT DISTINCT s.id - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - JOIN itemType tp ON tp.id = i.typeFk - JOIN itemCategory ic ON ic.id = tp.categoryFk - LEFT JOIN tmp.coste c ON c.id = s.id - WHERE t.shipped >= vShippedFrom AND t.shipped <= vShippedTo - AND c.id IS NULL - AND ic.merchandise; - - CALL sale_recalcComponent('renewPrices'); - - DROP TEMPORARY TABLE tmp.recalculateSales; - DROP TEMPORARY TABLE tmp.coste; - END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( - vTicketFk INT, - vClientFk INT, - vNickname VARCHAR(50), - vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, - vWarehouseFk INT, - vCompanyFk INT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption VARCHAR(25)) -BEGIN - - /** - * Modifica en el ticket los campos que se le pasan por parámetro - * y cambia sus componentes - * - * @param vTicketFk Id del ticket a modificar - * @param vClientFk nuevo cliente - * @param vNickname nuevo alias - * @param vAgencyModeFk nueva agencia - * @param vAddressFk nuevo consignatario - * @param vZoneFk nueva zona - * @param vWarehouseFk nuevo almacen - * @param vCompanyFk nueva empresa - * @param vShipped nueva fecha del envio de mercancia - * @param vLanded nueva fecha de recepcion de mercancia - * @param vIsDeleted si se borra el ticket - * @param vHasToBeUnrouted si se le elimina la ruta al ticket - * @param vOption opcion para el case del proc ticketComponentUpdateSale - */ - - DECLARE vPrice DECIMAL(10,2); - DECLARE vBonus DECIMAL(10,2); - - CALL ticket_componentPreview (vTicketFk, vLanded, vAddressFk, vZoneFk, vWarehouseFk); - - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t - JOIN address a ON a.id = vAddressFk - SET t.nickname = a.nickname - WHERE t.id = vTicketFk; - - END IF; - - CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); - - SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus - FROM tmp.zoneGetShipped - WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; - - UPDATE ticket t - SET - t.clientFk = vClientFk, - t.nickname = vNickname, - t.agencyModeFk = vAgencyModeFk, - t.addressFk = vAddressFk, - t.zoneFk = vZoneFk, - t.zonePrice = vPrice, - t.zoneBonus = vBonus, - t.warehouseFk = vWarehouseFk, - t.companyFk = vCompanyFk, - t.landed = vLanded, - t.shipped = vShipped, - t.isDeleted = vIsDeleted - WHERE - t.id = vTicketFk; - - IF vHasToBeUnrouted THEN - UPDATE ticket t SET t.routeFk = NULL - WHERE t.id = vTicketFk; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - CREATE TEMPORARY TABLE tmp.ticketComponent - SELECT * FROM tmp.ticketComponentPreview; - - CALL ticketComponentUpdateSale (vOption); - - DROP TEMPORARY TABLE tmp.sale; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - - DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; -END$$ -DELIMITER ; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption VARCHAR(25)) -proc: BEGIN - -/** - * Crea tabla temporal para sale_recalcComponent() para recalcular los componentes - * - * @param vSelf Id del ticket - * @param vOption si no se quiere forzar llamar con NULL - */ - - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - SELECT s.id - FROM sale s - WHERE s.ticketFk = vSelf; - - CALL sale_recalcComponent(vOption); - - DROP TEMPORARY TABLE tmp.recalculateSales; -END$$ -DELIMITER ; - -TRUNCATE TABLE `vn`.`ticketUpdateAction`; -INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(1, 'Cambiar los precios en el ticket', 'renewPrices'); -INSERT INTO `vn`.`ticketUpdateAction` (id, description, code) VALUES(2, 'Convertir en maná', 'mana'); \ No newline at end of file diff --git a/db/changes/240601/.gitkeep b/db/changes/240601/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 69a59885a..3be5893f7 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -4,52 +4,8 @@ USE `util`; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL); -INSERT INTO `version` VALUES ('vn-database','10806','f73a447391b7541f41e3be2ccc05327c1254578e','2024-01-04 08:36:01','10808'); +INSERT INTO `version` VALUES ('vn-database','10818','c156178ea565d81485769882618e122d9cba5d4e','2024-01-25 10:00:48','10831'); -INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10097','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10103','00-awbVolume.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10104','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10105','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10113','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL); @@ -74,7 +30,6 @@ INSERT INTO `versionLog` VALUES ('vn-database','10141','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','10142','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10143','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10144','00-AfegirFKPArt1.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10144','00-firstScript.sql','jenkins@10.0.2.68','2022-05-13 09:44:25',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10147','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10149','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10150','00-firstScript.sql','jenkins@10.0.2.68','2022-05-17 09:57:16',NULL,NULL); @@ -131,7 +86,6 @@ INSERT INTO `versionLog` VALUES ('vn-database','10207','00-Alter_table_entry.sql INSERT INTO `versionLog` VALUES ('vn-database','10207','01-Update_invoiceAmount.sql','jenkins@10.0.2.69','2022-06-16 07:23:00',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10208','00-firstScript.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10209','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 08:47:40',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10210','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 17:39:17',1046,'Base de datos no seleccionada'); INSERT INTO `versionLog` VALUES ('vn-database','10211','01-firstScript.sql','jenkins@10.0.2.69','2022-06-17 07:11:27',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10215','00-renameIsInventory.sql','jenkins@10.0.2.69','2022-06-30 09:31:26',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10216','00-firstScript.sql','jenkins@10.0.2.69','2022-06-23 11:15:28',NULL,NULL); @@ -473,7 +427,6 @@ INSERT INTO `versionLog` VALUES ('vn-database','10633','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','10634','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-06 12:15:55',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10637','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-15 12:30:19',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10640','00-companyFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10640','00-updateCompany.sql','jenkins@db-proxy1.static.verdnatura.es','2023-06-07 14:22:13',1205,'Tiempo de espera de bloqueo excedido; intente rearrancar la transacción'); INSERT INTO `versionLog` VALUES ('vn-database','10640','01-companyFkAi.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:43:23',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10640','02-companyFkCreate.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:47:04',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10640','04-supplierFkDrop.sql','jenkins@db-proxy2.static.verdnatura.es','2023-06-07 14:48:30',NULL,NULL); @@ -544,7 +497,7 @@ INSERT INTO `versionLog` VALUES ('vn-database','10718','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','10719','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-01 12:53:30',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10720','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:22',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10721','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); -INSERT INTO `versionLog` VALUES ('vn-database','10722','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-09 13:00:29',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10724','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:28',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10725','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-09-12 14:15:14',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10726','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 15:32:20',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10727','00-addPrinterField.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-21 09:42:29',NULL,NULL); @@ -558,6 +511,9 @@ INSERT INTO `versionLog` VALUES ('vn-database','10727','07-AddFieldsToPackingSit INSERT INTO `versionLog` VALUES ('vn-database','10730','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-15 11:42:48',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10733','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-05 09:54:00',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10736','00-workerBossNull.sql','jenkins@db-proxy1.static.verdnatura.es','2023-09-22 00:02:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10738','00-addFieldToTravel.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10738','01-copyDataToTravel.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:31',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10738','03-deprecateDuaAwbFk.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:32',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10739','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-10-10 10:19:07',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10740','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:26',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10741','01-refactorCplusTrascendency472.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-02 09:13:27',NULL,NULL); @@ -582,7 +538,9 @@ INSERT INTO `versionLog` VALUES ('vn-database','10756','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','10757','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:57',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10758','00-sectorType.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:18',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10758','01-dipole.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:17:18',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10758','02-agencyMode.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:32',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10761','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-16 09:30:58',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10764','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-04 12:07:59',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10768','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:37',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10771','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:37',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10773','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:38',NULL,NULL); @@ -590,6 +548,7 @@ INSERT INTO `versionLog` VALUES ('vn-database','10775','00-firstScript.sql','jen INSERT INTO `versionLog` VALUES ('vn-database','10778','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2023-11-30 13:11:38',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10782','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:18:16',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10783','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-11-24 14:49:17',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10784','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:32',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10785','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:38',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10785','02-invoiceIn.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:38',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10785','02-invoiceInTax.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-14 12:33:39',NULL,NULL); @@ -599,7 +558,23 @@ INSERT INTO `versionLog` VALUES ('vn-database','10792','00-buy.sql','jenkins@db- INSERT INTO `versionLog` VALUES ('vn-database','10798','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:21:14',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10799','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2023-12-26 12:00:59',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10800','00-firstScript.sql','jenkins@db-proxy2.static.verdnatura.es','2024-01-03 10:21:16',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10801','00-firstScript.sql','jenkins@test-db-proxy1.servers.dc.verdnatura.es','2024-01-11 05:53:13',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10806','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-03 11:56:05',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10808','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10809','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:32',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10810','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-04 14:29:30',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10811','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10812','00-update.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10812','01-delete.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10812','02-rename.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10812','03-changePosition.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10812','04-unique.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10813','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10815','00-firstScript.sql','jenkins@db-proxy1.static.verdnatura.es','2024-01-09 18:11:57',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10816','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10817','00-invoiceOutConfig_refLen.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-24 21:47:35',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10818','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-25 09:00:36',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','10827','00-firstScript.sql','jenkins@db-proxy2.servers.dc.verdnatura.es','2024-01-23 12:32:13',NULL,NULL); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; @@ -693,6 +668,7 @@ INSERT INTO `role` VALUES (123,'deliveryAssistant','Jefe auxiliar repartos',1,'2 INSERT INTO `role` VALUES (124,'hrBuyer','Recursos Humanos con Buyer',1,'2023-10-23 13:50:43','2023-10-23 13:50:43',NULL); INSERT INTO `role` VALUES (125,'claimViewer','Trabajadores que consulta las reclamaciones ',1,'2023-11-16 09:14:46','2023-11-16 09:14:46',10578); INSERT INTO `role` VALUES (126,'greenhouseBoss','Jefe de invernadero',1,'2023-11-16 14:32:13','2023-11-16 14:32:13',NULL); +INSERT INTO `role` VALUES (127,'timeControl','Tablet para fichar',1,'2024-01-09 16:36:56','2024-01-09 16:36:56',NULL); INSERT INTO `roleInherit` VALUES (1,1,2,NULL); INSERT INTO `roleInherit` VALUES (2,1,3,NULL); @@ -729,7 +705,6 @@ INSERT INTO `roleInherit` VALUES (37,34,1,NULL); INSERT INTO `roleInherit` VALUES (38,34,13,NULL); INSERT INTO `roleInherit` VALUES (39,34,33,NULL); INSERT INTO `roleInherit` VALUES (40,35,1,NULL); -INSERT INTO `roleInherit` VALUES (41,36,44,NULL); INSERT INTO `roleInherit` VALUES (42,36,47,NULL); INSERT INTO `roleInherit` VALUES (43,37,1,NULL); INSERT INTO `roleInherit` VALUES (44,38,37,NULL); @@ -912,7 +887,6 @@ INSERT INTO `roleInherit` VALUES (281,5,18,NULL); INSERT INTO `roleInherit` VALUES (282,50,60,NULL); INSERT INTO `roleInherit` VALUES (283,5,21,NULL); INSERT INTO `roleInherit` VALUES (285,58,76,NULL); -INSERT INTO `roleInherit` VALUES (287,69,58,NULL); INSERT INTO `roleInherit` VALUES (288,115,66,NULL); INSERT INTO `roleInherit` VALUES (290,104,115,NULL); INSERT INTO `roleInherit` VALUES (291,115,103,NULL); @@ -954,6 +928,10 @@ INSERT INTO `roleInherit` VALUES (350,49,75,NULL); INSERT INTO `roleInherit` VALUES (351,72,35,NULL); INSERT INTO `roleInherit` VALUES (353,110,49,NULL); INSERT INTO `roleInherit` VALUES (354,103,119,NULL); +INSERT INTO `roleInherit` VALUES (355,127,11,NULL); +INSERT INTO `roleInherit` VALUES (356,123,125,NULL); +INSERT INTO `roleInherit` VALUES (357,36,35,NULL); +INSERT INTO `roleInherit` VALUES (358,36,49,NULL); INSERT INTO `userPassword` VALUES (1,7,1,0,2,1); @@ -1098,13 +1076,11 @@ INSERT INTO `ACL` VALUES (165,'TicketDms','*','*','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'); INSERT INTO `ACL` VALUES (172,'Sms','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (173,'Sms','send','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (176,'Device','*','*','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (177,'Device','*','*','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (179,'ItemLog','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (180,'RouteLog','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'); @@ -1521,13 +1497,10 @@ INSERT INTO `ACL` VALUES (657,'Supplier','getItemsPackaging','READ','ALLOW','ROL INSERT INTO `ACL` VALUES (658,'Ticket','closeAll','WRITE','ALLOW','ROLE','system'); INSERT INTO `ACL` VALUES (659,'Account','*','*','ALLOW','ROLE','developerBoss'); INSERT INTO `ACL` VALUES (664,'MailForward','*','*','ALLOW','ROLE','itManagement'); -INSERT INTO `ACL` VALUES (665,'Role','*','READ','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (666,'Role','*','WRITE','ALLOW','ROLE','it'); INSERT INTO `ACL` VALUES (667,'VnUser','*','*','ALLOW','ROLE','itManagement'); INSERT INTO `ACL` VALUES (668,'VnUser','__get__preview','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (669,'VnUser','preview','*','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (670,'VnUser','create','*','ALLOW','ROLE','itManagement'); -INSERT INTO `ACL` VALUES (671,'VnUser','renewToken','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (672,'PackingSiteAdvanced','*','*','ALLOW','ROLE','production'); INSERT INTO `ACL` VALUES (673,'InvoiceOut','makePdfAndNotify','WRITE','ALLOW','ROLE','invoicing'); INSERT INTO `ACL` VALUES (674,'InvoiceOutConfig','*','READ','ALLOW','ROLE','invoicing'); @@ -1568,8 +1541,8 @@ INSERT INTO `ACL` VALUES (713,'Client','__get__addresses','READ','ALLOW','ROLE', INSERT INTO `ACL` VALUES (714,'ExpeditionMistakeType','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (715,'WorkerMistakeType','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (716,'ExpeditionMistake','*','WRITE','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (717,'WorkerMistake','*','WRITE','ALLOW','ROLE','coolerBoss'); -INSERT INTO `ACL` VALUES (718,'MistakesTypes','*','WRITE','ALLOW','ROLE','coolerBoss'); +INSERT INTO `ACL` VALUES (717,'WorkerMistake','*','WRITE','ALLOW','ROLE','coolerAssist'); +INSERT INTO `ACL` VALUES (718,'MistakesTypes','*','WRITE','ALLOW','ROLE','coolerAssist'); INSERT INTO `ACL` VALUES (719,'MistakeType','*','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (720,'MachineWorker','*','READ','ALLOW','ROLE','coolerAssist'); INSERT INTO `ACL` VALUES (721,'Printer','*','READ','ALLOW','ROLE','employee'); @@ -1608,7 +1581,7 @@ INSERT INTO `ACL` VALUES (754,'Route','find','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (755,'Route','findById','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (756,'Route','findOne','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (757,'Route','getRoutesByWorker','READ','ALLOW','ROLE','employee'); -INSERT INTO `ACL` VALUES (758,'Route','canViewAllRoute','READ','ALLOW','ROLE','deliveryBoss'); +INSERT INTO `ACL` VALUES (758,'Route','canViewAllRoute','READ','ALLOW','ROLE','deliveryAssistant'); INSERT INTO `ACL` VALUES (759,'Route','cmr','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (760,'Route','downloadCmrsZip','READ','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (761,'Route','downloadZip','READ','ALLOW','ROLE','employee'); @@ -1622,6 +1595,21 @@ INSERT INTO `ACL` VALUES (768,'Route','guessPriority','WRITE','ALLOW','ROLE','em INSERT INTO `ACL` VALUES (769,'Route','insertTicket','WRITE','ALLOW','ROLE','employee'); INSERT INTO `ACL` VALUES (770,'Route','getDeliveryPoint','READ','ALLOW','ROLE','deliveryBoss'); INSERT INTO `ACL` VALUES (771,'Route','summary','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (772,'Route','getExpeditionSummary','READ','ALLOW','ROLE','delivery'); +INSERT INTO `ACL` VALUES (773,'WorkerTimeControl','login','READ','ALLOW','ROLE','timeControl'); +INSERT INTO `ACL` VALUES (774,'WorkerTimeControl','getClockIn','READ','ALLOW','ROLE','timeControl'); +INSERT INTO `ACL` VALUES (775,'WorkerTimeControl','clockIn','WRITE','ALLOW','ROLE','timeControl'); +INSERT INTO `ACL` VALUES (776,'WorkerTimeControl','addTimeEntry','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (777,'WorkerTimeControl','deleteTimeEntry','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (778,'WorkerTimeControl','updateTimeEntry','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (779,'WorkerTimeControl','sendMail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (780,'WorkerTimeControl','updateWorkerTimeControlMail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (781,'WorkerTimeControl','weeklyHourRecordEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (782,'WorkerTimeControl','getMailStates','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (783,'WorkerTimeControl','resendWeeklyHourEmail','WRITE','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (784,'VnRole','*','READ','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (785,'VnRole','*','WRITE','ALLOW','ROLE','it'); +INSERT INTO `ACL` VALUES (786,'State','isAllEditable','READ','ALLOW','ROLE','delivery'); INSERT INTO `fieldAcl` VALUES (1,'Client','name','update','employee'); INSERT INTO `fieldAcl` VALUES (2,'Client','contact','update','employee'); @@ -1941,7 +1929,7 @@ INSERT INTO `continent` VALUES (3,'África','AF'); INSERT INTO `continent` VALUES (4,'Europa','EU'); INSERT INTO `continent` VALUES (5,'Oceanía','OC'); -INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,104,763,0,0,0,0,28,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (1,'VN','VERDNATURA',1,106,763,0,0,0,0,28,NULL,'/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (22,'shopping','COMPRAS',2,3,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (23,'CMA','CAMARA',13,14,NULL,72,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL,NULL); INSERT INTO `department` VALUES (31,'it','INFORMATICA',4,5,NULL,72,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL,NULL); @@ -1952,28 +1940,28 @@ INSERT INTO `department` VALUES (37,'PROD','PRODUCCION',12,33,NULL,72,1,1,1,10,1 INSERT INTO `department` VALUES (38,'picking','SACADO',15,16,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (39,'packing','ENCAJADO',17,18,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (41,'administration','ADMINISTRACION',34,35,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (43,'VT','VENTAS',36,59,NULL,0,0,0,1,11,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (44,'management','GERENCIA',60,61,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (45,'logistic','LOGISTICA',62,63,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (46,'delivery','REPARTO',64,65,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL); -INSERT INTO `department` VALUES (48,'storage','ALMACENAJE',66,67,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (49,NULL,'PROPIEDAD',68,69,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (52,NULL,'CARGA AEREA',70,71,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (53,'marketing','MARKETING Y COMUNICACIÓN',72,73,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (54,NULL,'ORNAMENTALES',74,75,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (43,'VT','VENTAS',36,61,NULL,0,0,0,1,12,1,'/1/',NULL,1,'',1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (44,'management','GERENCIA',62,63,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (45,'logistic','LOGISTICA',64,65,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (46,'delivery','REPARTO',66,67,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (48,'storage','ALMACENAJE',68,69,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (49,NULL,'PROPIEDAD',70,71,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (52,NULL,'CARGA AEREA',72,73,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (53,'marketing','MARKETING Y COMUNICACIÓN',74,75,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (54,NULL,'ORNAMENTALES',76,77,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (55,NULL,'TALLER NATURAL',19,20,14548,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1118,NULL); INSERT INTO `department` VALUES (56,NULL,'TALLER ARTIFICIAL',21,22,8470,72,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,1927,NULL); -INSERT INTO `department` VALUES (58,'CMP','CAMPOS',76,79,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (59,'maintenance','MANTENIMIENTO',80,81,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL); -INSERT INTO `department` VALUES (60,'claims','RECLAMACIONES',82,83,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,1,0,0,NULL,NULL); -INSERT INTO `department` VALUES (61,NULL,'VNH',84,87,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (66,NULL,'VERDNAMADRID',88,89,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (58,'CMP','CAMPOS',78,81,NULL,72,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (59,'maintenance','MANTENIMIENTO',82,83,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (60,'claims','RECLAMACIONES',84,85,NULL,72,0,0,1,0,1,'/1/',NULL,1,NULL,1,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (61,NULL,'VNH',86,89,NULL,73,0,0,1,1,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (66,NULL,'VERDNAMADRID',90,91,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (68,NULL,'COMPLEMENTOS',23,24,NULL,72,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,0,0,NULL,NULL); -INSERT INTO `department` VALUES (69,NULL,'VERDNABARNA',90,91,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (69,NULL,'VERDNABARNA',92,93,NULL,74,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (80,NULL,'EQUIPO J VALLES',37,38,4250,72,0,0,2,0,43,'/1/43/','jvp_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (86,NULL,'LIMPIEZA',92,93,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (89,NULL,'COORDINACION',94,95,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (90,NULL,'TRAILER',85,86,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (86,NULL,'LIMPIEZA',94,95,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (89,NULL,'COORDINACION',96,97,NULL,0,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (90,NULL,'TRAILER',87,88,NULL,0,0,0,2,0,61,'/1/61/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (91,'artificial','ARTIFICIAL',25,26,NULL,0,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (92,NULL,'EQUIPO SILVERIO',39,40,1203,0,0,0,2,0,43,'/1/43/','sdc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (94,NULL,'EQUIPO J BROCAL',41,42,3797,0,0,0,2,0,43,'/1/43/','jes_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); @@ -1981,18 +1969,19 @@ INSERT INTO `department` VALUES (95,NULL,'EQUIPO C ZAMBRANO',43,44,4667,0,0,0,2, INSERT INTO `department` VALUES (96,NULL,'EQUIPO C LOPEZ',45,46,4661,0,0,0,2,0,43,'/1/43/','cla_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (115,NULL,'EQUIPO CLAUDI',47,48,3810,0,0,0,2,0,43,'/1/43/','csr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (123,NULL,'EQUIPO ELENA BASCUÑANA',49,50,7102,0,0,0,2,0,43,'/1/43/','ebt_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (124,NULL,'CONTROL INTERNO',96,97,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (124,NULL,'CONTROL INTERNO',98,99,NULL,72,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (125,NULL,'EQUIPO MIRIAM MAR',51,52,1118,0,0,0,2,0,43,'/1/43/','mir_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (126,NULL,'PRESERVADO',27,28,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,0,NULL,NULL); INSERT INTO `department` VALUES (128,NULL,'PALETIZADO',29,30,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (130,NULL,'REVISION',31,32,NULL,0,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (131,'greenhouse','INVERNADERO',77,78,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL); +INSERT INTO `department` VALUES (131,'greenhouse','INVERNADERO',79,80,NULL,0,0,0,2,0,58,'/1/58/',NULL,0,NULL,0,1,0,0,NULL,NULL); INSERT INTO `department` VALUES (132,NULL,'EQUIPO DC',53,54,1731,0,0,0,2,0,43,'/1/43/','dc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (133,'franceTeam','EQUIPO FRANCIA',55,56,1731,72,0,0,2,0,43,'/1/43/','fra_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `department` VALUES (134,NULL,'EQUIPO RODRI',57,58,6264,0,0,0,2,0,43,'/1/43/','rhr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (135,'routers','ENRUTADORES',98,99,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (136,'heavyVehicles','VEHICULOS PESADOS',100,101,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); -INSERT INTO `department` VALUES (137,'sorter','SORTER',102,103,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (135,'routers','ENRUTADORES',100,101,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (136,'heavyVehicles','VEHICULOS PESADOS',102,103,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (137,'sorter','SORTER',104,105,NULL,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL,NULL); +INSERT INTO `department` VALUES (139,NULL,'EQUIPO MIRIAM MAR 2',59,60,3803,0,0,0,2,0,43,'/1/43/','mir2_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL,NULL); INSERT INTO `docuware` VALUES (1,'deliveryNote','Albaranes cliente','find','find','N__ALBAR_N',NULL); INSERT INTO `docuware` VALUES (2,'deliveryNote','Albaranes cliente','store','Archivar','N__ALBAR_N',NULL); @@ -2287,8 +2276,8 @@ INSERT INTO `state` VALUES (37,'Previa Revisado',3,0,'PREVIOUS_CONTROLLED',2,29, INSERT INTO `state` VALUES (38,'Prep Cámara',6,1,'COOLER_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'); INSERT INTO `state` VALUES (41,'Prep Parcial',6,1,'PARTIAL_PREPARATION',7,14,0,0,0,2,0,0,2,0,'warning'); -INSERT INTO `ticketUpdateAction` VALUES (1,'Cambiar los precios en el ticket','changePrice'); -INSERT INTO `ticketUpdateAction` VALUES (3,'Convertir en maná','turnInMana'); +INSERT INTO `ticketUpdateAction` VALUES (1,'Cambiar los precios en el ticket','renewPrices'); +INSERT INTO `ticketUpdateAction` VALUES (2,'Convertir en maná','mana'); INSERT INTO `volumeConfig` VALUES (2.67,1.60,0.8,150,0.30,120,57,2.0,50,200,10,167.0); @@ -2303,7 +2292,15 @@ INSERT INTO `workCenter` VALUES (8,'Silla-Agrario',26,NULL,NULL,NULL,NULL,NULL); INSERT INTO `workCenter` VALUES (9,'Algemesi',20,1354,60,'Fenollars, 2',523549,NULL); INSERT INTO `workCenter` VALUES (10,'Rubi',88,NULL,84,'Av. de la Llana, 131',549722,NULL); -INSERT INTO `workerBusinessAgreement` VALUES (1,'Flores y Plantas',2.5,1830,'2012-01-01',NULL); +INSERT INTO `workerTimeControlError` VALUES (1,'IS_NOT_ALLOWED_FUTURE','No se permite fichar a futuro'); +INSERT INTO `workerTimeControlError` VALUES (2,'INACTIVE_BUSINESS','No hay un contrato en vigor'); +INSERT INTO `workerTimeControlError` VALUES (3,'IS_NOT_ALLOWED_WORK','No está permitido trabajar'); +INSERT INTO `workerTimeControlError` VALUES (4,'ODD_WORKERTIMECONTROL','Fichadas impares'); +INSERT INTO `workerTimeControlError` VALUES (5,'DAY_MAX_TIME','Superado el tiempo máximo entre entrada y salida'); +INSERT INTO `workerTimeControlError` VALUES (6,'BREAK_DAY','Descanso diario'); +INSERT INTO `workerTimeControlError` VALUES (7,'BREAK_WEEK','Descanso semanal'); +INSERT INTO `workerTimeControlError` VALUES (8,'WRONG_DIRECTION','Dirección incorrecta'); +INSERT INTO `workerTimeControlError` VALUES (9,'UNDEFINED_ERROR','Error sin definir'); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/db/dump/.dump/privileges.sql b/db/dump/.dump/privileges.sql index b8abe322e..290c8a2a3 100644 --- a/db/dump/.dump/privileges.sql +++ b/db/dump/.dump/privileges.sql @@ -676,7 +676,6 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','glsExpedition__',' INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','postCode','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','pgcMaster','alexm@%','0000-00-00 00:00:00','Select,Insert',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemBarcode','alexm@%','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemBarcode','alexm@%','0000-00-00 00:00:00','Insert',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','host','alexm@%','0000-00-00 00:00:00','Select,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','hr','Facturas','guillermo@10.5.1.4','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticket','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); @@ -701,11 +700,11 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceInTax INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','invoiceOut','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','invoiceOutExpense','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','item','alexm@%','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','item','jenkins@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','','Update'); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceOutSerial','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesPerson','invoiceOutTax','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','item','alexm@%','0000-00-00 00:00:00','Insert',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','itemBarcode','alexm@%','0000-00-00 00:00:00','Insert,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','production','itemBarcode','guillermo@db-proxy2.servers.dc.verdnatura.es','0000-00-00 00:00:00','Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','itemBotanical','alexm@%','0000-00-00 00:00:00','Select,Insert',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemBotanicalWithGenus','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','itemCategory','alexm@%','0000-00-00 00:00:00','Select',''); @@ -774,7 +773,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','noticeSubscripti INSERT IGNORE INTO `tables_priv` VALUES ('','vn','logistic','noticeCategory','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','coolerBoss','noticeCategory','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','mrwServiceWeekday','alexm@%','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','mrw','alexm@%','0000-00-00 00:00:00','Select,Delete',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionAssi','mrw','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','employee','mrwService','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ppePlan','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hrBoss','accountingConfig','alexm@%','0000-00-00 00:00:00','Select',''); @@ -911,8 +910,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','manager','supplier','alexm@%' INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','supplierAccount','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','supplierAgencyTerm','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','supplierAgencyTerm','alexm@%','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','supplierExpense','alexm@%','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','financialBoss','supplierExpense','alexm@%','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','supplierExpense','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','marketingBoss','ticketService','alexm@%','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','ticketService','jgallego@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','packager','sendingServiceWeekday','jenkins@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); @@ -1152,6 +1150,10 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','ticketLastState','g INSERT IGNORE INTO `tables_priv` VALUES ('','hedera','guest','myAddress','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','tag','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemTag','guillermo@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn2008','handmadeBoss','Tipos','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Update',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','saleBuy','carlosap@10.5.1.6','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','orderTicket','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','salesAssistant','negativeOrigin','alexm@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','route','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','itemPackingType','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','expedition','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); @@ -1218,7 +1220,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','administrative','farmingInvoi INSERT IGNORE INTO `tables_priv` VALUES ('','vn','productionBoss','routesMonitor','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','','Update'); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','routeCommission','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','expeditionState','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); -INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','warehouse','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Insert',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyerBoss','warehouse','alexm@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Insert,Update',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimBeginning','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','invoicing','vehiclePlateRegex','guillermo@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','hr','businessSchedule','alexm@db-proxy1.static.verdnatura.es','0000-00-00 00:00:00','Select,Insert,Update,Delete',''); @@ -1337,6 +1339,7 @@ INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','claimState','juan@d INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','company','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','srt','grafana','buffer','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); INSERT IGNORE INTO `tables_priv` VALUES ('','vn','grafana','greuge','juan@db-proxy2.static.verdnatura.es','0000-00-00 00:00:00','Select',''); +INSERT IGNORE INTO `tables_priv` VALUES ('','vn','buyer','item','guillermo@db-proxy1.servers.dc.verdnatura.es','0000-00-00 00:00:00','','Select,Update'); /*!40000 ALTER TABLE `tables_priv` ENABLE KEYS */; /*!40000 ALTER TABLE `columns_priv` DISABLE KEYS */; @@ -1475,6 +1478,67 @@ INSERT IGNORE INTO `columns_priv` VALUES ('','vn','salesAssistant','sale','edit INSERT IGNORE INTO `columns_priv` VALUES ('','vn','deliveryAssistant','postCode','code','0000-00-00 00:00:00','Update'); INSERT IGNORE INTO `columns_priv` VALUES ('','vn','deliveryAssistant','postCode','townFk','0000-00-00 00:00:00','Update'); INSERT IGNORE INTO `columns_priv` VALUES ('','vn','deliveryAssistant','town','provinceFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','id','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','equivalent','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','stems','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','minPrice','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','isToPrint','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','family','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','box','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','category','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','doPhoto','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','image','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','inkFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','intrastatFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','hasMinPrice','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','created','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','comment','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','typeFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','generic','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','producerFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','description','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','density','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','relevancy','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','expenseFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','isActive','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','subName','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','tag5','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','value5','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','tag6','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','value6','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','tag7','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','value7','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','tag8','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','value8','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','tag9','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','value9','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','tag10','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','value10','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','minimum','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','upToDown','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','supplyResponseFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','hasKgPrice','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','isFloramondo','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','isFragile','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','numberOfItemsPerCask','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','embalageCode','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','quality','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','stemMultiplier','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','itemPackingTypeFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','packingOut','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','genericFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','packingShelve','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','isLaid','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','lastUsed','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','weightByPiece','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','editorFk','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','recycledPlastic','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','nonRecycledPlastic','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','employee','item','minQuantity','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','item','size','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','item','originFk','0000-00-00 00:00:00','Select,Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','item','longName','0000-00-00 00:00:00','Update'); +INSERT IGNORE INTO `columns_priv` VALUES ('','vn','buyer','item','name','0000-00-00 00:00:00','Update'); /*!40000 ALTER TABLE `columns_priv` ENABLE KEYS */; /*!40000 ALTER TABLE `procs_priv` DISABLE KEYS */; @@ -1539,7 +1603,6 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','srt','production','buffer_settypeby INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','buyUltimate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','financialBoss','balance_create','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','claimManager','buyUltimate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); -INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','employee','base_ticket','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','barcodeToItem','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','ticket_splititempackingtype','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','entry_getCommission','FUNCTION','alexm@%','Execute','0000-00-00 00:00:00'); @@ -1596,7 +1659,6 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','srt','production','expedition_scan' INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','historico_absoluto','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','buyer','historico_multiple','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','client_getDebt','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); -INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','logistic','f10_no_vincular','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn2008','hrBoss','balance_create','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','cooler','buyultimate','PROCEDURE','alexm@%','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','util','grafana','firstdayofyear','FUNCTION','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); @@ -1765,7 +1827,7 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','util','guest','VN_UTC_TIMESTAMP','F INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','itemshelving_getsaledate','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','ticket_setState','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','invoicing','invoiceout_new','PROCEDURE','alexm@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); -INSERT IGNORE INTO `procs_priv` VALUES ('','vn','palletizer','ticket_setState','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','sale_replaceItem','PROCEDURE','jgallego@db-proxy1.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','hr','ledger_next','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','deliveryAssistant','workerjourney_replace','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','account','developerBoss','role_sync','PROCEDURE','juan@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); @@ -1878,6 +1940,7 @@ INSERT IGNORE INTO `procs_priv` VALUES ('','vn','delivery','itemShelving_getinf INSERT IGNORE INTO `procs_priv` VALUES ('','vn','production','collection_get','PROCEDURE','alexm@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','buyer','item_comparative','PROCEDURE','guillermo@db-proxy1.static.verdnatura.es','Execute','0000-00-00 00:00:00'); INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','sale_getBoxPickingList','PROCEDURE','guillermo@db-proxy2.static.verdnatura.es','Execute','0000-00-00 00:00:00'); +INSERT IGNORE INTO `procs_priv` VALUES ('','vn','employee','worker_isInDepartment','FUNCTION','jgallego@db-proxy1.servers.dc.verdnatura.es','Execute','0000-00-00 00:00:00'); /*!40000 ALTER TABLE `procs_priv` ENABLE KEYS */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -1898,7 +1961,7 @@ INSERT IGNORE INTO `global_priv` VALUES ('','agency','{\"access\": 0, \"max_que INSERT IGNORE INTO `global_priv` VALUES ('','android','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','artificialBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','assetManager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); -INSERT IGNORE INTO `global_priv` VALUES ('','buyer','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','buyer','{\"access\": 0, \"version_id\": 101106, \"is_role\": true}'); INSERT IGNORE INTO `global_priv` VALUES ('','buyerBoss','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); INSERT IGNORE INTO `global_priv` VALUES ('','claimManager','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','cooler','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); @@ -1910,7 +1973,7 @@ INSERT IGNORE INTO `global_priv` VALUES ('','deliveryAssistant','{\"access\":0, INSERT IGNORE INTO `global_priv` VALUES ('','deliveryBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','developer','{\"access\": 5909905728, \"is_role\": true, \"version_id\": 100707}'); INSERT IGNORE INTO `global_priv` VALUES ('','developerBoss','{\"access\":33554432,\"version_id\":100707,\"is_role\":true}'); -INSERT IGNORE INTO `global_priv` VALUES ('','employee','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); +INSERT IGNORE INTO `global_priv` VALUES ('','employee','{\"access\": 0, \"is_role\": true, \"version_id\": 101106}'); INSERT IGNORE INTO `global_priv` VALUES ('','entryEditor','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','ext','{\"access\": 0, \"is_role\": true, \"version_id\": 100707}'); INSERT IGNORE INTO `global_priv` VALUES ('','financial','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); @@ -1940,7 +2003,7 @@ INSERT IGNORE INTO `global_priv` VALUES ('','palletizer','{\"access\":0,\"versi INSERT IGNORE INTO `global_priv` VALUES ('','palletizerBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','preservedBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','production','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); -INSERT IGNORE INTO `global_priv` VALUES ('','productionAssi','{\"access\": 0, \"version_id\": 100707, \"is_role\": true}'); +INSERT IGNORE INTO `global_priv` VALUES ('','productionAssi','{\"access\": 0, \"version_id\": 101106, \"is_role\": true}'); INSERT IGNORE INTO `global_priv` VALUES ('','productionBoss','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','productionPlus','{\"access\":0,\"version_id\":100707,\"is_role\":true}'); INSERT IGNORE INTO `global_priv` VALUES ('','root','{\"access\": 549755781119, \"version_id\": 100705, \"is_role\": true}'); diff --git a/db/dump/.dump/triggers.sql b/db/dump/.dump/triggers.sql new file mode 100644 index 000000000..f68b463d2 --- /dev/null +++ b/db/dump/.dump/triggers.sql @@ -0,0 +1,10780 @@ +-- MariaDB dump 10.19 Distrib 10.5.21-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: db.verdnatura.es Database: account +-- ------------------------------------------------------ +-- Server version 10.11.6-MariaDB-1:10.11.6+maria~deb12-log +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Current Database: `account` +-- + +USE `account`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_beforeInsert` + BEFORE INSERT ON `account` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_afterInsert` + AFTER INSERT ON `account` + FOR EACH ROW +BEGIN + INSERT IGNORE INTO userSync (`name`) + SELECT `name` FROM `user` WHERE 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_beforeUpdate` + BEFORE UPDATE ON `account` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`account_afterDelete` + AFTER DELETE ON `account` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'Account', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + INSERT IGNORE INTO userSync (`name`) + SELECT `name` FROM `user` WHERE id = 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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailAlias_beforeInsert` + BEFORE INSERT ON `mailAlias` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailAlias_beforeUpdate` + BEFORE UPDATE ON `mailAlias` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailAlias_afterDelete` + AFTER DELETE ON `mailAlias` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'MailAlias', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailForward_beforeInsert` + BEFORE INSERT ON `mailForward` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailForward_beforeUpdate` + BEFORE UPDATE ON `mailForward` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`mailForward_afterDelete` + AFTER DELETE ON `mailForward` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'MailForward', + `changedModelId` = OLD.account, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`role_beforeInsert` + BEFORE INSERT ON `role` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL role_checkName(NEW.`name`); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`role_beforeUpdate` + BEFORE UPDATE ON `role` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + IF !(NEW.`name` <=> OLD.`name`) THEN + CALL role_checkName (NEW.`name`); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`role_afterDelete` + AFTER DELETE ON `role` + FOR EACH ROW +BEGIN + INSERT INTO roleLog + SET `action` = 'delete', + `changedModel` = 'Role', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`roleInherit_beforeInsert` + BEFORE INSERT ON `roleInherit` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`roleInherit_beforeUpdate` + BEFORE UPDATE ON `roleInherit` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`roleInherit_afterDelete` + AFTER DELETE ON `roleInherit` + FOR EACH ROW +BEGIN + INSERT INTO roleLog + SET `action` = 'delete', + `changedModel` = 'RoleInherit', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_beforeInsert` + BEFORE INSERT ON `user` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + CALL user_checkName(NEW.`name`); + + IF NEW.nickname = '' THEN + SET NEW.nickname = NEW.`name`; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_afterInsert` + AFTER INSERT ON `user` + FOR EACH ROW +BEGIN + CALL hedera.image_ref('user', NEW.image); + + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_beforeUpdate` + BEFORE UPDATE ON `user` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF !(NEW.`name` <=> OLD.`name`) THEN + CALL user_checkName (NEW.`name`); + END IF; + + IF !(NEW.`password` <=> OLD.`password`) THEN + SET NEW.lastPassChange = util.VN_NOW(); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_afterUpdate` + AFTER UPDATE ON `user` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL hedera.image_unref('user', OLD.image); + CALL hedera.image_ref('user', NEW.image); + END IF; + + INSERT IGNORE INTO userSync SET `name` = NEW.`name`; + + IF !(OLD.`name` <=> NEW.`name`) THEN + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `account`.`user_afterDelete` + AFTER DELETE ON `user` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'User', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL hedera.image_unref('user', OLD.image); + + INSERT IGNORE INTO userSync SET `name` = OLD.`name`; +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 */ ; + +-- +-- Current Database: `bi` +-- + +USE `bi`; + +-- +-- Current Database: `bs` +-- + +USE `bs`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `bs`.`clientNewBorn_BEFORE_UPDATE` + BEFORE UPDATE ON `clientNewBorn` + FOR EACH ROW +BEGIN + -- Si ha pasado un año o mas + IF TIMESTAMPDIFF(YEAR,NEW.lastShipped, OLD.lastShipped) THEN + SET NEW.firstShipped = NEW.lastShipped; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `bs`.`nightTaskBeforeInsert` + BEFORE INSERT ON `nightTask` + FOR EACH ROW +BEGIN + + IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN + + CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `bs`.`nightTaskBeforeUpdate` + BEFORE UPDATE ON `nightTask` + FOR EACH ROW +BEGIN + + IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN + + CALL util.throw('ONLY_ALPHANUMERICS_ALLOWED'); + + 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 */ ; + +-- +-- Current Database: `cache` +-- + +USE `cache`; + +-- +-- Current Database: `dipole` +-- + +USE `dipole`; + +-- +-- Current Database: `edi` +-- + +USE `edi`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`item_feature_bi` + BEFORE INSERT ON `item_feature` + FOR EACH ROW +BEGIN + IF NEW.expiry_date = '0000-00-00' THEN + SET NEW.expiry_date = 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`putOrder_BEFORE_INSERT` + BEFORE INSERT ON `putOrder` + FOR EACH ROW +BEGIN + + DECLARE nextID INT; + + SELECT 1 + MAX(id) INTO nextID FROM putOrder ; + + SET NEW.orderTradelineItemID = nextID; + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`BEFORE UPDATE` + BEFORE UPDATE ON `putOrder` + FOR EACH ROW +BEGIN + + DECLARE vError VARCHAR(100) DEFAULT 'Orderregel niet meer teruggevonden op basis van de orderps'; + DECLARE vVmpIdError INT DEFAULT 7; + DECLARE vVmpFk INT; + DECLARE vSupplyResponseNumberOfUnits INT; + + SELECT sr.vmpID INTO vVmpFk + FROM edi.supplyResponse sr + WHERE sr.id = NEW.supplyResponseID; + + IF NEW.OrderStatus = 3 + AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) + AND NEW.error = vError + AND vVmpFk = vVmpIdError + + THEN + + SET NEW.OrderStatus = 2; + + END IF; + + -- Error de disponible menor de lo solicitado + IF NEW.error LIKE 'error2602%' THEN + + SELECT NumberOfUnits INTO vSupplyResponseNumberOfUnits + FROM edi.supplyResponse sr + WHERE sr.ID = NEW.supplyResponseID; + + SET NEW.error = CONCAT('(',vSupplyResponseNumberOfUnits,') ', NEW.error); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`putOrder_AFTER_UPDATE` + AFTER UPDATE ON `putOrder` + FOR EACH ROW +BEGIN + DECLARE vSaleFk INT; + DECLARE vOrderStatusDenied INT DEFAULT 3; + DECLARE vOrderStatusOK INT DEFAULT 2; + DECLARE vIsEktSender BOOLEAN; + + IF NEW.OrderStatus = vOrderStatusDenied AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN + + SELECT s.id INTO vSaleFk + FROM vn.sale s + JOIN vn.ticket t ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() + AND i.supplyResponseFk = NEW.supplyResponseID + LIMIT 1; + + UPDATE vn.sale s + JOIN vn.ticket t ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID + SET s.quantity = 0 + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() + AND i.supplyResponseFk = NEW.supplyResponseID; + + INSERT INTO vn.mail (sender, `subject`, body) + SELECT IF(u.id IS NOT NULL AND c.email IS NOT NULL, + c.email, + CONCAT(account.user_getNameFromId(c.salesPersonFk), '@verdnatura.es') + ), + 'Producto no disponible en Floramondo', + CONCAT('El artículo ', s.concept, ' del ticket ', t.id , ' ha sido cancelado por Floramondo. ', + ' Se ha actualizado la cantidad de ', OLD.quantity,' a 0. ', + IF (u.id IS NOT NULL AND c.email IS NOT NULL , + CONCAT('https://shop.verdnatura.es/#!form=ecomerce%2Fticket&ticket=', t.id ), + CONCAT('https://salix.verdnatura.es/#!/ticket/', t.id ,'/summary'))) + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.`client` c ON c.id = t.clientFk + LEFT JOIN account.user u ON u.id= c.salesPersonFk AND u.name IN ('ruben', 'ismaelalcolea') + WHERE s.id = vSaleFk; + + END IF; + + + IF NEW.OrderStatus = vOrderStatusOK AND NOT (NEW.OrderStatus <=> OLD.OrderStatus) THEN + + SELECT v.isEktSender INTO vIsEktSender + FROM edi.VMPSettings v + JOIN edi.supplyResponse sr ON sr.vmpID = v.VMPID + WHERE sr.id = NEW.supplyResponseID; + + IF NOT vIsEktSender THEN + + CALL edi.ekt_add(NEW.id); + + END IF; + + IF NEW.barcode THEN + + INSERT IGNORE INTO vn.itemBarcode(itemFk, code) + SELECT i.id, NEW.barcode + FROM vn.item i + WHERE i.supplyResponseFk = NEW.supplyResponseID; + + 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `edi`.`supplyResponse_AFTER_UPDATE` + AFTER UPDATE ON `supplyResponse` + FOR EACH ROW +BEGIN + + UPDATE vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + JOIN vn.item i ON i.id = b.itemFk + JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID + SET b.quantity = NEW.NumberOfItemsPerCask * NEW.NumberOfUnits, + b.stickers = NEW.NumberOfUnits + WHERE i.supplyResponseFk = NEW.ID + AND am.name = 'LOGIFLORA' + AND e.isRaid + AND tr.landed >= util.VN_CURDATE(); + +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 */ ; + +-- +-- Current Database: `hedera` +-- + +USE `hedera`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`link_afterInsert` + AFTER INSERT ON `link` + FOR EACH ROW +BEGIN + CALL image_ref('link', NEW.image); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`link_afterUpdate` + AFTER UPDATE ON `link` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL image_unref('link', OLD.image); + CALL image_ref('link', NEW.image); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`link_afterDelete` + AFTER DELETE ON `link` + FOR EACH ROW +BEGIN + CALL image_unref('link', OLD.image); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`news_afterInsert` + AFTER INSERT ON `news` + FOR EACH ROW +BEGIN + CALL image_ref('news', NEW.image); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`news_afterUpdate` + AFTER UPDATE ON `news` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL image_unref('news', OLD.image); + CALL image_ref('news', NEW.image); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`news_afterDelete` + AFTER DELETE ON `news` + FOR EACH ROW +BEGIN + CALL image_unref('news', OLD.image); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterInsert` + AFTER INSERT ON `order` + FOR EACH ROW +BEGIN + IF NEW.address_id = 2850 THEN + -- Fallo que se insertan no se sabe como tickets en este cliente + CALL vn.mail_insert( + 'jgallego@verdnatura.es', + 'noreply@verdnatura.es', + 'Creada order al address 2850', + CONCAT(account.myUser_getName(), ' ha creado la order ',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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` + AFTER UPDATE ON `order` + FOR EACH ROW +BEGIN + CALL stock.log_add('order', NEW.id, OLD.id); + + IF !(OLD.address_id <=> NEW.address_id) + OR !(OLD.company_id <=> NEW.company_id) + OR !(OLD.customer_id <=> NEW.customer_id) THEN + CALL order_requestRecalc(NEW.id); + END IF; + + IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN + -- Fallo que se actualiza no se sabe como tickets en este cliente + CALL vn.mail_insert( + 'jgallego@verdnatura.es', + 'noreply@verdnatura.es', + 'Actualizada order al address 2850', + CONCAT(account.myUser_getName(), ' ha creado la order ',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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_beforeInsert` + BEFORE INSERT ON `orderRow` + FOR EACH ROW +BEGIN + DECLARE vIsFirst BOOL; + + SELECT (first_row_stamp IS NULL) INTO vIsFirst + FROM `order` + WHERE id = NEW.orderFk; + + IF vIsFirst THEN + UPDATE `order` SET first_row_stamp = util.VN_NOW() + WHERE id = NEW.orderFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterInsert` + AFTER INSERT ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NEW.id, NULL); + CALL order_requestRecalc(NEW.orderFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterUpdate` + AFTER UPDATE ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NEW.id, OLD.id); + CALL order_requestRecalc(OLD.orderFk); + CALL order_requestRecalc(NEW.orderFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterDelete` + AFTER DELETE ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NULL, OLD.id); + CALL order_requestRecalc(OLD.orderFk); +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 */ ; + +-- +-- Current Database: `pbx` +-- + +USE `pbx`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`blacklist_beforeInsert` + BEFORE INSERT ON `blacklist` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`blacklist_berforeUpdate` + BEFORE UPDATE ON `blacklist` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`followme_beforeInsert` + BEFORE INSERT ON `followme` + FOR EACH ROW +BEGIN + CALL pbx.phone_isValid(NEW.phone); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`followme_beforeUpdate` + BEFORE UPDATE ON `followme` + FOR EACH ROW +BEGIN + CALL pbx.phone_isValid(NEW.phone); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queue_beforeInsert` + BEFORE INSERT ON `queue` + FOR EACH ROW +BEGIN + CALL queue_isValid(NEW.`name`); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queue_beforeUpdate` + BEFORE UPDATE ON `queue` + FOR EACH ROW +BEGIN + CALL queue_isValid(NEW.`name`); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queuePhone_beforeInsert` + BEFORE INSERT ON `queuePhone` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`queuePhone_beforeUpdate` + BEFORE UPDATE ON `queuePhone` + FOR EACH ROW +BEGIN + CALL phone_isValid(NEW.phone); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_beforeInsert` + BEFORE INSERT ON `sip` + FOR EACH ROW +BEGIN + CALL sip_isValid(NEW.extension); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_afterInsert` + AFTER INSERT ON `sip` + FOR EACH ROW +BEGIN + INSERT INTO sipReg + SET userId = NEW.user_id; + + INSERT IGNORE INTO `account`.userSync (`name`) + SELECT `name` FROM `account`.`user` + WHERE id = NEW.user_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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_beforeUpdate` + BEFORE UPDATE ON `sip` + FOR EACH ROW +BEGIN + CALL sip_isValid(NEW.extension); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `pbx`.`sip_afterUpdate` + AFTER UPDATE ON `sip` + FOR EACH ROW +BEGIN + IF !(OLD.extension <=> NEW.extension) + OR !(OLD.user_id <=> NEW.user_id) THEN + INSERT IGNORE INTO `account`.userSync (`name`) + SELECT `name` FROM `account`.`user` + WHERE id = NEW.user_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 */ ; + +-- +-- Current Database: `psico` +-- + +USE `psico`; + +-- +-- Current Database: `rfid` +-- + +USE `rfid`; + +-- +-- Current Database: `sage` +-- + +USE `sage`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `sage`.`movConta_BEFORE_UPDATE` + BEFORE UPDATE ON `movConta` + FOR EACH ROW +BEGIN + IF NEW.enlazadoSage = TRUE THEN + UPDATE vn.XDiario SET enlazadoSage = TRUE WHERE ASIEN = NEW.Asiento; + 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 */ ; + +-- +-- Current Database: `salix` +-- + +USE `salix`; + +-- +-- Current Database: `srt` +-- + +USE `srt`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `srt`.`expedition_BU` + BEFORE UPDATE ON `expedition` + FOR EACH ROW +BEGIN + + SET NEW.updated = util.VN_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 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`@`localhost`*/ /*!50003 TRIGGER `srt`.`moving_AI` + AFTER INSERT ON `moving` + FOR EACH ROW +BEGIN + + INSERT INTO srt.movingLog(movingFk, expeditionFk, bufferFromFk, bufferToFk, stateFk, isColliding, `action`) + VALUES(NEW.id, NEW.expeditionFk, NEW.bufferFromFk, NEW.bufferToFk, NEW.stateFk, NEW.isColliding, 'NEW2'); + + DELETE FROM srt.movingLast; + + INSERT INTO srt.movingLast (id, expeditionFk, bufferFromFk, bufferToFk) + VALUES(NEW.id, NEW.expeditionFk, NEW.bufferFromFk, NEW.bufferToFk); + + IF srt.buffer_isFull(NEW.bufferToFk) THEN + + CALL srt.buffer_setStateType(NEW.bufferToFk, 'FULL',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 */ ; + +-- +-- Current Database: `stock` +-- + +USE `stock`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`inbound_beforeInsert` + BEFORE INSERT ON `inbound` + FOR EACH ROW +BEGIN + SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); + + CALL visible_log( + NEW.isPicked, + NEW.warehouseFk, + NEW.itemFk, + NEW.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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`inbound_afterDelete` + AFTER DELETE ON `inbound` + FOR EACH ROW +BEGIN + UPDATE outbound o + JOIN inboundPick ou ON ou.outboundFk = o.id + SET o.lack = o.lack + ou.quantity, + o.isSync = FALSE + WHERE ou.inboundFk = OLD.id; + + DELETE FROM inboundPick + WHERE inboundFk = OLD.id; + + CALL visible_log( + OLD.isPicked, + OLD.warehouseFk, + OLD.itemFk, + -OLD.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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`outbound_beforeInsert` + BEFORE INSERT ON `outbound` + FOR EACH ROW +BEGIN + SET NEW.lack = NEW.quantity; + SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); + + CALL visible_log( + NEW.isPicked, + NEW.warehouseFk, + NEW.itemFk, + -NEW.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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `stock`.`outbound_afterDelete` + AFTER DELETE ON `outbound` + FOR EACH ROW +BEGIN + UPDATE inbound i + JOIN inboundPick ou ON ou.inboundFk = i.id + SET i.available = i.available + ou.quantity, + i.isSync = FALSE + WHERE ou.outboundFk = OLD.id; + + DELETE FROM inboundPick + WHERE outboundFk = OLD.id; + + CALL visible_log( + OLD.isPicked, + OLD.warehouseFk, + OLD.itemFk, + OLD.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 */ ; + +-- +-- Current Database: `tmp` +-- + +USE `tmp`; + +-- +-- Current Database: `util` +-- + +USE `util`; + +-- +-- Current Database: `vn` +-- + +USE `vn`; +/*!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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`XDiario_beforeInsert` + BEFORE INSERT ON `XDiario` + FOR EACH ROW +BEGIN + IF NEW.SUBCTA <=> '' THEN + SET NEW.SUBCTA = NULL; + END IF; + IF NEW.SUBCTA IS NOT NULL AND NOT LENGTH(NEW.SUBCTA) <=> 10 THEN + CALL util.throw('INVALID_STRING_LENGTH'); + END IF; + IF NEW.CONTRA <=> '' THEN + SET NEW.CONTRA = NULL; + END IF; + IF NEW.CONTRA IS NOT NULL AND NOT LENGTH(NEW.CONTRA) <=> 10 THEN + CALL util.throw('INVALID_STRING_LENGTH'); + END IF; + CALL XDiario_checkDate(NEW.FECHA); + CALL XDiario_checkDate(NEW.FECHA_EX); + CALL XDiario_checkDate(NEW.FECHA_OP); + CALL XDiario_checkDate(NEW.FECHA_RT); + CALL XDiario_checkDate(NEW.FECREGCON); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`XDiario_beforeUpdate` + BEFORE UPDATE ON `XDiario` + FOR EACH ROW +BEGIN + IF NOT NEW.SUBCTA <=> OLD.SUBCTA THEN + IF NEW.SUBCTA <=> '' THEN + SET NEW.SUBCTA = NULL; + END IF; + IF NEW.SUBCTA IS NOT NULL AND NOT LENGTH(NEW.SUBCTA) <=> 10 THEN + CALL util.throw('INVALID_STRING_LENGTH'); + END IF; + END IF; + IF NOT NEW.CONTRA <=> OLD.CONTRA THEN + IF NEW.CONTRA <=> '' THEN + SET NEW.CONTRA = NULL; + END IF; + IF NEW.CONTRA IS NOT NULL AND NOT LENGTH(NEW.CONTRA) <=> 10 THEN + CALL util.throw('INVALID_STRING_LENGTH'); + END IF; + END IF; + IF NOT NEW.FECHA <=> OLD.FECHA THEN + CALL XDiario_checkDate(NEW.FECHA); + END IF; + IF NOT NEW.FECHA_EX <=> OLD.FECHA_EX THEN + CALL XDiario_checkDate(NEW.FECHA_EX); + END IF; + IF NOT NEW.FECHA_OP <=> OLD.FECHA_OP THEN + CALL XDiario_checkDate(NEW.FECHA_OP); + END IF; + IF NOT NEW.FECHA_RT <=> OLD.FECHA_RT THEN + CALL XDiario_checkDate(NEW.FECHA_RT); + END IF; + IF NOT NEW.FECREGCON <=> OLD.FECREGCON THEN + CALL XDiario_checkDate(NEW.FECREGCON); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_beforeInsert` + BEFORE INSERT ON `address` + FOR EACH ROW +BEGIN + DECLARE vIsEqualizated BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF (NEW.mobile <> '') THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + + IF NEW.isEqualizated IS NULL THEN + SELECT isEqualizated + INTO vIsEqualizated + FROM client + WHERE id = NEW.clientFk; + + SET NEW.isEqualizated = vIsEqualizated; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_afterInsert` + BEFORE INSERT ON `address` + FOR EACH ROW +BEGIN + IF (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_beforeUpdate` + BEFORE UPDATE ON `address` + FOR EACH ROW +BEGIN + + SET NEW.editorFk = account.myUser_getId(); + + IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN + CALL pbx.phone_isValid(NEW.mobile); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_afterUpdate` + AFTER UPDATE ON `address` + FOR EACH ROW +BEGIN + -- Recargos de equivalencia distintos implican facturacion por consignatario + IF NEW.isEqualizated != OLD.isEqualizated THEN + IF + (SELECT COUNT(*) FROM + ( + SELECT DISTINCT (isEqualizated = FALSE) as Equ + FROM address + WHERE clientFk = NEW.clientFk + ) t1 + ) > 1 + THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + END IF; + END IF; + IF NEW.isDefaultAddress AND NEW.isActive = FALSE THEN + CALL util.throw ('Cannot desactivate the default address'); + END IF; + + IF NOT (NEW.isEqualizated <=> OLD.isEqualizated) THEN + INSERT IGNORE INTO ticketRecalc (ticketFk) + SELECT id FROM ticket t + WHERE t.addressFk = NEW.id + AND t.refFk IS NULL; + END IF; + + IF (NEW.clientFk <> OLD.clientFk OR NEW.isActive <> OLD.isActive OR NOT (NEW.provinceFk <=> OLD.provinceFk)) + AND (SELECT client_hasDifferentCountries(NEW.clientFk)) THEN + UPDATE client + SET hasToInvoiceByAddress = TRUE + WHERE id = NEW.clientFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`address_afterDelete` + AFTER DELETE ON `address` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Address', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`agency_afterInsert` + AFTER INSERT ON `agency` + FOR EACH ROW +BEGIN + INSERT INTO agencyMode(name,agencyFk) VALUES(NEW.name,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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_BI` + BEFORE INSERT ON `autonomy` + FOR EACH ROW +BEGIN + + SET NEW.geoFk = zoneGeo_new('autonomy', NEW.`name`, (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_BU` + BEFORE UPDATE ON `autonomy` + FOR EACH ROW +BEGIN + IF !(OLD.countryFk <=> NEW.countryFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`autonomy_AD` + AFTER DELETE ON `autonomy` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`awb_bi` + BEFORE INSERT ON `awb` + FOR EACH ROW +BEGIN + + SET NEW.year= year(util.VN_CURDATE()); + + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`bankEntity_beforeInsert` + BEFORE INSERT ON `bankEntity` + FOR EACH ROW +BEGIN + CALL bankEntity_checkBic(NEW.bic); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`bankEntity_beforeUpdate` + BEFORE UPDATE ON `bankEntity` + FOR EACH ROW +BEGIN + IF NOT (NEW.bic <=> OLD.bic) THEN + CALL bankEntity_checkBic(NEW.bic); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`budgetNotes_BeforeInsert` + BEFORE INSERT ON `budgetNotes` + FOR EACH ROW +BEGIN + + IF ISNULL(NEW.userFk) THEN + + SET NEW.userFk = account.myUser_getId(); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_beforeInsert` + BEFORE INSERT ON `business` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.ended IS NULL THEN + SET NEW.payedHolidays = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_afterInsert` + AFTER INSERT ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_beforeUpdate` + BEFORE UPDATE ON `business` + FOR EACH ROW +BEGIN + DECLARE isOverlapping BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.ended IS NULL THEN + SET NEW.payedHolidays = 0; + END IF; + + IF !(OLD.started <=> NEW.started AND OLD.ended <=> NEW.ended) THEN + + SELECT COUNT(*) > 0 INTO isOverlapping + FROM business b + WHERE (util.hasDateOverlapped( + NEW.started, + IFNULL(NEW.ended, b.started), + b.started, + IFNULL(b.ended, NEW.started)) + OR (NEW.ended <=> NULL AND b.ended <=> NULL)) + AND b.id <> OLD.id + AND workerFk = OLD.workerFk; + + IF isOverlapping THEN + CALL util.throw ('IS_OVERLAPPING'); + 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_afterUpdate` + AFTER UPDATE ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); + + IF NOT (OLD.workerFk <=> NEW.workerFk) THEN + CALL worker_updateBusiness(OLD.workerFk); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`business_afterDelete` + AFTER DELETE ON `business` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'Business', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL worker_updateBusiness(OLD.workerFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeInsert` + BEFORE INSERT ON `buy` + FOR EACH ROW +trig: BEGIN + DECLARE vWarehouse INT; + DECLARE vLanding DATE; + DECLARE vGrouping INT; + DECLARE vGroupingMode TINYINT; + DECLARE vGenericFk INT; + DECLARE vGenericInDate BOOL; + + IF @isModeInventory THEN + LEAVE trig; + END IF; + + IF NEW.printedStickers <> 0 THEN + CALL util.throw('it is not possible to create buy lines with printedstickers other than 0'); + END IF; + + SET NEW.editorFk = account.myUser_getId(); + + CALL buy_checkGrouping(NEW.`grouping`); + + SELECT t.warehouseInFk, t.landed + INTO vWarehouse, vLanding + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.id = NEW.entryFk; + + SELECT b.`grouping`, b.groupingMode + INTO vGrouping, vGroupingMode + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed <= vLanding + AND b.itemFk = NEW.itemFk + 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` = vGrouping; + END IF; + + IF NEW.groupingMode IS NULL THEN + SET NEW.groupingMode = vGroupingMode; + END IF; + + -- Generics + SELECT i.genericFk INTO vGenericFk + FROM item i + WHERE i.id = NEW.itemFk; + + IF vGenericFk THEN + SELECT COUNT(*) INTO vGenericInDate + FROM genericAllocation ga + JOIN entry e ON e.id = NEW.entryFk + JOIN travel tr on tr.id = e.travelFk + WHERE ga.itemFk = vGenericFk + AND tr.landed BETWEEN ga.startDated AND ga.endDated; + + IF vGenericInDate THEN + SET NEW.itemOriginalFk = NEW.itemFk; + SET NEW.itemFk = vGenericFk; + END IF; + END IF; + + IF NEW.quantity < 0 THEN + SET NEW.isIgnored = TRUE; + END IF; + + IF NEW.weight AND NEW.packing + AND (SELECT weightByPiece FROM item WHERE id = NEW.itemFk) IS NULL THEN + + UPDATE item + SET weightByPiece = (NEW.weight * 1000) / NEW.packing + WHERE id = NEW.itemFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterInsert` + AFTER INSERT ON `buy` + FOR EACH ROW +trig: BEGIN + IF @isModeInventory OR @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL stock.log_add('buy', NEW.id, NULL); + + CALL buy_afterUpsert(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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeUpdate` + BEFORE UPDATE ON `buy` + FOR EACH ROW +trig:BEGIN + DECLARE vGenericFk INT; + DECLARE vGenericInDate BOOL; + DECLARE vIsInventory BOOL; + DECLARE vDefaultEntry INT; + + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT defaultEntry INTO vDefaultEntry + FROM entryConfig; + + IF (NOT OLD.entryFk <=> NEW.entryFk OR NOT OLD.printedStickers <=> NEW.printedStickers) + AND NEW.printedStickers <> 0 THEN + SELECT defaultEntry INTO vDefaultEntry + FROM entryConfig; + + IF NEW.entryFk = vDefaultEntry THEN + CALL util.throw('There can be no lines with printed labels on the default entry'); + END IF; + END IF; + + IF NOT NEW.`grouping` <=> OLD.`grouping` THEN + CALL buy_checkGrouping(NEW.`grouping`); + END IF; + + -- Generics + SELECT i.genericFk INTO vGenericFk + FROM item i + WHERE i.id = NEW.itemFk; + + IF vGenericFk THEN + SELECT COUNT(*) INTO vGenericInDate + FROM genericAllocation ga + JOIN entry e ON e.id = NEW.entryFk + JOIN travel tr on tr.id = e.travelFk + WHERE ga.itemFk = vGenericFk + AND tr.landed BETWEEN ga.startDated AND ga.endDated; + IF vGenericInDate THEN + SET NEW.itemOriginalFk = NEW.itemFk; + SET NEW.itemFk = vGenericFk; + END IF; + END IF; + + SELECT COUNT(*) INTO vIsInventory + FROM entry e + JOIN supplier s ON s.id = e.supplierFk + JOIN entryConfig ec ON ec.inventorySupplierFk = e.supplierFk + WHERE e.id = NEW.entryFk; + + IF vIsInventory THEN + IF NOT NEW.printedStickers <=> OLD.printedStickers THEN + CALL util.throw("Stickers cannot be modified if they are inventory"); + END IF; + END IF; + + IF NEW.quantity < 0 THEN + SET NEW.isIgnored = TRUE; + 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterUpdate` + AFTER UPDATE ON `buy` + FOR EACH ROW +trig: BEGIN + DECLARE vLanded DATE; + DECLARE vBuyerFk INT; + DECLARE vIsBuyerToBeEmailed BOOL; + DECLARE vItemName VARCHAR(50); + + IF @isModeInventory OR @isTriggerDisabled THEN + LEAVE trig; + END IF; + + IF !(NEW.id <=> OLD.id) + OR !(NEW.entryFk <=> OLD.entryFk) + OR !(NEW.itemFk <=> OLD.itemFk) + OR !(NEW.quantity <=> OLD.quantity) + OR !(NEW.created <=> OLD.created) THEN + CALL stock.log_add('buy', NEW.id, OLD.id); + END IF; + + CALL buy_afterUpsert(NEW.id); + + SELECT w.isBuyerToBeEmailed, t.landed + INTO vIsBuyerToBeEmailed, vLanded + FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + WHERE e.id = NEW.entryFk; + + SELECT it.workerFk, i.longName + INTO vBuyerFk, vItemName + FROM itemCategory k + JOIN itemType it ON it.categoryFk = k.id + JOIN item i ON i.typeFk = it.id + WHERE i.id = OLD.itemFk; + + IF vIsBuyerToBeEmailed AND + vBuyerFk != account.myUser_getId() AND + vLanded = util.VN_CURDATE() THEN + IF !(NEW.itemFk <=> OLD.itemFk) OR + !(NEW.quantity <=> OLD.quantity) OR + !(NEW.packing <=> OLD.packing) OR + !(NEW.grouping <=> OLD.grouping) OR + !(NEW.packagingFk <=> OLD.packagingFk) OR + !(NEW.weight <=> OLD.weight) THEN + CALL vn.mail_insert( + CONCAT(account.user_getNameFromId(vBuyerFk),'@verdnatura.es'), + CONCAT(account.myUser_getName(),'@verdnatura.es'), + CONCAT('E ', NEW.entryFk ,' Se ha modificado item ', NEW.itemFk, ' ', vItemName), + 'Este email se ha generado automáticamente' + ); + 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeDelete` + BEFORE DELETE ON buy + FOR EACH ROW +BEGIN + IF OLD.printedStickers <> 0 THEN + CALL util.throw("it is not possible to delete buys with printed labels "); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterDelete` + AFTER DELETE ON `buy` + FOR EACH ROW +trig: BEGIN + DECLARE vValues VARCHAR(255); + + IF @isModeInventory OR @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL stock.log_add('buy', NULL, OLD.id); + + INSERT INTO entryLog + SET `action` = 'delete', + `changedModel` = 'Buy', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claim_beforeInsert` + BEFORE INSERT ON `claim` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claim_beforeUpdate` + BEFORE UPDATE ON `claim` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claim_afterDelete` + AFTER DELETE ON `claim` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'Claim', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimBeginning_beforeInsert` + BEFORE INSERT ON `claimBeginning` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimBeginning_beforeUpdate` + BEFORE UPDATE ON `claimBeginning` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimBeginning_afterDelete` + AFTER DELETE ON `claimBeginning` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimBeginning', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDevelopment_beforeInsert` + BEFORE INSERT ON `claimDevelopment` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDevelopment_beforeUpdate` + BEFORE UPDATE ON `claimDevelopment` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDevelopment_afterDelete` + AFTER DELETE ON `claimDevelopment` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimDevelopment', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDms_beforeInsert` + BEFORE INSERT ON `claimDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDms_beforeUpdate` + BEFORE UPDATE ON `claimDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimDms_afterDelete` + AFTER DELETE ON `claimDms` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimDms', + `changedModelId` = OLD.claimFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimEnd_beforeInsert` + BEFORE INSERT ON `claimEnd` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimEnd_beforeUpdate` + BEFORE UPDATE ON `claimEnd` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimEnd_afterDelete` + AFTER DELETE ON `claimEnd` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimEnd', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimObservation_beforeInsert` + BEFORE INSERT ON `claimObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimObservation_beforeUpdate` + BEFORE UPDATE ON `claimObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimObservation_afterDelete` + AFTER DELETE ON `claimObservation` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_beforeInsert` + BEFORE INSERT ON `claimState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_beforeUpdate` + BEFORE UPDATE ON `claimState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`claimState_afterDelete` + AFTER DELETE ON `claimState` + FOR EACH ROW +BEGIN + INSERT INTO claimLog + SET `action` = 'delete', + `changedModel` = 'ClaimState', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_beforeInsert` + BEFORE INSERT ON `client` + FOR EACH ROW +BEGIN + + SET NEW.editorFk = account.myUser_getId(); + + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF (NEW.mobile <> '') THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + + SET NEW.accountingAccount = 4300000000 + NEW.id; + + SET NEW.lastSalesPersonFk = NEW.salesPersonFk; +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_AfterInsert` + AFTER INSERT ON `client` + FOR EACH ROW +BEGIN + IF NEW.credit IS NOT NULL AND NEW.credit THEN + INSERT INTO clientCredit + SET clientFk = NEW.id, + workerFk = NEW.editorFk, + amount = NEW.credit; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_beforeUpdate` + BEFORE UPDATE ON `client` + FOR EACH ROW +BEGIN + DECLARE vText VARCHAR(255) DEFAULT NULL; + DECLARE vPayMethodFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF NOT(NEW.credit <=> OLD.credit) THEN + INSERT INTO clientCredit + SET clientFk = NEW.id, + amount = NEW.credit, + workerFk = NEW.editorFk; + END IF; + -- Comprueba que el formato de los teléfonos es válido + + IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + + SELECT id INTO vPayMethodFk + FROM vn.payMethod + WHERE code = 'bankDraft'; + + IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN + SET NEW.dueDay = 5; + END IF; + + -- Avisar al comercial si ha llegado la documentación sepa/core + + IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN + SET vText = 'Sepa de VNL'; + END IF; + + IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN + SET vText = 'Core de VNL'; + END IF; + + IF vText IS NOT NULL + THEN + INSERT INTO mail(receiver, replyTo, `subject`, body) + SELECT + CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'), + 'administracion@verdnatura.es', + CONCAT('Cliente ', NEW.id), + CONCAT('Recibida la documentación: ', vText) + FROM worker w + LEFT JOIN account.user u ON w.id = u.id AND u.active + LEFT JOIN account.account ac ON ac.id = u.id + WHERE w.id = NEW.salesPersonFk; + END IF; + + IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN + IF (SELECT COUNT(clientFk) + FROM clientProtected + WHERE clientFk = NEW.id + ) > 0 THEN + CALL util.throw("HAS_CLIENT_PROTECTED"); + END IF; + END IF; + + IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN + SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk); + END IF; + + IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN + SET NEW.isTaxDataChecked = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_afterUpdate` + AFTER UPDATE ON `client` + FOR EACH ROW +BEGIN + IF !(NEW.defaultAddressFk <=> OLD.defaultAddressFk) THEN + UPDATE `address` SET isDefaultAddress = 0 + WHERE clientFk = NEW.id; + + UPDATE `address` SET isDefaultAddress = 1 + WHERE id = NEW.defaultAddressFk; + END IF; + + IF NOT (NEW.provinceFk <=> OLD.provinceFk) OR NOT (NEW.isVies <=> OLD.isVies) THEN + INSERT IGNORE INTO ticketRecalc (ticketFk) + SELECT id FROM ticket t + WHERE t.clientFk = NEW.id + AND t.refFk IS NULL; + END IF; + + IF NOT NEW.isActive THEN + UPDATE account.`user` + SET active = FALSE + WHERE id = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`client_afterDelete` + AFTER DELETE ON `client` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Client', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientContact_beforeInsert` + BEFORE INSERT ON `clientContact` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientContact_afterDelete` + AFTER DELETE ON `clientContact` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientContact', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER clientCredit_AfterInsert +AFTER INSERT +ON clientCredit FOR EACH ROW +BEGIN + + DECLARE vSender VARCHAR(50); + + SELECT u.name INTO vSender + FROM account.`user` u + WHERE u.id = NEW.workerFk; + + IF vSender IN ('juanvi','pepe') THEN + + CALL `vn`.`mail_insert`('pako@verdnatura.es', + NULL, + CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €'), + CONCAT('ClientCredit ',vSender, ' ', NEW.clientFk, ' ' , NEW.amount, ' €')); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientDms_beforeInsert` + BEFORE INSERT ON `clientDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientDms_beforeUpdate` + BEFORE UPDATE ON `clientDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientDms_afterDelete` + AFTER DELETE ON `clientDms` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientDms', + `changedModelId` = OLD.dmsFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientObservation_beforeInsert` + BEFORE INSERT ON `clientObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientObservation_beforeUpdate` + BEFORE UPDATE ON `clientObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientObservation_afterDelete` + AFTER DELETE ON `clientObservation` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientSample_beforeInsert` + BEFORE INSERT ON `clientSample` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientSample_beforeUpdate` + BEFORE UPDATE ON `clientSample` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`clientSample_afterDelete` + AFTER DELETE ON `clientSample` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'ClientSample', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`cmr_beforeDelete` + BEFORE DELETE ON `cmr` + FOR EACH ROW +BEGIN + IF NOT (OLD.companyFk <=> NULL AND OLD.addressFromFk <=> NULL AND OLD.packagesList <=> NULL) THEN + CALL util.throw("Can not delete cmr, fields required not empty"); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE` + BEFORE UPDATE ON `collection` + FOR EACH ROW +BEGIN + + DECLARE vStateFk INT; + DECLARE vTotalLines INT; + DECLARE vPickedLines INT; + + IF NEW.saleTotalCount <= NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount + OR NEW.salePickedCount != OLD.salePickedCount) + THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'PREPARED'; + + SET NEW.stateFk = vStateFk; + + END IF; + + IF NEW.saleTotalCount > NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'ON_PREPARATION'; + + SET NEW.stateFk = vStateFk; + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER vn.collectionColors_beforeInsert +BEFORE INSERT +ON collectionColors FOR EACH ROW +BEGIN + CALL util.checkHex(NEW.rgb); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionColors_beforeUpdate` + BEFORE UPDATE ON `collectionColors` + FOR EACH ROW +BEGIN + CALL util.checkHex(NEW.rgb); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionVolumetry_afterInsert` + AFTER INSERT ON `collectionVolumetry` + FOR EACH ROW +BEGIN + DECLARE vJSON JSON DEFAULT JSON_OBJECT(); + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.level), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('lines', NEW.lines), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('liters', NEW.liters), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('height', NEW.height), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); + + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'insert'), vJSON); + + SET vJSON = util.notification_send( + 'modified-collection-volumetry', + JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), + vUserFk + ); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionVolumetry_afterUpdate` + AFTER UPDATE ON `collectionVolumetry` + FOR EACH ROW +BEGIN + DECLARE vJSON JSON DEFAULT JSON_OBJECT(); + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + IF NOT (NEW.id <=> OLD.id) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('id', NEW.id), vJSON); + END IF; + + IF NOT (NEW.`level` <=> OLD.`level`) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('level', NEW.`level`), vJSON); + END IF; + + IF NOT (NEW.`lines` <=> OLD.`lines`) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('lines', NEW.`lines`), vJSON); + END IF; + + IF NOT (NEW.liters <=> OLD.liters) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('liters', NEW.liters), vJSON); + END IF; + + IF NOT (NEW.height <=> OLD.height) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('height', NEW.height), vJSON); + END IF; + + IF NOT (NEW.itemPackingTypeFk <=> OLD.itemPackingTypeFk) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', NEW.itemPackingTypeFk), vJSON); + END IF; + + IF NOT (NEW.trainFk <=> OLD.trainFk) THEN + SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', NEW.trainFk), vJSON); + END IF; + + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'update'), vJSON); + + SET vJSON = util.notification_send( + 'modified-collection-volumetry', + JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), + vUserFk + ); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collectionVolumetry_afterDelete` + AFTER DELETE ON `collectionVolumetry` + FOR EACH ROW +BEGIN + DECLARE vJSON JSON DEFAULT JSON_OBJECT(); + DECLARE vUserFk INT DEFAULT account.myUser_getId(); + + SET vJSON = JSON_MERGE(JSON_OBJECT('id', OLD.id), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('level', OLD.level), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('lines', OLD.lines), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('liters', OLD.liters), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('height', OLD.height), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('itemPackingTypeFk', OLD.itemPackingTypeFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('trainFk', OLD.trainFk), vJSON); + + SET vJSON = JSON_MERGE(JSON_OBJECT('userFk', vUserFk), vJSON); + SET vJSON = JSON_MERGE(JSON_OBJECT('action', 'delete'), vJSON); + + SET vJSON = util.notification_send( + 'modified-collection-volumetry', + JSON_OBJECT('data', JSON_EXTRACT(vJSON, '$')), + vUserFk + ); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_beforeInsert` + BEFORE INSERT ON `country` + FOR EACH ROW +BEGIN + SET NEW.geoFk = zoneGeo_new('country', NEW.country, 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_AFTER_INSERT` + AFTER INSERT ON `country` + FOR EACH ROW +BEGIN + UPDATE sage.Naciones + SET countryFk = NEW.id + WHERE Nacion = NEW.country; + + IF ROW_COUNT() = 0 THEN + CALL mail_insert( + 'cau@verdnatura.es', + NULL, + 'Actualizar tabla sage.Naciones', + CONCAT('Se ha insertado un nuevo país en la tabla vn.conuntry. Para el correcto funcionamiento del sistema \n\t\t\t\tde contabilidad es necesario actualizar la columna sage.Naciones.countryFk con el valor del nuevo país. \n\t\t\t Hay que buscar el nuevo país: ', NEW.country, ' en la tabla sage.Naciones y actualizar el campo sage.Naciones.countryFk con el valor ', 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_beforeUpdate` + BEFORE UPDATE ON `country` + FOR EACH ROW +BEGIN + -- IF !(OLD.geoFk <=> NEW.geoFk) THEN + -- CALL zoneGeo_throwNotEditable; + -- 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_afterUpdate` + AFTER UPDATE ON `country` + FOR EACH ROW +BEGIN + IF !(OLD.country <=> NEW.country) THEN + UPDATE zoneGeo SET `name` = NEW.country + WHERE id = NEW.geoFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`country_afterDelete` + AFTER DELETE ON `country` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`creditClassification_beforeUpdate` + BEFORE UPDATE ON `creditClassification` + FOR EACH ROW +BEGIN + IF NEW.client <> OLD.client THEN + CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT'); + END IF; + IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN + UPDATE `client` c + SET creditInsurance = NULL WHERE c.id = NEW.client; + 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`creditInsurance_beforeInsert` + BEFORE INSERT ON `creditInsurance` + FOR EACH ROW +BEGIN + IF NEW.creditClassificationFk THEN + SET NEW.creditClassification = NEW.creditClassificationFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`creditInsurance_afterInsert` + AFTER INSERT ON `creditInsurance` + FOR EACH ROW +BEGIN + UPDATE `client` c + JOIN vn.creditClassification cc ON cc.client = c.id + SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification; + +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`delivery_beforeInsert` + BEFORE INSERT ON `delivery` + FOR EACH ROW +BEGIN + + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) + THEN + UPDATE address + SET longitude = NEW.longitude, + latitude = NEW.latitude + WHERE id IN ( + SELECT addressFK + FROM ticket + WHERE id = NEW.ticketFk + ); + 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`delivery_beforeUpdate` + BEFORE UPDATE ON `delivery` + FOR EACH ROW +BEGIN + +IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) + THEN + UPDATE address + SET longitude = NEW.longitude, + latitude = NEW.latitude + WHERE id IN ( + SELECT addressFK + FROM ticket + WHERE id = NEW.ticketFk + ); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_beforeInsert` + BEFORE INSERT ON `department` + FOR EACH ROW +BEGIN + UPDATE vn.department_recalc SET isChanged = TRUE; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_afterUpdate` + AFTER UPDATE ON `department` + FOR EACH ROW +BEGIN + IF !(OLD.parentFk <=> NEW.parentFk) THEN + UPDATE vn.department_recalc SET isChanged = TRUE; + END IF; + + IF !(OLD.twoFactor <=> NEW.twoFactor) THEN + UPDATE account.user u + JOIN vn.workerDepartment wd ON wd.workerFk = u.id + SET u.twoFactor = NEW.twoFactor + WHERE wd.departmentFk = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_beforeDelete` + BEFORE DELETE ON `department` + FOR EACH ROW +BEGIN + + UPDATE vn.business b + JOIN vn.department d ON d.id = b.departmentFk + SET b.departmentFk = d.parentFk + WHERE b.departmentFk = 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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`department_afterDelete` + AFTER DELETE ON `department` + FOR EACH ROW +BEGIN + + UPDATE vn.department_recalc SET isChanged = TRUE; + + UPDATE vn.business b + JOIN vn.department d ON d.id = b.departmentFk + SET b.departmentFk = d.parentFk + WHERE b.departmentFk = 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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProduction_beforeInsert` + BEFORE INSERT ON `deviceProduction` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProduction_beforeUpdate` + BEFORE UPDATE ON `deviceProduction` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProduction_afterDelete` + AFTER DELETE ON `deviceProduction` + FOR EACH ROW +BEGIN + INSERT INTO deviceProductionLog + SET `action` = 'delete', + `changedModel` = 'DeviceProduction', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionConfig_afterUpdate` + AFTER UPDATE ON `deviceProductionConfig` + FOR EACH ROW +BEGIN + IF NEW.isAllUsersAllowed = 1 OR NEW.isAllUsersAllowed = -1 THEN + SET @username := (SELECT account.myUser_getName()); + INSERT INTO vn.mail (receiver, subject, body) + VALUES ('cau@verdnatura.es', 'Se ha activado la autenticación sin restricciones en la app', + CONCAT('El usuario ', @username,' ha habilitado la opción para que todos los usuarios puedan acceder a la app sin restricciones')); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionModels_beforeInsert` + BEFORE INSERT ON `deviceProductionModels` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionModels_beforeUpdate` + BEFORE UPDATE ON `deviceProductionModels` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionState_beforeInsert` + BEFORE INSERT ON `deviceProductionState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionState_beforeUpdate` + BEFORE UPDATE ON `deviceProductionState` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionUser_beforeInsert` + BEFORE INSERT ON `deviceProductionUser` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionUser_beforeUpdate` + BEFORE UPDATE ON `deviceProductionUser` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`deviceProductionUser_afterDelete` + AFTER DELETE ON `deviceProductionUser` + FOR EACH ROW +BEGIN + INSERT INTO deviceProductionLog + SET `action` = 'delete', + `changedModel` = 'DeviceProductionUser', + `changedModelId` = OLD.deviceProductionFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeInsert` + BEFORE INSERT ON `dms` + FOR EACH ROW +BEGIN + DECLARE vHardCopyNumber INT; + DECLARE vDmsTypeCode INT; + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + CALL util.throw('this warehouse has not dms'); + END IF; + + IF NEW.hasFile THEN + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms + WHERE warehouseFk = NEW.warehouseFk; + + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); + END IF; + + SELECT code INTO vDmsTypeCode + FROM dmsType WHERE NEW.dmsTypeFk = id; + IF (vDmsTypeCode ='ticket') THEN + UPDATE ticket SET isSigned = 1 WHERE id = NEW.reference; + 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` + BEFORE UPDATE ON `dms` + FOR EACH ROW +BEGIN + DECLARE vHardCopyNumber INT; + + IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) + OR + (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); + END IF; + + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms + WHERE warehouseFk = NEW.warehouseFk; + + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); + END IF; + + IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN + + SET NEW.hasFile = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeDelete` + BEFORE DELETE ON `dms` + FOR EACH ROW +BEGIN + DECLARE vCanNotBeDeleted INT; + SELECT COUNT(*) INTO vCanNotBeDeleted + FROM dmsType dt + WHERE NOT (code <=> 'trash') + AND dt.id = OLD.dmsTypeFk; + + IF vCanNotBeDeleted THEN + CALL util.throw('A dms can not 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`duaTax_BEFORE_INSERT` + BEFORE INSERT ON `duaTax` + FOR EACH ROW +BEGIN + SET NEW.rate = duaTax_getRate(NEW.duaFk, NEW.taxClassFk); + SET NEW.tax = NEW.base * NEW.rate / 100; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`duaTax_BEFORE_UPDATE` + BEFORE UPDATE ON `duaTax` + FOR EACH ROW +BEGIN + SET NEW.rate = duaTax_getRate(NEW.duaFk, NEW.taxClassFk); + SET NEW.tax = NEW.base * NEW.rate / 100; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ektEntryAssign_afterInsert +AFTER INSERT +ON ektEntryAssign FOR EACH ROW + UPDATE entry SET reference = NEW.`ref` WHERE id = NEW.entryFk */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER vn.ektEntryAssign_afterUpdate + AFTER UPDATE ON ektEntryAssign + FOR EACH ROW +BEGIN + IF NOT(NEW.`ref` <=> OLD.`ref`) OR NOT(NEW.`entryFk` <=> OLD.`entryFk`) THEN + UPDATE entry SET reference = NEW.`ref` WHERE id = NEW.entryFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_beforeInsert` + BEFORE INSERT ON `entry` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL supplier_checkIsActive(NEW.supplierFk); + SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); + SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_afterInsert` + AFTER INSERT ON `entry` + FOR EACH ROW +BEGIN + CALL travel_requestRecalc(NEW.travelFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_beforeUpdate` + BEFORE UPDATE ON `entry` + FOR EACH ROW +BEGIN + DECLARE vIsVirtual BOOL; + DECLARE vPrintedCount INT; + DECLARE vHasDistinctWarehouses BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF !(NEW.travelFk <=> OLD.travelFk) THEN + SELECT COUNT(*) > 0 INTO vIsVirtual + FROM entryVirtual WHERE entryFk = NEW.id; + + SELECT !(o.warehouseInFk <=> n.warehouseInFk) + OR !(o.warehouseOutFk <=> n.warehouseOutFk) + INTO vHasDistinctWarehouses + FROM travel o, travel n + WHERE o.id = OLD.travelFk + AND n.id = NEW.travelFk; + + IF vIsVirtual AND vHasDistinctWarehouses THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'A cloned entry cannot be moved to a travel with different warehouses'; + END IF; + + IF NEW.travelFk IS NULL THEN + SELECT COUNT(*) INTO vPrintedCount + FROM buy + WHERE entryFk = OLD.id + AND printedStickers > 0; + + IF vPrintedCount > 0 THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'An entry that contains lines with printed labels cannot be deleted'; + END IF; + END IF; + END IF; + + IF NOT (NEW.supplierFk <=> OLD.supplierFk) THEN + CALL supplier_checkIsActive(NEW.supplierFk); + SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); + END IF; + + IF NOT (NEW.travelFk <=> OLD.travelFk) + OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN + SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk,NEW.supplierFk); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_afterUpdate` + AFTER UPDATE ON `entry` + FOR EACH ROW +BEGIN + IF NOT(NEW.id <=> OLD.id) + OR NOT(NEW.travelFk <=> OLD.travelFk) + OR NOT(NEW.isRaid <=> OLD.isRaid) THEN + CALL stock.log_add('entry', NEW.id, OLD.id); + END IF; + + IF NOT (NEW.travelFk <=> OLD.travelFk) THEN + CALL travel_requestRecalc(OLD.travelFk); + CALL travel_requestRecalc(NEW.travelFk); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_beforeDelete` + BEFORE DELETE ON `entry` + FOR EACH ROW +BEGIN + DELETE FROM buy WHERE entryFk = 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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entry_afterDelete` + AFTER DELETE ON `entry` + FOR EACH ROW +BEGIN + INSERT INTO entryLog + SET `action` = 'delete', + `changedModel` = 'Entry', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL travel_requestRecalc(OLD.travelFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entryObservation_beforeInsert` + BEFORE INSERT ON `entryObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entryObservation_beforeUpdate` + BEFORE UPDATE ON `entryObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`entryObservation_afterDelete` + AFTER DELETE ON `entryObservation` + FOR EACH ROW +BEGIN + INSERT INTO entryLog + SET `action` = 'delete', + `changedModel` = 'EntryObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeInsert` + BEFORE INSERT ON `expedition` + FOR EACH ROW +BEGIN + DECLARE intcounter INT; + DECLARE vShipFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.freightItemFk IS NOT NULL THEN + + UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk; + + SELECT IFNULL(MAX(counter),0) +1 INTO intcounter + FROM expedition e + INNER JOIN ticket t1 ON e.ticketFk = t1.id + LEFT JOIN ticketState ts ON ts.ticketFk = t1.id + INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + AND t1.warehouseFk = t2.warehouseFk + WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk + AND t1.agencyModeFk = t2.agencyModeFk; + + SET NEW.`counter` = intcounter; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeUpdate` + BEFORE UPDATE ON `expedition` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.counter <> OLD.counter THEN + IF (SELECT COUNT(*) FROM expedition e + INNER JOIN ticket t1 ON e.ticketFk = t1.id + INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped) + WHERE t1.id = NEW.ticketFk AND counter = NEW.counter) > 0 THEN + SET NEW.id = NULL; + 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_beforeDelete` + BEFORE DELETE ON `expedition` + FOR EACH ROW +BEGIN + UPDATE ticket t + SET packages = (SELECT COUNT(counter)-1 + FROM expedition e WHERE e.ticketFk = OLD.ticketFk and e.freightItemFk) + WHERE t.id = OLD.ticketFk; + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expedition_afterDelete` + AFTER DELETE ON `expedition` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'Expedition', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionPallet_BEFORE_INSERT` + BEFORE INSERT ON `expeditionPallet` + FOR EACH ROW +BEGIN + + DECLARE vNewPosition INT; + + SELECT MAX(position) + 1 INTO vNewPosition + FROM vn.expeditionPallet + WHERE truckFk = NEW.truckFk; + + SET NEW.position = IFNULL(vNewPosition,1); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionScan_BEFORE_INSERT` + BEFORE INSERT ON `expeditionScan` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionState_BeforeInsert` + BEFORE INSERT ON `expeditionState` + FOR EACH ROW +BEGIN + SET NEW.userFk = IFNULL(NEW.userFk, account.myUser_getId()); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER expeditionState_AfterInsert +AFTER INSERT +ON expeditionState FOR EACH ROW +BEGIN + + UPDATE vn.expedition e + SET e.stateTypeFk = NEW.typeFk + WHERE e.id = NEW.expeditionFk; + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionTruck_BEFORE_INSERT` + BEFORE INSERT ON `expeditionTruck` + FOR EACH ROW +BEGIN + + SET NEW.description = UCASE(NEW.description); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`expeditionTruck_BEFORE_UPDATE` + BEFORE UPDATE ON `expeditionTruck` + FOR EACH ROW +BEGIN + + SET NEW.description = UCASE(NEW.description); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`floramondoConfig_AFTER_INSERT` + AFTER INSERT ON `floramondoConfig` + FOR EACH ROW +BEGIN + CALL util.throw ("Tabla config no permite añadir más registros"); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`gregue_beforeInsert` + BEFORE INSERT ON greuge + FOR EACH ROW +BEGIN + IF NEW.userFk IS NULL THEN + SET NEW.userFk = account.myUser_getId(); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`greuge_beforeInsert` + BEFORE INSERT ON `greuge` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`greuge_beforeUpdate` + BEFORE UPDATE ON `greuge` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`greuge_afterDelete` + AFTER DELETE ON `greuge` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Greuge', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`host_beforeUpdate` + BEFORE UPDATE ON `host` + FOR EACH ROW +BEGIN + SET new.updated = util.VN_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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_bi` + BEFORE INSERT ON `invoiceIn` + FOR EACH ROW +BEGIN + DECLARE vSerie CHAR(1) DEFAULT 'R'; + DECLARE vNumReceived INT; + DECLARE vIssuingCountry, vhostCountry INT; + DECLARE vActive TINYINT; + DECLARE vWithholdingSageFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier + WHERE id = NEW.supplierFk; + + SET NEW.withholdingSageFk = vWithholdingSageFk; + + SELECT countryFk, isActive INTO vIssuingCountry, vActive + FROM vn.supplier + WHERE id = NEW.supplierFk; + + SELECT countryFk INTO vhostCountry + FROM vn.supplier + WHERE id = NEW.companyFk; + + IF vActive = 0 THEN + CALL util.throw('INACTIVE_PROVIDER'); + END IF; + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + ) THEN + CALL util.throw('reference duplicated'); + END IF; + + SELECT CASE WHEN (SELECT account FROM vn.supplier where id = NEW.supplierFk) LIKE '___3______' THEN 'C' + WHEN (SELECT vIssuingCountry=vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'R' + WHEN (SELECT vIssuingCountry <> vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where p1.CEE < 2 and p2.CEE < 2) = 1 THEN 'E' + WHEN (SELECT vIssuingCountry<>vhostCountry from vn.country p1 join vn.country p2 ON p2.id = vhostCountry AND p1.id = vIssuingCountry + where NOT p1.CEE < 2 AND not p1.id = 1) = 1 THEN 'W' + END INTO vSerie; + + SET NEW.serial = IFNULL(vSerie,'R'); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_bu` + BEFORE UPDATE ON `invoiceIn` + FOR EACH ROW +BEGIN + + DECLARE vWithholdingSageFk INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF (SELECT COUNT(*) FROM vn.invoiceIn + WHERE supplierRef = NEW.supplierRef + AND supplierFk = NEW.supplierFk + AND YEAR(issued) = YEAR(NEW.issued) + AND id <> NEW.id + ) THEN + CALL util.throw('reference duplicated'); + END IF; + + IF NEW.supplierFk != OLD.supplierFk THEN + CALL supplier_checkIsActive(NEW.supplierFk); + SELECT withholdingSageFk INTO vWithholdingSageFk + FROM vn.supplier + WHERE id = NEW.supplierFk; + SET NEW.withholdingSageFk = vWithholdingSageFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_au` + AFTER UPDATE ON `invoiceIn` + FOR EACH ROW +BEGIN + + IF NEW.issued != OLD.issued + OR NEW.currencyFk != OLD.currencyFk THEN + + UPDATE invoiceInTax iit + JOIN invoiceIn ii ON ii.id = iit.invoiceInFk + LEFT JOIN referenceRate rr ON rr.dated = ii.issued + AND rr.currencyFk = ii.currencyFk + SET iit.taxableBase = IF(iit.foreignValue IS NULL, iit.taxableBase, iit.foreignValue / rr.value) + WHERE ii.id = NEW.id; + + UPDATE invoiceInDueDay iidd + JOIN invoiceIn ii ON ii.id = iidd.invoiceInFk + LEFT JOIN referenceRate rr ON rr.dated = ii.issued + AND rr.currencyFk = ii.currencyFk + SET iidd.amount = IF(iidd.foreignValue IS NULL, iidd.amount, iidd.foreignValue / rr.value) + WHERE ii.id = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceIn_afterDelete` + AFTER DELETE ON `invoiceIn` + FOR EACH ROW +BEGIN + INSERT INTO invoiceInLog + SET `action` = 'delete', + `changedModel` = 'InvoiceIn', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInDueDay_beforeInsert` + BEFORE INSERT ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + DECLARE vIsNotified BOOLEAN; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT isNotified INTO vIsNotified + FROM vn.invoiceIn ii + JOIN vn.supplier s ON s.id = ii.supplierFk + JOIN vn.payMethod pm ON pm.id = s.payMethodFk + WHERE ii.id = NEW.invoiceInFk; + + IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) + THEN + CALL mail_insert( + 'begonya@verdnatura.es', + 'begonya@verdnatura.es', + 'Añadido vencimiento en el pasado', + CONCAT( + account.myUser_getName(), ' ha añadido un vencimiento de ', + NEW.amount, '€ en una fecha pasada en la recibida ', NEW.invoiceInFk + ) + ); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInDueDay_beforeUpdate` + BEFORE UPDATE ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + DECLARE vIsNotified BOOLEAN; + + SET NEW.editorFk = account.myUser_getId(); + + SELECT isNotified INTO vIsNotified + FROM vn.invoiceIn ii + JOIN vn.supplier s ON s.id = ii.supplierFk + JOIN vn.payMethod pm ON pm.id = s.payMethodFk + WHERE ii.id = NEW.invoiceInFk; + + IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) + THEN + CALL mail_insert( + 'begonya@verdnatura.es', + 'begonya@verdnatura.es', + 'Añadido vencimiento en el pasado', + CONCAT( + account.myUser_getName(), ' ha añadido un vencimiento de ', + NEW.amount,'€ en una fecha pasada en la recibida ',NEW.invoiceInFk + ) + ); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInDueDay_afterDelete` + AFTER DELETE ON `invoiceInDueDay` + FOR EACH ROW +BEGIN + INSERT INTO invoiceInLog + SET `action` = 'delete', + `changedModel` = 'InvoiceInDueDay', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_beforeInsert` + BEFORE INSERT ON `invoiceInTax` + FOR EACH ROW +BEGIN + CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_beforeUpdate` + BEFORE UPDATE ON `invoiceInTax` + FOR EACH ROW +BEGIN + IF NOT (NEW.invoiceInFk <=> OLD.invoiceInFk) THEN + CALL invoiceInTax_afterUpsert(NEW.invoiceInFk); + END IF; + + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceInTax_afterDelete` + AFTER DELETE ON `invoiceInTax` + FOR EACH ROW +BEGIN + INSERT INTO invoiceInLog + SET `action` = 'delete', + `changedModel` = 'InvoiceInTax', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeInsert` + BEFORE INSERT ON `invoiceOut` + FOR EACH ROW +BEGIN +/** + * Generates the next reference for the invoice serial. There cannot be gaps + * between identifiers of the same serial! + * + * Reference format: + * {0} Invoice serial + * {1} The company code + * {2-3} Last two digits of issue year + * {4-$} Autoincrement identifier + */ + DECLARE vRef INT DEFAULT 0; + DECLARE vRefLen INT; + DECLARE vRefPrefix VARCHAR(255); + DECLARE vLastRef VARCHAR(255); + DECLARE vCompanyCode INT; + DECLARE vYearLen INT DEFAULT 2; + DECLARE vPrefixLen INT; + + SELECT companyCode INTO vCompanyCode + FROM company + WHERE id = NEW.companyFk; + + IF vCompanyCode IS NULL THEN + CALL util.throw('companyCodeNotDefined'); + END IF; + + SELECT MAX(i.ref) INTO vLastRef + FROM invoiceOut i + WHERE i.serial = NEW.serial + AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.lastDayOfYear(NEW.issued) + AND i.companyFk = NEW.companyFk; + + IF vLastRef IS NOT NULL THEN + SET vPrefixLen = LENGTH(NEW.serial) + LENGTH(vCompanyCode) + vYearLen; + SET vRefLen = LENGTH(vLastRef) - vPrefixLen; + SET vRefPrefix = LEFT(vLastRef, vPrefixLen); + SET vRef = RIGHT(vLastRef, vRefLen); + ELSE + SELECT refLen INTO vRefLen FROM invoiceOutConfig; + SET vRefPrefix = CONCAT( + NEW.serial, + vCompanyCode, + RIGHT(YEAR(NEW.issued), vYearLen) + ); + END IF; + + SET vRef = vRef + 1; + IF LENGTH(vRef) > vRefLen THEN + CALL util.throw('refIdLenExceeded'); + END IF; + + SET NEW.ref = CONCAT(vRefPrefix, LPAD(vRef, vRefLen, '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 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_afterInsert` + AFTER INSERT ON `invoiceOut` + FOR EACH ROW +BEGIN + CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeUpdate` + BEFORE UPDATE ON `invoiceOut` + FOR EACH ROW +BEGIN +CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount); +CALL clientRisk_update (NEW.clientFk, NEW.companyFk, NEW.amount); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`invoiceOut_beforeDelete` + BEFORE DELETE ON `invoiceOut` + FOR EACH ROW +BEGIN + CALL clientRisk_update (OLD.clientFk, OLD.companyFk, -OLD.amount); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_beforeInsert` + BEFORE INSERT ON `item` + FOR EACH ROW +BEGIN + DECLARE vItemPackingType VARCHAR(1); + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.itemPackingTypeFk IS NULL THEN + SELECT itemPackingTypeFk INTO vItemPackingType + FROM vn.itemType it + WHERE id = NEW.typeFk; + + SET NEW.itemPackingTypeFk = vItemPackingType; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterInsert` + AFTER INSERT ON `item` + FOR EACH ROW +BEGIN + CALL hedera.image_ref('catalog', NEW.image); + + INSERT INTO vn.itemTaxCountry(itemFk, countryFk) VALUES + (NEW.id, 1), + (NEW.id, 5); + + DELETE ifr.* + FROM edi.item_free ifr + WHERE ifr.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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_beforeUpdate` + BEFORE UPDATE ON `item` + FOR EACH ROW +BEGIN + DECLARE vNewPackingShelve INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF ISNULL(NEW.packingShelve) AND NOT ISNULL(NEW.packingOut) THEN + SELECT NEW.packingOut * vc.shelveVolume / vc.standardFlowerBox + INTO vNewPackingShelve + FROM vn.volumeConfig vc; + + SET NEW.packingShelve = vNewPackingShelve; + END IF; + + IF NEW.itemPackingTypeFk = '' THEN + SET NEW.itemPackingTypeFk = 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterUpdate` + AFTER UPDATE ON `item` + FOR EACH ROW +BEGIN + IF !(NEW.image <=> OLD.image) THEN + CALL hedera.image_unref('catalog', OLD.image); + CALL hedera.image_ref('catalog', NEW.image); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterDelete` + AFTER DELETE ON `item` + FOR EACH ROW +BEGIN + CALL hedera.image_unref('catalog', OLD.image); + + IF OLD.isFloramondo THEN + INSERT IGNORE edi.item_free + SET id = OLD.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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBarcode_beforeInsert` + BEFORE INSERT ON `itemBarcode` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBarcode_beforeUpdate` + BEFORE UPDATE ON `itemBarcode` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBarcode_afterDelete` + AFTER DELETE ON `itemBarcode` + FOR EACH ROW +BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemBarcode', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBotanical_beforeInsert` + BEFORE INSERT ON `itemBotanical` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBotanical_beforeUpdate` + BEFORE UPDATE ON `itemBotanical` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemBotanical_afterDelete` + AFTER DELETE ON `itemBotanical` + FOR EACH ROW +BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemBotanical', + `changedModelId` = OLD.itemFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemCategory_AFTER_INSERT` + AFTER INSERT ON `itemCategory` + FOR EACH ROW +BEGIN + CALL mail_insert('cau@verdnatura.es', + NULL, + CONCAT('Se ha añadido la familia: ', NEW.name), + 'Hay que añadir la familia en el formulario gastos'); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemCost_beforeInsert` + BEFORE INSERT ON `itemCost` + FOR EACH ROW +BEGIN + IF NEW.itemFk IN (95, 98) THEN + SET NEW.cm3 = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemCost_beforeUpdate` + BEFORE UPDATE ON `itemCost` + FOR EACH ROW +BEGIN + IF NEW.itemFk IN (95, 98) THEN + SET NEW.cm3 = 0; + END IF; + + IF !(NEW.cm3delivery <=> OLD.cm3delivery) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.itemCost ic + JOIN vn.sale s ON s.itemFk = ic.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk AND t.warehouseFk = ic.warehouseFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND ic.itemFk = NEW.itemFk + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + IF NEW.cm3Delivery = 0 AND NEW.warehouseFk = 60 THEN + CALL mail_insert( + 'jgallego@verdnatura.es', + NULL, + 'update cm3Delivery', + CONCAT('articulo: ', NEW.itemFk)); + 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_INSERT` + BEFORE INSERT ON `itemShelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.userFk = account.myUser_getId(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_AFTER_INSERT` + AFTER INSERT ON `itemShelving` + FOR EACH ROW +INSERT INTO vn.itemShelvingLog( itemShelvingFk, + workerFk, + accion, + itemFk, + shelvingFk, + visible, + `grouping`, + packing) + VALUES( NEW.id, + NEW.userFk, + 'CREA REGISTRO', + NEW.itemFk, + NEW.shelvingFk, + NEW.visible, + NEW.`grouping`, + NEW.packing + ) */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_UPDATE` + BEFORE UPDATE ON `itemShelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + IF NEW.userFk IS NULL THEN + SET NEW.userFk = account.myUser_getId(); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_AFTER_UPDATE` + AFTER UPDATE ON `itemShelving` + FOR EACH ROW + + INSERT INTO itemShelvingLog + SET itemShelvingFk = NEW.id, + workerFk = account.myUser_getId(), + accion = 'CAMBIO', + itemFk = NEW.itemFk, + shelvingFk = NEW.shelvingFk, + visible = NEW.visible, + `grouping` = NEW.`grouping`, + packing = NEW.packing */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving_BEFORE_DELETE` + BEFORE DELETE ON `itemShelving` + FOR EACH ROW +INSERT INTO vn.itemShelvingLog(itemShelvingFk, + workerFk, + accion, + shelvingFk, + itemFk) + VALUES( OLD.id, + account.myUser_getId(), + 'ELIMINADO', + OLD.shelvingFk, + OLD.itemFk) */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelving _afterDelete` + AFTER DELETE ON `itemShelving` + FOR EACH ROW +BEGIN + INSERT INTO shelvingLog + SET `action` = 'delete', + `changedModel` = 'itemShelving', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemShelvingSale_AFTER_INSERT` + AFTER INSERT ON `itemShelvingSale` + FOR EACH ROW +BEGIN + + UPDATE vn.sale + SET isPicked = TRUE + WHERE id = NEW.saleFk; + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_beforeInsert` + BEFORE INSERT ON `itemTag` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.intValue = itemTag_getIntValue(NEW.`value`); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_afterInsert` + AFTER INSERT ON `itemTag` + FOR EACH ROW +trig: BEGIN + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL item_refreshFromTags(NEW.itemFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_beforeUpdate` + BEFORE UPDATE ON `itemTag` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF !(OLD.`value` <=> NEW.`value`) + OR !(OLD.intValue <=> NEW.intValue) THEN + SET NEW.intValue = itemTag_getIntValue(NEW.`value`); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_afterUpdate` + AFTER UPDATE ON `itemTag` + FOR EACH ROW +trig: BEGIN + DECLARE vItemFk INT; + DECLARE visTriggerDisabled BOOL; + + SELECT isItemTagTriggerDisabled INTO visTriggerDisabled + FROM vn.itemConfig; + + IF @isTriggerDisabled OR visTriggerDisabled THEN + LEAVE trig; + END IF; + + SET vItemFk = NEW.itemFk; + DROP TEMPORARY TABLE IF EXISTS tmp.item; + CREATE TEMPORARY TABLE tmp.item + SELECT vItemFk id; + + CALL item_refreshTags(); + DROP TEMPORARY TABLE tmp.item; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTag_afterDelete` + AFTER DELETE ON `itemTag` + FOR EACH ROW +trig: BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemTag', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL item_refreshFromTags(OLD.itemFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTaxCountry_beforeInsert` + BEFORE INSERT ON `itemTaxCountry` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTaxCountry_beforeUpdate` + BEFORE UPDATE ON `itemTaxCountry` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemTaxCountry_afterDelete` + AFTER DELETE ON `itemTaxCountry` + FOR EACH ROW +BEGIN + INSERT INTO itemLog + SET `action` = 'delete', + `changedModel` = 'ItemTaxCountry', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemType_beforeUpdate` + BEFORE UPDATE ON `itemType` + FOR EACH ROW +BEGIN + IF NEW.itemPackingTypeFk = '' THEN + + SET NEW.itemPackingTypeFk = NULL; + + END IF; + + IF NEW.itemPackingTypeFk != OLD.itemPackingTypeFk THEN + UPDATE vn.item + SET itemPackingTypeFk = NEW.itemPackingTypeFk + WHERE typeFk = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`machine_BI` + BEFORE INSERT ON `machine` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`mail_beforeInsert` + BEFORE INSERT ON `mail` + FOR EACH ROW +BEGIN + + IF NEW.sender IS NOT NULL THEN + + SET NEW.receiver = NEW.sender; + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`mandate_beforeInsert` + BEFORE INSERT ON `mandate` + FOR EACH ROW +BEGIN + IF (NEW.code IS NULL) THEN + SET NEW.code=CONCAT(NEW.clientFk,'-',(SELECT AUTO_INCREMENT + FROM information_schema.TABLES + WHERE TABLE_SCHEMA='vn' and TABLE_NAME='mandate')); + 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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`operator_beforeInsert` + BEFORE INSERT ON `operator` + FOR EACH ROW +BEGIN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`operator_beforeUpdate` + BEFORE UPDATE ON `operator` + FOR EACH ROW +BEGIN + IF NOT (NEW.labelerFk <=> OLD.labelerFk AND NEW.sectorFk <=> OLD.sectorFk) THEN + CALL vn.printer_checkSector(NEW.labelerFk, NEW.sectorFk); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packaging_beforeInsert` + BEFORE INSERT ON `packaging` + FOR EACH ROW +BEGIN + SET NEW.value = packaging_calculate(NEW.isPackageReturnable, NEW.packagingReturnFk, NEW.base, NEW.price, NEW.upload); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packaging_beforeUpdate` + BEFORE UPDATE ON `packaging` + FOR EACH ROW +BEGIN + SET NEW.value = packaging_calculate(NEW.isPackageReturnable, NEW.packagingReturnFk, NEW.base, NEW.price, NEW.upload); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packingSite_beforeInsert` + BEFORE INSERT ON `packingSite` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packingSite_beforeUpdate` + BEFORE UPDATE ON `packingSite` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`packingSite_afterDelete` + AFTER DELETE ON `packingSite` + FOR EACH ROW +BEGIN + INSERT INTO packingSiteDeviceLog + SET `action` = 'delete', + `changedModel` = 'PackingSite', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`parking_BEFORE_INSERT` + BEFORE INSERT ON `parking` + FOR EACH ROW +BEGIN + + -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`parking_BEFORE_UPDATE` + BEFORE UPDATE ON `parking` + FOR EACH ROW +BEGIN + + -- SET new.`code` = CONCAT(new.`column`,' - ',new.`row`) ; + +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`@`localhost`*/ /*!50003 TRIGGER `payment_beforeInsert` BEFORE INSERT ON `payment` FOR EACH ROW +BEGIN + DECLARE cuenta_banco,cuenta_proveedor DOUBLE; + DECLARE vNewBookEntry INT; + DECLARE bolCASH BOOLEAN; + DECLARE isSupplierActive BOOLEAN; + + -- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH + SELECT (at2.code = 'cash') INTO bolCASH + FROM vn.bank b + JOIN vn.accountingType at2 ON at2.id = b.cash + WHERE b.id = NEW.bankFk; + + IF bolCASH THEN + + SELECT account INTO cuenta_banco + FROM bank + WHERE id = NEW.bankFk; + + SELECT account INTO cuenta_proveedor + FROM supplier + WHERE id = NEW.supplierFk; + + CALL vn.ledger_next(vNewBookEntry); + + INSERT INTO XDiario ( ASIEN, + FECHA, + SUBCTA, + CONTRA, + CONCEPTO, + EURODEBE, + EUROHABER, + empresa_id) + SELECT vNewBookEntry, + NEW.received, + SUBCTA, + CONTRA, + NEW.concept, + EURODEBE, + EUROHABER, + NEW.companyFk + FROM ( SELECT cuenta_banco SUBCTA, + cuenta_proveedor CONTRA, + 0 EURODEBE, + NEW.amount + NEW.bankingFees EUROHABER + UNION ALL + SELECT cuenta_proveedor SUBCTA, + cuenta_banco CONTRA, + NEW.amount EURODEBE, + 0 EUROHABER) gf; + + IF NEW.bankingFees <> 0 THEN + INSERT INTO XDiario ( ASIEN, + FECHA, + SUBCTA, + CONTRA, + CONCEPTO, + EURODEBE, + EUROHABER, + empresa_id) + SELECT vNewBookEntry, + NEW.received, + IF(c.id = 1,6260000002, + IF(CEE = 1,6260000003,6260000004)), + cuenta_banco, + NEW.concept, + NEW.bankingFees, + 0, + NEW.companyFk + FROM supplier s + JOIN country c ON s.countryFk = c.id + WHERE s.id = NEW.supplierFk; + END IF; + END IF; + + SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received); + + SELECT isActive INTO isSupplierActive + FROM supplier + WHERE id = NEW.supplierFk; + + IF isSupplierActive = FALSE THEN + CALL util.throw('SUPPLIER_INACTIVE'); + END IF; + + IF ISNULL(NEW.workerFk) THEN + SET NEW.workerFk = account.myUser_getId(); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`payment_afterInsert` + AFTER INSERT ON `payment` + FOR EACH ROW +BEGIN + DECLARE vIsPayMethodChecked BOOLEAN; + DECLARE vEmail VARCHAR(150); + + SELECT isPayMethodChecked INTO vIsPayMethodChecked + FROM supplier + WHERE id = NEW.supplierFk; + + + IF vIsPayMethodChecked = FALSE THEN + + SELECT notificationEmail INTO vEmail + FROM department + WHERE name = 'FINANZAS'; + + CALL mail_insert( + vEmail, + NULL, + 'Pago con método sin verificar', + CONCAT( + 'Se ha realizado el pago ', + NEW.id, + ' al proveedor ', + NEW.supplierFk, + ' con el método de pago sin verificar.' + ) + ); + 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`@`localhost`*/ /*!50003 TRIGGER payment_beforeUpdate BEFORE UPDATE ON payment FOR EACH ROW +BEGIN + IF ISNULL(NEW.workerFk) THEN + SET NEW.workerFk = account.myUser_getId(); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_beforeInsert` + BEFORE INSERT ON `postCode` + FOR EACH ROW +BEGIN + SET NEW.geoFk = zoneGeo_new('postCode', NEW.`code`, + (SELECT geoFk FROM town WHERE id = NEW.townFk)); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_beforeUpdate` + BEFORE UPDATE ON `postCode` + FOR EACH ROW +BEGIN + -- IF !(OLD.geoFk <=> NEW.geoFk) THEN + -- CALL zoneGeo_throwNotEditable; + -- 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_afterUpdate` + AFTER UPDATE ON `postCode` + FOR EACH ROW +BEGIN + IF !(OLD.townFk <=> NEW.townFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM town WHERE id = NEW.townFk)); + END IF; + + IF !(OLD.`code` <=> NEW.`code`) THEN + UPDATE zoneGeo SET `name` = NEW.`code` + WHERE id = NEW.geoFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`postCode_afterDelete` + AFTER DELETE ON `postCode` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`priceFixed_beforeInsert` + BEFORE INSERT ON `priceFixed` + FOR EACH ROW +BEGIN + DECLARE vDated DATE; + IF NEW.started > NEW.ended THEN + SET vDated = NEW.started; + SET NEW.started = NEW.ended; + SET NEW.ended = vDated; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`priceFixed_beforeUpdate` + BEFORE UPDATE ON `priceFixed` + FOR EACH ROW +BEGIN + DECLARE vDated DATE; + IF NEW.started > NEW.ended THEN + SET vDated = NEW.started; + SET NEW.started = NEW.ended; + SET NEW.ended = vDated; + 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 = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER projectNotes_BeforeInsert +BEFORE INSERT +ON projectNotes FOR EACH ROW +BEGIN + + IF ISNULL(NEW.userFk) THEN + + SET NEW.userFk = account.myUser_getId(); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_beforeInsert` + BEFORE INSERT ON `province` + FOR EACH ROW +BEGIN + + SET NEW.geoFk = zoneGeo_new('province', NEW.`name`, + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_beforeUpdate` + BEFORE UPDATE ON `province` + FOR EACH ROW +BEGIN + + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate` + AFTER UPDATE ON `province` + FOR EACH ROW +BEGIN + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterDelete` + AFTER DELETE ON `province` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`rate_beforeInsert` + BEFORE INSERT ON `rate` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`rate_beforeUpdate` + BEFORE UPDATE ON `rate` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`rate_afterDelete` + AFTER DELETE ON `rate` + FOR EACH ROW +BEGIN + INSERT INTO rateLog + SET `action` = 'delete', + `changedModel` = 'Rate', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert` + BEFORE INSERT ON `receipt` + FOR EACH ROW +BEGIN + DECLARE vIsAutoConciliated BOOLEAN; + + IF NEW.isConciliate = FALSE THEN + SELECT isAutoConciliated INTO vIsAutoConciliated + FROM accounting a + JOIN accountingType at2 ON at2.id = a.accountingTypeFk + WHERE a.id = NEW.bankFk; + + SET NEW.isConciliate = vIsAutoConciliated; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterInsert` + AFTER INSERT ON `receipt` + FOR EACH ROW +CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid) */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeUpdate` + BEFORE UPDATE ON `receipt` + FOR EACH ROW +BEGIN + CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid); + CALL clientRisk_update(NEW.clientFk, NEW.companyFk, -NEW.amountPaid); + SET NEW.workerFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` + AFTER UPDATE ON `receipt` + FOR EACH ROW +BEGIN + IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN + CALL mail_insert( + 'finanzas@verdnatura.es', + NULL, + CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), + CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) + ); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeDelete` + BEFORE DELETE ON `receipt` + FOR EACH ROW +CALL clientRisk_update(OLD.clientFk, OLD.companyFk, OLD.amountPaid) */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`recovery_beforeInsert` + BEFORE INSERT ON `recovery` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`recovery_beforeUpdate` + BEFORE UPDATE ON `recovery` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`recovery_afterDelete` + AFTER DELETE ON `recovery` + FOR EACH ROW +BEGIN + INSERT INTO clientLog + SET `action` = 'delete', + `changedModel` = 'Recovery', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_beforeInsert` + BEFORE INSERT ON `route` + FOR EACH ROW +BEGIN + DECLARE vDefaultAgencyModeFk INT; + DECLARE vUserFk INT ; + + SET vUserFk = account.myUser_getId(); + SET NEW.editorFk = vUserFk; + SET NEW.firstEditorFk = vUserFk; + + SET NEW.commissionWorkCenterFk = ( + SELECT IFNULL(b.workCenterFK, r.defaultWorkCenterFk) + FROM vn.routeConfig r + LEFT JOIN vn.business b ON b.workerFk = vUserFk + AND NEW.created BETWEEN b.started AND IFNULL(b.ended, NEW.created)); + + IF ISNULL(NEW.agencyModeFk) THEN + SELECT r.agencyModeFk INTO vDefaultAgencyModeFk + FROM routeDefaultAgencyMode r + JOIN business b ON b.workCenterFk = r.workCenterFK + JOIN worker w ON w.businessFk = b.id + WHERE b.workerFk = vUserFk; + + SET NEW.agencyModeFk = vDefaultAgencyModeFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterInsert` + AFTER INSERT ON `route` + FOR EACH ROW +BEGIN + CALL route_calcCommission(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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_beforeUpdate` + BEFORE UPDATE ON `route` + FOR EACH ROW +BEGIN + DECLARE vKmMax INT; + + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.isOk <> FALSE AND OLD.isOk = FALSE THEN + SET NEW.m3 = ( SELECT SUM(litros)/1000 + FROM vn.saleVolume s + JOIN vn.ticket t ON s.ticketFk = t.id + WHERE t.routeFk = NEW.id); + END IF; + + IF NEW.kmEnd < NEW.kmStart AND NEW.kmEnd <> 0 THEN + CALL util.throw ('KmEnd menor que kmStart'); + END IF; + + SELECT kmMax INTO vKmMax + FROM routeConfig rc; + + IF ((NEW.kmEnd - NEW.kmStart) > vKmMax) AND NEW.kmEnd <> 0 THEN + CALL util.throw (CONCAT('The km can not exceed ', vKmMax)); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterUpdate` + AFTER UPDATE ON `route` + FOR EACH ROW +BEGIN + IF IFNULL(NEW.gestdocFk,0) <> IFNULL(OLD.gestdocFk,0) AND NEW.gestdocFk > 0 THEN + -- JGF 09/09/14 cuando se añade un gestdoc a una ruta, se le asigna automagicamente a todos sus Tickets + + -- Inserta el gestdoc en todos los tickets de la ruta + INSERT INTO ticketDms(ticketFk,dmsFk) + SELECT id, NEW.gestdocFk FROM ticket WHERE routeFk = NEW.id + ON DUPLICATE KEY UPDATE dmsFk = NEW.gestdocFk; + + -- Update del firmado + UPDATE ticket t + JOIN ticketDms tg ON t.id = tg.ticketFk + SET isSigned = 1 WHERE t.routeFk = NEW.id; + END IF; + + IF !(NEW.kmStart <=> OLD.kmStart) + OR !(NEW.kmEnd <=> OLD.kmEnd) + OR !(NEW.workerFk <=> OLD.workerFk) + OR !(NEW.m3 <=> OLD.m3) + OR !(NEW.agencyModeFk <=> OLD.agencyModeFk)THEN + CALL route_calcCommission(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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`route_afterDelete` + AFTER DELETE ON `route` + FOR EACH ROW +BEGIN + INSERT INTO routeLog + SET `action` = 'delete', + `changedModel` = 'Route', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routesMonitor_beforeInsert` + BEFORE INSERT ON `routesMonitor` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routesMonitor_beforeUpdate` + BEFORE UPDATE ON `routesMonitor` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routesMonitor_afterDelete` + AFTER DELETE ON `routesMonitor` + FOR EACH ROW +BEGIN + INSERT INTO routeLog + SET `action` = 'delete', + `changedModel` = 'RoutesMonitor', + `changedModelId` = OLD.routeFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_beforeInsert` + BEFORE INSERT ON `sale` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.originalQuantity = NEW.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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_afterInsert` + AFTER INSERT ON `sale` + FOR EACH ROW +BEGIN + IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN + CALL util.throw('Cannot insert a service item into a ticket'); + END IF; + + CALL stock.log_add('sale', NEW.id, NULL); + CALL ticket_requestRecalc(NEW.ticketFk); + + IF NEW.quantity > 0 THEN + + UPDATE vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id + AND tc.ticketFk = NEW.ticketFk + JOIN vn.item i ON i.id = NEW.itemFk + AND (c.itemPackingTypeFk = i.itemPackingTypeFk + OR c.itemPackingTypeFk IS NULL) + SET c.saleTotalCount = c.saleTotalCount + 1; + + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = NEW.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_beforeUpdate` + BEFORE UPDATE ON `sale` + FOR EACH ROW +BEGIN +/* + IF (SELECT COUNT(*) from item i WHERE id = NEW.itemFk AND family = 'SER') THEN + CALL util.throw('Cannot insert a service item into a ticket'); + END IF; +*/ + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.discount > 100 THEN + SET NEW.discount = 0; + END IF; + + IF old.discount > 0 AND NEW.discount = 0 THEN + INSERT INTO ticketLog + SET originFk = NEW.ticketFk, userFk = account.myUser_getId(), `action` = 'insert', + description = CONCAT('Cambio de descuento del item :', ' ', new.itemFk, ' de ', old.discount ,' a 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_afterUpdate` + AFTER UPDATE ON `sale` + FOR EACH ROW +BEGIN + DECLARE vIsToSendMail BOOL; + DECLARE vUserRole VARCHAR(255); + + IF !(NEW.id <=> OLD.id) + OR !(NEW.ticketFk <=> OLD.ticketFk) + OR !(NEW.itemFk <=> OLD.itemFk) + OR !(NEW.quantity <=> OLD.quantity) + OR !(NEW.created <=> OLD.created) + OR !(NEW.isPicked <=> OLD.isPicked) THEN + CALL stock.log_add('sale', NEW.id, OLD.id); + END IF; + + IF !(NEW.price <=> OLD.price) + OR !(NEW.ticketFk <=> OLD.ticketFk) + OR !(NEW.itemFk <=> OLD.itemFk) + OR !(NEW.quantity <=> OLD.quantity) + OR !(NEW.discount <=> OLD.discount) THEN + CALL ticket_requestRecalc(NEW.ticketFk); + CALL ticket_requestRecalc(OLD.ticketFk); + END IF; + + IF !(OLD.ticketFk <=> NEW.ticketFk) THEN + UPDATE ticketRequest SET ticketFk = NEW.ticketFk + WHERE saleFk = NEW.id; + END IF; + + SELECT account.myUser_getName() INTO vUserRole; + SELECT account.user_getMysqlRole(vUserRole) INTO vUserRole; + + IF !(OLD.quantity <=> NEW.quantity) THEN + SELECT COUNT(*) INTO vIsToSendMail + FROM ticketTracking tt + JOIN vn.state s ON s.id = tt.stateFk + WHERE s.code='PACKED' + AND tt.ticketFk = OLD.ticketFk + AND vUserRole IN ('salesPerson', 'salesTeamBoss') + LIMIT 1; + + IF vIsToSendMail THEN + CALL vn.mail_insert('jefesventas@verdnatura.es', + 'noreply@verdnatura.es', + CONCAT('Ticket ', OLD.ticketFk ,' modificada cantidad tras encajado'), + CONCAT('Ticket ', OLD.ticketFk ,'.
', + 'Modificada la catidad de ', OLD.quantity, ' a ' , NEW.quantity, + ' del artículo ', OLD.itemFk, ' tras estado encajado del ticket.
', + 'Este email se ha generado automáticamente' ) + ); + END IF; + IF (OLD.quantity > NEW.quantity) THEN + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT NEW.id, cm.id, sc.value + FROM saleComponent sc + JOIN component cd ON cd.id = sc.componentFk + JOIN component cm ON cm.code = 'mana' + WHERE saleFk = NEW.id AND cd.code = 'lastUnitsDiscount' + ON DUPLICATE KEY UPDATE value = sc.value + VALUES(value); + + DELETE sc.* + FROM vn.saleComponent sc + JOIN component c ON c.id = sc.componentFk + WHERE saleFk = NEW.id AND c.code = 'lastUnitsDiscount'; + END IF; + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = NEW.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + END IF; + + IF !(ABS(NEW.isPicked) <=> ABS(OLD.isPicked)) AND NEW.quantity > 0 THEN + UPDATE vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk + SET c.salePickedCount = c.salePickedCount + IF(NEW.isPicked != 0, 1, -1); + END IF; + + IF !(NEW.quantity <=> OLD.quantity) AND (NEW.quantity = 0 OR OLD.quantity = 0) THEN + UPDATE vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = NEW.ticketFk + SET c.saleTotalCount = c.saleTotalCount + IF(OLD.quantity = 0, 1, -1); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_BEFORE_DELETE` + BEFORE DELETE ON `sale` + FOR EACH ROW +BEGIN + IF OLD.quantity > 0 THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = OLD.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sale_afterDelete` + AFTER DELETE ON `sale` + FOR EACH ROW +BEGIN + DECLARE vIsToSendMail BOOL; + DECLARE vUserRole VARCHAR(255); + + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'Sale', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL stock.log_add('sale', NULL, OLD.id); + CALL ticket_requestRecalc(OLD.ticketFk); + + SELECT account.myUser_getName() INTO vUserRole; + SELECT account.user_getMysqlRole(vUserRole) INTO vUserRole; + + SELECT COUNT(*) INTO vIsToSendMail + FROM ticketTracking tt + JOIN vn.state s ON s.id = tt.stateFk + WHERE s.code='PACKED' + AND tt.ticketFk = OLD.ticketFk + AND vUserRole IN ('salesPerson', 'salesBoss') + LIMIT 1; + + IF vIsToSendMail THEN + CALL vn.mail_insert('jefesventas@verdnatura.es', + 'noreply@verdnatura.es', + CONCAT('Ticket ', OLD.ticketFk ,' eliminado artículo tras encajado' ), + CONCAT('Ticket ', OLD.ticketFk ,'.
', + 'Eliminado artículo ', OLD.itemFk, ' tras estado encajado del ticket.
Este email se ha generado automáticamente' ) + ); + END IF; + + IF OLD.quantity > 0 THEN + UPDATE vn.collection c + JOIN vn.ticketCollection tc ON tc.collectionFk = c.id AND tc.ticketFk = OLD.ticketFk + JOIN vn.item i ON i.id = OLD.itemFk + AND (c.itemPackingTypeFk = i.itemPackingTypeFk + OR ISNULL(c.itemPackingTypeFk)) + SET c.saleTotalCount = c.saleTotalCount - 1, + c.salePickedCount = c.salePickedCount - ABS(OLD.isPicked); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`BEFORE_INSERT` + BEFORE INSERT ON `saleBuy` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleBuy_AI` + AFTER INSERT ON `saleBuy` + FOR EACH ROW +BEGIN +/* Activar de nuevo cuando volvamos a vender fruta y verdura + * + UPDATE vn.sale s + SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk) + WHERE s.id = NEW.saleFk; +*/ +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleGroup_beforeInsert` + BEFORE INSERT ON `saleGroup` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleGroup_beforeUpdate` + BEFORE UPDATE ON `saleGroup` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleGroup_afterDelete` + AFTER DELETE ON `saleGroup` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'SaleGroup', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`saleTracking_After_Insert` + AFTER INSERT ON `saleTracking` + FOR EACH ROW +BEGIN + + IF NEW.isChecked THEN + + UPDATE vn.sale s + SET s.isPicked = TRUE + WHERE s.id = NEW.saleFk + AND s.isPicked = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingCart_beforeInsert` + BEFORE INSERT ON `sharingCart` + FOR EACH ROW +BEGIN + IF NEW.workerFk = NEW.workerSubstitute THEN + CALL util.throw ('worker and workerSubstitute must be different'); + ELSE + INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) + SELECT NEW.workerFk, NEW.workerSubstitute, dated + FROM time + WHERE dated BETWEEN NEW.started AND NEW.ended; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingCart_beforeUpdate` + BEFORE UPDATE ON `sharingCart` + FOR EACH ROW +BEGIN + IF NEW.workerFk = NEW.workerSubstitute THEN + CALL util.throw ('worker and workerSubstitute must be different'); + ELSE + DELETE sc FROM sharingCartDaily sc + WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND + sc.ownerFk = OLD.workerFk AND + sc.substituteFk = OLD.workerSubstitute; + + INSERT IGNORE INTO sharingCartDaily (ownerFk, substituteFk, dated) + SELECT NEW.workerFk, NEW.workerSubstitute, dated + FROM time + WHERE dated BETWEEN NEW.started AND NEW.ended; + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingCart_beforeDelete` + BEFORE DELETE ON `sharingCart` + FOR EACH ROW +BEGIN + DELETE sc FROM sharingCartDaily sc + WHERE sc.dated BETWEEN OLD.started AND OLD.ended AND + sc.ownerFk = OLD.workerFk AND + sc.substituteFk = OLD.workerSubstitute; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingClient_beforeInsert` + BEFORE INSERT ON `sharingClient` + FOR EACH ROW +BEGIN + SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); + SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`sharingClient_beforeUpdate` + BEFORE UPDATE ON `sharingClient` + FOR EACH ROW +BEGIN + SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); + SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`shelving_beforeInsert` + BEFORE INSERT ON `shelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.code = "" THEN + CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`shelving_BEFORE_UPDATE` + BEFORE UPDATE ON `shelving` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.code = "" THEN + CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); + END IF; + + IF NOT(OLD.parkingFk <=> NEW.parkingFK) THEN + SET NEW.isMoving = FALSE; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`shelving_afterDelete` + AFTER DELETE ON `shelving` + FOR EACH ROW +BEGIN + INSERT INTO shelvingLog + SET `action` = 'delete', + `changedModel` = 'Shelving', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`solunionCAP_AFTER_INSERT` + AFTER INSERT ON `solunionCAP` + FOR EACH ROW +BEGIN + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`solunionCAP_AFTER_UPDATE` + AFTER UPDATE ON `solunionCAP` + FOR EACH ROW +BEGIN + IF NEW.dateLeaving IS NOT NULL THEN + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; + ELSE + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`solunionCAP_BEFORE_DELETE` + BEFORE DELETE ON `solunionCAP` + FOR EACH ROW +BEGIN + UPDATE vn2008.Clientes c + JOIN creditClassification cc ON c.Id_Cliente = cc.client + JOIN creditInsurance ci ON ci.creditClassification = cc.id + SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`specie_BEFORE_INSERT` + BEFORE INSERT ON `specie` + FOR EACH ROW +BEGIN + SET NEW.name = LCASE(NEW.name); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`specie_BEFORE_UPDATE` + BEFORE UPDATE ON `specie` + FOR EACH ROW +BEGIN + SET NEW.name = LCASE(NEW.name); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_beforeInsert` + BEFORE INSERT ON `supplier` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_beforeUpdate` + BEFORE UPDATE ON `supplier` + FOR EACH ROW +BEGIN + DECLARE vHasChange BOOL; + DECLARE vPayMethodChanged BOOL; + DECLARE vPayMethodHasVerified BOOL; + DECLARE vParams JSON; + DECLARE vOldPayMethodName VARCHAR(20); + DECLARE vNewPayMethodName VARCHAR(20); + + SET NEW.editorFk = account.myUser_getId(); + + SELECT hasVerified INTO vPayMethodHasVerified + FROM payMethod + WHERE id = NEW.payMethodFk; + + SET vPayMethodChanged = NOT(NEW.payMethodFk <=> OLD.payMethodFk); + + IF vPayMethodChanged THEN + SELECT name INTO vOldPayMethodName + FROM payMethod + WHERE id = OLD.payMethodFk; + SELECT name INTO vNewPayMethodName + FROM payMethod + WHERE id = NEW.payMethodFk; + + SET vParams = JSON_OBJECT( + 'name', NEW.name, + 'oldPayMethod', vOldPayMethodName, + 'newPayMethod', vNewPayMethodName + ); + SELECT util.notification_send('supplier-pay-method-update', vParams, NULL) INTO @id; + END IF; + + SET vHasChange = NOT(NEW.payDemFk <=> OLD.payDemFk AND NEW.payDay <=> OLD.payDay) OR vPayMethodChanged; + + IF vHasChange AND vPayMethodHasVerified THEN + SET NEW.isPayMethodChecked = FALSE; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplier_afterDelete` + AFTER DELETE ON `supplier` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'Supplier', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAccount_beforeInsert` + BEFORE INSERT ON `supplierAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAccount_beforeUpdate` + BEFORE UPDATE ON `supplierAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAccount_afterDelete` + AFTER DELETE ON `supplierAccount` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'SupplierAccount', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAddress_beforeInsert` + BEFORE INSERT ON `supplierAddress` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAddress_beforeUpdate` + BEFORE UPDATE ON `supplierAddress` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierAddress_afterDelete` + AFTER DELETE ON `supplierAddress` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'SupplierAddress', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierContact_beforeInsert` + BEFORE INSERT ON `supplierContact` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierContact_beforeUpdate` + BEFORE UPDATE ON `supplierContact` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`supplierContact_afterDelete` + AFTER DELETE ON `supplierContact` + FOR EACH ROW +BEGIN + INSERT INTO supplierLog + SET `action` = 'delete', + `changedModel` = 'SupplierContact', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`tag_BEFORE_INSERT` + BEFORE INSERT ON `tag` + FOR EACH ROW +BEGIN + IF NEW.ediTypeFk IS NULL AND (SELECT COUNT(*) FROM tag WHERE `name` = NEW.`name`) THEN + CALL util.throw('name duplicated'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeInsert` + BEFORE INSERT ON `ticket` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_afterInsert` + AFTER INSERT ON `ticket` + FOR EACH ROW +BEGIN + + DECLARE vClientType VARCHAR(255); + DECLARE vStateCode VARCHAR(255); + DECLARE vTransferorFirstShipped DATE; + + -- Borrar cuando se cambie el insert ticket en la APP móvil + + SELECT typeFk INTO vClientType + FROM vn.`client` WHERE id = NEW.clientFk; + + IF vClientType = 'loses' THEN + SET vStateCode = 'DELIVERED'; + ELSE + SET vStateCode = 'FREE'; + END IF; + + CALL ticket_setState(NEW.id, vStateCode); + + IF YEAR(NEW.shipped) > 2000 THEN + + SELECT cnb.firstShipped INTO vTransferorFirstShipped + FROM bs.clientNewBorn cnb + JOIN `client` c ON c.transferorFk = cnb.clientFk + WHERE c.id = NEW.clientFk; + + INSERT INTO bs.clientNewBorn(clientFk, firstShipped, lastShipped) + VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, util.VN_CURDATE()), util.VN_CURDATE()) + ON DUPLICATE KEY UPDATE lastShipped = util.VN_CURDATE(); + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeUpdate` + BEFORE UPDATE ON `ticket` + FOR EACH ROW +BEGIN + DECLARE vNewTime TIME; + DECLARE vHasTicketRefund BOOL; + + SET NEW.editorFk = account.myUser_getId(); + + IF NOT (NEW.routeFk <=> OLD.routeFk) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.route r + WHERE r.isOk = FALSE + AND r.id IN (OLD.routeFk,NEW.routeFk) + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + END IF; + + IF NOT (DATE(NEW.shipped) <=> DATE(OLD.shipped)) THEN + IF YEAR(NEW.shipped) < 2000 THEN + SIGNAL SQLSTATE '46000' + SET MESSAGE_TEXT = 'Year cannot be lesser than 2000'; + END IF; + + IF YEAR(NEW.shipped) = 2000 THEN + SET NEW.isDeleted = TRUE; + END IF; + + END IF; + + IF NOT (NEW.isDeleted <=> OLD.isDeleted) AND NEW.isDeleted THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND t.id = NEW.id + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + SET NEW.shipped = DATE_FORMAT(NEW.shipped, '2000-%m-%d %T'); + SET NEW.landed = DATE_FORMAT(NEW.landed, '2000-%m-%d %T'); + SET NEW.routeFk = NULL; + SET NEW.zoneFk = NULL; + END IF; + + IF NEW.routeFk AND NEW.isDeleted THEN + CALL util.throw ('This ticket is deleted'); + END IF; + + IF NOT (NEW.routeFk <=> OLD.routeFk) AND NEW.routeFk IS NOT NULL THEN + SELECT MAX(TIME(shipped)) INTO vNewTime + FROM vn.ticket + WHERE routeFk = NEW.routeFk + HAVING MAX(TIME(shipped)) > TIME(NEW.shipped); + + IF vNewTime THEN + SET NEW.shipped = TIMESTAMP(DATE(NEW.shipped), vNewTime); + END IF; + INSERT IGNORE INTO zoneAgencyMode (agencyModeFk,zoneFk) + SELECT r.agencyModeFk, NEW.zoneFk FROM route r + WHERE r.id = NEW.routeFk; + + CALL vn.routeUpdateM3(NEW.routeFk); + END IF; + + SELECT COUNT(*) INTO vHasTicketRefund + FROM ticketRefund + WHERE originalTicketFk = NEW.id + OR refundTicketFk = NEW.id; + + IF vHasTicketRefund AND NEW.clientFk <> OLD.clientFk THEN + CALL util.throw('The ticket has a refund associated'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_afterUpdate` + AFTER UPDATE ON `ticket` + FOR EACH ROW +BEGIN + + IF !(NEW.id <=> OLD.id) + OR !(NEW.warehouseFk <=> OLD.warehouseFk) + OR !(NEW.shipped <=> OLD.shipped) THEN + CALL stock.log_add('ticket', NEW.id, OLD.id); + END IF; + + IF !(NEW.clientFk <=> OLD.clientFk) + OR !(NEW.addressFk <=> OLD.addressFk) + OR !(NEW.companyFk <=> OLD.companyFk) THEN + CALL ticket_requestRecalc(NEW.id); + END IF; + + IF NEW.routeFk <> OLD.routeFk THEN + UPDATE expedition + SET hasNewRoute = TRUE + WHERE ticketFk = 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_beforeDelete` + BEFORE DELETE ON `ticket` + FOR EACH ROW +BEGIN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.route r + WHERE r.isOk = FALSE + AND r.id = OLD.routeFk + AND r.created >= util.VN_CURDATE() + GROUP BY r.id; + + DELETE FROM sale WHERE ticketFk = OLD.id; + + DELETE FROM ticketDms WHERE ticketFk = 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 */ ; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticket_afterDelete` + AFTER DELETE ON `ticket` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'Ticket', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete +AFTER DELETE +ON ticketCollection FOR EACH ROW +BEGIN + + DECLARE vSalesRemaining INT; + + SELECT count(*) INTO vSalesRemaining + FROM vn.ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE collectionFk = OLD.collectionFk + AND tc.id != OLD.id; + + IF NOT vSalesRemaining THEN + + DELETE FROM vn.collection WHERE id = OLD.collectionFk; + + ELSE + + UPDATE vn.collection + SET saleTotalCount = vSalesRemaining + WHERE id = OLD.collectionFk; + + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_beforeInsert` + BEFORE INSERT ON `ticketDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_beforeUpdate` + BEFORE UPDATE ON `ticketDms` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_beforeDelete` + BEFORE DELETE ON `ticketDms` + FOR EACH ROW +BEGIN + UPDATE dms + SET dmsTypeFk = (SELECT id + FROM dmsType + WHERE `code` = 'trash' + ) + WHERE id = OLD.dmsFk AND ( SELECT IF(COUNT(*) > 0, FALSE, TRUE) + FROM ticketDms + WHERE dmsFk = OLD.dmsFk + ) ; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketDms_afterDelete` + AFTER DELETE ON `ticketDms` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'ticketDms', + `changedModelId` = OLD.ticketFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketObservation_beforeInsert` + BEFORE INSERT ON `ticketObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketObservation_beforeUpdate` + BEFORE UPDATE ON `ticketObservation` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketObservation_afterDelete` + AFTER DELETE ON `ticketObservation` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketObservation', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_BEFORE_INSERT` + BEFORE INSERT ON `ticketPackaging` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.workerFk = account.myUser_getId(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_beforeUpdate` + BEFORE UPDATE ON `ticketPackaging` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_afterDelete` + AFTER DELETE ON `ticketPackaging` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketPackaging', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketParking_BEFORE_INSERT` + BEFORE INSERT ON `ticketParking` + FOR EACH ROW +BEGIN + + SET NEW.workerFk = vn.getUser(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeInsert` + BEFORE INSERT ON `ticketRefund` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeUpdate` + BEFORE UPDATE ON `ticketRefund` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_afterDelete` + AFTER DELETE ON `ticketRefund` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketRefund', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRequest_beforeInsert` + BEFORE INSERT ON `ticketRequest` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.ticketFk IS NULL THEN + SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk); + END IF; + + IF NEW.requesterFk IS NULL THEN + SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode); + END IF; + + IF NEW.attenderFk IS NULL THEN + SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRequest_beforeUpdate` + BEFORE UPDATE ON `ticketRequest` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + IF NEW.saleFk <> OLD.saleFk THEN + SET NEW.ticketFk = (SELECT s.ticketFk FROM sale s WHERE s.id = NEW.saleFk); + END IF; + + IF NEW.salesPersonCode <> OLD.salesPersonCode THEN + SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode); + END IF; + + IF NEW.buyerCode <> OLD.buyerCode THEN + SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRequest_afterDelete` + AFTER DELETE ON `ticketRequest` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketRequest', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_beforeInsert` + BEFORE INSERT ON `ticketService` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_ai` + AFTER INSERT ON `ticketService` + FOR EACH ROW +BEGIN + + CALL ticket_requestRecalc(NEW.ticketFk); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_beforeUpdate` + BEFORE UPDATE ON `ticketService` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_au` + AFTER UPDATE ON `ticketService` + FOR EACH ROW +BEGIN + IF !(NEW.price <=> OLD.price) + OR !(NEW.ticketFk <=> OLD.ticketFk) + OR !(NEW.quantity <=> OLD.quantity) THEN + CALL ticket_requestRecalc(NEW.ticketFk); + CALL ticket_requestRecalc(OLD.ticketFk); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketService_ad` + AFTER DELETE ON `ticketService` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketService', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL ticket_requestRecalc(OLD.ticketFk); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_beforeInsert` + BEFORE INSERT ON `ticketTracking` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_afterInsert` + AFTER INSERT ON `ticketTracking` + FOR EACH ROW +BEGIN + DECLARE vNumTicketsPrepared INT; + + REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) + SELECT NEW.ticketFk, NEW.id, `name` + FROM state + WHERE id = NEW.stateFk; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_beforeUpdate` + BEFORE UPDATE ON `ticketTracking` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_afterUpdate` + AFTER UPDATE ON `ticketTracking` + FOR EACH ROW +BEGIN + DECLARE vTicketFk INT; + DECLARE vTicketTrackingFk INT; + DECLARE vStateName VARCHAR(15); + + IF NEW.stateFk <> OLD.stateFk THEN + REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) + SELECT NEW.ticketFk, NEW.id, `name` + FROM state + WHERE id = NEW.stateFk; + END IF; + + IF NEW.ticketFk <> OLD.ticketFk THEN + SELECT i.ticketFk, i.id, s.`name` + INTO vTicketFk, vTicketTrackingFk, vStateName + FROM ticketTracking i + JOIN state s ON i.stateFk = s.id + WHERE ticketFk = NEW.ticketFk + ORDER BY created DESC + LIMIT 1; + + IF vTicketFk > 0 THEN + REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name) + VALUES(vTicketFk, vTicketTrackingFk, vStateName); + 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 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketTracking_afterDelete` + AFTER DELETE ON `ticketTracking` + FOR EACH ROW +BEGIN + DECLARE vTicketFk INT; + DECLARE vTicketTrackingFk INT; + DECLARE vStateName VARCHAR(15); + + DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' + BEGIN + DELETE FROM vn.ticketLastState + WHERE ticketFk = OLD.ticketFk; + END; + + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketTracking', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + + CALL util.debugAdd('deletedState', + CONCAT('interFk: ', OLD.id, + ' ticketFk: ', OLD.ticketFk, + ' stateFk: ', OLD.stateFk)); + + SELECT i.ticketFk, i.id, s.`name` + INTO vTicketFk, vTicketTrackingFk, vStateName + FROM ticketTracking i + JOIN state s ON i.stateFk = s.id + WHERE ticketFk = OLD.ticketFk + ORDER BY created DESC + LIMIT 1; + + IF vTicketFk > 0 THEN + REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name) + VALUES(vTicketFk, vTicketTrackingFk, vStateName); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketWeekly_beforeInsert` + BEFORE INSERT ON `ticketWeekly` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketWeekly_beforeUpdate` + BEFORE UPDATE ON `ticketWeekly` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketWeekly_afterDelete` + AFTER DELETE ON `ticketWeekly` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'TicketWeekly', + `changedModelId` = OLD.ticketFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`time_AFTER_UPDATE` + AFTER UPDATE ON `time` + FOR EACH ROW +BEGIN + /*INSERT INTO vn.mail SET + `sender` = 'jgallego@verdnatura.es', + `replyTo` = 'jgallego@verdnatura.es', + `subject` = 'tabla time modificada', + `body` = CONCAT(account.myUser_getName(), ' ha modificado la tabla time ', + NEW.`dated`);*/ +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_beforeInsert` + BEFORE INSERT ON `town` + FOR EACH ROW +BEGIN + SET NEW.geoFk = zoneGeo_new('town', NEW.`name`, + (SELECT geoFk FROM province WHERE id = NEW.provinceFk)); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_beforeUpdate` + BEFORE UPDATE ON `town` + FOR EACH ROW +BEGIN + -- IF !(OLD.geoFk <=> NEW.geoFk) THEN + -- CALL zoneGeo_throwNotEditable; + -- 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_afterUpdate` + AFTER UPDATE ON `town` + FOR EACH ROW +BEGIN + IF !(OLD.provinceFk <=> NEW.provinceFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM province WHERE id = NEW.provinceFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`town_afterDelete` + AFTER DELETE ON `town` + FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_beforeInsert` + BEFORE INSERT ON `travel` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + + CALL travel_checkDates(NEW.shipped, NEW.landed); + + CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_beforeUpdate` + BEFORE UPDATE ON `travel` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +/* + IF ((NOT NEW.shipped <=> OLD.shipped ) + OR (NOT NEW.landed <=> OLD.landed ) + OR (NOT NEW.warehouseInFk <=> OLD.warehouseInFk ) + OR (NOT NEW.warehouseOutFk <=> OLD.warehouseOutFk )) + AND (OLD.totalEntries AND OLD.landed < CURDATE()) THEN + CALL util.throw("Cannot past travels with entries"); + END IF; +*/ + IF NOT (NEW.landed <=> OLD.landed) + OR NOT (NEW.shipped <=> OLD.shipped) THEN + CALL travel_checkDates(NEW.shipped, NEW.landed); + END IF; + + IF NOT (NEW.isReceived <=> OLD.isReceived) THEN + CALL travel_checkPackaging(NEW.id); + END IF; + + IF NOT (NEW.warehouseInFk <=> OLD.warehouseInFk) THEN + CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_afterUpdate` + AFTER UPDATE ON `travel` + FOR EACH ROW +BEGIN + CALL stock.log_add('travel', NEW.id, OLD.id); + + IF !(NEW.shipped <=> OLD.shipped) THEN + UPDATE entry + SET commission = entry_getCommission(travelFk, currencyFk,supplierFk) + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travel_afterDelete` + AFTER DELETE ON `travel` + FOR EACH ROW +BEGIN + INSERT INTO travelLog + SET `action` = 'delete', + `changedModel` = 'Travel', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_beforeInsert` + BEFORE INSERT ON `travelThermograph` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_beforeUpdate` + BEFORE UPDATE ON `travelThermograph` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`travelThermograph_afterDelete` + AFTER DELETE ON `travelThermograph` + FOR EACH ROW +BEGIN + INSERT INTO travelLog + SET `action` = 'delete', + `changedModel` = 'TravelThermograph', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`vehicle_beforeInsert` + BEFORE INSERT ON `vehicle` + FOR EACH ROW +BEGIN + CALL vehicle_checkNumberPlate(NEW.numberPlate, NEW.countryCodeFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`vehicle_beforeUpdate` + BEFORE UPDATE ON `vehicle` + FOR EACH ROW +BEGIN + CALL vehicle_checkNumberPlate(NEW.numberPlate, NEW.countryCodeFk); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`warehouse_afterInsert` + BEFORE UPDATE ON `warehouse` + FOR EACH ROW +BEGIN + IF NEW.isFeedStock AND NEW.isInventory THEN + CALL util.throw("isFeedStock and isInventory cannot both be true"); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`warehouse_afterUpdate` + AFTER UPDATE ON `warehouse` + FOR EACH ROW +BEGIN + IF NEW.isFeedStock IS TRUE AND OLD.isFeedStock IS FALSE THEN + INSERT IGNORE INTO warehouseAlias(`name`) VALUES(NEW.`name`); + INSERT IGNORE INTO warehouseJoined(warehouseFk, warehouseAliasFk) + VALUES(NEW.id,LAST_INSERT_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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`worker_beforeInsert` + BEFORE INSERT ON `worker` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`worker_beforeUpdate` + BEFORE UPDATE ON `worker` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`worker_afterDelete` + AFTER DELETE ON `worker` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'Worker', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerDocument_beforeInsert` + BEFORE INSERT ON `workerDocument` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerDocument_beforeUpdate` + BEFORE UPDATE ON `workerDocument` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerDocument_afterDelete` + AFTER DELETE ON `workerDocument` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'WorkerDocument', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerIncome_afterInsert` + AFTER INSERT ON `workerIncome` + FOR EACH ROW +BEGIN + CALL worker_updateBalance(NEW.workerFk,NEW.credit,NEW.debit); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerIncome_afterUpdate` + AFTER UPDATE ON `workerIncome` + FOR EACH ROW +BEGIN + CALL worker_updateBalance(NEW.workerFk,-OLD.credit,-OLD.debit); + + CALL worker_updateBalance(NEW.workerFk,NEW.credit,NEW.debit); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerIncome_afterDelete` + AFTER DELETE ON `workerIncome` + FOR EACH ROW +BEGIN + CALL worker_updateBalance(OLD.workerFk,-OLD.credit,-OLD.debit); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workerTimeControl_AI` + AFTER INSERT ON `workerTimeControl` + FOR EACH ROW +BEGIN + IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN + CALL util.throw('date in the future'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`workingHoursBeforeInsert` + BEFORE INSERT ON `workingHours` + FOR EACH ROW +BEGIN + IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = util.VN_CURDATE()) > 0 THEN + CALL util.throw ('ALREADY_LOGGED'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zone_beforeInsert` + BEFORE INSERT ON `zone` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zone_beforeUpdate` + BEFORE UPDATE ON `zone` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zone_afterDelete` + AFTER DELETE ON `zone` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'Zone', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneEvent_beforeInsert` + BEFORE INSERT ON `zoneEvent` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneEvent_beforeUpdate` + BEFORE UPDATE ON `zoneEvent` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneEvent_afterDelete` + AFTER DELETE ON `zoneEvent` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'zoneEvent', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_BI` + BEFORE INSERT ON `zoneExclusion` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.userFk = account.myUser_getId(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_BU` + BEFORE UPDATE ON `zoneExclusion` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); + SET NEW.userFk = account.myUser_getId(); + +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneExclusion_afterDelete` + AFTER DELETE ON `zoneExclusion` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'zoneExclusion', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneGeo_beforeInsert` + BEFORE INSERT ON `zoneGeo` + FOR EACH ROW +BEGIN + CALL zoneGeo_checkName(NEW.`name`); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneGeo_beforeUpdate` + BEFORE UPDATE ON `zoneGeo` + FOR EACH ROW +BEGIN + IF !(OLD.`name` <=> NEW.`name`) THEN + CALL zoneGeo_checkName(NEW.`name`); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneIncluded_beforeInsert` + BEFORE INSERT ON `zoneIncluded` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneIncluded_beforeUpdate` + BEFORE UPDATE ON `zoneIncluded` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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 = utf8mb3 */ ; +/*!50003 SET character_set_results = utf8mb3 */ ; +/*!50003 SET collation_connection = utf8mb3_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneIncluded_afterDelete` + AFTER DELETE ON `zoneIncluded` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'zoneIncluded', + `changedModelId` = OLD.zoneFk, + `userFk` = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneWarehouse_beforeInsert` + BEFORE INSERT ON `zoneWarehouse` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneWarehouse_beforeUpdate` + BEFORE UPDATE ON `zoneWarehouse` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`zoneWarehouse_afterDelete` + AFTER DELETE ON `zoneWarehouse` + FOR EACH ROW +BEGIN + INSERT INTO zoneLog + SET `action` = 'delete', + `changedModel` = 'ZoneWarehouse', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +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 */ ; + +-- +-- Current Database: `vn2008` +-- + +USE `vn2008`; +/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn2008`.`Conteo_ai` + AFTER INSERT ON `Conteo` + FOR EACH ROW +BEGIN + DECLARE intTravel INTEGER; + SELECT t.id INTO intTravel FROM Compres c JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada + JOIN travel t ON t.id = e.travel_id + WHERE landing = util.VN_CURDATE() AND c.Id_Article = NEW.Id_Article AND warehouse_id = NEW.warehouse_id AND received <> TRUE LIMIT 1; + IF (intTravel) then + UPDATE travel SET received = TRUE WHERE id = intTravel; + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn2008`.`account_conciliacion_BEFORE_INSERT` + BEFORE INSERT ON `account_conciliacion` + FOR EACH ROW +set new.id_calculated = replace( + replace( + replace( + replace( + concat(new.Id_Proveedores_account,new.Fechaoperacion,new.importe,new.Concepto,new.DebeHaber) + ,' ','') + ,":",'') + ,'-','') + ,'.','') */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn2008`.`agency_hourBeforeInsert` + BEFORE INSERT ON `agency_hour` + FOR EACH ROW +BEGIN + DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + IF NEW.week_day IS NULL AND NEW.province_id IS NULL AND NEW.subtract_day = 0 AND NEW.max_hour = 0 THEN + CALL util.throw ('FILL_MORE_FIELDS'); + END IF; + + SELECT COUNT(*) INTO vAlreadyExists + FROM vn2008.agency_hour + WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id + AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour + AND NEW.agency_id <=> agency_id; + + IF vAlreadyExists > 1 THEN + CALL util.throw('ALREADY_EXISTS'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn2008`.`agency_hour_AFTER_UPDATE` + AFTER UPDATE ON `agency_hour` + FOR EACH ROW +BEGIN +DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + + SELECT COUNT(*) INTO vAlreadyExists + FROM vn2008.agency_hour + WHERE NEW.week_day <=> week_day AND NEW.province_id <=> province_id + AND NEW.warehouse_id <=> warehouse_id AND NEW.max_hour <=> max_hour + AND NEW.agency_id <=> agency_id; + + IF vAlreadyExists > 1 THEN + CALL util.throw('ALREADY_EXISTS'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn2008`.`awb_recibida_ad` + AFTER DELETE ON `awb_recibida` + FOR EACH ROW +IF (SELECT COUNT(*) FROM recibida_iva where recibida_id = OLD.recibida_id) = 0 + AND + (SELECT COUNT(*) FROM recibida_vencimiento where recibida_id = OLD.recibida_id) = 0 + AND + (SELECT contabilizada FROM recibida WHERE id = OLD.recibida_id) = 0 +THEN + DELETE FROM recibida WHERE id = OLD.recibida_id; +END IF */;; +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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn2008`.`movement_label_au` + AFTER UPDATE ON `movement_label` + FOR EACH ROW +-- Edit trigger body code below this line. Do not edit lines above this one +IF NEW.stem >= (SELECT Cantidad FROM Movimientos WHERE Id_Movimiento = NEW.Id_Movimiento) THEN + UPDATE Movimientos SET OK = 1 WHERE Id_Movimiento = NEW.Id_Movimiento; +END IF */;; +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 */ ; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2024-01-25 16:24:46 diff --git a/db/dump/Dockerfile b/db/dump/Dockerfile index 72bcf54d5..91d0fde2c 100644 --- a/db/dump/Dockerfile +++ b/db/dump/Dockerfile @@ -1,4 +1,4 @@ -FROM mariadb:10.7.7 +FROM mariadb:10.11.6 ENV TZ Europe/Madrid diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 0f0edef86..d5eec544f 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -15,8 +15,8 @@ INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, max -- XXX: eti -INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,agencyFk,`ref`,m3,kg,cargoSupplierFk) - VALUES (9,'2022-05-20','2022-05-20',13,4,1,'nine travel',69.0,600,1); +INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,`ref`,m3,kg,cargoSupplierFk) + VALUES (9,'2022-05-20','2022-05-20',13,4,'nine travel',69.0,600,1); INSERT INTO vn.entry (id, supplierFk, dated, invoiceNumber, evaNotes, travelFk, companyFk) VALUES @@ -25,9 +25,9 @@ INSERT INTO vn.entry (id, supplierFk, dated, invoiceNumber, evaNotes, travelFk, INSERT INTO vn.buy (id,entryFk,itemFk,quantity,dispatched,buyingValue,freightValue,isIgnored,stickers,packing,`grouping`,groupingMode,comissionValue,packageValue,packagingFk,price1,price2,price3,minPrice,printedStickers,workerFk,isChecked,isPickedOff,created,`__cm2`,weight) VALUES - (16,8,1,100,0,50.0,1.5,0,1,1,1,0,0.0,1.5,'4',0.0,99.6,99.4,0.0,0,0,1,0,'2022-06-20 00:00:00',0,1.0), - (17,9,2,450,0,5.0,1.0,0,1,10,10,0,0.0,1.0,'3',0.0,7.3,7.0,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), - (18,9,15,500,0,55.0,1.0,0,1,1,1,0,0.0,1.0,'5',0.0,78.3,75.6,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), + (16,10,1,100,0,50.0,1.5,0,1,1,1,0,0.0,1.5,'4',0.0,99.6,99.4,0.0,0,0,1,0,'2022-06-20 00:00:00',0,1.0), + (17,10,2,450,0,5.0,1.0,0,1,10,10,0,0.0,1.0,'3',0.0,7.3,7.0,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), + (18,10,15,500,0,55.0,1.0,0,1,1,1,0,0.0,1.0,'5',0.0,78.3,75.6,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), (19,10,11,5000,0,50.0,1.0,0,1,1,1,1,0.0,1.0,'4',0.0,99.6,99.4,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5); INSERT INTO vn2008.Splits (Id_Split,Id_Ticket,Id_Entrada,Fecha,Notas) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 9894275a3..6a58b60f5 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -6,6 +6,10 @@ */ SET foreign_key_checks = 0; +-- CREATE ROLE 'salix'; +-- GRANT 'salix' TO 'root'@'%'; +-- SET DEFAULT ROLE 'salix' FOR 'root'@'%'; + CREATE SCHEMA IF NOT EXISTS `vn2008`; CREATE SCHEMA IF NOT EXISTS `tmp`; @@ -91,18 +95,17 @@ INSERT INTO `vn`.`educationLevel` (`id`, `name`) (1, 'ESTUDIOS PRIMARIOS COMPLETOS'), (2, 'ENSEÑANZAS DE BACHILLERATO'); -INSERT INTO `vn`.`worker` - SET `id` = 9, - `code` = 009, - `firstName` = 'developer', - `lastName` = 'developer', - `bossFk` = 9; +INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`) + SELECT id,UPPER(LPAD(role, 3, '0')), name, name, NULL + FROM `account`.`user` + WHERE `id` = 9; -INSERT IGNORE INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`) +INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`) SELECT id,UPPER(LPAD(role, 3, '0')), name, name, 9 - FROM `account`.`user`; + FROM `account`.`user` + WHERE `id` <> 9; -UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 20; +UPDATE `vn`.`worker` SET bossFk = NULL WHERE id = 20; UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 1 OR id = 9; UPDATE `vn`.`worker` SET bossFk = 19 WHERE id = 18; @@ -175,51 +178,33 @@ INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) (1, 'Main Warehouse'), (2, 'Gotham'); -INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`, `hasProduction`, isOrigin, isDestiny) +INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`, `hasProduction`) VALUES - (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1), - (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 2, 13, 1, 1, 0), - (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0), - (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1, 0, 1), - (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1, 0, 0), - (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 2, 1, 0, 0, 0), - (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0, 0, 0); + (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 2, 1, 1), + (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 2, 13, 1), + (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), + (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), + (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), + (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 2, 1, 0), + (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0); +INSERT INTO `vn`.`sectorType` (id,description) + VALUES (1,'First type'); -INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`) +INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`) VALUES - (1, 'First sector', 1, 'FIRST'), - (2, 'Second sector', 2, 'SECOND'); + (1, 'First sector', 1, 'FIRST', 1), + (2, 'Second sector', 2, 'SECOND',1); -INSERT INTO vn.printerModel (code) - VALUES ('pcode1'), - ('pcode2'); - -INSERT INTO vn.screenModel (code) - VALUES ('scode1'), - ('scode2'); - -INSERT INTO vn.screen (name,modelFk) - VALUES ('screen1','scode1'), - ('screen1','scode2'); - -INSERT INTO vn.scannerModel (code) - VALUES ('sscode1'), - ('sscode2'); - -INSERT INTO vn.scanner (name,modelFk) - VALUES ('scanner1','sscode1'), - ('scanner2','sscode2'); - - -INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `modelFk`, `isLabeler`, `sectorFk`, `ipAddress`) +INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAddress`) VALUES - (1, 'printer1', 'path1','pcode1', 0, 1 , NULL), - (2, 'printer2', 'path2','pcode1', 1, 1 , NULL), - (4, 'printer4', 'path4','pcode2', 0, 1, '10.1.10.4'); + (1, 'printer1', 'path1', 0, 1 , NULL), + (2, 'printer2', 'path2', 1, 1 , NULL), + (4, 'printer4', 'path4', 0, NULL, '10.1.10.4'); UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1; + INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`,`bossFk`, `phone`) VALUES (1106, 'LGN', 'David Charles', 'Haller', 19, 432978106), @@ -390,20 +375,20 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) (4, 'GCN Channel'), (5, 'The Newspaper'); -INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`) +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) VALUES - (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), - (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), - (1103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street, Apartament 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), - (1104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist'), - (1105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist'), - (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist'), - (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1, 'florist'), - (1108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist'), - (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'), - (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'), - (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others'), - (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others'); + (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist','normal'), + (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), + (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), + (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist','normal'), + (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist','normal'), + (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist','normal'), + (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'), + (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 @@ -437,7 +422,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1), (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1), (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1), - (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), + (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1), (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1), (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1), @@ -469,7 +454,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0), (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0), (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0), - (128, 'Cerebro', 'address 28', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), + (128, 'Cerebro', 'address 28', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), (129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0), (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0); @@ -502,7 +487,24 @@ CREATE TEMPORARY TABLE tmp.address WHERE `defaultAddressFk` IS NULL; DROP TEMPORARY TABLE tmp.address; -INSERT INTO `vn`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`) +INSERT INTO `vn`.`clientCredit`(`clientFk`, `workerFk`, `amount`, `created`) + VALUES + (1101, 5, 300, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 MONTH)), + (1101, 5, 900, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 MONTH)), + (1101, 5, 800, DATE_ADD(util.VN_CURDATE(), INTERVAL -9 MONTH)), + (1101, 5, 700, DATE_ADD(util.VN_CURDATE(), INTERVAL -8 MONTH)), + (1101, 5, 600, DATE_ADD(util.VN_CURDATE(), INTERVAL -7 MONTH)), + (1101, 5, 500, DATE_ADD(util.VN_CURDATE(), INTERVAL -6 MONTH)), + (1101, 5, 400, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 MONTH)), + (1101, 9, 300, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), + (1101, 9, 200, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), + (1101, 9, 100, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), + (1101, 9, 50 , DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (1102, 9, 800, util.VN_CURDATE()), + (1104, 9, 90 , util.VN_CURDATE()), + (1105, 9, 90 , util.VN_CURDATE()); + +INSERT INTO `vn`.`roleCreditLimit`(`id`, `maxAmount`, `roleFk`) VALUES (1, 9999999, 20), (2, 10000, 21), @@ -609,20 +611,24 @@ INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion` ('NATIONAL', 0, 1), ('WORLD', 2, 15); +INSERT INTO vn.invoiceOutConfig + SET parallelism = 8; + INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) VALUES - ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), - ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), - ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), - ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'quick'), - ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); + ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), + ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), + ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), + ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'quick'), + ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), + ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) VALUES - (1, 'T', 1014.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), + (1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (4, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), + (4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0); UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; @@ -631,30 +637,6 @@ UPDATE `vn`.`invoiceOut` SET ref = 'T3333333' WHERE id = 3; UPDATE `vn`.`invoiceOut` SET ref = 'T4444444' WHERE id = 4; UPDATE `vn`.`invoiceOut` SET ref = 'A1111111' WHERE id = 5; - -INSERT INTO vn.siiTrascendencyInvoiceOut (id, description) - VALUES - (1, 'Operación de régimen general'), - (2, 'Exportación'), - (3, 'Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección (135 - 139 de LIVA)'), - (4, 'Régimen especial oro de inversión'), - (5, 'Régimen especial agencias de viajes'), - (6, 'Régimen especial grupo de entidades en IVA (Nivel Avanzado)'), - (7, 'Régimen especial criterio de caja'), - (8, 'Operaciones sujetas al IPSI / IGIC'), - (9, 'Facturación de las prestaciones de servicios de agencias de viaje que actúan como mediadoras en nombre y por cuenta ajena (D.A.4ª RD 1619/2012)'), - (10, 'Cobros por cuenta de terceros de honorarios profesionales o de Dº derivados de la propiedad industrial, de autor u otros por cuenta de sus socios, asociados,colegiados efectuados por sociedades, asociaciones, colegios profesionales u otras entidades '), - (11, 'Operaciones de arrendamiento de local de negocio sujetas a retención'), - (12, 'Operaciones de arrendamiento de local de negocio no sujetos a retención'), - (13, 'Operaciones de arrendamiento de local de negocio sujetas y no sujetas a retención'), - (14, 'Factura con IVA pendiente de devengo (certificaciones de obra cuyo destinatario sea una Administración Pública)'), - (15, 'Factura con IVA pendiente de devengo - operaciones de tracto sucesivo'), - (16, 'Primer semestre 2017'); - - -INSERT INTO vn.invoiceOutConfig - SET parallelism = 8; - INSERT INTO `vn`.`invoiceOutTax` (`invoiceOutFk`, `taxableBase`, `vat`, `pgcFk`) VALUES (1, 895.76, 89.58, 4722000010), @@ -688,19 +670,20 @@ INSERT INTO `vn`.`invoiceOutExpense`(`id`, `invoiceOutFk`, `amount`, `expenseFk` INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `itemMaxSize`) VALUES - (1, 'Zone pickup A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), - (2, 'Zone pickup B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), + (1, 'Zone pickup A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), + (2, 'Zone pickup B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), (3, 'Zone 247 A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), (4, 'Zone 247 B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), (5, 'Zone expensive A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), (6, 'Zone expensive B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), - (7, 'Zone refund', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 100), - (8, 'Zone others', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 100), - (9, 'Zone superMan', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 0, 0, 100), - (10, 'Zone teleportation', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 0, 0, 100), - (11, 'Zone pickup C', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100), - (12, 'Zone entanglement', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 0, 0, 100), - (13, 'Zone quantum break', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 0, 0, 100); + (7, 'Zone refund', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 1, 0, 100), + (8, 'Zone others', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 1, 0, 100), + (9, 'Zone superMan', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 1, 0, 100), + (10, 'Zone teleportation', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 1, 0, 100), + (11, 'Zone pickup C', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), + (12, 'Zone entanglement', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 1, 0, 100), + (13, 'Zone quantum break', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 1, 0, 100); + INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) VALUES @@ -748,38 +731,38 @@ INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agen INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`) VALUES - (1 , 3, 1, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1), - (2 , 1, 1, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2), - (3 , 1, 7, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL), - (4 , 3, 2, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL), - (5 , 3, 3, 3, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL), - (6 , 1, 3, 3, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL), - (7 , NULL, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (8 , NULL, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Bat cave', 121, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (9 , NULL, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (10, 1, 1, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (11, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (12, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (13, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (1 , 3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1), + (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2), + (3 , 1, 7, 1, 6, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL), + (4 , 3, 2, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL), + (5 , 3, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL), + (6 , 1, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL), + (7 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (8 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Bat cave', 121, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (9 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (10, 1, 1, 5, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (11, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (12, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (13, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), (14, 1, 2, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1104, 'Malibu Point', 4, NULL, 0, 9, 5, 1, util.VN_CURDATE(), NULL), - (15, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 'An incredibly long alias for testing purposes', 125, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (16, 1, 7, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (17, 1, 7, 2, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (18, 1, 4, 4, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 'Cerebro', 128, NULL, 0, 12, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +12 HOUR), NULL), + (15, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 'An incredibly long alias for testing purposes', 125, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (16, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (17, 1, 7, 2, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), + (18, 1, 4, 4, 4, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 'Cerebro', 128, NULL, 0, 12, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +12 HOUR), NULL), (19, 1, 5, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 1, NULL, 5, 1, util.VN_CURDATE(), NULL), - (20, 1, 5, 5, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), - (21, NULL, 5, 5, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), - (22, NULL, 5, 5, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), - (23, NULL, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'address 21', 121, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), - (24 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), + (20, 1, 5, 5, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), + (21, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), + (22, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), + (23, NULL, 8, 1, 7, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'address 21', 121, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), + (24 ,NULL, 8, 1, 7, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), (25 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), (26 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), (27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (28, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (29, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (30, 1, 8, 1, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (31, 1, 8, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (32, 1, 8, 1, NULL, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL); + (28, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (29, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (30, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), + (32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES @@ -801,7 +784,7 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des -- FIX for state hours on local, inter_afterInsert -- UPDATE vncontrol.inter SET odbc_date = DATE_ADD(util.VN_CURDATE(), INTERVAL -10 SECOND); -INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) +INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `userFk`, `created`) VALUES (1, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), (2, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), @@ -845,6 +828,7 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, VALUES (1, 'beta-server', 'nightmare@mydomain.com', '200', DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH)); + INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) VALUES (1, 'Diff', 'diff'), @@ -907,7 +891,9 @@ INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`) ('SLV', 'Silver', 1, 4, 'CACFD2'), ('BRW', 'Brown', 1, 5, 'DC7633'), ('BLK', 'Black', 1, 6, '000000'), - ('BAS', 'Blue/Silver', 1, 7, '5DADE2'); + ('BAS', 'Blue/Silver', 1, 7, '5DADE2'), + ('GRN', 'Green', 1, 8, '28A745'), + ('WHT', 'White', 1, 9, 'FFFFFF'); INSERT INTO `vn`.`origin`(`id`,`code`, `name`) VALUES @@ -954,26 +940,26 @@ INSERT INTO `vn`.`itemFamily`(`code`, `description`) ('SER', 'Services'), ('VT', 'Sales'); -INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenseFk`, - `comment`, `relevancy`, `image`, `subName`, `minPrice`, `stars`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`, `weightByPiece`) +INSERT INTO `vn`.`item`(`id`, `typeFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenseFk`, + `comment`, `relevancy`, `image`, `subName`, `minPrice`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`, `weightByPiece`) VALUES - (1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 1, 'EMB', 0, NULL, 'V', 0, 15,3), - (2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 2, 'VT', 0, NULL, 'H', 0, 10,2), - (3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, 5,5), - (4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL,NULL), - (10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 2, 'VT', 1, NULL, NULL, 1, NULL,NULL), - (14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL,NULL), - (15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), - (16, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), - (71, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL); + (1, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 'EMB', 0, NULL, 'V', 0, 15,3), + (2, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 'VT', 0, NULL, 'H', 0, 10,2), + (3, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 'VT', 0, NULL, NULL, 0, 5,5), + (4, 1, 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (5, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (6, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (7, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (8, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (9, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL,NULL), + (10, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (11, 1, 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (12, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), + (13, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 'VT', 1, NULL, NULL, 1, NULL,NULL), + (14, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL,NULL), + (15, 4, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), + (16, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), + (71, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL); -- Update the taxClass after insert of the items UPDATE `vn`.`itemTaxCountry` SET `taxClassFk` = 2 @@ -1000,6 +986,10 @@ INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPack ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, util.VN_CURDATE(), 15, 90.00), ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, util.VN_CURDATE(), 16, 0.00); +INSERT INTO `vn`.`packagingConfig`(`upperGap`, `defaultSmallPackageFk`, `defaultBigPackageFk`) + VALUES + ('10', 1, 'pallet 100'); + INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) VALUES (1, 'En reparto', 'ON DELIVERY'), @@ -1041,45 +1031,45 @@ INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`) VALUES - (1, 1, 1, 'Ranged weapon longbow 2m', 5, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (1, 1, 1, 'Ranged weapon longbow 200cm', 5, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), (2, 2, 1, 'Melee weapon combat fist 15cm', 10, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (3, 1, 1, 'Ranged weapon longbow 2m', 2, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (4, 4, 1, 'Melee weapon heavy shield 1x0.5m', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (5, 1, 2, 'Ranged weapon longbow 2m', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (6, 1, 3, 'Ranged weapon longbow 2m', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), - (7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.44, 0, 0, 0, util.VN_CURDATE()), - (8, 4, 11, 'Melee weapon heavy shield 1x0.5m', 10, 1.79, 0, 0, 0, util.VN_CURDATE()), - (9, 1, 16, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), + (3, 1, 1, 'Ranged weapon longbow 200cm', 2, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (4, 4, 1, 'Melee weapon heavy shield 100cm', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (5, 1, 2, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (6, 1, 3, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), + (7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.74, 0, 0, 0, util.VN_CURDATE()), + (8, 4, 11, 'Melee weapon heavy shield 100cm', 10, 1.79, 0, 0, 0, util.VN_CURDATE()), + (9, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), (10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, util.VN_CURDATE()), - (11, 1, 16, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), - (12, 4, 16, 'Melee weapon heavy shield 1x0.5m', 20, 1.71, 0, 0, 0, util.VN_CURDATE()), + (11, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), + (12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE()), (13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE()), - (14, 1, 8, 'Ranged weapon longbow 2m', 2, 103.49, 0, 0, 0, util.VN_CURDATE()), - (15, 1, 19, 'Ranged weapon longbow 2m', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), + (14, 1, 8, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE()), + (15, 1, 19, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), (16, 2, 20, 'Melee weapon combat fist 15cm', 20, 7.07, 0, 0, 0, util.VN_CURDATE()), (17, 2, 22, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (18, 4, 22, 'Melee weapon heavy shield 1x0.5m', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (19, 1, 4, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), - (20, 1, 5, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), - (21, 1, 6, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (22, 1, 7, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (23, 1, 9, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (24, 1, 10, 'Ranged weapon longbow 2m', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (25, 4, 12, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (26, 4, 13, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (27, 4, 14, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (28, 4, 15, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (29, 4, 17, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (30, 4, 18, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (18, 4, 22, 'Melee weapon heavy shield 100cm', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), + (19, 1, 4, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), + (20, 1, 5, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), + (21, 1, 6, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), + (22, 1, 7, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (23, 1, 9, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (24, 1, 10, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (25, 4, 12, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (26, 4, 13, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (27, 4, 14, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (28, 4, 15, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (29, 4, 17, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (30, 4, 18, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE()), - (32, 1, 24, 'Ranged weapon longbow 2m', -1, 8.07, 0, 0, 0, util.VN_CURDATE()), + (32, 1, 24, 'Ranged weapon longbow 200cm', -1, 8.07, 0, 0, 0, util.VN_CURDATE()), (33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE()), - (34, 4, 28, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (35, 4, 29, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (37, 4, 31, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (36, 4, 30, 'Melee weapon heavy shield 1x0.5m', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (34, 4, 28, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (35, 4, 29, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (37, 4, 31, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), + (36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), (38, 2, 32, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (39, 1, 32, 'Ranged weapon longbow 2m', 2, 103.49, 0, 0, 0, util.VN_CURDATE()); + (39, 1, 32, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE()); INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) VALUES @@ -1295,7 +1285,7 @@ INSERT INTO `vn`.`tag`(`id`, `code`, `name`, `isFree`, `isQuantitatif`, `sourceT (5, NULL, 'Diámetro', 1, 1, NULL, 'mm',NULL, 'diameter'), (7, NULL, 'Ancho de la base', 1, 1, NULL, 'mm',NULL, NULL), (23, 'stems', 'Tallos', 1, 1, NULL, NULL, NULL, 'stems'), - (27, NULL, 'Longitud(cm)', 1, 1, NULL, 'cm', NULL, NULL), + (27, NULL, 'Longitud(cm)', 1, 1, NULL, 'cm', NULL, 'size'), (36, 'producer', 'Proveedor', 1, 0, NULL, NULL, NULL, 'producer'), (56, NULL, 'Genero', 1, 0, NULL, NULL, NULL, NULL), (58, NULL, 'Variedad', 1, 0, NULL, NULL, NULL, NULL), @@ -1306,7 +1296,7 @@ INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`) VALUES (1, 1, 56, 'Ranged weapon', 1), (2, 1, 58, 'longbow', 2), - (3, 1, 27, '2m', 3), + (3, 1, 27, '200cm', 3), (4, 1, 36, 'Stark Industries', 4), (5, 1, 1, 'Brown', 5), (6, 1, 67, '+1 precission', 6), @@ -1320,42 +1310,42 @@ INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`) (14, 2, 23, '2', 7), (15, 3, 56, 'Ranged weapon', 1), (16, 3, 58, 'sniper rifle', 2), - (17, 3, 4, '300mm', 3), + (17, 3, 4, '113cm', 3), (18, 3, 36, 'Stark Industries', 4), (19, 3, 1, 'Green', 5), (20, 3, 67, 'precission', 6), (21, 3, 23, '3', 7), (22, 4, 56, 'Melee weapon', 1), (23, 4, 58, 'heavy shield', 2), - (24, 4, 4, '1x0.5m', 3), + (24, 4, 4, '100cm', 3), (25, 4, 36, 'Stark Industries', 4), (26, 4, 1, 'Black', 5), (27, 4, 67, 'containtment', 6), (28, 4, 23, '4', 7), (29, 5, 56, 'Ranged weapon', 1), (30, 5, 58, 'pistol', 2), - (31, 5, 27, '9mm', 3), + (31, 5, 67, '9mm', 3), (32, 5, 36, 'Stark Industries', 4), (33, 5, 1, 'Silver', 5), - (34, 5, 67, 'rapid fire', 6), + (34, 5, 27, '15cm', 6), (35, 5, 23, '5', 7), (36, 6, 56, 'Container', 1), (37, 6, 58, 'ammo box', 2), - (38, 6, 27, '1m', 3), + (38, 6, 27, '100cm', 3), (39, 6, 36, 'Stark Industries', 4), (40, 6, 1, 'Green', 5), (41, 6, 67, 'supply', 6), (42, 6, 23, '6', 7), (43, 7, 56, 'Container', 1), (44, 7, 58, 'medical box', 2), - (45, 7, 27, '1m', 3), + (45, 7, 27, '100cm', 3), (46, 7, 36, 'Stark Industries', 4), (47, 7, 1, 'White', 5), (48, 7, 67, 'supply', 6), (49, 7, 23, '7', 7), (50, 8, 56, 'Ranged Reinforced weapon', 1), (51, 8, 58, '+1 longbow', 2), - (52, 8, 27, '2m', 3), + (52, 8, 27, '200cm', 3), (53, 8, 36, 'Stark Industries', 4), (54, 8, 1, 'Brown', 5), (55, 8, 67, 'precission', 6), @@ -1369,14 +1359,14 @@ INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`) (63, 9, 23, '9', 7), (64, 10, 56, 'Ranged Reinforced weapon', 1), (65, 10, 58, 'sniper rifle', 2), - (66, 10, 4, '300mm', 3), + (66, 10, 67, '700mm', 3), (67, 10, 36, 'Stark Industries', 4), (68, 10, 1, 'Green', 5), - (69, 10, 67, 'precission', 6), + (69, 10, 27, '130cm', 6), (70, 10, 23, '10', 7), (71, 11, 56, 'Melee Reinforced weapon', 1), (72, 11, 58, 'heavy shield', 2), - (73, 11, 4, '1x0.5m', 3), + (73, 11, 4, '120cm', 3), (74, 11, 36, 'Stark Industries', 4), (75, 11, 1, 'Black', 5), (76, 11, 67, 'containtment', 6), @@ -1386,18 +1376,18 @@ INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`) (80, 12, 27, '9mm', 3), (81, 12, 36, 'Stark Industries', 4), (82, 12, 1, 'Silver', 5), - (83, 12, 67, 'rapid fire', 6), + (83, 12, 67, '23cm', 6), (84, 12, 23, '12', 7), (85, 13, 56, 'Chest', 1), (86, 13, 58, 'ammo box', 2), - (87, 13, 27, '1m', 3), + (87, 13, 27, '100cm', 3), (88, 13, 36, 'Stark Industries', 4), (89, 13, 1, 'Green', 5), (90, 13, 67, 'supply', 6), (91, 13, 23, '13', 7), (92, 14, 56, 'Chest', 1), (93, 14, 58, 'medical box', 2), - (94, 14, 27, '1m', 3), + (94, 14, 27, '100cm', 3), (95, 14, 36, 'Stark Industries', 4), (96, 14, 1, 'White', 5), (97, 14, 67, 'supply', 6), @@ -1443,23 +1433,34 @@ INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_ INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) VALUES - (1, 0), (2, 1), (3, 2), - (4, 4), (5, 6), (15, 6); -INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`) +INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) VALUES - (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1), - (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2), - (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1), - (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2), - (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1), - (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2); + (1, '07546501420', 67, 671, util.VN_CURDATE(), 1761, 1, 1), + (2, '07546491421', 252, 2769, util.VN_CURDATE(), 5231, 1, 1), + (3, '07546500823', 102, 1495, util.VN_CURDATE(), 3221, 1, 1), + (4, '99610288821', 252, 2777, util.VN_CURDATE(), 3641, 1, 1), + (5, '07546500834', 229, 3292, util.VN_CURDATE(), 6601, 2, 1), + (6, '22101929561', 37, 458, util.VN_CURDATE(), 441, 2, 1), + (7, '07546491432', 258, 3034, util.VN_CURDATE(), 6441, 2, 1), + (8, '99610288644', 476, 4461, util.VN_CURDATE(), 5751, 442, 1), + (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), + (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); + +INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`) + VALUES + (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), + (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2, 2), + (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), + (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), + (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), + (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) VALUES @@ -1963,9 +1964,9 @@ INSERT INTO `vn`.`workerTeam`(`id`, `team`, `workerFk`) INSERT INTO `vn`.`ticketRequest`(`id`, `description`, `requesterFk`, `attenderFk`, `quantity`, `itemFk`, `price`, `isOk`, `saleFk`, `ticketFk`, `created`) VALUES - (1, 'Ranged weapon longbow 2m', 18, 35, 5, 1, 9.10, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), + (1, 'Ranged weapon longbow 200cm', 18, 35, 5, 1, 9.10, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), (2, 'Melee weapon combat first 15cm', 18, 35, 10, 2, 1.07, 0, NULL, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), - (3, 'Melee weapon heavy shield 1x0.5m', 18, 35, 20, NULL, 3.06, NULL, NULL, 23, util.VN_CURDATE()), + (3, 'Melee weapon heavy shield 100cm', 18, 35, 20, NULL, 3.06, NULL, NULL, 23, util.VN_CURDATE()), (4, 'Melee weapon combat first 15cm', 18, 35, 15, NULL, 1.30, NULL, NULL, 11, util.VN_CURDATE()), (5, 'Melee weapon combat first 15cm', 18, 35, 15, 4, 1.30, 0, NULL, 18, util.VN_CURDATE()); @@ -2001,6 +2002,8 @@ INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES (1, 'General schedule', 40, 0); +INSERT INTO `vn`.`workerBusinessAgreement` (`id`, `name`, `monthHolidays`, `yearHours`, `started`, `ended`) + VALUES(1, 'flowers', 2.5, 1830, '2001-01-01', NULL); DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker @@ -2037,6 +2040,10 @@ UPDATE `vn`.`business` b SET b.`departmentFk` = 43 WHERE b.id IN(18, 19); +UPDATE `vn`.`business` b + SET b.`started` = b.`started` - INTERVAL 100 DAY + WHERE b.id = 1107; + INSERT INTO `vn`.`workCenterHoliday` (`workCenterFk`, `days`, `year`) VALUES ('1', '27.5', YEAR(util.VN_CURDATE())), @@ -2085,22 +2092,22 @@ INSERT INTO `vn`.`absenceType` (`id`, `name`, `rgb`, `code`, `holidayEntitlement INSERT INTO `vn`.`calendar` (`businessFk`, `dayOffTypeFk`, `dated`) VALUES - (1, 6, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 10 DAY))), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 10 DAY))), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 11 DAY))), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -12 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 12 DAY))), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -20 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 20 DAY))), - (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -13 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 8 DAY))), - (1106, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -14 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 9 DAY))), - (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 7 DAY))), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 10 DAY))), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 11 DAY))), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -12 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 12 DAY))), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -20 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 20 DAY))), - (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -13 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 8 DAY))), - (1107, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -14 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 9 DAY))), - (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL 7 DAY))), - (1107, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL - 16 DAY)); + (1, 6, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 10 DAY, util.VN_CURDATE() + INTERVAL 10 DAY)), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 10 DAY, util.VN_CURDATE() + INTERVAL 10 DAY)), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 11 DAY, util.VN_CURDATE() + INTERVAL 11 DAY)), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 12 DAY, util.VN_CURDATE() + INTERVAL 12 DAY)), + (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 20 DAY, util.VN_CURDATE() + INTERVAL 20 DAY)), + (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 13 DAY, util.VN_CURDATE() + INTERVAL 8 DAY)), + (1106, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 14 DAY, util.VN_CURDATE() + INTERVAL 9 DAY)), + (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 15 DAY, util.VN_CURDATE() + INTERVAL 7 DAY)), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 10 DAY, util.VN_CURDATE() + INTERVAL 10 DAY)), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 11 DAY, util.VN_CURDATE() + INTERVAL 11 DAY)), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 12 DAY, util.VN_CURDATE() + INTERVAL 12 DAY)), + (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 20 DAY, util.VN_CURDATE() + INTERVAL 20 DAY)), + (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 13 DAY, util.VN_CURDATE() + INTERVAL 8 DAY)), + (1107, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 14 DAY, util.VN_CURDATE() + INTERVAL 9 DAY)), + (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 15 DAY, util.VN_CURDATE() + INTERVAL 7 DAY)), + (1107, 2, util.VN_CURDATE() - INTERVAL 16 DAY); INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`, `apiKey`) VALUES @@ -2367,9 +2374,11 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`) (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'), (10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); -INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`) +INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`, `weekDays`) VALUES - (9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)); + (9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR), 'mon'), + (9, 'range', util.VN_CURDATE(), NULL, 'tue'), + (9, 'range', NULL, util.VN_CURDATE(), 'wed'); INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`) VALUES @@ -2382,28 +2391,28 @@ INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, ` (1107, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 1), (1107, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 1); -INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`) +INSERT INTO `vn`.`dmsType`(`id`, `name`, `readRoleFk`, `writeRoleFk`, `code`) VALUES - (1, 'Facturas Recibidas', 'recibidas', NULL, NULL, 'invoiceIn'), - (2, 'Doc oficial', 'oficial', NULL, NULL, 'officialDoc'), - (3, 'Laboral', 'laboral', 37, 37, 'hhrrData'), - (4, 'Albaranes recibidos', 'entradas', NULL, NULL, 'deliveryNote'), - (5, 'Otros', 'otros', 1, 1, 'miscellaneous'), - (6, 'Pruebas', 'pruebas', NULL, NULL, 'tests'), - (7, 'IAE Clientes', 'IAE_Clientes', 1, 1, 'economicActivitiesTax'), - (8, 'Fiscal', 'fiscal', NULL, NULL, 'fiscal'), - (9, 'Vehiculos', 'vehiculos', NULL, NULL, 'vehicles'), - (10, 'Plantillas', 'plantillas', NULL, NULL, 'templates'), - (11, 'Contratos', 'contratos', NULL, NULL, 'contracts'), - (12, 'ley de pagos', 'ley pagos', 1, 1, 'paymentsLaw'), - (13, 'Basura', 'basura', 1, 1, 'trash'), - (14, 'Ticket', 'tickets', 1, 1, 'ticket'), - (15, 'Presupuestos', 'Presupuestos', NULL, NULL, 'budgets'), - (16, 'Logistica', 'logistica', NULL, NULL, 'logistics'), - (17, 'cmr', 'cmr', NULL, NULL, 'cmr'), - (18, 'dua', 'dua', NULL, NULL, 'dua'), - (19, 'inmovilizado', 'inmovilizado', NULL, NULL, 'fixedAssets'), - (20, 'Reclamación', 'reclamacion', 1, 1, 'claim'); + (1, 'Facturas Recibidas', NULL, NULL, 'invoiceIn'), + (2, 'Doc oficial', NULL, NULL, 'officialDoc'), + (3, 'Laboral', 37, 37, 'hhrrData'), + (4, 'Albaranes recibidos', NULL, NULL, 'deliveryNote'), + (5, 'Otros', 1, 1, 'miscellaneous'), + (6, 'Pruebas', NULL, NULL, 'tests'), + (7, 'IAE Clientes', 1, 1, 'economicActivitiesTax'), + (8, 'Fiscal', NULL, NULL, 'fiscal'), + (9, 'Vehiculos', NULL, NULL, 'vehicles'), + (10, 'Plantillas', NULL, NULL, 'templates'), + (11, 'Contratos', NULL, NULL, 'contracts'), + (12, 'ley de pagos', 1, 1, 'paymentsLaw'), + (13, 'Basura', 1, 1, 'trash'), + (14, 'Ticket', 1, 1, 'ticket'), + (15, 'Presupuestos', NULL, NULL, 'budgets'), + (16, 'Logistica', NULL, NULL, 'logistics'), + (17, 'cmr', NULL, NULL, 'cmr'), + (18, 'dua', NULL, NULL, 'dua'), + (19, 'inmovilizado', NULL, NULL, 'fixedAssets'), + (20, 'Reclamación', 1, 1, 'claim'); INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) VALUES @@ -2515,20 +2524,7 @@ INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate (DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), (util.VN_CURDATE(), 1, 12, 17, 22, 27); -INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) - VALUES - (1, '07546501420', 67, 671, util.VN_CURDATE(), 1761, 1, 1), - (2, '07546491421', 252, 2769, util.VN_CURDATE(), 5231, 1, 1), - (3, '07546500823', 102, 1495, util.VN_CURDATE(), 3221, 1, 1), - (4, '99610288821', 252, 2777, util.VN_CURDATE(), 3641, 1, 1), - (5, '07546500834', 229, 3292, util.VN_CURDATE(), 6601, 2, 1), - (6, '22101929561', 37, 458, util.VN_CURDATE(), 441, 2, 1), - (7, '07546491432', 258, 3034, util.VN_CURDATE(), 6441, 2, 1), - (8, '99610288644', 476, 4461, util.VN_CURDATE(), 5751, 442, 1), - (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), - (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); - -INSERT INTO `vn`.`dua` (id, code, awbFk, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) +INSERT INTO `vn`.`dua` (id, code, awbFk__, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) VALUES (1, '19ES0028013A481523', 1, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), (2, '21ES00280136115760', 2, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1376.20, 442), @@ -2541,6 +2537,17 @@ INSERT INTO `vn`.`dua` (id, code, awbFk, issued, operated, booked, bookEntried, (9, '19ES00280132025491', 9, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 7126.23, 442), (10, '19ES00280132025492', 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 4631.45, 442); +INSERT INTO `vn`.`duaEntry` (`duaFk`, `entryFk`, `value`, `customsValue`, `euroValue`) + VALUES + (1, 1, 1.00, 1.00, 1.00), + (2, 2, 1.00, 1.00, 1.00), + (3, 3, 1.00, 1.00, 1.00), + (4, 4, 1.00, 1.00, 1.00), + (5, 5, 1.00, 1.00, 1.00), + (6, 6, 1.00, 1.00, 1.00), + (7, 7, 1.00, 1.00, 1.00), + (8, 8, 1.00, 1.00, 1.00); + REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`) VALUES (1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1), @@ -2788,19 +2795,17 @@ INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk VALUES (1, 1); -INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`) +INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`, `maxTimeToBreak`, `maxWorkShortCycle`, `maxWorkLongCycle`) VALUES - (1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13, 28800, 32400); + (1, 43200, 32400, 129600, 259200, 1080000, '', 'imap.verdnatura.es', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.00, 0.33, 40, '22:00:00', '06:00:00', 72000, 1200, 18000, 72000, 6, 13, 28800, 32400, 3600, 561600, 950400); INSERT INTO `vn`.`host` (`id`, `code`, `description`, `warehouseFk`, `bankFk`) VALUES (1, 'pc1', 'pc host', 1, 1); -INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`, `printerFk`) +INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`) VALUES - (1, 'h1', 1, '', 1); - -INSERT INTO vn.packingSiteLog (packingSiteFk, hostFk, workerFk, printerModelFk) VALUES('h1', '1', 1, 'pcode1'); + (1, 'h1', 1, ''); INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGroupKey`, `avgBoxingTime`) VALUES @@ -2814,11 +2819,18 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`) (2, 'invoice-electronic', 'A electronic invoice has been generated'), (3, 'not-main-printer-configured', 'A printer distinct than main has been configured'), (4, 'supplier-pay-method-update', 'A supplier pay method has been updated'), - (5, 'modified-entry', 'An entry has been modified'); + (5, 'modified-entry', 'An entry has been modified'), + (6, 'book-entry-deleted', 'accounting entries deleted'); INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) VALUES - (1, 9); + (1, 9), + (1, 1), + (2, 1), + (3, 9), + (4, 1), + (5, 9), + (6, 9); INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) VALUES @@ -2830,9 +2842,12 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) VALUES (1, 1109), (1, 1110), + (2, 1110), + (4, 1110), (2, 1109), - (1,9), - (1,3); + (1, 9), + (1, 3), + (6, 9); INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) @@ -2865,24 +2880,24 @@ UPDATE `account`.`user` INSERT INTO `vn`.`ticketLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`) VALUES - (7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 1, NULL), - (7, 18, 'update', 'Ticket', '{"quantity":1,"concept":"Chest ammo box"}', '{"quantity":10,"concept":"Chest ammo box"}', 1, NULL), - (7, 18, 'update', 'Sale', '{"price":3}', '{"price":5}', 1, NULL), - (7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 1x0.5m de '5' a '10'"), - (16, 9, 'update', 'Sale', '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', '{"quantity":8,"concept":"Shield", "price": 10.5, "itemFk": 1}' , 5689, 'Shield'); + (7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 22, NULL), + (7, 18, 'update', 'Ticket', '{"quantity":1,"concept":"Chest ammo box"}', '{"quantity":10,"concept":"Chest ammo box"}', 22, NULL), + (7, 18, 'update', 'Sale', '{"price":3}', '{"price":5}', 22, NULL), + (7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 100cm de '5' a '10'"), + (16, 9, 'update', 'Sale', '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', '{"quantity":8,"concept":"Shield", "price": 10.5, "itemFk": 1}' , 12, 'Shield'); INSERT INTO `vn`.`ticketLog` (originFk, userFk, `action`, creationDate, changedModel, changedModelId, changedModelValue, oldInstance, newInstance, description) VALUES (1, NULL, 'delete', '2001-06-09 11:00:04', 'Ticket', 45, 'Spider Man' , NULL, NULL, NULL), (1, 18, 'select', '2001-06-09 11:00:03', 'Ticket', 45, 'Spider Man' , NULL, NULL, NULL), - (1, NULL, 'update', '2001-05-09 10:00:02', 'Sale', 69854, 'Armor' , '{"isPicked": false}','{"isPicked": true}', NULL), - (1, 18, 'update', '2001-01-01 10:05:01', 'Sale', 69854, 'Armor' , NULL, NULL, 'Armor quantity changed from ''15'' to ''10'''), - (1, NULL, 'delete', '2001-01-01 10:00:10', 'Sale', 5689, 'Shield' , '{"quantity":10,"concept":"Shield"}', NULL, NULL), - (1, 18, 'insert', '2000-12-31 15:00:05', 'Sale', 69854, 'Armor' , NULL,'{"quantity":15,"concept":"Armor", "price": 345.99, "itemFk": 2}', NULL), + (1, NULL, 'update', '2001-05-09 10:00:02', 'Sale', 5, 'Armor' , '{"isPicked": false}','{"isPicked": true}', NULL), + (1, 18, 'update', '2001-01-01 10:05:01', 'Sale', 5, 'Armor' , NULL, NULL, 'Armor quantity changed from ''15'' to ''10'''), + (1, NULL, 'delete', '2001-01-01 10:00:10', 'Sale', 4, 'Shield' , '{"quantity":10,"concept":"Shield"}', NULL, NULL), + (1, 18, 'insert', '2000-12-31 15:00:05', 'Sale', 1, 'Armor' , NULL,'{"quantity":15,"concept":"Armor", "price": 345.99, "itemFk": 2}', NULL), (1, 18, 'update', '2000-12-28 08:40:45', 'Ticket', 45, 'Spider Man' , '{"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"isBlocked":false,"hasPriority":false,"companyFk":442,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}','{"warehouseFk":61,"shipped":"2023-05-17T22:00:00.000Z","nickname":"Spider Man","isSigned":false,"isLabeled":false,"isPrinted":false,"packages":1,"hour":0,"isBlocked":true,"hasPriority":true,"companyFk":443,"landed":"2023-05-18T22:00:00.000Z","isBoxed":false,"isDeleted":false,"zoneFk":713,"zonePrice":13,"zoneBonus":1}', NULL), (1, 18, 'select', '2000-12-27 03:40:30', 'Ticket', 45, NULL , NULL, NULL, NULL), - (1, 18, 'insert', '2000-04-10 09:40:15', 'Sale', 5689, 'Shield' , NULL, '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', NULL), + (1, 18, 'insert', '2000-04-10 09:40:15', 'Sale', 4, 'Shield' , NULL, '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', NULL), (1, 18, 'insert', '1999-05-09 10:00:00', 'Ticket', 45, 'Super Man' , NULL, '{"id":45,"clientFk":8608,"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","addressFk":48637,"isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"created":"2023-05-16T11:42:56.000Z","isBlocked":false,"hasPriority":false,"companyFk":442,"agencyModeFk":639,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}', NULL); INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) VALUES @@ -2900,6 +2915,7 @@ INSERT INTO `vn`.`profileType` (`id`, `name`) INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) VALUES ('lilium', 'development', 'http://localhost:9000/#/'), + ('hedera', 'development', 'http://localhost:9090/'), ('salix', 'development', 'http://localhost:5000/#!/'); INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`) @@ -2908,7 +2924,9 @@ INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`) INSERT INTO `vn`.`payDemDetail` (`id`, `detail`) VALUES - (1, 1); + (1, 1), + (2, 20), + (7, 1); INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk`, `businessTypeFk`) VALUES @@ -2916,8 +2934,7 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES - (1, 12), - (8, 10); + (24, 8); INSERT INTO `vn`.`deviceProductionModels` (`code`) VALUES @@ -2934,11 +2951,11 @@ INSERT INTO `vn`.`deviceProductionState` (`code`, `description`) ('retired', 'retirada'); INSERT INTO `vn`.`deviceProduction` (`imei`, `modelFk`, `macWifi`, `serialNumber`, `android_id`, `purchased`, `stateFk`, `isInScalefusion`, `description`) - VALUES - ('ime1', 'BLACKVIEW', 'macWifi1', 'serialNumber1', 'androidId0000001', util.VN_NOW(), 'active', 0, NULL), - ('ime2', 'DODGEE', 'macWifi2', 'serialNumber2', 'androidId0000002', util.VN_NOW(), 'idle', 0, NULL), - ('ime3', 'ZEBRA', 'macWifi3', 'serialNumber3', 'androidId0000003', util.VN_NOW(), 'active', 0, NULL), - ('ime4', 'BLACKVIEW', 'macWifi4', 'serialNumber4', 'androidId0000004', util.VN_NOW(), 'idle', 0, NULL); +VALUES + ('ime1', 'BLACKVIEW', 'macWifi1', 'serialNumber1', 'androidid11234567890', util.VN_NOW(), 'active', 0, NULL), + ('ime2', 'DODGEE', 'macWifi2', 'serialNumber2', 'androidid21234567890', util.VN_NOW(), 'idle', 0, NULL), + ('ime3', 'ZEBRA', 'macWifi3', 'serialNumber3', 'androidid31234567890', util.VN_NOW(), 'active', 0, NULL), + ('ime4', 'BLACKVIEW', 'macWifi4', 'serialNumber4', 'androidid41234567890', util.VN_NOW(), 'idle', 0, NULL); INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `created`) VALUES @@ -2973,9 +2990,9 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`) (2, 1, 50, 2), (3, 1, 0, 3); -INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `renewInterval`) +INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`) VALUES - (1, 21600, 300); + (1, 21600, 60, 300); INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`) VALUES @@ -2996,3 +3013,56 @@ INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `t INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) VALUES (1, 0, 0, 'marvel.com'); + +INSERT INTO vn.XDiario (id, ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, BASEEURO, SERIE, FACTURA, IVA, RECEQUIV, CLAVE, CAMBIO, DEBEME, HABERME, AUXILIAR, MONEDAUSO, TIPOOPE, NFACTICK, TERIDNIF, TERNIF, TERNOM, OPBIENES, L340, enlazado, FECHA_EX, LRECT349, empresa_id, LDIFADUAN, METAL, METALIMP, CLIENTE, METALEJE, FECHA_OP, FACTURAEX, TIPOCLAVE, TIPOEXENCI, TIPONOSUJE, TIPOFACT, TIPORECTIF, SERIE_RT, FACTU_RT, BASEIMP_RT, BASEIMP_RF, RECTIFICA, FECHA_RT, FECREGCON, enlazadoSage) + VALUES + (1, 1.0, util.VN_CURDATE(), '4300001104', NULL, 'n/fra T3333333', 8.88, NULL, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), + (2, 1.0, util.VN_CURDATE(), '2000000000', '4300001104', 'n/fra T3333333 Tony Stark', NULL, 8.07, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), + (3, 1.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T3333333 Tony Stark', NULL, 0.81, 8.07, 'T', '3333333', 10.00, NULL, NULL, NULL, NULL, NULL, '', '2', '', 1, 1, '06089160W', 'IRON MAN', 1, 1, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, 1, 1, 1, 1, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), + (4, 2.0, util.VN_CURDATE(), '4300001104', NULL, 'n/fra T4444444', 8.88, NULL, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0), + (5, 2.0, util.VN_CURDATE(), '2000000000', '4300001104', 'n/fra T4444444 Tony Stark', NULL, 8.07, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0), + (6, 2.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T4444444 Tony Stark', NULL, 0.81, 8.07, 'T', '4444444', 10.00, NULL, NULL, NULL, NULL, NULL, '', '2', '', 1, 1, '06089160W', 'IRON MAN', 1, 1, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, 1, 1, 1, 1, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0); + +INSERT INTO `vn`.`mistakeType` (`id`, `description`) + VALUES + (1, 'Incorrect quantity'); + +INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) + VALUES + (1, 'Error in VAT calculation'), + (2, 'Error in sales details'), + (3, 'Error in customer data'); + +UPDATE `vn`.`client` + SET fi='65004204V' + WHERE id=1; + +UPDATE `vn`.`worker` + SET fi='59328808D' + WHERE id=1106; + + +INSERT INTO `account`.`mailAliasAcl` (`mailAliasFk`, `roleFk`) + VALUES + (1, 1), + (2, 9), + (3, 15); + +INSERT INTO `vn`.`docuwareTablet` (`tablet`,`description`) + VALUES + ('Tablet1','Jarvis tablet'), + ('Tablet2','Avengers tablet'); + +INSERT INTO `vn`.`sms` (`id`, `senderFk`, `sender`, `destination`, `message`, `statusCode`, `status`, `created`) + VALUES (1, 66, '111111111', '0001111111111', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()), + (2, 66, '222222222', '0002222222222', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'PENDING', util.VN_CURDATE()), + (3, 66, '333333333', '0003333333333', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'ERROR', util.VN_CURDATE()), + (4, 66, '444444444', '0004444444444', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()); + +INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`) + VALUES(1, 1103, 1, NULL), + (2, 1103, 2, NULL), + (3, 1103, 3, 32), + (4, 1103, 4, 32), + (13, 1101, 1, NULL), + (14, 1101, 4, 27); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql deleted file mode 100644 index dae737466..000000000 --- a/db/dump/fixtures.sql +++ /dev/null @@ -1,3060 +0,0 @@ -CREATE ROLE 'salix'; -GRANT 'salix' TO 'root'@'%'; -SET DEFAULT ROLE 'salix' FOR 'root'@'%'; - -CREATE SCHEMA IF NOT EXISTS `vn2008`; -CREATE SCHEMA IF NOT EXISTS `tmp`; - -UPDATE `util`.`config` - SET `environment`= 'development'; - --- FOR MOCK vn.time - -DROP PROCEDURE IF EXISTS `vn`.`mockVnTime`; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`mockVnTime`() -BEGIN - - DECLARE vDate DATE; - SET vDate = '2000-01-01'; - - WHILE ( YEAR(vDate) <= 2002 ) DO - INSERT IGNORE INTO vn.`time` (dated, period, `month`, `year`, `day`, week, yearMonth, salesYear) - VALUES (vDate, CONCAT(YEAR(vDate), (WEEK(vDate)+1)), MONTH(vDate), YEAR(vDate), DAY(vDate), WEEK(vDate)+1, CONCAT(YEAR(vDate), MONTH(vDate)), YEAR(vDate)); - - SET vDate = DATE_ADD(vDate, INTERVAL 1 DAY); - END WHILE; - -END$$ -DELIMITER ; - -CALL `vn`.`mockVnTime`(); -DROP PROCEDURE IF EXISTS `vn`.`mockVnTime`; --- END MOCK vn.time - -ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1; -ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1; -ALTER TABLE `vn`.`zoneGeo` AUTO_INCREMENT = 1; -ALTER TABLE `vn`.`ticket` AUTO_INCREMENT = 1; - -INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`) - VALUES - ('DEFAULT_TOKEN', '1209600', CURDATE(), 66); - -INSERT INTO `salix`.`printConfig` (`id`, `itRecipient`, `incidencesEmail`) - VALUES - (1, 'it@gotamcity.com', 'incidences@gotamcity.com'); - -INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) - VALUES - ('1', '6'); - -INSERT INTO `vn`.`bionicConfig` (`generalInflationCoeficient`, `minimumDensityVolumetricWeight`, `verdnaturaVolumeBox`, `itemCarryBox`) - VALUES - (1.30, 167.00, 138000, 71); - -INSERT INTO `vn`.`chatConfig` (`host`, `api`) - VALUES - ('https://chat.verdnatura.es', 'https://chat.verdnatura.es/api/v1'); - -INSERT IGNORE INTO `vn`.`greugeConfig`(`id`, `freightPickUpPrice`) - VALUES - ('1', '11'); - -UPDATE `account`.`role` SET id = 100 WHERE id = 0; - -INSERT INTO `account`.`roleConfig`(`id`, `mysqlPassword`, `rolePrefix`, `userPrefix`, `userHost`, `tplUser`) - VALUES - (1, 'mysqlPassword', '$', '!', '%', 'any'); - -CALL `account`.`role_sync`; - -INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `role`,`active`,`email`, `lang`, `image`, `password`) - SELECT id, name, CONCAT(name, 'Nick'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2' - FROM `account`.`role` - ORDER BY id; - -INSERT INTO `account`.`account`(`id`) - SELECT `u`.`id` - FROM `account`.`user` `u` - JOIN `account`.`role` `r` ON `u`.`role` = `r`.`id` - WHERE `r`.`name` <> 'customer'; - -INSERT INTO `vn`.`educationLevel` (`id`, `name`) - VALUES - (1, 'ESTUDIOS PRIMARIOS COMPLETOS'), - (2, 'ENSEÑANZAS DE BACHILLERATO'); - -INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`) - SELECT id,UPPER(LPAD(role, 3, '0')), name, name, NULL - FROM `account`.`user` - WHERE `id` = 9; - -INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `bossFk`) - SELECT id,UPPER(LPAD(role, 3, '0')), name, name, 9 - FROM `account`.`user` - WHERE `id` <> 9; - -UPDATE `vn`.`worker` SET bossFk = NULL WHERE id = 20; -UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 1 OR id = 9; -UPDATE `vn`.`worker` SET bossFk = 19 WHERE id = 18; - -DELETE FROM `vn`.`worker` WHERE firstName ='customer'; - -INSERT INTO `hedera`.`tpvConfig`(`id`, `currency`, `terminal`, `transactionType`, `maxAmount`, `employeeFk`, `testUrl`) - VALUES - (1, 978, 1, 0, 2000, 9, 0); - -INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`, `image`) - VALUES - (1101, 'BruceWayne', 'Bruce Wayne', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'BruceWayne@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1102, 'PetterParker', 'Petter Parker', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'PetterParker@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1103, 'ClarkKent', 'Clark Kent', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'ClarkKent@mydomain.com', 'fr', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1104, 'TonyStark', 'Tony Stark', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'TonyStark@mydomain.com', 'es', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1105, 'MaxEisenhardt', 'Max Eisenhardt', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1106, 'DavidCharlesHaller', 'David Charles Haller', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'DavidCharlesHaller@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1107, 'HankPym', 'Hank Pym', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'HankPym@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1108, 'CharlesXavier', 'Charles Xavier', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'CharlesXavier@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1109, 'BruceBanner', 'Bruce Banner', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'BruceBanner@mydomain.com', 'en', 'e7723f0b24ff05b32ed09d95196f2f29'), - (1110, 'JessicaJones', 'Jessica Jones', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 1, 1, 'JessicaJones@mydomain.com', 'en', NULL), - (1111, 'Missing', 'Missing', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 0, NULL, 'en', NULL), - (1112, 'Trash', 'Trash', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', 2, 0, NULL, 'en', NULL); - -UPDATE account.`user` - SET passExpired = DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR) - WHERE name = 'maintenance'; - -INSERT INTO `account`.`mailAlias`(`id`, `alias`, `description`, `isPublic`) - VALUES - (1, 'general', 'General mailing list', FALSE), - (2, 'it' , 'IT department' , TRUE), - (3, 'sales' , 'Sales department' , TRUE); - -INSERT INTO `account`.`mailAliasAccount`(`mailAlias`, `account`) - VALUES - (1, 1), - (1, 18), - (3, 18), - (1, 9), - (2, 9); - -INSERT INTO `account`.`mailForward`(`account`, `forwardTo`) - VALUES - (1, 'employee@domain.local'); - - - -INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`) - VALUES - (1, 'EUR', 'Euro', 1), - (2, 'USD', 'Dollar USA', 1.4), - (3, 'GBP', 'Libra', 1), - (4, 'JPY', 'Yen Japones', 1); - -INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`) - VALUES - (1, 'España', 1, 'ES', 1, 24, 4, 0, 1), - (2, 'Italia', 1, 'IT', 1, 27, 4, 0, 1), - (3, 'Alemania', 1, 'DE', 1, 22, 4, 0, 1), - (4, 'Rumania', 1, 'RO', 1, 24, 4, 0, 1), - (5, 'Holanda', 1, 'NL', 1, 18, 4, 0, 1), - (8, 'Portugal', 1, 'PT', 1, 27, 4, 0, 1), - (13,'Ecuador', 0, 'EC', 1, 24, 2, 1, 2), - (19,'Francia', 1, 'FR', 1, 27, 4, 0, 1), - (30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2); - -INSERT INTO `vn`.`warehouseAlias`(`id`, `name`) - VALUES - (1, 'Main Warehouse'), - (2, 'Gotham'); - -INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `aliasFk`, `countryFk`, `hasProduction`) - VALUES - (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 2, 1, 1), - (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 2, 13, 1), - (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), - (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), - (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 2, 1, 1), - (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 2, 1, 0), - (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 2, 1, 0); - -INSERT INTO `vn`.`sectorType` (id,description) - VALUES (1,'First type'); - -INSERT INTO `vn`.`sector`(`id`, `description`, `warehouseFk`, `code`, `typeFk`) - VALUES - (1, 'First sector', 1, 'FIRST', 1), - (2, 'Second sector', 2, 'SECOND',1); - -INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAddress`) - VALUES - (1, 'printer1', 'path1', 0, 1 , NULL), - (2, 'printer2', 'path2', 1, 1 , NULL), - (4, 'printer4', 'path4', 0, NULL, '10.1.10.4'); - -UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1; - - -INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`,`bossFk`, `phone`) - VALUES - (1106, 'LGN', 'David Charles', 'Haller', 19, 432978106), - (1107, 'ANT', 'Hank' , 'Pym' , 19, 432978107), - (1108, 'DCX', 'Charles' , 'Xavier', 19, 432978108), - (1109, 'HLK', 'Bruce' , 'Banner', 19, 432978109), - (1110, 'JJJ', 'Jessica' , 'Jones' , 19, 432978110); - -INSERT INTO `vn`.`parking` (`id`, `column`, `row`, `sectorFk`, `code`, `pickingOrder`) - VALUES - ('1', 700, '01', 1, '700-01', 70001), - ('2', 700, '02', 2, '700-02', 70002), - ('3', 100, '01', 1, '100-01', 1), - (32397, 100, '02', 1, 'A-47-1', 1165), - (34831, 200, '01', 1, 'K-26-2', 20220), - (34965, 200, '02', 2, 'L-08-4', 21800), - (39096, 200, '03', 2, 'LR-02-3', 99999); - -INSERT INTO `vn`.`shelving` (`code`, `parkingFk`, `isPrinted`, `priority`, `userFk`, `isRecyclable`) - VALUES - ('AA6', 34965, 1, 0, NULL, 0), - ('AA7', 34965, 1, 0, NULL, 0), - ('AA8', 34965, 1, 0, NULL, 0), - ('AA9', NULL, 1, 0, NULL, 0), - ('AAA', NULL, 0, 0, 1109, 1), - ('AAB', NULL, 0, 0, 1109, 1), - ('AAC', NULL, 1, 99, 1109, 1), - ('AAD', NULL, 0, 0, 1109, 1), - ('AAE', 39096, 1, 0, 1109, 1), - ('AAF', 34831, 1, 0, 1109, 1), - ('GVC', 1, 0, 1, 1106, 1), - ('HEJ', 2, 0, 1, 1106, 1), - ('UXN', 1, 0, 1, 1106, 1); - -INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`code`, `maxAmount`, `daysInFuture`) - VALUES - (1, 'CC and credit policies', 'Transfers', 'wireTransfer', NULL, 1), - (2, 'Cash', 'Cash', 'cash', 1000, 0), - (3, 'Credit card', 'Credit Card', 'creditCard', NULL, 0), - (4, 'Finalcial lines', NULL, NULL, NULL, 0), - (5, 'Other products', NULL, NULL, NULL, 0), - (6, 'Loans', NULL, NULL, NULL, 0), - (7, 'Leasing', NULL, NULL, NULL, 0), - (8, 'Compensations', 'Compensations', 'compensation', NULL, 0); - -INSERT INTO `vn`.`bankEntity`(`id`, `countryFk`, `name`, `bic`) - VALUES - (128, 1, 'The Best Bank', 'BBKKESMMMMMM'), - (2100, 1, 'Caixa Bank', 'CAIXESBB'); - -INSERT INTO `vn`.`accounting`(`id`, `bank`, `account`, `accountingTypeFk`, `entityFk`, `isActive`, `currencyFk`, `code`) - VALUES - (1, 'Pay on receipt', '5720000001', 3, 128, 1, 1, 'payOnReceipt'), - (2, 'Cash', '5700000001', 2, 128, 1, 1, 'cash'), - (3, 'Compensation', '4000000000', 8, 128, 1, 1, 'compensation'), - (4, 'Transfers', '4000000001', 1, 128, 1, 1, 'transfers'), - (3117, 'Caixa Rural d''Algemesi', '5720000000', 8, 2100, 1, 1, 'cra'); - -INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`) - VALUES - (1, 'AGENCY', 'Agencia'), - (2, 'DELIVERY', 'Reparto'), - (3, 'PICKUP', 'Recogida'), - (4, 'OTHER', 'Otros'); - -INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `warehouseAliasFk`) - VALUES - (1, 'inhouse pickup' , 1, 1), - (2, 'Super-Man delivery' , 1, 1), - (3, 'Teleportation device' , 1, 1), - (4, 'Entanglement' , 1, 1), - (5, 'Quantum break device' , 1, 1), - (6, 'Walking' , 1, 1), - (7, 'Gotham247' , 1, 1), - (8, 'Gotham247Expensive' , 1, 1), - (9, 'Refund' , 1, 1), - (10, 'Other agency' , 1, 1); - -UPDATE `vn`.`agencyMode` SET `id` = 1 WHERE `name` = 'inhouse pickup'; -UPDATE `vn`.`agencyMode` SET `id` = 2 WHERE `name` = 'Super-Man delivery'; -UPDATE `vn`.`agencyMode` SET `id` = 3 WHERE `name` = 'Teleportation device'; -UPDATE `vn`.`agencyMode` SET `id` = 4 WHERE `name` = 'Entanglement'; -UPDATE `vn`.`agencyMode` SET `id` = 5 WHERE `name` = 'Quantum break device'; -UPDATE `vn`.`agencyMode` SET `id` = 6 WHERE `name` = 'Walking'; -UPDATE `vn`.`agencyMode` SET `id` = 7 WHERE `name` = 'Gotham247'; -UPDATE `vn`.`agencyMode` SET `id` = 8 WHERE `name` = 'Gotham247Expensive'; -UPDATE `vn`.`agencyMode` SET `id` = 23 WHERE `name` = 'Refund'; -UPDATE `vn`.`agencyMode` SET `id` = 10 WHERE `name` = 'Other agency'; - -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 3 WHERE `id` = 1; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 2; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 3; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 4; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 5; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 2 WHERE `id` = 6; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 7; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23; -UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10; - -UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com'; - -UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; - -INSERT INTO `vn`.`payMethod`(`id`,`code`, `name`, `graceDays`, `outstandingDebt`, `isIbanRequiredForClients`, `isIbanRequiredForSuppliers`, `hasVerified`) - VALUES - (1, NULL, 'PayMethod one', 0, 001, 0, 0, 0), - (2, NULL, 'PayMethod two', 10, 001, 0, 0, 1), - (3, 'compensation', 'PayMethod three', 0, 001, 0, 0, 0), - (4, NULL, 'PayMethod with IBAN', 0, 001, 1, 0, 0), - (5, NULL, 'PayMethod five', 10, 001, 0, 0, 0), - (8,'wireTransfer', 'WireTransfer', 5, 001, 1, 1, 0); - -INSERT INTO `vn`.`payDem`(`id`, `payDem`) - VALUES - (1, 10), - (2, 20), - (7, 0); - -INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`) - VALUES - (1, 'Autonomy one', 1), - (2, 'Autonomy two', 1), - (3, 'Autonomy three', 2), - (4, 'Autonomy four', 13); - - -INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `autonomyFk`, `warehouseFk`) - VALUES - (1, 'Province one', 1, 1, NULL), - (2, 'Province two', 1, 1, NULL), - (3, 'Province three', 30, 2, NULL), - (4, 'Province four', 2, 3, NULL), - (5, 'Province five', 13, 4, NULL); - -INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) - VALUES - (1, 'Valencia', 1), - (2, 'Gotham', 1), - (3, 'Algemesi', 1), - (4, 'Alzira', 1), - (5, 'Quito', 5); - -INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) - VALUES - ('46000', 1, 6), - ('46460', 2, 6), - ('46680', 3, 6), - ('46600', 4, 7), - ('EC170150', 5, 8); - -INSERT INTO `vn`.`clientType`(`id`, `code`, `type`) - VALUES - (1, 'normal', 'Normal'), - (2, 'internalUse', 'Autoconsumo'), - (3, 'handMaking', 'Confección'), - (4, 'loses', 'Mermas'); - -INSERT INTO `vn`.`cplusTerIdNif`(`id`, `description`) - VALUES - (1, 'NIF'); - -INSERT INTO `vn`.`contactChannel`(`id`, `name`) - VALUES - (1, 'Rumors on the streets'), - (2, 'Metropolis newspaper'), - (3, 'Daily Bugle'), - (4, 'GCN Channel'), - (5, 'The Newspaper'); - -INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`, `hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`, `businessTypeFk`,`typeFk`) - VALUES - (1101, 'Bruce Wayne', '84612325V', 'BATMAN', 'Alfred', '1007 MOUNTAIN DRIVE, GOTHAM', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1102, 'Petter Parker', '87945234L', 'SPIDER MAN', 'Aunt May', '20 INGRAM STREET, QUEENS, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1103, 'Clark Kent', '06815934E', 'SUPER MAN', 'lois lane', '344 CLINTON STREET, APARTAMENT 3-D', 'Gotham', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 0, 19, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1104, 'Tony Stark', '06089160W', 'IRON MAN', 'Pepper Potts', '10880 MALIBU POINT, 90265', 'Gotham', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 2, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1105, 'Max Eisenhardt', '251628698', 'MAGNETO', 'Rogue', 'UNKNOWN WHEREABOUTS', 'Gotham', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 3, 1, 300, 8, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1, 'florist','normal'), - (1106, 'DavidCharlesHaller', '53136686Q', 'LEGION', 'Charles Xavier', 'CITY OF NEW YORK, NEW YORK, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), - (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1, 'florist','normal'), - (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1, 'florist','normal'), - (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist','normal'), - (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist','normal'), - (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'), - (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, 'others','loses'); - -INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 - FROM `account`.`role` `r` - WHERE `r`.`hasLogin` = 1; - -INSERT INTO `vn`.`clientManaCache`(`clientFk`, `mana`, `dated`) - VALUES - (1101, 50, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (1102, 100, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (1103, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (1104, -30, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)); - -INSERT INTO `vn`.`mandateType`(`id`, `name`) - VALUES - (1, 'B2B'), - (2, 'CORE'), - (3, 'LCR'); - -INSERT INTO `vn`.`clientConfig`(`id`, `riskTolerance`, `maxCreditRows`, `maxPriceIncreasingRatio`, `riskScope`, `defaultPayMethodFk`, `defaultDueDay`, `defaultCredit`, `defaultIsTaxDataChecked`, `defaultHasCoreVnl`, `defaultMandateTypeFk`) - VALUES - (1, 200, 10, 0.25, 2, 4, 5, 300.00, 1, 1, 2); - - -INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`, `isDefaultAddress`) - VALUES - (1, 'Bruce Wayne', '1007 Mountain Drive, Gotham', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 1), - (2, 'Petter Parker', '20 Ingram Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 1), - (3, 'Clark Kent', '344 Clinton Street', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 1), - (4, 'Tony Stark', '10880 Malibu Point', 'Gotham', 46460, 1, 1111111111, 222222222, 1 , 1104, 2, NULL, NULL, 0, 1), - (5, 'Max Eisenhardt', 'Unknown Whereabouts', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 1), - (6, 'DavidCharlesHaller', 'Evil hideout', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 1), - (7, 'Hank Pym', 'Anthill', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 1), - (8, 'Charles Xavier', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 1), - (9, 'Bruce Banner', 'Somewhere in New York', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 1), - (10, 'Jessica Jones', 'NYCC 2015 Poster', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 1), - (11, 'Missing', 'The space', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1111, 10, NULL, NULL, 0, 1), - (12, 'Trash', 'New York city', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1112, 10, NULL, NULL, 0, 1), - (101, 'Somewhere in Thailand', 'address 01', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (102, 'Somewhere in Poland', 'address 02', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (103, 'Somewhere in Japan', 'address 03', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (104, 'Somewhere in Spain', 'address 04', 'Gotham', 46460, 1, 3333333333, 444444444, 1, 1109, 2, NULL, NULL, 0, 0), - (105, 'Somewhere in Potugal', 'address 05', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (106, 'Somewhere in UK', 'address 06', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (107, 'Somewhere in Valencia', 'address 07', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (108, 'Somewhere in Gotham', 'address 08', 'Gotham', 46460, 1, 5555555555, 666666666, 1, 1109, 2, NULL, NULL, 0, 0), - (109, 'Somewhere in London', 'address 09', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (110, 'Somewhere in Algemesi', 'address 10', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (111, 'Somewhere in Carlet', 'address 11', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (112, 'Somewhere in Campanar', 'address 12', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (113, 'Somewhere in Malilla', 'address 13', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (114, 'Somewhere in France', 'address 14', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (115, 'Somewhere in Birmingham', 'address 15', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (116, 'Somewhere in Scotland', 'address 16', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (117, 'Somewhere in nowhere', 'address 17', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (118, 'Somewhere over the rainbow', 'address 18', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (119, 'Somewhere in Alberic', 'address 19', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (120, 'Somewhere in Montortal', 'address 20', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1109, 2, NULL, NULL, 0, 0), - (121, 'the bat cave', 'address 21', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1101, 2, NULL, NULL, 0, 0), - (122, 'NY roofs', 'address 22', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1102, 2, NULL, NULL, 0, 0), - (123, 'The phone box', 'address 23', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1103, 2, NULL, NULL, 0, 0), - (124, 'Stark tower Gotham', 'address 24', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1104, 2, NULL, NULL, 0, 0), - (125, 'The plastic cell', 'address 25', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1105, 2, NULL, NULL, 0, 0), - (126, 'Many places', 'address 26', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1106, 2, NULL, NULL, 0, 0), - (127, 'Your pocket', 'address 27', 'Gotham', 46460, 1, 1111111111, 222222222, 1, 1107, 2, NULL, NULL, 0, 0), - (128, 'Cerebro', 'address 28', 'Gotham', 46460, 5, 1111111111, 222222222, 1, 1108, 2, NULL, NULL, 0, 0), - (129, 'Luke Cages Bar', 'address 29', 'Gotham', 'EC170150', 1, 1111111111, 222222222, 1, 1110, 2, NULL, NULL, 0, 0), - (130, 'Non valid address', 'address 30', 'Gotham', 46460, 1, 1111111111, 222222222, 0, 1101, 2, NULL, NULL, 0, 0); - -INSERT INTO `vn`.`address`( `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `isActive`, `clientFk`, `agencyModeFk`, `isDefaultAddress`) - SELECT name, CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, 1, id, 2, 1 - FROM `account`.`role` `r` - WHERE `r`.`hasLogin` = 1; - -UPDATE `vn`.`client` SET defaultAddressFk = 1 WHERE id = 1101; -UPDATE `vn`.`client` SET defaultAddressFk = 2 WHERE id = 1102; -UPDATE `vn`.`client` SET defaultAddressFk = 3 WHERE id = 1103; -UPDATE `vn`.`client` SET defaultAddressFk = 4 WHERE id = 1104; -UPDATE `vn`.`client` SET defaultAddressFk = 5 WHERE id = 1105; -UPDATE `vn`.`client` SET defaultAddressFk = 6 WHERE id = 1106; -UPDATE `vn`.`client` SET defaultAddressFk = 7 WHERE id = 1107; -UPDATE `vn`.`client` SET defaultAddressFk = 8 WHERE id = 1108; -UPDATE `vn`.`client` SET defaultAddressFk = 9 WHERE id = 1109; -UPDATE `vn`.`client` SET defaultAddressFk = 10 WHERE id = 1110; -UPDATE `vn`.`client` SET defaultAddressFk = 11 WHERE id = 200; -UPDATE `vn`.`client` SET defaultAddressFk = 12 WHERE id = 400; - -DROP TEMPORARY TABLE IF EXISTS tmp.address; - -CREATE TEMPORARY TABLE tmp.address - SELECT * FROM `vn`.`address`; - - UPDATE `vn`.`client` `c` - JOIN `tmp`.`address` `a` ON `a`.`clientFk` = `c`.`id` - SET `c`.`defaultAddressFk` = `a`.`id` - WHERE `defaultAddressFk` IS NULL; -DROP TEMPORARY TABLE tmp.address; - -INSERT INTO `vn`.`clientCredit`(`clientFk`, `workerFk`, `amount`, `created`) - VALUES - (1101, 5, 300, DATE_ADD(util.VN_CURDATE(), INTERVAL -11 MONTH)), - (1101, 5, 900, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 MONTH)), - (1101, 5, 800, DATE_ADD(util.VN_CURDATE(), INTERVAL -9 MONTH)), - (1101, 5, 700, DATE_ADD(util.VN_CURDATE(), INTERVAL -8 MONTH)), - (1101, 5, 600, DATE_ADD(util.VN_CURDATE(), INTERVAL -7 MONTH)), - (1101, 5, 500, DATE_ADD(util.VN_CURDATE(), INTERVAL -6 MONTH)), - (1101, 5, 400, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 MONTH)), - (1101, 9, 300, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), - (1101, 9, 200, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), - (1101, 9, 100, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), - (1101, 9, 50 , DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (1102, 9, 800, util.VN_CURDATE()), - (1104, 9, 90 , util.VN_CURDATE()), - (1105, 9, 90 , util.VN_CURDATE()); - -INSERT INTO `vn`.`roleCreditLimit`(`id`, `maxAmount`, `roleFk`) - VALUES - (1, 9999999, 20), - (2, 10000, 21), - (3, 600, 13); - -INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`) - VALUES - (1, 1101, 1, 'Madness, as you know, is like gravity, all it takes is a little push', util.VN_CURDATE()), - (2, 1102, 1, 'With great power, comes great responsibility', util.VN_CURDATE()), - (3, 1103, 3, 'this is a job for Super-Man!', util.VN_CURDATE()), - (4, 1104, 3, 'yes... I am Iron-Man', util.VN_CURDATE()), - (5, 1105, 5, 'They do understand. Our mutant powers make us superior', util.VN_CURDATE()), - (6, 1106, 5, 'My name is Legion, for we are many!', util.VN_CURDATE()), - (7, 1107, 9, 'I think our first move should be calling the Avengers..', util.VN_CURDATE()), - (8, 1108, 9, 'Just because someone stumbles and loses their path, does not mean they are lost forever.', util.VN_CURDATE()), - (9, 1109, 18, 'HULK SMASH! ...', util.VN_CURDATE()), - (10, 1110, 18, 'They say everyone is born a hero. But if you let it, life will push you over the line until you are the villain.', util.VN_CURDATE()); - -INSERT INTO `vn`.`observationType`(`id`,`description`, `code`) - VALUES - (1, 'ItemPicker', 'itemPicker'), - (2, 'Packager', 'packager'), - (3, 'Delivery', 'delivery'), - (4, 'SalesPerson', 'salesPerson'), - (5, 'Administrative', 'administrative'), - (6, 'Weight', 'weight'), - (7, 'InvoiceOut', 'invoiceOut'); - -INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) - VALUES - (1, 121, 1, 'under the floor'), - (2, 121, 2, 'wears leather and goes out at night'), - (3, 121, 3, 'care with the dog'), - (5, 122, 5, 'Delivery after 10am'); - -INSERT INTO `vn`.`creditClassification`(`id`, `client`, `dateStart`, `dateEnd`) - VALUES - (1, 1101, util.VN_CURDATE(), util.VN_CURDATE()), - (2, 1102, util.VN_CURDATE(), util.VN_CURDATE()), - (3, 1103, util.VN_CURDATE(), util.VN_CURDATE()), - (4, 1104, util.VN_CURDATE(), util.VN_CURDATE()), - (5, 1105, util.VN_CURDATE(), util.VN_CURDATE()); - -INSERT INTO `vn`.`creditInsurance`(`id`, `creditClassificationFk`, `credit`, `creationDate`, `grade`) - VALUES - (1, 1, 3000, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL), - (2, 2, 6000, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL), - (3, 3, 10000, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL); - -INSERT INTO `vn`.`companyGroup`(`id`, `code`) - VALUES - (1, 'wayneIndustries'), - (2, 'verdnatura'); - -INSERT INTO `vn`.`supplierActivity`(`code`, `name`) - VALUES - ('animals', 'Food and complements for pets'), - ('complements', 'Other complements'), - ('flowerPlants', 'Wholesale of flowers and plants'), - ('vegetablesFruits', 'Fruit and vegetable trade'); - -INSERT INTO `vn`.`supplier`(`id`, `name`, `nickname`,`account`,`countryFk`,`nif`, `commission`, `created`, `isActive`, `street`, `city`, `provinceFk`, `postCode`, `payMethodFk`, `payDemFk`, `payDay`, `taxTypeSageFk`, `withholdingSageFk`, `transactionTypeSageFk`, `workerFk`, `supplierActivityFk`, `isPayMethodChecked`, `healthRegister`) - VALUES - (1, 'Plants SL', 'Plants nick', 4100000001, 1, '06089160W', 0, util.VN_CURDATE(), 1, 'supplier address 1', 'PONTEVEDRA', 1, 15214, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), - (2, 'Farmer King', 'The farmer', 4000020002, 1, '87945234L', 0, util.VN_CURDATE(), 1, 'supplier address 2', 'GOTHAM', 2, 43022, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), - (69, 'Packaging', 'Packaging nick', 4100000069, 1, '94935005K', 0, util.VN_CURDATE(), 1, 'supplier address 5', 'ASGARD', 3, 46600, 1, 1, 15, 4, 1, 1, 18, 'flowerPlants', 1, '400664487V'), - (442, 'Verdnatura Levante SL', 'Verdnatura', 5115000442, 1, '06815934E', 0, util.VN_CURDATE(), 1, 'supplier address 3', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), - (567, 'Holland', 'Holland nick', 4000020567, 1, '14364089Z', 0, util.VN_CURDATE(), 1, 'supplier address 6', 'ASGARD', 3, 46600, 1, 2, 10, 93, 2, 8, 18, 'animals', 1, '400664487V'), - (791, 'Bros SL', 'Bros nick', 5115000791, 1, '37718083S', 0, util.VN_CURDATE(), 1, 'supplier address 7', 'ASGARD', 3, 46600, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'), - (1381, 'Ornamentales', 'Ornamentales', 7185001381, 1, '07972486L', 0, util.VN_CURDATE(), 1, 'supplier address 4', 'GOTHAM', 1, 43022, 1, 2, 15, 6, 9, 3, 18, 'complements', 1, '400664487V'); - -INSERT INTO `vn`.`supplierAddress`(`id`, `supplierFk`, `nickname`, `street`, `provinceFk`, `postalCode`, `city`, `phone`, `mobile`) - VALUES - (1, 1, 'Ace Chemicals', 'The Midtown', 1, '46000', 'Gotham', '111111111', '222222222'), - (2, 1, 'Arkham Asylum', 'Grand Avenue', 1, '46000', 'Gotham', '111111111', '222222222'), - (3, 2, 'Wayne Tower', 'Grand Avenue', 1, '46000', 'Gotham', '111111111', '222222222'), - (4, 2, 'Bank of Gotham', 'Founders Island', 1, '46000', 'Gotham', '111111111', '222222222'), - (5, 442, 'GCR building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'), - (6, 442, 'The Gotham Tonight building', 'Bristol district', 1, '46000', 'Gotham', '111111111', '222222222'); - -INSERT INTO `vn`.`supplierContact`(`id`, `supplierFk`, `phone`, `mobile`, `email`, `observation`, `name`) - VALUES - (1, 1, 123121212, 654789123, 'supplier1@email.es', 'observation1', 'the boss'), - (2, 1, 987456132, NULL, NULL, NULL, 'the salesperson'), - (3, 2, 321654987, NULL, 'supplier2@email.es', NULL, NULL), - (4, 442, 321654987, NULL, NULL, 'observation442', NULL); - -INSERT INTO `vn`.`supplierAccount`(`id`, `supplierFk`, `iban`, `bankEntityFk`) - VALUES - (241, 442, 'ES111122333344111122221111', 128); - -INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `sage200Company`, `expired`, `companyGroupFk`, `phytosanitary` , `clientFk`) - VALUES - (69 , 'CCs', NULL, 30, NULL, 0, NULL, 1, NULL , NULL), - (442 , 'VNL', 241, 30, 2 , 1, NULL, 2, 'VNL Company - Plant passport' , 1101), - (567 , 'VNH', NULL, 30, NULL, 4, NULL, 1, 'VNH Company - Plant passport' , NULL), - (791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', 1, NULL , NULL), - (1381, 'ORN', NULL, 30, NULL, 7, NULL, 1, 'ORN Company - Plant passport' , NULL); - -INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) - VALUES - ('CEE', 1, 10), - ('EQU', 0, 1), - ('NATIONAL', 0, 1), - ('WORLD', 2, 15); - -INSERT INTO vn.invoiceOutConfig - SET parallelism = 8; - -INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) - VALUES - ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), - ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), - ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), - ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'quick'), - ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), - ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); - -INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) - VALUES - (1, 'T', 1026.24, util.VN_CURDATE(), 1101, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (2, 'T', 121.36, util.VN_CURDATE(), 1102, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (3, 'T', 8.88, util.VN_CURDATE(), 1103, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (4, 'T', 8.88, util.VN_CURDATE(), 1104, util.VN_CURDATE(), 442, util.VN_CURDATE(), util.VN_CURDATE(), 1, 0), - (5, 'A', 8.88, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 0); - -UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; -UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2; -UPDATE `vn`.`invoiceOut` SET ref = 'T3333333' WHERE id = 3; -UPDATE `vn`.`invoiceOut` SET ref = 'T4444444' WHERE id = 4; -UPDATE `vn`.`invoiceOut` SET ref = 'A1111111' WHERE id = 5; - -INSERT INTO `vn`.`invoiceOutTax` (`invoiceOutFk`, `taxableBase`, `vat`, `pgcFk`) - VALUES - (1, 895.76, 89.58, 4722000010), - (1, 33.80, 7.10, 4722000021), - (2, 110.33, 11.03, 4770000010), - (3, 8.07, 0.81, 4770000010), - (4, 8.07, 0.81, 4770000010), - (5, 8.07, 0.81, 4770000010); - -INSERT INTO `vn`.`expense`(`id`, `name`, `isWithheld`) - VALUES - (2000000000, 'Inmovilizado pendiente', 0), - (2000000001, 'Compra de bienes de inmovilizado', 0), - (4751000000, 'Retenciones', 1), - (4751000001, 'Retencion', 0), - (6210000567, 'Alquiler VNH', 0), - (6240000000, 'Transportes de ventas rutas', 0), - (7001000000, 'Mercaderia', 0), - (7050000000, 'Prestacion de servicios', 1); - - -INSERT INTO `vn`.`invoiceOutExpense`(`id`, `invoiceOutFk`, `amount`, `expenseFk`, `created`) - VALUES - (1, 1, 813.06, 2000000000, util.VN_CURDATE()), - (2, 1, 33.80, 4751000000, util.VN_CURDATE()), - (3, 1, 70.70, 6210000567, util.VN_CURDATE()), - (4, 2, 110.33, 2000000000, util.VN_CURDATE()), - (5, 3, 8.07, 2000000000, util.VN_CURDATE()), - (6, 4, 8.07, 2000000000, util.VN_CURDATE()), - (7, 5, 8.07, 2000000000, util.VN_CURDATE()); - -INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `itemMaxSize`) - VALUES - (1, 'Zone pickup A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), - (2, 'Zone pickup B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), - (3, 'Zone 247 A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), - (4, 'Zone 247 B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100), - (5, 'Zone expensive A', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), - (6, 'Zone expensive B', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100), - (7, 'Zone refund', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 1, 0, 100), - (8, 'Zone others', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 1, 0, 100), - (9, 'Zone superMan', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 1, 0, 100), - (10, 'Zone teleportation', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 1, 0, 100), - (11, 'Zone pickup C', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 1, 0, 100), - (12, 'Zone entanglement', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 1, 0, 100), - (13, 'Zone quantum break', CONCAT(util.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 1, 0, 100); - - -INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) - VALUES - (1, 1, 1), - (2, 2, 2), - (3, 3, 1), - (4, 4, 2), - (5, 5, 1), - (6, 6, 2), - (7, 7, 1), - (8, 8, 1), - (9, 9, 1), - (10, 10, 3), - (11, 11, 5), - (12, 12, 4), - (13, 13, 5); - -INSERT INTO `vn`.`zoneClosure` (`zoneFk`, `dated`, `hour`) - VALUES - (1, util.VN_CURDATE(), '23:59'), - (2, util.VN_CURDATE(), '23:59'), - (3, util.VN_CURDATE(), '23:59'), - (4, util.VN_CURDATE(), '23:59'), - (5, util.VN_CURDATE(), '23:59'), - (6, util.VN_CURDATE(), '23:59'), - (7, util.VN_CURDATE(), '23:59'), - (8, util.VN_CURDATE(), '23:59'), - (9, util.VN_CURDATE(), '23:59'), - (10, util.VN_CURDATE(), '23:59'), - (11, util.VN_CURDATE(), '23:59'), - (12, util.VN_CURDATE(), '23:59'), - (13, util.VN_CURDATE(), '23:59'); - -INSERT INTO `vn`.`zoneConfig` (`scope`) VALUES ('1'); - -INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`) - VALUES - (1, '1899-12-30 12:15:00', 56, util.VN_CURDATE(), 1, 1, 'first route', 1.8, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1), - (2, '1899-12-30 13:20:00', 56, util.VN_CURDATE(), 1, 2, 'second route', 0.2, 20, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 9), - (3, '1899-12-30 14:30:00', 56, util.VN_CURDATE(), 2, 3, 'third route', 0.5, 30, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 10), - (4, '1899-12-30 15:45:00', 56, util.VN_CURDATE(), 3, 4, 'fourth route', 0, 40, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 12), - (5, '1899-12-30 16:00:00', 56, util.VN_CURDATE(), 4, 5, 'fifth route', 0.1, 50, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 13), - (6, NULL, 57, util.VN_CURDATE(), 5, 7, 'sixth route', 1.7, 60, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 3), - (7, NULL, 57, util.VN_CURDATE(), 6, 8, 'seventh route', 0, 70, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 5); - -INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `landed`, `clientFk`,`nickname`, `addressFk`, `refFk`, `isDeleted`, `zoneFk`, `zonePrice`, `zoneBonus`, `created`, `weight`) - VALUES - (1 , 3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 121, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1), - (2 , 1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Bat cave', 1, NULL, 0, 1, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2), - (3 , 1, 7, 1, 6, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL), - (4 , 3, 2, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 9, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL), - (5 , 3, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 'Stark tower', 124, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL), - (6 , 1, 3, 3, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 10, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL), - (7 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Mountain Drive Gotham', 1, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (8 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'Bat cave', 121, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (9 , NULL, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 'Stark tower', 124, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (10, 1, 1, 5, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'Ingram Street', 2, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (11, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (12, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (13, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (14, 1, 2, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1104, 'Malibu Point', 4, NULL, 0, 9, 5, 1, util.VN_CURDATE(), NULL), - (15, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 'An incredibly long alias for testing purposes', 125, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (16, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (17, 1, 7, 2, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 'Many Places', 126, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL), - (18, 1, 4, 4, 4, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 'Cerebro', 128, NULL, 0, 12, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +12 HOUR), NULL), - (19, 1, 5, 5, NULL, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 1, NULL, 5, 1, util.VN_CURDATE(), NULL), - (20, 1, 5, 5, 3, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Thailand', 129, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), - (21, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Holland', 102, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), - (22, NULL, 5, 5, 5, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 'Somewhere in Japan', 103, NULL, 0, 13, 5, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), NULL), - (23, NULL, 8, 1, 7, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 'address 21', 121, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), - (24 ,NULL, 8, 1, 7, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 5, 5, 1, util.VN_CURDATE(), NULL), - (25 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Bruce Wayne', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (26 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'An incredibly long alias for testing purposes', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (27 ,NULL, 8, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1101, 'Wolverine', 1, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (28, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (29, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (30, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL), - (32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL); - -INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) - VALUES - (1, 11, 1, 'ready'), - (2, 2, 2, 'do it fast please'), - (3, 3, 5, 'Faster faster fasteeeeeer!!!'), - (4, 4, 5, 'Deliver before 8am'), - (5, 13, 5, 'You can run from the disappointments you are trying to forget. But its only when you embrace your past that you truly move forward. Maybe I never get to go home again, but I found my way there. And I am glad I did.'), - (6, 14, 5, 'Careful, armed warhead'), - (7, 23, 1, 'under the floor'), - (8, 23, 2, 'wears leather and goes out at night'), - (9, 23, 5, 'care with the dog'), - (10, 23, 4, 'Reclama ticket: 8'), - (11, 24, 4, 'Reclama ticket: 7'), - (12, 11, 3, 'Delivery after 10am'), - (13, 1, 7, 'observation of ticket one'), - (14, 2, 7, 'observation of ticket two'); - --- FIX for state hours on local, inter_afterInsert --- UPDATE vncontrol.inter SET odbc_date = DATE_ADD(util.VN_CURDATE(), INTERVAL -10 SECOND); - -INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `userFk`, `created`) - VALUES - (1, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), - (2, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), - (3, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -2 MONTH)), - (4, 16, 5 , DATE_ADD(util.VN_NOW(), INTERVAL -3 MONTH)), - (5, 16, 18, DATE_ADD(util.VN_NOW(), INTERVAL -4 MONTH)), - (6, 16, 18, DATE_ADD(util.VN_NOW(), INTERVAL -1 MONTH)), - (7, 10, 18, util.VN_NOW()), - (8, 5, 19, util.VN_NOW()), - (9, 5, 19, util.VN_NOW()), - (10, 5, 19, util.VN_NOW()), - (11, 3, 19, util.VN_NOW()), - (12, 3, 19, util.VN_NOW()), - (13, 3, 19, util.VN_NOW()), - (14, 3, 19, util.VN_NOW()), - (15, 2, 19, util.VN_NOW()), - (16, 3, 19, util.VN_NOW()), - (17, 2, 19, util.VN_NOW()), - (18, 2, 19, util.VN_NOW()), - (19, 2, 19, util.VN_NOW()), - (20, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), - (21, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), - (22, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), - (23, 16, 21, util.VN_NOW()), - (24, 16, 21, util.VN_NOW()); - -INSERT INTO `vn`.`deliveryPoint` (`id`, `name`, `ubication`) - VALUES - (1, 'Gotham','1007 Mountain Drive, Gotham'); - -INSERT INTO `vn`.`vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `companyFk`, `warehouseFk`, `description`, `m3`, `isActive`, `deliveryPointFk`) - VALUES - (1, '3333-BAT', 'WAYNE INDUSTRIES', 'BATMOBILE', 442, 1, 'The ultimate war machine', 50, 1, 1), - (2, '1111-IMK', 'STARK INDUSTRIES', 'MARK-III', 442, 1, 'Iron-Man Heavy Armor MARK-III', 18, 1, 1), - (3, '2222-IMK', 'STARK INDUSTRIES', 'MARK-VI', 442, 1, 'Iron-Man Heavy Armor MARK-VI', 16, 1, 1), - (4, '3333-IMK', 'STARK INDUSTRIES', 'MARK-VII', 442, 1, 'Iron-Man Heavy Armor MARK-VII', 14, 1, 1), - (5, '4444-IMK', 'STARK INDUSTRIES', 'MARK-XLII', 442, 1, 'Iron-Man Heavy Armor MARK-XLII', 13, 1, 1), - (6, '5555-IMK', 'STARK INDUSTRIES', 'MARK-XLV', 442, 1, 'Iron-Man Heavy Armor MARK-XLV', 12, 0, 1); - -INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`, `inventoried`) - VALUES - (1, 'beta-server', 'nightmare@mydomain.com', '200', DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH)); - - -INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) - VALUES - (1, 'Diff', 'diff'), - (2, 'Recover', 'recover'), - (3, 'Mana', 'mana'), - (4, 'Reclaim', 'reclaim'), - (5, 'Heritage', 'heritage'), - (6, 'Miscellaneous', 'miscellaneous'), - (7, 'Freight Pickup', 'freightPickUp'); - -INSERT INTO `vn`.`greuge`(`id`, `clientFk`, `description`, `amount`, `shipped`, `created`, `greugeTypeFk`, `ticketFk`) - VALUES - (1, 1101, 'some diff charges', -19.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 1, 1), - (2, 1101, 'more diff charges', 60, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 2, 1), - (3, 1101, 'even more! diff charges', -9.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 3, 1), - (4, 1101, 'insane diff charges', 60, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 4, 1), - (5, 1101, 'gargantuous diff charges', -9.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 5, 1), - (6, 1101, 'diff charges', 88.30, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 6, 1), - (7, 1101, 'unaffordable diff charges', -39.12, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 1, 1), - (8, 1101, 'some recovery charges', 29.35, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 2, 1), - (9, 1101, 'some manna charges', -9.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 3, 1), - (10, 1101, 'some claim charges', 13.13, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 4, 1), - (11, 1101, 'some heritage charges', -15.99, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 5, 1), - (12, 1101, 'some miscellaneous charges', 58.00, DATE_ADD(util.VN_CURDATE(), INTERVAL 1 MONTH), util.VN_CURDATE(), 6, 1); - -INSERT INTO `vn`.`mandate`(`id`, `clientFk`, `companyFk`, `code`, `created`, `mandateTypeFk`) - VALUES - (1, 1102, 442, '1-1', util.VN_CURDATE(), 2); - -INSERT INTO `vn`.`itemCategory`(`id`, `name`, `display`, `color`, `icon`, `code`) - VALUES - (1, 'Plant', 1, 'B92A26', 'icon-plant', 'plant'), - (2, 'Flower', 2, 'dcf711', 'icon-flower', 'flower'), - (3, 'Logistic', 0, 'b9f711', NULL, 'logistical'), - (4, 'Handmade', 1, NULL, 'icon-handmade', 'handmade'), - (5, 'Artificial', 1, NULL, 'icon-artificial', 'artificial'), - (6, 'Green', 1, NULL, 'icon-greenery', 'greenery'), - (7, 'Accessories', 1, NULL, 'icon-accessory', 'accessory'), - (8, 'Fruit', 1, NULL, 'icon-fruit', 'fruit'); - -INSERT INTO `vn`.`temperature`(`code`, `name`, `description`) - VALUES - ('warm', 'Warm', 'Warm'), - ('cool', 'Cool', 'Cool'); - -INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `life`, `workerFk`, `isPackaging`, `temperatureFk`, `isFragile`) - VALUES - (1, 'CRI', 'Crisantemo', 2, 31, 35, 0, 'cool', 0), - (2, 'ITG', 'Anthurium', 1, 31, 35, 0, 'cool', 1), - (3, 'WPN', 'Paniculata', 2, 31, 35, 0, 'cool', 0), - (4, 'PRT', 'Delivery ports', 3, NULL, 35, 1, 'warm', 0), - (5, 'CON', 'Container', 3, NULL, 35, 1, 'warm', 0), - (6, 'ALS', 'Alstroemeria', 1, 31, 16, 0, 'warm', 1); - -INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`) - VALUES - ('YEL', 'Yellow', 1, 1, 'F4D03F'), - ('BLU', 'Blue', 1, 2, '5DADE2'), - ('RED', 'Red', 1, 3, 'EC7063'), - ('SLV', 'Silver', 1, 4, 'CACFD2'), - ('BRW', 'Brown', 1, 5, 'DC7633'), - ('BLK', 'Black', 1, 6, '000000'), - ('BAS', 'Blue/Silver', 1, 7, '5DADE2'), - ('GRN', 'Green', 1, 8, '28A745'), - ('WHT', 'White', 1, 9, 'FFFFFF'); - -INSERT INTO `vn`.`origin`(`id`,`code`, `name`) - VALUES - (1, 'SPA', 'Spain'), - (2, 'HOL', 'Holand'), - (3, 'VLC', 'Valencia'); - -INSERT INTO `vn`.`producer`(`id`, `name`) - VALUES - (1, 'Marvel Studios'), - (2, 'Nordic Mythology'); - -INSERT INTO `vn`.`taxType`(`id`, `nickname`, `isAccrued`, `serial`, `TIPOOPE`, `description`, `countryFk`) - VALUES - (1, 'National', 1, 'R', 'I', 'national VAT', 1), - (2, 'European', 0, 'E', 'I', 'europe VAT', 1); - -INSERT INTO `vn`.`taxCode`(`id`, `dated`, `code`, `taxTypeFk`, `rate`, `equalizationTax`, `type`, `link`, `isActive`, `updated`, `transactionCode`) - VALUES - (1 , util.VN_CURDATE(), '1111111111', 1, 7.0 , 0.0, 'R', 1, 1, util.VN_CURDATE(), 1), - (2 , util.VN_CURDATE(), '2222222222', 2, 16.0, 0.0, 'G', 2, 1, util.VN_CURDATE(), 1), - (21 , util.VN_CURDATE(), '3333333333', 1, 7.0, 0.0, 'R', 3, 1, util.VN_CURDATE(), 1), - (108, util.VN_CURDATE(), '4444444444', 2, 8.0 , 0.0, 'R', 4, 1, util.VN_CURDATE(), 1); - -INSERT INTO `vn`.`taxClass`(`id`, `description`, `code`) - VALUES - (1, 'Reduced VAT', 'R'), - (2, 'General VAT', 'G'); - -INSERT INTO `vn`.`taxClassCode`(`taxClassFk`, `effectived`, `taxCodeFk`) - VALUES - (1, util.VN_CURDATE(), 1), - (1, util.VN_CURDATE(), 21), - (2, util.VN_CURDATE(), 2); - -INSERT INTO `vn`.`intrastat`(`id`, `description`, `taxClassFk`, `taxCodeFk`) - VALUES - (05080000, 'Coral y materiales similares', 2, 2), - (06021010, 'Plantas vivas: Esqueje/injerto, Vid', 1, 1); - -INSERT INTO `vn`.`itemFamily`(`code`, `description`) - VALUES - ('EMB', 'Packagings'), - ('SER', 'Services'), - ('VT', 'Sales'); - -INSERT INTO `vn`.`item`(`id`, `typeFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenseFk`, - `comment`, `relevancy`, `image`, `subName`, `minPrice`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`, `weightByPiece`) - VALUES - (1, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 'EMB', 0, NULL, 'V', 0, 15,3), - (2, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 'VT', 0, NULL, 'H', 0, 10,2), - (3, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 'VT', 0, NULL, NULL, 0, 5,5), - (4, 1, 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (5, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (6, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (7, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (8, 2, 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (9, 2, 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL,NULL), - (10, 1, 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (11, 1, 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (12, 3, 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL), - (13, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 'VT', 1, NULL, NULL, 1, NULL,NULL), - (14, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL,NULL), - (15, 4, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), - (16, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL), - (71, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL); - --- Update the taxClass after insert of the items -UPDATE `vn`.`itemTaxCountry` SET `taxClassFk` = 2 - WHERE `itemFk` IN(4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 71); - -INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`, `started`, `ended`, `bonus`, `warehouseFk`, `created`) - VALUES - (1, 1, 0, 0, 2.5, 2, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()), - (2, 3, 10, 10, 10, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()), - (3, 13, 8.5, 10, 7.5, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 1, 2, util.VN_CURDATE()); - -INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`) - VALUES - (71,0.141,1); - -INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPackageReturnable`, `created`, `itemFk`, `price`) - VALUES - (1, 0.00, 10, 10, 0, 1, util.VN_CURDATE(), 6, 1.50), - (2, 100.00, 20, 20, 0, 1, util.VN_CURDATE(), 7, 1.00), - (3, 14000.00, 0, 0, 0, 1, util.VN_CURDATE(), NULL, 0), - (4, 218000.00, 0, 0, 0, 0, util.VN_CURDATE(), NULL, 0), - (5, 292000.00, 0, 0, 0, 0, util.VN_CURDATE(), NULL, 0), - (94, 140875.00, 49.00, 115.00, 25.00, 0, util.VN_CURDATE(), 71, 0.00), - ('cc', 1640038.00, 56.00, 220.00, 128.00, 1, util.VN_CURDATE(), 15, 90.00), - ('pallet 100', 2745600.00, 100.00, 220.00, 120.00, 1, util.VN_CURDATE(), 16, 0.00); - -INSERT INTO `vn`.`packagingConfig`(`upperGap`, `defaultSmallPackageFk`, `defaultBigPackageFk`) - VALUES - ('10', 1, 'pallet 100'); - -INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) - VALUES - (1, 'En reparto', 'ON DELIVERY'), - (2, 'Entregada', 'DELIVERED'), - (3, 'Perdida', 'LOST'); - - -INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, `created`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`, `hostFk`) - VALUES - (1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, 'UR9000006041', 94, 1, 'pc1'), - (2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 18, 'UR9000006041', 94, 1, NULL), - (3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 18, 'UR9000006041', 94, 2, NULL), - (4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 18, 'UR9000006041', 94, 2, NULL), - (5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 3, NULL), - (6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 18, NULL, 94, 3, NULL), - (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), - (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), - (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), - (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (13, 1, 10,71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); - - -INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) - VALUES - (1, util.VN_CURDATE(), 1, 1, 1), - (2, util.VN_CURDATE(), 2, 1, 1), - (3, util.VN_CURDATE(), 3, 1, 1), - (4, util.VN_CURDATE(), 3, 2, 1106), - (5, util.VN_CURDATE(), 5, 1, 1106), - (6, util.VN_CURDATE(), 5, 3, 1106); - -INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) - VALUES - (1, 1, 2, 2, util.VN_CURDATE(), NULL), - (2, 2, 2, 1, util.VN_CURDATE(), NULL), - (3, 3, 2, 4, util.VN_CURDATE(), NULL); - -INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `price`, `discount`, `reserved`, `isPicked`, `created`) - VALUES - (1, 1, 1, 'Ranged weapon longbow 200cm', 5, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (2, 2, 1, 'Melee weapon combat fist 15cm', 10, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (3, 1, 1, 'Ranged weapon longbow 200cm', 2, 100.39, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (4, 4, 1, 'Melee weapon heavy shield 100cm', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (5, 1, 2, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (6, 1, 3, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), - (7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.74, 0, 0, 0, util.VN_CURDATE()), - (8, 4, 11, 'Melee weapon heavy shield 100cm', 10, 1.79, 0, 0, 0, util.VN_CURDATE()), - (9, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), - (10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, util.VN_CURDATE()), - (11, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), - (12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE()), - (13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE()), - (14, 1, 8, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE()), - (15, 1, 19, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE()), - (16, 2, 20, 'Melee weapon combat fist 15cm', 20, 7.07, 0, 0, 0, util.VN_CURDATE()), - (17, 2, 22, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (18, 4, 22, 'Melee weapon heavy shield 100cm', 20, 1.69, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (19, 1, 4, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), - (20, 1, 5, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), - (21, 1, 6, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (22, 1, 7, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (23, 1, 9, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (24, 1, 10, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (25, 4, 12, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (26, 4, 13, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (27, 4, 14, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (28, 4, 15, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (29, 4, 17, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (30, 4, 18, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE()), - (32, 1, 24, 'Ranged weapon longbow 200cm', -1, 8.07, 0, 0, 0, util.VN_CURDATE()), - (33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE()), - (34, 4, 28, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (35, 4, 29, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (37, 4, 31, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), - (38, 2, 32, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (39, 1, 32, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE()); - -INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) - VALUES - (1, 28, 50), - (1, 29, 49.4), - (1, 39, 0.994), - (2, 28, 5), - (2, 29, 2), - (2, 39, 0.07), - (3, 28, 50), - (3, 29, 49.4), - (3, 39, 0.994), - (4, 28, 1.25), - (4, 29, 0.42), - (4, 39, 0.017), - (5, 17, 9.94), - (5, 28, 50), - (5, 29, 49.4), - (5, 39, 0.994), - (6, 17, 9.94), - (6, 28, 50), - (6, 29, 49.4), - (6, 39, 0.994), - (7, 15, 0.0199), - (7, 17, 0.35), - (7, 28, 5), - (7, 29, 2), - (7, 39, 0.07), - (8, 15, 0.0199), - (8, 17, 0.084), - (8, 28, 1.25), - (8, 29, 0.42), - (8, 39, 0.017), - (9, 15, 3.0949), - (9, 21, 0.001), - (9, 28, 53), - (9, 29, 46.4), - (9, 39, 0.994), - (10, 15, 0.0199), - (10, 28, 7), - (10, 29, 0), - (10, 39, 0.07), - (11, 15, 3.0949), - (11, 21, 0.001), - (11, 28, 53), - (11, 29, 46.4), - (11, 39, 0.994), - (12, 15, 0.0199), - (12, 21, 0.003), - (12, 28, 2.25), - (12, 29, -0.58), - (12, 39, 0.017), - (13, 15, 0.114), - (13, 28, 5), - (13, 29, 2), - (13, 39, 0.07), - (14, 15, 3.0949), - (14, 28, 50), - (14, 29, 49.4), - (14, 39, 0.994), - (15, 15, 3.0949), - (15, 28, 50), - (15, 29, 49.4), - (15, 39, 0.994), - (16, 28, 5), - (16, 29, 2), - (16, 39, 0.07), - (17, 28, 5), - (17, 29, 2), - (17, 39, 0.07), - (18, 28, 1.25), - (18, 29, 0.42), - (18, 39, 0.017), - (19, 17, 0.7), - (19, 22, 0.3), - (19, 28, 5), - (19, 29, 2), - (19, 39, 0.02), - (20, 17, 0.7), - (20, 22, 0.3), - (20, 28, 5), - (20, 29, 2), - (20, 39, 0.02), - (21, 17, 0.7), - (21, 22, 0.3), - (21, 28, 5), - (21, 29, 2), - (21, 39, 0.02), - (22, 17, 0.7), - (22, 22, 0.3), - (22, 28, 5), - (22, 29, 2), - (22, 39, 0.02), - (23, 17, 0.7), - (23, 22, 0.3), - (23, 28, 5), - (23, 29, 2), - (23, 39, 0.02), - (24, 17, 0.7), - (24, 22, 0.3), - (24, 28, 5), - (24, 29, 2), - (24, 39, 0.02), - (25, 17, 0.033), - (25, 28, 1.25), - (25, 29, 0.42), - (25, 39, 0.017), - (26, 17, 0.033), - (26, 28, 1.25), - (26, 29, 0.42), - (26, 39, 0.017), - (27, 17, 0.033), - (27, 28, 1.25), - (27, 29, 0.42), - (27, 39, 0.017), - (28, 17, 0.033), - (28, 28, 1.25), - (28, 29, 0.42), - (28, 39, 0.017), - (29, 17, 0.033), - (29, 28, 1.25), - (29, 29, 0.42), - (29, 39, 0.017), - (30, 17, 0.033), - (30, 28, 1.25), - (30, 29, 0.42), - (30, 39, 0.017), - (31, 28, 5), - (31, 29, 2), - (31, 36, 0.01), - (31, 39, 0.07), - (32, 28, 50), - (32, 29, 49.4), - (32, 36, -92.324), - (32, 39, 0.994); - -INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`, `userFk`) - VALUES - (2, 'GVC', 1, 1, 1, 1106), - (4, 'HEJ', 1, 1, 1, 1106), - (1, 'UXN', 2, 12, 12, 1106); - -INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`) - VALUES - ('1', '1', '1', util.VN_CURDATE(), '1106'), - ('2', '2', '5', util.VN_CURDATE(), '1106'), - ('1', '7', '1', util.VN_CURDATE(), '1106'), - ('2', '8', '5', util.VN_CURDATE(), '1106'); - -INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `id`, `stateFk`) - VALUES - (1, 0, util.VN_CURDATE(), 5, 55, 1, 14), - (1, 1, util.VN_CURDATE(), 5, 54, 2, 8), - (2, 1, util.VN_CURDATE(), 10, 40, 3, 8), - (3, 1, util.VN_CURDATE(), 2, 40, 4, 8), - (31, 1, util.VN_CURDATE(), -5, 40, 5, 8); - -INSERT INTO `vn`.`itemBarcode`(`id`, `itemFk`, `code`) - VALUES - (1, 1, 1111111111), - (2, 1, 2222222222), - (3, 1, 3333333333), - (4, 2, 4444444444); - -INSERT INTO `vn`.`train`(`id`, `name`) - VALUES - (1, 'Train1'), - (2, 'Train2'); - -INSERT INTO `vn`.`operator` (`workerFk`, `numberOfWagons`, `trainFk`, `itemPackingTypeFk`, `warehouseFk`, `sectorFk`, `labelerFk`) - VALUES - ('1106', '1', '1', 'H', '1', '1', '1'), - ('1107', '1', '1', 'V', '1', '1', '1'); - -INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`) - VALUES - (1, 1106, 5, DATE_ADD(util.VN_CURDATE(),INTERVAL +1 DAY), 1), - (2, 1106, 14, util.VN_CURDATE(), 1); - -INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) - VALUES - (1, 1, 1), - (2, 1, NULL), - (3, 2, NULL), - (23, 1, NULL); - -INSERT INTO `vn`.`genus`(`id`, `name`) - VALUES - (1, 'Abelia'), - (2, 'Abies'), - (3, 'Abutilon'); - -INSERT INTO `vn`.`specie`(`id`, `name`) - VALUES - (1, 'grandiflora'), - (2, 'procera'), - (3, 'decurrens'), - (4, 'dealbata'); - -INSERT INTO `vn`.`itemBotanical`(`itemFk`, `genusFk`, `specieFk`) - VALUES - (1, 1, 1), - (2, 2, 2), - (3, 2, NULL), - (4, 2, 1); - -INSERT INTO `vn`.`tag`(`id`, `code`, `name`, `isFree`, `isQuantitatif`, `sourceTable`, `unit`, `ediTypeFk`, `overwrite`) - VALUES - (1, 'color', 'Color', 0, 0, 'ink', NULL, NULL, 'inkFk'), - (2, NULL, 'Forma', 1, 0, NULL, NULL,NULL, NULL), - (3, NULL, 'Material', 1, 0, NULL, NULL,NULL, NULL), - (4, NULL, 'Longitud', 1, 1, NULL, 'mm', NULL, 'size'), - (5, NULL, 'Diámetro', 1, 1, NULL, 'mm',NULL, 'diameter'), - (7, NULL, 'Ancho de la base', 1, 1, NULL, 'mm',NULL, NULL), - (23, 'stems', 'Tallos', 1, 1, NULL, NULL, NULL, 'stems'), - (27, NULL, 'Longitud(cm)', 1, 1, NULL, 'cm', NULL, 'size'), - (36, 'producer', 'Proveedor', 1, 0, NULL, NULL, NULL, 'producer'), - (56, NULL, 'Genero', 1, 0, NULL, NULL, NULL, NULL), - (58, NULL, 'Variedad', 1, 0, NULL, NULL, NULL, NULL), - (67, 'category', 'Categoria', 1, 0, NULL, NULL, NULL, NULL), - (92, NULL, 'Nombre temporal', 1, 0, NULL, NULL, NULL, NULL); - -INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`) - VALUES - (1, 1, 56, 'Ranged weapon', 1), - (2, 1, 58, 'longbow', 2), - (3, 1, 27, '200cm', 3), - (4, 1, 36, 'Stark Industries', 4), - (5, 1, 1, 'Brown', 5), - (6, 1, 67, '+1 precission', 6), - (7, 1, 23, '1', 7), - (8, 2, 56, 'Melee weapon', 1), - (9, 2, 58, 'combat fist', 2), - (10, 2, 27, '15cm', 3), - (11, 2, 36, 'Stark Industries', 4), - (12, 2, 1, 'Silver', 5), - (13, 2, 67, 'Concussion', 6), - (14, 2, 23, '2', 7), - (15, 3, 56, 'Ranged weapon', 1), - (16, 3, 58, 'sniper rifle', 2), - (17, 3, 4, '113cm', 3), - (18, 3, 36, 'Stark Industries', 4), - (19, 3, 1, 'Green', 5), - (20, 3, 67, 'precission', 6), - (21, 3, 23, '3', 7), - (22, 4, 56, 'Melee weapon', 1), - (23, 4, 58, 'heavy shield', 2), - (24, 4, 4, '100cm', 3), - (25, 4, 36, 'Stark Industries', 4), - (26, 4, 1, 'Black', 5), - (27, 4, 67, 'containtment', 6), - (28, 4, 23, '4', 7), - (29, 5, 56, 'Ranged weapon', 1), - (30, 5, 58, 'pistol', 2), - (31, 5, 67, '9mm', 3), - (32, 5, 36, 'Stark Industries', 4), - (33, 5, 1, 'Silver', 5), - (34, 5, 27, '15cm', 6), - (35, 5, 23, '5', 7), - (36, 6, 56, 'Container', 1), - (37, 6, 58, 'ammo box', 2), - (38, 6, 27, '100cm', 3), - (39, 6, 36, 'Stark Industries', 4), - (40, 6, 1, 'Green', 5), - (41, 6, 67, 'supply', 6), - (42, 6, 23, '6', 7), - (43, 7, 56, 'Container', 1), - (44, 7, 58, 'medical box', 2), - (45, 7, 27, '100cm', 3), - (46, 7, 36, 'Stark Industries', 4), - (47, 7, 1, 'White', 5), - (48, 7, 67, 'supply', 6), - (49, 7, 23, '7', 7), - (50, 8, 56, 'Ranged Reinforced weapon', 1), - (51, 8, 58, '+1 longbow', 2), - (52, 8, 27, '200cm', 3), - (53, 8, 36, 'Stark Industries', 4), - (54, 8, 1, 'Brown', 5), - (55, 8, 67, 'precission', 6), - (56, 8, 23, '8', 7), - (57, 9, 56, 'Melee Reinforced weapon', 1), - (58, 9, 58, 'combat fist', 2), - (59, 9, 27, '15cm', 3), - (60, 9, 36, 'Stark Industries', 4), - (61, 9, 1, 'Silver', 5), - (62, 9, 67, 'Concussion', 6), - (63, 9, 23, '9', 7), - (64, 10, 56, 'Ranged Reinforced weapon', 1), - (65, 10, 58, 'sniper rifle', 2), - (66, 10, 67, '700mm', 3), - (67, 10, 36, 'Stark Industries', 4), - (68, 10, 1, 'Green', 5), - (69, 10, 27, '130cm', 6), - (70, 10, 23, '10', 7), - (71, 11, 56, 'Melee Reinforced weapon', 1), - (72, 11, 58, 'heavy shield', 2), - (73, 11, 4, '120cm', 3), - (74, 11, 36, 'Stark Industries', 4), - (75, 11, 1, 'Black', 5), - (76, 11, 67, 'containtment', 6), - (77, 11, 23, '11', 7), - (78, 12, 56, 'Ranged Reinforced weapon', 1), - (79, 12, 58, 'pistol', 2), - (80, 12, 27, '9mm', 3), - (81, 12, 36, 'Stark Industries', 4), - (82, 12, 1, 'Silver', 5), - (83, 12, 67, '23cm', 6), - (84, 12, 23, '12', 7), - (85, 13, 56, 'Chest', 1), - (86, 13, 58, 'ammo box', 2), - (87, 13, 27, '100cm', 3), - (88, 13, 36, 'Stark Industries', 4), - (89, 13, 1, 'Green', 5), - (90, 13, 67, 'supply', 6), - (91, 13, 23, '13', 7), - (92, 14, 56, 'Chest', 1), - (93, 14, 58, 'medical box', 2), - (94, 14, 27, '100cm', 3), - (95, 14, 36, 'Stark Industries', 4), - (96, 14, 1, 'White', 5), - (97, 14, 67, 'supply', 6), - (98, 14, 23, '1', 7), - (99, 15, 92, 'Trolley', 2), - (100, 16, 92, 'Pallet', 2), - (101, 71, 92, 'Shipping cost', 2); - -INSERT INTO `vn`.`itemTypeTag`(`id`, `itemTypeFk`, `tagFk`, `priority`) - VALUES - (1, 1, 1, 0), - (2, 2, 2, 0), - (3, 3, 3, 0), - (4, 1, 4, 4), - (5, 1, 5, 5); - -CALL `vn`.`itemRefreshTags`(NULL); - -INSERT INTO `vn`.`itemLog` (`id`, `originFk`, `userFk`, `action`, `description`, `changedModel`, `oldInstance`, `newInstance`, `changedModelId`, `changedModelValue`) - VALUES - ('1', '1', '1', 'insert', 'We made a change!', 'Item', '{}', '{}', 1, '1'); - -INSERT INTO `vn`.`recovery`(`id`, `clientFk`, `started`, `finished`, `amount`, `period`) - VALUES - (1, 1101, DATE_ADD(util.VN_CURDATE(),INTERVAL -7 MONTH), DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), 50, 7), - (2, 1102, DATE_ADD(util.VN_CURDATE(),INTERVAL -5 MONTH), util.VN_CURDATE(), 100, 1), - (3, 1102, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(),INTERVAL 1 MONTH), 50, 7), - (4, 1103, util.VN_CURDATE(), NULL, 50, 7); - -INSERT INTO `bs`.`clientAnnualConsumption`(`clientFk`, `invoiced`) - VALUES - (1101, 1500), - (1102, 100), - (1103, 1000), - (1104, 500), - (1105, 5000); - -INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`) - VALUES - (1, 2, 'available', CONCAT_WS('/',1,util.VN_CURDATE()), util.VN_NOW(), DATE_ADD(util.VN_NOW(),INTERVAL 15 MINUTE), util.VN_CURDATE(), NULL), - (2, 4, 'last_buy', CONCAT_WS('/',1,util.VN_CURDATE()), util.VN_NOW(), DATE_ADD(util.VN_NOW(),INTERVAL 15 MINUTE), util.VN_CURDATE(), NULL), - (3, 8, 'visible', CONCAT_WS('/',1,util.VN_CURDATE()), util.VN_NOW(), DATE_ADD(util.VN_NOW(),INTERVAL 15 MINUTE), util.VN_CURDATE(), NULL); - -INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) - VALUES - (2, 1), - (3, 2), - (5, 6), - (15, 6); - -INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) - VALUES - (1, '07546501420', 67, 671, util.VN_CURDATE(), 1761, 1, 1), - (2, '07546491421', 252, 2769, util.VN_CURDATE(), 5231, 1, 1), - (3, '07546500823', 102, 1495, util.VN_CURDATE(), 3221, 1, 1), - (4, '99610288821', 252, 2777, util.VN_CURDATE(), 3641, 1, 1), - (5, '07546500834', 229, 3292, util.VN_CURDATE(), 6601, 2, 1), - (6, '22101929561', 37, 458, util.VN_CURDATE(), 441, 2, 1), - (7, '07546491432', 258, 3034, util.VN_CURDATE(), 6441, 2, 1), - (8, '99610288644', 476, 4461, util.VN_CURDATE(), 5751, 442, 1), - (9, '99610289193', 302, 2972, util.VN_CURDATE(), 3871, 442, 1), - (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); - -INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`) - VALUES - (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), - (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2, 2), - (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), - (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), - (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), - (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10); - -INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) - VALUES - (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'IN2001', 'Movement 1', 0, 0, ''), - (2, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'IN2002', 'Movement 2', 0, 0, 'observation two'), - (3, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 0, 442, 'IN2003', 'Movement 3', 0, 0, 'observation three'), - (4, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'IN2004', 'Movement 4', 0, 0, 'observation four'), - (5, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'IN2005', 'Movement 5', 0, 0, 'observation five'), - (6, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'IN2006', 'Movement 6', 0, 0, 'observation six'), - (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'), - (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''); - -INSERT INTO `bs`.`waste`(`buyer`, `year`, `week`, `family`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleWaste`, `rate`) - VALUES - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation', 1, 1, '1062', '51', '4.8'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Colombia', 2, 1, '35074', '687', '2.0'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Mini', 3, 1, '1777', '13', '0.7'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Carnation Short', 4, 1, '3182', '59', '0.6'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Crisantemo', 5, 1, '1747', '13', '0.7'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Lilium Oriental', 6, 1, '7182', '59', '0.6'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Alstroemeria', 7, 1, '1777', '13', '0.7'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Cymbidium', 1, 1, '4181', '59', '0.6'), - ('CharlesXavier', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Cymbidium', 2, 1, '7268', '59', '0.6'), - ('DavidCharlesHaller', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Containers', 2, 1, '-74', '0', '0.0'), - ('DavidCharlesHaller', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Packagings', 3, 1, '-7', '0', '0.0'), - ('DavidCharlesHaller', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Freight', 4, 1, '1100', '0', '0.0'), - ('HankPym', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Funeral Accessories', 5, 1, '848', '-187', '-22.1'), - ('HankPym', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Miscellaneous Accessories', 6, 1, '186', '0', '0.0'), - ('HankPym', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 'Adhesives', 7, 1, '277', '0', '0.0'); - -INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagingFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`, `printedStickers`,`isChecked`,`isIgnored`,`weight`, `created`) - VALUES - (1, 1, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), - (2, 2, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (3, 3, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 0, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE()), - (4, 2, 2, 5, 450, 3, 1, 1.000, 1.000, 0.000, 10, 10, 0, NULL, 0.00, 7.30, 7.00, 0, 1, 0, 2.5, util.VN_CURDATE()), - (5, 3, 3, 55, 500, 5, 1, 1.000, 1.000, 0.000, 1, 1, 0, NULL, 0.00, 78.3, 75.6, 0, 1, 0, 2.5, util.VN_CURDATE()), - (6, 4, 8, 50, 1000, 4, 1, 1.000, 1.000, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 2.5, util.VN_CURDATE()), - (7, 4, 9, 20, 1000, 3, 1, 0.500, 0.500, 0.000, 10, 10, 1, NULL, 0.00, 30.50, 29.00, 0, 1, 0, 2.5, util.VN_CURDATE()), - (8, 4, 4, 1.25, 1000, 3, 1, 0.500, 0.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 2.5, util.VN_CURDATE()), - (9, 4, 4, 1.25, 1000, 3, 1, 0.500, 0.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), - (10, 5, 1, 50, 10, 4, 1, 2.500, 2.500, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), - (11, 5, 4, 1.25, 10, 3, 1, 2.500, 2.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), - (12, 6, 4, 1.25, 0, 3, 1, 2.500, 2.500, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), - (13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 1, NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), - (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), - (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()); - -INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) - VALUES - (1, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 3, 1, 121, 442, NULL, 'TPV', 1,'155.89', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (2, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1104, 3, 1, 124, 442, NULL, 'WEB', 1,'100.10', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (3, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 1104, 1, 2, 124, 442, NULL, 'ANDROID', 1,'107.25', DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH)), - (4, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 1104, 1, 2, 124, 442, NULL, 'SALIX', 1,'10.01', DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH)), - (5, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 1104, 1, 3, 124, 442, NULL, 'SALIX', 1,'10.01', DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH)), - (6, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 1101, 1, 3, 1, 442, NULL, 'SALIX', 1,'10.01', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH)), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 2, 7, 1, 442, NULL, 'SALIX', 0,'10.01', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1101, 2, 7, 121, 442, NULL, 'SALIX', 0,'123.53', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (9, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 2, 7, 124, 442, NULL, 'SALIX', 0,'10.01', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (10, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 3, 1, 2, 442, NULL, 'SALIX', 0,'10.01', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (11, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 2, 7, 122, 442, NULL, 'SALIX', 0,'60.90', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (12, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 3, 1, 3, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (13, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 1, 2, 123, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (14, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1104, 1, 2, 4, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (15, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1105, 1, 3, 125, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (16, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1106, 2, 7, 126, 442, NULL, 'SALIX', 0,'155.89', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (17, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1107, 1, 4, 127, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (18, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1108, 1, 4, 128, 442, NULL, 'SALIX', 0,'72.60', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (19, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1109, 1, 5, 129, 442, NULL, 'SALIX', 0,'16.50', util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE()), - (20, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 1, 5, 101, 442, NULL, 'SALIX', 0,'21.45', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (21, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 1, 5, 102, 442, NULL, 'SALIX', 0,'0.00', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (22, DATE_ADD(DATE_ADD(util.VN_CURDATE(),INTERVAL +1 MONTH), INTERVAL +1 DAY), 1109, 1, 5, 103, 442, NULL, 'SALIX', 0,'148.50', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)); - -INSERT INTO `hedera`.`orderRow`(`id`, `orderFk`, `itemFk`, `warehouseFk`, `shipment`, `amount`, `price`, `rate`, `created`, `saleFk`) - VALUES - (1, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1), - (2, 1, 2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 10, 1.07, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2), - (3, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3), - (4, 1, 4, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 20, 3.06, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4), - (5, 2, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 10, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5), - (6, 3, 1, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 15, 6.50, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 6), - (7, 11, 2, 1, util.VN_CURDATE(), 15, 1.30, 0, util.VN_CURDATE(), 7), - (8, 11, 4, 1, util.VN_CURDATE(), 10, 3.26, 0, util.VN_CURDATE(), 8), - (9, 16, 1, 1, util.VN_CURDATE(), 5, 9.10, 0, util.VN_CURDATE(), 9), - (10, 16, 2, 1, util.VN_CURDATE(), 10, 1.07, 0, util.VN_CURDATE(), 10), - (11, 16, 1, 1, util.VN_CURDATE(), 2, 9.10, 0, util.VN_CURDATE(), 11), - (12, 16, 4, 1, util.VN_CURDATE(), 20, 3.06, 0, util.VN_CURDATE(), 12), - (13, 8, 2, 1, util.VN_CURDATE(), 15, 1.30, 0, util.VN_CURDATE(), 13), - (14, 8, 1, 1, util.VN_CURDATE(), 10, 9.28, 0, util.VN_CURDATE(), 14), - (15, 19, 1, 1, util.VN_CURDATE(), 10, 1.50, 0, util.VN_CURDATE(), 15), - (16, 20, 2, 1, util.VN_CURDATE(), 15, 1.30, 0, util.VN_CURDATE(), 16), - (17, 22, 2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 30, 2.30, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 17), - (18, 22, 4, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 20, 3.00, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 18), - (19, 4, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 19), - (20, 5, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 20), - (21, 6, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 9.10, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 21), - (22, 7, 1, 1, util.VN_CURDATE(), 1, 9.10, 0, util.VN_CURDATE(), 22), - (23, 9, 1, 1, util.VN_CURDATE(), 1, 9.10, 0, util.VN_CURDATE(), 23), - (24, 10, 1, 1, util.VN_CURDATE(), 1, 9.10, 0, util.VN_CURDATE(), 24), - (25, 12, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 25), - (26, 13, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 26), - (27, 14, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 27), - (28, 15, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 28), - (29, 17, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 29), - (30, 18, 4, 1, util.VN_CURDATE(), 20, 3.00, 0, util.VN_CURDATE(), 30); - -INSERT INTO `hedera`.`orderRowComponent`(`rowFk`, `componentFk`, `price`) - VALUES - (1, 15, 0.58), - (1, 23, 6.5), - (1, 28, 20.72), - (1, 29, -18.72), - (1, 39, 0.02), - (2, 15, 0.058), - (2, 21, 0.002), - (2, 28, 5.6), - (2, 29, -4.6), - (2, 39, 0.01), - (3, 15, 0.58), - (3, 23, 6.5), - (3, 28, 20.72), - (3, 29, -18.72), - (3, 39, 0.02), - (4, 15, 0.051), - (4, 21, -0.001), - (4, 28, 20.72), - (4, 29, -19.72), - (4, 37, 2), - (4, 39, 0.01), - (5, 15, 0.58), - (5, 23, 6.5), - (5, 28, 20.72), - (5, 29, -18.72), - (5, 39, 0.02), - (6, 23, 6.5), - (7, 15, 0.0114), - (7, 28, 5.6), - (7, 29, -4.6), - (7, 39, 0.01), - (8, 15, 0.0016), - (8, 28, 20.72), - (8, 29, -19.72), - (8, 37, 2), - (8, 39, 0.01), - (9, 15, 0.58), - (9, 23, 6.5), - (9, 28, 20.72), - (9, 29, -18.72), - (9, 39, 0.02), - (10, 15, 0.058), - (10, 21, 0.002), - (10, 28, 5.6), - (10, 29, -4.6), - (10, 39, 0.01), - (11, 15, 0.58), - (11, 23, 6.5), - (11, 28, 20.72), - (11, 29, -18.72), - (11, 39, 0.02), - (12, 15, 0.051), - (12, 22, -0.001), - (12, 28, 20.72), - (12, 29, -19.72), - (12, 37, 2), - (12, 39, 0.01), - (13, 15, 0.2899), - (13, 28, 5.6), - (13, 29, -4.6), - (13, 39, 0.01), - (14, 15, 0.58), - (14, 23, 6.5), - (14, 28, 20.72), - (14, 29, -18.72), - (14, 39, 0.02), - (15, 15, 0.58), - (15, 23, 6.5), - (15, 28, 20.72), - (15, 29, -18.72), - (15, 39, 0.02), - (16, 15, 0.058), - (16, 21, 0.002), - (16, 28, 5.6), - (16, 29, -4.6), - (16, 39, 0.01), - (17, 15, 0.058), - (17, 21, 0.002), - (17, 28, 5.6), - (17, 29, -4.6), - (17, 39, 0.01), - (18, 15, 0.051), - (18, 22, -0.001), - (18, 28, 20.72), - (18, 29, -19.72), - (18, 37, 2), - (18, 39, 0.01), - (19, 15, 0.58), - (19, 23, 6.5), - (19, 28, 20.72), - (19, 29, -18.72), - (19, 39, 0.02), - (20, 15, 0.58), - (20, 23, 6.5), - (20, 28, 20.72), - (20, 29, -18.72), - (20, 39, 0.02), - (21, 15, 0.58), - (21, 23, 6.5), - (21, 28, 20.72), - (21, 29, -18.72), - (21, 39, 0.02), - (22, 15, 0.58), - (22, 23, 6.5), - (22, 28, 20.72), - (22, 29, -18.72), - (22, 39, 0.02), - (23, 15, 0.58), - (23, 23, 6.5), - (23, 28, 20.72), - (23, 29, -18.72), - (23, 39, 0.02), - (24, 15, 0.58), - (24, 23, 6.5), - (24, 28, 20.72), - (24, 29, -18.72), - (24, 39, 0.02), - (25, 15, 0.051), - (25, 22, -0.001), - (25, 28, 20.72), - (25, 29, -19.72), - (25, 37, 2), - (25, 39, 0.01), - (26, 15, 0.051), - (26, 22, -0.001), - (26, 28, 20.72), - (26, 29, -19.72), - (26, 37, 2), - (26, 39, 0.01), - (27, 15, 0.051), - (27, 22, -0.001), - (27, 28, 20.72), - (27, 29, -19.72), - (27, 37, 2), - (27, 39, 0.01), - (28, 15, 0.051), - (28, 22, -0.001), - (28, 28, 20.72), - (28, 29, -19.72), - (28, 37, 2), - (28, 39, 0.01), - (29, 15, 0.051), - (29, 22, -0.001), - (29, 28, 20.72), - (29, 29, -19.72), - (29, 37, 2), - (29, 39, 0.01), - (30, 15, 0.051), - (30, 22, -0.001), - (30, 28, 20.72), - (30, 29, -19.72), - (30, 37, 2), - (30, 39, 0.01); - -INSERT INTO `hedera`.`visit`(`id`, `firstAgentFk`) - VALUES - (1, NULL), - (2, NULL), - (3, NULL), - (4, NULL), - (5, NULL), - (6, NULL), - (7, NULL), - (8, NULL), - (9, NULL), - (10, NULL), - (11, NULL); - -INSERT INTO `hedera`.`visitAgent`(`id`, `visitFk`) - VALUES - (1, 1), - (2, 2), - (3, 3), - (4, 4), - (5, 5), - (6, 6), - (7, 7), - (8, 8), - (9, 9), - (10, 10), - (11, 11); - -INSERT INTO `hedera`.`visitAccess`(`id`, `agentFk`, `stamp`) - VALUES - (1, 1, util.VN_CURDATE()), - (2, 2, util.VN_CURDATE()), - (3, 3, util.VN_CURDATE()), - (4, 4, util.VN_CURDATE()), - (5, 5, util.VN_CURDATE()), - (6, 6, util.VN_CURDATE()), - (7, 7, util.VN_CURDATE()), - (8, 8, util.VN_CURDATE()), - (9, 9, util.VN_CURDATE()), - (10, 10, util.VN_CURDATE()), - (11, 11, util.VN_CURDATE()); - -INSERT INTO `hedera`.`visitUser`(`id`, `accessFk`, `userFk`, `stamp`) - VALUES - (1, 1, 1101, util.VN_CURDATE()), - (2, 2, 1101, util.VN_CURDATE()), - (3, 3, 1101, util.VN_CURDATE()), - (4, 4, 1102, util.VN_CURDATE()), - (5, 5, 1102, util.VN_CURDATE()), - (6, 6, 1102, util.VN_CURDATE()), - (7, 7, 1103, util.VN_CURDATE()), - (8, 8, 1103, util.VN_CURDATE()), - (9, 9, 1103, util.VN_CURDATE()), - (10, 10, 1102, DATE_SUB(util.VN_CURDATE(), INTERVAL 1 DAY)), - (11, 11, 1103, DATE_SUB(util.VN_CURDATE(), INTERVAL 1 DAY)); - -INSERT INTO `hedera`.`userSession`(`created`, `lastUpdate`, `ssid`, `data`, `userVisitFk`) - VALUES - (util.VN_CURDATE(), util.VN_CURDATE(), '121', 'data', 1), - (util.VN_CURDATE(), util.VN_CURDATE(), '122', 'data', 2), - (util.VN_CURDATE(), util.VN_CURDATE(), '123', 'data', 3), - (util.VN_CURDATE(), util.VN_CURDATE(), '124', 'data', 4), - (util.VN_CURDATE(), util.VN_CURDATE(), '125', 'data', 5), - (util.VN_CURDATE(), util.VN_CURDATE(), '126', 'data', 6), - (util.VN_CURDATE(), util.VN_CURDATE(), '127', 'data', 7), - (util.VN_CURDATE(), util.VN_CURDATE(), '128', 'data', 8), - (util.VN_CURDATE(), util.VN_CURDATE(), '129', 'data', 9); - -INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`) - VALUES - (1, 1101, 'contact 1', 666777888), - (2, 1101, 'contact 2', 111222333), - (3, 1101, 'contact 3', 222333444), - (4, 1102, 'contact 1', 876543219); - -INSERT INTO `vn`.`workerManaExcluded`(`workerFk`) - VALUES - (9); -/* - el mana de los trabajadores lo podemos poner a mano en la tabla si lo calculamos antes, - pero si hazemos alguna modificacion en alguna tabla que utiliza para calcularlo ya no seria correcto - - La otra manera es poner el calculo con los 2 trabajadores que utilizamos ahora mismo para los tickets -*/ - -call vn.manaSpellersRequery(19); -call vn.manaSpellersRequery(18); - -INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk`, `userFk`, `companyFk`) - VALUES - (1, 1101, 1, util.VN_CURDATE(), 18, 18, 442), - (2, 1101, 1, util.VN_CURDATE(), 18, 18, 442), - (3, 1101, 2, util.VN_CURDATE(), 18, 18, 442), - (4, 1102, 2, util.VN_CURDATE(), 18, 18, 567), - (5, 1102, 3, util.VN_CURDATE(), 19, 19, 567); - -INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`, `hasToNotify`) - VALUES - ( 1, 'pending', 'Pendiente', 1, 1, 0), - ( 2, 'managed', 'Gestionado', 72, 5, 0), - ( 3, 'resolved', 'Resuelto', 72, 7, 0), - ( 4, 'canceled', 'Anulado', 72, 6, 1), - ( 5, 'incomplete', 'Incompleta', 1, 3, 1), - ( 6, 'mana', 'Mana', 72, 4, 0), - ( 7, 'lack', 'Faltas', 72, 2, 0); - -INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`, `ticketFk`) - VALUES - (1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183', 11), - (2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL, 16), - (3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL, 7), - (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL, 8); - -INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) - VALUES - (1, 18, 'Cu nam labores lobortis definiebas, ei aliquyam salutatus persequeris quo, cum eu nemore fierent dissentiunt. Per vero dolor id, vide democritum scribentur eu vim, pri erroribus temporibus ex.', util.VN_CURDATE()), - (2, 18, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', util.VN_CURDATE()), - (3, 18, 'An vim commodo dolorem volutpat, cu expetendis voluptatum usu, et mutat consul adversarium his. His natum numquam legimus an, diam fabulas mei ut. Melius fabellas sadipscing vel id. Partem diceret mandamus mea ne, has te tempor nostrud. Aeque nostro eum no.', util.VN_CURDATE()), - (4, 18, 'Wisi forensibus mnesarchum in cum. Per id impetus abhorreant, his no magna definiebas, inani rationibus in quo. Ut vidisse dolores est, ut quis nominavi mel. Ad pri quod apeirian concludaturque.', util.VN_CURDATE()); - -INSERT INTO `vn`.`claimBeginning`(`id`, `claimFk`, `saleFk`, `quantity`) - VALUES - (1, 1, 7, 5), - (2, 2, 10, 10), - (3, 3, 22, 1), - (4, 4, 13, 5); - -INSERT INTO `vn`.`claimDestination`(`id`, `description`, `addressFk`) - VALUES - (1, 'Bueno', NULL), - (2, 'Basura/Perd.', 12), - (3, 'Confeccion', NULL), - (4, 'Reclam.PRAG', 12), - (5, 'Corregido', 11); - -INSERT INTO `vn`.`claimDevelopment`(`id`, `claimFk`, `claimResponsibleFk`, `workerFk`, `claimReasonFk`, `claimResultFk`, `claimRedeliveryFk`, `claimDestinationFk`) - VALUES - (1, 1, 1, 21, 1, 1, 2, 5), - (2, 1, 2, 21, 7, 2, 2, 5), - (3, 2, 7, 21, 9, 3, 2, 5), - (4, 3, 7, 21, 15, 8, 2, 5), - (5, 4, 7, 21, 7, 8, 2, 5); - -INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestinationFk`) - VALUES - (1, 31, 4, 21, 2), - (2, 32, 3, 21, 3); - -INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`) - VALUES - (1, 50), - (2, 30); - -INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`) - VALUES - (1101, 500, NULL, 0.00, 0.00, 1.00), - (1102, 1000, 2.00, 0.01, 0.05, 1.00), - (1103, 2000, 0.00, 0.00, 0.02, 1.00), - (1104, 2500, 150.00, 0.02, 0.10, 1.00); - -INSERT INTO vn.claimRma (`id`, `code`, `created`, `workerFk`) - VALUES - (1, '02676A049183', DEFAULT, 1106), - (2, '02676A049183', DEFAULT, 1106), - (3, '02676A049183', DEFAULT, 1107), - (4, '02676A049183', DEFAULT, 1107), - (5, '01837B023653', DEFAULT, 1106); - -INSERT INTO `vn`.`claimLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`) - VALUES - (1, 18, 'update', 'Claim', '{"hasToPickUp":false}', '{"hasToPickUp":true}', 1, NULL), - (1, 18, 'update', 'ClaimObservation', '{}', '{"claimFk":1,"text":"Waiting for customer"}', 1, NULL), - (1, 18, 'insert', 'ClaimBeginning', '{}', '{"claimFk":1,"saleFk":1,"quantity":10}', 1, NULL), - (1, 18, 'insert', 'ClaimDms', '{}', '{"claimFk":1,"dmsFk":1}', 1, NULL); - -INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`) - VALUES - (1, 'Arkham Bank', 442, 1, 'h12387193H10238'), - (2, 'NewYork Bank', 442, 1, '7981ugsgd1hsdad'); - -INSERT INTO `hedera`.`tpvTransaction`(`id`,`merchantFk`, `clientFk`,`receiptFk`, `amount`, `response`, `errorCode`, `status`, `created`) - VALUES - (1, 1, 1101, NULL, 2000, NULL, 'SIS0042', 'ok', util.VN_CURDATE()), - (2, 1, 1101, NULL, 1000, NULL, 'SIS0051', 'started', util.VN_CURDATE()), - (3, 2, 1101, NULL, 7268, NULL, NULL, 'ok', util.VN_CURDATE()), - (4, 2, 1101, NULL, 4698, NULL, NULL, 'started', util.VN_CURDATE()), - (5, 1, 1104, NULL, 2000, NULL, 'SIS0043', 'ok', util.VN_CURDATE()), - (6, 2, 1104, NULL, 4000, NULL, 'SIS0044', 'started', util.VN_CURDATE()); - -INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`) - VALUES - (1, 1), - (2, 2), - (3, 3), - (4, 4), - (5, 5), - (6, 6), - (7, 7), - (8, 8), - (9, 9), - (10, 10), - (11, 11), - (12, 12), - (13, 13), - (14, 14), - (15, 15), - (16, 16), - (17, 17), - (18, 18), - (19, 19), - (20, 20), - (21, 21), - (22, 22); - -INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`) - VALUES - (1, 1, 69), - (5, 1, 442), - (9, 1, 442), - (18, 3, 567); - -INSERT INTO `vn`.`receipt`(`id`, `invoiceFk`, `amountPaid`, `payed`, `workerFk`, `bankFk`, `clientFk`, `created`, `companyFk`, `isConciliate`) - VALUES - (1, 'Cobro web', 100.50, util.VN_CURDATE(), 9, 1, 1101, util.VN_CURDATE(), 442, 1), - (2, 'Cobro web', 200.50, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), 9, 1, 1101, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), 442, 1), - (3, 'Cobro en efectivo', 300.00, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), 9, 1, 1102, DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), 442, 0), - (4, 'Cobro en efectivo', 400.00, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 9, 1, 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 442, 0), - (5, 'Compensación', 400.00, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 9, 3, 1103, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY), 442, 0); - -INSERT INTO `vn`.`workerTeam`(`id`, `team`, `workerFk`) - VALUES - (1, 1, 9), - (2, 2, 18), - (3, 2, 19), - (4, 3, 1101), - (5, 3, 1102), - (6, 4, 1103), - (7, 4, 1104); - -INSERT INTO `vn`.`ticketRequest`(`id`, `description`, `requesterFk`, `attenderFk`, `quantity`, `itemFk`, `price`, `isOk`, `saleFk`, `ticketFk`, `created`) - VALUES - (1, 'Ranged weapon longbow 200cm', 18, 35, 5, 1, 9.10, 1, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), - (2, 'Melee weapon combat first 15cm', 18, 35, 10, 2, 1.07, 0, NULL, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL -15 DAY)), - (3, 'Melee weapon heavy shield 100cm', 18, 35, 20, NULL, 3.06, NULL, NULL, 23, util.VN_CURDATE()), - (4, 'Melee weapon combat first 15cm', 18, 35, 15, NULL, 1.30, NULL, NULL, 11, util.VN_CURDATE()), - (5, 'Melee weapon combat first 15cm', 18, 35, 15, 4, 1.30, 0, NULL, 18, util.VN_CURDATE()); - -INSERT INTO `vn`.`ticketServiceType`(`id`, `name`, `expenseFk`) - VALUES - (1, 'Porte Agencia', 7001000000), - (2, 'Portes Retorno', 7001000000), - (3, 'Porte Carry', 7001000000), - (4, 'Cargo FITOSANITARIO', 4751000000), - (5, 'Documentos', 2000000000); - -INSERT INTO `vn`.`ticketService`(`id`, `description`, `quantity`, `price`, `taxClassFk`, `ticketFk`, `ticketServiceTypeFk`) - VALUES - (1, 'Documentos', 1, 2.00, 1, 1, 1), - (2, 'Porte Agencia', 1, 10.00, 1, 2, 1), - (3, 'Documentos', 1, 5.50, 1, 11, 1), - (4, 'Documentos', 1, 2.00, 1, 9, 1), - (5, 'Documentos', 1, 2.00, 1, 8, 1); - -INSERT INTO `pbx`.`sip`(`user_id`, `extension`) - VALUES - (1, 1010), - (3, 1101), - (5, 1102), - (9, 1201); - -INSERT INTO `vn`.`professionalCategory` (`id`, `name`, `level`, `dayBreak`) - VALUES - (1, 'employee', NULL, NULL), - (2, 'florist', NULL, NULL); - -INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) - VALUES - (1, 'General schedule', 40, 0); - -INSERT INTO `vn`.`workerBusinessAgreement` (`id`, `name`, `monthHolidays`, `yearHours`, `started`, `ended`) - VALUES(1, 'flowers', 2.5, 1830, '2001-01-01', NULL); - -DROP TEMPORARY TABLE IF EXISTS tmp.worker; -CREATE TEMPORARY TABLE tmp.worker - (PRIMARY KEY (id)) - ENGINE = MEMORY - SELECT w.id, w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-25') as started, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)), '-12-25') as ended, CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` - FROM `vn`.`worker` `w`; - -INSERT INTO `vn`.`business`(`id`, `workerFk`, `companyCodeFk`, `started`, `ended`, `workerBusiness`, `reasonEndFk`, `notes`, `departmentFk`, `workerBusinessProfessionalCategoryFk`, `calendarTypeFk`, `isHourlyLabor`, `workerBusinessAgreementFk`, `workcenterFk`) - SELECT * FROM tmp.worker; - -DROP TEMPORARY TABLE IF EXISTS tmp.worker; -CREATE TEMPORARY TABLE tmp.worker - (PRIMARY KEY (id)) - ENGINE = MEMORY - SELECT '1111' as 'id', w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-12-25') as started, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-24') as ended, CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` - FROM `vn`.`worker` `w` - WHERE `w`.`id` = 1109; - -INSERT INTO `vn`.`business` (`id`, `workerFk`, `companyCodeFk`, `started`, `ended`, `workerBusiness`, `reasonEndFk`, `notes`, `departmentFk`, `workerBusinessProfessionalCategoryFk`, `calendarTypeFk`, `isHourlyLabor`, `workerBusinessAgreementFk`, `workcenterFk`) - SELECT * FROM tmp.worker; - -DROP TEMPORARY TABLE IF EXISTS tmp.worker; - -UPDATE `vn`.`business` - SET `payedHolidays`= 8 - WHERE `id`= 1106; - -UPDATE `vn`.`business` b - SET b.`workerBusinessProfessionalCategoryFk` = 2 - WHERE b.`workerFk` = 1110; - -UPDATE `vn`.`business` b - SET b.`departmentFk` = 43 - WHERE b.id IN(18, 19); - -UPDATE `vn`.`business` b - SET b.`started` = b.`started` - INTERVAL 100 DAY - WHERE b.id = 1107; - -INSERT INTO `vn`.`workCenterHoliday` (`workCenterFk`, `days`, `year`) - VALUES - ('1', '27.5', YEAR(util.VN_CURDATE())), - ('5', '22', YEAR(util.VN_CURDATE())), - ('1', '24.5', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR))), - ('5', '23', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR))); - -INSERT INTO `vn`.`workerBusinessType` (`id`, `name`, `isFullTime`, `isPermanent`, `hasHolidayEntitlement`) - VALUES - (1, 'CONTRATO HOLANDA', 1, 0, 1), - (100, 'INDEFINIDO A TIEMPO COMPLETO', 1, 1, 1), - (109, 'CONVERSION DE TEMPORAL EN INDEFINIDO T.COMPLETO', 1, 1, 1); - -UPDATE `vn`.`business` b - SET `rate` = 7, - `workerBusinessTypeFk` = 100, - `amount` = 900.50 - WHERE b.id = 1; - -UPDATE `vn`.`business` b - SET `rate` = 7, - `workerBusinessTypeFk` = 100, - `amount` = 1263.03 - WHERE b.id = 1106; - -UPDATE `vn`.`business` b - SET `rate` = 7, - `workerBusinessTypeFk` = 100, - `amount` = 2000 - WHERE b.id = 1107; - -UPDATE `vn`.`business` b - SET `rate` = 7, - `workerBusinessTypeFk` = 100, - `amount` = 1500 - WHERE b.id = 1108; - -INSERT INTO `vn`.`absenceType` (`id`, `name`, `rgb`, `code`, `holidayEntitlementRate`, `discountRate`) - VALUES - (1, 'Holidays', '#FF4444', 'holiday', 0, 0), - (2, 'Leave of absence', '#C71585', 'absence', 0, 1), - (6, 'Half holiday', '#E65F00', 'halfHoliday', 0, 0.5), - (15, 'Half Paid Leave', '#5151c0', 'halfPaidLeave', 0, 1), - (20, 'Furlough', '#97B92F', 'furlough', 1, 1), - (21, 'Furlough half day', '#778899', 'halfFurlough', 0.5, 1); - -INSERT INTO `vn`.`calendar` (`businessFk`, `dayOffTypeFk`, `dated`) - VALUES - (1, 6, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 10 DAY, util.VN_CURDATE() + INTERVAL 10 DAY)), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 10 DAY, util.VN_CURDATE() + INTERVAL 10 DAY)), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 11 DAY, util.VN_CURDATE() + INTERVAL 11 DAY)), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 12 DAY, util.VN_CURDATE() + INTERVAL 12 DAY)), - (1106, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 20 DAY, util.VN_CURDATE() + INTERVAL 20 DAY)), - (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 13 DAY, util.VN_CURDATE() + INTERVAL 8 DAY)), - (1106, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 14 DAY, util.VN_CURDATE() + INTERVAL 9 DAY)), - (1106, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 15 DAY, util.VN_CURDATE() + INTERVAL 7 DAY)), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 10 DAY, util.VN_CURDATE() + INTERVAL 10 DAY)), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 11 DAY, util.VN_CURDATE() + INTERVAL 11 DAY)), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 12 DAY, util.VN_CURDATE() + INTERVAL 12 DAY)), - (1107, 1, IF(MONTH(util.VN_CURDATE()) = 12 AND DAY(util.VN_CURDATE()) > 10, util.VN_CURDATE() - INTERVAL 20 DAY, util.VN_CURDATE() + INTERVAL 20 DAY)), - (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 13 DAY, util.VN_CURDATE() + INTERVAL 8 DAY)), - (1107, 1, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 14 DAY, util.VN_CURDATE() + INTERVAL 9 DAY)), - (1107, 2, IF(MONTH(util.VN_CURDATE()) >= 1 AND DAY(util.VN_CURDATE()) > 20, util.VN_CURDATE() - INTERVAL 15 DAY, util.VN_CURDATE() + INTERVAL 7 DAY)), - (1107, 2, util.VN_CURDATE() - INTERVAL 16 DAY); - -INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`, `apiKey`) - VALUES - ('1', 'https://api.gateway360.com/api/3.0/sms/send', 'Verdnatura', '5715476da95b46d686a5a255e6459523'); - -INSERT INTO `vn`.`sharingClient`(`id`, `workerFk`, `started`, `ended`, `clientFk`) - VALUES - (1, 19, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY), 1101), - (2, 18, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY), 1106); - -INSERT INTO `vn`.`sharingCart`(`id`, `workerFk`, `started`, `ended`, `workerSubstitute`, `created`) - VALUES - (1, 18, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY), 19, DATE_ADD(util.VN_CURDATE(), INTERVAL -5 DAY)); - -CALL `vn`.zoneGeo_calcTree(); -- this is an auto calculate for table vn.zoneGeo, columns: path,lft,rgt,depth,sons - -INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`) - VALUES - (1, 3, 0), - (1, 4, 0), - (1, 5, 0), - (1, 1, 1), - (2, 3, 0), - (2, 4, 0), - (2, 5, 0), - (2, 1, 1), - (3, 3, 0), - (3, 4, 0), - (3, 5, 0), - (3, 1, 1), - (4, 3, 0), - (4, 4, 0), - (4, 5, 0), - (4, 1, 1), - (5, 3, 1), - (5, 4, 0), - (5, 5, 1), - (5, 1, 1), - (6, 3, 1), - (6, 4, 0), - (6, 5, 1), - (6, 1, 1), - (7, 3, 0), - (7, 4, 0), - (7, 5, 0), - (7, 1, 1), - (8, 3, 0), - (8, 4, 0), - (8, 5, 0), - (8, 1, 1), - (9, 7, 1), - (10, 14, 1); - -INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) - VALUES - (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=2, 2, 9) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=3, 3, 10) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=4, 4, 11) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=5, 5, 12) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (1, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=6, 6, 13) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=2, 2, 9) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=3, 3, 10) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=4, 4, 11) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=5, 5, 12) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (2, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=6, 6, 13) - DAYOFWEEK(util.VN_CURDATE())) DAY)), - (3, 'day', util.VN_CURDATE()), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), - (3, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), - (4, 'day', util.VN_CURDATE()), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), - (4, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), - (5, 'day', util.VN_CURDATE()), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), - (5, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), - (6, 'day', util.VN_CURDATE()), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +7 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +8 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +9 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +10 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +11 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +12 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +13 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +14 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +15 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +16 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +17 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +18 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +19 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +20 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +21 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +22 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +23 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +24 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +25 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +26 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +27 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +28 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +29 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +30 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +31 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +32 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +33 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +34 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +35 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +36 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +37 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +38 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +39 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +40 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +41 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +42 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +43 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +44 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +45 DAY)), - (6, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +46 DAY)), - (7, 'day', util.VN_CURDATE()), - (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY)), - (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +3 DAY)), - (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +4 DAY)), - (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY)), - (7, 'day', DATE_ADD(util.VN_CURDATE(), INTERVAL +6 DAY)); - -INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `weekDays`) - VALUES - (8, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'), - (10, 'indefinitely', 'mon,tue,wed,thu,fri,sat,sun'); - -INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `started`, `ended`, `weekDays`) - VALUES - (9, 'range', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR), 'mon'), - (9, 'range', util.VN_CURDATE(), NULL, 'tue'), - (9, 'range', NULL, util.VN_CURDATE(), 'wed'); - -INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `manual`, `direction`, `isSendMail`) - VALUES - (1106, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in', 0), - (1106, CONCAT(util.VN_CURDATE(), ' 10:00'), TRUE, 'middle', 0), - (1106, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 0), - (1106, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 0), - (1107, CONCAT(util.VN_CURDATE(), ' 07:00'), TRUE, 'in', 1), - (1107, CONCAT(util.VN_CURDATE(), ' 10:00'), TRUE, 'middle', 1), - (1107, CONCAT(util.VN_CURDATE(), ' 10:20'), TRUE, 'middle', 1), - (1107, CONCAT(util.VN_CURDATE(), ' 14:50'), TRUE, 'out', 1); - -INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`) - VALUES - (1, 'Facturas Recibidas', 'recibidas', NULL, NULL, 'invoiceIn'), - (2, 'Doc oficial', 'oficial', NULL, NULL, 'officialDoc'), - (3, 'Laboral', 'laboral', 37, 37, 'hhrrData'), - (4, 'Albaranes recibidos', 'entradas', NULL, NULL, 'deliveryNote'), - (5, 'Otros', 'otros', 1, 1, 'miscellaneous'), - (6, 'Pruebas', 'pruebas', NULL, NULL, 'tests'), - (7, 'IAE Clientes', 'IAE_Clientes', 1, 1, 'economicActivitiesTax'), - (8, 'Fiscal', 'fiscal', NULL, NULL, 'fiscal'), - (9, 'Vehiculos', 'vehiculos', NULL, NULL, 'vehicles'), - (10, 'Plantillas', 'plantillas', NULL, NULL, 'templates'), - (11, 'Contratos', 'contratos', NULL, NULL, 'contracts'), - (12, 'ley de pagos', 'ley pagos', 1, 1, 'paymentsLaw'), - (13, 'Basura', 'basura', 1, 1, 'trash'), - (14, 'Ticket', 'tickets', 1, 1, 'ticket'), - (15, 'Presupuestos', 'Presupuestos', NULL, NULL, 'budgets'), - (16, 'Logistica', 'logistica', NULL, NULL, 'logistics'), - (17, 'cmr', 'cmr', NULL, NULL, 'cmr'), - (18, 'dua', 'dua', NULL, NULL, 'dua'), - (19, 'inmovilizado', 'inmovilizado', NULL, NULL, 'fixedAssets'), - (20, 'Reclamación', 'reclamacion', 1, 1, 'claim'); - -INSERT INTO `vn`.`dms`(`id`, `dmsTypeFk`, `file`, `contentType`, `workerFk`, `warehouseFk`, `companyFk`, `hardCopyNumber`, `hasFile`, `reference`, `description`, `created`) - VALUES - (1, 14, '1.txt', 'text/plain', 5, 1, 442, NULL, FALSE, 'Ticket:11', 'Ticket:11 dms for the ticket', util.VN_CURDATE()), - (2, 5, '2.txt', 'text/plain', 5, 1, 442, 1, TRUE, 'Client:104', 'Client:104 dms for the client', util.VN_CURDATE()), - (3, 5, '3.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Client: 104', 'Client:104 readme', util.VN_CURDATE()), - (4, 3, '4.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'Worker: 106', 'Worker:106 readme', util.VN_CURDATE()), - (5, 5, '5.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'travel: 1', 'dmsForThermograph', util.VN_CURDATE()), - (6, 5, '6.txt', 'text/plain', 5, 1, 442, NULL, TRUE, 'NotExists', 'DoesNotExists', util.VN_CURDATE()), - (7, 20, '7.jpg', 'image/jpeg', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()), - (8, 20, '8.mp4', 'video/mp4', 9, 1, 442, NULL, FALSE, '1', 'TICKET ID DEL CLIENTE BRUCE WAYNE ID 1101', util.VN_CURDATE()); - -INSERT INTO `vn`.`claimDms`(`claimFk`, `dmsFk`) - VALUES - (1, 7), - (1, 8); - -INSERT INTO `vn`.`ticketDms`(`ticketFk`, `dmsFk`) - VALUES - (11, 1); - -INSERT INTO `vn`.`clientDms`(`clientFk`, `dmsFk`) - VALUES - (1104, 2), - (1104, 3); - -INSERT INTO `vn`.`workerDocument`(`id`, `worker`, `document`,`isReadableByWorker`) - VALUES - (1, 1106, 4, TRUE), - (2, 1107, 3, FALSE); - -INSERT INTO `vn`.`device` (`sn`, `model`, `userFk`) - VALUES - ('aaa', 'android', '9'); - -INSERT INTO `vn`.`queuePriority`(`id`, `priority`, `code`) - VALUES - (1, 'Alta', 'high'), - (2, 'Normal', 'normal'), - (3, 'Baja', 'low'); - -INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `weekScope`, `dayWorkMax`, `dayStayMax`, `weekMaxBreak`, `weekMaxScope`, `askInOut`) - VALUES - (1, 43200, 129600, 734400, 43200, 50400, 259200, 1296000, 36000); - -INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11'); - -INSERT INTO `vn`.`thermograph`(`id`, `model`) - VALUES - ('TMM190901395', 'TEMPMATE'), - ('TL.BBA85422', 'TL30'), - ('TZ1905012010', 'DISPOSABLE'), - ('138350-0', 'DISPOSABLE'); - - -INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `result`, `dmsFk`) - VALUES - ('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', 'Ok', NULL), - ('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL), - ('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL), - ('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5), - ('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5), - ('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL); - -REPLACE INTO `vn`.`incoterms`(`code`, `name`) - VALUES - ('FAS', 'Free Alongside Ship'); - -REPLACE INTO `vn`.`customsAgent`(`id`, `fiscalName`, `street`, `nif`, `phone`, `email`) - VALUES - (1, 'Agent one', '1007 Mountain Drive, Gotham', 'N1111111111', '111111111', 'agentone@gotham.com'), - (2, 'Agent two', '1007 Mountain Drive, Gotham', 'N2222222222', '222222222', 'agenttwo@gotham.com'); - -INSERT INTO `vn`.`tablet`(`uuid`, `name`, `place`, `macwifi`) - VALUES - ('1', 'TEST', 'ON THE FIXTURES', '0'), - ('2', 'DEV', 'OTHER TABLET', '0'); - -INSERT INTO `vn`.`tabletDepartment`(`tabletFk`, `departmentFk`) - VALUES - (1, 23), - (2, 1); - -INSERT INTO `vn`.`campaign`(`code`, `dated`) - VALUES - ('valentinesDay', CONCAT(YEAR(util.VN_CURDATE()), '-02-14')), - ('valentinesDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-02-14')), - ('valentinesDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-02-14')), - ('valentinesDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -3 YEAR)), '-02-14')), - ('mothersDay', CONCAT(YEAR(util.VN_CURDATE()), '-05-05')), - ('mothersDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-05-05')), - ('mothersDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-05-05')), - ('mothersDay', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -3 YEAR)), '-05-05')), - ('allSaints', CONCAT(YEAR(util.VN_CURDATE()), '-11-01')), - ('allSaints', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-11-01')), - ('allSaints', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-11-01')), - ('allSaints', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -3 YEAR)), '-11-01')); - -INSERT INTO `hedera`.`imageCollectionSize`(`id`, `collectionFk`,`width`, `height`) - VALUES - (1, 4, 160, 160); - -INSERT INTO `vn`.`rateConfig`(`rate0`, `rate1`, `rate2`, `rate3`) - VALUES - (36, 31, 25, 21); - -INSERT INTO `vn`.`rate`(`dated`, `warehouseFk`, `rate0`, `rate1`, `rate2`, `rate3`) - VALUES - (DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR), 1, 10, 15, 20, 25), - (util.VN_CURDATE(), 1, 12, 17, 22, 27); - -INSERT INTO `vn`.`dua` (id, code, awbFk__, issued, operated, booked, bookEntried, gestdocFk, customsValue, companyFk) - VALUES - (1, '19ES0028013A481523', 1, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 11276.95, 442), - (2, '21ES00280136115760', 2, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1376.20, 442), - (3, '19ES00280131956004', 3, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 3, 14268.50, 442), - (4, '19ES00280131955995', 4, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 1, 8242.50, 442), - (5, '19ES00280132022070', 5, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 10012.49, 442), - (6, '19ES00280132032308', 6, util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 19914.25, 442), - (7, '19ES00280132025489', 7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 1934.06, 442), - (8, '19ES00280132025490', 8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 3618.52, 442), - (9, '19ES00280132025491', 9, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 7126.23, 442), - (10, '19ES00280132025492', 10, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), util.VN_CURDATE(), util.VN_CURDATE(), util.VN_CURDATE(), 2, 4631.45, 442); - -INSERT INTO `vn`.`duaEntry` (`duaFk`, `entryFk`, `value`, `customsValue`, `euroValue`) - VALUES - (1, 1, 1.00, 1.00, 1.00), - (2, 2, 1.00, 1.00, 1.00), - (3, 3, 1.00, 1.00, 1.00), - (4, 4, 1.00, 1.00, 1.00), - (5, 5, 1.00, 1.00, 1.00), - (6, 6, 1.00, 1.00, 1.00), - (7, 7, 1.00, 1.00, 1.00), - (8, 8, 1.00, 1.00, 1.00); - -REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`) - VALUES - (1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1), - (2, 1002, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1235, 1, 442, 1), - (3, 1003, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1236, 0, 442, 1), - (4, 1004, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1237, 0, 442, 1), - (5, 1005, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1238, 1, 442, 1), - (6, 1006, 'R', 2, util.VN_CURDATE(), util.VN_CURDATE(), 1239, 0, 442, 1), - (7, 1007, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1240, 1, 442, 1), - (8, 1008, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1241, 1, 442, 1), - (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 1, 442, 1), - (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 1, 442, 1); - -INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`, `daysAgo`) - VALUES - (1, -2, '2% retention', 2, 45); - -INSERT INTO `vn`.`invoiceInDueDay`(`invoiceInFk`, `dueDated`, `bankFk`, `amount`) - VALUES - (1, util.VN_CURDATE(), 1, 336.99), - (1, util.VN_CURDATE(), 1, 15.25), - (2, util.VN_CURDATE(), 1, 168), - (2, util.VN_CURDATE(), 1, 55.17), - (3, util.VN_CURDATE(), 1, 87.95), - (3, util.VN_CURDATE(), 1, 7.65), - (4, util.VN_CURDATE(), 1, 373.27), - (4, util.VN_CURDATE(), 1, 73.36), - (5, util.VN_CURDATE(), 1, 64.23), - (6, util.VN_CURDATE(), 1, 32.95), - (7, util.VN_CURDATE(), 1, 58.64); - -INSERT INTO `vn`.`duaInvoiceIn`(`id`, `duaFk`, `invoiceInFk`) - VALUES - (1, 1, 1), - (2, 2, 2), - (3, 3, 3), - (4, 4, 4), - (5, 5, 5), - (6, 6, 6), - (7, 7, 7), - (8, 8, 8), - (9, 9, 9), - (10, 10, 10); - -INSERT INTO `vn`.`invoiceInTax` (`invoiceInFk`, `taxableBase`, `expenseFk`, `foreignValue`, `taxTypeSageFk`, `transactionTypeSageFk`) - VALUES - (1, 99.99, '2000000000', NULL, NULL, NULL), - (2, 999.99, '2000000000', NULL, NULL, NULL), - (3, 1000.50, '2000000000', NULL, NULL, NULL), - (4, 0.50, '2000000000', NULL, NULL, NULL), - (5, 150.50, '2000000000', NULL, NULL, NULL), - (1, 252.25, '4751000000', NULL, 7, 61), - (2, 223.17, '6210000567', NULL, 8, 20), - (3, 95.60, '7001000000', NULL, 8, 35), - (4, 446.63, '7001000000', NULL, 6, 61), - (5, 64.23, '6210000567', NULL, 8, 20), - (6, 29.95, '7001000000', NULL, 7, 20), - (7, 58.64, '6210000567', NULL, 8, 20); - -INSERT INTO `vn`.`invoiceInIntrastat` (`invoiceInFk`, `net`, `intrastatFk`, `amount`, `stems`, `countryFk`) - VALUES - (1, 30.50, 5080000, 10.00, 162, 5), - (1, 10, 6021010, 20.00, 205, 5), - (2, 13.20, 5080000, 15.00, 580, 5), - (2, 16.10, 6021010, 25.00, 80, 5); - -INSERT INTO `vn`.`ticketRecalc`(`ticketFk`) - SELECT t.id - FROM vn.ticket t - LEFT JOIN vn.ticketRecalc tr ON tr.ticketFk = t.id - WHERE tr.ticketFk IS NULL; - -CALL `vn`.`ticket_doRecalc`(); - -UPDATE `vn`.`ticket` - SET refFk = 'T1111111' - WHERE id IN (1,2); - -UPDATE `vn`.`ticket` - SET refFk = 'T2222222' - WHERE id = 3; - -UPDATE `vn`.`ticket` - SET refFk = 'T3333333' - WHERE id = 4; - -UPDATE `vn`.`ticket` - SET refFk = 'T4444444' - WHERE id = 5; - -UPDATE `vn`.`ticket` - SET refFk = 'A1111111' - WHERE id = 6; - -INSERT INTO `vn`.`zoneAgencyMode`(`id`, `agencyModeFk`, `zoneFk`) - VALUES - (1, 1, 1), - (2, 1, 2), - (3, 6, 5), - (4, 7, 1); - -INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `userFk`, `price`, `driverName`) - VALUES - (1, 'val-algemesi', 'RE-001', 'PO-001', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'), - (2, 'alg-valencia', 'RE-002', 'PO-002', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'), - (3, 'alz-algemesi', 'RE-003', 'PO-003', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman'); - -INSERT INTO `vn`.`expeditionTruck` (`id`, `roadmapFk`, `warehouseFk`, `eta`, `description`, `userFk`) - VALUES - (1, 1, 1, DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY), 'Best truck in fleet', 1), - (2, 1, 2, DATE_ADD(util.VN_NOW(), INTERVAL '1 2' DAY_HOUR), 'Second truck in fleet', 1), - (3, 1, 3, DATE_ADD(util.VN_NOW(), INTERVAL '1 4' DAY_HOUR), 'Third truck in fleet', 1), - (4, 2, 1, DATE_ADD(util.VN_NOW(), INTERVAL 3 DAY), 'Truck red', 1); - -INSERT INTO `vn`.`expeditionPallet` (`id`, `truckFk`, `built`, `position`, `isPrint`) - VALUES - (1, 1, util.VN_CURDATE(), 1, 1); - -INSERT INTO `vn`.`expeditionScan` (`id`, `expeditionFk`, `scanned`, `palletFk`) - VALUES - (1, 1, util.VN_CURDATE(), 1), - (2, 2, util.VN_CURDATE(), 1), - (3, 3, util.VN_CURDATE(), 1), - (4, 4, util.VN_CURDATE(), 1), - (5, 5, util.VN_CURDATE(), 1), - (6, 6, util.VN_CURDATE(), 1), - (7, 7, util.VN_CURDATE(), 1), - (8, 8, util.VN_CURDATE(), 1), - (9, 9, util.VN_CURDATE(), 1), - (10, 10, util.VN_CURDATE(), 1); - -CALL `cache`.`last_buy_refresh`(FALSE); - -UPDATE `vn`.`item` SET `genericFk` = 9 - WHERE `id` = 2; - -INSERT INTO `bs`.`defaulter` (`clientFk`, `amount`, `created`, `defaulterSinced`) - VALUES - (1101, 500, util.VN_CURDATE(), util.VN_CURDATE()), - (1102, 500, util.VN_CURDATE(), util.VN_CURDATE()), - (1103, 500, util.VN_CURDATE(), util.VN_CURDATE()), - (1107, 500, util.VN_CURDATE(), util.VN_CURDATE()), - (1109, 500, util.VN_CURDATE(), util.VN_CURDATE()); - -UPDATE `vn`.`route` - SET `invoiceInFk`=1 - WHERE `id`=1; - -UPDATE `vn`.`route` - SET `invoiceInFk`=2 - WHERE `id`=2; - -INSERT INTO `bs`.`sale` (`saleFk`, `amount`, `dated`, `typeFk`, `clientFk`) - VALUES - (1, 501.95, util.VN_CURDATE(), 2, 1101), - (2, 70.7, util.VN_CURDATE(), 2, 1101), - (3, 200.78, util.VN_CURDATE(), 2, 1101), - (4, 33.8, util.VN_CURDATE(), 1, 1101), - (30, 34.4, util.VN_CURDATE(), 1, 1108); - -INSERT INTO `vn`.`docuwareConfig` (`url`) - VALUES - ('http://docuware.url/'); - -INSERT INTO `vn`.`calendarHolidaysName` (`id`, `name`) - VALUES - (1, 'dayOfIT'); - -INSERT INTO `vn`.`calendarHolidaysType` (`id`, `name`, `hexColour`) - VALUES - (1, 'National', '#4169E1'); - -INSERT INTO `vn`.`calendarHolidays` (`id`, `calendarHolidaysTypeFk`, `dated`, `calendarHolidaysNameFk`, `workCenterFk`) - VALUES - (1, 1, CONCAT(YEAR(util.VN_CURDATE()), '-12-09'), 1, 1); - -INSERT INTO `vn`.`supplierAgencyTerm` (`agencyFk`, `supplierFk`, `minimumPackages`, `kmPrice`, `packagePrice`, `routePrice`, `minimumKm`, `minimumM3`, `m3Price`) - VALUES - (1, 1, 0, 0.00, 0.00, NULL, 0, 0.00, 23), - (2, 1, 60, 0.00, 0.00, NULL, 0, 5.00, 33), - (3, 2, 0, 15.00, 0.00, NULL, 0, 0.00, 0), - (4, 2, 0, 20.00, 0.00, NULL, 0, 0.00, 0), - (5, 442, 0, 0.00, 3.05, NULL, 0, 0.00, 0); - -INSERT INTO `vn`.`chat` (`senderFk`, `recipient`, `dated`, `checkUserStatus`, `message`, `status`, `attempts`) - VALUES - (1101, '@PetterParker', util.VN_CURDATE(), 1, 'First test message', 0, 'sent'), - (1101, '@PetterParker', util.VN_CURDATE(), 0, 'Second test message', 0, 'pending'); - - -INSERT INTO `vn`.`mobileAppVersionControl` (`appName`, `version`, `isVersionCritical`) - VALUES - ('delivery', '9.2', 0), - ('warehouse', '8.1', 0); - -INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`) - VALUES - ('RE-001', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442), - ('RE-002', 'STILL', 'LTX-20', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442); - -INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed`) - VALUES - (1106, 1, util.VN_CURDATE(), util.VN_CURDATE()), - (1106, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)), - (1106, 2, util.VN_CURDATE(), NULL), - (1106, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 DAY)); - -INSERT INTO `vn`.`zoneExclusion` (`id`, `zoneFk`, `dated`, `created`, `userFk`) -VALUES - (1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=7, 7, 14) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100), - (2, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL (IF(DAYOFWEEK(util.VN_CURDATE())<=8, 8, 15) - DAYOFWEEK(util.VN_CURDATE())) DAY), util.VN_CURDATE(), 100); - -INSERT INTO `vn`.`zoneExclusionGeo` (`zoneExclusionFk`, `geoFk`) - VALUES - (2, 1); - -INSERT INTO `vn`.`mdbBranch` (`name`) - VALUES - ('test'), - ('master'); - -INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`) - VALUES - ('tpv', 'test', '1'), - ('lab', 'master', '1'); - -INSERT INTO `vn`.`accountingConfig` (`id`, `minDate`, `maxDate`) - VALUES - (1, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-01-01'), CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)), '-01-01')); - - -INSERT INTO `vn`.`saleGroup` (`userFk`, `parkingFk`, `sectorFk`) - VALUES - (1, 1, 1); - -INSERT INTO `vn`.`saleGroupDetail` (`saleFk`, `saleGroupFk`) - VALUES - (31, 1); - -INSERT INTO `vn`.`sectorCollection` (`userFk`, `sectorFk`) - VALUES - (1, 1); - -INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk`) - VALUES - (1, 1); - -INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`, `maxTimeToBreak`, `maxWorkShortCycle`, `maxWorkLongCycle`) - VALUES - (1, 43200, 32400, 129600, 259200, 1080000, '', 'imap.verdnatura.es', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.00, 0.33, 40, '22:00:00', '06:00:00', 72000, 1200, 18000, 72000, 6, 13, 28800, 32400, 3600, 561600, 950400); - -INSERT INTO `vn`.`host` (`id`, `code`, `description`, `warehouseFk`, `bankFk`) - VALUES - (1, 'pc1', 'pc host', 1, 1); - -INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`) - VALUES - (1, 'h1', 1, ''); - -INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGroupKey`, `avgBoxingTime`) - VALUES - ('', 'SHINNOBI_TOKEN', 'GROUP_TOKEN', 6000); -INSERT INTO `util`.`notificationConfig` - SET `cleanDays` = 90; - -INSERT INTO `util`.`notification` (`id`, `name`, `description`) - VALUES - (1, 'print-email', 'notification fixture one'), - (2, 'invoice-electronic', 'A electronic invoice has been generated'), - (3, 'not-main-printer-configured', 'A printer distinct than main has been configured'), - (4, 'supplier-pay-method-update', 'A supplier pay method has been updated'), - (5, 'modified-entry', 'An entry has been modified'), - (6, 'book-entry-deleted', 'accounting entries deleted'); - -INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) - VALUES - (1, 9), - (1, 1), - (2, 1), - (3, 9), - (4, 1), - (5, 9), - (6, 9); - -INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) - VALUES - (1, 'print-email', '{"id": "1"}', 9, 'pending', util.VN_CURDATE()), - (2, 'print-email', '{"id": "2"}', null, 'pending', util.VN_CURDATE()), - (3, 'print-email', null, null, 'pending', util.VN_CURDATE()); - -INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) - VALUES - (1, 1109), - (1, 1110), - (2, 1110), - (4, 1110), - (2, 1109), - (1, 9), - (1, 3), - (6, 9); - - -INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) - VALUES - (1, 9); - -INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) - VALUES - (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6); - -INSERT INTO `vn`.`collection` (`id`, `created`, `workerFk`, `stateFk`, `itemPackingTypeFk`, `saleTotalCount`, `salePickedCount`, `trainFk`, `sectorFk`, `wagons`) - VALUES - (3, util.VN_NOW(), 1107, 5, NULL, 0, 0, 1, NULL, NULL); - -INSERT INTO `vn`.`itemConfig` (`id`, `isItemTagTriggerDisabled`, `monthToDeactivate`, `wasteRecipients`, `validPriorities`, `defaultPriority`, `defaultTag`, `warehouseFk`) - VALUES - (0, 0, 24, '', '[1,2,3]', 2, 56, 60); - -INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`) - VALUES - (9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL); - -INSERT INTO `vn`.`saleCloned` (`saleClonedFk`, `saleOriginalFk`) - VALUES - (29, 25); - -UPDATE `account`.`user` - SET `hasGrant` = 1 - WHERE `id` = 66; - -INSERT INTO `vn`.`ticketLog` (`originFk`, userFk, `action`, changedModel, oldInstance, newInstance, changedModelId, `description`) - VALUES - (7, 18, 'update', 'Sale', '{"quantity":1}', '{"quantity":10}', 22, NULL), - (7, 18, 'update', 'Ticket', '{"quantity":1,"concept":"Chest ammo box"}', '{"quantity":10,"concept":"Chest ammo box"}', 22, NULL), - (7, 18, 'update', 'Sale', '{"price":3}', '{"price":5}', 22, NULL), - (7, 18, 'update', NULL, NULL, NULL, NULL, "Cambio cantidad Melee weapon heavy shield 100cm de '5' a '10'"), - (16, 9, 'update', 'Sale', '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', '{"quantity":8,"concept":"Shield", "price": 10.5, "itemFk": 1}' , 12, 'Shield'); - - -INSERT INTO `vn`.`ticketLog` (originFk, userFk, `action`, creationDate, changedModel, changedModelId, changedModelValue, oldInstance, newInstance, description) - VALUES - (1, NULL, 'delete', '2001-06-09 11:00:04', 'Ticket', 45, 'Spider Man' , NULL, NULL, NULL), - (1, 18, 'select', '2001-06-09 11:00:03', 'Ticket', 45, 'Spider Man' , NULL, NULL, NULL), - (1, NULL, 'update', '2001-05-09 10:00:02', 'Sale', 5, 'Armor' , '{"isPicked": false}','{"isPicked": true}', NULL), - (1, 18, 'update', '2001-01-01 10:05:01', 'Sale', 5, 'Armor' , NULL, NULL, 'Armor quantity changed from ''15'' to ''10'''), - (1, NULL, 'delete', '2001-01-01 10:00:10', 'Sale', 4, 'Shield' , '{"quantity":10,"concept":"Shield"}', NULL, NULL), - (1, 18, 'insert', '2000-12-31 15:00:05', 'Sale', 1, 'Armor' , NULL,'{"quantity":15,"concept":"Armor", "price": 345.99, "itemFk": 2}', NULL), - (1, 18, 'update', '2000-12-28 08:40:45', 'Ticket', 45, 'Spider Man' , '{"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"isBlocked":false,"hasPriority":false,"companyFk":442,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}','{"warehouseFk":61,"shipped":"2023-05-17T22:00:00.000Z","nickname":"Spider Man","isSigned":false,"isLabeled":false,"isPrinted":false,"packages":1,"hour":0,"isBlocked":true,"hasPriority":true,"companyFk":443,"landed":"2023-05-18T22:00:00.000Z","isBoxed":false,"isDeleted":false,"zoneFk":713,"zonePrice":13,"zoneBonus":1}', NULL), - (1, 18, 'select', '2000-12-27 03:40:30', 'Ticket', 45, NULL , NULL, NULL, NULL), - (1, 18, 'insert', '2000-04-10 09:40:15', 'Sale', 4, 'Shield' , NULL, '{"quantity":10,"concept":"Shield", "price": 10.5, "itemFk": 1}', NULL), - (1, 18, 'insert', '1999-05-09 10:00:00', 'Ticket', 45, 'Super Man' , NULL, '{"id":45,"clientFk":8608,"warehouseFk":60,"shipped":"2023-05-16T22:00:00.000Z","nickname":"Super Man","addressFk":48637,"isSigned":true,"isLabeled":true,"isPrinted":true,"packages":0,"hour":0,"created":"2023-05-16T11:42:56.000Z","isBlocked":false,"hasPriority":false,"companyFk":442,"agencyModeFk":639,"landed":"2023-05-17T22:00:00.000Z","isBoxed":true,"isDeleted":true,"zoneFk":713,"zonePrice":13,"zoneBonus":0}', NULL); -INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) - VALUES - (0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', '1,6', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all'); - -INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`) - VALUES - ('foo', 'master', NULL, NULL), - ('bar', 'test', 9, util.VN_NOW()); - -INSERT INTO `vn`.`profileType` (`id`, `name`) - VALUES - (1, 'working'); - -INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) - VALUES - ('lilium', 'development', 'http://localhost:9000/#/'), - ('hedera', 'development', 'http://localhost:9090/'), - ('salix', 'development', 'http://localhost:5000/#!/'); - -INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`) - VALUES - (3, 'invoice', NULL, 'InvoiceOuts/{refFk}/invoice-out-pdf'); - -INSERT INTO `vn`.`payDemDetail` (`id`, `detail`) - VALUES - (1, 1), - (2, 20), - (7, 1); - -INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk`, `businessTypeFk`) - VALUES - (1, NULL, 1, 4, 'worker'); - -INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) - VALUES - (24, 8); - -INSERT INTO `vn`.`deviceProductionModels` (`code`) - VALUES - ('BLACKVIEW'), - ('DODGEE'), - ('ZEBRA'); - -INSERT INTO `vn`.`deviceProductionState` (`code`, `description`) - VALUES - ('active', 'activo'), - ('idle', 'inactivo'), - ('lost', 'perdida'), - ('repair', 'reparación'), - ('retired', 'retirada'); - -INSERT INTO `vn`.`deviceProduction` (`imei`, `modelFk`, `macWifi`, `serialNumber`, `android_id`, `purchased`, `stateFk`, `isInScalefusion`, `description`) -VALUES - ('ime1', 'BLACKVIEW', 'macWifi1', 'serialNumber1', 'androidid11234567890', util.VN_NOW(), 'active', 0, NULL), - ('ime2', 'DODGEE', 'macWifi2', 'serialNumber2', 'androidid21234567890', util.VN_NOW(), 'idle', 0, NULL), - ('ime3', 'ZEBRA', 'macWifi3', 'serialNumber3', 'androidid31234567890', util.VN_NOW(), 'active', 0, NULL), - ('ime4', 'BLACKVIEW', 'macWifi4', 'serialNumber4', 'androidid41234567890', util.VN_NOW(), 'idle', 0, NULL); - -INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `created`) - VALUES - (1, 1, util.VN_NOW()), - (3, 3, util.VN_NOW()); - -INSERT INTO `vn`.`workerTimeControlMail` (`id`, `workerFk`, `year`, `week`, `state`, `updated`, `sendedCounter`, `reason`) - VALUES - (1, 9, 2000, 49, 'REVISE', util.VN_NOW(), 1, 'test2'), - (2, 9, 2000, 50, 'SENDED', util.VN_NOW(), 1, NULL), - (3, 9, 2000, 51, 'CONFIRMED', util.VN_NOW(), 1, NULL), - (4, 9, 2001, 1, 'SENDED', util.VN_NOW(), 1, NULL); - -INSERT INTO `vn`.`wagonConfig` (`id`, `width`, `height`, `maxWagonHeight`, `minHeightBetweenTrays`, `maxTrays`) - VALUES - (1, 1350, 1900, 200, 50, 6); - -INSERT INTO `vn`.`wagonTypeColor` (`id`, `name`, `rgb`) - VALUES - (1, 'white', '#ffffff'), - (2, 'red', '#ff0000'), - (3, 'green', '#00ff00'), - (4, 'blue', '#0000ff'); - -INSERT INTO `vn`.`wagonType` (`id`, `name`, `divisible`) - VALUES - (1, 'Wagon Type #1', 1); - -INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`) - VALUES - (1, 1, 100, 1), - (2, 1, 50, 2), - (3, 1, 0, 3); - -INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`) - VALUES - (1, 21600, 60, 300); - -INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`) - VALUES - (1, 1, 1, 1, 442); - -INSERT INTO `vn`.`buyConfig` (`id`, `monthsAgo`) - VALUES - (1, 6); - -INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `taxAreaFk`) - VALUES - ('C', 'Asgard', 1, 'WORLD'), - ('E', 'Midgard', 1, 'CEE'), - ('R', 'Jotunheim', 1, 'NATIONAL'), - ('W', 'Vanaheim', 1, 'WORLD'); - - -INSERT INTO `hedera`.`imageConfig` (`id`, `maxSize`, `useXsendfile`, `url`) - VALUES - (1, 0, 0, 'marvel.com'); - -INSERT INTO vn.XDiario (id, ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, BASEEURO, SERIE, FACTURA, IVA, RECEQUIV, CLAVE, CAMBIO, DEBEME, HABERME, AUXILIAR, MONEDAUSO, TIPOOPE, NFACTICK, TERIDNIF, TERNIF, TERNOM, OPBIENES, L340, enlazado, FECHA_EX, LRECT349, empresa_id, LDIFADUAN, METAL, METALIMP, CLIENTE, METALEJE, FECHA_OP, FACTURAEX, TIPOCLAVE, TIPOEXENCI, TIPONOSUJE, TIPOFACT, TIPORECTIF, SERIE_RT, FACTU_RT, BASEIMP_RT, BASEIMP_RF, RECTIFICA, FECHA_RT, FECREGCON, enlazadoSage) - VALUES - (1, 1.0, util.VN_CURDATE(), '4300001104', NULL, 'n/fra T3333333', 8.88, NULL, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), - (2, 1.0, util.VN_CURDATE(), '2000000000', '4300001104', 'n/fra T3333333 Tony Stark', NULL, 8.07, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), - (3, 1.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T3333333 Tony Stark', NULL, 0.81, 8.07, 'T', '3333333', 10.00, NULL, NULL, NULL, NULL, NULL, '', '2', '', 1, 1, '06089160W', 'IRON MAN', 1, 1, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, 1, 1, 1, 1, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 1), - (4, 2.0, util.VN_CURDATE(), '4300001104', NULL, 'n/fra T4444444', 8.88, NULL, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0), - (5, 2.0, util.VN_CURDATE(), '2000000000', '4300001104', 'n/fra T4444444 Tony Stark', NULL, 8.07, NULL, NULL, '0', NULL, 0.00, NULL, NULL, NULL, NULL, NULL, '2', NULL, 1, 2, 'I.F.', 'Nombre Importador', 1, 0, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0), - (6, 2.0, util.VN_CURDATE(), '4770000010', '4300001104', 'Inmovilizado pendiente : n/fra T4444444 Tony Stark', NULL, 0.81, 8.07, 'T', '4444444', 10.00, NULL, NULL, NULL, NULL, NULL, '', '2', '', 1, 1, '06089160W', 'IRON MAN', 1, 1, 0, util.VN_CURDATE(), 0, 442, 0, 0, 0.00, NULL, NULL, util.VN_CURDATE(), NULL, 1, 1, 1, 1, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0); - -INSERT INTO `vn`.`mistakeType` (`id`, `description`) - VALUES - (1, 'Incorrect quantity'); - -INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`) - VALUES - (1, 'Error in VAT calculation'), - (2, 'Error in sales details'), - (3, 'Error in customer data'); - -UPDATE `vn`.`client` - SET fi='65004204V' - WHERE id=1; - -UPDATE `vn`.`worker` - SET fi='59328808D' - WHERE id=1106; - - -INSERT INTO `account`.`mailAliasAcl` (`mailAliasFk`, `roleFk`) - VALUES - (1, 1), - (2, 9), - (3, 15); - -INSERT INTO `vn`.`docuwareTablet` (`tablet`,`description`) - VALUES - ('Tablet1','Jarvis tablet'), - ('Tablet2','Avengers tablet'); - -INSERT INTO `vn`.`sms` (`id`, `senderFk`, `sender`, `destination`, `message`, `statusCode`, `status`, `created`) - VALUES (1, 66, '111111111', '0001111111111', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()), - (2, 66, '222222222', '0002222222222', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'PENDING', util.VN_CURDATE()), - (3, 66, '333333333', '0003333333333', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'ERROR', util.VN_CURDATE()), - (4, 66, '444444444', '0004444444444', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()); - -INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`) - VALUES(1, 1103, 1, NULL), - (2, 1103, 2, NULL), - (3, 1103, 3, 32), - (4, 1103, 4, 32), - (13, 1101, 1, NULL), - (14, 1101, 4, 27); diff --git a/db/routines/bs/procedures/clean.sql b/db/routines/bs/procedures/clean.sql index 3c29553f5..eff2faadb 100644 --- a/db/routines/bs/procedures/clean.sql +++ b/db/routines/bs/procedures/clean.sql @@ -1,10 +1,11 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`clean`() BEGIN - DECLARE vFourYearsAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; - DECLARE vOneYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; - DECLARE vTwoYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 3 YEAR; - DECLARE vThreeYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; + + DECLARE vOneYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 1 YEAR; + DECLARE vTwoYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; + DECLARE vThreeYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 3 YEAR; + DECLARE vFourYearsAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 4 YEAR; DECLARE vEighteenMonths DATE DEFAULT util.VN_CURDATE() - INTERVAL 18 MONTH; DELETE FROM clientNewBorn diff --git a/db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql b/db/routines/bs/triggers/clientNewBorn_beforeUpdate.sql similarity index 92% rename from db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql rename to db/routines/bs/triggers/clientNewBorn_beforeUpdate.sql index ac68eedb8..a88567a21 100644 --- a/db/routines/bs/triggers/clientNewBorn_BEFORE_UPDATE.sql +++ b/db/routines/bs/triggers/clientNewBorn_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`clientNewBorn_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`clientNewBorn_beforeUpdate` BEFORE UPDATE ON `clientNewBorn` FOR EACH ROW BEGIN diff --git a/db/routines/bs/triggers/nightTaskBeforeInsert.sql b/db/routines/bs/triggers/nightTask_beforeInsert.sql similarity index 94% rename from db/routines/bs/triggers/nightTaskBeforeInsert.sql rename to db/routines/bs/triggers/nightTask_beforeInsert.sql index b32aaf7f5..96f2b5291 100644 --- a/db/routines/bs/triggers/nightTaskBeforeInsert.sql +++ b/db/routines/bs/triggers/nightTask_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`nightTaskBeforeInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`nightTask_beforeInsert` BEFORE INSERT ON `nightTask` FOR EACH ROW BEGIN diff --git a/db/routines/bs/triggers/nightTaskBeforeUpdate.sql b/db/routines/bs/triggers/nightTask_beforeUpdate.sql similarity index 94% rename from db/routines/bs/triggers/nightTaskBeforeUpdate.sql rename to db/routines/bs/triggers/nightTask_beforeUpdate.sql index fd7fdc0df..1da1da8c3 100644 --- a/db/routines/bs/triggers/nightTaskBeforeUpdate.sql +++ b/db/routines/bs/triggers/nightTask_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`nightTaskBeforeUpdate` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `bs`.`nightTask_beforeUpdate` BEFORE UPDATE ON `nightTask` FOR EACH ROW BEGIN diff --git a/db/routines/edi/procedures/ekt_load.sql b/db/routines/edi/procedures/ekt_load.sql index d07f45ba8..920226693 100644 --- a/db/routines/edi/procedures/ekt_load.sql +++ b/db/routines/edi/procedures/ekt_load.sql @@ -1,7 +1,12 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`ekt_load`(IN `vSelf` INT) proc:BEGIN - +/** + * Carga los datos esenciales para el sistema EKT. + * Inserta compras y ventas si es necesario. + * + * @param vSelf Id de ekt + */ DECLARE vRef INT; DECLARE vBuy INT; DECLARE vItem INT; @@ -9,42 +14,37 @@ proc:BEGIN DECLARE vPackage INT; DECLARE vPutOrderFk INT; DECLARE vIsLot BOOLEAN; - DECLARE vForceToPacking INT DEFAULT 2; - DECLARE vEntryFk INT; - DECLARE vHasToChangePackagingFk BOOLEAN; - DECLARE vIsFloramondoDirect BOOLEAN; - DECLARE vTicketFk INT; + DECLARE vForceToPacking INT DEFAULT 2; + DECLARE vEntryFk INT; + DECLARE vHasToChangePackagingFk BOOLEAN; + DECLARE vIsFloramondoDirect BOOLEAN; + DECLARE vTicketFk INT; DECLARE vHasItemGroup BOOL; DECLARE vDescription VARCHAR(255); DECLARE vSaleFk INT; -- Carga los datos necesarios del EKT - - SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), + SELECT e.ref, qty, package, putOrderFk MOD 1000000, i2.id , NOT ISNULL(eea.addressFk), NOT ISNULL(igto.group_code), CONCAT(e.`ref`, ' ', e.item, ' ', e.sub, ' EktFk:', e.id) INTO vRef, vQty, vPackage, vPutOrderFk, vItem, vIsFloramondoDirect, vHasItemGroup, vDescription - FROM edi.ekt e - LEFT JOIN edi.item i ON e.ref = i.id - LEFT JOIN edi.putOrder po ON po.id = e.putOrderFk + FROM ekt e + LEFT JOIN item i ON e.ref = i.id + LEFT JOIN putOrder po ON po.id = e.putOrderFk LEFT JOIN vn.item i2 ON i2.supplyResponseFk = po.supplyResponseID LEFT JOIN vn.ektEntryAssign eea ON eea.sub = e.sub - LEFT JOIN edi.item_groupToOffer igto ON igto.group_code = i.group_id + LEFT JOIN item_groupToOffer igto ON igto.group_code = i.group_id WHERE e.id = vSelf LIMIT 1; - + IF NOT vHasItemGroup THEN - CALL vn.mail_insert('logistica@verdnatura.es', 'nocontestar@verdnatura.es', 'Nuevo grupo en Floramondo', vDescription); - CALL vn.mail_insert('pako@verdnatura.es', 'nocontestar@verdnatura.es', CONCAT('Nuevo grupo en Floramondo: ', vDescription), vDescription); - LEAVE proc; - END IF; -- Asigna la entrada - SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; - + SELECT vn.ekt_getEntry(vSelf) INTO vEntryFk; + -- Inserta el cubo si no existe IF vPackage = 800 THEN @@ -57,7 +57,7 @@ proc:BEGIN ELSE - SET vPackage = 8000 + vQty; + SET vPackage = 8000 + vQty; INSERT IGNORE INTO vn.packaging(id, width, `depth`) SELECT vPackage, vc.ccLength / vQty, vc.ccWidth @@ -79,29 +79,25 @@ proc:BEGIN `to` = 'ekt@verdnatura.es'; END IF; END IF; - + -- Si es una compra de Logiflora obtiene el articulo IF vPutOrderFk THEN - SELECT i.id INTO vItem - FROM edi.putOrder po + FROM putOrder po JOIN vn.item i ON i.supplyResponseFk = po.supplyResponseID WHERE po.id = vPutOrderFk LIMIT 1; - END IF; - INSERT IGNORE INTO item_track SET - item_id = vRef; + INSERT IGNORE INTO item_track + SET item_id = vRef; - IF IFNULL(vItem,0) = 0 THEN - + IF vItem IS NULL THEN -- Intenta obtener el artículo en base a los atributos holandeses - SELECT b.id, IFNULL(b.itemOriginalFk ,b.itemFk) INTO vBuy, vItem - FROM edi.ekt e - JOIN edi.item_track t ON t.item_id = e.ref - LEFT JOIN edi.ekt l ON l.ref = e.ref + FROM ekt e + JOIN item_track t ON t.item_id = e.ref + LEFT JOIN ekt l ON l.ref = e.ref LEFT JOIN vn.buy b ON b.ektFk = l.id LEFT JOIN vn.item i ON i.id = b.itemFk JOIN vn2008.config cfg @@ -125,51 +121,44 @@ proc:BEGIN LIMIT 1; END IF; - + -- Si no encuentra el articulo lo crea en el caso de las compras directas en Floramondo - IF ISNULL(vItem) AND vIsFloramondoDirect THEN - - CALL edi.item_getNewByEkt(vSelf, vItem); - + IF vItem IS NULL AND vIsFloramondoDirect THEN + CALL item_getNewByEkt(vSelf, vItem); END IF; - INSERT INTO vn.buy - ( - entryFk - ,ektFk - ,buyingValue - ,itemFk - ,stickers - ,packing - ,`grouping` - ,quantity - ,groupingMode - ,packagingFk - ,weight - ) - SELECT - vEntryFk - ,vSelf - ,(@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue - ,IFNULL(vItem, cfg.generic_item) itemFk - ,e.qty stickers - ,@pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing - ,IFNULL(b.`grouping`, e.pac) - ,@pac * e.qty - ,vForceToPacking - ,IF(vHasToChangePackagingFk OR ISNULL(b.packagingFk), vPackage, b.packagingFk) - ,(IFNULL(i.weightByPiece,0) * @pac)/1000 - FROM edi.ekt e - LEFT JOIN vn.buy b ON b.id = vBuy - LEFT JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN vn.supplier s ON e.pro = s.id - JOIN vn2008.config cfg - WHERE e.id = vSelf - LIMIT 1; + INSERT INTO vn.buy ( + entryFk, + ektFk, + buyingValue, + itemFk, + stickers, + packing, + `grouping`, + quantity, + groupingMode, + packagingFk, + weight) + SELECT vEntryFk, + vSelf, + (@t := IF(i.stems, i.stems, 1)) * e.pri / IFNULL(i.stemMultiplier, 1) buyingValue, + IFNULL(vItem, cfg.generic_item) itemFk, + e.qty stickers, + @pac := IFNULL(i.stemMultiplier, 1) * e.pac / @t packing, + IFNULL(b.`grouping`, e.pac), + @pac * e.qty, + vForceToPacking, + IF(vHasToChangePackagingFk OR b.packagingFk IS NULL, vPackage, b.packagingFk), + (IFNULL(i.weightByPiece, 0) * @pac) / 1000 + FROM ekt e + LEFT JOIN vn.buy b ON b.id = vBuy + LEFT JOIN vn.item i ON i.id = b.itemFk + LEFT JOIN vn.supplier s ON e.pro = s.id + JOIN vn2008.config cfg + WHERE e.id = vSelf + LIMIT 1; - DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; - - CREATE TEMPORARY TABLE tmp.buyRecalc + CREATE OR REPLACE TEMPORARY TABLE tmp.buyRecalc SELECT buy.id FROM vn.buy WHERE ektFk = vSelf; @@ -178,31 +167,26 @@ proc:BEGIN -- Si es una compra de Logiflora hay que informar la tabla vn.saleBuy IF vPutOrderFk THEN - REPLACE vn.saleBuy(saleFk, buyFk, workerFk) SELECT po.saleFk, b.id, account.myUser_getId() - FROM edi.putOrder po + FROM putOrder po JOIN vn.buy b ON b.ektFk = vSelf WHERE po.id = vPutOrderFk; - END IF; - -- Si es una compra directa en Floramondo hay que añadirlo al ticket + -- Si es una compra directa en Floramondo hay que añadirlo al ticket IF vIsFloramondoDirect THEN - SELECT t.id INTO vTicketFk - FROM vn.ticket t - JOIN vn.ektEntryAssign eea - ON eea.addressFk = t.addressFk + FROM vn.ticket t + JOIN vn.ektEntryAssign eea ON eea.addressFk = t.addressFk AND t.warehouseFk = eea.warehouseInFk - JOIN edi.ekt e - ON e.sub = eea.sub + JOIN ekt e ON e.sub = eea.sub AND e.id = vSelf - WHERE e.fec = t.shipped - LIMIT 1; + WHERE e.fec = t.shipped + LIMIT 1; - IF ISNULL(vTicketFk) THEN - + IF vTicketFk IS NULL THEN + SET @clientFk = NULL; INSERT INTO vn.ticket ( clientFk, shipped, @@ -214,21 +198,19 @@ proc:BEGIN landed, zoneFk, zonePrice, - zoneBonus - ) - SELECT - a.clientFk, - e.fec, - a.id, - a.agencyModeFk, - a.nickname, - eea.warehouseInFk, - c.id, - e.fec, - z.id, - z.price, - z.bonus - FROM edi.ekt e + zoneBonus) + SELECT @clientFk := a.clientFk, + e.fec, + a.id, + a.agencyModeFk, + a.nickname, + eea.warehouseInFk, + c.id, + e.fec, + z.id, + z.price, + z.bonus + FROM ekt e JOIN vn.ektEntryAssign eea ON eea.sub = e.sub JOIN vn.address a ON a.id = eea.addressFk JOIN vn.company c ON c.code = 'VNL' @@ -237,40 +219,37 @@ proc:BEGIN LIMIT 1; SET vTicketFk = LAST_INSERT_ID(); - - INSERT INTO vn.ticketLog - SET originFk = vTicketFk, - userFk = account.myUser_getId(), - `action` = 'insert', - description = CONCAT('EktLoad ha creado el ticket:', ' ', vTicketFk); + IF @clientFk IS NULL THEN + CALL util.throw(CONCAT("Ticket creation failed: ", vSelf)); + END IF; END IF; INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, price) SELECT vItem, vTicketFk, e.item, e.qty * e.pac, e.pri * ( 1 + fhc.floramondoMargin ) - FROM edi.ekt e - JOIN edi.floraHollandConfig fhc - WHERE e.id = vSelf; - + FROM ekt e + JOIN floraHollandConfig fhc + WHERE e.id = vSelf; + SELECT LAST_INSERT_ID() INTO vSaleFk; - + REPLACE vn.saleBuy(saleFk, buyFk, workerFk) SELECT vSaleFk, b.id, account.myUser_getId() FROM vn.buy b - WHERE b.ektFk = vSelf; + WHERE b.ektFk = vSelf; INSERT INTO vn.saleComponent(saleFk, componentFk, value) SELECT vSaleFk, c.id, e.pri - FROM edi.ekt e + FROM ekt e JOIN vn.component c ON c.code = 'purchaseValue' - WHERE e.id = vSelf; - + WHERE e.id = vSelf; + INSERT INTO vn.saleComponent(saleFk, componentFk, value) SELECT vSaleFk, c.id, e.pri * fhc.floramondoMargin - FROM edi.ekt e - JOIN edi.floraHollandConfig fhc + FROM ekt e + JOIN floraHollandConfig fhc JOIN vn.component c ON c.code = 'margin' - WHERE e.id = vSelf; + WHERE e.id = vSelf; END IF; DROP TEMPORARY TABLE tmp.buyRecalc; END$$ diff --git a/db/routines/edi/triggers/item_feature_bi.sql b/db/routines/edi/triggers/item_feature_beforeInsert.sql similarity index 90% rename from db/routines/edi/triggers/item_feature_bi.sql rename to db/routines/edi/triggers/item_feature_beforeInsert.sql index 81d16d0c8..4e3e9cc0e 100644 --- a/db/routines/edi/triggers/item_feature_bi.sql +++ b/db/routines/edi/triggers/item_feature_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`item_feature_bi` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`item_feature_beforeInsert` BEFORE INSERT ON `item_feature` FOR EACH ROW BEGIN diff --git a/db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql b/db/routines/edi/triggers/putOrder_afterUpdate.sql similarity index 99% rename from db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql rename to db/routines/edi/triggers/putOrder_afterUpdate.sql index fa34425c9..b56ae4c66 100644 --- a/db/routines/edi/triggers/putOrder_AFTER_UPDATE.sql +++ b/db/routines/edi/triggers/putOrder_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_afterUpdate` AFTER UPDATE ON `putOrder` FOR EACH ROW BEGIN diff --git a/db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql b/db/routines/edi/triggers/putOrder_beforeInsert.sql similarity index 93% rename from db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql rename to db/routines/edi/triggers/putOrder_beforeInsert.sql index c1ac76df5..beddd191c 100644 --- a/db/routines/edi/triggers/putOrder_BEFORE_INSERT.sql +++ b/db/routines/edi/triggers/putOrder_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_beforeInsert` BEFORE INSERT ON `putOrder` FOR EACH ROW BEGIN diff --git a/db/routines/edi/triggers/BEFORE UPDATE.sql b/db/routines/edi/triggers/putOrder_beforeUpdate.sql similarity index 91% rename from db/routines/edi/triggers/BEFORE UPDATE.sql rename to db/routines/edi/triggers/putOrder_beforeUpdate.sql index 1ba9b4b0f..f18b77a0c 100644 --- a/db/routines/edi/triggers/BEFORE UPDATE.sql +++ b/db/routines/edi/triggers/putOrder_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`BEFORE UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`putOrder_beforeUpdate` BEFORE UPDATE ON `putOrder` FOR EACH ROW BEGIN diff --git a/db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql b/db/routines/edi/triggers/supplyResponse_afterUpdate.sql similarity index 96% rename from db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql rename to db/routines/edi/triggers/supplyResponse_afterUpdate.sql index f4115cbb3..389ef9f1c 100644 --- a/db/routines/edi/triggers/supplyResponse_AFTER_UPDATE.sql +++ b/db/routines/edi/triggers/supplyResponse_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`supplyResponse_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `edi`.`supplyResponse_afterUpdate` AFTER UPDATE ON `supplyResponse` FOR EACH ROW BEGIN diff --git a/db/routines/sage/procedures/accountingMovements_add.sql b/db/routines/sage/procedures/accountingMovements_add.sql index ab0477823..bd86e132d 100644 --- a/db/routines/sage/procedures/accountingMovements_add.sql +++ b/db/routines/sage/procedures/accountingMovements_add.sql @@ -22,7 +22,6 @@ BEGIN DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; DECLARE vInvoiceTypeInformativeCode VARCHAR(1); DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2) ; - DECLARE vBookEntries TEXT; SELECT SiglaNacion INTO vCountryCanariasCode FROM Naciones @@ -412,40 +411,5 @@ BEGIN AND importeDivisa > 0 AND ImporteAsiento < 0; - -- Comprobación que los importes e ivas sean correctos, avisa vía CAU - SELECT GROUP_CONCAT(Asiento ORDER BY Asiento ASC SEPARATOR ',') INTO vBookEntries - FROM(SELECT sub.Asiento - FROM (SELECT mc.Asiento, SUM(mc.ImporteAsiento) amount - FROM movConta mc - WHERE mc.enlazadoSage = FALSE - GROUP BY mc.Asiento)sub - JOIN (SELECT x.ASIEN, SUM(IFNULL(x.EURODEBE,0) + IFNULL(x.EUROHABER,0)) amount - FROM vn.XDiario x - WHERE x.enlazadoSage = FALSE - GROUP BY ASIEN)sub2 ON sub2.ASIEN = sub.Asiento - WHERE sub.amount <> sub2.amount - UNION ALL - SELECT sub.Asiento - FROM (SELECT Asiento, SUM(BaseIva1 + BaseIva2 + BaseIva3 + BaseIva4) amountTaxableBase - FROM movConta - WHERE TipoFactura <> 'I' - AND enlazadoSage = FALSE - GROUP BY Asiento) sub - JOIN (SELECT ASIEN, SUM(BASEEURO) amountTaxableBase - FROM (SELECT ASIEN, SUM(BASEEURO) BASEEURO - FROM vn.XDiario - WHERE FACTURA - AND auxiliar <> '*' - AND enlazadoSage = FALSE - GROUP BY FACTURA, ASIEN)sub3 - GROUP BY ASIEN) sub2 ON sub2.ASIEN = sub.Asiento - WHERE sub.amountTaxableBase<>sub2.amountTaxableBase - AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase) sub; - - IF vBookEntries IS NOT NULL THEN - SELECT util.notification_send ("book-entries-imported-incorrectly", - CONCAT('{"bookEntries":"', vBookEntries,'"}'), - null); - END IF; END$$ DELIMITER ; diff --git a/db/routines/sage/procedures/clean.sql b/db/routines/sage/procedures/clean.sql new file mode 100644 index 000000000..f1175c4dc --- /dev/null +++ b/db/routines/sage/procedures/clean.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`clean`() +BEGIN +/** + * Maintains tables over time by removing unnecessary data + */ + DECLARE vTwoYearAgo DATE DEFAULT util.VN_CURDATE() - INTERVAL 2 YEAR; + + DELETE FROM movConta WHERE FechaAsiento < vTwoYearAgo; + +END$$ +DELIMITER ; diff --git a/db/routines/sage/procedures/importErrorNotification.sql b/db/routines/sage/procedures/importErrorNotification.sql new file mode 100644 index 000000000..b070097f4 --- /dev/null +++ b/db/routines/sage/procedures/importErrorNotification.sql @@ -0,0 +1,62 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `sage`.`importErrorNotification`() +BEGIN +/** + * Inserta notificaciones con los errores detectados durante la importación + * + */ + DECLARE vBookEntries TEXT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT GROUP_CONCAT(error SEPARATOR ' ') INTO vBookEntries + FROM( + SELECT CONCAT('- Importes: ', sub.Asiento) error + FROM (SELECT mc.Asiento, SUM(mc.ImporteAsiento) amount + FROM movConta mc + WHERE mc.enlazadoSage = FALSE + GROUP BY mc.Asiento)sub + JOIN (SELECT x.ASIEN, SUM(IFNULL(x.EURODEBE,0) + IFNULL(x.EUROHABER,0)) amount + FROM vn.XDiario x + WHERE x.enlazadoSage = FALSE + GROUP BY ASIEN)sub2 ON sub2.ASIEN = sub.Asiento + WHERE sub.amount <> sub2.amount + UNION ALL + SELECT CONCAT('- Base imponible: ', sub.Asiento) + FROM (SELECT Asiento, SUM(BaseIva1 + BaseIva2 + BaseIva3 + BaseIva4) amountTaxableBase + FROM movConta + WHERE TipoFactura <> 'I' + AND enlazadoSage = FALSE + GROUP BY Asiento) sub + JOIN (SELECT ASIEN, SUM(BASEEURO) amountTaxableBase + FROM (SELECT ASIEN, SUM(BASEEURO) BASEEURO + FROM vn.XDiario + WHERE FACTURA + AND auxiliar <> '*' + AND enlazadoSage = FALSE + GROUP BY FACTURA, ASIEN)sub3 + GROUP BY ASIEN) sub2 ON sub2.ASIEN = sub.Asiento + WHERE sub.amountTaxableBase<>sub2.amountTaxableBase + AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase + UNION ALL + SELECT CONCAT('- Factura Duplicada: ', mc.Asiento) + FROM accountingEntryError + )sub; + + IF vBookEntries IS NOT NULL THEN + START TRANSACTION; + + SELECT util.notification_send ("book-entries-imported-incorrectly", + CONCAT('{"bookEntries":"', vBookEntries,'"}'), + null); + + TRUNCATE accountingEntryError; + + COMMIT; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql b/db/routines/sage/triggers/movConta_beforeUpdate.sql similarity index 92% rename from db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql rename to db/routines/sage/triggers/movConta_beforeUpdate.sql index 0b7a30fe1..316b28b7f 100644 --- a/db/routines/sage/triggers/movConta_BEFORE_UPDATE.sql +++ b/db/routines/sage/triggers/movConta_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `sage`.`movConta_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `sage`.`movConta_beforeUpdate` BEFORE UPDATE ON `movConta` FOR EACH ROW BEGIN diff --git a/db/routines/srt/triggers/expedition_BU.sql b/db/routines/srt/triggers/expedition_beforeUpdate.sql similarity index 89% rename from db/routines/srt/triggers/expedition_BU.sql rename to db/routines/srt/triggers/expedition_beforeUpdate.sql index fb557d151..b8933aaf5 100644 --- a/db/routines/srt/triggers/expedition_BU.sql +++ b/db/routines/srt/triggers/expedition_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `srt`.`expedition_BU` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `srt`.`expedition_beforeUpdate` BEFORE UPDATE ON `expedition` FOR EACH ROW BEGIN diff --git a/db/routines/srt/triggers/moving_AI.sql b/db/routines/srt/triggers/moving_afterInsert.sql similarity index 97% rename from db/routines/srt/triggers/moving_AI.sql rename to db/routines/srt/triggers/moving_afterInsert.sql index 6c2dcf961..aaa09c99c 100644 --- a/db/routines/srt/triggers/moving_AI.sql +++ b/db/routines/srt/triggers/moving_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `srt`.`moving_AI` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `srt`.`moving_afterInsert` AFTER INSERT ON `moving` FOR EACH ROW BEGIN diff --git a/db/routines/vn/events/client_unassignSalesPerson.sql b/db/routines/vn/events/client_unassignSalesPerson.sql index 4ca8b7de9..46ad414b1 100644 --- a/db/routines/vn/events/client_unassignSalesPerson.sql +++ b/db/routines/vn/events/client_unassignSalesPerson.sql @@ -1,8 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`jgallego`@`%` EVENT `vn`.`client_unassignSalesPerson` +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`client_unassignSalesPerson` ON SCHEDULE EVERY 1 DAY STARTS '2023-06-01 03:30:00.000' ON COMPLETION PRESERVE - DISABLE + ENABLE DO CALL client_unassignSalesPerson$$ DELIMITER ; diff --git a/db/routines/vn/events/sale_checkWithoutComponents.sql b/db/routines/vn/events/sale_checkWithoutComponents.sql index b67a6f4fa..2a1ced6ca 100644 --- a/db/routines/vn/events/sale_checkWithoutComponents.sql +++ b/db/routines/vn/events/sale_checkWithoutComponents.sql @@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`sale_checkWithoutCompon ON SCHEDULE EVERY 10 MINUTE STARTS '2020-05-04 11:56:23.000' ON COMPLETION PRESERVE - DISABLE + ENABLE DO call sale_checkNoComponents(DATE_ADD(util.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(util.VN_NOW(), INTERVAL -1 MINUTE))$$ DELIMITER ; diff --git a/db/routines/vn/functions/workerTimeControl_add.sql b/db/routines/vn/functions/workerTimeControl_add.sql deleted file mode 100644 index 63c40d7f2..000000000 --- a/db/routines/vn/functions/workerTimeControl_add.sql +++ /dev/null @@ -1,57 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`workerTimeControl_add`(vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) - RETURNS int(11) - DETERMINISTIC -BEGIN - DECLARE vDirection VARCHAR(6); - DECLARE vLastIn DATETIME; - DECLARE vDayStayMax INT; - DECLARE vHasDirectionOut INT; - DECLARE vLastInsertedId INT; - - SELECT dayStayMax INTO vDayStayMax - FROM workerTimeControlParams; - - SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; - - IF vDirection = 'out' THEN - - SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk - AND direction = 'in' - AND timed < vTimed; - - UPDATE workerTimeControl wtc - SET wtc.direction = 'middle' - WHERE userFk = vUserFk - AND direction = 'out' - AND timed BETWEEN vLastIn AND vTimed; - - ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut - FROM workerTimeControl wtc - WHERE userFk = vUserFk - AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); - - UPDATE workerTimeControl wtc - SET wtc.direction = IF (vHasDirectionOut,'middle','out') - WHERE userFk = vUserFk - AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); - - END IF; - END IF; - - INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) - VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - - SET vLastInsertedId = LAST_INSERT_ID(); - - CALL workerTimeControlSOWP(vUserFk, vTimed); - - RETURN vLastInsertedId; -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/workerTimeControl_addDirection.sql b/db/routines/vn/functions/workerTimeControl_addDirection.sql deleted file mode 100644 index 4d935e895..000000000 --- a/db/routines/vn/functions/workerTimeControl_addDirection.sql +++ /dev/null @@ -1,57 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`workerTimeControl_addDirection`(vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) - RETURNS int(11) - DETERMINISTIC -BEGIN - DECLARE vDirection VARCHAR(6); - DECLARE vLastIn DATETIME; - DECLARE vDayStayMax INT; - DECLARE vHasDirectionOut INT; - DECLARE vLastInsertedId INT; - - SELECT dayStayMax INTO vDayStayMax - FROM workerTimeControlParams; - - SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; - - IF vDirection = 'out' THEN - - SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk - AND direction = 'in' - AND timed < vTimed; - - UPDATE workerTimeControl wtc - SET wtc.direction = 'middle' - WHERE userFk = vUserFk - AND direction = 'out' - AND timed BETWEEN vLastIn AND vTimed; - - ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut - FROM workerTimeControl wtc - WHERE userFk = vUserFk - AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); - - UPDATE workerTimeControl wtc - SET wtc.direction = IF (vHasDirectionOut,'middle','out') - WHERE userFk = vUserFk - AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); - - END IF; - END IF; - - INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) - VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - - SET vLastInsertedId = LAST_INSERT_ID(); - - CALL workerTimeControlSOWP(vUserFk, vTimed); - - RETURN vLastInsertedId; -END$$ -DELIMITER ; diff --git a/db/routines/vn/functions/worker_isInDepartment.sql b/db/routines/vn/functions/worker_isInDepartment.sql new file mode 100644 index 000000000..8eee3656e --- /dev/null +++ b/db/routines/vn/functions/worker_isInDepartment.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`worker_isInDepartment`(vDepartmentCode VARCHAR(255)) + RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Devuelve booleano si el trabajador conectado pertenece + * al departamento vDepartmentCode o a sus departamentos subordinados + * + * @param vDepartmentCode code del departamento que se desea comprobar. + * @return Devuelve verdadero si es jefe del empleado por escala jerárquica. + */ + DECLARE vIsInDepartment BOOLEAN; + WITH RECURSIVE department AS ( + SELECT d.id FROM vn.department d WHERE code = vDepartmentCode + UNION + SELECT d.id + FROM department ds + JOIN vn.department d ON ds.id = d.parentFk + ) + SELECT COUNT(*) INTO vIsInDepartment FROM department ds + JOIN vn.workerDepartment wd ON wd.departmentFk = ds.id + WHERE wd.workerFk = account.myUser_getId(); + + RETURN vIsInDepartment; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql index 404a8fdab..4346ef640 100644 --- a/db/routines/vn/procedures/buyUltimate.sql +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -25,12 +25,15 @@ BEGIN SELECT itemFk, buyFk, warehouseFk, landed landing FROM tmp.buyUltimateFromInterval WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed <= vDated; + AND landed <= vDated + AND NOT isIgnored; INSERT IGNORE INTO tmp.buyUltimate SELECT itemFk, buyFk, warehouseFk, landed landing FROM tmp.buyUltimateFromInterval WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed > vDated; + AND landed > vDated + ORDER BY isIgnored = FALSE DESC; + END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index e9d30f4c9..92434a47b 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -26,11 +26,13 @@ BEGIN SELECT itemFk, warehouseFk, buyFk, - MAX(landed) landed + MAX(landed) landed, + isIgnored FROM (SELECT b.itemFk, t.warehouseInFk warehouseFk, b.id buyFk, - t.landed + t.landed, + b.isIgnored FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk @@ -42,12 +44,13 @@ BEGIN LIMIT 10000000000000000000) sub GROUP BY itemFk, warehouseFk; - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT b.itemFk, t.warehouseInFk warehouseFk, b.id buyFk, - t.landed + t.landed, + b.isIgnored FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk @@ -57,12 +60,13 @@ BEGIN AND NOT b.isIgnored GROUP BY itemFk, warehouseInFk; - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT b.itemFk, t.warehouseInFk warehouseFk, b.id buyFk, - t.landed + t.landed, + b.isIgnored FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk @@ -71,17 +75,19 @@ BEGIN AND b.quantity = 0 GROUP BY itemFk, warehouseInFk; - -- ItemOriginal - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + -- ItemOriginal + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT itemFk, warehouseFk, buyFk, - MAX(landed) landed + MAX(landed) landed, + isIgnored FROM (SELECT b.itemFk, t.warehouseInFk warehouseFk, b.id buyFk, t.landed, - itemOriginalFk + itemOriginalFk, + b.isIgnored FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk @@ -95,12 +101,13 @@ BEGIN LIMIT 10000000000000000000) sub GROUP BY itemOriginalFk, warehouseFk; - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT b.itemFk, t.warehouseInFk warehouseFk, b.id buyFk, - t.landed + t.landed, + b.isIgnored FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk @@ -111,12 +118,13 @@ BEGIN AND itemOriginalFk GROUP BY itemOriginalFk, warehouseInFk; - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT b.itemFk, t.warehouseInFk warehouseFk, b.id buyFk, - t.landed + t.landed, + b.isIgnored FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel t ON t.id = e.travelFk diff --git a/db/routines/vn/procedures/buy_recalcPricesByAwb.sql b/db/routines/vn/procedures/buy_recalcPricesByAwb.sql index bc0c9bcb3..6f6baf305 100644 --- a/db/routines/vn/procedures/buy_recalcPricesByAwb.sql +++ b/db/routines/vn/procedures/buy_recalcPricesByAwb.sql @@ -12,9 +12,8 @@ BEGIN SELECT b.id FROM buy b JOIN entry e ON e.id = b.entryFk - JOIN duaEntry de ON de.entryFk = e.id - JOIN dua d ON d.id = de.duaFk - JOIN awb a ON a.id = d.awbFk + JOIN travel t ON t.id = e.travelFk + JOIN awb a ON a.id = t.awbFk WHERE a.code = awbFk; CALL buy_recalcPrices(); diff --git a/db/routines/vn/procedures/client_unassignSalesPerson.sql b/db/routines/vn/procedures/client_unassignSalesPerson.sql index 8c624204e..f939ae68b 100644 --- a/db/routines/vn/procedures/client_unassignSalesPerson.sql +++ b/db/routines/vn/procedures/client_unassignSalesPerson.sql @@ -18,9 +18,9 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; CREATE OR REPLACE TEMPORARY TABLE tClientList - SELECT c.clientFk + SELECT c.id clientFk FROM bs.clientDied cd - JOIN client c ON c.id = cd.id + JOIN client c ON c.id = cd.clientFk LEFT JOIN clientProtected cp ON cp.clientFk = c.id LEFT JOIN salesPersonProtected sp ON sp.salesPersonFk = c.salesPersonFk JOIN province p ON p.id = c.provinceFk diff --git a/db/routines/vn/procedures/collection_assign.sql b/db/routines/vn/procedures/collection_assign.sql index 038f8f9a3..0918bf1da 100644 --- a/db/routines/vn/procedures/collection_assign.sql +++ b/db/routines/vn/procedures/collection_assign.sql @@ -1,72 +1,88 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_assign`(vUserFk INT, OUT vCollectionFk INT) -proc:BEGIN -/* Comprueba si existen colecciones libres que se ajustan al perfil del usuario - * y le asigna la más antigua. - * Añade un registro al semillero de colecciones - */ - DECLARE vHasTooMuchCollections BOOL; - DECLARE vLockTime INT DEFAULT 15; - - -- Si hay colecciones sin terminar, sale del proceso - CALL vn.collection_get(vUserFk); - - SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 - INTO vHasTooMuchCollections - FROM tCollection - JOIN vn.productionConfig pc ; - - DROP TEMPORARY TABLE tCollection; - - IF vHasTooMuchCollections THEN - CALL util.throw('Hay colecciones pendientes'); - LEAVE proc; - END IF; - - IF NOT GET_LOCK('collection_assign',vLockTime) THEN - LEAVE proc; - END IF; - - -- Se eliminan las colecciones sin asignar que estan obsoletas - INSERT INTO ticketTracking(stateFk, ticketFk) - SELECT s.id, tc.ticketFk - FROM vn.collection c - JOIN vn.ticketCollection tc ON tc.collectionFk = c.id - JOIN vn.state s ON s.code = 'PRINTED_AUTO' - JOIN vn.productionConfig pc - WHERE c.workerFk IS NULL - AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; - - DELETE c.* - FROM vn.collection c - JOIN vn.productionConfig pc - WHERE c.workerFk IS NULL - AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; - - -- Se a�ade registro al semillero - INSERT INTO vn.collectionHotbed(userFk) - VALUES(vUserFk); - - -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion - SELECT MIN(c.id) - INTO vCollectionFk - FROM vn.collection c - JOIN vn.operator o - ON (o.itemPackingTypeFk = c.itemPackingTypeFk OR c.itemPackingTypeFk IS NULL) - AND o.numberOfWagons = c.wagons - AND o.trainFk = c.trainFk - AND o.warehouseFk = c.warehouseFk - AND c.workerFk IS NULL - WHERE o.workerFk = vUserFk; - - IF vCollectionFk IS NULL THEN - CALL vn.collection_new(vUserFk, vCollectionFk); - END IF; - - UPDATE vn.collection - SET workerFk = vUserFk - WHERE id = vCollectionFk; - - DO RELEASE_LOCK('collection_assign'); -END$$ -DELIMITER ; +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_assign`( + vUserFk INT, + OUT vCollectionFk INT +) +proc:BEGIN +/** + * Comprueba si existen colecciones libres que se ajustan + * al perfil del usuario y le asigna la más antigua. + * Añade un registro al semillero de colecciones. + * + * @param vUserFk Id de usuario + * @param vCollectionFk Id de colección + */ + DECLARE vHasTooMuchCollections BOOL; + DECLARE vLockTime INT DEFAULT 15; + + -- Si hay colecciones sin terminar, sale del proceso + CALL collection_get(vUserFk); + + SELECT (pc.maxNotReadyCollections - COUNT(*)) <= 0 + INTO vHasTooMuchCollections + FROM tCollection + JOIN productionConfig pc ; + + DROP TEMPORARY TABLE tCollection; + + IF vHasTooMuchCollections THEN + CALL util.throw('Hay colecciones pendientes'); + LEAVE proc; + END IF; + + IF NOT GET_LOCK('collection_assign',vLockTime) THEN + LEAVE proc; + END IF; + + -- Se eliminan las colecciones sin asignar que estan obsoletas + INSERT INTO ticketTracking(stateFk, ticketFk) + SELECT s.id, tc.ticketFk + FROM `collection` c + JOIN ticketCollection tc ON tc.collectionFk = c.id + JOIN `state` s ON s.code = 'PRINTED_AUTO' + JOIN productionConfig pc + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + + DELETE c.* + FROM `collection` c + JOIN productionConfig pc + WHERE c.workerFk IS NULL + AND TIMEDIFF(util.VN_NOW(), c.created) > pc.maxNotAssignedCollectionLifeTime; + + -- Se añade registro al semillero + INSERT INTO collectionHotbed(userFk) + VALUES(vUserFk); + + -- Comprueba si hay colecciones disponibles que se ajustan a su configuracion + SELECT MIN(c.id) + INTO vCollectionFk + FROM `collection` c + JOIN operator o + ON (o.itemPackingTypeFk = c.itemPackingTypeFk OR c.itemPackingTypeFk IS NULL) + AND o.numberOfWagons = c.wagons + AND o.trainFk = c.trainFk + AND o.warehouseFk = c.warehouseFk + AND c.workerFk IS NULL + AND (c.saleTotalCount <= o.linesLimit OR o.linesLimit IS NULL) + JOIN ( + SELECT tc.collectionFk, SUM(sv.volume) volume + FROM ticketCollection tc + JOIN saleVolume sv ON sv.ticketFk = tc.ticketFk + WHERE sv.shipped >= util.VN_CURDATE() + GROUP BY tc.collectionFk + ) sub ON sub.collectionFk = c.id + AND (volume <= o.volumeLimit OR o.volumeLimit IS NULL) + WHERE o.workerFk = vUserFk; + + IF vCollectionFk IS NULL THEN + CALL collection_new(vUserFk, vCollectionFk); + END IF; + + UPDATE `collection` + SET workerFk = vUserFk + WHERE id = vCollectionFk; + + DO RELEASE_LOCK('collection_assign'); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index 8bb382db1..d91c63c24 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -9,6 +9,10 @@ proc:BEGIN DECLARE vWarehouseFk INT; DECLARE vWagons INT; DECLARE vTrainFk INT; + DECLARE vLinesLimit INT DEFAULT NULL; + DECLARE vTicketLines INT; + DECLARE vVolumeLimit DECIMAL DEFAULT NULL; + DECLARE vTicketVolume DECIMAL; DECLARE vMaxTickets INT; DECLARE vStateFk VARCHAR(45); DECLARE vFirstTicketFk INT; @@ -24,12 +28,11 @@ proc:BEGIN DECLARE vLockName VARCHAR(215); DECLARE vLockTime INT DEFAULT 15; DECLARE vFreeWagonFk INT; - DECLARE cur1 CURSOR FOR - SELECT ticketFk + DECLARE c1 CURSOR FOR + SELECT ticketFk, `lines`, m3 FROM tmp.productionBuffer WHERE ticketFk <> vFirstTicketFk - ORDER BY - HH, + ORDER BY HH, mm, productionOrder DESC, m3 DESC, @@ -41,32 +44,34 @@ proc:BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - SELECT - pc.ticketTrolleyMax * o.numberOfWagons, - pc.hasUniqueCollectionTime, - w.code, - o.warehouseFk, - o.itemPackingTypeFk, - st.code, - CONCAT('collection_new', o.warehouseFk, ':',o.itemPackingTypeFk), - o.numberOfWagons, - o.trainFk - INTO - vMaxTickets, - vHasUniqueCollectionTime, - vWorkerCode, - vWarehouseFk, - vItemPackingTypeFk, - vStateFk, - vLockName, - vWagons, - vTrainFk + SELECT pc.ticketTrolleyMax * o.numberOfWagons, + pc.hasUniqueCollectionTime, + w.code, + o.warehouseFk, + o.itemPackingTypeFk, + st.code, + CONCAT('collection_new', o.warehouseFk, ':',o.itemPackingTypeFk), + o.numberOfWagons, + o.trainFk, + o.linesLimit, + o.volumeLimit + INTO vMaxTickets, + vHasUniqueCollectionTime, + vWorkerCode, + vWarehouseFk, + vItemPackingTypeFk, + vStateFk, + vLockName, + vWagons, + vTrainFk, + vLinesLimit, + vVolumeLimit FROM productionConfig pc JOIN worker w ON w.id = vUserFk JOIN state st ON st.`code` = 'ON_PREPARATION' JOIN operator o ON o.workerFk = vUserFk; - IF NOT GET_LOCK(vLockName,vLockTime) THEN + IF NOT GET_LOCK(vLockName, vLockTime) THEN LEAVE proc; END IF; @@ -122,16 +127,16 @@ proc:BEGIN SELECT COUNT(*) INTO vHasAssignedTickets FROM tmp.productionBuffer pb JOIN state s ON s.id = pb.state - WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode; + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode; -- Se dejan en la tabla tmp.productionBuffer sólo aquellos tickets adecuados IF vHasAssignedTickets THEN DELETE pb.* FROM tmp.productionBuffer pb JOIN state s ON s.id = pb.state - WHERE s.code <> 'PICKER_DESIGNED' - OR pb.workerCode <> vWorkerCode; + WHERE s.code <> 'PICKER_DESIGNED' + OR pb.workerCode <> vWorkerCode; ELSE DELETE pb.* FROM tmp.productionBuffer pb @@ -140,23 +145,32 @@ proc:BEGIN JOIN agency a ON a.id = am.agencyFk JOIN productionConfig pc WHERE pb.shipped <> util.VN_CURDATE() - OR (pb.ubicacion IS NULL AND a.isOwn = TRUE) - OR (s.isPreparable = FALSE AND s.isPrintable = FALSE) + OR (pb.ubicacion IS NULL AND a.isOwn) + OR (NOT s.isPreparable AND NOT s.isPrintable) OR pb.collectionH IS NOT NULL OR pb.collectionV IS NOT NULL OR pb.collectionN IS NOT NULL - OR (pb.H = 0 AND pb.V > 0 AND vItemPackingTypeFk = 'H') - OR (pb.V = 0 AND vItemPackingTypeFk = 'V') + OR (NOT pb.H AND pb.V > 0 AND vItemPackingTypeFk = 'H') + OR (NOT pb.V AND vItemPackingTypeFk = 'V') OR (pc.isPreviousPreparationRequired AND pb.previousWithoutParking) - OR LENGTH(pb.problem) > 0; + OR LENGTH(pb.problem) > 0 + OR (pb.lines >= vLinesLimit AND vLinesLimit IS NOT NULL) + OR (pb.m3 >= vVolumeLimit AND vVolumeLimit IS NOT NULL); END IF; -- Es importante que el primer ticket se coja en todos los casos - SELECT ticketFk, HH, mm - INTO vFirstTicketFk, vHour, vMinute - FROM tmp.productionBuffer - ORDER BY + SELECT ticketFk, HH, + mm, + `lines`, + m3 + INTO vFirstTicketFk, + vHour, + vMinute, + vTicketLines, + vTicketVolume + FROM tmp.productionBuffer + ORDER BY HH, mm, productionOrder DESC, m3 DESC, @@ -168,90 +182,103 @@ proc:BEGIN -- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede IF vHasUniqueCollectionTime THEN - DELETE - FROM tmp.productionBuffer + DELETE FROM tmp.productionBuffer WHERE HH <> vHour OR mm <> vMinute; END IF; SET vTicketFk = vFirstTicketFk; + SET @lines = 0; + SET @volume = 0; - OPEN cur1; - + OPEN c1; read_loop: LOOP SET vDone = FALSE; - CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk); + -- Buscamos un ticket que cumpla con los requisitos en el listado + IF ((vTicketLines + @lines) <= vLinesLimit OR vLinesLimit IS NULL) + AND ((vTicketVolume + @volume) <= vVolumeLimit OR vVolumeLimit IS NULL) THEN - DROP TEMPORARY TABLE tmp.ticketIPT; + CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk); + DROP TEMPORARY TABLE tmp.ticketIPT; - UPDATE tmp.productionBuffer pb - JOIN (SELECT @litros:= SUM(litros) liters, COUNT(*) `lines`, MAX(i.`size`) height - FROM saleVolume sv - JOIN sale s ON s.id = sv.saleFk - JOIN item i ON i.id = s.itemFk - WHERE sv.ticketFk = vTicketFk ) sub - SET pb.liters = sub.liters, pb.`lines` = sub.`lines`, pb.height = sub.height - WHERE pb.ticketFk = vTicketFk; + UPDATE tmp.productionBuffer pb + JOIN ( + SELECT SUM(litros) liters, + @lines:= COUNT(*) + @lines `lines`, + MAX(i.`size`) height, + @volume := SUM(sv.volume) + @volume volume + FROM saleVolume sv + JOIN sale s ON s.id = sv.saleFk + JOIN item i ON i.id = s.itemFk + WHERE sv.ticketFk = vTicketFk + ) sub + SET pb.liters = sub.liters, + pb.`lines` = sub.`lines`, + pb.height = sub.height + WHERE pb.ticketFk = vTicketFk; - UPDATE tTrain tt - JOIN tmp.productionBuffer pb ON pb.ticketFk = vTicketFk - SET tt.ticketFk = pb.ticketFk - WHERE tt.liters >= pb.liters - AND tt.`lines` >= pb.`lines` - AND (tt.height >= pb.height OR vItemPackingTypeFk <> 'V') - AND tt.ticketFk IS NULL - ORDER BY - wagon, - shelve, - tt.liters, - tt.`lines`, - tt.height - LIMIT 1; - - -- Si no le encuentra una balda adecuada, intentamos darle un carro entero - -- si queda alguno libre - - IF NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN - SELECT tt.wagon - INTO vFreeWagonFk - FROM tTrain tt - LEFT JOIN (SELECT DISTINCT wagon - FROM tTrain - WHERE ticketFk IS NOT NULL - ) nn ON nn.wagon = tt.wagon - WHERE nn.wagon IS NULL - ORDER BY wagon + UPDATE tTrain tt + JOIN tmp.productionBuffer pb ON pb.ticketFk = vTicketFk + SET tt.ticketFk = pb.ticketFk + WHERE tt.liters >= pb.liters + AND tt.`lines` >= pb.`lines` + AND (tt.height >= pb.height OR vItemPackingTypeFk <> 'V') + AND tt.ticketFk IS NULL + ORDER BY wagon, + shelve, + tt.liters, + tt.`lines`, + tt.height LIMIT 1; - IF vFreeWagonFk THEN - UPDATE tTrain - SET ticketFk = vFirstTicketFk - WHERE wagon = vFreeWagonFk; - - -- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo - DELETE tt.* + -- Si no le encuentra una balda adecuada, intentamos darle un carro entero si queda alguno libre + IF NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN + SELECT tt.wagon + INTO vFreeWagonFk FROM tTrain tt - LEFT JOIN (SELECT DISTINCT wagon + LEFT JOIN ( + SELECT DISTINCT wagon + FROM tTrain + WHERE ticketFk IS NOT NULL + ) nn ON nn.wagon = tt.wagon + WHERE nn.wagon IS NULL + ORDER BY wagon + LIMIT 1; + + IF vFreeWagonFk THEN + UPDATE tTrain + SET ticketFk = vFirstTicketFk + WHERE wagon = vFreeWagonFk; + + -- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo + DELETE tt.* + FROM tTrain tt + LEFT JOIN ( + SELECT DISTINCT wagon FROM tTrain WHERE ticketFk IS NOT NULL - ) nn ON nn.wagon = tt.wagon - WHERE nn.wagon IS NULL; + ) nn ON nn.wagon = tt.wagon + WHERE nn.wagon IS NULL; + END IF; END IF; - END IF; - FETCH cur1 INTO vTicketFk; - - IF vDone OR NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk IS NULL) THEN - LEAVE read_loop; + FETCH c1 INTO vTicketFk, vTicketLines, vTicketVolume; + IF vDone OR NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk IS NULL) THEN + LEAVE read_loop; + END IF; + ELSE + FETCH c1 INTO vTicketFk, vTicketLines, vTicketVolume; + IF vDone THEN + LEAVE read_loop; + END IF; END IF; END LOOP; - - CLOSE cur1; + CLOSE c1; IF (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN UPDATE collection c - JOIN state st ON st.code = 'ON_PREPARATION' + JOIN state st ON st.code = 'ON_PREPARATION' SET c.stateFk = st.id WHERE c.id = vCollectionFk; @@ -263,7 +290,6 @@ proc:BEGIN ORDER BY tt.wagon, tt.shelve; -- Actualiza el estado de los tickets - CALL collection_setState(vCollectionFk, vStateFk); -- Aviso para la preparacion previa @@ -274,24 +300,23 @@ proc:BEGIN CALL sales_mergeByCollection(vCollectionFk); - UPDATE collection c - JOIN (SELECT count(*) saleTotalCount , - sum(s.isPicked != 0) salePickedCount - FROM ticketCollection tc - JOIN sale s ON s.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND s.quantity > 0 + UPDATE `collection` c + JOIN ( + SELECT COUNT(*) saleTotalCount, + SUM(s.isPicked <> 0) salePickedCount + FROM ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND s.quantity > 0 ) sub SET c.saleTotalCount = sub.saleTotalCount, c.salePickedCount = sub.salePickedCount WHERE c.id = vCollectionFk; ELSE - - -- CALL util.throw('No ha sido posible obtener colección'); - DELETE FROM collection WHERE id = vCollectionFk; - SET vCollectionFk = NULL; - + DELETE FROM `collection` + WHERE id = vCollectionFk; + SET vCollectionFk = NULL; END IF; DO RELEASE_LOCK(vLockName); diff --git a/db/routines/vn/procedures/comparative_add.sql b/db/routines/vn/procedures/comparative_add.sql index 349d26db5..756096e54 100644 --- a/db/routines/vn/procedures/comparative_add.sql +++ b/db/routines/vn/procedures/comparative_add.sql @@ -23,9 +23,10 @@ BEGIN FROM `time` WHERE dated = util.VN_CURDATE(); - IF vMaxPeriod < vPeriod - AND vWeek > vConfigWeek THEN - REPLACE comparative( + IF vMaxPeriod < vPeriod AND vWeek > vConfigWeek THEN + DELETE FROM comparative WHERE timePeriod BETWEEN vMaxPeriod AND vPeriod; + + INSERT INTO comparative( timePeriod, itemFk, warehouseFk, diff --git a/db/routines/vn/procedures/duaParcialMake.sql b/db/routines/vn/procedures/duaParcialMake.sql index 9504cd38a..cbb56e16d 100644 --- a/db/routines/vn/procedures/duaParcialMake.sql +++ b/db/routines/vn/procedures/duaParcialMake.sql @@ -4,8 +4,8 @@ BEGIN DECLARE vNewDuaFk INT; - INSERT INTO dua(awbFk,companyFk) - SELECT awbFk,companyFk + INSERT INTO dua(companyFk) + SELECT companyFk FROM dua WHERE id = vDuaFk; @@ -15,7 +15,7 @@ BEGIN SELECT vNewDuaFk, entryFk, value, value - customsValue FROM duaEntry WHERE duaFk = vDuaFk - AND value != customsValue; + AND value != customsValue; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ektEntryAssign_setEntry.sql b/db/routines/vn/procedures/ektEntryAssign_setEntry.sql index 441555ad5..d80215e37 100644 --- a/db/routines/vn/procedures/ektEntryAssign_setEntry.sql +++ b/db/routines/vn/procedures/ektEntryAssign_setEntry.sql @@ -80,7 +80,7 @@ OPEN cur1; FROM vn.travel tr JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk AND ea.warehouseInFk = tr.warehouseInFk - AND ea.agencyModeFk = tr.agencyFk + AND ea.agencyModeFk = tr.agencyModeFk WHERE ea.id = vId AND tr.landed = vLanded; diff --git a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql index e9461369a..77e989630 100644 --- a/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql +++ b/db/routines/vn/procedures/invoiceInTax_afterUpsert.sql @@ -13,7 +13,8 @@ BEGIN SELECT COUNT(*) INTO vLines FROM invoiceInTax - WHERE invoiceInFk = vInvoiceInFk; + WHERE invoiceInFk = vInvoiceInFk + AND (taxTypeSageFk OR transactionTypeSageFk); IF vLines >= vTaxRowLimit THEN CALL util.throw (CONCAT('The maximum number of lines is ', vTaxRowLimit)); diff --git a/db/routines/vn/procedures/itemProposal_Add.sql b/db/routines/vn/procedures/itemProposal_Add.sql index 537cecb1c..5a01cb67a 100644 --- a/db/routines/vn/procedures/itemProposal_Add.sql +++ b/db/routines/vn/procedures/itemProposal_Add.sql @@ -8,52 +8,63 @@ BEGIN * @param vMateFk articulo sustituto * @ param vQuantity cantidad que se va a sustituir */ - DECLARE vTicketFk INT; - DECLARE vItemFk INT; - DECLARE vWarehouseFk SMALLINT; - DECLARE vDate DATE; - DECLARE vGrouping INT; + DECLARE vTicketFk INT; + DECLARE vItemFk INT; + DECLARE vWarehouseFk SMALLINT; + DECLARE vDate DATE; + DECLARE vGrouping INT; DECLARE vBox INT; DECLARE vPacking INT; - DECLARE vRoundQuantity INT DEFAULT 1; - - SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk - INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE s.id = vSaleFk; - - UPDATE vn.sale - SET quantity = quantity - vQuantity - WHERE id = vSaleFk; - - CALL vn.buyUltimate(vWarehouseFk, vDate); - - SELECT `grouping`, groupingMode, packing - INTO vGrouping,vBox,vPacking - FROM buy b - JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk - WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; - - IF vBox = 2 AND vPacking > 0 THEN - SET vRoundQuantity = vPacking; - END IF; - IF vBox = 1 AND vGrouping > 0 THEN - SET vRoundQuantity = vGrouping; - END IF; - - INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept) - SELECT vTicketFk, vMateFk, CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ',i.longName) - FROM vn.item i - WHERE id = vMateFk; - - SELECT LAST_INSERT_ID() INTO vSaleFk; - - CALL vn.sale_calculateComponent(vSaleFk, NULL); - - INSERT INTO vn.itemProposal(itemFk, mateFk, counter) - VALUES(vItemFk, vMateFk, 1) - ON DUPLICATE KEY UPDATE counter = counter + 1; + DECLARE vRoundQuantity INT DEFAULT 1; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT s.ticketFk, LEAST(s.quantity, vQuantity), s.itemFk,t.shipped,t.warehouseFk + INTO vTicketFk, vQuantity, vItemFk,vDate,vWarehouseFk + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE s.id = vSaleFk; + + CALL buyUltimate(vWarehouseFk, vDate); + + SELECT `grouping`, groupingMode, packing INTO vGrouping, vBox, vPacking + FROM buy b + JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk + WHERE tmp.itemFk = vMateFk AND tmp.WarehouseFk = vWarehouseFk; + + IF vBox = 2 AND vPacking > 0 THEN + SET vRoundQuantity = vPacking; + END IF; + IF vBox = 1 AND vGrouping > 0 THEN + SET vRoundQuantity = vGrouping; + END IF; + + START TRANSACTION; + + UPDATE sale + SET quantity = quantity - vQuantity + WHERE id = vSaleFk; + + INSERT INTO sale(ticketFk, itemFk, quantity, concept) + SELECT vTicketFk, + vMateFk, + CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, + CONCAT('+ ',i.longName) + FROM item i + WHERE id = vMateFk; + + SELECT LAST_INSERT_ID() INTO vSaleFk; + + CALL sale_calculateComponent(vSaleFk, NULL); + + INSERT INTO itemProposal(itemFk, mateFk, counter) + VALUES(vItemFk, vMateFk, 1) + ON DUPLICATE KEY UPDATE counter = counter + 1; + + COMMIT; END$$ -DELIMITER ; +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/itemShelving_filterBuyer.sql b/db/routines/vn/procedures/itemShelving_filterBuyer.sql index 4ddaf3d12..a232139d3 100644 --- a/db/routines/vn/procedures/itemShelving_filterBuyer.sql +++ b/db/routines/vn/procedures/itemShelving_filterBuyer.sql @@ -9,7 +9,7 @@ proc:BEGIN * @return Lista de articulos */ DECLARE vCalcVisibleFk INT; - + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); SELECT * FROM @@ -23,7 +23,7 @@ proc:BEGIN CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho, sub.name itemColour FROM (SELECT iss.itemFk, - CONCAT(i.longName, ' ', i.size,' ', IFNULL(i.subName,'') ) longName, + CONCAT(i.longName, ' ', IFNULL(i.size, ''),' ', IFNULL(i.subName, '') ) longName, '' size, CONCAT(iss.parkingCode, ' ', iss.shelvingFk) producer, 0 upstairs, @@ -38,7 +38,7 @@ proc:BEGIN LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk WHERE s.warehouseFk = vWarehouseFk AND it.workerFk = vBuyerFk - GROUP BY itemFk + GROUP BY itemFk ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente FROM sale s LEFT JOIN saleTracking st ON st.saleFk = s.id @@ -49,9 +49,9 @@ proc:BEGIN AND st.saleFk IS NULL AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk - ) sub2 ON sub2.itemFk = sub.itemFk - UNION ALL - SELECT v.item_id , + ) sub2 ON sub2.itemFk = sub.itemFk + UNION ALL + SELECT v.item_id, i.longName, CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, diff --git a/db/routines/vn/procedures/productionControl.sql b/db/routines/vn/procedures/productionControl.sql index 51af98e0b..3f3663865 100644 --- a/db/routines/vn/procedures/productionControl.sql +++ b/db/routines/vn/procedures/productionControl.sql @@ -81,8 +81,8 @@ proc: BEGIN rm.bufferFk FROM tmp.productionTicket tt JOIN ticket t ON tt.ticketFk = t.id - LEFT JOIN ticketStateToday tst ON tst.ticket = t.id - LEFT JOIN state st ON st.id = tst.state + LEFT JOIN ticketStateToday tst ON tst.ticketFk = t.id + LEFT JOIN `state` st ON st.id = tst.state LEFT JOIN client c ON c.id = t.clientFk LEFT JOIN worker wk ON wk.id = c.salesPersonFk JOIN address a ON a.id = t.addressFk diff --git a/db/routines/vn/procedures/recipe_Plaster.sql b/db/routines/vn/procedures/recipe_Plaster.sql index 65e2ab473..18fdf55c8 100644 --- a/db/routines/vn/procedures/recipe_Plaster.sql +++ b/db/routines/vn/procedures/recipe_Plaster.sql @@ -3,33 +3,33 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`recipe_Plaster`(vIt BEGIN DECLARE vLastCost DECIMAL(10,2); - DECLARE vWarehouseFk INT; - DECLARE vShipped DATE; - DECLARE vEntryFk INT; - DECLARE vTravelFk INT; - - CALL cache.last_buy_refresh(FALSE); - - SELECT warehouseFk, shipped + DECLARE vWarehouseFk INT; + DECLARE vShipped DATE; + DECLARE vEntryFk INT; + DECLARE vTravelFk INT; + + CALL cache.last_buy_refresh(FALSE); + + SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped FROM vn.ticket - WHERE id = vTicketFk; + WHERE id = vTicketFk; UPDATE vn.ticket t JOIN vn.item i ON i.id = vItemFk - SET t.nickname = CONCAT(vQuantity,' ',i.longName) + SET t.nickname = CONCAT(vQuantity,' ',i.longName) WHERE t.id = vTicketFk; - + SELECT b.buyingValue INTO vLastCost FROM vn.buy b JOIN cache.last_buy lb ON lb.buy_id = b.id WHERE lb.item_id = vItemFk - ORDER BY (lb.warehouse_id = vWarehouseFk) DESC - LIMIT 1; - + ORDER BY (lb.warehouse_id = vWarehouseFk) DESC + LIMIT 1; + INSERT INTO vn.sale(ticketFk, itemFk, quantity, concept, price) SELECT vTicketFk, 98, - vQuantity, i.longName, vLastCost FROM vn.item i - WHERE i.id = vItemFk; + WHERE i.id = vItemFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/saleGroup_add.sql b/db/routines/vn/procedures/saleGroup_add.sql index 679b84025..63e3bdedd 100644 --- a/db/routines/vn/procedures/saleGroup_add.sql +++ b/db/routines/vn/procedures/saleGroup_add.sql @@ -1,13 +1,15 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_add`(vSectorFk INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_add`(vSectorFk INT,vTicketFk INT) BEGIN /** * Añade un nuevo registro a la tabla y devuelve su id. * * @param vSectorFk Identificador de vn.sector */ - INSERT INTO vn.saleGroup(userFk, sectorFk) - VALUES (account.myUser_getId(), vSectorFk); + INSERT INTO vn.saleGroup + SET `userFk` = account.myUser_getId(), + `sectorFk` = vSectorFk, + `ticketFk` = vTicketFk; SELECT LAST_INSERT_ID(); END$$ diff --git a/db/routines/vn/procedures/sale_calculateComponent.sql b/db/routines/vn/procedures/sale_calculateComponent.sql index d720c5b06..63786c75c 100644 --- a/db/routines/vn/procedures/sale_calculateComponent.sql +++ b/db/routines/vn/procedures/sale_calculateComponent.sql @@ -1,19 +1,19 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_calculateComponent`(vSelf INT, vOption VARCHAR(25)) proc: BEGIN /** * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes * * @param vSelf Id de la venta * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - */ - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales - SELECT s.id - FROM sale s - WHERE s.id = vSelf; - - CALL sale_recalcComponent(vOption); - - DROP TEMPORARY TABLE tmp.recalculateSales; + */ + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.id = vSelf; + + CALL sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/sale_checkNoComponents.sql b/db/routines/vn/procedures/sale_checkNoComponents.sql index 136c13409..79abbbf92 100644 --- a/db/routines/vn/procedures/sale_checkNoComponents.sql +++ b/db/routines/vn/procedures/sale_checkNoComponents.sql @@ -61,7 +61,7 @@ BEGIN FROM sale WHERE id = vSaleFk; - CALL sale_calculateComponent(vSaleFk, 1); + CALL sale_calculateComponent(vSaleFk, 'renewPrices'); END LOOP; CLOSE vCur; diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 407c15854..0f2b2bc71 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -1,13 +1,13 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getBoxPickingList`(vSectorFk INT, vDated DATE) BEGIN -/** +/** * Returns a suitable boxPicking sales list * * @param vSectorFk Identifier for vn.sector table * @param vDated Date for vn.tickets.shipping * -* @return tmp.sale +* @return tmp.sale */ DECLARE vWarehouseFk INT; @@ -17,6 +17,55 @@ BEGIN CALL productionControl(vWarehouseFk, 0); + -- Products with vn.item.isBoxPickingMode = TRUE, pay atention to vn.itemShelving.packing + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (saleFk INT PRIMARY KEY) + SELECT + s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + FLOOR(s.quantity / ish.packing) stickers, + ish.packing, + b.packagingFk + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN itemShelving ish ON ish.itemFk = s.itemFk + LEFT JOIN ( SELECT iss.itemShelvingFk, + s.itemFk, + SUM(iss.quantity) reserve + FROM itemShelvingSale iss + JOIN sale s ON s.id = iss.saleFk + WHERE iss.isPicked = FALSE + AND iss.created >= vDated + GROUP BY iss.itemShelvingFk, s.itemFk) tISS + ON tISS.itemFk = ish.itemFk AND tISS.itemShelvingFk = ish.id + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk + JOIN agencyMode am ON am.id = pb.agencyModeFk + LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk + LEFT JOIN buy b ON b.id = lb.buy_id + WHERE s.quantity BETWEEN ish.packing AND (ish.visible - IFNULL(tISS.reserve,0)) + AND i.isBoxPickingMode + AND NOT pb.problem + AND sgd.saleFk IS NULL + AND p.sectorFk = vSectorFk + AND ts.isPreviousPreparable + AND ((rm.bufferFk AND rm.isPickingAllowed) + OR am.code = 'REC_ALG') + AND pb.shipped = vDated + GROUP BY s.id + ORDER BY etd; + + -- Remaining products, vn.item.packingOut + INSERT IGNORE INTO tmp.sale SELECT s.ticketFk, s.id saleFk, @@ -26,7 +75,8 @@ BEGIN MAKETIME(pb.HH,pb.mm,0) etd, pb.routeFk, s.quantity / i.packingOut stickers, - i.packingOut + i.packingOut, + pc.defaultBigPackageFk FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk @@ -34,25 +84,27 @@ BEGIN JOIN parking p ON p.id = sh.parkingFk JOIN tmp.productionBuffer pb ON pb.ticketFk = s.ticketFk JOIN agencyMode am ON am.id = pb.agencyModeFk + JOIN packagingConfig pc LEFT JOIN routesMonitor rm ON rm.routeFk = pb.routeFk LEFT JOIN itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = p.sectorFk LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk - WHERE s.quantity MOD i.packingOut = 0 - AND pb.problem = "" + WHERE s.quantity >= i.packingOut + AND NOT pb.problem AND s.quantity > 0 AND sgd.saleFk IS NULL AND p.sectorFk = vSectorFk AND ts.isPreviousPreparable AND iss.visible >= s.quantity AND ((rm.bufferFk AND rm.isPickingAllowed) - OR am.name = 'REC_ALGEMESI') + OR am.code = 'REC_ALG') AND pb.shipped = vDated GROUP BY s.id ORDER BY etd; + SELECT * FROM tmp.sale; + DROP TEMPORARY TABLE tmp.productionBuffer; + DROP TEMPORARY TABLE tmp.sale; END$$ DELIMITER ; - - diff --git a/db/routines/vn/procedures/sale_recalcComponent.sql b/db/routines/vn/procedures/sale_recalcComponent.sql index 4e407ca6b..54297571a 100644 --- a/db/routines/vn/procedures/sale_recalcComponent.sql +++ b/db/routines/vn/procedures/sale_recalcComponent.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_recalcComponent`(vOption VARCHAR(25)) proc: BEGIN /** * Este procedimiento recalcula los componentes de un conjunto de sales, @@ -10,21 +10,21 @@ proc: BEGIN */ DECLARE vShipped DATE; DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicketFk INT; - DECLARE vLanded DATE; - DECLARE vIsEditable BOOLEAN; - DECLARE vZoneFk INTEGER; - DECLARE vDone BOOL DEFAULT FALSE; - + DECLARE vAgencyModeFk INT; + DECLARE vAddressFk INT; + DECLARE vTicketFk INT; + DECLARE vLanded DATE; + DECLARE vIsEditable BOOLEAN; + DECLARE vZoneFk INTEGER; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vCur CURSOR FOR SELECT DISTINCT s.ticketFk FROM tmp.recalculateSales rs JOIN vn.sale s ON s.id = rs.id; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - + OPEN vCur; l: LOOP @@ -59,13 +59,13 @@ proc: BEGIN IF NOT EXISTS (SELECT TRUE FROM tmp.zoneGetLanded LIMIT 1) THEN CALL util.throw(CONCAT('There is no zone for these parameters ', vTicketFk)); END IF; - + IF vLanded IS NULL OR vZoneFk IS NULL THEN UPDATE ticket t SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) WHERE t.id = vTicketFk AND t.landed IS NULL; - + IF vZoneFk IS NULL THEN SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; UPDATE ticket t @@ -76,10 +76,10 @@ proc: BEGIN END IF; DROP TEMPORARY TABLE tmp.zoneGetLanded; - + -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - + CALL buyUltimate (vWarehouseFk, vShipped); + CREATE OR REPLACE TEMPORARY TABLE tmp.sale (PRIMARY KEY (saleFk)) ENGINE = MEMORY SELECT s.id saleFk, vWarehouseFk warehouseFk @@ -87,7 +87,7 @@ proc: BEGIN JOIN tmp.recalculateSales rs ON s.id = rs.id WHERE s.ticketFk = vTicketFk; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketLot SELECT vWarehouseFk warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk FROM sale s JOIN tmp.recalculateSales rs ON s.id = rs.id @@ -99,15 +99,15 @@ proc: BEGIN CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); IF vOption IS NULL THEN - SET vOption = IF(vIsEditable, 1, 6); - END IF; - - CALL ticketComponentUpdateSale(vOption); - CALL catalog_componentPurge(); - + SET vOption = IF(vIsEditable, 'renewPrices', 'imbalance'); + END IF; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.sale; - + DROP TEMPORARY TABLE tmp.sale; + END LOOP; CLOSE vCur; diff --git a/db/routines/vn/procedures/sale_replaceItem.sql b/db/routines/vn/procedures/sale_replaceItem.sql new file mode 100644 index 000000000..1edad1983 --- /dev/null +++ b/db/routines/vn/procedures/sale_replaceItem.sql @@ -0,0 +1,136 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_replaceItem`(vSaleFk INT, vNewItemFk INT, vQuantity INT) +BEGIN +/** + * Añade un nuevo articulo para sustituir a otro, y actualiza la memoria de sustituciones. + * + * @param vSaleFk id de la tabla sale + * @param vNewItemFk articulo sustituto + * @param vQuantity cantidad que se va a sustituir + */ + DECLARE vTicketFk INT; + DECLARE vItemFk INT; + DECLARE vWarehouseFk SMALLINT; + DECLARE vDate DATE; + DECLARE vGrouping INT; + DECLARE vGroupingModeFk INT; + DECLARE vPacking INT; + DECLARE vRoundQuantity INT DEFAULT 1; + DECLARE vLanded DATE; + DECLARE vAddressFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vNewPrice DECIMAL(10,2); + DECLARE vOldPrice DECIMAL(10,2); + DECLARE vOption INT DEFAULT NULL; + DECLARE vNewSaleFk INT; + DECLARE vChangePrice INT DEFAULT 1; + DECLARE vBuyerDiscount INT DEFAULT 4; + DECLARE vManaDiscount INT DEFAULT 3; + DECLARE vForceToGrouping INT DEFAULT 1; + DECLARE vForceToPacking INT DEFAULT 2; + DECLARE vFinalPrice DECIMAL(10,2); + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT s.ticketFk, + LEAST(s.quantity, vQuantity), + s.itemFk, + t.shipped, + t.warehouseFk, + t.landed, + t.addressFk, + t.agencyModeFk, + s.price + INTO vTicketFk, + vQuantity, + vItemFk, + vDate, + vWarehouseFk, + vLanded, + vAddressFk, + vAgencyModeFk, + vOldPrice + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + WHERE s.id = vSaleFk; + + CALL buyUltimate(vWarehouseFk, vDate); + + SELECT `grouping`, groupingMode, packing + INTO vGrouping,vGroupingModeFk,vPacking + FROM buy b + JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk + WHERE tmp.itemFk = vNewItemFk AND tmp.WarehouseFk = vWarehouseFk; + + IF vGroupingModeFk = vForceToPacking AND vPacking > 0 THEN + SET vRoundQuantity = vPacking; + END IF; + IF vGroupingModeFk = vForceToGrouping AND vGrouping > 0 THEN + SET vRoundQuantity = vGrouping; + END IF; + + CALL catalog_calcFromItem( + vLanded, + vAddressFk, + vAgencyModeFk, + vNewItemFk); + + SELECT price INTO vNewPrice + FROM tmp.ticketCalculateItem; + + IF vNewPrice IS NULL THEN + CALL util.throw('price retrieval failed'); + END IF; + IF vNewPrice > vOldPrice THEN + SET vFinalPrice = vOldPrice; + IF worker_isInDepartment('vt') THEN + SET vOption = vManaDiscount; + ELSE + SET vOption = vBuyerDiscount; + END IF; + ELSE + SET vFinalPrice = vNewPrice; + SET vOption = vChangePrice; + END IF; + + START TRANSACTION; + + UPDATE sale + SET quantity = quantity - vQuantity + WHERE id = vSaleFk; + + INSERT INTO vn.sale(ticketFk, + itemFk, + quantity, + concept, + price) + SELECT vTicketFk, + vNewItemFk, + CEIL(vQuantity / vRoundQuantity) * vRoundQuantity, CONCAT('+ ',i.longName), + vFinalPrice + FROM vn.item i + WHERE id = vNewItemFk; + + SELECT LAST_INSERT_ID() INTO vNewSaleFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE id = vNewSaleFk; + + CALL ticketComponentUpdateSale(vOption); + CALL catalog_componentPurge(); + + INSERT INTO itemProposal(itemFk, mateFk, counter) + VALUES(vItemFk, vNewItemFk, 1) + ON DUPLICATE KEY UPDATE counter = counter + 1; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticketCalculateClon.sql b/db/routines/vn/procedures/ticketCalculateClon.sql index 0be51c2ce..7ded84f45 100644 --- a/db/routines/vn/procedures/ticketCalculateClon.sql +++ b/db/routines/vn/procedures/ticketCalculateClon.sql @@ -11,16 +11,16 @@ BEGIN REPLACE INTO orderTicket(orderFk,ticketFk) SELECT orderFk, vTicketNew FROM orderTicket - WHERE ticketFk = vTicketOld; - + WHERE ticketFk = vTicketOld; + -- Bionizamos lineas con Preu = 0 CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT id + SELECT id FROM sale WHERE ticketFk = vTicketNew AND price = 0; - - CALL sale_recalcComponent(1); + + CALL sale_recalcComponent('renewPrices'); -- Bionizamos lineas con Preu > 0 CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales @@ -28,10 +28,10 @@ BEGIN SELECT id FROM sale WHERE ticketFk = vTicketNew AND price > 0; - - CALL sale_recalcComponent(6); + + CALL sale_recalcComponent('imbalance'); DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; - + END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticketComponentUpdate.sql b/db/routines/vn/procedures/ticketComponentUpdate.sql index 28af8b87f..bdb3bf6cb 100644 --- a/db/routines/vn/procedures/ticketComponentUpdate.sql +++ b/db/routines/vn/procedures/ticketComponentUpdate.sql @@ -1,65 +1,62 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdate`( vTicketFk INT, - vClientFk INT, - vAgencyModeFk INT, - vAddressFk INT, - vWarehouseFk TINYINT, - vCompanyFk SMALLINT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption INT) + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) BEGIN - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN ROLLBACK; - RESIGNAL; + RESIGNAL; END; START TRANSACTION; - - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + UPDATE ticket t JOIN address a ON a.id = vAddressFk SET t.nickname = a.nickname WHERE t.id = vTicketFk; - - END IF; - + END IF; + UPDATE ticket t SET t.clientFk = vClientFk, t.agencyModeFk = vAgencyModeFk, t.addressFk = vAddressFk, t.warehouseFk = vWarehouseFk, - t.companyFk = vCompanyFk, + t.companyFk = vCompanyFk, t.landed = vLanded, t.shipped = vShipped, - t.isDeleted = vIsDeleted + t.isDeleted = vIsDeleted WHERE t.id = vTicketFk; - + IF vHasToBeUnrouted THEN UPDATE ticket t SET t.routeFk = NULL WHERE t.id = vTicketFk; - END IF; - - IF vOption <> 8 THEN - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - - CALL ticketComponentUpdateSale (vOption); - - DROP TEMPORARY TABLE tmp.sale; END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticketComponentUpdateSale.sql b/db/routines/vn/procedures/ticketComponentUpdateSale.sql index fe11d1e83..d002655d1 100644 --- a/db/routines/vn/procedures/ticketComponentUpdateSale.sql +++ b/db/routines/vn/procedures/ticketComponentUpdateSale.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vOption INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketComponentUpdateSale`(vCode VARCHAR(25)) BEGIN /** * A partir de la tabla tmp.sale, crea los Movimientos_componentes @@ -9,153 +9,80 @@ BEGIN * @param table tmp.sale tabla memory con el campo saleFk, warehouseFk **/ DECLARE vComponentFk INT; - DECLARE vRenewComponents BOOLEAN; - DECLARE vKeepPrices BOOLEAN; - - CASE vOption - WHEN 1 THEN - SET vRenewComponents = TRUE; - SET vKeepPrices = FALSE; - WHEN 2 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'debtCollection'; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 3 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'mana'; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 4 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'buyerDiscount'; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - /* WHEN 5 THEN - SET vComponentFk = 35; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE;*/ - WHEN 6 THEN - SELECT id INTO vComponentFk FROM component WHERE `code` = 'imbalance'; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 7 THEN - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk NOT IN (28, 29) - GROUP BY s.id; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk NOT IN (28, 29) - GROUP BY s.id; - - SET vRenewComponents = FALSE; - SET vKeepPrices = FALSE; - WHEN 8 THEN - DELETE sc.* - FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id; - - SET vRenewComponents = FALSE; - SET vKeepPrices = FALSE; - WHEN 9 THEN - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - END CASE; - IF vRenewComponents THEN - DELETE sc.* - FROM tmp.sale tmps - JOIN saleComponent sc ON sc.saleFk = tmps.saleFk - JOIN `component` c ON c.id = sc.componentFk - WHERE c.isRenewable; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, tc.componentFk, tc.cost - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN `component` c ON c.id = tc.componentFk - WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); - - -- Añadir componente venta por paquete - DROP TEMPORARY TABLE IF EXISTS tmp.sale2; - CREATE TEMPORARY TABLE tmp.sale2 - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT * FROM tmp.sale; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent2; - CREATE TEMPORARY TABLE tmp.ticketComponent2 - SELECT * FROM tmp.ticketComponent; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT t.id, t.componentFk, t.cost - FROM ( - SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto - FROM vn.sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id - JOIN vn.buy b ON b.id = buy_id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' - LEFT JOIN ( - SELECT s.id - FROM vn.sale s - JOIN tmp.sale2 tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent2 tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk - JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' - ) tp ON tp.id = s.id - WHERE tp.id IS NULL - HAVING resto <> 0) t; - - DROP TEMPORARY TABLE IF EXISTS - tmp.sale2, - tmp.ticketComponent2; - END IF; + IF vCode <> 'renewPrices' THEN + SELECT id INTO vComponentFk FROM component WHERE `code` = vCode; + END IF; - IF vKeepPrices THEN + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN `component` c ON c.id = sc.componentFk + WHERE c.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, tc.cost + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN `component` c ON c.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE); + + -- Añadir componente venta por paquete + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT t.id, t.componentFk, t.cost + FROM ( + SELECT s.id, tc.componentFk, tc.cost, MOD(s.quantity, b.packing) as resto + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND tmps.warehouseFk = lb.warehouse_id + JOIN vn.buy b ON b.id = buy_id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN `component` c ON c.id = tc.componentFk AND c.code = 'salePerPackage' + LEFT JOIN ( + SELECT s.id + FROM vn.sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + JOIN saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = tc.componentFk + JOIN `component` c ON c.id = sc.componentFk AND c.code = 'lastUnitsDiscount' + ) tp ON tp.id = s.id + WHERE tp.id IS NULL + HAVING resto <> 0) t; + + IF vCode <> 'renewPrices' THEN REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.saleFk <> vComponentFk - GROUP BY s.id - HAVING dif <> 0; - ELSE + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE UPDATE sale s JOIN item i on i.id = s.itemFk JOIN itemType it on it.id = i.typeFk - JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk GROUP BY sc.saleFk) sc ON sc.saleFk = s.id SET s.price = sumValue / ((100 - s.discount) / 100) - WHERE it.code != 'PRT' ; - + WHERE it.code != 'PRT' ; + REPLACE INTO saleComponent(saleFk, componentFk, value) SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id WHERE sc.componentFk != 21 - GROUP BY s.id + GROUP BY s.id HAVING ROUND(saleValue, 4) <> 0; - END IF; - - UPDATE sale s + END IF; + + UPDATE sale s JOIN ( SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc @@ -165,16 +92,16 @@ BEGIN GROUP BY sc.saleFk) sc ON sc.saleFk = s.id SET s.priceFixed = sumValue, s.isPriceFixed = 1; - DELETE sc.* + DELETE sc.* FROM saleComponent sc JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk JOIN sale s on s.id = sc.saleFk JOIN item i ON i.id = s.itemFk JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT'; + WHERE it.code = 'PRT'; INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 15, s.price + SELECT s.id, 15, s.price FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id JOIN item i ON i.id = s.itemFK diff --git a/db/routines/vn/procedures/ticketMissed_List.sql b/db/routines/vn/procedures/ticketMissed_List.sql index c35852b15..6b0f66e6a 100644 --- a/db/routines/vn/procedures/ticketMissed_List.sql +++ b/db/routines/vn/procedures/ticketMissed_List.sql @@ -23,7 +23,7 @@ BEGIN JOIN vn.parking p ON p.id = tp.parkingFk JOIN vn.sector sc ON sc.id = p.sectorFk LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk JOIN vn.ticket t ON t.id = tp.ticketFk JOIN vn.zone z ON z.id = t.zoneFk JOIN vn.agencyMode am ON am.id = z.agencyModeFk diff --git a/db/routines/vn/procedures/ticketParking_findSkipped.sql b/db/routines/vn/procedures/ticketParking_findSkipped.sql index 1da3e2a7f..b00006ffe 100644 --- a/db/routines/vn/procedures/ticketParking_findSkipped.sql +++ b/db/routines/vn/procedures/ticketParking_findSkipped.sql @@ -37,7 +37,7 @@ BEGIN JOIN vn.parking p ON p.id = tp.parkingFk JOIN vn.sector sc ON sc.id = p.sectorFk LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticketFk = tp.ticketFk JOIN vn.ticket t ON t.id = tp.ticketFk JOIN vn.zone z ON z.id = t.zoneFk JOIN vn.agencyMode am ON am.id = z.agencyModeFk diff --git a/db/routines/vn/procedures/ticketStateToday_setState.sql b/db/routines/vn/procedures/ticketStateToday_setState.sql index 98e5ee480..73a92bbb5 100644 --- a/db/routines/vn/procedures/ticketStateToday_setState.sql +++ b/db/routines/vn/procedures/ticketStateToday_setState.sql @@ -14,7 +14,7 @@ BEGIN SELECT s.alertLevel INTO vAlertLevel FROM state s JOIN ticketStateToday tst ON tst.state = s.id - WHERE tst.ticket = vTicketFk + WHERE tst.ticketFk = vTicketFk LIMIT 1; IF vAlertLevel < 2 THEN diff --git a/db/routines/vn/procedures/ticket_canbePostponed.sql b/db/routines/vn/procedures/ticket_canbePostponed.sql index a88099fed..442059b99 100644 --- a/db/routines/vn/procedures/ticket_canbePostponed.sql +++ b/db/routines/vn/procedures/ticket_canbePostponed.sql @@ -22,6 +22,7 @@ BEGIN t.warehouseFk, ts.alertLevel, t.shipped, + t.totalWithVat, sub2.shipped futureShipped, t.workerFk, st.code stateCode, diff --git a/db/routines/vn/procedures/ticket_checkNoComponents.sql b/db/routines/vn/procedures/ticket_checkNoComponents.sql index 6b3e75e85..28fe333f0 100644 --- a/db/routines/vn/procedures/ticket_checkNoComponents.sql +++ b/db/routines/vn/procedures/ticket_checkNoComponents.sql @@ -24,9 +24,9 @@ BEGIN WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo AND ic.merchandise; - CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales + CREATE OR REPLACE TEMPORARY TABLE tmp.recalculateSales (primary key (id)) ENGINE = MEMORY - SELECT DISTINCT s.id + SELECT DISTINCT s.id FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk @@ -37,9 +37,9 @@ BEGIN AND c.id IS NULL AND ic.merchandise; - CALL vn.sale_recalcComponent(1); - - DROP TEMPORARY TABLE tmp.recalculateSales; + CALL sale_recalcComponent('renewPrices'); + + DROP TEMPORARY TABLE tmp.recalculateSales; DROP TEMPORARY TABLE tmp.coste; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_componentMakeUpdate.sql b/db/routines/vn/procedures/ticket_componentMakeUpdate.sql index 001e7ebaa..4b0a5bdbc 100644 --- a/db/routines/vn/procedures/ticket_componentMakeUpdate.sql +++ b/db/routines/vn/procedures/ticket_componentMakeUpdate.sql @@ -1,18 +1,18 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_componentMakeUpdate`( - vTicketFk INT, + vTicketFk INT, vClientFk INT, - vNickname VARCHAR(50), + vNickname VARCHAR(50), vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, + vAddressFk INT, + vZoneFk INT, vWarehouseFk INT, - vCompanyFk INT, + vCompanyFk INT, vShipped DATETIME, - vLanded DATE, + vLanded DATE, vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption INT) + vHasToBeUnrouted BOOLEAN, + vOption VARCHAR(25)) BEGIN /** @@ -53,7 +53,7 @@ BEGIN SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus FROM tmp.zoneGetShipped WHERE shipped BETWEEN DATE(vShipped) AND util.dayEnd(vShipped) AND warehouseFk = vWarehouseFk LIMIT 1; - + UPDATE ticket t SET t.clientFk = vClientFk, @@ -70,29 +70,27 @@ BEGIN t.isDeleted = vIsDeleted WHERE t.id = vTicketFk; - + IF vHasToBeUnrouted THEN UPDATE ticket t SET t.routeFk = NULL WHERE t.id = vTicketFk; END IF; - - IF vOption <> 8 THEN - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - CREATE TEMPORARY TABLE tmp.ticketComponent - SELECT * FROM tmp.ticketComponentPreview; + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; - CALL ticketComponentUpdateSale (vOption); + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent + SELECT * FROM tmp.ticketComponentPreview; - DROP TEMPORARY TABLE tmp.sale; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - END IF; + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; DROP TEMPORARY TABLE tmp.zoneGetShipped, tmp.ticketComponentPreview; END$$ diff --git a/db/routines/vn/procedures/ticket_recalcComponents.sql b/db/routines/vn/procedures/ticket_recalcComponents.sql index f48d70ee2..0282c0e42 100644 --- a/db/routines/vn/procedures/ticket_recalcComponents.sql +++ b/db/routines/vn/procedures/ticket_recalcComponents.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_recalcComponents`(vSelf INT, vOption VARCHAR(25)) proc: BEGIN /** diff --git a/db/routines/vn/procedures/ticket_split.sql b/db/routines/vn/procedures/ticket_split.sql index e8a94c610..172f6829a 100644 --- a/db/routines/vn/procedures/ticket_split.sql +++ b/db/routines/vn/procedures/ticket_split.sql @@ -32,7 +32,7 @@ proc:BEGIN nickname = CONCAT('(',DAY(util.VN_CURDATE()),') ', nickname ) WHERE id = vTicketFk; - SELECT CONCAT("Se ha cambiado el ticket ", vTicketFk, " al dia ", vDated); + SELECT "moved" message, NULL ticketFuture; LEAVE proc; END IF; @@ -46,8 +46,7 @@ proc:BEGIN s.concept = CONCAT('(s) ', s.concept) WHERE ss.ticketFk = vTicketFk; - SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, - " al ticket existente ", vTicketFutureFk,"(", vDated,")"); + SELECT "future" message, NULL ticketFuture; LEAVE proc; END IF; @@ -72,7 +71,6 @@ proc:BEGIN CALL vn.ticketStateUpdate(vTicketFutureFk, 'FIXING'); - SELECT CONCAT("Se han movido lineas del ticket ", vTicketFk, - " al nuevo ticket ", vTicketFutureFk,"(", vDated,")"); + SELECT "new" message,vTicketFutureFk ticketFuture; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/timeWorkerControl_check.sql b/db/routines/vn/procedures/timeWorkerControl_check.sql deleted file mode 100644 index 877bc9b69..000000000 --- a/db/routines/vn/procedures/timeWorkerControl_check.sql +++ /dev/null @@ -1,10 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeWorkerControl_check`(vUserFk INT, vDated DATE,vTabletFk VARCHAR(100)) -proc: BEGIN -/** - * deprecated call workerTimeControl_check - */ -CALL vn.workerTimeControl_check(vUserFk,vDated,vTabletFk); - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlAdd.sql b/db/routines/vn/procedures/workerTimeControlAdd.sql deleted file mode 100644 index 1f5f0db2d..000000000 --- a/db/routines/vn/procedures/workerTimeControlAdd.sql +++ /dev/null @@ -1,14 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlAdd`(IN vUserFk INT, IN vWarehouseFk INT, IN vDated DATETIME) -BEGIN - - /*INSERT INTO workerTimeControl(userFk, timed, manual, warehouseFk) - VALUES(vUserFk, vDated, FALSE, vWarehouseFk); - - CALL vn.workerTimeControlSOWP(vUserFk , vDated);*/ - - CALL vn.workerTimeControl_add(vUserFk,vWarehouseFk,util.VN_NOW(),FALSE); - - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlPinGenerate.sql b/db/routines/vn/procedures/workerTimeControlPinGenerate.sql deleted file mode 100644 index afbb47c31..000000000 --- a/db/routines/vn/procedures/workerTimeControlPinGenerate.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlPinGenerate`( - vWorkerFk INT) -BEGIN -/** - * Create new pin for workerFk or new pin for all workers if vWorkerFk is null - * - */ - - - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControlSetOrder.sql b/db/routines/vn/procedures/workerTimeControlSetOrder.sql deleted file mode 100644 index 953fa25f5..000000000 --- a/db/routines/vn/procedures/workerTimeControlSetOrder.sql +++ /dev/null @@ -1,16 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlSetOrder`() -BEGIN - - SET @order := 1; - SET @userFk := 0; - SET @day := 0; - - UPDATE tmp.workerTimeControl - SET `order` = IF(userFk = @userFk AND day(timed) = @day, @order := @order + 1, @order := 1), - userFk = @userFk := userFk, - manual = manual + (0 * @day := day(timed)) - ORDER BY userFk, timed; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_add.sql b/db/routines/vn/procedures/workerTimeControl_add.sql deleted file mode 100644 index 7769d71aa..000000000 --- a/db/routines/vn/procedures/workerTimeControl_add.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) -BEGIN - - - SELECT workerTimeControl_add(vUserFk,vWarehouseFk,vTimed,vIsManual); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_repair.sql b/db/routines/vn/procedures/workerTimeControl_repair.sql deleted file mode 100644 index f4f0fd0a5..000000000 --- a/db/routines/vn/procedures/workerTimeControl_repair.sql +++ /dev/null @@ -1,39 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_repair`() -proc: BEGIN -/** - * Corrige las fichadas - * - */ - -/*1- poner todos a middle*/ -UPDATE vn.workerTimeControl SET direction = 'middle'; - -/*2- poner los out*/ -UPDATE vn.workerTimeControl wtc - JOIN - (SELECT userFk,MAX(timed) maxTimed FROM - (SELECT id, userFk, timed, date(timed) dated - FROM vn.workerTimeControl - ) sub - GROUP BY userFk,dated - )sub - SET direction = "out" - WHERE wtc.userFk = sub.userFk - AND wtc.timed = sub.maxTimed; - - /*3- poner los in*/ -UPDATE vn.workerTimeControl wtc - JOIN - (SELECT userFk,MIN(timed) maxTimed FROM - (SELECT id, userFk, timed, date(timed) dated - FROM vn.workerTimeControl - ) sub - GROUP BY userFk,dated - )sub - SET direction = "in" - WHERE wtc.userFk = sub.userFk - AND wtc.timed = sub.maxTimed ; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/workerTimeControl_setOrder.sql b/db/routines/vn/procedures/workerTimeControl_setOrder.sql deleted file mode 100644 index c3d3753ae..000000000 --- a/db/routines/vn/procedures/workerTimeControl_setOrder.sql +++ /dev/null @@ -1,15 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControl_setOrder`(vUserFk INT, vStarted DATE, vFinished DATE) -BEGIN - - SET @order := 0; - SET @day := '2000-01-01'; - - UPDATE vn.workerTimeControl w - SET w.`order` = @order := IF(@day = @day := date(timed), @order, 0) + 1 - WHERE w.userFk = vUserFk - AND w.timed BETWEEN vStarted AND util.dayend(vFinished) - ORDER BY w.timed; - -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/zone_upcomingDeliveries.sql b/db/routines/vn/procedures/zone_upcomingDeliveries.sql index 3d83b51cf..96c4136ae 100644 --- a/db/routines/vn/procedures/zone_upcomingDeliveries.sql +++ b/db/routines/vn/procedures/zone_upcomingDeliveries.sql @@ -5,7 +5,7 @@ BEGIN DECLARE vForwardDays INT; SELECT forwardDays INTO vForwardDays FROM zoneConfig; - CALL util.time_createTable(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); + CALL util.time_generate(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); DROP TEMPORARY TABLE IF EXISTS tLandings; CREATE TEMPORARY TABLE tLandings diff --git a/db/routines/vn/triggers/autonomy_AD.sql b/db/routines/vn/triggers/autonomy_afterDelete.sql similarity index 91% rename from db/routines/vn/triggers/autonomy_AD.sql rename to db/routines/vn/triggers/autonomy_afterDelete.sql index f9e1ccf36..f278ccdea 100644 --- a/db/routines/vn/triggers/autonomy_AD.sql +++ b/db/routines/vn/triggers/autonomy_afterDelete.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_AD` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_afterDelete` AFTER DELETE ON `autonomy` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/autonomy_BI.sql b/db/routines/vn/triggers/autonomy_beforeInsert.sql similarity index 93% rename from db/routines/vn/triggers/autonomy_BI.sql rename to db/routines/vn/triggers/autonomy_beforeInsert.sql index e5f9ca9ca..3a6448b81 100644 --- a/db/routines/vn/triggers/autonomy_BI.sql +++ b/db/routines/vn/triggers/autonomy_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_BI` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_beforeInsert` BEFORE INSERT ON `autonomy` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/autonomy_BU.sql b/db/routines/vn/triggers/autonomy_beforeUpdate.sql similarity index 95% rename from db/routines/vn/triggers/autonomy_BU.sql rename to db/routines/vn/triggers/autonomy_beforeUpdate.sql index fd68cef58..a2c9a2a11 100644 --- a/db/routines/vn/triggers/autonomy_BU.sql +++ b/db/routines/vn/triggers/autonomy_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_BU` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`autonomy_beforeUpdate` BEFORE UPDATE ON `autonomy` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/awb_bi.sql b/db/routines/vn/triggers/awb_beforeInsert.sql similarity index 93% rename from db/routines/vn/triggers/awb_bi.sql rename to db/routines/vn/triggers/awb_beforeInsert.sql index 1cc0fc2f7..8dc216024 100644 --- a/db/routines/vn/triggers/awb_bi.sql +++ b/db/routines/vn/triggers/awb_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`awb_bi` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`awb_beforeInsert` BEFORE INSERT ON `awb` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/calendar_afterDelete.sql b/db/routines/vn/triggers/calendar_afterDelete.sql new file mode 100644 index 000000000..acd2c55b7 --- /dev/null +++ b/db/routines/vn/triggers/calendar_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`calendar_afterDelete` + AFTER DELETE ON `calendar` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'Calendar', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/calendar_beforeInsert.sql b/db/routines/vn/triggers/calendar_beforeInsert.sql new file mode 100644 index 000000000..9e51e6d18 --- /dev/null +++ b/db/routines/vn/triggers/calendar_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`calendar_beforeInsert` + BEFORE INSERT ON `calendar` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/calendar_beforeUpdate.sql b/db/routines/vn/triggers/calendar_beforeUpdate.sql new file mode 100644 index 000000000..bb1ba53c3 --- /dev/null +++ b/db/routines/vn/triggers/calendar_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`calendar_beforeUpdate` + BEFORE UPDATE ON `calendar` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/clientCredit_AfterInsert.sql b/db/routines/vn/triggers/clientCredit_AfterInsert.sql index a0f1c65ce..440f24865 100644 --- a/db/routines/vn/triggers/clientCredit_AfterInsert.sql +++ b/db/routines/vn/triggers/clientCredit_AfterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientCredit_AfterInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientCredit_afterInsert` AFTER INSERT ON `clientCredit` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/client_AfterInsert.sql b/db/routines/vn/triggers/client_AfterInsert.sql index 401d8951f..764d8f067 100644 --- a/db/routines/vn/triggers/client_AfterInsert.sql +++ b/db/routines/vn/triggers/client_AfterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_AfterInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_afterInsert` AFTER INSERT ON `client` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/collection_BEFORE_UPDATE.sql b/db/routines/vn/triggers/collection_beforeUpdate.sql similarity index 93% rename from db/routines/vn/triggers/collection_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/collection_beforeUpdate.sql index a4a5ff91c..40a0b7bed 100644 --- a/db/routines/vn/triggers/collection_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/collection_beforeUpdate.sql @@ -1,36 +1,36 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collection_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`collection_beforeUpdate` BEFORE UPDATE ON `collection` FOR EACH ROW -BEGIN - - DECLARE vStateFk INT; - DECLARE vTotalLines INT; - DECLARE vPickedLines INT; - - IF NEW.saleTotalCount <= NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount - OR NEW.salePickedCount != OLD.salePickedCount) - THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'PREPARED'; - - SET NEW.stateFk = vStateFk; - - END IF; - - IF NEW.saleTotalCount > NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'ON_PREPARATION'; - - SET NEW.stateFk = vStateFk; - - END IF; - +BEGIN + + DECLARE vStateFk INT; + DECLARE vTotalLines INT; + DECLARE vPickedLines INT; + + IF NEW.saleTotalCount <= NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount + OR NEW.salePickedCount != OLD.salePickedCount) + THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'PREPARED'; + + SET NEW.stateFk = vStateFk; + + END IF; + + IF NEW.saleTotalCount > NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'ON_PREPARATION'; + + SET NEW.stateFk = vStateFk; + + END IF; + END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/country_AFTER_INSERT.sql b/db/routines/vn/triggers/country_afterInsert.sql similarity index 97% rename from db/routines/vn/triggers/country_AFTER_INSERT.sql rename to db/routines/vn/triggers/country_afterInsert.sql index baf17b18b..0a7e5dc00 100644 --- a/db/routines/vn/triggers/country_AFTER_INSERT.sql +++ b/db/routines/vn/triggers/country_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_afterInsert` AFTER INSERT ON `country` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/delivery_beforeInsert.sql b/db/routines/vn/triggers/delivery_beforeInsert.sql new file mode 100644 index 000000000..89431c30f --- /dev/null +++ b/db/routines/vn/triggers/delivery_beforeInsert.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert` + BEFORE INSERT ON `delivery` + FOR EACH ROW +BEGIN + + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) + THEN + UPDATE address + SET longitude = NEW.longitude, + latitude = NEW.latitude + WHERE id IN ( + SELECT addressFK + FROM ticket + WHERE id = NEW.ticketFk + ); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/delivery_beforeUpdate.sql b/db/routines/vn/triggers/delivery_beforeUpdate.sql new file mode 100644 index 000000000..7e6aa7d4c --- /dev/null +++ b/db/routines/vn/triggers/delivery_beforeUpdate.sql @@ -0,0 +1,20 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate` + BEFORE UPDATE ON `delivery` + FOR EACH ROW +BEGIN + +IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) + THEN + UPDATE address + SET longitude = NEW.longitude, + latitude = NEW.latitude + WHERE id IN ( + SELECT addressFK + FROM ticket + WHERE id = NEW.ticketFk + ); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql b/db/routines/vn/triggers/duaTax_beforeInsert.sql similarity index 93% rename from db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql rename to db/routines/vn/triggers/duaTax_beforeInsert.sql index 5a937cc79..9ca1d970d 100644 --- a/db/routines/vn/triggers/duaTax_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/duaTax_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`duaTax_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`duaTax_beforeInsert` BEFORE INSERT ON `duaTax` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql b/db/routines/vn/triggers/duaTax_beforeUpdate.sql similarity index 93% rename from db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/duaTax_beforeUpdate.sql index 13c7f91c7..dca8958a9 100644 --- a/db/routines/vn/triggers/duaTax_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/duaTax_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`duaTax_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`duaTax_beforeUpdate` BEFORE UPDATE ON `duaTax` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql b/db/routines/vn/triggers/expeditionPallet_beforeInsert.sql similarity index 92% rename from db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql rename to db/routines/vn/triggers/expeditionPallet_beforeInsert.sql index 2ed69502b..419cc2553 100644 --- a/db/routines/vn/triggers/expeditionPallet_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/expeditionPallet_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionPallet_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionPallet_beforeInsert` BEFORE INSERT ON `expeditionPallet` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql b/db/routines/vn/triggers/expeditionScan_beforeInsert.sql similarity index 88% rename from db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql rename to db/routines/vn/triggers/expeditionScan_beforeInsert.sql index dfc25f8bc..1dce8fe9b 100644 --- a/db/routines/vn/triggers/expeditionScan_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/expeditionScan_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionScan_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionScan_beforeInsert` BEFORE INSERT ON `expeditionScan` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/expeditionState_AfterInsert.sql b/db/routines/vn/triggers/expeditionState_AfterInsert.sql index 618c2cfee..3d8f4130c 100644 --- a/db/routines/vn/triggers/expeditionState_AfterInsert.sql +++ b/db/routines/vn/triggers/expeditionState_AfterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_AfterInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_afterInsert` AFTER INSERT ON `expeditionState` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/expeditionState_BeforeInsert.sql b/db/routines/vn/triggers/expeditionState_BeforeInsert.sql index b210889ec..350240aab 100644 --- a/db/routines/vn/triggers/expeditionState_BeforeInsert.sql +++ b/db/routines/vn/triggers/expeditionState_BeforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_BeforeInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_beforeInsert` BEFORE INSERT ON `expeditionState` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql b/db/routines/vn/triggers/expeditionTruck_beforeInsert.sql similarity index 88% rename from db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql rename to db/routines/vn/triggers/expeditionTruck_beforeInsert.sql index d7bf827f0..23cba7b3a 100644 --- a/db/routines/vn/triggers/expeditionTruck_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/expeditionTruck_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionTruck_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionTruck_beforeInsert` BEFORE INSERT ON `expeditionTruck` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql b/db/routines/vn/triggers/expeditionTruck_beforeUpdate.sql similarity index 88% rename from db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/expeditionTruck_beforeUpdate.sql index f08e02ddf..1b3b97238 100644 --- a/db/routines/vn/triggers/expeditionTruck_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/expeditionTruck_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionTruck_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionTruck_beforeUpdate` BEFORE UPDATE ON `expeditionTruck` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql b/db/routines/vn/triggers/floramondoConfig_afterInsert.sql similarity index 89% rename from db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql rename to db/routines/vn/triggers/floramondoConfig_afterInsert.sql index f4d9a5317..f64cb7878 100644 --- a/db/routines/vn/triggers/floramondoConfig_AFTER_INSERT.sql +++ b/db/routines/vn/triggers/floramondoConfig_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`floramondoConfig_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`floramondoConfig_afterInsert` AFTER INSERT ON `floramondoConfig` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/invoiceIn_au.sql b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql similarity index 97% rename from db/routines/vn/triggers/invoiceIn_au.sql rename to db/routines/vn/triggers/invoiceIn_afterUpdate.sql index b8e385c4b..b1308393c 100644 --- a/db/routines/vn/triggers/invoiceIn_au.sql +++ b/db/routines/vn/triggers/invoiceIn_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_au` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_afterUpdate` AFTER UPDATE ON `invoiceIn` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/invoiceIn_bi.sql b/db/routines/vn/triggers/invoiceIn_beforeInsert.sql similarity index 98% rename from db/routines/vn/triggers/invoiceIn_bi.sql rename to db/routines/vn/triggers/invoiceIn_beforeInsert.sql index 5baf75897..c09e71ba1 100644 --- a/db/routines/vn/triggers/invoiceIn_bi.sql +++ b/db/routines/vn/triggers/invoiceIn_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_bi` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeInsert` BEFORE INSERT ON `invoiceIn` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/invoiceIn_bu.sql b/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql similarity index 97% rename from db/routines/vn/triggers/invoiceIn_bu.sql rename to db/routines/vn/triggers/invoiceIn_beforeUpdate.sql index 5fe54a518..ae69ad379 100644 --- a/db/routines/vn/triggers/invoiceIn_bu.sql +++ b/db/routines/vn/triggers/invoiceIn_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_bu` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceIn_beforeUpdate` BEFORE UPDATE ON `invoiceIn` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/invoiceOut_beforeInsert.sql b/db/routines/vn/triggers/invoiceOut_beforeInsert.sql index 159c98370..0081c8803 100644 --- a/db/routines/vn/triggers/invoiceOut_beforeInsert.sql +++ b/db/routines/vn/triggers/invoiceOut_beforeInsert.sql @@ -3,30 +3,57 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_beforeInse BEFORE INSERT ON `invoiceOut` FOR EACH ROW BEGIN - DECLARE vRef CHAR(10) ; +/** + * Generates the next reference for the invoice serial. There cannot be gaps + * between identifiers of the same serial! + * + * Reference format: + * {0} Invoice serial + * {1} The company code + * {2-3} Last two digits of issue year + * {4-$} Autoincrement identifier + */ + DECLARE vRef INT DEFAULT 0; + DECLARE vRefLen INT; + DECLARE vRefPrefix VARCHAR(255); + DECLARE vLastRef VARCHAR(255); + DECLARE vCompanyCode INT; + DECLARE vYearLen INT DEFAULT 2; + DECLARE vPrefixLen INT; - IF YEAR(NEW.issued) <= 2021 THEN + SELECT companyCode INTO vCompanyCode + FROM company + WHERE id = NEW.companyFk; - SELECT CONCAT(NEW.serial, - IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , - RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 7,'0')) + 1) INTO vRef - FROM invoiceOut i - LEFT JOIN company c ON c.id = i.companyFk - WHERE i.serial = NEW.serial - AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) - AND c.id = NEW.companyFk; - ELSE - - SELECT CONCAT(NEW.serial, - IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , - RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 8,'0')) + 1) INTO vRef - FROM invoiceOut i - LEFT JOIN company c ON c.id = i.companyFk - WHERE i.serial = NEW.serial - AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.dayEnd(util.lastDayOfYear(NEW.issued)) - AND c.id = NEW.companyFk; + IF vCompanyCode IS NULL THEN + CALL util.throw('companyCodeNotDefined'); END IF; - SET NEW.ref = vRef; + SELECT MAX(i.ref) INTO vLastRef + FROM invoiceOut i + WHERE i.serial = NEW.serial + AND i.issued BETWEEN util.firstDayOfYear(NEW.issued) AND util.lastDayOfYear(NEW.issued) + AND i.companyFk = NEW.companyFk; + + IF vLastRef IS NOT NULL THEN + SET vPrefixLen = LENGTH(NEW.serial) + LENGTH(vCompanyCode) + vYearLen; + SET vRefLen = LENGTH(vLastRef) - vPrefixLen; + SET vRefPrefix = LEFT(vLastRef, vPrefixLen); + SET vRef = RIGHT(vLastRef, vRefLen); + ELSE + SELECT refLen INTO vRefLen FROM invoiceOutConfig; + SET vRefPrefix = CONCAT( + NEW.serial, + vCompanyCode, + RIGHT(YEAR(NEW.issued), vYearLen) + ); + END IF; + + SET vRef = vRef + 1; + IF LENGTH(vRef) > vRefLen THEN + CALL util.throw('refIdLenExceeded'); + END IF; + + SET NEW.ref = CONCAT(vRefPrefix, LPAD(vRef, vRefLen, '0')); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql b/db/routines/vn/triggers/itemCategory_afterInsert.sql similarity index 93% rename from db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql rename to db/routines/vn/triggers/itemCategory_afterInsert.sql index 82272126d..9449737d1 100644 --- a/db/routines/vn/triggers/itemCategory_AFTER_INSERT.sql +++ b/db/routines/vn/triggers/itemCategory_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemCategory_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemCategory_afterInsert` AFTER INSERT ON `itemCategory` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/itemShelving _afterDelete.sql b/db/routines/vn/triggers/itemShelving _afterDelete.sql new file mode 100644 index 000000000..7c0d54358 --- /dev/null +++ b/db/routines/vn/triggers/itemShelving _afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving _afterDelete` + AFTER DELETE ON `itemShelving` + FOR EACH ROW +BEGIN + INSERT INTO shelvingLog + SET `action` = 'delete', + `changedModel` = 'itemShelving', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql similarity index 89% rename from db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql rename to db/routines/vn/triggers/itemShelvingSale_afterInsert.sql index aca98dbef..63ca893bd 100644 --- a/db/routines/vn/triggers/itemShelvingSale_AFTER_INSERT.sql +++ b/db/routines/vn/triggers/itemShelvingSale_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelvingSale_afterInsert` AFTER INSERT ON `itemShelvingSale` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql b/db/routines/vn/triggers/itemShelving_afterInsert.sql similarity index 95% rename from db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql rename to db/routines/vn/triggers/itemShelving_afterInsert.sql index e9b4397ca..5c0cb3853 100644 --- a/db/routines/vn/triggers/itemShelving_AFTER_INSERT.sql +++ b/db/routines/vn/triggers/itemShelving_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterInsert` AFTER INSERT ON `itemShelving` FOR EACH ROW INSERT INTO vn.itemShelvingLog( itemShelvingFk, diff --git a/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql b/db/routines/vn/triggers/itemShelving_afterUpdate.sql similarity index 94% rename from db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql rename to db/routines/vn/triggers/itemShelving_afterUpdate.sql index 50a9c7d01..107e8ecdc 100644 --- a/db/routines/vn/triggers/itemShelving_AFTER_UPDATE.sql +++ b/db/routines/vn/triggers/itemShelving_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_afterUpdate` AFTER UPDATE ON `itemShelving` FOR EACH ROW INSERT INTO itemShelvingLog diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql b/db/routines/vn/triggers/itemShelving_beforeDelete.sql similarity index 94% rename from db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql rename to db/routines/vn/triggers/itemShelving_beforeDelete.sql index 2018066c4..a9f59e011 100644 --- a/db/routines/vn/triggers/itemShelving_BEFORE_DELETE.sql +++ b/db/routines/vn/triggers/itemShelving_beforeDelete.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_DELETE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeDelete` BEFORE DELETE ON `itemShelving` FOR EACH ROW INSERT INTO vn.itemShelvingLog(itemShelvingFk, diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql b/db/routines/vn/triggers/itemShelving_beforeInsert.sql similarity index 74% rename from db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql rename to db/routines/vn/triggers/itemShelving_beforeInsert.sql index 3a3f5c41a..011cf3701 100644 --- a/db/routines/vn/triggers/itemShelving_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/itemShelving_beforeInsert.sql @@ -1,11 +1,10 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeInsert` BEFORE INSERT ON `itemShelving` FOR EACH ROW BEGIN - + SET NEW.editorFk = account.myUser_getId(); SET NEW.userFk = account.myUser_getId(); - END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql similarity index 77% rename from db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/itemShelving_beforeUpdate.sql index 6937eb1fd..6fd919d2e 100644 --- a/db/routines/vn/triggers/itemShelving_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/itemShelving_beforeUpdate.sql @@ -1,8 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`itemShelving_beforeUpdate` BEFORE UPDATE ON `itemShelving` FOR EACH ROW BEGIN + SET NEW.editorFk = account.myUser_getId(); IF NEW.userFk IS NULL THEN SET NEW.userFk = account.myUser_getId(); END IF; diff --git a/db/routines/vn/triggers/machine_BI.sql b/db/routines/vn/triggers/machine_beforeInsert.sql similarity index 91% rename from db/routines/vn/triggers/machine_BI.sql rename to db/routines/vn/triggers/machine_beforeInsert.sql index 4b9210e65..269879b22 100644 --- a/db/routines/vn/triggers/machine_BI.sql +++ b/db/routines/vn/triggers/machine_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`machine_BI` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`machine_beforeInsert` BEFORE INSERT ON `machine` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/parking_BEFORE_INSERT.sql b/db/routines/vn/triggers/parking_beforeInsert.sql similarity index 91% rename from db/routines/vn/triggers/parking_BEFORE_INSERT.sql rename to db/routines/vn/triggers/parking_beforeInsert.sql index 9ae2464cb..9cf0bd42a 100644 --- a/db/routines/vn/triggers/parking_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/parking_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`parking_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`parking_beforeInsert` BEFORE INSERT ON `parking` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/parking_BEFORE_UPDATE.sql b/db/routines/vn/triggers/parking_beforeUpdate.sql similarity index 92% rename from db/routines/vn/triggers/parking_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/parking_beforeUpdate.sql index bc2187c64..38238daa1 100644 --- a/db/routines/vn/triggers/parking_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/parking_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`parking_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`parking_beforeUpdate` BEFORE UPDATE ON `parking` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/projectNotes_BeforeInsert.sql b/db/routines/vn/triggers/projectNotes_BeforeInsert.sql index 8b6424ef0..58d75bec7 100644 --- a/db/routines/vn/triggers/projectNotes_BeforeInsert.sql +++ b/db/routines/vn/triggers/projectNotes_BeforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`projectNotes_BeforeInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`projectNotes_beforeInsert` BEFORE INSERT ON `projectNotes` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/saleBuy_AI.sql b/db/routines/vn/triggers/saleBuy_AI.sql deleted file mode 100644 index 3186a0ec7..000000000 --- a/db/routines/vn/triggers/saleBuy_AI.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleBuy_AI` - AFTER INSERT ON `saleBuy` - FOR EACH ROW -BEGIN -/* Activar de nuevo cuando volvamos a vender fruta y verdura - * - UPDATE vn.sale s - SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk) - WHERE s.id = NEW.saleFk; -*/ -END$$ -DELIMITER ; diff --git a/db/routines/vn/triggers/BEFORE_INSERT.sql b/db/routines/vn/triggers/saleBuy_beforeInsert.sql similarity index 59% rename from db/routines/vn/triggers/BEFORE_INSERT.sql rename to db/routines/vn/triggers/saleBuy_beforeInsert.sql index c0fcf4e3e..1c36671d5 100644 --- a/db/routines/vn/triggers/BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/saleBuy_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleBuy_beforeInsert` BEFORE INSERT ON `saleBuy` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/saleGroup_afterDelete.sql b/db/routines/vn/triggers/saleGroup_afterDelete.sql new file mode 100644 index 000000000..1e0163187 --- /dev/null +++ b/db/routines/vn/triggers/saleGroup_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroup_afterDelete` + AFTER DELETE ON `saleGroup` + FOR EACH ROW +BEGIN + INSERT INTO ticketLog + SET `action` = 'delete', + `changedModel` = 'SaleGroup', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleGroup_beforeInser.sql b/db/routines/vn/triggers/saleGroup_beforeInser.sql new file mode 100644 index 000000000..18be92ed6 --- /dev/null +++ b/db/routines/vn/triggers/saleGroup_beforeInser.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroup_beforeInsert` + BEFORE INSERT ON `saleGroup` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleGroup_beforeUpdate.sql b/db/routines/vn/triggers/saleGroup_beforeUpdate.sql new file mode 100644 index 000000000..1f6aa6def --- /dev/null +++ b/db/routines/vn/triggers/saleGroup_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleGroup_beforeUpdate` + BEFORE UPDATE ON `saleGroup` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/saleTracking_After_Insert.sql b/db/routines/vn/triggers/saleTracking_afterInsert.sql similarity index 92% rename from db/routines/vn/triggers/saleTracking_After_Insert.sql rename to db/routines/vn/triggers/saleTracking_afterInsert.sql index 861428f19..00bef8486 100644 --- a/db/routines/vn/triggers/saleTracking_After_Insert.sql +++ b/db/routines/vn/triggers/saleTracking_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleTracking_After_Insert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`saleTracking_afterInsert` AFTER INSERT ON `saleTracking` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/sale_BEFORE_DELETE.sql b/db/routines/vn/triggers/sale_beforeDelete.sql similarity index 96% rename from db/routines/vn/triggers/sale_BEFORE_DELETE.sql rename to db/routines/vn/triggers/sale_beforeDelete.sql index 724f65262..a91e7f010 100644 --- a/db/routines/vn/triggers/sale_BEFORE_DELETE.sql +++ b/db/routines/vn/triggers/sale_beforeDelete.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_BEFORE_DELETE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`sale_beforeDelete` BEFORE DELETE ON `sale` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql b/db/routines/vn/triggers/shelving_beforeUpdate.sql similarity index 94% rename from db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/shelving_beforeUpdate.sql index 770e2a495..89e7cb7e9 100644 --- a/db/routines/vn/triggers/shelving_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/shelving_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`shelving_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`shelving_beforeUpdate` BEFORE UPDATE ON `shelving` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql b/db/routines/vn/triggers/solunionCAP_afterInsert.sql similarity index 94% rename from db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql rename to db/routines/vn/triggers/solunionCAP_afterInsert.sql index a35635e43..8524689a7 100644 --- a/db/routines/vn/triggers/solunionCAP_AFTER_INSERT.sql +++ b/db/routines/vn/triggers/solunionCAP_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_AFTER_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_afterInsert` AFTER INSERT ON `solunionCAP` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql b/db/routines/vn/triggers/solunionCAP_afterUpdate.sql similarity index 96% rename from db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql rename to db/routines/vn/triggers/solunionCAP_afterUpdate.sql index 91ea1b4ba..688241515 100644 --- a/db/routines/vn/triggers/solunionCAP_AFTER_UPDATE.sql +++ b/db/routines/vn/triggers/solunionCAP_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_afterUpdate` AFTER UPDATE ON `solunionCAP` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql b/db/routines/vn/triggers/solunionCAP_beforeDelete.sql similarity index 94% rename from db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql rename to db/routines/vn/triggers/solunionCAP_beforeDelete.sql index 590a38734..85d65a949 100644 --- a/db/routines/vn/triggers/solunionCAP_BEFORE_DELETE.sql +++ b/db/routines/vn/triggers/solunionCAP_beforeDelete.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_BEFORE_DELETE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_beforeDelete` BEFORE DELETE ON `solunionCAP` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/specie_BEFORE_INSERT.sql b/db/routines/vn/triggers/specie_beforeInsert.sql similarity index 91% rename from db/routines/vn/triggers/specie_BEFORE_INSERT.sql rename to db/routines/vn/triggers/specie_beforeInsert.sql index 2b5fd85d6..68abf0d30 100644 --- a/db/routines/vn/triggers/specie_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/specie_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`specie_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`specie_beforeInsert` BEFORE INSERT ON `specie` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/specie_BEFORE_UPDATE.sql b/db/routines/vn/triggers/specie_beforeUpdate.sql similarity index 91% rename from db/routines/vn/triggers/specie_BEFORE_UPDATE.sql rename to db/routines/vn/triggers/specie_beforeUpdate.sql index d451c5a8f..364b1d52f 100644 --- a/db/routines/vn/triggers/specie_BEFORE_UPDATE.sql +++ b/db/routines/vn/triggers/specie_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`specie_BEFORE_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`specie_beforeUpdate` BEFORE UPDATE ON `specie` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/tag_BEFORE_INSERT.sql b/db/routines/vn/triggers/tag_beforeInsert.sql similarity index 73% rename from db/routines/vn/triggers/tag_BEFORE_INSERT.sql rename to db/routines/vn/triggers/tag_beforeInsert.sql index 69536a711..27057754d 100644 --- a/db/routines/vn/triggers/tag_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/tag_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`tag_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`tag_beforeInsert` BEFORE INSERT ON `tag` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql b/db/routines/vn/triggers/ticketPackaging_beforeInsert.sql similarity index 90% rename from db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql rename to db/routines/vn/triggers/ticketPackaging_beforeInsert.sql index 36d64ca3e..a58955e0d 100644 --- a/db/routines/vn/triggers/ticketPackaging_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/ticketPackaging_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketPackaging_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketPackaging_beforeInsert` BEFORE INSERT ON `ticketPackaging` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql b/db/routines/vn/triggers/ticketParking_beforeInsert.sql similarity index 88% rename from db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql rename to db/routines/vn/triggers/ticketParking_beforeInsert.sql index ec403b307..2add4f3ea 100644 --- a/db/routines/vn/triggers/ticketParking_BEFORE_INSERT.sql +++ b/db/routines/vn/triggers/ticketParking_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketParking_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketParking_beforeInsert` BEFORE INSERT ON `ticketParking` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/ticketService_ad.sql b/db/routines/vn/triggers/ticketService_afterDelete.sql similarity index 94% rename from db/routines/vn/triggers/ticketService_ad.sql rename to db/routines/vn/triggers/ticketService_afterDelete.sql index 94c771c65..11d5aaf24 100644 --- a/db/routines/vn/triggers/ticketService_ad.sql +++ b/db/routines/vn/triggers/ticketService_afterDelete.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_ad` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_afterDelete` AFTER DELETE ON `ticketService` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/ticketService_ai.sql b/db/routines/vn/triggers/ticketService_afterInsert.sql similarity index 89% rename from db/routines/vn/triggers/ticketService_ai.sql rename to db/routines/vn/triggers/ticketService_afterInsert.sql index c98ebccd5..b9142ff72 100644 --- a/db/routines/vn/triggers/ticketService_ai.sql +++ b/db/routines/vn/triggers/ticketService_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_ai` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_afterInsert` AFTER INSERT ON `ticketService` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/ticketService_au.sql b/db/routines/vn/triggers/ticketService_afterUpdate.sql similarity index 94% rename from db/routines/vn/triggers/ticketService_au.sql rename to db/routines/vn/triggers/ticketService_afterUpdate.sql index 989cb3b08..ecc9e9a5a 100644 --- a/db/routines/vn/triggers/ticketService_au.sql +++ b/db/routines/vn/triggers/ticketService_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_au` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketService_afterUpdate` AFTER UPDATE ON `ticketService` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/time_AFTER_UPDATE.sql b/db/routines/vn/triggers/time_afterUpdate.sql similarity index 96% rename from db/routines/vn/triggers/time_AFTER_UPDATE.sql rename to db/routines/vn/triggers/time_afterUpdate.sql index 14fdf96dc..1eb735923 100644 --- a/db/routines/vn/triggers/time_AFTER_UPDATE.sql +++ b/db/routines/vn/triggers/time_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`time_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`time_afterUpdate` AFTER UPDATE ON `time` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/travel_beforeInsert.sql b/db/routines/vn/triggers/travel_beforeInsert.sql index 38e28b7e9..4e1dae3ef 100644 --- a/db/routines/vn/triggers/travel_beforeInsert.sql +++ b/db/routines/vn/triggers/travel_beforeInsert.sql @@ -7,15 +7,6 @@ BEGIN CALL travel_checkDates(NEW.shipped, NEW.landed); - -- Actualizar agencyFk y agencyModeFk - IF NEW.agencyFk THEN - SET NEW.agencyModeFk = NEW.agencyFk; - END IF; - - IF NEW.agencyModeFk THEN - SET NEW.agencyFk = NEW.agencyModeFk; - END IF; - - CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); + CALL travel_checkWarehouseIsFeedStock(NEW.warehouseInFk); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/travel_beforeUpdate.sql b/db/routines/vn/triggers/travel_beforeUpdate.sql index 46fa2edb8..440b21c04 100644 --- a/db/routines/vn/triggers/travel_beforeUpdate.sql +++ b/db/routines/vn/triggers/travel_beforeUpdate.sql @@ -18,15 +18,6 @@ BEGIN CALL travel_checkDates(NEW.shipped, NEW.landed); END IF; - -- Actualizar agencyFk y agencyModeFk - IF NOT (NEW.agencyFk <=> OLD.agencyFk)THEN - SET NEW.agencyModeFk = NEW.agencyFk; - END IF; - - IF NOT (NEW.agencyModeFk <=> OLD.agencyModeFk) THEN - SET NEW.agencyFk = NEW.agencyModeFk; - END IF; - IF NOT (NEW.isReceived <=> OLD.isReceived) THEN CALL travel_checkPackaging(NEW.id); END IF; diff --git a/db/routines/vn/triggers/workerTimeControl_afterDelete.sql b/db/routines/vn/triggers/workerTimeControl_afterDelete.sql new file mode 100644 index 000000000..6f0f00dbf --- /dev/null +++ b/db/routines/vn/triggers/workerTimeControl_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerTimeControl_afterDelete` + AFTER DELETE ON `workerTimeControl` + FOR EACH ROW +BEGIN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'WorkerTimeControl', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/workerTimeControl_AI.sql b/db/routines/vn/triggers/workerTimeControl_afterInsert.sql similarity index 65% rename from db/routines/vn/triggers/workerTimeControl_AI.sql rename to db/routines/vn/triggers/workerTimeControl_afterInsert.sql index 8e55004eb..b8b9c3b01 100644 --- a/db/routines/vn/triggers/workerTimeControl_AI.sql +++ b/db/routines/vn/triggers/workerTimeControl_afterInsert.sql @@ -1,10 +1,10 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerTimeControl_AI` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerTimeControl_afterInsert` AFTER INSERT ON `workerTimeControl` FOR EACH ROW BEGIN - IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN + IF NEW.timed > (util.VN_NOW() + INTERVAL 1 DAY) THEN CALL util.throw('date in the future'); - END IF; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/workerTimeControl_beforeInsert.sql b/db/routines/vn/triggers/workerTimeControl_beforeInsert.sql new file mode 100644 index 000000000..a899b879a --- /dev/null +++ b/db/routines/vn/triggers/workerTimeControl_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerTimeControl_beforeInsert` + BEFORE INSERT ON `workerTimeControl` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/workerTimeControl_beforeUpdate.sql b/db/routines/vn/triggers/workerTimeControl_beforeUpdate.sql new file mode 100644 index 000000000..969e08711 --- /dev/null +++ b/db/routines/vn/triggers/workerTimeControl_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workerTimeControl_beforeUpdate` + BEFORE UPDATE ON `workerTimeControl` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/workingHoursBeforeInsert.sql b/db/routines/vn/triggers/workingHours_beforeInsert.sql similarity index 93% rename from db/routines/vn/triggers/workingHoursBeforeInsert.sql rename to db/routines/vn/triggers/workingHours_beforeInsert.sql index 763061be8..dce726f10 100644 --- a/db/routines/vn/triggers/workingHoursBeforeInsert.sql +++ b/db/routines/vn/triggers/workingHours_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workingHoursBeforeInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`workingHours_beforeInsert` BEFORE INSERT ON `workingHours` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/zoneExclusion_BI.sql b/db/routines/vn/triggers/zoneExclusion_beforeInsert.sql similarity index 91% rename from db/routines/vn/triggers/zoneExclusion_BI.sql rename to db/routines/vn/triggers/zoneExclusion_beforeInsert.sql index 117a482ab..6b2d2f5c7 100644 --- a/db/routines/vn/triggers/zoneExclusion_BI.sql +++ b/db/routines/vn/triggers/zoneExclusion_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_BI` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_beforeInsert` BEFORE INSERT ON `zoneExclusion` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/zoneExclusion_BU.sql b/db/routines/vn/triggers/zoneExclusion_beforeUpdate.sql similarity index 91% rename from db/routines/vn/triggers/zoneExclusion_BU.sql rename to db/routines/vn/triggers/zoneExclusion_beforeUpdate.sql index cab6ae3c4..1daa6d2f0 100644 --- a/db/routines/vn/triggers/zoneExclusion_BU.sql +++ b/db/routines/vn/triggers/zoneExclusion_beforeUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_BU` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneExclusion_beforeUpdate` BEFORE UPDATE ON `zoneExclusion` FOR EACH ROW BEGIN diff --git a/db/routines/vn/views/awbVolume.sql b/db/routines/vn/views/awbVolume.sql index 0f4778864..2c77973ca 100644 --- a/db/routines/vn/views/awbVolume.sql +++ b/db/routines/vn/views/awbVolume.sql @@ -1,7 +1,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`awbVolume` -AS SELECT `d`.`awbFk` AS `awbFk`, +AS SELECT `t`.`awbFk` AS `awbFk`, `b`.`stickers` * `i`.`density` * IF( `p`.`volume` > 0, `p`.`volume`, @@ -14,23 +14,18 @@ FROM ( ( ( ( - ( - ( - `vn`.`buy` `b` - JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) - ) - JOIN `vn`.`itemType` `it` ON(`i`.`typeFk` = `it`.`id`) - ) - JOIN `vn`.`packaging` `p` ON(`p`.`id` = `b`.`packagingFk`) + `vn`.`buy` `b` + JOIN `vn`.`item` `i` ON(`b`.`itemFk` = `i`.`id`) ) - JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) + JOIN `vn`.`itemType` `it` ON(`i`.`typeFk` = `it`.`id`) ) - JOIN `vn`.`travel` `t` ON(`t`.`id` = `e`.`travelFk`) + JOIN `vn`.`packaging` `p` ON(`p`.`id` = `b`.`packagingFk`) ) - JOIN `vn`.`duaEntry` `de` ON(`de`.`entryFk` = `e`.`id`) + JOIN `vn`.`entry` `e` ON(`b`.`entryFk` = `e`.`id`) ) - JOIN `vn`.`dua` `d` ON(`d`.`id` = `de`.`duaFk`) + JOIN `vn`.`travel` `t` ON(`t`.`id` = `e`.`travelFk`) ) JOIN `vn`.`volumeConfig` `vc` ) WHERE `t`.`shipped` > makedate(year(`util`.`VN_CURDATE`()) - 1, 1) + AND t.awbFk \ No newline at end of file diff --git a/db/routines/vn/views/expeditionRoute_freeTickets.sql b/db/routines/vn/views/expeditionRoute_freeTickets.sql index 2c25ac94f..85e6297c9 100644 --- a/db/routines/vn/views/expeditionRoute_freeTickets.sql +++ b/db/routines/vn/views/expeditionRoute_freeTickets.sql @@ -1,17 +1,26 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER - VIEW `vn`.`expeditionRoute_freeTickets` AS -SELECT - `t`.`routeFk` AS `routeFk`, - `tss`.`ticketFk` AS `ticket`, - `s`.`name` AS `code`, - `w`.`name` AS `almacen`, - `tss`.`updated` AS `updated`, - `p`.`code` AS `parkingCode` - FROM `vn`.`ticketState` `tss` - JOIN `vn`.`ticket` `t` ON `t`.`id` = `tss`.`ticketFk` - JOIN `vn`.`warehouse` `w` ON `w`.`id` = `t`.`warehouseFk` - JOIN `vn`.`state` `s` ON `s`.`id` = `tss`.`state` - LEFT JOIN `vn`.`ticketParking` `tp` ON `tp`.`ticketFk` = `t`.`id` - LEFT JOIN `vn`.`parking` `p` ON `p`.`id` = `tp`.`parkingFk` - WHERE IFNULL(`t`.`packages`, 0) = 0; \ No newline at end of file + VIEW `vn`.`expeditionRoute_freeTickets` +AS SELECT `t`.`routeFk` AS `routeFk`, + `tss`.`ticketFk` AS `ticket`, + `s`.`name` AS `code`, + `w`.`name` AS `almacen`, + `tss`.`updated` AS `updated`, + `p`.`code` AS `parkingCode` +FROM ( + ( + ( + ( + ( + `vn`.`ticketState` `tss` + JOIN `vn`.`ticket` `t` ON(`t`.`id` = `tss`.`ticketFk`) + ) + JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`) + ) + JOIN `vn`.`state` `s` ON(`s`.`id` = `tss`.`state`) + ) + LEFT JOIN `vn`.`ticketParking` `tp` ON(`tp`.`ticketFk` = `t`.`id`) + ) + LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `tp`.`parkingFk`) + ) +WHERE IFNULL(`t`.`packages`, 0) = 0 diff --git a/db/routines/vn/views/itemShelvingAvailable.sql b/db/routines/vn/views/itemShelvingAvailable.sql index e9599a1db..868d6a963 100644 --- a/db/routines/vn/views/itemShelvingAvailable.sql +++ b/db/routines/vn/views/itemShelvingAvailable.sql @@ -38,7 +38,7 @@ FROM ( ) JOIN `vn`.`agencyMode` `am` ON(`am`.`id` = `t`.`agencyModeFk`) ) - JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `t`.`id`) + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticketFk` = `t`.`id`) ) JOIN `vn`.`state` `st` ON(`st`.`id` = `tst`.`state`) ) diff --git a/db/routines/vn/views/itemShelvingStock.sql b/db/routines/vn/views/itemShelvingStock.sql index c4057d7f0..15afe72a2 100644 --- a/db/routines/vn/views/itemShelvingStock.sql +++ b/db/routines/vn/views/itemShelvingStock.sql @@ -1,27 +1,35 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`itemShelvingStock` AS -SELECT ish.itemFk, - SUM(ish.visible) visible, - MIN(ish.packing) packing, - MIN(ish.`grouping`) `grouping`, - s.description sector, - SUM(ish.visible) visibleOriginal, - 0 removed, - p.sectorFk, - s.warehouseFk, - ish.shelvingFk, - p.code, - sh.parkingFk, - ish.id itemShelvingFk, - ish.created, - st.description = 'previousPrepared' isPreviousPrepared - FROM itemShelving ish - LEFT JOIN shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = sh.parkingFk - LEFT JOIN sector s ON s.id = p.sectorFk - LEFT JOIN sectorType st ON st.id = s.typeFk - WHERE ish.visible <> 0 - AND p.sectorFk <> 0 - GROUP BY ish.itemFk, - p.sectorFk +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`itemShelvingStock` +AS SELECT `ish`.`itemFk` AS `itemFk`, + sum(`ish`.`visible`) AS `visible`, + min(`ish`.`packing`) AS `packing`, + min(`ish`.`grouping`) AS `grouping`, + `s`.`description` AS `sector`, + sum(`ish`.`visible`) AS `visibleOriginal`, + 0 AS `removed`, + `p`.`sectorFk` AS `sectorFk`, + `s`.`warehouseFk` AS `warehouseFk`, + `ish`.`shelvingFk` AS `shelvingFk`, + `p`.`code` AS `parkingCode`, + `sh`.`parkingFk` AS `parkingFk`, + `ish`.`id` AS `itemShelvingFk`, + `ish`.`created` AS `created`, + `st`.`description` = 'previousPrepared' AS `isPreviousPrepared` +FROM ( + ( + ( + ( + `vn`.`itemShelving` `ish` + LEFT JOIN `vn`.`shelving` `sh` ON(`sh`.`code` = `ish`.`shelvingFk`) + ) + LEFT JOIN `vn`.`parking` `p` ON(`p`.`id` = `sh`.`parkingFk`) + ) + LEFT JOIN `vn`.`sector` `s` ON(`s`.`id` = `p`.`sectorFk`) + ) + LEFT JOIN `vn`.`sectorType` `st` ON(`st`.`id` = `s`.`typeFk`) + ) +WHERE `ish`.`visible` <> 0 + AND `p`.`sectorFk` <> 0 +GROUP BY `ish`.`itemFk`, + `p`.`sectorFk` diff --git a/db/routines/vn/views/ticketDownBuffer.sql b/db/routines/vn/views/ticketDownBuffer.sql index 84e053fd4..4d157f20c 100644 --- a/db/routines/vn/views/ticketDownBuffer.sql +++ b/db/routines/vn/views/ticketDownBuffer.sql @@ -15,8 +15,8 @@ FROM ( ) JOIN `vn`.`parking` `pk` ON(`pk`.`id` = `tp`.`parkingFk`) ) - JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `td`.`ticketFk`) + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticketFk` = `td`.`ticketFk`) ) - JOIN `vn`.`worker` `w` ON(`w`.`id` = `tst`.`worker`) + JOIN `vn`.`worker` `w` ON(`w`.`id` = `tst`.`userFk`) ) WHERE `td`.`selected` = 2 diff --git a/db/routines/vn/views/ticketState.sql b/db/routines/vn/views/ticketState.sql index f8273d7a9..118a58b34 100644 --- a/db/routines/vn/views/ticketState.sql +++ b/db/routines/vn/views/ticketState.sql @@ -3,14 +3,12 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn`.`ticketState` AS SELECT `tt`.`created` AS `updated`, `tt`.`stateFk` AS `stateFk`, - `tt`.`userFk` AS `workerFk`, + `tt`.`userFk` AS `userFk`, `tls`.`ticketFk` AS `ticketFk`, `s`.`id` AS `state`, `s`.`order` AS `productionOrder`, `s`.`alertLevel` AS `alertLevel`, `s`.`code` AS `code`, - `tls`.`ticketFk` AS `ticket`, - `tt`.`userFk` AS `worker`, `s`.`isPreviousPreparable` AS `isPreviousPreparable`, `s`.`isPicked` AS `isPicked` FROM ( diff --git a/db/routines/vn/views/ticketStateToday.sql b/db/routines/vn/views/ticketStateToday.sql index f4a0ebc02..cf1f24539 100644 --- a/db/routines/vn/views/ticketStateToday.sql +++ b/db/routines/vn/views/ticketStateToday.sql @@ -5,7 +5,7 @@ AS SELECT `ts`.`ticketFk` AS `ticket`, `ts`.`state` AS `state`, `ts`.`productionOrder` AS `productionOrder`, `ts`.`alertLevel` AS `alertLevel`, - `ts`.`worker` AS `worker`, + `ts`.`userFk` AS `worker`, `ts`.`code` AS `code`, `ts`.`updated` AS `updated`, `ts`.`isPicked` AS `isPicked` diff --git a/db/routines/vn/views/zoneEstimatedDelivery.sql b/db/routines/vn/views/zoneEstimatedDelivery.sql index cfd837add..081ccb0bd 100644 --- a/db/routines/vn/views/zoneEstimatedDelivery.sql +++ b/db/routines/vn/views/zoneEstimatedDelivery.sql @@ -19,7 +19,7 @@ FROM ( ( ( `vn`.`ticket` `t` - JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `t`.`id`) + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticketFk` = `t`.`id`) ) JOIN `vn`.`state` `s` ON(`s`.`id` = `tst`.`state`) ) diff --git a/db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql b/db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql deleted file mode 100644 index 3dd9e9dc4..000000000 --- a/db/routines/vn2008/procedures/Cajas_Saldo_Detalle.sql +++ /dev/null @@ -1,51 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Cajas_Saldo_Detalle`() -BEGIN - - Select Proveedores.Id_Proveedor, Proveedor, Fecha, round(Importe) as Importe - from Proveedores - join - ( - select Fecha, sub.Id_Proveedor, sum(Importe) as Importe - from - - ( - - select round(sum(Importe),2) as Importe, TIMESTAMPADD(DAY,-1,util.VN_CURDATE()) as Fecha, Id_Proveedor - from pago - join Proveedores using(Id_Proveedor) - where Fecha >= '2011-01-01' - and Id_Proveedor NOT IN (select id from empresa) - group by Id_Proveedor - - union all - - select IFNULL(-1 * round(sum(rv.Cantidad / if(Id_Moneda = 2,rate,1)),2),0) AS Vto, TIMESTAMPADD(DAY,-1,util.VN_CURDATE()), proveedor_id - from recibida_vencimiento rv - join recibida r on r.id = rv.recibida_id - join reference_rate rr on rr.`date` = rv.fecha - join Proveedores P on P.Id_Proveedor = r.proveedor_id - join Paises PS on PS.Id = P.pais_id - where rv.fecha between '2011-01-01' and util.VN_CURDATE()-1 - and Id_Proveedor NOT IN (select id from empresa) - group by proveedor_id - - union all - - select -1 * round(rv.Cantidad / if(Id_Moneda = 2,(SELECT value FROM vn.referenceRate ORDER BY dated DESC LIMIT 1),1),2) AS Vto, rv.fecha, proveedor_id - from recibida_vencimiento rv - join recibida r on r.id = rv.recibida_id - join Proveedores P on P.Id_Proveedor = r.proveedor_id - join Paises PS on PS.Id = P.pais_id - where rv.fecha >= util.VN_CURDATE() - and Id_Proveedor NOT IN (select id from empresa) - - union all - - select @remesas:= @pago:= @saldo:= 0.0000, util.VN_CURDATE(), @prov:= 0) sub - group by Fecha,Id_Proveedor - ) sub2 using(Id_Proveedor) - having Importe < -100 - ; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql b/db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql deleted file mode 100644 index 3c8e40702..000000000 --- a/db/routines/vn2008/procedures/CompresTriggerBeforeDelete.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`CompresTriggerBeforeDelete`(oldId INT, oldEntrada INT) -BEGIN - - DECLARE hasToRecalculate BOOLEAN; - DECLARE newWarehouse INT; - - SELECT Id_Compra INTO hasToRecalculate FROM vn.lastBuy lb - WHERE lb.id = oldId LIMIT 1; - - IF hasToRecalculate THEN - SELECT warehouse_id INTO newWarehouse FROM travel t - JOIN Entradas e ON t.id = e.travel_id - WHERE e.Id_Entrada = oldEntrada; - - CALL vn.lastBuyRefresh(newWarehouse); - END IF; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql b/db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql deleted file mode 100644 index e48359f55..000000000 --- a/db/routines/vn2008/procedures/EntradasTriggerBeforeDelete.sql +++ /dev/null @@ -1,18 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`EntradasTriggerBeforeDelete`(oldTravel INT, oldId INT) -BEGIN - - DECLARE hasToRecalculate BOOLEAN; - DECLARE newWarehouse INT; - - SELECT Id_Compra INTO hasToRecalculate FROM Compres c - JOIN vn.lastBuy lb ON lb.id = c.Id_Compra - WHERE c.Id_Entrada = newId LIMIT 1; - IF hasToRecalculate THEN - SELECT warehouse_id INTO newWarehouse FROM travel WHERE id = oldTravel; - CALL vn.lastBuyRefresh(newWarehouse); - END IF; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql b/db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql deleted file mode 100644 index 8e387ce1f..000000000 --- a/db/routines/vn2008/procedures/EntradasTriggerBeforeUpdate.sql +++ /dev/null @@ -1,28 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`EntradasTriggerBeforeUpdate`(oldTravel INT, newTravel INT, oldRedada BOOLEAN, - newRedada BOOLEAN, newId INT) -BEGIN - DECLARE newWarehouse INTEGER; - DECLARE hasToRecalculate BOOLEAN; - - IF oldRedada <> newRedada OR newTravel IS NULL THEN - - SELECT Id_Compra INTO hasToRecalculate FROM Compres c - JOIN vn.lastBuy lb ON lb.id = c.Id_Compra - WHERE c.Id_Entrada = newId LIMIT 1; - IF hasToRecalculate THEN - SELECT warehouse_id INTO newWarehouse FROM travel WHERE id = newtravel; - CALL vn.lastBuyRefresh(newWarehouse); - END IF; - END IF; - - IF newTravel <> oldTravel AND newTravel IS NOT NULL THEN - UPDATE travel t - JOIN Compres c ON c.Id_Entrada = newId - JOIN vn.lastBuy lb ON c.Id_Article = lb.item AND t.warehouse_id = lb.warehouse - SET lb.id = c.Id_Compra - WHERE t.id = newTravel AND t.landing BETWEEN vn.getInventoryDate() AND util.yesterday() - AND t.landing > lb.landing; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/Facturas_Saltos.sql b/db/routines/vn2008/procedures/Facturas_Saltos.sql deleted file mode 100644 index 22c7ab516..000000000 --- a/db/routines/vn2008/procedures/Facturas_Saltos.sql +++ /dev/null @@ -1,65 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Facturas_Saltos`(IN datSTART DATE , IN datEND DATE) -BEGIN - - -DECLARE strSER1 VARCHAR(2); -DECLARE strSER2 VARCHAR(2); -DECLARE intEMP1 INT; -DECLARE intEMP2 INT; -DECLARE v_done BOOLEAN DEFAULT FALSE; -DECLARE strFAC1 VARCHAR(11); -DECLARE strFAC2 VARCHAR(11); - - -DECLARE rs CURSOR FOR - SELECT Id_Factura, empresa_id, Serie - FROM Facturas - WHERE Fecha BETWEEN datSTART AND datEND - ORDER BY empresa_id, Serie, Id_Factura; - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; - -OPEN rs; - -DROP TEMPORARY TABLE IF EXISTS Facturas_Saltarinas; - -CREATE TEMPORARY TABLE Facturas_Saltarinas -(Factura_Inicial VARCHAR(11), - Factura_Final VARCHAR(11), - Empresa VARCHAR(3), - Serie VARCHAR(1)); - -FETCH rs INTO strFAC1, intEMP1, strSER1; - -IF NOT v_done THEN - - FETCH rs INTO strFAC2, intEMP2, strSER2; - -END IF; - -WHILE NOT v_done DO - - IF strSER1 = strSER2 AND intEMP1 = intEMP2 AND right(strFAC2,5) - right(strFAC1,5) > 1 then - - INSERT INTO Facturas_Saltarinas(Factura_Inicial, Factura_Final, Empresa, Serie) - SELECT strFAC1, strFAC2, abbreviation, strSER1 - FROM empresa - WHERE id = intEMP1; - - END IF; - - SET strFAC1 = strFAC2; - SET intEMP1 = intEMP2; - SET STRSER1 = strSER2; - - FETCH rs INTO strFAC2, intEMP2, strSER2; - -END WHILE; - -SELECT * FROM Facturas_Saltarinas; - -CLOSE rs; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/InsertarEspionaje.sql b/db/routines/vn2008/procedures/InsertarEspionaje.sql deleted file mode 100644 index 5ddc1c820..000000000 --- a/db/routines/vn2008/procedures/InsertarEspionaje.sql +++ /dev/null @@ -1,26 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`InsertarEspionaje`(intIdTrabajador INT(11),intIdEquipo int) -BEGIN - -DECLARE intNReg TINYINT DEFAULT 0; - -SELECT Count(*) AS NReg -INTO intNReg -FROM Espionajes -WHERE Fecha=Current_date -AND Id_Trabajador=intIdTrabajador; - -IF (intNReg=0) THEN - INSERT INTO Espionajes (Id_Trabajador,Fecha,HoraEntrada,Id_Equipo) - VALUES (intIdTrabajador,CURRENT_DATE,CURRENT_TIME,intIdEquipo); -ELSE - UPDATE Espionajes - SET HoraSalida=CURRENT_TIME - WHERE Id_Trabajador=intIdTrabajador - AND Fecha=util.VN_CURDATE(); -END IF; - - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/Rutas_Graph.sql b/db/routines/vn2008/procedures/Rutas_Graph.sql deleted file mode 100644 index b1a7471d0..000000000 --- a/db/routines/vn2008/procedures/Rutas_Graph.sql +++ /dev/null @@ -1,46 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Rutas_Graph`() -BEGIN - - DECLARE datSTART DATE DEFAULT TIMESTAMPADD(DAY,-3,util.VN_CURDATE()); - DECLARE datEND DATE; - - SET datEND = util.dayEnd(timestampadd(DAY,3,util.VN_CURDATE())); - - CALL vn.buyUltimate(NULL, datSTART); - - SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(buy_id)) / 1000000 AS DECIMAL(5,1)) AS m3, Agencia, w.name AS Almacen, DATE(R.Fecha) AS Fecha_Ruta - FROM vn2008.Rutas R - JOIN vn2008.Agencias a ON a.Id_Agencia = R.Id_Agencia - JOIN vn2008.Tickets t USING(Id_Ruta) - JOIN vn2008.warehouse w ON w.id = t.warehouse_id - JOIN vn2008.Movimientos m USING(Id_Ticket) - JOIN cache.last_buy b ON m.Id_Article = b.item_id AND t.warehouse_id = b.warehouse_id - WHERE R.Fecha BETWEEN datSTART AND datEND - GROUP BY Agencia, Almacen, Fecha_Ruta - UNION ALL - SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(buy_id)) / 1000000 AS decimal(5,1)) AS m3 ,Agencia, w.name AS Almacen, timestampadd(DAY,1,t.Fecha) AS Fecha - FROM vn2008.Tickets t - JOIN warehouse w ON w.id = warehouse_id - JOIN Agencias a USING(Id_Agencia) - JOIN vn2008.Movimientos m USING(Id_Ticket) - JOIN cache.last_buy b ON m.Id_Article = b.item_id AND t.warehouse_id = b.warehouse_id - LEFT JOIN warehouse_pickup wp ON wp.agency_id = t.Id_Agencia and wp.warehouse_id = t.warehouse_id - JOIN warehouse_pickup is_rec ON is_rec.agency_id = t.Id_Agencia - WHERE t.Fecha BETWEEN TIMESTAMPADD(DAY,-1,datSTART) AND TIMESTAMPADD(DAY,-1,datEND) - AND wp.agency_id IS NULL - GROUP BY Agencia, Almacen, timestampadd(DAY,1,t.Fecha) - -- JGF 2016-05-05 - UNION ALL - SELECT CAST(SUM(Cantidad * vn.buy_getUnitVolume(Id_Compra)) / 1000000 AS decimal(5,1)) AS m3 ,a.Agencia, w.name AS Almacen, timestampadd(DAY,1,t.shipment) AS Fecha - FROM Compres c - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - JOIN Agencias a ON a.Id_Agencia = t.agency_id - JOIN warehouse w ON w.id = t.warehouse_id_out - JOIN warehouse_pickup wp ON wp.warehouse_id = t.warehouse_id_out - WHERE t.shipment BETWEEN TIMESTAMPADD(DAY,-1,datSTART) AND TIMESTAMPADD(DAY,-1,datEND) - GROUP BY a.Agencia, Almacen, Fecha; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/Trabuque.sql b/db/routines/vn2008/procedures/Trabuque.sql deleted file mode 100644 index 9efbc86c9..000000000 --- a/db/routines/vn2008/procedures/Trabuque.sql +++ /dev/null @@ -1,72 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Trabuque`(IN intIDTICKET BIGINT, IN dblINCREMENTO DOUBLE ) -BEGIN - - - -#Vamos a calcular el porcentaje a incrementar las cantidades de las lineas de movimiento para inflar / desinflar la base final - -DECLARE dblBASE_INICIAL DOUBLE DEFAULT 0; -DECLARE dblBASE_FINAL DOUBLE DEFAULT 0; -DECLARE dblAUMENTO DOUBLE DEFAULT 1; - - -SELECT SUM(Cantidad * Preu * (100 - Descuento) / 100) -INTO dblBASE_INICIAL -FROM Movimientos -WHERE Id_Ticket = intIDTICKET; - -SET dblBASE_FINAL = dblBASE_INICIAL; - - -#Eliminamos lineas a 0 - -DELETE FROM Movimientos WHERE Cantidad = 0 AND Id_Ticket = intIDTICKET; - -# Vamos a ir probando incrementos paulatinos hasta que encontremos el que supera lo pedido, teniendo en cuenta el sentido del incremento - -IF dblINCREMENTO < 0 THEN - - - - WHILE (dblBASE_FINAL > dblBASE_INICIAL + dblINCREMENTO) or (dblAUMENTO < 0 ) DO - - SET dblAUMENTO = dblAUMENTO - 0.01; - - SELECT SUM(IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) * Preu * (100 - Descuento) / 100) - INTO dblBASE_FINAL - FROM Movimientos - WHERE Id_Ticket = intIDTICKET; - - END WHILE; - -ELSE - - WHILE dblBASE_FINAL < dblBASE_INICIAL + dblINCREMENTO DO - - SET dblAUMENTO = dblAUMENTO + 0.01; - - SELECT SUM(IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) * Preu * (100 - Descuento) / 100) - INTO dblBASE_FINAL - FROM Movimientos - WHERE Id_Ticket = intIDTICKET; - - END WHILE; - -END IF; - -UPDATE Movimientos -SET Cantidad = IF(@cantidad:= ROUND(dblAUMENTO * Cantidad),@cantidad,1) -WHERE Id_Ticket = intIDTICKET; - -SELECT tipoiva - , ROUND(SUM(Cantidad * Preu * (100 - Descuento) / 100),2) as Base - , ROUND(ROUND(SUM(Cantidad * Preu * (100 - Descuento) / 100),2) * iva / 100,2) as Cuota -FROM Movimientos M -INNER JOIN Articles A USING(Id_Article) -INNER JOIN tblIVA USING(tipoiva) -WHERE Id_Ticket = intIDTICKET -GROUP BY tipoiva; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql b/db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql deleted file mode 100644 index 5c8f174be..000000000 --- a/db/routines/vn2008/procedures/Vehiculos_consumo_calculateLiters100km.sql +++ /dev/null @@ -1,42 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`Vehiculos_consumo_calculateLiters100km`() -BEGIN - DECLARE vConsumptionVehicleId INT; - DECLARE vDone BOOL; - DECLARE vOldKm INT; - DECLARE vOldLiters INT; - DECLARE vNewKm INT; - DECLARE vVehicleId INT; - - DECLARE cur CURSOR FOR - SELECT Vehiculos_consumo_id, Id_Vehiculo, km FROM vn2008.Vehiculos_consumo; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN cur; - - l: LOOP - SET vDone = FALSE; - FETCH cur INTO vConsumptionVehicleId, vVehicleId, vNewKm; - - IF vDone THEN - LEAVE l; - END IF; - - SELECT km, litros INTO vOldKm, vOldLiters - FROM Vehiculos_consumo - WHERE Id_Vehiculo = vVehicleId - AND Vehiculos_consumo_id < vConsumptionVehicleId - ORDER BY Vehiculos_consumo_id DESC - LIMIT 1; - - UPDATE Vehiculos_consumo - SET liters100km = vOldLiters/((vNewKm-vOldKm)*0.01) - WHERE Vehiculos_consumo_id = vConsumptionVehicleId; - - END LOOP; - - CLOSE cur; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/add_awb_component.sql b/db/routines/vn2008/procedures/add_awb_component.sql index a563bd0df..e75290b4b 100644 --- a/db/routines/vn2008/procedures/add_awb_component.sql +++ b/db/routines/vn2008/procedures/add_awb_component.sql @@ -5,13 +5,10 @@ BEGIN DECLARE vShipped DATE; DECLARE vHasStems BOOLEAN; - SELECT tr.shipped, IF(a.stems, TRUE, FALSE) + SELECT t.shipped, IF(a.stems, TRUE, FALSE) INTO vShipped, vHasStems - FROM vn.travel tr - JOIN vn.entry e ON e.travelFk = tr.id - JOIN vn.duaEntry de ON de.entryFk = e.id - JOIN vn.dua d ON d.id = de.duaFk - JOIN vn.awb a ON a.id = d.awbFk + FROM vn.travel t + JOIN vn.awb a ON a.id = t.awbFk WHERE awbFk = vAwbFk LIMIT 1; diff --git a/db/routines/vn2008/procedures/agencia_descuadre.sql b/db/routines/vn2008/procedures/agencia_descuadre.sql deleted file mode 100644 index 59bf2476d..000000000 --- a/db/routines/vn2008/procedures/agencia_descuadre.sql +++ /dev/null @@ -1,32 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`agencia_descuadre`(vFrom DATE, vTo DATE, vAgencyModeFk INT, vWarehouseAlias INT) -BEGIN - DECLARE vToDayEnd DATETIME; - - SET vToDayEnd = util.dayEnd(vTo); - - SELECT t.id ticketFk,t.addressFk, - v.amount AS VN, v.amount - shipping_charge AS Difer, - e.shipping_charge AS teorico, t.packages, t.clientFk, t.zoneFk, a.provinceFk - - FROM vn.ticket t - LEFT JOIN - (SELECT ticketFk, SUM(amount) amount,shipped - FROM vn.sale_freightComponent - WHERE shipped BETWEEN vFrom AND vToDayEnd - GROUP BY ticketFk) v ON t.id = v.ticketFk - LEFT JOIN (SELECT t.id, SUM(t.zonePrice * ebv.ratio) shipping_charge - FROM vn.ticket t - LEFT JOIN vn.expedition e ON e.ticketFk = t.id - JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk - WHERE t.shipped BETWEEN vFrom AND vToDayEnd - GROUP BY t.id - ) e ON t.id = e.id - JOIN vn.address a ON a.id = t.addressFk - JOIN warehouse_group wg ON wg.warehouse_id = t.warehouseFk - WHERE DATE(t.shipped) BETWEEN vFrom AND vToDayEnd - AND t.agencyModeFk = vAgencyModeFk - AND wg.warehouse_alias_id = vWarehouseAlias; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/article_available_single.sql b/db/routines/vn2008/procedures/article_available_single.sql deleted file mode 100644 index efc0df3b7..000000000 --- a/db/routines/vn2008/procedures/article_available_single.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`article_available_single`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT) -BEGIN - -/* CALL bionic_available_single (v_wh, v_date,id_single,0);*/ - - - SELECT available AS minimo FROM tmp.item - WHERE item_id = id_single; --- ixen totes les linies en lloc d'una sola - DROP TEMPORARY TABLE IF EXISTS tmp.item; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/base_ticket.sql b/db/routines/vn2008/procedures/base_ticket.sql deleted file mode 100644 index 2352eabaf..000000000 --- a/db/routines/vn2008/procedures/base_ticket.sql +++ /dev/null @@ -1,12 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`base_ticket`(IN Id_Ticket INT) -BEGIN - SELECT - red(SUM(Cantidad * Preu * (100 - Descuento) / 100)) AS base - FROm - Movimientos m - INNER JOIN Tickets t USING (Id_Ticket) - WHERE t.Id_Ticket = Id_Ticket; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/bionic_available_types_filter.sql b/db/routines/vn2008/procedures/bionic_available_types_filter.sql deleted file mode 100644 index 308c6396e..000000000 --- a/db/routines/vn2008/procedures/bionic_available_types_filter.sql +++ /dev/null @@ -1,38 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`bionic_available_types_filter`( - v_date DATE, - v_consigna INT, - v_agencia INT) -BEGIN -/** - * Este procedimiento devuelve una tabla t_bionic_available_types - * que debe de ser borrar por quien la llame, y se conecta con la tabla articlelist - * que tambien hay que eliminar. - * - * @param vDatefecha de recepcion de mercancia - * @table t_bionic_available_types - */ - - CALL vn.catalog_Calculate(v_date, v_consigna, v_agencia); - - -- Introducimos los valores en una tabla temporal - DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types; - - CALL check_table_existence('articlelist'); - - IF @table_exists THEN - call util.throw('No usar articlelist'); - END IF; - - CREATE TEMPORARY TABLE t_bionic_available_types - SELECT a.tipo_id, t.Tipo, r.reino, count(*) as item_count - FROM tmp.ticketCalculateItem tci - JOIN vn2008.Articles a ON tci.itemFk = a.Id_Article - JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id - JOIN vn2008.reinos r ON r.id = t.reino_id - WHERE tci.available > 0 - GROUP BY a.tipo_id; - - DROP TEMPORARY TABLE tmp.ticketCalculateItem; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_label.sql b/db/routines/vn2008/procedures/buy_label.sql deleted file mode 100644 index 0ee1be5a4..000000000 --- a/db/routines/vn2008/procedures/buy_label.sql +++ /dev/null @@ -1,40 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_label`(IN entry_id_ INT, IN groupby TINYINT(1)) -BEGIN - - DECLARE done INT DEFAULT 0; - DECLARE label INT; - DECLARE id INT; - DECLARE recordset CURSOR FOR SELECT Compres.Etiquetas, Compres.Id_Compra FROM Compres INNER JOIN - (SELECT e.Id_entrada FROM Entradas e INNER JOIN ( - SELECT Id_Entrada,Inventario,Id_proveedor,travel_id,Id_Agencia FROM Entradas e1 INNER JOIN travel t ON e1.travel_id = t.id WHERE Id_Entrada = entry_id_) y - ON y.Inventario = e.Inventario AND e.travel_id = y.travel_id AND e.Id_proveedor = y.Id_proveedor AND y.Id_Agencia = e.Id_Agencia - WHERE (0 OR e.Id_Entrada = entry_id_)) entry_label - ON Compres.Id_Entrada = entry_label.Id_entrada - INNER JOIN Articles ON Compres.Id_Article = Articles.Id_Article WHERE Articles.Imprimir <> FALSE; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; - - DROP TEMPORARY TABLE IF EXISTS `buy_label_source`; - - CREATE TEMPORARY TABLE `buy_label_source` - ( - `buy_id` INT(11) NOT NULL - ) - - ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - OPEN recordset; - - REPEAT - - FETCH recordset INTO label, id; - WHILE label > 0 DO - - SET label = label - 1; - INSERT INTO buy_label_source (buy_id) VALUES (id); - - END WHILE; - - UNTIL done END REPEAT; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_split.sql b/db/routines/vn2008/procedures/buy_split.sql deleted file mode 100644 index 188bd89ec..000000000 --- a/db/routines/vn2008/procedures/buy_split.sql +++ /dev/null @@ -1,150 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_split`(IN `v_buy` INT, IN `v_entry` INT) -BEGIN - - -- DEPRECATED use vn.buySplit - - DECLARE v_item INT; - DECLARE v_packing INT; - DECLARE v_remaining INT; - DECLARE v_labels INT; - DECLARE v_remainder INT; - DECLARE v_is_buy INT; - DECLARE v_id INT; - DECLARE v_amount INT; - DECLARE v_done BOOL DEFAULT FALSE; - DECLARE vNameCharMax INT DEFAULT 16; - - DECLARE cur CURSOR FOR - SELECT TRUE, c.Id_Compra, c.Cantidad - IFNULL((c.Vida * c.Packing), 0) - FROM Compres c - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE c.Id_Article = v_item - AND DATE(t.shipment) = util.VN_CURDATE() AND t.warehouse_id_out IN (7, 40) - AND t.warehouse_id NOT IN (60) - AND NOT e.redada AND NOT e.Inventario - AND IFNULL(c.Vida, 0) < c.Etiquetas - UNION ALL - SELECT FALSE, m.Id_Movimiento, m.Cantidad - IFNULL(l.stem, 0) - FROM Movimientos m - JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket - LEFT JOIN movement_label l ON l.Id_Movimiento = m.Id_Movimiento - WHERE m.Id_Article = v_item - AND t.Fecha >= util.VN_CURDATE() AND t.warehouse_id IN (7, 40) - AND NOT t.Etiquetasemitidas - AND IFNULL(l.stem, 0) < m.Cantidad - LOCK IN SHARE MODE; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET v_done = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - -- Obtiene los datos de la compra - - SELECT Id_Article, Packing, Cantidad - INTO v_item, v_packing, v_remaining - FROM Compres WHERE Id_Compra = v_buy; - - -- Crea splits de los tickets - - DROP TEMPORARY TABLE IF EXISTS tmp.split; - CREATE TEMPORARY TABLE tmp.split - ( - is_buy BOOL, - id INT, - labels INT, - remainder INT - ) - ENGINE = MEMORY; - - OPEN cur; - - l: LOOP - SET v_done = FALSE; - FETCH cur INTO v_is_buy, v_id, v_amount; - - IF v_done OR v_remaining = 0 THEN - LEAVE l; - END IF; - - SET v_amount = LEAST(v_amount, v_remaining); - SET v_remaining = v_remaining - v_amount; - SET v_labels = v_amount DIV v_packing; - - INSERT INTO tmp.split - VALUES (v_is_buy, v_id, v_labels, v_amount % v_packing); - - IF v_is_buy - THEN - UPDATE Compres - SET Vida = Vida + v_labels - WHERE Id_Compra = v_id; - ELSE - INSERT INTO movement_label - SET - Id_Movimiento = v_id, - stem = v_amount, - label = v_labels - ON DUPLICATE KEY UPDATE - stem = stem + VALUES(stem), - label = label + VALUES(label); - END IF; - END LOOP; - - CLOSE cur; - - -- Crea los movimientos de almacén a silla - - CALL buy_transfer (v_buy, v_entry); - - UPDATE Compres SET dispatched = Vida * Packing - WHERE Id_Compra = v_buy; - - -- Devuelve los splits creados - - DROP TEMPORARY TABLE IF EXISTS tmp.aux; - CREATE TEMPORARY TABLE tmp.aux - ENGINE = MEMORY - SELECT s.labels, s.remainder, w.`name` destination, - a.Id_Article, a.Article, a.Medida, ' ' counter, ' ' destination2 - FROM tmp.split s - JOIN Compres c ON c.Id_Compra = s.id - JOIN Articles a ON a.Id_Article = c.Id_Article - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - JOIN warehouse w ON t.warehouse_id = w.id - WHERE s.is_buy; - - INSERT INTO tmp.aux - SELECT s.labels, s.remainder, IF(p.`name` IN ('BARCELONA','TARRAGONA','GIRONA','LLEIDA','LÉRIDA') AND t.Id_Cliente != 93, '<< VILASSAR >>',o.Consignatario), - a.Id_Article, a.Article, a.Medida, - vn.ticketSplitCounter(t.Id_Ticket), IF(p.`name` IN ('BARCELONA','TARRAGONA','GIRONA','LLEIDA','LÉRIDA') AND t.Id_Cliente != 93, o.Consignatario,CONCAT(o.id_consigna, ' ', p.`name`,' (', c.`code`,')')) - /*UCASE(CONCAT(p.`name`,' (', c.`code`, ')'))*/ - FROM tmp.split s - JOIN Movimientos m ON m.Id_Movimiento = s.id - JOIN Articles a ON a.Id_Article = m.Id_Article - JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket - JOIN Consignatarios o ON o.Id_Consigna = t.Id_Consigna - JOIN vn.province p ON p.id = o.province_id - JOIN vn.country c ON c.id = p.countryFk - WHERE NOT s.is_buy; - - SELECT * FROM tmp.aux; - - -- Limpia y confirma cambios - - DROP TEMPORARY TABLE - tmp.split, - tmp.aux; - - COMMIT; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql b/db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql deleted file mode 100644 index d2248505d..000000000 --- a/db/routines/vn2008/procedures/buy_tarifas_recalcular_almacen.sql +++ /dev/null @@ -1,36 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_tarifas_recalcular_almacen`(IN wh_id INT, IN datFEC DATE) -BEGIN - -DECLARE done INT DEFAULT 0; -DECLARE idE INT; - -DECLARE cur1 CURSOR FOR -SELECT Id_Entrada -FROM Entradas -JOIN travel ON travel.id = travel_id -WHERE landing >= datFEC AND wh_id IN (0,warehouse_id); - -DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; - -OPEN cur1; - -REPEAT - - FETCH cur1 INTO idE; - - IF NOT done THEN - - Call buy_tarifas_entry(idE); - - - - END IF; - - -UNTIL done END REPEAT; - - CLOSE cur1; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/buy_transfer.sql b/db/routines/vn2008/procedures/buy_transfer.sql deleted file mode 100644 index 935a570bd..000000000 --- a/db/routines/vn2008/procedures/buy_transfer.sql +++ /dev/null @@ -1,104 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`buy_transfer`(IN `v_buy` INT, IN `entryFk` INT) -proc: BEGIN -/** - * Traslada la cantidad restante de una compra de Holanda - * al almacén de Silla. - */ - DECLARE v_wh INT; - DECLARE v_fv INT; - DECLARE v_amount INT; - DECLARE v_item INT; - DECLARE v_holland_wh INT DEFAULT 7; - DECLARE vIsIgnored BOOL DEFAULT FALSE; - DECLARE vDestinationWarehouse INT; - - -- Comprueba que es mercancía que llega al almacén de Holanda - - SELECT t.warehouse_id, IF(tp.warehouseFk=1,1,0), tp.warehouseFk, c.Id_Article, c.Novincular - INTO v_wh, v_fv, vDestinationWarehouse, v_item, vIsIgnored - FROM Compres c - JOIN Entradas e ON c.Id_Entrada = e.Id_Entrada - JOIN travel t ON t.id = e.travel_id - JOIN Articles a ON a.Id_Article = c.Id_Article - JOIN Tipos tp ON tp.tipo_id = a.tipo_id - WHERE c.Id_Compra = v_buy; - - IF v_wh != v_holland_wh THEN - LEAVE proc; - END IF; - - IF entryFk IS NULL THEN - LEAVE proc; - END IF; - - -- Calcula la cantidad a trasladar - - SELECT IFNULL(SUM(amount), 0) INTO v_amount - FROM ( - SELECT SUM(c.Cantidad) amount - FROM Compres c - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE c.Id_Article = v_item - AND t.landing = util.VN_CURDATE() - AND t.warehouse_id = v_holland_wh - UNION ALL - SELECT -SUM(c.Cantidad) - FROM Compres c - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE c.Id_Article = v_item - AND t.shipment = util.VN_CURDATE() - AND t.warehouse_id_out = v_holland_wh - UNION ALL - SELECT -SUM(Cantidad) - FROM Movimientos m - JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket - WHERE m.Id_Article = v_item - AND t.Fecha = util.VN_CURDATE() - AND t.warehouse_id = v_holland_wh - ) t; - - IF v_amount <= 0 THEN - LEAVE proc; - END IF; - - -- Si la linea tiene no vincular hay que buscar la anterior válida - IF vIsIgnored THEN - CALL buyUltimate(vDestinationWarehouse, util.VN_CURDATE()); - SELECT buyFk INTO v_buy - FROM tmp.buyUltimate - LIMIT 1; - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - END IF; - - -- Crea la nueva línea de compra con el translado - - INSERT INTO Compres ( - Id_Article, Etiquetas, Cantidad, Id_Entrada, - Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, - Embalajefijo, Comisionfija, buy_edi_id) - SELECT c.Id_Article, - v_amount DIV c.Packing, - v_amount, - entryFk, - c.Id_Cubo, - c.Packing, - c.`grouping`, - c.caja, - @cost := IFNULL(c.Costefijo, 0) + IFNULL(c.Comisionfija, 0) + IFNULL(c.Portefijo, 0), - @porte := ROUND((@cm3:= vn.item_getVolume(c.Id_Article, c.Id_Cubo)) * a.m3 / 1000000 / c.Packing, 3), - c.EmbalajeFijo, - @comision := ROUND(c.Costefijo * e.comision / 100, 3), - c.buy_edi_id - FROM Compres c - JOIN Cubos cu ON cu.Id_Cubo = c.Id_Cubo - JOIN Entradas e ON e.Id_Entrada = entryFk - JOIN travel t ON t.id = e.travel_id - JOIN Agencias a ON t.agency_id = a.Id_Agencia - WHERE c.Id_Compra = v_buy; - - CALL buy_tarifas (LAST_INSERT_ID()); -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/check_table_existence.sql b/db/routines/vn2008/procedures/check_table_existence.sql deleted file mode 100644 index 081912d3b..000000000 --- a/db/routines/vn2008/procedures/check_table_existence.sql +++ /dev/null @@ -1,16 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`check_table_existence`(IN table_name CHAR(64)) -BEGIN - DECLARE CONTINUE HANDLER FOR SQLSTATE '42S02' SET @err = 1; - SET @err = 0; - SET @table_name = table_name; - SET @sqlString = CONCAT('SELECT NULL FROM ',@table_name); - PREPARE stmt1 FROM @sqlString; - IF (@err = 1) THEN - SET @table_exists = 0; - ELSE - SET @table_exists = 1; - DEALLOCATE PREPARE stmt1; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/clean.sql b/db/routines/vn2008/procedures/clean.sql index e2f3c9544..c2d2e34a0 100644 --- a/db/routines/vn2008/procedures/clean.sql +++ b/db/routines/vn2008/procedures/clean.sql @@ -77,13 +77,23 @@ proc: BEGIN DELETE FROM scan WHERE odbc_date < vDate6 AND id <> 1; IF v_full THEN + CREATE OR REPLACE TEMPORARY TABLE tTicketDelete + SELECT DISTINCT tl.originFk ticketFk + FROM vn.ticketLog tl + JOIN (SELECT MAX(tl.id)ids + FROM vn.ticket t + JOIN vn.ticketLog tl ON tl.originFk = t.id + WHERE t.shipped BETWEEN '2000-01-01' AND '2000-12-31' + AND t.isDeleted + GROUP BY t.id + )sub ON sub.ids = tl.id + WHERE tl.creationDate <= util.VN_CURDATE() - INTERVAL 60 DAY; + DELETE t - FROM Tickets t - LEFT JOIN Tickets_turno tt ON tt.Id_Ticket = t.Id_Ticket - WHERE Fecha NOT IN ('2000-01-01','2000-01-02') - AND YEAR(Fecha) = 2000 - AND ABS(DATEDIFF(Fecha,vDate2000)) > vRangeDeleteTicket - AND tt.Id_Ticket IS NULL; + FROM vn.ticket t + JOIN tTicketDelete tmp ON tmp.ticketFk = t.id; + + DROP TEMPORARY TABLE tTicketDelete; END IF; -- Tickets Nulos PAK 11/10/2016 diff --git a/db/routines/vn2008/procedures/comercial_caducado.sql b/db/routines/vn2008/procedures/comercial_caducado.sql deleted file mode 100644 index 47b0d6249..000000000 --- a/db/routines/vn2008/procedures/comercial_caducado.sql +++ /dev/null @@ -1,57 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`comercial_caducado`() -BEGIN - --- Este procedimiento le pasa los clientes al jefe de ventas cuando llevan dos meses inactivos - -IF day(util.VN_CURDATE()) = 5 then -- solo se ejecuta los dias 5 de cada mes - - Update Clientes - join - ( - Select c.Id_Cliente - from Clientes c - join jerarquia j on j.worker_id = c.Id_Trabajador -- este filtro es para que solo toque los de los comerciales - - join - ( - select Id_Cliente, sum(Importe) as Saldo - from - ( - select Id_Cliente, Importe from Facturas - union all - select Id_Cliente, - Entregado from Recibos - ) sub - group by Id_Cliente - ) sindeuda on sindeuda.Id_Cliente = c.Id_Cliente - - left join - ( - select distinct Id_Cliente - from Facturas - where Fecha BETWEEN util.VN_CURDATE() - INTERVAL 12 MONTH AND util.VN_CURDATE() - ) f on f.Id_Cliente = c.Id_Cliente - - left join - ( - select distinct Id_Cliente - from Tickets - where Fecha between util.VN_CURDATE() - INTERVAL 2 DAY AND util.VN_CURDATE() + INTERVAL 200 DAY - - ) tic_vivos on tic_vivos.Id_Cliente = c.Id_Cliente - - where c.Created < util.VN_CURDATE() - INTERVAL 2 MONTH -- este filtro respeta a los recien nacidos.... - and j.boss_id = 87 -- sólo afecta a los comerciales de Alfredo - and f.Id_Cliente is null -- comprueba que no tenga facturas en los dos ultimos meses - and sindeuda.Saldo < 10 -- sólo cambia a los clientes con deuda escasa o nula - and tic_vivos.Id_Cliente is null -- si tiene tickets vivos, lo respeta - - - ) sub using(Id_Cliente) - - set Id_Trabajador = 87 ;-- Alfredo Giner; - -end if; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql b/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql deleted file mode 100644 index 107bb59af..000000000 --- a/db/routines/vn2008/procedures/compresTriggerBeforeInsert.sql +++ /dev/null @@ -1,17 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`compresTriggerBeforeInsert`(newNoVincular INT, newEntrada INT, newCompra INT, newItem INT) -BEGIN - DECLARE newWarehouse INTEGER; - - IF newNoVincular = FALSE THEN - - UPDATE travel t - JOIN vn.lastBuy lb ON newItem = lb.item AND t.warehouse_id = lb.warehouse - JOIN Entradas e ON e.travel_id = t.id - SET lb.id = newCompra - WHERE e.Id_Entrada = newEntrada AND t.landing > lb.landing AND t.landing <= util.VN_CURDATE(); - - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql b/db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql deleted file mode 100644 index e420dc0ab..000000000 --- a/db/routines/vn2008/procedures/compresTriggerBeforeUpdate.sql +++ /dev/null @@ -1,36 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`compresTriggerBeforeUpdate`(vOldEntrada INT, vNewEntrada INT, oldItem INT, - newItem INT, newNoVincular BOOLEAN, newCompra INT) -BEGIN - DECLARE newWarehouse INTEGER; - DECLARE hasToRecalculate BOOLEAN; - - IF newNoVincular = FALSE THEN - IF oldItem <> newItem OR vOldEntrada <> vNewEntrada THEN - SELECT Id_Compra INTO hasToRecalculate FROM travel t - JOIN Entradas e ON e.travel_id = t.id - JOIN vn.lastBuy lb ON lb.id = newCompra - WHERE e.Id_Entrada = vOldEntrada LIMIT 1; - - IF hasToRecalculate THEN - SELECT warehouse_id INTO newWarehouse FROM travel t - JOIN Entradas e ON t.id = e.travel_id - WHERE e.Id_Entrada = vOldEntrada; - CALL vn.lastBuyRefresh(newWarehouse); - END IF; - END IF; - IF vOldEntrada <> vNewEntrada THEN - - UPDATE Entradas oldEntrada - JOIN travel oldTravel ON oldEntrada.travel_id = oldtravel.id - JOIN Entradas newEntrada ON newEntrada.Id_Entrada = vNewEntrada - JOIN travel newTravel ON newTravel.id = newEntrada.travel_id - JOIN vn.lastBuy lb ON newItem = lb.item AND newTravel.warehouse_id = lb.warehouse - SET lb.id = newCompra - WHERE oldEntrada.Id_Entrada = vOldEntrada AND oldTravel.warehouse_id <> newTravel.warehouse_id - AND newTravel.landing > lb.landing AND newTravel.landing <= util.VN_CURDATE(); - END IF; - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/createBouquet.sql b/db/routines/vn2008/procedures/createBouquet.sql deleted file mode 100644 index 2796ce9aa..000000000 --- a/db/routines/vn2008/procedures/createBouquet.sql +++ /dev/null @@ -1,50 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`createBouquet`( - vName VARCHAR(50), - vType int, - vSize int, - vColour VARCHAR(5), - OUT vItem INT(11) -) -BEGIN - - DECLARE vTaxClass VARCHAR(1); - DECLARE vIntrastatFk INT(11); - - -- COMPROBAMOS SI EXISTE UN ARTÍCULO IGUAL. - SELECT Id_Article INTO vItem - FROM Articles - WHERE (Id_Article BETWEEN 161000 AND 169000) - AND Article LIKE CONCAT('%', vName) - AND tipo_id = vType - AND Medida = vSize - AND Color = vColour - LIMIT 1; - - -- SI NO EXISTE CREAMOS UNO NUEVO - IF vItem IS NULL THEN - - -- OBTENER EL ID ENTRE 161000 Y 169000 DEL SIGUIENTE ARTÍCULO - SELECT (IF(MAX(Id_Article) IS NULL, 161000, (MAX(Id_Article) + 1))) INTO vItem FROM Articles WHERE Id_Article BETWEEN 161000 AND 169000; - - -- INSERTAR EL ARTÍCULO - INSERT INTO vn.item (id, `name`, typeFk, size, inkFk, originFk, intrastatFk) - VALUES ( - vItem, - vName, - vType, - vSize, - vColour, - 1, - 06031970 - ); - - SELECT id INTO vTaxClass FROM vn.taxClass WHERE `code` = 'G'; - SELECT id INTO vIntrastatFk FROM vn.intrastat - WHERE description LIKE 'Flores,follaje y frutos artificiales: otras%'; - - UPDATE vn.itemTaxCountry SET taxClassFk = vTaxClass WHERE itemFk = LAST_INSERT_ID(); - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/credit_update.sql b/db/routines/vn2008/procedures/credit_update.sql deleted file mode 100644 index e29fa5ada..000000000 --- a/db/routines/vn2008/procedures/credit_update.sql +++ /dev/null @@ -1,17 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`credit_update`() -BEGIN - -DECLARE dblDiferencia DOUBLE DEFAULT 10.0; -DECLARE dblImporteRec,auxdblImporteRec DOUBLE DEFAULT 0.0; -DECLARE dblImporteFac,auxdblImporteFac DOUBLE DEFAULT 0.0; -DECLARE intIdRecibo,auxintIdRecibo INT (11) DEFAULT 0; -DECLARE intId_Cliente,auxintId_Cliente,intId_ClienteRec,auxintId_ClienteRec INT DEFAULT 0; -DECLARE bitFin,bitFinRecord,bitFinRecord1 BIT DEFAULT 0; -DECLARE datFechaVencimiento DATE DEFAULT util.VN_CURDATE(); -DECLARE intEmpresa_id INT DEFAULT 0; - - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/entryFromOrder.sql b/db/routines/vn2008/procedures/entryFromOrder.sql deleted file mode 100644 index e340177af..000000000 --- a/db/routines/vn2008/procedures/entryFromOrder.sql +++ /dev/null @@ -1,55 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`entryFromOrder`(IN vShipmentWarehouse INTEGER, IN vLandingWarehouse INTEGER, IN vItem INTEGER, - IN vAmount INTEGER,IN vVolume INTEGER,vCost DECIMAL(10,2), IN vRetailedPrice DECIMAL(10,2), vInOutDate DATE) -BEGIN - - DECLARE vTravel INT; - DECLARE vEntry INT; - DECLARE vBucket VARCHAR(10); - - -- seleccionamos travel - SELECT id, Id_Entrada INTO vTravel, vEntry - FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id - WHERE t.landing = vInOutDate AND t.shipment = vInOutDate AND t.warehouse_id_out = vShipmentWarehouse - AND t.warehouse_id = vLandingWarehouse AND agency_id = 15 - LIMIT 1; - - -- creamos el travel si es necesario - IF NOT IFNULL(vTravel,0) THEN - INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) - VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse, 15); - SELECT LAST_INSERT_ID() INTO vTravel; - END IF; - -- creamos la Entrada si es necesario - IF NOT IFNULL(vEntry,0) THEN - INSERT INTO Entradas (Id_Proveedor, travel_id) - VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' - SELECT LAST_INSERT_ID() INTO vEntry; - END IF; - - -- creamos el cubo si es necesario - SELECT Id_Cubo INTO vBucket FROM Cubos WHERE Volumen = vVolume LIMIT 1; - - IF NOT IFNULL(vBucket,'') > '' THEN - INSERT INTO Cubos (Id_Cubo, Volumen) - VALUES (CONCAT('dm',vVolume/1000), vVolume); - SELECT LAST_INSERT_ID() INTO vBucket; - END IF; - - INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, Embalajefijo, - Comisionfija, Tarifa2, Tarifa3) - VALUES(vItem, - vAmount, - vEntry, - vBucket, - 1, - 1, - 0, - vCost, - 0, - 0, - 0, - vRetailedPrice, - vRetailedPrice); -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/entryFromTicket.sql b/db/routines/vn2008/procedures/entryFromTicket.sql deleted file mode 100644 index f580959d7..000000000 --- a/db/routines/vn2008/procedures/entryFromTicket.sql +++ /dev/null @@ -1,62 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`entryFromTicket`(IN vTicket INTEGER, IN vLandingWarehouse INTEGER) -BEGIN - - DECLARE vShipmentWarehouse INT; - DECLARE vLandingDate DATE; - DECLARE vShipmentDate DATE; - DECLARE vTravel INT; - DECLARE vEntry INT; - - SELECT warehouse_id, Fecha, Fecha INTO vShipmentWarehouse, vShipmentDate, vLandingDate - FROM Tickets - WHERE Id_Ticket = vTicket; - - -- seleccionamos travel - SELECT id, Id_Entrada INTO vTravel, vEntry - FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id - WHERE t.landing = vLandingDate - AND t.shipment = vShipmentDate - AND t.warehouse_id_out = vShipmentWarehouse - AND t.warehouse_id = vLandingWarehouse - AND agency_id = 15 - LIMIT 1; - - -- creamos el travel si es necesario - IF vTravel IS NULL THEN - SELECT vLandingDate; - INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) - VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, 15); - SELECT LAST_INSERT_ID() INTO vTravel; - END IF; - - -- creamos la Entrada si es necesario - IF vEntry IS NULL THEN - INSERT INTO Entradas (Id_Proveedor, travel_id) - VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' - SELECT LAST_INSERT_ID() INTO vEntry; - END IF; - - CALL vn.buyUltimate(vShipmentWarehouse,vShipmentDate); - - INSERT INTO Compres(Id_Article,Cantidad, Id_Entrada, Id_Cubo, Packing, `grouping`, caja, Costefijo, Portefijo, Embalajefijo, Comisionfija, Tarifa2, Tarifa3) - SELECT m.Id_Article, - m.Cantidad, - vEntry, - c.Id_Cubo, - c.Packing, - IF(c.`grouping`,c.`grouping`,1), - c.caja, - Costefijo, - c.Portefijo, - c.Embalajefijo, - c.Comisionfija, - m.Preu Tarifa2, - m.Preu Tarifa3 - FROM Movimientos m - JOIN Articles a ON m.Id_Article = a.Id_Article - LEFT JOIN tmp.buyUltimate b ON m.Id_Article = b.itemFk AND b.warehouseFk = vShipmentWarehouse - LEFT JOIN Compres c ON c.Id_Compra = b.buyFk - WHERE m.Id_Ticket = vTicket; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/eti_to_print.sql b/db/routines/vn2008/procedures/eti_to_print.sql deleted file mode 100644 index 4185d6a0a..000000000 --- a/db/routines/vn2008/procedures/eti_to_print.sql +++ /dev/null @@ -1,24 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`eti_to_print`(IN idENTRADA INT, IN idPRODUCER INT) -BEGIN - -select Vida as Impresas - ,Etiquetas as bultos - ,Packing - ,Id_Article - ,CONCAT(Article,' ',Medida,' ', Categoria) as Articat - ,p.name as marca - ,Proveedor - ,Id_Entrada - ,Id_Compra -from Compres c -join Entradas e using(Id_Entrada) -join Proveedores using(Id_Proveedor) -join travel tr on tr.id = e.travel_id -join Articles a using(Id_Article) -left join producer p using(producer_id) -where Id_Entrada = idENTRADA - and idPRODUCER in (0,a.producer_id) ; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/f10_no_vincular.sql b/db/routines/vn2008/procedures/f10_no_vincular.sql deleted file mode 100644 index 4ec93f68e..000000000 --- a/db/routines/vn2008/procedures/f10_no_vincular.sql +++ /dev/null @@ -1,60 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`f10_no_vincular`(lngEntrada INTEGER) -BEGIN - DECLARE datFecha DATE DEFAULT util.VN_CURDATE(); - --- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo - DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_; - CREATE TEMPORARY TABLE IF NOT EXISTS f10_no_vincular_ - SELECT c.Id_Entrada,c.Id_Compra,c.Id_Article, c.Novincular, c.Packing, be.pri - FROM Compres c - JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha - LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = c.Id_Entrada - WHERE - ((ek.Id_Entrada IS NOT NULL AND ek.sub IS NULL) - OR (c.Id_Entrada = 9200 AND be.ok <> FALSE) - OR c.Id_Entrada = lngEntrada) AND Id_Article <> 90; - - -- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo - DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing; - CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Packing - SELECT * FROM ( - SELECT * FROM f10_no_vincular_ - ORDER BY pri DESC - LIMIT 10000000000000000000) t - GROUP BY Id_Article,Packing - HAVING count(Id_Compra) > 1 AND BIT_OR(Id_Entrada = 9200); - - UPDATE Compres c - JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha - JOIN f10_mismo_Packing f ON f.Id_Article = c.Id_Article AND c.Packing = f.Packing - LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = f.Id_Entrada - SET c.Novincular = IF(c.Id_Compra = f.Id_Compra,0,1) - WHERE - ((ek.Id_Entrada IS NOT NULL AND ek.sub IS NULL) - OR (c.Id_Entrada = 9200 AND be.ok <> FALSE) - OR c.Id_Entrada = lngEntrada); - --- Modifica el Id_Articulo si hay dos entradas con packing y el mismo Id_Articulo - DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo; - CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Articulo - SELECT Id_Article FROM ( - SELECT * FROM ( - SELECT * FROM f10_no_vincular_ - ORDER BY Id_Entrada = 9200 DESC - LIMIT 10000000000000000000) t - GROUP BY Id_Article,Packing ) t - GROUP BY Id_Article HAVING COUNT(*) > 1 AND BIT_OR(Id_Entrada = 9200); - SELECT 4; - UPDATE Compres c - JOIN buy_edi be ON c.buy_edi_id = be.id AND be.fec = datFecha - JOIN f10_mismo_Articulo f ON f.Id_Article = c.Id_Article - LEFT JOIN Entradas_kop ek ON ek.Id_Entrada = c.Id_Entrada - SET c.Id_Article = 90 - WHERE c.Id_Entrada = 9200 AND be.ok <> FALSE; - - DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_; - DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing; - DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/historico_joined.sql b/db/routines/vn2008/procedures/historico_joined.sql deleted file mode 100644 index 730562de1..000000000 --- a/db/routines/vn2008/procedures/historico_joined.sql +++ /dev/null @@ -1,88 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`historico_joined`(IN idART INT, IN wh_joined INT, IN v_virtual INT) -BEGIN - DECLARE datFEC DATETIME; - - SELECT Fechainventario INTO datFEC FROM tblContadores; - SET @a = 0; - SELECT DATE(Fecha) Fecha, - Entrada, - Salida, - OK, - Alias, - Referencia, - id, - @a := @a + IFNULL(Entrada,0) - IFNULL(Salida,0) acumulado, - F5, - v_virtual, - CodigoTrabajador - FROM - ( SELECT TR.landing Fecha, - C.Cantidad Entrada, - NULL Salida, - (TR.received != FALSE) OK, - P.Proveedor Alias, - E.Referencia Referencia, - E.Id_Entrada id, - TR.delivered F5, - tra.CodigoTrabajador - FROM Compres C - JOIN Entradas E USING (Id_Entrada) - JOIN travel TR ON TR.id = E.travel_id - JOIN Proveedores P USING (Id_Proveedor) - LEFT JOIN Articles a ON a.Id_Article = C.Id_Article - LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id - LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador - LEFT JOIN warehouse_joined wj ON wj.warehouse_id = TR.warehouse_id - WHERE TR.landing >= datFEC - AND wh_joined IN (wj.warehouse_alias_id , 0) - AND C.Id_Article = idART - AND E.Inventario = 0 - AND E.Redada = 0 - UNION ALL - SELECT TR.shipment Fecha, - NULL Entrada, - C.Cantidad Salida, - TR.delivered OK, - P.Proveedor Alias, - E.Referencia Referencia, - E.Id_Entrada id, - TR.delivered F5, - tra.CodigoTrabajador - FROM Compres C - JOIN Entradas E USING (Id_Entrada) - JOIN travel TR ON TR.id = E.travel_id - JOIN Proveedores P USING (Id_Proveedor) - LEFT JOIN Articles a ON a.Id_Article = C.Id_Article - LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id - LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador - LEFT JOIN warehouse_joined wj ON wj.warehouse_id = TR.warehouse_id_out - WHERE TR.shipment >= datFEC - AND wh_joined IN (wj.warehouse_alias_id,0) - AND Id_Proveedor <> 4 - AND C.Id_Article = idART - AND E.Inventario = 0 - AND E.Redada = 0 - UNION ALL - SELECT T.Fecha Fecha, - NULL Entrada, - M.Cantidad Salida, - (M.OK <> 0 OR T.Etiquetasemitidas <> 0 OR T.Factura IS NOT NULL) OK, - T.Alias Alias, - T.Localizacion Referencia, - T.Id_Ticket id, - T.PedidoImpreso EtiquetasEmitidas, - tr.CodigoTrabajador - FROM Movimientos M - JOIN Tickets T USING (Id_Ticket) - JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente - LEFT JOIN Trabajadores tr ON tr.Id_Trabajador = C.Id_Trabajador - LEFT JOIN warehouse_joined wj ON wj.warehouse_id = T.warehouse_id - WHERE T.Fecha >= datFEC - AND M.Id_Article = idART - AND wh_joined IN (wj.warehouse_alias_id , 0) - ) AS Historico - ORDER BY Fecha, Entrada DESC, OK DESC; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/inventario_valorado.sql b/db/routines/vn2008/procedures/inventario_valorado.sql deleted file mode 100644 index e8e5eeed0..000000000 --- a/db/routines/vn2008/procedures/inventario_valorado.sql +++ /dev/null @@ -1,185 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`inventario_valorado`(IN vDated DATE, IN vIsDetailed BOOLEAN) -BEGIN - -/** - * DEPRECATED usar item_ValuateInventory - */ - DECLARE vInventoried DATE; - DECLARE vHasNotInventory BOOLEAN DEFAULT 0; - DECLARE vInventoried2 DATE; - DECLARE vDateDayEnd DATETIME; - - SET vDateDayEnd = util.dayEnd(vDated); - SELECT landing INTO vInventoried - FROM travel tr - JOIN Entradas E ON E.travel_id = tr.id - WHERE landing <= vDateDayEnd - AND E.Id_Proveedor = 4 - ORDER BY landing DESC - LIMIT 1; - - SET vHasNotInventory = IF (vInventoried is null, TRUE, FALSE); - - IF vHasNotInventory THEN - - SELECT landing INTO vInventoried2 - FROM travel tr - JOIN Entradas E ON E.travel_id = tr.id - WHERE landing >= vDated - AND E.Id_Proveedor = 4 - ORDER BY landing ASC - LIMIT 1; - - SET vInventoried = TIMESTAMPADD(DAY,1,vDated); - SET vDateDayEnd = vInventoried2; - - END IF; - - DROP TEMPORARY TABLE IF EXISTS inv; - - CREATE TEMPORARY TABLE inv - (warehouseFk SMALLINT, - Id_Article BIGINT, - cantidad INT, - coste DOUBLE DEFAULT 0, - total DOUBLE DEFAULT 0, - Almacen VARCHAR(20), - PRIMARY KEY (Almacen, Id_Article) USING HASH) - ENGINE = MEMORY; - - IF vHasNotInventory = TRUE THEN - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouse_id, C.Id_Article, SUM(C.Cantidad), w.`name` - FROM Compres C - JOIN Articles A USING(Id_Article) - JOIN Entradas E USING (Id_Entrada) - JOIN travel tr ON tr.id = E.travel_id - JOIN Tipos t USING(tipo_id) - JOIN warehouse w ON w.id = warehouse_id - WHERE landing = vDateDayEnd - AND E.Id_Proveedor = 4 - AND w.valuatedInventory - AND t.inventory - GROUP BY tr.warehouse_id, C.Id_Article; - - END IF; - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouse_id, C.Id_Article, C.Cantidad * IF(vHasNotInventory,-1,1), w.`name` - FROM Compres C - JOIN Articles A USING(Id_Article) - JOIN Entradas E USING (Id_Entrada) - JOIN travel tr ON tr.id = E.travel_id - JOIN Tipos t USING(tipo_id) - JOIN warehouse w ON w.id = tr.warehouse_id - WHERE landing BETWEEN vInventoried AND vDateDayEnd - AND IF(landing = util.VN_CURDATE(), tr.received, trUE) - AND NOT redada - AND w.valuatedInventory - AND t.inventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(vHasNotInventory,-1,1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouse_id_out, C.Id_Article, C.Cantidad * IF(vHasNotInventory,1,-1), w.`name` - FROM Compres C - JOIN Articles A USING(Id_Article) - JOIN Entradas E USING (Id_Entrada) - JOIN travel tr ON tr.id = E.travel_id - JOIN Tipos t USING(tipo_id) - JOIN warehouse w ON w.id = warehouse_id_out - WHERE shipment BETWEEN vInventoried AND vDateDayEnd - AND NOT redada - AND w.valuatedInventory - AND t.inventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(vHasNotInventory,1,-1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, M.Id_Article, M.Cantidad * IF(vHasNotInventory,1,-1), w.`name` - FROM Movimientos M - JOIN Tickets T USING (Id_Ticket) - JOIN Clientes C USING(Id_Cliente) - JOIN Articles A USING(Id_Article) - JOIN Tipos t USING(tipo_id) - JOIN warehouse w ON w.id = warehouse_id - WHERE T.Fecha BETWEEN vInventoried AND vDateDayEnd - AND w.valuatedInventory - AND t.inventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(vHasNotInventory,1,-1); - - IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, M.Id_Article, M.Cantidad * IF(vHasNotInventory,0,1), w.`name` - FROM Movimientos M - JOIN Tickets T USING (Id_Ticket) - JOIN Clientes C USING(Id_Cliente) - JOIN Articles A USING(Id_Article) - JOIN Tipos t USING(tipo_id) - JOIN warehouse w ON w.id = warehouse_id - WHERE T.Fecha BETWEEN vDated AND vDateDayEnd - AND (M.OK <> 0 or T.Etiquetasemitidas <> 0 ) - AND w.valuatedInventory - AND t.inventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(vHasNotInventory,0,1); - - END IF; - - -- Mercancia en transito - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouse_id, C.Id_Article, C.Cantidad, CONCAT(wOut.`name`,' - ', wIn.`name`) - FROM Compres C - JOIN Articles A USING(Id_Article) - JOIN Entradas E USING (Id_Entrada) - JOIN travel tr ON tr.id = E.travel_id - JOIN Tipos t USING(tipo_id) - JOIN warehouse wIn ON wIn.id = tr.warehouse_id - JOIN warehouse wOut ON wOut.id = tr.warehouse_id_out - WHERE vDated >= shipment AND vDated < landing - AND NOT redada - AND wIn.valuatedInventory - AND t.inventory - AND E.Confirmada - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad); - - CALL vn.buyUltimate(NULL,vDateDayEnd); - - UPDATE inv i - JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.Id_Article = bu.itemFk - JOIN Compres C ON C.Id_Compra = bu.buyFk - SET total = i.cantidad * (ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0)), - coste = ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0) - WHERE i.cantidad <> 0; - - DELETE FROM inv WHERE Cantidad IS NULL or Cantidad = 0; - - IF vIsDetailed THEN - - SELECT inv.warehouseFk, a.Id_Article, a.Article, a.Medida, inv.Cantidad, tp.Id_Tipo, - tp.reino_id, inv.coste, cast(inv.total as decimal(10,2)) total, Almacen - FROM inv - JOIN warehouse w on w.id = warehouseFk - JOIN Articles a ON a.Id_Article = inv.Id_Article - JOIN Tipos tp ON tp.tipo_id = a.tipo_id - WHERE w.valuatedInventory - and inv.total > 0 - order by inv.total desc; - - ELSE - - SELECT i.Almacen, r.reino as Reino, cast(i.total as decimal(10,2)) as Euros, tr.Codigotrabajador as Comprador,A.Id_Article - FROM inv i - JOIN warehouse w on w.id = warehouseFk - JOIN Articles A USING(Id_Article) - JOIN Tipos t USING(tipo_id) - LEFT JOIN Trabajadores tr ON tr.Id_trabajador = t.Id_trabajador - JOIN reinos r ON r.id = t.reino_id - WHERE w.valuatedInventory - AND i.total > 0; - - END IF; - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE inv; -end$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/item_buy.sql b/db/routines/vn2008/procedures/item_buy.sql deleted file mode 100644 index 244334c80..000000000 --- a/db/routines/vn2008/procedures/item_buy.sql +++ /dev/null @@ -1,32 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`item_buy`(IN v_wh TINYINT, IN v_date DATETIME) -BEGIN - DECLARE date_inv DATE; - ALTER TABLE item - ADD buy_id INT UNSIGNED; - - IF v_date < (SELECT vn.getInventoryDate()) THEN - SELECT MIN(landing) INTO date_inv FROM travel t INNER JOIN Entradas e ON e.travel_id = t.id - WHERE warehouse_id_out = 13 AND landing <= v_date; - ELSE - SET date_inv = vn.getInventoryDate(); - END IF; - UPDATE item i INNER JOIN ( - SELECT * FROM ( - SELECT c.Id_Article item_id, c.Id_Compra id - FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) - INNER JOIN travel t ON t.id = e.travel_id - WHERE t.landing BETWEEN date_inv AND v_date - AND c.Novincular = FALSE - AND c.Tarifa2 >= 0 - ORDER BY v_wh = t.warehouse_id DESC, t.landing DESC - LIMIT 10000000000000000000 - ) t - GROUP BY item_id - ) t - ON i.id = t.item_id - SET i.buy_id = t.id; - - CREATE INDEX buy USING HASH ON item (buy_id); -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/item_express.sql b/db/routines/vn2008/procedures/item_express.sql deleted file mode 100644 index 46275014d..000000000 --- a/db/routines/vn2008/procedures/item_express.sql +++ /dev/null @@ -1,41 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`item_express`(IN intWH INT, IN datFEC DATE) -BEGIN - -DECLARE datINV DATE; - - - -SELECT FechaInventario INTO datINV FROM tblContadores LIMIT 1; - - -SELECT sub1.Id_Article, Visible, Tarifa2 -FROM -(SELECT Id_Article, SUM(Cantidad) as Visible -FROM Compres C -JOIN Entradas E USING(Id_Entrada) -JOIN travel T ON T.id = E.travel_id -WHERE shipment >= datINV -AND landing <= datFEC -AND Redada = 0 -AND warehouse_id = intWH -GROUP BY Id_Article) sub1 -JOIN -( -SELECT * FROM -( -SELECT Id_Article, Tarifa2 -FROM Compres C -JOIN Entradas E USING(Id_Entrada) -JOIN travel T ON T.id = E.travel_id -WHERE shipment >= datINV -AND landing <= datFEC -AND Redada = 0 -AND Novincular = 0 -AND warehouse_id = intWH -ORDER BY landing DESC LIMIT 10000000000000000000) sub -GROUP BY Id_Article) sub2 USING(Id_Article); - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/item_new.sql b/db/routines/vn2008/procedures/item_new.sql deleted file mode 100644 index 701e4986a..000000000 --- a/db/routines/vn2008/procedures/item_new.sql +++ /dev/null @@ -1,11 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`item_new`() -BEGIN - CREATE TEMPORARY TABLE item - ( - item_id INT UNSIGNED NOT NULL, - UNIQUE KEY USING HASH (item_id) - ) - ENGINE = MEMORY; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/malpagantes.sql b/db/routines/vn2008/procedures/malpagantes.sql deleted file mode 100644 index 196de92d2..000000000 --- a/db/routines/vn2008/procedures/malpagantes.sql +++ /dev/null @@ -1,44 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`malpagantes`() -BEGIN - -set @cliente := 0; -set @saldo := 0; - -Select Id_Cliente, Cliente from -Clientes -join -(select distinct Id_Cliente -from Facturas -where Fecha > '2015-01-01') cli using(Id_Cliente) -left join -( -select distinct Id_Cliente -from -( -select Fecha - , @saldo := IF(@cliente = Id_Cliente, @saldo + Importe, Importe) Saldo - , @cliente := Id_Cliente as Id_Cliente -from -( -select Id_Cliente, Fecha, Importe from - -( -select Id_Cliente, -1 * Importe Importe, Fecha -from Facturas -union all -select Id_Cliente, Entregado, Fechacobro -from Recibos -) sub -order by Id_Cliente, Fecha -) sub2 -) sub3 -where Saldo > -1 -and Fecha > '2015-01-01' - -) sub4 using(Id_Cliente) -where sub4.Id_Cliente is null; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/mensaje.sql b/db/routines/vn2008/procedures/mensaje.sql deleted file mode 100644 index 89f9bf4f0..000000000 --- a/db/routines/vn2008/procedures/mensaje.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`mensaje`(IN idREM INT, IN idDES INT, IN strMSG LONGTEXT) -BEGIN - -/*DECLARE lngLASTID BIGINT;*/ - --- Caso sencillo - -INSERT INTO Mensajes(Mensaje, Fecha, Remitente, Destinatario) -VALUES(strMSG, util.VN_NOW(), idREM, idDES); - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/msg.sql b/db/routines/vn2008/procedures/msg.sql deleted file mode 100644 index e402efe39..000000000 --- a/db/routines/vn2008/procedures/msg.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`msg`(IN memTXT VARCHAR(255), IN idREM INTEGER, idDES INTEGER) -BEGIN - DECLARE last_ID INTEGER; - DECLARE codDES CHAR(3); - - SELECT CodigoTrabajador INTO codDES FROM Trabajadores WHERE Id_Trabajador = idDES; - - INSERT INTO Mensajes(Mensaje,Fecha,Remitente,Destinatario) - VALUES(memTXT, util.VN_NOW(),idREM, idDES); - - SELECT LAST_INSERT_ID() INTO last_ID; - - - INSERT INTO Incidencias(Incidencia,Id_Trabajador,Destino,Fecha,Fecha_Mod) - VALUES (CONCAT('@@ ',last_ID),idREM,codDES,util.VN_NOW(),util.VN_NOW()); - - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/newItem.sql b/db/routines/vn2008/procedures/newItem.sql deleted file mode 100644 index 8982b6adc..000000000 --- a/db/routines/vn2008/procedures/newItem.sql +++ /dev/null @@ -1,34 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`newItem`(IN vTicket INTEGER, IN vVolume INTEGER, IN vQuantity INTEGER) -BEGIN - - DECLARE vLandingWarehouse INT; - DECLARE vLandingDate DATE; - DECLARE vShipmentDate DATE; - DECLARE vTravel INT; - DECLARE vEntry INT; - - SELECT warehouse_id, Fecha, landing INTO vLandingWarehouse, vShipmentDate, vLandingDate FROM Tickets WHERE Id_Ticket = vTicket; - - -- seleccionamos travel - SELECT id, Id_Entrada INTO vTravel, vEntry - FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id - WHERE t.landing = vLandingDate AND t.shipment = vShipmentDate AND t.warehouse_id_out = vLandingWarehouse AND t.warehouse_id = vWarehouse - AND t.delivered = FALSE ; -- agency ?? - - -- creamos el travel si es necesario - IF NOT vTravel THEN - INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id) - VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, a); - SELECT LAST_INSERT_ID() INTO vTravel; - END IF; - - -- creamos la Entrada si es necesario - IF NOT vEntry THEN - INSERT INTO Entradas (Id_Proveedor, travel_id) - VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN' - SELECT LAST_INSERT_ID() INTO vEntry; - END IF; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/niching.sql b/db/routines/vn2008/procedures/niching.sql deleted file mode 100644 index eff501ed5..000000000 --- a/db/routines/vn2008/procedures/niching.sql +++ /dev/null @@ -1,49 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`niching`(IN i_ini INT, IN i_end INT -, IN i_bal INT, IN i_col INT ) -BEGIN - -DECLARE i INT(5); -DECLARE j INT(5); - -DROP TEMPORARY TABLE IF EXISTS labels; - -CREATE TEMPORARY TABLE `labels` - (`label` VARCHAR(15) NULL) -ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - -WHILE i_ini <= i_end DO - - SET i = i_bal; - - WHILE i > 0 DO - - - - SET j = i_col; - IF j = 0 THEN - INSERT INTO labels(label) - VALUES (CONCAT(i_ini,IF(i=0,' ',char(64 + i)))); - ELSE - - WHILE j > 0 DO - - INSERT INTO labels(label) - VALUES (CONCAT(i_ini,char(64 + i), j)); - - SET j = j - 1; - - END WHILE; - END IF; - SET i = i - 1; - - END WHILE; - -SET i_ini = i_ini + 1; - -END WHILE; - -SELECT CONCAT('*',label,'*') as label, label as id FROM labels; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/notify_passport.sql b/db/routines/vn2008/procedures/notify_passport.sql deleted file mode 100644 index 5b611f063..000000000 --- a/db/routines/vn2008/procedures/notify_passport.sql +++ /dev/null @@ -1,12 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`notify_passport`( - IN vItemFk INT, - IN vStickers SMALLINT, - IN vPacking SMALLINT, - IN vBuyFk INT -) -BEGIN - -- DPRECATED use vn.buy_notifyPassport - CALL vn.buy_notifyPassport(vBuyFk, vItemFk, vStickers, vPacking); -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/percentil.sql b/db/routines/vn2008/procedures/percentil.sql deleted file mode 100644 index 650be0138..000000000 --- a/db/routines/vn2008/procedures/percentil.sql +++ /dev/null @@ -1,30 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`percentil`() -BEGIN - -DECLARE max_range INT; - -DROP TEMPORARY TABLE IF EXISTS previa; - -CREATE TEMPORARY TABLE previa -SELECT @posicion:= @posicion +1 as Posicion, Id_Cliente, Total FROM ( -SELECT Id_Cliente, Total FROM ( -SELECT Id_Cliente, SUM(Importe) as Total -FROM Facturas -INNER JOIN Clientes USING(Id_Cliente) -INNER JOIN (SELECT @posicion := 0) sub_pos -WHERE invoice -AND YEAR(Fecha) = YEAR(util.VN_CURDATE()) -GROUP BY Id_Cliente) sub -ORDER BY Total -) sub2; - -SELECT COUNT(*) INTO max_range FROM previa; - -UPDATE Clientes SET percentil = 0; - -UPDATE Clientes INNER JOIN previa USING(Id_Cliente) -SET Clientes.percentil = ROUND(Posicion *100 / max_range,0); - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/prepare_client_list.sql b/db/routines/vn2008/procedures/prepare_client_list.sql deleted file mode 100644 index 740bbff4a..000000000 --- a/db/routines/vn2008/procedures/prepare_client_list.sql +++ /dev/null @@ -1,11 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`prepare_client_list`() -BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; - CREATE TEMPORARY TABLE tmp.client_list - (PRIMARY KEY (Id_Cliente)) - ENGINE = MEMORY - SELECT DISTINCT Id_Cliente - FROM tmp.ticket_list; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/proc_end.sql b/db/routines/vn2008/procedures/proc_end.sql deleted file mode 100644 index 982ef708f..000000000 --- a/db/routines/vn2008/procedures/proc_end.sql +++ /dev/null @@ -1,11 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`proc_end`() -BEGIN - -UPDATE stat SET `end` = util.VN_NOW() -WHERE id = (SELECT id FROM lastid); - -DROP TEMPORARY TABLE IF EXISTS lastid; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/proc_start.sql b/db/routines/vn2008/procedures/proc_start.sql deleted file mode 100644 index 57d919c12..000000000 --- a/db/routines/vn2008/procedures/proc_start.sql +++ /dev/null @@ -1,13 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`proc_start`(IN v_proc_id INT) -BEGIN - -INSERT INTO stat(proc_id) VALUES(v_proc_id); - - -DROP TEMPORARY TABLE IF EXISTS lastid; -CREATE TEMPORARY TABLE lastid -SELECT last_insert_id() id; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/prueba_miguel.sql b/db/routines/vn2008/procedures/prueba_miguel.sql deleted file mode 100644 index 829f4a8cf..000000000 --- a/db/routines/vn2008/procedures/prueba_miguel.sql +++ /dev/null @@ -1,6 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`prueba_miguel`() -BEGIN -select 1; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/quadre_clientes.sql b/db/routines/vn2008/procedures/quadre_clientes.sql deleted file mode 100644 index 3db4c073a..000000000 --- a/db/routines/vn2008/procedures/quadre_clientes.sql +++ /dev/null @@ -1,67 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`quadre_clientes`(IN datFEC DATETIME) -BEGIN - - - DECLARE datSTART DATE; - SET datFEC = TIMESTAMP(datFEC,'23:59:59'); - SELECT util.firstDayOfYear(datFEC) INTO datSTART; - - SELECT P2.Alias, C.Id_Cliente, C.Cuenta, Gestion, Contaplus, Gestion - Contaplus as Diferencia, empresa_id, Cliente - - FROM Clientes C - - JOIN pay_met pm ON pm.id = C.pay_met_id - - JOIN - - ( - - SELECT empresa_id, Id_Cliente, round(sum(Gestion),2) as Gestion, round(sum(Contaplus),2) as Contaplus - - FROM - - ( - SELECT empresa_id, Id_Cliente, Gestion, 0 as Contaplus - - FROM - - ( - SELECT empresa_id, Id_Cliente, -1 * Importe as Gestion - FROM Facturas - WHERE Fecha BETWEEN datSTART AND datFEC - UNION ALL - SELECT empresa_id, Id_Cliente, Entregado - FROM Recibos - WHERE Fechacobro BETWEEN datSTART AND datFEC - ) G - - WHERE empresa_id <> 965 - - UNION ALL - - SELECT empresa_id, Id_Cliente, 0, round(nz(Eurohaber) - nz(Eurodebe),2) as Contaplus - - FROM bi.XDiario_ALL XD - - JOIN Clientes C ON C.Cuenta = XD.SUBCTA - - WHERE Fecha BETWEEN datSTART AND datFEC - - ) sub1 - - GROUP BY empresa_id, Id_Cliente - - ) sub2 USING(Id_Cliente) - - JOIN Proveedores P2 ON P2.Id_Proveedor = sub2.empresa_id - - WHERE pm.deudaviva -- Cliente de perdidas no vale la pena revisarlo - - HAVING ABS(Diferencia) > 0.05 - - ORDER BY Cliente; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/quadre_clientes_detalle.sql b/db/routines/vn2008/procedures/quadre_clientes_detalle.sql deleted file mode 100644 index 4ed261d4b..000000000 --- a/db/routines/vn2008/procedures/quadre_clientes_detalle.sql +++ /dev/null @@ -1,70 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`quadre_clientes_detalle`(IN idC INT, IN idE INT, IN datFEC DATETIME) -BEGIN - -DECLARE datSTART DATE; - -SET datSTART = util.firstDayOfYear(datFEC); -SET datFEC = TIMESTAMP(datFEC,'23:59:59'); - --- Creamos una tabla para almacenar las facturas del cliente, junto con el numero de veces que se repite. -DROP TEMPORARY TABLE IF EXISTS qFACTURAS; - -CREATE TEMPORARY TABLE qFACTURAS -(Fecha DATETIME, - TPVcount INT, - Factura DECIMAL(10,2) SIGNED, - Recibo DECIMAL(10,2) SIGNED, - CPcount INT, - Debe DECIMAL(10,2) SIGNED, - Haber DECIMAL(10,2) SIGNED, - Control INT DEFAULT 0, - PRIMARY KEY(Fecha, TPVcount, Factura, Recibo, CPcount, Debe, Haber)) - ENGINE = InnoDB -; - --- Insertamos las facturas y los recibos de gestion. -INSERT INTO qFACTURAS - - SELECT Fecha, COUNT(*) as TPVcount, round(Importe,2) as Factura, 0 as Recibo, COUNT(*)as CPcount,round(Importe,2) as Debe, 0 as Haber, 1 as Control - FROM Facturas - WHERE Id_Cliente = idC AND empresa_id = idE AND Fecha BETWEEN datSTART AND datFEC - GROUP BY Fecha, round(Importe,2) - UNION ALL - SELECT Fechacobro as Fecha, COUNT(*) as TPVcount, 0 as Factura, round(Entregado,2) as Recibo,COUNT(*) as CPCount, 0 as Debe, round(Entregado,2) as Haber, 3 as Control - FROM Recibos - WHERE Id_Cliente = idC AND empresa_id = idE AND Fechacobro BETWEEN datSTART AND datFEC - GROUP BY Fechacobro, round(Entregado,2); - --- Insertamos los asientos de contabilidad, marcando con control = -1 las repetidas. -INSERT INTO qFACTURAS - SELECT * - FROM ( - SELECT Fecha, COUNT(*) as TPVcount, round(Eurodebe,2) as Factura, round(Eurohaber,2) as Recibo, COUNT(*) as CPcount, round(Eurodebe,2) as Debe, round(Eurohaber,2) as Haber, 2 as Control - FROM bi.XDiario_ALL XD - JOIN Clientes C ON C.Cuenta = XD.SUBCTA - WHERE Id_Cliente = idC AND empresa_id = idE AND Fecha BETWEEN datSTART AND datFEC - AND (Eurodebe <> 0 OR Eurohaber <>0) - GROUP BY Fecha, round(Eurodebe,2), round(Eurohaber,2) - ) sub - - ON DUPLICATE KEY UPDATE Control = -1; - - - --- Eliminamos las repetidas --- DELETE FROM qFACTURAS WHERE Control = -1; - --- Arreglamos las buenas -UPDATE qFACTURAS SET TPVcount = 0, Factura = 0, Recibo = 0 WHERE Control = 2; -UPDATE qFACTURAS SET CPcount = 0, Debe = 0, Haber = 0 WHERE Control IN (1,3); - --- Mostramos el resultado -SELECT *, @saldo := @saldo + TPVcount * (Factura + Recibo) - CPCount * ( Debe + Haber ) as Saldo -FROM qFACTURAS -JOIN (SELECT @saldo := 0) truqui ; -DROP TEMPORARY TABLE IF EXISTS qFACTURAS; - - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/recobro_credito.sql b/db/routines/vn2008/procedures/recobro_credito.sql index 8c4ca5f94..ca5304b6c 100644 --- a/db/routines/vn2008/procedures/recobro_credito.sql +++ b/db/routines/vn2008/procedures/recobro_credito.sql @@ -8,12 +8,12 @@ BEGIN END; START TRANSACTION; - INSERT INTO vn.clientCredit(clientFk, amount) + INSERT INTO vn.clientCredit(clientFk, amount) SELECT c.id, 0 FROM vn.`client` c JOIN vn.payMethod pm ON pm.id = c.payMethodFk WHERE c.credit <> 0 AND pm.`code` = 'card'; - + UPDATE vn.`client` c JOIN vn.payMethod pm ON pm.id = c.payMethodFk SET credit = 0 @@ -49,7 +49,7 @@ BEGIN SELECT Id_Cliente, newCredit, NULL FROM clientes_credit; - DROP TEMPORARY TABLE clientes_credit; + DROP TEMPORARY TABLE clientes_credit; COMMIT; END$$ -DELIMITER ; +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn2008/procedures/scan_rutas_view.sql b/db/routines/vn2008/procedures/scan_rutas_view.sql deleted file mode 100644 index e61d94d71..000000000 --- a/db/routines/vn2008/procedures/scan_rutas_view.sql +++ /dev/null @@ -1,31 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`scan_rutas_view`() -BEGIN - - -/* muestra las rutas agrupadas de los ultimos tres dias, así como una lista de los tickets sin enrutar, agrpados por agencia y fecha*/ - -select Fecha, Id_Ruta, Matricula, sub.m3, CodigoTrabajador, Agencia, Bultos, w.name as Almacen -from -( -select r.Fecha, Id_Ruta, r.Id_Trabajador, r.Id_Agencia, Id_Vehiculo, sum(m3) m3, sum(Bultos) Bultos, warehouse_id -from Rutas r -join Tickets t using(Id_Ruta) -where r.Fecha >= timestampadd(day,-3,util.VN_CURDATE()) -group by Id_Ruta, warehouse_id - -union all - -select ifnull(landing,Fecha), dayofmonth(Fecha) * 100000 + Id_Agencia ruta , count(*) as m3, Id_Agencia, null, null, sum(Bultos), warehouse_id -from Tickets -where Id_Ruta is null -and Fecha between timestampadd(day,-3,util.VN_CURDATE()) and util.dayEnd(util.VN_CURDATE()) -group by ruta, warehouse_id -) sub -left join Vehiculos using(Id_Vehiculo) -left join Agencias using(Id_Agencia) -left join Trabajadores using(Id_Trabajador) -left join warehouse w on w.id = sub.warehouse_id; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql b/db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql deleted file mode 100644 index 5c824ac9b..000000000 --- a/db/routines/vn2008/procedures/sort_merge_passes_ernesto.sql +++ /dev/null @@ -1,85 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`sort_merge_passes_ernesto`() -BEGIN -declare i INT; -declare SMP INT; -DECLARE SMP_RATE INT; -DECLARE SMP_OLD INT; -DECLARE SMP_NEW INT; - -SET i = 0; -loop1: REPEAT - SET i = i + 1; - SET @SleepTime = 300; - - SELECT variable_value INTO @SMP_OLD FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes'; - - SELECT SLEEP(@SleepTime) INTO @NiCasoAEsteSLEEP_EsNormal; - - SELECT variable_value INTO @SMP_NEW FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes'; - SET @SMP = @SMP_NEW - @SMP_OLD; - SET @SMP_RATE = @SMP * 3600 / @SleepTime; - - Select VARIABLE_value into @connections from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'connections'; - Select VARIABLE_value into @Threads_created from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_created'; - Select VARIABLE_value into @Threads_cached from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_cached'; - Select VARIABLE_value into @Innodb_os_log_written from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Innodb_os_log_written'; - - Select VARIABLE_value into @Created_tmp_disk_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Created_tmp_disk_tables'; - Select VARIABLE_value into @created_tmp_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'created_tmp_tables'; - Select VARIABLE_value into @Created_tmp_files from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Created_tmp_files'; - Select VARIABLE_value into @opened_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'opened_tables'; - Select VARIABLE_value into @open_tables from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'open_tables'; - Select VARIABLE_value into @TABLE_OPEN_CACHE_OVERFLOWS from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_OVERFLOWS'; - Select VARIABLE_value into @TABLE_OPEN_CACHE_MISSES from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_MISSES'; - Select VARIABLE_value into @TABLE_OPEN_CACHE_HITS from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'TABLE_OPEN_CACHE_HITS'; - Select VARIABLE_value into @Uptime_since_flush_status from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Uptime_since_flush_status'; - Select VARIABLE_value into @Uptime from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Uptime'; - Select VARIABLE_value into @Qcache_hits from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_hits'; - Select VARIABLE_value into @Qcache_inserts from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_inserts'; - Select VARIABLE_value into @Qcache_not_cached from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Qcache_not_cached'; - Select VARIABLE_value into @Innodb_num_open_files from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Innodb_num_open_files'; - Select VARIABLE_value into @Open_table_definitions from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Open_table_definitions'; - select count into @trx_rseg_history_len from information_schema.innodb_metrics where name = 'trx_rseg_history_len'; - - Select @@global.table_definition_cache into @table_definition_cache; - Select @@global.table_open_cache into @table_open_cache; - Select @@global.table_open_cache_instances into @table_open_cache_instances; - Select @@global.thread_cache_size into @Thread_cache_size; - Select @@global.sort_buffer_size into @sort_buffer_size; - select @@global.join_buffer_size into @join_buffer_size; - select @@global.read_rnd_buffer_size into @read_rnd_buffer_size; - select @@global.tmp_table_size into @tmp_table_size; - select @@global.max_heap_table_size into @max_heap_table_size; - Select @@global.open_files_limit into @open_files_limit; - Select @@global.innodb_open_files into @innodb_open_files; - Select @@global.query_cache_size into @query_cache_size; - Select @@global.query_cache_type into @query_cache_type; - select @@global.log_output into @log_output; - - SELECT (Open_tables * Uptime / Opened_Tables) AS OpenTablesxUptimeDivOpened INTO @OpenTablesxUptimeDivOpened FROM - (SELECT variable_value Uptime FROM information_schema.global_status - WHERE variable_name = 'Uptime_since_flush_status') up, - (SELECT variable_value Open_tables FROM information_schema.global_status - WHERE variable_name = 'Open_tables') opn, - (SELECT IF(variable_value=0,1,variable_value) Opened_tables - FROM information_schema.global_status - WHERE variable_name = 'Opened_tables') opnd; - - INSERT INTO sort_merge_results_ernesto (hora, uptime, uptime_since_flush, smp_old, smp_new, smp, smp_hour,connections, Threads_created, Threads_cached, Thread_cache_size, sort_buffer_size, opened_tables, - Created_tmp_disk_tables, created_tmp_tables, Innodb_os_log_written, table_definition_cache, table_open_cache, table_open_cache_instances, open_tables, TABLE_OPEN_CACHE_OVERFLOWS, TABLE_OPEN_CACHE_MISSES, - TABLE_OPEN_CACHE_HITS, tmp_table_size, max_heap_table_size, OpenTablesxUptimeDivOpened, join_buffer_size, open_files_limit, innodb_open_files, Created_tmp_files, query_cache_size, query_cache_type, Qcache_hits, - Qcache_inserts, Qcache_not_cached, Innodb_num_open_files, Open_table_definitions, read_rnd_buffer_size, log_output, trx_rseg_history_len) - VALUES (util.VN_NOW(), @uptime, @uptime_since_flush, @SMP_OLD, @SMP_NEW, @SMP, @SMP_RATE, @connections, @Threads_created, @Threads_cached, @Thread_cache_size, @sort_buffer_size, @opened_tables, - @Created_tmp_disk_tables, @created_tmp_tables, @Innodb_os_log_written, @table_definition_cache, @table_open_cache, @table_open_cache_instances, @open_tables, @TABLE_OPEN_CACHE_OVERFLOWS, @TABLE_OPEN_CACHE_MISSES, - @TABLE_OPEN_CACHE_HITS, @tmp_table_size, @max_heap_table_size, @OpenTablesxUptimeDivOpened, @join_buffer_size, @open_files_limit, @innodb_open_files, @Created_tmp_files, @query_cache_size, @query_cache_type, @Qcache_hits, - @Qcache_inserts, @Qcache_not_cached, @Innodb_num_open_files, @Open_table_definitions, @read_rnd_buffer_size, @log_output, @trx_rseg_history_len); - - if (i mod 3 = 0) then - SELECT * FROM sort_merge_results_ernesto order by hora desc limit 20; - End if; - - UNTIL i >= 12 * 24 -END REPEAT; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/splitAnthuriums2016.sql b/db/routines/vn2008/procedures/splitAnthuriums2016.sql deleted file mode 100644 index fa7b7caf9..000000000 --- a/db/routines/vn2008/procedures/splitAnthuriums2016.sql +++ /dev/null @@ -1,86 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`splitAnthuriums2016`() -BEGIN - -DECLARE vStartingDate DATETIME DEFAULT '2016-10-18'; -DECLARE vEndingDate DATETIME DEFAULT '2016-10-31 23:59:00'; -DECLARE vMyTicket INT; -DECLARE vNewTicket INT; --- DECLARE SILLA_PCA INT DEFAULT 44; -DECLARE done INT DEFAULT 0; - -DECLARE rs CURSOR FOR -SELECT DISTINCT Id_Ticket -FROM Movimientos m -JOIN Tickets t using(Id_Ticket) -JOIN Articles a using(Id_Article) -JOIN Tipos tp using(tipo_id) -WHERE t.Fecha between vStartingDate and vEndingDate -AND warehouse_id = 1 -AND - ( - Id_Tipo = 'ANT' - OR - ( Id_Article = 100 - AND - Concepte LIKE 'ANT%') - ); - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; - -OPEN rs; - -FETCH rs INTO vMyTicket; - - - -WHILE NOT done DO - - - INSERT INTO Tickets(Id_Cliente - , warehouse_id - , Fecha - , Alias - , Id_Consigna - , Id_Trabajador - , Id_Ruta - , empresa_id - , Id_Agencia - , landing) - SELECT Id_Cliente - , SILLA_PCA as warehouse_id - , Fecha - , Alias - , Id_Consigna - , Id_Trabajador - , Id_Ruta - , empresa_id - , Id_Agencia - , landing - FROM Tickets - WHERE Id_Ticket = vMyTicket; - - SELECT LAST_INSERT_ID() INTO vNewTicket; - - -- SELECT vMyTicket, vNewTicket; SET done = 1; - UPDATE Movimientos m - JOIN Articles a using(Id_Article) - JOIN Tipos tp using(tipo_id) - SET Id_Ticket = vNewTicket - WHERE Id_Ticket = vMyTicket - AND ( - Id_Tipo = 'ANT' - OR - ( m.Id_Article = 100 - AND - Concepte LIKE 'ANT%') - ); - - FETCH rs INTO vMyTicket; - -END WHILE; - -CLOSE rs; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/subordinate.sql b/db/routines/vn2008/procedures/subordinate.sql deleted file mode 100644 index a30396951..000000000 --- a/db/routines/vn2008/procedures/subordinate.sql +++ /dev/null @@ -1,46 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`subordinate`(IN `vWorker` INT, IN `vBaseCase` BOOLEAN) - NO SQL -BEGIN - -- deprecated usar vn.worker_GetHierarch - DECLARE vAuxWorker INT; - - IF vBaseCase THEN - SET @@max_sp_recursion_depth = 5 ; - DROP TEMPORARY TABLE IF EXISTS subordinate; - CREATE TEMPORARY TABLE subordinate - (INDEX (Id_Trabajador)) - ENGINE = MEMORY - SELECT vWorker Id_Trabajador, TRUE visited, 0 boss; - END IF; - - INSERT INTO subordinate - SELECT Id_Trabajador, FALSE, vWorker - FROM Trabajadores WHERE boss = vWorker; - - IF (SELECT COUNT(*) FROM subordinate WHERE NOT visited AND vWorker = boss LIMIT 1) > 0 THEN - SELECT Id_Trabajador INTO vAuxWorker - FROM subordinate - WHERE NOT visited AND vWorker = boss LIMIT 1; - - REPEAT - CALL subordinate(vAuxWorker, FALSE); - UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = vAuxWorker; - SET vAuxWorker = 0; - - SELECT Id_Trabajador INTO vAuxWorker - FROM subordinate - WHERE NOT visited - AND vWorker = boss - LIMIT 1; - - UNTIL vAuxWorker = 0 - END REPEAT; - END IF; - - IF vWorker = 2 THEN - INSERT INTO subordinate - SET Id_Trabajador = vWorker, visited = TRUE, boss = vWorker; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/suppliersDebt.sql b/db/routines/vn2008/procedures/suppliersDebt.sql deleted file mode 100644 index 9670badc5..000000000 --- a/db/routines/vn2008/procedures/suppliersDebt.sql +++ /dev/null @@ -1,35 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`suppliersDebt`() -BEGIN - SELECT abbreviation as Empresa, Proveedor, Euros, divisa, empresa_id, proveedor_id - FROM - ( - SELECT empresa_id, - proveedor_id, - cast(sum(Euros) AS DECIMAL(10,2)) as Euros, - cast(sum(divisa) AS DECIMAL(10,2)) as divisa - FROM - ( - SELECT empresa_id, - proveedor_id, - -1 * cantidad as Euros, - -1 * divisa as divisa - FROM recibida_vencimiento rv - INNER JOIN recibida r ON r.id = rv.recibida_id - WHERE r.fecha > '2014-12-31' - - UNION ALL - - SELECT empresa_id, - id_proveedor, - importe, - divisa - FROM pago - WHERE fecha > '2014-12-31' - ) sub - GROUP BY empresa_id, proveedor_id - ) sub2 - JOIN Proveedores p ON p.Id_Proveedor = sub2.proveedor_id - JOIN empresa e ON e.id = sub2.empresa_id; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/top_seller.sql b/db/routines/vn2008/procedures/top_seller.sql deleted file mode 100644 index cb51d1425..000000000 --- a/db/routines/vn2008/procedures/top_seller.sql +++ /dev/null @@ -1,113 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`top_seller`() -BEGIN - - drop table if exists top_sellers_min; - create temporary table top_sellers_min ENGINE = MEMORY - select a.Id_Article , tip.reino_id as Reino, count(m.Id_Article) as contados - from Movimientos m - inner join Tickets t - on m.Id_Ticket = t.Id_Ticket - inner join Articles a - on a.Id_Article = m.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tip.reino_id - where t.Fecha between timestampadd(day,-7,util.VN_CURDATE()) and util.VN_CURDATE() - group by m.Id_Article; - - drop table if exists top_seller; - create temporary table top_seller ENGINE = MEMORY - select a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, - tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados - from top_sellers_min tmp - inner join Articles a - on a.Id_Article = tmp.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tmp.Reino - where tmp.Reino = 1 - order by contados desc - limit 5; - - insert into top_seller - select - a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, - tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados - from top_sellers_min tmp - inner join Articles a - on a.Id_Article = tmp.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tmp.Reino - where tmp.Reino = 2 - order by contados desc - limit 5; - - insert into top_seller - select - a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, - tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados - from top_sellers_min tmp - inner join Articles a - on a.Id_Article = tmp.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tmp.Reino - where tmp.Reino = 3 - order by contados desc - limit 5; - - insert into top_seller - select - a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, - tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados - from top_sellers_min tmp - inner join Articles a - on a.Id_Article = tmp.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tmp.Reino - where tmp.Reino = 4 - order by contados desc - limit 5; - - insert into top_seller - select - a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, - tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados - from top_sellers_min tmp - inner join Articles a - on a.Id_Article = tmp.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tmp.Reino - where tmp.Reino = 5 - order by contados desc - limit 5; - - insert into top_seller - select - a.Article, tmp.Id_Article , a.Foto as foto, a.tipo_id as Id_Tipo, - tmp.Reino, r.reino as ReinoNombre, tip.Tipo as Tipo, tmp.contados - from top_sellers_min tmp - inner join Articles a - on a.Id_Article = tmp.Id_Article - inner join Tipos tip - on a.tipo_id = tip.tipo_id - inner join reinos r - on r.id = tmp.Reino - where tmp.Reino = 7 - order by contados desc - limit 5; - - drop table if exists top_sellers_min; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/travel_tree_shipment.sql b/db/routines/vn2008/procedures/travel_tree_shipment.sql deleted file mode 100644 index acbca6752..000000000 --- a/db/routines/vn2008/procedures/travel_tree_shipment.sql +++ /dev/null @@ -1,37 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`travel_tree_shipment`(v_date DATE, v_consigna INT, v_agency INT, v_warehouse INT) -BEGIN -/** -* DEPRECATED usar vn.agencyHourGetLanded -* - * Devuelve una tabla temporal con el dia de recepcion para v_date. - * - * @param v_date Fecha de preparacion de mercancia - * @param v_consigna Id de consignatario, %NULL para recogida - * @param v_agency Id agencia - * @table travel_tree_shipment Datos de recepción - */ - DROP TEMPORARY TABLE IF EXISTS travel_tree_shipment; - CREATE TEMPORARY TABLE travel_tree_shipment - ENGINE = MEMORY - SELECT v_warehouse warehouse_id, v_envio landing FROM ( - SELECT * FROM ( - SELECT v_warehouse, TIMESTAMPADD(DAY, subtract_day, v_date) v_envio, subtract_day, ah.max_hour - FROM agency_hour ah - LEFT JOIN Consignatarios c ON c.Id_Consigna = v_consigna - WHERE (week_day = weekday(TIMESTAMPADD(DAY, subtract_day, v_date)) OR week_day IS NULL) - AND (ah.agency_id = v_agency OR ah.agency_id IS NULL) - AND ah.warehouse_id = v_warehouse - AND (ah.province_id = c.province_id OR ah.province_id IS NULL OR v_consigna IS NULL) - ORDER BY ( - (ah.week_day IS NOT NULL) + - (ah.agency_id IS NOT NULL) + - (- ah.subtract_day) + - ((ah.province_id IS NOT NULL)*3) - ) DESC - ) t - LIMIT 1 - ) t - WHERE IF(v_date = util.VN_CURDATE(), max_hour > HOUR(util.VN_NOW()), TRUE) AND subtract_day < 225; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_delete.sql b/db/routines/vn2008/procedures/unary_delete.sql deleted file mode 100644 index 7f60569ca..000000000 --- a/db/routines/vn2008/procedures/unary_delete.sql +++ /dev/null @@ -1,30 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_delete`(v_node INT, v_delete bool) -BEGIN -/** - * Borra un nodo. Se puede indicar si se quieren mantener los hijos. - * En este caso los hijos pasan al padre del nodo. - * Si no tiene padre, los hijos pasaran a ser padres. - * - * @v_node: Nodo que se quiere borrar. - * @v_delete: Se indica si se borran los nodos. - **/ - - DECLARE v_parent INT; - - SELECT parent - INTO v_parent - FROM unary - WHERE id = v_node; - - IF(v_delete = FALSE) THEN - UPDATE unary - SET parent = v_parent - WHERE parent = v_node; - END IF; - - DELETE FROM unary - WHERE id = v_node; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_insert.sql b/db/routines/vn2008/procedures/unary_insert.sql deleted file mode 100644 index 743944f86..000000000 --- a/db/routines/vn2008/procedures/unary_insert.sql +++ /dev/null @@ -1,17 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_insert`(OUT v_unary INT, v_parent INT) -BEGIN - - /** - * Inserta un nuevo nodo. Se puede indicar el padre. - * - * @v_parent: Nodo padre. - * @v_unary: Id del nuevo nodo. - **/ - - INSERT INTO unary(parent) VALUES(v_parent); - - SELECT last_insert_id() INTO v_unary; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_scan_ident.sql b/db/routines/vn2008/procedures/unary_scan_ident.sql deleted file mode 100644 index 5c62e93e7..000000000 --- a/db/routines/vn2008/procedures/unary_scan_ident.sql +++ /dev/null @@ -1,25 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_scan_ident`(v_top INT, v_space INT) -BEGIN -/** - * A partir de un nodo devuelve el id y el nombre del nodod y sus hijos. - * El nombre viene identado segun el numero de espacios multiplicado por la profundiad del nodo. - * - * v_top: Id del nodo padre. - * v_space: Spacios a dejar al identar, - * @table tmp.tree_ident Tabla con los ids de los nodos descendientes y su nombre identado; - **/ - - DROP TEMPORARY TABLE IF EXISTS tmp.tree_ident; - CALL tree_leaves(v_top); - - CREATE TEMPORARY TABLE tmp.tree_ident - ENGINE = MEMORY - SELECT t.id, - CONCAT( REPEAT(REPEAT(" ",v_space), t.depth), sp.name) AS name - FROM tmp.tree t - INNER JOIN unary_scan sp - ON t.id = sp.id; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_scan_insert.sql b/db/routines/vn2008/procedures/unary_scan_insert.sql deleted file mode 100644 index 0ac2c7b1e..000000000 --- a/db/routines/vn2008/procedures/unary_scan_insert.sql +++ /dev/null @@ -1,20 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_scan_insert`(v_name VARCHAR(45), v_parent INT, v_type VARCHAR(45)) -BEGIN - - /** - * Inserta un nuevo nodo de tipo unary_scan. Se puede indicar el padre. - * - * @v_name: Nombre del nodo. - * @v_parent: Nodo padre. - * @v_type: Tipo del nodo a crear. - **/ - - DECLARE v_unary INT; - - CALL unary_insert(v_unary, v_parent); - - INSERT INTO unary_scan(name, unary_id, type) VALUES(v_name, v_unary, v_type); - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/unary_update.sql b/db/routines/vn2008/procedures/unary_update.sql deleted file mode 100644 index 8bb366810..000000000 --- a/db/routines/vn2008/procedures/unary_update.sql +++ /dev/null @@ -1,32 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`unary_update`(v_node INT, v_new_parent INT, v_move bool) -BEGIN -/** - * Cambia el padre de un nodo. Se puede indicar si se quieren mover los hijos. - * En este caso los hijos pasan al padre del nodo. - * Si no tiene padre, los hijos pasaran a ser padres. - * - * @v_node: Nodo que se quiere mover. - * @v_new_parent: Padre al que se quiere mover el nodo. - * @v_move: Se indica si se mueven los nodos. - **/ - - DECLARE v_parent INT; - - SELECT parent - INTO v_parent - FROM unary - WHERE id = v_node; - - IF(v_move = TRUE) THEN - UPDATE unary - SET parent = v_parent - WHERE parent = v_node; - END IF; - - UPDATE unary - SET parent = v_new_parent - WHERE id = v_node; - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/triggers/Conteo_ai.sql b/db/routines/vn2008/triggers/Conteo_afterInsert.sql similarity index 96% rename from db/routines/vn2008/triggers/Conteo_ai.sql rename to db/routines/vn2008/triggers/Conteo_afterInsert.sql index 5d8a0ef25..90f2a5edd 100644 --- a/db/routines/vn2008/triggers/Conteo_ai.sql +++ b/db/routines/vn2008/triggers/Conteo_afterInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`Conteo_ai` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`Conteo_afterInsert` AFTER INSERT ON `Conteo` FOR EACH ROW BEGIN diff --git a/db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql b/db/routines/vn2008/triggers/account_conciliacion_beforeInsert.sql similarity index 92% rename from db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql rename to db/routines/vn2008/triggers/account_conciliacion_beforeInsert.sql index 01c8af36e..fb6283e1a 100644 --- a/db/routines/vn2008/triggers/account_conciliacion_BEFORE_INSERT.sql +++ b/db/routines/vn2008/triggers/account_conciliacion_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`account_conciliacion_BEFORE_INSERT` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`account_conciliacion_beforeInsert` BEFORE INSERT ON `account_conciliacion` FOR EACH ROW set new.id_calculated = replace( diff --git a/db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql b/db/routines/vn2008/triggers/agency_hour_afterUpdate.sql similarity index 95% rename from db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql rename to db/routines/vn2008/triggers/agency_hour_afterUpdate.sql index fb958c165..81996137b 100644 --- a/db/routines/vn2008/triggers/agency_hour_AFTER_UPDATE.sql +++ b/db/routines/vn2008/triggers/agency_hour_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hour_AFTER_UPDATE` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hour_afterUpdate` AFTER UPDATE ON `agency_hour` FOR EACH ROW BEGIN diff --git a/db/routines/vn2008/triggers/agency_hourBeforeInsert.sql b/db/routines/vn2008/triggers/agency_hour_beforeInsert.sql similarity index 96% rename from db/routines/vn2008/triggers/agency_hourBeforeInsert.sql rename to db/routines/vn2008/triggers/agency_hour_beforeInsert.sql index f4ea375c5..a6007934e 100644 --- a/db/routines/vn2008/triggers/agency_hourBeforeInsert.sql +++ b/db/routines/vn2008/triggers/agency_hour_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hourBeforeInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`agency_hour_beforeInsert` BEFORE INSERT ON `agency_hour` FOR EACH ROW BEGIN diff --git a/db/routines/vn2008/triggers/awb_recibida_ad.sql b/db/routines/vn2008/triggers/awb_recibida_afterDelete.sql similarity index 94% rename from db/routines/vn2008/triggers/awb_recibida_ad.sql rename to db/routines/vn2008/triggers/awb_recibida_afterDelete.sql index e33d7fd3c..6a3380b8f 100644 --- a/db/routines/vn2008/triggers/awb_recibida_ad.sql +++ b/db/routines/vn2008/triggers/awb_recibida_afterDelete.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`awb_recibida_ad` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`awb_recibida_afterDelete` AFTER DELETE ON `awb_recibida` FOR EACH ROW IF (SELECT COUNT(*) FROM recibida_iva where recibida_id = OLD.recibida_id) = 0 diff --git a/db/routines/vn2008/triggers/movement_label_au.sql b/db/routines/vn2008/triggers/movement_label_afterUpdate.sql similarity index 92% rename from db/routines/vn2008/triggers/movement_label_au.sql rename to db/routines/vn2008/triggers/movement_label_afterUpdate.sql index 5f9561e15..364568fb3 100644 --- a/db/routines/vn2008/triggers/movement_label_au.sql +++ b/db/routines/vn2008/triggers/movement_label_afterUpdate.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`movement_label_au` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn2008`.`movement_label_afterUpdate` AFTER UPDATE ON `movement_label` FOR EACH ROW IF NEW.stem >= (SELECT Cantidad FROM Movimientos WHERE Id_Movimiento = NEW.Id_Movimiento) THEN diff --git a/db/routines/vn2008/views/client_observation.sql b/db/routines/vn2008/views/client_observation.sql deleted file mode 100644 index 7cd357b4e..000000000 --- a/db/routines/vn2008/views/client_observation.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`client_observation` -AS SELECT `co`.`id` AS `client_observation_id`, - `co`.`clientFk` AS `Id_Cliente`, - `co`.`workerFk` AS `Id_Trabajador`, - `co`.`text` AS `text`, - `co`.`created` AS `odbc_date` -FROM `vn`.`clientObservation` `co` diff --git a/db/routines/vn2008/views/clientes_gestdoc.sql b/db/routines/vn2008/views/clientes_gestdoc.sql deleted file mode 100644 index e711fded4..000000000 --- a/db/routines/vn2008/views/clientes_gestdoc.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`clientes_gestdoc` -AS SELECT `cd`.`clientFk` AS `Id_Cliente`, - `cd`.`dmsFk` AS `gest_doc_id` -FROM `vn`.`clientDms` `cd` diff --git a/db/routines/vn2008/views/clientes_regalos_enc.sql b/db/routines/vn2008/views/clientes_regalos_enc.sql deleted file mode 100644 index b8ed6fec2..000000000 --- a/db/routines/vn2008/views/clientes_regalos_enc.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`clientes_regalos_enc` -AS SELECT `cpg`.`clientFk` AS `Id_Cliente`, - `cpg`.`giftFk` AS `Id_Regalo`, - `cpg`.`added` AS `odbc_date` -FROM `vn`.`clientPackagingGifts` `cpg` diff --git a/db/routines/vn2008/views/clientes_regalos_lista_enc.sql b/db/routines/vn2008/views/clientes_regalos_lista_enc.sql deleted file mode 100644 index e129776b5..000000000 --- a/db/routines/vn2008/views/clientes_regalos_lista_enc.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`clientes_regalos_lista_enc` -AS SELECT `pg`.`id` AS `Id_Regalo`, - `pg`.`description` AS `Descripcion`, - `pg`.`photo` AS `foto`, - IF( - `util`.`VN_CURDATE`() BETWEEN `pg`.`started` AND `pg`.`ended`, - 1, - 0 - ) AS `activo`, - `pg`.`started` AS `datstart`, - `pg`.`ended` AS `datend`, - IFNULL(`pg`.`warehouseFk`, 0) AS `warehouse_id`, - IFNULL(`pg`.`provinceFk`, 0) AS `province_id`, - IFNULL(`pg`.`countryFk`, 0) AS `countryFk` -FROM `vn`.`packagingGifts` `pg` diff --git a/db/routines/vn2008/views/clientes_tipo.sql b/db/routines/vn2008/views/clientes_tipo.sql deleted file mode 100644 index 130dceb65..000000000 --- a/db/routines/vn2008/views/clientes_tipo.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`clientes_tipo` -AS SELECT `ct`.`id` AS `clientes_tipo_id`, - `ct`.`code` AS `code`, - `ct`.`type` AS `tipo`, - `ct`.`isCreatedAsServed` AS `isCreatedAsServed` -FROM `vn`.`clientType` `ct` diff --git a/db/routines/vn2008/views/cooler_path_detail.sql b/db/routines/vn2008/views/cooler_path_detail.sql deleted file mode 100644 index 97b234186..000000000 --- a/db/routines/vn2008/views/cooler_path_detail.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`cooler_path_detail` -AS SELECT `cpd`.`id` AS `cooler_path_detail_id`, - `cpd`.`coolerPathFk` AS `cooler_path_id`, - `cpd`.`hallway` AS `pasillo` -FROM `vn`.`coolerPathDetail` `cpd` diff --git a/db/routines/vn2008/views/credit.sql b/db/routines/vn2008/views/credit.sql deleted file mode 100644 index 233e9dc1a..000000000 --- a/db/routines/vn2008/views/credit.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`credit` -AS SELECT `c`.`id` AS `id`, - `c`.`clientFk` AS `Id_Cliente`, - `c`.`workerFk` AS `Id_Trabajador`, - `c`.`amount` AS `amount`, - `c`.`created` AS `odbc_date` -FROM `vn`.`clientCredit` `c` diff --git a/db/routines/vn2008/views/escritos_det.sql b/db/routines/vn2008/views/escritos_det.sql deleted file mode 100644 index 46b6db506..000000000 --- a/db/routines/vn2008/views/escritos_det.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`escritos_det` -AS SELECT `cs`.`id` AS `id`, - `cs`.`clientFk` AS `Id_Cliente`, - `cs`.`typeFk` AS `escritos_id`, - `cs`.`created` AS `fecha`, - `cs`.`workerFk` AS `Id_Trabajador`, - `cs`.`userFk` AS `userFk`, - `cs`.`companyFk` AS `empresa_id`, - `cs`.`balance` AS `saldo` -FROM `vn`.`clientSample` `cs` diff --git a/db/routines/vn2008/views/gesttip.sql b/db/routines/vn2008/views/gesttip.sql index 0c3befe1a..663e70617 100644 --- a/db/routines/vn2008/views/gesttip.sql +++ b/db/routines/vn2008/views/gesttip.sql @@ -3,7 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn2008`.`gesttip` AS SELECT `g`.`id` AS `id`, `g`.`name` AS `tipo`, - `g`.`path` AS `path`, `g`.`readRoleFk` AS `readRoleFk`, `g`.`writeRoleFk` AS `writeRoleFk`, `g`.`code` AS `code` diff --git a/db/routines/vn2008/views/iva_codigo.sql b/db/routines/vn2008/views/iva_codigo.sql deleted file mode 100644 index 6bd811abe..000000000 --- a/db/routines/vn2008/views/iva_codigo.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`iva_codigo` -AS SELECT `tc`.`id` AS `id`, - `tc`.`dated` AS `fecha`, - `tc`.`code` AS `codigo`, - `tc`.`taxTypeFk` AS `iva_tipo_id`, - `tc`.`rate` AS `iva`, - `tc`.`equalizationTax` AS `recargo`, - `tc`.`type` AS `tipo`, - `tc`.`link` AS `link`, - `tc`.`isActive` AS `isActive`, - `tc`.`updated` AS `updated`, - `tc`.`transactionCode` AS `transactionCode` -FROM `vn`.`taxCode` `tc` diff --git a/db/routines/vn2008/views/iva_group.sql b/db/routines/vn2008/views/iva_group.sql deleted file mode 100644 index f4fc1e92e..000000000 --- a/db/routines/vn2008/views/iva_group.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`iva_group` -AS SELECT `tc`.`id` AS `iva_group_id`, - `tc`.`description` AS `description`, - `tc`.`code` AS `code` -FROM `vn`.`taxClass` `tc` diff --git a/db/routines/vn2008/views/iva_group_codigo.sql b/db/routines/vn2008/views/iva_group_codigo.sql deleted file mode 100644 index 86e72ebe9..000000000 --- a/db/routines/vn2008/views/iva_group_codigo.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`iva_group_codigo` -AS SELECT `tcc`.`taxClassFk` AS `iva_group_id`, - `tcc`.`effectived` AS `date`, - `tcc`.`taxCodeFk` AS `iva_codigo_id` -FROM `vn`.`taxClassCode` `tcc` diff --git a/db/routines/vn2008/views/iva_tipo.sql b/db/routines/vn2008/views/iva_tipo.sql deleted file mode 100644 index 0c62243e2..000000000 --- a/db/routines/vn2008/views/iva_tipo.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`iva_tipo` -AS SELECT `tt`.`id` AS `id`, - `tt`.`nickname` AS `alias`, - `tt`.`isAccrued` AS `isAccrued`, - `tt`.`serial` AS `serie_id`, - `tt`.`TIPOOPE` AS `TIPOOPE`, - `tt`.`description` AS `descripcion`, - `tt`.`countryFk` AS `Id_Pais` -FROM `vn`.`taxType` `tt` diff --git a/db/routines/vn2008/views/travel.sql b/db/routines/vn2008/views/travel.sql index 9c98120ef..b55dbf9b6 100644 --- a/db/routines/vn2008/views/travel.sql +++ b/db/routines/vn2008/views/travel.sql @@ -16,5 +16,6 @@ AS SELECT `t`.`id` AS `id`, `t`.`kg` AS `kg`, `t`.`cargoSupplierFk` AS `cargoSupplierFk`, `t`.`totalEntries` AS `totalEntries`, - `t`.`appointment` AS `appointment` + `t`.`appointment` AS `appointment`, + `t`.`awbFk` AS `awbFk` FROM `vn`.`travel` `t` diff --git a/db/versions/10193-navyHydrangea/00-delete.sql b/db/versions/.archive/10193-navyHydrangea/00-delete.sql similarity index 100% rename from db/versions/10193-navyHydrangea/00-delete.sql rename to db/versions/.archive/10193-navyHydrangea/00-delete.sql diff --git a/db/versions/10193-navyHydrangea/01-botanicExport.sql b/db/versions/.archive/10193-navyHydrangea/01-botanicExport.sql similarity index 100% rename from db/versions/10193-navyHydrangea/01-botanicExport.sql rename to db/versions/.archive/10193-navyHydrangea/01-botanicExport.sql diff --git a/db/versions/10193-navyHydrangea/02-item.sql b/db/versions/.archive/10193-navyHydrangea/02-item.sql similarity index 100% rename from db/versions/10193-navyHydrangea/02-item.sql rename to db/versions/.archive/10193-navyHydrangea/02-item.sql diff --git a/db/versions/10193-navyHydrangea/03-autonomy.sql b/db/versions/.archive/10193-navyHydrangea/03-autonomy.sql similarity index 100% rename from db/versions/10193-navyHydrangea/03-autonomy.sql rename to db/versions/.archive/10193-navyHydrangea/03-autonomy.sql diff --git a/db/versions/10193-navyHydrangea/03-turn.sql b/db/versions/.archive/10193-navyHydrangea/03-turn.sql similarity index 100% rename from db/versions/10193-navyHydrangea/03-turn.sql rename to db/versions/.archive/10193-navyHydrangea/03-turn.sql diff --git a/db/versions/10193-navyHydrangea/04-country.sql b/db/versions/.archive/10193-navyHydrangea/04-country.sql similarity index 100% rename from db/versions/10193-navyHydrangea/04-country.sql rename to db/versions/.archive/10193-navyHydrangea/04-country.sql diff --git a/db/versions/10379-turquoiseOrchid/00-firstScript.sql b/db/versions/.archive/10379-turquoiseOrchid/00-firstScript.sql similarity index 100% rename from db/versions/10379-turquoiseOrchid/00-firstScript.sql rename to db/versions/.archive/10379-turquoiseOrchid/00-firstScript.sql diff --git a/db/versions/10384-limeLaurel/00-business_workcenterFk.sql b/db/versions/.archive/10384-limeLaurel/00-business_workcenterFk.sql similarity index 100% rename from db/versions/10384-limeLaurel/00-business_workcenterFk.sql rename to db/versions/.archive/10384-limeLaurel/00-business_workcenterFk.sql diff --git a/db/versions/10395-blueGalax/00-firstScript.sql b/db/versions/.archive/10395-blueGalax/00-firstScript.sql similarity index 100% rename from db/versions/10395-blueGalax/00-firstScript.sql rename to db/versions/.archive/10395-blueGalax/00-firstScript.sql diff --git a/db/versions/10396-grayRoebelini/00-firstScript.sql b/db/versions/.archive/10396-grayRoebelini/00-firstScript.sql similarity index 100% rename from db/versions/10396-grayRoebelini/00-firstScript.sql rename to db/versions/.archive/10396-grayRoebelini/00-firstScript.sql diff --git a/db/versions/10397-4848TicketsFloramondo/00-firstScript.sql b/db/versions/.archive/10397-4848TicketsFloramondo/00-firstScript.sql similarity index 100% rename from db/versions/10397-4848TicketsFloramondo/00-firstScript.sql rename to db/versions/.archive/10397-4848TicketsFloramondo/00-firstScript.sql diff --git a/db/versions/10399-blueErica/00-firstScript.sql b/db/versions/.archive/10399-blueErica/00-firstScript.sql similarity index 100% rename from db/versions/10399-blueErica/00-firstScript.sql rename to db/versions/.archive/10399-blueErica/00-firstScript.sql diff --git a/db/versions/10400-brownEucalyptus/00-firstScript.sql b/db/versions/.archive/10400-brownEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10400-brownEucalyptus/00-firstScript.sql rename to db/versions/.archive/10400-brownEucalyptus/00-firstScript.sql diff --git a/db/versions/10402-orangeTulip/00-firstScript.sql b/db/versions/.archive/10402-orangeTulip/00-firstScript.sql similarity index 100% rename from db/versions/10402-orangeTulip/00-firstScript.sql rename to db/versions/.archive/10402-orangeTulip/00-firstScript.sql diff --git a/db/versions/10404-grayMedeola/00-firstScript.sql b/db/versions/.archive/10404-grayMedeola/00-firstScript.sql similarity index 100% rename from db/versions/10404-grayMedeola/00-firstScript.sql rename to db/versions/.archive/10404-grayMedeola/00-firstScript.sql diff --git a/db/versions/10405-orangeGalax/00-firstScript.sql b/db/versions/.archive/10405-orangeGalax/00-firstScript.sql similarity index 100% rename from db/versions/10405-orangeGalax/00-firstScript.sql rename to db/versions/.archive/10405-orangeGalax/00-firstScript.sql diff --git a/db/versions/10407-blueOak/00-firstScript.sql b/db/versions/.archive/10407-blueOak/00-firstScript.sql similarity index 100% rename from db/versions/10407-blueOak/00-firstScript.sql rename to db/versions/.archive/10407-blueOak/00-firstScript.sql diff --git a/db/versions/10408-purpleIvy/00-firstScript.sql b/db/versions/.archive/10408-purpleIvy/00-firstScript.sql similarity index 100% rename from db/versions/10408-purpleIvy/00-firstScript.sql rename to db/versions/.archive/10408-purpleIvy/00-firstScript.sql diff --git a/db/versions/10409-brownSalal/00-firstScript.sql b/db/versions/.archive/10409-brownSalal/00-firstScript.sql similarity index 100% rename from db/versions/10409-brownSalal/00-firstScript.sql rename to db/versions/.archive/10409-brownSalal/00-firstScript.sql diff --git a/db/versions/10412-yellowCarnation/00-firstScript.sql b/db/versions/.archive/10412-yellowCarnation/00-firstScript.sql similarity index 100% rename from db/versions/10412-yellowCarnation/00-firstScript.sql rename to db/versions/.archive/10412-yellowCarnation/00-firstScript.sql diff --git a/db/versions/10413-whiteCymbidium/00-firstScript.sql b/db/versions/.archive/10413-whiteCymbidium/00-firstScript.sql similarity index 100% rename from db/versions/10413-whiteCymbidium/00-firstScript.sql rename to db/versions/.archive/10413-whiteCymbidium/00-firstScript.sql diff --git a/db/versions/10416-blueAsparagus/00-firstScript.sql b/db/versions/.archive/10416-blueAsparagus/00-firstScript.sql similarity index 100% rename from db/versions/10416-blueAsparagus/00-firstScript.sql rename to db/versions/.archive/10416-blueAsparagus/00-firstScript.sql diff --git a/db/versions/10420-goldenCataractarum/00-firstScript.sql b/db/versions/.archive/10420-goldenCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10420-goldenCataractarum/00-firstScript.sql rename to db/versions/.archive/10420-goldenCataractarum/00-firstScript.sql diff --git a/db/versions/10421-navyMonstera/00-firstScript.sql b/db/versions/.archive/10421-navyMonstera/00-firstScript.sql similarity index 100% rename from db/versions/10421-navyMonstera/00-firstScript.sql rename to db/versions/.archive/10421-navyMonstera/00-firstScript.sql diff --git a/db/versions/10426-silverAsparagus/00-firstScript.sql b/db/versions/.archive/10426-silverAsparagus/00-firstScript.sql similarity index 100% rename from db/versions/10426-silverAsparagus/00-firstScript.sql rename to db/versions/.archive/10426-silverAsparagus/00-firstScript.sql diff --git a/db/versions/10428-wheatRose/00-firstScript.sql b/db/versions/.archive/10428-wheatRose/00-firstScript.sql similarity index 100% rename from db/versions/10428-wheatRose/00-firstScript.sql rename to db/versions/.archive/10428-wheatRose/00-firstScript.sql diff --git a/db/versions/10431-redCordyline/00-firstScript.sql b/db/versions/.archive/10431-redCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10431-redCordyline/00-firstScript.sql rename to db/versions/.archive/10431-redCordyline/00-firstScript.sql diff --git a/db/versions/10433-salmonAnthurium/00-firstScript.sql b/db/versions/.archive/10433-salmonAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10433-salmonAnthurium/00-firstScript.sql rename to db/versions/.archive/10433-salmonAnthurium/00-firstScript.sql diff --git a/db/versions/10434-grayTulip/00-firstScript.sql b/db/versions/.archive/10434-grayTulip/00-firstScript.sql similarity index 100% rename from db/versions/10434-grayTulip/00-firstScript.sql rename to db/versions/.archive/10434-grayTulip/00-firstScript.sql diff --git a/db/versions/10435-aquaGalax/00-firstScript.sql b/db/versions/.archive/10435-aquaGalax/00-firstScript.sql similarity index 100% rename from db/versions/10435-aquaGalax/00-firstScript.sql rename to db/versions/.archive/10435-aquaGalax/00-firstScript.sql diff --git a/db/versions/10436-tealPalmetto/00-createFkWorker.sql b/db/versions/.archive/10436-tealPalmetto/00-createFkWorker.sql similarity index 100% rename from db/versions/10436-tealPalmetto/00-createFkWorker.sql rename to db/versions/.archive/10436-tealPalmetto/00-createFkWorker.sql diff --git a/db/versions/10436-tealPalmetto/01-addStateToWorkerProductivity.sql b/db/versions/.archive/10436-tealPalmetto/01-addStateToWorkerProductivity.sql similarity index 100% rename from db/versions/10436-tealPalmetto/01-addStateToWorkerProductivity.sql rename to db/versions/.archive/10436-tealPalmetto/01-addStateToWorkerProductivity.sql diff --git a/db/versions/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql b/db/versions/.archive/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql similarity index 100% rename from db/versions/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql rename to db/versions/.archive/10436-tealPalmetto/02-DeprecateVnSaleTrackingState.sql diff --git a/db/versions/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql b/db/versions/.archive/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql similarity index 100% rename from db/versions/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql rename to db/versions/.archive/10436-tealPalmetto/03-DeprecateColumnVnSaleTrackingActionFk.sql diff --git a/db/versions/10436-tealPalmetto/04-DropSchemaVnControl.sql b/db/versions/.archive/10436-tealPalmetto/04-DropSchemaVnControl.sql similarity index 100% rename from db/versions/10436-tealPalmetto/04-DropSchemaVnControl.sql rename to db/versions/.archive/10436-tealPalmetto/04-DropSchemaVnControl.sql diff --git a/db/versions/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql b/db/versions/.archive/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql similarity index 100% rename from db/versions/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql rename to db/versions/.archive/10436-tealPalmetto/05-RemoveFkWorkerProductivity.sql diff --git a/db/versions/10439-greenTulip/00-fixRole.sql b/db/versions/.archive/10439-greenTulip/00-fixRole.sql similarity index 100% rename from db/versions/10439-greenTulip/00-fixRole.sql rename to db/versions/.archive/10439-greenTulip/00-fixRole.sql diff --git a/db/versions/10440-grayDendro/00-firstScript.sql b/db/versions/.archive/10440-grayDendro/00-firstScript.sql similarity index 100% rename from db/versions/10440-grayDendro/00-firstScript.sql rename to db/versions/.archive/10440-grayDendro/00-firstScript.sql diff --git a/db/versions/10444-crimsonBamboo/00-firstScript.sql b/db/versions/.archive/10444-crimsonBamboo/00-firstScript.sql similarity index 100% rename from db/versions/10444-crimsonBamboo/00-firstScript.sql rename to db/versions/.archive/10444-crimsonBamboo/00-firstScript.sql diff --git a/db/versions/10445-orangeMoss/00-firstScript.sql b/db/versions/.archive/10445-orangeMoss/00-firstScript.sql similarity index 100% rename from db/versions/10445-orangeMoss/00-firstScript.sql rename to db/versions/.archive/10445-orangeMoss/00-firstScript.sql diff --git a/db/versions/10448-wheatChrysanthemum/00-firstScript.sql b/db/versions/.archive/10448-wheatChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10448-wheatChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10448-wheatChrysanthemum/00-firstScript.sql diff --git a/db/versions/10450-blackIvy/00-firstScript.sql b/db/versions/.archive/10450-blackIvy/00-firstScript.sql similarity index 100% rename from db/versions/10450-blackIvy/00-firstScript.sql rename to db/versions/.archive/10450-blackIvy/00-firstScript.sql diff --git a/db/versions/10451-salmonOak/00-firstScript.sql b/db/versions/.archive/10451-salmonOak/00-firstScript.sql similarity index 100% rename from db/versions/10451-salmonOak/00-firstScript.sql rename to db/versions/.archive/10451-salmonOak/00-firstScript.sql diff --git a/db/versions/10452-redEucalyptus/00-firstScript.sql b/db/versions/.archive/10452-redEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10452-redEucalyptus/00-firstScript.sql rename to db/versions/.archive/10452-redEucalyptus/00-firstScript.sql diff --git a/db/versions/10453-aquaMedeola/00-firstScript.sql b/db/versions/.archive/10453-aquaMedeola/00-firstScript.sql similarity index 100% rename from db/versions/10453-aquaMedeola/00-firstScript.sql rename to db/versions/.archive/10453-aquaMedeola/00-firstScript.sql diff --git a/db/versions/10454-bronzeMoss/00-firstScript.sql b/db/versions/.archive/10454-bronzeMoss/00-firstScript.sql similarity index 100% rename from db/versions/10454-bronzeMoss/00-firstScript.sql rename to db/versions/.archive/10454-bronzeMoss/00-firstScript.sql diff --git a/db/versions/10455-blackGerbera/00-firstScript.sql b/db/versions/.archive/10455-blackGerbera/00-firstScript.sql similarity index 100% rename from db/versions/10455-blackGerbera/00-firstScript.sql rename to db/versions/.archive/10455-blackGerbera/00-firstScript.sql diff --git a/db/versions/10456-greenArborvitae/00-firstScript.sql b/db/versions/.archive/10456-greenArborvitae/00-firstScript.sql similarity index 100% rename from db/versions/10456-greenArborvitae/00-firstScript.sql rename to db/versions/.archive/10456-greenArborvitae/00-firstScript.sql diff --git a/db/versions/10457-crimsonTulip/00-firstScript.sql b/db/versions/.archive/10457-crimsonTulip/00-firstScript.sql similarity index 100% rename from db/versions/10457-crimsonTulip/00-firstScript.sql rename to db/versions/.archive/10457-crimsonTulip/00-firstScript.sql diff --git a/db/versions/10458-orangePalmetto/00-firstScript.sql b/db/versions/.archive/10458-orangePalmetto/00-firstScript.sql similarity index 100% rename from db/versions/10458-orangePalmetto/00-firstScript.sql rename to db/versions/.archive/10458-orangePalmetto/00-firstScript.sql diff --git a/db/versions/10459-chocolateMedeola/00-alterTableUtilConfig.sql b/db/versions/.archive/10459-chocolateMedeola/00-alterTableUtilConfig.sql similarity index 100% rename from db/versions/10459-chocolateMedeola/00-alterTableUtilConfig.sql rename to db/versions/.archive/10459-chocolateMedeola/00-alterTableUtilConfig.sql diff --git a/db/versions/10459-chocolateMedeola/01-createFunctionCurdate.sql b/db/versions/.archive/10459-chocolateMedeola/01-createFunctionCurdate.sql similarity index 100% rename from db/versions/10459-chocolateMedeola/01-createFunctionCurdate.sql rename to db/versions/.archive/10459-chocolateMedeola/01-createFunctionCurdate.sql diff --git a/db/versions/10459-chocolateMedeola/02-createFunctionMockTime.sql b/db/versions/.archive/10459-chocolateMedeola/02-createFunctionMockTime.sql similarity index 100% rename from db/versions/10459-chocolateMedeola/02-createFunctionMockTime.sql rename to db/versions/.archive/10459-chocolateMedeola/02-createFunctionMockTime.sql diff --git a/db/versions/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql b/db/versions/.archive/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql similarity index 100% rename from db/versions/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql rename to db/versions/.archive/10459-chocolateMedeola/03-createFunctionMockTimeBase.sql diff --git a/db/versions/10459-chocolateMedeola/04-createFunctionNow.sql b/db/versions/.archive/10459-chocolateMedeola/04-createFunctionNow.sql similarity index 100% rename from db/versions/10459-chocolateMedeola/04-createFunctionNow.sql rename to db/versions/.archive/10459-chocolateMedeola/04-createFunctionNow.sql diff --git a/db/versions/10460-crimsonDendro/00-firstScript.sql b/db/versions/.archive/10460-crimsonDendro/00-firstScript.sql similarity index 100% rename from db/versions/10460-crimsonDendro/00-firstScript.sql rename to db/versions/.archive/10460-crimsonDendro/00-firstScript.sql diff --git a/db/versions/10461-filtroPorTipos/00-firstScript.sql b/db/versions/.archive/10461-filtroPorTipos/00-firstScript.sql similarity index 100% rename from db/versions/10461-filtroPorTipos/00-firstScript.sql rename to db/versions/.archive/10461-filtroPorTipos/00-firstScript.sql diff --git a/db/versions/10463-wheatMonstera/00-firstScript.sql b/db/versions/.archive/10463-wheatMonstera/00-firstScript.sql similarity index 100% rename from db/versions/10463-wheatMonstera/00-firstScript.sql rename to db/versions/.archive/10463-wheatMonstera/00-firstScript.sql diff --git a/db/versions/10468-goldenGerbera/00-firstScript.sql b/db/versions/.archive/10468-goldenGerbera/00-firstScript.sql similarity index 100% rename from db/versions/10468-goldenGerbera/00-firstScript.sql rename to db/versions/.archive/10468-goldenGerbera/00-firstScript.sql diff --git a/db/versions/10469-bronzeEucalyptus/00-firstScript.sql b/db/versions/.archive/10469-bronzeEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10469-bronzeEucalyptus/00-firstScript.sql rename to db/versions/.archive/10469-bronzeEucalyptus/00-firstScript.sql diff --git a/db/versions/10470-notaUltimoUsuario/00-firstScript.sql b/db/versions/.archive/10470-notaUltimoUsuario/00-firstScript.sql similarity index 100% rename from db/versions/10470-notaUltimoUsuario/00-firstScript.sql rename to db/versions/.archive/10470-notaUltimoUsuario/00-firstScript.sql diff --git a/db/versions/10471-orangeMastic/00-firstScript.sql b/db/versions/.archive/10471-orangeMastic/00-firstScript.sql similarity index 100% rename from db/versions/10471-orangeMastic/00-firstScript.sql rename to db/versions/.archive/10471-orangeMastic/00-firstScript.sql diff --git a/db/versions/10472-bronzeOak/00-firstScript.sql b/db/versions/.archive/10472-bronzeOak/00-firstScript.sql similarity index 100% rename from db/versions/10472-bronzeOak/00-firstScript.sql rename to db/versions/.archive/10472-bronzeOak/00-firstScript.sql diff --git a/db/versions/10477-goldenDendro/00-firstScript.sql b/db/versions/.archive/10477-goldenDendro/00-firstScript.sql similarity index 100% rename from db/versions/10477-goldenDendro/00-firstScript.sql rename to db/versions/.archive/10477-goldenDendro/00-firstScript.sql diff --git a/db/versions/10478-tealGalax/00-dropBasket.sql b/db/versions/.archive/10478-tealGalax/00-dropBasket.sql similarity index 100% rename from db/versions/10478-tealGalax/00-dropBasket.sql rename to db/versions/.archive/10478-tealGalax/00-dropBasket.sql diff --git a/db/versions/10478-tealGalax/00-firstScript.sql b/db/versions/.archive/10478-tealGalax/00-firstScript.sql similarity index 100% rename from db/versions/10478-tealGalax/00-firstScript.sql rename to db/versions/.archive/10478-tealGalax/00-firstScript.sql diff --git a/db/versions/10478-tealGalax/01-orderConfigured.sql b/db/versions/.archive/10478-tealGalax/01-orderConfigured.sql similarity index 100% rename from db/versions/10478-tealGalax/01-orderConfigured.sql rename to db/versions/.archive/10478-tealGalax/01-orderConfigured.sql diff --git a/db/versions/10478-tealGalax/02-configuredUpdate.sql b/db/versions/.archive/10478-tealGalax/02-configuredUpdate.sql similarity index 100% rename from db/versions/10478-tealGalax/02-configuredUpdate.sql rename to db/versions/.archive/10478-tealGalax/02-configuredUpdate.sql diff --git a/db/versions/10478-tealGalax/99-privileges.sql b/db/versions/.archive/10478-tealGalax/99-privileges.sql similarity index 100% rename from db/versions/10478-tealGalax/99-privileges.sql rename to db/versions/.archive/10478-tealGalax/99-privileges.sql diff --git a/db/versions/10480-blueTulip/00-firstScript.sql b/db/versions/.archive/10480-blueTulip/00-firstScript.sql similarity index 100% rename from db/versions/10480-blueTulip/00-firstScript.sql rename to db/versions/.archive/10480-blueTulip/00-firstScript.sql diff --git a/db/versions/10481-brownAspidistra/00-firstScript.sql b/db/versions/.archive/10481-brownAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10481-brownAspidistra/00-firstScript.sql rename to db/versions/.archive/10481-brownAspidistra/00-firstScript.sql diff --git a/db/versions/10482-blueMastic/00-firstScript.sql b/db/versions/.archive/10482-blueMastic/00-firstScript.sql similarity index 100% rename from db/versions/10482-blueMastic/00-firstScript.sql rename to db/versions/.archive/10482-blueMastic/00-firstScript.sql diff --git a/db/versions/10485-aquaCamellia/00-firstScript.sql b/db/versions/.archive/10485-aquaCamellia/00-firstScript.sql similarity index 100% rename from db/versions/10485-aquaCamellia/00-firstScript.sql rename to db/versions/.archive/10485-aquaCamellia/00-firstScript.sql diff --git a/db/versions/10488-grayCarnation/00-firstScript.sql b/db/versions/.archive/10488-grayCarnation/00-firstScript.sql similarity index 100% rename from db/versions/10488-grayCarnation/00-firstScript.sql rename to db/versions/.archive/10488-grayCarnation/00-firstScript.sql diff --git a/db/versions/10491-orangeDracena/00-firstScript.sql b/db/versions/.archive/10491-orangeDracena/00-firstScript.sql similarity index 100% rename from db/versions/10491-orangeDracena/00-firstScript.sql rename to db/versions/.archive/10491-orangeDracena/00-firstScript.sql diff --git a/db/versions/10492-wheatIvy/00-firstScript.sql b/db/versions/.archive/10492-wheatIvy/00-firstScript.sql similarity index 100% rename from db/versions/10492-wheatIvy/00-firstScript.sql rename to db/versions/.archive/10492-wheatIvy/00-firstScript.sql diff --git a/db/versions/10493-purpleAnthurium/00-firstScript.sql b/db/versions/.archive/10493-purpleAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10493-purpleAnthurium/00-firstScript.sql rename to db/versions/.archive/10493-purpleAnthurium/00-firstScript.sql diff --git a/db/versions/10495-whiteFern/00-firstScript.sql b/db/versions/.archive/10495-whiteFern/00-firstScript.sql similarity index 100% rename from db/versions/10495-whiteFern/00-firstScript.sql rename to db/versions/.archive/10495-whiteFern/00-firstScript.sql diff --git a/db/versions/10498-redAspidistra/00-firstScript.sql b/db/versions/.archive/10498-redAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10498-redAspidistra/00-firstScript.sql rename to db/versions/.archive/10498-redAspidistra/00-firstScript.sql diff --git a/db/versions/10500-limeChrysanthemum/00-firstScript.sql b/db/versions/.archive/10500-limeChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10500-limeChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10500-limeChrysanthemum/00-firstScript.sql diff --git a/db/versions/10500-limeRaphis/00-firstScript.sql b/db/versions/.archive/10500-limeRaphis/00-firstScript.sql similarity index 100% rename from db/versions/10500-limeRaphis/00-firstScript.sql rename to db/versions/.archive/10500-limeRaphis/00-firstScript.sql diff --git a/db/versions/10501-orangeAnthurium/00-firstScript.sql b/db/versions/.archive/10501-orangeAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10501-orangeAnthurium/00-firstScript.sql rename to db/versions/.archive/10501-orangeAnthurium/00-firstScript.sql diff --git a/db/versions/10502-azureCarnation/00-firstScript.sql b/db/versions/.archive/10502-azureCarnation/00-firstScript.sql similarity index 100% rename from db/versions/10502-azureCarnation/00-firstScript.sql rename to db/versions/.archive/10502-azureCarnation/00-firstScript.sql diff --git a/db/versions/10502-yellowCordyline/00-firstScript.sql b/db/versions/.archive/10502-yellowCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10502-yellowCordyline/00-firstScript.sql rename to db/versions/.archive/10502-yellowCordyline/00-firstScript.sql diff --git a/db/versions/10504-maroonPalmetto/00-firstScript.sql b/db/versions/.archive/10504-maroonPalmetto/00-firstScript.sql similarity index 100% rename from db/versions/10504-maroonPalmetto/00-firstScript.sql rename to db/versions/.archive/10504-maroonPalmetto/00-firstScript.sql diff --git a/db/versions/10506-aquaPaniculata/01-firstScript.sql b/db/versions/.archive/10506-aquaPaniculata/01-firstScript.sql similarity index 100% rename from db/versions/10506-aquaPaniculata/01-firstScript.sql rename to db/versions/.archive/10506-aquaPaniculata/01-firstScript.sql diff --git a/db/versions/10506-aquaPaniculata/02-secondScript.sql b/db/versions/.archive/10506-aquaPaniculata/02-secondScript.sql similarity index 100% rename from db/versions/10506-aquaPaniculata/02-secondScript.sql rename to db/versions/.archive/10506-aquaPaniculata/02-secondScript.sql diff --git a/db/versions/10506-aquaPaniculata/03-thirdScript.sql b/db/versions/.archive/10506-aquaPaniculata/03-thirdScript.sql similarity index 100% rename from db/versions/10506-aquaPaniculata/03-thirdScript.sql rename to db/versions/.archive/10506-aquaPaniculata/03-thirdScript.sql diff --git a/db/versions/10506-crimsonRoebelini/00-firstScript.sql b/db/versions/.archive/10506-crimsonRoebelini/00-firstScript.sql similarity index 100% rename from db/versions/10506-crimsonRoebelini/00-firstScript.sql rename to db/versions/.archive/10506-crimsonRoebelini/00-firstScript.sql diff --git a/db/versions/10507-greenAspidistra/00-firstScript.sql b/db/versions/.archive/10507-greenAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10507-greenAspidistra/00-firstScript.sql rename to db/versions/.archive/10507-greenAspidistra/00-firstScript.sql diff --git a/db/versions/10508-maroonMonstera/00-firstScript.sql b/db/versions/.archive/10508-maroonMonstera/00-firstScript.sql similarity index 100% rename from db/versions/10508-maroonMonstera/00-firstScript.sql rename to db/versions/.archive/10508-maroonMonstera/00-firstScript.sql diff --git a/db/versions/10510-salmonMoss/00-dropBusinessFk.sql b/db/versions/.archive/10510-salmonMoss/00-dropBusinessFk.sql similarity index 100% rename from db/versions/10510-salmonMoss/00-dropBusinessFk.sql rename to db/versions/.archive/10510-salmonMoss/00-dropBusinessFk.sql diff --git a/db/versions/10510-salmonMoss/01-createTableProfessionalCategory.sql b/db/versions/.archive/10510-salmonMoss/01-createTableProfessionalCategory.sql similarity index 100% rename from db/versions/10510-salmonMoss/01-createTableProfessionalCategory.sql rename to db/versions/.archive/10510-salmonMoss/01-createTableProfessionalCategory.sql diff --git a/db/versions/10510-salmonMoss/02-exportToNewTable.sql b/db/versions/.archive/10510-salmonMoss/02-exportToNewTable.sql similarity index 100% rename from db/versions/10510-salmonMoss/02-exportToNewTable.sql rename to db/versions/.archive/10510-salmonMoss/02-exportToNewTable.sql diff --git a/db/versions/10510-salmonMoss/03-RecreateFK.sql b/db/versions/.archive/10510-salmonMoss/03-RecreateFK.sql similarity index 100% rename from db/versions/10510-salmonMoss/03-RecreateFK.sql rename to db/versions/.archive/10510-salmonMoss/03-RecreateFK.sql diff --git a/db/versions/10510-salmonMoss/04-kkPostgresqlTable.sql b/db/versions/.archive/10510-salmonMoss/04-kkPostgresqlTable.sql similarity index 100% rename from db/versions/10510-salmonMoss/04-kkPostgresqlTable.sql rename to db/versions/.archive/10510-salmonMoss/04-kkPostgresqlTable.sql diff --git a/db/versions/10511-chocolateChrysanthemum/00-firstScript.sql b/db/versions/.archive/10511-chocolateChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10511-chocolateChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10511-chocolateChrysanthemum/00-firstScript.sql diff --git a/db/versions/10512-purpleRoebelini/00-firstScript.sql b/db/versions/.archive/10512-purpleRoebelini/00-firstScript.sql similarity index 100% rename from db/versions/10512-purpleRoebelini/00-firstScript.sql rename to db/versions/.archive/10512-purpleRoebelini/00-firstScript.sql diff --git a/db/versions/10513-aquaCataractarum/00-firstScript.sql b/db/versions/.archive/10513-aquaCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10513-aquaCataractarum/00-firstScript.sql rename to db/versions/.archive/10513-aquaCataractarum/00-firstScript.sql diff --git a/db/versions/10514-silverAspidistra/00-firstScript.sql b/db/versions/.archive/10514-silverAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10514-silverAspidistra/00-firstScript.sql rename to db/versions/.archive/10514-silverAspidistra/00-firstScript.sql diff --git a/db/versions/10516-crimsonSalal/00-firstScript.sql b/db/versions/.archive/10516-crimsonSalal/00-firstScript.sql similarity index 100% rename from db/versions/10516-crimsonSalal/00-firstScript.sql rename to db/versions/.archive/10516-crimsonSalal/00-firstScript.sql diff --git a/db/versions/10521-salmonLilium/00-firstScript.sql b/db/versions/.archive/10521-salmonLilium/00-firstScript.sql similarity index 100% rename from db/versions/10521-salmonLilium/00-firstScript.sql rename to db/versions/.archive/10521-salmonLilium/00-firstScript.sql diff --git a/db/versions/10522-yellowMedeola/00-firstScript.sql b/db/versions/.archive/10522-yellowMedeola/00-firstScript.sql similarity index 100% rename from db/versions/10522-yellowMedeola/00-firstScript.sql rename to db/versions/.archive/10522-yellowMedeola/00-firstScript.sql diff --git a/db/versions/10523-tealCataractarum/00-firstScript.sql b/db/versions/.archive/10523-tealCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10523-tealCataractarum/00-firstScript.sql rename to db/versions/.archive/10523-tealCataractarum/00-firstScript.sql diff --git a/db/versions/10524-limeCordyline/00-firstScript.sql b/db/versions/.archive/10524-limeCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10524-limeCordyline/00-firstScript.sql rename to db/versions/.archive/10524-limeCordyline/00-firstScript.sql diff --git a/db/versions/10524-limeCordyline/01-rateEditorFk.sql b/db/versions/.archive/10524-limeCordyline/01-rateEditorFk.sql similarity index 100% rename from db/versions/10524-limeCordyline/01-rateEditorFk.sql rename to db/versions/.archive/10524-limeCordyline/01-rateEditorFk.sql diff --git a/db/versions/10525-yellowRuscus/00-firstScript.sql b/db/versions/.archive/10525-yellowRuscus/00-firstScript.sql similarity index 100% rename from db/versions/10525-yellowRuscus/00-firstScript.sql rename to db/versions/.archive/10525-yellowRuscus/00-firstScript.sql diff --git a/db/versions/10526-goldenOak/00-firstScript.sql b/db/versions/.archive/10526-goldenOak/00-firstScript.sql similarity index 100% rename from db/versions/10526-goldenOak/00-firstScript.sql rename to db/versions/.archive/10526-goldenOak/00-firstScript.sql diff --git a/db/versions/10528-orangeRoebelini/00-firstScript.sql b/db/versions/.archive/10528-orangeRoebelini/00-firstScript.sql similarity index 100% rename from db/versions/10528-orangeRoebelini/00-firstScript.sql rename to db/versions/.archive/10528-orangeRoebelini/00-firstScript.sql diff --git a/db/versions/10530-orangeCyca/00-firstScript.sql b/db/versions/.archive/10530-orangeCyca/00-firstScript.sql similarity index 100% rename from db/versions/10530-orangeCyca/00-firstScript.sql rename to db/versions/.archive/10530-orangeCyca/00-firstScript.sql diff --git a/db/versions/10531-chocolateFern/00-firstScript.sql b/db/versions/.archive/10531-chocolateFern/00-firstScript.sql similarity index 100% rename from db/versions/10531-chocolateFern/00-firstScript.sql rename to db/versions/.archive/10531-chocolateFern/00-firstScript.sql diff --git a/db/versions/10532-tealTulip/00-firstScript.sql b/db/versions/.archive/10532-tealTulip/00-firstScript.sql similarity index 100% rename from db/versions/10532-tealTulip/00-firstScript.sql rename to db/versions/.archive/10532-tealTulip/00-firstScript.sql diff --git a/db/versions/10533-crimsonLaurel/00-firstScript.sql b/db/versions/.archive/10533-crimsonLaurel/00-firstScript.sql similarity index 100% rename from db/versions/10533-crimsonLaurel/00-firstScript.sql rename to db/versions/.archive/10533-crimsonLaurel/00-firstScript.sql diff --git a/db/versions/10537-grayCordyline/00-firstScript.sql b/db/versions/.archive/10537-grayCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10537-grayCordyline/00-firstScript.sql rename to db/versions/.archive/10537-grayCordyline/00-firstScript.sql diff --git a/db/versions/10538-silverAspidistra/00-createChronopostConfig.sql b/db/versions/.archive/10538-silverAspidistra/00-createChronopostConfig.sql similarity index 100% rename from db/versions/10538-silverAspidistra/00-createChronopostConfig.sql rename to db/versions/.archive/10538-silverAspidistra/00-createChronopostConfig.sql diff --git a/db/versions/10538-silverAspidistra/01-createChronopostService.sql b/db/versions/.archive/10538-silverAspidistra/01-createChronopostService.sql similarity index 100% rename from db/versions/10538-silverAspidistra/01-createChronopostService.sql rename to db/versions/.archive/10538-silverAspidistra/01-createChronopostService.sql diff --git a/db/versions/10538-silverAspidistra/02-createChronopostExpedition.sql b/db/versions/.archive/10538-silverAspidistra/02-createChronopostExpedition.sql similarity index 100% rename from db/versions/10538-silverAspidistra/02-createChronopostExpedition.sql rename to db/versions/.archive/10538-silverAspidistra/02-createChronopostExpedition.sql diff --git a/db/versions/10538-silverAspidistra/03-createChronopostSenderAddress.sql b/db/versions/.archive/10538-silverAspidistra/03-createChronopostSenderAddress.sql similarity index 100% rename from db/versions/10538-silverAspidistra/03-createChronopostSenderAddress.sql rename to db/versions/.archive/10538-silverAspidistra/03-createChronopostSenderAddress.sql diff --git a/db/versions/10538-silverAspidistra/04-addgrantPrivilegies.sql b/db/versions/.archive/10538-silverAspidistra/04-addgrantPrivilegies.sql similarity index 100% rename from db/versions/10538-silverAspidistra/04-addgrantPrivilegies.sql rename to db/versions/.archive/10538-silverAspidistra/04-addgrantPrivilegies.sql diff --git a/db/versions/10538-silverAspidistra/05-updateChronopostConfig.sql b/db/versions/.archive/10538-silverAspidistra/05-updateChronopostConfig.sql similarity index 100% rename from db/versions/10538-silverAspidistra/05-updateChronopostConfig.sql rename to db/versions/.archive/10538-silverAspidistra/05-updateChronopostConfig.sql diff --git a/db/versions/10539-pinkPalmetto/00-firstScript.sql b/db/versions/.archive/10539-pinkPalmetto/00-firstScript.sql similarity index 100% rename from db/versions/10539-pinkPalmetto/00-firstScript.sql rename to db/versions/.archive/10539-pinkPalmetto/00-firstScript.sql diff --git a/db/versions/10540-bronzeOrchid/00-firstScript.sql b/db/versions/.archive/10540-bronzeOrchid/00-firstScript.sql similarity index 100% rename from db/versions/10540-bronzeOrchid/00-firstScript.sql rename to db/versions/.archive/10540-bronzeOrchid/00-firstScript.sql diff --git a/db/versions/10545-maroonDracena/00-firstScript.sql b/db/versions/.archive/10545-maroonDracena/00-firstScript.sql similarity index 100% rename from db/versions/10545-maroonDracena/00-firstScript.sql rename to db/versions/.archive/10545-maroonDracena/00-firstScript.sql diff --git a/db/versions/10546-redOak/00-firstScript.sql b/db/versions/.archive/10546-redOak/00-firstScript.sql similarity index 100% rename from db/versions/10546-redOak/00-firstScript.sql rename to db/versions/.archive/10546-redOak/00-firstScript.sql diff --git a/db/versions/10547-aquaDendro/00-firstScript.sql b/db/versions/.archive/10547-aquaDendro/00-firstScript.sql similarity index 100% rename from db/versions/10547-aquaDendro/00-firstScript.sql rename to db/versions/.archive/10547-aquaDendro/00-firstScript.sql diff --git a/db/versions/10549-goldenHydrangea/00-updateUpdateLog.sql b/db/versions/.archive/10549-goldenHydrangea/00-updateUpdateLog.sql similarity index 100% rename from db/versions/10549-goldenHydrangea/00-updateUpdateLog.sql rename to db/versions/.archive/10549-goldenHydrangea/00-updateUpdateLog.sql diff --git a/db/versions/10549-goldenHydrangea/01-updateInsertLog.sql b/db/versions/.archive/10549-goldenHydrangea/01-updateInsertLog.sql similarity index 100% rename from db/versions/10549-goldenHydrangea/01-updateInsertLog.sql rename to db/versions/.archive/10549-goldenHydrangea/01-updateInsertLog.sql diff --git a/db/versions/10549-goldenHydrangea/02-updateDeleteLog.sql b/db/versions/.archive/10549-goldenHydrangea/02-updateDeleteLog.sql similarity index 100% rename from db/versions/10549-goldenHydrangea/02-updateDeleteLog.sql rename to db/versions/.archive/10549-goldenHydrangea/02-updateDeleteLog.sql diff --git a/db/versions/10549-goldenHydrangea/03-deleteEmptyLog.sql b/db/versions/.archive/10549-goldenHydrangea/03-deleteEmptyLog.sql similarity index 100% rename from db/versions/10549-goldenHydrangea/03-deleteEmptyLog.sql rename to db/versions/.archive/10549-goldenHydrangea/03-deleteEmptyLog.sql diff --git a/db/versions/10549-goldenHydrangea/04-optimizeLogTables.sql b/db/versions/.archive/10549-goldenHydrangea/04-optimizeLogTables.sql similarity index 100% rename from db/versions/10549-goldenHydrangea/04-optimizeLogTables.sql rename to db/versions/.archive/10549-goldenHydrangea/04-optimizeLogTables.sql diff --git a/db/versions/10550-grayMonstera/00-editorFk.sql b/db/versions/.archive/10550-grayMonstera/00-editorFk.sql similarity index 100% rename from db/versions/10550-grayMonstera/00-editorFk.sql rename to db/versions/.archive/10550-grayMonstera/00-editorFk.sql diff --git a/db/versions/10550-grayMonstera/01-originFk.sql b/db/versions/.archive/10550-grayMonstera/01-originFk.sql similarity index 100% rename from db/versions/10550-grayMonstera/01-originFk.sql rename to db/versions/.archive/10550-grayMonstera/01-originFk.sql diff --git a/db/versions/10552-blackAnthurium/00-firstScript.sql b/db/versions/.archive/10552-blackAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10552-blackAnthurium/00-firstScript.sql rename to db/versions/.archive/10552-blackAnthurium/00-firstScript.sql diff --git a/db/versions/10554-maroonFern/00-firstScript.sql b/db/versions/.archive/10554-maroonFern/00-firstScript.sql similarity index 100% rename from db/versions/10554-maroonFern/00-firstScript.sql rename to db/versions/.archive/10554-maroonFern/00-firstScript.sql diff --git a/db/versions/10557-whiteCordyline/00-firstScript.sql b/db/versions/.archive/10557-whiteCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10557-whiteCordyline/00-firstScript.sql rename to db/versions/.archive/10557-whiteCordyline/00-firstScript.sql diff --git a/db/versions/10559-brownDracena/00-firstScript.sql b/db/versions/.archive/10559-brownDracena/00-firstScript.sql similarity index 100% rename from db/versions/10559-brownDracena/00-firstScript.sql rename to db/versions/.archive/10559-brownDracena/00-firstScript.sql diff --git a/db/versions/10560-crimsonCataractarum/00-firstScript.sql b/db/versions/.archive/10560-crimsonCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10560-crimsonCataractarum/00-firstScript.sql rename to db/versions/.archive/10560-crimsonCataractarum/00-firstScript.sql diff --git a/db/versions/10562-whiteDendro/00-firstScript.sql b/db/versions/.archive/10562-whiteDendro/00-firstScript.sql similarity index 100% rename from db/versions/10562-whiteDendro/00-firstScript.sql rename to db/versions/.archive/10562-whiteDendro/00-firstScript.sql diff --git a/db/versions/10563-azureMonstera/00-delivery_ticketFk.sql b/db/versions/.archive/10563-azureMonstera/00-delivery_ticketFk.sql similarity index 100% rename from db/versions/10563-azureMonstera/00-delivery_ticketFk.sql rename to db/versions/.archive/10563-azureMonstera/00-delivery_ticketFk.sql diff --git a/db/versions/10566-azureArborvitae/00-firstScript.sql b/db/versions/.archive/10566-azureArborvitae/00-firstScript.sql similarity index 100% rename from db/versions/10566-azureArborvitae/00-firstScript.sql rename to db/versions/.archive/10566-azureArborvitae/00-firstScript.sql diff --git a/db/versions/10567-salmonAspidistra/00-firstScript.sql b/db/versions/.archive/10567-salmonAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10567-salmonAspidistra/00-firstScript.sql rename to db/versions/.archive/10567-salmonAspidistra/00-firstScript.sql diff --git a/db/versions/10568-grayAnthurium/00-firstScript.sql b/db/versions/.archive/10568-grayAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10568-grayAnthurium/00-firstScript.sql rename to db/versions/.archive/10568-grayAnthurium/00-firstScript.sql diff --git a/db/versions/10569-salmonLaurel/00-firstScript.sql b/db/versions/.archive/10569-salmonLaurel/00-firstScript.sql similarity index 100% rename from db/versions/10569-salmonLaurel/00-firstScript.sql rename to db/versions/.archive/10569-salmonLaurel/00-firstScript.sql diff --git a/db/versions/10570-goldenTulip/00-createSendingConfig.sql b/db/versions/.archive/10570-goldenTulip/00-createSendingConfig.sql similarity index 100% rename from db/versions/10570-goldenTulip/00-createSendingConfig.sql rename to db/versions/.archive/10570-goldenTulip/00-createSendingConfig.sql diff --git a/db/versions/10570-goldenTulip/01-createSendingServiceWeekday.sql b/db/versions/.archive/10570-goldenTulip/01-createSendingServiceWeekday.sql similarity index 100% rename from db/versions/10570-goldenTulip/01-createSendingServiceWeekday.sql rename to db/versions/.archive/10570-goldenTulip/01-createSendingServiceWeekday.sql diff --git a/db/versions/10570-goldenTulip/02-createSendingService.sql b/db/versions/.archive/10570-goldenTulip/02-createSendingService.sql similarity index 100% rename from db/versions/10570-goldenTulip/02-createSendingService.sql rename to db/versions/.archive/10570-goldenTulip/02-createSendingService.sql diff --git a/db/versions/10570-goldenTulip/03-permisos.sql b/db/versions/.archive/10570-goldenTulip/03-permisos.sql similarity index 100% rename from db/versions/10570-goldenTulip/03-permisos.sql rename to db/versions/.archive/10570-goldenTulip/03-permisos.sql diff --git a/db/versions/10571-navyCyca/00-firstScript.sql b/db/versions/.archive/10571-navyCyca/00-firstScript.sql similarity index 100% rename from db/versions/10571-navyCyca/00-firstScript.sql rename to db/versions/.archive/10571-navyCyca/00-firstScript.sql diff --git a/db/versions/10573-tealChico/00-firstScript.sql b/db/versions/.archive/10573-tealChico/00-firstScript.sql similarity index 100% rename from db/versions/10573-tealChico/00-firstScript.sql rename to db/versions/.archive/10573-tealChico/00-firstScript.sql diff --git a/db/versions/10575-crimsonAnthurium/00-firstScript.sql b/db/versions/.archive/10575-crimsonAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10575-crimsonAnthurium/00-firstScript.sql rename to db/versions/.archive/10575-crimsonAnthurium/00-firstScript.sql diff --git a/db/versions/10577-salmonMonstera/00-firstScript.sql b/db/versions/.archive/10577-salmonMonstera/00-firstScript.sql similarity index 100% rename from db/versions/10577-salmonMonstera/00-firstScript.sql rename to db/versions/.archive/10577-salmonMonstera/00-firstScript.sql diff --git a/db/versions/10578-brownCarnation/00-firstScript.sql b/db/versions/.archive/10578-brownCarnation/00-firstScript.sql similarity index 100% rename from db/versions/10578-brownCarnation/00-firstScript.sql rename to db/versions/.archive/10578-brownCarnation/00-firstScript.sql diff --git a/db/versions/10579-aquaRoebelini/00-firstScript.sql b/db/versions/.archive/10579-aquaRoebelini/00-firstScript.sql similarity index 100% rename from db/versions/10579-aquaRoebelini/00-firstScript.sql rename to db/versions/.archive/10579-aquaRoebelini/00-firstScript.sql diff --git a/db/versions/10580-purpleCataractarum/00-itemTypeDropConstraint.sql b/db/versions/.archive/10580-purpleCataractarum/00-itemTypeDropConstraint.sql similarity index 100% rename from db/versions/10580-purpleCataractarum/00-itemTypeDropConstraint.sql rename to db/versions/.archive/10580-purpleCataractarum/00-itemTypeDropConstraint.sql diff --git a/db/versions/10580-purpleCataractarum/01-itemTypeAddConstraint.sql b/db/versions/.archive/10580-purpleCataractarum/01-itemTypeAddConstraint.sql similarity index 100% rename from db/versions/10580-purpleCataractarum/01-itemTypeAddConstraint.sql rename to db/versions/.archive/10580-purpleCataractarum/01-itemTypeAddConstraint.sql diff --git a/db/versions/10581-grayPaniculata/00-itemTypeAutoIncrement.sql b/db/versions/.archive/10581-grayPaniculata/00-itemTypeAutoIncrement.sql similarity index 100% rename from db/versions/10581-grayPaniculata/00-itemTypeAutoIncrement.sql rename to db/versions/.archive/10581-grayPaniculata/00-itemTypeAutoIncrement.sql diff --git a/db/versions/10582-purpleOrchid/00-firstScript.sql b/db/versions/.archive/10582-purpleOrchid/00-firstScript.sql similarity index 100% rename from db/versions/10582-purpleOrchid/00-firstScript.sql rename to db/versions/.archive/10582-purpleOrchid/00-firstScript.sql diff --git a/db/versions/10583-turquoiseGerbera/00-firstScript.sql b/db/versions/.archive/10583-turquoiseGerbera/00-firstScript.sql similarity index 100% rename from db/versions/10583-turquoiseGerbera/00-firstScript.sql rename to db/versions/.archive/10583-turquoiseGerbera/00-firstScript.sql diff --git a/db/versions/10584-azureGerbera/00-firstScript.sql b/db/versions/.archive/10584-azureGerbera/00-firstScript.sql similarity index 100% rename from db/versions/10584-azureGerbera/00-firstScript.sql rename to db/versions/.archive/10584-azureGerbera/00-firstScript.sql diff --git a/db/versions/10585-pinkMedeola/00-ticketLog.sql b/db/versions/.archive/10585-pinkMedeola/00-ticketLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/00-ticketLog.sql rename to db/versions/.archive/10585-pinkMedeola/00-ticketLog.sql diff --git a/db/versions/10585-pinkMedeola/01-entryLog.sql b/db/versions/.archive/10585-pinkMedeola/01-entryLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/01-entryLog.sql rename to db/versions/.archive/10585-pinkMedeola/01-entryLog.sql diff --git a/db/versions/10585-pinkMedeola/02-claimLog.sql b/db/versions/.archive/10585-pinkMedeola/02-claimLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/02-claimLog.sql rename to db/versions/.archive/10585-pinkMedeola/02-claimLog.sql diff --git a/db/versions/10585-pinkMedeola/03-clientLog.sql b/db/versions/.archive/10585-pinkMedeola/03-clientLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/03-clientLog.sql rename to db/versions/.archive/10585-pinkMedeola/03-clientLog.sql diff --git a/db/versions/10585-pinkMedeola/04-invoiceInLog.sql b/db/versions/.archive/10585-pinkMedeola/04-invoiceInLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/04-invoiceInLog.sql rename to db/versions/.archive/10585-pinkMedeola/04-invoiceInLog.sql diff --git a/db/versions/10585-pinkMedeola/05-itemLog.sql b/db/versions/.archive/10585-pinkMedeola/05-itemLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/05-itemLog.sql rename to db/versions/.archive/10585-pinkMedeola/05-itemLog.sql diff --git a/db/versions/10585-pinkMedeola/06-routeLog.sql b/db/versions/.archive/10585-pinkMedeola/06-routeLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/06-routeLog.sql rename to db/versions/.archive/10585-pinkMedeola/06-routeLog.sql diff --git a/db/versions/10585-pinkMedeola/07-shelvingLog.sql b/db/versions/.archive/10585-pinkMedeola/07-shelvingLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/07-shelvingLog.sql rename to db/versions/.archive/10585-pinkMedeola/07-shelvingLog.sql diff --git a/db/versions/10585-pinkMedeola/08-supplierLog.sql b/db/versions/.archive/10585-pinkMedeola/08-supplierLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/08-supplierLog.sql rename to db/versions/.archive/10585-pinkMedeola/08-supplierLog.sql diff --git a/db/versions/10585-pinkMedeola/09-travelLog.sql b/db/versions/.archive/10585-pinkMedeola/09-travelLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/09-travelLog.sql rename to db/versions/.archive/10585-pinkMedeola/09-travelLog.sql diff --git a/db/versions/10585-pinkMedeola/10-workerLog.sql b/db/versions/.archive/10585-pinkMedeola/10-workerLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/10-workerLog.sql rename to db/versions/.archive/10585-pinkMedeola/10-workerLog.sql diff --git a/db/versions/10585-pinkMedeola/11-zoneLog.sql b/db/versions/.archive/10585-pinkMedeola/11-zoneLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/11-zoneLog.sql rename to db/versions/.archive/10585-pinkMedeola/11-zoneLog.sql diff --git a/db/versions/10585-pinkMedeola/12-userLog.sql b/db/versions/.archive/10585-pinkMedeola/12-userLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/12-userLog.sql rename to db/versions/.archive/10585-pinkMedeola/12-userLog.sql diff --git a/db/versions/10585-pinkMedeola/13-roleLog.sql b/db/versions/.archive/10585-pinkMedeola/13-roleLog.sql similarity index 100% rename from db/versions/10585-pinkMedeola/13-roleLog.sql rename to db/versions/.archive/10585-pinkMedeola/13-roleLog.sql diff --git a/db/versions/10587-navyOak/00-arcRead_addMinimum.sql b/db/versions/.archive/10587-navyOak/00-arcRead_addMinimum.sql similarity index 100% rename from db/versions/10587-navyOak/00-arcRead_addMinimum.sql rename to db/versions/.archive/10587-navyOak/00-arcRead_addMinimum.sql diff --git a/db/versions/10593-greenLilium/00-firstScript.sql b/db/versions/.archive/10593-greenLilium/00-firstScript.sql similarity index 100% rename from db/versions/10593-greenLilium/00-firstScript.sql rename to db/versions/.archive/10593-greenLilium/00-firstScript.sql diff --git a/db/versions/10596-purpleCamellia/00-firstScript.sql b/db/versions/.archive/10596-purpleCamellia/00-firstScript.sql similarity index 100% rename from db/versions/10596-purpleCamellia/00-firstScript.sql rename to db/versions/.archive/10596-purpleCamellia/00-firstScript.sql diff --git a/db/versions/10597-navyAralia/00-firstScript.sql b/db/versions/.archive/10597-navyAralia/00-firstScript.sql similarity index 100% rename from db/versions/10597-navyAralia/00-firstScript.sql rename to db/versions/.archive/10597-navyAralia/00-firstScript.sql diff --git a/db/versions/10598-purpleGalax/00-workerLog.sql b/db/versions/.archive/10598-purpleGalax/00-workerLog.sql similarity index 100% rename from db/versions/10598-purpleGalax/00-workerLog.sql rename to db/versions/.archive/10598-purpleGalax/00-workerLog.sql diff --git a/db/versions/10598-purpleGalax/01-supplierLog.sql b/db/versions/.archive/10598-purpleGalax/01-supplierLog.sql similarity index 100% rename from db/versions/10598-purpleGalax/01-supplierLog.sql rename to db/versions/.archive/10598-purpleGalax/01-supplierLog.sql diff --git a/db/versions/10598-purpleGalax/02-workerTimeControlLog.sql b/db/versions/.archive/10598-purpleGalax/02-workerTimeControlLog.sql similarity index 100% rename from db/versions/10598-purpleGalax/02-workerTimeControlLog.sql rename to db/versions/.archive/10598-purpleGalax/02-workerTimeControlLog.sql diff --git a/db/versions/10598-purpleGalax/03-workerClockLog.sql b/db/versions/.archive/10598-purpleGalax/03-workerClockLog.sql similarity index 100% rename from db/versions/10598-purpleGalax/03-workerClockLog.sql rename to db/versions/.archive/10598-purpleGalax/03-workerClockLog.sql diff --git a/db/versions/10599-orangeHydrangea/00-firstScript.sql b/db/versions/.archive/10599-orangeHydrangea/00-firstScript.sql similarity index 100% rename from db/versions/10599-orangeHydrangea/00-firstScript.sql rename to db/versions/.archive/10599-orangeHydrangea/00-firstScript.sql diff --git a/db/versions/10601-orangeErica/00-firstScript.sql b/db/versions/.archive/10601-orangeErica/00-firstScript.sql similarity index 100% rename from db/versions/10601-orangeErica/00-firstScript.sql rename to db/versions/.archive/10601-orangeErica/00-firstScript.sql diff --git a/db/versions/10602-whiteArborvitae/00-firstScript.sql b/db/versions/.archive/10602-whiteArborvitae/00-firstScript.sql similarity index 100% rename from db/versions/10602-whiteArborvitae/00-firstScript.sql rename to db/versions/.archive/10602-whiteArborvitae/00-firstScript.sql diff --git a/db/versions/10606-pinkChico/00-firstScript.sql b/db/versions/.archive/10606-pinkChico/00-firstScript.sql similarity index 100% rename from db/versions/10606-pinkChico/00-firstScript.sql rename to db/versions/.archive/10606-pinkChico/00-firstScript.sql diff --git a/db/versions/10608-pinkAsparagus/00-firstScript.sql b/db/versions/.archive/10608-pinkAsparagus/00-firstScript.sql similarity index 100% rename from db/versions/10608-pinkAsparagus/00-firstScript.sql rename to db/versions/.archive/10608-pinkAsparagus/00-firstScript.sql diff --git a/db/versions/10609-grayRaphis/00-firstScript.sql b/db/versions/.archive/10609-grayRaphis/00-firstScript.sql similarity index 100% rename from db/versions/10609-grayRaphis/00-firstScript.sql rename to db/versions/.archive/10609-grayRaphis/00-firstScript.sql diff --git a/db/versions/10610-goldenArborvitae/00-updateCompanyId.sql b/db/versions/.archive/10610-goldenArborvitae/00-updateCompanyId.sql similarity index 100% rename from db/versions/10610-goldenArborvitae/00-updateCompanyId.sql rename to db/versions/.archive/10610-goldenArborvitae/00-updateCompanyId.sql diff --git a/db/versions/10610-goldenArborvitae/01-updateSupplierId.sql b/db/versions/.archive/10610-goldenArborvitae/01-updateSupplierId.sql similarity index 100% rename from db/versions/10610-goldenArborvitae/01-updateSupplierId.sql rename to db/versions/.archive/10610-goldenArborvitae/01-updateSupplierId.sql diff --git a/db/versions/10610-goldenArborvitae/02-invoiceOutCompany.sql b/db/versions/.archive/10610-goldenArborvitae/02-invoiceOutCompany.sql similarity index 100% rename from db/versions/10610-goldenArborvitae/02-invoiceOutCompany.sql rename to db/versions/.archive/10610-goldenArborvitae/02-invoiceOutCompany.sql diff --git a/db/versions/10611-blueGerbera/00-firstScript.sql b/db/versions/.archive/10611-blueGerbera/00-firstScript.sql similarity index 100% rename from db/versions/10611-blueGerbera/00-firstScript.sql rename to db/versions/.archive/10611-blueGerbera/00-firstScript.sql diff --git a/db/versions/10613-purpleAspidistra/00-firstScript.sql b/db/versions/.archive/10613-purpleAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10613-purpleAspidistra/00-firstScript.sql rename to db/versions/.archive/10613-purpleAspidistra/00-firstScript.sql diff --git a/db/versions/10614-chocolateGalax/00-firstScript.sql b/db/versions/.archive/10614-chocolateGalax/00-firstScript.sql similarity index 100% rename from db/versions/10614-chocolateGalax/00-firstScript.sql rename to db/versions/.archive/10614-chocolateGalax/00-firstScript.sql diff --git a/db/versions/10615-azureCataractarum/00-firstScript.sql b/db/versions/.archive/10615-azureCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10615-azureCataractarum/00-firstScript.sql rename to db/versions/.archive/10615-azureCataractarum/00-firstScript.sql diff --git a/db/versions/10616-yellowIvy/00-firstScript.sql b/db/versions/.archive/10616-yellowIvy/00-firstScript.sql similarity index 100% rename from db/versions/10616-yellowIvy/00-firstScript.sql rename to db/versions/.archive/10616-yellowIvy/00-firstScript.sql diff --git a/db/versions/10616-yellowIvy/01-firstScript.sql b/db/versions/.archive/10616-yellowIvy/01-firstScript.sql similarity index 100% rename from db/versions/10616-yellowIvy/01-firstScript.sql rename to db/versions/.archive/10616-yellowIvy/01-firstScript.sql diff --git a/db/versions/10617-aquaAralia/00-firstScript.sql b/db/versions/.archive/10617-aquaAralia/00-firstScript.sql similarity index 100% rename from db/versions/10617-aquaAralia/00-firstScript.sql rename to db/versions/.archive/10617-aquaAralia/00-firstScript.sql diff --git a/db/versions/10618-whiteArborvitae/00-firstScript.sql b/db/versions/.archive/10618-whiteArborvitae/00-firstScript.sql similarity index 100% rename from db/versions/10618-whiteArborvitae/00-firstScript.sql rename to db/versions/.archive/10618-whiteArborvitae/00-firstScript.sql diff --git a/db/versions/10619-chocolateErica/00-firstScript.sql b/db/versions/.archive/10619-chocolateErica/00-firstScript.sql similarity index 100% rename from db/versions/10619-chocolateErica/00-firstScript.sql rename to db/versions/.archive/10619-chocolateErica/00-firstScript.sql diff --git a/db/versions/10620-azurePalmetto/00-firstScript.sql b/db/versions/.archive/10620-azurePalmetto/00-firstScript.sql similarity index 100% rename from db/versions/10620-azurePalmetto/00-firstScript.sql rename to db/versions/.archive/10620-azurePalmetto/00-firstScript.sql diff --git a/db/versions/10624-blueAnthurium/00-firstScript.sql b/db/versions/.archive/10624-blueAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10624-blueAnthurium/00-firstScript.sql rename to db/versions/.archive/10624-blueAnthurium/00-firstScript.sql diff --git a/db/versions/10625-whiteOak/00-firstScript.sql b/db/versions/.archive/10625-whiteOak/00-firstScript.sql similarity index 100% rename from db/versions/10625-whiteOak/00-firstScript.sql rename to db/versions/.archive/10625-whiteOak/00-firstScript.sql diff --git a/db/versions/10626-silverRaphis/00-firstScript.sql b/db/versions/.archive/10626-silverRaphis/00-firstScript.sql similarity index 100% rename from db/versions/10626-silverRaphis/00-firstScript.sql rename to db/versions/.archive/10626-silverRaphis/00-firstScript.sql diff --git a/db/versions/10628-grayOrchid/00-firstScript.sql b/db/versions/.archive/10628-grayOrchid/00-firstScript.sql similarity index 100% rename from db/versions/10628-grayOrchid/00-firstScript.sql rename to db/versions/.archive/10628-grayOrchid/00-firstScript.sql diff --git a/db/versions/10630-brownMastic/00-firstScript.sql b/db/versions/.archive/10630-brownMastic/00-firstScript.sql similarity index 100% rename from db/versions/10630-brownMastic/00-firstScript.sql rename to db/versions/.archive/10630-brownMastic/00-firstScript.sql diff --git a/db/versions/10631-yellowBamboo/00-firstScript.sql b/db/versions/.archive/10631-yellowBamboo/00-firstScript.sql similarity index 100% rename from db/versions/10631-yellowBamboo/00-firstScript.sql rename to db/versions/.archive/10631-yellowBamboo/00-firstScript.sql diff --git a/db/versions/10632-wheatPaniculata/00-firstScript.sql b/db/versions/.archive/10632-wheatPaniculata/00-firstScript.sql similarity index 100% rename from db/versions/10632-wheatPaniculata/00-firstScript.sql rename to db/versions/.archive/10632-wheatPaniculata/00-firstScript.sql diff --git a/db/versions/10633-orangeArborvitae/00-firstScript.sql b/db/versions/.archive/10633-orangeArborvitae/00-firstScript.sql similarity index 100% rename from db/versions/10633-orangeArborvitae/00-firstScript.sql rename to db/versions/.archive/10633-orangeArborvitae/00-firstScript.sql diff --git a/db/versions/10634-pinkCymbidium/00-firstScript.sql b/db/versions/.archive/10634-pinkCymbidium/00-firstScript.sql similarity index 100% rename from db/versions/10634-pinkCymbidium/00-firstScript.sql rename to db/versions/.archive/10634-pinkCymbidium/00-firstScript.sql diff --git a/db/versions/10637-yellowAspidistra/00-firstScript.sql b/db/versions/.archive/10637-yellowAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10637-yellowAspidistra/00-firstScript.sql rename to db/versions/.archive/10637-yellowAspidistra/00-firstScript.sql diff --git a/db/versions/10640-redPalmetto/00-companyFkDrop.sql b/db/versions/.archive/10640-redPalmetto/00-companyFkDrop.sql similarity index 100% rename from db/versions/10640-redPalmetto/00-companyFkDrop.sql rename to db/versions/.archive/10640-redPalmetto/00-companyFkDrop.sql diff --git a/db/versions/10640-redPalmetto/01-companyFkAi.sql b/db/versions/.archive/10640-redPalmetto/01-companyFkAi.sql similarity index 100% rename from db/versions/10640-redPalmetto/01-companyFkAi.sql rename to db/versions/.archive/10640-redPalmetto/01-companyFkAi.sql diff --git a/db/versions/10640-redPalmetto/02-companyFkCreate.sql b/db/versions/.archive/10640-redPalmetto/02-companyFkCreate.sql similarity index 100% rename from db/versions/10640-redPalmetto/02-companyFkCreate.sql rename to db/versions/.archive/10640-redPalmetto/02-companyFkCreate.sql diff --git a/db/versions/10640-redPalmetto/04-supplierFkDrop.sql b/db/versions/.archive/10640-redPalmetto/04-supplierFkDrop.sql similarity index 100% rename from db/versions/10640-redPalmetto/04-supplierFkDrop.sql rename to db/versions/.archive/10640-redPalmetto/04-supplierFkDrop.sql diff --git a/db/versions/10640-redPalmetto/05-supplierFkAi.sql b/db/versions/.archive/10640-redPalmetto/05-supplierFkAi.sql similarity index 100% rename from db/versions/10640-redPalmetto/05-supplierFkAi.sql rename to db/versions/.archive/10640-redPalmetto/05-supplierFkAi.sql diff --git a/db/versions/10640-redPalmetto/06-supplierFkCreate.sql b/db/versions/.archive/10640-redPalmetto/06-supplierFkCreate.sql similarity index 100% rename from db/versions/10640-redPalmetto/06-supplierFkCreate.sql rename to db/versions/.archive/10640-redPalmetto/06-supplierFkCreate.sql diff --git a/db/versions/10642-crimsonAspidistra/00-firstScript.sql b/db/versions/.archive/10642-crimsonAspidistra/00-firstScript.sql similarity index 100% rename from db/versions/10642-crimsonAspidistra/00-firstScript.sql rename to db/versions/.archive/10642-crimsonAspidistra/00-firstScript.sql diff --git a/db/versions/10643-blueCataractarum/00-firstScript.sql b/db/versions/.archive/10643-blueCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10643-blueCataractarum/00-firstScript.sql rename to db/versions/.archive/10643-blueCataractarum/00-firstScript.sql diff --git a/db/versions/10644-aquaLaurel/00-firstScript.sql b/db/versions/.archive/10644-aquaLaurel/00-firstScript.sql similarity index 100% rename from db/versions/10644-aquaLaurel/00-firstScript.sql rename to db/versions/.archive/10644-aquaLaurel/00-firstScript.sql diff --git a/db/versions/10645-purplePalmetto/00-addNewFields.sql b/db/versions/.archive/10645-purplePalmetto/00-addNewFields.sql similarity index 100% rename from db/versions/10645-purplePalmetto/00-addNewFields.sql rename to db/versions/.archive/10645-purplePalmetto/00-addNewFields.sql diff --git a/db/versions/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql b/db/versions/.archive/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql similarity index 100% rename from db/versions/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql rename to db/versions/.archive/10645-purplePalmetto/01-updateCollectionWagonPrimaryKey.sql diff --git a/db/versions/10645-purplePalmetto/02-updateWagonPrimaryKey.sql b/db/versions/.archive/10645-purplePalmetto/02-updateWagonPrimaryKey.sql similarity index 100% rename from db/versions/10645-purplePalmetto/02-updateWagonPrimaryKey.sql rename to db/versions/.archive/10645-purplePalmetto/02-updateWagonPrimaryKey.sql diff --git a/db/versions/10645-purplePalmetto/03-addFieldToPackingSite.sql b/db/versions/.archive/10645-purplePalmetto/03-addFieldToPackingSite.sql similarity index 100% rename from db/versions/10645-purplePalmetto/03-addFieldToPackingSite.sql rename to db/versions/.archive/10645-purplePalmetto/03-addFieldToPackingSite.sql diff --git a/db/versions/10647-goldenBamboo/00-renombrarTabla.sql b/db/versions/.archive/10647-goldenBamboo/00-renombrarTabla.sql similarity index 100% rename from db/versions/10647-goldenBamboo/00-renombrarTabla.sql rename to db/versions/.archive/10647-goldenBamboo/00-renombrarTabla.sql diff --git a/db/versions/10648-blackBirch/00-firstScript.sql b/db/versions/.archive/10648-blackBirch/00-firstScript.sql similarity index 100% rename from db/versions/10648-blackBirch/00-firstScript.sql rename to db/versions/.archive/10648-blackBirch/00-firstScript.sql diff --git a/db/versions/10649-yellowAsparagus/00-firstScript.sql b/db/versions/.archive/10649-yellowAsparagus/00-firstScript.sql similarity index 100% rename from db/versions/10649-yellowAsparagus/00-firstScript.sql rename to db/versions/.archive/10649-yellowAsparagus/00-firstScript.sql diff --git a/db/versions/10651-chocolatePalmetto/00-comparativeCountryFk.sql b/db/versions/.archive/10651-chocolatePalmetto/00-comparativeCountryFk.sql similarity index 100% rename from db/versions/10651-chocolatePalmetto/00-comparativeCountryFk.sql rename to db/versions/.archive/10651-chocolatePalmetto/00-comparativeCountryFk.sql diff --git a/db/versions/10651-chocolatePalmetto/01-comparativeAddConfig.sql b/db/versions/.archive/10651-chocolatePalmetto/01-comparativeAddConfig.sql similarity index 100% rename from db/versions/10651-chocolatePalmetto/01-comparativeAddConfig.sql rename to db/versions/.archive/10651-chocolatePalmetto/01-comparativeAddConfig.sql diff --git a/db/versions/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql b/db/versions/.archive/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql similarity index 100% rename from db/versions/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql rename to db/versions/.archive/10651-chocolatePalmetto/02-nightTaskAddNewTask.sql diff --git a/db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql b/db/versions/.archive/10651-chocolatePalmetto/03-grantProc.vn.sql similarity index 79% rename from db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql rename to db/versions/.archive/10651-chocolatePalmetto/03-grantProc.vn.sql index 151d1a24b..f6118b993 100644 --- a/db/versions/10651-chocolatePalmetto/03-grantProc.vn.sql +++ b/db/versions/.archive/10651-chocolatePalmetto/03-grantProc.vn.sql @@ -1,2 +1,2 @@ GRANT EXECUTE ON PROCEDURE vn.item_comparative TO claimManager, buyer; -FLUSH PRIVILEGES; +FLUSH PRIVILEGES; \ No newline at end of file diff --git a/db/versions/10652-maroonPhormium/00-firstScript.sql b/db/versions/.archive/10652-maroonPhormium/00-firstScript.sql similarity index 100% rename from db/versions/10652-maroonPhormium/00-firstScript.sql rename to db/versions/.archive/10652-maroonPhormium/00-firstScript.sql diff --git a/db/versions/10653-redHydrangea/00-firstScript.sql b/db/versions/.archive/10653-redHydrangea/00-firstScript.sql similarity index 100% rename from db/versions/10653-redHydrangea/00-firstScript.sql rename to db/versions/.archive/10653-redHydrangea/00-firstScript.sql diff --git a/db/versions/10655-navyRuscus/00-firstScript.sql b/db/versions/.archive/10655-navyRuscus/00-firstScript.sql similarity index 100% rename from db/versions/10655-navyRuscus/00-firstScript.sql rename to db/versions/.archive/10655-navyRuscus/00-firstScript.sql diff --git a/db/versions/10656-navyMastic/00-firstScript.sql b/db/versions/.archive/10656-navyMastic/00-firstScript.sql similarity index 100% rename from db/versions/10656-navyMastic/00-firstScript.sql rename to db/versions/.archive/10656-navyMastic/00-firstScript.sql diff --git a/db/versions/10657-redDracena/00-renameErrorProduction.sql b/db/versions/.archive/10657-redDracena/00-renameErrorProduction.sql similarity index 100% rename from db/versions/10657-redDracena/00-renameErrorProduction.sql rename to db/versions/.archive/10657-redDracena/00-renameErrorProduction.sql diff --git a/db/versions/10657-redDracena/01-changeNightTask.sql b/db/versions/.archive/10657-redDracena/01-changeNightTask.sql similarity index 100% rename from db/versions/10657-redDracena/01-changeNightTask.sql rename to db/versions/.archive/10657-redDracena/01-changeNightTask.sql diff --git a/db/versions/10657-redDracena/02-addCodeToClaimResponsible.sql b/db/versions/.archive/10657-redDracena/02-addCodeToClaimResponsible.sql similarity index 100% rename from db/versions/10657-redDracena/02-addCodeToClaimResponsible.sql rename to db/versions/.archive/10657-redDracena/02-addCodeToClaimResponsible.sql diff --git a/db/versions/10657-redDracena/03-grantSelectGrafana.sql b/db/versions/.archive/10657-redDracena/03-grantSelectGrafana.sql similarity index 100% rename from db/versions/10657-redDracena/03-grantSelectGrafana.sql rename to db/versions/.archive/10657-redDracena/03-grantSelectGrafana.sql diff --git a/db/versions/10658-whiteDracena/00-firstScript.sql b/db/versions/.archive/10658-whiteDracena/00-firstScript.sql similarity index 100% rename from db/versions/10658-whiteDracena/00-firstScript.sql rename to db/versions/.archive/10658-whiteDracena/00-firstScript.sql diff --git a/db/versions/10659-azureDracena/00-firstScript.sql b/db/versions/.archive/10659-azureDracena/00-firstScript.sql similarity index 100% rename from db/versions/10659-azureDracena/00-firstScript.sql rename to db/versions/.archive/10659-azureDracena/00-firstScript.sql diff --git a/db/versions/10661-crimsonIvy/00-firstScript.sql b/db/versions/.archive/10661-crimsonIvy/00-firstScript.sql similarity index 100% rename from db/versions/10661-crimsonIvy/00-firstScript.sql rename to db/versions/.archive/10661-crimsonIvy/00-firstScript.sql diff --git a/db/versions/10662-wheatErica/00-firstScript.sql b/db/versions/.archive/10662-wheatErica/00-firstScript.sql similarity index 100% rename from db/versions/10662-wheatErica/00-firstScript.sql rename to db/versions/.archive/10662-wheatErica/00-firstScript.sql diff --git a/db/versions/10663-tealCymbidium/00-firstScript.sql b/db/versions/.archive/10663-tealCymbidium/00-firstScript.sql similarity index 100% rename from db/versions/10663-tealCymbidium/00-firstScript.sql rename to db/versions/.archive/10663-tealCymbidium/00-firstScript.sql diff --git a/db/versions/10665-maroonSalal/00-firstScript.sql b/db/versions/.archive/10665-maroonSalal/00-firstScript.sql similarity index 100% rename from db/versions/10665-maroonSalal/00-firstScript.sql rename to db/versions/.archive/10665-maroonSalal/00-firstScript.sql diff --git a/db/versions/10666-limeGerbera/00-firstScript.sql b/db/versions/.archive/10666-limeGerbera/00-firstScript.sql similarity index 100% rename from db/versions/10666-limeGerbera/00-firstScript.sql rename to db/versions/.archive/10666-limeGerbera/00-firstScript.sql diff --git a/db/versions/10667-blackChrysanthemum/00-firstScript.sql b/db/versions/.archive/10667-blackChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10667-blackChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10667-blackChrysanthemum/00-firstScript.sql diff --git a/db/versions/10668-tealBirch/00-firstScript.sql b/db/versions/.archive/10668-tealBirch/00-firstScript.sql similarity index 100% rename from db/versions/10668-tealBirch/00-firstScript.sql rename to db/versions/.archive/10668-tealBirch/00-firstScript.sql diff --git a/db/versions/10671-maroonIvy/00-firstScript.sql b/db/versions/.archive/10671-maroonIvy/00-firstScript.sql similarity index 100% rename from db/versions/10671-maroonIvy/00-firstScript.sql rename to db/versions/.archive/10671-maroonIvy/00-firstScript.sql diff --git a/db/versions/10675-grayRuscus/00-firstScript.sql b/db/versions/.archive/10675-grayRuscus/00-firstScript.sql similarity index 100% rename from db/versions/10675-grayRuscus/00-firstScript.sql rename to db/versions/.archive/10675-grayRuscus/00-firstScript.sql diff --git a/db/versions/10676-aquaTulip/00-firstScript.sql b/db/versions/.archive/10676-aquaTulip/00-firstScript.sql similarity index 100% rename from db/versions/10676-aquaTulip/00-firstScript.sql rename to db/versions/.archive/10676-aquaTulip/00-firstScript.sql diff --git a/db/versions/10677-yellowMoss/00-firstScript.sql b/db/versions/.archive/10677-yellowMoss/00-firstScript.sql similarity index 100% rename from db/versions/10677-yellowMoss/00-firstScript.sql rename to db/versions/.archive/10677-yellowMoss/00-firstScript.sql diff --git a/db/versions/10678-orangeMedeola/00-firstScript.sql b/db/versions/.archive/10678-orangeMedeola/00-firstScript.sql similarity index 100% rename from db/versions/10678-orangeMedeola/00-firstScript.sql rename to db/versions/.archive/10678-orangeMedeola/00-firstScript.sql diff --git a/db/versions/10679-inventoryDiscrepancy/00-tables.sql b/db/versions/.archive/10679-inventoryDiscrepancy/00-tables.sql similarity index 100% rename from db/versions/10679-inventoryDiscrepancy/00-tables.sql rename to db/versions/.archive/10679-inventoryDiscrepancy/00-tables.sql diff --git a/db/versions/10680-turquoiseLilium/00-firstScript.sql b/db/versions/.archive/10680-turquoiseLilium/00-firstScript.sql similarity index 100% rename from db/versions/10680-turquoiseLilium/00-firstScript.sql rename to db/versions/.archive/10680-turquoiseLilium/00-firstScript.sql diff --git a/db/versions/10682-crimsonEucalyptus/00-firstScript.sql b/db/versions/.archive/10682-crimsonEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10682-crimsonEucalyptus/00-firstScript.sql rename to db/versions/.archive/10682-crimsonEucalyptus/00-firstScript.sql diff --git a/db/versions/10683-bronzeMastic/00-firstScript.sql b/db/versions/.archive/10683-bronzeMastic/00-firstScript.sql similarity index 100% rename from db/versions/10683-bronzeMastic/00-firstScript.sql rename to db/versions/.archive/10683-bronzeMastic/00-firstScript.sql diff --git a/db/versions/10684-tealEucalyptus/00-firstScript.sql b/db/versions/.archive/10684-tealEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10684-tealEucalyptus/00-firstScript.sql rename to db/versions/.archive/10684-tealEucalyptus/00-firstScript.sql diff --git a/db/versions/10685-blueMedeola/00-firstScript.sql b/db/versions/.archive/10685-blueMedeola/00-firstScript.sql similarity index 100% rename from db/versions/10685-blueMedeola/00-firstScript.sql rename to db/versions/.archive/10685-blueMedeola/00-firstScript.sql diff --git a/db/versions/10690-azureGalax/00-firstScript.sql b/db/versions/.archive/10690-azureGalax/00-firstScript.sql similarity index 100% rename from db/versions/10690-azureGalax/00-firstScript.sql rename to db/versions/.archive/10690-azureGalax/00-firstScript.sql diff --git a/db/versions/10691-bronzeCamellia/00-firstScript.sql b/db/versions/.archive/10691-bronzeCamellia/00-firstScript.sql similarity index 100% rename from db/versions/10691-bronzeCamellia/00-firstScript.sql rename to db/versions/.archive/10691-bronzeCamellia/00-firstScript.sql diff --git a/db/versions/10692-silverLilium/00-firstScript.sql b/db/versions/.archive/10692-silverLilium/00-firstScript.sql similarity index 100% rename from db/versions/10692-silverLilium/00-firstScript.sql rename to db/versions/.archive/10692-silverLilium/00-firstScript.sql diff --git a/db/versions/10693-chocolateCordyline/00-firstScript.sql b/db/versions/.archive/10693-chocolateCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10693-chocolateCordyline/00-firstScript.sql rename to db/versions/.archive/10693-chocolateCordyline/00-firstScript.sql diff --git a/db/versions/10694-bluePaniculata/00-firstScript.sql b/db/versions/.archive/10694-bluePaniculata/00-firstScript.sql similarity index 100% rename from db/versions/10694-bluePaniculata/00-firstScript.sql rename to db/versions/.archive/10694-bluePaniculata/00-firstScript.sql diff --git a/db/versions/10695-pinkMastic/00-firstScript.sql b/db/versions/.archive/10695-pinkMastic/00-firstScript.sql similarity index 100% rename from db/versions/10695-pinkMastic/00-firstScript.sql rename to db/versions/.archive/10695-pinkMastic/00-firstScript.sql diff --git a/db/versions/10696-blackCataractarum/00-firstScript.sql b/db/versions/.archive/10696-blackCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10696-blackCataractarum/00-firstScript.sql rename to db/versions/.archive/10696-blackCataractarum/00-firstScript.sql diff --git a/db/versions/10698-yellowGalax/00-firstScript.sql b/db/versions/.archive/10698-yellowGalax/00-firstScript.sql similarity index 100% rename from db/versions/10698-yellowGalax/00-firstScript.sql rename to db/versions/.archive/10698-yellowGalax/00-firstScript.sql diff --git a/db/versions/10699-aquaOak/00-firstScript.sql b/db/versions/.archive/10699-aquaOak/00-firstScript.sql similarity index 100% rename from db/versions/10699-aquaOak/00-firstScript.sql rename to db/versions/.archive/10699-aquaOak/00-firstScript.sql diff --git a/db/versions/10700-salmonTulip/00-firstScript.sql b/db/versions/.archive/10700-salmonTulip/00-firstScript.sql similarity index 100% rename from db/versions/10700-salmonTulip/00-firstScript.sql rename to db/versions/.archive/10700-salmonTulip/00-firstScript.sql diff --git a/db/versions/10701-turquoisePaniculata/00-firstScript.sql b/db/versions/.archive/10701-turquoisePaniculata/00-firstScript.sql similarity index 100% rename from db/versions/10701-turquoisePaniculata/00-firstScript.sql rename to db/versions/.archive/10701-turquoisePaniculata/00-firstScript.sql diff --git a/db/versions/10702-crimsonCymbidium/00-firstScript.sql b/db/versions/.archive/10702-crimsonCymbidium/00-firstScript.sql similarity index 100% rename from db/versions/10702-crimsonCymbidium/00-firstScript.sql rename to db/versions/.archive/10702-crimsonCymbidium/00-firstScript.sql diff --git a/db/versions/10704-wheatMastic/00-firstScript.sql b/db/versions/.archive/10704-wheatMastic/00-firstScript.sql similarity index 100% rename from db/versions/10704-wheatMastic/00-firstScript.sql rename to db/versions/.archive/10704-wheatMastic/00-firstScript.sql diff --git a/db/versions/10705-yellowBirch/00-firstScript.sql b/db/versions/.archive/10705-yellowBirch/00-firstScript.sql similarity index 100% rename from db/versions/10705-yellowBirch/00-firstScript.sql rename to db/versions/.archive/10705-yellowBirch/00-firstScript.sql diff --git a/db/versions/10707-azureFern/00-firstScript.sql b/db/versions/.archive/10707-azureFern/00-firstScript.sql similarity index 100% rename from db/versions/10707-azureFern/00-firstScript.sql rename to db/versions/.archive/10707-azureFern/00-firstScript.sql diff --git a/db/versions/10708-greenChrysanthemum/00-firstScript.sql b/db/versions/.archive/10708-greenChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10708-greenChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10708-greenChrysanthemum/00-firstScript.sql diff --git a/db/versions/10712-crimsonCordyline/00-firstScript.sql b/db/versions/.archive/10712-crimsonCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10712-crimsonCordyline/00-firstScript.sql rename to db/versions/.archive/10712-crimsonCordyline/00-firstScript.sql diff --git a/db/versions/10714-azureOak/00-firstScript.sql b/db/versions/.archive/10714-azureOak/00-firstScript.sql similarity index 100% rename from db/versions/10714-azureOak/00-firstScript.sql rename to db/versions/.archive/10714-azureOak/00-firstScript.sql diff --git a/db/versions/10716-chocolateCamellia/00-firstScript.sql b/db/versions/.archive/10716-chocolateCamellia/00-firstScript.sql similarity index 100% rename from db/versions/10716-chocolateCamellia/00-firstScript.sql rename to db/versions/.archive/10716-chocolateCamellia/00-firstScript.sql diff --git a/db/versions/10717-silverRose/00-firstScript.sql b/db/versions/.archive/10717-silverRose/00-firstScript.sql similarity index 100% rename from db/versions/10717-silverRose/00-firstScript.sql rename to db/versions/.archive/10717-silverRose/00-firstScript.sql diff --git a/db/versions/10718-orangeRaphis/00-firstScript.sql b/db/versions/.archive/10718-orangeRaphis/00-firstScript.sql similarity index 100% rename from db/versions/10718-orangeRaphis/00-firstScript.sql rename to db/versions/.archive/10718-orangeRaphis/00-firstScript.sql diff --git a/db/versions/10719-orangeMonstera/00-firstScript.sql b/db/versions/.archive/10719-orangeMonstera/00-firstScript.sql similarity index 100% rename from db/versions/10719-orangeMonstera/00-firstScript.sql rename to db/versions/.archive/10719-orangeMonstera/00-firstScript.sql diff --git a/db/versions/10720-wheatCymbidium/00-firstScript.sql b/db/versions/.archive/10720-wheatCymbidium/00-firstScript.sql similarity index 100% rename from db/versions/10720-wheatCymbidium/00-firstScript.sql rename to db/versions/.archive/10720-wheatCymbidium/00-firstScript.sql diff --git a/db/versions/10721-blueEucalyptus/00-firstScript.sql b/db/versions/.archive/10721-blueEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10721-blueEucalyptus/00-firstScript.sql rename to db/versions/.archive/10721-blueEucalyptus/00-firstScript.sql diff --git a/db/versions/.archive/10722-azureAralia/00-firstScript.vn.sql b/db/versions/.archive/10722-azureAralia/00-firstScript.vn.sql new file mode 100644 index 000000000..2d04dfe03 --- /dev/null +++ b/db/versions/.archive/10722-azureAralia/00-firstScript.vn.sql @@ -0,0 +1,289 @@ +CREATE ROLE 'salix', 'android', 'hedera-web', 'grafana'; + +REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'salix'@'10.0.%.%', 'android'@'10.0.%.%', 'hedera-web'@'10.0.%.%', 'grafana'@'10.0.%.%'; + +GRANT 'salix' TO 'salix'@'10.0.%.%'; +GRANT 'android' TO 'android'@'10.0.%.%'; +GRANT 'hedera-web' TO 'hedera-web'@'10.0.%.%'; +GRANT 'grafana' TO 'grafana'@'10.0.%.%'; + +SET DEFAULT ROLE 'salix' FOR 'salix'@'10.0.%.%'; +SET DEFAULT ROLE 'android' FOR 'android'@'10.0.%.%'; +SET DEFAULT ROLE 'hedera-web' FOR 'hedera-web'@'10.0.%.%'; +SET DEFAULT ROLE 'grafana' FOR 'grafana'@'10.0.%.%'; + +-- salix + -- GRANT `$root` TO `salix` WITH ADMIN OPTION; Access denied for user 'root'@'%' +GRANT CREATE USER ON *.* TO `salix` WITH GRANT OPTION; +GRANT SELECT, UPDATE ON `mysql`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE, EVENT ON `account`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `bs`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `util`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `pbx`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE, EVENT ON `vn`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `salix`.* TO `salix`; +GRANT SELECT ON `managedesktop`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `edi`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `vn2008`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `tmp`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `sage`.* TO `salix`; +GRANT SELECT, CREATE TEMPORARY TABLES, EXECUTE ON `cache`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `nst`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `hedera`.* TO `salix`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `postgresql`.* TO `salix`; + +-- android +GRANT USAGE ON *.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `android`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `vn`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `cache`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `hedera`.* TO `android`; +GRANT SELECT, EXECUTE ON `pbx`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE TEMPORARY TABLES ON `tmp`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `vn2008`.* TO `android`; +GRANT SELECT ON `edi`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, EXECUTE ON `account`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, SHOW VIEW ON `bi`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `Consumos`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `vncontrol`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `srt`.* TO `android`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `psico`.* TO `android`; +GRANT SELECT ON `salix`.`AccessToken` TO `android`; +GRANT EXECUTE ON PROCEDURE `util`.`debugadd` TO `android`; +GRANT EXECUTE ON PROCEDURE `util`.`log_add` TO `android`; +GRANT EXECUTE ON FUNCTION `util`.`vn_now` TO `android`; + +-- hedera-web +GRANT USAGE ON *.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `stock`.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `vn`.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `hedera`.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `account`.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `vn2008`.* TO `hedera-web`; +GRANT SELECT ON `util`.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `edi`.* TO `hedera-web`; +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE TEMPORARY TABLES, EXECUTE ON `salix`.* TO `hedera-web`; + +-- grafana +GRANT USAGE ON *.* TO `grafana` WITH MAX_USER_CONNECTIONS 50; +GRANT EXECUTE ON `util`.* TO `grafana`; +GRANT SELECT ON `vn`.`mistakeType` TO `grafana`; +GRANT SELECT ON `vn`.`collectionHotbed` TO `grafana`; +GRANT SELECT ON `bs`.`clientDied` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionScan` TO `grafana`; +GRANT SELECT ON `vn`.`sale` TO `grafana`; +GRANT SELECT ON `vn`.`printQueue` TO `grafana`; +GRANT SELECT ON `vn`.`operator` TO `grafana`; +GRANT SELECT ON `vn`.`itemType` TO `grafana`; +GRANT SELECT ON `vn`.`expedition` TO `grafana`; +GRANT SELECT ON `srt`.`bufferState` TO `grafana`; +GRANT SELECT ON `edi`.`offerList` TO `grafana`; +GRANT SELECT ON `vn`.`creditInsurance` TO `grafana`; +GRANT SELECT ON `vn`.`workerTimeControl` TO `grafana`; +GRANT SELECT ON `vn`.`volumeConfig` TO `grafana`; +GRANT SELECT ON `vn`.`agency` TO `grafana`; +GRANT SELECT ON `vn`.`alertLevel` TO `grafana`; +GRANT SELECT (user_id, extension) ON `pbx`.`sip` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionStateType` TO `grafana`; +GRANT SELECT ON `vn`.`businessType` TO `grafana`; +GRANT SELECT ON `vn`.`time` TO `grafana`; +GRANT SELECT ON `hedera`.`visitUser` TO `grafana`; +GRANT SELECT ON `vn`.`workCenter` TO `grafana`; +GRANT SELECT ON `vn`.`ticket` TO `grafana`; +GRANT SELECT ON `vn`.`ticketWeekly` TO `grafana`; +GRANT SELECT ON `vn`.`claimEnd` TO `grafana`; +GRANT SELECT ON `vn`.`arcRead` TO `grafana`; +GRANT SELECT ON `vn`.`saleGoal` TO `grafana`; +GRANT SELECT ON `edi`.`supplyResponse` TO `grafana`; +GRANT SELECT ON `vn`.`invoiceInTax` TO `grafana`; +GRANT SELECT ON `bs`.`salesPersonEvolution` TO `grafana`; +GRANT SELECT ON `vn`.`saleComponent` TO `grafana`; +GRANT SELECT ON `vn`.`itemShelvingStock` TO `grafana`; +GRANT SELECT ON `vn`.`clientChain` TO `grafana`; +GRANT SELECT ON `edi`.`VMPSettings` TO `grafana`; +GRANT SELECT ON `util`.`debug` TO `grafana`; +GRANT SELECT ON `vn`.`claimResponsible` TO `grafana`; +GRANT SELECT ON `vn`.`ticketState` TO `grafana`; +GRANT SELECT ON `vn`.`packingSiteLog` TO `grafana`; +GRANT SELECT ON `bs`.`sale` TO `grafana`; +GRANT SELECT ON `vn`.`ink` TO `grafana`; +GRANT SELECT ON `bs`.`inventoryDiscrepancyDetail` TO `grafana`; +GRANT SELECT ON `vn`.`clientCredit` TO `grafana`; +GRANT SELECT ON `vn`.`workerMana` TO `grafana`; +GRANT SELECT ON `vn`.`greugeType` TO `grafana`; +GRANT SELECT ON `vn`.`supplierPackaging` TO `grafana`; +GRANT SELECT ON `vn`.`mdbVersion` TO `grafana`; +GRANT SELECT ON `vn`.`clientLog` TO `grafana`; +GRANT SELECT ON `vn`.`calendar` TO `grafana`; +GRANT SELECT ON `vn`.`campaign` TO `grafana`; +GRANT SELECT ON `vn`.`ticketService` TO `grafana`; +GRANT SELECT ON `vn`.`report` TO `grafana`; +GRANT SELECT ON `vn`.`buyer` TO `grafana`; +GRANT SELECT ON `bs`.`defaulter` TO `grafana`; +GRANT SELECT ON `vn`.`componentType` TO `grafana`; +GRANT SELECT ON `vn`.`clientManaCache` TO `grafana`; +GRANT SELECT ON `vn`.`invoiceIn` TO `grafana`; +GRANT SELECT ON `edi`.`deliveryInformation` TO `grafana`; +GRANT SELECT ON `srt`.`bufferType` TO `grafana`; +GRANT SELECT ON `account`.`role` TO `grafana`; +GRANT SELECT ON `edi`.`supplyOffer` TO `grafana`; +GRANT SELECT ON `vn`.`travel` TO `grafana`; +GRANT SELECT ON `srt`.`bufferFreeLength` TO `grafana`; +GRANT SELECT ON `vn`.`worker` TO `grafana`; +GRANT SELECT ON `vn`.`client` TO `grafana`; +GRANT SELECT ON `vn`.`supplier` TO `grafana`; +GRANT SELECT ON `vn`.`zoneEstimatedDelivery` TO `grafana`; +GRANT SELECT ON `vn`.`workerDistributionCategory` TO `grafana`; +GRANT SELECT ON `vn`.`entry` TO `grafana`; +GRANT SELECT ON `vn`.`claimBeginning` TO `grafana`; +GRANT SELECT ON `vn`.`payMethod` TO `grafana`; +GRANT SELECT ON `vn`.`collection` TO `grafana`; +GRANT SELECT ON `srt`.`routePalletized` TO `grafana`; +GRANT SELECT ON `bs`.`inventoryDiscrepancy` TO `grafana`; +GRANT SELECT ON `vn`.`itemImageQueue` TO `grafana`; +GRANT SELECT ON `bi`.`rutasBoard` TO `grafana`; +GRANT SELECT ON `vn`.`department` TO `grafana`; +GRANT SELECT ON `bs`.`workerLabourDataByMonth` TO `grafana`; +GRANT SELECT ON `vn`.`route` TO `grafana`; +GRANT SELECT ON `vn`.`routeCommission` TO `grafana`; +GRANT SELECT ON `bs`.`m3` TO `grafana`; +GRANT SELECT ON `vn`.`itemCost` TO `grafana`; +GRANT SELECT ON `vn`.`zone` TO `grafana`; +GRANT SELECT ON `vn`.`mdbApp` TO `grafana`; +GRANT SELECT ON `vn`.`ticketPackaging` TO `grafana`; +GRANT SELECT ON `vn`.`itemTaxCountry` TO `grafana`; +GRANT SELECT ON `vn`.`sectorCollection` TO `grafana`; +GRANT SELECT ON `vn`.`address` TO `grafana`; +GRANT SELECT ON `vn`.`deviceProductionLog` TO `grafana`; +GRANT SELECT ON `vn`.`itemPackingType` TO `grafana`; +GRANT SELECT ON `vn`.`workerJourney` TO `grafana`; +GRANT SELECT ON `srt`.`expedition` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionMistake` TO `grafana`; +GRANT SELECT ON `vn`.`productionError` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionState` TO `grafana`; +GRANT SELECT ON `bs`.`salesByItemTypeDay` TO `grafana`; +GRANT SELECT ON `vn`.`packingSite` TO `grafana`; +GRANT SELECT ON `vn`.`businessCalendar` TO `grafana`; +GRANT SELECT ON `vn`.`chain` TO `grafana`; +GRANT SELECT ON `vn`.`clientRisk` TO `grafana`; +GRANT SELECT ON `vn`.`claimRedelivery` TO `grafana`; +GRANT SELECT ON `vn`.`business` TO `grafana`; +GRANT SELECT ON `bs`.`clientAnnualConsumption` TO `grafana`; +GRANT SELECT ON `vn`.`dock` TO `grafana`; +GRANT SELECT ON `vn`.`item` TO `grafana`; +GRANT SELECT ON `vn`.`province` TO `grafana`; +GRANT SELECT ON `vn`.`shelving` TO `grafana`; +GRANT SELECT ON `vn`.`claim` TO `grafana`; +GRANT SELECT ON `vn`.`clientType` TO `grafana`; +GRANT SELECT ON `vn`.`supplierAccount` TO `grafana`; +GRANT SELECT ON `vn`.`workerDepartment` TO `grafana`; +GRANT SELECT ON `pbx`.`cdr` TO `grafana`; +GRANT SELECT ON `vn`.`workerTimeControlConfig` TO `grafana`; +GRANT SELECT ON `vn`.`workerMistake` TO `grafana`; +GRANT SELECT ON `edi`.`putOrder` TO `grafana`; +GRANT SELECT ON `vn`.`saleMistake` TO `grafana`; +GRANT SELECT ON `vn`.`deviceProductionUser` TO `grafana`; +GRANT SELECT ON `vn`.`contactChannel` TO `grafana`; +GRANT SELECT ON `vn`.`deviceLog` TO `grafana`; +GRANT SELECT ON `vn`.`vehicle` TO `grafana`; +GRANT SELECT ON `vn`.`packaging` TO `grafana`; +GRANT SELECT ON `bs`.`workerProductivityConfig` TO `grafana`; +GRANT SELECT ON `srt`.`antenna` TO `grafana`; +GRANT SELECT ON `vn`.`cmr` TO `grafana`; +GRANT SELECT ON `vn`.`accounting` TO `grafana`; +GRANT SELECT ON `vn`.`creditClassification` TO `grafana`; +GRANT SELECT ON `vn`.`ticketLog` TO `grafana`; +GRANT SELECT ON `srt`.`moving` TO `grafana`; +GRANT SELECT ON `vn`.`claimDevelopment` TO `grafana`; +GRANT SELECT ON `srt`.`expeditionLog` TO `grafana`; +GRANT SELECT ON `bs`.`compradores_evolution` TO `grafana`; +GRANT SELECT ON `vn`.`currency` TO `grafana`; +GRANT SELECT ON `vn`.`claimObservation` TO `grafana`; +GRANT SELECT ON `vn`.`salesPreviousPreparated` TO `grafana`; +GRANT SELECT ON `vn`.`claimState` TO `grafana`; +GRANT SELECT ON `vn`.`company` TO `grafana`; +GRANT SELECT ON `srt`.`buffer` TO `grafana`; +GRANT SELECT ON `vn`.`greuge` TO `grafana`; +GRANT SELECT ON `vn`.`routeComplement` TO `grafana`; +GRANT SELECT ON `vn`.`saleVolume` TO `grafana`; +GRANT SELECT ON `vn`.`component` TO `grafana`; +GRANT SELECT ON `vn`.`train` TO `grafana`; +GRANT SELECT ON `srt`.`ticketPalletized` TO `grafana`; +GRANT SELECT ON `vn`.`autonomy` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionMistakeType` TO `grafana`; +GRANT SELECT ON `vn`.`ticketParking` TO `grafana`; +GRANT SELECT ON `vn`.`itemShelving` TO `grafana`; +GRANT SELECT ON `vn`.`state` TO `grafana`; +GRANT SELECT ON `vn`.`taxClass` TO `grafana`; +GRANT SELECT ON `bs`.`salesByWeek` TO `grafana`; +GRANT SELECT ON `vn`.`invoiceInDueDay` TO `grafana`; +GRANT SELECT ON `vn`.`sectorProductivity` TO `grafana`; +GRANT SELECT ON `bs`.`salesByclientSalesPerson` TO `grafana`; +GRANT SELECT ON `edi`.`marketPlace` TO `grafana`; +GRANT SELECT ON `vn`.`routeAction` TO `grafana`; +GRANT SELECT ON `vn`.`deviceProduction` TO `grafana`; +GRANT SELECT ON `vn`.`invoiceOut` TO `grafana`; +GRANT SELECT ON `vn`.`printer` TO `grafana`; +GRANT SELECT ON `vn`.`mdbBranch` TO `grafana`; +GRANT SELECT ON `bs`.`workerProductivity` TO `grafana`; +GRANT SELECT ON `vn`.`config` TO `grafana`; +GRANT SELECT ON `hedera`.`userSession` TO `grafana`; +GRANT SELECT ON `vn`.`receipt` TO `grafana`; +GRANT SELECT ON `vn`.`buy` TO `grafana`; +GRANT SELECT ON `vn`.`calendarHolidays` TO `grafana`; +GRANT SELECT ON `vn`.`parking` TO `grafana`; +GRANT SELECT ON `vn`.`role` TO `grafana`; +GRANT SELECT ON `vn`.`errorLogApp` TO `grafana`; +GRANT SELECT ON `vn`.`continent` TO `grafana`; +GRANT SELECT ON `srt`.`lastRFID` TO `grafana`; +GRANT SELECT ON `vn`.`farmingInvoiceIn` TO `grafana`; +GRANT SELECT ON `vn`.`agencyMode` TO `grafana`; +GRANT SELECT ON `vn`.`absenceType` TO `grafana`; +GRANT SELECT ON `vn`.`saleGroupDetail` TO `grafana`; +GRANT SELECT ON `vn`.`workerMistakeType` TO `grafana`; +GRANT SELECT ON `vn`.`mdbVersionTree` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionTruck` TO `grafana`; +GRANT SELECT ON `vn`.`routeConfig` TO `grafana`; +GRANT SELECT ON `vn`.`claimReason` TO `grafana`; +GRANT SELECT ON `edi`.`log` TO `grafana`; +GRANT SELECT ON `srt`.`failureLog` TO `grafana`; +GRANT SELECT ON `bs`.`clientNewBorn` TO `grafana`; +GRANT SELECT ON `vn`.`farming` TO `grafana`; +GRANT SELECT ON `hedera`.`order` TO `grafana`; +GRANT SELECT ON `bs`.`packingSpeed` TO `grafana`; +GRANT SELECT ON `vn`.`expense` TO `grafana`; +GRANT SELECT ON `vn`.`workerLabour` TO `grafana`; +GRANT SELECT ON `hedera`.`orderRow` TO `grafana`; +GRANT SELECT ON `srt`.`movingLog` TO `grafana`; +GRANT SELECT ON `vn`.`warehouse` TO `grafana`; +GRANT SELECT ON `vn`.`sector` TO `grafana`; +GRANT SELECT ON `vn`.`salesPersonGoal` TO `grafana`; +GRANT SELECT ON `srt`.`movingState` TO `grafana`; +GRANT SELECT ON `vn`.`claimResult` TO `grafana`; +GRANT SELECT ON `vn`.`routesMonitor` TO `grafana`; +GRANT SELECT ON `vn`.`expeditionPallet` TO `grafana`; +GRANT SELECT ON `bs`.`ventas` TO `grafana`; +GRANT SELECT ON `vn`.`intrastat` TO `grafana`; +GRANT SELECT ON `vn`.`printQueueArgs` TO `grafana`; +GRANT SELECT ON `bi`.`Greuge_Evolution` TO `grafana`; +GRANT SELECT ON `vn`.`host` TO `grafana`; +GRANT SELECT ON `vn`.`country` TO `grafana`; +GRANT SELECT ON `bs`.`waste` TO `grafana`; +GRANT SELECT ON `vn`.`ticketTracking` TO `grafana`; +GRANT SELECT ON `vn`.`itemCategory` TO `grafana`; +GRANT SELECT ON `vn`.`saleTracking` TO `grafana`; +GRANT SELECT ON `vn`.`producer` TO `grafana`; +GRANT SELECT ON `cache`.`stock` TO `grafana`; +GRANT SELECT (name, active, role, email, id, nickname) ON `account`.`user` TO `grafana`; +GRANT SELECT ON `vn`.`deliveryMethod` TO `grafana`; +GRANT SELECT ON `vn`.`ticketCollection` TO `grafana`; +GRANT EXECUTE ON PROCEDURE `vn`.`zone_upcomingdeliveries` TO `grafana`; +GRANT EXECUTE ON PROCEDURE `vn`.`zone_getaddresses` TO `grafana`; +GRANT EXECUTE ON FUNCTION `util`.`firstdayofmonth` TO `grafana`; +GRANT EXECUTE ON FUNCTION `util`.`dayend` TO `grafana`; +GRANT EXECUTE ON FUNCTION `vn`.`lastdayofweek` TO `grafana`; +GRANT EXECUTE ON FUNCTION `vn`.`firstdayofweek` TO `grafana`; +GRANT EXECUTE ON FUNCTION `util`.`quarterfirstday` TO `grafana`; +GRANT EXECUTE ON FUNCTION `util`.`firstdayofyear` TO `grafana`; + +FLUSH PRIVILEGES; diff --git a/db/versions/10725-wheatAnthurium/00-firstScript.sql b/db/versions/.archive/10725-wheatAnthurium/00-firstScript.sql similarity index 100% rename from db/versions/10725-wheatAnthurium/00-firstScript.sql rename to db/versions/.archive/10725-wheatAnthurium/00-firstScript.sql diff --git a/db/versions/10726-blackMastic/00-firstScript.sql b/db/versions/.archive/10726-blackMastic/00-firstScript.sql similarity index 100% rename from db/versions/10726-blackMastic/00-firstScript.sql rename to db/versions/.archive/10726-blackMastic/00-firstScript.sql diff --git a/db/versions/10727-limeErica/00-addPrinterField.sql b/db/versions/.archive/10727-limeErica/00-addPrinterField.sql similarity index 100% rename from db/versions/10727-limeErica/00-addPrinterField.sql rename to db/versions/.archive/10727-limeErica/00-addPrinterField.sql diff --git a/db/versions/10727-limeErica/01-createTableScreenModel.sql b/db/versions/.archive/10727-limeErica/01-createTableScreenModel.sql similarity index 100% rename from db/versions/10727-limeErica/01-createTableScreenModel.sql rename to db/versions/.archive/10727-limeErica/01-createTableScreenModel.sql diff --git a/db/versions/10727-limeErica/02-createTableScreen.sql b/db/versions/.archive/10727-limeErica/02-createTableScreen.sql similarity index 100% rename from db/versions/10727-limeErica/02-createTableScreen.sql rename to db/versions/.archive/10727-limeErica/02-createTableScreen.sql diff --git a/db/versions/10727-limeErica/03-createTableScreenModel.sql b/db/versions/.archive/10727-limeErica/03-createTableScreenModel.sql similarity index 100% rename from db/versions/10727-limeErica/03-createTableScreenModel.sql rename to db/versions/.archive/10727-limeErica/03-createTableScreenModel.sql diff --git a/db/versions/10727-limeErica/04-createTableScanner.sql b/db/versions/.archive/10727-limeErica/04-createTableScanner.sql similarity index 100% rename from db/versions/10727-limeErica/04-createTableScanner.sql rename to db/versions/.archive/10727-limeErica/04-createTableScanner.sql diff --git a/db/versions/10727-limeErica/05-createTablePackingSiteDeviceLog.sql b/db/versions/.archive/10727-limeErica/05-createTablePackingSiteDeviceLog.sql similarity index 100% rename from db/versions/10727-limeErica/05-createTablePackingSiteDeviceLog.sql rename to db/versions/.archive/10727-limeErica/05-createTablePackingSiteDeviceLog.sql diff --git a/db/versions/10727-limeErica/06-alterTablePrinterModel.sql b/db/versions/.archive/10727-limeErica/06-alterTablePrinterModel.sql similarity index 100% rename from db/versions/10727-limeErica/06-alterTablePrinterModel.sql rename to db/versions/.archive/10727-limeErica/06-alterTablePrinterModel.sql diff --git a/db/versions/10727-limeErica/07-AddFieldsToPackingSite.sql b/db/versions/.archive/10727-limeErica/07-AddFieldsToPackingSite.sql similarity index 100% rename from db/versions/10727-limeErica/07-AddFieldsToPackingSite.sql rename to db/versions/.archive/10727-limeErica/07-AddFieldsToPackingSite.sql diff --git a/db/versions/10730-whiteChrysanthemum/00-firstScript.sql b/db/versions/.archive/10730-whiteChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10730-whiteChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10730-whiteChrysanthemum/00-firstScript.sql diff --git a/db/versions/10733-azureErica/00-firstScript.sql b/db/versions/.archive/10733-azureErica/00-firstScript.sql similarity index 100% rename from db/versions/10733-azureErica/00-firstScript.sql rename to db/versions/.archive/10733-azureErica/00-firstScript.sql diff --git a/db/versions/10736-maroonChico/00-workerBossNull.sql b/db/versions/.archive/10736-maroonChico/00-workerBossNull.sql similarity index 100% rename from db/versions/10736-maroonChico/00-workerBossNull.sql rename to db/versions/.archive/10736-maroonChico/00-workerBossNull.sql diff --git a/db/versions/10739-turquoiseCordyline/00-firstScript.sql b/db/versions/.archive/10739-turquoiseCordyline/00-firstScript.sql similarity index 100% rename from db/versions/10739-turquoiseCordyline/00-firstScript.sql rename to db/versions/.archive/10739-turquoiseCordyline/00-firstScript.sql diff --git a/db/versions/10740-pinkCataractarum/00-firstScript.sql b/db/versions/.archive/10740-pinkCataractarum/00-firstScript.sql similarity index 100% rename from db/versions/10740-pinkCataractarum/00-firstScript.sql rename to db/versions/.archive/10740-pinkCataractarum/00-firstScript.sql diff --git a/db/versions/10741-maroonMastic/01-refactorCplusTrascendency472.sql b/db/versions/.archive/10741-maroonMastic/01-refactorCplusTrascendency472.sql similarity index 100% rename from db/versions/10741-maroonMastic/01-refactorCplusTrascendency472.sql rename to db/versions/.archive/10741-maroonMastic/01-refactorCplusTrascendency472.sql diff --git a/db/versions/10741-maroonMastic/02-refactorCplusTrascendency477.sql b/db/versions/.archive/10741-maroonMastic/02-refactorCplusTrascendency477.sql similarity index 100% rename from db/versions/10741-maroonMastic/02-refactorCplusTrascendency477.sql rename to db/versions/.archive/10741-maroonMastic/02-refactorCplusTrascendency477.sql diff --git a/db/versions/10741-maroonMastic/03-refactorCplusInvoiceType477.sql b/db/versions/.archive/10741-maroonMastic/03-refactorCplusInvoiceType477.sql similarity index 100% rename from db/versions/10741-maroonMastic/03-refactorCplusInvoiceType477.sql rename to db/versions/.archive/10741-maroonMastic/03-refactorCplusInvoiceType477.sql diff --git a/db/versions/10741-maroonMastic/04-refactorCplusInvoiceType472.sql b/db/versions/.archive/10741-maroonMastic/04-refactorCplusInvoiceType472.sql similarity index 100% rename from db/versions/10741-maroonMastic/04-refactorCplusInvoiceType472.sql rename to db/versions/.archive/10741-maroonMastic/04-refactorCplusInvoiceType472.sql diff --git a/db/versions/10741-maroonMastic/05-fixes.sql b/db/versions/.archive/10741-maroonMastic/05-fixes.sql similarity index 100% rename from db/versions/10741-maroonMastic/05-fixes.sql rename to db/versions/.archive/10741-maroonMastic/05-fixes.sql diff --git a/db/versions/10744-aquaBirch/00-firstScript.sql b/db/versions/.archive/10744-aquaBirch/00-firstScript.sql similarity index 100% rename from db/versions/10744-aquaBirch/00-firstScript.sql rename to db/versions/.archive/10744-aquaBirch/00-firstScript.sql diff --git a/db/versions/10746-aquaMastic/00-firstScript.sql b/db/versions/.archive/10746-aquaMastic/00-firstScript.sql similarity index 100% rename from db/versions/10746-aquaMastic/00-firstScript.sql rename to db/versions/.archive/10746-aquaMastic/00-firstScript.sql diff --git a/db/versions/10747-brownRaphis/00-firstScript.sql b/db/versions/.archive/10747-brownRaphis/00-firstScript.sql similarity index 100% rename from db/versions/10747-brownRaphis/00-firstScript.sql rename to db/versions/.archive/10747-brownRaphis/00-firstScript.sql diff --git a/db/versions/10748-navyRose/00-firstScript.sql b/db/versions/.archive/10748-navyRose/00-firstScript.sql similarity index 100% rename from db/versions/10748-navyRose/00-firstScript.sql rename to db/versions/.archive/10748-navyRose/00-firstScript.sql diff --git a/db/versions/10748-navyRose/01-SecondScript.sql b/db/versions/.archive/10748-navyRose/01-SecondScript.sql similarity index 100% rename from db/versions/10748-navyRose/01-SecondScript.sql rename to db/versions/.archive/10748-navyRose/01-SecondScript.sql diff --git a/db/versions/10749-chocolateEucalyptus/00-firstScript.sql b/db/versions/.archive/10749-chocolateEucalyptus/00-firstScript.sql similarity index 100% rename from db/versions/10749-chocolateEucalyptus/00-firstScript.sql rename to db/versions/.archive/10749-chocolateEucalyptus/00-firstScript.sql diff --git a/db/versions/10750-limeAsparagus/00-firstScript.sql b/db/versions/.archive/10750-limeAsparagus/00-firstScript.sql similarity index 100% rename from db/versions/10750-limeAsparagus/00-firstScript.sql rename to db/versions/.archive/10750-limeAsparagus/00-firstScript.sql diff --git a/db/versions/10750-wheatGalax/00-ticket_addGrants.sql b/db/versions/.archive/10750-wheatGalax/00-ticket_addGrants.sql similarity index 100% rename from db/versions/10750-wheatGalax/00-ticket_addGrants.sql rename to db/versions/.archive/10750-wheatGalax/00-ticket_addGrants.sql diff --git a/db/versions/10751-silverArborvitae/00-firstScript.sql b/db/versions/.archive/10751-silverArborvitae/00-firstScript.sql similarity index 100% rename from db/versions/10751-silverArborvitae/00-firstScript.sql rename to db/versions/.archive/10751-silverArborvitae/00-firstScript.sql diff --git a/db/versions/10752-crimsonChrysanthemum/00-firstScript.sql b/db/versions/.archive/10752-crimsonChrysanthemum/00-firstScript.sql similarity index 100% rename from db/versions/10752-crimsonChrysanthemum/00-firstScript.sql rename to db/versions/.archive/10752-crimsonChrysanthemum/00-firstScript.sql diff --git a/db/versions/10753-blueDracena/00-firstScript.sql b/db/versions/.archive/10753-blueDracena/00-firstScript.sql similarity index 100% rename from db/versions/10753-blueDracena/00-firstScript.sql rename to db/versions/.archive/10753-blueDracena/00-firstScript.sql diff --git a/db/versions/10754-purpleMonstera/00-firstScript.sql b/db/versions/.archive/10754-purpleMonstera/00-firstScript.sql similarity index 100% rename from db/versions/10754-purpleMonstera/00-firstScript.sql rename to db/versions/.archive/10754-purpleMonstera/00-firstScript.sql diff --git a/db/versions/10755-redGalax/00-firstScript.sql b/db/versions/.archive/10755-redGalax/00-firstScript.sql similarity index 100% rename from db/versions/10755-redGalax/00-firstScript.sql rename to db/versions/.archive/10755-redGalax/00-firstScript.sql diff --git a/db/versions/10724-maroonOrchid/00-firstScript.sql b/db/versions/10724-maroonOrchid/00-firstScript.sql new file mode 100644 index 000000000..0e9e73e4b --- /dev/null +++ b/db/versions/10724-maroonOrchid/00-firstScript.sql @@ -0,0 +1,33 @@ +-- Place your SQL code here +USE vn; +ALTER TABLE `vn`.`saleGroup` +ADD COLUMN IF NOT EXISTS `ticketFk` int(11) NULL, +ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL; + +ALTER TABLE vn.saleGroup ADD CONSTRAINT saleGroup_FK + FOREIGN KEY (ticketFk) REFERENCES vn.ticket(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.saleGroup + MODIFY COLUMN userFk int(10) unsigned DEFAULT NULL NULL; + +ALTER TABLE vn.saleGroup ADD CONSTRAINT saleGroup_userFK + FOREIGN KEY (userFk) REFERENCES account.`user`(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.saleGroup ADD CONSTRAINT saleGroup_parkingFK + FOREIGN KEY (parkingFk) REFERENCES vn.`parking`(id) ON DELETE CASCADE ON UPDATE CASCADE; + +ALTER TABLE vn.saleGroup ADD CONSTRAINT saleGroup_sectorFK + FOREIGN KEY (sectorFk) REFERENCES vn.`sector`(id) ON DELETE CASCADE ON UPDATE CASCADE; + +UPDATE `vn`.`saleGroup` sg + JOIN ( + SELECT sgd.saleGroupFk, s.ticketFk + FROM saleGroupDetail sgd + JOIN sale s ON s.id = sgd.saleFk + GROUP BY sgd.saleGroupFk + ) sub ON sg.id = sub.saleGroupFk + SET sg.ticketFk = sub.ticketFk; + +ALTER TABLE vn.ticketLog MODIFY COLUMN changedModel enum('Ticket','Sale','TicketWeekly','TicketTracking','TicketService','TicketRequest', + 'TicketRefund','TicketPackaging','TicketObservation','TicketDms','Expedition','Sms','SaleGroup') + CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Ticket' NOT NULL; diff --git a/db/versions/10738-greenCordyline/00-addFieldToTravel.sql b/db/versions/10738-greenCordyline/00-addFieldToTravel.sql new file mode 100644 index 000000000..af4903c95 --- /dev/null +++ b/db/versions/10738-greenCordyline/00-addFieldToTravel.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.travel DROP FOREIGN KEY IF EXISTS travel_FK_1 ; +ALTER TABLE vn.travel DROP COLUMN IF EXISTS awbFk; + +ALTER TABLE vn.travel + ADD awbFk SMALLINT(11) UNSIGNED; + +ALTER TABLE vn.travel + ADD CONSTRAINT travel_FK_1 FOREIGN KEY (awbFk) REFERENCES vn.awb(id) + ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10738-greenCordyline/01-copyDataToTravel.sql b/db/versions/10738-greenCordyline/01-copyDataToTravel.sql new file mode 100644 index 000000000..0469d4ce8 --- /dev/null +++ b/db/versions/10738-greenCordyline/01-copyDataToTravel.sql @@ -0,0 +1,9 @@ +UPDATE vn.travel t + JOIN(SELECT t.id travelFk, d.awbFk + FROM vn.dua d + JOIN vn.duaEntry de ON de.duaFk = d.id + JOIN vn.`entry` e ON e.id = de.entryFk + JOIN vn.travel t ON t.id = e.travelFk + GROUP BY t.id + )sub ON sub.travelFk = t.id + SET t.awbFk = sub.awbFk; diff --git a/db/versions/10738-greenCordyline/03-deprecateDuaAwbFk.sql b/db/versions/10738-greenCordyline/03-deprecateDuaAwbFk.sql new file mode 100644 index 000000000..3daf86f9b --- /dev/null +++ b/db/versions/10738-greenCordyline/03-deprecateDuaAwbFk.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.dua CHANGE awbFk awbFk__ smallint(11) unsigned DEFAULT NULL NULL COMMENT '@Deprecated refs #5871 01/10/2023'; +ALTER TABLE vn.dua DROP FOREIGN KEY dua_fk2; diff --git a/db/versions/10758-boxPicking/02-agencyMode.sql b/db/versions/10758-boxPicking/02-agencyMode.sql new file mode 100644 index 000000000..0cb71d5af --- /dev/null +++ b/db/versions/10758-boxPicking/02-agencyMode.sql @@ -0,0 +1,3 @@ +UPDATE vn.agencyMode am + SET am.code = 'REC_ALG' + WHERE am.name = 'REC_ALGEMESI'; \ No newline at end of file diff --git a/db/versions/10758-boxPicking/03-item.sql b/db/versions/10758-boxPicking/03-item.sql new file mode 100644 index 000000000..1ba254dc0 --- /dev/null +++ b/db/versions/10758-boxPicking/03-item.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.item ADD isBoxPickingMode BOOLEAN DEFAULT FALSE NOT NULL +COMMENT 'FALSE: using item.packingOut TRUE: boxPicking using itemShelving.packing'; + diff --git a/db/versions/10764-navyTulip/00-firstScript.sql b/db/versions/10764-navyTulip/00-firstScript.sql new file mode 100644 index 000000000..9cfbe0ccb --- /dev/null +++ b/db/versions/10764-navyTulip/00-firstScript.sql @@ -0,0 +1,7 @@ +USE sage; + +CREATE TABLE `accountingEntryError` ( + `accountingEntryFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`accountingEntryFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci + COMMENT='Listado de asientos presentes en Sage para notificar su error'; \ No newline at end of file diff --git a/db/versions/10781-crimsonMonstera/00-firstScript.sql b/db/versions/10781-crimsonMonstera/00-firstScript.sql new file mode 100644 index 000000000..5babdb003 --- /dev/null +++ b/db/versions/10781-crimsonMonstera/00-firstScript.sql @@ -0,0 +1,9 @@ +ALTER TABLE `vn`.`workerTimeControl` + ADD COLUMN IF NOT EXISTS `logExclude` tinyint(1) AS (IF(`manual`, FALSE, TRUE)) VIRTUAL, + ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL; + +ALTER TABLE `vn`.`calendar` + ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL; + +ALTER TABLE vn.workerLog MODIFY COLUMN changedModel enum('Worker','Calendar','WorkerTimeControlMail','Business','WorkerDms','WorkerTimeControl') CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT 'Worker' NOT NULL; + diff --git a/db/versions/10784-tealCamellia/00-firstScript.sql b/db/versions/10784-tealCamellia/00-firstScript.sql new file mode 100644 index 000000000..a5c5b519f --- /dev/null +++ b/db/versions/10784-tealCamellia/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE `vn`.`itemShelving` +ADD COLUMN IF NOT EXISTS `editorFk` int(10) unsigned DEFAULT NULL; \ No newline at end of file diff --git a/db/versions/10808-maroonRoebelini/00-firstScript.sql b/db/versions/10808-maroonRoebelini/00-firstScript.sql new file mode 100644 index 000000000..7f45f2522 --- /dev/null +++ b/db/versions/10808-maroonRoebelini/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT INTO bs.nightTask (`order`,`schema`,`procedure`) + VALUES (652,'sage','clean'); \ No newline at end of file diff --git a/db/versions/10809-purpleDendro/00-firstScript.sql b/db/versions/10809-purpleDendro/00-firstScript.sql new file mode 100644 index 000000000..53511fcb3 --- /dev/null +++ b/db/versions/10809-purpleDendro/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.operator ADD linesLimit int DEFAULT NULL NULL COMMENT 'Límite de lineas en una colección para la asignación de pedidos'; +ALTER TABLE vn.operator ADD volumeLimit decimal DEFAULT NULL NULL COMMENT 'Límite de volumen en una colección para la asignación de pedidos'; diff --git a/db/versions/10810-turquoiseCataractarum/00-firstScript.sql b/db/versions/10810-turquoiseCataractarum/00-firstScript.sql new file mode 100644 index 000000000..3e939e069 --- /dev/null +++ b/db/versions/10810-turquoiseCataractarum/00-firstScript.sql @@ -0,0 +1,7 @@ +USE sage; + +CREATE OR REPLACE TABLE `accountingEntryError` ( + `accountingEntryFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`accountingEntryFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci + COMMENT='Listado de asientos presentes en Sage para notificar su error'; \ No newline at end of file diff --git a/db/versions/10811-pinkBirch/00-firstScript.sql b/db/versions/10811-pinkBirch/00-firstScript.sql new file mode 100644 index 000000000..1d02ec0d6 --- /dev/null +++ b/db/versions/10811-pinkBirch/00-firstScript.sql @@ -0,0 +1,7 @@ +ALTER TABLE vn.travel DROP KEY shipment_1; + +ALTER TABLE `vn`.`travel` ADD CONSTRAINT shipment_1 UNIQUE KEY (shipped,landed,warehouseInFk,warehouseOutFk,agencyModeFk,`ref`); + +ALTER TABLE vn.travel DROP FOREIGN KEY travel_ibfk_3; + +ALTER TABLE vn.travel CHANGE agencyFk agencyFk__ smallint(5) unsigned NOT NULL COMMENT '@deprecated 2024-10-01 refs #6604'; diff --git a/db/versions/10812-goldenPaniculata/00-update.sql b/db/versions/10812-goldenPaniculata/00-update.sql new file mode 100644 index 000000000..3d882e546 --- /dev/null +++ b/db/versions/10812-goldenPaniculata/00-update.sql @@ -0,0 +1,8 @@ +UPDATE IGNORE vn.dms + SET dmsTypeFk = (SELECT id FROM vn.dmsType WHERE code = 'vehicle') + WHERE id IN ( + SELECT d.id + FROM vn.dms d + JOIN vn.dmsType dt ON dt.id = d.dmsTypeFk + WHERE dt.code = 'vehicles' + ); diff --git a/db/versions/10812-goldenPaniculata/01-delete.sql b/db/versions/10812-goldenPaniculata/01-delete.sql new file mode 100644 index 000000000..6d98064cc --- /dev/null +++ b/db/versions/10812-goldenPaniculata/01-delete.sql @@ -0,0 +1 @@ +DELETE IGNORE FROM vn.dmsType WHERE code = 'vehicles'; diff --git a/db/versions/10812-goldenPaniculata/02-rename.sql b/db/versions/10812-goldenPaniculata/02-rename.sql new file mode 100644 index 000000000..d98292e2f --- /dev/null +++ b/db/versions/10812-goldenPaniculata/02-rename.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.dmsType CHANGE `path` path__ varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT '@deprecated 2024-01-08 refs #6410'; +ALTER TABLE vn.dmsType MODIFY COLUMN path__ varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL COMMENT '@deprecated 2024-01-08 refs #6410'; diff --git a/db/versions/10812-goldenPaniculata/03-changePosition.sql b/db/versions/10812-goldenPaniculata/03-changePosition.sql new file mode 100644 index 000000000..9aea1fdf8 --- /dev/null +++ b/db/versions/10812-goldenPaniculata/03-changePosition.sql @@ -0,0 +1 @@ +ALTER TABLE vn.dmsType CHANGE code code varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL AFTER id; diff --git a/db/versions/10812-goldenPaniculata/04-unique.sql b/db/versions/10812-goldenPaniculata/04-unique.sql new file mode 100644 index 000000000..5cbe32b0d --- /dev/null +++ b/db/versions/10812-goldenPaniculata/04-unique.sql @@ -0,0 +1 @@ +ALTER TABLE vn.dmsType ADD CONSTRAINT dmsType_unique UNIQUE KEY (code); diff --git a/db/versions/10813-salmonChico/00-firstScript.sql b/db/versions/10813-salmonChico/00-firstScript.sql new file mode 100644 index 000000000..d5bd26ca3 --- /dev/null +++ b/db/versions/10813-salmonChico/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.entryObservation DROP FOREIGN KEY entry_id_entryFk; +ALTER TABLE vn.entryObservation ADD CONSTRAINT entry_id_entryFk FOREIGN KEY (entryFk) REFERENCES vn.entry(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/versions/10815-brownGalax/00-firstScript.sql b/db/versions/10815-brownGalax/00-firstScript.sql new file mode 100644 index 000000000..7812988aa --- /dev/null +++ b/db/versions/10815-brownGalax/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.comparative DROP KEY comparative_UN; +ALTER TABLE vn.comparative ADD CONSTRAINT comparative_unique UNIQUE KEY (timePeriod,itemFk,warehouseFk,countryFk); \ No newline at end of file diff --git a/db/versions/10816-yellowMonstera/00-firstScript.sql b/db/versions/10816-yellowMonstera/00-firstScript.sql new file mode 100644 index 000000000..3dd5378f0 --- /dev/null +++ b/db/versions/10816-yellowMonstera/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.operator MODIFY COLUMN volumeLimit decimal(10,6) DEFAULT NULL NULL COMMENT 'Límite de volumen en una colección para la asignación de pedidos'; diff --git a/db/changes/240401/02-invoiceOutConfig_refLen.sql b/db/versions/10817-navyChico/00-invoiceOutConfig_refLen.sql similarity index 75% rename from db/changes/240401/02-invoiceOutConfig_refLen.sql rename to db/versions/10817-navyChico/00-invoiceOutConfig_refLen.sql index a5f5c2088..8b91889f2 100644 --- a/db/changes/240401/02-invoiceOutConfig_refLen.sql +++ b/db/versions/10817-navyChico/00-invoiceOutConfig_refLen.sql @@ -1,2 +1,2 @@ -ALTER TABLE `vn`.`invoiceOutConfig` +ALTER TABLE vn.invoiceOutConfig ADD IF NOT EXISTS refLen TINYINT UNSIGNED DEFAULT 5 NOT NULL COMMENT 'Invoice reference identifier length'; diff --git a/db/versions/10818-crimsonCamellia/00-firstScript.sql b/db/versions/10818-crimsonCamellia/00-firstScript.sql new file mode 100644 index 000000000..81550be61 --- /dev/null +++ b/db/versions/10818-crimsonCamellia/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplier MODIFY COLUMN isSerious tinyint(1) unsigned DEFAULT 0 NOT NULL; diff --git a/db/versions/10819-blueIvy/00-firstScript.sql b/db/versions/10819-blueIvy/00-firstScript.sql new file mode 100644 index 000000000..b9145ec69 --- /dev/null +++ b/db/versions/10819-blueIvy/00-firstScript.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` + SQL SECURITY DEFINER + VIEW `vn`.`ticketStateToday` +AS SELECT + `ts`.`ticketFk` AS `ticketFk`, + `ts`.`state` AS `state`, + `ts`.`productionOrder` AS `productionOrder`, + `ts`.`alertLevel` AS `alertLevel`, + `ts`.`userFk` AS `userFk`, + `ts`.`code` AS `code`, + `ts`.`updated` AS `updated`, + `ts`.`isPicked` AS `isPicked` +FROM + (`vn`.`ticketState` `ts` +JOIN `vn`.`ticket` `t` ON + (`t`.`id` = `ts`.`ticketFk`)) +WHERE + `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `vn`.`MIDNIGHT`(`util`.`VN_CURDATE`()); diff --git a/db/versions/10820-limeAspidistra/00-grants.sql b/db/versions/10820-limeAspidistra/00-grants.sql new file mode 100644 index 000000000..5e85236d4 --- /dev/null +++ b/db/versions/10820-limeAspidistra/00-grants.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_replaceItem`() BEGIN END; +GRANT EXECUTE ON PROCEDURE `vn`.`sale_replaceItem` TO `employee`; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`worker_isInDepartment`() + RETURNS int(11) + DETERMINISTIC +BEGIN + RETURN 1; +END$$ +DELIMITER ; + +GRANT EXECUTE ON FUNCTION `vn`.`worker_isInDepartment` TO `employee`; +FLUSH PRIVILEGES; diff --git a/db/versions/10827-purpleRaphis/00-firstScript.sql b/db/versions/10827-purpleRaphis/00-firstScript.sql new file mode 100644 index 000000000..6f3a48ff1 --- /dev/null +++ b/db/versions/10827-purpleRaphis/00-firstScript.sql @@ -0,0 +1,10 @@ +-- Place your SQL code here +CREATE TABLE `vn`.`negativeOrigin` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `itemFk` INT NOT NULL, + `type` ENUM('FALTAS', 'CONTENEDOR', 'ENTRADAS', 'OVERBOOKING') NOT NULL, + `dated` DATE DEFAULT CURRENT_DATE, + `quantity` DECIMAL(10,2) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_constraint` (`itemFk`, `type`, `dated`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/db/versions/10828-purpleRuscus/00-firstScript.sql b/db/versions/10828-purpleRuscus/00-firstScript.sql new file mode 100644 index 000000000..6a02da353 --- /dev/null +++ b/db/versions/10828-purpleRuscus/00-firstScript.sql @@ -0,0 +1 @@ +REVOKE SELECT ON TABLE vn2008.clientes_regalos_lista_enc FROM employee; \ No newline at end of file diff --git a/db/versions/10828-purpleRuscus/01-RevokeClientes_regalos_lista.sql b/db/versions/10828-purpleRuscus/01-RevokeClientes_regalos_lista.sql new file mode 100644 index 000000000..7971d9e47 --- /dev/null +++ b/db/versions/10828-purpleRuscus/01-RevokeClientes_regalos_lista.sql @@ -0,0 +1 @@ +REVOKE SELECT ON TABLE vn2008.credit FROM financialBoss; \ No newline at end of file diff --git a/db/changes/240601/00-util_tx_commit.sql b/db/versions/10832-purpleAralia/00-util_tx_commit.sql similarity index 100% rename from db/changes/240601/00-util_tx_commit.sql rename to db/versions/10832-purpleAralia/00-util_tx_commit.sql diff --git a/db/changes/240601/00-util_tx_rollback.sql b/db/versions/10832-purpleAralia/00-util_tx_rollback.sql similarity index 100% rename from db/changes/240601/00-util_tx_rollback.sql rename to db/versions/10832-purpleAralia/00-util_tx_rollback.sql diff --git a/db/changes/240601/00-util_tx_start.sql b/db/versions/10832-purpleAralia/00-util_tx_start.sql similarity index 100% rename from db/changes/240601/00-util_tx_start.sql rename to db/versions/10832-purpleAralia/00-util_tx_start.sql diff --git a/db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql b/db/versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql similarity index 100% rename from db/changes/240601/00-update_procedure_TravelCloneWithEntries.sql rename to db/versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql diff --git a/db/changes/240601/00-grant_privileges_util_tx.sql b/db/versions/10832-purpleAralia/02-grant_privileges_util_tx.sql similarity index 100% rename from db/changes/240601/00-grant_privileges_util_tx.sql rename to db/versions/10832-purpleAralia/02-grant_privileges_util_tx.sql diff --git a/myt.config.yml b/myt.config.yml index 56ab7818a..59cb47be7 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -3,7 +3,6 @@ versionSchema: util replace: true sumViews: false mockDate: '2001-01-01 12:00:00' -subdir: db schemas: - account - bi @@ -72,7 +71,7 @@ fixtures: - ticketUpdateAction - volumeConfig - workCenter - - workerBusinessAgreement + - workerTimeControlError cache: - cache hedera: From 81639726b213fe3ce21426497d3fa7d6106acd03 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 26 Jan 2024 00:09:24 +0100 Subject: [PATCH 097/116] feat: refs #5483 final merge --- back/tests.js | 4 +- db/dump/.dump/data.sql | 2 +- db/dump/fixtures.after.sql | 51 ++++++++----------- .../vn/views/zoneEstimatedDelivery.sql | 2 +- e2e/helpers/tests.js | 13 +++-- gulpfile.js | 6 +-- myt.config.yml | 1 + package-lock.json | 14 ++--- package.json | 2 +- 9 files changed, 46 insertions(+), 49 deletions(-) diff --git a/back/tests.js b/back/tests.js index b56b32d94..9946d09ed 100644 --- a/back/tests.js +++ b/back/tests.js @@ -1,6 +1,6 @@ const path = require('path'); -const Myt = require('../../myt/myt'); -const Run = require('../../myt/myt-run'); +const Myt = require('@verdnatura/myt/myt'); +const Run = require('@verdnatura/myt/myt-run'); let dataSources = require('../loopback/server/datasources.json'); let myt; diff --git a/db/dump/.dump/data.sql b/db/dump/.dump/data.sql index 3be5893f7..8bbe54598 100644 --- a/db/dump/.dump/data.sql +++ b/db/dump/.dump/data.sql @@ -4,7 +4,7 @@ USE `util`; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL); -INSERT INTO `version` VALUES ('vn-database','10818','c156178ea565d81485769882618e122d9cba5d4e','2024-01-25 10:00:48','10831'); +INSERT INTO `version` VALUES ('vn-database','10818','b7edbbe12f35d0cbc3e6b83e54977ac1c8acfc74','2024-01-25 10:00:48','10831'); INSERT INTO `versionLog` VALUES ('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL); INSERT INTO `versionLog` VALUES ('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL); diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index d5eec544f..370ee0e3b 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -9,12 +9,12 @@ SET foreign_key_checks = 0; INSERT INTO util.config (environment, mockTime, mockUtcTime, mockEnabled) VALUES ('local', '2001-01-01 12:00:00', '2001-01-01 11:00:00', TRUE); - +/* #5483 INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, maxLockTime, defaultSupplierFk) VALUES(1, NULL, 1, 300, 1); - +*/ -- XXX: eti - +/* #5483 INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,`ref`,m3,kg,cargoSupplierFk) VALUES (9,'2022-05-20','2022-05-20',13,4,'nine travel',69.0,600,1); @@ -29,7 +29,7 @@ INSERT INTO vn.buy (id,entryFk,itemFk,quantity,dispatched,buyingValue,freightVal (17,10,2,450,0,5.0,1.0,0,1,10,10,0,0.0,1.0,'3',0.0,7.3,7.0,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), (18,10,15,500,0,55.0,1.0,0,1,1,1,0,0.0,1.0,'5',0.0,78.3,75.6,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5), (19,10,11,5000,0,50.0,1.0,0,1,1,1,1,0.0,1.0,'4',0.0,99.6,99.4,0.0,0,0,1,0,'2022-06-20 00:00:00',0,2.5); - +*/ INSERT INTO vn2008.Splits (Id_Split,Id_Ticket,Id_Entrada,Fecha,Notas) VALUES (1,7,2,'00-00-0000 00:00:00.000','nota1'), @@ -37,8 +37,6 @@ INSERT INTO vn2008.Splits (Id_Split,Id_Ticket,Id_Entrada,Fecha,Notas) (3,15,7,'00-00-0000 00:00:00.000','nota3'), (4,22,10,'00-00-0000 00:00:00.000','nota4'); --- XXX: ent - -- XXX: enc INSERT INTO vn.mdbVersion (app, branchFk, version) @@ -51,17 +49,16 @@ UPDATE vn.warehouse UPDATE vn.packaging SET freightItemFk = 1, isBox = 1 WHERE id = '94'; - +/* #5483 INSERT INTO `vn`.`packagingConfig`(`upperGap`, `defaultSmallPackageFk`, `defaultBigPackageFk`) VALUES ('10', 1, 2); - +*/ UPDATE vn.packaging SET freightItemFk=1 WHERE id='1'; UPDATE vn.packaging SET freightItemFk=1 WHERE id='2'; INSERT INTO vn.packagingWithFreight (packagingFk, priority) VALUES('1', 1); - INSERT INTO vn.cmrConfig (dayOfMonth, landingDays) VALUES(5, 1); @@ -76,8 +73,6 @@ INSERT INTO vn.cmr (id, truckPlate, observations, senderInstruccions, paymentIns UPDATE `vn`.`claimRatio` SET `claimAmount` = '10' WHERE (`clientFk` = '1101'); -UPDATE `util`.`config` SET `environment` = 'local' WHERE (`id` = '1'); - INSERT INTO `vn`.`agency` (`name`, `warehouseFk`, `warehouseAliasFk`, `isOwn`, `isAnyVolumeAllowed`) VALUES ('Agencia', '1', '1', '1', '1'), ('Otra agencia ', '1', '2', '0', '0'); @@ -91,11 +86,11 @@ INSERT INTO vn.client (id,name,defaultAddressFk,street,fi,email,dueDay,isTaxData INSERT INTO vn.address (clientFk,street,city,provinceFk,postalCode,nickname,isEqualizated,isLogifloraAllowed,isDefaultAddress) VALUES (100,'rootStreet','ALGEMESI',3,'46680','root',0,0,1); - +/* #5483 INSERT INTO vn.ticket (clientFk,warehouseFk,shipped,nickname,refFk,addressFk,routeFk,companyFk,agencyModeFk,landed,zoneFk, totalWithVat, totalWithoutVat) VALUES (100,1,'2025-07-06 00:00:00','Saco de patatas',NULL,103,6,442,1,'2025-07-06',13, 500, 450), (100,1,'2021-07-06 00:00:00','Alubias de la abuelita Enrriqueta','T4444444',103,6,442,1,'2021-07-06',13, 1000, 900); - +*/ INSERT INTO vn.receipt (invoiceFk,amountPaid,payed,workerFk,bankFk,clientFk,isConciliate,companyFk) VALUES ('Cobro mental',999.0,'2021-06-21 00:00:00',9,3,100,1,442), ('Cobro web',50.0,'2022-06-21 00:00:00',9,3,100,1,567); @@ -114,12 +109,12 @@ UPDATE vn.agencyMode UPDATE vn.agencyMode SET deliveryMethodFk=2 WHERE id=2; - +/* #5483 INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) VALUES (100, 3, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 3, NULL, 1, 567, 1, '2022-07-12', 0, 0, 5, NULL, NULL, NULL, NULL, NULL), (100, 4, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 4, NULL, 1, 567, 1, '2022-07-12', 0, 0, 6, NULL, NULL, NULL, NULL, NULL), (100, 5, '2022-07-12 00:00:00', 'root', NULL, 195, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-12 16:18:58', 1, NULL, 5, NULL, 1, 567, 1, '2022-07-12', 0, 0, 1, NULL, NULL, NULL, NULL, NULL); - +*/ INSERT INTO vn.sector (description,warehouseFk) VALUES ('Sector One',1); @@ -128,31 +123,27 @@ INSERT INTO vn.saleGroup (userFk,parkingFk,sectorFk) VALUES INSERT INTO vn.saleGroupDetail (saleFk,saleGroupFk) VALUES (32,1); - +/* #5483 INSERT INTO vn.itemShelving (id,itemFk,visible,shelvingFk,`grouping`,packing,packagingFk,userFk) VALUES (4,1,5,'HEJ',12,12,'2',100); - +*/ INSERT INTO vn.beach (code,warehouseFk) VALUES ('TEST',1); INSERT INTO vn.routesMonitor (routeFk,name,beachFk,m3,expeditionTruckFk) VALUES (1,'TEST','TEST',1.0,1); - +/* #5483 INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) VALUES (1101, 1, '2022-07-19 10:00:00', 'Bruce Wayne', NULL, 1, NULL, NULL, 0, 0, 0, 0, NULL, 0, '2022-07-19 08:14:37', 1, NULL, 1, 1, 1, 442, 1, '2022-07-06', 0, 0, 13, 5.00, 1.00, 80.00, 75.00, NULL); INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded) VALUES (1, 24, 'Ranged weapon longbow 2m', 1.00, NULL, 8.07, 0, 0.00, 0, 0, 0, '2022-07-06 00:00:00', 0); - +*/ INSERT INTO vn2008.zones (zone_id,name,printingOrder) VALUES (1,'zone Test',1); -- XXX: lab -INSERT INTO `hedera`.`imageConfig` (`maxSize`,`url`) - VALUES - ('20', '//verdnatura.es/vn-image-data'); - INSERT INTO `vn`.`businessReasonEnd` (`id`, `reason`) VALUES ('1', 'Baja voluntaria'), @@ -249,7 +240,7 @@ INSERT INTO vn.saleGroupDetail (created, saleFk, saleGroupFk) INSERT INTO vn.saleTracking (saleFk, isChecked, created, originalQuantity, workerFk, id, stateFk) VALUES (15, 1, '2022-07-29 07:56:16', 10.0, 9, 6, 26); - +/* #5483 INSERT INTO vn.ticket (id, clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) VALUES (3000001, 1110, 1, '2022-07-28 21:00:00', 'ATELIER ART FLORAL', NULL, 129, NULL, NULL, 0, 0, 0, 1, NULL, 0, '2022-07-28 20:27:14', 1, NULL, 1, 16, 1, 442, 1, '2022-07-29', 0, 0, 1, 4.00, 0.00, 41.68, 37.42, NULL); @@ -261,7 +252,7 @@ INSERT INTO vn.collection (id, created, workerFk, stateFk, itemPackingTypeFk, sa INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded) VALUES ( 1, 3000001, 'Ranged weapon longbow 2m', 5.00, NULL, 100.39, 0, 0.00, 0, 1, 0, '2022-06-13 00:00:00', 0); - +*/ INSERT INTO vn.collectionColors(code, shelve, wagon, trainFk) VALUES ( 'ROJO', 1, 1, 1); @@ -269,7 +260,7 @@ INSERT INTO vn.collectionColors(code, shelve, wagon, trainFk) INSERT INTO vn.ticketCollection (ticketFk, collectionFk, created, `level`, wagon, smartTagFk, usedShelves, itemCount, liters) VALUES (3000001, 600001, '2022-07-28 20:04:24', 1, 1, NULL, NULL, 6, 122); - +/* #5483 INSERT INTO vn.itemShelving (itemFk, shelvingFk, visible, created, `grouping`, packing, packagingFk, userFk, buyFk) VALUES ( 1, 'HEJ', 4, '2022-07-13 10:33:34', 12, 12, NULL, 9 , 1), @@ -279,14 +270,14 @@ INSERT INTO vn.itemShelving (itemFk, shelvingFk, visible, created, `grouping`, p INSERT INTO vn.operator (workerFk, numberOfWagons, trainFk, itemPackingTypeFk, warehouseFk) VALUES (9, 1, 1, 'V', 1); - +*/ -- XXX: web - +/* #5483 INSERT INTO `hedera`.`config` (`cookieLife`, `defaultForm`) VALUES (15,'cms/home'); INSERT INTO `hedera`.`imageConfig` (`maxSize`, `url`) - VALUES (20, '//verdnatura.es/vn-image-data'); + VALUES (20, '//cdn.verdnatura.es/image'); INSERT INTO `hedera`.`orderConfig` (`employeeFk`, `guestMethod`, `guestAgencyFk`, `defaultCompanyFk`) VALUES (1, 'PICKUP', 1, 442); @@ -300,7 +291,7 @@ UPDATE `vn`.`agencyMode` SET `description` = `name`; INSERT INTO `hedera`.`tpvConfig` (currency, terminal, transactionType, maxAmount, employeeFk, `url`, testMode, testUrl, testKey, merchantUrl) VALUES (978, 1, 0, 2000, 9, 'https://sis.redsys.es/sis/realizarPago', 0, 'https://sis-t.redsys.es:25443/sis/realizarPago', 'sq7HjrUOBfKmC576ILgskD5srU870gJ7', NULL); - +*/ INSERT INTO hedera.tpvMerchantEnable (merchantFk, companyFk) VALUES (1, 442); diff --git a/db/routines/vn/views/zoneEstimatedDelivery.sql b/db/routines/vn/views/zoneEstimatedDelivery.sql index 081ccb0bd..cfd837add 100644 --- a/db/routines/vn/views/zoneEstimatedDelivery.sql +++ b/db/routines/vn/views/zoneEstimatedDelivery.sql @@ -19,7 +19,7 @@ FROM ( ( ( `vn`.`ticket` `t` - JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticketFk` = `t`.`id`) + JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `t`.`id`) ) JOIN `vn`.`state` `s` ON(`s`.`id` = `tst`.`state`) ) diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js index adb2f8f72..a4a059622 100644 --- a/e2e/helpers/tests.js +++ b/e2e/helpers/tests.js @@ -3,8 +3,11 @@ require('core-js/stable'); require('regenerator-runtime/runtime'); require('vn-loopback/server/boot/date')(); +const path = require('path'); +const Myt = require('@verdnatura/myt/myt'); +const Run = require('@verdnatura/myt/myt-run'); + const axios = require('axios'); -const Docker = require('../../db/docker.js'); const e2eConfig = require('./config.js'); const log = require('fancy-log'); @@ -18,9 +21,9 @@ async function test() { if (process.argv[2] === 'show') process.env.E2E_SHOW = true; - const container = new Docker('salix-db'); - - await container.run(); + const myt = new Myt(); + await myt.init({workspace: path.join(__dirname, '../..')}); + await myt.run(Run); const Jasmine = require('jasmine'); const jasmine = new Jasmine(); @@ -67,6 +70,8 @@ async function test() { jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; await jasmine.execute(); + + await myt.deinit(); } async function backendStatus() { diff --git a/gulpfile.js b/gulpfile.js index 04510afa7..a4caa6196 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,9 +3,9 @@ const gulp = require('gulp'); const PluginError = require('plugin-error'); const argv = require('minimist')(process.argv.slice(2)); const log = require('fancy-log'); -const Myt = require('../myt/myt'); -const Run = require('../myt/myt-run'); -const Start = require('../myt/myt-start'); +const Myt = require('@verdnatura/myt/myt'); +const Run = require('@verdnatura/myt/myt-run'); +const Start = require('@verdnatura/myt/myt-start'); // Configuration diff --git a/myt.config.yml b/myt.config.yml index 59cb47be7..2e37a0d97 100755 --- a/myt.config.yml +++ b/myt.config.yml @@ -3,6 +3,7 @@ versionSchema: util replace: true sumViews: false mockDate: '2001-01-01 12:00:00' +subdir: db schemas: - account - bi diff --git a/package-lock.json b/package-lock.json index 9c9108fa0..04964d0ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.29", + "@verdnatura/myt": "^1.5.31", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.29", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.29.tgz", - "integrity": "sha512-d8PiGjjEQpEu4MyddRXGgay9gLOsD8V2SBxLws748g1WpECETJUZF8I8YKf/jH4Y91f1bFmW9kJn/PR+gA44ww==", + "version": "1.5.31", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.31.tgz", + "integrity": "sha512-1mh5lY+gYRnvZsJUmc4t5kTyoo4uSvKJBI6KE1H+VEOnF9uuxSlie6srM04KexjzXIlrWa3xnZIYDrXP2D+fAQ==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.29", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.29.tgz", - "integrity": "sha512-d8PiGjjEQpEu4MyddRXGgay9gLOsD8V2SBxLws748g1WpECETJUZF8I8YKf/jH4Y91f1bFmW9kJn/PR+gA44ww==", + "version": "1.5.31", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.31.tgz", + "integrity": "sha512-1mh5lY+gYRnvZsJUmc4t5kTyoo4uSvKJBI6KE1H+VEOnF9uuxSlie6srM04KexjzXIlrWa3xnZIYDrXP2D+fAQ==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index fd122b40a..18742cf56 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.29", + "@verdnatura/myt": "^1.5.31", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 0afc9ab1095f3300c6441c7ce3df80e14a5d5046 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 26 Jan 2024 09:55:21 +0100 Subject: [PATCH 098/116] refs #6174 test: fix test bug --- .../back/methods/invoiceOut/specs/transferinvoice.spec.js | 1 + .../ticket/back/methods/ticket/invoiceTicketsAndPdf.js | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js index 11575999a..eaaef3e26 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/transferinvoice.spec.js @@ -17,6 +17,7 @@ describe('InvoiceOut transferInvoice()', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); + spyOn(models.InvoiceOut, 'makePdfAndNotify'); }); it('should return the id of the created issued invoice', async() => { diff --git a/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js b/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js index 5529a3ae3..2211eb50b 100644 --- a/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js +++ b/modules/ticket/back/methods/ticket/invoiceTicketsAndPdf.js @@ -28,12 +28,8 @@ module.exports = function(Self) { }); Self.invoiceTicketsAndPdf = async(ctx, ticketsIds, invoiceCorrection, options) => { - let invoiceIds = null; - - invoiceIds = await Self.invoiceTickets(ctx, ticketsIds, invoiceCorrection, options); - if (!invoiceIds) return []; - if (!options.transaction) - await Self.app.models.InvoiceOut.makePdfList(ctx, invoiceIds, null, options); + const invoiceIds = await Self.invoiceTickets(ctx, ticketsIds, invoiceCorrection, options); + await Self.app.models.InvoiceOut.makePdfList(ctx, invoiceIds, null, options); return invoiceIds; }; }; From 38c57595d1ad830fec5df8723e513f98f5795c9e Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 26 Jan 2024 10:50:33 +0100 Subject: [PATCH 099/116] feat: refs #6625 Changed default values operator --- db/changes/240601/01-changedDefaultValues.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/changes/240601/01-changedDefaultValues.sql diff --git a/db/changes/240601/01-changedDefaultValues.sql b/db/changes/240601/01-changedDefaultValues.sql new file mode 100644 index 000000000..7393bfe18 --- /dev/null +++ b/db/changes/240601/01-changedDefaultValues.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`operator` MODIFY COLUMN linesLimit int(11) DEFAULT 20 NULL COMMENT 'Límite de lineas en una colección para la asignación de pedidos'; +ALTER TABLE `vn`.`operator` MODIFY COLUMN volumeLimit decimal(10,6) DEFAULT 0.5 NULL COMMENT 'Límite de volumen en una colección para la asignación de pedidos'; +ALTER TABLE `vn`.`operator` MODIFY COLUMN numberOfWagons int(11) DEFAULT 2 NULL; From ce0684e6ffc6b9098c2725027036980bb0fe2ac2 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 28 Jan 2024 12:40:13 +0100 Subject: [PATCH 100/116] fix: refs #5483 myt updated, jenkins tests and fixtures fixes --- Jenkinsfile | 10 ++++++---- back/tests.js | 3 ++- db/dump/fixtures.after.sql | 8 ++++---- package-lock.json | 14 +++++++------- package.json | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cf9b8cd67..507e5d1f6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -106,13 +106,15 @@ pipeline { }} steps { configFileProvider([ - configFile(fileId: "config.${env.NODE_ENV}.ini", + configFile(fileId: "config.${NODE_ENV}.ini", variable: 'MYSQL_CONFIG') ]) { - sh 'cp "$MYSQL_CONFIG" db/config.$NODE_ENV.ini' + sh 'mkdir -p db/remotes' + sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini' + } + nodejs('node-v20') { + sh 'npx myt push $NODE_ENV --force --commit' } - - sh 'db/import-changes.sh -f $NODE_ENV' } } } diff --git a/back/tests.js b/back/tests.js index 9946d09ed..45d19a671 100644 --- a/back/tests.js +++ b/back/tests.js @@ -26,7 +26,8 @@ async function test() { await myt.init({ workspace: path.join(__dirname, '..'), random: true, - ci: isCI + ci: isCI, + network: isCI ? 'jenkins' : null }); const {dbConfig} = await myt.run(Run); diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index 370ee0e3b..57ccb8626 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -14,10 +14,10 @@ INSERT INTO vn.entryConfig (defaultEntry, mailToNotify, inventorySupplierFk, max VALUES(1, NULL, 1, 300, 1); */ -- XXX: eti -/* #5483 + INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,`ref`,m3,kg,cargoSupplierFk) VALUES (9,'2022-05-20','2022-05-20',13,4,'nine travel',69.0,600,1); - +/* #5483 INSERT INTO vn.entry (id, supplierFk, dated, invoiceNumber, evaNotes, travelFk, companyFk) VALUES (9, 1, '0000-00-00 00:00:00', 'Movement 9', 'observation nine', 8, 442), @@ -222,10 +222,10 @@ INSERT INTO vn.expeditionStateType (id, description, code) INSERT INTO vn.expedition (agencyModeFk,ticketFk,isBox,counter,hostFk,hasNewRoute) VALUES (1,21,1,1,'',0); - +/* #5483 INSERT INTO vn.sectorCollection (id, created, userFk, sectorFk) VALUES(18, '2022-07-29 09:03:31', 9, 1); - +*/ INSERT INTO vn.saleGroup (id, created, userFk, parkingFk, sectorFk) VALUES(3, '2022-07-29 07:18:49', 9, NULL, 1); diff --git a/package-lock.json b/package-lock.json index 04964d0ff..cab69c696 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.31", + "@verdnatura/myt": "^1.5.32", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.31", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.31.tgz", - "integrity": "sha512-1mh5lY+gYRnvZsJUmc4t5kTyoo4uSvKJBI6KE1H+VEOnF9uuxSlie6srM04KexjzXIlrWa3xnZIYDrXP2D+fAQ==", + "version": "1.5.32", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.32.tgz", + "integrity": "sha512-LAxg2Ri+QWuFjWbm9Hf5iPE4i5qqGTrKtgwOuNzTri8bErCwPbQRJWgIJBv4xKTppXTm7tBWOUF4+IBf6Ep8Nw==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.31", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.31.tgz", - "integrity": "sha512-1mh5lY+gYRnvZsJUmc4t5kTyoo4uSvKJBI6KE1H+VEOnF9uuxSlie6srM04KexjzXIlrWa3xnZIYDrXP2D+fAQ==", + "version": "1.5.32", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.32.tgz", + "integrity": "sha512-LAxg2Ri+QWuFjWbm9Hf5iPE4i5qqGTrKtgwOuNzTri8bErCwPbQRJWgIJBv4xKTppXTm7tBWOUF4+IBf6Ep8Nw==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 18742cf56..446ee7db0 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.31", + "@verdnatura/myt": "^1.5.32", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 49f2a66b093d11c16fc2a6f40628bea535d0a39b Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 28 Jan 2024 12:49:43 +0100 Subject: [PATCH 101/116] fix: refs #5483 myt updated --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index cab69c696..aef0d0d73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.32", + "@verdnatura/myt": "^1.5.33", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.32", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.32.tgz", - "integrity": "sha512-LAxg2Ri+QWuFjWbm9Hf5iPE4i5qqGTrKtgwOuNzTri8bErCwPbQRJWgIJBv4xKTppXTm7tBWOUF4+IBf6Ep8Nw==", + "version": "1.5.33", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.33.tgz", + "integrity": "sha512-ZnkXBKI/eSgaBwGzoHS0hIjPA6o7tZ5hdKrP/kIz367sE8ovRUH1svSd4PjzZywwA6AZEiukDF4mCQAN+e+5Cw==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.32", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.32.tgz", - "integrity": "sha512-LAxg2Ri+QWuFjWbm9Hf5iPE4i5qqGTrKtgwOuNzTri8bErCwPbQRJWgIJBv4xKTppXTm7tBWOUF4+IBf6Ep8Nw==", + "version": "1.5.33", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.33.tgz", + "integrity": "sha512-ZnkXBKI/eSgaBwGzoHS0hIjPA6o7tZ5hdKrP/kIz367sE8ovRUH1svSd4PjzZywwA6AZEiukDF4mCQAN+e+5Cw==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 446ee7db0..4e9fde3c6 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.32", + "@verdnatura/myt": "^1.5.33", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 04091353e26379a4f04e816512bf3b143f65108b Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 28 Jan 2024 12:58:10 +0100 Subject: [PATCH 102/116] fix: refs #5483 myt updated --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index aef0d0d73..273514e83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.33", + "@verdnatura/myt": "^1.5.34", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.33", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.33.tgz", - "integrity": "sha512-ZnkXBKI/eSgaBwGzoHS0hIjPA6o7tZ5hdKrP/kIz367sE8ovRUH1svSd4PjzZywwA6AZEiukDF4mCQAN+e+5Cw==", + "version": "1.5.34", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.34.tgz", + "integrity": "sha512-J8MHXsB0yQMTmMAKMzWETpL6bjN1UVY7D9QcB3oT4eKTQazSnxwMLKarJEex/bMM+wKfuQo+o8vvhEv6Xv9WAw==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.33", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.33.tgz", - "integrity": "sha512-ZnkXBKI/eSgaBwGzoHS0hIjPA6o7tZ5hdKrP/kIz367sE8ovRUH1svSd4PjzZywwA6AZEiukDF4mCQAN+e+5Cw==", + "version": "1.5.34", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.34.tgz", + "integrity": "sha512-J8MHXsB0yQMTmMAKMzWETpL6bjN1UVY7D9QcB3oT4eKTQazSnxwMLKarJEex/bMM+wKfuQo+o8vvhEv6Xv9WAw==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 4e9fde3c6..b1f309896 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.33", + "@verdnatura/myt": "^1.5.34", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 52cb1c496a376e4412fcc59a2a8e62312ba011d1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 28 Jan 2024 14:34:53 +0100 Subject: [PATCH 103/116] fix: refs #5483 myt updated, front test workers increased to 4 --- Jenkinsfile | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 507e5d1f6..c8a0579d7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,7 +58,7 @@ pipeline { stage('Frontend') { steps { nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=4' } } } diff --git a/package-lock.json b/package-lock.json index 273514e83..859fbcf6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.34", + "@verdnatura/myt": "^1.6.0", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.5.34", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.34.tgz", - "integrity": "sha512-J8MHXsB0yQMTmMAKMzWETpL6bjN1UVY7D9QcB3oT4eKTQazSnxwMLKarJEex/bMM+wKfuQo+o8vvhEv6Xv9WAw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.0.tgz", + "integrity": "sha512-bQWWMTkvX4wQzojp//XmTRLFGTBuVJ+pwNZxSoIl4LjsidCq5FId48qpkFG9E/CBi3gaf7AkbYDD+A8pv1WMUQ==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.5.34", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.5.34.tgz", - "integrity": "sha512-J8MHXsB0yQMTmMAKMzWETpL6bjN1UVY7D9QcB3oT4eKTQazSnxwMLKarJEex/bMM+wKfuQo+o8vvhEv6Xv9WAw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.0.tgz", + "integrity": "sha512-bQWWMTkvX4wQzojp//XmTRLFGTBuVJ+pwNZxSoIl4LjsidCq5FId48qpkFG9E/CBi3gaf7AkbYDD+A8pv1WMUQ==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index b1f309896..0d1fd41bd 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.5.34", + "@verdnatura/myt": "^1.6.0", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 149c2b0293c8041bee94a9e83252cb308c76c9d2 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 Jan 2024 07:39:39 +0100 Subject: [PATCH 104/116] refs #5483 fix: zoneEstimatedDelivery in salix --- .../vn/views/zoneEstimatedDelivery.sql | 67 ++++++------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/db/routines/vn/views/zoneEstimatedDelivery.sql b/db/routines/vn/views/zoneEstimatedDelivery.sql index cfd837add..e52d5487e 100644 --- a/db/routines/vn/views/zoneEstimatedDelivery.sql +++ b/db/routines/vn/views/zoneEstimatedDelivery.sql @@ -1,48 +1,25 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`zoneEstimatedDelivery` -AS SELECT `t`.`zoneFk` AS `zoneFk`, - `zc`.`hour` AS `zoneClosureHour`, - `z`.`hour` AS `zoneHour`, - `sv`.`volume` AS `volume`, - `al`.`hasToRecalcPrice` AS `hasToRecalcPrice`, - `lhp`.`m3` AS `m3`, - `dl`.`minSpeed` AS `minSpeed` -FROM ( - ( - ( - ( - ( - ( - ( - ( - ( - ( - `vn`.`ticket` `t` - JOIN `vn`.`ticketStateToday` `tst` ON(`tst`.`ticket` = `t`.`id`) - ) - JOIN `vn`.`state` `s` ON(`s`.`id` = `tst`.`state`) - ) - JOIN `vn`.`saleVolume` `sv` ON(`sv`.`ticketFk` = `t`.`id`) - ) - LEFT JOIN `vn`.`lastHourProduction` `lhp` ON(`lhp`.`warehouseFk` = `t`.`warehouseFk`) - ) - JOIN `vn`.`warehouse` `w` ON(`w`.`id` = `t`.`warehouseFk`) - ) - JOIN `vn`.`warehouseAlias` `wa` ON(`wa`.`id` = `w`.`aliasFk`) - ) STRAIGHT_JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) - ) - LEFT JOIN `vn`.`zoneClosure` `zc` ON( - `zc`.`zoneFk` = `t`.`zoneFk` - AND `zc`.`dated` = `util`.`VN_CURDATE`() - ) - ) - LEFT JOIN `cache`.`departure_limit` `dl` ON( - `dl`.`warehouse_id` = `t`.`warehouseFk` - AND `dl`.`fecha` = `util`.`VN_CURDATE`() - ) - ) - JOIN `vn`.`alertLevel` `al` ON(`al`.`id` = `s`.`alertLevel`) - ) -WHERE `w`.`hasProduction` <> 0 - AND cast(`t`.`shipped` AS date) = `util`.`VN_CURDATE`() + AS SELECT t.zoneFk, + zc.`hour` zoneClosureHour, + z.`hour` zoneHour, + sv.volume volume, + al.hasToRecalcPrice, + lhp.m3, + dl.minSpeed + FROM ticket t + JOIN ticketStateToday tst ON tst.ticket = t.id + JOIN state s ON s.id = tst.state + JOIN saleVolume sv ON sv.ticketFk = t.id + LEFT JOIN lastHourProduction lhp ON lhp.warehouseFk = t.warehouseFk + JOIN warehouse w ON w.id = t.warehouseFk + JOIN warehouseAlias wa ON wa.id = w.aliasFk + STRAIGHT_JOIN `zone` z ON z.id = t.zoneFk + LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk + AND zc.dated = util.VN_CURDATE() + LEFT JOIN cache.departure_limit dl ON dl.warehouse_id = t.warehouseFk + AND dl.fecha = util.VN_CURDATE() + JOIN alertLevel al ON al.id = s.alertLevel + WHERE w.hasProduction + AND DATE(t.shipped) = util.VN_CURDATE() From c91cf660bedcaf91e0f1bec12d7ce8ae151fb1f5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 29 Jan 2024 11:14:02 +0100 Subject: [PATCH 105/116] feat: #6625 Changed version to myt --- db/changes/240601/01-changedDefaultValues.sql | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 db/changes/240601/01-changedDefaultValues.sql diff --git a/db/changes/240601/01-changedDefaultValues.sql b/db/changes/240601/01-changedDefaultValues.sql deleted file mode 100644 index 7393bfe18..000000000 --- a/db/changes/240601/01-changedDefaultValues.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `vn`.`operator` MODIFY COLUMN linesLimit int(11) DEFAULT 20 NULL COMMENT 'Límite de lineas en una colección para la asignación de pedidos'; -ALTER TABLE `vn`.`operator` MODIFY COLUMN volumeLimit decimal(10,6) DEFAULT 0.5 NULL COMMENT 'Límite de volumen en una colección para la asignación de pedidos'; -ALTER TABLE `vn`.`operator` MODIFY COLUMN numberOfWagons int(11) DEFAULT 2 NULL; From 2268ef377fb961e1f31ff72898e6d424b53d7029 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 29 Jan 2024 12:32:50 +0100 Subject: [PATCH 106/116] feat: #6625 Changed version to myt --- db/versions/10845-silverOrchid/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/10845-silverOrchid/00-firstScript.sql diff --git a/db/versions/10845-silverOrchid/00-firstScript.sql b/db/versions/10845-silverOrchid/00-firstScript.sql new file mode 100644 index 000000000..7393bfe18 --- /dev/null +++ b/db/versions/10845-silverOrchid/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`operator` MODIFY COLUMN linesLimit int(11) DEFAULT 20 NULL COMMENT 'Límite de lineas en una colección para la asignación de pedidos'; +ALTER TABLE `vn`.`operator` MODIFY COLUMN volumeLimit decimal(10,6) DEFAULT 0.5 NULL COMMENT 'Límite de volumen en una colección para la asignación de pedidos'; +ALTER TABLE `vn`.`operator` MODIFY COLUMN numberOfWagons int(11) DEFAULT 2 NULL; From 9bf08f31ae0441ab0262c61c9c4dc372d325a269 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 29 Jan 2024 14:10:22 +0100 Subject: [PATCH 107/116] refs #6174 feat: replace method in salix-front --- modules/ticket/front/descriptor-menu/index.js | 2 +- modules/ticket/front/index/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index cd819e623..297d8ee1b 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -265,7 +265,7 @@ class Controller extends Section { }); } - return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]}) + return this.$http.post(`Tickets/invoiceTicketsAndPdf`, {ticketsIds: [this.id]}) .then(() => this.reload()) .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); } diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index b3afc838c..489f677a3 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -163,7 +163,7 @@ export default class Controller extends Section { makeInvoice() { const ticketsIds = this.checked.map(ticket => ticket.id); - return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds}) + return this.$http.post(`Tickets/invoiceTicketsAndPdf`, {ticketsIds}) .then(() => this.$.model.refresh()) .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); } From 5396b402a53472f1a635532ad60ef791ce8e9122 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 29 Jan 2024 14:10:30 +0100 Subject: [PATCH 108/116] refs #6174 feat: acl --- db/versions/10848-blackAspidistra/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/10848-blackAspidistra/00-firstScript.sql diff --git a/db/versions/10848-blackAspidistra/00-firstScript.sql b/db/versions/10848-blackAspidistra/00-firstScript.sql new file mode 100644 index 000000000..cc9a59a24 --- /dev/null +++ b/db/versions/10848-blackAspidistra/00-firstScript.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES + ('Ticket', 'makePdfList', '*', 'ALLOW', 'ROLE', 'employee'), + ('Ticket', 'invoiceTicketsAndPdf', '*', 'ALLOW', 'ROLE', 'employee'); From 8484afe2ea98fd950aaa4decb2b7b76a53d88107 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 29 Jan 2024 14:29:10 +0100 Subject: [PATCH 109/116] refactor: #6725 Deleted originFk from log tables --- db/versions/10849-chocolateCymbidium/00-roleLog.sql | 1 + db/versions/10849-chocolateCymbidium/01-userLog.sql | 1 + db/versions/10849-chocolateCymbidium/02-entryLog.sql | 1 + db/versions/10849-chocolateCymbidium/03-clientLog.sql | 1 + db/versions/10849-chocolateCymbidium/04-itemLog.sql | 1 + db/versions/10849-chocolateCymbidium/05-shelvingLog.sql | 1 + db/versions/10849-chocolateCymbidium/06-workerLog.sql | 1 + db/versions/10849-chocolateCymbidium/07-deviceProductionLog.sql | 1 + db/versions/10849-chocolateCymbidium/08-zoneLog.sql | 1 + db/versions/10849-chocolateCymbidium/09-rateLog.sql | 1 + db/versions/10849-chocolateCymbidium/10-ticketLog.sql | 1 + db/versions/10849-chocolateCymbidium/11-userLog.sql | 1 + db/versions/10849-chocolateCymbidium/12-routeLog.sql | 1 + db/versions/10849-chocolateCymbidium/13-claimLog.sql | 1 + db/versions/10849-chocolateCymbidium/14-supplierLog.sql | 1 + db/versions/10849-chocolateCymbidium/15-invoiceInLog.sql | 1 + db/versions/10849-chocolateCymbidium/16-travelLog.sql | 1 + db/versions/10849-chocolateCymbidium/17-packingSiteDeviceLog.sql | 1 + 18 files changed, 18 insertions(+) create mode 100644 db/versions/10849-chocolateCymbidium/00-roleLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/01-userLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/02-entryLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/03-clientLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/04-itemLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/05-shelvingLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/06-workerLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/07-deviceProductionLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/08-zoneLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/09-rateLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/10-ticketLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/11-userLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/12-routeLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/13-claimLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/14-supplierLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/15-invoiceInLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/16-travelLog.sql create mode 100644 db/versions/10849-chocolateCymbidium/17-packingSiteDeviceLog.sql diff --git a/db/versions/10849-chocolateCymbidium/00-roleLog.sql b/db/versions/10849-chocolateCymbidium/00-roleLog.sql new file mode 100644 index 000000000..0f2eb1953 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/00-roleLog.sql @@ -0,0 +1 @@ +ALTER TABLE account.roleLog DROP FOREIGN KEY roleLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/01-userLog.sql b/db/versions/10849-chocolateCymbidium/01-userLog.sql new file mode 100644 index 000000000..87d687afe --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/01-userLog.sql @@ -0,0 +1 @@ +ALTER TABLE account.userLog DROP FOREIGN KEY userLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/02-entryLog.sql b/db/versions/10849-chocolateCymbidium/02-entryLog.sql new file mode 100644 index 000000000..e273f54a3 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/02-entryLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entryLog DROP FOREIGN KEY entryLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/03-clientLog.sql b/db/versions/10849-chocolateCymbidium/03-clientLog.sql new file mode 100644 index 000000000..38a3424a1 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/03-clientLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.clientLog DROP FOREIGN KEY clientLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/04-itemLog.sql b/db/versions/10849-chocolateCymbidium/04-itemLog.sql new file mode 100644 index 000000000..7ad6a6b15 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/04-itemLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.itemLog DROP FOREIGN KEY itemLogItemFk; diff --git a/db/versions/10849-chocolateCymbidium/05-shelvingLog.sql b/db/versions/10849-chocolateCymbidium/05-shelvingLog.sql new file mode 100644 index 000000000..031921bdf --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/05-shelvingLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.shelvingLog DROP FOREIGN KEY shelvingLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/06-workerLog.sql b/db/versions/10849-chocolateCymbidium/06-workerLog.sql new file mode 100644 index 000000000..c8d4faf44 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/06-workerLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.workerLog DROP FOREIGN KEY workerFk; diff --git a/db/versions/10849-chocolateCymbidium/07-deviceProductionLog.sql b/db/versions/10849-chocolateCymbidium/07-deviceProductionLog.sql new file mode 100644 index 000000000..1cd5b54e9 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/07-deviceProductionLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.deviceProductionLog DROP FOREIGN KEY deviceProductionOriginFk; diff --git a/db/versions/10849-chocolateCymbidium/08-zoneLog.sql b/db/versions/10849-chocolateCymbidium/08-zoneLog.sql new file mode 100644 index 000000000..b4ed11043 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/08-zoneLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.zoneLog DROP FOREIGN KEY zoneLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/09-rateLog.sql b/db/versions/10849-chocolateCymbidium/09-rateLog.sql new file mode 100644 index 000000000..33e2d4b93 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/09-rateLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.rateLog DROP FOREIGN KEY rateOriginFk; diff --git a/db/versions/10849-chocolateCymbidium/10-ticketLog.sql b/db/versions/10849-chocolateCymbidium/10-ticketLog.sql new file mode 100644 index 000000000..e7117d3c6 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/10-ticketLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticketLog DROP FOREIGN KEY ticketLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/11-userLog.sql b/db/versions/10849-chocolateCymbidium/11-userLog.sql new file mode 100644 index 000000000..44aa9c495 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/11-userLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.userLog DROP FOREIGN KEY userLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/12-routeLog.sql b/db/versions/10849-chocolateCymbidium/12-routeLog.sql new file mode 100644 index 000000000..dbe8ce143 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/12-routeLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.routeLog DROP FOREIGN KEY routeLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/13-claimLog.sql b/db/versions/10849-chocolateCymbidium/13-claimLog.sql new file mode 100644 index 000000000..23ac00c9a --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/13-claimLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.claimLog DROP FOREIGN KEY claimOriginFk; diff --git a/db/versions/10849-chocolateCymbidium/14-supplierLog.sql b/db/versions/10849-chocolateCymbidium/14-supplierLog.sql new file mode 100644 index 000000000..53626bbd9 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/14-supplierLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.supplierLog DROP FOREIGN KEY supplierLog_supplierFk; diff --git a/db/versions/10849-chocolateCymbidium/15-invoiceInLog.sql b/db/versions/10849-chocolateCymbidium/15-invoiceInLog.sql new file mode 100644 index 000000000..18f015196 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/15-invoiceInLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.invoiceInLog DROP FOREIGN KEY invoiceInLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/16-travelLog.sql b/db/versions/10849-chocolateCymbidium/16-travelLog.sql new file mode 100644 index 000000000..18e68e376 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/16-travelLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.travelLog DROP FOREIGN KEY travelLog_ibfk_1; diff --git a/db/versions/10849-chocolateCymbidium/17-packingSiteDeviceLog.sql b/db/versions/10849-chocolateCymbidium/17-packingSiteDeviceLog.sql new file mode 100644 index 000000000..2119c24d9 --- /dev/null +++ b/db/versions/10849-chocolateCymbidium/17-packingSiteDeviceLog.sql @@ -0,0 +1 @@ +ALTER TABLE vn.packingSiteDeviceLog DROP FOREIGN KEY packingSiteDeviceLog_ibfk_1; From 2e0da0881bceb6667840f6c72ac6343eb5af4d93 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 29 Jan 2024 14:54:19 +0100 Subject: [PATCH 110/116] refs #6174 test: fix method --- modules/ticket/front/descriptor-menu/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index c755b14c3..6d74881b8 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -191,7 +191,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { jest.spyOn(controller.vnApp, 'showSuccess'); const expectedParams = {ticketsIds: [ticket.id]}; - $httpBackend.expectPOST(`Tickets/invoiceTickets`, expectedParams).respond(); + $httpBackend.expectPOST(`Tickets/invoiceTicketsAndPdf`, expectedParams).respond(); controller.makeInvoice(); $httpBackend.flush(); From a3442d488739b204d70df27277bb086c17e7f1dc Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 29 Jan 2024 15:47:46 +0100 Subject: [PATCH 111/116] fix: refs #6276 fixtures --- db/dump/fixtures.before.sql | 7 ++++--- e2e/paths/05-ticket/02_expeditions_and_log.spec.js | 2 +- e2e/paths/13-supplier/02_basic_data.spec.js | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6a58b60f5..0f608d19d 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -6,9 +6,10 @@ */ SET foreign_key_checks = 0; --- CREATE ROLE 'salix'; --- GRANT 'salix' TO 'root'@'%'; --- SET DEFAULT ROLE 'salix' FOR 'root'@'%'; +DROP ROLE 'salix'; +CREATE ROLE 'salix'; +GRANT 'salix' TO 'root'@'%'; +SET DEFAULT ROLE 'salix' FOR 'root'@'%'; CREATE SCHEMA IF NOT EXISTS `vn2008`; CREATE SCHEMA IF NOT EXISTS `tmp`; diff --git a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js index b97576940..4e8005043 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -27,6 +27,6 @@ describe('Ticket expeditions and log path', () => { const result = await page .countElement(selectors.ticketExpedition.expeditionRow); - expect(result).toEqual(4); + expect(result).toEqual(6); }); }); diff --git a/e2e/paths/13-supplier/02_basic_data.spec.js b/e2e/paths/13-supplier/02_basic_data.spec.js index 72ea6d890..582e2fb62 100644 --- a/e2e/paths/13-supplier/02_basic_data.spec.js +++ b/e2e/paths/13-supplier/02_basic_data.spec.js @@ -44,7 +44,7 @@ describe('Supplier basic data path', () => { it('should check the isSerious checkbox is now unchecked', async() => { const result = await page.checkboxState(selectors.supplierBasicData.isSerious); - expect(result).toBe('unchecked'); + expect(result).toBe('checked'); }); it('should check the isActive checkbox is now unchecked', async() => { From 7c18e22c38cbf600f82153203f08aa5452074649 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 29 Jan 2024 20:16:03 +0100 Subject: [PATCH 112/116] feat: refs #5483 myt updated, back tests now use tmpfs for DB --- back/tests.js | 1 + package-lock.json | 14 +++++++------- package.json | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/back/tests.js b/back/tests.js index 45d19a671..a9cdeb338 100644 --- a/back/tests.js +++ b/back/tests.js @@ -27,6 +27,7 @@ async function test() { workspace: path.join(__dirname, '..'), random: true, ci: isCI, + tmpfs: true, network: isCI ? 'jenkins' : null }); const {dbConfig} = await myt.run(Run); diff --git a/package-lock.json b/package-lock.json index 859fbcf6e..1cde1277e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.0", + "@verdnatura/myt": "^1.6.2", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.0.tgz", - "integrity": "sha512-bQWWMTkvX4wQzojp//XmTRLFGTBuVJ+pwNZxSoIl4LjsidCq5FId48qpkFG9E/CBi3gaf7AkbYDD+A8pv1WMUQ==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.2.tgz", + "integrity": "sha512-ATgpNoXK0LYrMOv6r32HNYY0YW0aVVtu/yhT57waPuIKmesE+ZVoWMtkm7ezY+3T95d1C0z849fBnp1ttbqvFA==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.0.tgz", - "integrity": "sha512-bQWWMTkvX4wQzojp//XmTRLFGTBuVJ+pwNZxSoIl4LjsidCq5FId48qpkFG9E/CBi3gaf7AkbYDD+A8pv1WMUQ==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.2.tgz", + "integrity": "sha512-ATgpNoXK0LYrMOv6r32HNYY0YW0aVVtu/yhT57waPuIKmesE+ZVoWMtkm7ezY+3T95d1C0z849fBnp1ttbqvFA==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 0d1fd41bd..164dbf15d 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.0", + "@verdnatura/myt": "^1.6.2", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From c63a323c12df853bab41d39347943611102fd2de Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 29 Jan 2024 20:23:51 +0100 Subject: [PATCH 113/116] fix: refs #5483 Myt updated --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1cde1277e..d04a12a14 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.2", + "@verdnatura/myt": "^1.6.3", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", @@ -3375,9 +3375,9 @@ } }, "node_modules/@verdnatura/myt": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.2.tgz", - "integrity": "sha512-ATgpNoXK0LYrMOv6r32HNYY0YW0aVVtu/yhT57waPuIKmesE+ZVoWMtkm7ezY+3T95d1C0z849fBnp1ttbqvFA==", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.3.tgz", + "integrity": "sha512-VRoTB5sEPL8a7VaX9l2afpaPNT6pBa+If1tP9tpaJ4enFQbNITlApcC0GK6XYmWMkJQjl2lgdN4/u0UCiNb2MQ==", "dev": true, "dependencies": { "@sqltools/formatter": "^1.2.5", @@ -30604,9 +30604,9 @@ } }, "@verdnatura/myt": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.2.tgz", - "integrity": "sha512-ATgpNoXK0LYrMOv6r32HNYY0YW0aVVtu/yhT57waPuIKmesE+ZVoWMtkm7ezY+3T95d1C0z849fBnp1ttbqvFA==", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/@verdnatura/myt/-/myt-1.6.3.tgz", + "integrity": "sha512-VRoTB5sEPL8a7VaX9l2afpaPNT6pBa+If1tP9tpaJ4enFQbNITlApcC0GK6XYmWMkJQjl2lgdN4/u0UCiNb2MQ==", "dev": true, "requires": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 164dbf15d..3f3a3ad8e 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.7.4", "@babel/preset-env": "^7.11.0", "@babel/register": "^7.7.7", - "@verdnatura/myt": "^1.6.2", + "@verdnatura/myt": "^1.6.3", "angular-mocks": "^1.7.9", "babel-jest": "^26.0.1", "babel-loader": "^8.2.4", From 8ea1600f4ac561e4e6e93ca1aacd0d954bd7427d Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 30 Jan 2024 08:11:21 +0100 Subject: [PATCH 114/116] fix: refs #6276 test title --- e2e/paths/13-supplier/02_basic_data.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/13-supplier/02_basic_data.spec.js b/e2e/paths/13-supplier/02_basic_data.spec.js index 582e2fb62..79a9898ca 100644 --- a/e2e/paths/13-supplier/02_basic_data.spec.js +++ b/e2e/paths/13-supplier/02_basic_data.spec.js @@ -41,7 +41,7 @@ describe('Supplier basic data path', () => { expect(result).toEqual('Plants Nick SL'); }); - it('should check the isSerious checkbox is now unchecked', async() => { + it('should check the isSerious checkbox is now checked', async() => { const result = await page.checkboxState(selectors.supplierBasicData.isSerious); expect(result).toBe('checked'); From c80c8a567887a114c28ea2cb7e303fb80c68eb18 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jan 2024 10:00:35 +0100 Subject: [PATCH 115/116] fix: refs #5483 No apply changes of db in dev --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index c8a0579d7..c65b01d47 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -101,6 +101,7 @@ pipeline { } stage('Database') { when { anyOf { + branch 'dev' branch 'test' branch 'master' }} From c1726f93904ad909fb1b9c8c89eae228c58db492 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 10:23:32 +0100 Subject: [PATCH 116/116] fix: refs #5483 Remove DB container when back tests end --- back/tests.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/back/tests.js b/back/tests.js index a9cdeb338..c4c477090 100644 --- a/back/tests.js +++ b/back/tests.js @@ -1,9 +1,10 @@ +/* eslint-disable no-console */ const path = require('path'); const Myt = require('@verdnatura/myt/myt'); const Run = require('@verdnatura/myt/myt-run'); let dataSources = require('../loopback/server/datasources.json'); -let myt; +let server; process.on('warning', warning => { console.log(warning.name); @@ -11,26 +12,33 @@ process.on('warning', warning => { console.log(warning.stack); }); -process.on('SIGUSR2', async() => { - if (myt) await myt.deinit(); -}); +process.on('SIGUSR2', rmServer); +process.on('exit', rmServer); -process.on('exit', async function() { - if (myt) await myt.deinit(); -}); +async function rmServer() { + if (!server) return; + await server.rm(); + server = null; +} async function test() { + console.log('Building and running DB container.'); + const isCI = process.argv[2] === 'ci'; - myt = new Myt(); + const myt = new Myt(); await myt.init({ workspace: path.join(__dirname, '..'), random: true, ci: isCI, - tmpfs: true, + tmpfs: process.platform == 'linux', network: isCI ? 'jenkins' : null }); - const {dbConfig} = await myt.run(Run); + server = await myt.run(Run); + await myt.deinit(); + const {dbConfig} = server; + + console.log('Initializing backend.'); dataSources = JSON.parse(JSON.stringify(dataSources)); Object.assign(dataSources.vn, { @@ -47,6 +55,8 @@ async function test() { // FIXME: Workaround to wait for loopback to be ready await app.models.Application.status(); + console.log('Running tests.'); + const Jasmine = require('jasmine'); const jasmine = new Jasmine(); @@ -82,9 +92,13 @@ async function test() { }); await jasmine.execute(); + + console.log('Stopping.'); + if (app) await app.disconnect(); - if (myt) await myt.deinit(); - console.log('App disconnected & container removed'); + await rmServer(); + + console.log('Tests ended.\n'); } test();